]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
MFV r346450:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFDeclContext.h
1 //===-- DWARFDeclContext.h --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef SymbolFileDWARF_DWARFDeclContext_h_
11 #define SymbolFileDWARF_DWARFDeclContext_h_
12
13 #include <string>
14 #include <vector>
15 #include "lldb/Utility/ConstString.h"
16 #include "DWARFDefines.h"
17
18 //----------------------------------------------------------------------
19 // DWARFDeclContext
20 //
21 // A class that represents a declaration context all the way down to a
22 // DIE. This is useful when trying to find a DIE in one DWARF to a DIE
23 // in another DWARF file.
24 //----------------------------------------------------------------------
25
26 class DWARFDeclContext {
27 public:
28   struct Entry {
29     Entry() : tag(0), name(NULL) {}
30     Entry(dw_tag_t t, const char *n) : tag(t), name(n) {}
31
32     bool NameMatches(const Entry &rhs) const {
33       if (name == rhs.name)
34         return true;
35       else if (name && rhs.name)
36         return strcmp(name, rhs.name) == 0;
37       return false;
38     }
39
40     // Test operator
41     explicit operator bool() const { return tag != 0; }
42
43     dw_tag_t tag;
44     const char *name;
45   };
46
47   DWARFDeclContext() : m_entries(), m_language(lldb::eLanguageTypeUnknown) {}
48
49   void AppendDeclContext(dw_tag_t tag, const char *name) {
50     m_entries.push_back(Entry(tag, name));
51   }
52
53   bool operator==(const DWARFDeclContext &rhs) const;
54
55   uint32_t GetSize() const { return m_entries.size(); }
56
57   Entry &operator[](uint32_t idx) {
58     // "idx" must be valid
59     return m_entries[idx];
60   }
61
62   const Entry &operator[](uint32_t idx) const {
63     // "idx" must be valid
64     return m_entries[idx];
65   }
66
67   const char *GetQualifiedName() const;
68
69   // Same as GetQaulifiedName, but the life time of the returned string will
70   // be that of the LLDB session.
71   lldb_private::ConstString GetQualifiedNameAsConstString() const {
72     return lldb_private::ConstString(GetQualifiedName());
73   }
74
75   void Clear() {
76     m_entries.clear();
77     m_qualified_name.clear();
78   }
79
80   lldb::LanguageType GetLanguage() const { return m_language; }
81
82   void SetLanguage(lldb::LanguageType language) { m_language = language; }
83
84 protected:
85   typedef std::vector<Entry> collection;
86   collection m_entries;
87   mutable std::string m_qualified_name;
88   lldb::LanguageType m_language;
89 };
90
91 #endif // SymbolFileDWARF_DWARFDeclContext_h_