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 class TypeCheckerTask extends CompilerTask { | 5 class TypeCheckerTask extends CompilerTask { |
| 6 TypeCheckerTask(Compiler compiler) : super(compiler); | 6 TypeCheckerTask(Compiler compiler) : super(compiler); |
| 7 String get name => "Type checker"; | 7 String get name => "Type checker"; |
| 8 | 8 |
| 9 static const bool LOG_FAILURES = false; | 9 static const bool LOG_FAILURES = false; |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 * | 34 * |
| 35 * The unaliased type of a typedef'd type is the unaliased type to which its | 35 * The unaliased type of a typedef'd type is the unaliased type to which its |
| 36 * name is bound. The unaliased version of any other type is the type itself. | 36 * name is bound. The unaliased version of any other type is the type itself. |
| 37 * | 37 * |
| 38 * For example, the unaliased type of [: typedef A Func<A,B>(B b) :] is the | 38 * For example, the unaliased type of [: typedef A Func<A,B>(B b) :] is the |
| 39 * function type [: (B) -> A :] and the unaliased type of | 39 * function type [: (B) -> A :] and the unaliased type of |
| 40 * [: Func<int,String> :] is the function type [: (String) -> int :]. | 40 * [: Func<int,String> :] is the function type [: (String) -> int :]. |
| 41 */ | 41 */ |
| 42 abstract DartType unalias(Compiler compiler); | 42 abstract DartType unalias(Compiler compiler); |
| 43 | 43 |
| 44 abstract bool equals(other); | 44 abstract bool operator ==(other); |
| 45 } | 45 } |
| 46 | 46 |
| 47 class TypeVariableType implements DartType { | 47 class TypeVariableType implements DartType { |
| 48 final TypeVariableElement element; | 48 final TypeVariableElement element; |
| 49 | 49 |
| 50 TypeVariableType(this.element); | 50 TypeVariableType(this.element); |
| 51 | 51 |
| 52 SourceString get name => element.name; | 52 SourceString get name => element.name; |
| 53 | 53 |
| 54 DartType unalias(Compiler compiler) => this; | 54 DartType unalias(Compiler compiler) => this; |
| 55 | 55 |
| 56 int hashCode() => 17 * element.hashCode(); | 56 int hashCode() => 17 * element.hashCode(); |
| 57 | 57 |
| 58 bool equals(other) { | 58 bool operator ==(other) { |
| 59 if (other is !TypeVariableType) return false; | 59 if (other is !TypeVariableType) return false; |
| 60 return other.element == element; | 60 return other.element == element; |
|
ahe
2012/09/17 08:19:58
===
Johnni Winther
2012/09/18 08:14:30
Done.
| |
| 61 } | 61 } |
| 62 | 62 |
| 63 String toString() => name.slowToString(); | 63 String toString() => name.slowToString(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * A statement type tracks whether a statement returns or may return. | 67 * A statement type tracks whether a statement returns or may return. |
| 68 */ | 68 */ |
| 69 class StatementType implements DartType { | 69 class StatementType implements DartType { |
| 70 final String stringName; | 70 final String stringName; |
| 71 Element get element => null; | 71 Element get element => null; |
| 72 | 72 |
| 73 SourceString get name => new SourceString(stringName); | 73 SourceString get name => new SourceString(stringName); |
| 74 | 74 |
| 75 const StatementType(this.stringName); | 75 const StatementType(this.stringName); |
| 76 | 76 |
| 77 static const RETURNING = const StatementType('<returning>'); | 77 static const RETURNING = const StatementType('<returning>'); |
| 78 static const NOT_RETURNING = const StatementType('<not returning>'); | 78 static const NOT_RETURNING = const StatementType('<not returning>'); |
| 79 static const MAYBE_RETURNING = const StatementType('<maybe returning>'); | 79 static const MAYBE_RETURNING = const StatementType('<maybe returning>'); |
| 80 | 80 |
| 81 /** Combine the information about two control-flow edges that are joined. */ | 81 /** Combine the information about two control-flow edges that are joined. */ |
| 82 StatementType join(StatementType other) { | 82 StatementType join(StatementType other) { |
| 83 return (this === other) ? this : MAYBE_RETURNING; | 83 return (this === other) ? this : MAYBE_RETURNING; |
| 84 } | 84 } |
| 85 | 85 |
| 86 DartType unalias(Compiler compiler) => this; | 86 DartType unalias(Compiler compiler) => this; |
| 87 | 87 |
| 88 int hashCode() => 17 * stringName.hashCode(); | 88 int hashCode() => 17 * stringName.hashCode(); |
| 89 | 89 |
| 90 bool equals(other) { | 90 bool operator ==(other) { |
| 91 if (other is !StatementType) return false; | 91 if (other is !StatementType) return false; |
| 92 return other.stringName == stringName; | 92 return other.stringName == stringName; |
| 93 } | 93 } |
| 94 | 94 |
| 95 String toString() => stringName; | 95 String toString() => stringName; |
| 96 } | 96 } |
| 97 | 97 |
| 98 class VoidType implements DartType { | 98 class VoidType implements DartType { |
| 99 const VoidType(this.element); | 99 const VoidType(this.element); |
| 100 SourceString get name => element.name; | 100 SourceString get name => element.name; |
| 101 final VoidElement element; | 101 final VoidElement element; |
| 102 | 102 |
| 103 DartType unalias(Compiler compiler) => this; | 103 DartType unalias(Compiler compiler) => this; |
| 104 | 104 |
| 105 int hashCode() => 1729; | 105 int hashCode() => 1729; |
| 106 | 106 |
| 107 bool equals(other) => other is VoidType; | 107 bool operator ==(other) => other is VoidType; |
| 108 | 108 |
| 109 String toString() => name.slowToString(); | 109 String toString() => name.slowToString(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 class InterfaceType implements DartType { | 112 class InterfaceType implements DartType { |
| 113 final Element element; | 113 final Element element; |
| 114 final Link<DartType> arguments; | 114 final Link<DartType> arguments; |
| 115 | 115 |
| 116 const InterfaceType(this.element, | 116 const InterfaceType(this.element, |
| 117 [this.arguments = const EmptyLink<DartType>()]); | 117 [this.arguments = const EmptyLink<DartType>()]); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 135 int hash = element.hashCode(); | 135 int hash = element.hashCode(); |
| 136 for (Link<DartType> arguments = this.arguments; | 136 for (Link<DartType> arguments = this.arguments; |
| 137 !arguments.isEmpty(); | 137 !arguments.isEmpty(); |
| 138 arguments = arguments.tail) { | 138 arguments = arguments.tail) { |
| 139 int argumentHash = arguments.head != null ? arguments.head.hashCode() : 0; | 139 int argumentHash = arguments.head != null ? arguments.head.hashCode() : 0; |
| 140 hash = 17 * hash + 3 * argumentHash; | 140 hash = 17 * hash + 3 * argumentHash; |
| 141 } | 141 } |
| 142 return hash; | 142 return hash; |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool equals(other) { | 145 bool operator ==(other) { |
| 146 if (other is !InterfaceType) return false; | 146 if (other is !InterfaceType) return false; |
| 147 if (element != other.element) return false; | |
|
ahe
2012/09/17 08:19:58
!==
Johnni Winther
2012/09/18 08:14:30
Done.
| |
| 147 return arguments == other.arguments; | 148 return arguments == other.arguments; |
| 148 } | 149 } |
| 149 } | 150 } |
| 150 | 151 |
| 151 class FunctionType implements DartType { | 152 class FunctionType implements DartType { |
| 152 final Element element; | 153 final Element element; |
| 153 DartType returnType; | 154 DartType returnType; |
| 154 Link<DartType> parameterTypes; | 155 Link<DartType> parameterTypes; |
| 155 | 156 |
| 156 FunctionType(DartType this.returnType, Link<DartType> this.parameterTypes, | 157 FunctionType(DartType this.returnType, Link<DartType> this.parameterTypes, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 187 int hashCode() { | 188 int hashCode() { |
| 188 int hash = 17 * element.hashCode() + 3 * returnType.hashCode(); | 189 int hash = 17 * element.hashCode() + 3 * returnType.hashCode(); |
| 189 for (Link<DartType> parameters = parameterTypes; | 190 for (Link<DartType> parameters = parameterTypes; |
| 190 !parameters.isEmpty(); | 191 !parameters.isEmpty(); |
| 191 parameters = parameters.tail) { | 192 parameters = parameters.tail) { |
| 192 hash = 17 * hash + 3 * parameters.head.hashCode(); | 193 hash = 17 * hash + 3 * parameters.head.hashCode(); |
| 193 } | 194 } |
| 194 return hash; | 195 return hash; |
| 195 } | 196 } |
| 196 | 197 |
| 197 bool equals(other) { | 198 bool operator ==(other) { |
| 198 if (other is !FunctionType) return false; | 199 if (other is !FunctionType) return false; |
| 199 return returnType == other.returnType | 200 return returnType == other.returnType |
| 200 && parameterTypes == other.parameterTypes; | 201 && parameterTypes == other.parameterTypes; |
| 201 } | 202 } |
| 202 } | 203 } |
| 203 | 204 |
| 204 class TypedefType implements DartType { | 205 class TypedefType implements DartType { |
| 205 final TypedefElement element; | 206 final TypedefElement element; |
| 206 final Link<DartType> typeArguments; | 207 final Link<DartType> typeArguments; |
| 207 | 208 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 222 if (!typeArguments.isEmpty()) { | 223 if (!typeArguments.isEmpty()) { |
| 223 sb.add('<'); | 224 sb.add('<'); |
| 224 typeArguments.printOn(sb, ', '); | 225 typeArguments.printOn(sb, ', '); |
| 225 sb.add('>'); | 226 sb.add('>'); |
| 226 } | 227 } |
| 227 return sb.toString(); | 228 return sb.toString(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 int hashCode() => 17 * element.hashCode(); | 231 int hashCode() => 17 * element.hashCode(); |
| 231 | 232 |
| 232 bool equals(other) { | 233 bool operator ==(other) { |
| 233 if (other is !TypedefType) return false; | 234 if (other is !TypedefType) return false; |
| 234 return other.element == element; | 235 if (element != other.element) return false; |
|
ahe
2012/09/17 08:19:58
!==
Johnni Winther
2012/09/18 08:14:30
Done.
| |
| 236 return typeArguments == other.typeArguments; | |
| 235 } | 237 } |
| 236 } | 238 } |
| 237 | 239 |
| 238 class Types { | 240 class Types { |
| 239 final Compiler compiler; | 241 final Compiler compiler; |
| 240 // TODO(karlklose): should we have a class Void? | 242 // TODO(karlklose): should we have a class Void? |
| 241 final VoidType voidType; | 243 final VoidType voidType; |
| 242 final InterfaceType dynamicType; | 244 final InterfaceType dynamicType; |
| 243 | 245 |
| 244 Types(Compiler compiler, Element dynamicElement) | 246 Types(Compiler compiler, Element dynamicElement) |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 } | 909 } |
| 908 | 910 |
| 909 visitCatchBlock(CatchBlock node) { | 911 visitCatchBlock(CatchBlock node) { |
| 910 return unhandledStatement(); | 912 return unhandledStatement(); |
| 911 } | 913 } |
| 912 | 914 |
| 913 visitTypedef(Typedef node) { | 915 visitTypedef(Typedef node) { |
| 914 return unhandledStatement(); | 916 return unhandledStatement(); |
| 915 } | 917 } |
| 916 } | 918 } |
| OLD | NEW |