| 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' show ClassElement, FieldElement; | 9 import '../../elements/elements.dart' show ClassElement, FieldElement, Element; |
| 10 import '../../js_backend/codegen/glue.dart'; | 10 import '../../js_backend/codegen/glue.dart'; |
| 11 import '../../dart2jslib.dart' show Selector; | 11 import '../../dart2jslib.dart' show Selector, World; |
| 12 | 12 |
| 13 /// Rewrites the initial CPS IR to make Dart semantics explicit and inserts | 13 /// Rewrites the initial CPS IR to make Dart semantics explicit and inserts |
| 14 /// special nodes that respect JavaScript behavior. | 14 /// special nodes that respect JavaScript behavior. |
| 15 /// | 15 /// |
| 16 /// Performs the following rewrites: | 16 /// Performs the following rewrites: |
| 17 /// - rewrite [IsTrue] in a [Branch] to do boolean conversion. | 17 /// - rewrite [IsTrue] in a [Branch] to do boolean conversion. |
| 18 class UnsugarVisitor extends RecursiveVisitor { | 18 class UnsugarVisitor extends RecursiveVisitor { |
| 19 Glue _glue; | 19 Glue _glue; |
| 20 | 20 |
| 21 UnsugarVisitor(this._glue); | 21 UnsugarVisitor(this._glue); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 LetPrim let = new LetPrim(primitive); | 42 LetPrim let = new LetPrim(primitive); |
| 43 InteriorNode parent = node.parent; | 43 InteriorNode parent = node.parent; |
| 44 parent.body = let; | 44 parent.body = let; |
| 45 let.body = node; | 45 let.body = node; |
| 46 node.parent = let; | 46 node.parent = let; |
| 47 let.parent = parent; | 47 let.parent = parent; |
| 48 } | 48 } |
| 49 | 49 |
| 50 processInvokeMethod(InvokeMethod node) { | 50 processInvokeMethod(InvokeMethod node) { |
| 51 Selector selector = node.selector; | 51 Selector selector = node.selector; |
| 52 // TODO(karlklose): should we rewrite all selectors? |
| 52 if (!_glue.isInterceptedSelector(selector)) return; | 53 if (!_glue.isInterceptedSelector(selector)) return; |
| 53 | 54 |
| 54 if (!selector.isCall && !selector.isOperator) { | 55 Primitive receiver = node.receiver.definition; |
| 55 // TODO(karlklose): handle special selectors. | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 Set<ClassElement> interceptedClasses = | 56 Set<ClassElement> interceptedClasses = |
| 60 _glue.getInterceptedClassesOn(selector); | 57 _glue.getInterceptedClassesOn(selector); |
| 61 _glue.registerSpecializedGetInterceptor(interceptedClasses); | 58 _glue.registerSpecializedGetInterceptor(interceptedClasses); |
| 62 | 59 |
| 63 Primitive receiver = node.receiver.definition; | |
| 64 Primitive intercepted = new Interceptor(receiver, interceptedClasses); | 60 Primitive intercepted = new Interceptor(receiver, interceptedClasses); |
| 65 insertLetPrim(intercepted, node); | 61 insertLetPrim(intercepted, node); |
| 66 node.arguments.insert(0, node.receiver); | 62 node.arguments.insert(0, node.receiver); |
| 67 node.receiver = new Reference<Primitive>(intercepted); | 63 node.receiver = new Reference<Primitive>(intercepted); |
| 68 } | 64 } |
| 69 | 65 |
| 70 Primitive makeNull() { | 66 Primitive makeNull() { |
| 71 NullConstantValue nullConst = new NullConstantValue(); | 67 NullConstantValue nullConst = new NullConstantValue(); |
| 72 return new Constant(new PrimitiveConstantExpression(nullConst)); | 68 return new Constant(new PrimitiveConstantExpression(nullConst)); |
| 73 } | 69 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 new LetPrim(i, | 87 new LetPrim(i, |
| 92 new Branch(new IsTrue(i), | 88 new Branch(new IsTrue(i), |
| 93 node.trueContinuation.definition, | 89 node.trueContinuation.definition, |
| 94 node.falseContinuation.definition))); | 90 node.falseContinuation.definition))); |
| 95 condition.value.unlink(); | 91 condition.value.unlink(); |
| 96 node.trueContinuation.unlink(); | 92 node.trueContinuation.unlink(); |
| 97 node.falseContinuation.unlink(); | 93 node.falseContinuation.unlink(); |
| 98 parent.body = newNode; | 94 parent.body = newNode; |
| 99 } | 95 } |
| 100 } | 96 } |
| OLD | NEW |