public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/7] Remove some type field accessor macros
Date: Thu, 21 Sep 2023 12:01:33 -0600	[thread overview]
Message-ID: <20230921-field-bits-v1-6-201285360900@adacore.com> (raw)
In-Reply-To: <20230921-field-bits-v1-0-201285360900@adacore.com>

This removes TYPE_FIELD_PRIVATE, TYPE_FIELD_PROTECTED,
TYPE_FIELD_IGNORE, and TYPE_FIELD_VIRTUAL.
---
 gdb/ada-valprint.c                |  2 +-
 gdb/c-typeprint.c                 | 10 +++++-----
 gdb/c-varobj.c                    | 16 +++++++++-------
 gdb/compile/compile-cplus-types.c |  7 ++++---
 gdb/cp-valprint.c                 |  4 ++--
 gdb/gdbtypes.c                    | 27 ++++++++++++++-------------
 gdb/gdbtypes.h                    |  9 ---------
 gdb/p-typeprint.c                 |  6 ++++--
 gdb/p-valprint.c                  |  4 ++--
 9 files changed, 41 insertions(+), 44 deletions(-)

diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index eaeca0f6516..686655b18c9 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -619,7 +619,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);
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 241fbca49b7..4a0c6950b0c 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -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 ();
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index b00a2345e2c..10edc37c2ea 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -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]++;
@@ -677,12 +679,12 @@ enum accessibility { private_field, protected_field, public_field };
 static int 
 match_accessibility (struct type *type, int index, enum accessibility acc)
 {
-  if (acc == private_field && TYPE_FIELD_PRIVATE (type, index))
+  field &fld = type->field (index);
+  if (acc == private_field && fld.is_private ())
     return 1;
-  else if (acc == protected_field && TYPE_FIELD_PROTECTED (type, index))
+  else if (acc == protected_field && fld.is_protected ())
     return 1;
-  else if (acc == public_field && !TYPE_FIELD_PRIVATE (type, index)
-	   && !TYPE_FIELD_PROTECTED (type, index))
+  else if (acc == public_field && fld.is_public ())
     return 1;
   else
     return 0;
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index ac27e83618b..a59d77b76a9 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -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;
 
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 820a761054a..a803c786d2b 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -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);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 55d12218b4e..e9c84004026 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5229,31 +5229,32 @@ 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)
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 53a8f7e803c..31745f28156 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1973,15 +1973,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
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 41058a8b59e..b5d66269d6e 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -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)
 			{
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index fb9386293a6..05601622560 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -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);

-- 
2.40.1


  parent reply	other threads:[~2023-09-21 18:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21 18:01 [PATCH 0/7] Remove char-based bitfield macros Tom Tromey
2023-09-21 18:01 ` [PATCH 1/7] Use .def file to stringify type codes Tom Tromey
2023-09-25 21:58   ` Lancelot SIX
2023-09-26 13:10     ` Tom Tromey
2023-09-21 18:01 ` [PATCH 2/7] Print field accessibility inline Tom Tromey
2023-09-21 18:01 ` [PATCH 3/7] Remove byte vectors from cplus_struct_type Tom Tromey
2023-09-25 22:32   ` Lancelot SIX
2023-10-27 14:20     ` Tom Tromey
2023-09-21 18:01 ` [PATCH 4/7] Add field::is_public Tom Tromey
2023-09-21 18:01 ` [PATCH 5/7] Remove some QUIT calls from need_access_label_p Tom Tromey
2023-09-21 18:01 ` Tom Tromey [this message]
2023-09-21 18:01 ` [PATCH 7/7] Remove char-based bitfield macros Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230921-field-bits-v1-6-201285360900@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).