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

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

Issue 10836261: dart2dart Preproces placeholders instead of renaming them lazily, (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
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 SendVisitor extends ResolvedVisitor { 5 class SendVisitor extends ResolvedVisitor {
6 final PlaceholderCollector collector; 6 final PlaceholderCollector collector;
7 7
8 SendVisitor(this.collector, TreeElements elements) : super(elements); 8 SendVisitor(this.collector, TreeElements elements) : super(elements);
9 9
10 visitSuperSend(Send node) {} 10 visitSuperSend(Send node) {}
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 } 66 }
67 67
68 tryRenamePrivateSelector(Send node) { 68 tryRenamePrivateSelector(Send node) {
69 collector.tryMakePrivateIdentifier(node.selector.asIdentifier()); 69 collector.tryMakePrivateIdentifier(node.selector.asIdentifier());
70 } 70 }
71 } 71 }
72 72
73 class PlaceholderCollector extends AbstractVisitor { 73 class PlaceholderCollector extends AbstractVisitor {
74 final Compiler compiler; 74 final Compiler compiler;
75 final Map<Node, Placeholder> placeholders; 75 final Map<Element, Map<Node, LocalPlaceholder>> localPlaceholders;
76 final Map<Element, Map<String, LocalPlaceholder>> localPlaceholders; 76 final Map<Node, PrivatePlaceholder> privatePlaceholders;
Anton Muhin 2012/08/15 12:19:30 should those be maps from Nodes to placeholders?
Roman 2012/08/15 12:43:21 I don't understand. How about the following plan?
77 final Map<Node, UnresolvedPlaceholder> unresolvedPlaceholders;
78 final Map<Node, NullPlaceholder> nullPlaceholders;
79 final Map<Node, ElementPlaceholder> elementPlaceholders;
80 Map<String, LocalPlaceholder> currentLocalPlaceholders;
77 Element currentElement; 81 Element currentElement;
78 TreeElements treeElements; 82 TreeElements treeElements;
79 83
80 PlaceholderCollector(this.compiler) : 84 PlaceholderCollector(this.compiler) :
81 placeholders = new Map<Node, Placeholder>(), 85 localPlaceholders = new Map<Element, Map<Node, LocalPlaceholder>>(),
82 localPlaceholders = new Map<Element, Map<String, LocalPlaceholder>>(); 86 privatePlaceholders = new Map<Node, PrivatePlaceholder>(),
87 unresolvedPlaceholders = new Map<Node, UnresolvedPlaceholder>(),
88 nullPlaceholders = new Map<Node, NullPlaceholder>(),
89 elementPlaceholders = new Map<Node, ElementPlaceholder>();
83 90
84 void collectFunctionDeclarationPlaceholders( 91 void collectFunctionDeclarationPlaceholders(
85 FunctionElement element, FunctionExpression node) { 92 FunctionElement element, FunctionExpression node) {
86 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) { 93 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) {
87 // Two complicated cases for class/interface renaming: 94 // Two complicated cases for class/interface renaming:
88 // 1) class which implements constructors of other interfaces, but not 95 // 1) class which implements constructors of other interfaces, but not
89 // implements interfaces themselves: 96 // implements interfaces themselves:
90 // 0.dart: class C { I(); } 97 // 0.dart: class C { I(); }
91 // 1.dart and 2.dart: interface I default C { I(); } 98 // 1.dart and 2.dart: interface I default C { I(); }
92 // now we have to duplicate our I() constructor in C class with 99 // now we have to duplicate our I() constructor in C class with
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // variable list element twice, better merge this with emitter logic. 180 // variable list element twice, better merge this with emitter logic.
174 currentElement = (element as VariableElement).variables; 181 currentElement = (element as VariableElement).variables;
175 elementNode = currentElement.parseNode(compiler); 182 elementNode = currentElement.parseNode(compiler);
176 collectFieldDeclarationPlaceholders(element, elementNode); 183 collectFieldDeclarationPlaceholders(element, elementNode);
177 } else if (element is ClassElement || element is TypedefElement) { 184 } else if (element is ClassElement || element is TypedefElement) {
178 currentElement = element; 185 currentElement = element;
179 elementNode = currentElement.parseNode(compiler); 186 elementNode = currentElement.parseNode(compiler);
180 } else { 187 } else {
181 assert(false); // Unreachable. 188 assert(false); // Unreachable.
182 } 189 }
190 currentLocalPlaceholders = new Map<String, LocalPlaceholder>();
183 compiler.withCurrentElement(element, () { 191 compiler.withCurrentElement(element, () {
184 elementNode.accept(this); 192 elementNode.accept(this);
185 }); 193 });
186 } 194 }
187 195
188 Type resolveType(TypeAnnotation typeAnnotation) { 196 Type resolveType(TypeAnnotation typeAnnotation) {
189 if (treeElements === null) return null; 197 if (treeElements === null) return null;
190 var result = treeElements.getType(typeAnnotation); 198 var result = treeElements.getType(typeAnnotation);
191 // TODO: Have better type resolution. 199 // TODO: Have better type resolution.
192 if (result === null) { 200 if (result === null) {
(...skipping 14 matching lines...) Expand all
207 || (element.isFunction() && !Elements.isStaticOrTopLevel(element))) { 215 || (element.isFunction() && !Elements.isStaticOrTopLevel(element))) {
208 makeLocalPlaceholder(node); 216 makeLocalPlaceholder(node);
209 } 217 }
210 } 218 }
211 219
212 void makeTypePlaceholder(Node node, Type type) { 220 void makeTypePlaceholder(Node node, Type type) {
213 makeElementPlaceholder(node, type.element); 221 makeElementPlaceholder(node, type.element);
214 } 222 }
215 223
216 void makeNullPlaceholder(Node node) { 224 void makeNullPlaceholder(Node node) {
217 placeholders[node] = new NullPlaceholder(); 225 nullPlaceholders[node] = new NullPlaceholder();
218 } 226 }
219 227
220 void makeElementPlaceholder(Node node, Element element) { 228 void makeElementPlaceholder(Node node, Element element) {
221 assert(element !== null); 229 assert(element !== null);
222 placeholders[node] = new ElementPlaceholder(element); 230 elementPlaceholders[node] = new ElementPlaceholder(element);
223 } 231 }
224 232
225 void makePrivateIdentifier(Identifier node) { 233 void makePrivateIdentifier(Identifier node) {
226 assert(node !== null); 234 assert(node !== null);
227 placeholders[node] = 235 privatePlaceholders[node] =
228 new PrivatePlaceholder(currentElement.getLibrary(), node); 236 new PrivatePlaceholder(currentElement.getLibrary(), node);
229 } 237 }
230 238
231 void makeUnresolvedPlaceholder(Node node) { 239 void makeUnresolvedPlaceholder(Node node) {
232 placeholders[node] = const UnresolvedPlaceholder(); 240 unresolvedPlaceholders[node] = const UnresolvedPlaceholder();
233 } 241 }
234 242
235 void makeLocalPlaceholder(Node node) { 243 void makeLocalPlaceholder(Node node) {
236 assert(currentElement is FunctionElement); 244 assert(currentElement is FunctionElement);
237 assert(node is Identifier); 245 assert(node is Identifier);
238 Map<String, LocalPlaceholder> functionLocals =
239 localPlaceholders.putIfAbsent(currentElement,
240 () => <LocalPlaceholder>{});
241 String identifier = node.asIdentifier().source.slowToString(); 246 String identifier = node.asIdentifier().source.slowToString();
242 LocalPlaceholder localPlaceholder = 247 LocalPlaceholder localPlaceholder =
243 functionLocals.putIfAbsent(identifier, 248 currentLocalPlaceholders.putIfAbsent(identifier,
244 () => new LocalPlaceholder(currentElement, identifier)); 249 () => new LocalPlaceholder(currentElement, identifier));
245 placeholders[node] = localPlaceholder;
246 } 250 }
247 251
248 void internalError(String reason, [Node node]) { 252 void internalError(String reason, [Node node]) {
249 compiler.cancel(reason: reason, node: node); 253 compiler.cancel(reason: reason, node: node);
250 } 254 }
251 255
252 visit(Node node) => (node === null) ? null : node.accept(this); 256 visit(Node node) => (node === null) ? null : node.accept(this);
253 257
254 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. 258 visitNode(Node node) { node.visitChildren(this); } // We must go deeper.
255 259
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 if (element is FunctionElement && element !== currentElement) { 374 if (element is FunctionElement && element !== currentElement) {
371 if (node.name !== null) { 375 if (node.name !== null) {
372 assert(node.name is Identifier); 376 assert(node.name is Identifier);
373 tryMakeLocalPlaceholder(element, node.name); 377 tryMakeLocalPlaceholder(element, node.name);
374 } 378 }
375 } 379 }
376 } 380 }
377 node.visitChildren(this); 381 node.visitChildren(this);
378 } 382 }
379 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698