LLDB  mainline
DWARFDeclContext.h
Go to the documentation of this file.
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 SymbolFileDWARF_DWARFDeclContext_h_
10 #define SymbolFileDWARF_DWARFDeclContext_h_
11 
12 #include <string>
13 #include <vector>
15 #include "DWARFDefines.h"
16 
17 // DWARFDeclContext
18 //
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.
22 
24 public:
25  struct Entry {
26  Entry() : tag(0), name(NULL) {}
27  Entry(dw_tag_t t, const char *n) : tag(t), name(n) {}
28 
29  bool NameMatches(const Entry &rhs) const {
30  if (name == rhs.name)
31  return true;
32  else if (name && rhs.name)
33  return strcmp(name, rhs.name) == 0;
34  return false;
35  }
36 
37  // Test operator
38  explicit operator bool() const { return tag != 0; }
39 
41  const char *name;
42  };
43 
45 
46  void AppendDeclContext(dw_tag_t tag, const char *name) {
47  m_entries.push_back(Entry(tag, name));
48  }
49 
50  bool operator==(const DWARFDeclContext &rhs) const;
51 
52  uint32_t GetSize() const { return m_entries.size(); }
53 
55  // "idx" must be valid
56  return m_entries[idx];
57  }
58 
59  const Entry &operator[](uint32_t idx) const {
60  // "idx" must be valid
61  return m_entries[idx];
62  }
63 
64  const char *GetQualifiedName() const;
65 
66  // Same as GetQaulifiedName, but the life time of the returned string will
67  // be that of the LLDB session.
70  }
71 
72  void Clear() {
73  m_entries.clear();
74  m_qualified_name.clear();
75  }
76 
78 
79  void SetLanguage(lldb::LanguageType language) { m_language = language; }
80 
81 protected:
82  typedef std::vector<Entry> collection;
83  collection m_entries;
84  mutable std::string m_qualified_name;
86 };
87 
88 #endif // SymbolFileDWARF_DWARFDeclContext_h_
const char * GetQualifiedName() const
lldb::LanguageType GetLanguage() const
const Entry & operator[](uint32_t idx) const
collection m_entries
Entry(dw_tag_t t, const char *n)
LanguageType
Programming language type.
bool operator==(const DWARFDeclContext &rhs) const
void SetLanguage(lldb::LanguageType language)
lldb::LanguageType m_language
Entry & operator[](uint32_t idx)
A uniqued constant string class.
Definition: ConstString.h:38
Unknown or invalid language value.
std::vector< Entry > collection
Definition: SBAddress.h:15
uint32_t GetSize() const
void AppendDeclContext(dw_tag_t tag, const char *name)
bool NameMatches(const Entry &rhs) const
lldb_private::ConstString GetQualifiedNameAsConstString() const
std::string m_qualified_name