mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 09:43:08 +00:00
[cfe] Add support for constructor initializers to text serialization
Change-Id: I1a311978460bee2f554a3bddbaf329698d1d33c4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153779 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
This commit is contained in:
parent
d5664c360a
commit
99b693ba88
2 changed files with 63 additions and 6 deletions
|
@ -328,21 +328,15 @@ class VerificationState {
|
|||
node is FunctionNode && node.body == null ||
|
||||
node is Procedure &&
|
||||
(!node.isStatic || node.kind != ProcedureKind.Method) ||
|
||||
node is AssertInitializer ||
|
||||
node is Class ||
|
||||
node is Component ||
|
||||
node is Constructor ||
|
||||
node is Extension ||
|
||||
node is FieldInitializer ||
|
||||
node is InvalidInitializer ||
|
||||
node is Library ||
|
||||
node is LibraryPart ||
|
||||
node is LocalInitializer ||
|
||||
node is MapEntry ||
|
||||
node is Name && node.isPrivate ||
|
||||
node is RedirectingFactoryConstructor ||
|
||||
node is RedirectingInitializer ||
|
||||
node is SuperInitializer ||
|
||||
node is Supertype ||
|
||||
node is Typedef;
|
||||
}
|
||||
|
@ -489,6 +483,8 @@ class TextSerializationVerifier extends RecursiveVisitor<void> {
|
|||
makeRoundTrip<Catch>(node, catchSerializer);
|
||||
} else if (node is SwitchCase) {
|
||||
makeRoundTrip<SwitchCase>(node, switchCaseSerializer);
|
||||
} else if (node is Initializer) {
|
||||
makeRoundTrip<Initializer>(node, initializerSerializer);
|
||||
} else {
|
||||
throw new StateError(
|
||||
"Don't know how to make a round trip for a supported node "
|
||||
|
|
|
@ -1826,6 +1826,59 @@ TextSerializer<InstanceConstant> instanceConstantSerializer =
|
|||
|
||||
Case<Constant> constantSerializer = Case.uninitialized(ConstantTagger());
|
||||
|
||||
class InitializerTagger implements Tagger<Initializer> {
|
||||
const InitializerTagger();
|
||||
|
||||
String tag(Initializer node) {
|
||||
if (node is AssertInitializer) {
|
||||
return "assert";
|
||||
} else if (node is FieldInitializer) {
|
||||
return "field";
|
||||
} else if (node is InvalidInitializer) {
|
||||
return "invalid";
|
||||
} else if (node is LocalInitializer) {
|
||||
return "local";
|
||||
} else if (node is RedirectingInitializer) {
|
||||
return "redirecting";
|
||||
} else if (node is SuperInitializer) {
|
||||
return "super";
|
||||
} else {
|
||||
throw UnimplementedError("InitializerTagger.tag(${node.runtimeType}).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextSerializer<AssertInitializer> assertInitializerSerializer = Wrapped(
|
||||
(w) => w.statement, (u) => AssertInitializer(u), statementSerializer);
|
||||
|
||||
TextSerializer<FieldInitializer> fieldInitializerSerializer = Wrapped(
|
||||
(w) => Tuple2(w.fieldReference.canonicalName, w.value),
|
||||
(u) => FieldInitializer.byReference(u.first.getReference(), u.second),
|
||||
Tuple2Serializer(CanonicalNameSerializer(), expressionSerializer));
|
||||
|
||||
TextSerializer<InvalidInitializer> invalidInitializerSerializer =
|
||||
Wrapped((_) => null, (_) => InvalidInitializer(), Nothing());
|
||||
|
||||
TextSerializer<LocalInitializer> localInitializerSerializer = Wrapped(
|
||||
(w) => w.variable,
|
||||
(u) => LocalInitializer(u),
|
||||
variableDeclarationSerializer);
|
||||
|
||||
TextSerializer<RedirectingInitializer> redirectingInitializerSerializer =
|
||||
Wrapped(
|
||||
(w) => Tuple2(w.targetReference.canonicalName, w.arguments),
|
||||
(u) => RedirectingInitializer.byReference(
|
||||
u.first.getReference(), u.second),
|
||||
Tuple2Serializer(CanonicalNameSerializer(), argumentsSerializer));
|
||||
|
||||
TextSerializer<SuperInitializer> superInitializerSerializer = Wrapped(
|
||||
(w) => Tuple2(w.targetReference.canonicalName, w.arguments),
|
||||
(u) => SuperInitializer.byReference(u.first.getReference(), u.second),
|
||||
Tuple2Serializer(CanonicalNameSerializer(), argumentsSerializer));
|
||||
|
||||
Case<Initializer> initializerSerializer =
|
||||
Case.uninitialized(InitializerTagger());
|
||||
|
||||
void initializeSerializers() {
|
||||
expressionSerializer.registerTags({
|
||||
"string": stringLiteralSerializer,
|
||||
|
@ -1950,4 +2003,12 @@ void initializeSerializers() {
|
|||
"const-expr": unevaluatedConstantSerializer,
|
||||
"const-object": instanceConstantSerializer,
|
||||
});
|
||||
initializerSerializer.registerTags({
|
||||
"assert": assertInitializerSerializer,
|
||||
"field": fieldInitializerSerializer,
|
||||
"invalid": invalidInitializerSerializer,
|
||||
"local": localInitializerSerializer,
|
||||
"redirecting": redirectingInitializerSerializer,
|
||||
"super": superInitializerSerializer,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue