| 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 'common/tasks.dart' show CompilerTask; | 7 import 'common/tasks.dart' show CompilerTask; |
| 8 import 'common.dart'; | 8 import 'common.dart'; |
| 9 import 'compile_time_constants.dart' show ConstantCompiler; | 9 import 'compile_time_constants.dart' show ConstantCompiler; |
| 10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
| 11 import 'constants/expressions.dart'; | 11 import 'constants/expressions.dart'; |
| 12 import 'constants/values.dart' | 12 import 'constants/values.dart' |
| 13 show | 13 show |
| 14 ConstantValue, | 14 ConstantValue, |
| 15 ConstructedConstantValue, | 15 ConstructedConstantValue, |
| 16 ListConstantValue, | 16 ListConstantValue, |
| 17 StringConstantValue, | 17 StringConstantValue, |
| 18 TypeConstantValue; | 18 TypeConstantValue; |
| 19 import 'elements/resolution_types.dart' | 19 import 'elements/resolution_types.dart' |
| 20 show ResolutionDartType, ResolutionInterfaceType; | 20 show ResolutionDartType, ResolutionInterfaceType; |
| 21 import 'elements/elements.dart' | 21 import 'elements/elements.dart' |
| 22 show | 22 show |
| 23 ClassElement, | 23 ClassElement, |
| 24 Element, | 24 Element, |
| 25 FieldElement, | 25 FieldElement, |
| 26 ImportElement, | 26 ImportElement, |
| 27 LibraryElement, | 27 LibraryElement, |
| 28 MetadataAnnotation, | 28 MetadataAnnotation, |
| 29 ScopeContainerElement; | 29 ScopeContainerElement; |
| 30 import 'elements/entities.dart'; |
| 30 import 'resolution/tree_elements.dart' show TreeElements; | 31 import 'resolution/tree_elements.dart' show TreeElements; |
| 31 import 'tree/tree.dart' show NamedArgument, NewExpression, Node; | 32 import 'tree/tree.dart' show NamedArgument, NewExpression, Node; |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Compiler task that analyzes MirrorsUsed annotations. | 35 * Compiler task that analyzes MirrorsUsed annotations. |
| 35 * | 36 * |
| 36 * When importing 'dart:mirrors', it is possible to annotate the import with | 37 * When importing 'dart:mirrors', it is possible to annotate the import with |
| 37 * MirrorsUsed annotation. This is a way to declare what elements will be | 38 * MirrorsUsed annotation. This is a way to declare what elements will be |
| 38 * reflected on at runtime. Such elements, even they would normally be | 39 * reflected on at runtime. Such elements, even they would normally be |
| 39 * discarded by the implicit tree-shaking algorithm must be preserved in the | 40 * discarded by the implicit tree-shaking algorithm must be preserved in the |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 final Compiler compiler; | 85 final Compiler compiler; |
| 85 | 86 |
| 86 MirrorUsageAnalyzerTask(Compiler compiler) | 87 MirrorUsageAnalyzerTask(Compiler compiler) |
| 87 : compiler = compiler, | 88 : compiler = compiler, |
| 88 super(compiler.measurer) { | 89 super(compiler.measurer) { |
| 89 analyzer = new MirrorUsageAnalyzer(compiler, this); | 90 analyzer = new MirrorUsageAnalyzer(compiler, this); |
| 90 } | 91 } |
| 91 | 92 |
| 92 /// Collect @MirrorsUsed annotations in all libraries. Called by the | 93 /// Collect @MirrorsUsed annotations in all libraries. Called by the |
| 93 /// compiler after all libraries are loaded, but before resolution. | 94 /// compiler after all libraries are loaded, but before resolution. |
| 94 void analyzeUsage(LibraryElement mainApp) { | 95 void analyzeUsage(LibraryEntity mainApp) { |
| 95 if (mainApp == null || compiler.commonElements.mirrorsLibrary == null) { | 96 if (mainApp == null || compiler.commonElements.mirrorsLibrary == null) { |
| 96 return; | 97 return; |
| 97 } | 98 } |
| 98 measure(analyzer.run); | 99 measure(analyzer.run); |
| 99 List<String> symbols = analyzer.mergedMirrorUsage.symbols; | 100 List<String> symbols = analyzer.mergedMirrorUsage.symbols; |
| 100 List<Element> targets = analyzer.mergedMirrorUsage.targets; | 101 List<Element> targets = analyzer.mergedMirrorUsage.targets; |
| 101 List<Element> metaTargets = analyzer.mergedMirrorUsage.metaTargets; | 102 List<Element> metaTargets = analyzer.mergedMirrorUsage.metaTargets; |
| 102 compiler.backend.mirrorsDataBuilder.registerMirrorUsage( | 103 compiler.backend.mirrorsDataBuilder.registerMirrorUsage( |
| 103 symbols == null ? null : new Set<String>.from(symbols), | 104 symbols == null ? null : new Set<String>.from(symbols), |
| 104 targets == null ? null : new Set<Element>.from(targets), | 105 targets == null ? null : new Set<Element>.from(targets), |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // @MirrorsUsed(targets: fisk) | 567 // @MirrorsUsed(targets: fisk) |
| 567 // ^^^^ | 568 // ^^^^ |
| 568 // | 569 // |
| 569 // Instead of saying 'fisk' should pretty print the problematic constant | 570 // Instead of saying 'fisk' should pretty print the problematic constant |
| 570 // value. | 571 // value. |
| 571 return spannable; | 572 return spannable; |
| 572 } | 573 } |
| 573 return node; | 574 return node; |
| 574 } | 575 } |
| 575 } | 576 } |
| OLD | NEW |