This change factors a chunk of code that was duplicated between Par.Ch2.P_Identifier and Par.Ch3.P_Defining_Identifier.
No behaviour change, no test. Tested on x86_64-pc-linux-gnu, committed on trunk 2011-10-13 Thomas Quinot <qui...@adacore.com> * par-ch2.adb, par.adb, par-util.adb, par-ch3.adb (Check_Future_Identifier): New subprogram, factors duplicated code from Par.Ch2.P_Identifier and Par.Ch3.P_Defining_Identifier.
Index: par-ch2.adb =================================================================== --- par-ch2.adb (revision 179894) +++ par-ch2.adb (working copy) @@ -62,34 +62,7 @@ -- Code duplication, see Par_Ch3.P_Defining_Identifier??? if Token = Tok_Identifier then - - -- Shouldn't the warnings below be emitted when in Ada 83 mode??? - - -- Ada 2005 (AI-284): If compiling in Ada 95 mode, we warn that - -- INTERFACE, OVERRIDING, and SYNCHRONIZED are new reserved words. - - if Ada_Version = Ada_95 - and then Warn_On_Ada_2005_Compatibility - then - if Token_Name = Name_Overriding - or else Token_Name = Name_Synchronized - or else (Token_Name = Name_Interface - and then Prev_Token /= Tok_Pragma) - then - Error_Msg_N ("& is a reserved word in Ada 2005?", Token_Node); - 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; - + Check_Future_Keyword; Ident_Node := Token_Node; Scan; -- past Identifier return Ident_Node; Index: par.adb =================================================================== --- par.adb (revision 179894) +++ par.adb (working copy) @@ -1156,6 +1156,11 @@ -- mode. The caller has typically checked that the current token, -- an identifier, matches one of the 95 keywords. + procedure Check_Future_Keyword; + -- Emit a warning if the current token is a valid identifier in the + -- language version in use, but is a reserved word in a later language + -- version (unless the language version in use is Ada 83). + procedure Check_Simple_Expression (E : Node_Id); -- Given an expression E, that has just been scanned, so that Expr_Form -- is still set, outputs an error if E is a non-simple expression. E is Index: par-util.adb =================================================================== --- par-util.adb (revision 179894) +++ par-util.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- -- @@ -169,6 +169,43 @@ end Check_Bad_Layout; -------------------------- + -- Check_Future_Keyword -- + -------------------------- + + procedure Check_Future_Keyword is + begin + -- Ada 2005 (AI-284): Compiling in Ada95 mode we warn that INTERFACE, + -- OVERRIDING, and SYNCHRONIZED are new reserved words. + + if Ada_Version = Ada_95 + and then Warn_On_Ada_2005_Compatibility + then + if Token_Name = Name_Overriding + or else Token_Name = Name_Synchronized + or else (Token_Name = Name_Interface + and then Prev_Token /= Tok_Pragma) + then + Error_Msg_N ("& is a reserved word in Ada 2005?", Token_Node); + 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; + + -- Note: we deliberately do not emit these warnings when operating in + -- Ada 83 mode because in that case we assume the user is building + -- legacy code anyway. + + end Check_Future_Keyword; + + -------------------------- -- Check_Misspelling_Of -- -------------------------- Index: par-ch3.adb =================================================================== --- par-ch3.adb (revision 179894) +++ par-ch3.adb (working copy) @@ -213,39 +213,8 @@ -- Duplication should be removed, common code should be factored??? if Token = Tok_Identifier then + Check_Future_Keyword; - -- Shouldn't the warnings below be emitted when in Ada 83 mode??? - - -- Ada 2005 (AI-284): If compiling in Ada 95 mode, we warn that - -- INTERFACE, OVERRIDING, and SYNCHRONIZED are new reserved words. - -- Note that in the case where these keywords are misused in Ada 95 - -- mode, this routine will generally not be called at all. - - -- What sort of misuse is this comment talking about??? These are - -- perfectly legitimate defining identifiers in Ada 95??? - - if Ada_Version = Ada_95 - and then Warn_On_Ada_2005_Compatibility - then - if Token_Name = Name_Overriding - or else Token_Name = Name_Synchronized - or else (Token_Name = Name_Interface - and then Prev_Token /= Tok_Pragma) - then - Error_Msg_N ("& is a reserved word in Ada 2005?", Token_Node); - 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