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 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 } | 98 } |
| 99 | 99 |
| 100 class ShiftRightOperation extends BinaryIntOperation { | 100 class ShiftRightOperation extends BinaryIntOperation { |
| 101 const ShiftRightOperation(); | 101 const ShiftRightOperation(); |
| 102 int foldInts(int left, int right) { | 102 int foldInts(int left, int right) { |
| 103 if (right < 0) return null; | 103 if (right < 0) return null; |
| 104 return left >> right; | 104 return left >> right; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 class BinaryBoolOperation implements BinaryOperation { | |
| 109 const BinaryBoolOperation(); | |
| 110 Constant fold(Constant left, Constant right) { | |
| 111 if (left.isBool() && right.isBool()) { | |
| 112 BoolConstant leftBool = left; | |
| 113 BoolConstant rightBool = right; | |
| 114 bool resultValue = foldBools(leftBool.value, rightBool.value); | |
| 115 if (resultValue === null) return null; | |
|
ngeoffray
2012/03/26 13:19:09
I believe this can never be true.
karlklose
2012/03/26 13:24:52
Not in the current subclasses, that is correct. I
| |
| 116 return new BoolConstant(resultValue); | |
| 117 } | |
| 118 return null; | |
| 119 } | |
| 120 | |
| 121 abstract bool foldBools(bool left, bool right); | |
| 122 } | |
| 123 | |
| 124 class BooleanAnd extends BinaryBoolOperation { | |
| 125 const BooleanAnd(); | |
| 126 bool foldBools(bool left, bool right) => left && right; | |
| 127 } | |
| 128 | |
| 129 class BooleanOr extends BinaryBoolOperation { | |
| 130 const BooleanOr(); | |
| 131 bool foldBools(bool left, bool right) => left || right; | |
| 132 } | |
| 133 | |
| 108 class ArithmeticNumOperation implements BinaryOperation { | 134 class ArithmeticNumOperation implements BinaryOperation { |
| 109 const ArithmeticNumOperation(); | 135 const ArithmeticNumOperation(); |
| 110 Constant fold(Constant left, Constant right) { | 136 Constant fold(Constant left, Constant right) { |
| 111 if (left.isNum() && right.isNum()) { | 137 if (left.isNum() && right.isNum()) { |
| 112 NumConstant leftNum = left; | 138 NumConstant leftNum = left; |
| 113 NumConstant rightNum = right; | 139 NumConstant rightNum = right; |
| 114 num foldedValue; | 140 num foldedValue; |
| 115 if (left.isInt() && right.isInt()) { | 141 if (left.isInt() && right.isInt()) { |
| 116 foldedValue = foldInts(leftNum.value, rightNum.value); | 142 foldedValue = foldInts(leftNum.value, rightNum.value); |
| 117 } else { | 143 } else { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 return new BoolConstant(left == right); | 271 return new BoolConstant(left == right); |
| 246 } | 272 } |
| 247 } | 273 } |
| 248 | 274 |
| 249 class IdentityOperation implements BinaryOperation { | 275 class IdentityOperation implements BinaryOperation { |
| 250 const IdentityOperation(); | 276 const IdentityOperation(); |
| 251 Constant fold(Constant left, Constant right) { | 277 Constant fold(Constant left, Constant right) { |
| 252 return new BoolConstant(left == right); | 278 return new BoolConstant(left == right); |
| 253 } | 279 } |
| 254 } | 280 } |
| OLD | NEW |