diff options
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp')
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp | 194 |
1 files changed, 6 insertions, 188 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index 58db9d4e742..94a23c8069a 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -52,9 +52,7 @@ private: ClangASTSource::ClangASTSource(const lldb::TargetSP &target) : m_import_in_progress(false), m_lookups_enabled(false), m_target(target), m_ast_context(nullptr), m_active_lexical_decls(), m_active_lookups() { - if (!target->GetUseModernTypeLookup()) { - m_ast_importer_sp = m_target->GetClangASTImporter(); - } + m_ast_importer_sp = m_target->GetClangASTImporter(); } void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context, @@ -63,81 +61,7 @@ void ClangASTSource::InstallASTContext(ClangASTContext &clang_ast_context, m_ast_context = clang_ast_context.getASTContext(); m_clang_ast_context = &clang_ast_context; m_file_manager = &file_manager; - if (m_target->GetUseModernTypeLookup()) { - // Configure the ExternalASTMerger. The merger needs to be able to import - // types from any source that we would do lookups in, which includes the - // persistent AST context as well as the modules and Objective-C runtime - // AST contexts. - - lldbassert(!m_merger_up); - clang::ExternalASTMerger::ImporterTarget target = {*m_ast_context, - file_manager}; - std::vector<clang::ExternalASTMerger::ImporterSource> sources; - for (lldb::ModuleSP module_sp : m_target->GetImages().Modules()) { - auto type_system_or_err = - module_sp->GetTypeSystemForLanguage(lldb::eLanguageTypeC); - if (auto err = type_system_or_err.takeError()) { - LLDB_LOG_ERROR( - lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS), - std::move(err), "Failed to get ClangASTContext"); - } else if (auto *module_ast_ctx = llvm::cast_or_null<ClangASTContext>( - &type_system_or_err.get())) { - lldbassert(module_ast_ctx->getASTContext()); - lldbassert(module_ast_ctx->getFileManager()); - sources.emplace_back(*module_ast_ctx->getASTContext(), - *module_ast_ctx->getFileManager(), - module_ast_ctx->GetOriginMap()); - } - } - - do { - lldb::ProcessSP process(m_target->GetProcessSP()); - - if (!process) - break; - - ObjCLanguageRuntime *language_runtime(ObjCLanguageRuntime::Get(*process)); - - if (!language_runtime) - break; - - if (auto *runtime_decl_vendor = llvm::dyn_cast_or_null<ClangDeclVendor>( - language_runtime->GetDeclVendor())) { - sources.push_back(runtime_decl_vendor->GetImporterSource()); - } - } while (false); - - do { - auto *modules_decl_vendor = m_target->GetClangModulesDeclVendor(); - - if (!modules_decl_vendor) - break; - - sources.push_back(modules_decl_vendor->GetImporterSource()); - } while (false); - - if (!is_shared_context) { - // Update the scratch AST context's merger to reflect any new sources we - // might have come across since the last time an expression was parsed. - - if (auto *clang_ast_context = ClangASTContext::GetScratch(*m_target)) { - - auto scratch_ast_context = - static_cast<ClangASTContextForExpressions *>(clang_ast_context); - - scratch_ast_context->GetMergerUnchecked().AddSources(sources); - - sources.push_back({*scratch_ast_context->getASTContext(), - *scratch_ast_context->getFileManager(), - scratch_ast_context->GetOriginMap()}); - } - } - - m_merger_up = - std::make_unique<clang::ExternalASTMerger>(target, sources); - } else { - m_ast_importer_sp->InstallMapCompleter(m_ast_context, *this); - } + m_ast_importer_sp->InstallMapCompleter(m_ast_context, *this); } ClangASTSource::~ClangASTSource() { @@ -293,9 +217,6 @@ void ClangASTSource::CompleteType(TagDecl *tag_decl) { ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl); if (!m_ast_importer_sp) { - if (HasMerger()) { - GetMergerUnchecked().CompleteType(tag_decl); - } return; } @@ -423,18 +344,7 @@ void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) { ClangUtil::DumpDecl(interface_decl)); if (!m_ast_importer_sp) { - if (HasMerger()) { - ObjCInterfaceDecl *complete_iface_decl = - GetCompleteObjCInterface(interface_decl); - - if (complete_iface_decl && (complete_iface_decl != interface_decl)) { - m_merger_up->ForceRecordOrigin(interface_decl, {complete_iface_decl, &complete_iface_decl->getASTContext()}); - } - - GetMergerUnchecked().CompleteType(interface_decl); - } else { - lldbassert(0 && "No mechanism for completing a type!"); - } + lldbassert(0 && "No mechanism for completing a type!"); return; } @@ -510,19 +420,7 @@ void ClangASTSource::FindExternalLexicalDecls( llvm::function_ref<bool(Decl::Kind)> predicate, llvm::SmallVectorImpl<Decl *> &decls) { - if (HasMerger()) { - if (auto *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_context)) { - ObjCInterfaceDecl *complete_iface_decl = - GetCompleteObjCInterface(interface_decl); - - if (complete_iface_decl && (complete_iface_decl != interface_decl)) { - m_merger_up->ForceRecordOrigin(interface_decl, {complete_iface_decl, &complete_iface_decl->getASTContext()}); - } - } - return GetMergerUnchecked().FindExternalLexicalDecls(decl_context, - predicate, - decls); - } else if (!m_ast_importer_sp) + if (!m_ast_importer_sp) return; Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); @@ -698,25 +596,6 @@ void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) { name.GetCString(), context.m_decl_context->getDeclKindName()); } - if (HasMerger() && !isa<TranslationUnitDecl>(context.m_decl_context) - /* possibly handle NamespaceDecls here? */) { - if (auto *interface_decl = - dyn_cast<ObjCInterfaceDecl>(context.m_decl_context)) { - ObjCInterfaceDecl *complete_iface_decl = - GetCompleteObjCInterface(interface_decl); - - if (complete_iface_decl && (complete_iface_decl != interface_decl)) { - GetMergerUnchecked().ForceRecordOrigin( - interface_decl, - {complete_iface_decl, &complete_iface_decl->getASTContext()}); - } - } - - GetMergerUnchecked().FindExternalVisibleDeclsByName(context.m_decl_context, - context.m_decl_name); - return; // otherwise we may need to fall back - } - context.m_namespace_map = std::make_shared<ClangASTImporter::NamespaceMap>(); if (const NamespaceDecl *namespace_context = @@ -741,7 +620,7 @@ void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) { FindExternalVisibleDecls(context, i->first, i->second, current_id); } - } else if (isa<ObjCInterfaceDecl>(context.m_decl_context) && !HasMerger()) { + } else if (isa<ObjCInterfaceDecl>(context.m_decl_context)) { FindObjCPropertyAndIvarDecls(context); } else if (!isa<TranslationUnitDecl>(context.m_decl_context)) { // we shouldn't be getting FindExternalVisibleDecls calls for these @@ -820,7 +699,7 @@ void ClangASTSource::FindExternalVisibleDecls( module_sp->GetFileSpec().GetFilename().GetCString()); } } - } else if (!HasMerger()) { + } else { const ModuleList &target_images = m_target->GetImages(); std::lock_guard<std::recursive_mutex> guard(target_images.GetMutex()); @@ -1131,21 +1010,6 @@ bool ClangASTSource::FindObjCMethodDeclsWithOrigin( void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); - if (HasMerger()) { - if (auto *interface_decl = dyn_cast<ObjCInterfaceDecl>(context.m_decl_context)) { - ObjCInterfaceDecl *complete_iface_decl = - GetCompleteObjCInterface(interface_decl); - - if (complete_iface_decl && (complete_iface_decl != context.m_decl_context)) { - m_merger_up->ForceRecordOrigin(interface_decl, {complete_iface_decl, &complete_iface_decl->getASTContext()}); - } - } - - GetMergerUnchecked().FindExternalVisibleDeclsByName(context.m_decl_context, - context.m_decl_name); - return; - } - static unsigned int invocation_id = 0; unsigned int current_id = invocation_id++; @@ -1950,45 +1814,10 @@ NamespaceDecl *ClangASTSource::AddNamespace( return dyn_cast<NamespaceDecl>(copied_decl); } -clang::QualType ClangASTSource::CopyTypeWithMerger( - clang::ASTContext &from_context, - clang::ExternalASTMerger &merger, - clang::QualType type) { - if (!merger.HasImporterForOrigin(from_context)) { - lldbassert(0 && "Couldn't find the importer for a source context!"); - return QualType(); - } - - if (llvm::Expected<QualType> type_or_error = - merger.ImporterForOrigin(from_context).Import(type)) { - return *type_or_error; - } else { - Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); - LLDB_LOG_ERROR(log, type_or_error.takeError(), "Couldn't import type: {0}"); - return QualType(); - } -} - clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) { clang::ASTContext &from_context = src_decl->getASTContext(); if (m_ast_importer_sp) { return m_ast_importer_sp->CopyDecl(m_ast_context, &from_context, src_decl); - } else if (m_merger_up) { - if (!m_merger_up->HasImporterForOrigin(from_context)) { - lldbassert(0 && "Couldn't find the importer for a source context!"); - return nullptr; - } - - if (llvm::Expected<Decl *> decl_or_error = - m_merger_up->ImporterForOrigin(from_context).Import(src_decl)) { - return *decl_or_error; - } else { - Log *log = - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); - LLDB_LOG_ERROR(log, decl_or_error.takeError(), - "Couldn't import decl: {0}"); - return nullptr; - } } else { lldbassert(0 && "No mechanism for copying a decl!"); return nullptr; @@ -1998,19 +1827,12 @@ clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) { ClangASTImporter::DeclOrigin ClangASTSource::GetDeclOrigin(const clang::Decl *decl) { if (m_ast_importer_sp) { return m_ast_importer_sp->GetDeclOrigin(decl); - } else if (m_merger_up) { - return ClangASTImporter::DeclOrigin(); // Implement this correctly in ExternalASTMerger } else { // this can happen early enough that no ExternalASTSource is installed. return ClangASTImporter::DeclOrigin(); } } -clang::ExternalASTMerger &ClangASTSource::GetMergerUnchecked() { - lldbassert(m_merger_up != nullptr); - return *m_merger_up; -} - CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) { ClangASTContext *src_ast = llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem()); @@ -2024,10 +1846,6 @@ CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) { if (m_ast_importer_sp) { copied_qual_type = ClangUtil::GetQualType( m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type)); - } else if (m_merger_up) { - copied_qual_type = - CopyTypeWithMerger(*src_ast->getASTContext(), *m_merger_up, - ClangUtil::GetQualType(src_type)); } else { lldbassert(0 && "No mechanism for copying a type!"); return CompilerType(); |