Skip to content

Commit 9d881e2

Browse files
committed
Re-do some if-statements to facilitate early exits.
1 parent c7eb5fd commit 9d881e2

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

lldb/source/ValueObject/DILEval.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@ LookupStaticIdentifier(lldb::TargetSP target_sp,
3030
VariableList variable_list;
3131
ConstString name(name_ref);
3232
target_sp->GetImages().FindGlobalVariables(name, 1, variable_list);
33-
if (!variable_list.Empty()) {
34-
ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
35-
if (exe_scope == nullptr)
36-
exe_scope = target_sp.get();
37-
for (const lldb::VariableSP &var_sp : variable_list) {
38-
lldb::ValueObjectSP valobj_sp(
39-
ValueObjectVariable::Create(exe_scope, var_sp));
40-
if (valobj_sp && valobj_sp->GetVariable() &&
41-
(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
42-
valobj_sp->GetVariable()->NameMatches(ConstString(name_ref))))
43-
return valobj_sp;
44-
}
33+
if (variable_list.Empty())
34+
return nullptr;
35+
36+
ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
37+
if (exe_scope == nullptr)
38+
exe_scope = target_sp.get();
39+
for (const lldb::VariableSP &var_sp : variable_list) {
40+
lldb::ValueObjectSP valobj_sp(
41+
ValueObjectVariable::Create(exe_scope, var_sp));
42+
if (valobj_sp && valobj_sp->GetVariable() &&
43+
(valobj_sp->GetVariable()->NameMatches(unqualified_name) ||
44+
valobj_sp->GetVariable()->NameMatches(ConstString(name_ref))))
45+
return valobj_sp;
4546
}
47+
4648
return nullptr;
4749
}
4850

@@ -110,18 +112,22 @@ LookupIdentifier(const std::string &name,
110112
const char *reg_name = name_ref.drop_front(1).data();
111113
Target *target = ctx_scope->CalculateTarget().get();
112114
Process *process = ctx_scope->CalculateProcess().get();
113-
if (target && process) {
114-
StackFrame *stack_frame = ctx_scope->CalculateStackFrame().get();
115-
if (stack_frame) {
116-
lldb::RegisterContextSP reg_ctx(stack_frame->GetRegisterContext());
117-
if (reg_ctx) {
118-
if (const RegisterInfo *reg_info =
119-
reg_ctx->GetRegisterInfoByName(reg_name))
120-
value_sp =
121-
ValueObjectRegister::Create(stack_frame, reg_ctx, reg_info);
122-
}
123-
}
124-
}
115+
if (!target || !process)
116+
return nullptr;
117+
118+
StackFrame *stack_frame = ctx_scope->CalculateStackFrame().get();
119+
if (!stack_frame)
120+
return nullptr;
121+
122+
lldb::RegisterContextSP reg_ctx(stack_frame->GetRegisterContext());
123+
if (!reg_ctx)
124+
return nullptr;
125+
126+
if (const RegisterInfo *reg_info =
127+
reg_ctx->GetRegisterInfoByName(reg_name))
128+
value_sp =
129+
ValueObjectRegister::Create(stack_frame, reg_ctx, reg_info);
130+
125131
if (value_sp)
126132
return IdentifierInfo::FromValue(*value_sp);
127133

@@ -211,7 +217,6 @@ LookupIdentifier(const std::string &name,
211217
}
212218
}
213219

214-
// Force static value, otherwise we can end up with the "real" type.
215220
if (value)
216221
return IdentifierInfo::FromValue(*value);
217222

0 commit comments

Comments
 (0)