Skip to content

Commit 23fd8f6

Browse files
authored
[lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (#123790)
This patch refactors `ParseChildParameters` in a way which makes it (in my opinion) more readable, removing some redundant local variables in the process and reduces the scope of some variables. **Motivation** Since `DW_AT_object_pointer`s are now attached to declarations, we can test for their existence to check whether a C++ method is static or not (whereas currently we're deducing this from `ParseChildParameters` based on some heuristics we know are true for most compilers). So my plan is to move the code for determining `type_quals` and `is_static` out of `ParseChildParameters`. The refactoring in this PR will make this follow-up patch hopefully easier to review. **Testing** * This should be NFC. The main change is that we now no longer iterate over `GetAttributes()` but instead retrieve the name, type and is_artificial attributes of the parameters individually.
1 parent 2ee36d4 commit 23fd8f6

File tree

1 file changed

+13
-56
lines changed

1 file changed

+13
-56
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,50 +3084,10 @@ size_t DWARFASTParserClang::ParseChildParameters(
30843084
const dw_tag_t tag = die.Tag();
30853085
switch (tag) {
30863086
case DW_TAG_formal_parameter: {
3087-
DWARFAttributes attributes = die.GetAttributes();
3088-
if (attributes.Size() == 0) {
3089-
arg_idx++;
3090-
break;
3091-
}
3092-
3093-
const char *name = nullptr;
3094-
DWARFFormValue param_type_die_form;
3095-
bool is_artificial = false;
3096-
// one of None, Auto, Register, Extern, Static, PrivateExtern
3097-
3098-
clang::StorageClass storage = clang::SC_None;
3099-
uint32_t i;
3100-
for (i = 0; i < attributes.Size(); ++i) {
3101-
const dw_attr_t attr = attributes.AttributeAtIndex(i);
3102-
DWARFFormValue form_value;
3103-
if (attributes.ExtractFormValueAtIndex(i, form_value)) {
3104-
switch (attr) {
3105-
case DW_AT_name:
3106-
name = form_value.AsCString();
3107-
break;
3108-
case DW_AT_type:
3109-
param_type_die_form = form_value;
3110-
break;
3111-
case DW_AT_artificial:
3112-
is_artificial = form_value.Boolean();
3113-
break;
3114-
case DW_AT_location:
3115-
case DW_AT_const_value:
3116-
case DW_AT_default_value:
3117-
case DW_AT_description:
3118-
case DW_AT_endianity:
3119-
case DW_AT_is_optional:
3120-
case DW_AT_segment:
3121-
case DW_AT_variable_parameter:
3122-
default:
3123-
case DW_AT_abstract_origin:
3124-
case DW_AT_sibling:
3125-
break;
3126-
}
3127-
}
3128-
}
3087+
const char *name = die.GetName();
3088+
DWARFDIE param_type_die = die.GetAttributeValueAsReferenceDIE(DW_AT_type);
31293089

3130-
if (is_artificial) {
3090+
if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) {
31313091
// In order to determine if a C++ member function is "const" we
31323092
// have to look at the const-ness of "this"...
31333093
if (arg_idx == 0 &&
@@ -3136,8 +3096,7 @@ size_t DWARFASTParserClang::ParseChildParameters(
31363096
// specification DIEs, so we can't rely upon the name being in
31373097
// the formal parameter DIE...
31383098
(name == nullptr || ::strcmp(name, "this") == 0)) {
3139-
Type *this_type = die.ResolveTypeUID(param_type_die_form.Reference());
3140-
if (this_type) {
3099+
if (Type *this_type = die.ResolveTypeUID(param_type_die)) {
31413100
uint32_t encoding_mask = this_type->GetEncodingMask();
31423101
if (encoding_mask & Type::eEncodingIsPointerUID) {
31433102
is_static = false;
@@ -3149,20 +3108,18 @@ size_t DWARFASTParserClang::ParseChildParameters(
31493108
}
31503109
}
31513110
}
3152-
} else {
3153-
Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
3154-
if (type) {
3155-
function_param_types.push_back(type->GetForwardCompilerType());
3111+
} else if (Type *type = die.ResolveTypeUID(param_type_die)) {
3112+
function_param_types.push_back(type->GetForwardCompilerType());
31563113

3157-
clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration(
3158-
containing_decl_ctx, GetOwningClangModule(die), name,
3159-
type->GetForwardCompilerType(), storage);
3160-
assert(param_var_decl);
3161-
function_param_decls.push_back(param_var_decl);
3114+
clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration(
3115+
containing_decl_ctx, GetOwningClangModule(die), name,
3116+
type->GetForwardCompilerType(), clang::StorageClass::SC_None);
3117+
assert(param_var_decl);
3118+
function_param_decls.push_back(param_var_decl);
31623119

3163-
m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
3164-
}
3120+
m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
31653121
}
3122+
31663123
arg_idx++;
31673124
} break;
31683125

0 commit comments

Comments
 (0)