Skip to content

Commit 2449b6c

Browse files
committed
[lldb] [disassembler] chore: enhance VariableAnnotator to return structured data: remove braces around single line ifs and cycles
Signed-off-by: Nikita B <[email protected]>
1 parent 0331516 commit 2449b6c

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

lldb/source/API/SBInstruction.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,20 @@ SBInstruction::GetVariableAnnotations(lldb::SBTarget target) {
357357

358358
SBStructuredData result;
359359

360-
if (!m_opaque_sp || !m_opaque_sp->IsValid() || !target.IsValid()) {
360+
if (!m_opaque_sp || !m_opaque_sp->IsValid() || !target.IsValid())
361361
return result;
362-
}
363362

364363
lldb::InstructionSP inst_sp = m_opaque_sp->GetSP();
365364
lldb::TargetSP target_sp = target.GetSP();
366365

367-
if (!inst_sp || !target_sp) {
366+
if (!inst_sp || !target_sp)
368367
return result;
369-
}
370368

371369
const Address &addr = inst_sp->GetAddress();
372370
ModuleSP module_sp = addr.GetModule();
373371

374-
if (!module_sp) {
372+
if (!module_sp)
375373
return result;
376-
}
377374

378375
VariableAnnotator annotator;
379376
std::vector<VariableAnnotation> annotations =
@@ -396,17 +393,14 @@ SBInstruction::GetVariableAnnotations(lldb::SBTarget target) {
396393
dict_sp->AddItem(
397394
"register_kind",
398395
std::make_shared<StructuredData::UnsignedInteger>(ann.register_kind));
399-
if (ann.decl_file.has_value()) {
396+
if (ann.decl_file.has_value())
400397
dict_sp->AddStringItem("decl_file", *ann.decl_file);
401-
}
402-
if (ann.decl_line.has_value()) {
398+
if (ann.decl_line.has_value())
403399
dict_sp->AddItem(
404400
"decl_line",
405401
std::make_shared<StructuredData::UnsignedInteger>(*ann.decl_line));
406-
}
407-
if (ann.type_name.has_value()) {
402+
if (ann.type_name.has_value())
408403
dict_sp->AddStringItem("type_name", *ann.type_name);
409-
}
410404

411405
array_sp->AddItem(dict_sp);
412406
}

lldb/source/Core/Disassembler.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,8 @@ VariableAnnotator::annotateStructured(Instruction &inst, Target &target,
330330

331331
// If we lost module context, mark all live variables as undefined.
332332
if (!module_sp) {
333-
for (const auto &KV : Live_) {
333+
for (const auto &KV : Live_)
334334
annotations.push_back(createAnnotation(KV.second, false, kUndefLocation));
335-
}
336335
Live_.clear();
337336
return annotations;
338337
}
@@ -344,9 +343,8 @@ VariableAnnotator::annotateStructured(Instruction &inst, Target &target,
344343
if (!module_sp->ResolveSymbolContextForAddress(iaddr, mask, sc) ||
345344
!sc.function) {
346345
// No function context: everything dies here.
347-
for (const auto &KV : Live_) {
346+
for (const auto &KV : Live_)
348347
annotations.push_back(createAnnotation(KV.second, false, kUndefLocation));
349-
}
350348
Live_.clear();
351349
return annotations;
352350
}
@@ -416,16 +414,13 @@ VariableAnnotator::annotateStructured(Instruction &inst, Target &target,
416414
const Declaration &decl = v->GetDeclaration();
417415
if (decl.GetFile()) {
418416
decl_file = decl.GetFile().GetFilename().AsCString();
419-
if (decl.GetLine() > 0) {
417+
if (decl.GetLine() > 0)
420418
decl_line = decl.GetLine();
421-
}
422419
}
423420

424-
if (Type *type = v->GetType()) {
425-
if (const char *type_str = type->GetName().AsCString()) {
421+
if (Type *type = v->GetType())
422+
if (const char *type_str = type->GetName().AsCString())
426423
type_name = type_str;
427-
}
428-
}
429424

430425
Current.try_emplace(
431426
v->GetID(), VarState{std::string(name), std::string(loc), start_addr,
@@ -449,11 +444,9 @@ VariableAnnotator::annotateStructured(Instruction &inst, Target &target,
449444

450445
// 2) Ends: anything that was live but is not in Current becomes
451446
// <kUndefLocation>.
452-
for (const auto &KV : Live_) {
453-
if (!Current.count(KV.first)) {
447+
for (const auto &KV : Live_)
448+
if (!Current.count(KV.first))
454449
annotations.push_back(createAnnotation(KV.second, false, kUndefLocation));
455-
}
456-
}
457450

458451
// Commit new state.
459452
Live_ = std::move(Current);

0 commit comments

Comments
 (0)