diff options
author | Ed Schonberg <schonberg@adacore.com> | 2020-05-17 21:02:59 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-07-08 10:55:51 -0400 |
commit | ff49b8053d16b0a565a02400ac0db81e5fd8f2cd (patch) | |
tree | 51744f051e71fbe19f3f25b6c35d31195cf7f21d /gcc/ada/exp_ch5.adb | |
parent | c1fece377a93b1809243280fcbe01b143f105c9c (diff) | |
download | gcc-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/exp_ch5.adb')
-rw-r--r-- | gcc/ada/exp_ch5.adb | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index 6992528..e98fcf7 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -3868,13 +3868,20 @@ package body Exp_Ch5 is Array_Dim : constant Pos := Number_Dimensions (Array_Typ); Id : constant Entity_Id := Defining_Identifier (I_Spec); Loc : constant Source_Ptr := Sloc (Isc); - Stats : constant List_Id := Statements (N); + Stats : List_Id := Statements (N); Core_Loop : Node_Id; Dim1 : Int; Ind_Comp : Node_Id; Iterator : Entity_Id; begin + if Present (Iterator_Filter (I_Spec)) then + pragma Assert (Ada_Version >= Ada_2020); + Stats := New_List (Make_If_Statement (Loc, + Condition => Iterator_Filter (I_Spec), + Then_Statements => Stats)); + end if; + -- for Element of Array loop -- It requires an internally generated cursor to iterate over the array @@ -4145,7 +4152,9 @@ package body Exp_Ch5 is Elem_Typ : constant Entity_Id := Etype (Id); Id_Kind : constant Entity_Kind := Ekind (Id); Loc : constant Source_Ptr := Sloc (N); - Stats : constant List_Id := Statements (N); + + Stats : List_Id := Statements (N); + -- Maybe wrapped in a conditional if a filter is present Cursor : Entity_Id; Decl : Node_Id; @@ -4167,6 +4176,13 @@ package body Exp_Ch5 is -- The package in which the container type is declared begin + if Present (Iterator_Filter (I_Spec)) then + pragma Assert (Ada_Version >= Ada_2020); + Stats := New_List (Make_If_Statement (Loc, + Condition => Iterator_Filter (I_Spec), + Then_Statements => Stats)); + end if; + -- Determine the advancement and initialization steps for the cursor. -- Analysis of the expanded loop will verify that the container has a -- reverse iterator. @@ -4640,11 +4656,20 @@ package body Exp_Ch5 is Loop_Id : constant Entity_Id := Defining_Identifier (LPS); Ltype : constant Entity_Id := Etype (Loop_Id); Btype : constant Entity_Id := Base_Type (Ltype); + Stats : constant List_Id := Statements (N); Expr : Node_Id; Decls : List_Id; New_Id : Entity_Id; begin + if Present (Iterator_Filter (LPS)) then + pragma Assert (Ada_Version >= Ada_2020); + Set_Statements (N, + New_List (Make_If_Statement (Loc, + Condition => Iterator_Filter (LPS), + Then_Statements => Stats))); + end if; + -- Deal with loop over predicates if Is_Discrete_Type (Ltype) @@ -4761,7 +4786,7 @@ package body Exp_Ch5 is Declarations => Decls, Handled_Statement_Sequence => Make_Handled_Sequence_Of_Statements (Loc, - Statements => Statements (N)))), + Statements => Stats))), End_Label => End_Label (N))); @@ -4863,7 +4888,7 @@ package body Exp_Ch5 is end if; end if; - -- When the iteration scheme mentiones attribute 'Loop_Entry, the loop + -- When the iteration scheme mentions attribute 'Loop_Entry, the loop -- is transformed into a conditional block where the original loop is -- the sole statement. Inspect the statements of the nested loop for -- controlled objects. |