| OLD | NEW |
| 1 library dart2js.unsugar_cps; | 1 library dart2js.unsugar_cps; |
| 2 | 2 |
| 3 import '../../cps_ir/cps_ir_nodes.dart'; | 3 import '../../cps_ir/cps_ir_nodes.dart'; |
| 4 | 4 |
| 5 // TODO(karlklose): share the [ParentVisitor]. | 5 // TODO(karlklose): share the [ParentVisitor]. |
| 6 import '../../cps_ir/optimizers.dart'; | 6 import '../../cps_ir/optimizers.dart'; |
| 7 import '../../constants/expressions.dart'; | 7 import '../../constants/expressions.dart'; |
| 8 import '../../constants/values.dart'; | 8 import '../../constants/values.dart'; |
| 9 import '../../elements/elements.dart' | 9 import '../../elements/elements.dart' |
| 10 show ClassElement, FieldElement, FunctionElement, Element; | 10 show ClassElement, FieldElement, FunctionElement, Element; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 | 31 |
| 32 @override | 32 @override |
| 33 visit(Node node) { | 33 visit(Node node) { |
| 34 Node result = node.accept(this); | 34 Node result = node.accept(this); |
| 35 return result != null ? result : node; | 35 return result != null ? result : node; |
| 36 } | 36 } |
| 37 | 37 |
| 38 Constant get trueConstant { | 38 Constant get trueConstant { |
| 39 return new Constant( | 39 return new Constant( |
| 40 new PrimitiveConstantExpression( | 40 new BoolConstantExpression( |
| 41 true, |
| 41 new TrueConstantValue())); | 42 new TrueConstantValue())); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void insertLetPrim(Primitive primitive, Expression node) { | 45 void insertLetPrim(Primitive primitive, Expression node) { |
| 45 LetPrim let = new LetPrim(primitive); | 46 LetPrim let = new LetPrim(primitive); |
| 46 InteriorNode parent = node.parent; | 47 InteriorNode parent = node.parent; |
| 47 parent.body = let; | 48 parent.body = let; |
| 48 let.body = node; | 49 let.body = node; |
| 49 node.parent = let; | 50 node.parent = let; |
| 50 let.parent = parent; | 51 let.parent = parent; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 Primitive intercepted = new Interceptor(receiver, interceptedClasses); | 129 Primitive intercepted = new Interceptor(receiver, interceptedClasses); |
| 129 insertLetPrim(intercepted, node); | 130 insertLetPrim(intercepted, node); |
| 130 node.arguments.insert(0, node.receiver); | 131 node.arguments.insert(0, node.receiver); |
| 131 node.callingConvention = CallingConvention.JS_INTERCEPTED; | 132 node.callingConvention = CallingConvention.JS_INTERCEPTED; |
| 132 assert(node.isValid); | 133 assert(node.isValid); |
| 133 node.receiver = new Reference<Primitive>(intercepted); | 134 node.receiver = new Reference<Primitive>(intercepted); |
| 134 } | 135 } |
| 135 | 136 |
| 136 Primitive makeNull() { | 137 Primitive makeNull() { |
| 137 NullConstantValue nullConst = new NullConstantValue(); | 138 NullConstantValue nullConst = new NullConstantValue(); |
| 138 return new Constant(new PrimitiveConstantExpression(nullConst)); | 139 return new Constant(new NullConstantExpression(nullConst)); |
| 139 } | 140 } |
| 140 | 141 |
| 141 processInvokeMethodDirectly(InvokeMethodDirectly node) { | 142 processInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 142 if (_glue.isInterceptedMethod(node.target)) { | 143 if (_glue.isInterceptedMethod(node.target)) { |
| 143 Primitive nullPrim = makeNull(); | 144 Primitive nullPrim = makeNull(); |
| 144 insertLetPrim(nullPrim, node); | 145 insertLetPrim(nullPrim, node); |
| 145 node.arguments.insert(0, node.receiver); | 146 node.arguments.insert(0, node.receiver); |
| 146 node.receiver = new Reference<Primitive>(nullPrim); | 147 node.receiver = new Reference<Primitive>(nullPrim); |
| 147 } | 148 } |
| 148 } | 149 } |
| 149 | 150 |
| 150 processBranch(Branch node) { | 151 processBranch(Branch node) { |
| 151 // TODO(karlklose): implement the checked mode part of boolean conversion. | 152 // TODO(karlklose): implement the checked mode part of boolean conversion. |
| 152 InteriorNode parent = node.parent; | 153 InteriorNode parent = node.parent; |
| 153 IsTrue condition = node.condition; | 154 IsTrue condition = node.condition; |
| 154 Primitive t = trueConstant; | 155 Primitive t = trueConstant; |
| 155 Primitive i = new Identical(condition.value.definition, t); | 156 Primitive i = new Identical(condition.value.definition, t); |
| 156 LetPrim newNode = new LetPrim(t, | 157 LetPrim newNode = new LetPrim(t, |
| 157 new LetPrim(i, | 158 new LetPrim(i, |
| 158 new Branch(new IsTrue(i), | 159 new Branch(new IsTrue(i), |
| 159 node.trueContinuation.definition, | 160 node.trueContinuation.definition, |
| 160 node.falseContinuation.definition))); | 161 node.falseContinuation.definition))); |
| 161 condition.value.unlink(); | 162 condition.value.unlink(); |
| 162 node.trueContinuation.unlink(); | 163 node.trueContinuation.unlink(); |
| 163 node.falseContinuation.unlink(); | 164 node.falseContinuation.unlink(); |
| 164 parent.body = newNode; | 165 parent.body = newNode; |
| 165 } | 166 } |
| 166 } | 167 } |
| OLD | NEW |