| 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 '../dart2jslib.dart' show Compiler; | 8 import '../dart2jslib.dart' show Compiler; |
| 9 import '../resolution/operators.dart'; |
| 9 import '../tree/tree.dart' show DartString; | 10 import '../tree/tree.dart' show DartString; |
| 10 import 'values.dart'; | 11 import 'values.dart'; |
| 11 | 12 |
| 12 abstract class Operation { | 13 abstract class Operation { |
| 13 String get name; | 14 String get name; |
| 14 } | 15 } |
| 15 | 16 |
| 16 abstract class UnaryOperation extends Operation { | 17 abstract class UnaryOperation extends Operation { |
| 17 /** Returns [:null:] if it was unable to fold the operation. */ | 18 /** Returns [:null:] if it was unable to fold the operation. */ |
| 18 ConstantValue fold(ConstantValue constant); | 19 ConstantValue fold(ConstantValue constant); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 bool isInt(ConstantValue constant); | 74 bool isInt(ConstantValue constant); |
| 74 /** Returns true if the [constant] is a double at runtime. */ | 75 /** Returns true if the [constant] is a double at runtime. */ |
| 75 bool isDouble(ConstantValue constant); | 76 bool isDouble(ConstantValue constant); |
| 76 /** Returns true if the [constant] is a string at runtime. */ | 77 /** Returns true if the [constant] is a string at runtime. */ |
| 77 bool isString(ConstantValue constant); | 78 bool isString(ConstantValue constant); |
| 78 /** Returns true if the [constant] is a boolean at runtime. */ | 79 /** Returns true if the [constant] is a boolean at runtime. */ |
| 79 bool isBool(ConstantValue constant); | 80 bool isBool(ConstantValue constant); |
| 80 /** Returns true if the [constant] is null at runtime. */ | 81 /** Returns true if the [constant] is null at runtime. */ |
| 81 bool isNull(ConstantValue constant); | 82 bool isNull(ConstantValue constant); |
| 82 | 83 |
| 83 UnaryOperation lookupUnary(String operator) { | 84 UnaryOperation lookupUnary(UnaryOperator operator) { |
| 84 switch (operator) { | 85 switch (operator.kind) { |
| 85 case '~': return bitNot; | 86 case UnaryOperatorKind.COMPLEMENT: return bitNot; |
| 86 case '-': return negate; | 87 case UnaryOperatorKind.NEGATE: return negate; |
| 87 case '!': return not; | 88 case UnaryOperatorKind.NOT: return not; |
| 88 default: return null; | 89 default: return null; |
| 89 } | 90 } |
| 90 } | 91 } |
| 91 | 92 |
| 92 BinaryOperation lookupBinary(String operator) { | 93 BinaryOperation lookupBinary(BinaryOperator operator) { |
| 93 switch (operator) { | 94 switch (operator.kind) { |
| 94 case "+": return add; | 95 case BinaryOperatorKind.ADD: return add; |
| 95 case "-": return subtract; | 96 case BinaryOperatorKind.SUB: return subtract; |
| 96 case "*": return multiply; | 97 case BinaryOperatorKind.MUL: return multiply; |
| 97 case "/": return divide; | 98 case BinaryOperatorKind.DIV: return divide; |
| 98 case "%": return modulo; | 99 case BinaryOperatorKind.MOD: return modulo; |
| 99 case "~/": return truncatingDivide; | 100 case BinaryOperatorKind.IDIV: return truncatingDivide; |
| 100 case "|": return bitOr; | 101 case BinaryOperatorKind.OR: return bitOr; |
| 101 case "&": return bitAnd; | 102 case BinaryOperatorKind.AND: return bitAnd; |
| 102 case "^": return bitXor; | 103 case BinaryOperatorKind.XOR: return bitXor; |
| 103 case "||": return booleanOr; | 104 case BinaryOperatorKind.LOGICAL_OR: return booleanOr; |
| 104 case "&&": return booleanAnd; | 105 case BinaryOperatorKind.LOGICAL_AND: return booleanAnd; |
| 105 case "<<": return shiftLeft; | 106 case BinaryOperatorKind.SHL: return shiftLeft; |
| 106 case ">>": return shiftRight; | 107 case BinaryOperatorKind.SHR: return shiftRight; |
| 107 case "<": return less; | 108 case BinaryOperatorKind.LT: return less; |
| 108 case "<=": return lessEqual; | 109 case BinaryOperatorKind.LTEQ: return lessEqual; |
| 109 case ">": return greater; | 110 case BinaryOperatorKind.GT: return greater; |
| 110 case ">=": return greaterEqual; | 111 case BinaryOperatorKind.GTEQ: return greaterEqual; |
| 111 case "==": return equal; | 112 case BinaryOperatorKind.EQ: return equal; |
| 112 default: return null; | 113 default: return null; |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 } | 116 } |
| OLD | NEW |