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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 * Documentation wanted -- johnniwinther | 54 * Documentation wanted -- johnniwinther |
55 * | 55 * |
56 * Invariant: [element] must be a declaration element. | 56 * Invariant: [element] must be a declaration element. |
57 */ | 57 */ |
58 void addToWorkList(Element element, [TreeElements elements]) { | 58 void addToWorkList(Element element, [TreeElements elements]) { |
59 assert(invariant(element, element.isDeclaration)); | 59 assert(invariant(element, element.isDeclaration)); |
60 if (element.isForeign(compiler)) return; | 60 if (element.isForeign(compiler)) return; |
61 | 61 |
62 if (!addElementToWorkList(element, elements)) return; | 62 if (!addElementToWorkList(element, elements)) return; |
63 | 63 |
64 if (element.isFactoryConstructor()) { | |
65 ClassElement cls = element.getEnclosingClass(); | |
66 // For factories (and instantiations of [List]), the target is abstract. | |
67 // Since we may need the type arguments for constructing the instance, | |
68 // we register the class to be added to the classes needing rti. | |
69 compiler.world.registerUsedFactoriesOfAbstractClasses(cls); | |
70 compiler.backend.registerSetRuntimeType(); | |
ngeoffray
2013/02/27 12:36:28
This (registerSetRuntimeType) should be done elsew
karlklose
2013/02/27 16:11:32
Obsolete.
| |
71 } | |
72 | |
64 // Enable runtime type support if we discover a getter called runtimeType. | 73 // Enable runtime type support if we discover a getter called runtimeType. |
65 // We have to enable runtime type before hitting the codegen, so | 74 // We have to enable runtime type before hitting the codegen, so |
66 // that constructors know whether they need to generate code for | 75 // that constructors know whether they need to generate code for |
67 // runtime type. | 76 // runtime type. |
68 if (element.isGetter() && element.name == Compiler.RUNTIME_TYPE) { | 77 if (element.isGetter() && element.name == Compiler.RUNTIME_TYPE) { |
69 compiler.enabledRuntimeType = true; | 78 compiler.enabledRuntimeType = true; |
70 compiler.backend.registerRuntimeType(); | 79 compiler.backend.registerRuntimeType(); |
71 } else if (element == compiler.functionApplyMethod) { | 80 } else if (element == compiler.functionApplyMethod) { |
72 compiler.enabledFunctionApply = true; | 81 compiler.enabledFunctionApply = true; |
73 } else if (element == compiler.invokeOnMethod) { | 82 } else if (element == compiler.invokeOnMethod) { |
74 compiler.enabledInvokeOn = true; | 83 compiler.enabledInvokeOn = true; |
75 } | 84 } |
76 | 85 |
77 nativeEnqueuer.registerElement(element); | 86 nativeEnqueuer.registerElement(element); |
78 } | 87 } |
79 | 88 |
80 /** | 89 /** |
81 * Adds [element] to the work list if it has not already been processed. | 90 * Adds [element] to the work list if it has not already been processed. |
82 * | 91 * |
83 * Returns [:true:] if the [element] should be processed. | 92 * Returns [:true:] if the [element] should be processed. |
84 */ | 93 */ |
85 // TODO(johnniwinther): Change to 'Returns true if the element was added to | 94 // TODO(johnniwinther): Change to 'Returns true if the element was added to |
86 // the work list'? | 95 // the work list'? |
87 bool addElementToWorkList(Element element, [TreeElements elements]); | 96 bool addElementToWorkList(Element element, [TreeElements elements]); |
88 | 97 |
98 void registerInstantiatedType(InterfaceType type) { | |
99 universe.instantiatedTypes.add(type); | |
100 registerInstantiatedClass(type.element); | |
101 } | |
102 | |
89 void registerInstantiatedClass(ClassElement cls) { | 103 void registerInstantiatedClass(ClassElement cls) { |
90 if (universe.instantiatedClasses.contains(cls)) return; | 104 if (universe.instantiatedClasses.contains(cls)) return; |
91 if (!cls.isAbstract(compiler)) { | 105 if (!cls.isAbstract(compiler)) { |
92 universe.instantiatedClasses.add(cls); | 106 universe.instantiatedClasses.add(cls); |
93 onRegisterInstantiatedClass(cls); | 107 onRegisterInstantiatedClass(cls); |
94 } | 108 } |
95 compiler.backend.registerInstantiatedClass(cls, this); | 109 compiler.backend.registerInstantiatedClass(cls, this); |
96 } | 110 } |
97 | 111 |
98 bool checkNoEnqueuedInvokedInstanceMethods() { | 112 bool checkNoEnqueuedInvokedInstanceMethods() { |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 while(!queue.isEmpty) { | 543 while(!queue.isEmpty) { |
530 // TODO(johnniwinther): Find an optimal process order for codegen. | 544 // TODO(johnniwinther): Find an optimal process order for codegen. |
531 f(queue.removeLast()); | 545 f(queue.removeLast()); |
532 } | 546 } |
533 } | 547 } |
534 | 548 |
535 void _logSpecificSummary(log(message)) { | 549 void _logSpecificSummary(log(message)) { |
536 log('Compiled ${generatedCode.length} methods.'); | 550 log('Compiled ${generatedCode.length} methods.'); |
537 } | 551 } |
538 } | 552 } |
OLD | NEW |