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 SendVisitor extends ResolvedVisitor { | 5 class SendVisitor extends ResolvedVisitor { |
| 6 final PlaceholderCollector collector; | 6 final PlaceholderCollector collector; |
| 7 | 7 |
| 8 SendVisitor(this.collector, TreeElements elements) : super(elements); | 8 SendVisitor(this.collector, TreeElements elements) : super(elements); |
| 9 | 9 |
| 10 visitSuperSend(Send node) {} | 10 visitSuperSend(Send node) {} |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 // variable list element twice, better merge this with emitter logic. | 144 // variable list element twice, better merge this with emitter logic. |
| 145 currentElement = element.variables; | 145 currentElement = element.variables; |
| 146 elementNode = currentElement.parseNode(compiler); | 146 elementNode = currentElement.parseNode(compiler); |
| 147 collectFieldDeclarationPlaceholders(element, elementNode); | 147 collectFieldDeclarationPlaceholders(element, elementNode); |
| 148 } else if (element is ClassElement || element is TypedefElement) { | 148 } else if (element is ClassElement || element is TypedefElement) { |
| 149 currentElement = element; | 149 currentElement = element; |
| 150 elementNode = currentElement.parseNode(compiler); | 150 elementNode = currentElement.parseNode(compiler); |
| 151 } else { | 151 } else { |
| 152 assert(false); // Unreachable. | 152 assert(false); // Unreachable. |
| 153 } | 153 } |
| 154 elementNode.accept(this); | 154 compiler.withCurrentElement(element, () { |
| 155 elementNode.accept(this); | |
| 156 }); | |
| 155 } | 157 } |
| 156 | 158 |
| 157 Type resolveType(TypeAnnotation typeAnnotation) { | 159 Type resolveType(TypeAnnotation typeAnnotation) { |
| 158 if (treeElements === null) return null; | 160 if (treeElements === null) return null; |
| 159 var result = treeElements.getType(typeAnnotation); | 161 var result = treeElements.getType(typeAnnotation); |
| 160 // TODO: Have better type resolution. | 162 // TODO: Have better type resolution. |
| 161 if (result === null) { | 163 if (result === null) { |
| 162 result = compiler.resolveTypeAnnotation(currentElement, typeAnnotation); | 164 result = compiler.resolveTypeAnnotation(currentElement, typeAnnotation); |
| 163 } | 165 } |
| 164 return result; | 166 return result; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 180 assert(element !== null); | 182 assert(element !== null); |
| 181 placeholders[node] = new ElementPlaceholder(element); | 183 placeholders[node] = new ElementPlaceholder(element); |
| 182 } | 184 } |
| 183 | 185 |
| 184 void makePrivateIdentifier(Identifier node) { | 186 void makePrivateIdentifier(Identifier node) { |
| 185 assert(node !== null); | 187 assert(node !== null); |
| 186 placeholders[node] = | 188 placeholders[node] = |
| 187 new PrivatePlaceholder(currentElement.getLibrary(), node); | 189 new PrivatePlaceholder(currentElement.getLibrary(), node); |
| 188 } | 190 } |
| 189 | 191 |
| 192 void makeUnresolvedPlaceholder(Node node) { | |
| 193 placeholders[node] = const UnresolvedPlaceholder(); | |
| 194 } | |
| 195 | |
| 190 void internalError(String reason, [Node node]) { | 196 void internalError(String reason, [Node node]) { |
| 191 compiler.cancel(reason: reason, node: node); | 197 compiler.cancel(reason: reason, node: node); |
| 192 } | 198 } |
| 193 | 199 |
| 194 visit(Node node) => (node === null) ? null : node.accept(this); | 200 visit(Node node) => (node === null) ? null : node.accept(this); |
| 195 | 201 |
| 196 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. | 202 visitNode(Node node) { node.visitChildren(this); } // We must go deeper. |
| 197 | 203 |
| 198 visitSend(Send send) { | 204 visitSend(Send send) { |
| 199 new SendVisitor(this, treeElements).visitSend(send); | 205 new SendVisitor(this, treeElements).visitSend(send); |
| 200 send.visitChildren(this); | 206 send.visitChildren(this); |
| 201 } | 207 } |
| 202 | 208 |
| 203 visitSendSet(SendSet send) { | 209 visitSendSet(SendSet send) { |
| 204 final element = treeElements[send]; | 210 final element = treeElements[send]; |
| 205 if (element !== null && element.isInstanceMember()) { | 211 if (element !== null && element.isInstanceMember()) { |
| 206 tryMakePrivateIdentifier(send.selector.asIdentifier()); | 212 tryMakePrivateIdentifier(send.selector.asIdentifier()); |
| 207 } | 213 } |
| 208 send.visitChildren(this); | 214 send.visitChildren(this); |
| 209 } | 215 } |
| 210 | 216 |
| 217 static possibleTypeVariable(TypeAnnotation typeAnnotation) { | |
|
Roman
2012/08/10 10:36:06
The name and signature of this method do not clear
Anton Muhin
2012/08/10 10:49:19
бу-бу-бу
On 2012/08/10 10:36:06, Roman wrote:
| |
| 218 if (typeAnnotation.typeName is !Identifier) return false; | |
| 219 if (typeAnnotation.typeArguments === null) return true; | |
| 220 if (typeAnnotation.typeArguments.length === 0) return true; | |
| 221 return false; | |
| 222 } | |
| 223 | |
| 211 visitTypeAnnotation(TypeAnnotation node) { | 224 visitTypeAnnotation(TypeAnnotation node) { |
| 225 // print('visitTypeAnnotation(${node.toDebugString()}): currentElement: $cur rentElement'); | |
|
Roman
2012/08/10 10:36:06
80 chars, debug stmt?
Anton Muhin
2012/08/10 10:49:19
Done.
| |
| 226 // Poor man generic variables resolution. | |
|
Roman
2012/08/10 10:36:06
Technically you don't resolve them, you skip type
Anton Muhin
2012/08/10 10:49:19
Yes. I do resolve them, meaning I do understand t
| |
| 227 // TODO(antonm): get rid of it once resolver can deal with it. | |
| 228 if (possibleTypeVariable(node)) { | |
| 229 String name = node.typeName.source.slowToString(); | |
| 230 if (currentElement is TypedefElement) { | |
| 231 TypedefElement typedefElement = currentElement; | |
| 232 NodeList typeParameters = typedefElement.cachedNode.typeParameters; | |
| 233 if (typeParameters !== null) { | |
| 234 for (TypeVariable typeVariable in typeParameters) { | |
| 235 Identifier typeVariableName = typeVariable.name; | |
| 236 if (typeVariableName.source.slowToString() == name) return; | |
| 237 } | |
| 238 } | |
| 239 } | |
| 240 if (currentElement is ClassElement) { | |
| 241 ClassElement classElement = currentElement; | |
| 242 String name = node.typeName.source.slowToString(); | |
| 243 for (TypeVariableType argument in classElement.type.arguments) { | |
| 244 // If names are equal, then it's a variable and sholdn't be renamed. | |
| 245 if (argument.name.slowToString() == name) return; | |
| 246 } | |
| 247 } | |
| 248 } | |
| 212 final type = compiler.resolveTypeAnnotation(currentElement, node); | 249 final type = compiler.resolveTypeAnnotation(currentElement, node); |
| 213 if (type is !InterfaceType) return null; | 250 if (type is !InterfaceType) return null; |
| 214 var target = node.typeName; | 251 var target = node.typeName; |
| 215 if (node.typeName is Send) { | 252 if (node.typeName is Send) { |
| 216 final element = treeElements[node]; | 253 final element = treeElements[node]; |
| 217 if (element !== null) { | 254 if (element !== null) { |
| 218 final send = node.typeName.asSend(); | 255 final send = node.typeName.asSend(); |
| 219 final hasPrefix = element.lookupConstructor( | 256 final hasPrefix = element.lookupConstructor( |
| 220 send.receiver.source, send.selector.source) === null; | 257 send.receiver.source, send.selector.source) === null; |
| 221 if (!hasPrefix) target = send.receiver; | 258 if (!hasPrefix) target = send.receiver; |
| 222 } | 259 } |
| 223 } | 260 } |
| 224 makeTypePlaceholder(target, type); | 261 // TODO(antonm): is there a better way to detect unresolved types? |
| 262 if (type !== compiler.types.dynamicType) { | |
|
Roman
2012/08/10 10:36:06
We probably don't want to rename true "Dynamic" re
Anton Muhin
2012/08/10 10:49:19
Done.
| |
| 263 makeTypePlaceholder(target, type); | |
| 264 } else { | |
| 265 makeUnresolvedPlaceholder(target); | |
| 266 } | |
| 225 node.visitChildren(this); | 267 node.visitChildren(this); |
| 226 } | 268 } |
| 227 } | 269 } |
| OLD | NEW |