| 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 'dart2jslib.dart' show | 7 import 'dart2jslib.dart' show |
| 8 Compiler, | 8 Compiler, |
| 9 CompilerTask, | 9 CompilerTask, |
| 10 Constant, | 10 Constant, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 MirrorUsageAnalyzer(Compiler compiler, this.task) | 168 MirrorUsageAnalyzer(Compiler compiler, this.task) |
| 169 : compiler = compiler, | 169 : compiler = compiler, |
| 170 librariesWithUsage = new Set<LibraryElement>(), | 170 librariesWithUsage = new Set<LibraryElement>(), |
| 171 cachedStrings = new Map<Constant, List<String>>(), | 171 cachedStrings = new Map<Constant, List<String>>(), |
| 172 cachedElements = new Map<Constant, List<Element>>(); | 172 cachedElements = new Map<Constant, List<Element>>(); |
| 173 | 173 |
| 174 /// Collect and merge all @MirrorsUsed annotations. As a side-effect, also | 174 /// Collect and merge all @MirrorsUsed annotations. As a side-effect, also |
| 175 /// compute which libraries have the annotation (which is used by | 175 /// compute which libraries have the annotation (which is used by |
| 176 /// [MirrorUsageAnalyzerTask.hasMirrorUsage]). | 176 /// [MirrorUsageAnalyzerTask.hasMirrorUsage]). |
| 177 void run() { | 177 void run() { |
| 178 wildcard = compiler.libraries.values.toList(); | 178 wildcard = compiler.libraryLoader.libraries.toList(); |
| 179 Map<LibraryElement, List<MirrorUsage>> usageMap = | 179 Map<LibraryElement, List<MirrorUsage>> usageMap = |
| 180 collectMirrorsUsedAnnotation(); | 180 collectMirrorsUsedAnnotation(); |
| 181 propagateOverrides(usageMap); | 181 propagateOverrides(usageMap); |
| 182 Set<LibraryElement> librariesWithoutUsage = new Set<LibraryElement>(); | 182 Set<LibraryElement> librariesWithoutUsage = new Set<LibraryElement>(); |
| 183 usageMap.forEach((LibraryElement library, List<MirrorUsage> usage) { | 183 usageMap.forEach((LibraryElement library, List<MirrorUsage> usage) { |
| 184 if (usage.isEmpty) librariesWithoutUsage.add(library); | 184 if (usage.isEmpty) librariesWithoutUsage.add(library); |
| 185 }); | 185 }); |
| 186 if (librariesWithoutUsage.isEmpty) { | 186 if (librariesWithoutUsage.isEmpty) { |
| 187 mergedMirrorUsage = mergeUsages(usageMap); | 187 mergedMirrorUsage = mergeUsages(usageMap); |
| 188 } else { | 188 } else { |
| 189 mergedMirrorUsage = new MirrorUsage(null, null, null, null); | 189 mergedMirrorUsage = new MirrorUsage(null, null, null, null); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 /// Collect all @MirrorsUsed from all libraries and represent them as | 193 /// Collect all @MirrorsUsed from all libraries and represent them as |
| 194 /// [MirrorUsage]. | 194 /// [MirrorUsage]. |
| 195 Map<LibraryElement, List<MirrorUsage>> collectMirrorsUsedAnnotation() { | 195 Map<LibraryElement, List<MirrorUsage>> collectMirrorsUsedAnnotation() { |
| 196 Map<LibraryElement, List<MirrorUsage>> result = | 196 Map<LibraryElement, List<MirrorUsage>> result = |
| 197 new Map<LibraryElement, List<MirrorUsage>>(); | 197 new Map<LibraryElement, List<MirrorUsage>>(); |
| 198 for (LibraryElement library in compiler.libraries.values) { | 198 for (LibraryElement library in compiler.libraryLoader.libraries) { |
| 199 if (library.isInternalLibrary) continue; | 199 if (library.isInternalLibrary) continue; |
| 200 for (LibraryTag tag in library.tags) { | 200 for (LibraryTag tag in library.tags) { |
| 201 Import importTag = tag.asImport(); | 201 Import importTag = tag.asImport(); |
| 202 if (importTag == null) continue; | 202 if (importTag == null) continue; |
| 203 compiler.withCurrentElement(library, () { | 203 compiler.withCurrentElement(library, () { |
| 204 List<MirrorUsage> usages = | 204 List<MirrorUsage> usages = |
| 205 mirrorsUsedOnLibraryTag(library, importTag); | 205 mirrorsUsedOnLibraryTag(library, importTag); |
| 206 if (usages != null) { | 206 if (usages != null) { |
| 207 List<MirrorUsage> existing = result[library]; | 207 List<MirrorUsage> existing = result[library]; |
| 208 if (existing != null) { | 208 if (existing != null) { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 464 } |
| 465 List<Element> result = <Element>[]; | 465 List<Element> result = <Element>[]; |
| 466 for (var entry in list) { | 466 for (var entry in list) { |
| 467 if (entry is DartType) { | 467 if (entry is DartType) { |
| 468 DartType type = entry; | 468 DartType type = entry; |
| 469 result.add(type.element); | 469 result.add(type.element); |
| 470 } else { | 470 } else { |
| 471 String string = entry; | 471 String string = entry; |
| 472 LibraryElement libraryCandiate; | 472 LibraryElement libraryCandiate; |
| 473 String libraryNameCandiate; | 473 String libraryNameCandiate; |
| 474 for (LibraryElement l in compiler.libraries.values) { | 474 for (LibraryElement l in compiler.libraryLoader.libraries) { |
| 475 if (l.hasLibraryName()) { | 475 if (l.hasLibraryName()) { |
| 476 String libraryName = l.getLibraryOrScriptName(); | 476 String libraryName = l.getLibraryOrScriptName(); |
| 477 if (string == libraryName) { | 477 if (string == libraryName) { |
| 478 // Found an exact match. | 478 // Found an exact match. |
| 479 libraryCandiate = l; | 479 libraryCandiate = l; |
| 480 libraryNameCandiate = libraryName; | 480 libraryNameCandiate = libraryName; |
| 481 break; | 481 break; |
| 482 } else if (string.startsWith('$libraryName.')) { | 482 } else if (string.startsWith('$libraryName.')) { |
| 483 if (libraryNameCandiate == null | 483 if (libraryNameCandiate == null |
| 484 || libraryNameCandiate.length < libraryName.length) { | 484 || libraryNameCandiate.length < libraryName.length) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 // @MirrorsUsed(targets: fisk) | 582 // @MirrorsUsed(targets: fisk) |
| 583 // ^^^^ | 583 // ^^^^ |
| 584 // | 584 // |
| 585 // Instead of saying 'fisk' should pretty print the problematic constant | 585 // Instead of saying 'fisk' should pretty print the problematic constant |
| 586 // value. | 586 // value. |
| 587 return spannable; | 587 return spannable; |
| 588 } | 588 } |
| 589 return node; | 589 return node; |
| 590 } | 590 } |
| 591 } | 591 } |
| OLD | NEW |