* [PATCH] Remove field_info::nfields member
@ 2020-02-27 21:11 Tom Tromey
2020-02-27 21:28 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2020-02-27 21:11 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I noticed that there's no real reason to have field_info::nfields in
the DWARF reader. It simply mirrors information that is already
available. This patch removes it, in favor of a convenience method.
gdb/ChangeLog
2020-02-27 Tom Tromey <tromey@adacore.com>
* dwarf2/read.c (struct field_info) <nfields>: Now a method, not a
member.
(dwarf2_add_field): Don't update nfields.
(dwarf2_attach_fields_to_type, process_structure_scope): Update.
---
gdb/ChangeLog | 7 +++++++
gdb/dwarf2/read.c | 15 ++++++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index c5f0ffa0d9d..fe0471e331f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1129,9 +1129,6 @@ struct field_info
std::vector<struct nextfield> fields;
std::vector<struct nextfield> baseclasses;
- /* Number of fields (including baseclasses). */
- int nfields = 0;
-
/* Set if the accessibility of one of the fields is not public. */
int non_public_fields = 0;
@@ -1147,6 +1144,12 @@ struct field_info
/* Nested types defined by this class and the number of elements in this
list. */
std::vector<struct decl_field> nested_types_list;
+
+ /* Return the total number of fields (including baseclasses). */
+ int nfields () const
+ {
+ return fields.size () + baseclasses.size ();
+ }
};
/* Loaded secondary compilation units are kept in memory until they
@@ -14207,8 +14210,6 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
new_field = &fip->fields.back ();
}
- fip->nfields++;
-
attr = dwarf2_attr (die, DW_AT_accessibility, cu);
if (attr != nullptr)
new_field->accessibility = DW_UNSND (attr);
@@ -14468,7 +14469,7 @@ static void
dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type,
struct dwarf2_cu *cu)
{
- int nfields = fip->nfields;
+ int nfields = fip->nfields ();
/* Record the field count, allocate space for the array of fields,
and create blank accessibility bitfields if necessary. */
@@ -15336,7 +15337,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
}
/* Attach fields and member functions to the type. */
- if (fi.nfields)
+ if (fi.nfields ())
dwarf2_attach_fields_to_type (&fi, type, cu);
if (!fi.fnfieldlists.empty ())
{
--
2.21.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Remove field_info::nfields member
2020-02-27 21:11 [PATCH] Remove field_info::nfields member Tom Tromey
@ 2020-02-27 21:28 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2020-02-27 21:28 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2020-02-27 4:11 p.m., Tom Tromey wrote:
> @@ -15336,7 +15337,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
> }
>
> /* Attach fields and member functions to the type. */
> - if (fi.nfields)
> + if (fi.nfields ())
Let's change this to
if (fi.nfields () != 0)
or
if (fi.nfields () > 0)
Otherwise, LGTM.
Simon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-27 21:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 21:11 [PATCH] Remove field_info::nfields member Tom Tromey
2020-02-27 21:28 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).