Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 if (constant.isInt) { | 89 if (constant.isInt) { |
| 90 IntConstant intConstant = constant; | 90 IntConstant intConstant = constant; |
| 91 if (intConstant.value == 0) { | 91 if (intConstant.value == 0) { |
| 92 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0); | 92 return JAVA_SCRIPT_CONSTANT_SYSTEM.createDouble(-0.0); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 return dartNegateOperation.fold(constant); | 95 return dartNegateOperation.fold(constant); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 class JavaScriptAddOperation implements BinaryOperation { | |
| 100 final _addOperation = const AddOperation(); | |
| 101 String get name => _addOperation.name; | |
| 102 | |
| 103 const JavaScriptAddOperation(); | |
| 104 | |
| 105 Constant fold(Constant left, Constant right) { | |
| 106 Constant result = _addOperation.fold(left, right); | |
| 107 if (result == null || result.isString) return result; | |
|
Johnni Winther
2014/09/24 09:29:22
This is not needed since convertToJavaScriptConsta
floitsch
2014/09/24 12:53:19
True, but it is typed to take a NumConstant and re
Johnni Winther
2014/09/25 09:07:56
Then I think I'd prefer to only call convertToJava
floitsch
2014/09/25 12:29:05
Done.
| |
| 108 return JAVA_SCRIPT_CONSTANT_SYSTEM.convertToJavaScriptConstant(result); | |
| 109 } | |
| 110 | |
| 111 apply(left, right) => _addOperation.apply(left, right); | |
| 112 } | |
| 113 | |
| 99 class JavaScriptBinaryArithmeticOperation implements BinaryOperation { | 114 class JavaScriptBinaryArithmeticOperation implements BinaryOperation { |
| 100 final BinaryOperation dartArithmeticOperation; | 115 final BinaryOperation dartArithmeticOperation; |
| 101 | 116 |
| 102 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation); | 117 const JavaScriptBinaryArithmeticOperation(this.dartArithmeticOperation); |
| 103 | 118 |
| 104 String get name => dartArithmeticOperation.name; | 119 String get name => dartArithmeticOperation.name; |
| 105 | 120 |
| 106 Constant fold(Constant left, Constant right) { | 121 Constant fold(Constant left, Constant right) { |
| 107 Constant result = dartArithmeticOperation.fold(left, right); | 122 Constant result = dartArithmeticOperation.fold(left, right); |
| 108 if (result == null) return result; | 123 if (result == null) return result; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 138 } | 153 } |
| 139 | 154 |
| 140 /** | 155 /** |
| 141 * Constant system following the semantics for Dart code that has been | 156 * Constant system following the semantics for Dart code that has been |
| 142 * compiled to JavaScript. | 157 * compiled to JavaScript. |
| 143 */ | 158 */ |
| 144 class JavaScriptConstantSystem extends ConstantSystem { | 159 class JavaScriptConstantSystem extends ConstantSystem { |
| 145 final int BITS31 = 0x8FFFFFFF; | 160 final int BITS31 = 0x8FFFFFFF; |
| 146 final int BITS32 = 0xFFFFFFFF; | 161 final int BITS32 = 0xFFFFFFFF; |
| 147 | 162 |
| 148 final add = const JavaScriptBinaryArithmeticOperation(const AddOperation()); | 163 final add = const JavaScriptAddOperation(); |
| 149 final bitAnd = const JavaScriptBinaryBitOperation(const BitAndOperation()); | 164 final bitAnd = const JavaScriptBinaryBitOperation(const BitAndOperation()); |
| 150 final bitNot = const JavaScriptBitNotOperation(); | 165 final bitNot = const JavaScriptBitNotOperation(); |
| 151 final bitOr = const JavaScriptBinaryBitOperation(const BitOrOperation()); | 166 final bitOr = const JavaScriptBinaryBitOperation(const BitOrOperation()); |
| 152 final bitXor = const JavaScriptBinaryBitOperation(const BitXorOperation()); | 167 final bitXor = const JavaScriptBinaryBitOperation(const BitXorOperation()); |
| 153 final booleanAnd = const BooleanAndOperation(); | 168 final booleanAnd = const BooleanAndOperation(); |
| 154 final booleanOr = const BooleanOrOperation(); | 169 final booleanOr = const BooleanOrOperation(); |
| 155 final divide = | 170 final divide = |
| 156 const JavaScriptBinaryArithmeticOperation(const DivideOperation()); | 171 const JavaScriptBinaryArithmeticOperation(const DivideOperation()); |
| 157 final equal = const EqualsOperation(); | 172 final equal = const EqualsOperation(); |
| 158 final greaterEqual = const GreaterEqualOperation(); | 173 final greaterEqual = const GreaterEqualOperation(); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 result.add(keyList); | 347 result.add(keyList); |
| 333 } else { | 348 } else { |
| 334 // Add the keys individually to avoid generating an unused list constant | 349 // Add the keys individually to avoid generating an unused list constant |
| 335 // for the keys. | 350 // for the keys. |
| 336 result.addAll(keys); | 351 result.addAll(keys); |
| 337 } | 352 } |
| 338 result.addAll(values); | 353 result.addAll(values); |
| 339 return result; | 354 return result; |
| 340 } | 355 } |
| 341 } | 356 } |
| OLD | NEW |