einfo.adb (Spec_PPC): Now defined for generic subprograms
authorRobert Dewar <dewar@adacore.com>
Thu, 31 Jul 2008 09:42:14 +0000 (11:42 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Thu, 31 Jul 2008 09:42:14 +0000 (11:42 +0200)
2008-07-31  Robert Dewar  <dewar@adacore.com>

* 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

gcc/ada/einfo.adb
gcc/ada/einfo.ads
gcc/ada/sem_prag.adb

index 01d384e..255b7a0 100644 (file)
@@ -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;
 
index 8316a68..c7182db 100644 (file)
@@ -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)
index a7cce6f..3183ce2 100644 (file)
@@ -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