1 //===-- ClangExternalASTSourceCallbacks.cpp ---------------------*- 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 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
11
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 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
24 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
25 #define NDEBUG
26 // Need to include assert.h so it is as clang would expect it to be (disabled)
27 #include <assert.h>
28 #endif
29
30 #include "clang/AST/DeclBase.h"
31 #include "clang/AST/DeclarationName.h"
32
33 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
34 #undef NDEBUG
35 #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
36 // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
37 #include <assert.h>
38 #endif
39
40 #include "lldb/Utility/Log.h"
41 #include "clang/AST/Decl.h"
42
43 using namespace clang;
44 using namespace lldb_private;
45
FindExternalVisibleDeclsByName(const clang::DeclContext * decl_ctx,clang::DeclarationName clang_decl_name)46 bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
47 const clang::DeclContext *decl_ctx,
48 clang::DeclarationName clang_decl_name) {
49 if (m_callback_find_by_name) {
50 llvm::SmallVector<clang::NamedDecl *, 3> results;
51
52 m_callback_find_by_name(m_callback_baton, decl_ctx, clang_decl_name,
53 &results);
54
55 SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, results);
56
57 return (results.size() != 0);
58 }
59
60 std::string decl_name(clang_decl_name.getAsString());
61 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
62 return false;
63 }
64
CompleteType(TagDecl * tag_decl)65 void ClangExternalASTSourceCallbacks::CompleteType(TagDecl *tag_decl) {
66 if (m_callback_tag_decl)
67 m_callback_tag_decl(m_callback_baton, tag_decl);
68 }
69
CompleteType(ObjCInterfaceDecl * objc_decl)70 void ClangExternalASTSourceCallbacks::CompleteType(
71 ObjCInterfaceDecl *objc_decl) {
72 if (m_callback_objc_decl)
73 m_callback_objc_decl(m_callback_baton, objc_decl);
74 }
75
layoutRecordType(const clang::RecordDecl * Record,uint64_t & Size,uint64_t & Alignment,llvm::DenseMap<const clang::FieldDecl *,uint64_t> & FieldOffsets,llvm::DenseMap<const clang::CXXRecordDecl *,clang::CharUnits> & BaseOffsets,llvm::DenseMap<const clang::CXXRecordDecl *,clang::CharUnits> & VirtualBaseOffsets)76 bool ClangExternalASTSourceCallbacks::layoutRecordType(
77 const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
78 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
79 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
80 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
81 &VirtualBaseOffsets) {
82 if (m_callback_layout_record_type)
83 return m_callback_layout_record_type(m_callback_baton, Record, Size,
84 Alignment, FieldOffsets, BaseOffsets,
85 VirtualBaseOffsets);
86
87 return false;
88 }
89
FindExternalLexicalDecls(const clang::DeclContext * decl_ctx,llvm::function_ref<bool (clang::Decl::Kind)> IsKindWeWant,llvm::SmallVectorImpl<clang::Decl * > & decls)90 void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(
91 const clang::DeclContext *decl_ctx,
92 llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
93 llvm::SmallVectorImpl<clang::Decl *> &decls) {
94 if (m_callback_tag_decl && decl_ctx) {
95 clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(
96 const_cast<clang::DeclContext *>(decl_ctx));
97 if (tag_decl)
98 CompleteType(tag_decl);
99 }
100 }
101