OSDN Git Service

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