OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * A phase in the compilation process that processes the entire AST and | 6 * A phase in the compilation process that processes the entire AST and |
7 * desugars await expressions. | 7 * desugars await expressions. |
8 */ | 8 */ |
9 awaitTransformation() { | 9 awaitTransformation() { |
10 for (var lib in world.libraries.getValues()) { | 10 for (var lib in world.libraries.getValues()) { |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 _desugarAwaitCall(AwaitExpression node, Identifier param) { | 666 _desugarAwaitCall(AwaitExpression node, Identifier param) { |
667 final thenMethod = new DotExpression(node.body, | 667 final thenMethod = new DotExpression(node.body, |
668 new Identifier('then', node.span), node.span); | 668 new Identifier('then', node.span), node.span); |
669 List<Statement> afterAwait = []; | 669 List<Statement> afterAwait = []; |
670 afterAwait.addAll(continuation); | 670 afterAwait.addAll(continuation); |
671 final thenArg = new LambdaExpression( | 671 final thenArg = new LambdaExpression( |
672 new FunctionDefinition([], null, null, | 672 new FunctionDefinition([], null, null, |
673 [new FormalNode( | 673 [new FormalNode( |
674 false, false, null /* infer type from body? */, | 674 false, false, null /* infer type from body? */, |
675 param, null, param.span) | 675 param, null, param.span) |
676 ], null, null, null, | 676 ], null, null, |
677 new BlockStatement(afterAwait, node.span), node.span), | 677 new BlockStatement(afterAwait, node.span), node.span), |
678 node.span); | 678 node.span); |
679 continuation.clear(); | 679 continuation.clear(); |
680 // TODO(sigmund): insert in new continuation all additional statements that | 680 // TODO(sigmund): insert in new continuation all additional statements that |
681 // propagate errors. | 681 // propagate errors. |
682 // this assumes that the normalization ensures await calls are within blocks | 682 // this assumes that the normalization ensures await calls are within blocks |
683 continuation.addFirst(_returnFuture(node.span)); | 683 continuation.addFirst(_returnFuture(node.span)); |
684 return new CallExpression(thenMethod, | 684 return new CallExpression(thenMethod, |
685 [new ArgumentNode(null, thenArg, node.span)], node.span); | 685 [new ArgumentNode(null, thenArg, node.span)], node.span); |
686 } | 686 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 new DotExpression( | 732 new DotExpression( |
733 new VarExpression(new Identifier(_COMPLETER_NAME, span), span), | 733 new VarExpression(new Identifier(_COMPLETER_NAME, span), span), |
734 new Identifier("future", span), span), span); | 734 new Identifier("future", span), span), span); |
735 } | 735 } |
736 | 736 |
737 /** Create a closure that contains the continuation statements. */ | 737 /** Create a closure that contains the continuation statements. */ |
738 _createContinuationClosure(String name, SourceSpan span) { | 738 _createContinuationClosure(String name, SourceSpan span) { |
739 List<Statement> continuationBlock = []; | 739 List<Statement> continuationBlock = []; |
740 continuationBlock.addAll(continuation); | 740 continuationBlock.addAll(continuation); |
741 return new FunctionDefinition([], null, | 741 return new FunctionDefinition([], null, |
742 new Identifier(name, span), [], null, null, null, | 742 new Identifier(name, span), [], null, null, |
743 new BlockStatement(continuationBlock, span), span); | 743 new BlockStatement(continuationBlock, span), span); |
744 } | 744 } |
745 | 745 |
746 /** Make a statement invoking a function in scope. */ | 746 /** Make a statement invoking a function in scope. */ |
747 _makeCallNoArgs(String func, SourceSpan span) { | 747 _makeCallNoArgs(String func, SourceSpan span) { |
748 return new ExpressionStatement(new CallExpression( | 748 return new ExpressionStatement(new CallExpression( |
749 new VarExpression(new Identifier(func, span), span), [], span), span); | 749 new VarExpression(new Identifier(func, span), span), [], span), span); |
750 } | 750 } |
751 } | 751 } |
752 | 752 |
(...skipping 27 matching lines...) Expand all Loading... |
780 // if (a) if (b) await t; 2; | 780 // if (a) if (b) await t; 2; |
781 // becomes: | 781 // becomes: |
782 // if (a) { if (b) { await t; } } 2; | 782 // if (a) { if (b) { await t; } } 2; |
783 // which becomes becomes: | 783 // which becomes becomes: |
784 // _2() { 2; } if (a) { if (b) { t.then((_) { _2(); } } } _2(); | 784 // _2() { 2; } if (a) { if (b) { t.then((_) { _2(); } } } _2(); |
785 // (seems that 'a' doesn't need { }) | 785 // (seems that 'a' doesn't need { }) |
786 // - 'if/while' with only one statement in the continuation (check the | 786 // - 'if/while' with only one statement in the continuation (check the |
787 // optimization that copies code rather than adding a continuation closure). | 787 // optimization that copies code rather than adding a continuation closure). |
788 // - await not inside a block (could break error propagation if normalization is | 788 // - await not inside a block (could break error propagation if normalization is |
789 // done incorrectly). | 789 // done incorrectly). |
OLD | NEW |