[Ada] Some is reserved in Ada 2012

Arnaud Charlet charlet@adacore.com
Mon Aug 29 11:06:00 GMT 2011


This patch makes "some" a reserved word, as will be required by the Ada 2012
RM.
The following test must get an error:

% gcc -c -gnat2012 some_id.ads 
some_id.ads:2:04: reserved word "some" cannot be used as identifier

package Some_Id is
   Some : Integer; -- ERROR: "some" is a reserved word
end Some_Id;

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

2011-08-29  Bob Duff  <duff@adacore.com>

	* par-ch2.adb (P_Identifier): Warn that "some" is reserved in Ada 2012.
	* par-ch4.adb (P_Quantified_Expression): Remove unnecessary code for
	treating "some" as unreserved in earlier Ada versions. This is now
	handled in Snames.Is_Keyword_Name. Parse "for some" using Tok_Some,
	rather than Name_Some, since Tok_Some is now recognized as reserved.
	* scans.adb (Initialize_Ada_Keywords): Handle Tok_Some like any other
	reserved word.
	* scans.ads: Minor comment fixes.
	* snames.adb-tmpl (Is_Keyword_Name): Handle Ada 2012 reserved words as
	for other language versions.
	* scn.adb (Scan_Reserved_Identifier): Remove unnecessary code for
	treating "some" as unreserved in earlier Ada versions. This is now
	handled in Snames.Is_Keyword_Name.
	* par-ch3.adb (P_Defining_Identifier): Warn that "some" is reserved in
	Ada 2012.
	(P_Subtype_Mark_Resync): Remove unnecessary code for treating "some" as
	unreserved in earlier Ada versions. This is now handled in
	Snames.Is_Keyword_Name.
	* snames.ads-tmpl (Ada_2012_Reserved_Words): Handle Ada 2012 reserved
	words as for other language versions.
	* gnat_ugn.texi (-gnatwy): Fix documentation: this switch applies to
	Ada 2012, not just Ada 2005.

-------------- next part --------------
Index: gnat_ugn.texi
===================================================================
--- gnat_ugn.texi	(revision 178186)
+++ gnat_ugn.texi	(working copy)
@@ -5780,12 +5780,14 @@
 (No_Exception_Propagation) is in effect.
 
 @item -gnatwy
-@emph{Activate warnings for Ada 2005 compatibility issues.}
+@emph{Activate warnings for Ada compatibility issues.}
 @cindex @option{-gnatwy} (@command{gcc})
-@cindex Ada 2005 compatibility issues warnings
-For the most part Ada 2005 is upwards compatible with Ada 95,
-but there are some exceptions (for example the fact that
-@code{interface} is now a reserved word in Ada 2005). This
+@cindex Ada compatibility issues warnings
+For the most part, newer versions of Ada are upwards compatible
+with older versions. For example, Ada 2005 programs will almost
+always work when compiled as Ada 2012.
+However there are some exceptions (for example the fact that
+@code{some} is now a reserved word in Ada 2012). This
 switch activates several warnings to help in identifying
 and correcting such incompatibilities. The default is that
 these warnings are generated. Note that at one point Ada 2005
@@ -5793,11 +5795,11 @@
 This warning can also be turned on using @option{-gnatwa}.
 
 @item -gnatwY
-@emph{Disable warnings for Ada 2005 compatibility issues.}
+@emph{Disable warnings for Ada compatibility issues.}
 @cindex @option{-gnatwY} (@command{gcc})
-@cindex Ada 2005 compatibility issues warnings
-This switch suppresses several warnings intended to help in identifying
-incompatibilities between Ada 95 and Ada 2005.
+@cindex Ada compatibility issues warnings
+This switch suppresses the warnings intended to help in identifying
+incompatibilities between Ada language versions.
 
 @item -gnatwz
 @emph{Activate warnings on unchecked conversions.}
Index: par-ch2.adb
===================================================================
--- par-ch2.adb	(revision 178155)
+++ par-ch2.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -76,6 +76,16 @@
             end if;
          end if;
 
+         --  Similarly, warn about Ada 2012 reserved words
+
+         if Ada_Version in Ada_95 .. Ada_2005
+           and then Warn_On_Ada_2012_Compatibility
+         then
+            if Token_Name = Name_Some then
+               Error_Msg_N ("& is a reserved word in Ada 2012?", Token_Node);
+            end if;
+         end if;
+
          Ident_Node := Token_Node;
          Scan; -- past Identifier
          return Ident_Node;
Index: par-ch3.adb
===================================================================
--- par-ch3.adb	(revision 178155)
+++ par-ch3.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -229,6 +229,16 @@
             end if;
          end if;
 
+         --  Similarly, warn about Ada 2012 reserved words
+
+         if Ada_Version in Ada_95 .. Ada_2005
+           and then Warn_On_Ada_2012_Compatibility
+         then
+            if Token_Name = Name_Some then
+               Error_Msg_N ("& is a reserved word in Ada 2012?", Token_Node);
+            end if;
+         end if;
+
       --  If we have a reserved identifier, manufacture an identifier with
       --  a corresponding name after posting an appropriate error message
 
@@ -1125,16 +1135,6 @@
          Discard_Junk_Node (P_Array_Type_Definition);
          return Error;
 
-      --  If Some becomes a keyword, the following is needed to make it
-      --  acceptable in older versions of Ada.
-
-      elsif Token = Tok_Some
-        and then Ada_Version < Ada_2012
-      then
-         Scan_Reserved_Identifier (False);
-         Scan;
-         return Token_Node;
-
       else
          Type_Node := P_Qualified_Simple_Name_Resync;
 
Index: par-ch4.adb
===================================================================
--- par-ch4.adb	(revision 178155)
+++ par-ch4.adb	(working copy)
@@ -1432,19 +1432,9 @@
          --  that doesn't belong to us!
 
          if Token in Token_Class_Eterm then
-
-            --  If Some becomes a keyword, the following is needed to make it
-            --  acceptable in older versions of Ada.
-
-            if Token = Tok_Some
-              and then Ada_Version < Ada_2012
-            then
-               Scan_Reserved_Identifier (False);
-            else
-               Error_Msg_AP
-                 ("expecting expression or component association");
-               exit;
-            end if;
+            Error_Msg_AP
+              ("expecting expression or component association");
+            exit;
          end if;
 
          --  Deal with misused box
@@ -2564,13 +2554,7 @@
       if Token = Tok_All then
          Set_All_Present (Node1);
 
-      --  We treat Some as a non-reserved keyword, so it appears to the scanner
-      --  as an identifier. If Some is made into a reserved word, the check
-      --  below is against Tok_Some.
-
-      elsif Token /= Tok_Identifier
-        or else Chars (Token_Node) /= Name_Some
-      then
+      elsif Token /= Tok_Some then
          Error_Msg_AP ("missing quantifier");
          raise Error_Resync;
       end if;
Index: scans.adb
===================================================================
--- scans.adb	(revision 178155)
+++ scans.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -118,13 +118,6 @@
       Set_Reserved (Name_Reverse,   Tok_Reverse);
       Set_Reserved (Name_Select,    Tok_Select);
       Set_Reserved (Name_Separate,  Tok_Separate);
-
-      --  We choose to make Some into a non-reserved word, so it is handled
-      --  like a regular identifier in most contexts. Uncomment the following
-      --  line if a pedantic Ada2012 mode is required.
-
-      --  Set_Reserved (Name_Some,      Tok_Some);
-
       Set_Reserved (Name_Subtype,   Tok_Subtype);
       Set_Reserved (Name_Tagged,    Tok_Tagged);
       Set_Reserved (Name_Task,      Tok_Task);
@@ -140,10 +133,14 @@
 
       --  Ada 2005 reserved words
 
-      Set_Reserved (Name_Interface,     Tok_Interface);
-      Set_Reserved (Name_Overriding,    Tok_Overriding);
-      Set_Reserved (Name_Synchronized,  Tok_Synchronized);
+      Set_Reserved (Name_Interface,    Tok_Interface);
+      Set_Reserved (Name_Overriding,   Tok_Overriding);
+      Set_Reserved (Name_Synchronized, Tok_Synchronized);
 
+      --  Ada 2012 reserved words
+
+      Set_Reserved (Name_Some, Tok_Some);
+
    end Initialize_Ada_Keywords;
 
    ------------------------
Index: scans.ads
===================================================================
--- scans.ads	(revision 178155)
+++ scans.ads	(working copy)
@@ -47,7 +47,7 @@
 
    --  Note: Namet.Is_Keyword_Name depends on the fact that the first entry in
    --  this type declaration is *not* for a reserved word. For details on why
-   --  there is this requirement, see Scans.Initialize_Ada_Keywords.
+   --  there is this requirement, see Initialize_Ada_Keywords below.
 
    type Token_Type is (
 
@@ -341,7 +341,9 @@
    --  Flag array used to test for reserved word
 
    procedure Initialize_Ada_Keywords;
-   --  Set up Token_Type values in Names table entries for Ada reserved words
+   --  Set up Token_Type values in Names table entries for Ada reserved
+   --  words. This ignores Ada_Version; Ada_Version is taken into account in
+   --  Snames.Is_Keyword_Name.
 
    --------------------------
    -- Scan State Variables --
Index: scn.adb
===================================================================
--- scn.adb	(revision 178155)
+++ scn.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -472,18 +472,9 @@
       Token_Name := Name_Find;
 
       if not Used_As_Identifier (Token) or else Force_Msg then
-
-         --  If "some" is made into a reserved work in Ada2012, the following
-         --  check will make it into a regular identifier in earlier versions
-         --  of the language.
-
-         if Token = Tok_Some and then Ada_Version < Ada_2012 then
-            null;
-         else
-            Error_Msg_Name_1 := Token_Name;
-            Error_Msg_SC ("reserved word* cannot be used as identifier!");
-            Used_As_Identifier (Token) := True;
-         end if;
+         Error_Msg_Name_1 := Token_Name;
+         Error_Msg_SC ("reserved word* cannot be used as identifier!");
+         Used_As_Identifier (Token) := True;
       end if;
 
       Token := Tok_Identifier;
Index: snames.adb-tmpl
===================================================================
--- snames.adb-tmpl	(revision 178179)
+++ snames.adb-tmpl	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -379,7 +379,9 @@
         and then (Ada_Version >= Ada_95
                   or else N not in Ada_95_Reserved_Words)
         and then (Ada_Version >= Ada_2005
-                  or else N not in Ada_2005_Reserved_Words);
+                  or else N not in Ada_2005_Reserved_Words)
+        and then (Ada_Version >= Ada_2012
+                  or else N not in Ada_2012_Reserved_Words);
    end Is_Keyword_Name;
 
    ----------------------------
Index: snames.ads-tmpl
===================================================================
--- snames.ads-tmpl	(revision 178179)
+++ snames.ads-tmpl	(working copy)
@@ -953,13 +953,9 @@
    Name_All_Checks                     : constant Name_Id := N + $;
    Last_Check_Name                     : constant Name_Id := N + $;
 
-   --  Names corresponding to reserved keywords, excluding those already
-   --  declared in the attribute list (Access, Delta, Digits, Mod, Range).
+   --  Ada 83 reserved words, excluding those already declared in the attribute
+   --  list (Access, Delta, Digits, Mod, Range).
 
-   --  Note: Name_Some is here even though for now we do not treat it as being
-   --  reserved. We treat it instead as an unreserved keyword. This may change
-   --  in the future, but in any case it belongs in the following list.
-
    Name_Abort                            : constant Name_Id := N + $;
    Name_Abs                              : constant Name_Id := N + $;
    Name_Accept                           : constant Name_Id := N + $;
@@ -1008,7 +1004,6 @@
    Name_Reverse                          : constant Name_Id := N + $;
    Name_Select                           : constant Name_Id := N + $;
    Name_Separate                         : constant Name_Id := N + $;
-   Name_Some                             : constant Name_Id := N + $;
    Name_Subtype                          : constant Name_Id := N + $;
    Name_Task                             : constant Name_Id := N + $;
    Name_Terminate                        : constant Name_Id := N + $;
@@ -1053,7 +1048,7 @@
 
    Name_Free                             : constant Name_Id := N + $;
 
-   --  Reserved words used only in Ada 95
+   --  Ada 95 reserved words
 
    First_95_Reserved_Word                : constant Name_Id := N + $;
    Name_Abstract                         : constant Name_Id := N + $;
@@ -1227,7 +1222,7 @@
    Name_No_Element                       : constant Name_Id := N + $;
    Name_Previous                         : constant Name_Id := N + $;
 
-   --  Ada 05 reserved words
+   --  Ada 2005 reserved words
 
    First_2005_Reserved_Word              : constant Name_Id := N + $;
    Name_Interface                        : constant Name_Id := N + $;
@@ -1238,6 +1233,15 @@
    subtype Ada_2005_Reserved_Words is
      Name_Id range First_2005_Reserved_Word .. Last_2005_Reserved_Word;
 
+   --  Ada 2012 reserved words
+
+   First_2012_Reserved_Word              : constant Name_Id := N + $;
+   Name_Some                             : constant Name_Id := N + $;
+   Last_2012_Reserved_Word               : constant Name_Id := N + $;
+
+   subtype Ada_2012_Reserved_Words is
+     Name_Id range First_2012_Reserved_Word .. Last_2012_Reserved_Word;
+
    --  Mark last defined name for consistency check in Snames body
 
    Last_Predefined_Name                  : constant Name_Id := N + $;


More information about the Gcc-patches mailing list