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