+2020-12-09 Simon Marchi <simon.marchi@efficios.com>
+
+ * gdbtypes.h (get_discrete_bounds): Return bool, adjust all
+ callers.
+ * gdbtypes.c (get_discrete_bounds): Return bool.
+
2020-12-09 Simon Marchi <simon.marchi@efficios.com>
* ada-lang.c (ada_value_slice_from_ptr): Adjust.
if ((check_typedef (index_type)->code () == TYPE_CODE_RANGE
&& is_dynamic_type (check_typedef (index_type)))
- || get_discrete_bounds (index_type, &low_bound, &high_bound) < 0)
+ || !get_discrete_bounds (index_type, &low_bound, &high_bound))
low_bound = high_bound = 0;
if (high_bound < low_bound)
*elt_bits = TYPE_LENGTH (new_type) = 0;
gdb_assert (type->code () == TYPE_CODE_ARRAY);
LONGEST low, high;
- if (get_discrete_bounds (type->index_type (), &low, &high) < 0
+ if (!get_discrete_bounds (type->index_type (), &low, &high)
|| low > high)
return 0;
LONGEST our_len = high - low + 1;
LONGEST lowerbound, upperbound;
LONGEST idx;
- if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
+ if (!get_discrete_bounds (range_type, &lowerbound, &upperbound))
{
lim_warning (_("don't know bounds of array"));
lowerbound = upperbound = 0;
{
LONGEST high;
- if (get_discrete_bounds (index_type, &low, &high) < 0)
+ if (!get_discrete_bounds (index_type, &low, &high))
len = 1;
else if (low > high)
{
LONGEST low_bound, high_bound;
int element_size = TYPE_LENGTH (type);
- if (get_discrete_bounds (expect_type->index_type (),
- &low_bound, &high_bound) < 0)
+ if (!get_discrete_bounds (expect_type->index_type (),
+ &low_bound, &high_bound))
{
low_bound = 0;
high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
int element_size = TYPE_LENGTH (check_typedef (element_type));
LONGEST low_bound, high_bound, index;
- if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
+ if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
{
low_bound = 0;
high_bound = (TYPE_LENGTH (type) / element_size) - 1;
|| check_type->code () == TYPE_CODE_TYPEDEF)
check_type = TYPE_TARGET_TYPE (check_type);
- if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
+ if (!get_discrete_bounds (element_type, &low_bound, &high_bound))
error (_("(power)set type with unknown size"));
memset (valaddr, '\0', TYPE_LENGTH (type));
for (tem = 0; tem < nargs; tem++)
/* Get the range, and extract the bounds. */
struct type *range_type = type->index_type ();
- if (get_discrete_bounds (range_type, &m_lowerbound, &m_upperbound) < 0)
+ if (!get_discrete_bounds (range_type, &m_lowerbound, &m_upperbound))
error ("unable to read array bounds");
/* Figure out the stride for this array. */
/* Extract the range, and get lower and upper bounds. */
struct type *range_type = check_typedef (type)->index_type ();
LONGEST lowerbound, upperbound;
- if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
+ if (!get_discrete_bounds (range_type, &lowerbound, &upperbound))
error ("failed to get range bounds");
/* CALC is used to calculate the offsets for each element in this
tmp_type = check_typedef (tmp_type);
struct type *range_type = tmp_type->index_type ();
LONGEST lowerbound, upperbound, stride;
- if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
+ if (!get_discrete_bounds (range_type, &lowerbound, &upperbound))
error ("failed to get range bounds");
/* Figure out the stride for this dimension. */
&& bounds->stride.kind () == PROP_CONST);
}
+/* See gdbtypes.h. */
-/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
- TYPE.
-
- Return 1 if type is a range type with two defined, constant bounds.
- Else, return 0 if it is discrete (and bounds will fit in LONGEST).
- Else, return -1. */
-
-int
+bool
get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
{
type = check_typedef (type);
constant bounds. */
if (type->bounds ()->low.kind () != PROP_CONST
|| type->bounds ()->high.kind () != PROP_CONST)
- return -1;
+ return false;
*lowp = type->bounds ()->low.const_val ();
*highp = type->bounds ()->high.const_val ();
gdb::optional<LONGEST> low_pos
= discrete_position (TYPE_TARGET_TYPE (type), *lowp);
- if (!low_pos.has_value ())
- return 0;
-
- *lowp = *low_pos;
+ if (low_pos.has_value ())
+ *lowp = *low_pos;
gdb::optional<LONGEST> high_pos
= discrete_position (TYPE_TARGET_TYPE (type), *highp);
- if (!high_pos.has_value ())
- return 0;
-
- *highp = *high_pos;
+ if (high_pos.has_value ())
+ *highp = *high_pos;
}
- return 1;
+ return true;
+
case TYPE_CODE_ENUM:
if (type->num_fields () > 0)
{
*lowp = 0;
*highp = -1;
}
- return 0;
+ return true;
+
case TYPE_CODE_BOOL:
*lowp = 0;
*highp = 1;
- return 0;
+ return true;
+
case TYPE_CODE_INT:
if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
- return -1;
+ return false;
+
if (!type->is_unsigned ())
{
*lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
*highp = -*lowp - 1;
- return 0;
+ return true;
}
/* fall through */
case TYPE_CODE_CHAR:
if TYPE_LENGTH (type) == sizeof (LONGEST). */
*highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
*highp = (*highp - 1) | *highp;
- return 0;
+ return true;
+
default:
- return -1;
+ return false;
}
}
struct type *index = type->index_type ();
LONGEST low = 0;
LONGEST high = 0;
- int res;
if (index == NULL)
return false;
- res = get_discrete_bounds (index, &low, &high);
- if (res == -1)
+ if (!get_discrete_bounds (index, &low, &high))
return false;
if (low_bound)
if (stride == 0)
stride = range_type->bit_stride ();
- if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
+ if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
low_bound = high_bound = 0;
+
element_type = check_typedef (TYPE_TARGET_TYPE (type));
/* Be careful when setting the array length. Ada arrays can be
empty arrays with the high_bound being smaller than the low_bound.
{
LONGEST low_bound, high_bound, bit_length;
- if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
+ if (!get_discrete_bounds (domain_type, &low_bound, &high_bound))
low_bound = high_bound = 0;
+
bit_length = high_bound - low_bound + 1;
TYPE_LENGTH (result_type)
= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
extern int get_vptr_fieldno (struct type *, struct type **);
-extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
+/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
+ TYPE.
+
+ Return true if the two bounds are available, false otherwise. */
+
+extern bool get_discrete_bounds (struct type *type, LONGEST *lowp,
+ LONGEST *highp);
/* Assuming TYPE is a simple, non-empty array type, compute its upper
and lower bound. Save the low bound into LOW_BOUND if not NULL.
This should be integrated into gdbtypes.c
inside get_discrete_bounds. */
-static int
+static bool
m2_get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
{
type = check_typedef (type);
l1 = type->field (i).type ()->bounds ()->low.const_val ();
h1 = type->field (len - 1).type ()->bounds ()->high.const_val ();
*of_type = target;
- if (m2_get_discrete_bounds (target, &l2, &h2) >= 0)
+ if (m2_get_discrete_bounds (target, &l2, &h2))
return (l1 == l2 && h1 == h2);
error (_("long_set failed to find discrete bounds for its subtype"));
return 0;
target = TYPE_TARGET_TYPE (range);
- if (get_discrete_bounds (range, &field_low, &field_high) >= 0)
+ if (get_discrete_bounds (range, &field_low, &field_high))
{
for (i = low_bound; i <= high_bound; i++)
{
if (field == len)
break;
range = type->field (field).type ()->index_type ();
- if (get_discrete_bounds (range, &field_low, &field_high) < 0)
+ if (!get_discrete_bounds (range, &field_low, &field_high))
break;
target = TYPE_TARGET_TYPE (range);
}
fputs_filtered ("{", stream);
- i = get_discrete_bounds (range, &low_bound, &high_bound);
+ i = get_discrete_bounds (range, &low_bound, &high_bound) ? 0 : -1;
maybe_bad_bstring:
if (i < 0)
{
fputs_filtered ("[", stream);
- int bound_info = get_discrete_bounds (range, &low_bound, &high_bound);
+ int bound_info = (get_discrete_bounds (range, &low_bound, &high_bound)
+ ? 0 : -1);
if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
{
/* If we know the size of the set type, we can figure out the
unsigned rel_index;
struct type *range = type->index_type ();
- if (get_discrete_bounds (range, &low_bound, &high_bound) < 0)
+ if (!get_discrete_bounds (range, &low_bound, &high_bound))
return -2;
if (index < low_bound || index > high_bound)
return -1;
int val_length = TYPE_LENGTH (type2);
LONGEST low_bound, high_bound, new_length;
- if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
+ if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
low_bound = 0, high_bound = 0;
new_length = val_length / element_length;
if (val_length % element_length != 0)
error (_("array not associated"));
range_type = array_type->index_type ();
- if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
+ if (!get_discrete_bounds (range_type, &lowerbound, &upperbound))
error (_("slice from bad array or bitstring"));
if (lowbound < lowerbound || length < 0