aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/par-ch4.adb
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2020-05-17 21:02:59 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2020-07-08 10:55:51 -0400
commitff49b8053d16b0a565a02400ac0db81e5fd8f2cd (patch)
tree51744f051e71fbe19f3f25b6c35d31195cf7f21d /gcc/ada/par-ch4.adb
parentc1fece377a93b1809243280fcbe01b143f105c9c (diff)
downloadgcc-ff49b8053d16b0a565a02400ac0db81e5fd8f2cd.zip
gcc-ff49b8053d16b0a565a02400ac0db81e5fd8f2cd.tar.gz
gcc-ff49b8053d16b0a565a02400ac0db81e5fd8f2cd.tar.bz2
[Ada] Ada_2020 AI12-0250 : Implement Iterator filters.
gcc/ada/ * par.adb (P_Iterator_Specification): Make public for use in other parser subprograms. * par-ch4.adb (P_Iterated_Component_Association): In Ada_2020, recognize use of Iterator_Specification in an element iterator. To simplify disambiguation between the two iterator forms, mark the component association as carrying an Iterator_Specification only when the element iterator (using "OF") is used. * par-ch5.adb (P_Loop_Parameter_Specification): In Ada_2020, parse iterator filter when present. (P_Iterator_Specification): Ditto. Remove declaration of P_Iterator_Specification, now in parent unit. * exp_ch5.adb (Expand_N_Loop_Statement): Apply Iterator filter when present. (Expand_Iterator_Loop_Over_Array): Ditto. (Expand_Iterator_Loop_Over_Container): Ditto. * sem_aggr.adb (Resolve_Array_Aggregate): Emit error nessage if an iterated component association includes a iterator specificcation with an element iterator, i.e. one that uses the OF keyword. * sem_ch5.adb (Analyze_Iterator_Specification): Analyze Iterator filter when present. (Analyze_Loop_Parameter_Specification): Ditto. * sinfo.adb: Suprogram bodies for new syntactic element Iterator_Filter. * sinfo.ads: Add Iterator_Filter to relevant nodes. Structure of Component_Association and Iteroted_Component_Association nodes is modified to take into account the possible presence of an iterator specification in the latter.
Diffstat (limited to 'gcc/ada/par-ch4.adb')
-rw-r--r--gcc/ada/par-ch4.adb38
1 files changed, 33 insertions, 5 deletions
diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb
index 0360212..e79abd1 100644
--- a/gcc/ada/par-ch4.adb
+++ b/gcc/ada/par-ch4.adb
@@ -3402,22 +3402,50 @@ package body Ch4 is
-- ITERATED_COMPONENT_ASSOCIATION ::=
-- for DEFINING_IDENTIFIER in DISCRETE_CHOICE_LIST => EXPRESSION
+ -- for ITERATOR_SPECIFICATION => EXPRESSION
function P_Iterated_Component_Association return Node_Id is
Assoc_Node : Node_Id;
+ Id : Node_Id;
+ State : Saved_Scan_State;
-- Start of processing for P_Iterated_Component_Association
begin
Scan; -- past FOR
+ Save_Scan_State (State);
+
+ -- A lookahead is necessary to differentiate between the
+ -- Ada2012 form with a choice list, and the Ada2020 element
+ -- iterator form, recognized by the presence of "OF". Other
+ -- disambiguation requires context and is done during semantc
+ -- analysis. Note that "for X in E" is syntactically ambiguous:
+ -- if E is a subypte indication this is a loop parameter spec,
+ -- while if E a name it is an iterator_specification, and the
+ -- disambiguation takes place during semantic analysis.
+
+ Id := P_Defining_Identifier;
Assoc_Node :=
New_Node (N_Iterated_Component_Association, Prev_Token_Ptr);
- Set_Defining_Identifier (Assoc_Node, P_Defining_Identifier);
- T_In;
- Set_Discrete_Choices (Assoc_Node, P_Discrete_Choice_List);
- TF_Arrow;
- Set_Expression (Assoc_Node, P_Expression);
+ if Token = Tok_In then
+ Set_Defining_Identifier (Assoc_Node, Id);
+ T_In;
+ Set_Discrete_Choices (Assoc_Node, P_Discrete_Choice_List);
+ TF_Arrow;
+ Set_Expression (Assoc_Node, P_Expression);
+
+ elsif Ada_Version >= Ada_2020
+ and then Token = Tok_Of
+ then
+ Restore_Scan_State (State);
+ Scan; -- past OF
+ Set_Defining_Identifier (Assoc_Node, Id);
+ Set_Iterator_Specification
+ (Assoc_Node, P_Iterator_Specification (Id));
+ TF_Arrow;
+ Set_Expression (Assoc_Node, P_Expression);
+ end if;
if Ada_Version < Ada_2020 then
Error_Msg_SC ("iterated component is an Ada 202x feature");