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 Enqueuer codegen; | 8 final Enqueuer codegen; |
9 final Enqueuer resolution; | 9 final Enqueuer resolution; |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... | |
22 } | 22 } |
23 | 23 |
24 class Enqueuer { | 24 class Enqueuer { |
25 final String name; | 25 final String name; |
26 final Compiler compiler; // TODO(ahe): Remove this dependency. | 26 final Compiler compiler; // TODO(ahe): Remove this dependency. |
27 final Function itemCompilationContextCreator; | 27 final Function itemCompilationContextCreator; |
28 final Map<String, Link<Element>> instanceMembersByName; | 28 final Map<String, Link<Element>> instanceMembersByName; |
29 final Set<ClassElement> seenClasses; | 29 final Set<ClassElement> seenClasses; |
30 final Universe universe; | 30 final Universe universe; |
31 final Queue<WorkItem> queue; | 31 final Queue<WorkItem> queue; |
32 final Map<SourceString, List<Element>> interceptedElements; | |
ahe
2012/11/12 13:24:11
Backend specific?
ngeoffray
2012/11/13 11:45:16
Done.
| |
32 | 33 |
33 /** | 34 /** |
34 * Map from declaration elements to the [TreeElements] object holding the | 35 * Map from declaration elements to the [TreeElements] object holding the |
35 * resolution mapping for the element implementation. | 36 * resolution mapping for the element implementation. |
36 * | 37 * |
37 * Invariant: Key elements are declaration elements. | 38 * Invariant: Key elements are declaration elements. |
38 */ | 39 */ |
39 final Map<Element, TreeElements> resolvedElements; | 40 final Map<Element, TreeElements> resolvedElements; |
40 | 41 |
41 bool queueIsClosed = false; | 42 bool queueIsClosed = false; |
42 EnqueueTask task; | 43 EnqueueTask task; |
43 | 44 |
44 Enqueuer(this.name, this.compiler, | 45 Enqueuer(this.name, this.compiler, |
45 ItemCompilationContext itemCompilationContextCreator()) | 46 ItemCompilationContext itemCompilationContextCreator()) |
46 : this.itemCompilationContextCreator = itemCompilationContextCreator, | 47 : this.itemCompilationContextCreator = itemCompilationContextCreator, |
47 instanceMembersByName = new Map<String, Link<Element>>(), | 48 instanceMembersByName = new Map<String, Link<Element>>(), |
48 seenClasses = new Set<ClassElement>(), | 49 seenClasses = new Set<ClassElement>(), |
49 universe = new Universe(), | 50 universe = new Universe(), |
50 queue = new Queue<WorkItem>(), | 51 queue = new Queue<WorkItem>(), |
52 interceptedElements = new Map<SourceString, List<Element>>(), | |
51 resolvedElements = new Map<Element, TreeElements>(); | 53 resolvedElements = new Map<Element, TreeElements>(); |
52 | 54 |
53 bool get isResolutionQueue => identical(compiler.enqueuer.resolution, this); | 55 bool get isResolutionQueue => identical(compiler.enqueuer.resolution, this); |
54 | 56 |
55 TreeElements getCachedElements(Element element) { | 57 TreeElements getCachedElements(Element element) { |
56 // TODO(ngeoffray): Get rid of this check. | 58 // TODO(ngeoffray): Get rid of this check. |
57 if (element.enclosingElement.isClosure()) { | 59 if (element.enclosingElement.isClosure()) { |
58 closureMapping.ClosureClassElement cls = element.enclosingElement; | 60 closureMapping.ClosureClassElement cls = element.enclosingElement; |
59 element = cls.methodElement; | 61 element = cls.methodElement; |
60 } | 62 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 if (cls.isInterface()) { | 136 if (cls.isInterface()) { |
135 compiler.internalErrorOnElement( | 137 compiler.internalErrorOnElement( |
136 // Use the current element, as this is where cls is referenced from. | 138 // Use the current element, as this is where cls is referenced from. |
137 compiler.currentElement, | 139 compiler.currentElement, |
138 'Expected a class, but $cls is an interface.'); | 140 'Expected a class, but $cls is an interface.'); |
139 } | 141 } |
140 universe.instantiatedClasses.add(cls); | 142 universe.instantiatedClasses.add(cls); |
141 onRegisterInstantiatedClass(cls); | 143 onRegisterInstantiatedClass(cls); |
142 } | 144 } |
143 | 145 |
146 void registerSpecialInstantiatedClass(ClassElement cls) { | |
147 registerInstantiatedClass(cls); | |
148 cls.forEachMember((_, Element member) { | |
149 List<Element> list = interceptedElements.putIfAbsent( | |
150 member.name, () => new List<Element>()); | |
151 list.add(member); | |
152 }); | |
153 } | |
154 | |
144 bool checkNoEnqueuedInvokedInstanceMethods() { | 155 bool checkNoEnqueuedInvokedInstanceMethods() { |
145 task.measure(() { | 156 task.measure(() { |
146 // Run through the classes and see if we need to compile methods. | 157 // Run through the classes and see if we need to compile methods. |
147 for (ClassElement classElement in universe.instantiatedClasses) { | 158 for (ClassElement classElement in universe.instantiatedClasses) { |
148 for (ClassElement currentClass = classElement; | 159 for (ClassElement currentClass = classElement; |
149 currentClass != null; | 160 currentClass != null; |
150 currentClass = currentClass.superclass) { | 161 currentClass = currentClass.superclass) { |
151 processInstantiatedClass(currentClass); | 162 processInstantiatedClass(currentClass); |
152 } | 163 } |
153 } | 164 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 | 377 |
367 String toString() => 'Enqueuer($name)'; | 378 String toString() => 'Enqueuer($name)'; |
368 | 379 |
369 registerUsedSelector(Selector selector) { | 380 registerUsedSelector(Selector selector) { |
370 Element interceptor = compiler.backend.getInterceptor(selector); | 381 Element interceptor = compiler.backend.getInterceptor(selector); |
371 if (interceptor != null) { | 382 if (interceptor != null) { |
372 registerStaticUse(interceptor); | 383 registerStaticUse(interceptor); |
373 } | 384 } |
374 } | 385 } |
375 } | 386 } |
OLD | NEW |