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 class EnqueueTask extends CompilerTask { | 5 class EnqueueTask extends CompilerTask { |
6 final Enqueuer codegen; | 6 final Enqueuer codegen; |
7 final Enqueuer resolution; | 7 final Enqueuer resolution; |
8 | 8 |
9 String get name() => 'Enqueue'; | 9 String get name() => 'Enqueue'; |
10 | 10 |
11 EnqueueTask(Compiler compiler) | 11 EnqueueTask(Compiler compiler) |
12 : codegen = new Enqueuer(compiler), | 12 : codegen = new Enqueuer(compiler), |
13 resolution = new Enqueuer(compiler), | 13 resolution = new Enqueuer(compiler), |
14 super(compiler) { | 14 super(compiler) { |
15 codegen.task = this; | 15 codegen.task = this; |
16 resolution.task = this; | 16 resolution.task = this; |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 class Enqueuer { | 20 class Enqueuer { |
21 final Compiler compiler; // TODO(ahe): Remove this dependency. | 21 final Compiler compiler; // TODO(ahe): Remove this dependency. |
22 final Map<String, Link<Element>> instanceMembersByName; | 22 final Map<String, Link<Element>> instanceMembersByName; |
23 final Set<ClassElement> seenClasses; | 23 final Set<ClassElement> seenClasses; |
24 final Universe universe; | 24 final Universe universe; |
25 final Queue<WorkItem> queue; | 25 final Queue<WorkItem> _queue; |
kasperl
2012/06/12 05:50:12
Why did you have to turn this private?
ahe
2012/06/12 06:22:49
Make public again.
ahe
2012/06/12 10:56:11
Temporary refactoring aid, reverted.
ahe
2012/06/12 10:56:11
Done.
| |
26 final Map<Element, TreeElements> resolvedElements; | |
26 bool queueIsClosed = false; | 27 bool queueIsClosed = false; |
27 EnqueueTask task; | 28 EnqueueTask task; |
28 | 29 |
29 Enqueuer(this.compiler) | 30 Enqueuer(this.compiler) |
30 : instanceMembersByName = new Map<String, Link<Element>>(), | 31 : instanceMembersByName = new Map<String, Link<Element>>(), |
31 seenClasses = new Set<ClassElement>(), | 32 seenClasses = new Set<ClassElement>(), |
32 universe = new Universe(), | 33 universe = new Universe(), |
33 queue = new Queue<WorkItem>(); | 34 _queue = new Queue<WorkItem>(), |
35 resolvedElements = new Map<Element, TreeElements>(); | |
36 | |
37 bool get isFirstQueue() => compiler.enqueuer.resolution === this; | |
38 | |
39 TreeElements getCachedElements(Element element) { | |
40 Element owner = element.getOutermostEnclosingMemberOrTopLevel(); | |
41 return compiler.enqueuer.resolution.resolvedElements[owner]; | |
42 } | |
34 | 43 |
35 void addToWorkList(Element element, [TreeElements elements]) { | 44 void addToWorkList(Element element, [TreeElements elements]) { |
45 // int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION | |
kasperl
2012/06/12 05:50:12
There's a lot of commented out code in this method
ahe
2012/06/12 06:22:49
Remove comments.
ahe
2012/06/12 10:56:11
Done.
ahe
2012/06/12 10:56:11
Done.
| |
46 // | ElementCategory.FACTORY; | |
47 // if (element is AbstractFieldElement) return; | |
48 // if (!element.isAccessor() && (element.kind.category & allowed) == 0) retu rn; | |
49 // if (!element.isParameter() && !element.isTopLevel() && !element.enclosing Element.isClass()) return; | |
50 if (element.isForeign()) return; | |
36 if (queueIsClosed) { | 51 if (queueIsClosed) { |
52 if (isFirstQueue && getCachedElements(element) !== null) return; | |
37 compiler.internalErrorOnElement(element, "Work list is closed."); | 53 compiler.internalErrorOnElement(element, "Work list is closed."); |
38 } | 54 } |
39 if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { | 55 if (!isFirstQueue && element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) { |
40 registerInstantiatedClass(element.enclosingElement); | 56 registerInstantiatedClass(element.enclosingElement); |
41 } | 57 } |
42 queue.add(new WorkItem(element, elements)); | 58 if (elements === null) { |
59 elements = getCachedElements(element); | |
60 if (!isFirstQueue && elements === null) { | |
ahe
2012/06/12 06:22:49
Remove this dead code.
ahe
2012/06/12 10:56:11
Done.
| |
61 if (element.getLibrary() !== compiler.interceptorsLibrary && | |
62 element.getLibrary() !== compiler.jsHelperLibrary) { | |
63 // compiler.internalErrorOnElement(element, 'Unresolved element'); | |
64 } | |
65 } | |
66 } | |
67 _queue.add(new WorkItem(element, elements)); | |
43 } | 68 } |
44 | 69 |
45 void registerInstantiatedClass(ClassElement cls) { | 70 void registerInstantiatedClass(ClassElement cls) { |
71 if (cls.isInterface()) throw '$cls is an interface'; | |
ahe
2012/06/12 06:22:49
Remove this.
ahe
2012/06/12 10:56:11
Turned into an internal error.
| |
46 universe.instantiatedClasses.add(cls); | 72 universe.instantiatedClasses.add(cls); |
47 onRegisterInstantiatedClass(cls); | 73 onRegisterInstantiatedClass(cls); |
48 } | 74 } |
49 | 75 |
50 bool checkNoEnqueuedInvokedInstanceMethods() { | 76 bool checkNoEnqueuedInvokedInstanceMethods() { |
51 task.measure(() { | 77 task.measure(() { |
52 // Run through the classes and see if we need to compile methods. | 78 // Run through the classes and see if we need to compile methods. |
53 for (ClassElement classElement in universe.instantiatedClasses) { | 79 for (ClassElement classElement in universe.instantiatedClasses) { |
54 for (ClassElement currentClass = classElement; | 80 for (ClassElement currentClass = classElement; |
55 currentClass !== null; | 81 currentClass !== null; |
(...skipping 23 matching lines...) Expand all Loading... | |
79 for (Selector selector in invokedSelectors) { | 105 for (Selector selector in invokedSelectors) { |
80 registerDynamicInvocation(Namer.CLOSURE_INVOCATION_NAME, selector); | 106 registerDynamicInvocation(Namer.CLOSURE_INVOCATION_NAME, selector); |
81 } | 107 } |
82 } | 108 } |
83 } | 109 } |
84 }); | 110 }); |
85 } | 111 } |
86 | 112 |
87 void processInstantiatedClassMember(Element member) { | 113 void processInstantiatedClassMember(Element member) { |
88 if (universe.generatedCode.containsKey(member)) return; | 114 if (universe.generatedCode.containsKey(member)) return; |
115 if (resolvedElements[member] !== null) return; | |
89 | 116 |
90 if (!member.isInstanceMember()) return; | 117 if (!member.isInstanceMember()) return; |
91 if (member.isField()) return; | 118 if (member.isField()) return; |
92 | 119 |
93 String memberName = member.name.slowToString(); | 120 String memberName = member.name.slowToString(); |
94 Link<Element> members = instanceMembersByName.putIfAbsent( | 121 Link<Element> members = instanceMembersByName.putIfAbsent( |
95 memberName, () => const EmptyLink<Element>()); | 122 memberName, () => const EmptyLink<Element>()); |
96 instanceMembersByName[memberName] = members.prepend(member); | 123 instanceMembersByName[memberName] = members.prepend(member); |
97 | 124 |
98 if (member.kind === ElementKind.GETTER || | 125 if (member.kind === ElementKind.GETTER || |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 } | 247 } |
221 | 248 |
222 void registerDynamicSetter(SourceString methodName, Selector selector) { | 249 void registerDynamicSetter(SourceString methodName, Selector selector) { |
223 registerSetter(methodName, selector); | 250 registerSetter(methodName, selector); |
224 } | 251 } |
225 | 252 |
226 // TODO(ngeoffray): This should get a type. | 253 // TODO(ngeoffray): This should get a type. |
227 void registerIsCheck(Element element) { | 254 void registerIsCheck(Element element) { |
228 universe.isChecks.add(element); | 255 universe.isChecks.add(element); |
229 } | 256 } |
257 | |
258 void forEach(f(WorkItem work)) { | |
259 while (!_queue.isEmpty()) { | |
260 f(_queue.removeLast()); | |
261 } | |
262 } | |
230 } | 263 } |
OLD | NEW |