Skip to content

[lldb] Reduce duplication in two of DWARFDIE context functions #122712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,36 @@ lldb_private::Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const {
return nullptr;
}

static CompilerContext GetContextEntry(DWARFDIE die) {
auto ctx = [die](CompilerContextKind kind) {
return CompilerContext(kind, ConstString(die.GetName()));
};

switch (die.Tag()) {
case DW_TAG_module:
return ctx(CompilerContextKind::Module);
case DW_TAG_namespace:
return ctx(CompilerContextKind::Namespace);
case DW_TAG_class_type:
case DW_TAG_structure_type:
return ctx(CompilerContextKind::ClassOrStruct);
case DW_TAG_union_type:
return ctx(CompilerContextKind::Union);
case DW_TAG_enumeration_type:
return ctx(CompilerContextKind::Enum);
case DW_TAG_subprogram:
return ctx(CompilerContextKind::Function);
case DW_TAG_variable:
return ctx(CompilerContextKind::Variable);
case DW_TAG_typedef:
return ctx(CompilerContextKind::Typedef);
case DW_TAG_base_type:
return ctx(CompilerContextKind::Builtin);
default:
llvm_unreachable("Check tag type in the caller!");
}
}

static void GetDeclContextImpl(DWARFDIE die,
llvm::SmallSet<lldb::user_id_t, 4> &seen,
std::vector<CompilerContext> &context) {
Expand All @@ -388,34 +418,17 @@ static void GetDeclContextImpl(DWARFDIE die,
}

// Add this DIE's contribution at the end of the chain.
auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
context.push_back({kind, ConstString(name)});
};
switch (die.Tag()) {
case DW_TAG_module:
push_ctx(CompilerContextKind::Module, die.GetName());
break;
case DW_TAG_namespace:
push_ctx(CompilerContextKind::Namespace, die.GetName());
break;
case DW_TAG_class_type:
case DW_TAG_structure_type:
push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
break;
case DW_TAG_union_type:
push_ctx(CompilerContextKind::Union, die.GetName());
break;
case DW_TAG_enumeration_type:
push_ctx(CompilerContextKind::Enum, die.GetName());
break;
case DW_TAG_subprogram:
push_ctx(CompilerContextKind::Function, die.GetName());
break;
case DW_TAG_variable:
push_ctx(CompilerContextKind::Variable, die.GetName());
break;
case DW_TAG_typedef:
push_ctx(CompilerContextKind::Typedef, die.GetName());
context.push_back(GetContextEntry(die));
break;
default:
break;
Expand All @@ -439,32 +452,18 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
// Stop if we hit a cycle.
while (die && seen.insert(die.GetID()).second) {
// Add this DIE's contribution at the end of the chain.
auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
context.push_back({kind, ConstString(name)});
};
switch (die.Tag()) {
case DW_TAG_namespace:
push_ctx(CompilerContextKind::Namespace, die.GetName());
break;
case DW_TAG_class_type:
case DW_TAG_structure_type:
push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
break;
case DW_TAG_union_type:
push_ctx(CompilerContextKind::Union, die.GetName());
break;
case DW_TAG_enumeration_type:
push_ctx(CompilerContextKind::Enum, die.GetName());
break;
case DW_TAG_variable:
push_ctx(CompilerContextKind::Variable, die.GetName());
break;
case DW_TAG_typedef:
push_ctx(CompilerContextKind::Typedef, die.GetName());
break;
case DW_TAG_base_type:
push_ctx(CompilerContextKind::Builtin, die.GetName());
context.push_back(GetContextEntry(die));
break;

// If any of the tags below appear in the parent chain, stop the decl
// context and return. Prior to these being in here, if a type existed in a
// namespace "a" like "a::my_struct", but we also have a function in that
Expand Down
Loading