From: Piotr Trojanek <[email protected]>

Typically, the recently added Modifies contract for SPARK will appear as an
aspect, but we also allow it to appear as a pragma, just like we do for Global,
Depends and other SPARK contracts.

gcc/ada/ChangeLog:

        * par-ch13.adb (P_Modifies_Specification): Now public, so it can be
        reused when parsing a pragma.
        * par-ch2.adb (P_Pragma): Parse pragma Modifies with a custom syntax.
        * par-prag.adb (Prag): A ??? comment is now implemented.
        * par.adb (P_Modifies_Specification): Now public, so it can be reused.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/par-ch13.adb |  1 -
 gcc/ada/par-ch2.adb  | 20 +++++++++++++++-----
 gcc/ada/par-prag.adb |  2 +-
 gcc/ada/par.adb      |  4 ++++
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/par-ch13.adb b/gcc/ada/par-ch13.adb
index 1bca0b44b8a..b043cf509a8 100644
--- a/gcc/ada/par-ch13.adb
+++ b/gcc/ada/par-ch13.adb
@@ -36,7 +36,6 @@ package body Ch13 is
 
    function P_Component_Clause return Node_Id;
    function P_Mod_Clause return Node_Id;
-   function P_Modifies_Specification return Node_Id;
 
    -----------------------------------
    -- Aspect_Specifications_Present --
diff --git a/gcc/ada/par-ch2.adb b/gcc/ada/par-ch2.adb
index a83f145236b..e661dd7b821 100644
--- a/gcc/ada/par-ch2.adb
+++ b/gcc/ada/par-ch2.adb
@@ -403,11 +403,21 @@ package body Ch2 is
          loop
             Arg_Count := Arg_Count + 1;
 
-            Scan_Pragma_Argument_Association
-              (Identifier_Seen   => Identifier_Seen,
-               Association       => Assoc_Node,
-               Reserved_Words_OK =>
-                 Prag_Name in Name_Restriction_Warnings | Name_Restrictions);
+            --  Syntax of the Modifies contract requires custom parsing
+
+            if Chars (Ident_Node) = Name_Modifies then
+               Assoc_Node :=
+                 New_Node (N_Pragma_Argument_Association, Token_Ptr);
+               Set_Chars (Assoc_Node, No_Name);
+               Set_Expression (Assoc_Node, Ch13.P_Modifies_Specification);
+            else
+               Scan_Pragma_Argument_Association
+                 (Identifier_Seen   => Identifier_Seen,
+                  Association       => Assoc_Node,
+                  Reserved_Words_OK =>
+                    Prag_Name in Name_Restriction_Warnings
+                               | Name_Restrictions);
+            end if;
 
             if Arg_Count = 2 and then Import_Check_Required then
                --  Here is where we cancel the SIS active status if this pragma
diff --git a/gcc/ada/par-prag.adb b/gcc/ada/par-prag.adb
index f93f7b4da16..d73c5d8cce7 100644
--- a/gcc/ada/par-prag.adb
+++ b/gcc/ada/par-prag.adb
@@ -1507,7 +1507,7 @@ begin
          | Pragma_Max_Entry_Queue_Length
          | Pragma_Max_Queue_Length
          | Pragma_Memory_Size
-         | Pragma_Modifies  --  ??? this pragma needs custom parsing
+         | Pragma_Modifies
          | Pragma_No_Body
          | Pragma_No_Caching
          | Pragma_No_Component_Reordering
diff --git a/gcc/ada/par.adb b/gcc/ada/par.adb
index f776bfb9da6..27491e673f1 100644
--- a/gcc/ada/par.adb
+++ b/gcc/ada/par.adb
@@ -1086,6 +1086,10 @@ function Par (Configuration_Pragmas : Boolean) return 
List_Id is
       --  identifier or a selected component). The current token is an
       --  apostrophe and the following token is either a left paren or
       --  RANGE (the latter being an error to be caught by P_Code_Statement.
+
+      function P_Modifies_Specification return Node_Id;
+      --  Parse a Modifies contract specification, which is also allowed to
+      --  appear as a pragma for compatibility with old versions of Ada.
    end Ch13;
 
    --  Note: the parsing for annexe J features (i.e. obsolescent features)
-- 
2.53.0

Reply via email to