| 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 an [HType] that represents [type] and all types that have | 9 * Returns an [HType] that represents [type] and all types that have |
| 10 * [type] as supertype. | 10 * [type] as supertype. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 return canBeNull ? HType.NUMBER_OR_NULL : HType.NUMBER; | 25 return canBeNull ? HType.NUMBER_OR_NULL : HType.NUMBER; |
| 26 } else if (element === compiler.doubleClass) { | 26 } else if (element === compiler.doubleClass) { |
| 27 return canBeNull ? HType.DOUBLE_OR_NULL : HType.DOUBLE; | 27 return canBeNull ? HType.DOUBLE_OR_NULL : HType.DOUBLE; |
| 28 } else if (element === compiler.stringClass) { | 28 } else if (element === compiler.stringClass) { |
| 29 return canBeNull ? HType.STRING_OR_NULL : HType.STRING; | 29 return canBeNull ? HType.STRING_OR_NULL : HType.STRING; |
| 30 } else if (element === compiler.boolClass) { | 30 } else if (element === compiler.boolClass) { |
| 31 return canBeNull ? HType.BOOLEAN_OR_NULL : HType.BOOLEAN; | 31 return canBeNull ? HType.BOOLEAN_OR_NULL : HType.BOOLEAN; |
| 32 } else if (element === compiler.listClass | 32 } else if (element === compiler.listClass |
| 33 || Elements.isListSupertype(element, compiler)) { | 33 || Elements.isListSupertype(element, compiler)) { |
| 34 return new HBoundedPotentialPrimitiveArray(type, canBeNull); | 34 return new HBoundedPotentialPrimitiveArray(type, canBeNull); |
| 35 } else if (Elements.isStringSupertype(element, compiler)) { | 35 } else if (Elements.isNumberOrStringSupertype(element, compiler)) { |
| 36 return new HBoundedPotentialPrimitiveNumberOrString(type, canBeNull); |
| 37 } else if (Elements.isStringOnlySupertype(element, compiler)) { |
| 36 return new HBoundedPotentialPrimitiveString(type, canBeNull); | 38 return new HBoundedPotentialPrimitiveString(type, canBeNull); |
| 37 } else { | 39 } else { |
| 38 return canBeNull ? new HBoundedType.withNull(type) | 40 return canBeNull ? new HBoundedType.withNull(type) |
| 39 : new HBoundedType.nonNull(type); | 41 : new HBoundedType.nonNull(type); |
| 40 } | 42 } |
| 41 } | 43 } |
| 42 | 44 |
| 43 static const HType CONFLICTING = const HConflictingType(); | 45 static const HType CONFLICTING = const HConflictingType(); |
| 44 static const HType UNKNOWN = const HUnknownType(); | 46 static const HType UNKNOWN = const HUnknownType(); |
| 45 static const HType BOOLEAN = const HBooleanType(); | 47 static const HType BOOLEAN = const HBooleanType(); |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 return HType.UNKNOWN; | 698 return HType.UNKNOWN; |
| 697 } | 699 } |
| 698 } | 700 } |
| 699 | 701 |
| 700 class HBoundedPotentialPrimitiveType extends HBoundedType { | 702 class HBoundedPotentialPrimitiveType extends HBoundedType { |
| 701 const HBoundedPotentialPrimitiveType(DartType type, bool canBeNull) | 703 const HBoundedPotentialPrimitiveType(DartType type, bool canBeNull) |
| 702 : super(type, canBeNull, false); | 704 : super(type, canBeNull, false); |
| 703 bool canBePrimitive() => true; | 705 bool canBePrimitive() => true; |
| 704 } | 706 } |
| 705 | 707 |
| 708 class HBoundedPotentialPrimitiveNumberOrString |
| 709 extends HBoundedPotentialPrimitiveType { |
| 710 const HBoundedPotentialPrimitiveNumberOrString(DartType type, bool canBeNull) |
| 711 : super(type, canBeNull); |
| 712 |
| 713 HType union(HType other) { |
| 714 if (other.isNumber()) return this; |
| 715 if (other.isNumberOrNull()) { |
| 716 if (canBeNull()) return this; |
| 717 return new HBoundedPotentialPrimitiveNumberOrString(type, true); |
| 718 } |
| 719 |
| 720 if (other.isString()) return this; |
| 721 if (other.isStringOrNull()) { |
| 722 if (canBeNull()) return this; |
| 723 return new HBoundedPotentialPrimitiveNumberOrString(type, true); |
| 724 } |
| 725 |
| 726 if (other.isNull()) { |
| 727 if (canBeNull()) return this; |
| 728 return new HBoundedPotentialPrimitiveNumberOrString(type, true); |
| 729 } |
| 730 |
| 731 return super.union(other); |
| 732 } |
| 733 |
| 734 HType intersection(HType other) { |
| 735 if (other.isNumber()) return other; |
| 736 if (other.isNumberOrNull()) { |
| 737 if (!canBeNull()) return HType.NUMBER; |
| 738 return other; |
| 739 } |
| 740 if (other.isString()) return other; |
| 741 if (other.isStringOrNull()) { |
| 742 if (!canBeNull()) return HType.STRING; |
| 743 return other; |
| 744 } |
| 745 return super.intersection(other); |
| 746 } |
| 747 } |
| 748 |
| 706 class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType { | 749 class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType { |
| 707 const HBoundedPotentialPrimitiveArray(DartType type, bool canBeNull) | 750 const HBoundedPotentialPrimitiveArray(DartType type, bool canBeNull) |
| 708 : super(type, canBeNull); | 751 : super(type, canBeNull); |
| 709 | 752 |
| 710 HType union(HType other) { | 753 HType union(HType other) { |
| 711 if (other.isString()) return HType.UNKNOWN; | 754 if (other.isString()) return HType.UNKNOWN; |
| 712 if (other.isReadableArray()) return this; | 755 if (other.isReadableArray()) return this; |
| 713 // TODO(ngeoffray): implement union types. | 756 // TODO(ngeoffray): implement union types. |
| 714 if (other.isIndexablePrimitive()) return HType.UNKNOWN; | 757 if (other.isIndexablePrimitive()) return HType.UNKNOWN; |
| 715 if (other.isNull()) { | 758 if (other.isNull()) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 operator [](HInstruction instruction) { | 819 operator [](HInstruction instruction) { |
| 777 HType result = _map[instruction]; | 820 HType result = _map[instruction]; |
| 778 if (result == null) return instruction.guaranteedType; | 821 if (result == null) return instruction.guaranteedType; |
| 779 return result; | 822 return result; |
| 780 } | 823 } |
| 781 | 824 |
| 782 operator []=(HInstruction instruction, HType value) { | 825 operator []=(HInstruction instruction, HType value) { |
| 783 _map[instruction] = value; | 826 _map[instruction] = value; |
| 784 } | 827 } |
| 785 } | 828 } |
| OLD | NEW |