1//===-- DWARFDeclContext.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 LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H
11
12#include "lldb/Utility/ConstString.h"
13#include "DWARFDefines.h"
14
15#include <cassert>
16#include <string>
17#include <vector>
18
19namespace lldb_private::plugin {
20namespace dwarf {
21// DWARFDeclContext
22//
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.
26
27class DWARFDeclContext {
28public:
29 struct Entry {
30 Entry() = default;
31 Entry(dw_tag_t t, const char *n) : tag(t), name(n) {}
32
33 bool NameMatches(const Entry &rhs) const {
34 if (name == rhs.name)
35 return true;
36 else if (name && rhs.name)
37 return strcmp(s1: name, s2: rhs.name) == 0;
38 return false;
39 }
40
41 // Test operator
42 explicit operator bool() const { return tag != 0; }
43
44 dw_tag_t tag = llvm::dwarf::DW_TAG_null;
45 const char *name = nullptr;
46 };
47
48 DWARFDeclContext() : m_entries() {}
49
50 DWARFDeclContext(llvm::ArrayRef<Entry> entries) {
51 llvm::append_range(C&: m_entries, R&: entries);
52 }
53
54 void AppendDeclContext(dw_tag_t tag, const char *name) {
55 m_entries.push_back(x: Entry(tag, name));
56 }
57
58 bool operator==(const DWARFDeclContext &rhs) const;
59 bool operator!=(const DWARFDeclContext &rhs) const { return !(*this == rhs); }
60
61 uint32_t GetSize() const { return m_entries.size(); }
62
63 Entry &operator[](uint32_t idx) {
64 assert(idx < m_entries.size() && "invalid index");
65 return m_entries[idx];
66 }
67
68 const Entry &operator[](uint32_t idx) const {
69 assert(idx < m_entries.size() && "invalid index");
70 return m_entries[idx];
71 }
72
73 const char *GetQualifiedName() const;
74
75 // Same as GetQualifiedName, but the life time of the returned string will
76 // be that of the LLDB session.
77 ConstString GetQualifiedNameAsConstString() const {
78 return ConstString(GetQualifiedName());
79 }
80
81 void Clear() {
82 m_entries.clear();
83 m_qualified_name.clear();
84 }
85
86protected:
87 typedef std::vector<Entry> collection;
88 collection m_entries;
89 mutable std::string m_qualified_name;
90};
91} // namespace dwarf
92} // namespace lldb_private::plugin
93
94#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H
95

source code of lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h