From: Robert Dewar Date: Thu, 31 Jul 2008 09:42:14 +0000 (+0200) Subject: einfo.adb (Spec_PPC): Now defined for generic subprograms X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=393e63ce0f939555c88554d773f9798f07a2a898;p=gcc.git einfo.adb (Spec_PPC): Now defined for generic subprograms 2008-07-31 Robert Dewar * einfo.adb (Spec_PPC): Now defined for generic subprograms * einfo.ads (Spec_PPC): Now defined for generic subprograms * sem_prag.adb (Check_Precondition_Postcondition): Handle generic subprogram case From-SVN: r138370 --- diff --git a/gcc/ada/einfo.adb b/gcc/ada/einfo.adb index 01d384ec4f6..255b7a0cdcc 100644 --- a/gcc/ada/einfo.adb +++ b/gcc/ada/einfo.adb @@ -2579,7 +2579,7 @@ package body Einfo is function Spec_PPC_List (Id : E) return N is begin - pragma Assert (Is_Subprogram (Id)); + pragma Assert (Is_Subprogram (Id) or else Is_Generic_Subprogram (Id)); return Node24 (Id); end Spec_PPC_List; @@ -5044,7 +5044,7 @@ package body Einfo is procedure Set_Spec_PPC_List (Id : E; V : N) is begin - pragma Assert (Is_Subprogram (Id)); + pragma Assert (Is_Subprogram (Id) or else Is_Generic_Subprogram (Id)); Set_Node24 (Id, V); end Set_Spec_PPC_List; diff --git a/gcc/ada/einfo.ads b/gcc/ada/einfo.ads index 8316a68018a..c7182dbe04f 100644 --- a/gcc/ada/einfo.ads +++ b/gcc/ada/einfo.ads @@ -3527,10 +3527,11 @@ package Einfo is -- the corresponding parameter entities in the spec. -- Spec_PPC_List (Node24) --- Present in subprogram entities. Points to a list of Precondition --- and Postcondition N_Pragma nodes for preconditions and postconditions --- declared in the spec. The last pragma encountered is at the head of --- this list, so it is in reverse order of textual appearance. +-- Present in subprogram and generic subprogram entities. Points to a +-- list of Precondition and Postcondition pragma nodes for preconditions +-- and postconditions declared in the spec. The last pragma encountered +-- is at the head of this list, so it is in reverse order of textual +-- appearance. -- Storage_Size_Variable (Node15) [implementation base type only] -- Present in access types and task type entities. This flag is set @@ -5277,7 +5278,7 @@ package Einfo is -- Generic_Renamings (Elist23) (for instance) -- Inner_Instances (Elist23) (for generic proc) -- Protection_Object (Node23) (for concurrent kind) - -- Spec_PPC_List (Node24) (non-generic case only) + -- Spec_PPC_List (Node24) -- Interface_Alias (Node25) -- Static_Initialization (Node26) (init_proc only) -- Overridden_Operation (Node26) diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb index a7cce6f2f09..3183ce27a01 100644 --- a/gcc/ada/sem_prag.adb +++ b/gcc/ada/sem_prag.adb @@ -1354,9 +1354,10 @@ package body Sem_Prag is PO : Node_Id; procedure Chain_PPC (PO : Node_Id); - -- PO is the N_Subprogram_Declaration node for the subprogram to - -- which the precondition/postcondition applies. This procedure - -- completes the processing for the pragma. + -- If PO is a subprogram declaration node (or a generic subprogram + -- declaration node), then the precondition/postcondition applies + -- to this subprogram and the processing for the pragma is completed. + -- Otherwise the pragma is misplaced. --------------- -- Chain_PPC -- @@ -1366,6 +1367,14 @@ package body Sem_Prag is S : Node_Id; begin + if not Nkind_In (PO, N_Subprogram_Declaration, + N_Generic_Subprogram_Declaration) + then + Pragma_Misplaced; + end if; + + -- Here if we have subprogram or generic subprogram declaration + S := Defining_Unit_Name (Specification (PO)); -- Analyze the pragma unless it appears within a package spec, @@ -1427,16 +1436,11 @@ package body Sem_Prag is elsif not Comes_From_Source (PO) then null; - -- Here if we hit a subprogram declaration + -- Only remaining possibility is subprogram declaration - elsif Nkind (PO) = N_Subprogram_Declaration then + else Chain_PPC (PO); return; - - -- If we encounter any other declaration moving back, misplaced - - else - Pragma_Misplaced; end if; end loop; @@ -1452,14 +1456,8 @@ package body Sem_Prag is -- See if it is in the pragmas after a library level subprogram elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then - declare - Decl : constant Node_Id := Unit (Parent (Parent (N))); - begin - if Nkind (Decl) = N_Subprogram_Declaration then - Chain_PPC (Decl); - return; - end if; - end; + Chain_PPC (Unit (Parent (Parent (N)))); + return; end if; -- If we fall through, pragma was misplaced