diff options
author | Ed Schonberg <schonberg@adacore.com> | 2020-07-13 16:29:56 -0400 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-10-20 03:21:30 -0400 |
commit | f3f1debe1b79b736cb1a29a11c06f63cee92ad06 (patch) | |
tree | 49149bac72599b5cd1f75f29692a10ad773f22bf | |
parent | 797c14b5cd592ee5ded30f4c002a18e8a76de7d9 (diff) | |
download | gcc-f3f1debe1b79b736cb1a29a11c06f63cee92ad06.zip gcc-f3f1debe1b79b736cb1a29a11c06f63cee92ad06.tar.gz gcc-f3f1debe1b79b736cb1a29a11c06f63cee92ad06.tar.bz2 |
[Ada] Ada_2020: Further code cleanup for container aggregates
gcc/ada/
* exp_aggr.adb (Expand_Iterated_Component): Reorganize code to
ensure that Loop_Id is properly initialized on all paths, and
remove code duplication.
-rw-r--r-- | gcc/ada/exp_aggr.adb | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 01e5c83..7bdd11b 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -6905,6 +6905,7 @@ package body Exp_Aggr is L_Range : Node_Id; L_Iteration_Scheme : Node_Id; Loop_Stat : Node_Id; + Params : List_Id; Stats : List_Id; begin @@ -6936,31 +6937,39 @@ package body Exp_Aggr is Loop_Parameter_Specification => Loop_Parameter_Specification (Comp)); Loop_Id := - Make_Defining_Identifier (Loc, - Chars => Chars (Defining_Identifier - (Loop_Parameter_Specification (Comp)))); + Make_Defining_Identifier (Loc, + Chars => Chars (Defining_Identifier + (Loop_Parameter_Specification (Comp)))); Set_Defining_Identifier - (Loop_Parameter_Specification - (L_Iteration_Scheme), Loop_Id); + (Loop_Parameter_Specification + (L_Iteration_Scheme), Loop_Id); end if; + else - elsif Present (Iterator_Specification (Comp)) then - L_Iteration_Scheme := - Make_Iteration_Scheme (Loc, - Iterator_Specification => Iterator_Specification (Comp)); + -- Iterated_Component_Association. - else - L_Range := Relocate_Node (First (Discrete_Choices (Comp))); Loop_Id := Make_Defining_Identifier (Loc, Chars => Chars (Defining_Identifier (Comp))); - L_Iteration_Scheme := - Make_Iteration_Scheme (Loc, - Loop_Parameter_Specification => - Make_Loop_Parameter_Specification (Loc, - Defining_Identifier => Loop_Id, - Discrete_Subtype_Definition => L_Range)); + if Present (Iterator_Specification (Comp)) then + L_Iteration_Scheme := + Make_Iteration_Scheme (Loc, + Iterator_Specification => Iterator_Specification (Comp)); + + else + -- Loop_Parameter_Specifcation is parsed with a choice list. + -- where the range is the first (and only) choice. + + L_Range := Relocate_Node (First (Discrete_Choices (Comp))); + + L_Iteration_Scheme := + Make_Iteration_Scheme (Loc, + Loop_Parameter_Specification => + Make_Loop_Parameter_Specification (Loc, + Defining_Identifier => Loop_Id, + Discrete_Subtype_Definition => L_Range)); + end if; end if; -- Build insertion statement. For a positional aggregate, only the @@ -6983,23 +6992,19 @@ package body Exp_Aggr is -- possibly with a specified key_expression. if Present (Key_Expr) then - Stats := New_List - (Make_Procedure_Call_Statement (Loc, - Name => New_Occurrence_Of (Entity (Add_Named_Subp), Loc), - Parameter_Associations => - New_List (New_Occurrence_Of (Temp, Loc), - New_Copy_Tree (Key_Expr), - New_Copy_Tree (Expr)))); - + Params := New_List (New_Occurrence_Of (Temp, Loc), + New_Copy_Tree (Key_Expr), + New_Copy_Tree (Expr)); else - Stats := New_List - (Make_Procedure_Call_Statement (Loc, - Name => New_Occurrence_Of (Entity (Add_Named_Subp), Loc), - Parameter_Associations => - New_List (New_Occurrence_Of (Temp, Loc), - New_Occurrence_Of (Loop_Id, Loc), - New_Copy_Tree (Expr)))); + Params := New_List (New_Occurrence_Of (Temp, Loc), + New_Occurrence_Of (Loop_Id, Loc), + New_Copy_Tree (Expr)); end if; + + Stats := New_List + (Make_Procedure_Call_Statement (Loc, + Name => New_Occurrence_Of (Entity (Add_Named_Subp), Loc), + Parameter_Associations => Params)); end if; Loop_Stat := Make_Implicit_Loop_Statement |