From bdb24faa2af4b989e757bc0a220224df9fe4d874 Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Tue, 25 Feb 2020 13:43:11 +0100 Subject: [PATCH] [lldb][NFC] Move filling namespace map in ClangASTSource to own function --- .../ExpressionParser/Clang/ClangASTSource.cpp | 101 ++++++++++++--------- .../ExpressionParser/Clang/ClangASTSource.h | 9 ++ 2 files changed, 66 insertions(+), 44 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp index bf0a354..f5c046e 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp @@ -616,50 +616,7 @@ void ClangASTSource::FindExternalVisibleDecls( if (!m_target) return; - if (module_sp && namespace_decl) { - CompilerDeclContext found_namespace_decl; - - if (SymbolFile *symbol_file = module_sp->GetSymbolFile()) { - found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl); - - if (found_namespace_decl) { - context.m_namespace_map->push_back( - std::pair( - module_sp, found_namespace_decl)); - - LLDB_LOG(log, " CAS::FEVD Found namespace {1} in module {2}", name, - module_sp->GetFileSpec().GetFilename()); - } - } - } else { - const ModuleList &target_images = m_target->GetImages(); - std::lock_guard guard(target_images.GetMutex()); - - for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) { - lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i); - - if (!image) - continue; - - CompilerDeclContext found_namespace_decl; - - SymbolFile *symbol_file = image->GetSymbolFile(); - - if (!symbol_file) - continue; - - found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl); - - if (found_namespace_decl) { - context.m_namespace_map->push_back( - std::pair( - image, found_namespace_decl)); - - LLDB_LOG(log, " CAS::FEVD Found namespace {1} in module {2}", name, - image->GetFileSpec().GetFilename()); - } - } - } + FillNamespaceMap(context, module_sp, namespace_decl); if (context.m_found_type) return; @@ -712,6 +669,62 @@ void ClangASTSource::FindExternalVisibleDecls( } } +void ClangASTSource::FillNamespaceMap( + NameSearchContext &context, lldb::ModuleSP module_sp, + const CompilerDeclContext &namespace_decl) { + const ConstString name(context.m_decl_name.getAsString().c_str()); + if (IgnoreName(name, true)) + return; + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + + if (module_sp && namespace_decl) { + CompilerDeclContext found_namespace_decl; + + if (SymbolFile *symbol_file = module_sp->GetSymbolFile()) { + found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl); + + if (found_namespace_decl) { + context.m_namespace_map->push_back( + std::pair( + module_sp, found_namespace_decl)); + + LLDB_LOG(log, " CAS::FEVD Found namespace {1} in module {2}", name, + module_sp->GetFileSpec().GetFilename()); + } + } + return; + } + + const ModuleList &target_images = m_target->GetImages(); + std::lock_guard guard(target_images.GetMutex()); + + for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) { + lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i); + + if (!image) + continue; + + CompilerDeclContext found_namespace_decl; + + SymbolFile *symbol_file = image->GetSymbolFile(); + + if (!symbol_file) + continue; + + found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl); + + if (found_namespace_decl) { + context.m_namespace_map->push_back( + std::pair(image, + found_namespace_decl)); + + LLDB_LOG(log, " CAS::FEVD Found namespace {1} in module {2}", name, + image->GetFileSpec().GetFilename()); + } + } +} + template class TaggedASTDecl { public: TaggedASTDecl() : decl(nullptr) {} diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h index 345ce2b..7de94e1 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h @@ -364,6 +364,15 @@ protected: void FindDeclInModules(NameSearchContext &context, ConstString name); void FindDeclInObjCRuntime(NameSearchContext &context, ConstString name); + /// Fills the namespace map of the given NameSearchContext. + /// + /// \param context The NameSearchContext with the namespace map to fill. + /// \param module_sp The module to search for namespaces or a nullptr if + /// the current target should be searched. + /// \param namespace_decl The DeclContext in which to search for namespaces. + void FillNamespaceMap(NameSearchContext &context, lldb::ModuleSP module_sp, + const CompilerDeclContext &namespace_decl); + friend struct NameSearchContext; bool m_import_in_progress; -- 2.7.4