[Lldb-commits] [lldb] bdb24fa - [lldb][NFC] Move filling namespace map in ClangASTSource to own function

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 25 04:59:44 PST 2020


Author: Raphael Isemann
Date: 2020-02-25T13:59:21+01:00
New Revision: bdb24faa2af4b989e757bc0a220224df9fe4d874

URL: https://github.com/llvm/llvm-project/commit/bdb24faa2af4b989e757bc0a220224df9fe4d874
DIFF: https://github.com/llvm/llvm-project/commit/bdb24faa2af4b989e757bc0a220224df9fe4d874.diff

LOG: [lldb][NFC] Move filling namespace map in ClangASTSource to own function

Added: 
    

Modified: 
    lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index bf0a354c890b..f5c046e6c021 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<lldb::ModuleSP, CompilerDeclContext>(
-                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<std::recursive_mutex> 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<lldb::ModuleSP, CompilerDeclContext>(
-                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<lldb::ModuleSP, CompilerDeclContext>(
+                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<std::recursive_mutex> 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<lldb::ModuleSP, CompilerDeclContext>(image,
+                                                         found_namespace_decl));
+
+      LLDB_LOG(log, "  CAS::FEVD Found namespace {1} in module {2}", name,
+               image->GetFileSpec().GetFilename());
+    }
+  }
+}
+
 template <class D> 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 345ce2b8f7db..7de94e19b591 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
@@ -364,6 +364,15 @@ class ClangASTSource : public clang::ExternalASTSource,
   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;


        


More information about the lldb-commits mailing list