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#include <optional>
15
16using namespace lldb_private;
17
19
20void ClangExternalASTSourceCallbacks::CompleteType(clang::TagDecl *tag_decl) {
21 m_ast.CompleteTagDecl(tag_decl);
22}
23
25 clang::ObjCInterfaceDecl *objc_decl) {
27}
28
30 const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
31 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
32 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,
33 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
34 &VirtualBaseOffsets) {
35 return m_ast.LayoutRecordType(Record, Size, Alignment, FieldOffsets,
36 BaseOffsets, VirtualBaseOffsets);
37}
38
40 const clang::DeclContext *decl_ctx,
41 llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
43 if (decl_ctx) {
44 clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(
45 const_cast<clang::DeclContext *>(decl_ctx));
46 if (tag_decl)
47 CompleteType(tag_decl);
48 }
49}
50
52 const clang::DeclContext *DC, clang::DeclarationName Name) {
53 llvm::SmallVector<clang::NamedDecl *, 4> decls;
54 // Objective-C methods are not added into the LookupPtr when they originate
55 // from an external source. SetExternalVisibleDeclsForName() adds them.
56 if (auto *oid = llvm::dyn_cast<clang::ObjCInterfaceDecl>(DC)) {
57 clang::ObjCContainerDecl::method_range noload_methods(oid->noload_decls());
58 for (auto *omd : noload_methods)
59 if (omd->getDeclName() == Name)
60 decls.push_back(omd);
61 }
62 return !SetExternalVisibleDeclsForName(DC, Name, decls).empty();
63}
64
67 m_modules.push_back(module);
68 unsigned id = m_modules.size();
69 m_ids.insert({module, id});
70 return OptionalClangModuleID(id);
71}
72
73std::optional<clang::ASTSourceDescriptor>
75 if (clang::Module *module = getModule(id))
76 return {*module};
77 return {};
78}
79
80clang::Module *ClangExternalASTSourceCallbacks::getModule(unsigned id) {
81 if (id && id <= m_modules.size())
82 return m_modules[id - 1];
83 return nullptr;
84}
85
88 return OptionalClangModuleID(m_ids[module]);
89}
bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, clang::DeclarationName Name) override
OptionalClangModuleID RegisterModule(clang::Module *module)
std::optional< clang::ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
Module-related methods.
OptionalClangModuleID GetIDForModule(clang::Module *module)
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
void FindExternalLexicalDecls(const clang::DeclContext *DC, llvm::function_ref< bool(clang::Decl::Kind)> IsKindWeWant, llvm::SmallVectorImpl< clang::Decl * > &Result) override
llvm::DenseMap< clang::Module *, unsigned > m_ids
void CompleteTagDecl(clang::TagDecl *)
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)
void CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14