2016-02-02 18:15:44 +00:00
|
|
|
// 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) \
|
2016-11-08 21:54:47 +00:00
|
|
|
const TokenPosition TokenPosition::k##name = TokenPosition(value);
|
|
|
|
SENTINEL_TOKEN_DESCRIPTORS(DEFINE_VALUES);
|
2016-02-02 18:15:44 +00:00
|
|
|
#undef DEFINE_VALUES
|
2016-11-08 21:54:47 +00:00
|
|
|
const TokenPosition TokenPosition::kMinSource = TokenPosition(kMinSourcePos);
|
2016-02-02 18:15:44 +00:00
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
const TokenPosition TokenPosition::kMaxSource = TokenPosition(kMaxSourcePos);
|
2016-02-02 18:15:44 +00:00
|
|
|
|
|
|
|
const char* TokenPosition::ToCString() const {
|
|
|
|
switch (value_) {
|
|
|
|
#define DEFINE_CASE(name, value) \
|
2016-11-08 21:54:47 +00:00
|
|
|
case value: \
|
|
|
|
return #name;
|
2016-02-02 18:15:44 +00:00
|
|
|
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
|