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

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

Issue 1335983004: Add ImportElement and ExportElement (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 3 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 7 import 'common/tasks.dart' show
8 CompilerTask; 8 CompilerTask;
9 import 'compile_time_constants.dart' show 9 import 'compile_time_constants.dart' show
10 ConstantCompiler; 10 ConstantCompiler;
(...skipping 10 matching lines...) Expand all
21 DartType, 21 DartType,
22 InterfaceType, 22 InterfaceType,
23 TypeKind; 23 TypeKind;
24 import 'diagnostics/messages.dart' show 24 import 'diagnostics/messages.dart' show
25 MessageKind; 25 MessageKind;
26 import 'diagnostics/spannable.dart' show 26 import 'diagnostics/spannable.dart' show
27 Spannable; 27 Spannable;
28 import 'elements/elements.dart' show 28 import 'elements/elements.dart' show
29 ClassElement, 29 ClassElement,
30 Element, 30 Element,
31 ImportElement,
31 LibraryElement, 32 LibraryElement,
32 MetadataAnnotation, 33 MetadataAnnotation,
33 ScopeContainerElement, 34 ScopeContainerElement,
34 VariableElement; 35 VariableElement;
35 import 'resolution/tree_elements.dart' show 36 import 'resolution/tree_elements.dart' show
36 TreeElements; 37 TreeElements;
37 import 'tree/tree.dart' show 38 import 'tree/tree.dart' show
38 Import, 39 Import,
39 LibraryTag, 40 LibraryTag,
40 NamedArgument, 41 NamedArgument,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 193 }
193 } 194 }
194 195
195 /// Collect all @MirrorsUsed from all libraries and represent them as 196 /// Collect all @MirrorsUsed from all libraries and represent them as
196 /// [MirrorUsage]. 197 /// [MirrorUsage].
197 Map<LibraryElement, List<MirrorUsage>> collectMirrorsUsedAnnotation() { 198 Map<LibraryElement, List<MirrorUsage>> collectMirrorsUsedAnnotation() {
198 Map<LibraryElement, List<MirrorUsage>> result = 199 Map<LibraryElement, List<MirrorUsage>> result =
199 new Map<LibraryElement, List<MirrorUsage>>(); 200 new Map<LibraryElement, List<MirrorUsage>>();
200 for (LibraryElement library in compiler.libraryLoader.libraries) { 201 for (LibraryElement library in compiler.libraryLoader.libraries) {
201 if (library.isInternalLibrary) continue; 202 if (library.isInternalLibrary) continue;
202 for (LibraryTag tag in library.tags) { 203 for (ImportElement import in library.imports) {
203 Import importTag = tag.asImport();
204 if (importTag == null) continue;
205 compiler.withCurrentElement(library, () { 204 compiler.withCurrentElement(library, () {
206 List<MirrorUsage> usages = 205 List<MirrorUsage> usages =
207 mirrorsUsedOnLibraryTag(library, importTag); 206 mirrorsUsedOnLibraryTag(library, import);
208 if (usages != null) { 207 if (usages != null) {
209 List<MirrorUsage> existing = result[library]; 208 List<MirrorUsage> existing = result[library];
210 if (existing != null) { 209 if (existing != null) {
211 existing.addAll(usages); 210 existing.addAll(usages);
212 } else { 211 } else {
213 result[library] = usages; 212 result[library] = usages;
214 } 213 }
215 } 214 }
216 }); 215 });
217 } 216 }
(...skipping 30 matching lines...) Expand all
248 List<MirrorUsage> overriddenUsages) { 247 List<MirrorUsage> overriddenUsages) {
249 List<MirrorUsage> usages = 248 List<MirrorUsage> usages =
250 usageMap.putIfAbsent(overridden, () => <MirrorUsage>[]); 249 usageMap.putIfAbsent(overridden, () => <MirrorUsage>[]);
251 usages.addAll(overriddenUsages); 250 usages.addAll(overriddenUsages);
252 }); 251 });
253 } 252 }
254 253
255 /// Find @MirrorsUsed annotations on the given import [tag] in [library]. The 254 /// Find @MirrorsUsed annotations on the given import [tag] in [library]. The
256 /// annotations are represented as [MirrorUsage]. 255 /// annotations are represented as [MirrorUsage].
257 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library, 256 List<MirrorUsage> mirrorsUsedOnLibraryTag(LibraryElement library,
258 Import tag) { 257 ImportElement import) {
259 LibraryElement importedLibrary = library.getLibraryFromTag(tag); 258 LibraryElement importedLibrary = import.importedLibrary;
260 if (importedLibrary != compiler.mirrorsLibrary) { 259 if (importedLibrary != compiler.mirrorsLibrary) {
261 return null; 260 return null;
262 } 261 }
263 List<MirrorUsage> result = <MirrorUsage>[]; 262 List<MirrorUsage> result = <MirrorUsage>[];
264 for (MetadataAnnotation metadata in tag.metadata) { 263 for (MetadataAnnotation metadata in import.metadata) {
265 metadata.ensureResolved(compiler); 264 metadata.ensureResolved(compiler);
266 ConstantValue value = 265 ConstantValue value =
267 compiler.constants.getConstantValue(metadata.constant); 266 compiler.constants.getConstantValue(metadata.constant);
268 Element element = value.getType(compiler.coreTypes).element; 267 Element element = value.getType(compiler.coreTypes).element;
269 if (element == compiler.mirrorsUsedClass) { 268 if (element == compiler.mirrorsUsedClass) {
270 result.add(buildUsage(value)); 269 result.add(buildUsage(value));
271 } 270 }
272 } 271 }
273 return result; 272 return result;
274 } 273 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 List<Element> result = <Element>[]; 468 List<Element> result = <Element>[];
470 for (var entry in list) { 469 for (var entry in list) {
471 if (entry is DartType) { 470 if (entry is DartType) {
472 DartType type = entry; 471 DartType type = entry;
473 result.add(type.element); 472 result.add(type.element);
474 } else { 473 } else {
475 String string = entry; 474 String string = entry;
476 LibraryElement libraryCandiate; 475 LibraryElement libraryCandiate;
477 String libraryNameCandiate; 476 String libraryNameCandiate;
478 for (LibraryElement l in compiler.libraryLoader.libraries) { 477 for (LibraryElement l in compiler.libraryLoader.libraries) {
479 if (l.hasLibraryName()) { 478 if (l.hasLibraryName) {
480 String libraryName = l.getLibraryOrScriptName(); 479 String libraryName = l.libraryOrScriptName;
481 if (string == libraryName) { 480 if (string == libraryName) {
482 // Found an exact match. 481 // Found an exact match.
483 libraryCandiate = l; 482 libraryCandiate = l;
484 libraryNameCandiate = libraryName; 483 libraryNameCandiate = libraryName;
485 break; 484 break;
486 } else if (string.startsWith('$libraryName.')) { 485 } else if (string.startsWith('$libraryName.')) {
487 if (libraryNameCandiate == null 486 if (libraryNameCandiate == null
488 || libraryNameCandiate.length < libraryName.length) { 487 || libraryNameCandiate.length < libraryName.length) {
489 // Found a better candiate 488 // Found a better candiate
490 libraryCandiate = l; 489 libraryCandiate = l;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 Element resolveLocalExpression(Element element, List<String> identifiers) { 527 Element resolveLocalExpression(Element element, List<String> identifiers) {
529 Element current = element; 528 Element current = element;
530 for (String identifier in identifiers) { 529 for (String identifier in identifiers) {
531 Element e = findLocalMemberIn(current, identifier); 530 Element e = findLocalMemberIn(current, identifier);
532 if (e == null) { 531 if (e == null) {
533 if (current.isLibrary) { 532 if (current.isLibrary) {
534 LibraryElement library = current; 533 LibraryElement library = current;
535 compiler.reportHint( 534 compiler.reportHint(
536 spannable, MessageKind.MIRRORS_CANNOT_RESOLVE_IN_LIBRARY, 535 spannable, MessageKind.MIRRORS_CANNOT_RESOLVE_IN_LIBRARY,
537 {'name': identifiers[0], 536 {'name': identifiers[0],
538 'library': library.getLibraryOrScriptName()}); 537 'library': library.libraryOrScriptName});
539 } else { 538 } else {
540 compiler.reportHint( 539 compiler.reportHint(
541 spannable, MessageKind.MIRRORS_CANNOT_FIND_IN_ELEMENT, 540 spannable, MessageKind.MIRRORS_CANNOT_FIND_IN_ELEMENT,
542 {'name': identifier, 'element': current.name}); 541 {'name': identifier, 'element': current.name});
543 } 542 }
544 return current; 543 return current;
545 } 544 }
546 current = e; 545 current = e;
547 } 546 }
548 return current; 547 return current;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 // @MirrorsUsed(targets: fisk) 585 // @MirrorsUsed(targets: fisk)
587 // ^^^^ 586 // ^^^^
588 // 587 //
589 // Instead of saying 'fisk' should pretty print the problematic constant 588 // Instead of saying 'fisk' should pretty print the problematic constant
590 // value. 589 // value.
591 return spannable; 590 return spannable;
592 } 591 }
593 return node; 592 return node;
594 } 593 }
595 } 594 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/mirrors/dart2js_mirrors.dart ('k') | pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698