| 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 library dart2js.constant_system; | 5 library dart2js.constant_system; |
| 6 | 6 |
| 7 import '../dart_types.dart'; | 7 import '../dart_types.dart'; |
| 8 import '../compiler.dart' show | 8 import '../compiler.dart' show Compiler; |
| 9 Compiler; | |
| 10 import '../resolution/operators.dart'; | 9 import '../resolution/operators.dart'; |
| 11 import '../tree/tree.dart' show | 10 import '../tree/tree.dart' show DartString; |
| 12 DartString; | |
| 13 import 'values.dart'; | 11 import 'values.dart'; |
| 14 | 12 |
| 15 abstract class Operation { | 13 abstract class Operation { |
| 16 String get name; | 14 String get name; |
| 17 } | 15 } |
| 18 | 16 |
| 19 abstract class UnaryOperation extends Operation { | 17 abstract class UnaryOperation extends Operation { |
| 20 /** Returns [:null:] if it was unable to fold the operation. */ | 18 /** Returns [:null:] if it was unable to fold the operation. */ |
| 21 ConstantValue fold(ConstantValue constant); | 19 ConstantValue fold(ConstantValue constant); |
| 22 } | 20 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 55 |
| 58 BinaryOperation get codeUnitAt; | 56 BinaryOperation get codeUnitAt; |
| 59 | 57 |
| 60 const ConstantSystem(); | 58 const ConstantSystem(); |
| 61 | 59 |
| 62 ConstantValue createInt(int i); | 60 ConstantValue createInt(int i); |
| 63 ConstantValue createDouble(double d); | 61 ConstantValue createDouble(double d); |
| 64 ConstantValue createString(DartString string); | 62 ConstantValue createString(DartString string); |
| 65 ConstantValue createBool(bool value); | 63 ConstantValue createBool(bool value); |
| 66 ConstantValue createNull(); | 64 ConstantValue createNull(); |
| 67 ConstantValue createList(InterfaceType type, | 65 ConstantValue createList(InterfaceType type, List<ConstantValue> values); |
| 68 List<ConstantValue> values); | |
| 69 // TODO(johnniwinther): Remove the need for [compiler]. | 66 // TODO(johnniwinther): Remove the need for [compiler]. |
| 70 ConstantValue createMap(Compiler compiler, | 67 ConstantValue createMap(Compiler compiler, InterfaceType type, |
| 71 InterfaceType type, | 68 List<ConstantValue> keys, List<ConstantValue> values); |
| 72 List<ConstantValue> keys, | |
| 73 List<ConstantValue> values); | |
| 74 // TODO(johnniwinther): Remove the need for [compiler]. | 69 // TODO(johnniwinther): Remove the need for [compiler]. |
| 75 ConstantValue createType(Compiler compiler, | 70 ConstantValue createType(Compiler compiler, DartType type); |
| 76 DartType type); | |
| 77 | 71 |
| 78 // We need to special case the subtype check for JavaScript constant | 72 // We need to special case the subtype check for JavaScript constant |
| 79 // system because an int is a double at runtime. | 73 // system because an int is a double at runtime. |
| 80 bool isSubtype(DartTypes types, DartType s, DartType t); | 74 bool isSubtype(DartTypes types, DartType s, DartType t); |
| 81 | 75 |
| 82 /** Returns true if the [constant] is an integer at runtime. */ | 76 /** Returns true if the [constant] is an integer at runtime. */ |
| 83 bool isInt(ConstantValue constant); | 77 bool isInt(ConstantValue constant); |
| 84 /** Returns true if the [constant] is a double at runtime. */ | 78 /** Returns true if the [constant] is a double at runtime. */ |
| 85 bool isDouble(ConstantValue constant); | 79 bool isDouble(ConstantValue constant); |
| 86 /** Returns true if the [constant] is a string at runtime. */ | 80 /** Returns true if the [constant] is a string at runtime. */ |
| 87 bool isString(ConstantValue constant); | 81 bool isString(ConstantValue constant); |
| 88 /** Returns true if the [constant] is a boolean at runtime. */ | 82 /** Returns true if the [constant] is a boolean at runtime. */ |
| 89 bool isBool(ConstantValue constant); | 83 bool isBool(ConstantValue constant); |
| 90 /** Returns true if the [constant] is null at runtime. */ | 84 /** Returns true if the [constant] is null at runtime. */ |
| 91 bool isNull(ConstantValue constant); | 85 bool isNull(ConstantValue constant); |
| 92 | 86 |
| 93 UnaryOperation lookupUnary(UnaryOperator operator) { | 87 UnaryOperation lookupUnary(UnaryOperator operator) { |
| 94 switch (operator.kind) { | 88 switch (operator.kind) { |
| 95 case UnaryOperatorKind.COMPLEMENT: return bitNot; | 89 case UnaryOperatorKind.COMPLEMENT: |
| 96 case UnaryOperatorKind.NEGATE: return negate; | 90 return bitNot; |
| 97 case UnaryOperatorKind.NOT: return not; | 91 case UnaryOperatorKind.NEGATE: |
| 98 default: return null; | 92 return negate; |
| 93 case UnaryOperatorKind.NOT: |
| 94 return not; |
| 95 default: |
| 96 return null; |
| 99 } | 97 } |
| 100 } | 98 } |
| 101 | 99 |
| 102 BinaryOperation lookupBinary(BinaryOperator operator) { | 100 BinaryOperation lookupBinary(BinaryOperator operator) { |
| 103 switch (operator.kind) { | 101 switch (operator.kind) { |
| 104 case BinaryOperatorKind.ADD: return add; | 102 case BinaryOperatorKind.ADD: |
| 105 case BinaryOperatorKind.SUB: return subtract; | 103 return add; |
| 106 case BinaryOperatorKind.MUL: return multiply; | 104 case BinaryOperatorKind.SUB: |
| 107 case BinaryOperatorKind.DIV: return divide; | 105 return subtract; |
| 108 case BinaryOperatorKind.MOD: return modulo; | 106 case BinaryOperatorKind.MUL: |
| 109 case BinaryOperatorKind.IDIV: return truncatingDivide; | 107 return multiply; |
| 110 case BinaryOperatorKind.OR: return bitOr; | 108 case BinaryOperatorKind.DIV: |
| 111 case BinaryOperatorKind.AND: return bitAnd; | 109 return divide; |
| 112 case BinaryOperatorKind.XOR: return bitXor; | 110 case BinaryOperatorKind.MOD: |
| 113 case BinaryOperatorKind.LOGICAL_OR: return booleanOr; | 111 return modulo; |
| 114 case BinaryOperatorKind.LOGICAL_AND: return booleanAnd; | 112 case BinaryOperatorKind.IDIV: |
| 115 case BinaryOperatorKind.SHL: return shiftLeft; | 113 return truncatingDivide; |
| 116 case BinaryOperatorKind.SHR: return shiftRight; | 114 case BinaryOperatorKind.OR: |
| 117 case BinaryOperatorKind.LT: return less; | 115 return bitOr; |
| 118 case BinaryOperatorKind.LTEQ: return lessEqual; | 116 case BinaryOperatorKind.AND: |
| 119 case BinaryOperatorKind.GT: return greater; | 117 return bitAnd; |
| 120 case BinaryOperatorKind.GTEQ: return greaterEqual; | 118 case BinaryOperatorKind.XOR: |
| 121 case BinaryOperatorKind.EQ: return equal; | 119 return bitXor; |
| 122 case BinaryOperatorKind.IF_NULL: return ifNull; | 120 case BinaryOperatorKind.LOGICAL_OR: |
| 123 default: return null; | 121 return booleanOr; |
| 122 case BinaryOperatorKind.LOGICAL_AND: |
| 123 return booleanAnd; |
| 124 case BinaryOperatorKind.SHL: |
| 125 return shiftLeft; |
| 126 case BinaryOperatorKind.SHR: |
| 127 return shiftRight; |
| 128 case BinaryOperatorKind.LT: |
| 129 return less; |
| 130 case BinaryOperatorKind.LTEQ: |
| 131 return lessEqual; |
| 132 case BinaryOperatorKind.GT: |
| 133 return greater; |
| 134 case BinaryOperatorKind.GTEQ: |
| 135 return greaterEqual; |
| 136 case BinaryOperatorKind.EQ: |
| 137 return equal; |
| 138 case BinaryOperatorKind.IF_NULL: |
| 139 return ifNull; |
| 140 default: |
| 141 return null; |
| 124 } | 142 } |
| 125 } | 143 } |
| 126 } | 144 } |
| OLD | NEW |