PR c++/3637
[official-gcc.git] / gcc / ada / exp_ch9.ads
blob949356fb39162048c31968eb5c29e793c1df8f6b
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ C H 9 --
6 -- --
7 -- S p e c --
8 -- --
9 -- $Revision: 1.56 $
10 -- --
11 -- Copyright (C) 1992-1999 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 -- --
27 ------------------------------------------------------------------------------
29 -- Expand routines for chapter 9 constructs
31 with Types; use Types;
33 package Exp_Ch9 is
35 procedure Add_Discriminal_Declarations
36 (Decls : List_Id;
37 Typ : Entity_Id;
38 Name : Name_Id;
39 Loc : Source_Ptr);
40 -- This routine is used to add discriminal declarations to task and
41 -- protected operation bodies. The discriminants are available by normal
42 -- selection from the concurrent object (whose name is passed as the third
43 -- parameter). Discriminant references inside the body have already
44 -- been replaced by references to the corresponding discriminals. The
45 -- declarations constructed by this procedure hook the references up with
46 -- the objects:
48 -- discriminal_name : discr_type renames name.discriminant_name;
50 -- Obviously we could have expanded the discriminant references in the
51 -- first place to be the appropriate selection, but this turns out to
52 -- be hard to do because it would introduce difference in handling of
53 -- discriminant references depending on their location.
55 procedure Add_Private_Declarations
56 (Decls : List_Id;
57 Typ : Entity_Id;
58 Name : Name_Id;
59 Loc : Source_Ptr);
60 -- This routine is used to add private declarations to protected bodies.
61 -- These are analogous to the discriminal declarations added to tasks
62 -- and protected operations, and consist of a renaming of each private
63 -- object to a selection from the concurrent object passed as an extra
64 -- parameter to each such operation:
65 -- private_name : private_type renames name.private_name;
66 -- As with discriminals, private references inside the protected
67 -- subprogram bodies have already been replaced by references to the
68 -- corresponding privals.
70 procedure Build_Activation_Chain_Entity (N : Node_Id);
71 -- Given a declaration N of an object that is a task, or contains tasks
72 -- (other than allocators to tasks) this routine ensures that an activation
73 -- chain has been declared in the appropriate scope, building the required
74 -- declaration for the chain variable if not. The name of this variable
75 -- is always _Chain and it is accessed by name. This procedure also adds
76 -- an appropriate call to Activate_Tasks to activate the tasks for this
77 -- activation chain. It does not however deal with the call needed in the
78 -- case of allocators to Expunge_Unactivated_Tasks, this is separately
79 -- handled in the Expand_Task_Allocator routine.
81 function Build_Call_With_Task (N : Node_Id; E : Entity_Id) return Node_Id;
82 -- N is a node representing the name of a task or an access to a task.
83 -- The value returned is a call to the function whose name is the entity
84 -- E (typically a runtime routine entity obtained using RTE) with the
85 -- Task_Id of the associated task as the parameter. The caller is
86 -- responsible for analyzing and resolving the resulting tree.
88 procedure Build_Master_Entity (E : Entity_Id);
89 -- Given an entity E for the declaration of an object containing tasks
90 -- or of a type declaration for an allocator whose designated type is a
91 -- task or contains tasks, this routine marks the appropriate enclosing
92 -- context as a master, and also declares a variable called _Master in
93 -- the current declarative part which captures the value of Current_Master
94 -- (if not already built by a prior call). We build this object (instead
95 -- of just calling Current_Master) for two reasons. First it is clearly
96 -- more efficient to call Current_Master only once for a bunch of tasks
97 -- in the same declarative part, and second it makes things easier in
98 -- generating the initialization routines, since they can just reference
99 -- the object _Master by name, and they will get the proper Current_Master
100 -- value at the outer level, and copy in the parameter value for the outer
101 -- initialization call if the call is for a nested component). Note that
102 -- in the case of nested packages, we only really need to make one such
103 -- object at the outer level, but it is much easier to generate one per
104 -- declarative part.
106 function Build_Protected_Sub_Specification
107 (N : Node_Id;
108 Prottyp : Entity_Id;
109 Unprotected : Boolean := False)
110 return Node_Id;
111 -- Build specification for protected subprogram. This is called when
112 -- expanding a protected type, and also when expanding the declaration for
113 -- an Access_To_Protected_Subprogram type. In the latter case, Prottyp is
114 -- empty, and the first parameter of the signature of the protected op is
115 -- of type System.Address.
117 procedure Build_Protected_Subprogram_Call
118 (N : Node_Id;
119 Name : Node_Id;
120 Rec : Node_Id;
121 External : Boolean := True);
122 -- The node N is a subprogram or entry call to a protected subprogram.
123 -- This procedure rewrites this call with the appropriate expansion.
124 -- Name is the subprogram, and Rec is the record corresponding to the
125 -- protected object. External is False if the call is to another
126 -- protected subprogram within the same object.
128 procedure Build_Task_Activation_Call (N : Node_Id);
129 -- This procedure is called for constructs that can be task activators
130 -- i.e. task bodies, subprogram bodies, package bodies and blocks. If
131 -- the construct is a task activator (as indicated by the non-empty
132 -- setting of Activation_Chain_Entity, either in the construct, or, in
133 -- the case of a package body, in its associated package spec), then
134 -- a call to Activate_Tasks with this entity as the single parameter
135 -- is inserted at the start of the statements of the activator.
137 procedure Build_Task_Allocate_Block
138 (Actions : List_Id;
139 N : Node_Id;
140 Args : List_Id);
141 -- This routine is used in the case of allocators where the designated
142 -- type is a task or contains tasks. In this case, the normal initialize
143 -- call is replaced by:
145 -- blockname : label;
146 -- blockname : declare
147 -- _Chain : Activation_Chain;
149 -- procedure _Expunge is
150 -- begin
151 -- Expunge_Unactivated_Tasks (_Chain);
152 -- end;
154 -- begin
155 -- Init (Args);
156 -- Activate_Tasks (_Chain);
157 -- at end
158 -- _Expunge;
159 -- end;
161 -- to get the task or tasks created and initialized. The expunge call
162 -- ensures that any tasks that get created but not activated due to an
163 -- exception are properly expunged (it has no effect in the normal case)
164 -- The argument N is the allocator, and Args is the list of arguments
165 -- for the initialization call, constructed by the caller, which uses
166 -- the Master_Id of the access type as the _Master parameter, and _Chain
167 -- (defined above) as the _Chain parameter.
169 function Concurrent_Ref (N : Node_Id) return Node_Id;
170 -- Given the name of a concurrent object (task or protected object), or
171 -- the name of an access to a concurrent object, this function returns an
172 -- expression referencing the associated Task_Id or Protection object,
173 -- respectively. Note that a special case is when the name is a reference
174 -- to a task type name. This can only happen within a task body, and the
175 -- meaning is to get the Task_Id for the currently executing task.
177 function Convert_Concurrent
178 (N : Node_Id;
179 Typ : Entity_Id)
180 return Node_Id;
181 -- N is an expression of type Typ. If the type is not a concurrent
182 -- type then it is returned unchanged. If it is a task or protected
183 -- reference, Convert_Concurrent creates an unchecked conversion node
184 -- from this expression to the corresponding concurrent record type
185 -- value. We need this in any situation where the concurrent type is
186 -- used, because the actual concurrent object is an object of the
187 -- corresponding concurrent type, and manipulations on the concurrent
188 -- object actually manipulate the corresponding object of the record
189 -- type.
191 function Entry_Index_Expression
192 (Sloc : Source_Ptr;
193 Ent : Entity_Id;
194 Index : Node_Id;
195 Ttyp : Entity_Id)
196 return Node_Id;
197 -- Returns an expression to compute a task entry index given the name
198 -- of the entry or entry family. For the case of a task entry family,
199 -- the Index parameter contains the expression for the subscript.
200 -- Ttyp is the task type.
202 procedure Establish_Task_Master (N : Node_Id);
203 -- Given a subprogram body, or a block statement, or a task body, this
204 -- proccedure makes the necessary transformations required of a task
205 -- master (add Enter_Master call at start, and establish a cleanup
206 -- routine to make sure Complete_Master is called on exit).
208 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id);
209 -- Build Equivalent_Type for an Access_to_protected_Subprogram.
211 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id);
212 -- Expand declarations required for accept statement. See bodies of
213 -- both Expand_Accept_Declarations and Expand_N_Accept_Statement for
214 -- full details of the nature and use of these declarations, which
215 -- are inserted immediately before the accept node N. The second
216 -- argument is the entity for the corresponding entry.
218 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id);
219 -- Expand the entry barrier into a function. This is called directly
220 -- from Analyze_Entry_Body so that the discriminals and privals of the
221 -- barrier can be attached to the function declaration list, and a new
222 -- set prepared for the entry body procedure, bedore the entry body
223 -- statement sequence can be expanded. The resulting function is analyzed
224 -- now, within the context of the protected object, to resolve calls to
225 -- other protected functions.
227 procedure Expand_Entry_Body_Declarations (N : Node_Id);
228 -- Expand declarations required for the expansion of the
229 -- statements of the body.
231 procedure Expand_N_Abort_Statement (N : Node_Id);
232 procedure Expand_N_Accept_Statement (N : Node_Id);
233 procedure Expand_N_Asynchronous_Select (N : Node_Id);
234 procedure Expand_N_Conditional_Entry_Call (N : Node_Id);
235 procedure Expand_N_Delay_Relative_Statement (N : Node_Id);
236 procedure Expand_N_Delay_Until_Statement (N : Node_Id);
237 procedure Expand_N_Entry_Body (N : Node_Id);
238 procedure Expand_N_Entry_Call_Statement (N : Node_Id);
239 procedure Expand_N_Entry_Declaration (N : Node_Id);
240 procedure Expand_N_Protected_Body (N : Node_Id);
242 procedure Expand_N_Protected_Type_Declaration (N : Node_Id);
243 -- Expands protected type declarations. This results, among
244 -- other things, in the declaration of a record type for the
245 -- representation of protected objects and (if there are entries)
246 -- in an entry service procedure. The Protection value used by
247 -- the GNARL to control the object will always be the first
248 -- field of the record, and the entry service procedure spec
249 -- (if it exists) will always immediately follow the record
250 -- declaration. This allows these two nodes to be found from
251 -- the type using Corresponding_Record, without benefit of
252 -- of further attributes.
254 procedure Expand_N_Requeue_Statement (N : Node_Id);
255 procedure Expand_N_Selective_Accept (N : Node_Id);
256 procedure Expand_N_Single_Task_Declaration (N : Node_Id);
257 procedure Expand_N_Task_Body (N : Node_Id);
258 procedure Expand_N_Task_Type_Declaration (N : Node_Id);
259 procedure Expand_N_Timed_Entry_Call (N : Node_Id);
261 procedure Expand_Protected_Body_Declarations
262 (N : Node_Id;
263 Spec_Id : Entity_Id);
264 -- Expand declarations required for a protected body. See bodies of
265 -- both Expand_Protected_Body_Declarations and Expand_N_Protected_Body
266 -- for full details of the nature and use of these declarations.
267 -- The second argument is the entity for the corresponding
268 -- protected type declaration.
270 function External_Subprogram (E : Entity_Id) return Entity_Id;
271 -- return the external version of a protected operation, which locks
272 -- the object before invoking the internal protected subprogram body.
274 function First_Protected_Operation (D : List_Id) return Node_Id;
275 -- Given the declarations list for a protected body, find the
276 -- first protected operation body.
278 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id;
279 -- Given the entity of the record type created for a task type, build
280 -- the call to Create_Task
282 function Make_Initialize_Protection
283 (Protect_Rec : Entity_Id)
284 return List_Id;
285 -- Given the entity of the record type created for a protected type, build
286 -- a list of statements needed for proper initialization of the object.
288 function Next_Protected_Operation (N : Node_Id) return Node_Id;
289 -- Given a protected operation node (a subprogram or entry body),
290 -- find the following node in the declarations list.
292 procedure Set_Discriminals
293 (Dec : Node_Id;
294 Op : Node_Id;
295 Loc : Source_Ptr);
296 -- Replace discriminals in a protected type for use by the
297 -- next protected operation on the type. Each operation needs a
298 -- new set of discirminals, since it needs a unique renaming of
299 -- the discriminant fields in the record used to implement the
300 -- protected type.
302 procedure Set_Privals
303 (Dec : Node_Id;
304 Op : Node_Id;
305 Loc : Source_Ptr);
306 -- Associates a new set of privals (placeholders for later access to
307 -- private components of protected objects) with the private object
308 -- declarations of a protected object. These will be used to expand
309 -- the references to private objects in the next protected
310 -- subprogram or entry body to be expanded.
312 end Exp_Ch9;