Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Unified Diff: lib/compiler/implementation/dart_backend/placeholder_collector.dart

Issue 10828250: Support for generic type variables and unresolved types added. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}
}

Powered by Google App Engine
This is Rietveld 408576698