]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Change type::fields to return an array_view
authorTom Tromey <tromey@adacore.com>
Fri, 1 Aug 2025 17:11:41 +0000 (11:11 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 12 Aug 2025 14:30:37 +0000 (08:30 -0600)
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>
14 files changed:
gdb/ada-lang.c
gdb/amd64-tdep.c
gdb/c-typeprint.c
gdb/dwarf2/read.c
gdb/eval.c
gdb/f-typeprint.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/guile/scm-type.c
gdb/mdebugread.c
gdb/python/py-type.c
gdb/rust-lang.c
gdb/stabsread.c
gdb/valops.c

index 329d11479895fa5da6aaa837405a624dec86860e..1955169eca607a4ac92d257cc6d87bcfb0237430 100644 (file)
@@ -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;
 }
index 82dd1e07cf3c0846b3762ceb3979789b557f8412..d5ea4aff4cf48897dec01fbcac13eb56b2712d9a 100644 (file)
@@ -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;
index df7bdbe2ce0d7b0e19244fa878849d371981acd7..b6b3f6b778bb81ed0512cc3e367a7f5798241ca0 100644 (file)
@@ -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)
        {
index ec8d376a7f2d9be22951cc78e5f3eab3edad21bb..c37da5949b01e1e059bb2e0433dfe0d22a950503 100644 (file)
@@ -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
index 539b700ad8ff08206efde54e6365fe5296aa7b05..6227a26a93dec090241126bf5cdb733394c956c3 100644 (file)
@@ -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
index 7d0cdc089798b0de1dc8751d8c8ffef2542a2c18..e96d27c537e8f726dcae490637f7c7d43aa34b48 100644 (file)
@@ -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);
            }
index 14a903b54b47b8e8314c924207d3583efaad7a59..24e6d0bf8f52c581ee3f70f14ea915c51762f480 100644 (file)
@@ -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.  */
index 9e2efe99cff4a58f10217ff4e19a82c923b8120b..75c77b3a90c6474dcc5fe1fba5edf5b3233dcc27 100644 (file)
@@ -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 *);
index 51145790b14f1e94b09862da3ff10f37b93e92e1..13676cef4f00a159ef56ded5c6f5ed7d721a6cb3 100644 (file)
@@ -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);
 }
index 5bb15c2e95b5cdf851d071bcb00bcab0a209541c..b9302c594cd2d5fa602f9c294b3f3d55ea0f1790 100644 (file)
@@ -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)
          {
index c546aa7536ab5622be41dec1936fd163df716158..10ae636a9d19a7064f36b30774f81af1809ea64e 100644 (file)
@@ -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;
index 39574139b414f1efc187cbbe9568ecaf3d3f746a..360555280c32a5327e5caa58a76177f22514a2f3 100644 (file)
@@ -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;
 
index 6ee61e0a1174a8ca021e3f9e2ce2d723d59a0e35..74d01756c8ca7688f3cf8f38f3a07e9079b69a80 100644 (file)
@@ -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;
 
index 88f3e32cfc721db8186dab661da378cce07479ec..c260a79b46dd8a230d4c1719d601e92e9db3e6e1 100644 (file)
@@ -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)
 
 \f
 /* 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))