Chromium Code Reviews| Index: pkg/compiler/lib/src/js_backend/codegen/unsugar.dart |
| diff --git a/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart b/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart |
| index a071b47a3b16a5fe29305fb9f578dfc0c252f040..670cddaa2adfdd4a870382a0436cae9180f95a20 100644 |
| --- a/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart |
| +++ b/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart |
| @@ -6,7 +6,8 @@ import '../../cps_ir/cps_ir_nodes.dart'; |
| import '../../cps_ir/optimizers.dart'; |
| import '../../constants/expressions.dart'; |
| import '../../constants/values.dart'; |
| -import '../../elements/elements.dart' show ClassElement, FieldElement, Element; |
| +import '../../elements/elements.dart' |
| + show ClassElement, FieldElement, FunctionElement, Element; |
| import '../../js_backend/codegen/glue.dart'; |
| import '../../dart2jslib.dart' show Selector, World; |
| @@ -17,12 +18,13 @@ import '../../dart2jslib.dart' show Selector, World; |
| /// - rewrite [IsTrue] in a [Branch] to do boolean conversion. |
|
asgerf
2015/04/14 12:59:17
Stale doc comment.
Kevin Millikin (Google)
2015/04/15 07:52:22
Thanks, updated.
|
| class UnsugarVisitor extends RecursiveVisitor { |
| Glue _glue; |
| + ParentVisitor _parentVisitor = new ParentVisitor(); |
| UnsugarVisitor(this._glue); |
| void rewrite(FunctionDefinition function) { |
| // Set all parent pointers. |
| - new ParentVisitor().visit(function); |
| + _parentVisitor.visit(function); |
| visit(function); |
| } |
| @@ -47,6 +49,67 @@ class UnsugarVisitor extends RecursiveVisitor { |
| let.parent = parent; |
| } |
| + /// Insert a static call to [function] at the point of [node] with result |
| + /// [result]. |
| + /// |
| + /// Rewrite [node] to |
| + /// |
| + /// let cont continuation(result) = node |
| + /// in invoke function arguments continuation |
| + /// |
| + /// The result parameter passed to this function because a common pattern is |
| + /// to replace all uses of one of the arguments with the result. To do that, |
| + /// create a result parameter first, replace all uses of the arguments with |
| + /// the result, and then insert the call with this function. |
|
asgerf
2015/04/14 12:59:17
The result parameter *is* passed ...
I don't see
Kevin Millikin (Google)
2015/04/15 07:52:22
Fair enough, I'll just remove that bit of the comm
|
| + void insertStaticCall(FunctionElement function, List<Primitive> arguments, |
| + Parameter result, |
| + Expression node) { |
| + InteriorNode parent = node.parent; |
| + Continuation continuation = new Continuation([result]); |
| + continuation.body = node; |
| + _parentVisitor.processContinuation(continuation); |
| + |
| + Selector selector = new Selector.fromElement(function); |
| + // TODO(johnniwinther): Come up with an implementation of SourceInformation |
| + // for calls such as this one that don't appear in the original source. |
| + InvokeStatic invoke = |
| + new InvokeStatic(function, selector, continuation, arguments, null); |
| + _parentVisitor.processInvokeStatic(invoke); |
| + |
| + LetCont letCont = new LetCont(continuation, invoke); |
| + _parentVisitor.processLetCont(letCont); |
| + |
| + parent.body = letCont; |
| + letCont.parent = parent; |
| + } |
| + |
| + processLetHandler(LetHandler node) { |
| + // BEFORE: Handlers have two parameters, exception and stack trace. |
| + // AFTER: Handlers have a single parameter, which is unwrapped to get |
| + // the exception and stack trace. |
| + assert(node.handler.parameters.length == 2); |
| + Parameter exceptionParameter = node.handler.parameters.first; |
| + Parameter stackTraceParameter = node.handler.parameters.last; |
| + Expression body = node.handler.body; |
| + if (exceptionParameter.hasAtLeastOneUse || |
| + stackTraceParameter.hasAtLeastOneUse) { |
| + Parameter exceptionValue = new Parameter(null); |
| + exceptionValue.substituteFor(exceptionParameter); |
| + insertStaticCall(_glue.getExceptionUnwrapper(), [exceptionParameter], |
| + exceptionValue, body); |
| + |
| + if (stackTraceParameter.hasAtLeastOneUse) { |
| + Parameter stackTraceValue = new Parameter(null); |
| + stackTraceValue.substituteFor(stackTraceParameter); |
| + insertStaticCall(_glue.getTraceFromException(), [exceptionValue], |
| + stackTraceValue, body); |
| + } |
| + } |
| + |
| + assert(stackTraceParameter.hasNoUses); |
| + node.handler.parameters.removeLast(); |
| + } |
| + |
| processInvokeMethod(InvokeMethod node) { |
| Selector selector = node.selector; |
| // TODO(karlklose): should we rewrite all selectors? |