344c68e54c
Metadata is no longer written ahead of all nodes. Instead, metadata for each node is written in the same context as the node itself (into a separate buffer). This allows metadata to contain (serialize) arbitrary nodes (for example, arbitrary DartTypes) and use serialization context of parent nodes (such as declared type parameters). However, with this change metadata looses the ability to reference arbitrary AST nodes. This ability was overly restricted and had no practical uses. (It was not possible to reference nodes which are not reachable from root Component. As a consequence, it was not possible to write references to arbitrary DartTypes.) This change aligns the serialization capabilities of metadata with how kernel AST nodes are serialized. Change-Id: I027299a33b599b62572eccd4aa7083ad1dd2b3b3 Reviewed-on: https://dart-review.googlesource.com/54481 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
71 lines
2.2 KiB
Dart
71 lines
2.2 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.procedure_attributes;
|
|
|
|
import 'package:kernel/ast.dart';
|
|
|
|
/// Metadata for annotating procedures with various attributes.
|
|
class ProcedureAttributesMetadata {
|
|
final bool hasDynamicUses;
|
|
final bool hasNonThisUses;
|
|
final bool hasTearOffUses;
|
|
|
|
const ProcedureAttributesMetadata(
|
|
{this.hasDynamicUses, this.hasNonThisUses, this.hasTearOffUses});
|
|
|
|
const ProcedureAttributesMetadata.noDynamicUses()
|
|
: this(hasDynamicUses: false, hasNonThisUses: true, hasTearOffUses: true);
|
|
|
|
@override
|
|
String toString() => "hasDynamicUses:$hasDynamicUses,"
|
|
"hasNonThisUses:$hasNonThisUses,"
|
|
"hasTearOffUses:$hasTearOffUses";
|
|
}
|
|
|
|
/// Repository for [ProcedureAttributesMetadata].
|
|
class ProcedureAttributesMetadataRepository
|
|
extends MetadataRepository<ProcedureAttributesMetadata> {
|
|
static const int kDynamicUsesBit = 1 << 0;
|
|
static const int kNonThisUsesBit = 1 << 1;
|
|
static const int kTearOffUsesBit = 1 << 2;
|
|
|
|
@override
|
|
final String tag = 'vm.procedure-attributes.metadata';
|
|
|
|
@override
|
|
final Map<TreeNode, ProcedureAttributesMetadata> mapping =
|
|
<TreeNode, ProcedureAttributesMetadata>{};
|
|
|
|
@override
|
|
void writeToBinary(
|
|
ProcedureAttributesMetadata metadata, Node node, BinarySink sink) {
|
|
int flags = 0;
|
|
if (metadata.hasDynamicUses) {
|
|
flags |= kDynamicUsesBit;
|
|
}
|
|
if (metadata.hasNonThisUses) {
|
|
flags |= kNonThisUsesBit;
|
|
}
|
|
if (metadata.hasTearOffUses) {
|
|
flags |= kTearOffUsesBit;
|
|
}
|
|
sink.writeByte(flags);
|
|
}
|
|
|
|
@override
|
|
ProcedureAttributesMetadata readFromBinary(Node node, BinarySource source) {
|
|
final int flags = source.readByte();
|
|
|
|
final bool hasDynamicUses = (flags & kDynamicUsesBit) == kDynamicUsesBit;
|
|
final bool hasNonThisUses = (flags & kNonThisUsesBit) == kNonThisUsesBit;
|
|
final bool hasTearOffUses = (flags & kTearOffUsesBit) == kTearOffUsesBit;
|
|
|
|
return new ProcedureAttributesMetadata(
|
|
hasDynamicUses: hasDynamicUses,
|
|
hasNonThisUses: hasNonThisUses,
|
|
hasTearOffUses: hasTearOffUses);
|
|
}
|
|
}
|