diff options
author | Ed Schonberg <schonberg@adacore.com> | 2020-07-10 11:13:57 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-10-19 05:53:41 -0400 |
commit | c0bab60bb9d6f56eedc95f77af3d1057b7fff3bb (patch) | |
tree | dab3252a76f14c20c02575c14109ad6d8e477610 /gcc/ada/par-ch4.adb | |
parent | 86b3d0d55f947d8c5328a25b113bb52ae3ac89fa (diff) | |
download | gcc-c0bab60bb9d6f56eedc95f77af3d1057b7fff3bb.zip gcc-c0bab60bb9d6f56eedc95f77af3d1057b7fff3bb.tar.gz gcc-c0bab60bb9d6f56eedc95f77af3d1057b7fff3bb.tar.bz2 |
[Ada] Ada_2020: Implement Key_Expression for named container aggregates
gcc/ada/
* par-ch4.adb: (P_Aggregate_Or_Paren_Expr): Recognize
Iterated_Element_Component.
(P_Iterated_Component_Association): Rebuild node as an Iterated_
Element_Association when Key_Expression is present, and attach
either the Loop_Parameter_Specification or the
Iterator_Specification to the new node.
* sem_aggr.adb: (Resolve_Container_Aggregate):
Resolve_Iterated_Association handles bota Iterated_Component_
and Iterated_Element_Associations, in which case it analyzes and
resoles the orresponding Key_Expression.
* exp_aggr.adb (Expand_Iterated_Component): If a Key_Expression
is present, use it as the required parameter in the call to the
insertion routine for the destination container aggregate. Call
this routine for both kinds of Iterated_Associations.
Diffstat (limited to 'gcc/ada/par-ch4.adb')
-rw-r--r-- | gcc/ada/par-ch4.adb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb index 649c88e..501429d 100644 --- a/gcc/ada/par-ch4.adb +++ b/gcc/ada/par-ch4.adb @@ -1607,8 +1607,11 @@ 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. - elsif Nkind (Expr_Node) = N_Iterated_Component_Association then + elsif Nkind (Expr_Node) in + N_Iterated_Component_Association | N_Iterated_Element_Association + then if No (Assoc_List) then Assoc_List := New_List (Expr_Node); else @@ -3417,6 +3420,7 @@ package body Ch4 is function P_Iterated_Component_Association return Node_Id is Assoc_Node : Node_Id; + Choice : Node_Id; Id : Node_Id; Iter_Spec : Node_Id; Loop_Spec : Node_Id; @@ -3451,15 +3455,25 @@ package body Ch4 is if Token = Tok_Use then - -- Key-expression is present, rewrite node as an + -- Ada_2020 Key-expression is present, rewrite node as an -- iterated_Element_Awwoiation. Scan; -- past USE Loop_Spec := New_Node (N_Loop_Parameter_Specification, Prev_Token_Ptr); Set_Defining_Identifier (Loop_Spec, Id); - Set_Discrete_Subtype_Definition (Loop_Spec, - First (Discrete_Choices (Assoc_Node))); + + Choice := First (Discrete_Choices (Assoc_Node)); + + if Present (Next (Choice)) then + Error_Msg_N ("expect loop parameter specification", Choice); + end if; + + Remove (Choice); + Set_Discrete_Subtype_Definition (Loop_Spec, Choice); + + Assoc_Node := + New_Node (N_Iterated_Element_Association, Prev_Token_Ptr); Set_Loop_Parameter_Specification (Assoc_Node, Loop_Spec); Set_Key_Expression (Assoc_Node, P_Expression); end if; |