From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id C904A39A402B for ; Wed, 5 May 2021 08:20:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C904A39A402B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=derodat@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id AA5D9561F0; Wed, 5 May 2021 04:20:05 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8PBJuarvMLZB; Wed, 5 May 2021 04:20:05 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 872761174DE; Wed, 5 May 2021 04:20:05 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 8682A103; Wed, 5 May 2021 04:20:05 -0400 (EDT) Date: Wed, 5 May 2021 04:20:05 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Refine types of variables with call to Scope as their initial values Message-ID: <20210505082005.GA31394@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2fHTh5uZTiUOsy+g" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Wed, 05 May 2021 08:20:16 -0000 --2fHTh5uZTiUOsy+g Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Call to Scope returns an Entity_Id, not just Node_Id. This patch refines the types in two occurrences of a call to Scope as an initial value. Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (User_Defined_Primitive_Equality_Op): Refine type of a local variable. * exp_dbug.adb (Scope_Contains): Refine all types from Node_Id to Entity_Id; rename parameters to match those of the Scope_Within routine (which is similar but not the same); also, simplify an OR ELSE into a membership test. --2fHTh5uZTiUOsy+g Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -8082,7 +8082,7 @@ package body Exp_Ch4 is function User_Defined_Primitive_Equality_Op (Typ : Entity_Id) return Entity_Id is - Enclosing_Scope : constant Node_Id := Scope (Typ); + Enclosing_Scope : constant Entity_Id := Scope (Typ); E : Entity_Id; begin for Private_Entities in Boolean loop diff --git a/gcc/ada/exp_dbug.adb b/gcc/ada/exp_dbug.adb --- a/gcc/ada/exp_dbug.adb +++ b/gcc/ada/exp_dbug.adb @@ -315,8 +315,11 @@ package body Exp_Dbug is -- output in one of these two forms. The result is prepended to the -- name stored in Name_Buffer. - function Scope_Contains (Sc : Node_Id; Ent : Entity_Id) return Boolean; - -- Return whether Ent belong to the Sc scope + function Scope_Contains + (Outer : Entity_Id; + Inner : Entity_Id) + return Boolean; + -- Return whether Inner belongs to the Outer scope ---------------------------- -- Enable_If_Packed_Array -- @@ -344,8 +347,7 @@ package body Exp_Dbug is elsif Nkind (N) = N_Identifier and then Scope_Contains (Scope (Entity (N)), Ent) - and then (Ekind (Entity (N)) = E_Constant - or else Ekind (Entity (N)) = E_In_Parameter) + and then Ekind (Entity (N)) in E_Constant | E_In_Parameter then Prepend_String_To_Buffer (Get_Name_String (Chars (Entity (N)))); @@ -361,12 +363,16 @@ package body Exp_Dbug is -- Scope_Contains -- -------------------- - function Scope_Contains (Sc : Node_Id; Ent : Entity_Id) return Boolean is - Cur : Node_Id := Scope (Ent); + function Scope_Contains + (Outer : Entity_Id; + Inner : Entity_Id) + return Boolean + is + Cur : Entity_Id := Scope (Inner); begin while Present (Cur) loop - if Cur = Sc then + if Cur = Outer then return True; end if; --2fHTh5uZTiUOsy+g--