Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame^] | 1 | //===-- DebugMacros.h -------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef liblldb_DebugMacros_h_ |
| 10 | #define liblldb_DebugMacros_h_ |
| 11 | |
| 12 | #include <memory> |
| 13 | #include <vector> |
| 14 | |
| 15 | #include "lldb/Utility/ConstString.h" |
| 16 | #include "lldb/lldb-private.h" |
| 17 | |
| 18 | namespace lldb_private { |
| 19 | |
| 20 | class CompileUnit; |
| 21 | class DebugMacros; |
| 22 | typedef std::shared_ptr<DebugMacros> DebugMacrosSP; |
| 23 | |
| 24 | class DebugMacroEntry { |
| 25 | public: |
| 26 | enum EntryType { INVALID, DEFINE, UNDEF, START_FILE, END_FILE, INDIRECT }; |
| 27 | |
| 28 | public: |
| 29 | static DebugMacroEntry CreateDefineEntry(uint32_t line, const char *str); |
| 30 | |
| 31 | static DebugMacroEntry CreateUndefEntry(uint32_t line, const char *str); |
| 32 | |
| 33 | static DebugMacroEntry CreateStartFileEntry(uint32_t line, |
| 34 | uint32_t debug_line_file_idx); |
| 35 | |
| 36 | static DebugMacroEntry CreateEndFileEntry(); |
| 37 | |
| 38 | static DebugMacroEntry |
| 39 | CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp); |
| 40 | |
| 41 | DebugMacroEntry() : m_type(INVALID) {} |
| 42 | |
| 43 | ~DebugMacroEntry() = default; |
| 44 | |
| 45 | EntryType GetType() const { return m_type; } |
| 46 | |
| 47 | uint64_t GetLineNumber() const { return m_line; } |
| 48 | |
| 49 | ConstString GetMacroString() const { return m_str; } |
| 50 | |
| 51 | const FileSpec &GetFileSpec(CompileUnit *comp_unit) const; |
| 52 | |
| 53 | DebugMacros *GetIndirectDebugMacros() const { |
| 54 | return m_debug_macros_sp.get(); |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | DebugMacroEntry(EntryType type, uint32_t line, uint32_t debug_line_file_idx, |
| 59 | const char *str); |
| 60 | |
| 61 | DebugMacroEntry(EntryType type, const DebugMacrosSP &debug_macros_sp); |
| 62 | |
| 63 | EntryType m_type : 3; |
| 64 | uint32_t m_line : 29; |
| 65 | uint32_t m_debug_line_file_idx; |
| 66 | ConstString m_str; |
| 67 | DebugMacrosSP m_debug_macros_sp; |
| 68 | }; |
| 69 | |
| 70 | class DebugMacros { |
| 71 | public: |
| 72 | DebugMacros() = default; |
| 73 | |
| 74 | ~DebugMacros() = default; |
| 75 | |
| 76 | void AddMacroEntry(const DebugMacroEntry &entry) { |
| 77 | m_macro_entries.push_back(entry); |
| 78 | } |
| 79 | |
| 80 | size_t GetNumMacroEntries() const { return m_macro_entries.size(); } |
| 81 | |
| 82 | DebugMacroEntry GetMacroEntryAtIndex(const size_t index) const { |
| 83 | if (index < m_macro_entries.size()) |
| 84 | return m_macro_entries[index]; |
| 85 | else |
| 86 | return DebugMacroEntry(); |
| 87 | } |
| 88 | |
| 89 | private: |
| 90 | DISALLOW_COPY_AND_ASSIGN(DebugMacros); |
| 91 | |
| 92 | std::vector<DebugMacroEntry> m_macro_entries; |
| 93 | }; |
| 94 | |
| 95 | } // namespace lldb_private |
| 96 | |
| 97 | #endif // liblldb_DebugMacros_h_ |