[lldb] [NFC] Refactor GetDWARFDeclContext to return DWARFDeclContext

Suggested by Pavel Labath.

Differential Revision: https://reviews.llvm.org/D73787
This commit is contained in:
Jan Kratochvil 2020-02-06 20:04:23 +01:00
parent 31cf581998
commit 1d11d5f624
5 changed files with 41 additions and 37 deletions

View File

@ -726,8 +726,7 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
if (type_sp)
return type_sp;
DWARFDeclContext die_decl_ctx;
SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx);
DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
@ -1515,8 +1514,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
if (type_sp)
return type_sp;
DWARFDeclContext die_decl_ctx;
SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx);
DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
// type_sp = FindDefinitionTypeForDIE (dwarf_cu, die,
// type_name_const_str);
@ -2323,10 +2321,9 @@ Function *DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
unsigned type_quals = 0;
std::vector<CompilerType> param_types;
std::vector<clang::ParmVarDecl *> param_decls;
DWARFDeclContext decl_ctx;
StreamString sstr;
SymbolFileDWARF::GetDWARFDeclContext(die, decl_ctx);
DWARFDeclContext decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
sstr << decl_ctx.GetQualifiedName();
clang::DeclContext *containing_decl_ctx =

View File

@ -868,21 +868,30 @@ void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable(
}
}
void DWARFDebugInfoEntry::GetDWARFDeclContext(
DWARFUnit *cu, DWARFDeclContext &dwarf_decl_ctx) const {
const dw_tag_t tag = Tag();
if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
return;
dwarf_decl_ctx.AppendDeclContext(tag, GetName(cu));
DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(cu);
if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) {
if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit &&
parent_decl_ctx_die.Tag() != DW_TAG_partial_unit)
parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext(
parent_decl_ctx_die.GetCU(), dwarf_decl_ctx);
DWARFDeclContext
DWARFDebugInfoEntry::GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die,
DWARFUnit *cu) {
DWARFDeclContext dwarf_decl_ctx;
for (;;) {
const dw_tag_t tag = die->Tag();
if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
return dwarf_decl_ctx;
dwarf_decl_ctx.AppendDeclContext(tag, die->GetName(cu));
DWARFDIE parent_decl_ctx_die = die->GetParentDeclContextDIE(cu);
if (!parent_decl_ctx_die || parent_decl_ctx_die.GetDIE() == die)
return dwarf_decl_ctx;
if (parent_decl_ctx_die.Tag() == DW_TAG_compile_unit ||
parent_decl_ctx_die.Tag() == DW_TAG_partial_unit)
return dwarf_decl_ctx;
die = parent_decl_ctx_die.GetDIE();
cu = parent_decl_ctx_die.GetCU();
}
}
DWARFDeclContext DWARFDebugInfoEntry::GetDWARFDeclContext(DWARFUnit *cu) const {
return GetDWARFDeclContextStatic(this, cu);
}
DWARFDIE
DWARFDebugInfoEntry::GetParentDeclContextDIE(DWARFUnit *cu) const {
DWARFAttributes attributes;

View File

@ -158,8 +158,7 @@ public:
return HasChildren() ? this + 1 : nullptr;
}
void GetDWARFDeclContext(DWARFUnit *cu,
DWARFDeclContext &dwarf_decl_ctx) const;
DWARFDeclContext GetDWARFDeclContext(DWARFUnit *cu) const;
DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const;
DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu,
@ -169,6 +168,9 @@ public:
void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
protected:
static DWARFDeclContext
GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die, DWARFUnit *cu);
dw_offset_t m_offset; // Offset within the .debug_info/.debug_types
uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
// If zero this die has no parent

View File

@ -2959,8 +2959,8 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(
}
if (try_resolving_type) {
DWARFDeclContext type_dwarf_decl_ctx;
GetDWARFDeclContext(type_die, type_dwarf_decl_ctx);
DWARFDeclContext type_dwarf_decl_ctx =
GetDWARFDeclContext(type_die);
if (log) {
GetObjectFile()->GetModule()->LogMessage(
@ -3377,12 +3377,10 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
// declaration context.
if ((parent_tag == DW_TAG_compile_unit ||
parent_tag == DW_TAG_partial_unit) &&
Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU()))) {
DWARFDeclContext decl_ctx;
GetDWARFDeclContext(die, decl_ctx);
mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
}
Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU())))
mangled = GetDWARFDeclContext(die)
.GetQualifiedNameAsConstString()
.GetCString();
}
if (tag == DW_TAG_formal_parameter)
@ -3984,14 +3982,13 @@ SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) {
return CompilerDeclContext();
}
void SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die,
DWARFDeclContext &dwarf_decl_ctx) {
if (!die.IsValid()) {
dwarf_decl_ctx.Clear();
return;
}
DWARFDeclContext SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die) {
if (!die.IsValid())
return {};
DWARFDeclContext dwarf_decl_ctx =
die.GetDIE()->GetDWARFDeclContext(die.GetCU());
dwarf_decl_ctx.SetLanguage(GetLanguage(*die.GetCU()));
die.GetDIE()->GetDWARFDeclContext(die.GetCU(), dwarf_decl_ctx);
return dwarf_decl_ctx;
}
LanguageType SymbolFileDWARF::LanguageTypeFromDWARF(uint64_t val) {

View File

@ -308,8 +308,7 @@ public:
static lldb_private::CompilerDeclContext
GetContainingDeclContext(const DWARFDIE &die);
static void GetDWARFDeclContext(const DWARFDIE &die,
DWARFDeclContext &dwarf_decl_ctx);
static DWARFDeclContext GetDWARFDeclContext(const DWARFDIE &die);
static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val);