]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/exp_ch7.ads
exp_ch5.adb, [...]: Rename...
[thirdparty/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 -- Copyright (C) 1992-2008, 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 Needs_Finalization (T : Entity_Id) return Boolean;
61 -- True if T potentially needs finalization actions. True if T is
62 -- controlled, or has subcomponents. Also True if T is a class-wide type,
63 -- because some type extension might add controlled subcomponents, except
64 -- that if pragma Restrictions (No_Finalization) applies, this is False for
65 -- class-wide types.
66
67 function CW_Or_Has_Controlled_Part (T : Entity_Id) return Boolean;
68 -- True if T is a class-wide type, or if it has controlled parts ("part"
69 -- means T or any of its subcomponents). This is the same as
70 -- Needs_Finalization, except when pragma Restrictions (No_Finalization)
71 -- applies, in which case we know that class-wide objects do not contain
72 -- controlled parts.
73
74 function Find_Final_List
75 (E : Entity_Id;
76 Ref : Node_Id := Empty) return Node_Id;
77 -- E is an entity representing a controlled object, a controlled type or a
78 -- scope. If Ref is not empty, it is a reference to a controlled record,
79 -- the closest Final list is in the controller component of the record
80 -- containing Ref otherwise this function returns a reference to the final
81 -- list attached to the closest dynamic scope (that can be E itself)
82 -- creating this final list if necessary.
83
84 function Has_New_Controlled_Component (E : Entity_Id) return Boolean;
85 -- E is a type entity. Give the same result as Has_Controlled_Component
86 -- except for tagged extensions where the result is True only if the
87 -- latest extension contains a controlled component.
88
89 function Make_Attach_Call
90 (Obj_Ref : Node_Id;
91 Flist_Ref : Node_Id;
92 With_Attach : Node_Id) return Node_Id;
93 -- Attach the referenced object to the referenced Final Chain 'Flist_Ref'
94 -- With_Attach is an expression of type Short_Short_Integer which can be
95 -- either '0' to signify no attachment, '1' for attachment to a simply
96 -- linked list or '2' for attachment to a doubly linked list.
97
98 function Make_Init_Call
99 (Ref : Node_Id;
100 Typ : Entity_Id;
101 Flist_Ref : Node_Id;
102 With_Attach : Node_Id) return List_Id;
103 -- Ref is an expression (with no-side effect and is not required to have
104 -- been previously analyzed) that references the object to be initialized.
105 -- Typ is the expected type of Ref, which is either a controlled type
106 -- (Is_Controlled) or a type with controlled components (Has_Controlled).
107 -- With_Attach is an integer expression which is the attachment level,
108 -- see System.Finalization_Implementation.Attach_To_Final_List for the
109 -- documentation of Nb_Link.
110 --
111 -- This function will generate the appropriate calls to make sure that the
112 -- objects referenced by Ref are initialized. The generated code is quite
113 -- different for an IS_Controlled type or a HAS_Controlled type, but this
114 -- is not the problem for the caller, the details are in the body.
115
116 function Make_Adjust_Call
117 (Ref : Node_Id;
118 Typ : Entity_Id;
119 Flist_Ref : Node_Id;
120 With_Attach : Node_Id;
121 Allocator : Boolean := False) return List_Id;
122 -- Ref is an expression (with no-side effect and is not required to have
123 -- been previously analyzed) that references the object to be adjusted. Typ
124 -- is the expected type of Ref, which is a controlled type (Is_Controlled)
125 -- or a type with controlled components (Has_Controlled). With_Attach is an
126 -- integer expression giving the attachment level (see documentation of
127 -- Attach_To_Final_List.Nb_Link param documentation in s-finimp.ads.
128 -- Note: if Typ is Finalize_Storage_Only and the object is at library
129 -- level, then With_Attach will be ignored, and a zero link level will be
130 -- passed to Attach_To_Final_List.
131 --
132 -- This function will generate the appropriate calls to make sure that the
133 -- objects referenced by Ref are adjusted. The generated code is quite
134 -- different depending on the fact the type IS_Controlled or HAS_Controlled
135 -- but this is not the problem of the caller, the details are in the body.
136 -- The objects must be attached when the adjust takes place after an
137 -- initialization expression but not when it takes place after a regular
138 -- assignment.
139 --
140 -- If Allocator is True, we are adjusting a newly-created object. The
141 -- existing chaining pointers should not be left unchanged, because they
142 -- may come from a bit-for-bit copy of those from an initializing object.
143 -- So, when this flag is True, if the chaining pointers should otherwise
144 -- be left unset, instead they are reset to null.
145
146 function Make_Final_Call
147 (Ref : Node_Id;
148 Typ : Entity_Id;
149 With_Detach : Node_Id) return List_Id;
150 -- Ref is an expression (with no-side effect and is not required to have
151 -- been previously analyzed) that references the object to be Finalized.
152 -- Typ is the expected type of Ref, which is a controlled type
153 -- (Is_Controlled) or a type with controlled components (Has_Controlled).
154 -- With_Detach is a boolean expression indicating whether to detach the
155 -- controlled object from whatever finalization list it is currently
156 -- attached to.
157 --
158 -- This function will generate the appropriate calls to make sure that the
159 -- objects referenced by Ref are finalized. The generated code is quite
160 -- different depending on the fact the type IS_Controlled or HAS_Controlled
161 -- but this is not the problem of the caller, the details are in the body.
162 -- The objects must be detached when finalizing an unchecked deallocated
163 -- object but not when finalizing the target of an assignment, it is not
164 -- necessary either on scope exit.
165
166 procedure Expand_Ctrl_Function_Call (N : Node_Id);
167 -- Expand a call to a function returning a controlled value. That is to
168 -- say attach the result of the call to the current finalization list,
169 -- which is the one of the transient scope created for such constructs.
170
171 function Make_Handler_For_Ctrl_Operation (Loc : Source_Ptr) return Node_Id;
172 -- Generate an implicit exception handler with an 'others' choice,
173 -- converting any occurrence to a raise of Program_Error.
174
175 --------------------------------------------
176 -- Task and Protected Object finalization --
177 --------------------------------------------
178
179 function Cleanup_Array
180 (N : Node_Id;
181 Obj : Node_Id;
182 Typ : Entity_Id) return List_Id;
183 -- Generate loops to finalize any tasks or simple protected objects that
184 -- are subcomponents of an array.
185
186 function Cleanup_Protected_Object
187 (N : Node_Id;
188 Ref : Node_Id) return Node_Id;
189 -- Generate code to finalize a protected object without entries
190
191 function Cleanup_Record
192 (N : Node_Id;
193 Obj : Node_Id;
194 Typ : Entity_Id) return List_Id;
195 -- For each subcomponent of a record that contains tasks or simple
196 -- protected objects, generate the appropriate finalization call.
197
198 function Cleanup_Task
199 (N : Node_Id;
200 Ref : Node_Id) return Node_Id;
201 -- Generate code to finalize a task
202
203 function Has_Simple_Protected_Object (T : Entity_Id) return Boolean;
204 -- Check whether composite type contains a simple protected component
205
206 function Is_Simple_Protected_Type (T : Entity_Id) return Boolean;
207 -- Check whether argument is a protected type without entries. Protected
208 -- types with entries are controlled, and their cleanup is handled by the
209 -- standard finalization machinery. For simple protected types we generate
210 -- inline code to release their locks.
211
212 --------------------------------
213 -- Transient Scope Management --
214 --------------------------------
215
216 procedure Expand_Cleanup_Actions (N : Node_Id);
217 -- Expand the necessary stuff into a scope to enable finalization of local
218 -- objects and deallocation of transient data when exiting the scope. N is
219 -- a "scope node" that is to say one of the following: N_Block_Statement,
220 -- N_Subprogram_Body, N_Task_Body, N_Entry_Body.
221
222 procedure Establish_Transient_Scope (N : Node_Id; Sec_Stack : Boolean);
223 -- Push a new transient scope on the scope stack. N is the node responsible
224 -- for the need of a transient scope. If Sec_Stack is True then the
225 -- secondary stack is brought in, otherwise it isn't.
226
227 function Node_To_Be_Wrapped return Node_Id;
228 -- return the node to be wrapped if the current scope is transient
229
230 procedure Store_Before_Actions_In_Scope (L : List_Id);
231 -- Append the list L of actions to the end of the before-actions store in
232 -- the top of the scope stack
233
234 procedure Store_After_Actions_In_Scope (L : List_Id);
235 -- Append the list L of actions to the beginning of the after-actions store
236 -- in the top of the scope stack
237
238 procedure Wrap_Transient_Declaration (N : Node_Id);
239 -- N is an object declaration. Expand the finalization calls after the
240 -- declaration and make the outer scope being the transient one.
241
242 procedure Wrap_Transient_Expression (N : Node_Id);
243 -- N is a sub-expression. Expand a transient block around an expression
244
245 procedure Wrap_Transient_Statement (N : Node_Id);
246 -- N is a statement. Expand a transient block around an instruction
247
248 end Exp_Ch7;