-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lldb][Format][NFCI] Refactor CPlusPlusLanguage::GetFunctionDisplayName into helpers and use LLVM style #135331
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
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
…me into helpers and use LLVM style Same cleanup as in llvm#135031. It pretty much is the same code that we had to duplicate in the language plugin. Maybe eventually we'll find a way of getting rid of the duplication.
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesSame cleanup as in #135031. It pretty much is the same code that we had to duplicate in the language plugin. Maybe eventually we'll find a way of getting rid of the duplication. Full diff: https://github.com/llvm/llvm-project/pull/135331.diff 1 Files Affected:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 4b045d12ad494..09fe9be665df7 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -1697,65 +1697,88 @@ bool CPlusPlusLanguage::IsSourceFile(llvm::StringRef file_path) const {
return file_path.contains("/usr/include/c++/");
}
+static VariableListSP GetFunctionVariableList(const SymbolContext &sc) {
+ assert(sc.function);
+
+ if (sc.block)
+ if (Block *inline_block = sc.block->GetContainingInlinedBlock())
+ return inline_block->GetBlockVariableList(true);
+
+ return sc.function->GetBlock(true).GetBlockVariableList(true);
+}
+
+static char const *GetInlinedFunctionName(const SymbolContext &sc) {
+ if (!sc.block)
+ return nullptr;
+
+ const Block *inline_block = sc.block->GetContainingInlinedBlock();
+ if (!inline_block)
+ return nullptr;
+
+ const InlineFunctionInfo *inline_info =
+ inline_block->GetInlinedFunctionInfo();
+ if (!inline_info)
+ return nullptr;
+
+ return inline_info->GetName().AsCString(nullptr);
+}
+
+static bool PrintFunctionNameWithArgs(Stream &s,
+ const ExecutionContext *exe_ctx,
+ const SymbolContext &sc) {
+ assert(sc.function);
+
+ ExecutionContextScope *exe_scope =
+ exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
+
+ const char *cstr = sc.function->GetName().AsCString(nullptr);
+ if (!cstr)
+ return false;
+
+ if (const char *inlined_name = GetInlinedFunctionName(sc)) {
+ s.PutCString(cstr);
+ s.PutCString(" [inlined] ");
+ cstr = inlined_name;
+ }
+
+ VariableList args;
+ if (auto variable_list_sp = GetFunctionVariableList(sc))
+ variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
+ args);
+
+ if (args.GetSize() > 0) {
+ PrettyPrintFunctionNameWithArgs(s, cstr, exe_scope, args);
+ } else {
+ s.PutCString(cstr);
+ }
+
+ return true;
+}
+
bool CPlusPlusLanguage::GetFunctionDisplayName(
const SymbolContext *sc, const ExecutionContext *exe_ctx,
FunctionNameRepresentation representation, Stream &s) {
switch (representation) {
case FunctionNameRepresentation::eNameWithArgs: {
+ assert(sc);
+
// Print the function name with arguments in it
- if (sc->function) {
- ExecutionContextScope *exe_scope =
- exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
- const char *cstr = sc->function->GetName().AsCString(nullptr);
- if (cstr) {
- const InlineFunctionInfo *inline_info = nullptr;
- VariableListSP variable_list_sp;
- bool get_function_vars = true;
- if (sc->block) {
- Block *inline_block = sc->block->GetContainingInlinedBlock();
-
- if (inline_block) {
- get_function_vars = false;
- inline_info = inline_block->GetInlinedFunctionInfo();
- if (inline_info)
- variable_list_sp = inline_block->GetBlockVariableList(true);
- }
- }
-
- if (get_function_vars) {
- variable_list_sp =
- sc->function->GetBlock(true).GetBlockVariableList(true);
- }
-
- if (inline_info) {
- s.PutCString(cstr);
- s.PutCString(" [inlined] ");
- cstr = inline_info->GetName().GetCString();
- }
-
- VariableList args;
- if (variable_list_sp)
- variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
- args);
- if (args.GetSize() > 0) {
- if (!PrettyPrintFunctionNameWithArgs(s, cstr, exe_scope, args))
- return false;
- } else {
- s.PutCString(cstr);
- }
- return true;
- }
- } else if (sc->symbol) {
- const char *cstr = sc->symbol->GetName().AsCString(nullptr);
- if (cstr) {
- s.PutCString(cstr);
- return true;
- }
- }
- } break;
- default:
+ if (sc->function)
+ return PrintFunctionNameWithArgs(s, exe_ctx, *sc);
+
+ if (!sc->symbol)
+ return false;
+
+ const char *cstr = sc->symbol->GetName().AsCString(nullptr);
+ if (!cstr)
+ return false;
+
+ s.PutCString(cstr);
+
+ return true;
+ }
+ case FunctionNameRepresentation::eNameWithNoArgs:
+ case FunctionNameRepresentation::eName:
return false;
}
-
- return false;
}
|
labath
approved these changes
Apr 11, 2025
var-const
pushed a commit
to ldionne/llvm-project
that referenced
this pull request
Apr 17, 2025
…me into helpers and use LLVM style (llvm#135331) Same cleanup as in llvm#135031. It pretty much is the same code that we had to duplicate in the language plugin. Maybe eventually we'll find a way of getting rid of the duplication.
Michael137
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Apr 26, 2025
…me into helpers and use LLVM style (llvm#135331) Same cleanup as in llvm#135031. It pretty much is the same code that we had to duplicate in the language plugin. Maybe eventually we'll find a way of getting rid of the duplication. (cherry picked from commit b656915)
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.
Same cleanup as in #135031. It pretty much is the same code that we had to duplicate in the language plugin. Maybe eventually we'll find a way of getting rid of the duplication.