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

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..94835409a2aa7dc016f0c80dd9fe73bd3883327e 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,44 @@ class PlaceholderCollector extends AbstractVisitor {
send.visitChildren(this);
}
+ static bool isPlainTypeName(TypeAnnotation typeAnnotation) {
+ if (typeAnnotation.typeName is !Identifier) return false;
+ if (typeAnnotation.typeArguments === null) return true;
+ if (typeAnnotation.typeArguments.length === 0) return true;
+ return false;
+ }
+
+ static bool isDynamicType(TypeAnnotation typeAnnotation) {
+ if (!isPlainTypeName(typeAnnotation)) return false;
+ String name = typeAnnotation.typeName.asIdentifier().source.slowToString();
+ return name == 'Dynamic';
+ }
+
visitTypeAnnotation(TypeAnnotation node) {
+ // Poor man generic variables resolution.
+ // TODO(antonm): get rid of it once resolver can deal with it.
+ if (isPlainTypeName(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 names are equal, then it's a variable and sholdn't be renamed.
+ 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 +264,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) {
+ makeTypePlaceholder(target, type);
+ } else {
+ if (!isDynamicType(node)) makeUnresolvedPlaceholder(target);
+ }
node.visitChildren(this);
}
}
« no previous file with comments | « lib/compiler/implementation/dart_backend/placeholder.dart ('k') | lib/compiler/implementation/dart_backend/renamer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698