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 // 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
24 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
25 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
27 // Need to include assert.h so it is as clang would expect it to be (disabled)
31 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
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)
39 // Other libraries and framework includes
40 #include "clang/AST/ExternalASTSource.h"
43 #include "lldb/Core/dwarf.h"
44 #include "lldb/lldb-defines.h"
45 #include "lldb/lldb-enumerations.h"
47 namespace lldb_private {
49 class 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) {}
55 bool GetIsDynamicCXXType() const { return m_is_dynamic_cxx; }
57 void SetIsDynamicCXXType(bool b) { m_is_dynamic_cxx = b; }
59 void SetUserID(lldb::user_id_t user_id) {
61 m_union_is_user_id = true;
62 m_union_is_isa_ptr = false;
65 lldb::user_id_t GetUserID() const {
66 if (m_union_is_user_id)
69 return LLDB_INVALID_UID;
72 void SetISAPtr(uint64_t isa_ptr) {
74 m_union_is_user_id = false;
75 m_union_is_isa_ptr = true;
78 uint64_t GetISAPtr() const {
79 if (m_union_is_isa_ptr)
85 void SetObjectPtrName(const char *name) {
86 m_has_object_ptr = true;
87 if (strcmp(name, "self") == 0)
89 else if (strcmp(name, "this") == 0)
92 m_has_object_ptr = false;
95 lldb::LanguageType GetObjectPtrLanguage() const {
96 if (m_has_object_ptr) {
98 return lldb::eLanguageTypeObjC;
100 return lldb::eLanguageTypeC_plus_plus;
102 return lldb::eLanguageTypeUnknown;
105 const char *GetObjectPtrName() const {
106 if (m_has_object_ptr) {
115 bool HasObjectPtr() const { return m_has_object_ptr; }
117 void Dump(Stream *s);
121 lldb::user_id_t m_user_id;
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;
129 class ClangExternalASTSourceCommon : public clang::ExternalASTSource {
131 ClangExternalASTSourceCommon();
132 ~ClangExternalASTSourceCommon() override;
134 ClangASTMetadata *GetMetadata(const void *object);
135 void SetMetadata(const void *object, ClangASTMetadata &metadata);
136 bool HasMetadata(const void *object);
138 static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source);
141 typedef llvm::DenseMap<const void *, ClangASTMetadata> MetadataMap;
143 MetadataMap m_metadata;
146 } // namespace lldb_private
148 #endif // liblldb_ClangExternalASTSourceCommon_h