1 //===-- ClangExternalASTSourceCommon.h --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ClangExternalASTSourceCommon_h
11 #define liblldb_ClangExternalASTSourceCommon_h
13 // Clang headers like to use NDEBUG inside of them to enable/disable debug
14 // releated 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
23 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
24 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
26 // Need to include assert.h so it is as clang would expect it to be (disabled)
30 #include "clang/AST/ExternalASTSource.h"
32 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
34 #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
35 // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
39 #include "lldb/lldb-defines.h"
40 #include "lldb/lldb-enumerations.h"
41 #include "lldb/Core/dwarf.h"
43 namespace lldb_private {
45 class ClangASTMetadata
50 m_union_is_user_id(false),
51 m_union_is_isa_ptr(false),
52 m_has_object_ptr(false),
54 m_is_dynamic_cxx (true)
59 GetIsDynamicCXXType () const
61 return m_is_dynamic_cxx;
65 SetIsDynamicCXXType (bool b)
71 SetUserID (lldb::user_id_t user_id)
74 m_union_is_user_id = true;
75 m_union_is_isa_ptr = false;
81 if (m_union_is_user_id)
84 return LLDB_INVALID_UID;
88 SetISAPtr (uint64_t isa_ptr)
91 m_union_is_user_id = false;
92 m_union_is_isa_ptr = true;
98 if (m_union_is_isa_ptr)
105 SetObjectPtrName(const char *name)
107 m_has_object_ptr = true;
108 if (strcmp (name, "self") == 0)
110 else if (strcmp (name, "this") == 0)
113 m_has_object_ptr = false;
117 GetObjectPtrLanguage () const
119 if (m_has_object_ptr)
122 return lldb::eLanguageTypeObjC;
124 return lldb::eLanguageTypeC_plus_plus;
126 return lldb::eLanguageTypeUnknown;
130 GetObjectPtrName() const
132 if (m_has_object_ptr)
146 return m_has_object_ptr;
155 lldb::user_id_t m_user_id;
158 bool m_union_is_user_id : 1,
159 m_union_is_isa_ptr : 1,
160 m_has_object_ptr : 1,
162 m_is_dynamic_cxx : 1;
166 class ClangExternalASTSourceCommon : public clang::ExternalASTSource
169 ClangExternalASTSourceCommon();
170 ~ClangExternalASTSourceCommon();
172 virtual ClangASTMetadata *GetMetadata(const void *object);
173 virtual void SetMetadata(const void *object, ClangASTMetadata &metadata);
174 virtual bool HasMetadata(const void *object);
176 typedef llvm::DenseMap<const void *, ClangASTMetadata> MetadataMap;
178 MetadataMap m_metadata;
179 uint64_t m_magic; ///< Because we don't have RTTI, we must take it
180 ///< on faith that any valid ExternalASTSource that
181 ///< we try to use the *Metadata APIs on inherits
182 ///< from ClangExternalASTSourceCommon. This magic
183 ///< number exists to enforce that.