forked from Imagelibrary/binutils-gdb
gdb: add accessors to struct dynamic_prop
Add setters, to ensure that the kind and value of the property are always kept in sync (a caller can't forget one or the other). Add getters, such that we can assert that when a caller accesses a data bit of the property, the property is indeed of the corresponding kind. Note that because of the way `struct dynamic_prop` is allocated currently, we can't make the `m_kind` and `m_data` fields private. That would make the type non-default-constructible, and we would have to call the constructor when allocating them. However, I still prefixed them with `m_` to indicate that they should not be accessed from outside the class (and also to be able to use the name `kind` for the method). gdb/ChangeLog: * gdbtypes.h (struct dynamic_prop) <kind, set_undefined, const_val, set_const_val, baton, set_locexpr, set_loclist, set_addr_offset, variant_parts, set_variant_parts, original_type, set_original_type>: New methods. <kind>: Rename to... <m_kind>: ... this. Update all users to use the new methods instead. <data>: Rename to... <m_data>: ... this. Update all users to use the new methods instead. Change-Id: Ib72a8eb440dfeb1a5421d0933334230d7f2478f9
This commit is contained in:
@@ -511,11 +511,87 @@ union dynamic_prop_data
|
||||
|
||||
struct dynamic_prop
|
||||
{
|
||||
dynamic_prop_kind kind () const
|
||||
{
|
||||
return m_kind;
|
||||
}
|
||||
|
||||
void set_undefined ()
|
||||
{
|
||||
m_kind = PROP_UNDEFINED;
|
||||
}
|
||||
|
||||
LONGEST const_val () const
|
||||
{
|
||||
gdb_assert (m_kind == PROP_CONST);
|
||||
|
||||
return m_data.const_val;
|
||||
}
|
||||
|
||||
void set_const_val (LONGEST const_val)
|
||||
{
|
||||
m_kind = PROP_CONST;
|
||||
m_data.const_val = const_val;
|
||||
}
|
||||
|
||||
void *baton () const
|
||||
{
|
||||
gdb_assert (m_kind == PROP_LOCEXPR
|
||||
|| m_kind == PROP_LOCLIST
|
||||
|| m_kind == PROP_ADDR_OFFSET);
|
||||
|
||||
return m_data.baton;
|
||||
}
|
||||
|
||||
void set_locexpr (void *baton)
|
||||
{
|
||||
m_kind = PROP_LOCEXPR;
|
||||
m_data.baton = baton;
|
||||
}
|
||||
|
||||
void set_loclist (void *baton)
|
||||
{
|
||||
m_kind = PROP_LOCLIST;
|
||||
m_data.baton = baton;
|
||||
}
|
||||
|
||||
void set_addr_offset (void *baton)
|
||||
{
|
||||
m_kind = PROP_ADDR_OFFSET;
|
||||
m_data.baton = baton;
|
||||
}
|
||||
|
||||
const gdb::array_view<variant_part> *variant_parts () const
|
||||
{
|
||||
gdb_assert (m_kind == PROP_VARIANT_PARTS);
|
||||
|
||||
return m_data.variant_parts;
|
||||
}
|
||||
|
||||
void set_variant_parts (gdb::array_view<variant_part> *variant_parts)
|
||||
{
|
||||
m_kind = PROP_VARIANT_PARTS;
|
||||
m_data.variant_parts = variant_parts;
|
||||
}
|
||||
|
||||
struct type *original_type () const
|
||||
{
|
||||
gdb_assert (m_kind == PROP_TYPE);
|
||||
|
||||
return m_data.original_type;
|
||||
}
|
||||
|
||||
void set_original_type (struct type *original_type)
|
||||
{
|
||||
m_kind = PROP_TYPE;
|
||||
m_data.original_type = original_type;
|
||||
}
|
||||
|
||||
/* Determine which field of the union dynamic_prop.data is used. */
|
||||
enum dynamic_prop_kind kind;
|
||||
enum dynamic_prop_kind m_kind;
|
||||
|
||||
/* Storage for dynamic or static value. */
|
||||
union dynamic_prop_data data;
|
||||
union dynamic_prop_data m_data;
|
||||
};
|
||||
|
||||
/* Compare two dynamic_prop objects for equality. dynamic_prop
|
||||
@@ -1519,19 +1595,19 @@ extern unsigned type_align (struct type *);
|
||||
extern bool set_type_align (struct type *, ULONGEST);
|
||||
|
||||
#define TYPE_LOW_BOUND(range_type) \
|
||||
((range_type)->bounds ()->low.data.const_val)
|
||||
((range_type)->bounds ()->low.const_val ())
|
||||
#define TYPE_HIGH_BOUND(range_type) \
|
||||
((range_type)->bounds ()->high.data.const_val)
|
||||
((range_type)->bounds ()->high.const_val ())
|
||||
#define TYPE_LOW_BOUND_UNDEFINED(range_type) \
|
||||
(TYPE_LOW_BOUND_KIND(range_type) == PROP_UNDEFINED)
|
||||
#define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
|
||||
(TYPE_HIGH_BOUND_KIND(range_type) == PROP_UNDEFINED)
|
||||
#define TYPE_HIGH_BOUND_KIND(range_type) \
|
||||
((range_type)->bounds ()->high.kind)
|
||||
((range_type)->bounds ()->high.kind ())
|
||||
#define TYPE_LOW_BOUND_KIND(range_type) \
|
||||
((range_type)->bounds ()->low.kind)
|
||||
((range_type)->bounds ()->low.kind ())
|
||||
#define TYPE_BIT_STRIDE(range_type) \
|
||||
((range_type)->bounds ()->stride.data.const_val \
|
||||
((range_type)->bounds ()->stride.const_val () \
|
||||
* ((range_type)->bounds ()->flag_is_byte_stride ? 8 : 1))
|
||||
|
||||
/* Property accessors for the type data location. */
|
||||
@@ -1540,9 +1616,9 @@ extern bool set_type_align (struct type *, ULONGEST);
|
||||
#define TYPE_DATA_LOCATION_BATON(thistype) \
|
||||
TYPE_DATA_LOCATION (thistype)->data.baton
|
||||
#define TYPE_DATA_LOCATION_ADDR(thistype) \
|
||||
TYPE_DATA_LOCATION (thistype)->data.const_val
|
||||
(TYPE_DATA_LOCATION (thistype)->const_val ())
|
||||
#define TYPE_DATA_LOCATION_KIND(thistype) \
|
||||
TYPE_DATA_LOCATION (thistype)->kind
|
||||
(TYPE_DATA_LOCATION (thistype)->kind ())
|
||||
#define TYPE_DYNAMIC_LENGTH(thistype) \
|
||||
((thistype)->dyn_prop (DYN_PROP_BYTE_SIZE))
|
||||
|
||||
@@ -1556,9 +1632,9 @@ extern bool set_type_align (struct type *, ULONGEST);
|
||||
#define TYPE_DYN_PROP_BATON(dynprop) \
|
||||
dynprop->data.baton
|
||||
#define TYPE_DYN_PROP_ADDR(dynprop) \
|
||||
dynprop->data.const_val
|
||||
(dynprop->const_val ())
|
||||
#define TYPE_DYN_PROP_KIND(dynprop) \
|
||||
dynprop->kind
|
||||
(dynprop->kind ())
|
||||
|
||||
|
||||
/* Accessors for struct range_bounds data attached to an array type's
|
||||
|
||||
Reference in New Issue
Block a user