Chromium Code Reviews| Index: frog/leg/operations.dart |
| diff --git a/frog/leg/operations.dart b/frog/leg/operations.dart |
| index 0f5ea51f6da5595c823b0b0c52191e0a2d913875..11304ddf7660231a076829a61184ea2d54795c10 100644 |
| --- a/frog/leg/operations.dart |
| +++ b/frog/leg/operations.dart |
| @@ -105,6 +105,32 @@ class ShiftRightOperation extends BinaryIntOperation { |
| } |
| } |
| +class BinaryBoolOperation implements BinaryOperation { |
| + const BinaryBoolOperation(); |
| + Constant fold(Constant left, Constant right) { |
| + if (left.isBool() && right.isBool()) { |
| + BoolConstant leftBool = left; |
| + BoolConstant rightBool = right; |
| + bool resultValue = foldBools(leftBool.value, rightBool.value); |
| + 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
|
| + return new BoolConstant(resultValue); |
| + } |
| + return null; |
| + } |
| + |
| + abstract bool foldBools(bool left, bool right); |
| +} |
| + |
| +class BooleanAnd extends BinaryBoolOperation { |
| + const BooleanAnd(); |
| + bool foldBools(bool left, bool right) => left && right; |
| +} |
| + |
| +class BooleanOr extends BinaryBoolOperation { |
| + const BooleanOr(); |
| + bool foldBools(bool left, bool right) => left || right; |
| +} |
| + |
| class ArithmeticNumOperation implements BinaryOperation { |
| const ArithmeticNumOperation(); |
| Constant fold(Constant left, Constant right) { |