]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Symbol/ClangExternalASTSourceCommon.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Symbol / ClangExternalASTSourceCommon.h
1 //===-- ClangExternalASTSourceCommon.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 liblldb_ClangExternalASTSourceCommon_h
11 #define liblldb_ClangExternalASTSourceCommon_h
12
13 // Clang headers like to use NDEBUG inside of them to enable/disable debug
14 // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
15 // or another. This is bad because it means that if clang was built in release
16 // mode, it assumes that you are building in release mode which is not always
17 // the case. You can end up with functions that are defined as empty in header
18 // files when NDEBUG is not defined, and this can cause link errors with the
19 // clang .a files that you have since you might be missing functions in the .a
20 // file. So we have to define NDEBUG when including clang headers to avoid any
21 // mismatches. This is covered by rdar://problem/8691220
22
23 // C Includes
24 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
25 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
26 #define NDEBUG
27 // Need to include assert.h so it is as clang would expect it to be (disabled)
28 #include <assert.h>
29 #endif
30
31 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
32 #undef NDEBUG
33 #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
34 // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
35 #include <assert.h>
36 #endif
37
38 // C++ Includes
39 // Other libraries and framework includes
40 #include "clang/AST/ExternalASTSource.h"
41
42 // Project includes
43 #include "lldb/Core/dwarf.h"
44 #include "lldb/lldb-defines.h"
45 #include "lldb/lldb-enumerations.h"
46
47 namespace lldb_private {
48
49 class ClangASTMetadata {
50 public:
51   ClangASTMetadata()
52       : m_user_id(0), m_union_is_user_id(false), m_union_is_isa_ptr(false),
53         m_has_object_ptr(false), m_is_self(false), m_is_dynamic_cxx(true) {}
54
55   bool GetIsDynamicCXXType() const { return m_is_dynamic_cxx; }
56
57   void SetIsDynamicCXXType(bool b) { m_is_dynamic_cxx = b; }
58
59   void SetUserID(lldb::user_id_t user_id) {
60     m_user_id = user_id;
61     m_union_is_user_id = true;
62     m_union_is_isa_ptr = false;
63   }
64
65   lldb::user_id_t GetUserID() const {
66     if (m_union_is_user_id)
67       return m_user_id;
68     else
69       return LLDB_INVALID_UID;
70   }
71
72   void SetISAPtr(uint64_t isa_ptr) {
73     m_isa_ptr = isa_ptr;
74     m_union_is_user_id = false;
75     m_union_is_isa_ptr = true;
76   }
77
78   uint64_t GetISAPtr() const {
79     if (m_union_is_isa_ptr)
80       return m_isa_ptr;
81     else
82       return 0;
83   }
84
85   void SetObjectPtrName(const char *name) {
86     m_has_object_ptr = true;
87     if (strcmp(name, "self") == 0)
88       m_is_self = true;
89     else if (strcmp(name, "this") == 0)
90       m_is_self = false;
91     else
92       m_has_object_ptr = false;
93   }
94
95   lldb::LanguageType GetObjectPtrLanguage() const {
96     if (m_has_object_ptr) {
97       if (m_is_self)
98         return lldb::eLanguageTypeObjC;
99       else
100         return lldb::eLanguageTypeC_plus_plus;
101     }
102     return lldb::eLanguageTypeUnknown;
103   }
104
105   const char *GetObjectPtrName() const {
106     if (m_has_object_ptr) {
107       if (m_is_self)
108         return "self";
109       else
110         return "this";
111     } else
112       return nullptr;
113   }
114
115   bool HasObjectPtr() const { return m_has_object_ptr; }
116
117   void Dump(Stream *s);
118
119 private:
120   union {
121     lldb::user_id_t m_user_id;
122     uint64_t m_isa_ptr;
123   };
124
125   bool m_union_is_user_id : 1, m_union_is_isa_ptr : 1, m_has_object_ptr : 1,
126       m_is_self : 1, m_is_dynamic_cxx : 1;
127 };
128
129 class ClangExternalASTSourceCommon : public clang::ExternalASTSource {
130 public:
131   ClangExternalASTSourceCommon();
132   ~ClangExternalASTSourceCommon() override;
133
134   ClangASTMetadata *GetMetadata(const void *object);
135   void SetMetadata(const void *object, ClangASTMetadata &metadata);
136   bool HasMetadata(const void *object);
137
138   static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source);
139
140 private:
141   typedef llvm::DenseMap<const void *, ClangASTMetadata> MetadataMap;
142
143   MetadataMap m_metadata;
144 };
145
146 } // namespace lldb_private
147
148 #endif // liblldb_ClangExternalASTSourceCommon_h