Commit 7a0c5484 authored by Raphael Isemann's avatar Raphael Isemann
Browse files

[lldb][NFC] NFC refactoring ClangExpressionDeclMap::LookupLocalVariable

Adding an early exits and moving variable declarations closer to their
actual use.
parent fef69706
Loading
Loading
Loading
Loading
+33 −36
Original line number Diff line number Diff line
@@ -1172,17 +1172,16 @@ void ClangExpressionDeclMap::LookupInModulesDeclVendor(
bool ClangExpressionDeclMap::LookupLocalVariable(
    NameSearchContext &context, ConstString name, unsigned current_id,
    SymbolContext &sym_ctx, CompilerDeclContext &namespace_decl) {
  ValueObjectSP valobj;
  VariableSP var;
  if (sym_ctx.block == nullptr)
    return false;

  StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
  CompilerDeclContext compiler_decl_context =
      sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext()
                               : CompilerDeclContext();
  CompilerDeclContext decl_context = sym_ctx.block->GetDeclContext();
  if (!decl_context)
    return false;

  if (compiler_decl_context) {
  // Make sure that the variables are parsed so that we have the
  // declarations.
  StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
  VariableListSP vars = frame->GetInScopeVariableList(true);
  for (size_t i = 0; i < vars->GetSize(); i++)
    vars->GetVariableAtIndex(i)->GetDecl();
@@ -1191,8 +1190,9 @@ bool ClangExpressionDeclMap::LookupLocalVariable(
  // decls in the search if we are looking for decls in the artificial
  // namespace $__lldb_local_vars.
  std::vector<CompilerDecl> found_decls =
        compiler_decl_context.FindDeclByName(name, namespace_decl.IsValid());
      decl_context.FindDeclByName(name, namespace_decl.IsValid());

  VariableSP var;
  bool variable_found = false;
  for (CompilerDecl decl : found_decls) {
    for (size_t vi = 0, ve = vars->GetSize(); vi != ve; ++vi) {
@@ -1205,15 +1205,12 @@ bool ClangExpressionDeclMap::LookupLocalVariable(

    if (var && !variable_found) {
      variable_found = true;
        valobj = ValueObjectVariable::Create(frame, var);
      ValueObjectSP valobj = ValueObjectVariable::Create(frame, var);
      AddOneVariable(context, var, valobj, current_id);
      context.m_found.variable = true;
    }
  }
    if (variable_found)
      return true;
  }
  return false;
  return variable_found;
}

void ClangExpressionDeclMap::LookupFunction(NameSearchContext &context,