| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 class EqualsOperation implements BinaryOperation { | 260 class EqualsOperation implements BinaryOperation { |
| 261 const EqualsOperation(); | 261 const EqualsOperation(); |
| 262 Constant fold(Constant left, Constant right) { | 262 Constant fold(Constant left, Constant right) { |
| 263 if (left.isNum() && right.isNum()) { | 263 if (left.isNum() && right.isNum()) { |
| 264 // Numbers need to be treated specially because: NaN != NaN, -0.0 == 0.0, | 264 // Numbers need to be treated specially because: NaN != NaN, -0.0 == 0.0, |
| 265 // and 1 == 1.0. | 265 // and 1 == 1.0. |
| 266 NumConstant leftNum = left; | 266 NumConstant leftNum = left; |
| 267 NumConstant rightNum = right; | 267 NumConstant rightNum = right; |
| 268 return new BoolConstant(leftNum.value == rightNum.value); | 268 return new BoolConstant(leftNum.value == rightNum.value); |
| 269 } | 269 } |
| 270 if (left.isConstructedObject()) { |
| 271 // Unless we know that the user-defined object does not implement the |
| 272 // equality operator we cannot fold here. |
| 273 return null; |
| 274 } |
| 270 return new BoolConstant(left == right); | 275 return new BoolConstant(left == right); |
| 271 } | 276 } |
| 272 } | 277 } |
| 273 | 278 |
| 274 class IdentityOperation implements BinaryOperation { | 279 class IdentityOperation implements BinaryOperation { |
| 275 const IdentityOperation(); | 280 const IdentityOperation(); |
| 276 Constant fold(Constant left, Constant right) { | 281 Constant fold(Constant left, Constant right) { |
| 277 return new BoolConstant(left == right); | 282 return new BoolConstant(left == right); |
| 278 } | 283 } |
| 279 } | 284 } |
| OLD | NEW |