Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class TypeCheckerTask extends CompilerTask { | 7 class TypeCheckerTask extends CompilerTask { |
| 8 TypeCheckerTask(Compiler compiler) : super(compiler); | 8 TypeCheckerTask(Compiler compiler) : super(compiler); |
| 9 String get name => "Type checker"; | 9 String get name => "Type checker"; |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 class TypeKind { | 29 class TypeKind { |
| 30 final String id; | 30 final String id; |
| 31 | 31 |
| 32 const TypeKind(String this.id); | 32 const TypeKind(String this.id); |
| 33 | 33 |
| 34 static const TypeKind FUNCTION = const TypeKind('function'); | 34 static const TypeKind FUNCTION = const TypeKind('function'); |
| 35 static const TypeKind INTERFACE = const TypeKind('interface'); | 35 static const TypeKind INTERFACE = const TypeKind('interface'); |
| 36 static const TypeKind STATEMENT = const TypeKind('statement'); | 36 static const TypeKind STATEMENT = const TypeKind('statement'); |
| 37 static const TypeKind TYPEDEF = const TypeKind('typedef'); | 37 static const TypeKind TYPEDEF = const TypeKind('typedef'); |
| 38 static const TypeKind TYPE_VARIABLE = const TypeKind('type variable'); | 38 static const TypeKind TYPE_VARIABLE = const TypeKind('type variable'); |
| 39 static const TypeKind MALFORMED_TYPE = const TypeKind('malformed'); | |
| 39 static const TypeKind VOID = const TypeKind('void'); | 40 static const TypeKind VOID = const TypeKind('void'); |
| 40 | 41 |
| 41 String toString() => id; | 42 String toString() => id; |
| 42 } | 43 } |
| 43 | 44 |
| 44 abstract class DartType { | 45 abstract class DartType { |
| 45 SourceString get name; | 46 SourceString get name; |
| 46 | 47 |
| 47 TypeKind get kind; | 48 TypeKind get kind; |
| 48 | 49 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 144 |
| 144 DartType unalias(Compiler compiler) => this; | 145 DartType unalias(Compiler compiler) => this; |
| 145 | 146 |
| 146 int get hashCode => 1729; | 147 int get hashCode => 1729; |
| 147 | 148 |
| 148 bool operator ==(other) => other is VoidType; | 149 bool operator ==(other) => other is VoidType; |
| 149 | 150 |
| 150 String toString() => name.slowToString(); | 151 String toString() => name.slowToString(); |
| 151 } | 152 } |
| 152 | 153 |
| 154 class MalformedType extends DartType { | |
| 155 const MalformedType(this.element); | |
| 156 | |
| 157 TypeKind get kind => TypeKind.MALFORMED_TYPE; | |
| 158 | |
| 159 SourceString get name => element.name; | |
| 160 | |
| 161 final MalformedTypeElement element; | |
| 162 | |
| 163 DartType unalias(Compiler compiler) => this; | |
| 164 | |
| 165 int get hashCode => 1733; | |
| 166 | |
| 167 bool operator ==(other) => other is MalformedType; | |
|
ngeoffray
2012/11/27 09:37:35
Not checking if elements are equal is kind of stra
aam-me
2012/11/28 01:49:47
Good point. I used VoidType above as a template.
| |
| 168 | |
| 169 String toString() => name.slowToString(); | |
| 170 } | |
| 171 | |
| 153 class InterfaceType extends DartType { | 172 class InterfaceType extends DartType { |
| 154 final Element element; | 173 final Element element; |
| 155 final Link<DartType> arguments; | 174 final Link<DartType> arguments; |
| 156 | 175 |
| 157 InterfaceType(this.element, | 176 InterfaceType(this.element, |
| 158 [this.arguments = const Link<DartType>()]) { | 177 [this.arguments = const Link<DartType>()]) { |
| 159 assert(invariant(element, element.isDeclaration)); | 178 assert(invariant(element, element.isDeclaration)); |
| 160 } | 179 } |
| 161 | 180 |
| 162 TypeKind get kind => TypeKind.INTERFACE; | 181 TypeKind get kind => TypeKind.INTERFACE; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 identical(s, dynamicType) || | 333 identical(s, dynamicType) || |
| 315 identical(s.element, compiler.objectClass) || | 334 identical(s.element, compiler.objectClass) || |
| 316 identical(t.element, compiler.nullClass)) { | 335 identical(t.element, compiler.nullClass)) { |
| 317 return true; | 336 return true; |
| 318 } | 337 } |
| 319 t = t.unalias(compiler); | 338 t = t.unalias(compiler); |
| 320 s = s.unalias(compiler); | 339 s = s.unalias(compiler); |
| 321 | 340 |
| 322 if (t is VoidType) { | 341 if (t is VoidType) { |
| 323 return false; | 342 return false; |
| 343 } else if (t is MalformedType) { | |
| 344 return false; | |
| 324 } else if (t is InterfaceType) { | 345 } else if (t is InterfaceType) { |
| 325 if (s is !InterfaceType) return false; | 346 if (s is !InterfaceType) return false; |
| 326 ClassElement tc = t.element; | 347 ClassElement tc = t.element; |
| 327 if (identical(tc, s.element)) return true; | 348 if (identical(tc, s.element)) return true; |
| 328 for (Link<DartType> supertypes = tc.allSupertypes; | 349 for (Link<DartType> supertypes = tc.allSupertypes; |
| 329 supertypes != null && !supertypes.isEmpty; | 350 supertypes != null && !supertypes.isEmpty; |
| 330 supertypes = supertypes.tail) { | 351 supertypes = supertypes.tail) { |
| 331 DartType supertype = supertypes.head; | 352 DartType supertype = supertypes.head; |
| 332 if (identical(supertype.element, s.element)) return true; | 353 if (identical(supertype.element, s.element)) return true; |
| 333 } | 354 } |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1032 } | 1053 } |
| 1033 | 1054 |
| 1034 DartType visitStringNode(StringNode node) { | 1055 DartType visitStringNode(StringNode node) { |
| 1035 compiler.unimplemented('visitNode', node: node); | 1056 compiler.unimplemented('visitNode', node: node); |
| 1036 } | 1057 } |
| 1037 | 1058 |
| 1038 DartType visitLibraryDependency(LibraryDependency node) { | 1059 DartType visitLibraryDependency(LibraryDependency node) { |
| 1039 compiler.unimplemented('visitNode', node: node); | 1060 compiler.unimplemented('visitNode', node: node); |
| 1040 } | 1061 } |
| 1041 } | 1062 } |
| OLD | NEW |