| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 128 // Note: SyncYielding functions have no Dart equivalent. Since they are |
| 129 // synchronous, we use Sync. (Note also that the Dart VM backend uses the |
| 130 // Dart async marker to decide if functions are debuggable.) |
| 127 final nestedClosureVariable = new VariableDeclaration(":sync_op"); | 131 final nestedClosureVariable = new VariableDeclaration(":sync_op"); |
| 128 final function = new FunctionNode(buildClosureBody(), | 132 final function = new FunctionNode(buildClosureBody(), |
| 129 positionalParameters: [iteratorVariable], | 133 positionalParameters: [iteratorVariable], |
| 130 requiredParameterCount: 1, | 134 requiredParameterCount: 1, |
| 131 asyncMarker: AsyncMarker.SyncYielding) | 135 asyncMarker: AsyncMarker.SyncYielding, |
| 136 dartAsyncMarker: AsyncMarker.Sync) |
| 132 ..fileOffset = enclosingFunction.fileOffset | 137 ..fileOffset = enclosingFunction.fileOffset |
| 133 ..fileEndOffset = enclosingFunction.fileEndOffset | 138 ..fileEndOffset = enclosingFunction.fileEndOffset |
| 134 ..returnType = helper.coreTypes.boolClass.rawType; | 139 ..returnType = helper.coreTypes.boolClass.rawType; |
| 135 | 140 |
| 136 final closureFunction = | 141 final closureFunction = |
| 137 new FunctionDeclaration(nestedClosureVariable, function) | 142 new FunctionDeclaration(nestedClosureVariable, function) |
| 138 ..fileOffset = enclosingFunction.parent.fileOffset; | 143 ..fileOffset = enclosingFunction.parent.fileOffset; |
| 139 | 144 |
| 140 // return new _SyncIterable(:sync_body); | 145 // return new _SyncIterable(:sync_body); |
| 141 final arguments = new Arguments([new VariableGet(nestedClosureVariable)]); | 146 final arguments = new Arguments([new VariableGet(nestedClosureVariable)]); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 statements.add(catchErrorContinuationVariable); | 221 statements.add(catchErrorContinuationVariable); |
| 217 | 222 |
| 218 // :async_op([:result, :exception, :stack_trace]) { | 223 // :async_op([:result, :exception, :stack_trace]) { |
| 219 // modified <node.body>; | 224 // modified <node.body>; |
| 220 // } | 225 // } |
| 221 final parameters = <VariableDeclaration>[ | 226 final parameters = <VariableDeclaration>[ |
| 222 expressionRewriter.asyncResult, | 227 expressionRewriter.asyncResult, |
| 223 new VariableDeclaration(':exception'), | 228 new VariableDeclaration(':exception'), |
| 224 new VariableDeclaration(':stack_trace'), | 229 new VariableDeclaration(':stack_trace'), |
| 225 ]; | 230 ]; |
| 231 |
| 232 // Note: SyncYielding functions have no Dart equivalent. Since they are |
| 233 // synchronous, we use Sync. (Note also that the Dart VM backend uses the |
| 234 // Dart async marker to decide if functions are debuggable.) |
| 226 final function = new FunctionNode(buildWrappedBody(), | 235 final function = new FunctionNode(buildWrappedBody(), |
| 227 positionalParameters: parameters, | 236 positionalParameters: parameters, |
| 228 requiredParameterCount: 0, | 237 requiredParameterCount: 0, |
| 229 asyncMarker: AsyncMarker.SyncYielding) | 238 asyncMarker: AsyncMarker.SyncYielding, |
| 239 dartAsyncMarker: AsyncMarker.Sync) |
| 230 ..fileOffset = enclosingFunction.fileOffset | 240 ..fileOffset = enclosingFunction.fileOffset |
| 231 ..fileEndOffset = enclosingFunction.fileEndOffset; | 241 ..fileEndOffset = enclosingFunction.fileEndOffset; |
| 232 | 242 |
| 233 // The await expression lifter might have created a number of | 243 // The await expression lifter might have created a number of |
| 234 // [VariableDeclarations]. | 244 // [VariableDeclarations]. |
| 235 // TODO(kustermann): If we didn't need any variables we should not emit | 245 // TODO(kustermann): If we didn't need any variables we should not emit |
| 236 // these. | 246 // these. |
| 237 statements.addAll(variableDeclarations()); | 247 statements.addAll(variableDeclarations()); |
| 238 statements.addAll(expressionRewriter.variables); | 248 statements.addAll(expressionRewriter.variables); |
| 239 | 249 |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 coreTypes.getMember('dart:core', '_SyncIterable', ''), | 914 coreTypes.getMember('dart:core', '_SyncIterable', ''), |
| 905 coreTypes.getMember('dart:async', '_StreamIterator', ''), | 915 coreTypes.getMember('dart:async', '_StreamIterator', ''), |
| 906 coreTypes.getMember('dart:async', 'Future', 'microtask'), | 916 coreTypes.getMember('dart:async', 'Future', 'microtask'), |
| 907 coreTypes.getMember('dart:async', '_AsyncStarStreamController', ''), | 917 coreTypes.getMember('dart:async', '_AsyncStarStreamController', ''), |
| 908 coreTypes.getTopLevelMember('dart:async', '_asyncThenWrapperHelper'), | 918 coreTypes.getTopLevelMember('dart:async', '_asyncThenWrapperHelper'), |
| 909 coreTypes.getTopLevelMember('dart:async', '_asyncErrorWrapperHelper'), | 919 coreTypes.getTopLevelMember('dart:async', '_asyncErrorWrapperHelper'), |
| 910 coreTypes.getTopLevelMember('dart:async', '_awaitHelper'), | 920 coreTypes.getTopLevelMember('dart:async', '_awaitHelper'), |
| 911 coreTypes); | 921 coreTypes); |
| 912 } | 922 } |
| 913 } | 923 } |
| OLD | NEW |