diff options
Diffstat (limited to 'gcc/ada/par-ch4.adb')
-rw-r--r-- | gcc/ada/par-ch4.adb | 101 |
1 files changed, 85 insertions, 16 deletions
diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb index 340668e..20f8dd1 100644 --- a/gcc/ada/par-ch4.adb +++ b/gcc/ada/par-ch4.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2020, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2021, 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- -- @@ -1280,7 +1280,7 @@ package body Ch4 is if Nkind (Aggr_Node) /= N_Aggregate and then Nkind (Aggr_Node) /= N_Extension_Aggregate - and then Ada_Version < Ada_2020 + and then Ada_Version < Ada_2022 then Error_Msg ("aggregate may not have single positional component", Aggr_Sloc); @@ -1399,7 +1399,7 @@ package body Ch4 is if Token = Tok_Left_Bracket then Scan; - -- Special case for null aggregate in Ada 2020 + -- Special case for null aggregate in Ada 2022 if Token = Tok_Right_Bracket then Scan; -- past ] @@ -1601,7 +1601,7 @@ package body Ch4 is -- identifier or OTHERS follows (the latter cases are missing -- comma cases). Also assume positional if a semicolon follows, -- which can happen if there are missing parens. - -- In Ada_2012 and Ada_2020 an iterated association can appear. + -- In Ada 2012 and 2022 an iterated association can appear. elsif Nkind (Expr_Node) in N_Iterated_Component_Association | N_Iterated_Element_Association @@ -1734,8 +1734,9 @@ package body Ch4 is -- aggregates (AI-287) function P_Record_Or_Array_Component_Association return Node_Id is - Assoc_Node : Node_Id; - + Assoc_Node : Node_Id; + Box_Present : Boolean := False; + Box_With_Identifier_Present : Boolean := False; begin -- A loop indicates an iterated_component_association @@ -1744,6 +1745,8 @@ package body Ch4 is end if; Assoc_Node := New_Node (N_Component_Association, Token_Ptr); + Set_Binding_Chars (Assoc_Node, No_Name); + Set_Choices (Assoc_Node, P_Discrete_Choice_List); Set_Sloc (Assoc_Node, Token_Ptr); TF_Arrow; @@ -1755,12 +1758,78 @@ package body Ch4 is Error_Msg_Ada_2005_Extension ("component association with '<'>"); + Box_Present := True; Set_Box_Present (Assoc_Node); - Scan; -- Past box - else + Scan; -- past box + elsif Token = Tok_Less then + declare + Scan_State : Saved_Scan_State; + Id : Node_Id; + begin + Save_Scan_State (Scan_State); + Scan; -- past "<" + if Token = Tok_Identifier then + Id := P_Defining_Identifier; + if Token = Tok_Greater then + if Extensions_Allowed then + Set_Box_Present (Assoc_Node); + Set_Binding_Chars (Assoc_Node, Chars (Id)); + Box_Present := True; + Box_With_Identifier_Present := True; + Scan; -- past ">" + else + Error_Msg + ("Identifier within box only supported under -gnatX", + Token_Ptr); + Box_Present := True; + -- Avoid cascading errors by ignoring the identifier + end if; + end if; + end if; + if not Box_Present then + -- it wasn't an "is <identifier>", so restore. + Restore_Scan_State (Scan_State); + end if; + end; + end if; + + if not Box_Present then Set_Expression (Assoc_Node, P_Expression); end if; + -- Check for "is <identifier>" for aggregate that is part of + -- a pattern for a general case statement. + + if Token = Tok_Is then + declare + Scan_State : Saved_Scan_State; + Id : Node_Id; + begin + Save_Scan_State (Scan_State); + Scan; -- past "is" + if Token = Tok_Identifier then + Id := P_Defining_Identifier; + + if not Extensions_Allowed then + Error_Msg + ("IS following component association" + & " only supported under -gnatX", + Token_Ptr); + elsif Box_With_Identifier_Present then + Error_Msg + ("Both identifier-in-box and trailing identifier" + & " specified for one component association", + Token_Ptr); + else + Set_Binding_Chars (Assoc_Node, Chars (Id)); + end if; + else + -- It wasn't an "is <identifier>", so restore. + Restore_Scan_State (Scan_State); + end if; + end; + end if; + return Assoc_Node; end P_Record_Or_Array_Component_Association; @@ -2928,7 +2997,7 @@ package body Ch4 is Scan; -- past minus when Tok_At_Sign => -- AI12-0125 : target_name - Error_Msg_Ada_2020_Feature ("target name", Token_Ptr); + Error_Msg_Ada_2022_Feature ("target name", Token_Ptr); Node1 := P_Name; return Node1; @@ -3396,7 +3465,7 @@ package body Ch4 is procedure Build_Iterated_Element_Association; -- If the iterator includes a key expression or a filter, it is - -- an Ada_2020 Iterator_Element_Association within a container + -- an Ada 2022 Iterator_Element_Association within a container -- aggregate. ---------------------------------------- @@ -3432,7 +3501,7 @@ package body Ch4 is Save_Scan_State (State); -- A lookahead is necessary to differentiate between the - -- Ada 2012 form with a choice list, and the Ada 202x element + -- Ada 2012 form with a choice list, and the Ada 2022 element -- iterator form, recognized by the presence of "OF". Other -- disambiguation requires context and is done during semantic -- analysis. Note that "for X in E" is syntactically ambiguous: @@ -3463,7 +3532,7 @@ package body Ch4 is if Token = Tok_Use then - -- Ada_2020 Key-expression is present, rewrite node as an + -- Ada 2022 Key-expression is present, rewrite node as an -- Iterated_Element_Association. Scan; -- past USE @@ -3471,7 +3540,7 @@ package body Ch4 is Set_Key_Expression (Assoc_Node, P_Expression); elsif Present (Filter) then - -- A loop_parameter_specification also indicates an Ada_2020 + -- A loop_parameter_specification also indicates an Ada 2022 -- construct, in contrast with a subtype indication used in -- array aggregates. @@ -3481,7 +3550,7 @@ package body Ch4 is TF_Arrow; Set_Expression (Assoc_Node, P_Expression); - elsif Ada_Version >= Ada_2020 + elsif Ada_Version >= Ada_2022 and then Token = Tok_Of then Restore_Scan_State (State); @@ -3504,7 +3573,7 @@ package body Ch4 is Set_Expression (Assoc_Node, P_Expression); end if; - Error_Msg_Ada_2020_Feature ("iterated component", Token_Ptr); + Error_Msg_Ada_2022_Feature ("iterated component", Token_Ptr); return Assoc_Node; end P_Iterated_Component_Association; @@ -3689,7 +3758,7 @@ package body Ch4 is Result : constant Node_Id := Make_Expression_With_Actions (Loc, Actions, Expression); begin - Error_Msg_Ada_2020_Feature ("declare expression", Loc); + Error_Msg_Ada_2022_Feature ("declare expression", Loc); return Result; end; |