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