Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Unified Diff: pkg/kernel/lib/transformations/continuation.dart

Issue 2627873002: VM: [Kernel] Fix remaining issues with kernel-based async/await implementation (Closed)
Patch Set: postfix -> prefix increment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/transformations/continuation.dart
diff --git a/pkg/kernel/lib/transformations/continuation.dart b/pkg/kernel/lib/transformations/continuation.dart
index 185edc50eb6ae1742b2cba8d4f2a7fdd6e57bad3..f92d6802355d12f8067061e93fb7e24afea673c0 100644
--- a/pkg/kernel/lib/transformations/continuation.dart
+++ b/pkg/kernel/lib/transformations/continuation.dart
@@ -50,13 +50,12 @@ class RecursiveContinuationRewriter extends Transformer {
abstract class ContinuationRewriterBase extends RecursiveContinuationRewriter {
final FunctionNode enclosingFunction;
- int currentTryDepth; // Nesting depth for try-blocks.
+ int currentTryDepth = 0; // Nesting depth for try-blocks.
int currentCatchDepth = 0; // Nesting depth for catch-blocks.
int capturedTryDepth = 0; // Deepest yield point within a try-block.
int capturedCatchDepth = 0; // Deepest yield point within a catch-block.
- ContinuationRewriterBase(HelperNodes helper, this.enclosingFunction,
- {this.currentTryDepth: 0})
+ ContinuationRewriterBase(HelperNodes helper, this.enclosingFunction)
: super(helper);
Statement createContinuationPoint([Expression value]) {
@@ -68,28 +67,30 @@ abstract class ContinuationRewriterBase extends RecursiveContinuationRewriter {
TreeNode visitTryCatch(TryCatch node) {
if (node.body != null) {
- currentTryDepth++;
+ ++currentTryDepth;
node.body = node.body.accept(this);
node.body?.parent = node;
- currentTryDepth--;
+ --currentTryDepth;
}
- currentCatchDepth++;
+ ++currentCatchDepth;
transformList(node.catches, this, node);
- currentCatchDepth--;
+ --currentCatchDepth;
return node;
}
TreeNode visitTryFinally(TryFinally node) {
if (node.body != null) {
- currentTryDepth++;
+ ++currentTryDepth;
node.body = node.body.accept(this);
node.body?.parent = node;
- currentTryDepth--;
+ --currentTryDepth;
}
if (node.finalizer != null) {
+ ++currentCatchDepth;
node.finalizer = node.finalizer.accept(this);
node.finalizer?.parent = node;
+ --currentCatchDepth;
}
return node;
}
@@ -189,8 +190,7 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
ExpressionLifter expressionRewriter;
AsyncRewriterBase(helper, enclosingFunction)
- // Body is wrapped in the try-catch so initial currentTryDepth is 1.
- : super(helper, enclosingFunction, currentTryDepth: 1) {}
+ : super(helper, enclosingFunction) {}
void setupAsyncContinuations(List<Statement> statements) {
expressionRewriter = new ExpressionLifter(this);
@@ -247,9 +247,11 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
}
Statement buildWrappedBody() {
+ ++currentTryDepth;
labeledBody = new LabeledStatement(null);
labeledBody.body = visitDelimited(enclosingFunction.body)
..parent = labeledBody;
+ --currentTryDepth;
var exceptionVariable = new VariableDeclaration(":exception");
var stackTraceVariable = new VariableDeclaration(":stack_trace");
@@ -617,7 +619,9 @@ abstract class AsyncRewriterBase extends ContinuationRewriterBase {
++currentTryDepth;
stmt.body = visitDelimited(stmt.body)..parent = stmt;
--currentTryDepth;
+ ++currentCatchDepth;
stmt.finalizer = visitDelimited(stmt.finalizer)..parent = stmt;
+ --currentCatchDepth;
statements.add(stmt);
return null;
}
@@ -684,10 +688,24 @@ class AsyncStarFunctionRewriter extends AsyncRewriterBase {
return enclosingFunction;
}
+ Statement buildWrappedBody() {
+ ++currentTryDepth;
+ Statement body = super.buildWrappedBody();
+ --currentTryDepth;
+
+ var finallyBody = new ExpressionStatement(new MethodInvocation(
+ new VariableGet(controllerVariable),
+ new Name("close", helper.asyncLibrary),
+ new Arguments(<Expression>[])));
+
+ var tryFinally = new TryFinally(body, new Block(<Statement>[finallyBody]));
+ return tryFinally;
+ }
+
Statement buildCatchBody(exceptionVariable, stackTraceVariable) {
return new ExpressionStatement(new MethodInvocation(
new VariableGet(controllerVariable),
- new Name("completeError", helper.asyncLibrary),
+ new Name("addError", helper.asyncLibrary),
new Arguments(<Expression>[
new VariableGet(exceptionVariable),
new VariableGet(stackTraceVariable)
@@ -699,11 +717,7 @@ class AsyncStarFunctionRewriter extends AsyncRewriterBase {
// have been translated into breaks from the labeled body.
return new Block(<Statement>[
body,
- new ExpressionStatement(new MethodInvocation(
- new VariableGet(controllerVariable),
- new Name("close", helper.asyncLibrary),
- new Arguments(<Expression>[]))),
- new ReturnStatement()..fileOffset = enclosingFunction.fileEndOffset
+ new ReturnStatement()..fileOffset = enclosingFunction.fileEndOffset,
]);
}
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698