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

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 | tests/compiler/dart2js/unparser_test.dart » ('j') | 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 7
8 Map<Element, TreeElements> get resolvedElements() => 8 Map<Element, TreeElements> get resolvedElements() =>
9 compiler.enqueuer.resolution.resolvedElements; 9 compiler.enqueuer.resolution.resolvedElements;
10 10
(...skipping 20 matching lines...) Expand all
31 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && 31 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 &&
32 !isDartCoreLib(compiler, element.getLibrary()) && 32 !isDartCoreLib(compiler, element.getLibrary()) &&
33 element is !AbstractFieldElement; 33 element is !AbstractFieldElement;
34 34
35 final emptyTreeElements = new TreeElementMapping(); 35 final emptyTreeElements = new TreeElementMapping();
36 36
37 Set<Element> topLevelElements = new Set<Element>(); 37 Set<Element> topLevelElements = new Set<Element>();
38 Map<ClassElement, Set<Element>> classMembers = 38 Map<ClassElement, Set<Element>> classMembers =
39 new Map<ClassElement, Set<Element>>(); 39 new Map<ClassElement, Set<Element>>();
40 40
41 PlaceholderCollector collector = new PlaceholderCollector(compiler); 41 // Build all top level elements to emit and necessary class members.
42 var newTypedefElementCallback, newClassElementCallback; 42 var newTypedefElementCallback, newClassElementCallback;
43 43
44 processElement(element, treeElements) { 44 processElement(element, treeElements) {
45 collector.collect(element, treeElements);
46 new ReferencedElementCollector( 45 new ReferencedElementCollector(
47 compiler, 46 compiler,
48 element, treeElements, 47 element, treeElements,
49 newTypedefElementCallback, newClassElementCallback).collect(); 48 newTypedefElementCallback, newClassElementCallback).collect();
50 } 49 }
51 50
52 addTopLevel(element, treeElements) { 51 addTopLevel(element, treeElements) {
53 if (topLevelElements.contains(element)) return; 52 if (topLevelElements.contains(element)) return;
54 topLevelElements.add(element); 53 topLevelElements.add(element);
55 processElement(element, treeElements); 54 processElement(element, treeElements);
(...skipping 24 matching lines...) Expand all
80 classMembers[enclosingClass].add(element); 79 classMembers[enclosingClass].add(element);
81 processElement(element, treeElements); 80 processElement(element, treeElements);
82 } else { 81 } else {
83 if (!element.isTopLevel()) { 82 if (!element.isTopLevel()) {
84 compiler.cancel(reason: 'Cannot process $element', element: element); 83 compiler.cancel(reason: 'Cannot process $element', element: element);
85 } 84 }
86 addTopLevel(element, treeElements); 85 addTopLevel(element, treeElements);
87 } 86 }
88 }); 87 });
89 88
89 // Create all necessary placeholders.
90 PlaceholderCollector collector = new PlaceholderCollector(compiler);
91 makePlaceholders(element) {
92 TreeElements treeElements = resolvedElements[element];
93 if (treeElements === null) treeElements = emptyTreeElements;
94 collector.collect(element, treeElements);
95 if (element is ClassElement) {
96 classMembers[element].forEach(makePlaceholders);
97 }
98 }
99 topLevelElements.forEach(makePlaceholders);
100
101 // Create renames.
90 Map<Node, String> renames = new Map<Node, String>(); 102 Map<Node, String> renames = new Map<Node, String>();
91 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); 103 Map<LibraryElement, String> imports = new Map<LibraryElement, String>();
92 renamePlaceholders(compiler, collector, renames, imports); 104 renamePlaceholders(compiler, collector, renames, imports);
93 105
94 // Sort elements. 106 // Sort elements.
95 compareElements(e0, e1) { 107 compareElements(e0, e1) {
96 compareBy(x, y, f) => f(x).compareTo(f(y)); 108 compareBy(x, y, f) => f(x).compareTo(f(y));
97 int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString()); 109 int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString());
98 if (result != 0) return result; 110 if (result != 0) return result;
99 return compareBy(e0, e1, (e) => e.position().charOffset); 111 return compareBy(e0, e1, (e) => e.position().charOffset);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (typeElement.isClass()) newClassElementCallback(typeElement); 184 if (typeElement.isClass()) newClassElementCallback(typeElement);
173 typeAnnotation.visitChildren(this); 185 typeAnnotation.visitChildren(this);
174 } 186 }
175 187
176 void collect() { 188 void collect() {
177 compiler.withCurrentElement(rootElement, () { 189 compiler.withCurrentElement(rootElement, () {
178 rootElement.parseNode(compiler).accept(this); 190 rootElement.parseNode(compiler).accept(this);
179 }); 191 });
180 } 192 }
181 } 193 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698