[PATCH 09/12] gdb: remove TYPE_FIELD_ENUMVAL

Simon Marchi simon.marchi@efficios.com
Thu Oct 21 17:23:52 GMT 2021


From: Simon Marchi <simon.marchi@polymtl.ca>

Remove TYPE_FIELD_ENUMVAL, replace with type::field +
field::loc_enumval.

Change-Id: I2ada73e4635aad3363ce2eb22c1dc52698ee2072
---
 gdb/ada-lang.c                    | 10 +++++-----
 gdb/ada-typeprint.c               |  6 +++---
 gdb/ada-valprint.c                |  6 +++---
 gdb/c-typeprint.c                 |  6 +++---
 gdb/compile/compile-c-types.c     |  2 +-
 gdb/compile/compile-cplus-types.c |  2 +-
 gdb/dwarf2/read.c                 |  2 +-
 gdb/gdbtypes.c                    | 18 +++++++++---------
 gdb/gdbtypes.h                    |  1 -
 gdb/m2-typeprint.c                |  6 +++---
 gdb/p-typeprint.c                 |  6 +++---
 gdb/python/py-type.c              |  2 +-
 gdb/typeprint.c                   |  2 +-
 gdb/valops.c                      |  2 +-
 gdb/valprint.c                    |  6 +++---
 15 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 007a3a88cb3..dc341dbc51e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -651,7 +651,7 @@ ada_discrete_type_high_bound (struct type *type)
 	  }
       }
     case TYPE_CODE_ENUM:
-      return TYPE_FIELD_ENUMVAL (type, type->num_fields () - 1);
+      return type->field (type->num_fields () - 1).loc_enumval ();
     case TYPE_CODE_BOOL:
       return 1;
     case TYPE_CODE_CHAR:
@@ -686,7 +686,7 @@ ada_discrete_type_low_bound (struct type *type)
 	  }
       }
     case TYPE_CODE_ENUM:
-      return TYPE_FIELD_ENUMVAL (type, 0);
+      return type->field (0).loc_enumval ();
     case TYPE_CODE_BOOL:
       return 0;
     case TYPE_CODE_CHAR:
@@ -4612,7 +4612,7 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
 
   /* All enums in the type should have an identical underlying value.  */
   for (i = 0; i < type1->num_fields (); i++)
-    if (TYPE_FIELD_ENUMVAL (type1, i) != TYPE_FIELD_ENUMVAL (type2, i))
+    if (type1->field (i).loc_enumval () != type2->field (i).loc_enumval ())
       return 0;
 
   /* All enumerals should also have the same name (modulo any numerical
@@ -8572,7 +8572,7 @@ val_atr (struct type *type, LONGEST val)
     {
       if (val < 0 || val >= type->num_fields ())
 	error (_("argument to 'VAL out of range"));
-      val = TYPE_FIELD_ENUMVAL (type, val);
+      val = type->field (val).loc_enumval ();
     }
   return value_from_longest (type, val);
 }
@@ -10206,7 +10206,7 @@ convert_char_literal (struct type *type, LONGEST val)
       size_t elen = strlen (ename);
 
       if (elen >= len && strcmp (name, ename + elen - len) == 0)
-	return TYPE_FIELD_ENUMVAL (type, f);
+	return type->field (f).loc_enumval ();
     }
   return val;
 }
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 6bc8912422b..e336e034480 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -328,11 +328,11 @@ print_enum_type (struct type *type, struct ui_file *stream)
       wrap_here ("    ");
       fputs_styled (ada_enum_name (type->field (i).name ()),
 		    variable_name_style.style (), stream);
-      if (lastval != TYPE_FIELD_ENUMVAL (type, i))
+      if (lastval != type->field (i).loc_enumval ())
 	{
 	  fprintf_filtered (stream, " => %s",
-			    plongest (TYPE_FIELD_ENUMVAL (type, i)));
-	  lastval = TYPE_FIELD_ENUMVAL (type, i);
+			    plongest (type->field (i).loc_enumval ()));
+	  lastval = type->field (i).loc_enumval ();
 	}
       lastval += 1;
     }
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 396e18f85fc..91a2f569edd 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -94,7 +94,7 @@ print_optional_low_bound (struct ui_file *stream, struct type *type,
     case TYPE_CODE_ENUM:
       if (low_bound == 0)
 	return 0;
-      low_bound = TYPE_FIELD_ENUMVAL (index_type, low_bound);
+      low_bound = index_type->field (low_bound).loc_enumval ();
       break;
     case TYPE_CODE_UNDEF:
       index_type = NULL;
@@ -381,7 +381,7 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
       len = type->num_fields ();
       for (i = 0; i < len; i++)
 	{
-	  if (TYPE_FIELD_ENUMVAL (type, i) == val)
+	  if (type->field (i).loc_enumval () == val)
 	    {
 	      break;
 	    }
@@ -835,7 +835,7 @@ ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse,
   for (i = 0; i < len; i++)
     {
       QUIT;
-      if (val == TYPE_FIELD_ENUMVAL (type, i))
+      if (val == type->field (i).loc_enumval ())
 	break;
     }
 
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index a471fdc2720..5f20233c78a 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1596,11 +1596,11 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
 	      wrap_here ("    ");
 	      fputs_styled (type->field (i).name (),
 			    variable_name_style.style (), stream);
-	      if (lastval != TYPE_FIELD_ENUMVAL (type, i))
+	      if (lastval != type->field (i).loc_enumval ())
 		{
 		  fprintf_filtered (stream, " = %s",
-				    plongest (TYPE_FIELD_ENUMVAL (type, i)));
-		  lastval = TYPE_FIELD_ENUMVAL (type, i);
+				    plongest (type->field (i).loc_enumval ()));
+		  lastval = type->field (i).loc_enumval ();
 		}
 	      lastval++;
 	    }
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 8fbbc0e4ef2..87eb970231d 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -137,7 +137,7 @@ convert_enum (compile_c_instance *context, struct type *type)
   for (i = 0; i < type->num_fields (); ++i)
     {
       context->plugin ().build_add_enum_constant
-	(result, type->field (i).name (), TYPE_FIELD_ENUMVAL (type, i));
+	(result, type->field (i).name (), type->field (i).loc_enumval ());
     }
 
   context->plugin ().finish_enum_type (result);
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index a54a5449242..1bd083df870 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -944,7 +944,7 @@ compile_cplus_convert_enum (compile_cplus_instance *instance, struct type *type,
 	continue;
 
       instance->plugin ().build_enum_constant (result, fname.get (),
-					       TYPE_FIELD_ENUMVAL (type, i));
+					       type->field (i).loc_enumval ());
     }
 
   /* Finish enum definition and pop scopes.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9777a1da440..a57d35d0b84 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9201,7 +9201,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
 	    {
 	      const char *name
 		= rust_last_path_segment (enum_type->field (i).name ());
-	      discriminant_map[name] = TYPE_FIELD_ENUMVAL (enum_type, i);
+	      discriminant_map[name] = enum_type->field (i).loc_enumval ();
 	    }
 	}
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 93bdb60fce9..d937d234026 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1068,12 +1068,12 @@ get_discrete_low_bound (struct type *type)
 	  {
 	    /* The enums may not be sorted by value, so search all
 	       entries.  */
-	    LONGEST low = TYPE_FIELD_ENUMVAL (type, 0);
+	    LONGEST low = type->field (0).loc_enumval ();
 
 	    for (int i = 0; i < type->num_fields (); i++)
 	      {
-		if (TYPE_FIELD_ENUMVAL (type, i) < low)
-		  low = TYPE_FIELD_ENUMVAL (type, i);
+		if (type->field (i).loc_enumval () < low)
+		  low = type->field (i).loc_enumval ();
 	      }
 
 	    /* Set unsigned indicator if warranted.  */
@@ -1139,12 +1139,12 @@ get_discrete_high_bound (struct type *type)
 	  {
 	    /* The enums may not be sorted by value, so search all
 	       entries.  */
-	    LONGEST high = TYPE_FIELD_ENUMVAL (type, 0);
+	    LONGEST high = type->field (0).loc_enumval ();
 
 	    for (int i = 0; i < type->num_fields (); i++)
 	      {
-		if (TYPE_FIELD_ENUMVAL (type, i) > high)
-		  high = TYPE_FIELD_ENUMVAL (type, i);
+		if (type->field (i).loc_enumval () > high)
+		  high = type->field (i).loc_enumval ();
 	      }
 
 	    return high;
@@ -1250,7 +1250,7 @@ discrete_position (struct type *type, LONGEST val)
 
       for (i = 0; i < type->num_fields (); i += 1)
 	{
-	  if (val == TYPE_FIELD_ENUMVAL (type, i))
+	  if (val == type->field (i).loc_enumval ())
 	    return i;
 	}
 
@@ -5337,7 +5337,7 @@ recursive_dump_type (struct type *type, int spaces)
     {
       if (type->code () == TYPE_CODE_ENUM)
 	printf_filtered ("%*s[%d] enumval %s type ", spaces + 2, "",
-			 idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
+			 idx, plongest (type->field (idx).loc_enumval ()));
       else
 	printf_filtered ("%*s[%d] bitpos %s bitsize %d type ", spaces + 2, "",
 			 idx, plongest (type->field (idx).loc_bitpos ()),
@@ -5565,7 +5565,7 @@ copy_type_recursive (struct objfile *objfile,
 	      new_type->field (i).set_loc_bitpos (type->field (i).loc_bitpos ());
 	      break;
 	    case FIELD_LOC_KIND_ENUMVAL:
-	      new_type->field (i).set_loc_enumval (TYPE_FIELD_ENUMVAL (type, i));
+	      new_type->field (i).set_loc_enumval (type->field (i).loc_enumval ());
 	      break;
 	    case FIELD_LOC_KIND_PHYSADDR:
 	      new_type->field (i).set_loc_physaddr
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 1b22705e34c..63accb7ca0e 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2128,7 +2128,6 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
 
-#define TYPE_FIELD_ENUMVAL(thistype, n) ((thistype)->field (n).loc_enumval ())
 #define TYPE_FIELD_STATIC_PHYSNAME(thistype, n) ((thistype)->field (n).loc_physname ())
 #define TYPE_FIELD_STATIC_PHYSADDR(thistype, n) ((thistype)->field (n).loc_physaddr ())
 #define TYPE_FIELD_DWARF_BLOCK(thistype, n) ((thistype)->field (n).loc_dwarf_block ())
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 8209686980f..c4504e7c266 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -611,11 +611,11 @@ m2_enum (struct type *type, struct ui_file *stream, int show, int level)
 	  wrap_here ("    ");
 	  fputs_styled (type->field (i).name (),
 			variable_name_style.style (), stream);
-	  if (lastval != TYPE_FIELD_ENUMVAL (type, i))
+	  if (lastval != type->field (i).loc_enumval ())
 	    {
 	      fprintf_filtered (stream, " = %s",
-				plongest (TYPE_FIELD_ENUMVAL (type, i)));
-	      lastval = TYPE_FIELD_ENUMVAL (type, i);
+				plongest (type->field (i).loc_enumval ()));
+	      lastval = type->field (i).loc_enumval ();
 	    }
 	  lastval++;
 	}
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 48bfba8b0d0..b2d167f68bf 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -711,12 +711,12 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
 		fprintf_filtered (stream, ", ");
 	      wrap_here ("    ");
 	      fputs_filtered (type->field (i).name (), stream);
-	      if (lastval != TYPE_FIELD_ENUMVAL (type, i))
+	      if (lastval != type->field (i).loc_enumval ())
 		{
 		  fprintf_filtered (stream,
 				    " := %s",
-				    plongest (TYPE_FIELD_ENUMVAL (type, i)));
-		  lastval = TYPE_FIELD_ENUMVAL (type, i);
+				    plongest (type->field (i).loc_enumval ()));
+		  lastval = type->field (i).loc_enumval ();
 		}
 	      lastval++;
 	    }
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 0895093e5e3..8b17b70fbe3 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -184,7 +184,7 @@ convert_field (struct type *type, int field)
 
       if (type->code () == TYPE_CODE_ENUM)
 	{
-	  arg = gdb_py_object_from_longest (TYPE_FIELD_ENUMVAL (type, field));
+	  arg = gdb_py_object_from_longest (type->field (field).loc_enumval ());
 	  attrstring = "enumval";
 	}
       else
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 18131b459fd..e4c5d1c05b2 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -626,7 +626,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
       len = type->num_fields ();
       for (i = 0; i < len; i++)
 	{
-	  if (TYPE_FIELD_ENUMVAL (type, i) == val)
+	  if (type->field (i).loc_enumval () == val)
 	    {
 	      break;
 	    }
diff --git a/gdb/valops.c b/gdb/valops.c
index b5654b85c7c..84054a6c8b2 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3340,7 +3340,7 @@ enum_constant_from_type (struct type *type, const char *name)
 	  && fname[len - name_len - 2] == ':'
 	  && fname[len - name_len - 1] == ':'
 	  && strcmp (&fname[len - name_len], name) == 0)
-	return value_from_longest (type, TYPE_FIELD_ENUMVAL (type, i));
+	return value_from_longest (type, type->field (i).loc_enumval ());
     }
 
   error (_("no constant named \"%s\" in enum \"%s\""),
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 0c29b343e4c..f0b231a5e78 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -608,7 +608,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
   for (i = 0; i < len; i++)
     {
       QUIT;
-      if (val == TYPE_FIELD_ENUMVAL (type, i))
+      if (val == type->field (i).loc_enumval ())
 	{
 	  break;
 	}
@@ -630,7 +630,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
 	{
 	  QUIT;
 
-	  ULONGEST enumval = TYPE_FIELD_ENUMVAL (type, i);
+	  ULONGEST enumval = type->field (i).loc_enumval ();
 	  int nbits = count_one_bits_ll (enumval);
 
 	  gdb_assert (nbits == 0 || nbits == 1);
@@ -645,7 +645,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
 	      else
 		fputs_filtered (" | ", stream);
 
-	      val &= ~TYPE_FIELD_ENUMVAL (type, i);
+	      val &= ~type->field (i).loc_enumval ();
 	      fputs_styled (type->field (i).name (),
 			    variable_name_style.style (), stream);
 	    }
-- 
2.33.0



More information about the Gdb-patches mailing list