Chromium Code Reviews| 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 { | 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 } | 126 } |
| 127 | 127 |
| 128 internalError(String reason, [Node node]) { | 128 internalError(String reason, [Node node]) { |
| 129 collector.internalError(reason, node); | 129 collector.internalError(reason, node); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 class PlaceholderCollector extends AbstractVisitor { | 133 class PlaceholderCollector extends AbstractVisitor { |
| 134 final Compiler compiler; | 134 final Compiler compiler; |
| 135 final Set<String> fixedMemberNames; // member names which cannot be renamed. | 135 final Set<String> fixedMemberNames; // member names which cannot be renamed. |
| 136 final Map<Element, ElementAst> elementAsts; | |
| 136 final Set<Node> nullNodes; // Nodes that should not be in output. | 137 final Set<Node> nullNodes; // Nodes that should not be in output. |
| 137 final Set<Identifier> unresolvedNodes; | 138 final Set<Identifier> unresolvedNodes; |
| 138 final Map<Element, Set<Node>> elementNodes; | 139 final Map<Element, Set<Node>> elementNodes; |
| 139 final Map<FunctionElement, FunctionScope> functionScopes; | 140 final Map<FunctionElement, FunctionScope> functionScopes; |
| 140 final Map<LibraryElement, Set<Identifier>> privateNodes; | 141 final Map<LibraryElement, Set<Identifier>> privateNodes; |
| 141 final List<DeclarationTypePlaceholder> declarationTypePlaceholders; | 142 final List<DeclarationTypePlaceholder> declarationTypePlaceholders; |
| 142 final Map<String, Set<Identifier>> memberPlaceholders; | 143 final Map<String, Set<Identifier>> memberPlaceholders; |
| 143 Map<String, LocalPlaceholder> currentLocalPlaceholders; | 144 Map<String, LocalPlaceholder> currentLocalPlaceholders; |
| 144 Element currentElement; | 145 Element currentElement; |
| 145 TreeElements treeElements; | 146 TreeElements treeElements; |
| 146 | 147 |
| 147 LibraryElement get coreLibrary => compiler.coreLibrary; | 148 LibraryElement get coreLibrary => compiler.coreLibrary; |
| 148 FunctionElement get entryFunction => compiler.mainApp.find(Compiler.MAIN); | 149 FunctionElement get entryFunction => compiler.mainApp.find(Compiler.MAIN); |
| 149 | 150 |
| 150 PlaceholderCollector(this.compiler, this.fixedMemberNames) : | 151 PlaceholderCollector(this.compiler, this.fixedMemberNames, this.elementAsts) : |
| 151 nullNodes = new Set<Node>(), | 152 nullNodes = new Set<Node>(), |
| 152 unresolvedNodes = new Set<Identifier>(), | 153 unresolvedNodes = new Set<Identifier>(), |
| 153 elementNodes = new Map<Element, Set<Node>>(), | 154 elementNodes = new Map<Element, Set<Node>>(), |
| 154 functionScopes = new Map<FunctionElement, FunctionScope>(), | 155 functionScopes = new Map<FunctionElement, FunctionScope>(), |
| 155 privateNodes = new Map<LibraryElement, Set<Identifier>>(), | 156 privateNodes = new Map<LibraryElement, Set<Identifier>>(), |
| 156 declarationTypePlaceholders = new List<DeclarationTypePlaceholder>(), | 157 declarationTypePlaceholders = new List<DeclarationTypePlaceholder>(), |
| 157 memberPlaceholders = new Map<String, Set<Identifier>>(); | 158 memberPlaceholders = new Map<String, Set<Identifier>>(); |
| 158 | 159 |
| 159 void tryMakeConstructorNamePlaceholder( | 160 void tryMakeConstructorNamePlaceholder( |
| 160 FunctionExpression constructor, ClassElement element) { | 161 FunctionExpression constructor, ClassElement element) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 190 // 2 cases: | 191 // 2 cases: |
| 191 // Plain interface name. Rename it unless it is the default | 192 // Plain interface name. Rename it unless it is the default |
| 192 // constructor for enclosing class. | 193 // constructor for enclosing class. |
| 193 // Example: | 194 // Example: |
| 194 // interface I { I(); } | 195 // interface I { I(); } |
| 195 // class C implements I { C(); } don't rename this case. | 196 // class C implements I { C(); } don't rename this case. |
| 196 // OR I.named() inside C, rename first part. | 197 // OR I.named() inside C, rename first part. |
| 197 if (element.defaultImplementation !== null | 198 if (element.defaultImplementation !== null |
| 198 && element.defaultImplementation !== element) { | 199 && element.defaultImplementation !== element) { |
| 199 FunctionElement implementingFactory = element.defaultImplementation; | 200 FunctionElement implementingFactory = element.defaultImplementation; |
| 200 tryMakeConstructorNamePlaceholder(implementingFactory.cachedNode, | 201 if (implementingFactory is !SynthesizedConstructorElement) { |
|
Roman
2012/09/07 08:10:56
Why this check? If it fixes something, please add
Anton Muhin
2012/09/07 12:26:07
This is somewhat related as we started to drop syn
| |
| 201 element.getEnclosingClass()); | 202 tryMakeConstructorNamePlaceholder( |
| 203 elementAsts[implementingFactory].ast, | |
| 204 element.getEnclosingClass()); | |
| 205 } | |
| 202 } | 206 } |
| 203 } else if (Elements.isStaticOrTopLevel(element)) { | 207 } else if (Elements.isStaticOrTopLevel(element)) { |
| 204 // Note: this code should only rename private identifiers for class' | 208 // Note: this code should only rename private identifiers for class' |
| 205 // fields/getters/setters/methods. Top-level identifiers are renamed | 209 // fields/getters/setters/methods. Top-level identifiers are renamed |
| 206 // just to escape conflicts and that should be enough as we shouldn't | 210 // just to escape conflicts and that should be enough as we shouldn't |
| 207 // be able to resolve private identifiers for other libraries. | 211 // be able to resolve private identifiers for other libraries. |
| 208 makeElementPlaceholder(node.name, element); | 212 makeElementPlaceholder(node.name, element); |
| 209 } else if (element.isMember()) { | 213 } else if (element.isMember()) { |
| 210 if (node.name is Identifier) { | 214 if (node.name is Identifier) { |
| 211 tryMakeMemberPlaceholder(node.name); | 215 tryMakeMemberPlaceholder(node.name); |
| 212 } else { | 216 } else { |
| 213 assert(node.name.asSend().isOperator); | 217 assert(node.name.asSend().isOperator); |
| 214 } | 218 } |
| 215 } | 219 } |
| 216 } | 220 } |
| 217 | 221 |
| 218 void collectFieldDeclarationPlaceholders(Element element, Node node) { | 222 void collectFieldDeclarationPlaceholders(Element element, Node node) { |
| 219 Identifier name = node is Identifier ? node : node.asSend().selector; | 223 Identifier name = node is Identifier ? node : node.asSend().selector; |
| 220 if (Elements.isStaticOrTopLevel(element)) { | 224 if (Elements.isStaticOrTopLevel(element)) { |
| 221 makeElementPlaceholder(name, element); | 225 makeElementPlaceholder(name, element); |
| 222 } else if (Elements.isInstanceField(element)) { | 226 } else if (Elements.isInstanceField(element)) { |
| 223 tryMakeMemberPlaceholder(name); | 227 tryMakeMemberPlaceholder(name); |
| 224 } | 228 } |
| 225 } | 229 } |
| 226 | 230 |
| 227 void collect(Element element, TreeElements elements) { | 231 void collect(Element element) { |
| 228 treeElements = elements; | 232 this.currentElement = element; |
| 229 currentElement = element; | 233 final ElementAst elementAst = elementAsts[element]; |
| 230 Node elementNode = currentElement.parseNode(compiler); | 234 this.treeElements = elementAst.treeElements; |
| 235 Node elementNode = elementAst.ast; | |
| 231 if (element is FunctionElement) { | 236 if (element is FunctionElement) { |
| 232 collectFunctionDeclarationPlaceholders(element, elementNode); | 237 collectFunctionDeclarationPlaceholders(element, elementNode); |
| 233 } else if (element is VariableListElement) { | 238 } else if (element is VariableListElement) { |
| 234 VariableDefinitions definitions = elementNode; | 239 VariableDefinitions definitions = elementNode; |
| 235 for (Node definition in definitions.definitions) { | 240 for (Node definition in definitions.definitions) { |
| 236 final definitionElement = elements[definition]; | 241 final definitionElement = treeElements[definition]; |
| 237 // definitionElement === null if variable is actually unused. | 242 // definitionElement === null if variable is actually unused. |
| 238 if (definitionElement === null) continue; | 243 if (definitionElement === null) continue; |
| 239 collectFieldDeclarationPlaceholders(definitionElement, definition); | 244 collectFieldDeclarationPlaceholders(definitionElement, definition); |
| 240 } | 245 } |
| 241 makeVarDeclarationTypePlaceholder(definitions); | 246 makeVarDeclarationTypePlaceholder(definitions); |
| 242 } else { | 247 } else { |
| 243 assert(element is ClassElement || element is TypedefElement); | 248 assert(element is ClassElement || element is TypedefElement); |
| 244 } | 249 } |
| 245 currentLocalPlaceholders = new Map<String, LocalPlaceholder>(); | 250 currentLocalPlaceholders = new Map<String, LocalPlaceholder>(); |
| 246 compiler.withCurrentElement(element, () { | 251 compiler.withCurrentElement(element, () { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 | 568 |
| 564 visitBlock(Block node) { | 569 visitBlock(Block node) { |
| 565 for (Node statement in node.statements.nodes) { | 570 for (Node statement in node.statements.nodes) { |
| 566 if (statement is VariableDefinitions) { | 571 if (statement is VariableDefinitions) { |
| 567 makeVarDeclarationTypePlaceholder(statement); | 572 makeVarDeclarationTypePlaceholder(statement); |
| 568 } | 573 } |
| 569 } | 574 } |
| 570 node.visitChildren(this); | 575 node.visitChildren(this); |
| 571 } | 576 } |
| 572 } | 577 } |
| OLD | NEW |