7ad5ee3dae
When using the --dump-kernel-bytecode flag, also print the line and number of the source position encoded by a synthetic token position. Also use the decoded value for a synthetic token position when converting it as a C string for printing, which also makes it easier to correlate real and synthetic token positions encoding the same source position. Also change the long outdated comment about synthetic token positions not encoding a real source offset, as most if not all uses of them do actually encode a real source offset. TEST=manual use during debugging Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try Change-Id: Ic16e320e9a10d8343e8a37c8270c7076bb7052c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484943 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
// Copyright (c) 2016, 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.
|
|
|
|
#include "vm/token_position.h"
|
|
|
|
#include "vm/object.h"
|
|
#include "vm/zone_text_buffer.h"
|
|
|
|
namespace dart {
|
|
|
|
uword TokenPosition::Hash() const {
|
|
return Utils::WordHash(value_);
|
|
}
|
|
|
|
TokenPosition TokenPosition::Deserialize(int32_t value) {
|
|
return TokenPosition(value);
|
|
}
|
|
|
|
int32_t TokenPosition::Serialize() const {
|
|
return static_cast<int32_t>(value_);
|
|
}
|
|
|
|
intptr_t TokenPosition::EncodeCoveragePosition(bool is_branch_coverage) {
|
|
// Normal coverage positions are encoded as 2 * pos, and branch coverage are
|
|
// encoded as 2 * pos + 1.
|
|
intptr_t encoded_position = 2 * static_cast<intptr_t>(value_);
|
|
return is_branch_coverage ? encoded_position + 1 : encoded_position;
|
|
}
|
|
|
|
TokenPosition TokenPosition::DecodeCoveragePosition(intptr_t encoded_position,
|
|
bool* is_branch_coverage) {
|
|
*is_branch_coverage = ((encoded_position % 2) == 1);
|
|
return TokenPosition(encoded_position / 2);
|
|
}
|
|
|
|
#define DEFINE_VALUES(name, value) \
|
|
const TokenPosition TokenPosition::k##name(value);
|
|
SENTINEL_TOKEN_DESCRIPTORS(DEFINE_VALUES);
|
|
#undef DEFINE_VALUES
|
|
const TokenPosition TokenPosition::kMinSource(kMinSourcePos);
|
|
const TokenPosition TokenPosition::kMaxSource(kMaxSourcePos);
|
|
|
|
const char* TokenPosition::ToCString() const {
|
|
switch (value_) {
|
|
#define DEFINE_CASE(name, value) \
|
|
case value: \
|
|
return #name;
|
|
SENTINEL_TOKEN_DESCRIPTORS(DEFINE_CASE);
|
|
#undef DEFINE_CASE
|
|
default:
|
|
break;
|
|
}
|
|
ASSERT(IsReal() || IsSynthetic());
|
|
ZoneTextBuffer buffer(Thread::Current()->zone());
|
|
int32_t encoded_value = value_;
|
|
if (IsSynthetic()) {
|
|
buffer.AddString("syn:");
|
|
// Use the decoded value for printing, so it can be more easily
|
|
// correlated with real token positions encoding the same source offset.
|
|
encoded_value = ConvertSynthetic(value_);
|
|
}
|
|
buffer.Printf("%" Pd32 "", encoded_value);
|
|
return buffer.buffer();
|
|
}
|
|
|
|
} // namespace dart
|