| 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 '../core_types.dart'; | 10 import '../core_types.dart'; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 [asyncJumpVariable, asyncContextVariable] | 110 [asyncJumpVariable, asyncContextVariable] |
| 111 ..addAll(createCapturedTryVariables()) | 111 ..addAll(createCapturedTryVariables()) |
| 112 ..addAll(createCapturedCatchVariables()); | 112 ..addAll(createCapturedCatchVariables()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 class SyncStarFunctionRewriter extends ContinuationRewriterBase { | 115 class SyncStarFunctionRewriter extends ContinuationRewriterBase { |
| 116 final VariableDeclaration iteratorVariable; | 116 final VariableDeclaration iteratorVariable; |
| 117 | 117 |
| 118 SyncStarFunctionRewriter(helper, enclosingFunction) | 118 SyncStarFunctionRewriter(helper, enclosingFunction) |
| 119 : iteratorVariable = new VariableDeclaration(':iterator') | 119 : iteratorVariable = new VariableDeclaration(':iterator') |
| 120 ..type = helper.iteratorClass.rawType, | 120 ..type = helper.iteratorClass.rawType, |
| 121 super(helper, enclosingFunction); | 121 super(helper, enclosingFunction); |
| 122 | 122 |
| 123 FunctionNode rewrite() { | 123 FunctionNode rewrite() { |
| 124 // :sync_body(:iterator) { | 124 // :sync_body(:iterator) { |
| 125 // modified <node.body>; | 125 // modified <node.body>; |
| 126 // } | 126 // } |
| 127 final nestedClosureVariable = new VariableDeclaration(":sync_op"); | 127 final nestedClosureVariable = new VariableDeclaration(":sync_op"); |
| 128 final function = new FunctionNode(buildClosureBody(), | 128 final function = new FunctionNode(buildClosureBody(), |
| 129 positionalParameters: [iteratorVariable], | 129 positionalParameters: [iteratorVariable], |
| 130 requiredParameterCount: 1, | 130 requiredParameterCount: 1, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 149 enclosingFunction.asyncMarker = AsyncMarker.Sync; | 149 enclosingFunction.asyncMarker = AsyncMarker.Sync; |
| 150 return enclosingFunction; | 150 return enclosingFunction; |
| 151 } | 151 } |
| 152 | 152 |
| 153 Statement buildClosureBody() { | 153 Statement buildClosureBody() { |
| 154 // The body will insert calls to | 154 // The body will insert calls to |
| 155 // :iterator.current_= | 155 // :iterator.current_= |
| 156 // :iterator.isYieldEach= | 156 // :iterator.isYieldEach= |
| 157 // and return `true` as long as it did something and `false` when it's done. | 157 // and return `true` as long as it did something and `false` when it's done. |
| 158 return new Block(<Statement>[ | 158 return new Block(<Statement>[ |
| 159 enclosingFunction.body.accept(this), | 159 enclosingFunction.body.accept(this), |
| 160 new ReturnStatement(new BoolLiteral(false)) | 160 new ReturnStatement(new BoolLiteral(false)) |
| 161 ]); | 161 ]); |
| 162 } | 162 } |
| 163 | 163 |
| 164 visitYieldStatement(YieldStatement node) { | 164 visitYieldStatement(YieldStatement node) { |
| 165 var transformedExpression = node.expression.accept(this); | 165 var transformedExpression = node.expression.accept(this); |
| 166 | 166 |
| 167 var statements = <Statement>[]; | 167 var statements = <Statement>[]; |
| 168 if (node.isYieldStar) { | 168 if (node.isYieldStar) { |
| 169 var markYieldEach = new ExpressionStatement(new PropertySet( | 169 var markYieldEach = new ExpressionStatement(new PropertySet( |
| 170 new VariableGet(iteratorVariable), | 170 new VariableGet(iteratorVariable), |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 if (future_type.typeArguments.length == 0) { | 779 if (future_type.typeArguments.length == 0) { |
| 780 returnType = const DynamicType(); | 780 returnType = const DynamicType(); |
| 781 } else if (future_type.typeArguments.length == 1) { | 781 } else if (future_type.typeArguments.length == 1) { |
| 782 returnType = future_type.typeArguments[0]; | 782 returnType = future_type.typeArguments[0]; |
| 783 } else { | 783 } else { |
| 784 returnType = const InvalidType(); | 784 returnType = const InvalidType(); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 var completerTypeArguments = <DartType>[returnType]; | 788 var completerTypeArguments = <DartType>[returnType]; |
| 789 var completerType = new InterfaceType( | 789 var completerType = |
| 790 helper.completerClass, completerTypeArguments); | 790 new InterfaceType(helper.completerClass, completerTypeArguments); |
| 791 | 791 |
| 792 // final Completer<T> :completer = new Completer<T>.sync(); | 792 // final Completer<T> :completer = new Completer<T>.sync(); |
| 793 completerVariable = new VariableDeclaration(":completer", | 793 completerVariable = new VariableDeclaration(":completer", |
| 794 initializer: new StaticInvocation(helper.completerConstructor, | 794 initializer: new StaticInvocation(helper.completerConstructor, |
| 795 new Arguments([], types: completerTypeArguments)) | 795 new Arguments([], types: completerTypeArguments)) |
| 796 ..fileOffset = enclosingFunction.body.fileOffset, | 796 ..fileOffset = enclosingFunction.body.fileOffset, |
| 797 isFinal: true, | 797 isFinal: true, |
| 798 type: completerType); | 798 type: completerType); |
| 799 statements.add(completerVariable); | 799 statements.add(completerVariable); |
| 800 | 800 |
| 801 returnVariable = new VariableDeclaration( | 801 returnVariable = new VariableDeclaration(":return_value", type: returnType); |
| 802 ":return_value", type: returnType); | |
| 803 statements.add(returnVariable); | 802 statements.add(returnVariable); |
| 804 | 803 |
| 805 setupAsyncContinuations(statements); | 804 setupAsyncContinuations(statements); |
| 806 | 805 |
| 807 // new Future.microtask(:async_op); | 806 // new Future.microtask(:async_op); |
| 808 var newMicrotaskStatement = new ExpressionStatement(new StaticInvocation( | 807 var newMicrotaskStatement = new ExpressionStatement(new StaticInvocation( |
| 809 helper.futureMicrotaskConstructor, | 808 helper.futureMicrotaskConstructor, |
| 810 new Arguments([new VariableGet(nestedClosureVariable)], | 809 new Arguments([new VariableGet(nestedClosureVariable)], |
| 811 types: [const DynamicType()])) | 810 types: [const DynamicType()])) |
| 812 ..fileOffset = enclosingFunction.fileOffset); | 811 ..fileOffset = enclosingFunction.fileOffset); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 findConstructor(syncIterableClass, ''), | 969 findConstructor(syncIterableClass, ''), |
| 971 findConstructor(streamIteratorClass, ''), | 970 findConstructor(streamIteratorClass, ''), |
| 972 findFactoryConstructor(futureClass, 'microtask'), | 971 findFactoryConstructor(futureClass, 'microtask'), |
| 973 findConstructor(streamControllerClass, ''), | 972 findConstructor(streamControllerClass, ''), |
| 974 findProcedure(asyncLibrary, '_asyncThenWrapperHelper'), | 973 findProcedure(asyncLibrary, '_asyncThenWrapperHelper'), |
| 975 findProcedure(asyncLibrary, '_asyncErrorWrapperHelper'), | 974 findProcedure(asyncLibrary, '_asyncErrorWrapperHelper'), |
| 976 findProcedure(asyncLibrary, '_awaitHelper'), | 975 findProcedure(asyncLibrary, '_awaitHelper'), |
| 977 new CoreTypes(program)); | 976 new CoreTypes(program)); |
| 978 } | 977 } |
| 979 } | 978 } |
| OLD | NEW |