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

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: 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..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) {
« 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