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; | |
| 10 import '../../js_backend/codegen/glue.dart'; | |
| 9 | 11 |
| 10 /// Rewrites the initial CPS IR to make Dart semantics explicit and inserts | 12 /// Rewrites the initial CPS IR to make Dart semantics explicit and inserts |
| 11 /// special nodes that respect JavaScript behavior. | 13 /// special nodes that respect JavaScript behavior. |
| 12 /// | 14 /// |
| 13 /// Performs the following rewrites: | 15 /// Performs the following rewrites: |
| 14 /// - rewrite [IsTrue] in a [Branch] to do boolean conversion. | 16 /// - rewrite [IsTrue] in a [Branch] to do boolean conversion. |
| 15 class UnsugarVisitor extends RecursiveVisitor { | 17 class UnsugarVisitor extends RecursiveVisitor { |
| 16 const UnsugarVisitor(); | 18 Glue _glue; |
| 19 | |
| 20 UnsugarVisitor(this._glue); | |
| 17 | 21 |
| 18 void rewrite(FunctionDefinition function) { | 22 void rewrite(FunctionDefinition function) { |
| 19 // Set all parent pointers. | 23 // Set all parent pointers. |
| 20 new ParentVisitor().visit(function); | 24 new ParentVisitor().visit(function); |
| 21 visit(function); | 25 visit(function); |
| 22 } | 26 } |
| 23 | 27 |
| 24 @override | 28 @override |
| 25 visit(Node node) { | 29 visit(Node node) { |
| 26 Node result = node.accept(this); | 30 Node result = node.accept(this); |
| 27 return result != null ? result : node; | 31 return result != null ? result : node; |
| 28 } | 32 } |
| 29 | 33 |
| 30 Constant get trueConstant { | 34 Constant get trueConstant { |
| 31 return new Constant( | 35 return new Constant( |
| 32 new PrimitiveConstantExpression( | 36 new PrimitiveConstantExpression( |
| 33 new TrueConstantValue())); | 37 new TrueConstantValue())); |
| 34 } | 38 } |
| 35 | 39 |
| 40 processInvokeMethod(InvokeMethod node) { | |
| 41 if (!_glue.isInterceptedSelector(node.selector)) return; | |
| 42 Set<ClassElement> interceptedClasses = | |
| 43 _glue.getInterceptedClassesOn(node.selector); | |
| 44 _glue.registerSpecializedGetInterceptor(interceptedClasses); | |
| 45 InteriorNode parent = node.parent; | |
| 46 Primitive receiver = node.receiver.definition; | |
| 47 Primitive intercepted = new Interceptor(receiver, interceptedClasses); | |
| 48 LetPrim newNode = new LetPrim(intercepted, | |
| 49 new InvokeMethod(intercepted, | |
| 50 node.selector, | |
| 51 node.continuation.definition, | |
| 52 node.arguments.map( | |
| 53 (Reference<Primitive> r) => r.definition).toList())); | |
|
sigurdm
2014/12/16 11:44:55
It would be nicer if you could just pass the argum
sigurdm
2014/12/16 11:44:56
I would add the extra argument here instead of at
karlklose
2014/12/16 12:04:03
Done.
karlklose
2014/12/16 12:04:03
Done.
| |
| 54 node.continuation.unlink(); | |
| 55 node.receiver.unlink(); | |
| 56 parent.body = newNode; | |
| 57 } | |
| 58 | |
| 36 processBranch(Branch node) { | 59 processBranch(Branch node) { |
| 37 // TODO(karlklose): implement the checked mode part of boolean conversion. | 60 // TODO(karlklose): implement the checked mode part of boolean conversion. |
| 38 InteriorNode parent = node.parent; | 61 InteriorNode parent = node.parent; |
| 39 IsTrue condition = node.condition; | 62 IsTrue condition = node.condition; |
| 40 Primitive t = trueConstant; | 63 Primitive t = trueConstant; |
| 41 Primitive i = new Identical(condition.value.definition, t); | 64 Primitive i = new Identical(condition.value.definition, t); |
| 42 LetPrim newNode = new LetPrim(t, | 65 LetPrim newNode = new LetPrim(t, |
| 43 new LetPrim(i, | 66 new LetPrim(i, |
| 44 new Branch(new IsTrue(i), | 67 new Branch(new IsTrue(i), |
| 45 node.trueContinuation.definition, | 68 node.trueContinuation.definition, |
| 46 node.falseContinuation.definition))); | 69 node.falseContinuation.definition))); |
| 47 condition.value.unlink(); | 70 condition.value.unlink(); |
| 48 node.trueContinuation.unlink(); | 71 node.trueContinuation.unlink(); |
| 49 node.falseContinuation.unlink(); | 72 node.falseContinuation.unlink(); |
| 50 parent.body = newNode; | 73 parent.body = newNode; |
| 51 } | 74 } |
| 52 } | 75 } |
| OLD | NEW |