aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbtypes.c
diff options
context:
space:
mode:
authorPer Bothner <per@bothner.com>1995-10-05 01:09:53 +0000
committerPer Bothner <per@bothner.com>1995-10-05 01:09:53 +0000
commit706bfe5a1c25b80f2af9c48477035cfe73987ae4 (patch)
treece4a369a9f5beaa3c7a7909bd4708aec8a3b2340 /gdb/gdbtypes.c
parentc780e5dbafac580ef35286c4325ecf59015f12b1 (diff)
downloadgdb-706bfe5a1c25b80f2af9c48477035cfe73987ae4.zip
gdb-706bfe5a1c25b80f2af9c48477035cfe73987ae4.tar.gz
gdb-706bfe5a1c25b80f2af9c48477035cfe73987ae4.tar.bz2
* 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. This fixes PR chill/8136.
Diffstat (limited to 'gdb/gdbtypes.c')
-rw-r--r--gdb/gdbtypes.c63
1 files changed, 46 insertions, 17 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index ca27e4c..2a17764 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -336,6 +336,48 @@ create_range_type (result_type, index_type, low_bound, high_bound)
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. */
@@ -350,26 +392,13 @@ force_to_range_type (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;