[Lldb-commits] [lldb] 3d81008 - [lldb][Lanugage][NFC] Adapt Language::ForEach to IterationAction (#161830)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 3 07:47:26 PDT 2025
Author: Michael Buch
Date: 2025-10-03T15:47:21+01:00
New Revision: 3d810086d1e16e2de57634d7eb5ecf25a5227e4c
URL: https://github.com/llvm/llvm-project/commit/3d810086d1e16e2de57634d7eb5ecf25a5227e4c
DIFF: https://github.com/llvm/llvm-project/commit/3d810086d1e16e2de57634d7eb5ecf25a5227e4c.diff
LOG: [lldb][Lanugage][NFC] Adapt Language::ForEach to IterationAction (#161830)
Added:
Modified:
lldb/include/lldb/Target/Language.h
lldb/source/Breakpoint/BreakpointResolverName.cpp
lldb/source/Commands/CommandObjectType.cpp
lldb/source/Core/Mangled.cpp
lldb/source/Symbol/Symtab.cpp
lldb/source/Target/Language.cpp
Removed:
################################################################################
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