1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
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;
42 with Itypes; use Itypes;
43 with Namet; use Namet;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
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;
67 package body Exp_Ch9 is
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.
76 Entry_Family_Bound : constant Int := 2**16;
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 function Actual_Index_Expression
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.
91 procedure Add_Object_Pointer
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
100 procedure Add_Formal_Renamings
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.
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.
117 function Build_Barrier_Function
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.
124 function Build_Barrier_Function_Specification
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.
130 function Build_Corresponding_Record
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).
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.
147 function Build_Parameter_Block
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>
157 -- type AnnN is access all <actualN-type>
158 -- type Pnn is record
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.
172 function Build_Renamed_Formal_Declaration
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.
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).
185 procedure Build_Wrapper_Bodies
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.
195 procedure Build_Wrapper_Specs
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.
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
212 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
213 -- Build subprogram declaration for previous one
215 function Build_Protected_Entry
218 Pid : Node_Id) return Node_Id;
219 -- Build the procedure implementing the statement sequence of the specified
222 function Build_Protected_Entry_Specification
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.
230 function Build_Protected_Spec
232 Obj_Type : 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.
243 function Build_Protected_Subprogram_Body
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).
255 function Build_Selected_Name
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
268 procedure Build_Simple_Entry_Call
273 -- Some comments here would be useful ???
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:
279 -- procedure tnameB (_Task : access tnameV);
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.
285 function Build_Unprotected_Subprogram_Body
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.
294 procedure Collect_Entry_Families
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.
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.
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
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.
325 function Family_Offset
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.
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.
349 procedure Find_Enclosing_Context
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
361 procedure Extract_Dispatching_Call
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.
373 procedure Extract_Entry
375 Concval : 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.
381 function Find_Task_Or_Protected_Pragma
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.
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
396 function Is_Potentially_Large_Family
397 (Base_Index : Entity_Id;
400 Hi : Node_Id) return Boolean;
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.
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.
412 function Parameter_Block_Pack
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.
424 -- Jnn1 : alias <formal-type1>;
425 -- Jnn1 := <actual1>;
428 -- Jnn1'unchecked_access;
429 -- <actual2>'reference;
432 function Parameter_Block_Unpack
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>;
441 -- <actualN> := P.<formalN>;
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.
453 -----------------------------
454 -- Actual_Index_Expression --
455 -----------------------------
457 function Actual_Index_Expression
461 Tsk : Entity_Id) return Node_Id
463 Ttyp : constant Entity_Id := Etype (Tsk);
471 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
472 -- Compute difference between bounds of entry family
474 --------------------------
475 -- Actual_Family_Offset --
476 --------------------------
478 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
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.
484 -----------------------------
485 -- Actual_Discriminant_Ref --
486 -----------------------------
488 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
489 Typ : constant Entity_Id := Etype (Bound);
493 if not Is_Entity_Name (Bound)
494 or else Ekind (Entity (Bound)) /= E_Discriminant
496 if Nkind (Bound) = N_Attribute_Reference then
499 B := New_Copy_Tree (Bound);
504 Make_Selected_Component (Sloc,
505 Prefix => New_Copy_Tree (Tsk),
506 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
508 Analyze_And_Resolve (B, Typ);
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;
518 -- Start of processing for Actual_Family_Offset
522 Make_Op_Subtract (Sloc,
523 Left_Opnd => Actual_Discriminant_Ref (Hi),
524 Right_Opnd => Actual_Discriminant_Ref (Lo));
525 end Actual_Family_Offset;
527 -- Start of processing for Actual_Index_Expression
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.
536 -- The following is a place holder for the count of simple entries
538 Num := Make_Integer_Literal (Sloc, 1);
540 -- We construct an expression which is a series of addition operations.
541 -- See comments in Entry_Index_Expression, which is identical in
544 if Present (Index) then
545 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
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)));
562 -- Now add lengths of preceding entries and entry families
564 Prev := First_Entity (Ttyp);
566 while Chars (Prev) /= Chars (Ent)
567 or else (Ekind (Prev) /= Ekind (Ent))
568 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
570 if Ekind (Prev) = E_Entry then
571 Set_Intval (Num, Intval (Num) + 1);
573 elsif Ekind (Prev) = E_Entry_Family then
575 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
577 -- The need for the following full view retrieval stems from
578 -- this complex case of nested generics and tasking:
581 -- type Formal_Index is range <>;
584 -- type Index is private;
591 -- type Index is new Formal_Index range 1 .. 10;
594 -- package body Outer is
596 -- entry Fam (Index); -- (2)
599 -- package body Inner is -- (3)
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.
617 and then Is_Private_Type (S)
618 and then Present (Full_View (S))
623 Lo := Type_Low_Bound (S);
624 Hi := Type_High_Bound (S);
632 Actual_Family_Offset (Hi, Lo),
634 Make_Integer_Literal (Sloc, 1)));
636 -- Other components are anonymous types to be ignored
646 end Actual_Index_Expression;
648 --------------------------
649 -- Add_Formal_Renamings --
650 --------------------------
652 procedure Add_Formal_Renamings
658 Ptr : constant Entity_Id :=
660 (Next (First (Parameter_Specifications (Spec))));
661 -- The name of the formal that holds the address of the parameter block
668 Renamed_Formal : Node_Id;
671 Formal := First_Formal (Ent);
672 while Present (Formal) loop
673 Comp := Entry_Component (Formal);
675 Make_Defining_Identifier (Sloc (Formal),
676 Chars => Chars (Formal));
677 Set_Etype (New_F, Etype (Formal));
678 Set_Scope (New_F, Ent);
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.
684 Set_Debug_Info_Needed (New_F);
686 if Ekind (Formal) = E_In_Parameter then
687 Set_Ekind (New_F, E_Constant);
689 Set_Ekind (New_F, E_Variable);
690 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
693 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
696 Make_Selected_Component (Loc,
698 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
699 Make_Identifier (Loc, Chars (Ptr))),
700 Selector_Name => New_Reference_To (Comp, Loc));
703 Build_Renamed_Formal_Declaration
704 (New_F, Formal, Comp, Renamed_Formal);
706 Append (Decl, Decls);
707 Set_Renamed_Object (Formal, New_F);
708 Next_Formal (Formal);
710 end Add_Formal_Renamings;
712 ------------------------
713 -- Add_Object_Pointer --
714 ------------------------
716 procedure Add_Object_Pointer
718 Conc_Typ : Entity_Id;
721 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
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.
730 -- Build the entity for the access type
733 Make_Defining_Identifier (Loc,
734 New_External_Name (Chars (Rec_Typ), 'P'));
737 -- _object : poVP := poVP!O;
740 Make_Object_Declaration (Loc,
741 Defining_Identifier =>
742 Make_Defining_Identifier (Loc, Name_uObject),
744 New_Reference_To (Obj_Ptr, Loc),
746 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
747 Set_Debug_Info_Needed (Defining_Identifier (Decl));
748 Prepend_To (Decls, Decl);
751 -- type poVP is access poV;
754 Make_Full_Type_Declaration (Loc,
755 Defining_Identifier =>
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;
765 -----------------------
766 -- Build_Accept_Body --
767 -----------------------
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);
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.
786 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
787 Insert_Before (Last (Statements (Stats)), Call);
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.
794 if Present (Exception_Handlers (Stats)) then
795 Hand := First (Exception_Handlers (Stats));
796 while Present (Hand) loop
799 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
800 Append (Call, Statements (Hand));
806 Make_Handled_Sequence_Of_Statements (Loc,
807 Statements => New_List (
808 Make_Block_Statement (Loc,
809 Handled_Statement_Sequence => Stats)));
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
819 -- when all others =>
820 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
822 -- We handle Abort_Signal to make sure that we properly catch the abort
823 -- case and wake up the caller.
825 Ohandle := Make_Others_Choice (Loc);
826 Set_All_Others (Ohandle);
828 Set_Exception_Handlers (New_S,
830 Make_Implicit_Exception_Handler (Loc,
831 Exception_Choices => New_List (Ohandle),
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)))))))));
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);
846 -- Exceptional_Complete_Rendezvous must be called with abort
847 -- still deferred, which is the case for a "when all others" handler.
850 end Build_Accept_Body;
852 -----------------------------------
853 -- Build_Activation_Chain_Entity --
854 -----------------------------------
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
861 --------------------------
862 -- Has_Activation_Chain --
863 --------------------------
865 function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
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
881 end Has_Activation_Chain;
886 Context_Id : Entity_Id;
889 -- Start of processing for Build_Activation_Chain_Entity
892 Find_Enclosing_Context (N, Context, Context_Id, Decls);
894 -- If an activation chain entity has not been declared already, create
897 if Nkind (Context) = N_Extended_Return_Statement
898 or else No (Activation_Chain_Entity (Context))
900 -- Since extended return statements do not store the entity of the
901 -- chain, examine the return object declarations to avoid creating
904 if Nkind (Context) = N_Extended_Return_Statement
905 and then Has_Activation_Chain (Context)
911 Loc : constant Source_Ptr := Sloc (Context);
916 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
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
927 if Nkind (Context) /= N_Extended_Return_Statement then
928 Set_Activation_Chain_Entity (Context, Chain);
932 Make_Object_Declaration (Loc,
933 Defining_Identifier => Chain,
934 Aliased_Present => True,
936 New_Reference_To (RTE (RE_Activation_Chain), Loc));
938 Prepend_To (Decls, Decl);
940 -- Ensure that the _chain appears in the proper scope of the
943 if Context_Id /= Current_Scope then
944 Push_Scope (Context_Id);
952 end Build_Activation_Chain_Entity;
954 ----------------------------
955 -- Build_Barrier_Function --
956 ----------------------------
958 function Build_Barrier_Function
961 Pid : Node_Id) return Node_Id
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;
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).
976 Install_Private_Data_Declarations (Sloc (N),
982 Family => Ekind (Ent) = E_Entry_Family);
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
989 if Opt.Suppress_Control_Flow_Optimizations then
990 Stmt := Make_Implicit_If_Statement (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))));
1000 Stmt := Make_Simple_Return_Statement (Loc, Cond);
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.
1008 Make_Subprogram_Body (Loc,
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);
1019 end Build_Barrier_Function;
1021 ------------------------------------------
1022 -- Build_Barrier_Function_Specification --
1023 ------------------------------------------
1025 function Build_Barrier_Function_Specification
1027 Def_Id : Entity_Id) return Node_Id
1030 Set_Debug_Info_Needed (Def_Id);
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),
1039 New_Reference_To (RTE (RE_Address), Loc)),
1041 Make_Parameter_Specification (Loc,
1042 Defining_Identifier =>
1043 Make_Defining_Identifier (Loc, Name_uE),
1045 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1047 Result_Definition =>
1048 New_Reference_To (Standard_Boolean, Loc));
1049 end Build_Barrier_Function_Specification;
1051 --------------------------
1052 -- Build_Call_With_Task --
1053 --------------------------
1055 function Build_Call_With_Task
1057 E : Entity_Id) return Node_Id
1059 Loc : constant Source_Ptr := Sloc (N);
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;
1067 -----------------------------
1068 -- Build_Class_Wide_Master --
1069 -----------------------------
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;
1076 Related_Node : Node_Id;
1080 -- Nothing to do if there is no task hierarchy
1082 if Restriction_Active (No_Task_Hierarchy) then
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.
1090 if Is_Itype (Typ) then
1091 Related_Node := Associated_Node_For_Itype (Typ);
1093 Related_Node := Parent (Typ);
1096 Master_Scope := Find_Master_Scope (Typ);
1098 -- Nothing to do if the master scope already contains a _master entity.
1099 -- The only exception to this is the following scenario:
1102 -- Transient_Scope_1
1105 -- Transient_Scope_2
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.
1113 Name_Id := Make_Identifier (Loc, Name_uMaster);
1115 if not Has_Master_Entity (Master_Scope)
1116 or else No (Current_Entity_In_Scope (Name_Id))
1119 Master_Decl : Node_Id;
1122 Set_Has_Master_Entity (Master_Scope);
1125 -- _master : constant Integer := Current_Master.all;
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),
1135 Make_Explicit_Dereference (Loc,
1136 New_Reference_To (RTE (RE_Current_Master), Loc)));
1138 Insert_Action (Related_Node, Master_Decl);
1139 Analyze (Master_Decl);
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).
1145 if Ekind (Current_Scope) /= E_Return_Statement then
1147 Par : Node_Id := Related_Node;
1150 while Nkind (Par) /= N_Compilation_Unit loop
1151 Par := Parent (Par);
1153 -- If we fall off the top, we are at the outer level, and
1154 -- the environment task is our effective master, so
1157 if Nkind_In (Par, N_Block_Statement,
1161 Set_Is_Task_Master (Par);
1171 Make_Defining_Identifier (Loc,
1172 New_External_Name (Chars (Typ), 'M'));
1175 -- Mnn renames _master;
1178 Make_Object_Renaming_Declaration (Loc,
1179 Defining_Identifier => Master_Id,
1180 Subtype_Mark => New_Reference_To (Standard_Integer, Loc),
1183 Insert_Action (Related_Node, Ren_Decl);
1185 Set_Master_Id (Typ, Master_Id);
1186 end Build_Class_Wide_Master;
1188 --------------------------------
1189 -- Build_Corresponding_Record --
1190 --------------------------------
1192 function Build_Corresponding_Record
1195 Loc : Source_Ptr) return Node_Id
1197 Rec_Ent : constant Entity_Id :=
1198 Make_Defining_Identifier
1199 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1202 New_Disc : Entity_Id;
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);
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;
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.
1225 -- In fact the discriminals b) are used in the renaming declarations
1226 -- for e). See details in einfo (Handling of Discriminants).
1228 if Present (Discriminant_Specifications (N)) then
1230 Disc := First_Discriminant (Ctyp);
1232 while Present (Disc) loop
1233 New_Disc := CR_Discriminant (Disc);
1236 Make_Discriminant_Specification (Loc,
1237 Defining_Identifier => New_Disc,
1238 Discriminant_Type =>
1239 New_Occurrence_Of (Etype (Disc), Loc),
1241 New_Copy (Discriminant_Default_Value (Disc))));
1243 Next_Discriminant (Disc);
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).
1259 Make_Full_Type_Declaration (Loc,
1260 Defining_Identifier => Rec_Ent,
1261 Discriminant_Specifications => Dlist,
1263 Make_Record_Definition (Loc,
1265 Make_Component_List (Loc,
1266 Component_Items => Cdecls),
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;
1273 ----------------------------------
1274 -- Build_Entry_Count_Expression --
1275 ----------------------------------
1277 function Build_Entry_Count_Expression
1278 (Concurrent_Type : Node_Id;
1279 Component_List : List_Id;
1280 Loc : Source_Ptr) return Node_Id
1292 -- Count number of non-family entries
1295 Ent := First_Entity (Concurrent_Type);
1296 while Present (Ent) loop
1297 if Ekind (Ent) = E_Entry then
1304 Ecount := Make_Integer_Literal (Loc, Eindx);
1306 -- Loop through entry families building the addition nodes
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
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);
1323 Left_Opnd => Ecount,
1324 Right_Opnd => Family_Size
1325 (Loc, Hi, Lo, Concurrent_Type, Large));
1332 end Build_Entry_Count_Expression;
1334 -----------------------
1335 -- Build_Entry_Names --
1336 -----------------------
1338 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1339 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1345 Typ : Entity_Id := Conc_Typ;
1347 procedure Build_Entry_Family_Name (Id : Entity_Id);
1349 -- for Lnn in Family_Low .. Family_High loop
1352 -- (_init._object <or> _init._task_id,
1354 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1356 -- Note that the bounds of the range may reference discriminants. The
1357 -- above construct is added directly to the statements of the block.
1359 procedure Build_Entry_Name (Id : Entity_Id);
1363 -- (_init._object <or>_init._task_id,
1365 -- new String ("<Entry name>");
1366 -- The above construct is added directly to the statements of the block.
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.
1372 procedure Increment_Index (Stmts : List_Id);
1373 -- Generate the following and add it to Stmts
1376 -----------------------------
1377 -- Build_Entry_Family_Name --
1378 -----------------------------
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;
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.
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));
1400 -- If a bound references a discriminant, generate an identifier
1401 -- with the same name. Resolution will map it to the formals of
1404 if Is_Entity_Name (Low)
1405 and then Ekind (Entity (Low)) = E_Discriminant
1407 Low := Make_Identifier (Loc, Chars (Low));
1409 Low := New_Copy_Tree (Low);
1412 if Is_Entity_Name (High)
1413 and then Ekind (Entity (High)) = E_Discriminant
1415 High := Make_Identifier (Loc, Chars (High));
1417 High := New_Copy_Tree (High);
1423 High_Bound => High);
1426 -- Start of processing for Build_Entry_Family_Name
1429 Get_Name_String (Chars (Id));
1431 -- Add a leading '('
1433 Add_Char_To_Name_Buffer ('(');
1436 -- new String'("<Entry name>(" & Lnn'Img & ")");
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.
1443 Make_Allocator (Loc,
1444 Make_Qualified_Expression (Loc,
1446 New_Reference_To (Standard_String, Loc),
1448 Make_Op_Concat (Loc,
1450 Make_Op_Concat (Loc,
1452 Make_String_Literal (Loc,
1453 Strval => String_From_Name_Buffer),
1455 Make_Attribute_Reference (Loc,
1457 New_Reference_To (L_Id, Loc),
1458 Attribute_Name => Name_Img)),
1460 Make_String_Literal (Loc,
1463 Increment_Index (L_Stmts);
1464 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1467 -- for Lnn in Family_Low .. Family_High loop
1470 -- (_init._object <or> _init._task_id, Inn, <Val>);
1474 Make_Loop_Statement (Loc,
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;
1485 ----------------------
1486 -- Build_Entry_Name --
1487 ----------------------
1489 procedure Build_Entry_Name (Id : Entity_Id) is
1493 Get_Name_String (Chars (Id));
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.
1500 Make_Allocator (Loc,
1501 Make_Qualified_Expression (Loc,
1503 New_Reference_To (Standard_String, Loc),
1505 Make_String_Literal (Loc,
1506 String_From_Name_Buffer)));
1508 Increment_Index (B_Stmts);
1509 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1510 end Build_Entry_Name;
1512 -------------------------------
1513 -- Build_Set_Entry_Name_Call --
1514 -------------------------------
1516 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1521 -- Determine the proper name for the first argument and the RTS
1524 if Is_Protected_Type (Typ) then
1525 Arg1 := Name_uObject;
1526 Proc := RO_PE_Set_Entry_Name;
1528 else pragma Assert (Is_Task_Type (Typ));
1529 Arg1 := Name_uTask_Id;
1530 Proc := RO_TS_Set_Entry_Name;
1534 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1537 Make_Procedure_Call_Statement (Loc,
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),
1545 Make_Identifier (Loc, Arg1)),
1546 New_Reference_To (Index, Loc), -- Inn
1548 end Build_Set_Entry_Name_Call;
1550 ---------------------
1551 -- Increment_Index --
1552 ---------------------
1554 procedure Increment_Index (Stmts : List_Id) is
1560 Make_Assignment_Statement (Loc,
1562 New_Reference_To (Index, Loc),
1566 New_Reference_To (Index, Loc),
1568 Make_Integer_Literal (Loc, 1))));
1569 end Increment_Index;
1571 -- Start of processing for Build_Entry_Names
1574 -- Retrieve the original concurrent type
1576 if Is_Concurrent_Record_Type (Typ) then
1577 Typ := Corresponding_Concurrent_Type (Typ);
1580 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1582 -- Nothing to do if the type has no entries
1584 if not Has_Entries (Typ) then
1588 -- Avoid generating entry names for a protected type with only one entry
1590 if Is_Protected_Type (Typ)
1591 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1596 Index := Make_Temporary (Loc, 'I');
1598 -- Step 1: Generate the declaration of the index variable:
1599 -- Inn : Protected_Entry_Index := 0;
1601 -- Inn : Task_Entry_Index := 0;
1603 if Is_Protected_Type (Typ) then
1604 Index_Typ := RE_Protected_Entry_Index;
1606 Index_Typ := RE_Task_Entry_Index;
1609 B_Decls := New_List;
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)));
1616 B_Stmts := New_List;
1618 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1621 Comp := First_Entity (Typ);
1622 while Present (Comp) loop
1623 if Ekind (Comp) = E_Entry then
1624 Build_Entry_Name (Comp);
1626 elsif Ekind (Comp) = E_Entry_Family then
1627 Build_Entry_Family_Name (Comp);
1633 -- Step 3: Wrap the statements in a block
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;
1643 ---------------------------
1644 -- Build_Parameter_Block --
1645 ---------------------------
1647 function Build_Parameter_Block
1651 Decls : List_Id) return Entity_Id
1657 Has_Comp : Boolean := False;
1661 Actual := First (Actuals);
1663 Formal := Defining_Identifier (First (Formals));
1665 while Present (Actual) loop
1666 if not Is_Controlling_Actual (Actual) then
1669 -- type Ann is access all <actual-type>
1671 Comp_Nam := Make_Temporary (Loc, 'A');
1674 Make_Full_Type_Declaration (Loc,
1675 Defining_Identifier => Comp_Nam,
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))));
1687 Make_Component_Declaration (Loc,
1688 Defining_Identifier =>
1689 Make_Defining_Identifier (Loc, Chars (Formal)),
1690 Component_Definition =>
1691 Make_Component_Definition (Loc,
1694 Subtype_Indication =>
1695 New_Reference_To (Comp_Nam, Loc))));
1700 Next_Actual (Actual);
1701 Next_Formal_With_Extras (Formal);
1704 Rec_Nam := Make_Temporary (Loc, 'P');
1709 -- type Pnn is record
1714 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1715 -- the original parameter names and Ann1 .. AnnN are the access to
1719 Make_Full_Type_Declaration (Loc,
1720 Defining_Identifier =>
1723 Make_Record_Definition (Loc,
1725 Make_Component_List (Loc, Comps))));
1728 -- type Pnn is null record;
1731 Make_Full_Type_Declaration (Loc,
1732 Defining_Identifier =>
1735 Make_Record_Definition (Loc,
1736 Null_Present => True,
1737 Component_List => Empty)));
1741 end Build_Parameter_Block;
1743 --------------------------------------
1744 -- Build_Renamed_Formal_Declaration --
1745 --------------------------------------
1747 function Build_Renamed_Formal_Declaration
1751 Renamed_Formal : Node_Id) return Node_Id
1753 Loc : constant Source_Ptr := Sloc (New_F);
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.
1762 if Is_Incomplete_Type (Etype (Formal))
1763 and then Is_Tagged_Type (Etype (Formal))
1766 Make_Object_Renaming_Declaration (Loc,
1767 Defining_Identifier => New_F,
1768 Subtype_Mark => New_Reference_To (Etype (Comp), Loc),
1769 Name => Renamed_Formal);
1773 Make_Object_Renaming_Declaration (Loc,
1774 Defining_Identifier => New_F,
1775 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
1777 Make_Explicit_Dereference (Loc, Renamed_Formal));
1781 end Build_Renamed_Formal_Declaration;
1783 -----------------------
1784 -- Build_PPC_Wrapper --
1785 -----------------------
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);
1791 Wrapper_Id : constant Entity_Id :=
1792 Make_Defining_Identifier (Loc,
1793 Chars => New_External_Name (Chars (E), 'E'));
1794 -- the wrapper procedure name
1796 Wrapper_Body : Node_Id;
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
1803 Actuals : constant List_Id := New_List;
1804 -- The actuals in the entry call
1806 Decls : constant List_Id := New_List;
1808 Entry_Call : Node_Id;
1809 Entry_Name : Node_Id;
1812 -- The specification of the wrapper procedure
1816 -- Only build the wrapper if entry has pre/postconditions.
1817 -- Should this be done unconditionally instead ???
1823 P := Spec_PPC_List (Contract (E));
1828 -- Transfer ppc pragmas to the declarations of the wrapper
1830 while Present (P) loop
1831 if Pragma_Name (P) = Name_Precondition
1832 or else Pragma_Name (P) = Name_Postcondition
1834 Append (Relocate_Node (P), Decls);
1835 Set_Analyzed (Last (Decls), False);
1838 P := Next_Pragma (P);
1842 -- First formal is synchronized object
1845 Make_Parameter_Specification (Loc,
1846 Defining_Identifier => Synch_Id,
1847 Out_Present => True,
1849 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1852 Make_Selected_Component (Loc,
1853 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1854 Selector_Name => New_Occurrence_Of (E, Loc));
1856 -- If entity is entry family, second formal is the corresponding index,
1857 -- and entry name is an indexed component.
1859 if Ekind (E) = E_Entry_Family then
1861 Index : constant Entity_Id :=
1862 Make_Defining_Identifier (Loc, Name_I);
1865 Make_Parameter_Specification (Loc,
1866 Defining_Identifier => Index,
1868 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1871 Make_Indexed_Component (Loc,
1872 Prefix => Entry_Name,
1873 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
1878 Make_Procedure_Call_Statement (Loc,
1880 Parameter_Associations => Actuals);
1882 -- Now add formals that match those of the entry, and build actuals for
1883 -- the nested entry call.
1887 New_Form : Entity_Id;
1888 Parm_Spec : Node_Id;
1891 Form := First_Formal (E);
1892 while Present (Form) loop
1893 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
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));
1901 Append (Parm_Spec, Specs);
1902 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1907 -- Add renaming declarations for the discriminants of the enclosing
1908 -- type, which may be visible in the preconditions.
1910 if Has_Discriminants (Synch_Type) then
1916 D := First_Discriminant (Synch_Type);
1917 while Present (D) loop
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),
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);
1933 Set_PPC_Wrapper (E, Wrapper_Id);
1935 Make_Subprogram_Body (Loc,
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)));
1945 -- The wrapper body is analyzed when the enclosing type is frozen
1947 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1948 end Build_PPC_Wrapper;
1950 --------------------------
1951 -- Build_Wrapper_Bodies --
1952 --------------------------
1954 procedure Build_Wrapper_Bodies
1959 Rec_Typ : Entity_Id;
1961 function Build_Wrapper_Body
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.
1972 ------------------------
1973 -- Build_Wrapper_Body --
1974 ------------------------
1976 function Build_Wrapper_Body
1978 Subp_Id : Entity_Id;
1979 Obj_Typ : Entity_Id;
1980 Formals : List_Id) return Node_Id
1982 Body_Spec : Node_Id;
1985 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1987 -- The subprogram is not overriding or is not a primitive declared
1988 -- between two views.
1990 if No (Body_Spec) then
1995 Actuals : List_Id := No_List;
1997 First_Form : Node_Id;
2002 -- Map formals to actuals. Use the list built for the wrapper
2003 -- spec, skipping the object notation parameter.
2005 First_Form := First (Parameter_Specifications (Body_Spec));
2007 Formal := First_Form;
2010 if Present (Formal) then
2011 Actuals := New_List;
2012 while Present (Formal) loop
2014 Make_Identifier (Loc,
2015 Chars => Chars (Defining_Identifier (Formal))));
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.
2026 if Is_Private_Primitive_Subprogram (Subp_Id) then
2027 if No (Actuals) then
2028 Actuals := New_List;
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)));
2038 Prepend_To (Actuals,
2039 Make_Identifier (Loc,
2040 Chars => Chars (Defining_Identifier (First_Form))));
2043 Nam := New_Reference_To (Subp_Id, Loc);
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.
2050 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2052 if Nkind (Parameter_Type (First_Form)) =
2056 Make_Explicit_Dereference (Loc,
2057 Prefix => Make_Identifier (Loc, Name_uO));
2059 Conv_Id := Make_Identifier (Loc, Name_uO);
2063 Make_Selected_Component (Loc,
2065 Unchecked_Convert_To
2066 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
2067 Selector_Name => New_Reference_To (Subp_Id, Loc));
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.
2074 if Ekind (Subp_Id) = E_Function then
2080 Make_Function_Call (Loc,
2082 Parameter_Associations => Actuals);
2084 if Has_Controlling_Result (Subp_Id) then
2086 Unchecked_Convert_To
2087 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
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))));
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,
2110 Parameter_Associations => Actuals))));
2113 end Build_Wrapper_Body;
2115 -- Start of processing for Build_Wrapper_Bodies
2118 if Is_Concurrent_Type (Typ) then
2119 Rec_Typ := Corresponding_Record_Type (Typ);
2124 -- Generate wrapper bodies for a concurrent type which implements an
2127 if Present (Interfaces (Rec_Typ)) then
2129 Insert_Nod : Node_Id;
2131 Prim_Elmt : Elmt_Id;
2132 Prim_Decl : Node_Id;
2134 Wrap_Body : Node_Id;
2135 Wrap_Id : Entity_Id;
2140 -- Examine all primitive operations of the corresponding record
2141 -- type, looking for wrapper specs. Generate bodies in order to
2144 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
2145 while Present (Prim_Elmt) loop
2146 Prim := Node (Prim_Elmt);
2148 if (Ekind (Prim) = E_Function
2149 or else Ekind (Prim) = E_Procedure)
2150 and then Is_Primitive_Wrapper (Prim)
2152 Subp := Wrapped_Entity (Prim);
2153 Prim_Decl := Parent (Parent (Prim));
2156 Build_Wrapper_Body (Loc,
2159 Formals => Parameter_Specifications (Parent (Subp)));
2160 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2162 Set_Corresponding_Spec (Wrap_Body, Prim);
2163 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2165 Insert_After (Insert_Nod, Wrap_Body);
2166 Insert_Nod := Wrap_Body;
2168 Analyze (Wrap_Body);
2171 Next_Elmt (Prim_Elmt);
2175 end Build_Wrapper_Bodies;
2177 ------------------------
2178 -- Build_Wrapper_Spec --
2179 ------------------------
2181 function Build_Wrapper_Spec
2182 (Subp_Id : Entity_Id;
2183 Obj_Typ : Entity_Id;
2184 Formals : List_Id) return Node_Id
2186 Loc : constant Source_Ptr := Sloc (Subp_Id);
2187 First_Param : Node_Id;
2189 Iface_Elmt : Elmt_Id;
2190 Iface_Op : Entity_Id;
2191 Iface_Op_Elmt : Elmt_Id;
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.
2200 function Replicate_Formals
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.
2208 -------------------------
2209 -- Overriding_Possible --
2210 -------------------------
2212 function Overriding_Possible
2213 (Iface_Op : Entity_Id;
2214 Wrapper : Entity_Id) return Boolean
2216 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2217 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
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.
2228 --------------------------------
2229 -- Type_Conformant_Parameters --
2230 --------------------------------
2232 function Type_Conformant_Parameters
2233 (Iface_Op_Params : List_Id;
2234 Wrapper_Params : List_Id) return Boolean
2236 Iface_Op_Param : Node_Id;
2237 Iface_Op_Typ : Entity_Id;
2238 Wrapper_Param : Node_Id;
2239 Wrapper_Typ : Entity_Id;
2242 -- Skip the first (controlling) parameter of primitive operation
2244 Iface_Op_Param := First (Iface_Op_Params);
2246 if Present (First_Formal (Iface_Op))
2247 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2249 Iface_Op_Param := Next (Iface_Op_Param);
2252 Wrapper_Param := First (Wrapper_Params);
2253 while Present (Iface_Op_Param)
2254 and then Present (Wrapper_Param)
2256 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2257 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2259 -- The two parameters must be mode conformant
2261 if not Conforming_Types
2262 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2267 Next (Iface_Op_Param);
2268 Next (Wrapper_Param);
2271 -- One of the lists is longer than the other
2273 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2278 end Type_Conformant_Parameters;
2280 -- Start of processing for Overriding_Possible
2283 if Chars (Iface_Op) /= Chars (Wrapper) then
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.
2291 if Ekind (Iface_Op) = E_Procedure
2292 and then Present (Parameter_Specifications (Iface_Op_Spec))
2295 Obj_Param : constant Node_Id :=
2296 First (Parameter_Specifications (Iface_Op_Spec));
2298 if not Out_Present (Obj_Param)
2299 and then Nkind (Parameter_Type (Obj_Param)) /=
2308 Type_Conformant_Parameters (
2309 Parameter_Specifications (Iface_Op_Spec),
2310 Parameter_Specifications (Wrapper_Spec));
2311 end Overriding_Possible;
2313 -----------------------
2314 -- Replicate_Formals --
2315 -----------------------
2317 function Replicate_Formals
2319 Formals : List_Id) return List_Id
2321 New_Formals : constant List_Id := New_List;
2323 Param_Type : Node_Id;
2326 Formal := First (Formals);
2328 -- Skip the object parameter when dealing with primitives declared
2329 -- between two views.
2331 if Is_Private_Primitive_Subprogram (Subp_Id)
2332 and then not Has_Controlling_Result (Subp_Id)
2334 Formal := Next (Formal);
2337 while Present (Formal) loop
2339 -- Create an explicit copy of the entry parameter
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.
2350 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2351 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2354 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
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));
2370 end Replicate_Formals;
2372 -- Start of processing for Build_Wrapper_Spec
2375 -- There is no point in building wrappers for non-tagged concurrent
2378 pragma Assert (Is_Tagged_Type (Obj_Typ));
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.
2386 First_Param := Empty;
2388 -- Check every implemented interface
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);
2395 -- Check every interface primitive
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);
2402 -- Ignore predefined primitives
2404 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2405 Iface_Op := Ultimate_Alias (Iface_Op);
2407 -- The current primitive operation can be overridden by
2408 -- the generated entry wrapper.
2410 if Overriding_Possible (Iface_Op, Subp_Id) then
2412 First (Parameter_Specifications (Parent (Iface_Op)));
2418 Next_Elmt (Iface_Op_Elmt);
2422 Next_Elmt (Iface_Elmt);
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
2435 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2438 (Corresponding_Concurrent_Type (Obj_Typ))
2441 Make_Parameter_Specification (Loc,
2442 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2444 Out_Present => False,
2445 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2447 -- For entries and procedures of protected types the mode of
2448 -- the controlling argument must be in-out.
2452 Make_Parameter_Specification (Loc,
2453 Defining_Identifier =>
2454 Make_Defining_Identifier (Loc,
2457 Out_Present => (Ekind (Subp_Id) /= E_Function),
2458 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
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;
2470 -- Minimum decoration is needed to catch the entity in
2471 -- Sem_Ch6.Override_Dispatching_Operation.
2473 if Ekind (Subp_Id) = E_Function then
2474 Set_Ekind (Wrapper_Id, E_Function);
2476 Set_Ekind (Wrapper_Id, E_Procedure);
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));
2484 -- Process the formals
2486 New_Formals := Replicate_Formals (Loc, Formals);
2488 -- A function with a controlling result and no first controlling
2489 -- formal needs no additional parameter.
2491 if Has_Controlling_Result (Subp_Id)
2493 (No (First_Formal (Subp_Id))
2494 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
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.
2502 elsif Present (First_Param) then
2503 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2505 Make_Access_Definition (Loc,
2507 New_Reference_To (Obj_Typ, Loc));
2508 Set_Null_Exclusion_Present (Obj_Param_Typ,
2509 Null_Exclusion_Present (Parameter_Type (First_Param)));
2512 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2516 Make_Parameter_Specification (Loc,
2517 Defining_Identifier =>
2518 Make_Defining_Identifier (Loc,
2520 In_Present => In_Present (First_Param),
2521 Out_Present => Out_Present (First_Param),
2522 Parameter_Type => Obj_Param_Typ);
2524 Prepend_To (New_Formals, Obj_Param);
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.
2532 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
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);
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.
2547 if Ekind (Subp_Id) = E_Function then
2552 if Has_Controlling_Result (Subp_Id) then
2555 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2557 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2561 Make_Function_Specification (Loc,
2562 Defining_Unit_Name => Wrapper_Id,
2563 Parameter_Specifications => New_Formals,
2564 Result_Definition => Res_Def);
2568 Make_Procedure_Specification (Loc,
2569 Defining_Unit_Name => Wrapper_Id,
2570 Parameter_Specifications => New_Formals);
2573 end Build_Wrapper_Spec;
2575 -------------------------
2576 -- Build_Wrapper_Specs --
2577 -------------------------
2579 procedure Build_Wrapper_Specs
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.
2590 procedure Scan_Declarations (L : List_Id) is
2592 Wrap_Decl : Node_Id;
2593 Wrap_Spec : Node_Id;
2601 while Present (Decl) loop
2604 if Nkind (Decl) = N_Entry_Declaration
2605 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2609 (Subp_Id => Defining_Identifier (Decl),
2611 Formals => Parameter_Specifications (Decl));
2613 elsif Nkind (Decl) = N_Subprogram_Declaration then
2616 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2619 Parameter_Specifications (Specification (Decl)));
2622 if Present (Wrap_Spec) then
2624 Make_Subprogram_Declaration (Loc,
2625 Specification => Wrap_Spec);
2627 Insert_After (N, Wrap_Decl);
2630 Analyze (Wrap_Decl);
2635 end Scan_Declarations;
2637 -- start of processing for Build_Wrapper_Specs
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));
2646 Rec_Typ := Corresponding_Record_Type (Typ);
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.
2652 if Present (Interfaces (Rec_Typ))
2653 and then Present (Def)
2655 Scan_Declarations (Visible_Declarations (Def));
2656 Scan_Declarations (Private_Declarations (Def));
2658 end Build_Wrapper_Specs;
2660 ---------------------------
2661 -- Build_Find_Body_Index --
2662 ---------------------------
2664 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2665 Loc : constant Source_Ptr := Sloc (Typ);
2668 Has_F : Boolean := False;
2670 If_St : Node_Id := Empty;
2673 Decls : List_Id := New_List;
2676 Siz : Node_Id := Empty;
2678 procedure Add_If_Clause (Expr : Node_Id);
2679 -- Add test for range of current entry
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.
2689 procedure Add_If_Clause (Expr : Node_Id) is
2691 Stats : constant List_Id :=
2693 Make_Simple_Return_Statement (Loc,
2694 Expression => Make_Integer_Literal (Loc, Index + 1)));
2697 -- Index for current entry body
2701 -- Compute total length of entry queues so far
2709 Right_Opnd => Expr);
2714 Left_Opnd => Make_Identifier (Loc, Name_uE),
2717 -- Map entry queue indexes in the range of the current family
2718 -- into the current index, that designates the entry body.
2722 Make_Implicit_If_Statement (Typ,
2724 Then_Statements => Stats,
2725 Elsif_Parts => New_List);
2731 Make_Elsif_Part (Loc,
2733 Then_Statements => Stats),
2734 Elsif_Parts (If_St));
2738 ------------------------------
2739 -- Convert_Discriminant_Ref --
2740 ------------------------------
2742 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2746 if Is_Entity_Name (Bound)
2747 and then Ekind (Entity (Bound)) = E_Discriminant
2750 Make_Selected_Component (Loc,
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)));
2758 B := New_Copy_Tree (Bound);
2762 end Convert_Discriminant_Ref;
2764 -- Start of processing for Build_Find_Body_Index
2767 Spec := Build_Find_Body_Index_Spec (Typ);
2769 Ent := First_Entity (Typ);
2770 while Present (Ent) loop
2771 if Ekind (Ent) = E_Entry_Family then
2781 -- If the protected type has no entry families, there is a one-one
2782 -- correspondence between entry queue and entry body.
2785 Make_Simple_Return_Statement (Loc,
2786 Expression => Make_Identifier (Loc, Name_uE));
2789 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2792 -- if E <= l1 then return 1;
2793 -- elsif E <= l1 + l2 then return 2;
2798 Ent := First_Entity (Typ);
2800 Add_Object_Pointer (Loc, Typ, Decls);
2802 while Present (Ent) loop
2803 if Ekind (Ent) = E_Entry then
2804 Add_If_Clause (Make_Integer_Literal (Loc, 1));
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));
2819 Make_Simple_Return_Statement (Loc,
2820 Expression => Make_Integer_Literal (Loc, 1));
2822 elsif Nkind (Ret) = N_If_Statement then
2824 -- Ranges are in increasing order, so last one doesn't need guard
2827 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2830 Set_Else_Statements (Ret, Then_Statements (Nod));
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;
2844 --------------------------------
2845 -- Build_Find_Body_Index_Spec --
2846 --------------------------------
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);
2858 Make_Function_Specification (Loc,
2859 Defining_Unit_Name => Id,
2860 Parameter_Specifications => New_List (
2861 Make_Parameter_Specification (Loc,
2862 Defining_Identifier => Parm1,
2864 New_Reference_To (RTE (RE_Address), Loc)),
2866 Make_Parameter_Specification (Loc,
2867 Defining_Identifier => Parm2,
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;
2874 -------------------------
2875 -- Build_Master_Entity --
2876 -------------------------
2878 procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
2879 Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
2881 Context_Id : Entity_Id;
2887 if Is_Itype (Obj_Or_Typ) then
2888 Par := Associated_Node_For_Itype (Obj_Or_Typ);
2890 Par := Parent (Obj_Or_Typ);
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.
2897 if Is_Record_Type (Current_Scope) then
2899 Context_Id := Current_Scope;
2900 Decls := List_Containing (Context);
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.
2907 Find_Enclosing_Context (Par, Context, Context_Id, Decls);
2910 -- Do not create a master if one already exists or there is no task
2913 if Has_Master_Entity (Context_Id)
2914 or else Restriction_Active (No_Task_Hierarchy)
2919 -- Create a master, generate:
2920 -- _Master : constant Master_Id := Current_Master.all;
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),
2929 Make_Explicit_Dereference (Loc,
2930 New_Reference_To (RTE (RE_Current_Master), Loc)));
2932 -- The master is inserted at the start of the declarative list of the
2935 Prepend_To (Decls, Decl);
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.
2941 if Context_Id /= Current_Scope then
2942 Push_Scope (Context_Id);
2949 -- Mark the enclosing scope and its associated construct as being task
2952 Set_Has_Master_Entity (Context_Id);
2954 while Present (Context)
2955 and then Nkind (Context) /= N_Compilation_Unit
2957 if Nkind_In (Context, N_Block_Statement,
2961 Set_Is_Task_Master (Context);
2964 elsif Nkind (Parent (Context)) = N_Subunit then
2965 Context := Corresponding_Stub (Parent (Context));
2968 Context := Parent (Context);
2970 end Build_Master_Entity;
2972 ---------------------------
2973 -- Build_Master_Renaming --
2974 ---------------------------
2976 procedure Build_Master_Renaming
2977 (Ptr_Typ : Entity_Id;
2978 Ins_Nod : Node_Id := Empty)
2980 Loc : constant Source_Ptr := Sloc (Ptr_Typ);
2982 Master_Decl : Node_Id;
2983 Master_Id : Entity_Id;
2986 -- Nothing to do if there is no task hierarchy
2988 if Restriction_Active (No_Task_Hierarchy) then
2992 -- Determine the proper context to insert the master renaming
2994 if Present (Ins_Nod) then
2996 elsif Is_Itype (Ptr_Typ) then
2997 Context := Associated_Node_For_Itype (Ptr_Typ);
2999 Context := Parent (Ptr_Typ);
3003 -- <Ptr_Typ>M : Master_Id renames _Master;
3006 Make_Defining_Identifier (Loc,
3007 New_External_Name (Chars (Ptr_Typ), 'M'));
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));
3015 Insert_Action (Context, Master_Decl);
3017 -- The renamed master now services the access type
3019 Set_Master_Id (Ptr_Typ, Master_Id);
3020 end Build_Master_Renaming;
3022 -----------------------------------------
3023 -- Build_Private_Protected_Declaration --
3024 -----------------------------------------
3026 function Build_Private_Protected_Declaration
3027 (N : Node_Id) return Entity_Id
3029 Loc : constant Source_Ptr := Sloc (N);
3030 Body_Id : constant Entity_Id := Defining_Entity (N);
3035 Spec_Id : Entity_Id;
3038 Formal := First_Formal (Body_Id);
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.
3044 if Present (Formal) or else Expander_Active then
3045 Plist := Copy_Parameter_List (Body_Id);
3050 if Nkind (Specification (N)) = N_Procedure_Specification then
3052 Make_Procedure_Specification (Loc,
3053 Defining_Unit_Name =>
3054 Make_Defining_Identifier (Sloc (Body_Id),
3055 Chars => Chars (Body_Id)),
3056 Parameter_Specifications =>
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));
3069 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
3070 Insert_Before (N, Decl);
3071 Spec_Id := Defining_Unit_Name (New_Spec);
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.
3078 Set_Comes_From_Source (Spec_Id, True);
3080 Set_Has_Completion (Spec_Id);
3081 Set_Convention (Spec_Id, Convention_Protected);
3083 end Build_Private_Protected_Declaration;
3085 ---------------------------
3086 -- Build_Protected_Entry --
3087 ---------------------------
3089 function Build_Protected_Entry
3092 Pid : Node_Id) return Node_Id
3094 Loc : constant Source_Ptr := Sloc (N);
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
3103 Han_Loc : Source_Ptr;
3104 -- Used for the exception handler, inserted at end of the body
3106 Op_Decls : constant List_Id := New_List;
3114 -- Set the source location on the exception handler only when debugging
3115 -- the expanded code (see Make_Implicit_Exception_Handler).
3117 if Debug_Generated_Code then
3120 -- Otherwise the inserted code should not be visible to the debugger
3123 Han_Loc := No_Location;
3127 Make_Defining_Identifier (Loc,
3128 Chars => Chars (Protected_Body_Subprogram (Ent)));
3130 Build_Protected_Entry_Specification (Loc, Edef, Empty);
3132 -- Add the following declarations:
3133 -- type poVP is access poV;
3134 -- _object : poVP := poVP (_O);
3136 -- where _O is the formal parameter associated with the concurrent
3137 -- object. These declarations are needed for Complete_Entry_Body.
3139 Add_Object_Pointer (Loc, Pid, Op_Decls);
3141 -- Add renamings for all formals, the Protection object, discriminals,
3142 -- privals and the entry index constant for use by debugger.
3144 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
3145 Debug_Private_Data_Declarations (Decls);
3147 case Corresponding_Runtime_Package (Pid) is
3148 when System_Tasking_Protected_Objects_Entries =>
3150 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
3152 when System_Tasking_Protected_Objects_Single_Entry =>
3154 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
3157 raise Program_Error;
3160 Op_Stats := New_List (
3161 Make_Block_Statement (Loc,
3162 Declarations => Decls,
3163 Handled_Statement_Sequence =>
3164 Handled_Statement_Sequence (N)),
3166 Make_Procedure_Call_Statement (End_Loc,
3168 Parameter_Associations => New_List (
3169 Make_Attribute_Reference (End_Loc,
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))));
3176 -- When exceptions can not be propagated, we never need to call
3177 -- Exception_Complete_Entry_Body
3179 if No_Exception_Handlers_Set then
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));
3190 Ohandle := Make_Others_Choice (Loc);
3191 Set_All_Others (Ohandle);
3193 case Corresponding_Runtime_Package (Pid) is
3194 when System_Tasking_Protected_Objects_Entries =>
3197 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
3199 when System_Tasking_Protected_Objects_Single_Entry =>
3202 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
3205 raise Program_Error;
3208 -- Establish link between subprogram body entity and source entry
3210 Set_Corresponding_Protected_Entry (Edef, Ent);
3212 -- Create body of entry procedure. The renaming declarations are
3213 -- placed ahead of the block that contains the actual entry body.
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),
3227 Statements => New_List (
3228 Make_Procedure_Call_Statement (Han_Loc,
3230 Parameter_Associations => New_List (
3231 Make_Attribute_Reference (Han_Loc,
3233 Make_Selected_Component (Han_Loc,
3235 Make_Identifier (Han_Loc, Name_uObject),
3237 Make_Identifier (Han_Loc, Name_uObject)),
3238 Attribute_Name => Name_Unchecked_Access),
3240 Make_Function_Call (Han_Loc,
3241 Name => New_Reference_To (
3242 RTE (RE_Get_GNAT_Exception), Loc)))))))));
3244 end Build_Protected_Entry;
3246 -----------------------------------------
3247 -- Build_Protected_Entry_Specification --
3248 -----------------------------------------
3250 function Build_Protected_Entry_Specification
3253 Ent_Id : Entity_Id) return Node_Id
3255 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3258 Set_Debug_Info_Needed (Def_Id);
3260 if Present (Ent_Id) then
3261 Append_Elmt (P, Accept_Address (Ent_Id));
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),
3272 New_Reference_To (RTE (RE_Address), Loc)),
3274 Make_Parameter_Specification (Loc,
3275 Defining_Identifier => P,
3277 New_Reference_To (RTE (RE_Address), Loc)),
3279 Make_Parameter_Specification (Loc,
3280 Defining_Identifier =>
3281 Make_Defining_Identifier (Loc, Name_uE),
3283 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
3284 end Build_Protected_Entry_Specification;
3286 --------------------------
3287 -- Build_Protected_Spec --
3288 --------------------------
3290 function Build_Protected_Spec
3292 Obj_Type : Entity_Id;
3294 Unprotected : Boolean := False) return List_Id
3296 Loc : constant Source_Ptr := Sloc (N);
3299 New_Plist : List_Id;
3300 New_Param : Node_Id;
3303 New_Plist := New_List;
3305 Formal := First_Formal (Ident);
3306 while Present (Formal) loop
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));
3316 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3319 Append (New_Param, New_Plist);
3320 Next_Formal (Formal);
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
3328 Make_Parameter_Specification (Loc,
3329 Defining_Identifier =>
3330 Make_Defining_Identifier (Loc, Name_uObject),
3333 (Etype (Ident) = Standard_Void_Type
3334 and then not Is_RTE (Obj_Type, RE_Address)),
3336 New_Reference_To (Obj_Type, Loc));
3337 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3338 Prepend_To (New_Plist, Decl);
3341 end Build_Protected_Spec;
3343 ---------------------------------------
3344 -- Build_Protected_Sub_Specification --
3345 ---------------------------------------
3347 function Build_Protected_Sub_Specification
3349 Prot_Typ : Entity_Id;
3350 Mode : Subprogram_Protection_Mode) return Node_Id
3352 Loc : constant Source_Ptr := Sloc (N);
3356 New_Plist : List_Id;
3359 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3360 (Dispatching_Mode => ' ',
3361 Protected_Mode => 'P',
3362 Unprotected_Mode => 'N');
3365 if Ekind (Defining_Unit_Name (Specification (N))) =
3368 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3373 Def_Id := Defining_Unit_Name (Specification (Decl));
3376 Build_Protected_Spec
3377 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3378 Mode = Unprotected_Mode);
3380 Make_Defining_Identifier (Loc,
3381 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
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/
3389 Set_Debug_Info_Needed (New_Id);
3391 -- If a pragma Eliminate applies to the source entity, the internal
3392 -- subprograms will be eliminated as well.
3394 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3396 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3398 Make_Procedure_Specification (Loc,
3399 Defining_Unit_Name => New_Id,
3400 Parameter_Specifications => New_Plist);
3402 -- Create a new specification for the anonymous subprogram type
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))));
3412 Set_Return_Present (Defining_Unit_Name (New_Spec));
3416 end Build_Protected_Sub_Specification;
3418 -------------------------------------
3419 -- Build_Protected_Subprogram_Body --
3420 -------------------------------------
3422 function Build_Protected_Subprogram_Body
3425 N_Op_Spec : Node_Id) return Node_Id
3427 Loc : constant Source_Ptr := Sloc (N);
3429 P_Op_Spec : Node_Id;
3432 Unprot_Call : Node_Id;
3434 Lock_Name : Node_Id;
3435 Lock_Stmt : Node_Id;
3436 Service_Name : 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
3441 Object_Parm : Node_Id;
3445 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3446 -- Tell whether a given subprogram cannot raise an exception
3448 -----------------------
3449 -- Is_Exception_Safe --
3450 -----------------------
3452 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
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
3458 ---------------------
3459 -- Has_Side_Effect --
3460 ---------------------
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 ???
3466 function Has_Side_Effect (N : Node_Id) return Boolean is
3470 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3471 -- Indicate whether N is a subprogram call or a raise statement
3473 ----------------------
3474 -- Is_Call_Or_Raise --
3475 ----------------------
3477 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3479 return Nkind_In (N, N_Procedure_Call_Statement,
3482 N_Raise_Constraint_Error,
3483 N_Raise_Program_Error,
3484 N_Raise_Storage_Error);
3485 end Is_Call_Or_Raise;
3487 -- Start of processing for Has_Side_Effect
3491 while Present (Stmt) loop
3492 if Is_Call_Or_Raise (Stmt) then
3496 -- An object declaration can also contain a function call
3497 -- or a raise statement
3499 if Nkind (Stmt) = N_Object_Declaration then
3500 Expr := Expression (Stmt);
3502 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3511 end Has_Side_Effect;
3513 -- Start of processing for Is_Exception_Safe
3516 -- If the checks handled by the back end are not disabled, we cannot
3517 -- ensure that no exception will be raised.
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
3528 if Has_Side_Effect (First (Declarations (Subprogram)))
3531 First (Statements (Handled_Statement_Sequence (Subprogram))))
3537 end Is_Exception_Safe;
3539 -- Start of processing for Build_Protected_Subprogram_Body
3542 Op_Spec := Specification (N);
3543 Exc_Safe := Is_Exception_Safe (N);
3546 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
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
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))));
3560 -- Make a call to the unprotected version of the subprogram built above
3561 -- for use by the protected version built below.
3563 if Nkind (Op_Spec) = N_Function_Specification then
3565 R := Make_Temporary (Loc, 'R');
3567 Make_Object_Declaration (Loc,
3568 Defining_Identifier => R,
3569 Constant_Present => True,
3570 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3572 Make_Function_Call (Loc,
3573 Name => Make_Identifier (Loc,
3574 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3575 Parameter_Associations => Uactuals));
3578 Make_Simple_Return_Statement (Loc,
3579 Expression => New_Reference_To (R, Loc));
3582 Unprot_Call := Make_Simple_Return_Statement (Loc,
3583 Expression => Make_Function_Call (Loc,
3585 Make_Identifier (Loc,
3586 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3587 Parameter_Associations => Uactuals));
3590 Lock_Kind := RE_Lock_Read_Only;
3594 Make_Procedure_Call_Statement (Loc,
3596 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3597 Parameter_Associations => Uactuals);
3599 Lock_Kind := RE_Lock;
3602 -- Wrap call in block that will be covered by an at_end handler
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)));
3611 -- Make the protected subprogram body. This locks the protected
3612 -- object and calls the unprotected version of the subprogram.
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);
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);
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);
3628 raise Program_Error;
3632 Make_Attribute_Reference (Loc,
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);
3639 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3641 Parameter_Associations => New_List (Object_Parm));
3643 if Abort_Allowed then
3645 Make_Procedure_Call_Statement (Loc,
3646 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3647 Parameter_Associations => Empty_List),
3651 Stmts := New_List (Lock_Stmt);
3654 if not Exc_Safe then
3655 Append (Unprot_Call, Stmts);
3657 if Nkind (Op_Spec) = N_Function_Specification then
3659 Stmts := Empty_List;
3661 Append (Unprot_Call, Stmts);
3665 Make_Procedure_Call_Statement (Loc,
3666 Name => Service_Name,
3667 Parameter_Associations =>
3668 New_List (New_Copy_Tree (Object_Parm))),
3671 if Abort_Allowed then
3673 Make_Procedure_Call_Statement (Loc,
3674 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3675 Parameter_Associations => Empty_List),
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);
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));
3697 if not Exc_Safe then
3698 Set_Is_Protected_Subprogram_Body (Sub_Body);
3702 end Build_Protected_Subprogram_Body;
3704 -------------------------------------
3705 -- Build_Protected_Subprogram_Call --
3706 -------------------------------------
3708 procedure Build_Protected_Subprogram_Call
3712 External : Boolean := True)
3714 Loc : constant Source_Ptr := Sloc (N);
3715 Sub : constant Entity_Id := Entity (Name);
3721 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3724 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3727 if Present (Parameter_Associations (N)) then
3728 Params := New_Copy_List_Tree (Parameter_Associations (N));
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.
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))
3740 Set_Etype (Rec, Root_Type (Etype (Rec)));
3741 Set_Subtype_Mark (Rec,
3742 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3745 Prepend (Rec, Params);
3747 if Ekind (Sub) = E_Procedure then
3749 Make_Procedure_Call_Statement (Loc,
3751 Parameter_Associations => Params));
3754 pragma Assert (Ekind (Sub) = E_Function);
3756 Make_Function_Call (Loc,
3758 Parameter_Associations => Params));
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)))
3766 Add_Shared_Var_Lock_Procs (N);
3768 end Build_Protected_Subprogram_Call;
3770 -------------------------
3771 -- Build_Selected_Name --
3772 -------------------------
3774 function Build_Selected_Name
3775 (Prefix : Entity_Id;
3776 Selector : Entity_Id;
3777 Append_Char : Character := ' ') return Name_Id
3779 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3780 Select_Len : Natural;
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));
3788 -- If scope is anonymous type, discard suffix to recover name of
3789 -- single protected object. Otherwise use protected type name.
3791 if Name_Buffer (Name_Len) = 'T' then
3792 Name_Len := Name_Len - 1;
3795 Add_Str_To_Name_Buffer ("__");
3796 for J in 1 .. Select_Len loop
3797 Add_Char_To_Name_Buffer (Select_Buffer (J));
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.
3806 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3808 if Append_Char /= ' ' then
3809 if Append_Char = 'P' or Append_Char = 'N' then
3810 Add_Char_To_Name_Buffer (Append_Char);
3813 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3814 return New_External_Name (Name_Find, ' ', -1);
3819 end Build_Selected_Name;
3821 -----------------------------
3822 -- Build_Simple_Entry_Call --
3823 -----------------------------
3825 -- A task entry call is converted to a call to Call_Simple
3828 -- P : parms := (parm, parm, parm);
3830 -- Call_Simple (acceptor-task, entry-index, P'Address);
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.
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.
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.
3851 -- A protected entry call is converted to a Protected_Entry_Call:
3854 -- P : E1_Params := (param, param, param);
3856 -- Bnn : Communications_Block;
3859 -- P : E1_Params := (param, param, param);
3860 -- Bnn : Communications_Block;
3863 -- Protected_Entry_Call (
3864 -- Object => po._object'Access,
3865 -- E => <entry index>;
3866 -- Uninterpreted_Data => P'Address;
3867 -- Mode => Simple_Call;
3874 procedure Build_Simple_Entry_Call
3883 -- If call has been inlined, nothing left to do
3885 if Nkind (N) = N_Block_Statement then
3889 -- Convert entry call to Call_Simple call
3892 Loc : constant Source_Ptr := Sloc (N);
3893 Parms : constant List_Id := Parameter_Associations (N);
3894 Stats : constant List_Id := New_List;
3897 Comm_Name : Entity_Id;
3901 Ent_Acc : Entity_Id;
3903 Iface_Tag : Entity_Id;
3904 Iface_Typ : Entity_Id;
3917 -- Simple entry and entry family cases merge here
3919 Ent := Entity (Ename);
3920 Ent_Acc := Entry_Parameters_Type (Ent);
3921 Conctyp := Etype (Concval);
3923 -- If prefix is an access type, dereference to obtain the task type
3925 if Is_Access_Type (Conctyp) then
3926 Conctyp := Designated_Type (Conctyp);
3929 -- Special case for protected subprogram calls
3931 if Is_Protected_Type (Conctyp)
3932 and then Is_Subprogram (Entity (Ename))
3934 if not Is_Eliminated (Entity (Ename)) then
3935 Build_Protected_Subprogram_Call
3936 (N, Ename, Convert_Concurrent (Concval, Conctyp));
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.
3948 if Nkind (Concval) = N_Function_Call
3949 and then Is_Task_Type (Conctyp)
3950 and then Ada_Version >= Ada_2005
3953 ExpR : constant Node_Id := Relocate_Node (Concval);
3954 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
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));
3972 Parm1 := Concurrent_Ref (Concval);
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
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)
3987 X := Make_Defining_Identifier (Loc, Name_uX);
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));
3997 Append_To (Decls, Xdecl);
3998 Parm2 := New_Reference_To (X, Loc);
4005 -- The third parameter is the packaged parameters. If there are
4006 -- none, then it is just the null address, since nothing is passed.
4009 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
4012 -- Case of parameters present, where third argument is the address
4013 -- of a packaged record containing the required parameter values.
4016 -- First build a list of parameter values, which are references to
4017 -- objects of the parameter types.
4021 Actual := First_Actual (N);
4022 Formal := First_Formal (Ent);
4024 while Present (Actual) loop
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.
4029 if Is_By_Copy_Type (Etype (Actual)) then
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));
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.
4041 Set_No_Initialization (N_Node);
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).
4049 if Ekind (Formal) /= E_Out_Parameter
4050 or else Is_Access_Type (Etype (Formal))
4053 New_Reference_To (Defining_Identifier (N_Node), Loc);
4054 Set_Assignment_OK (N_Var);
4056 Make_Assignment_Statement (Loc,
4058 Expression => Relocate_Node (Actual)));
4061 Append (N_Node, Decls);
4064 Make_Attribute_Reference (Loc,
4065 Attribute_Name => Name_Unchecked_Access,
4067 New_Reference_To (Defining_Identifier (N_Node), Loc)));
4069 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4071 elsif Is_VM_By_Copy_Actual (Actual) then
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);
4081 Append (N_Node, Decls);
4084 Make_Attribute_Reference (Loc,
4085 Attribute_Name => Name_Unchecked_Access,
4087 New_Reference_To (Defining_Identifier (N_Node), Loc)));
4090 -- Interface class-wide formal
4092 if Ada_Version >= Ada_2005
4093 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
4094 and then Is_Interface (Etype (Formal))
4096 Iface_Typ := Etype (Etype (Formal));
4099 -- formal_iface_type! (actual.iface_tag)'reference
4102 Find_Interface_Tag (Etype (Actual), Iface_Typ);
4103 pragma Assert (Present (Iface_Tag));
4106 Make_Reference (Loc,
4107 Unchecked_Convert_To (Iface_Typ,
4108 Make_Selected_Component (Loc,
4110 Relocate_Node (Actual),
4112 New_Reference_To (Iface_Tag, Loc)))));
4118 Make_Reference (Loc, Relocate_Node (Actual)));
4122 Next_Actual (Actual);
4123 Next_Formal_With_Extras (Formal);
4126 -- Now build the declaration of parameters initialized with the
4127 -- aggregate containing this constructed parameter list.
4129 P := Make_Defining_Identifier (Loc, Name_uP);
4132 Make_Object_Declaration (Loc,
4133 Defining_Identifier => P,
4134 Object_Definition =>
4135 New_Reference_To (Designated_Type (Ent_Acc), Loc),
4137 Make_Aggregate (Loc, Expressions => Plist));
4140 Make_Attribute_Reference (Loc,
4141 Prefix => New_Reference_To (P, Loc),
4142 Attribute_Name => Name_Address);
4144 Append (Pdecl, Decls);
4147 -- Now we can create the call, case of protected type
4149 if Is_Protected_Type (Conctyp) then
4150 case Corresponding_Runtime_Package (Conctyp) is
4151 when System_Tasking_Protected_Objects_Entries =>
4153 -- Change the type of the index declaration
4155 Set_Object_Definition (Xdecl,
4156 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
4158 -- Some additional declarations for protected entry calls
4164 -- Bnn : Communications_Block;
4166 Comm_Name := Make_Temporary (Loc, 'B');
4169 Make_Object_Declaration (Loc,
4170 Defining_Identifier => Comm_Name,
4171 Object_Definition =>
4172 New_Reference_To (RTE (RE_Communication_Block), Loc)));
4174 -- Some additional statements for protected entry calls
4176 -- Protected_Entry_Call (
4177 -- Object => po._object'Access,
4178 -- E => <entry index>;
4179 -- Uninterpreted_Data => P'Address;
4180 -- Mode => Simple_Call;
4184 Make_Procedure_Call_Statement (Loc,
4186 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
4188 Parameter_Associations => New_List (
4189 Make_Attribute_Reference (Loc,
4190 Attribute_Name => Name_Unchecked_Access,
4194 New_Reference_To (RTE (RE_Simple_Call), Loc),
4195 New_Occurrence_Of (Comm_Name, Loc)));
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);
4204 Make_Procedure_Call_Statement (Loc,
4205 Name => New_Reference_To (
4206 RTE (RE_Protected_Single_Entry_Call), Loc),
4208 Parameter_Associations => New_List (
4209 Make_Attribute_Reference (Loc,
4210 Attribute_Name => Name_Unchecked_Access,
4213 New_Reference_To (RTE (RE_Simple_Call), Loc)));
4216 raise Program_Error;
4219 -- Case of task type
4223 Make_Procedure_Call_Statement (Loc,
4224 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
4225 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
4229 Append_To (Stats, Call);
4231 -- If there are out or in/out parameters by copy add assignment
4232 -- statements for the result values.
4234 if Present (Parms) then
4235 Actual := First_Actual (N);
4236 Formal := First_Formal (Ent);
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
4245 Make_Assignment_Statement (Loc,
4246 Name => New_Copy (Actual),
4248 Make_Explicit_Dereference (Loc,
4249 Make_Selected_Component (Loc,
4250 Prefix => New_Reference_To (P, Loc),
4252 Make_Identifier (Loc, Chars (Formal)))));
4254 -- In all cases (including limited private types) we want
4255 -- the assignment to be valid.
4257 Set_Assignment_OK (Name (N_Node));
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
4266 if (Nkind (Parent (N)) = N_Triggering_Alternative
4267 and then N = Triggering_Statement (Parent (N)))
4269 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4270 and then N = Entry_Call_Statement (Parent (N)))
4272 if No (Statements (Parent (N))) then
4273 Set_Statements (Parent (N), New_List);
4276 Prepend (N_Node, Statements (Parent (N)));
4279 Insert_After (Call, N_Node);
4283 Next_Actual (Actual);
4284 Next_Formal_With_Extras (Formal);
4288 -- Finally, create block and analyze it
4291 Make_Block_Statement (Loc,
4292 Declarations => Decls,
4293 Handled_Statement_Sequence =>
4294 Make_Handled_Sequence_Of_Statements (Loc,
4295 Statements => Stats)));
4299 end Build_Simple_Entry_Call;
4301 --------------------------------
4302 -- Build_Task_Activation_Call --
4303 --------------------------------
4305 procedure Build_Task_Activation_Call (N : Node_Id) is
4306 Loc : constant Source_Ptr := Sloc (N);
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.
4317 if Nkind (N) = N_Package_Body then
4318 P := Corresponding_Spec (N);
4321 exit when Nkind (P) = N_Package_Declaration;
4324 Chain := Activation_Chain_Entity (P);
4327 Chain := Activation_Chain_Entity (N);
4330 if Present (Chain) then
4331 if Restricted_Profile then
4332 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
4334 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4338 Make_Procedure_Call_Statement (Loc,
4340 Parameter_Associations =>
4341 New_List (Make_Attribute_Reference (Loc,
4342 Prefix => New_Occurrence_Of (Chain, Loc),
4343 Attribute_Name => Name_Unchecked_Access)));
4345 if Nkind (N) = N_Package_Declaration then
4346 if Present (Corresponding_Body (N)) then
4349 elsif Present (Private_Declarations (Specification (N))) then
4350 Append (Call, Private_Declarations (Specification (N)));
4353 Append (Call, Visible_Declarations (Specification (N)));
4357 if Present (Handled_Statement_Sequence (N)) then
4359 -- The call goes at the start of the statement sequence
4360 -- after the start of exception range label if one is present.
4366 Stm := First (Statements (Handled_Statement_Sequence (N)));
4368 -- A special case, skip exception range label if one is
4369 -- present (from front end zcx processing).
4371 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
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.
4379 if Nkind (Stm) = N_Block_Statement
4380 and then Exception_Junk (Stm)
4383 First (Statements (Handled_Statement_Sequence (Stm)));
4386 -- Insertion point is after any exception label pushes,
4387 -- since we want it covered by any local handlers.
4389 while Nkind (Stm) in N_Push_xxx_Label loop
4393 -- Now we have the proper insertion point
4395 Insert_Before (Stm, Call);
4399 Set_Handled_Statement_Sequence (N,
4400 Make_Handled_Sequence_Of_Statements (Loc,
4401 Statements => New_List (Call)));
4406 Check_Task_Activation (N);
4408 end Build_Task_Activation_Call;
4410 -------------------------------
4411 -- Build_Task_Allocate_Block --
4412 -------------------------------
4414 procedure Build_Task_Allocate_Block
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');
4429 Make_Block_Statement (Loc,
4430 Identifier => New_Reference_To (Blkent, Loc),
4431 Declarations => New_List (
4433 -- _Chain : Activation_Chain;
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))),
4441 Handled_Statement_Sequence =>
4442 Make_Handled_Sequence_Of_Statements (Loc,
4444 Statements => New_List (
4448 Make_Procedure_Call_Statement (Loc,
4449 Name => New_Reference_To (Init, Loc),
4450 Parameter_Associations => Args),
4452 -- Activate_Tasks (_Chain);
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))))),
4461 Has_Created_Identifier => True,
4462 Is_Task_Allocation_Block => True);
4465 Make_Implicit_Label_Declaration (Loc,
4466 Defining_Identifier => Blkent,
4467 Label_Construct => Block));
4469 Append_To (Actions, Block);
4471 Set_Activation_Chain_Entity (Block, Chain);
4472 end Build_Task_Allocate_Block;
4474 -----------------------------------------------
4475 -- Build_Task_Allocate_Block_With_Init_Stmts --
4476 -----------------------------------------------
4478 procedure Build_Task_Allocate_Block_With_Init_Stmts
4481 Init_Stmts : List_Id)
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');
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))));
4499 Make_Block_Statement (Loc,
4500 Identifier => New_Reference_To (Blkent, Loc),
4501 Declarations => New_List (
4503 -- _Chain : Activation_Chain;
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))),
4511 Handled_Statement_Sequence =>
4512 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4514 Has_Created_Identifier => True,
4515 Is_Task_Allocation_Block => True);
4518 Make_Implicit_Label_Declaration (Loc,
4519 Defining_Identifier => Blkent,
4520 Label_Construct => Block));
4522 Append_To (Actions, Block);
4524 Set_Activation_Chain_Entity (Block, Chain);
4525 end Build_Task_Allocate_Block_With_Init_Stmts;
4527 -----------------------------------
4528 -- Build_Task_Proc_Specification --
4529 -----------------------------------
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;
4536 -- Case of explicit task type, suffix TB
4538 if Comes_From_Source (T) then
4540 Make_Defining_Identifier (Loc,
4541 Chars => New_External_Name (Chars (T), "TB"));
4543 -- Case of anonymous task type, suffix B
4547 Make_Defining_Identifier (Loc,
4548 Chars => New_External_Name (Chars (T), 'B'));
4551 Set_Is_Internal (Spec_Id);
4553 -- Associate the procedure with the task, if this is the declaration
4554 -- (and not the body) of the procedure.
4556 if No (Task_Body_Procedure (T)) then
4557 Set_Task_Body_Procedure (T, Spec_Id);
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),
4568 Make_Access_Definition (Loc,
4570 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4571 end Build_Task_Proc_Specification;
4573 ---------------------------------------
4574 -- Build_Unprotected_Subprogram_Body --
4575 ---------------------------------------
4577 function Build_Unprotected_Subprogram_Body
4579 Pid : Node_Id) return Node_Id
4581 Decls : constant List_Id := Declarations (N);
4584 -- Add renamings for the Protection object, discriminals, privals and
4585 -- the entry index constant for use by debugger.
4587 Debug_Private_Data_Declarations (Decls);
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
4594 Make_Subprogram_Body (Sloc (N),
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;
4601 ----------------------------
4602 -- Collect_Entry_Families --
4603 ----------------------------
4605 procedure Collect_Entry_Families
4608 Current_Node : in out Node_Id;
4609 Conctyp : Entity_Id)
4612 Efam_Decl : Node_Id;
4613 Efam_Type : Entity_Id;
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');
4624 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4626 Bas_Decl : Node_Id := Empty;
4631 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4633 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4634 Bas := Make_Temporary (Loc, 'B');
4637 Make_Subtype_Declaration (Loc,
4638 Defining_Identifier => Bas,
4639 Subtype_Indication =>
4640 Make_Subtype_Indication (Loc,
4642 New_Occurrence_Of (Standard_Integer, Loc),
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)))));
4651 Insert_After (Current_Node, Bas_Decl);
4652 Current_Node := Bas_Decl;
4657 Make_Full_Type_Declaration (Loc,
4658 Defining_Identifier => Efam_Type,
4660 Make_Unconstrained_Array_Definition (Loc,
4662 (New_List (New_Occurrence_Of (Bas, Loc))),
4664 Component_Definition =>
4665 Make_Component_Definition (Loc,
4666 Aliased_Present => False,
4667 Subtype_Indication =>
4668 New_Reference_To (Standard_Character, Loc))));
4671 Insert_After (Current_Node, Efam_Decl);
4672 Current_Node := Efam_Decl;
4673 Analyze (Efam_Decl);
4676 Make_Component_Declaration (Loc,
4677 Defining_Identifier =>
4678 Make_Defining_Identifier (Loc, Chars (Efam)),
4680 Component_Definition =>
4681 Make_Component_Definition (Loc,
4682 Aliased_Present => False,
4683 Subtype_Indication =>
4684 Make_Subtype_Indication (Loc,
4686 New_Occurrence_Of (Efam_Type, Loc),
4689 Make_Index_Or_Discriminant_Constraint (Loc,
4690 Constraints => New_List (
4692 (Etype (Discrete_Subtype_Definition
4693 (Parent (Efam))), Loc)))))));
4699 end Collect_Entry_Families;
4701 -----------------------
4702 -- Concurrent_Object --
4703 -----------------------
4705 function Concurrent_Object
4706 (Spec_Id : Entity_Id;
4707 Conc_Typ : Entity_Id) return Entity_Id
4710 -- Parameter _O or _object
4712 if Is_Protected_Type (Conc_Typ) then
4713 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4718 pragma Assert (Is_Task_Type (Conc_Typ));
4719 return First_Formal (Task_Body_Procedure (Conc_Typ));
4721 end Concurrent_Object;
4723 ----------------------
4724 -- Copy_Result_Type --
4725 ----------------------
4727 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4728 New_Res : constant Node_Id := New_Copy_Tree (Res);
4733 -- If the result type is an access_to_subprogram, we must create
4734 -- new entities for its spec.
4736 if Nkind (New_Res) = N_Access_Definition
4737 and then Present (Access_To_Subprogram_Definition (New_Res))
4739 -- Provide new entities for the formals
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)));
4752 end Copy_Result_Type;
4754 --------------------
4755 -- Concurrent_Ref --
4756 --------------------
4758 -- The expression returned for a reference to a concurrent object has the
4761 -- taskV!(name)._Task_Id
4765 -- objectV!(name)._Object
4767 -- for a protected object. For the case of an access to a concurrent
4768 -- object, there is an extra explicit dereference:
4770 -- taskV!(name.all)._Task_Id
4771 -- objectV!(name.all)._Object
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.
4777 -- For the case of a task type name, the expression is
4781 -- i.e. a call to the Self function which returns precisely this Task_Id
4783 -- For the case of a protected type name, the expression is
4787 -- which is a renaming of the _object field of the current object
4788 -- record, passed into protected operations as a parameter.
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);
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).
4800 ---------------------
4801 -- Is_Current_Task --
4802 ---------------------
4804 function Is_Current_Task (T : Entity_Id) return Boolean is
4808 Scop := Current_Scope;
4809 while Present (Scop)
4810 and then Scop /= Standard_Standard
4816 elsif Is_Task_Type (Scop) then
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.
4823 elsif Is_Overloadable (Scop)
4824 and then In_Open_Scopes (T)
4829 Scop := Scope (Scop);
4833 -- We know that we are within the task body, so should have found it
4836 raise Program_Error;
4837 end Is_Current_Task;
4839 -- Start of processing for Concurrent_Ref
4842 if Is_Access_Type (Ntyp) then
4843 Dtyp := Designated_Type (Ntyp);
4845 if Is_Protected_Type (Dtyp) then
4846 Sel := Name_uObject;
4848 Sel := Name_uTask_Id;
4852 Make_Selected_Component (Loc,
4854 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4855 Make_Explicit_Dereference (Loc, N)),
4856 Selector_Name => Make_Identifier (Loc, Sel));
4858 elsif Is_Entity_Name (N)
4859 and then Is_Concurrent_Type (Entity (N))
4861 if Is_Task_Type (Entity (N)) then
4863 if Is_Current_Task (Entity (N)) then
4865 Make_Function_Call (Loc,
4866 Name => New_Reference_To (RTE (RE_Self), Loc));
4871 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4872 T_Body : constant Node_Id :=
4873 Parent (Corresponding_Body (Parent (Entity (N))));
4877 Make_Object_Declaration (Loc,
4878 Defining_Identifier => T_Self,
4879 Object_Definition =>
4880 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4882 Make_Function_Call (Loc,
4883 Name => New_Reference_To (RTE (RE_Self), Loc)));
4884 Prepend (Decl, Declarations (T_Body));
4886 Set_Scope (T_Self, Entity (N));
4887 return New_Occurrence_Of (T_Self, Loc);
4892 pragma Assert (Is_Protected_Type (Entity (N)));
4895 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4899 if Is_Protected_Type (Ntyp) then
4900 Sel := Name_uObject;
4902 elsif Is_Task_Type (Ntyp) then
4903 Sel := Name_uTask_Id;
4906 raise Program_Error;
4910 Make_Selected_Component (Loc,
4912 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4914 Selector_Name => Make_Identifier (Loc, Sel));
4918 ------------------------
4919 -- Convert_Concurrent --
4920 ------------------------
4922 function Convert_Concurrent
4924 Typ : Entity_Id) return Node_Id
4927 if not Is_Concurrent_Type (Typ) then
4931 Unchecked_Convert_To
4932 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4934 end Convert_Concurrent;
4936 -------------------------------------
4937 -- Debug_Private_Data_Declarations --
4938 -------------------------------------
4940 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4941 Debug_Nod : Node_Id;
4945 Decl := First (Decls);
4946 while Present (Decl)
4947 and then not Comes_From_Source (Decl)
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;
4955 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4956 Set_Debug_Info_Needed (Defining_Identifier (Decl));
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));
4967 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4968 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4969 Debug_Nod := Debug_Renaming_Declaration (Decl);
4971 if Present (Debug_Nod) then
4972 Insert_After (Decl, Debug_Nod);
4978 end Debug_Private_Data_Declarations;
4980 ----------------------------
4981 -- Entry_Index_Expression --
4982 ----------------------------
4984 function Entry_Index_Expression
4988 Ttyp : Entity_Id) return Node_Id
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.
5004 -- The following is a place holder for the count of simple entries
5006 Num := Make_Integer_Literal (Sloc, 1);
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
5015 -- number_simple_entries +
5016 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5017 -- family'length + ...
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.
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.
5028 if Present (Index) then
5029 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
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))),
5049 -- Now add lengths of preceding entries and entry families
5051 Prev := First_Entity (Ttyp);
5053 while Chars (Prev) /= Chars (Ent)
5054 or else (Ekind (Prev) /= Ekind (Ent))
5055 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
5057 if Ekind (Prev) = E_Entry then
5058 Set_Intval (Num, Intval (Num) + 1);
5060 elsif Ekind (Prev) = E_Entry_Family then
5062 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
5063 Lo := Type_Low_Bound (S);
5064 Hi := Type_High_Bound (S);
5069 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
5071 -- Other components are anonymous types to be ignored
5081 end Entry_Index_Expression;
5083 ---------------------------
5084 -- Establish_Task_Master --
5085 ---------------------------
5087 procedure Establish_Task_Master (N : Node_Id) is
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);
5095 end Establish_Task_Master;
5097 --------------------------------
5098 -- Expand_Accept_Declarations --
5099 --------------------------------
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
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.
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.
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.
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:
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)
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.
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.
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.
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;
5158 if Full_Expander_Active then
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.
5164 if not Trivial_Accept_OK
5166 (No (Stats) or else Null_Statements (Statements (Stats)))
5168 Set_Handled_Statement_Sequence (N,
5169 Make_Handled_Sequence_Of_Statements (Loc,
5170 Statements => New_List (Make_Null_Statement (Loc))));
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.
5179 if Present (Handled_Statement_Sequence (N)) then
5184 Ent := Make_Temporary (Loc, 'L');
5185 Lab_Id := New_Reference_To (Ent, Loc);
5186 Lab := Make_Label (Loc, Lab_Id);
5188 Make_Implicit_Label_Declaration (Loc,
5189 Defining_Identifier => Ent,
5190 Label_Construct => Lab);
5191 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5193 Ent := Make_Temporary (Loc, 'L');
5194 Lab_Id := New_Reference_To (Ent, Loc);
5195 Lab := Make_Label (Loc, Lab_Id);
5197 Make_Implicit_Label_Declaration (Loc,
5198 Defining_Identifier => Ent,
5199 Label_Construct => Lab);
5200 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5208 -- Case of stand alone accept statement
5210 if Is_List_Member (N) then
5212 if Present (Handled_Statement_Sequence (N)) then
5213 Ann := Make_Temporary (Loc, 'A');
5216 Make_Object_Declaration (Loc,
5217 Defining_Identifier => Ann,
5218 Object_Definition =>
5219 New_Reference_To (RTE (RE_Address), Loc));
5221 Insert_Before (N, Adecl);
5224 Insert_Before (N, Ldecl);
5227 Insert_Before (N, Ldecl2);
5231 -- Case of accept statement which is in an accept alternative
5235 Acc_Alt : constant Node_Id := Parent (N);
5236 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
5240 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
5241 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
5243 -- ??? Consider a single label for select statements
5245 if Present (Handled_Statement_Sequence (N)) then
5247 Statements (Handled_Statement_Sequence (N)));
5251 Statements (Handled_Statement_Sequence (N)));
5255 -- Find first accept alternative of the selective accept. A
5256 -- valid selective accept must have at least one accept in it.
5258 Alt := First (Select_Alternatives (Sel_Acc));
5260 while Nkind (Alt) /= N_Accept_Alternative loop
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.
5269 if N = Accept_Statement (Alt) then
5270 Ann := Make_Temporary (Loc, 'A');
5272 Make_Object_Declaration (Loc,
5273 Defining_Identifier => Ann,
5274 Object_Definition =>
5275 New_Reference_To (RTE (RE_Address), Loc));
5277 Insert_Before (Sel_Acc, Adecl);
5280 -- If we are not the first accept statement, then find the Ann
5281 -- variable allocated by the first accept and use it.
5285 Node (Last_Elmt (Accept_Address
5286 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
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.
5295 if Present (Ann) then
5296 Append_Elmt (Ann, Accept_Address (Ent));
5297 Set_Debug_Info_Needed (Ann);
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.
5307 if Present (Parameter_Specifications (N))
5308 and then Present (Handled_Statement_Sequence (N))
5315 Renamed_Formal : Node_Id;
5319 Formal := First_Formal (Ent);
5321 while Present (Formal) loop
5322 Comp := Entry_Component (Formal);
5324 Make_Defining_Identifier (Loc, Chars (Formal));
5326 Set_Etype (New_F, Etype (Formal));
5327 Set_Scope (New_F, Ent);
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.
5333 Set_Debug_Info_Needed (New_F);
5335 if Ekind (Formal) = E_In_Parameter then
5336 Set_Ekind (New_F, E_Constant);
5338 Set_Ekind (New_F, E_Variable);
5339 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5342 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5345 Make_Selected_Component (Loc,
5347 Unchecked_Convert_To (
5348 Entry_Parameters_Type (Ent),
5349 New_Reference_To (Ann, Loc)),
5351 New_Reference_To (Comp, Loc));
5354 Build_Renamed_Formal_Declaration
5355 (New_F, Formal, Comp, Renamed_Formal);
5357 if No (Declarations (N)) then
5358 Set_Declarations (N, New_List);
5361 Append (Decl, Declarations (N));
5362 Set_Renamed_Object (Formal, New_F);
5363 Next_Formal (Formal);
5370 end Expand_Accept_Declarations;
5372 ---------------------------------------------
5373 -- Expand_Access_Protected_Subprogram_Type --
5374 ---------------------------------------------
5376 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5377 Loc : constant Source_Ptr := Sloc (N);
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);
5390 -- Create access to subprogram with full signature
5392 if Etype (D_T) /= Standard_Void_Type then
5394 Make_Access_Function_Definition (Loc,
5395 Parameter_Specifications => P_List,
5396 Result_Definition =>
5397 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5401 Make_Access_Procedure_Definition (Loc,
5402 Parameter_Specifications => P_List);
5406 Make_Full_Type_Declaration (Loc,
5407 Defining_Identifier => D_T2,
5408 Type_Definition => Def1);
5410 Insert_After (N, Decl1);
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.
5417 Set_Original_Access_Type (D_T2, T);
5419 -- Create Equivalent_Type, a record with two components for an access to
5420 -- object and an access to subprogram.
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))),
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))));
5439 Make_Full_Type_Declaration (Loc,
5440 Defining_Identifier => E_T,
5442 Make_Record_Definition (Loc,
5444 Make_Component_List (Loc, Component_Items => Comps)));
5446 Insert_After (Decl1, Decl2);
5448 Set_Equivalent_Type (T, E_T);
5449 end Expand_Access_Protected_Subprogram_Type;
5451 --------------------------
5452 -- Expand_Entry_Barrier --
5453 --------------------------
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);
5462 Body_Decl : Node_Id;
5465 if No_Run_Time_Mode then
5466 Error_Msg_CRT ("entry barrier", N);
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.
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);
5484 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5486 if Nkind (Parent (Body_Decl)) = N_Subunit then
5487 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5490 Insert_Before_And_Analyze (Body_Decl, B_F);
5492 Set_Discriminals (Spec_Decl);
5493 Set_Scope (Func, Scope (Prot));
5496 Analyze_And_Resolve (Cond, Any_Boolean);
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.
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
5510 if Is_Entity_Name (Cond) then
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.
5517 if Full_Expander_Active
5518 and then Scope (Entity (Cond)) /= Func
5520 Set_Declarations (B_F, Empty_List);
5523 if Entity (Cond) = Standard_False
5525 Entity (Cond) = Standard_True
5529 elsif not Expander_Active
5530 and then Scope (Entity (Cond)) = Current_Scope
5534 -- Check for case of _object.all.field (note that the explicit
5535 -- dereference gets inserted by analyze/expand of _object.field)
5537 elsif Present (Renamed_Object (Entity (Cond)))
5539 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5543 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5549 -- It is not a boolean variable or literal, so check the restriction
5551 Check_Restriction (Simple_Barriers, Cond);
5552 end Expand_Entry_Barrier;
5554 ------------------------------
5555 -- Expand_N_Abort_Statement --
5556 ------------------------------
5558 -- Expand abort T1, T2, .. Tn; into:
5559 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5561 procedure Expand_N_Abort_Statement (N : Node_Id) is
5562 Loc : constant Source_Ptr := Sloc (N);
5563 Tlist : constant List_Id := Names (N);
5569 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5572 Tasknm := First (Tlist);
5574 while Present (Tasknm) loop
5577 -- A task interface class-wide type object is being aborted.
5578 -- Retrieve its _task_id by calling a dispatching routine.
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))
5585 Append_To (Component_Associations (Aggr),
5586 Make_Component_Association (Loc,
5587 Choices => New_List (
5588 Make_Integer_Literal (Loc, Count)),
5591 -- Task_Id (Tasknm._disp_get_task_id)
5593 Make_Unchecked_Type_Conversion (Loc,
5595 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5597 Make_Selected_Component (Loc,
5598 Prefix => New_Copy_Tree (Tasknm),
5600 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
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)));
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))));
5622 end Expand_N_Abort_Statement;
5624 -------------------------------
5625 -- Expand_N_Accept_Statement --
5626 -------------------------------
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.
5634 -- If there is no handled statement sequence, or only null statements,
5635 -- then this is called a trivial accept, and the expansion is:
5637 -- Accept_Trivial (entry-index)
5639 -- If there is a handled statement sequence, then the expansion is:
5646 -- Accept_Call (entry-index, Ann);
5647 -- Renaming_Declarations for formals
5648 -- <statement sequence from N_Accept_Statement node>
5649 -- Complete_Rendezvous;
5654 -- <exception handler from N_Accept_Statement node>
5655 -- Complete_Rendezvous;
5657 -- <exception handler from N_Accept_Statement node>
5658 -- Complete_Rendezvous;
5663 -- when all others =>
5664 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
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.
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).
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.
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));
5697 -- Start of processing for Expand_N_Accept_Statement
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.
5704 if not Is_List_Member (N) then
5705 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
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.
5712 elsif Trivial_Accept_OK
5713 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5715 -- Remove declarations for renamings, because the parameter block
5716 -- will not be assigned.
5723 D := First (Declarations (N));
5725 while Present (D) loop
5727 if Nkind (D) = N_Object_Renaming_Declaration then
5735 if Present (Declarations (N)) then
5736 Insert_Actions (N, Declarations (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))));
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.
5751 if Present (Stats) then
5752 Remove_Last_Elmt (Acstack);
5755 -- Case of statement sequence present
5758 -- Construct the block, using the declarations from the accept
5759 -- statement if any to initialize the declarations of the block.
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);
5767 Make_Block_Statement (Loc,
5768 Identifier => New_Reference_To (Blkent, Loc),
5769 Declarations => Declarations (N),
5770 Handled_Statement_Sequence => Build_Accept_Body (N));
5772 -- For the analysis of the generated declarations, the parent node
5773 -- must be properly set.
5775 Set_Parent (Block, Parent (N));
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
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)));
5790 if Parent (Stats) = N then
5791 Prepend (Call, Statements (Stats));
5800 Push_Scope (Blkent);
5808 D := First (Declarations (N));
5809 while Present (D) loop
5812 if Nkind (D) = N_Object_Renaming_Declaration then
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.
5820 Typ := Entity (Subtype_Mark (D));
5821 Insert_After (Call, D);
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
5829 if Is_Class_Wide_Type (Typ) then
5830 Set_Etype (Defining_Identifier (D), Typ);
5841 -- Replace the accept statement by the new block
5846 -- Last step is to unstack the Accept_Address value
5848 Remove_Last_Elmt (Acstack);
5850 end Expand_N_Accept_Statement;
5852 ----------------------------------
5853 -- Expand_N_Asynchronous_Select --
5854 ----------------------------------
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
5861 -- If the trigger is a task entry call, the select is implemented with
5862 -- a Task_Entry_Call:
5867 -- P : parms := (parm, parm, parm);
5869 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5871 -- procedure _clean is
5874 -- Cancel_Task_Entry_Call (C);
5881 -- (<acceptor-task>, -- Acceptor
5882 -- <entry-index>, -- E
5883 -- P'Address, -- Uninterpreted_Data
5884 -- Asynchronous_Call, -- Mode
5885 -- B); -- Rendezvous_Successful
5892 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5895 -- when Abort_Signal => Abort_Undefer;
5902 -- <triggered-statements>
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)
5911 -- P : parms := (parm, parm, parm);
5913 -- Call_Simple (acceptor-task, entry-index, P'Address);
5919 -- so the task at hand is to convert the latter expansion into the former
5921 -- If the trigger is a protected entry call, the select is implemented
5922 -- with Protected_Entry_Call:
5925 -- P : E1_Params := (param, param, param);
5926 -- Bnn : Communications_Block;
5931 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5933 -- procedure _clean is
5936 -- if Enqueued (Bnn) then
5937 -- Cancel_Protected_Entry_Call (Bnn);
5944 -- Protected_Entry_Call
5945 -- (po._object'Access, -- Object
5946 -- <entry index>, -- E
5947 -- P'Address, -- Uninterpreted_Data
5948 -- Asynchronous_Call, -- Mode
5951 -- if Enqueued (Bnn) then
5955 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5958 -- when Abort_Signal => Abort_Undefer;
5961 -- if not Cancelled (Bnn) then
5962 -- <triggered-statements>
5966 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5970 -- P : E1_Params := (param, param, param);
5971 -- Bnn : Communications_Block;
5974 -- Protected_Entry_Call
5975 -- (po._object'Access, -- Object
5976 -- <entry index>, -- E
5977 -- P'Address, -- Uninterpreted_Data
5978 -- Simple_Call, -- Mode
5985 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
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);
6000 -- if K = Ada.Tags.TK_Limited_Tagged then
6001 -- <dispatching-call>;
6002 -- <triggering-statements>;
6006 -- Ada.Tags.Get_Offset_Index
6007 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6009 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6011 -- if C = POK_Protected_Entry then
6013 -- procedure _clean is
6015 -- if Enqueued (Bnn) then
6016 -- Cancel_Protected_Entry_Call (Bnn);
6022 -- _Disp_Asynchronous_Select
6023 -- (<object>, S, P'Address, D, B);
6024 -- Bnn := Communication_Block (D);
6026 -- Param1 := P.Param1;
6028 -- ParamN := P.ParamN;
6030 -- if Enqueued (Bnn) then
6031 -- <abortable-statements>
6034 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6037 -- when Abort_Signal => Abort_Undefer;
6040 -- if not Cancelled (Bnn) then
6041 -- <triggering-statements>
6044 -- elsif C = POK_Task_Entry then
6046 -- procedure _clean is
6048 -- Cancel_Task_Entry_Call (U);
6054 -- _Disp_Asynchronous_Select
6055 -- (<object>, S, P'Address, D, B);
6056 -- Bnn := Communication_Bloc (D);
6058 -- Param1 := P.Param1;
6060 -- ParamN := P.ParamN;
6065 -- <abortable-statements>
6067 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6070 -- when Abort_Signal => Abort_Undefer;
6074 -- <triggering-statements>
6079 -- <dispatching-call>;
6080 -- <triggering-statements>
6085 -- The job is to convert this to the asynchronous form
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
6096 -- For a description of the use of P and the assignments after the call,
6097 -- see Expand_N_Entry_Call_Statement.
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);
6106 Abort_Block_Ent : Entity_Id;
6107 Abortable_Block : Node_Id;
6109 Blk_Ent : Entity_Id;
6110 Blk_Typ : Entity_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;
6119 Dblock_Ent : Entity_Id;
6124 Enqueue_Call : Node_Id;
6127 Handler_Stmt : Node_Id;
6129 Lim_Typ_Stmts : List_Id;
6135 ProtE_Stmts : List_Id;
6136 ProtP_Stmts : List_Id;
6139 TaskE_Stmts : List_Id;
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
6150 Process_Statements_For_Controlled_Objects (Trig);
6151 Process_Statements_For_Controlled_Objects (Abrt);
6153 Blk_Ent := Make_Temporary (Loc, 'A');
6154 Ecall := Triggering_Statement (Trig);
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.
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)
6170 -- This is either a dispatching call or a delay statement used as a
6171 -- trigger which was expanded into a procedure call.
6173 if Nkind (Ecall) = N_Procedure_Call_Statement then
6174 if Ada_Version >= Ada_2005
6176 (No (Original_Node (Ecall))
6177 or else not Nkind_In (Original_Node (Ecall),
6178 N_Delay_Relative_Statement,
6179 N_Delay_Until_Statement))
6181 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
6186 -- Call status flag processing, generate:
6187 -- B : Boolean := False;
6189 B := Build_B (Loc, Decls);
6191 -- Communication block processing, generate:
6192 -- Bnn : Communication_Block;
6194 Bnn := Make_Temporary (Loc, 'B');
6196 Make_Object_Declaration (Loc,
6197 Defining_Identifier => Bnn,
6198 Object_Definition =>
6199 New_Reference_To (RTE (RE_Communication_Block), Loc)));
6201 -- Call kind processing, generate:
6202 -- C : Ada.Tags.Prim_Op_Kind;
6204 C := Build_C (Loc, Decls);
6206 -- Tagged kind processing, generate:
6207 -- K : Ada.Tags.Tagged_Kind :=
6208 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6210 -- Dummy communication block, generate:
6211 -- D : Dummy_Communication_Block;
6214 Make_Object_Declaration (Loc,
6215 Defining_Identifier =>
6216 Make_Defining_Identifier (Loc, Name_uD),
6217 Object_Definition =>
6219 RTE (RE_Dummy_Communication_Block), Loc)));
6221 K := Build_K (Loc, Decls, Obj);
6223 -- Parameter block processing
6225 Blk_Typ := Build_Parameter_Block
6226 (Loc, Actuals, Formals, Decls);
6227 P := Parameter_Block_Pack
6228 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6230 -- Dispatch table slot processing, generate:
6233 S := Build_S (Loc, Decls);
6235 -- Additional status flag processing, generate:
6238 T := Make_Temporary (Loc, 'T');
6240 Make_Object_Declaration (Loc,
6241 Defining_Identifier => T,
6242 Object_Definition =>
6243 New_Reference_To (Standard_Boolean, Loc)));
6245 ------------------------------
6246 -- Protected entry handling --
6247 ------------------------------
6250 -- Param1 := P.Param1;
6252 -- ParamN := P.ParamN;
6254 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6257 -- Bnn := Communication_Block (D);
6259 Prepend_To (Cleanup_Stmts,
6260 Make_Assignment_Statement (Loc,
6262 New_Reference_To (Bnn, Loc),
6264 Make_Unchecked_Type_Conversion (Loc,
6266 New_Reference_To (RTE (RE_Communication_Block), Loc),
6267 Expression => Make_Identifier (Loc, Name_uD))));
6270 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6272 Prepend_To (Cleanup_Stmts,
6273 Make_Procedure_Call_Statement (Loc,
6276 Find_Prim_Op (Etype (Etype (Obj)),
6277 Name_uDisp_Asynchronous_Select),
6279 Parameter_Associations =>
6281 New_Copy_Tree (Obj), -- <object>
6282 New_Reference_To (S, Loc), -- S
6283 Make_Attribute_Reference (Loc, -- P'Address
6285 New_Reference_To (P, Loc),
6288 Make_Identifier (Loc, Name_uD), -- D
6289 New_Reference_To (B, Loc)))); -- B
6292 -- if Enqueued (Bnn) then
6293 -- <abortable-statements>
6296 Append_To (Cleanup_Stmts,
6297 Make_If_Statement (Loc,
6299 Make_Function_Call (Loc,
6301 New_Reference_To (RTE (RE_Enqueued), Loc),
6302 Parameter_Associations =>
6304 New_Reference_To (Bnn, Loc))),
6307 New_Copy_List_Tree (Astats)));
6309 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6310 -- will then generate a _clean for the communication block Bnn.
6314 -- procedure _clean is
6316 -- if Enqueued (Bnn) then
6317 -- Cancel_Protected_Entry_Call (Bnn);
6326 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6328 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6330 -- Wrap the cleanup block in an exception handling block
6336 -- when Abort_Signal => Abort_Undefer;
6339 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6342 Make_Implicit_Label_Declaration (Loc,
6343 Defining_Identifier =>
6347 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6350 -- if not Cancelled (Bnn) then
6351 -- <triggering-statements>
6354 Append_To (ProtE_Stmts,
6355 Make_If_Statement (Loc,
6359 Make_Function_Call (Loc,
6361 New_Reference_To (RTE (RE_Cancelled), Loc),
6362 Parameter_Associations =>
6364 New_Reference_To (Bnn, Loc)))),
6367 New_Copy_List_Tree (Tstats)));
6369 -------------------------
6370 -- Task entry handling --
6371 -------------------------
6374 -- Param1 := P.Param1;
6376 -- ParamN := P.ParamN;
6378 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6381 -- Bnn := Communication_Block (D);
6383 Append_To (TaskE_Stmts,
6384 Make_Assignment_Statement (Loc,
6386 New_Reference_To (Bnn, Loc),
6388 Make_Unchecked_Type_Conversion (Loc,
6390 New_Reference_To (RTE (RE_Communication_Block), Loc),
6391 Expression => Make_Identifier (Loc, Name_uD))));
6394 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6396 Prepend_To (TaskE_Stmts,
6397 Make_Procedure_Call_Statement (Loc,
6400 Find_Prim_Op (Etype (Etype (Obj)),
6401 Name_uDisp_Asynchronous_Select),
6403 Parameter_Associations =>
6405 New_Copy_Tree (Obj), -- <object>
6406 New_Reference_To (S, Loc), -- S
6407 Make_Attribute_Reference (Loc, -- P'Address
6409 New_Reference_To (P, Loc),
6412 Make_Identifier (Loc, Name_uD), -- D
6413 New_Reference_To (B, Loc)))); -- B
6418 Prepend_To (TaskE_Stmts,
6419 Make_Procedure_Call_Statement (Loc,
6421 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6422 Parameter_Associations =>
6427 -- <abortable-statements>
6429 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6431 Prepend_To (Cleanup_Stmts,
6432 Make_Procedure_Call_Statement (Loc,
6434 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6435 Parameter_Associations =>
6438 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6439 -- will generate a _clean for the additional status flag.
6443 -- procedure _clean is
6445 -- Cancel_Task_Entry_Call (U);
6453 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6455 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6457 -- Wrap the cleanup block in an exception handling block
6463 -- when Abort_Signal => Abort_Undefer;
6466 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6468 Append_To (TaskE_Stmts,
6469 Make_Implicit_Label_Declaration (Loc,
6470 Defining_Identifier => Abort_Block_Ent));
6472 Append_To (TaskE_Stmts,
6474 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6478 -- <triggering-statements>
6481 Append_To (TaskE_Stmts,
6482 Make_If_Statement (Loc,
6486 New_Reference_To (T, Loc)),
6489 New_Copy_List_Tree (Tstats)));
6491 ----------------------------------
6492 -- Protected procedure handling --
6493 ----------------------------------
6496 -- <dispatching-call>;
6497 -- <triggering-statements>
6499 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6500 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6503 -- S := Ada.Tags.Get_Offset_Index
6504 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6507 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6510 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6512 Append_To (Conc_Typ_Stmts,
6513 Make_Procedure_Call_Statement (Loc,
6516 Find_Prim_Op (Etype (Etype (Obj)),
6517 Name_uDisp_Get_Prim_Op_Kind),
6519 Parameter_Associations =>
6521 New_Copy_Tree (Obj),
6522 New_Reference_To (S, Loc),
6523 New_Reference_To (C, Loc))));
6526 -- if C = POK_Procedure_Entry then
6528 -- elsif C = POK_Task_Entry then
6534 Append_To (Conc_Typ_Stmts,
6535 Make_If_Statement (Loc,
6539 New_Reference_To (C, Loc),
6541 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6548 Make_Elsif_Part (Loc,
6552 New_Reference_To (C, Loc),
6554 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6563 -- <dispatching-call>;
6564 -- <triggering-statements>
6566 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6567 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6570 -- if K = Ada.Tags.TK_Limited_Tagged then
6577 Make_If_Statement (Loc,
6581 New_Reference_To (K, Loc),
6583 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6592 Make_Block_Statement (Loc,
6595 Handled_Statement_Sequence =>
6596 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6601 -- Delay triggering statement processing
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.
6607 Dblock_Ent := Make_Temporary (Loc, 'D');
6609 Pdef := Entity (Name (Ecall));
6611 if Is_RTE (Pdef, RO_CA_Delay_For) then
6613 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6615 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6617 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6619 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6620 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
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));
6628 -- Create the inner block to protect the abortable part
6630 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6633 Make_Procedure_Call_Statement (Loc,
6634 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
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);
6645 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6648 Make_Implicit_If_Statement (N,
6649 Condition => Make_Function_Call (Loc,
6650 Name => Enqueue_Call,
6651 Parameter_Associations => Parameter_Associations (Ecall)),
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),
6661 Exception_Handlers => Hdle)))));
6663 Stmts := New_List (Ecall);
6665 -- Construct statement sequence for new block
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));
6678 -- The result is the new block
6680 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
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))),
6691 Handled_Statement_Sequence =>
6692 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6702 Extract_Entry (Ecall, Concval, Ename, Index);
6703 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6705 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6706 Decls := Declarations (Ecall);
6708 if Is_Protected_Type (Etype (Concval)) then
6710 -- Get the declarations of the block expanded from the entry call
6712 Decl := First (Decls);
6713 while Present (Decl)
6715 (Nkind (Decl) /= N_Object_Declaration
6716 or else not Is_RTE (Etype (Object_Definition (Decl)),
6717 RE_Communication_Block))
6722 pragma Assert (Present (Decl));
6723 Cancel_Param := Defining_Identifier (Decl);
6725 -- Change the mode of the Protected_Entry_Call call
6727 -- Protected_Entry_Call (
6728 -- Object => po._object'Access,
6729 -- E => <entry index>;
6730 -- Uninterpreted_Data => P'Address;
6731 -- Mode => Asynchronous_Call;
6734 Stmt := First (Stmts);
6736 -- Skip assignments to temporaries created for in-out parameters
6738 -- This makes unwarranted assumptions about the shape of the expanded
6739 -- tree for the call, and should be cleaned up ???
6741 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6747 Param := First (Parameter_Associations (Call));
6748 while Present (Param)
6749 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6754 pragma Assert (Present (Param));
6755 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6758 -- Append an if statement to execute the abortable part
6761 -- if Enqueued (Bnn) then
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));
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);
6780 -- For the VM call Update_Exception instead of Abort_Undefer.
6781 -- See 4jexcept.ads for an explanation.
6783 if VM_Target = No_VM then
6784 if Exception_Mechanism = Back_End_Exceptions then
6786 -- Aborts are not deferred at beginning of exception handlers
6789 Handler_Stmt := Make_Null_Statement (Loc);
6792 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6793 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6794 Parameter_Associations => No_List);
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))));
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),
6817 Exception_Handlers => New_List (
6818 Make_Implicit_Exception_Handler (Loc,
6820 -- when Abort_Signal =>
6821 -- Abort_Undefer.all;
6823 Exception_Choices =>
6824 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6825 Statements => New_List (Handler_Stmt))))),
6827 -- if not Cancelled (Bnn) then
6828 -- triggered statements
6831 Make_Implicit_If_Statement (N,
6832 Condition => Make_Op_Not (Loc,
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));
6840 -- Asynchronous task entry call
6847 B := Make_Defining_Identifier (Loc, Name_uB);
6849 -- Insert declaration of B in declarations of existing block
6852 Make_Object_Declaration (Loc,
6853 Defining_Identifier => B,
6854 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6856 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6858 -- Insert declaration of C in declarations of existing block
6861 Make_Object_Declaration (Loc,
6862 Defining_Identifier => Cancel_Param,
6863 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6865 -- Remove and save the call to Call_Simple
6867 Stmt := First (Stmts);
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 ???
6873 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6879 -- Create the inner block to protect the abortable part
6881 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6884 Make_Procedure_Call_Statement (Loc,
6885 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
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);
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 =>
6907 Exception_Handlers => Hdle)));
6909 -- Create new call statement
6911 Params := Parameter_Associations (Call);
6914 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6916 New_Reference_To (B, Loc));
6919 Make_Procedure_Call_Statement (Loc,
6921 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6922 Parameter_Associations => Params));
6924 -- Construct statement sequence for new block
6927 Make_Implicit_If_Statement (N,
6930 New_Reference_To (Cancel_Param, Loc)),
6931 Then_Statements => Tstats));
6933 -- Protected the call against abort
6936 Make_Procedure_Call_Statement (Loc,
6937 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6938 Parameter_Associations => Empty_List));
6941 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6943 -- The result is the new block
6946 Make_Block_Statement (Loc,
6947 Declarations => Decls,
6948 Handled_Statement_Sequence =>
6949 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6952 end Expand_N_Asynchronous_Select;
6954 -------------------------------------
6955 -- Expand_N_Conditional_Entry_Call --
6956 -------------------------------------
6958 -- The conditional task entry call is converted to a call to
6963 -- P : parms := (parm, parm, parm);
6967 -- (<acceptor-task>, -- Acceptor
6968 -- <entry-index>, -- E
6969 -- P'Address, -- Uninterpreted_Data
6970 -- Conditional_Call, -- Mode
6971 -- B); -- Rendezvous_Successful
6976 -- normal-statements
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:
6988 -- P : parms := (parm, parm, parm);
6990 -- ... info for in-out parameters
6991 -- Call_Simple (acceptor-task, entry-index, P'Address);
6997 -- so the task at hand is to convert the latter expansion into the former
6999 -- The conditional protected entry call is converted to a call to
7000 -- Protected_Entry_Call:
7003 -- P : parms := (parm, parm, parm);
7004 -- Bnn : Communications_Block;
7007 -- Protected_Entry_Call
7008 -- (po._object'Access, -- Object
7009 -- <entry index>, -- E
7010 -- P'Address, -- Uninterpreted_Data
7011 -- Conditional_Call, -- Mode
7016 -- if Cancelled (Bnn) then
7019 -- normal-statements
7023 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
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);
7035 -- if K = Ada.Tags.TK_Limited_Tagged then
7036 -- <dispatching-call>;
7037 -- <triggering-statements>
7041 -- Ada.Tags.Get_Offset_Index
7042 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7044 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7046 -- if C = POK_Protected_Entry
7047 -- or else C = POK_Task_Entry
7049 -- Param1 := P.Param1;
7051 -- ParamN := P.ParamN;
7055 -- if C = POK_Procedure
7056 -- or else C = POK_Protected_Procedure
7057 -- or else C = POK_Task_Procedure
7059 -- <dispatching-call>;
7062 -- <triggering-statements>
7064 -- <else-statements>
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);
7075 Blk_Typ : Entity_Id;
7077 Call_Ent : Entity_Id;
7078 Conc_Typ_Stmts : List_Id;
7082 Lim_Typ_Stmts : List_Id;
7089 Transient_Blk : Node_Id;
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
7099 Process_Statements_For_Controlled_Objects (N);
7101 if Ada_Version >= Ada_2005
7102 and then Nkind (Blk) = N_Procedure_Call_Statement
7104 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7109 -- Call status flag processing, generate:
7110 -- B : Boolean := False;
7112 B := Build_B (Loc, Decls);
7114 -- Call kind processing, generate:
7115 -- C : Ada.Tags.Prim_Op_Kind;
7117 C := Build_C (Loc, Decls);
7119 -- Tagged kind processing, generate:
7120 -- K : Ada.Tags.Tagged_Kind :=
7121 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7123 K := Build_K (Loc, Decls, Obj);
7125 -- Parameter block processing
7127 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7128 P := Parameter_Block_Pack
7129 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7131 -- Dispatch table slot processing, generate:
7134 S := Build_S (Loc, Decls);
7137 -- S := Ada.Tags.Get_Offset_Index
7138 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7141 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7144 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7146 Append_To (Conc_Typ_Stmts,
7147 Make_Procedure_Call_Statement (Loc,
7150 Find_Prim_Op (Etype (Etype (Obj)),
7151 Name_uDisp_Conditional_Select),
7153 Parameter_Associations =>
7155 New_Copy_Tree (Obj), -- <object>
7156 New_Reference_To (S, Loc), -- S
7157 Make_Attribute_Reference (Loc, -- P'Address
7159 New_Reference_To (P, Loc),
7162 New_Reference_To (C, Loc), -- C
7163 New_Reference_To (B, Loc)))); -- B
7166 -- if C = POK_Protected_Entry
7167 -- or else C = POK_Task_Entry
7169 -- Param1 := P.Param1;
7171 -- ParamN := P.ParamN;
7174 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7176 -- Generate the if statement only when the packed parameters need
7177 -- explicit assignments to their corresponding actuals.
7179 if Present (Unpack) then
7180 Append_To (Conc_Typ_Stmts,
7181 Make_If_Statement (Loc,
7188 New_Reference_To (C, Loc),
7190 New_Reference_To (RTE (
7191 RE_POK_Protected_Entry), Loc)),
7195 New_Reference_To (C, Loc),
7197 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
7205 -- if C = POK_Procedure
7206 -- or else C = POK_Protected_Procedure
7207 -- or else C = POK_Task_Procedure
7209 -- <dispatching-call>
7211 -- <normal-statements>
7213 -- <else-statements>
7216 N_Stats := New_Copy_List_Tree (Statements (Alt));
7218 Prepend_To (N_Stats,
7219 Make_If_Statement (Loc,
7225 New_Reference_To (C, Loc),
7227 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
7234 New_Reference_To (C, Loc),
7236 New_Reference_To (RTE (
7237 RE_POK_Protected_Procedure), Loc)),
7242 New_Reference_To (C, Loc),
7244 New_Reference_To (RTE (
7245 RE_POK_Task_Procedure), Loc)))),
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)));
7257 -- <dispatching-call>;
7258 -- <triggering-statements>
7260 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
7261 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
7264 -- if K = Ada.Tags.TK_Limited_Tagged then
7271 Make_If_Statement (Loc,
7275 New_Reference_To (K, Loc),
7277 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
7286 Make_Block_Statement (Loc,
7289 Handled_Statement_Sequence =>
7290 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
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
7301 First_Real_Statement (Handled_Statement_Sequence (Blk));
7303 if Present (Transient_Blk)
7304 and then Nkind (Transient_Blk) = N_Block_Statement
7306 Blk := Transient_Blk;
7309 Stmts := Statements (Handled_Statement_Sequence (Blk));
7310 Stmt := First (Stmts);
7311 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7316 Params := Parameter_Associations (Call);
7318 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7320 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7322 Param := First (Params);
7323 while Present (Param)
7324 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7329 pragma Assert (Present (Param));
7330 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
7334 -- Find the Communication_Block parameter for the call to the
7335 -- Cancelled function.
7337 Decl := First (Declarations (Blk));
7338 while Present (Decl)
7339 and then not Is_RTE (Etype (Object_Definition (Decl)),
7340 RE_Communication_Block)
7345 -- Add an if statement to execute the else part if the call
7346 -- does not succeed (as indicated by the Cancelled predicate).
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)));
7358 B := Make_Defining_Identifier (Loc, Name_uB);
7360 -- Insert declaration of B in declarations of existing block
7362 if No (Declarations (Blk)) then
7363 Set_Declarations (Blk, New_List);
7366 Prepend_To (Declarations (Blk),
7367 Make_Object_Declaration (Loc,
7368 Defining_Identifier => B,
7369 Object_Definition =>
7370 New_Reference_To (Standard_Boolean, Loc)));
7372 -- Create new call statement
7375 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7376 Append_To (Params, New_Reference_To (B, Loc));
7379 Make_Procedure_Call_Statement (Loc,
7380 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7381 Parameter_Associations => Params));
7383 -- Construct statement sequence for new block
7386 Make_Implicit_If_Statement (N,
7387 Condition => New_Reference_To (B, Loc),
7388 Then_Statements => Statements (Alt),
7389 Else_Statements => Else_Statements (N)));
7392 -- The result is the new block
7395 Make_Block_Statement (Loc,
7396 Declarations => Declarations (Blk),
7397 Handled_Statement_Sequence =>
7398 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7402 end Expand_N_Conditional_Entry_Call;
7404 ---------------------------------------
7405 -- Expand_N_Delay_Relative_Statement --
7406 ---------------------------------------
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.
7412 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7413 Loc : constant Source_Ptr := Sloc (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))));
7420 end Expand_N_Delay_Relative_Statement;
7422 ------------------------------------
7423 -- Expand_N_Delay_Until_Statement --
7424 ------------------------------------
7426 -- Delay Until statement is implemented as a procedure call to
7427 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7429 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7430 Loc : constant Source_Ptr := Sloc (N);
7434 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7435 Typ := RTE (RO_CA_Delay_Until);
7437 Typ := RTE (RO_RT_Delay_Until);
7441 Make_Procedure_Call_Statement (Loc,
7442 Name => New_Reference_To (Typ, Loc),
7443 Parameter_Associations => New_List (Expression (N))));
7446 end Expand_N_Delay_Until_Statement;
7448 -------------------------
7449 -- Expand_N_Entry_Body --
7450 -------------------------
7452 procedure Expand_N_Entry_Body (N : Node_Id) is
7454 -- Associate discriminals with the next protected operation body to be
7457 if Present (Next_Protected_Operation (N)) then
7458 Set_Discriminals (Parent (Current_Scope));
7460 end Expand_N_Entry_Body;
7462 -----------------------------------
7463 -- Expand_N_Entry_Call_Statement --
7464 -----------------------------------
7466 -- An entry call is expanded into GNARLI calls to implement a simple entry
7467 -- call (see Build_Simple_Entry_Call).
7469 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7475 if No_Run_Time_Mode then
7476 Error_Msg_CRT ("entry call", N);
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
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.
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)
7496 Extract_Entry (N, Concval, Ename, Index);
7497 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7499 end Expand_N_Entry_Call_Statement;
7501 --------------------------------
7502 -- Expand_N_Entry_Declaration --
7503 --------------------------------
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.
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;
7523 Last_Decl : Node_Id;
7524 Component : Entity_Id;
7527 Rec_Ent : Entity_Id;
7528 Acc_Ent : Entity_Id;
7531 Formal := First_Formal (Entry_Ent);
7534 -- Most processing is done only if parameters are present
7536 if Present (Formal) then
7537 Components := New_List;
7539 -- Loop through formals
7541 while Present (Formal) loop
7542 Set_Is_Entry_Formal (Formal);
7544 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7545 Set_Entry_Component (Formal, Component);
7546 Set_Entry_Formal (Component, Formal);
7547 Ftype := Etype (Formal);
7549 -- Declare new access type and then append
7551 Ctype := Make_Temporary (Loc, 'A');
7554 Make_Full_Type_Declaration (Loc,
7555 Defining_Identifier => Ctype,
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)));
7562 Insert_After (Last_Decl, Decl);
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))));
7573 Next_Formal_With_Extras (Formal);
7576 -- Create the Entry_Parameter_Record declaration
7578 Rec_Ent := Make_Temporary (Loc, 'P');
7581 Make_Full_Type_Declaration (Loc,
7582 Defining_Identifier => Rec_Ent,
7584 Make_Record_Definition (Loc,
7586 Make_Component_List (Loc,
7587 Component_Items => Components)));
7589 Insert_After (Last_Decl, Decl);
7592 -- Construct and link in the corresponding access type
7594 Acc_Ent := Make_Temporary (Loc, 'A');
7596 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7599 Make_Full_Type_Declaration (Loc,
7600 Defining_Identifier => Acc_Ent,
7602 Make_Access_To_Object_Definition (Loc,
7603 All_Present => True,
7604 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7606 Insert_After (Last_Decl, Decl);
7608 end Expand_N_Entry_Declaration;
7610 -----------------------------
7611 -- Expand_N_Protected_Body --
7612 -----------------------------
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:
7622 -- (O : System.Address;
7623 -- E : Protected_Entry_Index)
7626 -- <discriminant renamings>
7627 -- <private object renamings>
7629 -- return <barrier expression>;
7632 -- procedure pprocN (_object : in out poV;...) is
7633 -- <discriminant renamings>
7634 -- <private object renamings>
7636 -- <sequence of statements>
7639 -- procedure pprocP (_object : in out poV;...) is
7640 -- procedure _clean is
7643 -- ptypeS (_object, Pn);
7644 -- Unlock (_object._object'Access);
7645 -- Abort_Undefer.all;
7650 -- Lock (_object._object'Access);
7651 -- pprocN (_object;...);
7656 -- function pfuncN (_object : poV;...) return Return_Type is
7657 -- <discriminant renamings>
7658 -- <private object renamings>
7660 -- <sequence of statements>
7663 -- function pfuncP (_object : poV) return Return_Type is
7664 -- procedure _clean is
7666 -- Unlock (_object._object'Access);
7667 -- Abort_Undefer.all;
7672 -- Lock (_object._object'Access);
7673 -- return pfuncN (_object);
7680 -- (O : System.Address;
7681 -- P : System.Address;
7682 -- E : Protected_Entry_Index)
7684 -- <discriminant renamings>
7685 -- <private object renamings>
7686 -- type poVP is access poV;
7687 -- _Object : ptVP := ptVP!(O);
7691 -- <statement sequence>
7692 -- Complete_Entry_Body (_Object._Object);
7694 -- when all others =>
7695 -- Exceptional_Complete_Entry_Body (
7696 -- _Object._Object, Get_GNAT_Exception);
7700 -- The type poV is the record created for the protected type to hold
7701 -- the state of the protected object.
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);
7707 Current_Node : Node_Id;
7708 Disp_Op_Body : Node_Id;
7709 New_Op_Body : Node_Id;
7710 Num_Entries : Natural := 0;
7714 function Build_Dispatching_Subprogram_Body
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:
7722 -- function <protected-function-name> (Param1 .. ParamN) return
7725 -- return <protected-function-name>P (Param1 .. ParamN);
7726 -- end <protected-function-name>;
7730 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7732 -- <protected-procedure-name>P (Param1 .. ParamN);
7733 -- end <protected-procedure-name>
7735 ---------------------------------------
7736 -- Build_Dispatching_Subprogram_Body --
7737 ---------------------------------------
7739 function Build_Dispatching_Subprogram_Body
7742 Prot_Bod : Node_Id) return Node_Id
7744 Loc : constant Source_Ptr := Sloc (N);
7751 -- Generate a specification without a letter suffix in order to
7752 -- override an interface function or procedure.
7754 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7756 -- The formal parameters become the actuals of the protected function
7757 -- or procedure call.
7759 Actuals := New_List;
7760 Formal := First (Parameter_Specifications (Spec));
7761 while Present (Formal) loop
7763 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7768 if Nkind (Spec) = N_Procedure_Specification then
7771 Make_Procedure_Call_Statement (Loc,
7773 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7774 Parameter_Associations => Actuals));
7776 pragma Assert (Nkind (Spec) = N_Function_Specification);
7780 Make_Simple_Return_Statement (Loc,
7782 Make_Function_Call (Loc,
7784 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7785 Parameter_Associations => Actuals)));
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;
7796 -- Start of processing for Expand_N_Protected_Body
7799 if No_Run_Time_Mode then
7800 Error_Msg_CRT ("protected body", N);
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.
7808 if Nkind (Parent (N)) = N_Subunit then
7809 Current_Node := Corresponding_Stub (Parent (N));
7814 Op_Body := First (Declarations (N));
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.
7820 Rewrite (N, Make_Null_Statement (Sloc (N)));
7823 while Present (Op_Body) loop
7824 case Nkind (Op_Body) is
7825 when N_Subprogram_Declaration =>
7828 when N_Subprogram_Body =>
7830 -- Do not create bodies for eliminated operations
7832 if not Is_Eliminated (Defining_Entity (Op_Body))
7833 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7836 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7838 Insert_After (Current_Node, New_Op_Body);
7839 Current_Node := New_Op_Body;
7840 Analyze (New_Op_Body);
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.
7854 if Present (Corresponding_Spec (Op_Body)) then
7856 Build_Protected_Subprogram_Body (
7857 Op_Body, Pid, Specification (New_Op_Body));
7859 Insert_After (Current_Node, New_Op_Body);
7860 Analyze (New_Op_Body);
7862 Current_Node := New_Op_Body;
7864 -- Generate an overriding primitive operation body for
7865 -- this subprogram if the protected type implements an
7868 if Ada_Version >= Ada_2005
7870 Present (Interfaces (Corresponding_Record_Type (Pid)))
7873 Build_Dispatching_Subprogram_Body
7874 (Op_Body, Pid, New_Op_Body);
7876 Insert_After (Current_Node, Disp_Op_Body);
7877 Analyze (Disp_Op_Body);
7879 Current_Node := Disp_Op_Body;
7884 when N_Entry_Body =>
7885 Op_Id := Defining_Identifier (Op_Body);
7886 Num_Entries := Num_Entries + 1;
7888 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7890 Insert_After (Current_Node, New_Op_Body);
7891 Current_Node := New_Op_Body;
7892 Analyze (New_Op_Body);
7894 when N_Implicit_Label_Declaration =>
7897 when N_Itype_Reference =>
7898 Insert_After (Current_Node, New_Copy (Op_Body));
7900 when N_Freeze_Entity =>
7901 New_Op_Body := New_Copy (Op_Body);
7903 if Present (Entity (Op_Body))
7904 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7906 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7909 Insert_After (Current_Node, New_Op_Body);
7910 Current_Node := New_Op_Body;
7911 Analyze (New_Op_Body);
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);
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);
7927 raise Program_Error;
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.
7938 if Corresponding_Runtime_Package (Pid) =
7939 System_Tasking_Protected_Objects_Entries
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);
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.
7951 if Ada_Version >= Ada_2005 then
7952 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7954 end Expand_N_Protected_Body;
7956 -----------------------------------------
7957 -- Expand_N_Protected_Type_Declaration --
7958 -----------------------------------------
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
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>
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.
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.
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.
7986 -- One entry_family component is present for each entry family in the
7987 -- task definition (see Expand_N_Task_Type_Declaration).
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.
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.
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.
8008 -- We also build the call to register the procedure if a pragma
8009 -- Interrupt_Handler applies.
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.
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);
8029 -- Note that this must come after the record type declaration, since
8030 -- the specs refer to this type.
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);
8036 Pdef : constant Node_Id := Protected_Definition (N);
8037 -- This contains two lists; one for visible and one for private decls
8041 Discr_Map : constant Elist_Id := New_Elmt_List;
8045 Comp_Id : Entity_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;
8054 Object_Comp : Node_Id;
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.
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.
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.
8072 --------------------
8073 -- Check_Inlining --
8074 --------------------
8076 procedure Check_Inlining (Subp : Entity_Id) is
8078 if Is_Inlined (Subp) then
8079 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8080 Set_Is_Inlined (Subp, False);
8084 ---------------------------------
8085 -- Check_Static_Component_Size --
8086 ---------------------------------
8088 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8089 Typ : constant Entity_Id := Etype (Comp);
8093 if Is_Scalar_Type (Typ) then
8096 elsif Is_Array_Type (Typ) then
8097 return Compile_Time_Known_Bounds (Typ);
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
8111 -- Any other types will be checked by the back-end
8116 end Static_Component_Size;
8118 ----------------------
8119 -- Register_Handler --
8120 ----------------------
8122 procedure Register_Handler is
8124 -- All semantic checks already done in Sem_Prag
8126 Prot_Proc : constant Entity_Id :=
8128 (Specification (Current_Node));
8130 Proc_Address : constant Node_Id :=
8131 Make_Attribute_Reference (Loc,
8132 Prefix => New_Reference_To (Prot_Proc, Loc),
8133 Attribute_Name => Name_Address);
8135 RTS_Call : constant Entity_Id :=
8136 Make_Procedure_Call_Statement (Loc,
8139 RTE (RE_Register_Interrupt_Handler), Loc),
8140 Parameter_Associations =>
8141 New_List (Proc_Address));
8143 Append_Freeze_Action (Prot_Proc, RTS_Call);
8144 end Register_Handler;
8146 -- Start of processing for Expand_N_Protected_Type_Declaration
8149 if Present (Corresponding_Record_Type (Prot_Typ)) then
8152 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
8155 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
8157 Qualify_Entity_Names (N);
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:
8165 -- protected discriminant => discriminal => record discriminant
8167 -- This replacement is not applied to default expressions, for which
8168 -- the discriminal is correct.
8170 if Has_Discriminants (Prot_Typ) then
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);
8187 -- Fill in the component declarations
8189 -- Add components for entry families. For each entry family, create an
8190 -- anonymous type declaration with the same size, and analyze the type.
8192 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
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.
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);
8207 -- Could this be simplified using Corresponding_Runtime_Package???
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
8215 Num_Attach_Handler := Num_Attach_Handler + 1;
8218 Next_Rep_Item (Ritem);
8221 if Restricted_Profile then
8222 if Has_Entries (Prot_Typ) then
8223 Protection_Subtype :=
8224 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8226 Protection_Subtype :=
8227 New_Reference_To (RTE (RE_Protection), Loc);
8230 Protection_Subtype :=
8231 Make_Subtype_Indication
8235 (RTE (RE_Static_Interrupt_Protection), Loc),
8237 Make_Index_Or_Discriminant_Constraint (
8239 Constraints => New_List (
8241 Make_Integer_Literal (Loc, Num_Attach_Handler))));
8244 elsif Has_Interrupt_Handler (Prot_Typ)
8245 and then not Restriction_Active (No_Dynamic_Attachment)
8247 Protection_Subtype :=
8248 Make_Subtype_Indication (
8250 Subtype_Mark => New_Reference_To
8251 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
8253 Make_Index_Or_Discriminant_Constraint (
8255 Constraints => New_List (Entry_Count_Expr)));
8257 -- Type has explicit entries or generated primitive entry wrappers
8259 elsif Has_Entries (Prot_Typ)
8260 or else (Ada_Version >= Ada_2005
8261 and then Present (Interface_List (N)))
8263 case Corresponding_Runtime_Package (Prot_Typ) is
8264 when System_Tasking_Protected_Objects_Entries =>
8265 Protection_Subtype :=
8266 Make_Subtype_Indication (Loc,
8268 New_Reference_To (RTE (RE_Protection_Entries), Loc),
8270 Make_Index_Or_Discriminant_Constraint (
8272 Constraints => New_List (Entry_Count_Expr)));
8274 when System_Tasking_Protected_Objects_Single_Entry =>
8275 Protection_Subtype :=
8276 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8279 raise Program_Error;
8283 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
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));
8296 pragma Assert (Present (Pdef));
8298 -- Add private field components
8300 if Present (Private_Declarations (Pdef)) then
8301 Priv := First (Private_Declarations (Pdef));
8303 while Present (Priv) loop
8305 if Nkind (Priv) = N_Component_Declaration then
8306 if not Static_Component_Size (Defining_Identifier (Priv)) then
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.
8313 if not Comes_From_Source (Prot_Typ) then
8314 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8316 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8317 Error_Msg_N ("component has non-static size?", Priv);
8319 ("\creation of protected object of type& will violate"
8320 & " restriction No_Implicit_Heap_Allocations?",
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.
8330 Old_Comp : constant Node_Id := Component_Definition (Priv);
8331 Oent : constant Entity_Id := Defining_Identifier (Priv);
8333 Nent : constant Entity_Id :=
8334 Make_Defining_Identifier (Sloc (Oent),
8335 Chars => Chars (Oent));
8338 if Present (Subtype_Indication (Old_Comp)) then
8340 Make_Component_Definition (Sloc (Oent),
8341 Aliased_Present => False,
8342 Subtype_Indication =>
8343 New_Copy_Tree (Subtype_Indication (Old_Comp),
8347 Make_Component_Definition (Sloc (Oent),
8348 Aliased_Present => False,
8349 Access_Definition =>
8350 New_Copy_Tree (Access_Definition (Old_Comp),
8355 Make_Component_Declaration (Loc,
8356 Defining_Identifier => Nent,
8357 Component_Definition => New_Comp,
8358 Expression => Expression (Priv));
8360 Set_Has_Per_Object_Constraint (Nent,
8361 Has_Per_Object_Constraint (Oent));
8363 Append_To (Cdecls, New_Priv);
8366 elsif Nkind (Priv) = N_Subprogram_Declaration then
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
8375 Make_Subprogram_Declaration (Loc,
8377 Build_Protected_Sub_Specification
8378 (Priv, Prot_Typ, Unprotected_Mode));
8380 Insert_After (Current_Node, Sub);
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;
8390 Make_Subprogram_Declaration (Loc,
8392 Build_Protected_Sub_Specification
8393 (Priv, Prot_Typ, Protected_Mode));
8395 Insert_After (Current_Node, Sub);
8397 Current_Node := Sub;
8399 if Is_Interrupt_Handler
8400 (Defining_Unit_Name (Specification (Priv)))
8402 if not Restricted_Profile then
8412 -- Put the _Object component after the private component so that it
8413 -- be finalized early as required by 9.4 (20)
8415 Append_To (Cdecls, Object_Comp);
8417 Insert_After (Current_Node, Rec_Decl);
8418 Current_Node := Rec_Decl;
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).
8425 Analyze (Rec_Decl, Suppress => All_Checks);
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.
8431 if Ada_Version >= Ada_2005 then
8432 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
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.
8440 if Has_Entries (Prot_Typ) then
8441 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8443 Entries_Aggr := Empty;
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.
8455 Comp := First (Visible_Declarations (Pdef));
8457 while Present (Comp) loop
8458 if Nkind (Comp) = N_Subprogram_Declaration then
8460 Make_Subprogram_Declaration (Loc,
8462 Build_Protected_Sub_Specification
8463 (Comp, Prot_Typ, Unprotected_Mode));
8465 Insert_After (Current_Node, Sub);
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)));
8473 -- Make the protected version of the subprogram available for
8474 -- expansion of external calls.
8476 Current_Node := Sub;
8479 Make_Subprogram_Declaration (Loc,
8481 Build_Protected_Sub_Specification
8482 (Comp, Prot_Typ, Protected_Mode));
8484 Insert_After (Current_Node, Sub);
8487 Current_Node := Sub;
8489 -- Generate an overriding primitive operation specification for
8490 -- this subprogram if the protected type implements an interface.
8492 if Ada_Version >= Ada_2005
8494 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8497 Make_Subprogram_Declaration (Loc,
8499 Build_Protected_Sub_Specification
8500 (Comp, Prot_Typ, Dispatching_Mode));
8502 Insert_After (Current_Node, Sub);
8505 Current_Node := Sub;
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:
8512 -- system.interrupts.register_interrupt_handler
8513 -- (prot_procP'address);
8515 if not Restricted_Profile
8516 and then Is_Interrupt_Handler
8517 (Defining_Unit_Name (Specification (Comp)))
8522 elsif Nkind (Comp) = N_Entry_Declaration then
8523 E_Count := E_Count + 1;
8524 Comp_Id := Defining_Identifier (Comp);
8527 Make_Defining_Identifier (Loc,
8528 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8530 Make_Subprogram_Declaration (Loc,
8532 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8534 Insert_After (Current_Node, Sub);
8537 -- Build wrapper procedure for pre/postconditions
8539 Build_PPC_Wrapper (Comp_Id, N);
8541 Set_Protected_Body_Subprogram
8542 (Defining_Identifier (Comp),
8543 Defining_Unit_Name (Specification (Sub)));
8545 Current_Node := Sub;
8548 Make_Defining_Identifier (Loc,
8549 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8551 Make_Subprogram_Declaration (Loc,
8553 Build_Barrier_Function_Specification (Loc, Bdef));
8555 Insert_After (Current_Node, 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;
8562 -- Collect pointers to the protected subprogram and the barrier
8563 -- of the current entry, for insertion into Entry_Bodies_Array.
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));
8581 -- If there are some private entry declarations, expand it as if they
8582 -- were visible entries.
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);
8592 Make_Defining_Identifier (Loc,
8593 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8595 Make_Subprogram_Declaration (Loc,
8597 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8599 Insert_After (Current_Node, Sub);
8602 Set_Protected_Body_Subprogram
8603 (Defining_Identifier (Comp),
8604 Defining_Unit_Name (Specification (Sub)));
8606 Current_Node := Sub;
8609 Make_Defining_Identifier (Loc,
8610 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8613 Make_Subprogram_Declaration (Loc,
8615 Build_Barrier_Function_Specification (Loc, Bdef));
8617 Insert_After (Current_Node, 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;
8624 -- Collect pointers to the protected subprogram and the barrier
8625 -- of the current entry, for insertion into Entry_Bodies_Array.
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))));
8642 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8643 -- all protected subprograms have been collected.
8645 if Has_Entries (Prot_Typ) then
8647 Make_Defining_Identifier (Sloc (Prot_Typ),
8648 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
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),
8660 Make_Index_Or_Discriminant_Constraint (Loc,
8661 Constraints => New_List (
8663 Make_Integer_Literal (Loc, 1),
8664 Make_Integer_Literal (Loc, E_Count))))),
8665 Expression => Entries_Aggr);
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),
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))));
8684 raise Program_Error;
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.
8690 Insert_After (Current_Node, Body_Arr);
8691 Current_Node := Body_Arr;
8694 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
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)
8701 if Corresponding_Runtime_Package (Prot_Typ) =
8702 System_Tasking_Protected_Objects_Entries
8705 Make_Subprogram_Declaration (Loc,
8706 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8707 Insert_After (Current_Node, Sub);
8711 end Expand_N_Protected_Type_Declaration;
8713 --------------------------------
8714 -- Expand_N_Requeue_Statement --
8715 --------------------------------
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:
8726 -- (O : System.Address;
8727 -- P : System.Address;
8728 -- E : Protected_Entry_Index)
8730 -- <discriminant renamings>
8731 -- <private object renamings>
8732 -- type poVP is access poV;
8733 -- _object : ptVP := ptVP!(O);
8737 -- <start of statement sequence for entry>
8739 -- -- Requeue from one protected entry body to another protected
8742 -- Requeue_Protected_Entry (
8743 -- _object._object'Access,
8744 -- new._object'Access,
8749 -- <some more of the statement sequence for entry>
8751 -- -- Requeue from an entry body to a task entry
8753 -- Requeue_Protected_To_Task_Entry (
8759 -- <rest of statement sequence for entry>
8760 -- Complete_Entry_Body (_object._object);
8763 -- when all others =>
8764 -- Exceptional_Complete_Entry_Body (
8765 -- _object._object, Get_GNAT_Exception);
8769 -- Requeue of a task entry call to a task entry
8771 -- Accept_Call (E, Ann);
8772 -- <start of statement sequence for accept statement>
8773 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8775 -- <rest of statement sequence for accept statement>
8777 -- Complete_Rendezvous;
8780 -- when all others =>
8781 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8783 -- Requeue of a task entry call to a protected entry
8785 -- Accept_Call (E, Ann);
8786 -- <start of statement sequence for accept statement>
8787 -- Requeue_Task_To_Protected_Entry (
8788 -- new._object'Access,
8793 -- <rest of statement sequence for accept statement>
8795 -- Complete_Rendezvous;
8798 -- when all others =>
8799 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8801 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8802 -- marked by pragma Implemented (XXX, By_Entry).
8804 -- The requeue is inside a protected entry:
8807 -- (O : System.Address;
8808 -- P : System.Address;
8809 -- E : Protected_Entry_Index)
8811 -- <discriminant renamings>
8812 -- <private object renamings>
8813 -- type poVP is access poV;
8814 -- _object : ptVP := ptVP!(O);
8818 -- <start of statement sequence for entry>
8821 -- (<interface class-wide object>,
8824 -- Ada.Tags.Get_Offset_Index
8826 -- <interface dispatch table index of target entry>),
8830 -- <rest of statement sequence for entry>
8831 -- Complete_Entry_Body (_object._object);
8834 -- when all others =>
8835 -- Exceptional_Complete_Entry_Body (
8836 -- _object._object, Get_GNAT_Exception);
8840 -- The requeue is inside a task entry:
8842 -- Accept_Call (E, Ann);
8843 -- <start of statement sequence for accept statement>
8845 -- (<interface class-wide object>,
8848 -- Ada.Tags.Get_Offset_Index
8850 -- <interface dispatch table index of target entrt>),
8854 -- <rest of statement sequence for accept statement>
8856 -- Complete_Rendezvous;
8859 -- when all others =>
8860 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
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.
8867 -- Target.Primitive (Param1, ..., ParamN);
8869 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8870 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
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);
8878 -- if C = POK_Protected_Entry
8879 -- or else C = POK_Task_Entry
8881 -- <statements for dispatching requeue>
8883 -- elsif C = POK_Protected_Procedure then
8884 -- <dispatching call equivalent>
8887 -- raise Program_Error;
8891 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8892 Loc : constant Source_Ptr := Sloc (N);
8893 Conc_Typ : Entity_Id;
8897 Old_Typ : Entity_Id;
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.
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.
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.
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
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.
8930 ---------------------------------------
8931 -- Build_Dispatching_Call_Equivalent --
8932 ---------------------------------------
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);
8943 -- Climb the parent chain looking for the inner-most entry body or
8944 -- accept statement.
8947 while Present (Acc_Ent)
8948 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8951 Acc_Ent := Parent (Acc_Ent);
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.
8958 pragma Assert (Present (Acc_Ent));
8960 -- Recover the list of formal parameters
8962 if Nkind (Acc_Ent) = N_Entry_Body then
8963 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8966 Formals := Parameter_Specifications (Acc_Ent);
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.
8974 if Present (Formals) then
8975 Actuals := New_List;
8976 Formal := First (Formals);
8977 while Present (Formal) loop
8979 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8985 -- Obj.Call_Ent (Actuals);
8988 Make_Procedure_Call_Statement (Loc,
8990 Make_Selected_Component (Loc,
8991 Prefix => Make_Identifier (Loc, Chars (Obj)),
8992 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
8994 Parameter_Associations => Actuals);
8995 end Build_Dispatching_Call_Equivalent;
8997 -------------------------------
8998 -- Build_Dispatching_Requeue --
8999 -------------------------------
9001 function Build_Dispatching_Requeue return Node_Id is
9002 Params : constant List_Id := New_List;
9005 -- Process the "with abort" parameter
9008 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
9010 -- Process the entry wrapper's position in the primary dispatch
9011 -- table parameter. Generate:
9013 -- Ada.Tags.Get_Offset_Index
9014 -- (Ada.Tags.Tag (Concval),
9015 -- <interface dispatch table position of Ename>)
9017 if Tagged_Type_Expansion then
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))))));
9029 Make_Function_Call (Loc,
9030 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
9032 Parameter_Associations => New_List (
9036 Make_Attribute_Reference (Loc,
9038 Attribute_Name => Name_Tag),
9042 Make_Attribute_Reference (Loc,
9043 Prefix => New_Reference_To (Etype (Concval), Loc),
9044 Attribute_Name => Name_Tag),
9048 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
9051 -- Specific actuals for protected to XXX requeue
9053 if Is_Protected_Type (Old_Typ) then
9055 Make_Attribute_Reference (Loc, -- _object'Address
9057 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9058 Attribute_Name => Name_Address));
9060 Prepend_To (Params, -- True
9061 New_Reference_To (Standard_True, Loc));
9063 -- Specific actuals for task to XXX requeue
9066 pragma Assert (Is_Task_Type (Old_Typ));
9068 Prepend_To (Params, -- null
9069 New_Reference_To (RTE (RE_Null_Address), Loc));
9071 Prepend_To (Params, -- False
9072 New_Reference_To (Standard_False, Loc));
9075 -- Add the object parameter
9077 Prepend_To (Params, New_Copy_Tree (Concval));
9080 -- _Disp_Requeue (<Params>);
9083 Make_Procedure_Call_Statement (Loc,
9084 Name => Make_Identifier (Loc, Name_uDisp_Requeue),
9085 Parameter_Associations => Params);
9086 end Build_Dispatching_Requeue;
9088 --------------------------------------
9089 -- Build_Dispatching_Requeue_To_Any --
9090 --------------------------------------
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);
9105 -- Dispatch table slot processing, generate:
9108 S := Build_S (Loc, Decls);
9110 -- Call kind processing, generate:
9111 -- C : Ada.Tags.Prim_Op_Kind;
9113 C := Build_C (Loc, Decls);
9116 -- S := Ada.Tags.Get_Offset_Index
9117 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9119 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
9122 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9125 Make_Procedure_Call_Statement (Loc,
9128 Find_Prim_Op (Etype (Etype (Obj)),
9129 Name_uDisp_Get_Prim_Op_Kind),
9131 Parameter_Associations => New_List (
9132 New_Copy_Tree (Obj),
9133 New_Reference_To (S, Loc),
9134 New_Reference_To (C, Loc))));
9138 -- if C = POK_Protected_Entry
9139 -- or else C = POK_Task_Entry
9142 Make_If_Statement (Loc,
9148 New_Reference_To (C, Loc),
9150 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
9155 New_Reference_To (C, Loc),
9157 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
9159 -- Dispatching requeue equivalent
9161 Then_Statements => New_List (
9162 Build_Dispatching_Requeue,
9165 -- elsif C = POK_Protected_Procedure then
9167 Elsif_Parts => New_List (
9168 Make_Elsif_Part (Loc,
9172 New_Reference_To (C, Loc),
9175 RTE (RE_POK_Protected_Procedure), Loc)),
9177 -- Dispatching call equivalent
9179 Then_Statements => New_List (
9180 Build_Dispatching_Call_Equivalent))),
9183 -- raise Program_Error;
9186 Else_Statements => New_List (
9187 Make_Raise_Program_Error (Loc,
9188 Reason => PE_Explicit_Raise))));
9190 -- Wrap everything into a block
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;
9200 --------------------------
9201 -- Build_Normal_Requeue --
9202 --------------------------
9204 function Build_Normal_Requeue return Node_Id is
9205 Params : constant List_Id := New_List;
9210 -- Process the "with abort" parameter
9213 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
9215 -- Add the index expression to the parameters. It is common among all
9219 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
9221 if Is_Protected_Type (Old_Typ) then
9223 Self_Param : Node_Id;
9227 Make_Attribute_Reference (Loc,
9229 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9231 Name_Unchecked_Access);
9233 -- Protected to protected requeue
9235 if Is_Protected_Type (Conc_Typ) then
9238 RTE (RE_Requeue_Protected_Entry), Loc);
9241 Make_Attribute_Reference (Loc,
9243 Concurrent_Ref (Concval),
9245 Name_Unchecked_Access);
9247 -- Protected to task requeue
9249 else pragma Assert (Is_Task_Type (Conc_Typ));
9252 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
9254 Param := Concurrent_Ref (Concval);
9257 Prepend_To (Params, Param);
9258 Prepend_To (Params, Self_Param);
9261 else pragma Assert (Is_Task_Type (Old_Typ));
9263 -- Task to protected requeue
9265 if Is_Protected_Type (Conc_Typ) then
9268 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
9271 Make_Attribute_Reference (Loc,
9273 Concurrent_Ref (Concval),
9275 Name_Unchecked_Access);
9277 -- Task to task requeue
9279 else pragma Assert (Is_Task_Type (Conc_Typ));
9281 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
9283 Param := Concurrent_Ref (Concval);
9286 Prepend_To (Params, Param);
9290 Make_Procedure_Call_Statement (Loc,
9292 Parameter_Associations => Params);
9293 end Build_Normal_Requeue;
9295 --------------------------
9296 -- Build_Skip_Statement --
9297 --------------------------
9299 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
9300 Skip_Stmt : Node_Id;
9303 -- Build a return statement to skip the rest of the entire body
9305 if Is_Protected_Type (Old_Typ) then
9306 Skip_Stmt := Make_Simple_Return_Statement (Loc);
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.
9317 -- Climb the parent chain looking for the enclosing accept
9320 Acc := Parent (Search);
9322 and then Nkind (Acc) /= N_Accept_Statement
9324 Acc := Parent (Acc);
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.
9332 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
9334 pragma Assert (Nkind (Label) = N_Label);
9336 -- Generate a goto statement to skip the rest of the accept
9339 Make_Goto_Statement (Loc,
9341 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9345 Set_Analyzed (Skip_Stmt);
9348 end Build_Skip_Statement;
9350 -- Start of processing for Expand_N_Requeue_Statement
9353 -- Extract the components of the entry call
9355 Extract_Entry (N, Concval, Ename, Index);
9356 Conc_Typ := Etype (Concval);
9358 -- Examine the scope stack in order to find nearest enclosing protected
9359 -- or task type. This will constitute our invocation source.
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)
9366 Old_Typ := Scope (Old_Typ);
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
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)
9379 Has_Impl : Boolean := False;
9380 Impl_Kind : Name_Id := No_Name;
9383 -- Check whether the Ename is flagged by pragma Implemented
9385 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9387 Impl_Kind := Implementation_Kind (Entity (Ename));
9390 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9391 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9394 and then Impl_Kind = Name_By_Entry
9396 Rewrite (N, Build_Dispatching_Requeue);
9398 Insert_After (N, Build_Skip_Statement (N));
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.
9405 and then Impl_Kind = Name_By_Protected_Procedure
9407 Rewrite (N, Build_Dispatching_Call_Equivalent);
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.
9416 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9421 -- Processing for regular (non-dispatching) requeues
9424 Rewrite (N, Build_Normal_Requeue);
9426 Insert_After (N, Build_Skip_Statement (N));
9428 end Expand_N_Requeue_Statement;
9430 -------------------------------
9431 -- Expand_N_Selective_Accept --
9432 -------------------------------
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);
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 ???
9442 Accept_Case : List_Id;
9443 Accept_List : constant List_Id := New_List;
9446 Alt_List : constant List_Id := New_List;
9447 Alt_Stats : List_Id;
9448 Ann : Entity_Id := Empty;
9451 Check_Guard : Boolean := True;
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;
9459 Else_Present : Boolean := False;
9460 Terminate_Alt : Node_Id := Empty;
9461 Select_Mode : Node_Id;
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;
9474 First_Delay : Boolean := True;
9475 Guard_Open : Entity_Id;
9481 Num_Accept : Nat := 0;
9484 Time_Type : Entity_Id;
9486 Select_Call : Node_Id;
9488 Qnam : constant Entity_Id :=
9489 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9491 Xnam : constant Entity_Id :=
9492 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9494 -----------------------
9495 -- Local subprograms --
9496 -----------------------
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.
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.
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.
9515 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9516 -- Build call to Selective_Wait runtime routine
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.
9522 procedure Process_Accept_Alternative
9526 -- Add code to call corresponding procedure, and branch to
9527 -- trailing statements, if any.
9529 ---------------------
9530 -- Accept_Or_Raise --
9531 ---------------------
9533 function Accept_Or_Raise return List_Id is
9536 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9539 -- We generate the following:
9541 -- for J in q'range loop
9542 -- if q(J).S /=null_task_entry then
9543 -- selective_wait (simple_mode,...);
9549 -- if no rendez_vous then
9550 -- raise program_error;
9553 -- Note that the code needs to know that the selector name
9554 -- in an Accept_Alternative is named S.
9556 Cond := Make_Op_Ne (Loc,
9558 Make_Selected_Component (Loc,
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)),
9565 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9568 Make_Implicit_Loop_Statement (N,
9569 Identifier => Empty,
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))))),
9582 Statements => New_List (
9583 Make_Implicit_If_Statement (N,
9585 Then_Statements => New_List (
9587 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9588 Make_Exit_Statement (Loc))))));
9591 Make_Raise_Program_Error (Loc,
9592 Condition => Make_Op_Eq (Loc,
9593 Left_Opnd => New_Reference_To (Xnam, Loc),
9595 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9596 Reason => PE_All_Guards_Closed));
9599 end Accept_Or_Raise;
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;
9619 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9622 if Present (Condition (Alt)) then
9624 Make_Conditional_Expression (Eloc, New_List (
9626 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9627 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9630 Entry_Index_Expression
9631 (Eloc, Eent, Index, Scope (Eent));
9634 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9635 Null_Body := New_Reference_To (Standard_False, Eloc);
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);
9646 Make_Defining_Identifier (Eloc,
9647 New_External_Name (Chars (Ename), 'A', Num_Accept));
9649 if Comes_From_Source (Alt) then
9650 Set_Debug_Info_Needed (PB_Ent);
9654 Make_Subprogram_Body (Eloc,
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)));
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.
9668 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9669 Append (Proc_Body, Body_List);
9672 Null_Body := New_Reference_To (Standard_True, Eloc);
9674 -- if accept statement has declarations, insert above, given that
9675 -- we are not creating a body for the accept.
9677 if Present (Declarations (Acc_Stm)) then
9678 Insert_Actions (N, Declarations (Acc_Stm));
9682 Append_To (Accept_List,
9683 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9685 Num_Accept := Num_Accept + 1;
9688 ----------------------------
9689 -- Make_And_Declare_Label --
9690 ----------------------------
9692 function Make_And_Declare_Label (Num : Int) return Node_Id is
9696 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9698 Make_Label (Loc, Lab_Id);
9701 Make_Implicit_Label_Declaration (Loc,
9702 Defining_Identifier =>
9703 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9704 Label_Construct => Lab));
9707 end Make_And_Declare_Label;
9709 ----------------------
9710 -- Make_Select_Call --
9711 ----------------------
9713 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9714 Params : constant List_Id := New_List;
9718 Make_Attribute_Reference (Loc,
9719 Prefix => New_Reference_To (Qnam, Loc),
9720 Attribute_Name => Name_Unchecked_Access),
9722 Append (Select_Mode, Params);
9723 Append (New_Reference_To (Ann, Loc), Params);
9724 Append (New_Reference_To (Xnam, Loc), Params);
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;
9732 --------------------------------
9733 -- Process_Accept_Alternative --
9734 --------------------------------
9736 procedure Process_Accept_Alternative
9741 Choices : List_Id := No_List;
9742 Alt_Stats : List_Id;
9745 Adjust_Condition (Condition (Alt));
9746 Alt_Stats := No_List;
9748 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9749 Choices := New_List (
9750 Make_Integer_Literal (Loc, Index));
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))));
9758 if Statements (Alt) /= Empty_List then
9760 if No (Alt_Stats) then
9762 -- Accept with no body, followed by trailing statements
9764 Choices := New_List (
9765 Make_Integer_Literal (Loc, Index));
9767 Alt_Stats := New_List;
9770 -- After the call, if any, branch to trailing statements. We
9771 -- create a label for each, as well as the corresponding label
9774 Lab := Make_And_Declare_Label (Index);
9775 Append_To (Alt_Stats,
9776 Make_Goto_Statement (Loc,
9777 Name => New_Copy (Identifier (Lab))));
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))));
9786 if Present (Alt_Stats) then
9788 -- Procedure call. and/or trailing statements
9790 Append_To (Alt_List,
9791 Make_Case_Statement_Alternative (Loc,
9792 Discrete_Choices => Choices,
9793 Statements => Alt_Stats));
9795 end Process_Accept_Alternative;
9797 -------------------------------
9798 -- Process_Delay_Alternative --
9799 -------------------------------
9801 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9804 Delay_Alt : List_Id;
9807 -- Deal with C/Fortran boolean as delay condition
9809 Adjust_Condition (Condition (Alt));
9811 -- Determine the smallest specified delay
9813 -- for each delay alternative generate:
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;
9824 -- The enclosing if-statement is omitted if there is no guard
9829 First_Delay := False;
9831 Delay_Alt := New_List (
9832 Make_Assignment_Statement (Loc,
9833 Name => New_Reference_To (Delay_Min, Loc),
9834 Expression => Expression (Delay_Statement (Alt))));
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)));
9844 Delay_Alt := New_List (
9845 Make_Assignment_Statement (Loc,
9846 Name => New_Reference_To (Delay_Val, Loc),
9847 Expression => Expression (Delay_Statement (Alt))));
9849 if Time_Type = Standard_Duration then
9852 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9853 Right_Opnd => New_Reference_To (Delay_Min, Loc));
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.
9862 Make_Function_Call (Loc,
9863 Name => Make_Selected_Component (Loc,
9864 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9866 Make_Operator_Symbol (Loc,
9867 Chars => Name_Op_Lt,
9868 Strval => No_String)),
9869 Parameter_Associations =>
9871 New_Reference_To (Delay_Val, Loc),
9872 New_Reference_To (Delay_Min, Loc)));
9874 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9877 Append_To (Delay_Alt,
9878 Make_Implicit_If_Statement (N,
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)),
9885 Make_Assignment_Statement (Loc,
9886 Name => New_Reference_To (Delay_Index, Loc),
9887 Expression => Make_Integer_Literal (Loc, Index)))));
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)));
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));
9904 Append_List (Delay_Alt, Delay_List);
9906 -- If the delay alternative has a statement part, add choice to the
9907 -- case statements for delays.
9909 if Present (Statements (Alt)) then
9911 if Delay_Count = 1 then
9912 Append_List (Statements (Alt), Delay_Alt_List);
9915 Choices := New_List (
9916 Make_Integer_Literal (Loc, Index));
9918 Append_To (Delay_Alt_List,
9919 Make_Case_Statement_Alternative (Loc,
9920 Discrete_Choices => Choices,
9921 Statements => Statements (Alt)));
9924 elsif Delay_Count = 1 then
9926 -- If the single delay has no trailing statements, add a branch
9927 -- to the exit label to the selective wait.
9929 Delay_Alt_List := New_List (
9930 Make_Goto_Statement (Loc,
9931 Name => New_Copy (Identifier (End_Lab))));
9934 end Process_Delay_Alternative;
9936 -- Start of processing for Expand_N_Selective_Accept
9939 Process_Statements_For_Controlled_Objects (N);
9941 -- First insert some declarations before the select. The first is:
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.
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:
9958 Alt := First (Alts);
9959 while Present (Alt) loop
9960 Process_Statements_For_Controlled_Objects (Alt);
9962 if Nkind (Alt) = N_Accept_Alternative then
9965 elsif Nkind (Alt) = N_Delay_Alternative then
9966 Delay_Count := Delay_Count + 1;
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.
9972 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9973 Time_Type := Standard_Duration;
9975 Time_Type := Etype (Expression (Delay_Statement (Alt)));
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)
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);
9990 if No (Condition (Alt)) then
9992 -- This guard will always be open
9994 Check_Guard := False;
9997 elsif Nkind (Alt) = N_Terminate_Alternative then
9998 Adjust_Condition (Condition (Alt));
9999 Terminate_Alt := Alt;
10002 Num_Alts := Num_Alts + 1;
10006 Else_Present := Present (Else_Statements (N));
10008 -- At the same time (see procedure Add_Accept) we build the accept list:
10010 -- Qnn : Accept_List (1 .. num-select) := (
10011 -- (null-body, entry-index),
10012 -- (null-body, entry-index),
10014 -- (null_body, entry-index));
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:
10021 -- (if guard then entry-index else Null_Task_Entry)
10023 -- If a guard is statically known to be false, the entry can simply
10024 -- be omitted from the accept list.
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,
10034 Make_Qualified_Expression (Loc,
10036 New_Reference_To (RTE (RE_Accept_List), Loc),
10038 Make_Aggregate (Loc, Expressions => Accept_List)));
10042 -- Then we declare the variable that holds the index for the accept
10043 -- that will be selected for service:
10045 -- Xnn : Select_Index;
10048 Make_Object_Declaration (Loc,
10049 Defining_Identifier => Xnam,
10050 Object_Definition =>
10051 New_Reference_To (RTE (RE_Select_Index), Loc),
10053 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10057 -- After this follow procedure declarations for each accept body
10059 -- procedure Pnn is
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.
10072 -- The original accept statement has been expanded into a block in
10073 -- the same fashion as for simple accepts (see Build_Accept_Body).
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.
10080 -- The procedure declarations have been assembled in Body_List
10082 -- If delays are present, we must compute the required delay.
10083 -- We first generate the declarations:
10085 -- Delay_Index : Boolean := 0;
10086 -- Delay_Min : Some_Time_Type.Time;
10087 -- Delay_Val : Some_Time_Type.Time;
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.
10093 -- In the most common case there is a single delay statement, and this
10094 -- is handled specially.
10096 if Delay_Count > 0 then
10098 -- Generate the required declarations
10101 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
10103 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
10105 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
10108 Make_Object_Declaration (Loc,
10109 Defining_Identifier => Delay_Val,
10110 Object_Definition => New_Reference_To (Time_Type, Loc)));
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)));
10119 Make_Object_Declaration (Loc,
10120 Defining_Identifier => Delay_Min,
10121 Object_Definition => New_Reference_To (Time_Type, Loc),
10123 Unchecked_Convert_To (Time_Type,
10124 Make_Attribute_Reference (Loc,
10126 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
10127 Attribute_Name => Name_Last))));
10129 -- Create Duration and Delay_Mode objects used for passing a delay
10132 D := Make_Temporary (Loc, 'D');
10133 M := Make_Temporary (Loc, 'M');
10139 -- Note that these values are defined in s-osprim.ads and must
10140 -- be kept in sync:
10142 -- Relative : constant := 0;
10143 -- Absolute_Calendar : constant := 1;
10144 -- Absolute_RT : constant := 2;
10146 if Time_Type = Standard_Duration then
10147 Discr := Make_Integer_Literal (Loc, 0);
10149 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10150 Discr := Make_Integer_Literal (Loc, 1);
10154 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10155 Discr := Make_Integer_Literal (Loc, 2);
10159 Make_Object_Declaration (Loc,
10160 Defining_Identifier => D,
10161 Object_Definition =>
10162 New_Reference_To (Standard_Duration, Loc)));
10165 Make_Object_Declaration (Loc,
10166 Defining_Identifier => M,
10167 Object_Definition =>
10168 New_Reference_To (Standard_Integer, Loc),
10169 Expression => Discr));
10172 if Check_Guard then
10174 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
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)));
10183 -- Delay_Count is zero, don't need M and D set (suppress warning)
10190 if Present (Terminate_Alt) then
10192 -- If the terminate alternative guard is False, use
10193 -- Simple_Mode; otherwise use Terminate_Mode.
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)));
10201 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
10204 elsif Else_Present or Delay_Count > 0 then
10205 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
10208 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
10211 Select_Call := Make_Select_Call (Select_Mode);
10212 Append (Select_Call, Stats);
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:
10220 -- when No_Rendezvous => -- omitted if simple mode
10235 -- Lab0: Else_Statements;
10238 -- Lab1: Trailing_Statements1;
10241 -- Lab2: Trailing_Statements2;
10246 -- Generate label for common exit
10248 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
10250 -- First entry is the default case, when no rendezvous is possible
10252 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10254 if Else_Present then
10256 -- If no rendezvous is possible, the else part is executed
10258 Lab := Make_And_Declare_Label (0);
10259 Alt_Stats := New_List (
10260 Make_Goto_Statement (Loc,
10261 Name => New_Copy (Identifier (Lab))));
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))));
10269 Alt_Stats := New_List (
10270 Make_Goto_Statement (Loc,
10271 Name => New_Copy (Identifier (End_Lab))));
10274 Append_To (Alt_List,
10275 Make_Case_Statement_Alternative (Loc,
10276 Discrete_Choices => Choices,
10277 Statements => Alt_Stats));
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.
10283 Alt := First (Select_Alternatives (N));
10284 Proc := First (Body_List);
10285 while Present (Alt) loop
10287 if Nkind (Alt) = N_Accept_Alternative then
10288 Process_Accept_Alternative (Alt, Index, Proc);
10289 Index := Index + 1;
10292 (Handled_Statement_Sequence (Accept_Statement (Alt)))
10297 elsif Nkind (Alt) = N_Delay_Alternative then
10298 Process_Delay_Alternative (Alt, Delay_Num);
10299 Delay_Num := Delay_Num + 1;
10305 -- An others choice is always added to the main case, as well
10306 -- as the delay case (to satisfy the compiler).
10308 Append_To (Alt_List,
10309 Make_Case_Statement_Alternative (Loc,
10310 Discrete_Choices =>
10311 New_List (Make_Others_Choice (Loc)),
10313 New_List (Make_Goto_Statement (Loc,
10314 Name => New_Copy (Identifier (End_Lab))))));
10316 Accept_Case := New_List (
10317 Make_Case_Statement (Loc,
10318 Expression => New_Reference_To (Xnam, Loc),
10319 Alternatives => Alt_List));
10321 Append_List (Trailing_List, Accept_Case);
10322 Append (End_Lab, Accept_Case);
10323 Append_List (Body_List, Decls);
10325 -- Construct case statement for trailing statements of delay
10326 -- alternatives, if there are several of them.
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)),
10334 New_List (Make_Null_Statement (Loc))));
10336 Delay_Case := New_List (
10337 Make_Case_Statement (Loc,
10338 Expression => New_Reference_To (Delay_Index, Loc),
10339 Alternatives => Delay_Alt_List));
10341 Delay_Case := Delay_Alt_List;
10344 -- If there are no delay alternatives, we append the case statement
10345 -- to the statement list.
10347 if Delay_Count = 0 then
10348 Append_List (Accept_Case, Stats);
10350 -- Delay alternatives present
10353 -- If delay alternatives are present we generate:
10355 -- find minimum delay.
10356 -- DX := minimum delay;
10357 -- M := <delay mode>;
10358 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10361 -- if X = No_Rendezvous then
10362 -- case statement for delay statements.
10364 -- case statement for accept alternatives.
10375 -- The type of the delay expression is known to be legal
10377 if Time_Type = Standard_Duration then
10378 Conv := New_Reference_To (Delay_Min, Loc);
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)));
10387 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
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)));
10394 Stmt := Make_Assignment_Statement (Loc,
10395 Name => New_Reference_To (D, Loc),
10396 Expression => Conv);
10398 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10400 Parms := Parameter_Associations (Select_Call);
10401 Parm := First (Parms);
10403 while Present (Parm)
10404 and then Parm /= Select_Mode
10409 pragma Assert (Present (Parm));
10410 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10413 -- Prepare two new parameters of Duration and Delay_Mode type
10414 -- which represent the value and the mode of the minimum delay.
10417 Insert_After (Parm, New_Reference_To (M, Loc));
10418 Insert_After (Parm, New_Reference_To (D, Loc));
10420 -- Create a call to RTS
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));
10427 -- This new call should follow the calculation of the minimum
10430 Insert_List_Before (Select_Call, Delay_List);
10432 if Check_Guard then
10434 Make_Implicit_If_Statement (N,
10435 Condition => New_Reference_To (Guard_Open, Loc),
10437 New_List (New_Copy_Tree (Stmt),
10438 New_Copy_Tree (Select_Call)),
10439 Else_Statements => Accept_Or_Raise);
10440 Rewrite (Select_Call, Stmt);
10442 Insert_Before (Select_Call, Stmt);
10446 Make_Implicit_If_Statement (N,
10447 Condition => Make_Op_Eq (Loc,
10448 Left_Opnd => New_Reference_To (Xnam, Loc),
10450 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10452 Then_Statements => Delay_Case,
10453 Else_Statements => Accept_Case);
10455 Append (Cases, Stats);
10459 -- Replace accept statement with appropriate block
10462 Make_Block_Statement (Loc,
10463 Declarations => Decls,
10464 Handled_Statement_Sequence =>
10465 Make_Handled_Sequence_Of_Statements (Loc,
10466 Statements => Stats));
10468 Rewrite (N, Block);
10471 -- Note: have to worry more about abort deferral in above code ???
10473 -- Final step is to unstack the Accept_Address entries for all accept
10474 -- statements appearing in accept alternatives in the select statement
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)))));
10485 end Expand_N_Selective_Accept;
10487 --------------------------------------
10488 -- Expand_N_Single_Task_Declaration --
10489 --------------------------------------
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!
10496 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10498 raise Program_Error;
10499 end Expand_N_Single_Task_Declaration;
10501 ------------------------
10502 -- Expand_N_Task_Body --
10503 ------------------------
10505 -- Given a task body
10507 -- task body tname is
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:
10517 -- procedure tnameB (_Task : access tnameV) is
10518 -- discriminal : dtype renames _Task.discriminant;
10520 -- procedure _clean is
10522 -- Abort_Defer.all;
10524 -- Abort_Undefer.all;
10529 -- Abort_Undefer.all;
10531 -- System.Task_Stages.Complete_Activation;
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
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).
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.
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);
10565 Insert_Nod : Node_Id;
10566 -- Used to determine the proper location of wrapper body insertions
10569 -- Add renaming declarations for discriminals and a declaration for the
10570 -- entry family index (if applicable).
10572 Install_Private_Data_Declarations
10573 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
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.
10578 if Abort_Allowed then
10579 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10581 (First (Statements (Handled_Statement_Sequence (N))), Call);
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).
10592 if Restricted_Profile then
10593 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10595 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10599 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10603 Make_Subprogram_Body (Loc,
10604 Specification => Build_Task_Proc_Specification (Ttyp),
10605 Declarations => Declarations (N),
10606 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
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.
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));
10619 Rewrite (N, New_N);
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.
10625 if Nkind (Parent (N)) /= N_Subunit then
10627 Make_Assignment_Statement (Loc,
10629 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10630 Expression => New_Reference_To (Standard_True, Loc)));
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.
10637 if Ada_Version >= Ada_2005 then
10638 if Nkind (Parent (N)) = N_Subunit then
10639 Insert_Nod := Corresponding_Stub (Parent (N));
10644 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10646 end Expand_N_Task_Body;
10648 ------------------------------------
10649 -- Expand_N_Task_Type_Declaration --
10650 ------------------------------------
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).
10658 -- taskE : aliased Boolean := False;
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:
10665 -- taskZ : Size_Type := Unspecified_Size;
10667 -- taskZ : Size_Type := Size_Type (size_expression);
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).
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
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;
10687 -- The discriminants are present only if the corresponding task type has
10688 -- discriminants, and they exactly mirror the task type discriminants.
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.
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.
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.
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.
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.
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
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.
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.
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.
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
10747 -- The Entity_Id for this created record type is placed in the
10748 -- Corresponding_Record_Type field of the associated task type entity.
10750 -- Next we create a procedure specification for the task body procedure:
10752 -- procedure taskB (_Task : access taskV);
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.
10760 -- Finally, we set the task index value field of the entry attribute in
10761 -- the case of a simple entry.
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);
10769 Proc_Spec : Node_Id;
10770 Rec_Decl : Node_Id;
10771 Rec_Ent : Entity_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;
10781 -- If already expanded, nothing to do
10783 if Present (Corresponding_Record_Type (Tasktyp)) then
10787 -- Here we will do the expansion
10789 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10791 Rec_Ent := Defining_Identifier (Rec_Decl);
10792 Cdecls := Component_Items (Component_List
10793 (Type_Definition (Rec_Decl)));
10795 Qualify_Entity_Names (N);
10797 -- First create the elaboration variable
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);
10809 -- Next create the declaration of the size variable (tasknmZ)
10811 Set_Storage_Size_Variable (Tasktyp,
10812 Make_Defining_Identifier (Sloc (Tasktyp),
10813 Chars => New_External_Name (Tasknm, 'Z')));
10815 if Present (Taskdef)
10816 and then Has_Storage_Size_Pragma (Taskdef)
10818 Is_Static_Expression
10820 (First (Pragma_Argument_Associations
10821 (Find_Task_Or_Protected_Pragma
10822 (Taskdef, Name_Storage_Size)))))
10825 Make_Object_Declaration (Loc,
10826 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10827 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10829 Convert_To (RTE (RE_Size_Type),
10831 (Expression (First (Pragma_Argument_Associations
10832 (Find_Task_Or_Protected_Pragma
10833 (Taskdef, Name_Storage_Size)))))));
10837 Make_Object_Declaration (Loc,
10838 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10839 Object_Definition =>
10840 New_Reference_To (RTE (RE_Size_Type), Loc),
10842 New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10845 Insert_After (Elab_Decl, Size_Decl);
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.
10851 -- Fill in the component declarations -- first the _Task_Id field
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),
10863 -- Declare static ATCB (that is, created by the expander) if we are
10864 -- using the Restricted run time.
10866 if Restricted_Profile then
10868 Make_Component_Declaration (Loc,
10869 Defining_Identifier =>
10870 Make_Defining_Identifier (Loc, Name_uATCB),
10872 Component_Definition =>
10873 Make_Component_Definition (Loc,
10874 Aliased_Present => True,
10875 Subtype_Indication => Make_Subtype_Indication (Loc,
10877 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
10880 Make_Index_Or_Discriminant_Constraint (Loc,
10882 New_List (Make_Integer_Literal (Loc, 0)))))));
10886 -- Declare static stack (that is, created by the expander) if we are
10887 -- using the Restricted run time on a bare board configuration.
10889 if Restricted_Profile
10890 and then Preallocated_Stacks_On_Target
10892 -- First we need to extract the appropriate stack size
10894 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10896 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
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);
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.
10912 if Nkind (Expr_N) in N_Has_Entity
10913 and then Present (Discriminal_Link (Entity (Expr_N)))
10917 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10919 Set_Parent (Task_Size, P);
10920 Set_Etype (Task_Size, Etyp);
10921 Set_Analyzed (Task_Size);
10924 Task_Size := Relocate_Node (Expr_N);
10930 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10933 Decl_Stack := Make_Component_Declaration (Loc,
10934 Defining_Identifier => Ent_Stack,
10936 Component_Definition =>
10937 Make_Component_Definition (Loc,
10938 Aliased_Present => True,
10939 Subtype_Indication => Make_Subtype_Indication (Loc,
10941 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
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),
10950 Append_To (Cdecls, Decl_Stack);
10952 -- The appropriate alignment for the stack is ensured by the run-time
10953 -- code in charge of task creation.
10957 -- Add components for entry families
10959 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10961 -- Add the _Priority component if a Priority pragma is present
10963 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10965 Prag : constant Node_Id :=
10966 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10970 Expr := First (Pragma_Argument_Associations (Prag));
10972 if Nkind (Expr) = N_Pragma_Argument_Association then
10973 Expr := Expression (Expr);
10976 Expr := New_Copy_Tree (Expr);
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.
10984 if Pragma_Name (Prag) = Name_Priority
10985 and then not GNAT_Mode
10987 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10989 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
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,
11001 Expression => Expr));
11005 -- Add the _Task_Size component if a Storage_Size pragma is present
11007 if Present (Taskdef)
11008 and then Has_Storage_Size_Pragma (Taskdef)
11011 Make_Component_Declaration (Loc,
11012 Defining_Identifier =>
11013 Make_Defining_Identifier (Loc, Name_uSize),
11015 Component_Definition =>
11016 Make_Component_Definition (Loc,
11017 Aliased_Present => False,
11018 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
11022 Convert_To (RTE (RE_Size_Type),
11024 Expression (First (
11025 Pragma_Argument_Associations (
11026 Find_Task_Or_Protected_Pragma
11027 (Taskdef, Name_Storage_Size))))))));
11030 -- Add the _Task_Info component if a Task_Info pragma is present
11032 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
11034 Make_Component_Declaration (Loc,
11035 Defining_Identifier =>
11036 Make_Defining_Identifier (Loc, Name_uTask_Info),
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)),
11044 Expression => New_Copy (
11045 Expression (First (
11046 Pragma_Argument_Associations (
11047 Find_Task_Or_Protected_Pragma
11048 (Taskdef, Name_Task_Info)))))));
11051 -- Add the _CPU component if a CPU pragma is present
11053 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
11055 Make_Component_Declaration (Loc,
11056 Defining_Identifier =>
11057 Make_Defining_Identifier (Loc, Name_uCPU),
11059 Component_Definition =>
11060 Make_Component_Definition (Loc,
11061 Aliased_Present => False,
11062 Subtype_Indication =>
11063 New_Reference_To (RTE (RE_CPU_Range), Loc)),
11065 Expression => New_Copy (
11066 Expression (First (
11067 Pragma_Argument_Associations (
11068 Find_Task_Or_Protected_Pragma
11069 (Taskdef, Name_CPU)))))));
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).
11076 if not Restricted_Profile
11077 and then Present (Taskdef)
11078 and then Has_Relative_Deadline_Pragma (Taskdef)
11081 Make_Component_Declaration (Loc,
11082 Defining_Identifier =>
11083 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
11085 Component_Definition =>
11086 Make_Component_Definition (Loc,
11087 Aliased_Present => False,
11088 Subtype_Indication =>
11089 New_Reference_To (RTE (RE_Time_Span), Loc)),
11092 Convert_To (RTE (RE_Time_Span),
11094 Expression (First (
11095 Pragma_Argument_Associations (
11096 Find_Task_Or_Protected_Pragma
11097 (Taskdef, Name_Relative_Deadline))))))));
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).
11105 if not Restricted_Profile
11106 and then Present (Taskdef)
11107 and then Has_Pragma_Dispatching_Domain (Taskdef)
11110 Make_Component_Declaration (Loc,
11111 Defining_Identifier =>
11112 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
11114 Component_Definition =>
11115 Make_Component_Definition (Loc,
11116 Aliased_Present => False,
11117 Subtype_Indication =>
11119 (RTE (RE_Dispatching_Domain_Access), Loc)),
11122 Unchecked_Convert_To (RTE (RE_Dispatching_Domain_Access),
11126 (Pragma_Argument_Associations
11127 (Find_Task_Or_Protected_Pragma
11128 (Taskdef, Name_Dispatching_Domain))))))));
11131 Insert_After (Size_Decl, Rec_Decl);
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.
11137 Analyze (Rec_Decl);
11139 -- Create the declaration of the task body procedure
11141 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
11143 Make_Subprogram_Declaration (Loc,
11144 Specification => Proc_Spec);
11146 Insert_After (Rec_Decl, Body_Decl);
11148 -- The subprogram does not comes from source, so we have to indicate the
11149 -- need for debugging information explicitly.
11151 if Comes_From_Source (Original_Node (N)) then
11152 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
11155 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11156 -- the corresponding record has been frozen.
11158 if Ada_Version >= Ada_2005 then
11159 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
11162 -- Ada 2005 (AI-345): We must defer freezing to allow further
11163 -- declaration of primitive subprograms covering task interfaces
11165 if Ada_Version <= Ada_95 then
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.
11174 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
11176 if Is_Non_Empty_List (L) then
11177 Insert_List_After (Body_Decl, L);
11182 -- Complete the expansion of access types to the current task type, if
11183 -- any were declared.
11185 Expand_Previous_Access_Type (Tasktyp);
11187 -- Create wrappers for entries that have pre/postconditions
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)))
11198 Build_PPC_Wrapper (Ent, N);
11204 end Expand_N_Task_Type_Declaration;
11206 -------------------------------
11207 -- Expand_N_Timed_Entry_Call --
11208 -------------------------------
11210 -- A timed entry call in normal case is not implemented using ATC mechanism
11211 -- anymore for efficiency reason.
11221 -- is expanded as follow:
11223 -- 1) When T.E is a task entry_call;
11227 -- X : Task_Entry_Index := <entry index>;
11228 -- DX : Duration := To_Duration (D);
11229 -- M : Delay_Mode := <discriminant>;
11230 -- P : parms := (parm, parm, parm);
11233 -- Timed_Protected_Entry_Call
11234 -- (<acceptor-task>, X, P'Address, DX, M, B);
11242 -- 2) When T.E is a protected entry_call;
11246 -- X : Protected_Entry_Index := <entry index>;
11247 -- DX : Duration := To_Duration (D);
11248 -- M : Delay_Mode := <discriminant>;
11249 -- P : parms := (parm, parm, parm);
11252 -- Timed_Protected_Entry_Call
11253 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
11261 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
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);
11274 -- if K = Ada.Tags.TK_Limited_Tagged then
11275 -- <dispatching-call>;
11276 -- <triggering-statements>
11280 -- Ada.Tags.Get_Offset_Index
11281 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
11283 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
11285 -- if C = POK_Protected_Entry
11286 -- or else C = POK_Task_Entry
11288 -- Param1 := P.Param1;
11290 -- ParamN := P.ParamN;
11294 -- if C = POK_Procedure
11295 -- or else C = POK_Protected_Procedure
11296 -- or else C = POK_Task_Procedure
11298 -- <dispatching-call>;
11301 -- <triggering-statements>
11303 -- <timed-statements>
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.
11313 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
11314 Loc : constant Source_Ptr := Sloc (N);
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));
11326 Blk_Typ : Entity_Id;
11328 Call_Ent : Entity_Id;
11329 Conc_Typ_Stmts : List_Id;
11333 D_Type : Entity_Id;
11339 Is_Disp_Select : Boolean;
11340 Lim_Typ_Stmts : List_Id;
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
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.
11361 if Restriction_Active (No_Select_Statements) then
11365 Process_Statements_For_Controlled_Objects (Entry_Call_Alternative (N));
11366 Process_Statements_For_Controlled_Objects (Delay_Alternative (N));
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.
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)
11383 Ada_Version >= Ada_2005
11384 and then Nkind (E_Call) = N_Procedure_Call_Statement;
11386 if Is_Disp_Select then
11387 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11393 -- B : Boolean := False;
11395 B := Build_B (Loc, Decls);
11398 -- C : Ada.Tags.Prim_Op_Kind;
11400 C := Build_C (Loc, Decls);
11402 -- Because the analysis of all statements was disabled, manually
11403 -- analyze the delay statement.
11406 D_Stat := Original_Node (D_Stat);
11409 -- Build an entry call using Simple_Entry_Call
11411 Extract_Entry (E_Call, Concval, Ename, Index);
11412 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11414 Decls := Declarations (E_Call);
11415 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11424 B := Make_Defining_Identifier (Loc, Name_uB);
11427 Make_Object_Declaration (Loc,
11428 Defining_Identifier => B,
11429 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
11432 -- Duration and mode processing
11434 D_Type := Base_Type (Etype (Expression (D_Stat)));
11436 -- Use the type of the delay expression (Calendar or Real_Time) to
11437 -- generate the appropriate conversion.
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));
11443 elsif Is_RTE (D_Type, RO_CA_Time) then
11444 D_Disc := Make_Integer_Literal (Loc, 1);
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))));
11451 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11452 D_Disc := Make_Integer_Literal (Loc, 2);
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))));
11460 D := Make_Temporary (Loc, 'D');
11466 Make_Object_Declaration (Loc,
11467 Defining_Identifier => D,
11468 Object_Definition => New_Reference_To (Standard_Duration, Loc)));
11470 M := Make_Temporary (Loc, 'M');
11473 -- M : Integer := (0 | 1 | 2);
11476 Make_Object_Declaration (Loc,
11477 Defining_Identifier => M,
11478 Object_Definition => New_Reference_To (Standard_Integer, Loc),
11479 Expression => D_Disc));
11481 -- Do the assignment at this stage only because the evaluation of the
11482 -- expression must not occur before (see ACVC C97302A).
11485 Make_Assignment_Statement (Loc,
11486 Name => New_Reference_To (D, Loc),
11487 Expression => D_Conv));
11489 -- Parameter block processing
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.
11495 if Is_Disp_Select then
11497 -- Tagged kind processing, generate:
11498 -- K : Ada.Tags.Tagged_Kind :=
11499 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11501 K := Build_K (Loc, Decls, Obj);
11503 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11505 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11507 -- Dispatch table slot processing, generate:
11510 S := Build_S (Loc, Decls);
11513 -- S := Ada.Tags.Get_Offset_Index
11514 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11517 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11520 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
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.
11527 Params := New_List;
11529 Append_To (Params, New_Copy_Tree (Obj));
11530 Append_To (Params, New_Reference_To (S, Loc));
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));
11540 Append_To (Conc_Typ_Stmts,
11541 Make_Procedure_Call_Statement (Loc,
11545 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
11546 Parameter_Associations => Params));
11549 -- if C = POK_Protected_Entry
11550 -- or else C = POK_Task_Entry
11552 -- Param1 := P.Param1;
11554 -- ParamN := P.ParamN;
11557 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11559 -- Generate the if statement only when the packed parameters need
11560 -- explicit assignments to their corresponding actuals.
11562 if Present (Unpack) then
11563 Append_To (Conc_Typ_Stmts,
11564 Make_If_Statement (Loc,
11570 Left_Opnd => New_Reference_To (C, Loc),
11573 (RTE (RE_POK_Protected_Entry), Loc)),
11577 Left_Opnd => New_Reference_To (C, Loc),
11579 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11581 Then_Statements => Unpack));
11587 -- if C = POK_Procedure
11588 -- or else C = POK_Protected_Procedure
11589 -- or else C = POK_Task_Procedure
11591 -- <dispatching-call>
11593 -- <triggering-statements>
11595 -- <timed-statements>
11598 N_Stats := Copy_Separate_List (E_Stats);
11600 Prepend_To (N_Stats,
11601 Make_If_Statement (Loc,
11607 Left_Opnd => New_Reference_To (C, Loc),
11609 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11615 Left_Opnd => New_Reference_To (C, Loc),
11617 New_Reference_To (RTE (
11618 RE_POK_Protected_Procedure), Loc)),
11621 Left_Opnd => New_Reference_To (C, Loc),
11624 (RTE (RE_POK_Task_Procedure), Loc)))),
11626 Then_Statements => New_List (E_Call)));
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));
11635 -- <dispatching-call>;
11636 -- <triggering-statements>
11638 Lim_Typ_Stmts := Copy_Separate_List (E_Stats);
11639 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11642 -- if K = Ada.Tags.TK_Limited_Tagged then
11649 Make_If_Statement (Loc,
11652 Left_Opnd => New_Reference_To (K, Loc),
11654 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11655 Then_Statements => Lim_Typ_Stmts,
11656 Else_Statements => Conc_Typ_Stmts));
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 ???
11663 Stmt := First (Stmts);
11664 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11668 -- Do the assignment at this stage only because the evaluation
11669 -- of the expression must not occur before (see ACVC C97302A).
11671 Insert_Before (Stmt,
11672 Make_Assignment_Statement (Loc,
11673 Name => New_Reference_To (D, Loc),
11674 Expression => D_Conv));
11677 Params := Parameter_Associations (Call);
11679 -- For a protected type, we build a Timed_Protected_Entry_Call
11681 if Is_Protected_Type (Etype (Concval)) then
11683 -- Create a new call statement
11685 Param := First (Params);
11686 while Present (Param)
11687 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11692 Dummy := Remove_Next (Next (Param));
11694 -- Remove garbage is following the Cancel_Param if present
11696 Dummy := Next (Param);
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
11702 pragma Assert (Present (Param));
11703 Rewrite (Param, New_Reference_To (D, Loc));
11705 Rewrite (Dummy, New_Reference_To (M, Loc));
11707 -- Add a Boolean flag for successful entry call
11709 Append_To (Params, New_Reference_To (B, Loc));
11711 case Corresponding_Runtime_Package (Etype (Concval)) is
11712 when System_Tasking_Protected_Objects_Entries =>
11714 Make_Procedure_Call_Statement (Loc,
11717 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11718 Parameter_Associations => Params));
11720 when System_Tasking_Protected_Objects_Single_Entry =>
11721 Param := First (Params);
11722 while Present (Param)
11724 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11732 Make_Procedure_Call_Statement (Loc,
11735 (RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11736 Parameter_Associations => Params));
11739 raise Program_Error;
11742 -- For the task case, build a Timed_Task_Entry_Call
11745 -- Create a new call statement
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));
11752 Make_Procedure_Call_Statement (Loc,
11754 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11755 Parameter_Associations => Params));
11759 Make_Implicit_If_Statement (N,
11760 Condition => New_Reference_To (B, Loc),
11761 Then_Statements => E_Stats,
11762 Else_Statements => D_Stats));
11766 Make_Block_Statement (Loc,
11767 Declarations => Decls,
11768 Handled_Statement_Sequence =>
11769 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11772 end Expand_N_Timed_Entry_Call;
11774 ----------------------------------------
11775 -- Expand_Protected_Body_Declarations --
11776 ----------------------------------------
11778 procedure Expand_Protected_Body_Declarations
11780 Spec_Id : Entity_Id)
11783 if No_Run_Time_Mode then
11784 Error_Msg_CRT ("protected body", N);
11787 elsif Full_Expander_Active then
11789 -- Associate discriminals with the first subprogram or entry body to
11792 if Present (First_Protected_Operation (Declarations (N))) then
11793 Set_Discriminals (Parent (Spec_Id));
11796 end Expand_Protected_Body_Declarations;
11798 -------------------------
11799 -- External_Subprogram --
11800 -------------------------
11802 function External_Subprogram (E : Entity_Id) return Entity_Id is
11803 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
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.
11812 -- If the operation is a function that returns an anonymous access type,
11813 -- the corresponding itype appears before the operation, and must be
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 ???
11819 if Is_Access_Type (Next_Entity (Subp)) then
11820 return Next_Entity (Next_Entity (Subp));
11822 return Next_Entity (Subp);
11824 end External_Subprogram;
11826 ------------------------------
11827 -- Extract_Dispatching_Call --
11828 ------------------------------
11830 procedure Extract_Dispatching_Call
11832 Call_Ent : out Entity_Id;
11833 Object : out Entity_Id;
11834 Actuals : out List_Id;
11835 Formals : out List_Id)
11837 Call_Nam : Node_Id;
11840 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11842 if Present (Original_Node (N)) then
11843 Call_Nam := Name (Original_Node (N));
11845 Call_Nam := Name (N);
11848 -- Retrieve the name of the dispatching procedure. It contains the
11849 -- dispatch table slot number.
11852 case Nkind (Call_Nam) is
11853 when N_Identifier =>
11856 when N_Selected_Component =>
11857 Call_Nam := Selector_Name (Call_Nam);
11860 raise Program_Error;
11865 Actuals := Parameter_Associations (N);
11866 Call_Ent := Entity (Call_Nam);
11867 Formals := Parameter_Specifications (Parent (Call_Ent));
11868 Object := First (Actuals);
11870 if Present (Original_Node (Object)) then
11871 Object := Original_Node (Object);
11874 -- If the type of the dispatching object is an access type then return
11875 -- an explicit dereference.
11877 if Is_Access_Type (Etype (Object)) then
11878 Object := Make_Explicit_Dereference (Sloc (N), Object);
11881 end Extract_Dispatching_Call;
11883 -------------------
11884 -- Extract_Entry --
11885 -------------------
11887 procedure Extract_Entry
11889 Concval : out Node_Id;
11890 Ename : out Node_Id;
11891 Index : out Node_Id)
11893 Nam : constant Node_Id := Name (N);
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.
11899 if Nkind (Nam) = N_Selected_Component then
11900 Concval := Prefix (Nam);
11901 Ename := Selector_Name (Nam);
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.
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));
11917 -------------------
11918 -- Family_Offset --
11919 -------------------
11921 function Family_Offset
11926 Cap : Boolean) return Node_Id
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.
11939 ------------------------------
11940 -- Convert_Discriminant_Ref --
11941 ------------------------------
11943 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11944 Loc : constant Source_Ptr := Sloc (Bound);
11949 if Is_Entity_Name (Bound)
11950 and then Ekind (Entity (Bound)) = E_Discriminant
11952 if Is_Task_Type (Ttyp)
11953 and then Has_Completion (Ttyp)
11955 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11956 Find_Direct_Name (B);
11958 elsif Is_Protected_Type (Ttyp) then
11959 D := First_Discriminant (Ttyp);
11960 while Chars (D) /= Chars (Entity (Bound)) loop
11961 Next_Discriminant (D);
11964 B := New_Reference_To (Discriminal (D), Loc);
11967 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11970 elsif Nkind (Bound) = N_Attribute_Reference then
11974 B := New_Copy_Tree (Bound);
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;
11984 -- Start of processing for Family_Offset
11987 Real_Hi := Convert_Discriminant_Ref (Hi);
11988 Real_Lo := Convert_Discriminant_Ref (Lo);
11991 if Is_Task_Type (Ttyp) then
11992 Ityp := RTE (RE_Task_Entry_Index);
11994 Ityp := RTE (RE_Protected_Entry_Index);
11998 Make_Attribute_Reference (Loc,
11999 Prefix => New_Reference_To (Ityp, Loc),
12000 Attribute_Name => Name_Min,
12001 Expressions => New_List (
12003 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12006 Make_Attribute_Reference (Loc,
12007 Prefix => New_Reference_To (Ityp, Loc),
12008 Attribute_Name => Name_Max,
12009 Expressions => New_List (
12011 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12014 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12021 function Family_Size
12026 Cap : Boolean) return Node_Id
12031 if Is_Task_Type (Ttyp) then
12032 Ityp := RTE (RE_Task_Entry_Index);
12034 Ityp := RTE (RE_Protected_Entry_Index);
12038 Make_Attribute_Reference (Loc,
12039 Prefix => New_Reference_To (Ityp, Loc),
12040 Attribute_Name => Name_Max,
12041 Expressions => New_List (
12044 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
12046 Make_Integer_Literal (Loc, 1)),
12047 Make_Integer_Literal (Loc, 0)));
12050 ----------------------------
12051 -- Find_Enclosing_Context --
12052 ----------------------------
12054 procedure Find_Enclosing_Context
12056 Context : out Node_Id;
12057 Context_Id : out Entity_Id;
12058 Context_Decls : out List_Id)
12061 -- Traverse the parent chain looking for an enclosing body, block,
12062 -- package or return statement.
12064 Context := Parent (N);
12065 while not Nkind_In (Context, N_Block_Statement,
12067 N_Extended_Return_Statement,
12069 N_Package_Declaration,
12073 Context := Parent (Context);
12076 -- Extract the constituents of the context
12078 if Nkind (Context) = N_Extended_Return_Statement then
12079 Context_Decls := Return_Object_Declarations (Context);
12080 Context_Id := Return_Statement_Entity (Context);
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.
12086 elsif Nkind (Context) = N_Package_Body then
12087 Context_Decls := Declarations (Context);
12088 Context_Id := Corresponding_Spec (Context);
12089 Context := Parent (Context_Id);
12091 if Nkind (Context) = N_Defining_Program_Unit_Name then
12092 Context := Parent (Parent (Context));
12094 Context := Parent (Context);
12097 elsif Nkind (Context) = N_Package_Declaration then
12098 Context_Decls := Visible_Declarations (Specification (Context));
12099 Context_Id := Defining_Unit_Name (Specification (Context));
12101 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12102 Context_Id := Defining_Identifier (Context_Id);
12106 Context_Decls := Declarations (Context);
12108 if Nkind (Context) = N_Block_Statement then
12109 Context_Id := Entity (Identifier (Context));
12111 elsif Nkind (Context) = N_Entry_Body then
12112 Context_Id := Defining_Identifier (Context);
12114 elsif Nkind (Context) = N_Subprogram_Body then
12115 if Present (Corresponding_Spec (Context)) then
12116 Context_Id := Corresponding_Spec (Context);
12118 Context_Id := Defining_Unit_Name (Specification (Context));
12120 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12121 Context_Id := Defining_Identifier (Context_Id);
12125 elsif Nkind (Context) = N_Task_Body then
12126 Context_Id := Corresponding_Spec (Context);
12129 raise Program_Error;
12133 pragma Assert (Present (Context));
12134 pragma Assert (Present (Context_Id));
12135 pragma Assert (Present (Context_Decls));
12136 end Find_Enclosing_Context;
12138 -----------------------
12139 -- Find_Master_Scope --
12140 -----------------------
12142 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
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.
12155 if Ada_Version >= Ada_2005 then
12156 while Is_Internal (S) loop
12157 if Nkind (Parent (S)) = N_Block_Statement
12159 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
12163 elsif Ekind (S) = E_Return_Statement then
12173 end Find_Master_Scope;
12175 -----------------------------------
12176 -- Find_Task_Or_Protected_Pragma --
12177 -----------------------------------
12179 function Find_Task_Or_Protected_Pragma
12181 P : Name_Id) return Node_Id
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
12192 elsif P = Name_Priority
12193 and then Pragma_Name (N) = Name_Interrupt_Priority
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
12212 elsif P = Name_Priority
12213 and then Pragma_Name (N) = Name_Interrupt_Priority
12226 raise Program_Error;
12227 end Find_Task_Or_Protected_Pragma;
12229 -------------------------------
12230 -- First_Protected_Operation --
12231 -------------------------------
12233 function First_Protected_Operation (D : List_Id) return Node_Id is
12234 First_Op : Node_Id;
12237 First_Op := First (D);
12238 while Present (First_Op)
12239 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
12245 end First_Protected_Operation;
12247 ---------------------------------------
12248 -- Install_Private_Data_Declarations --
12249 ---------------------------------------
12251 procedure Install_Private_Data_Declarations
12253 Spec_Id : Entity_Id;
12254 Conc_Typ : Entity_Id;
12255 Body_Nod : Node_Id;
12257 Barrier : Boolean := False;
12258 Family : Boolean := False)
12260 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
12263 Insert_Node : Node_Id := Empty;
12264 Obj_Ent : Entity_Id;
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
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.
12280 procedure Add (Decl : Node_Id) is
12282 if No (Insert_Node) then
12283 Prepend_To (Decls, Decl);
12285 Insert_After (Insert_Node, Decl);
12288 Insert_Node := Decl;
12291 --------------------------
12292 -- Replace_Discriminant --
12293 --------------------------
12295 function Replace_Bound (Bound : Node_Id) return Node_Id is
12297 if Nkind (Bound) = N_Identifier
12298 and then Is_Discriminal (Entity (Bound))
12300 return Make_Identifier (Loc, Chars (Entity (Bound)));
12302 return Duplicate_Subexpr (Bound);
12306 -- Start of processing for Install_Private_Data_Declarations
12309 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
12310 -- formal parameter _O, _object or _task depending on the context.
12312 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
12314 -- Special processing of _O for barrier functions, protected entries
12321 (Ekind (Spec_Id) = E_Entry
12322 or else Ekind (Spec_Id) = E_Entry_Family))
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'));
12332 -- type prot_typVP is access prot_typV;
12335 Make_Full_Type_Declaration (Loc,
12336 Defining_Identifier => Typ_Id,
12338 Make_Access_To_Object_Definition (Loc,
12339 Subtype_Indication =>
12340 New_Reference_To (Conc_Rec, Loc)));
12344 -- _object : prot_typVP := prot_typV (_O);
12347 Make_Object_Declaration (Loc,
12348 Defining_Identifier =>
12349 Make_Defining_Identifier (Loc, Name_uObject),
12350 Object_Definition => New_Reference_To (Typ_Id, Loc),
12352 Unchecked_Convert_To (Typ_Id,
12353 New_Reference_To (Obj_Ent, Loc)));
12356 -- Set the reference to the concurrent object
12358 Obj_Ent := Defining_Identifier (Decl);
12362 -- Step 2: Create the Protection object and build its declaration for
12363 -- any protected entry (family) of subprogram.
12365 if Is_Protected then
12367 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
12371 Set_Protection_Object (Spec_Id, Prot_Ent);
12373 -- Determine the proper protection type
12375 if Has_Attach_Handler (Conc_Typ)
12376 and then not Restricted_Profile
12377 and then not Restriction_Active (No_Dynamic_Attachment)
12379 Prot_Typ := RE_Static_Interrupt_Protection;
12381 elsif Has_Interrupt_Handler (Conc_Typ)
12382 and then not Restriction_Active (No_Dynamic_Attachment)
12384 Prot_Typ := RE_Dynamic_Interrupt_Protection;
12386 -- The type has explicit entries or generated primitive entry
12389 elsif Has_Entries (Conc_Typ)
12391 (Ada_Version >= Ada_2005
12392 and then Present (Interface_List (Parent (Conc_Typ))))
12394 case Corresponding_Runtime_Package (Conc_Typ) is
12395 when System_Tasking_Protected_Objects_Entries =>
12396 Prot_Typ := RE_Protection_Entries;
12398 when System_Tasking_Protected_Objects_Single_Entry =>
12399 Prot_Typ := RE_Protection_Entry;
12402 raise Program_Error;
12406 Prot_Typ := RE_Protection;
12410 -- conc_typR : protection_typ renames _object._object;
12413 Make_Object_Renaming_Declaration (Loc,
12414 Defining_Identifier => Prot_Ent,
12416 New_Reference_To (RTE (Prot_Typ), Loc),
12418 Make_Selected_Component (Loc,
12419 Prefix => New_Reference_To (Obj_Ent, Loc),
12420 Selector_Name => Make_Identifier (Loc, Name_uObject)));
12425 -- Step 3: Add discriminant renamings (if any)
12427 if Has_Discriminants (Conc_Typ) then
12432 D := First_Discriminant (Conc_Typ);
12433 while Present (D) loop
12435 -- Adjust the source location
12437 Set_Sloc (Discriminal (D), Loc);
12440 -- discr_name : discr_typ renames _object.discr_name;
12442 -- discr_name : discr_typ renames _task.discr_name;
12445 Make_Object_Renaming_Declaration (Loc,
12446 Defining_Identifier => Discriminal (D),
12447 Subtype_Mark => New_Reference_To (Etype (D), Loc),
12449 Make_Selected_Component (Loc,
12450 Prefix => New_Reference_To (Obj_Ent, Loc),
12451 Selector_Name => Make_Identifier (Loc, Chars (D))));
12454 Next_Discriminant (D);
12459 -- Step 4: Add private component renamings (if any)
12461 if Is_Protected then
12462 Def := Protected_Definition (Parent (Conc_Typ));
12464 if Present (Private_Declarations (Def)) then
12467 Comp_Id : Entity_Id;
12468 Decl_Id : Entity_Id;
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);
12476 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12478 -- Minimal decoration
12480 if Ekind (Spec_Id) = E_Function then
12481 Set_Ekind (Decl_Id, E_Constant);
12483 Set_Ekind (Decl_Id, E_Variable);
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));
12491 -- comp_name : comp_typ renames _object.comp_name;
12494 Make_Object_Renaming_Declaration (Loc,
12495 Defining_Identifier => Decl_Id,
12497 New_Reference_To (Etype (Comp_Id), Loc),
12499 Make_Selected_Component (Loc,
12501 New_Reference_To (Obj_Ent, Loc),
12503 Make_Identifier (Loc, Chars (Comp_Id))));
12513 -- Step 5: Add the declaration of the entry index and the associated
12514 -- type for barrier functions and entry families.
12516 if (Barrier and then Family)
12517 or else Ekind (Spec_Id) = E_Entry_Family
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));
12528 Index_Typ : Entity_Id;
12532 -- Minimal decoration
12534 Set_Ekind (Index_Con, E_Constant);
12535 Set_Entry_Index_Constant (Index, Index_Con);
12536 Set_Discriminal_Link (Index_Con, Index);
12538 -- Retrieve the bounds of the entry family
12540 High := Type_High_Bound (Etype (Index));
12541 Low := Type_Low_Bound (Etype (Index));
12543 -- In the simple case the entry family is given by a subtype
12544 -- mark and the index constant has the same type.
12546 if Is_Entity_Name (Original_Node (
12547 Discrete_Subtype_Definition (Parent (Index))))
12549 Index_Typ := Etype (Index);
12551 -- Otherwise a new subtype declaration is required
12554 High := Replace_Bound (High);
12555 Low := Replace_Bound (Low);
12557 Index_Typ := Make_Temporary (Loc, 'J');
12560 -- subtype Jnn is <Etype of Index> range Low .. High;
12563 Make_Subtype_Declaration (Loc,
12564 Defining_Identifier => Index_Typ,
12565 Subtype_Indication =>
12566 Make_Subtype_Indication (Loc,
12568 New_Reference_To (Base_Type (Etype (Index)), Loc),
12570 Make_Range_Constraint (Loc,
12571 Range_Expression =>
12572 Make_Range (Loc, Low, High))));
12576 Set_Etype (Index_Con, Index_Typ);
12578 -- Create the object which designates the index:
12579 -- J : constant Jnn :=
12580 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
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.
12587 Make_Object_Declaration (Loc,
12588 Defining_Identifier => Index_Con,
12589 Constant_Present => True,
12590 Object_Definition =>
12591 New_Reference_To (Index_Typ, Loc),
12594 Make_Attribute_Reference (Loc,
12596 New_Reference_To (Index_Typ, Loc),
12597 Attribute_Name => Name_Val,
12599 Expressions => New_List (
12603 Make_Op_Subtract (Loc,
12605 New_Reference_To (E, Loc),
12607 Entry_Index_Expression (Loc,
12608 Defining_Identifier (Body_Nod),
12612 Make_Attribute_Reference (Loc,
12614 New_Reference_To (Index_Typ, Loc),
12615 Attribute_Name => Name_Pos,
12616 Expressions => New_List (
12617 Make_Attribute_Reference (Loc,
12619 New_Reference_To (Index_Typ, Loc),
12620 Attribute_Name => Name_First)))))));
12624 end Install_Private_Data_Declarations;
12626 ---------------------------------
12627 -- Is_Potentially_Large_Family --
12628 ---------------------------------
12630 function Is_Potentially_Large_Family
12631 (Base_Index : Entity_Id;
12632 Conctyp : Entity_Id;
12634 Hi : Node_Id) return Boolean
12637 return Scope (Base_Index) = Standard_Standard
12638 and then Base_Index = Base_Type (Standard_Integer)
12639 and then Has_Discriminants (Conctyp)
12641 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12643 (Denotes_Discriminant (Lo, True)
12644 or else Denotes_Discriminant (Hi, True));
12645 end Is_Potentially_Large_Family;
12647 -------------------------------------
12648 -- Is_Private_Primitive_Subprogram --
12649 -------------------------------------
12651 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12654 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12655 and then Is_Private_Primitive (Id);
12656 end Is_Private_Primitive_Subprogram;
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;
12667 Formal := First_Formal (Bod_Subp);
12668 while Present (Formal) loop
12670 -- Look for formal parameter _E
12672 if Chars (Formal) = Name_uE then
12676 Next_Formal (Formal);
12679 -- A protected body subprogram should always have the parameter in
12682 raise Program_Error;
12685 --------------------------------
12686 -- Make_Initialize_Protection --
12687 --------------------------------
12689 function Make_Initialize_Protection
12690 (Protect_Rec : Entity_Id) return List_Id
12692 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12696 Ptyp : constant Node_Id :=
12697 Corresponding_Concurrent_Type (Protect_Rec);
12699 L : constant List_Id := New_List;
12700 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12701 Restricted : constant Boolean := Restricted_Profile;
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.
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.
12714 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12715 -- of this type should have been removed during semantic analysis.
12717 Pdec := Parent (Ptyp);
12718 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12719 N_Single_Protected_Declaration)
12724 -- Now we can find the object definition from this declaration
12726 Pdef := Protected_Definition (Pdec);
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.
12734 -- Object parameter. This is a pointer to the object of type
12735 -- Protection used by the GNARL to control the protected object.
12738 Make_Attribute_Reference (Loc,
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));
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).
12752 and then Has_Pragma_Priority (Pdef)
12755 Prio : constant Node_Id :=
12758 (Pragma_Argument_Associations
12759 (Find_Task_Or_Protected_Pragma
12760 (Pdef, Name_Priority))));
12764 -- If priority is a static expression, then we can duplicate it
12765 -- with no problem and simply append it to the argument list.
12767 if Is_Static_Expression (Prio) then
12769 Duplicate_Subexpr_No_Checks (Prio));
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.
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).
12785 Temp := Make_Temporary (Loc, 'R', Prio);
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)));
12793 Append_To (Args, New_Occurrence_Of (Temp, Loc));
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).
12800 elsif Has_Attach_Handler (Ptyp)
12801 or else Has_Interrupt_Handler (Ptyp)
12804 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12806 -- Normal case, no priority or xx_Handler specified, default priority
12810 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
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.
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.
12824 or else Has_Interfaces (Protect_Rec)
12826 ((Has_Attach_Handler (Ptyp) or else Has_Interrupt_Handler (Ptyp))
12827 and then not Restriction_Active (No_Dynamic_Attachment))
12830 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
12832 Called_Subp : RE_Id;
12836 when System_Tasking_Protected_Objects_Entries =>
12837 Called_Subp := RE_Initialize_Protection_Entries;
12839 when System_Tasking_Protected_Objects =>
12840 Called_Subp := RE_Initialize_Protection;
12842 when System_Tasking_Protected_Objects_Single_Entry =>
12843 Called_Subp := RE_Initialize_Protection_Entry;
12846 raise Program_Error;
12850 or else not Restricted
12851 or else Has_Interfaces (Protect_Rec)
12854 Make_Attribute_Reference (Loc,
12855 Prefix => Make_Identifier (Loc, Name_uInit),
12856 Attribute_Name => Name_Address));
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.
12865 P_Arr := Entry_Bodies_Array (Ptyp);
12868 Make_Attribute_Reference (Loc,
12869 Prefix => New_Reference_To (P_Arr, Loc),
12870 Attribute_Name => Name_Unrestricted_Access));
12872 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12874 -- Find index mapping function (clumsy but ok for now)
12876 while Ekind (P_Arr) /= E_Function loop
12877 Next_Entity (P_Arr);
12881 Make_Attribute_Reference (Loc,
12882 Prefix => New_Reference_To (P_Arr, Loc),
12883 Attribute_Name => Name_Unrestricted_Access));
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.
12889 if not Restricted_Profile then
12890 if Entry_Names_OK then
12892 New_Reference_To (Standard_True, Loc));
12895 New_Reference_To (Standard_False, Loc));
12900 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12901 Append_To (Args, Make_Null (Loc));
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));
12910 Make_Procedure_Call_Statement (Loc,
12911 Name => New_Reference_To (RTE (Called_Subp), Loc),
12912 Parameter_Associations => Args));
12916 Make_Procedure_Call_Statement (Loc,
12917 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12918 Parameter_Associations => Args));
12921 if Has_Attach_Handler (Ptyp) then
12923 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12924 -- make the following call:
12926 -- Install_Handlers (_object,
12927 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12929 -- or, in the case of Ravenscar:
12931 -- Install_Restricted_Handlers
12932 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12935 Args : constant List_Id := New_List;
12936 Table : constant List_Id := New_List;
12937 Ritem : Node_Id := First_Rep_Item (Ptyp);
12940 -- Build the Attach_Handler table argument
12942 while Present (Ritem) loop
12943 if Nkind (Ritem) = N_Pragma
12944 and then Pragma_Name (Ritem) = Name_Attach_Handler
12947 Handler : constant Node_Id :=
12948 First (Pragma_Argument_Associations (Ritem));
12950 Interrupt : constant Node_Id := Next (Handler);
12951 Expr : constant Node_Id := Expression (Interrupt);
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))));
12967 Next_Rep_Item (Ritem);
12970 -- Append the table argument we just built
12972 Append_To (Args, Make_Aggregate (Loc, Table));
12974 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12975 -- call to the statements.
12978 -- Call a simplified version of Install_Handlers to be used
12979 -- when the Ravenscar restrictions are in effect
12980 -- (Install_Restricted_Handlers).
12983 Make_Procedure_Call_Statement (Loc,
12986 (RTE (RE_Install_Restricted_Handlers), Loc),
12987 Parameter_Associations => Args));
12990 -- First, prepends the _object argument
12993 Make_Attribute_Reference (Loc,
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));
13000 -- Then, insert call to Install_Handlers
13003 Make_Procedure_Call_Statement (Loc,
13004 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
13005 Parameter_Associations => Args));
13011 end Make_Initialize_Protection;
13013 ---------------------------
13014 -- Make_Task_Create_Call --
13015 ---------------------------
13017 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
13018 Loc : constant Source_Ptr := Sloc (Task_Rec);
13028 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
13029 Tnam := Chars (Ttyp);
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.
13037 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13038 -- this type should have been removed during semantic analysis.
13040 Tdec := Parent (Ttyp);
13041 while not Nkind_In (Tdec, N_Task_Type_Declaration,
13042 N_Single_Task_Declaration)
13047 -- Now we can find the task definition from this declaration
13049 Tdef := Task_Definition (Tdec);
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.
13057 -- Priority parameter. Set to Unspecified_Priority unless there is a
13058 -- priority pragma, in which case we take the value from the pragma.
13060 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
13062 Make_Selected_Component (Loc,
13063 Prefix => Make_Identifier (Loc, Name_uInit),
13064 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
13067 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
13070 -- Optional Stack parameter
13072 if Restricted_Profile then
13074 -- If the stack has been preallocated by the expander then
13075 -- pass its address. Otherwise, pass a null address.
13077 if Preallocated_Stacks_On_Target then
13079 Make_Attribute_Reference (Loc,
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));
13088 New_Reference_To (RTE (RE_Null_Address), Loc));
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.
13100 and then Has_Storage_Size_Pragma (Tdef)
13103 Make_Selected_Component (Loc,
13104 Prefix => Make_Identifier (Loc, Name_uInit),
13105 Selector_Name => Make_Identifier (Loc, Name_uSize)));
13109 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
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.
13116 and then Has_Task_Info_Pragma (Tdef)
13119 Make_Selected_Component (Loc,
13120 Prefix => Make_Identifier (Loc, Name_uInit),
13121 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
13125 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
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.
13133 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
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))));
13142 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
13145 if not Restricted_Profile then
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.
13154 -- Case where pragma Relative_Deadline applies: use given value
13156 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
13158 Make_Selected_Component (Loc,
13160 Make_Identifier (Loc, Name_uInit),
13162 Make_Identifier (Loc, Name_uRelative_Deadline)));
13164 -- No pragma Relative_Deadline apply to the task
13168 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
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.
13179 -- Case where pragma or aspect Dispatching_Domain applies: use given
13182 if Present (Tdef) and then Has_Pragma_Dispatching_Domain (Tdef) then
13184 Make_Selected_Component (Loc,
13186 Make_Identifier (Loc, Name_uInit),
13188 Make_Identifier (Loc, Name_uDispatching_Domain)));
13190 -- No pragma or aspect Dispatching_Domain apply to the task
13193 Append_To (Args, Make_Null (Loc));
13196 -- Number of entries. This is an expression of the form:
13198 -- n + _Init.a'Length + _Init.a'B'Length + ...
13200 -- where a,b... are the entry family names for the task definition
13203 Build_Entry_Count_Expression
13208 (Parent (Corresponding_Record_Type (Ttyp))))),
13210 Append_To (Args, Ecount);
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.
13217 if Restriction_Active (No_Task_Hierarchy) = False then
13218 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
13221 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
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.
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);
13239 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
13240 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
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.
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 ???
13250 if VM_Target = No_VM then
13251 Set_Itype (Ref, Subp_Ptr_Typ);
13252 Append_Freeze_Action (Task_Rec, Ref);
13255 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
13256 Make_Qualified_Expression (Loc,
13257 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
13259 Make_Attribute_Reference (Loc,
13261 New_Occurrence_Of (Body_Proc, Loc),
13262 Attribute_Name => Name_Unrestricted_Access))));
13264 -- For the .NET/JVM cases revert to the original code below ???
13268 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
13269 Make_Attribute_Reference (Loc,
13271 New_Occurrence_Of (Body_Proc, Loc),
13272 Attribute_Name => Name_Address)));
13276 -- Discriminants parameter. This is just the address of the task
13277 -- value record itself (which contains the discriminant values
13280 Make_Attribute_Reference (Loc,
13281 Prefix => Make_Identifier (Loc, Name_uInit),
13282 Attribute_Name => Name_Address));
13284 -- Elaborated parameter. This is an access to the elaboration Boolean
13287 Make_Attribute_Reference (Loc,
13288 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
13289 Attribute_Name => Name_Unchecked_Access));
13291 -- Chain parameter. This is a reference to the _Chain parameter of
13292 -- the initialization procedure.
13294 Append_To (Args, Make_Identifier (Loc, Name_uChain));
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.
13301 and then Has_Task_Name_Pragma (Tdef)
13303 -- Copy expression in full, because it may be dynamic and have
13309 (Pragma_Argument_Associations
13310 (Find_Task_Or_Protected_Pragma
13311 (Tdef, Name_Task_Name))))));
13314 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
13317 -- Created_Task parameter. This is the _Task_Id field of the task
13321 Make_Selected_Component (Loc,
13322 Prefix => Make_Identifier (Loc, Name_uInit),
13323 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
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.
13328 if not Restricted_Profile then
13329 if Has_Entries (Ttyp)
13330 and then Entry_Names_OK
13332 Append_To (Args, New_Reference_To (Standard_True, Loc));
13334 Append_To (Args, New_Reference_To (Standard_False, Loc));
13338 if Restricted_Profile then
13339 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
13341 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
13345 Make_Procedure_Call_Statement (Loc,
13347 Parameter_Associations => Args);
13348 end Make_Task_Create_Call;
13350 ------------------------------
13351 -- Next_Protected_Operation --
13352 ------------------------------
13354 function Next_Protected_Operation (N : Node_Id) return Node_Id is
13358 Next_Op := Next (N);
13359 while Present (Next_Op)
13360 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
13366 end Next_Protected_Operation;
13368 ---------------------
13369 -- Null_Statements --
13370 ---------------------
13372 function Null_Statements (Stats : List_Id) return Boolean is
13376 Stmt := First (Stats);
13377 while Nkind (Stmt) /= N_Empty
13378 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
13380 (Nkind (Stmt) = N_Pragma
13381 and then (Pragma_Name (Stmt) = Name_Unreferenced
13383 Pragma_Name (Stmt) = Name_Unmodified
13385 Pragma_Name (Stmt) = Name_Warnings)))
13390 return Nkind (Stmt) = N_Empty;
13391 end Null_Statements;
13393 --------------------------
13394 -- Parameter_Block_Pack --
13395 --------------------------
13397 function Parameter_Block_Pack
13399 Blk_Typ : Entity_Id;
13403 Stmts : List_Id) return Node_Id
13405 Actual : Entity_Id;
13406 Expr : Node_Id := Empty;
13407 Formal : Entity_Id;
13408 Has_Param : Boolean := False;
13411 Temp_Asn : Node_Id;
13412 Temp_Nam : Node_Id;
13415 Actual := First (Actuals);
13416 Formal := Defining_Identifier (First (Formals));
13417 Params := New_List;
13419 while Present (Actual) loop
13420 if Is_By_Copy_Type (Etype (Actual)) then
13422 -- Jnn : aliased <formal-type>
13424 Temp_Nam := Make_Temporary (Loc, 'J');
13427 Make_Object_Declaration (Loc,
13430 Defining_Identifier =>
13432 Object_Definition =>
13433 New_Reference_To (Etype (Formal), Loc)));
13435 if Ekind (Formal) /= E_Out_Parameter then
13441 New_Reference_To (Temp_Nam, Loc);
13443 Set_Assignment_OK (Temp_Asn);
13446 Make_Assignment_Statement (Loc,
13450 New_Copy_Tree (Actual)));
13454 -- Jnn'unchecked_access
13457 Make_Attribute_Reference (Loc,
13459 Name_Unchecked_Access,
13461 New_Reference_To (Temp_Nam, Loc)));
13465 -- The controlling parameter is omitted
13468 if not Is_Controlling_Actual (Actual) then
13470 Make_Reference (Loc, New_Copy_Tree (Actual)));
13476 Next_Actual (Actual);
13477 Next_Formal_With_Extras (Formal);
13481 Expr := Make_Aggregate (Loc, Params);
13486 -- J1'unchecked_access;
13487 -- <actual2>'reference;
13490 P := Make_Temporary (Loc, 'P');
13493 Make_Object_Declaration (Loc,
13494 Defining_Identifier =>
13496 Object_Definition =>
13497 New_Reference_To (Blk_Typ, Loc),
13502 end Parameter_Block_Pack;
13504 ----------------------------
13505 -- Parameter_Block_Unpack --
13506 ----------------------------
13508 function Parameter_Block_Unpack
13512 Formals : List_Id) return List_Id
13514 Actual : Entity_Id;
13516 Formal : Entity_Id;
13517 Has_Asnmt : Boolean := False;
13518 Result : constant List_Id := New_List;
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
13528 -- <actual> := P.<formal>;
13531 Make_Assignment_Statement (Loc,
13535 Make_Explicit_Dereference (Loc,
13536 Make_Selected_Component (Loc,
13538 New_Reference_To (P, Loc),
13540 Make_Identifier (Loc, Chars (Formal)))));
13542 Set_Assignment_OK (Name (Asnmt));
13543 Append_To (Result, Asnmt);
13548 Next_Actual (Actual);
13549 Next_Formal_With_Extras (Formal);
13555 return New_List (Make_Null_Statement (Loc));
13557 end Parameter_Block_Unpack;
13559 ----------------------
13560 -- Set_Discriminals --
13561 ----------------------
13563 procedure Set_Discriminals (Dec : Node_Id) is
13566 D_Minal : Entity_Id;
13569 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13570 Pdef := Defining_Identifier (Dec);
13572 if Has_Discriminants (Pdef) then
13573 D := First_Discriminant (Pdef);
13574 while Present (D) loop
13576 Make_Defining_Identifier (Sloc (D),
13577 Chars => New_External_Name (Chars (D), 'D'));
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);
13585 Next_Discriminant (D);
13588 end Set_Discriminals;
13590 -----------------------
13591 -- Trivial_Accept_OK --
13592 -----------------------
13594 function Trivial_Accept_OK return Boolean is
13596 case Opt.Task_Dispatching_Policy is
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.
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.
13616 -- For now, disallow the optimization for all other policies. This
13617 -- may be over-conservative, but it is certainly not incorrect.
13623 end Trivial_Accept_OK;