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 { | 5 class LocalPlaceholder { |
| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 collector.internalError(reason, node); | 136 collector.internalError(reason, node); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 class PlaceholderCollector extends Visitor { | 140 class PlaceholderCollector extends Visitor { |
| 141 final Compiler compiler; | 141 final Compiler compiler; |
| 142 final Set<String> fixedMemberNames; // member names which cannot be renamed. | 142 final Set<String> fixedMemberNames; // member names which cannot be renamed. |
| 143 final Map<Element, ElementAst> elementAsts; | 143 final Map<Element, ElementAst> elementAsts; |
| 144 final Set<Node> nullNodes; // Nodes that should not be in output. | 144 final Set<Node> nullNodes; // Nodes that should not be in output. |
| 145 final Set<Identifier> unresolvedNodes; | 145 final Set<Identifier> unresolvedNodes; |
| 146 final Map<Element, Set<Node>> elementNodes; | 146 final Map<Element, Set<Identifier>> elementNodes; |
| 147 final Map<FunctionElement, FunctionScope> functionScopes; | 147 final Map<FunctionElement, FunctionScope> functionScopes; |
| 148 final Map<LibraryElement, Set<Identifier>> privateNodes; | 148 final Map<LibraryElement, Set<Identifier>> privateNodes; |
| 149 final List<DeclarationTypePlaceholder> declarationTypePlaceholders; | 149 final List<DeclarationTypePlaceholder> declarationTypePlaceholders; |
| 150 final Map<String, Set<Identifier>> memberPlaceholders; | 150 final Map<String, Set<Identifier>> memberPlaceholders; |
| 151 Map<String, LocalPlaceholder> currentLocalPlaceholders; | 151 Map<String, LocalPlaceholder> currentLocalPlaceholders; |
| 152 Element currentElement; | 152 Element currentElement; |
| 153 FunctionElement topmostEnclosingFunction; | 153 FunctionElement topmostEnclosingFunction; |
| 154 TreeElements treeElements; | 154 TreeElements treeElements; |
| 155 | 155 |
| 156 LibraryElement get coreLibrary => compiler.coreLibrary; | 156 LibraryElement get coreLibrary => compiler.coreLibrary; |
| 157 FunctionElement get entryFunction => compiler.mainApp.find(Compiler.MAIN); | 157 FunctionElement get entryFunction => compiler.mainApp.find(Compiler.MAIN); |
| 158 | 158 |
| 159 get currentFunctionScope => functionScopes.putIfAbsent( | 159 get currentFunctionScope => functionScopes.putIfAbsent( |
| 160 topmostEnclosingFunction, () => new FunctionScope()); | 160 topmostEnclosingFunction, () => new FunctionScope()); |
| 161 | 161 |
| 162 PlaceholderCollector(this.compiler, this.fixedMemberNames, this.elementAsts) : | 162 PlaceholderCollector(this.compiler, this.fixedMemberNames, this.elementAsts) : |
| 163 nullNodes = new Set<Node>(), | 163 nullNodes = new Set<Node>(), |
| 164 unresolvedNodes = new Set<Identifier>(), | 164 unresolvedNodes = new Set<Identifier>(), |
| 165 elementNodes = new Map<Element, Set<Node>>(), | 165 elementNodes = new Map<Element, Set<Identifier>>(), |
| 166 functionScopes = new Map<FunctionElement, FunctionScope>(), | 166 functionScopes = new Map<FunctionElement, FunctionScope>(), |
| 167 privateNodes = new Map<LibraryElement, Set<Identifier>>(), | 167 privateNodes = new Map<LibraryElement, Set<Identifier>>(), |
| 168 declarationTypePlaceholders = new List<DeclarationTypePlaceholder>(), | 168 declarationTypePlaceholders = new List<DeclarationTypePlaceholder>(), |
| 169 memberPlaceholders = new Map<String, Set<Identifier>>(); | 169 memberPlaceholders = new Map<String, Set<Identifier>>(); |
| 170 | 170 |
| 171 void tryMakeConstructorNamePlaceholder( | 171 void tryMakeConstructorNamePlaceholder( |
| 172 FunctionExpression constructor, ClassElement element) { | 172 FunctionExpression constructor, ClassElement element) { |
| 173 Node nameNode = constructor.name; | 173 Node nameNode = constructor.name; |
| 174 if (nameNode is Send) nameNode = nameNode.receiver; | 174 if (nameNode is Send) nameNode = nameNode.receiver; |
| 175 if (nameNode.asIdentifier().token.slowToString() | 175 if (nameNode.asIdentifier().token.slowToString() |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 assert(node !== null); | 288 assert(node !== null); |
| 289 if (node.source.isPrivate()) return; | 289 if (node.source.isPrivate()) return; |
| 290 if (node is Operator) return; | 290 if (node is Operator) return; |
| 291 final identifier = node.source.slowToString(); | 291 final identifier = node.source.slowToString(); |
| 292 if (fixedMemberNames.contains(identifier)) return; | 292 if (fixedMemberNames.contains(identifier)) return; |
| 293 memberPlaceholders.putIfAbsent( | 293 memberPlaceholders.putIfAbsent( |
| 294 identifier, () => new Set<Identifier>()).add(node); | 294 identifier, () => new Set<Identifier>()).add(node); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void makeTypePlaceholder(Node node, DartType type) { | 297 void makeTypePlaceholder(Node node, DartType type) { |
| 298 if (node is Send) { | |
| 299 // Prefix. | |
| 300 assert(node.receiver is Identifier); | |
| 301 assert(node.selector is Identifier); | |
| 302 makeNullPlaceholder(node.receiver); | |
|
Anton Muhin
2012/10/04 15:34:37
is it okay if we use a name with a prefix from pla
Roman
2012/10/04 16:05:59
We never use existing prefixes in the renamer anyw
Anton Muhin
2012/10/04 16:07:14
Fair.
On 2012/10/04 16:05:59, Roman wrote:
| |
| 303 node = node.selector; | |
| 304 } | |
| 298 makeElementPlaceholder(node, type.element); | 305 makeElementPlaceholder(node, type.element); |
| 299 } | 306 } |
| 300 | 307 |
| 301 void makeOmitDeclarationTypePlaceholder(TypeAnnotation type) { | 308 void makeOmitDeclarationTypePlaceholder(TypeAnnotation type) { |
| 302 if (type === null) return; | 309 if (type === null) return; |
| 303 declarationTypePlaceholders.add( | 310 declarationTypePlaceholders.add( |
| 304 new DeclarationTypePlaceholder(type, false)); | 311 new DeclarationTypePlaceholder(type, false)); |
| 305 } | 312 } |
| 306 | 313 |
| 307 void makeVarDeclarationTypePlaceholder(VariableDefinitions node) { | 314 void makeVarDeclarationTypePlaceholder(VariableDefinitions node) { |
| 308 // TODO(smok): Maybe instead of calling this method and | 315 // TODO(smok): Maybe instead of calling this method and |
| 309 // makeDeclaratioTypePlaceholder have type declaration placeholder | 316 // makeDeclaratioTypePlaceholder have type declaration placeholder |
| 310 // collector logic in visitVariableDefinitions when resolver becomes better | 317 // collector logic in visitVariableDefinitions when resolver becomes better |
| 311 // and/or catch syntax changes. | 318 // and/or catch syntax changes. |
| 312 if (node.type === null) return; | 319 if (node.type === null) return; |
| 313 Element definitionElement = treeElements[node.definitions.nodes.head]; | 320 Element definitionElement = treeElements[node.definitions.nodes.head]; |
| 314 bool requiresVar = !node.modifiers.isFinalOrConst(); | 321 bool requiresVar = !node.modifiers.isFinalOrConst(); |
| 315 declarationTypePlaceholders.add( | 322 declarationTypePlaceholders.add( |
| 316 new DeclarationTypePlaceholder(node.type, requiresVar)); | 323 new DeclarationTypePlaceholder(node.type, requiresVar)); |
| 317 } | 324 } |
| 318 | 325 |
| 319 void makeNullPlaceholder(Node node) { | 326 void makeNullPlaceholder(Node node) { |
| 320 assert(node is Identifier || node is Send); | 327 assert(node is Identifier || node is Send); |
| 321 nullNodes.add(node); | 328 nullNodes.add(node); |
| 322 } | 329 } |
| 323 | 330 |
| 324 void makeElementPlaceholder(Node node, Element element) { | 331 void makeElementPlaceholder(Identifier node, Element element) { |
| 325 assert(element !== null); | 332 assert(element !== null); |
| 326 if (element === entryFunction) return; | 333 if (element === entryFunction) return; |
| 327 if (element.getLibrary() === coreLibrary) return; | 334 if (element.getLibrary() === coreLibrary) return; |
| 328 if (element.getLibrary().isPlatformLibrary && !element.isTopLevel()) { | 335 if (element.getLibrary().isPlatformLibrary && !element.isTopLevel()) { |
| 329 return; | 336 return; |
| 330 } | 337 } |
| 331 if (element == compiler.types.dynamicType.element) { | 338 if (element == compiler.types.dynamicType.element) { |
| 332 internalError( | 339 internalError( |
| 333 'Should never make element placeholder for dynamic type element', | 340 'Should never make element placeholder for dynamic type element', |
| 334 node); | 341 node); |
| 335 } | 342 } |
| 336 elementNodes.putIfAbsent(element, () => new Set<Node>()).add(node); | 343 elementNodes.putIfAbsent(element, () => new Set<Identifier>()).add(node); |
| 337 } | 344 } |
| 338 | 345 |
| 339 void makePrivateIdentifier(Identifier node) { | 346 void makePrivateIdentifier(Identifier node) { |
| 340 assert(node !== null); | 347 assert(node !== null); |
| 341 privateNodes.putIfAbsent( | 348 privateNodes.putIfAbsent( |
| 342 currentElement.getLibrary(), () => new Set<Identifier>()).add(node); | 349 currentElement.getLibrary(), () => new Set<Identifier>()).add(node); |
| 343 } | 350 } |
| 344 | 351 |
| 345 void makeUnresolvedPlaceholder(Node node) { | 352 void makeUnresolvedPlaceholder(Node node) { |
| 346 unresolvedNodes.add(node); | 353 unresolvedNodes.add(node); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 // Corner case: dart:core type with a prefix. | 466 // Corner case: dart:core type with a prefix. |
| 460 // Most probably there are some additional problems with | 467 // Most probably there are some additional problems with |
| 461 // coreLibPrefix.topLevels. | 468 // coreLibPrefix.topLevels. |
| 462 Element typeElement = type.element; | 469 Element typeElement = type.element; |
| 463 Element dynamicTypeElement = compiler.types.dynamicType.element; | 470 Element dynamicTypeElement = compiler.types.dynamicType.element; |
| 464 if (hasPrefix && | 471 if (hasPrefix && |
| 465 (typeElement.getLibrary() === coreLibrary || | 472 (typeElement.getLibrary() === coreLibrary || |
| 466 typeElement === dynamicTypeElement)) { | 473 typeElement === dynamicTypeElement)) { |
| 467 makeNullPlaceholder(node.typeName.asSend().receiver); | 474 makeNullPlaceholder(node.typeName.asSend().receiver); |
| 468 } else { | 475 } else { |
| 476 if (hasPrefix) { | |
| 477 assert(node.typeName is Send); | |
| 478 assert(node.typeName.receiver is Identifier); | |
| 479 assert(node.typeName.selector is Identifier); | |
| 480 makeNullPlaceholder(node.typeName.receiver); | |
|
Anton Muhin
2012/10/04 15:34:37
ditto
| |
| 481 } | |
| 469 if (typeElement !== dynamicTypeElement) { | 482 if (typeElement !== dynamicTypeElement) { |
| 470 makeTypePlaceholder(target, type); | 483 makeTypePlaceholder(target, type); |
| 471 } else { | 484 } else { |
| 472 if (!isDynamicType(node)) makeUnresolvedPlaceholder(target); | 485 if (!isDynamicType(node)) makeUnresolvedPlaceholder(target); |
| 473 } | 486 } |
| 474 } | 487 } |
| 475 } | 488 } |
| 476 // Trying to differentiate new A.foo() and lib.A cases. In the latter case | 489 // Trying to differentiate new A.foo() and lib.A cases. In the latter case |
| 477 // we don't want to go deeper into typeName. | 490 // we don't want to go deeper into typeName. |
| 478 if (hasPrefix) { | 491 if (hasPrefix) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 | 630 |
| 618 visitBlock(Block node) { | 631 visitBlock(Block node) { |
| 619 for (Node statement in node.statements.nodes) { | 632 for (Node statement in node.statements.nodes) { |
| 620 if (statement is VariableDefinitions) { | 633 if (statement is VariableDefinitions) { |
| 621 makeVarDeclarationTypePlaceholder(statement); | 634 makeVarDeclarationTypePlaceholder(statement); |
| 622 } | 635 } |
| 623 } | 636 } |
| 624 node.visitChildren(this); | 637 node.visitChildren(this); |
| 625 } | 638 } |
| 626 } | 639 } |
| OLD | NEW |