1 //===-- ClangExternalASTSourceCommon.h --------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_ClangExternalASTSourceCommon_h
10 #define liblldb_ClangExternalASTSourceCommon_h
12 // Clang headers like to use NDEBUG inside of them to enable/disable debug
13 // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
14 // or another. This is bad because it means that if clang was built in release
15 // mode, it assumes that you are building in release mode which is not always
16 // the case. You can end up with functions that are defined as empty in header
17 // files when NDEBUG is not defined, and this can cause link errors with the
18 // clang .a files that you have since you might be missing functions in the .a
19 // file. So we have to define NDEBUG when including clang headers to avoid any
20 // mismatches. This is covered by rdar://problem/8691220
22 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
23 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
25 // Need to include assert.h so it is as clang would expect it to be (disabled)
29 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
31 #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
32 // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
36 #include "clang/AST/ExternalASTSource.h"
38 #include "lldb/Core/dwarf.h"
39 #include "lldb/lldb-defines.h"
40 #include "lldb/lldb-enumerations.h"
42 namespace lldb_private {
44 class ClangASTMetadata {
47 : m_user_id(0), m_union_is_user_id(false), m_union_is_isa_ptr(false),
48 m_has_object_ptr(false), m_is_self(false), m_is_dynamic_cxx(true) {}
50 bool GetIsDynamicCXXType() const { return m_is_dynamic_cxx; }
52 void SetIsDynamicCXXType(bool b) { m_is_dynamic_cxx = b; }
54 void SetUserID(lldb::user_id_t user_id) {
56 m_union_is_user_id = true;
57 m_union_is_isa_ptr = false;
60 lldb::user_id_t GetUserID() const {
61 if (m_union_is_user_id)
64 return LLDB_INVALID_UID;
67 void SetISAPtr(uint64_t isa_ptr) {
69 m_union_is_user_id = false;
70 m_union_is_isa_ptr = true;
73 uint64_t GetISAPtr() const {
74 if (m_union_is_isa_ptr)
80 void SetObjectPtrName(const char *name) {
81 m_has_object_ptr = true;
82 if (strcmp(name, "self") == 0)
84 else if (strcmp(name, "this") == 0)
87 m_has_object_ptr = false;
90 lldb::LanguageType GetObjectPtrLanguage() const {
91 if (m_has_object_ptr) {
93 return lldb::eLanguageTypeObjC;
95 return lldb::eLanguageTypeC_plus_plus;
97 return lldb::eLanguageTypeUnknown;
100 const char *GetObjectPtrName() const {
101 if (m_has_object_ptr) {
110 bool HasObjectPtr() const { return m_has_object_ptr; }
112 void Dump(Stream *s);
116 lldb::user_id_t m_user_id;
120 bool m_union_is_user_id : 1, m_union_is_isa_ptr : 1, m_has_object_ptr : 1,
121 m_is_self : 1, m_is_dynamic_cxx : 1;
124 class ClangExternalASTSourceCommon : public clang::ExternalASTSource {
126 ClangExternalASTSourceCommon();
127 ~ClangExternalASTSourceCommon() override;
129 ClangASTMetadata *GetMetadata(const void *object);
130 void SetMetadata(const void *object, ClangASTMetadata &metadata);
131 bool HasMetadata(const void *object);
133 static ClangExternalASTSourceCommon *Lookup(clang::ExternalASTSource *source);
136 typedef llvm::DenseMap<const void *, ClangASTMetadata> MetadataMap;
138 MetadataMap m_metadata;
141 } // namespace lldb_private
143 #endif // liblldb_ClangExternalASTSourceCommon_h