1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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_Ch11; use Exp_Ch11;
33 with Exp_Ch6; use Exp_Ch6;
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_Res; use Sem_Res;
57 with Sem_Util; use Sem_Util;
58 with Sinfo; use Sinfo;
59 with Snames; use Snames;
60 with Stand; use Stand;
61 with Stringt; use Stringt;
62 with Targparm; use Targparm;
63 with Tbuild; use Tbuild;
64 with Uintp; use Uintp;
66 package body Exp_Ch9 is
68 -- The following constant establishes the upper bound for the index of
69 -- an entry family. It is used to limit the allocated size of protected
70 -- types with defaulted discriminant of an integer type, when the bound
71 -- of some entry family depends on a discriminant. The limitation to
72 -- entry families of 128K should be reasonable in all cases, and is a
73 -- documented implementation restriction. It will be lifted when protected
74 -- entry families are re-implemented as a single ordered queue.
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_Entry_Count_Expression
131 (Concurrent_Type : Node_Id;
132 Component_List : List_Id;
133 Loc : Source_Ptr) return Node_Id;
134 -- Compute number of entries for concurrent object. This is a count of
135 -- simple entries, followed by an expression that computes the length
136 -- of the range of each entry family. A single array with that size is
137 -- allocated for each concurrent object of the type.
139 function Build_Parameter_Block
143 Decls : List_Id) return Entity_Id;
144 -- Generate an access type for each actual parameter in the list Actuals.
145 -- Create an encapsulating record that contains all the actuals and return
146 -- its type. Generate:
147 -- type Ann1 is access all <actual1-type>
149 -- type AnnN is access all <actualN-type>
150 -- type Pnn is record
156 procedure Build_Wrapper_Bodies
160 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
161 -- record of a concurrent type. N is the insertion node where all bodies
162 -- will be placed. This routine builds the bodies of the subprograms which
163 -- serve as an indirection mechanism to overriding primitives of concurrent
164 -- types, entries and protected procedures. Any new body is analyzed.
166 procedure Build_Wrapper_Specs
170 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
171 -- record of a concurrent type. N is the insertion node where all specs
172 -- will be placed. This routine builds the specs of the subprograms which
173 -- serve as an indirection mechanism to overriding primitives of concurrent
174 -- types, entries and protected procedures. Any new spec is analyzed.
176 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
177 -- Build the function that translates the entry index in the call
178 -- (which depends on the size of entry families) into an index into the
179 -- Entry_Bodies_Array, to determine the body and barrier function used
180 -- in a protected entry call. A pointer to this function appears in every
183 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
184 -- Build subprogram declaration for previous one
186 function Build_Protected_Entry
189 Pid : Node_Id) return Node_Id;
190 -- Build the procedure implementing the statement sequence of the specified
193 function Build_Protected_Entry_Specification
196 Ent_Id : Entity_Id) return Node_Id;
197 -- Build a specification for the procedure implementing the statements of
198 -- the specified entry body. Add attributes associating it with the entry
199 -- defining identifier Ent_Id.
201 function Build_Protected_Spec
203 Obj_Type : Entity_Id;
205 Unprotected : Boolean := False) return List_Id;
206 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
207 -- Subprogram_Type. Builds signature of protected subprogram, adding the
208 -- formal that corresponds to the object itself. For an access to protected
209 -- subprogram, there is no object type to specify, so the parameter has
210 -- type Address and mode In. An indirect call through such a pointer will
211 -- convert the address to a reference to the actual object. The object is
212 -- a limited record and therefore a by_reference type.
214 function Build_Protected_Subprogram_Body
217 N_Op_Spec : Node_Id) return Node_Id;
218 -- This function is used to construct the protected version of a protected
219 -- subprogram. Its statement sequence first defers abort, then locks
220 -- the associated protected object, and then enters a block that contains
221 -- a call to the unprotected version of the subprogram (for details, see
222 -- Build_Unprotected_Subprogram_Body). This block statement requires
223 -- a cleanup handler that unlocks the object in all cases.
224 -- (see Exp_Ch7.Expand_Cleanup_Actions).
226 function Build_Selected_Name
228 Selector : Entity_Id;
229 Append_Char : Character := ' ') return Name_Id;
230 -- Build a name in the form of Prefix__Selector, with an optional
231 -- character appended. This is used for internal subprograms generated
232 -- for operations of protected types, including barrier functions.
233 -- For the subprograms generated for entry bodies and entry barriers,
234 -- the generated name includes a sequence number that makes names
235 -- unique in the presence of entry overloading. This is necessary
236 -- because entry body procedures and barrier functions all have the
239 procedure Build_Simple_Entry_Call
244 -- Some comments here would be useful ???
246 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
247 -- This routine constructs a specification for the procedure that we will
248 -- build for the task body for task type T. The spec has the form:
250 -- procedure tnameB (_Task : access tnameV);
252 -- where name is the character name taken from the task type entity that
253 -- is passed as the argument to the procedure, and tnameV is the task
254 -- value type that is associated with the task type.
256 function Build_Unprotected_Subprogram_Body
258 Pid : Node_Id) return Node_Id;
259 -- This routine constructs the unprotected version of a protected
260 -- subprogram body, which is contains all of the code in the
261 -- original, unexpanded body. This is the version of the protected
262 -- subprogram that is called from all protected operations on the same
263 -- object, including the protected version of the same subprogram.
265 procedure Collect_Entry_Families
268 Current_Node : in out Node_Id;
269 Conctyp : Entity_Id);
270 -- For each entry family in a concurrent type, create an anonymous array
271 -- type of the right size, and add a component to the corresponding_record.
273 function Concurrent_Object
274 (Spec_Id : Entity_Id;
275 Conc_Typ : Entity_Id) return Entity_Id;
276 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
277 -- the entity associated with the concurrent object in the Protected_Body_
278 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
279 -- denotes formal parameter _O, _object or _task.
281 function Copy_Result_Type (Res : Node_Id) return Node_Id;
282 -- Copy the result type of a function specification, when building the
283 -- internal operation corresponding to a protected function, or when
284 -- expanding an access to protected function. If the result is an anonymous
285 -- access to subprogram itself, we need to create a new signature with the
286 -- same parameter names and the same resolved types, but with new entities
289 procedure Debug_Private_Data_Declarations (Decls : List_Id);
290 -- Decls is a list which may contain the declarations created by Install_
291 -- Private_Data_Declarations. All generated entities are marked as needing
292 -- debug info and debug nodes are manually generation where necessary. This
293 -- step of the expansion must to be done after private data has been moved
294 -- to its final resting scope to ensure proper visibility of debug objects.
296 function Family_Offset
301 Cap : Boolean) return Node_Id;
302 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
303 -- an accept statement, or the upper bound in the discrete subtype of
304 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
305 -- the concurrent type of the entry. If Cap is true, the result is
306 -- capped according to Entry_Family_Bound.
313 Cap : Boolean) return Node_Id;
314 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
315 -- a family, and handle properly the superflat case. This is equivalent
316 -- to the use of 'Length on the index type, but must use Family_Offset
317 -- to handle properly the case of bounds that depend on discriminants.
318 -- If Cap is true, the result is capped according to Entry_Family_Bound.
320 procedure Extract_Dispatching_Call
322 Call_Ent : out Entity_Id;
323 Object : out Entity_Id;
324 Actuals : out List_Id;
325 Formals : out List_Id);
326 -- Given a dispatching call, extract the entity of the name of the call,
327 -- its object parameter, its actual parameters and the formal parameters
328 -- of the overridden interface-level version.
330 procedure Extract_Entry
332 Concval : out Node_Id;
334 Index : out Node_Id);
335 -- Given an entry call, returns the associated concurrent object,
336 -- the entry name, and the entry family index.
338 function Find_Task_Or_Protected_Pragma
340 P : Name_Id) return Node_Id;
341 -- Searches the task or protected definition T for the first occurrence
342 -- of the pragma whose name is given by P. The caller has ensured that
343 -- the pragma is present in the task definition. A special case is that
344 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
345 -- ??? Should be implemented with the rep item chain mechanism.
347 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
348 -- Given a subprogram identifier, return the entity which is associated
349 -- with the protection entry index in the Protected_Body_Subprogram or the
350 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
353 function Is_Potentially_Large_Family
354 (Base_Index : Entity_Id;
357 Hi : Node_Id) return Boolean;
359 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
360 -- Determine whether Id is a function or a procedure and is marked as a
361 -- private primitive.
363 function Null_Statements (Stats : List_Id) return Boolean;
364 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
365 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
366 -- well to still count as null. Returns True for a null sequence. The
367 -- argument is the list of statements from the DO-END sequence.
369 function Parameter_Block_Pack
375 Stmts : List_Id) return Entity_Id;
376 -- Set the components of the generated parameter block with the values of
377 -- the actual parameters. Generate aliased temporaries to capture the
378 -- values for types that are passed by copy. Otherwise generate a reference
379 -- to the actual's value. Return the address of the aggregate block.
381 -- Jnn1 : alias <formal-type1>;
382 -- Jnn1 := <actual1>;
385 -- Jnn1'unchecked_access;
386 -- <actual2>'reference;
389 function Parameter_Block_Unpack
393 Formals : List_Id) return List_Id;
394 -- Retrieve the values of the components from the parameter block and
395 -- assign then to the original actual parameters. Generate:
396 -- <actual1> := P.<formal1>;
398 -- <actualN> := P.<formalN>;
400 function Trivial_Accept_OK return Boolean;
401 -- If there is no DO-END block for an accept, or if the DO-END block has
402 -- only null statements, then it is possible to do the Rendezvous with much
403 -- less overhead using the Accept_Trivial routine in the run-time library.
404 -- However, this is not always a valid optimization. Whether it is valid or
405 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
406 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
407 -- a rescheduling is required, so this optimization is not allowed. This
408 -- function returns True if the optimization is permitted.
410 -----------------------------
411 -- Actual_Index_Expression --
412 -----------------------------
414 function Actual_Index_Expression
418 Tsk : Entity_Id) return Node_Id
420 Ttyp : constant Entity_Id := Etype (Tsk);
428 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
429 -- Compute difference between bounds of entry family
431 --------------------------
432 -- Actual_Family_Offset --
433 --------------------------
435 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
437 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
438 -- Replace a reference to a discriminant with a selected component
439 -- denoting the discriminant of the target task.
441 -----------------------------
442 -- Actual_Discriminant_Ref --
443 -----------------------------
445 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
446 Typ : constant Entity_Id := Etype (Bound);
450 if not Is_Entity_Name (Bound)
451 or else Ekind (Entity (Bound)) /= E_Discriminant
453 if Nkind (Bound) = N_Attribute_Reference then
456 B := New_Copy_Tree (Bound);
461 Make_Selected_Component (Sloc,
462 Prefix => New_Copy_Tree (Tsk),
463 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
465 Analyze_And_Resolve (B, Typ);
469 Make_Attribute_Reference (Sloc,
470 Attribute_Name => Name_Pos,
471 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
472 Expressions => New_List (B));
473 end Actual_Discriminant_Ref;
475 -- Start of processing for Actual_Family_Offset
479 Make_Op_Subtract (Sloc,
480 Left_Opnd => Actual_Discriminant_Ref (Hi),
481 Right_Opnd => Actual_Discriminant_Ref (Lo));
482 end Actual_Family_Offset;
484 -- Start of processing for Actual_Index_Expression
487 -- The queues of entries and entry families appear in textual order in
488 -- the associated record. The entry index is computed as the sum of the
489 -- number of queues for all entries that precede the designated one, to
490 -- which is added the index expression, if this expression denotes a
491 -- member of a family.
493 -- The following is a place holder for the count of simple entries
495 Num := Make_Integer_Literal (Sloc, 1);
497 -- We construct an expression which is a series of addition operations.
498 -- See comments in Entry_Index_Expression, which is identical in
501 if Present (Index) then
502 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
509 Actual_Family_Offset (
510 Make_Attribute_Reference (Sloc,
511 Attribute_Name => Name_Pos,
512 Prefix => New_Reference_To (Base_Type (S), Sloc),
513 Expressions => New_List (Relocate_Node (Index))),
514 Type_Low_Bound (S)));
519 -- Now add lengths of preceding entries and entry families
521 Prev := First_Entity (Ttyp);
523 while Chars (Prev) /= Chars (Ent)
524 or else (Ekind (Prev) /= Ekind (Ent))
525 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
527 if Ekind (Prev) = E_Entry then
528 Set_Intval (Num, Intval (Num) + 1);
530 elsif Ekind (Prev) = E_Entry_Family then
532 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
534 -- The need for the following full view retrieval stems from
535 -- this complex case of nested generics and tasking:
538 -- type Formal_Index is range <>;
541 -- type Index is private;
548 -- type Index is new Formal_Index range 1 .. 10;
551 -- package body Outer is
553 -- entry Fam (Index); -- (2)
556 -- package body Inner is -- (3)
564 -- We are currently building the index expression for the entry
565 -- call "T.E" (1). Part of the expansion must mention the range
566 -- of the discrete type "Index" (2) of entry family "Fam".
567 -- However only the private view of type "Index" is available to
568 -- the inner generic (3) because there was no prior mention of
569 -- the type inside "Inner". This visibility requirement is
570 -- implicit and cannot be detected during the construction of
571 -- the generic trees and needs special handling.
574 and then Is_Private_Type (S)
575 and then Present (Full_View (S))
580 Lo := Type_Low_Bound (S);
581 Hi := Type_High_Bound (S);
589 Actual_Family_Offset (Hi, Lo),
591 Make_Integer_Literal (Sloc, 1)));
593 -- Other components are anonymous types to be ignored
603 end Actual_Index_Expression;
605 --------------------------
606 -- Add_Formal_Renamings --
607 --------------------------
609 procedure Add_Formal_Renamings
615 Ptr : constant Entity_Id :=
617 (Next (First (Parameter_Specifications (Spec))));
618 -- The name of the formal that holds the address of the parameter block
627 Formal := First_Formal (Ent);
628 while Present (Formal) loop
629 Comp := Entry_Component (Formal);
631 Make_Defining_Identifier (Sloc (Formal),
632 Chars => Chars (Formal));
633 Set_Etype (New_F, Etype (Formal));
634 Set_Scope (New_F, Ent);
636 -- Now we set debug info needed on New_F even though it does not
637 -- come from source, so that the debugger will get the right
638 -- information for these generated names.
640 Set_Debug_Info_Needed (New_F);
642 if Ekind (Formal) = E_In_Parameter then
643 Set_Ekind (New_F, E_Constant);
645 Set_Ekind (New_F, E_Variable);
646 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
649 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
652 Make_Object_Renaming_Declaration (Loc,
653 Defining_Identifier => New_F,
655 New_Reference_To (Etype (Formal), Loc),
657 Make_Explicit_Dereference (Loc,
658 Make_Selected_Component (Loc,
660 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
661 Make_Identifier (Loc, Chars (Ptr))),
663 New_Reference_To (Comp, Loc))));
665 Append (Decl, Decls);
666 Set_Renamed_Object (Formal, New_F);
667 Next_Formal (Formal);
669 end Add_Formal_Renamings;
671 ------------------------
672 -- Add_Object_Pointer --
673 ------------------------
675 procedure Add_Object_Pointer
677 Conc_Typ : Entity_Id;
680 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
685 -- Create the renaming declaration for the Protection object of a
686 -- protected type. _Object is used by Complete_Entry_Body.
687 -- ??? An attempt to make this a renaming was unsuccessful.
689 -- Build the entity for the access type
692 Make_Defining_Identifier (Loc,
693 New_External_Name (Chars (Rec_Typ), 'P'));
696 -- _object : poVP := poVP!O;
699 Make_Object_Declaration (Loc,
700 Defining_Identifier =>
701 Make_Defining_Identifier (Loc, Name_uObject),
703 New_Reference_To (Obj_Ptr, Loc),
705 Unchecked_Convert_To (Obj_Ptr,
706 Make_Identifier (Loc, Name_uO)));
707 Set_Debug_Info_Needed (Defining_Identifier (Decl));
708 Prepend_To (Decls, Decl);
711 -- type poVP is access poV;
714 Make_Full_Type_Declaration (Loc,
715 Defining_Identifier =>
718 Make_Access_To_Object_Definition (Loc,
719 Subtype_Indication =>
720 New_Reference_To (Rec_Typ, Loc)));
721 Set_Debug_Info_Needed (Defining_Identifier (Decl));
722 Prepend_To (Decls, Decl);
723 end Add_Object_Pointer;
725 -----------------------
726 -- Build_Accept_Body --
727 -----------------------
729 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
730 Loc : constant Source_Ptr := Sloc (Astat);
731 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
738 -- At the end of the statement sequence, Complete_Rendezvous is called.
739 -- A label skipping the Complete_Rendezvous, and all other accept
740 -- processing, has already been added for the expansion of requeue
741 -- statements. The Sloc is copied from the last statement since it
742 -- is really part of this last statement.
746 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
747 Insert_Before (Last (Statements (Stats)), Call);
750 -- If exception handlers are present, then append Complete_Rendezvous
751 -- calls to the handlers, and construct the required outer block. As
752 -- above, the Sloc is copied from the last statement in the sequence.
754 if Present (Exception_Handlers (Stats)) then
755 Hand := First (Exception_Handlers (Stats));
756 while Present (Hand) loop
759 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
760 Append (Call, Statements (Hand));
766 Make_Handled_Sequence_Of_Statements (Loc,
767 Statements => New_List (
768 Make_Block_Statement (Loc,
769 Handled_Statement_Sequence => Stats)));
775 -- At this stage we know that the new statement sequence does not
776 -- have an exception handler part, so we supply one to call
777 -- Exceptional_Complete_Rendezvous. This handler is
779 -- when all others =>
780 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
782 -- We handle Abort_Signal to make sure that we properly catch the abort
783 -- case and wake up the caller.
785 Ohandle := Make_Others_Choice (Loc);
786 Set_All_Others (Ohandle);
788 Set_Exception_Handlers (New_S,
790 Make_Implicit_Exception_Handler (Loc,
791 Exception_Choices => New_List (Ohandle),
793 Statements => New_List (
794 Make_Procedure_Call_Statement (Sloc (Stats),
795 Name => New_Reference_To (
796 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
797 Parameter_Associations => New_List (
798 Make_Function_Call (Sloc (Stats),
799 Name => New_Reference_To (
800 RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
802 Set_Parent (New_S, Astat); -- temp parent for Analyze call
803 Analyze_Exception_Handlers (Exception_Handlers (New_S));
804 Expand_Exception_Handlers (New_S);
806 -- Exceptional_Complete_Rendezvous must be called with abort
807 -- still deferred, which is the case for a "when all others" handler.
810 end Build_Accept_Body;
812 -----------------------------------
813 -- Build_Activation_Chain_Entity --
814 -----------------------------------
816 procedure Build_Activation_Chain_Entity (N : Node_Id) is
822 -- Loop to find enclosing construct containing activation chain variable
826 while not Nkind_In (P, N_Subprogram_Body,
827 N_Package_Declaration,
831 N_Extended_Return_Statement)
836 -- If we are in a package body, the activation chain variable is
837 -- declared in the body, but the Activation_Chain_Entity is attached to
840 if Nkind (P) = N_Package_Body then
841 Decls := Declarations (P);
842 P := Unit_Declaration_Node (Corresponding_Spec (P));
844 elsif Nkind (P) = N_Package_Declaration then
845 Decls := Visible_Declarations (Specification (P));
847 elsif Nkind (P) = N_Extended_Return_Statement then
848 Decls := Return_Object_Declarations (P);
851 Decls := Declarations (P);
854 -- If activation chain entity not already declared, declare it
856 if Nkind (P) = N_Extended_Return_Statement
857 or else No (Activation_Chain_Entity (P))
859 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
861 -- Note: An extended return statement is not really a task activator,
862 -- but it does have an activation chain on which to store the tasks
863 -- temporarily. On successful return, the tasks on this chain are
864 -- moved to the chain passed in by the caller. We do not build an
865 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
866 -- because we do not want to build a call to Activate_Tasks. Task
867 -- activation is the responsibility of the caller.
869 if Nkind (P) /= N_Extended_Return_Statement then
870 Set_Activation_Chain_Entity (P, Chain);
874 Make_Object_Declaration (Sloc (P),
875 Defining_Identifier => Chain,
876 Aliased_Present => True,
878 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
880 Analyze (First (Decls));
882 end Build_Activation_Chain_Entity;
884 ----------------------------
885 -- Build_Barrier_Function --
886 ----------------------------
888 function Build_Barrier_Function
891 Pid : Node_Id) return Node_Id
893 Loc : constant Source_Ptr := Sloc (N);
894 Func_Id : constant Entity_Id := Barrier_Function (Ent);
895 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
896 Op_Decls : constant List_Id := New_List;
900 -- Add a declaration for the Protection object, renaming declarations
901 -- for the discriminals and privals and finally a declaration for the
902 -- entry family index (if applicable).
904 Install_Private_Data_Declarations
905 (Loc, Func_Id, Pid, N, Op_Decls, True, Ekind (Ent) = E_Entry_Family);
907 -- Note: the condition in the barrier function needs to be properly
908 -- processed for the C/Fortran boolean possibility, but this happens
909 -- automatically since the return statement does this normalization.
912 Make_Subprogram_Body (Loc,
914 Build_Barrier_Function_Specification (Loc,
915 Make_Defining_Identifier (Loc, Chars (Func_Id))),
916 Declarations => Op_Decls,
917 Handled_Statement_Sequence =>
918 Make_Handled_Sequence_Of_Statements (Loc,
919 Statements => New_List (
920 Make_Simple_Return_Statement (Loc,
921 Expression => Condition (Ent_Formals)))));
922 Set_Is_Entry_Barrier_Function (Func_Body);
925 end Build_Barrier_Function;
927 ------------------------------------------
928 -- Build_Barrier_Function_Specification --
929 ------------------------------------------
931 function Build_Barrier_Function_Specification
933 Def_Id : Entity_Id) return Node_Id
936 Set_Debug_Info_Needed (Def_Id);
938 return Make_Function_Specification (Loc,
939 Defining_Unit_Name => Def_Id,
940 Parameter_Specifications => New_List (
941 Make_Parameter_Specification (Loc,
942 Defining_Identifier =>
943 Make_Defining_Identifier (Loc, Name_uO),
945 New_Reference_To (RTE (RE_Address), Loc)),
947 Make_Parameter_Specification (Loc,
948 Defining_Identifier =>
949 Make_Defining_Identifier (Loc, Name_uE),
951 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
954 New_Reference_To (Standard_Boolean, Loc));
955 end Build_Barrier_Function_Specification;
957 --------------------------
958 -- Build_Call_With_Task --
959 --------------------------
961 function Build_Call_With_Task
963 E : Entity_Id) return Node_Id
965 Loc : constant Source_Ptr := Sloc (N);
968 Make_Function_Call (Loc,
969 Name => New_Reference_To (E, Loc),
970 Parameter_Associations => New_List (Concurrent_Ref (N)));
971 end Build_Call_With_Task;
973 --------------------------------
974 -- Build_Corresponding_Record --
975 --------------------------------
977 function Build_Corresponding_Record
980 Loc : Source_Ptr) return Node_Id
982 Rec_Ent : constant Entity_Id :=
983 Make_Defining_Identifier
984 (Loc, New_External_Name (Chars (Ctyp), 'V'));
987 New_Disc : Entity_Id;
991 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
992 Set_Ekind (Rec_Ent, E_Record_Type);
993 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
994 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
995 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
996 Set_Stored_Constraint (Rec_Ent, No_Elist);
999 -- Use discriminals to create list of discriminants for record, and
1000 -- create new discriminals for use in default expressions, etc. It is
1001 -- worth noting that a task discriminant gives rise to 5 entities;
1003 -- a) The original discriminant.
1004 -- b) The discriminal for use in the task.
1005 -- c) The discriminant of the corresponding record.
1006 -- d) The discriminal for the init proc of the corresponding record.
1007 -- e) The local variable that renames the discriminant in the procedure
1008 -- for the task body.
1010 -- In fact the discriminals b) are used in the renaming declarations
1011 -- for e). See details in einfo (Handling of Discriminants).
1013 if Present (Discriminant_Specifications (N)) then
1015 Disc := First_Discriminant (Ctyp);
1017 while Present (Disc) loop
1018 New_Disc := CR_Discriminant (Disc);
1021 Make_Discriminant_Specification (Loc,
1022 Defining_Identifier => New_Disc,
1023 Discriminant_Type =>
1024 New_Occurrence_Of (Etype (Disc), Loc),
1026 New_Copy (Discriminant_Default_Value (Disc))));
1028 Next_Discriminant (Disc);
1035 -- Now we can construct the record type declaration. Note that this
1036 -- record is "limited tagged". It is "limited" to reflect the underlying
1037 -- limitedness of the task or protected object that it represents, and
1038 -- ensuring for example that it is properly passed by reference. It is
1039 -- "tagged" to give support to dispatching calls through interfaces (Ada
1043 Make_Full_Type_Declaration (Loc,
1044 Defining_Identifier => Rec_Ent,
1045 Discriminant_Specifications => Dlist,
1047 Make_Record_Definition (Loc,
1049 Make_Component_List (Loc,
1050 Component_Items => Cdecls),
1052 Ada_Version >= Ada_05 and then Is_Tagged_Type (Ctyp),
1053 Limited_Present => True));
1054 end Build_Corresponding_Record;
1056 ----------------------------------
1057 -- Build_Entry_Count_Expression --
1058 ----------------------------------
1060 function Build_Entry_Count_Expression
1061 (Concurrent_Type : Node_Id;
1062 Component_List : List_Id;
1063 Loc : Source_Ptr) return Node_Id
1075 -- Count number of non-family entries
1078 Ent := First_Entity (Concurrent_Type);
1079 while Present (Ent) loop
1080 if Ekind (Ent) = E_Entry then
1087 Ecount := Make_Integer_Literal (Loc, Eindx);
1089 -- Loop through entry families building the addition nodes
1091 Ent := First_Entity (Concurrent_Type);
1092 Comp := First (Component_List);
1093 while Present (Ent) loop
1094 if Ekind (Ent) = E_Entry_Family then
1095 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1099 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1100 Hi := Type_High_Bound (Typ);
1101 Lo := Type_Low_Bound (Typ);
1102 Large := Is_Potentially_Large_Family
1103 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1106 Left_Opnd => Ecount,
1107 Right_Opnd => Family_Size
1108 (Loc, Hi, Lo, Concurrent_Type, Large));
1115 end Build_Entry_Count_Expression;
1117 -----------------------
1118 -- Build_Entry_Names --
1119 -----------------------
1121 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1122 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1128 Typ : Entity_Id := Conc_Typ;
1130 procedure Build_Entry_Family_Name (Id : Entity_Id);
1132 -- for Lnn in Family_Low .. Family_High loop
1135 -- (_init._object <or> _init._task_id,
1137 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1139 -- Note that the bounds of the range may reference discriminants. The
1140 -- above construct is added directly to the statements of the block.
1142 procedure Build_Entry_Name (Id : Entity_Id);
1146 -- (_init._object <or>_init._task_id,
1148 -- new String ("<Entry name>");
1149 -- The above construct is added directly to the statements of the block.
1151 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1152 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1153 -- _init._task_id or _init._object, Inn and Arg3.
1155 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id;
1156 -- Given a protected type or its corresponding record, find the type of
1159 procedure Increment_Index (Stmts : List_Id);
1160 -- Generate the following and add it to Stmts
1163 -----------------------------
1164 -- Build_Entry_Family_Name --
1165 -----------------------------
1167 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1168 Def : constant Node_Id :=
1169 Discrete_Subtype_Definition (Parent (Id));
1170 L_Id : constant Entity_Id :=
1171 Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
1172 L_Stmts : constant List_Id := New_List;
1175 function Build_Range (Def : Node_Id) return Node_Id;
1176 -- Given a discrete subtype definition of an entry family, generate a
1177 -- range node which covers the range of Def's type.
1183 function Build_Range (Def : Node_Id) return Node_Id is
1184 High : Node_Id := Type_High_Bound (Etype (Def));
1185 Low : Node_Id := Type_Low_Bound (Etype (Def));
1188 -- If a bound references a discriminant, generate an identifier
1189 -- with the same name. Resolution will map it to the formals of
1192 if Is_Entity_Name (Low)
1193 and then Ekind (Entity (Low)) = E_Discriminant
1195 Low := Make_Identifier (Loc, Chars (Low));
1197 Low := New_Copy_Tree (Low);
1200 if Is_Entity_Name (High)
1201 and then Ekind (Entity (High)) = E_Discriminant
1203 High := Make_Identifier (Loc, Chars (High));
1205 High := New_Copy_Tree (High);
1211 High_Bound => High);
1214 -- Start of processing for Build_Entry_Family_Name
1217 Get_Name_String (Chars (Id));
1219 -- Add a leading '('
1221 Add_Char_To_Name_Buffer ('(');
1224 -- new String'("<Entry name>(" & Lnn'Img & ")");
1226 -- This is an implicit heap allocation, and Comes_From_Source is
1227 -- False, which ensures that it will get flagged as a violation of
1228 -- No_Implicit_Heap_Allocations when that restriction applies.
1231 Make_Allocator (Loc,
1232 Make_Qualified_Expression (Loc,
1234 New_Reference_To (Standard_String, Loc),
1236 Make_Op_Concat (Loc,
1238 Make_Op_Concat (Loc,
1240 Make_String_Literal (Loc,
1241 Strval => String_From_Name_Buffer),
1243 Make_Attribute_Reference (Loc,
1245 New_Reference_To (L_Id, Loc),
1246 Attribute_Name => Name_Img)),
1248 Make_String_Literal (Loc,
1251 Increment_Index (L_Stmts);
1252 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1255 -- for Lnn in Family_Low .. Family_High loop
1258 -- (_init._object <or> _init._task_id, Inn, <Val>);
1262 Make_Loop_Statement (Loc,
1264 Make_Iteration_Scheme (Loc,
1265 Loop_Parameter_Specification =>
1266 Make_Loop_Parameter_Specification (Loc,
1267 Defining_Identifier => L_Id,
1268 Discrete_Subtype_Definition =>
1269 Build_Range (Def))),
1270 Statements => L_Stmts,
1271 End_Label => Empty));
1272 end Build_Entry_Family_Name;
1274 ----------------------
1275 -- Build_Entry_Name --
1276 ----------------------
1278 procedure Build_Entry_Name (Id : Entity_Id) is
1282 Get_Name_String (Chars (Id));
1284 -- This is an implicit heap allocation, and Comes_From_Source is
1285 -- False, which ensures that it will get flagged as a violation of
1286 -- No_Implicit_Heap_Allocations when that restriction applies.
1289 Make_Allocator (Loc,
1290 Make_Qualified_Expression (Loc,
1292 New_Reference_To (Standard_String, Loc),
1294 Make_String_Literal (Loc,
1295 String_From_Name_Buffer)));
1297 Increment_Index (B_Stmts);
1298 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1299 end Build_Entry_Name;
1301 -------------------------------
1302 -- Build_Set_Entry_Name_Call --
1303 -------------------------------
1305 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1310 -- Determine the proper name for the first argument and the RTS
1313 if Is_Protected_Type (Typ) then
1314 Arg1 := Name_uObject;
1315 Proc := RO_PE_Set_Entry_Name;
1317 else pragma Assert (Is_Task_Type (Typ));
1318 Arg1 := Name_uTask_Id;
1319 Proc := RO_TS_Set_Entry_Name;
1323 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1326 Make_Procedure_Call_Statement (Loc,
1328 New_Reference_To (RTE (Proc), Loc),
1329 Parameter_Associations => New_List (
1330 Make_Selected_Component (Loc, -- _init._object
1331 Prefix => -- _init._task_id
1332 Make_Identifier (Loc, Name_uInit),
1334 Make_Identifier (Loc, Arg1)),
1335 New_Reference_To (Index, Loc), -- Inn
1337 end Build_Set_Entry_Name_Call;
1339 --------------------------
1340 -- Find_Protection_Type --
1341 --------------------------
1343 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
1345 Typ : Entity_Id := Conc_Typ;
1348 if Is_Concurrent_Type (Typ) then
1349 Typ := Corresponding_Record_Type (Typ);
1352 Comp := First_Component (Typ);
1353 while Present (Comp) loop
1354 if Chars (Comp) = Name_uObject then
1355 return Base_Type (Etype (Comp));
1358 Next_Component (Comp);
1361 -- The corresponding record of a protected type should always have an
1364 raise Program_Error;
1365 end Find_Protection_Type;
1367 ---------------------
1368 -- Increment_Index --
1369 ---------------------
1371 procedure Increment_Index (Stmts : List_Id) is
1377 Make_Assignment_Statement (Loc,
1379 New_Reference_To (Index, Loc),
1383 New_Reference_To (Index, Loc),
1385 Make_Integer_Literal (Loc, 1))));
1386 end Increment_Index;
1388 -- Start of processing for Build_Entry_Names
1391 -- Retrieve the original concurrent type
1393 if Is_Concurrent_Record_Type (Typ) then
1394 Typ := Corresponding_Concurrent_Type (Typ);
1397 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1399 -- Nothing to do if the type has no entries
1401 if not Has_Entries (Typ) then
1405 -- Avoid generating entry names for a protected type with only one entry
1407 if Is_Protected_Type (Typ)
1408 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1413 Index := Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
1415 -- Step 1: Generate the declaration of the index variable:
1416 -- Inn : Protected_Entry_Index := 0;
1418 -- Inn : Task_Entry_Index := 0;
1420 if Is_Protected_Type (Typ) then
1421 Index_Typ := RE_Protected_Entry_Index;
1423 Index_Typ := RE_Task_Entry_Index;
1426 B_Decls := New_List;
1428 Make_Object_Declaration (Loc,
1429 Defining_Identifier => Index,
1430 Object_Definition =>
1431 New_Reference_To (RTE (Index_Typ), Loc),
1433 Make_Integer_Literal (Loc, 0)));
1435 B_Stmts := New_List;
1437 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1440 Comp := First_Entity (Typ);
1441 while Present (Comp) loop
1442 if Ekind (Comp) = E_Entry then
1443 Build_Entry_Name (Comp);
1445 elsif Ekind (Comp) = E_Entry_Family then
1446 Build_Entry_Family_Name (Comp);
1452 -- Step 3: Wrap the statements in a block
1455 Make_Block_Statement (Loc,
1456 Declarations => B_Decls,
1457 Handled_Statement_Sequence =>
1458 Make_Handled_Sequence_Of_Statements (Loc,
1459 Statements => B_Stmts));
1460 end Build_Entry_Names;
1462 ---------------------------
1463 -- Build_Parameter_Block --
1464 ---------------------------
1466 function Build_Parameter_Block
1470 Decls : List_Id) return Entity_Id
1476 Has_Comp : Boolean := False;
1480 Actual := First (Actuals);
1482 Formal := Defining_Identifier (First (Formals));
1484 while Present (Actual) loop
1485 if not Is_Controlling_Actual (Actual) then
1488 -- type Ann is access all <actual-type>
1491 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
1494 Make_Full_Type_Declaration (Loc,
1495 Defining_Identifier =>
1498 Make_Access_To_Object_Definition (Loc,
1502 Ekind (Formal) = E_In_Parameter,
1503 Subtype_Indication =>
1504 New_Reference_To (Etype (Actual), Loc))));
1510 Make_Component_Declaration (Loc,
1511 Defining_Identifier =>
1512 Make_Defining_Identifier (Loc, Chars (Formal)),
1513 Component_Definition =>
1514 Make_Component_Definition (Loc,
1517 Subtype_Indication =>
1518 New_Reference_To (Comp_Nam, Loc))));
1523 Next_Actual (Actual);
1524 Next_Formal_With_Extras (Formal);
1528 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
1533 -- type Pnn is record
1538 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1539 -- the original parameter names and Ann1 .. AnnN are the access to
1543 Make_Full_Type_Declaration (Loc,
1544 Defining_Identifier =>
1547 Make_Record_Definition (Loc,
1549 Make_Component_List (Loc, Comps))));
1552 -- type Pnn is null record;
1555 Make_Full_Type_Declaration (Loc,
1556 Defining_Identifier =>
1559 Make_Record_Definition (Loc,
1560 Null_Present => True,
1561 Component_List => Empty)));
1565 end Build_Parameter_Block;
1567 --------------------------
1568 -- Build_Wrapper_Bodies --
1569 --------------------------
1571 procedure Build_Wrapper_Bodies
1576 Rec_Typ : Entity_Id;
1578 function Build_Wrapper_Body
1580 Subp_Id : Entity_Id;
1581 Obj_Typ : Entity_Id;
1582 Formals : List_Id) return Node_Id;
1583 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1584 -- associated with a protected or task type. Subp_Id is the subprogram
1585 -- name which will be wrapped. Obj_Typ is the type of the new formal
1586 -- parameter which handles dispatching and object notation. Formals are
1587 -- the original formals of Subp_Id which will be explicitly replicated.
1589 ------------------------
1590 -- Build_Wrapper_Body --
1591 ------------------------
1593 function Build_Wrapper_Body
1595 Subp_Id : Entity_Id;
1596 Obj_Typ : Entity_Id;
1597 Formals : List_Id) return Node_Id
1599 Body_Spec : Node_Id;
1602 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1604 -- The subprogram is not overriding or is not a primitive declared
1605 -- between two views.
1607 if No (Body_Spec) then
1612 Actuals : List_Id := No_List;
1614 First_Formal : Node_Id;
1619 -- Map formals to actuals. Use the list built for the wrapper
1620 -- spec, skipping the object notation parameter.
1622 First_Formal := First (Parameter_Specifications (Body_Spec));
1624 Formal := First_Formal;
1627 if Present (Formal) then
1628 Actuals := New_List;
1630 while Present (Formal) loop
1632 Make_Identifier (Loc, Chars =>
1633 Chars (Defining_Identifier (Formal))));
1639 -- Special processing for primitives declared between a private
1640 -- type and its completion.
1642 if Is_Private_Primitive_Subprogram (Subp_Id) then
1643 if No (Actuals) then
1644 Actuals := New_List;
1647 Prepend_To (Actuals,
1648 Unchecked_Convert_To (
1649 Corresponding_Concurrent_Type (Obj_Typ),
1650 Make_Identifier (Loc, Name_uO)));
1652 Nam := New_Reference_To (Subp_Id, Loc);
1655 -- An access-to-variable object parameter requires an explicit
1656 -- dereference in the unchecked conversion. This case occurs
1657 -- when a protected entry wrapper must override an interface
1658 -- level procedure with interface access as first parameter.
1660 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1662 if Nkind (Parameter_Type (First_Formal)) =
1666 Make_Explicit_Dereference (Loc,
1667 Prefix => Make_Identifier (Loc, Name_uO));
1669 Conv_Id := Make_Identifier (Loc, Name_uO);
1673 Make_Selected_Component (Loc,
1675 Unchecked_Convert_To (
1676 Corresponding_Concurrent_Type (Obj_Typ),
1679 New_Reference_To (Subp_Id, Loc));
1682 -- Create the subprogram body
1684 if Ekind (Subp_Id) = E_Function then
1686 Make_Subprogram_Body (Loc,
1687 Specification => Body_Spec,
1688 Declarations => Empty_List,
1689 Handled_Statement_Sequence =>
1690 Make_Handled_Sequence_Of_Statements (Loc,
1691 Statements => New_List (
1692 Make_Simple_Return_Statement (Loc,
1693 Make_Function_Call (Loc,
1695 Parameter_Associations => Actuals)))));
1699 Make_Subprogram_Body (Loc,
1700 Specification => Body_Spec,
1701 Declarations => Empty_List,
1702 Handled_Statement_Sequence =>
1703 Make_Handled_Sequence_Of_Statements (Loc,
1704 Statements => New_List (
1705 Make_Procedure_Call_Statement (Loc,
1707 Parameter_Associations => Actuals))));
1710 end Build_Wrapper_Body;
1712 -- Start of processing for Build_Wrapper_Bodies
1715 if Is_Concurrent_Type (Typ) then
1716 Rec_Typ := Corresponding_Record_Type (Typ);
1721 -- Generate wrapper bodies for a concurrent type which implements an
1724 if Present (Interfaces (Rec_Typ)) then
1726 Insert_Nod : Node_Id;
1728 Prim_Elmt : Elmt_Id;
1729 Prim_Decl : Node_Id;
1731 Wrap_Body : Node_Id;
1732 Wrap_Id : Entity_Id;
1737 -- Examine all primitive operations of the corresponding record
1738 -- type, looking for wrapper specs. Generate bodies in order to
1741 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1742 while Present (Prim_Elmt) loop
1743 Prim := Node (Prim_Elmt);
1745 if (Ekind (Prim) = E_Function
1746 or else Ekind (Prim) = E_Procedure)
1747 and then Is_Primitive_Wrapper (Prim)
1749 Subp := Wrapped_Entity (Prim);
1750 Prim_Decl := Parent (Parent (Prim));
1753 Build_Wrapper_Body (Loc,
1756 Formals => Parameter_Specifications (Parent (Subp)));
1757 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
1759 Set_Corresponding_Spec (Wrap_Body, Prim);
1760 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
1762 Insert_After (Insert_Nod, Wrap_Body);
1763 Insert_Nod := Wrap_Body;
1765 Analyze (Wrap_Body);
1768 Next_Elmt (Prim_Elmt);
1772 end Build_Wrapper_Bodies;
1774 ------------------------
1775 -- Build_Wrapper_Spec --
1776 ------------------------
1778 function Build_Wrapper_Spec
1779 (Subp_Id : Entity_Id;
1780 Obj_Typ : Entity_Id;
1781 Formals : List_Id) return Node_Id
1783 Loc : constant Source_Ptr := Sloc (Subp_Id);
1784 First_Param : Node_Id;
1786 Iface_Elmt : Elmt_Id;
1787 Iface_Op : Entity_Id;
1788 Iface_Op_Elmt : Elmt_Id;
1790 function Overriding_Possible
1791 (Iface_Op : Entity_Id;
1792 Wrapper : Entity_Id) return Boolean;
1793 -- Determine whether a primitive operation can be overridden by Wrapper.
1794 -- Iface_Op is the candidate primitive operation of an interface type,
1795 -- Wrapper is the generated entry wrapper.
1797 function Replicate_Formals
1799 Formals : List_Id) return List_Id;
1800 -- An explicit parameter replication is required due to the Is_Entry_
1801 -- Formal flag being set for all the formals of an entry. The explicit
1802 -- replication removes the flag that would otherwise cause a different
1803 -- path of analysis.
1805 -------------------------
1806 -- Overriding_Possible --
1807 -------------------------
1809 function Overriding_Possible
1810 (Iface_Op : Entity_Id;
1811 Wrapper : Entity_Id) return Boolean
1813 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
1814 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
1816 function Type_Conformant_Parameters
1817 (Iface_Op_Params : List_Id;
1818 Wrapper_Params : List_Id) return Boolean;
1819 -- Determine whether the parameters of the generated entry wrapper
1820 -- and those of a primitive operation are type conformant. During
1821 -- this check, the first parameter of the primitive operation is
1824 --------------------------------
1825 -- Type_Conformant_Parameters --
1826 --------------------------------
1828 function Type_Conformant_Parameters
1829 (Iface_Op_Params : List_Id;
1830 Wrapper_Params : List_Id) return Boolean
1832 Iface_Op_Param : Node_Id;
1833 Iface_Op_Typ : Entity_Id;
1834 Wrapper_Param : Node_Id;
1835 Wrapper_Typ : Entity_Id;
1838 -- Skip the first parameter of the primitive operation
1840 Iface_Op_Param := Next (First (Iface_Op_Params));
1841 Wrapper_Param := First (Wrapper_Params);
1842 while Present (Iface_Op_Param)
1843 and then Present (Wrapper_Param)
1845 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
1846 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
1848 -- The two parameters must be mode conformant
1850 if not Conforming_Types
1851 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
1856 Next (Iface_Op_Param);
1857 Next (Wrapper_Param);
1860 -- One of the lists is longer than the other
1862 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
1867 end Type_Conformant_Parameters;
1869 -- Start of processing for Overriding_Possible
1872 if Chars (Iface_Op) /= Chars (Wrapper) then
1876 -- If an inherited subprogram is implemented by a protected procedure
1877 -- or an entry, then the first parameter of the inherited subprogram
1878 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
1880 if Ekind (Iface_Op) = E_Procedure
1881 and then Present (Parameter_Specifications (Iface_Op_Spec))
1884 Obj_Param : constant Node_Id :=
1885 First (Parameter_Specifications (Iface_Op_Spec));
1887 if not Out_Present (Obj_Param)
1888 and then Nkind (Parameter_Type (Obj_Param)) /=
1897 Type_Conformant_Parameters (
1898 Parameter_Specifications (Iface_Op_Spec),
1899 Parameter_Specifications (Wrapper_Spec));
1900 end Overriding_Possible;
1902 -----------------------
1903 -- Replicate_Formals --
1904 -----------------------
1906 function Replicate_Formals
1908 Formals : List_Id) return List_Id
1910 New_Formals : constant List_Id := New_List;
1912 Param_Type : Node_Id;
1915 Formal := First (Formals);
1917 -- Skip the object parameter when dealing with primitives declared
1918 -- between two views.
1920 if Is_Private_Primitive_Subprogram (Subp_Id) then
1921 Formal := Next (Formal);
1924 while Present (Formal) loop
1926 -- Create an explicit copy of the entry parameter
1928 -- When creating the wrapper subprogram for a primitive operation
1929 -- of a protected interface we must construct an equivalent
1930 -- signature to that of the overriding operation. For regular
1931 -- parameters we can just use the type of the formal, but for
1932 -- access to subprogram parameters we need to reanalyze the
1933 -- parameter type to create local entities for the signature of
1934 -- the subprogram type. Using the entities of the overriding
1935 -- subprogram will result in out-of-scope errors in the back-end.
1937 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
1938 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
1941 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
1944 Append_To (New_Formals,
1945 Make_Parameter_Specification (Loc,
1946 Defining_Identifier =>
1947 Make_Defining_Identifier (Loc,
1948 Chars => Chars (Defining_Identifier (Formal))),
1949 In_Present => In_Present (Formal),
1950 Out_Present => Out_Present (Formal),
1951 Parameter_Type => Param_Type));
1957 end Replicate_Formals;
1959 -- Start of processing for Build_Wrapper_Spec
1962 -- There is no point in building wrappers for non-tagged concurrent
1965 pragma Assert (Is_Tagged_Type (Obj_Typ));
1967 -- An entry or a protected procedure can override a routine where the
1968 -- controlling formal is either IN OUT, OUT or is of access-to-variable
1969 -- type. Since the wrapper must have the exact same signature as that of
1970 -- the overridden subprogram, we try to find the overriding candidate
1971 -- and use its controlling formal.
1973 First_Param := Empty;
1975 -- Check every implemented interface
1977 if Present (Interfaces (Obj_Typ)) then
1978 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
1979 Search : while Present (Iface_Elmt) loop
1980 Iface := Node (Iface_Elmt);
1982 -- Check every interface primitive
1984 if Present (Primitive_Operations (Iface)) then
1985 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
1986 while Present (Iface_Op_Elmt) loop
1987 Iface_Op := Node (Iface_Op_Elmt);
1989 -- Ignore predefined primitives
1991 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
1992 Iface_Op := Ultimate_Alias (Iface_Op);
1994 -- The current primitive operation can be overridden by
1995 -- the generated entry wrapper.
1997 if Overriding_Possible (Iface_Op, Subp_Id) then
1999 First (Parameter_Specifications (Parent (Iface_Op)));
2005 Next_Elmt (Iface_Op_Elmt);
2009 Next_Elmt (Iface_Elmt);
2013 -- If the subprogram to be wrapped is not overriding anything or is not
2014 -- a primitive declared between two views, do not produce anything. This
2015 -- avoids spurious errors involving overriding.
2018 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2024 Wrapper_Id : constant Entity_Id :=
2025 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2026 New_Formals : List_Id;
2027 Obj_Param : Node_Id;
2028 Obj_Param_Typ : Entity_Id;
2031 -- Minimum decoration is needed to catch the entity in
2032 -- Sem_Ch6.Override_Dispatching_Operation.
2034 if Ekind (Subp_Id) = E_Function then
2035 Set_Ekind (Wrapper_Id, E_Function);
2037 Set_Ekind (Wrapper_Id, E_Procedure);
2040 Set_Is_Primitive_Wrapper (Wrapper_Id);
2041 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2042 Set_Is_Private_Primitive (Wrapper_Id,
2043 Is_Private_Primitive_Subprogram (Subp_Id));
2045 -- Process the formals
2047 New_Formals := Replicate_Formals (Loc, Formals);
2049 -- Routine Subp_Id has been found to override an interface primitive.
2050 -- If the interface operation has an access parameter, create a copy
2051 -- of it, with the same null exclusion indicator if present.
2053 if Present (First_Param) then
2054 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2056 Make_Access_Definition (Loc,
2058 New_Reference_To (Obj_Typ, Loc));
2059 Set_Null_Exclusion_Present (Obj_Param_Typ,
2060 Null_Exclusion_Present (Parameter_Type (First_Param)));
2063 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2067 Make_Parameter_Specification (Loc,
2068 Defining_Identifier =>
2069 Make_Defining_Identifier (Loc,
2071 In_Present => In_Present (First_Param),
2072 Out_Present => Out_Present (First_Param),
2073 Parameter_Type => Obj_Param_Typ);
2075 -- If we are dealing with a primitive declared between two views,
2076 -- create a default parameter.
2078 else pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2080 Make_Parameter_Specification (Loc,
2081 Defining_Identifier =>
2082 Make_Defining_Identifier (Loc, Name_uO),
2084 Out_Present => Ekind (Subp_Id) /= E_Function,
2085 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2088 Prepend_To (New_Formals, Obj_Param);
2090 -- Build the final spec
2092 if Ekind (Subp_Id) = E_Function then
2094 Make_Function_Specification (Loc,
2095 Defining_Unit_Name => Wrapper_Id,
2096 Parameter_Specifications => New_Formals,
2097 Result_Definition =>
2098 New_Copy (Result_Definition (Parent (Subp_Id))));
2101 Make_Procedure_Specification (Loc,
2102 Defining_Unit_Name => Wrapper_Id,
2103 Parameter_Specifications => New_Formals);
2106 end Build_Wrapper_Spec;
2108 -------------------------
2109 -- Build_Wrapper_Specs --
2110 -------------------------
2112 procedure Build_Wrapper_Specs
2118 Rec_Typ : Entity_Id;
2121 if Is_Protected_Type (Typ) then
2122 Def := Protected_Definition (Parent (Typ));
2123 else pragma Assert (Is_Task_Type (Typ));
2124 Def := Task_Definition (Parent (Typ));
2127 Rec_Typ := Corresponding_Record_Type (Typ);
2129 -- Generate wrapper specs for a concurrent type which implements an
2130 -- interface and has visible entries and/or protected procedures.
2132 if Present (Interfaces (Rec_Typ))
2133 and then Present (Def)
2134 and then Present (Visible_Declarations (Def))
2138 Wrap_Decl : Node_Id;
2139 Wrap_Spec : Node_Id;
2142 Decl := First (Visible_Declarations (Def));
2143 while Present (Decl) loop
2146 if Nkind (Decl) = N_Entry_Declaration
2147 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2151 (Subp_Id => Defining_Identifier (Decl),
2153 Formals => Parameter_Specifications (Decl));
2155 elsif Nkind (Decl) = N_Subprogram_Declaration then
2158 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2161 Parameter_Specifications (Specification (Decl)));
2164 if Present (Wrap_Spec) then
2166 Make_Subprogram_Declaration (Loc,
2167 Specification => Wrap_Spec);
2169 Insert_After (N, Wrap_Decl);
2172 Analyze (Wrap_Decl);
2179 end Build_Wrapper_Specs;
2181 ---------------------------
2182 -- Build_Find_Body_Index --
2183 ---------------------------
2185 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2186 Loc : constant Source_Ptr := Sloc (Typ);
2189 Has_F : Boolean := False;
2191 If_St : Node_Id := Empty;
2194 Decls : List_Id := New_List;
2197 Siz : Node_Id := Empty;
2199 procedure Add_If_Clause (Expr : Node_Id);
2200 -- Add test for range of current entry
2202 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2203 -- If a bound of an entry is given by a discriminant, retrieve the
2204 -- actual value of the discriminant from the enclosing object.
2210 procedure Add_If_Clause (Expr : Node_Id) is
2212 Stats : constant List_Id :=
2214 Make_Simple_Return_Statement (Loc,
2215 Expression => Make_Integer_Literal (Loc, Index + 1)));
2218 -- Index for current entry body
2222 -- Compute total length of entry queues so far
2230 Right_Opnd => Expr);
2235 Left_Opnd => Make_Identifier (Loc, Name_uE),
2238 -- Map entry queue indices in the range of the current family
2239 -- into the current index, that designates the entry body.
2243 Make_Implicit_If_Statement (Typ,
2245 Then_Statements => Stats,
2246 Elsif_Parts => New_List);
2252 Make_Elsif_Part (Loc,
2254 Then_Statements => Stats),
2255 Elsif_Parts (If_St));
2259 ------------------------------
2260 -- Convert_Discriminant_Ref --
2261 ------------------------------
2263 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2267 if Is_Entity_Name (Bound)
2268 and then Ekind (Entity (Bound)) = E_Discriminant
2271 Make_Selected_Component (Loc,
2273 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2274 Make_Explicit_Dereference (Loc,
2275 Make_Identifier (Loc, Name_uObject))),
2276 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2277 Set_Etype (B, Etype (Entity (Bound)));
2279 B := New_Copy_Tree (Bound);
2283 end Convert_Discriminant_Ref;
2285 -- Start of processing for Build_Find_Body_Index
2288 Spec := Build_Find_Body_Index_Spec (Typ);
2290 Ent := First_Entity (Typ);
2291 while Present (Ent) loop
2292 if Ekind (Ent) = E_Entry_Family then
2302 -- If the protected type has no entry families, there is a one-one
2303 -- correspondence between entry queue and entry body.
2306 Make_Simple_Return_Statement (Loc,
2307 Expression => Make_Identifier (Loc, Name_uE));
2310 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2313 -- if E <= l1 then return 1;
2314 -- elsif E <= l1 + l2 then return 2;
2319 Ent := First_Entity (Typ);
2321 Add_Object_Pointer (Loc, Typ, Decls);
2323 while Present (Ent) loop
2325 if Ekind (Ent) = E_Entry then
2326 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2328 elsif Ekind (Ent) = E_Entry_Family then
2330 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2331 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2332 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2333 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2342 Make_Simple_Return_Statement (Loc,
2343 Expression => Make_Integer_Literal (Loc, 1));
2345 elsif Nkind (Ret) = N_If_Statement then
2347 -- Ranges are in increasing order, so last one doesn't need guard
2350 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2353 Set_Else_Statements (Ret, Then_Statements (Nod));
2359 Make_Subprogram_Body (Loc,
2360 Specification => Spec,
2361 Declarations => Decls,
2362 Handled_Statement_Sequence =>
2363 Make_Handled_Sequence_Of_Statements (Loc,
2364 Statements => New_List (Ret)));
2365 end Build_Find_Body_Index;
2367 --------------------------------
2368 -- Build_Find_Body_Index_Spec --
2369 --------------------------------
2371 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2372 Loc : constant Source_Ptr := Sloc (Typ);
2373 Id : constant Entity_Id :=
2374 Make_Defining_Identifier (Loc,
2375 Chars => New_External_Name (Chars (Typ), 'F'));
2376 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2377 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2381 Make_Function_Specification (Loc,
2382 Defining_Unit_Name => Id,
2383 Parameter_Specifications => New_List (
2384 Make_Parameter_Specification (Loc,
2385 Defining_Identifier => Parm1,
2387 New_Reference_To (RTE (RE_Address), Loc)),
2389 Make_Parameter_Specification (Loc,
2390 Defining_Identifier => Parm2,
2392 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2393 Result_Definition => New_Occurrence_Of (
2394 RTE (RE_Protected_Entry_Index), Loc));
2395 end Build_Find_Body_Index_Spec;
2397 -------------------------
2398 -- Build_Master_Entity --
2399 -------------------------
2401 procedure Build_Master_Entity (E : Entity_Id) is
2402 Loc : constant Source_Ptr := Sloc (E);
2410 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2411 -- in internal scopes, unless present already.. Required for nested
2412 -- limited aggregates, where the expansion of task components may
2413 -- generate inner blocks. If the block is the rewriting of a call
2414 -- or the scope is an extended return statement this is valid master.
2415 -- The master in an extended return is only used within the return,
2416 -- and is subsequently overwritten in Move_Activation_Chain, but it
2419 if Ada_Version >= Ada_05 then
2420 while Is_Internal (S) loop
2421 if Nkind (Parent (S)) = N_Block_Statement
2423 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
2426 elsif Ekind (S) = E_Return_Statement then
2434 -- Nothing to do if we already built a master entity for this scope
2435 -- or if there is no task hierarchy.
2437 if Has_Master_Entity (S)
2438 or else Restriction_Active (No_Task_Hierarchy)
2443 -- Otherwise first build the master entity
2444 -- _Master : constant Master_Id := Current_Master.all;
2445 -- and insert it just before the current declaration
2448 Make_Object_Declaration (Loc,
2449 Defining_Identifier =>
2450 Make_Defining_Identifier (Loc, Name_uMaster),
2451 Constant_Present => True,
2452 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2454 Make_Explicit_Dereference (Loc,
2455 New_Reference_To (RTE (RE_Current_Master), Loc)));
2458 Insert_Before (P, Decl);
2461 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2462 -- non-internal scope selected above.
2464 if Ada_Version >= Ada_05 then
2465 Set_Has_Master_Entity (S);
2467 Set_Has_Master_Entity (Scope (E));
2470 -- Now mark the containing scope as a task master
2472 while Nkind (P) /= N_Compilation_Unit loop
2475 -- If we fall off the top, we are at the outer level, and the
2476 -- environment task is our effective master, so nothing to mark.
2479 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2481 Set_Is_Task_Master (P, True);
2484 elsif Nkind (Parent (P)) = N_Subunit then
2485 P := Corresponding_Stub (Parent (P));
2488 end Build_Master_Entity;
2490 ---------------------------
2491 -- Build_Protected_Entry --
2492 ---------------------------
2494 function Build_Protected_Entry
2497 Pid : Node_Id) return Node_Id
2499 Loc : constant Source_Ptr := Sloc (N);
2501 Decls : constant List_Id := Declarations (N);
2502 End_Lab : constant Node_Id :=
2503 End_Label (Handled_Statement_Sequence (N));
2504 End_Loc : constant Source_Ptr :=
2505 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2506 -- Used for the generated call to Complete_Entry_Body
2508 Han_Loc : Source_Ptr;
2509 -- Used for the exception handler, inserted at end of the body
2511 Op_Decls : constant List_Id := New_List;
2519 -- Set the source location on the exception handler only when debugging
2520 -- the expanded code (see Make_Implicit_Exception_Handler).
2522 if Debug_Generated_Code then
2525 -- Otherwise the inserted code should not be visible to the debugger
2528 Han_Loc := No_Location;
2532 Make_Defining_Identifier (Loc,
2533 Chars => Chars (Protected_Body_Subprogram (Ent)));
2535 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2537 -- Add the following declarations:
2538 -- type poVP is access poV;
2539 -- _object : poVP := poVP (_O);
2541 -- where _O is the formal parameter associated with the concurrent
2542 -- object. These declarations are needed for Complete_Entry_Body.
2544 Add_Object_Pointer (Loc, Pid, Op_Decls);
2546 -- Add renamings for all formals, the Protection object, discriminals,
2547 -- privals and the entry index constant for use by debugger.
2549 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2550 Debug_Private_Data_Declarations (Decls);
2552 case Corresponding_Runtime_Package (Pid) is
2553 when System_Tasking_Protected_Objects_Entries =>
2555 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2557 when System_Tasking_Protected_Objects_Single_Entry =>
2559 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2562 raise Program_Error;
2565 Op_Stats := New_List (
2566 Make_Block_Statement (Loc,
2567 Declarations => Decls,
2568 Handled_Statement_Sequence =>
2569 Handled_Statement_Sequence (N)),
2571 Make_Procedure_Call_Statement (End_Loc,
2573 Parameter_Associations => New_List (
2574 Make_Attribute_Reference (End_Loc,
2576 Make_Selected_Component (End_Loc,
2578 Make_Identifier (End_Loc, Name_uObject),
2580 Make_Identifier (End_Loc, Name_uObject)),
2581 Attribute_Name => Name_Unchecked_Access))));
2583 -- When exceptions can not be propagated, we never need to call
2584 -- Exception_Complete_Entry_Body
2586 if No_Exception_Handlers_Set then
2588 Make_Subprogram_Body (Loc,
2589 Specification => Espec,
2590 Declarations => Op_Decls,
2591 Handled_Statement_Sequence =>
2592 Make_Handled_Sequence_Of_Statements (Loc,
2593 Statements => Op_Stats,
2594 End_Label => End_Lab));
2597 Ohandle := Make_Others_Choice (Loc);
2598 Set_All_Others (Ohandle);
2600 case Corresponding_Runtime_Package (Pid) is
2601 when System_Tasking_Protected_Objects_Entries =>
2604 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2606 when System_Tasking_Protected_Objects_Single_Entry =>
2609 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2612 raise Program_Error;
2615 -- Create body of entry procedure. The renaming declarations are
2616 -- placed ahead of the block that contains the actual entry body.
2619 Make_Subprogram_Body (Loc,
2620 Specification => Espec,
2621 Declarations => Op_Decls,
2622 Handled_Statement_Sequence =>
2623 Make_Handled_Sequence_Of_Statements (Loc,
2624 Statements => Op_Stats,
2625 End_Label => End_Lab,
2626 Exception_Handlers => New_List (
2627 Make_Implicit_Exception_Handler (Han_Loc,
2628 Exception_Choices => New_List (Ohandle),
2630 Statements => New_List (
2631 Make_Procedure_Call_Statement (Han_Loc,
2633 Parameter_Associations => New_List (
2634 Make_Attribute_Reference (Han_Loc,
2636 Make_Selected_Component (Han_Loc,
2638 Make_Identifier (Han_Loc, Name_uObject),
2640 Make_Identifier (Han_Loc, Name_uObject)),
2641 Attribute_Name => Name_Unchecked_Access),
2643 Make_Function_Call (Han_Loc,
2644 Name => New_Reference_To (
2645 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2647 end Build_Protected_Entry;
2649 -----------------------------------------
2650 -- Build_Protected_Entry_Specification --
2651 -----------------------------------------
2653 function Build_Protected_Entry_Specification
2656 Ent_Id : Entity_Id) return Node_Id
2658 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2661 Set_Debug_Info_Needed (Def_Id);
2663 if Present (Ent_Id) then
2664 Append_Elmt (P, Accept_Address (Ent_Id));
2668 Make_Procedure_Specification (Loc,
2669 Defining_Unit_Name => Def_Id,
2670 Parameter_Specifications => New_List (
2671 Make_Parameter_Specification (Loc,
2672 Defining_Identifier =>
2673 Make_Defining_Identifier (Loc, Name_uO),
2675 New_Reference_To (RTE (RE_Address), Loc)),
2677 Make_Parameter_Specification (Loc,
2678 Defining_Identifier => P,
2680 New_Reference_To (RTE (RE_Address), Loc)),
2682 Make_Parameter_Specification (Loc,
2683 Defining_Identifier =>
2684 Make_Defining_Identifier (Loc, Name_uE),
2686 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2687 end Build_Protected_Entry_Specification;
2689 --------------------------
2690 -- Build_Protected_Spec --
2691 --------------------------
2693 function Build_Protected_Spec
2695 Obj_Type : Entity_Id;
2697 Unprotected : Boolean := False) return List_Id
2699 Loc : constant Source_Ptr := Sloc (N);
2702 New_Plist : List_Id;
2703 New_Param : Node_Id;
2706 New_Plist := New_List;
2708 Formal := First_Formal (Ident);
2709 while Present (Formal) loop
2711 Make_Parameter_Specification (Loc,
2712 Defining_Identifier =>
2713 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2714 In_Present => In_Present (Parent (Formal)),
2715 Out_Present => Out_Present (Parent (Formal)),
2716 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
2719 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2722 Append (New_Param, New_Plist);
2723 Next_Formal (Formal);
2726 -- If the subprogram is a procedure and the context is not an access
2727 -- to protected subprogram, the parameter is in-out. Otherwise it is
2731 Make_Parameter_Specification (Loc,
2732 Defining_Identifier =>
2733 Make_Defining_Identifier (Loc, Name_uObject),
2736 (Etype (Ident) = Standard_Void_Type
2737 and then not Is_RTE (Obj_Type, RE_Address)),
2739 New_Reference_To (Obj_Type, Loc));
2740 Set_Debug_Info_Needed (Defining_Identifier (Decl));
2741 Prepend_To (New_Plist, Decl);
2744 end Build_Protected_Spec;
2746 ---------------------------------------
2747 -- Build_Protected_Sub_Specification --
2748 ---------------------------------------
2750 function Build_Protected_Sub_Specification
2752 Prot_Typ : Entity_Id;
2753 Mode : Subprogram_Protection_Mode) return Node_Id
2755 Loc : constant Source_Ptr := Sloc (N);
2759 New_Plist : List_Id;
2762 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2763 (Dispatching_Mode => ' ',
2764 Protected_Mode => 'P',
2765 Unprotected_Mode => 'N');
2768 if Ekind (Defining_Unit_Name (Specification (N))) =
2771 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2776 Def_Id := Defining_Unit_Name (Specification (Decl));
2779 Build_Protected_Spec
2780 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
2781 Mode = Unprotected_Mode);
2783 Make_Defining_Identifier (Loc,
2784 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
2786 -- The unprotected operation carries the user code, and debugging
2787 -- information must be generated for it, even though this spec does
2788 -- not come from source. It is also convenient to allow gdb to step
2789 -- into the protected operation, even though it only contains lock/
2792 Set_Debug_Info_Needed (New_Id);
2794 -- If a pragma Eliminate applies to the source entity, the internal
2795 -- subprograms will be eliminated as well.
2797 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
2799 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2801 Make_Procedure_Specification (Loc,
2802 Defining_Unit_Name => New_Id,
2803 Parameter_Specifications => New_Plist);
2805 -- Create a new specification for the anonymous subprogram type
2809 Make_Function_Specification (Loc,
2810 Defining_Unit_Name => New_Id,
2811 Parameter_Specifications => New_Plist,
2812 Result_Definition =>
2813 Copy_Result_Type (Result_Definition (Specification (Decl))));
2815 Set_Return_Present (Defining_Unit_Name (New_Spec));
2819 end Build_Protected_Sub_Specification;
2821 -------------------------------------
2822 -- Build_Protected_Subprogram_Body --
2823 -------------------------------------
2825 function Build_Protected_Subprogram_Body
2828 N_Op_Spec : Node_Id) return Node_Id
2830 Loc : constant Source_Ptr := Sloc (N);
2832 P_Op_Spec : Node_Id;
2835 Unprot_Call : Node_Id;
2837 Lock_Name : Node_Id;
2838 Lock_Stmt : Node_Id;
2839 Service_Name : Node_Id;
2841 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2842 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2844 Object_Parm : Node_Id;
2847 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2848 -- Tell whether a given subprogram cannot raise an exception
2850 -----------------------
2851 -- Is_Exception_Safe --
2852 -----------------------
2854 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2856 function Has_Side_Effect (N : Node_Id) return Boolean;
2857 -- Return True whenever encountering a subprogram call or raise
2858 -- statement of any kind in the sequence of statements
2860 ---------------------
2861 -- Has_Side_Effect --
2862 ---------------------
2864 -- What is this doing buried two levels down in exp_ch9. It seems
2865 -- like a generally useful function, and indeed there may be code
2866 -- duplication going on here ???
2868 function Has_Side_Effect (N : Node_Id) return Boolean is
2872 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
2873 -- Indicate whether N is a subprogram call or a raise statement
2875 ----------------------
2876 -- Is_Call_Or_Raise --
2877 ----------------------
2879 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
2881 return Nkind_In (N, N_Procedure_Call_Statement,
2884 N_Raise_Constraint_Error,
2885 N_Raise_Program_Error,
2886 N_Raise_Storage_Error);
2887 end Is_Call_Or_Raise;
2889 -- Start of processing for Has_Side_Effect
2893 while Present (Stmt) loop
2894 if Is_Call_Or_Raise (Stmt) then
2898 -- An object declaration can also contain a function call
2899 -- or a raise statement
2901 if Nkind (Stmt) = N_Object_Declaration then
2902 Expr := Expression (Stmt);
2904 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
2913 end Has_Side_Effect;
2915 -- Start of processing for Is_Exception_Safe
2918 -- If the checks handled by the back end are not disabled, we cannot
2919 -- ensure that no exception will be raised.
2921 if not Access_Checks_Suppressed (Empty)
2922 or else not Discriminant_Checks_Suppressed (Empty)
2923 or else not Range_Checks_Suppressed (Empty)
2924 or else not Index_Checks_Suppressed (Empty)
2925 or else Opt.Stack_Checking_Enabled
2930 if Has_Side_Effect (First (Declarations (Subprogram)))
2933 First (Statements (Handled_Statement_Sequence (Subprogram))))
2939 end Is_Exception_Safe;
2941 -- Start of processing for Build_Protected_Subprogram_Body
2944 Op_Spec := Specification (N);
2945 Exc_Safe := Is_Exception_Safe (N);
2948 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
2950 -- Build a list of the formal parameters of the protected version of
2951 -- the subprogram to use as the actual parameters of the unprotected
2954 Uactuals := New_List;
2955 Pformal := First (Parameter_Specifications (P_Op_Spec));
2956 while Present (Pformal) loop
2958 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
2963 -- Make a call to the unprotected version of the subprogram built above
2964 -- for use by the protected version built below.
2966 if Nkind (Op_Spec) = N_Function_Specification then
2968 R := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2970 Make_Object_Declaration (Loc,
2971 Defining_Identifier => R,
2972 Constant_Present => True,
2973 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
2975 Make_Function_Call (Loc,
2976 Name => Make_Identifier (Loc,
2977 Chars (Defining_Unit_Name (N_Op_Spec))),
2978 Parameter_Associations => Uactuals));
2979 Return_Stmt := Make_Simple_Return_Statement (Loc,
2980 Expression => New_Reference_To (R, Loc));
2983 Unprot_Call := Make_Simple_Return_Statement (Loc,
2984 Expression => Make_Function_Call (Loc,
2986 Make_Identifier (Loc,
2987 Chars (Defining_Unit_Name (N_Op_Spec))),
2988 Parameter_Associations => Uactuals));
2993 Make_Procedure_Call_Statement (Loc,
2995 Make_Identifier (Loc,
2996 Chars (Defining_Unit_Name (N_Op_Spec))),
2997 Parameter_Associations => Uactuals);
3000 -- Wrap call in block that will be covered by an at_end handler
3002 if not Exc_Safe then
3003 Unprot_Call := Make_Block_Statement (Loc,
3004 Handled_Statement_Sequence =>
3005 Make_Handled_Sequence_Of_Statements (Loc,
3006 Statements => New_List (Unprot_Call)));
3009 -- Make the protected subprogram body. This locks the protected
3010 -- object and calls the unprotected version of the subprogram.
3012 case Corresponding_Runtime_Package (Pid) is
3013 when System_Tasking_Protected_Objects_Entries =>
3014 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3015 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3017 when System_Tasking_Protected_Objects_Single_Entry =>
3018 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3019 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3021 when System_Tasking_Protected_Objects =>
3022 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3023 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3026 raise Program_Error;
3030 Make_Attribute_Reference (Loc,
3032 Make_Selected_Component (Loc,
3034 Make_Identifier (Loc, Name_uObject),
3036 Make_Identifier (Loc, Name_uObject)),
3037 Attribute_Name => Name_Unchecked_Access);
3039 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3041 Parameter_Associations => New_List (Object_Parm));
3043 if Abort_Allowed then
3045 Make_Procedure_Call_Statement (Loc,
3046 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3047 Parameter_Associations => Empty_List),
3051 Stmts := New_List (Lock_Stmt);
3054 if not Exc_Safe then
3055 Append (Unprot_Call, Stmts);
3057 if Nkind (Op_Spec) = N_Function_Specification then
3059 Stmts := Empty_List;
3061 Append (Unprot_Call, Stmts);
3065 Make_Procedure_Call_Statement (Loc,
3066 Name => Service_Name,
3067 Parameter_Associations =>
3068 New_List (New_Copy_Tree (Object_Parm))),
3071 if Abort_Allowed then
3073 Make_Procedure_Call_Statement (Loc,
3074 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3075 Parameter_Associations => Empty_List),
3079 if Nkind (Op_Spec) = N_Function_Specification then
3080 Append (Return_Stmt, Stmts);
3081 Append (Make_Block_Statement (Loc,
3082 Declarations => New_List (Unprot_Call),
3083 Handled_Statement_Sequence =>
3084 Make_Handled_Sequence_Of_Statements (Loc,
3085 Statements => Stmts)), Pre_Stmts);
3091 Make_Subprogram_Body (Loc,
3092 Declarations => Empty_List,
3093 Specification => P_Op_Spec,
3094 Handled_Statement_Sequence =>
3095 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3097 if not Exc_Safe then
3098 Set_Is_Protected_Subprogram_Body (Sub_Body);
3102 end Build_Protected_Subprogram_Body;
3104 -------------------------------------
3105 -- Build_Protected_Subprogram_Call --
3106 -------------------------------------
3108 procedure Build_Protected_Subprogram_Call
3112 External : Boolean := True)
3114 Loc : constant Source_Ptr := Sloc (N);
3115 Sub : constant Entity_Id := Entity (Name);
3121 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3124 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3127 if Present (Parameter_Associations (N)) then
3128 Params := New_Copy_List_Tree (Parameter_Associations (N));
3133 Prepend (Rec, Params);
3135 if Ekind (Sub) = E_Procedure then
3137 Make_Procedure_Call_Statement (Loc,
3139 Parameter_Associations => Params));
3142 pragma Assert (Ekind (Sub) = E_Function);
3144 Make_Function_Call (Loc,
3146 Parameter_Associations => Params));
3150 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3151 and then Is_Entity_Name (Expression (Rec))
3152 and then Is_Shared_Passive (Entity (Expression (Rec)))
3154 Add_Shared_Var_Lock_Procs (N);
3156 end Build_Protected_Subprogram_Call;
3158 -------------------------
3159 -- Build_Selected_Name --
3160 -------------------------
3162 function Build_Selected_Name
3163 (Prefix : Entity_Id;
3164 Selector : Entity_Id;
3165 Append_Char : Character := ' ') return Name_Id
3167 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3168 Select_Len : Natural;
3171 Get_Name_String (Chars (Selector));
3172 Select_Len := Name_Len;
3173 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3174 Get_Name_String (Chars (Prefix));
3176 -- If scope is anonymous type, discard suffix to recover name of
3177 -- single protected object. Otherwise use protected type name.
3179 if Name_Buffer (Name_Len) = 'T' then
3180 Name_Len := Name_Len - 1;
3183 Add_Str_To_Name_Buffer ("__");
3184 for J in 1 .. Select_Len loop
3185 Add_Char_To_Name_Buffer (Select_Buffer (J));
3188 -- Now add the Append_Char if specified. The encoding to follow
3189 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3190 -- then the entity is associated to a protected type subprogram.
3191 -- Otherwise, it is a protected type entry. For each case, the
3192 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3194 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3196 if Append_Char /= ' ' then
3197 if Append_Char = 'P' or Append_Char = 'N' then
3198 Add_Char_To_Name_Buffer (Append_Char);
3201 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3202 return New_External_Name (Name_Find, ' ', -1);
3207 end Build_Selected_Name;
3209 -----------------------------
3210 -- Build_Simple_Entry_Call --
3211 -----------------------------
3213 -- A task entry call is converted to a call to Call_Simple
3216 -- P : parms := (parm, parm, parm);
3218 -- Call_Simple (acceptor-task, entry-index, P'Address);
3224 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3225 -- the parameters, and the constructed aggregate value contains either the
3226 -- parameters or, in the case of non-elementary types, references to these
3227 -- parameters. Then the address of this aggregate is passed to the runtime
3228 -- routine, along with the task id value and the task entry index value.
3229 -- Pnn is only required if parameters are present.
3231 -- The assignments after the call are present only in the case of in-out
3232 -- or out parameters for elementary types, and are used to assign back the
3233 -- resulting values of such parameters.
3235 -- Note: the reason that we insert a block here is that in the context
3236 -- of selects, conditional entry calls etc. the entry call statement
3237 -- appears on its own, not as an element of a list.
3239 -- A protected entry call is converted to a Protected_Entry_Call:
3242 -- P : E1_Params := (param, param, param);
3244 -- Bnn : Communications_Block;
3247 -- P : E1_Params := (param, param, param);
3248 -- Bnn : Communications_Block;
3251 -- Protected_Entry_Call (
3252 -- Object => po._object'Access,
3253 -- E => <entry index>;
3254 -- Uninterpreted_Data => P'Address;
3255 -- Mode => Simple_Call;
3262 procedure Build_Simple_Entry_Call
3271 -- If call has been inlined, nothing left to do
3273 if Nkind (N) = N_Block_Statement then
3277 -- Convert entry call to Call_Simple call
3280 Loc : constant Source_Ptr := Sloc (N);
3281 Parms : constant List_Id := Parameter_Associations (N);
3282 Stats : constant List_Id := New_List;
3285 Comm_Name : Entity_Id;
3289 Ent_Acc : Entity_Id;
3291 Iface_Tag : Entity_Id;
3292 Iface_Typ : Entity_Id;
3305 -- Simple entry and entry family cases merge here
3307 Ent := Entity (Ename);
3308 Ent_Acc := Entry_Parameters_Type (Ent);
3309 Conctyp := Etype (Concval);
3311 -- If prefix is an access type, dereference to obtain the task type
3313 if Is_Access_Type (Conctyp) then
3314 Conctyp := Designated_Type (Conctyp);
3317 -- Special case for protected subprogram calls
3319 if Is_Protected_Type (Conctyp)
3320 and then Is_Subprogram (Entity (Ename))
3322 if not Is_Eliminated (Entity (Ename)) then
3323 Build_Protected_Subprogram_Call
3324 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3331 -- First parameter is the Task_Id value from the task value or the
3332 -- Object from the protected object value, obtained by selecting
3333 -- the _Task_Id or _Object from the result of doing an unchecked
3334 -- conversion to convert the value to the corresponding record type.
3336 if Nkind (Concval) = N_Function_Call
3337 and then Is_Task_Type (Conctyp)
3338 and then Ada_Version >= Ada_05
3341 Obj : constant Entity_Id :=
3342 Make_Defining_Identifier (Loc, New_Internal_Name ('F'));
3347 Make_Object_Declaration (Loc,
3348 Defining_Identifier => Obj,
3349 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3350 Expression => Relocate_Node (Concval));
3351 Set_Etype (Obj, Conctyp);
3352 Decls := New_List (Decl);
3353 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3360 Parm1 := Concurrent_Ref (Concval);
3362 -- Second parameter is the entry index, computed by the routine
3363 -- provided for this purpose. The value of this expression is
3364 -- assigned to an intermediate variable to assure that any entry
3365 -- family index expressions are evaluated before the entry
3369 or else Restriction_Active (No_Entry_Queue) = False
3370 or else not Is_Protected_Type (Conctyp)
3371 or else Number_Entries (Conctyp) > 1
3372 or else (Has_Attach_Handler (Conctyp)
3373 and then not Restricted_Profile)
3375 X := Make_Defining_Identifier (Loc, Name_uX);
3378 Make_Object_Declaration (Loc,
3379 Defining_Identifier => X,
3380 Object_Definition =>
3381 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3382 Expression => Actual_Index_Expression (
3383 Loc, Entity (Ename), Index, Concval));
3385 Append_To (Decls, Xdecl);
3386 Parm2 := New_Reference_To (X, Loc);
3393 -- The third parameter is the packaged parameters. If there are
3394 -- none, then it is just the null address, since nothing is passed.
3397 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3400 -- Case of parameters present, where third argument is the address
3401 -- of a packaged record containing the required parameter values.
3404 -- First build a list of parameter values, which are references to
3405 -- objects of the parameter types.
3409 Actual := First_Actual (N);
3410 Formal := First_Formal (Ent);
3412 while Present (Actual) loop
3414 -- If it is a by_copy_type, copy it to a new variable. The
3415 -- packaged record has a field that points to this variable.
3417 if Is_By_Copy_Type (Etype (Actual)) then
3419 Make_Object_Declaration (Loc,
3420 Defining_Identifier =>
3421 Make_Defining_Identifier (Loc,
3422 Chars => New_Internal_Name ('J')),
3423 Aliased_Present => True,
3424 Object_Definition =>
3425 New_Reference_To (Etype (Formal), Loc));
3427 -- Mark the object as not needing initialization since the
3428 -- initialization is performed separately, avoiding errors
3429 -- on cases such as formals of null-excluding access types.
3431 Set_No_Initialization (N_Node);
3433 -- We must make an assignment statement separate for the
3434 -- case of limited type. We cannot assign it unless the
3435 -- Assignment_OK flag is set first. An out formal of an
3436 -- access type must also be initialized from the actual,
3437 -- as stated in RM 6.4.1 (13).
3439 if Ekind (Formal) /= E_Out_Parameter
3440 or else Is_Access_Type (Etype (Formal))
3443 New_Reference_To (Defining_Identifier (N_Node), Loc);
3444 Set_Assignment_OK (N_Var);
3446 Make_Assignment_Statement (Loc,
3448 Expression => Relocate_Node (Actual)));
3451 Append (N_Node, Decls);
3454 Make_Attribute_Reference (Loc,
3455 Attribute_Name => Name_Unchecked_Access,
3457 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3459 -- Interface class-wide formal
3461 if Ada_Version >= Ada_05
3462 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3463 and then Is_Interface (Etype (Formal))
3465 Iface_Typ := Etype (Etype (Formal));
3468 -- formal_iface_type! (actual.iface_tag)'reference
3471 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3472 pragma Assert (Present (Iface_Tag));
3475 Make_Reference (Loc,
3476 Unchecked_Convert_To (Iface_Typ,
3477 Make_Selected_Component (Loc,
3479 Relocate_Node (Actual),
3481 New_Reference_To (Iface_Tag, Loc)))));
3487 Make_Reference (Loc, Relocate_Node (Actual)));
3491 Next_Actual (Actual);
3492 Next_Formal_With_Extras (Formal);
3495 -- Now build the declaration of parameters initialized with the
3496 -- aggregate containing this constructed parameter list.
3498 P := Make_Defining_Identifier (Loc, Name_uP);
3501 Make_Object_Declaration (Loc,
3502 Defining_Identifier => P,
3503 Object_Definition =>
3504 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3506 Make_Aggregate (Loc, Expressions => Plist));
3509 Make_Attribute_Reference (Loc,
3510 Prefix => New_Reference_To (P, Loc),
3511 Attribute_Name => Name_Address);
3513 Append (Pdecl, Decls);
3516 -- Now we can create the call, case of protected type
3518 if Is_Protected_Type (Conctyp) then
3519 case Corresponding_Runtime_Package (Conctyp) is
3520 when System_Tasking_Protected_Objects_Entries =>
3522 -- Change the type of the index declaration
3524 Set_Object_Definition (Xdecl,
3525 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3527 -- Some additional declarations for protected entry calls
3533 -- Bnn : Communications_Block;
3536 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3539 Make_Object_Declaration (Loc,
3540 Defining_Identifier => Comm_Name,
3541 Object_Definition =>
3542 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3544 -- Some additional statements for protected entry calls
3546 -- Protected_Entry_Call (
3547 -- Object => po._object'Access,
3548 -- E => <entry index>;
3549 -- Uninterpreted_Data => P'Address;
3550 -- Mode => Simple_Call;
3554 Make_Procedure_Call_Statement (Loc,
3556 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3558 Parameter_Associations => New_List (
3559 Make_Attribute_Reference (Loc,
3560 Attribute_Name => Name_Unchecked_Access,
3564 New_Reference_To (RTE (RE_Simple_Call), Loc),
3565 New_Occurrence_Of (Comm_Name, Loc)));
3567 when System_Tasking_Protected_Objects_Single_Entry =>
3568 -- Protected_Single_Entry_Call (
3569 -- Object => po._object'Access,
3570 -- Uninterpreted_Data => P'Address;
3571 -- Mode => Simple_Call);
3574 Make_Procedure_Call_Statement (Loc,
3575 Name => New_Reference_To (
3576 RTE (RE_Protected_Single_Entry_Call), Loc),
3578 Parameter_Associations => New_List (
3579 Make_Attribute_Reference (Loc,
3580 Attribute_Name => Name_Unchecked_Access,
3583 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3586 raise Program_Error;
3589 -- Case of task type
3593 Make_Procedure_Call_Statement (Loc,
3594 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3595 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3599 Append_To (Stats, Call);
3601 -- If there are out or in/out parameters by copy add assignment
3602 -- statements for the result values.
3604 if Present (Parms) then
3605 Actual := First_Actual (N);
3606 Formal := First_Formal (Ent);
3608 Set_Assignment_OK (Actual);
3609 while Present (Actual) loop
3610 if Is_By_Copy_Type (Etype (Actual))
3611 and then Ekind (Formal) /= E_In_Parameter
3614 Make_Assignment_Statement (Loc,
3615 Name => New_Copy (Actual),
3617 Make_Explicit_Dereference (Loc,
3618 Make_Selected_Component (Loc,
3619 Prefix => New_Reference_To (P, Loc),
3621 Make_Identifier (Loc, Chars (Formal)))));
3623 -- In all cases (including limited private types) we want
3624 -- the assignment to be valid.
3626 Set_Assignment_OK (Name (N_Node));
3628 -- If the call is the triggering alternative in an
3629 -- asynchronous select, or the entry_call alternative of a
3630 -- conditional entry call, the assignments for in-out
3631 -- parameters are incorporated into the statement list that
3632 -- follows, so that there are executed only if the entry
3635 if (Nkind (Parent (N)) = N_Triggering_Alternative
3636 and then N = Triggering_Statement (Parent (N)))
3638 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3639 and then N = Entry_Call_Statement (Parent (N)))
3641 if No (Statements (Parent (N))) then
3642 Set_Statements (Parent (N), New_List);
3645 Prepend (N_Node, Statements (Parent (N)));
3648 Insert_After (Call, N_Node);
3652 Next_Actual (Actual);
3653 Next_Formal_With_Extras (Formal);
3657 -- Finally, create block and analyze it
3660 Make_Block_Statement (Loc,
3661 Declarations => Decls,
3662 Handled_Statement_Sequence =>
3663 Make_Handled_Sequence_Of_Statements (Loc,
3664 Statements => Stats)));
3668 end Build_Simple_Entry_Call;
3670 --------------------------------
3671 -- Build_Task_Activation_Call --
3672 --------------------------------
3674 procedure Build_Task_Activation_Call (N : Node_Id) is
3675 Loc : constant Source_Ptr := Sloc (N);
3682 -- Get the activation chain entity. Except in the case of a package
3683 -- body, this is in the node that was passed. For a package body, we
3684 -- have to find the corresponding package declaration node.
3686 if Nkind (N) = N_Package_Body then
3687 P := Corresponding_Spec (N);
3690 exit when Nkind (P) = N_Package_Declaration;
3693 Chain := Activation_Chain_Entity (P);
3696 Chain := Activation_Chain_Entity (N);
3699 if Present (Chain) then
3700 if Restricted_Profile then
3701 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3703 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3707 Make_Procedure_Call_Statement (Loc,
3709 Parameter_Associations =>
3710 New_List (Make_Attribute_Reference (Loc,
3711 Prefix => New_Occurrence_Of (Chain, Loc),
3712 Attribute_Name => Name_Unchecked_Access)));
3714 if Nkind (N) = N_Package_Declaration then
3715 if Present (Corresponding_Body (N)) then
3718 elsif Present (Private_Declarations (Specification (N))) then
3719 Append (Call, Private_Declarations (Specification (N)));
3722 Append (Call, Visible_Declarations (Specification (N)));
3726 if Present (Handled_Statement_Sequence (N)) then
3728 -- The call goes at the start of the statement sequence
3729 -- after the start of exception range label if one is present.
3735 Stm := First (Statements (Handled_Statement_Sequence (N)));
3737 -- A special case, skip exception range label if one is
3738 -- present (from front end zcx processing).
3740 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3744 -- Another special case, if the first statement is a block
3745 -- from optimization of a local raise to a goto, then the
3746 -- call goes inside this block.
3748 if Nkind (Stm) = N_Block_Statement
3749 and then Exception_Junk (Stm)
3752 First (Statements (Handled_Statement_Sequence (Stm)));
3755 -- Insertion point is after any exception label pushes,
3756 -- since we want it covered by any local handlers.
3758 while Nkind (Stm) in N_Push_xxx_Label loop
3762 -- Now we have the proper insertion point
3764 Insert_Before (Stm, Call);
3768 Set_Handled_Statement_Sequence (N,
3769 Make_Handled_Sequence_Of_Statements (Loc,
3770 Statements => New_List (Call)));
3775 Check_Task_Activation (N);
3777 end Build_Task_Activation_Call;
3779 -------------------------------
3780 -- Build_Task_Allocate_Block --
3781 -------------------------------
3783 procedure Build_Task_Allocate_Block
3788 T : constant Entity_Id := Entity (Expression (N));
3789 Init : constant Entity_Id := Base_Init_Proc (T);
3790 Loc : constant Source_Ptr := Sloc (N);
3791 Chain : constant Entity_Id :=
3792 Make_Defining_Identifier (Loc, Name_uChain);
3798 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3801 Make_Block_Statement (Loc,
3802 Identifier => New_Reference_To (Blkent, Loc),
3803 Declarations => New_List (
3805 -- _Chain : Activation_Chain;
3807 Make_Object_Declaration (Loc,
3808 Defining_Identifier => Chain,
3809 Aliased_Present => True,
3810 Object_Definition =>
3811 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3813 Handled_Statement_Sequence =>
3814 Make_Handled_Sequence_Of_Statements (Loc,
3816 Statements => New_List (
3820 Make_Procedure_Call_Statement (Loc,
3821 Name => New_Reference_To (Init, Loc),
3822 Parameter_Associations => Args),
3824 -- Activate_Tasks (_Chain);
3826 Make_Procedure_Call_Statement (Loc,
3827 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3828 Parameter_Associations => New_List (
3829 Make_Attribute_Reference (Loc,
3830 Prefix => New_Reference_To (Chain, Loc),
3831 Attribute_Name => Name_Unchecked_Access))))),
3833 Has_Created_Identifier => True,
3834 Is_Task_Allocation_Block => True);
3837 Make_Implicit_Label_Declaration (Loc,
3838 Defining_Identifier => Blkent,
3839 Label_Construct => Block));
3841 Append_To (Actions, Block);
3843 Set_Activation_Chain_Entity (Block, Chain);
3844 end Build_Task_Allocate_Block;
3846 -----------------------------------------------
3847 -- Build_Task_Allocate_Block_With_Init_Stmts --
3848 -----------------------------------------------
3850 procedure Build_Task_Allocate_Block_With_Init_Stmts
3853 Init_Stmts : List_Id)
3855 Loc : constant Source_Ptr := Sloc (N);
3856 Chain : constant Entity_Id :=
3857 Make_Defining_Identifier (Loc, Name_uChain);
3862 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3864 Append_To (Init_Stmts,
3865 Make_Procedure_Call_Statement (Loc,
3866 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3867 Parameter_Associations => New_List (
3868 Make_Attribute_Reference (Loc,
3869 Prefix => New_Reference_To (Chain, Loc),
3870 Attribute_Name => Name_Unchecked_Access))));
3873 Make_Block_Statement (Loc,
3874 Identifier => New_Reference_To (Blkent, Loc),
3875 Declarations => New_List (
3877 -- _Chain : Activation_Chain;
3879 Make_Object_Declaration (Loc,
3880 Defining_Identifier => Chain,
3881 Aliased_Present => True,
3882 Object_Definition =>
3883 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3885 Handled_Statement_Sequence =>
3886 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
3888 Has_Created_Identifier => True,
3889 Is_Task_Allocation_Block => True);
3892 Make_Implicit_Label_Declaration (Loc,
3893 Defining_Identifier => Blkent,
3894 Label_Construct => Block));
3896 Append_To (Actions, Block);
3898 Set_Activation_Chain_Entity (Block, Chain);
3899 end Build_Task_Allocate_Block_With_Init_Stmts;
3901 -----------------------------------
3902 -- Build_Task_Proc_Specification --
3903 -----------------------------------
3905 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
3906 Loc : constant Source_Ptr := Sloc (T);
3907 Spec_Id : Entity_Id;
3911 Make_Defining_Identifier (Loc,
3912 Chars => New_External_Name (Chars (T), 'B'));
3913 Set_Is_Internal (Spec_Id);
3915 -- Associate the procedure with the task, if this is the declaration
3916 -- (and not the body) of the procedure.
3918 if No (Task_Body_Procedure (T)) then
3919 Set_Task_Body_Procedure (T, Spec_Id);
3923 Make_Procedure_Specification (Loc,
3924 Defining_Unit_Name => Spec_Id,
3925 Parameter_Specifications => New_List (
3926 Make_Parameter_Specification (Loc,
3927 Defining_Identifier =>
3928 Make_Defining_Identifier (Loc, Name_uTask),
3930 Make_Access_Definition (Loc,
3932 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
3933 end Build_Task_Proc_Specification;
3935 ---------------------------------------
3936 -- Build_Unprotected_Subprogram_Body --
3937 ---------------------------------------
3939 function Build_Unprotected_Subprogram_Body
3941 Pid : Node_Id) return Node_Id
3943 Decls : constant List_Id := Declarations (N);
3946 -- Add renamings for the Protection object, discriminals, privals and
3947 -- the entry index constant for use by debugger.
3949 Debug_Private_Data_Declarations (Decls);
3951 -- Make an unprotected version of the subprogram for use within the same
3952 -- object, with a new name and an additional parameter representing the
3956 Make_Subprogram_Body (Sloc (N),
3958 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
3959 Declarations => Decls,
3960 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
3961 end Build_Unprotected_Subprogram_Body;
3963 ----------------------------
3964 -- Collect_Entry_Families --
3965 ----------------------------
3967 procedure Collect_Entry_Families
3970 Current_Node : in out Node_Id;
3971 Conctyp : Entity_Id)
3974 Efam_Decl : Node_Id;
3975 Efam_Type : Entity_Id;
3978 Efam := First_Entity (Conctyp);
3979 while Present (Efam) loop
3980 if Ekind (Efam) = E_Entry_Family then
3982 Make_Defining_Identifier (Loc,
3983 Chars => New_Internal_Name ('F'));
3988 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
3990 Bas_Decl : Node_Id := Empty;
3995 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
3997 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
3999 Make_Defining_Identifier (Loc,
4000 Chars => New_Internal_Name ('B'));
4003 Make_Subtype_Declaration (Loc,
4004 Defining_Identifier => Bas,
4005 Subtype_Indication =>
4006 Make_Subtype_Indication (Loc,
4008 New_Occurrence_Of (Standard_Integer, Loc),
4010 Make_Range_Constraint (Loc,
4011 Range_Expression => Make_Range (Loc,
4012 Make_Integer_Literal
4013 (Loc, -Entry_Family_Bound),
4014 Make_Integer_Literal
4015 (Loc, Entry_Family_Bound - 1)))));
4017 Insert_After (Current_Node, Bas_Decl);
4018 Current_Node := Bas_Decl;
4023 Make_Full_Type_Declaration (Loc,
4024 Defining_Identifier => Efam_Type,
4026 Make_Unconstrained_Array_Definition (Loc,
4028 (New_List (New_Occurrence_Of (Bas, Loc))),
4030 Component_Definition =>
4031 Make_Component_Definition (Loc,
4032 Aliased_Present => False,
4033 Subtype_Indication =>
4034 New_Reference_To (Standard_Character, Loc))));
4037 Insert_After (Current_Node, Efam_Decl);
4038 Current_Node := Efam_Decl;
4039 Analyze (Efam_Decl);
4042 Make_Component_Declaration (Loc,
4043 Defining_Identifier =>
4044 Make_Defining_Identifier (Loc, Chars (Efam)),
4046 Component_Definition =>
4047 Make_Component_Definition (Loc,
4048 Aliased_Present => False,
4049 Subtype_Indication =>
4050 Make_Subtype_Indication (Loc,
4052 New_Occurrence_Of (Efam_Type, Loc),
4055 Make_Index_Or_Discriminant_Constraint (Loc,
4056 Constraints => New_List (
4058 (Etype (Discrete_Subtype_Definition
4059 (Parent (Efam))), Loc)))))));
4065 end Collect_Entry_Families;
4067 -----------------------
4068 -- Concurrent_Object --
4069 -----------------------
4071 function Concurrent_Object
4072 (Spec_Id : Entity_Id;
4073 Conc_Typ : Entity_Id) return Entity_Id
4076 -- Parameter _O or _object
4078 if Is_Protected_Type (Conc_Typ) then
4079 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4084 pragma Assert (Is_Task_Type (Conc_Typ));
4085 return First_Formal (Task_Body_Procedure (Conc_Typ));
4087 end Concurrent_Object;
4089 ----------------------
4090 -- Copy_Result_Type --
4091 ----------------------
4093 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4094 New_Res : constant Node_Id := New_Copy_Tree (Res);
4099 -- If the result type is an access_to_subprogram, we must create
4100 -- new entities for its spec.
4102 if Nkind (New_Res) = N_Access_Definition
4103 and then Present (Access_To_Subprogram_Definition (New_Res))
4105 -- Provide new entities for the formals
4107 Par_Spec := First (Parameter_Specifications
4108 (Access_To_Subprogram_Definition (New_Res)));
4109 while Present (Par_Spec) loop
4110 Formal := Defining_Identifier (Par_Spec);
4111 Set_Defining_Identifier (Par_Spec,
4112 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4118 end Copy_Result_Type;
4120 --------------------
4121 -- Concurrent_Ref --
4122 --------------------
4124 -- The expression returned for a reference to a concurrent object has the
4127 -- taskV!(name)._Task_Id
4131 -- objectV!(name)._Object
4133 -- for a protected object. For the case of an access to a concurrent
4134 -- object, there is an extra explicit dereference:
4136 -- taskV!(name.all)._Task_Id
4137 -- objectV!(name.all)._Object
4139 -- here taskV and objectV are the types for the associated records, which
4140 -- contain the required _Task_Id and _Object fields for tasks and protected
4141 -- objects, respectively.
4143 -- For the case of a task type name, the expression is
4147 -- i.e. a call to the Self function which returns precisely this Task_Id
4149 -- For the case of a protected type name, the expression is
4153 -- which is a renaming of the _object field of the current object
4154 -- record, passed into protected operations as a parameter.
4156 function Concurrent_Ref (N : Node_Id) return Node_Id is
4157 Loc : constant Source_Ptr := Sloc (N);
4158 Ntyp : constant Entity_Id := Etype (N);
4162 function Is_Current_Task (T : Entity_Id) return Boolean;
4163 -- Check whether the reference is to the immediately enclosing task
4164 -- type, or to an outer one (rare but legal).
4166 ---------------------
4167 -- Is_Current_Task --
4168 ---------------------
4170 function Is_Current_Task (T : Entity_Id) return Boolean is
4174 Scop := Current_Scope;
4175 while Present (Scop)
4176 and then Scop /= Standard_Standard
4182 elsif Is_Task_Type (Scop) then
4185 -- If this is a procedure nested within the task type, we must
4186 -- assume that it can be called from an inner task, and therefore
4187 -- cannot treat it as a local reference.
4189 elsif Is_Overloadable (Scop)
4190 and then In_Open_Scopes (T)
4195 Scop := Scope (Scop);
4199 -- We know that we are within the task body, so should have found it
4202 raise Program_Error;
4203 end Is_Current_Task;
4205 -- Start of processing for Concurrent_Ref
4208 if Is_Access_Type (Ntyp) then
4209 Dtyp := Designated_Type (Ntyp);
4211 if Is_Protected_Type (Dtyp) then
4212 Sel := Name_uObject;
4214 Sel := Name_uTask_Id;
4218 Make_Selected_Component (Loc,
4220 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4221 Make_Explicit_Dereference (Loc, N)),
4222 Selector_Name => Make_Identifier (Loc, Sel));
4224 elsif Is_Entity_Name (N)
4225 and then Is_Concurrent_Type (Entity (N))
4227 if Is_Task_Type (Entity (N)) then
4229 if Is_Current_Task (Entity (N)) then
4231 Make_Function_Call (Loc,
4232 Name => New_Reference_To (RTE (RE_Self), Loc));
4237 T_Self : constant Entity_Id :=
4238 Make_Defining_Identifier (Loc,
4239 Chars => New_Internal_Name ('T'));
4240 T_Body : constant Node_Id :=
4241 Parent (Corresponding_Body (Parent (Entity (N))));
4244 Decl := Make_Object_Declaration (Loc,
4245 Defining_Identifier => T_Self,
4246 Object_Definition =>
4247 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4249 Make_Function_Call (Loc,
4250 Name => New_Reference_To (RTE (RE_Self), Loc)));
4251 Prepend (Decl, Declarations (T_Body));
4253 Set_Scope (T_Self, Entity (N));
4254 return New_Occurrence_Of (T_Self, Loc);
4259 pragma Assert (Is_Protected_Type (Entity (N)));
4262 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4266 if Is_Protected_Type (Ntyp) then
4267 Sel := Name_uObject;
4269 elsif Is_Task_Type (Ntyp) then
4270 Sel := Name_uTask_Id;
4273 raise Program_Error;
4277 Make_Selected_Component (Loc,
4279 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4281 Selector_Name => Make_Identifier (Loc, Sel));
4285 ------------------------
4286 -- Convert_Concurrent --
4287 ------------------------
4289 function Convert_Concurrent
4291 Typ : Entity_Id) return Node_Id
4294 if not Is_Concurrent_Type (Typ) then
4298 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
4301 end Convert_Concurrent;
4303 -------------------------------------
4304 -- Debug_Private_Data_Declarations --
4305 -------------------------------------
4307 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4308 Debug_Nod : Node_Id;
4312 Decl := First (Decls);
4313 while Present (Decl)
4314 and then not Comes_From_Source (Decl)
4316 -- Declaration for concurrent entity _object and its access type,
4317 -- along with the entry index subtype:
4318 -- type prot_typVP is access prot_typV;
4319 -- _object : prot_typVP := prot_typV (_O);
4320 -- subtype Jnn is <Type of Index> range Low .. High;
4322 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4323 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4325 -- Declaration for the Protection object, discriminals, privals and
4326 -- entry index constant:
4327 -- conc_typR : protection_typ renames _object._object;
4328 -- discr_nameD : discr_typ renames _object.discr_name;
4329 -- discr_nameD : discr_typ renames _task.discr_name;
4330 -- prival_name : comp_typ renames _object.comp_name;
4331 -- J : constant Jnn :=
4332 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4334 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4335 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4336 Debug_Nod := Debug_Renaming_Declaration (Decl);
4338 if Present (Debug_Nod) then
4339 Insert_After (Decl, Debug_Nod);
4345 end Debug_Private_Data_Declarations;
4347 ----------------------------
4348 -- Entry_Index_Expression --
4349 ----------------------------
4351 function Entry_Index_Expression
4355 Ttyp : Entity_Id) return Node_Id
4365 -- The queues of entries and entry families appear in textual order in
4366 -- the associated record. The entry index is computed as the sum of the
4367 -- number of queues for all entries that precede the designated one, to
4368 -- which is added the index expression, if this expression denotes a
4369 -- member of a family.
4371 -- The following is a place holder for the count of simple entries
4373 Num := Make_Integer_Literal (Sloc, 1);
4375 -- We construct an expression which is a series of addition operations.
4376 -- The first operand is the number of single entries that precede this
4377 -- one, the second operand is the index value relative to the start of
4378 -- the referenced family, and the remaining operands are the lengths of
4379 -- the entry families that precede this entry, i.e. the constructed
4382 -- number_simple_entries +
4383 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4384 -- family'length + ...
4386 -- where index-value is the given index value, and s is the index
4387 -- subtype (we have to use pos because the subtype might be an
4388 -- enumeration type preventing direct subtraction). Note that the task
4389 -- entry array is one-indexed.
4391 -- The upper bound of the entry family may be a discriminant, so we
4392 -- retrieve the lower bound explicitly to compute offset, rather than
4393 -- using the index subtype which may mention a discriminant.
4395 if Present (Index) then
4396 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4405 Make_Attribute_Reference (Sloc,
4406 Attribute_Name => Name_Pos,
4407 Prefix => New_Reference_To (Base_Type (S), Sloc),
4408 Expressions => New_List (Relocate_Node (Index))),
4416 -- Now add lengths of preceding entries and entry families
4418 Prev := First_Entity (Ttyp);
4420 while Chars (Prev) /= Chars (Ent)
4421 or else (Ekind (Prev) /= Ekind (Ent))
4422 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4424 if Ekind (Prev) = E_Entry then
4425 Set_Intval (Num, Intval (Num) + 1);
4427 elsif Ekind (Prev) = E_Entry_Family then
4429 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4430 Lo := Type_Low_Bound (S);
4431 Hi := Type_High_Bound (S);
4436 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4438 -- Other components are anonymous types to be ignored
4448 end Entry_Index_Expression;
4450 ---------------------------
4451 -- Establish_Task_Master --
4452 ---------------------------
4454 procedure Establish_Task_Master (N : Node_Id) is
4457 if Restriction_Active (No_Task_Hierarchy) = False then
4458 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4459 Prepend_To (Declarations (N), Call);
4462 end Establish_Task_Master;
4464 --------------------------------
4465 -- Expand_Accept_Declarations --
4466 --------------------------------
4468 -- Part of the expansion of an accept statement involves the creation of
4469 -- a declaration that can be referenced from the statement sequence of
4474 -- This declaration is inserted immediately before the accept statement
4475 -- and it is important that it be inserted before the statements of the
4476 -- statement sequence are analyzed. Thus it would be too late to create
4477 -- this declaration in the Expand_N_Accept_Statement routine, which is
4478 -- why there is a separate procedure to be called directly from Sem_Ch9.
4480 -- Ann is used to hold the address of the record containing the parameters
4481 -- (see Expand_N_Entry_Call for more details on how this record is built).
4482 -- References to the parameters do an unchecked conversion of this address
4483 -- to a pointer to the required record type, and then access the field that
4484 -- holds the value of the required parameter. The entity for the address
4485 -- variable is held as the top stack element (i.e. the last element) of the
4486 -- Accept_Address stack in the corresponding entry entity, and this element
4487 -- must be set in place before the statements are processed.
4489 -- The above description applies to the case of a stand alone accept
4490 -- statement, i.e. one not appearing as part of a select alternative.
4492 -- For the case of an accept that appears as part of a select alternative
4493 -- of a selective accept, we must still create the declaration right away,
4494 -- since Ann is needed immediately, but there is an important difference:
4496 -- The declaration is inserted before the selective accept, not before
4497 -- the accept statement (which is not part of a list anyway, and so would
4498 -- not accommodate inserted declarations)
4500 -- We only need one address variable for the entire selective accept. So
4501 -- the Ann declaration is created only for the first accept alternative,
4502 -- and subsequent accept alternatives reference the same Ann variable.
4504 -- We can distinguish the two cases by seeing whether the accept statement
4505 -- is part of a list. If not, then it must be in an accept alternative.
4507 -- To expand the requeue statement, a label is provided at the end of the
4508 -- accept statement or alternative of which it is a part, so that the
4509 -- statement can be skipped after the requeue is complete. This label is
4510 -- created here rather than during the expansion of the accept statement,
4511 -- because it will be needed by any requeue statements within the accept,
4512 -- which are expanded before the accept.
4514 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4515 Loc : constant Source_Ptr := Sloc (N);
4516 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4517 Ann : Entity_Id := Empty;
4525 if Expander_Active then
4527 -- If we have no handled statement sequence, we may need to build
4528 -- a dummy sequence consisting of a null statement. This can be
4529 -- skipped if the trivial accept optimization is permitted.
4531 if not Trivial_Accept_OK
4533 (No (Stats) or else Null_Statements (Statements (Stats)))
4535 Set_Handled_Statement_Sequence (N,
4536 Make_Handled_Sequence_Of_Statements (Loc,
4537 New_List (Make_Null_Statement (Loc))));
4540 -- Create and declare two labels to be placed at the end of the
4541 -- accept statement. The first label is used to allow requeues to
4542 -- skip the remainder of entry processing. The second label is used
4543 -- to skip the remainder of entry processing if the rendezvous
4544 -- completes in the middle of the accept body.
4546 if Present (Handled_Statement_Sequence (N)) then
4547 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4549 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4550 Lab := Make_Label (Loc, Lab_Id);
4552 Make_Implicit_Label_Declaration (Loc,
4553 Defining_Identifier => Entity (Lab_Id),
4554 Label_Construct => Lab);
4555 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4557 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4559 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4560 Lab := Make_Label (Loc, Lab_Id);
4562 Make_Implicit_Label_Declaration (Loc,
4563 Defining_Identifier => Entity (Lab_Id),
4564 Label_Construct => Lab);
4565 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4572 -- Case of stand alone accept statement
4574 if Is_List_Member (N) then
4576 if Present (Handled_Statement_Sequence (N)) then
4578 Make_Defining_Identifier (Loc,
4579 Chars => New_Internal_Name ('A'));
4582 Make_Object_Declaration (Loc,
4583 Defining_Identifier => Ann,
4584 Object_Definition =>
4585 New_Reference_To (RTE (RE_Address), Loc));
4587 Insert_Before (N, Adecl);
4590 Insert_Before (N, Ldecl);
4593 Insert_Before (N, Ldecl2);
4597 -- Case of accept statement which is in an accept alternative
4601 Acc_Alt : constant Node_Id := Parent (N);
4602 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4606 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4607 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4609 -- ??? Consider a single label for select statements
4611 if Present (Handled_Statement_Sequence (N)) then
4613 Statements (Handled_Statement_Sequence (N)));
4617 Statements (Handled_Statement_Sequence (N)));
4621 -- Find first accept alternative of the selective accept. A
4622 -- valid selective accept must have at least one accept in it.
4624 Alt := First (Select_Alternatives (Sel_Acc));
4626 while Nkind (Alt) /= N_Accept_Alternative loop
4630 -- If we are the first accept statement, then we have to create
4631 -- the Ann variable, as for the stand alone case, except that
4632 -- it is inserted before the selective accept. Similarly, a
4633 -- label for requeue expansion must be declared.
4635 if N = Accept_Statement (Alt) then
4637 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4640 Make_Object_Declaration (Loc,
4641 Defining_Identifier => Ann,
4642 Object_Definition =>
4643 New_Reference_To (RTE (RE_Address), Loc));
4645 Insert_Before (Sel_Acc, Adecl);
4648 -- If we are not the first accept statement, then find the Ann
4649 -- variable allocated by the first accept and use it.
4653 Node (Last_Elmt (Accept_Address
4654 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4659 -- Merge here with Ann either created or referenced, and Adecl
4660 -- pointing to the corresponding declaration. Remaining processing
4661 -- is the same for the two cases.
4663 if Present (Ann) then
4664 Append_Elmt (Ann, Accept_Address (Ent));
4665 Set_Debug_Info_Needed (Ann);
4668 -- Create renaming declarations for the entry formals. Each reference
4669 -- to a formal becomes a dereference of a component of the parameter
4670 -- block, whose address is held in Ann. These declarations are
4671 -- eventually inserted into the accept block, and analyzed there so
4672 -- that they have the proper scope for gdb and do not conflict with
4673 -- other declarations.
4675 if Present (Parameter_Specifications (N))
4676 and then Present (Handled_Statement_Sequence (N))
4686 Formal := First_Formal (Ent);
4688 while Present (Formal) loop
4689 Comp := Entry_Component (Formal);
4691 Make_Defining_Identifier (Loc, Chars (Formal));
4693 Set_Etype (New_F, Etype (Formal));
4694 Set_Scope (New_F, Ent);
4696 -- Now we set debug info needed on New_F even though it does
4697 -- not come from source, so that the debugger will get the
4698 -- right information for these generated names.
4700 Set_Debug_Info_Needed (New_F);
4702 if Ekind (Formal) = E_In_Parameter then
4703 Set_Ekind (New_F, E_Constant);
4705 Set_Ekind (New_F, E_Variable);
4706 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4709 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4712 Make_Object_Renaming_Declaration (Loc,
4713 Defining_Identifier =>
4716 New_Reference_To (Etype (Formal), Loc),
4718 Make_Explicit_Dereference (Loc,
4719 Make_Selected_Component (Loc,
4721 Unchecked_Convert_To (
4722 Entry_Parameters_Type (Ent),
4723 New_Reference_To (Ann, Loc)),
4725 New_Reference_To (Comp, Loc))));
4727 if No (Declarations (N)) then
4728 Set_Declarations (N, New_List);
4731 Append (Decl, Declarations (N));
4732 Set_Renamed_Object (Formal, New_F);
4733 Next_Formal (Formal);
4740 end Expand_Accept_Declarations;
4742 ---------------------------------------------
4743 -- Expand_Access_Protected_Subprogram_Type --
4744 ---------------------------------------------
4746 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4747 Loc : constant Source_Ptr := Sloc (N);
4749 T : constant Entity_Id := Defining_Identifier (N);
4750 D_T : constant Entity_Id := Designated_Type (T);
4751 D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc,
4752 Chars => New_Internal_Name ('D'));
4753 E_T : constant Entity_Id := Make_Defining_Identifier (Loc,
4754 Chars => New_Internal_Name ('E'));
4755 P_List : constant List_Id := Build_Protected_Spec
4756 (N, RTE (RE_Address), D_T, False);
4762 -- Create access to subprogram with full signature
4764 if Etype (D_T) /= Standard_Void_Type then
4766 Make_Access_Function_Definition (Loc,
4767 Parameter_Specifications => P_List,
4768 Result_Definition =>
4769 Copy_Result_Type (Result_Definition (Type_Definition (N))));
4773 Make_Access_Procedure_Definition (Loc,
4774 Parameter_Specifications => P_List);
4778 Make_Full_Type_Declaration (Loc,
4779 Defining_Identifier => D_T2,
4780 Type_Definition => Def1);
4782 Insert_After (N, Decl1);
4785 -- Create Equivalent_Type, a record with two components for an access to
4786 -- object and an access to subprogram.
4789 Make_Component_Declaration (Loc,
4790 Defining_Identifier =>
4791 Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
4792 Component_Definition =>
4793 Make_Component_Definition (Loc,
4794 Aliased_Present => False,
4795 Subtype_Indication =>
4796 New_Occurrence_Of (RTE (RE_Address), Loc))),
4798 Make_Component_Declaration (Loc,
4799 Defining_Identifier =>
4800 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4801 Component_Definition =>
4802 Make_Component_Definition (Loc,
4803 Aliased_Present => False,
4804 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4807 Make_Full_Type_Declaration (Loc,
4808 Defining_Identifier => E_T,
4810 Make_Record_Definition (Loc,
4812 Make_Component_List (Loc,
4813 Component_Items => Comps)));
4815 Insert_After (Decl1, Decl2);
4817 Set_Equivalent_Type (T, E_T);
4818 end Expand_Access_Protected_Subprogram_Type;
4820 --------------------------
4821 -- Expand_Entry_Barrier --
4822 --------------------------
4824 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4825 Cond : constant Node_Id :=
4826 Condition (Entry_Body_Formal_Part (N));
4827 Prot : constant Entity_Id := Scope (Ent);
4828 Spec_Decl : constant Node_Id := Parent (Prot);
4831 Body_Decl : Node_Id;
4834 if No_Run_Time_Mode then
4835 Error_Msg_CRT ("entry barrier", N);
4839 -- The body of the entry barrier must be analyzed in the context of the
4840 -- protected object, but its scope is external to it, just as any other
4841 -- unprotected version of a protected operation. The specification has
4842 -- been produced when the protected type declaration was elaborated. We
4843 -- build the body, insert it in the enclosing scope, but analyze it in
4844 -- the current context. A more uniform approach would be to treat the
4845 -- barrier just as a protected function, and discard the protected
4846 -- version of it because it is never called.
4848 if Expander_Active then
4849 B_F := Build_Barrier_Function (N, Ent, Prot);
4850 Func := Barrier_Function (Ent);
4851 Set_Corresponding_Spec (B_F, Func);
4853 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
4855 if Nkind (Parent (Body_Decl)) = N_Subunit then
4856 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
4859 Insert_Before_And_Analyze (Body_Decl, B_F);
4861 Set_Discriminals (Spec_Decl);
4862 Set_Scope (Func, Scope (Prot));
4865 Analyze_And_Resolve (Cond, Any_Boolean);
4868 -- The Ravenscar profile restricts barriers to simple variables declared
4869 -- within the protected object. We also allow Boolean constants, since
4870 -- these appear in several published examples and are also allowed by
4871 -- the Aonix compiler.
4873 -- Note that after analysis variables in this context will be replaced
4874 -- by the corresponding prival, that is to say a renaming of a selected
4875 -- component of the form _Object.Var. If expansion is disabled, as
4876 -- within a generic, we check that the entity appears in the current
4879 if Is_Entity_Name (Cond) then
4881 -- A small optimization of useless renamings. If the scope of the
4882 -- entity of the condition is not the barrier function, then the
4883 -- condition does not reference any of the generated renamings
4884 -- within the function.
4887 and then Scope (Entity (Cond)) /= Func
4889 Set_Declarations (B_F, Empty_List);
4892 if Entity (Cond) = Standard_False
4894 Entity (Cond) = Standard_True
4898 elsif not Expander_Active
4899 and then Scope (Entity (Cond)) = Current_Scope
4903 -- Check for case of _object.all.field (note that the explicit
4904 -- dereference gets inserted by analyze/expand of _object.field)
4906 elsif Present (Renamed_Object (Entity (Cond)))
4908 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
4912 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
4918 -- It is not a boolean variable or literal, so check the restriction
4920 Check_Restriction (Simple_Barriers, Cond);
4921 end Expand_Entry_Barrier;
4923 ------------------------------
4924 -- Expand_N_Abort_Statement --
4925 ------------------------------
4927 -- Expand abort T1, T2, .. Tn; into:
4928 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
4930 procedure Expand_N_Abort_Statement (N : Node_Id) is
4931 Loc : constant Source_Ptr := Sloc (N);
4932 Tlist : constant List_Id := Names (N);
4938 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
4941 Tasknm := First (Tlist);
4943 while Present (Tasknm) loop
4946 -- A task interface class-wide type object is being aborted.
4947 -- Retrieve its _task_id by calling a dispatching routine.
4949 if Ada_Version >= Ada_05
4950 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
4951 and then Is_Interface (Etype (Tasknm))
4952 and then Is_Task_Interface (Etype (Tasknm))
4954 Append_To (Component_Associations (Aggr),
4955 Make_Component_Association (Loc,
4956 Choices => New_List (
4957 Make_Integer_Literal (Loc, Count)),
4960 -- Task_Id (Tasknm._disp_get_task_id)
4962 Make_Unchecked_Type_Conversion (Loc,
4964 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
4966 Make_Selected_Component (Loc,
4968 New_Copy_Tree (Tasknm),
4970 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
4973 Append_To (Component_Associations (Aggr),
4974 Make_Component_Association (Loc,
4975 Choices => New_List (
4976 Make_Integer_Literal (Loc, Count)),
4977 Expression => Concurrent_Ref (Tasknm)));
4984 Make_Procedure_Call_Statement (Loc,
4985 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
4986 Parameter_Associations => New_List (
4987 Make_Qualified_Expression (Loc,
4988 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
4989 Expression => Aggr))));
4992 end Expand_N_Abort_Statement;
4994 -------------------------------
4995 -- Expand_N_Accept_Statement --
4996 -------------------------------
4998 -- This procedure handles expansion of accept statements that stand
4999 -- alone, i.e. they are not part of an accept alternative. The expansion
5000 -- of accept statement in accept alternatives is handled by the routines
5001 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5002 -- following description applies only to stand alone accept statements.
5004 -- If there is no handled statement sequence, or only null statements,
5005 -- then this is called a trivial accept, and the expansion is:
5007 -- Accept_Trivial (entry-index)
5009 -- If there is a handled statement sequence, then the expansion is:
5016 -- Accept_Call (entry-index, Ann);
5017 -- Renaming_Declarations for formals
5018 -- <statement sequence from N_Accept_Statement node>
5019 -- Complete_Rendezvous;
5024 -- <exception handler from N_Accept_Statement node>
5025 -- Complete_Rendezvous;
5027 -- <exception handler from N_Accept_Statement node>
5028 -- Complete_Rendezvous;
5033 -- when all others =>
5034 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5037 -- The first three declarations were already inserted ahead of the accept
5038 -- statement by the Expand_Accept_Declarations procedure, which was called
5039 -- directly from the semantics during analysis of the accept statement,
5040 -- before analyzing its contained statements.
5042 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5043 -- from possible expansion activity (the original source of course does
5044 -- not have any declarations associated with the accept statement, since
5045 -- an accept statement has no declarative part). In particular, if the
5046 -- expander is active, the first such declaration is the declaration of
5047 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5049 -- The two blocks are merged into a single block if the inner block has
5050 -- no exception handlers, but otherwise two blocks are required, since
5051 -- exceptions might be raised in the exception handlers of the inner
5052 -- block, and Exceptional_Complete_Rendezvous must be called.
5054 procedure Expand_N_Accept_Statement (N : Node_Id) is
5055 Loc : constant Source_Ptr := Sloc (N);
5056 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5057 Ename : constant Node_Id := Entry_Direct_Name (N);
5058 Eindx : constant Node_Id := Entry_Index (N);
5059 Eent : constant Entity_Id := Entity (Ename);
5060 Acstack : constant Elist_Id := Accept_Address (Eent);
5061 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5062 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5067 -- Start of processing for Expand_N_Accept_Statement
5070 -- If accept statement is not part of a list, then its parent must be
5071 -- an accept alternative, and, as described above, we do not do any
5072 -- expansion for such accept statements at this level.
5074 if not Is_List_Member (N) then
5075 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5078 -- Trivial accept case (no statement sequence, or null statements).
5079 -- If the accept statement has declarations, then just insert them
5080 -- before the procedure call.
5082 elsif Trivial_Accept_OK
5083 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5085 -- Remove declarations for renamings, because the parameter block
5086 -- will not be assigned.
5093 D := First (Declarations (N));
5095 while Present (D) loop
5097 if Nkind (D) = N_Object_Renaming_Declaration then
5105 if Present (Declarations (N)) then
5106 Insert_Actions (N, Declarations (N));
5110 Make_Procedure_Call_Statement (Loc,
5111 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5112 Parameter_Associations => New_List (
5113 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5117 -- Discard Entry_Address that was created for it, so it will not be
5118 -- emitted if this accept statement is in the statement part of a
5119 -- delay alternative.
5121 if Present (Stats) then
5122 Remove_Last_Elmt (Acstack);
5125 -- Case of statement sequence present
5128 -- Construct the block, using the declarations from the accept
5129 -- statement if any to initialize the declarations of the block.
5131 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5132 Set_Ekind (Blkent, E_Block);
5133 Set_Etype (Blkent, Standard_Void_Type);
5134 Set_Scope (Blkent, Current_Scope);
5137 Make_Block_Statement (Loc,
5138 Identifier => New_Reference_To (Blkent, Loc),
5139 Declarations => Declarations (N),
5140 Handled_Statement_Sequence => Build_Accept_Body (N));
5142 -- Prepend call to Accept_Call to main statement sequence If the
5143 -- accept has exception handlers, the statement sequence is wrapped
5144 -- in a block. Insert call and renaming declarations in the
5145 -- declarations of the block, so they are elaborated before the
5149 Make_Procedure_Call_Statement (Loc,
5150 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5151 Parameter_Associations => New_List (
5152 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5153 New_Reference_To (Ann, Loc)));
5155 if Parent (Stats) = N then
5156 Prepend (Call, Statements (Stats));
5165 Push_Scope (Blkent);
5173 D := First (Declarations (N));
5174 while Present (D) loop
5177 if Nkind (D) = N_Object_Renaming_Declaration then
5179 -- The renaming declarations for the formals were created
5180 -- during analysis of the accept statement, and attached to
5181 -- the list of declarations. Place them now in the context
5182 -- of the accept block or subprogram.
5185 Typ := Entity (Subtype_Mark (D));
5186 Insert_After (Call, D);
5189 -- If the formal is class_wide, it does not have an actual
5190 -- subtype. The analysis of the renaming declaration creates
5191 -- one, but we need to retain the class-wide nature of the
5194 if Is_Class_Wide_Type (Typ) then
5195 Set_Etype (Defining_Identifier (D), Typ);
5206 -- Replace the accept statement by the new block
5211 -- Last step is to unstack the Accept_Address value
5213 Remove_Last_Elmt (Acstack);
5215 end Expand_N_Accept_Statement;
5217 ----------------------------------
5218 -- Expand_N_Asynchronous_Select --
5219 ----------------------------------
5221 -- This procedure assumes that the trigger statement is an entry call or
5222 -- a dispatching procedure call. A delay alternative should already have
5223 -- been expanded into an entry call to the appropriate delay object Wait
5226 -- If the trigger is a task entry call, the select is implemented with
5227 -- a Task_Entry_Call:
5232 -- P : parms := (parm, parm, parm);
5234 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5236 -- procedure _clean is
5239 -- Cancel_Task_Entry_Call (C);
5246 -- (<acceptor-task>, -- Acceptor
5247 -- <entry-index>, -- E
5248 -- P'Address, -- Uninterpreted_Data
5249 -- Asynchronous_Call, -- Mode
5250 -- B); -- Rendezvous_Successful
5257 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5260 -- when Abort_Signal => Abort_Undefer;
5267 -- <triggered-statements>
5271 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5272 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5276 -- P : parms := (parm, parm, parm);
5278 -- Call_Simple (acceptor-task, entry-index, P'Address);
5284 -- so the task at hand is to convert the latter expansion into the former
5286 -- If the trigger is a protected entry call, the select is implemented
5287 -- with Protected_Entry_Call:
5290 -- P : E1_Params := (param, param, param);
5291 -- Bnn : Communications_Block;
5296 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5298 -- procedure _clean is
5301 -- if Enqueued (Bnn) then
5302 -- Cancel_Protected_Entry_Call (Bnn);
5309 -- Protected_Entry_Call
5310 -- (po._object'Access, -- Object
5311 -- <entry index>, -- E
5312 -- P'Address, -- Uninterpreted_Data
5313 -- Asynchronous_Call, -- Mode
5316 -- if Enqueued (Bnn) then
5320 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5323 -- when Abort_Signal => Abort_Undefer;
5326 -- if not Cancelled (Bnn) then
5327 -- <triggered-statements>
5331 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5335 -- P : E1_Params := (param, param, param);
5336 -- Bnn : Communications_Block;
5339 -- Protected_Entry_Call
5340 -- (po._object'Access, -- Object
5341 -- <entry index>, -- E
5342 -- P'Address, -- Uninterpreted_Data
5343 -- Simple_Call, -- Mode
5350 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5354 -- B : Boolean := False;
5355 -- Bnn : Communication_Block;
5356 -- C : Ada.Tags.Prim_Op_Kind;
5357 -- D : System.Storage_Elements.Dummy_Communication_Block;
5358 -- K : Ada.Tags.Tagged_Kind :=
5359 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5360 -- P : Parameters := (Param1 .. ParamN);
5365 -- if K = Ada.Tags.TK_Limited_Tagged then
5366 -- <dispatching-call>;
5367 -- <triggering-statements>;
5371 -- Ada.Tags.Get_Offset_Index
5372 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5374 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5376 -- if C = POK_Protected_Entry then
5378 -- procedure _clean is
5380 -- if Enqueued (Bnn) then
5381 -- Cancel_Protected_Entry_Call (Bnn);
5387 -- _Disp_Asynchronous_Select
5388 -- (<object>, S, P'Address, D, B);
5389 -- Bnn := Communication_Block (D);
5391 -- Param1 := P.Param1;
5393 -- ParamN := P.ParamN;
5395 -- if Enqueued (Bnn) then
5396 -- <abortable-statements>
5399 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5402 -- when Abort_Signal => Abort_Undefer;
5405 -- if not Cancelled (Bnn) then
5406 -- <triggering-statements>
5409 -- elsif C = POK_Task_Entry then
5411 -- procedure _clean is
5413 -- Cancel_Task_Entry_Call (U);
5419 -- _Disp_Asynchronous_Select
5420 -- (<object>, S, P'Address, D, B);
5421 -- Bnn := Communication_Bloc (D);
5423 -- Param1 := P.Param1;
5425 -- ParamN := P.ParamN;
5430 -- <abortable-statements>
5432 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5435 -- when Abort_Signal => Abort_Undefer;
5439 -- <triggering-statements>
5444 -- <dispatching-call>;
5445 -- <triggering-statements>
5450 -- The job is to convert this to the asynchronous form
5452 -- If the trigger is a delay statement, it will have been expanded into a
5453 -- call to one of the GNARL delay procedures. This routine will convert
5454 -- this into a protected entry call on a delay object and then continue
5455 -- processing as for a protected entry call trigger. This requires
5456 -- declaring a Delay_Block object and adding a pointer to this object to
5457 -- the parameter list of the delay procedure to form the parameter list of
5458 -- the entry call. This object is used by the runtime to queue the delay
5461 -- For a description of the use of P and the assignments after the call,
5462 -- see Expand_N_Entry_Call_Statement.
5464 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5465 Loc : constant Source_Ptr := Sloc (N);
5466 Abrt : constant Node_Id := Abortable_Part (N);
5467 Astats : constant List_Id := Statements (Abrt);
5468 Trig : constant Node_Id := Triggering_Alternative (N);
5469 Tstats : constant List_Id := Statements (Trig);
5471 Abort_Block_Ent : Entity_Id;
5472 Abortable_Block : Node_Id;
5474 Blk_Ent : Entity_Id;
5475 Blk_Typ : Entity_Id;
5477 Call_Ent : Entity_Id;
5478 Cancel_Param : Entity_Id;
5479 Cleanup_Block : Node_Id;
5480 Cleanup_Block_Ent : Entity_Id;
5481 Cleanup_Stmts : List_Id;
5482 Conc_Typ_Stmts : List_Id;
5484 Dblock_Ent : Entity_Id;
5489 Enqueue_Call : Node_Id;
5493 Lim_Typ_Stmts : List_Id;
5499 ProtE_Stmts : List_Id;
5500 ProtP_Stmts : List_Id;
5503 Target_Undefer : RE_Id;
5504 TaskE_Stmts : List_Id;
5505 Undefer_Args : List_Id := No_List;
5507 B : Entity_Id; -- Call status flag
5508 Bnn : Entity_Id; -- Communication block
5509 C : Entity_Id; -- Call kind
5510 K : Entity_Id; -- Tagged kind
5511 P : Entity_Id; -- Parameter block
5512 S : Entity_Id; -- Primitive operation slot
5513 T : Entity_Id; -- Additional status flag
5516 Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5517 Ecall := Triggering_Statement (Trig);
5519 -- The arguments in the call may require dynamic allocation, and the
5520 -- call statement may have been transformed into a block. The block
5521 -- may contain additional declarations for internal entities, and the
5522 -- original call is found by sequential search.
5524 if Nkind (Ecall) = N_Block_Statement then
5525 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5526 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5527 N_Entry_Call_Statement)
5533 -- This is either a dispatching call or a delay statement used as a
5534 -- trigger which was expanded into a procedure call.
5536 if Nkind (Ecall) = N_Procedure_Call_Statement then
5537 if Ada_Version >= Ada_05
5539 (No (Original_Node (Ecall))
5540 or else not Nkind_In (Original_Node (Ecall),
5541 N_Delay_Relative_Statement,
5542 N_Delay_Until_Statement))
5544 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5549 -- Call status flag processing, generate:
5550 -- B : Boolean := False;
5552 B := Build_B (Loc, Decls);
5554 -- Communication block processing, generate:
5555 -- Bnn : Communication_Block;
5557 Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
5560 Make_Object_Declaration (Loc,
5561 Defining_Identifier =>
5563 Object_Definition =>
5564 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5566 -- Call kind processing, generate:
5567 -- C : Ada.Tags.Prim_Op_Kind;
5569 C := Build_C (Loc, Decls);
5571 -- Tagged kind processing, generate:
5572 -- K : Ada.Tags.Tagged_Kind :=
5573 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5575 -- Dummy communication block, generate:
5576 -- D : Dummy_Communication_Block;
5579 Make_Object_Declaration (Loc,
5580 Defining_Identifier =>
5581 Make_Defining_Identifier (Loc, Name_uD),
5582 Object_Definition =>
5584 RTE (RE_Dummy_Communication_Block), Loc)));
5586 K := Build_K (Loc, Decls, Obj);
5588 -- Parameter block processing
5590 Blk_Typ := Build_Parameter_Block
5591 (Loc, Actuals, Formals, Decls);
5592 P := Parameter_Block_Pack
5593 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5595 -- Dispatch table slot processing, generate:
5598 S := Build_S (Loc, Decls);
5600 -- Additional status flag processing, generate:
5602 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
5605 Make_Object_Declaration (Loc,
5606 Defining_Identifier =>
5608 Object_Definition =>
5609 New_Reference_To (Standard_Boolean, Loc)));
5611 ------------------------------
5612 -- Protected entry handling --
5613 ------------------------------
5616 -- Param1 := P.Param1;
5618 -- ParamN := P.ParamN;
5620 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5623 -- Bnn := Communication_Block (D);
5625 Prepend_To (Cleanup_Stmts,
5626 Make_Assignment_Statement (Loc,
5628 New_Reference_To (Bnn, Loc),
5630 Make_Unchecked_Type_Conversion (Loc,
5632 New_Reference_To (RTE (RE_Communication_Block), Loc),
5634 Make_Identifier (Loc, Name_uD))));
5637 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5639 Prepend_To (Cleanup_Stmts,
5640 Make_Procedure_Call_Statement (Loc,
5643 Find_Prim_Op (Etype (Etype (Obj)),
5644 Name_uDisp_Asynchronous_Select),
5646 Parameter_Associations =>
5648 New_Copy_Tree (Obj), -- <object>
5649 New_Reference_To (S, Loc), -- S
5650 Make_Attribute_Reference (Loc, -- P'Address
5652 New_Reference_To (P, Loc),
5655 Make_Identifier (Loc, Name_uD), -- D
5656 New_Reference_To (B, Loc)))); -- B
5659 -- if Enqueued (Bnn) then
5660 -- <abortable-statements>
5663 Append_To (Cleanup_Stmts,
5664 Make_If_Statement (Loc,
5666 Make_Function_Call (Loc,
5668 New_Reference_To (RTE (RE_Enqueued), Loc),
5669 Parameter_Associations =>
5671 New_Reference_To (Bnn, Loc))),
5674 New_Copy_List_Tree (Astats)));
5676 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5677 -- will then generate a _clean for the communication block Bnn.
5681 -- procedure _clean is
5683 -- if Enqueued (Bnn) then
5684 -- Cancel_Protected_Entry_Call (Bnn);
5693 Cleanup_Block_Ent :=
5694 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5697 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5699 -- Wrap the cleanup block in an exception handling block
5705 -- when Abort_Signal => Abort_Undefer;
5709 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5713 Make_Implicit_Label_Declaration (Loc,
5714 Defining_Identifier =>
5718 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5721 -- if not Cancelled (Bnn) then
5722 -- <triggering-statements>
5725 Append_To (ProtE_Stmts,
5726 Make_If_Statement (Loc,
5730 Make_Function_Call (Loc,
5732 New_Reference_To (RTE (RE_Cancelled), Loc),
5733 Parameter_Associations =>
5735 New_Reference_To (Bnn, Loc)))),
5738 New_Copy_List_Tree (Tstats)));
5740 -------------------------
5741 -- Task entry handling --
5742 -------------------------
5745 -- Param1 := P.Param1;
5747 -- ParamN := P.ParamN;
5749 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5752 -- Bnn := Communication_Block (D);
5754 Append_To (TaskE_Stmts,
5755 Make_Assignment_Statement (Loc,
5757 New_Reference_To (Bnn, Loc),
5759 Make_Unchecked_Type_Conversion (Loc,
5761 New_Reference_To (RTE (RE_Communication_Block), Loc),
5763 Make_Identifier (Loc, Name_uD))));
5766 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5768 Prepend_To (TaskE_Stmts,
5769 Make_Procedure_Call_Statement (Loc,
5772 Find_Prim_Op (Etype (Etype (Obj)),
5773 Name_uDisp_Asynchronous_Select),
5775 Parameter_Associations =>
5777 New_Copy_Tree (Obj), -- <object>
5778 New_Reference_To (S, Loc), -- S
5779 Make_Attribute_Reference (Loc, -- P'Address
5781 New_Reference_To (P, Loc),
5784 Make_Identifier (Loc, Name_uD), -- D
5785 New_Reference_To (B, Loc)))); -- B
5790 Prepend_To (TaskE_Stmts,
5791 Make_Procedure_Call_Statement (Loc,
5793 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5794 Parameter_Associations =>
5799 -- <abortable-statements>
5801 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5803 Prepend_To (Cleanup_Stmts,
5804 Make_Procedure_Call_Statement (Loc,
5806 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5807 Parameter_Associations =>
5810 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5811 -- will generate a _clean for the additional status flag.
5815 -- procedure _clean is
5817 -- Cancel_Task_Entry_Call (U);
5825 Cleanup_Block_Ent :=
5826 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5829 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
5831 -- Wrap the cleanup block in an exception handling block
5837 -- when Abort_Signal => Abort_Undefer;
5841 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5843 Append_To (TaskE_Stmts,
5844 Make_Implicit_Label_Declaration (Loc,
5845 Defining_Identifier =>
5848 Append_To (TaskE_Stmts,
5850 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5854 -- <triggering-statements>
5857 Append_To (TaskE_Stmts,
5858 Make_If_Statement (Loc,
5862 New_Reference_To (T, Loc)),
5865 New_Copy_List_Tree (Tstats)));
5867 ----------------------------------
5868 -- Protected procedure handling --
5869 ----------------------------------
5872 -- <dispatching-call>;
5873 -- <triggering-statements>
5875 ProtP_Stmts := New_Copy_List_Tree (Tstats);
5876 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
5879 -- S := Ada.Tags.Get_Offset_Index
5880 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
5883 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
5886 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5888 Append_To (Conc_Typ_Stmts,
5889 Make_Procedure_Call_Statement (Loc,
5892 Find_Prim_Op (Etype (Etype (Obj)),
5893 Name_uDisp_Get_Prim_Op_Kind),
5895 Parameter_Associations =>
5897 New_Copy_Tree (Obj),
5898 New_Reference_To (S, Loc),
5899 New_Reference_To (C, Loc))));
5902 -- if C = POK_Procedure_Entry then
5904 -- elsif C = POK_Task_Entry then
5910 Append_To (Conc_Typ_Stmts,
5911 Make_If_Statement (Loc,
5915 New_Reference_To (C, Loc),
5917 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
5924 Make_Elsif_Part (Loc,
5928 New_Reference_To (C, Loc),
5930 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
5939 -- <dispatching-call>;
5940 -- <triggering-statements>
5942 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
5943 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
5946 -- if K = Ada.Tags.TK_Limited_Tagged then
5953 Make_If_Statement (Loc,
5957 New_Reference_To (K, Loc),
5959 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
5968 Make_Block_Statement (Loc,
5971 Handled_Statement_Sequence =>
5972 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5977 -- Delay triggering statement processing
5980 -- Add a Delay_Block object to the parameter list of the delay
5981 -- procedure to form the parameter list of the Wait entry call.
5984 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
5986 Pdef := Entity (Name (Ecall));
5988 if Is_RTE (Pdef, RO_CA_Delay_For) then
5990 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
5992 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
5994 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
5996 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
5997 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6000 Append_To (Parameter_Associations (Ecall),
6001 Make_Attribute_Reference (Loc,
6002 Prefix => New_Reference_To (Dblock_Ent, Loc),
6003 Attribute_Name => Name_Unchecked_Access));
6005 -- Create the inner block to protect the abortable part
6008 Make_Implicit_Exception_Handler (Loc,
6009 Exception_Choices =>
6010 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6011 Statements => New_List (
6012 Make_Procedure_Call_Statement (Loc,
6013 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6016 Make_Procedure_Call_Statement (Loc,
6017 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6020 Make_Block_Statement (Loc,
6021 Identifier => New_Reference_To (Blk_Ent, Loc),
6022 Handled_Statement_Sequence =>
6023 Make_Handled_Sequence_Of_Statements (Loc,
6024 Statements => Astats),
6025 Has_Created_Identifier => True,
6026 Is_Asynchronous_Call_Block => True);
6028 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6031 Make_Implicit_If_Statement (N,
6032 Condition => Make_Function_Call (Loc,
6033 Name => Enqueue_Call,
6034 Parameter_Associations => Parameter_Associations (Ecall)),
6036 New_List (Make_Block_Statement (Loc,
6037 Handled_Statement_Sequence =>
6038 Make_Handled_Sequence_Of_Statements (Loc,
6039 Statements => New_List (
6040 Make_Implicit_Label_Declaration (Loc,
6041 Defining_Identifier => Blk_Ent,
6042 Label_Construct => Abortable_Block),
6044 Exception_Handlers => Hdle)))));
6046 Stmts := New_List (Ecall);
6048 -- Construct statement sequence for new block
6051 Make_Implicit_If_Statement (N,
6052 Condition => Make_Function_Call (Loc,
6053 Name => New_Reference_To (
6054 RTE (RE_Timed_Out), Loc),
6055 Parameter_Associations => New_List (
6056 Make_Attribute_Reference (Loc,
6057 Prefix => New_Reference_To (Dblock_Ent, Loc),
6058 Attribute_Name => Name_Unchecked_Access))),
6059 Then_Statements => Tstats));
6061 -- The result is the new block
6063 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6066 Make_Block_Statement (Loc,
6067 Declarations => New_List (
6068 Make_Object_Declaration (Loc,
6069 Defining_Identifier => Dblock_Ent,
6070 Aliased_Present => True,
6071 Object_Definition => New_Reference_To (
6072 RTE (RE_Delay_Block), Loc))),
6074 Handled_Statement_Sequence =>
6075 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6085 Extract_Entry (Ecall, Concval, Ename, Index);
6086 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6088 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6089 Decls := Declarations (Ecall);
6091 if Is_Protected_Type (Etype (Concval)) then
6093 -- Get the declarations of the block expanded from the entry call
6095 Decl := First (Decls);
6096 while Present (Decl)
6098 (Nkind (Decl) /= N_Object_Declaration
6099 or else not Is_RTE (Etype (Object_Definition (Decl)),
6100 RE_Communication_Block))
6105 pragma Assert (Present (Decl));
6106 Cancel_Param := Defining_Identifier (Decl);
6108 -- Change the mode of the Protected_Entry_Call call
6110 -- Protected_Entry_Call (
6111 -- Object => po._object'Access,
6112 -- E => <entry index>;
6113 -- Uninterpreted_Data => P'Address;
6114 -- Mode => Asynchronous_Call;
6117 Stmt := First (Stmts);
6119 -- Skip assignments to temporaries created for in-out parameters
6121 -- This makes unwarranted assumptions about the shape of the expanded
6122 -- tree for the call, and should be cleaned up ???
6124 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6130 Param := First (Parameter_Associations (Call));
6131 while Present (Param)
6132 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6137 pragma Assert (Present (Param));
6138 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6141 -- Append an if statement to execute the abortable part
6144 -- if Enqueued (Bnn) then
6147 Make_Implicit_If_Statement (N,
6148 Condition => Make_Function_Call (Loc,
6149 Name => New_Reference_To (
6150 RTE (RE_Enqueued), Loc),
6151 Parameter_Associations => New_List (
6152 New_Reference_To (Cancel_Param, Loc))),
6153 Then_Statements => Astats));
6156 Make_Block_Statement (Loc,
6157 Identifier => New_Reference_To (Blk_Ent, Loc),
6158 Handled_Statement_Sequence =>
6159 Make_Handled_Sequence_Of_Statements (Loc,
6160 Statements => Stmts),
6161 Has_Created_Identifier => True,
6162 Is_Asynchronous_Call_Block => True);
6164 -- For the VM call Update_Exception instead of Abort_Undefer.
6165 -- See 4jexcept.ads for an explanation.
6167 if VM_Target = No_VM then
6168 Target_Undefer := RE_Abort_Undefer;
6170 Target_Undefer := RE_Update_Exception;
6172 New_List (Make_Function_Call (Loc,
6173 Name => New_Occurrence_Of
6174 (RTE (RE_Current_Target_Exception), Loc)));
6178 Make_Block_Statement (Loc,
6179 Handled_Statement_Sequence =>
6180 Make_Handled_Sequence_Of_Statements (Loc,
6181 Statements => New_List (
6182 Make_Implicit_Label_Declaration (Loc,
6183 Defining_Identifier => Blk_Ent,
6184 Label_Construct => Abortable_Block),
6189 Exception_Handlers => New_List (
6190 Make_Implicit_Exception_Handler (Loc,
6192 -- when Abort_Signal =>
6193 -- Abort_Undefer.all;
6195 Exception_Choices =>
6196 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6197 Statements => New_List (
6198 Make_Procedure_Call_Statement (Loc,
6199 Name => New_Reference_To (
6200 RTE (Target_Undefer), Loc),
6201 Parameter_Associations => Undefer_Args)))))),
6203 -- if not Cancelled (Bnn) then
6204 -- triggered statements
6207 Make_Implicit_If_Statement (N,
6208 Condition => Make_Op_Not (Loc,
6210 Make_Function_Call (Loc,
6211 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6212 Parameter_Associations => New_List (
6213 New_Occurrence_Of (Cancel_Param, Loc)))),
6214 Then_Statements => Tstats));
6216 -- Asynchronous task entry call
6223 B := Make_Defining_Identifier (Loc, Name_uB);
6225 -- Insert declaration of B in declarations of existing block
6228 Make_Object_Declaration (Loc,
6229 Defining_Identifier => B,
6230 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6232 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6234 -- Insert declaration of C in declarations of existing block
6237 Make_Object_Declaration (Loc,
6238 Defining_Identifier => Cancel_Param,
6239 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6241 -- Remove and save the call to Call_Simple
6243 Stmt := First (Stmts);
6245 -- Skip assignments to temporaries created for in-out parameters.
6246 -- This makes unwarranted assumptions about the shape of the expanded
6247 -- tree for the call, and should be cleaned up ???
6249 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6255 -- Create the inner block to protect the abortable part
6258 Make_Implicit_Exception_Handler (Loc,
6259 Exception_Choices =>
6260 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6263 Make_Procedure_Call_Statement (Loc,
6264 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6267 Make_Procedure_Call_Statement (Loc,
6268 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6271 Make_Block_Statement (Loc,
6272 Identifier => New_Reference_To (Blk_Ent, Loc),
6273 Handled_Statement_Sequence =>
6274 Make_Handled_Sequence_Of_Statements (Loc,
6275 Statements => Astats),
6276 Has_Created_Identifier => True,
6277 Is_Asynchronous_Call_Block => True);
6280 Make_Block_Statement (Loc,
6281 Handled_Statement_Sequence =>
6282 Make_Handled_Sequence_Of_Statements (Loc,
6283 Statements => New_List (
6284 Make_Implicit_Label_Declaration (Loc,
6285 Defining_Identifier =>
6290 Exception_Handlers => Hdle)));
6292 -- Create new call statement
6294 Params := Parameter_Associations (Call);
6297 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6299 New_Reference_To (B, Loc));
6302 Make_Procedure_Call_Statement (Loc,
6304 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6305 Parameter_Associations => Params));
6307 -- Construct statement sequence for new block
6310 Make_Implicit_If_Statement (N,
6313 New_Reference_To (Cancel_Param, Loc)),
6314 Then_Statements => Tstats));
6316 -- Protected the call against abort
6319 Make_Procedure_Call_Statement (Loc,
6320 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6321 Parameter_Associations => Empty_List));
6324 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6326 -- The result is the new block
6329 Make_Block_Statement (Loc,
6330 Declarations => Decls,
6331 Handled_Statement_Sequence =>
6332 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6335 end Expand_N_Asynchronous_Select;
6337 -------------------------------------
6338 -- Expand_N_Conditional_Entry_Call --
6339 -------------------------------------
6341 -- The conditional task entry call is converted to a call to
6346 -- P : parms := (parm, parm, parm);
6350 -- (<acceptor-task>, -- Acceptor
6351 -- <entry-index>, -- E
6352 -- P'Address, -- Uninterpreted_Data
6353 -- Conditional_Call, -- Mode
6354 -- B); -- Rendezvous_Successful
6359 -- normal-statements
6365 -- For a description of the use of P and the assignments after the call,
6366 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6367 -- conditional entry call has already been expanded (by the Expand_N_Entry
6368 -- _Call_Statement procedure) as follows:
6371 -- P : parms := (parm, parm, parm);
6373 -- ... info for in-out parameters
6374 -- Call_Simple (acceptor-task, entry-index, P'Address);
6380 -- so the task at hand is to convert the latter expansion into the former
6382 -- The conditional protected entry call is converted to a call to
6383 -- Protected_Entry_Call:
6386 -- P : parms := (parm, parm, parm);
6387 -- Bnn : Communications_Block;
6390 -- Protected_Entry_Call
6391 -- (po._object'Access, -- Object
6392 -- <entry index>, -- E
6393 -- P'Address, -- Uninterpreted_Data
6394 -- Conditional_Call, -- Mode
6399 -- if Cancelled (Bnn) then
6402 -- normal-statements
6406 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6410 -- B : Boolean := False;
6411 -- C : Ada.Tags.Prim_Op_Kind;
6412 -- K : Ada.Tags.Tagged_Kind :=
6413 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6414 -- P : Parameters := (Param1 .. ParamN);
6418 -- if K = Ada.Tags.TK_Limited_Tagged then
6419 -- <dispatching-call>;
6420 -- <triggering-statements>
6424 -- Ada.Tags.Get_Offset_Index
6425 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6427 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6429 -- if C = POK_Protected_Entry
6430 -- or else C = POK_Task_Entry
6432 -- Param1 := P.Param1;
6434 -- ParamN := P.ParamN;
6438 -- if C = POK_Procedure
6439 -- or else C = POK_Protected_Procedure
6440 -- or else C = POK_Task_Procedure
6442 -- <dispatching-call>;
6445 -- <triggering-statements>
6447 -- <else-statements>
6452 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6453 Loc : constant Source_Ptr := Sloc (N);
6454 Alt : constant Node_Id := Entry_Call_Alternative (N);
6455 Blk : Node_Id := Entry_Call_Statement (Alt);
6458 Blk_Typ : Entity_Id;
6460 Call_Ent : Entity_Id;
6461 Conc_Typ_Stmts : List_Id;
6465 Lim_Typ_Stmts : List_Id;
6472 Transient_Blk : Node_Id;
6475 B : Entity_Id; -- Call status flag
6476 C : Entity_Id; -- Call kind
6477 K : Entity_Id; -- Tagged kind
6478 P : Entity_Id; -- Parameter block
6479 S : Entity_Id; -- Primitive operation slot
6482 if Ada_Version >= Ada_05
6483 and then Nkind (Blk) = N_Procedure_Call_Statement
6485 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6490 -- Call status flag processing, generate:
6491 -- B : Boolean := False;
6493 B := Build_B (Loc, Decls);
6495 -- Call kind processing, generate:
6496 -- C : Ada.Tags.Prim_Op_Kind;
6498 C := Build_C (Loc, Decls);
6500 -- Tagged kind processing, generate:
6501 -- K : Ada.Tags.Tagged_Kind :=
6502 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6504 K := Build_K (Loc, Decls, Obj);
6506 -- Parameter block processing
6508 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6509 P := Parameter_Block_Pack
6510 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6512 -- Dispatch table slot processing, generate:
6515 S := Build_S (Loc, Decls);
6518 -- S := Ada.Tags.Get_Offset_Index
6519 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6522 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6525 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6527 Append_To (Conc_Typ_Stmts,
6528 Make_Procedure_Call_Statement (Loc,
6531 Find_Prim_Op (Etype (Etype (Obj)),
6532 Name_uDisp_Conditional_Select),
6534 Parameter_Associations =>
6536 New_Copy_Tree (Obj), -- <object>
6537 New_Reference_To (S, Loc), -- S
6538 Make_Attribute_Reference (Loc, -- P'Address
6540 New_Reference_To (P, Loc),
6543 New_Reference_To (C, Loc), -- C
6544 New_Reference_To (B, Loc)))); -- B
6547 -- if C = POK_Protected_Entry
6548 -- or else C = POK_Task_Entry
6550 -- Param1 := P.Param1;
6552 -- ParamN := P.ParamN;
6555 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6557 -- Generate the if statement only when the packed parameters need
6558 -- explicit assignments to their corresponding actuals.
6560 if Present (Unpack) then
6561 Append_To (Conc_Typ_Stmts,
6562 Make_If_Statement (Loc,
6569 New_Reference_To (C, Loc),
6571 New_Reference_To (RTE (
6572 RE_POK_Protected_Entry), Loc)),
6576 New_Reference_To (C, Loc),
6578 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6586 -- if C = POK_Procedure
6587 -- or else C = POK_Protected_Procedure
6588 -- or else C = POK_Task_Procedure
6590 -- <dispatching-call>
6592 -- <normal-statements>
6594 -- <else-statements>
6597 N_Stats := New_Copy_List_Tree (Statements (Alt));
6599 Prepend_To (N_Stats,
6600 Make_If_Statement (Loc,
6606 New_Reference_To (C, Loc),
6608 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6615 New_Reference_To (C, Loc),
6617 New_Reference_To (RTE (
6618 RE_POK_Protected_Procedure), Loc)),
6623 New_Reference_To (C, Loc),
6625 New_Reference_To (RTE (
6626 RE_POK_Task_Procedure), Loc)))),
6631 Append_To (Conc_Typ_Stmts,
6632 Make_If_Statement (Loc,
6633 Condition => New_Reference_To (B, Loc),
6634 Then_Statements => N_Stats,
6635 Else_Statements => Else_Statements (N)));
6638 -- <dispatching-call>;
6639 -- <triggering-statements>
6641 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6642 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6645 -- if K = Ada.Tags.TK_Limited_Tagged then
6652 Make_If_Statement (Loc,
6656 New_Reference_To (K, Loc),
6658 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6667 Make_Block_Statement (Loc,
6670 Handled_Statement_Sequence =>
6671 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6673 -- As described above, The entry alternative is transformed into a
6674 -- block that contains the gnulli call, and possibly assignment
6675 -- statements for in-out parameters. The gnulli call may itself be
6676 -- rewritten into a transient block if some unconstrained parameters
6677 -- require it. We need to retrieve the call to complete its parameter
6682 First_Real_Statement (Handled_Statement_Sequence (Blk));
6684 if Present (Transient_Blk)
6685 and then Nkind (Transient_Blk) = N_Block_Statement
6687 Blk := Transient_Blk;
6690 Stmts := Statements (Handled_Statement_Sequence (Blk));
6691 Stmt := First (Stmts);
6692 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6697 Params := Parameter_Associations (Call);
6699 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6701 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6703 Param := First (Params);
6704 while Present (Param)
6705 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6710 pragma Assert (Present (Param));
6711 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6715 -- Find the Communication_Block parameter for the call to the
6716 -- Cancelled function.
6718 Decl := First (Declarations (Blk));
6719 while Present (Decl)
6720 and then not Is_RTE (Etype (Object_Definition (Decl)),
6721 RE_Communication_Block)
6726 -- Add an if statement to execute the else part if the call
6727 -- does not succeed (as indicated by the Cancelled predicate).
6730 Make_Implicit_If_Statement (N,
6731 Condition => Make_Function_Call (Loc,
6732 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6733 Parameter_Associations => New_List (
6734 New_Reference_To (Defining_Identifier (Decl), Loc))),
6735 Then_Statements => Else_Statements (N),
6736 Else_Statements => Statements (Alt)));
6739 B := Make_Defining_Identifier (Loc, Name_uB);
6741 -- Insert declaration of B in declarations of existing block
6743 if No (Declarations (Blk)) then
6744 Set_Declarations (Blk, New_List);
6747 Prepend_To (Declarations (Blk),
6748 Make_Object_Declaration (Loc,
6749 Defining_Identifier => B,
6750 Object_Definition =>
6751 New_Reference_To (Standard_Boolean, Loc)));
6753 -- Create new call statement
6756 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6757 Append_To (Params, New_Reference_To (B, Loc));
6760 Make_Procedure_Call_Statement (Loc,
6761 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6762 Parameter_Associations => Params));
6764 -- Construct statement sequence for new block
6767 Make_Implicit_If_Statement (N,
6768 Condition => New_Reference_To (B, Loc),
6769 Then_Statements => Statements (Alt),
6770 Else_Statements => Else_Statements (N)));
6773 -- The result is the new block
6776 Make_Block_Statement (Loc,
6777 Declarations => Declarations (Blk),
6778 Handled_Statement_Sequence =>
6779 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6783 end Expand_N_Conditional_Entry_Call;
6785 ---------------------------------------
6786 -- Expand_N_Delay_Relative_Statement --
6787 ---------------------------------------
6789 -- Delay statement is implemented as a procedure call to Delay_For
6790 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6791 -- simple delays imposed by the use of Protected Objects.
6793 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6794 Loc : constant Source_Ptr := Sloc (N);
6797 Make_Procedure_Call_Statement (Loc,
6798 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6799 Parameter_Associations => New_List (Expression (N))));
6801 end Expand_N_Delay_Relative_Statement;
6803 ------------------------------------
6804 -- Expand_N_Delay_Until_Statement --
6805 ------------------------------------
6807 -- Delay Until statement is implemented as a procedure call to
6808 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6810 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6811 Loc : constant Source_Ptr := Sloc (N);
6815 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6816 Typ := RTE (RO_CA_Delay_Until);
6818 Typ := RTE (RO_RT_Delay_Until);
6822 Make_Procedure_Call_Statement (Loc,
6823 Name => New_Reference_To (Typ, Loc),
6824 Parameter_Associations => New_List (Expression (N))));
6827 end Expand_N_Delay_Until_Statement;
6829 -------------------------
6830 -- Expand_N_Entry_Body --
6831 -------------------------
6833 procedure Expand_N_Entry_Body (N : Node_Id) is
6835 -- Associate discriminals with the next protected operation body to be
6838 if Present (Next_Protected_Operation (N)) then
6839 Set_Discriminals (Parent (Current_Scope));
6841 end Expand_N_Entry_Body;
6843 -----------------------------------
6844 -- Expand_N_Entry_Call_Statement --
6845 -----------------------------------
6847 -- An entry call is expanded into GNARLI calls to implement a simple entry
6848 -- call (see Build_Simple_Entry_Call).
6850 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
6856 if No_Run_Time_Mode then
6857 Error_Msg_CRT ("entry call", N);
6861 -- If this entry call is part of an asynchronous select, don't expand it
6862 -- here; it will be expanded with the select statement. Don't expand
6863 -- timed entry calls either, as they are translated into asynchronous
6866 -- ??? This whole approach is questionable; it may be better to go back
6867 -- to allowing the expansion to take place and then attempting to fix it
6868 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6869 -- whether the expanded call is on a task or protected entry.
6871 if (Nkind (Parent (N)) /= N_Triggering_Alternative
6872 or else N /= Triggering_Statement (Parent (N)))
6873 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
6874 or else N /= Entry_Call_Statement (Parent (N))
6875 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
6877 Extract_Entry (N, Concval, Ename, Index);
6878 Build_Simple_Entry_Call (N, Concval, Ename, Index);
6880 end Expand_N_Entry_Call_Statement;
6882 --------------------------------
6883 -- Expand_N_Entry_Declaration --
6884 --------------------------------
6886 -- If there are parameters, then first, each of the formals is marked by
6887 -- setting Is_Entry_Formal. Next a record type is built which is used to
6888 -- hold the parameter values. The name of this record type is entryP where
6889 -- entry is the name of the entry, with an additional corresponding access
6890 -- type called entryPA. The record type has matching components for each
6891 -- formal (the component names are the same as the formal names). For
6892 -- elementary types, the component type matches the formal type. For
6893 -- composite types, an access type is declared (with the name formalA)
6894 -- which designates the formal type, and the type of the component is this
6895 -- access type. Finally the Entry_Component of each formal is set to
6896 -- reference the corresponding record component.
6898 procedure Expand_N_Entry_Declaration (N : Node_Id) is
6899 Loc : constant Source_Ptr := Sloc (N);
6900 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
6901 Components : List_Id;
6904 Last_Decl : Node_Id;
6905 Component : Entity_Id;
6908 Rec_Ent : Entity_Id;
6909 Acc_Ent : Entity_Id;
6912 Formal := First_Formal (Entry_Ent);
6915 -- Most processing is done only if parameters are present
6917 if Present (Formal) then
6918 Components := New_List;
6920 -- Loop through formals
6922 while Present (Formal) loop
6923 Set_Is_Entry_Formal (Formal);
6925 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
6926 Set_Entry_Component (Formal, Component);
6927 Set_Entry_Formal (Component, Formal);
6928 Ftype := Etype (Formal);
6930 -- Declare new access type and then append
6933 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6936 Make_Full_Type_Declaration (Loc,
6937 Defining_Identifier => Ctype,
6939 Make_Access_To_Object_Definition (Loc,
6940 All_Present => True,
6941 Constant_Present => Ekind (Formal) = E_In_Parameter,
6942 Subtype_Indication => New_Reference_To (Ftype, Loc)));
6944 Insert_After (Last_Decl, Decl);
6947 Append_To (Components,
6948 Make_Component_Declaration (Loc,
6949 Defining_Identifier => Component,
6950 Component_Definition =>
6951 Make_Component_Definition (Loc,
6952 Aliased_Present => False,
6953 Subtype_Indication => New_Reference_To (Ctype, Loc))));
6955 Next_Formal_With_Extras (Formal);
6958 -- Create the Entry_Parameter_Record declaration
6961 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
6964 Make_Full_Type_Declaration (Loc,
6965 Defining_Identifier => Rec_Ent,
6967 Make_Record_Definition (Loc,
6969 Make_Component_List (Loc,
6970 Component_Items => Components)));
6972 Insert_After (Last_Decl, Decl);
6975 -- Construct and link in the corresponding access type
6978 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6980 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
6983 Make_Full_Type_Declaration (Loc,
6984 Defining_Identifier => Acc_Ent,
6986 Make_Access_To_Object_Definition (Loc,
6987 All_Present => True,
6988 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
6990 Insert_After (Last_Decl, Decl);
6993 end Expand_N_Entry_Declaration;
6995 -----------------------------
6996 -- Expand_N_Protected_Body --
6997 -----------------------------
6999 -- Protected bodies are expanded to the completion of the subprograms
7000 -- created for the corresponding protected type. These are a protected and
7001 -- unprotected version of each protected subprogram in the object, a
7002 -- function to calculate each entry barrier, and a procedure to execute the
7003 -- sequence of statements of each protected entry body. For example, for
7004 -- protected type ptype:
7007 -- (O : System.Address;
7008 -- E : Protected_Entry_Index)
7011 -- <discriminant renamings>
7012 -- <private object renamings>
7014 -- return <barrier expression>;
7017 -- procedure pprocN (_object : in out poV;...) is
7018 -- <discriminant renamings>
7019 -- <private object renamings>
7021 -- <sequence of statements>
7024 -- procedure pprocP (_object : in out poV;...) is
7025 -- procedure _clean is
7028 -- ptypeS (_object, Pn);
7029 -- Unlock (_object._object'Access);
7030 -- Abort_Undefer.all;
7035 -- Lock (_object._object'Access);
7036 -- pprocN (_object;...);
7041 -- function pfuncN (_object : poV;...) return Return_Type is
7042 -- <discriminant renamings>
7043 -- <private object renamings>
7045 -- <sequence of statements>
7048 -- function pfuncP (_object : poV) return Return_Type is
7049 -- procedure _clean is
7051 -- Unlock (_object._object'Access);
7052 -- Abort_Undefer.all;
7057 -- Lock (_object._object'Access);
7058 -- return pfuncN (_object);
7065 -- (O : System.Address;
7066 -- P : System.Address;
7067 -- E : Protected_Entry_Index)
7069 -- <discriminant renamings>
7070 -- <private object renamings>
7071 -- type poVP is access poV;
7072 -- _Object : ptVP := ptVP!(O);
7076 -- <statement sequence>
7077 -- Complete_Entry_Body (_Object._Object);
7079 -- when all others =>
7080 -- Exceptional_Complete_Entry_Body (
7081 -- _Object._Object, Get_GNAT_Exception);
7085 -- The type poV is the record created for the protected type to hold
7086 -- the state of the protected object.
7088 procedure Expand_N_Protected_Body (N : Node_Id) is
7089 Loc : constant Source_Ptr := Sloc (N);
7090 Pid : constant Entity_Id := Corresponding_Spec (N);
7092 Current_Node : Node_Id;
7093 Disp_Op_Body : Node_Id;
7094 New_Op_Body : Node_Id;
7095 Num_Entries : Natural := 0;
7100 Chain : Entity_Id := Empty;
7101 -- Finalization chain that may be attached to new body
7103 function Build_Dispatching_Subprogram_Body
7106 Prot_Bod : Node_Id) return Node_Id;
7107 -- Build a dispatching version of the protected subprogram body. The
7108 -- newly generated subprogram contains a call to the original protected
7109 -- body. The following code is generated:
7111 -- function <protected-function-name> (Param1 .. ParamN) return
7114 -- return <protected-function-name>P (Param1 .. ParamN);
7115 -- end <protected-function-name>;
7119 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7121 -- <protected-procedure-name>P (Param1 .. ParamN);
7122 -- end <protected-procedure-name>
7124 ---------------------------------------
7125 -- Build_Dispatching_Subprogram_Body --
7126 ---------------------------------------
7128 function Build_Dispatching_Subprogram_Body
7131 Prot_Bod : Node_Id) return Node_Id
7133 Loc : constant Source_Ptr := Sloc (N);
7140 -- Generate a specification without a letter suffix in order to
7141 -- override an interface function or procedure.
7144 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7146 -- The formal parameters become the actuals of the protected
7147 -- function or procedure call.
7149 Actuals := New_List;
7150 Formal := First (Parameter_Specifications (Spec));
7151 while Present (Formal) loop
7153 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7158 if Nkind (Spec) = N_Procedure_Specification then
7161 Make_Procedure_Call_Statement (Loc,
7163 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7164 Parameter_Associations => Actuals));
7166 pragma Assert (Nkind (Spec) = N_Function_Specification);
7170 Make_Simple_Return_Statement (Loc,
7172 Make_Function_Call (Loc,
7174 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7175 Parameter_Associations => Actuals)));
7179 Make_Subprogram_Body (Loc,
7180 Declarations => Empty_List,
7181 Specification => Spec,
7182 Handled_Statement_Sequence =>
7183 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7184 end Build_Dispatching_Subprogram_Body;
7186 -- Start of processing for Expand_N_Protected_Body
7189 if No_Run_Time_Mode then
7190 Error_Msg_CRT ("protected body", N);
7194 -- This is the proper body corresponding to a stub. The declarations
7195 -- must be inserted at the point of the stub, which in turn is in the
7196 -- declarative part of the parent unit.
7198 if Nkind (Parent (N)) = N_Subunit then
7199 Current_Node := Corresponding_Stub (Parent (N));
7204 Op_Body := First (Declarations (N));
7206 -- The protected body is replaced with the bodies of its
7207 -- protected operations, and the declarations for internal objects
7208 -- that may have been created for entry family bounds.
7210 Rewrite (N, Make_Null_Statement (Sloc (N)));
7213 while Present (Op_Body) loop
7214 case Nkind (Op_Body) is
7215 when N_Subprogram_Declaration =>
7218 when N_Subprogram_Body =>
7220 -- Do not create bodies for eliminated operations
7222 if not Is_Eliminated (Defining_Entity (Op_Body))
7223 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7226 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7228 -- Propagate the finalization chain to the new body. In the
7229 -- unlikely event that the subprogram contains a declaration
7230 -- or allocator for an object that requires finalization,
7231 -- the corresponding chain is created when analyzing the
7232 -- body, and attached to its entity. This entity is not
7233 -- further elaborated, and so the chain properly belongs to
7234 -- the newly created subprogram body.
7237 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7239 if Present (Chain) then
7240 Set_Finalization_Chain_Entity
7241 (Protected_Body_Subprogram
7242 (Corresponding_Spec (Op_Body)), Chain);
7244 (Handled_Statement_Sequence (New_Op_Body), False);
7247 Insert_After (Current_Node, New_Op_Body);
7248 Current_Node := New_Op_Body;
7249 Analyze (New_Op_Body);
7251 -- Build the corresponding protected operation. It may
7252 -- appear that this is needed only if this is a visible
7253 -- operation of the type, or if it is an interrupt handler,
7254 -- and this was the strategy used previously in GNAT.
7255 -- However, the operation may be exported through a 'Access
7256 -- to an external caller. This is the common idiom in code
7257 -- that uses the Ada 2005 Timing_Events package. As a result
7258 -- we need to produce the protected body for both visible
7259 -- and private operations.
7261 if Present (Corresponding_Spec (Op_Body)) then
7263 Unit_Declaration_Node (Corresponding_Spec (Op_Body));
7265 if Nkind (Parent (Op_Decl)) =
7266 N_Protected_Definition
7269 Build_Protected_Subprogram_Body (
7270 Op_Body, Pid, Specification (New_Op_Body));
7272 Insert_After (Current_Node, New_Op_Body);
7273 Analyze (New_Op_Body);
7275 Current_Node := New_Op_Body;
7277 -- Generate an overriding primitive operation body for
7278 -- this subprogram if the protected type implements
7281 if Ada_Version >= Ada_05
7282 and then Present (Interfaces (
7283 Corresponding_Record_Type (Pid)))
7286 Build_Dispatching_Subprogram_Body (
7287 Op_Body, Pid, New_Op_Body);
7289 Insert_After (Current_Node, Disp_Op_Body);
7290 Analyze (Disp_Op_Body);
7292 Current_Node := Disp_Op_Body;
7298 when N_Entry_Body =>
7299 Op_Id := Defining_Identifier (Op_Body);
7300 Num_Entries := Num_Entries + 1;
7302 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7304 Insert_After (Current_Node, New_Op_Body);
7305 Current_Node := New_Op_Body;
7306 Analyze (New_Op_Body);
7308 when N_Implicit_Label_Declaration =>
7311 when N_Itype_Reference =>
7312 Insert_After (Current_Node, New_Copy (Op_Body));
7314 when N_Freeze_Entity =>
7315 New_Op_Body := New_Copy (Op_Body);
7317 if Present (Entity (Op_Body))
7318 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7320 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7323 Insert_After (Current_Node, New_Op_Body);
7324 Current_Node := New_Op_Body;
7325 Analyze (New_Op_Body);
7328 New_Op_Body := New_Copy (Op_Body);
7329 Insert_After (Current_Node, New_Op_Body);
7330 Current_Node := New_Op_Body;
7331 Analyze (New_Op_Body);
7333 when N_Object_Declaration =>
7334 pragma Assert (not Comes_From_Source (Op_Body));
7335 New_Op_Body := New_Copy (Op_Body);
7336 Insert_After (Current_Node, New_Op_Body);
7337 Current_Node := New_Op_Body;
7338 Analyze (New_Op_Body);
7341 raise Program_Error;
7348 -- Finally, create the body of the function that maps an entry index
7349 -- into the corresponding body index, except when there is no entry,
7350 -- or in a ravenscar-like profile.
7352 if Corresponding_Runtime_Package (Pid) =
7353 System_Tasking_Protected_Objects_Entries
7355 New_Op_Body := Build_Find_Body_Index (Pid);
7356 Insert_After (Current_Node, New_Op_Body);
7357 Current_Node := New_Op_Body;
7358 Analyze (New_Op_Body);
7361 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7362 -- protected body. At this point all wrapper specs have been created,
7363 -- frozen and included in the dispatch table for the protected type.
7365 if Ada_Version >= Ada_05 then
7366 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7368 end Expand_N_Protected_Body;
7370 -----------------------------------------
7371 -- Expand_N_Protected_Type_Declaration --
7372 -----------------------------------------
7374 -- First we create a corresponding record type declaration used to
7375 -- represent values of this protected type.
7376 -- The general form of this type declaration is
7378 -- type poV (discriminants) is record
7379 -- _Object : aliased <kind>Protection
7380 -- [(<entry count> [, <handler count>])];
7381 -- [entry_family : array (bounds) of Void;]
7382 -- <private data fields>
7385 -- The discriminants are present only if the corresponding protected type
7386 -- has discriminants, and they exactly mirror the protected type
7387 -- discriminants. The private data fields similarly mirror the private
7388 -- declarations of the protected type.
7390 -- The Object field is always present. It contains RTS specific data used
7391 -- to control the protected object. It is declared as Aliased so that it
7392 -- can be passed as a pointer to the RTS. This allows the protected record
7393 -- to be referenced within RTS data structures. An appropriate Protection
7394 -- type and discriminant are generated.
7396 -- The Service field is present for protected objects with entries. It
7397 -- contains sufficient information to allow the entry service procedure for
7398 -- this object to be called when the object is not known till runtime.
7400 -- One entry_family component is present for each entry family in the
7401 -- task definition (see Expand_N_Task_Type_Declaration).
7403 -- When a protected object is declared, an instance of the protected type
7404 -- value record is created. The elaboration of this declaration creates the
7405 -- correct bounds for the entry families, and also evaluates the priority
7406 -- expression if needed. The initialization routine for the protected type
7407 -- itself then calls Initialize_Protection with appropriate parameters to
7408 -- initialize the value of the Task_Id field. Install_Handlers may be also
7409 -- called if a pragma Attach_Handler applies.
7411 -- Note: this record is passed to the subprograms created by the expansion
7412 -- of protected subprograms and entries. It is an in parameter to protected
7413 -- functions and an in out parameter to procedures and entry bodies. The
7414 -- Entity_Id for this created record type is placed in the
7415 -- Corresponding_Record_Type field of the associated protected type entity.
7417 -- Next we create a procedure specifications for protected subprograms and
7418 -- entry bodies. For each protected subprograms two subprograms are
7419 -- created, an unprotected and a protected version. The unprotected version
7420 -- is called from within other operations of the same protected object.
7422 -- We also build the call to register the procedure if a pragma
7423 -- Interrupt_Handler applies.
7425 -- A single subprogram is created to service all entry bodies; it has an
7426 -- additional boolean out parameter indicating that the previous entry call
7427 -- made by the current task was serviced immediately, i.e. not by proxy.
7428 -- The O parameter contains a pointer to a record object of the type
7429 -- described above. An untyped interface is used here to allow this
7430 -- procedure to be called in places where the type of the object to be
7431 -- serviced is not known. This must be done, for example, when a call that
7432 -- may have been requeued is cancelled; the corresponding object must be
7433 -- serviced, but which object that is not known till runtime.
7436 -- (O : System.Address; P : out Boolean);
7437 -- procedure pprocN (_object : in out poV);
7438 -- procedure pproc (_object : in out poV);
7439 -- function pfuncN (_object : poV);
7440 -- function pfunc (_object : poV);
7443 -- Note that this must come after the record type declaration, since
7444 -- the specs refer to this type.
7446 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7447 Loc : constant Source_Ptr := Sloc (N);
7448 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7450 Pdef : constant Node_Id := Protected_Definition (N);
7451 -- This contains two lists; one for visible and one for private decls
7455 Discr_Map : constant Elist_Id := New_Elmt_List;
7459 Comp_Id : Entity_Id;
7461 Current_Node : Node_Id := N;
7462 Bdef : Entity_Id := Empty; -- avoid uninit warning
7463 Edef : Entity_Id := Empty; -- avoid uninit warning
7464 Entries_Aggr : Node_Id;
7465 Body_Id : Entity_Id;
7468 Object_Comp : Node_Id;
7470 procedure Check_Inlining (Subp : Entity_Id);
7471 -- If the original operation has a pragma Inline, propagate the flag
7472 -- to the internal body, for possible inlining later on. The source
7473 -- operation is invisible to the back-end and is never actually called.
7475 procedure Register_Handler;
7476 -- For a protected operation that is an interrupt handler, add the
7477 -- freeze action that will register it as such.
7479 --------------------
7480 -- Check_Inlining --
7481 --------------------
7483 procedure Check_Inlining (Subp : Entity_Id) is
7485 if Is_Inlined (Subp) then
7486 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7487 Set_Is_Inlined (Subp, False);
7491 ----------------------
7492 -- Register_Handler --
7493 ----------------------
7495 procedure Register_Handler is
7497 -- All semantic checks already done in Sem_Prag
7499 Prot_Proc : constant Entity_Id :=
7501 (Specification (Current_Node));
7503 Proc_Address : constant Node_Id :=
7504 Make_Attribute_Reference (Loc,
7505 Prefix => New_Reference_To (Prot_Proc, Loc),
7506 Attribute_Name => Name_Address);
7508 RTS_Call : constant Entity_Id :=
7509 Make_Procedure_Call_Statement (Loc,
7512 RTE (RE_Register_Interrupt_Handler), Loc),
7513 Parameter_Associations =>
7514 New_List (Proc_Address));
7516 Append_Freeze_Action (Prot_Proc, RTS_Call);
7517 end Register_Handler;
7519 -- Start of processing for Expand_N_Protected_Type_Declaration
7522 if Present (Corresponding_Record_Type (Prot_Typ)) then
7525 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7528 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7530 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7531 -- of implemented interfaces.
7533 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
7535 Qualify_Entity_Names (N);
7537 -- If the type has discriminants, their occurrences in the declaration
7538 -- have been replaced by the corresponding discriminals. For components
7539 -- that are constrained by discriminants, their homologues in the
7540 -- corresponding record type must refer to the discriminants of that
7541 -- record, so we must apply a new renaming to subtypes_indications:
7543 -- protected discriminant => discriminal => record discriminant
7545 -- This replacement is not applied to default expressions, for which
7546 -- the discriminal is correct.
7548 if Has_Discriminants (Prot_Typ) then
7554 Disc := First_Discriminant (Prot_Typ);
7555 Decl := First (Discriminant_Specifications (Rec_Decl));
7556 while Present (Disc) loop
7557 Append_Elmt (Discriminal (Disc), Discr_Map);
7558 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7559 Next_Discriminant (Disc);
7565 -- Fill in the component declarations
7567 -- Add components for entry families. For each entry family, create an
7568 -- anonymous type declaration with the same size, and analyze the type.
7570 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7572 -- Prepend the _Object field with the right type to the component list.
7573 -- We need to compute the number of entries, and in some cases the
7574 -- number of Attach_Handler pragmas.
7578 Num_Attach_Handler : Int := 0;
7579 Protection_Subtype : Node_Id;
7580 Entry_Count_Expr : constant Node_Id :=
7581 Build_Entry_Count_Expression
7582 (Prot_Typ, Cdecls, Loc);
7585 -- Could this be simplified using Corresponding_Runtime_Package???
7587 if Has_Attach_Handler (Prot_Typ) then
7588 Ritem := First_Rep_Item (Prot_Typ);
7589 while Present (Ritem) loop
7590 if Nkind (Ritem) = N_Pragma
7591 and then Pragma_Name (Ritem) = Name_Attach_Handler
7593 Num_Attach_Handler := Num_Attach_Handler + 1;
7596 Next_Rep_Item (Ritem);
7599 if Restricted_Profile then
7600 if Has_Entries (Prot_Typ) then
7601 Protection_Subtype :=
7602 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7604 Protection_Subtype :=
7605 New_Reference_To (RTE (RE_Protection), Loc);
7608 Protection_Subtype :=
7609 Make_Subtype_Indication
7613 (RTE (RE_Static_Interrupt_Protection), Loc),
7615 Make_Index_Or_Discriminant_Constraint (
7617 Constraints => New_List (
7619 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7622 elsif Has_Interrupt_Handler (Prot_Typ) then
7623 Protection_Subtype :=
7624 Make_Subtype_Indication (
7626 Subtype_Mark => New_Reference_To
7627 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7629 Make_Index_Or_Discriminant_Constraint (
7631 Constraints => New_List (Entry_Count_Expr)));
7633 -- Type has explicit entries or generated primitive entry wrappers
7635 elsif Has_Entries (Prot_Typ)
7636 or else (Ada_Version >= Ada_05
7637 and then Present (Interface_List (N)))
7639 case Corresponding_Runtime_Package (Prot_Typ) is
7640 when System_Tasking_Protected_Objects_Entries =>
7641 Protection_Subtype :=
7642 Make_Subtype_Indication (Loc,
7644 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7646 Make_Index_Or_Discriminant_Constraint (
7648 Constraints => New_List (Entry_Count_Expr)));
7650 when System_Tasking_Protected_Objects_Single_Entry =>
7651 Protection_Subtype :=
7652 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7655 raise Program_Error;
7659 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7663 Make_Component_Declaration (Loc,
7664 Defining_Identifier =>
7665 Make_Defining_Identifier (Loc, Name_uObject),
7666 Component_Definition =>
7667 Make_Component_Definition (Loc,
7668 Aliased_Present => True,
7669 Subtype_Indication => Protection_Subtype));
7672 pragma Assert (Present (Pdef));
7674 -- Add private field components
7676 if Present (Private_Declarations (Pdef)) then
7677 Priv := First (Private_Declarations (Pdef));
7679 while Present (Priv) loop
7681 if Nkind (Priv) = N_Component_Declaration then
7683 -- The component definition consists of a subtype indication,
7684 -- or (in Ada 2005) an access definition. Make a copy of the
7685 -- proper definition.
7688 Old_Comp : constant Node_Id := Component_Definition (Priv);
7689 Pent : constant Entity_Id := Defining_Identifier (Priv);
7693 if Present (Subtype_Indication (Old_Comp)) then
7695 Make_Component_Definition (Sloc (Pent),
7696 Aliased_Present => False,
7697 Subtype_Indication =>
7698 New_Copy_Tree (Subtype_Indication (Old_Comp),
7702 Make_Component_Definition (Sloc (Pent),
7703 Aliased_Present => False,
7704 Access_Definition =>
7705 New_Copy_Tree (Access_Definition (Old_Comp),
7710 Make_Component_Declaration (Loc,
7711 Defining_Identifier =>
7712 Make_Defining_Identifier (Sloc (Pent), Chars (Pent)),
7713 Component_Definition => New_Comp,
7714 Expression => Expression (Priv));
7716 Append_To (Cdecls, New_Priv);
7719 elsif Nkind (Priv) = N_Subprogram_Declaration then
7721 -- Make the unprotected version of the subprogram available
7722 -- for expansion of intra object calls. There is need for
7723 -- a protected version only if the subprogram is an interrupt
7724 -- handler, otherwise this operation can only be called from
7728 Make_Subprogram_Declaration (Loc,
7730 Build_Protected_Sub_Specification
7731 (Priv, Prot_Typ, Unprotected_Mode));
7733 Insert_After (Current_Node, Sub);
7736 Set_Protected_Body_Subprogram
7737 (Defining_Unit_Name (Specification (Priv)),
7738 Defining_Unit_Name (Specification (Sub)));
7739 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
7740 Current_Node := Sub;
7743 Make_Subprogram_Declaration (Loc,
7745 Build_Protected_Sub_Specification
7746 (Priv, Prot_Typ, Protected_Mode));
7748 Insert_After (Current_Node, Sub);
7750 Current_Node := Sub;
7752 if Is_Interrupt_Handler
7753 (Defining_Unit_Name (Specification (Priv)))
7755 if not Restricted_Profile then
7765 -- Put the _Object component after the private component so that it
7766 -- be finalized early as required by 9.4 (20)
7768 Append_To (Cdecls, Object_Comp);
7770 Insert_After (Current_Node, Rec_Decl);
7771 Current_Node := Rec_Decl;
7773 -- Analyze the record declaration immediately after construction,
7774 -- because the initialization procedure is needed for single object
7775 -- declarations before the next entity is analyzed (the freeze call
7776 -- that generates this initialization procedure is found below).
7778 Analyze (Rec_Decl, Suppress => All_Checks);
7780 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7781 -- the corresponding record is frozen. If any wrappers are generated,
7782 -- Current_Node is updated accordingly.
7784 if Ada_Version >= Ada_05 then
7785 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
7788 -- Collect pointers to entry bodies and their barriers, to be placed
7789 -- in the Entry_Bodies_Array for the type. For each entry/family we
7790 -- add an expression to the aggregate which is the initial value of
7791 -- this array. The array is declared after all protected subprograms.
7793 if Has_Entries (Prot_Typ) then
7794 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
7796 Entries_Aggr := Empty;
7799 -- Build two new procedure specifications for each protected subprogram;
7800 -- one to call from outside the object and one to call from inside.
7801 -- Build a barrier function and an entry body action procedure
7802 -- specification for each protected entry. Initialize the entry body
7803 -- array. If subprogram is flagged as eliminated, do not generate any
7804 -- internal operations.
7808 Comp := First (Visible_Declarations (Pdef));
7810 while Present (Comp) loop
7811 if Nkind (Comp) = N_Subprogram_Declaration then
7813 Make_Subprogram_Declaration (Loc,
7815 Build_Protected_Sub_Specification
7816 (Comp, Prot_Typ, Unprotected_Mode));
7818 Insert_After (Current_Node, Sub);
7821 Set_Protected_Body_Subprogram
7822 (Defining_Unit_Name (Specification (Comp)),
7823 Defining_Unit_Name (Specification (Sub)));
7824 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
7826 -- Make the protected version of the subprogram available for
7827 -- expansion of external calls.
7829 Current_Node := Sub;
7832 Make_Subprogram_Declaration (Loc,
7834 Build_Protected_Sub_Specification
7835 (Comp, Prot_Typ, Protected_Mode));
7837 Insert_After (Current_Node, Sub);
7840 Current_Node := Sub;
7842 -- Generate an overriding primitive operation specification for
7843 -- this subprogram if the protected type implements an interface.
7845 if Ada_Version >= Ada_05
7847 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
7850 Make_Subprogram_Declaration (Loc,
7852 Build_Protected_Sub_Specification
7853 (Comp, Prot_Typ, Dispatching_Mode));
7855 Insert_After (Current_Node, Sub);
7858 Current_Node := Sub;
7861 -- If a pragma Interrupt_Handler applies, build and add a call to
7862 -- Register_Interrupt_Handler to the freezing actions of the
7863 -- protected version (Current_Node) of the subprogram:
7865 -- system.interrupts.register_interrupt_handler
7866 -- (prot_procP'address);
7868 if not Restricted_Profile
7869 and then Is_Interrupt_Handler
7870 (Defining_Unit_Name (Specification (Comp)))
7875 elsif Nkind (Comp) = N_Entry_Declaration then
7876 E_Count := E_Count + 1;
7877 Comp_Id := Defining_Identifier (Comp);
7880 Make_Defining_Identifier (Loc,
7881 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
7883 Make_Subprogram_Declaration (Loc,
7885 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
7887 Insert_After (Current_Node, Sub);
7890 Set_Protected_Body_Subprogram
7891 (Defining_Identifier (Comp),
7892 Defining_Unit_Name (Specification (Sub)));
7894 Current_Node := Sub;
7897 Make_Defining_Identifier (Loc,
7898 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
7900 Make_Subprogram_Declaration (Loc,
7902 Build_Barrier_Function_Specification (Loc, Bdef));
7904 Insert_After (Current_Node, Sub);
7906 Set_Protected_Body_Subprogram (Bdef, Bdef);
7907 Set_Barrier_Function (Comp_Id, Bdef);
7908 Set_Scope (Bdef, Scope (Comp_Id));
7909 Current_Node := Sub;
7911 -- Collect pointers to the protected subprogram and the barrier
7912 -- of the current entry, for insertion into Entry_Bodies_Array.
7915 Make_Aggregate (Loc,
7916 Expressions => New_List (
7917 Make_Attribute_Reference (Loc,
7918 Prefix => New_Reference_To (Bdef, Loc),
7919 Attribute_Name => Name_Unrestricted_Access),
7920 Make_Attribute_Reference (Loc,
7921 Prefix => New_Reference_To (Edef, Loc),
7922 Attribute_Name => Name_Unrestricted_Access))),
7923 Expressions (Entries_Aggr));
7930 -- If there are some private entry declarations, expand it as if they
7931 -- were visible entries.
7933 if Present (Private_Declarations (Pdef)) then
7934 Comp := First (Private_Declarations (Pdef));
7935 while Present (Comp) loop
7936 if Nkind (Comp) = N_Entry_Declaration then
7937 E_Count := E_Count + 1;
7938 Comp_Id := Defining_Identifier (Comp);
7941 Make_Defining_Identifier (Loc,
7942 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
7944 Make_Subprogram_Declaration (Loc,
7946 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
7948 Insert_After (Current_Node, Sub);
7951 Set_Protected_Body_Subprogram
7952 (Defining_Identifier (Comp),
7953 Defining_Unit_Name (Specification (Sub)));
7955 Current_Node := Sub;
7958 Make_Defining_Identifier (Loc,
7959 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
7962 Make_Subprogram_Declaration (Loc,
7964 Build_Barrier_Function_Specification (Loc, Bdef));
7966 Insert_After (Current_Node, Sub);
7968 Set_Protected_Body_Subprogram (Bdef, Bdef);
7969 Set_Barrier_Function (Comp_Id, Bdef);
7970 Set_Scope (Bdef, Scope (Comp_Id));
7971 Current_Node := Sub;
7973 -- Collect pointers to the protected subprogram and the barrier
7974 -- of the current entry, for insertion into Entry_Bodies_Array.
7976 Append_To (Expressions (Entries_Aggr),
7977 Make_Aggregate (Loc,
7978 Expressions => New_List (
7979 Make_Attribute_Reference (Loc,
7980 Prefix => New_Reference_To (Bdef, Loc),
7981 Attribute_Name => Name_Unrestricted_Access),
7982 Make_Attribute_Reference (Loc,
7983 Prefix => New_Reference_To (Edef, Loc),
7984 Attribute_Name => Name_Unrestricted_Access))));
7991 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
7992 -- all protected subprograms have been collected.
7994 if Has_Entries (Prot_Typ) then
7996 Make_Defining_Identifier (Sloc (Prot_Typ),
7997 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
7999 case Corresponding_Runtime_Package (Prot_Typ) is
8000 when System_Tasking_Protected_Objects_Entries =>
8001 Body_Arr := Make_Object_Declaration (Loc,
8002 Defining_Identifier => Body_Id,
8003 Aliased_Present => True,
8004 Object_Definition =>
8005 Make_Subtype_Indication (Loc,
8006 Subtype_Mark => New_Reference_To (
8007 RTE (RE_Protected_Entry_Body_Array), Loc),
8009 Make_Index_Or_Discriminant_Constraint (Loc,
8010 Constraints => New_List (
8012 Make_Integer_Literal (Loc, 1),
8013 Make_Integer_Literal (Loc, E_Count))))),
8014 Expression => Entries_Aggr);
8016 when System_Tasking_Protected_Objects_Single_Entry =>
8017 Body_Arr := Make_Object_Declaration (Loc,
8018 Defining_Identifier => Body_Id,
8019 Aliased_Present => True,
8020 Object_Definition => New_Reference_To
8021 (RTE (RE_Entry_Body), Loc),
8023 Make_Aggregate (Loc,
8024 Expressions => New_List (
8025 Make_Attribute_Reference (Loc,
8026 Prefix => New_Reference_To (Bdef, Loc),
8027 Attribute_Name => Name_Unrestricted_Access),
8028 Make_Attribute_Reference (Loc,
8029 Prefix => New_Reference_To (Edef, Loc),
8030 Attribute_Name => Name_Unrestricted_Access))));
8033 raise Program_Error;
8036 -- A pointer to this array will be placed in the corresponding record
8037 -- by its initialization procedure so this needs to be analyzed here.
8039 Insert_After (Current_Node, Body_Arr);
8040 Current_Node := Body_Arr;
8043 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8045 -- Finally, build the function that maps an entry index into the
8046 -- corresponding body. A pointer to this function is placed in each
8047 -- object of the type. Except for a ravenscar-like profile (no abort,
8048 -- no entry queue, 1 entry)
8050 if Corresponding_Runtime_Package (Prot_Typ) =
8051 System_Tasking_Protected_Objects_Entries
8054 Make_Subprogram_Declaration (Loc,
8055 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8056 Insert_After (Current_Node, Sub);
8060 end Expand_N_Protected_Type_Declaration;
8062 --------------------------------
8063 -- Expand_N_Requeue_Statement --
8064 --------------------------------
8066 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8067 -- operations, depending on the source and destination (task or protected
8068 -- object). A dispatching requeue statement is expanded into a call to the
8069 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8070 -- jump around the remainder of processing for the original entry and, if
8071 -- the destination is (different) protected object, to attempt to service
8072 -- it. The following illustrates the various cases:
8075 -- (O : System.Address;
8076 -- P : System.Address;
8077 -- E : Protected_Entry_Index)
8079 -- <discriminant renamings>
8080 -- <private object renamings>
8081 -- type poVP is access poV;
8082 -- _object : ptVP := ptVP!(O);
8086 -- <start of statement sequence for entry>
8088 -- -- Requeue from one protected entry body to another protected
8091 -- Requeue_Protected_Entry (
8092 -- _object._object'Access,
8093 -- new._object'Access,
8098 -- <some more of the statement sequence for entry>
8100 -- -- Requeue from an entry body to a task entry
8102 -- Requeue_Protected_To_Task_Entry (
8108 -- <rest of statement sequence for entry>
8109 -- Complete_Entry_Body (_object._object);
8112 -- when all others =>
8113 -- Exceptional_Complete_Entry_Body (
8114 -- _object._object, Get_GNAT_Exception);
8118 -- Requeue of a task entry call to a task entry
8120 -- Accept_Call (E, Ann);
8121 -- <start of statement sequence for accept statement>
8122 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8124 -- <rest of statement sequence for accept statement>
8126 -- Complete_Rendezvous;
8129 -- when all others =>
8130 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8132 -- Requeue of a task entry call to a protected entry
8134 -- Accept_Call (E, Ann);
8135 -- <start of statement sequence for accept statement>
8136 -- Requeue_Task_To_Protected_Entry (
8137 -- new._object'Access,
8142 -- <rest of statement sequence for accept statement>
8144 -- Complete_Rendezvous;
8147 -- when all others =>
8148 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8150 -- Ada 2005 (AI05-0030): Dispatching requeue from protected to interface
8154 -- (O : System.Address;
8155 -- P : System.Address;
8156 -- E : Protected_Entry_Index)
8158 -- <discriminant renamings>
8159 -- <private object renamings>
8160 -- type poVP is access poV;
8161 -- _object : ptVP := ptVP!(O);
8165 -- <start of statement sequence for entry>
8168 -- (<interface class-wide object>,
8171 -- Ada.Tags.Get_Offset_Index
8173 -- <interface dispatch table index of target entry>),
8177 -- <rest of statement sequence for entry>
8178 -- Complete_Entry_Body (_object._object);
8181 -- when all others =>
8182 -- Exceptional_Complete_Entry_Body (
8183 -- _object._object, Get_GNAT_Exception);
8187 -- Ada 2005 (AI05-0030): Dispatching requeue from task to interface
8190 -- Accept_Call (E, Ann);
8191 -- <start of statement sequence for accept statement>
8193 -- (<interface class-wide object>,
8196 -- Ada.Tags.Get_Offset_Index
8198 -- <interface dispatch table index of target entrt>),
8202 -- <rest of statement sequence for accept statement>
8204 -- Complete_Rendezvous;
8207 -- when all others =>
8208 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8210 -- Further details on these expansions can be found in Expand_N_Protected_
8211 -- Body and Expand_N_Accept_Statement.
8213 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8214 Loc : constant Source_Ptr := Sloc (N);
8215 Abortable : Node_Id;
8217 Conc_Typ : Entity_Id;
8222 New_Param : Node_Id;
8223 Old_Typ : Entity_Id;
8226 RTS_Call : Entity_Id;
8227 Self_Param : Node_Id;
8228 Skip_Stat : Node_Id;
8232 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
8234 -- Extract the components of the entry call
8236 Extract_Entry (N, Concval, Ename, Index);
8237 Conc_Typ := Etype (Concval);
8239 -- Examine the scope stack in order to find nearest enclosing protected
8240 -- or task type. This will constitute our invocation source.
8242 Old_Typ := Current_Scope;
8243 while Present (Old_Typ)
8244 and then not Is_Protected_Type (Old_Typ)
8245 and then not Is_Task_Type (Old_Typ)
8247 Old_Typ := Scope (Old_Typ);
8250 -- Generate the parameter list for all cases. The abortable flag is
8251 -- common among dispatching and regular requeue.
8253 Params := New_List (Abortable);
8255 -- Ada 2005 (AI05-0030): We have a dispatching requeue of the form
8256 -- Concval.Ename where the type of Concval is class-wide concurrent
8259 if Ada_Version >= Ada_05
8260 and then Present (Concval)
8261 and then Is_Class_Wide_Type (Conc_Typ)
8262 and then Is_Concurrent_Interface (Conc_Typ)
8264 RTS_Call := Make_Identifier (Loc, Name_uDisp_Requeue);
8267 -- Ada.Tags.Get_Offset_Index
8268 -- (Ada.Tags.Tag (Concval),
8269 -- <interface dispatch table position of Ename>)
8272 Make_Function_Call (Loc,
8274 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8275 Parameter_Associations =>
8277 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8278 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8280 -- Specific actuals for protected to interface class-wide type
8283 if Is_Protected_Type (Old_Typ) then
8285 Make_Attribute_Reference (Loc, -- _object'Address
8287 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8290 Prepend_To (Params, -- True
8291 New_Reference_To (Standard_True, Loc));
8293 -- Specific actuals for task to interface class-wide type requeue
8296 pragma Assert (Is_Task_Type (Old_Typ));
8298 Prepend_To (Params, -- null
8299 New_Reference_To (RTE (RE_Null_Address), Loc));
8300 Prepend_To (Params, -- False
8301 New_Reference_To (Standard_False, Loc));
8304 -- Finally, add the common object parameter
8306 Prepend_To (Params, New_Copy_Tree (Concval));
8308 -- Regular requeue processing
8311 New_Param := Concurrent_Ref (Concval);
8313 -- The index expression is common among all four cases
8316 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8318 if Is_Protected_Type (Old_Typ) then
8320 Make_Attribute_Reference (Loc,
8322 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8324 Name_Unchecked_Access);
8326 -- Protected to protected requeue
8328 if Is_Protected_Type (Conc_Typ) then
8330 New_Reference_To (RTE (RE_Requeue_Protected_Entry), Loc);
8333 Make_Attribute_Reference (Loc,
8337 Name_Unchecked_Access);
8339 -- Protected to task requeue
8342 pragma Assert (Is_Task_Type (Conc_Typ));
8345 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8348 Prepend (New_Param, Params);
8349 Prepend (Self_Param, Params);
8352 pragma Assert (Is_Task_Type (Old_Typ));
8354 -- Task to protected requeue
8356 if Is_Protected_Type (Conc_Typ) then
8359 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8362 Make_Attribute_Reference (Loc,
8366 Name_Unchecked_Access);
8368 -- Task to task requeue
8371 pragma Assert (Is_Task_Type (Conc_Typ));
8373 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8376 Prepend (New_Param, Params);
8380 -- Create the GNARLI or predefined primitive call
8383 Make_Procedure_Call_Statement (Loc,
8385 Parameter_Associations => Params);
8390 if Is_Protected_Type (Old_Typ) then
8392 -- Build the return statement to skip the rest of the entry body
8394 Skip_Stat := Make_Simple_Return_Statement (Loc);
8397 -- If the requeue is within a task, find the end label of the
8398 -- enclosing accept statement.
8400 Acc_Stat := Parent (N);
8401 while Nkind (Acc_Stat) /= N_Accept_Statement loop
8402 Acc_Stat := Parent (Acc_Stat);
8405 -- The last statement is the second label, used for completing the
8406 -- rendezvous the usual way. The label we are looking for is right
8410 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
8412 pragma Assert (Nkind (Lab_Node) = N_Label);
8414 -- Build the goto statement to skip the rest of the accept
8418 Make_Goto_Statement (Loc,
8419 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
8422 Set_Analyzed (Skip_Stat);
8424 Insert_After (N, Skip_Stat);
8425 end Expand_N_Requeue_Statement;
8427 -------------------------------
8428 -- Expand_N_Selective_Accept --
8429 -------------------------------
8431 procedure Expand_N_Selective_Accept (N : Node_Id) is
8432 Loc : constant Source_Ptr := Sloc (N);
8433 Alts : constant List_Id := Select_Alternatives (N);
8435 -- Note: in the below declarations a lot of new lists are allocated
8436 -- unconditionally which may well not end up being used. That's
8437 -- not a good idea since it wastes space gratuitously ???
8439 Accept_Case : List_Id;
8440 Accept_List : constant List_Id := New_List;
8443 Alt_List : constant List_Id := New_List;
8444 Alt_Stats : List_Id;
8445 Ann : Entity_Id := Empty;
8448 Check_Guard : Boolean := True;
8450 Decls : constant List_Id := New_List;
8451 Stats : constant List_Id := New_List;
8452 Body_List : constant List_Id := New_List;
8453 Trailing_List : constant List_Id := New_List;
8456 Else_Present : Boolean := False;
8457 Terminate_Alt : Node_Id := Empty;
8458 Select_Mode : Node_Id;
8460 Delay_Case : List_Id;
8461 Delay_Count : Integer := 0;
8462 Delay_Val : Entity_Id;
8463 Delay_Index : Entity_Id;
8464 Delay_Min : Entity_Id;
8465 Delay_Num : Int := 1;
8466 Delay_Alt_List : List_Id := New_List;
8467 Delay_List : constant List_Id := New_List;
8471 First_Delay : Boolean := True;
8472 Guard_Open : Entity_Id;
8478 Num_Accept : Nat := 0;
8481 Time_Type : Entity_Id;
8483 Select_Call : Node_Id;
8485 Qnam : constant Entity_Id :=
8486 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
8488 Xnam : constant Entity_Id :=
8489 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
8491 -----------------------
8492 -- Local subprograms --
8493 -----------------------
8495 function Accept_Or_Raise return List_Id;
8496 -- For the rare case where delay alternatives all have guards, and
8497 -- all of them are closed, it is still possible that there were open
8498 -- accept alternatives with no callers. We must reexamine the
8499 -- Accept_List, and execute a selective wait with no else if some
8500 -- accept is open. If none, we raise program_error.
8502 procedure Add_Accept (Alt : Node_Id);
8503 -- Process a single accept statement in a select alternative. Build
8504 -- procedure for body of accept, and add entry to dispatch table with
8505 -- expression for guard, in preparation for call to run time select.
8507 function Make_And_Declare_Label (Num : Int) return Node_Id;
8508 -- Manufacture a label using Num as a serial number and declare it.
8509 -- The declaration is appended to Decls. The label marks the trailing
8510 -- statements of an accept or delay alternative.
8512 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
8513 -- Build call to Selective_Wait runtime routine
8515 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
8516 -- Add code to compare value of delay with previous values, and
8517 -- generate case entry for trailing statements.
8519 procedure Process_Accept_Alternative
8523 -- Add code to call corresponding procedure, and branch to
8524 -- trailing statements, if any.
8526 ---------------------
8527 -- Accept_Or_Raise --
8528 ---------------------
8530 function Accept_Or_Raise return List_Id is
8533 J : constant Entity_Id := Make_Defining_Identifier (Loc,
8534 New_Internal_Name ('J'));
8537 -- We generate the following:
8539 -- for J in q'range loop
8540 -- if q(J).S /=null_task_entry then
8541 -- selective_wait (simple_mode,...);
8547 -- if no rendez_vous then
8548 -- raise program_error;
8551 -- Note that the code needs to know that the selector name
8552 -- in an Accept_Alternative is named S.
8554 Cond := Make_Op_Ne (Loc,
8556 Make_Selected_Component (Loc,
8557 Prefix => Make_Indexed_Component (Loc,
8558 Prefix => New_Reference_To (Qnam, Loc),
8559 Expressions => New_List (New_Reference_To (J, Loc))),
8560 Selector_Name => Make_Identifier (Loc, Name_S)),
8562 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
8565 Make_Implicit_Loop_Statement (N,
8566 Identifier => Empty,
8568 Make_Iteration_Scheme (Loc,
8569 Loop_Parameter_Specification =>
8570 Make_Loop_Parameter_Specification (Loc,
8571 Defining_Identifier => J,
8572 Discrete_Subtype_Definition =>
8573 Make_Attribute_Reference (Loc,
8574 Prefix => New_Reference_To (Qnam, Loc),
8575 Attribute_Name => Name_Range,
8576 Expressions => New_List (
8577 Make_Integer_Literal (Loc, 1))))),
8579 Statements => New_List (
8580 Make_Implicit_If_Statement (N,
8582 Then_Statements => New_List (
8584 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
8585 Make_Exit_Statement (Loc))))));
8588 Make_Raise_Program_Error (Loc,
8589 Condition => Make_Op_Eq (Loc,
8590 Left_Opnd => New_Reference_To (Xnam, Loc),
8592 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8593 Reason => PE_All_Guards_Closed));
8596 end Accept_Or_Raise;
8602 procedure Add_Accept (Alt : Node_Id) is
8603 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
8604 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
8605 Eloc : constant Source_Ptr := Sloc (Ename);
8606 Eent : constant Entity_Id := Entity (Ename);
8607 Index : constant Node_Id := Entry_Index (Acc_Stm);
8608 Null_Body : Node_Id;
8609 Proc_Body : Node_Id;
8616 Ann := Node (Last_Elmt (Accept_Address (Eent)));
8619 if Present (Condition (Alt)) then
8621 Make_Conditional_Expression (Eloc, New_List (
8623 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
8624 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
8627 Entry_Index_Expression
8628 (Eloc, Eent, Index, Scope (Eent));
8631 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8632 Null_Body := New_Reference_To (Standard_False, Eloc);
8634 if Abort_Allowed then
8635 Call := Make_Procedure_Call_Statement (Eloc,
8636 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
8637 Insert_Before (First (Statements (Handled_Statement_Sequence (
8638 Accept_Statement (Alt)))), Call);
8643 Make_Defining_Identifier (Eloc,
8644 New_External_Name (Chars (Ename), 'A', Num_Accept));
8646 if Comes_From_Source (Alt) then
8647 Set_Debug_Info_Needed (PB_Ent);
8651 Make_Subprogram_Body (Eloc,
8653 Make_Procedure_Specification (Eloc,
8654 Defining_Unit_Name => PB_Ent),
8655 Declarations => Declarations (Acc_Stm),
8656 Handled_Statement_Sequence =>
8657 Build_Accept_Body (Accept_Statement (Alt)));
8659 -- During the analysis of the body of the accept statement, any
8660 -- zero cost exception handler records were collected in the
8661 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8662 -- This is where we move them to where they belong, namely the
8663 -- newly created procedure.
8665 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8666 Append (Proc_Body, Body_List);
8669 Null_Body := New_Reference_To (Standard_True, Eloc);
8671 -- if accept statement has declarations, insert above, given that
8672 -- we are not creating a body for the accept.
8674 if Present (Declarations (Acc_Stm)) then
8675 Insert_Actions (N, Declarations (Acc_Stm));
8679 Append_To (Accept_List,
8680 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
8682 Num_Accept := Num_Accept + 1;
8685 ----------------------------
8686 -- Make_And_Declare_Label --
8687 ----------------------------
8689 function Make_And_Declare_Label (Num : Int) return Node_Id is
8693 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8695 Make_Label (Loc, Lab_Id);
8698 Make_Implicit_Label_Declaration (Loc,
8699 Defining_Identifier =>
8700 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8701 Label_Construct => Lab));
8704 end Make_And_Declare_Label;
8706 ----------------------
8707 -- Make_Select_Call --
8708 ----------------------
8710 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8711 Params : constant List_Id := New_List;
8715 Make_Attribute_Reference (Loc,
8716 Prefix => New_Reference_To (Qnam, Loc),
8717 Attribute_Name => Name_Unchecked_Access),
8719 Append (Select_Mode, Params);
8720 Append (New_Reference_To (Ann, Loc), Params);
8721 Append (New_Reference_To (Xnam, Loc), Params);
8724 Make_Procedure_Call_Statement (Loc,
8725 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8726 Parameter_Associations => Params);
8727 end Make_Select_Call;
8729 --------------------------------
8730 -- Process_Accept_Alternative --
8731 --------------------------------
8733 procedure Process_Accept_Alternative
8738 Choices : List_Id := No_List;
8739 Alt_Stats : List_Id;
8742 Adjust_Condition (Condition (Alt));
8743 Alt_Stats := No_List;
8745 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8746 Choices := New_List (
8747 Make_Integer_Literal (Loc, Index));
8749 Alt_Stats := New_List (
8750 Make_Procedure_Call_Statement (Sloc (Proc),
8751 Name => New_Reference_To (
8752 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
8755 if Statements (Alt) /= Empty_List then
8757 if No (Alt_Stats) then
8759 -- Accept with no body, followed by trailing statements
8761 Choices := New_List (
8762 Make_Integer_Literal (Loc, Index));
8764 Alt_Stats := New_List;
8767 -- After the call, if any, branch to trailing statements. We
8768 -- create a label for each, as well as the corresponding label
8771 Lab := Make_And_Declare_Label (Index);
8772 Append_To (Alt_Stats,
8773 Make_Goto_Statement (Loc,
8774 Name => New_Copy (Identifier (Lab))));
8776 Append (Lab, Trailing_List);
8777 Append_List (Statements (Alt), Trailing_List);
8778 Append_To (Trailing_List,
8779 Make_Goto_Statement (Loc,
8780 Name => New_Copy (Identifier (End_Lab))));
8783 if Present (Alt_Stats) then
8785 -- Procedure call. and/or trailing statements
8787 Append_To (Alt_List,
8788 Make_Case_Statement_Alternative (Loc,
8789 Discrete_Choices => Choices,
8790 Statements => Alt_Stats));
8792 end Process_Accept_Alternative;
8794 -------------------------------
8795 -- Process_Delay_Alternative --
8796 -------------------------------
8798 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
8801 Delay_Alt : List_Id;
8804 -- Deal with C/Fortran boolean as delay condition
8806 Adjust_Condition (Condition (Alt));
8808 -- Determine the smallest specified delay
8810 -- for each delay alternative generate:
8812 -- if guard-expression then
8813 -- Delay_Val := delay-expression;
8814 -- Guard_Open := True;
8815 -- if Delay_Val < Delay_Min then
8816 -- Delay_Min := Delay_Val;
8817 -- Delay_Index := Index;
8821 -- The enclosing if-statement is omitted if there is no guard
8826 First_Delay := False;
8828 Delay_Alt := New_List (
8829 Make_Assignment_Statement (Loc,
8830 Name => New_Reference_To (Delay_Min, Loc),
8831 Expression => Expression (Delay_Statement (Alt))));
8833 if Delay_Count > 1 then
8834 Append_To (Delay_Alt,
8835 Make_Assignment_Statement (Loc,
8836 Name => New_Reference_To (Delay_Index, Loc),
8837 Expression => Make_Integer_Literal (Loc, Index)));
8841 Delay_Alt := New_List (
8842 Make_Assignment_Statement (Loc,
8843 Name => New_Reference_To (Delay_Val, Loc),
8844 Expression => Expression (Delay_Statement (Alt))));
8846 if Time_Type = Standard_Duration then
8849 Left_Opnd => New_Reference_To (Delay_Val, Loc),
8850 Right_Opnd => New_Reference_To (Delay_Min, Loc));
8853 -- The scope of the time type must define a comparison
8854 -- operator. The scope itself may not be visible, so we
8855 -- construct a node with entity information to insure that
8856 -- semantic analysis can find the proper operator.
8859 Make_Function_Call (Loc,
8860 Name => Make_Selected_Component (Loc,
8861 Prefix => New_Reference_To (Scope (Time_Type), Loc),
8863 Make_Operator_Symbol (Loc,
8864 Chars => Name_Op_Lt,
8865 Strval => No_String)),
8866 Parameter_Associations =>
8868 New_Reference_To (Delay_Val, Loc),
8869 New_Reference_To (Delay_Min, Loc)));
8871 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
8874 Append_To (Delay_Alt,
8875 Make_Implicit_If_Statement (N,
8877 Then_Statements => New_List (
8878 Make_Assignment_Statement (Loc,
8879 Name => New_Reference_To (Delay_Min, Loc),
8880 Expression => New_Reference_To (Delay_Val, Loc)),
8882 Make_Assignment_Statement (Loc,
8883 Name => New_Reference_To (Delay_Index, Loc),
8884 Expression => Make_Integer_Literal (Loc, Index)))));
8888 Append_To (Delay_Alt,
8889 Make_Assignment_Statement (Loc,
8890 Name => New_Reference_To (Guard_Open, Loc),
8891 Expression => New_Reference_To (Standard_True, Loc)));
8894 if Present (Condition (Alt)) then
8895 Delay_Alt := New_List (
8896 Make_Implicit_If_Statement (N,
8897 Condition => Condition (Alt),
8898 Then_Statements => Delay_Alt));
8901 Append_List (Delay_Alt, Delay_List);
8903 -- If the delay alternative has a statement part, add choice to the
8904 -- case statements for delays.
8906 if Present (Statements (Alt)) then
8908 if Delay_Count = 1 then
8909 Append_List (Statements (Alt), Delay_Alt_List);
8912 Choices := New_List (
8913 Make_Integer_Literal (Loc, Index));
8915 Append_To (Delay_Alt_List,
8916 Make_Case_Statement_Alternative (Loc,
8917 Discrete_Choices => Choices,
8918 Statements => Statements (Alt)));
8921 elsif Delay_Count = 1 then
8923 -- If the single delay has no trailing statements, add a branch
8924 -- to the exit label to the selective wait.
8926 Delay_Alt_List := New_List (
8927 Make_Goto_Statement (Loc,
8928 Name => New_Copy (Identifier (End_Lab))));
8931 end Process_Delay_Alternative;
8933 -- Start of processing for Expand_N_Selective_Accept
8936 -- First insert some declarations before the select. The first is:
8940 -- This variable holds the parameters passed to the accept body. This
8941 -- declaration has already been inserted by the time we get here by
8942 -- a call to Expand_Accept_Declarations made from the semantics when
8943 -- processing the first accept statement contained in the select. We
8944 -- can find this entity as Accept_Address (E), where E is any of the
8945 -- entries references by contained accept statements.
8947 -- The first step is to scan the list of Selective_Accept_Statements
8948 -- to find this entity, and also count the number of accepts, and
8949 -- determine if terminated, delay or else is present:
8953 Alt := First (Alts);
8954 while Present (Alt) loop
8956 if Nkind (Alt) = N_Accept_Alternative then
8959 elsif Nkind (Alt) = N_Delay_Alternative then
8960 Delay_Count := Delay_Count + 1;
8962 -- If the delays are relative delays, the delay expressions have
8963 -- type Standard_Duration. Otherwise they must have some time type
8964 -- recognized by GNAT.
8966 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
8967 Time_Type := Standard_Duration;
8969 Time_Type := Etype (Expression (Delay_Statement (Alt)));
8971 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
8972 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
8977 "& is not a time type (RM 9.6(6))",
8978 Expression (Delay_Statement (Alt)), Time_Type);
8979 Time_Type := Standard_Duration;
8980 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
8984 if No (Condition (Alt)) then
8986 -- This guard will always be open
8988 Check_Guard := False;
8991 elsif Nkind (Alt) = N_Terminate_Alternative then
8992 Adjust_Condition (Condition (Alt));
8993 Terminate_Alt := Alt;
8996 Num_Alts := Num_Alts + 1;
9000 Else_Present := Present (Else_Statements (N));
9002 -- At the same time (see procedure Add_Accept) we build the accept list:
9004 -- Qnn : Accept_List (1 .. num-select) := (
9005 -- (null-body, entry-index),
9006 -- (null-body, entry-index),
9008 -- (null_body, entry-index));
9010 -- In the above declaration, null-body is True if the corresponding
9011 -- accept has no body, and false otherwise. The entry is either the
9012 -- entry index expression if there is no guard, or if a guard is
9013 -- present, then a conditional expression of the form:
9015 -- (if guard then entry-index else Null_Task_Entry)
9017 -- If a guard is statically known to be false, the entry can simply
9018 -- be omitted from the accept list.
9021 Make_Object_Declaration (Loc,
9022 Defining_Identifier => Qnam,
9023 Object_Definition =>
9024 New_Reference_To (RTE (RE_Accept_List), Loc),
9025 Aliased_Present => True,
9028 Make_Qualified_Expression (Loc,
9030 New_Reference_To (RTE (RE_Accept_List), Loc),
9032 Make_Aggregate (Loc, Expressions => Accept_List)));
9036 -- Then we declare the variable that holds the index for the accept
9037 -- that will be selected for service:
9039 -- Xnn : Select_Index;
9042 Make_Object_Declaration (Loc,
9043 Defining_Identifier => Xnam,
9044 Object_Definition =>
9045 New_Reference_To (RTE (RE_Select_Index), Loc),
9047 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9051 -- After this follow procedure declarations for each accept body
9058 -- where the ... are statements from the corresponding procedure body.
9059 -- No parameters are involved, since the parameters are passed via Ann
9060 -- and the parameter references have already been expanded to be direct
9061 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9062 -- any embedded tasking statements (which would normally be illegal in
9063 -- procedures), have been converted to calls to the tasking runtime so
9064 -- there is no problem in putting them into procedures.
9066 -- The original accept statement has been expanded into a block in
9067 -- the same fashion as for simple accepts (see Build_Accept_Body).
9069 -- Note: we don't really need to build these procedures for the case
9070 -- where no delay statement is present, but it is just as easy to
9071 -- build them unconditionally, and not significantly inefficient,
9072 -- since if they are short they will be inlined anyway.
9074 -- The procedure declarations have been assembled in Body_List
9076 -- If delays are present, we must compute the required delay.
9077 -- We first generate the declarations:
9079 -- Delay_Index : Boolean := 0;
9080 -- Delay_Min : Some_Time_Type.Time;
9081 -- Delay_Val : Some_Time_Type.Time;
9083 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9084 -- active delay that is actually chosen as the basis for the possible
9085 -- delay if an immediate rendez-vous is not possible.
9087 -- In the most common case there is a single delay statement, and this
9088 -- is handled specially.
9090 if Delay_Count > 0 then
9092 -- Generate the required declarations
9095 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9097 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9099 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9102 Make_Object_Declaration (Loc,
9103 Defining_Identifier => Delay_Val,
9104 Object_Definition => New_Reference_To (Time_Type, Loc)));
9107 Make_Object_Declaration (Loc,
9108 Defining_Identifier => Delay_Index,
9109 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9110 Expression => Make_Integer_Literal (Loc, 0)));
9113 Make_Object_Declaration (Loc,
9114 Defining_Identifier => Delay_Min,
9115 Object_Definition => New_Reference_To (Time_Type, Loc),
9117 Unchecked_Convert_To (Time_Type,
9118 Make_Attribute_Reference (Loc,
9120 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9121 Attribute_Name => Name_Last))));
9123 -- Create Duration and Delay_Mode objects used for passing a delay
9126 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
9127 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
9133 -- Note that these values are defined in s-osprim.ads and must
9136 -- Relative : constant := 0;
9137 -- Absolute_Calendar : constant := 1;
9138 -- Absolute_RT : constant := 2;
9140 if Time_Type = Standard_Duration then
9141 Discr := Make_Integer_Literal (Loc, 0);
9143 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9144 Discr := Make_Integer_Literal (Loc, 1);
9148 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9149 Discr := Make_Integer_Literal (Loc, 2);
9153 Make_Object_Declaration (Loc,
9154 Defining_Identifier => D,
9155 Object_Definition =>
9156 New_Reference_To (Standard_Duration, Loc)));
9159 Make_Object_Declaration (Loc,
9160 Defining_Identifier => M,
9161 Object_Definition =>
9162 New_Reference_To (Standard_Integer, Loc),
9163 Expression => Discr));
9168 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9171 Make_Object_Declaration (Loc,
9172 Defining_Identifier => Guard_Open,
9173 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9174 Expression => New_Reference_To (Standard_False, Loc)));
9177 -- Delay_Count is zero, don't need M and D set (suppress warning)
9184 if Present (Terminate_Alt) then
9186 -- If the terminate alternative guard is False, use
9187 -- Simple_Mode; otherwise use Terminate_Mode.
9189 if Present (Condition (Terminate_Alt)) then
9190 Select_Mode := Make_Conditional_Expression (Loc,
9191 New_List (Condition (Terminate_Alt),
9192 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9193 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9195 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9198 elsif Else_Present or Delay_Count > 0 then
9199 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9202 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9205 Select_Call := Make_Select_Call (Select_Mode);
9206 Append (Select_Call, Stats);
9208 -- Now generate code to act on the result. There is an entry
9209 -- in this case for each accept statement with a non-null body,
9210 -- followed by a branch to the statements that follow the Accept.
9211 -- In the absence of delay alternatives, we generate:
9214 -- when No_Rendezvous => -- omitted if simple mode
9229 -- Lab0: Else_Statements;
9232 -- Lab1: Trailing_Statements1;
9235 -- Lab2: Trailing_Statements2;
9240 -- Generate label for common exit
9242 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9244 -- First entry is the default case, when no rendezvous is possible
9246 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9248 if Else_Present then
9250 -- If no rendezvous is possible, the else part is executed
9252 Lab := Make_And_Declare_Label (0);
9253 Alt_Stats := New_List (
9254 Make_Goto_Statement (Loc,
9255 Name => New_Copy (Identifier (Lab))));
9257 Append (Lab, Trailing_List);
9258 Append_List (Else_Statements (N), Trailing_List);
9259 Append_To (Trailing_List,
9260 Make_Goto_Statement (Loc,
9261 Name => New_Copy (Identifier (End_Lab))));
9263 Alt_Stats := New_List (
9264 Make_Goto_Statement (Loc,
9265 Name => New_Copy (Identifier (End_Lab))));
9268 Append_To (Alt_List,
9269 Make_Case_Statement_Alternative (Loc,
9270 Discrete_Choices => Choices,
9271 Statements => Alt_Stats));
9273 -- We make use of the fact that Accept_Index is an integer type, and
9274 -- generate successive literals for entries for each accept. Only those
9275 -- for which there is a body or trailing statements get a case entry.
9277 Alt := First (Select_Alternatives (N));
9278 Proc := First (Body_List);
9279 while Present (Alt) loop
9281 if Nkind (Alt) = N_Accept_Alternative then
9282 Process_Accept_Alternative (Alt, Index, Proc);
9286 (Handled_Statement_Sequence (Accept_Statement (Alt)))
9291 elsif Nkind (Alt) = N_Delay_Alternative then
9292 Process_Delay_Alternative (Alt, Delay_Num);
9293 Delay_Num := Delay_Num + 1;
9299 -- An others choice is always added to the main case, as well
9300 -- as the delay case (to satisfy the compiler).
9302 Append_To (Alt_List,
9303 Make_Case_Statement_Alternative (Loc,
9305 New_List (Make_Others_Choice (Loc)),
9307 New_List (Make_Goto_Statement (Loc,
9308 Name => New_Copy (Identifier (End_Lab))))));
9310 Accept_Case := New_List (
9311 Make_Case_Statement (Loc,
9312 Expression => New_Reference_To (Xnam, Loc),
9313 Alternatives => Alt_List));
9315 Append_List (Trailing_List, Accept_Case);
9316 Append (End_Lab, Accept_Case);
9317 Append_List (Body_List, Decls);
9319 -- Construct case statement for trailing statements of delay
9320 -- alternatives, if there are several of them.
9322 if Delay_Count > 1 then
9323 Append_To (Delay_Alt_List,
9324 Make_Case_Statement_Alternative (Loc,
9326 New_List (Make_Others_Choice (Loc)),
9328 New_List (Make_Null_Statement (Loc))));
9330 Delay_Case := New_List (
9331 Make_Case_Statement (Loc,
9332 Expression => New_Reference_To (Delay_Index, Loc),
9333 Alternatives => Delay_Alt_List));
9335 Delay_Case := Delay_Alt_List;
9338 -- If there are no delay alternatives, we append the case statement
9339 -- to the statement list.
9341 if Delay_Count = 0 then
9342 Append_List (Accept_Case, Stats);
9344 -- Delay alternatives present
9347 -- If delay alternatives are present we generate:
9349 -- find minimum delay.
9350 -- DX := minimum delay;
9351 -- M := <delay mode>;
9352 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9355 -- if X = No_Rendezvous then
9356 -- case statement for delay statements.
9358 -- case statement for accept alternatives.
9369 -- The type of the delay expression is known to be legal
9371 if Time_Type = Standard_Duration then
9372 Conv := New_Reference_To (Delay_Min, Loc);
9374 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9375 Conv := Make_Function_Call (Loc,
9376 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9377 New_List (New_Reference_To (Delay_Min, Loc)));
9381 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9383 Conv := Make_Function_Call (Loc,
9384 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9385 New_List (New_Reference_To (Delay_Min, Loc)));
9388 Stmt := Make_Assignment_Statement (Loc,
9389 Name => New_Reference_To (D, Loc),
9390 Expression => Conv);
9392 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
9394 Parms := Parameter_Associations (Select_Call);
9395 Parm := First (Parms);
9397 while Present (Parm)
9398 and then Parm /= Select_Mode
9403 pragma Assert (Present (Parm));
9404 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
9407 -- Prepare two new parameters of Duration and Delay_Mode type
9408 -- which represent the value and the mode of the minimum delay.
9411 Insert_After (Parm, New_Reference_To (M, Loc));
9412 Insert_After (Parm, New_Reference_To (D, Loc));
9414 -- Create a call to RTS
9416 Rewrite (Select_Call,
9417 Make_Procedure_Call_Statement (Loc,
9418 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
9419 Parameter_Associations => Parms));
9421 -- This new call should follow the calculation of the minimum
9424 Insert_List_Before (Select_Call, Delay_List);
9428 Make_Implicit_If_Statement (N,
9429 Condition => New_Reference_To (Guard_Open, Loc),
9431 New_List (New_Copy_Tree (Stmt),
9432 New_Copy_Tree (Select_Call)),
9433 Else_Statements => Accept_Or_Raise);
9434 Rewrite (Select_Call, Stmt);
9436 Insert_Before (Select_Call, Stmt);
9440 Make_Implicit_If_Statement (N,
9441 Condition => Make_Op_Eq (Loc,
9442 Left_Opnd => New_Reference_To (Xnam, Loc),
9444 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9446 Then_Statements => Delay_Case,
9447 Else_Statements => Accept_Case);
9449 Append (Cases, Stats);
9453 -- Replace accept statement with appropriate block
9456 Make_Block_Statement (Loc,
9457 Declarations => Decls,
9458 Handled_Statement_Sequence =>
9459 Make_Handled_Sequence_Of_Statements (Loc,
9460 Statements => Stats));
9465 -- Note: have to worry more about abort deferral in above code ???
9467 -- Final step is to unstack the Accept_Address entries for all accept
9468 -- statements appearing in accept alternatives in the select statement
9470 Alt := First (Alts);
9471 while Present (Alt) loop
9472 if Nkind (Alt) = N_Accept_Alternative then
9473 Remove_Last_Elmt (Accept_Address
9474 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
9479 end Expand_N_Selective_Accept;
9481 --------------------------------------
9482 -- Expand_N_Single_Task_Declaration --
9483 --------------------------------------
9485 -- Single task declarations should never be present after semantic
9486 -- analysis, since we expect them to be replaced by a declaration of an
9487 -- anonymous task type, followed by a declaration of the task object. We
9488 -- include this routine to make sure that is happening!
9490 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
9492 raise Program_Error;
9493 end Expand_N_Single_Task_Declaration;
9495 ------------------------
9496 -- Expand_N_Task_Body --
9497 ------------------------
9499 -- Given a task body
9501 -- task body tname is
9507 -- This expansion routine converts it into a procedure and sets the
9508 -- elaboration flag for the procedure to true, to represent the fact
9509 -- that the task body is now elaborated:
9511 -- procedure tnameB (_Task : access tnameV) is
9512 -- discriminal : dtype renames _Task.discriminant;
9514 -- procedure _clean is
9518 -- Abort_Undefer.all;
9523 -- Abort_Undefer.all;
9525 -- System.Task_Stages.Complete_Activation;
9533 -- In addition, if the task body is an activator, then a call to activate
9534 -- tasks is added at the start of the statements, before the call to
9535 -- Complete_Activation, and if in addition the task is a master then it
9536 -- must be established as a master. These calls are inserted and analyzed
9537 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9540 -- There is one discriminal declaration line generated for each
9541 -- discriminant that is present to provide an easy reference point for
9542 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9544 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9545 -- task body procedures have a profile (Arg : System.Address). That is
9546 -- needed because GNARLI has to use the same access-to-subprogram type
9547 -- for all task types. We depend here on knowing that in GNAT, passing
9548 -- an address argument by value is identical to passing a record value
9549 -- by access (in either case a single pointer is passed), so even though
9550 -- this procedure has the wrong profile. In fact it's all OK, since the
9551 -- callings sequence is identical.
9553 procedure Expand_N_Task_Body (N : Node_Id) is
9554 Loc : constant Source_Ptr := Sloc (N);
9555 Ttyp : constant Entity_Id := Corresponding_Spec (N);
9559 Insert_Nod : Node_Id;
9560 -- Used to determine the proper location of wrapper body insertions
9563 -- Add renaming declarations for discriminals and a declaration for the
9564 -- entry family index (if applicable).
9566 Install_Private_Data_Declarations
9567 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
9569 -- Add a call to Abort_Undefer at the very beginning of the task
9570 -- body since this body is called with abort still deferred.
9572 if Abort_Allowed then
9573 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
9575 (First (Statements (Handled_Statement_Sequence (N))), Call);
9579 -- The statement part has already been protected with an at_end and
9580 -- cleanup actions. The call to Complete_Activation must be placed
9581 -- at the head of the sequence of statements of that block. The
9582 -- declarations have been merged in this sequence of statements but
9583 -- the first real statement is accessible from the First_Real_Statement
9584 -- field (which was set for exactly this purpose).
9586 if Restricted_Profile then
9587 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
9589 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
9593 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
9597 Make_Subprogram_Body (Loc,
9598 Specification => Build_Task_Proc_Specification (Ttyp),
9599 Declarations => Declarations (N),
9600 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
9602 -- If the task contains generic instantiations, cleanup actions are
9603 -- delayed until after instantiation. Transfer the activation chain to
9604 -- the subprogram, to insure that the activation call is properly
9605 -- generated. It the task body contains inner tasks, indicate that the
9606 -- subprogram is a task master.
9608 if Delay_Cleanups (Ttyp) then
9609 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
9610 Set_Is_Task_Master (New_N, Is_Task_Master (N));
9616 -- Set elaboration flag immediately after task body. If the body is a
9617 -- subunit, the flag is set in the declarative part containing the stub.
9619 if Nkind (Parent (N)) /= N_Subunit then
9621 Make_Assignment_Statement (Loc,
9623 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
9624 Expression => New_Reference_To (Standard_True, Loc)));
9627 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9628 -- the task body. At this point all wrapper specs have been created,
9629 -- frozen and included in the dispatch table for the task type.
9631 if Ada_Version >= Ada_05 then
9632 if Nkind (Parent (N)) = N_Subunit then
9633 Insert_Nod := Corresponding_Stub (Parent (N));
9638 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
9640 end Expand_N_Task_Body;
9642 ------------------------------------
9643 -- Expand_N_Task_Type_Declaration --
9644 ------------------------------------
9646 -- We have several things to do. First we must create a Boolean flag used
9647 -- to mark if the body is elaborated yet. This variable gets set to True
9648 -- when the body of the task is elaborated (we can't rely on the normal
9649 -- ABE mechanism for the task body, since we need to pass an access to
9650 -- this elaboration boolean to the runtime routines).
9652 -- taskE : aliased Boolean := False;
9654 -- Next a variable is declared to hold the task stack size (either the
9655 -- default : Unspecified_Size, or a value that is set by a pragma
9656 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9657 -- the variable is initialized with this value:
9659 -- taskZ : Size_Type := Unspecified_Size;
9661 -- taskZ : Size_Type := Size_Type (size_expression);
9663 -- Note: No variable is needed to hold the task relative deadline since
9664 -- its value would never be static because the parameter is of a private
9665 -- type (Ada.Real_Time.Time_Span).
9667 -- Next we create a corresponding record type declaration used to represent
9668 -- values of this task. The general form of this type declaration is
9670 -- type taskV (discriminants) is record
9671 -- _Task_Id : Task_Id;
9672 -- entry_family : array (bounds) of Void;
9673 -- _Priority : Integer := priority_expression;
9674 -- _Size : Size_Type := Size_Type (size_expression);
9675 -- _Task_Info : Task_Info_Type := task_info_expression;
9678 -- The discriminants are present only if the corresponding task type has
9679 -- discriminants, and they exactly mirror the task type discriminants.
9681 -- The Id field is always present. It contains the Task_Id value, as set by
9682 -- the call to Create_Task. Note that although the task is limited, the
9683 -- task value record type is not limited, so there is no problem in passing
9684 -- this field as an out parameter to Create_Task.
9686 -- One entry_family component is present for each entry family in the task
9687 -- definition. The bounds correspond to the bounds of the entry family
9688 -- (which may depend on discriminants). The element type is void, since we
9689 -- only need the bounds information for determining the entry index. Note
9690 -- that the use of an anonymous array would normally be illegal in this
9691 -- context, but this is a parser check, and the semantics is quite prepared
9692 -- to handle such a case.
9694 -- The _Size field is present only if a Storage_Size pragma appears in the
9695 -- task definition. The expression captures the argument that was present
9696 -- in the pragma, and is used to override the task stack size otherwise
9697 -- associated with the task type.
9699 -- The _Priority field is present only if a Priority or Interrupt_Priority
9700 -- pragma appears in the task definition. The expression captures the
9701 -- argument that was present in the pragma, and is used to provide the Size
9702 -- parameter to the call to Create_Task.
9704 -- The _Task_Info field is present only if a Task_Info pragma appears in
9705 -- the task definition. The expression captures the argument that was
9706 -- present in the pragma, and is used to provide the Task_Image parameter
9707 -- to the call to Create_Task.
9709 -- The _Relative_Deadline field is present only if a Relative_Deadline
9710 -- pragma appears in the task definition. The expression captures the
9711 -- argument that was present in the pragma, and is used to provide the
9712 -- Relative_Deadline parameter to the call to Create_Task.
9714 -- When a task is declared, an instance of the task value record is
9715 -- created. The elaboration of this declaration creates the correct bounds
9716 -- for the entry families, and also evaluates the size, priority, and
9717 -- task_Info expressions if needed. The initialization routine for the task
9718 -- type itself then calls Create_Task with appropriate parameters to
9719 -- initialize the value of the Task_Id field.
9721 -- Note: the address of this record is passed as the "Discriminants"
9722 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9723 -- body procedure, it does not matter that it does not quite match the
9724 -- GNARLI model of what is being passed (the record contains more than just
9725 -- the discriminants, but the discriminants can be found from the record
9728 -- The Entity_Id for this created record type is placed in the
9729 -- Corresponding_Record_Type field of the associated task type entity.
9731 -- Next we create a procedure specification for the task body procedure:
9733 -- procedure taskB (_Task : access taskV);
9735 -- Note that this must come after the record type declaration, since
9736 -- the spec refers to this type. It turns out that the initialization
9737 -- procedure for the value type references the task body spec, but that's
9738 -- fine, since it won't be generated till the freeze point for the type,
9739 -- which is certainly after the task body spec declaration.
9741 -- Finally, we set the task index value field of the entry attribute in
9742 -- the case of a simple entry.
9744 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9745 Loc : constant Source_Ptr := Sloc (N);
9746 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9747 Tasknm : constant Name_Id := Chars (Tasktyp);
9748 Taskdef : constant Node_Id := Task_Definition (N);
9750 Proc_Spec : Node_Id;
9752 Rec_Ent : Entity_Id;
9754 Elab_Decl : Node_Id;
9755 Size_Decl : Node_Id;
9756 Body_Decl : Node_Id;
9757 Task_Size : Node_Id;
9758 Ent_Stack : Entity_Id;
9759 Decl_Stack : Node_Id;
9762 -- If already expanded, nothing to do
9764 if Present (Corresponding_Record_Type (Tasktyp)) then
9768 -- Here we will do the expansion
9770 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9772 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9773 -- of implemented interfaces.
9775 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9777 Rec_Ent := Defining_Identifier (Rec_Decl);
9778 Cdecls := Component_Items (Component_List
9779 (Type_Definition (Rec_Decl)));
9781 Qualify_Entity_Names (N);
9783 -- First create the elaboration variable
9786 Make_Object_Declaration (Loc,
9787 Defining_Identifier =>
9788 Make_Defining_Identifier (Sloc (Tasktyp),
9789 Chars => New_External_Name (Tasknm, 'E')),
9790 Aliased_Present => True,
9791 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9792 Expression => New_Reference_To (Standard_False, Loc));
9793 Insert_After (N, Elab_Decl);
9795 -- Next create the declaration of the size variable (tasknmZ)
9797 Set_Storage_Size_Variable (Tasktyp,
9798 Make_Defining_Identifier (Sloc (Tasktyp),
9799 Chars => New_External_Name (Tasknm, 'Z')));
9801 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
9802 Is_Static_Expression (Expression (First (
9803 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
9804 Taskdef, Name_Storage_Size)))))
9807 Make_Object_Declaration (Loc,
9808 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9809 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9811 Convert_To (RTE (RE_Size_Type),
9814 Pragma_Argument_Associations (
9815 Find_Task_Or_Protected_Pragma
9816 (Taskdef, Name_Storage_Size)))))));
9820 Make_Object_Declaration (Loc,
9821 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9822 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9823 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
9826 Insert_After (Elab_Decl, Size_Decl);
9828 -- Next build the rest of the corresponding record declaration. This is
9829 -- done last, since the corresponding record initialization procedure
9830 -- will reference the previously created entities.
9832 -- Fill in the component declarations -- first the _Task_Id field
9835 Make_Component_Declaration (Loc,
9836 Defining_Identifier =>
9837 Make_Defining_Identifier (Loc, Name_uTask_Id),
9838 Component_Definition =>
9839 Make_Component_Definition (Loc,
9840 Aliased_Present => False,
9841 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
9844 -- Declare static ATCB (that is, created by the expander) if we are
9845 -- using the Restricted run time.
9847 if Restricted_Profile then
9849 Make_Component_Declaration (Loc,
9850 Defining_Identifier =>
9851 Make_Defining_Identifier (Loc, Name_uATCB),
9853 Component_Definition =>
9854 Make_Component_Definition (Loc,
9855 Aliased_Present => True,
9856 Subtype_Indication => Make_Subtype_Indication (Loc,
9857 Subtype_Mark => New_Occurrence_Of
9858 (RTE (RE_Ada_Task_Control_Block), Loc),
9861 Make_Index_Or_Discriminant_Constraint (Loc,
9863 New_List (Make_Integer_Literal (Loc, 0)))))));
9867 -- Declare static stack (that is, created by the expander) if we are
9868 -- using the Restricted run time on a bare board configuration.
9870 if Restricted_Profile
9871 and then Preallocated_Stacks_On_Target
9873 -- First we need to extract the appropriate stack size
9875 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
9877 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
9879 Expr_N : constant Node_Id :=
9881 Pragma_Argument_Associations (
9882 Find_Task_Or_Protected_Pragma
9883 (Taskdef, Name_Storage_Size))));
9884 Etyp : constant Entity_Id := Etype (Expr_N);
9885 P : constant Node_Id := Parent (Expr_N);
9888 -- The stack is defined inside the corresponding record.
9889 -- Therefore if the size of the stack is set by means of
9890 -- a discriminant, we must reference the discriminant of the
9891 -- corresponding record type.
9893 if Nkind (Expr_N) in N_Has_Entity
9894 and then Present (Discriminal_Link (Entity (Expr_N)))
9898 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
9900 Set_Parent (Task_Size, P);
9901 Set_Etype (Task_Size, Etyp);
9902 Set_Analyzed (Task_Size);
9905 Task_Size := Relocate_Node (Expr_N);
9911 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
9914 Decl_Stack := Make_Component_Declaration (Loc,
9915 Defining_Identifier => Ent_Stack,
9917 Component_Definition =>
9918 Make_Component_Definition (Loc,
9919 Aliased_Present => True,
9920 Subtype_Indication => Make_Subtype_Indication (Loc,
9922 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
9925 Make_Index_Or_Discriminant_Constraint (Loc,
9926 Constraints => New_List (Make_Range (Loc,
9927 Low_Bound => Make_Integer_Literal (Loc, 1),
9928 High_Bound => Convert_To (RTE (RE_Storage_Offset),
9931 Append_To (Cdecls, Decl_Stack);
9933 -- The appropriate alignment for the stack is ensured by the run-time
9934 -- code in charge of task creation.
9938 -- Add components for entry families
9940 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
9942 -- Add the _Priority component if a Priority pragma is present
9944 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
9946 Prag : constant Node_Id :=
9947 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
9951 Expr := First (Pragma_Argument_Associations (Prag));
9953 if Nkind (Expr) = N_Pragma_Argument_Association then
9954 Expr := Expression (Expr);
9957 Expr := New_Copy_Tree (Expr);
9959 -- Add conversion to proper type to do range check if required
9960 -- Note that for runtime units, we allow out of range interrupt
9961 -- priority values to be used in a priority pragma. This is for
9962 -- the benefit of some versions of System.Interrupts which use
9963 -- a special server task with maximum interrupt priority.
9965 if Pragma_Name (Prag) = Name_Priority
9966 and then not GNAT_Mode
9968 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
9970 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
9974 Make_Component_Declaration (Loc,
9975 Defining_Identifier =>
9976 Make_Defining_Identifier (Loc, Name_uPriority),
9977 Component_Definition =>
9978 Make_Component_Definition (Loc,
9979 Aliased_Present => False,
9980 Subtype_Indication => New_Reference_To (Standard_Integer,
9982 Expression => Expr));
9986 -- Add the _Task_Size component if a Storage_Size pragma is present
9988 if Present (Taskdef)
9989 and then Has_Storage_Size_Pragma (Taskdef)
9992 Make_Component_Declaration (Loc,
9993 Defining_Identifier =>
9994 Make_Defining_Identifier (Loc, Name_uSize),
9996 Component_Definition =>
9997 Make_Component_Definition (Loc,
9998 Aliased_Present => False,
9999 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10003 Convert_To (RTE (RE_Size_Type),
10005 Expression (First (
10006 Pragma_Argument_Associations (
10007 Find_Task_Or_Protected_Pragma
10008 (Taskdef, Name_Storage_Size))))))));
10011 -- Add the _Task_Info component if a Task_Info pragma is present
10013 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10015 Make_Component_Declaration (Loc,
10016 Defining_Identifier =>
10017 Make_Defining_Identifier (Loc, Name_uTask_Info),
10019 Component_Definition =>
10020 Make_Component_Definition (Loc,
10021 Aliased_Present => False,
10022 Subtype_Indication =>
10023 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10025 Expression => New_Copy (
10026 Expression (First (
10027 Pragma_Argument_Associations (
10028 Find_Task_Or_Protected_Pragma
10029 (Taskdef, Name_Task_Info)))))));
10032 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10033 -- present. If we are using a restricted run time this component will
10034 -- not be added (deadlines are not allowed by the Ravenscar profile).
10036 if not Restricted_Profile
10037 and then Present (Taskdef)
10038 and then Has_Relative_Deadline_Pragma (Taskdef)
10041 Make_Component_Declaration (Loc,
10042 Defining_Identifier =>
10043 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10045 Component_Definition =>
10046 Make_Component_Definition (Loc,
10047 Aliased_Present => False,
10048 Subtype_Indication =>
10049 New_Reference_To (RTE (RE_Time_Span), Loc)),
10052 Convert_To (RTE (RE_Time_Span),
10054 Expression (First (
10055 Pragma_Argument_Associations (
10056 Find_Task_Or_Protected_Pragma
10057 (Taskdef, Name_Relative_Deadline))))))));
10060 Insert_After (Size_Decl, Rec_Decl);
10062 -- Analyze the record declaration immediately after construction,
10063 -- because the initialization procedure is needed for single task
10064 -- declarations before the next entity is analyzed.
10066 Analyze (Rec_Decl);
10068 -- Create the declaration of the task body procedure
10070 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10072 Make_Subprogram_Declaration (Loc,
10073 Specification => Proc_Spec);
10075 Insert_After (Rec_Decl, Body_Decl);
10077 -- The subprogram does not comes from source, so we have to indicate the
10078 -- need for debugging information explicitly.
10080 if Comes_From_Source (Original_Node (N)) then
10081 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10084 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10085 -- the corresponding record has been frozen.
10087 if Ada_Version >= Ada_05 then
10088 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10091 -- Ada 2005 (AI-345): We must defer freezing to allow further
10092 -- declaration of primitive subprograms covering task interfaces
10094 if Ada_Version <= Ada_95 then
10096 -- Now we can freeze the corresponding record. This needs manually
10097 -- freezing, since it is really part of the task type, and the task
10098 -- type is frozen at this stage. We of course need the initialization
10099 -- procedure for this corresponding record type and we won't get it
10100 -- in time if we don't freeze now.
10103 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
10105 if Is_Non_Empty_List (L) then
10106 Insert_List_After (Body_Decl, L);
10111 -- Complete the expansion of access types to the current task type, if
10112 -- any were declared.
10114 Expand_Previous_Access_Type (Tasktyp);
10115 end Expand_N_Task_Type_Declaration;
10117 -------------------------------
10118 -- Expand_N_Timed_Entry_Call --
10119 -------------------------------
10121 -- A timed entry call in normal case is not implemented using ATC mechanism
10122 -- anymore for efficiency reason.
10132 -- is expanded as follow:
10134 -- 1) When T.E is a task entry_call;
10138 -- X : Task_Entry_Index := <entry index>;
10139 -- DX : Duration := To_Duration (D);
10140 -- M : Delay_Mode := <discriminant>;
10141 -- P : parms := (parm, parm, parm);
10144 -- Timed_Protected_Entry_Call
10145 -- (<acceptor-task>, X, P'Address, DX, M, B);
10153 -- 2) When T.E is a protected entry_call;
10157 -- X : Protected_Entry_Index := <entry index>;
10158 -- DX : Duration := To_Duration (D);
10159 -- M : Delay_Mode := <discriminant>;
10160 -- P : parms := (parm, parm, parm);
10163 -- Timed_Protected_Entry_Call
10164 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10172 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10175 -- B : Boolean := False;
10176 -- C : Ada.Tags.Prim_Op_Kind;
10177 -- DX : Duration := To_Duration (D)
10178 -- K : Ada.Tags.Tagged_Kind :=
10179 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10180 -- M : Integer :=...;
10181 -- P : Parameters := (Param1 .. ParamN);
10185 -- if K = Ada.Tags.TK_Limited_Tagged then
10186 -- <dispatching-call>;
10187 -- <triggering-statements>
10191 -- Ada.Tags.Get_Offset_Index
10192 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10194 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10196 -- if C = POK_Protected_Entry
10197 -- or else C = POK_Task_Entry
10199 -- Param1 := P.Param1;
10201 -- ParamN := P.ParamN;
10205 -- if C = POK_Procedure
10206 -- or else C = POK_Protected_Procedure
10207 -- or else C = POK_Task_Procedure
10209 -- <dispatching-call>;
10212 -- <triggering-statements>
10214 -- <timed-statements>
10219 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10220 Loc : constant Source_Ptr := Sloc (N);
10222 E_Call : Node_Id :=
10223 Entry_Call_Statement (Entry_Call_Alternative (N));
10224 E_Stats : constant List_Id :=
10225 Statements (Entry_Call_Alternative (N));
10226 D_Stat : Node_Id :=
10227 Delay_Statement (Delay_Alternative (N));
10228 D_Stats : constant List_Id :=
10229 Statements (Delay_Alternative (N));
10232 Blk_Typ : Entity_Id;
10234 Call_Ent : Entity_Id;
10235 Conc_Typ_Stmts : List_Id;
10239 D_Type : Entity_Id;
10245 Is_Disp_Select : Boolean;
10246 Lim_Typ_Stmts : List_Id;
10255 B : Entity_Id; -- Call status flag
10256 C : Entity_Id; -- Call kind
10257 D : Entity_Id; -- Delay
10258 K : Entity_Id; -- Tagged kind
10259 M : Entity_Id; -- Delay mode
10260 P : Entity_Id; -- Parameter block
10261 S : Entity_Id; -- Primitive operation slot
10264 -- The arguments in the call may require dynamic allocation, and the
10265 -- call statement may have been transformed into a block. The block
10266 -- may contain additional declarations for internal entities, and the
10267 -- original call is found by sequential search.
10269 if Nkind (E_Call) = N_Block_Statement then
10270 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10271 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10272 N_Entry_Call_Statement)
10279 Ada_Version >= Ada_05
10280 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10282 if Is_Disp_Select then
10283 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
10289 -- B : Boolean := False;
10291 B := Build_B (Loc, Decls);
10294 -- C : Ada.Tags.Prim_Op_Kind;
10296 C := Build_C (Loc, Decls);
10298 -- Because the analysis of all statements was disabled, manually
10299 -- analyze the delay statement.
10302 D_Stat := Original_Node (D_Stat);
10305 -- Build an entry call using Simple_Entry_Call
10307 Extract_Entry (E_Call, Concval, Ename, Index);
10308 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
10310 Decls := Declarations (E_Call);
10311 Stmts := Statements (Handled_Statement_Sequence (E_Call));
10320 B := Make_Defining_Identifier (Loc, Name_uB);
10323 Make_Object_Declaration (Loc,
10324 Defining_Identifier =>
10326 Object_Definition =>
10327 New_Reference_To (Standard_Boolean, Loc)));
10330 -- Duration and mode processing
10332 D_Type := Base_Type (Etype (Expression (D_Stat)));
10334 -- Use the type of the delay expression (Calendar or Real_Time) to
10335 -- generate the appropriate conversion.
10337 if Nkind (D_Stat) = N_Delay_Relative_Statement then
10338 D_Disc := Make_Integer_Literal (Loc, 0);
10339 D_Conv := Relocate_Node (Expression (D_Stat));
10341 elsif Is_RTE (D_Type, RO_CA_Time) then
10342 D_Disc := Make_Integer_Literal (Loc, 1);
10343 D_Conv := Make_Function_Call (Loc,
10344 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10345 New_List (New_Copy (Expression (D_Stat))));
10347 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
10348 D_Disc := Make_Integer_Literal (Loc, 2);
10349 D_Conv := Make_Function_Call (Loc,
10350 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10351 New_List (New_Copy (Expression (D_Stat))));
10354 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
10360 Make_Object_Declaration (Loc,
10361 Defining_Identifier =>
10363 Object_Definition =>
10364 New_Reference_To (Standard_Duration, Loc)));
10366 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
10369 -- M : Integer := (0 | 1 | 2);
10372 Make_Object_Declaration (Loc,
10373 Defining_Identifier =>
10375 Object_Definition =>
10376 New_Reference_To (Standard_Integer, Loc),
10380 -- Do the assignment at this stage only because the evaluation of the
10381 -- expression must not occur before (see ACVC C97302A).
10384 Make_Assignment_Statement (Loc,
10386 New_Reference_To (D, Loc),
10390 -- Parameter block processing
10392 -- Manually create the parameter block for dispatching calls. In the
10393 -- case of entries, the block has already been created during the call
10394 -- to Build_Simple_Entry_Call.
10396 if Is_Disp_Select then
10398 -- Tagged kind processing, generate:
10399 -- K : Ada.Tags.Tagged_Kind :=
10400 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
10402 K := Build_K (Loc, Decls, Obj);
10404 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
10405 P := Parameter_Block_Pack
10406 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
10408 -- Dispatch table slot processing, generate:
10411 S := Build_S (Loc, Decls);
10414 -- S := Ada.Tags.Get_Offset_Index
10415 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
10418 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
10421 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
10423 -- where Obj is the controlling formal parameter, S is the dispatch
10424 -- table slot number of the dispatching operation, P is the wrapped
10425 -- parameter block, D is the duration, M is the duration mode, C is
10426 -- the call kind and B is the call status.
10428 Params := New_List;
10430 Append_To (Params, New_Copy_Tree (Obj));
10431 Append_To (Params, New_Reference_To (S, Loc));
10432 Append_To (Params, Make_Attribute_Reference (Loc,
10433 Prefix => New_Reference_To (P, Loc),
10434 Attribute_Name => Name_Address));
10435 Append_To (Params, New_Reference_To (D, Loc));
10436 Append_To (Params, New_Reference_To (M, Loc));
10437 Append_To (Params, New_Reference_To (C, Loc));
10438 Append_To (Params, New_Reference_To (B, Loc));
10440 Append_To (Conc_Typ_Stmts,
10441 Make_Procedure_Call_Statement (Loc,
10444 Find_Prim_Op (Etype (Etype (Obj)),
10445 Name_uDisp_Timed_Select),
10447 Parameter_Associations =>
10451 -- if C = POK_Protected_Entry
10452 -- or else C = POK_Task_Entry
10454 -- Param1 := P.Param1;
10456 -- ParamN := P.ParamN;
10459 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
10461 -- Generate the if statement only when the packed parameters need
10462 -- explicit assignments to their corresponding actuals.
10464 if Present (Unpack) then
10465 Append_To (Conc_Typ_Stmts,
10466 Make_If_Statement (Loc,
10473 New_Reference_To (C, Loc),
10475 New_Reference_To (RTE (
10476 RE_POK_Protected_Entry), Loc)),
10480 New_Reference_To (C, Loc),
10482 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
10491 -- if C = POK_Procedure
10492 -- or else C = POK_Protected_Procedure
10493 -- or else C = POK_Task_Procedure
10495 -- <dispatching-call>
10497 -- <triggering-statements>
10499 -- <timed-statements>
10502 N_Stats := New_Copy_List_Tree (E_Stats);
10504 Prepend_To (N_Stats,
10505 Make_If_Statement (Loc,
10512 New_Reference_To (C, Loc),
10514 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
10520 New_Reference_To (C, Loc),
10522 New_Reference_To (RTE (
10523 RE_POK_Protected_Procedure), Loc)),
10527 New_Reference_To (C, Loc),
10529 New_Reference_To (RTE (
10530 RE_POK_Task_Procedure), Loc)))),
10533 New_List (E_Call)));
10535 Append_To (Conc_Typ_Stmts,
10536 Make_If_Statement (Loc,
10537 Condition => New_Reference_To (B, Loc),
10538 Then_Statements => N_Stats,
10539 Else_Statements => D_Stats));
10542 -- <dispatching-call>;
10543 -- <triggering-statements>
10545 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
10546 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
10549 -- if K = Ada.Tags.TK_Limited_Tagged then
10556 Make_If_Statement (Loc,
10560 New_Reference_To (K, Loc),
10562 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
10571 -- Skip assignments to temporaries created for in-out parameters.
10572 -- This makes unwarranted assumptions about the shape of the expanded
10573 -- tree for the call, and should be cleaned up ???
10575 Stmt := First (Stmts);
10576 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
10580 -- Do the assignment at this stage only because the evaluation
10581 -- of the expression must not occur before (see ACVC C97302A).
10583 Insert_Before (Stmt,
10584 Make_Assignment_Statement (Loc,
10585 Name => New_Reference_To (D, Loc),
10586 Expression => D_Conv));
10589 Params := Parameter_Associations (Call);
10591 -- For a protected type, we build a Timed_Protected_Entry_Call
10593 if Is_Protected_Type (Etype (Concval)) then
10595 -- Create a new call statement
10597 Param := First (Params);
10598 while Present (Param)
10599 and then not Is_RTE (Etype (Param), RE_Call_Modes)
10604 Dummy := Remove_Next (Next (Param));
10606 -- Remove garbage is following the Cancel_Param if present
10608 Dummy := Next (Param);
10610 -- Remove the mode of the Protected_Entry_Call call, then remove
10611 -- the Communication_Block of the Protected_Entry_Call call, and
10612 -- finally add Duration and a Delay_Mode parameter
10614 pragma Assert (Present (Param));
10615 Rewrite (Param, New_Reference_To (D, Loc));
10617 Rewrite (Dummy, New_Reference_To (M, Loc));
10619 -- Add a Boolean flag for successful entry call
10621 Append_To (Params, New_Reference_To (B, Loc));
10623 case Corresponding_Runtime_Package (Etype (Concval)) is
10624 when System_Tasking_Protected_Objects_Entries =>
10626 Make_Procedure_Call_Statement (Loc,
10629 (RTE (RE_Timed_Protected_Entry_Call), Loc),
10630 Parameter_Associations => Params));
10632 when System_Tasking_Protected_Objects_Single_Entry =>
10633 Param := First (Params);
10634 while Present (Param)
10636 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
10644 Make_Procedure_Call_Statement (Loc,
10645 Name => New_Reference_To (
10646 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
10647 Parameter_Associations => Params));
10650 raise Program_Error;
10653 -- For the task case, build a Timed_Task_Entry_Call
10656 -- Create a new call statement
10658 Append_To (Params, New_Reference_To (D, Loc));
10659 Append_To (Params, New_Reference_To (M, Loc));
10660 Append_To (Params, New_Reference_To (B, Loc));
10663 Make_Procedure_Call_Statement (Loc,
10665 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
10666 Parameter_Associations => Params));
10670 Make_Implicit_If_Statement (N,
10671 Condition => New_Reference_To (B, Loc),
10672 Then_Statements => E_Stats,
10673 Else_Statements => D_Stats));
10677 Make_Block_Statement (Loc,
10678 Declarations => Decls,
10679 Handled_Statement_Sequence =>
10680 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
10683 end Expand_N_Timed_Entry_Call;
10685 ----------------------------------------
10686 -- Expand_Protected_Body_Declarations --
10687 ----------------------------------------
10689 procedure Expand_Protected_Body_Declarations
10691 Spec_Id : Entity_Id)
10694 if No_Run_Time_Mode then
10695 Error_Msg_CRT ("protected body", N);
10698 elsif Expander_Active then
10700 -- Associate discriminals with the first subprogram or entry body to
10703 if Present (First_Protected_Operation (Declarations (N))) then
10704 Set_Discriminals (Parent (Spec_Id));
10707 end Expand_Protected_Body_Declarations;
10709 -------------------------
10710 -- External_Subprogram --
10711 -------------------------
10713 function External_Subprogram (E : Entity_Id) return Entity_Id is
10714 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10717 -- The internal and external subprograms follow each other on the entity
10718 -- chain. Note that previously private operations had no separate
10719 -- external subprogram. We now create one in all cases, because a
10720 -- private operation may actually appear in an external call, through
10721 -- a 'Access reference used for a callback.
10723 -- If the operation is a function that returns an anonymous access type,
10724 -- the corresponding itype appears before the operation, and must be
10727 -- This mechanism is fragile, there should be a real link between the
10728 -- two versions of the operation, but there is no place to put it ???
10730 if Is_Access_Type (Next_Entity (Subp)) then
10731 return Next_Entity (Next_Entity (Subp));
10733 return Next_Entity (Subp);
10735 end External_Subprogram;
10737 ------------------------------
10738 -- Extract_Dispatching_Call --
10739 ------------------------------
10741 procedure Extract_Dispatching_Call
10743 Call_Ent : out Entity_Id;
10744 Object : out Entity_Id;
10745 Actuals : out List_Id;
10746 Formals : out List_Id)
10748 Call_Nam : Node_Id;
10751 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10753 if Present (Original_Node (N)) then
10754 Call_Nam := Name (Original_Node (N));
10756 Call_Nam := Name (N);
10759 -- Retrieve the name of the dispatching procedure. It contains the
10760 -- dispatch table slot number.
10763 case Nkind (Call_Nam) is
10764 when N_Identifier =>
10767 when N_Selected_Component =>
10768 Call_Nam := Selector_Name (Call_Nam);
10771 raise Program_Error;
10776 Actuals := Parameter_Associations (N);
10777 Call_Ent := Entity (Call_Nam);
10778 Formals := Parameter_Specifications (Parent (Call_Ent));
10779 Object := First (Actuals);
10781 if Present (Original_Node (Object)) then
10782 Object := Original_Node (Object);
10784 end Extract_Dispatching_Call;
10786 -------------------
10787 -- Extract_Entry --
10788 -------------------
10790 procedure Extract_Entry
10792 Concval : out Node_Id;
10793 Ename : out Node_Id;
10794 Index : out Node_Id)
10796 Nam : constant Node_Id := Name (N);
10799 -- For a simple entry, the name is a selected component, with the
10800 -- prefix being the task value, and the selector being the entry.
10802 if Nkind (Nam) = N_Selected_Component then
10803 Concval := Prefix (Nam);
10804 Ename := Selector_Name (Nam);
10807 -- For a member of an entry family, the name is an indexed component
10808 -- where the prefix is a selected component, whose prefix in turn is
10809 -- the task value, and whose selector is the entry family. The single
10810 -- expression in the expressions list of the indexed component is the
10811 -- subscript for the family.
10813 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
10814 Concval := Prefix (Prefix (Nam));
10815 Ename := Selector_Name (Prefix (Nam));
10816 Index := First (Expressions (Nam));
10820 -------------------
10821 -- Family_Offset --
10822 -------------------
10824 function Family_Offset
10829 Cap : Boolean) return Node_Id
10835 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
10836 -- If one of the bounds is a reference to a discriminant, replace with
10837 -- corresponding discriminal of type. Within the body of a task retrieve
10838 -- the renamed discriminant by simple visibility, using its generated
10839 -- name. Within a protected object, find the original discriminant and
10840 -- replace it with the discriminal of the current protected operation.
10842 ------------------------------
10843 -- Convert_Discriminant_Ref --
10844 ------------------------------
10846 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
10847 Loc : constant Source_Ptr := Sloc (Bound);
10852 if Is_Entity_Name (Bound)
10853 and then Ekind (Entity (Bound)) = E_Discriminant
10855 if Is_Task_Type (Ttyp)
10856 and then Has_Completion (Ttyp)
10858 B := Make_Identifier (Loc, Chars (Entity (Bound)));
10859 Find_Direct_Name (B);
10861 elsif Is_Protected_Type (Ttyp) then
10862 D := First_Discriminant (Ttyp);
10863 while Chars (D) /= Chars (Entity (Bound)) loop
10864 Next_Discriminant (D);
10867 B := New_Reference_To (Discriminal (D), Loc);
10870 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
10873 elsif Nkind (Bound) = N_Attribute_Reference then
10877 B := New_Copy_Tree (Bound);
10881 Make_Attribute_Reference (Loc,
10882 Attribute_Name => Name_Pos,
10883 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
10884 Expressions => New_List (B));
10885 end Convert_Discriminant_Ref;
10887 -- Start of processing for Family_Offset
10890 Real_Hi := Convert_Discriminant_Ref (Hi);
10891 Real_Lo := Convert_Discriminant_Ref (Lo);
10894 if Is_Task_Type (Ttyp) then
10895 Ityp := RTE (RE_Task_Entry_Index);
10897 Ityp := RTE (RE_Protected_Entry_Index);
10901 Make_Attribute_Reference (Loc,
10902 Prefix => New_Reference_To (Ityp, Loc),
10903 Attribute_Name => Name_Min,
10904 Expressions => New_List (
10906 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
10909 Make_Attribute_Reference (Loc,
10910 Prefix => New_Reference_To (Ityp, Loc),
10911 Attribute_Name => Name_Max,
10912 Expressions => New_List (
10914 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
10917 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
10924 function Family_Size
10929 Cap : Boolean) return Node_Id
10934 if Is_Task_Type (Ttyp) then
10935 Ityp := RTE (RE_Task_Entry_Index);
10937 Ityp := RTE (RE_Protected_Entry_Index);
10941 Make_Attribute_Reference (Loc,
10942 Prefix => New_Reference_To (Ityp, Loc),
10943 Attribute_Name => Name_Max,
10944 Expressions => New_List (
10947 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
10949 Make_Integer_Literal (Loc, 1)),
10950 Make_Integer_Literal (Loc, 0)));
10953 -----------------------------------
10954 -- Find_Task_Or_Protected_Pragma --
10955 -----------------------------------
10957 function Find_Task_Or_Protected_Pragma
10959 P : Name_Id) return Node_Id
10964 N := First (Visible_Declarations (T));
10965 while Present (N) loop
10966 if Nkind (N) = N_Pragma then
10967 if Pragma_Name (N) = P then
10970 elsif P = Name_Priority
10971 and then Pragma_Name (N) = Name_Interrupt_Priority
10984 N := First (Private_Declarations (T));
10985 while Present (N) loop
10986 if Nkind (N) = N_Pragma then
10987 if Pragma_Name (N) = P then
10990 elsif P = Name_Priority
10991 and then Pragma_Name (N) = Name_Interrupt_Priority
11004 raise Program_Error;
11005 end Find_Task_Or_Protected_Pragma;
11007 -------------------------------
11008 -- First_Protected_Operation --
11009 -------------------------------
11011 function First_Protected_Operation (D : List_Id) return Node_Id is
11012 First_Op : Node_Id;
11015 First_Op := First (D);
11016 while Present (First_Op)
11017 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11023 end First_Protected_Operation;
11025 ---------------------------------------
11026 -- Install_Private_Data_Declarations --
11027 ---------------------------------------
11029 procedure Install_Private_Data_Declarations
11031 Spec_Id : Entity_Id;
11032 Conc_Typ : Entity_Id;
11033 Body_Nod : Node_Id;
11035 Barrier : Boolean := False;
11036 Family : Boolean := False)
11038 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11041 Insert_Node : Node_Id := Empty;
11042 Obj_Ent : Entity_Id;
11044 procedure Add (Decl : Node_Id);
11045 -- Add a single declaration after Insert_Node. If this is the first
11046 -- addition, Decl is added to the front of Decls and it becomes the
11049 function Replace_Bound (Bound : Node_Id) return Node_Id;
11050 -- The bounds of an entry index may depend on discriminants, create a
11051 -- reference to the corresponding prival. Otherwise return a duplicate
11052 -- of the original bound.
11058 procedure Add (Decl : Node_Id) is
11060 if No (Insert_Node) then
11061 Prepend_To (Decls, Decl);
11063 Insert_After (Insert_Node, Decl);
11066 Insert_Node := Decl;
11069 --------------------------
11070 -- Replace_Discriminant --
11071 --------------------------
11073 function Replace_Bound (Bound : Node_Id) return Node_Id is
11075 if Nkind (Bound) = N_Identifier
11076 and then Is_Discriminal (Entity (Bound))
11078 return Make_Identifier (Loc, Chars (Entity (Bound)));
11080 return Duplicate_Subexpr (Bound);
11084 -- Start of processing for Install_Private_Data_Declarations
11087 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11088 -- formal parameter _O, _object or _task depending on the context.
11090 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11092 -- Special processing of _O for barrier functions, protected entries
11099 (Ekind (Spec_Id) = E_Entry
11100 or else Ekind (Spec_Id) = E_Entry_Family))
11103 Conc_Rec : constant Entity_Id :=
11104 Corresponding_Record_Type (Conc_Typ);
11105 Typ_Id : constant Entity_Id :=
11106 Make_Defining_Identifier (Loc,
11107 New_External_Name (Chars (Conc_Rec), 'P'));
11110 -- type prot_typVP is access prot_typV;
11113 Make_Full_Type_Declaration (Loc,
11114 Defining_Identifier => Typ_Id,
11116 Make_Access_To_Object_Definition (Loc,
11117 Subtype_Indication =>
11118 New_Reference_To (Conc_Rec, Loc)));
11122 -- _object : prot_typVP := prot_typV (_O);
11125 Make_Object_Declaration (Loc,
11126 Defining_Identifier =>
11127 Make_Defining_Identifier (Loc, Name_uObject),
11128 Object_Definition => New_Reference_To (Typ_Id, Loc),
11130 Unchecked_Convert_To (Typ_Id,
11131 New_Reference_To (Obj_Ent, Loc)));
11134 -- Set the reference to the concurrent object
11136 Obj_Ent := Defining_Identifier (Decl);
11140 -- Step 2: Create the Protection object and build its declaration for
11141 -- any protected entry (family) of subprogram.
11143 if Is_Protected then
11145 Prot_Ent : constant Entity_Id :=
11146 Make_Defining_Identifier (Loc,
11147 New_Internal_Name ('R'));
11151 Set_Protection_Object (Spec_Id, Prot_Ent);
11153 -- Determine the proper protection type
11155 if Has_Attach_Handler (Conc_Typ)
11156 and then not Restricted_Profile
11158 Prot_Typ := RE_Static_Interrupt_Protection;
11160 elsif Has_Interrupt_Handler (Conc_Typ) then
11161 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11163 -- The type has explicit entries or generated primitive entry
11166 elsif Has_Entries (Conc_Typ)
11168 (Ada_Version >= Ada_05
11169 and then Present (Interface_List (Parent (Conc_Typ))))
11171 case Corresponding_Runtime_Package (Conc_Typ) is
11172 when System_Tasking_Protected_Objects_Entries =>
11173 Prot_Typ := RE_Protection_Entries;
11175 when System_Tasking_Protected_Objects_Single_Entry =>
11176 Prot_Typ := RE_Protection_Entry;
11179 raise Program_Error;
11183 Prot_Typ := RE_Protection;
11187 -- conc_typR : protection_typ renames _object._object;
11190 Make_Object_Renaming_Declaration (Loc,
11191 Defining_Identifier => Prot_Ent,
11193 New_Reference_To (RTE (Prot_Typ), Loc),
11195 Make_Selected_Component (Loc,
11197 New_Reference_To (Obj_Ent, Loc),
11199 Make_Identifier (Loc, Name_uObject)));
11204 -- Step 3: Add discriminant renamings (if any)
11206 if Has_Discriminants (Conc_Typ) then
11211 D := First_Discriminant (Conc_Typ);
11212 while Present (D) loop
11214 -- Adjust the source location
11216 Set_Sloc (Discriminal (D), Loc);
11219 -- discr_name : discr_typ renames _object.discr_name;
11221 -- discr_name : discr_typ renames _task.discr_name;
11224 Make_Object_Renaming_Declaration (Loc,
11225 Defining_Identifier => Discriminal (D),
11226 Subtype_Mark => New_Reference_To (Etype (D), Loc),
11228 Make_Selected_Component (Loc,
11229 Prefix => New_Reference_To (Obj_Ent, Loc),
11230 Selector_Name => Make_Identifier (Loc, Chars (D))));
11233 Next_Discriminant (D);
11238 -- Step 4: Add private component renamings (if any)
11240 if Is_Protected then
11241 Def := Protected_Definition (Parent (Conc_Typ));
11243 if Present (Private_Declarations (Def)) then
11246 Comp_Id : Entity_Id;
11247 Decl_Id : Entity_Id;
11250 Comp := First (Private_Declarations (Def));
11251 while Present (Comp) loop
11252 if Nkind (Comp) = N_Component_Declaration then
11253 Comp_Id := Defining_Identifier (Comp);
11255 Make_Defining_Identifier (Loc, Chars (Comp_Id));
11257 -- Minimal decoration
11259 if Ekind (Spec_Id) = E_Function then
11260 Set_Ekind (Decl_Id, E_Constant);
11262 Set_Ekind (Decl_Id, E_Variable);
11265 Set_Prival (Comp_Id, Decl_Id);
11266 Set_Prival_Link (Decl_Id, Comp_Id);
11267 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
11270 -- comp_name : comp_typ renames _object.comp_name;
11273 Make_Object_Renaming_Declaration (Loc,
11274 Defining_Identifier => Decl_Id,
11276 New_Reference_To (Etype (Comp_Id), Loc),
11278 Make_Selected_Component (Loc,
11280 New_Reference_To (Obj_Ent, Loc),
11282 Make_Identifier (Loc, Chars (Comp_Id))));
11292 -- Step 5: Add the declaration of the entry index and the associated
11293 -- type for barrier functions and entry families.
11295 if (Barrier and then Family)
11296 or else Ekind (Spec_Id) = E_Entry_Family
11299 E : constant Entity_Id := Index_Object (Spec_Id);
11300 Index : constant Entity_Id :=
11301 Defining_Identifier (
11302 Entry_Index_Specification (
11303 Entry_Body_Formal_Part (Body_Nod)));
11304 Index_Con : constant Entity_Id :=
11305 Make_Defining_Identifier (Loc, Chars (Index));
11307 Index_Typ : Entity_Id;
11311 -- Minimal decoration
11313 Set_Ekind (Index_Con, E_Constant);
11314 Set_Entry_Index_Constant (Index, Index_Con);
11315 Set_Discriminal_Link (Index_Con, Index);
11317 -- Retrieve the bounds of the entry family
11319 High := Type_High_Bound (Etype (Index));
11320 Low := Type_Low_Bound (Etype (Index));
11322 -- In the simple case the entry family is given by a subtype
11323 -- mark and the index constant has the same type.
11325 if Is_Entity_Name (Original_Node (
11326 Discrete_Subtype_Definition (Parent (Index))))
11328 Index_Typ := Etype (Index);
11330 -- Otherwise a new subtype declaration is required
11333 High := Replace_Bound (High);
11334 Low := Replace_Bound (Low);
11337 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
11340 -- subtype Jnn is <Etype of Index> range Low .. High;
11343 Make_Subtype_Declaration (Loc,
11344 Defining_Identifier => Index_Typ,
11345 Subtype_Indication =>
11346 Make_Subtype_Indication (Loc,
11348 New_Reference_To (Base_Type (Etype (Index)), Loc),
11350 Make_Range_Constraint (Loc,
11351 Range_Expression =>
11352 Make_Range (Loc, Low, High))));
11356 Set_Etype (Index_Con, Index_Typ);
11358 -- Create the object which designates the index:
11359 -- J : constant Jnn :=
11360 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
11362 -- where Jnn is the subtype created above or the original type of
11363 -- the index, _E is a formal of the protected body subprogram and
11364 -- <index expr> is the index of the first family member.
11367 Make_Object_Declaration (Loc,
11368 Defining_Identifier => Index_Con,
11369 Constant_Present => True,
11370 Object_Definition =>
11371 New_Reference_To (Index_Typ, Loc),
11374 Make_Attribute_Reference (Loc,
11376 New_Reference_To (Index_Typ, Loc),
11377 Attribute_Name => Name_Val,
11379 Expressions => New_List (
11383 Make_Op_Subtract (Loc,
11385 New_Reference_To (E, Loc),
11387 Entry_Index_Expression (Loc,
11388 Defining_Identifier (Body_Nod),
11392 Make_Attribute_Reference (Loc,
11394 New_Reference_To (Index_Typ, Loc),
11395 Attribute_Name => Name_Pos,
11396 Expressions => New_List (
11397 Make_Attribute_Reference (Loc,
11399 New_Reference_To (Index_Typ, Loc),
11400 Attribute_Name => Name_First)))))));
11404 end Install_Private_Data_Declarations;
11406 ---------------------------------
11407 -- Is_Potentially_Large_Family --
11408 ---------------------------------
11410 function Is_Potentially_Large_Family
11411 (Base_Index : Entity_Id;
11412 Conctyp : Entity_Id;
11414 Hi : Node_Id) return Boolean
11417 return Scope (Base_Index) = Standard_Standard
11418 and then Base_Index = Base_Type (Standard_Integer)
11419 and then Has_Discriminants (Conctyp)
11421 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
11423 (Denotes_Discriminant (Lo, True)
11424 or else Denotes_Discriminant (Hi, True));
11425 end Is_Potentially_Large_Family;
11427 -------------------------------------
11428 -- Is_Private_Primitive_Subprogram --
11429 -------------------------------------
11431 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
11434 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
11435 and then Is_Private_Primitive (Id);
11436 end Is_Private_Primitive_Subprogram;
11442 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
11443 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
11444 Formal : Entity_Id;
11447 Formal := First_Formal (Bod_Subp);
11448 while Present (Formal) loop
11450 -- Look for formal parameter _E
11452 if Chars (Formal) = Name_uE then
11456 Next_Formal (Formal);
11459 -- A protected body subprogram should always have the parameter in
11462 raise Program_Error;
11465 --------------------------------
11466 -- Make_Initialize_Protection --
11467 --------------------------------
11469 function Make_Initialize_Protection
11470 (Protect_Rec : Entity_Id) return List_Id
11472 Loc : constant Source_Ptr := Sloc (Protect_Rec);
11476 Ptyp : constant Node_Id :=
11477 Corresponding_Concurrent_Type (Protect_Rec);
11479 L : constant List_Id := New_List;
11480 Has_Entry : constant Boolean := Has_Entries (Ptyp);
11481 Restricted : constant Boolean := Restricted_Profile;
11484 -- We may need two calls to properly initialize the object, one to
11485 -- Initialize_Protection, and possibly one to Install_Handlers if we
11486 -- have a pragma Attach_Handler.
11488 -- Get protected declaration. In the case of a task type declaration,
11489 -- this is simply the parent of the protected type entity. In the single
11490 -- protected object declaration, this parent will be the implicit type,
11491 -- and we can find the corresponding single protected object declaration
11492 -- by searching forward in the declaration list in the tree.
11494 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
11495 -- of this type should have been removed during semantic analysis.
11497 Pdec := Parent (Ptyp);
11498 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
11499 N_Single_Protected_Declaration)
11504 -- Now we can find the object definition from this declaration
11506 Pdef := Protected_Definition (Pdec);
11508 -- Build the parameter list for the call. Note that _Init is the name
11509 -- of the formal for the object to be initialized, which is the task
11510 -- value record itself.
11514 -- Object parameter. This is a pointer to the object of type
11515 -- Protection used by the GNARL to control the protected object.
11518 Make_Attribute_Reference (Loc,
11520 Make_Selected_Component (Loc,
11521 Prefix => Make_Identifier (Loc, Name_uInit),
11522 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11523 Attribute_Name => Name_Unchecked_Access));
11525 -- Priority parameter. Set to Unspecified_Priority unless there is a
11526 -- priority pragma, in which case we take the value from the pragma,
11527 -- or there is an interrupt pragma and no priority pragma, and we
11528 -- set the ceiling to Interrupt_Priority'Last, an implementation-
11529 -- defined value, see D.3(10).
11532 and then Has_Priority_Pragma (Pdef)
11535 Prio : constant Node_Id :=
11538 (Pragma_Argument_Associations
11539 (Find_Task_Or_Protected_Pragma
11540 (Pdef, Name_Priority))));
11544 -- If priority is a static expression, then we can duplicate it
11545 -- with no problem and simply append it to the argument list.
11547 if Is_Static_Expression (Prio) then
11549 Duplicate_Subexpr_No_Checks (Prio));
11551 -- Otherwise, the priority may be a per-object expression, if it
11552 -- depends on a discriminant of the type. In this case, create
11553 -- local variable to capture the expression. Note that it is
11554 -- really necessary to create this variable explicitly. It might
11555 -- be thought that removing side effects would the appropriate
11556 -- approach, but that could generate declarations improperly
11557 -- placed in the enclosing scope.
11559 -- Note: Use System.Any_Priority as the expected type for the
11560 -- non-static priority expression, in case the expression has not
11561 -- been analyzed yet (as occurs for example with pragma
11562 -- Interrupt_Priority).
11566 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
11569 Make_Object_Declaration (Loc,
11570 Defining_Identifier => Temp,
11571 Object_Definition =>
11572 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
11573 Expression => Relocate_Node (Prio)));
11575 Append_To (Args, New_Occurrence_Of (Temp, Loc));
11579 -- When no priority is specified but an xx_Handler pragma is, we default
11580 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
11582 elsif Has_Interrupt_Handler (Ptyp)
11583 or else Has_Attach_Handler (Ptyp)
11586 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
11588 -- Normal case, no priority or xx_Handler specified, default priority
11592 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11595 -- Test for Compiler_Info parameter. This parameter allows entry body
11596 -- procedures and barrier functions to be called from the runtime. It
11597 -- is a pointer to the record generated by the compiler to represent
11598 -- the protected object.
11601 or else Has_Interrupt_Handler (Ptyp)
11602 or else Has_Attach_Handler (Ptyp)
11603 or else Has_Interfaces (Protect_Rec)
11606 Pkg_Id : constant RTU_Id :=
11607 Corresponding_Runtime_Package (Ptyp);
11608 Called_Subp : RE_Id;
11612 when System_Tasking_Protected_Objects_Entries =>
11613 Called_Subp := RE_Initialize_Protection_Entries;
11615 when System_Tasking_Protected_Objects =>
11616 Called_Subp := RE_Initialize_Protection;
11618 when System_Tasking_Protected_Objects_Single_Entry =>
11619 Called_Subp := RE_Initialize_Protection_Entry;
11622 raise Program_Error;
11625 if Has_Entry or else not Restricted then
11627 Make_Attribute_Reference (Loc,
11628 Prefix => Make_Identifier (Loc, Name_uInit),
11629 Attribute_Name => Name_Address));
11632 -- Entry_Bodies parameter. This is a pointer to an array of
11633 -- pointers to the entry body procedures and barrier functions of
11634 -- the object. If the protected type has no entries this object
11635 -- will not exist, in this case, pass a null.
11638 P_Arr := Entry_Bodies_Array (Ptyp);
11641 Make_Attribute_Reference (Loc,
11642 Prefix => New_Reference_To (P_Arr, Loc),
11643 Attribute_Name => Name_Unrestricted_Access));
11645 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
11647 -- Find index mapping function (clumsy but ok for now)
11649 while Ekind (P_Arr) /= E_Function loop
11650 Next_Entity (P_Arr);
11654 Make_Attribute_Reference (Loc,
11656 New_Reference_To (P_Arr, Loc),
11657 Attribute_Name => Name_Unrestricted_Access));
11659 -- Build_Entry_Names generation flag. When set to true, the
11660 -- runtime will allocate an array to hold the string names
11661 -- of protected entries.
11663 if not Restricted_Profile then
11664 if Entry_Names_OK then
11666 New_Reference_To (Standard_True, Loc));
11669 New_Reference_To (Standard_False, Loc));
11674 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
11675 Append_To (Args, Make_Null (Loc));
11677 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
11678 Append_To (Args, Make_Null (Loc));
11679 Append_To (Args, Make_Null (Loc));
11680 Append_To (Args, New_Reference_To (Standard_False, Loc));
11684 Make_Procedure_Call_Statement (Loc,
11685 Name => New_Reference_To (RTE (Called_Subp), Loc),
11686 Parameter_Associations => Args));
11690 Make_Procedure_Call_Statement (Loc,
11691 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
11692 Parameter_Associations => Args));
11695 if Has_Attach_Handler (Ptyp) then
11697 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
11698 -- make the following call:
11700 -- Install_Handlers (_object,
11701 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11703 -- or, in the case of Ravenscar:
11705 -- Install_Restricted_Handlers
11706 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11709 Args : constant List_Id := New_List;
11710 Table : constant List_Id := New_List;
11711 Ritem : Node_Id := First_Rep_Item (Ptyp);
11714 -- Build the Attach_Handler table argument
11716 while Present (Ritem) loop
11717 if Nkind (Ritem) = N_Pragma
11718 and then Pragma_Name (Ritem) = Name_Attach_Handler
11721 Handler : constant Node_Id :=
11722 First (Pragma_Argument_Associations (Ritem));
11724 Interrupt : constant Node_Id := Next (Handler);
11725 Expr : constant Node_Id := Expression (Interrupt);
11729 Make_Aggregate (Loc, Expressions => New_List (
11730 Unchecked_Convert_To
11731 (RTE (RE_System_Interrupt_Id), Expr),
11732 Make_Attribute_Reference (Loc,
11733 Prefix => Make_Selected_Component (Loc,
11734 Make_Identifier (Loc, Name_uInit),
11735 Duplicate_Subexpr_No_Checks
11736 (Expression (Handler))),
11737 Attribute_Name => Name_Access))));
11741 Next_Rep_Item (Ritem);
11744 -- Append the table argument we just built
11746 Append_To (Args, Make_Aggregate (Loc, Table));
11748 -- Append the Install_Handlers (or Install_Restricted_Handlers)
11749 -- call to the statements.
11752 -- Call a simplified version of Install_Handlers to be used
11753 -- when the Ravenscar restrictions are in effect
11754 -- (Install_Restricted_Handlers).
11757 Make_Procedure_Call_Statement (Loc,
11760 (RTE (RE_Install_Restricted_Handlers), Loc),
11761 Parameter_Associations => Args));
11764 -- First, prepends the _object argument
11767 Make_Attribute_Reference (Loc,
11769 Make_Selected_Component (Loc,
11770 Prefix => Make_Identifier (Loc, Name_uInit),
11771 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11772 Attribute_Name => Name_Unchecked_Access));
11774 -- Then, insert call to Install_Handlers
11777 Make_Procedure_Call_Statement (Loc,
11778 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
11779 Parameter_Associations => Args));
11785 end Make_Initialize_Protection;
11787 ---------------------------
11788 -- Make_Task_Create_Call --
11789 ---------------------------
11791 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
11792 Loc : constant Source_Ptr := Sloc (Task_Rec);
11802 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
11803 Tnam := Chars (Ttyp);
11805 -- Get task declaration. In the case of a task type declaration, this is
11806 -- simply the parent of the task type entity. In the single task
11807 -- declaration, this parent will be the implicit type, and we can find
11808 -- the corresponding single task declaration by searching forward in the
11809 -- declaration list in the tree.
11811 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
11812 -- this type should have been removed during semantic analysis.
11814 Tdec := Parent (Ttyp);
11815 while not Nkind_In (Tdec, N_Task_Type_Declaration,
11816 N_Single_Task_Declaration)
11821 -- Now we can find the task definition from this declaration
11823 Tdef := Task_Definition (Tdec);
11825 -- Build the parameter list for the call. Note that _Init is the name
11826 -- of the formal for the object to be initialized, which is the task
11827 -- value record itself.
11831 -- Priority parameter. Set to Unspecified_Priority unless there is a
11832 -- priority pragma, in which case we take the value from the pragma.
11834 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
11836 Make_Selected_Component (Loc,
11837 Prefix => Make_Identifier (Loc, Name_uInit),
11838 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
11841 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11844 -- Optional Stack parameter
11846 if Restricted_Profile then
11848 -- If the stack has been preallocated by the expander then
11849 -- pass its address. Otherwise, pass a null address.
11851 if Preallocated_Stacks_On_Target then
11853 Make_Attribute_Reference (Loc,
11854 Prefix => Make_Selected_Component (Loc,
11855 Prefix => Make_Identifier (Loc, Name_uInit),
11857 Make_Identifier (Loc, Name_uStack)),
11858 Attribute_Name => Name_Address));
11862 New_Reference_To (RTE (RE_Null_Address), Loc));
11866 -- Size parameter. If no Storage_Size pragma is present, then
11867 -- the size is taken from the taskZ variable for the type, which
11868 -- is either Unspecified_Size, or has been reset by the use of
11869 -- a Storage_Size attribute definition clause. If a pragma is
11870 -- present, then the size is taken from the _Size field of the
11871 -- task value record, which was set from the pragma value.
11874 and then Has_Storage_Size_Pragma (Tdef)
11877 Make_Selected_Component (Loc,
11878 Prefix => Make_Identifier (Loc, Name_uInit),
11879 Selector_Name => Make_Identifier (Loc, Name_uSize)));
11883 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
11886 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
11887 -- Task_Info pragma, in which case we take the value from the pragma.
11890 and then Has_Task_Info_Pragma (Tdef)
11893 Make_Selected_Component (Loc,
11894 Prefix => Make_Identifier (Loc, Name_uInit),
11895 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
11899 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
11902 if not Restricted_Profile then
11904 -- Deadline parameter. If no Relative_Deadline pragma is present,
11905 -- then the deadline is Time_Span_Zero. If a pragma is present, then
11906 -- the deadline is taken from the _Relative_Deadline field of the
11907 -- task value record, which was set from the pragma value. Note that
11908 -- this parameter must not be generated for the restricted profiles
11909 -- since Ravenscar does not allow deadlines.
11911 -- Case where pragma Relative_Deadline applies: use given value
11913 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
11915 Make_Selected_Component (Loc,
11916 Prefix => Make_Identifier (Loc, Name_uInit),
11918 Make_Identifier (Loc, Name_uRelative_Deadline)));
11920 -- No pragma Relative_Deadline apply to the task
11924 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
11927 -- Number of entries. This is an expression of the form:
11929 -- n + _Init.a'Length + _Init.a'B'Length + ...
11931 -- where a,b... are the entry family names for the task definition
11934 Build_Entry_Count_Expression
11939 (Parent (Corresponding_Record_Type (Ttyp))))),
11941 Append_To (Args, Ecount);
11943 -- Master parameter. This is a reference to the _Master parameter of
11944 -- the initialization procedure, except in the case of the pragma
11945 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
11946 -- See comments in System.Tasking.Initialization.Init_RTS for the
11949 if Restriction_Active (No_Task_Hierarchy) = False then
11950 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
11952 Append_To (Args, Make_Integer_Literal (Loc, 3));
11956 -- State parameter. This is a pointer to the task body procedure. The
11957 -- required value is obtained by taking 'Unrestricted_Access of the task
11958 -- body procedure and converting it (with an unchecked conversion) to
11959 -- the type required by the task kernel. For further details, see the
11960 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
11961 -- than 'Address in order to avoid creating trampolines.
11964 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
11965 Subp_Ptr_Typ : constant Node_Id :=
11966 Create_Itype (E_Access_Subprogram_Type, Tdec);
11967 Ref : constant Node_Id := Make_Itype_Reference (Loc);
11970 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
11971 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
11973 -- Be sure to freeze a reference to the access-to-subprogram type,
11974 -- otherwise gigi will complain that it's in the wrong scope, because
11975 -- it's actually inside the init procedure for the record type that
11976 -- corresponds to the task type.
11978 -- This processing is causing a crash in the .NET/JVM back ends that
11979 -- is not yet understood, so skip it in these cases ???
11981 if VM_Target = No_VM then
11982 Set_Itype (Ref, Subp_Ptr_Typ);
11983 Append_Freeze_Action (Task_Rec, Ref);
11986 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
11987 Make_Qualified_Expression (Loc,
11988 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
11990 Make_Attribute_Reference (Loc,
11992 New_Occurrence_Of (Body_Proc, Loc),
11993 Attribute_Name => Name_Unrestricted_Access))));
11995 -- For the .NET/JVM cases revert to the original code below ???
11999 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12000 Make_Attribute_Reference (Loc,
12002 New_Occurrence_Of (Body_Proc, Loc),
12003 Attribute_Name => Name_Address)));
12007 -- Discriminants parameter. This is just the address of the task
12008 -- value record itself (which contains the discriminant values
12011 Make_Attribute_Reference (Loc,
12012 Prefix => Make_Identifier (Loc, Name_uInit),
12013 Attribute_Name => Name_Address));
12015 -- Elaborated parameter. This is an access to the elaboration Boolean
12018 Make_Attribute_Reference (Loc,
12019 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12020 Attribute_Name => Name_Unchecked_Access));
12022 -- Chain parameter. This is a reference to the _Chain parameter of
12023 -- the initialization procedure.
12025 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12027 -- Task name parameter. Take this from the _Task_Id parameter to the
12028 -- init call unless there is a Task_Name pragma, in which case we take
12029 -- the value from the pragma.
12032 and then Has_Task_Name_Pragma (Tdef)
12034 -- Copy expression in full, because it may be dynamic and have
12040 (Pragma_Argument_Associations
12041 (Find_Task_Or_Protected_Pragma
12042 (Tdef, Name_Task_Name))))));
12045 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12048 -- Created_Task parameter. This is the _Task_Id field of the task
12052 Make_Selected_Component (Loc,
12053 Prefix => Make_Identifier (Loc, Name_uInit),
12054 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12056 -- Build_Entry_Names generation flag. When set to true, the runtime
12057 -- will allocate an array to hold the string names of task entries.
12059 if not Restricted_Profile then
12060 if Has_Entries (Ttyp)
12061 and then Entry_Names_OK
12063 Append_To (Args, New_Reference_To (Standard_True, Loc));
12065 Append_To (Args, New_Reference_To (Standard_False, Loc));
12069 if Restricted_Profile then
12070 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12072 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12076 Make_Procedure_Call_Statement (Loc,
12078 Parameter_Associations => Args);
12079 end Make_Task_Create_Call;
12081 ------------------------------
12082 -- Next_Protected_Operation --
12083 ------------------------------
12085 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12089 Next_Op := Next (N);
12090 while Present (Next_Op)
12091 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12097 end Next_Protected_Operation;
12099 ---------------------
12100 -- Null_Statements --
12101 ---------------------
12103 function Null_Statements (Stats : List_Id) return Boolean is
12107 Stmt := First (Stats);
12108 while Nkind (Stmt) /= N_Empty
12109 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12111 (Nkind (Stmt) = N_Pragma
12112 and then (Pragma_Name (Stmt) = Name_Unreferenced
12114 Pragma_Name (Stmt) = Name_Unmodified
12116 Pragma_Name (Stmt) = Name_Warnings)))
12121 return Nkind (Stmt) = N_Empty;
12122 end Null_Statements;
12124 --------------------------
12125 -- Parameter_Block_Pack --
12126 --------------------------
12128 function Parameter_Block_Pack
12130 Blk_Typ : Entity_Id;
12134 Stmts : List_Id) return Node_Id
12136 Actual : Entity_Id;
12137 Expr : Node_Id := Empty;
12138 Formal : Entity_Id;
12139 Has_Param : Boolean := False;
12142 Temp_Asn : Node_Id;
12143 Temp_Nam : Node_Id;
12146 Actual := First (Actuals);
12147 Formal := Defining_Identifier (First (Formals));
12148 Params := New_List;
12150 while Present (Actual) loop
12151 if Is_By_Copy_Type (Etype (Actual)) then
12153 -- Jnn : aliased <formal-type>
12156 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
12159 Make_Object_Declaration (Loc,
12162 Defining_Identifier =>
12164 Object_Definition =>
12165 New_Reference_To (Etype (Formal), Loc)));
12167 if Ekind (Formal) /= E_Out_Parameter then
12173 New_Reference_To (Temp_Nam, Loc);
12175 Set_Assignment_OK (Temp_Asn);
12178 Make_Assignment_Statement (Loc,
12182 New_Copy_Tree (Actual)));
12186 -- Jnn'unchecked_access
12189 Make_Attribute_Reference (Loc,
12191 Name_Unchecked_Access,
12193 New_Reference_To (Temp_Nam, Loc)));
12197 -- The controlling parameter is omitted
12200 if not Is_Controlling_Actual (Actual) then
12202 Make_Reference (Loc, New_Copy_Tree (Actual)));
12208 Next_Actual (Actual);
12209 Next_Formal_With_Extras (Formal);
12213 Expr := Make_Aggregate (Loc, Params);
12218 -- J1'unchecked_access;
12219 -- <actual2>'reference;
12222 P := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
12225 Make_Object_Declaration (Loc,
12226 Defining_Identifier =>
12228 Object_Definition =>
12229 New_Reference_To (Blk_Typ, Loc),
12234 end Parameter_Block_Pack;
12236 ----------------------------
12237 -- Parameter_Block_Unpack --
12238 ----------------------------
12240 function Parameter_Block_Unpack
12244 Formals : List_Id) return List_Id
12246 Actual : Entity_Id;
12248 Formal : Entity_Id;
12249 Has_Asnmt : Boolean := False;
12250 Result : constant List_Id := New_List;
12253 Actual := First (Actuals);
12254 Formal := Defining_Identifier (First (Formals));
12255 while Present (Actual) loop
12256 if Is_By_Copy_Type (Etype (Actual))
12257 and then Ekind (Formal) /= E_In_Parameter
12260 -- <actual> := P.<formal>;
12263 Make_Assignment_Statement (Loc,
12267 Make_Explicit_Dereference (Loc,
12268 Make_Selected_Component (Loc,
12270 New_Reference_To (P, Loc),
12272 Make_Identifier (Loc, Chars (Formal)))));
12274 Set_Assignment_OK (Name (Asnmt));
12275 Append_To (Result, Asnmt);
12280 Next_Actual (Actual);
12281 Next_Formal_With_Extras (Formal);
12287 return New_List (Make_Null_Statement (Loc));
12289 end Parameter_Block_Unpack;
12291 ----------------------
12292 -- Set_Discriminals --
12293 ----------------------
12295 procedure Set_Discriminals (Dec : Node_Id) is
12298 D_Minal : Entity_Id;
12301 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
12302 Pdef := Defining_Identifier (Dec);
12304 if Has_Discriminants (Pdef) then
12305 D := First_Discriminant (Pdef);
12306 while Present (D) loop
12308 Make_Defining_Identifier (Sloc (D),
12309 Chars => New_External_Name (Chars (D), 'D'));
12311 Set_Ekind (D_Minal, E_Constant);
12312 Set_Etype (D_Minal, Etype (D));
12313 Set_Scope (D_Minal, Pdef);
12314 Set_Discriminal (D, D_Minal);
12315 Set_Discriminal_Link (D_Minal, D);
12317 Next_Discriminant (D);
12320 end Set_Discriminals;
12322 -----------------------
12323 -- Trivial_Accept_OK --
12324 -----------------------
12326 function Trivial_Accept_OK return Boolean is
12328 case Opt.Task_Dispatching_Policy is
12330 -- If we have the default task dispatching policy in effect, we can
12331 -- definitely do the optimization (one way of looking at this is to
12332 -- think of the formal definition of the default policy being allowed
12333 -- to run any task it likes after a rendezvous, so even if notionally
12334 -- a full rescheduling occurs, we can say that our dispatching policy
12335 -- (i.e. the default dispatching policy) reorders the queue to be the
12336 -- same as just before the call.
12341 -- FIFO_Within_Priorities certainly does not permit this
12342 -- optimization since the Rendezvous is a scheduling action that may
12343 -- require some other task to be run.
12348 -- For now, disallow the optimization for all other policies. This
12349 -- may be over-conservative, but it is certainly not incorrect.
12355 end Trivial_Accept_OK;