From 20aadb931ddf2c6c4f9209fffd1fbfda50215342 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 21 Sep 2023 10:36:23 -0600 Subject: 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 Reviewed-by: Keith Seitz --- gdb/ada-valprint.c | 2 +- gdb/c-typeprint.c | 10 +++++----- gdb/c-varobj.c | 31 ++++++++----------------------- gdb/compile/compile-cplus-types.c | 7 ++++--- gdb/cp-valprint.c | 4 ++-- gdb/gdbtypes.c | 27 ++++++++++++++------------- gdb/gdbtypes.h | 9 --------- gdb/p-typeprint.c | 6 ++++-- gdb/p-valprint.c | 4 ++-- 9 files changed, 40 insertions(+), 60 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index f1c4e8b..86cab35 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -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 (_(""), metadata_style.style (), stream); diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 241fbca..4a0c695 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -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 (); diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c index 543cd58..05b5bd7 100644 --- a/gdb/c-varobj.c +++ b/gdb/c-varobj.c @@ -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; diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index ac27e83..a59d77b 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -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; diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c index 820a761..a803c78 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -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 ("", 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 ("", metadata_style.style (), stream); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 8468b9a..aa2fce0 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -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 () : "", - 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) diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 6a11f58..76ea3f7 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -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 diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c index 41058a8..b5d6626 100644 --- a/gdb/p-typeprint.c +++ b/gdb/p-typeprint.c @@ -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) { diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c index fb93862..0560162 100644 --- a/gdb/p-valprint.c +++ b/gdb/p-valprint.c @@ -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 ("", 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 ("", metadata_style.style (), stream); -- cgit v1.1