Files
sdk/pkg/vm/lib/metadata/direct_call.dart
T
Jens Johansen 6c909a0efa Be explicit about whether a reference is allowed to be null or not
Before this change we allowed to serialize some references as null,
and would only complain when trying to read the dill back in.
This CL changes that so it complains up front.

It is unknown if any of this would ever occur in practise.

Change-Id: Id5e1af89abfb88a2d4249bd439b53b062d7aeffa
Reviewed-on: https://dart-review.googlesource.com/c/85392
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2019-01-04 08:39:36 +00:00

54 lines
1.8 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';
/// Metadata for annotating method invocations converted to direct calls.
class DirectCallMetadata {
final Reference _targetReference;
final bool checkReceiverForNull;
DirectCallMetadata(Member target, bool checkReceiverForNull)
: this.byReference(getMemberReference(target), checkReceiverForNull);
DirectCallMetadata.byReference(
this._targetReference, this.checkReceiverForNull);
Member get target => _targetReference.asMember;
@override
String toString() => "${target}${checkReceiverForNull ? '??' : ''}";
}
/// Repository for [DirectCallMetadata].
class DirectCallMetadataRepository
extends MetadataRepository<DirectCallMetadata> {
@override
final String tag = 'vm.direct-call.metadata';
@override
final Map<TreeNode, DirectCallMetadata> mapping =
<TreeNode, DirectCallMetadata>{};
@override
void writeToBinary(DirectCallMetadata metadata, Node node, BinarySink sink) {
sink.writeNullAllowedCanonicalNameReference(
getCanonicalNameOfMember(metadata.target));
sink.writeByte(metadata.checkReceiverForNull ? 1 : 0);
}
@override
DirectCallMetadata readFromBinary(Node node, BinarySource source) {
final targetReference = source.readCanonicalNameReference()?.getReference();
if (targetReference == null) {
throw 'DirectCallMetadata should have a non-null target';
}
final checkReceiverForNull = (source.readByte() != 0);
return new DirectCallMetadata.byReference(
targetReference, checkReceiverForNull);
}
}