Files
sdk/pkg/vm/lib/metadata/direct_call.dart
T
Johnni Winther 1aa6f00107 [kernel] Refactor CanonicalName/Reference integration
The CL is a step towards have a more restricted and wellstructured
handled of references and canonical names.

The CL moves Reference to canonical_name.dart and makes
CanonicalName.reference private, and replaces CanonicalName.getReference
with a 'reference' getter.

It also removes NamedNode.canonicalName, Field.getterCanonicalName and
Field.setterCanonicalName so that these can only be accessed through the
corresponding reference. This is to reduce the reliance on the
canonical names which, ideally, should only be part of serialization and
deserialization.

TEST=existing

Change-Id: I955fb7d52d4e112d8741f7c12dcf38b74ae0c91a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190442
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-03-10 15:39:28 +00:00

60 lines
1.9 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library vm.metadata.direct_call;
import 'package:kernel/ast.dart';
import 'package:kernel/src/printer.dart';
/// Metadata for annotating method invocations converted to direct calls.
class DirectCallMetadata {
final Reference _targetReference;
final bool checkReceiverForNull;
DirectCallMetadata(Member target, bool checkReceiverForNull)
: this.byReference(
getMemberReferenceGetter(target), checkReceiverForNull);
DirectCallMetadata.byReference(
this._targetReference, this.checkReceiverForNull);
Member get target => _targetReference.asMember;
@override
String toString() => "${target.toText(astTextStrategyForTesting)}"
"${checkReceiverForNull ? '??' : ''}";
}
/// Repository for [DirectCallMetadata].
class DirectCallMetadataRepository
extends MetadataRepository<DirectCallMetadata> {
static const repositoryTag = 'vm.direct-call.metadata';
@override
String get tag => repositoryTag;
@override
final Map<TreeNode, DirectCallMetadata> mapping =
<TreeNode, DirectCallMetadata>{};
@override
void writeToBinary(DirectCallMetadata metadata, Node node, BinarySink sink) {
sink.writeNullAllowedCanonicalNameReference(
getCanonicalNameOfMemberGetter(metadata.target));
sink.writeByte(metadata.checkReceiverForNull ? 1 : 0);
}
@override
DirectCallMetadata readFromBinary(Node node, BinarySource source) {
final targetReference =
source.readNullableCanonicalNameReference()?.reference;
if (targetReference == null) {
throw 'DirectCallMetadata should have a non-null target';
}
final checkReceiverForNull = (source.readByte() != 0);
return new DirectCallMetadata.byReference(
targetReference, checkReceiverForNull);
}
}