LLDB  mainline
ClangExternalASTSourceCallbacks.cpp
Go to the documentation of this file.
1 //===-- ClangExternalASTSourceCallbacks.cpp -------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
11 
12 #include "clang/AST/Decl.h"
13 #include "clang/AST/DeclObjC.h"
14 
15 using namespace lldb_private;
16 
18 
19 void ClangExternalASTSourceCallbacks::CompleteType(clang::TagDecl *tag_decl) {
20  m_ast.CompleteTagDecl(tag_decl);
21 }
22 
24  clang::ObjCInterfaceDecl *objc_decl) {
26 }
27 
29  const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
30  llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
31  llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
32  llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
33  &VirtualBaseOffsets) {
34  return m_ast.LayoutRecordType(Record, Size, Alignment, FieldOffsets,
35  BaseOffsets, VirtualBaseOffsets);
36 }
37 
39  const clang::DeclContext *decl_ctx,
40  llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
42  if (decl_ctx) {
43  clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(
44  const_cast<clang::DeclContext *>(decl_ctx));
45  if (tag_decl)
46  CompleteType(tag_decl);
47  }
48 }
49 
51  const clang::DeclContext *DC, clang::DeclarationName Name) {
52  llvm::SmallVector<clang::NamedDecl *, 4> decls;
53  // Objective-C methods are not added into the LookupPtr when they originate
54  // from an external source. SetExternalVisibleDeclsForName() adds them.
55  if (auto *oid = llvm::dyn_cast<clang::ObjCInterfaceDecl>(DC)) {
56  clang::ObjCContainerDecl::method_range noload_methods(oid->noload_decls());
57  for (auto *omd : noload_methods)
58  if (omd->getDeclName() == Name)
59  decls.push_back(omd);
60  }
61  return !SetExternalVisibleDeclsForName(DC, Name, decls).empty();
62 }
63 
66  m_modules.push_back(module);
67  unsigned id = m_modules.size();
68  m_ids.insert({module, id});
69  return OptionalClangModuleID(id);
70 }
71 
72 llvm::Optional<clang::ASTSourceDescriptor>
74  if (clang::Module *module = getModule(id))
75  return {*module};
76  return {};
77 }
78 
79 clang::Module *ClangExternalASTSourceCallbacks::getModule(unsigned id) {
80  if (id && id <= m_modules.size())
81  return m_modules[id - 1];
82  return nullptr;
83 }
84 
87  return OptionalClangModuleID(m_ids[module]);
88 }
lldb_private::ClangExternalASTSourceCallbacks::m_ids
llvm::DenseMap< clang::Module *, unsigned > m_ids
Definition: ClangExternalASTSourceCallbacks.h:61
lldb_private::TypeSystemClang::LayoutRecordType
bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets)
Definition: TypeSystemClang.cpp:9253
lldb_private::ClangExternalASTSourceCallbacks::CompleteType
void CompleteType(clang::TagDecl *tag_decl) override
Definition: ClangExternalASTSourceCallbacks.cpp:19
lldb_private::TypeSystemClang::CompleteObjCInterfaceDecl
void CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *)
Definition: TypeSystemClang.cpp:9231
lldb_private::ClangExternalASTSourceCallbacks::ID
static char ID
LLVM RTTI support.
Definition: ClangExternalASTSourceCallbacks.h:19
lldb_private::TypeSystemClang::CompleteTagDecl
void CompleteTagDecl(clang::TagDecl *)
Definition: TypeSystemClang.cpp:9222
lldb_private::ClangExternalASTSourceCallbacks::getModule
clang::Module * getModule(unsigned ID) override
Definition: ClangExternalASTSourceCallbacks.cpp:79
TypeSystemClang.h
lldb_private::ClangExternalASTSourceCallbacks::m_modules
std::vector< clang::Module * > m_modules
Definition: ClangExternalASTSourceCallbacks.h:60
lldb_private::ClangExternalASTSourceCallbacks::getSourceDescriptor
llvm::Optional< clang::ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
Module-related methods.
Definition: ClangExternalASTSourceCallbacks.cpp:73
lldb_private::ClangExternalASTSourceCallbacks::layoutRecordType
bool 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) override
Definition: ClangExternalASTSourceCallbacks.cpp:28
lldb_private::OptionalClangModuleID
A Clang module ID.
Definition: TypeSystemClang.h:57
lldb_private::ClangExternalASTSourceCallbacks::FindExternalLexicalDecls
void FindExternalLexicalDecls(const clang::DeclContext *DC, llvm::function_ref< bool(clang::Decl::Kind)> IsKindWeWant, llvm::SmallVectorImpl< clang::Decl * > &Result) override
Definition: ClangExternalASTSourceCallbacks.cpp:38
lldb_private::ClangExternalASTSourceCallbacks::RegisterModule
OptionalClangModuleID RegisterModule(clang::Module *module)
Definition: ClangExternalASTSourceCallbacks.cpp:65
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ClangExternalASTSourceCallbacks::GetIDForModule
OptionalClangModuleID GetIDForModule(clang::Module *module)
Definition: ClangExternalASTSourceCallbacks.cpp:86
lldb_private::ClangExternalASTSourceCallbacks::m_ast
TypeSystemClang & m_ast
Definition: ClangExternalASTSourceCallbacks.h:59
llvm::SmallVectorImpl
Definition: Disassembler.h:42
lldb_private::ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName
bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override
Definition: ClangExternalASTSourceCallbacks.cpp:50
ClangExternalASTSourceCallbacks.h