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 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); | 5 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); |
6 | 6 |
7 class JavaScriptBitNotOperation extends BitNotOperation { | 7 class JavaScriptBitNotOperation extends BitNotOperation { |
8 const JavaScriptBitNotOperation(); | 8 const JavaScriptBitNotOperation(); |
9 | 9 |
10 Constant fold(Constant constant) { | 10 Constant fold(Constant constant) { |
(...skipping 11 matching lines...) Expand all Loading... |
22 /** | 22 /** |
23 * In JavaScript we truncate the result to an unsigned 32 bit integer. Also, -0 | 23 * In JavaScript we truncate the result to an unsigned 32 bit integer. Also, -0 |
24 * is treated as if it was the integer 0. | 24 * is treated as if it was the integer 0. |
25 */ | 25 */ |
26 class JavaScriptBinaryBitOperation implements BinaryOperation { | 26 class JavaScriptBinaryBitOperation implements BinaryOperation { |
27 final BinaryBitOperation dartBitOperation; | 27 final BinaryBitOperation dartBitOperation; |
28 | 28 |
29 const JavaScriptBinaryBitOperation(this.dartBitOperation); | 29 const JavaScriptBinaryBitOperation(this.dartBitOperation); |
30 | 30 |
31 bool isUserDefinable() => dartBitOperation.isUserDefinable(); | 31 bool isUserDefinable() => dartBitOperation.isUserDefinable(); |
32 SourceString get name() => dartBitOperation.name; | 32 SourceString get name => dartBitOperation.name; |
33 | 33 |
34 Constant fold(Constant left, Constant right) { | 34 Constant fold(Constant left, Constant right) { |
35 // In JavaScript we don't check for -0 and treat it as if it was zero. | 35 // In JavaScript we don't check for -0 and treat it as if it was zero. |
36 if (left.isMinusZero()) left = DART_CONSTANT_SYSTEM.createInt(0); | 36 if (left.isMinusZero()) left = DART_CONSTANT_SYSTEM.createInt(0); |
37 if (right.isMinusZero()) right = DART_CONSTANT_SYSTEM.createInt(0); | 37 if (right.isMinusZero()) right = DART_CONSTANT_SYSTEM.createInt(0); |
38 IntConstant result = dartBitOperation.fold(left, right); | 38 IntConstant result = dartBitOperation.fold(left, right); |
39 if (result != null) { | 39 if (result != null) { |
40 // We convert the result of bit-operations to 32 bit unsigned integers. | 40 // We convert the result of bit-operations to 32 bit unsigned integers. |
41 return JAVA_SCRIPT_CONSTANT_SYSTEM.createInt32(result.value); | 41 return JAVA_SCRIPT_CONSTANT_SYSTEM.createInt32(result.value); |
42 } | 42 } |
(...skipping 26 matching lines...) Expand all Loading... |
69 return super.fold(left, right); | 69 return super.fold(left, right); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 class JavaScriptNegateOperation implements UnaryOperation { | 73 class JavaScriptNegateOperation implements UnaryOperation { |
74 final NegateOperation dartNegateOperation = const NegateOperation(); | 74 final NegateOperation dartNegateOperation = const NegateOperation(); |
75 | 75 |
76 const JavaScriptNegateOperation(); | 76 const JavaScriptNegateOperation(); |
77 | 77 |
78 bool isUserDefinable() => dartNegateOperation.isUserDefinable(); | 78 bool isUserDefinable() => dartNegateOperation.isUserDefinable(); |
79 SourceString get name() => dartNegateOperation.name; | 79 SourceString get name => dartNegateOperation.name; |
80 | 80 |
81 Constant fold(Constant constant) { | 81 Constant fold(Constant constant) { |
82 if (constant.isInt()) { | 82 if (constant.isInt()) { |
83 IntConstant intConstant = constant; | 83 IntConstant intConstant = constant; |
84 if (intConstant.value == 0) { | 84 if (intConstant.value == 0) { |
85 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0); | 85 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0); |
86 } | 86 } |
87 } | 87 } |
88 return dartNegateOperation.fold(constant); | 88 return dartNegateOperation.fold(constant); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 class JavaScriptBinaryArithmeticOperation implements BinaryOperation { | 92 class JavaScriptBinaryArithmeticOperation implements BinaryOperation { |
93 final BinaryOperation dartArithmeticOperation; | 93 final BinaryOperation dartArithmeticOperation; |
94 | 94 |
95 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation); | 95 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation); |
96 | 96 |
97 bool isUserDefinable() => dartArithmeticOperation.isUserDefinable(); | 97 bool isUserDefinable() => dartArithmeticOperation.isUserDefinable(); |
98 SourceString get name() => dartArithmeticOperation.name; | 98 SourceString get name => dartArithmeticOperation.name; |
99 | 99 |
100 Constant fold(Constant left, Constant right) { | 100 Constant fold(Constant left, Constant right) { |
101 Constant result = dartArithmeticOperation.fold(left, right); | 101 Constant result = dartArithmeticOperation.fold(left, right); |
102 if (result == null) return result; | 102 if (result == null) return result; |
103 return JAVA_SCRIPT_CONSTANT_SYSTEM.convertToJavaScriptConstant(result); | 103 return JAVA_SCRIPT_CONSTANT_SYSTEM.convertToJavaScriptConstant(result); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 class JavaScriptIdentityOperation implements BinaryOperation { | 107 class JavaScriptIdentityOperation implements BinaryOperation { |
108 final IdentityOperation dartIdentityOperation = const IdentityOperation(); | 108 final IdentityOperation dartIdentityOperation = const IdentityOperation(); |
109 | 109 |
110 const JavaScriptIdentityOperation(); | 110 const JavaScriptIdentityOperation(); |
111 | 111 |
112 bool isUserDefinable() => dartIdentityOperation.isUserDefinable(); | 112 bool isUserDefinable() => dartIdentityOperation.isUserDefinable(); |
113 SourceString get name() => dartIdentityOperation.name; | 113 SourceString get name => dartIdentityOperation.name; |
114 | 114 |
115 BoolConstant fold(Constant left, Constant right) { | 115 BoolConstant fold(Constant left, Constant right) { |
116 BoolConstant result = dartIdentityOperation.fold(left, right); | 116 BoolConstant result = dartIdentityOperation.fold(left, right); |
117 if (result == null || result.value) return result; | 117 if (result == null || result.value) return result; |
118 // In JavaScript -0.0 === 0 and all doubles are equal to their integer | 118 // In JavaScript -0.0 === 0 and all doubles are equal to their integer |
119 // values. Furthermore NaN !== NaN. | 119 // values. Furthermore NaN !== NaN. |
120 if (left.isNum() && right.isNum()) { | 120 if (left.isNum() && right.isNum()) { |
121 NumConstant leftNum = left; | 121 NumConstant leftNum = left; |
122 NumConstant rightNum = right; | 122 NumConstant rightNum = right; |
123 double leftDouble = leftNum.value.toDouble(); | 123 double leftDouble = leftNum.value.toDouble(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 NullConstant createNull() => new NullConstant(); | 211 NullConstant createNull() => new NullConstant(); |
212 | 212 |
213 // Integer checks don't verify that the number is not -0.0. | 213 // Integer checks don't verify that the number is not -0.0. |
214 bool isInt(Constant constant) => constant.isInt() || constant.isMinusZero(); | 214 bool isInt(Constant constant) => constant.isInt() || constant.isMinusZero(); |
215 bool isDouble(Constant constant) | 215 bool isDouble(Constant constant) |
216 => constant.isDouble() && !constant.isMinusZero(); | 216 => constant.isDouble() && !constant.isMinusZero(); |
217 bool isString(Constant constant) => constant.isString(); | 217 bool isString(Constant constant) => constant.isString(); |
218 bool isBool(Constant constant) => constant.isBool(); | 218 bool isBool(Constant constant) => constant.isBool(); |
219 bool isNull(Constant constant) => constant.isNull(); | 219 bool isNull(Constant constant) => constant.isNull(); |
220 } | 220 } |
OLD | NEW |