This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[Ada] Improve naming of dynamic tasks (patch)


This patch improves naming of dynamically generated tasks.
Checked in for Ed.

  -Geert

2001-10-10  Ed Schonberg <schonber@gnat.com>

	* exp_ch4.adb (Expand_N_Allocator): Generate meaningful names for
	a dynamic task if the allocator appears in an indexed assignment
	or selected component assignment.
	
	* exp_util.adb (Build_Task_Array_Image, Build_Task_Record_Image): 
	For a dynamic task in an assignment statement, use target of 
	assignment to generate meaningful name.
	
*** exp_ch4.adb	2001/09/23 23:15:31	1.463
--- exp_ch4.adb	2001/10/05 15:43:37	1.464
*************** package body Exp_Ch4 is
*** 1818,1824 ****
                    --  If the context of the allocator is a declaration or
                    --  an assignment, we can generate a meaningful image for
                    --  it, even though subsequent assignments might remove
!                   --  the connection between task and entity.
  
                    if Nkind (Parent (N)) = N_Assignment_Statement then
                       declare
--- 1818,1827 ----
                    --  If the context of the allocator is a declaration or
                    --  an assignment, we can generate a meaningful image for
                    --  it, even though subsequent assignments might remove
!                   --  the connection between task and entity. We build this
!                   --  image when the left-hand side is a simple variable,
!                   --  a simple indexed assignment or a simple selected
!                   --  component.
  
                    if Nkind (Parent (N)) = N_Assignment_Statement then
                       declare
*************** package body Exp_Ch4 is
*** 1832,1837 ****
--- 1835,1847 ----
                                   New_Occurrence_Of
                                     (Entity (Nam), Sloc (Nam)), T);
  
+                         elsif (Nkind (Nam) = N_Indexed_Component
+                                 or else Nkind (Nam) = N_Selected_Component)
+                           and then Is_Entity_Name (Prefix (Nam))
+                         then
+                            Decls :=
+                              Build_Task_Image_Decls (
+                              Loc, Nam, Etype (Prefix (Nam)));
                          else
                             Decls := Build_Task_Image_Decls (Loc, T, T);
                          end if;

*** exp_util.adb	2001/09/23 23:19:39	1.331
--- exp_util.adb	2001/10/05 15:43:39	1.332
*************** package body Exp_Util is
*** 64,74 ****
     function Build_Task_Array_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id)
        return   Node_Id;
     --  Build function to generate the image string for a task that is an
     --  array component, concatenating the images of each index. To avoid
     --  storage leaks, the string is built with successive slice assignments.
  
     function Build_Task_Image_Function
       (Loc   : Source_Ptr;
--- 64,78 ----
     function Build_Task_Array_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id;
!       Dyn    : Boolean := False)
        return   Node_Id;
     --  Build function to generate the image string for a task that is an
     --  array component, concatenating the images of each index. To avoid
     --  storage leaks, the string is built with successive slice assignments.
+    --  The flag Dyn indicates whether this is called for the initialization
+    --  procedure of an array of tasks, or for the name of a dynamically
+    --  created task that is assigned to an indexed component.
  
     function Build_Task_Image_Function
       (Loc   : Source_Ptr;
*************** package body Exp_Util is
*** 94,103 ****
     function Build_Task_Record_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id)
        return Node_Id;
     --  Build function to generate the image string for a task that is a
     --  record component. Concatenate name of variable with that of selector.
  
     function Make_CW_Equivalent_Type
       (T    : Entity_Id;
--- 98,111 ----
     function Build_Task_Record_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id;
!       Dyn    : Boolean := False)
        return Node_Id;
     --  Build function to generate the image string for a task that is a
     --  record component. Concatenate name of variable with that of selector.
+    --  The flag Dyn indicates whether this is called for the initialization
+    --  procedure of record with task components, or for a dynamically
+    --  created task that is assigned to a selected component.
  
     function Make_CW_Equivalent_Type
       (T    : Entity_Id;
*************** package body Exp_Util is
*** 326,342 ****
     --  The generated function has the following structure:
  
     --  function F return Task_Image_Type is
!    --     Prefix : string := Task_Id.all;
     --     T1 : String := Index1'Image (Val1);
     --     ...
     --     Tn : String := indexn'image (Valn);
     --     Len : Integer := T1'Length + ... + Tn'Length + n + 1;
     --     --  Len includes commas and the end parentheses.
     --     Res : String (1..Len);
!    --     Pos : Integer := Prefix'Length;
     --
     --  begin
!    --     Res (1 .. Pos) := Prefix;
     --     Pos := Pos + 1;
     --     Res (Pos)    := '(';
     --     Pos := Pos + 1;
--- 334,350 ----
     --  The generated function has the following structure:
  
     --  function F return Task_Image_Type is
!    --     Pref : string := Task_Id.all;
     --     T1 : String := Index1'Image (Val1);
     --     ...
     --     Tn : String := indexn'image (Valn);
     --     Len : Integer := T1'Length + ... + Tn'Length + n + 1;
     --     --  Len includes commas and the end parentheses.
     --     Res : String (1..Len);
!    --     Pos : Integer := Pref'Length;
     --
     --  begin
!    --     Res (1 .. Pos) := Pref;
     --     Pos := Pos + 1;
     --     Res (Pos)    := '(';
     --     Pos := Pos + 1;
*************** package body Exp_Util is
*** 357,363 ****
     function Build_Task_Array_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id)
        return   Node_Id
     is
        Dims : constant Nat := Number_Dimensions (A_Type);
--- 365,372 ----
     function Build_Task_Array_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id;
!       Dyn    : Boolean := False)
        return   Node_Id
     is
        Dims : constant Nat := Number_Dimensions (A_Type);
*************** package body Exp_Util is
*** 375,383 ****
        Pos : Entity_Id;
        --  Running index for substring assignments
  
!       Prefix : Entity_Id;
        --  Name of enclosing variable, prefix of resulting name
  
        Res : Entity_Id;
        --  String to hold result
  
--- 384,395 ----
        Pos : Entity_Id;
        --  Running index for substring assignments
  
!       Pref : Entity_Id;
        --  Name of enclosing variable, prefix of resulting name
  
+       P_Nam : Node_Id;
+       --  string expression for Pref.
+ 
        Res : Entity_Id;
        --  String to hold result
  
*************** package body Exp_Util is
*** 394,408 ****
        Stats : List_Id := New_List;
  
     begin
!       Prefix := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
  
        Append_To (Decls,
          Make_Object_Declaration (Loc,
!           Defining_Identifier => Prefix,
            Object_Definition => New_Occurrence_Of (Standard_String, Loc),
!           Expression =>
!             Make_Explicit_Dereference (Loc,
!               Prefix => Make_Identifier (Loc, Name_uTask_Id))));
  
        Indx := First_Index (A_Type);
        Val  := First (Expressions (Id_Ref));
--- 406,431 ----
        Stats : List_Id := New_List;
  
     begin
!       Pref := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
! 
!       --  For a dynamic task, the name comes from the target variable.
!       --  For a static one it is a formal of the enclosing init_proc.
! 
!       if Dyn then
!          Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
!          P_Nam :=
!            Make_String_Literal (Loc, Strval => String_From_Name_Buffer);
!       else
!          P_Nam :=
!            Make_Explicit_Dereference (Loc,
!              Prefix => Make_Identifier (Loc, Name_uTask_Id));
!       end if;
  
        Append_To (Decls,
          Make_Object_Declaration (Loc,
!           Defining_Identifier => Pref,
            Object_Definition => New_Occurrence_Of (Standard_String, Loc),
!           Expression => P_Nam));
  
        Indx := First_Index (A_Type);
        Val  := First (Expressions (Id_Ref));
*************** package body Exp_Util is
*** 436,442 ****
             Make_Attribute_Reference (Loc,
               Attribute_Name => Name_Length,
               Prefix =>
!                New_Occurrence_Of (Prefix, Loc),
               Expressions => New_List (Make_Integer_Literal (Loc, 1))));
  
        for J in 1 .. Dims loop
--- 459,465 ----
             Make_Attribute_Reference (Loc,
               Attribute_Name => Name_Length,
               Prefix =>
!                New_Occurrence_Of (Pref, Loc),
               Expressions => New_List (Make_Integer_Literal (Loc, 1))));
  
        for J in 1 .. Dims loop
*************** package body Exp_Util is
*** 451,457 ****
                  Expressions => New_List (Make_Integer_Literal (Loc, 1))));
        end loop;
  
!       Build_Task_Image_Prefix (Loc, Len, Res, Pos, Prefix, Sum, Decls, Stats);
  
        Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
  
--- 474,480 ----
                  Expressions => New_List (Make_Integer_Literal (Loc, 1))));
        end loop;
  
!       Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
  
        Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
  
*************** package body Exp_Util is
*** 560,570 ****
        A_Type : Entity_Id)
        return   List_Id
     is
!       T_Id  : Entity_Id := Empty;
!       Decl  : Node_Id;
!       Decls : List_Id   := New_List;
!       Expr  : Node_Id   := Empty;
!       Fun   : Node_Id   := Empty;
  
     begin
        --  If Discard_Names is in effect, generate a dummy declaration only.
--- 583,596 ----
        A_Type : Entity_Id)
        return   List_Id
     is
!       T_Id   : Entity_Id := Empty;
!       Decl   : Node_Id;
!       Decls  : List_Id   := New_List;
!       Expr   : Node_Id   := Empty;
!       Fun    : Node_Id   := Empty;
!       Is_Dyn : constant Boolean :=
!         Nkind (Parent (Id_Ref)) = N_Assignment_Statement
!          and then Nkind (Expression (Parent (Id_Ref))) = N_Allocator;
  
     begin
        --  If Discard_Names is in effect, generate a dummy declaration only.
*************** package body Exp_Util is
*** 607,620 ****
              T_Id :=
                Make_Defining_Identifier (Loc,
                  New_External_Name (Chars (Selector_Name (Id_Ref)), 'I'));
!             Fun := Build_Task_Record_Image (Loc, Id_Ref, A_Type);
  
           elsif Nkind (Id_Ref) = N_Indexed_Component then
              T_Id :=
                Make_Defining_Identifier (Loc,
                  New_External_Name (Chars (A_Type), 'I'));
  
!             Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type);
           end if;
        end if;
  
--- 633,646 ----
              T_Id :=
                Make_Defining_Identifier (Loc,
                  New_External_Name (Chars (Selector_Name (Id_Ref)), 'I'));
!             Fun := Build_Task_Record_Image (Loc, Id_Ref, A_Type, Is_Dyn);
  
           elsif Nkind (Id_Ref) = N_Indexed_Component then
              T_Id :=
                Make_Defining_Identifier (Loc,
                  New_External_Name (Chars (A_Type), 'I'));
  
!             Fun := Build_Task_Array_Image (Loc, Id_Ref, A_Type, Is_Dyn);
           end if;
        end if;
  
*************** package body Exp_Util is
*** 760,766 ****
     function Build_Task_Record_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id)
        return   Node_Id
     is
        Len : Entity_Id;
--- 786,793 ----
     function Build_Task_Record_Image
       (Loc    : Source_Ptr;
        Id_Ref : Node_Id;
!       A_Type : Entity_Id;
!       Dyn    : Boolean := False)
        return   Node_Id
     is
        Len : Entity_Id;
*************** package body Exp_Util is
*** 772,780 ****
        Res : Entity_Id;
        --  String to hold result
  
!       Prefix : Entity_Id;
        --  Name of enclosing variable, prefix of resulting name
  
        Sum : Node_Id;
        --  Expression to compute total size of string.
  
--- 799,810 ----
        Res : Entity_Id;
        --  String to hold result
  
!       Pref : Entity_Id;
        --  Name of enclosing variable, prefix of resulting name
  
+       P_Nam : Node_Id;
+       --  string expression for Pref.
+ 
        Sum : Node_Id;
        --  Expression to compute total size of string.
  
*************** package body Exp_Util is
*** 785,799 ****
        Stats : List_Id := New_List;
  
     begin
!       Prefix := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
  
        Append_To (Decls,
          Make_Object_Declaration (Loc,
!           Defining_Identifier => Prefix,
            Object_Definition => New_Occurrence_Of (Standard_String, Loc),
!           Expression =>
!             Make_Explicit_Dereference (Loc,
!               Prefix => Make_Identifier (Loc, Name_uTask_Id))));
  
        Sel := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
  
--- 815,840 ----
        Stats : List_Id := New_List;
  
     begin
!       Pref := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
! 
!       --  For a dynamic task, the name comes from the target variable.
!       --  For a static one it is a formal of the enclosing init_proc.
  
+       if Dyn then
+          Get_Name_String (Chars (Entity (Prefix (Id_Ref))));
+          P_Nam :=
+            Make_String_Literal (Loc, Strval => String_From_Name_Buffer);
+       else
+          P_Nam :=
+            Make_Explicit_Dereference (Loc,
+              Prefix => Make_Identifier (Loc, Name_uTask_Id));
+       end if;
+ 
        Append_To (Decls,
          Make_Object_Declaration (Loc,
!           Defining_Identifier => Pref,
            Object_Definition => New_Occurrence_Of (Standard_String, Loc),
!           Expression => P_Nam));
  
        Sel := Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
  
*************** package body Exp_Util is
*** 815,824 ****
             Make_Attribute_Reference (Loc,
               Attribute_Name => Name_Length,
               Prefix =>
!                New_Occurrence_Of (Prefix, Loc),
               Expressions => New_List (Make_Integer_Literal (Loc, 1))));
  
!       Build_Task_Image_Prefix (Loc, Len, Res, Pos, Prefix, Sum, Decls, Stats);
  
        Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
  
--- 856,865 ----
             Make_Attribute_Reference (Loc,
               Attribute_Name => Name_Length,
               Prefix =>
!                New_Occurrence_Of (Pref, Loc),
               Expressions => New_List (Make_Integer_Literal (Loc, 1))));
  
!       Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
  
        Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
  




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]