Chromium Code Reviews| Index: lib/compiler/implementation/dart_backend/placeholder_collector.dart |
| diff --git a/lib/compiler/implementation/dart_backend/placeholder_collector.dart b/lib/compiler/implementation/dart_backend/placeholder_collector.dart |
| index 76a8ff03e693cb1f8be2478a84d4f33e137cfa3f..6352fd489e9b18ba676f95eb06007d157122bdc9 100644 |
| --- a/lib/compiler/implementation/dart_backend/placeholder_collector.dart |
| +++ b/lib/compiler/implementation/dart_backend/placeholder_collector.dart |
| @@ -151,7 +151,9 @@ class PlaceholderCollector extends AbstractVisitor { |
| } else { |
| assert(false); // Unreachable. |
| } |
| - elementNode.accept(this); |
| + compiler.withCurrentElement(element, () { |
| + elementNode.accept(this); |
| + }); |
| } |
| Type resolveType(TypeAnnotation typeAnnotation) { |
| @@ -187,6 +189,10 @@ class PlaceholderCollector extends AbstractVisitor { |
| new PrivatePlaceholder(currentElement.getLibrary(), node); |
| } |
| + void makeUnresolvedPlaceholder(Node node) { |
| + placeholders[node] = const UnresolvedPlaceholder(); |
| + } |
| + |
| void internalError(String reason, [Node node]) { |
| compiler.cancel(reason: reason, node: node); |
| } |
| @@ -208,7 +214,38 @@ class PlaceholderCollector extends AbstractVisitor { |
| send.visitChildren(this); |
| } |
| + 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:
|
| + if (typeAnnotation.typeName is !Identifier) return false; |
| + if (typeAnnotation.typeArguments === null) return true; |
| + if (typeAnnotation.typeArguments.length === 0) return true; |
| + return false; |
| + } |
| + |
| visitTypeAnnotation(TypeAnnotation node) { |
| + // print('visitTypeAnnotation(${node.toDebugString()}): currentElement: $currentElement'); |
|
Roman
2012/08/10 10:36:06
80 chars, debug stmt?
Anton Muhin
2012/08/10 10:49:19
Done.
|
| + // 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
|
| + // TODO(antonm): get rid of it once resolver can deal with it. |
| + if (possibleTypeVariable(node)) { |
| + String name = node.typeName.source.slowToString(); |
| + if (currentElement is TypedefElement) { |
| + TypedefElement typedefElement = currentElement; |
| + NodeList typeParameters = typedefElement.cachedNode.typeParameters; |
| + if (typeParameters !== null) { |
| + for (TypeVariable typeVariable in typeParameters) { |
| + Identifier typeVariableName = typeVariable.name; |
| + if (typeVariableName.source.slowToString() == name) return; |
| + } |
| + } |
| + } |
| + if (currentElement is ClassElement) { |
| + ClassElement classElement = currentElement; |
| + String name = node.typeName.source.slowToString(); |
| + for (TypeVariableType argument in classElement.type.arguments) { |
| + // If names are equal, then it's a variable and sholdn't be renamed. |
| + if (argument.name.slowToString() == name) return; |
| + } |
| + } |
| + } |
| final type = compiler.resolveTypeAnnotation(currentElement, node); |
| if (type is !InterfaceType) return null; |
| var target = node.typeName; |
| @@ -221,7 +258,12 @@ class PlaceholderCollector extends AbstractVisitor { |
| if (!hasPrefix) target = send.receiver; |
| } |
| } |
| - makeTypePlaceholder(target, type); |
| + // TODO(antonm): is there a better way to detect unresolved types? |
| + 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.
|
| + makeTypePlaceholder(target, type); |
| + } else { |
| + makeUnresolvedPlaceholder(target); |
| + } |
| node.visitChildren(this); |
| } |
| } |