diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-12-17 12:22:34 +0100 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-12-17 12:24:31 +0100 |
commit | ff0102b32cfe506dfc16a86e38e70b0940697aa2 (patch) | |
tree | 5ca3f549f0f4768a7f8b95af6297382a521de7ed /lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp | |
parent | df5a905aa8a868bdb700d88e427491ee56243e30 (diff) | |
download | bcm5719-llvm-ff0102b32cfe506dfc16a86e38e70b0940697aa2.tar.gz bcm5719-llvm-ff0102b32cfe506dfc16a86e38e70b0940697aa2.zip |
[lldb] Remove modern-type-lookup
Summary:
As discussed on the mailing list [1] we have to make a decision for how to proceed with the modern-type-lookup.
This patch removes modern-type-lookup from LLDB. This just removes all the code behind the modern-type-lookup
setting but it does *not* remove any code from Clang (i.e., the ExternalASTMerger and the clang-import-test stay around
for now).
The motivation for this is that I don't think that the current approach of implementing modern-type-lookup
will work out. Especially creating a completely new lookup system behind some setting that is never turned on by anyone
and then one day make one big switch to the new system seems wrong. It doesn't fit into the way LLVM is developed and has
so far made the transition work much more complicated than it has to be.
A lot of the benefits that were supposed to come with the modern-type-lookup are related to having a better organization
in the way types move across LLDB and having less dependencies on unrelated LLDB code. By just looking at the current code (mostly
the ClangASTImporter) I think we can reach the same goals by just incrementally cleaning up, documenting, refactoring
and actually testing the existing code we have.
[1] http://lists.llvm.org/pipermail/lldb-dev/2019-December/015831.html
Reviewers: shafik, martong
Subscribers: rnkovacs, christof, arphaman, JDevlieghere, usaxena95, lldb-commits, friss
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D71562
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(); |