From patchwork Wed Jun 23 09:54:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Implement pragma Ada_2012 and -gnat12 switch Date: Tue, 22 Jun 2010 23:54:39 -0000 From: Arnaud Charlet X-Patchwork-Id: 56624 Message-Id: <20100623095439.GA6396@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Robert Dewar This patch implements pragma Ada_2012 (pragma Ada_12 allowed as a synonym) and switch -gnat12 to activate Ada 2012 mode. Already implemented Ada_2012 features have been placed under control of this switch. The effect of -gnatX and pragma Extensions_Allowed (On) has been modified to set the latest Ada version to minimize compatibility issues. The patch also adds -gnat2005 and -gnat2012 as synonyms for -gnat05/12. The following compiles clean with this patch pragma Ada_2012; function Ada12test (X : Boolean) return Integer is begin return (if X then 2 else 42); end Ada12test; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-23 Robert Dewar * usage.adb: Add documentation for -gnat12 switch. * errout.ads: Add VMS alias entry for -gnat12 switch * gnat_rm.texi: Add documentation for pragma Ada_12 and Ada_2012 Add documentation for pragma Extensions_Allowed. * opt.ads: Add entry for Ada 2012 mode. * sem_ch4.adb, par-ch3.adb, par-ch4.adb: Use new Ada 2012 mode for 2012 features. * sem_prag.adb, par-prag.adb: Add processing for pragma Ada_12 and Ada_2012. * sem_ch13.adb: Add handling for Ada 2012 mode. * snames.ads-tmpl: Add entries for pragma Ada_2012 and Ada_12. * switch-c.adb: Add handling for -gnat12 switch. Implement -gnat2005 and -gnat2012. * usage.adb: Add documentation for -gnat12 switch. * vms_data.ads: Add /12 switch for Ada 2012 mode. Index: usage.adb =================================================================== --- usage.adb (revision 161073) +++ usage.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2010, 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- -- @@ -595,7 +595,17 @@ begin if Ada_Version_Default = Ada_05 then Write_Line ("Ada 2005 mode (default)"); else - Write_Line ("Allow Ada 2005 extensions"); + Write_Line ("Enforce Ada 2005 restrictions"); + end if; + + -- Line for -gnat12 switch + + Write_Switch_Char ("12"); + + if Ada_Version_Default = Ada_12 then + Write_Line ("Ada 2012 mode (default)"); + else + Write_Line ("Allow Ada 2012 extensions"); end if; -- Line for -gnat-p switch Index: gnat_rm.texi =================================================================== --- gnat_rm.texi (revision 161205) +++ gnat_rm.texi (working copy) @@ -99,6 +99,8 @@ Implementation Defined Pragmas * Pragma Ada_95:: * Pragma Ada_05:: * Pragma Ada_2005:: +* Pragma Ada_12:: +* Pragma Ada_2012:: * Pragma Annotate:: * Pragma Assert:: * Pragma Assume_No_Invalid_Values:: @@ -132,6 +134,7 @@ Implementation Defined Pragmas * Pragma Export_Value:: * Pragma Export_Valued_Procedure:: * Pragma Extend_System:: +* Pragma Extensions_Allowed:: * Pragma External:: * Pragma External_Name_Casing:: * Pragma Fast_Math:: @@ -712,6 +715,8 @@ consideration, the use of these pragmas * Pragma Ada_95:: * Pragma Ada_05:: * Pragma Ada_2005:: +* Pragma Ada_12:: +* Pragma Ada_2012:: * Pragma Annotate:: * Pragma Assert:: * Pragma Assume_No_Invalid_Values:: @@ -745,6 +750,7 @@ consideration, the use of these pragmas * Pragma Export_Value:: * Pragma Export_Valued_Procedure:: * Pragma Extend_System:: +* Pragma Extensions_Allowed:: * Pragma External:: * Pragma External_Name_Casing:: * Pragma Fast_Math:: @@ -903,9 +909,7 @@ pragma Ada_05; @noindent A configuration pragma that establishes Ada 2005 mode for the unit to which it applies, regardless of the mode set by the command line switches. -This mode is set automatically for the @code{Ada} and @code{System} -packages and their children, so you need not specify it in these -contexts. This pragma is useful when writing a reusable component that +This pragma is useful when writing a reusable component that itself uses Ada 2005 features, but which is intended to be usable from either Ada 83 or Ada 95 programs. @@ -922,6 +926,37 @@ pragma Ada_2005; This configuration pragma is a synonym for pragma Ada_05 and has the same syntax and effect. +@node Pragma Ada_12 +@unnumberedsec Pragma Ada_12 +@findex Ada_12 +@noindent +Syntax: +@smallexample @c ada +pragma Ada_12; +@end smallexample + +@noindent +A configuration pragma that establishes Ada 2012 mode for the unit to which +it applies, regardless of the mode set by the command line switches. +This mode is set automatically for the @code{Ada} and @code{System} +packages and their children, so you need not specify it in these +contexts. This pragma is useful when writing a reusable component that +itself uses Ada 2012 features, but which is intended to be usable from +Ada 83, Ada 95, or Ada 2005 programs. + +@node Pragma Ada_2012 +@unnumberedsec Pragma Ada_2012 +@findex Ada_2005 +@noindent +Syntax: +@smallexample @c ada +pragma Ada_2012; +@end smallexample + +@noindent +This configuration pragma is a synonym for pragma Ada_12 and has the +same syntax and effect. + @node Pragma Annotate @unnumberedsec Pragma Annotate @findex Annotate @@ -2174,6 +2209,35 @@ it you will have to use the appropriate system units. @xref{Top, @value{EDITION} User's Guide, About This Guide,, gnat_ugn, @value{EDITION} User's Guide}, for details. +@node Pragma Extensions_Allowed +@unnumberedsec Pragma Extensions_Allowed +@cindex Ada Extensions +@cindex GNAT Extensions +@findex Extensions_Allowed +@noindent +Syntax: + +@smallexample @c ada +pragma Extensions_Allowed (On | Off); +@end smallexample + +@noindent +This configuration pragma enables or disables the implementation +extension mode (the use of Off as a parameter cancels the effect +of the @option{-gnatX} command switch). + +In extension mode, the latest version of the Ada language is +implemented (currently Ada 2012), and in addition a small number +of GNAT specific extensions are recognized as follows: + +@table @asis +@item Constrained attribute for generic objects +The @code{Constrained} attribute is permitted for objects of +generic types. The result indicates if the corresponding actual +is constrained. + +@end table + @node Pragma External @unnumberedsec Pragma External @findex External @@ -8879,8 +8943,8 @@ The algorithm is the Mersenne Twister, a state. See A.5.2(38). @end cartouche @noindent -The value returned by the Image function is the concatenation of -the fixed-width decimal representations of the 624 32-bit integers +The value returned by the Image function is the concatenation of +the fixed-width decimal representations of the 624 32-bit integers of the state vector. @sp 1 Index: switch-c.adb =================================================================== --- switch-c.adb (revision 161073) +++ switch-c.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2001-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 2001-2010, 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- -- @@ -532,11 +532,11 @@ package body Switch.C is System_Extend_Unit := Empty; Warning_Mode := Treat_As_Error; - -- Set Ada 2005 mode explicitly. We don't want to rely on the + -- Set Ada 2012 mode explicitly. We don't want to rely on the -- implicit setting here, since for example, we want -- Preelaborate_05 treated as Preelaborate - Ada_Version := Ada_05; + Ada_Version := Ada_12; Ada_Version_Explicit := Ada_Version; -- Set default warnings and style checks for -gnatg @@ -903,6 +903,8 @@ package body Switch.C is when 'X' => Ptr := Ptr + 1; Extensions_Allowed := True; + Ada_Version := Ada_Version_Type'Last; + Ada_Version_Explicit := Ada_Version_Type'Last; -- Processing for y switch @@ -1048,6 +1050,42 @@ package body Switch.C is Ada_Version_Explicit := Ada_Version; end if; + -- Processing for 12 switch + + when '1' => + if Ptr = Max then + Bad_Switch ("-gnat1"); + end if; + + Ptr := Ptr + 1; + + if Switch_Chars (Ptr) /= '2' then + Bad_Switch ("-gnat1" & Switch_Chars (Ptr .. Max)); + else + Ptr := Ptr + 1; + Ada_Version := Ada_12; + Ada_Version_Explicit := Ada_Version; + end if; + + -- Processing for 2005 and 2012 switches + + when '2' => + if Ptr > Max - 3 then + Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Max)); + + elsif Switch_Chars (Ptr .. Ptr + 3) = "2005" then + Ada_Version := Ada_05; + + elsif Switch_Chars (Ptr .. Ptr + 3) = "2012" then + Ada_Version := Ada_12; + + else + Bad_Switch ("-gnat" & Switch_Chars (Ptr .. Ptr + 3)); + end if; + + Ada_Version_Explicit := Ada_Version; + Ptr := Ptr + 4; + -- Switch cancellation, currently only -gnat-p is allowed. -- All we do here is the error checking, since the actual -- processing for switch cancellation is done by calls to Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 161184) +++ sem_prag.adb (working copy) @@ -5257,8 +5257,9 @@ package body Sem_Prag is -- said this was a configuration pragma, but we did not check and -- are hesitant to add the check now. - -- However, we really cannot tolerate mixing Ada 2005 with Ada 83 - -- or Ada 95, so we must check if we are in Ada 2005 mode. + -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012 + -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005 + -- or Ada 2012 mode. if Ada_Version >= Ada_05 then Check_Valid_Configuration_Pragma; @@ -5347,6 +5348,33 @@ package body Sem_Prag is end if; end; + --------------------- + -- Ada_12/Ada_2012 -- + --------------------- + + -- pragma Ada_12; + -- pragma Ada_2012; + + -- Note: these pragma also have some specific processing in Par.Prag + -- because we want to set the Ada 2012 version mode during parsing. + + when Pragma_Ada_12 | Pragma_Ada_2012 => + GNAT_Pragma; + Check_Arg_Count (0); + + -- For Ada_2012 we unconditionally enforce the documented + -- configuration pragma placement, since we do not want to + -- tolerate mixed modes in a unit involving Ada 2012. That would + -- cause real difficulties for those cases where there are + -- incompatibilities between Ada 95 and Ada 2005/Ada 2012. + + Check_Valid_Configuration_Pragma; + + -- Now set Ada 2012 mode + + Ada_Version := Ada_12; + Ada_Version_Explicit := Ada_12; + ---------------------- -- All_Calls_Remote -- ---------------------- @@ -7451,8 +7479,11 @@ package body Sem_Prag is if Chars (Expression (Arg1)) = Name_On then Extensions_Allowed := True; + Ada_Version := Ada_Version_Type'Last; + else Extensions_Allowed := False; + Ada_Version := Ada_Version_Explicit; end if; -------------- @@ -10080,7 +10111,7 @@ package body Sem_Prag is -- This is one of the few cases where we need to test the value of -- Ada_Version_Explicit rather than Ada_Version (which is always - -- set to Ada_05 in a predefined unit), we need to know the + -- set to Ada_12 in a predefined unit), we need to know the -- explicit version set to know if this pragma is active. if Ada_Version_Explicit >= Ada_05 then @@ -10580,7 +10611,7 @@ package body Sem_Prag is -- This is one of the few cases where we need to test the value of -- Ada_Version_Explicit rather than Ada_Version (which is always - -- set to Ada_05 in a predefined unit), we need to know the + -- set to Ada_12 in a predefined unit), we need to know the -- explicit version set to know if this pragma is active. if Ada_Version_Explicit >= Ada_05 then @@ -12647,6 +12678,8 @@ package body Sem_Prag is Pragma_Ada_95 => -1, Pragma_Ada_05 => -1, Pragma_Ada_2005 => -1, + Pragma_Ada_12 => -1, + Pragma_Ada_2012 => -1, Pragma_All_Calls_Remote => -1, Pragma_Annotate => -1, Pragma_Assert => -1, Index: par-ch4.adb =================================================================== --- par-ch4.adb (revision 161166) +++ par-ch4.adb (working copy) @@ -2352,7 +2352,7 @@ package body Ch4 is -- If this looks like a conditional expression, then treat it -- that way with an error message. - elsif Extensions_Allowed then + elsif Ada_Version >= Ada_12 then Error_Msg_SC ("conditional expression must be parenthesized"); return P_Conditional_Expression; @@ -2378,7 +2378,7 @@ package body Ch4 is -- If this looks like a case expression, then treat it that way -- with an error message. - elsif Extensions_Allowed then + elsif Ada_Version >= Ada_12 then Error_Msg_SC ("case expression must be parenthesized"); return P_Case_Expression; @@ -2668,9 +2668,9 @@ package body Ch4 is Save_State : Saved_Scan_State; begin - if not Extensions_Allowed then - Error_Msg_SC ("|case expression is an Ada extension"); - Error_Msg_SC ("\|use -gnatX switch to compile this unit"); + if Ada_Version < Ada_12 then + Error_Msg_SC ("|case expression is an Ada 2012 feature"); + Error_Msg_SC ("\|use -gnat12 switch to compile this unit"); end if; Scan; -- past CASE @@ -2759,9 +2759,9 @@ package body Ch4 is begin Inside_Conditional_Expression := Inside_Conditional_Expression + 1; - if Token = Tok_If and then not Extensions_Allowed then - Error_Msg_SC ("|conditional expression is an Ada extension"); - Error_Msg_SC ("\|use -gnatX switch to compile this unit"); + if Token = Tok_If and then Ada_Version < Ada_12 then + Error_Msg_SC ("|conditional expression is an Ada 2012 feature"); + Error_Msg_SC ("\|use -gnat12 switch to compile this unit"); end if; Scan; -- past IF or ELSIF @@ -2836,15 +2836,15 @@ package body Ch4 is procedure P_Membership_Test (N : Node_Id) is Alt : constant Node_Id := P_Range_Or_Subtype_Mark - (Allow_Simple_Expression => Extensions_Allowed); + (Allow_Simple_Expression => (Ada_Version >= Ada_12)); begin -- Set case if Token = Tok_Vertical_Bar then - if not Extensions_Allowed then - Error_Msg_SC ("set notation is a language extension"); - Error_Msg_SC ("\|use -gnatX switch to compile this unit"); + if Ada_Version < Ada_12 then + Error_Msg_SC ("set notation is an Ada 2012 feature"); + Error_Msg_SC ("\|use -gnat12 switch to compile this unit"); end if; Set_Alternatives (N, New_List (Alt)); Index: errout.ads =================================================================== --- errout.ads (revision 161073) +++ errout.ads (working copy) @@ -376,6 +376,9 @@ package Errout is Gname5 : aliased constant String := "gnat05"; Vname5 : aliased constant String := "05"; + Gname6 : aliased constant String := "gnat12"; + Vname6 : aliased constant String := "12"; + type Cstring_Ptr is access constant String; Gnames : array (Nat range <>) of Cstring_Ptr := @@ -383,14 +386,16 @@ package Errout is Gname2'Access, Gname3'Access, Gname4'Access, - Gname5'Access); + Gname5'Access, + Gname6'Access); Vnames : array (Nat range <>) of Cstring_Ptr := (Vname1'Access, Vname2'Access, Vname3'Access, Vname4'Access, - Vname5'Access); + Vname5'Access, + Vname6'Access); ----------------------------------------------------- -- Global Values Used for Error Message Insertions -- Index: sem_ch4.adb =================================================================== --- sem_ch4.adb (revision 161244) +++ sem_ch4.adb (working copy) @@ -2344,7 +2344,7 @@ package body Sem_Ch4 is Analyze_Expression (L); if No (R) - and then Extensions_Allowed + and then Ada_Version >= Ada_12 then Analyze_Set_Membership; return; Index: par-prag.adb =================================================================== --- par-prag.adb (revision 161073) +++ par-prag.adb (working copy) @@ -306,7 +306,7 @@ begin -- Ada_05/Ada_2005 -- --------------------- - -- This pragma must be processed at parse time, since we want to set + -- These pragmas must be processed at parse time, since we want to set -- the Ada version properly at parse time to recognize the appropriate -- Ada version syntax. However, it is only the zero argument form that -- must be processed at parse time. @@ -317,6 +317,18 @@ begin Ada_Version_Explicit := Ada_05; end if; + --------------------- + -- Ada_12/Ada_2012 -- + --------------------- + + -- These pragmas must be processed at parse time, since we want to set + -- the Ada version properly at parse time to recognize the appropriate + -- Ada version syntax. + + when Pragma_Ada_12 | Pragma_Ada_2012 => + Ada_Version := Ada_12; + Ada_Version_Explicit := Ada_12; + ----------- -- Debug -- ----------- @@ -374,8 +386,10 @@ begin if Chars (Expression (Arg1)) = Name_On then Extensions_Allowed := True; + Ada_Version := Ada_12; else Extensions_Allowed := False; + Ada_Version := Ada_Version_Explicit; end if; ---------------- Index: vms_data.ads =================================================================== --- vms_data.ads (revision 161187) +++ vms_data.ads (working copy) @@ -1227,7 +1227,13 @@ package VMS_Data is "-gnat05"; -- /05 (D) -- - -- Allows GNAT to recognize all implemented proposed Ada 2005 + -- Allows GNAT to recognize the full range of Ada 2005 constructs. + + S_GCC_Ada_12 : aliased constant S := "/12 " & + "-gnat12"; + -- /05 (D) + -- + -- Allows GNAT to recognize all implemented proposed Ada 2012 -- extensions. See features file for list of implemented features. S_GCC_Add : aliased constant S := "/ADD_PROJECT_SEARCH_DIR=*" & Index: opt.ads =================================================================== --- opt.ads (revision 161265) +++ opt.ads (working copy) @@ -64,17 +64,15 @@ package Opt is -- GNATBIND, GNATLINK -- Set True if binder file to be generated in Ada rather than C - type Ada_Version_Type is (Ada_83, Ada_95, Ada_05); - pragma Warnings (Off, Ada_Version_Type); + type Ada_Version_Type is (Ada_83, Ada_95, Ada_05, Ada_12); -- Versions of Ada for Ada_Version below. Note that these are ordered, -- so that tests like Ada_Version >= Ada_95 are legitimate and useful. - -- The Warnings_Off pragma stops warnings for Ada_Version >= Ada_05, - -- which we want to allow, so that things work OK when Ada_15 is added! - -- This warning is now removed, so this pragma can be removed some time??? Ada_Version_Default : constant Ada_Version_Type := Ada_05; + pragma Warnings (Off, Ada_Version_Default); -- GNAT - -- Default Ada version if no switch given + -- Default Ada version if no switch given. The Warnings off is to kill + -- constant condition warnings. Ada_Version : Ada_Version_Type := Ada_Version_Default; -- GNAT @@ -91,7 +89,7 @@ package Opt is -- the rare cases (notably for pragmas Preelaborate_05 and Pure_05) -- where in the run-time we want the explicit version set. - Ada_Version_Runtime : Ada_Version_Type := Ada_05; + Ada_Version_Runtime : Ada_Version_Type := Ada_12; -- GNAT -- Ada version used to compile the runtime. Used to set Ada_Version (but -- not Ada_Version_Explicit) when compiling predefined or internal units. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 161247) +++ sem_ch13.adb (working copy) @@ -315,7 +315,7 @@ package body Sem_Ch13 is -- In AI-133. This involves gathering all components which start at -- the same byte offset and processing them together - when Ada_05 => + when Ada_05 .. Ada_Version_Type'Last => declare Max_Machine_Scalar_Size : constant Uint := UI_From_Int Index: par-ch3.adb =================================================================== --- par-ch3.adb (revision 161073) +++ par-ch3.adb (working copy) @@ -124,9 +124,8 @@ package body Ch3 is elsif Nkind_In (N, N_In, N_Not_In) and then Paren_Count (N) = 0 then - Error_Msg_N ("|this expression must be parenthesized!", N); Error_Msg_N - ("\|since extensions (and set notation) are allowed", N); + ("|this expression must be parenthesized in Ada 2012 mode!", N); end if; end Check_Restricted_Expression; @@ -3663,10 +3662,10 @@ package body Ch3 is -- Expression else - -- If extensions are permitted then the expression must be a - -- simple expression. The resaon for this restriction (i.e. - -- going back to the Ada 83 rule) is to avoid ambiguities - -- when set membership operations are allowed, consider the + -- In Ada 2012 mode, the expression must be a simple + -- expression. The resaon for this restriction (i.e. going + -- back to the Ada 83 rule) is to avoid ambiguities when set + -- membership operations are allowed, consider the -- following: -- when A in 1 .. 10 | 12 => @@ -3679,12 +3678,12 @@ package body Ch3 is -- when (A in 1 .. 10 | 12) => -- when (A in 1 .. 10) | 12 => - -- To solve this, if extensins are enabled, we disallow + -- To solve this, in Ada 2012 mode, we disallow -- the use of membership operations in expressions in -- choices. Technically in the grammar, the expression -- must match the grammar for restricted expression. - if Extensions_Allowed then + if Ada_Version >= Ada_12 then Check_Restricted_Expression (Expr_Node); -- In Ada 83 mode, the syntax required a simple expression Index: snames.ads-tmpl =================================================================== --- snames.ads-tmpl (revision 161073) +++ snames.ads-tmpl (working copy) @@ -34,7 +34,7 @@ with Namet; use Namet; package Snames is -- This package contains definitions of standard names (i.e. entries in the --- Names table) that are used throughout the GNAT compiler). It also contains +-- Names table) that are used throughout the GNAT compiler. It also contains -- the definitions of some enumeration types whose definitions are tied to -- the order of these preset names. @@ -334,6 +334,8 @@ package Snames is Name_Ada_95 : constant Name_Id := N + $; -- GNAT Name_Ada_05 : constant Name_Id := N + $; -- GNAT Name_Ada_2005 : constant Name_Id := N + $; -- GNAT + Name_Ada_12 : constant Name_Id := N + $; -- GNAT + Name_Ada_2012 : constant Name_Id := N + $; -- GNAT Name_Assertion_Policy : constant Name_Id := N + $; -- Ada 05 Name_Assume_No_Invalid_Values : constant Name_Id := N + $; -- GNAT Name_C_Pass_By_Copy : constant Name_Id := N + $; -- GNAT @@ -1416,6 +1418,8 @@ package Snames is Pragma_Ada_95, Pragma_Ada_05, Pragma_Ada_2005, + Pragma_Ada_12, + Pragma_Ada_2012, Pragma_Assertion_Policy, Pragma_Assume_No_Invalid_Values, Pragma_C_Pass_By_Copy,