2014-02-19 Robert Dewar <dewar@adacore.com>
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Feb 2014 10:42:16 +0000 (10:42 +0000)
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Feb 2014 10:42:16 +0000 (10:42 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@207883 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/exp_ch4.adb
gcc/ada/sinfo.ads

index 478b5ff..1892dbf 100644 (file)
@@ -1,5 +1,11 @@
 2014-02-19  Robert Dewar  <dewar@adacore.com>
 
+       * 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  <dewar@adacore.com>
+
        * 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.
 
index 43dc991..b9ff98c 100644 (file)
@@ -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);
 
index 4feed59..ee35965 100644 (file)
@@ -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 --
       --------------------------------------