OSDN Git Service

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