This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [rfc][19/37] Eliminate builtin_type_ macros: Ada range type handling


Joel Brobecker wrote:

> First, I need to correct myself - ranges are not just for integral
> types. You can have a range over any discrete type, which means
> things like this:
> 
>    type Digit is (Zero, One, Two, ...);
>    subtype Binary is Digit range (Zero .. One);
> 
> In this case, Binary would be defined as a subrange of the enumeration
> type. However, after thinking about it awhile, I don't think that
> enumeration types are that different from integral types in terms
> of comparison and range check.

Yes, value_less etc. should be able to handle enumeration (and range)
types fine.

> That being said:
> 
> > Well, the only effect going through GDB values to perform the
> > comparison has is to do the appropriate type promotions.  However, if
> > this doesn't actually apply for Ada, I'm wondering why we don't simply
> > do the comparison on integral LONGEST values directly, like in the
> > patch below?
> 
> The only problem that I see is when the base type of the range type
> is unsigned.  value_less is supposed to be able to handle such cases,
> whereas converting the bounds to a LONGEST might cause some problems,
> no?

I see.  We'd need to compare either LONGEST or ULONGEST to take care
of signed vs. unsigned types.  value_less already does this ...

So I guess your original proposal to use the range type itself is
the simplest solution.  Implemented by the patch below.

Bye,
Ulrich

ChangeLog:

	* ada-lang.c (ada_array_length): Use builtin_type_int32 instead
	of builtin_type_int.
	(ada_evaluate_subexp) [UNOP_IN_RANGE]: Use operand range type
	instead of builtin_type_int.


Index: gdb-head/gdb/ada-lang.c
===================================================================
--- gdb-head.orig/gdb/ada-lang.c
+++ gdb-head/gdb/ada-lang.c
@@ -2623,7 +2623,7 @@ ada_array_length (struct value *arr, int
     }
   else
     return
-      value_from_longest (builtin_type_int,
+      value_from_longest (builtin_type_int32,
                           value_as_long (desc_one_bound (desc_bounds (arr),
                                                          n, 1))
                           - value_as_long (desc_one_bound (desc_bounds (arr),
@@ -8860,9 +8860,8 @@ ada_evaluate_subexp (struct type *expect
           return value_from_longest (type, (LONGEST) 1);
 
         case TYPE_CODE_RANGE:
-          arg2 = value_from_longest (builtin_type_int, TYPE_LOW_BOUND (type));
-          arg3 = value_from_longest (builtin_type_int,
-                                     TYPE_HIGH_BOUND (type));
+	  arg2 = value_from_longest (type, TYPE_LOW_BOUND (type));
+	  arg3 = value_from_longest (type, TYPE_HIGH_BOUND (type));
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
           type = language_bool_type (exp->language_defn, exp->gdbarch);

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]