aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2020-12-09 13:51:45 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2020-12-09 13:51:45 -0500
commit6244c1196a49a5732ac3667b4df0f157cf681d7b (patch)
tree77a97a40d9cc1477eefef80e6b100f21ec2f239d /gdb/ada-lang.c
parent037311d1df303c91395cdfe07b6ab414de99e420 (diff)
downloadfsf-binutils-gdb-6244c1196a49a5732ac3667b4df0f157cf681d7b.zip
fsf-binutils-gdb-6244c1196a49a5732ac3667b4df0f157cf681d7b.tar.gz
fsf-binutils-gdb-6244c1196a49a5732ac3667b4df0f157cf681d7b.tar.bz2
gdb: make discrete_position return optional
Instead of returning a boolean status and returning the value through a pointer, return an optional that does both jobs. This helps in the following patches, and I think it is an improvement in general. gdb/ChangeLog: * ada-lang.c (ada_value_slice_from_ptr): Adjust. (ada_value_slice): Adjust. (pos_atr): Adjust. * gdbtypes.c (get_discrete_bounds): Adjust. (discrete_position): Return optional. * gdbtypes.h (discrete_position): Return optional. Change-Id: I758dbd8858b296ee472ed39ec35db1dbd624a5ae
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 8a1d9df..5813ecd 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2815,11 +2815,13 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
type0->dyn_prop (DYN_PROP_BYTE_STRIDE),
TYPE_FIELD_BITSIZE (type0, 0));
int base_low = ada_discrete_type_low_bound (type0->index_type ());
- LONGEST base_low_pos, low_pos;
+ gdb::optional<LONGEST> base_low_pos, low_pos;
CORE_ADDR base;
- if (!discrete_position (base_index_type, low, &low_pos)
- || !discrete_position (base_index_type, base_low, &base_low_pos))
+ low_pos = discrete_position (base_index_type, low);
+ base_low_pos = discrete_position (base_index_type, base_low);
+
+ if (!low_pos.has_value () || !base_low_pos.has_value ())
{
warning (_("unable to get positions in slice, use bounds instead"));
low_pos = low;
@@ -2830,7 +2832,7 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
if (stride == 0)
stride = TYPE_LENGTH (TYPE_TARGET_TYPE (type0));
- base = value_as_address (array_ptr) + (low_pos - base_low_pos) * stride;
+ base = value_as_address (array_ptr) + (*low_pos - *base_low_pos) * stride;
return value_at_lazy (slice_type, base);
}
@@ -2846,10 +2848,13 @@ ada_value_slice (struct value *array, int low, int high)
(NULL, TYPE_TARGET_TYPE (type), index_type,
type->dyn_prop (DYN_PROP_BYTE_STRIDE),
TYPE_FIELD_BITSIZE (type, 0));
- LONGEST low_pos, high_pos;
+ gdb::optional<LONGEST> low_pos, high_pos;
+
- if (!discrete_position (base_index_type, low, &low_pos)
- || !discrete_position (base_index_type, high, &high_pos))
+ low_pos = discrete_position (base_index_type, low);
+ high_pos = discrete_position (base_index_type, high);
+
+ if (!low_pos.has_value () || !high_pos.has_value ())
{
warning (_("unable to get positions in slice, use bounds instead"));
low_pos = low;
@@ -2857,7 +2862,7 @@ ada_value_slice (struct value *array, int low, int high)
}
return value_cast (slice_type,
- value_slice (array, low, high_pos - low_pos + 1));
+ value_slice (array, low, *high_pos - *low_pos + 1));
}
/* If type is a record type in the form of a standard GNAT array
@@ -8926,15 +8931,15 @@ pos_atr (struct value *arg)
{
struct value *val = coerce_ref (arg);
struct type *type = value_type (val);
- LONGEST result;
if (!discrete_type_p (type))
error (_("'POS only defined on discrete types"));
- if (!discrete_position (type, value_as_long (val), &result))
+ gdb::optional<LONGEST> result = discrete_position (type, value_as_long (val));
+ if (!result.has_value ())
error (_("enumeration value is invalid: can't find 'POS"));
- return result;
+ return *result;
}
static struct value *