blob: a96ef19b02f5d1e7b766abfca2e14e5fab0cd3bf [file] [log] [blame]
Greg Clayton47a15b72011-01-17 04:19:51 +00001//===-- 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 Clayton47a15b72011-01-17 04:19:51 +000012
Kate Stoneb9c1b512016-09-06 20:57:50 +000013// Clang headers like to use NDEBUG inside of them to enable/disable debug
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +000014// related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
Greg Clayton47a15b72011-01-17 04:19:51 +000015// 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 Callanan3b1d4f62011-10-26 17:46:51 +000023#if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
Greg Clayton47a15b72011-01-17 04:19:51 +000024#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 Turner6f9e6902017-03-03 20:56:28 +000040#include "lldb/Utility/Log.h"
Greg Claytone6b36cd2015-12-08 01:02:08 +000041#include "clang/AST/Decl.h"
Greg Clayton47a15b72011-01-17 04:19:51 +000042
43using namespace clang;
44using namespace lldb_private;
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(
Greg Clayton47a15b72011-01-17 04:19:51 +000047 const clang::DeclContext *decl_ctx,
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 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 Stoneb9c1b512016-09-06 20:57:50 +000061 SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
62 return false;
Greg Clayton47a15b72011-01-17 04:19:51 +000063}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065void ClangExternalASTSourceCallbacks::CompleteType(TagDecl *tag_decl) {
66 if (m_callback_tag_decl)
67 m_callback_tag_decl(m_callback_baton, tag_decl);
Greg Clayton47a15b72011-01-17 04:19:51 +000068}
69
Kate Stoneb9c1b512016-09-06 20:57:50 +000070void ClangExternalASTSourceCallbacks::CompleteType(
71 ObjCInterfaceDecl *objc_decl) {
72 if (m_callback_objc_decl)
73 m_callback_objc_decl(m_callback_baton, objc_decl);
Greg Clayton47a15b72011-01-17 04:19:51 +000074}
Sean Callanan5b26f272012-02-04 08:49:35 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076bool ClangExternalASTSourceCallbacks::layoutRecordType(
Zachary Turner504f38d2015-03-24 16:24:50 +000077 const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
Zachary Turnera98fac22015-03-24 18:56:08 +000078 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
79 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 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 Callanan5b26f272012-02-04 08:49:35 +000088}
89
Kate Stoneb9c1b512016-09-06 20:57:50 +000090void 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 Claytone6b36cd2015-12-08 01:02:08 +0000100}