[Lldb-commits] [lldb] [lldb][Lanugage][NFC] Adapt Language::ForEach to IterationAction (PR #161830)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 3 05:02:24 PDT 2025


https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/161830

None

>From 1691ea3e08708962b21193afc0b938c45d37598a Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 3 Oct 2025 13:00:45 +0100
Subject: [PATCH] [lldb][Lanugage][NFC] Adapt Language::ForEach to
 IterationAction

---
 lldb/include/lldb/Target/Language.h               |  5 +++--
 lldb/source/Breakpoint/BreakpointResolverName.cpp |  2 +-
 lldb/source/Commands/CommandObjectType.cpp        |  4 ++--
 lldb/source/Core/Mangled.cpp                      |  4 ++--
 lldb/source/Symbol/Symtab.cpp                     |  2 +-
 lldb/source/Target/Language.cpp                   | 15 ++++++++-------
 6 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 3d0aa326d5a6d..6f20a02335b35 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -166,7 +166,7 @@ class Language : public PluginInterface {
                               llvm::StringRef file_path);
 
   // return false from callback to stop iterating
-  static void ForEach(std::function<bool(Language *)> callback);
+  static void ForEach(llvm::function_ref<IterationAction(Language *)> callback);
 
   virtual lldb::LanguageType GetLanguageType() const = 0;
 
@@ -420,7 +420,8 @@ class Language : public PluginInterface {
                                                     llvm::StringRef suffix);
 
   // return false from callback to stop iterating
-  static void ForAllLanguages(std::function<bool(lldb::LanguageType)> callback);
+  static void ForAllLanguages(
+      llvm::function_ref<IterationAction(lldb::LanguageType)> callback);
 
   static bool LanguageIsCPlusPlus(lldb::LanguageType language);
 
diff --git a/lldb/source/Breakpoint/BreakpointResolverName.cpp b/lldb/source/Breakpoint/BreakpointResolverName.cpp
index 6372595a0f21f..4f252f91cccdc 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -233,7 +233,7 @@ void BreakpointResolverName::AddNameLookup(ConstString name,
         m_lookups.emplace_back(variant_lookup);
       }
     }
-    return true;
+    return IterationAction::Continue;
   };
 
   if (Language *lang = Language::FindPlugin(m_language)) {
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 19cd3ff2972e9..22ed5b8ed593a 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -2610,7 +2610,7 @@ class CommandObjectTypeLookup : public CommandObjectRaw {
     Language::ForEach([&](Language *lang) {
       if (const char *help = lang->GetLanguageSpecificTypeLookupHelp())
         stream.Printf("%s\n", help);
-      return true;
+      return IterationAction::Continue;
     });
 
     m_cmd_help_long = std::string(stream.GetString());
@@ -2649,7 +2649,7 @@ class CommandObjectTypeLookup : public CommandObjectRaw {
              (m_command_options.m_language == eLanguageTypeUnknown))) {
       Language::ForEach([&](Language *lang) {
         languages.push_back(lang);
-        return true;
+        return IterationAction::Continue;
       });
     } else {
       languages.push_back(Language::FindPlugin(m_command_options.m_language));
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 0780846b0ed60..f7683c55baf84 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -428,9 +428,9 @@ lldb::LanguageType Mangled::GuessLanguage() const {
   Language::ForEach([this, &result](Language *l) {
     if (l->SymbolNameFitsToLanguage(*this)) {
       result = l->GetLanguageType();
-      return false;
+      return IterationAction::Stop;
     }
-    return true;
+    return IterationAction::Continue;
   });
   return result;
 }
diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index 970f6c474e375..6080703998ff2 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -289,7 +289,7 @@ void Symtab::InitNameIndexes() {
     std::vector<Language *> languages;
     Language::ForEach([&languages](Language *l) {
       languages.push_back(l);
-      return true;
+      return IterationAction::Continue;
     });
 
     auto &name_to_index = GetNameToSymbolIndexMap(lldb::eFunctionNameTypeNone);
diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp
index 484d9badde397..d4a926874b0ce 100644
--- a/lldb/source/Target/Language.cpp
+++ b/lldb/source/Target/Language.cpp
@@ -111,9 +111,9 @@ Language *Language::FindPlugin(llvm::StringRef file_path) {
   ForEach([&result, file_path](Language *language) {
     if (language->IsSourceFile(file_path)) {
       result = language;
-      return false;
+      return IterationAction::Stop;
     }
-    return true;
+    return IterationAction::Continue;
   });
   return result;
 }
@@ -128,7 +128,8 @@ Language *Language::FindPlugin(LanguageType language,
   return result;
 }
 
-void Language::ForEach(std::function<bool(Language *)> callback) {
+void Language::ForEach(
+    llvm::function_ref<IterationAction(Language *)> callback) {
   // If we want to iterate over all languages, we first have to complete the
   // LanguagesMap.
   static llvm::once_flag g_initialize;
@@ -153,7 +154,7 @@ void Language::ForEach(std::function<bool(Language *)> callback) {
   }
 
   for (auto *lang : loaded_plugins) {
-    if (!callback(lang))
+    if (callback(lang) == IterationAction::Stop)
       break;
   }
 }
@@ -289,9 +290,9 @@ void Language::PrintAllLanguages(Stream &s, const char *prefix,
 }
 
 void Language::ForAllLanguages(
-    std::function<bool(lldb::LanguageType)> callback) {
+    llvm::function_ref<IterationAction(lldb::LanguageType)> callback) {
   for (uint32_t i = 1; i < num_languages; i++) {
-    if (!callback(language_names[i].type))
+    if (callback(language_names[i].type) == IterationAction::Stop)
       break;
   }
 }
@@ -416,7 +417,7 @@ std::set<lldb::LanguageType> Language::GetSupportedLanguages() {
   std::set<lldb::LanguageType> supported_languages;
   ForEach([&](Language *lang) {
     supported_languages.emplace(lang->GetLanguageType());
-    return true;
+    return IterationAction::Continue;
   });
   return supported_languages;
 }



More information about the lldb-commits mailing list