]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove some type field accessor macros
authorTom Tromey <tromey@adacore.com>
Thu, 21 Sep 2023 16:36:23 +0000 (10:36 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 21 Nov 2023 21:52:05 +0000 (14:52 -0700)
This removes TYPE_FIELD_PRIVATE, TYPE_FIELD_PROTECTED,
TYPE_FIELD_IGNORE, and TYPE_FIELD_VIRTUAL.

In c-varobj.c, match_accessibility can be removed entirely now.  Note
that the comment before this function was incorrect.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Keith Seitz <keiths@redhat.com>
gdb/ada-valprint.c
gdb/c-typeprint.c
gdb/c-varobj.c
gdb/compile/compile-cplus-types.c
gdb/cp-valprint.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/p-typeprint.c
gdb/p-valprint.c

index f1c4e8b0b706443c478ddfdcef69bf8ec7f9d075..86cab353e0f1810e0a619ad1ed50af017fc81926 100644 (file)
@@ -627,7 +627,7 @@ print_field_values (struct value *value, struct value *outer_value,
        {
          /* Bitfields require special handling, especially due to byte
             order problems.  */
-         if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
+         if (type->field (i).is_ignored ())
            {
              fputs_styled (_("<optimized out or zero length>"),
                            metadata_style.style (), stream);
index 241fbca49b7dd7e55846007ca426ea1d36ed95fe..4a0c6950b0ce3575910b315c7fb7f768dd3d5cb3 100644 (file)
@@ -238,7 +238,7 @@ cp_type_print_derivation_info (struct ui_file *stream,
       gdb_puts (i == 0 ? ": " : ", ", stream);
       gdb_printf (stream, "%s%s ",
                  BASETYPE_VIA_PUBLIC (type, i)
-                 ? "public" : (TYPE_FIELD_PROTECTED (type, i)
+                 ? "public" : (type->field (i).is_protected ()
                                ? "protected" : "private"),
                  BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
       name = TYPE_BASECLASS (type, i)->name ();
@@ -912,7 +912,7 @@ need_access_label_p (struct type *type)
   if (type->is_declared_class ())
     {
       for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
-       if (!TYPE_FIELD_PRIVATE (type, i))
+       if (!type->field (i).is_private ())
          return true;
       for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
        for (int i = 0; i < TYPE_FN_FIELDLIST_LENGTH (type, j); i++)
@@ -926,7 +926,7 @@ need_access_label_p (struct type *type)
   else
     {
       for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
-       if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i))
+       if (!type->field (i).is_public ())
          return true;
       for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
        {
@@ -1102,8 +1102,8 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
            {
              section_type = output_access_specifier
                (stream, section_type, level,
-                TYPE_FIELD_PROTECTED (type, i),
-                TYPE_FIELD_PRIVATE (type, i), flags);
+                type->field (i).is_protected (),
+                type->field (i).is_private (), flags);
            }
 
          bool is_static = type->field (i).is_static ();
index 543cd585eb241d01af3395773c9c4a1f0a7423e6..05b5bd7fa237d9489544d933d8dafc3ad61a9fbc 100644 (file)
@@ -647,16 +647,18 @@ cplus_class_num_children (struct type *type, int children[3])
   vptr_fieldno = get_vptr_fieldno (type, &basetype);
   for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
     {
+      field &fld = type->field (i);
+
       /* If we have a virtual table pointer, omit it.  Even if virtual
         table pointers are not specifically marked in the debug info,
         they should be artificial.  */
       if ((type == basetype && i == vptr_fieldno)
-         || type->field (i).is_artificial ())
+         || fld.is_artificial ())
        continue;
 
-      if (TYPE_FIELD_PROTECTED (type, i))
+      if (fld.is_protected ())
        children[v_protected]++;
-      else if (TYPE_FIELD_PRIVATE (type, i))
+      else if (fld.is_private ())
        children[v_private]++;
       else
        children[v_public]++;
@@ -669,23 +671,6 @@ cplus_name_of_variable (const struct varobj *parent)
   return c_name_of_variable (parent);
 }
 
-/* Check if field INDEX of TYPE has the specified accessibility.
-   Return 0 if so and 1 otherwise.  */
-
-static int 
-match_accessibility (struct type *type, int index, enum accessibility acc)
-{
-  if (acc == accessibility::PRIVATE && TYPE_FIELD_PRIVATE (type, index))
-    return 1;
-  else if (acc == accessibility::PROTECTED && TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else if (acc == accessibility::PUBLIC && !TYPE_FIELD_PRIVATE (type, index)
-          && !TYPE_FIELD_PROTECTED (type, index))
-    return 1;
-  else
-    return 0;
-}
-
 static void
 cplus_describe_child (const struct varobj *parent, int index,
                      std::string *cname, struct value **cvalue, struct type **ctype,
@@ -751,9 +736,9 @@ cplus_describe_child (const struct varobj *parent, int index,
              if ((type == basetype && type_index == vptr_fieldno)
                  || type->field (type_index).is_artificial ())
                ; /* ignore vptr */
-             else if (match_accessibility (type, type_index, acc))
-                   --index;
-                 ++type_index;
+             else if (type->field (type_index).accessibility () == acc)
+               --index;
+             ++type_index;
            }
          --type_index;
 
index ac27e83618b585b516275d42812fa99a0a6251f4..a59d77b76a9bf04ceac4489b9a8b6a407b0f7d7c 100644 (file)
@@ -73,9 +73,10 @@ compile_cplus_instance::decl_name (const char *natural)
 static enum gcc_cp_symbol_kind
 get_field_access_flag (const struct type *type, int num)
 {
-  if (TYPE_FIELD_PROTECTED (type, num))
+  field &fld = type->field (num);
+  if (fld.is_protected ())
     return GCC_CP_ACCESS_PROTECTED;
-  else if (TYPE_FIELD_PRIVATE (type, num))
+  else if (fld.is_private ())
     return GCC_CP_ACCESS_PRIVATE;
 
   /* GDB assumes everything else is public.  */
@@ -583,7 +584,7 @@ compile_cplus_convert_struct_or_union_members
     {
       const char *field_name = type->field (i).name ();
 
-      if (TYPE_FIELD_IGNORE (type, i)
+      if (type->field (i).is_ignored ()
          || type->field (i).is_artificial ())
        continue;
 
index 820a761054a89bb2474cb928b8aeae910474c8ab..a803c786d2b068d4e066de930e371e17f7352af6 100644 (file)
@@ -265,7 +265,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
 
              /* Bitfields require special handling, especially due to
                 byte order problems.  */
-             if (TYPE_FIELD_IGNORE (type, i))
+             if (type->field (i).is_ignored ())
                {
                  fputs_styled ("<optimized out or zero length>",
                                metadata_style.style (), stream);
@@ -290,7 +290,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
            }
          else
            {
-             if (TYPE_FIELD_IGNORE (type, i))
+             if (type->field (i).is_ignored ())
                {
                  fputs_styled ("<optimized out or zero length>",
                                metadata_style.style (), stream);
index 8468b9ad67c5e6cbd2aca32c5d466490e76eecad..aa2fce00e1180541ede0fed180a430307b8c5652 100644 (file)
@@ -5229,33 +5229,34 @@ recursive_dump_type (struct type *type, int spaces)
   gdb_printf ("%s\n", host_address_to_string (type->fields ()));
   for (idx = 0; idx < type->num_fields (); idx++)
     {
+      field &fld = type->field (idx);
       if (type->code () == TYPE_CODE_ENUM)
        gdb_printf ("%*s[%d] enumval %s type ", spaces + 2, "",
-                   idx, plongest (type->field (idx).loc_enumval ()));
+                   idx, plongest (fld.loc_enumval ()));
       else
        gdb_printf ("%*s[%d] bitpos %s bitsize %d type ", spaces + 2, "",
-                   idx, plongest (type->field (idx).loc_bitpos ()),
-                   type->field (idx).bitsize ());
+                   idx, plongest (fld.loc_bitpos ()),
+                   fld.bitsize ());
       gdb_printf ("%s name '%s' (%s)",
-                 host_address_to_string (type->field (idx).type ()),
-                 type->field (idx).name () != NULL
-                 ? type->field (idx).name ()
+                 host_address_to_string (fld.type ()),
+                 fld.name () != NULL
+                 ? fld.name ()
                  : "<NULL>",
-                 host_address_to_string (type->field (idx).name ()));
-      if (TYPE_FIELD_VIRTUAL (type, idx))
+                 host_address_to_string (fld.name ()));
+      if (fld.is_virtual ())
        gdb_printf (" virtual");
 
-      if (TYPE_FIELD_PRIVATE (type, idx))
+      if (fld.is_private ())
        gdb_printf (" private");
-      else if (TYPE_FIELD_PROTECTED (type, idx))
+      else if (fld.is_protected ())
        gdb_printf (" protected");
-      else if (TYPE_FIELD_IGNORE (type, idx))
+      else if (fld.is_ignored ())
        gdb_printf (" ignored");
 
       gdb_printf ("\n");
-      if (type->field (idx).type () != NULL)
+      if (fld.type () != NULL)
        {
-         recursive_dump_type (type->field (idx).type (), spaces + 4);
+         recursive_dump_type (fld.type (), spaces + 4);
        }
     }
   if (type->code () == TYPE_CODE_RANGE)
index 6a11f58737cdb76d9f5c13db7f8af463ae2308e0..76ea3f7e8eb8547ffaeda2d603d67d2e4c1aef5f 100644 (file)
@@ -1974,15 +1974,6 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define BASETYPE_VIA_VIRTUAL(thistype, index) \
   ((thistype)->field (index).is_virtual ())
 
-#define TYPE_FIELD_PRIVATE(thistype, n) \
-  ((thistype)->field (n).is_private ())
-#define TYPE_FIELD_PROTECTED(thistype, n) \
-  ((thistype)->field (n).is_protected ())
-#define TYPE_FIELD_IGNORE(thistype, n) \
-  ((thistype)->field (n).is_ignored ())
-#define TYPE_FIELD_VIRTUAL(thistype, n) \
-  ((thistype)->field (n).is_virtual ())
-
 #define TYPE_FN_FIELDLISTS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists
 #define TYPE_FN_FIELDLIST(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n]
 #define TYPE_FN_FIELDLIST1(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].fn_fields
index 41058a8b59e580a21cad8bf7779e9fb7760afb2e..b5d66269d6ed359ef233f43086fcea08f4f3900d 100644 (file)
@@ -486,7 +486,9 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 
              if (HAVE_CPLUS_STRUCT (type))
                {
-                 if (TYPE_FIELD_PROTECTED (type, i))
+                 field &fld = type->field (i);
+
+                 if (fld.is_protected ())
                    {
                      if (section_type != s_protected)
                        {
@@ -495,7 +497,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
                                      level + 2, "");
                        }
                    }
-                 else if (TYPE_FIELD_PRIVATE (type, i))
+                 else if (fld.is_private ())
                    {
                      if (section_type != s_private)
                        {
index fb9386293a6f4d790058cd22662a7055ac0f42d8..056016225600785fcb3b45552dabee0377dce618 100644 (file)
@@ -604,7 +604,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
 
              /* Bitfields require special handling, especially due to byte
                 order problems.  */
-             if (TYPE_FIELD_IGNORE (type, i))
+             if (type->field (i).is_ignored ())
                {
                  fputs_styled ("<optimized out or zero length>",
                                metadata_style.style (), stream);
@@ -629,7 +629,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
            }
          else
            {
-             if (TYPE_FIELD_IGNORE (type, i))
+             if (type->field (i).is_ignored ())
                {
                  fputs_styled ("<optimized out or zero length>",
                                metadata_style.style (), stream);