| 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 interface Operation { | 5 interface Operation { |
| 6 final SourceString name; | 6 final SourceString name; |
| 7 bool isUserDefinable(); | 7 bool isUserDefinable(); |
| 8 } | 8 } |
| 9 | 9 |
| 10 interface UnaryOperation extends Operation { | 10 interface UnaryOperation extends Operation { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 161 } |
| 162 // A division by 0 means that we might not have a folded value. | 162 // A division by 0 means that we might not have a folded value. |
| 163 if (foldedValue === null) return null; | 163 if (foldedValue === null) return null; |
| 164 if (left.isInt() && right.isInt() && !isDivide()) { | 164 if (left.isInt() && right.isInt() && !isDivide()) { |
| 165 assert(foldedValue is int); | 165 assert(foldedValue is int); |
| 166 return new IntConstant(foldedValue); | 166 return new IntConstant(foldedValue); |
| 167 } else { | 167 } else { |
| 168 return new DoubleConstant(foldedValue); | 168 return new DoubleConstant(foldedValue); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 return null; |
| 171 } | 172 } |
| 172 | 173 |
| 173 bool isDivide() => false; | 174 bool isDivide() => false; |
| 174 num foldInts(int left, int right) => foldNums(left, right); | 175 num foldInts(int left, int right) => foldNums(left, right); |
| 175 abstract num foldNums(num left, num right); | 176 abstract num foldNums(num left, num right); |
| 176 } | 177 } |
| 177 | 178 |
| 178 class SubtractOperation extends ArithmeticNumOperation { | 179 class SubtractOperation extends ArithmeticNumOperation { |
| 179 final SourceString name = const SourceString('-'); | 180 final SourceString name = const SourceString('-'); |
| 180 const SubtractOperation(); | 181 const SubtractOperation(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 bool isUserDefinable() => false; | 313 bool isUserDefinable() => false; |
| 313 const IdentityOperation(); | 314 const IdentityOperation(); |
| 314 Constant fold(Constant left, Constant right) { | 315 Constant fold(Constant left, Constant right) { |
| 315 // In order to preserve runtime semantics which says that NaN !== NaN don't | 316 // In order to preserve runtime semantics which says that NaN !== NaN don't |
| 316 // constant fold NaN === NaN. Otherwise the output depends on inlined | 317 // constant fold NaN === NaN. Otherwise the output depends on inlined |
| 317 // variables and other optimizations. | 318 // variables and other optimizations. |
| 318 if (left.isNaN() && right.isNaN()) return null; | 319 if (left.isNaN() && right.isNaN()) return null; |
| 319 return new BoolConstant(left == right); | 320 return new BoolConstant(left == right); |
| 320 } | 321 } |
| 321 } | 322 } |
| OLD | NEW |