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

Unified Diff: frog/leg/resolver.dart

Issue 9431029: Implement interface types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove debug function. Created 8 years, 10 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
« no previous file with comments | « no previous file | frog/leg/typechecker.dart » ('j') | frog/leg/typechecker.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/resolver.dart
diff --git a/frog/leg/resolver.dart b/frog/leg/resolver.dart
index f745eb73f2940d6c6323cffc2b9d674f5aa25f6b..b061b5bcbd62395580d8bf2943f0cf414263789a 100644
--- a/frog/leg/resolver.dart
+++ b/frog/leg/resolver.dart
@@ -573,38 +573,8 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
}
}
- visitTypeAnnotation(TypeAnnotation node) {
- SourceString className;
- if (node.typeName.asSend() !== null) {
- // In new and const expressions, the type name can be a Send to
- // denote named constructors or library prefixes.
- Send send = node.typeName.asSend();
- className = send.receiver.asIdentifier().source;
- } else {
- className = node.typeName.asIdentifier().source;
- }
- if (className == const SourceString('var')) return null;
- if (className == const SourceString('void')) return null;
- Element element = context.lookup(className);
- if (element === null) {
- if (typeRequired) {
- error(node, MessageKind.CANNOT_RESOLVE_TYPE, [className]);
- } else {
- warning(node, MessageKind.CANNOT_RESOLVE_TYPE, [className]);
- }
- } else if (element.kind !== ElementKind.CLASS) {
- if (typeRequired) {
- error(node, MessageKind.NOT_A_TYPE, [className]);
- } else {
- warning(node, MessageKind.NOT_A_TYPE, [className]);
- }
- } else {
- ClassElement cls = element;
- compiler.resolver.toResolve.add(element);
- // TODO(ahe): This should be a Type.
- useElement(node, element);
- }
- return element;
+ ClassElement visitTypeAnnotation(TypeAnnotation node) {
+ return resolveTypeAnnotation(node).element;
}
Element defineElement(Node node, Element element,
@@ -776,14 +746,6 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
return target;
}
- resolveTypeTest(Node argument) {
- TypeAnnotation node = argument.asTypeAnnotation();
- if (node == null) {
- node = argument.asSend().receiver;
- }
- resolveTypeRequired(node);
- }
-
void handleArguments(Send node) {
int count = 0;
List<SourceString> namedArguments = <SourceString>[];
@@ -954,7 +916,7 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
} else {
constructorName = typeName.asIdentifier().source;
}
- ClassElement cls = resolveTypeRequired(selector);
+ ClassElement cls = resolveTypeRequired(selector).element;
if (cls === null) {
error(selector, MessageKind.CANNOT_RESOLVE_TYPE, [selector]);
return null;
@@ -972,12 +934,59 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
return null;
}
- ClassElement resolveTypeRequired(Node node) {
+ Type resolveTypeRequired(TypeAnnotation node) {
bool old = typeRequired;
typeRequired = true;
- ClassElement cls = visit(node);
+ Type result = resolveTypeAnnotation(node);
typeRequired = old;
- return cls;
+ return result;
+ }
+
+ Type resolveTypeTest(Node argument) {
+ TypeAnnotation node = argument.asTypeAnnotation();
+ if (node == null) {
ahe 2012/02/29 12:49:15 Add comment saying this is handling "x is !Foo".
karlklose 2012/03/30 11:56:40 Done.
+ node = argument.asSend().receiver;
ahe 2012/02/29 12:49:15 node = argument.asSend().receiver.asTypeAnnotation
karlklose 2012/03/30 11:56:40 Done.
+ }
+ return resolveTypeRequired(node);
+ }
+
+ Type resolveTypeAnnotation(TypeAnnotation node) {
+ SourceString className;
+ if (node.typeName.asSend() !== null) {
ahe 2012/02/29 12:49:15 Please create a visitor.
karlklose 2012/03/30 11:56:40 I moved this code to a function.
+ // In new and const expressions, the type name can be a Send to
+ // denote named constructors or library prefixes.
ahe 2012/02/29 12:49:15 Add: // TODO(ahe): We assume it is a named constr
karlklose 2012/03/30 11:56:40 Obsolete.
+ Send send = node.typeName.asSend();
+ className = send.receiver.asIdentifier().source;
+ } else {
+ className = node.typeName.asIdentifier().source;
+ }
+ if (className == const SourceString('var') ||
+ className == const SourceString('void')){
ahe 2012/02/29 12:49:15 Move this if-test to right after line 961. In the
karlklose 2012/03/30 11:56:40 Done.
+ return compiler.types.lookup(className);
+ }
+ Element element = context.lookup(className);
+ var report = typeRequired ? error : warning;
+ if (element === null) {
+ report(node, MessageKind.CANNOT_RESOLVE_TYPE, [className]);
+ } else if (element.kind !== ElementKind.CLASS) {
+ report(node, MessageKind.NOT_A_TYPE, [className]);
+ } else {
+ ClassElement cls = element;
+ // Register class of this type to be resolved and associate it with node.
ngeoffray 2012/02/24 13:36:15 the class ... with the node.
karlklose 2012/03/30 11:56:40 Comment removed.
+ compiler.resolver.toResolve.add(cls);
+ useElement(node, cls);
+ // Resolve type arguments, if any.
+ LinkBuilder<Type> arguments = new LinkBuilder<Type>();
+ Link link = node.typeArguments != null ? node.typeArguments.nodes
ngeoffray 2012/02/24 13:36:15 Link<TypeAnnotation>
karlklose 2012/03/30 11:56:40 Done.
+ : const EmptyLink();
+ for (; !link.isEmpty(); link = link.tail) {
+ TypeAnnotation argumentAnnotation = link.head;
+ arguments.addLast(resolveTypeAnnotation(argumentAnnotation));
+ }
ngeoffray 2012/02/24 13:36:15 Do you think you could write a full Dart test or a
karlklose 2012/03/30 11:56:40 I will add a test to the ResolverTest.
+ // Construct and return resulting type.
+ return new InterfaceType(className, cls, arguments.toLink());
+ }
+ return compiler.types.dynamicType;
}
visitModifiers(Modifiers node) {
« no previous file with comments | « no previous file | frog/leg/typechecker.dart » ('j') | frog/leg/typechecker.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698