* ChangeLog: Repair from previous update.
[platform/upstream/gcc.git] / gcc / ada / exp_ch7.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              E X P _ C H 7                               --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                            $Revision: 1.42 $
10 --                                                                          --
11 --          Copyright (C) 1992-2000 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- GNAT was originally developed  by the GNAT team at  New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 with Types; use Types;
30
31 package Exp_Ch7 is
32
33    procedure Expand_N_Package_Body        (N : Node_Id);
34    procedure Expand_N_Package_Declaration (N : Node_Id);
35
36    ------------------------------
37    --  Finalization Management --
38    ------------------------------
39
40    function In_Finalization_Root (E : Entity_Id) return Boolean;
41    --  True if current scope is in package System.Finalization_Root. Used
42    --  to avoid certain expansions that would involve circularity in the
43    --  Rtsfind mechanism.
44
45    procedure Build_Final_List (N : Node_Id; Typ : Entity_Id);
46    --  Build finalization list for anonymous access types, and for access
47    --  types that are frozen before their designated types are known to
48    --  be controlled.
49
50    procedure Build_Controlling_Procs (Typ : Entity_Id);
51    --  Typ is a record, and array type having controlled components.
52    --  Create the procedures Deep_Initialize, Deep_Adjust and Deep_Finalize
53    --  that take care of finalization management at run-time.
54
55    function Controller_Component (Typ : Entity_Id) return Entity_Id;
56    --  Returns the entity of the component whose name is 'Name_uController'
57
58    function Controlled_Type (T : Entity_Id) return Boolean;
59    --  True if T potentially needs finalization actions
60
61    function Find_Final_List
62      (E    : Entity_Id;
63       Ref  : Node_Id := Empty)
64       return Node_Id;
65       --  E is an entity representing a controlled object, a controlled type
66       --  or a scope. If Ref is not empty, it is a reference to a controlled
67       --  record, the closest Final list is in the controller component of
68       --  the record containing Ref otherwise this function returns a
69       --  reference to the final list attached to the closest dynamic scope
70       --  (that can be E itself) creating this final list if necessary.
71
72    function Has_New_Controlled_Component (E : Entity_Id) return Boolean;
73    --  E is a type entity. Give the same resul as Has_Controlled_Component
74    --  except for tagged extensions where the result is True only if the
75    --  latest extension contains a controlled component.
76
77    function Make_Attach_Call
78      (Obj_Ref      : Node_Id;
79       Flist_Ref    : Node_Id;
80       With_Attach  : Node_Id)
81       return         Node_Id;
82    --  Attach the referenced object to the referenced Final Chain
83    --  'Flist_Ref' With_Attach is an expression of type Short_Short_Integer
84    --  which can be either '0' to signify no attachment, '1' for
85    --  attachement to a simply linked list or '2' for attachement to a
86    --  doubly linked list.
87
88    function Make_Init_Call
89      (Ref          : Node_Id;
90       Typ          : Entity_Id;
91       Flist_Ref    : Node_Id;
92       With_Attach  : Node_Id)
93       return         List_Id;
94    --  Ref is an expression (with no-side effect and is not required to
95    --  have been previously analyzed) that references the object to be
96    --  initialized. Typ is the expected type of Ref, which is a controlled
97    --  type (Is_Controlled) or a type with controlled components
98    --  (Has_Controlled). 'Dynamic_Case' controls the way the object is
99    --  attached which is different whether the object is dynamically
100    --  allocated or not.
101    --
102    --  This function will generate the appropriate calls to make
103    --  sure that the objects referenced by Ref are initialized. The
104    --  generate code is quite different depending on the fact the type
105    --  IS_Controlled or HAS_Controlled but this is not the problem of the
106    --  caller, the details are in the body.
107
108    function Make_Adjust_Call
109      (Ref          : Node_Id;
110       Typ          : Entity_Id;
111       Flist_Ref    : Node_Id;
112       With_Attach  : Node_Id)
113       return         List_Id;
114    --  Ref is an expression (with no-side effect and is not required to
115    --  have been previously analyzed) that references the object to be
116    --  adjusted. Typ is the expected type of Ref, which is a controlled
117    --  type (Is_Controlled) or a type with controlled components
118    --  (Has_Controlled).
119    --
120    --  This function will generate the appropriate calls to make
121    --  sure that the objects referenced by Ref are adjusted. The generated
122    --  code is quite different depending on the fact the type IS_Controlled
123    --  or HAS_Controlled but this is not the problem of the caller, the
124    --  details are in the body. If the parameter With_Attach is set to
125    --  True, the finalizable objects involved are attached to the proper
126    --  finalization chain. The objects must be attached when the adjust
127    --  takes place after an initialization expression but not when it takes
128    --  place after a regular assignment.
129    --
130    --  The description of With_Attach is completely obsolete ???
131
132    function Make_Final_Call
133      (Ref         : Node_Id;
134       Typ         : Entity_Id;
135       With_Detach : Node_Id)
136       return        List_Id;
137    --  Ref is an expression (with no-side effect and is not required to
138    --  have been previously analyzed) that references the object
139    --  to be Finalized. Typ is the expected type of Ref, which is a
140    --  controlled type (Is_Controlled) or a type with controlled
141    --  components (Has_Controlled).
142    --
143    --  This function will generate the appropriate calls to make
144    --  sure that the objects referenced by Ref are finalized. The generated
145    --  code is quite different depending on the fact the type IS_Controlled
146    --  or HAS_Controlled but this is not the problem of the caller, the
147    --  details are in the body. If the parameter With_Detach is set to
148    --  True, the finalizable objects involved are detached from the proper
149    --  finalization chain. The objects must be detached when finalizing an
150    --  unchecked deallocated object but not when finalizing the target of
151    --  an assignment, it is not necessary either on scope exit.
152
153    procedure Expand_Ctrl_Function_Call (N : Node_Id);
154    --  Expand a call to a function returning a controlled value. That is to
155    --  say attach the result of the call to the current finalization list,
156    --  which is the one of the transient scope created for such constructs.
157
158    --------------------------------
159    -- Transient Scope Management --
160    --------------------------------
161
162    procedure Expand_Cleanup_Actions (N : Node_Id);
163    --  Expand the necessary stuff into a scope to enable finalization of local
164    --  objects and deallocation of transient data when exiting the scope. N is
165    --  a "scope node" that is to say one of the following: N_Block_Statement,
166    --  N_Subprogram_Body, N_Task_Body, N_Entry_Body.
167
168    procedure Establish_Transient_Scope (N : Node_Id; Sec_Stack : Boolean);
169    --  Push a new transient scope on the scope stack. N is the node responsible
170    --  for the need of a transient scope. If Sec_Stack is True then the
171    --  secondary stack is brought in, otherwise it isn't.
172
173    function Node_To_Be_Wrapped return Node_Id;
174    --  return the node to be wrapped if the current scope is transient.
175
176    procedure Store_Before_Actions_In_Scope (L : List_Id);
177    --  Append the list L of actions to the end of the before-actions store
178    --  in the top of the scope stack
179
180    procedure Store_After_Actions_In_Scope (L : List_Id);
181    --  Append the list L of actions to the beginning of the after-actions
182    --  store in the top of the scope stack
183
184    procedure Wrap_Transient_Declaration (N : Node_Id);
185    --  N is an object declaration. Expand the finalization calls after the
186    --  declaration and make the outer scope beeing the transient one.
187
188    procedure Wrap_Transient_Expression (N : Node_Id);
189    --  N is a sub-expression. Expand a transient block around an expression
190
191    procedure Wrap_Transient_Statement (N : Node_Id);
192    --  N is a statement. Expand a transient block around an instruction
193
194 end Exp_Ch7;