OLD | NEW |
(Empty) | |
| 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 |
| 12 TokenPosition TokenPosition::SnapshotDecode(int32_t value) { |
| 13 return TokenPosition(static_cast<intptr_t>(value)); |
| 14 } |
| 15 |
| 16 |
| 17 int32_t TokenPosition::SnapshotEncode() { |
| 18 return static_cast<int32_t>(value_); |
| 19 } |
| 20 |
| 21 |
| 22 bool TokenPosition::IsSynthetic() const { |
| 23 if (value_ >= kMinSourcePos) { |
| 24 return false; |
| 25 } |
| 26 if (value_ < kLast.value()) { |
| 27 return true; |
| 28 } |
| 29 return false; |
| 30 } |
| 31 |
| 32 |
| 33 #define DEFINE_VALUES(name, value) \ |
| 34 const TokenPosition TokenPosition::k##name = TokenPosition(value); |
| 35 SENTINEL_TOKEN_DESCRIPTORS(DEFINE_VALUES); |
| 36 #undef DEFINE_VALUES |
| 37 const TokenPosition TokenPosition::kMinSource = |
| 38 TokenPosition(kMinSourcePos); |
| 39 |
| 40 const TokenPosition TokenPosition::kMaxSource = |
| 41 TokenPosition(kMaxSourcePos); |
| 42 |
| 43 |
| 44 const char* TokenPosition::ToCString() const { |
| 45 switch (value_) { |
| 46 #define DEFINE_CASE(name, value) \ |
| 47 case value: return #name; |
| 48 SENTINEL_TOKEN_DESCRIPTORS(DEFINE_CASE); |
| 49 #undef DEFINE_CASE |
| 50 default: { |
| 51 Zone* zone = Thread::Current()->zone(); |
| 52 ASSERT(zone != NULL); |
| 53 if (IsSynthetic()) { |
| 54 // TODO(johnmccutchan): Print synthetic positions differently. |
| 55 return FromSynthetic().ToCString(); |
| 56 } else { |
| 57 return OS::SCreate(zone, "%d", value_); |
| 58 } |
| 59 } |
| 60 } |
| 61 } |
| 62 |
| 63 } // namespace dart |
OLD | NEW |