aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/par-ch4.adb
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2020-08-23 15:01:15 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2020-10-22 08:11:25 -0400
commitdaaf017932882f96a6572622766c2975dcc93819 (patch)
tree57616da8e46a9402ad851ad6338df7410fd115a9 /gcc/ada/par-ch4.adb
parente354dca60268ea14f3b20fb865b23e27af751022 (diff)
downloadgcc-daaf017932882f96a6572622766c2975dcc93819.zip
gcc-daaf017932882f96a6572622766c2975dcc93819.tar.gz
gcc-daaf017932882f96a6572622766c2975dcc93819.tar.bz2
[Ada] Ada_2020 AI12-0250: Iterator filters in Iterated_Element_Assocations
gcc/ada/ * par-ch4.adb (P_Iterated_Component_Association): If the construct includes an iterator filter it corresponds to an Iterated_Element_Association, so build the proper node for it. * exp_aggr.adb (Expand_Container_Aggregate, Aggregate_Size): If the component is an Iterated_Element_Association, treat it as having a non-static size.
Diffstat (limited to 'gcc/ada/par-ch4.adb')
-rw-r--r--gcc/ada/par-ch4.adb63
1 files changed, 48 insertions, 15 deletions
diff --git a/gcc/ada/par-ch4.adb b/gcc/ada/par-ch4.adb
index 501429d..925da76 100644
--- a/gcc/ada/par-ch4.adb
+++ b/gcc/ada/par-ch4.adb
@@ -3421,11 +3421,37 @@ package body Ch4 is
function P_Iterated_Component_Association return Node_Id is
Assoc_Node : Node_Id;
Choice : Node_Id;
+ Filter : Node_Id := Empty;
Id : Node_Id;
Iter_Spec : Node_Id;
Loop_Spec : Node_Id;
State : Saved_Scan_State;
+ 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
+ -- aggregate.
+
+ ----------------------------------------
+ -- Build_Iterated_Element_Association --
+ ----------------------------------------
+
+ procedure Build_Iterated_Element_Association is
+ begin
+ Choice := First (Discrete_Choices (Assoc_Node));
+ Assoc_Node :=
+ New_Node (N_Iterated_Element_Association, Prev_Token_Ptr);
+ Set_Loop_Parameter_Specification (Assoc_Node, Loop_Spec);
+
+ if Present (Next (Choice)) then
+ Error_Msg_N ("expect loop parameter specification", Choice);
+ end if;
+
+ Remove (Choice);
+ Set_Discrete_Subtype_Definition (Loop_Spec, Choice);
+ Set_Iterator_Filter (Loop_Spec, Filter);
+ end Build_Iterated_Element_Association;
+
-- Start of processing for P_Iterated_Component_Association
begin
@@ -3443,6 +3469,8 @@ package body Ch4 is
-- In addition, if "use" is present after the specification,
-- this is an Iterated_Element_Association that carries a
-- key_expression, and we generate the appropriate node.
+ -- Finally, the Iterated_Element form is reserved for contwiner
+ -- aggregates, and is illegal in array aggregates.
Id := P_Defining_Identifier;
Assoc_Node :=
@@ -3453,29 +3481,34 @@ package body Ch4 is
T_In;
Set_Discrete_Choices (Assoc_Node, P_Discrete_Choice_List);
+ -- The iterator may include a filter.
+
+ if Token = Tok_When then
+ Scan; -- past WHEN
+ Filter := P_Condition;
+ end if;
+
+ -- Build loop_parameter specification.
+
+ Loop_Spec :=
+ New_Node (N_Loop_Parameter_Specification, Prev_Token_Ptr);
+ Set_Defining_Identifier (Loop_Spec, Id);
+
if Token = Tok_Use then
-- 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);
-
- Choice := First (Discrete_Choices (Assoc_Node));
-
- if Present (Next (Choice)) then
- Error_Msg_N ("expect loop parameter specification", Choice);
- end if;
+ Build_Iterated_Element_Association;
+ Set_Key_Expression (Assoc_Node, P_Expression);
- Remove (Choice);
- Set_Discrete_Subtype_Definition (Loop_Spec, Choice);
+ elsif Present (Filter) then
+ -- A loop_Parameter_Specification also indicates an Ada_2020
+ -- conwtruct, in contrast with a subtype indication used in
+ -- array aggregates.
- 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);
+ Build_Iterated_Element_Association;
end if;
TF_Arrow;