diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2020-07-12 23:05:08 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2020-07-12 23:06:12 -0400 |
commit | cf88be6855e5bb3d43e1fd78f28aeb2ec5fc11a1 (patch) | |
tree | 7934180bead39035aa5c7f5c00fbbfb2d4d79277 /gdb/f-valprint.c | |
parent | 509971ae766fdba08437cbd8bc266aae8d2aa9e9 (diff) | |
download | binutils-gdb-cf88be6855e5bb3d43e1fd78f28aeb2ec5fc11a1.tar.gz |
gdb: make type::bounds work for array and string types
Getting the bounds of an array (or string) type is a common operation,
and is currently done through its index type:
my_array_type->index_type ()->bounds ()
I think it would make sense to let the `type::bounds` methods work for
arrays and strings, as a shorthand for this. It's natural that when
asking for the bounds of an array, we get the bounds of the range type
used as its index type. In a way, it's equivalent as the now-removed
TYPE_ARRAY_{LOWER,UPPER}_BOUND_IS_UNDEFINED and
TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE, except it returns the
`range_bounds` object. The caller is then responsible for getting the
property it needs in it.
I updated all the spots I could find that could take advantage of this.
Note that this also makes `type::bit_stride` work on array types, since
`type::bit_stride` uses `type::bounds`. `my_array_type->bit_stride ()`
now returns the bit stride of the array's index type. So some spots
are also changed to take advantage of this.
gdb/ChangeLog:
* gdbtypes.h (struct type) <bounds>: Handle array and string
types.
* ada-lang.c (assign_aggregate): Use type::bounds on
array/string type.
* c-typeprint.c (c_type_print_varspec_suffix): Likewise.
* c-varobj.c (c_number_of_children): Likewise.
(c_describe_child): Likewise.
* eval.c (evaluate_subexp_for_sizeof): Likewise.
* f-typeprint.c (f_type_print_varspec_suffix): Likewise.
(f_type_print_base): Likewise.
* f-valprint.c (f77_array_offset_tbl): Likewise.
(f77_get_upperbound): Likewise.
(f77_print_array_1): Likewise.
* guile/scm-type.c (gdbscm_type_range): Likewise.
* m2-typeprint.c (m2_array): Likewise.
(m2_is_long_set_of_type): Likewise.
* m2-valprint.c (get_long_set_bounds): Likewise.
* p-typeprint.c (pascal_type_print_varspec_prefix): Likewise.
* python/py-type.c (typy_range): Likewise.
* rust-lang.c (rust_internal_print_type): Likewise.
* type-stack.c (type_stack::follow_types): Likewise.
* valarith.c (value_subscripted_rvalue): Likewise.
* valops.c (value_cast): Likewise.
Change-Id: I5c0c08930bffe42fd69cb4bfcece28944dd88d1f
Diffstat (limited to 'gdb/f-valprint.c')
-rw-r--r-- | gdb/f-valprint.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 17e15f9bdff..fabdf458616 100644 --- a/gdb/f-valprint.c +++ b/gdb/f-valprint.c @@ -46,16 +46,16 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2]; LONGEST f77_get_lowerbound (struct type *type) { - if (type->index_type ()->bounds ()->low.kind () == PROP_UNDEFINED) + if (type->bounds ()->low.kind () == PROP_UNDEFINED) error (_("Lower bound may not be '*' in F77")); - return type->index_type ()->bounds ()->low.const_val (); + return type->bounds ()->low.const_val (); } LONGEST f77_get_upperbound (struct type *type) { - if (type->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED) + if (type->bounds ()->high.kind () == PROP_UNDEFINED) { /* We have an assumed size array on our hands. Assume that upper_bound == lower_bound so that we show at least 1 element. @@ -65,7 +65,7 @@ f77_get_upperbound (struct type *type) return f77_get_lowerbound (type); } - return type->index_type ()->bounds ()->high.const_val (); + return type->bounds ()->high.const_val (); } /* Obtain F77 adjustable array dimensions. */ @@ -124,8 +124,7 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type, struct gdbarch *gdbarch = get_type_arch (type); size_t dim_size = type_length_units (TYPE_TARGET_TYPE (type)); int unit_size = gdbarch_addressable_memory_unit_size (gdbarch); - size_t byte_stride - = type->index_type ()->bounds ()->bit_stride () / (unit_size * 8); + size_t byte_stride = type->bit_stride () / (unit_size * 8); if (byte_stride == 0) byte_stride = dim_size; size_t offs = 0; |