OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
7 import 'package:compiler/src/compiler.dart'; | 7 import 'package:compiler/src/compiler.dart'; |
8 import 'package:compiler/src/elements/elements.dart'; | 8 import 'package:compiler/src/elements/elements.dart'; |
9 import 'package:compiler/src/js_backend/js_backend.dart'; | 9 import 'package:compiler/src/js_backend/js_backend.dart'; |
10 import 'package:compiler/src/types/types.dart'; | 10 import 'package:compiler/src/types/types.dart'; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation'); | 54 Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation'); |
55 JavaScriptBackend backend = compiler.backend; | 55 JavaScriptBackend backend = compiler.backend; |
56 Expect.isNotNull(backend.annotations.expectNoInlineClass, | 56 Expect.isNotNull(backend.annotations.expectNoInlineClass, |
57 'NoInlineClass is unresolved.'); | 57 'NoInlineClass is unresolved.'); |
58 Expect.isNotNull(backend.annotations.expectTrustTypeAnnotationsClass, | 58 Expect.isNotNull(backend.annotations.expectTrustTypeAnnotationsClass, |
59 'TrustTypeAnnotations is unresolved.'); | 59 'TrustTypeAnnotations is unresolved.'); |
60 Expect.isNotNull(backend.annotations.expectAssumeDynamicClass, | 60 Expect.isNotNull(backend.annotations.expectAssumeDynamicClass, |
61 'AssumeDynamicClass is unresolved.'); | 61 'AssumeDynamicClass is unresolved.'); |
62 | 62 |
63 void testTypeMatch(FunctionElement function, TypeMask expectedParameterType, | 63 void testTypeMatch(FunctionElement function, TypeMask expectedParameterType, |
64 TypeMask expectedReturnType, TypesInferrer inferrer) { | 64 TypeMask expectedReturnType, TypesInferrer inferrer) { |
65 for (ParameterElement parameter in function.parameters) { | 65 for (ParameterElement parameter in function.parameters) { |
66 TypeMask type = inferrer.getTypeOfElement(parameter); | 66 TypeMask type = inferrer.getTypeOfElement(parameter); |
67 Expect.equals(expectedParameterType, simplify(type, compiler), | 67 Expect.equals( |
68 "$parameter"); | 68 expectedParameterType, simplify(type, compiler), "$parameter"); |
69 } | 69 } |
70 if (expectedReturnType != null) { | 70 if (expectedReturnType != null) { |
71 TypeMask type = inferrer.getReturnTypeOfElement(function); | 71 TypeMask type = inferrer.getReturnTypeOfElement(function); |
72 Expect.equals(expectedReturnType, simplify(type, compiler), | 72 Expect.equals( |
73 "$function"); | 73 expectedReturnType, simplify(type, compiler), "$function"); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 void test(String name, | 77 void test(String name, |
78 {bool expectNoInline: false, | 78 {bool expectNoInline: false, |
79 bool expectTrustTypeAnnotations: false, | 79 bool expectTrustTypeAnnotations: false, |
80 TypeMask expectedParameterType: null, | 80 TypeMask expectedParameterType: null, |
81 TypeMask expectedReturnType: null, | 81 TypeMask expectedReturnType: null, |
82 bool expectAssumeDynamic: false}) { | 82 bool expectAssumeDynamic: false}) { |
83 Element method = compiler.mainApp.find(name); | 83 Element method = compiler.mainApp.find(name); |
84 Expect.isNotNull(method); | 84 Expect.isNotNull(method); |
85 Expect.equals( | 85 Expect.equals(expectNoInline, backend.annotations.noInline(method), |
86 expectNoInline, | 86 "Unexpected annotation of @NoInline on '$method'."); |
87 backend.annotations.noInline(method), | 87 Expect.equals( |
88 "Unexpected annotation of @NoInline on '$method'."); | 88 expectTrustTypeAnnotations, |
89 Expect.equals( | 89 backend.annotations.trustTypeAnnotations(method), |
90 expectTrustTypeAnnotations, | 90 "Unexpected annotation of @TrustTypeAnnotations on '$method'."); |
91 backend.annotations.trustTypeAnnotations(method), | 91 Expect.equals( |
92 "Unexpected annotation of @TrustTypeAnnotations on '$method'."); | 92 expectAssumeDynamic, |
93 Expect.equals( | 93 backend.annotations.assumeDynamic(method), |
94 expectAssumeDynamic, | 94 "Unexpected annotation of @AssumeDynamic on '$method'."); |
95 backend.annotations.assumeDynamic(method), | 95 TypesInferrer inferrer = compiler.globalInference.typesInferrer; |
96 "Unexpected annotation of @AssumeDynamic on '$method'."); | 96 if (expectTrustTypeAnnotations && expectedParameterType != null) { |
97 TypesInferrer inferrer = compiler.globalInference.typesInferrer; | 97 testTypeMatch( |
98 if (expectTrustTypeAnnotations && expectedParameterType != null) { | 98 method, expectedParameterType, expectedReturnType, inferrer); |
99 testTypeMatch(method, expectedParameterType, expectedReturnType, | 99 } else if (expectAssumeDynamic) { |
100 inferrer); | 100 testTypeMatch(method, compiler.commonMasks.dynamicType, null, inferrer); |
101 } else if (expectAssumeDynamic) { | 101 } |
102 testTypeMatch(method, | |
103 compiler.commonMasks.dynamicType, null, inferrer); | |
104 } | |
105 } | 102 } |
106 | 103 |
107 TypeMask jsStringType = compiler.commonMasks.stringType; | 104 TypeMask jsStringType = compiler.commonMasks.stringType; |
108 TypeMask jsIntType = compiler.commonMasks.intType; | 105 TypeMask jsIntType = compiler.commonMasks.intType; |
109 TypeMask coreStringType = new TypeMask.subtype( | 106 TypeMask coreStringType = |
110 compiler.coreClasses.stringClass, compiler.world); | 107 new TypeMask.subtype(compiler.coreClasses.stringClass, compiler.world); |
111 | 108 |
112 test('method'); | 109 test('method'); |
113 test('methodAssumeDynamic', expectAssumeDynamic: true); | 110 test('methodAssumeDynamic', expectAssumeDynamic: true); |
114 test('methodTrustTypeAnnotations', | 111 test('methodTrustTypeAnnotations', |
115 expectTrustTypeAnnotations: true, | 112 expectTrustTypeAnnotations: true, expectedParameterType: jsStringType); |
116 expectedParameterType: jsStringType); | |
117 test('methodNoInline', expectNoInline: true); | 113 test('methodNoInline', expectNoInline: true); |
118 test('methodNoInlineTrustTypeAnnotations', | 114 test('methodNoInlineTrustTypeAnnotations', |
119 expectNoInline: true, | 115 expectNoInline: true, |
120 expectTrustTypeAnnotations: true, | 116 expectTrustTypeAnnotations: true, |
121 expectedParameterType: jsStringType, | 117 expectedParameterType: jsStringType, |
122 expectedReturnType: jsIntType); | 118 expectedReturnType: jsIntType); |
123 test('methodAssumeDynamicTrustTypeAnnotations', | 119 test('methodAssumeDynamicTrustTypeAnnotations', |
124 expectAssumeDynamic: true, | 120 expectAssumeDynamic: true, |
125 expectTrustTypeAnnotations: true, | 121 expectTrustTypeAnnotations: true, |
126 expectedParameterType: coreStringType); | 122 expectedParameterType: coreStringType); |
127 | |
128 }); | 123 }); |
129 } | 124 } |
OLD | NEW |