Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / ada / exp_ch9.ads
blob65e3d76cb270f0e5b2e46c3c99af07d826aed26f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ C H 9 --
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 ------------------------------------------------------------------------------
26 -- Expand routines for chapter 9 constructs
28 with Namet; use Namet;
29 with Types; use Types;
31 package Exp_Ch9 is
33 type Subprogram_Protection_Mode is
34 (Dispatching_Mode,
35 Protected_Mode,
36 Unprotected_Mode);
37 -- This type is used to distinguish the different protection modes of a
38 -- protected subprogram.
40 procedure Add_Discriminal_Declarations
41 (Decls : List_Id;
42 Typ : Entity_Id;
43 Name : Name_Id;
44 Loc : Source_Ptr);
45 -- This routine is used to add discriminal declarations to task and
46 -- protected operation bodies. The discriminants are available by normal
47 -- selection from the concurrent object (whose name is passed as the third
48 -- parameter). Discriminant references inside the body have already
49 -- been replaced by references to the corresponding discriminals. The
50 -- declarations constructed by this procedure hook the references up with
51 -- the objects:
53 -- discriminal_name : discr_type renames name.discriminant_name;
55 -- Obviously we could have expanded the discriminant references in the
56 -- first place to be the appropriate selection, but this turns out to
57 -- be hard to do because it would introduce difference in handling of
58 -- discriminant references depending on their location.
60 procedure Add_Private_Declarations
61 (Decls : List_Id;
62 Typ : Entity_Id;
63 Name : Name_Id;
64 Loc : Source_Ptr);
65 -- This routine is used to add private declarations to protected bodies.
66 -- These are analogous to the discriminal declarations added to tasks
67 -- and protected operations, and consist of a renaming of each private
68 -- object to a selection from the concurrent object passed as an extra
69 -- parameter to each such operation:
70 -- private_name : private_type renames name.private_name;
71 -- As with discriminals, private references inside the protected
72 -- subprogram bodies have already been replaced by references to the
73 -- corresponding privals.
75 procedure Build_Activation_Chain_Entity (N : Node_Id);
76 -- Given a declaration N of an object that is a task, or contains tasks
77 -- (other than allocators to tasks) this routine ensures that an activation
78 -- chain has been declared in the appropriate scope, building the required
79 -- declaration for the chain variable if not. The name of this variable
80 -- is always _Chain and it is accessed by name.
82 function Build_Call_With_Task (N : Node_Id; E : Entity_Id) return Node_Id;
83 -- N is a node representing the name of a task or an access to a task.
84 -- The value returned is a call to the function whose name is the entity
85 -- E (typically a runtime routine entity obtained using RTE) with the
86 -- Task_Id of the associated task as the parameter. The caller is
87 -- responsible for analyzing and resolving the resulting tree.
89 function Build_Corresponding_Record
90 (N : Node_Id;
91 Ctyp : Node_Id;
92 Loc : Source_Ptr) return Node_Id;
93 -- Common to tasks and protected types. Copy discriminant specifications,
94 -- build record declaration. N is the type declaration, Ctyp is the
95 -- concurrent entity (task type or protected type).
97 procedure Build_Master_Entity (E : Entity_Id);
98 -- Given an entity E for the declaration of an object containing tasks
99 -- or of a type declaration for an allocator whose designated type is a
100 -- task or contains tasks, this routine marks the appropriate enclosing
101 -- context as a master, and also declares a variable called _Master in
102 -- the current declarative part which captures the value of Current_Master
103 -- (if not already built by a prior call). We build this object (instead
104 -- of just calling Current_Master) for two reasons. First it is clearly
105 -- more efficient to call Current_Master only once for a bunch of tasks
106 -- in the same declarative part, and second it makes things easier in
107 -- generating the initialization routines, since they can just reference
108 -- the object _Master by name, and they will get the proper Current_Master
109 -- value at the outer level, and copy in the parameter value for the outer
110 -- initialization call if the call is for a nested component). Note that
111 -- in the case of nested packages, we only really need to make one such
112 -- object at the outer level, but it is much easier to generate one per
113 -- declarative part.
115 function Build_Protected_Sub_Specification
116 (N : Node_Id;
117 Prottyp : Entity_Id;
118 Mode : Subprogram_Protection_Mode) return Node_Id;
119 -- Build specification for protected subprogram. This is called when
120 -- expanding a protected type, and also when expanding the declaration for
121 -- an Access_To_Protected_Subprogram type. In the latter case, Prottyp is
122 -- empty, and the first parameter of the signature of the protected op is
123 -- of type System.Address.
125 procedure Build_Protected_Subprogram_Call
126 (N : Node_Id;
127 Name : Node_Id;
128 Rec : Node_Id;
129 External : Boolean := True);
130 -- The node N is a subprogram or entry call to a protected subprogram.
131 -- This procedure rewrites this call with the appropriate expansion.
132 -- Name is the subprogram, and Rec is the record corresponding to the
133 -- protected object. External is False if the call is to another
134 -- protected subprogram within the same object.
136 procedure Build_Task_Activation_Call (N : Node_Id);
137 -- This procedure is called for constructs that can be task activators
138 -- i.e. task bodies, subprogram bodies, package bodies and blocks. If
139 -- the construct is a task activator (as indicated by the non-empty
140 -- setting of Activation_Chain_Entity, either in the construct, or, in
141 -- the case of a package body, in its associated package spec), then
142 -- a call to Activate_Tasks with this entity as the single parameter
143 -- is inserted at the start of the statements of the activator.
145 procedure Build_Task_Allocate_Block
146 (Actions : List_Id;
147 N : Node_Id;
148 Args : List_Id);
149 -- This routine is used in the case of allocators where the designated
150 -- type is a task or contains tasks. In this case, the normal initialize
151 -- call is replaced by:
153 -- blockname : label;
154 -- blockname : declare
155 -- _Chain : Activation_Chain;
157 -- procedure _Expunge is
158 -- begin
159 -- Expunge_Unactivated_Tasks (_Chain);
160 -- end;
162 -- begin
163 -- Init (Args);
164 -- Activate_Tasks (_Chain);
165 -- at end
166 -- _Expunge;
167 -- end;
169 -- to get the task or tasks created and initialized. The expunge call
170 -- ensures that any tasks that get created but not activated due to an
171 -- exception are properly expunged (it has no effect in the normal case)
172 -- The argument N is the allocator, and Args is the list of arguments
173 -- for the initialization call, constructed by the caller, which uses
174 -- the Master_Id of the access type as the _Master parameter, and _Chain
175 -- (defined above) as the _Chain parameter.
177 procedure Build_Task_Allocate_Block_With_Init_Stmts
178 (Actions : List_Id;
179 N : Node_Id;
180 Init_Stmts : List_Id);
181 -- Ada 2005 (AI-287): Similar to previous routine, but used to expand
182 -- allocated aggregates with default initialized components. Init_Stmts
183 -- contains the list of statements required to initialize the allocated
184 -- aggregate. It replaces the call to Init (Args) done by
185 -- Build_Task_Allocate_Block.
187 function Concurrent_Ref (N : Node_Id) return Node_Id;
188 -- Given the name of a concurrent object (task or protected object), or
189 -- the name of an access to a concurrent object, this function returns an
190 -- expression referencing the associated Task_Id or Protection object,
191 -- respectively. Note that a special case is when the name is a reference
192 -- to a task type name. This can only happen within a task body, and the
193 -- meaning is to get the Task_Id for the currently executing task.
195 function Convert_Concurrent
196 (N : Node_Id;
197 Typ : Entity_Id)
198 return Node_Id;
199 -- N is an expression of type Typ. If the type is not a concurrent
200 -- type then it is returned unchanged. If it is a task or protected
201 -- reference, Convert_Concurrent creates an unchecked conversion node
202 -- from this expression to the corresponding concurrent record type
203 -- value. We need this in any situation where the concurrent type is
204 -- used, because the actual concurrent object is an object of the
205 -- corresponding concurrent type, and manipulations on the concurrent
206 -- object actually manipulate the corresponding object of the record
207 -- type.
209 function Entry_Index_Expression
210 (Sloc : Source_Ptr;
211 Ent : Entity_Id;
212 Index : Node_Id;
213 Ttyp : Entity_Id)
214 return Node_Id;
215 -- Returns an expression to compute a task entry index given the name
216 -- of the entry or entry family. For the case of a task entry family,
217 -- the Index parameter contains the expression for the subscript.
218 -- Ttyp is the task type.
220 procedure Establish_Task_Master (N : Node_Id);
221 -- Given a subprogram body, or a block statement, or a task body, this
222 -- proccedure makes the necessary transformations required of a task
223 -- master (add Enter_Master call at start, and establish a cleanup
224 -- routine to make sure Complete_Master is called on exit).
226 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id);
227 -- Build Equivalent_Type for an Access_to_protected_Subprogram
229 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id);
230 -- Expand declarations required for accept statement. See bodies of
231 -- both Expand_Accept_Declarations and Expand_N_Accept_Statement for
232 -- full details of the nature and use of these declarations, which
233 -- are inserted immediately before the accept node N. The second
234 -- argument is the entity for the corresponding entry.
236 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id);
237 -- Expand the entry barrier into a function. This is called directly
238 -- from Analyze_Entry_Body so that the discriminals and privals of the
239 -- barrier can be attached to the function declaration list, and a new
240 -- set prepared for the entry body procedure, bedore the entry body
241 -- statement sequence can be expanded. The resulting function is analyzed
242 -- now, within the context of the protected object, to resolve calls to
243 -- other protected functions.
245 procedure Expand_Entry_Body_Declarations (N : Node_Id);
246 -- Expand declarations required for the expansion of the
247 -- statements of the body.
249 procedure Expand_N_Abort_Statement (N : Node_Id);
250 procedure Expand_N_Accept_Statement (N : Node_Id);
251 procedure Expand_N_Asynchronous_Select (N : Node_Id);
252 procedure Expand_N_Conditional_Entry_Call (N : Node_Id);
253 procedure Expand_N_Delay_Relative_Statement (N : Node_Id);
254 procedure Expand_N_Delay_Until_Statement (N : Node_Id);
255 procedure Expand_N_Entry_Body (N : Node_Id);
256 procedure Expand_N_Entry_Call_Statement (N : Node_Id);
257 procedure Expand_N_Entry_Declaration (N : Node_Id);
258 procedure Expand_N_Protected_Body (N : Node_Id);
260 procedure Expand_N_Protected_Type_Declaration (N : Node_Id);
261 -- Expands protected type declarations. This results, among other things,
262 -- in the declaration of a record type for the representation of protected
263 -- objects and (if there are entries) in an entry service procedure. The
264 -- Protection value used by the GNARL to control the object will always be
265 -- the first field of the record, and the entry service procedure spec (if
266 -- it exists) will always immediately follow the record declaration. This
267 -- allows these two nodes to be found from the type, without benefit of
268 -- further attributes, using Corresponding_Record.
270 procedure Expand_N_Requeue_Statement (N : Node_Id);
271 procedure Expand_N_Selective_Accept (N : Node_Id);
272 procedure Expand_N_Single_Task_Declaration (N : Node_Id);
273 procedure Expand_N_Task_Body (N : Node_Id);
274 procedure Expand_N_Task_Type_Declaration (N : Node_Id);
275 procedure Expand_N_Timed_Entry_Call (N : Node_Id);
277 procedure Expand_Protected_Body_Declarations
278 (N : Node_Id;
279 Spec_Id : Entity_Id);
280 -- Expand declarations required for a protected body. See bodies of
281 -- both Expand_Protected_Body_Declarations and Expand_N_Protected_Body
282 -- for full details of the nature and use of these declarations.
283 -- The second argument is the entity for the corresponding
284 -- protected type declaration.
286 function External_Subprogram (E : Entity_Id) return Entity_Id;
287 -- return the external version of a protected operation, which locks
288 -- the object before invoking the internal protected subprogram body.
290 function First_Protected_Operation (D : List_Id) return Node_Id;
291 -- Given the declarations list for a protected body, find the
292 -- first protected operation body.
294 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id;
295 -- Given the entity of the record type created for a task type, build
296 -- the call to Create_Task
298 function Make_Initialize_Protection
299 (Protect_Rec : Entity_Id)
300 return List_Id;
301 -- Given the entity of the record type created for a protected type, build
302 -- a list of statements needed for proper initialization of the object.
304 function Next_Protected_Operation (N : Node_Id) return Node_Id;
305 -- Given a protected operation node (a subprogram or entry body),
306 -- find the following node in the declarations list.
308 procedure Set_Discriminals (Dec : Node_Id);
309 -- Replace discriminals in a protected type for use by the
310 -- next protected operation on the type. Each operation needs a
311 -- new set of discirminals, since it needs a unique renaming of
312 -- the discriminant fields in the record used to implement the
313 -- protected type.
315 procedure Set_Privals
316 (Dec : Node_Id;
317 Op : Node_Id;
318 Loc : Source_Ptr;
319 After_Barrier : Boolean := False);
320 -- Associates a new set of privals (placeholders for later access to
321 -- private components of protected objects) with the private object
322 -- declarations of a protected object. These will be used to expand
323 -- the references to private objects in the next protected
324 -- subprogram or entry body to be expanded.
326 -- The flag After_Barrier indicates whether this is called after building
327 -- the barrier function for an entry body. This flag determines whether
328 -- the privals should have source names (which simplifies debugging) or
329 -- internally generated names. Entry barriers contain no debuggable code,
330 -- and there may be visibility conflicts between an entry index and a
331 -- a prival, so privals for barrier function have internal names.
333 end Exp_Ch9;