]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Add support for Unreferenced aspect on formal parameters
authorArnaud Charlet <charlet@adacore.com>
Tue, 21 Jul 2020 09:45:31 +0000 (05:45 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 20 Oct 2020 07:21:51 +0000 (03:21 -0400)
gcc/ada/

* aspects.adb (Has_Aspect_Specifications_Flag): Add
N_Parameter_Specification.
* par-ch13.adb (Aspect_Specifications_Present): Also handle case
of an unknown aspect on the last formal parameter (terminated by
a Tok_Right_Paren). Minor reformatting.
* par-ch6.adb (P_Formal_Part): Scan aspects on formal
parameters.
* par.adb: Fix typos.
* sem_ch6.adb (Process_Formals): Add processing of aspects and
in particular Unreferenced aspect for now.
* sinfo.ads: Allow ASPECT_SPECIFICATIONS on a
PARAMETER_SPECIFICATION.
* doc/gnat_rm/implementation_defined_aspects.rst
(Aspect Unreferenced): Update documentation.
* gnat_rm.texi: Regenerate.

gcc/ada/aspects.adb
gcc/ada/doc/gnat_rm/implementation_defined_aspects.rst
gcc/ada/gnat_rm.texi
gcc/ada/par-ch13.adb
gcc/ada/par-ch6.adb
gcc/ada/par.adb
gcc/ada/sem_ch6.adb
gcc/ada/sinfo.ads

index c222c33efe07ebdd2b6efc44080bda01a5b0fd5b..0c5a3cf58c6bf269ed7091ea98194145687551da 100644 (file)
@@ -455,6 +455,7 @@ package body Aspects is
       N_Package_Instantiation                  => True,
       N_Package_Specification                  => True,
       N_Package_Renaming_Declaration           => True,
+      N_Parameter_Specification                => True,
       N_Private_Extension_Declaration          => True,
       N_Private_Type_Declaration               => True,
       N_Procedure_Instantiation                => True,
index 736710d11d6c7560d6a454a9fdcf2508887dd7a2..de5efea5385283312842a706dc1903dc4d7941ab 100644 (file)
@@ -564,9 +564,11 @@ Aspect Unreferenced
 ===================
 .. index:: Unreferenced
 
-This boolean aspect is equivalent to :ref:`pragma Unreferenced<Pragma-Unreferenced>`. Note that
-in the case of formal parameters, it is not permitted to have aspects for
-a formal parameter, so in this case the pragma form must be used.
+This boolean aspect is equivalent to :ref:`pragma Unreferenced<Pragma-Unreferenced>`.
+
+When using the ``-gnatX`` switch, this aspect is also supported on formal
+parameters, which is in particular the only form possible for expression
+functions.
 
 Aspect Unreferenced_Objects
 ===========================
index 33a696a4a46e872027df4466af6640d612e1f38a..da262f1f4ab6394e0f3503119a4b9c26c2155e91 100644 (file)
@@ -9923,9 +9923,11 @@ This boolean aspect is equivalent to @ref{10b,,pragma Unmodified}.
 
 @geindex Unreferenced
 
-This boolean aspect is equivalent to @ref{10c,,pragma Unreferenced}. Note that
-in the case of formal parameters, it is not permitted to have aspects for
-a formal parameter, so in this case the pragma form must be used.
+This boolean aspect is equivalent to @ref{10c,,pragma Unreferenced}.
+
+When using the @code{-gnatX} switch, this aspect is also supported on formal
+parameters, which is in particular the only form possible for expression
+functions.
 
 @node Aspect Unreferenced_Objects,Aspect Value_Size,Aspect Unreferenced,Implementation Defined Aspects
 @anchor{gnat_rm/implementation_defined_aspects aspect-unreferenced-objects}@anchor{15e}
index 459d7fe0701270ecc4413b6f18783b1ff3da6128..95223a1a354d56515462a33491c20773d290ddb9 100644 (file)
@@ -153,7 +153,8 @@ package body Ch13 is
             Result := True;
          else
             Scan; -- past identifier
-            Result := Token in Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon;
+            Result := Token in
+              Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon | Tok_Right_Paren;
          end if;
 
       --  If earlier than Ada 2012, check for valid aspect identifier (possibly
@@ -956,7 +957,7 @@ package body Ch13 is
          --  If Decl is Error, we ignore the aspects, and issue a message
 
          elsif Decl = Error
-            or else not Permits_Aspect_Specifications (Decl)
+           or else not Permits_Aspect_Specifications (Decl)
          then
             Error_Msg ("aspect specifications not allowed here", Ptr);
 
index 1ff79506b7b09a05c5fe77bb041758f460a14568..622a508b6cd8e603037325a61b524e54aa2f93b9 100644 (file)
@@ -1627,6 +1627,25 @@ package body Ch6 is
             Scan; -- past right paren
             exit Specification_Loop;
 
+         --  Support for aspects on formal parameters is a GNAT extension for
+         --  the time being.
+
+         elsif Token = Tok_With then
+            if not Extensions_Allowed then
+               Error_Msg_SP ("aspect on formal parameter requires -gnatX");
+            end if;
+
+            P_Aspect_Specifications (Specification_Node, False);
+
+            if Token = Tok_Right_Paren then
+               Scan;  -- past right paren
+               exit Specification_Loop;
+
+            elsif Token = Tok_Semicolon then
+               Save_Scan_State (Scan_State);
+               Scan; -- past semicolon
+            end if;
+
          --  Special check for common error of using comma instead of semicolon
 
          elsif Token = Tok_Comma then
index 69da69d07be2803c25402cfcc957c64d57ba06a1..4c3a1549988a27e145e4e08201a04cc5252eb84b 100644 (file)
@@ -995,10 +995,10 @@ function Par (Configuration_Pragmas : Boolean) return List_Id is
       procedure P_Aspect_Specifications
         (Decl      : Node_Id;
          Semicolon : Boolean := True);
-      --  This procedure scans out a series of aspect spefications. If argument
-      --  Semicolon is True, a terminating semicolon is also scanned. If this
-      --  argument is False, the scan pointer is left pointing past the aspects
-      --  and the caller must check for a proper terminator.
+      --  This procedure scans out a series of aspect specifications. If
+      --  argument Semicolon is True, a terminating semicolon is also scanned.
+      --  If this argument is False, the scan pointer is left pointing past the
+      --  aspects and the caller must check for a proper terminator.
       --
       --  P_Aspect_Specifications is called with the current token pointing
       --  to either a WITH keyword starting an aspect specification, or an
index 215c4ada782f067552c686f62998fd6256070f55..8bf5889a05aa39a781c1b03410127e2d1500de20 100644 (file)
@@ -672,9 +672,9 @@ package body Sem_Ch6 is
       end if;
    end Analyze_Expression_Function;
 
-   ----------------------------------------
-   -- Analyze_Extended_Return_Statement  --
-   ----------------------------------------
+   ---------------------------------------
+   -- Analyze_Extended_Return_Statement --
+   ---------------------------------------
 
    procedure Analyze_Extended_Return_Statement (N : Node_Id) is
    begin
@@ -12282,6 +12282,27 @@ package body Sem_Ch6 is
             end if;
          end if;
 
+         --  Deal with aspects on formal parameters. Only Unreferenced is
+         --  supported for the time being.
+
+         if Has_Aspects (Param_Spec) then
+            declare
+               Aspect : Node_Id := First (Aspect_Specifications (Param_Spec));
+            begin
+               while Present (Aspect) loop
+                  if Chars (Identifier (Aspect)) = Name_Unreferenced then
+                     Set_Has_Pragma_Unreferenced (Formal);
+                  else
+                     Error_Msg_NE
+                       ("unsupported aspect& on parameter",
+                        Aspect, Identifier (Aspect));
+                  end if;
+
+                  Next (Aspect);
+               end loop;
+            end;
+         end if;
+
       <<Continue>>
          Next (Param_Spec);
       end loop;
index 231ebb586abb247c578a5a0f1c3768cb629e99cb..4f0a41f01b1f32f84740e6dc52129fbfbdb49018 100644 (file)
@@ -5414,9 +5414,9 @@ package Sinfo is
 
       --  PARAMETER_SPECIFICATION ::=
       --    DEFINING_IDENTIFIER_LIST : [ALIASED] MODE [NULL_EXCLUSION]
-      --      SUBTYPE_MARK [:= DEFAULT_EXPRESSION]
+      --      SUBTYPE_MARK [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATIONS]
       --  | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
-      --      [:= DEFAULT_EXPRESSION]
+      --      [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATIONS]
 
       --  Although the syntax allows multiple identifiers in the list, the
       --  semantics is as though successive specifications were given with