Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp
39648 views
//===-- ClangExternalASTSourceCallbacks.cpp -------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h"9#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"1011#include "clang/AST/Decl.h"12#include "clang/AST/DeclObjC.h"13#include "clang/Basic/Module.h"14#include <optional>1516using namespace lldb_private;1718char ClangExternalASTSourceCallbacks::ID;1920void ClangExternalASTSourceCallbacks::CompleteType(clang::TagDecl *tag_decl) {21m_ast.CompleteTagDecl(tag_decl);22}2324void ClangExternalASTSourceCallbacks::CompleteType(25clang::ObjCInterfaceDecl *objc_decl) {26m_ast.CompleteObjCInterfaceDecl(objc_decl);27}2829bool ClangExternalASTSourceCallbacks::layoutRecordType(30const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,31llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,32llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets,33llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>34&VirtualBaseOffsets) {35return m_ast.LayoutRecordType(Record, Size, Alignment, FieldOffsets,36BaseOffsets, VirtualBaseOffsets);37}3839void ClangExternalASTSourceCallbacks::FindExternalLexicalDecls(40const clang::DeclContext *decl_ctx,41llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,42llvm::SmallVectorImpl<clang::Decl *> &decls) {43if (decl_ctx) {44clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(45const_cast<clang::DeclContext *>(decl_ctx));46if (tag_decl)47CompleteType(tag_decl);48}49}5051bool ClangExternalASTSourceCallbacks::FindExternalVisibleDeclsByName(52const clang::DeclContext *DC, clang::DeclarationName Name) {53llvm::SmallVector<clang::NamedDecl *, 4> decls;54// Objective-C methods are not added into the LookupPtr when they originate55// from an external source. SetExternalVisibleDeclsForName() adds them.56if (auto *oid = llvm::dyn_cast<clang::ObjCInterfaceDecl>(DC)) {57clang::ObjCContainerDecl::method_range noload_methods(oid->noload_decls());58for (auto *omd : noload_methods)59if (omd->getDeclName() == Name)60decls.push_back(omd);61}62return !SetExternalVisibleDeclsForName(DC, Name, decls).empty();63}6465OptionalClangModuleID66ClangExternalASTSourceCallbacks::RegisterModule(clang::Module *module) {67m_modules.push_back(module);68unsigned id = m_modules.size();69m_ids.insert({module, id});70return OptionalClangModuleID(id);71}7273std::optional<clang::ASTSourceDescriptor>74ClangExternalASTSourceCallbacks::getSourceDescriptor(unsigned id) {75if (clang::Module *module = getModule(id))76return {*module};77return {};78}7980clang::Module *ClangExternalASTSourceCallbacks::getModule(unsigned id) {81if (id && id <= m_modules.size())82return m_modules[id - 1];83return nullptr;84}8586OptionalClangModuleID87ClangExternalASTSourceCallbacks::GetIDForModule(clang::Module *module) {88return OptionalClangModuleID(m_ids[module]);89}909192