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

Side by Side Diff: lib/compiler/implementation/dart_backend/backend.dart

Issue 10837289: Split collecting and traversing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 class DartBackend extends Backend { 5 class DartBackend extends Backend {
6 final List<CompilerTask> tasks; 6 final List<CompilerTask> tasks;
7 final UnparseValidator unparseValidator; 7 final UnparseValidator unparseValidator;
8 8
9 Map<Element, TreeElements> get resolvedElements() => 9 Map<Element, TreeElements> get resolvedElements() =>
10 compiler.enqueuer.resolution.resolvedElements; 10 compiler.enqueuer.resolution.resolvedElements;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && 44 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 &&
45 !isDartCoreLib(compiler, element.getLibrary()) && 45 !isDartCoreLib(compiler, element.getLibrary()) &&
46 element is !AbstractFieldElement; 46 element is !AbstractFieldElement;
47 47
48 final emptyTreeElements = new TreeElementMapping(); 48 final emptyTreeElements = new TreeElementMapping();
49 49
50 Set<Element> topLevelElements = new Set<Element>(); 50 Set<Element> topLevelElements = new Set<Element>();
51 Map<ClassElement, Set<Element>> classMembers = 51 Map<ClassElement, Set<Element>> classMembers =
52 new Map<ClassElement, Set<Element>>(); 52 new Map<ClassElement, Set<Element>>();
53 53
54 PlaceholderCollector collector = new PlaceholderCollector(compiler); 54 // Build all top level elements to emit and necessary class members.
55 var newTypedefElementCallback, newClassElementCallback; 55 var newTypedefElementCallback, newClassElementCallback;
56 56
57 processElement(element, treeElements) { 57 processElement(element, treeElements) {
58 collector.collect(element, treeElements);
59 new ReferencedElementCollector( 58 new ReferencedElementCollector(
60 compiler, 59 compiler,
61 element, treeElements, 60 element, treeElements,
62 newTypedefElementCallback, newClassElementCallback).collect(); 61 newTypedefElementCallback, newClassElementCallback).collect();
63 } 62 }
64 63
65 addTopLevel(element, treeElements) { 64 addTopLevel(element, treeElements) {
66 if (topLevelElements.contains(element)) return; 65 if (topLevelElements.contains(element)) return;
67 topLevelElements.add(element); 66 topLevelElements.add(element);
68 processElement(element, treeElements); 67 processElement(element, treeElements);
(...skipping 24 matching lines...) Expand all
93 classMembers[enclosingClass].add(element); 92 classMembers[enclosingClass].add(element);
94 processElement(element, treeElements); 93 processElement(element, treeElements);
95 } else { 94 } else {
96 if (!element.isTopLevel()) { 95 if (!element.isTopLevel()) {
97 compiler.cancel(reason: 'Cannot process $element', element: element); 96 compiler.cancel(reason: 'Cannot process $element', element: element);
98 } 97 }
99 addTopLevel(element, treeElements); 98 addTopLevel(element, treeElements);
100 } 99 }
101 }); 100 });
102 101
102 // Create all necessary placeholders.
103 PlaceholderCollector collector = new PlaceholderCollector(compiler);
104 makePlaceholders(element) {
105 TreeElements treeElements = resolvedElements[element];
106 if (treeElements === null) treeElements = emptyTreeElements;
107 collector.collect(element, treeElements);
108 if (element is ClassElement) {
Roman 2012/08/17 08:22:28 I would prefer that class members are explicitly c
Anton Muhin 2012/08/17 08:32:41 I actually started that way, but decided eventuall
Roman 2012/08/17 08:34:24 Probably I'm wrong, but I think that some element
Anton Muhin 2012/08/17 08:38:04 Yes. Now we go over all the member elements and p
109 classMembers[element].forEach(makePlaceholders);
110 }
111 }
112 topLevelElements.forEach(makePlaceholders);
113
114 // Create renames.
103 Map<Node, String> renames = new Map<Node, String>(); 115 Map<Node, String> renames = new Map<Node, String>();
104 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); 116 Map<LibraryElement, String> imports = new Map<LibraryElement, String>();
105 renamePlaceholders(compiler, collector, renames, imports); 117 renamePlaceholders(compiler, collector, renames, imports);
106 118
107 // Sort elements. 119 // Sort elements.
108 compareElements(e0, e1) { 120 compareElements(e0, e1) {
109 compareBy(x, y, f) => f(x).compareTo(f(y)); 121 compareBy(x, y, f) => f(x).compareTo(f(y));
110 int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString()); 122 int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString());
111 if (result != 0) return result; 123 if (result != 0) return result;
112 return compareBy(e0, e1, (e) => e.position().charOffset); 124 return compareBy(e0, e1, (e) => e.position().charOffset);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (typeElement.isClass()) newClassElementCallback(typeElement); 197 if (typeElement.isClass()) newClassElementCallback(typeElement);
186 typeAnnotation.visitChildren(this); 198 typeAnnotation.visitChildren(this);
187 } 199 }
188 200
189 void collect() { 201 void collect() {
190 compiler.withCurrentElement(rootElement, () { 202 compiler.withCurrentElement(rootElement, () {
191 rootElement.parseNode(compiler).accept(this); 203 rootElement.parseNode(compiler).accept(this);
192 }); 204 });
193 } 205 }
194 } 206 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698