From patchwork Fri Oct 27 17:36:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 78627 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FAAD38618FC for ; Fri, 27 Oct 2023 17:37:49 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id A5D22386074C for ; Fri, 27 Oct 2023 17:36:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5D22386074C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A5D22386074C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698428216; cv=none; b=f76NXPYSWCokhl3iXM7RdocYiIlZXTET9Ag36G6GmDkXg3yK+dQCUXW9tEbUWwaWKGTAevCyXMEd8PhZ5rPBhS+1/xVmPrGeTJ3fbX1tCl2pu+Hf4iE2lHBHXkatYXcNikSOXZRHTxcpU3Adg69ArwuVKFsbnqzeY6sXMZLpUlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698428216; c=relaxed/simple; bh=0NSdml0qc+LbAK3Lc3swEQpuqQbxRCQ84LW6otnLQ8Q=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=FMvVC1simPcQHH9Hq8KowU1dkfdALmJVsAj20R6Bf7rEvbh7KkrXrkIENQKr1arT4DAAdpPdImgM7YLWPlZehKaxAc+N+30zeUdbYm98d9MC3XCoMfKQbMIvrSheGEnarbXDI9GAph/cp5lIvC9uN1XuFiQ7YvPb3YGfND2i2zw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-357f59f76e6so6917175ab.0 for ; Fri, 27 Oct 2023 10:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1698428214; x=1699033014; darn=sourceware.org; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QtX/v+XCDTJ/YylZ9Aw3Ekfy6NknKuTqplhjgh28Hq8=; b=KgsF7qHZ9nba2F16v7BbRbW5htcpOKz61ePMX4WaqrTBFdgph+eo2hDaxieG+B2vHK p26spWjUSJtixlBrhzQGNgD6XVkqEdsh3y62nst69vOd/25JthiQrYKcTJnyTs6TD7LT lnGra4Esp/JVXZ0Nmnb+ghLJHNlyPz19mbXWBuSpmKLM/pv4Ouj04OtEMhF0jP6NtlRk YNbiYobDkVsbWDKIukwRh7OfATuT4Ea/e5a288pEAzdgAyxET9oWHoQHszD3UlUKmDxC wjwPq8B3bcKA6N1LOZpD03lCurjbkvXdaKNaCnLmtHhsgpgIoLZwsh6HSi2CNZb97Uyl wx+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698428214; x=1699033014; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QtX/v+XCDTJ/YylZ9Aw3Ekfy6NknKuTqplhjgh28Hq8=; b=qVAmc8Wjzrf52xqd8T+34Oyp7tza67AzbDGuOX9hAZRauneWwN2MfSd+vdf2TRLiCH LHpvH4a91f6I9TA7DpQzKZmNYrq2/dnQYomDWsNOMQ4E8Ev20jh/WGI3/5GXgR+qDynn +Hb5d8bUygHDaz3Vwd4LfcwvuzXmuzbkWwqr5kpeLyjVS5ec4lCXl4dZrYvdbERyt4Du E83O0GMvHIuCpUo+8mslnQ4LI+nF5Zg6vjLvsbxm6AksIzHsB5/FbBedAFEusfdBp0UB bqzh4Tbp1Csu8ZvF8PRluEHFC21pVI9hWTCejjG0BIIPRH1SLbdooh1+iQZhuZuab4XW OCrw== X-Gm-Message-State: AOJu0YzlJTFxIv8l+EI10BaEZLmJYVVTZtCizY5KH0ncGzLajcJ6S5uL j5OYMC+AoHLCvF9SddU0eOc6YqrMnpxjYgRZgXADLQ== X-Google-Smtp-Source: AGHT+IF+bHCcKX+LZm6yjexuQYCt+00B4fdeOnZNw+ODfWv+pq0uD2b9ho0XCSPS+6ejfnSWNaCozA== X-Received: by 2002:a92:cda5:0:b0:357:f41c:8bf6 with SMTP id g5-20020a92cda5000000b00357f41c8bf6mr4655538ild.17.1698428213781; Fri, 27 Oct 2023 10:36:53 -0700 (PDT) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id r4-20020a92ce84000000b00357ce043118sm591754ilo.79.2023.10.27.10.36.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 10:36:53 -0700 (PDT) From: Tom Tromey Date: Fri, 27 Oct 2023 11:36:46 -0600 Subject: [PATCH v2 6/9] Remove some type field accessor macros MIME-Version: 1.0 Message-Id: <20231027-field-bits-v2-6-cbec64f2136a@adacore.com> References: <20231027-field-bits-v2-0-cbec64f2136a@adacore.com> In-Reply-To: <20231027-field-bits-v2-0-cbec64f2136a@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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. --- 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 b32f1e506d1..b981be89b18 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 241fbca49b7..4a0c6950b0c 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 543cd585eb2..f3bc0731c99 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).get_accessibility () == acc) + --index; + ++type_index; } --type_index; diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index ac27e83618b..a59d77b76a9 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 820a761054a..a803c786d2b 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 68a210faca4..10fea9f74fa 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -5228,31 +5228,32 @@ 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 a4d2f3fa3e6..ec27ca3b47a 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 41058a8b59e..b5d66269d6e 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 fb9386293a6..05601622560 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);