1 //===-- DWARFDeclContext.h --------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef SymbolFileDWARF_DWARFDeclContext_h_
10 #define SymbolFileDWARF_DWARFDeclContext_h_
14 #include "lldb/Utility/ConstString.h"
15 #include "DWARFDefines.h"
19 // A class that represents a declaration context all the way down to a
20 // DIE. This is useful when trying to find a DIE in one DWARF to a DIE
21 // in another DWARF file.
23 class DWARFDeclContext {
26 Entry() : tag(0), name(nullptr) {}
27 Entry(dw_tag_t t, const char *n) : tag(t), name(n) {}
29 bool NameMatches(const Entry &rhs) const {
32 else if (name && rhs.name)
33 return strcmp(name, rhs.name) == 0;
38 explicit operator bool() const { return tag != 0; }
44 DWARFDeclContext() : m_entries(), m_language(lldb::eLanguageTypeUnknown) {}
46 void AppendDeclContext(dw_tag_t tag, const char *name) {
47 m_entries.push_back(Entry(tag, name));
50 bool operator==(const DWARFDeclContext &rhs) const;
52 uint32_t GetSize() const { return m_entries.size(); }
54 Entry &operator[](uint32_t idx) {
55 // "idx" must be valid
56 return m_entries[idx];
59 const Entry &operator[](uint32_t idx) const {
60 // "idx" must be valid
61 return m_entries[idx];
64 const char *GetQualifiedName() const;
66 // Same as GetQaulifiedName, but the life time of the returned string will
67 // be that of the LLDB session.
68 lldb_private::ConstString GetQualifiedNameAsConstString() const {
69 return lldb_private::ConstString(GetQualifiedName());
74 m_qualified_name.clear();
77 lldb::LanguageType GetLanguage() const { return m_language; }
79 void SetLanguage(lldb::LanguageType language) { m_language = language; }
82 typedef std::vector<Entry> collection;
84 mutable std::string m_qualified_name;
85 lldb::LanguageType m_language;
88 #endif // SymbolFileDWARF_DWARFDeclContext_h_