Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3fa2d81

Browse files
Dmitry Stefantsovcommit-bot@chromium.org
authored andcommitted
[cfe] Add serialization support for top-level methods
Change-Id: Ie2f949142dc8fd97a0ad937b1ccc38918f3aae87 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143584 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
1 parent 2d12821 commit 3fa2d81

File tree

2 files changed

+207
-102
lines changed

2 files changed

+207
-102
lines changed

pkg/kernel/lib/text/text_serializer.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,37 @@ FunctionNode wrapSyncYieldingFunctionNode(
12271227
Case<FunctionNode> functionNodeSerializer =
12281228
new Case.uninitialized(const FunctionNodeTagger());
12291229

1230+
class ProcedureTagger implements Tagger<Procedure> {
1231+
const ProcedureTagger();
1232+
1233+
String tag(Procedure node) {
1234+
String prefix = node.isStatic ? "static-" : "";
1235+
switch (node.kind) {
1236+
case ProcedureKind.Method:
1237+
return "${prefix}method";
1238+
default:
1239+
throw new UnsupportedError("${node.kind}");
1240+
}
1241+
}
1242+
}
1243+
1244+
TextSerializer<Procedure> staticMethodSerializer = new Wrapped(
1245+
unwrapStaticMethod,
1246+
wrapStaticMethod,
1247+
new Tuple2Serializer(nameSerializer, functionNodeSerializer));
1248+
1249+
Tuple2<Name, FunctionNode> unwrapStaticMethod(Procedure procedure) {
1250+
return new Tuple2(procedure.name, procedure.function);
1251+
}
1252+
1253+
Procedure wrapStaticMethod(Tuple2<Name, FunctionNode> tuple) {
1254+
return new Procedure(tuple.first, ProcedureKind.Method, tuple.second,
1255+
isStatic: true);
1256+
}
1257+
1258+
Case<Procedure> procedureSerializer =
1259+
new Case.uninitialized(const ProcedureTagger());
1260+
12301261
void initializeSerializers() {
12311262
expressionSerializer.tags.addAll([
12321263
"string",
@@ -1358,4 +1389,6 @@ void initializeSerializers() {
13581389
asyncStarFunctionNodeSerializer,
13591390
syncYieldingStarFunctionNodeSerializer,
13601391
]);
1392+
procedureSerializer.tags.addAll(["static-method"]);
1393+
procedureSerializer.serializers.addAll([staticMethodSerializer]);
13611394
}

0 commit comments

Comments
 (0)