+Wed Oct 4 17:23:03 1995 Per Bothner <bothner@kalessin.cygnus.com>
+
+ * gdbtypes.c (get_discrete_bounds): New function.
+ (force_to_range_type): Use get_discrete_bounds.
+ * gdbtypes.h (get_discrete_bounds): Add declaration.
+ * valarith.c (value_bit_index): Generalize to use get_discrete_bounds.
+ * ch-valprint.c (chill_val_print): Make (power)sets and bitstring
+ support use get_discrete_bounds and generally be more robust.
+
Tue Oct 3 16:54:56 1995 Stan Shebs <shebs@andros.cygnus.com>
* remote-nrom.c (nrom_ops): Add value for to_thread_alive,
}
{
struct type *range = elttype;
- int low_bound = TYPE_LOW_BOUND (range);
- int high_bound = TYPE_HIGH_BOUND (range);
+ LONGEST low_bound, high_bound;
int i;
int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
int need_comma = 0;
fputs_filtered ("B'", stream);
else
fputs_filtered ("[", stream);
+
+ i = get_discrete_bounds (range, &low_bound, &high_bound);
+ maybe_bad_bstring:
+ if (i < 0)
+ {
+ fputs_filtered ("<error value>", stream);
+ goto done;
+ }
+
for (i = low_bound; i <= high_bound; i++)
{
int element = value_bit_index (type, valaddr, i);
+ if (element < 0)
+ {
+ i = element;
+ goto maybe_bad_bstring;
+ }
if (is_bitstring)
fprintf_filtered (stream, "%d", element);
else if (element)
}
}
}
+ done:
if (is_bitstring)
fputs_filtered ("'", stream);
else
return (result_type);
}
+/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
+ Return 1 of type is a range type, 0 if it is discrete (and bounds
+ will fit in LONGEST), or -1 otherwise. */
+
+int
+get_discrete_bounds (type, lowp, highp)
+ struct type *type;
+ LONGEST *lowp, *highp;
+{
+ switch (TYPE_CODE (type))
+ {
+ TYPE_CODE_RANGE:
+ *lowp = TYPE_LOW_BOUND (type);
+ *highp = TYPE_HIGH_BOUND (type);
+ return 1;
+ case TYPE_CODE_ENUM:
+ *lowp = TYPE_FIELD_BITPOS (type, 0);
+ *highp = TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
+ return 0;
+ case TYPE_CODE_BOOL:
+ *lowp = 0;
+ *highp = 1;
+ return 0;
+ case TYPE_CODE_INT:
+ if (TYPE_LENGTH (type) >= sizeof (LONGEST)) /* Too big */
+ return -1;
+ if (!TYPE_UNSIGNED (type))
+ {
+ *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
+ *highp = -*lowp - 1;
+ return 0;
+ }
+ /* ... fall through for unsigned ints ... */
+ case TYPE_CODE_CHAR:
+ *lowp = 0;
+ *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT) - 1;
+ return 0;
+ default:
+ return -1;
+ }
+}
+
/* A lot of code assumes that the "index type" of an array/string/
set/bitstring is specifically a range type, though in some languages
it can be any discrete type. */
return type;
case TYPE_CODE_ENUM:
- {
- int low_bound = TYPE_FIELD_BITPOS (type, 0);
- int high_bound = TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
- struct type *range_type =
- create_range_type (NULL, type, low_bound, high_bound);
- TYPE_NAME (range_type) = TYPE_NAME (range_type);
- TYPE_DUMMY_RANGE (range_type) = 1;
- return range_type;
- }
case TYPE_CODE_BOOL:
- {
- struct type *range_type = create_range_type (NULL, type, 0, 1);
- TYPE_NAME (range_type) = TYPE_NAME (range_type);
- TYPE_DUMMY_RANGE (range_type) = 1;
- return range_type;
- }
case TYPE_CODE_CHAR:
{
- int char_max = 1 << (TYPE_LENGTH (type) * HOST_CHAR_BIT) - 1;
- struct type *range_type = create_range_type (NULL, type, 0, char_max);
+ LONGEST low_bound, high_bound;
+ struct type *range_type;
+ get_discrete_bounds (type, &low_bound, &high_bound);
+ range_type = create_range_type (NULL, type, low_bound, high_bound);
TYPE_NAME (range_type) = TYPE_NAME (range_type);
TYPE_DUMMY_RANGE (range_type) = 1;
return range_type;