[multiple changes]
[gcc.git] / gcc / ada / exp_ch9.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ C H 9 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2011, 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 ------------------------------------------------------------------------------
25
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Ch3; use Exp_Ch3;
32 with Exp_Ch6; use Exp_Ch6;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Dbug; use Exp_Dbug;
35 with Exp_Disp; use Exp_Disp;
36 with Exp_Sel; use Exp_Sel;
37 with Exp_Smem; use Exp_Smem;
38 with Exp_Tss; use Exp_Tss;
39 with Exp_Util; use Exp_Util;
40 with Freeze; use Freeze;
41 with Hostparm;
42 with Itypes; use Itypes;
43 with Namet; use Namet;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
46 with Opt; use Opt;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
50 with Sem; use Sem;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Ch11; use Sem_Ch11;
55 with Sem_Elab; use Sem_Elab;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Res; use Sem_Res;
58 with Sem_Util; use Sem_Util;
59 with Sinfo; use Sinfo;
60 with Snames; use Snames;
61 with Stand; use Stand;
62 with Stringt; use Stringt;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Uintp; use Uintp;
66
67 package body Exp_Ch9 is
68
69 -- The following constant establishes the upper bound for the index of
70 -- an entry family. It is used to limit the allocated size of protected
71 -- types with defaulted discriminant of an integer type, when the bound
72 -- of some entry family depends on a discriminant. The limitation to
73 -- entry families of 128K should be reasonable in all cases, and is a
74 -- documented implementation restriction.
75
76 Entry_Family_Bound : constant Int := 2**16;
77
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
81
82 function Actual_Index_Expression
83 (Sloc : Source_Ptr;
84 Ent : Entity_Id;
85 Index : Node_Id;
86 Tsk : Entity_Id) return Node_Id;
87 -- Compute the index position for an entry call. Tsk is the target task. If
88 -- the bounds of some entry family depend on discriminants, the expression
89 -- computed by this function uses the discriminants of the target task.
90
91 procedure Add_Object_Pointer
92 (Loc : Source_Ptr;
93 Conc_Typ : Entity_Id;
94 Decls : List_Id);
95 -- Prepend an object pointer declaration to the declaration list Decls.
96 -- This object pointer is initialized to a type conversion of the System.
97 -- Address pointer passed to entry barrier functions and entry body
98 -- procedures.
99
100 procedure Add_Formal_Renamings
101 (Spec : Node_Id;
102 Decls : List_Id;
103 Ent : Entity_Id;
104 Loc : Source_Ptr);
105 -- Create renaming declarations for the formals, inside the procedure that
106 -- implements an entry body. The renamings make the original names of the
107 -- formals accessible to gdb, and serve no other purpose.
108 -- Spec is the specification of the procedure being built.
109 -- Decls is the list of declarations to be enhanced.
110 -- Ent is the entity for the original entry body.
111
112 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
113 -- Transform accept statement into a block with added exception handler.
114 -- Used both for simple accept statements and for accept alternatives in
115 -- select statements. Astat is the accept statement.
116
117 function Build_Barrier_Function
118 (N : Node_Id;
119 Ent : Entity_Id;
120 Pid : Node_Id) return Node_Id;
121 -- Build the function body returning the value of the barrier expression
122 -- for the specified entry body.
123
124 function Build_Barrier_Function_Specification
125 (Loc : Source_Ptr;
126 Def_Id : Entity_Id) return Node_Id;
127 -- Build a specification for a function implementing the protected entry
128 -- barrier of the specified entry body.
129
130 function Build_Corresponding_Record
131 (N : Node_Id;
132 Ctyp : Node_Id;
133 Loc : Source_Ptr) return Node_Id;
134 -- Common to tasks and protected types. Copy discriminant specifications,
135 -- build record declaration. N is the type declaration, Ctyp is the
136 -- concurrent entity (task type or protected type).
137
138 function Build_Entry_Count_Expression
139 (Concurrent_Type : Node_Id;
140 Component_List : List_Id;
141 Loc : Source_Ptr) return Node_Id;
142 -- Compute number of entries for concurrent object. This is a count of
143 -- simple entries, followed by an expression that computes the length
144 -- of the range of each entry family. A single array with that size is
145 -- allocated for each concurrent object of the type.
146
147 function Build_Parameter_Block
148 (Loc : Source_Ptr;
149 Actuals : List_Id;
150 Formals : List_Id;
151 Decls : List_Id) return Entity_Id;
152 -- Generate an access type for each actual parameter in the list Actuals.
153 -- Create an encapsulating record that contains all the actuals and return
154 -- its type. Generate:
155 -- type Ann1 is access all <actual1-type>
156 -- ...
157 -- type AnnN is access all <actualN-type>
158 -- type Pnn is record
159 -- <formal1> : Ann1;
160 -- ...
161 -- <formalN> : AnnN;
162 -- end record;
163
164 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id);
165 -- Build body of wrapper procedure for an entry or entry family that has
166 -- pre/postconditions. The body gathers the PPC's and expands them in the
167 -- usual way, and performs the entry call itself. This way preconditions
168 -- are evaluated before the call is queued. E is the entry in question,
169 -- and Decl is the enclosing synchronized type declaration at whose
170 -- freeze point the generated body is analyzed.
171
172 function Build_Renamed_Formal_Declaration
173 (New_F : Entity_Id;
174 Formal : Entity_Id;
175 Comp : Entity_Id;
176 Renamed_Formal : Node_Id) return Node_Id;
177 -- Create a renaming declaration for a formal, within a protected entry
178 -- body or an accept body. The renamed object is a component of the
179 -- parameter block that is a parameter in the entry call.
180
181 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
182 -- does not dereference the corresponding component to prevent an illegal
183 -- use of the incomplete type (AI05-0151).
184
185 procedure Build_Wrapper_Bodies
186 (Loc : Source_Ptr;
187 Typ : Entity_Id;
188 N : Node_Id);
189 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
190 -- record of a concurrent type. N is the insertion node where all bodies
191 -- will be placed. This routine builds the bodies of the subprograms which
192 -- serve as an indirection mechanism to overriding primitives of concurrent
193 -- types, entries and protected procedures. Any new body is analyzed.
194
195 procedure Build_Wrapper_Specs
196 (Loc : Source_Ptr;
197 Typ : Entity_Id;
198 N : in out Node_Id);
199 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
200 -- record of a concurrent type. N is the insertion node where all specs
201 -- will be placed. This routine builds the specs of the subprograms which
202 -- serve as an indirection mechanism to overriding primitives of concurrent
203 -- types, entries and protected procedures. Any new spec is analyzed.
204
205 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
206 -- Build the function that translates the entry index in the call
207 -- (which depends on the size of entry families) into an index into the
208 -- Entry_Bodies_Array, to determine the body and barrier function used
209 -- in a protected entry call. A pointer to this function appears in every
210 -- protected object.
211
212 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
213 -- Build subprogram declaration for previous one
214
215 function Build_Protected_Entry
216 (N : Node_Id;
217 Ent : Entity_Id;
218 Pid : Node_Id) return Node_Id;
219 -- Build the procedure implementing the statement sequence of the specified
220 -- entry body.
221
222 function Build_Protected_Entry_Specification
223 (Loc : Source_Ptr;
224 Def_Id : Entity_Id;
225 Ent_Id : Entity_Id) return Node_Id;
226 -- Build a specification for the procedure implementing the statements of
227 -- the specified entry body. Add attributes associating it with the entry
228 -- defining identifier Ent_Id.
229
230 function Build_Protected_Spec
231 (N : Node_Id;
232 Obj_Type : Entity_Id;
233 Ident : Entity_Id;
234 Unprotected : Boolean := False) return List_Id;
235 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
236 -- Subprogram_Type. Builds signature of protected subprogram, adding the
237 -- formal that corresponds to the object itself. For an access to protected
238 -- subprogram, there is no object type to specify, so the parameter has
239 -- type Address and mode In. An indirect call through such a pointer will
240 -- convert the address to a reference to the actual object. The object is
241 -- a limited record and therefore a by_reference type.
242
243 function Build_Protected_Subprogram_Body
244 (N : Node_Id;
245 Pid : Node_Id;
246 N_Op_Spec : Node_Id) return Node_Id;
247 -- This function is used to construct the protected version of a protected
248 -- subprogram. Its statement sequence first defers abort, then locks
249 -- the associated protected object, and then enters a block that contains
250 -- a call to the unprotected version of the subprogram (for details, see
251 -- Build_Unprotected_Subprogram_Body). This block statement requires
252 -- a cleanup handler that unlocks the object in all cases.
253 -- (see Exp_Ch7.Expand_Cleanup_Actions).
254
255 function Build_Selected_Name
256 (Prefix : Entity_Id;
257 Selector : Entity_Id;
258 Append_Char : Character := ' ') return Name_Id;
259 -- Build a name in the form of Prefix__Selector, with an optional
260 -- character appended. This is used for internal subprograms generated
261 -- for operations of protected types, including barrier functions.
262 -- For the subprograms generated for entry bodies and entry barriers,
263 -- the generated name includes a sequence number that makes names
264 -- unique in the presence of entry overloading. This is necessary
265 -- because entry body procedures and barrier functions all have the
266 -- same signature.
267
268 procedure Build_Simple_Entry_Call
269 (N : Node_Id;
270 Concval : Node_Id;
271 Ename : Node_Id;
272 Index : Node_Id);
273 -- Some comments here would be useful ???
274
275 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
276 -- This routine constructs a specification for the procedure that we will
277 -- build for the task body for task type T. The spec has the form:
278 --
279 -- procedure tnameB (_Task : access tnameV);
280 --
281 -- where name is the character name taken from the task type entity that
282 -- is passed as the argument to the procedure, and tnameV is the task
283 -- value type that is associated with the task type.
284
285 function Build_Unprotected_Subprogram_Body
286 (N : Node_Id;
287 Pid : Node_Id) return Node_Id;
288 -- This routine constructs the unprotected version of a protected
289 -- subprogram body, which is contains all of the code in the
290 -- original, unexpanded body. This is the version of the protected
291 -- subprogram that is called from all protected operations on the same
292 -- object, including the protected version of the same subprogram.
293
294 procedure Collect_Entry_Families
295 (Loc : Source_Ptr;
296 Cdecls : List_Id;
297 Current_Node : in out Node_Id;
298 Conctyp : Entity_Id);
299 -- For each entry family in a concurrent type, create an anonymous array
300 -- type of the right size, and add a component to the corresponding_record.
301
302 function Concurrent_Object
303 (Spec_Id : Entity_Id;
304 Conc_Typ : Entity_Id) return Entity_Id;
305 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
306 -- the entity associated with the concurrent object in the Protected_Body_
307 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
308 -- denotes formal parameter _O, _object or _task.
309
310 function Copy_Result_Type (Res : Node_Id) return Node_Id;
311 -- Copy the result type of a function specification, when building the
312 -- internal operation corresponding to a protected function, or when
313 -- expanding an access to protected function. If the result is an anonymous
314 -- access to subprogram itself, we need to create a new signature with the
315 -- same parameter names and the same resolved types, but with new entities
316 -- for the formals.
317
318 procedure Debug_Private_Data_Declarations (Decls : List_Id);
319 -- Decls is a list which may contain the declarations created by Install_
320 -- Private_Data_Declarations. All generated entities are marked as needing
321 -- debug info and debug nodes are manually generation where necessary. This
322 -- step of the expansion must to be done after private data has been moved
323 -- to its final resting scope to ensure proper visibility of debug objects.
324
325 function Family_Offset
326 (Loc : Source_Ptr;
327 Hi : Node_Id;
328 Lo : Node_Id;
329 Ttyp : Entity_Id;
330 Cap : Boolean) return Node_Id;
331 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in
332 -- an accept statement, or the upper bound in the discrete subtype of
333 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
334 -- the concurrent type of the entry. If Cap is true, the result is
335 -- capped according to Entry_Family_Bound.
336
337 function Family_Size
338 (Loc : Source_Ptr;
339 Hi : Node_Id;
340 Lo : Node_Id;
341 Ttyp : Entity_Id;
342 Cap : Boolean) return Node_Id;
343 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
344 -- a family, and handle properly the superflat case. This is equivalent
345 -- to the use of 'Length on the index type, but must use Family_Offset
346 -- to handle properly the case of bounds that depend on discriminants.
347 -- If Cap is true, the result is capped according to Entry_Family_Bound.
348
349 procedure Find_Enclosing_Context
350 (N : Node_Id;
351 Context : out Node_Id;
352 Context_Id : out Entity_Id;
353 Context_Decls : out List_Id);
354 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
355 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
356 -- nearest enclosing body, block, package or return statement and return
357 -- its constituents. Context is the enclosing construct, Context_Id is
358 -- the scope of Context_Id and Context_Decls is the declarative list of
359 -- Context.
360
361 procedure Extract_Dispatching_Call
362 (N : Node_Id;
363 Call_Ent : out Entity_Id;
364 Object : out Entity_Id;
365 Actuals : out List_Id;
366 Formals : out List_Id);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
372
373 procedure Extract_Entry
374 (N : Node_Id;
375 Concval : out Node_Id;
376 Ename : out Node_Id;
377 Index : out Node_Id);
378 -- Given an entry call, returns the associated concurrent object,
379 -- the entry name, and the entry family index.
380
381 function Find_Task_Or_Protected_Pragma
382 (T : Node_Id;
383 P : Name_Id) return Node_Id;
384 -- Searches the task or protected definition T for the first occurrence
385 -- of the pragma whose name is given by P. The caller has ensured that
386 -- the pragma is present in the task definition. A special case is that
387 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
388 -- ??? Should be implemented with the rep item chain mechanism.
389
390 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
391 -- Given a subprogram identifier, return the entity which is associated
392 -- with the protection entry index in the Protected_Body_Subprogram or the
393 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
394 -- parameter _E.
395
396 function Is_Potentially_Large_Family
397 (Base_Index : Entity_Id;
398 Conctyp : Entity_Id;
399 Lo : Node_Id;
400 Hi : Node_Id) return Boolean;
401
402 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
403 -- Determine whether Id is a function or a procedure and is marked as a
404 -- private primitive.
405
406 function Null_Statements (Stats : List_Id) return Boolean;
407 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
408 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
409 -- well to still count as null. Returns True for a null sequence. The
410 -- argument is the list of statements from the DO-END sequence.
411
412 function Parameter_Block_Pack
413 (Loc : Source_Ptr;
414 Blk_Typ : Entity_Id;
415 Actuals : List_Id;
416 Formals : List_Id;
417 Decls : List_Id;
418 Stmts : List_Id) return Entity_Id;
419 -- Set the components of the generated parameter block with the values of
420 -- the actual parameters. Generate aliased temporaries to capture the
421 -- values for types that are passed by copy. Otherwise generate a reference
422 -- to the actual's value. Return the address of the aggregate block.
423 -- Generate:
424 -- Jnn1 : alias <formal-type1>;
425 -- Jnn1 := <actual1>;
426 -- ...
427 -- P : Blk_Typ := (
428 -- Jnn1'unchecked_access;
429 -- <actual2>'reference;
430 -- ...);
431
432 function Parameter_Block_Unpack
433 (Loc : Source_Ptr;
434 P : Entity_Id;
435 Actuals : List_Id;
436 Formals : List_Id) return List_Id;
437 -- Retrieve the values of the components from the parameter block and
438 -- assign then to the original actual parameters. Generate:
439 -- <actual1> := P.<formal1>;
440 -- ...
441 -- <actualN> := P.<formalN>;
442
443 function Trivial_Accept_OK return Boolean;
444 -- If there is no DO-END block for an accept, or if the DO-END block has
445 -- only null statements, then it is possible to do the Rendezvous with much
446 -- less overhead using the Accept_Trivial routine in the run-time library.
447 -- However, this is not always a valid optimization. Whether it is valid or
448 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
449 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
450 -- a rescheduling is required, so this optimization is not allowed. This
451 -- function returns True if the optimization is permitted.
452
453 -----------------------------
454 -- Actual_Index_Expression --
455 -----------------------------
456
457 function Actual_Index_Expression
458 (Sloc : Source_Ptr;
459 Ent : Entity_Id;
460 Index : Node_Id;
461 Tsk : Entity_Id) return Node_Id
462 is
463 Ttyp : constant Entity_Id := Etype (Tsk);
464 Expr : Node_Id;
465 Num : Node_Id;
466 Lo : Node_Id;
467 Hi : Node_Id;
468 Prev : Entity_Id;
469 S : Node_Id;
470
471 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
472 -- Compute difference between bounds of entry family
473
474 --------------------------
475 -- Actual_Family_Offset --
476 --------------------------
477
478 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
479
480 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
481 -- Replace a reference to a discriminant with a selected component
482 -- denoting the discriminant of the target task.
483
484 -----------------------------
485 -- Actual_Discriminant_Ref --
486 -----------------------------
487
488 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
489 Typ : constant Entity_Id := Etype (Bound);
490 B : Node_Id;
491
492 begin
493 if not Is_Entity_Name (Bound)
494 or else Ekind (Entity (Bound)) /= E_Discriminant
495 then
496 if Nkind (Bound) = N_Attribute_Reference then
497 return Bound;
498 else
499 B := New_Copy_Tree (Bound);
500 end if;
501
502 else
503 B :=
504 Make_Selected_Component (Sloc,
505 Prefix => New_Copy_Tree (Tsk),
506 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
507
508 Analyze_And_Resolve (B, Typ);
509 end if;
510
511 return
512 Make_Attribute_Reference (Sloc,
513 Attribute_Name => Name_Pos,
514 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
515 Expressions => New_List (B));
516 end Actual_Discriminant_Ref;
517
518 -- Start of processing for Actual_Family_Offset
519
520 begin
521 return
522 Make_Op_Subtract (Sloc,
523 Left_Opnd => Actual_Discriminant_Ref (Hi),
524 Right_Opnd => Actual_Discriminant_Ref (Lo));
525 end Actual_Family_Offset;
526
527 -- Start of processing for Actual_Index_Expression
528
529 begin
530 -- The queues of entries and entry families appear in textual order in
531 -- the associated record. The entry index is computed as the sum of the
532 -- number of queues for all entries that precede the designated one, to
533 -- which is added the index expression, if this expression denotes a
534 -- member of a family.
535
536 -- The following is a place holder for the count of simple entries
537
538 Num := Make_Integer_Literal (Sloc, 1);
539
540 -- We construct an expression which is a series of addition operations.
541 -- See comments in Entry_Index_Expression, which is identical in
542 -- structure.
543
544 if Present (Index) then
545 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
546
547 Expr :=
548 Make_Op_Add (Sloc,
549 Left_Opnd => Num,
550
551 Right_Opnd =>
552 Actual_Family_Offset (
553 Make_Attribute_Reference (Sloc,
554 Attribute_Name => Name_Pos,
555 Prefix => New_Reference_To (Base_Type (S), Sloc),
556 Expressions => New_List (Relocate_Node (Index))),
557 Type_Low_Bound (S)));
558 else
559 Expr := Num;
560 end if;
561
562 -- Now add lengths of preceding entries and entry families
563
564 Prev := First_Entity (Ttyp);
565
566 while Chars (Prev) /= Chars (Ent)
567 or else (Ekind (Prev) /= Ekind (Ent))
568 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
569 loop
570 if Ekind (Prev) = E_Entry then
571 Set_Intval (Num, Intval (Num) + 1);
572
573 elsif Ekind (Prev) = E_Entry_Family then
574 S :=
575 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
576
577 -- The need for the following full view retrieval stems from
578 -- this complex case of nested generics and tasking:
579
580 -- generic
581 -- type Formal_Index is range <>;
582 -- ...
583 -- package Outer is
584 -- type Index is private;
585 -- generic
586 -- ...
587 -- package Inner is
588 -- procedure P;
589 -- end Inner;
590 -- private
591 -- type Index is new Formal_Index range 1 .. 10;
592 -- end Outer;
593
594 -- package body Outer is
595 -- task type T is
596 -- entry Fam (Index); -- (2)
597 -- entry E;
598 -- end T;
599 -- package body Inner is -- (3)
600 -- procedure P is
601 -- begin
602 -- T.E; -- (1)
603 -- end P;
604 -- end Inner;
605 -- ...
606
607 -- We are currently building the index expression for the entry
608 -- call "T.E" (1). Part of the expansion must mention the range
609 -- of the discrete type "Index" (2) of entry family "Fam".
610 -- However only the private view of type "Index" is available to
611 -- the inner generic (3) because there was no prior mention of
612 -- the type inside "Inner". This visibility requirement is
613 -- implicit and cannot be detected during the construction of
614 -- the generic trees and needs special handling.
615
616 if In_Instance_Body
617 and then Is_Private_Type (S)
618 and then Present (Full_View (S))
619 then
620 S := Full_View (S);
621 end if;
622
623 Lo := Type_Low_Bound (S);
624 Hi := Type_High_Bound (S);
625
626 Expr :=
627 Make_Op_Add (Sloc,
628 Left_Opnd => Expr,
629 Right_Opnd =>
630 Make_Op_Add (Sloc,
631 Left_Opnd =>
632 Actual_Family_Offset (Hi, Lo),
633 Right_Opnd =>
634 Make_Integer_Literal (Sloc, 1)));
635
636 -- Other components are anonymous types to be ignored
637
638 else
639 null;
640 end if;
641
642 Next_Entity (Prev);
643 end loop;
644
645 return Expr;
646 end Actual_Index_Expression;
647
648 --------------------------
649 -- Add_Formal_Renamings --
650 --------------------------
651
652 procedure Add_Formal_Renamings
653 (Spec : Node_Id;
654 Decls : List_Id;
655 Ent : Entity_Id;
656 Loc : Source_Ptr)
657 is
658 Ptr : constant Entity_Id :=
659 Defining_Identifier
660 (Next (First (Parameter_Specifications (Spec))));
661 -- The name of the formal that holds the address of the parameter block
662 -- for the call.
663
664 Comp : Entity_Id;
665 Decl : Node_Id;
666 Formal : Entity_Id;
667 New_F : Entity_Id;
668 Renamed_Formal : Node_Id;
669
670 begin
671 Formal := First_Formal (Ent);
672 while Present (Formal) loop
673 Comp := Entry_Component (Formal);
674 New_F :=
675 Make_Defining_Identifier (Sloc (Formal),
676 Chars => Chars (Formal));
677 Set_Etype (New_F, Etype (Formal));
678 Set_Scope (New_F, Ent);
679
680 -- Now we set debug info needed on New_F even though it does not
681 -- come from source, so that the debugger will get the right
682 -- information for these generated names.
683
684 Set_Debug_Info_Needed (New_F);
685
686 if Ekind (Formal) = E_In_Parameter then
687 Set_Ekind (New_F, E_Constant);
688 else
689 Set_Ekind (New_F, E_Variable);
690 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
691 end if;
692
693 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
694
695 Renamed_Formal :=
696 Make_Selected_Component (Loc,
697 Prefix =>
698 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
699 Make_Identifier (Loc, Chars (Ptr))),
700 Selector_Name => New_Reference_To (Comp, Loc));
701
702 Decl :=
703 Build_Renamed_Formal_Declaration
704 (New_F, Formal, Comp, Renamed_Formal);
705
706 Append (Decl, Decls);
707 Set_Renamed_Object (Formal, New_F);
708 Next_Formal (Formal);
709 end loop;
710 end Add_Formal_Renamings;
711
712 ------------------------
713 -- Add_Object_Pointer --
714 ------------------------
715
716 procedure Add_Object_Pointer
717 (Loc : Source_Ptr;
718 Conc_Typ : Entity_Id;
719 Decls : List_Id)
720 is
721 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
722 Decl : Node_Id;
723 Obj_Ptr : Node_Id;
724
725 begin
726 -- Create the renaming declaration for the Protection object of a
727 -- protected type. _Object is used by Complete_Entry_Body.
728 -- ??? An attempt to make this a renaming was unsuccessful.
729
730 -- Build the entity for the access type
731
732 Obj_Ptr :=
733 Make_Defining_Identifier (Loc,
734 New_External_Name (Chars (Rec_Typ), 'P'));
735
736 -- Generate:
737 -- _object : poVP := poVP!O;
738
739 Decl :=
740 Make_Object_Declaration (Loc,
741 Defining_Identifier =>
742 Make_Defining_Identifier (Loc, Name_uObject),
743 Object_Definition =>
744 New_Reference_To (Obj_Ptr, Loc),
745 Expression =>
746 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
747 Set_Debug_Info_Needed (Defining_Identifier (Decl));
748 Prepend_To (Decls, Decl);
749
750 -- Generate:
751 -- type poVP is access poV;
752
753 Decl :=
754 Make_Full_Type_Declaration (Loc,
755 Defining_Identifier =>
756 Obj_Ptr,
757 Type_Definition =>
758 Make_Access_To_Object_Definition (Loc,
759 Subtype_Indication =>
760 New_Reference_To (Rec_Typ, Loc)));
761 Set_Debug_Info_Needed (Defining_Identifier (Decl));
762 Prepend_To (Decls, Decl);
763 end Add_Object_Pointer;
764
765 -----------------------
766 -- Build_Accept_Body --
767 -----------------------
768
769 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
770 Loc : constant Source_Ptr := Sloc (Astat);
771 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
772 New_S : Node_Id;
773 Hand : Node_Id;
774 Call : Node_Id;
775 Ohandle : Node_Id;
776
777 begin
778 -- At the end of the statement sequence, Complete_Rendezvous is called.
779 -- A label skipping the Complete_Rendezvous, and all other accept
780 -- processing, has already been added for the expansion of requeue
781 -- statements. The Sloc is copied from the last statement since it
782 -- is really part of this last statement.
783
784 Call :=
785 Build_Runtime_Call
786 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
787 Insert_Before (Last (Statements (Stats)), Call);
788 Analyze (Call);
789
790 -- If exception handlers are present, then append Complete_Rendezvous
791 -- calls to the handlers, and construct the required outer block. As
792 -- above, the Sloc is copied from the last statement in the sequence.
793
794 if Present (Exception_Handlers (Stats)) then
795 Hand := First (Exception_Handlers (Stats));
796 while Present (Hand) loop
797 Call :=
798 Build_Runtime_Call
799 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
800 Append (Call, Statements (Hand));
801 Analyze (Call);
802 Next (Hand);
803 end loop;
804
805 New_S :=
806 Make_Handled_Sequence_Of_Statements (Loc,
807 Statements => New_List (
808 Make_Block_Statement (Loc,
809 Handled_Statement_Sequence => Stats)));
810
811 else
812 New_S := Stats;
813 end if;
814
815 -- At this stage we know that the new statement sequence does not
816 -- have an exception handler part, so we supply one to call
817 -- Exceptional_Complete_Rendezvous. This handler is
818
819 -- when all others =>
820 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
821
822 -- We handle Abort_Signal to make sure that we properly catch the abort
823 -- case and wake up the caller.
824
825 Ohandle := Make_Others_Choice (Loc);
826 Set_All_Others (Ohandle);
827
828 Set_Exception_Handlers (New_S,
829 New_List (
830 Make_Implicit_Exception_Handler (Loc,
831 Exception_Choices => New_List (Ohandle),
832
833 Statements => New_List (
834 Make_Procedure_Call_Statement (Sloc (Stats),
835 Name => New_Reference_To (
836 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
837 Parameter_Associations => New_List (
838 Make_Function_Call (Sloc (Stats),
839 Name => New_Reference_To (
840 RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
841
842 Set_Parent (New_S, Astat); -- temp parent for Analyze call
843 Analyze_Exception_Handlers (Exception_Handlers (New_S));
844 Expand_Exception_Handlers (New_S);
845
846 -- Exceptional_Complete_Rendezvous must be called with abort
847 -- still deferred, which is the case for a "when all others" handler.
848
849 return New_S;
850 end Build_Accept_Body;
851
852 -----------------------------------
853 -- Build_Activation_Chain_Entity --
854 -----------------------------------
855
856 procedure Build_Activation_Chain_Entity (N : Node_Id) is
857 function Has_Activation_Chain (Stmt : Node_Id) return Boolean;
858 -- Determine whether an extended return statement has an activation
859 -- chain.
860
861 --------------------------
862 -- Has_Activation_Chain --
863 --------------------------
864
865 function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
866 Decl : Node_Id;
867
868 begin
869 Decl := First (Return_Object_Declarations (Stmt));
870 while Present (Decl) loop
871 if Nkind (Decl) = N_Object_Declaration
872 and then Chars (Defining_Identifier (Decl)) = Name_uChain
873 then
874 return True;
875 end if;
876
877 Next (Decl);
878 end loop;
879
880 return False;
881 end Has_Activation_Chain;
882
883 -- Local variables
884
885 Context : Node_Id;
886 Context_Id : Entity_Id;
887 Decls : List_Id;
888
889 -- Start of processing for Build_Activation_Chain_Entity
890
891 begin
892 Find_Enclosing_Context (N, Context, Context_Id, Decls);
893
894 -- If an activation chain entity has not been declared already, create
895 -- one.
896
897 if Nkind (Context) = N_Extended_Return_Statement
898 or else No (Activation_Chain_Entity (Context))
899 then
900 -- Since extended return statements do not store the entity of the
901 -- chain, examine the return object declarations to avoid creating
902 -- a duplicate.
903
904 if Nkind (Context) = N_Extended_Return_Statement
905 and then Has_Activation_Chain (Context)
906 then
907 return;
908 end if;
909
910 declare
911 Loc : constant Source_Ptr := Sloc (Context);
912 Chain : Entity_Id;
913 Decl : Node_Id;
914
915 begin
916 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
917
918 -- Note: An extended return statement is not really a task
919 -- activator, but it does have an activation chain on which to
920 -- store the tasks temporarily. On successful return, the tasks
921 -- on this chain are moved to the chain passed in by the caller.
922 -- We do not build an Activation_Chain_Entity for an extended
923 -- return statement, because we do not want to build a call to
924 -- Activate_Tasks. Task activation is the responsibility of the
925 -- caller.
926
927 if Nkind (Context) /= N_Extended_Return_Statement then
928 Set_Activation_Chain_Entity (Context, Chain);
929 end if;
930
931 Decl :=
932 Make_Object_Declaration (Loc,
933 Defining_Identifier => Chain,
934 Aliased_Present => True,
935 Object_Definition =>
936 New_Reference_To (RTE (RE_Activation_Chain), Loc));
937
938 Prepend_To (Decls, Decl);
939
940 -- Ensure that the _chain appears in the proper scope of the
941 -- context.
942
943 if Context_Id /= Current_Scope then
944 Push_Scope (Context_Id);
945 Analyze (Decl);
946 Pop_Scope;
947 else
948 Analyze (Decl);
949 end if;
950 end;
951 end if;
952 end Build_Activation_Chain_Entity;
953
954 ----------------------------
955 -- Build_Barrier_Function --
956 ----------------------------
957
958 function Build_Barrier_Function
959 (N : Node_Id;
960 Ent : Entity_Id;
961 Pid : Node_Id) return Node_Id
962 is
963 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
964 Cond : constant Node_Id := Condition (Ent_Formals);
965 Loc : constant Source_Ptr := Sloc (Cond);
966 Func_Id : constant Entity_Id := Barrier_Function (Ent);
967 Op_Decls : constant List_Id := New_List;
968 Stmt : Node_Id;
969 Func_Body : Node_Id;
970
971 begin
972 -- Add a declaration for the Protection object, renaming declarations
973 -- for the discriminals and privals and finally a declaration for the
974 -- entry family index (if applicable).
975
976 Install_Private_Data_Declarations (Sloc (N),
977 Spec_Id => Func_Id,
978 Conc_Typ => Pid,
979 Body_Nod => N,
980 Decls => Op_Decls,
981 Barrier => True,
982 Family => Ekind (Ent) = E_Entry_Family);
983
984 -- If compiling with -fpreserve-control-flow, make sure we insert an
985 -- IF statement so that the back-end knows to generate a conditional
986 -- branch instruction, even if the condition is just the name of a
987 -- boolean object.
988
989 if Opt.Suppress_Control_Flow_Optimizations then
990 Stmt := Make_Implicit_If_Statement (Cond,
991 Condition => Cond,
992 Then_Statements => New_List (
993 Make_Simple_Return_Statement (Loc,
994 New_Occurrence_Of (Standard_True, Loc))),
995 Else_Statements => New_List (
996 Make_Simple_Return_Statement (Loc,
997 New_Occurrence_Of (Standard_False, Loc))));
998
999 else
1000 Stmt := Make_Simple_Return_Statement (Loc, Cond);
1001 end if;
1002
1003 -- Note: the condition in the barrier function needs to be properly
1004 -- processed for the C/Fortran boolean possibility, but this happens
1005 -- automatically since the return statement does this normalization.
1006
1007 Func_Body :=
1008 Make_Subprogram_Body (Loc,
1009 Specification =>
1010 Build_Barrier_Function_Specification (Loc,
1011 Make_Defining_Identifier (Loc, Chars (Func_Id))),
1012 Declarations => Op_Decls,
1013 Handled_Statement_Sequence =>
1014 Make_Handled_Sequence_Of_Statements (Loc,
1015 Statements => New_List (Stmt)));
1016 Set_Is_Entry_Barrier_Function (Func_Body);
1017
1018 return Func_Body;
1019 end Build_Barrier_Function;
1020
1021 ------------------------------------------
1022 -- Build_Barrier_Function_Specification --
1023 ------------------------------------------
1024
1025 function Build_Barrier_Function_Specification
1026 (Loc : Source_Ptr;
1027 Def_Id : Entity_Id) return Node_Id
1028 is
1029 begin
1030 Set_Debug_Info_Needed (Def_Id);
1031
1032 return Make_Function_Specification (Loc,
1033 Defining_Unit_Name => Def_Id,
1034 Parameter_Specifications => New_List (
1035 Make_Parameter_Specification (Loc,
1036 Defining_Identifier =>
1037 Make_Defining_Identifier (Loc, Name_uO),
1038 Parameter_Type =>
1039 New_Reference_To (RTE (RE_Address), Loc)),
1040
1041 Make_Parameter_Specification (Loc,
1042 Defining_Identifier =>
1043 Make_Defining_Identifier (Loc, Name_uE),
1044 Parameter_Type =>
1045 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1046
1047 Result_Definition =>
1048 New_Reference_To (Standard_Boolean, Loc));
1049 end Build_Barrier_Function_Specification;
1050
1051 --------------------------
1052 -- Build_Call_With_Task --
1053 --------------------------
1054
1055 function Build_Call_With_Task
1056 (N : Node_Id;
1057 E : Entity_Id) return Node_Id
1058 is
1059 Loc : constant Source_Ptr := Sloc (N);
1060 begin
1061 return
1062 Make_Function_Call (Loc,
1063 Name => New_Reference_To (E, Loc),
1064 Parameter_Associations => New_List (Concurrent_Ref (N)));
1065 end Build_Call_With_Task;
1066
1067 -----------------------------
1068 -- Build_Class_Wide_Master --
1069 -----------------------------
1070
1071 procedure Build_Class_Wide_Master (Typ : Entity_Id) is
1072 Loc : constant Source_Ptr := Sloc (Typ);
1073 Master_Id : Entity_Id;
1074 Master_Scope : Entity_Id;
1075 Name_Id : Node_Id;
1076 Related_Node : Node_Id;
1077 Ren_Decl : Node_Id;
1078
1079 begin
1080 -- Nothing to do if there is no task hierarchy
1081
1082 if Restriction_Active (No_Task_Hierarchy) then
1083 return;
1084 end if;
1085
1086 -- Find the declaration that created the access type. It is either a
1087 -- type declaration, or an object declaration with an access definition,
1088 -- in which case the type is anonymous.
1089
1090 if Is_Itype (Typ) then
1091 Related_Node := Associated_Node_For_Itype (Typ);
1092 else
1093 Related_Node := Parent (Typ);
1094 end if;
1095
1096 Master_Scope := Find_Master_Scope (Typ);
1097
1098 -- Nothing to do if the master scope already contains a _master entity.
1099 -- The only exception to this is the following scenario:
1100
1101 -- Source_Scope
1102 -- Transient_Scope_1
1103 -- _master
1104
1105 -- Transient_Scope_2
1106 -- use of master
1107
1108 -- In this case the source scope is marked as having the master entity
1109 -- even though the actual declaration appears inside an inner scope. If
1110 -- the second transient scope requires a _master, it cannot use the one
1111 -- already declared because the entity is not visible.
1112
1113 Name_Id := Make_Identifier (Loc, Name_uMaster);
1114
1115 if not Has_Master_Entity (Master_Scope)
1116 or else No (Current_Entity_In_Scope (Name_Id))
1117 then
1118 declare
1119 Master_Decl : Node_Id;
1120
1121 begin
1122 Set_Has_Master_Entity (Master_Scope);
1123
1124 -- Generate:
1125 -- _master : constant Integer := Current_Master.all;
1126
1127 Master_Decl :=
1128 Make_Object_Declaration (Loc,
1129 Defining_Identifier =>
1130 Make_Defining_Identifier (Loc, Name_uMaster),
1131 Constant_Present => True,
1132 Object_Definition =>
1133 New_Reference_To (Standard_Integer, Loc),
1134 Expression =>
1135 Make_Explicit_Dereference (Loc,
1136 New_Reference_To (RTE (RE_Current_Master), Loc)));
1137
1138 Insert_Action (Related_Node, Master_Decl);
1139 Analyze (Master_Decl);
1140
1141 -- Mark the containing scope as a task master. Masters associated
1142 -- with return statements are already marked at this stage (see
1143 -- Analyze_Subprogram_Body).
1144
1145 if Ekind (Current_Scope) /= E_Return_Statement then
1146 declare
1147 Par : Node_Id := Related_Node;
1148
1149 begin
1150 while Nkind (Par) /= N_Compilation_Unit loop
1151 Par := Parent (Par);
1152
1153 -- If we fall off the top, we are at the outer level, and
1154 -- the environment task is our effective master, so
1155 -- nothing to mark.
1156
1157 if Nkind_In (Par, N_Block_Statement,
1158 N_Subprogram_Body,
1159 N_Task_Body)
1160 then
1161 Set_Is_Task_Master (Par);
1162 exit;
1163 end if;
1164 end loop;
1165 end;
1166 end if;
1167 end;
1168 end if;
1169
1170 Master_Id :=
1171 Make_Defining_Identifier (Loc,
1172 New_External_Name (Chars (Typ), 'M'));
1173
1174 -- Generate:
1175 -- Mnn renames _master;
1176
1177 Ren_Decl :=
1178 Make_Object_Renaming_Declaration (Loc,
1179 Defining_Identifier => Master_Id,
1180 Subtype_Mark => New_Reference_To (Standard_Integer, Loc),
1181 Name => Name_Id);
1182
1183 Insert_Action (Related_Node, Ren_Decl);
1184
1185 Set_Master_Id (Typ, Master_Id);
1186 end Build_Class_Wide_Master;
1187
1188 --------------------------------
1189 -- Build_Corresponding_Record --
1190 --------------------------------
1191
1192 function Build_Corresponding_Record
1193 (N : Node_Id;
1194 Ctyp : Entity_Id;
1195 Loc : Source_Ptr) return Node_Id
1196 is
1197 Rec_Ent : constant Entity_Id :=
1198 Make_Defining_Identifier
1199 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1200 Disc : Entity_Id;
1201 Dlist : List_Id;
1202 New_Disc : Entity_Id;
1203 Cdecls : List_Id;
1204
1205 begin
1206 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1207 Set_Ekind (Rec_Ent, E_Record_Type);
1208 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1209 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1210 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1211 Set_Stored_Constraint (Rec_Ent, No_Elist);
1212 Cdecls := New_List;
1213
1214 -- Use discriminals to create list of discriminants for record, and
1215 -- create new discriminals for use in default expressions, etc. It is
1216 -- worth noting that a task discriminant gives rise to 5 entities;
1217
1218 -- a) The original discriminant.
1219 -- b) The discriminal for use in the task.
1220 -- c) The discriminant of the corresponding record.
1221 -- d) The discriminal for the init proc of the corresponding record.
1222 -- e) The local variable that renames the discriminant in the procedure
1223 -- for the task body.
1224
1225 -- In fact the discriminals b) are used in the renaming declarations
1226 -- for e). See details in einfo (Handling of Discriminants).
1227
1228 if Present (Discriminant_Specifications (N)) then
1229 Dlist := New_List;
1230 Disc := First_Discriminant (Ctyp);
1231
1232 while Present (Disc) loop
1233 New_Disc := CR_Discriminant (Disc);
1234
1235 Append_To (Dlist,
1236 Make_Discriminant_Specification (Loc,
1237 Defining_Identifier => New_Disc,
1238 Discriminant_Type =>
1239 New_Occurrence_Of (Etype (Disc), Loc),
1240 Expression =>
1241 New_Copy (Discriminant_Default_Value (Disc))));
1242
1243 Next_Discriminant (Disc);
1244 end loop;
1245
1246 else
1247 Dlist := No_List;
1248 end if;
1249
1250 -- Now we can construct the record type declaration. Note that this
1251 -- record is "limited tagged". It is "limited" to reflect the underlying
1252 -- limitedness of the task or protected object that it represents, and
1253 -- ensuring for example that it is properly passed by reference. It is
1254 -- "tagged" to give support to dispatching calls through interfaces. We
1255 -- propagate here the list of interfaces covered by the concurrent type
1256 -- (Ada 2005: AI-345).
1257
1258 return
1259 Make_Full_Type_Declaration (Loc,
1260 Defining_Identifier => Rec_Ent,
1261 Discriminant_Specifications => Dlist,
1262 Type_Definition =>
1263 Make_Record_Definition (Loc,
1264 Component_List =>
1265 Make_Component_List (Loc,
1266 Component_Items => Cdecls),
1267 Tagged_Present =>
1268 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1269 Interface_List => Interface_List (N),
1270 Limited_Present => True));
1271 end Build_Corresponding_Record;
1272
1273 ----------------------------------
1274 -- Build_Entry_Count_Expression --
1275 ----------------------------------
1276
1277 function Build_Entry_Count_Expression
1278 (Concurrent_Type : Node_Id;
1279 Component_List : List_Id;
1280 Loc : Source_Ptr) return Node_Id
1281 is
1282 Eindx : Nat;
1283 Ent : Entity_Id;
1284 Ecount : Node_Id;
1285 Comp : Node_Id;
1286 Lo : Node_Id;
1287 Hi : Node_Id;
1288 Typ : Entity_Id;
1289 Large : Boolean;
1290
1291 begin
1292 -- Count number of non-family entries
1293
1294 Eindx := 0;
1295 Ent := First_Entity (Concurrent_Type);
1296 while Present (Ent) loop
1297 if Ekind (Ent) = E_Entry then
1298 Eindx := Eindx + 1;
1299 end if;
1300
1301 Next_Entity (Ent);
1302 end loop;
1303
1304 Ecount := Make_Integer_Literal (Loc, Eindx);
1305
1306 -- Loop through entry families building the addition nodes
1307
1308 Ent := First_Entity (Concurrent_Type);
1309 Comp := First (Component_List);
1310 while Present (Ent) loop
1311 if Ekind (Ent) = E_Entry_Family then
1312 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1313 Next (Comp);
1314 end loop;
1315
1316 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1317 Hi := Type_High_Bound (Typ);
1318 Lo := Type_Low_Bound (Typ);
1319 Large := Is_Potentially_Large_Family
1320 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1321 Ecount :=
1322 Make_Op_Add (Loc,
1323 Left_Opnd => Ecount,
1324 Right_Opnd => Family_Size
1325 (Loc, Hi, Lo, Concurrent_Type, Large));
1326 end if;
1327
1328 Next_Entity (Ent);
1329 end loop;
1330
1331 return Ecount;
1332 end Build_Entry_Count_Expression;
1333
1334 -----------------------
1335 -- Build_Entry_Names --
1336 -----------------------
1337
1338 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1339 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1340 B_Decls : List_Id;
1341 B_Stmts : List_Id;
1342 Comp : Node_Id;
1343 Index : Entity_Id;
1344 Index_Typ : RE_Id;
1345 Typ : Entity_Id := Conc_Typ;
1346
1347 procedure Build_Entry_Family_Name (Id : Entity_Id);
1348 -- Generate:
1349 -- for Lnn in Family_Low .. Family_High loop
1350 -- Inn := Inn + 1;
1351 -- Set_Entry_Name
1352 -- (_init._object <or> _init._task_id,
1353 -- Inn,
1354 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1355 -- end loop;
1356 -- Note that the bounds of the range may reference discriminants. The
1357 -- above construct is added directly to the statements of the block.
1358
1359 procedure Build_Entry_Name (Id : Entity_Id);
1360 -- Generate:
1361 -- Inn := Inn + 1;
1362 -- Set_Entry_Name
1363 -- (_init._object <or>_init._task_id,
1364 -- Inn,
1365 -- new String ("<Entry name>");
1366 -- The above construct is added directly to the statements of the block.
1367
1368 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1369 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1370 -- _init._task_id or _init._object, Inn and Arg3.
1371
1372 procedure Increment_Index (Stmts : List_Id);
1373 -- Generate the following and add it to Stmts
1374 -- Inn := Inn + 1;
1375
1376 -----------------------------
1377 -- Build_Entry_Family_Name --
1378 -----------------------------
1379
1380 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1381 Def : constant Node_Id :=
1382 Discrete_Subtype_Definition (Parent (Id));
1383 L_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
1384 L_Stmts : constant List_Id := New_List;
1385 Val : Node_Id;
1386
1387 function Build_Range (Def : Node_Id) return Node_Id;
1388 -- Given a discrete subtype definition of an entry family, generate a
1389 -- range node which covers the range of Def's type.
1390
1391 -----------------
1392 -- Build_Range --
1393 -----------------
1394
1395 function Build_Range (Def : Node_Id) return Node_Id is
1396 High : Node_Id := Type_High_Bound (Etype (Def));
1397 Low : Node_Id := Type_Low_Bound (Etype (Def));
1398
1399 begin
1400 -- If a bound references a discriminant, generate an identifier
1401 -- with the same name. Resolution will map it to the formals of
1402 -- the init proc.
1403
1404 if Is_Entity_Name (Low)
1405 and then Ekind (Entity (Low)) = E_Discriminant
1406 then
1407 Low := Make_Identifier (Loc, Chars (Low));
1408 else
1409 Low := New_Copy_Tree (Low);
1410 end if;
1411
1412 if Is_Entity_Name (High)
1413 and then Ekind (Entity (High)) = E_Discriminant
1414 then
1415 High := Make_Identifier (Loc, Chars (High));
1416 else
1417 High := New_Copy_Tree (High);
1418 end if;
1419
1420 return
1421 Make_Range (Loc,
1422 Low_Bound => Low,
1423 High_Bound => High);
1424 end Build_Range;
1425
1426 -- Start of processing for Build_Entry_Family_Name
1427
1428 begin
1429 Get_Name_String (Chars (Id));
1430
1431 -- Add a leading '('
1432
1433 Add_Char_To_Name_Buffer ('(');
1434
1435 -- Generate:
1436 -- new String'("<Entry name>(" & Lnn'Img & ")");
1437
1438 -- This is an implicit heap allocation, and Comes_From_Source is
1439 -- False, which ensures that it will get flagged as a violation of
1440 -- No_Implicit_Heap_Allocations when that restriction applies.
1441
1442 Val :=
1443 Make_Allocator (Loc,
1444 Make_Qualified_Expression (Loc,
1445 Subtype_Mark =>
1446 New_Reference_To (Standard_String, Loc),
1447 Expression =>
1448 Make_Op_Concat (Loc,
1449 Left_Opnd =>
1450 Make_Op_Concat (Loc,
1451 Left_Opnd =>
1452 Make_String_Literal (Loc,
1453 Strval => String_From_Name_Buffer),
1454 Right_Opnd =>
1455 Make_Attribute_Reference (Loc,
1456 Prefix =>
1457 New_Reference_To (L_Id, Loc),
1458 Attribute_Name => Name_Img)),
1459 Right_Opnd =>
1460 Make_String_Literal (Loc,
1461 Strval => ")"))));
1462
1463 Increment_Index (L_Stmts);
1464 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1465
1466 -- Generate:
1467 -- for Lnn in Family_Low .. Family_High loop
1468 -- Inn := Inn + 1;
1469 -- Set_Entry_Name
1470 -- (_init._object <or> _init._task_id, Inn, <Val>);
1471 -- end loop;
1472
1473 Append_To (B_Stmts,
1474 Make_Loop_Statement (Loc,
1475 Iteration_Scheme =>
1476 Make_Iteration_Scheme (Loc,
1477 Loop_Parameter_Specification =>
1478 Make_Loop_Parameter_Specification (Loc,
1479 Defining_Identifier => L_Id,
1480 Discrete_Subtype_Definition => Build_Range (Def))),
1481 Statements => L_Stmts,
1482 End_Label => Empty));
1483 end Build_Entry_Family_Name;
1484
1485 ----------------------
1486 -- Build_Entry_Name --
1487 ----------------------
1488
1489 procedure Build_Entry_Name (Id : Entity_Id) is
1490 Val : Node_Id;
1491
1492 begin
1493 Get_Name_String (Chars (Id));
1494
1495 -- This is an implicit heap allocation, and Comes_From_Source is
1496 -- False, which ensures that it will get flagged as a violation of
1497 -- No_Implicit_Heap_Allocations when that restriction applies.
1498
1499 Val :=
1500 Make_Allocator (Loc,
1501 Make_Qualified_Expression (Loc,
1502 Subtype_Mark =>
1503 New_Reference_To (Standard_String, Loc),
1504 Expression =>
1505 Make_String_Literal (Loc,
1506 String_From_Name_Buffer)));
1507
1508 Increment_Index (B_Stmts);
1509 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1510 end Build_Entry_Name;
1511
1512 -------------------------------
1513 -- Build_Set_Entry_Name_Call --
1514 -------------------------------
1515
1516 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1517 Arg1 : Name_Id;
1518 Proc : RE_Id;
1519
1520 begin
1521 -- Determine the proper name for the first argument and the RTS
1522 -- routine to call.
1523
1524 if Is_Protected_Type (Typ) then
1525 Arg1 := Name_uObject;
1526 Proc := RO_PE_Set_Entry_Name;
1527
1528 else pragma Assert (Is_Task_Type (Typ));
1529 Arg1 := Name_uTask_Id;
1530 Proc := RO_TS_Set_Entry_Name;
1531 end if;
1532
1533 -- Generate:
1534 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1535
1536 return
1537 Make_Procedure_Call_Statement (Loc,
1538 Name =>
1539 New_Reference_To (RTE (Proc), Loc),
1540 Parameter_Associations => New_List (
1541 Make_Selected_Component (Loc, -- _init._object
1542 Prefix => -- _init._task_id
1543 Make_Identifier (Loc, Name_uInit),
1544 Selector_Name =>
1545 Make_Identifier (Loc, Arg1)),
1546 New_Reference_To (Index, Loc), -- Inn
1547 Arg3)); -- Val
1548 end Build_Set_Entry_Name_Call;
1549
1550 ---------------------
1551 -- Increment_Index --
1552 ---------------------
1553
1554 procedure Increment_Index (Stmts : List_Id) is
1555 begin
1556 -- Generate:
1557 -- Inn := Inn + 1;
1558
1559 Append_To (Stmts,
1560 Make_Assignment_Statement (Loc,
1561 Name =>
1562 New_Reference_To (Index, Loc),
1563 Expression =>
1564 Make_Op_Add (Loc,
1565 Left_Opnd =>
1566 New_Reference_To (Index, Loc),
1567 Right_Opnd =>
1568 Make_Integer_Literal (Loc, 1))));
1569 end Increment_Index;
1570
1571 -- Start of processing for Build_Entry_Names
1572
1573 begin
1574 -- Retrieve the original concurrent type
1575
1576 if Is_Concurrent_Record_Type (Typ) then
1577 Typ := Corresponding_Concurrent_Type (Typ);
1578 end if;
1579
1580 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1581
1582 -- Nothing to do if the type has no entries
1583
1584 if not Has_Entries (Typ) then
1585 return Empty;
1586 end if;
1587
1588 -- Avoid generating entry names for a protected type with only one entry
1589
1590 if Is_Protected_Type (Typ)
1591 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1592 then
1593 return Empty;
1594 end if;
1595
1596 Index := Make_Temporary (Loc, 'I');
1597
1598 -- Step 1: Generate the declaration of the index variable:
1599 -- Inn : Protected_Entry_Index := 0;
1600 -- or
1601 -- Inn : Task_Entry_Index := 0;
1602
1603 if Is_Protected_Type (Typ) then
1604 Index_Typ := RE_Protected_Entry_Index;
1605 else
1606 Index_Typ := RE_Task_Entry_Index;
1607 end if;
1608
1609 B_Decls := New_List;
1610 Append_To (B_Decls,
1611 Make_Object_Declaration (Loc,
1612 Defining_Identifier => Index,
1613 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1614 Expression => Make_Integer_Literal (Loc, 0)));
1615
1616 B_Stmts := New_List;
1617
1618 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1619 -- family member.
1620
1621 Comp := First_Entity (Typ);
1622 while Present (Comp) loop
1623 if Ekind (Comp) = E_Entry then
1624 Build_Entry_Name (Comp);
1625
1626 elsif Ekind (Comp) = E_Entry_Family then
1627 Build_Entry_Family_Name (Comp);
1628 end if;
1629
1630 Next_Entity (Comp);
1631 end loop;
1632
1633 -- Step 3: Wrap the statements in a block
1634
1635 return
1636 Make_Block_Statement (Loc,
1637 Declarations => B_Decls,
1638 Handled_Statement_Sequence =>
1639 Make_Handled_Sequence_Of_Statements (Loc,
1640 Statements => B_Stmts));
1641 end Build_Entry_Names;
1642
1643 ---------------------------
1644 -- Build_Parameter_Block --
1645 ---------------------------
1646
1647 function Build_Parameter_Block
1648 (Loc : Source_Ptr;
1649 Actuals : List_Id;
1650 Formals : List_Id;
1651 Decls : List_Id) return Entity_Id
1652 is
1653 Actual : Entity_Id;
1654 Comp_Nam : Node_Id;
1655 Comps : List_Id;
1656 Formal : Entity_Id;
1657 Has_Comp : Boolean := False;
1658 Rec_Nam : Node_Id;
1659
1660 begin
1661 Actual := First (Actuals);
1662 Comps := New_List;
1663 Formal := Defining_Identifier (First (Formals));
1664
1665 while Present (Actual) loop
1666 if not Is_Controlling_Actual (Actual) then
1667
1668 -- Generate:
1669 -- type Ann is access all <actual-type>
1670
1671 Comp_Nam := Make_Temporary (Loc, 'A');
1672
1673 Append_To (Decls,
1674 Make_Full_Type_Declaration (Loc,
1675 Defining_Identifier => Comp_Nam,
1676 Type_Definition =>
1677 Make_Access_To_Object_Definition (Loc,
1678 All_Present => True,
1679 Constant_Present => Ekind (Formal) = E_In_Parameter,
1680 Subtype_Indication =>
1681 New_Reference_To (Etype (Actual), Loc))));
1682
1683 -- Generate:
1684 -- Param : Ann;
1685
1686 Append_To (Comps,
1687 Make_Component_Declaration (Loc,
1688 Defining_Identifier =>
1689 Make_Defining_Identifier (Loc, Chars (Formal)),
1690 Component_Definition =>
1691 Make_Component_Definition (Loc,
1692 Aliased_Present =>
1693 False,
1694 Subtype_Indication =>
1695 New_Reference_To (Comp_Nam, Loc))));
1696
1697 Has_Comp := True;
1698 end if;
1699
1700 Next_Actual (Actual);
1701 Next_Formal_With_Extras (Formal);
1702 end loop;
1703
1704 Rec_Nam := Make_Temporary (Loc, 'P');
1705
1706 if Has_Comp then
1707
1708 -- Generate:
1709 -- type Pnn is record
1710 -- Param1 : Ann1;
1711 -- ...
1712 -- ParamN : AnnN;
1713
1714 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1715 -- the original parameter names and Ann1 .. AnnN are the access to
1716 -- actual types.
1717
1718 Append_To (Decls,
1719 Make_Full_Type_Declaration (Loc,
1720 Defining_Identifier =>
1721 Rec_Nam,
1722 Type_Definition =>
1723 Make_Record_Definition (Loc,
1724 Component_List =>
1725 Make_Component_List (Loc, Comps))));
1726 else
1727 -- Generate:
1728 -- type Pnn is null record;
1729
1730 Append_To (Decls,
1731 Make_Full_Type_Declaration (Loc,
1732 Defining_Identifier =>
1733 Rec_Nam,
1734 Type_Definition =>
1735 Make_Record_Definition (Loc,
1736 Null_Present => True,
1737 Component_List => Empty)));
1738 end if;
1739
1740 return Rec_Nam;
1741 end Build_Parameter_Block;
1742
1743 --------------------------------------
1744 -- Build_Renamed_Formal_Declaration --
1745 --------------------------------------
1746
1747 function Build_Renamed_Formal_Declaration
1748 (New_F : Entity_Id;
1749 Formal : Entity_Id;
1750 Comp : Entity_Id;
1751 Renamed_Formal : Node_Id) return Node_Id
1752 is
1753 Loc : constant Source_Ptr := Sloc (New_F);
1754 Decl : Node_Id;
1755
1756 begin
1757 -- If the formal is a tagged incomplete type, it is already passed
1758 -- by reference, so it is sufficient to rename the pointer component
1759 -- that corresponds to the actual. Otherwise we need to dereference
1760 -- the pointer component to obtain the actual.
1761
1762 if Is_Incomplete_Type (Etype (Formal))
1763 and then Is_Tagged_Type (Etype (Formal))
1764 then
1765 Decl :=
1766 Make_Object_Renaming_Declaration (Loc,
1767 Defining_Identifier => New_F,
1768 Subtype_Mark => New_Reference_To (Etype (Comp), Loc),
1769 Name => Renamed_Formal);
1770
1771 else
1772 Decl :=
1773 Make_Object_Renaming_Declaration (Loc,
1774 Defining_Identifier => New_F,
1775 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
1776 Name =>
1777 Make_Explicit_Dereference (Loc, Renamed_Formal));
1778 end if;
1779
1780 return Decl;
1781 end Build_Renamed_Formal_Declaration;
1782
1783 -----------------------
1784 -- Build_PPC_Wrapper --
1785 -----------------------
1786
1787 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1788 Loc : constant Source_Ptr := Sloc (E);
1789 Synch_Type : constant Entity_Id := Scope (E);
1790
1791 Wrapper_Id : constant Entity_Id :=
1792 Make_Defining_Identifier (Loc,
1793 Chars => New_External_Name (Chars (E), 'E'));
1794 -- the wrapper procedure name
1795
1796 Wrapper_Body : Node_Id;
1797
1798 Synch_Id : constant Entity_Id :=
1799 Make_Defining_Identifier (Loc,
1800 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1801 -- The parameter that designates the synchronized object in the call
1802
1803 Actuals : constant List_Id := New_List;
1804 -- The actuals in the entry call
1805
1806 Decls : constant List_Id := New_List;
1807
1808 Entry_Call : Node_Id;
1809 Entry_Name : Node_Id;
1810
1811 Specs : List_Id;
1812 -- The specification of the wrapper procedure
1813
1814 begin
1815
1816 -- Only build the wrapper if entry has pre/postconditions.
1817 -- Should this be done unconditionally instead ???
1818
1819 declare
1820 P : Node_Id;
1821
1822 begin
1823 P := Spec_PPC_List (Contract (E));
1824 if No (P) then
1825 return;
1826 end if;
1827
1828 -- Transfer ppc pragmas to the declarations of the wrapper
1829
1830 while Present (P) loop
1831 if Pragma_Name (P) = Name_Precondition
1832 or else Pragma_Name (P) = Name_Postcondition
1833 then
1834 Append (Relocate_Node (P), Decls);
1835 Set_Analyzed (Last (Decls), False);
1836 end if;
1837
1838 P := Next_Pragma (P);
1839 end loop;
1840 end;
1841
1842 -- First formal is synchronized object
1843
1844 Specs := New_List (
1845 Make_Parameter_Specification (Loc,
1846 Defining_Identifier => Synch_Id,
1847 Out_Present => True,
1848 In_Present => True,
1849 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1850
1851 Entry_Name :=
1852 Make_Selected_Component (Loc,
1853 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1854 Selector_Name => New_Occurrence_Of (E, Loc));
1855
1856 -- If entity is entry family, second formal is the corresponding index,
1857 -- and entry name is an indexed component.
1858
1859 if Ekind (E) = E_Entry_Family then
1860 declare
1861 Index : constant Entity_Id :=
1862 Make_Defining_Identifier (Loc, Name_I);
1863 begin
1864 Append_To (Specs,
1865 Make_Parameter_Specification (Loc,
1866 Defining_Identifier => Index,
1867 Parameter_Type =>
1868 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1869
1870 Entry_Name :=
1871 Make_Indexed_Component (Loc,
1872 Prefix => Entry_Name,
1873 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
1874 end;
1875 end if;
1876
1877 Entry_Call :=
1878 Make_Procedure_Call_Statement (Loc,
1879 Name => Entry_Name,
1880 Parameter_Associations => Actuals);
1881
1882 -- Now add formals that match those of the entry, and build actuals for
1883 -- the nested entry call.
1884
1885 declare
1886 Form : Entity_Id;
1887 New_Form : Entity_Id;
1888 Parm_Spec : Node_Id;
1889
1890 begin
1891 Form := First_Formal (E);
1892 while Present (Form) loop
1893 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
1894 Parm_Spec :=
1895 Make_Parameter_Specification (Loc,
1896 Defining_Identifier => New_Form,
1897 Out_Present => Out_Present (Parent (Form)),
1898 In_Present => In_Present (Parent (Form)),
1899 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
1900
1901 Append (Parm_Spec, Specs);
1902 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1903 Next_Formal (Form);
1904 end loop;
1905 end;
1906
1907 -- Add renaming declarations for the discriminants of the enclosing
1908 -- type, which may be visible in the preconditions.
1909
1910 if Has_Discriminants (Synch_Type) then
1911 declare
1912 D : Entity_Id;
1913 Decl : Node_Id;
1914
1915 begin
1916 D := First_Discriminant (Synch_Type);
1917 while Present (D) loop
1918 Decl :=
1919 Make_Object_Renaming_Declaration (Loc,
1920 Defining_Identifier =>
1921 Make_Defining_Identifier (Loc, Chars (D)),
1922 Subtype_Mark => New_Reference_To (Etype (D), Loc),
1923 Name =>
1924 Make_Selected_Component (Loc,
1925 Prefix => New_Reference_To (Synch_Id, Loc),
1926 Selector_Name => Make_Identifier (Loc, Chars (D))));
1927 Prepend (Decl, Decls);
1928 Next_Discriminant (D);
1929 end loop;
1930 end;
1931 end if;
1932
1933 Set_PPC_Wrapper (E, Wrapper_Id);
1934 Wrapper_Body :=
1935 Make_Subprogram_Body (Loc,
1936 Specification =>
1937 Make_Procedure_Specification (Loc,
1938 Defining_Unit_Name => Wrapper_Id,
1939 Parameter_Specifications => Specs),
1940 Declarations => Decls,
1941 Handled_Statement_Sequence =>
1942 Make_Handled_Sequence_Of_Statements (Loc,
1943 Statements => New_List (Entry_Call)));
1944
1945 -- The wrapper body is analyzed when the enclosing type is frozen
1946
1947 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1948 end Build_PPC_Wrapper;
1949
1950 --------------------------
1951 -- Build_Wrapper_Bodies --
1952 --------------------------
1953
1954 procedure Build_Wrapper_Bodies
1955 (Loc : Source_Ptr;
1956 Typ : Entity_Id;
1957 N : Node_Id)
1958 is
1959 Rec_Typ : Entity_Id;
1960
1961 function Build_Wrapper_Body
1962 (Loc : Source_Ptr;
1963 Subp_Id : Entity_Id;
1964 Obj_Typ : Entity_Id;
1965 Formals : List_Id) return Node_Id;
1966 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1967 -- associated with a protected or task type. Subp_Id is the subprogram
1968 -- name which will be wrapped. Obj_Typ is the type of the new formal
1969 -- parameter which handles dispatching and object notation. Formals are
1970 -- the original formals of Subp_Id which will be explicitly replicated.
1971
1972 ------------------------
1973 -- Build_Wrapper_Body --
1974 ------------------------
1975
1976 function Build_Wrapper_Body
1977 (Loc : Source_Ptr;
1978 Subp_Id : Entity_Id;
1979 Obj_Typ : Entity_Id;
1980 Formals : List_Id) return Node_Id
1981 is
1982 Body_Spec : Node_Id;
1983
1984 begin
1985 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1986
1987 -- The subprogram is not overriding or is not a primitive declared
1988 -- between two views.
1989
1990 if No (Body_Spec) then
1991 return Empty;
1992 end if;
1993
1994 declare
1995 Actuals : List_Id := No_List;
1996 Conv_Id : Node_Id;
1997 First_Form : Node_Id;
1998 Formal : Node_Id;
1999 Nam : Node_Id;
2000
2001 begin
2002 -- Map formals to actuals. Use the list built for the wrapper
2003 -- spec, skipping the object notation parameter.
2004
2005 First_Form := First (Parameter_Specifications (Body_Spec));
2006
2007 Formal := First_Form;
2008 Next (Formal);
2009
2010 if Present (Formal) then
2011 Actuals := New_List;
2012 while Present (Formal) loop
2013 Append_To (Actuals,
2014 Make_Identifier (Loc,
2015 Chars => Chars (Defining_Identifier (Formal))));
2016 Next (Formal);
2017 end loop;
2018 end if;
2019
2020 -- Special processing for primitives declared between a private
2021 -- type and its completion: the wrapper needs a properly typed
2022 -- parameter if the wrapped operation has a controlling first
2023 -- parameter. Note that this might not be the case for a function
2024 -- with a controlling result.
2025
2026 if Is_Private_Primitive_Subprogram (Subp_Id) then
2027 if No (Actuals) then
2028 Actuals := New_List;
2029 end if;
2030
2031 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
2032 Prepend_To (Actuals,
2033 Unchecked_Convert_To
2034 (Corresponding_Concurrent_Type (Obj_Typ),
2035 Make_Identifier (Loc, Name_uO)));
2036
2037 else
2038 Prepend_To (Actuals,
2039 Make_Identifier (Loc,
2040 Chars => Chars (Defining_Identifier (First_Form))));
2041 end if;
2042
2043 Nam := New_Reference_To (Subp_Id, Loc);
2044 else
2045 -- An access-to-variable object parameter requires an explicit
2046 -- dereference in the unchecked conversion. This case occurs
2047 -- when a protected entry wrapper must override an interface
2048 -- level procedure with interface access as first parameter.
2049
2050 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2051
2052 if Nkind (Parameter_Type (First_Form)) =
2053 N_Access_Definition
2054 then
2055 Conv_Id :=
2056 Make_Explicit_Dereference (Loc,
2057 Prefix => Make_Identifier (Loc, Name_uO));
2058 else
2059 Conv_Id := Make_Identifier (Loc, Name_uO);
2060 end if;
2061
2062 Nam :=
2063 Make_Selected_Component (Loc,
2064 Prefix =>
2065 Unchecked_Convert_To
2066 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
2067 Selector_Name => New_Reference_To (Subp_Id, Loc));
2068 end if;
2069
2070 -- Create the subprogram body. For a function, the call to the
2071 -- actual subprogram has to be converted to the corresponding
2072 -- record if it is a controlling result.
2073
2074 if Ekind (Subp_Id) = E_Function then
2075 declare
2076 Res : Node_Id;
2077
2078 begin
2079 Res :=
2080 Make_Function_Call (Loc,
2081 Name => Nam,
2082 Parameter_Associations => Actuals);
2083
2084 if Has_Controlling_Result (Subp_Id) then
2085 Res :=
2086 Unchecked_Convert_To
2087 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
2088 end if;
2089
2090 return
2091 Make_Subprogram_Body (Loc,
2092 Specification => Body_Spec,
2093 Declarations => Empty_List,
2094 Handled_Statement_Sequence =>
2095 Make_Handled_Sequence_Of_Statements (Loc,
2096 Statements => New_List (
2097 Make_Simple_Return_Statement (Loc, Res))));
2098 end;
2099
2100 else
2101 return
2102 Make_Subprogram_Body (Loc,
2103 Specification => Body_Spec,
2104 Declarations => Empty_List,
2105 Handled_Statement_Sequence =>
2106 Make_Handled_Sequence_Of_Statements (Loc,
2107 Statements => New_List (
2108 Make_Procedure_Call_Statement (Loc,
2109 Name => Nam,
2110 Parameter_Associations => Actuals))));
2111 end if;
2112 end;
2113 end Build_Wrapper_Body;
2114
2115 -- Start of processing for Build_Wrapper_Bodies
2116
2117 begin
2118 if Is_Concurrent_Type (Typ) then
2119 Rec_Typ := Corresponding_Record_Type (Typ);
2120 else
2121 Rec_Typ := Typ;
2122 end if;
2123
2124 -- Generate wrapper bodies for a concurrent type which implements an
2125 -- interface.
2126
2127 if Present (Interfaces (Rec_Typ)) then
2128 declare
2129 Insert_Nod : Node_Id;
2130 Prim : Entity_Id;
2131 Prim_Elmt : Elmt_Id;
2132 Prim_Decl : Node_Id;
2133 Subp : Entity_Id;
2134 Wrap_Body : Node_Id;
2135 Wrap_Id : Entity_Id;
2136
2137 begin
2138 Insert_Nod := N;
2139
2140 -- Examine all primitive operations of the corresponding record
2141 -- type, looking for wrapper specs. Generate bodies in order to
2142 -- complete them.
2143
2144 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
2145 while Present (Prim_Elmt) loop
2146 Prim := Node (Prim_Elmt);
2147
2148 if (Ekind (Prim) = E_Function
2149 or else Ekind (Prim) = E_Procedure)
2150 and then Is_Primitive_Wrapper (Prim)
2151 then
2152 Subp := Wrapped_Entity (Prim);
2153 Prim_Decl := Parent (Parent (Prim));
2154
2155 Wrap_Body :=
2156 Build_Wrapper_Body (Loc,
2157 Subp_Id => Subp,
2158 Obj_Typ => Rec_Typ,
2159 Formals => Parameter_Specifications (Parent (Subp)));
2160 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2161
2162 Set_Corresponding_Spec (Wrap_Body, Prim);
2163 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2164
2165 Insert_After (Insert_Nod, Wrap_Body);
2166 Insert_Nod := Wrap_Body;
2167
2168 Analyze (Wrap_Body);
2169 end if;
2170
2171 Next_Elmt (Prim_Elmt);
2172 end loop;
2173 end;
2174 end if;
2175 end Build_Wrapper_Bodies;
2176
2177 ------------------------
2178 -- Build_Wrapper_Spec --
2179 ------------------------
2180
2181 function Build_Wrapper_Spec
2182 (Subp_Id : Entity_Id;
2183 Obj_Typ : Entity_Id;
2184 Formals : List_Id) return Node_Id
2185 is
2186 Loc : constant Source_Ptr := Sloc (Subp_Id);
2187 First_Param : Node_Id;
2188 Iface : Entity_Id;
2189 Iface_Elmt : Elmt_Id;
2190 Iface_Op : Entity_Id;
2191 Iface_Op_Elmt : Elmt_Id;
2192
2193 function Overriding_Possible
2194 (Iface_Op : Entity_Id;
2195 Wrapper : Entity_Id) return Boolean;
2196 -- Determine whether a primitive operation can be overridden by Wrapper.
2197 -- Iface_Op is the candidate primitive operation of an interface type,
2198 -- Wrapper is the generated entry wrapper.
2199
2200 function Replicate_Formals
2201 (Loc : Source_Ptr;
2202 Formals : List_Id) return List_Id;
2203 -- An explicit parameter replication is required due to the Is_Entry_
2204 -- Formal flag being set for all the formals of an entry. The explicit
2205 -- replication removes the flag that would otherwise cause a different
2206 -- path of analysis.
2207
2208 -------------------------
2209 -- Overriding_Possible --
2210 -------------------------
2211
2212 function Overriding_Possible
2213 (Iface_Op : Entity_Id;
2214 Wrapper : Entity_Id) return Boolean
2215 is
2216 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2217 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2218
2219 function Type_Conformant_Parameters
2220 (Iface_Op_Params : List_Id;
2221 Wrapper_Params : List_Id) return Boolean;
2222 -- Determine whether the parameters of the generated entry wrapper
2223 -- and those of a primitive operation are type conformant. During
2224 -- this check, the first parameter of the primitive operation is
2225 -- skipped if it is a controlling argument: protected functions
2226 -- may have a controlling result.
2227
2228 --------------------------------
2229 -- Type_Conformant_Parameters --
2230 --------------------------------
2231
2232 function Type_Conformant_Parameters
2233 (Iface_Op_Params : List_Id;
2234 Wrapper_Params : List_Id) return Boolean
2235 is
2236 Iface_Op_Param : Node_Id;
2237 Iface_Op_Typ : Entity_Id;
2238 Wrapper_Param : Node_Id;
2239 Wrapper_Typ : Entity_Id;
2240
2241 begin
2242 -- Skip the first (controlling) parameter of primitive operation
2243
2244 Iface_Op_Param := First (Iface_Op_Params);
2245
2246 if Present (First_Formal (Iface_Op))
2247 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2248 then
2249 Iface_Op_Param := Next (Iface_Op_Param);
2250 end if;
2251
2252 Wrapper_Param := First (Wrapper_Params);
2253 while Present (Iface_Op_Param)
2254 and then Present (Wrapper_Param)
2255 loop
2256 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2257 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2258
2259 -- The two parameters must be mode conformant
2260
2261 if not Conforming_Types
2262 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2263 then
2264 return False;
2265 end if;
2266
2267 Next (Iface_Op_Param);
2268 Next (Wrapper_Param);
2269 end loop;
2270
2271 -- One of the lists is longer than the other
2272
2273 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2274 return False;
2275 end if;
2276
2277 return True;
2278 end Type_Conformant_Parameters;
2279
2280 -- Start of processing for Overriding_Possible
2281
2282 begin
2283 if Chars (Iface_Op) /= Chars (Wrapper) then
2284 return False;
2285 end if;
2286
2287 -- If an inherited subprogram is implemented by a protected procedure
2288 -- or an entry, then the first parameter of the inherited subprogram
2289 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2290
2291 if Ekind (Iface_Op) = E_Procedure
2292 and then Present (Parameter_Specifications (Iface_Op_Spec))
2293 then
2294 declare
2295 Obj_Param : constant Node_Id :=
2296 First (Parameter_Specifications (Iface_Op_Spec));
2297 begin
2298 if not Out_Present (Obj_Param)
2299 and then Nkind (Parameter_Type (Obj_Param)) /=
2300 N_Access_Definition
2301 then
2302 return False;
2303 end if;
2304 end;
2305 end if;
2306
2307 return
2308 Type_Conformant_Parameters (
2309 Parameter_Specifications (Iface_Op_Spec),
2310 Parameter_Specifications (Wrapper_Spec));
2311 end Overriding_Possible;
2312
2313 -----------------------
2314 -- Replicate_Formals --
2315 -----------------------
2316
2317 function Replicate_Formals
2318 (Loc : Source_Ptr;
2319 Formals : List_Id) return List_Id
2320 is
2321 New_Formals : constant List_Id := New_List;
2322 Formal : Node_Id;
2323 Param_Type : Node_Id;
2324
2325 begin
2326 Formal := First (Formals);
2327
2328 -- Skip the object parameter when dealing with primitives declared
2329 -- between two views.
2330
2331 if Is_Private_Primitive_Subprogram (Subp_Id)
2332 and then not Has_Controlling_Result (Subp_Id)
2333 then
2334 Formal := Next (Formal);
2335 end if;
2336
2337 while Present (Formal) loop
2338
2339 -- Create an explicit copy of the entry parameter
2340
2341 -- When creating the wrapper subprogram for a primitive operation
2342 -- of a protected interface we must construct an equivalent
2343 -- signature to that of the overriding operation. For regular
2344 -- parameters we can just use the type of the formal, but for
2345 -- access to subprogram parameters we need to reanalyze the
2346 -- parameter type to create local entities for the signature of
2347 -- the subprogram type. Using the entities of the overriding
2348 -- subprogram will result in out-of-scope errors in the back-end.
2349
2350 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2351 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2352 else
2353 Param_Type :=
2354 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
2355 end if;
2356
2357 Append_To (New_Formals,
2358 Make_Parameter_Specification (Loc,
2359 Defining_Identifier =>
2360 Make_Defining_Identifier (Loc,
2361 Chars => Chars (Defining_Identifier (Formal))),
2362 In_Present => In_Present (Formal),
2363 Out_Present => Out_Present (Formal),
2364 Parameter_Type => Param_Type));
2365
2366 Next (Formal);
2367 end loop;
2368
2369 return New_Formals;
2370 end Replicate_Formals;
2371
2372 -- Start of processing for Build_Wrapper_Spec
2373
2374 begin
2375 -- There is no point in building wrappers for non-tagged concurrent
2376 -- types.
2377
2378 pragma Assert (Is_Tagged_Type (Obj_Typ));
2379
2380 -- An entry or a protected procedure can override a routine where the
2381 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2382 -- type. Since the wrapper must have the exact same signature as that of
2383 -- the overridden subprogram, we try to find the overriding candidate
2384 -- and use its controlling formal.
2385
2386 First_Param := Empty;
2387
2388 -- Check every implemented interface
2389
2390 if Present (Interfaces (Obj_Typ)) then
2391 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2392 Search : while Present (Iface_Elmt) loop
2393 Iface := Node (Iface_Elmt);
2394
2395 -- Check every interface primitive
2396
2397 if Present (Primitive_Operations (Iface)) then
2398 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2399 while Present (Iface_Op_Elmt) loop
2400 Iface_Op := Node (Iface_Op_Elmt);
2401
2402 -- Ignore predefined primitives
2403
2404 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2405 Iface_Op := Ultimate_Alias (Iface_Op);
2406
2407 -- The current primitive operation can be overridden by
2408 -- the generated entry wrapper.
2409
2410 if Overriding_Possible (Iface_Op, Subp_Id) then
2411 First_Param :=
2412 First (Parameter_Specifications (Parent (Iface_Op)));
2413
2414 exit Search;
2415 end if;
2416 end if;
2417
2418 Next_Elmt (Iface_Op_Elmt);
2419 end loop;
2420 end if;
2421
2422 Next_Elmt (Iface_Elmt);
2423 end loop Search;
2424 end if;
2425
2426 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2427 -- this subprogram and this is not a primitive declared between two
2428 -- views then force the generation of a wrapper. As an optimization,
2429 -- previous versions of the frontend avoid generating the wrapper;
2430 -- however, the wrapper facilitates locating and reporting an error
2431 -- when a duplicate declaration is found later. See example in
2432 -- AI05-0090-1.
2433
2434 if No (First_Param)
2435 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2436 then
2437 if Is_Task_Type
2438 (Corresponding_Concurrent_Type (Obj_Typ))
2439 then
2440 First_Param :=
2441 Make_Parameter_Specification (Loc,
2442 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2443 In_Present => True,
2444 Out_Present => False,
2445 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2446
2447 -- For entries and procedures of protected types the mode of
2448 -- the controlling argument must be in-out.
2449
2450 else
2451 First_Param :=
2452 Make_Parameter_Specification (Loc,
2453 Defining_Identifier =>
2454 Make_Defining_Identifier (Loc,
2455 Chars => Name_uO),
2456 In_Present => True,
2457 Out_Present => (Ekind (Subp_Id) /= E_Function),
2458 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2459 end if;
2460 end if;
2461
2462 declare
2463 Wrapper_Id : constant Entity_Id :=
2464 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2465 New_Formals : List_Id;
2466 Obj_Param : Node_Id;
2467 Obj_Param_Typ : Entity_Id;
2468
2469 begin
2470 -- Minimum decoration is needed to catch the entity in
2471 -- Sem_Ch6.Override_Dispatching_Operation.
2472
2473 if Ekind (Subp_Id) = E_Function then
2474 Set_Ekind (Wrapper_Id, E_Function);
2475 else
2476 Set_Ekind (Wrapper_Id, E_Procedure);
2477 end if;
2478
2479 Set_Is_Primitive_Wrapper (Wrapper_Id);
2480 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2481 Set_Is_Private_Primitive (Wrapper_Id,
2482 Is_Private_Primitive_Subprogram (Subp_Id));
2483
2484 -- Process the formals
2485
2486 New_Formals := Replicate_Formals (Loc, Formals);
2487
2488 -- A function with a controlling result and no first controlling
2489 -- formal needs no additional parameter.
2490
2491 if Has_Controlling_Result (Subp_Id)
2492 and then
2493 (No (First_Formal (Subp_Id))
2494 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2495 then
2496 null;
2497
2498 -- Routine Subp_Id has been found to override an interface primitive.
2499 -- If the interface operation has an access parameter, create a copy
2500 -- of it, with the same null exclusion indicator if present.
2501
2502 elsif Present (First_Param) then
2503 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2504 Obj_Param_Typ :=
2505 Make_Access_Definition (Loc,
2506 Subtype_Mark =>
2507 New_Reference_To (Obj_Typ, Loc));
2508 Set_Null_Exclusion_Present (Obj_Param_Typ,
2509 Null_Exclusion_Present (Parameter_Type (First_Param)));
2510
2511 else
2512 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2513 end if;
2514
2515 Obj_Param :=
2516 Make_Parameter_Specification (Loc,
2517 Defining_Identifier =>
2518 Make_Defining_Identifier (Loc,
2519 Chars => Name_uO),
2520 In_Present => In_Present (First_Param),
2521 Out_Present => Out_Present (First_Param),
2522 Parameter_Type => Obj_Param_Typ);
2523
2524 Prepend_To (New_Formals, Obj_Param);
2525
2526 -- If we are dealing with a primitive declared between two views,
2527 -- implemented by a synchronized operation, we need to create
2528 -- a default parameter. The mode of the parameter must match that
2529 -- of the primitive operation.
2530
2531 else
2532 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2533 Obj_Param :=
2534 Make_Parameter_Specification (Loc,
2535 Defining_Identifier =>
2536 Make_Defining_Identifier (Loc, Name_uO),
2537 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2538 Out_Present => Ekind (Subp_Id) /= E_Function,
2539 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2540 Prepend_To (New_Formals, Obj_Param);
2541 end if;
2542
2543 -- Build the final spec. If it is a function with a controlling
2544 -- result, it is a primitive operation of the corresponding
2545 -- record type, so mark the spec accordingly.
2546
2547 if Ekind (Subp_Id) = E_Function then
2548 declare
2549 Res_Def : Node_Id;
2550
2551 begin
2552 if Has_Controlling_Result (Subp_Id) then
2553 Res_Def :=
2554 New_Occurrence_Of
2555 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2556 else
2557 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2558 end if;
2559
2560 return
2561 Make_Function_Specification (Loc,
2562 Defining_Unit_Name => Wrapper_Id,
2563 Parameter_Specifications => New_Formals,
2564 Result_Definition => Res_Def);
2565 end;
2566 else
2567 return
2568 Make_Procedure_Specification (Loc,
2569 Defining_Unit_Name => Wrapper_Id,
2570 Parameter_Specifications => New_Formals);
2571 end if;
2572 end;
2573 end Build_Wrapper_Spec;
2574
2575 -------------------------
2576 -- Build_Wrapper_Specs --
2577 -------------------------
2578
2579 procedure Build_Wrapper_Specs
2580 (Loc : Source_Ptr;
2581 Typ : Entity_Id;
2582 N : in out Node_Id)
2583 is
2584 Def : Node_Id;
2585 Rec_Typ : Entity_Id;
2586 procedure Scan_Declarations (L : List_Id);
2587 -- Common processing for visible and private declarations
2588 -- of a protected type.
2589
2590 procedure Scan_Declarations (L : List_Id) is
2591 Decl : Node_Id;
2592 Wrap_Decl : Node_Id;
2593 Wrap_Spec : Node_Id;
2594
2595 begin
2596 if No (L) then
2597 return;
2598 end if;
2599
2600 Decl := First (L);
2601 while Present (Decl) loop
2602 Wrap_Spec := Empty;
2603
2604 if Nkind (Decl) = N_Entry_Declaration
2605 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2606 then
2607 Wrap_Spec :=
2608 Build_Wrapper_Spec
2609 (Subp_Id => Defining_Identifier (Decl),
2610 Obj_Typ => Rec_Typ,
2611 Formals => Parameter_Specifications (Decl));
2612
2613 elsif Nkind (Decl) = N_Subprogram_Declaration then
2614 Wrap_Spec :=
2615 Build_Wrapper_Spec
2616 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2617 Obj_Typ => Rec_Typ,
2618 Formals =>
2619 Parameter_Specifications (Specification (Decl)));
2620 end if;
2621
2622 if Present (Wrap_Spec) then
2623 Wrap_Decl :=
2624 Make_Subprogram_Declaration (Loc,
2625 Specification => Wrap_Spec);
2626
2627 Insert_After (N, Wrap_Decl);
2628 N := Wrap_Decl;
2629
2630 Analyze (Wrap_Decl);
2631 end if;
2632
2633 Next (Decl);
2634 end loop;
2635 end Scan_Declarations;
2636
2637 -- start of processing for Build_Wrapper_Specs
2638
2639 begin
2640 if Is_Protected_Type (Typ) then
2641 Def := Protected_Definition (Parent (Typ));
2642 else pragma Assert (Is_Task_Type (Typ));
2643 Def := Task_Definition (Parent (Typ));
2644 end if;
2645
2646 Rec_Typ := Corresponding_Record_Type (Typ);
2647
2648 -- Generate wrapper specs for a concurrent type which implements an
2649 -- interface. Operations in both the visible and private parts may
2650 -- implement progenitor operations.
2651
2652 if Present (Interfaces (Rec_Typ))
2653 and then Present (Def)
2654 then
2655 Scan_Declarations (Visible_Declarations (Def));
2656 Scan_Declarations (Private_Declarations (Def));
2657 end if;
2658 end Build_Wrapper_Specs;
2659
2660 ---------------------------
2661 -- Build_Find_Body_Index --
2662 ---------------------------
2663
2664 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2665 Loc : constant Source_Ptr := Sloc (Typ);
2666 Ent : Entity_Id;
2667 E_Typ : Entity_Id;
2668 Has_F : Boolean := False;
2669 Index : Nat;
2670 If_St : Node_Id := Empty;
2671 Lo : Node_Id;
2672 Hi : Node_Id;
2673 Decls : List_Id := New_List;
2674 Ret : Node_Id;
2675 Spec : Node_Id;
2676 Siz : Node_Id := Empty;
2677
2678 procedure Add_If_Clause (Expr : Node_Id);
2679 -- Add test for range of current entry
2680
2681 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2682 -- If a bound of an entry is given by a discriminant, retrieve the
2683 -- actual value of the discriminant from the enclosing object.
2684
2685 -------------------
2686 -- Add_If_Clause --
2687 -------------------
2688
2689 procedure Add_If_Clause (Expr : Node_Id) is
2690 Cond : Node_Id;
2691 Stats : constant List_Id :=
2692 New_List (
2693 Make_Simple_Return_Statement (Loc,
2694 Expression => Make_Integer_Literal (Loc, Index + 1)));
2695
2696 begin
2697 -- Index for current entry body
2698
2699 Index := Index + 1;
2700
2701 -- Compute total length of entry queues so far
2702
2703 if No (Siz) then
2704 Siz := Expr;
2705 else
2706 Siz :=
2707 Make_Op_Add (Loc,
2708 Left_Opnd => Siz,
2709 Right_Opnd => Expr);
2710 end if;
2711
2712 Cond :=
2713 Make_Op_Le (Loc,
2714 Left_Opnd => Make_Identifier (Loc, Name_uE),
2715 Right_Opnd => Siz);
2716
2717 -- Map entry queue indexes in the range of the current family
2718 -- into the current index, that designates the entry body.
2719
2720 if No (If_St) then
2721 If_St :=
2722 Make_Implicit_If_Statement (Typ,
2723 Condition => Cond,
2724 Then_Statements => Stats,
2725 Elsif_Parts => New_List);
2726
2727 Ret := If_St;
2728
2729 else
2730 Append (
2731 Make_Elsif_Part (Loc,
2732 Condition => Cond,
2733 Then_Statements => Stats),
2734 Elsif_Parts (If_St));
2735 end if;
2736 end Add_If_Clause;
2737
2738 ------------------------------
2739 -- Convert_Discriminant_Ref --
2740 ------------------------------
2741
2742 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2743 B : Node_Id;
2744
2745 begin
2746 if Is_Entity_Name (Bound)
2747 and then Ekind (Entity (Bound)) = E_Discriminant
2748 then
2749 B :=
2750 Make_Selected_Component (Loc,
2751 Prefix =>
2752 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2753 Make_Explicit_Dereference (Loc,
2754 Make_Identifier (Loc, Name_uObject))),
2755 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2756 Set_Etype (B, Etype (Entity (Bound)));
2757 else
2758 B := New_Copy_Tree (Bound);
2759 end if;
2760
2761 return B;
2762 end Convert_Discriminant_Ref;
2763
2764 -- Start of processing for Build_Find_Body_Index
2765
2766 begin
2767 Spec := Build_Find_Body_Index_Spec (Typ);
2768
2769 Ent := First_Entity (Typ);
2770 while Present (Ent) loop
2771 if Ekind (Ent) = E_Entry_Family then
2772 Has_F := True;
2773 exit;
2774 end if;
2775
2776 Next_Entity (Ent);
2777 end loop;
2778
2779 if not Has_F then
2780
2781 -- If the protected type has no entry families, there is a one-one
2782 -- correspondence between entry queue and entry body.
2783
2784 Ret :=
2785 Make_Simple_Return_Statement (Loc,
2786 Expression => Make_Identifier (Loc, Name_uE));
2787
2788 else
2789 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2790 -- the following:
2791 --
2792 -- if E <= l1 then return 1;
2793 -- elsif E <= l1 + l2 then return 2;
2794 -- ...
2795
2796 Index := 0;
2797 Siz := Empty;
2798 Ent := First_Entity (Typ);
2799
2800 Add_Object_Pointer (Loc, Typ, Decls);
2801
2802 while Present (Ent) loop
2803 if Ekind (Ent) = E_Entry then
2804 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2805
2806 elsif Ekind (Ent) = E_Entry_Family then
2807 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2808 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2809 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2810 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2811 end if;
2812
2813 Next_Entity (Ent);
2814 end loop;
2815
2816 if Index = 1 then
2817 Decls := New_List;
2818 Ret :=
2819 Make_Simple_Return_Statement (Loc,
2820 Expression => Make_Integer_Literal (Loc, 1));
2821
2822 elsif Nkind (Ret) = N_If_Statement then
2823
2824 -- Ranges are in increasing order, so last one doesn't need guard
2825
2826 declare
2827 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2828 begin
2829 Remove (Nod);
2830 Set_Else_Statements (Ret, Then_Statements (Nod));
2831 end;
2832 end if;
2833 end if;
2834
2835 return
2836 Make_Subprogram_Body (Loc,
2837 Specification => Spec,
2838 Declarations => Decls,
2839 Handled_Statement_Sequence =>
2840 Make_Handled_Sequence_Of_Statements (Loc,
2841 Statements => New_List (Ret)));
2842 end Build_Find_Body_Index;
2843
2844 --------------------------------
2845 -- Build_Find_Body_Index_Spec --
2846 --------------------------------
2847
2848 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2849 Loc : constant Source_Ptr := Sloc (Typ);
2850 Id : constant Entity_Id :=
2851 Make_Defining_Identifier (Loc,
2852 Chars => New_External_Name (Chars (Typ), 'F'));
2853 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2854 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2855
2856 begin
2857 return
2858 Make_Function_Specification (Loc,
2859 Defining_Unit_Name => Id,
2860 Parameter_Specifications => New_List (
2861 Make_Parameter_Specification (Loc,
2862 Defining_Identifier => Parm1,
2863 Parameter_Type =>
2864 New_Reference_To (RTE (RE_Address), Loc)),
2865
2866 Make_Parameter_Specification (Loc,
2867 Defining_Identifier => Parm2,
2868 Parameter_Type =>
2869 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2870 Result_Definition => New_Occurrence_Of (
2871 RTE (RE_Protected_Entry_Index), Loc));
2872 end Build_Find_Body_Index_Spec;
2873
2874 -------------------------
2875 -- Build_Master_Entity --
2876 -------------------------
2877
2878 procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
2879 Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
2880 Context : Node_Id;
2881 Context_Id : Entity_Id;
2882 Decl : Node_Id;
2883 Decls : List_Id;
2884 Par : Node_Id;
2885
2886 begin
2887 if Is_Itype (Obj_Or_Typ) then
2888 Par := Associated_Node_For_Itype (Obj_Or_Typ);
2889 else
2890 Par := Parent (Obj_Or_Typ);
2891 end if;
2892
2893 -- When creating a master for a record component which is either a task
2894 -- or access-to-task, the enclosing record is the master scope and the
2895 -- proper insertion point is the component list.
2896
2897 if Is_Record_Type (Current_Scope) then
2898 Context := Par;
2899 Context_Id := Current_Scope;
2900 Decls := List_Containing (Context);
2901
2902 -- Default case for object declarations and access types. Note that the
2903 -- context is updated to the nearest enclosing body, block, package or
2904 -- return statement.
2905
2906 else
2907 Find_Enclosing_Context (Par, Context, Context_Id, Decls);
2908 end if;
2909
2910 -- Do not create a master if one already exists or there is no task
2911 -- hierarchy.
2912
2913 if Has_Master_Entity (Context_Id)
2914 or else Restriction_Active (No_Task_Hierarchy)
2915 then
2916 return;
2917 end if;
2918
2919 -- Create a master, generate:
2920 -- _Master : constant Master_Id := Current_Master.all;
2921
2922 Decl :=
2923 Make_Object_Declaration (Loc,
2924 Defining_Identifier =>
2925 Make_Defining_Identifier (Loc, Name_uMaster),
2926 Constant_Present => True,
2927 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2928 Expression =>
2929 Make_Explicit_Dereference (Loc,
2930 New_Reference_To (RTE (RE_Current_Master), Loc)));
2931
2932 -- The master is inserted at the start of the declarative list of the
2933 -- context.
2934
2935 Prepend_To (Decls, Decl);
2936
2937 -- In certain cases where transient scopes are involved, the immediate
2938 -- scope is not always the proper master scope. Ensure that the master
2939 -- declaration and entity appear in the same context.
2940
2941 if Context_Id /= Current_Scope then
2942 Push_Scope (Context_Id);
2943 Analyze (Decl);
2944 Pop_Scope;
2945 else
2946 Analyze (Decl);
2947 end if;
2948
2949 -- Mark the enclosing scope and its associated construct as being task
2950 -- masters.
2951
2952 Set_Has_Master_Entity (Context_Id);
2953
2954 while Present (Context)
2955 and then Nkind (Context) /= N_Compilation_Unit
2956 loop
2957 if Nkind_In (Context, N_Block_Statement,
2958 N_Subprogram_Body,
2959 N_Task_Body)
2960 then
2961 Set_Is_Task_Master (Context);
2962 exit;
2963
2964 elsif Nkind (Parent (Context)) = N_Subunit then
2965 Context := Corresponding_Stub (Parent (Context));
2966 end if;
2967
2968 Context := Parent (Context);
2969 end loop;
2970 end Build_Master_Entity;
2971
2972 ---------------------------
2973 -- Build_Master_Renaming --
2974 ---------------------------
2975
2976 procedure Build_Master_Renaming
2977 (Ptr_Typ : Entity_Id;
2978 Ins_Nod : Node_Id := Empty)
2979 is
2980 Loc : constant Source_Ptr := Sloc (Ptr_Typ);
2981 Context : Node_Id;
2982 Master_Decl : Node_Id;
2983 Master_Id : Entity_Id;
2984
2985 begin
2986 -- Nothing to do if there is no task hierarchy
2987
2988 if Restriction_Active (No_Task_Hierarchy) then
2989 return;
2990 end if;
2991
2992 -- Determine the proper context to insert the master renaming
2993
2994 if Present (Ins_Nod) then
2995 Context := Ins_Nod;
2996 elsif Is_Itype (Ptr_Typ) then
2997 Context := Associated_Node_For_Itype (Ptr_Typ);
2998 else
2999 Context := Parent (Ptr_Typ);
3000 end if;
3001
3002 -- Generate:
3003 -- <Ptr_Typ>M : Master_Id renames _Master;
3004
3005 Master_Id :=
3006 Make_Defining_Identifier (Loc,
3007 New_External_Name (Chars (Ptr_Typ), 'M'));
3008
3009 Master_Decl :=
3010 Make_Object_Renaming_Declaration (Loc,
3011 Defining_Identifier => Master_Id,
3012 Subtype_Mark => New_Reference_To (RTE (RE_Master_Id), Loc),
3013 Name => Make_Identifier (Loc, Name_uMaster));
3014
3015 Insert_Action (Context, Master_Decl);
3016
3017 -- The renamed master now services the access type
3018
3019 Set_Master_Id (Ptr_Typ, Master_Id);
3020 end Build_Master_Renaming;
3021
3022 -----------------------------------------
3023 -- Build_Private_Protected_Declaration --
3024 -----------------------------------------
3025
3026 function Build_Private_Protected_Declaration
3027 (N : Node_Id) return Entity_Id
3028 is
3029 Loc : constant Source_Ptr := Sloc (N);
3030 Body_Id : constant Entity_Id := Defining_Entity (N);
3031 Decl : Node_Id;
3032 Plist : List_Id;
3033 Formal : Entity_Id;
3034 New_Spec : Node_Id;
3035 Spec_Id : Entity_Id;
3036
3037 begin
3038 Formal := First_Formal (Body_Id);
3039
3040 -- The protected operation always has at least one formal, namely the
3041 -- object itself, but it is only placed in the parameter list if
3042 -- expansion is enabled.
3043
3044 if Present (Formal) or else Expander_Active then
3045 Plist := Copy_Parameter_List (Body_Id);
3046 else
3047 Plist := No_List;
3048 end if;
3049
3050 if Nkind (Specification (N)) = N_Procedure_Specification then
3051 New_Spec :=
3052 Make_Procedure_Specification (Loc,
3053 Defining_Unit_Name =>
3054 Make_Defining_Identifier (Sloc (Body_Id),
3055 Chars => Chars (Body_Id)),
3056 Parameter_Specifications =>
3057 Plist);
3058 else
3059 New_Spec :=
3060 Make_Function_Specification (Loc,
3061 Defining_Unit_Name =>
3062 Make_Defining_Identifier (Sloc (Body_Id),
3063 Chars => Chars (Body_Id)),
3064 Parameter_Specifications => Plist,
3065 Result_Definition =>
3066 New_Occurrence_Of (Etype (Body_Id), Loc));
3067 end if;
3068
3069 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
3070 Insert_Before (N, Decl);
3071 Spec_Id := Defining_Unit_Name (New_Spec);
3072
3073 -- Indicate that the entity comes from source, to ensure that cross-
3074 -- reference information is properly generated. The body itself is
3075 -- rewritten during expansion, and the body entity will not appear in
3076 -- calls to the operation.
3077
3078 Set_Comes_From_Source (Spec_Id, True);
3079 Analyze (Decl);
3080 Set_Has_Completion (Spec_Id);
3081 Set_Convention (Spec_Id, Convention_Protected);
3082 return Spec_Id;
3083 end Build_Private_Protected_Declaration;
3084
3085 ---------------------------
3086 -- Build_Protected_Entry --
3087 ---------------------------
3088
3089 function Build_Protected_Entry
3090 (N : Node_Id;
3091 Ent : Entity_Id;
3092 Pid : Node_Id) return Node_Id
3093 is
3094 Loc : constant Source_Ptr := Sloc (N);
3095
3096 Decls : constant List_Id := Declarations (N);
3097 End_Lab : constant Node_Id :=
3098 End_Label (Handled_Statement_Sequence (N));
3099 End_Loc : constant Source_Ptr :=
3100 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
3101 -- Used for the generated call to Complete_Entry_Body
3102
3103 Han_Loc : Source_Ptr;
3104 -- Used for the exception handler, inserted at end of the body
3105
3106 Op_Decls : constant List_Id := New_List;
3107 Complete : Node_Id;
3108 Edef : Entity_Id;
3109 Espec : Node_Id;
3110 Ohandle : Node_Id;
3111 Op_Stats : List_Id;
3112
3113 begin
3114 -- Set the source location on the exception handler only when debugging
3115 -- the expanded code (see Make_Implicit_Exception_Handler).
3116
3117 if Debug_Generated_Code then
3118 Han_Loc := End_Loc;
3119
3120 -- Otherwise the inserted code should not be visible to the debugger
3121
3122 else
3123 Han_Loc := No_Location;
3124 end if;
3125
3126 Edef :=
3127 Make_Defining_Identifier (Loc,
3128 Chars => Chars (Protected_Body_Subprogram (Ent)));
3129 Espec :=
3130 Build_Protected_Entry_Specification (Loc, Edef, Empty);
3131
3132 -- Add the following declarations:
3133 -- type poVP is access poV;
3134 -- _object : poVP := poVP (_O);
3135 --
3136 -- where _O is the formal parameter associated with the concurrent
3137 -- object. These declarations are needed for Complete_Entry_Body.
3138
3139 Add_Object_Pointer (Loc, Pid, Op_Decls);
3140
3141 -- Add renamings for all formals, the Protection object, discriminals,
3142 -- privals and the entry index constant for use by debugger.
3143
3144 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
3145 Debug_Private_Data_Declarations (Decls);
3146
3147 case Corresponding_Runtime_Package (Pid) is
3148 when System_Tasking_Protected_Objects_Entries =>
3149 Complete :=
3150 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
3151
3152 when System_Tasking_Protected_Objects_Single_Entry =>
3153 Complete :=
3154 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
3155
3156 when others =>
3157 raise Program_Error;
3158 end case;
3159
3160 Op_Stats := New_List (
3161 Make_Block_Statement (Loc,
3162 Declarations => Decls,
3163 Handled_Statement_Sequence =>
3164 Handled_Statement_Sequence (N)),
3165
3166 Make_Procedure_Call_Statement (End_Loc,
3167 Name => Complete,
3168 Parameter_Associations => New_List (
3169 Make_Attribute_Reference (End_Loc,
3170 Prefix =>
3171 Make_Selected_Component (End_Loc,
3172 Prefix => Make_Identifier (End_Loc, Name_uObject),
3173 Selector_Name => Make_Identifier (End_Loc, Name_uObject)),
3174 Attribute_Name => Name_Unchecked_Access))));
3175
3176 -- When exceptions can not be propagated, we never need to call
3177 -- Exception_Complete_Entry_Body
3178
3179 if No_Exception_Handlers_Set then
3180 return
3181 Make_Subprogram_Body (Loc,
3182 Specification => Espec,
3183 Declarations => Op_Decls,
3184 Handled_Statement_Sequence =>
3185 Make_Handled_Sequence_Of_Statements (Loc,
3186 Statements => Op_Stats,
3187 End_Label => End_Lab));
3188
3189 else
3190 Ohandle := Make_Others_Choice (Loc);
3191 Set_All_Others (Ohandle);
3192
3193 case Corresponding_Runtime_Package (Pid) is
3194 when System_Tasking_Protected_Objects_Entries =>
3195 Complete :=
3196 New_Reference_To
3197 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
3198
3199 when System_Tasking_Protected_Objects_Single_Entry =>
3200 Complete :=
3201 New_Reference_To
3202 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
3203
3204 when others =>
3205 raise Program_Error;
3206 end case;
3207
3208 -- Establish link between subprogram body entity and source entry
3209
3210 Set_Corresponding_Protected_Entry (Edef, Ent);
3211
3212 -- Create body of entry procedure. The renaming declarations are
3213 -- placed ahead of the block that contains the actual entry body.
3214
3215 return
3216 Make_Subprogram_Body (Loc,
3217 Specification => Espec,
3218 Declarations => Op_Decls,
3219 Handled_Statement_Sequence =>
3220 Make_Handled_Sequence_Of_Statements (Loc,
3221 Statements => Op_Stats,
3222 End_Label => End_Lab,
3223 Exception_Handlers => New_List (
3224 Make_Implicit_Exception_Handler (Han_Loc,
3225 Exception_Choices => New_List (Ohandle),
3226
3227 Statements => New_List (
3228 Make_Procedure_Call_Statement (Han_Loc,
3229 Name => Complete,
3230 Parameter_Associations => New_List (
3231 Make_Attribute_Reference (Han_Loc,
3232 Prefix =>
3233 Make_Selected_Component (Han_Loc,
3234 Prefix =>
3235 Make_Identifier (Han_Loc, Name_uObject),
3236 Selector_Name =>
3237 Make_Identifier (Han_Loc, Name_uObject)),
3238 Attribute_Name => Name_Unchecked_Access),
3239
3240 Make_Function_Call (Han_Loc,
3241 Name => New_Reference_To (
3242 RTE (RE_Get_GNAT_Exception), Loc)))))))));
3243 end if;
3244 end Build_Protected_Entry;
3245
3246 -----------------------------------------
3247 -- Build_Protected_Entry_Specification --
3248 -----------------------------------------
3249
3250 function Build_Protected_Entry_Specification
3251 (Loc : Source_Ptr;
3252 Def_Id : Entity_Id;
3253 Ent_Id : Entity_Id) return Node_Id
3254 is
3255 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3256
3257 begin
3258 Set_Debug_Info_Needed (Def_Id);
3259
3260 if Present (Ent_Id) then
3261 Append_Elmt (P, Accept_Address (Ent_Id));
3262 end if;
3263
3264 return
3265 Make_Procedure_Specification (Loc,
3266 Defining_Unit_Name => Def_Id,
3267 Parameter_Specifications => New_List (
3268 Make_Parameter_Specification (Loc,
3269 Defining_Identifier =>
3270 Make_Defining_Identifier (Loc, Name_uO),
3271 Parameter_Type =>
3272 New_Reference_To (RTE (RE_Address), Loc)),
3273
3274 Make_Parameter_Specification (Loc,
3275 Defining_Identifier => P,
3276 Parameter_Type =>
3277 New_Reference_To (RTE (RE_Address), Loc)),
3278
3279 Make_Parameter_Specification (Loc,
3280 Defining_Identifier =>
3281 Make_Defining_Identifier (Loc, Name_uE),
3282 Parameter_Type =>
3283 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
3284 end Build_Protected_Entry_Specification;
3285
3286 --------------------------
3287 -- Build_Protected_Spec --
3288 --------------------------
3289
3290 function Build_Protected_Spec
3291 (N : Node_Id;
3292 Obj_Type : Entity_Id;
3293 Ident : Entity_Id;
3294 Unprotected : Boolean := False) return List_Id
3295 is
3296 Loc : constant Source_Ptr := Sloc (N);
3297 Decl : Node_Id;
3298 Formal : Entity_Id;
3299 New_Plist : List_Id;
3300 New_Param : Node_Id;
3301
3302 begin
3303 New_Plist := New_List;
3304
3305 Formal := First_Formal (Ident);
3306 while Present (Formal) loop
3307 New_Param :=
3308 Make_Parameter_Specification (Loc,
3309 Defining_Identifier =>
3310 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
3311 In_Present => In_Present (Parent (Formal)),
3312 Out_Present => Out_Present (Parent (Formal)),
3313 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
3314
3315 if Unprotected then
3316 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3317 end if;
3318
3319 Append (New_Param, New_Plist);
3320 Next_Formal (Formal);
3321 end loop;
3322
3323 -- If the subprogram is a procedure and the context is not an access
3324 -- to protected subprogram, the parameter is in-out. Otherwise it is
3325 -- an in parameter.
3326
3327 Decl :=
3328 Make_Parameter_Specification (Loc,
3329 Defining_Identifier =>
3330 Make_Defining_Identifier (Loc, Name_uObject),
3331 In_Present => True,
3332 Out_Present =>
3333 (Etype (Ident) = Standard_Void_Type
3334 and then not Is_RTE (Obj_Type, RE_Address)),
3335 Parameter_Type =>
3336 New_Reference_To (Obj_Type, Loc));
3337 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3338 Prepend_To (New_Plist, Decl);
3339
3340 return New_Plist;
3341 end Build_Protected_Spec;
3342
3343 ---------------------------------------
3344 -- Build_Protected_Sub_Specification --
3345 ---------------------------------------
3346
3347 function Build_Protected_Sub_Specification
3348 (N : Node_Id;
3349 Prot_Typ : Entity_Id;
3350 Mode : Subprogram_Protection_Mode) return Node_Id
3351 is
3352 Loc : constant Source_Ptr := Sloc (N);
3353 Decl : Node_Id;
3354 Def_Id : Entity_Id;
3355 New_Id : Entity_Id;
3356 New_Plist : List_Id;
3357 New_Spec : Node_Id;
3358
3359 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3360 (Dispatching_Mode => ' ',
3361 Protected_Mode => 'P',
3362 Unprotected_Mode => 'N');
3363
3364 begin
3365 if Ekind (Defining_Unit_Name (Specification (N))) =
3366 E_Subprogram_Body
3367 then
3368 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3369 else
3370 Decl := N;
3371 end if;
3372
3373 Def_Id := Defining_Unit_Name (Specification (Decl));
3374
3375 New_Plist :=
3376 Build_Protected_Spec
3377 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3378 Mode = Unprotected_Mode);
3379 New_Id :=
3380 Make_Defining_Identifier (Loc,
3381 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3382
3383 -- The unprotected operation carries the user code, and debugging
3384 -- information must be generated for it, even though this spec does
3385 -- not come from source. It is also convenient to allow gdb to step
3386 -- into the protected operation, even though it only contains lock/
3387 -- unlock calls.
3388
3389 Set_Debug_Info_Needed (New_Id);
3390
3391 -- If a pragma Eliminate applies to the source entity, the internal
3392 -- subprograms will be eliminated as well.
3393
3394 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3395
3396 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3397 New_Spec :=
3398 Make_Procedure_Specification (Loc,
3399 Defining_Unit_Name => New_Id,
3400 Parameter_Specifications => New_Plist);
3401
3402 -- Create a new specification for the anonymous subprogram type
3403
3404 else
3405 New_Spec :=
3406 Make_Function_Specification (Loc,
3407 Defining_Unit_Name => New_Id,
3408 Parameter_Specifications => New_Plist,
3409 Result_Definition =>
3410 Copy_Result_Type (Result_Definition (Specification (Decl))));
3411
3412 Set_Return_Present (Defining_Unit_Name (New_Spec));
3413 end if;
3414
3415 return New_Spec;
3416 end Build_Protected_Sub_Specification;
3417
3418 -------------------------------------
3419 -- Build_Protected_Subprogram_Body --
3420 -------------------------------------
3421
3422 function Build_Protected_Subprogram_Body
3423 (N : Node_Id;
3424 Pid : Node_Id;
3425 N_Op_Spec : Node_Id) return Node_Id
3426 is
3427 Loc : constant Source_Ptr := Sloc (N);
3428 Op_Spec : Node_Id;
3429 P_Op_Spec : Node_Id;
3430 Uactuals : List_Id;
3431 Pformal : Node_Id;
3432 Unprot_Call : Node_Id;
3433 Sub_Body : Node_Id;
3434 Lock_Name : Node_Id;
3435 Lock_Stmt : Node_Id;
3436 Service_Name : Node_Id;
3437 R : Node_Id;
3438 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3439 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3440 Stmts : List_Id;
3441 Object_Parm : Node_Id;
3442 Exc_Safe : Boolean;
3443 Lock_Kind : RE_Id;
3444
3445 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3446 -- Tell whether a given subprogram cannot raise an exception
3447
3448 -----------------------
3449 -- Is_Exception_Safe --
3450 -----------------------
3451
3452 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3453
3454 function Has_Side_Effect (N : Node_Id) return Boolean;
3455 -- Return True whenever encountering a subprogram call or raise
3456 -- statement of any kind in the sequence of statements
3457
3458 ---------------------
3459 -- Has_Side_Effect --
3460 ---------------------
3461
3462 -- What is this doing buried two levels down in exp_ch9. It seems
3463 -- like a generally useful function, and indeed there may be code
3464 -- duplication going on here ???
3465
3466 function Has_Side_Effect (N : Node_Id) return Boolean is
3467 Stmt : Node_Id;
3468 Expr : Node_Id;
3469
3470 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3471 -- Indicate whether N is a subprogram call or a raise statement
3472
3473 ----------------------
3474 -- Is_Call_Or_Raise --
3475 ----------------------
3476
3477 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3478 begin
3479 return Nkind_In (N, N_Procedure_Call_Statement,
3480 N_Function_Call,
3481 N_Raise_Statement,
3482 N_Raise_Constraint_Error,
3483 N_Raise_Program_Error,
3484 N_Raise_Storage_Error);
3485 end Is_Call_Or_Raise;
3486
3487 -- Start of processing for Has_Side_Effect
3488
3489 begin
3490 Stmt := N;
3491 while Present (Stmt) loop
3492 if Is_Call_Or_Raise (Stmt) then
3493 return True;
3494 end if;
3495
3496 -- An object declaration can also contain a function call
3497 -- or a raise statement
3498
3499 if Nkind (Stmt) = N_Object_Declaration then
3500 Expr := Expression (Stmt);
3501
3502 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3503 return True;
3504 end if;
3505 end if;
3506
3507 Next (Stmt);
3508 end loop;
3509
3510 return False;
3511 end Has_Side_Effect;
3512
3513 -- Start of processing for Is_Exception_Safe
3514
3515 begin
3516 -- If the checks handled by the back end are not disabled, we cannot
3517 -- ensure that no exception will be raised.
3518
3519 if not Access_Checks_Suppressed (Empty)
3520 or else not Discriminant_Checks_Suppressed (Empty)
3521 or else not Range_Checks_Suppressed (Empty)
3522 or else not Index_Checks_Suppressed (Empty)
3523 or else Opt.Stack_Checking_Enabled
3524 then
3525 return False;
3526 end if;
3527
3528 if Has_Side_Effect (First (Declarations (Subprogram)))
3529 or else
3530 Has_Side_Effect (
3531 First (Statements (Handled_Statement_Sequence (Subprogram))))
3532 then
3533 return False;
3534 else
3535 return True;
3536 end if;
3537 end Is_Exception_Safe;
3538
3539 -- Start of processing for Build_Protected_Subprogram_Body
3540
3541 begin
3542 Op_Spec := Specification (N);
3543 Exc_Safe := Is_Exception_Safe (N);
3544
3545 P_Op_Spec :=
3546 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3547
3548 -- Build a list of the formal parameters of the protected version of
3549 -- the subprogram to use as the actual parameters of the unprotected
3550 -- version.
3551
3552 Uactuals := New_List;
3553 Pformal := First (Parameter_Specifications (P_Op_Spec));
3554 while Present (Pformal) loop
3555 Append_To (Uactuals,
3556 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
3557 Next (Pformal);
3558 end loop;
3559
3560 -- Make a call to the unprotected version of the subprogram built above
3561 -- for use by the protected version built below.
3562
3563 if Nkind (Op_Spec) = N_Function_Specification then
3564 if Exc_Safe then
3565 R := Make_Temporary (Loc, 'R');
3566 Unprot_Call :=
3567 Make_Object_Declaration (Loc,
3568 Defining_Identifier => R,
3569 Constant_Present => True,
3570 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3571 Expression =>
3572 Make_Function_Call (Loc,
3573 Name => Make_Identifier (Loc,
3574 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3575 Parameter_Associations => Uactuals));
3576
3577 Return_Stmt :=
3578 Make_Simple_Return_Statement (Loc,
3579 Expression => New_Reference_To (R, Loc));
3580
3581 else
3582 Unprot_Call := Make_Simple_Return_Statement (Loc,
3583 Expression => Make_Function_Call (Loc,
3584 Name =>
3585 Make_Identifier (Loc,
3586 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3587 Parameter_Associations => Uactuals));
3588 end if;
3589
3590 Lock_Kind := RE_Lock_Read_Only;
3591
3592 else
3593 Unprot_Call :=
3594 Make_Procedure_Call_Statement (Loc,
3595 Name =>
3596 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3597 Parameter_Associations => Uactuals);
3598
3599 Lock_Kind := RE_Lock;
3600 end if;
3601
3602 -- Wrap call in block that will be covered by an at_end handler
3603
3604 if not Exc_Safe then
3605 Unprot_Call := Make_Block_Statement (Loc,
3606 Handled_Statement_Sequence =>
3607 Make_Handled_Sequence_Of_Statements (Loc,
3608 Statements => New_List (Unprot_Call)));
3609 end if;
3610
3611 -- Make the protected subprogram body. This locks the protected
3612 -- object and calls the unprotected version of the subprogram.
3613
3614 case Corresponding_Runtime_Package (Pid) is
3615 when System_Tasking_Protected_Objects_Entries =>
3616 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3617 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3618
3619 when System_Tasking_Protected_Objects_Single_Entry =>
3620 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3621 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3622
3623 when System_Tasking_Protected_Objects =>
3624 Lock_Name := New_Reference_To (RTE (Lock_Kind), Loc);
3625 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3626
3627 when others =>
3628 raise Program_Error;
3629 end case;
3630
3631 Object_Parm :=
3632 Make_Attribute_Reference (Loc,
3633 Prefix =>
3634 Make_Selected_Component (Loc,
3635 Prefix => Make_Identifier (Loc, Name_uObject),
3636 Selector_Name => Make_Identifier (Loc, Name_uObject)),
3637 Attribute_Name => Name_Unchecked_Access);
3638
3639 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3640 Name => Lock_Name,
3641 Parameter_Associations => New_List (Object_Parm));
3642
3643 if Abort_Allowed then
3644 Stmts := New_List (
3645 Make_Procedure_Call_Statement (Loc,
3646 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3647 Parameter_Associations => Empty_List),
3648 Lock_Stmt);
3649
3650 else
3651 Stmts := New_List (Lock_Stmt);
3652 end if;
3653
3654 if not Exc_Safe then
3655 Append (Unprot_Call, Stmts);
3656 else
3657 if Nkind (Op_Spec) = N_Function_Specification then
3658 Pre_Stmts := Stmts;
3659 Stmts := Empty_List;
3660 else
3661 Append (Unprot_Call, Stmts);
3662 end if;
3663
3664 Append (
3665 Make_Procedure_Call_Statement (Loc,
3666 Name => Service_Name,
3667 Parameter_Associations =>
3668 New_List (New_Copy_Tree (Object_Parm))),
3669 Stmts);
3670
3671 if Abort_Allowed then
3672 Append (
3673 Make_Procedure_Call_Statement (Loc,
3674 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3675 Parameter_Associations => Empty_List),
3676 Stmts);
3677 end if;
3678
3679 if Nkind (Op_Spec) = N_Function_Specification then
3680 Append (Return_Stmt, Stmts);
3681 Append (Make_Block_Statement (Loc,
3682 Declarations => New_List (Unprot_Call),
3683 Handled_Statement_Sequence =>
3684 Make_Handled_Sequence_Of_Statements (Loc,
3685 Statements => Stmts)), Pre_Stmts);
3686 Stmts := Pre_Stmts;
3687 end if;
3688 end if;
3689
3690 Sub_Body :=
3691 Make_Subprogram_Body (Loc,
3692 Declarations => Empty_List,
3693 Specification => P_Op_Spec,
3694 Handled_Statement_Sequence =>
3695 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3696
3697 if not Exc_Safe then
3698 Set_Is_Protected_Subprogram_Body (Sub_Body);
3699 end if;
3700
3701 return Sub_Body;
3702 end Build_Protected_Subprogram_Body;
3703
3704 -------------------------------------
3705 -- Build_Protected_Subprogram_Call --
3706 -------------------------------------
3707
3708 procedure Build_Protected_Subprogram_Call
3709 (N : Node_Id;
3710 Name : Node_Id;
3711 Rec : Node_Id;
3712 External : Boolean := True)
3713 is
3714 Loc : constant Source_Ptr := Sloc (N);
3715 Sub : constant Entity_Id := Entity (Name);
3716 New_Sub : Node_Id;
3717 Params : List_Id;
3718
3719 begin
3720 if External then
3721 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3722 else
3723 New_Sub :=
3724 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3725 end if;
3726
3727 if Present (Parameter_Associations (N)) then
3728 Params := New_Copy_List_Tree (Parameter_Associations (N));
3729 else
3730 Params := New_List;
3731 end if;
3732
3733 -- If the type is an untagged derived type, convert to the root type,
3734 -- which is the one on which the operations are defined.
3735
3736 if Nkind (Rec) = N_Unchecked_Type_Conversion
3737 and then not Is_Tagged_Type (Etype (Rec))
3738 and then Is_Derived_Type (Etype (Rec))
3739 then
3740 Set_Etype (Rec, Root_Type (Etype (Rec)));
3741 Set_Subtype_Mark (Rec,
3742 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3743 end if;
3744
3745 Prepend (Rec, Params);
3746
3747 if Ekind (Sub) = E_Procedure then
3748 Rewrite (N,
3749 Make_Procedure_Call_Statement (Loc,
3750 Name => New_Sub,
3751 Parameter_Associations => Params));
3752
3753 else
3754 pragma Assert (Ekind (Sub) = E_Function);
3755 Rewrite (N,
3756 Make_Function_Call (Loc,
3757 Name => New_Sub,
3758 Parameter_Associations => Params));
3759 end if;
3760
3761 if External
3762 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3763 and then Is_Entity_Name (Expression (Rec))
3764 and then Is_Shared_Passive (Entity (Expression (Rec)))
3765 then
3766 Add_Shared_Var_Lock_Procs (N);
3767 end if;
3768 end Build_Protected_Subprogram_Call;
3769
3770 -------------------------
3771 -- Build_Selected_Name --
3772 -------------------------
3773
3774 function Build_Selected_Name
3775 (Prefix : Entity_Id;
3776 Selector : Entity_Id;
3777 Append_Char : Character := ' ') return Name_Id
3778 is
3779 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3780 Select_Len : Natural;
3781
3782 begin
3783 Get_Name_String (Chars (Selector));
3784 Select_Len := Name_Len;
3785 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3786 Get_Name_String (Chars (Prefix));
3787
3788 -- If scope is anonymous type, discard suffix to recover name of
3789 -- single protected object. Otherwise use protected type name.
3790
3791 if Name_Buffer (Name_Len) = 'T' then
3792 Name_Len := Name_Len - 1;
3793 end if;
3794
3795 Add_Str_To_Name_Buffer ("__");
3796 for J in 1 .. Select_Len loop
3797 Add_Char_To_Name_Buffer (Select_Buffer (J));
3798 end loop;
3799
3800 -- Now add the Append_Char if specified. The encoding to follow
3801 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3802 -- then the entity is associated to a protected type subprogram.
3803 -- Otherwise, it is a protected type entry. For each case, the
3804 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3805
3806 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3807
3808 if Append_Char /= ' ' then
3809 if Append_Char = 'P' or Append_Char = 'N' then
3810 Add_Char_To_Name_Buffer (Append_Char);
3811 return Name_Find;
3812 else
3813 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3814 return New_External_Name (Name_Find, ' ', -1);
3815 end if;
3816 else
3817 return Name_Find;
3818 end if;
3819 end Build_Selected_Name;
3820
3821 -----------------------------
3822 -- Build_Simple_Entry_Call --
3823 -----------------------------
3824
3825 -- A task entry call is converted to a call to Call_Simple
3826
3827 -- declare
3828 -- P : parms := (parm, parm, parm);
3829 -- begin
3830 -- Call_Simple (acceptor-task, entry-index, P'Address);
3831 -- parm := P.param;
3832 -- parm := P.param;
3833 -- ...
3834 -- end;
3835
3836 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3837 -- the parameters, and the constructed aggregate value contains either the
3838 -- parameters or, in the case of non-elementary types, references to these
3839 -- parameters. Then the address of this aggregate is passed to the runtime
3840 -- routine, along with the task id value and the task entry index value.
3841 -- Pnn is only required if parameters are present.
3842
3843 -- The assignments after the call are present only in the case of in-out
3844 -- or out parameters for elementary types, and are used to assign back the
3845 -- resulting values of such parameters.
3846
3847 -- Note: the reason that we insert a block here is that in the context
3848 -- of selects, conditional entry calls etc. the entry call statement
3849 -- appears on its own, not as an element of a list.
3850
3851 -- A protected entry call is converted to a Protected_Entry_Call:
3852
3853 -- declare
3854 -- P : E1_Params := (param, param, param);
3855 -- Pnn : Boolean;
3856 -- Bnn : Communications_Block;
3857
3858 -- declare
3859 -- P : E1_Params := (param, param, param);
3860 -- Bnn : Communications_Block;
3861
3862 -- begin
3863 -- Protected_Entry_Call (
3864 -- Object => po._object'Access,
3865 -- E => <entry index>;
3866 -- Uninterpreted_Data => P'Address;
3867 -- Mode => Simple_Call;
3868 -- Block => Bnn);
3869 -- parm := P.param;
3870 -- parm := P.param;
3871 -- ...
3872 -- end;
3873
3874 procedure Build_Simple_Entry_Call
3875 (N : Node_Id;
3876 Concval : Node_Id;
3877 Ename : Node_Id;
3878 Index : Node_Id)
3879 is
3880 begin
3881 Expand_Call (N);
3882
3883 -- If call has been inlined, nothing left to do
3884
3885 if Nkind (N) = N_Block_Statement then
3886 return;
3887 end if;
3888
3889 -- Convert entry call to Call_Simple call
3890
3891 declare
3892 Loc : constant Source_Ptr := Sloc (N);
3893 Parms : constant List_Id := Parameter_Associations (N);
3894 Stats : constant List_Id := New_List;
3895 Actual : Node_Id;
3896 Call : Node_Id;
3897 Comm_Name : Entity_Id;
3898 Conctyp : Node_Id;
3899 Decls : List_Id;
3900 Ent : Entity_Id;
3901 Ent_Acc : Entity_Id;
3902 Formal : Node_Id;
3903 Iface_Tag : Entity_Id;
3904 Iface_Typ : Entity_Id;
3905 N_Node : Node_Id;
3906 N_Var : Node_Id;
3907 P : Entity_Id;
3908 Parm1 : Node_Id;
3909 Parm2 : Node_Id;
3910 Parm3 : Node_Id;
3911 Pdecl : Node_Id;
3912 Plist : List_Id;
3913 X : Entity_Id;
3914 Xdecl : Node_Id;
3915
3916 begin
3917 -- Simple entry and entry family cases merge here
3918
3919 Ent := Entity (Ename);
3920 Ent_Acc := Entry_Parameters_Type (Ent);
3921 Conctyp := Etype (Concval);
3922
3923 -- If prefix is an access type, dereference to obtain the task type
3924
3925 if Is_Access_Type (Conctyp) then
3926 Conctyp := Designated_Type (Conctyp);
3927 end if;
3928
3929 -- Special case for protected subprogram calls
3930
3931 if Is_Protected_Type (Conctyp)
3932 and then Is_Subprogram (Entity (Ename))
3933 then
3934 if not Is_Eliminated (Entity (Ename)) then
3935 Build_Protected_Subprogram_Call
3936 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3937 Analyze (N);
3938 end if;
3939
3940 return;
3941 end if;
3942
3943 -- First parameter is the Task_Id value from the task value or the
3944 -- Object from the protected object value, obtained by selecting
3945 -- the _Task_Id or _Object from the result of doing an unchecked
3946 -- conversion to convert the value to the corresponding record type.
3947
3948 if Nkind (Concval) = N_Function_Call
3949 and then Is_Task_Type (Conctyp)
3950 and then Ada_Version >= Ada_2005
3951 then
3952 declare
3953 ExpR : constant Node_Id := Relocate_Node (Concval);
3954 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3955 Decl : Node_Id;
3956
3957 begin
3958 Decl :=
3959 Make_Object_Declaration (Loc,
3960 Defining_Identifier => Obj,
3961 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3962 Expression => ExpR);
3963 Set_Etype (Obj, Conctyp);
3964 Decls := New_List (Decl);
3965 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3966 end;
3967
3968 else
3969 Decls := New_List;
3970 end if;
3971
3972 Parm1 := Concurrent_Ref (Concval);
3973
3974 -- Second parameter is the entry index, computed by the routine
3975 -- provided for this purpose. The value of this expression is
3976 -- assigned to an intermediate variable to assure that any entry
3977 -- family index expressions are evaluated before the entry
3978 -- parameters.
3979
3980 if Abort_Allowed
3981 or else Restriction_Active (No_Entry_Queue) = False
3982 or else not Is_Protected_Type (Conctyp)
3983 or else Number_Entries (Conctyp) > 1
3984 or else (Has_Attach_Handler (Conctyp)
3985 and then not Restricted_Profile)
3986 then
3987 X := Make_Defining_Identifier (Loc, Name_uX);
3988
3989 Xdecl :=
3990 Make_Object_Declaration (Loc,
3991 Defining_Identifier => X,
3992 Object_Definition =>
3993 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3994 Expression => Actual_Index_Expression (
3995 Loc, Entity (Ename), Index, Concval));
3996
3997 Append_To (Decls, Xdecl);
3998 Parm2 := New_Reference_To (X, Loc);
3999
4000 else
4001 Xdecl := Empty;
4002 Parm2 := Empty;
4003 end if;
4004
4005 -- The third parameter is the packaged parameters. If there are
4006 -- none, then it is just the null address, since nothing is passed.
4007
4008 if No (Parms) then
4009 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
4010 P := Empty;
4011
4012 -- Case of parameters present, where third argument is the address
4013 -- of a packaged record containing the required parameter values.
4014
4015 else
4016 -- First build a list of parameter values, which are references to
4017 -- objects of the parameter types.
4018
4019 Plist := New_List;
4020
4021 Actual := First_Actual (N);
4022 Formal := First_Formal (Ent);
4023
4024 while Present (Actual) loop
4025
4026 -- If it is a by_copy_type, copy it to a new variable. The
4027 -- packaged record has a field that points to this variable.
4028
4029 if Is_By_Copy_Type (Etype (Actual)) then
4030 N_Node :=
4031 Make_Object_Declaration (Loc,
4032 Defining_Identifier => Make_Temporary (Loc, 'J'),
4033 Aliased_Present => True,
4034 Object_Definition =>
4035 New_Reference_To (Etype (Formal), Loc));
4036
4037 -- Mark the object as not needing initialization since the
4038 -- initialization is performed separately, avoiding errors
4039 -- on cases such as formals of null-excluding access types.
4040
4041 Set_No_Initialization (N_Node);
4042
4043 -- We must make an assignment statement separate for the
4044 -- case of limited type. We cannot assign it unless the
4045 -- Assignment_OK flag is set first. An out formal of an
4046 -- access type must also be initialized from the actual,
4047 -- as stated in RM 6.4.1 (13).
4048
4049 if Ekind (Formal) /= E_Out_Parameter
4050 or else Is_Access_Type (Etype (Formal))
4051 then
4052 N_Var :=
4053 New_Reference_To (Defining_Identifier (N_Node), Loc);
4054 Set_Assignment_OK (N_Var);
4055 Append_To (Stats,
4056 Make_Assignment_Statement (Loc,
4057 Name => N_Var,
4058 Expression => Relocate_Node (Actual)));
4059 end if;
4060
4061 Append (N_Node, Decls);
4062
4063 Append_To (Plist,
4064 Make_Attribute_Reference (Loc,
4065 Attribute_Name => Name_Unchecked_Access,
4066 Prefix =>
4067 New_Reference_To (Defining_Identifier (N_Node), Loc)));
4068
4069 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4070
4071 elsif Is_VM_By_Copy_Actual (Actual) then
4072 N_Node :=
4073 Make_Object_Declaration (Loc,
4074 Defining_Identifier => Make_Temporary (Loc, 'J'),
4075 Aliased_Present => True,
4076 Object_Definition =>
4077 New_Reference_To (Etype (Formal), Loc),
4078 Expression => New_Copy_Tree (Actual));
4079 Set_Assignment_OK (N_Node);
4080
4081 Append (N_Node, Decls);
4082
4083 Append_To (Plist,
4084 Make_Attribute_Reference (Loc,
4085 Attribute_Name => Name_Unchecked_Access,
4086 Prefix =>
4087 New_Reference_To (Defining_Identifier (N_Node), Loc)));
4088
4089 else
4090 -- Interface class-wide formal
4091
4092 if Ada_Version >= Ada_2005
4093 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
4094 and then Is_Interface (Etype (Formal))
4095 then
4096 Iface_Typ := Etype (Etype (Formal));
4097
4098 -- Generate:
4099 -- formal_iface_type! (actual.iface_tag)'reference
4100
4101 Iface_Tag :=
4102 Find_Interface_Tag (Etype (Actual), Iface_Typ);
4103 pragma Assert (Present (Iface_Tag));
4104
4105 Append_To (Plist,
4106 Make_Reference (Loc,
4107 Unchecked_Convert_To (Iface_Typ,
4108 Make_Selected_Component (Loc,
4109 Prefix =>
4110 Relocate_Node (Actual),
4111 Selector_Name =>
4112 New_Reference_To (Iface_Tag, Loc)))));
4113 else
4114 -- Generate:
4115 -- actual'reference
4116
4117 Append_To (Plist,
4118 Make_Reference (Loc, Relocate_Node (Actual)));
4119 end if;
4120 end if;
4121
4122 Next_Actual (Actual);
4123 Next_Formal_With_Extras (Formal);
4124 end loop;
4125
4126 -- Now build the declaration of parameters initialized with the
4127 -- aggregate containing this constructed parameter list.
4128
4129 P := Make_Defining_Identifier (Loc, Name_uP);
4130
4131 Pdecl :=
4132 Make_Object_Declaration (Loc,
4133 Defining_Identifier => P,
4134 Object_Definition =>
4135 New_Reference_To (Designated_Type (Ent_Acc), Loc),
4136 Expression =>
4137 Make_Aggregate (Loc, Expressions => Plist));
4138
4139 Parm3 :=
4140 Make_Attribute_Reference (Loc,
4141 Prefix => New_Reference_To (P, Loc),
4142 Attribute_Name => Name_Address);
4143
4144 Append (Pdecl, Decls);
4145 end if;
4146
4147 -- Now we can create the call, case of protected type
4148
4149 if Is_Protected_Type (Conctyp) then
4150 case Corresponding_Runtime_Package (Conctyp) is
4151 when System_Tasking_Protected_Objects_Entries =>
4152
4153 -- Change the type of the index declaration
4154
4155 Set_Object_Definition (Xdecl,
4156 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
4157
4158 -- Some additional declarations for protected entry calls
4159
4160 if No (Decls) then
4161 Decls := New_List;
4162 end if;
4163
4164 -- Bnn : Communications_Block;
4165
4166 Comm_Name := Make_Temporary (Loc, 'B');
4167
4168 Append_To (Decls,
4169 Make_Object_Declaration (Loc,
4170 Defining_Identifier => Comm_Name,
4171 Object_Definition =>
4172 New_Reference_To (RTE (RE_Communication_Block), Loc)));
4173
4174 -- Some additional statements for protected entry calls
4175
4176 -- Protected_Entry_Call (
4177 -- Object => po._object'Access,
4178 -- E => <entry index>;
4179 -- Uninterpreted_Data => P'Address;
4180 -- Mode => Simple_Call;
4181 -- Block => Bnn);
4182
4183 Call :=
4184 Make_Procedure_Call_Statement (Loc,
4185 Name =>
4186 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
4187
4188 Parameter_Associations => New_List (
4189 Make_Attribute_Reference (Loc,
4190 Attribute_Name => Name_Unchecked_Access,
4191 Prefix => Parm1),
4192 Parm2,
4193 Parm3,
4194 New_Reference_To (RTE (RE_Simple_Call), Loc),
4195 New_Occurrence_Of (Comm_Name, Loc)));
4196
4197 when System_Tasking_Protected_Objects_Single_Entry =>
4198 -- Protected_Single_Entry_Call (
4199 -- Object => po._object'Access,
4200 -- Uninterpreted_Data => P'Address;
4201 -- Mode => Simple_Call);
4202
4203 Call :=
4204 Make_Procedure_Call_Statement (Loc,
4205 Name => New_Reference_To (
4206 RTE (RE_Protected_Single_Entry_Call), Loc),
4207
4208 Parameter_Associations => New_List (
4209 Make_Attribute_Reference (Loc,
4210 Attribute_Name => Name_Unchecked_Access,
4211 Prefix => Parm1),
4212 Parm3,
4213 New_Reference_To (RTE (RE_Simple_Call), Loc)));
4214
4215 when others =>
4216 raise Program_Error;
4217 end case;
4218
4219 -- Case of task type
4220
4221 else
4222 Call :=
4223 Make_Procedure_Call_Statement (Loc,
4224 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
4225 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
4226
4227 end if;
4228
4229 Append_To (Stats, Call);
4230
4231 -- If there are out or in/out parameters by copy add assignment
4232 -- statements for the result values.
4233
4234 if Present (Parms) then
4235 Actual := First_Actual (N);
4236 Formal := First_Formal (Ent);
4237
4238 Set_Assignment_OK (Actual);
4239 while Present (Actual) loop
4240 if (Is_By_Copy_Type (Etype (Actual))
4241 or else Is_VM_By_Copy_Actual (Actual))
4242 and then Ekind (Formal) /= E_In_Parameter
4243 then
4244 N_Node :=
4245 Make_Assignment_Statement (Loc,
4246 Name => New_Copy (Actual),
4247 Expression =>
4248 Make_Explicit_Dereference (Loc,
4249 Make_Selected_Component (Loc,
4250 Prefix => New_Reference_To (P, Loc),
4251 Selector_Name =>
4252 Make_Identifier (Loc, Chars (Formal)))));
4253
4254 -- In all cases (including limited private types) we want
4255 -- the assignment to be valid.
4256
4257 Set_Assignment_OK (Name (N_Node));
4258
4259 -- If the call is the triggering alternative in an
4260 -- asynchronous select, or the entry_call alternative of a
4261 -- conditional entry call, the assignments for in-out
4262 -- parameters are incorporated into the statement list that
4263 -- follows, so that there are executed only if the entry
4264 -- call succeeds.
4265
4266 if (Nkind (Parent (N)) = N_Triggering_Alternative
4267 and then N = Triggering_Statement (Parent (N)))
4268 or else
4269 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4270 and then N = Entry_Call_Statement (Parent (N)))
4271 then
4272 if No (Statements (Parent (N))) then
4273 Set_Statements (Parent (N), New_List);
4274 end if;
4275
4276 Prepend (N_Node, Statements (Parent (N)));
4277
4278 else
4279 Insert_After (Call, N_Node);
4280 end if;
4281 end if;
4282
4283 Next_Actual (Actual);
4284 Next_Formal_With_Extras (Formal);
4285 end loop;
4286 end if;
4287
4288 -- Finally, create block and analyze it
4289
4290 Rewrite (N,
4291 Make_Block_Statement (Loc,
4292 Declarations => Decls,
4293 Handled_Statement_Sequence =>
4294 Make_Handled_Sequence_Of_Statements (Loc,
4295 Statements => Stats)));
4296
4297 Analyze (N);
4298 end;
4299 end Build_Simple_Entry_Call;
4300
4301 --------------------------------
4302 -- Build_Task_Activation_Call --
4303 --------------------------------
4304
4305 procedure Build_Task_Activation_Call (N : Node_Id) is
4306 Loc : constant Source_Ptr := Sloc (N);
4307 Chain : Entity_Id;
4308 Call : Node_Id;
4309 Name : Node_Id;
4310 P : Node_Id;
4311
4312 begin
4313 -- Get the activation chain entity. Except in the case of a package
4314 -- body, this is in the node that was passed. For a package body, we
4315 -- have to find the corresponding package declaration node.
4316
4317 if Nkind (N) = N_Package_Body then
4318 P := Corresponding_Spec (N);
4319 loop
4320 P := Parent (P);
4321 exit when Nkind (P) = N_Package_Declaration;
4322 end loop;
4323
4324 Chain := Activation_Chain_Entity (P);
4325
4326 else
4327 Chain := Activation_Chain_Entity (N);
4328 end if;
4329
4330 if Present (Chain) then
4331 if Restricted_Profile then
4332 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
4333 else
4334 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4335 end if;
4336
4337 Call :=
4338 Make_Procedure_Call_Statement (Loc,
4339 Name => Name,
4340 Parameter_Associations =>
4341 New_List (Make_Attribute_Reference (Loc,
4342 Prefix => New_Occurrence_Of (Chain, Loc),
4343 Attribute_Name => Name_Unchecked_Access)));
4344
4345 if Nkind (N) = N_Package_Declaration then
4346 if Present (Corresponding_Body (N)) then
4347 null;
4348
4349 elsif Present (Private_Declarations (Specification (N))) then
4350 Append (Call, Private_Declarations (Specification (N)));
4351
4352 else
4353 Append (Call, Visible_Declarations (Specification (N)));
4354 end if;
4355
4356 else
4357 if Present (Handled_Statement_Sequence (N)) then
4358
4359 -- The call goes at the start of the statement sequence
4360 -- after the start of exception range label if one is present.
4361
4362 declare
4363 Stm : Node_Id;
4364
4365 begin
4366 Stm := First (Statements (Handled_Statement_Sequence (N)));
4367
4368 -- A special case, skip exception range label if one is
4369 -- present (from front end zcx processing).
4370
4371 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4372 Next (Stm);
4373 end if;
4374
4375 -- Another special case, if the first statement is a block
4376 -- from optimization of a local raise to a goto, then the
4377 -- call goes inside this block.
4378
4379 if Nkind (Stm) = N_Block_Statement
4380 and then Exception_Junk (Stm)
4381 then
4382 Stm :=
4383 First (Statements (Handled_Statement_Sequence (Stm)));
4384 end if;
4385
4386 -- Insertion point is after any exception label pushes,
4387 -- since we want it covered by any local handlers.
4388
4389 while Nkind (Stm) in N_Push_xxx_Label loop
4390 Next (Stm);
4391 end loop;
4392
4393 -- Now we have the proper insertion point
4394
4395 Insert_Before (Stm, Call);
4396 end;
4397
4398 else
4399 Set_Handled_Statement_Sequence (N,
4400 Make_Handled_Sequence_Of_Statements (Loc,
4401 Statements => New_List (Call)));
4402 end if;
4403 end if;
4404
4405 Analyze (Call);
4406 Check_Task_Activation (N);
4407 end if;
4408 end Build_Task_Activation_Call;
4409
4410 -------------------------------
4411 -- Build_Task_Allocate_Block --
4412 -------------------------------
4413
4414 procedure Build_Task_Allocate_Block
4415 (Actions : List_Id;
4416 N : Node_Id;
4417 Args : List_Id)
4418 is
4419 T : constant Entity_Id := Entity (Expression (N));
4420 Init : constant Entity_Id := Base_Init_Proc (T);
4421 Loc : constant Source_Ptr := Sloc (N);
4422 Chain : constant Entity_Id :=
4423 Make_Defining_Identifier (Loc, Name_uChain);
4424 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4425 Block : Node_Id;
4426
4427 begin
4428 Block :=
4429 Make_Block_Statement (Loc,
4430 Identifier => New_Reference_To (Blkent, Loc),
4431 Declarations => New_List (
4432
4433 -- _Chain : Activation_Chain;
4434
4435 Make_Object_Declaration (Loc,
4436 Defining_Identifier => Chain,
4437 Aliased_Present => True,
4438 Object_Definition =>
4439 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4440
4441 Handled_Statement_Sequence =>
4442 Make_Handled_Sequence_Of_Statements (Loc,
4443
4444 Statements => New_List (
4445
4446 -- Init (Args);
4447
4448 Make_Procedure_Call_Statement (Loc,
4449 Name => New_Reference_To (Init, Loc),
4450 Parameter_Associations => Args),
4451
4452 -- Activate_Tasks (_Chain);
4453
4454 Make_Procedure_Call_Statement (Loc,
4455 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4456 Parameter_Associations => New_List (
4457 Make_Attribute_Reference (Loc,
4458 Prefix => New_Reference_To (Chain, Loc),
4459 Attribute_Name => Name_Unchecked_Access))))),
4460
4461 Has_Created_Identifier => True,
4462 Is_Task_Allocation_Block => True);
4463
4464 Append_To (Actions,
4465 Make_Implicit_Label_Declaration (Loc,
4466 Defining_Identifier => Blkent,
4467 Label_Construct => Block));
4468
4469 Append_To (Actions, Block);
4470
4471 Set_Activation_Chain_Entity (Block, Chain);
4472 end Build_Task_Allocate_Block;
4473
4474 -----------------------------------------------
4475 -- Build_Task_Allocate_Block_With_Init_Stmts --
4476 -----------------------------------------------
4477
4478 procedure Build_Task_Allocate_Block_With_Init_Stmts
4479 (Actions : List_Id;
4480 N : Node_Id;
4481 Init_Stmts : List_Id)
4482 is
4483 Loc : constant Source_Ptr := Sloc (N);
4484 Chain : constant Entity_Id :=
4485 Make_Defining_Identifier (Loc, Name_uChain);
4486 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4487 Block : Node_Id;
4488
4489 begin
4490 Append_To (Init_Stmts,
4491 Make_Procedure_Call_Statement (Loc,
4492 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4493 Parameter_Associations => New_List (
4494 Make_Attribute_Reference (Loc,
4495 Prefix => New_Reference_To (Chain, Loc),
4496 Attribute_Name => Name_Unchecked_Access))));
4497
4498 Block :=
4499 Make_Block_Statement (Loc,
4500 Identifier => New_Reference_To (Blkent, Loc),
4501 Declarations => New_List (
4502
4503 -- _Chain : Activation_Chain;
4504
4505 Make_Object_Declaration (Loc,
4506 Defining_Identifier => Chain,
4507 Aliased_Present => True,
4508 Object_Definition =>
4509 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4510
4511 Handled_Statement_Sequence =>
4512 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4513
4514 Has_Created_Identifier => True,
4515 Is_Task_Allocation_Block => True);
4516
4517 Append_To (Actions,
4518 Make_Implicit_Label_Declaration (Loc,
4519 Defining_Identifier => Blkent,
4520 Label_Construct => Block));
4521
4522 Append_To (Actions, Block);
4523
4524 Set_Activation_Chain_Entity (Block, Chain);
4525 end Build_Task_Allocate_Block_With_Init_Stmts;
4526
4527 -----------------------------------
4528 -- Build_Task_Proc_Specification --
4529 -----------------------------------
4530
4531 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4532 Loc : constant Source_Ptr := Sloc (T);
4533 Spec_Id : Entity_Id;
4534
4535 begin
4536 -- Case of explicit task type, suffix TB
4537
4538 if Comes_From_Source (T) then
4539 Spec_Id :=
4540 Make_Defining_Identifier (Loc,
4541 Chars => New_External_Name (Chars (T), "TB"));
4542
4543 -- Case of anonymous task type, suffix B
4544
4545 else
4546 Spec_Id :=
4547 Make_Defining_Identifier (Loc,
4548 Chars => New_External_Name (Chars (T), 'B'));
4549 end if;
4550
4551 Set_Is_Internal (Spec_Id);
4552
4553 -- Associate the procedure with the task, if this is the declaration
4554 -- (and not the body) of the procedure.
4555
4556 if No (Task_Body_Procedure (T)) then
4557 Set_Task_Body_Procedure (T, Spec_Id);
4558 end if;
4559
4560 return
4561 Make_Procedure_Specification (Loc,
4562 Defining_Unit_Name => Spec_Id,
4563 Parameter_Specifications => New_List (
4564 Make_Parameter_Specification (Loc,
4565 Defining_Identifier =>
4566 Make_Defining_Identifier (Loc, Name_uTask),
4567 Parameter_Type =>
4568 Make_Access_Definition (Loc,
4569 Subtype_Mark =>
4570 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4571 end Build_Task_Proc_Specification;
4572
4573 ---------------------------------------
4574 -- Build_Unprotected_Subprogram_Body --
4575 ---------------------------------------
4576
4577 function Build_Unprotected_Subprogram_Body
4578 (N : Node_Id;
4579 Pid : Node_Id) return Node_Id
4580 is
4581 Decls : constant List_Id := Declarations (N);
4582
4583 begin
4584 -- Add renamings for the Protection object, discriminals, privals and
4585 -- the entry index constant for use by debugger.
4586
4587 Debug_Private_Data_Declarations (Decls);
4588
4589 -- Make an unprotected version of the subprogram for use within the same
4590 -- object, with a new name and an additional parameter representing the
4591 -- object.
4592
4593 return
4594 Make_Subprogram_Body (Sloc (N),
4595 Specification =>
4596 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4597 Declarations => Decls,
4598 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4599 end Build_Unprotected_Subprogram_Body;
4600
4601 ----------------------------
4602 -- Collect_Entry_Families --
4603 ----------------------------
4604
4605 procedure Collect_Entry_Families
4606 (Loc : Source_Ptr;
4607 Cdecls : List_Id;
4608 Current_Node : in out Node_Id;
4609 Conctyp : Entity_Id)
4610 is
4611 Efam : Entity_Id;
4612 Efam_Decl : Node_Id;
4613 Efam_Type : Entity_Id;
4614
4615 begin
4616 Efam := First_Entity (Conctyp);
4617 while Present (Efam) loop
4618 if Ekind (Efam) = E_Entry_Family then
4619 Efam_Type := Make_Temporary (Loc, 'F');
4620
4621 declare
4622 Bas : Entity_Id :=
4623 Base_Type
4624 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4625
4626 Bas_Decl : Node_Id := Empty;
4627 Lo, Hi : Node_Id;
4628
4629 begin
4630 Get_Index_Bounds
4631 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4632
4633 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4634 Bas := Make_Temporary (Loc, 'B');
4635
4636 Bas_Decl :=
4637 Make_Subtype_Declaration (Loc,
4638 Defining_Identifier => Bas,
4639 Subtype_Indication =>
4640 Make_Subtype_Indication (Loc,
4641 Subtype_Mark =>
4642 New_Occurrence_Of (Standard_Integer, Loc),
4643 Constraint =>
4644 Make_Range_Constraint (Loc,
4645 Range_Expression => Make_Range (Loc,
4646 Make_Integer_Literal
4647 (Loc, -Entry_Family_Bound),
4648 Make_Integer_Literal
4649 (Loc, Entry_Family_Bound - 1)))));
4650
4651 Insert_After (Current_Node, Bas_Decl);
4652 Current_Node := Bas_Decl;
4653 Analyze (Bas_Decl);
4654 end if;
4655
4656 Efam_Decl :=
4657 Make_Full_Type_Declaration (Loc,
4658 Defining_Identifier => Efam_Type,
4659 Type_Definition =>
4660 Make_Unconstrained_Array_Definition (Loc,
4661 Subtype_Marks =>
4662 (New_List (New_Occurrence_Of (Bas, Loc))),
4663
4664 Component_Definition =>
4665 Make_Component_Definition (Loc,
4666 Aliased_Present => False,
4667 Subtype_Indication =>
4668 New_Reference_To (Standard_Character, Loc))));
4669 end;
4670
4671 Insert_After (Current_Node, Efam_Decl);
4672 Current_Node := Efam_Decl;
4673 Analyze (Efam_Decl);
4674
4675 Append_To (Cdecls,
4676 Make_Component_Declaration (Loc,
4677 Defining_Identifier =>
4678 Make_Defining_Identifier (Loc, Chars (Efam)),
4679
4680 Component_Definition =>
4681 Make_Component_Definition (Loc,
4682 Aliased_Present => False,
4683 Subtype_Indication =>
4684 Make_Subtype_Indication (Loc,
4685 Subtype_Mark =>
4686 New_Occurrence_Of (Efam_Type, Loc),
4687
4688 Constraint =>
4689 Make_Index_Or_Discriminant_Constraint (Loc,
4690 Constraints => New_List (
4691 New_Occurrence_Of
4692 (Etype (Discrete_Subtype_Definition
4693 (Parent (Efam))), Loc)))))));
4694
4695 end if;
4696
4697 Next_Entity (Efam);
4698 end loop;
4699 end Collect_Entry_Families;
4700
4701 -----------------------
4702 -- Concurrent_Object --
4703 -----------------------
4704
4705 function Concurrent_Object
4706 (Spec_Id : Entity_Id;
4707 Conc_Typ : Entity_Id) return Entity_Id
4708 is
4709 begin
4710 -- Parameter _O or _object
4711
4712 if Is_Protected_Type (Conc_Typ) then
4713 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4714
4715 -- Parameter _task
4716
4717 else
4718 pragma Assert (Is_Task_Type (Conc_Typ));
4719 return First_Formal (Task_Body_Procedure (Conc_Typ));
4720 end if;
4721 end Concurrent_Object;
4722
4723 ----------------------
4724 -- Copy_Result_Type --
4725 ----------------------
4726
4727 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4728 New_Res : constant Node_Id := New_Copy_Tree (Res);
4729 Par_Spec : Node_Id;
4730 Formal : Entity_Id;
4731
4732 begin
4733 -- If the result type is an access_to_subprogram, we must create
4734 -- new entities for its spec.
4735
4736 if Nkind (New_Res) = N_Access_Definition
4737 and then Present (Access_To_Subprogram_Definition (New_Res))
4738 then
4739 -- Provide new entities for the formals
4740
4741 Par_Spec := First (Parameter_Specifications
4742 (Access_To_Subprogram_Definition (New_Res)));
4743 while Present (Par_Spec) loop
4744 Formal := Defining_Identifier (Par_Spec);
4745 Set_Defining_Identifier (Par_Spec,
4746 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4747 Next (Par_Spec);
4748 end loop;
4749 end if;
4750
4751 return New_Res;
4752 end Copy_Result_Type;
4753
4754 --------------------
4755 -- Concurrent_Ref --
4756 --------------------
4757
4758 -- The expression returned for a reference to a concurrent object has the
4759 -- form:
4760
4761 -- taskV!(name)._Task_Id
4762
4763 -- for a task, and
4764
4765 -- objectV!(name)._Object
4766
4767 -- for a protected object. For the case of an access to a concurrent
4768 -- object, there is an extra explicit dereference:
4769
4770 -- taskV!(name.all)._Task_Id
4771 -- objectV!(name.all)._Object
4772
4773 -- here taskV and objectV are the types for the associated records, which
4774 -- contain the required _Task_Id and _Object fields for tasks and protected
4775 -- objects, respectively.
4776
4777 -- For the case of a task type name, the expression is
4778
4779 -- Self;
4780
4781 -- i.e. a call to the Self function which returns precisely this Task_Id
4782
4783 -- For the case of a protected type name, the expression is
4784
4785 -- objectR
4786
4787 -- which is a renaming of the _object field of the current object
4788 -- record, passed into protected operations as a parameter.
4789
4790 function Concurrent_Ref (N : Node_Id) return Node_Id is
4791 Loc : constant Source_Ptr := Sloc (N);
4792 Ntyp : constant Entity_Id := Etype (N);
4793 Dtyp : Entity_Id;
4794 Sel : Name_Id;
4795
4796 function Is_Current_Task (T : Entity_Id) return Boolean;
4797 -- Check whether the reference is to the immediately enclosing task
4798 -- type, or to an outer one (rare but legal).
4799
4800 ---------------------
4801 -- Is_Current_Task --
4802 ---------------------
4803
4804 function Is_Current_Task (T : Entity_Id) return Boolean is
4805 Scop : Entity_Id;
4806
4807 begin
4808 Scop := Current_Scope;
4809 while Present (Scop)
4810 and then Scop /= Standard_Standard
4811 loop
4812
4813 if Scop = T then
4814 return True;
4815
4816 elsif Is_Task_Type (Scop) then
4817 return False;
4818
4819 -- If this is a procedure nested within the task type, we must
4820 -- assume that it can be called from an inner task, and therefore
4821 -- cannot treat it as a local reference.
4822
4823 elsif Is_Overloadable (Scop)
4824 and then In_Open_Scopes (T)
4825 then
4826 return False;
4827
4828 else
4829 Scop := Scope (Scop);
4830 end if;
4831 end loop;
4832
4833 -- We know that we are within the task body, so should have found it
4834 -- in scope.
4835
4836 raise Program_Error;
4837 end Is_Current_Task;
4838
4839 -- Start of processing for Concurrent_Ref
4840
4841 begin
4842 if Is_Access_Type (Ntyp) then
4843 Dtyp := Designated_Type (Ntyp);
4844
4845 if Is_Protected_Type (Dtyp) then
4846 Sel := Name_uObject;
4847 else
4848 Sel := Name_uTask_Id;
4849 end if;
4850
4851 return
4852 Make_Selected_Component (Loc,
4853 Prefix =>
4854 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4855 Make_Explicit_Dereference (Loc, N)),
4856 Selector_Name => Make_Identifier (Loc, Sel));
4857
4858 elsif Is_Entity_Name (N)
4859 and then Is_Concurrent_Type (Entity (N))
4860 then
4861 if Is_Task_Type (Entity (N)) then
4862
4863 if Is_Current_Task (Entity (N)) then
4864 return
4865 Make_Function_Call (Loc,
4866 Name => New_Reference_To (RTE (RE_Self), Loc));
4867
4868 else
4869 declare
4870 Decl : Node_Id;
4871 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4872 T_Body : constant Node_Id :=
4873 Parent (Corresponding_Body (Parent (Entity (N))));
4874
4875 begin
4876 Decl :=
4877 Make_Object_Declaration (Loc,
4878 Defining_Identifier => T_Self,
4879 Object_Definition =>
4880 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4881 Expression =>
4882 Make_Function_Call (Loc,
4883 Name => New_Reference_To (RTE (RE_Self), Loc)));
4884 Prepend (Decl, Declarations (T_Body));
4885 Analyze (Decl);
4886 Set_Scope (T_Self, Entity (N));
4887 return New_Occurrence_Of (T_Self, Loc);
4888 end;
4889 end if;
4890
4891 else
4892 pragma Assert (Is_Protected_Type (Entity (N)));
4893
4894 return
4895 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4896 end if;
4897
4898 else
4899 if Is_Protected_Type (Ntyp) then
4900 Sel := Name_uObject;
4901
4902 elsif Is_Task_Type (Ntyp) then
4903 Sel := Name_uTask_Id;
4904
4905 else
4906 raise Program_Error;
4907 end if;
4908
4909 return
4910 Make_Selected_Component (Loc,
4911 Prefix =>
4912 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4913 New_Copy_Tree (N)),
4914 Selector_Name => Make_Identifier (Loc, Sel));
4915 end if;
4916 end Concurrent_Ref;
4917
4918 ------------------------
4919 -- Convert_Concurrent --
4920 ------------------------
4921
4922 function Convert_Concurrent
4923 (N : Node_Id;
4924 Typ : Entity_Id) return Node_Id
4925 is
4926 begin
4927 if not Is_Concurrent_Type (Typ) then
4928 return N;
4929 else
4930 return
4931 Unchecked_Convert_To
4932 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4933 end if;
4934 end Convert_Concurrent;
4935
4936 -------------------------------------
4937 -- Debug_Private_Data_Declarations --
4938 -------------------------------------
4939
4940 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4941 Debug_Nod : Node_Id;
4942 Decl : Node_Id;
4943
4944 begin
4945 Decl := First (Decls);
4946 while Present (Decl)
4947 and then not Comes_From_Source (Decl)
4948 loop
4949 -- Declaration for concurrent entity _object and its access type,
4950 -- along with the entry index subtype:
4951 -- type prot_typVP is access prot_typV;
4952 -- _object : prot_typVP := prot_typV (_O);
4953 -- subtype Jnn is <Type of Index> range Low .. High;
4954
4955 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4956 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4957
4958 -- Declaration for the Protection object, discriminals, privals and
4959 -- entry index constant:
4960 -- conc_typR : protection_typ renames _object._object;
4961 -- discr_nameD : discr_typ renames _object.discr_name;
4962 -- discr_nameD : discr_typ renames _task.discr_name;
4963 -- prival_name : comp_typ renames _object.comp_name;
4964 -- J : constant Jnn :=
4965 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4966
4967 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4968 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4969 Debug_Nod := Debug_Renaming_Declaration (Decl);
4970
4971 if Present (Debug_Nod) then
4972 Insert_After (Decl, Debug_Nod);
4973 end if;
4974 end if;
4975
4976 Next (Decl);
4977 end loop;
4978 end Debug_Private_Data_Declarations;
4979
4980 ----------------------------
4981 -- Entry_Index_Expression --
4982 ----------------------------
4983
4984 function Entry_Index_Expression
4985 (Sloc : Source_Ptr;
4986 Ent : Entity_Id;
4987 Index : Node_Id;
4988 Ttyp : Entity_Id) return Node_Id
4989 is
4990 Expr : Node_Id;
4991 Num : Node_Id;
4992 Lo : Node_Id;
4993 Hi : Node_Id;
4994 Prev : Entity_Id;
4995 S : Node_Id;
4996
4997 begin
4998 -- The queues of entries and entry families appear in textual order in
4999 -- the associated record. The entry index is computed as the sum of the
5000 -- number of queues for all entries that precede the designated one, to
5001 -- which is added the index expression, if this expression denotes a
5002 -- member of a family.
5003
5004 -- The following is a place holder for the count of simple entries
5005
5006 Num := Make_Integer_Literal (Sloc, 1);
5007
5008 -- We construct an expression which is a series of addition operations.
5009 -- The first operand is the number of single entries that precede this
5010 -- one, the second operand is the index value relative to the start of
5011 -- the referenced family, and the remaining operands are the lengths of
5012 -- the entry families that precede this entry, i.e. the constructed
5013 -- expression is:
5014
5015 -- number_simple_entries +
5016 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5017 -- family'length + ...
5018
5019 -- where index-value is the given index value, and s is the index
5020 -- subtype (we have to use pos because the subtype might be an
5021 -- enumeration type preventing direct subtraction). Note that the task
5022 -- entry array is one-indexed.
5023
5024 -- The upper bound of the entry family may be a discriminant, so we
5025 -- retrieve the lower bound explicitly to compute offset, rather than
5026 -- using the index subtype which may mention a discriminant.
5027
5028 if Present (Index) then
5029 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
5030
5031 Expr :=
5032 Make_Op_Add (Sloc,
5033 Left_Opnd => Num,
5034
5035 Right_Opnd =>
5036 Family_Offset (
5037 Sloc,
5038 Make_Attribute_Reference (Sloc,
5039 Attribute_Name => Name_Pos,
5040 Prefix => New_Reference_To (Base_Type (S), Sloc),
5041 Expressions => New_List (Relocate_Node (Index))),
5042 Type_Low_Bound (S),
5043 Ttyp,
5044 False));
5045 else
5046 Expr := Num;
5047 end if;
5048
5049 -- Now add lengths of preceding entries and entry families
5050
5051 Prev := First_Entity (Ttyp);
5052
5053 while Chars (Prev) /= Chars (Ent)
5054 or else (Ekind (Prev) /= Ekind (Ent))
5055 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
5056 loop
5057 if Ekind (Prev) = E_Entry then
5058 Set_Intval (Num, Intval (Num) + 1);
5059
5060 elsif Ekind (Prev) = E_Entry_Family then
5061 S :=
5062 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
5063 Lo := Type_Low_Bound (S);
5064 Hi := Type_High_Bound (S);
5065
5066 Expr :=
5067 Make_Op_Add (Sloc,
5068 Left_Opnd => Expr,
5069 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
5070
5071 -- Other components are anonymous types to be ignored
5072
5073 else
5074 null;
5075 end if;
5076
5077 Next_Entity (Prev);
5078 end loop;
5079
5080 return Expr;
5081 end Entry_Index_Expression;
5082
5083 ---------------------------
5084 -- Establish_Task_Master --
5085 ---------------------------
5086
5087 procedure Establish_Task_Master (N : Node_Id) is
5088 Call : Node_Id;
5089 begin
5090 if Restriction_Active (No_Task_Hierarchy) = False then
5091 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
5092 Prepend_To (Declarations (N), Call);
5093 Analyze (Call);
5094 end if;
5095 end Establish_Task_Master;
5096
5097 --------------------------------
5098 -- Expand_Accept_Declarations --
5099 --------------------------------
5100
5101 -- Part of the expansion of an accept statement involves the creation of
5102 -- a declaration that can be referenced from the statement sequence of
5103 -- the accept:
5104
5105 -- Ann : Address;
5106
5107 -- This declaration is inserted immediately before the accept statement
5108 -- and it is important that it be inserted before the statements of the
5109 -- statement sequence are analyzed. Thus it would be too late to create
5110 -- this declaration in the Expand_N_Accept_Statement routine, which is
5111 -- why there is a separate procedure to be called directly from Sem_Ch9.
5112
5113 -- Ann is used to hold the address of the record containing the parameters
5114 -- (see Expand_N_Entry_Call for more details on how this record is built).
5115 -- References to the parameters do an unchecked conversion of this address
5116 -- to a pointer to the required record type, and then access the field that
5117 -- holds the value of the required parameter. The entity for the address
5118 -- variable is held as the top stack element (i.e. the last element) of the
5119 -- Accept_Address stack in the corresponding entry entity, and this element
5120 -- must be set in place before the statements are processed.
5121
5122 -- The above description applies to the case of a stand alone accept
5123 -- statement, i.e. one not appearing as part of a select alternative.
5124
5125 -- For the case of an accept that appears as part of a select alternative
5126 -- of a selective accept, we must still create the declaration right away,
5127 -- since Ann is needed immediately, but there is an important difference:
5128
5129 -- The declaration is inserted before the selective accept, not before
5130 -- the accept statement (which is not part of a list anyway, and so would
5131 -- not accommodate inserted declarations)
5132
5133 -- We only need one address variable for the entire selective accept. So
5134 -- the Ann declaration is created only for the first accept alternative,
5135 -- and subsequent accept alternatives reference the same Ann variable.
5136
5137 -- We can distinguish the two cases by seeing whether the accept statement
5138 -- is part of a list. If not, then it must be in an accept alternative.
5139
5140 -- To expand the requeue statement, a label is provided at the end of the
5141 -- accept statement or alternative of which it is a part, so that the
5142 -- statement can be skipped after the requeue is complete. This label is
5143 -- created here rather than during the expansion of the accept statement,
5144 -- because it will be needed by any requeue statements within the accept,
5145 -- which are expanded before the accept.
5146
5147 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
5148 Loc : constant Source_Ptr := Sloc (N);
5149 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5150 Ann : Entity_Id := Empty;
5151 Adecl : Node_Id;
5152 Lab_Id : Node_Id;
5153 Lab : Node_Id;
5154 Ldecl : Node_Id;
5155 Ldecl2 : Node_Id;
5156
5157 begin
5158 if Full_Expander_Active then
5159
5160 -- If we have no handled statement sequence, we may need to build
5161 -- a dummy sequence consisting of a null statement. This can be
5162 -- skipped if the trivial accept optimization is permitted.
5163
5164 if not Trivial_Accept_OK
5165 and then
5166 (No (Stats) or else Null_Statements (Statements (Stats)))
5167 then
5168 Set_Handled_Statement_Sequence (N,
5169 Make_Handled_Sequence_Of_Statements (Loc,
5170 Statements => New_List (Make_Null_Statement (Loc))));
5171 end if;
5172
5173 -- Create and declare two labels to be placed at the end of the
5174 -- accept statement. The first label is used to allow requeues to
5175 -- skip the remainder of entry processing. The second label is used
5176 -- to skip the remainder of entry processing if the rendezvous
5177 -- completes in the middle of the accept body.
5178
5179 if Present (Handled_Statement_Sequence (N)) then
5180 declare
5181 Ent : Entity_Id;
5182
5183 begin
5184 Ent := Make_Temporary (Loc, 'L');
5185 Lab_Id := New_Reference_To (Ent, Loc);
5186 Lab := Make_Label (Loc, Lab_Id);
5187 Ldecl :=
5188 Make_Implicit_Label_Declaration (Loc,
5189 Defining_Identifier => Ent,
5190 Label_Construct => Lab);
5191 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5192
5193 Ent := Make_Temporary (Loc, 'L');
5194 Lab_Id := New_Reference_To (Ent, Loc);
5195 Lab := Make_Label (Loc, Lab_Id);
5196 Ldecl2 :=
5197 Make_Implicit_Label_Declaration (Loc,
5198 Defining_Identifier => Ent,
5199 Label_Construct => Lab);
5200 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5201 end;
5202
5203 else
5204 Ldecl := Empty;
5205 Ldecl2 := Empty;
5206 end if;
5207
5208 -- Case of stand alone accept statement
5209
5210 if Is_List_Member (N) then
5211
5212 if Present (Handled_Statement_Sequence (N)) then
5213 Ann := Make_Temporary (Loc, 'A');
5214
5215 Adecl :=
5216 Make_Object_Declaration (Loc,
5217 Defining_Identifier => Ann,
5218 Object_Definition =>
5219 New_Reference_To (RTE (RE_Address), Loc));
5220
5221 Insert_Before (N, Adecl);
5222 Analyze (Adecl);
5223
5224 Insert_Before (N, Ldecl);
5225 Analyze (Ldecl);
5226
5227 Insert_Before (N, Ldecl2);
5228 Analyze (Ldecl2);
5229 end if;
5230
5231 -- Case of accept statement which is in an accept alternative
5232
5233 else
5234 declare
5235 Acc_Alt : constant Node_Id := Parent (N);
5236 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
5237 Alt : Node_Id;
5238
5239 begin
5240 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
5241 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
5242
5243 -- ??? Consider a single label for select statements
5244
5245 if Present (Handled_Statement_Sequence (N)) then
5246 Prepend (Ldecl2,
5247 Statements (Handled_Statement_Sequence (N)));
5248 Analyze (Ldecl2);
5249
5250 Prepend (Ldecl,
5251 Statements (Handled_Statement_Sequence (N)));
5252 Analyze (Ldecl);
5253 end if;
5254
5255 -- Find first accept alternative of the selective accept. A
5256 -- valid selective accept must have at least one accept in it.
5257
5258 Alt := First (Select_Alternatives (Sel_Acc));
5259
5260 while Nkind (Alt) /= N_Accept_Alternative loop
5261 Next (Alt);
5262 end loop;
5263
5264 -- If we are the first accept statement, then we have to create
5265 -- the Ann variable, as for the stand alone case, except that
5266 -- it is inserted before the selective accept. Similarly, a
5267 -- label for requeue expansion must be declared.
5268
5269 if N = Accept_Statement (Alt) then
5270 Ann := Make_Temporary (Loc, 'A');
5271 Adecl :=
5272 Make_Object_Declaration (Loc,
5273 Defining_Identifier => Ann,
5274 Object_Definition =>
5275 New_Reference_To (RTE (RE_Address), Loc));
5276
5277 Insert_Before (Sel_Acc, Adecl);
5278 Analyze (Adecl);
5279
5280 -- If we are not the first accept statement, then find the Ann
5281 -- variable allocated by the first accept and use it.
5282
5283 else
5284 Ann :=
5285 Node (Last_Elmt (Accept_Address
5286 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
5287 end if;
5288 end;
5289 end if;
5290
5291 -- Merge here with Ann either created or referenced, and Adecl
5292 -- pointing to the corresponding declaration. Remaining processing
5293 -- is the same for the two cases.
5294
5295 if Present (Ann) then
5296 Append_Elmt (Ann, Accept_Address (Ent));
5297 Set_Debug_Info_Needed (Ann);
5298 end if;
5299
5300 -- Create renaming declarations for the entry formals. Each reference
5301 -- to a formal becomes a dereference of a component of the parameter
5302 -- block, whose address is held in Ann. These declarations are
5303 -- eventually inserted into the accept block, and analyzed there so
5304 -- that they have the proper scope for gdb and do not conflict with
5305 -- other declarations.
5306
5307 if Present (Parameter_Specifications (N))
5308 and then Present (Handled_Statement_Sequence (N))
5309 then
5310 declare
5311 Comp : Entity_Id;
5312 Decl : Node_Id;
5313 Formal : Entity_Id;
5314 New_F : Entity_Id;
5315 Renamed_Formal : Node_Id;
5316
5317 begin
5318 Push_Scope (Ent);
5319 Formal := First_Formal (Ent);
5320
5321 while Present (Formal) loop
5322 Comp := Entry_Component (Formal);
5323 New_F :=
5324 Make_Defining_Identifier (Loc, Chars (Formal));
5325
5326 Set_Etype (New_F, Etype (Formal));
5327 Set_Scope (New_F, Ent);
5328
5329 -- Now we set debug info needed on New_F even though it does
5330 -- not come from source, so that the debugger will get the
5331 -- right information for these generated names.
5332
5333 Set_Debug_Info_Needed (New_F);
5334
5335 if Ekind (Formal) = E_In_Parameter then
5336 Set_Ekind (New_F, E_Constant);
5337 else
5338 Set_Ekind (New_F, E_Variable);
5339 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5340 end if;
5341
5342 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5343
5344 Renamed_Formal :=
5345 Make_Selected_Component (Loc,
5346 Prefix =>
5347 Unchecked_Convert_To (
5348 Entry_Parameters_Type (Ent),
5349 New_Reference_To (Ann, Loc)),
5350 Selector_Name =>
5351 New_Reference_To (Comp, Loc));
5352
5353 Decl :=
5354 Build_Renamed_Formal_Declaration
5355 (New_F, Formal, Comp, Renamed_Formal);
5356
5357 if No (Declarations (N)) then
5358 Set_Declarations (N, New_List);
5359 end if;
5360
5361 Append (Decl, Declarations (N));
5362 Set_Renamed_Object (Formal, New_F);
5363 Next_Formal (Formal);
5364 end loop;
5365
5366 End_Scope;
5367 end;
5368 end if;
5369 end if;
5370 end Expand_Accept_Declarations;
5371
5372 ---------------------------------------------
5373 -- Expand_Access_Protected_Subprogram_Type --
5374 ---------------------------------------------
5375
5376 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5377 Loc : constant Source_Ptr := Sloc (N);
5378 Comps : List_Id;
5379 T : constant Entity_Id := Defining_Identifier (N);
5380 D_T : constant Entity_Id := Designated_Type (T);
5381 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5382 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5383 P_List : constant List_Id := Build_Protected_Spec
5384 (N, RTE (RE_Address), D_T, False);
5385 Decl1 : Node_Id;
5386 Decl2 : Node_Id;
5387 Def1 : Node_Id;
5388
5389 begin
5390 -- Create access to subprogram with full signature
5391
5392 if Etype (D_T) /= Standard_Void_Type then
5393 Def1 :=
5394 Make_Access_Function_Definition (Loc,
5395 Parameter_Specifications => P_List,
5396 Result_Definition =>
5397 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5398
5399 else
5400 Def1 :=
5401 Make_Access_Procedure_Definition (Loc,
5402 Parameter_Specifications => P_List);
5403 end if;
5404
5405 Decl1 :=
5406 Make_Full_Type_Declaration (Loc,
5407 Defining_Identifier => D_T2,
5408 Type_Definition => Def1);
5409
5410 Insert_After (N, Decl1);
5411 Analyze (Decl1);
5412
5413 -- Associate the access to subprogram with its original access to
5414 -- protected subprogram type. Needed by the backend to know that this
5415 -- type corresponds with an access to protected subprogram type.
5416
5417 Set_Original_Access_Type (D_T2, T);
5418
5419 -- Create Equivalent_Type, a record with two components for an access to
5420 -- object and an access to subprogram.
5421
5422 Comps := New_List (
5423 Make_Component_Declaration (Loc,
5424 Defining_Identifier => Make_Temporary (Loc, 'P'),
5425 Component_Definition =>
5426 Make_Component_Definition (Loc,
5427 Aliased_Present => False,
5428 Subtype_Indication =>
5429 New_Occurrence_Of (RTE (RE_Address), Loc))),
5430
5431 Make_Component_Declaration (Loc,
5432 Defining_Identifier => Make_Temporary (Loc, 'S'),
5433 Component_Definition =>
5434 Make_Component_Definition (Loc,
5435 Aliased_Present => False,
5436 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5437
5438 Decl2 :=
5439 Make_Full_Type_Declaration (Loc,
5440 Defining_Identifier => E_T,
5441 Type_Definition =>
5442 Make_Record_Definition (Loc,
5443 Component_List =>
5444 Make_Component_List (Loc, Component_Items => Comps)));
5445
5446 Insert_After (Decl1, Decl2);
5447 Analyze (Decl2);
5448 Set_Equivalent_Type (T, E_T);
5449 end Expand_Access_Protected_Subprogram_Type;
5450
5451 --------------------------
5452 -- Expand_Entry_Barrier --
5453 --------------------------
5454
5455 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5456 Cond : constant Node_Id :=
5457 Condition (Entry_Body_Formal_Part (N));
5458 Prot : constant Entity_Id := Scope (Ent);
5459 Spec_Decl : constant Node_Id := Parent (Prot);
5460 Func : Node_Id;
5461 B_F : Node_Id;
5462 Body_Decl : Node_Id;
5463
5464 begin
5465 if No_Run_Time_Mode then
5466 Error_Msg_CRT ("entry barrier", N);
5467 return;
5468 end if;
5469
5470 -- The body of the entry barrier must be analyzed in the context of the
5471 -- protected object, but its scope is external to it, just as any other
5472 -- unprotected version of a protected operation. The specification has
5473 -- been produced when the protected type declaration was elaborated. We
5474 -- build the body, insert it in the enclosing scope, but analyze it in
5475 -- the current context. A more uniform approach would be to treat the
5476 -- barrier just as a protected function, and discard the protected
5477 -- version of it because it is never called.
5478
5479 if Full_Expander_Active then
5480 B_F := Build_Barrier_Function (N, Ent, Prot);
5481 Func := Barrier_Function (Ent);
5482 Set_Corresponding_Spec (B_F, Func);
5483
5484 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5485
5486 if Nkind (Parent (Body_Decl)) = N_Subunit then
5487 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5488 end if;
5489
5490 Insert_Before_And_Analyze (Body_Decl, B_F);
5491
5492 Set_Discriminals (Spec_Decl);
5493 Set_Scope (Func, Scope (Prot));
5494
5495 else
5496 Analyze_And_Resolve (Cond, Any_Boolean);
5497 end if;
5498
5499 -- The Ravenscar profile restricts barriers to simple variables declared
5500 -- within the protected object. We also allow Boolean constants, since
5501 -- these appear in several published examples and are also allowed by
5502 -- the Aonix compiler.
5503
5504 -- Note that after analysis variables in this context will be replaced
5505 -- by the corresponding prival, that is to say a renaming of a selected
5506 -- component of the form _Object.Var. If expansion is disabled, as
5507 -- within a generic, we check that the entity appears in the current
5508 -- scope.
5509
5510 if Is_Entity_Name (Cond) then
5511
5512 -- A small optimization of useless renamings. If the scope of the
5513 -- entity of the condition is not the barrier function, then the
5514 -- condition does not reference any of the generated renamings
5515 -- within the function.
5516
5517 if Full_Expander_Active
5518 and then Scope (Entity (Cond)) /= Func
5519 then
5520 Set_Declarations (B_F, Empty_List);
5521 end if;
5522
5523 if Entity (Cond) = Standard_False
5524 or else
5525 Entity (Cond) = Standard_True
5526 then
5527 return;
5528
5529 elsif not Expander_Active
5530 and then Scope (Entity (Cond)) = Current_Scope
5531 then
5532 return;
5533
5534 -- Check for case of _object.all.field (note that the explicit
5535 -- dereference gets inserted by analyze/expand of _object.field)
5536
5537 elsif Present (Renamed_Object (Entity (Cond)))
5538 and then
5539 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5540 and then
5541 Chars
5542 (Prefix
5543 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5544 then
5545 return;
5546 end if;
5547 end if;
5548
5549 -- It is not a boolean variable or literal, so check the restriction
5550
5551 Check_Restriction (Simple_Barriers, Cond);
5552 end Expand_Entry_Barrier;
5553
5554 ------------------------------
5555 -- Expand_N_Abort_Statement --
5556 ------------------------------
5557
5558 -- Expand abort T1, T2, .. Tn; into:
5559 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5560
5561 procedure Expand_N_Abort_Statement (N : Node_Id) is
5562 Loc : constant Source_Ptr := Sloc (N);
5563 Tlist : constant List_Id := Names (N);
5564 Count : Nat;
5565 Aggr : Node_Id;
5566 Tasknm : Node_Id;
5567
5568 begin
5569 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5570 Count := 0;
5571
5572 Tasknm := First (Tlist);
5573
5574 while Present (Tasknm) loop
5575 Count := Count + 1;
5576
5577 -- A task interface class-wide type object is being aborted.
5578 -- Retrieve its _task_id by calling a dispatching routine.
5579
5580 if Ada_Version >= Ada_2005
5581 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5582 and then Is_Interface (Etype (Tasknm))
5583 and then Is_Task_Interface (Etype (Tasknm))
5584 then
5585 Append_To (Component_Associations (Aggr),
5586 Make_Component_Association (Loc,
5587 Choices => New_List (
5588 Make_Integer_Literal (Loc, Count)),
5589 Expression =>
5590
5591 -- Task_Id (Tasknm._disp_get_task_id)
5592
5593 Make_Unchecked_Type_Conversion (Loc,
5594 Subtype_Mark =>
5595 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5596 Expression =>
5597 Make_Selected_Component (Loc,
5598 Prefix => New_Copy_Tree (Tasknm),
5599 Selector_Name =>
5600 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5601
5602 else
5603 Append_To (Component_Associations (Aggr),
5604 Make_Component_Association (Loc,
5605 Choices => New_List (
5606 Make_Integer_Literal (Loc, Count)),
5607 Expression => Concurrent_Ref (Tasknm)));
5608 end if;
5609
5610 Next (Tasknm);
5611 end loop;
5612
5613 Rewrite (N,
5614 Make_Procedure_Call_Statement (Loc,
5615 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5616 Parameter_Associations => New_List (
5617 Make_Qualified_Expression (Loc,
5618 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5619 Expression => Aggr))));
5620
5621 Analyze (N);
5622 end Expand_N_Abort_Statement;
5623
5624 -------------------------------
5625 -- Expand_N_Accept_Statement --
5626 -------------------------------
5627
5628 -- This procedure handles expansion of accept statements that stand
5629 -- alone, i.e. they are not part of an accept alternative. The expansion
5630 -- of accept statement in accept alternatives is handled by the routines
5631 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5632 -- following description applies only to stand alone accept statements.
5633
5634 -- If there is no handled statement sequence, or only null statements,
5635 -- then this is called a trivial accept, and the expansion is:
5636
5637 -- Accept_Trivial (entry-index)
5638
5639 -- If there is a handled statement sequence, then the expansion is:
5640
5641 -- Ann : Address;
5642 -- {Lnn : Label}
5643
5644 -- begin
5645 -- begin
5646 -- Accept_Call (entry-index, Ann);
5647 -- Renaming_Declarations for formals
5648 -- <statement sequence from N_Accept_Statement node>
5649 -- Complete_Rendezvous;
5650 -- <<Lnn>>
5651 --
5652 -- exception
5653 -- when ... =>
5654 -- <exception handler from N_Accept_Statement node>
5655 -- Complete_Rendezvous;
5656 -- when ... =>
5657 -- <exception handler from N_Accept_Statement node>
5658 -- Complete_Rendezvous;
5659 -- ...
5660 -- end;
5661
5662 -- exception
5663 -- when all others =>
5664 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5665 -- end;
5666
5667 -- The first three declarations were already inserted ahead of the accept
5668 -- statement by the Expand_Accept_Declarations procedure, which was called
5669 -- directly from the semantics during analysis of the accept statement,
5670 -- before analyzing its contained statements.
5671
5672 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5673 -- from possible expansion activity (the original source of course does
5674 -- not have any declarations associated with the accept statement, since
5675 -- an accept statement has no declarative part). In particular, if the
5676 -- expander is active, the first such declaration is the declaration of
5677 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5678 --
5679 -- The two blocks are merged into a single block if the inner block has
5680 -- no exception handlers, but otherwise two blocks are required, since
5681 -- exceptions might be raised in the exception handlers of the inner
5682 -- block, and Exceptional_Complete_Rendezvous must be called.
5683
5684 procedure Expand_N_Accept_Statement (N : Node_Id) is
5685 Loc : constant Source_Ptr := Sloc (N);
5686 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5687 Ename : constant Node_Id := Entry_Direct_Name (N);
5688 Eindx : constant Node_Id := Entry_Index (N);
5689 Eent : constant Entity_Id := Entity (Ename);
5690 Acstack : constant Elist_Id := Accept_Address (Eent);
5691 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5692 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5693 Blkent : Entity_Id;
5694 Call : Node_Id;
5695 Block : Node_Id;
5696
5697 -- Start of processing for Expand_N_Accept_Statement
5698
5699 begin
5700 -- If accept statement is not part of a list, then its parent must be
5701 -- an accept alternative, and, as described above, we do not do any
5702 -- expansion for such accept statements at this level.
5703
5704 if not Is_List_Member (N) then
5705 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5706 return;
5707
5708 -- Trivial accept case (no statement sequence, or null statements).
5709 -- If the accept statement has declarations, then just insert them
5710 -- before the procedure call.
5711
5712 elsif Trivial_Accept_OK
5713 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5714 then
5715 -- Remove declarations for renamings, because the parameter block
5716 -- will not be assigned.
5717
5718 declare
5719 D : Node_Id;
5720 Next_D : Node_Id;
5721
5722 begin
5723 D := First (Declarations (N));
5724
5725 while Present (D) loop
5726 Next_D := Next (D);
5727 if Nkind (D) = N_Object_Renaming_Declaration then
5728 Remove (D);
5729 end if;
5730
5731 D := Next_D;
5732 end loop;
5733 end;
5734
5735 if Present (Declarations (N)) then
5736 Insert_Actions (N, Declarations (N));
5737 end if;
5738
5739 Rewrite (N,
5740 Make_Procedure_Call_Statement (Loc,
5741 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5742 Parameter_Associations => New_List (
5743 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5744
5745 Analyze (N);
5746
5747 -- Discard Entry_Address that was created for it, so it will not be
5748 -- emitted if this accept statement is in the statement part of a
5749 -- delay alternative.
5750
5751 if Present (Stats) then
5752 Remove_Last_Elmt (Acstack);
5753 end if;
5754
5755 -- Case of statement sequence present
5756
5757 else
5758 -- Construct the block, using the declarations from the accept
5759 -- statement if any to initialize the declarations of the block.
5760
5761 Blkent := Make_Temporary (Loc, 'A');
5762 Set_Ekind (Blkent, E_Block);
5763 Set_Etype (Blkent, Standard_Void_Type);
5764 Set_Scope (Blkent, Current_Scope);
5765
5766 Block :=
5767 Make_Block_Statement (Loc,
5768 Identifier => New_Reference_To (Blkent, Loc),
5769 Declarations => Declarations (N),
5770 Handled_Statement_Sequence => Build_Accept_Body (N));
5771
5772 -- For the analysis of the generated declarations, the parent node
5773 -- must be properly set.
5774
5775 Set_Parent (Block, Parent (N));
5776
5777 -- Prepend call to Accept_Call to main statement sequence If the
5778 -- accept has exception handlers, the statement sequence is wrapped
5779 -- in a block. Insert call and renaming declarations in the
5780 -- declarations of the block, so they are elaborated before the
5781 -- handlers.
5782
5783 Call :=
5784 Make_Procedure_Call_Statement (Loc,
5785 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5786 Parameter_Associations => New_List (
5787 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5788 New_Reference_To (Ann, Loc)));
5789
5790 if Parent (Stats) = N then
5791 Prepend (Call, Statements (Stats));
5792 else
5793 Set_Declarations
5794 (Parent (Stats),
5795 New_List (Call));
5796 end if;
5797
5798 Analyze (Call);
5799
5800 Push_Scope (Blkent);
5801
5802 declare
5803 D : Node_Id;
5804 Next_D : Node_Id;
5805 Typ : Entity_Id;
5806
5807 begin
5808 D := First (Declarations (N));
5809 while Present (D) loop
5810 Next_D := Next (D);
5811
5812 if Nkind (D) = N_Object_Renaming_Declaration then
5813
5814 -- The renaming declarations for the formals were created
5815 -- during analysis of the accept statement, and attached to
5816 -- the list of declarations. Place them now in the context
5817 -- of the accept block or subprogram.
5818
5819 Remove (D);
5820 Typ := Entity (Subtype_Mark (D));
5821 Insert_After (Call, D);
5822 Analyze (D);
5823
5824 -- If the formal is class_wide, it does not have an actual
5825 -- subtype. The analysis of the renaming declaration creates
5826 -- one, but we need to retain the class-wide nature of the
5827 -- entity.
5828
5829 if Is_Class_Wide_Type (Typ) then
5830 Set_Etype (Defining_Identifier (D), Typ);
5831 end if;
5832
5833 end if;
5834
5835 D := Next_D;
5836 end loop;
5837 end;
5838
5839 End_Scope;
5840
5841 -- Replace the accept statement by the new block
5842
5843 Rewrite (N, Block);
5844 Analyze (N);
5845
5846 -- Last step is to unstack the Accept_Address value
5847
5848 Remove_Last_Elmt (Acstack);
5849 end if;
5850 end Expand_N_Accept_Statement;
5851
5852 ----------------------------------
5853 -- Expand_N_Asynchronous_Select --
5854 ----------------------------------
5855
5856 -- This procedure assumes that the trigger statement is an entry call or
5857 -- a dispatching procedure call. A delay alternative should already have
5858 -- been expanded into an entry call to the appropriate delay object Wait
5859 -- entry.
5860
5861 -- If the trigger is a task entry call, the select is implemented with
5862 -- a Task_Entry_Call:
5863
5864 -- declare
5865 -- B : Boolean;
5866 -- C : Boolean;
5867 -- P : parms := (parm, parm, parm);
5868
5869 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5870
5871 -- procedure _clean is
5872 -- begin
5873 -- ...
5874 -- Cancel_Task_Entry_Call (C);
5875 -- ...
5876 -- end _clean;
5877
5878 -- begin
5879 -- Abort_Defer;
5880 -- Task_Entry_Call
5881 -- (<acceptor-task>, -- Acceptor
5882 -- <entry-index>, -- E
5883 -- P'Address, -- Uninterpreted_Data
5884 -- Asynchronous_Call, -- Mode
5885 -- B); -- Rendezvous_Successful
5886
5887 -- begin
5888 -- begin
5889 -- Abort_Undefer;
5890 -- <abortable-part>
5891 -- at end
5892 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5893 -- end;
5894 -- exception
5895 -- when Abort_Signal => Abort_Undefer;
5896 -- end;
5897
5898 -- parm := P.param;
5899 -- parm := P.param;
5900 -- ...
5901 -- if not C then
5902 -- <triggered-statements>
5903 -- end if;
5904 -- end;
5905
5906 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5907 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5908 -- as follows:
5909
5910 -- declare
5911 -- P : parms := (parm, parm, parm);
5912 -- begin
5913 -- Call_Simple (acceptor-task, entry-index, P'Address);
5914 -- parm := P.param;
5915 -- parm := P.param;
5916 -- ...
5917 -- end;
5918
5919 -- so the task at hand is to convert the latter expansion into the former
5920
5921 -- If the trigger is a protected entry call, the select is implemented
5922 -- with Protected_Entry_Call:
5923
5924 -- declare
5925 -- P : E1_Params := (param, param, param);
5926 -- Bnn : Communications_Block;
5927
5928 -- begin
5929 -- declare
5930
5931 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5932
5933 -- procedure _clean is
5934 -- begin
5935 -- ...
5936 -- if Enqueued (Bnn) then
5937 -- Cancel_Protected_Entry_Call (Bnn);
5938 -- end if;
5939 -- ...
5940 -- end _clean;
5941
5942 -- begin
5943 -- begin
5944 -- Protected_Entry_Call
5945 -- (po._object'Access, -- Object
5946 -- <entry index>, -- E
5947 -- P'Address, -- Uninterpreted_Data
5948 -- Asynchronous_Call, -- Mode
5949 -- Bnn); -- Block
5950
5951 -- if Enqueued (Bnn) then
5952 -- <abortable-part>
5953 -- end if;
5954 -- at end
5955 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5956 -- end;
5957 -- exception
5958 -- when Abort_Signal => Abort_Undefer;
5959 -- end;
5960
5961 -- if not Cancelled (Bnn) then
5962 -- <triggered-statements>
5963 -- end if;
5964 -- end;
5965
5966 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5967 -- entry call:
5968
5969 -- declare
5970 -- P : E1_Params := (param, param, param);
5971 -- Bnn : Communications_Block;
5972
5973 -- begin
5974 -- Protected_Entry_Call
5975 -- (po._object'Access, -- Object
5976 -- <entry index>, -- E
5977 -- P'Address, -- Uninterpreted_Data
5978 -- Simple_Call, -- Mode
5979 -- Bnn); -- Block
5980 -- parm := P.param;
5981 -- parm := P.param;
5982 -- ...
5983 -- end;
5984
5985 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5986 -- expanded into:
5987
5988 -- declare
5989 -- B : Boolean := False;
5990 -- Bnn : Communication_Block;
5991 -- C : Ada.Tags.Prim_Op_Kind;
5992 -- D : System.Storage_Elements.Dummy_Communication_Block;
5993 -- K : Ada.Tags.Tagged_Kind :=
5994 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5995 -- P : Parameters := (Param1 .. ParamN);
5996 -- S : Integer;
5997 -- U : Boolean;
5998
5999 -- begin
6000 -- if K = Ada.Tags.TK_Limited_Tagged then
6001 -- <dispatching-call>;
6002 -- <triggering-statements>;
6003
6004 -- else
6005 -- S :=
6006 -- Ada.Tags.Get_Offset_Index
6007 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6008
6009 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6010
6011 -- if C = POK_Protected_Entry then
6012 -- declare
6013 -- procedure _clean is
6014 -- begin
6015 -- if Enqueued (Bnn) then
6016 -- Cancel_Protected_Entry_Call (Bnn);
6017 -- end if;
6018 -- end _clean;
6019
6020 -- begin
6021 -- begin
6022 -- _Disp_Asynchronous_Select
6023 -- (<object>, S, P'Address, D, B);
6024 -- Bnn := Communication_Block (D);
6025
6026 -- Param1 := P.Param1;
6027 -- ...
6028 -- ParamN := P.ParamN;
6029
6030 -- if Enqueued (Bnn) then
6031 -- <abortable-statements>
6032 -- end if;
6033 -- at end
6034 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6035 -- end;
6036 -- exception
6037 -- when Abort_Signal => Abort_Undefer;
6038 -- end;
6039
6040 -- if not Cancelled (Bnn) then
6041 -- <triggering-statements>
6042 -- end if;
6043
6044 -- elsif C = POK_Task_Entry then
6045 -- declare
6046 -- procedure _clean is
6047 -- begin
6048 -- Cancel_Task_Entry_Call (U);
6049 -- end _clean;
6050
6051 -- begin
6052 -- Abort_Defer;
6053
6054 -- _Disp_Asynchronous_Select
6055 -- (<object>, S, P'Address, D, B);
6056 -- Bnn := Communication_Bloc (D);
6057
6058 -- Param1 := P.Param1;
6059 -- ...
6060 -- ParamN := P.ParamN;
6061
6062 -- begin
6063 -- begin
6064 -- Abort_Undefer;
6065 -- <abortable-statements>
6066 -- at end
6067 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6068 -- end;
6069 -- exception
6070 -- when Abort_Signal => Abort_Undefer;
6071 -- end;
6072
6073 -- if not U then
6074 -- <triggering-statements>
6075 -- end if;
6076 -- end;
6077
6078 -- else
6079 -- <dispatching-call>;
6080 -- <triggering-statements>
6081 -- end if;
6082 -- end if;
6083 -- end;
6084
6085 -- The job is to convert this to the asynchronous form
6086
6087 -- If the trigger is a delay statement, it will have been expanded into a
6088 -- call to one of the GNARL delay procedures. This routine will convert
6089 -- this into a protected entry call on a delay object and then continue
6090 -- processing as for a protected entry call trigger. This requires
6091 -- declaring a Delay_Block object and adding a pointer to this object to
6092 -- the parameter list of the delay procedure to form the parameter list of
6093 -- the entry call. This object is used by the runtime to queue the delay
6094 -- request.
6095
6096 -- For a description of the use of P and the assignments after the call,
6097 -- see Expand_N_Entry_Call_Statement.
6098
6099 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
6100 Loc : constant Source_Ptr := Sloc (N);
6101 Abrt : constant Node_Id := Abortable_Part (N);
6102 Astats : constant List_Id := Statements (Abrt);
6103 Trig : constant Node_Id := Triggering_Alternative (N);
6104 Tstats : constant List_Id := Statements (Trig);
6105
6106 Abort_Block_Ent : Entity_Id;
6107 Abortable_Block : Node_Id;
6108 Actuals : List_Id;
6109 Blk_Ent : Entity_Id;
6110 Blk_Typ : Entity_Id;
6111 Call : Node_Id;
6112 Call_Ent : Entity_Id;
6113 Cancel_Param : Entity_Id;
6114 Cleanup_Block : Node_Id;
6115 Cleanup_Block_Ent : Entity_Id;
6116 Cleanup_Stmts : List_Id;
6117 Conc_Typ_Stmts : List_Id;
6118 Concval : Node_Id;
6119 Dblock_Ent : Entity_Id;
6120 Decl : Node_Id;
6121 Decls : List_Id;
6122 Ecall : Node_Id;
6123 Ename : Node_Id;
6124 Enqueue_Call : Node_Id;
6125 Formals : List_Id;
6126 Hdle : List_Id;
6127 Handler_Stmt : Node_Id;
6128 Index : Node_Id;
6129 Lim_Typ_Stmts : List_Id;
6130 N_Orig : Node_Id;
6131 Obj : Entity_Id;
6132 Param : Node_Id;
6133 Params : List_Id;
6134 Pdef : Entity_Id;
6135 ProtE_Stmts : List_Id;
6136 ProtP_Stmts : List_Id;
6137 Stmt : Node_Id;
6138 Stmts : List_Id;
6139 TaskE_Stmts : List_Id;
6140
6141 B : Entity_Id; -- Call status flag
6142 Bnn : Entity_Id; -- Communication block
6143 C : Entity_Id; -- Call kind
6144 K : Entity_Id; -- Tagged kind
6145 P : Entity_Id; -- Parameter block
6146 S : Entity_Id; -- Primitive operation slot
6147 T : Entity_Id; -- Additional status flag
6148
6149 begin
6150 Process_Statements_For_Controlled_Objects (Trig);
6151 Process_Statements_For_Controlled_Objects (Abrt);
6152
6153 Blk_Ent := Make_Temporary (Loc, 'A');
6154 Ecall := Triggering_Statement (Trig);
6155
6156 -- The arguments in the call may require dynamic allocation, and the
6157 -- call statement may have been transformed into a block. The block
6158 -- may contain additional declarations for internal entities, and the
6159 -- original call is found by sequential search.
6160
6161 if Nkind (Ecall) = N_Block_Statement then
6162 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
6163 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
6164 N_Entry_Call_Statement)
6165 loop
6166 Next (Ecall);
6167 end loop;
6168 end if;
6169
6170 -- This is either a dispatching call or a delay statement used as a
6171 -- trigger which was expanded into a procedure call.
6172
6173 if Nkind (Ecall) = N_Procedure_Call_Statement then
6174 if Ada_Version >= Ada_2005
6175 and then
6176 (No (Original_Node (Ecall))
6177 or else not Nkind_In (Original_Node (Ecall),
6178 N_Delay_Relative_Statement,
6179 N_Delay_Until_Statement))
6180 then
6181 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
6182
6183 Decls := New_List;
6184 Stmts := New_List;
6185
6186 -- Call status flag processing, generate:
6187 -- B : Boolean := False;
6188
6189 B := Build_B (Loc, Decls);
6190
6191 -- Communication block processing, generate:
6192 -- Bnn : Communication_Block;
6193
6194 Bnn := Make_Temporary (Loc, 'B');
6195 Append_To (Decls,
6196 Make_Object_Declaration (Loc,
6197 Defining_Identifier => Bnn,
6198 Object_Definition =>
6199 New_Reference_To (RTE (RE_Communication_Block), Loc)));
6200
6201 -- Call kind processing, generate:
6202 -- C : Ada.Tags.Prim_Op_Kind;
6203
6204 C := Build_C (Loc, Decls);
6205
6206 -- Tagged kind processing, generate:
6207 -- K : Ada.Tags.Tagged_Kind :=
6208 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6209
6210 -- Dummy communication block, generate:
6211 -- D : Dummy_Communication_Block;
6212
6213 Append_To (Decls,
6214 Make_Object_Declaration (Loc,
6215 Defining_Identifier =>
6216 Make_Defining_Identifier (Loc, Name_uD),
6217 Object_Definition =>
6218 New_Reference_To (
6219 RTE (RE_Dummy_Communication_Block), Loc)));
6220
6221 K := Build_K (Loc, Decls, Obj);
6222
6223 -- Parameter block processing
6224
6225 Blk_Typ := Build_Parameter_Block
6226 (Loc, Actuals, Formals, Decls);
6227 P := Parameter_Block_Pack
6228 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6229
6230 -- Dispatch table slot processing, generate:
6231 -- S : Integer;
6232
6233 S := Build_S (Loc, Decls);
6234
6235 -- Additional status flag processing, generate:
6236 -- Tnn : Boolean;
6237
6238 T := Make_Temporary (Loc, 'T');
6239 Append_To (Decls,
6240 Make_Object_Declaration (Loc,
6241 Defining_Identifier => T,
6242 Object_Definition =>
6243 New_Reference_To (Standard_Boolean, Loc)));
6244
6245 ------------------------------
6246 -- Protected entry handling --
6247 ------------------------------
6248
6249 -- Generate:
6250 -- Param1 := P.Param1;
6251 -- ...
6252 -- ParamN := P.ParamN;
6253
6254 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6255
6256 -- Generate:
6257 -- Bnn := Communication_Block (D);
6258
6259 Prepend_To (Cleanup_Stmts,
6260 Make_Assignment_Statement (Loc,
6261 Name =>
6262 New_Reference_To (Bnn, Loc),
6263 Expression =>
6264 Make_Unchecked_Type_Conversion (Loc,
6265 Subtype_Mark =>
6266 New_Reference_To (RTE (RE_Communication_Block), Loc),
6267 Expression => Make_Identifier (Loc, Name_uD))));
6268
6269 -- Generate:
6270 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6271
6272 Prepend_To (Cleanup_Stmts,
6273 Make_Procedure_Call_Statement (Loc,
6274 Name =>
6275 New_Reference_To (
6276 Find_Prim_Op (Etype (Etype (Obj)),
6277 Name_uDisp_Asynchronous_Select),
6278 Loc),
6279 Parameter_Associations =>
6280 New_List (
6281 New_Copy_Tree (Obj), -- <object>
6282 New_Reference_To (S, Loc), -- S
6283 Make_Attribute_Reference (Loc, -- P'Address
6284 Prefix =>
6285 New_Reference_To (P, Loc),
6286 Attribute_Name =>
6287 Name_Address),
6288 Make_Identifier (Loc, Name_uD), -- D
6289 New_Reference_To (B, Loc)))); -- B
6290
6291 -- Generate:
6292 -- if Enqueued (Bnn) then
6293 -- <abortable-statements>
6294 -- end if;
6295
6296 Append_To (Cleanup_Stmts,
6297 Make_If_Statement (Loc,
6298 Condition =>
6299 Make_Function_Call (Loc,
6300 Name =>
6301 New_Reference_To (RTE (RE_Enqueued), Loc),
6302 Parameter_Associations =>
6303 New_List (
6304 New_Reference_To (Bnn, Loc))),
6305
6306 Then_Statements =>
6307 New_Copy_List_Tree (Astats)));
6308
6309 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6310 -- will then generate a _clean for the communication block Bnn.
6311
6312 -- Generate:
6313 -- declare
6314 -- procedure _clean is
6315 -- begin
6316 -- if Enqueued (Bnn) then
6317 -- Cancel_Protected_Entry_Call (Bnn);
6318 -- end if;
6319 -- end _clean;
6320 -- begin
6321 -- Cleanup_Stmts
6322 -- at end
6323 -- _clean;
6324 -- end;
6325
6326 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6327 Cleanup_Block :=
6328 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6329
6330 -- Wrap the cleanup block in an exception handling block
6331
6332 -- Generate:
6333 -- begin
6334 -- Cleanup_Block
6335 -- exception
6336 -- when Abort_Signal => Abort_Undefer;
6337 -- end;
6338
6339 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6340 ProtE_Stmts :=
6341 New_List (
6342 Make_Implicit_Label_Declaration (Loc,
6343 Defining_Identifier =>
6344 Abort_Block_Ent),
6345
6346 Build_Abort_Block
6347 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6348
6349 -- Generate:
6350 -- if not Cancelled (Bnn) then
6351 -- <triggering-statements>
6352 -- end if;
6353
6354 Append_To (ProtE_Stmts,
6355 Make_If_Statement (Loc,
6356 Condition =>
6357 Make_Op_Not (Loc,
6358 Right_Opnd =>
6359 Make_Function_Call (Loc,
6360 Name =>
6361 New_Reference_To (RTE (RE_Cancelled), Loc),
6362 Parameter_Associations =>
6363 New_List (
6364 New_Reference_To (Bnn, Loc)))),
6365
6366 Then_Statements =>
6367 New_Copy_List_Tree (Tstats)));
6368
6369 -------------------------
6370 -- Task entry handling --
6371 -------------------------
6372
6373 -- Generate:
6374 -- Param1 := P.Param1;
6375 -- ...
6376 -- ParamN := P.ParamN;
6377
6378 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6379
6380 -- Generate:
6381 -- Bnn := Communication_Block (D);
6382
6383 Append_To (TaskE_Stmts,
6384 Make_Assignment_Statement (Loc,
6385 Name =>
6386 New_Reference_To (Bnn, Loc),
6387 Expression =>
6388 Make_Unchecked_Type_Conversion (Loc,
6389 Subtype_Mark =>
6390 New_Reference_To (RTE (RE_Communication_Block), Loc),
6391 Expression => Make_Identifier (Loc, Name_uD))));
6392
6393 -- Generate:
6394 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6395
6396 Prepend_To (TaskE_Stmts,
6397 Make_Procedure_Call_Statement (Loc,
6398 Name =>
6399 New_Reference_To (
6400 Find_Prim_Op (Etype (Etype (Obj)),
6401 Name_uDisp_Asynchronous_Select),
6402 Loc),
6403 Parameter_Associations =>
6404 New_List (
6405 New_Copy_Tree (Obj), -- <object>
6406 New_Reference_To (S, Loc), -- S
6407 Make_Attribute_Reference (Loc, -- P'Address
6408 Prefix =>
6409 New_Reference_To (P, Loc),
6410 Attribute_Name =>
6411 Name_Address),
6412 Make_Identifier (Loc, Name_uD), -- D
6413 New_Reference_To (B, Loc)))); -- B
6414
6415 -- Generate:
6416 -- Abort_Defer;
6417
6418 Prepend_To (TaskE_Stmts,
6419 Make_Procedure_Call_Statement (Loc,
6420 Name =>
6421 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6422 Parameter_Associations =>
6423 No_List));
6424
6425 -- Generate:
6426 -- Abort_Undefer;
6427 -- <abortable-statements>
6428
6429 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6430
6431 Prepend_To (Cleanup_Stmts,
6432 Make_Procedure_Call_Statement (Loc,
6433 Name =>
6434 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6435 Parameter_Associations =>
6436 No_List));
6437
6438 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6439 -- will generate a _clean for the additional status flag.
6440
6441 -- Generate:
6442 -- declare
6443 -- procedure _clean is
6444 -- begin
6445 -- Cancel_Task_Entry_Call (U);
6446 -- end _clean;
6447 -- begin
6448 -- Cleanup_Stmts
6449 -- at end
6450 -- _clean;
6451 -- end;
6452
6453 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6454 Cleanup_Block :=
6455 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6456
6457 -- Wrap the cleanup block in an exception handling block
6458
6459 -- Generate:
6460 -- begin
6461 -- Cleanup_Block
6462 -- exception
6463 -- when Abort_Signal => Abort_Undefer;
6464 -- end;
6465
6466 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6467
6468 Append_To (TaskE_Stmts,
6469 Make_Implicit_Label_Declaration (Loc,
6470 Defining_Identifier => Abort_Block_Ent));
6471
6472 Append_To (TaskE_Stmts,
6473 Build_Abort_Block
6474 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6475
6476 -- Generate:
6477 -- if not T then
6478 -- <triggering-statements>
6479 -- end if;
6480
6481 Append_To (TaskE_Stmts,
6482 Make_If_Statement (Loc,
6483 Condition =>
6484 Make_Op_Not (Loc,
6485 Right_Opnd =>
6486 New_Reference_To (T, Loc)),
6487
6488 Then_Statements =>
6489 New_Copy_List_Tree (Tstats)));
6490
6491 ----------------------------------
6492 -- Protected procedure handling --
6493 ----------------------------------
6494
6495 -- Generate:
6496 -- <dispatching-call>;
6497 -- <triggering-statements>
6498
6499 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6500 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6501
6502 -- Generate:
6503 -- S := Ada.Tags.Get_Offset_Index
6504 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6505
6506 Conc_Typ_Stmts :=
6507 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6508
6509 -- Generate:
6510 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6511
6512 Append_To (Conc_Typ_Stmts,
6513 Make_Procedure_Call_Statement (Loc,
6514 Name =>
6515 New_Reference_To (
6516 Find_Prim_Op (Etype (Etype (Obj)),
6517 Name_uDisp_Get_Prim_Op_Kind),
6518 Loc),
6519 Parameter_Associations =>
6520 New_List (
6521 New_Copy_Tree (Obj),
6522 New_Reference_To (S, Loc),
6523 New_Reference_To (C, Loc))));
6524
6525 -- Generate:
6526 -- if C = POK_Procedure_Entry then
6527 -- ProtE_Stmts
6528 -- elsif C = POK_Task_Entry then
6529 -- TaskE_Stmts
6530 -- else
6531 -- ProtP_Stmts
6532 -- end if;
6533
6534 Append_To (Conc_Typ_Stmts,
6535 Make_If_Statement (Loc,
6536 Condition =>
6537 Make_Op_Eq (Loc,
6538 Left_Opnd =>
6539 New_Reference_To (C, Loc),
6540 Right_Opnd =>
6541 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6542
6543 Then_Statements =>
6544 ProtE_Stmts,
6545
6546 Elsif_Parts =>
6547 New_List (
6548 Make_Elsif_Part (Loc,
6549 Condition =>
6550 Make_Op_Eq (Loc,
6551 Left_Opnd =>
6552 New_Reference_To (C, Loc),
6553 Right_Opnd =>
6554 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6555
6556 Then_Statements =>
6557 TaskE_Stmts)),
6558
6559 Else_Statements =>
6560 ProtP_Stmts));
6561
6562 -- Generate:
6563 -- <dispatching-call>;
6564 -- <triggering-statements>
6565
6566 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6567 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6568
6569 -- Generate:
6570 -- if K = Ada.Tags.TK_Limited_Tagged then
6571 -- Lim_Typ_Stmts
6572 -- else
6573 -- Conc_Typ_Stmts
6574 -- end if;
6575
6576 Append_To (Stmts,
6577 Make_If_Statement (Loc,
6578 Condition =>
6579 Make_Op_Eq (Loc,
6580 Left_Opnd =>
6581 New_Reference_To (K, Loc),
6582 Right_Opnd =>
6583 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6584
6585 Then_Statements =>
6586 Lim_Typ_Stmts,
6587
6588 Else_Statements =>
6589 Conc_Typ_Stmts));
6590
6591 Rewrite (N,
6592 Make_Block_Statement (Loc,
6593 Declarations =>
6594 Decls,
6595 Handled_Statement_Sequence =>
6596 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6597
6598 Analyze (N);
6599 return;
6600
6601 -- Delay triggering statement processing
6602
6603 else
6604 -- Add a Delay_Block object to the parameter list of the delay
6605 -- procedure to form the parameter list of the Wait entry call.
6606
6607 Dblock_Ent := Make_Temporary (Loc, 'D');
6608
6609 Pdef := Entity (Name (Ecall));
6610
6611 if Is_RTE (Pdef, RO_CA_Delay_For) then
6612 Enqueue_Call :=
6613 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6614
6615 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6616 Enqueue_Call :=
6617 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6618
6619 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6620 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6621 end if;
6622
6623 Append_To (Parameter_Associations (Ecall),
6624 Make_Attribute_Reference (Loc,
6625 Prefix => New_Reference_To (Dblock_Ent, Loc),
6626 Attribute_Name => Name_Unchecked_Access));
6627
6628 -- Create the inner block to protect the abortable part
6629
6630 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6631
6632 Prepend_To (Astats,
6633 Make_Procedure_Call_Statement (Loc,
6634 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6635
6636 Abortable_Block :=
6637 Make_Block_Statement (Loc,
6638 Identifier => New_Reference_To (Blk_Ent, Loc),
6639 Handled_Statement_Sequence =>
6640 Make_Handled_Sequence_Of_Statements (Loc,
6641 Statements => Astats),
6642 Has_Created_Identifier => True,
6643 Is_Asynchronous_Call_Block => True);
6644
6645 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6646
6647 Rewrite (Ecall,
6648 Make_Implicit_If_Statement (N,
6649 Condition => Make_Function_Call (Loc,
6650 Name => Enqueue_Call,
6651 Parameter_Associations => Parameter_Associations (Ecall)),
6652 Then_Statements =>
6653 New_List (Make_Block_Statement (Loc,
6654 Handled_Statement_Sequence =>
6655 Make_Handled_Sequence_Of_Statements (Loc,
6656 Statements => New_List (
6657 Make_Implicit_Label_Declaration (Loc,
6658 Defining_Identifier => Blk_Ent,
6659 Label_Construct => Abortable_Block),
6660 Abortable_Block),
6661 Exception_Handlers => Hdle)))));
6662
6663 Stmts := New_List (Ecall);
6664
6665 -- Construct statement sequence for new block
6666
6667 Append_To (Stmts,
6668 Make_Implicit_If_Statement (N,
6669 Condition => Make_Function_Call (Loc,
6670 Name => New_Reference_To (
6671 RTE (RE_Timed_Out), Loc),
6672 Parameter_Associations => New_List (
6673 Make_Attribute_Reference (Loc,
6674 Prefix => New_Reference_To (Dblock_Ent, Loc),
6675 Attribute_Name => Name_Unchecked_Access))),
6676 Then_Statements => Tstats));
6677
6678 -- The result is the new block
6679
6680 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6681
6682 Rewrite (N,
6683 Make_Block_Statement (Loc,
6684 Declarations => New_List (
6685 Make_Object_Declaration (Loc,
6686 Defining_Identifier => Dblock_Ent,
6687 Aliased_Present => True,
6688 Object_Definition => New_Reference_To (
6689 RTE (RE_Delay_Block), Loc))),
6690
6691 Handled_Statement_Sequence =>
6692 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6693
6694 Analyze (N);
6695 return;
6696 end if;
6697
6698 else
6699 N_Orig := N;
6700 end if;
6701
6702 Extract_Entry (Ecall, Concval, Ename, Index);
6703 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6704
6705 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6706 Decls := Declarations (Ecall);
6707
6708 if Is_Protected_Type (Etype (Concval)) then
6709
6710 -- Get the declarations of the block expanded from the entry call
6711
6712 Decl := First (Decls);
6713 while Present (Decl)
6714 and then
6715 (Nkind (Decl) /= N_Object_Declaration
6716 or else not Is_RTE (Etype (Object_Definition (Decl)),
6717 RE_Communication_Block))
6718 loop
6719 Next (Decl);
6720 end loop;
6721
6722 pragma Assert (Present (Decl));
6723 Cancel_Param := Defining_Identifier (Decl);
6724
6725 -- Change the mode of the Protected_Entry_Call call
6726
6727 -- Protected_Entry_Call (
6728 -- Object => po._object'Access,
6729 -- E => <entry index>;
6730 -- Uninterpreted_Data => P'Address;
6731 -- Mode => Asynchronous_Call;
6732 -- Block => Bnn);
6733
6734 Stmt := First (Stmts);
6735
6736 -- Skip assignments to temporaries created for in-out parameters
6737
6738 -- This makes unwarranted assumptions about the shape of the expanded
6739 -- tree for the call, and should be cleaned up ???
6740
6741 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6742 Next (Stmt);
6743 end loop;
6744
6745 Call := Stmt;
6746
6747 Param := First (Parameter_Associations (Call));
6748 while Present (Param)
6749 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6750 loop
6751 Next (Param);
6752 end loop;
6753
6754 pragma Assert (Present (Param));
6755 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6756 Analyze (Param);
6757
6758 -- Append an if statement to execute the abortable part
6759
6760 -- Generate:
6761 -- if Enqueued (Bnn) then
6762
6763 Append_To (Stmts,
6764 Make_Implicit_If_Statement (N,
6765 Condition => Make_Function_Call (Loc,
6766 Name => New_Reference_To (RTE (RE_Enqueued), Loc),
6767 Parameter_Associations => New_List (
6768 New_Reference_To (Cancel_Param, Loc))),
6769 Then_Statements => Astats));
6770
6771 Abortable_Block :=
6772 Make_Block_Statement (Loc,
6773 Identifier => New_Reference_To (Blk_Ent, Loc),
6774 Handled_Statement_Sequence =>
6775 Make_Handled_Sequence_Of_Statements (Loc,
6776 Statements => Stmts),
6777 Has_Created_Identifier => True,
6778 Is_Asynchronous_Call_Block => True);
6779
6780 -- For the VM call Update_Exception instead of Abort_Undefer.
6781 -- See 4jexcept.ads for an explanation.
6782
6783 if VM_Target = No_VM then
6784 if Exception_Mechanism = Back_End_Exceptions then
6785
6786 -- Aborts are not deferred at beginning of exception handlers
6787 -- in ZCX.
6788
6789 Handler_Stmt := Make_Null_Statement (Loc);
6790
6791 else
6792 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6793 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6794 Parameter_Associations => No_List);
6795 end if;
6796 else
6797 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6798 Name => New_Reference_To (RTE (RE_Update_Exception), Loc),
6799 Parameter_Associations => New_List (
6800 Make_Function_Call (Loc,
6801 Name => New_Occurrence_Of
6802 (RTE (RE_Current_Target_Exception), Loc))));
6803 end if;
6804
6805 Stmts := New_List (
6806 Make_Block_Statement (Loc,
6807 Handled_Statement_Sequence =>
6808 Make_Handled_Sequence_Of_Statements (Loc,
6809 Statements => New_List (
6810 Make_Implicit_Label_Declaration (Loc,
6811 Defining_Identifier => Blk_Ent,
6812 Label_Construct => Abortable_Block),
6813 Abortable_Block),
6814
6815 -- exception
6816
6817 Exception_Handlers => New_List (
6818 Make_Implicit_Exception_Handler (Loc,
6819
6820 -- when Abort_Signal =>
6821 -- Abort_Undefer.all;
6822
6823 Exception_Choices =>
6824 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6825 Statements => New_List (Handler_Stmt))))),
6826
6827 -- if not Cancelled (Bnn) then
6828 -- triggered statements
6829 -- end if;
6830
6831 Make_Implicit_If_Statement (N,
6832 Condition => Make_Op_Not (Loc,
6833 Right_Opnd =>
6834 Make_Function_Call (Loc,
6835 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6836 Parameter_Associations => New_List (
6837 New_Occurrence_Of (Cancel_Param, Loc)))),
6838 Then_Statements => Tstats));
6839
6840 -- Asynchronous task entry call
6841
6842 else
6843 if No (Decls) then
6844 Decls := New_List;
6845 end if;
6846
6847 B := Make_Defining_Identifier (Loc, Name_uB);
6848
6849 -- Insert declaration of B in declarations of existing block
6850
6851 Prepend_To (Decls,
6852 Make_Object_Declaration (Loc,
6853 Defining_Identifier => B,
6854 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6855
6856 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6857
6858 -- Insert declaration of C in declarations of existing block
6859
6860 Prepend_To (Decls,
6861 Make_Object_Declaration (Loc,
6862 Defining_Identifier => Cancel_Param,
6863 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6864
6865 -- Remove and save the call to Call_Simple
6866
6867 Stmt := First (Stmts);
6868
6869 -- Skip assignments to temporaries created for in-out parameters.
6870 -- This makes unwarranted assumptions about the shape of the expanded
6871 -- tree for the call, and should be cleaned up ???
6872
6873 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6874 Next (Stmt);
6875 end loop;
6876
6877 Call := Stmt;
6878
6879 -- Create the inner block to protect the abortable part
6880
6881 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6882
6883 Prepend_To (Astats,
6884 Make_Procedure_Call_Statement (Loc,
6885 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6886
6887 Abortable_Block :=
6888 Make_Block_Statement (Loc,
6889 Identifier => New_Reference_To (Blk_Ent, Loc),
6890 Handled_Statement_Sequence =>
6891 Make_Handled_Sequence_Of_Statements (Loc,
6892 Statements => Astats),
6893 Has_Created_Identifier => True,
6894 Is_Asynchronous_Call_Block => True);
6895
6896 Insert_After (Call,
6897 Make_Block_Statement (Loc,
6898 Handled_Statement_Sequence =>
6899 Make_Handled_Sequence_Of_Statements (Loc,
6900 Statements => New_List (
6901 Make_Implicit_Label_Declaration (Loc,
6902 Defining_Identifier =>
6903 Blk_Ent,
6904 Label_Construct =>
6905 Abortable_Block),
6906 Abortable_Block),
6907 Exception_Handlers => Hdle)));
6908
6909 -- Create new call statement
6910
6911 Params := Parameter_Associations (Call);
6912
6913 Append_To (Params,
6914 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6915 Append_To (Params,
6916 New_Reference_To (B, Loc));
6917
6918 Rewrite (Call,
6919 Make_Procedure_Call_Statement (Loc,
6920 Name =>
6921 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6922 Parameter_Associations => Params));
6923
6924 -- Construct statement sequence for new block
6925
6926 Append_To (Stmts,
6927 Make_Implicit_If_Statement (N,
6928 Condition =>
6929 Make_Op_Not (Loc,
6930 New_Reference_To (Cancel_Param, Loc)),
6931 Then_Statements => Tstats));
6932
6933 -- Protected the call against abort
6934
6935 Prepend_To (Stmts,
6936 Make_Procedure_Call_Statement (Loc,
6937 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6938 Parameter_Associations => Empty_List));
6939 end if;
6940
6941 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6942
6943 -- The result is the new block
6944
6945 Rewrite (N_Orig,
6946 Make_Block_Statement (Loc,
6947 Declarations => Decls,
6948 Handled_Statement_Sequence =>
6949 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6950
6951 Analyze (N_Orig);
6952 end Expand_N_Asynchronous_Select;
6953
6954 -------------------------------------
6955 -- Expand_N_Conditional_Entry_Call --
6956 -------------------------------------
6957
6958 -- The conditional task entry call is converted to a call to
6959 -- Task_Entry_Call:
6960
6961 -- declare
6962 -- B : Boolean;
6963 -- P : parms := (parm, parm, parm);
6964
6965 -- begin
6966 -- Task_Entry_Call
6967 -- (<acceptor-task>, -- Acceptor
6968 -- <entry-index>, -- E
6969 -- P'Address, -- Uninterpreted_Data
6970 -- Conditional_Call, -- Mode
6971 -- B); -- Rendezvous_Successful
6972 -- parm := P.param;
6973 -- parm := P.param;
6974 -- ...
6975 -- if B then
6976 -- normal-statements
6977 -- else
6978 -- else-statements
6979 -- end if;
6980 -- end;
6981
6982 -- For a description of the use of P and the assignments after the call,
6983 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6984 -- conditional entry call has already been expanded (by the Expand_N_Entry
6985 -- _Call_Statement procedure) as follows:
6986
6987 -- declare
6988 -- P : parms := (parm, parm, parm);
6989 -- begin
6990 -- ... info for in-out parameters
6991 -- Call_Simple (acceptor-task, entry-index, P'Address);
6992 -- parm := P.param;
6993 -- parm := P.param;
6994 -- ...
6995 -- end;
6996
6997 -- so the task at hand is to convert the latter expansion into the former
6998
6999 -- The conditional protected entry call is converted to a call to
7000 -- Protected_Entry_Call:
7001
7002 -- declare
7003 -- P : parms := (parm, parm, parm);
7004 -- Bnn : Communications_Block;
7005
7006 -- begin
7007 -- Protected_Entry_Call
7008 -- (po._object'Access, -- Object
7009 -- <entry index>, -- E
7010 -- P'Address, -- Uninterpreted_Data
7011 -- Conditional_Call, -- Mode
7012 -- Bnn); -- Block
7013 -- parm := P.param;
7014 -- parm := P.param;
7015 -- ...
7016 -- if Cancelled (Bnn) then
7017 -- else-statements
7018 -- else
7019 -- normal-statements
7020 -- end if;
7021 -- end;
7022
7023 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7024 -- into:
7025
7026 -- declare
7027 -- B : Boolean := False;
7028 -- C : Ada.Tags.Prim_Op_Kind;
7029 -- K : Ada.Tags.Tagged_Kind :=
7030 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7031 -- P : Parameters := (Param1 .. ParamN);
7032 -- S : Integer;
7033
7034 -- begin
7035 -- if K = Ada.Tags.TK_Limited_Tagged then
7036 -- <dispatching-call>;
7037 -- <triggering-statements>
7038
7039 -- else
7040 -- S :=
7041 -- Ada.Tags.Get_Offset_Index
7042 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7043
7044 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7045
7046 -- if C = POK_Protected_Entry
7047 -- or else C = POK_Task_Entry
7048 -- then
7049 -- Param1 := P.Param1;
7050 -- ...
7051 -- ParamN := P.ParamN;
7052 -- end if;
7053
7054 -- if B then
7055 -- if C = POK_Procedure
7056 -- or else C = POK_Protected_Procedure
7057 -- or else C = POK_Task_Procedure
7058 -- then
7059 -- <dispatching-call>;
7060 -- end if;
7061
7062 -- <triggering-statements>
7063 -- else
7064 -- <else-statements>
7065 -- end if;
7066 -- end if;
7067 -- end;
7068
7069 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
7070 Loc : constant Source_Ptr := Sloc (N);
7071 Alt : constant Node_Id := Entry_Call_Alternative (N);
7072 Blk : Node_Id := Entry_Call_Statement (Alt);
7073
7074 Actuals : List_Id;
7075 Blk_Typ : Entity_Id;
7076 Call : Node_Id;
7077 Call_Ent : Entity_Id;
7078 Conc_Typ_Stmts : List_Id;
7079 Decl : Node_Id;
7080 Decls : List_Id;
7081 Formals : List_Id;
7082 Lim_Typ_Stmts : List_Id;
7083 N_Stats : List_Id;
7084 Obj : Entity_Id;
7085 Param : Node_Id;
7086 Params : List_Id;
7087 Stmt : Node_Id;
7088 Stmts : List_Id;
7089 Transient_Blk : Node_Id;
7090 Unpack : List_Id;
7091
7092 B : Entity_Id; -- Call status flag
7093 C : Entity_Id; -- Call kind
7094 K : Entity_Id; -- Tagged kind
7095 P : Entity_Id; -- Parameter block
7096 S : Entity_Id; -- Primitive operation slot
7097
7098 begin
7099 Process_Statements_For_Controlled_Objects (N);
7100
7101 if Ada_Version >= Ada_2005
7102 and then Nkind (Blk) = N_Procedure_Call_Statement
7103 then
7104 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7105
7106 Decls := New_List;
7107 Stmts := New_List;
7108
7109 -- Call status flag processing, generate:
7110 -- B : Boolean := False;
7111
7112 B := Build_B (Loc, Decls);
7113
7114 -- Call kind processing, generate:
7115 -- C : Ada.Tags.Prim_Op_Kind;
7116
7117 C := Build_C (Loc, Decls);
7118
7119 -- Tagged kind processing, generate:
7120 -- K : Ada.Tags.Tagged_Kind :=
7121 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7122
7123 K := Build_K (Loc, Decls, Obj);
7124
7125 -- Parameter block processing
7126
7127 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7128 P := Parameter_Block_Pack
7129 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7130
7131 -- Dispatch table slot processing, generate:
7132 -- S : Integer;
7133
7134 S := Build_S (Loc, Decls);
7135
7136 -- Generate:
7137 -- S := Ada.Tags.Get_Offset_Index
7138 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7139
7140 Conc_Typ_Stmts :=
7141 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7142
7143 -- Generate:
7144 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7145
7146 Append_To (Conc_Typ_Stmts,
7147 Make_Procedure_Call_Statement (Loc,
7148 Name =>
7149 New_Reference_To (
7150 Find_Prim_Op (Etype (Etype (Obj)),
7151 Name_uDisp_Conditional_Select),
7152 Loc),
7153 Parameter_Associations =>
7154 New_List (
7155 New_Copy_Tree (Obj), -- <object>
7156 New_Reference_To (S, Loc), -- S
7157 Make_Attribute_Reference (Loc, -- P'Address
7158 Prefix =>
7159 New_Reference_To (P, Loc),
7160 Attribute_Name =>
7161 Name_Address),
7162 New_Reference_To (C, Loc), -- C
7163 New_Reference_To (B, Loc)))); -- B
7164
7165 -- Generate:
7166 -- if C = POK_Protected_Entry
7167 -- or else C = POK_Task_Entry
7168 -- then
7169 -- Param1 := P.Param1;
7170 -- ...
7171 -- ParamN := P.ParamN;
7172 -- end if;
7173
7174 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7175
7176 -- Generate the if statement only when the packed parameters need
7177 -- explicit assignments to their corresponding actuals.
7178
7179 if Present (Unpack) then
7180 Append_To (Conc_Typ_Stmts,
7181 Make_If_Statement (Loc,
7182
7183 Condition =>
7184 Make_Or_Else (Loc,
7185 Left_Opnd =>
7186 Make_Op_Eq (Loc,
7187 Left_Opnd =>
7188 New_Reference_To (C, Loc),
7189 Right_Opnd =>
7190 New_Reference_To (RTE (
7191 RE_POK_Protected_Entry), Loc)),
7192 Right_Opnd =>
7193 Make_Op_Eq (Loc,
7194 Left_Opnd =>
7195 New_Reference_To (C, Loc),
7196 Right_Opnd =>
7197 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
7198
7199 Then_Statements =>
7200 Unpack));
7201 end if;
7202
7203 -- Generate:
7204 -- if B then
7205 -- if C = POK_Procedure
7206 -- or else C = POK_Protected_Procedure
7207 -- or else C = POK_Task_Procedure
7208 -- then
7209 -- <dispatching-call>
7210 -- end if;
7211 -- <normal-statements>
7212 -- else
7213 -- <else-statements>
7214 -- end if;
7215
7216 N_Stats := New_Copy_List_Tree (Statements (Alt));
7217
7218 Prepend_To (N_Stats,
7219 Make_If_Statement (Loc,
7220 Condition =>
7221 Make_Or_Else (Loc,
7222 Left_Opnd =>
7223 Make_Op_Eq (Loc,
7224 Left_Opnd =>
7225 New_Reference_To (C, Loc),
7226 Right_Opnd =>
7227 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
7228
7229 Right_Opnd =>
7230 Make_Or_Else (Loc,
7231 Left_Opnd =>
7232 Make_Op_Eq (Loc,
7233 Left_Opnd =>
7234 New_Reference_To (C, Loc),
7235 Right_Opnd =>
7236 New_Reference_To (RTE (
7237 RE_POK_Protected_Procedure), Loc)),
7238
7239 Right_Opnd =>
7240 Make_Op_Eq (Loc,
7241 Left_Opnd =>
7242 New_Reference_To (C, Loc),
7243 Right_Opnd =>
7244 New_Reference_To (RTE (
7245 RE_POK_Task_Procedure), Loc)))),
7246
7247 Then_Statements =>
7248 New_List (Blk)));
7249
7250 Append_To (Conc_Typ_Stmts,
7251 Make_If_Statement (Loc,
7252 Condition => New_Reference_To (B, Loc),
7253 Then_Statements => N_Stats,
7254 Else_Statements => Else_Statements (N)));
7255
7256 -- Generate:
7257 -- <dispatching-call>;
7258 -- <triggering-statements>
7259
7260 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
7261 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
7262
7263 -- Generate:
7264 -- if K = Ada.Tags.TK_Limited_Tagged then
7265 -- Lim_Typ_Stmts
7266 -- else
7267 -- Conc_Typ_Stmts
7268 -- end if;
7269
7270 Append_To (Stmts,
7271 Make_If_Statement (Loc,
7272 Condition =>
7273 Make_Op_Eq (Loc,
7274 Left_Opnd =>
7275 New_Reference_To (K, Loc),
7276 Right_Opnd =>
7277 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
7278
7279 Then_Statements =>
7280 Lim_Typ_Stmts,
7281
7282 Else_Statements =>
7283 Conc_Typ_Stmts));
7284
7285 Rewrite (N,
7286 Make_Block_Statement (Loc,
7287 Declarations =>
7288 Decls,
7289 Handled_Statement_Sequence =>
7290 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7291
7292 -- As described above, The entry alternative is transformed into a
7293 -- block that contains the gnulli call, and possibly assignment
7294 -- statements for in-out parameters. The gnulli call may itself be
7295 -- rewritten into a transient block if some unconstrained parameters
7296 -- require it. We need to retrieve the call to complete its parameter
7297 -- list.
7298
7299 else
7300 Transient_Blk :=
7301 First_Real_Statement (Handled_Statement_Sequence (Blk));
7302
7303 if Present (Transient_Blk)
7304 and then Nkind (Transient_Blk) = N_Block_Statement
7305 then
7306 Blk := Transient_Blk;
7307 end if;
7308
7309 Stmts := Statements (Handled_Statement_Sequence (Blk));
7310 Stmt := First (Stmts);
7311 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7312 Next (Stmt);
7313 end loop;
7314
7315 Call := Stmt;
7316 Params := Parameter_Associations (Call);
7317
7318 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7319
7320 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7321
7322 Param := First (Params);
7323 while Present (Param)
7324 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7325 loop
7326 Next (Param);
7327 end loop;
7328
7329 pragma Assert (Present (Param));
7330 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
7331
7332 Analyze (Param);
7333
7334 -- Find the Communication_Block parameter for the call to the
7335 -- Cancelled function.
7336
7337 Decl := First (Declarations (Blk));
7338 while Present (Decl)
7339 and then not Is_RTE (Etype (Object_Definition (Decl)),
7340 RE_Communication_Block)
7341 loop
7342 Next (Decl);
7343 end loop;
7344
7345 -- Add an if statement to execute the else part if the call
7346 -- does not succeed (as indicated by the Cancelled predicate).
7347
7348 Append_To (Stmts,
7349 Make_Implicit_If_Statement (N,
7350 Condition => Make_Function_Call (Loc,
7351 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
7352 Parameter_Associations => New_List (
7353 New_Reference_To (Defining_Identifier (Decl), Loc))),
7354 Then_Statements => Else_Statements (N),
7355 Else_Statements => Statements (Alt)));
7356
7357 else
7358 B := Make_Defining_Identifier (Loc, Name_uB);
7359
7360 -- Insert declaration of B in declarations of existing block
7361
7362 if No (Declarations (Blk)) then
7363 Set_Declarations (Blk, New_List);
7364 end if;
7365
7366 Prepend_To (Declarations (Blk),
7367 Make_Object_Declaration (Loc,
7368 Defining_Identifier => B,
7369 Object_Definition =>
7370 New_Reference_To (Standard_Boolean, Loc)));
7371
7372 -- Create new call statement
7373
7374 Append_To (Params,
7375 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7376 Append_To (Params, New_Reference_To (B, Loc));
7377
7378 Rewrite (Call,
7379 Make_Procedure_Call_Statement (Loc,
7380 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7381 Parameter_Associations => Params));
7382
7383 -- Construct statement sequence for new block
7384
7385 Append_To (Stmts,
7386 Make_Implicit_If_Statement (N,
7387 Condition => New_Reference_To (B, Loc),
7388 Then_Statements => Statements (Alt),
7389 Else_Statements => Else_Statements (N)));
7390 end if;
7391
7392 -- The result is the new block
7393
7394 Rewrite (N,
7395 Make_Block_Statement (Loc,
7396 Declarations => Declarations (Blk),
7397 Handled_Statement_Sequence =>
7398 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7399 end if;
7400
7401 Analyze (N);
7402 end Expand_N_Conditional_Entry_Call;
7403
7404 ---------------------------------------
7405 -- Expand_N_Delay_Relative_Statement --
7406 ---------------------------------------
7407
7408 -- Delay statement is implemented as a procedure call to Delay_For
7409 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7410 -- simple delays imposed by the use of Protected Objects.
7411
7412 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7413 Loc : constant Source_Ptr := Sloc (N);
7414 begin
7415 Rewrite (N,
7416 Make_Procedure_Call_Statement (Loc,
7417 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7418 Parameter_Associations => New_List (Expression (N))));
7419 Analyze (N);
7420 end Expand_N_Delay_Relative_Statement;
7421
7422 ------------------------------------
7423 -- Expand_N_Delay_Until_Statement --
7424 ------------------------------------
7425
7426 -- Delay Until statement is implemented as a procedure call to
7427 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7428
7429 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7430 Loc : constant Source_Ptr := Sloc (N);
7431 Typ : Entity_Id;
7432
7433 begin
7434 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7435 Typ := RTE (RO_CA_Delay_Until);
7436 else
7437 Typ := RTE (RO_RT_Delay_Until);
7438 end if;
7439
7440 Rewrite (N,
7441 Make_Procedure_Call_Statement (Loc,
7442 Name => New_Reference_To (Typ, Loc),
7443 Parameter_Associations => New_List (Expression (N))));
7444
7445 Analyze (N);
7446 end Expand_N_Delay_Until_Statement;
7447
7448 -------------------------
7449 -- Expand_N_Entry_Body --
7450 -------------------------
7451
7452 procedure Expand_N_Entry_Body (N : Node_Id) is
7453 begin
7454 -- Associate discriminals with the next protected operation body to be
7455 -- expanded.
7456
7457 if Present (Next_Protected_Operation (N)) then
7458 Set_Discriminals (Parent (Current_Scope));
7459 end if;
7460 end Expand_N_Entry_Body;
7461
7462 -----------------------------------
7463 -- Expand_N_Entry_Call_Statement --
7464 -----------------------------------
7465
7466 -- An entry call is expanded into GNARLI calls to implement a simple entry
7467 -- call (see Build_Simple_Entry_Call).
7468
7469 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7470 Concval : Node_Id;
7471 Ename : Node_Id;
7472 Index : Node_Id;
7473
7474 begin
7475 if No_Run_Time_Mode then
7476 Error_Msg_CRT ("entry call", N);
7477 return;
7478 end if;
7479
7480 -- If this entry call is part of an asynchronous select, don't expand it
7481 -- here; it will be expanded with the select statement. Don't expand
7482 -- timed entry calls either, as they are translated into asynchronous
7483 -- entry calls.
7484
7485 -- ??? This whole approach is questionable; it may be better to go back
7486 -- to allowing the expansion to take place and then attempting to fix it
7487 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7488 -- whether the expanded call is on a task or protected entry.
7489
7490 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7491 or else N /= Triggering_Statement (Parent (N)))
7492 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7493 or else N /= Entry_Call_Statement (Parent (N))
7494 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7495 then
7496 Extract_Entry (N, Concval, Ename, Index);
7497 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7498 end if;
7499 end Expand_N_Entry_Call_Statement;
7500
7501 --------------------------------
7502 -- Expand_N_Entry_Declaration --
7503 --------------------------------
7504
7505 -- If there are parameters, then first, each of the formals is marked by
7506 -- setting Is_Entry_Formal. Next a record type is built which is used to
7507 -- hold the parameter values. The name of this record type is entryP where
7508 -- entry is the name of the entry, with an additional corresponding access
7509 -- type called entryPA. The record type has matching components for each
7510 -- formal (the component names are the same as the formal names). For
7511 -- elementary types, the component type matches the formal type. For
7512 -- composite types, an access type is declared (with the name formalA)
7513 -- which designates the formal type, and the type of the component is this
7514 -- access type. Finally the Entry_Component of each formal is set to
7515 -- reference the corresponding record component.
7516
7517 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7518 Loc : constant Source_Ptr := Sloc (N);
7519 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7520 Components : List_Id;
7521 Formal : Node_Id;
7522 Ftype : Entity_Id;
7523 Last_Decl : Node_Id;
7524 Component : Entity_Id;
7525 Ctype : Entity_Id;
7526 Decl : Node_Id;
7527 Rec_Ent : Entity_Id;
7528 Acc_Ent : Entity_Id;
7529
7530 begin
7531 Formal := First_Formal (Entry_Ent);
7532 Last_Decl := N;
7533
7534 -- Most processing is done only if parameters are present
7535
7536 if Present (Formal) then
7537 Components := New_List;
7538
7539 -- Loop through formals
7540
7541 while Present (Formal) loop
7542 Set_Is_Entry_Formal (Formal);
7543 Component :=
7544 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7545 Set_Entry_Component (Formal, Component);
7546 Set_Entry_Formal (Component, Formal);
7547 Ftype := Etype (Formal);
7548
7549 -- Declare new access type and then append
7550
7551 Ctype := Make_Temporary (Loc, 'A');
7552
7553 Decl :=
7554 Make_Full_Type_Declaration (Loc,
7555 Defining_Identifier => Ctype,
7556 Type_Definition =>
7557 Make_Access_To_Object_Definition (Loc,
7558 All_Present => True,
7559 Constant_Present => Ekind (Formal) = E_In_Parameter,
7560 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7561
7562 Insert_After (Last_Decl, Decl);
7563 Last_Decl := Decl;
7564
7565 Append_To (Components,
7566 Make_Component_Declaration (Loc,
7567 Defining_Identifier => Component,
7568 Component_Definition =>
7569 Make_Component_Definition (Loc,
7570 Aliased_Present => False,
7571 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7572
7573 Next_Formal_With_Extras (Formal);
7574 end loop;
7575
7576 -- Create the Entry_Parameter_Record declaration
7577
7578 Rec_Ent := Make_Temporary (Loc, 'P');
7579
7580 Decl :=
7581 Make_Full_Type_Declaration (Loc,
7582 Defining_Identifier => Rec_Ent,
7583 Type_Definition =>
7584 Make_Record_Definition (Loc,
7585 Component_List =>
7586 Make_Component_List (Loc,
7587 Component_Items => Components)));
7588
7589 Insert_After (Last_Decl, Decl);
7590 Last_Decl := Decl;
7591
7592 -- Construct and link in the corresponding access type
7593
7594 Acc_Ent := Make_Temporary (Loc, 'A');
7595
7596 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7597
7598 Decl :=
7599 Make_Full_Type_Declaration (Loc,
7600 Defining_Identifier => Acc_Ent,
7601 Type_Definition =>
7602 Make_Access_To_Object_Definition (Loc,
7603 All_Present => True,
7604 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7605
7606 Insert_After (Last_Decl, Decl);
7607 end if;
7608 end Expand_N_Entry_Declaration;
7609
7610 -----------------------------
7611 -- Expand_N_Protected_Body --
7612 -----------------------------
7613
7614 -- Protected bodies are expanded to the completion of the subprograms
7615 -- created for the corresponding protected type. These are a protected and
7616 -- unprotected version of each protected subprogram in the object, a
7617 -- function to calculate each entry barrier, and a procedure to execute the
7618 -- sequence of statements of each protected entry body. For example, for
7619 -- protected type ptype:
7620
7621 -- function entB
7622 -- (O : System.Address;
7623 -- E : Protected_Entry_Index)
7624 -- return Boolean
7625 -- is
7626 -- <discriminant renamings>
7627 -- <private object renamings>
7628 -- begin
7629 -- return <barrier expression>;
7630 -- end entB;
7631
7632 -- procedure pprocN (_object : in out poV;...) is
7633 -- <discriminant renamings>
7634 -- <private object renamings>
7635 -- begin
7636 -- <sequence of statements>
7637 -- end pprocN;
7638
7639 -- procedure pprocP (_object : in out poV;...) is
7640 -- procedure _clean is
7641 -- Pn : Boolean;
7642 -- begin
7643 -- ptypeS (_object, Pn);
7644 -- Unlock (_object._object'Access);
7645 -- Abort_Undefer.all;
7646 -- end _clean;
7647
7648 -- begin
7649 -- Abort_Defer.all;
7650 -- Lock (_object._object'Access);
7651 -- pprocN (_object;...);
7652 -- at end
7653 -- _clean;
7654 -- end pproc;
7655
7656 -- function pfuncN (_object : poV;...) return Return_Type is
7657 -- <discriminant renamings>
7658 -- <private object renamings>
7659 -- begin
7660 -- <sequence of statements>
7661 -- end pfuncN;
7662
7663 -- function pfuncP (_object : poV) return Return_Type is
7664 -- procedure _clean is
7665 -- begin
7666 -- Unlock (_object._object'Access);
7667 -- Abort_Undefer.all;
7668 -- end _clean;
7669
7670 -- begin
7671 -- Abort_Defer.all;
7672 -- Lock (_object._object'Access);
7673 -- return pfuncN (_object);
7674
7675 -- at end
7676 -- _clean;
7677 -- end pfunc;
7678
7679 -- procedure entE
7680 -- (O : System.Address;
7681 -- P : System.Address;
7682 -- E : Protected_Entry_Index)
7683 -- is
7684 -- <discriminant renamings>
7685 -- <private object renamings>
7686 -- type poVP is access poV;
7687 -- _Object : ptVP := ptVP!(O);
7688
7689 -- begin
7690 -- begin
7691 -- <statement sequence>
7692 -- Complete_Entry_Body (_Object._Object);
7693 -- exception
7694 -- when all others =>
7695 -- Exceptional_Complete_Entry_Body (
7696 -- _Object._Object, Get_GNAT_Exception);
7697 -- end;
7698 -- end entE;
7699
7700 -- The type poV is the record created for the protected type to hold
7701 -- the state of the protected object.
7702
7703 procedure Expand_N_Protected_Body (N : Node_Id) is
7704 Loc : constant Source_Ptr := Sloc (N);
7705 Pid : constant Entity_Id := Corresponding_Spec (N);
7706
7707 Current_Node : Node_Id;
7708 Disp_Op_Body : Node_Id;
7709 New_Op_Body : Node_Id;
7710 Num_Entries : Natural := 0;
7711 Op_Body : Node_Id;
7712 Op_Id : Entity_Id;
7713
7714 function Build_Dispatching_Subprogram_Body
7715 (N : Node_Id;
7716 Pid : Node_Id;
7717 Prot_Bod : Node_Id) return Node_Id;
7718 -- Build a dispatching version of the protected subprogram body. The
7719 -- newly generated subprogram contains a call to the original protected
7720 -- body. The following code is generated:
7721 --
7722 -- function <protected-function-name> (Param1 .. ParamN) return
7723 -- <return-type> is
7724 -- begin
7725 -- return <protected-function-name>P (Param1 .. ParamN);
7726 -- end <protected-function-name>;
7727 --
7728 -- or
7729 --
7730 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7731 -- begin
7732 -- <protected-procedure-name>P (Param1 .. ParamN);
7733 -- end <protected-procedure-name>
7734
7735 ---------------------------------------
7736 -- Build_Dispatching_Subprogram_Body --
7737 ---------------------------------------
7738
7739 function Build_Dispatching_Subprogram_Body
7740 (N : Node_Id;
7741 Pid : Node_Id;
7742 Prot_Bod : Node_Id) return Node_Id
7743 is
7744 Loc : constant Source_Ptr := Sloc (N);
7745 Actuals : List_Id;
7746 Formal : Node_Id;
7747 Spec : Node_Id;
7748 Stmts : List_Id;
7749
7750 begin
7751 -- Generate a specification without a letter suffix in order to
7752 -- override an interface function or procedure.
7753
7754 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7755
7756 -- The formal parameters become the actuals of the protected function
7757 -- or procedure call.
7758
7759 Actuals := New_List;
7760 Formal := First (Parameter_Specifications (Spec));
7761 while Present (Formal) loop
7762 Append_To (Actuals,
7763 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7764
7765 Next (Formal);
7766 end loop;
7767
7768 if Nkind (Spec) = N_Procedure_Specification then
7769 Stmts :=
7770 New_List (
7771 Make_Procedure_Call_Statement (Loc,
7772 Name =>
7773 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7774 Parameter_Associations => Actuals));
7775 else
7776 pragma Assert (Nkind (Spec) = N_Function_Specification);
7777
7778 Stmts :=
7779 New_List (
7780 Make_Simple_Return_Statement (Loc,
7781 Expression =>
7782 Make_Function_Call (Loc,
7783 Name =>
7784 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7785 Parameter_Associations => Actuals)));
7786 end if;
7787
7788 return
7789 Make_Subprogram_Body (Loc,
7790 Declarations => Empty_List,
7791 Specification => Spec,
7792 Handled_Statement_Sequence =>
7793 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7794 end Build_Dispatching_Subprogram_Body;
7795
7796 -- Start of processing for Expand_N_Protected_Body
7797
7798 begin
7799 if No_Run_Time_Mode then
7800 Error_Msg_CRT ("protected body", N);
7801 return;
7802 end if;
7803
7804 -- This is the proper body corresponding to a stub. The declarations
7805 -- must be inserted at the point of the stub, which in turn is in the
7806 -- declarative part of the parent unit.
7807
7808 if Nkind (Parent (N)) = N_Subunit then
7809 Current_Node := Corresponding_Stub (Parent (N));
7810 else
7811 Current_Node := N;
7812 end if;
7813
7814 Op_Body := First (Declarations (N));
7815
7816 -- The protected body is replaced with the bodies of its
7817 -- protected operations, and the declarations for internal objects
7818 -- that may have been created for entry family bounds.
7819
7820 Rewrite (N, Make_Null_Statement (Sloc (N)));
7821 Analyze (N);
7822
7823 while Present (Op_Body) loop
7824 case Nkind (Op_Body) is
7825 when N_Subprogram_Declaration =>
7826 null;
7827
7828 when N_Subprogram_Body =>
7829
7830 -- Do not create bodies for eliminated operations
7831
7832 if not Is_Eliminated (Defining_Entity (Op_Body))
7833 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7834 then
7835 New_Op_Body :=
7836 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7837
7838 Insert_After (Current_Node, New_Op_Body);
7839 Current_Node := New_Op_Body;
7840 Analyze (New_Op_Body);
7841
7842 -- Build the corresponding protected operation. It may
7843 -- appear that this is needed only if this is a visible
7844 -- operation of the type, or if it is an interrupt handler,
7845 -- and this was the strategy used previously in GNAT.
7846 -- However, the operation may be exported through a 'Access
7847 -- to an external caller. This is the common idiom in code
7848 -- that uses the Ada 2005 Timing_Events package. As a result
7849 -- we need to produce the protected body for both visible
7850 -- and private operations, as well as operations that only
7851 -- have a body in the source, and for which we create a
7852 -- declaration in the protected body itself.
7853
7854 if Present (Corresponding_Spec (Op_Body)) then
7855 New_Op_Body :=
7856 Build_Protected_Subprogram_Body (
7857 Op_Body, Pid, Specification (New_Op_Body));
7858
7859 Insert_After (Current_Node, New_Op_Body);
7860 Analyze (New_Op_Body);
7861
7862 Current_Node := New_Op_Body;
7863
7864 -- Generate an overriding primitive operation body for
7865 -- this subprogram if the protected type implements an
7866 -- interface.
7867
7868 if Ada_Version >= Ada_2005
7869 and then
7870 Present (Interfaces (Corresponding_Record_Type (Pid)))
7871 then
7872 Disp_Op_Body :=
7873 Build_Dispatching_Subprogram_Body
7874 (Op_Body, Pid, New_Op_Body);
7875
7876 Insert_After (Current_Node, Disp_Op_Body);
7877 Analyze (Disp_Op_Body);
7878
7879 Current_Node := Disp_Op_Body;
7880 end if;
7881 end if;
7882 end if;
7883
7884 when N_Entry_Body =>
7885 Op_Id := Defining_Identifier (Op_Body);
7886 Num_Entries := Num_Entries + 1;
7887
7888 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7889
7890 Insert_After (Current_Node, New_Op_Body);
7891 Current_Node := New_Op_Body;
7892 Analyze (New_Op_Body);
7893
7894 when N_Implicit_Label_Declaration =>
7895 null;
7896
7897 when N_Itype_Reference =>
7898 Insert_After (Current_Node, New_Copy (Op_Body));
7899
7900 when N_Freeze_Entity =>
7901 New_Op_Body := New_Copy (Op_Body);
7902
7903 if Present (Entity (Op_Body))
7904 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7905 then
7906 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7907 end if;
7908
7909 Insert_After (Current_Node, New_Op_Body);
7910 Current_Node := New_Op_Body;
7911 Analyze (New_Op_Body);
7912
7913 when N_Pragma =>
7914 New_Op_Body := New_Copy (Op_Body);
7915 Insert_After (Current_Node, New_Op_Body);
7916 Current_Node := New_Op_Body;
7917 Analyze (New_Op_Body);
7918
7919 when N_Object_Declaration =>
7920 pragma Assert (not Comes_From_Source (Op_Body));
7921 New_Op_Body := New_Copy (Op_Body);
7922 Insert_After (Current_Node, New_Op_Body);
7923 Current_Node := New_Op_Body;
7924 Analyze (New_Op_Body);
7925
7926 when others =>
7927 raise Program_Error;
7928
7929 end case;
7930
7931 Next (Op_Body);
7932 end loop;
7933
7934 -- Finally, create the body of the function that maps an entry index
7935 -- into the corresponding body index, except when there is no entry, or
7936 -- in a Ravenscar-like profile.
7937
7938 if Corresponding_Runtime_Package (Pid) =
7939 System_Tasking_Protected_Objects_Entries
7940 then
7941 New_Op_Body := Build_Find_Body_Index (Pid);
7942 Insert_After (Current_Node, New_Op_Body);
7943 Current_Node := New_Op_Body;
7944 Analyze (New_Op_Body);
7945 end if;
7946
7947 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7948 -- protected body. At this point all wrapper specs have been created,
7949 -- frozen and included in the dispatch table for the protected type.
7950
7951 if Ada_Version >= Ada_2005 then
7952 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7953 end if;
7954 end Expand_N_Protected_Body;
7955
7956 -----------------------------------------
7957 -- Expand_N_Protected_Type_Declaration --
7958 -----------------------------------------
7959
7960 -- First we create a corresponding record type declaration used to
7961 -- represent values of this protected type.
7962 -- The general form of this type declaration is
7963
7964 -- type poV (discriminants) is record
7965 -- _Object : aliased <kind>Protection
7966 -- [(<entry count> [, <handler count>])];
7967 -- [entry_family : array (bounds) of Void;]
7968 -- <private data fields>
7969 -- end record;
7970
7971 -- The discriminants are present only if the corresponding protected type
7972 -- has discriminants, and they exactly mirror the protected type
7973 -- discriminants. The private data fields similarly mirror the private
7974 -- declarations of the protected type.
7975
7976 -- The Object field is always present. It contains RTS specific data used
7977 -- to control the protected object. It is declared as Aliased so that it
7978 -- can be passed as a pointer to the RTS. This allows the protected record
7979 -- to be referenced within RTS data structures. An appropriate Protection
7980 -- type and discriminant are generated.
7981
7982 -- The Service field is present for protected objects with entries. It
7983 -- contains sufficient information to allow the entry service procedure for
7984 -- this object to be called when the object is not known till runtime.
7985
7986 -- One entry_family component is present for each entry family in the
7987 -- task definition (see Expand_N_Task_Type_Declaration).
7988
7989 -- When a protected object is declared, an instance of the protected type
7990 -- value record is created. The elaboration of this declaration creates the
7991 -- correct bounds for the entry families, and also evaluates the priority
7992 -- expression if needed. The initialization routine for the protected type
7993 -- itself then calls Initialize_Protection with appropriate parameters to
7994 -- initialize the value of the Task_Id field. Install_Handlers may be also
7995 -- called if a pragma Attach_Handler applies.
7996
7997 -- Note: this record is passed to the subprograms created by the expansion
7998 -- of protected subprograms and entries. It is an in parameter to protected
7999 -- functions and an in out parameter to procedures and entry bodies. The
8000 -- Entity_Id for this created record type is placed in the
8001 -- Corresponding_Record_Type field of the associated protected type entity.
8002
8003 -- Next we create a procedure specifications for protected subprograms and
8004 -- entry bodies. For each protected subprograms two subprograms are
8005 -- created, an unprotected and a protected version. The unprotected version
8006 -- is called from within other operations of the same protected object.
8007
8008 -- We also build the call to register the procedure if a pragma
8009 -- Interrupt_Handler applies.
8010
8011 -- A single subprogram is created to service all entry bodies; it has an
8012 -- additional boolean out parameter indicating that the previous entry call
8013 -- made by the current task was serviced immediately, i.e. not by proxy.
8014 -- The O parameter contains a pointer to a record object of the type
8015 -- described above. An untyped interface is used here to allow this
8016 -- procedure to be called in places where the type of the object to be
8017 -- serviced is not known. This must be done, for example, when a call that
8018 -- may have been requeued is cancelled; the corresponding object must be
8019 -- serviced, but which object that is not known till runtime.
8020
8021 -- procedure ptypeS
8022 -- (O : System.Address; P : out Boolean);
8023 -- procedure pprocN (_object : in out poV);
8024 -- procedure pproc (_object : in out poV);
8025 -- function pfuncN (_object : poV);
8026 -- function pfunc (_object : poV);
8027 -- ...
8028
8029 -- Note that this must come after the record type declaration, since
8030 -- the specs refer to this type.
8031
8032 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
8033 Loc : constant Source_Ptr := Sloc (N);
8034 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
8035
8036 Pdef : constant Node_Id := Protected_Definition (N);
8037 -- This contains two lists; one for visible and one for private decls
8038
8039 Rec_Decl : Node_Id;
8040 Cdecls : List_Id;
8041 Discr_Map : constant Elist_Id := New_Elmt_List;
8042 Priv : Node_Id;
8043 New_Priv : Node_Id;
8044 Comp : Node_Id;
8045 Comp_Id : Entity_Id;
8046 Sub : Node_Id;
8047 Current_Node : Node_Id := N;
8048 Bdef : Entity_Id := Empty; -- avoid uninit warning
8049 Edef : Entity_Id := Empty; -- avoid uninit warning
8050 Entries_Aggr : Node_Id;
8051 Body_Id : Entity_Id;
8052 Body_Arr : Node_Id;
8053 E_Count : Int;
8054 Object_Comp : Node_Id;
8055
8056 procedure Check_Inlining (Subp : Entity_Id);
8057 -- If the original operation has a pragma Inline, propagate the flag
8058 -- to the internal body, for possible inlining later on. The source
8059 -- operation is invisible to the back-end and is never actually called.
8060
8061 function Static_Component_Size (Comp : Entity_Id) return Boolean;
8062 -- When compiling under the Ravenscar profile, private components must
8063 -- have a static size, or else a protected object will require heap
8064 -- allocation, violating the corresponding restriction. It is preferable
8065 -- to make this check here, because it provides a better error message
8066 -- than the back-end, which refers to the object as a whole.
8067
8068 procedure Register_Handler;
8069 -- For a protected operation that is an interrupt handler, add the
8070 -- freeze action that will register it as such.
8071
8072 --------------------
8073 -- Check_Inlining --
8074 --------------------
8075
8076 procedure Check_Inlining (Subp : Entity_Id) is
8077 begin
8078 if Is_Inlined (Subp) then
8079 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8080 Set_Is_Inlined (Subp, False);
8081 end if;
8082 end Check_Inlining;
8083
8084 ---------------------------------
8085 -- Check_Static_Component_Size --
8086 ---------------------------------
8087
8088 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8089 Typ : constant Entity_Id := Etype (Comp);
8090 C : Entity_Id;
8091
8092 begin
8093 if Is_Scalar_Type (Typ) then
8094 return True;
8095
8096 elsif Is_Array_Type (Typ) then
8097 return Compile_Time_Known_Bounds (Typ);
8098
8099 elsif Is_Record_Type (Typ) then
8100 C := First_Component (Typ);
8101 while Present (C) loop
8102 if not Static_Component_Size (C) then
8103 return False;
8104 end if;
8105
8106 Next_Component (C);
8107 end loop;
8108
8109 return True;
8110
8111 -- Any other types will be checked by the back-end
8112
8113 else
8114 return True;
8115 end if;
8116 end Static_Component_Size;
8117
8118 ----------------------
8119 -- Register_Handler --
8120 ----------------------
8121
8122 procedure Register_Handler is
8123
8124 -- All semantic checks already done in Sem_Prag
8125
8126 Prot_Proc : constant Entity_Id :=
8127 Defining_Unit_Name
8128 (Specification (Current_Node));
8129
8130 Proc_Address : constant Node_Id :=
8131 Make_Attribute_Reference (Loc,
8132 Prefix => New_Reference_To (Prot_Proc, Loc),
8133 Attribute_Name => Name_Address);
8134
8135 RTS_Call : constant Entity_Id :=
8136 Make_Procedure_Call_Statement (Loc,
8137 Name =>
8138 New_Reference_To (
8139 RTE (RE_Register_Interrupt_Handler), Loc),
8140 Parameter_Associations =>
8141 New_List (Proc_Address));
8142 begin
8143 Append_Freeze_Action (Prot_Proc, RTS_Call);
8144 end Register_Handler;
8145
8146 -- Start of processing for Expand_N_Protected_Type_Declaration
8147
8148 begin
8149 if Present (Corresponding_Record_Type (Prot_Typ)) then
8150 return;
8151 else
8152 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
8153 end if;
8154
8155 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
8156
8157 Qualify_Entity_Names (N);
8158
8159 -- If the type has discriminants, their occurrences in the declaration
8160 -- have been replaced by the corresponding discriminals. For components
8161 -- that are constrained by discriminants, their homologues in the
8162 -- corresponding record type must refer to the discriminants of that
8163 -- record, so we must apply a new renaming to subtypes_indications:
8164
8165 -- protected discriminant => discriminal => record discriminant
8166
8167 -- This replacement is not applied to default expressions, for which
8168 -- the discriminal is correct.
8169
8170 if Has_Discriminants (Prot_Typ) then
8171 declare
8172 Disc : Entity_Id;
8173 Decl : Node_Id;
8174
8175 begin
8176 Disc := First_Discriminant (Prot_Typ);
8177 Decl := First (Discriminant_Specifications (Rec_Decl));
8178 while Present (Disc) loop
8179 Append_Elmt (Discriminal (Disc), Discr_Map);
8180 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
8181 Next_Discriminant (Disc);
8182 Next (Decl);
8183 end loop;
8184 end;
8185 end if;
8186
8187 -- Fill in the component declarations
8188
8189 -- Add components for entry families. For each entry family, create an
8190 -- anonymous type declaration with the same size, and analyze the type.
8191
8192 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
8193
8194 -- Prepend the _Object field with the right type to the component list.
8195 -- We need to compute the number of entries, and in some cases the
8196 -- number of Attach_Handler pragmas.
8197
8198 declare
8199 Ritem : Node_Id;
8200 Num_Attach_Handler : Int := 0;
8201 Protection_Subtype : Node_Id;
8202 Entry_Count_Expr : constant Node_Id :=
8203 Build_Entry_Count_Expression
8204 (Prot_Typ, Cdecls, Loc);
8205
8206 begin
8207 -- Could this be simplified using Corresponding_Runtime_Package???
8208
8209 if Has_Attach_Handler (Prot_Typ) then
8210 Ritem := First_Rep_Item (Prot_Typ);
8211 while Present (Ritem) loop
8212 if Nkind (Ritem) = N_Pragma
8213 and then Pragma_Name (Ritem) = Name_Attach_Handler
8214 then
8215 Num_Attach_Handler := Num_Attach_Handler + 1;
8216 end if;
8217
8218 Next_Rep_Item (Ritem);
8219 end loop;
8220
8221 if Restricted_Profile then
8222 if Has_Entries (Prot_Typ) then
8223 Protection_Subtype :=
8224 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8225 else
8226 Protection_Subtype :=
8227 New_Reference_To (RTE (RE_Protection), Loc);
8228 end if;
8229 else
8230 Protection_Subtype :=
8231 Make_Subtype_Indication
8232 (Sloc => Loc,
8233 Subtype_Mark =>
8234 New_Reference_To
8235 (RTE (RE_Static_Interrupt_Protection), Loc),
8236 Constraint =>
8237 Make_Index_Or_Discriminant_Constraint (
8238 Sloc => Loc,
8239 Constraints => New_List (
8240 Entry_Count_Expr,
8241 Make_Integer_Literal (Loc, Num_Attach_Handler))));
8242 end if;
8243
8244 elsif Has_Interrupt_Handler (Prot_Typ)
8245 and then not Restriction_Active (No_Dynamic_Attachment)
8246 then
8247 Protection_Subtype :=
8248 Make_Subtype_Indication (
8249 Sloc => Loc,
8250 Subtype_Mark => New_Reference_To
8251 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
8252 Constraint =>
8253 Make_Index_Or_Discriminant_Constraint (
8254 Sloc => Loc,
8255 Constraints => New_List (Entry_Count_Expr)));
8256
8257 -- Type has explicit entries or generated primitive entry wrappers
8258
8259 elsif Has_Entries (Prot_Typ)
8260 or else (Ada_Version >= Ada_2005
8261 and then Present (Interface_List (N)))
8262 then
8263 case Corresponding_Runtime_Package (Prot_Typ) is
8264 when System_Tasking_Protected_Objects_Entries =>
8265 Protection_Subtype :=
8266 Make_Subtype_Indication (Loc,
8267 Subtype_Mark =>
8268 New_Reference_To (RTE (RE_Protection_Entries), Loc),
8269 Constraint =>
8270 Make_Index_Or_Discriminant_Constraint (
8271 Sloc => Loc,
8272 Constraints => New_List (Entry_Count_Expr)));
8273
8274 when System_Tasking_Protected_Objects_Single_Entry =>
8275 Protection_Subtype :=
8276 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8277
8278 when others =>
8279 raise Program_Error;
8280 end case;
8281
8282 else
8283 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
8284 end if;
8285
8286 Object_Comp :=
8287 Make_Component_Declaration (Loc,
8288 Defining_Identifier =>
8289 Make_Defining_Identifier (Loc, Name_uObject),
8290 Component_Definition =>
8291 Make_Component_Definition (Loc,
8292 Aliased_Present => True,
8293 Subtype_Indication => Protection_Subtype));
8294 end;
8295
8296 pragma Assert (Present (Pdef));
8297
8298 -- Add private field components
8299
8300 if Present (Private_Declarations (Pdef)) then
8301 Priv := First (Private_Declarations (Pdef));
8302
8303 while Present (Priv) loop
8304
8305 if Nkind (Priv) = N_Component_Declaration then
8306 if not Static_Component_Size (Defining_Identifier (Priv)) then
8307
8308 -- When compiling for a restricted profile, the private
8309 -- components must have a static size. If not, this is an
8310 -- error for a single protected declaration, and rates a
8311 -- warning on a protected type declaration.
8312
8313 if not Comes_From_Source (Prot_Typ) then
8314 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8315
8316 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8317 Error_Msg_N ("component has non-static size?", Priv);
8318 Error_Msg_NE
8319 ("\creation of protected object of type& will violate"
8320 & " restriction No_Implicit_Heap_Allocations?",
8321 Priv, Prot_Typ);
8322 end if;
8323 end if;
8324
8325 -- The component definition consists of a subtype indication,
8326 -- or (in Ada 2005) an access definition. Make a copy of the
8327 -- proper definition.
8328
8329 declare
8330 Old_Comp : constant Node_Id := Component_Definition (Priv);
8331 Oent : constant Entity_Id := Defining_Identifier (Priv);
8332 New_Comp : Node_Id;
8333 Nent : constant Entity_Id :=
8334 Make_Defining_Identifier (Sloc (Oent),
8335 Chars => Chars (Oent));
8336
8337 begin
8338 if Present (Subtype_Indication (Old_Comp)) then
8339 New_Comp :=
8340 Make_Component_Definition (Sloc (Oent),
8341 Aliased_Present => False,
8342 Subtype_Indication =>
8343 New_Copy_Tree (Subtype_Indication (Old_Comp),
8344 Discr_Map));
8345 else
8346 New_Comp :=
8347 Make_Component_Definition (Sloc (Oent),
8348 Aliased_Present => False,
8349 Access_Definition =>
8350 New_Copy_Tree (Access_Definition (Old_Comp),
8351 Discr_Map));
8352 end if;
8353
8354 New_Priv :=
8355 Make_Component_Declaration (Loc,
8356 Defining_Identifier => Nent,
8357 Component_Definition => New_Comp,
8358 Expression => Expression (Priv));
8359
8360 Set_Has_Per_Object_Constraint (Nent,
8361 Has_Per_Object_Constraint (Oent));
8362
8363 Append_To (Cdecls, New_Priv);
8364 end;
8365
8366 elsif Nkind (Priv) = N_Subprogram_Declaration then
8367
8368 -- Make the unprotected version of the subprogram available
8369 -- for expansion of intra object calls. There is need for
8370 -- a protected version only if the subprogram is an interrupt
8371 -- handler, otherwise this operation can only be called from
8372 -- within the body.
8373
8374 Sub :=
8375 Make_Subprogram_Declaration (Loc,
8376 Specification =>
8377 Build_Protected_Sub_Specification
8378 (Priv, Prot_Typ, Unprotected_Mode));
8379
8380 Insert_After (Current_Node, Sub);
8381 Analyze (Sub);
8382
8383 Set_Protected_Body_Subprogram
8384 (Defining_Unit_Name (Specification (Priv)),
8385 Defining_Unit_Name (Specification (Sub)));
8386 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8387 Current_Node := Sub;
8388
8389 Sub :=
8390 Make_Subprogram_Declaration (Loc,
8391 Specification =>
8392 Build_Protected_Sub_Specification
8393 (Priv, Prot_Typ, Protected_Mode));
8394
8395 Insert_After (Current_Node, Sub);
8396 Analyze (Sub);
8397 Current_Node := Sub;
8398
8399 if Is_Interrupt_Handler
8400 (Defining_Unit_Name (Specification (Priv)))
8401 then
8402 if not Restricted_Profile then
8403 Register_Handler;
8404 end if;
8405 end if;
8406 end if;
8407
8408 Next (Priv);
8409 end loop;
8410 end if;
8411
8412 -- Put the _Object component after the private component so that it
8413 -- be finalized early as required by 9.4 (20)
8414
8415 Append_To (Cdecls, Object_Comp);
8416
8417 Insert_After (Current_Node, Rec_Decl);
8418 Current_Node := Rec_Decl;
8419
8420 -- Analyze the record declaration immediately after construction,
8421 -- because the initialization procedure is needed for single object
8422 -- declarations before the next entity is analyzed (the freeze call
8423 -- that generates this initialization procedure is found below).
8424
8425 Analyze (Rec_Decl, Suppress => All_Checks);
8426
8427 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8428 -- the corresponding record is frozen. If any wrappers are generated,
8429 -- Current_Node is updated accordingly.
8430
8431 if Ada_Version >= Ada_2005 then
8432 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8433 end if;
8434
8435 -- Collect pointers to entry bodies and their barriers, to be placed
8436 -- in the Entry_Bodies_Array for the type. For each entry/family we
8437 -- add an expression to the aggregate which is the initial value of
8438 -- this array. The array is declared after all protected subprograms.
8439
8440 if Has_Entries (Prot_Typ) then
8441 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8442 else
8443 Entries_Aggr := Empty;
8444 end if;
8445
8446 -- Build two new procedure specifications for each protected subprogram;
8447 -- one to call from outside the object and one to call from inside.
8448 -- Build a barrier function and an entry body action procedure
8449 -- specification for each protected entry. Initialize the entry body
8450 -- array. If subprogram is flagged as eliminated, do not generate any
8451 -- internal operations.
8452
8453 E_Count := 0;
8454
8455 Comp := First (Visible_Declarations (Pdef));
8456
8457 while Present (Comp) loop
8458 if Nkind (Comp) = N_Subprogram_Declaration then
8459 Sub :=
8460 Make_Subprogram_Declaration (Loc,
8461 Specification =>
8462 Build_Protected_Sub_Specification
8463 (Comp, Prot_Typ, Unprotected_Mode));
8464
8465 Insert_After (Current_Node, Sub);
8466 Analyze (Sub);
8467
8468 Set_Protected_Body_Subprogram
8469 (Defining_Unit_Name (Specification (Comp)),
8470 Defining_Unit_Name (Specification (Sub)));
8471 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8472
8473 -- Make the protected version of the subprogram available for
8474 -- expansion of external calls.
8475
8476 Current_Node := Sub;
8477
8478 Sub :=
8479 Make_Subprogram_Declaration (Loc,
8480 Specification =>
8481 Build_Protected_Sub_Specification
8482 (Comp, Prot_Typ, Protected_Mode));
8483
8484 Insert_After (Current_Node, Sub);
8485 Analyze (Sub);
8486
8487 Current_Node := Sub;
8488
8489 -- Generate an overriding primitive operation specification for
8490 -- this subprogram if the protected type implements an interface.
8491
8492 if Ada_Version >= Ada_2005
8493 and then
8494 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8495 then
8496 Sub :=
8497 Make_Subprogram_Declaration (Loc,
8498 Specification =>
8499 Build_Protected_Sub_Specification
8500 (Comp, Prot_Typ, Dispatching_Mode));
8501
8502 Insert_After (Current_Node, Sub);
8503 Analyze (Sub);
8504
8505 Current_Node := Sub;
8506 end if;
8507
8508 -- If a pragma Interrupt_Handler applies, build and add a call to
8509 -- Register_Interrupt_Handler to the freezing actions of the
8510 -- protected version (Current_Node) of the subprogram:
8511
8512 -- system.interrupts.register_interrupt_handler
8513 -- (prot_procP'address);
8514
8515 if not Restricted_Profile
8516 and then Is_Interrupt_Handler
8517 (Defining_Unit_Name (Specification (Comp)))
8518 then
8519 Register_Handler;
8520 end if;
8521
8522 elsif Nkind (Comp) = N_Entry_Declaration then
8523 E_Count := E_Count + 1;
8524 Comp_Id := Defining_Identifier (Comp);
8525
8526 Edef :=
8527 Make_Defining_Identifier (Loc,
8528 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8529 Sub :=
8530 Make_Subprogram_Declaration (Loc,
8531 Specification =>
8532 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8533
8534 Insert_After (Current_Node, Sub);
8535 Analyze (Sub);
8536
8537 -- Build wrapper procedure for pre/postconditions
8538
8539 Build_PPC_Wrapper (Comp_Id, N);
8540
8541 Set_Protected_Body_Subprogram
8542 (Defining_Identifier (Comp),
8543 Defining_Unit_Name (Specification (Sub)));
8544
8545 Current_Node := Sub;
8546
8547 Bdef :=
8548 Make_Defining_Identifier (Loc,
8549 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8550 Sub :=
8551 Make_Subprogram_Declaration (Loc,
8552 Specification =>
8553 Build_Barrier_Function_Specification (Loc, Bdef));
8554
8555 Insert_After (Current_Node, Sub);
8556 Analyze (Sub);
8557 Set_Protected_Body_Subprogram (Bdef, Bdef);
8558 Set_Barrier_Function (Comp_Id, Bdef);
8559 Set_Scope (Bdef, Scope (Comp_Id));
8560 Current_Node := Sub;
8561
8562 -- Collect pointers to the protected subprogram and the barrier
8563 -- of the current entry, for insertion into Entry_Bodies_Array.
8564
8565 Append (
8566 Make_Aggregate (Loc,
8567 Expressions => New_List (
8568 Make_Attribute_Reference (Loc,
8569 Prefix => New_Reference_To (Bdef, Loc),
8570 Attribute_Name => Name_Unrestricted_Access),
8571 Make_Attribute_Reference (Loc,
8572 Prefix => New_Reference_To (Edef, Loc),
8573 Attribute_Name => Name_Unrestricted_Access))),
8574 Expressions (Entries_Aggr));
8575
8576 end if;
8577
8578 Next (Comp);
8579 end loop;
8580
8581 -- If there are some private entry declarations, expand it as if they
8582 -- were visible entries.
8583
8584 if Present (Private_Declarations (Pdef)) then
8585 Comp := First (Private_Declarations (Pdef));
8586 while Present (Comp) loop
8587 if Nkind (Comp) = N_Entry_Declaration then
8588 E_Count := E_Count + 1;
8589 Comp_Id := Defining_Identifier (Comp);
8590
8591 Edef :=
8592 Make_Defining_Identifier (Loc,
8593 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8594 Sub :=
8595 Make_Subprogram_Declaration (Loc,
8596 Specification =>
8597 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8598
8599 Insert_After (Current_Node, Sub);
8600 Analyze (Sub);
8601
8602 Set_Protected_Body_Subprogram
8603 (Defining_Identifier (Comp),
8604 Defining_Unit_Name (Specification (Sub)));
8605
8606 Current_Node := Sub;
8607
8608 Bdef :=
8609 Make_Defining_Identifier (Loc,
8610 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8611
8612 Sub :=
8613 Make_Subprogram_Declaration (Loc,
8614 Specification =>
8615 Build_Barrier_Function_Specification (Loc, Bdef));
8616
8617 Insert_After (Current_Node, Sub);
8618 Analyze (Sub);
8619 Set_Protected_Body_Subprogram (Bdef, Bdef);
8620 Set_Barrier_Function (Comp_Id, Bdef);
8621 Set_Scope (Bdef, Scope (Comp_Id));
8622 Current_Node := Sub;
8623
8624 -- Collect pointers to the protected subprogram and the barrier
8625 -- of the current entry, for insertion into Entry_Bodies_Array.
8626
8627 Append_To (Expressions (Entries_Aggr),
8628 Make_Aggregate (Loc,
8629 Expressions => New_List (
8630 Make_Attribute_Reference (Loc,
8631 Prefix => New_Reference_To (Bdef, Loc),
8632 Attribute_Name => Name_Unrestricted_Access),
8633 Make_Attribute_Reference (Loc,
8634 Prefix => New_Reference_To (Edef, Loc),
8635 Attribute_Name => Name_Unrestricted_Access))));
8636 end if;
8637
8638 Next (Comp);
8639 end loop;
8640 end if;
8641
8642 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8643 -- all protected subprograms have been collected.
8644
8645 if Has_Entries (Prot_Typ) then
8646 Body_Id :=
8647 Make_Defining_Identifier (Sloc (Prot_Typ),
8648 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8649
8650 case Corresponding_Runtime_Package (Prot_Typ) is
8651 when System_Tasking_Protected_Objects_Entries =>
8652 Body_Arr := Make_Object_Declaration (Loc,
8653 Defining_Identifier => Body_Id,
8654 Aliased_Present => True,
8655 Object_Definition =>
8656 Make_Subtype_Indication (Loc,
8657 Subtype_Mark => New_Reference_To (
8658 RTE (RE_Protected_Entry_Body_Array), Loc),
8659 Constraint =>
8660 Make_Index_Or_Discriminant_Constraint (Loc,
8661 Constraints => New_List (
8662 Make_Range (Loc,
8663 Make_Integer_Literal (Loc, 1),
8664 Make_Integer_Literal (Loc, E_Count))))),
8665 Expression => Entries_Aggr);
8666
8667 when System_Tasking_Protected_Objects_Single_Entry =>
8668 Body_Arr := Make_Object_Declaration (Loc,
8669 Defining_Identifier => Body_Id,
8670 Aliased_Present => True,
8671 Object_Definition => New_Reference_To
8672 (RTE (RE_Entry_Body), Loc),
8673 Expression =>
8674 Make_Aggregate (Loc,
8675 Expressions => New_List (
8676 Make_Attribute_Reference (Loc,
8677 Prefix => New_Reference_To (Bdef, Loc),
8678 Attribute_Name => Name_Unrestricted_Access),
8679 Make_Attribute_Reference (Loc,
8680 Prefix => New_Reference_To (Edef, Loc),
8681 Attribute_Name => Name_Unrestricted_Access))));
8682
8683 when others =>
8684 raise Program_Error;
8685 end case;
8686
8687 -- A pointer to this array will be placed in the corresponding record
8688 -- by its initialization procedure so this needs to be analyzed here.
8689
8690 Insert_After (Current_Node, Body_Arr);
8691 Current_Node := Body_Arr;
8692 Analyze (Body_Arr);
8693
8694 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8695
8696 -- Finally, build the function that maps an entry index into the
8697 -- corresponding body. A pointer to this function is placed in each
8698 -- object of the type. Except for a ravenscar-like profile (no abort,
8699 -- no entry queue, 1 entry)
8700
8701 if Corresponding_Runtime_Package (Prot_Typ) =
8702 System_Tasking_Protected_Objects_Entries
8703 then
8704 Sub :=
8705 Make_Subprogram_Declaration (Loc,
8706 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8707 Insert_After (Current_Node, Sub);
8708 Analyze (Sub);
8709 end if;
8710 end if;
8711 end Expand_N_Protected_Type_Declaration;
8712
8713 --------------------------------
8714 -- Expand_N_Requeue_Statement --
8715 --------------------------------
8716
8717 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8718 -- operations, depending on the source and destination (task or protected
8719 -- object). A dispatching requeue statement is expanded into a call to the
8720 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8721 -- jump around the remainder of processing for the original entry and, if
8722 -- the destination is (different) protected object, to attempt to service
8723 -- it. The following illustrates the various cases:
8724
8725 -- procedure entE
8726 -- (O : System.Address;
8727 -- P : System.Address;
8728 -- E : Protected_Entry_Index)
8729 -- is
8730 -- <discriminant renamings>
8731 -- <private object renamings>
8732 -- type poVP is access poV;
8733 -- _object : ptVP := ptVP!(O);
8734
8735 -- begin
8736 -- begin
8737 -- <start of statement sequence for entry>
8738
8739 -- -- Requeue from one protected entry body to another protected
8740 -- -- entry.
8741
8742 -- Requeue_Protected_Entry (
8743 -- _object._object'Access,
8744 -- new._object'Access,
8745 -- E,
8746 -- Abort_Present);
8747 -- return;
8748
8749 -- <some more of the statement sequence for entry>
8750
8751 -- -- Requeue from an entry body to a task entry
8752
8753 -- Requeue_Protected_To_Task_Entry (
8754 -- New._task_id,
8755 -- E,
8756 -- Abort_Present);
8757 -- return;
8758
8759 -- <rest of statement sequence for entry>
8760 -- Complete_Entry_Body (_object._object);
8761
8762 -- exception
8763 -- when all others =>
8764 -- Exceptional_Complete_Entry_Body (
8765 -- _object._object, Get_GNAT_Exception);
8766 -- end;
8767 -- end entE;
8768
8769 -- Requeue of a task entry call to a task entry
8770
8771 -- Accept_Call (E, Ann);
8772 -- <start of statement sequence for accept statement>
8773 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8774 -- goto Lnn;
8775 -- <rest of statement sequence for accept statement>
8776 -- <<Lnn>>
8777 -- Complete_Rendezvous;
8778
8779 -- exception
8780 -- when all others =>
8781 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8782
8783 -- Requeue of a task entry call to a protected entry
8784
8785 -- Accept_Call (E, Ann);
8786 -- <start of statement sequence for accept statement>
8787 -- Requeue_Task_To_Protected_Entry (
8788 -- new._object'Access,
8789 -- E,
8790 -- Abort_Present);
8791 -- newS (new, Pnn);
8792 -- goto Lnn;
8793 -- <rest of statement sequence for accept statement>
8794 -- <<Lnn>>
8795 -- Complete_Rendezvous;
8796
8797 -- exception
8798 -- when all others =>
8799 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8800
8801 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8802 -- marked by pragma Implemented (XXX, By_Entry).
8803
8804 -- The requeue is inside a protected entry:
8805
8806 -- procedure entE
8807 -- (O : System.Address;
8808 -- P : System.Address;
8809 -- E : Protected_Entry_Index)
8810 -- is
8811 -- <discriminant renamings>
8812 -- <private object renamings>
8813 -- type poVP is access poV;
8814 -- _object : ptVP := ptVP!(O);
8815
8816 -- begin
8817 -- begin
8818 -- <start of statement sequence for entry>
8819
8820 -- _Disp_Requeue
8821 -- (<interface class-wide object>,
8822 -- True,
8823 -- _object'Address,
8824 -- Ada.Tags.Get_Offset_Index
8825 -- (Tag (_object),
8826 -- <interface dispatch table index of target entry>),
8827 -- Abort_Present);
8828 -- return;
8829
8830 -- <rest of statement sequence for entry>
8831 -- Complete_Entry_Body (_object._object);
8832
8833 -- exception
8834 -- when all others =>
8835 -- Exceptional_Complete_Entry_Body (
8836 -- _object._object, Get_GNAT_Exception);
8837 -- end;
8838 -- end entE;
8839
8840 -- The requeue is inside a task entry:
8841
8842 -- Accept_Call (E, Ann);
8843 -- <start of statement sequence for accept statement>
8844 -- _Disp_Requeue
8845 -- (<interface class-wide object>,
8846 -- False,
8847 -- null,
8848 -- Ada.Tags.Get_Offset_Index
8849 -- (Tag (_object),
8850 -- <interface dispatch table index of target entrt>),
8851 -- Abort_Present);
8852 -- newS (new, Pnn);
8853 -- goto Lnn;
8854 -- <rest of statement sequence for accept statement>
8855 -- <<Lnn>>
8856 -- Complete_Rendezvous;
8857
8858 -- exception
8859 -- when all others =>
8860 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8861
8862 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8863 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8864 -- statement is replaced by a dispatching call with actual parameters taken
8865 -- from the inner-most accept statement or entry body.
8866
8867 -- Target.Primitive (Param1, ..., ParamN);
8868
8869 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8870 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8871
8872 -- declare
8873 -- S : constant Offset_Index :=
8874 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8875 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8876
8877 -- begin
8878 -- if C = POK_Protected_Entry
8879 -- or else C = POK_Task_Entry
8880 -- then
8881 -- <statements for dispatching requeue>
8882
8883 -- elsif C = POK_Protected_Procedure then
8884 -- <dispatching call equivalent>
8885
8886 -- else
8887 -- raise Program_Error;
8888 -- end if;
8889 -- end;
8890
8891 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8892 Loc : constant Source_Ptr := Sloc (N);
8893 Conc_Typ : Entity_Id;
8894 Concval : Node_Id;
8895 Ename : Node_Id;
8896 Index : Node_Id;
8897 Old_Typ : Entity_Id;
8898
8899 function Build_Dispatching_Call_Equivalent return Node_Id;
8900 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8901 -- the form Concval.Ename. It is statically known that Ename is allowed
8902 -- to be implemented by a protected procedure. Create a dispatching call
8903 -- equivalent of Concval.Ename taking the actual parameters from the
8904 -- inner-most accept statement or entry body.
8905
8906 function Build_Dispatching_Requeue return Node_Id;
8907 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8908 -- the form Concval.Ename. It is statically known that Ename is allowed
8909 -- to be implemented by a protected or a task entry. Create a call to
8910 -- primitive _Disp_Requeue which handles the low-level actions.
8911
8912 function Build_Dispatching_Requeue_To_Any return Node_Id;
8913 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8914 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8915 -- (XXX, By_Any) or not marked at all. Create a block which determines
8916 -- at runtime whether Ename denotes an entry or a procedure and perform
8917 -- the appropriate kind of dispatching select.
8918
8919 function Build_Normal_Requeue return Node_Id;
8920 -- N denotes a non-dispatching requeue statement to either a task or a
8921 -- protected entry. Build the appropriate runtime call to perform the
8922 -- action.
8923
8924 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8925 -- For a protected entry, create a return statement to skip the rest of
8926 -- the entry body. Otherwise, create a goto statement to skip the rest
8927 -- of a task accept statement. The lookup for the enclosing entry body
8928 -- or accept statement starts from Search.
8929
8930 ---------------------------------------
8931 -- Build_Dispatching_Call_Equivalent --
8932 ---------------------------------------
8933
8934 function Build_Dispatching_Call_Equivalent return Node_Id is
8935 Call_Ent : constant Entity_Id := Entity (Ename);
8936 Obj : constant Node_Id := Original_Node (Concval);
8937 Acc_Ent : Node_Id;
8938 Actuals : List_Id;
8939 Formal : Node_Id;
8940 Formals : List_Id;
8941
8942 begin
8943 -- Climb the parent chain looking for the inner-most entry body or
8944 -- accept statement.
8945
8946 Acc_Ent := N;
8947 while Present (Acc_Ent)
8948 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8949 N_Entry_Body)
8950 loop
8951 Acc_Ent := Parent (Acc_Ent);
8952 end loop;
8953
8954 -- A requeue statement should be housed inside an entry body or an
8955 -- accept statement at some level. If this is not the case, then the
8956 -- tree is malformed.
8957
8958 pragma Assert (Present (Acc_Ent));
8959
8960 -- Recover the list of formal parameters
8961
8962 if Nkind (Acc_Ent) = N_Entry_Body then
8963 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8964 end if;
8965
8966 Formals := Parameter_Specifications (Acc_Ent);
8967
8968 -- Create the actual parameters for the dispatching call. These are
8969 -- simply copies of the entry body or accept statement formals in the
8970 -- same order as they appear.
8971
8972 Actuals := No_List;
8973
8974 if Present (Formals) then
8975 Actuals := New_List;
8976 Formal := First (Formals);
8977 while Present (Formal) loop
8978 Append_To (Actuals,
8979 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8980 Next (Formal);
8981 end loop;
8982 end if;
8983
8984 -- Generate:
8985 -- Obj.Call_Ent (Actuals);
8986
8987 return
8988 Make_Procedure_Call_Statement (Loc,
8989 Name =>
8990 Make_Selected_Component (Loc,
8991 Prefix => Make_Identifier (Loc, Chars (Obj)),
8992 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
8993
8994 Parameter_Associations => Actuals);
8995 end Build_Dispatching_Call_Equivalent;
8996
8997 -------------------------------
8998 -- Build_Dispatching_Requeue --
8999 -------------------------------
9000
9001 function Build_Dispatching_Requeue return Node_Id is
9002 Params : constant List_Id := New_List;
9003
9004 begin
9005 -- Process the "with abort" parameter
9006
9007 Prepend_To (Params,
9008 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
9009
9010 -- Process the entry wrapper's position in the primary dispatch
9011 -- table parameter. Generate:
9012
9013 -- Ada.Tags.Get_Offset_Index
9014 -- (Ada.Tags.Tag (Concval),
9015 -- <interface dispatch table position of Ename>)
9016
9017 if Tagged_Type_Expansion then
9018 Prepend_To (Params,
9019 Make_Function_Call (Loc,
9020 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
9021 Parameter_Associations => New_List (
9022 Unchecked_Convert_To (RTE (RE_Tag), Concval),
9023 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
9024
9025 -- VM targets
9026
9027 else
9028 Prepend_To (Params,
9029 Make_Function_Call (Loc,
9030 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
9031
9032 Parameter_Associations => New_List (
9033
9034 -- Obj_Typ
9035
9036 Make_Attribute_Reference (Loc,
9037 Prefix => Concval,
9038 Attribute_Name => Name_Tag),
9039
9040 -- Tag_Typ
9041
9042 Make_Attribute_Reference (Loc,
9043 Prefix => New_Reference_To (Etype (Concval), Loc),
9044 Attribute_Name => Name_Tag),
9045
9046 -- Position
9047
9048 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
9049 end if;
9050
9051 -- Specific actuals for protected to XXX requeue
9052
9053 if Is_Protected_Type (Old_Typ) then
9054 Prepend_To (Params,
9055 Make_Attribute_Reference (Loc, -- _object'Address
9056 Prefix =>
9057 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9058 Attribute_Name => Name_Address));
9059
9060 Prepend_To (Params, -- True
9061 New_Reference_To (Standard_True, Loc));
9062
9063 -- Specific actuals for task to XXX requeue
9064
9065 else
9066 pragma Assert (Is_Task_Type (Old_Typ));
9067
9068 Prepend_To (Params, -- null
9069 New_Reference_To (RTE (RE_Null_Address), Loc));
9070
9071 Prepend_To (Params, -- False
9072 New_Reference_To (Standard_False, Loc));
9073 end if;
9074
9075 -- Add the object parameter
9076
9077 Prepend_To (Params, New_Copy_Tree (Concval));
9078
9079 -- Generate:
9080 -- _Disp_Requeue (<Params>);
9081
9082 return
9083 Make_Procedure_Call_Statement (Loc,
9084 Name => Make_Identifier (Loc, Name_uDisp_Requeue),
9085 Parameter_Associations => Params);
9086 end Build_Dispatching_Requeue;
9087
9088 --------------------------------------
9089 -- Build_Dispatching_Requeue_To_Any --
9090 --------------------------------------
9091
9092 function Build_Dispatching_Requeue_To_Any return Node_Id is
9093 Call_Ent : constant Entity_Id := Entity (Ename);
9094 Obj : constant Node_Id := Original_Node (Concval);
9095 Skip : constant Node_Id := Build_Skip_Statement (N);
9096 C : Entity_Id;
9097 Decls : List_Id;
9098 S : Entity_Id;
9099 Stmts : List_Id;
9100
9101 begin
9102 Decls := New_List;
9103 Stmts := New_List;
9104
9105 -- Dispatch table slot processing, generate:
9106 -- S : Integer;
9107
9108 S := Build_S (Loc, Decls);
9109
9110 -- Call kind processing, generate:
9111 -- C : Ada.Tags.Prim_Op_Kind;
9112
9113 C := Build_C (Loc, Decls);
9114
9115 -- Generate:
9116 -- S := Ada.Tags.Get_Offset_Index
9117 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9118
9119 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
9120
9121 -- Generate:
9122 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9123
9124 Append_To (Stmts,
9125 Make_Procedure_Call_Statement (Loc,
9126 Name =>
9127 New_Reference_To (
9128 Find_Prim_Op (Etype (Etype (Obj)),
9129 Name_uDisp_Get_Prim_Op_Kind),
9130 Loc),
9131 Parameter_Associations => New_List (
9132 New_Copy_Tree (Obj),
9133 New_Reference_To (S, Loc),
9134 New_Reference_To (C, Loc))));
9135
9136 Append_To (Stmts,
9137
9138 -- if C = POK_Protected_Entry
9139 -- or else C = POK_Task_Entry
9140 -- then
9141
9142 Make_If_Statement (Loc,
9143 Condition =>
9144 Make_Op_Or (Loc,
9145 Left_Opnd =>
9146 Make_Op_Eq (Loc,
9147 Left_Opnd =>
9148 New_Reference_To (C, Loc),
9149 Right_Opnd =>
9150 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
9151
9152 Right_Opnd =>
9153 Make_Op_Eq (Loc,
9154 Left_Opnd =>
9155 New_Reference_To (C, Loc),
9156 Right_Opnd =>
9157 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
9158
9159 -- Dispatching requeue equivalent
9160
9161 Then_Statements => New_List (
9162 Build_Dispatching_Requeue,
9163 Skip),
9164
9165 -- elsif C = POK_Protected_Procedure then
9166
9167 Elsif_Parts => New_List (
9168 Make_Elsif_Part (Loc,
9169 Condition =>
9170 Make_Op_Eq (Loc,
9171 Left_Opnd =>
9172 New_Reference_To (C, Loc),
9173 Right_Opnd =>
9174 New_Reference_To (
9175 RTE (RE_POK_Protected_Procedure), Loc)),
9176
9177 -- Dispatching call equivalent
9178
9179 Then_Statements => New_List (
9180 Build_Dispatching_Call_Equivalent))),
9181
9182 -- else
9183 -- raise Program_Error;
9184 -- end if;
9185
9186 Else_Statements => New_List (
9187 Make_Raise_Program_Error (Loc,
9188 Reason => PE_Explicit_Raise))));
9189
9190 -- Wrap everything into a block
9191
9192 return
9193 Make_Block_Statement (Loc,
9194 Declarations => Decls,
9195 Handled_Statement_Sequence =>
9196 Make_Handled_Sequence_Of_Statements (Loc,
9197 Statements => Stmts));
9198 end Build_Dispatching_Requeue_To_Any;
9199
9200 --------------------------
9201 -- Build_Normal_Requeue --
9202 --------------------------
9203
9204 function Build_Normal_Requeue return Node_Id is
9205 Params : constant List_Id := New_List;
9206 Param : Node_Id;
9207 RT_Call : Node_Id;
9208
9209 begin
9210 -- Process the "with abort" parameter
9211
9212 Prepend_To (Params,
9213 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
9214
9215 -- Add the index expression to the parameters. It is common among all
9216 -- four cases.
9217
9218 Prepend_To (Params,
9219 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
9220
9221 if Is_Protected_Type (Old_Typ) then
9222 declare
9223 Self_Param : Node_Id;
9224
9225 begin
9226 Self_Param :=
9227 Make_Attribute_Reference (Loc,
9228 Prefix =>
9229 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9230 Attribute_Name =>
9231 Name_Unchecked_Access);
9232
9233 -- Protected to protected requeue
9234
9235 if Is_Protected_Type (Conc_Typ) then
9236 RT_Call :=
9237 New_Reference_To (
9238 RTE (RE_Requeue_Protected_Entry), Loc);
9239
9240 Param :=
9241 Make_Attribute_Reference (Loc,
9242 Prefix =>
9243 Concurrent_Ref (Concval),
9244 Attribute_Name =>
9245 Name_Unchecked_Access);
9246
9247 -- Protected to task requeue
9248
9249 else pragma Assert (Is_Task_Type (Conc_Typ));
9250 RT_Call :=
9251 New_Reference_To (
9252 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
9253
9254 Param := Concurrent_Ref (Concval);
9255 end if;
9256
9257 Prepend_To (Params, Param);
9258 Prepend_To (Params, Self_Param);
9259 end;
9260
9261 else pragma Assert (Is_Task_Type (Old_Typ));
9262
9263 -- Task to protected requeue
9264
9265 if Is_Protected_Type (Conc_Typ) then
9266 RT_Call :=
9267 New_Reference_To (
9268 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
9269
9270 Param :=
9271 Make_Attribute_Reference (Loc,
9272 Prefix =>
9273 Concurrent_Ref (Concval),
9274 Attribute_Name =>
9275 Name_Unchecked_Access);
9276
9277 -- Task to task requeue
9278
9279 else pragma Assert (Is_Task_Type (Conc_Typ));
9280 RT_Call :=
9281 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
9282
9283 Param := Concurrent_Ref (Concval);
9284 end if;
9285
9286 Prepend_To (Params, Param);
9287 end if;
9288
9289 return
9290 Make_Procedure_Call_Statement (Loc,
9291 Name => RT_Call,
9292 Parameter_Associations => Params);
9293 end Build_Normal_Requeue;
9294
9295 --------------------------
9296 -- Build_Skip_Statement --
9297 --------------------------
9298
9299 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
9300 Skip_Stmt : Node_Id;
9301
9302 begin
9303 -- Build a return statement to skip the rest of the entire body
9304
9305 if Is_Protected_Type (Old_Typ) then
9306 Skip_Stmt := Make_Simple_Return_Statement (Loc);
9307
9308 -- If the requeue is within a task, find the end label of the
9309 -- enclosing accept statement and create a goto statement to it.
9310
9311 else
9312 declare
9313 Acc : Node_Id;
9314 Label : Node_Id;
9315
9316 begin
9317 -- Climb the parent chain looking for the enclosing accept
9318 -- statement.
9319
9320 Acc := Parent (Search);
9321 while Present (Acc)
9322 and then Nkind (Acc) /= N_Accept_Statement
9323 loop
9324 Acc := Parent (Acc);
9325 end loop;
9326
9327 -- The last statement is the second label used for completing
9328 -- the rendezvous the usual way. The label we are looking for
9329 -- is right before it.
9330
9331 Label :=
9332 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
9333
9334 pragma Assert (Nkind (Label) = N_Label);
9335
9336 -- Generate a goto statement to skip the rest of the accept
9337
9338 Skip_Stmt :=
9339 Make_Goto_Statement (Loc,
9340 Name =>
9341 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9342 end;
9343 end if;
9344
9345 Set_Analyzed (Skip_Stmt);
9346
9347 return Skip_Stmt;
9348 end Build_Skip_Statement;
9349
9350 -- Start of processing for Expand_N_Requeue_Statement
9351
9352 begin
9353 -- Extract the components of the entry call
9354
9355 Extract_Entry (N, Concval, Ename, Index);
9356 Conc_Typ := Etype (Concval);
9357
9358 -- Examine the scope stack in order to find nearest enclosing protected
9359 -- or task type. This will constitute our invocation source.
9360
9361 Old_Typ := Current_Scope;
9362 while Present (Old_Typ)
9363 and then not Is_Protected_Type (Old_Typ)
9364 and then not Is_Task_Type (Old_Typ)
9365 loop
9366 Old_Typ := Scope (Old_Typ);
9367 end loop;
9368
9369 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9370 -- Concval.Ename where the type of Concval is class-wide concurrent
9371 -- interface.
9372
9373 if Ada_Version >= Ada_2012
9374 and then Present (Concval)
9375 and then Is_Class_Wide_Type (Conc_Typ)
9376 and then Is_Concurrent_Interface (Conc_Typ)
9377 then
9378 declare
9379 Has_Impl : Boolean := False;
9380 Impl_Kind : Name_Id := No_Name;
9381
9382 begin
9383 -- Check whether the Ename is flagged by pragma Implemented
9384
9385 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9386 Has_Impl := True;
9387 Impl_Kind := Implementation_Kind (Entity (Ename));
9388 end if;
9389
9390 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9391 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9392
9393 if Has_Impl
9394 and then Impl_Kind = Name_By_Entry
9395 then
9396 Rewrite (N, Build_Dispatching_Requeue);
9397 Analyze (N);
9398 Insert_After (N, Build_Skip_Statement (N));
9399
9400 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9401 -- a protected procedure. In this case the requeue is transformed
9402 -- into a dispatching call.
9403
9404 elsif Has_Impl
9405 and then Impl_Kind = Name_By_Protected_Procedure
9406 then
9407 Rewrite (N, Build_Dispatching_Call_Equivalent);
9408 Analyze (N);
9409
9410 -- The procedure_or_entry_NAME's implementation kind is either
9411 -- By_Any or pragma Implemented was not applied at all. In this
9412 -- case a runtime test determines whether Ename denotes an entry
9413 -- or a protected procedure and performs the appropriate call.
9414
9415 else
9416 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9417 Analyze (N);
9418 end if;
9419 end;
9420
9421 -- Processing for regular (non-dispatching) requeues
9422
9423 else
9424 Rewrite (N, Build_Normal_Requeue);
9425 Analyze (N);
9426 Insert_After (N, Build_Skip_Statement (N));
9427 end if;
9428 end Expand_N_Requeue_Statement;
9429
9430 -------------------------------
9431 -- Expand_N_Selective_Accept --
9432 -------------------------------
9433
9434 procedure Expand_N_Selective_Accept (N : Node_Id) is
9435 Loc : constant Source_Ptr := Sloc (N);
9436 Alts : constant List_Id := Select_Alternatives (N);
9437
9438 -- Note: in the below declarations a lot of new lists are allocated
9439 -- unconditionally which may well not end up being used. That's
9440 -- not a good idea since it wastes space gratuitously ???
9441
9442 Accept_Case : List_Id;
9443 Accept_List : constant List_Id := New_List;
9444
9445 Alt : Node_Id;
9446 Alt_List : constant List_Id := New_List;
9447 Alt_Stats : List_Id;
9448 Ann : Entity_Id := Empty;
9449
9450 Block : Node_Id;
9451 Check_Guard : Boolean := True;
9452
9453 Decls : constant List_Id := New_List;
9454 Stats : constant List_Id := New_List;
9455 Body_List : constant List_Id := New_List;
9456 Trailing_List : constant List_Id := New_List;
9457
9458 Choices : List_Id;
9459 Else_Present : Boolean := False;
9460 Terminate_Alt : Node_Id := Empty;
9461 Select_Mode : Node_Id;
9462
9463 Delay_Case : List_Id;
9464 Delay_Count : Integer := 0;
9465 Delay_Val : Entity_Id;
9466 Delay_Index : Entity_Id;
9467 Delay_Min : Entity_Id;
9468 Delay_Num : Int := 1;
9469 Delay_Alt_List : List_Id := New_List;
9470 Delay_List : constant List_Id := New_List;
9471 D : Entity_Id;
9472 M : Entity_Id;
9473
9474 First_Delay : Boolean := True;
9475 Guard_Open : Entity_Id;
9476
9477 End_Lab : Node_Id;
9478 Index : Int := 1;
9479 Lab : Node_Id;
9480 Num_Alts : Int;
9481 Num_Accept : Nat := 0;
9482 Proc : Node_Id;
9483 Q : Node_Id;
9484 Time_Type : Entity_Id;
9485 X : Node_Id;
9486 Select_Call : Node_Id;
9487
9488 Qnam : constant Entity_Id :=
9489 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9490
9491 Xnam : constant Entity_Id :=
9492 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9493
9494 -----------------------
9495 -- Local subprograms --
9496 -----------------------
9497
9498 function Accept_Or_Raise return List_Id;
9499 -- For the rare case where delay alternatives all have guards, and
9500 -- all of them are closed, it is still possible that there were open
9501 -- accept alternatives with no callers. We must reexamine the
9502 -- Accept_List, and execute a selective wait with no else if some
9503 -- accept is open. If none, we raise program_error.
9504
9505 procedure Add_Accept (Alt : Node_Id);
9506 -- Process a single accept statement in a select alternative. Build
9507 -- procedure for body of accept, and add entry to dispatch table with
9508 -- expression for guard, in preparation for call to run time select.
9509
9510 function Make_And_Declare_Label (Num : Int) return Node_Id;
9511 -- Manufacture a label using Num as a serial number and declare it.
9512 -- The declaration is appended to Decls. The label marks the trailing
9513 -- statements of an accept or delay alternative.
9514
9515 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9516 -- Build call to Selective_Wait runtime routine
9517
9518 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9519 -- Add code to compare value of delay with previous values, and
9520 -- generate case entry for trailing statements.
9521
9522 procedure Process_Accept_Alternative
9523 (Alt : Node_Id;
9524 Index : Int;
9525 Proc : Node_Id);
9526 -- Add code to call corresponding procedure, and branch to
9527 -- trailing statements, if any.
9528
9529 ---------------------
9530 -- Accept_Or_Raise --
9531 ---------------------
9532
9533 function Accept_Or_Raise return List_Id is
9534 Cond : Node_Id;
9535 Stats : List_Id;
9536 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9537
9538 begin
9539 -- We generate the following:
9540
9541 -- for J in q'range loop
9542 -- if q(J).S /=null_task_entry then
9543 -- selective_wait (simple_mode,...);
9544 -- done := True;
9545 -- exit;
9546 -- end if;
9547 -- end loop;
9548 --
9549 -- if no rendez_vous then
9550 -- raise program_error;
9551 -- end if;
9552
9553 -- Note that the code needs to know that the selector name
9554 -- in an Accept_Alternative is named S.
9555
9556 Cond := Make_Op_Ne (Loc,
9557 Left_Opnd =>
9558 Make_Selected_Component (Loc,
9559 Prefix =>
9560 Make_Indexed_Component (Loc,
9561 Prefix => New_Reference_To (Qnam, Loc),
9562 Expressions => New_List (New_Reference_To (J, Loc))),
9563 Selector_Name => Make_Identifier (Loc, Name_S)),
9564 Right_Opnd =>
9565 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9566
9567 Stats := New_List (
9568 Make_Implicit_Loop_Statement (N,
9569 Identifier => Empty,
9570 Iteration_Scheme =>
9571 Make_Iteration_Scheme (Loc,
9572 Loop_Parameter_Specification =>
9573 Make_Loop_Parameter_Specification (Loc,
9574 Defining_Identifier => J,
9575 Discrete_Subtype_Definition =>
9576 Make_Attribute_Reference (Loc,
9577 Prefix => New_Reference_To (Qnam, Loc),
9578 Attribute_Name => Name_Range,
9579 Expressions => New_List (
9580 Make_Integer_Literal (Loc, 1))))),
9581
9582 Statements => New_List (
9583 Make_Implicit_If_Statement (N,
9584 Condition => Cond,
9585 Then_Statements => New_List (
9586 Make_Select_Call (
9587 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9588 Make_Exit_Statement (Loc))))));
9589
9590 Append_To (Stats,
9591 Make_Raise_Program_Error (Loc,
9592 Condition => Make_Op_Eq (Loc,
9593 Left_Opnd => New_Reference_To (Xnam, Loc),
9594 Right_Opnd =>
9595 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9596 Reason => PE_All_Guards_Closed));
9597
9598 return Stats;
9599 end Accept_Or_Raise;
9600
9601 ----------------
9602 -- Add_Accept --
9603 ----------------
9604
9605 procedure Add_Accept (Alt : Node_Id) is
9606 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9607 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9608 Eloc : constant Source_Ptr := Sloc (Ename);
9609 Eent : constant Entity_Id := Entity (Ename);
9610 Index : constant Node_Id := Entry_Index (Acc_Stm);
9611 Null_Body : Node_Id;
9612 Proc_Body : Node_Id;
9613 PB_Ent : Entity_Id;
9614 Expr : Node_Id;
9615 Call : Node_Id;
9616
9617 begin
9618 if No (Ann) then
9619 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9620 end if;
9621
9622 if Present (Condition (Alt)) then
9623 Expr :=
9624 Make_Conditional_Expression (Eloc, New_List (
9625 Condition (Alt),
9626 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9627 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9628 else
9629 Expr :=
9630 Entry_Index_Expression
9631 (Eloc, Eent, Index, Scope (Eent));
9632 end if;
9633
9634 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9635 Null_Body := New_Reference_To (Standard_False, Eloc);
9636
9637 if Abort_Allowed then
9638 Call := Make_Procedure_Call_Statement (Eloc,
9639 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9640 Insert_Before (First (Statements (Handled_Statement_Sequence (
9641 Accept_Statement (Alt)))), Call);
9642 Analyze (Call);
9643 end if;
9644
9645 PB_Ent :=
9646 Make_Defining_Identifier (Eloc,
9647 New_External_Name (Chars (Ename), 'A', Num_Accept));
9648
9649 if Comes_From_Source (Alt) then
9650 Set_Debug_Info_Needed (PB_Ent);
9651 end if;
9652
9653 Proc_Body :=
9654 Make_Subprogram_Body (Eloc,
9655 Specification =>
9656 Make_Procedure_Specification (Eloc,
9657 Defining_Unit_Name => PB_Ent),
9658 Declarations => Declarations (Acc_Stm),
9659 Handled_Statement_Sequence =>
9660 Build_Accept_Body (Accept_Statement (Alt)));
9661
9662 -- During the analysis of the body of the accept statement, any
9663 -- zero cost exception handler records were collected in the
9664 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9665 -- This is where we move them to where they belong, namely the
9666 -- newly created procedure.
9667
9668 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9669 Append (Proc_Body, Body_List);
9670
9671 else
9672 Null_Body := New_Reference_To (Standard_True, Eloc);
9673
9674 -- if accept statement has declarations, insert above, given that
9675 -- we are not creating a body for the accept.
9676
9677 if Present (Declarations (Acc_Stm)) then
9678 Insert_Actions (N, Declarations (Acc_Stm));
9679 end if;
9680 end if;
9681
9682 Append_To (Accept_List,
9683 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9684
9685 Num_Accept := Num_Accept + 1;
9686 end Add_Accept;
9687
9688 ----------------------------
9689 -- Make_And_Declare_Label --
9690 ----------------------------
9691
9692 function Make_And_Declare_Label (Num : Int) return Node_Id is
9693 Lab_Id : Node_Id;
9694
9695 begin
9696 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9697 Lab :=
9698 Make_Label (Loc, Lab_Id);
9699
9700 Append_To (Decls,
9701 Make_Implicit_Label_Declaration (Loc,
9702 Defining_Identifier =>
9703 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9704 Label_Construct => Lab));
9705
9706 return Lab;
9707 end Make_And_Declare_Label;
9708
9709 ----------------------
9710 -- Make_Select_Call --
9711 ----------------------
9712
9713 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9714 Params : constant List_Id := New_List;
9715
9716 begin
9717 Append (
9718 Make_Attribute_Reference (Loc,
9719 Prefix => New_Reference_To (Qnam, Loc),
9720 Attribute_Name => Name_Unchecked_Access),
9721 Params);
9722 Append (Select_Mode, Params);
9723 Append (New_Reference_To (Ann, Loc), Params);
9724 Append (New_Reference_To (Xnam, Loc), Params);
9725
9726 return
9727 Make_Procedure_Call_Statement (Loc,
9728 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9729 Parameter_Associations => Params);
9730 end Make_Select_Call;
9731
9732 --------------------------------
9733 -- Process_Accept_Alternative --
9734 --------------------------------
9735
9736 procedure Process_Accept_Alternative
9737 (Alt : Node_Id;
9738 Index : Int;
9739 Proc : Node_Id)
9740 is
9741 Choices : List_Id := No_List;
9742 Alt_Stats : List_Id;
9743
9744 begin
9745 Adjust_Condition (Condition (Alt));
9746 Alt_Stats := No_List;
9747
9748 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9749 Choices := New_List (
9750 Make_Integer_Literal (Loc, Index));
9751
9752 Alt_Stats := New_List (
9753 Make_Procedure_Call_Statement (Sloc (Proc),
9754 Name => New_Reference_To (
9755 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9756 end if;
9757
9758 if Statements (Alt) /= Empty_List then
9759
9760 if No (Alt_Stats) then
9761
9762 -- Accept with no body, followed by trailing statements
9763
9764 Choices := New_List (
9765 Make_Integer_Literal (Loc, Index));
9766
9767 Alt_Stats := New_List;
9768 end if;
9769
9770 -- After the call, if any, branch to trailing statements. We
9771 -- create a label for each, as well as the corresponding label
9772 -- declaration.
9773
9774 Lab := Make_And_Declare_Label (Index);
9775 Append_To (Alt_Stats,
9776 Make_Goto_Statement (Loc,
9777 Name => New_Copy (Identifier (Lab))));
9778
9779 Append (Lab, Trailing_List);
9780 Append_List (Statements (Alt), Trailing_List);
9781 Append_To (Trailing_List,
9782 Make_Goto_Statement (Loc,
9783 Name => New_Copy (Identifier (End_Lab))));
9784 end if;
9785
9786 if Present (Alt_Stats) then
9787
9788 -- Procedure call. and/or trailing statements
9789
9790 Append_To (Alt_List,
9791 Make_Case_Statement_Alternative (Loc,
9792 Discrete_Choices => Choices,
9793 Statements => Alt_Stats));
9794 end if;
9795 end Process_Accept_Alternative;
9796
9797 -------------------------------
9798 -- Process_Delay_Alternative --
9799 -------------------------------
9800
9801 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9802 Choices : List_Id;
9803 Cond : Node_Id;
9804 Delay_Alt : List_Id;
9805
9806 begin
9807 -- Deal with C/Fortran boolean as delay condition
9808
9809 Adjust_Condition (Condition (Alt));
9810
9811 -- Determine the smallest specified delay
9812
9813 -- for each delay alternative generate:
9814
9815 -- if guard-expression then
9816 -- Delay_Val := delay-expression;
9817 -- Guard_Open := True;
9818 -- if Delay_Val < Delay_Min then
9819 -- Delay_Min := Delay_Val;
9820 -- Delay_Index := Index;
9821 -- end if;
9822 -- end if;
9823
9824 -- The enclosing if-statement is omitted if there is no guard
9825
9826 if Delay_Count = 1
9827 or else First_Delay
9828 then
9829 First_Delay := False;
9830
9831 Delay_Alt := New_List (
9832 Make_Assignment_Statement (Loc,
9833 Name => New_Reference_To (Delay_Min, Loc),
9834 Expression => Expression (Delay_Statement (Alt))));
9835
9836 if Delay_Count > 1 then
9837 Append_To (Delay_Alt,
9838 Make_Assignment_Statement (Loc,
9839 Name => New_Reference_To (Delay_Index, Loc),
9840 Expression => Make_Integer_Literal (Loc, Index)));
9841 end if;
9842
9843 else
9844 Delay_Alt := New_List (
9845 Make_Assignment_Statement (Loc,
9846 Name => New_Reference_To (Delay_Val, Loc),
9847 Expression => Expression (Delay_Statement (Alt))));
9848
9849 if Time_Type = Standard_Duration then
9850 Cond :=
9851 Make_Op_Lt (Loc,
9852 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9853 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9854
9855 else
9856 -- The scope of the time type must define a comparison
9857 -- operator. The scope itself may not be visible, so we
9858 -- construct a node with entity information to insure that
9859 -- semantic analysis can find the proper operator.
9860
9861 Cond :=
9862 Make_Function_Call (Loc,
9863 Name => Make_Selected_Component (Loc,
9864 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9865 Selector_Name =>
9866 Make_Operator_Symbol (Loc,
9867 Chars => Name_Op_Lt,
9868 Strval => No_String)),
9869 Parameter_Associations =>
9870 New_List (
9871 New_Reference_To (Delay_Val, Loc),
9872 New_Reference_To (Delay_Min, Loc)));
9873
9874 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9875 end if;
9876
9877 Append_To (Delay_Alt,
9878 Make_Implicit_If_Statement (N,
9879 Condition => Cond,
9880 Then_Statements => New_List (
9881 Make_Assignment_Statement (Loc,
9882 Name => New_Reference_To (Delay_Min, Loc),
9883 Expression => New_Reference_To (Delay_Val, Loc)),
9884
9885 Make_Assignment_Statement (Loc,
9886 Name => New_Reference_To (Delay_Index, Loc),
9887 Expression => Make_Integer_Literal (Loc, Index)))));
9888 end if;
9889
9890 if Check_Guard then
9891 Append_To (Delay_Alt,
9892 Make_Assignment_Statement (Loc,
9893 Name => New_Reference_To (Guard_Open, Loc),
9894 Expression => New_Reference_To (Standard_True, Loc)));
9895 end if;
9896
9897 if Present (Condition (Alt)) then
9898 Delay_Alt := New_List (
9899 Make_Implicit_If_Statement (N,
9900 Condition => Condition (Alt),
9901 Then_Statements => Delay_Alt));
9902 end if;
9903
9904 Append_List (Delay_Alt, Delay_List);
9905
9906 -- If the delay alternative has a statement part, add choice to the
9907 -- case statements for delays.
9908
9909 if Present (Statements (Alt)) then
9910
9911 if Delay_Count = 1 then
9912 Append_List (Statements (Alt), Delay_Alt_List);
9913
9914 else
9915 Choices := New_List (
9916 Make_Integer_Literal (Loc, Index));
9917
9918 Append_To (Delay_Alt_List,
9919 Make_Case_Statement_Alternative (Loc,
9920 Discrete_Choices => Choices,
9921 Statements => Statements (Alt)));
9922 end if;
9923
9924 elsif Delay_Count = 1 then
9925
9926 -- If the single delay has no trailing statements, add a branch
9927 -- to the exit label to the selective wait.
9928
9929 Delay_Alt_List := New_List (
9930 Make_Goto_Statement (Loc,
9931 Name => New_Copy (Identifier (End_Lab))));
9932
9933 end if;
9934 end Process_Delay_Alternative;
9935
9936 -- Start of processing for Expand_N_Selective_Accept
9937
9938 begin
9939 Process_Statements_For_Controlled_Objects (N);
9940
9941 -- First insert some declarations before the select. The first is:
9942
9943 -- Ann : Address
9944
9945 -- This variable holds the parameters passed to the accept body. This
9946 -- declaration has already been inserted by the time we get here by
9947 -- a call to Expand_Accept_Declarations made from the semantics when
9948 -- processing the first accept statement contained in the select. We
9949 -- can find this entity as Accept_Address (E), where E is any of the
9950 -- entries references by contained accept statements.
9951
9952 -- The first step is to scan the list of Selective_Accept_Statements
9953 -- to find this entity, and also count the number of accepts, and
9954 -- determine if terminated, delay or else is present:
9955
9956 Num_Alts := 0;
9957
9958 Alt := First (Alts);
9959 while Present (Alt) loop
9960 Process_Statements_For_Controlled_Objects (Alt);
9961
9962 if Nkind (Alt) = N_Accept_Alternative then
9963 Add_Accept (Alt);
9964
9965 elsif Nkind (Alt) = N_Delay_Alternative then
9966 Delay_Count := Delay_Count + 1;
9967
9968 -- If the delays are relative delays, the delay expressions have
9969 -- type Standard_Duration. Otherwise they must have some time type
9970 -- recognized by GNAT.
9971
9972 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9973 Time_Type := Standard_Duration;
9974 else
9975 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9976
9977 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9978 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9979 then
9980 null;
9981 else
9982 Error_Msg_NE (
9983 "& is not a time type (RM 9.6(6))",
9984 Expression (Delay_Statement (Alt)), Time_Type);
9985 Time_Type := Standard_Duration;
9986 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9987 end if;
9988 end if;
9989
9990 if No (Condition (Alt)) then
9991
9992 -- This guard will always be open
9993
9994 Check_Guard := False;
9995 end if;
9996
9997 elsif Nkind (Alt) = N_Terminate_Alternative then
9998 Adjust_Condition (Condition (Alt));
9999 Terminate_Alt := Alt;
10000 end if;
10001
10002 Num_Alts := Num_Alts + 1;
10003 Next (Alt);
10004 end loop;
10005
10006 Else_Present := Present (Else_Statements (N));
10007
10008 -- At the same time (see procedure Add_Accept) we build the accept list:
10009
10010 -- Qnn : Accept_List (1 .. num-select) := (
10011 -- (null-body, entry-index),
10012 -- (null-body, entry-index),
10013 -- ..
10014 -- (null_body, entry-index));
10015
10016 -- In the above declaration, null-body is True if the corresponding
10017 -- accept has no body, and false otherwise. The entry is either the
10018 -- entry index expression if there is no guard, or if a guard is
10019 -- present, then a conditional expression of the form:
10020
10021 -- (if guard then entry-index else Null_Task_Entry)
10022
10023 -- If a guard is statically known to be false, the entry can simply
10024 -- be omitted from the accept list.
10025
10026 Q :=
10027 Make_Object_Declaration (Loc,
10028 Defining_Identifier => Qnam,
10029 Object_Definition =>
10030 New_Reference_To (RTE (RE_Accept_List), Loc),
10031 Aliased_Present => True,
10032
10033 Expression =>
10034 Make_Qualified_Expression (Loc,
10035 Subtype_Mark =>
10036 New_Reference_To (RTE (RE_Accept_List), Loc),
10037 Expression =>
10038 Make_Aggregate (Loc, Expressions => Accept_List)));
10039
10040 Append (Q, Decls);
10041
10042 -- Then we declare the variable that holds the index for the accept
10043 -- that will be selected for service:
10044
10045 -- Xnn : Select_Index;
10046
10047 X :=
10048 Make_Object_Declaration (Loc,
10049 Defining_Identifier => Xnam,
10050 Object_Definition =>
10051 New_Reference_To (RTE (RE_Select_Index), Loc),
10052 Expression =>
10053 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10054
10055 Append (X, Decls);
10056
10057 -- After this follow procedure declarations for each accept body
10058
10059 -- procedure Pnn is
10060 -- begin
10061 -- ...
10062 -- end;
10063
10064 -- where the ... are statements from the corresponding procedure body.
10065 -- No parameters are involved, since the parameters are passed via Ann
10066 -- and the parameter references have already been expanded to be direct
10067 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10068 -- any embedded tasking statements (which would normally be illegal in
10069 -- procedures), have been converted to calls to the tasking runtime so
10070 -- there is no problem in putting them into procedures.
10071
10072 -- The original accept statement has been expanded into a block in
10073 -- the same fashion as for simple accepts (see Build_Accept_Body).
10074
10075 -- Note: we don't really need to build these procedures for the case
10076 -- where no delay statement is present, but it is just as easy to
10077 -- build them unconditionally, and not significantly inefficient,
10078 -- since if they are short they will be inlined anyway.
10079
10080 -- The procedure declarations have been assembled in Body_List
10081
10082 -- If delays are present, we must compute the required delay.
10083 -- We first generate the declarations:
10084
10085 -- Delay_Index : Boolean := 0;
10086 -- Delay_Min : Some_Time_Type.Time;
10087 -- Delay_Val : Some_Time_Type.Time;
10088
10089 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10090 -- active delay that is actually chosen as the basis for the possible
10091 -- delay if an immediate rendez-vous is not possible.
10092
10093 -- In the most common case there is a single delay statement, and this
10094 -- is handled specially.
10095
10096 if Delay_Count > 0 then
10097
10098 -- Generate the required declarations
10099
10100 Delay_Val :=
10101 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
10102 Delay_Index :=
10103 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
10104 Delay_Min :=
10105 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
10106
10107 Append_To (Decls,
10108 Make_Object_Declaration (Loc,
10109 Defining_Identifier => Delay_Val,
10110 Object_Definition => New_Reference_To (Time_Type, Loc)));
10111
10112 Append_To (Decls,
10113 Make_Object_Declaration (Loc,
10114 Defining_Identifier => Delay_Index,
10115 Object_Definition => New_Reference_To (Standard_Integer, Loc),
10116 Expression => Make_Integer_Literal (Loc, 0)));
10117
10118 Append_To (Decls,
10119 Make_Object_Declaration (Loc,
10120 Defining_Identifier => Delay_Min,
10121 Object_Definition => New_Reference_To (Time_Type, Loc),
10122 Expression =>
10123 Unchecked_Convert_To (Time_Type,
10124 Make_Attribute_Reference (Loc,
10125 Prefix =>
10126 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
10127 Attribute_Name => Name_Last))));
10128
10129 -- Create Duration and Delay_Mode objects used for passing a delay
10130 -- value to RTS
10131
10132 D := Make_Temporary (Loc, 'D');
10133 M := Make_Temporary (Loc, 'M');
10134
10135 declare
10136 Discr : Entity_Id;
10137
10138 begin
10139 -- Note that these values are defined in s-osprim.ads and must
10140 -- be kept in sync:
10141 --
10142 -- Relative : constant := 0;
10143 -- Absolute_Calendar : constant := 1;
10144 -- Absolute_RT : constant := 2;
10145
10146 if Time_Type = Standard_Duration then
10147 Discr := Make_Integer_Literal (Loc, 0);
10148
10149 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10150 Discr := Make_Integer_Literal (Loc, 1);
10151
10152 else
10153 pragma Assert
10154 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10155 Discr := Make_Integer_Literal (Loc, 2);
10156 end if;
10157
10158 Append_To (Decls,
10159 Make_Object_Declaration (Loc,
10160 Defining_Identifier => D,
10161 Object_Definition =>
10162 New_Reference_To (Standard_Duration, Loc)));
10163
10164 Append_To (Decls,
10165 Make_Object_Declaration (Loc,
10166 Defining_Identifier => M,
10167 Object_Definition =>
10168 New_Reference_To (Standard_Integer, Loc),
10169 Expression => Discr));
10170 end;
10171
10172 if Check_Guard then
10173 Guard_Open :=
10174 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
10175
10176 Append_To (Decls,
10177 Make_Object_Declaration (Loc,
10178 Defining_Identifier => Guard_Open,
10179 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10180 Expression => New_Reference_To (Standard_False, Loc)));
10181 end if;
10182
10183 -- Delay_Count is zero, don't need M and D set (suppress warning)
10184
10185 else
10186 M := Empty;
10187 D := Empty;
10188 end if;
10189
10190 if Present (Terminate_Alt) then
10191
10192 -- If the terminate alternative guard is False, use
10193 -- Simple_Mode; otherwise use Terminate_Mode.
10194
10195 if Present (Condition (Terminate_Alt)) then
10196 Select_Mode := Make_Conditional_Expression (Loc,
10197 New_List (Condition (Terminate_Alt),
10198 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
10199 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
10200 else
10201 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
10202 end if;
10203
10204 elsif Else_Present or Delay_Count > 0 then
10205 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
10206
10207 else
10208 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
10209 end if;
10210
10211 Select_Call := Make_Select_Call (Select_Mode);
10212 Append (Select_Call, Stats);
10213
10214 -- Now generate code to act on the result. There is an entry
10215 -- in this case for each accept statement with a non-null body,
10216 -- followed by a branch to the statements that follow the Accept.
10217 -- In the absence of delay alternatives, we generate:
10218
10219 -- case X is
10220 -- when No_Rendezvous => -- omitted if simple mode
10221 -- goto Lab0;
10222
10223 -- when 1 =>
10224 -- P1n;
10225 -- goto Lab1;
10226
10227 -- when 2 =>
10228 -- P2n;
10229 -- goto Lab2;
10230
10231 -- when others =>
10232 -- goto Exit;
10233 -- end case;
10234 --
10235 -- Lab0: Else_Statements;
10236 -- goto exit;
10237
10238 -- Lab1: Trailing_Statements1;
10239 -- goto Exit;
10240 --
10241 -- Lab2: Trailing_Statements2;
10242 -- goto Exit;
10243 -- ...
10244 -- Exit:
10245
10246 -- Generate label for common exit
10247
10248 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
10249
10250 -- First entry is the default case, when no rendezvous is possible
10251
10252 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10253
10254 if Else_Present then
10255
10256 -- If no rendezvous is possible, the else part is executed
10257
10258 Lab := Make_And_Declare_Label (0);
10259 Alt_Stats := New_List (
10260 Make_Goto_Statement (Loc,
10261 Name => New_Copy (Identifier (Lab))));
10262
10263 Append (Lab, Trailing_List);
10264 Append_List (Else_Statements (N), Trailing_List);
10265 Append_To (Trailing_List,
10266 Make_Goto_Statement (Loc,
10267 Name => New_Copy (Identifier (End_Lab))));
10268 else
10269 Alt_Stats := New_List (
10270 Make_Goto_Statement (Loc,
10271 Name => New_Copy (Identifier (End_Lab))));
10272 end if;
10273
10274 Append_To (Alt_List,
10275 Make_Case_Statement_Alternative (Loc,
10276 Discrete_Choices => Choices,
10277 Statements => Alt_Stats));
10278
10279 -- We make use of the fact that Accept_Index is an integer type, and
10280 -- generate successive literals for entries for each accept. Only those
10281 -- for which there is a body or trailing statements get a case entry.
10282
10283 Alt := First (Select_Alternatives (N));
10284 Proc := First (Body_List);
10285 while Present (Alt) loop
10286
10287 if Nkind (Alt) = N_Accept_Alternative then
10288 Process_Accept_Alternative (Alt, Index, Proc);
10289 Index := Index + 1;
10290
10291 if Present
10292 (Handled_Statement_Sequence (Accept_Statement (Alt)))
10293 then
10294 Next (Proc);
10295 end if;
10296
10297 elsif Nkind (Alt) = N_Delay_Alternative then
10298 Process_Delay_Alternative (Alt, Delay_Num);
10299 Delay_Num := Delay_Num + 1;
10300 end if;
10301
10302 Next (Alt);
10303 end loop;
10304
10305 -- An others choice is always added to the main case, as well
10306 -- as the delay case (to satisfy the compiler).
10307
10308 Append_To (Alt_List,
10309 Make_Case_Statement_Alternative (Loc,
10310 Discrete_Choices =>
10311 New_List (Make_Others_Choice (Loc)),
10312 Statements =>
10313 New_List (Make_Goto_Statement (Loc,
10314 Name => New_Copy (Identifier (End_Lab))))));
10315
10316 Accept_Case := New_List (
10317 Make_Case_Statement (Loc,
10318 Expression => New_Reference_To (Xnam, Loc),
10319 Alternatives => Alt_List));
10320
10321 Append_List (Trailing_List, Accept_Case);
10322 Append (End_Lab, Accept_Case);
10323 Append_List (Body_List, Decls);
10324
10325 -- Construct case statement for trailing statements of delay
10326 -- alternatives, if there are several of them.
10327
10328 if Delay_Count > 1 then
10329 Append_To (Delay_Alt_List,
10330 Make_Case_Statement_Alternative (Loc,
10331 Discrete_Choices =>
10332 New_List (Make_Others_Choice (Loc)),
10333 Statements =>
10334 New_List (Make_Null_Statement (Loc))));
10335
10336 Delay_Case := New_List (
10337 Make_Case_Statement (Loc,
10338 Expression => New_Reference_To (Delay_Index, Loc),
10339 Alternatives => Delay_Alt_List));
10340 else
10341 Delay_Case := Delay_Alt_List;
10342 end if;
10343
10344 -- If there are no delay alternatives, we append the case statement
10345 -- to the statement list.
10346
10347 if Delay_Count = 0 then
10348 Append_List (Accept_Case, Stats);
10349
10350 -- Delay alternatives present
10351
10352 else
10353 -- If delay alternatives are present we generate:
10354
10355 -- find minimum delay.
10356 -- DX := minimum delay;
10357 -- M := <delay mode>;
10358 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10359 -- DX, MX, X);
10360 --
10361 -- if X = No_Rendezvous then
10362 -- case statement for delay statements.
10363 -- else
10364 -- case statement for accept alternatives.
10365 -- end if;
10366
10367 declare
10368 Cases : Node_Id;
10369 Stmt : Node_Id;
10370 Parms : List_Id;
10371 Parm : Node_Id;
10372 Conv : Node_Id;
10373
10374 begin
10375 -- The type of the delay expression is known to be legal
10376
10377 if Time_Type = Standard_Duration then
10378 Conv := New_Reference_To (Delay_Min, Loc);
10379
10380 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10381 Conv := Make_Function_Call (Loc,
10382 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10383 New_List (New_Reference_To (Delay_Min, Loc)));
10384
10385 else
10386 pragma Assert
10387 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10388
10389 Conv := Make_Function_Call (Loc,
10390 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10391 New_List (New_Reference_To (Delay_Min, Loc)));
10392 end if;
10393
10394 Stmt := Make_Assignment_Statement (Loc,
10395 Name => New_Reference_To (D, Loc),
10396 Expression => Conv);
10397
10398 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10399
10400 Parms := Parameter_Associations (Select_Call);
10401 Parm := First (Parms);
10402
10403 while Present (Parm)
10404 and then Parm /= Select_Mode
10405 loop
10406 Next (Parm);
10407 end loop;
10408
10409 pragma Assert (Present (Parm));
10410 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10411 Analyze (Parm);
10412
10413 -- Prepare two new parameters of Duration and Delay_Mode type
10414 -- which represent the value and the mode of the minimum delay.
10415
10416 Next (Parm);
10417 Insert_After (Parm, New_Reference_To (M, Loc));
10418 Insert_After (Parm, New_Reference_To (D, Loc));
10419
10420 -- Create a call to RTS
10421
10422 Rewrite (Select_Call,
10423 Make_Procedure_Call_Statement (Loc,
10424 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10425 Parameter_Associations => Parms));
10426
10427 -- This new call should follow the calculation of the minimum
10428 -- delay.
10429
10430 Insert_List_Before (Select_Call, Delay_List);
10431
10432 if Check_Guard then
10433 Stmt :=
10434 Make_Implicit_If_Statement (N,
10435 Condition => New_Reference_To (Guard_Open, Loc),
10436 Then_Statements =>
10437 New_List (New_Copy_Tree (Stmt),
10438 New_Copy_Tree (Select_Call)),
10439 Else_Statements => Accept_Or_Raise);
10440 Rewrite (Select_Call, Stmt);
10441 else
10442 Insert_Before (Select_Call, Stmt);
10443 end if;
10444
10445 Cases :=
10446 Make_Implicit_If_Statement (N,
10447 Condition => Make_Op_Eq (Loc,
10448 Left_Opnd => New_Reference_To (Xnam, Loc),
10449 Right_Opnd =>
10450 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10451
10452 Then_Statements => Delay_Case,
10453 Else_Statements => Accept_Case);
10454
10455 Append (Cases, Stats);
10456 end;
10457 end if;
10458
10459 -- Replace accept statement with appropriate block
10460
10461 Block :=
10462 Make_Block_Statement (Loc,
10463 Declarations => Decls,
10464 Handled_Statement_Sequence =>
10465 Make_Handled_Sequence_Of_Statements (Loc,
10466 Statements => Stats));
10467
10468 Rewrite (N, Block);
10469 Analyze (N);
10470
10471 -- Note: have to worry more about abort deferral in above code ???
10472
10473 -- Final step is to unstack the Accept_Address entries for all accept
10474 -- statements appearing in accept alternatives in the select statement
10475
10476 Alt := First (Alts);
10477 while Present (Alt) loop
10478 if Nkind (Alt) = N_Accept_Alternative then
10479 Remove_Last_Elmt (Accept_Address
10480 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10481 end if;
10482
10483 Next (Alt);
10484 end loop;
10485 end Expand_N_Selective_Accept;
10486
10487 --------------------------------------
10488 -- Expand_N_Single_Task_Declaration --
10489 --------------------------------------
10490
10491 -- Single task declarations should never be present after semantic
10492 -- analysis, since we expect them to be replaced by a declaration of an
10493 -- anonymous task type, followed by a declaration of the task object. We
10494 -- include this routine to make sure that is happening!
10495
10496 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10497 begin
10498 raise Program_Error;
10499 end Expand_N_Single_Task_Declaration;
10500
10501 ------------------------
10502 -- Expand_N_Task_Body --
10503 ------------------------
10504
10505 -- Given a task body
10506
10507 -- task body tname is
10508 -- <declarations>
10509 -- begin
10510 -- <statements>
10511 -- end x;
10512
10513 -- This expansion routine converts it into a procedure and sets the
10514 -- elaboration flag for the procedure to true, to represent the fact
10515 -- that the task body is now elaborated:
10516
10517 -- procedure tnameB (_Task : access tnameV) is
10518 -- discriminal : dtype renames _Task.discriminant;
10519
10520 -- procedure _clean is
10521 -- begin
10522 -- Abort_Defer.all;
10523 -- Complete_Task;
10524 -- Abort_Undefer.all;
10525 -- return;
10526 -- end _clean;
10527
10528 -- begin
10529 -- Abort_Undefer.all;
10530 -- <declarations>
10531 -- System.Task_Stages.Complete_Activation;
10532 -- <statements>
10533 -- at end
10534 -- _clean;
10535 -- end tnameB;
10536
10537 -- tnameE := True;
10538
10539 -- In addition, if the task body is an activator, then a call to activate
10540 -- tasks is added at the start of the statements, before the call to
10541 -- Complete_Activation, and if in addition the task is a master then it
10542 -- must be established as a master. These calls are inserted and analyzed
10543 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10544 -- expanded.
10545
10546 -- There is one discriminal declaration line generated for each
10547 -- discriminant that is present to provide an easy reference point for
10548 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10549
10550 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10551 -- task body procedures have a profile (Arg : System.Address). That is
10552 -- needed because GNARLI has to use the same access-to-subprogram type
10553 -- for all task types. We depend here on knowing that in GNAT, passing
10554 -- an address argument by value is identical to passing a record value
10555 -- by access (in either case a single pointer is passed), so even though
10556 -- this procedure has the wrong profile. In fact it's all OK, since the
10557 -- callings sequence is identical.
10558
10559 procedure Expand_N_Task_Body (N : Node_Id) is
10560 Loc : constant Source_Ptr := Sloc (N);
10561 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10562 Call : Node_Id;
10563 New_N : Node_Id;
10564
10565 Insert_Nod : Node_Id;
10566 -- Used to determine the proper location of wrapper body insertions
10567
10568 begin
10569 -- Add renaming declarations for discriminals and a declaration for the
10570 -- entry family index (if applicable).
10571
10572 Install_Private_Data_Declarations
10573 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10574
10575 -- Add a call to Abort_Undefer at the very beginning of the task
10576 -- body since this body is called with abort still deferred.
10577
10578 if Abort_Allowed then
10579 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10580 Insert_Before
10581 (First (Statements (Handled_Statement_Sequence (N))), Call);
10582 Analyze (Call);
10583 end if;
10584
10585 -- The statement part has already been protected with an at_end and
10586 -- cleanup actions. The call to Complete_Activation must be placed
10587 -- at the head of the sequence of statements of that block. The
10588 -- declarations have been merged in this sequence of statements but
10589 -- the first real statement is accessible from the First_Real_Statement
10590 -- field (which was set for exactly this purpose).
10591
10592 if Restricted_Profile then
10593 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10594 else
10595 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10596 end if;
10597
10598 Insert_Before
10599 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10600 Analyze (Call);
10601
10602 New_N :=
10603 Make_Subprogram_Body (Loc,
10604 Specification => Build_Task_Proc_Specification (Ttyp),
10605 Declarations => Declarations (N),
10606 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10607
10608 -- If the task contains generic instantiations, cleanup actions are
10609 -- delayed until after instantiation. Transfer the activation chain to
10610 -- the subprogram, to insure that the activation call is properly
10611 -- generated. It the task body contains inner tasks, indicate that the
10612 -- subprogram is a task master.
10613
10614 if Delay_Cleanups (Ttyp) then
10615 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10616 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10617 end if;
10618
10619 Rewrite (N, New_N);
10620 Analyze (N);
10621
10622 -- Set elaboration flag immediately after task body. If the body is a
10623 -- subunit, the flag is set in the declarative part containing the stub.
10624
10625 if Nkind (Parent (N)) /= N_Subunit then
10626 Insert_After (N,
10627 Make_Assignment_Statement (Loc,
10628 Name =>
10629 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10630 Expression => New_Reference_To (Standard_True, Loc)));
10631 end if;
10632
10633 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10634 -- the task body. At this point all wrapper specs have been created,
10635 -- frozen and included in the dispatch table for the task type.
10636
10637 if Ada_Version >= Ada_2005 then
10638 if Nkind (Parent (N)) = N_Subunit then
10639 Insert_Nod := Corresponding_Stub (Parent (N));
10640 else
10641 Insert_Nod := N;
10642 end if;
10643
10644 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10645 end if;
10646 end Expand_N_Task_Body;
10647
10648 ------------------------------------
10649 -- Expand_N_Task_Type_Declaration --
10650 ------------------------------------
10651
10652 -- We have several things to do. First we must create a Boolean flag used
10653 -- to mark if the body is elaborated yet. This variable gets set to True
10654 -- when the body of the task is elaborated (we can't rely on the normal
10655 -- ABE mechanism for the task body, since we need to pass an access to
10656 -- this elaboration boolean to the runtime routines).
10657
10658 -- taskE : aliased Boolean := False;
10659
10660 -- Next a variable is declared to hold the task stack size (either the
10661 -- default : Unspecified_Size, or a value that is set by a pragma
10662 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10663 -- the variable is initialized with this value:
10664
10665 -- taskZ : Size_Type := Unspecified_Size;
10666 -- or
10667 -- taskZ : Size_Type := Size_Type (size_expression);
10668
10669 -- Note: No variable is needed to hold the task relative deadline since
10670 -- its value would never be static because the parameter is of a private
10671 -- type (Ada.Real_Time.Time_Span).
10672
10673 -- Next we create a corresponding record type declaration used to represent
10674 -- values of this task. The general form of this type declaration is
10675
10676 -- type taskV (discriminants) is record
10677 -- _Task_Id : Task_Id;
10678 -- entry_family : array (bounds) of Void;
10679 -- _Priority : Integer := priority_expression;
10680 -- _Size : Size_Type := size_expression;
10681 -- _Task_Info : Task_Info_Type := task_info_expression;
10682 -- _CPU : Integer := cpu_range_expression;
10683 -- _Relative_Deadline : Time_Span := time_span_expression;
10684 -- _Domain : Dispatching_Domain := dd_expression;
10685 -- end record;
10686
10687 -- The discriminants are present only if the corresponding task type has
10688 -- discriminants, and they exactly mirror the task type discriminants.
10689
10690 -- The Id field is always present. It contains the Task_Id value, as set by
10691 -- the call to Create_Task. Note that although the task is limited, the
10692 -- task value record type is not limited, so there is no problem in passing
10693 -- this field as an out parameter to Create_Task.
10694
10695 -- One entry_family component is present for each entry family in the task
10696 -- definition. The bounds correspond to the bounds of the entry family
10697 -- (which may depend on discriminants). The element type is void, since we
10698 -- only need the bounds information for determining the entry index. Note
10699 -- that the use of an anonymous array would normally be illegal in this
10700 -- context, but this is a parser check, and the semantics is quite prepared
10701 -- to handle such a case.
10702
10703 -- The _Size field is present only if a Storage_Size pragma appears in the
10704 -- task definition. The expression captures the argument that was present
10705 -- in the pragma, and is used to override the task stack size otherwise
10706 -- associated with the task type.
10707
10708 -- The _Priority field is present only if a Priority or Interrupt_Priority
10709 -- pragma appears in the task definition. The expression captures the
10710 -- argument that was present in the pragma, and is used to provide the Size
10711 -- parameter to the call to Create_Task.
10712
10713 -- The _Task_Info field is present only if a Task_Info pragma appears in
10714 -- the task definition. The expression captures the argument that was
10715 -- present in the pragma, and is used to provide the Task_Image parameter
10716 -- to the call to Create_Task.
10717
10718 -- The _CPU field is present only if a CPU pragma appears in the task
10719 -- definition. The expression captures the argument that was present in
10720 -- the pragma, and is used to provide the CPU parameter to the call to
10721 -- Create_Task.
10722
10723 -- The _Relative_Deadline field is present only if a Relative_Deadline
10724 -- pragma appears in the task definition. The expression captures the
10725 -- argument that was present in the pragma, and is used to provide the
10726 -- Relative_Deadline parameter to the call to Create_Task.
10727
10728 -- The _Domain field is present only if a Dispatching_Domain pragma or
10729 -- aspect appears in the task definition. The expression captures the
10730 -- argument that was present in the pragma or aspect, and is used to
10731 -- provide the Dispatching_Domain parameter to the call to Create_Task.
10732
10733 -- When a task is declared, an instance of the task value record is
10734 -- created. The elaboration of this declaration creates the correct bounds
10735 -- for the entry families, and also evaluates the size, priority, and
10736 -- task_Info expressions if needed. The initialization routine for the task
10737 -- type itself then calls Create_Task with appropriate parameters to
10738 -- initialize the value of the Task_Id field.
10739
10740 -- Note: the address of this record is passed as the "Discriminants"
10741 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10742 -- body procedure, it does not matter that it does not quite match the
10743 -- GNARLI model of what is being passed (the record contains more than just
10744 -- the discriminants, but the discriminants can be found from the record
10745 -- value).
10746
10747 -- The Entity_Id for this created record type is placed in the
10748 -- Corresponding_Record_Type field of the associated task type entity.
10749
10750 -- Next we create a procedure specification for the task body procedure:
10751
10752 -- procedure taskB (_Task : access taskV);
10753
10754 -- Note that this must come after the record type declaration, since
10755 -- the spec refers to this type. It turns out that the initialization
10756 -- procedure for the value type references the task body spec, but that's
10757 -- fine, since it won't be generated till the freeze point for the type,
10758 -- which is certainly after the task body spec declaration.
10759
10760 -- Finally, we set the task index value field of the entry attribute in
10761 -- the case of a simple entry.
10762
10763 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10764 Loc : constant Source_Ptr := Sloc (N);
10765 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10766 Tasknm : constant Name_Id := Chars (Tasktyp);
10767 Taskdef : constant Node_Id := Task_Definition (N);
10768
10769 Proc_Spec : Node_Id;
10770 Rec_Decl : Node_Id;
10771 Rec_Ent : Entity_Id;
10772 Cdecls : List_Id;
10773 Elab_Decl : Node_Id;
10774 Size_Decl : Node_Id;
10775 Body_Decl : Node_Id;
10776 Task_Size : Node_Id;
10777 Ent_Stack : Entity_Id;
10778 Decl_Stack : Node_Id;
10779
10780 begin
10781 -- If already expanded, nothing to do
10782
10783 if Present (Corresponding_Record_Type (Tasktyp)) then
10784 return;
10785 end if;
10786
10787 -- Here we will do the expansion
10788
10789 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10790
10791 Rec_Ent := Defining_Identifier (Rec_Decl);
10792 Cdecls := Component_Items (Component_List
10793 (Type_Definition (Rec_Decl)));
10794
10795 Qualify_Entity_Names (N);
10796
10797 -- First create the elaboration variable
10798
10799 Elab_Decl :=
10800 Make_Object_Declaration (Loc,
10801 Defining_Identifier =>
10802 Make_Defining_Identifier (Sloc (Tasktyp),
10803 Chars => New_External_Name (Tasknm, 'E')),
10804 Aliased_Present => True,
10805 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10806 Expression => New_Reference_To (Standard_False, Loc));
10807 Insert_After (N, Elab_Decl);
10808
10809 -- Next create the declaration of the size variable (tasknmZ)
10810
10811 Set_Storage_Size_Variable (Tasktyp,
10812 Make_Defining_Identifier (Sloc (Tasktyp),
10813 Chars => New_External_Name (Tasknm, 'Z')));
10814
10815 if Present (Taskdef)
10816 and then Has_Storage_Size_Pragma (Taskdef)
10817 and then
10818 Is_Static_Expression
10819 (Expression
10820 (First (Pragma_Argument_Associations
10821 (Find_Task_Or_Protected_Pragma
10822 (Taskdef, Name_Storage_Size)))))
10823 then
10824 Size_Decl :=
10825 Make_Object_Declaration (Loc,
10826 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10827 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10828 Expression =>
10829 Convert_To (RTE (RE_Size_Type),
10830 Relocate_Node
10831 (Expression (First (Pragma_Argument_Associations
10832 (Find_Task_Or_Protected_Pragma
10833 (Taskdef, Name_Storage_Size)))))));
10834
10835 else
10836 Size_Decl :=
10837 Make_Object_Declaration (Loc,
10838 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10839 Object_Definition =>
10840 New_Reference_To (RTE (RE_Size_Type), Loc),
10841 Expression =>
10842 New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10843 end if;
10844
10845 Insert_After (Elab_Decl, Size_Decl);
10846
10847 -- Next build the rest of the corresponding record declaration. This is
10848 -- done last, since the corresponding record initialization procedure
10849 -- will reference the previously created entities.
10850
10851 -- Fill in the component declarations -- first the _Task_Id field
10852
10853 Append_To (Cdecls,
10854 Make_Component_Declaration (Loc,
10855 Defining_Identifier =>
10856 Make_Defining_Identifier (Loc, Name_uTask_Id),
10857 Component_Definition =>
10858 Make_Component_Definition (Loc,
10859 Aliased_Present => False,
10860 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10861 Loc))));
10862
10863 -- Declare static ATCB (that is, created by the expander) if we are
10864 -- using the Restricted run time.
10865
10866 if Restricted_Profile then
10867 Append_To (Cdecls,
10868 Make_Component_Declaration (Loc,
10869 Defining_Identifier =>
10870 Make_Defining_Identifier (Loc, Name_uATCB),
10871
10872 Component_Definition =>
10873 Make_Component_Definition (Loc,
10874 Aliased_Present => True,
10875 Subtype_Indication => Make_Subtype_Indication (Loc,
10876 Subtype_Mark =>
10877 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
10878
10879 Constraint =>
10880 Make_Index_Or_Discriminant_Constraint (Loc,
10881 Constraints =>
10882 New_List (Make_Integer_Literal (Loc, 0)))))));
10883
10884 end if;
10885
10886 -- Declare static stack (that is, created by the expander) if we are
10887 -- using the Restricted run time on a bare board configuration.
10888
10889 if Restricted_Profile
10890 and then Preallocated_Stacks_On_Target
10891 then
10892 -- First we need to extract the appropriate stack size
10893
10894 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10895
10896 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10897 declare
10898 Expr_N : constant Node_Id :=
10899 Expression (First (
10900 Pragma_Argument_Associations (
10901 Find_Task_Or_Protected_Pragma
10902 (Taskdef, Name_Storage_Size))));
10903 Etyp : constant Entity_Id := Etype (Expr_N);
10904 P : constant Node_Id := Parent (Expr_N);
10905
10906 begin
10907 -- The stack is defined inside the corresponding record.
10908 -- Therefore if the size of the stack is set by means of
10909 -- a discriminant, we must reference the discriminant of the
10910 -- corresponding record type.
10911
10912 if Nkind (Expr_N) in N_Has_Entity
10913 and then Present (Discriminal_Link (Entity (Expr_N)))
10914 then
10915 Task_Size :=
10916 New_Reference_To
10917 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10918 Loc);
10919 Set_Parent (Task_Size, P);
10920 Set_Etype (Task_Size, Etyp);
10921 Set_Analyzed (Task_Size);
10922
10923 else
10924 Task_Size := Relocate_Node (Expr_N);
10925 end if;
10926 end;
10927
10928 else
10929 Task_Size :=
10930 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10931 end if;
10932
10933 Decl_Stack := Make_Component_Declaration (Loc,
10934 Defining_Identifier => Ent_Stack,
10935
10936 Component_Definition =>
10937 Make_Component_Definition (Loc,
10938 Aliased_Present => True,
10939 Subtype_Indication => Make_Subtype_Indication (Loc,
10940 Subtype_Mark =>
10941 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10942
10943 Constraint =>
10944 Make_Index_Or_Discriminant_Constraint (Loc,
10945 Constraints => New_List (Make_Range (Loc,
10946 Low_Bound => Make_Integer_Literal (Loc, 1),
10947 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10948 Task_Size)))))));
10949
10950 Append_To (Cdecls, Decl_Stack);
10951
10952 -- The appropriate alignment for the stack is ensured by the run-time
10953 -- code in charge of task creation.
10954
10955 end if;
10956
10957 -- Add components for entry families
10958
10959 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10960
10961 -- Add the _Priority component if a Priority pragma is present
10962
10963 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10964 declare
10965 Prag : constant Node_Id :=
10966 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10967 Expr : Node_Id;
10968
10969 begin
10970 Expr := First (Pragma_Argument_Associations (Prag));
10971
10972 if Nkind (Expr) = N_Pragma_Argument_Association then
10973 Expr := Expression (Expr);
10974 end if;
10975
10976 Expr := New_Copy_Tree (Expr);
10977
10978 -- Add conversion to proper type to do range check if required
10979 -- Note that for runtime units, we allow out of range interrupt
10980 -- priority values to be used in a priority pragma. This is for
10981 -- the benefit of some versions of System.Interrupts which use
10982 -- a special server task with maximum interrupt priority.
10983
10984 if Pragma_Name (Prag) = Name_Priority
10985 and then not GNAT_Mode
10986 then
10987 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10988 else
10989 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10990 end if;
10991
10992 Append_To (Cdecls,
10993 Make_Component_Declaration (Loc,
10994 Defining_Identifier =>
10995 Make_Defining_Identifier (Loc, Name_uPriority),
10996 Component_Definition =>
10997 Make_Component_Definition (Loc,
10998 Aliased_Present => False,
10999 Subtype_Indication => New_Reference_To (Standard_Integer,
11000 Loc)),
11001 Expression => Expr));
11002 end;
11003 end if;
11004
11005 -- Add the _Task_Size component if a Storage_Size pragma is present
11006
11007 if Present (Taskdef)
11008 and then Has_Storage_Size_Pragma (Taskdef)
11009 then
11010 Append_To (Cdecls,
11011 Make_Component_Declaration (Loc,
11012 Defining_Identifier =>
11013 Make_Defining_Identifier (Loc, Name_uSize),
11014
11015 Component_Definition =>
11016 Make_Component_Definition (Loc,
11017 Aliased_Present => False,
11018 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
11019 Loc)),
11020
11021 Expression =>
11022 Convert_To (RTE (RE_Size_Type),
11023 Relocate_Node (
11024 Expression (First (
11025 Pragma_Argument_Associations (
11026 Find_Task_Or_Protected_Pragma
11027 (Taskdef, Name_Storage_Size))))))));
11028 end if;
11029
11030 -- Add the _Task_Info component if a Task_Info pragma is present
11031
11032 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
11033 Append_To (Cdecls,
11034 Make_Component_Declaration (Loc,
11035 Defining_Identifier =>
11036 Make_Defining_Identifier (Loc, Name_uTask_Info),
11037
11038 Component_Definition =>
11039 Make_Component_Definition (Loc,
11040 Aliased_Present => False,
11041 Subtype_Indication =>
11042 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
11043
11044 Expression => New_Copy (
11045 Expression (First (
11046 Pragma_Argument_Associations (
11047 Find_Task_Or_Protected_Pragma
11048 (Taskdef, Name_Task_Info)))))));
11049 end if;
11050
11051 -- Add the _CPU component if a CPU pragma is present
11052
11053 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
11054 Append_To (Cdecls,
11055 Make_Component_Declaration (Loc,
11056 Defining_Identifier =>
11057 Make_Defining_Identifier (Loc, Name_uCPU),
11058
11059 Component_Definition =>
11060 Make_Component_Definition (Loc,
11061 Aliased_Present => False,
11062 Subtype_Indication =>
11063 New_Reference_To (RTE (RE_CPU_Range), Loc)),
11064
11065 Expression => New_Copy (
11066 Expression (First (
11067 Pragma_Argument_Associations (
11068 Find_Task_Or_Protected_Pragma
11069 (Taskdef, Name_CPU)))))));
11070 end if;
11071
11072 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11073 -- present. If we are using a restricted run time this component will
11074 -- not be added (deadlines are not allowed by the Ravenscar profile).
11075
11076 if not Restricted_Profile
11077 and then Present (Taskdef)
11078 and then Has_Relative_Deadline_Pragma (Taskdef)
11079 then
11080 Append_To (Cdecls,
11081 Make_Component_Declaration (Loc,
11082 Defining_Identifier =>
11083 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
11084
11085 Component_Definition =>
11086 Make_Component_Definition (Loc,
11087 Aliased_Present => False,
11088 Subtype_Indication =>
11089 New_Reference_To (RTE (RE_Time_Span), Loc)),
11090
11091 Expression =>
11092 Convert_To (RTE (RE_Time_Span),
11093 Relocate_Node (
11094 Expression (First (
11095 Pragma_Argument_Associations (
11096 Find_Task_Or_Protected_Pragma
11097 (Taskdef, Name_Relative_Deadline))))))));
11098 end if;
11099
11100 -- Add the _Dispatching_Domain component if a Dispatching_Domain pragma
11101 -- or aspect is present. If we are using a restricted run time this
11102 -- component will not be added (dispatching domains are not allowed by
11103 -- the Ravenscar profile).
11104
11105 if not Restricted_Profile
11106 and then Present (Taskdef)
11107 and then Has_Pragma_Dispatching_Domain (Taskdef)
11108 then
11109 Append_To (Cdecls,
11110 Make_Component_Declaration (Loc,
11111 Defining_Identifier =>
11112 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
11113
11114 Component_Definition =>
11115 Make_Component_Definition (Loc,
11116 Aliased_Present => False,
11117 Subtype_Indication =>
11118 New_Reference_To
11119 (RTE (RE_Dispatching_Domain_Access), Loc)),
11120
11121 Expression =>
11122 Unchecked_Convert_To (RTE (RE_Dispatching_Domain_Access),
11123 Relocate_Node
11124 (Expression
11125 (First
11126 (Pragma_Argument_Associations
11127 (Find_Task_Or_Protected_Pragma
11128 (Taskdef, Name_Dispatching_Domain))))))));
11129 end if;
11130
11131 Insert_After (Size_Decl, Rec_Decl);
11132
11133 -- Analyze the record declaration immediately after construction,
11134 -- because the initialization procedure is needed for single task
11135 -- declarations before the next entity is analyzed.
11136
11137 Analyze (Rec_Decl);
11138
11139 -- Create the declaration of the task body procedure
11140
11141 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
11142 Body_Decl :=
11143 Make_Subprogram_Declaration (Loc,
11144 Specification => Proc_Spec);
11145
11146 Insert_After (Rec_Decl, Body_Decl);
11147
11148 -- The subprogram does not comes from source, so we have to indicate the
11149 -- need for debugging information explicitly.
11150
11151 if Comes_From_Source (Original_Node (N)) then
11152 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
11153 end if;
11154
11155 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11156 -- the corresponding record has been frozen.
11157
11158 if Ada_Version >= Ada_2005 then
11159 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
11160 end if;
11161
11162 -- Ada 2005 (AI-345): We must defer freezing to allow further
11163 -- declaration of primitive subprograms covering task interfaces
11164
11165 if Ada_Version <= Ada_95 then
11166
11167 -- Now we can freeze the corresponding record. This needs manually
11168 -- freezing, since it is really part of the task type, and the task
11169 -- type is frozen at this stage. We of course need the initialization
11170 -- procedure for this corresponding record type and we won't get it
11171 -- in time if we don't freeze now.
11172
11173 declare
11174 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
11175 begin
11176 if Is_Non_Empty_List (L) then
11177 Insert_List_After (Body_Decl, L);
11178 end if;
11179 end;
11180 end if;
11181
11182 -- Complete the expansion of access types to the current task type, if
11183 -- any were declared.
11184
11185 Expand_Previous_Access_Type (Tasktyp);
11186
11187 -- Create wrappers for entries that have pre/postconditions
11188
11189 declare
11190 Ent : Entity_Id;
11191
11192 begin
11193 Ent := First_Entity (Tasktyp);
11194 while Present (Ent) loop
11195 if Ekind_In (Ent, E_Entry, E_Entry_Family)
11196 and then Present (Spec_PPC_List (Contract (Ent)))
11197 then
11198 Build_PPC_Wrapper (Ent, N);
11199 end if;
11200
11201 Next_Entity (Ent);
11202 end loop;
11203 end;
11204 end Expand_N_Task_Type_Declaration;
11205
11206 -------------------------------
11207 -- Expand_N_Timed_Entry_Call --
11208 -------------------------------
11209
11210 -- A timed entry call in normal case is not implemented using ATC mechanism
11211 -- anymore for efficiency reason.
11212
11213 -- select
11214 -- T.E;
11215 -- S1;
11216 -- or
11217 -- Delay D;
11218 -- S2;
11219 -- end select;
11220
11221 -- is expanded as follow:
11222
11223 -- 1) When T.E is a task entry_call;
11224
11225 -- declare
11226 -- B : Boolean;
11227 -- X : Task_Entry_Index := <entry index>;
11228 -- DX : Duration := To_Duration (D);
11229 -- M : Delay_Mode := <discriminant>;
11230 -- P : parms := (parm, parm, parm);
11231
11232 -- begin
11233 -- Timed_Protected_Entry_Call
11234 -- (<acceptor-task>, X, P'Address, DX, M, B);
11235 -- if B then
11236 -- S1;
11237 -- else
11238 -- S2;
11239 -- end if;
11240 -- end;
11241
11242 -- 2) When T.E is a protected entry_call;
11243
11244 -- declare
11245 -- B : Boolean;
11246 -- X : Protected_Entry_Index := <entry index>;
11247 -- DX : Duration := To_Duration (D);
11248 -- M : Delay_Mode := <discriminant>;
11249 -- P : parms := (parm, parm, parm);
11250
11251 -- begin
11252 -- Timed_Protected_Entry_Call
11253 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
11254 -- if B then
11255 -- S1;
11256 -- else
11257 -- S2;
11258 -- end if;
11259 -- end;
11260
11261 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
11262
11263 -- declare
11264 -- B : Boolean := False;
11265 -- C : Ada.Tags.Prim_Op_Kind;
11266 -- DX : Duration := To_Duration (D)
11267 -- K : Ada.Tags.Tagged_Kind :=
11268 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
11269 -- M : Integer :=...;
11270 -- P : Parameters := (Param1 .. ParamN);
11271 -- S : Integer;
11272
11273 -- begin
11274 -- if K = Ada.Tags.TK_Limited_Tagged then
11275 -- <dispatching-call>;
11276 -- <triggering-statements>
11277
11278 -- else
11279 -- S :=
11280 -- Ada.Tags.Get_Offset_Index
11281 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
11282
11283 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
11284
11285 -- if C = POK_Protected_Entry
11286 -- or else C = POK_Task_Entry
11287 -- then
11288 -- Param1 := P.Param1;
11289 -- ...
11290 -- ParamN := P.ParamN;
11291 -- end if;
11292
11293 -- if B then
11294 -- if C = POK_Procedure
11295 -- or else C = POK_Protected_Procedure
11296 -- or else C = POK_Task_Procedure
11297 -- then
11298 -- <dispatching-call>;
11299 -- end if;
11300
11301 -- <triggering-statements>
11302 -- else
11303 -- <timed-statements>
11304 -- end if;
11305 -- end if;
11306 -- end;
11307
11308 -- The triggering statement and the sequence of timed statements have not
11309 -- been analyzed yet (see Analyzed_Timed_Entry_Call). They may contain
11310 -- local declarations, and therefore the copies that are made during
11311 -- expansion must be disjoint, as for any other inlining.
11312
11313 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
11314 Loc : constant Source_Ptr := Sloc (N);
11315
11316 E_Call : Node_Id :=
11317 Entry_Call_Statement (Entry_Call_Alternative (N));
11318 E_Stats : constant List_Id :=
11319 Statements (Entry_Call_Alternative (N));
11320 D_Stat : Node_Id :=
11321 Delay_Statement (Delay_Alternative (N));
11322 D_Stats : constant List_Id :=
11323 Statements (Delay_Alternative (N));
11324
11325 Actuals : List_Id;
11326 Blk_Typ : Entity_Id;
11327 Call : Node_Id;
11328 Call_Ent : Entity_Id;
11329 Conc_Typ_Stmts : List_Id;
11330 Concval : Node_Id;
11331 D_Conv : Node_Id;
11332 D_Disc : Node_Id;
11333 D_Type : Entity_Id;
11334 Decls : List_Id;
11335 Dummy : Node_Id;
11336 Ename : Node_Id;
11337 Formals : List_Id;
11338 Index : Node_Id;
11339 Is_Disp_Select : Boolean;
11340 Lim_Typ_Stmts : List_Id;
11341 N_Stats : List_Id;
11342 Obj : Entity_Id;
11343 Param : Node_Id;
11344 Params : List_Id;
11345 Stmt : Node_Id;
11346 Stmts : List_Id;
11347 Unpack : List_Id;
11348
11349 B : Entity_Id; -- Call status flag
11350 C : Entity_Id; -- Call kind
11351 D : Entity_Id; -- Delay
11352 K : Entity_Id; -- Tagged kind
11353 M : Entity_Id; -- Delay mode
11354 P : Entity_Id; -- Parameter block
11355 S : Entity_Id; -- Primitive operation slot
11356
11357 begin
11358 -- Under the Ravenscar profile, timed entry calls are excluded. An error
11359 -- was already reported on spec, so do not attempt to expand the call.
11360
11361 if Restriction_Active (No_Select_Statements) then
11362 return;
11363 end if;
11364
11365 Process_Statements_For_Controlled_Objects (Entry_Call_Alternative (N));
11366 Process_Statements_For_Controlled_Objects (Delay_Alternative (N));
11367
11368 -- The arguments in the call may require dynamic allocation, and the
11369 -- call statement may have been transformed into a block. The block
11370 -- may contain additional declarations for internal entities, and the
11371 -- original call is found by sequential search.
11372
11373 if Nkind (E_Call) = N_Block_Statement then
11374 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
11375 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
11376 N_Entry_Call_Statement)
11377 loop
11378 Next (E_Call);
11379 end loop;
11380 end if;
11381
11382 Is_Disp_Select :=
11383 Ada_Version >= Ada_2005
11384 and then Nkind (E_Call) = N_Procedure_Call_Statement;
11385
11386 if Is_Disp_Select then
11387 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11388
11389 Decls := New_List;
11390 Stmts := New_List;
11391
11392 -- Generate:
11393 -- B : Boolean := False;
11394
11395 B := Build_B (Loc, Decls);
11396
11397 -- Generate:
11398 -- C : Ada.Tags.Prim_Op_Kind;
11399
11400 C := Build_C (Loc, Decls);
11401
11402 -- Because the analysis of all statements was disabled, manually
11403 -- analyze the delay statement.
11404
11405 Analyze (D_Stat);
11406 D_Stat := Original_Node (D_Stat);
11407
11408 else
11409 -- Build an entry call using Simple_Entry_Call
11410
11411 Extract_Entry (E_Call, Concval, Ename, Index);
11412 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11413
11414 Decls := Declarations (E_Call);
11415 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11416
11417 if No (Decls) then
11418 Decls := New_List;
11419 end if;
11420
11421 -- Generate:
11422 -- B : Boolean;
11423
11424 B := Make_Defining_Identifier (Loc, Name_uB);
11425
11426 Prepend_To (Decls,
11427 Make_Object_Declaration (Loc,
11428 Defining_Identifier => B,
11429 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
11430 end if;
11431
11432 -- Duration and mode processing
11433
11434 D_Type := Base_Type (Etype (Expression (D_Stat)));
11435
11436 -- Use the type of the delay expression (Calendar or Real_Time) to
11437 -- generate the appropriate conversion.
11438
11439 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11440 D_Disc := Make_Integer_Literal (Loc, 0);
11441 D_Conv := Relocate_Node (Expression (D_Stat));
11442
11443 elsif Is_RTE (D_Type, RO_CA_Time) then
11444 D_Disc := Make_Integer_Literal (Loc, 1);
11445 D_Conv :=
11446 Make_Function_Call (Loc,
11447 Name => New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11448 Parameter_Associations =>
11449 New_List (New_Copy (Expression (D_Stat))));
11450
11451 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11452 D_Disc := Make_Integer_Literal (Loc, 2);
11453 D_Conv :=
11454 Make_Function_Call (Loc,
11455 Name => New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11456 Parameter_Associations =>
11457 New_List (New_Copy (Expression (D_Stat))));
11458 end if;
11459
11460 D := Make_Temporary (Loc, 'D');
11461
11462 -- Generate:
11463 -- D : Duration;
11464
11465 Append_To (Decls,
11466 Make_Object_Declaration (Loc,
11467 Defining_Identifier => D,
11468 Object_Definition => New_Reference_To (Standard_Duration, Loc)));
11469
11470 M := Make_Temporary (Loc, 'M');
11471
11472 -- Generate:
11473 -- M : Integer := (0 | 1 | 2);
11474
11475 Append_To (Decls,
11476 Make_Object_Declaration (Loc,
11477 Defining_Identifier => M,
11478 Object_Definition => New_Reference_To (Standard_Integer, Loc),
11479 Expression => D_Disc));
11480
11481 -- Do the assignment at this stage only because the evaluation of the
11482 -- expression must not occur before (see ACVC C97302A).
11483
11484 Append_To (Stmts,
11485 Make_Assignment_Statement (Loc,
11486 Name => New_Reference_To (D, Loc),
11487 Expression => D_Conv));
11488
11489 -- Parameter block processing
11490
11491 -- Manually create the parameter block for dispatching calls. In the
11492 -- case of entries, the block has already been created during the call
11493 -- to Build_Simple_Entry_Call.
11494
11495 if Is_Disp_Select then
11496
11497 -- Tagged kind processing, generate:
11498 -- K : Ada.Tags.Tagged_Kind :=
11499 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11500
11501 K := Build_K (Loc, Decls, Obj);
11502
11503 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11504 P :=
11505 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11506
11507 -- Dispatch table slot processing, generate:
11508 -- S : Integer;
11509
11510 S := Build_S (Loc, Decls);
11511
11512 -- Generate:
11513 -- S := Ada.Tags.Get_Offset_Index
11514 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11515
11516 Conc_Typ_Stmts :=
11517 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11518
11519 -- Generate:
11520 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11521
11522 -- where Obj is the controlling formal parameter, S is the dispatch
11523 -- table slot number of the dispatching operation, P is the wrapped
11524 -- parameter block, D is the duration, M is the duration mode, C is
11525 -- the call kind and B is the call status.
11526
11527 Params := New_List;
11528
11529 Append_To (Params, New_Copy_Tree (Obj));
11530 Append_To (Params, New_Reference_To (S, Loc));
11531 Append_To (Params,
11532 Make_Attribute_Reference (Loc,
11533 Prefix => New_Reference_To (P, Loc),
11534 Attribute_Name => Name_Address));
11535 Append_To (Params, New_Reference_To (D, Loc));
11536 Append_To (Params, New_Reference_To (M, Loc));
11537 Append_To (Params, New_Reference_To (C, Loc));
11538 Append_To (Params, New_Reference_To (B, Loc));
11539
11540 Append_To (Conc_Typ_Stmts,
11541 Make_Procedure_Call_Statement (Loc,
11542 Name =>
11543 New_Reference_To
11544 (Find_Prim_Op
11545 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
11546 Parameter_Associations => Params));
11547
11548 -- Generate:
11549 -- if C = POK_Protected_Entry
11550 -- or else C = POK_Task_Entry
11551 -- then
11552 -- Param1 := P.Param1;
11553 -- ...
11554 -- ParamN := P.ParamN;
11555 -- end if;
11556
11557 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11558
11559 -- Generate the if statement only when the packed parameters need
11560 -- explicit assignments to their corresponding actuals.
11561
11562 if Present (Unpack) then
11563 Append_To (Conc_Typ_Stmts,
11564 Make_If_Statement (Loc,
11565
11566 Condition =>
11567 Make_Or_Else (Loc,
11568 Left_Opnd =>
11569 Make_Op_Eq (Loc,
11570 Left_Opnd => New_Reference_To (C, Loc),
11571 Right_Opnd =>
11572 New_Reference_To
11573 (RTE (RE_POK_Protected_Entry), Loc)),
11574
11575 Right_Opnd =>
11576 Make_Op_Eq (Loc,
11577 Left_Opnd => New_Reference_To (C, Loc),
11578 Right_Opnd =>
11579 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11580
11581 Then_Statements => Unpack));
11582 end if;
11583
11584 -- Generate:
11585
11586 -- if B then
11587 -- if C = POK_Procedure
11588 -- or else C = POK_Protected_Procedure
11589 -- or else C = POK_Task_Procedure
11590 -- then
11591 -- <dispatching-call>
11592 -- end if;
11593 -- <triggering-statements>
11594 -- else
11595 -- <timed-statements>
11596 -- end if;
11597
11598 N_Stats := Copy_Separate_List (E_Stats);
11599
11600 Prepend_To (N_Stats,
11601 Make_If_Statement (Loc,
11602
11603 Condition =>
11604 Make_Or_Else (Loc,
11605 Left_Opnd =>
11606 Make_Op_Eq (Loc,
11607 Left_Opnd => New_Reference_To (C, Loc),
11608 Right_Opnd =>
11609 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11610
11611 Right_Opnd =>
11612 Make_Or_Else (Loc,
11613 Left_Opnd =>
11614 Make_Op_Eq (Loc,
11615 Left_Opnd => New_Reference_To (C, Loc),
11616 Right_Opnd =>
11617 New_Reference_To (RTE (
11618 RE_POK_Protected_Procedure), Loc)),
11619 Right_Opnd =>
11620 Make_Op_Eq (Loc,
11621 Left_Opnd => New_Reference_To (C, Loc),
11622 Right_Opnd =>
11623 New_Reference_To
11624 (RTE (RE_POK_Task_Procedure), Loc)))),
11625
11626 Then_Statements => New_List (E_Call)));
11627
11628 Append_To (Conc_Typ_Stmts,
11629 Make_If_Statement (Loc,
11630 Condition => New_Reference_To (B, Loc),
11631 Then_Statements => N_Stats,
11632 Else_Statements => D_Stats));
11633
11634 -- Generate:
11635 -- <dispatching-call>;
11636 -- <triggering-statements>
11637
11638 Lim_Typ_Stmts := Copy_Separate_List (E_Stats);
11639 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11640
11641 -- Generate:
11642 -- if K = Ada.Tags.TK_Limited_Tagged then
11643 -- Lim_Typ_Stmts
11644 -- else
11645 -- Conc_Typ_Stmts
11646 -- end if;
11647
11648 Append_To (Stmts,
11649 Make_If_Statement (Loc,
11650 Condition =>
11651 Make_Op_Eq (Loc,
11652 Left_Opnd => New_Reference_To (K, Loc),
11653 Right_Opnd =>
11654 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11655 Then_Statements => Lim_Typ_Stmts,
11656 Else_Statements => Conc_Typ_Stmts));
11657
11658 else
11659 -- Skip assignments to temporaries created for in-out parameters.
11660 -- This makes unwarranted assumptions about the shape of the expanded
11661 -- tree for the call, and should be cleaned up ???
11662
11663 Stmt := First (Stmts);
11664 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11665 Next (Stmt);
11666 end loop;
11667
11668 -- Do the assignment at this stage only because the evaluation
11669 -- of the expression must not occur before (see ACVC C97302A).
11670
11671 Insert_Before (Stmt,
11672 Make_Assignment_Statement (Loc,
11673 Name => New_Reference_To (D, Loc),
11674 Expression => D_Conv));
11675
11676 Call := Stmt;
11677 Params := Parameter_Associations (Call);
11678
11679 -- For a protected type, we build a Timed_Protected_Entry_Call
11680
11681 if Is_Protected_Type (Etype (Concval)) then
11682
11683 -- Create a new call statement
11684
11685 Param := First (Params);
11686 while Present (Param)
11687 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11688 loop
11689 Next (Param);
11690 end loop;
11691
11692 Dummy := Remove_Next (Next (Param));
11693
11694 -- Remove garbage is following the Cancel_Param if present
11695
11696 Dummy := Next (Param);
11697
11698 -- Remove the mode of the Protected_Entry_Call call, then remove
11699 -- the Communication_Block of the Protected_Entry_Call call, and
11700 -- finally add Duration and a Delay_Mode parameter
11701
11702 pragma Assert (Present (Param));
11703 Rewrite (Param, New_Reference_To (D, Loc));
11704
11705 Rewrite (Dummy, New_Reference_To (M, Loc));
11706
11707 -- Add a Boolean flag for successful entry call
11708
11709 Append_To (Params, New_Reference_To (B, Loc));
11710
11711 case Corresponding_Runtime_Package (Etype (Concval)) is
11712 when System_Tasking_Protected_Objects_Entries =>
11713 Rewrite (Call,
11714 Make_Procedure_Call_Statement (Loc,
11715 Name =>
11716 New_Reference_To
11717 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11718 Parameter_Associations => Params));
11719
11720 when System_Tasking_Protected_Objects_Single_Entry =>
11721 Param := First (Params);
11722 while Present (Param)
11723 and then not
11724 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11725 loop
11726 Next (Param);
11727 end loop;
11728
11729 Remove (Param);
11730
11731 Rewrite (Call,
11732 Make_Procedure_Call_Statement (Loc,
11733 Name =>
11734 New_Reference_To
11735 (RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11736 Parameter_Associations => Params));
11737
11738 when others =>
11739 raise Program_Error;
11740 end case;
11741
11742 -- For the task case, build a Timed_Task_Entry_Call
11743
11744 else
11745 -- Create a new call statement
11746
11747 Append_To (Params, New_Reference_To (D, Loc));
11748 Append_To (Params, New_Reference_To (M, Loc));
11749 Append_To (Params, New_Reference_To (B, Loc));
11750
11751 Rewrite (Call,
11752 Make_Procedure_Call_Statement (Loc,
11753 Name =>
11754 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11755 Parameter_Associations => Params));
11756 end if;
11757
11758 Append_To (Stmts,
11759 Make_Implicit_If_Statement (N,
11760 Condition => New_Reference_To (B, Loc),
11761 Then_Statements => E_Stats,
11762 Else_Statements => D_Stats));
11763 end if;
11764
11765 Rewrite (N,
11766 Make_Block_Statement (Loc,
11767 Declarations => Decls,
11768 Handled_Statement_Sequence =>
11769 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11770
11771 Analyze (N);
11772 end Expand_N_Timed_Entry_Call;
11773
11774 ----------------------------------------
11775 -- Expand_Protected_Body_Declarations --
11776 ----------------------------------------
11777
11778 procedure Expand_Protected_Body_Declarations
11779 (N : Node_Id;
11780 Spec_Id : Entity_Id)
11781 is
11782 begin
11783 if No_Run_Time_Mode then
11784 Error_Msg_CRT ("protected body", N);
11785 return;
11786
11787 elsif Full_Expander_Active then
11788
11789 -- Associate discriminals with the first subprogram or entry body to
11790 -- be expanded.
11791
11792 if Present (First_Protected_Operation (Declarations (N))) then
11793 Set_Discriminals (Parent (Spec_Id));
11794 end if;
11795 end if;
11796 end Expand_Protected_Body_Declarations;
11797
11798 -------------------------
11799 -- External_Subprogram --
11800 -------------------------
11801
11802 function External_Subprogram (E : Entity_Id) return Entity_Id is
11803 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11804
11805 begin
11806 -- The internal and external subprograms follow each other on the entity
11807 -- chain. Note that previously private operations had no separate
11808 -- external subprogram. We now create one in all cases, because a
11809 -- private operation may actually appear in an external call, through
11810 -- a 'Access reference used for a callback.
11811
11812 -- If the operation is a function that returns an anonymous access type,
11813 -- the corresponding itype appears before the operation, and must be
11814 -- skipped.
11815
11816 -- This mechanism is fragile, there should be a real link between the
11817 -- two versions of the operation, but there is no place to put it ???
11818
11819 if Is_Access_Type (Next_Entity (Subp)) then
11820 return Next_Entity (Next_Entity (Subp));
11821 else
11822 return Next_Entity (Subp);
11823 end if;
11824 end External_Subprogram;
11825
11826 ------------------------------
11827 -- Extract_Dispatching_Call --
11828 ------------------------------
11829
11830 procedure Extract_Dispatching_Call
11831 (N : Node_Id;
11832 Call_Ent : out Entity_Id;
11833 Object : out Entity_Id;
11834 Actuals : out List_Id;
11835 Formals : out List_Id)
11836 is
11837 Call_Nam : Node_Id;
11838
11839 begin
11840 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11841
11842 if Present (Original_Node (N)) then
11843 Call_Nam := Name (Original_Node (N));
11844 else
11845 Call_Nam := Name (N);
11846 end if;
11847
11848 -- Retrieve the name of the dispatching procedure. It contains the
11849 -- dispatch table slot number.
11850
11851 loop
11852 case Nkind (Call_Nam) is
11853 when N_Identifier =>
11854 exit;
11855
11856 when N_Selected_Component =>
11857 Call_Nam := Selector_Name (Call_Nam);
11858
11859 when others =>
11860 raise Program_Error;
11861
11862 end case;
11863 end loop;
11864
11865 Actuals := Parameter_Associations (N);
11866 Call_Ent := Entity (Call_Nam);
11867 Formals := Parameter_Specifications (Parent (Call_Ent));
11868 Object := First (Actuals);
11869
11870 if Present (Original_Node (Object)) then
11871 Object := Original_Node (Object);
11872 end if;
11873
11874 -- If the type of the dispatching object is an access type then return
11875 -- an explicit dereference.
11876
11877 if Is_Access_Type (Etype (Object)) then
11878 Object := Make_Explicit_Dereference (Sloc (N), Object);
11879 Analyze (Object);
11880 end if;
11881 end Extract_Dispatching_Call;
11882
11883 -------------------
11884 -- Extract_Entry --
11885 -------------------
11886
11887 procedure Extract_Entry
11888 (N : Node_Id;
11889 Concval : out Node_Id;
11890 Ename : out Node_Id;
11891 Index : out Node_Id)
11892 is
11893 Nam : constant Node_Id := Name (N);
11894
11895 begin
11896 -- For a simple entry, the name is a selected component, with the
11897 -- prefix being the task value, and the selector being the entry.
11898
11899 if Nkind (Nam) = N_Selected_Component then
11900 Concval := Prefix (Nam);
11901 Ename := Selector_Name (Nam);
11902 Index := Empty;
11903
11904 -- For a member of an entry family, the name is an indexed component
11905 -- where the prefix is a selected component, whose prefix in turn is
11906 -- the task value, and whose selector is the entry family. The single
11907 -- expression in the expressions list of the indexed component is the
11908 -- subscript for the family.
11909
11910 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11911 Concval := Prefix (Prefix (Nam));
11912 Ename := Selector_Name (Prefix (Nam));
11913 Index := First (Expressions (Nam));
11914 end if;
11915 end Extract_Entry;
11916
11917 -------------------
11918 -- Family_Offset --
11919 -------------------
11920
11921 function Family_Offset
11922 (Loc : Source_Ptr;
11923 Hi : Node_Id;
11924 Lo : Node_Id;
11925 Ttyp : Entity_Id;
11926 Cap : Boolean) return Node_Id
11927 is
11928 Ityp : Entity_Id;
11929 Real_Hi : Node_Id;
11930 Real_Lo : Node_Id;
11931
11932 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11933 -- If one of the bounds is a reference to a discriminant, replace with
11934 -- corresponding discriminal of type. Within the body of a task retrieve
11935 -- the renamed discriminant by simple visibility, using its generated
11936 -- name. Within a protected object, find the original discriminant and
11937 -- replace it with the discriminal of the current protected operation.
11938
11939 ------------------------------
11940 -- Convert_Discriminant_Ref --
11941 ------------------------------
11942
11943 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11944 Loc : constant Source_Ptr := Sloc (Bound);
11945 B : Node_Id;
11946 D : Entity_Id;
11947
11948 begin
11949 if Is_Entity_Name (Bound)
11950 and then Ekind (Entity (Bound)) = E_Discriminant
11951 then
11952 if Is_Task_Type (Ttyp)
11953 and then Has_Completion (Ttyp)
11954 then
11955 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11956 Find_Direct_Name (B);
11957
11958 elsif Is_Protected_Type (Ttyp) then
11959 D := First_Discriminant (Ttyp);
11960 while Chars (D) /= Chars (Entity (Bound)) loop
11961 Next_Discriminant (D);
11962 end loop;
11963
11964 B := New_Reference_To (Discriminal (D), Loc);
11965
11966 else
11967 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11968 end if;
11969
11970 elsif Nkind (Bound) = N_Attribute_Reference then
11971 return Bound;
11972
11973 else
11974 B := New_Copy_Tree (Bound);
11975 end if;
11976
11977 return
11978 Make_Attribute_Reference (Loc,
11979 Attribute_Name => Name_Pos,
11980 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11981 Expressions => New_List (B));
11982 end Convert_Discriminant_Ref;
11983
11984 -- Start of processing for Family_Offset
11985
11986 begin
11987 Real_Hi := Convert_Discriminant_Ref (Hi);
11988 Real_Lo := Convert_Discriminant_Ref (Lo);
11989
11990 if Cap then
11991 if Is_Task_Type (Ttyp) then
11992 Ityp := RTE (RE_Task_Entry_Index);
11993 else
11994 Ityp := RTE (RE_Protected_Entry_Index);
11995 end if;
11996
11997 Real_Hi :=
11998 Make_Attribute_Reference (Loc,
11999 Prefix => New_Reference_To (Ityp, Loc),
12000 Attribute_Name => Name_Min,
12001 Expressions => New_List (
12002 Real_Hi,
12003 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12004
12005 Real_Lo :=
12006 Make_Attribute_Reference (Loc,
12007 Prefix => New_Reference_To (Ityp, Loc),
12008 Attribute_Name => Name_Max,
12009 Expressions => New_List (
12010 Real_Lo,
12011 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12012 end if;
12013
12014 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12015 end Family_Offset;
12016
12017 -----------------
12018 -- Family_Size --
12019 -----------------
12020
12021 function Family_Size
12022 (Loc : Source_Ptr;
12023 Hi : Node_Id;
12024 Lo : Node_Id;
12025 Ttyp : Entity_Id;
12026 Cap : Boolean) return Node_Id
12027 is
12028 Ityp : Entity_Id;
12029
12030 begin
12031 if Is_Task_Type (Ttyp) then
12032 Ityp := RTE (RE_Task_Entry_Index);
12033 else
12034 Ityp := RTE (RE_Protected_Entry_Index);
12035 end if;
12036
12037 return
12038 Make_Attribute_Reference (Loc,
12039 Prefix => New_Reference_To (Ityp, Loc),
12040 Attribute_Name => Name_Max,
12041 Expressions => New_List (
12042 Make_Op_Add (Loc,
12043 Left_Opnd =>
12044 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
12045 Right_Opnd =>
12046 Make_Integer_Literal (Loc, 1)),
12047 Make_Integer_Literal (Loc, 0)));
12048 end Family_Size;
12049
12050 ----------------------------
12051 -- Find_Enclosing_Context --
12052 ----------------------------
12053
12054 procedure Find_Enclosing_Context
12055 (N : Node_Id;
12056 Context : out Node_Id;
12057 Context_Id : out Entity_Id;
12058 Context_Decls : out List_Id)
12059 is
12060 begin
12061 -- Traverse the parent chain looking for an enclosing body, block,
12062 -- package or return statement.
12063
12064 Context := Parent (N);
12065 while not Nkind_In (Context, N_Block_Statement,
12066 N_Entry_Body,
12067 N_Extended_Return_Statement,
12068 N_Package_Body,
12069 N_Package_Declaration,
12070 N_Subprogram_Body,
12071 N_Task_Body)
12072 loop
12073 Context := Parent (Context);
12074 end loop;
12075
12076 -- Extract the constituents of the context
12077
12078 if Nkind (Context) = N_Extended_Return_Statement then
12079 Context_Decls := Return_Object_Declarations (Context);
12080 Context_Id := Return_Statement_Entity (Context);
12081
12082 -- Package declarations and bodies use a common library-level activation
12083 -- chain or task master, therefore return the package declaration as the
12084 -- proper carrier for the appropriate flag.
12085
12086 elsif Nkind (Context) = N_Package_Body then
12087 Context_Decls := Declarations (Context);
12088 Context_Id := Corresponding_Spec (Context);
12089 Context := Parent (Context_Id);
12090
12091 if Nkind (Context) = N_Defining_Program_Unit_Name then
12092 Context := Parent (Parent (Context));
12093 else
12094 Context := Parent (Context);
12095 end if;
12096
12097 elsif Nkind (Context) = N_Package_Declaration then
12098 Context_Decls := Visible_Declarations (Specification (Context));
12099 Context_Id := Defining_Unit_Name (Specification (Context));
12100
12101 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12102 Context_Id := Defining_Identifier (Context_Id);
12103 end if;
12104
12105 else
12106 Context_Decls := Declarations (Context);
12107
12108 if Nkind (Context) = N_Block_Statement then
12109 Context_Id := Entity (Identifier (Context));
12110
12111 elsif Nkind (Context) = N_Entry_Body then
12112 Context_Id := Defining_Identifier (Context);
12113
12114 elsif Nkind (Context) = N_Subprogram_Body then
12115 if Present (Corresponding_Spec (Context)) then
12116 Context_Id := Corresponding_Spec (Context);
12117 else
12118 Context_Id := Defining_Unit_Name (Specification (Context));
12119
12120 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12121 Context_Id := Defining_Identifier (Context_Id);
12122 end if;
12123 end if;
12124
12125 elsif Nkind (Context) = N_Task_Body then
12126 Context_Id := Corresponding_Spec (Context);
12127
12128 else
12129 raise Program_Error;
12130 end if;
12131 end if;
12132
12133 pragma Assert (Present (Context));
12134 pragma Assert (Present (Context_Id));
12135 pragma Assert (Present (Context_Decls));
12136 end Find_Enclosing_Context;
12137
12138 -----------------------
12139 -- Find_Master_Scope --
12140 -----------------------
12141
12142 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
12143 S : Entity_Id;
12144
12145 begin
12146 -- In Ada 2005, the master is the innermost enclosing scope that is not
12147 -- transient. If the enclosing block is the rewriting of a call or the
12148 -- scope is an extended return statement this is valid master. The
12149 -- master in an extended return is only used within the return, and is
12150 -- subsequently overwritten in Move_Activation_Chain, but it must exist
12151 -- now before that overwriting occurs.
12152
12153 S := Scope (E);
12154
12155 if Ada_Version >= Ada_2005 then
12156 while Is_Internal (S) loop
12157 if Nkind (Parent (S)) = N_Block_Statement
12158 and then
12159 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
12160 then
12161 exit;
12162
12163 elsif Ekind (S) = E_Return_Statement then
12164 exit;
12165
12166 else
12167 S := Scope (S);
12168 end if;
12169 end loop;
12170 end if;
12171
12172 return S;
12173 end Find_Master_Scope;
12174
12175 -----------------------------------
12176 -- Find_Task_Or_Protected_Pragma --
12177 -----------------------------------
12178
12179 function Find_Task_Or_Protected_Pragma
12180 (T : Node_Id;
12181 P : Name_Id) return Node_Id
12182 is
12183 N : Node_Id;
12184
12185 begin
12186 N := First (Visible_Declarations (T));
12187 while Present (N) loop
12188 if Nkind (N) = N_Pragma then
12189 if Pragma_Name (N) = P then
12190 return N;
12191
12192 elsif P = Name_Priority
12193 and then Pragma_Name (N) = Name_Interrupt_Priority
12194 then
12195 return N;
12196
12197 else
12198 Next (N);
12199 end if;
12200
12201 else
12202 Next (N);
12203 end if;
12204 end loop;
12205
12206 N := First (Private_Declarations (T));
12207 while Present (N) loop
12208 if Nkind (N) = N_Pragma then
12209 if Pragma_Name (N) = P then
12210 return N;
12211
12212 elsif P = Name_Priority
12213 and then Pragma_Name (N) = Name_Interrupt_Priority
12214 then
12215 return N;
12216
12217 else
12218 Next (N);
12219 end if;
12220
12221 else
12222 Next (N);
12223 end if;
12224 end loop;
12225
12226 raise Program_Error;
12227 end Find_Task_Or_Protected_Pragma;
12228
12229 -------------------------------
12230 -- First_Protected_Operation --
12231 -------------------------------
12232
12233 function First_Protected_Operation (D : List_Id) return Node_Id is
12234 First_Op : Node_Id;
12235
12236 begin
12237 First_Op := First (D);
12238 while Present (First_Op)
12239 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
12240 loop
12241 Next (First_Op);
12242 end loop;
12243
12244 return First_Op;
12245 end First_Protected_Operation;
12246
12247 ---------------------------------------
12248 -- Install_Private_Data_Declarations --
12249 ---------------------------------------
12250
12251 procedure Install_Private_Data_Declarations
12252 (Loc : Source_Ptr;
12253 Spec_Id : Entity_Id;
12254 Conc_Typ : Entity_Id;
12255 Body_Nod : Node_Id;
12256 Decls : List_Id;
12257 Barrier : Boolean := False;
12258 Family : Boolean := False)
12259 is
12260 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
12261 Decl : Node_Id;
12262 Def : Node_Id;
12263 Insert_Node : Node_Id := Empty;
12264 Obj_Ent : Entity_Id;
12265
12266 procedure Add (Decl : Node_Id);
12267 -- Add a single declaration after Insert_Node. If this is the first
12268 -- addition, Decl is added to the front of Decls and it becomes the
12269 -- insertion node.
12270
12271 function Replace_Bound (Bound : Node_Id) return Node_Id;
12272 -- The bounds of an entry index may depend on discriminants, create a
12273 -- reference to the corresponding prival. Otherwise return a duplicate
12274 -- of the original bound.
12275
12276 ---------
12277 -- Add --
12278 ---------
12279
12280 procedure Add (Decl : Node_Id) is
12281 begin
12282 if No (Insert_Node) then
12283 Prepend_To (Decls, Decl);
12284 else
12285 Insert_After (Insert_Node, Decl);
12286 end if;
12287
12288 Insert_Node := Decl;
12289 end Add;
12290
12291 --------------------------
12292 -- Replace_Discriminant --
12293 --------------------------
12294
12295 function Replace_Bound (Bound : Node_Id) return Node_Id is
12296 begin
12297 if Nkind (Bound) = N_Identifier
12298 and then Is_Discriminal (Entity (Bound))
12299 then
12300 return Make_Identifier (Loc, Chars (Entity (Bound)));
12301 else
12302 return Duplicate_Subexpr (Bound);
12303 end if;
12304 end Replace_Bound;
12305
12306 -- Start of processing for Install_Private_Data_Declarations
12307
12308 begin
12309 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
12310 -- formal parameter _O, _object or _task depending on the context.
12311
12312 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
12313
12314 -- Special processing of _O for barrier functions, protected entries
12315 -- and families.
12316
12317 if Barrier
12318 or else
12319 (Is_Protected
12320 and then
12321 (Ekind (Spec_Id) = E_Entry
12322 or else Ekind (Spec_Id) = E_Entry_Family))
12323 then
12324 declare
12325 Conc_Rec : constant Entity_Id :=
12326 Corresponding_Record_Type (Conc_Typ);
12327 Typ_Id : constant Entity_Id :=
12328 Make_Defining_Identifier (Loc,
12329 New_External_Name (Chars (Conc_Rec), 'P'));
12330 begin
12331 -- Generate:
12332 -- type prot_typVP is access prot_typV;
12333
12334 Decl :=
12335 Make_Full_Type_Declaration (Loc,
12336 Defining_Identifier => Typ_Id,
12337 Type_Definition =>
12338 Make_Access_To_Object_Definition (Loc,
12339 Subtype_Indication =>
12340 New_Reference_To (Conc_Rec, Loc)));
12341 Add (Decl);
12342
12343 -- Generate:
12344 -- _object : prot_typVP := prot_typV (_O);
12345
12346 Decl :=
12347 Make_Object_Declaration (Loc,
12348 Defining_Identifier =>
12349 Make_Defining_Identifier (Loc, Name_uObject),
12350 Object_Definition => New_Reference_To (Typ_Id, Loc),
12351 Expression =>
12352 Unchecked_Convert_To (Typ_Id,
12353 New_Reference_To (Obj_Ent, Loc)));
12354 Add (Decl);
12355
12356 -- Set the reference to the concurrent object
12357
12358 Obj_Ent := Defining_Identifier (Decl);
12359 end;
12360 end if;
12361
12362 -- Step 2: Create the Protection object and build its declaration for
12363 -- any protected entry (family) of subprogram.
12364
12365 if Is_Protected then
12366 declare
12367 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
12368 Prot_Typ : RE_Id;
12369
12370 begin
12371 Set_Protection_Object (Spec_Id, Prot_Ent);
12372
12373 -- Determine the proper protection type
12374
12375 if Has_Attach_Handler (Conc_Typ)
12376 and then not Restricted_Profile
12377 and then not Restriction_Active (No_Dynamic_Attachment)
12378 then
12379 Prot_Typ := RE_Static_Interrupt_Protection;
12380
12381 elsif Has_Interrupt_Handler (Conc_Typ)
12382 and then not Restriction_Active (No_Dynamic_Attachment)
12383 then
12384 Prot_Typ := RE_Dynamic_Interrupt_Protection;
12385
12386 -- The type has explicit entries or generated primitive entry
12387 -- wrappers.
12388
12389 elsif Has_Entries (Conc_Typ)
12390 or else
12391 (Ada_Version >= Ada_2005
12392 and then Present (Interface_List (Parent (Conc_Typ))))
12393 then
12394 case Corresponding_Runtime_Package (Conc_Typ) is
12395 when System_Tasking_Protected_Objects_Entries =>
12396 Prot_Typ := RE_Protection_Entries;
12397
12398 when System_Tasking_Protected_Objects_Single_Entry =>
12399 Prot_Typ := RE_Protection_Entry;
12400
12401 when others =>
12402 raise Program_Error;
12403 end case;
12404
12405 else
12406 Prot_Typ := RE_Protection;
12407 end if;
12408
12409 -- Generate:
12410 -- conc_typR : protection_typ renames _object._object;
12411
12412 Decl :=
12413 Make_Object_Renaming_Declaration (Loc,
12414 Defining_Identifier => Prot_Ent,
12415 Subtype_Mark =>
12416 New_Reference_To (RTE (Prot_Typ), Loc),
12417 Name =>
12418 Make_Selected_Component (Loc,
12419 Prefix => New_Reference_To (Obj_Ent, Loc),
12420 Selector_Name => Make_Identifier (Loc, Name_uObject)));
12421 Add (Decl);
12422 end;
12423 end if;
12424
12425 -- Step 3: Add discriminant renamings (if any)
12426
12427 if Has_Discriminants (Conc_Typ) then
12428 declare
12429 D : Entity_Id;
12430
12431 begin
12432 D := First_Discriminant (Conc_Typ);
12433 while Present (D) loop
12434
12435 -- Adjust the source location
12436
12437 Set_Sloc (Discriminal (D), Loc);
12438
12439 -- Generate:
12440 -- discr_name : discr_typ renames _object.discr_name;
12441 -- or
12442 -- discr_name : discr_typ renames _task.discr_name;
12443
12444 Decl :=
12445 Make_Object_Renaming_Declaration (Loc,
12446 Defining_Identifier => Discriminal (D),
12447 Subtype_Mark => New_Reference_To (Etype (D), Loc),
12448 Name =>
12449 Make_Selected_Component (Loc,
12450 Prefix => New_Reference_To (Obj_Ent, Loc),
12451 Selector_Name => Make_Identifier (Loc, Chars (D))));
12452 Add (Decl);
12453
12454 Next_Discriminant (D);
12455 end loop;
12456 end;
12457 end if;
12458
12459 -- Step 4: Add private component renamings (if any)
12460
12461 if Is_Protected then
12462 Def := Protected_Definition (Parent (Conc_Typ));
12463
12464 if Present (Private_Declarations (Def)) then
12465 declare
12466 Comp : Node_Id;
12467 Comp_Id : Entity_Id;
12468 Decl_Id : Entity_Id;
12469
12470 begin
12471 Comp := First (Private_Declarations (Def));
12472 while Present (Comp) loop
12473 if Nkind (Comp) = N_Component_Declaration then
12474 Comp_Id := Defining_Identifier (Comp);
12475 Decl_Id :=
12476 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12477
12478 -- Minimal decoration
12479
12480 if Ekind (Spec_Id) = E_Function then
12481 Set_Ekind (Decl_Id, E_Constant);
12482 else
12483 Set_Ekind (Decl_Id, E_Variable);
12484 end if;
12485
12486 Set_Prival (Comp_Id, Decl_Id);
12487 Set_Prival_Link (Decl_Id, Comp_Id);
12488 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
12489
12490 -- Generate:
12491 -- comp_name : comp_typ renames _object.comp_name;
12492
12493 Decl :=
12494 Make_Object_Renaming_Declaration (Loc,
12495 Defining_Identifier => Decl_Id,
12496 Subtype_Mark =>
12497 New_Reference_To (Etype (Comp_Id), Loc),
12498 Name =>
12499 Make_Selected_Component (Loc,
12500 Prefix =>
12501 New_Reference_To (Obj_Ent, Loc),
12502 Selector_Name =>
12503 Make_Identifier (Loc, Chars (Comp_Id))));
12504 Add (Decl);
12505 end if;
12506
12507 Next (Comp);
12508 end loop;
12509 end;
12510 end if;
12511 end if;
12512
12513 -- Step 5: Add the declaration of the entry index and the associated
12514 -- type for barrier functions and entry families.
12515
12516 if (Barrier and then Family)
12517 or else Ekind (Spec_Id) = E_Entry_Family
12518 then
12519 declare
12520 E : constant Entity_Id := Index_Object (Spec_Id);
12521 Index : constant Entity_Id :=
12522 Defining_Identifier (
12523 Entry_Index_Specification (
12524 Entry_Body_Formal_Part (Body_Nod)));
12525 Index_Con : constant Entity_Id :=
12526 Make_Defining_Identifier (Loc, Chars (Index));
12527 High : Node_Id;
12528 Index_Typ : Entity_Id;
12529 Low : Node_Id;
12530
12531 begin
12532 -- Minimal decoration
12533
12534 Set_Ekind (Index_Con, E_Constant);
12535 Set_Entry_Index_Constant (Index, Index_Con);
12536 Set_Discriminal_Link (Index_Con, Index);
12537
12538 -- Retrieve the bounds of the entry family
12539
12540 High := Type_High_Bound (Etype (Index));
12541 Low := Type_Low_Bound (Etype (Index));
12542
12543 -- In the simple case the entry family is given by a subtype
12544 -- mark and the index constant has the same type.
12545
12546 if Is_Entity_Name (Original_Node (
12547 Discrete_Subtype_Definition (Parent (Index))))
12548 then
12549 Index_Typ := Etype (Index);
12550
12551 -- Otherwise a new subtype declaration is required
12552
12553 else
12554 High := Replace_Bound (High);
12555 Low := Replace_Bound (Low);
12556
12557 Index_Typ := Make_Temporary (Loc, 'J');
12558
12559 -- Generate:
12560 -- subtype Jnn is <Etype of Index> range Low .. High;
12561
12562 Decl :=
12563 Make_Subtype_Declaration (Loc,
12564 Defining_Identifier => Index_Typ,
12565 Subtype_Indication =>
12566 Make_Subtype_Indication (Loc,
12567 Subtype_Mark =>
12568 New_Reference_To (Base_Type (Etype (Index)), Loc),
12569 Constraint =>
12570 Make_Range_Constraint (Loc,
12571 Range_Expression =>
12572 Make_Range (Loc, Low, High))));
12573 Add (Decl);
12574 end if;
12575
12576 Set_Etype (Index_Con, Index_Typ);
12577
12578 -- Create the object which designates the index:
12579 -- J : constant Jnn :=
12580 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12581 --
12582 -- where Jnn is the subtype created above or the original type of
12583 -- the index, _E is a formal of the protected body subprogram and
12584 -- <index expr> is the index of the first family member.
12585
12586 Decl :=
12587 Make_Object_Declaration (Loc,
12588 Defining_Identifier => Index_Con,
12589 Constant_Present => True,
12590 Object_Definition =>
12591 New_Reference_To (Index_Typ, Loc),
12592
12593 Expression =>
12594 Make_Attribute_Reference (Loc,
12595 Prefix =>
12596 New_Reference_To (Index_Typ, Loc),
12597 Attribute_Name => Name_Val,
12598
12599 Expressions => New_List (
12600
12601 Make_Op_Add (Loc,
12602 Left_Opnd =>
12603 Make_Op_Subtract (Loc,
12604 Left_Opnd =>
12605 New_Reference_To (E, Loc),
12606 Right_Opnd =>
12607 Entry_Index_Expression (Loc,
12608 Defining_Identifier (Body_Nod),
12609 Empty, Conc_Typ)),
12610
12611 Right_Opnd =>
12612 Make_Attribute_Reference (Loc,
12613 Prefix =>
12614 New_Reference_To (Index_Typ, Loc),
12615 Attribute_Name => Name_Pos,
12616 Expressions => New_List (
12617 Make_Attribute_Reference (Loc,
12618 Prefix =>
12619 New_Reference_To (Index_Typ, Loc),
12620 Attribute_Name => Name_First)))))));
12621 Add (Decl);
12622 end;
12623 end if;
12624 end Install_Private_Data_Declarations;
12625
12626 ---------------------------------
12627 -- Is_Potentially_Large_Family --
12628 ---------------------------------
12629
12630 function Is_Potentially_Large_Family
12631 (Base_Index : Entity_Id;
12632 Conctyp : Entity_Id;
12633 Lo : Node_Id;
12634 Hi : Node_Id) return Boolean
12635 is
12636 begin
12637 return Scope (Base_Index) = Standard_Standard
12638 and then Base_Index = Base_Type (Standard_Integer)
12639 and then Has_Discriminants (Conctyp)
12640 and then Present
12641 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12642 and then
12643 (Denotes_Discriminant (Lo, True)
12644 or else Denotes_Discriminant (Hi, True));
12645 end Is_Potentially_Large_Family;
12646
12647 -------------------------------------
12648 -- Is_Private_Primitive_Subprogram --
12649 -------------------------------------
12650
12651 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12652 begin
12653 return
12654 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12655 and then Is_Private_Primitive (Id);
12656 end Is_Private_Primitive_Subprogram;
12657
12658 ------------------
12659 -- Index_Object --
12660 ------------------
12661
12662 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12663 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12664 Formal : Entity_Id;
12665
12666 begin
12667 Formal := First_Formal (Bod_Subp);
12668 while Present (Formal) loop
12669
12670 -- Look for formal parameter _E
12671
12672 if Chars (Formal) = Name_uE then
12673 return Formal;
12674 end if;
12675
12676 Next_Formal (Formal);
12677 end loop;
12678
12679 -- A protected body subprogram should always have the parameter in
12680 -- question.
12681
12682 raise Program_Error;
12683 end Index_Object;
12684
12685 --------------------------------
12686 -- Make_Initialize_Protection --
12687 --------------------------------
12688
12689 function Make_Initialize_Protection
12690 (Protect_Rec : Entity_Id) return List_Id
12691 is
12692 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12693 P_Arr : Entity_Id;
12694 Pdef : Node_Id;
12695 Pdec : Node_Id;
12696 Ptyp : constant Node_Id :=
12697 Corresponding_Concurrent_Type (Protect_Rec);
12698 Args : List_Id;
12699 L : constant List_Id := New_List;
12700 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12701 Restricted : constant Boolean := Restricted_Profile;
12702
12703 begin
12704 -- We may need two calls to properly initialize the object, one to
12705 -- Initialize_Protection, and possibly one to Install_Handlers if we
12706 -- have a pragma Attach_Handler.
12707
12708 -- Get protected declaration. In the case of a task type declaration,
12709 -- this is simply the parent of the protected type entity. In the single
12710 -- protected object declaration, this parent will be the implicit type,
12711 -- and we can find the corresponding single protected object declaration
12712 -- by searching forward in the declaration list in the tree.
12713
12714 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12715 -- of this type should have been removed during semantic analysis.
12716
12717 Pdec := Parent (Ptyp);
12718 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12719 N_Single_Protected_Declaration)
12720 loop
12721 Next (Pdec);
12722 end loop;
12723
12724 -- Now we can find the object definition from this declaration
12725
12726 Pdef := Protected_Definition (Pdec);
12727
12728 -- Build the parameter list for the call. Note that _Init is the name
12729 -- of the formal for the object to be initialized, which is the task
12730 -- value record itself.
12731
12732 Args := New_List;
12733
12734 -- Object parameter. This is a pointer to the object of type
12735 -- Protection used by the GNARL to control the protected object.
12736
12737 Append_To (Args,
12738 Make_Attribute_Reference (Loc,
12739 Prefix =>
12740 Make_Selected_Component (Loc,
12741 Prefix => Make_Identifier (Loc, Name_uInit),
12742 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12743 Attribute_Name => Name_Unchecked_Access));
12744
12745 -- Priority parameter. Set to Unspecified_Priority unless there is a
12746 -- priority pragma, in which case we take the value from the pragma,
12747 -- or there is an interrupt pragma and no priority pragma, and we
12748 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12749 -- defined value, see D.3(10).
12750
12751 if Present (Pdef)
12752 and then Has_Pragma_Priority (Pdef)
12753 then
12754 declare
12755 Prio : constant Node_Id :=
12756 Expression
12757 (First
12758 (Pragma_Argument_Associations
12759 (Find_Task_Or_Protected_Pragma
12760 (Pdef, Name_Priority))));
12761 Temp : Entity_Id;
12762
12763 begin
12764 -- If priority is a static expression, then we can duplicate it
12765 -- with no problem and simply append it to the argument list.
12766
12767 if Is_Static_Expression (Prio) then
12768 Append_To (Args,
12769 Duplicate_Subexpr_No_Checks (Prio));
12770
12771 -- Otherwise, the priority may be a per-object expression, if it
12772 -- depends on a discriminant of the type. In this case, create
12773 -- local variable to capture the expression. Note that it is
12774 -- really necessary to create this variable explicitly. It might
12775 -- be thought that removing side effects would the appropriate
12776 -- approach, but that could generate declarations improperly
12777 -- placed in the enclosing scope.
12778
12779 -- Note: Use System.Any_Priority as the expected type for the
12780 -- non-static priority expression, in case the expression has not
12781 -- been analyzed yet (as occurs for example with pragma
12782 -- Interrupt_Priority).
12783
12784 else
12785 Temp := Make_Temporary (Loc, 'R', Prio);
12786 Append_To (L,
12787 Make_Object_Declaration (Loc,
12788 Defining_Identifier => Temp,
12789 Object_Definition =>
12790 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12791 Expression => Relocate_Node (Prio)));
12792
12793 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12794 end if;
12795 end;
12796
12797 -- When no priority is specified but an xx_Handler pragma is, we default
12798 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12799
12800 elsif Has_Attach_Handler (Ptyp)
12801 or else Has_Interrupt_Handler (Ptyp)
12802 then
12803 Append_To (Args,
12804 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12805
12806 -- Normal case, no priority or xx_Handler specified, default priority
12807
12808 else
12809 Append_To (Args,
12810 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12811 end if;
12812
12813 -- Test for Compiler_Info parameter. This parameter allows entry body
12814 -- procedures and barrier functions to be called from the runtime. It
12815 -- is a pointer to the record generated by the compiler to represent
12816 -- the protected object.
12817
12818 -- A protected type without entries that covers an interface and
12819 -- overrides the abstract routines with protected procedures is
12820 -- considered equivalent to a protected type with entries in the
12821 -- context of dispatching select statements.
12822
12823 if Has_Entry
12824 or else Has_Interfaces (Protect_Rec)
12825 or else
12826 ((Has_Attach_Handler (Ptyp) or else Has_Interrupt_Handler (Ptyp))
12827 and then not Restriction_Active (No_Dynamic_Attachment))
12828 then
12829 declare
12830 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
12831
12832 Called_Subp : RE_Id;
12833
12834 begin
12835 case Pkg_Id is
12836 when System_Tasking_Protected_Objects_Entries =>
12837 Called_Subp := RE_Initialize_Protection_Entries;
12838
12839 when System_Tasking_Protected_Objects =>
12840 Called_Subp := RE_Initialize_Protection;
12841
12842 when System_Tasking_Protected_Objects_Single_Entry =>
12843 Called_Subp := RE_Initialize_Protection_Entry;
12844
12845 when others =>
12846 raise Program_Error;
12847 end case;
12848
12849 if Has_Entry
12850 or else not Restricted
12851 or else Has_Interfaces (Protect_Rec)
12852 then
12853 Append_To (Args,
12854 Make_Attribute_Reference (Loc,
12855 Prefix => Make_Identifier (Loc, Name_uInit),
12856 Attribute_Name => Name_Address));
12857 end if;
12858
12859 -- Entry_Bodies parameter. This is a pointer to an array of
12860 -- pointers to the entry body procedures and barrier functions of
12861 -- the object. If the protected type has no entries this object
12862 -- will not exist, in this case, pass a null.
12863
12864 if Has_Entry then
12865 P_Arr := Entry_Bodies_Array (Ptyp);
12866
12867 Append_To (Args,
12868 Make_Attribute_Reference (Loc,
12869 Prefix => New_Reference_To (P_Arr, Loc),
12870 Attribute_Name => Name_Unrestricted_Access));
12871
12872 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12873
12874 -- Find index mapping function (clumsy but ok for now)
12875
12876 while Ekind (P_Arr) /= E_Function loop
12877 Next_Entity (P_Arr);
12878 end loop;
12879
12880 Append_To (Args,
12881 Make_Attribute_Reference (Loc,
12882 Prefix => New_Reference_To (P_Arr, Loc),
12883 Attribute_Name => Name_Unrestricted_Access));
12884
12885 -- Build_Entry_Names generation flag. When set to true, the
12886 -- runtime will allocate an array to hold the string names
12887 -- of protected entries.
12888
12889 if not Restricted_Profile then
12890 if Entry_Names_OK then
12891 Append_To (Args,
12892 New_Reference_To (Standard_True, Loc));
12893 else
12894 Append_To (Args,
12895 New_Reference_To (Standard_False, Loc));
12896 end if;
12897 end if;
12898 end if;
12899
12900 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12901 Append_To (Args, Make_Null (Loc));
12902
12903 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12904 Append_To (Args, Make_Null (Loc));
12905 Append_To (Args, Make_Null (Loc));
12906 Append_To (Args, New_Reference_To (Standard_False, Loc));
12907 end if;
12908
12909 Append_To (L,
12910 Make_Procedure_Call_Statement (Loc,
12911 Name => New_Reference_To (RTE (Called_Subp), Loc),
12912 Parameter_Associations => Args));
12913 end;
12914 else
12915 Append_To (L,
12916 Make_Procedure_Call_Statement (Loc,
12917 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12918 Parameter_Associations => Args));
12919 end if;
12920
12921 if Has_Attach_Handler (Ptyp) then
12922
12923 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12924 -- make the following call:
12925
12926 -- Install_Handlers (_object,
12927 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12928
12929 -- or, in the case of Ravenscar:
12930
12931 -- Install_Restricted_Handlers
12932 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12933
12934 declare
12935 Args : constant List_Id := New_List;
12936 Table : constant List_Id := New_List;
12937 Ritem : Node_Id := First_Rep_Item (Ptyp);
12938
12939 begin
12940 -- Build the Attach_Handler table argument
12941
12942 while Present (Ritem) loop
12943 if Nkind (Ritem) = N_Pragma
12944 and then Pragma_Name (Ritem) = Name_Attach_Handler
12945 then
12946 declare
12947 Handler : constant Node_Id :=
12948 First (Pragma_Argument_Associations (Ritem));
12949
12950 Interrupt : constant Node_Id := Next (Handler);
12951 Expr : constant Node_Id := Expression (Interrupt);
12952
12953 begin
12954 Append_To (Table,
12955 Make_Aggregate (Loc, Expressions => New_List (
12956 Unchecked_Convert_To
12957 (RTE (RE_System_Interrupt_Id), Expr),
12958 Make_Attribute_Reference (Loc,
12959 Prefix => Make_Selected_Component (Loc,
12960 Make_Identifier (Loc, Name_uInit),
12961 Duplicate_Subexpr_No_Checks
12962 (Expression (Handler))),
12963 Attribute_Name => Name_Access))));
12964 end;
12965 end if;
12966
12967 Next_Rep_Item (Ritem);
12968 end loop;
12969
12970 -- Append the table argument we just built
12971
12972 Append_To (Args, Make_Aggregate (Loc, Table));
12973
12974 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12975 -- call to the statements.
12976
12977 if Restricted then
12978 -- Call a simplified version of Install_Handlers to be used
12979 -- when the Ravenscar restrictions are in effect
12980 -- (Install_Restricted_Handlers).
12981
12982 Append_To (L,
12983 Make_Procedure_Call_Statement (Loc,
12984 Name =>
12985 New_Reference_To
12986 (RTE (RE_Install_Restricted_Handlers), Loc),
12987 Parameter_Associations => Args));
12988
12989 else
12990 -- First, prepends the _object argument
12991
12992 Prepend_To (Args,
12993 Make_Attribute_Reference (Loc,
12994 Prefix =>
12995 Make_Selected_Component (Loc,
12996 Prefix => Make_Identifier (Loc, Name_uInit),
12997 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12998 Attribute_Name => Name_Unchecked_Access));
12999
13000 -- Then, insert call to Install_Handlers
13001
13002 Append_To (L,
13003 Make_Procedure_Call_Statement (Loc,
13004 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
13005 Parameter_Associations => Args));
13006 end if;
13007 end;
13008 end if;
13009
13010 return L;
13011 end Make_Initialize_Protection;
13012
13013 ---------------------------
13014 -- Make_Task_Create_Call --
13015 ---------------------------
13016
13017 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
13018 Loc : constant Source_Ptr := Sloc (Task_Rec);
13019 Args : List_Id;
13020 Ecount : Node_Id;
13021 Name : Node_Id;
13022 Tdec : Node_Id;
13023 Tdef : Node_Id;
13024 Tnam : Name_Id;
13025 Ttyp : Node_Id;
13026
13027 begin
13028 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
13029 Tnam := Chars (Ttyp);
13030
13031 -- Get task declaration. In the case of a task type declaration, this is
13032 -- simply the parent of the task type entity. In the single task
13033 -- declaration, this parent will be the implicit type, and we can find
13034 -- the corresponding single task declaration by searching forward in the
13035 -- declaration list in the tree.
13036
13037 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13038 -- this type should have been removed during semantic analysis.
13039
13040 Tdec := Parent (Ttyp);
13041 while not Nkind_In (Tdec, N_Task_Type_Declaration,
13042 N_Single_Task_Declaration)
13043 loop
13044 Next (Tdec);
13045 end loop;
13046
13047 -- Now we can find the task definition from this declaration
13048
13049 Tdef := Task_Definition (Tdec);
13050
13051 -- Build the parameter list for the call. Note that _Init is the name
13052 -- of the formal for the object to be initialized, which is the task
13053 -- value record itself.
13054
13055 Args := New_List;
13056
13057 -- Priority parameter. Set to Unspecified_Priority unless there is a
13058 -- priority pragma, in which case we take the value from the pragma.
13059
13060 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
13061 Append_To (Args,
13062 Make_Selected_Component (Loc,
13063 Prefix => Make_Identifier (Loc, Name_uInit),
13064 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
13065 else
13066 Append_To (Args,
13067 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
13068 end if;
13069
13070 -- Optional Stack parameter
13071
13072 if Restricted_Profile then
13073
13074 -- If the stack has been preallocated by the expander then
13075 -- pass its address. Otherwise, pass a null address.
13076
13077 if Preallocated_Stacks_On_Target then
13078 Append_To (Args,
13079 Make_Attribute_Reference (Loc,
13080 Prefix =>
13081 Make_Selected_Component (Loc,
13082 Prefix => Make_Identifier (Loc, Name_uInit),
13083 Selector_Name => Make_Identifier (Loc, Name_uStack)),
13084 Attribute_Name => Name_Address));
13085
13086 else
13087 Append_To (Args,
13088 New_Reference_To (RTE (RE_Null_Address), Loc));
13089 end if;
13090 end if;
13091
13092 -- Size parameter. If no Storage_Size pragma is present, then
13093 -- the size is taken from the taskZ variable for the type, which
13094 -- is either Unspecified_Size, or has been reset by the use of
13095 -- a Storage_Size attribute definition clause. If a pragma is
13096 -- present, then the size is taken from the _Size field of the
13097 -- task value record, which was set from the pragma value.
13098
13099 if Present (Tdef)
13100 and then Has_Storage_Size_Pragma (Tdef)
13101 then
13102 Append_To (Args,
13103 Make_Selected_Component (Loc,
13104 Prefix => Make_Identifier (Loc, Name_uInit),
13105 Selector_Name => Make_Identifier (Loc, Name_uSize)));
13106
13107 else
13108 Append_To (Args,
13109 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
13110 end if;
13111
13112 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
13113 -- Task_Info pragma, in which case we take the value from the pragma.
13114
13115 if Present (Tdef)
13116 and then Has_Task_Info_Pragma (Tdef)
13117 then
13118 Append_To (Args,
13119 Make_Selected_Component (Loc,
13120 Prefix => Make_Identifier (Loc, Name_uInit),
13121 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
13122
13123 else
13124 Append_To (Args,
13125 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
13126 end if;
13127
13128 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
13129 -- in which case we take the value from the pragma. The parameter is
13130 -- passed as an Integer because in the case of unspecified CPU the
13131 -- value is not in the range of CPU_Range.
13132
13133 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
13134 Append_To (Args,
13135 Convert_To (Standard_Integer,
13136 Make_Selected_Component (Loc,
13137 Prefix => Make_Identifier (Loc, Name_uInit),
13138 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
13139
13140 else
13141 Append_To (Args,
13142 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
13143 end if;
13144
13145 if not Restricted_Profile then
13146
13147 -- Deadline parameter. If no Relative_Deadline pragma is present,
13148 -- then the deadline is Time_Span_Zero. If a pragma is present, then
13149 -- the deadline is taken from the _Relative_Deadline field of the
13150 -- task value record, which was set from the pragma value. Note that
13151 -- this parameter must not be generated for the restricted profiles
13152 -- since Ravenscar does not allow deadlines.
13153
13154 -- Case where pragma Relative_Deadline applies: use given value
13155
13156 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
13157 Append_To (Args,
13158 Make_Selected_Component (Loc,
13159 Prefix =>
13160 Make_Identifier (Loc, Name_uInit),
13161 Selector_Name =>
13162 Make_Identifier (Loc, Name_uRelative_Deadline)));
13163
13164 -- No pragma Relative_Deadline apply to the task
13165
13166 else
13167 Append_To (Args,
13168 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
13169 end if;
13170
13171 -- Dispatching_Domain parameter. If no Dispatching_Domain pragma or
13172 -- aspect is present, then the dispatching domain is null. If a
13173 -- pragma or aspect is present, then the dispatching domain is taken
13174 -- from the _Dispatching_Domain field of the task value record,
13175 -- which was set from the pragma value. Note that this parameter
13176 -- must not be generated for the restricted profiles since Ravenscar
13177 -- does not allow dispatching domains.
13178
13179 -- Case where pragma or aspect Dispatching_Domain applies: use given
13180 -- value.
13181
13182 if Present (Tdef) and then Has_Pragma_Dispatching_Domain (Tdef) then
13183 Append_To (Args,
13184 Make_Selected_Component (Loc,
13185 Prefix =>
13186 Make_Identifier (Loc, Name_uInit),
13187 Selector_Name =>
13188 Make_Identifier (Loc, Name_uDispatching_Domain)));
13189
13190 -- No pragma or aspect Dispatching_Domain apply to the task
13191
13192 else
13193 Append_To (Args, Make_Null (Loc));
13194 end if;
13195
13196 -- Number of entries. This is an expression of the form:
13197
13198 -- n + _Init.a'Length + _Init.a'B'Length + ...
13199
13200 -- where a,b... are the entry family names for the task definition
13201
13202 Ecount :=
13203 Build_Entry_Count_Expression
13204 (Ttyp,
13205 Component_Items
13206 (Component_List
13207 (Type_Definition
13208 (Parent (Corresponding_Record_Type (Ttyp))))),
13209 Loc);
13210 Append_To (Args, Ecount);
13211
13212 -- Master parameter. This is a reference to the _Master parameter of
13213 -- the initialization procedure, except in the case of the pragma
13214 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
13215 -- System.Tasking.Library_Task_Level.
13216
13217 if Restriction_Active (No_Task_Hierarchy) = False then
13218 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
13219 else
13220 Append_To (Args,
13221 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
13222 end if;
13223 end if;
13224
13225 -- State parameter. This is a pointer to the task body procedure. The
13226 -- required value is obtained by taking 'Unrestricted_Access of the task
13227 -- body procedure and converting it (with an unchecked conversion) to
13228 -- the type required by the task kernel. For further details, see the
13229 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
13230 -- than 'Address in order to avoid creating trampolines.
13231
13232 declare
13233 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
13234 Subp_Ptr_Typ : constant Node_Id :=
13235 Create_Itype (E_Access_Subprogram_Type, Tdec);
13236 Ref : constant Node_Id := Make_Itype_Reference (Loc);
13237
13238 begin
13239 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
13240 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
13241
13242 -- Be sure to freeze a reference to the access-to-subprogram type,
13243 -- otherwise gigi will complain that it's in the wrong scope, because
13244 -- it's actually inside the init procedure for the record type that
13245 -- corresponds to the task type.
13246
13247 -- This processing is causing a crash in the .NET/JVM back ends that
13248 -- is not yet understood, so skip it in these cases ???
13249
13250 if VM_Target = No_VM then
13251 Set_Itype (Ref, Subp_Ptr_Typ);
13252 Append_Freeze_Action (Task_Rec, Ref);
13253
13254 Append_To (Args,
13255 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
13256 Make_Qualified_Expression (Loc,
13257 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
13258 Expression =>
13259 Make_Attribute_Reference (Loc,
13260 Prefix =>
13261 New_Occurrence_Of (Body_Proc, Loc),
13262 Attribute_Name => Name_Unrestricted_Access))));
13263
13264 -- For the .NET/JVM cases revert to the original code below ???
13265
13266 else
13267 Append_To (Args,
13268 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
13269 Make_Attribute_Reference (Loc,
13270 Prefix =>
13271 New_Occurrence_Of (Body_Proc, Loc),
13272 Attribute_Name => Name_Address)));
13273 end if;
13274 end;
13275
13276 -- Discriminants parameter. This is just the address of the task
13277 -- value record itself (which contains the discriminant values
13278
13279 Append_To (Args,
13280 Make_Attribute_Reference (Loc,
13281 Prefix => Make_Identifier (Loc, Name_uInit),
13282 Attribute_Name => Name_Address));
13283
13284 -- Elaborated parameter. This is an access to the elaboration Boolean
13285
13286 Append_To (Args,
13287 Make_Attribute_Reference (Loc,
13288 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
13289 Attribute_Name => Name_Unchecked_Access));
13290
13291 -- Chain parameter. This is a reference to the _Chain parameter of
13292 -- the initialization procedure.
13293
13294 Append_To (Args, Make_Identifier (Loc, Name_uChain));
13295
13296 -- Task name parameter. Take this from the _Task_Id parameter to the
13297 -- init call unless there is a Task_Name pragma, in which case we take
13298 -- the value from the pragma.
13299
13300 if Present (Tdef)
13301 and then Has_Task_Name_Pragma (Tdef)
13302 then
13303 -- Copy expression in full, because it may be dynamic and have
13304 -- side effects.
13305
13306 Append_To (Args,
13307 New_Copy_Tree
13308 (Expression (First
13309 (Pragma_Argument_Associations
13310 (Find_Task_Or_Protected_Pragma
13311 (Tdef, Name_Task_Name))))));
13312
13313 else
13314 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
13315 end if;
13316
13317 -- Created_Task parameter. This is the _Task_Id field of the task
13318 -- record value
13319
13320 Append_To (Args,
13321 Make_Selected_Component (Loc,
13322 Prefix => Make_Identifier (Loc, Name_uInit),
13323 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
13324
13325 -- Build_Entry_Names generation flag. When set to true, the runtime
13326 -- will allocate an array to hold the string names of task entries.
13327
13328 if not Restricted_Profile then
13329 if Has_Entries (Ttyp)
13330 and then Entry_Names_OK
13331 then
13332 Append_To (Args, New_Reference_To (Standard_True, Loc));
13333 else
13334 Append_To (Args, New_Reference_To (Standard_False, Loc));
13335 end if;
13336 end if;
13337
13338 if Restricted_Profile then
13339 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
13340 else
13341 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
13342 end if;
13343
13344 return
13345 Make_Procedure_Call_Statement (Loc,
13346 Name => Name,
13347 Parameter_Associations => Args);
13348 end Make_Task_Create_Call;
13349
13350 ------------------------------
13351 -- Next_Protected_Operation --
13352 ------------------------------
13353
13354 function Next_Protected_Operation (N : Node_Id) return Node_Id is
13355 Next_Op : Node_Id;
13356
13357 begin
13358 Next_Op := Next (N);
13359 while Present (Next_Op)
13360 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
13361 loop
13362 Next (Next_Op);
13363 end loop;
13364
13365 return Next_Op;
13366 end Next_Protected_Operation;
13367
13368 ---------------------
13369 -- Null_Statements --
13370 ---------------------
13371
13372 function Null_Statements (Stats : List_Id) return Boolean is
13373 Stmt : Node_Id;
13374
13375 begin
13376 Stmt := First (Stats);
13377 while Nkind (Stmt) /= N_Empty
13378 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
13379 or else
13380 (Nkind (Stmt) = N_Pragma
13381 and then (Pragma_Name (Stmt) = Name_Unreferenced
13382 or else
13383 Pragma_Name (Stmt) = Name_Unmodified
13384 or else
13385 Pragma_Name (Stmt) = Name_Warnings)))
13386 loop
13387 Next (Stmt);
13388 end loop;
13389
13390 return Nkind (Stmt) = N_Empty;
13391 end Null_Statements;
13392
13393 --------------------------
13394 -- Parameter_Block_Pack --
13395 --------------------------
13396
13397 function Parameter_Block_Pack
13398 (Loc : Source_Ptr;
13399 Blk_Typ : Entity_Id;
13400 Actuals : List_Id;
13401 Formals : List_Id;
13402 Decls : List_Id;
13403 Stmts : List_Id) return Node_Id
13404 is
13405 Actual : Entity_Id;
13406 Expr : Node_Id := Empty;
13407 Formal : Entity_Id;
13408 Has_Param : Boolean := False;
13409 P : Entity_Id;
13410 Params : List_Id;
13411 Temp_Asn : Node_Id;
13412 Temp_Nam : Node_Id;
13413
13414 begin
13415 Actual := First (Actuals);
13416 Formal := Defining_Identifier (First (Formals));
13417 Params := New_List;
13418
13419 while Present (Actual) loop
13420 if Is_By_Copy_Type (Etype (Actual)) then
13421 -- Generate:
13422 -- Jnn : aliased <formal-type>
13423
13424 Temp_Nam := Make_Temporary (Loc, 'J');
13425
13426 Append_To (Decls,
13427 Make_Object_Declaration (Loc,
13428 Aliased_Present =>
13429 True,
13430 Defining_Identifier =>
13431 Temp_Nam,
13432 Object_Definition =>
13433 New_Reference_To (Etype (Formal), Loc)));
13434
13435 if Ekind (Formal) /= E_Out_Parameter then
13436
13437 -- Generate:
13438 -- Jnn := <actual>
13439
13440 Temp_Asn :=
13441 New_Reference_To (Temp_Nam, Loc);
13442
13443 Set_Assignment_OK (Temp_Asn);
13444
13445 Append_To (Stmts,
13446 Make_Assignment_Statement (Loc,
13447 Name =>
13448 Temp_Asn,
13449 Expression =>
13450 New_Copy_Tree (Actual)));
13451 end if;
13452
13453 -- Generate:
13454 -- Jnn'unchecked_access
13455
13456 Append_To (Params,
13457 Make_Attribute_Reference (Loc,
13458 Attribute_Name =>
13459 Name_Unchecked_Access,
13460 Prefix =>
13461 New_Reference_To (Temp_Nam, Loc)));
13462
13463 Has_Param := True;
13464
13465 -- The controlling parameter is omitted
13466
13467 else
13468 if not Is_Controlling_Actual (Actual) then
13469 Append_To (Params,
13470 Make_Reference (Loc, New_Copy_Tree (Actual)));
13471
13472 Has_Param := True;
13473 end if;
13474 end if;
13475
13476 Next_Actual (Actual);
13477 Next_Formal_With_Extras (Formal);
13478 end loop;
13479
13480 if Has_Param then
13481 Expr := Make_Aggregate (Loc, Params);
13482 end if;
13483
13484 -- Generate:
13485 -- P : Ann := (
13486 -- J1'unchecked_access;
13487 -- <actual2>'reference;
13488 -- ...);
13489
13490 P := Make_Temporary (Loc, 'P');
13491
13492 Append_To (Decls,
13493 Make_Object_Declaration (Loc,
13494 Defining_Identifier =>
13495 P,
13496 Object_Definition =>
13497 New_Reference_To (Blk_Typ, Loc),
13498 Expression =>
13499 Expr));
13500
13501 return P;
13502 end Parameter_Block_Pack;
13503
13504 ----------------------------
13505 -- Parameter_Block_Unpack --
13506 ----------------------------
13507
13508 function Parameter_Block_Unpack
13509 (Loc : Source_Ptr;
13510 P : Entity_Id;
13511 Actuals : List_Id;
13512 Formals : List_Id) return List_Id
13513 is
13514 Actual : Entity_Id;
13515 Asnmt : Node_Id;
13516 Formal : Entity_Id;
13517 Has_Asnmt : Boolean := False;
13518 Result : constant List_Id := New_List;
13519
13520 begin
13521 Actual := First (Actuals);
13522 Formal := Defining_Identifier (First (Formals));
13523 while Present (Actual) loop
13524 if Is_By_Copy_Type (Etype (Actual))
13525 and then Ekind (Formal) /= E_In_Parameter
13526 then
13527 -- Generate:
13528 -- <actual> := P.<formal>;
13529
13530 Asnmt :=
13531 Make_Assignment_Statement (Loc,
13532 Name =>
13533 New_Copy (Actual),
13534 Expression =>
13535 Make_Explicit_Dereference (Loc,
13536 Make_Selected_Component (Loc,
13537 Prefix =>
13538 New_Reference_To (P, Loc),
13539 Selector_Name =>
13540 Make_Identifier (Loc, Chars (Formal)))));
13541
13542 Set_Assignment_OK (Name (Asnmt));
13543 Append_To (Result, Asnmt);
13544
13545 Has_Asnmt := True;
13546 end if;
13547
13548 Next_Actual (Actual);
13549 Next_Formal_With_Extras (Formal);
13550 end loop;
13551
13552 if Has_Asnmt then
13553 return Result;
13554 else
13555 return New_List (Make_Null_Statement (Loc));
13556 end if;
13557 end Parameter_Block_Unpack;
13558
13559 ----------------------
13560 -- Set_Discriminals --
13561 ----------------------
13562
13563 procedure Set_Discriminals (Dec : Node_Id) is
13564 D : Entity_Id;
13565 Pdef : Entity_Id;
13566 D_Minal : Entity_Id;
13567
13568 begin
13569 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13570 Pdef := Defining_Identifier (Dec);
13571
13572 if Has_Discriminants (Pdef) then
13573 D := First_Discriminant (Pdef);
13574 while Present (D) loop
13575 D_Minal :=
13576 Make_Defining_Identifier (Sloc (D),
13577 Chars => New_External_Name (Chars (D), 'D'));
13578
13579 Set_Ekind (D_Minal, E_Constant);
13580 Set_Etype (D_Minal, Etype (D));
13581 Set_Scope (D_Minal, Pdef);
13582 Set_Discriminal (D, D_Minal);
13583 Set_Discriminal_Link (D_Minal, D);
13584
13585 Next_Discriminant (D);
13586 end loop;
13587 end if;
13588 end Set_Discriminals;
13589
13590 -----------------------
13591 -- Trivial_Accept_OK --
13592 -----------------------
13593
13594 function Trivial_Accept_OK return Boolean is
13595 begin
13596 case Opt.Task_Dispatching_Policy is
13597
13598 -- If we have the default task dispatching policy in effect, we can
13599 -- definitely do the optimization (one way of looking at this is to
13600 -- think of the formal definition of the default policy being allowed
13601 -- to run any task it likes after a rendezvous, so even if notionally
13602 -- a full rescheduling occurs, we can say that our dispatching policy
13603 -- (i.e. the default dispatching policy) reorders the queue to be the
13604 -- same as just before the call.
13605
13606 when ' ' =>
13607 return True;
13608
13609 -- FIFO_Within_Priorities certainly does not permit this
13610 -- optimization since the Rendezvous is a scheduling action that may
13611 -- require some other task to be run.
13612
13613 when 'F' =>
13614 return False;
13615
13616 -- For now, disallow the optimization for all other policies. This
13617 -- may be over-conservative, but it is certainly not incorrect.
13618
13619 when others =>
13620 return False;
13621
13622 end case;
13623 end Trivial_Accept_OK;
13624
13625 end Exp_Ch9;