| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 abstract class Operation { | 7 abstract class Operation { |
| 8 String get name; | 8 String get name; |
| 9 } | 9 } |
| 10 | 10 |
| 11 abstract class UnaryOperation extends Operation { | 11 abstract class UnaryOperation extends Operation { |
| 12 /** Returns [:null:] if it was unable to fold the operation. */ | 12 /** Returns [:null:] if it was unable to fold the operation. */ |
| 13 Constant fold(Constant constant); | 13 ConstantValue fold(ConstantValue constant); |
| 14 } | 14 } |
| 15 | 15 |
| 16 abstract class BinaryOperation extends Operation { | 16 abstract class BinaryOperation extends Operation { |
| 17 /** Returns [:null:] if it was unable to fold the operation. */ | 17 /** Returns [:null:] if it was unable to fold the operation. */ |
| 18 Constant fold(Constant left, Constant right); | 18 ConstantValue fold(ConstantValue left, ConstantValue right); |
| 19 apply(left, right); | 19 apply(left, right); |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * A [ConstantSystem] is responsible for creating constants and folding them. | 23 * A [ConstantSystem] is responsible for creating constants and folding them. |
| 24 */ | 24 */ |
| 25 abstract class ConstantSystem { | 25 abstract class ConstantSystem { |
| 26 BinaryOperation get add; | 26 BinaryOperation get add; |
| 27 BinaryOperation get bitAnd; | 27 BinaryOperation get bitAnd; |
| 28 UnaryOperation get bitNot; | 28 UnaryOperation get bitNot; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 BinaryOperation get multiply; | 41 BinaryOperation get multiply; |
| 42 UnaryOperation get negate; | 42 UnaryOperation get negate; |
| 43 UnaryOperation get not; | 43 UnaryOperation get not; |
| 44 BinaryOperation get shiftLeft; | 44 BinaryOperation get shiftLeft; |
| 45 BinaryOperation get shiftRight; | 45 BinaryOperation get shiftRight; |
| 46 BinaryOperation get subtract; | 46 BinaryOperation get subtract; |
| 47 BinaryOperation get truncatingDivide; | 47 BinaryOperation get truncatingDivide; |
| 48 | 48 |
| 49 const ConstantSystem(); | 49 const ConstantSystem(); |
| 50 | 50 |
| 51 Constant createInt(int i); | 51 ConstantValue createInt(int i); |
| 52 Constant createDouble(double d); | 52 ConstantValue createDouble(double d); |
| 53 Constant createString(DartString string); | 53 ConstantValue createString(DartString string); |
| 54 Constant createBool(bool value); | 54 ConstantValue createBool(bool value); |
| 55 Constant createNull(); | 55 ConstantValue createNull(); |
| 56 Constant createMap(Compiler compiler, InterfaceType type, | 56 ConstantValue createMap(Compiler compiler, |
| 57 List<Constant> keys, List<Constant> values); | 57 InterfaceType type, |
| 58 List<ConstantValue> keys, |
| 59 List<ConstantValue> values); |
| 58 | 60 |
| 59 // We need to special case the subtype check for JavaScript constant | 61 // We need to special case the subtype check for JavaScript constant |
| 60 // system because an int is a double at runtime. | 62 // system because an int is a double at runtime. |
| 61 bool isSubtype(Compiler compiler, DartType s, DartType t); | 63 bool isSubtype(Compiler compiler, DartType s, DartType t); |
| 62 | 64 |
| 63 /** Returns true if the [constant] is an integer at runtime. */ | 65 /** Returns true if the [constant] is an integer at runtime. */ |
| 64 bool isInt(Constant constant); | 66 bool isInt(ConstantValue constant); |
| 65 /** Returns true if the [constant] is a double at runtime. */ | 67 /** Returns true if the [constant] is a double at runtime. */ |
| 66 bool isDouble(Constant constant); | 68 bool isDouble(ConstantValue constant); |
| 67 /** Returns true if the [constant] is a string at runtime. */ | 69 /** Returns true if the [constant] is a string at runtime. */ |
| 68 bool isString(Constant constant); | 70 bool isString(ConstantValue constant); |
| 69 /** Returns true if the [constant] is a boolean at runtime. */ | 71 /** Returns true if the [constant] is a boolean at runtime. */ |
| 70 bool isBool(Constant constant); | 72 bool isBool(ConstantValue constant); |
| 71 /** Returns true if the [constant] is null at runtime. */ | 73 /** Returns true if the [constant] is null at runtime. */ |
| 72 bool isNull(Constant constant); | 74 bool isNull(ConstantValue constant); |
| 73 | 75 |
| 74 UnaryOperation lookupUnary(String operator) { | 76 UnaryOperation lookupUnary(String operator) { |
| 75 switch (operator) { | 77 switch (operator) { |
| 76 case '~': return bitNot; | 78 case '~': return bitNot; |
| 77 case '-': return negate; | 79 case '-': return negate; |
| 78 case '!': return not; | 80 case '!': return not; |
| 79 default: return null; | 81 default: return null; |
| 80 } | 82 } |
| 81 } | 83 } |
| 82 | 84 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 97 case ">>": return shiftRight; | 99 case ">>": return shiftRight; |
| 98 case "<": return less; | 100 case "<": return less; |
| 99 case "<=": return lessEqual; | 101 case "<=": return lessEqual; |
| 100 case ">": return greater; | 102 case ">": return greater; |
| 101 case ">=": return greaterEqual; | 103 case ">=": return greaterEqual; |
| 102 case "==": return equal; | 104 case "==": return equal; |
| 103 default: return null; | 105 default: return null; |
| 104 } | 106 } |
| 105 } | 107 } |
| 106 } | 108 } |
| OLD | NEW |