DebugMacros.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef LLDB_SYMBOL_DEBUGMACROS_H
  9. #define LLDB_SYMBOL_DEBUGMACROS_H
  10. #include <memory>
  11. #include <vector>
  12. #include "lldb/Utility/ConstString.h"
  13. #include "lldb/lldb-private.h"
  14. namespace lldb_private {
  15. class CompileUnit;
  16. class DebugMacros;
  17. typedef std::shared_ptr<DebugMacros> DebugMacrosSP;
  18. class DebugMacroEntry {
  19. public:
  20. enum EntryType : uint8_t {
  21. INVALID, DEFINE, UNDEF, START_FILE, END_FILE, INDIRECT
  22. };
  23. static DebugMacroEntry CreateDefineEntry(uint32_t line, const char *str);
  24. static DebugMacroEntry CreateUndefEntry(uint32_t line, const char *str);
  25. static DebugMacroEntry CreateStartFileEntry(uint32_t line,
  26. uint32_t debug_line_file_idx);
  27. static DebugMacroEntry CreateEndFileEntry();
  28. static DebugMacroEntry
  29. CreateIndirectEntry(const DebugMacrosSP &debug_macros_sp);
  30. DebugMacroEntry() : m_type(INVALID) {}
  31. ~DebugMacroEntry() = default;
  32. EntryType GetType() const { return static_cast<EntryType>(m_type); }
  33. uint64_t GetLineNumber() const { return m_line; }
  34. ConstString GetMacroString() const { return m_str; }
  35. const FileSpec &GetFileSpec(CompileUnit *comp_unit) const;
  36. DebugMacros *GetIndirectDebugMacros() const {
  37. return m_debug_macros_sp.get();
  38. }
  39. private:
  40. DebugMacroEntry(EntryType type, uint32_t line, uint32_t debug_line_file_idx,
  41. const char *str);
  42. DebugMacroEntry(EntryType type, const DebugMacrosSP &debug_macros_sp);
  43. uint32_t m_type : 3;
  44. uint32_t m_line : 29;
  45. uint32_t m_debug_line_file_idx;
  46. ConstString m_str;
  47. DebugMacrosSP m_debug_macros_sp;
  48. };
  49. class DebugMacros {
  50. public:
  51. DebugMacros() = default;
  52. ~DebugMacros() = default;
  53. void AddMacroEntry(const DebugMacroEntry &entry) {
  54. m_macro_entries.push_back(entry);
  55. }
  56. size_t GetNumMacroEntries() const { return m_macro_entries.size(); }
  57. DebugMacroEntry GetMacroEntryAtIndex(const size_t index) const {
  58. if (index < m_macro_entries.size())
  59. return m_macro_entries[index];
  60. else
  61. return DebugMacroEntry();
  62. }
  63. private:
  64. DebugMacros(const DebugMacros &) = delete;
  65. const DebugMacros &operator=(const DebugMacros &) = delete;
  66. std::vector<DebugMacroEntry> m_macro_entries;
  67. };
  68. } // namespace lldb_private
  69. #endif // LLDB_SYMBOL_DEBUGMACROS_H