Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: frog/leg/operations.dart

Issue 9810027: Allow constant folding of && and ||. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « frog/leg/compile_time_constants.dart ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/operations.dart
diff --git a/frog/leg/operations.dart b/frog/leg/operations.dart
index 0f5ea51f6da5595c823b0b0c52191e0a2d913875..8ad5427d01f1e2d320ded4f8f4d14d8bcd74c2a2 100644
--- a/frog/leg/operations.dart
+++ b/frog/leg/operations.dart
@@ -105,6 +105,31 @@ class ShiftRightOperation extends BinaryIntOperation {
}
}
+class BinaryBoolOperation implements BinaryOperation {
+ const BinaryBoolOperation();
+ Constant fold(Constant left, Constant right) {
Lasse Reichstein Nielsen 2012/03/27 07:48:53 This seems like a pretty weak folding, if it requi
+ if (left.isBool() && right.isBool()) {
+ BoolConstant leftBool = left;
+ BoolConstant rightBool = right;
+ bool resultValue = foldBools(leftBool.value, rightBool.value);
+ return new BoolConstant(resultValue);
+ }
+ return null;
Lasse Reichstein Nielsen 2012/03/27 07:48:53 If left or right are not boolean, you can still fo
+ }
+
+ 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) {
« no previous file with comments | « frog/leg/compile_time_constants.dart ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698