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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library dart2js.unsugar_cps;
2
3 import '../../cps_ir/cps_ir_nodes.dart';
4
5 // TODO(karlklose): share the [ParentVisitor].
6 import 'package:compiler/src/cps_ir/optimizers.dart';
7
8 class Boolify extends IsTrue {
9 Boolify(Primitive expression) : super(expression);
10 accept(Visitor visitor) => visitor.visitBoolify(this);
11 }
12
13 /// Rewrites the initial CPS IR to make Dart semantics explicit.
14 ///
15 /// Performs the following rewrites:
16 /// - Branch(IsTrue(v), c1, c2) -> Branch(Boolify(v), c1, c2)
17 class UnsugarVisitor extends RecursiveVisitor {
18 const UnsugarVisitor();
19
20 void rewrite(FunctionDefinition function) {
21 // Set all parent pointers.
22 new ParentVisitor().visit(function);
23 visit(function);
24 }
25
26 @override
27 Node visit(Node node) {
28 Node result = node.accept(this);
29 return result != null ? result : node;
30 }
31
32 visitBranch(Branch node) {
33 // Create new node.
34 IsTrue condition = node.condition;
35 Branch newNode = new Branch(
36 new Boolify(condition.value.definition),
37 node.trueContinuation.definition,
38 node.falseContinuation.definition);
39 // Replace the node in the parent context.
40 InteriorNode parent = node.parent;
41 parent.body = newNode;
42 newNode.parent = parent;
43 // Remove stale referenced.
sigurdm 2014/11/20 12:47:28 reference*s*
44 condition.value.unlink();
45 node.trueContinuation.unlink();
46 node.falseContinuation.unlink();
47 }
48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698