| 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 '../../cps_ir/optimizers.dart'; |
| 7 import '../../constants/expressions.dart'; |
| 8 import '../../constants/values.dart'; |
| 9 |
| 10 /// Rewrites the initial CPS IR to make Dart semantics explicit and inserts |
| 11 /// special nodes that respect JavaScript behavior. |
| 12 /// |
| 13 /// Performs the following rewrites: |
| 14 /// - rewrite [IsTrue] in a [Branch] to do boolean conversion. |
| 15 class UnsugarVisitor extends RecursiveVisitor { |
| 16 const UnsugarVisitor(); |
| 17 |
| 18 void rewrite(FunctionDefinition function) { |
| 19 // Set all parent pointers. |
| 20 new ParentVisitor().visit(function); |
| 21 visit(function); |
| 22 } |
| 23 |
| 24 @override |
| 25 visit(Node node) { |
| 26 Node result = node.accept(this); |
| 27 return result != null ? result : node; |
| 28 } |
| 29 |
| 30 Constant get trueConstant { |
| 31 return new Constant( |
| 32 new PrimitiveConstantExpression( |
| 33 new TrueConstantValue())); |
| 34 } |
| 35 |
| 36 processBranch(Branch node) { |
| 37 // TODO(karlklose): implement the checked mode part of boolean conversion. |
| 38 InteriorNode parent = node.parent; |
| 39 IsTrue condition = node.condition; |
| 40 Primitive t = trueConstant; |
| 41 Primitive i = new Identical(condition.value.definition, t); |
| 42 LetPrim newNode = new LetPrim(t, |
| 43 new LetPrim(i, |
| 44 new Branch(new IsTrue(i), |
| 45 node.trueContinuation.definition, |
| 46 node.falseContinuation.definition))); |
| 47 condition.value.unlink(); |
| 48 node.trueContinuation.unlink(); |
| 49 node.falseContinuation.unlink(); |
| 50 parent.body = newNode; |
| 51 } |
| 52 } |
| OLD | NEW |