| 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 Constant implements Hashable { | 5 class Constant implements Hashable { |
| 6 const Constant(); | 6 const Constant(); |
| 7 | 7 |
| 8 bool isNull() => false; | 8 bool isNull() => false; |
| 9 bool isBool() => false; | 9 bool isBool() => false; |
| 10 bool isTrue() => false; | 10 bool isTrue() => false; |
| 11 bool isFalse() => false; | 11 bool isFalse() => false; |
| 12 bool isInt() => false; | 12 bool isInt() => false; |
| 13 bool isDouble() => false; | 13 bool isDouble() => false; |
| 14 bool isNum() => false; | 14 bool isNum() => false; |
| 15 bool isString() => false; | 15 bool isString() => false; |
| 16 bool isList() => false; | 16 bool isList() => false; |
| 17 bool isMap() => false; | 17 bool isMap() => false; |
| 18 bool isConstructedObject() => false; | 18 bool isConstructedObject() => false; |
| 19 /** Returns true if the constant is null, a bool, a number or a string. */ |
| 20 bool isPrimitive() => false; |
| 19 /** Returns true if the constant is a list, a map or a constructed object. */ | 21 /** Returns true if the constant is a list, a map or a constructed object. */ |
| 20 bool isObject() => false; | 22 bool isObject() => false; |
| 21 | 23 |
| 22 abstract void writeJsCode(StringBuffer buffer, ConstantHandler handler); | 24 abstract void writeJsCode(StringBuffer buffer, ConstantHandler handler); |
| 23 /** | 25 /** |
| 24 * Unless the constant can be emitted multiple times (as for numbers and | 26 * Unless the constant can be emitted multiple times (as for numbers and |
| 25 * strings) adds its canonical name to the buffer. | 27 * strings) adds its canonical name to the buffer. |
| 26 */ | 28 */ |
| 27 abstract void writeCanonicalizedJsCode(StringBuffer buffer, | 29 abstract void writeCanonicalizedJsCode(StringBuffer buffer, |
| 28 ConstantHandler handler); | 30 ConstantHandler handler); |
| 29 abstract List<Constant> getDependencies(); | 31 abstract List<Constant> getDependencies(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 class PrimitiveConstant extends Constant { | 34 class PrimitiveConstant extends Constant { |
| 33 abstract get value(); | 35 abstract get value(); |
| 34 const PrimitiveConstant(); | 36 const PrimitiveConstant(); |
| 37 bool isPrimitive() => true; |
| 35 | 38 |
| 36 bool operator ==(var other) { | 39 bool operator ==(var other) { |
| 37 if (other is !PrimitiveConstant) return false; | 40 if (other is !PrimitiveConstant) return false; |
| 38 PrimitiveConstant otherPrimitive = other; | 41 PrimitiveConstant otherPrimitive = other; |
| 39 // We use == instead of === so that DartStrings compare correctly. | 42 // We use == instead of === so that DartStrings compare correctly. |
| 40 return value == otherPrimitive.value; | 43 return value == otherPrimitive.value; |
| 41 } | 44 } |
| 42 | 45 |
| 43 String toString() => value.toString(); | 46 String toString() => value.toString(); |
| 44 // Primitive constants don't have dependencies. | 47 // Primitive constants don't have dependencies. |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 case "<=": | 873 case "<=": |
| 871 folded = const LessEqualOperation().fold(left, right); | 874 folded = const LessEqualOperation().fold(left, right); |
| 872 break; | 875 break; |
| 873 case ">": | 876 case ">": |
| 874 folded = const GreaterOperation().fold(left, right); | 877 folded = const GreaterOperation().fold(left, right); |
| 875 break; | 878 break; |
| 876 case ">=": | 879 case ">=": |
| 877 folded = const GreaterEqualOperation().fold(left, right); | 880 folded = const GreaterEqualOperation().fold(left, right); |
| 878 break; | 881 break; |
| 879 case "==": | 882 case "==": |
| 880 folded = const EqualsOperation().fold(left, right); | 883 if (left.isPrimitive() && right.isPrimitive()) { |
| 884 folded = const EqualsOperation().fold(left, right); |
| 885 } |
| 881 break; | 886 break; |
| 882 case "===": | 887 case "===": |
| 883 folded = const IdentityOperation().fold(left, right); | 888 if (left.isPrimitive() && right.isPrimitive()) { |
| 889 folded = const IdentityOperation().fold(left, right); |
| 890 } |
| 884 break; | 891 break; |
| 885 case "!=": | 892 case "!=": |
| 886 BoolConstant areEquals = const EqualsOperation().fold(left, right); | 893 if (left.isPrimitive() && right.isPrimitive()) { |
| 887 if (areEquals === null) { | 894 BoolConstant areEquals = const EqualsOperation().fold(left, right); |
| 888 folded = null; | 895 if (areEquals === null) { |
| 889 } else { | 896 folded = null; |
| 890 folded = areEquals.negate(); | 897 } else { |
| 898 folded = areEquals.negate(); |
| 899 } |
| 891 } | 900 } |
| 892 break; | 901 break; |
| 893 case "!==": | 902 case "!==": |
| 894 BoolConstant areIdentical = | 903 if (left.isPrimitive() && right.isPrimitive()) { |
| 895 const IdentityOperation().fold(left, right); | 904 BoolConstant areIdentical = |
| 896 if (areIdentical === null) { | 905 const IdentityOperation().fold(left, right); |
| 897 folded = null; | 906 if (areIdentical === null) { |
| 898 } else { | 907 folded = null; |
| 899 folded = areIdentical.negate(); | 908 } else { |
| 909 folded = areIdentical.negate(); |
| 910 } |
| 900 } | 911 } |
| 901 break; | 912 break; |
| 902 default: | 913 default: |
| 903 compiler.internalError("Unexpected operator.", node: op); | 914 compiler.internalError("Unexpected operator.", node: op); |
| 904 break; | 915 break; |
| 905 } | 916 } |
| 906 if (folded === null) error(send); | 917 if (folded === null) error(send); |
| 907 return folded; | 918 return folded; |
| 908 } | 919 } |
| 909 return super.visitSend(send); | 920 return super.visitSend(send); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 fieldValue = compiler.compileVariable(member); | 1106 fieldValue = compiler.compileVariable(member); |
| 1096 } | 1107 } |
| 1097 jsNewArguments.add(fieldValue); | 1108 jsNewArguments.add(fieldValue); |
| 1098 } | 1109 } |
| 1099 } | 1110 } |
| 1100 classElement = classElement.superclass; | 1111 classElement = classElement.superclass; |
| 1101 } | 1112 } |
| 1102 return jsNewArguments; | 1113 return jsNewArguments; |
| 1103 } | 1114 } |
| 1104 } | 1115 } |
| OLD | NEW |