gdb: add type::num_fields / type::set_num_fields

Add the `num_fields` and `set_num_fields` methods on `struct type`, in
order to remove the `TYPE_NFIELDS` macro.  In this patch, the
`TYPE_NFIELDS` macro is changed to use `type::num_fields`, so all the
call sites that are used to set the number of fields are changed to use
`type::set_num_fields`.  The next patch will remove `TYPE_NFIELDS`
completely.

I think that in the future, we should consider making the interface of
`struct type` better.  For example, right now it's possible for the
number of fields property and the actual number of fields set to be out
of sync.  However, I want to keep the existing behavior in this patch,
just translate from macros to methods.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <num_fields, set_num_fields>: New
	methods.
	(TYPE_NFIELDS): Use type::num_fields.  Change all call sites
	that modify the number of fields to use type::set_num_fields
	instead.

Change-Id: I5ad9de5be4097feaf942d111077434bf91d13dc5
This commit is contained in:
Simon Marchi
2020-05-22 16:55:14 -04:00
parent 9392ebb3bb
commit 5e33d5f4e1
14 changed files with 62 additions and 43 deletions

View File

@@ -308,7 +308,7 @@ attach_fields_to_type (struct ctf_field_info *fip, struct type *type)
return;
/* Record the field count, allocate space for the array of fields. */
TYPE_NFIELDS (type) = nfields;
type->set_num_fields (nfields);
TYPE_FIELDS (type)
= (struct field *) TYPE_ZALLOC (type, sizeof (struct field) * nfields);
@@ -1139,7 +1139,7 @@ add_stt_func (struct ctf_context *ccp, unsigned long idx)
ftype = get_tid_type (ccp->of, tid);
if (finfo.ctc_flags & CTF_FUNC_VARARG)
TYPE_VARARGS (ftype) = 1;
TYPE_NFIELDS (ftype) = argc;
ftype->set_num_fields (argc);
/* If argc is 0, it has a "void" type. */
if (argc != 0)