Skip to content

Commit 89fe40a

Browse files
[lldb][NFC] Make GetVariableNotCapturedDiagnostic a member of StackFrame
This NFC commit moves the function GetVariableNotCapturedDiagnostic into StackFrame, so that it may be shared between the DIL and Legacy implementations of `GetValueForVariableExpressionPath`.
1 parent 2fd48a7 commit 89fe40a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lldb/include/lldb/Target/StackFrame.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,17 @@ class StackFrame : public ExecutionContextScope,
533533

534534
lldb::RecognizedStackFrameSP GetRecognizedFrame();
535535

536+
// BEGIN SWIFT
537+
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
538+
// rdar://152321823
539+
/// If `sc` represents a "closure-like" function according to `lang`, and
540+
/// `missing_var_name` can be found in a parent context, create a diagnostic
541+
/// explaining that this variable is available but not captured by the
542+
/// closure.
543+
std::string
544+
GetVariableNotCapturedDiagnostic(llvm::StringRef missing_var_name);
545+
// END SWIFT
546+
536547
protected:
537548
friend class StackFrameList;
538549

lldb/source/Target/StackFrame.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -479,20 +479,13 @@ VariableList *StackFrame::GetVariableList(bool get_file_globals,
479479
}
480480

481481
// BEGIN SWIFT
482-
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
483-
// rdar://152321823
484-
485-
/// If `sc` represents a "closure-like" function according to `lang`, and
486-
/// `missing_var_name` can be found in a parent context, create a diagnostic
487-
/// explaining that this variable is available but not captured by the closure.
488-
static std::string
489-
GetVariableNotCapturedDiagnostic(SymbolContext &sc, SourceLanguage lang,
490-
ConstString missing_var_name) {
491-
Language *lang_plugin = Language::FindPlugin(lang.AsLanguageType());
482+
std::string
483+
StackFrame::GetVariableNotCapturedDiagnostic(llvm::StringRef missing_var_name) {
484+
Language *lang_plugin = Language::FindPlugin(GetLanguage().AsLanguageType());
492485
if (lang_plugin == nullptr)
493486
return "";
494487
Function *parent_func =
495-
lang_plugin->FindParentOfClosureWithVariable(missing_var_name, sc);
488+
lang_plugin->FindParentOfClosureWithVariable(missing_var_name, m_sc);
496489
if (!parent_func)
497490
return "";
498491
return llvm::formatv("A variable named '{0}' existed in function '{1}', but "
@@ -708,8 +701,8 @@ ValueObjectSP StackFrame::LegacyGetValueForVariableExpressionPath(
708701
// BEGIN SWIFT
709702
// Implement LanguageCPlusPlus::GetParentNameIfClosure and upstream this.
710703
// rdar://152321823
711-
if (std::string message = GetVariableNotCapturedDiagnostic(
712-
m_sc, GetLanguage(), name_const_string);
704+
if (std::string message =
705+
GetVariableNotCapturedDiagnostic(name_const_string);
713706
!message.empty())
714707
error = Status::FromErrorString(message.c_str());
715708
else

0 commit comments

Comments
 (0)