From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 8CFD43858D28; Fri, 7 Jan 2022 16:26:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CFD43858D28 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6345] [Ada] Add an option to Get_Fullest_View to not recurse X-Act-Checkin: gcc X-Git-Author: Richard Kenner X-Git-Refname: refs/heads/master X-Git-Oldrev: 0c65ca0625b426863ecd294eb9945513a6d057bc X-Git-Newrev: 1226283cd9ec5c1a916ed219895ffe11b89ea9c0 Message-Id: <20220107162658.8CFD43858D28@sourceware.org> Date: Fri, 7 Jan 2022 16:26:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jan 2022 16:26:58 -0000 https://gcc.gnu.org/g:1226283cd9ec5c1a916ed219895ffe11b89ea9c0 commit r12-6345-g1226283cd9ec5c1a916ed219895ffe11b89ea9c0 Author: Richard Kenner Date: Wed Dec 8 17:11:00 2021 -0500 [Ada] Add an option to Get_Fullest_View to not recurse gcc/ada/ * sem_util.ads, sem_util.adb (Get_Fullest_View): Add option to not recurse and return the next-most-fullest view. Diff: --- gcc/ada/sem_util.adb | 47 +++++++++++++++++++++++++++-------------------- gcc/ada/sem_util.ads | 7 +++++-- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 48f4bfb7d92..2e2ac247047 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -10926,7 +10926,12 @@ package body Sem_Util is ---------------------- function Get_Fullest_View - (E : Entity_Id; Include_PAT : Boolean := True) return Entity_Id is + (E : Entity_Id; + Include_PAT : Boolean := True; + Recurse : Boolean := True) return Entity_Id + is + New_E : Entity_Id := Empty; + begin -- Prevent cascaded errors @@ -10934,47 +10939,45 @@ package body Sem_Util is return E; end if; - -- Strictly speaking, the recursion below isn't necessary, but - -- it's both simplest and safest. + -- Look at each kind of entity to see where we may need to go deeper. case Ekind (E) is when Incomplete_Kind => if From_Limited_With (E) then - return Get_Fullest_View (Non_Limited_View (E), Include_PAT); + New_E := Non_Limited_View (E); elsif Present (Full_View (E)) then - return Get_Fullest_View (Full_View (E), Include_PAT); + New_E := Full_View (E); elsif Ekind (E) = E_Incomplete_Subtype then - return Get_Fullest_View (Etype (E)); + New_E := Etype (E); end if; when Private_Kind => if Present (Underlying_Full_View (E)) then - return - Get_Fullest_View (Underlying_Full_View (E), Include_PAT); + New_E := Underlying_Full_View (E); elsif Present (Full_View (E)) then - return Get_Fullest_View (Full_View (E), Include_PAT); + New_E := Full_View (E); elsif Etype (E) /= E then - return Get_Fullest_View (Etype (E), Include_PAT); + New_E := Etype (E); end if; when Array_Kind => if Include_PAT and then Present (Packed_Array_Impl_Type (E)) then - return Get_Fullest_View (Packed_Array_Impl_Type (E)); + New_E := Packed_Array_Impl_Type (E); end if; when E_Record_Subtype => if Present (Cloned_Subtype (E)) then - return Get_Fullest_View (Cloned_Subtype (E), Include_PAT); + New_E := Cloned_Subtype (E); end if; when E_Class_Wide_Type => - return Get_Fullest_View (Root_Type (E), Include_PAT); + New_E := Root_Type (E); when E_Class_Wide_Subtype => if Present (Equivalent_Type (E)) then - return Get_Fullest_View (Equivalent_Type (E), Include_PAT); + New_E := Equivalent_Type (E); elsif Present (Cloned_Subtype (E)) then - return Get_Fullest_View (Cloned_Subtype (E), Include_PAT); + New_E := Cloned_Subtype (E); end if; when E_Protected_Subtype @@ -10983,25 +10986,29 @@ package body Sem_Util is | E_Task_Type => if Present (Corresponding_Record_Type (E)) then - return Get_Fullest_View (Corresponding_Record_Type (E), - Include_PAT); + New_E := Corresponding_Record_Type (E); end if; when E_Access_Protected_Subprogram_Type | E_Anonymous_Access_Protected_Subprogram_Type => if Present (Equivalent_Type (E)) then - return Get_Fullest_View (Equivalent_Type (E), Include_PAT); + New_E := Equivalent_Type (E); end if; when E_Access_Subtype => - return Get_Fullest_View (Base_Type (E), Include_PAT); + New_E := Base_Type (E); when others => null; end case; - return E; + -- If we found a fuller view, either return it or recurse. Otherwise, + -- return our input. + + return (if No (New_E) then E + elsif Recurse then Get_Fullest_View (New_E, Include_PAT, Recurse) + else New_E); end Get_Fullest_View; ------------------------ diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index 5ef0a228abe..0006cf9ac51 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -1354,10 +1354,13 @@ package Sem_Util is -- CRec_Typ - the corresponding record type of the full views function Get_Fullest_View - (E : Entity_Id; Include_PAT : Boolean := True) return Entity_Id; + (E : Entity_Id; + Include_PAT : Boolean := True; + Recurse : Boolean := True) return Entity_Id; -- Get the fullest possible view of E, looking through private, limited, -- packed array and other implementation types. If Include_PAT is False, - -- don't look inside packed array types. + -- don't look inside packed array types. If Recurse is False, just + -- go down one level (so it's no longer the "fullest" view). function Has_Access_Values (T : Entity_Id) return Boolean; -- Returns true if the underlying type of T is an access type, or has a