Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] (for VLA) Prepare for 3-fields TYPE_CODE_RANGE  (TYPE_HIGH_BOUND)
@ 2008-12-26 22:43 Jan Kratochvil
  2008-12-28 13:09 ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2008-12-26 22:43 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker, Ulrich Weigand, Jim Blandy, Tobias Burnus

Hi,

the VLA (variable-length-arrays) / Fortran dynamic arrays / DW_FORM_block*
patch requires support for DW_AT_byte_stride which got implemented as a third
field for TYPE_CODE_RANGE - besides TYPE_LOW_BOUND and TYPE_HIGH_BOUND also
TYPE_BYTE_STRIDE.

Some Ada code assumed the last field of TYPE_CODE_RANGE is TYPE_HIGH_BOUND.

Questionable is whether ada_array_bound_from_type() can get something besides
TYPE_CODE_RANGE or TYPE_CODE_ENUM which gets internal_error()ed now.  I did
not find such case but the TYPE_CODE_ENUM case could be changed to `default:'
if it can happen.

Most of the patch are [obv]ious macro substitutions as a cleanup which are
requested for approval if it is right to do at all.

Regression tested on x86_64-unknown-linux-gnu with create_range_type()'s:
-  TYPE_NFIELDS (result_type) = 2;
+  TYPE_NFIELDS (result_type) = 3;


Thanks,
Jan


2008-12-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix TYPE_HIGH_BOUND for TYPE_CODE_RANGE using arbitrary TYPE_NFIELDS.
	* ada-lang.c (packed_array_type, ada_index_type): Use TYPE_INDEX_TYPE.
	(ada_array_bound_from_type): Move `index_type' declaration to the
	function start.  Return the bounds for TYPE_CODE_RANGE using
	TYPE_LOW_BOUND and TYPE_HIGH_BOUND.  Abort on invalid index type codes.
	* ada-typeprint.c (print_range): Set `upper_bound' for TYPE_CODE_RANGE
	now using TYPE_HIGH_BOUND.
	* ada-valprint.c (val_print_packed_array_elements): Use `index_type'.
	* eval.c (evaluate_subexp_standard): Use TYPE_INDEX_TYPE.
	* gdbtypes.c (create_range_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
	refer to the number of fields only through TYPE_NFIELDS.
	(create_array_type): Use TYPE_INDEX_TYPE.
	(check_typedef): Use TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND.
	* gdbtypes.h (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED)
	(TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED): Use TYPE_INDEX_TYPE.
	(TYPE_ARRAY_UPPER_BOUND_VALUE, TYPE_ARRAY_LOWER_BOUND_VALUE): Use
	TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
	* hppa-tdep.c (hppa_alignof <TYPE_CODE_ARRAY>): Use TYPE_INDEX_TYPE.
	* mdebugread.c (parse_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
	* valarith.c (value_bit_index): Use TYPE_INDEX_TYPE.

--- gdb/ada-lang.c	15 Dec 2008 10:40:28 -0000	1.185
+++ gdb/ada-lang.c	26 Dec 2008 19:50:02 -0000
@@ -1777,11 +1777,11 @@ packed_array_type (struct type *type, lo
   new_type = alloc_type (TYPE_OBJFILE (type));
   new_elt_type = packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
                                     elt_bits);
-  create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0));
+  create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
   TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
   TYPE_NAME (new_type) = ada_type_name (type);
 
-  if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
+  if (get_discrete_bounds (TYPE_INDEX_TYPE (type),
                            &low_bound, &high_bound) < 0)
     low_bound = high_bound = 0;
   if (high_bound < low_bound)
@@ -2468,7 +2468,7 @@ ada_index_type (struct type *type, int n
 
       for (i = 1; i < n; i += 1)
         type = TYPE_TARGET_TYPE (type);
-      result_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0));
+      result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
       /* FIXME: The stabs type r(0,0);bound;bound in an array type
          has a target type of TYPE_CODE_UNDEF.  We compensate here, but
          perhaps stabsread.c would make more sense.  */
@@ -2492,8 +2492,9 @@ static LONGEST
 ada_array_bound_from_type (struct type * arr_type, int n, int which,
                            struct type ** typep)
 {
-  struct type *type;
-  struct type *index_type_desc;
+  struct type *type, *index_type_desc, *index_type;
+
+  gdb_assert (which == 0 || which == 1);
 
   if (ada_is_packed_array_type (arr_type))
     arr_type = decode_packed_array_type (arr_type);
@@ -2511,10 +2512,11 @@ ada_array_bound_from_type (struct type *
     type = arr_type;
 
   index_type_desc = ada_find_parallel_type (type, "___XA");
-  if (index_type_desc == NULL)
+  if (index_type_desc != NULL)
+    index_type = to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
+				      NULL, TYPE_OBJFILE (arr_type));
+  else
     {
-      struct type *index_type;
-
       while (n > 1)
         {
           type = TYPE_TARGET_TYPE (type);
@@ -2522,33 +2524,22 @@ ada_array_bound_from_type (struct type *
         }
 
       index_type = TYPE_INDEX_TYPE (type);
-      if (typep != NULL)
-        *typep = index_type;
-
-      /* The index type is either a range type or an enumerated type.
-         For the range type, we have some macros that allow us to
-         extract the value of the low and high bounds.  But they
-         do now work for enumerated types.  The expressions used
-         below work for both range and enum types.  */
-      return
-        (LONGEST) (which == 0
-                   ? TYPE_FIELD_BITPOS (index_type, 0)
-                   : TYPE_FIELD_BITPOS (index_type,
-                                        TYPE_NFIELDS (index_type) - 1));
     }
-  else
-    {
-      struct type *index_type =
-        to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
-                             NULL, TYPE_OBJFILE (arr_type));
 
-      if (typep != NULL)
-        *typep = index_type;
+  if (typep != NULL)
+    *typep = index_type;
 
-      return
-        (LONGEST) (which == 0
-                   ? TYPE_LOW_BOUND (index_type)
-                   : TYPE_HIGH_BOUND (index_type));
+  switch (TYPE_CODE (index_type))
+    {
+    case TYPE_CODE_RANGE:
+      return which == 0 ? TYPE_LOW_BOUND (index_type)
+			: TYPE_HIGH_BOUND (index_type);
+    case TYPE_CODE_ENUM:
+      return which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
+			: TYPE_FIELD_BITPOS (index_type,
+					     TYPE_NFIELDS (index_type) - 1);
+    default:
+      internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
     }
 }
 
--- gdb/ada-typeprint.c	11 Sep 2008 14:22:32 -0000	1.22
+++ gdb/ada-typeprint.c	26 Dec 2008 21:34:32 -0000
@@ -170,8 +170,9 @@ print_range (struct type *type, struct u
       /* We extract the range type bounds respectively from the first element
          and the last element of the type->fields array */
       const LONGEST lower_bound = (LONGEST) TYPE_LOW_BOUND (type);
-      const LONGEST upper_bound =
-	(LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
+      const LONGEST upper_bound = (TYPE_CODE (type) == TYPE_CODE_RANGE
+	? (LONGEST) TYPE_HIGH_BOUND (type)
+	: (LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1));
 
       ada_print_scalar (target_type, lower_bound, stream);
       fprintf_filtered (stream, " .. ");
--- gdb/ada-valprint.c	28 Oct 2008 17:19:56 -0000	1.44
+++ gdb/ada-valprint.c	26 Dec 2008 19:50:02 -0000
@@ -162,7 +162,7 @@ val_print_packed_array_elements (struct 
 
   {
     LONGEST high;
-    if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0)
+    if (get_discrete_bounds (index_type, &low, &high) < 0)
       len = 1;
     else
       len = high - low + 1;
--- gdb/eval.c	4 Nov 2008 15:32:54 -0000	1.102
+++ gdb/eval.c	26 Dec 2008 19:50:06 -0000
@@ -824,7 +824,7 @@ evaluate_subexp_standard (struct type *e
       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
 	  && TYPE_CODE (type) == TYPE_CODE_ARRAY)
 	{
-	  struct type *range_type = TYPE_FIELD_TYPE (type, 0);
+	  struct type *range_type = TYPE_INDEX_TYPE (type);
 	  struct type *element_type = TYPE_TARGET_TYPE (type);
 	  struct value *array = allocate_value (expect_type);
 	  int element_size = TYPE_LENGTH (check_typedef (element_type));
--- gdb/gdbtypes.c	10 Nov 2008 20:53:43 -0000	1.155
+++ gdb/gdbtypes.c	26 Dec 2008 19:50:06 -0000
@@ -711,16 +711,18 @@ create_range_type (struct type *result_t
   else
     TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
   TYPE_NFIELDS (result_type) = 2;
-  TYPE_FIELDS (result_type) = (struct field *)
-    TYPE_ALLOC (result_type, 2 * sizeof (struct field));
-  memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
-  TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
-  TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
+  TYPE_FIELDS (result_type) = TYPE_ALLOC (result_type,
+					  TYPE_NFIELDS (result_type)
+					  * sizeof (struct field));
+  memset (TYPE_FIELDS (result_type), 0,
+	  TYPE_NFIELDS (result_type) * sizeof (struct field));
+  TYPE_LOW_BOUND (result_type) = low_bound;
+  TYPE_HIGH_BOUND (result_type) = high_bound;
 
   if (low_bound >= 0)
     TYPE_UNSIGNED (result_type) = 1;
 
-  return (result_type);
+  return result_type;
 }
 
 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
@@ -831,7 +833,7 @@ create_array_type (struct type *result_t
   TYPE_FIELDS (result_type) =
     (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
   memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
-  TYPE_FIELD_TYPE (result_type, 0) = range_type;
+  TYPE_INDEX_TYPE (result_type) = range_type;
   TYPE_VPTR_FIELDNO (result_type) = -1;
 
   /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
@@ -1517,15 +1519,15 @@ check_typedef (struct type *type)
 	}
       else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
 	       && TYPE_NFIELDS (type) == 1
-	       && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
+	       && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
 		   == TYPE_CODE_RANGE))
 	{
 	  /* Now recompute the length of the array type, based on its
 	     number of elements and the target type's length.
 	     Watch out for Ada null Ada arrays where the high bound
 	     is smaller than the low bound.  */
-	  const int low_bound = TYPE_FIELD_BITPOS (range_type, 0);
-	  const int high_bound = TYPE_FIELD_BITPOS (range_type, 1);
+	  const int low_bound = TYPE_LOW_BOUND (range_type);
+	  const int high_bound = TYPE_HIGH_BOUND (range_type);
 	  int nb_elements;
 	
 	  if (high_bound < low_bound)
--- gdb/gdbtypes.h	28 Oct 2008 17:19:56 -0000	1.95
+++ gdb/gdbtypes.h	26 Dec 2008 19:50:07 -0000
@@ -815,15 +815,15 @@ extern void allocate_cplus_struct_type (
 /* Moto-specific stuff for FORTRAN arrays */
 
 #define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
-   (TYPE_FIELD_ARTIFICIAL((TYPE_FIELD_TYPE((arraytype),0)),1))
+   (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
-   (TYPE_FIELD_ARTIFICIAL((TYPE_FIELD_TYPE((arraytype),0)),0))
+   (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
 
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
-   (TYPE_FIELD_BITPOS((TYPE_FIELD_TYPE((arraytype),0)),1))
+   (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
 
 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
-   (TYPE_FIELD_BITPOS((TYPE_FIELD_TYPE((arraytype),0)),0))
+   (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
 
 /* C++ */
 
--- gdb/hppa-tdep.c	15 Sep 2008 01:56:31 -0000	1.261
+++ gdb/hppa-tdep.c	26 Dec 2008 19:50:10 -0000
@@ -1313,7 +1313,7 @@ hppa_alignof (struct type *type)
     case TYPE_CODE_FLT:
       return TYPE_LENGTH (type);
     case TYPE_CODE_ARRAY:
-      return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
+      return hppa_alignof (TYPE_INDEX_TYPE (type));
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
       max_align = 1;
--- gdb/mdebugread.c	8 Oct 2008 12:49:12 -0000	1.96
+++ gdb/mdebugread.c	26 Dec 2008 19:51:28 -0000
@@ -1644,11 +1644,11 @@ parse_type (int fd, union aux_ext *ax, u
 			  TYPE_ALLOC (tp, 2 * sizeof (struct field)));
       TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
 					    &current_objfile->objfile_obstack);
-      TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
+      TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
       ax++;
       TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
 					    &current_objfile->objfile_obstack);
-      TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
+      TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
       ax++;
     }
 
--- gdb/valarith.c	11 Sep 2008 14:25:49 -0000	1.67
+++ gdb/valarith.c	26 Dec 2008 19:51:34 -0000
@@ -1557,7 +1557,7 @@ value_bit_index (struct type *type, cons
   LONGEST low_bound, high_bound;
   LONGEST word;
   unsigned rel_index;
-  struct type *range = TYPE_FIELD_TYPE (type, 0);
+  struct type *range = TYPE_INDEX_TYPE (type);
   if (get_discrete_bounds (range, &low_bound, &high_bound) < 0)
     return -2;
   if (index < low_bound || index > high_bound)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] (for VLA) Prepare for 3-fields TYPE_CODE_RANGE (TYPE_HIGH_BOUND)
  2008-12-26 22:43 [patch] (for VLA) Prepare for 3-fields TYPE_CODE_RANGE (TYPE_HIGH_BOUND) Jan Kratochvil
@ 2008-12-28 13:09 ` Joel Brobecker
  2008-12-28 14:18   ` Jan Kratochvil
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2008-12-28 13:09 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches, Ulrich Weigand, Jim Blandy, Tobias Burnus

> Questionable is whether ada_array_bound_from_type() can get something besides
> TYPE_CODE_RANGE or TYPE_CODE_ENUM which gets internal_error()ed now.  I did
> not find such case but the TYPE_CODE_ENUM case could be changed to `default:'
> if it can happen.

Initially, I was thinking that maybe we could get a range type that's
a TYPE_CODE_INT. But that's not possible either with stabs nor DWARF.
But I think the code is fine as it is.

> 2008-12-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	Fix TYPE_HIGH_BOUND for TYPE_CODE_RANGE using arbitrary TYPE_NFIELDS.

Perhaps you could mention that this is in preparation for supporting
DW_AT_byte_stride.

> 	* ada-lang.c (packed_array_type, ada_index_type): Use TYPE_INDEX_TYPE.
> 	(ada_array_bound_from_type): Move `index_type' declaration to the
> 	function start.  Return the bounds for TYPE_CODE_RANGE using
> 	TYPE_LOW_BOUND and TYPE_HIGH_BOUND.  Abort on invalid index type codes.
> 	* ada-typeprint.c (print_range): Set `upper_bound' for TYPE_CODE_RANGE
> 	now using TYPE_HIGH_BOUND.
> 	* ada-valprint.c (val_print_packed_array_elements): Use `index_type'.
> 	* eval.c (evaluate_subexp_standard): Use TYPE_INDEX_TYPE.
> 	* gdbtypes.c (create_range_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
> 	refer to the number of fields only through TYPE_NFIELDS.
> 	(create_array_type): Use TYPE_INDEX_TYPE.
> 	(check_typedef): Use TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND.
> 	* gdbtypes.h (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED)
> 	(TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED): Use TYPE_INDEX_TYPE.
> 	(TYPE_ARRAY_UPPER_BOUND_VALUE, TYPE_ARRAY_LOWER_BOUND_VALUE): Use
> 	TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
> 	* hppa-tdep.c (hppa_alignof <TYPE_CODE_ARRAY>): Use TYPE_INDEX_TYPE.
> 	* mdebugread.c (parse_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
> 	* valarith.c (value_bit_index): Use TYPE_INDEX_TYPE.

OK.  Please just make a tiny change before checking in.


(in ada_array_bound_from_type):

> +  if (typep != NULL)
> +    *typep = index_type;
>  
> -      return
> -        (LONGEST) (which == 0
> -                   ? TYPE_LOW_BOUND (index_type)
> -                   : TYPE_HIGH_BOUND (index_type));
> +  switch (TYPE_CODE (index_type))
> +    {
> +    case TYPE_CODE_RANGE:
> +      return which == 0 ? TYPE_LOW_BOUND (index_type)
> +			: TYPE_HIGH_BOUND (index_type);
> +    case TYPE_CODE_ENUM:
> +      return which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
> +			: TYPE_FIELD_BITPOS (index_type,
> +					     TYPE_NFIELDS (index_type) - 1);
> +    default:
> +      internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
>      }

If we raise the internal_error, I'd rather we do no assign *typep.
Can you instead compute the bound value first, and then, if we haven't
detected the internal error, assign *typep before returning the bound?

Thanks,
-- 
Joel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] (for VLA) Prepare for 3-fields TYPE_CODE_RANGE  (TYPE_HIGH_BOUND)
  2008-12-28 13:09 ` Joel Brobecker
@ 2008-12-28 14:18   ` Jan Kratochvil
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kratochvil @ 2008-12-28 14:18 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches, Ulrich Weigand, Jim Blandy, Tobias Burnus

On Sun, 28 Dec 2008 14:08:36 +0100, Joel Brobecker wrote:
> Perhaps you could mention that this is in preparation for supporting
> DW_AT_byte_stride.

Done.

> (in ada_array_bound_from_type):
> If we raise the internal_error, I'd rather we do no assign *typep.
> Can you instead compute the bound value first, and then, if we haven't
> detected the internal error, assign *typep before returning the bound?

Done.

Checked in.


Thanks,
Jan


2008-12-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix TYPE_HIGH_BOUND for TYPE_CODE_RANGE using arbitrary TYPE_NFIELDS in
	preparation for supporting DW_AT_byte_stride.
	* ada-lang.c (packed_array_type, ada_index_type): Use TYPE_INDEX_TYPE.
	(ada_array_bound_from_type): Move `index_type' declaration to the
	function start.  New variable `retval'.  Return the bounds for
	TYPE_CODE_RANGE using TYPE_LOW_BOUND and TYPE_HIGH_BOUND.  Abort on
	invalid index type codes.
	* ada-typeprint.c (print_range): Set `upper_bound' for TYPE_CODE_RANGE
	now using TYPE_HIGH_BOUND.
	* ada-valprint.c (val_print_packed_array_elements): Use `index_type'.
	* eval.c (evaluate_subexp_standard): Use TYPE_INDEX_TYPE.
	* gdbtypes.c (create_range_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
	refer to the number of fields only through TYPE_NFIELDS.
	(create_array_type): Use TYPE_INDEX_TYPE.
	(check_typedef): Use TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND.
	* gdbtypes.h (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED)
	(TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED): Use TYPE_INDEX_TYPE.
	(TYPE_ARRAY_UPPER_BOUND_VALUE, TYPE_ARRAY_LOWER_BOUND_VALUE): Use
	TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
	* hppa-tdep.c (hppa_alignof <TYPE_CODE_ARRAY>): Use TYPE_INDEX_TYPE.
	* mdebugread.c (parse_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
	* valarith.c (value_bit_index): Use TYPE_INDEX_TYPE.

===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.185
retrieving revision 1.186
diff -u -r1.185 -r1.186
--- src/gdb/ada-lang.c	2008/12/15 10:40:28	1.185
+++ src/gdb/ada-lang.c	2008/12/28 14:14:18	1.186
@@ -1777,11 +1777,11 @@
   new_type = alloc_type (TYPE_OBJFILE (type));
   new_elt_type = packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
                                     elt_bits);
-  create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0));
+  create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
   TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
   TYPE_NAME (new_type) = ada_type_name (type);
 
-  if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
+  if (get_discrete_bounds (TYPE_INDEX_TYPE (type),
                            &low_bound, &high_bound) < 0)
     low_bound = high_bound = 0;
   if (high_bound < low_bound)
@@ -2468,7 +2468,7 @@
 
       for (i = 1; i < n; i += 1)
         type = TYPE_TARGET_TYPE (type);
-      result_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0));
+      result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
       /* FIXME: The stabs type r(0,0);bound;bound in an array type
          has a target type of TYPE_CODE_UNDEF.  We compensate here, but
          perhaps stabsread.c would make more sense.  */
@@ -2492,8 +2492,10 @@
 ada_array_bound_from_type (struct type * arr_type, int n, int which,
                            struct type ** typep)
 {
-  struct type *type;
-  struct type *index_type_desc;
+  struct type *type, *index_type_desc, *index_type;
+  LONGEST retval;
+
+  gdb_assert (which == 0 || which == 1);
 
   if (ada_is_packed_array_type (arr_type))
     arr_type = decode_packed_array_type (arr_type);
@@ -2511,10 +2513,11 @@
     type = arr_type;
 
   index_type_desc = ada_find_parallel_type (type, "___XA");
-  if (index_type_desc == NULL)
+  if (index_type_desc != NULL)
+    index_type = to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
+				      NULL, TYPE_OBJFILE (arr_type));
+  else
     {
-      struct type *index_type;
-
       while (n > 1)
         {
           type = TYPE_TARGET_TYPE (type);
@@ -2522,34 +2525,27 @@
         }
 
       index_type = TYPE_INDEX_TYPE (type);
-      if (typep != NULL)
-        *typep = index_type;
-
-      /* The index type is either a range type or an enumerated type.
-         For the range type, we have some macros that allow us to
-         extract the value of the low and high bounds.  But they
-         do now work for enumerated types.  The expressions used
-         below work for both range and enum types.  */
-      return
-        (LONGEST) (which == 0
-                   ? TYPE_FIELD_BITPOS (index_type, 0)
-                   : TYPE_FIELD_BITPOS (index_type,
-                                        TYPE_NFIELDS (index_type) - 1));
     }
-  else
+
+  switch (TYPE_CODE (index_type))
     {
-      struct type *index_type =
-        to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
-                             NULL, TYPE_OBJFILE (arr_type));
+    case TYPE_CODE_RANGE:
+      retval = which == 0 ? TYPE_LOW_BOUND (index_type)
+			  : TYPE_HIGH_BOUND (index_type);
+      break;
+    case TYPE_CODE_ENUM:
+      retval = which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
+			  : TYPE_FIELD_BITPOS (index_type,
+					       TYPE_NFIELDS (index_type) - 1);
+      break;
+    default:
+      internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
+    }
 
-      if (typep != NULL)
-        *typep = index_type;
+  if (typep != NULL)
+    *typep = index_type;
 
-      return
-        (LONGEST) (which == 0
-                   ? TYPE_LOW_BOUND (index_type)
-                   : TYPE_HIGH_BOUND (index_type));
-    }
+  return retval;
 }
 
 /* Given that arr is an array value, returns the lower bound of the
===================================================================
RCS file: /cvs/src/src/gdb/ada-typeprint.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- src/gdb/ada-typeprint.c	2008/09/11 14:22:32	1.22
+++ src/gdb/ada-typeprint.c	2008/12/28 14:14:18	1.23
@@ -170,8 +170,9 @@
       /* We extract the range type bounds respectively from the first element
          and the last element of the type->fields array */
       const LONGEST lower_bound = (LONGEST) TYPE_LOW_BOUND (type);
-      const LONGEST upper_bound =
-	(LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
+      const LONGEST upper_bound = (TYPE_CODE (type) == TYPE_CODE_RANGE
+	? (LONGEST) TYPE_HIGH_BOUND (type)
+	: (LONGEST) TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1));
 
       ada_print_scalar (target_type, lower_bound, stream);
       fprintf_filtered (stream, " .. ");
===================================================================
RCS file: /cvs/src/src/gdb/ada-valprint.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- src/gdb/ada-valprint.c	2008/10/28 17:19:56	1.44
+++ src/gdb/ada-valprint.c	2008/12/28 14:14:19	1.45
@@ -162,7 +162,7 @@
 
   {
     LONGEST high;
-    if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0)
+    if (get_discrete_bounds (index_type, &low, &high) < 0)
       len = 1;
     else
       len = high - low + 1;
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -r1.102 -r1.103
--- src/gdb/eval.c	2008/11/04 15:32:54	1.102
+++ src/gdb/eval.c	2008/12/28 14:14:19	1.103
@@ -824,7 +824,7 @@
       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
 	  && TYPE_CODE (type) == TYPE_CODE_ARRAY)
 	{
-	  struct type *range_type = TYPE_FIELD_TYPE (type, 0);
+	  struct type *range_type = TYPE_INDEX_TYPE (type);
 	  struct type *element_type = TYPE_TARGET_TYPE (type);
 	  struct value *array = allocate_value (expect_type);
 	  int element_size = TYPE_LENGTH (check_typedef (element_type));
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -r1.155 -r1.156
--- src/gdb/gdbtypes.c	2008/11/10 20:53:43	1.155
+++ src/gdb/gdbtypes.c	2008/12/28 14:14:19	1.156
@@ -711,16 +711,18 @@
   else
     TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
   TYPE_NFIELDS (result_type) = 2;
-  TYPE_FIELDS (result_type) = (struct field *)
-    TYPE_ALLOC (result_type, 2 * sizeof (struct field));
-  memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
-  TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
-  TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
+  TYPE_FIELDS (result_type) = TYPE_ALLOC (result_type,
+					  TYPE_NFIELDS (result_type)
+					  * sizeof (struct field));
+  memset (TYPE_FIELDS (result_type), 0,
+	  TYPE_NFIELDS (result_type) * sizeof (struct field));
+  TYPE_LOW_BOUND (result_type) = low_bound;
+  TYPE_HIGH_BOUND (result_type) = high_bound;
 
   if (low_bound >= 0)
     TYPE_UNSIGNED (result_type) = 1;
 
-  return (result_type);
+  return result_type;
 }
 
 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
@@ -831,7 +833,7 @@
   TYPE_FIELDS (result_type) =
     (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
   memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
-  TYPE_FIELD_TYPE (result_type, 0) = range_type;
+  TYPE_INDEX_TYPE (result_type) = range_type;
   TYPE_VPTR_FIELDNO (result_type) = -1;
 
   /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
@@ -1517,15 +1519,15 @@
 	}
       else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
 	       && TYPE_NFIELDS (type) == 1
-	       && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
+	       && (TYPE_CODE (range_type = TYPE_INDEX_TYPE (type))
 		   == TYPE_CODE_RANGE))
 	{
 	  /* Now recompute the length of the array type, based on its
 	     number of elements and the target type's length.
 	     Watch out for Ada null Ada arrays where the high bound
 	     is smaller than the low bound.  */
-	  const int low_bound = TYPE_FIELD_BITPOS (range_type, 0);
-	  const int high_bound = TYPE_FIELD_BITPOS (range_type, 1);
+	  const int low_bound = TYPE_LOW_BOUND (range_type);
+	  const int high_bound = TYPE_HIGH_BOUND (range_type);
 	  int nb_elements;
 	
 	  if (high_bound < low_bound)
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- src/gdb/gdbtypes.h	2008/10/28 17:19:56	1.95
+++ src/gdb/gdbtypes.h	2008/12/28 14:14:19	1.96
@@ -815,15 +815,15 @@
 /* Moto-specific stuff for FORTRAN arrays */
 
 #define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
-   (TYPE_FIELD_ARTIFICIAL((TYPE_FIELD_TYPE((arraytype),0)),1))
+   (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),1))
 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
-   (TYPE_FIELD_ARTIFICIAL((TYPE_FIELD_TYPE((arraytype),0)),0))
+   (TYPE_FIELD_ARTIFICIAL(TYPE_INDEX_TYPE((arraytype)),0))
 
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
-   (TYPE_FIELD_BITPOS((TYPE_FIELD_TYPE((arraytype),0)),1))
+   (TYPE_HIGH_BOUND(TYPE_INDEX_TYPE((arraytype))))
 
 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
-   (TYPE_FIELD_BITPOS((TYPE_FIELD_TYPE((arraytype),0)),0))
+   (TYPE_LOW_BOUND(TYPE_INDEX_TYPE((arraytype))))
 
 /* C++ */
 
===================================================================
RCS file: /cvs/src/src/gdb/hppa-tdep.c,v
retrieving revision 1.261
retrieving revision 1.262
diff -u -r1.261 -r1.262
--- src/gdb/hppa-tdep.c	2008/09/15 01:56:31	1.261
+++ src/gdb/hppa-tdep.c	2008/12/28 14:14:19	1.262
@@ -1313,7 +1313,7 @@
     case TYPE_CODE_FLT:
       return TYPE_LENGTH (type);
     case TYPE_CODE_ARRAY:
-      return hppa_alignof (TYPE_FIELD_TYPE (type, 0));
+      return hppa_alignof (TYPE_INDEX_TYPE (type));
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
       max_align = 1;
===================================================================
RCS file: /cvs/src/src/gdb/mdebugread.c,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- src/gdb/mdebugread.c	2008/10/08 12:49:12	1.96
+++ src/gdb/mdebugread.c	2008/12/28 14:14:19	1.97
@@ -1644,11 +1644,11 @@
 			  TYPE_ALLOC (tp, 2 * sizeof (struct field)));
       TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
 					    &current_objfile->objfile_obstack);
-      TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
+      TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
       ax++;
       TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
 					    &current_objfile->objfile_obstack);
-      TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
+      TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
       ax++;
     }
 
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- src/gdb/valarith.c	2008/09/11 14:25:49	1.67
+++ src/gdb/valarith.c	2008/12/28 14:14:19	1.68
@@ -1557,7 +1557,7 @@
   LONGEST low_bound, high_bound;
   LONGEST word;
   unsigned rel_index;
-  struct type *range = TYPE_FIELD_TYPE (type, 0);
+  struct type *range = TYPE_INDEX_TYPE (type);
   if (get_discrete_bounds (range, &low_bound, &high_bound) < 0)
     return -2;
   if (index < low_bound || index > high_bound)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-12-28 14:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-26 22:43 [patch] (for VLA) Prepare for 3-fields TYPE_CODE_RANGE (TYPE_HIGH_BOUND) Jan Kratochvil
2008-12-28 13:09 ` Joel Brobecker
2008-12-28 14:18   ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox