Skip to content

Commit b96cced

Browse files
authored
Merge pull request #7578 from augusto2112/refactor-add-variables
[lldb][NFC] Split looking up variables and registering in two functions
2 parents 14d30fb + 6d8423c commit b96cced

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftUserExpression.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,10 @@ static bool AddVariableInfo(
398398
return true;
399399
}
400400

401-
/// Create a \c VariableInfo record for each visible variable.
402-
static bool RegisterAllVariables(
403-
SymbolContext &sc, lldb::StackFrameSP &stack_frame_sp,
404-
SwiftASTContextForExpressions &ast_context,
405-
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
406-
lldb::DynamicValueType use_dynamic,
407-
lldb::BindGenericTypes bind_generic_types) {
408-
LLDB_SCOPED_TIMER();
401+
/// Collets all the variables visible in the current scope.
402+
static bool CollectVariablesInScope(SymbolContext &sc,
403+
lldb::StackFrameSP &stack_frame_sp,
404+
VariableList &variables) {
409405
if (!sc.block && !sc.function)
410406
return true;
411407

@@ -415,20 +411,9 @@ static bool RegisterAllVariables(
415411
if (!top_block)
416412
top_block = &sc.function->GetBlock(true);
417413

418-
SwiftLanguageRuntime *language_runtime = nullptr;
419-
420-
if (stack_frame_sp)
421-
language_runtime =
422-
SwiftLanguageRuntime::Get(stack_frame_sp->GetThread()->GetProcess());
423-
424414
// The module scoped variables are stored at the CompUnit level, so
425415
// after we go through the current context, then we have to take one
426416
// more pass through the variables in the CompUnit.
427-
VariableList variables;
428-
429-
// Proceed from the innermost scope outwards, adding all variables
430-
// not already shadowed by an inner declaration.
431-
llvm::SmallDenseSet<const char *, 8> processed_names;
432417
bool done = false;
433418
do {
434419
// Iterate over all parent contexts *including* the top_block.
@@ -457,7 +442,29 @@ static bool RegisterAllVariables(
457442
if (globals_sp)
458443
variables.AddVariables(globals_sp.get());
459444
}
445+
return true;
446+
}
447+
448+
/// Create a \c VariableInfo record for each visible variable.
449+
static bool RegisterAllVariables(
450+
SymbolContext &sc, lldb::StackFrameSP &stack_frame_sp,
451+
SwiftASTContextForExpressions &ast_context,
452+
llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &local_variables,
453+
lldb::DynamicValueType use_dynamic,
454+
lldb::BindGenericTypes bind_generic_types) {
455+
LLDB_SCOPED_TIMER();
456+
SwiftLanguageRuntime *language_runtime = nullptr;
457+
458+
if (stack_frame_sp)
459+
language_runtime =
460+
SwiftLanguageRuntime::Get(stack_frame_sp->GetThread()->GetProcess());
460461

462+
VariableList variables;
463+
CollectVariablesInScope(sc, stack_frame_sp, variables);
464+
465+
// Proceed from the innermost scope outwards, adding all variables
466+
// not already shadowed by an inner declaration.
467+
llvm::SmallDenseSet<const char *, 8> processed_names;
461468
for (size_t vi = 0, ve = variables.GetSize(); vi != ve; ++vi)
462469
if (!AddVariableInfo({variables.GetVariableAtIndex(vi)}, stack_frame_sp,
463470
ast_context, language_runtime, processed_names,

0 commit comments

Comments
 (0)