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

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

Issue 1678753002: Summarize constructor initializers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Updates for review comments. Created 4 years, 10 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/analyzer/lib/src/summary/summarize_const_expr.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_const_expr.dart b/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
index d82ee6447f9c925ca0f7d346e6a729295cf013a4..70f1974459146d20333aab29aa62e2e98278779c 100644
--- a/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_const_expr.dart
@@ -10,6 +10,35 @@ import 'package:analyzer/src/summary/format.dart';
import 'package:analyzer/src/summary/idl.dart';
/**
+ * Serialize the given constructor initializer [node].
+ */
+UnlinkedConstructorInitializer serializeConstructorInitializer(
+ ConstructorInitializer node,
+ UnlinkedConstBuilder serializeConstExpr(Expression expr)) {
+ if (node is ConstructorFieldInitializer) {
+ return new UnlinkedConstructorInitializerBuilder(
+ kind: UnlinkedConstructorInitializerKind.field,
+ name: node.fieldName.name,
+ expression: serializeConstExpr(node.expression));
+ }
+ if (node is RedirectingConstructorInvocation) {
+ return new UnlinkedConstructorInitializerBuilder(
+ kind: UnlinkedConstructorInitializerKind.thisInvocation,
+ name: node?.constructorName?.name,
+ arguments:
+ node.argumentList.arguments.map(serializeConstExpr).toList());
+ }
+ if (node is SuperConstructorInvocation) {
+ return new UnlinkedConstructorInitializerBuilder(
+ kind: UnlinkedConstructorInitializerKind.superInvocation,
+ name: node?.constructorName?.name,
+ arguments:
+ node.argumentList.arguments.map(serializeConstExpr).toList());
+ }
+ throw new StateError('Unexpected initializer type ${node.runtimeType}');
+}
+
+/**
* Instances of this class keep track of intermediate state during
* serialization of a single constant [Expression].
*/
@@ -40,6 +69,12 @@ abstract class AbstractConstExprSerializer {
final List<EntityRefBuilder> references = <EntityRefBuilder>[];
/**
+ * Return `true` if a constructor initializer expression is being serialized
+ * and the given [name] is a constructor parameter reference.
+ */
+ bool isConstructorParameterName(String name);
+
+ /**
* Serialize the given [expr] expression into this serializer state.
*/
void serialize(Expression expr) {
@@ -62,8 +97,13 @@ abstract class AbstractConstExprSerializer {
} else if (expr is NullLiteral) {
operations.add(UnlinkedConstOperation.pushNull);
} else if (expr is Identifier) {
- references.add(serializeIdentifier(expr));
- operations.add(UnlinkedConstOperation.pushReference);
+ if (expr is SimpleIdentifier && isConstructorParameterName(expr.name)) {
+ strings.add(expr.name);
+ operations.add(UnlinkedConstOperation.pushConstructorParameter);
+ } else {
+ references.add(serializeIdentifier(expr));
+ operations.add(UnlinkedConstOperation.pushReference);
+ }
} else if (expr is InstanceCreationExpression) {
serializeInstanceCreation(
serializeConstructorName(
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_ast.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698