[01/22] gdb: add type::is_unsigned / type::set_is_unsigned

Message ID 20200818165556.27332-2-simon.marchi@efficios.com
State New
Headers show
Series
  • Change type flags macros to methods
Related show

Commit Message

Simon Marchi via Gdb-patches Aug. 18, 2020, 4:55 p.m.
Add the `is_unsigned` and `set_is_unsigned` methods on `struct type`, in
order to remove the `TYPE_UNSIGNED` macro.  In this patch, the
`TYPE_UNSIGNED` macro is changed to use `type::is_unsigned`, so all the
call sites that are used to set this property on a type are changed to
use the new method.  The next patch will remove the macro completely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <is_unsigned, set_is_unsigned>: New
	methods.
	(TYPE_UNSIGNED): Use type::is_unsigned.  Change all write call
	sites to use type::set_is_unsigned.

Change-Id: Ib09ddce84eda160a801a8f288cccf61c8ef136bc
---
 gdb/ada-valprint.c        |  2 +-
 gdb/coffread.c            |  2 +-
 gdb/dwarf2/read.c         |  8 ++++++--
 gdb/gdbtypes.c            | 30 ++++++++++++++----------------
 gdb/gdbtypes.h            | 14 ++++++++++++--
 gdb/mdebugread.c          |  2 +-
 gdb/stabsread.c           |  5 +++--
 gdb/target-descriptions.c |  3 ++-
 gdb/windows-tdep.c        |  2 +-
 9 files changed, 41 insertions(+), 27 deletions(-)

-- 
2.28.0

Patch

diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 6a5b7d3f37a..c61688db2b1 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -43,7 +43,7 @@  adjust_type_signedness (struct type *type)
 {
   if (type != NULL && type->code () == TYPE_CODE_RANGE
       && type->bounds ()->low.const_val () >= 0)
-    TYPE_UNSIGNED (type) = 1;
+    type->set_is_unsigned (true);
 }
 
 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 1592dc645cd..a43d9e2679e 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -2152,7 +2152,7 @@  coff_read_enum_type (int index, int length, int lastsym,
     }
 
   if (unsigned_enum)
-    TYPE_UNSIGNED (type) = 1;
+    type->set_is_unsigned (true);
 
   return type;
 }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0ac8533263a..643bfc5509f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -16568,7 +16568,8 @@  update_enumeration_type_from_children (struct die_info *die,
     }
 
   if (unsigned_enum)
-    TYPE_UNSIGNED (type) = 1;
+    type->set_is_unsigned (true);
+
   if (flag_enum)
     TYPE_FLAG_ENUM (type) = 1;
 }
@@ -16643,9 +16644,12 @@  read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct type *underlying_type = TYPE_TARGET_TYPE (type);
       underlying_type = check_typedef (underlying_type);
-      TYPE_UNSIGNED (type) = TYPE_UNSIGNED (underlying_type);
+
+      type->set_is_unsigned (underlying_type->is_unsigned ());
+
       if (TYPE_LENGTH (type) == 0)
 	TYPE_LENGTH (type) = TYPE_LENGTH (underlying_type);
+
       if (TYPE_RAW_ALIGN (type) == 0
 	  && TYPE_RAW_ALIGN (underlying_type) != 0)
 	set_type_align (type, TYPE_RAW_ALIGN (underlying_type));
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c1eb03d8984..5d3a6f79e09 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -371,7 +371,7 @@  make_pointer_type (struct type *type, struct type **typeptr)
   /* Mark pointers as unsigned.  The target converts between pointers
      and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
      gdbarch_address_to_pointer.  */
-  TYPE_UNSIGNED (ntype) = 1;
+  ntype->set_is_unsigned (true);
 
   /* Update the length of all the other variants of this type.  */
   chain = TYPE_CHAIN (ntype);
@@ -945,14 +945,14 @@  create_range_type (struct type *result_type, struct type *index_type,
   result_type->set_bounds (bounds);
 
   if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0)
-    TYPE_UNSIGNED (result_type) = 1;
+    result_type->set_is_unsigned (true);
 
   /* Ada allows the declaration of range types whose upper bound is
      less than the lower bound, so checking the lower bound is not
      enough.  Make sure we do not mark a range type whose upper bound
      is negative as unsigned.  */
   if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0)
-    TYPE_UNSIGNED (result_type) = 0;
+    result_type->set_is_unsigned (false);
 
   TYPE_ENDIANITY_NOT_DEFAULT (result_type)
     = TYPE_ENDIANITY_NOT_DEFAULT (index_type);
@@ -1069,9 +1069,7 @@  get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
 
 	  /* Set unsigned indicator if warranted.  */
 	  if (*lowp >= 0)
-	    {
-	      TYPE_UNSIGNED (type) = 1;
-	    }
+	    type->set_is_unsigned (true);
 	}
       else
 	{
@@ -1396,7 +1394,7 @@  create_set_type (struct type *result_type, struct type *domain_type)
       TYPE_LENGTH (result_type)
 	= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
       if (low_bound >= 0)
-	TYPE_UNSIGNED (result_type) = 1;
+	result_type->set_is_unsigned (true);
     }
   result_type->field (0).set_type (domain_type);
 
@@ -3187,7 +3185,7 @@  init_integer_type (struct objfile *objfile,
 
   t = init_type (objfile, TYPE_CODE_INT, bit, name);
   if (unsigned_p)
-    TYPE_UNSIGNED (t) = 1;
+    t->set_is_unsigned (true);
 
   return t;
 }
@@ -3204,7 +3202,7 @@  init_character_type (struct objfile *objfile,
 
   t = init_type (objfile, TYPE_CODE_CHAR, bit, name);
   if (unsigned_p)
-    TYPE_UNSIGNED (t) = 1;
+    t->set_is_unsigned (true);
 
   return t;
 }
@@ -3221,7 +3219,7 @@  init_boolean_type (struct objfile *objfile,
 
   t = init_type (objfile, TYPE_CODE_BOOL, bit, name);
   if (unsigned_p)
-    TYPE_UNSIGNED (t) = 1;
+    t->set_is_unsigned (true);
 
   return t;
 }
@@ -3315,7 +3313,7 @@  init_pointer_type (struct objfile *objfile,
 
   t = init_type (objfile, TYPE_CODE_PTR, bit, name);
   TYPE_TARGET_TYPE (t) = target_type;
-  TYPE_UNSIGNED (t) = 1;
+  t->set_is_unsigned (true);
   return t;
 }
 
@@ -5473,7 +5471,7 @@  arch_integer_type (struct gdbarch *gdbarch,
 
   t = arch_type (gdbarch, TYPE_CODE_INT, bit, name);
   if (unsigned_p)
-    TYPE_UNSIGNED (t) = 1;
+    t->set_is_unsigned (true);
 
   return t;
 }
@@ -5490,7 +5488,7 @@  arch_character_type (struct gdbarch *gdbarch,
 
   t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name);
   if (unsigned_p)
-    TYPE_UNSIGNED (t) = 1;
+    t->set_is_unsigned (true);
 
   return t;
 }
@@ -5507,7 +5505,7 @@  arch_boolean_type (struct gdbarch *gdbarch,
 
   t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name);
   if (unsigned_p)
-    TYPE_UNSIGNED (t) = 1;
+    t->set_is_unsigned (true);
 
   return t;
 }
@@ -5557,7 +5555,7 @@  arch_pointer_type (struct gdbarch *gdbarch,
 
   t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
   TYPE_TARGET_TYPE (t) = target_type;
-  TYPE_UNSIGNED (t) = 1;
+  t->set_is_unsigned (true);
   return t;
 }
 
@@ -5570,7 +5568,7 @@  arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
   struct type *type;
 
   type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name);
-  TYPE_UNSIGNED (type) = 1;
+  type->set_is_unsigned (true);
   type->set_num_fields (0);
   /* Pre-allocate enough space assuming every field is one bit.  */
   type->set_fields
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 55a6dafb7e2..a5ce444e2ef 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -213,7 +213,7 @@  DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
 /* * Unsigned integer type.  If this is not set for a TYPE_CODE_INT,
    the type is signed (unless TYPE_NOSIGN (below) is set).  */
 
-#define TYPE_UNSIGNED(t)	(TYPE_MAIN_TYPE (t)->flag_unsigned)
+#define TYPE_UNSIGNED(t)	((t)->is_unsigned ())
 
 /* * No sign for this type.  In C++, "char", "signed char", and
    "unsigned char" are distinct types; so we need an extra flag to
@@ -855,7 +855,7 @@  struct main_type
      because they packs nicely here.  See the TYPE_* macros for
      documentation about these fields.  */
 
-  unsigned int flag_unsigned : 1;
+  unsigned int m_flag_unsigned : 1;
   unsigned int flag_nosign : 1;
   unsigned int flag_stub : 1;
   unsigned int flag_target_stub : 1;
@@ -1068,6 +1068,16 @@  struct type
     return this->bounds ()->bit_stride ();
   }
 
+  bool is_unsigned () const
+  {
+    return this->main_type->m_flag_unsigned;
+  }
+
+  void set_is_unsigned (bool is_unsigned)
+  {
+    this->main_type->m_flag_unsigned = is_unsigned;
+  }
+
   /* * 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;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index d38372041d7..376101e95cb 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1072,7 +1072,7 @@  parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 		f++;
 	      }
 	    if (unsigned_enum)
-	      TYPE_UNSIGNED (t) = 1;
+	      t->set_is_unsigned (true);
 	  }
 	/* Make this the current type.  */
 	top_stack->cur_type = t;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index d2ff54a47bd..b30b0750f36 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -3616,7 +3616,7 @@  read_enum_type (const char **pp, struct type *type,
   type->set_code (TYPE_CODE_ENUM);
   TYPE_STUB (type) = 0;
   if (unsigned_enum)
-    TYPE_UNSIGNED (type) = 1;
+    type->set_is_unsigned (true);
   type->set_num_fields (nsyms);
   type->set_fields
     ((struct field *)
@@ -3731,7 +3731,8 @@  read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile
       struct type *type = init_type (objfile, TYPE_CODE_VOID,
 				     TARGET_CHAR_BIT, NULL);
       if (unsigned_type)
-        TYPE_UNSIGNED (type) = 1;
+	type->set_is_unsigned (true);
+
       return type;
     }
 
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 20d624c0c65..86812bbbc48 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -284,7 +284,8 @@  make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype)
       m_type = arch_type (m_gdbarch, TYPE_CODE_ENUM, e->size * TARGET_CHAR_BIT,
 			  e->name.c_str ());
 
-      TYPE_UNSIGNED (m_type) = 1;
+      m_type->set_is_unsigned (true);
+
       for (const tdesc_type_field &f : e->fields)
 	{
 	  struct field *fld
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index aa0adeba99b..0dee73a7bba 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -754,7 +754,7 @@  create_enum (struct gdbarch *gdbarch, int bit, const char *name,
   type->set_num_fields (count);
   type->set_fields
     ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count));
-  TYPE_UNSIGNED (type) = 1;
+  type->set_is_unsigned (true);
 
   for (i = 0; i < count; i++)
   {