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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/unsugar.dart

Issue 737353002: cps-ir: Implement boolean conversion in and use it to implement '&&', '||', and '?:'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
Index: pkg/compiler/lib/src/js_backend/codegen/unsugar.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart b/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ec8303d256f016fb75518c73e45a3327c61635e3
--- /dev/null
+++ b/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart
@@ -0,0 +1,48 @@
+library dart2js.unsugar_cps;
+
+import '../../cps_ir/cps_ir_nodes.dart';
+
+// TODO(karlklose): share the [ParentVisitor].
+import 'package:compiler/src/cps_ir/optimizers.dart';
+
+class Boolify extends IsTrue {
+ Boolify(Primitive expression) : super(expression);
+ accept(Visitor visitor) => visitor.visitBoolify(this);
+}
+
+/// Rewrites the initial CPS IR to make Dart semantics explicit.
+///
+/// Performs the following rewrites:
+/// - Branch(IsTrue(v), c1, c2) -> Branch(Boolify(v), c1, c2)
+class UnsugarVisitor extends RecursiveVisitor {
+ const UnsugarVisitor();
+
+ void rewrite(FunctionDefinition function) {
+ // Set all parent pointers.
+ new ParentVisitor().visit(function);
+ visit(function);
+ }
+
+ @override
+ Node visit(Node node) {
+ Node result = node.accept(this);
+ return result != null ? result : node;
+ }
+
+ visitBranch(Branch node) {
+ // Create new node.
+ IsTrue condition = node.condition;
+ Branch newNode = new Branch(
+ new Boolify(condition.value.definition),
+ node.trueContinuation.definition,
+ node.falseContinuation.definition);
+ // Replace the node in the parent context.
+ InteriorNode parent = node.parent;
+ parent.body = newNode;
+ newNode.parent = parent;
+ // Remove stale referenced.
sigurdm 2014/11/20 12:47:28 reference*s*
+ condition.value.unlink();
+ node.trueContinuation.unlink();
+ node.falseContinuation.unlink();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698