From patchwork Wed Jun 7 15:41:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 70741 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 6AA693857734 for ; Wed, 7 Jun 2023 15:41:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AA693857734 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1686152514; bh=RgnmXmAkfr2tP9r4z3t9ovyPOhY9qYBzHIxD6EjfFsU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=t6AtC8EFhedY3536yqKcXbXwO9/xlmr6i8FCqHpj4upIVLhki2a4xFKYdD0pfYYRb VlqgjUAFWqVhOTr1nhclaBbH0bEnUIys1YYWvFj6Dp1rE1kglq0gNWoGKHlZAm+42l aWhvyJUKJuTO8J+POgrwj08nmsYmeWA2K31TfE+E= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 838343858C54 for ; Wed, 7 Jun 2023 15:41:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 838343858C54 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-777b922466dso134486739f.3 for ; Wed, 07 Jun 2023 08:41:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686152490; x=1688744490; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RgnmXmAkfr2tP9r4z3t9ovyPOhY9qYBzHIxD6EjfFsU=; b=QgzUI5+7UEW1VDw/FN7ZHr8AQQ4gNqgMvjF4nGmubZUlWPbFNVZoc6kS6KRcQMtEjh VcS50rDDikPK+Desg8IuFInH70uWQRJYdwA3c1G7Sm0oy7lp4EVIyPtt6KqRS3h6tknS +c9TvJG0D/QuAz4R7EAiXZhTqv1uRfPdVHNfoW64Lxp+GdbpvrRntUQ9AQxFxC1utWkH rTAuLU7nja56MyE5EiovdYO3mj3p1yHYeLcAPB2mpT7qmMNjwIp0Eq1OC/zzYhfXSK+f o6aWzZj7nYMISduLxzaD0p3JGaqcnz+hO7cOdCnJSlpprjxxZq/DsOifkeLymuZVlfr4 lJqg== X-Gm-Message-State: AC+VfDzBPOzFBfycBXNIc7TlsVb9R5u1r63IczJmHVVb0A8Olgp/fcEx qev2vGGY2Izpnl2gr7KquAU4a2awOoG1LDOXvJhqEA== X-Google-Smtp-Source: ACHHUZ7oVPEKna86LDan5s2uNo//PUmMhfV6nl7FTyC6UPz6eyQcTbuw3ip9n0+a7567aMZwI3sieA== X-Received: by 2002:a6b:6102:0:b0:777:b531:eb56 with SMTP id v2-20020a6b6102000000b00777b531eb56mr4735978iob.7.1686152490684; Wed, 07 Jun 2023 08:41:30 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id z3-20020a029f03000000b0040f94261ab1sm3655147jal.12.2023.06.07.08.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 08:41:30 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed] Simplify ada_lookup_struct_elt_type Date: Wed, 7 Jun 2023 09:41:23 -0600 Message-Id: <20230607154123.1266562-1-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This patch simplifies ada_lookup_struct_elt_type by changing it to call find_struct_field. The two functions were substantially similar, even to the point of having identical comments. I tested this using both the gdb test suite and the internal AdaCore test suite. Given this and the fact that it is Ada-specific, I am checking it in. --- gdb/ada-lang.c | 83 +++----------------------------------------------- 1 file changed, 5 insertions(+), 78 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 3c86c31817f..667ef2a60e9 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -7267,9 +7267,6 @@ type_as_string (struct type *type) } /* Given a type TYPE, look up the type of the component of type named NAME. - If DISPP is non-null, add its byte displacement from the beginning of a - structure (pointed to by a value) of type TYPE to *DISPP (does not - work for packed fields). Matches any field whose name has NAME as a prefix, possibly followed by "___". @@ -7290,9 +7287,6 @@ static struct type * ada_lookup_struct_elt_type (struct type *type, const char *name, int refok, int noerr) { - int i; - int parent_offset = -1; - if (name == NULL) goto BadName; @@ -7318,78 +7312,11 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok, type = to_static_fixed_type (type); - for (i = 0; i < type->num_fields (); i += 1) - { - const char *t_field_name = type->field (i).name (); - struct type *t; - - if (t_field_name == NULL) - continue; - - else if (ada_is_parent_field (type, i)) - { - /* This is a field pointing us to the parent type of a tagged - type. As hinted in this function's documentation, we give - preference to fields in the current record first, so what - we do here is just record the index of this field before - we skip it. If it turns out we couldn't find our field - in the current record, then we'll get back to it and search - inside it whether the field might exist in the parent. */ - - parent_offset = i; - continue; - } - - else if (field_name_match (t_field_name, name)) - return type->field (i).type (); - - else if (ada_is_wrapper_field (type, i)) - { - t = ada_lookup_struct_elt_type (type->field (i).type (), name, - 0, 1); - if (t != NULL) - return t; - } - - else if (ada_is_variant_part (type, i)) - { - int j; - struct type *field_type = ada_check_typedef (type->field (i).type ()); - - for (j = field_type->num_fields () - 1; j >= 0; j -= 1) - { - /* FIXME pnh 2008/01/26: We check for a field that is - NOT wrapped in a struct, since the compiler sometimes - generates these for unchecked variant types. Revisit - if the compiler changes this practice. */ - const char *v_field_name = field_type->field (j).name (); - - if (v_field_name != NULL - && field_name_match (v_field_name, name)) - t = field_type->field (j).type (); - else - t = ada_lookup_struct_elt_type (field_type->field (j).type (), - name, 0, 1); - - if (t != NULL) - return t; - } - } - - } - - /* Field not found so far. If this is a tagged type which - has a parent, try finding that field in the parent now. */ - - if (parent_offset != -1) - { - struct type *t; - - t = ada_lookup_struct_elt_type (type->field (parent_offset).type (), - name, 0, 1); - if (t != NULL) - return t; - } + struct type *result; + find_struct_field (name, type, 0, &result, nullptr, nullptr, nullptr, + nullptr); + if (result != nullptr) + return result; BadName: if (!noerr)