| 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 LocalPlaceholder implements Hashable { |
| 6 final String identifier; |
| 7 final Set<Node> nodes; |
| 8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); |
| 9 int hashCode() => identifier.hashCode(); |
| 10 String toString() => |
| 11 'local_placeholder[id($identifier), nodes($nodes)]'; |
| 12 } |
| 13 |
| 5 class SendVisitor extends ResolvedVisitor { | 14 class SendVisitor extends ResolvedVisitor { |
| 6 final PlaceholderCollector collector; | 15 final PlaceholderCollector collector; |
| 7 | 16 |
| 8 SendVisitor(this.collector, TreeElements elements) : super(elements); | 17 SendVisitor(this.collector, TreeElements elements) : super(elements); |
| 9 | 18 |
| 10 visitSuperSend(Send node) {} | 19 visitSuperSend(Send node) {} |
| 11 visitOperatorSend(Send node) {} | 20 visitOperatorSend(Send node) {} |
| 12 visitForeignSend(Send node) {} | 21 visitForeignSend(Send node) {} |
| 13 | 22 |
| 14 visitClosureSend(Send node) { | 23 visitClosureSend(Send node) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 74 } |
| 66 } | 75 } |
| 67 | 76 |
| 68 tryRenamePrivateSelector(Send node) { | 77 tryRenamePrivateSelector(Send node) { |
| 69 collector.tryMakePrivateIdentifier(node.selector.asIdentifier()); | 78 collector.tryMakePrivateIdentifier(node.selector.asIdentifier()); |
| 70 } | 79 } |
| 71 } | 80 } |
| 72 | 81 |
| 73 class PlaceholderCollector extends AbstractVisitor { | 82 class PlaceholderCollector extends AbstractVisitor { |
| 74 final Compiler compiler; | 83 final Compiler compiler; |
| 75 final Map<Node, Placeholder> placeholders; | 84 final Set<Node> nullNodes; // Nodes that should not be in output. |
| 76 final Map<Element, Map<String, LocalPlaceholder>> localPlaceholders; | 85 final Set<Identifier> unresolvedNodes; |
| 86 final Map<Element, Set<Node>> elementNodes; |
| 87 final Map<FunctionElement, Set<LocalPlaceholder>> localPlaceholders; |
| 88 final Map<LibraryElement, Set<Node>> privateNodes; |
| 89 Map<String, LocalPlaceholder> currentLocalPlaceholders; |
| 77 Element currentElement; | 90 Element currentElement; |
| 78 TreeElements treeElements; | 91 TreeElements treeElements; |
| 79 | 92 |
| 80 PlaceholderCollector(this.compiler) : | 93 PlaceholderCollector(this.compiler) : |
| 81 placeholders = new Map<Node, Placeholder>(), | 94 nullNodes = new Set<Node>(), |
| 82 localPlaceholders = new Map<Element, Map<String, LocalPlaceholder>>(); | 95 unresolvedNodes = new Set<Identifier>(), |
| 96 elementNodes = new Map<Element, Set<Node>>(), |
| 97 localPlaceholders = new Map<FunctionElement, Set<LocalPlaceholder>>(), |
| 98 privateNodes = new Map<LibraryElement, Set<Node>>(); |
| 83 | 99 |
| 84 void collectFunctionDeclarationPlaceholders( | 100 void collectFunctionDeclarationPlaceholders( |
| 85 FunctionElement element, FunctionExpression node) { | 101 FunctionElement element, FunctionExpression node) { |
| 86 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) { | 102 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) { |
| 87 // Two complicated cases for class/interface renaming: | 103 // Two complicated cases for class/interface renaming: |
| 88 // 1) class which implements constructors of other interfaces, but not | 104 // 1) class which implements constructors of other interfaces, but not |
| 89 // implements interfaces themselves: | 105 // implements interfaces themselves: |
| 90 // 0.dart: class C { I(); } | 106 // 0.dart: class C { I(); } |
| 91 // 1.dart and 2.dart: interface I default C { I(); } | 107 // 1.dart and 2.dart: interface I default C { I(); } |
| 92 // now we have to duplicate our I() constructor in C class with | 108 // now we have to duplicate our I() constructor in C class with |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // variable list element twice, better merge this with emitter logic. | 189 // variable list element twice, better merge this with emitter logic. |
| 174 currentElement = (element as VariableElement).variables; | 190 currentElement = (element as VariableElement).variables; |
| 175 elementNode = currentElement.parseNode(compiler); | 191 elementNode = currentElement.parseNode(compiler); |
| 176 collectFieldDeclarationPlaceholders(element, elementNode); | 192 collectFieldDeclarationPlaceholders(element, elementNode); |
| 177 } else if (element is ClassElement || element is TypedefElement) { | 193 } else if (element is ClassElement || element is TypedefElement) { |
| 178 currentElement = element; | 194 currentElement = element; |
| 179 elementNode = currentElement.parseNode(compiler); | 195 elementNode = currentElement.parseNode(compiler); |
| 180 } else { | 196 } else { |
| 181 assert(false); // Unreachable. | 197 assert(false); // Unreachable. |
| 182 } | 198 } |
| 199 currentLocalPlaceholders = new Map<String, LocalPlaceholder>(); |
| 183 compiler.withCurrentElement(element, () { | 200 compiler.withCurrentElement(element, () { |
| 184 elementNode.accept(this); | 201 elementNode.accept(this); |
| 185 }); | 202 }); |
| 186 } | 203 } |
| 187 | 204 |
| 188 Type resolveType(TypeAnnotation typeAnnotation) { | 205 Type resolveType(TypeAnnotation typeAnnotation) { |
| 189 if (treeElements === null) return null; | 206 if (treeElements === null) return null; |
| 190 var result = treeElements.getType(typeAnnotation); | 207 var result = treeElements.getType(typeAnnotation); |
| 191 // TODO: Have better type resolution. | 208 // TODO: Have better type resolution. |
| 192 if (result === null) { | 209 if (result === null) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 207 || (element.isFunction() && !Elements.isStaticOrTopLevel(element))) { | 224 || (element.isFunction() && !Elements.isStaticOrTopLevel(element))) { |
| 208 makeLocalPlaceholder(node); | 225 makeLocalPlaceholder(node); |
| 209 } | 226 } |
| 210 } | 227 } |
| 211 | 228 |
| 212 void makeTypePlaceholder(Node node, Type type) { | 229 void makeTypePlaceholder(Node node, Type type) { |
| 213 makeElementPlaceholder(node, type.element); | 230 makeElementPlaceholder(node, type.element); |
| 214 } | 231 } |
| 215 | 232 |
| 216 void makeNullPlaceholder(Node node) { | 233 void makeNullPlaceholder(Node node) { |
| 217 placeholders[node] = new NullPlaceholder(); | 234 assert(node is Identifier || node is Send); |
| 235 nullNodes.add(node); |
| 218 } | 236 } |
| 219 | 237 |
| 220 void makeElementPlaceholder(Node node, Element element) { | 238 void makeElementPlaceholder(Node node, Element element) { |
| 221 assert(element !== null); | 239 assert(element !== null); |
| 222 placeholders[node] = new ElementPlaceholder(element); | 240 elementNodes.putIfAbsent(element, () => new Set<Node>()).add(node); |
| 223 } | 241 } |
| 224 | 242 |
| 225 void makePrivateIdentifier(Identifier node) { | 243 void makePrivateIdentifier(Identifier node) { |
| 226 assert(node !== null); | 244 assert(node !== null); |
| 227 placeholders[node] = | 245 privateNodes.putIfAbsent( |
| 228 new PrivatePlaceholder(currentElement.getLibrary(), node); | 246 currentElement.getLibrary(), () => new Set<Node>()).add(node); |
| 229 } | 247 } |
| 230 | 248 |
| 231 void makeUnresolvedPlaceholder(Node node) { | 249 void makeUnresolvedPlaceholder(Node node) { |
| 232 placeholders[node] = const UnresolvedPlaceholder(); | 250 unresolvedNodes.add(node); |
| 233 } | 251 } |
| 234 | 252 |
| 235 void makeLocalPlaceholder(Node node) { | 253 void makeLocalPlaceholder(Node node) { |
| 236 assert(currentElement is FunctionElement); | 254 assert(currentElement is FunctionElement); |
| 237 assert(node is Identifier); | 255 assert(node is Identifier); |
| 238 Map<String, LocalPlaceholder> functionLocals = | |
| 239 localPlaceholders.putIfAbsent(currentElement, | |
| 240 () => <LocalPlaceholder>{}); | |
| 241 String identifier = node.asIdentifier().source.slowToString(); | 256 String identifier = node.asIdentifier().source.slowToString(); |
| 242 LocalPlaceholder localPlaceholder = | 257 LocalPlaceholder localPlaceholder = |
| 243 functionLocals.putIfAbsent(identifier, | 258 currentLocalPlaceholders.putIfAbsent(identifier, |
| 244 () => new LocalPlaceholder(currentElement, identifier)); | 259 () { |
| 245 placeholders[node] = localPlaceholder; | 260 LocalPlaceholder localPlaceholder = |
| 261 new LocalPlaceholder(identifier); |
| 262 localPlaceholders.putIfAbsent(currentElement, |
| 263 () => new Set<LocalPlaceholder>()).add(localPlaceholder); |
| 264 return localPlaceholder; |
| 265 }); |
| 246 } | 266 } |
| 247 | 267 |
| 248 void internalError(String reason, [Node node]) { | 268 void internalError(String reason, [Node node]) { |
| 249 compiler.cancel(reason: reason, node: node); | 269 compiler.cancel(reason: reason, node: node); |
| 250 } | 270 } |
| 251 | 271 |
| 252 visit(Node node) => (node === null) ? null : node.accept(this); | 272 visit(Node node) => (node === null) ? null : node.accept(this); |
| 253 | 273 |
| 254 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. | 274 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. |
| 255 | 275 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 if (element is FunctionElement && element !== currentElement) { | 390 if (element is FunctionElement && element !== currentElement) { |
| 371 if (node.name !== null) { | 391 if (node.name !== null) { |
| 372 assert(node.name is Identifier); | 392 assert(node.name is Identifier); |
| 373 tryMakeLocalPlaceholder(element, node.name); | 393 tryMakeLocalPlaceholder(element, node.name); |
| 374 } | 394 } |
| 375 } | 395 } |
| 376 } | 396 } |
| 377 node.visitChildren(this); | 397 node.visitChildren(this); |
| 378 } | 398 } |
| 379 } | 399 } |
| OLD | NEW |