1061da546Spatrick //===-- DWARFDeclContext.h --------------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9dda28197Spatrick #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H 10dda28197Spatrick #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H 11061da546Spatrick 12061da546Spatrick #include <string> 13061da546Spatrick #include <vector> 14061da546Spatrick #include "lldb/Utility/ConstString.h" 15061da546Spatrick #include "DWARFDefines.h" 16061da546Spatrick 17061da546Spatrick // DWARFDeclContext 18061da546Spatrick // 19061da546Spatrick // A class that represents a declaration context all the way down to a 20061da546Spatrick // DIE. This is useful when trying to find a DIE in one DWARF to a DIE 21061da546Spatrick // in another DWARF file. 22061da546Spatrick 23061da546Spatrick class DWARFDeclContext { 24061da546Spatrick public: 25061da546Spatrick struct Entry { 26*be691f3bSpatrick Entry() = default; EntryEntry27061da546Spatrick Entry(dw_tag_t t, const char *n) : tag(t), name(n) {} 28061da546Spatrick NameMatchesEntry29061da546Spatrick bool NameMatches(const Entry &rhs) const { 30061da546Spatrick if (name == rhs.name) 31061da546Spatrick return true; 32061da546Spatrick else if (name && rhs.name) 33061da546Spatrick return strcmp(name, rhs.name) == 0; 34061da546Spatrick return false; 35061da546Spatrick } 36061da546Spatrick 37061da546Spatrick // Test operator 38061da546Spatrick explicit operator bool() const { return tag != 0; } 39061da546Spatrick 40*be691f3bSpatrick dw_tag_t tag = llvm::dwarf::DW_TAG_null; 41*be691f3bSpatrick const char *name = nullptr; 42061da546Spatrick }; 43061da546Spatrick DWARFDeclContext()44*be691f3bSpatrick DWARFDeclContext() : m_entries() {} 45061da546Spatrick AppendDeclContext(dw_tag_t tag,const char * name)46061da546Spatrick void AppendDeclContext(dw_tag_t tag, const char *name) { 47061da546Spatrick m_entries.push_back(Entry(tag, name)); 48061da546Spatrick } 49061da546Spatrick 50061da546Spatrick bool operator==(const DWARFDeclContext &rhs) const; 51dda28197Spatrick bool operator!=(const DWARFDeclContext &rhs) const { return !(*this == rhs); } 52061da546Spatrick GetSize()53061da546Spatrick uint32_t GetSize() const { return m_entries.size(); } 54061da546Spatrick 55061da546Spatrick Entry &operator[](uint32_t idx) { 56061da546Spatrick // "idx" must be valid 57061da546Spatrick return m_entries[idx]; 58061da546Spatrick } 59061da546Spatrick 60061da546Spatrick const Entry &operator[](uint32_t idx) const { 61061da546Spatrick // "idx" must be valid 62061da546Spatrick return m_entries[idx]; 63061da546Spatrick } 64061da546Spatrick 65061da546Spatrick const char *GetQualifiedName() const; 66061da546Spatrick 67061da546Spatrick // Same as GetQualifiedName, but the life time of the returned string will 68061da546Spatrick // be that of the LLDB session. GetQualifiedNameAsConstString()69061da546Spatrick lldb_private::ConstString GetQualifiedNameAsConstString() const { 70061da546Spatrick return lldb_private::ConstString(GetQualifiedName()); 71061da546Spatrick } 72061da546Spatrick Clear()73061da546Spatrick void Clear() { 74061da546Spatrick m_entries.clear(); 75061da546Spatrick m_qualified_name.clear(); 76061da546Spatrick } 77061da546Spatrick 78061da546Spatrick protected: 79061da546Spatrick typedef std::vector<Entry> collection; 80061da546Spatrick collection m_entries; 81061da546Spatrick mutable std::string m_qualified_name; 82061da546Spatrick }; 83061da546Spatrick 84dda28197Spatrick #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H 85