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 BinaryOperation get codeUnitAt; | |
50 | |
51 const ConstantSystem(); | |
52 | |
53 ConstantValue createInt(int i); | |
54 ConstantValue createDouble(double d); | |
55 ConstantValue createString(DartString string); | |
56 ConstantValue createBool(bool value); | |
57 ConstantValue createNull(); | |
58 ConstantValue createMap(Compiler compiler, | |
59 InterfaceType type, | |
60 List<ConstantValue> keys, | |
61 List<ConstantValue> values); | |
62 | |
63 // We need to special case the subtype check for JavaScript constant | |
64 // system because an int is a double at runtime. | |
65 bool isSubtype(Compiler compiler, DartType s, DartType t); | |
66 | |
67 /** Returns true if the [constant] is an integer at runtime. */ | |
68 bool isInt(ConstantValue constant); | |
69 /** Returns true if the [constant] is a double at runtime. */ | |
70 bool isDouble(ConstantValue constant); | |
71 /** Returns true if the [constant] is a string at runtime. */ | |
72 bool isString(ConstantValue constant); | |
73 /** Returns true if the [constant] is a boolean at runtime. */ | |
74 bool isBool(ConstantValue constant); | |
75 /** Returns true if the [constant] is null at runtime. */ | |
76 bool isNull(ConstantValue constant); | |
77 | |
78 UnaryOperation lookupUnary(String operator) { | |
79 switch (operator) { | |
80 case '~': return bitNot; | |
81 case '-': return negate; | |
82 case '!': return not; | |
83 default: return null; | |
84 } | |
85 } | |
86 | |
87 BinaryOperation lookupBinary(String operator) { | |
88 switch (operator) { | |
89 case "+": return add; | |
90 case "-": return subtract; | |
91 case "*": return multiply; | |
92 case "/": return divide; | |
93 case "%": return modulo; | |
94 case "~/": return truncatingDivide; | |
95 case "|": return bitOr; | |
96 case "&": return bitAnd; | |
97 case "^": return bitXor; | |
98 case "||": return booleanOr; | |
99 case "&&": return booleanAnd; | |
100 case "<<": return shiftLeft; | |
101 case ">>": return shiftRight; | |
102 case "<": return less; | |
103 case "<=": return lessEqual; | |
104 case ">": return greater; | |
105 case ">=": return greaterEqual; | |
106 case "==": return equal; | |
107 default: return null; | |
108 } | |
109 } | |
110 } | |
OLD | NEW |