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 factory HType.fromBoundedType(Type type, Compiler compiler) { | 8 factory HType.fromBoundedType(Type type, |
|
floitsch
2012/05/07 09:50:07
/***/ doc explaining what boundedType means.
ngeoffray
2012/05/07 13:15:42
Done.
| |
| 9 Compiler compiler, | |
| 10 [bool canBeNull = false]) { | |
| 9 Element element = type.element; | 11 Element element = type.element; |
| 10 if (element.kind === ElementKind.TYPE_VARIABLE) { | 12 if (element.kind === ElementKind.TYPE_VARIABLE) { |
| 11 compiler.unimplemented("type variables"); | 13 compiler.unimplemented("type variables"); |
| 12 } | 14 } |
| 13 | 15 |
| 14 if (element === compiler.intClass) { | 16 if (!canBeNull) { |
| 15 return HType.INTEGER; | 17 if (element === compiler.intClass) { |
| 16 } else if (element === compiler.numClass) { | 18 return HType.INTEGER; |
| 17 return HType.NUMBER; | 19 } else if (element === compiler.numClass) { |
| 18 } else if (element === compiler.doubleClass) { | 20 return HType.NUMBER; |
| 19 return HType.DOUBLE; | 21 } else if (element === compiler.doubleClass) { |
| 20 } else if (element === compiler.stringClass) { | 22 return HType.DOUBLE; |
| 21 return HType.STRING; | 23 } else if (element === compiler.stringClass) { |
| 22 } else if (element === compiler.listClass | 24 return HType.STRING; |
| 23 || Elements.isStringSupertype(element, compiler) | 25 } else if (element === compiler.boolClass) { |
| 24 || Elements.isListSupertype(element, compiler)) { | 26 return HType.BOOLEAN; |
| 25 return new HBoundedPotentialPrimitiveType(type); | 27 } |
| 28 } | |
| 29 if (element === compiler.listClass | |
| 30 || Elements.isListSupertype(element, compiler)) { | |
| 31 return new HBoundedPotentialPrimitiveArray(type, canBeNull); | |
| 32 } else if (Elements.isStringSupertype(element, compiler)) { | |
| 33 return new HBoundedPotentialPrimitiveString(type, canBeNull); | |
| 34 } else if (element === compiler.objectClass | |
| 35 || element === compiler.dynamicClass) { | |
| 36 return null; | |
| 37 } else if (element === compiler.intClass | |
| 38 || element === compiler.boolClass | |
| 39 || element === compiler.numClass | |
| 40 || element === compiler.doubleClass | |
| 41 || element === compiler.stringClass) { | |
| 42 // TODO(ngeoffray): Create primitive nullable types. | |
| 43 return null; | |
|
floitsch
2012/05/07 09:50:07
Please don't return 'null' from a factory.
I would
ngeoffray
2012/05/07 13:15:42
I plan on changing that. I added a TODO here and w
| |
| 26 } else { | 44 } else { |
| 27 return new HBoundedType(type); | 45 return new HBoundedType(type, canBeNull); |
| 28 } | 46 } |
| 29 } | 47 } |
| 30 | 48 |
| 31 static final HType CONFLICTING = const HAnalysisType("conflicting"); | 49 static final HType CONFLICTING = const HAnalysisType("conflicting"); |
| 32 static final HType UNKNOWN = const HAnalysisType("unknown"); | 50 static final HType UNKNOWN = const HAnalysisType("unknown"); |
| 33 static final HType BOOLEAN = const HBooleanType(); | 51 static final HType BOOLEAN = const HBooleanType(); |
| 34 static final HType NUMBER = const HNumberType(); | 52 static final HType NUMBER = const HNumberType(); |
| 35 static final HType INTEGER = const HIntegerType(); | 53 static final HType INTEGER = const HIntegerType(); |
| 36 static final HType DOUBLE = const HDoubleType(); | 54 static final HType DOUBLE = const HDoubleType(); |
| 37 static final HType INDEXABLE_PRIMITIVE = const HIndexablePrimitiveType(); | 55 static final HType INDEXABLE_PRIMITIVE = const HIndexablePrimitiveType(); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 HType intersection(HType other) { | 339 HType intersection(HType other) { |
| 322 if (this === other || other.isUnknown()) return HType.EXTENDABLE_ARRAY; | 340 if (this === other || other.isUnknown()) return HType.EXTENDABLE_ARRAY; |
| 323 if (other.isString()) return HType.CONFLICTING; | 341 if (other.isString()) return HType.CONFLICTING; |
| 324 if (other.isIndexablePrimitive()) return HType.EXTENDABLE_ARRAY; | 342 if (other.isIndexablePrimitive()) return HType.EXTENDABLE_ARRAY; |
| 325 return HType.CONFLICTING; | 343 return HType.CONFLICTING; |
| 326 } | 344 } |
| 327 } | 345 } |
| 328 | 346 |
| 329 class HBoundedType extends HType { | 347 class HBoundedType extends HType { |
| 330 final Type type; | 348 final Type type; |
| 349 final bool _canBeNull; | |
| 331 | 350 |
| 332 const HBoundedType(Type this.type); | 351 bool canBeNull() => _canBeNull; |
| 352 | |
| 353 const HBoundedType(Type this.type, [bool this._canBeNull = false]); | |
| 333 String toString() => type.toString(); | 354 String toString() => type.toString(); |
| 334 | 355 |
| 335 Type computeType(Compiler compiler) => type; | 356 Type computeType(Compiler compiler) => type; |
| 336 | 357 |
| 337 HType combine(HType other) { | 358 HType combine(HType other) { |
| 338 if (other is HBoundedType) { | 359 if (other is HBoundedType) { |
| 339 HBoundedType temp = other; | 360 HBoundedType temp = other; |
| 340 // Return [other] in case it is an exact type. | 361 // Return [other] in case it is an exact type. |
| 341 if (this.type === temp.type) return other; | 362 if (this.type === temp.type) return other; |
| 342 } | 363 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 362 HType combine(HType other) { | 383 HType combine(HType other) { |
| 363 if (other.isExact()) { | 384 if (other.isExact()) { |
| 364 HExactType concrete = other; | 385 HExactType concrete = other; |
| 365 if (this.type === concrete.type) return this; | 386 if (this.type === concrete.type) return this; |
| 366 } | 387 } |
| 367 if (other.isUnknown()) return this; | 388 if (other.isUnknown()) return this; |
| 368 return HType.CONFLICTING; | 389 return HType.CONFLICTING; |
| 369 } | 390 } |
| 370 } | 391 } |
| 371 | 392 |
| 372 class HBoundedPotentialPrimitiveType extends HBoundedType { | 393 class HBoundedPotentialPrimitiveArray extends HBoundedType { |
| 373 const HBoundedPotentialPrimitiveType(Type type) : super(type); | 394 const HBoundedPotentialPrimitiveArray(Type type, bool canBeNull) |
| 395 : super(type, canBeNull); | |
| 374 bool canBePrimitive() => true; | 396 bool canBePrimitive() => true; |
| 397 | |
| 398 HType combine(HType other) { | |
| 399 if (other.isReadableArray()) return other; | |
| 400 if (other.isIndexablePrimitive()) return HType.READABLE_ARRAY; | |
| 401 return super.combine(other); | |
| 402 } | |
| 375 } | 403 } |
| 404 | |
| 405 class HBoundedPotentialPrimitiveString extends HBoundedType { | |
| 406 const HBoundedPotentialPrimitiveString(Type type, bool canBeNull) | |
| 407 : super(type, canBeNull); | |
| 408 bool canBePrimitive() => true; | |
| 409 | |
| 410 HType combine(HType other) { | |
| 411 if (other.isString()) return other; | |
| 412 if (other.isIndexablePrimitive) return HType.STRING; | |
| 413 return super.combine(other); | |
| 414 } | |
| 415 } | |
| OLD | NEW |