Remove some type field accessor macros

This removes TYPE_FIELD_PRIVATE, TYPE_FIELD_PROTECTED,
TYPE_FIELD_IGNORE, and TYPE_FIELD_VIRTUAL.

In c-varobj.c, match_accessibility can be removed entirely now.  Note
that the comment before this function was incorrect.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Keith Seitz <keiths@redhat.com>
This commit is contained in:
Tom Tromey 2023-09-21 10:36:23 -06:00
parent a3e9fbf7e8
commit 20aadb931d
9 changed files with 40 additions and 60 deletions

View file

@ -627,7 +627,7 @@ print_field_values (struct value *value, struct value *outer_value,
{
/* Bitfields require special handling, especially due to byte
order problems. */
if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
if (type->field (i).is_ignored ())
{
fputs_styled (_("<optimized out or zero length>"),
metadata_style.style (), stream);

View file

@ -238,7 +238,7 @@ cp_type_print_derivation_info (struct ui_file *stream,
gdb_puts (i == 0 ? ": " : ", ", stream);
gdb_printf (stream, "%s%s ",
BASETYPE_VIA_PUBLIC (type, i)
? "public" : (TYPE_FIELD_PROTECTED (type, i)
? "public" : (type->field (i).is_protected ()
? "protected" : "private"),
BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
name = TYPE_BASECLASS (type, i)->name ();
@ -912,7 +912,7 @@ need_access_label_p (struct type *type)
if (type->is_declared_class ())
{
for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
if (!TYPE_FIELD_PRIVATE (type, i))
if (!type->field (i).is_private ())
return true;
for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
for (int i = 0; i < TYPE_FN_FIELDLIST_LENGTH (type, j); i++)
@ -926,7 +926,7 @@ need_access_label_p (struct type *type)
else
{
for (int i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
if (TYPE_FIELD_PRIVATE (type, i) || TYPE_FIELD_PROTECTED (type, i))
if (!type->field (i).is_public ())
return true;
for (int j = 0; j < TYPE_NFN_FIELDS (type); j++)
{
@ -1102,8 +1102,8 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
{
section_type = output_access_specifier
(stream, section_type, level,
TYPE_FIELD_PROTECTED (type, i),
TYPE_FIELD_PRIVATE (type, i), flags);
type->field (i).is_protected (),
type->field (i).is_private (), flags);
}
bool is_static = type->field (i).is_static ();

View file

@ -647,16 +647,18 @@ cplus_class_num_children (struct type *type, int children[3])
vptr_fieldno = get_vptr_fieldno (type, &basetype);
for (i = TYPE_N_BASECLASSES (type); i < type->num_fields (); i++)
{
field &fld = type->field (i);
/* If we have a virtual table pointer, omit it. Even if virtual
table pointers are not specifically marked in the debug info,
they should be artificial. */
if ((type == basetype && i == vptr_fieldno)
|| type->field (i).is_artificial ())
|| fld.is_artificial ())
continue;
if (TYPE_FIELD_PROTECTED (type, i))
if (fld.is_protected ())
children[v_protected]++;
else if (TYPE_FIELD_PRIVATE (type, i))
else if (fld.is_private ())
children[v_private]++;
else
children[v_public]++;
@ -669,23 +671,6 @@ cplus_name_of_variable (const struct varobj *parent)
return c_name_of_variable (parent);
}
/* Check if field INDEX of TYPE has the specified accessibility.
Return 0 if so and 1 otherwise. */
static int
match_accessibility (struct type *type, int index, enum accessibility acc)
{
if (acc == accessibility::PRIVATE && TYPE_FIELD_PRIVATE (type, index))
return 1;
else if (acc == accessibility::PROTECTED && TYPE_FIELD_PROTECTED (type, index))
return 1;
else if (acc == accessibility::PUBLIC && !TYPE_FIELD_PRIVATE (type, index)
&& !TYPE_FIELD_PROTECTED (type, index))
return 1;
else
return 0;
}
static void
cplus_describe_child (const struct varobj *parent, int index,
std::string *cname, struct value **cvalue, struct type **ctype,
@ -751,9 +736,9 @@ cplus_describe_child (const struct varobj *parent, int index,
if ((type == basetype && type_index == vptr_fieldno)
|| type->field (type_index).is_artificial ())
; /* ignore vptr */
else if (match_accessibility (type, type_index, acc))
--index;
++type_index;
else if (type->field (type_index).accessibility () == acc)
--index;
++type_index;
}
--type_index;

View file

@ -73,9 +73,10 @@ compile_cplus_instance::decl_name (const char *natural)
static enum gcc_cp_symbol_kind
get_field_access_flag (const struct type *type, int num)
{
if (TYPE_FIELD_PROTECTED (type, num))
field &fld = type->field (num);
if (fld.is_protected ())
return GCC_CP_ACCESS_PROTECTED;
else if (TYPE_FIELD_PRIVATE (type, num))
else if (fld.is_private ())
return GCC_CP_ACCESS_PRIVATE;
/* GDB assumes everything else is public. */
@ -583,7 +584,7 @@ compile_cplus_convert_struct_or_union_members
{
const char *field_name = type->field (i).name ();
if (TYPE_FIELD_IGNORE (type, i)
if (type->field (i).is_ignored ()
|| type->field (i).is_artificial ())
continue;

View file

@ -265,7 +265,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
/* Bitfields require special handling, especially due to
byte order problems. */
if (TYPE_FIELD_IGNORE (type, i))
if (type->field (i).is_ignored ())
{
fputs_styled ("<optimized out or zero length>",
metadata_style.style (), stream);
@ -290,7 +290,7 @@ cp_print_value_fields (struct value *val, struct ui_file *stream,
}
else
{
if (TYPE_FIELD_IGNORE (type, i))
if (type->field (i).is_ignored ())
{
fputs_styled ("<optimized out or zero length>",
metadata_style.style (), stream);

View file

@ -5229,33 +5229,34 @@ recursive_dump_type (struct type *type, int spaces)
gdb_printf ("%s\n", host_address_to_string (type->fields ()));
for (idx = 0; idx < type->num_fields (); idx++)
{
field &fld = type->field (idx);
if (type->code () == TYPE_CODE_ENUM)
gdb_printf ("%*s[%d] enumval %s type ", spaces + 2, "",
idx, plongest (type->field (idx).loc_enumval ()));
idx, plongest (fld.loc_enumval ()));
else
gdb_printf ("%*s[%d] bitpos %s bitsize %d type ", spaces + 2, "",
idx, plongest (type->field (idx).loc_bitpos ()),
type->field (idx).bitsize ());
idx, plongest (fld.loc_bitpos ()),
fld.bitsize ());
gdb_printf ("%s name '%s' (%s)",
host_address_to_string (type->field (idx).type ()),
type->field (idx).name () != NULL
? type->field (idx).name ()
host_address_to_string (fld.type ()),
fld.name () != NULL
? fld.name ()
: "<NULL>",
host_address_to_string (type->field (idx).name ()));
if (TYPE_FIELD_VIRTUAL (type, idx))
host_address_to_string (fld.name ()));
if (fld.is_virtual ())
gdb_printf (" virtual");
if (TYPE_FIELD_PRIVATE (type, idx))
if (fld.is_private ())
gdb_printf (" private");
else if (TYPE_FIELD_PROTECTED (type, idx))
else if (fld.is_protected ())
gdb_printf (" protected");
else if (TYPE_FIELD_IGNORE (type, idx))
else if (fld.is_ignored ())
gdb_printf (" ignored");
gdb_printf ("\n");
if (type->field (idx).type () != NULL)
if (fld.type () != NULL)
{
recursive_dump_type (type->field (idx).type (), spaces + 4);
recursive_dump_type (fld.type (), spaces + 4);
}
}
if (type->code () == TYPE_CODE_RANGE)

View file

@ -1974,15 +1974,6 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
#define BASETYPE_VIA_VIRTUAL(thistype, index) \
((thistype)->field (index).is_virtual ())
#define TYPE_FIELD_PRIVATE(thistype, n) \
((thistype)->field (n).is_private ())
#define TYPE_FIELD_PROTECTED(thistype, n) \
((thistype)->field (n).is_protected ())
#define TYPE_FIELD_IGNORE(thistype, n) \
((thistype)->field (n).is_ignored ())
#define TYPE_FIELD_VIRTUAL(thistype, n) \
((thistype)->field (n).is_virtual ())
#define TYPE_FN_FIELDLISTS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists
#define TYPE_FN_FIELDLIST(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n]
#define TYPE_FN_FIELDLIST1(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].fn_fields

View file

@ -486,7 +486,9 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
if (HAVE_CPLUS_STRUCT (type))
{
if (TYPE_FIELD_PROTECTED (type, i))
field &fld = type->field (i);
if (fld.is_protected ())
{
if (section_type != s_protected)
{
@ -495,7 +497,7 @@ pascal_language::type_print_base (struct type *type, struct ui_file *stream, int
level + 2, "");
}
}
else if (TYPE_FIELD_PRIVATE (type, i))
else if (fld.is_private ())
{
if (section_type != s_private)
{

View file

@ -604,7 +604,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
/* Bitfields require special handling, especially due to byte
order problems. */
if (TYPE_FIELD_IGNORE (type, i))
if (type->field (i).is_ignored ())
{
fputs_styled ("<optimized out or zero length>",
metadata_style.style (), stream);
@ -629,7 +629,7 @@ pascal_object_print_value_fields (struct value *val, struct ui_file *stream,
}
else
{
if (TYPE_FIELD_IGNORE (type, i))
if (type->field (i).is_ignored ())
{
fputs_styled ("<optimized out or zero length>",
metadata_style.style (), stream);