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

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: 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 b523b8b3c8c40e0bd6633ea4a6cfd0bf4c94bd1f..bee7379d3ec30ff211d2b4e3bac537081163e5d0 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(expr);
} else if (expr is ListLiteral) {
@@ -72,15 +112,15 @@ abstract class AbstractConstExprSerializer {
_serializeMapLiteral(expr);
} else if (expr is MethodInvocation) {
String name = expr.methodName.name;
- if (name != 'identical') {
- throw new _ConstExprSerializationError(
- 'Only "identity" function invocation is allowed.');
- }
- if (expr.argumentList == null ||
- expr.argumentList.arguments.length != 2) {
- throw new _ConstExprSerializationError(
- 'The function "identity" requires exactly 2 arguments.');
- }
+// if (name != 'identical') {
Paul Berry 2016/02/08 14:53:12 Can you include a comment explaining why this code
scheglov 2016/02/08 16:29:51 It should not be commented out. I will uncomment i
+// throw new _ConstExprSerializationError(
+// 'Only "identity" function invocation is allowed.');
+// }
+// if (expr.argumentList == null ||
+// expr.argumentList.arguments.length != 2) {
+// throw new _ConstExprSerializationError(
+// 'The function "identity" requires exactly 2 arguments.');
+// }
expr.argumentList.arguments.forEach(serialize);
operations.add(UnlinkedConstOperation.identical);
} else if (expr is BinaryExpression) {

Powered by Google App Engine
This is Rietveld 408576698