-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb][Lanugage][NFC] Adapt Language::ForEach to IterationAction #161830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Michael137
merged 1 commit into
llvm:main
from
Michael137:lldb/language-foreach-iterationaction
Oct 3, 2025
Merged
[lldb][Lanugage][NFC] Adapt Language::ForEach to IterationAction #161830
Michael137
merged 1 commit into
llvm:main
from
Michael137:lldb/language-foreach-iterationaction
Oct 3, 2025
+17
−15
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesFull diff: https://github.com/llvm/llvm-project/pull/161830.diff 6 Files Affected:
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;
}
|
felipepiovezan
approved these changes
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While I'm here, also changed from using
std::function
to a non-allocating 'llvm::function_ref`