From 4322f3d99b7e5875de59c04939c4a4def1ffde5c Mon Sep 17 00:00:00 2001 From: Javier Miranda Date: Tue, 3 Mar 2020 14:27:18 -0500 Subject: [PATCH] [Ada] Classwide controlled obj not dispatching 2020-06-10 Javier Miranda gcc/ada/ * sem_ch3.adb (Analyze_Declarations): Adjust the machinery that takes care of late body overriding of initialize, adjust, finalize. Remove ASIS mode code. --- gcc/ada/sem_ch3.adb | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 83393c8..4cddbbe 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -2592,12 +2592,10 @@ package body Sem_Ch3 is -- Local variables Context : Node_Id := Empty; + Ctrl_Typ : Entity_Id := Empty; Freeze_From : Entity_Id := Empty; Next_Decl : Node_Id; - Body_Seen : Boolean := False; - -- Flag set when the first body [stub] is encountered - -- Start of processing for Analyze_Declarations begin @@ -2613,6 +2611,16 @@ package body Sem_Ch3 is Freeze_From := First_Entity (Current_Scope); end if; + -- Remember if the declaration we just processed is the full type + -- declaration of a controlled type (to handle late overriding of + -- initialize, adjust or finalize). + + if Nkind (Decl) = N_Full_Type_Declaration + and then Is_Controlled (Defining_Identifier (Decl)) + then + Ctrl_Typ := Defining_Identifier (Decl); + end if; + -- At the end of a declarative part, freeze remaining entities -- declared in it. The end of the visible declarations of package -- specification is not the end of a declarative part if private @@ -2758,19 +2766,17 @@ package body Sem_Ch3 is -- ??? A cleaner approach may be possible and/or this solution -- could be extended to general-purpose late primitives, TBD. - if not Body_Seen and then not Is_Body (Decl) then - Body_Seen := True; + if Present (Ctrl_Typ) then - if Nkind (Next_Decl) = N_Subprogram_Body then - Handle_Late_Controlled_Primitive (Next_Decl); - end if; + -- No need to continue searching for late body overriding if + -- the controlled type is already frozen. - else - -- In ASIS mode, if the next declaration is a body, complete - -- the analysis of declarations so far. - -- Is this still needed??? + if Is_Frozen (Ctrl_Typ) then + Ctrl_Typ := Empty; - Resolve_Aspects; + elsif Nkind (Next_Decl) = N_Subprogram_Body then + Handle_Late_Controlled_Primitive (Next_Decl); + end if; end if; Adjust_Decl; -- 2.7.4