+2020-05-22 Simon Marchi <simon.marchi@efficios.com>
+
+ * gdbtypes.h (struct type) <fields, set_fields>: New methods.
+ (TYPE_FIELDS): Use type::fields. Change all call sites that
+ modify the propery to use type::set_fields instead.
+
2020-05-22 Simon Marchi <simon.marchi@efficios.com>
* gdbtypes.h (TYPE_NFIELDS): Remove. Change all cal sites to use
struct type *type = alloc_type_copy (templ);
type->set_code (TYPE_CODE_STRUCT);
- TYPE_FIELDS (type) = NULL;
INIT_NONE_SPECIFIC (type);
type->set_name ("<empty>");
TYPE_LENGTH (type) = 0;
rtype->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (rtype);
rtype->set_num_fields (nfields);
- TYPE_FIELDS (rtype) = (struct field *)
- TYPE_ALLOC (rtype, nfields * sizeof (struct field));
- memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
+ rtype->set_fields
+ ((struct field *) TYPE_ZALLOC (rtype, nfields * sizeof (struct field)));
rtype->set_name (ada_type_name (type));
TYPE_FIXED_INSTANCE (rtype) = 1;
type->set_code (type0->code ());
INIT_NONE_SPECIFIC (type);
type->set_num_fields (nfields);
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, nfields * sizeof (struct field));
- memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
+
+ field *fields =
+ ((struct field *)
+ TYPE_ALLOC (type, nfields * sizeof (struct field)));
+ memcpy (fields, TYPE_FIELDS (type0),
sizeof (struct field) * nfields);
+ type->set_fields (fields);
+
type->set_name (ada_type_name (type0));
TYPE_FIXED_INSTANCE (type) = 1;
TYPE_LENGTH (type) = 0;
rtype->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (rtype);
rtype->set_num_fields (nfields);
- TYPE_FIELDS (rtype) =
+
+ field *fields =
(struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
- memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
- sizeof (struct field) * nfields);
+ memcpy (fields, TYPE_FIELDS (type), sizeof (struct field) * nfields);
+ rtype->set_fields (fields);
+
rtype->set_name (ada_type_name (type));
TYPE_FIXED_INSTANCE (rtype) = 1;
TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
if (nparams > 0)
{
ftype->set_num_fields (nparams);
- TYPE_FIELDS (ftype) = (struct field *)
- TYPE_ALLOC (ftype, nparams * sizeof (struct field));
+ ftype->set_fields
+ ((struct field *)
+ TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
iparams = 0;
/* Here we want to directly access the dictionary, because
TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
target->set_num_fields (real_target->num_fields ());
- TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target,
- field_size);
- memcpy (TYPE_FIELDS (target),
- TYPE_FIELDS (real_target),
- field_size);
+ field *fields = (struct field *) TYPE_ALLOC (target, field_size);
+ memcpy (fields, real_target->fields (), field_size);
+ target->set_fields (fields);
if (real_target->name ())
{
type->set_name (NULL);
INIT_CPLUS_SPECIFIC (type);
TYPE_LENGTH (type) = 0;
- TYPE_FIELDS (type) = 0;
+ type->set_fields (nullptr);
type->set_num_fields (0);
}
else
type->set_name (NULL);
INIT_CPLUS_SPECIFIC (type);
TYPE_LENGTH (type) = 0;
- TYPE_FIELDS (type) = 0;
+ type->set_fields (nullptr);
type->set_num_fields (0);
}
else
type->set_code (TYPE_CODE_ENUM);
type->set_name (NULL);
TYPE_LENGTH (type) = 0;
- TYPE_FIELDS (type) = 0;
+ type->set_fields (nullptr);
type->set_num_fields (0);
}
else
/* Now create the vector of fields, and record how big it is. */
type->set_num_fields (nfields);
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, sizeof (struct field) * nfields);
+ type->set_fields
+ ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nfields));
/* Copy the saved-up fields into the field vector. */
TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
type->set_code (TYPE_CODE_ENUM);
type->set_num_fields (nsyms);
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+ type->set_fields
+ ((struct field *) TYPE_ALLOC (type, sizeof (struct field) * nsyms));
/* Find the symbols for the values and put them into the type.
The symbols can be found in the symlist that we put them on
/* Record the field count, allocate space for the array of fields. */
type->set_num_fields (nfields);
- TYPE_FIELDS (type)
- = (struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields);
+ type->set_fields
+ ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
/* Copy the saved-up fields into the field vector. */
for (int i = 0; i < nfields; ++i)
/* If argc is 0, it has a "void" type. */
if (argc != 0)
- TYPE_FIELDS (ftype)
- = (struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field));
+ ftype->set_fields
+ ((struct field *) TYPE_ZALLOC (ftype, argc * sizeof (struct field)));
/* TYPE_FIELD_TYPE must never be NULL. Fill it with void_type, if failed
to find the argument type. */
type->set_num_fields (3);
/* Save the field we care about. */
struct field saved_field = TYPE_FIELD (type, 0);
- TYPE_FIELDS (type)
- = (struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field));
+ type->set_fields
+ ((struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field)));
/* Put the discriminant at index 0. */
TYPE_FIELD_TYPE (type, 0) = field_type;
* sizeof (struct field)));
memcpy (new_fields + 1, TYPE_FIELDS (type),
type->num_fields () * sizeof (struct field));
- TYPE_FIELDS (type) = new_fields;
+ type->set_fields (new_fields);
type->set_num_fields (type->num_fields () + 1);
/* Install the discriminant at index 0 in the union. */
if (sub_type->num_fields () > 0)
{
sub_type->set_num_fields (sub_type->num_fields () - 1);
- ++TYPE_FIELDS (sub_type);
+ sub_type->set_fields (sub_type->fields () + 1);
}
TYPE_FIELD_NAME (type, i) = variant_name;
sub_type->set_name
/* Record the field count, allocate space for the array of fields,
and create blank accessibility bitfields if necessary. */
type->set_num_fields (nfields);
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ZALLOC (type, sizeof (struct field) * nfields);
+ type->set_fields
+ ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields));
if (fip->non_public_fields && cu->language != language_ada)
{
if (!fields.empty ())
{
type->set_num_fields (fields.size ());
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, sizeof (struct field) * fields.size ());
+ type->set_fields
+ ((struct field *)
+ TYPE_ALLOC (type, sizeof (struct field) * fields.size ()));
memcpy (TYPE_FIELDS (type), fields.data (),
sizeof (struct field) * fields.size ());
}
/* Allocate storage for parameters and fill them in. */
ftype->set_num_fields (nparams);
- TYPE_FIELDS (ftype) = (struct field *)
- TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
+ ftype->set_fields
+ ((struct field *) TYPE_ZALLOC (ftype, nparams * sizeof (struct field)));
/* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
even if we error out during the parameters reading below. */
allocate memory for auxiliary fields, and free the memory ourselves
when we are done with it. */
type->set_num_fields (num_types);
- TYPE_FIELDS (type) = (struct field *)
- xzalloc (sizeof (struct field) * num_types);
+ type->set_fields
+ ((struct field *) xzalloc (sizeof (struct field) * num_types));
while (num_types-- > 0)
TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
}
fn->set_num_fields (nparams);
- TYPE_FIELDS (fn)
- = (struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field));
+ fn->set_fields
+ ((struct field *) TYPE_ZALLOC (fn, nparams * sizeof (struct field)));
for (i = 0; i < nparams; ++i)
TYPE_FIELD_TYPE (fn, i) = param_types[i];
TYPE_TARGET_TYPE (result_type) = element_type;
result_type->set_num_fields (1);
- TYPE_FIELDS (result_type) =
- (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
+ result_type->set_fields
+ ((struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)));
TYPE_INDEX_TYPE (result_type) = range_type;
if (byte_stride_prop != NULL)
result_type->add_dyn_prop (DYN_PROP_BYTE_STRIDE, *byte_stride_prop);
result_type->set_code (TYPE_CODE_SET);
result_type->set_num_fields (1);
- TYPE_FIELDS (result_type)
- = (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
+ result_type->set_fields
+ ((struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)));
if (!TYPE_STUB (domain_type))
{
type->set_code (TYPE_CODE_METHOD);
TYPE_TARGET_TYPE (type) = to_type;
set_type_self_type (type, self_type);
- TYPE_FIELDS (type) = args;
+ type->set_fields (args);
type->set_num_fields (nargs);
if (varargs)
TYPE_VARARGS (type) = 1;
gdb_assert (type->code () == TYPE_CODE_UNION);
resolved_type = copy_type (type);
- TYPE_FIELDS (resolved_type)
- = (struct field *) TYPE_ALLOC (resolved_type,
- resolved_type->num_fields ()
- * sizeof (struct field));
+ resolved_type->set_fields
+ ((struct field *)
+ TYPE_ALLOC (resolved_type,
+ resolved_type->num_fields () * sizeof (struct field)));
memcpy (TYPE_FIELDS (resolved_type),
TYPE_FIELDS (type),
resolved_type->num_fields () * sizeof (struct field));
resolved_type->set_num_fields
(std::count (flags.begin (), flags.end (), true));
- TYPE_FIELDS (resolved_type)
- = (struct field *) TYPE_ALLOC (resolved_type,
- resolved_type->num_fields ()
- * sizeof (struct field));
+ resolved_type->set_fields
+ ((struct field *)
+ TYPE_ALLOC (resolved_type,
+ resolved_type->num_fields () * sizeof (struct field)));
+
int out = 0;
for (int i = 0; i < type->num_fields (); ++i)
{
}
else
{
- TYPE_FIELDS (resolved_type)
- = (struct field *) TYPE_ALLOC (resolved_type,
- resolved_type->num_fields ()
- * sizeof (struct field));
+ resolved_type->set_fields
+ ((struct field *)
+ TYPE_ALLOC (resolved_type,
+ resolved_type->num_fields () * sizeof (struct field)));
memcpy (TYPE_FIELDS (resolved_type),
TYPE_FIELDS (type),
resolved_type->num_fields () * sizeof (struct field));
int i, nfields;
nfields = type->num_fields ();
- TYPE_FIELDS (new_type) = (struct field *)
- TYPE_ZALLOC (new_type, nfields * sizeof (struct field));
+ new_type->set_fields
+ ((struct field *)
+ TYPE_ZALLOC (new_type, nfields * sizeof (struct field)));
+
for (i = 0; i < nfields; i++)
{
TYPE_FIELD_ARTIFICIAL (new_type, i) =
TYPE_UNSIGNED (type) = 1;
type->set_num_fields (0);
/* Pre-allocate enough space assuming every field is one bit. */
- TYPE_FIELDS (type)
- = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
+ type->set_fields
+ ((struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field)));
return type;
}
struct field *f;
t->set_num_fields (t->num_fields () + 1);
- TYPE_FIELDS (t) = XRESIZEVEC (struct field, TYPE_FIELDS (t),
- t->num_fields ());
+ t->set_fields (XRESIZEVEC (struct field, TYPE_FIELDS (t),
+ t->num_fields ()));
f = &(TYPE_FIELDS (t)[t->num_fields () - 1]);
memset (f, 0, sizeof f[0]);
FIELD_TYPE (f[0]) = field;
this->main_type->nfields = num_fields;
}
+ /* Get the fields array of this type. */
+ field *fields () const
+ {
+ return this->main_type->flds_bnds.fields;
+ }
+
+ /* Set the fields array of this type. */
+ void set_fields (field *fields)
+ {
+ this->main_type->flds_bnds.fields = fields;
+ }
+
/* * Return the dynamic property of the requested KIND from this type's
list of dynamic properties. */
dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
space in struct type. */
extern bool set_type_align (struct type *, ULONGEST);
-#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
+#define TYPE_FIELDS(thistype) (thistype)->fields ()
#define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
#define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
t->set_num_fields (field - field_list);
- TYPE_FIELDS (t) = field_list;
+ t->set_fields (field_list);
t->set_name ("gdb_gnu_v3_abi_vtable");
INIT_CPLUS_SPECIFIC (t);
t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
t->set_num_fields (field - field_list);
- TYPE_FIELDS (t) = field_list;
+ t->set_fields (field_list);
t->set_name ("gdb_gnu_v3_type_info");
INIT_CPLUS_SPECIFIC (t);
t->set_code (type_code);
TYPE_LENGTH (t) = sh->value;
t->set_num_fields (nfields);
- TYPE_FIELDS (t) = f = ((struct field *)
- TYPE_ALLOC (t,
- nfields * sizeof (struct field)));
+ f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field)));
+ t->set_fields (f);
if (type_code == TYPE_CODE_ENUM)
{
struct block_iterator iter;
ftype->set_num_fields (nparams);
- TYPE_FIELDS (ftype) = (struct field *)
- TYPE_ALLOC (ftype, nparams * sizeof (struct field));
+ ftype->set_fields
+ ((struct field *)
+ TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
iparams = 0;
ALL_BLOCK_SYMBOLS (cblock, iter, sym)
result->set_name (name);
result->set_num_fields (nfields);
- TYPE_FIELDS (result)
- = (struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field));
+ result->set_fields
+ ((struct field *) TYPE_ZALLOC (result, nfields * sizeof (struct field)));
i = 0;
bitpos = 0;
}
/* Allocate parameter information fields and fill them in. */
- TYPE_FIELDS (ftype) = (struct field *)
- TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
+ ftype->set_fields
+ ((struct field *)
+ TYPE_ALLOC (ftype, nsemi * sizeof (struct field)));
while (*p++ == ';')
{
struct type *ptype;
&& arg_types->type->code () == TYPE_CODE_VOID)
num_args = 0;
- TYPE_FIELDS (func_type)
- = (struct field *) TYPE_ALLOC (func_type,
- num_args * sizeof (struct field));
+ func_type->set_fields
+ ((struct field *) TYPE_ALLOC (func_type,
+ num_args * sizeof (struct field)));
memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
{
int i;
array of fields, and create blank visibility bitfields if necessary. */
type->set_num_fields (nfields);
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, sizeof (struct field) * nfields);
+ type->set_fields
+ ((struct field *)
+ TYPE_ALLOC (type, sizeof (struct field) * nfields));
memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
if (non_public_fields)
if (unsigned_enum)
TYPE_UNSIGNED (type) = 1;
type->set_num_fields (nsyms);
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ALLOC (type, sizeof (struct field) * nsyms);
+ type->set_fields
+ ((struct field *)
+ TYPE_ALLOC (type, sizeof (struct field) * nsyms));
memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
/* Find the symbols for the values and put them into the type.
type = arch_type (gdbarch, TYPE_CODE_ENUM, bit, name);
type->set_num_fields (count);
- TYPE_FIELDS (type) = (struct field *)
- TYPE_ZALLOC (type, sizeof (struct field) * count);
+ type->set_fields
+ ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count));
TYPE_UNSIGNED (type) = 1;
for (i = 0; i < count; i++)