forked from OSchip/llvm-project
[lldb][NFC] NFC refactoring ClangExpressionDeclMap::LookupLocalVariable
Adding an early exits and moving variable declarations closer to their actual use.
This commit is contained in:
parent
fef69706dc
commit
7a0c548444
|
@ -1172,48 +1172,45 @@ void ClangExpressionDeclMap::LookupInModulesDeclVendor(
|
||||||
bool ClangExpressionDeclMap::LookupLocalVariable(
|
bool ClangExpressionDeclMap::LookupLocalVariable(
|
||||||
NameSearchContext &context, ConstString name, unsigned current_id,
|
NameSearchContext &context, ConstString name, unsigned current_id,
|
||||||
SymbolContext &sym_ctx, CompilerDeclContext &namespace_decl) {
|
SymbolContext &sym_ctx, CompilerDeclContext &namespace_decl) {
|
||||||
ValueObjectSP valobj;
|
if (sym_ctx.block == nullptr)
|
||||||
VariableSP var;
|
return false;
|
||||||
|
|
||||||
|
CompilerDeclContext decl_context = sym_ctx.block->GetDeclContext();
|
||||||
|
if (!decl_context)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Make sure that the variables are parsed so that we have the
|
||||||
|
// declarations.
|
||||||
StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
|
StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
|
||||||
CompilerDeclContext compiler_decl_context =
|
VariableListSP vars = frame->GetInScopeVariableList(true);
|
||||||
sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext()
|
for (size_t i = 0; i < vars->GetSize(); i++)
|
||||||
: CompilerDeclContext();
|
vars->GetVariableAtIndex(i)->GetDecl();
|
||||||
|
|
||||||
if (compiler_decl_context) {
|
// Search for declarations matching the name. Do not include imported
|
||||||
// Make sure that the variables are parsed so that we have the
|
// decls in the search if we are looking for decls in the artificial
|
||||||
// declarations.
|
// namespace $__lldb_local_vars.
|
||||||
VariableListSP vars = frame->GetInScopeVariableList(true);
|
std::vector<CompilerDecl> found_decls =
|
||||||
for (size_t i = 0; i < vars->GetSize(); i++)
|
decl_context.FindDeclByName(name, namespace_decl.IsValid());
|
||||||
vars->GetVariableAtIndex(i)->GetDecl();
|
|
||||||
|
|
||||||
// Search for declarations matching the name. Do not include imported
|
VariableSP var;
|
||||||
// decls in the search if we are looking for decls in the artificial
|
bool variable_found = false;
|
||||||
// namespace $__lldb_local_vars.
|
for (CompilerDecl decl : found_decls) {
|
||||||
std::vector<CompilerDecl> found_decls =
|
for (size_t vi = 0, ve = vars->GetSize(); vi != ve; ++vi) {
|
||||||
compiler_decl_context.FindDeclByName(name, namespace_decl.IsValid());
|
VariableSP candidate_var = vars->GetVariableAtIndex(vi);
|
||||||
|
if (candidate_var->GetDecl() == decl) {
|
||||||
bool variable_found = false;
|
var = candidate_var;
|
||||||
for (CompilerDecl decl : found_decls) {
|
break;
|
||||||
for (size_t vi = 0, ve = vars->GetSize(); vi != ve; ++vi) {
|
|
||||||
VariableSP candidate_var = vars->GetVariableAtIndex(vi);
|
|
||||||
if (candidate_var->GetDecl() == decl) {
|
|
||||||
var = candidate_var;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (var && !variable_found) {
|
|
||||||
variable_found = true;
|
|
||||||
valobj = ValueObjectVariable::Create(frame, var);
|
|
||||||
AddOneVariable(context, var, valobj, current_id);
|
|
||||||
context.m_found.variable = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (variable_found)
|
|
||||||
return true;
|
if (var && !variable_found) {
|
||||||
|
variable_found = true;
|
||||||
|
ValueObjectSP valobj = ValueObjectVariable::Create(frame, var);
|
||||||
|
AddOneVariable(context, var, valobj, current_id);
|
||||||
|
context.m_found.variable = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return variable_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangExpressionDeclMap::LookupFunction(NameSearchContext &context,
|
void ClangExpressionDeclMap::LookupFunction(NameSearchContext &context,
|
||||||
|
|
Loading…
Reference in New Issue