gdb: add field::name / field::set_name

Add the `name` and `set_name` methods on `struct field`, in order to
remove `FIELD_NAME` and `TYPE_FIELD_NAME` macros.  In this patch, the
macros are changed to use `field::name`, so all the call sites that are
used to set the field's name are changed to use `field::set_name`.
The next patch will remove the macros completely.

Note that because of the name clash between the existing field named
`name` and the new method, I renamed the field `m_name`.  It is not
private per-se, because we can't make `struct field` a non-POD yet, but
it should be considered private anyway (not accessed outside `struct
field`).

Change-Id: If16ddbca4e0c39d0ff9da420bb5cdebe5b9b0896
This commit is contained in:
Simon Marchi 2021-08-30 11:49:48 -04:00
parent cdfbeec413
commit d3fd12dfc5
11 changed files with 71 additions and 59 deletions

View file

@ -4876,8 +4876,9 @@ print_args (struct field *args, int nargs, int spaces)
for (i = 0; i < nargs; i++)
{
printf_filtered ("%*s[%d] name '%s'\n", spaces, "", i,
args[i].name != NULL ? args[i].name : "<NULL>");
printf_filtered
("%*s[%d] name '%s'\n", spaces, "", i,
args[i].name () != NULL ? args[i].name () : "<NULL>");
recursive_dump_type (args[i].type (), spaces + 2);
}
}
@ -5558,8 +5559,7 @@ copy_type_recursive (struct objfile *objfile,
(copy_type_recursive (objfile, type->field (i).type (),
copied_types));
if (TYPE_FIELD_NAME (type, i))
TYPE_FIELD_NAME (new_type, i) =
xstrdup (TYPE_FIELD_NAME (type, i));
new_type->field (i).set_name (xstrdup (TYPE_FIELD_NAME (type, i)));
switch (TYPE_FIELD_LOC_KIND (type, i))
{
case FIELD_LOC_KIND_BITPOS:
@ -5846,7 +5846,7 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
gdb_assert (nr_bits >= 1 && (start_bitpos + nr_bits) <= type_bitsize);
gdb_assert (name != NULL);
TYPE_FIELD_NAME (type, field_nr) = xstrdup (name);
type->field (field_nr).set_name (xstrdup (name));
type->field (field_nr).set_type (field_type);
SET_FIELD_BITPOS (type->field (field_nr), start_bitpos);
TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
@ -5897,7 +5897,7 @@ append_composite_type_field_raw (struct type *t, const char *name,
f = &t->field (t->num_fields () - 1);
memset (f, 0, sizeof f[0]);
f[0].set_type (field);
FIELD_NAME (f[0]) = name;
f[0].set_name (name);
return f;
}