public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields
@ 2020-05-19 18:44 Simon Marchi
  2020-05-19 18:44 ` [PATCH 2/4] gdb: remove TYPE_NFIELDS macro Simon Marchi
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Simon Marchi @ 2020-05-19 18:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Add the `num_fields` and `set_num_fields` methods on `struct type`, in
order to remove the `TYPE_NFIELDS` macro.  In this patch, the
`TYPE_NFIELDS` macro is changed to use `type::num_fields`, so all the
call sites that are used to set the number of fields are changed to use
`type::set_num_fields`.  The next patch will remove `TYPE_NFIELDS`
completely.

I think that in the future, we should consider making the interface of
`struct type` better.  For example, right now it's possible for the
number of fields property and the actual number of fields set to be out
of sync.  However, I want to keep the existing behavior in this patch,
just translate from macros to methods.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <num_fields, set_num_fields>: New
	methods.
	(TYPE_NFIELDS): Use type::num_fields.  Change all call sites
	that modify the number of fields to use type::set_num_fields
	instead.
---
 gdb/ada-lang.c     | 11 +++++------
 gdb/buildsym.c     |  2 +-
 gdb/coffread.c     | 12 ++++++------
 gdb/ctfread.c      |  4 ++--
 gdb/dwarf2/read.c  | 12 ++++++------
 gdb/eval.c         |  2 +-
 gdb/gdbtypes.c     | 18 +++++++++---------
 gdb/gdbtypes.h     | 14 +++++++++++++-
 gdb/gnu-v3-abi.c   |  4 ++--
 gdb/mdebugread.c   |  6 +++---
 gdb/rust-lang.c    |  2 +-
 gdb/stabsread.c    |  8 ++++----
 gdb/windows-tdep.c |  2 +-
 13 files changed, 54 insertions(+), 43 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 825549d86e9..b740b3f8894 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8026,7 +8026,6 @@ empty_record (struct type *templ)
   struct type *type = alloc_type_copy (templ);
 
   type->set_code (TYPE_CODE_STRUCT);
-  TYPE_NFIELDS (type) = 0;
   TYPE_FIELDS (type) = NULL;
   INIT_NONE_SPECIFIC (type);
   type->set_name ("<empty>");
@@ -8083,7 +8082,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
   rtype = alloc_type_copy (type);
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
-  TYPE_NFIELDS (rtype) = nfields;
+  rtype->set_num_fields (nfields);
   TYPE_FIELDS (rtype) = (struct field *)
     TYPE_ALLOC (rtype, nfields * sizeof (struct field));
   memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
@@ -8251,7 +8250,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
         {
           for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
             TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
-          TYPE_NFIELDS (rtype) -= 1;
+	  rtype->set_num_fields (rtype->num_fields () - 1);
         }
       else
         {
@@ -8358,7 +8357,7 @@ template_to_static_fixed_type (struct type *type0)
 	      TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
 	      type->set_code (type0->code ());
 	      INIT_NONE_SPECIFIC (type);
-	      TYPE_NFIELDS (type) = nfields;
+	      type->set_num_fields (nfields);
 	      TYPE_FIELDS (type) = (struct field *)
 		TYPE_ALLOC (type, nfields * sizeof (struct field));
 	      memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
@@ -8407,7 +8406,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   rtype = alloc_type_copy (type);
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
-  TYPE_NFIELDS (rtype) = nfields;
+  rtype->set_num_fields (nfields);
   TYPE_FIELDS (rtype) =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
   memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
@@ -8430,7 +8429,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
 
       for (f = variant_field + 1; f < nfields; f += 1)
         TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
-      TYPE_NFIELDS (rtype) -= 1;
+      rtype->set_num_fields (rtype->num_fields () - 1);
     }
   else
     {
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index b9bcc33080a..f66607cd736 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -271,7 +271,7 @@ buildsym_compunit::finish_block_internal
 	    }
 	  if (nparams > 0)
 	    {
-	      TYPE_NFIELDS (ftype) = nparams;
+	      ftype->set_num_fields (nparams);
 	      TYPE_FIELDS (ftype) = (struct field *)
 		TYPE_ALLOC (ftype, nparams * sizeof (struct field));
 
diff --git a/gdb/coffread.c b/gdb/coffread.c
index fc44e53cc4c..59d6d231151 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1455,7 +1455,7 @@ patch_type (struct type *type, struct type *real_type)
   int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
 
   TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
-  TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
+  target->set_num_fields (TYPE_NFIELDS (real_target));
   TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target,
 						      field_size);
 
@@ -1884,7 +1884,7 @@ decode_base_type (struct coff_symbol *cs,
 	  INIT_CPLUS_SPECIFIC (type);
 	  TYPE_LENGTH (type) = 0;
 	  TYPE_FIELDS (type) = 0;
-	  TYPE_NFIELDS (type) = 0;
+	  type->set_num_fields (0);
 	}
       else
 	{
@@ -1904,7 +1904,7 @@ decode_base_type (struct coff_symbol *cs,
 	  INIT_CPLUS_SPECIFIC (type);
 	  TYPE_LENGTH (type) = 0;
 	  TYPE_FIELDS (type) = 0;
-	  TYPE_NFIELDS (type) = 0;
+	  type->set_num_fields (0);
 	}
       else
 	{
@@ -1925,7 +1925,7 @@ decode_base_type (struct coff_symbol *cs,
 	  type->set_name (NULL);
 	  TYPE_LENGTH (type) = 0;
 	  TYPE_FIELDS (type) = 0;
-	  TYPE_NFIELDS (type) = 0;
+	  type->set_num_fields (0);
 	}
       else
 	{
@@ -2041,7 +2041,7 @@ coff_read_struct_type (int index, int length, int lastsym,
     }
   /* Now create the vector of fields, and record how big it is.  */
 
-  TYPE_NFIELDS (type) = nfields;
+  type->set_num_fields (nfields);
   TYPE_FIELDS (type) = (struct field *)
     TYPE_ALLOC (type, sizeof (struct field) * nfields);
 
@@ -2121,7 +2121,7 @@ coff_read_enum_type (int index, int length, int lastsym,
   else /* Assume ints.  */
     TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
   type->set_code (TYPE_CODE_ENUM);
-  TYPE_NFIELDS (type) = nsyms;
+  type->set_num_fields (nsyms);
   TYPE_FIELDS (type) = (struct field *)
     TYPE_ALLOC (type, sizeof (struct field) * nsyms);
 
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index b5bdb5f9cf1..31f927e3bc9 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -308,7 +308,7 @@ attach_fields_to_type (struct ctf_field_info *fip, struct type *type)
     return;
 
   /* Record the field count, allocate space for the array of fields.  */
-  TYPE_NFIELDS (type) = nfields;
+  type->set_num_fields (nfields);
   TYPE_FIELDS (type)
     = (struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields);
 
@@ -1139,7 +1139,7 @@ add_stt_func (struct ctf_context *ccp, unsigned long idx)
   ftype = get_tid_type (ccp->of, tid);
   if (finfo.ctc_flags & CTF_FUNC_VARARG)
     TYPE_VARARGS (ftype) = 1;
-  TYPE_NFIELDS (ftype) = argc;
+  ftype->set_num_fields (argc);
 
   /* If argc is 0, it has a "void" type.  */
   if (argc != 0)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2ab7c5c3313..89ca038414e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9326,7 +9326,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       /* Smash this type to be a structure type.  We have to do this
 	 because the type has already been recorded.  */
       type->set_code (TYPE_CODE_STRUCT);
-      TYPE_NFIELDS (type) = 3;
+      type->set_num_fields (3);
       /* Save the field we care about.  */
       struct field saved_field = TYPE_FIELD (type, 0);
       TYPE_FIELDS (type)
@@ -9425,7 +9425,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       memcpy (new_fields + 1, TYPE_FIELDS (type),
 	      TYPE_NFIELDS (type) * sizeof (struct field));
       TYPE_FIELDS (type) = new_fields;
-      TYPE_NFIELDS (type) = TYPE_NFIELDS (type) + 1;
+      type->set_num_fields (TYPE_NFIELDS (type) + 1);
 
       /* Install the discriminant at index 0 in the union.  */
       TYPE_FIELD (type, 0) = *disr_field;
@@ -9473,7 +9473,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	  struct type *sub_type = TYPE_FIELD_TYPE (type, i);
 	  if (TYPE_NFIELDS (sub_type) > 0)
 	    {
-	      --TYPE_NFIELDS (sub_type);
+	      sub_type->set_num_fields (sub_type->num_fields () - 1);
 	      ++TYPE_FIELDS (sub_type);
 	    }
 	  TYPE_FIELD_NAME (type, i) = variant_name;
@@ -14768,7 +14768,7 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
 
   /* Record the field count, allocate space for the array of fields,
      and create blank accessibility bitfields if necessary.  */
-  TYPE_NFIELDS (type) = nfields;
+  type->set_num_fields (nfields);
   TYPE_FIELDS (type) = (struct field *)
     TYPE_ZALLOC (type, sizeof (struct field) * nfields);
 
@@ -15897,7 +15897,7 @@ update_enumeration_type_from_children (struct die_info *die,
 
   if (!fields.empty ())
     {
-      TYPE_NFIELDS (type) = fields.size ();
+      type->set_num_fields (fields.size ());
       TYPE_FIELDS (type) = (struct field *)
 	TYPE_ALLOC (type, sizeof (struct field) * fields.size ());
       memcpy (TYPE_FIELDS (type), fields.data (),
@@ -17048,7 +17048,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 	}
 
       /* Allocate storage for parameters and fill them in.  */
-      TYPE_NFIELDS (ftype) = nparams;
+      ftype->set_num_fields (nparams);
       TYPE_FIELDS (ftype) = (struct field *)
 	TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
 
diff --git a/gdb/eval.c b/gdb/eval.c
index ea086027880..023b629c1aa 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -682,7 +682,7 @@ fake_method::fake_method (type_instance_flags flags,
      neither an objfile nor a gdbarch.  As a result we must manually
      allocate memory for auxiliary fields, and free the memory ourselves
      when we are done with it.  */
-  TYPE_NFIELDS (type) = num_types;
+  type->set_num_fields (num_types);
   TYPE_FIELDS (type) = (struct field *)
     xzalloc (sizeof (struct field) * num_types);
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 68d4c0c4a24..f42657ab8f9 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -562,7 +562,7 @@ lookup_function_type_with_arguments (struct type *type,
 	TYPE_PROTOTYPED (fn) = 1;
     }
 
-  TYPE_NFIELDS (fn) = nparams;
+  fn->set_num_fields (nparams);
   TYPE_FIELDS (fn)
     = (struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field));
   for (i = 0; i < nparams; ++i)
@@ -1281,7 +1281,7 @@ create_array_type_with_stride (struct type *result_type,
   result_type->set_code (TYPE_CODE_ARRAY);
   TYPE_TARGET_TYPE (result_type) = element_type;
 
-  TYPE_NFIELDS (result_type) = 1;
+  result_type->set_num_fields (1);
   TYPE_FIELDS (result_type) =
     (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
   TYPE_INDEX_TYPE (result_type) = range_type;
@@ -1380,7 +1380,7 @@ create_set_type (struct type *result_type, struct type *domain_type)
     result_type = alloc_type_copy (domain_type);
 
   result_type->set_code (TYPE_CODE_SET);
-  TYPE_NFIELDS (result_type) = 1;
+  result_type->set_num_fields (1);
   TYPE_FIELDS (result_type)
     = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
 
@@ -1550,7 +1550,7 @@ smash_to_method_type (struct type *type, struct type *self_type,
   TYPE_TARGET_TYPE (type) = to_type;
   set_type_self_type (type, self_type);
   TYPE_FIELDS (type) = args;
-  TYPE_NFIELDS (type) = nargs;
+  type->set_num_fields (nargs);
   if (varargs)
     TYPE_VARARGS (type) = 1;
   TYPE_LENGTH (type) = 1;	/* In practice, this is never needed.  */
@@ -2402,8 +2402,8 @@ compute_variant_fields (struct type *type,
   for (const auto &part : parts)
     compute_variant_fields_inner (type, addr_stack, part, flags);
 
-  TYPE_NFIELDS (resolved_type) = std::count (flags.begin (), flags.end (),
-					     true);
+  resolved_type->set_num_fields
+    (std::count (flags.begin (), flags.end (), true));
   TYPE_FIELDS (resolved_type)
     = (struct field *) TYPE_ALLOC (resolved_type,
 				   TYPE_NFIELDS (resolved_type)
@@ -5558,7 +5558,7 @@ arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
 
   type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name);
   TYPE_UNSIGNED (type) = 1;
-  TYPE_NFIELDS (type) = 0;
+  type->set_num_fields (0);
   /* Pre-allocate enough space assuming every field is one bit.  */
   TYPE_FIELDS (type)
     = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
@@ -5587,7 +5587,7 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
   TYPE_FIELD_TYPE (type, field_nr) = field_type;
   SET_FIELD_BITPOS (TYPE_FIELD (type, field_nr), start_bitpos);
   TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
-  ++TYPE_NFIELDS (type);
+  type->set_num_fields (type->num_fields () + 1);
 }
 
 /* Special version of append_flags_type_field to add a flag field.
@@ -5630,7 +5630,7 @@ append_composite_type_field_raw (struct type *t, const char *name,
 {
   struct field *f;
 
-  TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
+  t->set_num_fields (TYPE_NFIELDS (t) + 1);
   TYPE_FIELDS (t) = XRESIZEVEC (struct field, TYPE_FIELDS (t),
 				TYPE_NFIELDS (t));
   f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index ba8e6f837aa..da8d5e2a119 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -901,6 +901,18 @@ struct type
     this->main_type->name = name;
   }
 
+  /* Get the number of fields of this type.  */
+  int num_fields () const
+  {
+    return this->main_type->nfields;
+  }
+
+  /* Set the number of fields of this type.  */
+  void set_num_fields (int num_fields)
+  {
+    this->main_type->nfields = num_fields;
+  }
+
   /* * Return the dynamic property of the requested KIND from this type's
      list of dynamic properties.  */
   dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
@@ -1446,7 +1458,7 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
+#define TYPE_NFIELDS(thistype) ((thistype)->num_fields ())
 #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
 
 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index df5818b300e..b0544319383 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -165,7 +165,7 @@ build_gdb_vtable_type (struct gdbarch *arch)
   gdb_assert (field == (field_list + 4));
 
   t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
-  TYPE_NFIELDS (t) = field - field_list;
+  t->set_num_fields (field - field_list);
   TYPE_FIELDS (t) = field_list;
   t->set_name ("gdb_gnu_v3_abi_vtable");
   INIT_CPLUS_SPECIFIC (t);
@@ -1054,7 +1054,7 @@ build_std_type_info_type (struct gdbarch *arch)
   gdb_assert (field == (field_list + 2));
 
   t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
-  TYPE_NFIELDS (t) = field - field_list;
+  t->set_num_fields (field - field_list);
   TYPE_FIELDS (t) = field_list;
   t->set_name ("gdb_gnu_v3_type_info");
   INIT_CPLUS_SPECIFIC (t);
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 9ad9c664bcb..1b499ccad34 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1017,7 +1017,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 
 	t->set_code (type_code);
 	TYPE_LENGTH (t) = sh->value;
-	TYPE_NFIELDS (t) = nfields;
+	t->set_num_fields (nfields);
 	TYPE_FIELDS (t) = f = ((struct field *)
 			       TYPE_ALLOC (t,
 					   nfields * sizeof (struct field)));
@@ -1186,7 +1186,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		{
 		  struct block_iterator iter;
 
-		  TYPE_NFIELDS (ftype) = nparams;
+		  ftype->set_num_fields (nparams);
 		  TYPE_FIELDS (ftype) = (struct field *)
 		    TYPE_ALLOC (ftype, nparams * sizeof (struct field));
 
@@ -1733,7 +1733,7 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
   /* Deal with range types.  */
   if (t->bt == btRange)
     {
-      TYPE_NFIELDS (tp) = 0;
+      tp->set_num_fields (0);
       TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
 			  TYPE_ZALLOC (tp, sizeof (struct range_bounds)));
       TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 2c76762eff2..f0bea374ecb 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -984,7 +984,7 @@ rust_composite_type (struct type *original,
   result->set_code (TYPE_CODE_STRUCT);
   result->set_name (name);
 
-  TYPE_NFIELDS (result) = nfields;
+  result->set_num_fields (nfields);
   TYPE_FIELDS (result)
     = (struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field));
 
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index a632856404b..c3da9a239b4 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1009,7 +1009,7 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	      TYPE_FIELD_TYPE (ftype, nparams) = ptype;
 	      TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
 	    }
-	  TYPE_NFIELDS (ftype) = nparams;
+	  ftype->set_num_fields (nparams);
 	  TYPE_PROTOTYPED (ftype) = 1;
 	}
       break;
@@ -1850,7 +1850,7 @@ read_type (const char **pp, struct objfile *objfile)
           for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
             TYPE_FIELD_TYPE (func_type, i) = t->type;
         }
-        TYPE_NFIELDS (func_type) = num_args;
+        func_type->set_num_fields (num_args);
         TYPE_PROTOTYPED (func_type) = 1;
 
         type = func_type;
@@ -3308,7 +3308,7 @@ attach_fields_to_type (struct stab_field_info *fip, struct type *type,
      non-public fields.  Record the field count, allocate space for the
      array of fields, and create blank visibility bitfields if necessary.  */
 
-  TYPE_NFIELDS (type) = nfields;
+  type->set_num_fields (nfields);
   TYPE_FIELDS (type) = (struct field *)
     TYPE_ALLOC (type, sizeof (struct field) * nfields);
   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
@@ -3654,7 +3654,7 @@ read_enum_type (const char **pp, struct type *type,
   TYPE_STUB (type) = 0;
   if (unsigned_enum)
     TYPE_UNSIGNED (type) = 1;
-  TYPE_NFIELDS (type) = nsyms;
+  type->set_num_fields (nsyms);
   TYPE_FIELDS (type) = (struct field *)
     TYPE_ALLOC (type, sizeof (struct field) * nsyms);
   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 20a18e6b683..d7c498f2e93 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -751,7 +751,7 @@ create_enum (struct gdbarch *gdbarch, int bit, const char *name,
   int i;
 
   type = arch_type (gdbarch, TYPE_CODE_ENUM, bit, name);
-  TYPE_NFIELDS (type) = count;
+  type->set_num_fields (count);
   TYPE_FIELDS (type) = (struct field *)
     TYPE_ZALLOC (type, sizeof (struct field) * count);
   TYPE_UNSIGNED (type) = 1;
-- 
2.26.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/4] gdb: remove TYPE_NFIELDS macro
  2020-05-19 18:44 [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Simon Marchi
@ 2020-05-19 18:44 ` Simon Marchi
  2020-05-22 20:20   ` Tom Tromey
  2020-05-19 18:44 ` [PATCH 3/4] gdb: add type::fields / type::set_fields Simon Marchi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2020-05-19 18:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Remove `TYPE_NFIELDS`, changing all the call sites to use
`type::num_fields` directly.  This is quite a big diff, but this was
mostly done using sed and coccinelle.  A few call sites were done by
hand.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_NFIELDS): Remove.  Change all cal sites to use
	type::num_fields instead.
---
 gdb/aarch64-tdep.c                |  4 +-
 gdb/ada-exp.y                     |  2 +-
 gdb/ada-lang.c                    | 70 +++++++++++++-------------
 gdb/ada-typeprint.c               | 18 +++----
 gdb/ada-valprint.c                |  6 +--
 gdb/ada-varobj.c                  |  4 +-
 gdb/amd64-tdep.c                  |  6 +--
 gdb/arm-tdep.c                    |  6 +--
 gdb/ax-gdb.c                      |  6 +--
 gdb/buildsym.c                    |  2 +-
 gdb/c-lang.c                      |  2 +-
 gdb/c-typeprint.c                 | 22 ++++-----
 gdb/c-varobj.c                    |  6 +--
 gdb/coffread.c                    |  4 +-
 gdb/compile/compile-c-symbols.c   |  2 +-
 gdb/compile/compile-c-types.c     | 10 ++--
 gdb/compile/compile-cplus-types.c |  8 +--
 gdb/compile/compile-object-load.c |  8 +--
 gdb/compile/compile-object-run.c  | 10 ++--
 gdb/completer.c                   |  2 +-
 gdb/cp-valprint.c                 |  4 +-
 gdb/d-valprint.c                  |  2 +-
 gdb/dwarf2/read.c                 | 52 ++++++++++----------
 gdb/eval.c                        |  6 +--
 gdb/f-typeprint.c                 |  4 +-
 gdb/f-valprint.c                  |  2 +-
 gdb/gdbtypes.c                    | 82 +++++++++++++++----------------
 gdb/gdbtypes.h                    |  3 +-
 gdb/gnu-v2-abi.c                  |  2 +-
 gdb/gnu-v3-abi.c                  |  6 +--
 gdb/go-lang.c                     |  4 +-
 gdb/guile/scm-type.c              | 12 ++---
 gdb/i386-darwin-tdep.c            |  2 +-
 gdb/i386-tdep.c                   |  6 +--
 gdb/i386-windows-tdep.c           |  2 +-
 gdb/ia64-tdep.c                   |  4 +-
 gdb/infcall.c                     |  8 +--
 gdb/iq2000-tdep.c                 |  2 +-
 gdb/m2-typeprint.c                | 16 +++---
 gdb/m2-valprint.c                 |  4 +-
 gdb/m32c-tdep.c                   |  2 +-
 gdb/m68k-tdep.c                   |  2 +-
 gdb/mdebugread.c                  |  8 +--
 gdb/mips-tdep.c                   | 30 +++++------
 gdb/mn10300-tdep.c                |  4 +-
 gdb/nds32-tdep.c                  |  4 +-
 gdb/or1k-tdep.c                   |  2 +-
 gdb/p-lang.c                      |  4 +-
 gdb/p-typeprint.c                 |  8 +--
 gdb/p-valprint.c                  |  2 +-
 gdb/ppc-sysv-tdep.c               |  6 +--
 gdb/python/py-type.c              |  8 +--
 gdb/riscv-tdep.c                  |  8 +--
 gdb/rust-exp.y                    |  2 +-
 gdb/rust-lang.c                   | 46 ++++++++---------
 gdb/rx-tdep.c                     |  4 +-
 gdb/s390-tdep.c                   |  6 +--
 gdb/score-tdep.c                  |  2 +-
 gdb/sh-tdep.c                     | 10 ++--
 gdb/sparc64-tdep.c                |  8 +--
 gdb/stabsread.c                   |  2 +-
 gdb/symtab.c                      |  4 +-
 gdb/tic6x-tdep.c                  |  2 +-
 gdb/typeprint.c                   |  2 +-
 gdb/v850-tdep.c                   |  8 +--
 gdb/valops.c                      | 26 +++++-----
 gdb/valprint.c                    |  4 +-
 67 files changed, 317 insertions(+), 318 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 37d75a81f08..2872d2d2bf7 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -1346,7 +1346,7 @@ aapcs_is_vfp_call_or_return_candidate_1 (struct type *type,
       {
 	int count = 0;
 
-	for (int i = 0; i < TYPE_NFIELDS (type); i++)
+	for (int i = 0; i < type->num_fields (); i++)
 	  {
 	    /* Ignore any static fields.  */
 	    if (field_is_static (&TYPE_FIELD (type, i)))
@@ -1628,7 +1628,7 @@ pass_in_v_vfp_candidate (struct gdbarch *gdbarch, struct regcache *regcache,
 
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
-      for (int i = 0; i < TYPE_NFIELDS (arg_type); i++)
+      for (int i = 0; i < arg_type->num_fields (); i++)
 	{
 	  /* Don't include static fields.  */
 	  if (field_is_static (&TYPE_FIELD (arg_type, i)))
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 15b28ac807d..2ae9830dbbb 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1394,7 +1394,7 @@ convert_char_literal (struct type *type, LONGEST val)
   else
     xsnprintf (name, sizeof (name), "QU%02x", (int) val);
   size_t len = strlen (name);
-  for (f = 0; f < TYPE_NFIELDS (type); f += 1)
+  for (f = 0; f < type->num_fields (); f += 1)
     {
       /* Check the suffix because an enum constant in a package will
 	 have a name like "pkg__QUxx".  This is safe enough because we
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b740b3f8894..e91ad614ce2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -571,7 +571,7 @@ ada_get_field_index (const struct type *type, const char *field_name,
   int fieldno;
   struct type *struct_type = check_typedef ((struct type *) type);
 
-  for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); fieldno++)
+  for (fieldno = 0; fieldno < struct_type->num_fields (); fieldno++)
     if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
       return fieldno;
 
@@ -755,7 +755,7 @@ ada_discrete_type_high_bound (struct type *type)
     case TYPE_CODE_RANGE:
       return TYPE_HIGH_BOUND (type);
     case TYPE_CODE_ENUM:
-      return TYPE_FIELD_ENUMVAL (type, TYPE_NFIELDS (type) - 1);
+      return TYPE_FIELD_ENUMVAL (type, type->num_fields () - 1);
     case TYPE_CODE_BOOL:
       return 1;
     case TYPE_CODE_CHAR:
@@ -1461,7 +1461,7 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
 
   if (index_desc_type == NULL)
     return;
-  gdb_assert (TYPE_NFIELDS (index_desc_type) > 0);
+  gdb_assert (index_desc_type->num_fields () > 0);
 
   /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
      to check one field only, no need to check them all).  If not, return
@@ -1476,7 +1476,7 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
     return;
 
   /* Fixup each field of INDEX_DESC_TYPE.  */
-  for (i = 0; i < TYPE_NFIELDS (index_desc_type); i++)
+  for (i = 0; i < index_desc_type->num_fields (); i++)
    {
      const char *name = TYPE_FIELD_NAME (index_desc_type, i);
      struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
@@ -1812,7 +1812,7 @@ desc_arity (struct type *type)
   type = desc_base_type (type);
 
   if (type != NULL)
-    return TYPE_NFIELDS (type) / 2;
+    return type->num_fields () / 2;
   return 0;
 }
 
@@ -3211,12 +3211,12 @@ ada_print_symbol_signature (struct ui_file *stream, struct symbol *sym,
       || type->code () != TYPE_CODE_FUNC)
     return;
 
-  if (TYPE_NFIELDS (type) > 0)
+  if (type->num_fields () > 0)
     {
       int i;
 
       fprintf_filtered (stream, " (");
-      for (i = 0; i < TYPE_NFIELDS (type); ++i)
+      for (i = 0; i < type->num_fields (); ++i)
 	{
 	  if (i > 0)
 	    fprintf_filtered (stream, "; ");
@@ -3902,7 +3902,7 @@ ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
   else if (func_type == NULL || func_type->code () != TYPE_CODE_FUNC)
     return 0;
 
-  if (TYPE_NFIELDS (func_type) != n_actuals)
+  if (func_type->num_fields () != n_actuals)
     return 0;
 
   for (i = 0; i < n_actuals; i += 1)
@@ -4963,7 +4963,7 @@ is_nondebugging_type (struct type *type)
 
    This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
    types and that their number of enumerals is identical (in other
-   words, TYPE_NFIELDS (type1) == TYPE_NFIELDS (type2)).  */
+   words, type1->num_fields () == type2->num_fields ()).  */
 
 static int
 ada_identical_enum_types_p (struct type *type1, struct type *type2)
@@ -4976,13 +4976,13 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
      underlying value and name.  */
 
   /* All enums in the type should have an identical underlying value.  */
-  for (i = 0; i < TYPE_NFIELDS (type1); i++)
+  for (i = 0; i < type1->num_fields (); i++)
     if (TYPE_FIELD_ENUMVAL (type1, i) != TYPE_FIELD_ENUMVAL (type2, i))
       return 0;
 
   /* All enumerals should also have the same name (modulo any numerical
      suffix).  */
-  for (i = 0; i < TYPE_NFIELDS (type1); i++)
+  for (i = 0; i < type1->num_fields (); i++)
     {
       const char *name_1 = TYPE_FIELD_NAME (type1, i);
       const char *name_2 = TYPE_FIELD_NAME (type2, i);
@@ -5045,8 +5045,8 @@ symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
 
   /* Quick check: They should all have the same number of enumerals.  */
   for (i = 1; i < syms.size (); i++)
-    if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].symbol))
-        != TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol)))
+    if (SYMBOL_TYPE (syms[i].symbol)->num_fields ()
+        != SYMBOL_TYPE (syms[0].symbol)->num_fields ())
       return 0;
 
   /* All the sanity checks passed, so we might have a set of
@@ -6532,7 +6532,7 @@ ada_is_interface_tag (struct type *type)
 int
 ada_is_ignored_field (struct type *type, int field_num)
 {
-  if (field_num < 0 || field_num > TYPE_NFIELDS (type))
+  if (field_num < 0 || field_num > type->num_fields ())
     return 1;
 
   /* Check the name of that field.  */
@@ -6868,7 +6868,7 @@ ada_parent_type (struct type *type)
   if (type == NULL || type->code () != TYPE_CODE_STRUCT)
     return NULL;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     if (ada_is_parent_field (type, i))
       {
         struct type *parent_type = TYPE_FIELD_TYPE (type, i);
@@ -7231,7 +7231,7 @@ find_struct_field (const char *name, struct type *type, int offset,
   if (bit_size_p != NULL)
     *bit_size_p = 0;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       int bit_pos = TYPE_FIELD_BITPOS (type, i);
       int fld_offset = offset + bit_pos / 8;
@@ -7283,7 +7283,7 @@ find_struct_field (const char *name, struct type *type, int offset,
           struct type *field_type
 	    = ada_check_typedef (TYPE_FIELD_TYPE (type, i));
 
-          for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
+          for (j = 0; j < field_type->num_fields (); j += 1)
             {
               if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j),
                                      fld_offset
@@ -7343,7 +7343,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
   int parent_offset = -1;
 
   type = ada_check_typedef (type);
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -7386,7 +7386,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
 									i));
           int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
 
-          for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
+          for (j = 0; j < field_type->num_fields (); j += 1)
             {
               struct value *v = ada_search_struct_field /* Force line
 							   break.  */
@@ -7444,7 +7444,7 @@ ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
   int i;
   type = ada_check_typedef (type);
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       if (TYPE_FIELD_NAME (type, i) == NULL)
         continue;
@@ -7537,7 +7537,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
 
   type = to_static_fixed_type (type);
 
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+  for (i = 0; i < type->num_fields (); i += 1)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
       struct type *t;
@@ -7576,7 +7576,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
           struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
 									i));
 
-          for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
+          for (j = field_type->num_fields () - 1; j >= 0; j -= 1)
             {
 	      /* FIXME pnh 2008/01/26: We check for a field that is
 	         NOT wrapped in a struct, since the compiler sometimes
@@ -7660,7 +7660,7 @@ ada_which_variant_applies (struct type *var_type, struct value *outer)
   discrim_val = value_as_long (discrim);
 
   others_clause = -1;
-  for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
+  for (i = 0; i < var_type->num_fields (); i += 1)
     {
       if (ada_is_others_clause (var_type, i))
         others_clause = i;
@@ -8010,7 +8010,7 @@ variant_field_index (struct type *type)
   if (type == NULL || type->code () != TYPE_CODE_STRUCT)
     return -1;
 
-  for (f = 0; f < TYPE_NFIELDS (type); f += 1)
+  for (f = 0; f < type->num_fields (); f += 1)
     {
       if (ada_is_variant_part (type, f))
         return f;
@@ -8069,11 +8069,11 @@ ada_template_to_fixed_record_type_1 (struct type *type,
      to be processed: unless keep_dynamic_fields, this includes only
      fields whose position and length are static will be processed.  */
   if (keep_dynamic_fields)
-    nfields = TYPE_NFIELDS (type);
+    nfields = type->num_fields ();
   else
     {
       nfields = 0;
-      while (nfields < TYPE_NFIELDS (type)
+      while (nfields < type->num_fields ()
              && !ada_is_variant_part (type, nfields)
              && !is_dynamic_field (type, nfields))
         nfields++;
@@ -8248,7 +8248,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
          cond_offset_target (address, off / TARGET_CHAR_BIT), dval);
       if (branch_type == NULL)
         {
-          for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
+          for (f = variant_field + 1; f < rtype->num_fields (); f += 1)
             TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
 	  rtype->set_num_fields (rtype->num_fields () - 1);
         }
@@ -8330,7 +8330,7 @@ template_to_static_fixed_type (struct type *type0)
 
   /* Don't clone TYPE0 until we are sure we are going to need a copy.  */
   type = type0;
-  nfields = TYPE_NFIELDS (type0);
+  nfields = type0->num_fields ();
 
   /* Whether or not we cloned TYPE0, cache the result so that we don't do
      recompute all over next time.  */
@@ -8389,7 +8389,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   struct value *dval;
   struct type *rtype;
   struct type *branch_type;
-  int nfields = TYPE_NFIELDS (type);
+  int nfields = type->num_fields ();
   int variant_field = variant_field_index (type);
 
   if (variant_field == -1)
@@ -8595,7 +8595,7 @@ ada_is_redundant_index_type_desc (struct type *array_type,
   struct type *this_layer = check_typedef (array_type);
   int i;
 
-  for (i = 0; i < TYPE_NFIELDS (desc_type); i++)
+  for (i = 0; i < desc_type->num_fields (); i++)
     {
       if (!ada_is_redundant_range_encoding (TYPE_INDEX_TYPE (this_layer),
 					    TYPE_FIELD_TYPE (desc_type, i)))
@@ -8699,7 +8699,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
       struct type *elt_type0;
 
       elt_type0 = type0;
-      for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
+      for (i = index_type_desc->num_fields (); i > 0; i -= 1)
         elt_type0 = TYPE_TARGET_TYPE (elt_type0);
 
       /* NOTE: result---the fixed version of elt_type0---should never
@@ -8717,7 +8717,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
         ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval, 1);
 
       elt_type0 = type0;
-      for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
+      for (i = index_type_desc->num_fields () - 1; i >= 0; i -= 1)
         {
           struct type *range_type =
             to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, i), dval);
@@ -9153,7 +9153,7 @@ value_val_atr (struct type *type, struct value *arg)
     {
       long pos = value_as_long (arg);
 
-      if (pos < 0 || pos >= TYPE_NFIELDS (type))
+      if (pos < 0 || pos >= type->num_fields ())
         error (_("argument to 'VAL out of range"));
       return value_from_longest (type, TYPE_FIELD_ENUMVAL (type, pos));
     }
@@ -9234,7 +9234,7 @@ ada_is_aligner_type (struct type *type)
     return 0;
 
   return (type->code () == TYPE_CODE_STRUCT
-          && TYPE_NFIELDS (type) == 1
+          && type->num_fields () == 1
           && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
 }
 
@@ -9268,7 +9268,7 @@ ada_get_base_type (struct type *raw_type)
   real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
   if (real_type_namer == NULL
       || real_type_namer->code () != TYPE_CODE_STRUCT
-      || TYPE_NFIELDS (real_type_namer) != 1)
+      || real_type_namer->num_fields () != 1)
     return raw_type;
 
   if (TYPE_FIELD_TYPE (real_type_namer, 0)->code () != TYPE_CODE_REF)
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 076c0a63bfa..2021edf0111 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -312,7 +312,7 @@ print_range_type (struct type *raw_type, struct ui_file *stream,
 static void
 print_enum_type (struct type *type, struct ui_file *stream)
 {
-  int len = TYPE_NFIELDS (type);
+  int len = type->num_fields ();
   int i;
   LONGEST lastval;
 
@@ -417,7 +417,7 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
 	{
 	  int k;
 
-	  n_indices = TYPE_NFIELDS (range_desc_type);
+	  n_indices = range_desc_type->num_fields ();
 	  for (k = 0, arr_type = type;
 	       k < n_indices;
 	       k += 1, arr_type = TYPE_TARGET_TYPE (arr_type))
@@ -563,7 +563,7 @@ print_variant_clauses (struct type *type, int field_num,
   if (par_type != NULL)
     var_type = par_type;
 
-  for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
+  for (i = 0; i < var_type->num_fields (); i += 1)
     {
       fprintf_filtered (stream, "\n%*swhen ", level + 4, "");
       if (print_choices (var_type, i, stream, discr_type))
@@ -786,13 +786,13 @@ print_record_field_types (struct type *type, struct type *outer_type,
 	}
       gdb_assert (prop->kind == PROP_VARIANT_PARTS);
       print_record_field_types_dynamic (*prop->data.variant_parts,
-					0, TYPE_NFIELDS (type),
+					0, type->num_fields (),
 					type, stream, show, level, flags);
-      return TYPE_NFIELDS (type);
+      return type->num_fields ();
     }
 
   return print_selected_record_field_types (type, outer_type,
-					    0, TYPE_NFIELDS (type) - 1,
+					    0, type->num_fields () - 1,
 					    stream, show, level, flags);
 }
    
@@ -863,7 +863,7 @@ print_unchecked_union_type (struct type *type, struct ui_file *stream,
 {
   if (show < 0)
     fprintf_filtered (stream, "record (?) is ... end record");
-  else if (TYPE_NFIELDS (type) == 0)
+  else if (type->num_fields () == 0)
     fprintf_filtered (stream, "record (?) is null; end record");
   else
     {
@@ -871,7 +871,7 @@ print_unchecked_union_type (struct type *type, struct ui_file *stream,
 
       fprintf_filtered (stream, "record (?) is\n%*scase ? is", level + 4, "");
 
-      for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+      for (i = 0; i < type->num_fields (); i += 1)
 	{
 	  fprintf_filtered (stream, "\n%*swhen ? =>\n%*s", level + 8, "",
 			    level + 12, "");
@@ -895,7 +895,7 @@ static void
 print_func_type (struct type *type, struct ui_file *stream, const char *name,
 		 const struct type_print_options *flags)
 {
-  int i, len = TYPE_NFIELDS (type);
+  int i, len = type->num_fields ();
 
   if (TYPE_TARGET_TYPE (type) != NULL
       && TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_VOID)
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index e11e47ee59e..f0e7bfc296b 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -400,7 +400,7 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
     {
 
     case TYPE_CODE_ENUM:
-      len = TYPE_NFIELDS (type);
+      len = type->num_fields ();
       for (i = 0; i < len; i++)
 	{
 	  if (TYPE_FIELD_ENUMVAL (type, i) == val)
@@ -600,7 +600,7 @@ print_field_values (struct value *value, struct value *outer_value,
   int i, len;
 
   struct type *type = value_type (value);
-  len = TYPE_NFIELDS (type);
+  len = type->num_fields ();
 
   for (i = 0; i < len; i += 1)
     {
@@ -886,7 +886,7 @@ ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse,
   const gdb_byte *valaddr = value_contents_for_printing (value);
   int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
 
-  len = TYPE_NFIELDS (type);
+  len = type->num_fields ();
   val = unpack_long (type, valaddr + offset_aligned);
   for (i = 0; i < len; i++)
     {
diff --git a/gdb/ada-varobj.c b/gdb/ada-varobj.c
index 98dc9d19900..485eae29b92 100644
--- a/gdb/ada-varobj.c
+++ b/gdb/ada-varobj.c
@@ -273,7 +273,7 @@ ada_varobj_get_struct_number_of_children (struct value *parent_value,
   gdb_assert (parent_type->code () == TYPE_CODE_STRUCT
 	      || parent_type->code () == TYPE_CODE_UNION);
 
-  for (i = 0; i < TYPE_NFIELDS (parent_type); i++)
+  for (i = 0; i < parent_type->num_fields (); i++)
     {
       if (ada_is_ignored_field (parent_type, i))
 	continue;
@@ -421,7 +421,7 @@ ada_varobj_describe_struct_child (struct value *parent_value,
   gdb_assert (parent_type->code () == TYPE_CODE_STRUCT
 	      || parent_type->code () == TYPE_CODE_UNION);
 
-  for (fieldno = 0; fieldno < TYPE_NFIELDS (parent_type); fieldno++)
+  for (fieldno = 0; fieldno < parent_type->num_fields (); fieldno++)
     {
       if (ada_is_ignored_field (parent_type, fieldno))
 	continue;
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 9fa5d2b83df..24f0614b235 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -549,7 +549,7 @@ amd64_has_unaligned_fields (struct type *type)
   if (type->code () == TYPE_CODE_STRUCT
       || type->code () == TYPE_CODE_UNION)
     {
-      for (int i = 0; i < TYPE_NFIELDS (type); i++)
+      for (int i = 0; i < type->num_fields (); i++)
 	{
 	  struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
 	  int bitpos = TYPE_FIELD_BITPOS (type, i);
@@ -608,7 +608,7 @@ amd64_classify_aggregate_field (struct type *type, int i,
     {
       /* Each field of an object is classified recursively.  */
       int j;
-      for (j = 0; j < TYPE_NFIELDS (subtype); j++)
+      for (j = 0; j < subtype->num_fields (); j++)
 	amd64_classify_aggregate_field (subtype, j, theclass, bitpos);
       return;
     }
@@ -684,7 +684,7 @@ amd64_classify_aggregate (struct type *type, enum amd64_reg_class theclass[2])
       gdb_assert (type->code () == TYPE_CODE_STRUCT
 		  || type->code () == TYPE_CODE_UNION);
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	amd64_classify_aggregate_field (type, i, theclass, 0);
     }
 
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 45df1bd39de..e9681925211 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -3497,7 +3497,7 @@ arm_vfp_cprc_sub_candidate (struct type *t,
 	int count = 0;
 	unsigned unitlen;
 	int i;
-	for (i = 0; i < TYPE_NFIELDS (t); i++)
+	for (i = 0; i < t->num_fields (); i++)
 	  {
 	    int sub_count = 0;
 
@@ -3526,7 +3526,7 @@ arm_vfp_cprc_sub_candidate (struct type *t,
 	int count = 0;
 	unsigned unitlen;
 	int i;
-	for (i = 0; i < TYPE_NFIELDS (t); i++)
+	for (i = 0; i < t->num_fields (); i++)
 	  {
 	    int sub_count = arm_vfp_cprc_sub_candidate (TYPE_FIELD_TYPE (t, i),
 							base_type);
@@ -7970,7 +7970,7 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type)
 	     --> yes, nRc = 1
 	  */
 
-	  for (i = 0; i < TYPE_NFIELDS (type); i++)
+	  for (i = 0; i < type->num_fields (); i++)
 	    {
 	      enum type_code field_type_code;
 
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 0f389e49cb7..4dcdc3b411f 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -316,7 +316,7 @@ gen_trace_static_fields (struct agent_expr *ax,
 
   type = check_typedef (type);
 
-  for (i = TYPE_NFIELDS (type) - 1; i >= nbases; i--)
+  for (i = type->num_fields () - 1; i >= nbases; i--)
     {
       if (field_is_static (&TYPE_FIELD (type, i)))
 	{
@@ -1444,7 +1444,7 @@ gen_struct_ref_recursive (struct agent_expr *ax, struct axs_value *value,
 
   type = check_typedef (type);
 
-  for (i = TYPE_NFIELDS (type) - 1; i >= nbases; i--)
+  for (i = type->num_fields () - 1; i >= nbases; i--)
     {
       const char *this_name = TYPE_FIELD_NAME (type, i);
 
@@ -1588,7 +1588,7 @@ gen_struct_elt_for_reference (struct agent_expr *ax, struct axs_value *value,
     internal_error (__FILE__, __LINE__,
 		    _("non-aggregate type to gen_struct_elt_for_reference"));
 
-  for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--)
+  for (i = t->num_fields () - 1; i >= TYPE_N_BASECLASSES (t); i--)
     {
       const char *t_field_name = TYPE_FIELD_NAME (t, i);
 
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index f66607cd736..b25d09b5c0c 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -254,7 +254,7 @@ buildsym_compunit::finish_block_internal
       SYMBOL_BLOCK_VALUE (symbol) = block;
       BLOCK_FUNCTION (block) = symbol;
 
-      if (TYPE_NFIELDS (ftype) <= 0)
+      if (ftype->num_fields () <= 0)
 	{
 	  /* No parameter type information is recorded with the
 	     function's type.  Set that from the type of the
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 557482f2be4..e549c5cb657 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -254,7 +254,7 @@ c_get_string (struct value *value, gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
     {
       /* If we know the size of the array, we can use it as a limit on
 	 the number of characters to be fetched.  */
-      if (TYPE_NFIELDS (type) == 1
+      if (type->num_fields () == 1
 	  && TYPE_FIELD_TYPE (type, 0)->code () == TYPE_CODE_RANGE)
 	{
 	  LONGEST low_bound, high_bound;
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index bbe12ccfe87..955cfd60451 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -278,7 +278,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
 			   const struct type_print_options *flags)
 {
   struct field *args = TYPE_FIELDS (mtype);
-  int nargs = TYPE_NFIELDS (mtype);
+  int nargs = mtype->num_fields ();
   int varargs = TYPE_VARARGS (mtype);
   int i;
 
@@ -560,7 +560,7 @@ c_type_print_args (struct type *type, struct ui_file *stream,
 
   fprintf_filtered (stream, "(");
 
-  for (i = 0; i < TYPE_NFIELDS (type); i++)
+  for (i = 0; i < type->num_fields (); i++)
     {
       struct type *param_type;
 
@@ -965,7 +965,7 @@ need_access_label_p (struct type *type)
   if (TYPE_DECLARED_CLASS (type))
     {
       QUIT;
-      for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
+      for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
 	if (!TYPE_FIELD_PRIVATE (type, i))
 	  return true;
       QUIT;
@@ -982,7 +982,7 @@ need_access_label_p (struct type *type)
   else
     {
       QUIT;
-      for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
+      for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
 	if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i))
 	  return true;
       QUIT;
@@ -1115,7 +1115,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 
       fprintf_filtered (stream, "{\n");
 
-      if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0
+      if (type->num_fields () == 0 && TYPE_NFN_FIELDS (type) == 0
 	  && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
 	{
 	  if (TYPE_STUB (type))
@@ -1143,7 +1143,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
       /* If there is a base class for this type,
 	 do not print the field that it occupies.  */
 
-      int len = TYPE_NFIELDS (type);
+      int len = type->num_fields ();
       vptr_fieldno = get_vptr_fieldno (type, &basetype);
 
       struct print_offset_data local_podata;
@@ -1374,7 +1374,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 	  if (semi_local_flags.print_nested_type_limit > 0)
 	    --semi_local_flags.print_nested_type_limit;
 
-	  if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
+	  if (type->num_fields () != 0 || TYPE_NFN_FIELDS (type) != 0)
 	    fprintf_filtered (stream, "\n");
 
 	  for (int i = 0; i < TYPE_NESTED_TYPES_COUNT (type); ++i)
@@ -1392,7 +1392,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
 
       if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
 	{
-	  if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0
+	  if (type->num_fields () != 0 || TYPE_NFN_FIELDS (type) != 0
 	      || TYPE_NESTED_TYPES_COUNT (type) != 0)
 	    fprintf_filtered (stream, "\n");
 
@@ -1593,7 +1593,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	    }
 
 	  fprintf_filtered (stream, "{");
-	  len = TYPE_NFIELDS (type);
+	  len = type->num_fields ();
 	  for (i = 0; i < len; i++)
 	    {
 	      QUIT;
@@ -1627,7 +1627,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	  {
 	    fputs_filtered (" ", stream);
 	    fprintf_filtered (stream, "{\n");
-	    if (TYPE_NFIELDS (type) == 0)
+	    if (type->num_fields () == 0)
 	      {
 		if (TYPE_STUB (type))
 		  fprintfi_filtered (level + 4, stream,
@@ -1638,7 +1638,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 				     _("%p[<no data fields>%p]\n"),
 				     metadata_style.style ().ptr (), nullptr);
 	      }
-	    len = TYPE_NFIELDS (type);
+	    len = type->num_fields ();
 	    for (i = 0; i < len; i++)
 	      {
 		QUIT;
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index 51940b9dd66..6cb260ddc91 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -164,7 +164,7 @@ c_is_path_expr_parent (const struct varobj *var)
 	    {
 	      const char *field_name;
 
-	      gdb_assert (var->index < TYPE_NFIELDS (parent_type));
+	      gdb_assert (var->index < parent_type->num_fields ());
 	      field_name = TYPE_FIELD_NAME (parent_type, var->index);
 	      return !(field_name == NULL || *field_name == '\0');
 	    }
@@ -202,7 +202,7 @@ c_number_of_children (const struct varobj *var)
 
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
-      children = TYPE_NFIELDS (type);
+      children = type->num_fields ();
       break;
 
     case TYPE_CODE_PTR:
@@ -649,7 +649,7 @@ cplus_class_num_children (struct type *type, int children[3])
   children[v_protected] = 0;
 
   vptr_fieldno = get_vptr_fieldno (type, &basetype);
-  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); i++)
+  for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
     {
       /* If we have a virtual table pointer, omit it.  Even if virtual
 	 table pointers are not specifically marked in the debug info,
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 59d6d231151..a2b69f44769 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1452,10 +1452,10 @@ patch_type (struct type *type, struct type *real_type)
 {
   struct type *target = TYPE_TARGET_TYPE (type);
   struct type *real_target = TYPE_TARGET_TYPE (real_type);
-  int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
+  int field_size = real_target->num_fields () * sizeof (struct field);
 
   TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
-  target->set_num_fields (TYPE_NFIELDS (real_target));
+  target->set_num_fields (real_target->num_fields ());
   TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target,
 						      field_size);
 
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index ab9f4425b7c..8b3cd370aa4 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -526,7 +526,7 @@ generate_vla_size (compile_instance *compiler,
       {
 	int i;
 
-	for (i = 0; i < TYPE_NFIELDS (type); ++i)
+	for (i = 0; i < type->num_fields (); ++i)
 	  if (!field_is_static (&TYPE_FIELD (type, i)))
 	    generate_vla_size (compiler, stream, gdbarch, registers_used, pc,
 			       TYPE_FIELD_TYPE (type, i), sym);
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 8f6ed0571ca..c4f5811678e 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -103,7 +103,7 @@ convert_struct_or_union (compile_c_instance *context, struct type *type)
     }
   context->insert_type (type, result);
 
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (i = 0; i < type->num_fields (); ++i)
     {
       gcc_type field_type;
       unsigned long bitsize = TYPE_FIELD_BITSIZE (type, i);
@@ -134,7 +134,7 @@ convert_enum (compile_c_instance *context, struct type *type)
 					     TYPE_LENGTH (type));
 
   result = context->plugin ().build_enum_type (int_type);
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (i = 0; i < type->num_fields (); ++i)
     {
       context->plugin ().build_add_enum_constant
 	(result, TYPE_FIELD_NAME (type, i), TYPE_FIELD_ENUMVAL (type, i));
@@ -175,9 +175,9 @@ convert_func (compile_c_instance *context, struct type *type)
      types.  Those are impossible in C, though.  */
   return_type = context->convert_type (target_type);
 
-  array.n_elements = TYPE_NFIELDS (type);
-  array.elements = XNEWVEC (gcc_type, TYPE_NFIELDS (type));
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  array.n_elements = type->num_fields ();
+  array.elements = XNEWVEC (gcc_type, type->num_fields ());
+  for (i = 0; i < type->num_fields (); ++i)
     array.elements[i] = context->convert_type (TYPE_FIELD_TYPE (type, i));
 
   result = context->plugin ().build_function_type (return_type,
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 523ab34b403..b2a4544c041 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -580,7 +580,7 @@ static void
 compile_cplus_convert_struct_or_union_members
   (compile_cplus_instance *instance, struct type *type, gcc_type comp_type)
 {
-  for (int i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); ++i)
+  for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); ++i)
     {
       const char *field_name = TYPE_FIELD_NAME (type, i);
 
@@ -938,7 +938,7 @@ compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
 					      ? GCC_CP_FLAG_ENUM_SCOPED
 					      : GCC_CP_FLAG_ENUM_NOFLAG),
 					   nullptr, 0);
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     {
       gdb::unique_xmalloc_ptr<char> fname
 	= compile_cplus_instance::decl_name (TYPE_FIELD_NAME (type, i));
@@ -986,9 +986,9 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
   gcc_type return_type = instance->convert_type (target_type);
 
   struct gcc_type_array array =
-    { TYPE_NFIELDS (type), XNEWVEC (gcc_type, TYPE_NFIELDS (type)) };
+    { type->num_fields (), XNEWVEC (gcc_type, type->num_fields ()) };
   int artificials = 0;
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     {
       if (strip_artificial && TYPE_FIELD_ARTIFICIAL (type, i))
 	{
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 76a9418dac0..7f5f5931f21 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -505,7 +505,7 @@ get_regs_type (struct symbol *func_sym, struct objfile *objfile)
   struct type *regsp_type, *regs_type;
 
   /* No register parameter present.  */
-  if (TYPE_NFIELDS (func_type) == 0)
+  if (func_type->num_fields () == 0)
     return NULL;
 
   regsp_type = check_typedef (TYPE_FIELD_TYPE (func_type, 0));
@@ -534,7 +534,7 @@ store_regs (struct type *regs_type, CORE_ADDR regs_base)
   struct gdbarch *gdbarch = target_gdbarch ();
   int fieldno;
 
-  for (fieldno = 0; fieldno < TYPE_NFIELDS (regs_type); fieldno++)
+  for (fieldno = 0; fieldno < regs_type->num_fields (); fieldno++)
     {
       const char *reg_name = TYPE_FIELD_NAME (regs_type, fieldno);
       ULONGEST reg_bitpos = TYPE_FIELD_BITPOS (regs_type, fieldno);
@@ -670,10 +670,10 @@ compile_object_load (const compile_file_names &file_names,
     default:
       internal_error (__FILE__, __LINE__, _("invalid scope %d"), scope);
     }
-  if (TYPE_NFIELDS (func_type) != expect_parameters)
+  if (func_type->num_fields () != expect_parameters)
     error (_("Invalid %d parameters of function \"%s\" in compiled "
 	     "module \"%s\"."),
-	   TYPE_NFIELDS (func_type), GCC_FE_WRAPPER_FUNCTION,
+	   func_type->num_fields (), GCC_FE_WRAPPER_FUNCTION,
 	   objfile_name (objfile));
   if (!types_deeply_equal (expect_return_type, TYPE_TARGET_TYPE (func_type)))
     error (_("Invalid return type of function \"%s\" in compiled "
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index cef1d06adf7..d8e28532566 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -153,23 +153,23 @@ compile_object_run (struct compile_module *module)
       func_val = value_from_pointer (lookup_pointer_type (func_type),
 				   BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func_sym)));
 
-      vargs = XALLOCAVEC (struct value *, TYPE_NFIELDS (func_type));
-      if (TYPE_NFIELDS (func_type) >= 1)
+      vargs = XALLOCAVEC (struct value *, func_type->num_fields ());
+      if (func_type->num_fields () >= 1)
 	{
 	  gdb_assert (regs_addr != 0);
 	  vargs[current_arg] = value_from_pointer
 			  (TYPE_FIELD_TYPE (func_type, current_arg), regs_addr);
 	  ++current_arg;
 	}
-      if (TYPE_NFIELDS (func_type) >= 2)
+      if (func_type->num_fields () >= 2)
 	{
 	  gdb_assert (data->out_value_addr != 0);
 	  vargs[current_arg] = value_from_pointer
 	       (TYPE_FIELD_TYPE (func_type, current_arg), data->out_value_addr);
 	  ++current_arg;
 	}
-      gdb_assert (current_arg == TYPE_NFIELDS (func_type));
-      auto args = gdb::make_array_view (vargs, TYPE_NFIELDS (func_type));
+      gdb_assert (current_arg == func_type->num_fields ());
+      auto args = gdb::make_array_view (vargs, func_type->num_fields ());
       call_function_by_hand_dummy (func_val, NULL, args,
 				   do_module_cleanup, data);
     }
diff --git a/gdb/completer.c b/gdb/completer.c
index d03dc77c65d..ad33b98c696 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1090,7 +1090,7 @@ add_struct_fields (struct type *type, completion_list &output,
   const char *type_name = NULL;
 
   type = check_typedef (type);
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (i = 0; i < type->num_fields (); ++i)
     {
       if (i < TYPE_N_BASECLASSES (type))
 	add_struct_fields (TYPE_BASECLASS (type, i),
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 1fb7edd5b05..a59afec4958 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -149,7 +149,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
     }
 
   fprintf_filtered (stream, "{");
-  len = TYPE_NFIELDS (type);
+  len = type->num_fields ();
   n_baseclasses = TYPE_N_BASECLASSES (type);
 
   /* First, print out baseclasses such that we don't print
@@ -638,7 +638,7 @@ cp_find_class_member (struct type **self_p, int *fieldno,
 
   *self_p = check_typedef (*self_p);
   self = *self_p;
-  len = TYPE_NFIELDS (self);
+  len = self->num_fields ();
 
   for (i = TYPE_N_BASECLASSES (self); i < len; i++)
     {
diff --git a/gdb/d-valprint.c b/gdb/d-valprint.c
index cb0f5095dfc..34f8b05a62b 100644
--- a/gdb/d-valprint.c
+++ b/gdb/d-valprint.c
@@ -34,7 +34,7 @@ dynamic_array_type (struct type *type,
 		    struct value *val,
 		    const struct value_print_options *options)
 {
-  if (TYPE_NFIELDS (type) == 2
+  if (type->num_fields () == 2
       && TYPE_FIELD_TYPE (type, 0)->code () == TYPE_CODE_INT
       && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
       && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 89ca038414e..dd69d6622b2 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9213,17 +9213,17 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
   /* When DISCRIMINANT_INDEX == -1, we have a univariant enum.  Those
      must be handled by the caller.  */
   gdb_assert (discriminant_index >= 0
-	      && discriminant_index < TYPE_NFIELDS (type));
+	      && discriminant_index < type->num_fields ());
   gdb_assert (default_index == -1
-	      || (default_index >= 0 && default_index < TYPE_NFIELDS (type)));
+	      || (default_index >= 0 && default_index < type->num_fields ()));
 
   /* We have one variant for each non-discriminant field.  */
-  int n_variants = TYPE_NFIELDS (type) - 1;
+  int n_variants = type->num_fields () - 1;
 
   variant *variants = new (obstack) variant[n_variants];
   int var_idx = 0;
   int range_idx = 0;
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     {
       if (i == discriminant_index)
 	continue;
@@ -9288,11 +9288,11 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
   gdb_assert (type->code () == TYPE_CODE_UNION);
 
   /* We don't need to deal with empty enums.  */
-  if (TYPE_NFIELDS (type) == 0)
+  if (type->num_fields () == 0)
     return;
 
 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
-  if (TYPE_NFIELDS (type) == 1
+  if (type->num_fields () == 1
       && startswith (TYPE_FIELD_NAME (type, 0), RUST_ENUM_PREFIX))
     {
       const char *name = TYPE_FIELD_NAME (type, 0) + strlen (RUST_ENUM_PREFIX);
@@ -9307,7 +9307,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	  unsigned long index = strtoul (name, &tail, 10);
 	  name = tail;
 	  if (*name != '$'
-	      || index >= TYPE_NFIELDS (field_type)
+	      || index >= field_type->num_fields ()
 	      || (TYPE_FIELD_LOC_KIND (field_type, index)
 		  != FIELD_LOC_KIND_BITPOS))
 	    {
@@ -9364,7 +9364,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
     }
   /* A union with a single anonymous field is probably an old-style
      univariant enum.  */
-  else if (TYPE_NFIELDS (type) == 1 && streq (TYPE_FIELD_NAME (type, 0), ""))
+  else if (type->num_fields () == 1 && streq (TYPE_FIELD_NAME (type, 0), ""))
     {
       /* Smash this type to be a structure type.  We have to do this
 	 because the type has already been recorded.  */
@@ -9381,7 +9381,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
   else
     {
       struct type *disr_type = nullptr;
-      for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+      for (int i = 0; i < type->num_fields (); ++i)
 	{
 	  disr_type = TYPE_FIELD_TYPE (type, i);
 
@@ -9390,7 +9390,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	      /* All fields of a true enum will be structs.  */
 	      return;
 	    }
-	  else if (TYPE_NFIELDS (disr_type) == 0)
+	  else if (disr_type->num_fields () == 0)
 	    {
 	      /* Could be data-less variant, so keep going.  */
 	      disr_type = nullptr;
@@ -9420,12 +9420,12 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       /* Make space for the discriminant field.  */
       struct field *disr_field = &TYPE_FIELD (disr_type, 0);
       field *new_fields
-	= (struct field *) TYPE_ZALLOC (type, ((TYPE_NFIELDS (type) + 1)
+	= (struct field *) TYPE_ZALLOC (type, ((type->num_fields () + 1)
 					       * sizeof (struct field)));
       memcpy (new_fields + 1, TYPE_FIELDS (type),
-	      TYPE_NFIELDS (type) * sizeof (struct field));
+	      type->num_fields () * sizeof (struct field));
       TYPE_FIELDS (type) = new_fields;
-      type->set_num_fields (TYPE_NFIELDS (type) + 1);
+      type->set_num_fields (type->num_fields () + 1);
 
       /* Install the discriminant at index 0 in the union.  */
       TYPE_FIELD (type, 0) = *disr_field;
@@ -9436,7 +9436,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	 variant name.  For convenience we build a map here.  */
       struct type *enum_type = FIELD_TYPE (*disr_field);
       std::unordered_map<std::string, ULONGEST> discriminant_map;
-      for (int i = 0; i < TYPE_NFIELDS (enum_type); ++i)
+      for (int i = 0; i < enum_type->num_fields (); ++i)
 	{
 	  if (TYPE_FIELD_LOC_KIND (enum_type, i) == FIELD_LOC_KIND_ENUMVAL)
 	    {
@@ -9446,7 +9446,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	    }
 	}
 
-      int n_fields = TYPE_NFIELDS (type);
+      int n_fields = type->num_fields ();
       /* We don't need a range entry for the discriminant, but we do
 	 need one for every other field, as there is no default
 	 variant.  */
@@ -9471,7 +9471,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 
 	  /* Remove the discriminant field, if it exists.  */
 	  struct type *sub_type = TYPE_FIELD_TYPE (type, i);
-	  if (TYPE_NFIELDS (sub_type) > 0)
+	  if (sub_type->num_fields () > 0)
 	    {
 	      sub_type->set_num_fields (sub_type->num_fields () - 1);
 	      ++TYPE_FIELDS (sub_type);
@@ -10297,7 +10297,7 @@ dwarf2_compute_name (const char *name,
 		     marks unnamed (and thus unused) parameters as
 		     artificial; there is no way to differentiate
 		     the two cases.  */
-		  if (TYPE_NFIELDS (type) > 0
+		  if (type->num_fields () > 0
 		      && TYPE_FIELD_ARTIFICIAL (type, 0)
 		      && TYPE_FIELD_TYPE (type, 0)->code () == TYPE_CODE_PTR
 		      && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type,
@@ -14960,14 +14960,14 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   this_type = read_type_die (die, cu);
   if (this_type && this_type->code () == TYPE_CODE_FUNC)
     {
-      int nparams = TYPE_NFIELDS (this_type);
+      int nparams = this_type->num_fields ();
 
       /* TYPE is the domain of this method, and THIS_TYPE is the type
 	   of the method itself (TYPE_CODE_METHOD).  */
       smash_to_method_type (fnp->type, type,
 			    TYPE_TARGET_TYPE (this_type),
 			    TYPE_FIELDS (this_type),
-			    TYPE_NFIELDS (this_type),
+			    this_type->num_fields (),
 			    TYPE_VARARGS (this_type));
 
       /* Handle static member functions.
@@ -15059,7 +15059,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 	      /* If there is no `this' field and no DW_AT_containing_type,
 		 we cannot actually find a base class context for the
 		 vtable!  */
-	      if (TYPE_NFIELDS (this_type) == 0
+	      if (this_type->num_fields () == 0
 		  || !TYPE_FIELD_ARTIFICIAL (this_type, 0))
 		{
 		  complaint (_("cannot determine context for virtual member "
@@ -15156,7 +15156,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   struct type *pfn_type, *self_type, *new_type;
 
   /* Check for a structure with no name and two children.  */
-  if (type->code () != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
+  if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
     return;
 
   /* Check for __pfn and __delta members.  */
@@ -15175,7 +15175,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
 
   /* Look for the "this" argument.  */
   pfn_type = TYPE_TARGET_TYPE (pfn_type);
-  if (TYPE_NFIELDS (pfn_type) == 0
+  if (pfn_type->num_fields () == 0
       /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
       || TYPE_FIELD_TYPE (pfn_type, 0)->code () != TYPE_CODE_PTR)
     return;
@@ -15183,7 +15183,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   self_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
   new_type = alloc_type (objfile);
   smash_to_method_type (new_type, self_type, TYPE_TARGET_TYPE (pfn_type),
-			TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type),
+			TYPE_FIELDS (pfn_type), pfn_type->num_fields (),
 			TYPE_VARARGS (pfn_type));
   smash_to_methodptr_type (type, new_type);
 }
@@ -15686,7 +15686,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 		  int i;
 
 		  /* Our own class provides vtbl ptr.  */
-		  for (i = TYPE_NFIELDS (t) - 1;
+		  for (i = t->num_fields () - 1;
 		       i >= TYPE_N_BASECLASSES (t);
 		       --i)
 		    {
@@ -15719,7 +15719,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 
 	      int i;
 
-	      for (i = TYPE_NFIELDS (type) - 1;
+	      for (i = type->num_fields () - 1;
 		   i >= TYPE_N_BASECLASSES (type);
 		   --i)
 		{
@@ -16686,7 +16686,7 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
 	= alloc_type (cu->per_cu->dwarf2_per_objfile->objfile);
 
       smash_to_method_type (new_type, domain, TYPE_TARGET_TYPE (to_type),
-			    TYPE_FIELDS (to_type), TYPE_NFIELDS (to_type),
+			    TYPE_FIELDS (to_type), to_type->num_fields (),
 			    TYPE_VARARGS (to_type));
       type = lookup_methodptr_type (new_type);
     }
diff --git a/gdb/eval.c b/gdb/eval.c
index 023b629c1aa..8104c956b42 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -295,11 +295,11 @@ evaluate_struct_tuple (struct value *struct_val,
 
       fieldno++;
       /* Skip static fields.  */
-      while (fieldno < TYPE_NFIELDS (struct_type)
+      while (fieldno < struct_type->num_fields ()
 	     && field_is_static (&TYPE_FIELD (struct_type,
 					      fieldno)))
 	fieldno++;
-      if (fieldno >= TYPE_NFIELDS (struct_type))
+      if (fieldno >= struct_type->num_fields ())
 	error (_("too many initializers"));
       field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
       if (field_type->code () == TYPE_CODE_UNION
@@ -1058,7 +1058,7 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
 	    type = TYPE_TARGET_TYPE (type);
 	  if (type && type->code () == TYPE_CODE_FUNC)
 	    {
-	      for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
+	      for (; tem <= nargs && tem <= type->num_fields (); tem++)
 		{
 		  argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type,
 								  tem - 1),
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 820ba5ff0ef..7057a06ef40 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -254,7 +254,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
 
     case TYPE_CODE_FUNC:
       {
-	int i, nfields = TYPE_NFIELDS (type);
+	int i, nfields = type->num_fields ();
 
 	f_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
 				     passed_a_ptr, 0,
@@ -430,7 +430,7 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show,
       if (show > 0)
 	{
 	  fputs_filtered ("\n", stream);
-	  for (index = 0; index < TYPE_NFIELDS (type); index++)
+	  for (index = 0; index < type->num_fields (); index++)
 	    {
 	      f_type_print_base (TYPE_FIELD_TYPE (type, index), stream,
 				 show - 1, level + 4);
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 76981fa4117..bd16a4348d3 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -313,7 +313,7 @@ f_value_print_innner (struct value *val, struct ui_file *stream, int recurse,
       /* Starting from the Fortran 90 standard, Fortran supports derived
          types.  */
       fprintf_filtered (stream, "( ");
-      for (index = 0; index < TYPE_NFIELDS (type); index++)
+      for (index = 0; index < type->num_fields (); index++)
         {
 	  struct value *field = value_field (val, index);
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f42657ab8f9..01d8530d0f5 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1040,14 +1040,14 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
       *highp = TYPE_HIGH_BOUND (type);
       return 1;
     case TYPE_CODE_ENUM:
-      if (TYPE_NFIELDS (type) > 0)
+      if (type->num_fields () > 0)
 	{
 	  /* The enums may not be sorted by value, so search all
 	     entries.  */
 	  int i;
 
 	  *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
-	  for (i = 0; i < TYPE_NFIELDS (type); i++)
+	  for (i = 0; i < type->num_fields (); i++)
 	    {
 	      if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
 		*lowp = TYPE_FIELD_ENUMVAL (type, i);
@@ -1159,7 +1159,7 @@ discrete_position (struct type *type, LONGEST val, LONGEST *pos)
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i += 1)
+      for (i = 0; i < type->num_fields (); i += 1)
         {
           if (val == TYPE_FIELD_ENUMVAL (type, i))
 	    {
@@ -1751,7 +1751,7 @@ lookup_struct_elt (struct type *type, const char *name, int noerr)
 	     type_name.c_str ());
     }
 
-  for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
+  for (i = type->num_fields () - 1; i >= TYPE_N_BASECLASSES (type); i--)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -2015,7 +2015,7 @@ is_dynamic_type_internal (struct type *type, int top_level)
 	 treated as one here.  */
     case TYPE_CODE_ARRAY:
       {
-	gdb_assert (TYPE_NFIELDS (type) == 1);
+	gdb_assert (type->num_fields () == 1);
 
 	/* The array is dynamic if either the bounds are dynamic...  */
 	if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type), 0))
@@ -2036,7 +2036,7 @@ is_dynamic_type_internal (struct type *type, int top_level)
 
 	bool is_cplus = HAVE_CPLUS_STRUCT (type);
 
-	for (i = 0; i < TYPE_NFIELDS (type); ++i)
+	for (i = 0; i < type->num_fields (); ++i)
 	  {
 	    /* Static fields can be ignored here.  */
 	    if (field_is_static (&TYPE_FIELD (type, i)))
@@ -2240,12 +2240,12 @@ resolve_dynamic_union (struct type *type,
   resolved_type = copy_type (type);
   TYPE_FIELDS (resolved_type)
     = (struct field *) TYPE_ALLOC (resolved_type,
-				   TYPE_NFIELDS (resolved_type)
+				   resolved_type->num_fields ()
 				   * sizeof (struct field));
   memcpy (TYPE_FIELDS (resolved_type),
 	  TYPE_FIELDS (type),
-	  TYPE_NFIELDS (resolved_type) * sizeof (struct field));
-  for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
+	  resolved_type->num_fields () * sizeof (struct field));
+  for (i = 0; i < resolved_type->num_fields (); ++i)
     {
       struct type *t;
 
@@ -2396,7 +2396,7 @@ compute_variant_fields (struct type *type,
 			const gdb::array_view<variant_part> &parts)
 {
   /* Assume all fields are included by default.  */
-  std::vector<bool> flags (TYPE_NFIELDS (resolved_type), true);
+  std::vector<bool> flags (resolved_type->num_fields (), true);
 
   /* Now disable fields based on the variants that control them.  */
   for (const auto &part : parts)
@@ -2406,10 +2406,10 @@ compute_variant_fields (struct type *type,
     (std::count (flags.begin (), flags.end (), true));
   TYPE_FIELDS (resolved_type)
     = (struct field *) TYPE_ALLOC (resolved_type,
-				   TYPE_NFIELDS (resolved_type)
+				   resolved_type->num_fields ()
 				   * sizeof (struct field));
   int out = 0;
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     {
       if (!flags[i])
 	continue;
@@ -2432,7 +2432,7 @@ resolve_dynamic_struct (struct type *type,
   unsigned resolved_type_bit_length = 0;
 
   gdb_assert (type->code () == TYPE_CODE_STRUCT);
-  gdb_assert (TYPE_NFIELDS (type) > 0);
+  gdb_assert (type->num_fields () > 0);
 
   resolved_type = copy_type (type);
 
@@ -2450,14 +2450,14 @@ resolve_dynamic_struct (struct type *type,
     {
       TYPE_FIELDS (resolved_type)
 	= (struct field *) TYPE_ALLOC (resolved_type,
-				       TYPE_NFIELDS (resolved_type)
+				       resolved_type->num_fields ()
 				       * sizeof (struct field));
       memcpy (TYPE_FIELDS (resolved_type),
 	      TYPE_FIELDS (type),
-	      TYPE_NFIELDS (resolved_type) * sizeof (struct field));
+	      resolved_type->num_fields () * sizeof (struct field));
     }
 
-  for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
+  for (i = 0; i < resolved_type->num_fields (); ++i)
     {
       unsigned new_bit_length;
       struct property_addr_info pinfo;
@@ -3388,7 +3388,7 @@ type_align (struct type *type)
     case TYPE_CODE_UNION:
       {
 	int number_of_non_static_fields = 0;
-	for (unsigned i = 0; i < TYPE_NFIELDS (type); ++i)
+	for (unsigned i = 0; i < type->num_fields (); ++i)
 	  {
 	    if (!field_is_static (&TYPE_FIELD (type, i)))
 	      {
@@ -3530,7 +3530,7 @@ is_scalar_type_recursive (struct type *t)
     return 1;
   /* Are we dealing with an array or string of known dimensions?  */
   else if ((t->code () == TYPE_CODE_ARRAY
-	    || t->code () == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1
+	    || t->code () == TYPE_CODE_STRING) && t->num_fields () == 1
 	   && TYPE_INDEX_TYPE(t)->code () == TYPE_CODE_RANGE)
     {
       LONGEST low_bound, high_bound;
@@ -3541,11 +3541,11 @@ is_scalar_type_recursive (struct type *t)
       return high_bound == low_bound && is_scalar_type_recursive (elt_type);
     }
   /* Are we dealing with a struct with one element?  */
-  else if (t->code () == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1)
+  else if (t->code () == TYPE_CODE_STRUCT && t->num_fields () == 1)
     return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0));
   else if (t->code () == TYPE_CODE_UNION)
     {
-      int i, n = TYPE_NFIELDS (t);
+      int i, n = t->num_fields ();
 
       /* If all elements of the union are scalar, then the union is scalar.  */
       for (i = 0; i < n; i++)
@@ -3943,13 +3943,13 @@ types_equal (struct type *a, struct type *b)
     {
       int i;
 
-      if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b))
+      if (a->num_fields () != b->num_fields ())
 	return false;
       
       if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b)))
 	return false;
 
-      for (i = 0; i < TYPE_NFIELDS (a); ++i)
+      for (i = 0; i < a->num_fields (); ++i)
 	if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i)))
 	  return false;
 
@@ -4008,7 +4008,7 @@ check_types_equal (struct type *type1, struct type *type2,
       || TYPE_VECTOR (type1) != TYPE_VECTOR (type2)
       || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2)
       || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2)
-      || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2))
+      || type1->num_fields () != type2->num_fields ())
     return false;
 
   if (!compare_maybe_null_strings (type1->name (), type2->name ()))
@@ -4025,7 +4025,7 @@ check_types_equal (struct type *type1, struct type *type2,
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type1); ++i)
+      for (i = 0; i < type1->num_fields (); ++i)
 	{
 	  const struct field *field1 = &TYPE_FIELD (type1, i);
 	  const struct field *field2 = &TYPE_FIELD (type2, i);
@@ -4762,7 +4762,7 @@ dump_fn_fieldlists (struct type *type, int spaces)
 				  gdb_stdout);
 	  printf_filtered ("\n");
 	  print_args (TYPE_FN_FIELD_ARGS (f, overload_idx),
-		      TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)),
+		      TYPE_FN_FIELD_TYPE (f, overload_idx)->num_fields (),
 		      spaces + 8 + 2);
 	  printfi_filtered (spaces + 8, "fcontext ");
 	  gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
@@ -4815,30 +4815,30 @@ print_cplus_stuff (struct type *type, int spaces)
 			TYPE_N_BASECLASSES (type));
       puts_filtered ("\n");
     }
-  if (TYPE_NFIELDS (type) > 0)
+  if (type->num_fields () > 0)
     {
       if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
 	{
 	  printfi_filtered (spaces, 
 			    "private_field_bits (%d bits at *",
-			    TYPE_NFIELDS (type));
+			    type->num_fields ());
 	  gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), 
 				  gdb_stdout);
 	  printf_filtered (")");
 	  print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
-			    TYPE_NFIELDS (type));
+			    type->num_fields ());
 	  puts_filtered ("\n");
 	}
       if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
 	{
 	  printfi_filtered (spaces, 
 			    "protected_field_bits (%d bits at *",
-			    TYPE_NFIELDS (type));
+			    type->num_fields ());
 	  gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), 
 				  gdb_stdout);
 	  printf_filtered (")");
 	  print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
-			    TYPE_NFIELDS (type));
+			    type->num_fields ());
 	  puts_filtered ("\n");
 	}
     }
@@ -4878,7 +4878,7 @@ recursive_dump_type (struct type *type, int spaces)
   if (spaces == 0)
     obstack_begin (&dont_print_type_obstack, 0);
 
-  if (TYPE_NFIELDS (type) > 0
+  if (type->num_fields () > 0
       || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0))
     {
       struct type **first_dont_print
@@ -5101,10 +5101,10 @@ recursive_dump_type (struct type *type, int spaces)
       puts_filtered (" TYPE_NOTTEXT");
     }
   puts_filtered ("\n");
-  printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
+  printfi_filtered (spaces, "nfields %d ", type->num_fields ());
   gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
   puts_filtered ("\n");
-  for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
+  for (idx = 0; idx < type->num_fields (); idx++)
     {
       if (type->code () == TYPE_CODE_ENUM)
 	printfi_filtered (spaces + 2,
@@ -5296,11 +5296,11 @@ copy_type_recursive (struct objfile *objfile,
   TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
 
   /* Copy the fields.  */
-  if (TYPE_NFIELDS (type))
+  if (type->num_fields ())
     {
       int i, nfields;
 
-      nfields = TYPE_NFIELDS (type);
+      nfields = type->num_fields ();
       TYPE_FIELDS (new_type) = (struct field *)
         TYPE_ZALLOC (new_type, nfields * sizeof (struct field));
       for (i = 0; i < nfields; i++)
@@ -5575,10 +5575,10 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
 			 struct type *field_type, const char *name)
 {
   int type_bitsize = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
-  int field_nr = TYPE_NFIELDS (type);
+  int field_nr = type->num_fields ();
 
   gdb_assert (type->code () == TYPE_CODE_FLAGS);
-  gdb_assert (TYPE_NFIELDS (type) + 1 <= type_bitsize);
+  gdb_assert (type->num_fields () + 1 <= type_bitsize);
   gdb_assert (start_bitpos >= 0 && start_bitpos < type_bitsize);
   gdb_assert (nr_bits >= 1 && nr_bits <= type_bitsize);
   gdb_assert (name != NULL);
@@ -5630,10 +5630,10 @@ append_composite_type_field_raw (struct type *t, const char *name,
 {
   struct field *f;
 
-  t->set_num_fields (TYPE_NFIELDS (t) + 1);
+  t->set_num_fields (t->num_fields () + 1);
   TYPE_FIELDS (t) = XRESIZEVEC (struct field, TYPE_FIELDS (t),
-				TYPE_NFIELDS (t));
-  f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]);
+				t->num_fields ());
+  f = &(TYPE_FIELDS (t)[t->num_fields () - 1]);
   memset (f, 0, sizeof f[0]);
   FIELD_TYPE (f[0]) = field;
   FIELD_NAME (f[0]) = name;
@@ -5657,7 +5657,7 @@ append_composite_type_field_aligned (struct type *t, const char *name,
   else if (t->code () == TYPE_CODE_STRUCT)
     {
       TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
-      if (TYPE_NFIELDS (t) > 1)
+      if (t->num_fields () > 1)
 	{
 	  SET_FIELD_BITPOS (f[0],
 			    (FIELD_BITPOS (f[-1])
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index da8d5e2a119..e5f46dca0d2 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1458,7 +1458,6 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_NFIELDS(thistype) ((thistype)->num_fields ())
 #define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
 
 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
@@ -1705,7 +1704,7 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define TYPE_IS_OPAQUE(thistype) \
   ((((thistype)->code () == TYPE_CODE_STRUCT) \
     || ((thistype)->code () == TYPE_CODE_UNION)) \
-   && (TYPE_NFIELDS (thistype) == 0) \
+   && ((thistype)->num_fields () == 0) \
    && (!HAVE_CPLUS_STRUCT (thistype) \
        || TYPE_NFN_FIELDS (thistype) == 0) \
    && (TYPE_STUB (thistype) || !TYPE_STUB_SUPPORTED (thistype)))
diff --git a/gdb/gnu-v2-abi.c b/gdb/gnu-v2-abi.c
index d4cf6b95629..9238f10986d 100644
--- a/gdb/gnu-v2-abi.c
+++ b/gdb/gnu-v2-abi.c
@@ -348,7 +348,7 @@ gnuv2_baseclass_offset (struct type *type, int index,
   if (BASETYPE_VIA_VIRTUAL (type, index))
     {
       /* Must hunt for the pointer to this virtual baseclass.  */
-      int i, len = TYPE_NFIELDS (type);
+      int i, len = type->num_fields ();
       int n_baseclasses = TYPE_N_BASECLASSES (type);
 
       /* First look for the virtual baseclass pointer
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index b0544319383..c1967e62bb7 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1326,7 +1326,7 @@ is_copy_or_move_constructor_type (struct type *class_type,
 				  type_code expected)
 {
   /* The method should take at least two arguments...  */
-  if (TYPE_NFIELDS (method_type) < 2)
+  if (method_type->num_fields () < 2)
     return false;
 
   /* ...and the second argument should be the same as the class
@@ -1343,7 +1343,7 @@ is_copy_or_move_constructor_type (struct type *class_type,
   /* ...and if any of the remaining arguments don't have a default value
      then this is not a copy or move constructor, but just a
      constructor.  */
-  for (int i = 2; i < TYPE_NFIELDS (method_type); i++)
+  for (int i = 2; i < method_type->num_fields (); i++)
     {
       arg_type = TYPE_FIELD_TYPE (method_type, i);
       /* FIXME aktemur/2019-10-31: As of this date, neither
@@ -1527,7 +1527,7 @@ gnuv3_pass_by_reference (struct type *type)
      are constructed whenever this class is.  We do not need to worry
      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_NFIELDS (type); fieldnum++)
+  for (fieldnum = 0; fieldnum < type->num_fields (); fieldnum++)
     if (!field_is_static (&TYPE_FIELD (type, fieldnum)))
       {
 	struct type *field_type = TYPE_FIELD_TYPE (type, fieldnum);
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 366ac368333..c97db1b9db7 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -73,7 +73,7 @@ gccgo_string_p (struct type *type)
 {
   /* gccgo strings don't necessarily have a name we can use.  */
 
-  if (TYPE_NFIELDS (type) == 2)
+  if (type->num_fields () == 2)
     {
       struct type *type0 = TYPE_FIELD_TYPE (type, 0);
       struct type *type1 = TYPE_FIELD_TYPE (type, 1);
@@ -106,7 +106,7 @@ gccgo_string_p (struct type *type)
 static int
 sixg_string_p (struct type *type)
 {
-  if (TYPE_NFIELDS (type) == 2
+  if (type->num_fields () == 2
       && type->name () != NULL
       && strcmp (type->name (), "string") == 0)
     return 1;
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 6ea6a3140cf..b216087e778 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -560,7 +560,7 @@ gdbscm_type_fields (SCM self)
     containing_type_scm = tyscm_scm_from_type (containing_type);
 
   result = SCM_EOL;
-  for (i = 0; i < TYPE_NFIELDS (containing_type); ++i)
+  for (i = 0; i < containing_type->num_fields (); ++i)
     result = scm_cons (tyscm_make_field_smob (containing_type_scm, i), result);
 
   return scm_reverse_x (result, SCM_EOL);
@@ -969,7 +969,7 @@ gdbscm_type_num_fields (SCM self)
     gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
 			       _(not_composite_error));
 
-  return scm_from_long (TYPE_NFIELDS (type));
+  return scm_from_long (type->num_fields ());
 }
 
 /* (type-field <gdb:type> string) -> <gdb:field>
@@ -997,7 +997,7 @@ gdbscm_type_field (SCM self, SCM field_scm)
   {
     gdb::unique_xmalloc_ptr<char> field = gdbscm_scm_to_c_string (field_scm);
 
-    for (int i = 0; i < TYPE_NFIELDS (type); i++)
+    for (int i = 0; i < type->num_fields (); i++)
       {
 	const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -1039,7 +1039,7 @@ gdbscm_type_has_field_p (SCM self, SCM field_scm)
     gdb::unique_xmalloc_ptr<char> field
       = gdbscm_scm_to_c_string (field_scm);
 
-    for (int i = 0; i < TYPE_NFIELDS (type); i++)
+    for (int i = 0; i < type->num_fields (); i++)
       {
 	const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -1105,11 +1105,11 @@ gdbscm_type_next_field_x (SCM self)
   type = t_smob->type;
 
   SCM_ASSERT_TYPE (scm_is_signed_integer (progress,
-					  0, TYPE_NFIELDS (type)),
+					  0, type->num_fields ()),
 		   progress, SCM_ARG1, FUNC_NAME, _("integer"));
   field = scm_to_int (progress);
 
-  if (field < TYPE_NFIELDS (type))
+  if (field < type->num_fields ())
     {
       result = tyscm_make_field_smob (object, field);
       itscm_set_iterator_smob_progress_x (i_smob, scm_from_int (field + 1));
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index 39081481790..8f9fc2dcb2e 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -136,7 +136,7 @@ i386_darwin_arg_type_alignment (struct type *type)
     {
       int i;
       int res = 4;
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	{
 	  int align
 	    = i386_darwin_arg_type_alignment (TYPE_FIELD_TYPE (type, i));
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index f4fe3a20c70..e87d7f36356 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2643,7 +2643,7 @@ i386_16_byte_align_p (struct type *type)
       || type->code () == TYPE_CODE_UNION)
     {
       int i;
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	{
 	  if (i386_16_byte_align_p (TYPE_FIELD_TYPE (type, i)))
 	    return 1;
@@ -2952,7 +2952,7 @@ i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
 
   /* Structures consisting of a single `float', `double' or 'long
      double' member are returned in %st(0).  */
-  if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
+  if (code == TYPE_CODE_STRUCT && type->num_fields () == 1)
     {
       type = check_typedef (TYPE_FIELD_TYPE (type, 0));
       if (type->code () == TYPE_CODE_FLT)
@@ -3020,7 +3020,7 @@ i386_return_value (struct gdbarch *gdbarch, struct value *function,
      the structure.  Since that should work for all structures that
      have only one member, we don't bother to check the member's type
      here.  */
-  if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
+  if (code == TYPE_CODE_STRUCT && type->num_fields () == 1)
     {
       type = check_typedef (TYPE_FIELD_TYPE (type, 0));
       return i386_return_value (gdbarch, function, type, regcache,
diff --git a/gdb/i386-windows-tdep.c b/gdb/i386-windows-tdep.c
index 7233b1f28f5..19428cb6cda 100644
--- a/gdb/i386-windows-tdep.c
+++ b/gdb/i386-windows-tdep.c
@@ -220,7 +220,7 @@ i386_windows_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* read_subroutine_type sets for non-static member functions the
      artificial flag of the first parameter ('this' pointer).  */
   if (type->code () == TYPE_CODE_METHOD
-      && TYPE_NFIELDS (type) > 0
+      && type->num_fields () > 0
       && TYPE_FIELD_ARTIFICIAL (type, 0)
       && TYPE_FIELD_TYPE (type, 0)->code () == TYPE_CODE_PTR)
     thiscall = 1;
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index de6273c8cc7..1d1fd2e5f0e 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -3340,7 +3340,7 @@ is_float_or_hfa_type_recurse (struct type *t, struct type **etp)
       {
 	int i;
 
-	for (i = 0; i < TYPE_NFIELDS (t); i++)
+	for (i = 0; i < t->num_fields (); i++)
 	  if (!is_float_or_hfa_type_recurse
 	      (check_typedef (TYPE_FIELD_TYPE (t, i)), etp))
 	    return 0;
@@ -3389,7 +3389,7 @@ slot_alignment_is_next_even (struct type *t)
       {
 	int i;
 
-	for (i = 0; i < TYPE_NFIELDS (t); i++)
+	for (i = 0; i < t->num_fields (); i++)
 	  if (slot_alignment_is_next_even
 	      (check_typedef (TYPE_FIELD_TYPE (t, i))))
 	    return 1;
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 8da843a0190..d211ad88df8 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -827,7 +827,7 @@ call_function_by_hand_dummy (struct value *function,
 
   values_type = check_typedef (values_type);
 
-  if (args.size () < TYPE_NFIELDS (ftype))
+  if (args.size () < ftype->num_fields ())
     error (_("Too few arguments in function call."));
 
   /* A holder for the inferior status.
@@ -1027,7 +1027,7 @@ call_function_by_hand_dummy (struct value *function,
 	 prototyped.  Can we respect TYPE_VARARGS?  Probably not.  */
       if (ftype->code () == TYPE_CODE_METHOD)
 	prototyped = 1;
-      if (TYPE_TARGET_TYPE (ftype) == NULL && TYPE_NFIELDS (ftype) == 0
+      if (TYPE_TARGET_TYPE (ftype) == NULL && ftype->num_fields () == 0
 	  && default_return_type != NULL)
 	{
 	  /* Calling a no-debug function with the return type
@@ -1042,12 +1042,12 @@ call_function_by_hand_dummy (struct value *function,
 	  */
 	  prototyped = 1;
 	}
-      else if (i < TYPE_NFIELDS (ftype))
+      else if (i < ftype->num_fields ())
 	prototyped = TYPE_PROTOTYPED (ftype);
       else
 	prototyped = 0;
 
-      if (i < TYPE_NFIELDS (ftype))
+      if (i < ftype->num_fields ())
 	param_type = TYPE_FIELD_TYPE (ftype, i);
       else
 	param_type = NULL;
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index 1767a457ca7..18d207535b4 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -604,7 +604,7 @@ iq2000_pass_8bytetype_by_address (struct type *type)
       && type->code () != TYPE_CODE_UNION)
     return 0;
   /* Structs with more than 1 field are always passed by address.  */
-  if (TYPE_NFIELDS (type) != 1)
+  if (type->num_fields () != 1)
     return 1;
   /* Get field type.  */
   ftype = (TYPE_FIELDS (type))[0].type;
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 99222993f4a..d2596b256d2 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -284,7 +284,7 @@ m2_procedure (struct type *type, struct ui_file *stream,
   if (TYPE_TARGET_TYPE (type) == NULL
       || TYPE_TARGET_TYPE (type)->code () != TYPE_CODE_VOID)
     {
-      int i, len = TYPE_NFIELDS (type);
+      int i, len = type->num_fields ();
 
       fprintf_filtered (stream, " (");
       for (i = 0; i < len; i++)
@@ -311,7 +311,7 @@ m2_print_bounds (struct type *type,
 {
   struct type *target = TYPE_TARGET_TYPE (type);
 
-  if (TYPE_NFIELDS(type) == 0)
+  if (type->num_fields () == 0)
     return;
 
   if (print_high)
@@ -346,7 +346,7 @@ m2_is_long_set (struct type *type)
 
       /* check if all fields of the RECORD are consecutive sets.  */
 
-      len = TYPE_NFIELDS (type);
+      len = type->num_fields ();
       for (i = TYPE_N_BASECLASSES (type); i < len; i++)
 	{
 	  if (TYPE_FIELD_TYPE (type, i) == NULL)
@@ -409,7 +409,7 @@ m2_is_long_set_of_type (struct type *type, struct type **of_type)
 
   if (type->code () == TYPE_CODE_STRUCT)
     {
-      len = TYPE_NFIELDS (type);
+      len = type->num_fields ();
       i = TYPE_N_BASECLASSES (type);
       if (len == 0)
 	return 0;
@@ -434,7 +434,7 @@ m2_long_set (struct type *type, struct ui_file *stream, int show, int level,
 {
   struct type *of_type;
   int i;
-  int len = TYPE_NFIELDS (type);
+  int len = type->num_fields ();
   LONGEST low;
   LONGEST high;
 
@@ -490,7 +490,7 @@ m2_is_unbounded_array (struct type *type)
        *  type of _m2_contents is a pointer.  The TYPE_TARGET_TYPE
        *  of the pointer determines the unbounded ARRAY OF type.
        */
-      if (TYPE_NFIELDS (type) != 2)
+      if (type->num_fields () != 2)
 	return 0;
       if (strcmp (TYPE_FIELD_NAME (type, 0), "_m2_contents") != 0)
 	return 0;
@@ -550,7 +550,7 @@ m2_record_fields (struct type *type, struct ui_file *stream, int show,
   else if (show > 0)
     {
       int i;
-      int len = TYPE_NFIELDS (type);
+      int len = type->num_fields ();
 
       if (type->code () == TYPE_CODE_STRUCT)
 	fprintf_filtered (stream, "RECORD\n");
@@ -601,7 +601,7 @@ m2_enum (struct type *type, struct ui_file *stream, int show, int level)
   else if (show > 0 || type->name () == NULL)
     {
       fprintf_filtered (stream, "(");
-      len = TYPE_NFIELDS (type);
+      len = type->num_fields ();
       lastval = 0;
       for (i = 0; i < len; i++)
 	{
diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c
index f0166118634..f9cb626fd68 100644
--- a/gdb/m2-valprint.c
+++ b/gdb/m2-valprint.c
@@ -51,7 +51,7 @@ get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high)
 
   if (type->code () == TYPE_CODE_STRUCT)
     {
-      len = TYPE_NFIELDS (type);
+      len = type->num_fields ();
       i = TYPE_N_BASECLASSES (type);
       if (len == 0)
 	return 0;
@@ -83,7 +83,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
   type = check_typedef (type);
 
   fprintf_filtered (stream, "{");
-  len = TYPE_NFIELDS (type);
+  len = type->num_fields ();
   if (get_long_set_bounds (type, &low_bound, &high_bound))
     {
       field = TYPE_N_BASECLASSES (type);
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index a49937a7bd2..d579616b06a 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -2033,7 +2033,7 @@ m32c_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
        separately, but the code in GCC doesn't actually do so.  */
     if (TYPE_PROTOTYPED (func_type))
 #endif
-      num_prototyped_args = TYPE_NFIELDS (func_type);
+      num_prototyped_args = func_type->num_fields ();
   }
 
   /* First, if the function returns an aggregate by value, push a
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 46a0f093201..578cfdbf19a 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -463,7 +463,7 @@ m68k_svr4_return_value (struct gdbarch *gdbarch, struct value *function,
      changing TYPE into the type of the first member of the structure.
      Since that should work for all structures that have only one
      member, we don't bother to check the member's type here.  */
-  if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
+  if (code == TYPE_CODE_STRUCT && type->num_fields () == 1)
     {
       type = check_typedef (TYPE_FIELD_TYPE (type, 0));
       return m68k_svr4_return_value (gdbarch, function, type, regcache,
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 1b499ccad34..f634dbb08f1 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1036,7 +1036,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 	       are hopefully rare enough.
 	       Alpha cc -migrate has a sh.value field of zero, we adjust
 	       that too.  */
-	    if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
+	    if (TYPE_LENGTH (t) == t->num_fields ()
 		|| TYPE_LENGTH (t) == 0)
 	      TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
 	    for (ext_tsym = ext_sh + external_sym_size;
@@ -1085,7 +1085,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 
 	/* gcc puts out an empty struct for an opaque struct definitions,
 	   do not create a symbol for it either.  */
-	if (TYPE_NFIELDS (t) == 0)
+	if (t->num_fields () == 0)
 	  {
 	    TYPE_STUB (t) = 1;
 	    break;
@@ -1174,7 +1174,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		}
 	    }
 
-	  if (TYPE_NFIELDS (ftype) <= 0)
+	  if (ftype->num_fields () <= 0)
 	    {
 	      /* No parameter type information is recorded with the function's
 	         type.  Set that from the type of the parameter symbols.  */
@@ -1297,7 +1297,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 
       /* Incomplete definitions of structs should not get a name.  */
       if (SYMBOL_TYPE (s)->name () == NULL
-	  && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
+	  && (SYMBOL_TYPE (s)->num_fields () != 0
 	      || (SYMBOL_TYPE (s)->code () != TYPE_CODE_STRUCT
 		  && SYMBOL_TYPE (s)->code () != TYPE_CODE_UNION)))
 	{
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index df59f416b8e..a3ab8c80e37 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -4407,7 +4407,7 @@ fp_register_arg_p (struct gdbarch *gdbarch, enum type_code typecode,
 	   || (MIPS_EABI (gdbarch)
 	       && (typecode == TYPE_CODE_STRUCT
 		   || typecode == TYPE_CODE_UNION)
-	       && TYPE_NFIELDS (arg_type) == 1
+	       && arg_type->num_fields () == 1
 	       && check_typedef (TYPE_FIELD_TYPE (arg_type, 0))->code ()
 	       == TYPE_CODE_FLT))
 	  && MIPS_FPU_TYPE(gdbarch) != MIPS_FPU_NONE);
@@ -4425,7 +4425,7 @@ mips_type_needs_double_align (struct type *type)
     return 1;
   else if (typecode == TYPE_CODE_STRUCT)
     {
-      if (TYPE_NFIELDS (type) < 1)
+      if (type->num_fields () < 1)
 	return 0;
       return mips_type_needs_double_align (TYPE_FIELD_TYPE (type, 0));
     }
@@ -4433,7 +4433,7 @@ mips_type_needs_double_align (struct type *type)
     {
       int i, n;
 
-      n = TYPE_NFIELDS (type);
+      n = type->num_fields ();
       for (i = 0; i < n; i++)
 	if (mips_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
 	  return 1;
@@ -4788,7 +4788,7 @@ mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
 	 are returned in a floating point register.  */
       if ((type->code () == TYPE_CODE_STRUCT
 	   || type->code () == TYPE_CODE_UNION)
-	  && TYPE_NFIELDS (type) == 1)
+	  && type->num_fields () == 1)
 	{
 	  struct type *fieldtype = TYPE_FIELD_TYPE (type, 0);
 
@@ -4850,7 +4850,7 @@ mips_n32n64_fp_arg_chunk_p (struct gdbarch *gdbarch, struct type *arg_type,
   if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE)
     return 0;
 
-  for (i = 0; i < TYPE_NFIELDS (arg_type); i++)
+  for (i = 0; i < arg_type->num_fields (); i++)
     {
       int pos;
       struct type *field_type;
@@ -5226,12 +5226,12 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
       return RETURN_VALUE_REGISTER_CONVENTION;
     }
   else if (type->code () == TYPE_CODE_STRUCT
-	   && TYPE_NFIELDS (type) <= 2
-	   && TYPE_NFIELDS (type) >= 1
-	   && ((TYPE_NFIELDS (type) == 1
+	   && type->num_fields () <= 2
+	   && type->num_fields () >= 1
+	   && ((type->num_fields () == 1
 		&& (check_typedef (TYPE_FIELD_TYPE (type, 0))->code ()
 		    == TYPE_CODE_FLT))
-	       || (TYPE_NFIELDS (type) == 2
+	       || (type->num_fields () == 2
 		   && (check_typedef (TYPE_FIELD_TYPE (type, 0))->code ()
 		       == TYPE_CODE_FLT)
 		   && (check_typedef (TYPE_FIELD_TYPE (type, 1))->code ()
@@ -5245,7 +5245,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
       for (field = 0, regnum = (tdep->mips_fpu_type != MIPS_FPU_NONE
 				? mips_regnum (gdbarch)->fp0
 				: MIPS_V0_REGNUM);
-	   field < TYPE_NFIELDS (type); field++, regnum += 2)
+	   field < type->num_fields (); field++, regnum += 2)
 	{
 	  int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
 			/ TARGET_CHAR_BIT);
@@ -5779,12 +5779,12 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
     }
 #if 0
   else if (type->code () == TYPE_CODE_STRUCT
-	   && TYPE_NFIELDS (type) <= 2
-	   && TYPE_NFIELDS (type) >= 1
-	   && ((TYPE_NFIELDS (type) == 1
+	   && type->num_fields () <= 2
+	   && type->num_fields () >= 1
+	   && ((type->num_fields () == 1
 		&& (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
 		    == TYPE_CODE_FLT))
-	       || (TYPE_NFIELDS (type) == 2
+	       || (type->num_fields () == 2
 		   && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0))
 		       == TYPE_CODE_FLT)
 		   && (TYPE_CODE (TYPE_FIELD_TYPE (type, 1))
@@ -5797,7 +5797,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
       int regnum;
       int field;
       for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
-	   field < TYPE_NFIELDS (type); field++, regnum += 2)
+	   field < type->num_fields (); field++, regnum += 2)
 	{
 	  int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
 			/ TARGET_CHAR_BIT);
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 98660485f7c..7f81c5985ff 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -107,7 +107,7 @@ mn10300_type_align (struct type *type)
 
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	{
 	  int falign = mn10300_type_align (TYPE_FIELD_TYPE (type, i));
 	  while (align < falign)
@@ -143,7 +143,7 @@ mn10300_use_struct_convention (struct type *type)
     case TYPE_CODE_UNION:
       /* Structures with a single field are handled as the field
 	 itself.  */
-      if (TYPE_NFIELDS (type) == 1)
+      if (type->num_fields () == 1)
 	return mn10300_use_struct_convention (TYPE_FIELD_TYPE (type, 0));
 
       /* Structures with word or double-word size are passed in memory, as
diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index d4d07c030f1..d403b71f10b 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -1405,7 +1405,7 @@ nds32_check_calling_use_fpr (struct type *type)
       typecode = t->code ();
       if (typecode != TYPE_CODE_STRUCT)
 	break;
-      else if (TYPE_NFIELDS (t) != 1)
+      else if (t->num_fields () != 1)
 	return 0;
       else
 	t = TYPE_FIELD_TYPE (t, 0);
@@ -1496,7 +1496,7 @@ nds32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 	 and pushes all unnamed arguments in stack.  */
 
       if (abi_use_fpr && TYPE_VARARGS (func_type)
-	  && i >= TYPE_NFIELDS (func_type))
+	  && i >= func_type->num_fields ())
 	goto use_stack;
 
       /* Try to use FPRs to pass arguments only when
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 37fb90c391d..75df206a2bd 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -635,7 +635,7 @@ or1k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
       int len = TYPE_LENGTH (arg_type);
       enum type_code typecode = arg_type->code ();
 
-      if (TYPE_VARARGS (func_type) && argnum >= TYPE_NFIELDS (func_type))
+      if (TYPE_VARARGS (func_type) && argnum >= func_type->num_fields ())
 	break; /* end or regular args, varargs go to stack.  */
 
       /* Extract the value, either a reference or the data.  */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 19dd8507335..aa483336d2c 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -104,7 +104,7 @@ is_pascal_string_type (struct type *type,int *length_pos,
     {
       /* Old Borland type pascal strings from Free Pascal Compiler.  */
       /* Two fields: length and st.  */
-      if (TYPE_NFIELDS (type) == 2
+      if (type->num_fields () == 2
 	  && TYPE_FIELD_NAME (type, 0)
 	  && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
 	  && TYPE_FIELD_NAME (type, 1)
@@ -124,7 +124,7 @@ is_pascal_string_type (struct type *type,int *length_pos,
         };
       /* GNU pascal strings.  */
       /* Three fields: Capacity, length and schema$ or _p_schema.  */
-      if (TYPE_NFIELDS (type) == 3
+      if (type->num_fields () == 3
 	  && TYPE_FIELD_NAME (type, 0)
 	  && strcmp (TYPE_FIELD_NAME (type, 0), "Capacity") == 0
 	  && TYPE_FIELD_NAME (type, 1)
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 05e28a49d3e..3246d4e82a5 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -309,7 +309,7 @@ static void
 pascal_print_func_args (struct type *type, struct ui_file *stream,
 			const struct type_print_options *flags)
 {
-  int i, len = TYPE_NFIELDS (type);
+  int i, len = type->num_fields ();
 
   if (len)
     {
@@ -559,7 +559,7 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
 	  pascal_type_print_derivation_info (stream, type);
 
 	  fprintf_filtered (stream, "\n");
-	  if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
+	  if ((type->num_fields () == 0) && (TYPE_NFN_FIELDS (type) == 0))
 	    {
 	      if (TYPE_STUB (type))
 		fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
@@ -576,7 +576,7 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
 	  /* If there is a base class for this type,
 	     do not print the field that it occupies.  */
 
-	  len = TYPE_NFIELDS (type);
+	  len = type->num_fields ();
 	  for (i = TYPE_N_BASECLASSES (type); i < len; i++)
 	    {
 	      QUIT;
@@ -758,7 +758,7 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
       else if (show > 0 || type->name () == NULL)
 	{
 	  fprintf_filtered (stream, "(");
-	  len = TYPE_NFIELDS (type);
+	  len = type->num_fields ();
 	  lastval = 0;
 	  for (i = 0; i < len; i++)
 	    {
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 44dcbf9dc42..284dc85bf8c 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -524,7 +524,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
   struct type *type = check_typedef (value_type (val));
 
   fprintf_filtered (stream, "{");
-  len = TYPE_NFIELDS (type);
+  len = type->num_fields ();
   n_baseclasses = TYPE_N_BASECLASSES (type);
 
   /* Print out baseclasses such that we don't print
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index 9dcf84c94c1..c0e6a929263 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -1138,7 +1138,7 @@ ppc64_aggregate_candidate (struct type *type,
 	  LONGEST count = 0;
 	  int i;
 
-	  for (i = 0; i < TYPE_NFIELDS (type); i++)
+	  for (i = 0; i < type->num_fields (); i++)
 	    {
 	      LONGEST sub_count;
 
@@ -1494,10 +1494,10 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
 	 single floating-point value, at any level of nesting of
 	 single-member structs, are passed in floating-point registers.  */
       if (type->code () == TYPE_CODE_STRUCT
-	  && TYPE_NFIELDS (type) == 1)
+	  && type->num_fields () == 1)
 	{
 	  while (type->code () == TYPE_CODE_STRUCT
-		 && TYPE_NFIELDS (type) == 1)
+		 && type->num_fields () == 1)
 	    type = check_typedef (TYPE_FIELD_TYPE (type, 0));
 
 	  if (type->code () == TYPE_CODE_FLT)
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 4b57e1638ed..dbe25ad8f6c 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1150,7 +1150,7 @@ typy_length (PyObject *self)
   if (type == NULL)
     return -1;
 
-  return TYPE_NFIELDS (type);
+  return type->num_fields ();
 }
 
 /* Implements boolean evaluation of gdb.Type.  Handle this like other
@@ -1193,7 +1193,7 @@ typy_getitem (PyObject *self, PyObject *key)
   if (type == NULL)
     return NULL;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i++)
+  for (i = 0; i < type->num_fields (); i++)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -1251,7 +1251,7 @@ typy_has_key (PyObject *self, PyObject *args)
   if (type == NULL)
     return NULL;
 
-  for (i = 0; i < TYPE_NFIELDS (type); i++)
+  for (i = 0; i < type->num_fields (); i++)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -1336,7 +1336,7 @@ typy_iterator_iternext (PyObject *self)
   typy_iterator_object *iter_obj = (typy_iterator_object *) self;
   struct type *type = iter_obj->source->type;
 
-  if (iter_obj->field < TYPE_NFIELDS (type))
+  if (iter_obj->field < type->num_fields ())
     {
       gdbpy_ref<> result = make_fielditem (type, iter_obj->field,
 					   iter_obj->kind);
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index dae6520f1f8..ac6f71f4711 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -642,11 +642,11 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
 
   if (regtype->code () == TYPE_CODE_FLT
       || (regtype->code () == TYPE_CODE_UNION
-	  && TYPE_NFIELDS (regtype) == 2
+	  && regtype->num_fields () == 2
 	  && TYPE_FIELD_TYPE (regtype, 0)->code () == TYPE_CODE_FLT
 	  && TYPE_FIELD_TYPE (regtype, 1)->code () == TYPE_CODE_FLT)
       || (regtype->code () == TYPE_CODE_UNION
-	  && TYPE_NFIELDS (regtype) == 3
+	  && regtype->num_fields () == 3
 	  && TYPE_FIELD_TYPE (regtype, 0)->code () == TYPE_CODE_FLT
 	  && TYPE_FIELD_TYPE (regtype, 1)->code () == TYPE_CODE_FLT
 	  && TYPE_FIELD_TYPE (regtype, 2)->code () == TYPE_CODE_FLT))
@@ -2044,7 +2044,7 @@ class riscv_struct_info
 void
 riscv_struct_info::analyse_inner (struct type *type, int offset)
 {
-  unsigned int count = TYPE_NFIELDS (type);
+  unsigned int count = type->num_fields ();
   unsigned int i;
 
   for (i = 0; i < count; ++i)
@@ -2445,7 +2445,7 @@ riscv_push_dummy_call (struct gdbarch *gdbarch,
       arg_type = check_typedef (value_type (arg_value));
 
       riscv_arg_location (gdbarch, info, &call_info, arg_type,
-			  TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
+			  TYPE_VARARGS (ftype) && i >= ftype->num_fields ());
 
       if (info->type != arg_type)
 	arg_value = value_cast (info->type, arg_value);
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 6e3e49259d0..47aa799754d 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2414,7 +2414,7 @@ rust_parser::convert_ast_to_expression (const struct rust_op *operation,
 
 	    if (!want_type
 		&& type->code () == TYPE_CODE_STRUCT
-		&& TYPE_NFIELDS (type) == 0)
+		&& type->num_fields () == 0)
 	      {
 		/* A unit-like struct.  */
 		write_exp_elt_opcode (pstate, OP_AGGREGATE);
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f0bea374ecb..f8696628474 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -81,7 +81,7 @@ rust_enum_p (struct type *type)
 static bool
 rust_empty_enum_p (const struct type *type)
 {
-  return TYPE_NFIELDS (type) == 0;
+  return type->num_fields () == 0;
 }
 
 /* Given an already-resolved enum type and contents, find which
@@ -91,7 +91,7 @@ static int
 rust_enum_variant (struct type *type)
 {
   /* The active variant is simply the first non-artificial field.  */
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     if (!TYPE_FIELD_ARTIFICIAL (type, i))
       return i;
 
@@ -126,7 +126,7 @@ rust_underscore_fields (struct type *type)
 
   if (type->code () != TYPE_CODE_STRUCT)
     return false;
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (i = 0; i < type->num_fields (); ++i)
     {
       if (!field_is_static (&TYPE_FIELD (type, i)))
 	{
@@ -149,7 +149,7 @@ rust_tuple_struct_type_p (struct type *type)
   /* This is just an approximation until DWARF can represent Rust more
      precisely.  We exclude zero-length structs because they may not
      be tuple structs, and there's no way to tell.  */
-  return TYPE_NFIELDS (type) > 0 && rust_underscore_fields (type);
+  return type->num_fields () > 0 && rust_underscore_fields (type);
 }
 
 /* Return true if TYPE is a slice type, otherwise false.  */
@@ -171,22 +171,22 @@ rust_range_type_p (struct type *type)
   int i;
 
   if (type->code () != TYPE_CODE_STRUCT
-      || TYPE_NFIELDS (type) > 2
+      || type->num_fields () > 2
       || type->name () == NULL
       || strstr (type->name (), "::Range") == NULL)
     return false;
 
-  if (TYPE_NFIELDS (type) == 0)
+  if (type->num_fields () == 0)
     return true;
 
   i = 0;
   if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
     {
-      if (TYPE_NFIELDS (type) == 1)
+      if (type->num_fields () == 1)
 	return true;
       i = 1;
     }
-  else if (TYPE_NFIELDS (type) == 2)
+  else if (type->num_fields () == 2)
     {
       /* First field had to be "start".  */
       return false;
@@ -255,7 +255,7 @@ rust_get_trait_object_pointer (struct value *value)
 {
   struct type *type = check_typedef (value_type (value));
 
-  if (type->code () != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2)
+  if (type->code () != TYPE_CODE_STRUCT || type->num_fields () != 2)
     return NULL;
 
   /* Try to be a bit resilient if the ABI changes.  */
@@ -402,7 +402,7 @@ val_print_struct (struct value *val, struct ui_file *stream, int recurse,
       if (type->name () != NULL)
         fprintf_filtered (stream, "%s", type->name ());
 
-      if (TYPE_NFIELDS (type) == 0)
+      if (type->num_fields () == 0)
         return;
 
       if (type->name () != NULL)
@@ -418,7 +418,7 @@ val_print_struct (struct value *val, struct ui_file *stream, int recurse,
   opts.deref_ref = 0;
 
   first_field = 1;
-  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (i = 0; i < type->num_fields (); ++i)
     {
       if (field_is_static (&TYPE_FIELD (type, i)))
         continue;
@@ -488,7 +488,7 @@ rust_print_enum (struct value *val, struct ui_file *stream, int recurse,
   val = value_field (val, variant_fieldno);
   struct type *variant_type = TYPE_FIELD_TYPE (type, variant_fieldno);
 
-  int nfields = TYPE_NFIELDS (variant_type);
+  int nfields = variant_type->num_fields ();
 
   bool is_tuple = rust_tuple_struct_type_p (variant_type);
 
@@ -510,7 +510,7 @@ rust_print_enum (struct value *val, struct ui_file *stream, int recurse,
     }
 
   bool first_field = true;
-  for (int j = 0; j < TYPE_NFIELDS (variant_type); j++)
+  for (int j = 0; j < variant_type->num_fields (); j++)
     {
       if (!first_field)
 	fputs_filtered (", ", stream);
@@ -721,7 +721,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
 	fputs_filtered (tagname, stream);
     }
 
-  if (TYPE_NFIELDS (type) == 0 && !is_tuple)
+  if (type->num_fields () == 0 && !is_tuple)
     return;
   if (for_rust_enum && !flags->print_offsets)
     fputs_filtered (is_tuple_struct ? "(" : "{", stream);
@@ -733,7 +733,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
      field indices here because it simplifies calls to
      print_offset_data::update below.  */
   std::vector<int> fields;
-  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+  for (int i = 0; i < type->num_fields (); ++i)
     {
       if (field_is_static (&TYPE_FIELD (type, i)))
 	continue;
@@ -783,7 +783,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
       /* Note that this check of "I" is ok because we only sorted the
 	 fields by offset when print_offsets was set, so we won't take
 	 this branch in that case.  */
-      else if (i + 1 < TYPE_NFIELDS (type))
+      else if (i + 1 < type->num_fields ())
 	fputs_filtered (", ", stream);
     }
 
@@ -855,7 +855,7 @@ rust_internal_print_type (struct type *type, const char *varstring,
       if (varstring != NULL)
 	fputs_filtered (varstring, stream);
       fputs_filtered ("(", stream);
-      for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+      for (int i = 0; i < type->num_fields (); ++i)
 	{
 	  QUIT;
 	  if (i > 0)
@@ -911,7 +911,7 @@ rust_internal_print_type (struct type *type, const char *varstring,
 	  }
 	fputs_filtered ("{\n", stream);
 
-	for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+	for (int i = 0; i < type->num_fields (); ++i)
 	  {
 	    const char *name = TYPE_FIELD_NAME (type, i);
 
@@ -1171,7 +1171,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside)
     error (_("Could not find function named '%s'"), name.c_str ());
 
   fn_type = SYMBOL_TYPE (sym.symbol);
-  if (TYPE_NFIELDS (fn_type) == 0)
+  if (fn_type->num_fields () == 0)
     error (_("Function '%s' takes no arguments"), name.c_str ());
 
   if (TYPE_FIELD_TYPE (fn_type, 0)->code () == TYPE_CODE_PTR)
@@ -1303,7 +1303,7 @@ rust_compute_range (struct type *type, struct value *range,
   *high = 0;
   *kind = BOTH_BOUND_DEFAULT;
 
-  if (TYPE_NFIELDS (type) == 0)
+  if (type->num_fields () == 0)
     return;
 
   i = 0;
@@ -1313,7 +1313,7 @@ rust_compute_range (struct type *type, struct value *range,
       *low = value_as_long (value_field (range, 0));
       ++i;
     }
-  if (TYPE_NFIELDS (type) > i
+  if (type->num_fields () > i
       && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
     {
       *kind = (*kind == BOTH_BOUND_DEFAULT
@@ -1365,7 +1365,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
 	base_type = TYPE_TARGET_TYPE (type);
       else if (rust_slice_type_p (type))
 	{
-	  for (int i = 0; i < TYPE_NFIELDS (type); ++i)
+	  for (int i = 0; i < type->num_fields (); ++i)
 	    {
 	      if (strcmp (TYPE_FIELD_NAME (type, i), "data_ptr") == 0)
 		{
@@ -1676,7 +1676,7 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp,
 	      }
 
 	    /* Tuples and tuple structs */
-	    nfields = TYPE_NFIELDS (type);
+	    nfields = type->num_fields ();
 
 	    if (field_number >= nfields || field_number < 0)
 	      {
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index 9963bc358d4..0a9b1e8e47a 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -687,7 +687,7 @@ rx_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
      of the ``arg_reg'' variable to get these other details correct.  */
 
   if (TYPE_VARARGS (func_type))
-    num_register_candidate_args = TYPE_NFIELDS (func_type) - 1;
+    num_register_candidate_args = func_type->num_fields () - 1;
   else
     num_register_candidate_args = 4;
 
@@ -796,7 +796,7 @@ rx_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 		      int p_arg_size = 4;
 
 		      if (TYPE_PROTOTYPED (func_type)
-			  && i < TYPE_NFIELDS (func_type))
+			  && i < func_type->num_fields ())
 			{
 			  struct type *p_arg_type =
 			    TYPE_FIELD_TYPE (func_type, i);
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index e94bf59b44d..d6f176a4867 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -1644,7 +1644,7 @@ s390_effective_inner_type (struct type *type, unsigned int min_size)
 
       /* Find a non-static field, if any.  Unless there's exactly one,
 	 abort the unwrapping.  */
-      for (int i = 0; i < TYPE_NFIELDS (type); i++)
+      for (int i = 0; i < type->num_fields (); i++)
 	{
 	  struct field f = TYPE_FIELD (type, i);
 
@@ -1938,7 +1938,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
      and arg_state.argp with the size of the parameter area.  */
   for (i = 0; i < nargs; i++)
     s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
-		     TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
+		     TYPE_VARARGS (ftype) && i >= ftype->num_fields ());
 
   param_area_start = align_down (arg_state.copy - arg_state.argp, 8);
 
@@ -1965,7 +1965,7 @@ s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* Write all parameters.  */
   for (i = 0; i < nargs; i++)
     s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
-		     TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
+		     TYPE_VARARGS (ftype) && i >= ftype->num_fields ());
 
   /* Store return PSWA.  In 31-bit mode, keep addressing mode bit.  */
   if (word_size == 4)
diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index 98ebeb2fcfc..b4f00e46ad4 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -478,7 +478,7 @@ score_type_needs_double_align (struct type *type)
     {
       int i, n;
 
-      n = TYPE_NFIELDS (type);
+      n = type->num_fields ();
       for (i = 0; i < n; i++)
         if (score_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
           return 1;
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index c6bef85588e..f134cf1c917 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -813,7 +813,7 @@ static int
 sh_use_struct_convention (int renesas_abi, struct type *type)
 {
   int len = TYPE_LENGTH (type);
-  int nelem = TYPE_NFIELDS (type);
+  int nelem = type->num_fields ();
 
   /* The Renesas ABI returns aggregate types always on stack.  */
   if (renesas_abi && (type->code () == TYPE_CODE_STRUCT
@@ -849,7 +849,7 @@ static int
 sh_use_struct_convention_nofpu (int renesas_abi, struct type *type)
 {
   /* The Renesas ABI returns long longs/doubles etc. always on stack.  */
-  if (renesas_abi && TYPE_NFIELDS (type) == 0 && TYPE_LENGTH (type) >= 8)
+  if (renesas_abi && type->num_fields () == 0 && TYPE_LENGTH (type) >= 8)
     return 1;
   return sh_use_struct_convention (renesas_abi, type);
 }
@@ -1046,7 +1046,7 @@ sh_treat_as_flt_p (struct type *type)
   if (type->code () != TYPE_CODE_STRUCT)
     return 0;
   /* Otherwise structs with more than one member are not treated as float.  */
-  if (TYPE_NFIELDS (type) != 1)
+  if (type->num_fields () != 1)
     return 0;
   /* Otherwise if the type of that member is float, the whole type is
      treated as float.  */
@@ -1084,7 +1084,7 @@ sh_push_dummy_call_fpu (struct gdbarch *gdbarch,
      registers have been used so far.  */
   if (sh_is_renesas_calling_convention (func_type)
       && TYPE_VARARGS (func_type))
-    last_reg_arg = TYPE_NFIELDS (func_type) - 2;
+    last_reg_arg = func_type->num_fields () - 2;
 
   /* First force sp to a 4-byte alignment.  */
   sp = sh_frame_align (gdbarch, sp);
@@ -1225,7 +1225,7 @@ sh_push_dummy_call_nofpu (struct gdbarch *gdbarch,
      registers have been used so far.  */
   if (sh_is_renesas_calling_convention (func_type)
       && TYPE_VARARGS (func_type))
-    last_reg_arg = TYPE_NFIELDS (func_type) - 2;
+    last_reg_arg = func_type->num_fields () - 2;
 
   /* First force sp to a 4-byte alignment.  */
   sp = sh_frame_align (gdbarch, sp);
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 2529ddc5158..5d6ef071099 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -1179,7 +1179,7 @@ sparc64_16_byte_align_p (struct type *type)
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	{
 	  struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
 
@@ -1256,7 +1256,7 @@ sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	{
 	  struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
 	  int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
@@ -1274,7 +1274,7 @@ sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
          probably in older releases to.  To appease GCC, if a
          structure has only a single `float' member, we store its
          value in %f1 too (we already have stored in %f0).  */
-      if (TYPE_NFIELDS (type) == 1)
+      if (type->num_fields () == 1)
 	{
 	  struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, 0));
 
@@ -1344,7 +1344,7 @@ sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	{
 	  struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
 	  int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index c3da9a239b4..daf88c851c7 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -3232,7 +3232,7 @@ read_tilde_fields (struct stab_field_info *fip, const char **pp,
 	  set_type_vptr_basetype (type, t);
 	  if (type == t)	/* Our own class provides vtbl ptr.  */
 	    {
-	      for (i = TYPE_NFIELDS (t) - 1;
+	      for (i = t->num_fields () - 1;
 		   i >= TYPE_N_BASECLASSES (t);
 		   --i)
 		{
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 20d73bb28f5..42f1b1ee690 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1966,7 +1966,7 @@ check_field (struct type *type, const char *name,
   /* The type may be a stub.  */
   type = check_typedef (type);
 
-  for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
+  for (i = type->num_fields () - 1; i >= TYPE_N_BASECLASSES (type); i--)
     {
       const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -5472,7 +5472,7 @@ completion_list_add_fields (completion_tracker &tracker,
       int j;
 
       if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
-	for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
+	for (j = TYPE_N_BASECLASSES (t); j < t->num_fields (); j++)
 	  if (TYPE_FIELD_NAME (t, j))
 	    completion_list_add_name (tracker, sym->language (),
 				      TYPE_FIELD_NAME (t, j),
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index eb9701548ce..57945d21db7 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -890,7 +890,7 @@ tic6x_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
   /* For a variadic C function, the last explicitly declared argument and all
      remaining arguments are passed on the stack.  */
   if (TYPE_VARARGS (func_type))
-    first_arg_on_stack = TYPE_NFIELDS (func_type) - 1;
+    first_arg_on_stack = func_type->num_fields () - 1;
 
   /* Now make space on the stack for the args.  */
   for (argnum = 0; argnum < nargs; argnum++)
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index e5009ea3800..a46f6a564c0 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -619,7 +619,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
     {
 
     case TYPE_CODE_ENUM:
-      len = TYPE_NFIELDS (type);
+      len = type->num_fields ();
       for (i = 0; i < len; i++)
 	{
 	  if (TYPE_FIELD_ENUMVAL (type, i) == val)
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 1e0fd41a532..298613e42c3 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -532,7 +532,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
      type whose size is greater than or equal to 4 -> returned in register.  */
   if ((type->code () == TYPE_CODE_STRUCT
        || type->code () == TYPE_CODE_UNION)
-       && TYPE_NFIELDS (type) == 1)
+       && type->num_fields () == 1)
     {
       fld_type = TYPE_FIELD_TYPE (type, 0);
       if (v850_type_is_scalar (fld_type) && TYPE_LENGTH (fld_type) >= 4)
@@ -553,7 +553,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
       && v850_type_is_scalar (TYPE_FIELD_TYPE (type, 0))
       && TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == 4)
     {
-      for (i = 1; i < TYPE_NFIELDS (type); ++i)
+      for (i = 1; i < type->num_fields (); ++i)
         {
 	  fld_type = TYPE_FIELD_TYPE (type, 0);
 	  if (fld_type->code () == TYPE_CODE_ARRAY)
@@ -572,7 +572,7 @@ v850_use_struct_convention (struct gdbarch *gdbarch, struct type *type)
      returned in register.  */
   if (type->code () == TYPE_CODE_UNION)
     {
-      for (i = 0; i < TYPE_NFIELDS (type); ++i)
+      for (i = 0; i < type->num_fields (); ++i)
         {
 	  fld_type = TYPE_FIELD_TYPE (type, 0);
 	  if (!v850_use_struct_convention (gdbarch, fld_type))
@@ -981,7 +981,7 @@ v850_eight_byte_align_p (struct type *type)
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (type); i++)
+      for (i = 0; i < type->num_fields (); i++)
 	{
 	  if (v850_eight_byte_align_p (TYPE_FIELD_TYPE (type, i)))
 	    return 1;
diff --git a/gdb/valops.c b/gdb/valops.c
index 40c8f34ea1d..8cbc3b92ec8 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1805,7 +1805,7 @@ do_search_struct_field (const char *name, struct value *arg1, LONGEST offset,
   nbases = TYPE_N_BASECLASSES (type);
 
   if (!looking_for_baseclass)
-    for (i = TYPE_NFIELDS (type) - 1; i >= nbases; i--)
+    for (i = type->num_fields () - 1; i >= nbases; i--)
       {
 	const char *t_field_name = TYPE_FIELD_NAME (type, i);
 
@@ -1851,7 +1851,7 @@ do_search_struct_field (const char *name, struct value *arg1, LONGEST offset,
 		   bitpos is zero in an anonymous union field, so we
 		   have to add the offset of the union here.  */
 		if (field_type->code () == TYPE_CODE_STRUCT
-		    || (TYPE_NFIELDS (field_type) > 0
+		    || (field_type->num_fields () > 0
 			&& TYPE_FIELD_BITPOS (field_type, 0) == 0))
 		  new_offset += TYPE_FIELD_BITPOS (type, i) / 8;
 
@@ -2007,7 +2007,7 @@ search_struct_method (const char *name, struct value **arg1p,
 	      {
 		if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
 			      TYPE_VARARGS (TYPE_FN_FIELD_TYPE (f, j)),
-			      TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, j)),
+			      TYPE_FN_FIELD_TYPE (f, j)->num_fields (),
 			      TYPE_FN_FIELD_ARGS (f, j), args))
 		  {
 		    if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
@@ -2219,7 +2219,7 @@ value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
     error (_("Attempt to extract a component of a value that is not a %s."),
 	   err);
 
-  for (i = TYPE_N_BASECLASSES (t); i < TYPE_NFIELDS (t); i++)
+  for (i = TYPE_N_BASECLASSES (t); i < t->num_fields (); i++)
     {
       if (!field_is_static (&TYPE_FIELD (t, i))
 	  && bitpos == TYPE_FIELD_BITPOS (t, i)
@@ -2957,11 +2957,11 @@ find_oload_champ (gdb::array_view<value *> args,
 
 	  if (methods != NULL)
 	    {
-	      nparms = TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (methods, ix));
+	      nparms = TYPE_FN_FIELD_TYPE (methods, ix)->num_fields ();
 	      static_offset = oload_method_static_p (methods, ix);
 	    }
 	  else
-	    nparms = TYPE_NFIELDS (SYMBOL_TYPE (functions[ix]));
+	    nparms = SYMBOL_TYPE (functions[ix])->num_fields ();
 
 	  parm_types.reserve (nparms);
 	  for (jj = 0; jj < nparms; jj++)
@@ -3121,7 +3121,7 @@ enum_constant_from_type (struct type *type, const char *name)
   gdb_assert (type->code () == TYPE_CODE_ENUM
 	      && TYPE_DECLARED_CLASS (type));
 
-  for (i = TYPE_N_BASECLASSES (type); i < TYPE_NFIELDS (type); ++i)
+  for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); ++i)
     {
       const char *fname = TYPE_FIELD_NAME (type, i);
       int len;
@@ -3189,14 +3189,14 @@ compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
 {
   int start = 0;
 
-  if (TYPE_NFIELDS (t1) > 0 && TYPE_FIELD_ARTIFICIAL (t1, 0))
+  if (t1->num_fields () > 0 && TYPE_FIELD_ARTIFICIAL (t1, 0))
     ++start;
 
   /* If skipping artificial fields, find the first real field
      in T1.  */
   if (skip_artificial)
     {
-      while (start < TYPE_NFIELDS (t1)
+      while (start < t1->num_fields ()
 	     && TYPE_FIELD_ARTIFICIAL (t1, start))
 	++start;
     }
@@ -3205,15 +3205,15 @@ compare_parameters (struct type *t1, struct type *t2, int skip_artificial)
 
   /* Special case: a method taking void.  T1 will contain no
      non-artificial fields, and T2 will contain TYPE_CODE_VOID.  */
-  if ((TYPE_NFIELDS (t1) - start) == 0 && TYPE_NFIELDS (t2) == 1
+  if ((t1->num_fields () - start) == 0 && t2->num_fields () == 1
       && TYPE_FIELD_TYPE (t2, 0)->code () == TYPE_CODE_VOID)
     return 1;
 
-  if ((TYPE_NFIELDS (t1) - start) == TYPE_NFIELDS (t2))
+  if ((t1->num_fields () - start) == t2->num_fields ())
     {
       int i;
 
-      for (i = 0; i < TYPE_NFIELDS (t2); ++i)
+      for (i = 0; i < t2->num_fields (); ++i)
 	{
 	  if (compare_ranks (rank_one_type (TYPE_FIELD_TYPE (t1, start + i),
 					    TYPE_FIELD_TYPE (t2, i), NULL),
@@ -3293,7 +3293,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
     error (_("Internal error: non-aggregate type "
 	     "to value_struct_elt_for_reference"));
 
-  for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--)
+  for (i = t->num_fields () - 1; i >= TYPE_N_BASECLASSES (t); i--)
     {
       const char *t_field_name = TYPE_FIELD_NAME (t, i);
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 4bd643e938d..17d091d6131 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -587,7 +587,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
   unsigned int i;
   unsigned int len;
 
-  len = TYPE_NFIELDS (type);
+  len = type->num_fields ();
   for (i = 0; i < len; i++)
     {
       QUIT;
@@ -1135,7 +1135,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
   const gdb_byte *valaddr = (value_contents_for_printing (original_value)
 			     + embedded_offset);
   ULONGEST val = unpack_long (type, valaddr);
-  int field, nfields = TYPE_NFIELDS (type);
+  int field, nfields = type->num_fields ();
   struct gdbarch *gdbarch = get_type_arch (type);
   struct type *bool_type = builtin_type (gdbarch)->builtin_bool;
 
-- 
2.26.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/4] gdb: add type::fields / type::set_fields
  2020-05-19 18:44 [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Simon Marchi
  2020-05-19 18:44 ` [PATCH 2/4] gdb: remove TYPE_NFIELDS macro Simon Marchi
@ 2020-05-19 18:44 ` Simon Marchi
  2020-05-22 20:21   ` Tom Tromey
  2020-05-19 18:44 ` [PATCH 4/4] gdb: remove TYPE_FIELDS macro Simon Marchi
  2020-05-22 20:16 ` [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Tom Tromey
  3 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2020-05-19 18:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Add the `fields` and `set_fields` methods on `struct type`, in order to
remove the `TYPE_FIELDS` macro.  In this patch, the `TYPE_FIELDS` macro
is changed to the `type::fields`, so all the call sites that use it to
set the fields array are changed to use `type::set_fields`.  The next
patch will remove `TYPE_FIELDS` entirely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <fields, set_fields>: New methods.
	(TYPE_FIELDS): Use type::fields.  Change all call sites that
	modify the propery to use type::set_fields instead.
---
 gdb/ada-lang.c    | 24 ++++++++++++---------
 gdb/buildsym.c    |  5 +++--
 gdb/coffread.c    | 22 +++++++++-----------
 gdb/ctfread.c     |  8 +++----
 gdb/dwarf2/read.c | 21 ++++++++++---------
 gdb/eval.c        |  4 ++--
 gdb/gdbtypes.c    | 53 +++++++++++++++++++++++++----------------------
 gdb/gdbtypes.h    | 14 ++++++++++++-
 gdb/gnu-v3-abi.c  |  4 ++--
 gdb/mdebugread.c  | 10 ++++-----
 gdb/rust-lang.c   |  4 ++--
 gdb/stabsread.c   | 21 +++++++++++--------
 12 files changed, 106 insertions(+), 84 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e91ad614ce2..1e6cc5f94a1 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8026,7 +8026,6 @@ empty_record (struct type *templ)
   struct type *type = alloc_type_copy (templ);
 
   type->set_code (TYPE_CODE_STRUCT);
-  TYPE_FIELDS (type) = NULL;
   INIT_NONE_SPECIFIC (type);
   type->set_name ("<empty>");
   TYPE_LENGTH (type) = 0;
@@ -8083,9 +8082,8 @@ ada_template_to_fixed_record_type_1 (struct type *type,
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
   rtype->set_num_fields (nfields);
-  TYPE_FIELDS (rtype) = (struct field *)
-    TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
+  rtype->set_fields
+   ((struct field *) TYPE_ZALLOC (rtype, nfields * sizeof (struct field)));
   rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
 
@@ -8358,10 +8356,14 @@ template_to_static_fixed_type (struct type *type0)
 	      type->set_code (type0->code ());
 	      INIT_NONE_SPECIFIC (type);
 	      type->set_num_fields (nfields);
-	      TYPE_FIELDS (type) = (struct field *)
-		TYPE_ALLOC (type, nfields * sizeof (struct field));
-	      memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
+
+	      field *fields =
+		((struct field *)
+		 TYPE_ALLOC (type, nfields * sizeof (struct field)));
+	      memcpy (fields, TYPE_FIELDS (type0),
 		      sizeof (struct field) * nfields);
+	      type->set_fields (fields);
+
 	      type->set_name (ada_type_name (type0));
 	      TYPE_FIXED_INSTANCE (type) = 1;
 	      TYPE_LENGTH (type) = 0;
@@ -8407,10 +8409,12 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
   rtype->set_code (TYPE_CODE_STRUCT);
   INIT_NONE_SPECIFIC (rtype);
   rtype->set_num_fields (nfields);
-  TYPE_FIELDS (rtype) =
+
+  field *fields =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
-          sizeof (struct field) * nfields);
+  memcpy (fields, TYPE_FIELDS (type), sizeof (struct field) * nfields);
+  rtype->set_fields (fields);
+
   rtype->set_name (ada_type_name (type));
   TYPE_FIXED_INSTANCE (rtype) = 1;
   TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index b25d09b5c0c..33bf6523e90 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -272,8 +272,9 @@ buildsym_compunit::finish_block_internal
 	  if (nparams > 0)
 	    {
 	      ftype->set_num_fields (nparams);
-	      TYPE_FIELDS (ftype) = (struct field *)
-		TYPE_ALLOC (ftype, nparams * sizeof (struct field));
+	      ftype->set_fields
+		((struct field *)
+		 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
 
 	      iparams = 0;
 	      /* Here we want to directly access the dictionary, because
diff --git a/gdb/coffread.c b/gdb/coffread.c
index a2b69f44769..cd65adddef3 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1456,12 +1456,10 @@ patch_type (struct type *type, struct type *real_type)
 
   TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
   target->set_num_fields (real_target->num_fields ());
-  TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target,
-						      field_size);
 
-  memcpy (TYPE_FIELDS (target), 
-	  TYPE_FIELDS (real_target), 
-	  field_size);
+  field *fields = (struct field *) TYPE_ALLOC (target, field_size);
+  memcpy (fields, real_target->fields (), field_size);
+  target->set_fields (fields);
 
   if (real_target->name ())
     {
@@ -1883,7 +1881,7 @@ decode_base_type (struct coff_symbol *cs,
 	  type->set_name (NULL);
 	  INIT_CPLUS_SPECIFIC (type);
 	  TYPE_LENGTH (type) = 0;
-	  TYPE_FIELDS (type) = 0;
+	  type->set_fields (nullptr);
 	  type->set_num_fields (0);
 	}
       else
@@ -1903,7 +1901,7 @@ decode_base_type (struct coff_symbol *cs,
 	  type->set_name (NULL);
 	  INIT_CPLUS_SPECIFIC (type);
 	  TYPE_LENGTH (type) = 0;
-	  TYPE_FIELDS (type) = 0;
+	  type->set_fields (nullptr);
 	  type->set_num_fields (0);
 	}
       else
@@ -1924,7 +1922,7 @@ decode_base_type (struct coff_symbol *cs,
 	  type->set_code (TYPE_CODE_ENUM);
 	  type->set_name (NULL);
 	  TYPE_LENGTH (type) = 0;
-	  TYPE_FIELDS (type) = 0;
+	  type->set_fields (nullptr);
 	  type->set_num_fields (0);
 	}
       else
@@ -2042,8 +2040,8 @@ coff_read_struct_type (int index, int length, int lastsym,
   /* Now create the vector of fields, and record how big it is.  */
 
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nfields));
 
   /* Copy the saved-up fields into the field vector.  */
 
@@ -2122,8 +2120,8 @@ coff_read_enum_type (int index, int length, int lastsym,
     TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
   type->set_code (TYPE_CODE_ENUM);
   type->set_num_fields (nsyms);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+  type->set_fields
+    ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nsyms));
 
   /* Find the symbols for the values and put them into the type.
      The symbols can be found in the symlist that we put them on
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 31f927e3bc9..c0694ed312f 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -309,8 +309,8 @@ attach_fields_to_type (struct ctf_field_info *fip, struct type *type)
 
   /* Record the field count, allocate space for the array of fields.  */
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type)
-    = (struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
 
   /* Copy the saved-up fields into the field vector.  */
   for (int i = 0; i < nfields; ++i)
@@ -1143,8 +1143,8 @@ add_stt_func (struct ctf_context *ccp, unsigned long idx)
 
   /* If argc is 0, it has a "void" type.  */
   if (argc != 0)
-    TYPE_FIELDS (ftype)
-      = (struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field));
+    ftype->set_fields
+      ((struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field)));
 
   /* TYPE_FIELD_TYPE must never be NULL.  Fill it with void_type, if failed
      to find the argument type.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index dd69d6622b2..06cf60b3b3f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9329,8 +9329,8 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       type->set_num_fields (3);
       /* Save the field we care about.  */
       struct field saved_field = TYPE_FIELD (type, 0);
-      TYPE_FIELDS (type)
-	= (struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field));
+      type->set_fields
+	((struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field)));
 
       /* Put the discriminant at index 0.  */
       TYPE_FIELD_TYPE (type, 0) = field_type;
@@ -9424,7 +9424,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 					       * sizeof (struct field)));
       memcpy (new_fields + 1, TYPE_FIELDS (type),
 	      type->num_fields () * sizeof (struct field));
-      TYPE_FIELDS (type) = new_fields;
+      type->set_fields (new_fields);
       type->set_num_fields (type->num_fields () + 1);
 
       /* Install the discriminant at index 0 in the union.  */
@@ -9474,7 +9474,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);
-	      ++TYPE_FIELDS (sub_type);
+	      sub_type->set_fields (sub_type->fields () + 1);
 	    }
 	  TYPE_FIELD_NAME (type, i) = variant_name;
 	  sub_type->set_name
@@ -14769,8 +14769,8 @@ dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
   /* Record the field count, allocate space for the array of fields,
      and create blank accessibility bitfields if necessary.  */
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ZALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
 
   if (fip->non_public_fields && cu->language != language_ada)
     {
@@ -15898,8 +15898,9 @@ update_enumeration_type_from_children (struct die_info *die,
   if (!fields.empty ())
     {
       type->set_num_fields (fields.size ());
-      TYPE_FIELDS (type) = (struct field *)
-	TYPE_ALLOC (type, sizeof (struct field) * fields.size ());
+      type->set_fields
+	((struct field *)
+	 TYPE_ALLOC (type, sizeof (struct field) * fields.size ()));
       memcpy (TYPE_FIELDS (type), fields.data (),
 	      sizeof (struct field) * fields.size ());
     }
@@ -17049,8 +17050,8 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
 
       /* Allocate storage for parameters and fill them in.  */
       ftype->set_num_fields (nparams);
-      TYPE_FIELDS (ftype) = (struct field *)
-	TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
+      ftype->set_fields
+	((struct field *) TYPE_ZALLOC (ftype, nparams * sizeof (struct field)));
 
       /* TYPE_FIELD_TYPE must never be NULL.  Pre-fill the array to ensure it
 	 even if we error out during the parameters reading below.  */
diff --git a/gdb/eval.c b/gdb/eval.c
index 8104c956b42..069cf5ddbc4 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -683,8 +683,8 @@ fake_method::fake_method (type_instance_flags flags,
      allocate memory for auxiliary fields, and free the memory ourselves
      when we are done with it.  */
   type->set_num_fields (num_types);
-  TYPE_FIELDS (type) = (struct field *)
-    xzalloc (sizeof (struct field) * num_types);
+  type->set_fields
+    ((struct field *) xzalloc (sizeof (struct field) * num_types));
 
   while (num_types-- > 0)
     TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 01d8530d0f5..d1623457a13 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -563,8 +563,8 @@ lookup_function_type_with_arguments (struct type *type,
     }
 
   fn->set_num_fields (nparams);
-  TYPE_FIELDS (fn)
-    = (struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field));
+  fn->set_fields
+    ((struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field)));
   for (i = 0; i < nparams; ++i)
     TYPE_FIELD_TYPE (fn, i) = param_types[i];
 
@@ -1282,8 +1282,8 @@ create_array_type_with_stride (struct type *result_type,
   TYPE_TARGET_TYPE (result_type) = element_type;
 
   result_type->set_num_fields (1);
-  TYPE_FIELDS (result_type) =
-    (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
+  result_type->set_fields
+    ((struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)));
   TYPE_INDEX_TYPE (result_type) = range_type;
   if (byte_stride_prop != NULL)
     result_type->add_dyn_prop (DYN_PROP_BYTE_STRIDE, *byte_stride_prop);
@@ -1381,8 +1381,8 @@ create_set_type (struct type *result_type, struct type *domain_type)
 
   result_type->set_code (TYPE_CODE_SET);
   result_type->set_num_fields (1);
-  TYPE_FIELDS (result_type)
-    = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
+  result_type->set_fields
+    ((struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)));
 
   if (!TYPE_STUB (domain_type))
     {
@@ -1549,7 +1549,7 @@ smash_to_method_type (struct type *type, struct type *self_type,
   type->set_code (TYPE_CODE_METHOD);
   TYPE_TARGET_TYPE (type) = to_type;
   set_type_self_type (type, self_type);
-  TYPE_FIELDS (type) = args;
+  type->set_fields (args);
   type->set_num_fields (nargs);
   if (varargs)
     TYPE_VARARGS (type) = 1;
@@ -2238,10 +2238,10 @@ resolve_dynamic_union (struct type *type,
   gdb_assert (type->code () == TYPE_CODE_UNION);
 
   resolved_type = copy_type (type);
-  TYPE_FIELDS (resolved_type)
-    = (struct field *) TYPE_ALLOC (resolved_type,
-				   resolved_type->num_fields ()
-				   * sizeof (struct field));
+  resolved_type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (resolved_type,
+		 resolved_type->num_fields () * sizeof (struct field)));
   memcpy (TYPE_FIELDS (resolved_type),
 	  TYPE_FIELDS (type),
 	  resolved_type->num_fields () * sizeof (struct field));
@@ -2404,10 +2404,11 @@ compute_variant_fields (struct type *type,
 
   resolved_type->set_num_fields
     (std::count (flags.begin (), flags.end (), true));
-  TYPE_FIELDS (resolved_type)
-    = (struct field *) TYPE_ALLOC (resolved_type,
-				   resolved_type->num_fields ()
-				   * sizeof (struct field));
+  resolved_type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (resolved_type,
+		 resolved_type->num_fields () * sizeof (struct field)));
+
   int out = 0;
   for (int i = 0; i < type->num_fields (); ++i)
     {
@@ -2448,10 +2449,10 @@ resolve_dynamic_struct (struct type *type,
     }
   else
     {
-      TYPE_FIELDS (resolved_type)
-	= (struct field *) TYPE_ALLOC (resolved_type,
-				       resolved_type->num_fields ()
-				       * sizeof (struct field));
+      resolved_type->set_fields
+	((struct field *)
+	 TYPE_ALLOC (resolved_type,
+		     resolved_type->num_fields () * sizeof (struct field)));
       memcpy (TYPE_FIELDS (resolved_type),
 	      TYPE_FIELDS (type),
 	      resolved_type->num_fields () * sizeof (struct field));
@@ -5301,8 +5302,10 @@ copy_type_recursive (struct objfile *objfile,
       int i, nfields;
 
       nfields = type->num_fields ();
-      TYPE_FIELDS (new_type) = (struct field *)
-        TYPE_ZALLOC (new_type, nfields * sizeof (struct field));
+      new_type->set_fields
+	((struct field *)
+	 TYPE_ZALLOC (new_type, nfields * sizeof (struct field)));
+
       for (i = 0; i < nfields; i++)
 	{
 	  TYPE_FIELD_ARTIFICIAL (new_type, i) = 
@@ -5560,8 +5563,8 @@ arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
   TYPE_UNSIGNED (type) = 1;
   type->set_num_fields (0);
   /* Pre-allocate enough space assuming every field is one bit.  */
-  TYPE_FIELDS (type)
-    = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
+  type->set_fields
+    ((struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field)));
 
   return type;
 }
@@ -5631,8 +5634,8 @@ append_composite_type_field_raw (struct type *t, const char *name,
   struct field *f;
 
   t->set_num_fields (t->num_fields () + 1);
-  TYPE_FIELDS (t) = XRESIZEVEC (struct field, TYPE_FIELDS (t),
-				t->num_fields ());
+  t->set_fields (XRESIZEVEC (struct field, TYPE_FIELDS (t),
+			     t->num_fields ()));
   f = &(TYPE_FIELDS (t)[t->num_fields () - 1]);
   memset (f, 0, sizeof f[0]);
   FIELD_TYPE (f[0]) = field;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index e5f46dca0d2..3ed9f8e7fc1 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -913,6 +913,18 @@ struct type
     this->main_type->nfields = num_fields;
   }
 
+  /* Get the fields array of this type.  */
+  field *fields () const
+  {
+    return this->main_type->flds_bnds.fields;
+  }
+
+  /* Set the fields array of this type.  */
+  void set_fields (field *fields)
+  {
+    this->main_type->flds_bnds.fields = fields;
+  }
+
   /* * Return the dynamic property of the requested KIND from this type's
      list of dynamic properties.  */
   dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
@@ -1458,7 +1470,7 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
+#define TYPE_FIELDS(thistype) (thistype)->fields ()
 
 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
 #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index c1967e62bb7..064f924c769 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -166,7 +166,7 @@ build_gdb_vtable_type (struct gdbarch *arch)
 
   t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
   t->set_num_fields (field - field_list);
-  TYPE_FIELDS (t) = field_list;
+  t->set_fields (field_list);
   t->set_name ("gdb_gnu_v3_abi_vtable");
   INIT_CPLUS_SPECIFIC (t);
 
@@ -1055,7 +1055,7 @@ build_std_type_info_type (struct gdbarch *arch)
 
   t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
   t->set_num_fields (field - field_list);
-  TYPE_FIELDS (t) = field_list;
+  t->set_fields (field_list);
   t->set_name ("gdb_gnu_v3_type_info");
   INIT_CPLUS_SPECIFIC (t);
 
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index f634dbb08f1..aeecb14f19e 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1018,9 +1018,8 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 	t->set_code (type_code);
 	TYPE_LENGTH (t) = sh->value;
 	t->set_num_fields (nfields);
-	TYPE_FIELDS (t) = f = ((struct field *)
-			       TYPE_ALLOC (t,
-					   nfields * sizeof (struct field)));
+	f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field)));
+	t->set_fields (f);
 
 	if (type_code == TYPE_CODE_ENUM)
 	  {
@@ -1187,8 +1186,9 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		  struct block_iterator iter;
 
 		  ftype->set_num_fields (nparams);
-		  TYPE_FIELDS (ftype) = (struct field *)
-		    TYPE_ALLOC (ftype, nparams * sizeof (struct field));
+		  ftype->set_fields
+		    ((struct field *)
+		     TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
 
 		  iparams = 0;
 		  ALL_BLOCK_SYMBOLS (cblock, iter, sym)
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f8696628474..f7eba1d9f2f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -985,8 +985,8 @@ rust_composite_type (struct type *original,
   result->set_name (name);
 
   result->set_num_fields (nfields);
-  TYPE_FIELDS (result)
-    = (struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field));
+  result->set_fields
+    ((struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field)));
 
   i = 0;
   bitpos = 0;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index daf88c851c7..e710a43b7a0 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -986,8 +986,9 @@ define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	    }
 
 	  /* Allocate parameter information fields and fill them in.  */
-	  TYPE_FIELDS (ftype) = (struct field *)
-	    TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
+	  ftype->set_fields
+	    ((struct field *)
+	     TYPE_ALLOC (ftype, nsemi * sizeof (struct field)));
 	  while (*p++ == ';')
 	    {
 	      struct type *ptype;
@@ -1836,9 +1837,9 @@ read_type (const char **pp, struct objfile *objfile)
             && arg_types->type->code () == TYPE_CODE_VOID)
           num_args = 0;
 
-        TYPE_FIELDS (func_type)
-          = (struct field *) TYPE_ALLOC (func_type,
-                                         num_args * sizeof (struct field));
+	func_type->set_fields
+	  ((struct field *) TYPE_ALLOC (func_type,
+					num_args * sizeof (struct field)));
         memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
         {
           int i;
@@ -3309,8 +3310,9 @@ attach_fields_to_type (struct stab_field_info *fip, struct type *type,
      array of fields, and create blank visibility bitfields if necessary.  */
 
   type->set_num_fields (nfields);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nfields);
+  type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (type, sizeof (struct field) * nfields));
   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
 
   if (non_public_fields)
@@ -3655,8 +3657,9 @@ read_enum_type (const char **pp, struct type *type,
   if (unsigned_enum)
     TYPE_UNSIGNED (type) = 1;
   type->set_num_fields (nsyms);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+  type->set_fields
+    ((struct field *)
+     TYPE_ALLOC (type, sizeof (struct field) * nsyms));
   memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
 
   /* Find the symbols for the values and put them into the type.
-- 
2.26.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/4] gdb: remove TYPE_FIELDS macro
  2020-05-19 18:44 [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Simon Marchi
  2020-05-19 18:44 ` [PATCH 2/4] gdb: remove TYPE_NFIELDS macro Simon Marchi
  2020-05-19 18:44 ` [PATCH 3/4] gdb: add type::fields / type::set_fields Simon Marchi
@ 2020-05-19 18:44 ` Simon Marchi
  2020-05-22 20:23   ` Tom Tromey
  2020-05-22 20:16 ` [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Tom Tromey
  3 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2020-05-19 18:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Remove all uses of the `TYPE_FIELDS` macro.  Replace them with either:

1) type::fields, to obtain a pointer to the fields array (same as
   TYPE_FIELDS yields)
2) type::field, a new convenience method that obtains a reference to one
   of the type's field by index.  It is meant to replace

     TYPE_FIELDS (type)[idx]

   with

     type->field (idx)

gdb/ChangeLog:

	* gdbtypes.h (struct type) <field>: New method.
	(TYPE_FIELDS): Remove, replace all uses with either type::fields
	or type::field.
---
 gdb/ada-lang.c       |  8 ++++----
 gdb/c-typeprint.c    |  2 +-
 gdb/dwarf2/read.c    | 10 +++++-----
 gdb/eval.c           |  2 +-
 gdb/gdbtypes.c       | 14 +++++++-------
 gdb/gdbtypes.h       | 14 +++++++++-----
 gdb/guile/scm-type.c |  2 +-
 gdb/iq2000-tdep.c    |  2 +-
 gdb/mdebugread.c     |  4 ++--
 gdb/mips-tdep.c      |  4 ++--
 gdb/stabsread.c      |  6 +++---
 gdb/windows-tdep.c   |  4 ++--
 12 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1e6cc5f94a1..5af69f709fb 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8247,7 +8247,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
       if (branch_type == NULL)
         {
           for (f = variant_field + 1; f < rtype->num_fields (); f += 1)
-            TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
+            rtype->field (f - 1) = rtype->field (f);
 	  rtype->set_num_fields (rtype->num_fields () - 1);
         }
       else
@@ -8360,7 +8360,7 @@ template_to_static_fixed_type (struct type *type0)
 	      field *fields =
 		((struct field *)
 		 TYPE_ALLOC (type, nfields * sizeof (struct field)));
-	      memcpy (fields, TYPE_FIELDS (type0),
+	      memcpy (fields, type0->fields (),
 		      sizeof (struct field) * nfields);
 	      type->set_fields (fields);
 
@@ -8412,7 +8412,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
 
   field *fields =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
-  memcpy (fields, TYPE_FIELDS (type), sizeof (struct field) * nfields);
+  memcpy (fields, type->fields (), sizeof (struct field) * nfields);
   rtype->set_fields (fields);
 
   rtype->set_name (ada_type_name (type));
@@ -8432,7 +8432,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
       int f;
 
       for (f = variant_field + 1; f < nfields; f += 1)
-        TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
+        rtype->field (f - 1) = rtype->field (f);
       rtype->set_num_fields (rtype->num_fields () - 1);
     }
   else
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 955cfd60451..29ac595cb25 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -277,7 +277,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix,
 			   enum language language,
 			   const struct type_print_options *flags)
 {
-  struct field *args = TYPE_FIELDS (mtype);
+  struct field *args = mtype->fields ();
   int nargs = mtype->num_fields ();
   int varargs = TYPE_VARARGS (mtype);
   int i;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 06cf60b3b3f..ef655ff109f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9422,7 +9422,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 (type),
+      memcpy (new_fields + 1, type->fields (),
 	      type->num_fields () * sizeof (struct field));
       type->set_fields (new_fields);
       type->set_num_fields (type->num_fields () + 1);
@@ -14966,7 +14966,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 	   of the method itself (TYPE_CODE_METHOD).  */
       smash_to_method_type (fnp->type, type,
 			    TYPE_TARGET_TYPE (this_type),
-			    TYPE_FIELDS (this_type),
+			    this_type->fields (),
 			    this_type->num_fields (),
 			    TYPE_VARARGS (this_type));
 
@@ -15183,7 +15183,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
   self_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0));
   new_type = alloc_type (objfile);
   smash_to_method_type (new_type, self_type, TYPE_TARGET_TYPE (pfn_type),
-			TYPE_FIELDS (pfn_type), pfn_type->num_fields (),
+			pfn_type->fields (), pfn_type->num_fields (),
 			TYPE_VARARGS (pfn_type));
   smash_to_methodptr_type (type, new_type);
 }
@@ -15901,7 +15901,7 @@ update_enumeration_type_from_children (struct die_info *die,
       type->set_fields
 	((struct field *)
 	 TYPE_ALLOC (type, sizeof (struct field) * fields.size ()));
-      memcpy (TYPE_FIELDS (type), fields.data (),
+      memcpy (type->fields (), fields.data (),
 	      sizeof (struct field) * fields.size ());
     }
 
@@ -16687,7 +16687,7 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
 	= alloc_type (cu->per_cu->dwarf2_per_objfile->objfile);
 
       smash_to_method_type (new_type, domain, TYPE_TARGET_TYPE (to_type),
-			    TYPE_FIELDS (to_type), to_type->num_fields (),
+			    to_type->fields (), to_type->num_fields (),
 			    TYPE_VARARGS (to_type));
       type = lookup_methodptr_type (new_type);
     }
diff --git a/gdb/eval.c b/gdb/eval.c
index 069cf5ddbc4..3f23cebfb29 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -692,7 +692,7 @@ fake_method::fake_method (type_instance_flags flags,
 
 fake_method::~fake_method ()
 {
-  xfree (TYPE_FIELDS (&m_type));
+  xfree (m_type.fields ());
 }
 
 /* Helper for evaluating an OP_VAR_VALUE.  */
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index d1623457a13..96b75a00a92 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2242,8 +2242,8 @@ resolve_dynamic_union (struct type *type,
     ((struct field *)
      TYPE_ALLOC (resolved_type,
 		 resolved_type->num_fields () * sizeof (struct field)));
-  memcpy (TYPE_FIELDS (resolved_type),
-	  TYPE_FIELDS (type),
+  memcpy (resolved_type->fields (),
+	  type->fields (),
 	  resolved_type->num_fields () * sizeof (struct field));
   for (i = 0; i < resolved_type->num_fields (); ++i)
     {
@@ -2453,8 +2453,8 @@ resolve_dynamic_struct (struct type *type,
 	((struct field *)
 	 TYPE_ALLOC (resolved_type,
 		     resolved_type->num_fields () * sizeof (struct field)));
-      memcpy (TYPE_FIELDS (resolved_type),
-	      TYPE_FIELDS (type),
+      memcpy (resolved_type->fields (),
+	      type->fields (),
 	      resolved_type->num_fields () * sizeof (struct field));
     }
 
@@ -5103,7 +5103,7 @@ recursive_dump_type (struct type *type, int spaces)
     }
   puts_filtered ("\n");
   printfi_filtered (spaces, "nfields %d ", type->num_fields ());
-  gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
+  gdb_print_host_address (type->fields (), gdb_stdout);
   puts_filtered ("\n");
   for (idx = 0; idx < type->num_fields (); idx++)
     {
@@ -5634,9 +5634,9 @@ 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, TYPE_FIELDS (t),
+  t->set_fields (XRESIZEVEC (struct field, t->fields (),
 			     t->num_fields ()));
-  f = &(TYPE_FIELDS (t)[t->num_fields () - 1]);
+  f = &t->field (t->num_fields () - 1);
   memset (f, 0, sizeof f[0]);
   FIELD_TYPE (f[0]) = field;
   FIELD_NAME (f[0]) = name;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 3ed9f8e7fc1..f91adbc6cc2 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -914,13 +914,19 @@ struct type
   }
 
   /* Get the fields array of this type.  */
-  field *fields () const
+  struct field *fields () const
   {
     return this->main_type->flds_bnds.fields;
   }
 
+  /* Get the field at index IDX.  */
+  struct field &field (int idx) const
+  {
+    return this->fields ()[idx];
+  }
+
   /* Set the fields array of this type.  */
-  void set_fields (field *fields)
+  void set_fields (struct field *fields)
   {
     this->main_type->flds_bnds.fields = fields;
   }
@@ -1470,8 +1476,6 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_FIELDS(thistype) (thistype)->fields ()
-
 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
 #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
 #define TYPE_LOW_BOUND(range_type) \
@@ -1667,7 +1671,7 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define TYPE_FN_FIELD(thisfn, n) (thisfn)[n]
 #define TYPE_FN_FIELD_PHYSNAME(thisfn, n) (thisfn)[n].physname
 #define TYPE_FN_FIELD_TYPE(thisfn, n) (thisfn)[n].type
-#define TYPE_FN_FIELD_ARGS(thisfn, n) TYPE_FIELDS ((thisfn)[n].type)
+#define TYPE_FN_FIELD_ARGS(thisfn, n) (((thisfn)[n].type)->fields ())
 #define TYPE_FN_FIELD_CONST(thisfn, n) ((thisfn)[n].is_const)
 #define TYPE_FN_FIELD_VOLATILE(thisfn, n) ((thisfn)[n].is_volatile)
 #define TYPE_FN_FIELD_PRIVATE(thisfn, n) ((thisfn)[n].is_private)
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index b216087e778..e58f1474699 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -512,7 +512,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 (type) != NULL);
+  gdb_assert (type->fields () != NULL);
 
   return &TYPE_FIELD (type, f_smob->field_num);
 }
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index 18d207535b4..b35b45ea4c5 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -607,7 +607,7 @@ iq2000_pass_8bytetype_by_address (struct type *type)
   if (type->num_fields () != 1)
     return 1;
   /* Get field type.  */
-  ftype = (TYPE_FIELDS (type))[0].type;
+  ftype = type->field (0).type;
   /* The field type must have size 8, otherwise pass by address.  */
   if (TYPE_LENGTH (ftype) != 8)
     return 1;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index aeecb14f19e..20fdd40d508 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1233,8 +1233,8 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 
     case stMember:		/* member of struct or union */
       {
-	struct field *f
-	  = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
+	struct field *f = &top_stack->cur_type->field (top_stack->cur_field);
+	top_stack->cur_field++;
 	FIELD_NAME (*f) = name;
 	SET_FIELD_BITPOS (*f, sh->value);
 	bitsize = 0;
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index a3ab8c80e37..c602398506b 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -5247,7 +5247,7 @@ mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
 				: MIPS_V0_REGNUM);
 	   field < type->num_fields (); field++, regnum += 2)
 	{
-	  int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
+	  int offset = (FIELD_BITPOS (type->field (field))
 			/ TARGET_CHAR_BIT);
 	  if (mips_debug)
 	    fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
@@ -5799,7 +5799,7 @@ mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
       for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
 	   field < type->num_fields (); field++, regnum += 2)
 	{
-	  int offset = (FIELD_BITPOS (TYPE_FIELDS (type)[field])
+	  int offset = (FIELD_BITPOS (type->fields ()[field])
 			/ TARGET_CHAR_BIT);
 	  if (mips_debug)
 	    fprintf_unfiltered (gdb_stderr, "Return float struct+%d\n",
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index e710a43b7a0..8d535294524 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1840,7 +1840,7 @@ read_type (const char **pp, struct objfile *objfile)
 	func_type->set_fields
 	  ((struct field *) TYPE_ALLOC (func_type,
 					num_args * sizeof (struct field)));
-        memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
+        memset (func_type->fields (), 0, num_args * sizeof (struct field));
         {
           int i;
           struct type_list *t;
@@ -3313,7 +3313,7 @@ attach_fields_to_type (struct stab_field_info *fip, struct type *type,
   type->set_fields
     ((struct field *)
      TYPE_ALLOC (type, sizeof (struct field) * nfields));
-  memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
+  memset (type->fields (), 0, sizeof (struct field) * nfields);
 
   if (non_public_fields)
     {
@@ -3660,7 +3660,7 @@ read_enum_type (const char **pp, struct type *type,
   type->set_fields
     ((struct field *)
      TYPE_ALLOC (type, sizeof (struct field) * nsyms));
-  memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
+  memset (type->fields (), 0, sizeof (struct field) * nsyms);
 
   /* Find the symbols for the values and put them into the type.
      The symbols can be found in the symlist that we put them on
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index d7c498f2e93..6eec2577f38 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -752,8 +752,8 @@ create_enum (struct gdbarch *gdbarch, int bit, const char *name,
 
   type = arch_type (gdbarch, TYPE_CODE_ENUM, bit, name);
   type->set_num_fields (count);
-  TYPE_FIELDS (type) = (struct field *)
-    TYPE_ZALLOC (type, sizeof (struct field) * count);
+  type->set_fields
+    ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count));
   TYPE_UNSIGNED (type) = 1;
 
   for (i = 0; i < count; i++)
-- 
2.26.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields
  2020-05-19 18:44 [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Simon Marchi
                   ` (2 preceding siblings ...)
  2020-05-19 18:44 ` [PATCH 4/4] gdb: remove TYPE_FIELDS macro Simon Marchi
@ 2020-05-22 20:16 ` Tom Tromey
  3 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2020-05-22 20:16 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Add the `num_fields` and `set_num_fields` methods on `struct type`, in
Simon> order to remove the `TYPE_NFIELDS` macro.  In this patch, the
Simon> `TYPE_NFIELDS` macro is changed to use `type::num_fields`, so all the
Simon> call sites that are used to set the number of fields are changed to use
Simon> `type::set_num_fields`.  The next patch will remove `TYPE_NFIELDS`
Simon> completely.

This looks good.

Simon> I think that in the future, we should consider making the interface of
Simon> `struct type` better.  For example, right now it's possible for the
Simon> number of fields property and the actual number of fields set to be out
Simon> of sync.  However, I want to keep the existing behavior in this patch,
Simon> just translate from macros to methods.

Fully agreed.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] gdb: remove TYPE_NFIELDS macro
  2020-05-19 18:44 ` [PATCH 2/4] gdb: remove TYPE_NFIELDS macro Simon Marchi
@ 2020-05-22 20:20   ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2020-05-22 20:20 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Remove `TYPE_NFIELDS`, changing all the call sites to use
Simon> `type::num_fields` directly.  This is quite a big diff, but this was
Simon> mostly done using sed and coccinelle.  A few call sites were done by
Simon> hand.

This looks good.  I only spot checked it.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/4] gdb: add type::fields / type::set_fields
  2020-05-19 18:44 ` [PATCH 3/4] gdb: add type::fields / type::set_fields Simon Marchi
@ 2020-05-22 20:21   ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2020-05-22 20:21 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Add the `fields` and `set_fields` methods on `struct type`, in order to
Simon> remove the `TYPE_FIELDS` macro.  In this patch, the `TYPE_FIELDS` macro
Simon> is changed to the `type::fields`, so all the call sites that use it to
Simon> set the fields array are changed to use `type::set_fields`.  The next
Simon> patch will remove `TYPE_FIELDS` entirely.

Looks good.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] gdb: remove TYPE_FIELDS macro
  2020-05-19 18:44 ` [PATCH 4/4] gdb: remove TYPE_FIELDS macro Simon Marchi
@ 2020-05-22 20:23   ` Tom Tromey
  2020-05-22 20:58     ` Simon Marchi
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2020-05-22 20:23 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Remove all uses of the `TYPE_FIELDS` macro.  Replace them with either:
Simon> 1) type::fields, to obtain a pointer to the fields array (same as
Simon>    TYPE_FIELDS yields)

Simon> 2) type::field, a new convenience method that obtains a reference to one
Simon>    of the type's field by index.  It is meant to replace
Simon>      TYPE_FIELDS (type)[idx]

I suppose a future patch will remove the TYPE_FIELD macro?


Simon> -  TYPE_FIELDS (type) = (struct field *)
Simon> -    TYPE_ZALLOC (type, sizeof (struct field) * count);
Simon> +  type->set_fields
Simon> +    ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count));
Simon>    TYPE_UNSIGNED (type) = 1;
 
Technically I suppose this should be in the earlier patch.

Anyway this looks good.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] gdb: remove TYPE_FIELDS macro
  2020-05-22 20:23   ` Tom Tromey
@ 2020-05-22 20:58     ` Simon Marchi
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2020-05-22 20:58 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi

On 2020-05-22 4:23 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Remove all uses of the `TYPE_FIELDS` macro.  Replace them with either:
> Simon> 1) type::fields, to obtain a pointer to the fields array (same as
> Simon>    TYPE_FIELDS yields)
> 
> Simon> 2) type::field, a new convenience method that obtains a reference to one
> Simon>    of the type's field by index.  It is meant to replace
> Simon>      TYPE_FIELDS (type)[idx]
> 
> I suppose a future patch will remove the TYPE_FIELD macro?

Hmm right, it would have made sense to have a patch for that in this series... too bad, I'll
just send it separately.

> Simon> -  TYPE_FIELDS (type) = (struct field *)
> Simon> -    TYPE_ZALLOC (type, sizeof (struct field) * count);
> Simon> +  type->set_fields
> Simon> +    ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count));
> Simon>    TYPE_UNSIGNED (type) = 1;
>  
> Technically I suppose this should be in the earlier patch.

Hmm yes, otherwise the previous commit wouldn't build.  Thanks for checking,
I've fixed, made sure that all commits built fine with --enable-targets=all
and pushed the series.

Simon


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-05-22 20:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 18:44 [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Simon Marchi
2020-05-19 18:44 ` [PATCH 2/4] gdb: remove TYPE_NFIELDS macro Simon Marchi
2020-05-22 20:20   ` Tom Tromey
2020-05-19 18:44 ` [PATCH 3/4] gdb: add type::fields / type::set_fields Simon Marchi
2020-05-22 20:21   ` Tom Tromey
2020-05-19 18:44 ` [PATCH 4/4] gdb: remove TYPE_FIELDS macro Simon Marchi
2020-05-22 20:23   ` Tom Tromey
2020-05-22 20:58     ` Simon Marchi
2020-05-22 20:16 ` [PATCH 1/4] gdb: add type::num_fields / type::set_num_fields Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).