[lldb][NFC] Move filling namespace map in ClangASTSource to own function
authorRaphael Isemann <teemperor@gmail.com>
Tue, 25 Feb 2020 12:43:11 +0000 (13:43 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Tue, 25 Feb 2020 12:59:21 +0000 (13:59 +0100)
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h

index bf0a354..f5c046e 100644 (file)
@@ -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) {}
index 345ce2b..7de94e1 100644 (file)
@@ -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;