+2020-05-22  Simon Marchi  <simon.marchi@efficios.com>
+
+       * gdbtypes.h (struct type) <field>: New method.
+       (TYPE_FIELDS): Remove, replace all uses with either type::fields
+       or type::field.
+
 2020-05-22  Simon Marchi  <simon.marchi@efficios.com>
 
        * gdbtypes.h (struct type) <fields, set_fields>: New methods.
 
       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
              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);
 
 
   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));
       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
 
                           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;
 
       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);
           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));
 
   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);
 }
       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 ());
     }
 
        = 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);
     }
 
 
 fake_method::~fake_method ()
 {
-  xfree (TYPE_FIELDS (&m_type));
+  xfree (m_type.fields ());
 }
 
 /* Helper for evaluating an OP_VAR_VALUE.  */
 
     ((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)
     {
        ((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));
     }
 
     }
   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++)
     {
   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;
 
   }
 
   /* 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;
   }
    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) \
 #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)
 
   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);
 }
 
   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;
 
 
     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;
 
                                : 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",
       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",
 
        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;
   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)
     {
   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