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

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

Issue 17315012: Generate less code when importing dart:mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments Created 7 years, 6 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 void registerInstantiatedClass(ClassElement cls, 133 void registerInstantiatedClass(ClassElement cls,
134 Enqueuer enqueuer, 134 Enqueuer enqueuer,
135 TreeElements elements) {} 135 TreeElements elements) {}
136 void registerStringInterpolation(TreeElements elements) {} 136 void registerStringInterpolation(TreeElements elements) {}
137 void registerCatchStatement(Enqueuer enqueuer, 137 void registerCatchStatement(Enqueuer enqueuer,
138 TreeElements elements) {} 138 TreeElements elements) {}
139 void registerWrapException(TreeElements elements) {} 139 void registerWrapException(TreeElements elements) {}
140 void registerThrowExpression(TreeElements elements) {} 140 void registerThrowExpression(TreeElements elements) {}
141 void registerLazyField(TreeElements elements) {} 141 void registerLazyField(TreeElements elements) {}
142 void registerTypeVariableExpression(TreeElements elements) {} 142 void registerTypeVariableExpression(TreeElements elements) {}
143 void registerTypeLiteral(TreeElements elements) {} 143 void registerTypeLiteral(Element element, TreeElements elements) {}
144 void registerStackTraceInCatch(TreeElements elements) {} 144 void registerStackTraceInCatch(TreeElements elements) {}
145 void registerIsCheck(DartType type, 145 void registerIsCheck(DartType type,
146 Enqueuer enqueuer, 146 Enqueuer enqueuer,
147 TreeElements elements) {} 147 TreeElements elements) {}
148 void registerAsCheck(DartType type, TreeElements elements) {} 148 void registerAsCheck(DartType type, TreeElements elements) {}
149 void registerThrowNoSuchMethod(TreeElements elements) {} 149 void registerThrowNoSuchMethod(TreeElements elements) {}
150 void registerThrowRuntimeError(TreeElements elements) {} 150 void registerThrowRuntimeError(TreeElements elements) {}
151 void registerAbstractClassInstantiation(TreeElements elements) {} 151 void registerAbstractClassInstantiation(TreeElements elements) {}
152 void registerFallThroughError(TreeElements elements) {} 152 void registerFallThroughError(TreeElements elements) {}
153 void registerSuperNoSuchMethod(TreeElements elements) {} 153 void registerSuperNoSuchMethod(TreeElements elements) {}
154 void registerConstantMap(TreeElements elements) {} 154 void registerConstantMap(TreeElements elements) {}
155 void registerRuntimeType(TreeElements elements) {} 155 void registerRuntimeType(TreeElements elements) {}
156 156
157 void registerRequiredType(DartType type, Element enclosingElement) {} 157 void registerRequiredType(DartType type, Element enclosingElement) {}
158 void registerClassUsingVariableExpression(ClassElement cls) {} 158 void registerClassUsingVariableExpression(ClassElement cls) {}
159 159
160 void registerConstSymbol(String name, TreeElements elements) {}
161 void registerNewSymbol(TreeElements elements) {}
162
160 bool isNullImplementation(ClassElement cls) { 163 bool isNullImplementation(ClassElement cls) {
161 return cls == compiler.nullClass; 164 return cls == compiler.nullClass;
162 } 165 }
163 ClassElement get intImplementation => compiler.intClass; 166 ClassElement get intImplementation => compiler.intClass;
164 ClassElement get doubleImplementation => compiler.doubleClass; 167 ClassElement get doubleImplementation => compiler.doubleClass;
165 ClassElement get numImplementation => compiler.numClass; 168 ClassElement get numImplementation => compiler.numClass;
166 ClassElement get stringImplementation => compiler.stringClass; 169 ClassElement get stringImplementation => compiler.stringClass;
167 ClassElement get listImplementation => compiler.listClass; 170 ClassElement get listImplementation => compiler.listClass;
168 ClassElement get growableListImplementation => compiler.listClass; 171 ClassElement get growableListImplementation => compiler.listClass;
169 ClassElement get fixedListImplementation => compiler.listClass; 172 ClassElement get fixedListImplementation => compiler.listClass;
170 ClassElement get constListImplementation => compiler.listClass; 173 ClassElement get constListImplementation => compiler.listClass;
171 ClassElement get mapImplementation => compiler.mapClass; 174 ClassElement get mapImplementation => compiler.mapClass;
172 ClassElement get constMapImplementation => compiler.mapClass; 175 ClassElement get constMapImplementation => compiler.mapClass;
173 ClassElement get functionImplementation => compiler.functionClass; 176 ClassElement get functionImplementation => compiler.functionClass;
174 ClassElement get typeImplementation => compiler.typeClass; 177 ClassElement get typeImplementation => compiler.typeClass;
175 ClassElement get boolImplementation => compiler.boolClass; 178 ClassElement get boolImplementation => compiler.boolClass;
176 ClassElement get nullImplementation => compiler.nullClass; 179 ClassElement get nullImplementation => compiler.nullClass;
177 180
178 ClassElement defaultSuperclass(ClassElement element) => compiler.objectClass; 181 ClassElement defaultSuperclass(ClassElement element) => compiler.objectClass;
179 182
180 bool isDefaultNoSuchMethodImplementation(Element element) { 183 bool isDefaultNoSuchMethodImplementation(Element element) {
181 assert(element.name == Compiler.NO_SUCH_METHOD); 184 assert(element.name == Compiler.NO_SUCH_METHOD);
182 ClassElement classElement = element.getEnclosingClass(); 185 ClassElement classElement = element.getEnclosingClass();
183 return classElement == compiler.objectClass; 186 return classElement == compiler.objectClass;
184 } 187 }
185 188
186 void enableMirrors() {} 189 void registerStaticUse(Element element, Enqueuer enqueuer) {}
187 190
188 void registerStaticUse(Element element, Enqueuer enqueuer) {} 191 void onLibraryScanned(LibraryElement library, Uri uri) {}
192
193 void registerMetadataInstantiatedClass(ClassElement element,
194 TreeElements elements) {}
195 void registerMetadataStaticUse(Element element) {}
196 void registerMetadataGetOfStaticFunction(FunctionElement element) {}
189 } 197 }
190 198
191 /** 199 /**
192 * Key class used in [TokenMap] in which the hash code for a token is based 200 * Key class used in [TokenMap] in which the hash code for a token is based
193 * on the [charOffset]. 201 * on the [charOffset].
194 */ 202 */
195 class TokenKey { 203 class TokenKey {
196 final Token token; 204 final Token token;
197 TokenKey(this.token); 205 TokenKey(this.token);
198 int get hashCode => token.charOffset; 206 int get hashCode => token.charOffset;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 tasks.addAll(backend.tasks); 530 tasks.addAll(backend.tasks);
523 metadataHandler = new ConstantHandler( 531 metadataHandler = new ConstantHandler(
524 this, backend.constantSystem, isMetadata: true); 532 this, backend.constantSystem, isMetadata: true);
525 } 533 }
526 534
527 Universe get resolverWorld => enqueuer.resolution.universe; 535 Universe get resolverWorld => enqueuer.resolution.universe;
528 Universe get codegenWorld => enqueuer.codegen.universe; 536 Universe get codegenWorld => enqueuer.codegen.universe;
529 537
530 bool get hasBuildId => buildId != UNDETERMINED_BUILD_ID; 538 bool get hasBuildId => buildId != UNDETERMINED_BUILD_ID;
531 539
532 bool get mirrorsEnabled => mirrorSystemClass != null;
533
534 bool get analyzeAll => analyzeAllFlag || compileAll; 540 bool get analyzeAll => analyzeAllFlag || compileAll;
535 541
536 bool get compileAll => false; 542 bool get compileAll => false;
537 543
538 bool get disableTypeInference { 544 bool get disableTypeInference {
539 return disableTypeInferenceFlag || disableTypeInferenceForMirrors; 545 return disableTypeInferenceFlag || disableTypeInferenceForMirrors;
540 } 546 }
541 547
542 int getNextFreeClassId() => nextFreeClassId++; 548 int getNextFreeClassId() => nextFreeClassId++;
543 549
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 if (dynamicClass != null) { 673 if (dynamicClass != null) {
668 // When loading the built-in libraries, dynamicClass is null. We 674 // When loading the built-in libraries, dynamicClass is null. We
669 // take advantage of this as core imports js_helper and sees [dynamic] 675 // take advantage of this as core imports js_helper and sees [dynamic]
670 // this way. 676 // this way.
671 withCurrentElement(dynamicClass, () { 677 withCurrentElement(dynamicClass, () {
672 library.addToScope(dynamicClass, this); 678 library.addToScope(dynamicClass, this);
673 }); 679 });
674 } 680 }
675 if (uri == Uri.parse('dart:mirrors')) { 681 if (uri == Uri.parse('dart:mirrors')) {
676 mirrorSystemClass = library.find(const SourceString('MirrorSystem')); 682 mirrorSystemClass = library.find(const SourceString('MirrorSystem'));
677 backend.enableMirrors();
678 metadataHandler = constantHandler;
679 } else if (uri == Uri.parse('dart:_collection-dev')) { 683 } else if (uri == Uri.parse('dart:_collection-dev')) {
680 symbolImplementationClass = library.find(const SourceString('Symbol')); 684 symbolImplementationClass = library.find(const SourceString('Symbol'));
681 } 685 }
686 backend.onLibraryScanned(library, uri);
682 } 687 }
683 688
684 void onClassResolved(ClassElement cls) { 689 void onClassResolved(ClassElement cls) {
685 if (mirrorSystemClass == cls) { 690 if (mirrorSystemClass == cls) {
686 mirrorSystemGetNameFunction = 691 mirrorSystemGetNameFunction =
687 cls.lookupLocalMember(const SourceString('getName')); 692 cls.lookupLocalMember(const SourceString('getName'));
688 } else if (symbolClass == cls) { 693 } else if (symbolClass == cls) {
689 symbolConstructor = cls.constructors.head; 694 symbolConstructor = cls.constructors.head;
690 } else if (symbolImplementationClass == cls) { 695 } else if (symbolImplementationClass == cls) {
691 symbolValidatedConstructor = symbolImplementationClass.lookupConstructor( 696 symbolValidatedConstructor = symbolImplementationClass.lookupConstructor(
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 864
860 log('Resolving...'); 865 log('Resolving...');
861 phase = PHASE_RESOLVING; 866 phase = PHASE_RESOLVING;
862 if (analyzeAll) { 867 if (analyzeAll) {
863 libraries.forEach( 868 libraries.forEach(
864 (_, lib) => fullyEnqueueLibrary(lib, enqueuer.resolution)); 869 (_, lib) => fullyEnqueueLibrary(lib, enqueuer.resolution));
865 } 870 }
866 // Elements required by enqueueHelpers are global dependencies 871 // Elements required by enqueueHelpers are global dependencies
867 // that are not pulled in by a particular element. 872 // that are not pulled in by a particular element.
868 backend.enqueueHelpers(enqueuer.resolution, globalDependencies); 873 backend.enqueueHelpers(enqueuer.resolution, globalDependencies);
869 resolveReflectiveDataIfNeeded();
870 processQueue(enqueuer.resolution, main); 874 processQueue(enqueuer.resolution, main);
871 enqueuer.resolution.logSummary(log); 875 enqueuer.resolution.logSummary(log);
872 876
873 if (compilationFailed) return; 877 if (compilationFailed) return;
874 if (analyzeOnly) return; 878 if (analyzeOnly) return;
875 assert(main != null); 879 assert(main != null);
876 phase = PHASE_DONE_RESOLVING; 880 phase = PHASE_DONE_RESOLVING;
877 881
878 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution 882 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution
879 // should know this. 883 // should know this.
(...skipping 25 matching lines...) Expand all
905 processQueue(enqueuer.codegen, main); 909 processQueue(enqueuer.codegen, main);
906 enqueuer.codegen.logSummary(log); 910 enqueuer.codegen.logSummary(log);
907 911
908 if (compilationFailed) return; 912 if (compilationFailed) return;
909 913
910 backend.assembleProgram(); 914 backend.assembleProgram();
911 915
912 checkQueues(); 916 checkQueues();
913 } 917 }
914 918
915 void resolveReflectiveDataIfNeeded() {
916 // Only need reflective data when dart:mirrors is loaded.
917 if (!mirrorsEnabled) return;
918
919 for (LibraryElement library in libraries.values) {
920 for (Link link = library.metadata; !link.isEmpty; link = link.tail) {
921 link.head.ensureResolved(this);
922 }
923 }
924 }
925
926 void fullyEnqueueLibrary(LibraryElement library, Enqueuer world) { 919 void fullyEnqueueLibrary(LibraryElement library, Enqueuer world) {
927 void enqueueAll(Element element) { 920 void enqueueAll(Element element) {
928 fullyEnqueueTopLevelElement(element, world); 921 fullyEnqueueTopLevelElement(element, world);
929 } 922 }
930 library.implementation.forEachLocalMember(enqueueAll); 923 library.implementation.forEachLocalMember(enqueueAll);
931 } 924 }
932 925
933 void fullyEnqueueTopLevelElement(Element element, Enqueuer world) { 926 void fullyEnqueueTopLevelElement(Element element, Enqueuer world) {
934 if (element.isClass()) { 927 if (element.isClass()) {
935 ClassElement cls = element; 928 ClassElement cls = element;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 1407
1415 void close() {} 1408 void close() {}
1416 1409
1417 toString() => name; 1410 toString() => name;
1418 1411
1419 /// Convenience method for getting an [api.CompilerOutputProvider]. 1412 /// Convenience method for getting an [api.CompilerOutputProvider].
1420 static NullSink outputProvider(String name, String extension) { 1413 static NullSink outputProvider(String name, String extension) {
1421 return new NullSink('$name.$extension'); 1414 return new NullSink('$name.$extension');
1422 } 1415 }
1423 } 1416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698