OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 part of dart2js; | |
6 | |
7 abstract class Operation { | |
8 String get name; | |
9 } | |
10 | |
11 abstract class UnaryOperation extends Operation { | |
12 /** Returns [:null:] if it was unable to fold the operation. */ | |
13 ConstantValue fold(ConstantValue constant); | |
14 } | |
15 | |
16 abstract class BinaryOperation extends Operation { | |
17 /** Returns [:null:] if it was unable to fold the operation. */ | |
18 ConstantValue fold(ConstantValue left, ConstantValue right); | |
19 apply(left, right); | |
20 } | |
21 | |
22 /** | |
23 * A [ConstantSystem] is responsible for creating constants and folding them. | |
24 */ | |
25 abstract class ConstantSystem { | |
26 BinaryOperation get add; | |
27 BinaryOperation get bitAnd; | |
28 UnaryOperation get bitNot; | |
29 BinaryOperation get bitOr; | |
30 BinaryOperation get bitXor; | |
31 BinaryOperation get booleanAnd; | |
32 BinaryOperation get booleanOr; | |
33 BinaryOperation get divide; | |
34 BinaryOperation get equal; | |
35 BinaryOperation get greaterEqual; | |
36 BinaryOperation get greater; | |
37 BinaryOperation get identity; | |
38 BinaryOperation get lessEqual; | |
39 BinaryOperation get less; | |
40 BinaryOperation get modulo; | |
41 BinaryOperation get multiply; | |
42 UnaryOperation get negate; | |
43 UnaryOperation get not; | |
44 BinaryOperation get shiftLeft; | |
45 BinaryOperation get shiftRight; | |
46 BinaryOperation get subtract; | |
47 BinaryOperation get truncatingDivide; | |
48 | |
49 const ConstantSystem(); | |
50 | |
51 ConstantValue createInt(int i); | |
52 ConstantValue createDouble(double d); | |
53 ConstantValue createString(DartString string); | |
54 ConstantValue createBool(bool value); | |
55 ConstantValue createNull(); | |
56 ConstantValue createMap(Compiler compiler, | |
57 InterfaceType type, | |
58 List<ConstantValue> keys, | |
59 List<ConstantValue> values); | |
60 | |
61 // We need to special case the subtype check for JavaScript constant | |
62 // system because an int is a double at runtime. | |
63 bool isSubtype(Compiler compiler, DartType s, DartType t); | |
64 | |
65 /** Returns true if the [constant] is an integer at runtime. */ | |
66 bool isInt(ConstantValue constant); | |
67 /** Returns true if the [constant] is a double at runtime. */ | |
68 bool isDouble(ConstantValue constant); | |
69 /** Returns true if the [constant] is a string at runtime. */ | |
70 bool isString(ConstantValue constant); | |
71 /** Returns true if the [constant] is a boolean at runtime. */ | |
72 bool isBool(ConstantValue constant); | |
73 /** Returns true if the [constant] is null at runtime. */ | |
74 bool isNull(ConstantValue constant); | |
75 | |
76 UnaryOperation lookupUnary(String operator) { | |
77 switch (operator) { | |
78 case '~': return bitNot; | |
79 case '-': return negate; | |
80 case '!': return not; | |
81 default: return null; | |
82 } | |
83 } | |
84 | |
85 BinaryOperation lookupBinary(String operator) { | |
86 switch (operator) { | |
87 case "+": return add; | |
88 case "-": return subtract; | |
89 case "*": return multiply; | |
90 case "/": return divide; | |
91 case "%": return modulo; | |
92 case "~/": return truncatingDivide; | |
93 case "|": return bitOr; | |
94 case "&": return bitAnd; | |
95 case "^": return bitXor; | |
96 case "||": return booleanOr; | |
97 case "&&": return booleanAnd; | |
98 case "<<": return shiftLeft; | |
99 case ">>": return shiftRight; | |
100 case "<": return less; | |
101 case "<=": return lessEqual; | |
102 case ">": return greater; | |
103 case ">=": return greaterEqual; | |
104 case "==": return equal; | |
105 default: return null; | |
106 } | |
107 } | |
108 } | |
OLD | NEW |