1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Types
; use Types
;
31 procedure Expand_N_Package_Body
(N
: Node_Id
);
32 procedure Expand_N_Package_Declaration
(N
: Node_Id
);
34 ------------------------------
35 -- Finalization Management --
36 ------------------------------
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
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
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.
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.
57 function Controller_Component
(Typ
: Entity_Id
) return Entity_Id
;
58 -- Returns the entity of the component whose name is 'Name_uController'
60 function Controlled_Type
(T
: Entity_Id
) return Boolean;
61 -- True if T potentially needs finalization actions
63 function Find_Final_List
65 Ref
: Node_Id
:= Empty
)
67 -- E is an entity representing a controlled object, a controlled type
68 -- or a scope. If Ref is not empty, it is a reference to a controlled
69 -- record, the closest Final list is in the controller component of
70 -- the record containing Ref otherwise this function returns a
71 -- reference to the final list attached to the closest dynamic scope
72 -- (that can be E itself) creating this final list if necessary.
74 function Has_New_Controlled_Component
(E
: Entity_Id
) return Boolean;
75 -- E is a type entity. Give the same resul as Has_Controlled_Component
76 -- except for tagged extensions where the result is True only if the
77 -- latest extension contains a controlled component.
79 function Make_Attach_Call
82 With_Attach
: Node_Id
)
84 -- Attach the referenced object to the referenced Final Chain
85 -- 'Flist_Ref' With_Attach is an expression of type Short_Short_Integer
86 -- which can be either '0' to signify no attachment, '1' for
87 -- attachement to a simply linked list or '2' for attachement to a
88 -- doubly linked list.
90 function Make_Init_Call
94 With_Attach
: Node_Id
)
96 -- Ref is an expression (with no-side effect and is not required to
97 -- have been previously analyzed) that references the object to be
98 -- initialized. Typ is the expected type of Ref, which is a controlled
99 -- type (Is_Controlled) or a type with controlled components
100 -- (Has_Controlled). With_Attach is an integer expression representing
101 -- the level of attachment, see Attach_To_Final_Lists' NB_Link param
102 -- documentation in s-finimp.ads.
104 -- This function will generate the appropriate calls to make
105 -- sure that the objects referenced by Ref are initialized. The
106 -- generate code is quite different depending on the fact the type
107 -- IS_Controlled or HAS_Controlled but this is not the problem of the
108 -- caller, the details are in the body.
110 function Make_Adjust_Call
114 With_Attach
: Node_Id
)
116 -- Ref is an expression (with no-side effect and is not required to
117 -- have been previously analyzed) that references the object to be
118 -- adjusted. Typ is the expected type of Ref, which is a controlled
119 -- type (Is_Controlled) or a type with controlled components
120 -- (Has_Controlled). With_Attach is an integer expression representing
121 -- the level of attachment, see Attach_To_Final_Lists' NB_Link param
122 -- documentation in s-finimp.ads.
124 -- This function will generate the appropriate calls to make
125 -- sure that the objects referenced by Ref are adjusted. The generated
126 -- code is quite different depending on the fact the type IS_Controlled
127 -- or HAS_Controlled but this is not the problem of the caller, the
128 -- details are in the body. The objects must be attached when the adjust
129 -- takes place after an initialization expression but not when it takes
130 -- place after a regular assignment.
132 function Make_Final_Call
135 With_Detach
: Node_Id
)
137 -- Ref is an expression (with no-side effect and is not required
138 -- to have been previously analyzed) that references the object to
139 -- 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). With_Attach is an integer
142 -- expression representing the level of attachment, see
143 -- Attach_To_Final_Lists' NB_Link param documentation in
146 -- This function will generate the appropriate calls to make
147 -- sure that the objects referenced by Ref are finalized. The generated
148 -- code is quite different depending on the fact the type IS_Controlled
149 -- or HAS_Controlled but this is not the problem of the caller, the
150 -- details are in the body. The objects must be detached when finalizing
151 -- an unchecked deallocated object but not when finalizing the target of
152 -- an assignment, it is not necessary either on scope exit.
154 procedure Expand_Ctrl_Function_Call
(N
: Node_Id
);
155 -- Expand a call to a function returning a controlled value. That is to
156 -- say attach the result of the call to the current finalization list,
157 -- which is the one of the transient scope created for such constructs.
159 --------------------------------------------
160 -- Task and Protected Object finalization --
161 --------------------------------------------
163 function Cleanup_Array
168 -- Generate loops to finalize any tasks or simple protected objects
169 -- that are subcomponents of an array.
171 function Cleanup_Protected_Object
175 -- Generate code to finalize a protected object without entries.
177 function Cleanup_Record
182 -- For each subcomponent of a record that contains tasks or simple
183 -- protected objects, generate the appropriate finalization call.
185 function Cleanup_Task
189 -- Generate code to finalize a task.
191 function Has_Simple_Protected_Object
(T
: Entity_Id
) return Boolean;
192 -- Check whether composite type contains a simple protected component.
194 function Is_Simple_Protected_Type
(T
: Entity_Id
) return Boolean;
195 -- Check whether argument is a protected type without entries.
196 -- Protected types with entries are controlled, and their cleanup
197 -- is handled by the standard finalization machinery. For simple
198 -- protected types we generate inline code to release their locks.
200 --------------------------------
201 -- Transient Scope Management --
202 --------------------------------
204 procedure Expand_Cleanup_Actions
(N
: Node_Id
);
205 -- Expand the necessary stuff into a scope to enable finalization of local
206 -- objects and deallocation of transient data when exiting the scope. N is
207 -- a "scope node" that is to say one of the following: N_Block_Statement,
208 -- N_Subprogram_Body, N_Task_Body, N_Entry_Body.
210 procedure Establish_Transient_Scope
(N
: Node_Id
; Sec_Stack
: Boolean);
211 -- Push a new transient scope on the scope stack. N is the node responsible
212 -- for the need of a transient scope. If Sec_Stack is True then the
213 -- secondary stack is brought in, otherwise it isn't.
215 function Node_To_Be_Wrapped
return Node_Id
;
216 -- return the node to be wrapped if the current scope is transient.
218 procedure Store_Before_Actions_In_Scope
(L
: List_Id
);
219 -- Append the list L of actions to the end of the before-actions store
220 -- in the top of the scope stack
222 procedure Store_After_Actions_In_Scope
(L
: List_Id
);
223 -- Append the list L of actions to the beginning of the after-actions
224 -- store in the top of the scope stack
226 procedure Wrap_Transient_Declaration
(N
: Node_Id
);
227 -- N is an object declaration. Expand the finalization calls after the
228 -- declaration and make the outer scope beeing the transient one.
230 procedure Wrap_Transient_Expression
(N
: Node_Id
);
231 -- N is a sub-expression. Expand a transient block around an expression
233 procedure Wrap_Transient_Statement
(N
: Node_Id
);
234 -- N is a statement. Expand a transient block around an instruction