Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 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 | |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 12 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 13 | // Clang headers like to use NDEBUG inside of them to enable/disable debug |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 14 | // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 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 | |
Sean Callanan | 3b1d4f6 | 2011-10-26 17:46:51 +0000 | [diff] [blame] | 23 | #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF) |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 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 | |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 40 | #include "lldb/Utility/Log.h" |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 41 | #include "clang/AST/Decl.h" |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 42 | |
| 43 | using namespace clang; |
| 44 | using namespace lldb_private; |
| 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName( |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 47 | const clang::DeclContext *decl_ctx, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 62 | return false; |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | void ClangExternalASTSourceCallbacks::CompleteType(TagDecl *tag_decl) { |
| 66 | if (m_callback_tag_decl) |
| 67 | m_callback_tag_decl(m_callback_baton, tag_decl); |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | void ClangExternalASTSourceCallbacks::CompleteType( |
| 71 | ObjCInterfaceDecl *objc_decl) { |
| 72 | if (m_callback_objc_decl) |
| 73 | m_callback_objc_decl(m_callback_baton, objc_decl); |
Greg Clayton | 47a15b7 | 2011-01-17 04:19:51 +0000 | [diff] [blame] | 74 | } |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | bool ClangExternalASTSourceCallbacks::layoutRecordType( |
Zachary Turner | 504f38d | 2015-03-24 16:24:50 +0000 | [diff] [blame] | 77 | const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, |
Zachary Turner | a98fac2 | 2015-03-24 18:56:08 +0000 | [diff] [blame] | 78 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets, |
| 79 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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 | } |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 100 | } |