Chromium Code Reviews| Index: lib/compiler/implementation/typechecker.dart |
| diff --git a/lib/compiler/implementation/typechecker.dart b/lib/compiler/implementation/typechecker.dart |
| index 80364dedfe1e348ac42bd2d0ca219626015875b1..4a4c506838c6a81e945af8ad8c89c6d93fb8eeda 100644 |
| --- a/lib/compiler/implementation/typechecker.dart |
| +++ b/lib/compiler/implementation/typechecker.dart |
| @@ -119,11 +119,12 @@ class Types { |
| final SimpleType voidType; |
| final SimpleType dynamicType; |
| - Types() : this.with(new LibraryElement(new Script(null, null))); |
| + Types(Element dynamicElement) |
| + : this.with(dynamicElement, new LibraryElement(new Script(null, null))); |
| - Types.with(LibraryElement library) |
| + Types.with(Element dynamicElement, LibraryElement library) |
| : voidType = new SimpleType(VOID, new ClassElement(VOID, library)), |
|
ahe
2012/04/17 16:14:47
Perhaps we should have a Void class as well.
karlklose
2012/04/18 08:19:08
I am not sure, I added a TODO for now.
ahe
2012/04/18 08:49:04
Good plan.
|
| - dynamicType = new SimpleType(DYNAMIC, new ClassElement(DYNAMIC, library)); |
| + dynamicType = new SimpleType(DYNAMIC, dynamicElement); |
| Type lookup(SourceString s) { |
| if (VOID == s) { |
| @@ -138,9 +139,10 @@ class Types { |
| bool isSubtype(Type t, Type s) { |
| if (t === s || t === dynamicType || s === dynamicType || |
| s.name == OBJECT) return true; |
| - if (t is SimpleType) { |
| - if (s is !SimpleType) return false; |
| + if (t is InterfaceType) { |
| + if (s is !InterfaceType) return false; |
| ClassElement tc = t.element; |
| + if (tc === s.element) return true; |
| for (Link<Type> supertypes = tc.allSupertypes; |
| supertypes != null && !supertypes.isEmpty(); |
| supertypes = supertypes.tail) { |
| @@ -162,6 +164,9 @@ class Types { |
| if (!tps.isEmpty() || !sps.isEmpty()) return false; |
| if (!isAssignable(sf.returnType, tf.returnType)) return false; |
| return true; |
| + } else if (t is TypeVariableType) { |
| + if (s is !TypeVariableType) return false; |
| + return (t.element === s.element); |
| } else { |
| throw 'internal error: unknown type kind'; |
| } |
| @@ -179,16 +184,6 @@ class CancelTypeCheckException { |
| CancelTypeCheckException(this.node, this.reason); |
| } |
| -Type lookupType(SourceString name, Compiler compiler, types) { |
| - Type t = types.lookup(name); |
| - if (t !== null) return t; |
| - Element element = compiler.coreLibrary.find(name); |
| - if (element !== null && element.kind === ElementKind.CLASS) { |
| - return element.computeType(compiler); |
| - } |
| - return null; |
| -} |
| - |
| class TypeCheckerVisitor implements Visitor<Type> { |
| final Compiler compiler; |
| final TreeElements elements; |
| @@ -208,12 +203,12 @@ class TypeCheckerVisitor implements Visitor<Type> { |
| Type listType; |
| TypeCheckerVisitor(this.compiler, this.elements, this.types) { |
| - intType = lookupType(Types.INT, compiler, types); |
| - doubleType = lookupType(Types.DOUBLE, compiler, types); |
| - boolType = lookupType(Types.BOOL, compiler, types); |
| - stringType = lookupType(Types.STRING, compiler, types); |
| - objectType = lookupType(Types.OBJECT, compiler, types); |
| - listType = lookupType(Types.LIST, compiler, types); |
| + intType = compiler.intClass.computeType(compiler); |
| + doubleType = compiler.doubleClass.computeType(compiler); |
| + boolType = compiler.boolClass.computeType(compiler); |
| + stringType = compiler.stringClass.computeType(compiler); |
| + objectType = compiler.objectClass.computeType(compiler); |
| + listType = compiler.listClass.computeType(compiler); |
| } |
| Type fail(node, [reason]) { |
| @@ -625,19 +620,7 @@ class TypeCheckerVisitor implements Visitor<Type> { |
| } |
| Type visitTypeAnnotation(TypeAnnotation node) { |
| - if (node.typeName === null) return types.dynamicType; |
| - Identifier identifier = node.typeName.asIdentifier(); |
| - if (identifier === null) { |
| - fail(node.typeName, 'library prefix not implemented'); |
| - } |
| - // TODO(ahe): Why wasn't this resolved by the resolver? |
| - Type type = lookupType(identifier.source, compiler, types); |
| - if (type === null) { |
| - // The type name cannot be resolved, but the resolver |
| - // already gave a warning, so we continue checking. |
| - return types.dynamicType; |
| - } |
| - return type; |
| + return elements.getType(node); |
| } |
| visitTypeVariable(TypeVariable node) { |