Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / ada / exp_ch9.ads
blob80d870ad8a103c20343b0d042752065934d4dc73
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-2010, 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 Types; use Types;
30 package Exp_Ch9 is
32 type Subprogram_Protection_Mode is
33 (Dispatching_Mode,
34 Protected_Mode,
35 Unprotected_Mode);
36 -- This type is used to distinguish the different protection modes of a
37 -- protected subprogram.
39 procedure Build_Activation_Chain_Entity (N : Node_Id);
40 -- Given a declaration N of an object that is a task, or contains tasks
41 -- (other than allocators to tasks) this routine ensures that an activation
42 -- chain has been declared in the appropriate scope, building the required
43 -- declaration for the chain variable if not. The name of this variable
44 -- is always _Chain and it is accessed by name.
46 function Build_Call_With_Task (N : Node_Id; E : Entity_Id) return Node_Id;
47 -- N is a node representing the name of a task or an access to a task.
48 -- The value returned is a call to the function whose name is the entity
49 -- E (typically a runtime routine entity obtained using RTE) with the
50 -- Task_Id of the associated task as the parameter. The caller is
51 -- responsible for analyzing and resolving the resulting tree.
53 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id;
54 -- Create the statements which populate the entry names array of a task or
55 -- protected type. The statements are wrapped inside a block due to a local
56 -- declaration.
58 procedure Build_Master_Entity (E : Entity_Id);
59 -- Given an entity E for the declaration of an object containing tasks
60 -- or of a type declaration for an allocator whose designated type is a
61 -- task or contains tasks, this routine marks the appropriate enclosing
62 -- context as a master, and also declares a variable called _Master in
63 -- the current declarative part which captures the value of Current_Master
64 -- (if not already built by a prior call). We build this object (instead
65 -- of just calling Current_Master) for two reasons. First it is clearly
66 -- more efficient to call Current_Master only once for a bunch of tasks
67 -- in the same declarative part, and second it makes things easier in
68 -- generating the initialization routines, since they can just reference
69 -- the object _Master by name, and they will get the proper Current_Master
70 -- value at the outer level, and copy in the parameter value for the outer
71 -- initialization call if the call is for a nested component). Note that
72 -- in the case of nested packages, we only really need to make one such
73 -- object at the outer level, but it is much easier to generate one per
74 -- declarative part.
76 function Build_Private_Protected_Declaration (N : Node_Id) return Entity_Id;
77 -- A subprogram body without a previous spec that appears in a protected
78 -- body must be expanded separately to create a subprogram declaration
79 -- for it, in order to resolve internal calls to it from other protected
80 -- operations. It would seem that no locking version of the operation is
81 -- needed, but in fact, in Ada 2005 the subprogram may be used in a call-
82 -- back, and therefore a protected version of the operation must be
83 -- generated as well.
85 function Build_Protected_Sub_Specification
86 (N : Node_Id;
87 Prot_Typ : Entity_Id;
88 Mode : Subprogram_Protection_Mode) return Node_Id;
89 -- Build the specification for protected subprogram. This is called when
90 -- expanding a protected type, and also when expanding the declaration for
91 -- an Access_To_Protected_Subprogram type. In the latter case, Prot_Typ is
92 -- empty, and the first parameter of the signature of the protected op is
93 -- of type System.Address.
95 procedure Build_Protected_Subprogram_Call
96 (N : Node_Id;
97 Name : Node_Id;
98 Rec : Node_Id;
99 External : Boolean := True);
100 -- The node N is a subprogram or entry call to a protected subprogram. This
101 -- procedure rewrites this call with the appropriate expansion. Name is the
102 -- subprogram, and Rec is the record corresponding to the protected object.
103 -- External is False if the call is to another protected subprogram within
104 -- the same object.
106 procedure Build_Task_Activation_Call (N : Node_Id);
107 -- This procedure is called for constructs that can be task activators,
108 -- i.e. task bodies, subprogram bodies, package bodies and blocks. If the
109 -- construct is a task activator (as indicated by the non-empty setting of
110 -- Activation_Chain_Entity, either in the construct, or, in the case of a
111 -- package body, in its associated package spec), then a call to
112 -- Activate_Tasks with this entity as the single parameter is inserted at
113 -- the start of the statements of the activator.
115 procedure Build_Task_Allocate_Block
116 (Actions : List_Id;
117 N : Node_Id;
118 Args : List_Id);
119 -- This routine is used in the case of allocators where the designated type
120 -- is a task or contains tasks. In this case, the normal initialize call
121 -- is replaced by:
123 -- blockname : label;
124 -- blockname : declare
125 -- _Chain : Activation_Chain;
127 -- procedure _Expunge is
128 -- begin
129 -- Expunge_Unactivated_Tasks (_Chain);
130 -- end;
132 -- begin
133 -- Init (Args);
134 -- Activate_Tasks (_Chain);
135 -- at end
136 -- _Expunge;
137 -- end;
139 -- to get the task or tasks created and initialized. The expunge call
140 -- ensures that any tasks that get created but not activated due to an
141 -- exception are properly expunged (it has no effect in the normal case).
142 -- The argument N is the allocator, and Args is the list of arguments for
143 -- the initialization call, constructed by the caller, which uses the
144 -- Master_Id of the access type as the _Master parameter, and _Chain
145 -- (defined above) as the _Chain parameter.
147 procedure Build_Task_Allocate_Block_With_Init_Stmts
148 (Actions : List_Id;
149 N : Node_Id;
150 Init_Stmts : List_Id);
151 -- Ada 2005 (AI-287): Similar to previous routine, but used to expand
152 -- allocated aggregates with default initialized components. Init_Stmts
153 -- contains the list of statements required to initialize the allocated
154 -- aggregate. It replaces the call to Init (Args) done by
155 -- Build_Task_Allocate_Block.
157 function Build_Wrapper_Spec
158 (Subp_Id : Entity_Id;
159 Obj_Typ : Entity_Id;
160 Formals : List_Id) return Node_Id;
161 -- Ada 2005 (AI-345): Build the specification of a primitive operation
162 -- associated with a protected or task type. This is required to implement
163 -- dispatching calls through interfaces. Subp_Id is the primitive to be
164 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
165 -- handle object notation, Formals are the original entry formals that
166 -- will be explicitly replicated.
168 function Concurrent_Ref (N : Node_Id) return Node_Id;
169 -- Given the name of a concurrent object (task or protected object), or
170 -- the name of an access to a concurrent object, this function returns an
171 -- expression referencing the associated Task_Id or Protection object,
172 -- respectively. Note that a special case is when the name is a reference
173 -- to a task type name. This can only happen within a task body, and the
174 -- meaning is to get the Task_Id for the currently executing task.
176 function Convert_Concurrent
177 (N : Node_Id;
178 Typ : Entity_Id) return Node_Id;
179 -- N is an expression of type Typ. If the type is not a concurrent type
180 -- then it is returned unchanged. If it is a task or protected reference,
181 -- Convert_Concurrent creates an unchecked conversion node from this
182 -- expression to the corresponding concurrent record type value. We need
183 -- this in any situation where the concurrent type is used, because the
184 -- actual concurrent object is an object of the corresponding concurrent
185 -- type, and manipulations on the concurrent object actually manipulate the
186 -- corresponding object of the record type.
188 function Entry_Index_Expression
189 (Sloc : Source_Ptr;
190 Ent : Entity_Id;
191 Index : Node_Id;
192 Ttyp : Entity_Id)
193 return Node_Id;
194 -- Returns an expression to compute a task entry index given the name of
195 -- the entry or entry family. For the case of a task entry family, the
196 -- Index parameter contains the expression for the subscript. Ttyp is the
197 -- task type.
199 procedure Establish_Task_Master (N : Node_Id);
200 -- Given a subprogram body, or a block statement, or a task body, this
201 -- procedure makes the necessary transformations required of a task master
202 -- (add Enter_Master call at start, and establish a cleanup routine to make
203 -- sure Complete_Master is called on exit).
205 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id);
206 -- Build Equivalent_Type for an Access_To_Protected_Subprogram.
207 -- Equivalent_Type is a record type with two components: a pointer to the
208 -- protected object, and a pointer to the operation itself.
210 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id);
211 -- Expand declarations required for accept statement. See bodies of both
212 -- Expand_Accept_Declarations and Expand_N_Accept_Statement for full
213 -- details of the nature and use of these declarations, which are inserted
214 -- immediately before the accept node N. The second argument is the entity
215 -- for the corresponding entry.
217 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id);
218 -- Expand the entry barrier into a function. This is called directly
219 -- from Analyze_Entry_Body so that the discriminals and privals of the
220 -- barrier can be attached to the function declaration list, and a new
221 -- set prepared for the entry body procedure, before the entry body
222 -- statement sequence can be expanded. The resulting function is analyzed
223 -- now, within the context of the protected object, to resolve calls to
224 -- other protected functions.
226 procedure Expand_N_Abort_Statement (N : Node_Id);
227 procedure Expand_N_Accept_Statement (N : Node_Id);
228 procedure Expand_N_Asynchronous_Select (N : Node_Id);
229 procedure Expand_N_Conditional_Entry_Call (N : Node_Id);
230 procedure Expand_N_Delay_Relative_Statement (N : Node_Id);
231 procedure Expand_N_Delay_Until_Statement (N : Node_Id);
232 procedure Expand_N_Entry_Body (N : Node_Id);
233 procedure Expand_N_Entry_Call_Statement (N : Node_Id);
234 procedure Expand_N_Entry_Declaration (N : Node_Id);
235 procedure Expand_N_Protected_Body (N : Node_Id);
237 procedure Expand_N_Protected_Type_Declaration (N : Node_Id);
238 -- Expands protected type declarations. This results, among other things,
239 -- in the declaration of a record type for the representation of protected
240 -- objects and (if there are entries) in an entry service procedure. The
241 -- Protection value used by the GNARL to control the object will always be
242 -- the first field of the record, and the entry service procedure spec (if
243 -- it exists) will always immediately follow the record declaration. This
244 -- allows these two nodes to be found from the type, without benefit of
245 -- further attributes, using Corresponding_Record.
247 procedure Expand_N_Requeue_Statement (N : Node_Id);
248 procedure Expand_N_Selective_Accept (N : Node_Id);
249 procedure Expand_N_Single_Task_Declaration (N : Node_Id);
250 procedure Expand_N_Task_Body (N : Node_Id);
251 procedure Expand_N_Task_Type_Declaration (N : Node_Id);
252 procedure Expand_N_Timed_Entry_Call (N : Node_Id);
254 procedure Expand_Protected_Body_Declarations
255 (N : Node_Id;
256 Spec_Id : Entity_Id);
257 -- Expand declarations required for a protected body. See bodies of both
258 -- Expand_Protected_Body_Declarations and Expand_N_Protected_Body for full
259 -- details of the nature and use of these declarations. The second argument
260 -- is the entity for the corresponding protected type declaration.
262 function External_Subprogram (E : Entity_Id) return Entity_Id;
263 -- return the external version of a protected operation, which locks
264 -- the object before invoking the internal protected subprogram body.
266 function First_Protected_Operation (D : List_Id) return Node_Id;
267 -- Given the declarations list for a protected body, find the
268 -- first protected operation body.
270 procedure Install_Private_Data_Declarations
271 (Loc : Source_Ptr;
272 Spec_Id : Entity_Id;
273 Conc_Typ : Entity_Id;
274 Body_Nod : Node_Id;
275 Decls : List_Id;
276 Barrier : Boolean := False;
277 Family : Boolean := False);
278 -- This routines generates several types, objects and object renamings used
279 -- in the handling of discriminants and private components of protected and
280 -- task types. It also generates the entry index for entry families. Formal
281 -- Spec_Id denotes an entry, entry family or a subprogram, Conc_Typ is the
282 -- concurrent type where Spec_Id resides, Body_Nod is the corresponding
283 -- body of Spec_Id, Decls are the declarations of the subprogram or entry.
284 -- Flag Barrier denotes whether the context is an entry barrier function.
285 -- Flag Family is used in conjunction with Barrier to denote a barrier for
286 -- an entry family.
288 -- The generated types, entities and renamings are:
290 -- * If flag Barrier is set or Spec_Id denotes a protected entry or an
291 -- entry family, generate:
293 -- type prot_typVP is access prot_typV;
294 -- _object : prot_typVP := prot_typV (_O);
296 -- where prot_typV is the corresponding record of a protected type and
297 -- _O is a formal parameter representing the concurrent object of either
298 -- the barrier function or the entry (family).
300 -- * If Conc_Typ is a protected type, create a renaming for the Protection
301 -- field _object:
303 -- conc_typR : protection_typ renames _object._object;
305 -- * If Conc_Typ has discriminants, create renamings of the form:
307 -- discr_nameD : discr_typ renames _object.discr_name;
308 -- or
309 -- discr_nameD : discr_typ renames _task.discr_name;
311 -- * If Conc_Typ denotes a protected type and has private components,
312 -- generate renamings of the form:
314 -- comp_name : comp_typ renames _object.comp_name;
316 -- * Finally, is flag Barrier and Family are set or Spec_Id denotes an
317 -- entry family, generate the entry index constant:
319 -- subtype Jnn is <Type of Index> range Low .. High;
320 -- J : constant Jnn :=
321 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
323 -- All the above declarations are inserted in the order shown to the front
324 -- of Decls.
326 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id;
327 -- Given the entity of the record type created for a task type, build
328 -- the call to Create_Task
330 function Make_Initialize_Protection
331 (Protect_Rec : Entity_Id) return List_Id;
332 -- Given the entity of the record type created for a protected type, build
333 -- a list of statements needed for proper initialization of the object.
335 function Next_Protected_Operation (N : Node_Id) return Node_Id;
336 -- Given a protected operation node (a subprogram or entry body), find the
337 -- following node in the declarations list.
339 procedure Set_Discriminals (Dec : Node_Id);
340 -- Replace discriminals in a protected type for use by the next protected
341 -- operation on the type. Each operation needs a new set of discriminals,
342 -- since it needs a unique renaming of the discriminant fields in the
343 -- record used to implement the protected type.
345 end Exp_Ch9;