mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
[kernel] Add ability to (de)serialize DirectPropertyGet
Change-Id: Ie75b45601f898a8286c72e97e11e7c08b64c00e8 Reviewed-on: https://dart-review.googlesource.com/c/89526 Reviewed-by: Kevin Millikin <kmillikin@google.com> Reviewed-by: Daniel Hillerström <hillerstrom@google.com>
This commit is contained in:
parent
793fbc0d4a
commit
50c06c55ba
|
@ -100,6 +100,7 @@ class ExpressionTagger extends ExpressionVisitor<String>
|
|||
String visitVariableSet(VariableSet _) => "set-var";
|
||||
String visitStaticGet(StaticGet _) => "get-static";
|
||||
String visitStaticSet(StaticSet _) => "set-static";
|
||||
String visitDirectPropertyGet(DirectPropertyGet _) => "get-direct-prop";
|
||||
}
|
||||
|
||||
TextSerializer<InvalidExpression> invalidExpressionSerializer = new Wrapped(
|
||||
|
@ -571,6 +572,24 @@ StaticSet wrapStaticSet(Tuple2<CanonicalName, Expression> tuple) {
|
|||
return new StaticSet.byReference(tuple.first.getReference(), tuple.second);
|
||||
}
|
||||
|
||||
TextSerializer<DirectPropertyGet> directPropertyGetSerializer = new Wrapped(
|
||||
unwrapDirectPropertyGet,
|
||||
wrapDirectPropertyGet,
|
||||
new Tuple2Serializer(
|
||||
expressionSerializer, const CanonicalNameSerializer()));
|
||||
|
||||
Tuple2<Expression, CanonicalName> unwrapDirectPropertyGet(
|
||||
DirectPropertyGet expression) {
|
||||
return new Tuple2(
|
||||
expression.receiver, expression.targetReference.canonicalName);
|
||||
}
|
||||
|
||||
DirectPropertyGet wrapDirectPropertyGet(
|
||||
Tuple2<Expression, CanonicalName> tuple) {
|
||||
return new DirectPropertyGet.byReference(
|
||||
tuple.first, tuple.second.getReference());
|
||||
}
|
||||
|
||||
Case<Expression> expressionSerializer =
|
||||
new Case.uninitialized(const ExpressionTagger());
|
||||
|
||||
|
@ -779,6 +798,7 @@ void initializeSerializers() {
|
|||
"set-var",
|
||||
"get-static",
|
||||
"set-static",
|
||||
"get-direct-prop",
|
||||
]);
|
||||
expressionSerializer.serializers.addAll([
|
||||
stringLiteralSerializer,
|
||||
|
@ -817,6 +837,7 @@ void initializeSerializers() {
|
|||
variableSetSerializer,
|
||||
staticGetSerializer,
|
||||
staticSetSerializer,
|
||||
directPropertyGetSerializer,
|
||||
]);
|
||||
dartTypeSerializer.tags.addAll([
|
||||
"invalid",
|
||||
|
|
|
@ -132,6 +132,30 @@ void test() {
|
|||
serializationState: new SerializationState(null),
|
||||
deserializationState: new DeserializationState(null, component.root));
|
||||
}(),
|
||||
() {
|
||||
Field field = new Field(new Name("field"), type: const DynamicType());
|
||||
Class klass = new Class(name: "A", fields: <Field>[field]);
|
||||
Library library = new Library(
|
||||
new Uri(scheme: "package", path: "foo/bar.dart"),
|
||||
classes: <Class>[klass]);
|
||||
Component component = new Component(libraries: <Library>[library]);
|
||||
component.computeCanonicalNames();
|
||||
|
||||
VariableDeclaration x =
|
||||
new VariableDeclaration("x", type: const DynamicType());
|
||||
return new TestCase(
|
||||
name: "/* suppose A {dynamic field;} A x; */ x.{A::field}",
|
||||
node: new DirectPropertyGet.byReference(
|
||||
new VariableGet(x), field.reference),
|
||||
expectation: ""
|
||||
"(get-direct-prop (get-var \"x^0\" _)"
|
||||
" \"package:foo/bar.dart::A::@fields::field\")",
|
||||
serializationState: new SerializationState(
|
||||
new SerializationEnvironment(null)..add(x, "x^0")),
|
||||
deserializationState: new DeserializationState(
|
||||
new DeserializationEnvironment(null)..add("x^0", x),
|
||||
component.root));
|
||||
}(),
|
||||
];
|
||||
for (TestCase testCase in tests) {
|
||||
String roundTripInput =
|
||||
|
|
Loading…
Reference in a new issue