Skip to content

Commit 1f704f7

Browse files
committed
gdb: remove TYPE_NFIELDS macro
Remove `TYPE_NFIELDS`, changing all the call sites to use `type::num_fields` directly. This is quite a big diff, but this was mostly done using sed and coccinelle. A few call sites were done by hand. gdb/ChangeLog: * gdbtypes.h (TYPE_NFIELDS): Remove. Change all cal sites to use type::num_fields instead. Change-Id: Ib73be4c36f9e770e0f729bac3b5257d7cb2f9591
1 parent 5e33d5f commit 1f704f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+322
-318
lines changed

gdb/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-05-22 Simon Marchi <simon.marchi@efficios.com>
2+
3+
* gdbtypes.h (TYPE_NFIELDS): Remove. Change all cal sites to use
4+
type::num_fields instead.
5+
16
2020-05-22 Simon Marchi <simon.marchi@efficios.com>
27

38
* gdbtypes.h (struct type) <num_fields, set_num_fields>: New

gdb/aarch64-tdep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ aapcs_is_vfp_call_or_return_candidate_1 (struct type *type,
13461346
{
13471347
int count = 0;
13481348

1349-
for (int i = 0; i < TYPE_NFIELDS (type); i++)
1349+
for (int i = 0; i < type->num_fields (); i++)
13501350
{
13511351
/* Ignore any static fields. */
13521352
if (field_is_static (&TYPE_FIELD (type, i)))
@@ -1628,7 +1628,7 @@ pass_in_v_vfp_candidate (struct gdbarch *gdbarch, struct regcache *regcache,
16281628

16291629
case TYPE_CODE_STRUCT:
16301630
case TYPE_CODE_UNION:
1631-
for (int i = 0; i < TYPE_NFIELDS (arg_type); i++)
1631+
for (int i = 0; i < arg_type->num_fields (); i++)
16321632
{
16331633
/* Don't include static fields. */
16341634
if (field_is_static (&TYPE_FIELD (arg_type, i)))

gdb/ada-exp.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ convert_char_literal (struct type *type, LONGEST val)
13941394
else
13951395
xsnprintf (name, sizeof (name), "QU%02x", (int) val);
13961396
size_t len = strlen (name);
1397-
for (f = 0; f < TYPE_NFIELDS (type); f += 1)
1397+
for (f = 0; f < type->num_fields (); f += 1)
13981398
{
13991399
/* Check the suffix because an enum constant in a package will
14001400
have a name like "pkg__QUxx". This is safe enough because we

gdb/ada-lang.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ ada_get_field_index (const struct type *type, const char *field_name,
571571
int fieldno;
572572
struct type *struct_type = check_typedef ((struct type *) type);
573573

574-
for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); fieldno++)
574+
for (fieldno = 0; fieldno < struct_type->num_fields (); fieldno++)
575575
if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
576576
return fieldno;
577577

@@ -755,7 +755,7 @@ ada_discrete_type_high_bound (struct type *type)
755755
case TYPE_CODE_RANGE:
756756
return TYPE_HIGH_BOUND (type);
757757
case TYPE_CODE_ENUM:
758-
return TYPE_FIELD_ENUMVAL (type, TYPE_NFIELDS (type) - 1);
758+
return TYPE_FIELD_ENUMVAL (type, type->num_fields () - 1);
759759
case TYPE_CODE_BOOL:
760760
return 1;
761761
case TYPE_CODE_CHAR:
@@ -1461,7 +1461,7 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
14611461

14621462
if (index_desc_type == NULL)
14631463
return;
1464-
gdb_assert (TYPE_NFIELDS (index_desc_type) > 0);
1464+
gdb_assert (index_desc_type->num_fields () > 0);
14651465

14661466
/* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
14671467
to check one field only, no need to check them all). If not, return
@@ -1476,7 +1476,7 @@ ada_fixup_array_indexes_type (struct type *index_desc_type)
14761476
return;
14771477

14781478
/* Fixup each field of INDEX_DESC_TYPE. */
1479-
for (i = 0; i < TYPE_NFIELDS (index_desc_type); i++)
1479+
for (i = 0; i < index_desc_type->num_fields (); i++)
14801480
{
14811481
const char *name = TYPE_FIELD_NAME (index_desc_type, i);
14821482
struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
@@ -1807,7 +1807,7 @@ desc_arity (struct type *type)
18071807
type = desc_base_type (type);
18081808

18091809
if (type != NULL)
1810-
return TYPE_NFIELDS (type) / 2;
1810+
return type->num_fields () / 2;
18111811
return 0;
18121812
}
18131813

@@ -3206,12 +3206,12 @@ ada_print_symbol_signature (struct ui_file *stream, struct symbol *sym,
32063206
|| type->code () != TYPE_CODE_FUNC)
32073207
return;
32083208

3209-
if (TYPE_NFIELDS (type) > 0)
3209+
if (type->num_fields () > 0)
32103210
{
32113211
int i;
32123212

32133213
fprintf_filtered (stream, " (");
3214-
for (i = 0; i < TYPE_NFIELDS (type); ++i)
3214+
for (i = 0; i < type->num_fields (); ++i)
32153215
{
32163216
if (i > 0)
32173217
fprintf_filtered (stream, "; ");
@@ -3897,7 +3897,7 @@ ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
38973897
else if (func_type == NULL || func_type->code () != TYPE_CODE_FUNC)
38983898
return 0;
38993899

3900-
if (TYPE_NFIELDS (func_type) != n_actuals)
3900+
if (func_type->num_fields () != n_actuals)
39013901
return 0;
39023902

39033903
for (i = 0; i < n_actuals; i += 1)
@@ -4958,7 +4958,7 @@ is_nondebugging_type (struct type *type)
49584958
49594959
This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
49604960
types and that their number of enumerals is identical (in other
4961-
words, TYPE_NFIELDS (type1) == TYPE_NFIELDS (type2)). */
4961+
words, type1->num_fields () == type2->num_fields ()). */
49624962

49634963
static int
49644964
ada_identical_enum_types_p (struct type *type1, struct type *type2)
@@ -4971,13 +4971,13 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
49714971
underlying value and name. */
49724972

49734973
/* All enums in the type should have an identical underlying value. */
4974-
for (i = 0; i < TYPE_NFIELDS (type1); i++)
4974+
for (i = 0; i < type1->num_fields (); i++)
49754975
if (TYPE_FIELD_ENUMVAL (type1, i) != TYPE_FIELD_ENUMVAL (type2, i))
49764976
return 0;
49774977

49784978
/* All enumerals should also have the same name (modulo any numerical
49794979
suffix). */
4980-
for (i = 0; i < TYPE_NFIELDS (type1); i++)
4980+
for (i = 0; i < type1->num_fields (); i++)
49814981
{
49824982
const char *name_1 = TYPE_FIELD_NAME (type1, i);
49834983
const char *name_2 = TYPE_FIELD_NAME (type2, i);
@@ -5040,8 +5040,8 @@ symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
50405040

50415041
/* Quick check: They should all have the same number of enumerals. */
50425042
for (i = 1; i < syms.size (); i++)
5043-
if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].symbol))
5044-
!= TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol)))
5043+
if (SYMBOL_TYPE (syms[i].symbol)->num_fields ()
5044+
!= SYMBOL_TYPE (syms[0].symbol)->num_fields ())
50455045
return 0;
50465046

50475047
/* All the sanity checks passed, so we might have a set of
@@ -6527,7 +6527,7 @@ ada_is_interface_tag (struct type *type)
65276527
int
65286528
ada_is_ignored_field (struct type *type, int field_num)
65296529
{
6530-
if (field_num < 0 || field_num > TYPE_NFIELDS (type))
6530+
if (field_num < 0 || field_num > type->num_fields ())
65316531
return 1;
65326532

65336533
/* Check the name of that field. */
@@ -6863,7 +6863,7 @@ ada_parent_type (struct type *type)
68636863
if (type == NULL || type->code () != TYPE_CODE_STRUCT)
68646864
return NULL;
68656865

6866-
for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6866+
for (i = 0; i < type->num_fields (); i += 1)
68676867
if (ada_is_parent_field (type, i))
68686868
{
68696869
struct type *parent_type = TYPE_FIELD_TYPE (type, i);
@@ -7226,7 +7226,7 @@ find_struct_field (const char *name, struct type *type, int offset,
72267226
if (bit_size_p != NULL)
72277227
*bit_size_p = 0;
72287228

7229-
for (i = 0; i < TYPE_NFIELDS (type); i += 1)
7229+
for (i = 0; i < type->num_fields (); i += 1)
72307230
{
72317231
int bit_pos = TYPE_FIELD_BITPOS (type, i);
72327232
int fld_offset = offset + bit_pos / 8;
@@ -7278,7 +7278,7 @@ find_struct_field (const char *name, struct type *type, int offset,
72787278
struct type *field_type
72797279
= ada_check_typedef (TYPE_FIELD_TYPE (type, i));
72807280

7281-
for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
7281+
for (j = 0; j < field_type->num_fields (); j += 1)
72827282
{
72837283
if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j),
72847284
fld_offset
@@ -7338,7 +7338,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
73387338
int parent_offset = -1;
73397339

73407340
type = ada_check_typedef (type);
7341-
for (i = 0; i < TYPE_NFIELDS (type); i += 1)
7341+
for (i = 0; i < type->num_fields (); i += 1)
73427342
{
73437343
const char *t_field_name = TYPE_FIELD_NAME (type, i);
73447344

@@ -7381,7 +7381,7 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
73817381
i));
73827382
int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
73837383

7384-
for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
7384+
for (j = 0; j < field_type->num_fields (); j += 1)
73857385
{
73867386
struct value *v = ada_search_struct_field /* Force line
73877387
break. */
@@ -7439,7 +7439,7 @@ ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
74397439
int i;
74407440
type = ada_check_typedef (type);
74417441

7442-
for (i = 0; i < TYPE_NFIELDS (type); i += 1)
7442+
for (i = 0; i < type->num_fields (); i += 1)
74437443
{
74447444
if (TYPE_FIELD_NAME (type, i) == NULL)
74457445
continue;
@@ -7532,7 +7532,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
75327532

75337533
type = to_static_fixed_type (type);
75347534

7535-
for (i = 0; i < TYPE_NFIELDS (type); i += 1)
7535+
for (i = 0; i < type->num_fields (); i += 1)
75367536
{
75377537
const char *t_field_name = TYPE_FIELD_NAME (type, i);
75387538
struct type *t;
@@ -7571,7 +7571,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
75717571
struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
75727572
i));
75737573

7574-
for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
7574+
for (j = field_type->num_fields () - 1; j >= 0; j -= 1)
75757575
{
75767576
/* FIXME pnh 2008/01/26: We check for a field that is
75777577
NOT wrapped in a struct, since the compiler sometimes
@@ -7655,7 +7655,7 @@ ada_which_variant_applies (struct type *var_type, struct value *outer)
76557655
discrim_val = value_as_long (discrim);
76567656

76577657
others_clause = -1;
7658-
for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
7658+
for (i = 0; i < var_type->num_fields (); i += 1)
76597659
{
76607660
if (ada_is_others_clause (var_type, i))
76617661
others_clause = i;
@@ -8005,7 +8005,7 @@ variant_field_index (struct type *type)
80058005
if (type == NULL || type->code () != TYPE_CODE_STRUCT)
80068006
return -1;
80078007

8008-
for (f = 0; f < TYPE_NFIELDS (type); f += 1)
8008+
for (f = 0; f < type->num_fields (); f += 1)
80098009
{
80108010
if (ada_is_variant_part (type, f))
80118011
return f;
@@ -8064,11 +8064,11 @@ ada_template_to_fixed_record_type_1 (struct type *type,
80648064
to be processed: unless keep_dynamic_fields, this includes only
80658065
fields whose position and length are static will be processed. */
80668066
if (keep_dynamic_fields)
8067-
nfields = TYPE_NFIELDS (type);
8067+
nfields = type->num_fields ();
80688068
else
80698069
{
80708070
nfields = 0;
8071-
while (nfields < TYPE_NFIELDS (type)
8071+
while (nfields < type->num_fields ()
80728072
&& !ada_is_variant_part (type, nfields)
80738073
&& !is_dynamic_field (type, nfields))
80748074
nfields++;
@@ -8243,7 +8243,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
82438243
cond_offset_target (address, off / TARGET_CHAR_BIT), dval);
82448244
if (branch_type == NULL)
82458245
{
8246-
for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
8246+
for (f = variant_field + 1; f < rtype->num_fields (); f += 1)
82478247
TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
82488248
rtype->set_num_fields (rtype->num_fields () - 1);
82498249
}
@@ -8325,7 +8325,7 @@ template_to_static_fixed_type (struct type *type0)
83258325

83268326
/* Don't clone TYPE0 until we are sure we are going to need a copy. */
83278327
type = type0;
8328-
nfields = TYPE_NFIELDS (type0);
8328+
nfields = type0->num_fields ();
83298329

83308330
/* Whether or not we cloned TYPE0, cache the result so that we don't do
83318331
recompute all over next time. */
@@ -8384,7 +8384,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
83848384
struct value *dval;
83858385
struct type *rtype;
83868386
struct type *branch_type;
8387-
int nfields = TYPE_NFIELDS (type);
8387+
int nfields = type->num_fields ();
83888388
int variant_field = variant_field_index (type);
83898389

83908390
if (variant_field == -1)
@@ -8590,7 +8590,7 @@ ada_is_redundant_index_type_desc (struct type *array_type,
85908590
struct type *this_layer = check_typedef (array_type);
85918591
int i;
85928592

8593-
for (i = 0; i < TYPE_NFIELDS (desc_type); i++)
8593+
for (i = 0; i < desc_type->num_fields (); i++)
85948594
{
85958595
if (!ada_is_redundant_range_encoding (TYPE_INDEX_TYPE (this_layer),
85968596
TYPE_FIELD_TYPE (desc_type, i)))
@@ -8694,7 +8694,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
86948694
struct type *elt_type0;
86958695

86968696
elt_type0 = type0;
8697-
for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
8697+
for (i = index_type_desc->num_fields (); i > 0; i -= 1)
86988698
elt_type0 = TYPE_TARGET_TYPE (elt_type0);
86998699

87008700
/* NOTE: result---the fixed version of elt_type0---should never
@@ -8712,7 +8712,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
87128712
ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval, 1);
87138713

87148714
elt_type0 = type0;
8715-
for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
8715+
for (i = index_type_desc->num_fields () - 1; i >= 0; i -= 1)
87168716
{
87178717
struct type *range_type =
87188718
to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, i), dval);
@@ -9148,7 +9148,7 @@ value_val_atr (struct type *type, struct value *arg)
91489148
{
91499149
long pos = value_as_long (arg);
91509150

9151-
if (pos < 0 || pos >= TYPE_NFIELDS (type))
9151+
if (pos < 0 || pos >= type->num_fields ())
91529152
error (_("argument to 'VAL out of range"));
91539153
return value_from_longest (type, TYPE_FIELD_ENUMVAL (type, pos));
91549154
}
@@ -9229,7 +9229,7 @@ ada_is_aligner_type (struct type *type)
92299229
return 0;
92309230

92319231
return (type->code () == TYPE_CODE_STRUCT
9232-
&& TYPE_NFIELDS (type) == 1
9232+
&& type->num_fields () == 1
92339233
&& strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
92349234
}
92359235

@@ -9263,7 +9263,7 @@ ada_get_base_type (struct type *raw_type)
92639263
real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
92649264
if (real_type_namer == NULL
92659265
|| real_type_namer->code () != TYPE_CODE_STRUCT
9266-
|| TYPE_NFIELDS (real_type_namer) != 1)
9266+
|| real_type_namer->num_fields () != 1)
92679267
return raw_type;
92689268

92699269
if (TYPE_FIELD_TYPE (real_type_namer, 0)->code () != TYPE_CODE_REF)

0 commit comments

Comments
 (0)