f6e4b77f6a
The Next() method on TokenPositions used to increment the internal value_ field, but now creates a new TokenPosition with value_ + 1. There are only three places this is used: * Getting the token position after the end token position for implicit closure functions in the scope builder. * Getting the token position after the end token position for variable declarations in the scope builder. * Iterating over the token positions on a single source line in the debugger. So the overhead of creating new TokenPositions vs. mutating the original should be limited, compared to the benefit of being able to assume TokenPosition values are constant once created. There's too much dependence on the copy and copy assignment operators due to the previous possibility of mutation to make the internal field constant at the moment without much more sweeping changes, unfortunately. Also remove the copy assignment in initializing TokenPosition constants. TEST=Tested using existing tests on trybots. Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-release-x64-try,vm-kernel-nnbd-linux-release-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-linux-product-x64-try,vm-kernel-precomp-linux-product-x64-try Change-Id: Ie18b7f45bd9c6a43647ecd189330d91a4dff373b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174922 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Clement Skau <cskau@google.com>
58 lines
1.6 KiB
C++
58 lines
1.6 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"
|
|
|
|
namespace dart {
|
|
|
|
TokenPosition TokenPosition::SnapshotDecode(int32_t value) {
|
|
return TokenPosition(static_cast<intptr_t>(value));
|
|
}
|
|
|
|
int32_t TokenPosition::SnapshotEncode() {
|
|
return static_cast<int32_t>(value_);
|
|
}
|
|
|
|
bool TokenPosition::IsSynthetic() const {
|
|
if (value_ >= kMinSourcePos) {
|
|
return false;
|
|
}
|
|
if (value_ < kLast.value()) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
#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: {
|
|
Zone* zone = Thread::Current()->zone();
|
|
ASSERT(zone != NULL);
|
|
if (IsSynthetic()) {
|
|
// TODO(johnmccutchan): Print synthetic positions differently.
|
|
return FromSynthetic().ToCString();
|
|
} else {
|
|
return OS::SCreate(zone, "%d", value_);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace dart
|