| 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 js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); | 7 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); |
| 8 | 8 |
| 9 class JavaScriptBitNotOperation extends BitNotOperation { | 9 class JavaScriptBitNotOperation extends BitNotOperation { |
| 10 const JavaScriptBitNotOperation(); | 10 const JavaScriptBitNotOperation(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (constant.isInt) { | 90 if (constant.isInt) { |
| 91 IntConstantValue intConstant = constant; | 91 IntConstantValue intConstant = constant; |
| 92 if (intConstant.primitiveValue == 0) { | 92 if (intConstant.primitiveValue == 0) { |
| 93 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0); | 93 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 return dartNegateOperation.fold(constant); | 96 return dartNegateOperation.fold(constant); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 class JavaScriptAddOperation implements BinaryOperation { |
| 101 final _addOperation = const AddOperation(); |
| 102 String get name => _addOperation.name; |
| 103 |
| 104 const JavaScriptAddOperation(); |
| 105 |
| 106 ConstantValue fold(ConstantValue left, ConstantValue right) { |
| 107 ConstantValue result = _addOperation.fold(left, right); |
| 108 if (result != null && result.isNum) { |
| 109 return JAVA_SCRIPT_CONSTANT_SYSTEM.convertToJavaScriptConstant(result); |
| 110 } |
| 111 return result; |
| 112 } |
| 113 |
| 114 apply(left, right) => _addOperation.apply(left, right); |
| 115 } |
| 116 |
| 100 class JavaScriptBinaryArithmeticOperation implements BinaryOperation { | 117 class JavaScriptBinaryArithmeticOperation implements BinaryOperation { |
| 101 final BinaryOperation dartArithmeticOperation; | 118 final BinaryOperation dartArithmeticOperation; |
| 102 | 119 |
| 103 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation); | 120 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation); |
| 104 | 121 |
| 105 String get name => dartArithmeticOperation.name; | 122 String get name => dartArithmeticOperation.name; |
| 106 | 123 |
| 107 ConstantValue fold(ConstantValue left, ConstantValue right) { | 124 ConstantValue fold(ConstantValue left, ConstantValue right) { |
| 108 ConstantValue result = dartArithmeticOperation.fold(left, right); | 125 ConstantValue result = dartArithmeticOperation.fold(left, right); |
| 109 if (result == null) return result; | 126 if (result == null) return result; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 139 } | 156 } |
| 140 | 157 |
| 141 /** | 158 /** |
| 142 * Constant system following the semantics for Dart code that has been | 159 * Constant system following the semantics for Dart code that has been |
| 143 * compiled to JavaScript. | 160 * compiled to JavaScript. |
| 144 */ | 161 */ |
| 145 class JavaScriptConstantSystem extends ConstantSystem { | 162 class JavaScriptConstantSystem extends ConstantSystem { |
| 146 final int BITS31 = 0x8FFFFFFF; | 163 final int BITS31 = 0x8FFFFFFF; |
| 147 final int BITS32 = 0xFFFFFFFF; | 164 final int BITS32 = 0xFFFFFFFF; |
| 148 | 165 |
| 149 final add = const JavaScriptBinaryArithmeticOperation(const AddOperation()); | 166 final add = const JavaScriptAddOperation(); |
| 150 final bitAnd = const JavaScriptBinaryBitOperation(const BitAndOperation()); | 167 final bitAnd = const JavaScriptBinaryBitOperation(const BitAndOperation()); |
| 151 final bitNot = const JavaScriptBitNotOperation(); | 168 final bitNot = const JavaScriptBitNotOperation(); |
| 152 final bitOr = const JavaScriptBinaryBitOperation(const BitOrOperation()); | 169 final bitOr = const JavaScriptBinaryBitOperation(const BitOrOperation()); |
| 153 final bitXor = const JavaScriptBinaryBitOperation(const BitXorOperation()); | 170 final bitXor = const JavaScriptBinaryBitOperation(const BitXorOperation()); |
| 154 final booleanAnd = const BooleanAndOperation(); | 171 final booleanAnd = const BooleanAndOperation(); |
| 155 final booleanOr = const BooleanOrOperation(); | 172 final booleanOr = const BooleanOrOperation(); |
| 156 final divide = | 173 final divide = |
| 157 const JavaScriptBinaryArithmeticOperation(const DivideOperation()); | 174 const JavaScriptBinaryArithmeticOperation(const DivideOperation()); |
| 158 final equal = const EqualsOperation(); | 175 final equal = const EqualsOperation(); |
| 159 final greaterEqual = const GreaterEqualOperation(); | 176 final greaterEqual = const GreaterEqualOperation(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 result.add(keyList); | 353 result.add(keyList); |
| 337 } else { | 354 } else { |
| 338 // Add the keys individually to avoid generating an unused list constant | 355 // Add the keys individually to avoid generating an unused list constant |
| 339 // for the keys. | 356 // for the keys. |
| 340 result.addAll(keys); | 357 result.addAll(keys); |
| 341 } | 358 } |
| 342 result.addAll(values); | 359 result.addAll(values); |
| 343 return result; | 360 return result; |
| 344 } | 361 } |
| 345 } | 362 } |
| OLD | NEW |