]>
Commit | Line | Data |
---|---|---|
70482933 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- E X P _ C H 7 -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
9de61fcb | 9 | -- Copyright (C) 1992-2005, Free Software Foundation, Inc. -- |
70482933 RK |
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 -- | |
cb5fee25 KC |
19 | -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, -- |
20 | -- Boston, MA 02110-1301, USA. -- | |
70482933 RK |
21 | -- -- |
22 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 23 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
70482933 RK |
24 | -- -- |
25 | ------------------------------------------------------------------------------ | |
26 | ||
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 | ||
0da2c8ac AC |
34 | ----------------------------- |
35 | -- Finalization Management -- | |
36 | ----------------------------- | |
70482933 RK |
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 | ||
07fc65c4 GB |
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 | ||
70482933 RK |
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 Find_Final_List | |
0da2c8ac AC |
64 | (E : Entity_Id; |
65 | Ref : Node_Id := Empty) return Node_Id; | |
66 | -- E is an entity representing a controlled object, a controlled type | |
67 | -- or a scope. If Ref is not empty, it is a reference to a controlled | |
68 | -- record, the closest Final list is in the controller component of | |
69 | -- the record containing Ref otherwise this function returns a | |
70 | -- reference to the final list attached to the closest dynamic scope | |
71 | -- (that can be E itself) creating this final list if necessary. | |
70482933 RK |
72 | |
73 | function Has_New_Controlled_Component (E : Entity_Id) return Boolean; | |
74 | -- E is a type entity. Give the same resul as Has_Controlled_Component | |
75 | -- except for tagged extensions where the result is True only if the | |
76 | -- latest extension contains a controlled component. | |
77 | ||
78 | function Make_Attach_Call | |
0da2c8ac AC |
79 | (Obj_Ref : Node_Id; |
80 | Flist_Ref : Node_Id; | |
81 | With_Attach : Node_Id) return Node_Id; | |
70482933 RK |
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 | |
0da2c8ac AC |
89 | (Ref : Node_Id; |
90 | Typ : Entity_Id; | |
91 | Flist_Ref : Node_Id; | |
92 | With_Attach : Node_Id) return List_Id; | |
70482933 RK |
93 | -- Ref is an expression (with no-side effect and is not required to |
94 | -- have been previously analyzed) that references the object to be | |
95 | -- initialized. Typ is the expected type of Ref, which is a controlled | |
96 | -- type (Is_Controlled) or a type with controlled components | |
fbf5a39b | 97 | -- (Has_Controlled). With_Attach is an integer expression representing |
d9246d2d | 98 | -- the level of attachment, see Attach_To_Final_List's Nb_Link param |
fbf5a39b | 99 | -- documentation in s-finimp.ads. |
70482933 RK |
100 | -- |
101 | -- This function will generate the appropriate calls to make | |
102 | -- sure that the objects referenced by Ref are initialized. The | |
103 | -- generate code is quite different depending on the fact the type | |
104 | -- IS_Controlled or HAS_Controlled but this is not the problem of the | |
105 | -- caller, the details are in the body. | |
106 | ||
107 | function Make_Adjust_Call | |
0da2c8ac AC |
108 | (Ref : Node_Id; |
109 | Typ : Entity_Id; | |
110 | Flist_Ref : Node_Id; | |
dfd99a80 TQ |
111 | With_Attach : Node_Id; |
112 | Allocator : Boolean := False) return List_Id; | |
70482933 RK |
113 | -- Ref is an expression (with no-side effect and is not required to |
114 | -- have been previously analyzed) that references the object to be | |
115 | -- adjusted. Typ is the expected type of Ref, which is a controlled | |
116 | -- type (Is_Controlled) or a type with controlled components | |
fbf5a39b | 117 | -- (Has_Controlled). With_Attach is an integer expression representing |
d9246d2d | 118 | -- the level of attachment, see Attach_To_Final_List's Nb_Link param |
9c8457a7 QO |
119 | -- documentation in s-finimp.ads. Note: if Typ is Finalize_Storage_Only |
120 | -- and the object is at library level, then With_Attach will be ignored, | |
121 | -- and a zero link level will be passed to Attach_To_Final_List. | |
70482933 RK |
122 | -- |
123 | -- This function will generate the appropriate calls to make | |
124 | -- sure that the objects referenced by Ref are adjusted. The generated | |
125 | -- code is quite different depending on the fact the type IS_Controlled | |
126 | -- or HAS_Controlled but this is not the problem of the caller, the | |
fbf5a39b | 127 | -- details are in the body. The objects must be attached when the adjust |
70482933 RK |
128 | -- takes place after an initialization expression but not when it takes |
129 | -- place after a regular assignment. | |
dfd99a80 TQ |
130 | -- |
131 | -- If Allocator is True, we are adjusting a newly-created object. The | |
132 | -- existing chaining pointers should not be left unchanged, because they | |
133 | -- may come from a bit-for-bit copy of those from an initializing object. | |
134 | -- So, when this flag is True, if the chaining pointers should otherwise | |
135 | -- be left unset, instead they are reset to null. | |
70482933 RK |
136 | |
137 | function Make_Final_Call | |
138 | (Ref : Node_Id; | |
139 | Typ : Entity_Id; | |
0da2c8ac | 140 | With_Detach : Node_Id) return List_Id; |
fbf5a39b AC |
141 | -- Ref is an expression (with no-side effect and is not required |
142 | -- to have been previously analyzed) that references the object to | |
143 | -- be Finalized. Typ is the expected type of Ref, which is a | |
70482933 | 144 | -- controlled type (Is_Controlled) or a type with controlled |
d9246d2d AC |
145 | -- components (Has_Controlled). With_Detach is a boolean expression |
146 | -- indicating whether to detach the controlled object from whatever | |
147 | -- finalization list it is currently attached to. | |
70482933 RK |
148 | -- |
149 | -- This function will generate the appropriate calls to make | |
150 | -- sure that the objects referenced by Ref are finalized. The generated | |
151 | -- code is quite different depending on the fact the type IS_Controlled | |
152 | -- or HAS_Controlled but this is not the problem of the caller, the | |
fbf5a39b AC |
153 | -- details are in the body. The objects must be detached when finalizing |
154 | -- an unchecked deallocated object but not when finalizing the target of | |
70482933 RK |
155 | -- an assignment, it is not necessary either on scope exit. |
156 | ||
157 | procedure Expand_Ctrl_Function_Call (N : Node_Id); | |
158 | -- Expand a call to a function returning a controlled value. That is to | |
159 | -- say attach the result of the call to the current finalization list, | |
160 | -- which is the one of the transient scope created for such constructs. | |
161 | ||
fbf5a39b AC |
162 | -------------------------------------------- |
163 | -- Task and Protected Object finalization -- | |
164 | -------------------------------------------- | |
165 | ||
166 | function Cleanup_Array | |
0da2c8ac AC |
167 | (N : Node_Id; |
168 | Obj : Node_Id; | |
169 | Typ : Entity_Id) return List_Id; | |
fbf5a39b AC |
170 | -- Generate loops to finalize any tasks or simple protected objects |
171 | -- that are subcomponents of an array. | |
172 | ||
173 | function Cleanup_Protected_Object | |
0da2c8ac AC |
174 | (N : Node_Id; |
175 | Ref : Node_Id) return Node_Id; | |
9de61fcb | 176 | -- Generate code to finalize a protected object without entries |
fbf5a39b AC |
177 | |
178 | function Cleanup_Record | |
0da2c8ac AC |
179 | (N : Node_Id; |
180 | Obj : Node_Id; | |
181 | Typ : Entity_Id) return List_Id; | |
fbf5a39b AC |
182 | -- For each subcomponent of a record that contains tasks or simple |
183 | -- protected objects, generate the appropriate finalization call. | |
184 | ||
185 | function Cleanup_Task | |
0da2c8ac AC |
186 | (N : Node_Id; |
187 | Ref : Node_Id) return Node_Id; | |
9de61fcb | 188 | -- Generate code to finalize a task |
fbf5a39b AC |
189 | |
190 | function Has_Simple_Protected_Object (T : Entity_Id) return Boolean; | |
9de61fcb | 191 | -- Check whether composite type contains a simple protected component |
fbf5a39b AC |
192 | |
193 | function Is_Simple_Protected_Type (T : Entity_Id) return Boolean; | |
194 | -- Check whether argument is a protected type without entries. | |
195 | -- Protected types with entries are controlled, and their cleanup | |
196 | -- is handled by the standard finalization machinery. For simple | |
197 | -- protected types we generate inline code to release their locks. | |
198 | ||
70482933 RK |
199 | -------------------------------- |
200 | -- Transient Scope Management -- | |
201 | -------------------------------- | |
202 | ||
203 | procedure Expand_Cleanup_Actions (N : Node_Id); | |
204 | -- Expand the necessary stuff into a scope to enable finalization of local | |
205 | -- objects and deallocation of transient data when exiting the scope. N is | |
206 | -- a "scope node" that is to say one of the following: N_Block_Statement, | |
207 | -- N_Subprogram_Body, N_Task_Body, N_Entry_Body. | |
208 | ||
209 | procedure Establish_Transient_Scope (N : Node_Id; Sec_Stack : Boolean); | |
210 | -- Push a new transient scope on the scope stack. N is the node responsible | |
211 | -- for the need of a transient scope. If Sec_Stack is True then the | |
212 | -- secondary stack is brought in, otherwise it isn't. | |
213 | ||
214 | function Node_To_Be_Wrapped return Node_Id; | |
9de61fcb | 215 | -- return the node to be wrapped if the current scope is transient |
70482933 RK |
216 | |
217 | procedure Store_Before_Actions_In_Scope (L : List_Id); | |
218 | -- Append the list L of actions to the end of the before-actions store | |
219 | -- in the top of the scope stack | |
220 | ||
221 | procedure Store_After_Actions_In_Scope (L : List_Id); | |
222 | -- Append the list L of actions to the beginning of the after-actions | |
223 | -- store in the top of the scope stack | |
224 | ||
225 | procedure Wrap_Transient_Declaration (N : Node_Id); | |
226 | -- N is an object declaration. Expand the finalization calls after the | |
227 | -- declaration and make the outer scope beeing the transient one. | |
228 | ||
229 | procedure Wrap_Transient_Expression (N : Node_Id); | |
230 | -- N is a sub-expression. Expand a transient block around an expression | |
231 | ||
232 | procedure Wrap_Transient_Statement (N : Node_Id); | |
233 | -- N is a statement. Expand a transient block around an instruction | |
234 | ||
235 | end Exp_Ch7; |