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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/compiler.dart

Issue 21110003: Implement MirrorUsed.targets for libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r25609 and added test. Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * If true, print a warning for each method that was resolved, but not 8 * If true, print a warning for each method that was resolved, but not
9 * compiled. 9 * compiled.
10 */ 10 */
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return classElement == compiler.objectClass; 204 return classElement == compiler.objectClass;
205 } 205 }
206 206
207 void registerStaticUse(Element element, Enqueuer enqueuer) {} 207 void registerStaticUse(Element element, Enqueuer enqueuer) {}
208 208
209 void onLibraryScanned(LibraryElement library, Uri uri) {} 209 void onLibraryScanned(LibraryElement library, Uri uri) {}
210 210
211 void registerMetadataInstantiatedType(DartType type, TreeElements elements) {} 211 void registerMetadataInstantiatedType(DartType type, TreeElements elements) {}
212 void registerMetadataStaticUse(Element element) {} 212 void registerMetadataStaticUse(Element element) {}
213 void registerMetadataGetOfStaticFunction(FunctionElement element) {} 213 void registerMetadataGetOfStaticFunction(FunctionElement element) {}
214
215 void registerMirrorUsage(Set<String> symbols,
Johnni Winther 2013/07/30 11:15:09 Please document.
ahe 2013/07/30 12:05:45 Done.
216 Set<Element> targets,
217 Set<Element> metaTargets) {}
218
219 bool isNeededForReflection(Element element) => false;
Johnni Winther 2013/07/30 11:15:09 Please document. For instance, is [element] only n
ahe 2013/07/30 12:05:45 Done.
214 } 220 }
215 221
216 /** 222 /**
217 * Key class used in [TokenMap] in which the hash code for a token is based 223 * Key class used in [TokenMap] in which the hash code for a token is based
218 * on the [charOffset]. 224 * on the [charOffset].
219 */ 225 */
220 class TokenKey { 226 class TokenKey {
221 final Token token; 227 final Token token;
222 TokenKey(this.token); 228 TokenKey(this.token);
223 int get hashCode => token.charOffset; 229 int get hashCode => token.charOffset;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 CompilerTask measuredTask; 337 CompilerTask measuredTask;
332 Element _currentElement; 338 Element _currentElement;
333 LibraryElement coreLibrary; 339 LibraryElement coreLibrary;
334 LibraryElement isolateLibrary; 340 LibraryElement isolateLibrary;
335 LibraryElement isolateHelperLibrary; 341 LibraryElement isolateHelperLibrary;
336 LibraryElement jsHelperLibrary; 342 LibraryElement jsHelperLibrary;
337 LibraryElement interceptorsLibrary; 343 LibraryElement interceptorsLibrary;
338 LibraryElement foreignLibrary; 344 LibraryElement foreignLibrary;
339 LibraryElement mainApp; 345 LibraryElement mainApp;
340 346
347 /// Initialized when dart:mirrors is loaded.
348 LibraryElement mirrorsLibrary;
349
341 ClassElement objectClass; 350 ClassElement objectClass;
342 ClassElement closureClass; 351 ClassElement closureClass;
343 ClassElement boundClosureClass; 352 ClassElement boundClosureClass;
344 ClassElement dynamicClass; 353 ClassElement dynamicClass;
345 ClassElement boolClass; 354 ClassElement boolClass;
346 ClassElement numClass; 355 ClassElement numClass;
347 ClassElement intClass; 356 ClassElement intClass;
348 ClassElement doubleClass; 357 ClassElement doubleClass;
349 ClassElement stringClass; 358 ClassElement stringClass;
350 ClassElement functionClass; 359 ClassElement functionClass;
351 ClassElement nullClass; 360 ClassElement nullClass;
352 ClassElement listClass; 361 ClassElement listClass;
353 ClassElement typeClass; 362 ClassElement typeClass;
354 ClassElement mapClass; 363 ClassElement mapClass;
355 ClassElement symbolClass; 364 ClassElement symbolClass;
356 ClassElement stackTraceClass; 365 ClassElement stackTraceClass;
357 366
358 // Initialized after mirrorSystemClass has been resolved. 367 // Initialized after mirrorSystemClass has been resolved.
359 FunctionElement symbolConstructor; 368 FunctionElement symbolConstructor;
360 369
361 // Initialized when dart:mirrors is loaded. 370 // Initialized when dart:mirrors is loaded.
362 ClassElement mirrorSystemClass; 371 ClassElement mirrorSystemClass;
363 372
373 // Initialized when dart:mirrors is loaded.
374 ClassElement mirrorsUsedClass;
375
364 // Initialized after mirrorSystemClass has been resolved. 376 // Initialized after mirrorSystemClass has been resolved.
365 FunctionElement mirrorSystemGetNameFunction; 377 FunctionElement mirrorSystemGetNameFunction;
366 378
367 // Initialized when dart:_collection-dev is loaded. 379 // Initialized when dart:_collection-dev is loaded.
368 ClassElement symbolImplementationClass; 380 ClassElement symbolImplementationClass;
369 381
370 // Initialized when symbolImplementationClass has been resolved. 382 // Initialized when symbolImplementationClass has been resolved.
371 FunctionElement symbolValidatedConstructor; 383 FunctionElement symbolValidatedConstructor;
372 384
373 // Initialized when dart:mirrors is loaded. 385 // Initialized when dart:mirrors is loaded.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 ResolverTask resolver; 442 ResolverTask resolver;
431 closureMapping.ClosureTask closureToClassMapper; 443 closureMapping.ClosureTask closureToClassMapper;
432 TypeCheckerTask checker; 444 TypeCheckerTask checker;
433 ti.TypesTask typesTask; 445 ti.TypesTask typesTask;
434 Backend backend; 446 Backend backend;
435 ConstantHandler constantHandler; 447 ConstantHandler constantHandler;
436 ConstantHandler metadataHandler; 448 ConstantHandler metadataHandler;
437 EnqueueTask enqueuer; 449 EnqueueTask enqueuer;
438 CompilerTask fileReadingTask; 450 CompilerTask fileReadingTask;
439 DeferredLoadTask deferredLoadTask; 451 DeferredLoadTask deferredLoadTask;
452 MirrorUsageAnalyzerTask mirrorUsageAnalyzerTask;
440 ContainerTracer containerTracer; 453 ContainerTracer containerTracer;
441 String buildId; 454 String buildId;
442 455
443 static const SourceString MAIN = const SourceString('main'); 456 static const SourceString MAIN = const SourceString('main');
444 static const SourceString CALL_OPERATOR_NAME = const SourceString('call'); 457 static const SourceString CALL_OPERATOR_NAME = const SourceString('call');
445 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); 458 static const SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod');
446 static const int NO_SUCH_METHOD_ARG_COUNT = 1; 459 static const int NO_SUCH_METHOD_ARG_COUNT = 1;
447 static const SourceString CREATE_INVOCATION_MIRROR = 460 static const SourceString CREATE_INVOCATION_MIRROR =
448 const SourceString('createInvocationMirror'); 461 const SourceString('createInvocationMirror');
449 static const SourceString INVOKE_ON = const SourceString('_invokeOn'); 462 static const SourceString INVOKE_ON = const SourceString('_invokeOn');
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 dietParser = new DietParserTask(this), 551 dietParser = new DietParserTask(this),
539 parser = new ParserTask(this), 552 parser = new ParserTask(this),
540 patchParser = new PatchParserTask(this), 553 patchParser = new PatchParserTask(this),
541 resolver = new ResolverTask(this), 554 resolver = new ResolverTask(this),
542 closureToClassMapper = new closureMapping.ClosureTask(this, closureNamer), 555 closureToClassMapper = new closureMapping.ClosureTask(this, closureNamer),
543 checker = new TypeCheckerTask(this), 556 checker = new TypeCheckerTask(this),
544 typesTask = new ti.TypesTask(this), 557 typesTask = new ti.TypesTask(this),
545 containerTracer = new ContainerTracer(this), 558 containerTracer = new ContainerTracer(this),
546 constantHandler = new ConstantHandler(this, backend.constantSystem), 559 constantHandler = new ConstantHandler(this, backend.constantSystem),
547 deferredLoadTask = new DeferredLoadTask(this), 560 deferredLoadTask = new DeferredLoadTask(this),
561 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this),
548 enqueuer = new EnqueueTask(this)]; 562 enqueuer = new EnqueueTask(this)];
549 563
550 tasks.addAll(backend.tasks); 564 tasks.addAll(backend.tasks);
551 metadataHandler = new ConstantHandler( 565 metadataHandler = new ConstantHandler(
552 this, backend.constantSystem, isMetadata: true); 566 this, backend.constantSystem, isMetadata: true);
553 } 567 }
554 568
555 Universe get resolverWorld => enqueuer.resolution.universe; 569 Universe get resolverWorld => enqueuer.resolution.universe;
556 Universe get codegenWorld => enqueuer.codegen.universe; 570 Universe get codegenWorld => enqueuer.codegen.universe;
557 571
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 void onLibraryScanned(LibraryElement library, Uri uri) { 699 void onLibraryScanned(LibraryElement library, Uri uri) {
686 if (dynamicClass != null) { 700 if (dynamicClass != null) {
687 // When loading the built-in libraries, dynamicClass is null. We 701 // When loading the built-in libraries, dynamicClass is null. We
688 // take advantage of this as core imports js_helper and sees [dynamic] 702 // take advantage of this as core imports js_helper and sees [dynamic]
689 // this way. 703 // this way.
690 withCurrentElement(dynamicClass, () { 704 withCurrentElement(dynamicClass, () {
691 library.addToScope(dynamicClass, this); 705 library.addToScope(dynamicClass, this);
692 }); 706 });
693 } 707 }
694 if (uri == new Uri(scheme: 'dart', path: 'mirrors')) { 708 if (uri == new Uri(scheme: 'dart', path: 'mirrors')) {
709 mirrorsLibrary = library;
695 mirrorSystemClass = 710 mirrorSystemClass =
696 findRequiredElement(library, const SourceString('MirrorSystem')); 711 findRequiredElement(library, const SourceString('MirrorSystem'));
712 mirrorsUsedClass =
713 findRequiredElement(library, const SourceString('MirrorsUsed'));
697 } else if (uri == new Uri(scheme: 'dart', path: '_collection-dev')) { 714 } else if (uri == new Uri(scheme: 'dart', path: '_collection-dev')) {
698 symbolImplementationClass = 715 symbolImplementationClass =
699 findRequiredElement(library, const SourceString('Symbol')); 716 findRequiredElement(library, const SourceString('Symbol'));
700 } else if (uri == new Uri(scheme: 'dart', path: 'async')) { 717 } else if (uri == new Uri(scheme: 'dart', path: 'async')) {
701 deferredLibraryClass = 718 deferredLibraryClass =
702 findRequiredElement(library, const SourceString('DeferredLibrary')); 719 findRequiredElement(library, const SourceString('DeferredLibrary'));
703 } 720 }
704 backend.onLibraryScanned(library, uri); 721 backend.onLibraryScanned(library, uri);
705 } 722 }
706 723
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 FunctionSignature parameters = mainMethod.computeSignature(this); 908 FunctionSignature parameters = mainMethod.computeSignature(this);
892 parameters.forEachParameter((Element parameter) { 909 parameters.forEachParameter((Element parameter) {
893 reportError( 910 reportError(
894 parameter, 911 parameter,
895 MessageKind.GENERIC, 912 MessageKind.GENERIC,
896 {'text': 913 {'text':
897 'Error: "${MAIN.slowToString()}" cannot have parameters.'}); 914 'Error: "${MAIN.slowToString()}" cannot have parameters.'});
898 }); 915 });
899 } 916 }
900 917
918 mirrorUsageAnalyzerTask.analyzeUsage(mainApp);
919
901 // In order to see if a library is deferred, we must compute the 920 // In order to see if a library is deferred, we must compute the
902 // compile-time constants that are metadata. This means adding 921 // compile-time constants that are metadata. This means adding
903 // something to the resolution queue. So we cannot wait with 922 // something to the resolution queue. So we cannot wait with
904 // this until after the resolution queue is processed. 923 // this until after the resolution queue is processed.
905 // TODO(ahe): Clean this up, for example, by not enqueueing 924 // TODO(ahe): Clean this up, for example, by not enqueueing
906 // classes only used for metadata. 925 // classes only used for metadata.
907 deferredLoadTask.findDeferredLibraries(mainApp); 926 deferredLoadTask.findDeferredLibraries(mainApp);
908 } 927 }
909 928
910 log('Resolving...'); 929 log('Resolving...');
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 api.Diagnostic.INFO); 1193 api.Diagnostic.INFO);
1175 } 1194 }
1176 1195
1177 void reportHint(Spannable node, MessageKind errorCode, 1196 void reportHint(Spannable node, MessageKind errorCode,
1178 [Map arguments = const {}]) { 1197 [Map arguments = const {}]) {
1179 reportMessage(spanFromSpannable(node), 1198 reportMessage(spanFromSpannable(node),
1180 errorCode.error(arguments), 1199 errorCode.error(arguments),
1181 api.Diagnostic.HINT); 1200 api.Diagnostic.HINT);
1182 } 1201 }
1183 1202
1203 void reportHere(Spannable node, String debugMessage) {
Johnni Winther 2013/07/30 11:15:09 Document that this is for debugging only.
ahe 2013/07/30 12:05:45 Done.
1204 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'});
1205 }
1206
1184 void reportInternalError(Spannable node, String message) { 1207 void reportInternalError(Spannable node, String message) {
1185 reportError( 1208 reportError(
1186 node, MessageKind.GENERIC, {'text': 'Internal Error: $message'}); 1209 node, MessageKind.GENERIC, {'text': 'Internal Error: $message'});
1187 } 1210 }
1188 1211
1189 void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) { 1212 void reportMessage(SourceSpan span, Diagnostic message, api.Diagnostic kind) {
1190 // TODO(ahe): The names Diagnostic and api.Diagnostic are in 1213 // TODO(ahe): The names Diagnostic and api.Diagnostic are in
1191 // conflict. Fix it. 1214 // conflict. Fix it.
1192 reportDiagnostic(span, "$message", kind); 1215 reportDiagnostic(span, "$message", kind);
1193 } 1216 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 1480
1458 void close() {} 1481 void close() {}
1459 1482
1460 toString() => name; 1483 toString() => name;
1461 1484
1462 /// Convenience method for getting an [api.CompilerOutputProvider]. 1485 /// Convenience method for getting an [api.CompilerOutputProvider].
1463 static NullSink outputProvider(String name, String extension) { 1486 static NullSink outputProvider(String name, String extension) {
1464 return new NullSink('$name.$extension'); 1487 return new NullSink('$name.$extension');
1465 } 1488 }
1466 } 1489 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698