Patchwork [Ada] Use Make_Temporary (2)

login
register
mail settings
Submitter Arnaud Charlet
Date June 17, 2010, 10:16 a.m.
Message ID <20100617101614.GA24749@adacore.com>
Download mbox | patch
Permalink /patch/56005/
State New
Headers show

Comments

Arnaud Charlet - June 17, 2010, 10:16 a.m.
This patch is the second of several that replaces calls to
Make_Defining_Identifier, with calls to Make_Temporary where
possible, setting Node where possible. This is an internal
cleanup that does not affect compiler functionality in any
way, so no test needed.

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-06-17  Robert Dewar  <dewar@adacore.com>

	* exp_ch6.adb, exp_ch7.adb, exp_ch5.adb: Use Make_Temporary
	* tbuild.ads (Make_Temporary): More comment updates
	* tbuild.adb: Minor reformatting

Patch

Index: exp_ch5.adb
===================================================================
--- exp_ch5.adb	(revision 160834)
+++ exp_ch5.adb	(working copy)
@@ -516,8 +516,7 @@  package body Exp_Ch5 is
 
       if Nkind (Rhs) = N_String_Literal then
          declare
-            Temp : constant Entity_Id :=
-                     Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
+            Temp : constant Entity_Id := Make_Temporary (Loc, 'T', Rhs);
             Decl : Node_Id;
 
          begin
@@ -1028,13 +1027,8 @@  package body Exp_Ch5 is
          R_Index := First_Index (R_Type);
 
          for J in 1 .. Ndim loop
-            Lnn (J) :=
-              Make_Defining_Identifier (Loc,
-                Chars => New_Internal_Name ('L'));
-
-            Rnn (J) :=
-              Make_Defining_Identifier (Loc,
-                Chars => New_Internal_Name ('R'));
+            Lnn (J) := Make_Temporary (Loc, 'L');
+            Rnn (J) := Make_Temporary (Loc, 'R');
 
             L_Index_Type (J) := Etype (L_Index);
             R_Index_Type (J) := Etype (R_Index);
@@ -1624,8 +1618,7 @@  package body Exp_Ch5 is
             BPAR_Expr : constant Node_Id   := Relocate_Node (Prefix (Lhs));
             BPAR_Typ  : constant Entity_Id := Etype (BPAR_Expr);
             Tnn       : constant Entity_Id :=
-                          Make_Defining_Identifier (Loc,
-                            Chars => New_Internal_Name ('T'));
+                          Make_Temporary (Loc, 'T', BPAR_Expr);
 
          begin
             --  Insert the post assignment first, because we want to copy the
@@ -2848,8 +2841,7 @@  package body Exp_Ch5 is
                      --  Create an access type designating the function's
                      --  result subtype.
 
-                     Ref_Type :=
-                       Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
+                     Ref_Type := Make_Temporary (Loc, 'A');
 
                      Ptr_Type_Decl :=
                        Make_Full_Type_Declaration (Loc,
@@ -2867,9 +2859,7 @@  package body Exp_Ch5 is
                      --  from an implicit access value passed in by the caller
                      --  or from the result of an allocator.
 
-                     Alloc_Obj_Id :=
-                       Make_Defining_Identifier (Loc,
-                         Chars => New_Internal_Name ('R'));
+                     Alloc_Obj_Id := Make_Temporary (Loc, 'R');
                      Set_Etype (Alloc_Obj_Id, Ref_Type);
 
                      Alloc_Obj_Decl :=
@@ -3854,8 +3844,7 @@  package body Exp_Ch5 is
       then
          declare
             Return_Object_Entity : constant Entity_Id :=
-                                     Make_Defining_Identifier (Loc,
-                                       New_Internal_Name ('R'));
+                                     Make_Temporary (Loc, 'R', Exp);
             Obj_Decl : constant Node_Id :=
                          Make_Object_Declaration (Loc,
                            Defining_Identifier => Return_Object_Entity,
@@ -4009,13 +3998,9 @@  package body Exp_Ch5 is
          elsif CW_Or_Has_Controlled_Part (Utyp) then
             declare
                Loc        : constant Source_Ptr := Sloc (N);
-               Temp       : constant Entity_Id :=
-                              Make_Defining_Identifier (Loc,
-                                Chars => New_Internal_Name ('R'));
-               Acc_Typ    : constant Entity_Id :=
-                              Make_Defining_Identifier (Loc,
-                                Chars => New_Internal_Name ('A'));
+               Acc_Typ    : constant Entity_Id := Make_Temporary (Loc, 'A');
                Alloc_Node : Node_Id;
+               Temp       : Entity_Id;
 
             begin
                Set_Ekind (Acc_Typ, E_Access_Type);
@@ -4031,13 +4016,15 @@  package body Exp_Ch5 is
                    Expression =>
                      Make_Qualified_Expression (Loc,
                        Subtype_Mark => New_Reference_To (Etype (Exp), Loc),
-                       Expression => Relocate_Node (Exp)));
+                       Expression   => Relocate_Node (Exp)));
 
                --  We do not want discriminant checks on the declaration,
                --  given that it gets its value from the allocator.
 
                Set_No_Initialization (Alloc_Node);
 
+               Temp := Make_Temporary (Loc, 'R', Alloc_Node);
+
                Insert_List_Before_And_Analyze (N, New_List (
                  Make_Full_Type_Declaration (Loc,
                    Defining_Identifier => Acc_Typ,
@@ -4118,18 +4105,18 @@  package body Exp_Ch5 is
 
          else
             declare
+               ExpR       : constant Node_Id   := Relocate_Node (Exp);
                Result_Id  : constant Entity_Id :=
-                              Make_Defining_Identifier (Loc,
-                                Chars => New_Internal_Name ('R'));
-               Result_Exp : constant Node_Id :=
+                              Make_Temporary (Loc, 'R', ExpR);
+               Result_Exp : constant Node_Id   :=
                               New_Reference_To (Result_Id, Loc);
-               Result_Obj : constant Node_Id :=
+               Result_Obj : constant Node_Id   :=
                               Make_Object_Declaration (Loc,
                                 Defining_Identifier => Result_Id,
                                 Object_Definition   =>
                                   New_Reference_To (R_Type, Loc),
                                 Constant_Present    => True,
-                                Expression          => Relocate_Node (Exp));
+                                Expression          => ExpR);
 
             begin
                Set_Assignment_OK (Result_Obj);
@@ -4213,16 +4200,16 @@  package body Exp_Ch5 is
         or else Is_Possibly_Unaligned_Object (Exp)
       then
          declare
-            Tnn : constant Entity_Id :=
-                    Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
+            ExpR : constant Node_Id   := Relocate_Node (Exp);
+            Tnn  : constant Entity_Id := Make_Temporary (Loc, 'T', ExpR);
          begin
             Insert_Action (Exp,
               Make_Object_Declaration (Loc,
                 Defining_Identifier => Tnn,
                 Constant_Present    => True,
                 Object_Definition   => New_Occurrence_Of (R_Type, Loc),
-                Expression          => Relocate_Node (Exp)),
-                Suppress => All_Checks);
+                Expression          => ExpR),
+              Suppress            => All_Checks);
             Rewrite (Exp, New_Occurrence_Of (Tnn, Loc));
          end;
       end if;
@@ -4255,8 +4242,8 @@  package body Exp_Ch5 is
 
          else
             declare
-               Tnn : constant Entity_Id :=
-                       Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
+               ExpR : constant Node_Id   := Relocate_Node (Exp);
+               Tnn  : constant Entity_Id := Make_Temporary (Loc, 'T', ExpR);
 
             begin
                --  For a complex expression of an elementary type, capture
@@ -4268,7 +4255,7 @@  package body Exp_Ch5 is
                       Defining_Identifier => Tnn,
                       Constant_Present    => True,
                       Object_Definition   => New_Occurrence_Of (R_Type, Loc),
-                      Expression          => Relocate_Node (Exp)),
+                      Expression          => ExpR),
                     Suppress => All_Checks);
 
                   Rewrite (Exp, New_Occurrence_Of (Tnn, Loc));
@@ -4281,7 +4268,7 @@  package body Exp_Ch5 is
                     Make_Object_Renaming_Declaration (Loc,
                       Defining_Identifier => Tnn,
                       Subtype_Mark        => New_Occurrence_Of (R_Type, Loc),
-                      Name                => Relocate_Node (Exp)),
+                      Name                => ExpR),
                     Suppress => All_Checks);
 
                   Rewrite (Exp, New_Occurrence_Of (Tnn, Loc));
@@ -4421,8 +4408,7 @@  package body Exp_Ch5 is
       --  Save the Tag in a local variable Tag_Tmp
 
       if Save_Tag then
-         Tag_Tmp :=
-           Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
+         Tag_Tmp := Make_Temporary (Loc, 'A');
 
          Append_To (Res,
            Make_Object_Declaration (Loc,
@@ -4461,8 +4447,7 @@  package body Exp_Ch5 is
                      New_Reference_To (Controller_Component (T), Loc));
             end if;
 
-            Prev_Tmp :=
-              Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
+            Prev_Tmp := Make_Temporary (Loc, 'B');
 
             Append_To (Res,
               Make_Object_Declaration (Loc,
@@ -4477,9 +4462,7 @@  package body Exp_Ch5 is
                       Unchecked_Convert_To (RTE (RE_Finalizable), Ctrl_Ref),
                     Selector_Name => Make_Identifier (Loc, Name_Prev))));
 
-            Next_Tmp :=
-              Make_Defining_Identifier (Loc,
-                Chars => New_Internal_Name ('C'));
+            Next_Tmp := Make_Temporary (Loc, 'C');
 
             Append_To (Res,
               Make_Object_Declaration (Loc,
@@ -4638,9 +4621,7 @@  package body Exp_Ch5 is
                      Make_Integer_Literal (Loc,
                        Intval => System_Storage_Unit));
 
-               Range_Type :=
-                 Make_Defining_Identifier (Loc,
-                   New_Internal_Name ('G'));
+               Range_Type := Make_Temporary (Loc, 'G');
 
                Append_To (Res,
                  Make_Subtype_Declaration (Loc,
@@ -4659,9 +4640,7 @@  package body Exp_Ch5 is
 
                Append_To (Res,
                  Make_Subtype_Declaration (Loc,
-                   Defining_Identifier =>
-                     Make_Defining_Identifier (Loc,
-                       New_Internal_Name ('S')),
+                   Defining_Identifier => Make_Temporary (Loc, 'S'),
                    Subtype_Indication  =>
                      Make_Subtype_Indication (Loc,
                        Subtype_Mark =>
@@ -4673,9 +4652,7 @@  package body Exp_Ch5 is
 
                --  type A is access S
 
-               Opaque_Type :=
-                 Make_Defining_Identifier (Loc,
-                   Chars => New_Internal_Name ('A'));
+               Opaque_Type := Make_Temporary (Loc, 'A');
 
                Append_To (Res,
                  Make_Full_Type_Declaration (Loc,
@@ -4721,9 +4698,7 @@  package body Exp_Ch5 is
                   --  Last index before hole: determined by position of the
                   --  _Controller.Prev component.
 
-                  Last_Before_Hole :=
-                    Make_Defining_Identifier (Loc,
-                      New_Internal_Name ('L'));
+                  Last_Before_Hole := Make_Temporary (Loc, 'L');
 
                   Append_To (Res,
                     Make_Object_Declaration (Loc,
@@ -4731,7 +4706,8 @@  package body Exp_Ch5 is
                       Object_Definition   => New_Occurrence_Of (
                         RTE (RE_Storage_Offset), Loc),
                       Constant_Present    => True,
-                      Expression          => Make_Op_Add (Loc,
+                      Expression          =>
+                        Make_Op_Add (Loc,
                           Make_Attribute_Reference (Loc,
                             Prefix => Prev_Ref,
                             Attribute_Name => Name_Position),
@@ -4756,9 +4732,7 @@  package body Exp_Ch5 is
 
                   --  First index after hole
 
-                  First_After_Hole :=
-                    Make_Defining_Identifier (Loc,
-                      New_Internal_Name ('F'));
+                  First_After_Hole := Make_Temporary (Loc, 'F');
 
                   Append_To (Res,
                     Make_Object_Declaration (Loc,
Index: exp_ch7.adb
===================================================================
--- exp_ch7.adb	(revision 160834)
+++ exp_ch7.adb	(working copy)
@@ -586,9 +586,7 @@  package body Exp_Ch7 is
          --  Here we generate the required loop
 
          else
-            Index :=
-              Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
-
+            Index := Make_Temporary (Loc, 'J');
             Append (New_Reference_To (Index, Loc), Index_List);
 
             return New_List (
@@ -1162,7 +1160,7 @@  package body Exp_Ch7 is
         and then not Sec_Stack_Needed_For_Return (Current_Scope)
         and then VM_Target = No_VM
       then
-         Mark := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
+         Mark := Make_Temporary (Loc, 'M');
          Append_To (New_Decls,
            Make_Object_Declaration (Loc,
              Defining_Identifier => Mark,
@@ -1785,9 +1783,7 @@  package body Exp_Ch7 is
                      end if;
                   end if;
 
-                  Id :=
-                    Make_Defining_Identifier (Flist_Loc,
-                      Chars => New_Internal_Name ('F'));
+                  Id := Make_Temporary (Flist_Loc, 'F');
                end;
 
                Set_Finalization_Chain_Entity (S, Id);
@@ -3438,7 +3434,7 @@  package body Exp_Ch7 is
       --       Fxxx : Finalizable_Ptr renames Lxxx.F;
 
       if Present (Finalization_Chain_Entity (S)) then
-         LC := Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
+         LC := Make_Temporary (Loc, 'L');
 
          --  Use the Sloc of the first declaration of N's containing list, to
          --  maintain monotonicity of source-line stepping during debugging.
Index: tbuild.ads
===================================================================
--- tbuild.ads	(revision 160893)
+++ tbuild.ads	(working copy)
@@ -180,15 +180,19 @@  package Tbuild is
      (Loc          : Source_Ptr;
       Id           : Character;
       Related_Node : Node_Id := Empty) return Entity_Id;
-   --  This function should be used for all cases where a temporary is
-   --  built with a name to be obtained by New_Internal_Name (here Id is
-   --  the character passed as the argument to New_Internal_Name). Loc
-   --  is the location for the Sloc value of the resulting Entity.
+   --  This function should be used for all cases where a defining identifier
+   --  is to be built with a name to be obtained by New_Internal_Name (here Id
+   --  is the character passed as the argument to New_Internal_Name). Loc is
+   --  the location for the Sloc value of the resulting Entity. Note that this
+   --  can be used for all kinds of temporary defining identifiers used in
+   --  expansion (objects, subtypes, functions etc).
    --
-   --  Related_Node is used when the identifier is capturing the value of
-   --  an expression (e.g. an aggregate). It should be set whenever possible
-   --  to point to the expression that is being captured. This is provided
-   --  to get better error messages, especially from CodePeer reports.
+   --  Related_Node is used when the defining identifier is for an object that
+   --  captures the value of an expression (e.g. an aggregate). It should be
+   --  set whenever possible to point to the expression that is being captured.
+   --  This is provided to get better error messages, e.g. from CodePeer.
+   --
+   --  Make_Temp_Id would probably be a better name for this function???
 
    function Make_Unsuppress_Block
      (Loc   : Source_Ptr;
Index: tbuild.adb
===================================================================
--- tbuild.adb	(revision 160893)
+++ tbuild.adb	(working copy)
@@ -686,7 +686,6 @@  package body Tbuild is
       Loc    : Source_Ptr) return Node_Id
    is
       Occurrence : Node_Id;
-
    begin
       Occurrence := New_Node (N_Identifier, Loc);
       Set_Chars (Occurrence, Chars (Def_Id));
Index: exp_ch6.adb
===================================================================
--- exp_ch6.adb	(revision 160834)
+++ exp_ch6.adb	(working copy)
@@ -808,9 +808,7 @@  package body Exp_Ch6 is
       Elm := First_Elmt (Var_List);
       while Present (Elm) loop
          Var := Node (Elm);
-         Ent :=
-           Make_Defining_Identifier (Loc,
-             Chars => New_Internal_Name ('S'));
+         Ent := Make_Temporary (Loc, 'S');
          Append_Elmt (Ent, Shad_List);
 
          --  Insert a declaration for this temporary at the start of the
@@ -966,9 +964,7 @@  package body Exp_Ch6 is
             return;
          end if;
 
-         Temp :=
-           Make_Defining_Identifier (Loc,
-             Chars => New_Internal_Name ('T'));
+         Temp := Make_Temporary (Loc, 'T');
 
          --  Use formal type for temp, unless formal type is an unconstrained
          --  array, in which case we don't have to worry about bounds checks,
@@ -1220,9 +1216,7 @@  package body Exp_Ch6 is
 
          Reset_Packed_Prefix;
 
-         Temp :=
-           Make_Defining_Identifier (Loc,
-             Chars => New_Internal_Name ('T'));
+         Temp := Make_Temporary (Loc, 'T');
          Incod  := Relocate_Node (Actual);
          Outcod := New_Copy_Tree (Incod);
 
@@ -1387,9 +1381,7 @@  package body Exp_Ch6 is
             return Entity (Actual);
 
          else
-            Var :=
-              Make_Defining_Identifier (Loc,
-                Chars => New_Internal_Name ('T'));
+            Var := Make_Temporary (Loc, 'T');
 
             N_Node :=
               Make_Object_Renaming_Declaration (Loc,
@@ -3312,8 +3304,8 @@  package body Exp_Ch6 is
 
       procedure Make_Exit_Label;
       --  Build declaration for exit label to be used in Return statements,
-      --  sets Exit_Lab (the label node) and Lab_Decl (corresponding implcit
-      --  declaration).
+      --  sets Exit_Lab (the label node) and Lab_Decl (corresponding implicit
+      --  declaration). Does nothing if Exit_Lab already set.
 
       function Process_Formals (N : Node_Id) return Traverse_Result;
       --  Replace occurrence of a formal with the corresponding actual, or the
@@ -3343,20 +3335,15 @@  package body Exp_Ch6 is
       ---------------------
 
       procedure Make_Exit_Label is
+         Lab_Ent : Entity_Id;
       begin
-         --  Create exit label for subprogram if one does not exist yet
-
          if No (Exit_Lab) then
-            Lab_Id :=
-              Make_Identifier (Loc,
-                Chars => New_Internal_Name ('L'));
-            Set_Entity (Lab_Id,
-              Make_Defining_Identifier (Loc, Chars (Lab_Id)));
+            Lab_Ent := Make_Temporary (Loc, 'L');
+            Lab_Id  := New_Reference_To (Lab_Ent, Loc);
             Exit_Lab := Make_Label (Loc, Lab_Id);
-
             Lab_Decl :=
               Make_Implicit_Label_Declaration (Loc,
-                Defining_Identifier  => Entity (Lab_Id),
+                Defining_Identifier  => Lab_Ent,
                 Label_Construct      => Exit_Lab);
          end if;
       end Make_Exit_Label;
@@ -3793,9 +3780,7 @@  package body Exp_Ch6 is
             end if;
 
          else
-            Temp :=
-              Make_Defining_Identifier (Loc,
-                Chars => New_Internal_Name ('C'));
+            Temp := Make_Temporary (Loc, 'C');
 
             --  If the actual for an in/in-out parameter is a view conversion,
             --  make it into an unchecked conversion, given that an untagged
@@ -3883,8 +3868,7 @@  package body Exp_Ch6 is
          else
             --  Replace call with temporary and create its declaration
 
-            Temp :=
-              Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
+            Temp := Make_Temporary (Loc, 'C');
             Set_Is_Internal (Temp);
 
             --  For the unconstrained case, the generated temporary has the
@@ -4610,10 +4594,8 @@  package body Exp_Ch6 is
          --  define _object later on.
 
          declare
-            Decls : List_Id;
-            Obj_Ptr : constant Entity_Id :=  Make_Defining_Identifier (Loc,
-                                               Chars =>
-                                                 New_Internal_Name ('T'));
+            Decls   : List_Id;
+            Obj_Ptr : constant Entity_Id :=  Make_Temporary (Loc, 'T');
 
          begin
             Decls := New_List (
@@ -4623,7 +4605,7 @@  package body Exp_Ch6 is
                      Make_Access_To_Object_Definition (Loc,
                        Subtype_Indication =>
                          New_Reference_To
-                      (Corresponding_Record_Type (Scop), Loc))));
+                           (Corresponding_Record_Type (Scop), Loc))));
 
             Insert_Actions (N, Decls);
             Insert_Actions (N, Freeze_Entity (Obj_Ptr, Sloc (N)));
@@ -5117,8 +5099,7 @@  package body Exp_Ch6 is
          --  Create a new access object and initialize it to the result of the
          --  new uninitialized allocator.
 
-         Return_Obj_Access :=
-           Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
+         Return_Obj_Access := Make_Temporary (Loc, 'R', Allocator);
          Set_Etype (Return_Obj_Access, Acc_Type);
 
          Insert_Action (Allocator,
@@ -5251,9 +5232,7 @@  package body Exp_Ch6 is
 
          --  Create a temporary object to hold the function result
 
-         Return_Obj_Id :=
-           Make_Defining_Identifier (Loc,
-             Chars => New_Internal_Name ('R'));
+         Return_Obj_Id := Make_Temporary (Loc, 'R');
          Set_Etype (Return_Obj_Id, Result_Subt);
 
          Return_Obj_Decl :=
@@ -5406,8 +5385,7 @@  package body Exp_Ch6 is
 
       --  Create an access type designating the function's result subtype
 
-      Ptr_Typ :=
-        Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
+      Ptr_Typ := Make_Temporary (Loc, 'A');
 
       Ptr_Typ_Decl :=
         Make_Full_Type_Declaration (Loc,
@@ -5422,7 +5400,7 @@  package body Exp_Ch6 is
       --  Finally, create an access object initialized to a reference to the
       --  function call.
 
-      Obj_Id := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
+      Obj_Id := Make_Temporary (Loc, 'R');
       Set_Etype (Obj_Id, Ptr_Typ);
 
       Obj_Decl :=
@@ -5684,8 +5662,7 @@  package body Exp_Ch6 is
 
       --  Create an access type designating the function's result subtype
 
-      Ref_Type :=
-        Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
+      Ref_Type := Make_Temporary (Loc, 'A');
 
       Ptr_Typ_Decl :=
         Make_Full_Type_Declaration (Loc,
@@ -5712,15 +5689,13 @@  package body Exp_Ch6 is
       --  Finally, create an access object initialized to a reference to the
       --  function call.
 
-      Def_Id :=
-        Make_Defining_Identifier (Loc,
-          Chars => New_Internal_Name ('R'));
-      Set_Etype (Def_Id, Ref_Type);
-
       New_Expr :=
         Make_Reference (Loc,
           Prefix => Relocate_Node (Func_Call));
 
+      Def_Id := Make_Temporary (Loc, 'R', New_Expr);
+      Set_Etype (Def_Id, Ref_Type);
+
       Insert_After_And_Analyze (Ptr_Typ_Decl,
         Make_Object_Declaration (Loc,
           Defining_Identifier => Def_Id,
@@ -5744,8 +5719,7 @@  package body Exp_Ch6 is
 
          Rewrite (Object_Decl,
            Make_Object_Renaming_Declaration (Loc,
-             Defining_Identifier => Make_Defining_Identifier (Loc,
-                                      New_Internal_Name ('D')),
+             Defining_Identifier => Make_Temporary (Loc, 'D'),
              Access_Definition   => Empty,
              Subtype_Mark        => New_Occurrence_Of (Result_Subt, Loc),
              Name                => Call_Deref));