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

Unified Diff: pkg/analyzer/lib/src/summary/summarize_ast.dart

Issue 1968063002: Handle more corner cases of closures while doing ast-based summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/summarize_ast.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_ast.dart b/pkg/analyzer/lib/src/summary/summarize_ast.dart
index 8349428600f886846e871b003c52e92500646849..f5dd314cd5cce51d57cff3756a110a9b59919437 100644
--- a/pkg/analyzer/lib/src/summary/summarize_ast.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_ast.dart
@@ -388,7 +388,9 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
return const <UnlinkedConstBuilder>[];
}
return annotations.map((Annotation a) {
- Map<int, int> localClosureIndexMap = null; // TODO(paulberry): fix.
+ // Closures can't appear inside annotations, so we don't need a
+ // localClosureIndexMap.
+ Map<int, int> localClosureIndexMap = null;
_ConstExprSerializer serializer =
new _ConstExprSerializer(this, localClosureIndexMap, null);
serializer.serializeAnnotation(a);
@@ -641,7 +643,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
}
b.visibleOffset = enclosingBlock?.offset;
b.visibleLength = enclosingBlock?.length;
- serializeFunctionBody(b, body);
+ serializeFunctionBody(b, null, body);
scopes.removeLast();
assert(scopes.length == oldScopesLength);
return b;
@@ -651,8 +653,12 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
* Record local functions and variables into the given executable. The given
* [body] is usually an actual [FunctionBody], but may be an [Expression]
* when we process a synthetic variable initializer function.
+ *
+ * If [initializers] is non-`null`, closures occurring inside the initializers
+ * are serialized first.
*/
- void serializeFunctionBody(UnlinkedExecutableBuilder b, AstNode body) {
+ void serializeFunctionBody(UnlinkedExecutableBuilder b,
+ List<ConstructorInitializer> initializers, AstNode body) {
if (body is BlockFunctionBody || body is ExpressionFunctionBody) {
for (UnlinkedParamBuilder parameter in b.parameters) {
parameter.visibleOffset = body.offset;
@@ -665,6 +671,11 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
executables = <UnlinkedExecutableBuilder>[];
labels = <UnlinkedLabelBuilder>[];
variables = <UnlinkedVariableBuilder>[];
+ if (initializers != null) {
+ for (ConstructorInitializer initializer in initializers) {
+ initializer.accept(this);
+ }
+ }
body.accept(this);
b.localFunctions = executables;
b.localLabels = labels;
@@ -700,7 +711,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
}
UnlinkedExecutableBuilder initializer =
new UnlinkedExecutableBuilder(nameOffset: expression.offset);
- serializeFunctionBody(initializer, expression);
+ serializeFunctionBody(initializer, null, expression);
initializer.inferredReturnTypeSlot = assignSlot();
return initializer;
}
@@ -987,7 +998,9 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
if (node.redirectedConstructor != null) {
b.isRedirectedConstructor = true;
TypeName typeName = node.redirectedConstructor.type;
- Map<int, int> localClosureIndexMap = null; // TODO(paulberry): fix.
+ // Closures can't appear inside factory constructor redirections, so we
+ // don't need a localClosureIndexMap.
+ Map<int, int> localClosureIndexMap = null;
b.redirectedConstructor =
new _ConstExprSerializer(this, localClosureIndexMap, null)
.serializeConstructorRef(null, typeName.name,
@@ -1009,10 +1022,12 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
b.documentationComment = serializeDocumentation(node.documentationComment);
b.annotations = serializeAnnotations(node.metadata);
b.codeRange = serializeCodeRange(node);
+ Map<int, int> localClosureIndexMap = _withLocalClosureIndexMap(() {
+ serializeFunctionBody(b, node.initializers, node.body);
+ });
if (node.constKeyword != null) {
Set<String> constructorParameterNames =
node.parameters.parameters.map((p) => p.identifier.name).toSet();
- Map<int, int> localClosureIndexMap = null; // TODO(paulberry): fix.
b.constantInitializers = node.initializers
.map((ConstructorInitializer initializer) =>
serializeConstructorInitializer(initializer, (Expression expr) {
@@ -1021,7 +1036,6 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
}))
.toList();
}
- serializeFunctionBody(b, node.body);
executables.add(b);
}
@@ -1030,7 +1044,9 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
DefaultFormalParameter node) {
UnlinkedParamBuilder b = node.parameter.accept(this);
if (node.defaultValue != null) {
- Map<int, int> localClosureIndexMap = null; // TODO(paulberry): fix.
+ // Closures can't appear inside default values, so we don't need a
+ // localClosureIndexMap.
+ Map<int, int> localClosureIndexMap = null;
b.defaultValue =
serializeConstExpr(localClosureIndexMap, node.defaultValue);
b.defaultValueCode = node.defaultValue.toSource();
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698