Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: pkg/compiler/lib/src/mirrors_used.dart

Issue 2265473004: Introduce "CommonElements" (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 MirrorUsageAnalyzerTask(Compiler compiler) 85 MirrorUsageAnalyzerTask(Compiler compiler)
86 : compiler = compiler, 86 : compiler = compiler,
87 super(compiler.measurer) { 87 super(compiler.measurer) {
88 analyzer = new MirrorUsageAnalyzer(compiler, this); 88 analyzer = new MirrorUsageAnalyzer(compiler, this);
89 } 89 }
90 90
91 /// Collect @MirrorsUsed annotations in all libraries. Called by the 91 /// Collect @MirrorsUsed annotations in all libraries. Called by the
92 /// compiler after all libraries are loaded, but before resolution. 92 /// compiler after all libraries are loaded, but before resolution.
93 void analyzeUsage(LibraryElement mainApp) { 93 void analyzeUsage(LibraryElement mainApp) {
94 if (mainApp == null || compiler.mirrorsLibrary == null) return; 94 if (mainApp == null || compiler.commonElements.mirrorsLibrary == null) {
95 return;
96 }
95 measure(analyzer.run); 97 measure(analyzer.run);
96 List<String> symbols = analyzer.mergedMirrorUsage.symbols; 98 List<String> symbols = analyzer.mergedMirrorUsage.symbols;
97 List<Element> targets = analyzer.mergedMirrorUsage.targets; 99 List<Element> targets = analyzer.mergedMirrorUsage.targets;
98 List<Element> metaTargets = analyzer.mergedMirrorUsage.metaTargets; 100 List<Element> metaTargets = analyzer.mergedMirrorUsage.metaTargets;
99 compiler.backend.registerMirrorUsage( 101 compiler.backend.registerMirrorUsage(
100 symbols == null ? null : new Set<String>.from(symbols), 102 symbols == null ? null : new Set<String>.from(symbols),
101 targets == null ? null : new Set<Element>.from(targets), 103 targets == null ? null : new Set<Element>.from(targets),
102 metaTargets == null ? null : new Set<Element>.from(metaTargets)); 104 metaTargets == null ? null : new Set<Element>.from(metaTargets));
103 librariesWithUsage = analyzer.librariesWithUsage; 105 librariesWithUsage = analyzer.librariesWithUsage;
104 } 106 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 usageMap.putIfAbsent(overridden, () => <MirrorUsage>[]); 236 usageMap.putIfAbsent(overridden, () => <MirrorUsage>[]);
235 usages.addAll(overriddenUsages); 237 usages.addAll(overriddenUsages);
236 }); 238 });
237 } 239 }
238 240
239 /// Find @MirrorsUsed annotations on the given import [tag] in [library]. The 241 /// Find @MirrorsUsed annotations on the given import [tag] in [library]. The
240 /// annotations are represented as [MirrorUsage]. 242 /// annotations are represented as [MirrorUsage].
241 List<MirrorUsage> mirrorsUsedOnLibraryTag( 243 List<MirrorUsage> mirrorsUsedOnLibraryTag(
242 LibraryElement library, ImportElement import) { 244 LibraryElement library, ImportElement import) {
243 LibraryElement importedLibrary = import.importedLibrary; 245 LibraryElement importedLibrary = import.importedLibrary;
244 if (importedLibrary != compiler.mirrorsLibrary) { 246 if (importedLibrary != compiler.commonElements.mirrorsLibrary) {
245 return null; 247 return null;
246 } 248 }
247 List<MirrorUsage> result = <MirrorUsage>[]; 249 List<MirrorUsage> result = <MirrorUsage>[];
248 for (MetadataAnnotation metadata in import.metadata) { 250 for (MetadataAnnotation metadata in import.metadata) {
249 metadata.ensureResolved(compiler.resolution); 251 metadata.ensureResolved(compiler.resolution);
250 ConstantValue value = 252 ConstantValue value =
251 compiler.constants.getConstantValue(metadata.constant); 253 compiler.constants.getConstantValue(metadata.constant);
252 Element element = value.getType(compiler.coreTypes).element; 254 Element element = value.getType(compiler.coreTypes).element;
253 if (element == compiler.mirrorsUsedClass) { 255 if (element == compiler.commonElements.mirrorsUsedClass) {
254 result.add(buildUsage(value)); 256 result.add(buildUsage(value));
255 } 257 }
256 } 258 }
257 return result; 259 return result;
258 } 260 }
259 261
260 /// Merge all [MirrorUsage] instances accross all libraries. 262 /// Merge all [MirrorUsage] instances accross all libraries.
261 MirrorUsage mergeUsages(Map<LibraryElement, List<MirrorUsage>> usageMap) { 263 MirrorUsage mergeUsages(Map<LibraryElement, List<MirrorUsage>> usageMap) {
262 Set<MirrorUsage> usagesToMerge = new Set<MirrorUsage>(); 264 Set<MirrorUsage> usagesToMerge = new Set<MirrorUsage>();
263 usageMap.forEach((LibraryElement library, List<MirrorUsage> usages) { 265 usageMap.forEach((LibraryElement library, List<MirrorUsage> usages) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } else if (metaTargets != wildcard && b.metaTargets != null) { 308 } else if (metaTargets != wildcard && b.metaTargets != null) {
307 metaTargets.addAll(b.metaTargets); 309 metaTargets.addAll(b.metaTargets);
308 } 310 }
309 return new MirrorUsage(symbols, targets, metaTargets, null); 311 return new MirrorUsage(symbols, targets, metaTargets, null);
310 } 312 }
311 313
312 /// Convert a [constant] to an instance of [MirrorUsage] using information 314 /// Convert a [constant] to an instance of [MirrorUsage] using information
313 /// that was resolved during [MirrorUsageAnalyzerTask.validate]. 315 /// that was resolved during [MirrorUsageAnalyzerTask.validate].
314 MirrorUsage buildUsage(ConstructedConstantValue constant) { 316 MirrorUsage buildUsage(ConstructedConstantValue constant) {
315 Map<Element, ConstantValue> fields = constant.fields; 317 Map<Element, ConstantValue> fields = constant.fields;
316 VariableElement symbolsField = 318 ClassElement cls = compiler.commonElements.mirrorsUsedClass;
317 compiler.mirrorsUsedClass.lookupLocalMember('symbols'); 319 VariableElement symbolsField = cls.lookupLocalMember('symbols');
318 VariableElement targetsField = 320 VariableElement targetsField = cls.lookupLocalMember('targets');
319 compiler.mirrorsUsedClass.lookupLocalMember('targets'); 321 VariableElement metaTargetsField = cls.lookupLocalMember('metaTargets');
320 VariableElement metaTargetsField = 322 VariableElement overrideField = cls.lookupLocalMember('override');
321 compiler.mirrorsUsedClass.lookupLocalMember('metaTargets');
322 VariableElement overrideField =
323 compiler.mirrorsUsedClass.lookupLocalMember('override');
324 323
325 return new MirrorUsage( 324 return new MirrorUsage(
326 cachedStrings[fields[symbolsField]], 325 cachedStrings[fields[symbolsField]],
327 cachedElements[fields[targetsField]], 326 cachedElements[fields[targetsField]],
328 cachedElements[fields[metaTargetsField]], 327 cachedElements[fields[metaTargetsField]],
329 cachedElements[fields[overrideField]]); 328 cachedElements[fields[overrideField]]);
330 } 329 }
331 } 330 }
332 331
333 /// Used to represent a resolved MirrorsUsed constant. 332 /// Used to represent a resolved MirrorsUsed constant.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // @MirrorsUsed(targets: fisk) 564 // @MirrorsUsed(targets: fisk)
566 // ^^^^ 565 // ^^^^
567 // 566 //
568 // Instead of saying 'fisk' should pretty print the problematic constant 567 // Instead of saying 'fisk' should pretty print the problematic constant
569 // value. 568 // value.
570 return spannable; 569 return spannable;
571 } 570 }
572 return node; 571 return node;
573 } 572 }
574 } 573 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698