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 abstract class HType { | 5 abstract class HType { |
| 6 const HType(); | 6 const HType(); |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Returns a [HType] that represents all types that have [type] as a | 9 * Returns a [HType] that represents all types that have [type] as a |
| 10 * supertype, or the type [type]. | 10 * supertype, or the type [type]. |
|
floitsch
2012/05/10 10:29:43
Returns an [HType] that represents [type] and all
ngeoffray
2012/05/11 10:17:54
Done.
| |
| 11 */ | 11 */ |
| 12 factory HType.fromBoundedType(Type type, | 12 factory HType.fromBoundedType(Type type, |
| 13 Compiler compiler, | 13 Compiler compiler, |
| 14 [bool canBeNull = false]) { | 14 [bool canBeNull = false]) { |
| 15 Element element = type.element; | 15 Element element = type.element; |
| 16 if (element.kind === ElementKind.TYPE_VARIABLE) { | 16 if (element.kind === ElementKind.TYPE_VARIABLE) { |
| 17 compiler.unimplemented("type variables"); | 17 // TODO(ngeoffray): Replace object type type [type]. |
|
floitsch
2012/05/10 10:29:43
type type [type] ?
ngeoffray
2012/05/11 10:17:54
Done.
| |
| 18 return new HBoundedPotentialPrimitiveType( | |
| 19 compiler.objectClass.computeType(compiler), canBeNull); | |
| 18 } | 20 } |
| 19 | 21 |
| 20 if (!canBeNull) { | 22 if (element === compiler.intClass) { |
| 21 if (element === compiler.intClass) { | 23 return canBeNull ? HType.INTEGER_OR_NULL : HType.INTEGER; |
| 22 return HType.INTEGER; | 24 } else if (element === compiler.numClass) { |
| 23 } else if (element === compiler.numClass) { | 25 return canBeNull ? HType.NUMBER_OR_NULL : HType.NUMBER; |
| 24 return HType.NUMBER; | 26 } else if (element === compiler.doubleClass) { |
| 25 } else if (element === compiler.doubleClass) { | 27 return canBeNull ? HType.DOUBLE_OR_NULL : HType.DOUBLE; |
| 26 return HType.DOUBLE; | 28 } else if (element === compiler.stringClass) { |
| 27 } else if (element === compiler.stringClass) { | 29 return canBeNull ? HType.STRING_OR_NULL : HType.STRING; |
| 28 return HType.STRING; | 30 } else if (element === compiler.boolClass) { |
| 29 } else if (element === compiler.boolClass) { | 31 return canBeNull ? HType.BOOLEAN_OR_NULL : HType.BOOLEAN; |
| 30 return HType.BOOLEAN; | 32 } else if (element === compiler.listClass |
| 31 } | |
| 32 } | |
| 33 if (element === compiler.listClass | |
| 34 || Elements.isListSupertype(element, compiler)) { | 33 || Elements.isListSupertype(element, compiler)) { |
| 35 return new HBoundedPotentialPrimitiveArray(type, canBeNull); | 34 return new HBoundedPotentialPrimitiveArray(type, canBeNull); |
| 36 } else if (Elements.isStringSupertype(element, compiler)) { | 35 } else if (Elements.isStringSupertype(element, compiler)) { |
| 37 return new HBoundedPotentialPrimitiveString(type, canBeNull); | 36 return new HBoundedPotentialPrimitiveString(type, canBeNull); |
| 38 } else if (element === compiler.intClass | |
| 39 || element === compiler.boolClass | |
| 40 || element === compiler.numClass | |
| 41 || element === compiler.doubleClass | |
| 42 || element === compiler.stringClass) { | |
| 43 // TODO(ngeoffray): Create primitive nullable types. | |
| 44 return null; | |
| 45 } else { | 37 } else { |
| 46 return new HBoundedType(type, canBeNull); | 38 return new HBoundedType(type, canBeNull); |
| 47 } | 39 } |
| 48 } | 40 } |
| 49 | 41 |
| 50 static final HType CONFLICTING = const HAnalysisType("conflicting"); | 42 static final HType CONFLICTING = const HAnalysisType("conflicting"); |
| 51 static final HType UNKNOWN = const HAnalysisType("unknown"); | 43 static final HType UNKNOWN = const HAnalysisType("unknown"); |
| 52 static final HType BOOLEAN = const HBooleanType(); | 44 static final HType BOOLEAN = const HBooleanType(); |
| 53 static final HType NUMBER = const HNumberType(); | 45 static final HType NUMBER = const HNumberType(); |
| 54 static final HType INTEGER = const HIntegerType(); | 46 static final HType INTEGER = const HIntegerType(); |
| 55 static final HType DOUBLE = const HDoubleType(); | 47 static final HType DOUBLE = const HDoubleType(); |
| 56 static final HType INDEXABLE_PRIMITIVE = const HIndexablePrimitiveType(); | 48 static final HType INDEXABLE_PRIMITIVE = const HIndexablePrimitiveType(); |
| 57 static final HType STRING = const HStringType(); | 49 static final HType STRING = const HStringType(); |
| 58 static final HType READABLE_ARRAY = const HReadableArrayType(); | 50 static final HType READABLE_ARRAY = const HReadableArrayType(); |
| 59 static final HType MUTABLE_ARRAY = const HMutableArrayType(); | 51 static final HType MUTABLE_ARRAY = const HMutableArrayType(); |
| 60 static final HType EXTENDABLE_ARRAY = const HExtendableArrayType(); | 52 static final HType EXTENDABLE_ARRAY = const HExtendableArrayType(); |
| 61 | 53 |
| 54 static final HType BOOLEAN_OR_NULL = const HBooleanOrNullType(); | |
|
Lasse Reichstein Nielsen
2012/05/10 10:15:20
DO you think it will eventually be worth it to hav
ngeoffray
2012/05/11 10:17:54
Yes. As discussed, I preferred special casing thes
| |
| 55 static final HType NUMBER_OR_NULL = const HNumberOrNullType(); | |
| 56 static final HType INTEGER_OR_NULL = const HIntegerOrNullType(); | |
| 57 static final HType DOUBLE_OR_NULL = const HDoubleOrNullType(); | |
| 58 static final HType STRING_OR_NULL = const HStringOrNullType(); | |
| 59 | |
| 62 bool isConflicting() => this === CONFLICTING; | 60 bool isConflicting() => this === CONFLICTING; |
| 63 bool isUnknown() => this === UNKNOWN; | 61 bool isUnknown() => this === UNKNOWN; |
| 64 bool isBoolean() => false; | 62 bool isBoolean() => false; |
| 65 bool isNumber() => false; | 63 bool isNumber() => false; |
| 66 bool isInteger() => false; | 64 bool isInteger() => false; |
| 67 bool isDouble() => false; | 65 bool isDouble() => false; |
| 68 bool isString() => false; | 66 bool isString() => false; |
| 67 bool isBooleanOrNull() => false; | |
| 68 bool isNumberOrNull() => false; | |
| 69 bool isIntegerOrNull() => false; | |
| 70 bool isDoubleOrNull() => false; | |
| 71 bool isStringOrNull() => false; | |
| 69 bool isIndexablePrimitive() => false; | 72 bool isIndexablePrimitive() => false; |
| 70 bool isReadableArray() => false; | 73 bool isReadableArray() => false; |
| 71 bool isMutableArray() => false; | 74 bool isMutableArray() => false; |
| 72 bool isExtendableArray() => false; | 75 bool isExtendableArray() => false; |
| 73 bool isPrimitive() => false; | 76 bool isPrimitive() => false; |
| 74 bool isExact() => false; | 77 bool isExact() => false; |
| 75 | 78 |
| 76 bool canBePrimitive() => false; | 79 bool canBePrimitive() => false; |
| 77 bool canBeNull() => false; | 80 bool canBeNull() => false; |
| 78 | 81 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 HType union(HType other) => combine(other); | 135 HType union(HType other) => combine(other); |
| 133 HType intersection(HType other) => combine(other); | 136 HType intersection(HType other) => combine(other); |
| 134 } | 137 } |
| 135 | 138 |
| 136 abstract class HPrimitiveType extends HType { | 139 abstract class HPrimitiveType extends HType { |
| 137 const HPrimitiveType(); | 140 const HPrimitiveType(); |
| 138 bool isPrimitive() => true; | 141 bool isPrimitive() => true; |
| 139 bool canBePrimitive() => true; | 142 bool canBePrimitive() => true; |
| 140 } | 143 } |
| 141 | 144 |
| 145 abstract class HPrimitiveOrNullType extends HType { | |
| 146 const HPrimitiveOrNullType(); | |
| 147 bool canBePrimitive() => true; | |
| 148 bool canBeNull() => true; | |
| 149 } | |
| 150 | |
| 151 class HBooleanOrNullType extends HPrimitiveOrNullType { | |
| 152 const HBooleanOrNullType(); | |
| 153 String toString() => "boolean or null"; | |
| 154 bool isBooleanOrNull() => true; | |
| 155 | |
| 156 Type computeType(Compiler compiler) { | |
| 157 return compiler.boolClass.computeType(compiler); | |
| 158 } | |
| 159 | |
| 160 HType union(HType other) { | |
| 161 if (other.isUnknown()) return HType.BOOLEAN_OR_NULL; | |
| 162 if (other.isBooleanOrNull()) return HType.BOOLEAN_OR_NULL; | |
| 163 if (other.isBoolean()) return HType.BOOLEAN_OR_NULL; | |
| 164 return HType.CONFLICTING; | |
| 165 } | |
| 166 | |
| 167 HType intersection(HType other) { | |
| 168 if (other.isUnknown()) return HType.BOOLEAN_OR_NULL; | |
| 169 if (other.isBooleanOrNull()) return HType.BOOLEAN_OR_NULL; | |
| 170 if (other.isBoolean()) return HType.BOOLEAN; | |
| 171 return HType.CONFLICTING; | |
| 172 } | |
| 173 } | |
| 174 | |
| 142 class HBooleanType extends HPrimitiveType { | 175 class HBooleanType extends HPrimitiveType { |
| 143 const HBooleanType(); | 176 const HBooleanType(); |
| 144 bool isBoolean() => true; | 177 bool isBoolean() => true; |
| 145 String toString() => "boolean"; | 178 String toString() => "boolean"; |
| 146 | 179 |
| 147 Type computeType(Compiler compiler) { | 180 Type computeType(Compiler compiler) { |
| 148 return compiler.boolClass.computeType(compiler); | 181 return compiler.boolClass.computeType(compiler); |
| 149 } | 182 } |
| 150 | 183 |
| 151 HType combine(HType other) { | 184 HType union(HType other) { |
| 152 if (other.isBoolean() || other.isUnknown()) return HType.BOOLEAN; | 185 if (other.isUnknown()) return HType.BOOLEAN; |
| 186 if (other.isBoolean()) return HType.BOOLEAN; | |
| 187 if (other.isBooleanOrNull()) return HType.BOOLEAN_OR_NULL; | |
| 153 return HType.CONFLICTING; | 188 return HType.CONFLICTING; |
| 154 } | 189 } |
| 155 | 190 |
| 156 // Since the boolean type is a one-element set the union and intersection are | 191 HType intersection(HType other) { |
| 157 // the same. | 192 if (other.isUnknown()) return HType.BOOLEAN; |
| 158 HType union(HType other) => combine(other); | 193 if (other.isBooleanOrNull()) return HType.BOOLEAN; |
| 159 HType intersection(HType other) => combine(other); | 194 if (other.isBoolean()) return HType.BOOLEAN; |
| 195 return HType.CONFLICTING; | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 class HNumberOrNullType extends HPrimitiveOrNullType { | |
| 200 const HNumberOrNullType(); | |
| 201 bool isNumberOrNull() => true; | |
| 202 String toString() => "number or null"; | |
| 203 | |
| 204 Type computeType(Compiler compiler) { | |
| 205 return compiler.numClass.computeType(compiler); | |
| 206 } | |
| 207 | |
| 208 HType union(HType other) { | |
| 209 if (other.isUnknown()) return HType.NUMBER_OR_NULL; | |
| 210 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; | |
| 211 if (other.isNumber()) return HType.NUMBER_OR_NULL; | |
| 212 return HType.CONFLICTING; | |
| 213 } | |
| 214 | |
| 215 HType intersection(HType other) { | |
| 216 if (other.isUnknown()) return HType.NUMBER_OR_NULL; | |
| 217 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; | |
|
floitsch
2012/05/10 10:29:43
not correct for integers or doubles.
ngeoffray
2012/05/11 10:17:54
Done.
| |
| 218 if (other.isNumber()) return HType.NUMBER; | |
| 219 return HType.CONFLICTING; | |
| 220 } | |
| 160 } | 221 } |
| 161 | 222 |
| 162 class HNumberType extends HPrimitiveType { | 223 class HNumberType extends HPrimitiveType { |
| 163 const HNumberType(); | 224 const HNumberType(); |
| 164 bool isNumber() => true; | 225 bool isNumber() => true; |
| 165 String toString() => "number"; | 226 String toString() => "number"; |
| 166 | 227 |
| 167 Type computeType(Compiler compiler) { | 228 Type computeType(Compiler compiler) { |
| 168 return compiler.numClass.computeType(compiler); | 229 return compiler.numClass.computeType(compiler); |
| 169 } | 230 } |
| 170 | 231 |
| 171 HType union(HType other) { | 232 HType union(HType other) { |
| 172 if (other.isNumber() || other.isUnknown()) return HType.NUMBER; | 233 if (other.isNumber()) return HType.NUMBER; |
| 234 if (other.isUnknown()) return HType.NUMBER; | |
| 235 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; | |
| 173 return HType.CONFLICTING; | 236 return HType.CONFLICTING; |
| 174 } | 237 } |
| 175 | 238 |
| 176 HType intersection(HType other) { | 239 HType intersection(HType other) { |
| 177 if (other.isUnknown()) return HType.NUMBER; | 240 if (other.isUnknown()) return HType.NUMBER; |
| 178 if (other.isNumber()) return other; | 241 if (other.isNumber()) return other; |
| 242 if (other.isIntegerOrNull()) return HType.INTEGER; | |
| 243 if (other.isDoubleOrNull()) return HType.DOUBLE; | |
| 244 if (other.isNumberOrNull()) return HType.NUMBER; | |
| 245 return HType.CONFLICTING; | |
| 246 } | |
| 247 } | |
| 248 | |
| 249 class HIntegerOrNullType extends HNumberOrNullType { | |
| 250 const HIntegerOrNullType(); | |
| 251 bool isIntegerOrNull() => true; | |
| 252 String toString() => "integer or null"; | |
| 253 | |
| 254 Type computeType(Compiler compiler) { | |
| 255 return compiler.intClass.computeType(compiler); | |
| 256 } | |
| 257 | |
| 258 HType union(HType other) { | |
| 259 if (other.isUnknown()) return HType.INTEGER_OR_NULL; | |
| 260 if (other.isIntegerOrNull()) return HType.INTEGER_OR_NULL; | |
| 261 if (other.isInteger()) return HType.INTEGER_OR_NULL; | |
| 262 if (other.isNumber()) return HType.NUMBER_OR_NULL; | |
| 263 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; | |
| 264 return HType.CONFLICTING; | |
| 265 } | |
| 266 | |
| 267 HType intersection(HType other) { | |
| 268 if (other.isUnknown()) return HType.INTEGER_OR_NULL; | |
| 269 if (other.isIntegerOrNull()) return HType.INTEGER_OR_NULL; | |
| 270 if (other.isInteger()) return HType.INTEGER; | |
| 271 if (other.isDouble()) return HType.CONFLICTING; | |
| 272 if (other.isDoubleOrNull()) return HType.CONFLICTING; | |
| 273 if (other.isNumber()) return HType.INTEGER; | |
| 274 if (other.isNumberOrNull()) return HType.INTEGER_OR_NULL; | |
| 179 return HType.CONFLICTING; | 275 return HType.CONFLICTING; |
| 180 } | 276 } |
| 181 } | 277 } |
| 182 | 278 |
| 183 class HIntegerType extends HNumberType { | 279 class HIntegerType extends HNumberType { |
| 184 const HIntegerType(); | 280 const HIntegerType(); |
| 185 bool isInteger() => true; | 281 bool isInteger() => true; |
| 186 String toString() => "integer"; | 282 String toString() => "integer"; |
| 187 | 283 |
| 188 Type computeType(Compiler compiler) { | 284 Type computeType(Compiler compiler) { |
| 189 return compiler.intClass.computeType(compiler); | 285 return compiler.intClass.computeType(compiler); |
| 190 } | 286 } |
| 191 | 287 |
| 192 HType union(HType other) { | 288 HType union(HType other) { |
| 193 if (other.isInteger() || other.isUnknown()) return HType.INTEGER; | 289 if (other.isUnknown()) return HType.INTEGER; |
| 290 if (other.isInteger()) return HType.INTEGER; | |
| 291 if (other.isIntegerOrNull()) return HType.INTEGER_OR_NULL; | |
| 194 if (other.isNumber()) return HType.NUMBER; | 292 if (other.isNumber()) return HType.NUMBER; |
| 293 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; | |
| 195 return HType.CONFLICTING; | 294 return HType.CONFLICTING; |
| 196 } | 295 } |
| 197 | 296 |
| 198 HType intersection(HType other) { | 297 HType intersection(HType other) { |
| 199 if (other.isUnknown()) return HType.INTEGER; | 298 if (other.isUnknown()) return HType.INTEGER; |
| 299 if (other.isIntegerOrNull()) return HType.INTEGER; | |
| 300 if (other.isInteger()) return HType.INTEGER; | |
| 200 if (other.isDouble()) return HType.CONFLICTING; | 301 if (other.isDouble()) return HType.CONFLICTING; |
| 201 if (other.isNumber()) return this; | 302 if (other.isDoubleOrNull()) return HType.CONFLICTING; |
| 303 if (other.isNumber()) return HType.INTEGER; | |
| 304 if (other.isNumberOrNull()) return HType.INTEGER; | |
| 305 return HType.CONFLICTING; | |
| 306 } | |
| 307 } | |
| 308 | |
| 309 class HDoubleOrNullType extends HNumberOrNullType { | |
| 310 const HDoubleOrNullType(); | |
| 311 bool isDoubleOrNull() => true; | |
| 312 String toString() => "double or null"; | |
| 313 | |
| 314 Type computeType(Compiler compiler) { | |
| 315 return compiler.doubleClass.computeType(compiler); | |
| 316 } | |
| 317 | |
| 318 HType union(HType other) { | |
| 319 if (other.isUnknown()) return HType.DOUBLE_OR_NULL; | |
| 320 if (other.isDoubleOrNull()) return HType.DOUBLE_OR_NULL; | |
| 321 if (other.isDouble()) return HType.DOUBLE_OR_NULL; | |
| 322 if (other.isNumber()) return HType.NUMBER_OR_NULL; | |
| 323 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; | |
| 324 return HType.CONFLICTING; | |
| 325 } | |
| 326 | |
| 327 HType intersection(HType other) { | |
| 328 if (other.isUnknown()) return HType.DOUBLE_OR_NULL; | |
| 329 if (other.isIntegerOrNull()) return HType.CONFLICTING; | |
| 330 if (other.isInteger()) return HType.CONFLICTING; | |
| 331 if (other.isDouble()) return HType.DOUBLE; | |
| 332 if (other.isDoubleOrNull()) return HType.DOUBLE_OR_NULL; | |
| 333 if (other.isNumber()) return HType.DOUBLE; | |
| 334 if (other.isNumberOrNull()) return HType.DOUBLE_OR_NULL; | |
| 202 return HType.CONFLICTING; | 335 return HType.CONFLICTING; |
| 203 } | 336 } |
| 204 } | 337 } |
| 205 | 338 |
| 206 class HDoubleType extends HNumberType { | 339 class HDoubleType extends HNumberType { |
| 207 const HDoubleType(); | 340 const HDoubleType(); |
| 208 bool isDouble() => true; | 341 bool isDouble() => true; |
| 209 String toString() => "double"; | 342 String toString() => "double"; |
| 210 | 343 |
| 211 Type computeType(Compiler compiler) { | 344 Type computeType(Compiler compiler) { |
| 212 return compiler.doubleClass.computeType(compiler); | 345 return compiler.doubleClass.computeType(compiler); |
| 213 } | 346 } |
| 214 | 347 |
| 215 HType union(HType other) { | 348 HType union(HType other) { |
| 216 if (other.isDouble() || other.isUnknown()) return HType.DOUBLE; | 349 if (other.isUnknown()) return HType.DOUBLE; |
| 350 if (other.isDouble()) return HType.DOUBLE; | |
| 351 if (other.isDoubleOrNull()) return HType.DOUBLE_OR_NULL; | |
| 217 if (other.isNumber()) return HType.NUMBER; | 352 if (other.isNumber()) return HType.NUMBER; |
| 353 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; | |
| 218 return HType.CONFLICTING; | 354 return HType.CONFLICTING; |
| 219 } | 355 } |
| 220 | 356 |
| 221 HType intersection(HType other) { | 357 HType intersection(HType other) { |
| 222 if (other.isUnknown()) return HType.DOUBLE; | 358 if (other.isUnknown()) return HType.DOUBLE; |
| 359 if (other.isIntegerOrNull()) return HType.CONFLICTING; | |
| 223 if (other.isInteger()) return HType.CONFLICTING; | 360 if (other.isInteger()) return HType.CONFLICTING; |
| 224 if (other.isNumber()) return this; | 361 if (other.isDouble()) return HType.DOUBLE; |
| 362 if (other.isDoubleOrNull()) return HType.DOUBLE; | |
| 363 if (other.isNumber()) return HType.DOUBLE; | |
| 364 if (other.isNumberOrNull()) return HType.DOUBLE; | |
| 225 return HType.CONFLICTING; | 365 return HType.CONFLICTING; |
| 226 } | 366 } |
| 227 } | 367 } |
| 228 | 368 |
| 229 class HIndexablePrimitiveType extends HPrimitiveType { | 369 class HIndexablePrimitiveType extends HPrimitiveType { |
| 230 const HIndexablePrimitiveType(); | 370 const HIndexablePrimitiveType(); |
| 231 bool isIndexablePrimitive() => true; | 371 bool isIndexablePrimitive() => true; |
| 232 String toString() => "indexable"; | 372 String toString() => "indexable"; |
| 233 | 373 |
| 234 Type computeType(Compiler compiler) { | 374 Type computeType(Compiler compiler) { |
| 235 // TODO(ngeoffray): Represent union types. | 375 // TODO(ngeoffray): Represent union types. |
| 236 return null; | 376 return null; |
| 237 } | 377 } |
| 238 | 378 |
| 239 HType union(HType other) { | 379 HType union(HType other) { |
| 240 if (other.isIndexablePrimitive() || other.isUnknown()) { | 380 if (other.isIndexablePrimitive() || other.isUnknown()) { |
| 241 return HType.INDEXABLE_PRIMITIVE; | 381 return HType.INDEXABLE_PRIMITIVE; |
| 242 } | 382 } |
| 243 return HType.CONFLICTING; | 383 return HType.CONFLICTING; |
| 244 } | 384 } |
| 245 | 385 |
| 246 HType intersection(HType other) { | 386 HType intersection(HType other) { |
| 247 if (other.isUnknown()) return HType.INDEXABLE_PRIMITIVE; | 387 if (other.isUnknown()) return HType.INDEXABLE_PRIMITIVE; |
| 248 if (other.isIndexablePrimitive()) return other; | 388 if (other.isIndexablePrimitive()) return other; |
| 249 return HType.CONFLICTING; | 389 return HType.CONFLICTING; |
| 250 } | 390 } |
| 251 } | 391 } |
| 252 | 392 |
| 393 class HStringOrNullType extends HPrimitiveOrNullType { | |
| 394 const HStringOrNullType(); | |
| 395 bool isStringOrNull() => true; | |
| 396 String toString() => "String or null"; | |
| 397 | |
| 398 Type computeType(Compiler compiler) { | |
| 399 return compiler.stringClass.computeType(compiler); | |
| 400 } | |
| 401 | |
| 402 HType union(HType other) { | |
| 403 if (other.isUnknown()) return HType.STRING_OR_NULL; | |
| 404 if (other.isString()) return HType.STRING_OR_NULL; | |
| 405 if (other.isStringOrNull()) return HType.STRING_OR_NULL; | |
| 406 return HType.CONFLICTING; | |
|
floitsch
2012/05/10 10:29:43
Add comment why indexable + null-string is conflic
ngeoffray
2012/05/11 10:17:54
Done.
| |
| 407 } | |
| 408 | |
| 409 HType intersection(HType other) { | |
| 410 if (other.isUnknown()) return HType.STRING_OR_NULL; | |
| 411 if (other.isString()) return HType.STRING; | |
| 412 if (other.isStringOrNull()) return HType.STRING_OR_NULL; | |
| 413 if (other.isArray()) return HType.CONFLICTING; | |
| 414 if (other.isIndexablePrimitive()) return HType.STRING; | |
| 415 return HType.CONFLICTING; | |
| 416 } | |
| 417 } | |
| 418 | |
| 253 class HStringType extends HIndexablePrimitiveType { | 419 class HStringType extends HIndexablePrimitiveType { |
| 254 const HStringType(); | 420 const HStringType(); |
| 255 bool isString() => true; | 421 bool isString() => true; |
| 256 String toString() => "String"; | 422 String toString() => "String"; |
| 257 | 423 |
| 258 Type computeType(Compiler compiler) { | 424 Type computeType(Compiler compiler) { |
| 259 return compiler.stringClass.computeType(compiler); | 425 return compiler.stringClass.computeType(compiler); |
| 260 } | 426 } |
| 261 | 427 |
| 262 HType union(HType other) { | 428 HType union(HType other) { |
| 263 if (other.isString() || other.isUnknown()) return HType.STRING; | 429 if (other.isUnknown()) return HType.STRING; |
| 430 if (other.isString()) return HType.STRING; | |
| 431 if (other.isStringOrNull()) return HType.STRING_OR_NULL; | |
| 264 if (other.isIndexablePrimitive()) return HType.INDEXABLE_PRIMITIVE; | 432 if (other.isIndexablePrimitive()) return HType.INDEXABLE_PRIMITIVE; |
| 265 return HType.CONFLICTING; | 433 return HType.CONFLICTING; |
| 266 } | 434 } |
| 267 | 435 |
| 268 HType intersection(HType other) { | 436 HType intersection(HType other) { |
| 269 if (other.isString() || other.isUnknown()) return HType.STRING; | 437 if (other.isUnknown()) return HType.STRING; |
| 438 if (other.isString()) return HType.STRING; | |
| 270 if (other.isArray()) return HType.CONFLICTING; | 439 if (other.isArray()) return HType.CONFLICTING; |
| 271 if (other.isIndexablePrimitive()) return HType.STRING; | 440 if (other.isIndexablePrimitive()) return HType.STRING; |
| 441 if (other.isStringOrNull()) return HType.STRING; | |
| 272 return HType.CONFLICTING; | 442 return HType.CONFLICTING; |
| 273 } | 443 } |
| 274 } | 444 } |
| 275 | 445 |
| 276 class HReadableArrayType extends HIndexablePrimitiveType { | 446 class HReadableArrayType extends HIndexablePrimitiveType { |
| 277 const HReadableArrayType(); | 447 const HReadableArrayType(); |
| 278 bool isReadableArray() => true; | 448 bool isReadableArray() => true; |
| 279 String toString() => "readable array"; | 449 String toString() => "readable array"; |
| 280 | 450 |
| 281 Type computeType(Compiler compiler) { | 451 Type computeType(Compiler compiler) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 HType combine(HType other) { | 554 HType combine(HType other) { |
| 385 if (other.isExact()) { | 555 if (other.isExact()) { |
| 386 HExactType concrete = other; | 556 HExactType concrete = other; |
| 387 if (this.type === concrete.type) return this; | 557 if (this.type === concrete.type) return this; |
| 388 } | 558 } |
| 389 if (other.isUnknown()) return this; | 559 if (other.isUnknown()) return this; |
| 390 return HType.CONFLICTING; | 560 return HType.CONFLICTING; |
| 391 } | 561 } |
| 392 } | 562 } |
| 393 | 563 |
| 394 class HBoundedPotentialPrimitiveArray extends HBoundedType { | 564 class HBoundedPotentialPrimitiveType extends HBoundedType { |
| 565 const HBoundedPotentialPrimitiveType(Type type, bool canBeNull) | |
| 566 : super(type, canBeNull); | |
| 567 bool canBePrimitive() => true; | |
| 568 } | |
| 569 | |
| 570 class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType { | |
| 395 const HBoundedPotentialPrimitiveArray(Type type, bool canBeNull) | 571 const HBoundedPotentialPrimitiveArray(Type type, bool canBeNull) |
| 396 : super(type, canBeNull); | 572 : super(type, canBeNull); |
| 397 bool canBePrimitive() => true; | |
| 398 | 573 |
| 399 HType combine(HType other) { | 574 HType combine(HType other) { |
| 400 if (other.isReadableArray()) return other; | 575 if (other.isReadableArray()) return other; |
| 401 if (other.isIndexablePrimitive()) return HType.READABLE_ARRAY; | 576 if (other.isIndexablePrimitive()) return HType.READABLE_ARRAY; |
|
floitsch
2012/05/10 10:29:43
no. If other isString and combine is used for inte
ngeoffray
2012/05/11 10:17:54
Done.
| |
| 402 return super.combine(other); | 577 return super.combine(other); |
| 403 } | 578 } |
| 404 } | 579 } |
| 405 | 580 |
| 406 class HBoundedPotentialPrimitiveString extends HBoundedType { | 581 class HBoundedPotentialPrimitiveString extends HBoundedPotentialPrimitiveType { |
| 407 const HBoundedPotentialPrimitiveString(Type type, bool canBeNull) | 582 const HBoundedPotentialPrimitiveString(Type type, bool canBeNull) |
| 408 : super(type, canBeNull); | 583 : super(type, canBeNull); |
| 409 bool canBePrimitive() => true; | |
| 410 | 584 |
| 411 HType combine(HType other) { | 585 HType combine(HType other) { |
| 412 if (other.isString()) return other; | 586 if (other.isString()) return other; |
| 413 if (other.isIndexablePrimitive()) return HType.STRING; | 587 if (other.isIndexablePrimitive()) return HType.STRING; |
|
floitsch
2012/05/10 10:29:43
ditto.
ngeoffray
2012/05/11 10:17:54
Done.
| |
| 414 return super.combine(other); | 588 return super.combine(other); |
| 415 } | 589 } |
| 416 } | 590 } |
| OLD | NEW |