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

Unified Diff: pkg/kernel/lib/transformations/closure/converter.dart

Issue 2891053003: Add support for converted closures with explicit contexts to VM (Closed)
Patch Set: Disable closure conversion in frontend (was enabled for testing) Created 3 years, 6 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
Index: pkg/kernel/lib/transformations/closure/converter.dart
diff --git a/pkg/kernel/lib/transformations/closure/converter.dart b/pkg/kernel/lib/transformations/closure/converter.dart
index e1865f7fd6d90a6c04a8e0dbeba37456490f612f..658dea8914dd8fd629eea358905acaf51ee5c676 100644
--- a/pkg/kernel/lib/transformations/closure/converter.dart
+++ b/pkg/kernel/lib/transformations/closure/converter.dart
@@ -230,6 +230,7 @@ class ClosureConverter extends Transformer {
}
}
rewriter = null;
+ context = null;
// Transform constructor body.
FunctionNode function = node.function;
if (function.body != null && function.body is! EmptyStatement) {
@@ -424,6 +425,8 @@ class ClosureConverter extends Transformer {
FunctionNode function = node.function;
if (function.body != null) {
+ bool hadSingleStatementBody = function.body is! Block;
+
setupContextForFunctionBody(function);
VariableDeclaration self = thisAccess[currentMemberFunction];
if (self != null) {
@@ -431,6 +434,22 @@ class ClosureConverter extends Transformer {
}
node.transformChildren(this);
resetContext();
+
+ // Here a special case is handled: the body of the procedure was a single
+ // statement and after the transformation it is a block with a single
+ // statement inside. In this case we make this statement the body of the
+ // procedure again. It is required to follow the conventions imposed by
+ // [addClass] in [DillLibraryBuilder].
+ // See [dill_library_builder.dart]
+ // (../../../../front_end/lib/src/fasta/dill/dill_library_builder.dart)
+ // for details.
+ if (hadSingleStatementBody && function.body is Block) {
+ Block body = function.body;
+ if (body.statements.length == 1) {
+ function.body = body.statements[0];
+ function.body.parent = function;
+ }
+ }
}
return node;
@@ -483,7 +502,7 @@ class ClosureConverter extends Transformer {
TreeNode visitBlock(Block node) {
return saveContext(() {
BlockRewriter blockRewriter = rewriter = rewriter.forNestedBlock(node);
- blockRewriter.transformStatements(node, this);
+ blockRewriter.transformStatements(this);
return node;
});
}
@@ -643,9 +662,8 @@ class ClosureConverter extends Transformer {
TreeNode visitPropertyGet(PropertyGet node) {
Name tearOffName = tearOffGetterNames[node.name];
if (tearOffName != null) {
- MethodInvocation replacement = new MethodInvocation(
- node.receiver, tearOffName, new Arguments(<Expression>[]));
- return super.visitMethodInvocation(replacement);
+ PropertyGet replacement = new PropertyGet(node.receiver, tearOffName);
+ return super.visitPropertyGet(replacement);
}
return super.visitPropertyGet(node);
}
@@ -871,7 +889,7 @@ class ClosureConverter extends Transformer {
self, procedure, contextVariable, parent.expression)));
Procedure tearOffMethod = new Procedure(
- name, ProcedureKind.Method, tearOffMethodFunction,
+ name, ProcedureKind.Getter, tearOffMethodFunction,
fileUri: currentFileUri);
newClassMembers.add(tearOffMethod);
« no previous file with comments | « no previous file | pkg/kernel/lib/transformations/closure/rewriter.dart » ('j') | runtime/vm/kernel_binary_flowgraph.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698