OSDN Git Service

2007-08-16 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.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 --          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Namet; use Namet;
28 with Types; use Types;
29
30 package Exp_Ch7 is
31
32    procedure Expand_N_Package_Body        (N : Node_Id);
33    procedure Expand_N_Package_Declaration (N : Node_Id);
34
35    -----------------------------
36    -- Finalization Management --
37    -----------------------------
38
39    function In_Finalization_Root (E : Entity_Id) return Boolean;
40    --  True if current scope is in package System.Finalization_Root. Used
41    --  to avoid certain expansions that would involve circularity in the
42    --  Rtsfind mechanism.
43
44    procedure Build_Final_List (N : Node_Id; Typ : Entity_Id);
45    --  Build finalization list for anonymous access types, and for access
46    --  types that are frozen before their designated types are known to
47    --  be controlled.
48
49    procedure Build_Controlling_Procs (Typ : Entity_Id);
50    --  Typ is a record, and array type having controlled components.
51    --  Create the procedures Deep_Initialize, Deep_Adjust and Deep_Finalize
52    --  that take care of finalization management at run-time.
53
54    procedure Build_Late_Proc (Typ : Entity_Id; Nam : Name_Id);
55    --  Build one controlling procedure when a late body overrides one of
56    --  the controlling operations.
57
58    function Controller_Component (Typ : Entity_Id) return Entity_Id;
59    --  Returns the entity of the component whose name is 'Name_uController'
60
61    function Controlled_Type (T : Entity_Id) return Boolean;
62    --  True if T potentially needs finalization actions
63
64    function CW_Or_Controlled_Type (T : Entity_Id) return Boolean;
65    --  True if T is either a potentially controlled type or a class-wide type.
66    --  Note that in normal mode, class-wide types are potentially controlled so
67    --  this function is different from Controlled_Type only under restrictions
68    --  No_Finalization.
69
70    function Find_Final_List
71      (E   : Entity_Id;
72       Ref : Node_Id := Empty) return Node_Id;
73    --  E is an entity representing a controlled object, a controlled type or a
74    --  scope. If Ref is not empty, it is a reference to a controlled record,
75    --  the closest Final list is in the controller component of the record
76    --  containing Ref otherwise this function returns a reference to the final
77    --  list attached to the closest dynamic scope (that can be E itself)
78    --  creating this final list if necessary.
79
80    function Has_New_Controlled_Component (E : Entity_Id) return Boolean;
81    --  E is a type entity. Give the same resul as Has_Controlled_Component
82    --  except for tagged extensions where the result is True only if the
83    --  latest extension contains a controlled component.
84
85    function Make_Attach_Call
86      (Obj_Ref     : Node_Id;
87       Flist_Ref   : Node_Id;
88       With_Attach : Node_Id) return Node_Id;
89    --  Attach the referenced object to the referenced Final Chain 'Flist_Ref'
90    --  With_Attach is an expression of type Short_Short_Integer which can be
91    --  either '0' to signify no attachment, '1' for attachement to a simply
92    --  linked list or '2' for attachement to a doubly linked list.
93
94    function Make_Init_Call
95      (Ref         : Node_Id;
96       Typ         : Entity_Id;
97       Flist_Ref   : Node_Id;
98       With_Attach : Node_Id) return List_Id;
99    --  Ref is an expression (with no-side effect and is not required to have
100    --  been previously analyzed) that references the object to be initialized.
101    --  Typ is the expected type of Ref, which is either a controlled type
102    --  (Is_Controlled) or a type with controlled components (Has_Controlled).
103    --  With_Attach is an integer expression which is the attchment level,
104    --  see System.Finalization_Implementation.Attach_To_Final_List for the
105    --  documentation of Nb_Link.
106    --
107    --  This function will generate the appropriate calls to make sure that the
108    --  objects referenced by Ref are initialized. The generated code is quite
109    --  different for an IS_Controlled type or a HAS_Controlled type, but this
110    --  is not the problem for the caller, the details are in the body.
111
112    function Make_Adjust_Call
113      (Ref         : Node_Id;
114       Typ         : Entity_Id;
115       Flist_Ref   : Node_Id;
116       With_Attach : Node_Id;
117       Allocator   : Boolean := False) return List_Id;
118    --  Ref is an expression (with no-side effect and is not required to have
119    --  been previously analyzed) that references the object to be adjusted. Typ
120    --  is the expected type of Ref, which is a controlled type (Is_Controlled)
121    --  or a type with controlled components (Has_Controlled). With_Attach is an
122    --  integer expression giving the attachment level (see documentation of
123    --  Attach_To_Final_List.Nb_Link param documentation in s-finimp.ads.
124    --  Note: if Typ is Finalize_Storage_Only and the object is at library
125    --  level, then With_Attach will be ignored, and a zero link level will be
126    --  passed to Attach_To_Final_List.
127    --
128    --  This function will generate the appropriate calls to make sure that the
129    --  objects referenced by Ref are adjusted. The generated code is quite
130    --  different depending on the fact the type IS_Controlled or HAS_Controlled
131    --  but this is not the problem of the caller, the details are in the body.
132    --  The objects must be attached when the adjust takes place after an
133    --  initialization expression but not when it takes place after a regular
134    --  assignment.
135    --
136    --  If Allocator is True, we are adjusting a newly-created object. The
137    --  existing chaining pointers should not be left unchanged, because they
138    --  may come from a bit-for-bit copy of those from an initializing object.
139    --  So, when this flag is True, if the chaining pointers should otherwise
140    --  be left unset, instead they are reset to null.
141
142    function Make_Final_Call
143      (Ref         : Node_Id;
144       Typ         : Entity_Id;
145       With_Detach : Node_Id) return List_Id;
146    --  Ref is an expression (with no-side effect and is not required to have
147    --  been previously analyzed) that references the object to be Finalized.
148    --  Typ is the expected type of Ref, which is a controlled type
149    --  (Is_Controlled) or a type with controlled components (Has_Controlled).
150    --  With_Detach is a boolean expression indicating whether to detach the
151    --  controlled object from whatever finalization list it is currently
152    --  attached to.
153    --
154    --  This function will generate the appropriate calls to make sure that the
155    --  objects referenced by Ref are finalized. The generated code is quite
156    --  different depending on the fact the type IS_Controlled or HAS_Controlled
157    --  but this is not the problem of the caller, the details are in the body.
158    --  The objects must be detached when finalizing an unchecked deallocated
159    --  object but not when finalizing the target of an assignment, it is not
160    --  necessary either on scope exit.
161
162    procedure Expand_Ctrl_Function_Call (N : Node_Id);
163    --  Expand a call to a function returning a controlled value. That is to
164    --  say attach the result of the call to the current finalization list,
165    --  which is the one of the transient scope created for such constructs.
166
167    function Make_Handler_For_Ctrl_Operation (Loc : Source_Ptr) return Node_Id;
168    --  Generate an implicit exception handler with an 'others' choice,
169    --  converting any occurrence to a raise of Program_Error.
170
171    --------------------------------------------
172    -- Task and Protected Object finalization --
173    --------------------------------------------
174
175    function Cleanup_Array
176      (N   : Node_Id;
177       Obj : Node_Id;
178       Typ : Entity_Id) return List_Id;
179    --  Generate loops to finalize any tasks or simple protected objects that
180    --  are subcomponents of an array.
181
182    function Cleanup_Protected_Object
183      (N   : Node_Id;
184       Ref : Node_Id) return Node_Id;
185    --  Generate code to finalize a protected object without entries
186
187    function Cleanup_Record
188      (N   : Node_Id;
189       Obj : Node_Id;
190       Typ : Entity_Id) return List_Id;
191    --  For each subcomponent of a record that contains tasks or simple
192    --  protected objects, generate the appropriate finalization call.
193
194    function Cleanup_Task
195      (N   : Node_Id;
196       Ref : Node_Id) return Node_Id;
197    --  Generate code to finalize a task
198
199    function Has_Simple_Protected_Object (T : Entity_Id) return Boolean;
200    --  Check whether composite type contains a simple protected component
201
202    function Is_Simple_Protected_Type (T : Entity_Id) return Boolean;
203    --  Check whether argument is a protected type without entries. Protected
204    --  types with entries are controlled, and their cleanup is handled by the
205    --  standard finalization machinery. For simple protected types we generate
206    --  inline code to release their locks.
207
208    --------------------------------
209    -- Transient Scope Management --
210    --------------------------------
211
212    procedure Expand_Cleanup_Actions (N : Node_Id);
213    --  Expand the necessary stuff into a scope to enable finalization of local
214    --  objects and deallocation of transient data when exiting the scope. N is
215    --  a "scope node" that is to say one of the following: N_Block_Statement,
216    --  N_Subprogram_Body, N_Task_Body, N_Entry_Body.
217
218    procedure Establish_Transient_Scope (N : Node_Id; Sec_Stack : Boolean);
219    --  Push a new transient scope on the scope stack. N is the node responsible
220    --  for the need of a transient scope. If Sec_Stack is True then the
221    --  secondary stack is brought in, otherwise it isn't.
222
223    function Node_To_Be_Wrapped return Node_Id;
224    --  return the node to be wrapped if the current scope is transient
225
226    procedure Store_Before_Actions_In_Scope (L : List_Id);
227    --  Append the list L of actions to the end of the before-actions store in
228    --  the top of the scope stack
229
230    procedure Store_After_Actions_In_Scope (L : List_Id);
231    --  Append the list L of actions to the beginning of the after-actions store
232    --  in the top of the scope stack
233
234    procedure Wrap_Transient_Declaration (N : Node_Id);
235    --  N is an object declaration. Expand the finalization calls after the
236    --  declaration and make the outer scope beeing the transient one.
237
238    procedure Wrap_Transient_Expression (N : Node_Id);
239    --  N is a sub-expression. Expand a transient block around an expression
240
241    procedure Wrap_Transient_Statement (N : Node_Id);
242    --  N is a statement. Expand a transient block around an instruction
243
244 end Exp_Ch7;