1 | // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
---|---|
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #include "vm/token_position.h" |
6 | |
7 | #include "vm/object.h" |
8 | |
9 | namespace dart { |
10 | |
11 | TokenPosition TokenPosition::SnapshotDecode(int32_t value) { |
12 | return TokenPosition(static_cast<intptr_t>(value)); |
13 | } |
14 | |
15 | int32_t TokenPosition::SnapshotEncode() { |
16 | return static_cast<int32_t>(value_); |
17 | } |
18 | |
19 | bool TokenPosition::IsSynthetic() const { |
20 | if (value_ >= kMinSourcePos) { |
21 | return false; |
22 | } |
23 | if (value_ < kLast.value()) { |
24 | return true; |
25 | } |
26 | return false; |
27 | } |
28 | |
29 | #define DEFINE_VALUES(name, value) \ |
30 | const TokenPosition TokenPosition::k##name = TokenPosition(value); |
31 | SENTINEL_TOKEN_DESCRIPTORS(DEFINE_VALUES); |
32 | #undef DEFINE_VALUES |
33 | const TokenPosition TokenPosition::kMinSource = TokenPosition(kMinSourcePos); |
34 | |
35 | const TokenPosition TokenPosition::kMaxSource = TokenPosition(kMaxSourcePos); |
36 | |
37 | const char* TokenPosition::ToCString() const { |
38 | switch (value_) { |
39 | #define DEFINE_CASE(name, value) \ |
40 | case value: \ |
41 | return #name; |
42 | SENTINEL_TOKEN_DESCRIPTORS(DEFINE_CASE); |
43 | #undef DEFINE_CASE |
44 | default: { |
45 | Zone* zone = Thread::Current()->zone(); |
46 | ASSERT(zone != NULL); |
47 | if (IsSynthetic()) { |
48 | // TODO(johnmccutchan): Print synthetic positions differently. |
49 | return FromSynthetic().ToCString(); |
50 | } else { |
51 | return OS::SCreate(zone, "%d", value_); |
52 | } |
53 | } |
54 | } |
55 | } |
56 | |
57 | } // namespace dart |
58 |