Replace field_is_static with a method

This changes field_is_static to be a method on struct field, and
updates all the callers.  Most of this patch was written by script.

Regression tested on x86-64 Fedora 36.
This commit is contained in:
Tom Tromey 2023-04-22 12:41:43 -06:00
parent 077a1f0848
commit c819a3380f
24 changed files with 55 additions and 57 deletions

View File

@ -1537,7 +1537,7 @@ aapcs_is_vfp_call_or_return_candidate_1 (struct type *type,
for (int i = 0; i < type->num_fields (); i++)
{
/* Ignore any static fields. */
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
struct type *member = check_typedef (type->field (i).type ());
@ -1813,7 +1813,7 @@ pass_in_v_vfp_candidate (struct gdbarch *gdbarch, struct regcache *regcache,
for (int i = 0; i < arg_type->num_fields (); i++)
{
/* Don't include static fields. */
if (field_is_static (&arg_type->field (i)))
if (arg_type->field (i).is_static ())
continue;
struct value *field = arg->primitive_field (0, i, arg_type);

View File

@ -557,7 +557,7 @@ amd64_has_unaligned_fields (struct type *type)
/* Ignore static fields, empty fields (for example nested
empty structures), and bitfields (these are handled by
the caller). */
if (field_is_static (&type->field (i))
if (type->field (i).is_static ()
|| (TYPE_FIELD_BITSIZE (type, i) == 0
&& subtype->length () == 0)
|| TYPE_FIELD_PACKED (type, i))
@ -601,7 +601,7 @@ amd64_classify_aggregate_field (struct type *type, int i,
/* Ignore static fields, or empty fields, for example nested
empty structures.*/
if (field_is_static (&type->field (i)) || bitsize == 0)
if (type->field (i).is_static () || bitsize == 0)
return;
int bitpos = bitoffset + type->field (i).loc_bitpos ();

View File

@ -4524,7 +4524,7 @@ arm_vfp_cprc_sub_candidate (struct type *t,
{
int sub_count = 0;
if (!field_is_static (&t->field (i)))
if (!t->field (i).is_static ())
sub_count = arm_vfp_cprc_sub_candidate (t->field (i).type (),
base_type);
if (sub_count == -1)

View File

@ -210,7 +210,7 @@ gen_trace_static_fields (struct agent_expr *ax,
for (i = type->num_fields () - 1; i >= nbases; i--)
{
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
{
gen_static_field (ax, &value, type, i);
if (value.optimized_out)
@ -1359,7 +1359,7 @@ gen_struct_ref_recursive (struct agent_expr *ax, struct axs_value *value,
"this") will have been generated already, which will
be unnecessary but not harmful if the static field is
being handled as a global. */
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
{
gen_static_field (ax, value, type, i);
if (value->optimized_out)
@ -1495,7 +1495,7 @@ gen_struct_elt_for_reference (struct agent_expr *ax, struct axs_value *value,
if (t_field_name && strcmp (t_field_name, fieldname) == 0)
{
if (field_is_static (&t->field (i)))
if (t->field (i).is_static ())
{
gen_static_field (ax, value, t, i);
if (value->optimized_out)

View File

@ -1113,7 +1113,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
TYPE_FIELD_PRIVATE (type, i), flags);
}
bool is_static = field_is_static (&type->field (i));
bool is_static = type->field (i).is_static ();
if (flags->print_offsets)
podata->update (type, i, stream);

View File

@ -254,7 +254,7 @@ value_struct_element_index (struct value *value, int type_index)
try
{
if (field_is_static (&type->field (type_index)))
if (type->field (type_index).is_static ())
result = value_static_field (type, type_index);
else
result = value->primitive_field (0, type_index, type);

View File

@ -528,7 +528,7 @@ generate_vla_size (compile_instance *compiler,
int i;
for (i = 0; i < type->num_fields (); ++i)
if (!field_is_static (&type->field (i)))
if (!type->field (i).is_static ())
generate_vla_size (compiler, stream, gdbarch, registers_used, pc,
type->field (i).type (), sym);
}

View File

@ -594,7 +594,7 @@ compile_cplus_convert_struct_or_union_members
gcc_type field_type
= instance->convert_type (type->field (i).type ());
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
{
CORE_ADDR physaddr;

View File

@ -193,7 +193,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
/* If requested, skip printing of static fields. */
if (!options->static_field_print
&& field_is_static (&type->field (i)))
&& type->field (i).is_static ())
continue;
if (fields_seen)
@ -227,7 +227,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
annotate_field_begin (type->field (i).type ());
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
{
gdb_puts ("static ", stream);
fprintf_symbol (stream,
@ -258,7 +258,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
}
annotate_field_value ();
if (!field_is_static (&type->field (i))
if (!type->field (i).is_static ()
&& TYPE_FIELD_PACKED (type, i))
{
struct value *v;
@ -295,7 +295,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
fputs_styled ("<optimized out or zero length>",
metadata_style.style (), stream);
}
else if (field_is_static (&type->field (i)))
else if (type->field (i).is_static ())
{
try
{
@ -637,7 +637,7 @@ cp_find_class_member (struct type **self_p, int *fieldno,
for (i = TYPE_N_BASECLASSES (self); i < len; i++)
{
field &f = self->field (i);
if (field_is_static (&f))
if (f.is_static ())
continue;
LONGEST bitpos = f.loc_bitpos ();

View File

@ -2366,7 +2366,7 @@ array_operation::evaluate_struct_tuple (struct value *struct_val,
fieldno++;
/* Skip static fields. */
while (fieldno < struct_type->num_fields ()
&& field_is_static (&struct_type->field (fieldno)))
&& struct_type->field (fieldno).is_static ())
fieldno++;
if (fieldno >= struct_type->num_fields ())
error (_("too many initializers"));

View File

@ -2113,7 +2113,7 @@ is_dynamic_type_internal (struct type *type, int top_level)
for (i = 0; i < type->num_fields (); ++i)
{
/* Static fields can be ignored here. */
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
/* If the field has dynamic type, then so does TYPE. */
if (is_dynamic_type_internal (type->field (i).type (), 0))
@ -2461,7 +2461,7 @@ resolve_dynamic_union (struct type *type,
{
struct type *t;
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
t = resolve_dynamic_type_internal (resolved_type->field (i).type (),
@ -2677,7 +2677,7 @@ resolve_dynamic_struct (struct type *type,
unsigned new_bit_length;
struct property_addr_info pinfo;
if (field_is_static (&resolved_type->field (i)))
if (resolved_type->field (i).is_static ())
continue;
if (resolved_type->field (i).loc_kind () == FIELD_LOC_KIND_DWARF_BLOCK)
@ -3582,7 +3582,7 @@ type_align (struct type *type)
int number_of_non_static_fields = 0;
for (unsigned i = 0; i < type->num_fields (); ++i)
{
if (!field_is_static (&type->field (i)))
if (!type->field (i).is_static ())
{
number_of_non_static_fields++;
ULONGEST f_align = type_align (type->field (i).type ());
@ -4941,18 +4941,6 @@ print_args (struct field *args, int nargs, int spaces)
}
}
int
field_is_static (struct field *f)
{
/* "static" fields are the fields whose location is not relative
to the address of the enclosing struct. It would be nice to
have a dedicated flag that would be set for static fields when
the type is being created. But in practice, checking the field
loc_kind should give us an accurate answer. */
return (f->loc_kind () == FIELD_LOC_KIND_PHYSNAME
|| f->loc_kind () == FIELD_LOC_KIND_PHYSADDR);
}
static void
dump_fn_fieldlists (struct type *type, int spaces)
{

View File

@ -559,6 +559,18 @@ struct field
m_name = name;
}
/* Return true if this field is static; false if not. */
bool is_static () const
{
/* "static" fields are the fields whose location is not relative
to the address of the enclosing struct. It would be nice to
have a dedicated flag that would be set for static fields when
the type is being created. But in practice, checking the field
loc_kind should give us an accurate answer. */
return (m_loc_kind == FIELD_LOC_KIND_PHYSNAME
|| m_loc_kind == FIELD_LOC_KIND_PHYSADDR);
}
/* Location getters / setters. */
field_loc_kind loc_kind () const
@ -2686,8 +2698,6 @@ extern struct rank rank_one_type (struct type *, struct type *,
extern void recursive_dump_type (struct type *, int);
extern int field_is_static (struct field *);
/* printcmd.c */
extern void print_scalar_formatted (const gdb_byte *, struct type *,

View File

@ -1536,7 +1536,7 @@ gnuv3_pass_by_reference (struct type *type)
about recursive loops here, since we are only looking at members
of complete class type. Also ignore any static members. */
for (fieldnum = 0; fieldnum < type->num_fields (); fieldnum++)
if (!field_is_static (&type->field (fieldnum)))
if (!type->field (fieldnum).is_static ())
{
struct type *field_type = type->field (fieldnum).type ();

View File

@ -2698,7 +2698,7 @@ i386_16_byte_align_p (struct type *type)
int i;
for (i = 0; i < type->num_fields (); i++)
{
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
if (i386_16_byte_align_p (type->field (i).type ()))
return 1;

View File

@ -521,7 +521,7 @@ compute_struct_member (struct type *type,
for (int i = 0; i < type->num_fields (); i++)
{
/* Ignore any static fields. */
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
struct type *field_type = check_typedef (type->field (i).type ());

View File

@ -4886,7 +4886,7 @@ mips_n32n64_fp_arg_chunk_p (struct gdbarch *gdbarch, struct type *arg_type,
struct type *field_type;
/* We're only looking at normal fields. */
if (field_is_static (&arg_type->field (i))
if (arg_type->field (i).is_static ()
|| (arg_type->field (i).loc_bitpos () % 8) != 0)
continue;

View File

@ -516,12 +516,12 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
}
print_spaces (level + 4, stream);
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
gdb_printf (stream, "static ");
print_type (type->field (i).type (),
type->field (i).name (),
stream, show - 1, level + 4, flags);
if (!field_is_static (&type->field (i))
if (!type->field (i).is_static ()
&& TYPE_FIELD_PACKED (type, i))
{
/* It is a bitfield. This code does not attempt

View File

@ -553,7 +553,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
{
/* If requested, skip printing of static fields. */
if (!options->pascal_static_field_print
&& field_is_static (&type->field (i)))
&& type->field (i).is_static ())
continue;
if (fields_seen)
gdb_printf (stream, ", ");
@ -582,7 +582,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
annotate_field_begin (type->field (i).type ());
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
{
gdb_puts ("static ", stream);
fprintf_symbol (stream,
@ -597,7 +597,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
gdb_puts (" = ", stream);
annotate_field_value ();
if (!field_is_static (&type->field (i))
if (!type->field (i).is_static ()
&& TYPE_FIELD_PACKED (type, i))
{
struct value *v;
@ -634,7 +634,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
fputs_styled ("<optimized out or zero length>",
metadata_style.style (), stream);
}
else if (field_is_static (&type->field (i)))
else if (type->field (i).is_static ())
{
/* struct value *v = value_static_field (type, i);
v4.17 specific. */

View File

@ -1149,7 +1149,7 @@ ppc64_aggregate_candidate (struct type *type,
{
LONGEST sub_count;
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
sub_count = ppc64_aggregate_candidate

View File

@ -154,7 +154,7 @@ convert_field (struct type *type, int field)
if (PyObject_SetAttrString (result.get (), "parent_type", arg.get ()) < 0)
return NULL;
if (!field_is_static (&type->field (field)))
if (!type->field (field).is_static ())
{
const char *attrstring;

View File

@ -130,7 +130,7 @@ rust_underscore_fields (struct type *type)
return false;
for (i = 0; i < type->num_fields (); ++i)
{
if (!field_is_static (&type->field (i)))
if (!type->field (i).is_static ())
{
char buf[20];
@ -403,7 +403,7 @@ rust_language::val_print_struct
first_field = 1;
for (i = 0; i < type->num_fields (); ++i)
{
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
if (!first_field)
@ -723,7 +723,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
std::vector<int> fields;
for (int i = 0; i < type->num_fields (); ++i)
{
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
continue;
if (is_enum && TYPE_FIELD_ARTIFICIAL (type, i))
continue;
@ -741,7 +741,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
{
QUIT;
gdb_assert (!field_is_static (&type->field (i)));
gdb_assert (!type->field (i).is_static ());
gdb_assert (! (is_enum && TYPE_FIELD_ARTIFICIAL (type, i)));
if (flags->print_offsets)

View File

@ -1648,7 +1648,7 @@ s390_effective_inner_type (struct type *type, unsigned int min_size)
{
struct field f = type->field (i);
if (field_is_static (&f))
if (f.is_static ())
continue;
if (inner != NULL)
return type;

View File

@ -125,7 +125,7 @@ void
print_offset_data::update (struct type *type, unsigned int field_idx,
struct ui_file *stream)
{
if (field_is_static (&type->field (field_idx)))
if (type->field (field_idx).is_static ())
{
print_spaces (indentation, stream);
return;

View File

@ -2017,7 +2017,7 @@ struct_field_searcher::search (struct value *arg1, LONGEST offset,
{
struct value *v;
if (field_is_static (&type->field (i)))
if (type->field (i).is_static ())
v = value_static_field (type, i);
else
v = arg1->primitive_field (offset, i, type);
@ -2462,7 +2462,7 @@ value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
for (i = TYPE_N_BASECLASSES (t); i < t->num_fields (); i++)
{
if (!field_is_static (&t->field (i))
if (!t->field (i).is_static ()
&& bitpos == t->field (i).loc_bitpos ()
&& types_equal (ftype, t->field (i).type ()))
return (*argp)->primitive_field (0, i, t);
@ -3581,7 +3581,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
if (t_field_name && strcmp (t_field_name, name) == 0)
{
if (field_is_static (&t->field (i)))
if (t->field (i).is_static ())
{
struct value *v = value_static_field (t, i);
if (want_address)