Patchwork [Ada] Fix bad semicolon msg in Ada 2012 mode

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 26, 2010, 12:56 p.m.
Message ID <20101026125652.GA8487@adacore.com>
Download mbox | patch
Permalink /patch/69244/
State New
Headers show

Comments

Arnaud Charlet - Oct. 26, 2010, 12:56 p.m.
This patch fixes over-enthusiastic detection of aspect specifications,
that was causing an incorrect disagnostic about an extra semicolon.
The following (in a single file) should compile clean with -gnats.

--  start file mcu2012.ads
pragma Ada_2012;
with Types; use Types;
package Sem_Ch11 is
end Sem_Ch11;
with Inline;
package Sem_Ch12 is
end Sem_Ch12;
-- end file mcu2012.ads

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-10-26  Robert Dewar  <dewar@adacore.com>

	* par.adb, par-ch13.adb (Aspect_Specifications_Present): Add Strict
	parameter.

Patch

Index: par-ch13.adb
===================================================================
--- par-ch13.adb	(revision 165935)
+++ par-ch13.adb	(working copy)
@@ -39,7 +39,9 @@  package body Ch13 is
    -- Aspect_Specifications_Present --
    -----------------------------------
 
-   function Aspect_Specifications_Present return Boolean is
+   function Aspect_Specifications_Present
+     (Strict : Boolean := Ada_Version < Ada_2012) return Boolean
+   is
       Scan_State : Saved_Scan_State;
       Result     : Boolean;
 
@@ -52,7 +54,12 @@  package body Ch13 is
       if Token = Tok_Semicolon then
          Scan; -- past semicolon
 
-         if Aspect_Specifications_Present then
+         --  The recursive test is set Strict, since we already have one
+         --  error (the unexpected semicolon), so we will ignore that semicolon
+         --  only if we absolutely definitely have an aspect specification
+         --  following it.
+
+         if Aspect_Specifications_Present (Strict => True) then
             Error_Msg_SP ("|extra "";"" ignored");
             return True;
 
@@ -79,13 +86,14 @@  package body Ch13 is
       if Token /= Tok_Identifier then
          Result := False;
 
-      --  In Ada 2012 mode, we are less strict, and we consider that we have
+      --  This is where we pay attention to the Strict mode. Normally when we
+      --  are in Ada 2012 mode, Strict is False, and we consider that we have
       --  an aspect specification if the identifier is an aspect name (even if
       --  not followed by =>) or the identifier is not an aspect name but is
       --  followed by =>. P_Aspect_Specifications will generate messages if the
       --  aspect specification is ill-formed.
 
-      elsif Ada_Version >= Ada_2012 then
+      elsif not Strict then
          if Get_Aspect_Id (Token_Name) /= No_Aspect then
             Result := True;
          else
Index: par.adb
===================================================================
--- par.adb	(revision 165935)
+++ par.adb	(working copy)
@@ -848,14 +848,21 @@  function Par (Configuration_Pragmas : Bo
    package Ch13 is
       function P_Representation_Clause                return Node_Id;
 
-      function Aspect_Specifications_Present return Boolean;
+      function Aspect_Specifications_Present
+        (Strict : Boolean := Ada_Version < Ada_2012) return Boolean;
       --  This function tests whether the next keyword is WITH followed by
       --  something that looks reasonably like an aspect specification. If so,
       --  True is returned. Otherwise False is returned. In either case control
       --  returns with the token pointer unchanged (i.e. pointing to the WITH
       --  token in the case where True is returned). This function takes care
       --  of generating appropriate messages if aspect specifications appear
-      --  in versions of Ada prior to Ada 2012.
+      --  in versions of Ada prior to Ada 2012. The parameter strict can be
+      --  set to True, to be rather strict about considering something to be
+      --  an aspect speficiation. If Strict is False, then the circuitry is
+      --  rather more generous in considering something ill-formed to be an
+      --  attempt at an aspect speciciation. The default is more strict for
+      --  Ada versions before Ada 2012 (where aspect specifications are not
+      --  permitted).
 
       procedure P_Aspect_Specifications (Decl : Node_Id);
       --  This subprogram is called with the current token pointing to either a