From 3a845e077b5cafd292efa58e859c10546e399603 Mon Sep 17 00:00:00 2001 From: Robert Dewar Date: Wed, 19 Feb 2014 10:42:16 +0000 Subject: exp_ch4.adb (Expand_N_Expression_With_Actions): Make sure declarations get properly inserted in Modify_Tree_For_C mode. 2014-02-19 Robert Dewar * exp_ch4.adb (Expand_N_Expression_With_Actions): Make sure declarations get properly inserted in Modify_Tree_For_C mode. * sinfo.ads: Minor comment addition. From-SVN: r207883 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/exp_ch4.adb | 32 +++++++++++++++++++++++++++++++- gcc/ada/sinfo.ads | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-) (limited to 'gcc') diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 478b5ff..1892dbf 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,11 @@ 2014-02-19 Robert Dewar + * exp_ch4.adb (Expand_N_Expression_With_Actions): Make sure + declarations get properly inserted in Modify_Tree_For_C mode. + * sinfo.ads: Minor comment addition. + +2014-02-19 Robert Dewar + * par-ch9.adb, exp_ch5.adb, sem_ch5.adb, exp_attr.adb, sem_util.adb, sem_util.ads, sem_ch13.adb, sem_ch13.ads: Minor reformatting. diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 43dc991..b9ff98c 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -5067,12 +5067,42 @@ package body Exp_Ch4 is -------------------------------------- procedure Expand_N_Expression_With_Actions (N : Node_Id) is + procedure Insert_Declaration (Decl : Node_Id); + -- This is like Insert_Action, but inserts outside the expression in + -- which N appears. This is needed, because otherwise we can end up + -- inserting a declaration in the actions of a short circuit, and that + -- will not do, because that's likely where we (the expression with + -- actions) node came from the first place. We are only inserting a + -- declaration with no side effects, so it is harmless (and needed) + -- to insert at a higher point in the tree. + function Process_Action (Act : Node_Id) return Traverse_Result; -- Inspect and process a single action of an expression_with_actions for -- transient controlled objects. If such objects are found, the routine -- generates code to clean them up when the context of the expression is -- evaluated or elaborated. + ------------------------ + -- Insert_Declaration -- + ------------------------ + + procedure Insert_Declaration (Decl : Node_Id) is + P : Node_Id; + + begin + -- Climb out of the current expression + + P := Decl; + loop + exit when Nkind (Parent (P)) not in N_Subexpr; + P := Parent (P); + end loop; + + -- Now do the insertion + + Insert_Action (P, Decl); + end Insert_Declaration; + -------------------- -- Process_Action -- -------------------- @@ -5135,7 +5165,7 @@ package body Exp_Ch4 is Exp := Expression (Act); Set_Constant_Present (Act, False); Set_Expression (Act, Empty); - Insert_Action (N, Relocate_Node (Act)); + Insert_Declaration (Relocate_Node (Act)); Loc := Sloc (Act); diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads index 4feed59..ee35965 100644 --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -2925,6 +2925,10 @@ package Sinfo is -- Discrete_Subtype_Definitions (List2) -- Component_Definition (Node4) + -- Note: although the language allows the full syntax for discrete + -- subtype definitions (i.e. a discrete subtype indication or a range), + -- in the generated tree, we always rewrite these as N_Range nodes. + -------------------------------------- -- 3.6 Discrete Subtype Definition -- -------------------------------------- -- cgit v1.1