From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id AB8F33851160 for ; Mon, 4 Jul 2022 07:50:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AB8F33851160 Received: by mail-ed1-x531.google.com with SMTP id g1so2986819edb.12 for ; Mon, 04 Jul 2022 00:50:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=U9RMRHV+MT69KwcIpmy1TIkS4xe+twCse2E7g+F0yWo=; b=ILvfiPsCpqL1e+A6TYpDKvE88wtcwXZGJ3QRsF9eywpxE+Z9tUAcQCJlHKwglIVUaI 6pN2zjt78Ap1HiF+C/3OSHvv7r0En1yfkeo+vxK/XhPR/CBOxfGXIDuCRsauKcCj/LWo I3yGPyqUDihkEvSD53Z4xtcoBmEcVnoRk8ysasJsaUrjIlLCeKUW2l6TjqDPIf//o9oz MZ+rTaZWPLbPWbddJb80vWy6YHKwgvFkHJ1zHZuZIiTNqP52G8ZbiOc0NRGCi36Rxzo7 TLAsl4Lpa0AzHsg2L6kKSmaTsGgdUu/W/okFosvMIfaMNM+kGLRRD1lcdeietnp0/DC2 Frlw== X-Gm-Message-State: AJIora8TMUiadSykwQwdFYN9wZIxiytDOLTTX3QYhWFWaQC2edVRHkR9 GgOMf5ZZr+qmiorqi53ktwyWtkBaPjN8jg== X-Google-Smtp-Source: AGRyM1viAy84aF45xxUv0YnCd5QERPxbz2sSZKoQPUzYRc6IWXevA86t8RKWvDbkrNI2XfdbtF1EZQ== X-Received: by 2002:a05:6402:2552:b0:435:9e1c:ca49 with SMTP id l18-20020a056402255200b004359e1cca49mr37107439edb.126.1656921026450; Mon, 04 Jul 2022 00:50:26 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id b9-20020aa7dc09000000b00437938c731fsm14188395edu.97.2022.07.04.00.50.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:50:25 -0700 (PDT) Date: Mon, 4 Jul 2022 07:50:25 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Refactor duplicated resolution of Count and Index attributes Message-ID: <20220704075025.GA99329@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="EVF5PPMfhYS0aIcm" Content-Disposition: inline X-Spam-Status: No, score=-13.2 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 07:50:29 -0000 --EVF5PPMfhYS0aIcm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Attribute Index, which was added to Ada 2022 by AI12-0143, is resolved just like attribute Count. However, code duplication rightly triggered a CodePeer warning. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_attr.adb (Resolve_Attribute): Refactor duplicated code for Count and Index attributes. --EVF5PPMfhYS0aIcm Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -12300,7 +12300,9 @@ package body Sem_Attr is -- if it is an element of an entry family, the index itself may -- have to be resolved because it can be a general expression. - when Attribute_Count => + when Attribute_Count + | Attribute_Index + => if Nkind (P) = N_Indexed_Component and then Is_Entity_Name (Prefix (P)) then @@ -12338,19 +12340,7 @@ package body Sem_Attr is -- Index -- ----------- - when Attribute_Index => - if Nkind (P) = N_Indexed_Component - and then Is_Entity_Name (Prefix (P)) - then - declare - Indx : constant Node_Id := First (Expressions (P)); - Fam : constant Entity_Id := Entity (Prefix (P)); - - begin - Resolve (Indx, Entry_Index_Type (Fam)); - Apply_Scalar_Range_Check (Indx, Entry_Index_Type (Fam)); - end; - end if; + -- Processing is shared with Count ---------------- -- Loop_Entry -- --EVF5PPMfhYS0aIcm--