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

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

Issue 2891053003: Add support for converted closures with explicit contexts to VM (Closed)
Patch Set: Add streaming-style comment in a branch of VisitExpression 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
« no previous file with comments | « no previous file | pkg/kernel/lib/transformations/closure/rewriter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d03da68508882601d79cab1f09f254952c9ce674 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;
karlklose 2017/06/19 11:58:14 Please check if this is still required.
Dmitry Stefantsov 2017/06/19 12:12:44 Thanks for pointing to this! Apparently, DillLibr
+
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;
});
}
@@ -627,25 +646,26 @@ class ClosureConverter extends Transformer {
}
TreeNode visitStaticGet(StaticGet node) {
- Member target = node.target;
- if (target is Procedure && target.kind == ProcedureKind.Method) {
- VariableDeclaration contextVariable = new VariableDeclaration(
- "#contextParameter",
- type: const VectorType());
- Expression expression = getTearOffExpression(
- null, node.target, contextVariable, new NullLiteral());
- expression.transformChildren(this);
- return expression;
- }
+ // TODO(dmitryas): Add support for tear-offs. When added, uncomment this.
+ //
+ // Member target = node.target;
+ // if (target is Procedure && target.kind == ProcedureKind.Method) {
+ // VariableDeclaration contextVariable = new VariableDeclaration(
+ // "#contextParameter",
+ // type: const VectorType());
+ // Expression expression = getTearOffExpression(
+ // null, node.target, contextVariable, new NullLiteral());
+ // expression.transformChildren(this);
+ // return expression;
+ // }
return super.visitStaticGet(node);
}
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 +891,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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698