Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |