1 //===-- ClangExternalASTSourceCallbacks.cpp ---------------------*- 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 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
14 // Other libraries and framework includes
16 // Clang headers like to use NDEBUG inside of them to enable/disable debug
17 // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
18 // or another. This is bad because it means that if clang was built in release
19 // mode, it assumes that you are building in release mode which is not always
20 // the case. You can end up with functions that are defined as empty in header
21 // files when NDEBUG is not defined, and this can cause link errors with the
22 // clang .a files that you have since you might be missing functions in the .a
23 // file. So we have to define NDEBUG when including clang headers to avoid any
24 // mismatches. This is covered by rdar://problem/8691220
26 #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
27 #define LLDB_DEFINED_NDEBUG_FOR_CLANG
29 // Need to include assert.h so it is as clang would expect it to be (disabled)
33 #include "clang/AST/DeclBase.h"
34 #include "clang/AST/DeclarationName.h"
36 #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
38 #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
39 // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
43 #include "lldb/Utility/Log.h"
44 #include "clang/AST/Decl.h"
46 using namespace clang;
47 using namespace lldb_private;
49 bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
50 const clang::DeclContext *decl_ctx,
51 clang::DeclarationName clang_decl_name) {
52 if (m_callback_find_by_name) {
53 llvm::SmallVector<clang::NamedDecl *, 3> results;
55 m_callback_find_by_name(m_callback_baton, decl_ctx, clang_decl_name,
58 SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, results);
60 return (results.size() != 0);
63 std::string decl_name(clang_decl_name.getAsString());
64 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
68 void ClangExternalASTSourceCallbacks::CompleteType(TagDecl *tag_decl) {
69 if (m_callback_tag_decl)
70 m_callback_tag_decl(m_callback_baton, tag_decl);
73 void ClangExternalASTSourceCallbacks::CompleteType(
74 ObjCInterfaceDecl *objc_decl) {
75 if (m_callback_objc_decl)
76 m_callback_objc_decl(m_callback_baton, objc_decl);
79 bool ClangExternalASTSourceCallbacks::layoutRecordType(
80 const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
81 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
82 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
83 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
84 &VirtualBaseOffsets) {
85 if (m_callback_layout_record_type)
86 return m_callback_layout_record_type(m_callback_baton, Record, Size,
87 Alignment, FieldOffsets, BaseOffsets,
93 void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(
94 const clang::DeclContext *decl_ctx,
95 llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
96 llvm::SmallVectorImpl<clang::Decl *> &decls) {
97 if (m_callback_tag_decl && decl_ctx) {
98 clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(
99 const_cast<clang::DeclContext *>(decl_ctx));
101 CompleteType(tag_decl);