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 321e9aa10bbec70655c19a433663c3fb31aa8538..36fda8bf5558699dacda38a28d35b093fdf7d74c 100644 |
--- a/pkg/analyzer/lib/src/summary/summarize_ast.dart |
+++ b/pkg/analyzer/lib/src/summary/summarize_ast.dart |
@@ -43,8 +43,9 @@ class _ConstExprSerializer extends AbstractConstExprSerializer { |
*/ |
final Set<String> parameterNames; |
- _ConstExprSerializer( |
- this.visitor, this.localClosureIndexMap, this.parameterNames); |
+ _ConstExprSerializer(bool forConst, this.visitor, this.localClosureIndexMap, |
+ this.parameterNames) |
+ : super(forConst); |
@override |
bool isParameterName(String name) { |
@@ -413,7 +414,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
// localClosureIndexMap. |
Map<int, int> localClosureIndexMap = null; |
_ConstExprSerializer serializer = |
- new _ConstExprSerializer(this, localClosureIndexMap, null); |
+ new _ConstExprSerializer(true, this, localClosureIndexMap, null); |
try { |
serializer.serializeAnnotation(a); |
} on StateError { |
@@ -549,10 +550,10 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
* Serialize the given [expression], creating an [UnlinkedExprBuilder]. |
*/ |
UnlinkedExprBuilder serializeConstExpr( |
- Map<int, int> localClosureIndexMap, Expression expression, |
+ bool forConst, Map<int, int> localClosureIndexMap, Expression expression, |
[Set<String> parameterNames]) { |
- _ConstExprSerializer serializer = |
- new _ConstExprSerializer(this, localClosureIndexMap, parameterNames); |
+ _ConstExprSerializer serializer = new _ConstExprSerializer( |
+ forConst, this, localClosureIndexMap, parameterNames); |
serializer.serialize(expression); |
return serializer.toBuilder(); |
} |
@@ -692,7 +693,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
_parameterNames.addAll(formalParameters.parameters |
.map((FormalParameter p) => p.identifier.name)); |
} |
- serializeFunctionBody(b, null, body, serializeBodyExpr, serializeBody); |
+ serializeFunctionBody( |
+ b, null, body, serializeBodyExpr, serializeBody, false); |
_parameterNames = oldParameterNames; |
scopes.removeLast(); |
assert(scopes.length == oldScopesLength); |
@@ -720,7 +722,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
List<ConstructorInitializer> initializers, |
AstNode body, |
bool serializeBodyExpr, |
- bool serializeBody) { |
+ bool serializeBody, |
+ bool forConst) { |
if (body is BlockFunctionBody || body is ExpressionFunctionBody) { |
for (UnlinkedParamBuilder parameter in b.parameters) { |
if (!parameter.isInitializingFormal) { |
@@ -749,11 +752,11 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
} |
if (serializeBodyExpr) { |
if (body is Expression) { |
- b.bodyExpr = |
- serializeConstExpr(_localClosureIndexMap, body, _parameterNames); |
+ b.bodyExpr = serializeConstExpr( |
+ forConst, _localClosureIndexMap, body, _parameterNames); |
} else if (body is ExpressionFunctionBody) { |
b.bodyExpr = serializeConstExpr( |
- _localClosureIndexMap, body.expression, _parameterNames); |
+ forConst, _localClosureIndexMap, body.expression, _parameterNames); |
} else { |
// TODO(paulberry): serialize other types of function bodies. |
} |
@@ -816,14 +819,14 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
* in [UnlinkedExecutableBuilder.bodyExpr]. |
*/ |
UnlinkedExecutableBuilder serializeInitializerFunction( |
- Expression expression, bool serializeBodyExpr) { |
+ Expression expression, bool serializeBodyExpr, bool forConst) { |
if (expression == null) { |
return null; |
} |
UnlinkedExecutableBuilder initializer = |
new UnlinkedExecutableBuilder(nameOffset: expression.offset); |
serializeFunctionBody( |
- initializer, null, expression, serializeBodyExpr, true); |
+ initializer, null, expression, serializeBodyExpr, true, forConst); |
initializer.inferredReturnTypeSlot = assignSlot(); |
return initializer; |
} |
@@ -1023,8 +1026,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
bool serializeBodyExpr = variable.isConst || |
variable.isFinal && isField && !isDeclaredStatic || |
variables.type == null; |
- b.initializer = |
- serializeInitializerFunction(variable.initializer, serializeBodyExpr); |
+ b.initializer = serializeInitializerFunction( |
+ variable.initializer, serializeBodyExpr, b.isConst); |
if (isField && !isDeclaredStatic && !variables.isFinal) { |
b.inheritsCovariantSlot = assignSlot(); |
} |
@@ -1126,7 +1129,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
// don't need a localClosureIndexMap. |
Map<int, int> localClosureIndexMap = null; |
b.redirectedConstructor = |
- new _ConstExprSerializer(this, localClosureIndexMap, null) |
+ new _ConstExprSerializer(true, this, localClosureIndexMap, null) |
.serializeConstructorRef(null, typeName.name, |
typeName.typeArguments, node.redirectedConstructor.name); |
} |
@@ -1147,16 +1150,16 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
b.documentationComment = serializeDocumentation(node.documentationComment); |
b.annotations = serializeAnnotations(node.metadata); |
b.codeRange = serializeCodeRange(node); |
- Map<int, int> localClosureIndexMap = serializeFunctionBody( |
- b, node.initializers, node.body, node.constKeyword != null, false); |
+ Map<int, int> localClosureIndexMap = serializeFunctionBody(b, |
+ node.initializers, node.body, node.constKeyword != null, false, false); |
if (node.constKeyword != null) { |
Set<String> constructorParameterNames = |
node.parameters.parameters.map((p) => p.identifier.name).toSet(); |
b.constantInitializers = node.initializers |
.map((ConstructorInitializer initializer) => |
serializeConstructorInitializer(initializer, (Expression expr) { |
- return serializeConstExpr( |
- localClosureIndexMap, expr, constructorParameterNames); |
+ return serializeConstExpr(true, localClosureIndexMap, expr, |
+ constructorParameterNames); |
})) |
.toList(); |
} |
@@ -1168,7 +1171,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { |
DefaultFormalParameter node) { |
UnlinkedParamBuilder b = |
node.parameter.accept(this) as UnlinkedParamBuilder; |
- b.initializer = serializeInitializerFunction(node.defaultValue, true); |
+ b.initializer = serializeInitializerFunction(node.defaultValue, true, true); |
if (node.defaultValue != null) { |
b.defaultValueCode = node.defaultValue.toSource(); |
} |