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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 Element currentElement; | 98 Element currentElement; |
| 99 TreeElements treeElements; | 99 TreeElements treeElements; |
| 100 | 100 |
| 101 PlaceholderCollector(this.compiler) : | 101 PlaceholderCollector(this.compiler) : |
| 102 nullNodes = new Set<Node>(), | 102 nullNodes = new Set<Node>(), |
| 103 unresolvedNodes = new Set<Identifier>(), | 103 unresolvedNodes = new Set<Identifier>(), |
| 104 elementNodes = new Map<Element, Set<Node>>(), | 104 elementNodes = new Map<Element, Set<Node>>(), |
| 105 localPlaceholders = new Map<FunctionElement, Set<LocalPlaceholder>>(), | 105 localPlaceholders = new Map<FunctionElement, Set<LocalPlaceholder>>(), |
| 106 privateNodes = new Map<LibraryElement, Set<Identifier>>(); | 106 privateNodes = new Map<LibraryElement, Set<Identifier>>(); |
| 107 | 107 |
| 108 void renameConstructorName(Node nameNode, ClassElement element) { | |
|
Anton Muhin
2012/08/21 11:18:42
rename/name sounds a big ugly, maybe something lik
Roman
2012/08/21 11:23:40
Renamed to tryMakeConstructorNamePlaceholder
| |
| 109 if (nameNode is Send) nameNode = nameNode.receiver; | |
| 110 if (nameNode.asIdentifier().token.slowToString() | |
| 111 == element.name.slowToString()) { | |
| 112 makeElementPlaceholder(nameNode, element); | |
| 113 } | |
| 114 } | |
| 115 | |
| 108 void collectFunctionDeclarationPlaceholders( | 116 void collectFunctionDeclarationPlaceholders( |
| 109 FunctionElement element, FunctionExpression node) { | 117 FunctionElement element, FunctionExpression node) { |
| 110 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) { | 118 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) { |
| 111 // Two complicated cases for class/interface renaming: | 119 // Two complicated cases for class/interface renaming: |
| 112 // 1) class which implements constructors of other interfaces, but not | 120 // 1) class which implements constructors of other interfaces, but not |
| 113 // implements interfaces themselves: | 121 // implements interfaces themselves: |
| 114 // 0.dart: class C { I(); } | 122 // 0.dart: class C { I(); } |
| 115 // 1.dart and 2.dart: interface I default C { I(); } | 123 // 1.dart and 2.dart: interface I default C { I(); } |
| 116 // now we have to duplicate our I() constructor in C class with | 124 // now we have to duplicate our I() constructor in C class with |
| 117 // proper names. | 125 // proper names. |
| 118 // 2) (even worse for us): | 126 // 2) (even worse for us): |
| 119 // 0.dart: class C { C(); } | 127 // 0.dart: class C { C(); } |
| 120 // 1.dart: interface C default p0.C { C(); } | 128 // 1.dart: interface C default p0.C { C(); } |
| 121 // the second case is just a bug now. | 129 // the second case is just a bug now. |
| 122 final enclosingClass = element.getEnclosingClass(); | 130 renameConstructorName(node.name, element.getEnclosingClass()); |
| 123 Node nameNode = node.name; | 131 |
| 124 if (nameNode is Send) nameNode = nameNode.receiver; | 132 // If we have interface constructor, make sure that we put placeholder |
| 125 // For cases like class C implements I { I(); } | 133 // for its default factory implementation. |
| 126 if (nameNode.asIdentifier().token.slowToString() | 134 // Example: |
| 127 == enclosingClass.name.slowToString()) { | 135 // interface I default C { I();} |
| 128 makeTypePlaceholder(nameNode, enclosingClass.type); | 136 // class C { factory I() {} } |
| 137 // 2 cases: | |
| 138 // Plain interface name. Rename it unless it is the default | |
| 139 // constructor for enclosing class. | |
| 140 // Example: | |
| 141 // interface I { I(); } | |
| 142 // class C implements I { C(); } don't rename this case. | |
| 143 // OR I.named() inside C, rename first part. | |
| 144 if (element.defaultImplementation !== null | |
| 145 && element.defaultImplementation !== element) { | |
| 146 FunctionElement implementingFactory = element.defaultImplementation; | |
| 147 renameConstructorName(implementingFactory.cachedNode.name, | |
|
Anton Muhin
2012/08/21 11:18:42
maybe move .name into renameConsturctorName--it's
Roman
2012/08/21 11:23:40
Done.
| |
| 148 element.getEnclosingClass()); | |
| 129 } | 149 } |
| 150 | |
| 130 // Process Ctor(this._field) correctly. | 151 // Process Ctor(this._field) correctly. |
| 131 for (Node parameter in node.parameters) { | 152 for (Node parameter in node.parameters) { |
| 132 VariableDefinitions definitions = parameter.asVariableDefinitions(); | 153 VariableDefinitions definitions = parameter.asVariableDefinitions(); |
| 133 if (definitions !== null) { | 154 if (definitions !== null) { |
| 134 for (Node definition in definitions.definitions) { | 155 for (Node definition in definitions.definitions) { |
| 135 Send send = definition.asSend(); | 156 Send send = definition.asSend(); |
| 136 if (send !== null) { | 157 if (send !== null) { |
| 137 assert(send.receiver is Identifier); | 158 assert(send.receiver is Identifier); |
| 138 assert(send.receiver.asIdentifier().isThis()); | 159 assert(send.receiver.asIdentifier().isThis()); |
| 139 if (send.selector is Identifier) { | 160 if (send.selector is Identifier) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 visit(node.defaultClause.typeArguments); | 444 visit(node.defaultClause.typeArguments); |
| 424 } | 445 } |
| 425 } | 446 } |
| 426 | 447 |
| 427 visitTypedef(Typedef node) { | 448 visitTypedef(Typedef node) { |
| 428 assert(currentElement is TypedefElement); | 449 assert(currentElement is TypedefElement); |
| 429 makeElementPlaceholder(node.name, currentElement); | 450 makeElementPlaceholder(node.name, currentElement); |
| 430 node.visitChildren(this); | 451 node.visitChildren(this); |
| 431 } | 452 } |
| 432 } | 453 } |
| OLD | NEW |