diff options
Diffstat (limited to 'gcc/ada/exp_ch5.adb')
-rw-r--r-- | gcc/ada/exp_ch5.adb | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index fd75b158449..d7f30991fca 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -3178,11 +3178,13 @@ package body Exp_Ch5 is -- Determine the advancement and initialization steps for the -- cursor. - -- Must verify that the container has a reverse iterator ??? + -- Analysis of the expanded loop will verify that the container + -- has a reverse iterator. if Reverse_Present (I_Spec) then Name_Init := Name_Last; Name_Step := Name_Previous; + else Name_Init := Name_First; Name_Step := Name_Next; @@ -3231,7 +3233,7 @@ package body Exp_Ch5 is Make_Selected_Component (Loc, Prefix => New_Occurrence_Of (Pack, Loc), Selector_Name => - Make_Identifier (Loc, Name_Has_Element)), + Make_Identifier (Loc, Name_Has_Element)), Parameter_Associations => New_List ( @@ -3248,20 +3250,19 @@ package body Exp_Ch5 is -- I : Iterator_Type renames Container; -- C : Pack.Cursor_Type := Container.[First | Last]; - declare - Decl1 : Node_Id; - Decl2 : Node_Id; + Insert_Action (N, + Make_Object_Renaming_Declaration (Loc, + Defining_Identifier => Iterator, + Subtype_Mark => New_Occurrence_Of (Iter_Type, Loc), + Name => Relocate_Node (Name (I_Spec)))); - begin - Decl1 := - Make_Object_Renaming_Declaration (Loc, - Defining_Identifier => Iterator, - Subtype_Mark => New_Occurrence_Of (Iter_Type, Loc), - Name => Relocate_Node (Name (I_Spec))); + -- Create declaration for cursor - -- Create declaration for cursor + declare + Decl : Node_Id; - Decl2 := + begin + Decl := Make_Object_Declaration (Loc, Defining_Identifier => Cursor, Object_Definition => @@ -3272,18 +3273,15 @@ package body Exp_Ch5 is Selector_Name => Make_Identifier (Loc, Name_Init))); - Set_Assignment_OK (Decl2); - - Insert_Actions (N, New_List (Decl1, Decl2)); - end; + -- The cursor is only modified in expanded code, so it appears + -- as unassigned to the warning machinery. We must suppress + -- this spurious warning explicitly. - -- The Iterator is not modified in the source, but of course will - -- be updated in the generated code. Indicate that it is actually - -- set to prevent spurious warnings. Ditto for the Cursor, which - -- is modified indirectly in generated code. + Set_Warnings_Off (Cursor); + Set_Assignment_OK (Decl); - Set_Never_Set_In_Source (Iterator, False); - Set_Never_Set_In_Source (Cursor, False); + Insert_Action (N, Decl); + end; -- If the range of iteration is given by a function call that -- returns a container, the finalization actions have been saved |