| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.mirrors_used; | 5 library dart2js.mirrors_used; |
| 6 | 6 |
| 7 import 'cps_ir/const_expression.dart'; |
| 8 |
| 7 import 'dart2jslib.dart' show | 9 import 'dart2jslib.dart' show |
| 8 Compiler, | 10 Compiler, |
| 9 CompilerTask, | 11 CompilerTask, |
| 10 Constant, | 12 Constant, |
| 11 ConstantCompiler, | 13 ConstantCompiler, |
| 12 ConstructedConstant, | 14 ConstructedConstant, |
| 13 ListConstant, | 15 ListConstant, |
| 14 MessageKind, | 16 MessageKind, |
| 15 StringConstant, | 17 StringConstant, |
| 16 TreeElements, | 18 TreeElements, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 127 } |
| 126 | 128 |
| 127 /// Call-back from the resolver to analyze MirorsUsed annotations. The result | 129 /// Call-back from the resolver to analyze MirorsUsed annotations. The result |
| 128 /// is stored in [analyzer] and later used to compute | 130 /// is stored in [analyzer] and later used to compute |
| 129 /// [:analyzer.mergedMirrorUsage:]. | 131 /// [:analyzer.mergedMirrorUsage:]. |
| 130 void validate(NewExpression node, TreeElements mapping) { | 132 void validate(NewExpression node, TreeElements mapping) { |
| 131 for (Node argument in node.send.arguments) { | 133 for (Node argument in node.send.arguments) { |
| 132 NamedArgument named = argument.asNamedArgument(); | 134 NamedArgument named = argument.asNamedArgument(); |
| 133 if (named == null) continue; | 135 if (named == null) continue; |
| 134 ConstantCompiler constantCompiler = compiler.resolver.constantCompiler; | 136 ConstantCompiler constantCompiler = compiler.resolver.constantCompiler; |
| 135 Constant value = constantCompiler.compileNode(named.expression, mapping); | 137 Constant value = |
| 138 constantCompiler.compileNode(named.expression, mapping).value; |
| 136 | 139 |
| 137 MirrorUsageBuilder builder = | 140 MirrorUsageBuilder builder = |
| 138 new MirrorUsageBuilder( | 141 new MirrorUsageBuilder( |
| 139 analyzer, mapping.analyzedElement.library, named.expression, | 142 analyzer, mapping.analyzedElement.library, named.expression, |
| 140 value, mapping); | 143 value, mapping); |
| 141 | 144 |
| 142 if (named.name.source == 'symbols') { | 145 if (named.name.source == 'symbols') { |
| 143 analyzer.cachedStrings[value] = | 146 analyzer.cachedStrings[value] = |
| 144 builder.convertConstantToUsageList(value, onlyStrings: true); | 147 builder.convertConstantToUsageList(value, onlyStrings: true); |
| 145 } else if (named.name.source == 'targets') { | 148 } else if (named.name.source == 'targets') { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 /// annotations are represented as [MirrorUsage]. | 257 /// annotations are represented as [MirrorUsage]. |
| 255 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library, | 258 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library, |
| 256 Import tag) { | 259 Import tag) { |
| 257 LibraryElement importedLibrary = library.getLibraryFromTag(tag); | 260 LibraryElement importedLibrary = library.getLibraryFromTag(tag); |
| 258 if (importedLibrary != compiler.mirrorsLibrary) { | 261 if (importedLibrary != compiler.mirrorsLibrary) { |
| 259 return null; | 262 return null; |
| 260 } | 263 } |
| 261 List<MirrorUsage> result = <MirrorUsage>[]; | 264 List<MirrorUsage> result = <MirrorUsage>[]; |
| 262 for (MetadataAnnotation metadata in tag.metadata) { | 265 for (MetadataAnnotation metadata in tag.metadata) { |
| 263 metadata.ensureResolved(compiler); | 266 metadata.ensureResolved(compiler); |
| 264 Element element = metadata.value.computeType(compiler).element; | 267 Element element = metadata.constant.value.computeType(compiler).element; |
| 265 if (element == compiler.mirrorsUsedClass) { | 268 if (element == compiler.mirrorsUsedClass) { |
| 266 result.add(buildUsage(metadata.value)); | 269 result.add(buildUsage(metadata.constant.value)); |
| 267 } | 270 } |
| 268 } | 271 } |
| 269 return result; | 272 return result; |
| 270 } | 273 } |
| 271 | 274 |
| 272 /// Merge all [MirrorUsage] instances accross all libraries. | 275 /// Merge all [MirrorUsage] instances accross all libraries. |
| 273 MirrorUsage mergeUsages(Map<LibraryElement, List<MirrorUsage>> usageMap) { | 276 MirrorUsage mergeUsages(Map<LibraryElement, List<MirrorUsage>> usageMap) { |
| 274 Set<MirrorUsage> usagesToMerge = new Set<MirrorUsage>(); | 277 Set<MirrorUsage> usagesToMerge = new Set<MirrorUsage>(); |
| 275 usageMap.forEach((LibraryElement library, List<MirrorUsage> usages) { | 278 usageMap.forEach((LibraryElement library, List<MirrorUsage> usages) { |
| 276 librariesWithUsage.add(library); | 279 librariesWithUsage.add(library); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 cls.ensureResolved(compiler); | 557 cls.ensureResolved(compiler); |
| 555 } | 558 } |
| 556 return scope.localLookup(name); | 559 return scope.localLookup(name); |
| 557 } | 560 } |
| 558 return null; | 561 return null; |
| 559 } | 562 } |
| 560 | 563 |
| 561 /// Attempt to find a [Spannable] corresponding to constant. | 564 /// Attempt to find a [Spannable] corresponding to constant. |
| 562 Spannable positionOf(Constant constant) { | 565 Spannable positionOf(Constant constant) { |
| 563 Node node; | 566 Node node; |
| 564 elements.forEachConstantNode((Node n, Constant c) { | 567 elements.forEachConstantNode((Node n, ConstExp c) { |
| 565 if (node == null && c == constant) { | 568 if (node == null && c.value == constant) { |
| 566 node = n; | 569 node = n; |
| 567 } | 570 } |
| 568 }); | 571 }); |
| 569 if (node == null) { | 572 if (node == null) { |
| 570 // TODO(ahe): Returning [spannable] here leads to confusing error | 573 // TODO(ahe): Returning [spannable] here leads to confusing error |
| 571 // messages. For example, consider: | 574 // messages. For example, consider: |
| 572 // @MirrorsUsed(targets: fisk) | 575 // @MirrorsUsed(targets: fisk) |
| 573 // import 'dart:mirrors'; | 576 // import 'dart:mirrors'; |
| 574 // | 577 // |
| 575 // const fisk = const [main]; | 578 // const fisk = const [main]; |
| 576 // | 579 // |
| 577 // main() {} | 580 // main() {} |
| 578 // | 581 // |
| 579 // The message is: | 582 // The message is: |
| 580 // example.dart:1:23: Hint: Can't use 'fisk' here because ... | 583 // example.dart:1:23: Hint: Can't use 'fisk' here because ... |
| 581 // Did you forget to add quotes? | 584 // Did you forget to add quotes? |
| 582 // @MirrorsUsed(targets: fisk) | 585 // @MirrorsUsed(targets: fisk) |
| 583 // ^^^^ | 586 // ^^^^ |
| 584 // | 587 // |
| 585 // Instead of saying 'fisk' should pretty print the problematic constant | 588 // Instead of saying 'fisk' should pretty print the problematic constant |
| 586 // value. | 589 // value. |
| 587 return spannable; | 590 return spannable; |
| 588 } | 591 } |
| 589 return node; | 592 return node; |
| 590 } | 593 } |
| 591 } | 594 } |
| OLD | NEW |