Chromium Code Reviews| 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; | 9 import '../../elements/elements.dart' show ClassElement, FieldElement; |
| 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; |
| 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; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 31 Node result = node.accept(this); | 31 Node result = node.accept(this); |
| 32 return result != null ? result : node; | 32 return result != null ? result : node; |
| 33 } | 33 } |
| 34 | 34 |
| 35 Constant get trueConstant { | 35 Constant get trueConstant { |
| 36 return new Constant( | 36 return new Constant( |
| 37 new PrimitiveConstantExpression( | 37 new PrimitiveConstantExpression( |
| 38 new TrueConstantValue())); | 38 new TrueConstantValue())); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void insertLetPrim(Primitive primitive, Expression node) { | |
| 42 LetPrim let = new LetPrim(primitive); | |
| 43 InteriorNode parent = node.parent; | |
| 44 parent.body = let; | |
| 45 let.body = node; | |
| 46 node.parent = let; | |
| 47 let.parent = parent; | |
| 48 } | |
| 49 | |
| 41 processInvokeMethod(InvokeMethod node) { | 50 processInvokeMethod(InvokeMethod node) { |
| 42 Selector selector = node.selector; | 51 Selector selector = node.selector; |
| 43 if (!_glue.isInterceptedSelector(selector)) return; | 52 if (!_glue.isInterceptedSelector(selector)) return; |
| 44 | 53 |
| 45 if (!selector.isCall && !selector.isOperator) { | 54 if (!selector.isCall && !selector.isOperator) { |
| 46 // TODO(karlklose): handle special selectors. | 55 // TODO(karlklose): handle special selectors. |
| 47 return; | 56 return; |
| 48 } | 57 } |
| 49 | 58 |
| 50 Set<ClassElement> interceptedClasses = | 59 Set<ClassElement> interceptedClasses = |
| 51 _glue.getInterceptedClassesOn(selector); | 60 _glue.getInterceptedClassesOn(selector); |
| 52 _glue.registerSpecializedGetInterceptor(interceptedClasses); | 61 _glue.registerSpecializedGetInterceptor(interceptedClasses); |
| 53 InteriorNode parent = node.parent; | 62 |
| 54 Primitive receiver = node.receiver.definition; | 63 Primitive receiver = node.receiver.definition; |
| 55 Primitive intercepted = new Interceptor(receiver, interceptedClasses); | 64 Primitive intercepted = new Interceptor(receiver, interceptedClasses); |
| 56 List<Reference<Primitive>> arguments = | 65 insertLetPrim(intercepted, node); |
| 57 new List<Reference<Primitive>>.generate(node.arguments.length + 1, | 66 node.arguments.insert(0, node.receiver); |
| 58 (int index) { | 67 node.receiver = new Reference<Primitive>(intercepted); |
| 59 return index == 0 ? new Reference<Primitive>(receiver) | 68 } |
| 60 : node.arguments[index - 1]; | 69 |
| 61 }); | 70 Primitive makeNull() { |
| 62 LetPrim newNode = new LetPrim(intercepted, | 71 NullConstantValue nullConst = new NullConstantValue(); |
| 63 new InvokeMethod.internal(new Reference<Primitive>(intercepted), | 72 return new Constant(new PrimitiveConstantExpression(nullConst)); |
| 64 selector, | 73 } |
| 65 new Reference<Continuation>(node.continuation.definition), | 74 |
| 66 arguments)); | 75 processInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 67 node.continuation.unlink(); | 76 if (_glue.isInterceptedSelector(node.selector)) { |
|
sigurdm
2015/01/20 10:54:25
A space after open parenthesis
asgerf
2015/01/20 13:07:50
That's _glue. There is no space.
| |
| 68 node.receiver.unlink(); | 77 Primitive nullPrim = makeNull(); |
| 69 parent.body = newNode; | 78 insertLetPrim(nullPrim, node); |
| 79 node.arguments.insert(0, node.receiver); | |
| 80 node.receiver = new Reference<Primitive>(nullPrim); | |
| 81 } | |
| 70 } | 82 } |
| 71 | 83 |
| 72 processBranch(Branch node) { | 84 processBranch(Branch node) { |
| 73 // TODO(karlklose): implement the checked mode part of boolean conversion. | 85 // TODO(karlklose): implement the checked mode part of boolean conversion. |
| 74 InteriorNode parent = node.parent; | 86 InteriorNode parent = node.parent; |
| 75 IsTrue condition = node.condition; | 87 IsTrue condition = node.condition; |
| 76 Primitive t = trueConstant; | 88 Primitive t = trueConstant; |
| 77 Primitive i = new Identical(condition.value.definition, t); | 89 Primitive i = new Identical(condition.value.definition, t); |
| 78 LetPrim newNode = new LetPrim(t, | 90 LetPrim newNode = new LetPrim(t, |
| 79 new LetPrim(i, | 91 new LetPrim(i, |
| 80 new Branch(new IsTrue(i), | 92 new Branch(new IsTrue(i), |
| 81 node.trueContinuation.definition, | 93 node.trueContinuation.definition, |
| 82 node.falseContinuation.definition))); | 94 node.falseContinuation.definition))); |
| 83 condition.value.unlink(); | 95 condition.value.unlink(); |
| 84 node.trueContinuation.unlink(); | 96 node.trueContinuation.unlink(); |
| 85 node.falseContinuation.unlink(); | 97 node.falseContinuation.unlink(); |
| 86 parent.body = newNode; | 98 parent.body = newNode; |
| 87 } | 99 } |
| 88 } | 100 } |
| OLD | NEW |