===================================================================
@@ -19217,10 +19217,6 @@
Check_No_Identifiers;
Check_At_Most_N_Arguments (1);
- if Inside_A_Generic then
- Error_Pragma ("incorrect placement of pragma% in a generic");
- end if;
-
-- Check the legality of the mode (no argument = ON)
if Arg_Count = 1 then
@@ -19233,9 +19229,15 @@
Mode_Id := Get_SPARK_Mode_Type (Mode);
Context := Parent (N);
+ -- Packages and subprograms declared in a generic unit cannot be
+ -- subject to the pragma.
+
+ if Inside_A_Generic then
+ Error_Pragma ("incorrect placement of pragma% in a generic");
+
-- The pragma appears in a configuration pragmas file
- if No (Context) then
+ elsif No (Context) then
Check_Valid_Configuration_Pragma;
if Present (SPARK_Mode_Pragma) then
@@ -19258,8 +19260,7 @@
and then Nkind (Unit (Library_Unit (Context))) in
N_Generic_Declaration)
then
- Error_Pragma
- ("incorrect placement of pragma% in a generic unit");
+ Error_Pragma ("incorrect placement of pragma% in a generic");
end if;
SPARK_Mode_Pragma := N;
===================================================================
@@ -3118,6 +3118,8 @@
Set_Parent_Spec (New_N, Save_Parent);
Rewrite (N, New_N);
+ Check_SPARK_Mode_In_Generic (N);
+
-- The aspect specifications are not attached to the tree, and must
-- be copied and attached to the generic copy explicitly.
===================================================================
@@ -23,6 +23,7 @@
-- --
------------------------------------------------------------------------------
+with Aspects; use Aspects;
with Atree; use Atree;
with Casing; use Casing;
with Checks; use Checks;
@@ -2699,6 +2700,31 @@
end if;
end Check_Result_And_Post_State;
+ ---------------------------------
+ -- Check_SPARK_Mode_In_Generic --
+ ---------------------------------
+
+ procedure Check_SPARK_Mode_In_Generic (N : Node_Id) is
+ Aspect : Node_Id;
+
+ begin
+ -- Try to find aspect SPARK_Mode and flag it as illegal
+
+ if Has_Aspects (N) then
+ Aspect := First (Aspect_Specifications (N));
+ while Present (Aspect) loop
+ if Get_Aspect_Id (Aspect) = Aspect_SPARK_Mode then
+ Error_Msg_Name_1 := Name_SPARK_Mode;
+ Error_Msg_N
+ ("incorrect placement of aspect % on a generic", Aspect);
+ exit;
+ end if;
+
+ Next (Aspect);
+ end loop;
+ end if;
+ end Check_SPARK_Mode_In_Generic;
+
------------------------------
-- Check_Unprotected_Access --
------------------------------
===================================================================
@@ -62,6 +62,7 @@
-- Precondition
-- Refined_Depends
-- Refined_Global
+ -- Refined_Post
-- Refined_States
-- Test_Case
@@ -289,6 +290,10 @@
-- and post-state. Prag is a [refined] postcondition or a contract-cases
-- pragma. Result_Seen is set when the pragma mentions attribute 'Result.
+ procedure Check_SPARK_Mode_In_Generic (N : Node_Id);
+ -- Given a generic package [body] or a generic subprogram [body], inspect
+ -- the aspect specifications (if any) and flag SPARK_Mode as illegal.
+
procedure Check_Unprotected_Access
(Context : Node_Id;
Expr : Node_Id);
===================================================================
@@ -1193,6 +1193,8 @@
end loop;
end;
+ Check_SPARK_Mode_In_Generic (N);
+
Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
Set_SPARK_Pragma_Inherited (Body_Id, True);