]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / 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 // C Includes
14 // C++ Includes
15 #include <string>
16 #include <vector>
17 // Other libraries and framework includes
18 #include "lldb/Core/ConstString.h"
19 // Project includes
20 #include "DWARFDefines.h"
21
22 //----------------------------------------------------------------------
23 // DWARFDeclContext
24 //
25 // A class that represents a declaration context all the way down to a
26 // DIE. This is useful when trying to find a DIE in one DWARF to a DIE
27 // in another DWARF file.
28 //----------------------------------------------------------------------
29
30 class DWARFDeclContext {
31 public:
32   struct Entry {
33     Entry() : tag(0), name(NULL) {}
34     Entry(dw_tag_t t, const char *n) : tag(t), name(n) {}
35
36     bool NameMatches(const Entry &rhs) const {
37       if (name == rhs.name)
38         return true;
39       else if (name && rhs.name)
40         return strcmp(name, rhs.name) == 0;
41       return false;
42     }
43
44     // Test operator
45     explicit operator bool() const { return tag != 0; }
46
47     dw_tag_t tag;
48     const char *name;
49   };
50
51   DWARFDeclContext() : m_entries(), m_language(lldb::eLanguageTypeUnknown) {}
52
53   void AppendDeclContext(dw_tag_t tag, const char *name) {
54     m_entries.push_back(Entry(tag, name));
55   }
56
57   bool operator==(const DWARFDeclContext &rhs) const;
58
59   uint32_t GetSize() const { return m_entries.size(); }
60
61   Entry &operator[](uint32_t idx) {
62     // "idx" must be valid
63     return m_entries[idx];
64   }
65
66   const Entry &operator[](uint32_t idx) const {
67     // "idx" must be valid
68     return m_entries[idx];
69   }
70
71   const char *GetQualifiedName() const;
72
73   // Same as GetQaulifiedName, but the life time of the returned string will
74   // be that of the LLDB session.
75   lldb_private::ConstString GetQualifiedNameAsConstString() const {
76     return lldb_private::ConstString(GetQualifiedName());
77   }
78
79   void Clear() {
80     m_entries.clear();
81     m_qualified_name.clear();
82   }
83
84   lldb::LanguageType GetLanguage() const { return m_language; }
85
86   void SetLanguage(lldb::LanguageType language) { m_language = language; }
87
88 protected:
89   typedef std::vector<Entry> collection;
90   collection m_entries;
91   mutable std::string m_qualified_name;
92   lldb::LanguageType m_language;
93 };
94
95 #endif // SymbolFileDWARF_DWARFDeclContext_h_