| 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; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 * On the other hand, if all libraries importing dart:mirrors have a | 73 * On the other hand, if all libraries importing dart:mirrors have a |
| 74 * MirrorsUsed annotation, these annotations are merged. | 74 * MirrorsUsed annotation, these annotations are merged. |
| 75 * | 75 * |
| 76 * MERGING MIRRORSUSED | 76 * MERGING MIRRORSUSED |
| 77 * | 77 * |
| 78 * TBD. | 78 * TBD. |
| 79 */ | 79 */ |
| 80 class MirrorUsageAnalyzerTask extends CompilerTask { | 80 class MirrorUsageAnalyzerTask extends CompilerTask { |
| 81 Set<LibraryElement> librariesWithUsage; | 81 Set<LibraryElement> librariesWithUsage; |
| 82 MirrorUsageAnalyzer analyzer; | 82 MirrorUsageAnalyzer analyzer; |
| 83 final Compiler compiler; |
| 83 | 84 |
| 84 MirrorUsageAnalyzerTask(Compiler compiler) : super(compiler) { | 85 MirrorUsageAnalyzerTask(Compiler compiler) |
| 86 : compiler = compiler, |
| 87 super(compiler.measurer) { |
| 85 analyzer = new MirrorUsageAnalyzer(compiler, this); | 88 analyzer = new MirrorUsageAnalyzer(compiler, this); |
| 86 } | 89 } |
| 87 | 90 |
| 88 /// Collect @MirrorsUsed annotations in all libraries. Called by the | 91 /// Collect @MirrorsUsed annotations in all libraries. Called by the |
| 89 /// compiler after all libraries are loaded, but before resolution. | 92 /// compiler after all libraries are loaded, but before resolution. |
| 90 void analyzeUsage(LibraryElement mainApp) { | 93 void analyzeUsage(LibraryElement mainApp) { |
| 91 if (mainApp == null || compiler.mirrorsLibrary == null) return; | 94 if (mainApp == null || compiler.mirrorsLibrary == null) return; |
| 92 measure(analyzer.run); | 95 measure(analyzer.run); |
| 93 List<String> symbols = analyzer.mergedMirrorUsage.symbols; | 96 List<String> symbols = analyzer.mergedMirrorUsage.symbols; |
| 94 List<Element> targets = analyzer.mergedMirrorUsage.targets; | 97 List<Element> targets = analyzer.mergedMirrorUsage.targets; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 146 |
| 144 class MirrorUsageAnalyzer { | 147 class MirrorUsageAnalyzer { |
| 145 final Compiler compiler; | 148 final Compiler compiler; |
| 146 final MirrorUsageAnalyzerTask task; | 149 final MirrorUsageAnalyzerTask task; |
| 147 List<LibraryElement> wildcard; | 150 List<LibraryElement> wildcard; |
| 148 final Set<LibraryElement> librariesWithUsage; | 151 final Set<LibraryElement> librariesWithUsage; |
| 149 final Map<ConstantValue, List<String>> cachedStrings; | 152 final Map<ConstantValue, List<String>> cachedStrings; |
| 150 final Map<ConstantValue, List<Element>> cachedElements; | 153 final Map<ConstantValue, List<Element>> cachedElements; |
| 151 MirrorUsage mergedMirrorUsage; | 154 MirrorUsage mergedMirrorUsage; |
| 152 | 155 |
| 153 MirrorUsageAnalyzer(Compiler compiler, this.task) | 156 MirrorUsageAnalyzer(this.compiler, this.task) |
| 154 : compiler = compiler, | 157 : librariesWithUsage = new Set<LibraryElement>(), |
| 155 librariesWithUsage = new Set<LibraryElement>(), | |
| 156 cachedStrings = new Map<ConstantValue, List<String>>(), | 158 cachedStrings = new Map<ConstantValue, List<String>>(), |
| 157 cachedElements = new Map<ConstantValue, List<Element>>(); | 159 cachedElements = new Map<ConstantValue, List<Element>>(); |
| 158 | 160 |
| 159 DiagnosticReporter get reporter => compiler.reporter; | 161 DiagnosticReporter get reporter => compiler.reporter; |
| 160 | 162 |
| 161 /// Collect and merge all @MirrorsUsed annotations. As a side-effect, also | 163 /// Collect and merge all @MirrorsUsed annotations. As a side-effect, also |
| 162 /// compute which libraries have the annotation (which is used by | 164 /// compute which libraries have the annotation (which is used by |
| 163 /// [MirrorUsageAnalyzerTask.hasMirrorUsage]). | 165 /// [MirrorUsageAnalyzerTask.hasMirrorUsage]). |
| 164 void run() { | 166 void run() { |
| 165 wildcard = compiler.libraryLoader.libraries.toList(); | 167 wildcard = compiler.libraryLoader.libraries.toList(); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 // @MirrorsUsed(targets: fisk) | 565 // @MirrorsUsed(targets: fisk) |
| 564 // ^^^^ | 566 // ^^^^ |
| 565 // | 567 // |
| 566 // Instead of saying 'fisk' should pretty print the problematic constant | 568 // Instead of saying 'fisk' should pretty print the problematic constant |
| 567 // value. | 569 // value. |
| 568 return spannable; | 570 return spannable; |
| 569 } | 571 } |
| 570 return node; | 572 return node; |
| 571 } | 573 } |
| 572 } | 574 } |
| OLD | NEW |