OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
6 import 'package:compiler/src/constants/values.dart' | 6 import 'package:compiler/src/constants/values.dart' |
7 show PrimitiveConstantValue; | 7 show PrimitiveConstantValue; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
10 import 'parser_helper.dart'; | 10 import 'parser_helper.dart'; |
(...skipping 18 matching lines...) Expand all Loading... |
29 @native | 29 @native |
30 $declaration | 30 $declaration |
31 main() {}"""; | 31 main() {}"""; |
32 | 32 |
33 compileAndCheck(source1, name, (compiler, element) { | 33 compileAndCheck(source1, name, (compiler, element) { |
34 compiler.enqueuer.resolution.queueIsClosed = false; | 34 compiler.enqueuer.resolution.queueIsClosed = false; |
35 Expect.equals(1, length(element.metadata), | 35 Expect.equals(1, length(element.metadata), |
36 'Unexpected metadata count on $element.'); | 36 'Unexpected metadata count on $element.'); |
37 PartialMetadataAnnotation annotation = element.metadata.head; | 37 PartialMetadataAnnotation annotation = element.metadata.head; |
38 annotation.ensureResolved(compiler); | 38 annotation.ensureResolved(compiler); |
39 PrimitiveConstantValue value = annotation.constant.value; | 39 PrimitiveConstantValue value = |
| 40 compiler.constants.getConstantValue(annotation.constant); |
40 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); | 41 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); |
41 | 42 |
42 checkPosition(annotation, annotation.cachedNode, source1, compiler); | 43 checkPosition(annotation, annotation.cachedNode, source1, compiler); |
43 }); | 44 }); |
44 | 45 |
45 // Ensure that each repeated annotation has a unique instance of | 46 // Ensure that each repeated annotation has a unique instance of |
46 // [MetadataAnnotation]. | 47 // [MetadataAnnotation]. |
47 var source2 = """const native = 'xyz'; | 48 var source2 = """const native = 'xyz'; |
48 @native @native | 49 @native @native |
49 $declaration | 50 $declaration |
50 main() {}"""; | 51 main() {}"""; |
51 | 52 |
52 compileAndCheck(source2, name, (compiler, element) { | 53 compileAndCheck(source2, name, (compiler, element) { |
53 compiler.enqueuer.resolution.queueIsClosed = false; | 54 compiler.enqueuer.resolution.queueIsClosed = false; |
54 Expect.equals(2, length(element.metadata)); | 55 Expect.equals(2, length(element.metadata)); |
55 PartialMetadataAnnotation annotation1 = element.metadata.head; | 56 PartialMetadataAnnotation annotation1 = element.metadata.head; |
56 PartialMetadataAnnotation annotation2 = element.metadata.tail.head; | 57 PartialMetadataAnnotation annotation2 = element.metadata.tail.head; |
57 annotation1.ensureResolved(compiler); | 58 annotation1.ensureResolved(compiler); |
58 annotation2.ensureResolved(compiler); | 59 annotation2.ensureResolved(compiler); |
59 Expect.isFalse(identical(annotation1, annotation2), | 60 Expect.isFalse(identical(annotation1, annotation2), |
60 'expected unique instances'); | 61 'expected unique instances'); |
61 Expect.notEquals(annotation1, annotation2, 'expected unequal instances'); | 62 Expect.notEquals(annotation1, annotation2, 'expected unequal instances'); |
62 PrimitiveConstantValue value1 = annotation1.constant.value; | 63 PrimitiveConstantValue value1 = |
63 PrimitiveConstantValue value2 = annotation2.constant.value; | 64 compiler.constants.getConstantValue(annotation1.constant); |
| 65 PrimitiveConstantValue value2 = |
| 66 compiler.constants.getConstantValue(annotation2.constant); |
64 Expect.identical(value1, value2, 'expected same compile-time constant'); | 67 Expect.identical(value1, value2, 'expected same compile-time constant'); |
65 Expect.stringEquals('xyz', value1.primitiveValue.slowToString()); | 68 Expect.stringEquals('xyz', value1.primitiveValue.slowToString()); |
66 Expect.stringEquals('xyz', value2.primitiveValue.slowToString()); | 69 Expect.stringEquals('xyz', value2.primitiveValue.slowToString()); |
67 | 70 |
68 checkPosition(annotation1, annotation1.cachedNode, source2, compiler); | 71 checkPosition(annotation1, annotation1.cachedNode, source2, compiler); |
69 checkPosition(annotation2, annotation2.cachedNode, source2, compiler); | 72 checkPosition(annotation2, annotation2.cachedNode, source2, compiler); |
70 }); | 73 }); |
71 | 74 |
72 if (isTopLevelOnly) return; | 75 if (isTopLevelOnly) return; |
73 | 76 |
74 // Ensure that a compile-time constant can be resolved from an | 77 // Ensure that a compile-time constant can be resolved from an |
75 // annotation. | 78 // annotation. |
76 var source3 = """const native = 'xyz'; | 79 var source3 = """const native = 'xyz'; |
77 class Foo { | 80 class Foo { |
78 @native | 81 @native |
79 $declaration | 82 $declaration |
80 } | 83 } |
81 main() {}"""; | 84 main() {}"""; |
82 | 85 |
83 compileAndCheck(source3, 'Foo', (compiler, element) { | 86 compileAndCheck(source3, 'Foo', (compiler, element) { |
84 compiler.enqueuer.resolution.queueIsClosed = false; | 87 compiler.enqueuer.resolution.queueIsClosed = false; |
85 Expect.equals(0, length(element.metadata)); | 88 Expect.equals(0, length(element.metadata)); |
86 element.ensureResolved(compiler); | 89 element.ensureResolved(compiler); |
87 Expect.equals(0, length(element.metadata)); | 90 Expect.equals(0, length(element.metadata)); |
88 element = element.lookupLocalMember(name); | 91 element = element.lookupLocalMember(name); |
89 Expect.equals(1, length(element.metadata)); | 92 Expect.equals(1, length(element.metadata)); |
90 PartialMetadataAnnotation annotation = element.metadata.head; | 93 PartialMetadataAnnotation annotation = element.metadata.head; |
91 annotation.ensureResolved(compiler); | 94 annotation.ensureResolved(compiler); |
92 PrimitiveConstantValue value = annotation.constant.value; | 95 PrimitiveConstantValue value = |
| 96 compiler.constants.getConstantValue(annotation.constant); |
93 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); | 97 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); |
94 | 98 |
95 checkPosition(annotation, annotation.cachedNode, source3, compiler); | 99 checkPosition(annotation, annotation.cachedNode, source3, compiler); |
96 }); | 100 }); |
97 | 101 |
98 // Ensure that each repeated annotation has a unique instance of | 102 // Ensure that each repeated annotation has a unique instance of |
99 // [MetadataAnnotation]. | 103 // [MetadataAnnotation]. |
100 var source4 = """const native = 'xyz'; | 104 var source4 = """const native = 'xyz'; |
101 class Foo { | 105 class Foo { |
102 @native @native | 106 @native @native |
103 $declaration | 107 $declaration |
104 } | 108 } |
105 main() {}"""; | 109 main() {}"""; |
106 | 110 |
107 compileAndCheck(source4, 'Foo', (compiler, element) { | 111 compileAndCheck(source4, 'Foo', (compiler, element) { |
108 compiler.enqueuer.resolution.queueIsClosed = false; | 112 compiler.enqueuer.resolution.queueIsClosed = false; |
109 Expect.equals(0, length(element.metadata)); | 113 Expect.equals(0, length(element.metadata)); |
110 element.ensureResolved(compiler); | 114 element.ensureResolved(compiler); |
111 Expect.equals(0, length(element.metadata)); | 115 Expect.equals(0, length(element.metadata)); |
112 element = element.lookupLocalMember(name); | 116 element = element.lookupLocalMember(name); |
113 Expect.equals(2, length(element.metadata)); | 117 Expect.equals(2, length(element.metadata)); |
114 PartialMetadataAnnotation annotation1 = element.metadata.head; | 118 PartialMetadataAnnotation annotation1 = element.metadata.head; |
115 PartialMetadataAnnotation annotation2 = element.metadata.tail.head; | 119 PartialMetadataAnnotation annotation2 = element.metadata.tail.head; |
116 annotation1.ensureResolved(compiler); | 120 annotation1.ensureResolved(compiler); |
117 annotation2.ensureResolved(compiler); | 121 annotation2.ensureResolved(compiler); |
118 Expect.isFalse(identical(annotation1, annotation2), | 122 Expect.isFalse(identical(annotation1, annotation2), |
119 'expected unique instances'); | 123 'expected unique instances'); |
120 Expect.notEquals(annotation1, annotation2, 'expected unequal instances'); | 124 Expect.notEquals(annotation1, annotation2, 'expected unequal instances'); |
121 PrimitiveConstantValue value1 = annotation1.constant.value; | 125 PrimitiveConstantValue value1 = |
122 PrimitiveConstantValue value2 = annotation2.constant.value; | 126 compiler.constants.getConstantValue(annotation1.constant); |
| 127 PrimitiveConstantValue value2 = |
| 128 compiler.constants.getConstantValue(annotation2.constant); |
123 Expect.identical(value1, value2, 'expected same compile-time constant'); | 129 Expect.identical(value1, value2, 'expected same compile-time constant'); |
124 Expect.stringEquals('xyz', value1.primitiveValue.slowToString()); | 130 Expect.stringEquals('xyz', value1.primitiveValue.slowToString()); |
125 Expect.stringEquals('xyz', value2.primitiveValue.slowToString()); | 131 Expect.stringEquals('xyz', value2.primitiveValue.slowToString()); |
126 | 132 |
127 checkPosition(annotation1, annotation1.cachedNode, source4, compiler); | 133 checkPosition(annotation1, annotation1.cachedNode, source4, compiler); |
128 checkPosition(annotation1, annotation2.cachedNode, source4, compiler); | 134 checkPosition(annotation1, annotation2.cachedNode, source4, compiler); |
129 }); | 135 }); |
130 } | 136 } |
131 | 137 |
132 void testClassMetadata() { | 138 void testClassMetadata() { |
(...skipping 28 matching lines...) Expand all Loading... |
161 asyncTest(() => compiler.runCompiler(uri).then((_) { | 167 asyncTest(() => compiler.runCompiler(uri).then((_) { |
162 compiler.enqueuer.resolution.queueIsClosed = false; | 168 compiler.enqueuer.resolution.queueIsClosed = false; |
163 LibraryElement element = compiler.libraryLoader.lookupLibrary(uri); | 169 LibraryElement element = compiler.libraryLoader.lookupLibrary(uri); |
164 Expect.isNotNull(element, 'Cannot find $uri'); | 170 Expect.isNotNull(element, 'Cannot find $uri'); |
165 | 171 |
166 Link<MetadataAnnotation> metadata = extractMetadata(element); | 172 Link<MetadataAnnotation> metadata = extractMetadata(element); |
167 Expect.equals(1, length(metadata)); | 173 Expect.equals(1, length(metadata)); |
168 | 174 |
169 PartialMetadataAnnotation annotation = metadata.head; | 175 PartialMetadataAnnotation annotation = metadata.head; |
170 annotation.ensureResolved(compiler); | 176 annotation.ensureResolved(compiler); |
171 PrimitiveConstantValue value = annotation.constant.value; | 177 PrimitiveConstantValue value = |
| 178 compiler.constants.getConstantValue(annotation.constant); |
172 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); | 179 Expect.stringEquals('xyz', value.primitiveValue.slowToString()); |
173 | 180 |
174 checkPosition(annotation, annotation.cachedNode, source, compiler); | 181 checkPosition(annotation, annotation.cachedNode, source, compiler); |
175 })); | 182 })); |
176 } | 183 } |
177 | 184 |
178 var source; | 185 var source; |
179 | 186 |
180 source = """@native | 187 source = """@native |
181 library foo; | 188 library foo; |
(...skipping 26 matching lines...) Expand all Loading... |
208 compileAndCheckLibrary(source, | 215 compileAndCheckLibrary(source, |
209 (e) => e.compilationUnits.first.partTag.metadata); | 216 (e) => e.compilationUnits.first.partTag.metadata); |
210 } | 217 } |
211 | 218 |
212 void main() { | 219 void main() { |
213 testClassMetadata(); | 220 testClassMetadata(); |
214 testTopLevelMethodMetadata(); | 221 testTopLevelMethodMetadata(); |
215 testTopLevelFieldMetadata(); | 222 testTopLevelFieldMetadata(); |
216 testLibraryTags(); | 223 testLibraryTags(); |
217 } | 224 } |
OLD | NEW |