| 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 | 6 |
| 7 } | 7 } |
| 8 | 8 |
| 9 interface UnaryOperation extends Operation { | 9 interface UnaryOperation extends Operation { |
| 10 /** Returns [:null:] if it was unable to fold the operation. */ | 10 /** Returns [:null:] if it was unable to fold the operation. */ |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Constant fold(Constant left, Constant right) { | 110 Constant fold(Constant left, Constant right) { |
| 111 if (left.isNum() && right.isNum()) { | 111 if (left.isNum() && right.isNum()) { |
| 112 NumConstant leftNum = left; | 112 NumConstant leftNum = left; |
| 113 NumConstant rightNum = right; | 113 NumConstant rightNum = right; |
| 114 num foldedValue; | 114 num foldedValue; |
| 115 if (left.isInt() && right.isInt()) { | 115 if (left.isInt() && right.isInt()) { |
| 116 foldedValue = foldInts(leftNum.value, rightNum.value); | 116 foldedValue = foldInts(leftNum.value, rightNum.value); |
| 117 } else { | 117 } else { |
| 118 foldedValue = foldNums(leftNum.value, rightNum.value); | 118 foldedValue = foldNums(leftNum.value, rightNum.value); |
| 119 } | 119 } |
| 120 assert(foldedValue != null); | 120 // A division by 0 means that we might not have a folded value. |
| 121 if (foldedValue === null) return null; |
| 121 if (left.isInt() && right.isInt() && !isDivide()) { | 122 if (left.isInt() && right.isInt() && !isDivide()) { |
| 122 assert(foldedValue is int); | 123 assert(foldedValue is int); |
| 123 return new IntConstant(foldedValue); | 124 return new IntConstant(foldedValue); |
| 124 } else { | 125 } else { |
| 125 return new DoubleConstant(foldedValue); | 126 return new DoubleConstant(foldedValue); |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 } | 129 } |
| 129 | 130 |
| 130 bool isDivide() => false; | 131 bool isDivide() => false; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 return new BoolConstant(left == right); | 245 return new BoolConstant(left == right); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 248 class IdentityOperation implements BinaryOperation { | 249 class IdentityOperation implements BinaryOperation { |
| 249 const IdentityOperation(); | 250 const IdentityOperation(); |
| 250 Constant fold(Constant left, Constant right) { | 251 Constant fold(Constant left, Constant right) { |
| 251 return new BoolConstant(left == right); | 252 return new BoolConstant(left == right); |
| 252 } | 253 } |
| 253 } | 254 } |
| OLD | NEW |