| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.transformations.continuation; | 5 library kernel.transformations.continuation; |
| 6 | 6 |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import '../ast.dart'; | 9 import '../ast.dart'; |
| 10 import '../visitor.dart'; | 10 import '../visitor.dart'; |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // var <variable> = :for-iterator.current; | 521 // var <variable> = :for-iterator.current; |
| 522 // ... | 522 // ... |
| 523 // } | 523 // } |
| 524 // } finally { | 524 // } finally { |
| 525 // :for-iterator.cancel(); | 525 // :for-iterator.cancel(); |
| 526 // } | 526 // } |
| 527 // } | 527 // } |
| 528 var iteratorVariable = new VariableDeclaration(':for-iterator', | 528 var iteratorVariable = new VariableDeclaration(':for-iterator', |
| 529 initializer: new ConstructorInvocation( | 529 initializer: new ConstructorInvocation( |
| 530 helper.streamIteratorConstructor, | 530 helper.streamIteratorConstructor, |
| 531 new Arguments(<Expression>[stmt.iterable]))); | 531 new Arguments(<Expression>[stmt.iterable], |
| 532 types: [const DynamicType()]))); |
| 532 | 533 |
| 533 // await iterator.moveNext() | 534 // await iterator.moveNext() |
| 534 var condition = new AwaitExpression(new MethodInvocation( | 535 var condition = new AwaitExpression(new MethodInvocation( |
| 535 new VariableGet(iteratorVariable), | 536 new VariableGet(iteratorVariable), |
| 536 new Name('moveNext'), | 537 new Name('moveNext'), |
| 537 new Arguments(<Expression>[]))); | 538 new Arguments(<Expression>[]))); |
| 538 | 539 |
| 539 // var <variable> = iterator.current; | 540 // var <variable> = iterator.current; |
| 540 var valueVariable = stmt.variable; | 541 var valueVariable = stmt.variable; |
| 541 valueVariable.initializer = new PropertyGet( | 542 valueVariable.initializer = new PropertyGet( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 VariableDeclaration returnVariable; | 727 VariableDeclaration returnVariable; |
| 727 | 728 |
| 728 AsyncFunctionRewriter(helper, enclosingFunction) | 729 AsyncFunctionRewriter(helper, enclosingFunction) |
| 729 : super(helper, enclosingFunction); | 730 : super(helper, enclosingFunction); |
| 730 | 731 |
| 731 FunctionNode rewrite() { | 732 FunctionNode rewrite() { |
| 732 var statements = <Statement>[]; | 733 var statements = <Statement>[]; |
| 733 | 734 |
| 734 // var :completer = new Completer.sync(); | 735 // var :completer = new Completer.sync(); |
| 735 completerVariable = new VariableDeclaration(":completer", | 736 completerVariable = new VariableDeclaration(":completer", |
| 736 initializer: new StaticInvocation( | 737 initializer: new StaticInvocation(helper.completerConstructor, |
| 737 helper.completerConstructor, new Arguments([])), | 738 new Arguments([], types: [const DynamicType()])), |
| 738 isFinal: true); | 739 isFinal: true); |
| 739 statements.add(completerVariable); | 740 statements.add(completerVariable); |
| 740 | 741 |
| 741 returnVariable = new VariableDeclaration(":return_value"); | 742 returnVariable = new VariableDeclaration(":return_value"); |
| 742 statements.add(returnVariable); | 743 statements.add(returnVariable); |
| 743 | 744 |
| 744 setupAsyncContinuations(statements); | 745 setupAsyncContinuations(statements); |
| 745 | 746 |
| 746 // new Future.microtask(:async_op); | 747 // new Future.microtask(:async_op); |
| 747 var newMicrotaskStatement = new ExpressionStatement(new StaticInvocation( | 748 var newMicrotaskStatement = new ExpressionStatement(new StaticInvocation( |
| 748 helper.futureMicrotaskConstructor, | 749 helper.futureMicrotaskConstructor, |
| 749 new Arguments([new VariableGet(nestedClosureVariable)]))); | 750 new Arguments([new VariableGet(nestedClosureVariable)], |
| 751 types: [const DynamicType()]))); |
| 750 statements.add(newMicrotaskStatement); | 752 statements.add(newMicrotaskStatement); |
| 751 | 753 |
| 752 // return :completer.future; | 754 // return :completer.future; |
| 753 var completerGet = new VariableGet(completerVariable); | 755 var completerGet = new VariableGet(completerVariable); |
| 754 var returnStatement = new ReturnStatement( | 756 var returnStatement = new ReturnStatement( |
| 755 new PropertyGet(completerGet, new Name('future', helper.asyncLibrary))); | 757 new PropertyGet(completerGet, new Name('future', helper.asyncLibrary))); |
| 756 statements.add(returnStatement); | 758 statements.add(returnStatement); |
| 757 | 759 |
| 758 enclosingFunction.body = new Block(statements); | 760 enclosingFunction.body = new Block(statements); |
| 759 enclosingFunction.body.parent = enclosingFunction; | 761 enclosingFunction.body.parent = enclosingFunction; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 findFactoryConstructor(completerClass, 'sync'), | 895 findFactoryConstructor(completerClass, 'sync'), |
| 894 findConstructor(syncIterableClass, ''), | 896 findConstructor(syncIterableClass, ''), |
| 895 findConstructor(streamIteratorClass, ''), | 897 findConstructor(streamIteratorClass, ''), |
| 896 findFactoryConstructor(futureClass, 'microtask'), | 898 findFactoryConstructor(futureClass, 'microtask'), |
| 897 findConstructor(streamControllerClass, ''), | 899 findConstructor(streamControllerClass, ''), |
| 898 findProcedure(asyncLibrary, '_asyncThenWrapperHelper'), | 900 findProcedure(asyncLibrary, '_asyncThenWrapperHelper'), |
| 899 findProcedure(asyncLibrary, '_asyncErrorWrapperHelper'), | 901 findProcedure(asyncLibrary, '_asyncErrorWrapperHelper'), |
| 900 findProcedure(asyncLibrary, '_awaitHelper')); | 902 findProcedure(asyncLibrary, '_awaitHelper')); |
| 901 } | 903 } |
| 902 } | 904 } |
| OLD | NEW |