Chromium Code Reviews| Index: lib/compiler/implementation/typechecker.dart |
| diff --git a/lib/compiler/implementation/typechecker.dart b/lib/compiler/implementation/typechecker.dart |
| index b7138b6bdbd0ff63ef8d5775e25583bf5af6c6cc..de96fa013a63c0415266a12d084586612c68c922 100644 |
| --- a/lib/compiler/implementation/typechecker.dart |
| +++ b/lib/compiler/implementation/typechecker.dart |
| @@ -24,9 +24,24 @@ class TypeCheckerTask extends CompilerTask { |
| } |
| } |
| +class TypeKind { |
| + final String id; |
| + |
| + const TypeKind(String this.id); |
| + |
| + static const TypeKind FUNCTION = const TypeKind('function'); |
| + static const TypeKind INTERFACE = const TypeKind('interface'); |
| + static const TypeKind STATEMENT = const TypeKind('statement'); |
| + static const TypeKind TYPEDEF = const TypeKind('typedef'); |
| + static const TypeKind TYPE_VARIABLE = const TypeKind('type variable'); |
| + static const TypeKind VOID = const TypeKind('void'); |
|
ahe
2012/10/26 08:18:40
How about adding a "toString" mehod?
Johnni Winther
2012/10/29 09:20:14
Done.
|
| +} |
| + |
| abstract class DartType { |
| abstract SourceString get name; |
| + abstract TypeKind get kind; |
| + |
| /** |
| * Returns the [Element] which declared this type. |
| * |
| @@ -58,6 +73,8 @@ class TypeVariableType implements DartType { |
| TypeVariableType(this.element); |
| + TypeKind get kind => TypeKind.TYPE_VARIABLE; |
| + |
| SourceString get name => element.name; |
| DartType unalias(Compiler compiler) => this; |
| @@ -77,8 +94,11 @@ class TypeVariableType implements DartType { |
| */ |
| class StatementType implements DartType { |
| final String stringName; |
| + |
| Element get element => null; |
| + TypeKind get kind => TypeKind.STATEMENT; |
| + |
| SourceString get name => new SourceString(stringName); |
| const StatementType(this.stringName); |
| @@ -106,7 +126,11 @@ class StatementType implements DartType { |
| class VoidType implements DartType { |
| const VoidType(this.element); |
| + |
| + TypeKind get kind => TypeKind.VOID; |
| + |
| SourceString get name => element.name; |
| + |
| final VoidElement element; |
| DartType unalias(Compiler compiler) => this; |
| @@ -125,6 +149,8 @@ class InterfaceType implements DartType { |
| const InterfaceType(this.element, |
| [this.arguments = const Link<DartType>()]); |
| + TypeKind get kind => TypeKind.INTERFACE; |
| + |
| SourceString get name => element.name; |
| DartType unalias(Compiler compiler) => this; |
| @@ -168,6 +194,8 @@ class FunctionType implements DartType { |
| assert(element == null || invariant(element, element.isDeclaration)); |
| } |
| + TypeKind get kind => TypeKind.FUNCTION; |
| + |
| DartType unalias(Compiler compiler) => this; |
| String toString() { |
| @@ -218,6 +246,8 @@ class TypedefType implements DartType { |
| const TypedefType(this.element, |
| [this.typeArguments = const Link<DartType>()]); |
| + TypeKind get kind => TypeKind.TYPEDEF; |
| + |
| SourceString get name => element.name; |
| DartType unalias(Compiler compiler) { |