This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [rfc][19/37] Eliminate builtin_type_ macros: Ada range type handling
> > > two more small changes to ada-lang.c: ada_array_length would
> > > simply use builtin_type_int as type of its return value, even
> > > though it should probably better use the type of the array bounds.
> >
> > I don't think this part is correct, since the bounds can be any discrete
> > type, which includes enumeration types. The 'Length attribute is defined
> > as returning a universal_integer. The definition of universal_integer
> > is a little complicated for me, but it is an integer.
>
> I see; it seems I have misinterpreted range types -- I though they
> were always based on an integer type.
A range type is, I think, always based on an integer type. But the
thing is that array index types can be any discrete type: This means
that one can use an enumerated type as well.
So, for ada_array_length, shall use use a type of builtin_type_int32?
That's what I did for my testing (more on this in a separate message)
> > > 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_TARGET_TYPE (type),
> > > + TYPE_LOW_BOUND (type));
> > > + arg3 = value_from_longest (TYPE_TARGET_TYPE (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);
> >
> > I don't really understand why the TYPE_TARGET_TYPE is necessarily
> > an integer type. I don't even think that the TYPE_TARGET_TYPE
> > is necessarily set, particularly in the case of enumerated types
> > or base types.
> >
> > We have access to the int type through the expression in this case.
> > Can we use that?
>
> I guess so, but it would appear this doesn't really help. There isn't
> really anything in the language that says the gdbarch's int type is the
> "correct" type to use here, or is there?
No, I don't think so. I had a look at the Ada Reference Manual,
and it doesn't say anything about that.
> If not, and this is just about using some "random" integer type to perform
> the comparison in, it seems to me using builtin_type_int32 here as well
> would be better ...
It just occured to me that, since this is a TYPE_CODE_RANGE, can't
we just use its type? A TYPE_CODE_RANGE should always be some kind
of "integer" type, so why not use that when calling value_from_longest?
I have this awful feeling that we're missing something, but I don't
see what. Do you see anything wrong with that?
--
Joel