1ac7ddfbfSEd Maste //===-- ClangExternalASTSourceCallbacks.cpp ---------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
11ac7ddfbfSEd Maste
12ac7ddfbfSEd Maste
13ac7ddfbfSEd Maste // Clang headers like to use NDEBUG inside of them to enable/disable debug
140127ef0fSEd Maste // related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
15ac7ddfbfSEd Maste // or another. This is bad because it means that if clang was built in release
16ac7ddfbfSEd Maste // mode, it assumes that you are building in release mode which is not always
17ac7ddfbfSEd Maste // the case. You can end up with functions that are defined as empty in header
18ac7ddfbfSEd Maste // files when NDEBUG is not defined, and this can cause link errors with the
19ac7ddfbfSEd Maste // clang .a files that you have since you might be missing functions in the .a
20ac7ddfbfSEd Maste // file. So we have to define NDEBUG when including clang headers to avoid any
21ac7ddfbfSEd Maste // mismatches. This is covered by rdar://problem/8691220
22ac7ddfbfSEd Maste
23ac7ddfbfSEd Maste #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
24ac7ddfbfSEd Maste #define LLDB_DEFINED_NDEBUG_FOR_CLANG
25ac7ddfbfSEd Maste #define NDEBUG
26ac7ddfbfSEd Maste // Need to include assert.h so it is as clang would expect it to be (disabled)
27ac7ddfbfSEd Maste #include <assert.h>
28ac7ddfbfSEd Maste #endif
29ac7ddfbfSEd Maste
30ac7ddfbfSEd Maste #include "clang/AST/DeclBase.h"
31ac7ddfbfSEd Maste #include "clang/AST/DeclarationName.h"
32ac7ddfbfSEd Maste
33ac7ddfbfSEd Maste #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
34ac7ddfbfSEd Maste #undef NDEBUG
35ac7ddfbfSEd Maste #undef LLDB_DEFINED_NDEBUG_FOR_CLANG
36ac7ddfbfSEd Maste // Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
37ac7ddfbfSEd Maste #include <assert.h>
38ac7ddfbfSEd Maste #endif
39ac7ddfbfSEd Maste
40f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
419f2f44ceSEd Maste #include "clang/AST/Decl.h"
42ac7ddfbfSEd Maste
43ac7ddfbfSEd Maste using namespace clang;
44ac7ddfbfSEd Maste using namespace lldb_private;
45ac7ddfbfSEd Maste
FindExternalVisibleDeclsByName(const clang::DeclContext * decl_ctx,clang::DeclarationName clang_decl_name)46435933ddSDimitry Andric bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
47ac7ddfbfSEd Maste const clang::DeclContext *decl_ctx,
48435933ddSDimitry Andric clang::DeclarationName clang_decl_name) {
49435933ddSDimitry Andric if (m_callback_find_by_name) {
50ac7ddfbfSEd Maste llvm::SmallVector<clang::NamedDecl *, 3> results;
51ac7ddfbfSEd Maste
52435933ddSDimitry Andric m_callback_find_by_name(m_callback_baton, decl_ctx, clang_decl_name,
53435933ddSDimitry Andric &results);
54ac7ddfbfSEd Maste
55ac7ddfbfSEd Maste SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, results);
56ac7ddfbfSEd Maste
57ac7ddfbfSEd Maste return (results.size() != 0);
58ac7ddfbfSEd Maste }
59ac7ddfbfSEd Maste
60ac7ddfbfSEd Maste std::string decl_name(clang_decl_name.getAsString());
61ac7ddfbfSEd Maste SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
62ac7ddfbfSEd Maste return false;
63ac7ddfbfSEd Maste }
64ac7ddfbfSEd Maste
CompleteType(TagDecl * tag_decl)65435933ddSDimitry Andric void ClangExternalASTSourceCallbacks::CompleteType(TagDecl *tag_decl) {
66ac7ddfbfSEd Maste if (m_callback_tag_decl)
67ac7ddfbfSEd Maste m_callback_tag_decl(m_callback_baton, tag_decl);
68ac7ddfbfSEd Maste }
69ac7ddfbfSEd Maste
CompleteType(ObjCInterfaceDecl * objc_decl)70435933ddSDimitry Andric void ClangExternalASTSourceCallbacks::CompleteType(
71435933ddSDimitry Andric ObjCInterfaceDecl *objc_decl) {
72ac7ddfbfSEd Maste if (m_callback_objc_decl)
73ac7ddfbfSEd Maste m_callback_objc_decl(m_callback_baton, objc_decl);
74ac7ddfbfSEd Maste }
75ac7ddfbfSEd Maste
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)76435933ddSDimitry Andric bool ClangExternalASTSourceCallbacks::layoutRecordType(
771c3bbb01SEd Maste const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
78ac7ddfbfSEd Maste llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
79ac7ddfbfSEd Maste llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
80435933ddSDimitry Andric llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
81435933ddSDimitry Andric &VirtualBaseOffsets) {
82ac7ddfbfSEd Maste if (m_callback_layout_record_type)
83435933ddSDimitry Andric return m_callback_layout_record_type(m_callback_baton, Record, Size,
84435933ddSDimitry Andric Alignment, FieldOffsets, BaseOffsets,
85ac7ddfbfSEd Maste VirtualBaseOffsets);
86ac7ddfbfSEd Maste
87ac7ddfbfSEd Maste return false;
88ac7ddfbfSEd Maste }
89ac7ddfbfSEd Maste
FindExternalLexicalDecls(const clang::DeclContext * decl_ctx,llvm::function_ref<bool (clang::Decl::Kind)> IsKindWeWant,llvm::SmallVectorImpl<clang::Decl * > & decls)90435933ddSDimitry Andric void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(
91435933ddSDimitry Andric const clang::DeclContext *decl_ctx,
929f2f44ceSEd Maste llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
93435933ddSDimitry Andric llvm::SmallVectorImpl<clang::Decl *> &decls) {
94435933ddSDimitry Andric if (m_callback_tag_decl && decl_ctx) {
95435933ddSDimitry Andric clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(
96435933ddSDimitry Andric const_cast<clang::DeclContext *>(decl_ctx));
979f2f44ceSEd Maste if (tag_decl)
989f2f44ceSEd Maste CompleteType(tag_decl);
999f2f44ceSEd Maste }
1009f2f44ceSEd Maste }
101