| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (send !== null) { | 136 if (send !== null) { |
| 137 assert(send.receiver is Identifier); | 137 assert(send.receiver is Identifier); |
| 138 assert(send.receiver.asIdentifier().isThis()); | 138 assert(send.receiver.asIdentifier().isThis()); |
| 139 if (send.selector is Identifier) { | 139 if (send.selector is Identifier) { |
| 140 tryMakePrivateIdentifier(send.selector.asIdentifier()); | 140 tryMakePrivateIdentifier(send.selector.asIdentifier()); |
| 141 } else if (send.selector is FunctionExpression) { | 141 } else if (send.selector is FunctionExpression) { |
| 142 // C(int this.f()) case where f is field of function type. | 142 // C(int this.f()) case where f is field of function type. |
| 143 tryMakePrivateIdentifier( | 143 tryMakePrivateIdentifier( |
| 144 send.selector.asFunctionExpression().name.asIdentifier()); | 144 send.selector.asFunctionExpression().name.asIdentifier()); |
| 145 } else { | 145 } else { |
| 146 internalError('Unreachable case'); | 146 unreachable(); |
| 147 } | 147 } |
| 148 } else { | 148 } else { |
| 149 assert(definition is Identifier | 149 assert(definition is Identifier |
| 150 || definition is FunctionExpression); | 150 || definition is FunctionExpression); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 } else { | 153 } else { |
| 154 assert(parameter is NodeList); | 154 assert(parameter is NodeList); |
| 155 // We don't have to rename privates in optionals. | 155 // We don't have to rename privates in optionals. |
| 156 } | 156 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 173 void collectFieldDeclarationPlaceholders( | 173 void collectFieldDeclarationPlaceholders( |
| 174 Element element, VariableDefinitions node) { | 174 Element element, VariableDefinitions node) { |
| 175 if (element.isInstanceMember()) { | 175 if (element.isInstanceMember()) { |
| 176 for (Node definition in node.definitions) { | 176 for (Node definition in node.definitions) { |
| 177 if (definition is Identifier) { | 177 if (definition is Identifier) { |
| 178 tryMakePrivateIdentifier(definition.asIdentifier()); | 178 tryMakePrivateIdentifier(definition.asIdentifier()); |
| 179 } else if (definition is SendSet) { | 179 } else if (definition is SendSet) { |
| 180 tryMakePrivateIdentifier( | 180 tryMakePrivateIdentifier( |
| 181 definition.asSendSet().selector.asIdentifier()); | 181 definition.asSendSet().selector.asIdentifier()); |
| 182 } else { | 182 } else { |
| 183 internalError('Unreachable case'); | 183 unreachable(); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 } else if (element.isTopLevel()) { | 186 } else if (element.isTopLevel()) { |
| 187 Node fieldNode = element.parseNode(compiler); | 187 Node fieldNode = element.parseNode(compiler); |
| 188 if (fieldNode is Identifier) { | 188 if (fieldNode is Identifier) { |
| 189 makeElementPlaceholder(fieldNode, element); | 189 makeElementPlaceholder(fieldNode, element); |
| 190 } else if (fieldNode is SendSet) { | 190 } else if (fieldNode is SendSet) { |
| 191 makeElementPlaceholder(fieldNode.selector, element); | 191 makeElementPlaceholder(fieldNode.selector, element); |
| 192 } else { | 192 } else { |
| 193 internalError('Unreachable case'); | 193 unreachable(); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 void collect(Element element, TreeElements elements) { | 198 void collect(Element element, TreeElements elements) { |
| 199 treeElements = elements; | 199 treeElements = elements; |
| 200 Node elementNode; | 200 Node elementNode; |
| 201 if (element is FunctionElement) { | 201 if (element is FunctionElement) { |
| 202 currentElement = element; | 202 currentElement = element; |
| 203 elementNode = currentElement.parseNode(compiler); | 203 elementNode = currentElement.parseNode(compiler); |
| 204 collectFunctionDeclarationPlaceholders(element, elementNode); | 204 collectFunctionDeclarationPlaceholders(element, elementNode); |
| 205 } else if (element.isField()) { | 205 } else if (element.isField()) { |
| 206 // TODO(smok): In the future make sure we don't process same | 206 // TODO(smok): In the future make sure we don't process same |
| 207 // variable list element twice, better merge this with emitter logic. | 207 // variable list element twice, better merge this with emitter logic. |
| 208 currentElement = (element as VariableElement).variables; | 208 currentElement = (element as VariableElement).variables; |
| 209 elementNode = currentElement.parseNode(compiler); | 209 elementNode = currentElement.parseNode(compiler); |
| 210 // We don't collect other elements from the same variable lists | 210 // We don't collect other elements from the same variable lists |
| 211 // if they are not used. http://dartbug.com/4536 | 211 // if they are not used. http://dartbug.com/4536 |
| 212 collectFieldDeclarationPlaceholders(element, elementNode); | 212 collectFieldDeclarationPlaceholders(element, elementNode); |
| 213 } else if (element is ClassElement || element is TypedefElement) { | 213 } else if (element is ClassElement || element is TypedefElement) { |
| 214 currentElement = element; | 214 currentElement = element; |
| 215 elementNode = currentElement.parseNode(compiler); | 215 elementNode = currentElement.parseNode(compiler); |
| 216 } else { | 216 } else { |
| 217 assert(false); // Unreachable. | 217 unreachable(); |
| 218 } | 218 } |
| 219 currentLocalPlaceholders = new Map<String, LocalPlaceholder>(); | 219 currentLocalPlaceholders = new Map<String, LocalPlaceholder>(); |
| 220 compiler.withCurrentElement(element, () { | 220 compiler.withCurrentElement(element, () { |
| 221 elementNode.accept(this); | 221 elementNode.accept(this); |
| 222 }); | 222 }); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void tryMakePrivateIdentifier(Identifier identifier) { | 225 void tryMakePrivateIdentifier(Identifier identifier) { |
| 226 if (identifier.source.isPrivate()) makePrivateIdentifier(identifier); | 226 if (identifier.source.isPrivate()) makePrivateIdentifier(identifier); |
| 227 } | 227 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 localPlaceholders.putIfAbsent(currentElement, | 272 localPlaceholders.putIfAbsent(currentElement, |
| 273 () => new Set<LocalPlaceholder>()).add(localPlaceholder); | 273 () => new Set<LocalPlaceholder>()).add(localPlaceholder); |
| 274 return localPlaceholder; | 274 return localPlaceholder; |
| 275 }); | 275 }); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void internalError(String reason, [Node node]) { | 278 void internalError(String reason, [Node node]) { |
| 279 compiler.cancel(reason: reason, node: node); | 279 compiler.cancel(reason: reason, node: node); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void unreachable() { internalError('Unreachable case'); } |
| 283 |
| 282 visit(Node node) => (node === null) ? null : node.accept(this); | 284 visit(Node node) => (node === null) ? null : node.accept(this); |
| 283 | 285 |
| 284 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. | 286 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. |
| 285 | 287 |
| 286 visitSend(Send send) { | 288 visitSend(Send send) { |
| 287 new SendVisitor(this, treeElements).visitSend(send); | 289 new SendVisitor(this, treeElements).visitSend(send); |
| 288 send.visitChildren(this); | 290 send.visitChildren(this); |
| 289 } | 291 } |
| 290 | 292 |
| 291 visitSendSet(SendSet send) { | 293 visitSendSet(SendSet send) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 visit(node.defaultClause.typeArguments); | 415 visit(node.defaultClause.typeArguments); |
| 414 } | 416 } |
| 415 } | 417 } |
| 416 | 418 |
| 417 visitTypedef(Typedef node) { | 419 visitTypedef(Typedef node) { |
| 418 assert(currentElement is TypedefElement); | 420 assert(currentElement is TypedefElement); |
| 419 makeElementPlaceholder(node.name, currentElement); | 421 makeElementPlaceholder(node.name, currentElement); |
| 420 node.visitChildren(this); | 422 node.visitChildren(this); |
| 421 } | 423 } |
| 422 } | 424 } |
| OLD | NEW |