vla: introduce new bound type abstraction adapt uses

The rational behind this patch is to get started to implement the feature
described in dwarf4 standard (2.19) Static and Dynamic Values of Attributes.
It adds new BOUND_PROP to store either a constant, exprloc, or reference to
describe an upper-/lower bound of a subrange. Other than that no new features
are introduced.

	* dwarf2read.c (read_subrange_type): Use struct bound_prop for
	declaring high/low bounds and change uses accordingly. Call
	create_range_type instead of create_static_range_type.
	* gdbtypes.c (create_range_type): New function.
	(create_range_type): Convert bounds into struct bound_prop and pass
	them to create_range_type.
	* gdbtypes.h (struct bound_prop): New struct.
	(create_range_type): New function prototype.
	(struct range_bounds): Use struct bound_prop instead of LONGEST for
	high/low bounds. Remove low_undefined/high_undefined and adapt all uses.
	(TYPE_LOW_BOUND,TYPE_HIGH_BOUND): Adapt macros to refer to the static
	part of the bound.
	* parse.c (follow_types): Set high bound kind to BOUND_UNDEFINED.
This commit is contained in:
Sanimir Agovic 2013-10-08 15:04:49 +01:00
parent 0c9c347402
commit 729efb1317
5 changed files with 123 additions and 47 deletions

View file

@ -798,6 +798,34 @@ allocate_stub_method (struct type *type)
return mtype;
}
/* Create a range type with a dynamic range from LOW_BOUND to
HIGH_BOUND, inclusive. See create_range_type for further details. */
struct type *
create_range_type (struct type *result_type, struct type *index_type,
const struct dynamic_prop *low_bound,
const struct dynamic_prop *high_bound)
{
if (result_type == NULL)
result_type = alloc_type_copy (index_type);
TYPE_CODE (result_type) = TYPE_CODE_RANGE;
TYPE_TARGET_TYPE (result_type) = index_type;
if (TYPE_STUB (index_type))
TYPE_TARGET_STUB (result_type) = 1;
else
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
TYPE_RANGE_DATA (result_type)->low = *low_bound;
TYPE_RANGE_DATA (result_type)->high = *high_bound;
if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
TYPE_UNSIGNED (result_type) = 1;
return result_type;
}
/* Create a range type using either a blank type supplied in
RESULT_TYPE, or creating a new type, inheriting the objfile from
INDEX_TYPE.
@ -812,21 +840,15 @@ struct type *
create_static_range_type (struct type *result_type, struct type *index_type,
LONGEST low_bound, LONGEST high_bound)
{
if (result_type == NULL)
result_type = alloc_type_copy (index_type);
TYPE_CODE (result_type) = TYPE_CODE_RANGE;
TYPE_TARGET_TYPE (result_type) = index_type;
if (TYPE_STUB (index_type))
TYPE_TARGET_STUB (result_type) = 1;
else
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
TYPE_LOW_BOUND (result_type) = low_bound;
TYPE_HIGH_BOUND (result_type) = high_bound;
struct dynamic_prop low, high;
if (low_bound >= 0)
TYPE_UNSIGNED (result_type) = 1;
low.kind = PROP_CONST;
low.data.const_val = low_bound;
high.kind = PROP_CONST;
high.data.const_val = high_bound;
result_type = create_range_type (result_type, index_type, &low, &high);
return result_type;
}