| OLD | NEW | 
|---|
| 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 class EnqueueTask extends CompilerTask { | 7 class EnqueueTask extends CompilerTask { | 
| 8   final ResolutionEnqueuer resolution; | 8   final ResolutionEnqueuer resolution; | 
| 9   final CodegenEnqueuer codegen; | 9   final CodegenEnqueuer codegen; | 
| 10 | 10 | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 81    * Adds [element] to the work list if it has not already been processed. | 81    * Adds [element] to the work list if it has not already been processed. | 
| 82    * | 82    * | 
| 83    * Returns [:true:] if the [element] should be processed. | 83    * Returns [:true:] if the [element] should be processed. | 
| 84    */ | 84    */ | 
| 85   // TODO(johnniwinther): Change to 'Returns true if the element was added to | 85   // TODO(johnniwinther): Change to 'Returns true if the element was added to | 
| 86   // the work list'? | 86   // the work list'? | 
| 87   bool addElementToWorkList(Element element, [TreeElements elements]); | 87   bool addElementToWorkList(Element element, [TreeElements elements]); | 
| 88 | 88 | 
| 89   void registerInstantiatedType(InterfaceType type) { | 89   void registerInstantiatedType(InterfaceType type) { | 
| 90     universe.instantiatedTypes.add(type); | 90     universe.instantiatedTypes.add(type); | 
| 91     registerInstantiatedClass(type.element); | 91     registerInstantiatedClass(type.element, compiler.globalDependencies); | 
| 92   } | 92   } | 
| 93 | 93 | 
| 94   void registerInstantiatedClass(ClassElement cls) { | 94   void registerInstantiatedClass(ClassElement cls, TreeElements elements) { | 
| 95     if (universe.instantiatedClasses.contains(cls)) return; | 95     if (universe.instantiatedClasses.contains(cls)) return; | 
| 96     if (!cls.isAbstract(compiler)) { | 96     if (!cls.isAbstract(compiler)) { | 
| 97       universe.instantiatedClasses.add(cls); | 97       universe.instantiatedClasses.add(cls); | 
| 98     } | 98     } | 
| 99     onRegisterInstantiatedClass(cls); | 99     onRegisterInstantiatedClass(cls); | 
| 100     compiler.backend.registerInstantiatedClass(cls, this); | 100     compiler.backend.registerInstantiatedClass(cls, this, elements); | 
| 101   } | 101   } | 
| 102 | 102 | 
| 103   bool checkNoEnqueuedInvokedInstanceMethods() { | 103   bool checkNoEnqueuedInvokedInstanceMethods() { | 
| 104     task.measure(() { | 104     task.measure(() { | 
| 105       // Run through the classes and see if we need to compile methods. | 105       // Run through the classes and see if we need to compile methods. | 
| 106       for (ClassElement classElement in universe.instantiatedClasses) { | 106       for (ClassElement classElement in universe.instantiatedClasses) { | 
| 107         for (ClassElement currentClass = classElement; | 107         for (ClassElement currentClass = classElement; | 
| 108              currentClass != null; | 108              currentClass != null; | 
| 109              currentClass = currentClass.superclass) { | 109              currentClass = currentClass.superclass) { | 
| 110           processInstantiatedClass(currentClass); | 110           processInstantiatedClass(currentClass); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 143       } | 143       } | 
| 144       if (universe.hasInvocation(member, compiler)) { | 144       if (universe.hasInvocation(member, compiler)) { | 
| 145         return addToWorkList(member); | 145         return addToWorkList(member); | 
| 146       } | 146       } | 
| 147       // If there is a property access with the same name as a method we | 147       // If there is a property access with the same name as a method we | 
| 148       // need to emit the method. | 148       // need to emit the method. | 
| 149       if (universe.hasInvokedGetter(member, compiler)) { | 149       if (universe.hasInvokedGetter(member, compiler)) { | 
| 150         // We will emit a closure, so make sure the closure class is | 150         // We will emit a closure, so make sure the closure class is | 
| 151         // generated. | 151         // generated. | 
| 152         compiler.closureClass.ensureResolved(compiler); | 152         compiler.closureClass.ensureResolved(compiler); | 
| 153         registerInstantiatedClass(compiler.closureClass); | 153         registerInstantiatedClass(compiler.closureClass, | 
|  | 154                                   compiler.globalDependencies); | 
| 154         return addToWorkList(member); | 155         return addToWorkList(member); | 
| 155       } | 156       } | 
| 156     } else if (member.kind == ElementKind.GETTER) { | 157     } else if (member.kind == ElementKind.GETTER) { | 
| 157       if (universe.hasInvokedGetter(member, compiler)) { | 158       if (universe.hasInvokedGetter(member, compiler)) { | 
| 158         return addToWorkList(member); | 159         return addToWorkList(member); | 
| 159       } | 160       } | 
| 160       // We don't know what selectors the returned closure accepts. If | 161       // We don't know what selectors the returned closure accepts. If | 
| 161       // the set contains any selector we have to assume that it matches. | 162       // the set contains any selector we have to assume that it matches. | 
| 162       if (universe.hasInvocation(member, compiler)) { | 163       if (universe.hasInvocation(member, compiler)) { | 
| 163         return addToWorkList(member); | 164         return addToWorkList(member); | 
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 348   } | 349   } | 
| 349 | 350 | 
| 350   void registerFieldGetter(Element element) { | 351   void registerFieldGetter(Element element) { | 
| 351     universe.fieldGetters.add(element); | 352     universe.fieldGetters.add(element); | 
| 352   } | 353   } | 
| 353 | 354 | 
| 354   void registerFieldSetter(Element element) { | 355   void registerFieldSetter(Element element) { | 
| 355     universe.fieldSetters.add(element); | 356     universe.fieldSetters.add(element); | 
| 356   } | 357   } | 
| 357 | 358 | 
| 358   void registerIsCheck(DartType type) { | 359   void registerIsCheck(DartType type, TreeElements elements) { | 
| 359     // Even in checked mode, type annotations for return type and argument | 360     // Even in checked mode, type annotations for return type and argument | 
| 360     // types do not imply type checks, so there should never be a check | 361     // types do not imply type checks, so there should never be a check | 
| 361     // against the type variable of a typedef. | 362     // against the type variable of a typedef. | 
| 362     assert(type.kind != TypeKind.TYPE_VARIABLE || | 363     assert(type.kind != TypeKind.TYPE_VARIABLE || | 
| 363            !type.element.enclosingElement.isTypedef()); | 364            !type.element.enclosingElement.isTypedef()); | 
| 364     universe.isChecks.add(type); | 365     universe.isChecks.add(type); | 
| 365     compiler.backend.registerIsCheck(type, this); | 366     compiler.backend.registerIsCheck(type, this, elements); | 
| 366   } | 367   } | 
| 367 | 368 | 
| 368   void registerAsCheck(DartType type) { | 369   void registerAsCheck(DartType type) { | 
| 369     registerIsCheck(type); | 370     registerIsCheck(type, compiler.globalDependencies); | 
| 370     compiler.backend.registerAsCheck(type); | 371     compiler.backend.registerAsCheck(type); | 
| 371   } | 372   } | 
| 372 | 373 | 
| 373   void forEach(f(WorkItem work)); | 374   void forEach(f(WorkItem work)); | 
| 374 | 375 | 
| 375   void logSummary(log(message)) { | 376   void logSummary(log(message)) { | 
| 376     _logSpecificSummary(log); | 377     _logSpecificSummary(log); | 
| 377     nativeEnqueuer.logSummary(log); | 378     nativeEnqueuer.logSummary(log); | 
| 378   } | 379   } | 
| 379 | 380 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 405 | 406 | 
| 406   bool isProcessed(Element member) => resolvedElements.containsKey(member); | 407   bool isProcessed(Element member) => resolvedElements.containsKey(member); | 
| 407 | 408 | 
| 408   TreeElements getCachedElements(Element element) { | 409   TreeElements getCachedElements(Element element) { | 
| 409     // TODO(ngeoffray): Get rid of this check. | 410     // TODO(ngeoffray): Get rid of this check. | 
| 410     if (element.enclosingElement.isClosure()) { | 411     if (element.enclosingElement.isClosure()) { | 
| 411       closureMapping.ClosureClassElement cls = element.enclosingElement; | 412       closureMapping.ClosureClassElement cls = element.enclosingElement; | 
| 412       element = cls.methodElement; | 413       element = cls.methodElement; | 
| 413     } | 414     } | 
| 414     Element owner = element.getOutermostEnclosingMemberOrTopLevel(); | 415     Element owner = element.getOutermostEnclosingMemberOrTopLevel(); | 
|  | 416     if (owner == null) { | 
|  | 417       owner = element; | 
|  | 418     } | 
| 415     return resolvedElements[owner.declaration]; | 419     return resolvedElements[owner.declaration]; | 
| 416   } | 420   } | 
| 417 | 421 | 
| 418   /** | 422   /** | 
| 419    * Sets the resolved elements of [element] to [elements], or if [elements] is | 423    * Sets the resolved elements of [element] to [elements], or if [elements] is | 
| 420    * [:null:], to the elements found through [getCachedElements]. | 424    * [:null:], to the elements found through [getCachedElements]. | 
| 421    * | 425    * | 
| 422    * Returns the resolved elements. | 426    * Returns the resolved elements. | 
| 423    */ | 427    */ | 
| 424   TreeElements ensureCachedElements(Element element, TreeElements elements) { | 428   TreeElements ensureCachedElements(Element element, TreeElements elements) { | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 460           enableIsolateSupport(library); | 464           enableIsolateSupport(library); | 
| 461         } | 465         } | 
| 462       } | 466       } | 
| 463     } | 467     } | 
| 464 | 468 | 
| 465     return true; | 469     return true; | 
| 466   } | 470   } | 
| 467 | 471 | 
| 468   void enableIsolateSupport(LibraryElement element) { | 472   void enableIsolateSupport(LibraryElement element) { | 
| 469     compiler.isolateLibrary = element.patch; | 473     compiler.isolateLibrary = element.patch; | 
| 470     addToWorkList( | 474     var startRootIsolate = | 
| 471         compiler.isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE)); | 475         compiler.isolateHelperLibrary.find(Compiler.START_ROOT_ISOLATE); | 
|  | 476     addToWorkList(startRootIsolate); | 
|  | 477     // TODO(ahe): This doesn't seem to be necessary. Why is that? | 
|  | 478     compiler.globalDependencies.registerBackendDependency(startRootIsolate); | 
| 472     addToWorkList(compiler.isolateHelperLibrary.find( | 479     addToWorkList(compiler.isolateHelperLibrary.find( | 
| 473         const SourceString('_currentIsolate'))); | 480         const SourceString('_currentIsolate'))); | 
| 474     addToWorkList(compiler.isolateHelperLibrary.find( | 481     addToWorkList(compiler.isolateHelperLibrary.find( | 
| 475         const SourceString('_callInIsolate'))); | 482         const SourceString('_callInIsolate'))); | 
| 476   } | 483   } | 
| 477 | 484 | 
| 478   void enableNoSuchMethod(Element element) { | 485   void enableNoSuchMethod(Element element) { | 
| 479     if (compiler.enabledNoSuchMethod) return; | 486     if (compiler.enabledNoSuchMethod) return; | 
| 480     if (element.getEnclosingClass() == compiler.objectClass) return; | 487     if (element.getEnclosingClass() == compiler.objectClass) return; | 
| 481     Selector selector = new Selector.noSuchMethod(); | 488     Selector selector = new Selector.noSuchMethod(); | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 536     while(!queue.isEmpty) { | 543     while(!queue.isEmpty) { | 
| 537       // TODO(johnniwinther): Find an optimal process order for codegen. | 544       // TODO(johnniwinther): Find an optimal process order for codegen. | 
| 538       f(queue.removeLast()); | 545       f(queue.removeLast()); | 
| 539     } | 546     } | 
| 540   } | 547   } | 
| 541 | 548 | 
| 542   void _logSpecificSummary(log(message)) { | 549   void _logSpecificSummary(log(message)) { | 
| 543     log('Compiled ${generatedCode.length} methods.'); | 550     log('Compiled ${generatedCode.length} methods.'); | 
| 544   } | 551   } | 
| 545 } | 552 } | 
| OLD | NEW | 
|---|