OSDN Git Service

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