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

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

Issue 10870008: dart2dart Rename statics as globals. (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 | lib/compiler/implementation/dart_backend/renamer.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 LocalPlaceholder implements Hashable { 5 class LocalPlaceholder implements Hashable {
6 final String identifier; 6 final String identifier;
7 final Set<Node> nodes; 7 final Set<Node> nodes;
8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); 8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>();
9 int hashCode() => identifier.hashCode(); 9 int hashCode() => identifier.hashCode();
10 String toString() => 10 String toString() =>
(...skipping 14 matching lines...) Expand all
25 final element = elements[node]; 25 final element = elements[node];
26 if (element !== null) { 26 if (element !== null) {
27 collector.tryMakeLocalPlaceholder(element, node.selector); 27 collector.tryMakeLocalPlaceholder(element, node.selector);
28 } 28 }
29 } 29 }
30 30
31 visitGetterSend(Send node) { 31 visitGetterSend(Send node) {
32 final element = elements[node]; 32 final element = elements[node];
33 // element === null means dynamic property access. 33 // element === null means dynamic property access.
34 if (element === null) return; 34 if (element === null) return;
35 // We don't want to rename non top-level element access
36 // unless it's a local variable.
37 if (element.isPrefix()) { 35 if (element.isPrefix()) {
38 // Node is prefix part in case of source 'lib.somesetter = 5;' 36 // Node is prefix part in case of source 'lib.somesetter = 5;'
39 collector.makeNullPlaceholder(node); 37 collector.makeNullPlaceholder(node);
40 return; 38 } else if (Elements.isStaticOrTopLevel(element)) {
39 // Unqualified or prefixed top level or static.
40 collector.makeElementPlaceholder(node.selector, element);
41 } else if (!element.isTopLevel()) { 41 } else if (!element.isTopLevel()) {
42 // May get FunctionExpression here in selector 42 // May get FunctionExpression here in selector
43 // in case of A(int this.f()); 43 // in case of A(int this.f());
44 if (node.selector is Identifier) { 44 if (node.selector is Identifier) {
45 collector.tryMakeLocalPlaceholder(element, node.selector); 45 collector.tryMakeLocalPlaceholder(element, node.selector);
46 } else { 46 } else {
47 assert(node.selector is FunctionExpression); 47 assert(node.selector is FunctionExpression);
48 } 48 }
49 return;
50 }
51 // Unqualified <class> in static invocation, why it's not a type annotation?
52 // Another option would be to process in visitStaticSend, NB:
53 // those elements are not top-level.
54 // OR: unqualified top level.
55 collector.makeElementPlaceholder(node.selector, element);
56 if (node.receiver !== null) {
57 // <lib prefix>.<top level>.
58 collector.makeNullPlaceholder(node.receiver); // Cut library prefix.
59 } 49 }
60 } 50 }
61 51
62 visitStaticSend(Send node) { 52 visitStaticSend(Send node) {
63 final element = elements[node]; 53 final element = elements[node];
64 if (!element.isTopLevel()) return; 54 if (element.isConstructor() || element.isFactoryConstructor()) return;
55 collector.makeElementPlaceholder(node.selector, element);
65 // Another ugly case: <lib prefix>.<top level> is represented as 56 // Another ugly case: <lib prefix>.<top level> is represented as
66 // receiver: lib prefix, selector: top level. 57 // receiver: lib prefix, selector: top level.
67 collector.makeElementPlaceholder(node.selector, element); 58 if (element.isTopLevel() && node.receiver !== null) {
68 if (node.receiver !== null) {
69 assert(elements[node.receiver].isPrefix()); 59 assert(elements[node.receiver].isPrefix());
70 // Hack: putting null into map overrides receiver of original node. 60 // Hack: putting null into map overrides receiver of original node.
71 collector.makeNullPlaceholder(node.receiver); 61 collector.makeNullPlaceholder(node.receiver);
72 } 62 }
73 } 63 }
74 64
75 internalError(String reason, [Node node]) { 65 internalError(String reason, [Node node]) {
76 collector.internalError(reason, node); 66 collector.internalError(reason, node);
77 } 67 }
78 } 68 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Example: 125 // Example:
136 // interface I { I(); } 126 // interface I { I(); }
137 // class C implements I { C(); } don't rename this case. 127 // class C implements I { C(); } don't rename this case.
138 // OR I.named() inside C, rename first part. 128 // OR I.named() inside C, rename first part.
139 if (element.defaultImplementation !== null 129 if (element.defaultImplementation !== null
140 && element.defaultImplementation !== element) { 130 && element.defaultImplementation !== element) {
141 FunctionElement implementingFactory = element.defaultImplementation; 131 FunctionElement implementingFactory = element.defaultImplementation;
142 tryMakeConstructorNamePlaceholder(implementingFactory.cachedNode, 132 tryMakeConstructorNamePlaceholder(implementingFactory.cachedNode,
143 element.getEnclosingClass()); 133 element.getEnclosingClass());
144 } 134 }
145 } else if (element.isTopLevel()) { 135 } else if (Elements.isStaticOrTopLevel(element)) {
146 // Note: this code should only rename private identifiers for class' 136 // Note: this code should only rename private identifiers for class'
147 // fields/getters/setters/methods. Top-level identifiers are renamed 137 // fields/getters/setters/methods. Top-level identifiers are renamed
148 // just to escape conflicts and that should be enough as we shouldn't 138 // just to escape conflicts and that should be enough as we shouldn't
149 // be able to resolve private identifiers for other libraries. 139 // be able to resolve private identifiers for other libraries.
150 makeElementPlaceholder(node.name, element); 140 makeElementPlaceholder(node.name, element);
151 } 141 }
152 } 142 }
153 143
154 void collectFieldDeclarationPlaceholders( 144 void collectFieldDeclarationPlaceholders(
155 Element element, VariableDefinitions node) { 145 Element element, VariableDefinitions node) {
156 if (element.isTopLevel()) { 146 if (Elements.isStaticOrTopLevel(element)) {
157 Node fieldNode = element.parseNode(compiler); 147 Node fieldNode = element.parseNode(compiler);
158 if (fieldNode is Identifier) { 148 if (fieldNode is Identifier) {
159 makeElementPlaceholder(fieldNode, element); 149 makeElementPlaceholder(fieldNode, element);
160 } else if (fieldNode is SendSet) { 150 } else if (fieldNode is SendSet) {
161 makeElementPlaceholder(fieldNode.selector, element); 151 makeElementPlaceholder(fieldNode.selector, element);
162 } else { 152 } else {
163 unreachable(); 153 unreachable();
164 } 154 }
165 } 155 }
166 } 156 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. 249 visitNode(Node node) { node.visitChildren(this); } // We must go deeper.
260 250
261 visitSend(Send send) { 251 visitSend(Send send) {
262 new SendVisitor(this, treeElements).visitSend(send); 252 new SendVisitor(this, treeElements).visitSend(send);
263 send.visitChildren(this); 253 send.visitChildren(this);
264 } 254 }
265 255
266 visitSendSet(SendSet send) { 256 visitSendSet(SendSet send) {
267 final element = treeElements[send]; 257 final element = treeElements[send];
268 if (element !== null) { 258 if (element !== null) {
269 if (element.isTopLevel()) { 259 if (Elements.isStaticOrTopLevel(element)) {
270 assert(element is VariableElement || element.isSetter()); 260 assert(element is VariableElement || element.isSetter());
271 makeElementPlaceholder(send.selector, element); 261 makeElementPlaceholder(send.selector, element);
272 } else { 262 } else {
273 assert(send.selector is Identifier); 263 assert(send.selector is Identifier);
274 tryMakeLocalPlaceholder(element, send.selector); 264 tryMakeLocalPlaceholder(element, send.selector);
275 } 265 }
276 } 266 }
277 send.visitChildren(this); 267 send.visitChildren(this);
278 } 268 }
279 269
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 } 398 }
409 node.visitChildren(this); 399 node.visitChildren(this);
410 } 400 }
411 401
412 visitTypedef(Typedef node) { 402 visitTypedef(Typedef node) {
413 assert(currentElement is TypedefElement); 403 assert(currentElement is TypedefElement);
414 makeElementPlaceholder(node.name, currentElement); 404 makeElementPlaceholder(node.name, currentElement);
415 node.visitChildren(this); 405 node.visitChildren(this);
416 } 406 }
417 } 407 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/dart_backend/renamer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698