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 LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H
12 #include "lldb/Utility/ConstString.h"
13 #include "DWARFDefines.h"
19 namespace lldb_private::plugin
{
23 // A class that represents a declaration context all the way down to a
24 // DIE. This is useful when trying to find a DIE in one DWARF to a DIE
25 // in another DWARF file.
27 class DWARFDeclContext
{
31 Entry(dw_tag_t t
, const char *n
) : tag(t
), name(n
) {}
33 bool NameMatches(const Entry
&rhs
) const {
36 else if (name
&& rhs
.name
)
37 return strcmp(name
, rhs
.name
) == 0;
42 explicit operator bool() const { return tag
!= 0; }
44 dw_tag_t tag
= llvm::dwarf::DW_TAG_null
;
45 const char *name
= nullptr;
48 DWARFDeclContext() : m_entries() {}
50 void AppendDeclContext(dw_tag_t tag
, const char *name
) {
51 m_entries
.push_back(Entry(tag
, name
));
54 bool operator==(const DWARFDeclContext
&rhs
) const;
55 bool operator!=(const DWARFDeclContext
&rhs
) const { return !(*this == rhs
); }
57 uint32_t GetSize() const { return m_entries
.size(); }
59 Entry
&operator[](uint32_t idx
) {
60 assert(idx
< m_entries
.size() && "invalid index");
61 return m_entries
[idx
];
64 const Entry
&operator[](uint32_t idx
) const {
65 assert(idx
< m_entries
.size() && "invalid index");
66 return m_entries
[idx
];
69 const char *GetQualifiedName() const;
71 // Same as GetQualifiedName, but the life time of the returned string will
72 // be that of the LLDB session.
73 ConstString
GetQualifiedNameAsConstString() const {
74 return ConstString(GetQualifiedName());
79 m_qualified_name
.clear();
83 typedef std::vector
<Entry
> collection
;
85 mutable std::string m_qualified_name
;
88 } // namespace lldb_private::plugin
90 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H