aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2025-08-01 11:11:41 -0600
committerTom Tromey <tromey@adacore.com>2025-08-12 08:30:37 -0600
commit89495c33260b3f637acb8f79181cc6db08771f90 (patch)
tree525da36fc4d6846f8b8b34ae12c449b414d38dbc
parent55c91b7e5c7f7829ff69738f159e0380383a7356 (diff)
downloadbinutils-89495c33260b3f637acb8f79181cc6db08771f90.zip
binutils-89495c33260b3f637acb8f79181cc6db08771f90.tar.gz
binutils-89495c33260b3f637acb8f79181cc6db08771f90.tar.bz2
Change type::fields to return an array_view
This patch changes type::fields to return an array_view of the fields, then fixes up the fallout. More cleanups would be possible here (in particular in the field initialization code) but I haven't done so. The main motivation for this patch was to make it simpler to iterate over the fields of a type. Regression tested on x86-64 Fedora 41. Approved-By: Simon Marchi <simon.marchi@efficios.com>
-rw-r--r--gdb/ada-lang.c37
-rw-r--r--gdb/amd64-tdep.c13
-rw-r--r--gdb/c-typeprint.c11
-rw-r--r--gdb/dwarf2/read.c24
-rw-r--r--gdb/eval.c2
-rw-r--r--gdb/f-typeprint.c11
-rw-r--r--gdb/gdbtypes.c90
-rw-r--r--gdb/gdbtypes.h18
-rw-r--r--gdb/guile/scm-type.c2
-rw-r--r--gdb/mdebugread.c2
-rw-r--r--gdb/python/py-type.c11
-rw-r--r--gdb/rust-lang.c16
-rw-r--r--gdb/stabsread.c5
-rw-r--r--gdb/valops.c12
14 files changed, 115 insertions, 139 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 329d114..1955169 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1677,8 +1677,6 @@ ada_decode_symbol (const struct general_symbol_info *arg)
void
ada_fixup_array_indexes_type (struct type *index_desc_type)
{
- int i;
-
if (index_desc_type == NULL)
return;
gdb_assert (index_desc_type->num_fields () > 0);
@@ -1696,13 +1694,13 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
return;
/* Fixup each field of INDEX_DESC_TYPE. */
- for (i = 0; i < index_desc_type->num_fields (); i++)
+ for (auto &field : index_desc_type->fields ())
{
- const char *name = index_desc_type->field (i).name ();
+ const char *name = field.name ();
struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
if (raw_type)
- index_desc_type->field (i).set_type (raw_type);
+ field.set_type (raw_type);
}
}
@@ -7080,17 +7078,16 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
else if (ada_is_variant_part (type, i))
{
/* PNH: Do we ever get here? See find_struct_field. */
- int j;
struct type *field_type = ada_check_typedef (type->field (i).type ());
int var_offset = offset + type->field (i).loc_bitpos () / 8;
- for (j = 0; j < field_type->num_fields (); j += 1)
+ for (const auto &field : field_type->fields ())
{
- struct value *v = ada_search_struct_field /* Force line
- break. */
- (name, arg,
- var_offset + field_type->field (j).loc_bitpos () / 8,
- field_type->field (j).type ());
+ struct value *v
+ = (ada_search_struct_field
+ (name, arg,
+ var_offset + field.loc_bitpos () / 8,
+ field.type ()));
if (v != NULL)
return v;
@@ -8182,12 +8179,11 @@ ada_is_redundant_index_type_desc (struct type *array_type,
struct type *desc_type)
{
struct type *this_layer = check_typedef (array_type);
- int i;
- for (i = 0; i < desc_type->num_fields (); i++)
+ for (const auto &field : desc_type->fields ())
{
if (!ada_is_redundant_range_encoding (this_layer->index_type (),
- desc_type->field (i).type ()))
+ field.type ()))
return 0;
this_layer = check_typedef (this_layer->target_type ());
}
@@ -8784,9 +8780,9 @@ ada_atr_enum_val (struct expression *exp, enum noside noside, struct type *type,
error (_("'Enum_Val requires integral argument"));
LONGEST value = value_as_long (arg);
- for (int i = 0; i < type->num_fields (); ++i)
+ for (const auto &field : type->fields ())
{
- if (type->field (i).loc_enumval () == value)
+ if (field.loc_enumval () == value)
return value_from_longest (original_type, value);
}
@@ -10502,7 +10498,6 @@ static LONGEST
convert_char_literal (struct type *type, LONGEST val)
{
char name[12];
- int f;
if (type == NULL)
return val;
@@ -10519,17 +10514,17 @@ convert_char_literal (struct type *type, LONGEST val)
else
xsnprintf (name, sizeof (name), "QWW%08lx", (unsigned long) val);
size_t len = strlen (name);
- for (f = 0; f < type->num_fields (); f += 1)
+ for (const auto &field : type->fields ())
{
/* Check the suffix because an enum constant in a package will
have a name like "pkg__QUxx". This is safe enough because we
already have the correct type, and because mangling means
there can't be clashes. */
- const char *ename = type->field (f).name ();
+ const char *ename = field.name ();
size_t elen = strlen (ename);
if (elen >= len && strcmp (name, ename + elen - len) == 0)
- return type->field (f).loc_enumval ();
+ return field.loc_enumval ();
}
return val;
}
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 82dd1e0..d5ea4af 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -513,20 +513,19 @@ amd64_has_unaligned_fields (struct type *type)
if (type->code () == TYPE_CODE_STRUCT
|| type->code () == TYPE_CODE_UNION)
{
- for (int i = 0; i < type->num_fields (); i++)
+ for (const auto &field : type->fields ())
{
- struct type *subtype = check_typedef (type->field (i).type ());
+ struct type *subtype = check_typedef (field.type ());
/* Ignore static fields, empty fields (for example nested
empty structures), and bitfields (these are handled by
the caller). */
- if (type->field (i).is_static ()
- || (type->field (i).bitsize () == 0
- && subtype->length () == 0)
- || type->field (i).is_packed ())
+ if (field.is_static ()
+ || (field.bitsize () == 0 && subtype->length () == 0)
+ || field.is_packed ())
continue;
- int bitpos = type->field (i).loc_bitpos ();
+ int bitpos = field.loc_bitpos ();
if (bitpos % 8 != 0)
return true;
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index df7bdbe..b6b3f6b 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -251,8 +251,8 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
enum language language,
const struct type_print_options *flags)
{
- struct field *args = mtype->fields ();
- int nargs = mtype->num_fields ();
+ auto args = mtype->fields ();
+ int nargs = args.size ();
int varargs = mtype->has_varargs ();
int i;
@@ -515,16 +515,15 @@ c_type_print_args (struct type *type, struct ui_file *stream,
int linkage_name, enum language language,
const struct type_print_options *flags)
{
- int i;
int printed_any = 0;
gdb_printf (stream, "(");
- for (i = 0; i < type->num_fields (); i++)
+ for (const auto &field : type->fields ())
{
struct type *param_type;
- if (type->field (i).is_artificial () && linkage_name)
+ if (field.is_artificial () && linkage_name)
continue;
if (printed_any)
@@ -533,7 +532,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
stream->wrap_here (4);
}
- param_type = type->field (i).type ();
+ param_type = field.type ();
if (language == language_cplus && linkage_name)
{
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ec8d376..c37da59 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -4504,9 +4504,9 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
else
{
struct type *disr_type = nullptr;
- for (int i = 0; i < type->num_fields (); ++i)
+ for (const auto &field : type->fields ())
{
- disr_type = type->field (i).type ();
+ disr_type = field.type ();
if (disr_type->code () != TYPE_CODE_STRUCT)
{
@@ -4545,7 +4545,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
field *new_fields
= (struct field *) TYPE_ZALLOC (type, ((type->num_fields () + 1)
* sizeof (struct field)));
- memcpy (new_fields + 1, type->fields (),
+ memcpy (new_fields + 1, type->fields ().data (),
type->num_fields () * sizeof (struct field));
type->set_fields (new_fields);
type->set_num_fields (type->num_fields () + 1);
@@ -4559,13 +4559,12 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
variant name. For convenience we build a map here. */
struct type *enum_type = disr_field->type ();
gdb::unordered_map<std::string_view, ULONGEST> discriminant_map;
- for (int i = 0; i < enum_type->num_fields (); ++i)
+ for (const auto &field : enum_type->fields ())
{
- if (enum_type->field (i).loc_kind () == FIELD_LOC_KIND_ENUMVAL)
+ if (field.loc_kind () == FIELD_LOC_KIND_ENUMVAL)
{
- const char *name
- = rust_last_path_segment (enum_type->field (i).name ());
- discriminant_map[name] = enum_type->field (i).loc_enumval ();
+ const char *name = rust_last_path_segment (field.name ());
+ discriminant_map[name] = field.loc_enumval ();
}
}
@@ -4601,7 +4600,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
if (sub_type->num_fields () > 0)
{
sub_type->set_num_fields (sub_type->num_fields () - 1);
- sub_type->set_fields (sub_type->fields () + 1);
+ sub_type->set_fields (sub_type->fields ().data () + 1);
}
type->field (i).set_name (variant_name);
sub_type->set_name
@@ -10629,7 +10628,6 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
smash_to_method_type (fnp->type, type,
this_type->target_type (),
this_type->fields (),
- this_type->num_fields (),
this_type->has_varargs ());
/* Handle static member functions.
@@ -10851,8 +10849,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
self_type = pfn_type->field (0).type ()->target_type ();
new_type = type_allocator (type).new_type ();
smash_to_method_type (new_type, self_type, pfn_type->target_type (),
- pfn_type->fields (), pfn_type->num_fields (),
- pfn_type->has_varargs ());
+ pfn_type->fields (), pfn_type->has_varargs ());
smash_to_methodptr_type (type, new_type);
}
@@ -12773,8 +12770,7 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
= type_allocator (cu->per_objfile->objfile, cu->lang ()).new_type ();
smash_to_method_type (new_type, domain, to_type->target_type (),
- to_type->fields (), to_type->num_fields (),
- to_type->has_varargs ());
+ to_type->fields (), to_type->has_varargs ());
type = lookup_methodptr_type (new_type);
}
else
diff --git a/gdb/eval.c b/gdb/eval.c
index 539b700..6227a26 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -492,7 +492,7 @@ fake_method::fake_method (type_instance_flags flags,
fake_method::~fake_method ()
{
- xfree (m_type.fields ());
+ xfree (m_type.fields ().data ());
}
namespace expr
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 7d0cdc0..e96d27c 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -299,8 +299,6 @@ void
f_language::f_type_print_base (struct type *type, struct ui_file *stream,
int show, int level) const
{
- int index;
-
QUIT;
stream->wrap_here (4);
@@ -423,14 +421,13 @@ f_language::f_type_print_base (struct type *type, struct ui_file *stream,
if (show > 0)
{
gdb_puts ("\n", stream);
- for (index = 0; index < type->num_fields (); index++)
+ for (const auto &field : type->fields ())
{
- f_type_print_base (type->field (index).type (), stream,
- show - 1, level + 4);
+ f_type_print_base (field.type (), stream, show - 1, level + 4);
gdb_puts (" :: ", stream);
- fputs_styled (type->field (index).name (),
+ fputs_styled (field.name (),
variable_name_style.style (), stream);
- f_type_print_varspec_suffix (type->field (index).type (),
+ f_type_print_varspec_suffix (field.type (),
stream, show - 1, 0, 0, 0, false);
gdb_puts ("\n", stream);
}
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 14a903b..24e6d0b 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1080,10 +1080,10 @@ get_discrete_low_bound (struct type *type)
entries. */
LONGEST low = type->field (0).loc_enumval ();
- for (int i = 0; i < type->num_fields (); i++)
+ for (const auto &field : type->fields ())
{
- if (type->field (i).loc_enumval () < low)
- low = type->field (i).loc_enumval ();
+ if (field.loc_enumval () < low)
+ low = field.loc_enumval ();
}
return low;
@@ -1147,10 +1147,10 @@ get_discrete_high_bound (struct type *type)
entries. */
LONGEST high = type->field (0).loc_enumval ();
- for (int i = 0; i < type->num_fields (); i++)
+ for (const auto &field : type->fields ())
{
- if (type->field (i).loc_enumval () > high)
- high = type->field (i).loc_enumval ();
+ if (field.loc_enumval () > high)
+ high = field.loc_enumval ();
}
return high;
@@ -1602,15 +1602,15 @@ smash_to_methodptr_type (struct type *type, struct type *to_type)
void
smash_to_method_type (struct type *type, struct type *self_type,
- struct type *to_type, struct field *args,
- int nargs, int varargs)
+ struct type *to_type, gdb::array_view<struct field> args,
+ int varargs)
{
smash_type (type);
type->set_code (TYPE_CODE_METHOD);
type->set_target_type (to_type);
set_type_self_type (type, self_type);
- type->set_fields (args);
- type->set_num_fields (nargs);
+ type->set_fields (args.data ());
+ type->set_num_fields (args.size ());
if (varargs)
type->set_has_varargs (true);
@@ -2494,23 +2494,22 @@ resolve_dynamic_union (struct type *type,
const frame_info_ptr &frame)
{
struct type *resolved_type;
- int i;
unsigned int max_len = 0;
gdb_assert (type->code () == TYPE_CODE_UNION);
resolved_type = copy_type (type);
resolved_type->copy_fields (type);
- for (i = 0; i < resolved_type->num_fields (); ++i)
+ for (auto &field : resolved_type->fields ())
{
struct type *t;
- if (type->field (i).is_static ())
+ if (field.is_static ())
continue;
- t = resolve_dynamic_type_internal (resolved_type->field (i).type (),
- addr_stack, frame, false);
- resolved_type->field (i).set_type (t);
+ t = resolve_dynamic_type_internal (field.type (), addr_stack,
+ frame, false);
+ field.set_type (t);
struct type *real_type = check_typedef (t);
if (real_type->length () > max_len)
@@ -2791,7 +2790,6 @@ resolve_dynamic_struct (struct type *type,
const frame_info_ptr &frame)
{
struct type *resolved_type;
- int i;
unsigned resolved_type_bit_length = 0;
gdb_assert (type->code () == TYPE_CODE_STRUCT);
@@ -2812,22 +2810,21 @@ resolve_dynamic_struct (struct type *type,
resolved_type->copy_fields (type);
}
- for (i = 0; i < resolved_type->num_fields (); ++i)
+ for (auto &field : resolved_type->fields ())
{
unsigned new_bit_length;
- if (resolved_type->field (i).is_static ())
+ if (field.is_static ())
continue;
- resolve_dynamic_field (resolved_type->field (i), addr_stack, frame);
+ resolve_dynamic_field (field, addr_stack, frame);
- new_bit_length = resolved_type->field (i).loc_bitpos ();
- if (resolved_type->field (i).bitsize () != 0)
- new_bit_length += resolved_type->field (i).bitsize ();
+ new_bit_length = field.loc_bitpos ();
+ if (field.bitsize () != 0)
+ new_bit_length += field.bitsize ();
else
{
- struct type *real_type
- = check_typedef (resolved_type->field (i).type ());
+ struct type *real_type = check_typedef (field.type ());
new_bit_length += (real_type->length () * TARGET_CHAR_BIT);
}
@@ -3394,7 +3391,8 @@ check_stub_method (struct type *type, int method_id, int signature_id)
/* MTYPE may currently be a function (TYPE_CODE_FUNC).
We want a method (TYPE_CODE_METHOD). */
smash_to_method_type (mtype, type, mtype->target_type (),
- argtypes, argcount, p[-2] == '.');
+ gdb::make_array_view (argtypes, argcount),
+ p[-2] == '.');
mtype->set_is_stub (false);
TYPE_FN_FIELD_STUB (f, signature_id) = 0;
}
@@ -3698,12 +3696,12 @@ type_align (struct type *type)
case TYPE_CODE_UNION:
{
int number_of_non_static_fields = 0;
- for (unsigned i = 0; i < type->num_fields (); ++i)
+ for (const auto &field : type->fields ())
{
- if (!type->field (i).is_static ())
+ if (!field.is_static ())
{
number_of_non_static_fields++;
- ULONGEST f_align = type_align (type->field (i).type ());
+ ULONGEST f_align = type_align (field.type ());
if (f_align == 0)
{
/* Don't pretend we know something we don't. */
@@ -5038,19 +5036,14 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
situation. */
static void
-print_args (struct field *args, int nargs, int spaces)
+print_args (gdb::array_view<struct field> args, int spaces)
{
- if (args != NULL)
+ for (int i = 0; i < args.size (); i++)
{
- int i;
-
- for (i = 0; i < nargs; i++)
- {
- gdb_printf
- ("%*s[%d] name '%s'\n", spaces, "", i,
- args[i].name () != NULL ? args[i].name () : "<NULL>");
- recursive_dump_type (args[i].type (), spaces + 2);
- }
+ gdb_printf
+ ("%*s[%d] name '%s'\n", spaces, "", i,
+ args[i].name () != NULL ? args[i].name () : "<NULL>");
+ recursive_dump_type (args[i].type (), spaces + 2);
}
}
@@ -5091,9 +5084,8 @@ dump_fn_fieldlists (struct type *type, int spaces)
gdb_printf
("%*sargs %s\n", spaces + 8, "",
- host_address_to_string (TYPE_FN_FIELD_ARGS (f, overload_idx)));
+ host_address_to_string (TYPE_FN_FIELD_ARGS (f, overload_idx).data ()));
print_args (TYPE_FN_FIELD_ARGS (f, overload_idx),
- TYPE_FN_FIELD_TYPE (f, overload_idx)->num_fields (),
spaces + 8 + 2);
gdb_printf
("%*sfcontext %s\n", spaces + 8, "",
@@ -5375,7 +5367,7 @@ recursive_dump_type (struct type *type, int spaces)
}
gdb_printf ("\n");
}
- gdb_printf ("%s\n", host_address_to_string (type->fields ()));
+ gdb_printf ("%s\n", host_address_to_string (type->fields ().data ()));
for (idx = 0; idx < type->num_fields (); idx++)
{
field &fld = type->field (idx);
@@ -5756,7 +5748,7 @@ append_composite_type_field_raw (struct type *t, const char *name,
struct field *f;
t->set_num_fields (t->num_fields () + 1);
- t->set_fields (XRESIZEVEC (struct field, t->fields (),
+ t->set_fields (XRESIZEVEC (struct field, t->fields ().data (),
t->num_fields ()));
f = &t->field (t->num_fields () - 1);
memset (f, 0, sizeof f[0]);
@@ -5907,7 +5899,7 @@ type::alloc_fields (unsigned int nfields, bool init)
return;
}
- size_t size = nfields * sizeof (*this->fields ());
+ size_t size = nfields * sizeof (struct field);
struct field *fields
= (struct field *) (init
? TYPE_ZALLOC (this, size)
@@ -5926,8 +5918,8 @@ type::copy_fields (struct type *src)
if (nfields == 0)
return;
- size_t size = nfields * sizeof (*this->fields ());
- memcpy (this->fields (), src->fields (), size);
+ size_t size = nfields * sizeof (struct field);
+ memcpy (this->fields ().data (), src->fields ().data (), size);
}
/* See gdbtypes.h. */
@@ -5940,8 +5932,8 @@ type::copy_fields (std::vector<struct field> &src)
if (nfields == 0)
return;
- size_t size = nfields * sizeof (*this->fields ());
- memcpy (this->fields (), src.data (), size);
+ size_t size = nfields * sizeof (struct field);
+ memcpy (this->fields ().data (), src.data (), size);
}
/* See gdbtypes.h. */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 9e2efe9..75c77b3 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1080,12 +1080,6 @@ struct type
this->main_type->m_nfields = num_fields;
}
- /* Get the fields array of this type. */
- struct field *fields () const
- {
- return this->main_type->flds_bnds.fields;
- }
-
/* Get the field at index IDX. */
struct field &field (int idx) const
{
@@ -1093,6 +1087,13 @@ struct type
return this->fields ()[idx];
}
+ /* Return an array view of the fields. */
+ gdb::array_view<struct field> fields () const
+ {
+ return gdb::make_array_view (this->main_type->flds_bnds.fields,
+ num_fields ());
+ }
+
/* Set the fields array of this type. */
void set_fields (struct field *fields)
{
@@ -2470,8 +2471,9 @@ extern struct type *lookup_memberptr_type (struct type *, struct type *);
extern struct type *lookup_methodptr_type (struct type *);
extern void smash_to_method_type (struct type *type, struct type *self_type,
- struct type *to_type, struct field *args,
- int nargs, int varargs);
+ struct type *to_type,
+ gdb::array_view<struct field> args,
+ int varargs);
extern void smash_to_memberptr_type (struct type *, struct type *,
struct type *);
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 5114579..13676ce 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -510,7 +510,7 @@ tyscm_field_smob_to_field (field_smob *f_smob)
struct type *type = tyscm_field_smob_containing_type (f_smob);
/* This should be non-NULL by construction. */
- gdb_assert (type->fields () != NULL);
+ gdb_assert (type->fields ().data () != nullptr);
return &type->field (f_smob->field_num);
}
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 5bb15c2..b9302c5 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1034,7 +1034,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
t->set_code (type_code);
t->set_length (sh->value);
t->alloc_fields (nfields);
- f = t->fields();
+ f = t->fields ().data ();
if (type_code == TYPE_CODE_ENUM)
{
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index c546aa7..10ae636 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1312,10 +1312,9 @@ static PyObject *
typy_has_key (PyObject *self, PyObject *args)
{
struct type *type = ((type_object *) self)->type;
- const char *field;
- int i;
+ const char *field_name;
- if (!PyArg_ParseTuple (args, "s", &field))
+ if (!PyArg_ParseTuple (args, "s", &field_name))
return NULL;
/* We want just fields of this type, not of base types, so instead of
@@ -1326,11 +1325,11 @@ typy_has_key (PyObject *self, PyObject *args)
if (type == NULL)
return NULL;
- for (i = 0; i < type->num_fields (); i++)
+ for (const auto &field : type->fields ())
{
- const char *t_field_name = type->field (i).name ();
+ const char *t_field_name = field.name ();
- if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
+ if (t_field_name && (strcmp_iw (t_field_name, field_name) == 0))
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 3957413..3605552 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -126,15 +126,15 @@ rust_underscore_fields (struct type *type)
if (type->code () != TYPE_CODE_STRUCT)
return false;
- for (int i = 0; i < type->num_fields (); ++i)
+ for (const auto &field : type->fields ())
{
- if (!type->field (i).is_static ())
+ if (!field.is_static ())
{
char buf[20];
xsnprintf (buf, sizeof (buf), "%d", field_number);
- const char *field_name = type->field (i).name ();
+ const char *field_name = field.name ();
if (startswith (field_name, "__"))
field_name += 2;
if (strcmp (buf, field_name) != 0)
@@ -376,11 +376,11 @@ rust_array_like_element_type (struct type *type)
{
/* Caller must check this. */
gdb_assert (rust_slice_type_p (type));
- for (int i = 0; i < type->num_fields (); ++i)
+ for (const auto &field : type->fields ())
{
- if (strcmp (type->field (i).name (), "data_ptr") == 0)
+ if (strcmp (field.name (), "data_ptr") == 0)
{
- struct type *base_type = type->field (i).type ()->target_type ();
+ struct type *base_type = field.type ()->target_type ();
if (rewrite_slice_type (base_type, nullptr, 0, nullptr))
return nullptr;
return base_type;
@@ -1017,9 +1017,9 @@ rust_internal_print_type (struct type *type, const char *varstring,
}
gdb_puts ("{\n", stream);
- for (int i = 0; i < type->num_fields (); ++i)
+ for (const auto &field : type->fields ())
{
- const char *name = type->field (i).name ();
+ const char *name = field.name ();
QUIT;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 6ee61e0..74d0175 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -4431,8 +4431,9 @@ again:
if (args == NULL)
return error_type (pp, objfile);
type = dbx_alloc_type (typenums, objfile);
- smash_to_method_type (type, domain, return_type, args,
- nargs, varargs);
+ smash_to_method_type (type, domain, return_type,
+ gdb::make_array_view (args, nargs),
+ varargs);
}
break;
diff --git a/gdb/valops.c b/gdb/valops.c
index 88f3e32..c260a79 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -45,9 +45,6 @@
/* Local functions. */
-static int typecmp (bool staticp, bool varargs, int nargs,
- struct field t1[], const gdb::array_view<value *> t2);
-
static struct value *search_struct_field (const char *, struct value *,
struct type *, int);
@@ -1766,7 +1763,7 @@ value_string (const gdb_byte *ptr, ssize_t count, struct type *char_type)
/* See if we can pass arguments in T2 to a function which takes arguments
- of types T1. T1 is a list of NARGS arguments, and T2 is an array_view
+ of types T1. T1 is an array_view of arguments, and T2 is an array_view
of the values we're trying to pass. If some arguments need coercion of
some sort, then the coerced values are written into T2. Return value is
0 if the arguments could be matched, or the position at which they
@@ -1783,8 +1780,8 @@ value_string (const gdb_byte *ptr, ssize_t count, struct type *char_type)
requested operation is type secure, shouldn't we? FIXME. */
static int
-typecmp (bool staticp, bool varargs, int nargs,
- struct field t1[], gdb::array_view<value *> t2)
+typecmp (bool staticp, bool varargs,
+ gdb::array_view<struct field> t1, gdb::array_view<value *> t2)
{
int i;
@@ -1794,7 +1791,7 @@ typecmp (bool staticp, bool varargs, int nargs,
t2 = t2.slice (1);
for (i = 0;
- (i < nargs) && t1[i].type ()->code () != TYPE_CODE_VOID;
+ (i < t1.size ()) && t1[i].type ()->code () != TYPE_CODE_VOID;
i++)
{
struct type *tt1, *tt2;
@@ -2227,7 +2224,6 @@ search_struct_method (const char *name, struct value **arg1p,
gdb_assert (args.has_value ());
if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
TYPE_FN_FIELD_TYPE (f, j)->has_varargs (),
- TYPE_FN_FIELD_TYPE (f, j)->num_fields (),
TYPE_FN_FIELD_ARGS (f, j), *args))
{
if (TYPE_FN_FIELD_VIRTUAL_P (f, j))