[10/12] gdb: remove TYPE_BIT_STRIDE

Message ID 20200706133950.145851-11-simon.marchi@polymtl.ca
State New
Headers show
Series
  • More type macros removal
Related show

Commit Message

Simon Marchi via Gdb-patches July 6, 2020, 1:39 p.m.
From: Simon Marchi <simon.marchi@efficios.com>


Remove the macro and add a `bit_stride` method to `struct range_bounds`,
which does the byte -> bit conversion if needed.

Add a convenience `bit_stride` method to `struct type` as well.  I don't
really understand why the bit/byte stride is stored in the data
structure for bounds.  Maybe it was just put there because
`range_bounds` was already a data structure specific to TYPE_CODE_RANGE
types?  If the stride is indeed not related to the bounds, then I find
it more logical to do `my_range_type->bit_stride ()` than
`my_range_type->bounds ()->bit_stride ()`, hence the convenience
function on `struct type`.

gdb/ChangeLog:

	* gdbtypes.h (struct range_bounds) <bit_stride>: New method.
	(struct type) <bit_stride>: New method.
	(TYPE_BIT_STRIDE): Remove.
	* gdbtypes.c (update_static_array_size): Use type::bit_stride.

Change-Id: I6ecc1cfefdc20711fa8f188a94a05c1e116c9922
---
 gdb/gdbtypes.c |  2 +-
 gdb/gdbtypes.h | 19 ++++++++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

-- 
2.27.0

Patch

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 227f696b7363..e87648813ec5 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1205,7 +1205,7 @@  update_static_array_size (struct type *type)
 	 arrays bit size field.  */
       stride = TYPE_FIELD_BITSIZE (type, 0);
       if (stride == 0)
-	stride = TYPE_BIT_STRIDE (range_type);
+	stride = range_type->bit_stride ();
 
       if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
 	low_bound = high_bound = 0;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 26db7935f265..bf6b270515ff 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -757,6 +757,14 @@  struct field
 
 struct range_bounds
 {
+  ULONGEST bit_stride () const
+  {
+    if (this->flag_is_byte_stride)
+      return this->stride.const_val () * 8;
+    else
+      return this->stride.const_val ();
+  }
+
   /* * Low bound of range.  */
 
   struct dynamic_prop low;
@@ -1045,6 +1053,11 @@  struct type
     this->main_type->flds_bnds.bounds = bounds;
   }
 
+  ULONGEST bit_stride () const
+  {
+    return this->bounds ()->bit_stride ();
+  }
+
   /* * 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;
@@ -1594,10 +1607,6 @@  extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_BIT_STRIDE(range_type) \
-  ((range_type)->bounds ()->stride.const_val () \
-   * ((range_type)->bounds ()->flag_is_byte_stride ? 8 : 1))
-
 /* Property accessors for the type data location.  */
 #define TYPE_DATA_LOCATION(thistype) \
   ((thistype)->dyn_prop (DYN_PROP_DATA_LOCATION))
@@ -1629,7 +1638,7 @@  extern bool set_type_align (struct type *, ULONGEST);
    index type.  */
 
 #define TYPE_ARRAY_BIT_STRIDE(arraytype) \
-  (TYPE_BIT_STRIDE(((arraytype)->index_type ())))
+  ((arraytype)->index_type ()->bounds ()->bit_stride ())
 
 /* C++ */