1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 Name_Len := Name_Len + 1;
1222 Name_Buffer (Name_Len) := '(';
1225 -- new String'("<Entry name>(" & Lnn'Img & ")");
1227 -- This is an implicit heap allocation, and Comes_From_Source is
1228 -- False, which ensures that it will get flagged as a violation of
1229 -- No_Implicit_Heap_Allocations when that restriction applies.
1232 Make_Allocator (Loc,
1233 Make_Qualified_Expression (Loc,
1235 New_Reference_To (Standard_String, Loc),
1237 Make_Op_Concat (Loc,
1239 Make_Op_Concat (Loc,
1241 Make_String_Literal (Loc,
1242 Strval => String_From_Name_Buffer),
1244 Make_Attribute_Reference (Loc,
1246 New_Reference_To (L_Id, Loc),
1247 Attribute_Name => Name_Img)),
1249 Make_String_Literal (Loc,
1252 Increment_Index (L_Stmts);
1253 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1256 -- for Lnn in Family_Low .. Family_High loop
1259 -- (_init._object <or> _init._task_id, Inn, <Val>);
1263 Make_Loop_Statement (Loc,
1265 Make_Iteration_Scheme (Loc,
1266 Loop_Parameter_Specification =>
1267 Make_Loop_Parameter_Specification (Loc,
1268 Defining_Identifier => L_Id,
1269 Discrete_Subtype_Definition =>
1270 Build_Range (Def))),
1271 Statements => L_Stmts,
1272 End_Label => Empty));
1273 end Build_Entry_Family_Name;
1275 ----------------------
1276 -- Build_Entry_Name --
1277 ----------------------
1279 procedure Build_Entry_Name (Id : Entity_Id) is
1283 Get_Name_String (Chars (Id));
1285 -- This is an implicit heap allocation, and Comes_From_Source is
1286 -- False, which ensures that it will get flagged as a violation of
1287 -- No_Implicit_Heap_Allocations when that restriction applies.
1290 Make_Allocator (Loc,
1291 Make_Qualified_Expression (Loc,
1293 New_Reference_To (Standard_String, Loc),
1295 Make_String_Literal (Loc,
1296 String_From_Name_Buffer)));
1298 Increment_Index (B_Stmts);
1299 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1300 end Build_Entry_Name;
1302 -------------------------------
1303 -- Build_Set_Entry_Name_Call --
1304 -------------------------------
1306 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1311 -- Determine the proper name for the first argument and the RTS
1314 if Is_Protected_Type (Typ) then
1315 Arg1 := Name_uObject;
1316 Proc := RO_PE_Set_Entry_Name;
1318 else pragma Assert (Is_Task_Type (Typ));
1319 Arg1 := Name_uTask_Id;
1320 Proc := RO_TS_Set_Entry_Name;
1324 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1327 Make_Procedure_Call_Statement (Loc,
1329 New_Reference_To (RTE (Proc), Loc),
1330 Parameter_Associations => New_List (
1331 Make_Selected_Component (Loc, -- _init._object
1332 Prefix => -- _init._task_id
1333 Make_Identifier (Loc, Name_uInit),
1335 Make_Identifier (Loc, Arg1)),
1336 New_Reference_To (Index, Loc), -- Inn
1338 end Build_Set_Entry_Name_Call;
1340 --------------------------
1341 -- Find_Protection_Type --
1342 --------------------------
1344 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
1346 Typ : Entity_Id := Conc_Typ;
1349 if Is_Concurrent_Type (Typ) then
1350 Typ := Corresponding_Record_Type (Typ);
1353 Comp := First_Component (Typ);
1354 while Present (Comp) loop
1355 if Chars (Comp) = Name_uObject then
1356 return Base_Type (Etype (Comp));
1359 Next_Component (Comp);
1362 -- The corresponding record of a protected type should always have an
1365 raise Program_Error;
1366 end Find_Protection_Type;
1368 ---------------------
1369 -- Increment_Index --
1370 ---------------------
1372 procedure Increment_Index (Stmts : List_Id) is
1378 Make_Assignment_Statement (Loc,
1380 New_Reference_To (Index, Loc),
1384 New_Reference_To (Index, Loc),
1386 Make_Integer_Literal (Loc, 1))));
1387 end Increment_Index;
1389 -- Start of processing for Build_Entry_Names
1392 -- Retrieve the original concurrent type
1394 if Is_Concurrent_Record_Type (Typ) then
1395 Typ := Corresponding_Concurrent_Type (Typ);
1398 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1400 -- Nothing to do if the type has no entries
1402 if not Has_Entries (Typ) then
1406 -- Avoid generating entry names for a protected type with only one entry
1408 if Is_Protected_Type (Typ)
1409 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1414 Index := Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
1416 -- Step 1: Generate the declaration of the index variable:
1417 -- Inn : Protected_Entry_Index := 0;
1419 -- Inn : Task_Entry_Index := 0;
1421 if Is_Protected_Type (Typ) then
1422 Index_Typ := RE_Protected_Entry_Index;
1424 Index_Typ := RE_Task_Entry_Index;
1427 B_Decls := New_List;
1429 Make_Object_Declaration (Loc,
1430 Defining_Identifier => Index,
1431 Object_Definition =>
1432 New_Reference_To (RTE (Index_Typ), Loc),
1434 Make_Integer_Literal (Loc, 0)));
1436 B_Stmts := New_List;
1438 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1441 Comp := First_Entity (Typ);
1442 while Present (Comp) loop
1443 if Ekind (Comp) = E_Entry then
1444 Build_Entry_Name (Comp);
1446 elsif Ekind (Comp) = E_Entry_Family then
1447 Build_Entry_Family_Name (Comp);
1453 -- Step 3: Wrap the statements in a block
1456 Make_Block_Statement (Loc,
1457 Declarations => B_Decls,
1458 Handled_Statement_Sequence =>
1459 Make_Handled_Sequence_Of_Statements (Loc,
1460 Statements => B_Stmts));
1461 end Build_Entry_Names;
1463 ---------------------------
1464 -- Build_Parameter_Block --
1465 ---------------------------
1467 function Build_Parameter_Block
1471 Decls : List_Id) return Entity_Id
1477 Has_Comp : Boolean := False;
1481 Actual := First (Actuals);
1483 Formal := Defining_Identifier (First (Formals));
1485 while Present (Actual) loop
1486 if not Is_Controlling_Actual (Actual) then
1489 -- type Ann is access all <actual-type>
1492 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
1495 Make_Full_Type_Declaration (Loc,
1496 Defining_Identifier =>
1499 Make_Access_To_Object_Definition (Loc,
1503 Ekind (Formal) = E_In_Parameter,
1504 Subtype_Indication =>
1505 New_Reference_To (Etype (Actual), Loc))));
1511 Make_Component_Declaration (Loc,
1512 Defining_Identifier =>
1513 Make_Defining_Identifier (Loc, Chars (Formal)),
1514 Component_Definition =>
1515 Make_Component_Definition (Loc,
1518 Subtype_Indication =>
1519 New_Reference_To (Comp_Nam, Loc))));
1524 Next_Actual (Actual);
1525 Next_Formal_With_Extras (Formal);
1529 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
1534 -- type Pnn is record
1539 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1540 -- the original parameter names and Ann1 .. AnnN are the access to
1544 Make_Full_Type_Declaration (Loc,
1545 Defining_Identifier =>
1548 Make_Record_Definition (Loc,
1550 Make_Component_List (Loc, Comps))));
1553 -- type Pnn is null record;
1556 Make_Full_Type_Declaration (Loc,
1557 Defining_Identifier =>
1560 Make_Record_Definition (Loc,
1561 Null_Present => True,
1562 Component_List => Empty)));
1566 end Build_Parameter_Block;
1568 --------------------------
1569 -- Build_Wrapper_Bodies --
1570 --------------------------
1572 procedure Build_Wrapper_Bodies
1577 Rec_Typ : Entity_Id;
1579 function Build_Wrapper_Body
1581 Subp_Id : Entity_Id;
1582 Obj_Typ : Entity_Id;
1583 Formals : List_Id) return Node_Id;
1584 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1585 -- associated with a protected or task type. Subp_Id is the subprogram
1586 -- name which will be wrapped. Obj_Typ is the type of the new formal
1587 -- parameter which handles dispatching and object notation. Formals are
1588 -- the original formals of Subp_Id which will be explicitly replicated.
1590 ------------------------
1591 -- Build_Wrapper_Body --
1592 ------------------------
1594 function Build_Wrapper_Body
1596 Subp_Id : Entity_Id;
1597 Obj_Typ : Entity_Id;
1598 Formals : List_Id) return Node_Id
1600 Body_Spec : Node_Id;
1603 Body_Spec := Build_Wrapper_Spec (Loc, Subp_Id, Obj_Typ, Formals);
1605 -- The subprogram is not overriding or is not a primitive declared
1606 -- between two views.
1608 if No (Body_Spec) then
1613 Actuals : List_Id := No_List;
1615 First_Formal : Node_Id;
1620 -- Map formals to actuals. Use the list built for the wrapper
1621 -- spec, skipping the object notation parameter.
1623 First_Formal := First (Parameter_Specifications (Body_Spec));
1625 Formal := First_Formal;
1628 if Present (Formal) then
1629 Actuals := New_List;
1631 while Present (Formal) loop
1633 Make_Identifier (Loc, Chars =>
1634 Chars (Defining_Identifier (Formal))));
1640 -- Special processing for primitives declared between a private
1641 -- type and its completion.
1643 if Is_Private_Primitive_Subprogram (Subp_Id) then
1644 if No (Actuals) then
1645 Actuals := New_List;
1648 Prepend_To (Actuals,
1649 Unchecked_Convert_To (
1650 Corresponding_Concurrent_Type (Obj_Typ),
1651 Make_Identifier (Loc, Name_uO)));
1653 Nam := New_Reference_To (Subp_Id, Loc);
1656 -- An access-to-variable object parameter requires an explicit
1657 -- dereference in the unchecked conversion. This case occurs
1658 -- when a protected entry wrapper must override an interface
1659 -- level procedure with interface access as first parameter.
1661 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1663 if Nkind (Parameter_Type (First_Formal)) =
1667 Make_Explicit_Dereference (Loc,
1668 Prefix => Make_Identifier (Loc, Name_uO));
1670 Conv_Id := Make_Identifier (Loc, Name_uO);
1674 Make_Selected_Component (Loc,
1676 Unchecked_Convert_To (
1677 Corresponding_Concurrent_Type (Obj_Typ),
1680 New_Reference_To (Subp_Id, Loc));
1683 -- Create the subprogram body
1685 if Ekind (Subp_Id) = E_Function then
1687 Make_Subprogram_Body (Loc,
1688 Specification => Body_Spec,
1689 Declarations => Empty_List,
1690 Handled_Statement_Sequence =>
1691 Make_Handled_Sequence_Of_Statements (Loc,
1692 Statements => New_List (
1693 Make_Simple_Return_Statement (Loc,
1694 Make_Function_Call (Loc,
1696 Parameter_Associations => Actuals)))));
1700 Make_Subprogram_Body (Loc,
1701 Specification => Body_Spec,
1702 Declarations => Empty_List,
1703 Handled_Statement_Sequence =>
1704 Make_Handled_Sequence_Of_Statements (Loc,
1705 Statements => New_List (
1706 Make_Procedure_Call_Statement (Loc,
1708 Parameter_Associations => Actuals))));
1711 end Build_Wrapper_Body;
1713 -- Start of processing for Build_Wrapper_Bodies
1716 if Is_Concurrent_Type (Typ) then
1717 Rec_Typ := Corresponding_Record_Type (Typ);
1722 -- Generate wrapper bodies for a concurrent type which implements an
1725 if Present (Interfaces (Rec_Typ)) then
1727 Insert_Nod : Node_Id;
1729 Prim_Elmt : Elmt_Id;
1730 Prim_Decl : Node_Id;
1732 Wrap_Body : Node_Id;
1733 Wrap_Id : Entity_Id;
1738 -- Examine all primitive operations of the corresponding record
1739 -- type, looking for wrapper specs. Generate bodies in order to
1742 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1743 while Present (Prim_Elmt) loop
1744 Prim := Node (Prim_Elmt);
1746 if (Ekind (Prim) = E_Function
1747 or else Ekind (Prim) = E_Procedure)
1748 and then Is_Primitive_Wrapper (Prim)
1750 Subp := Wrapped_Entity (Prim);
1751 Prim_Decl := Parent (Parent (Prim));
1754 Build_Wrapper_Body (Loc,
1757 Formals => Parameter_Specifications (Parent (Subp)));
1758 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
1760 Set_Corresponding_Spec (Wrap_Body, Prim);
1761 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
1763 Insert_After (Insert_Nod, Wrap_Body);
1764 Insert_Nod := Wrap_Body;
1766 Analyze (Wrap_Body);
1769 Next_Elmt (Prim_Elmt);
1773 end Build_Wrapper_Bodies;
1775 ------------------------
1776 -- Build_Wrapper_Spec --
1777 ------------------------
1779 function Build_Wrapper_Spec
1781 Subp_Id : Entity_Id;
1782 Obj_Typ : Entity_Id;
1783 Formals : List_Id) return Node_Id
1785 First_Param : Node_Id;
1787 Iface_Elmt : Elmt_Id;
1788 Iface_Op : Entity_Id;
1789 Iface_Op_Elmt : Elmt_Id;
1791 function Overriding_Possible
1792 (Iface_Op : Entity_Id;
1793 Wrapper : Entity_Id) return Boolean;
1794 -- Determine whether a primitive operation can be overridden by Wrapper.
1795 -- Iface_Op is the candidate primitive operation of an interface type,
1796 -- Wrapper is the generated entry wrapper.
1798 function Replicate_Formals
1800 Formals : List_Id) return List_Id;
1801 -- An explicit parameter replication is required due to the Is_Entry_
1802 -- Formal flag being set for all the formals of an entry. The explicit
1803 -- replication removes the flag that would otherwise cause a different
1804 -- path of analysis.
1806 -------------------------
1807 -- Overriding_Possible --
1808 -------------------------
1810 function Overriding_Possible
1811 (Iface_Op : Entity_Id;
1812 Wrapper : Entity_Id) return Boolean
1814 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
1815 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
1817 function Type_Conformant_Parameters
1818 (Iface_Op_Params : List_Id;
1819 Wrapper_Params : List_Id) return Boolean;
1820 -- Determine whether the parameters of the generated entry wrapper
1821 -- and those of a primitive operation are type conformant. During
1822 -- this check, the first parameter of the primitive operation is
1825 --------------------------------
1826 -- Type_Conformant_Parameters --
1827 --------------------------------
1829 function Type_Conformant_Parameters
1830 (Iface_Op_Params : List_Id;
1831 Wrapper_Params : List_Id) return Boolean
1833 Iface_Op_Param : Node_Id;
1834 Iface_Op_Typ : Entity_Id;
1835 Wrapper_Param : Node_Id;
1836 Wrapper_Typ : Entity_Id;
1839 -- Skip the first parameter of the primitive operation
1841 Iface_Op_Param := Next (First (Iface_Op_Params));
1842 Wrapper_Param := First (Wrapper_Params);
1843 while Present (Iface_Op_Param)
1844 and then Present (Wrapper_Param)
1846 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
1847 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
1849 -- The two parameters must be mode conformant
1851 if not Conforming_Types
1852 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
1857 Next (Iface_Op_Param);
1858 Next (Wrapper_Param);
1861 -- One of the lists is longer than the other
1863 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
1868 end Type_Conformant_Parameters;
1870 -- Start of processing for Overriding_Possible
1873 if Chars (Iface_Op) /= Chars (Wrapper) then
1877 -- If an inherited subprogram is implemented by a protected procedure
1878 -- or an entry, then the first parameter of the inherited subprogram
1879 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
1881 if Ekind (Iface_Op) = E_Procedure
1882 and then Present (Parameter_Specifications (Iface_Op_Spec))
1885 Obj_Param : constant Node_Id :=
1886 First (Parameter_Specifications (Iface_Op_Spec));
1888 if not Out_Present (Obj_Param)
1889 and then Nkind (Parameter_Type (Obj_Param)) /=
1898 Type_Conformant_Parameters (
1899 Parameter_Specifications (Iface_Op_Spec),
1900 Parameter_Specifications (Wrapper_Spec));
1901 end Overriding_Possible;
1903 -----------------------
1904 -- Replicate_Formals --
1905 -----------------------
1907 function Replicate_Formals
1909 Formals : List_Id) return List_Id
1911 New_Formals : constant List_Id := New_List;
1913 Param_Type : Node_Id;
1916 Formal := First (Formals);
1918 -- Skip the object parameter when dealing with primitives declared
1919 -- between two views.
1921 if Is_Private_Primitive_Subprogram (Subp_Id) then
1922 Formal := Next (Formal);
1925 while Present (Formal) loop
1927 -- Create an explicit copy of the entry parameter
1929 -- When creating the wrapper subprogram for a primitive operation
1930 -- of a protected interface we must construct an equivalent
1931 -- signature to that of the overriding operation. For regular
1932 -- parameters we can just use the type of the formal, but for
1933 -- access to subprogram parameters we need to reanalyze the
1934 -- parameter type to create local entities for the signature of
1935 -- the subprogram type. Using the entities of the overriding
1936 -- subprogram will result in out-of-scope errors in the back-end.
1938 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
1939 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
1942 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
1945 Append_To (New_Formals,
1946 Make_Parameter_Specification (Loc,
1947 Defining_Identifier =>
1948 Make_Defining_Identifier (Loc,
1949 Chars => Chars (Defining_Identifier (Formal))),
1950 In_Present => In_Present (Formal),
1951 Out_Present => Out_Present (Formal),
1952 Parameter_Type => Param_Type));
1958 end Replicate_Formals;
1960 -- Start of processing for Build_Wrapper_Spec
1963 -- There is no point in building wrappers for non-tagged concurrent
1966 pragma Assert (Is_Tagged_Type (Obj_Typ));
1968 -- An entry or a protected procedure can override a routine where the
1969 -- controlling formal is either IN OUT, OUT or is of access-to-variable
1970 -- type. Since the wrapper must have the exact same signature as that of
1971 -- the overridden subprogram, we try to find the overriding candidate
1972 -- and use its controlling formal.
1974 First_Param := Empty;
1976 -- Check every implemented interface
1978 if Present (Interfaces (Obj_Typ)) then
1979 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
1980 Search : while Present (Iface_Elmt) loop
1981 Iface := Node (Iface_Elmt);
1983 -- Check every interface primitive
1985 if Present (Primitive_Operations (Iface)) then
1986 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
1987 while Present (Iface_Op_Elmt) loop
1988 Iface_Op := Node (Iface_Op_Elmt);
1990 -- Ignore predefined primitives
1992 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
1993 Iface_Op := Ultimate_Alias (Iface_Op);
1995 -- The current primitive operation can be overridden by
1996 -- the generated entry wrapper.
1998 if Overriding_Possible (Iface_Op, Subp_Id) then
2000 First (Parameter_Specifications (Parent (Iface_Op)));
2006 Next_Elmt (Iface_Op_Elmt);
2010 Next_Elmt (Iface_Elmt);
2014 -- If the subprogram to be wrapped is not overriding anything or is not
2015 -- a primitive declared between two views, do not produce anything. This
2016 -- avoids spurious errors involving overriding.
2019 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2025 Wrapper_Id : constant Entity_Id :=
2026 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2027 New_Formals : List_Id;
2028 Obj_Param : Node_Id;
2029 Obj_Param_Typ : Entity_Id;
2032 -- Minimum decoration is needed to catch the entity in
2033 -- Sem_Ch6.Override_Dispatching_Operation.
2035 if Ekind (Subp_Id) = E_Function then
2036 Set_Ekind (Wrapper_Id, E_Function);
2038 Set_Ekind (Wrapper_Id, E_Procedure);
2041 Set_Is_Primitive_Wrapper (Wrapper_Id);
2042 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2043 Set_Is_Private_Primitive (Wrapper_Id,
2044 Is_Private_Primitive_Subprogram (Subp_Id));
2046 -- Process the formals
2048 New_Formals := Replicate_Formals (Loc, Formals);
2050 -- Routine Subp_Id has been found to override an interface primitive.
2051 -- If the interface operation has an access parameter, create a copy
2052 -- of it, with the same null exclusion indicator if present.
2054 if Present (First_Param) then
2055 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2057 Make_Access_Definition (Loc,
2059 New_Reference_To (Obj_Typ, Loc));
2060 Set_Null_Exclusion_Present (Obj_Param_Typ,
2061 Null_Exclusion_Present (Parameter_Type (First_Param)));
2064 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2068 Make_Parameter_Specification (Loc,
2069 Defining_Identifier =>
2070 Make_Defining_Identifier (Loc,
2072 In_Present => In_Present (First_Param),
2073 Out_Present => Out_Present (First_Param),
2074 Parameter_Type => Obj_Param_Typ);
2076 -- If we are dealing with a primitive declared between two views,
2077 -- create a default parameter.
2079 else pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2081 Make_Parameter_Specification (Loc,
2082 Defining_Identifier =>
2083 Make_Defining_Identifier (Loc, Name_uO),
2085 Out_Present => Ekind (Subp_Id) /= E_Function,
2086 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2089 Prepend_To (New_Formals, Obj_Param);
2091 -- Build the final spec
2093 if Ekind (Subp_Id) = E_Function then
2095 Make_Function_Specification (Loc,
2096 Defining_Unit_Name => Wrapper_Id,
2097 Parameter_Specifications => New_Formals,
2098 Result_Definition =>
2099 New_Copy (Result_Definition (Parent (Subp_Id))));
2102 Make_Procedure_Specification (Loc,
2103 Defining_Unit_Name => Wrapper_Id,
2104 Parameter_Specifications => New_Formals);
2107 end Build_Wrapper_Spec;
2109 -------------------------
2110 -- Build_Wrapper_Specs --
2111 -------------------------
2113 procedure Build_Wrapper_Specs
2119 Rec_Typ : Entity_Id;
2122 if Is_Protected_Type (Typ) then
2123 Def := Protected_Definition (Parent (Typ));
2124 else pragma Assert (Is_Task_Type (Typ));
2125 Def := Task_Definition (Parent (Typ));
2128 Rec_Typ := Corresponding_Record_Type (Typ);
2130 -- Generate wrapper specs for a concurrent type which implements an
2131 -- interface and has visible entries and/or protected procedures.
2133 if Present (Interfaces (Rec_Typ))
2134 and then Present (Def)
2135 and then Present (Visible_Declarations (Def))
2139 Wrap_Decl : Node_Id;
2140 Wrap_Spec : Node_Id;
2143 Decl := First (Visible_Declarations (Def));
2144 while Present (Decl) loop
2147 if Nkind (Decl) = N_Entry_Declaration
2148 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2151 Build_Wrapper_Spec (Loc,
2152 Subp_Id => Defining_Identifier (Decl),
2154 Formals => Parameter_Specifications (Decl));
2156 elsif Nkind (Decl) = N_Subprogram_Declaration then
2158 Build_Wrapper_Spec (Loc,
2159 Subp_Id => Defining_Unit_Name (Specification (Decl)),
2162 Parameter_Specifications (Specification (Decl)));
2165 if Present (Wrap_Spec) then
2167 Make_Subprogram_Declaration (Loc,
2168 Specification => Wrap_Spec);
2170 Insert_After (N, Wrap_Decl);
2173 Analyze (Wrap_Decl);
2180 end Build_Wrapper_Specs;
2182 ---------------------------
2183 -- Build_Find_Body_Index --
2184 ---------------------------
2186 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2187 Loc : constant Source_Ptr := Sloc (Typ);
2190 Has_F : Boolean := False;
2192 If_St : Node_Id := Empty;
2195 Decls : List_Id := New_List;
2198 Siz : Node_Id := Empty;
2200 procedure Add_If_Clause (Expr : Node_Id);
2201 -- Add test for range of current entry
2203 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2204 -- If a bound of an entry is given by a discriminant, retrieve the
2205 -- actual value of the discriminant from the enclosing object.
2211 procedure Add_If_Clause (Expr : Node_Id) is
2213 Stats : constant List_Id :=
2215 Make_Simple_Return_Statement (Loc,
2216 Expression => Make_Integer_Literal (Loc, Index + 1)));
2219 -- Index for current entry body
2223 -- Compute total length of entry queues so far
2231 Right_Opnd => Expr);
2236 Left_Opnd => Make_Identifier (Loc, Name_uE),
2239 -- Map entry queue indices in the range of the current family
2240 -- into the current index, that designates the entry body.
2244 Make_Implicit_If_Statement (Typ,
2246 Then_Statements => Stats,
2247 Elsif_Parts => New_List);
2253 Make_Elsif_Part (Loc,
2255 Then_Statements => Stats),
2256 Elsif_Parts (If_St));
2260 ------------------------------
2261 -- Convert_Discriminant_Ref --
2262 ------------------------------
2264 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2268 if Is_Entity_Name (Bound)
2269 and then Ekind (Entity (Bound)) = E_Discriminant
2272 Make_Selected_Component (Loc,
2274 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2275 Make_Explicit_Dereference (Loc,
2276 Make_Identifier (Loc, Name_uObject))),
2277 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2278 Set_Etype (B, Etype (Entity (Bound)));
2280 B := New_Copy_Tree (Bound);
2284 end Convert_Discriminant_Ref;
2286 -- Start of processing for Build_Find_Body_Index
2289 Spec := Build_Find_Body_Index_Spec (Typ);
2291 Ent := First_Entity (Typ);
2292 while Present (Ent) loop
2293 if Ekind (Ent) = E_Entry_Family then
2303 -- If the protected type has no entry families, there is a one-one
2304 -- correspondence between entry queue and entry body.
2307 Make_Simple_Return_Statement (Loc,
2308 Expression => Make_Identifier (Loc, Name_uE));
2311 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2314 -- if E <= l1 then return 1;
2315 -- elsif E <= l1 + l2 then return 2;
2320 Ent := First_Entity (Typ);
2322 Add_Object_Pointer (Loc, Typ, Decls);
2324 while Present (Ent) loop
2326 if Ekind (Ent) = E_Entry then
2327 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2329 elsif Ekind (Ent) = E_Entry_Family then
2331 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2332 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2333 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2334 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2343 Make_Simple_Return_Statement (Loc,
2344 Expression => Make_Integer_Literal (Loc, 1));
2346 elsif Nkind (Ret) = N_If_Statement then
2348 -- Ranges are in increasing order, so last one doesn't need guard
2351 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2354 Set_Else_Statements (Ret, Then_Statements (Nod));
2360 Make_Subprogram_Body (Loc,
2361 Specification => Spec,
2362 Declarations => Decls,
2363 Handled_Statement_Sequence =>
2364 Make_Handled_Sequence_Of_Statements (Loc,
2365 Statements => New_List (Ret)));
2366 end Build_Find_Body_Index;
2368 --------------------------------
2369 -- Build_Find_Body_Index_Spec --
2370 --------------------------------
2372 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2373 Loc : constant Source_Ptr := Sloc (Typ);
2374 Id : constant Entity_Id :=
2375 Make_Defining_Identifier (Loc,
2376 Chars => New_External_Name (Chars (Typ), 'F'));
2377 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2378 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2382 Make_Function_Specification (Loc,
2383 Defining_Unit_Name => Id,
2384 Parameter_Specifications => New_List (
2385 Make_Parameter_Specification (Loc,
2386 Defining_Identifier => Parm1,
2388 New_Reference_To (RTE (RE_Address), Loc)),
2390 Make_Parameter_Specification (Loc,
2391 Defining_Identifier => Parm2,
2393 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2394 Result_Definition => New_Occurrence_Of (
2395 RTE (RE_Protected_Entry_Index), Loc));
2396 end Build_Find_Body_Index_Spec;
2398 -------------------------
2399 -- Build_Master_Entity --
2400 -------------------------
2402 procedure Build_Master_Entity (E : Entity_Id) is
2403 Loc : constant Source_Ptr := Sloc (E);
2411 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2412 -- in internal scopes, unless present already.. Required for nested
2413 -- limited aggregates, where the expansion of task components may
2414 -- generate inner blocks. If the block is the rewriting of a call
2415 -- or the scope is an extended return statement this is valid master.
2416 -- The master in an extended return is only used within the return,
2417 -- and is subsequently overwritten in Move_Activation_Chain, but it
2420 if Ada_Version >= Ada_05 then
2421 while Is_Internal (S) loop
2422 if Nkind (Parent (S)) = N_Block_Statement
2424 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
2427 elsif Ekind (S) = E_Return_Statement then
2435 -- Nothing to do if we already built a master entity for this scope
2436 -- or if there is no task hierarchy.
2438 if Has_Master_Entity (S)
2439 or else Restriction_Active (No_Task_Hierarchy)
2444 -- Otherwise first build the master entity
2445 -- _Master : constant Master_Id := Current_Master.all;
2446 -- and insert it just before the current declaration
2449 Make_Object_Declaration (Loc,
2450 Defining_Identifier =>
2451 Make_Defining_Identifier (Loc, Name_uMaster),
2452 Constant_Present => True,
2453 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2455 Make_Explicit_Dereference (Loc,
2456 New_Reference_To (RTE (RE_Current_Master), Loc)));
2459 Insert_Before (P, Decl);
2462 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2463 -- non-internal scope selected above.
2465 if Ada_Version >= Ada_05 then
2466 Set_Has_Master_Entity (S);
2468 Set_Has_Master_Entity (Scope (E));
2471 -- Now mark the containing scope as a task master
2473 while Nkind (P) /= N_Compilation_Unit loop
2476 -- If we fall off the top, we are at the outer level, and the
2477 -- environment task is our effective master, so nothing to mark.
2480 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2482 Set_Is_Task_Master (P, True);
2485 elsif Nkind (Parent (P)) = N_Subunit then
2486 P := Corresponding_Stub (Parent (P));
2489 end Build_Master_Entity;
2491 ---------------------------
2492 -- Build_Protected_Entry --
2493 ---------------------------
2495 function Build_Protected_Entry
2498 Pid : Node_Id) return Node_Id
2500 Loc : constant Source_Ptr := Sloc (N);
2502 Decls : constant List_Id := Declarations (N);
2503 End_Lab : constant Node_Id :=
2504 End_Label (Handled_Statement_Sequence (N));
2505 End_Loc : constant Source_Ptr :=
2506 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2507 -- Used for the generated call to Complete_Entry_Body
2509 Han_Loc : Source_Ptr;
2510 -- Used for the exception handler, inserted at end of the body
2512 Op_Decls : constant List_Id := New_List;
2520 -- Set the source location on the exception handler only when debugging
2521 -- the expanded code (see Make_Implicit_Exception_Handler).
2523 if Debug_Generated_Code then
2526 -- Otherwise the inserted code should not be visible to the debugger
2529 Han_Loc := No_Location;
2533 Make_Defining_Identifier (Loc,
2534 Chars => Chars (Protected_Body_Subprogram (Ent)));
2536 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2538 -- Add the following declarations:
2539 -- type poVP is access poV;
2540 -- _object : poVP := poVP (_O);
2542 -- where _O is the formal parameter associated with the concurrent
2543 -- object. These declarations are needed for Complete_Entry_Body.
2545 Add_Object_Pointer (Loc, Pid, Op_Decls);
2547 -- Add renamings for all formals, the Protection object, discriminals,
2548 -- privals and the entry index constant for use by debugger.
2550 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2551 Debug_Private_Data_Declarations (Decls);
2553 case Corresponding_Runtime_Package (Pid) is
2554 when System_Tasking_Protected_Objects_Entries =>
2556 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2558 when System_Tasking_Protected_Objects_Single_Entry =>
2560 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2563 raise Program_Error;
2566 Op_Stats := New_List (
2567 Make_Block_Statement (Loc,
2568 Declarations => Decls,
2569 Handled_Statement_Sequence =>
2570 Handled_Statement_Sequence (N)),
2572 Make_Procedure_Call_Statement (End_Loc,
2574 Parameter_Associations => New_List (
2575 Make_Attribute_Reference (End_Loc,
2577 Make_Selected_Component (End_Loc,
2579 Make_Identifier (End_Loc, Name_uObject),
2581 Make_Identifier (End_Loc, Name_uObject)),
2582 Attribute_Name => Name_Unchecked_Access))));
2584 -- When exceptions can not be propagated, we never need to call
2585 -- Exception_Complete_Entry_Body
2587 if No_Exception_Handlers_Set then
2589 Make_Subprogram_Body (Loc,
2590 Specification => Espec,
2591 Declarations => Op_Decls,
2592 Handled_Statement_Sequence =>
2593 Make_Handled_Sequence_Of_Statements (Loc,
2594 Statements => Op_Stats,
2595 End_Label => End_Lab));
2598 Ohandle := Make_Others_Choice (Loc);
2599 Set_All_Others (Ohandle);
2601 case Corresponding_Runtime_Package (Pid) is
2602 when System_Tasking_Protected_Objects_Entries =>
2605 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2607 when System_Tasking_Protected_Objects_Single_Entry =>
2610 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2613 raise Program_Error;
2616 -- Create body of entry procedure. The renaming declarations are
2617 -- placed ahead of the block that contains the actual entry body.
2620 Make_Subprogram_Body (Loc,
2621 Specification => Espec,
2622 Declarations => Op_Decls,
2623 Handled_Statement_Sequence =>
2624 Make_Handled_Sequence_Of_Statements (Loc,
2625 Statements => Op_Stats,
2626 End_Label => End_Lab,
2627 Exception_Handlers => New_List (
2628 Make_Implicit_Exception_Handler (Han_Loc,
2629 Exception_Choices => New_List (Ohandle),
2631 Statements => New_List (
2632 Make_Procedure_Call_Statement (Han_Loc,
2634 Parameter_Associations => New_List (
2635 Make_Attribute_Reference (Han_Loc,
2637 Make_Selected_Component (Han_Loc,
2639 Make_Identifier (Han_Loc, Name_uObject),
2641 Make_Identifier (Han_Loc, Name_uObject)),
2642 Attribute_Name => Name_Unchecked_Access),
2644 Make_Function_Call (Han_Loc,
2645 Name => New_Reference_To (
2646 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2648 end Build_Protected_Entry;
2650 -----------------------------------------
2651 -- Build_Protected_Entry_Specification --
2652 -----------------------------------------
2654 function Build_Protected_Entry_Specification
2657 Ent_Id : Entity_Id) return Node_Id
2659 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2662 Set_Debug_Info_Needed (Def_Id);
2664 if Present (Ent_Id) then
2665 Append_Elmt (P, Accept_Address (Ent_Id));
2669 Make_Procedure_Specification (Loc,
2670 Defining_Unit_Name => Def_Id,
2671 Parameter_Specifications => New_List (
2672 Make_Parameter_Specification (Loc,
2673 Defining_Identifier =>
2674 Make_Defining_Identifier (Loc, Name_uO),
2676 New_Reference_To (RTE (RE_Address), Loc)),
2678 Make_Parameter_Specification (Loc,
2679 Defining_Identifier => P,
2681 New_Reference_To (RTE (RE_Address), Loc)),
2683 Make_Parameter_Specification (Loc,
2684 Defining_Identifier =>
2685 Make_Defining_Identifier (Loc, Name_uE),
2687 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2688 end Build_Protected_Entry_Specification;
2690 --------------------------
2691 -- Build_Protected_Spec --
2692 --------------------------
2694 function Build_Protected_Spec
2696 Obj_Type : Entity_Id;
2698 Unprotected : Boolean := False) return List_Id
2700 Loc : constant Source_Ptr := Sloc (N);
2703 New_Plist : List_Id;
2704 New_Param : Node_Id;
2707 New_Plist := New_List;
2709 Formal := First_Formal (Ident);
2710 while Present (Formal) loop
2712 Make_Parameter_Specification (Loc,
2713 Defining_Identifier =>
2714 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2715 In_Present => In_Present (Parent (Formal)),
2716 Out_Present => Out_Present (Parent (Formal)),
2717 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
2720 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2723 Append (New_Param, New_Plist);
2724 Next_Formal (Formal);
2727 -- If the subprogram is a procedure and the context is not an access
2728 -- to protected subprogram, the parameter is in-out. Otherwise it is
2732 Make_Parameter_Specification (Loc,
2733 Defining_Identifier =>
2734 Make_Defining_Identifier (Loc, Name_uObject),
2737 (Etype (Ident) = Standard_Void_Type
2738 and then not Is_RTE (Obj_Type, RE_Address)),
2740 New_Reference_To (Obj_Type, Loc));
2741 Set_Debug_Info_Needed (Defining_Identifier (Decl));
2742 Prepend_To (New_Plist, Decl);
2745 end Build_Protected_Spec;
2747 ---------------------------------------
2748 -- Build_Protected_Sub_Specification --
2749 ---------------------------------------
2751 function Build_Protected_Sub_Specification
2753 Prot_Typ : Entity_Id;
2754 Mode : Subprogram_Protection_Mode) return Node_Id
2756 Loc : constant Source_Ptr := Sloc (N);
2760 New_Plist : List_Id;
2763 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2764 (Dispatching_Mode => ' ',
2765 Protected_Mode => 'P',
2766 Unprotected_Mode => 'N');
2769 if Ekind (Defining_Unit_Name (Specification (N))) =
2772 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2777 Def_Id := Defining_Unit_Name (Specification (Decl));
2780 Build_Protected_Spec
2781 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
2782 Mode = Unprotected_Mode);
2784 Make_Defining_Identifier (Loc,
2785 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
2787 -- The unprotected operation carries the user code, and debugging
2788 -- information must be generated for it, even though this spec does
2789 -- not come from source. It is also convenient to allow gdb to step
2790 -- into the protected operation, even though it only contains lock/
2793 Set_Debug_Info_Needed (New_Id);
2795 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2797 Make_Procedure_Specification (Loc,
2798 Defining_Unit_Name => New_Id,
2799 Parameter_Specifications => New_Plist);
2801 -- Create a new specification for the anonymous subprogram type
2805 Make_Function_Specification (Loc,
2806 Defining_Unit_Name => New_Id,
2807 Parameter_Specifications => New_Plist,
2808 Result_Definition =>
2809 Copy_Result_Type (Result_Definition (Specification (Decl))));
2811 Set_Return_Present (Defining_Unit_Name (New_Spec));
2815 end Build_Protected_Sub_Specification;
2817 -------------------------------------
2818 -- Build_Protected_Subprogram_Body --
2819 -------------------------------------
2821 function Build_Protected_Subprogram_Body
2824 N_Op_Spec : Node_Id) return Node_Id
2826 Loc : constant Source_Ptr := Sloc (N);
2828 P_Op_Spec : Node_Id;
2831 Unprot_Call : Node_Id;
2833 Lock_Name : Node_Id;
2834 Lock_Stmt : Node_Id;
2835 Service_Name : Node_Id;
2837 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2838 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2840 Object_Parm : Node_Id;
2843 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2844 -- Tell whether a given subprogram cannot raise an exception
2846 -----------------------
2847 -- Is_Exception_Safe --
2848 -----------------------
2850 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2852 function Has_Side_Effect (N : Node_Id) return Boolean;
2853 -- Return True whenever encountering a subprogram call or raise
2854 -- statement of any kind in the sequence of statements
2856 ---------------------
2857 -- Has_Side_Effect --
2858 ---------------------
2860 -- What is this doing buried two levels down in exp_ch9. It seems
2861 -- like a generally useful function, and indeed there may be code
2862 -- duplication going on here ???
2864 function Has_Side_Effect (N : Node_Id) return Boolean is
2868 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
2869 -- Indicate whether N is a subprogram call or a raise statement
2871 ----------------------
2872 -- Is_Call_Or_Raise --
2873 ----------------------
2875 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
2877 return Nkind_In (N, N_Procedure_Call_Statement,
2880 N_Raise_Constraint_Error,
2881 N_Raise_Program_Error,
2882 N_Raise_Storage_Error);
2883 end Is_Call_Or_Raise;
2885 -- Start of processing for Has_Side_Effect
2889 while Present (Stmt) loop
2890 if Is_Call_Or_Raise (Stmt) then
2894 -- An object declaration can also contain a function call
2895 -- or a raise statement
2897 if Nkind (Stmt) = N_Object_Declaration then
2898 Expr := Expression (Stmt);
2900 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
2909 end Has_Side_Effect;
2911 -- Start of processing for Is_Exception_Safe
2914 -- If the checks handled by the back end are not disabled, we cannot
2915 -- ensure that no exception will be raised.
2917 if not Access_Checks_Suppressed (Empty)
2918 or else not Discriminant_Checks_Suppressed (Empty)
2919 or else not Range_Checks_Suppressed (Empty)
2920 or else not Index_Checks_Suppressed (Empty)
2921 or else Opt.Stack_Checking_Enabled
2926 if Has_Side_Effect (First (Declarations (Subprogram)))
2929 First (Statements (Handled_Statement_Sequence (Subprogram))))
2935 end Is_Exception_Safe;
2937 -- Start of processing for Build_Protected_Subprogram_Body
2940 Op_Spec := Specification (N);
2941 Exc_Safe := Is_Exception_Safe (N);
2944 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
2946 -- Build a list of the formal parameters of the protected version of
2947 -- the subprogram to use as the actual parameters of the unprotected
2950 Uactuals := New_List;
2951 Pformal := First (Parameter_Specifications (P_Op_Spec));
2952 while Present (Pformal) loop
2954 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
2959 -- Make a call to the unprotected version of the subprogram built above
2960 -- for use by the protected version built below.
2962 if Nkind (Op_Spec) = N_Function_Specification then
2964 R := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2966 Make_Object_Declaration (Loc,
2967 Defining_Identifier => R,
2968 Constant_Present => True,
2969 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
2971 Make_Function_Call (Loc,
2972 Name => Make_Identifier (Loc,
2973 Chars (Defining_Unit_Name (N_Op_Spec))),
2974 Parameter_Associations => Uactuals));
2975 Return_Stmt := Make_Simple_Return_Statement (Loc,
2976 Expression => New_Reference_To (R, Loc));
2979 Unprot_Call := Make_Simple_Return_Statement (Loc,
2980 Expression => Make_Function_Call (Loc,
2982 Make_Identifier (Loc,
2983 Chars (Defining_Unit_Name (N_Op_Spec))),
2984 Parameter_Associations => Uactuals));
2989 Make_Procedure_Call_Statement (Loc,
2991 Make_Identifier (Loc,
2992 Chars (Defining_Unit_Name (N_Op_Spec))),
2993 Parameter_Associations => Uactuals);
2996 -- Wrap call in block that will be covered by an at_end handler
2998 if not Exc_Safe then
2999 Unprot_Call := Make_Block_Statement (Loc,
3000 Handled_Statement_Sequence =>
3001 Make_Handled_Sequence_Of_Statements (Loc,
3002 Statements => New_List (Unprot_Call)));
3005 -- Make the protected subprogram body. This locks the protected
3006 -- object and calls the unprotected version of the subprogram.
3008 case Corresponding_Runtime_Package (Pid) is
3009 when System_Tasking_Protected_Objects_Entries =>
3010 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3011 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3013 when System_Tasking_Protected_Objects_Single_Entry =>
3014 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3015 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3017 when System_Tasking_Protected_Objects =>
3018 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3019 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3022 raise Program_Error;
3026 Make_Attribute_Reference (Loc,
3028 Make_Selected_Component (Loc,
3030 Make_Identifier (Loc, Name_uObject),
3032 Make_Identifier (Loc, Name_uObject)),
3033 Attribute_Name => Name_Unchecked_Access);
3035 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3037 Parameter_Associations => New_List (Object_Parm));
3039 if Abort_Allowed then
3041 Make_Procedure_Call_Statement (Loc,
3042 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3043 Parameter_Associations => Empty_List),
3047 Stmts := New_List (Lock_Stmt);
3050 if not Exc_Safe then
3051 Append (Unprot_Call, Stmts);
3053 if Nkind (Op_Spec) = N_Function_Specification then
3055 Stmts := Empty_List;
3057 Append (Unprot_Call, Stmts);
3061 Make_Procedure_Call_Statement (Loc,
3062 Name => Service_Name,
3063 Parameter_Associations =>
3064 New_List (New_Copy_Tree (Object_Parm))),
3067 if Abort_Allowed then
3069 Make_Procedure_Call_Statement (Loc,
3070 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3071 Parameter_Associations => Empty_List),
3075 if Nkind (Op_Spec) = N_Function_Specification then
3076 Append (Return_Stmt, Stmts);
3077 Append (Make_Block_Statement (Loc,
3078 Declarations => New_List (Unprot_Call),
3079 Handled_Statement_Sequence =>
3080 Make_Handled_Sequence_Of_Statements (Loc,
3081 Statements => Stmts)), Pre_Stmts);
3087 Make_Subprogram_Body (Loc,
3088 Declarations => Empty_List,
3089 Specification => P_Op_Spec,
3090 Handled_Statement_Sequence =>
3091 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3093 if not Exc_Safe then
3094 Set_Is_Protected_Subprogram_Body (Sub_Body);
3098 end Build_Protected_Subprogram_Body;
3100 -------------------------------------
3101 -- Build_Protected_Subprogram_Call --
3102 -------------------------------------
3104 procedure Build_Protected_Subprogram_Call
3108 External : Boolean := True)
3110 Loc : constant Source_Ptr := Sloc (N);
3111 Sub : constant Entity_Id := Entity (Name);
3117 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3120 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3123 if Present (Parameter_Associations (N)) then
3124 Params := New_Copy_List_Tree (Parameter_Associations (N));
3129 Prepend (Rec, Params);
3131 if Ekind (Sub) = E_Procedure then
3133 Make_Procedure_Call_Statement (Loc,
3135 Parameter_Associations => Params));
3138 pragma Assert (Ekind (Sub) = E_Function);
3140 Make_Function_Call (Loc,
3142 Parameter_Associations => Params));
3146 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3147 and then Is_Entity_Name (Expression (Rec))
3148 and then Is_Shared_Passive (Entity (Expression (Rec)))
3150 Add_Shared_Var_Lock_Procs (N);
3152 end Build_Protected_Subprogram_Call;
3154 -------------------------
3155 -- Build_Selected_Name --
3156 -------------------------
3158 function Build_Selected_Name
3159 (Prefix : Entity_Id;
3160 Selector : Entity_Id;
3161 Append_Char : Character := ' ') return Name_Id
3163 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3164 Select_Len : Natural;
3167 Get_Name_String (Chars (Selector));
3168 Select_Len := Name_Len;
3169 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3170 Get_Name_String (Chars (Prefix));
3172 -- If scope is anonymous type, discard suffix to recover name of
3173 -- single protected object. Otherwise use protected type name.
3175 if Name_Buffer (Name_Len) = 'T' then
3176 Name_Len := Name_Len - 1;
3179 Name_Buffer (Name_Len + 1) := '_';
3180 Name_Buffer (Name_Len + 2) := '_';
3182 Name_Len := Name_Len + 2;
3183 for J in 1 .. Select_Len loop
3184 Name_Len := Name_Len + 1;
3185 Name_Buffer (Name_Len) := 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 Name_Len := Name_Len + 1;
3199 Name_Buffer (Name_Len) := Append_Char;
3202 Name_Buffer (Name_Len + 1) := '_';
3203 Name_Buffer (Name_Len + 2) := Append_Char;
3204 Name_Len := Name_Len + 2;
3205 return New_External_Name (Name_Find, ' ', -1);
3210 end Build_Selected_Name;
3212 -----------------------------
3213 -- Build_Simple_Entry_Call --
3214 -----------------------------
3216 -- A task entry call is converted to a call to Call_Simple
3219 -- P : parms := (parm, parm, parm);
3221 -- Call_Simple (acceptor-task, entry-index, P'Address);
3227 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3228 -- the parameters, and the constructed aggregate value contains either the
3229 -- parameters or, in the case of non-elementary types, references to these
3230 -- parameters. Then the address of this aggregate is passed to the runtime
3231 -- routine, along with the task id value and the task entry index value.
3232 -- Pnn is only required if parameters are present.
3234 -- The assignments after the call are present only in the case of in-out
3235 -- or out parameters for elementary types, and are used to assign back the
3236 -- resulting values of such parameters.
3238 -- Note: the reason that we insert a block here is that in the context
3239 -- of selects, conditional entry calls etc. the entry call statement
3240 -- appears on its own, not as an element of a list.
3242 -- A protected entry call is converted to a Protected_Entry_Call:
3245 -- P : E1_Params := (param, param, param);
3247 -- Bnn : Communications_Block;
3250 -- P : E1_Params := (param, param, param);
3251 -- Bnn : Communications_Block;
3254 -- Protected_Entry_Call (
3255 -- Object => po._object'Access,
3256 -- E => <entry index>;
3257 -- Uninterpreted_Data => P'Address;
3258 -- Mode => Simple_Call;
3265 procedure Build_Simple_Entry_Call
3274 -- If call has been inlined, nothing left to do
3276 if Nkind (N) = N_Block_Statement then
3280 -- Convert entry call to Call_Simple call
3283 Loc : constant Source_Ptr := Sloc (N);
3284 Parms : constant List_Id := Parameter_Associations (N);
3285 Stats : constant List_Id := New_List;
3288 Comm_Name : Entity_Id;
3292 Ent_Acc : Entity_Id;
3294 Iface_Tag : Entity_Id;
3295 Iface_Typ : Entity_Id;
3308 -- Simple entry and entry family cases merge here
3310 Ent := Entity (Ename);
3311 Ent_Acc := Entry_Parameters_Type (Ent);
3312 Conctyp := Etype (Concval);
3314 -- If prefix is an access type, dereference to obtain the task type
3316 if Is_Access_Type (Conctyp) then
3317 Conctyp := Designated_Type (Conctyp);
3320 -- Special case for protected subprogram calls
3322 if Is_Protected_Type (Conctyp)
3323 and then Is_Subprogram (Entity (Ename))
3325 if not Is_Eliminated (Entity (Ename)) then
3326 Build_Protected_Subprogram_Call
3327 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3334 -- First parameter is the Task_Id value from the task value or the
3335 -- Object from the protected object value, obtained by selecting
3336 -- the _Task_Id or _Object from the result of doing an unchecked
3337 -- conversion to convert the value to the corresponding record type.
3339 if Nkind (Concval) = N_Function_Call
3340 and then Is_Task_Type (Conctyp)
3341 and then Ada_Version >= Ada_05
3344 Obj : constant Entity_Id :=
3345 Make_Defining_Identifier (Loc, New_Internal_Name ('F'));
3350 Make_Object_Declaration (Loc,
3351 Defining_Identifier => Obj,
3352 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3353 Expression => Relocate_Node (Concval));
3354 Set_Etype (Obj, Conctyp);
3355 Decls := New_List (Decl);
3356 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3363 Parm1 := Concurrent_Ref (Concval);
3365 -- Second parameter is the entry index, computed by the routine
3366 -- provided for this purpose. The value of this expression is
3367 -- assigned to an intermediate variable to assure that any entry
3368 -- family index expressions are evaluated before the entry
3372 or else Restriction_Active (No_Entry_Queue) = False
3373 or else not Is_Protected_Type (Conctyp)
3374 or else Number_Entries (Conctyp) > 1
3375 or else (Has_Attach_Handler (Conctyp)
3376 and then not Restricted_Profile)
3378 X := Make_Defining_Identifier (Loc, Name_uX);
3381 Make_Object_Declaration (Loc,
3382 Defining_Identifier => X,
3383 Object_Definition =>
3384 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3385 Expression => Actual_Index_Expression (
3386 Loc, Entity (Ename), Index, Concval));
3388 Append_To (Decls, Xdecl);
3389 Parm2 := New_Reference_To (X, Loc);
3396 -- The third parameter is the packaged parameters. If there are
3397 -- none, then it is just the null address, since nothing is passed.
3400 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3403 -- Case of parameters present, where third argument is the address
3404 -- of a packaged record containing the required parameter values.
3407 -- First build a list of parameter values, which are references to
3408 -- objects of the parameter types.
3412 Actual := First_Actual (N);
3413 Formal := First_Formal (Ent);
3415 while Present (Actual) loop
3417 -- If it is a by_copy_type, copy it to a new variable. The
3418 -- packaged record has a field that points to this variable.
3420 if Is_By_Copy_Type (Etype (Actual)) then
3422 Make_Object_Declaration (Loc,
3423 Defining_Identifier =>
3424 Make_Defining_Identifier (Loc,
3425 Chars => New_Internal_Name ('J')),
3426 Aliased_Present => True,
3427 Object_Definition =>
3428 New_Reference_To (Etype (Formal), Loc));
3430 -- Mark the object as not needing initialization since the
3431 -- initialization is performed separately, avoiding errors
3432 -- on cases such as formals of null-excluding access types.
3434 Set_No_Initialization (N_Node);
3436 -- We must make an assignment statement separate for the
3437 -- case of limited type. We cannot assign it unless the
3438 -- Assignment_OK flag is set first. An out formal of an
3439 -- access type must also be initialized from the actual,
3440 -- as stated in RM 6.4.1 (13).
3442 if Ekind (Formal) /= E_Out_Parameter
3443 or else Is_Access_Type (Etype (Formal))
3446 New_Reference_To (Defining_Identifier (N_Node), Loc);
3447 Set_Assignment_OK (N_Var);
3449 Make_Assignment_Statement (Loc,
3451 Expression => Relocate_Node (Actual)));
3454 Append (N_Node, Decls);
3457 Make_Attribute_Reference (Loc,
3458 Attribute_Name => Name_Unchecked_Access,
3460 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3462 -- Interface class-wide formal
3464 if Ada_Version >= Ada_05
3465 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3466 and then Is_Interface (Etype (Formal))
3468 Iface_Typ := Etype (Etype (Formal));
3471 -- formal_iface_type! (actual.iface_tag)'reference
3474 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3475 pragma Assert (Present (Iface_Tag));
3478 Make_Reference (Loc,
3479 Unchecked_Convert_To (Iface_Typ,
3480 Make_Selected_Component (Loc,
3482 Relocate_Node (Actual),
3484 New_Reference_To (Iface_Tag, Loc)))));
3490 Make_Reference (Loc, Relocate_Node (Actual)));
3494 Next_Actual (Actual);
3495 Next_Formal_With_Extras (Formal);
3498 -- Now build the declaration of parameters initialized with the
3499 -- aggregate containing this constructed parameter list.
3501 P := Make_Defining_Identifier (Loc, Name_uP);
3504 Make_Object_Declaration (Loc,
3505 Defining_Identifier => P,
3506 Object_Definition =>
3507 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3509 Make_Aggregate (Loc, Expressions => Plist));
3512 Make_Attribute_Reference (Loc,
3513 Prefix => New_Reference_To (P, Loc),
3514 Attribute_Name => Name_Address);
3516 Append (Pdecl, Decls);
3519 -- Now we can create the call, case of protected type
3521 if Is_Protected_Type (Conctyp) then
3522 case Corresponding_Runtime_Package (Conctyp) is
3523 when System_Tasking_Protected_Objects_Entries =>
3525 -- Change the type of the index declaration
3527 Set_Object_Definition (Xdecl,
3528 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3530 -- Some additional declarations for protected entry calls
3536 -- Bnn : Communications_Block;
3539 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3542 Make_Object_Declaration (Loc,
3543 Defining_Identifier => Comm_Name,
3544 Object_Definition =>
3545 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3547 -- Some additional statements for protected entry calls
3549 -- Protected_Entry_Call (
3550 -- Object => po._object'Access,
3551 -- E => <entry index>;
3552 -- Uninterpreted_Data => P'Address;
3553 -- Mode => Simple_Call;
3557 Make_Procedure_Call_Statement (Loc,
3559 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3561 Parameter_Associations => New_List (
3562 Make_Attribute_Reference (Loc,
3563 Attribute_Name => Name_Unchecked_Access,
3567 New_Reference_To (RTE (RE_Simple_Call), Loc),
3568 New_Occurrence_Of (Comm_Name, Loc)));
3570 when System_Tasking_Protected_Objects_Single_Entry =>
3571 -- Protected_Single_Entry_Call (
3572 -- Object => po._object'Access,
3573 -- Uninterpreted_Data => P'Address;
3574 -- Mode => Simple_Call);
3577 Make_Procedure_Call_Statement (Loc,
3578 Name => New_Reference_To (
3579 RTE (RE_Protected_Single_Entry_Call), Loc),
3581 Parameter_Associations => New_List (
3582 Make_Attribute_Reference (Loc,
3583 Attribute_Name => Name_Unchecked_Access,
3586 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3589 raise Program_Error;
3592 -- Case of task type
3596 Make_Procedure_Call_Statement (Loc,
3597 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3598 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3602 Append_To (Stats, Call);
3604 -- If there are out or in/out parameters by copy add assignment
3605 -- statements for the result values.
3607 if Present (Parms) then
3608 Actual := First_Actual (N);
3609 Formal := First_Formal (Ent);
3611 Set_Assignment_OK (Actual);
3612 while Present (Actual) loop
3613 if Is_By_Copy_Type (Etype (Actual))
3614 and then Ekind (Formal) /= E_In_Parameter
3617 Make_Assignment_Statement (Loc,
3618 Name => New_Copy (Actual),
3620 Make_Explicit_Dereference (Loc,
3621 Make_Selected_Component (Loc,
3622 Prefix => New_Reference_To (P, Loc),
3624 Make_Identifier (Loc, Chars (Formal)))));
3626 -- In all cases (including limited private types) we want
3627 -- the assignment to be valid.
3629 Set_Assignment_OK (Name (N_Node));
3631 -- If the call is the triggering alternative in an
3632 -- asynchronous select, or the entry_call alternative of a
3633 -- conditional entry call, the assignments for in-out
3634 -- parameters are incorporated into the statement list that
3635 -- follows, so that there are executed only if the entry
3638 if (Nkind (Parent (N)) = N_Triggering_Alternative
3639 and then N = Triggering_Statement (Parent (N)))
3641 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3642 and then N = Entry_Call_Statement (Parent (N)))
3644 if No (Statements (Parent (N))) then
3645 Set_Statements (Parent (N), New_List);
3648 Prepend (N_Node, Statements (Parent (N)));
3651 Insert_After (Call, N_Node);
3655 Next_Actual (Actual);
3656 Next_Formal_With_Extras (Formal);
3660 -- Finally, create block and analyze it
3663 Make_Block_Statement (Loc,
3664 Declarations => Decls,
3665 Handled_Statement_Sequence =>
3666 Make_Handled_Sequence_Of_Statements (Loc,
3667 Statements => Stats)));
3671 end Build_Simple_Entry_Call;
3673 --------------------------------
3674 -- Build_Task_Activation_Call --
3675 --------------------------------
3677 procedure Build_Task_Activation_Call (N : Node_Id) is
3678 Loc : constant Source_Ptr := Sloc (N);
3685 -- Get the activation chain entity. Except in the case of a package
3686 -- body, this is in the node that was passed. For a package body, we
3687 -- have to find the corresponding package declaration node.
3689 if Nkind (N) = N_Package_Body then
3690 P := Corresponding_Spec (N);
3693 exit when Nkind (P) = N_Package_Declaration;
3696 Chain := Activation_Chain_Entity (P);
3699 Chain := Activation_Chain_Entity (N);
3702 if Present (Chain) then
3703 if Restricted_Profile then
3704 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3706 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3710 Make_Procedure_Call_Statement (Loc,
3712 Parameter_Associations =>
3713 New_List (Make_Attribute_Reference (Loc,
3714 Prefix => New_Occurrence_Of (Chain, Loc),
3715 Attribute_Name => Name_Unchecked_Access)));
3717 if Nkind (N) = N_Package_Declaration then
3718 if Present (Corresponding_Body (N)) then
3721 elsif Present (Private_Declarations (Specification (N))) then
3722 Append (Call, Private_Declarations (Specification (N)));
3725 Append (Call, Visible_Declarations (Specification (N)));
3729 if Present (Handled_Statement_Sequence (N)) then
3731 -- The call goes at the start of the statement sequence
3732 -- after the start of exception range label if one is present.
3738 Stm := First (Statements (Handled_Statement_Sequence (N)));
3740 -- A special case, skip exception range label if one is
3741 -- present (from front end zcx processing).
3743 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3747 -- Another special case, if the first statement is a block
3748 -- from optimization of a local raise to a goto, then the
3749 -- call goes inside this block.
3751 if Nkind (Stm) = N_Block_Statement
3752 and then Exception_Junk (Stm)
3755 First (Statements (Handled_Statement_Sequence (Stm)));
3758 -- Insertion point is after any exception label pushes,
3759 -- since we want it covered by any local handlers.
3761 while Nkind (Stm) in N_Push_xxx_Label loop
3765 -- Now we have the proper insertion point
3767 Insert_Before (Stm, Call);
3771 Set_Handled_Statement_Sequence (N,
3772 Make_Handled_Sequence_Of_Statements (Loc,
3773 Statements => New_List (Call)));
3778 Check_Task_Activation (N);
3780 end Build_Task_Activation_Call;
3782 -------------------------------
3783 -- Build_Task_Allocate_Block --
3784 -------------------------------
3786 procedure Build_Task_Allocate_Block
3791 T : constant Entity_Id := Entity (Expression (N));
3792 Init : constant Entity_Id := Base_Init_Proc (T);
3793 Loc : constant Source_Ptr := Sloc (N);
3794 Chain : constant Entity_Id :=
3795 Make_Defining_Identifier (Loc, Name_uChain);
3801 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3804 Make_Block_Statement (Loc,
3805 Identifier => New_Reference_To (Blkent, Loc),
3806 Declarations => New_List (
3808 -- _Chain : Activation_Chain;
3810 Make_Object_Declaration (Loc,
3811 Defining_Identifier => Chain,
3812 Aliased_Present => True,
3813 Object_Definition =>
3814 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3816 Handled_Statement_Sequence =>
3817 Make_Handled_Sequence_Of_Statements (Loc,
3819 Statements => New_List (
3823 Make_Procedure_Call_Statement (Loc,
3824 Name => New_Reference_To (Init, Loc),
3825 Parameter_Associations => Args),
3827 -- Activate_Tasks (_Chain);
3829 Make_Procedure_Call_Statement (Loc,
3830 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3831 Parameter_Associations => New_List (
3832 Make_Attribute_Reference (Loc,
3833 Prefix => New_Reference_To (Chain, Loc),
3834 Attribute_Name => Name_Unchecked_Access))))),
3836 Has_Created_Identifier => True,
3837 Is_Task_Allocation_Block => True);
3840 Make_Implicit_Label_Declaration (Loc,
3841 Defining_Identifier => Blkent,
3842 Label_Construct => Block));
3844 Append_To (Actions, Block);
3846 Set_Activation_Chain_Entity (Block, Chain);
3847 end Build_Task_Allocate_Block;
3849 -----------------------------------------------
3850 -- Build_Task_Allocate_Block_With_Init_Stmts --
3851 -----------------------------------------------
3853 procedure Build_Task_Allocate_Block_With_Init_Stmts
3856 Init_Stmts : List_Id)
3858 Loc : constant Source_Ptr := Sloc (N);
3859 Chain : constant Entity_Id :=
3860 Make_Defining_Identifier (Loc, Name_uChain);
3865 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3867 Append_To (Init_Stmts,
3868 Make_Procedure_Call_Statement (Loc,
3869 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3870 Parameter_Associations => New_List (
3871 Make_Attribute_Reference (Loc,
3872 Prefix => New_Reference_To (Chain, Loc),
3873 Attribute_Name => Name_Unchecked_Access))));
3876 Make_Block_Statement (Loc,
3877 Identifier => New_Reference_To (Blkent, Loc),
3878 Declarations => New_List (
3880 -- _Chain : Activation_Chain;
3882 Make_Object_Declaration (Loc,
3883 Defining_Identifier => Chain,
3884 Aliased_Present => True,
3885 Object_Definition =>
3886 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3888 Handled_Statement_Sequence =>
3889 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
3891 Has_Created_Identifier => True,
3892 Is_Task_Allocation_Block => True);
3895 Make_Implicit_Label_Declaration (Loc,
3896 Defining_Identifier => Blkent,
3897 Label_Construct => Block));
3899 Append_To (Actions, Block);
3901 Set_Activation_Chain_Entity (Block, Chain);
3902 end Build_Task_Allocate_Block_With_Init_Stmts;
3904 -----------------------------------
3905 -- Build_Task_Proc_Specification --
3906 -----------------------------------
3908 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
3909 Loc : constant Source_Ptr := Sloc (T);
3910 Spec_Id : Entity_Id;
3914 Make_Defining_Identifier (Loc,
3915 Chars => New_External_Name (Chars (T), 'B'));
3916 Set_Is_Internal (Spec_Id);
3918 -- Associate the procedure with the task, if this is the declaration
3919 -- (and not the body) of the procedure.
3921 if No (Task_Body_Procedure (T)) then
3922 Set_Task_Body_Procedure (T, Spec_Id);
3926 Make_Procedure_Specification (Loc,
3927 Defining_Unit_Name => Spec_Id,
3928 Parameter_Specifications => New_List (
3929 Make_Parameter_Specification (Loc,
3930 Defining_Identifier =>
3931 Make_Defining_Identifier (Loc, Name_uTask),
3933 Make_Access_Definition (Loc,
3935 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
3936 end Build_Task_Proc_Specification;
3938 ---------------------------------------
3939 -- Build_Unprotected_Subprogram_Body --
3940 ---------------------------------------
3942 function Build_Unprotected_Subprogram_Body
3944 Pid : Node_Id) return Node_Id
3946 Decls : constant List_Id := Declarations (N);
3949 -- Add renamings for the Protection object, discriminals, privals and
3950 -- the entry index constant for use by debugger.
3952 Debug_Private_Data_Declarations (Decls);
3954 -- Make an unprotected version of the subprogram for use within the same
3955 -- object, with a new name and an additional parameter representing the
3959 Make_Subprogram_Body (Sloc (N),
3961 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
3962 Declarations => Decls,
3963 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
3964 end Build_Unprotected_Subprogram_Body;
3966 ----------------------------
3967 -- Collect_Entry_Families --
3968 ----------------------------
3970 procedure Collect_Entry_Families
3973 Current_Node : in out Node_Id;
3974 Conctyp : Entity_Id)
3977 Efam_Decl : Node_Id;
3978 Efam_Type : Entity_Id;
3981 Efam := First_Entity (Conctyp);
3982 while Present (Efam) loop
3983 if Ekind (Efam) = E_Entry_Family then
3985 Make_Defining_Identifier (Loc,
3986 Chars => New_Internal_Name ('F'));
3991 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
3993 Bas_Decl : Node_Id := Empty;
3998 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4000 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4002 Make_Defining_Identifier (Loc,
4003 Chars => New_Internal_Name ('B'));
4006 Make_Subtype_Declaration (Loc,
4007 Defining_Identifier => Bas,
4008 Subtype_Indication =>
4009 Make_Subtype_Indication (Loc,
4011 New_Occurrence_Of (Standard_Integer, Loc),
4013 Make_Range_Constraint (Loc,
4014 Range_Expression => Make_Range (Loc,
4015 Make_Integer_Literal
4016 (Loc, -Entry_Family_Bound),
4017 Make_Integer_Literal
4018 (Loc, Entry_Family_Bound - 1)))));
4020 Insert_After (Current_Node, Bas_Decl);
4021 Current_Node := Bas_Decl;
4026 Make_Full_Type_Declaration (Loc,
4027 Defining_Identifier => Efam_Type,
4029 Make_Unconstrained_Array_Definition (Loc,
4031 (New_List (New_Occurrence_Of (Bas, Loc))),
4033 Component_Definition =>
4034 Make_Component_Definition (Loc,
4035 Aliased_Present => False,
4036 Subtype_Indication =>
4037 New_Reference_To (Standard_Character, Loc))));
4040 Insert_After (Current_Node, Efam_Decl);
4041 Current_Node := Efam_Decl;
4042 Analyze (Efam_Decl);
4045 Make_Component_Declaration (Loc,
4046 Defining_Identifier =>
4047 Make_Defining_Identifier (Loc, Chars (Efam)),
4049 Component_Definition =>
4050 Make_Component_Definition (Loc,
4051 Aliased_Present => False,
4052 Subtype_Indication =>
4053 Make_Subtype_Indication (Loc,
4055 New_Occurrence_Of (Efam_Type, Loc),
4058 Make_Index_Or_Discriminant_Constraint (Loc,
4059 Constraints => New_List (
4061 (Etype (Discrete_Subtype_Definition
4062 (Parent (Efam))), Loc)))))));
4068 end Collect_Entry_Families;
4070 -----------------------
4071 -- Concurrent_Object --
4072 -----------------------
4074 function Concurrent_Object
4075 (Spec_Id : Entity_Id;
4076 Conc_Typ : Entity_Id) return Entity_Id
4079 -- Parameter _O or _object
4081 if Is_Protected_Type (Conc_Typ) then
4082 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4087 pragma Assert (Is_Task_Type (Conc_Typ));
4088 return First_Formal (Task_Body_Procedure (Conc_Typ));
4090 end Concurrent_Object;
4092 ----------------------
4093 -- Copy_Result_Type --
4094 ----------------------
4096 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4097 New_Res : constant Node_Id := New_Copy_Tree (Res);
4102 -- If the result type is an access_to_subprogram, we must create
4103 -- new entities for its spec.
4105 if Nkind (New_Res) = N_Access_Definition
4106 and then Present (Access_To_Subprogram_Definition (New_Res))
4108 -- Provide new entities for the formals
4110 Par_Spec := First (Parameter_Specifications
4111 (Access_To_Subprogram_Definition (New_Res)));
4112 while Present (Par_Spec) loop
4113 Formal := Defining_Identifier (Par_Spec);
4114 Set_Defining_Identifier (Par_Spec,
4115 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4121 end Copy_Result_Type;
4123 --------------------
4124 -- Concurrent_Ref --
4125 --------------------
4127 -- The expression returned for a reference to a concurrent object has the
4130 -- taskV!(name)._Task_Id
4134 -- objectV!(name)._Object
4136 -- for a protected object. For the case of an access to a concurrent
4137 -- object, there is an extra explicit dereference:
4139 -- taskV!(name.all)._Task_Id
4140 -- objectV!(name.all)._Object
4142 -- here taskV and objectV are the types for the associated records, which
4143 -- contain the required _Task_Id and _Object fields for tasks and protected
4144 -- objects, respectively.
4146 -- For the case of a task type name, the expression is
4150 -- i.e. a call to the Self function which returns precisely this Task_Id
4152 -- For the case of a protected type name, the expression is
4156 -- which is a renaming of the _object field of the current object
4157 -- record, passed into protected operations as a parameter.
4159 function Concurrent_Ref (N : Node_Id) return Node_Id is
4160 Loc : constant Source_Ptr := Sloc (N);
4161 Ntyp : constant Entity_Id := Etype (N);
4165 function Is_Current_Task (T : Entity_Id) return Boolean;
4166 -- Check whether the reference is to the immediately enclosing task
4167 -- type, or to an outer one (rare but legal).
4169 ---------------------
4170 -- Is_Current_Task --
4171 ---------------------
4173 function Is_Current_Task (T : Entity_Id) return Boolean is
4177 Scop := Current_Scope;
4178 while Present (Scop)
4179 and then Scop /= Standard_Standard
4185 elsif Is_Task_Type (Scop) then
4188 -- If this is a procedure nested within the task type, we must
4189 -- assume that it can be called from an inner task, and therefore
4190 -- cannot treat it as a local reference.
4192 elsif Is_Overloadable (Scop)
4193 and then In_Open_Scopes (T)
4198 Scop := Scope (Scop);
4202 -- We know that we are within the task body, so should have found it
4205 raise Program_Error;
4206 end Is_Current_Task;
4208 -- Start of processing for Concurrent_Ref
4211 if Is_Access_Type (Ntyp) then
4212 Dtyp := Designated_Type (Ntyp);
4214 if Is_Protected_Type (Dtyp) then
4215 Sel := Name_uObject;
4217 Sel := Name_uTask_Id;
4221 Make_Selected_Component (Loc,
4223 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4224 Make_Explicit_Dereference (Loc, N)),
4225 Selector_Name => Make_Identifier (Loc, Sel));
4227 elsif Is_Entity_Name (N)
4228 and then Is_Concurrent_Type (Entity (N))
4230 if Is_Task_Type (Entity (N)) then
4232 if Is_Current_Task (Entity (N)) then
4234 Make_Function_Call (Loc,
4235 Name => New_Reference_To (RTE (RE_Self), Loc));
4240 T_Self : constant Entity_Id :=
4241 Make_Defining_Identifier (Loc,
4242 Chars => New_Internal_Name ('T'));
4243 T_Body : constant Node_Id :=
4244 Parent (Corresponding_Body (Parent (Entity (N))));
4247 Decl := Make_Object_Declaration (Loc,
4248 Defining_Identifier => T_Self,
4249 Object_Definition =>
4250 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4252 Make_Function_Call (Loc,
4253 Name => New_Reference_To (RTE (RE_Self), Loc)));
4254 Prepend (Decl, Declarations (T_Body));
4256 Set_Scope (T_Self, Entity (N));
4257 return New_Occurrence_Of (T_Self, Loc);
4262 pragma Assert (Is_Protected_Type (Entity (N)));
4265 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4269 if Is_Protected_Type (Ntyp) then
4270 Sel := Name_uObject;
4272 elsif Is_Task_Type (Ntyp) then
4273 Sel := Name_uTask_Id;
4276 raise Program_Error;
4280 Make_Selected_Component (Loc,
4282 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4284 Selector_Name => Make_Identifier (Loc, Sel));
4288 ------------------------
4289 -- Convert_Concurrent --
4290 ------------------------
4292 function Convert_Concurrent
4294 Typ : Entity_Id) return Node_Id
4297 if not Is_Concurrent_Type (Typ) then
4301 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
4304 end Convert_Concurrent;
4306 -------------------------------------
4307 -- Debug_Private_Data_Declarations --
4308 -------------------------------------
4310 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4311 Debug_Nod : Node_Id;
4315 Decl := First (Decls);
4316 while Present (Decl)
4317 and then not Comes_From_Source (Decl)
4319 -- Declaration for concurrent entity _object and its access type,
4320 -- along with the entry index subtype:
4321 -- type prot_typVP is access prot_typV;
4322 -- _object : prot_typVP := prot_typV (_O);
4323 -- subtype Jnn is <Type of Index> range Low .. High;
4325 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4326 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4328 -- Declaration for the Protection object, discriminals, privals and
4329 -- entry index constant:
4330 -- conc_typR : protection_typ renames _object._object;
4331 -- discr_nameD : discr_typ renames _object.discr_name;
4332 -- discr_nameD : discr_typ renames _task.discr_name;
4333 -- prival_name : comp_typ renames _object.comp_name;
4334 -- J : constant Jnn :=
4335 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4337 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4338 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4339 Debug_Nod := Debug_Renaming_Declaration (Decl);
4341 if Present (Debug_Nod) then
4342 Insert_After (Decl, Debug_Nod);
4348 end Debug_Private_Data_Declarations;
4350 ----------------------------
4351 -- Entry_Index_Expression --
4352 ----------------------------
4354 function Entry_Index_Expression
4358 Ttyp : Entity_Id) return Node_Id
4368 -- The queues of entries and entry families appear in textual order in
4369 -- the associated record. The entry index is computed as the sum of the
4370 -- number of queues for all entries that precede the designated one, to
4371 -- which is added the index expression, if this expression denotes a
4372 -- member of a family.
4374 -- The following is a place holder for the count of simple entries
4376 Num := Make_Integer_Literal (Sloc, 1);
4378 -- We construct an expression which is a series of addition operations.
4379 -- The first operand is the number of single entries that precede this
4380 -- one, the second operand is the index value relative to the start of
4381 -- the referenced family, and the remaining operands are the lengths of
4382 -- the entry families that precede this entry, i.e. the constructed
4385 -- number_simple_entries +
4386 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4387 -- family'length + ...
4389 -- where index-value is the given index value, and s is the index
4390 -- subtype (we have to use pos because the subtype might be an
4391 -- enumeration type preventing direct subtraction). Note that the task
4392 -- entry array is one-indexed.
4394 -- The upper bound of the entry family may be a discriminant, so we
4395 -- retrieve the lower bound explicitly to compute offset, rather than
4396 -- using the index subtype which may mention a discriminant.
4398 if Present (Index) then
4399 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4408 Make_Attribute_Reference (Sloc,
4409 Attribute_Name => Name_Pos,
4410 Prefix => New_Reference_To (Base_Type (S), Sloc),
4411 Expressions => New_List (Relocate_Node (Index))),
4419 -- Now add lengths of preceding entries and entry families
4421 Prev := First_Entity (Ttyp);
4423 while Chars (Prev) /= Chars (Ent)
4424 or else (Ekind (Prev) /= Ekind (Ent))
4425 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4427 if Ekind (Prev) = E_Entry then
4428 Set_Intval (Num, Intval (Num) + 1);
4430 elsif Ekind (Prev) = E_Entry_Family then
4432 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4433 Lo := Type_Low_Bound (S);
4434 Hi := Type_High_Bound (S);
4439 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4441 -- Other components are anonymous types to be ignored
4451 end Entry_Index_Expression;
4453 ---------------------------
4454 -- Establish_Task_Master --
4455 ---------------------------
4457 procedure Establish_Task_Master (N : Node_Id) is
4460 if Restriction_Active (No_Task_Hierarchy) = False then
4461 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4462 Prepend_To (Declarations (N), Call);
4465 end Establish_Task_Master;
4467 --------------------------------
4468 -- Expand_Accept_Declarations --
4469 --------------------------------
4471 -- Part of the expansion of an accept statement involves the creation of
4472 -- a declaration that can be referenced from the statement sequence of
4477 -- This declaration is inserted immediately before the accept statement
4478 -- and it is important that it be inserted before the statements of the
4479 -- statement sequence are analyzed. Thus it would be too late to create
4480 -- this declaration in the Expand_N_Accept_Statement routine, which is
4481 -- why there is a separate procedure to be called directly from Sem_Ch9.
4483 -- Ann is used to hold the address of the record containing the parameters
4484 -- (see Expand_N_Entry_Call for more details on how this record is built).
4485 -- References to the parameters do an unchecked conversion of this address
4486 -- to a pointer to the required record type, and then access the field that
4487 -- holds the value of the required parameter. The entity for the address
4488 -- variable is held as the top stack element (i.e. the last element) of the
4489 -- Accept_Address stack in the corresponding entry entity, and this element
4490 -- must be set in place before the statements are processed.
4492 -- The above description applies to the case of a stand alone accept
4493 -- statement, i.e. one not appearing as part of a select alternative.
4495 -- For the case of an accept that appears as part of a select alternative
4496 -- of a selective accept, we must still create the declaration right away,
4497 -- since Ann is needed immediately, but there is an important difference:
4499 -- The declaration is inserted before the selective accept, not before
4500 -- the accept statement (which is not part of a list anyway, and so would
4501 -- not accommodate inserted declarations)
4503 -- We only need one address variable for the entire selective accept. So
4504 -- the Ann declaration is created only for the first accept alternative,
4505 -- and subsequent accept alternatives reference the same Ann variable.
4507 -- We can distinguish the two cases by seeing whether the accept statement
4508 -- is part of a list. If not, then it must be in an accept alternative.
4510 -- To expand the requeue statement, a label is provided at the end of the
4511 -- accept statement or alternative of which it is a part, so that the
4512 -- statement can be skipped after the requeue is complete. This label is
4513 -- created here rather than during the expansion of the accept statement,
4514 -- because it will be needed by any requeue statements within the accept,
4515 -- which are expanded before the accept.
4517 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4518 Loc : constant Source_Ptr := Sloc (N);
4519 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4520 Ann : Entity_Id := Empty;
4528 if Expander_Active then
4530 -- If we have no handled statement sequence, we may need to build
4531 -- a dummy sequence consisting of a null statement. This can be
4532 -- skipped if the trivial accept optimization is permitted.
4534 if not Trivial_Accept_OK
4536 (No (Stats) or else Null_Statements (Statements (Stats)))
4538 Set_Handled_Statement_Sequence (N,
4539 Make_Handled_Sequence_Of_Statements (Loc,
4540 New_List (Make_Null_Statement (Loc))));
4543 -- Create and declare two labels to be placed at the end of the
4544 -- accept statement. The first label is used to allow requeues to
4545 -- skip the remainder of entry processing. The second label is used
4546 -- to skip the remainder of entry processing if the rendezvous
4547 -- completes in the middle of the accept body.
4549 if Present (Handled_Statement_Sequence (N)) then
4550 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4552 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4553 Lab := Make_Label (Loc, Lab_Id);
4555 Make_Implicit_Label_Declaration (Loc,
4556 Defining_Identifier => Entity (Lab_Id),
4557 Label_Construct => Lab);
4558 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4560 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4562 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4563 Lab := Make_Label (Loc, Lab_Id);
4565 Make_Implicit_Label_Declaration (Loc,
4566 Defining_Identifier => Entity (Lab_Id),
4567 Label_Construct => Lab);
4568 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4575 -- Case of stand alone accept statement
4577 if Is_List_Member (N) then
4579 if Present (Handled_Statement_Sequence (N)) then
4581 Make_Defining_Identifier (Loc,
4582 Chars => New_Internal_Name ('A'));
4585 Make_Object_Declaration (Loc,
4586 Defining_Identifier => Ann,
4587 Object_Definition =>
4588 New_Reference_To (RTE (RE_Address), Loc));
4590 Insert_Before (N, Adecl);
4593 Insert_Before (N, Ldecl);
4596 Insert_Before (N, Ldecl2);
4600 -- Case of accept statement which is in an accept alternative
4604 Acc_Alt : constant Node_Id := Parent (N);
4605 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4609 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4610 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4612 -- ??? Consider a single label for select statements
4614 if Present (Handled_Statement_Sequence (N)) then
4616 Statements (Handled_Statement_Sequence (N)));
4620 Statements (Handled_Statement_Sequence (N)));
4624 -- Find first accept alternative of the selective accept. A
4625 -- valid selective accept must have at least one accept in it.
4627 Alt := First (Select_Alternatives (Sel_Acc));
4629 while Nkind (Alt) /= N_Accept_Alternative loop
4633 -- If we are the first accept statement, then we have to create
4634 -- the Ann variable, as for the stand alone case, except that
4635 -- it is inserted before the selective accept. Similarly, a
4636 -- label for requeue expansion must be declared.
4638 if N = Accept_Statement (Alt) then
4640 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4643 Make_Object_Declaration (Loc,
4644 Defining_Identifier => Ann,
4645 Object_Definition =>
4646 New_Reference_To (RTE (RE_Address), Loc));
4648 Insert_Before (Sel_Acc, Adecl);
4651 -- If we are not the first accept statement, then find the Ann
4652 -- variable allocated by the first accept and use it.
4656 Node (Last_Elmt (Accept_Address
4657 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4662 -- Merge here with Ann either created or referenced, and Adecl
4663 -- pointing to the corresponding declaration. Remaining processing
4664 -- is the same for the two cases.
4666 if Present (Ann) then
4667 Append_Elmt (Ann, Accept_Address (Ent));
4668 Set_Debug_Info_Needed (Ann);
4671 -- Create renaming declarations for the entry formals. Each reference
4672 -- to a formal becomes a dereference of a component of the parameter
4673 -- block, whose address is held in Ann. These declarations are
4674 -- eventually inserted into the accept block, and analyzed there so
4675 -- that they have the proper scope for gdb and do not conflict with
4676 -- other declarations.
4678 if Present (Parameter_Specifications (N))
4679 and then Present (Handled_Statement_Sequence (N))
4689 Formal := First_Formal (Ent);
4691 while Present (Formal) loop
4692 Comp := Entry_Component (Formal);
4694 Make_Defining_Identifier (Loc, Chars (Formal));
4696 Set_Etype (New_F, Etype (Formal));
4697 Set_Scope (New_F, Ent);
4699 -- Now we set debug info needed on New_F even though it does
4700 -- not come from source, so that the debugger will get the
4701 -- right information for these generated names.
4703 Set_Debug_Info_Needed (New_F);
4705 if Ekind (Formal) = E_In_Parameter then
4706 Set_Ekind (New_F, E_Constant);
4708 Set_Ekind (New_F, E_Variable);
4709 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4712 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4715 Make_Object_Renaming_Declaration (Loc,
4716 Defining_Identifier =>
4719 New_Reference_To (Etype (Formal), Loc),
4721 Make_Explicit_Dereference (Loc,
4722 Make_Selected_Component (Loc,
4724 Unchecked_Convert_To (
4725 Entry_Parameters_Type (Ent),
4726 New_Reference_To (Ann, Loc)),
4728 New_Reference_To (Comp, Loc))));
4730 if No (Declarations (N)) then
4731 Set_Declarations (N, New_List);
4734 Append (Decl, Declarations (N));
4735 Set_Renamed_Object (Formal, New_F);
4736 Next_Formal (Formal);
4743 end Expand_Accept_Declarations;
4745 ---------------------------------------------
4746 -- Expand_Access_Protected_Subprogram_Type --
4747 ---------------------------------------------
4749 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4750 Loc : constant Source_Ptr := Sloc (N);
4752 T : constant Entity_Id := Defining_Identifier (N);
4753 D_T : constant Entity_Id := Designated_Type (T);
4754 D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc,
4755 Chars => New_Internal_Name ('D'));
4756 E_T : constant Entity_Id := Make_Defining_Identifier (Loc,
4757 Chars => New_Internal_Name ('E'));
4758 P_List : constant List_Id := Build_Protected_Spec
4759 (N, RTE (RE_Address), D_T, False);
4765 -- Create access to subprogram with full signature
4767 if Etype (D_T) /= Standard_Void_Type then
4769 Make_Access_Function_Definition (Loc,
4770 Parameter_Specifications => P_List,
4771 Result_Definition =>
4772 Copy_Result_Type (Result_Definition (Type_Definition (N))));
4776 Make_Access_Procedure_Definition (Loc,
4777 Parameter_Specifications => P_List);
4781 Make_Full_Type_Declaration (Loc,
4782 Defining_Identifier => D_T2,
4783 Type_Definition => Def1);
4785 Insert_After (N, Decl1);
4788 -- Create Equivalent_Type, a record with two components for an access to
4789 -- object and an access to subprogram.
4792 Make_Component_Declaration (Loc,
4793 Defining_Identifier =>
4794 Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
4795 Component_Definition =>
4796 Make_Component_Definition (Loc,
4797 Aliased_Present => False,
4798 Subtype_Indication =>
4799 New_Occurrence_Of (RTE (RE_Address), Loc))),
4801 Make_Component_Declaration (Loc,
4802 Defining_Identifier =>
4803 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4804 Component_Definition =>
4805 Make_Component_Definition (Loc,
4806 Aliased_Present => False,
4807 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4810 Make_Full_Type_Declaration (Loc,
4811 Defining_Identifier => E_T,
4813 Make_Record_Definition (Loc,
4815 Make_Component_List (Loc,
4816 Component_Items => Comps)));
4818 Insert_After (Decl1, Decl2);
4820 Set_Equivalent_Type (T, E_T);
4821 end Expand_Access_Protected_Subprogram_Type;
4823 --------------------------
4824 -- Expand_Entry_Barrier --
4825 --------------------------
4827 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4828 Cond : constant Node_Id :=
4829 Condition (Entry_Body_Formal_Part (N));
4830 Prot : constant Entity_Id := Scope (Ent);
4831 Spec_Decl : constant Node_Id := Parent (Prot);
4834 Body_Decl : Node_Id;
4837 if No_Run_Time_Mode then
4838 Error_Msg_CRT ("entry barrier", N);
4842 -- The body of the entry barrier must be analyzed in the context of the
4843 -- protected object, but its scope is external to it, just as any other
4844 -- unprotected version of a protected operation. The specification has
4845 -- been produced when the protected type declaration was elaborated. We
4846 -- build the body, insert it in the enclosing scope, but analyze it in
4847 -- the current context. A more uniform approach would be to treat the
4848 -- barrier just as a protected function, and discard the protected
4849 -- version of it because it is never called.
4851 if Expander_Active then
4852 B_F := Build_Barrier_Function (N, Ent, Prot);
4853 Func := Barrier_Function (Ent);
4854 Set_Corresponding_Spec (B_F, Func);
4856 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
4858 if Nkind (Parent (Body_Decl)) = N_Subunit then
4859 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
4862 Insert_Before_And_Analyze (Body_Decl, B_F);
4864 Set_Discriminals (Spec_Decl);
4865 Set_Scope (Func, Scope (Prot));
4868 Analyze_And_Resolve (Cond, Any_Boolean);
4871 -- The Ravenscar profile restricts barriers to simple variables declared
4872 -- within the protected object. We also allow Boolean constants, since
4873 -- these appear in several published examples and are also allowed by
4874 -- the Aonix compiler.
4876 -- Note that after analysis variables in this context will be replaced
4877 -- by the corresponding prival, that is to say a renaming of a selected
4878 -- component of the form _Object.Var. If expansion is disabled, as
4879 -- within a generic, we check that the entity appears in the current
4882 if Is_Entity_Name (Cond) then
4884 -- A small optimization of useless renamings. If the scope of the
4885 -- entity of the condition is not the barrier function, then the
4886 -- condition does not reference any of the generated renamings
4887 -- within the function.
4890 and then Scope (Entity (Cond)) /= Func
4892 Set_Declarations (B_F, Empty_List);
4895 if Entity (Cond) = Standard_False
4897 Entity (Cond) = Standard_True
4901 elsif not Expander_Active
4902 and then Scope (Entity (Cond)) = Current_Scope
4906 -- Check for case of _object.all.field (note that the explicit
4907 -- dereference gets inserted by analyze/expand of _object.field)
4909 elsif Present (Renamed_Object (Entity (Cond)))
4911 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
4915 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
4921 -- It is not a boolean variable or literal, so check the restriction
4923 Check_Restriction (Simple_Barriers, Cond);
4924 end Expand_Entry_Barrier;
4926 ------------------------------
4927 -- Expand_N_Abort_Statement --
4928 ------------------------------
4930 -- Expand abort T1, T2, .. Tn; into:
4931 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
4933 procedure Expand_N_Abort_Statement (N : Node_Id) is
4934 Loc : constant Source_Ptr := Sloc (N);
4935 Tlist : constant List_Id := Names (N);
4941 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
4944 Tasknm := First (Tlist);
4946 while Present (Tasknm) loop
4949 -- A task interface class-wide type object is being aborted.
4950 -- Retrieve its _task_id by calling a dispatching routine.
4952 if Ada_Version >= Ada_05
4953 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
4954 and then Is_Interface (Etype (Tasknm))
4955 and then Is_Task_Interface (Etype (Tasknm))
4957 Append_To (Component_Associations (Aggr),
4958 Make_Component_Association (Loc,
4959 Choices => New_List (
4960 Make_Integer_Literal (Loc, Count)),
4963 -- Task_Id (Tasknm._disp_get_task_id)
4965 Make_Unchecked_Type_Conversion (Loc,
4967 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
4969 Make_Selected_Component (Loc,
4971 New_Copy_Tree (Tasknm),
4973 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
4976 Append_To (Component_Associations (Aggr),
4977 Make_Component_Association (Loc,
4978 Choices => New_List (
4979 Make_Integer_Literal (Loc, Count)),
4980 Expression => Concurrent_Ref (Tasknm)));
4987 Make_Procedure_Call_Statement (Loc,
4988 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
4989 Parameter_Associations => New_List (
4990 Make_Qualified_Expression (Loc,
4991 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
4992 Expression => Aggr))));
4995 end Expand_N_Abort_Statement;
4997 -------------------------------
4998 -- Expand_N_Accept_Statement --
4999 -------------------------------
5001 -- This procedure handles expansion of accept statements that stand
5002 -- alone, i.e. they are not part of an accept alternative. The expansion
5003 -- of accept statement in accept alternatives is handled by the routines
5004 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5005 -- following description applies only to stand alone accept statements.
5007 -- If there is no handled statement sequence, or only null statements,
5008 -- then this is called a trivial accept, and the expansion is:
5010 -- Accept_Trivial (entry-index)
5012 -- If there is a handled statement sequence, then the expansion is:
5019 -- Accept_Call (entry-index, Ann);
5020 -- Renaming_Declarations for formals
5021 -- <statement sequence from N_Accept_Statement node>
5022 -- Complete_Rendezvous;
5027 -- <exception handler from N_Accept_Statement node>
5028 -- Complete_Rendezvous;
5030 -- <exception handler from N_Accept_Statement node>
5031 -- Complete_Rendezvous;
5036 -- when all others =>
5037 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5040 -- The first three declarations were already inserted ahead of the accept
5041 -- statement by the Expand_Accept_Declarations procedure, which was called
5042 -- directly from the semantics during analysis of the accept statement,
5043 -- before analyzing its contained statements.
5045 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5046 -- from possible expansion activity (the original source of course does
5047 -- not have any declarations associated with the accept statement, since
5048 -- an accept statement has no declarative part). In particular, if the
5049 -- expander is active, the first such declaration is the declaration of
5050 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5052 -- The two blocks are merged into a single block if the inner block has
5053 -- no exception handlers, but otherwise two blocks are required, since
5054 -- exceptions might be raised in the exception handlers of the inner
5055 -- block, and Exceptional_Complete_Rendezvous must be called.
5057 procedure Expand_N_Accept_Statement (N : Node_Id) is
5058 Loc : constant Source_Ptr := Sloc (N);
5059 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5060 Ename : constant Node_Id := Entry_Direct_Name (N);
5061 Eindx : constant Node_Id := Entry_Index (N);
5062 Eent : constant Entity_Id := Entity (Ename);
5063 Acstack : constant Elist_Id := Accept_Address (Eent);
5064 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5065 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5070 -- Start of processing for Expand_N_Accept_Statement
5073 -- If accept statement is not part of a list, then its parent must be
5074 -- an accept alternative, and, as described above, we do not do any
5075 -- expansion for such accept statements at this level.
5077 if not Is_List_Member (N) then
5078 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5081 -- Trivial accept case (no statement sequence, or null statements).
5082 -- If the accept statement has declarations, then just insert them
5083 -- before the procedure call.
5085 elsif Trivial_Accept_OK
5086 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5088 -- Remove declarations for renamings, because the parameter block
5089 -- will not be assigned.
5096 D := First (Declarations (N));
5098 while Present (D) loop
5100 if Nkind (D) = N_Object_Renaming_Declaration then
5108 if Present (Declarations (N)) then
5109 Insert_Actions (N, Declarations (N));
5113 Make_Procedure_Call_Statement (Loc,
5114 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5115 Parameter_Associations => New_List (
5116 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5120 -- Discard Entry_Address that was created for it, so it will not be
5121 -- emitted if this accept statement is in the statement part of a
5122 -- delay alternative.
5124 if Present (Stats) then
5125 Remove_Last_Elmt (Acstack);
5128 -- Case of statement sequence present
5131 -- Construct the block, using the declarations from the accept
5132 -- statement if any to initialize the declarations of the block.
5134 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5135 Set_Ekind (Blkent, E_Block);
5136 Set_Etype (Blkent, Standard_Void_Type);
5137 Set_Scope (Blkent, Current_Scope);
5140 Make_Block_Statement (Loc,
5141 Identifier => New_Reference_To (Blkent, Loc),
5142 Declarations => Declarations (N),
5143 Handled_Statement_Sequence => Build_Accept_Body (N));
5145 -- Prepend call to Accept_Call to main statement sequence If the
5146 -- accept has exception handlers, the statement sequence is wrapped
5147 -- in a block. Insert call and renaming declarations in the
5148 -- declarations of the block, so they are elaborated before the
5152 Make_Procedure_Call_Statement (Loc,
5153 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5154 Parameter_Associations => New_List (
5155 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5156 New_Reference_To (Ann, Loc)));
5158 if Parent (Stats) = N then
5159 Prepend (Call, Statements (Stats));
5168 Push_Scope (Blkent);
5176 D := First (Declarations (N));
5177 while Present (D) loop
5180 if Nkind (D) = N_Object_Renaming_Declaration then
5182 -- The renaming declarations for the formals were created
5183 -- during analysis of the accept statement, and attached to
5184 -- the list of declarations. Place them now in the context
5185 -- of the accept block or subprogram.
5188 Typ := Entity (Subtype_Mark (D));
5189 Insert_After (Call, D);
5192 -- If the formal is class_wide, it does not have an actual
5193 -- subtype. The analysis of the renaming declaration creates
5194 -- one, but we need to retain the class-wide nature of the
5197 if Is_Class_Wide_Type (Typ) then
5198 Set_Etype (Defining_Identifier (D), Typ);
5209 -- Replace the accept statement by the new block
5214 -- Last step is to unstack the Accept_Address value
5216 Remove_Last_Elmt (Acstack);
5218 end Expand_N_Accept_Statement;
5220 ----------------------------------
5221 -- Expand_N_Asynchronous_Select --
5222 ----------------------------------
5224 -- This procedure assumes that the trigger statement is an entry call or
5225 -- a dispatching procedure call. A delay alternative should already have
5226 -- been expanded into an entry call to the appropriate delay object Wait
5229 -- If the trigger is a task entry call, the select is implemented with
5230 -- a Task_Entry_Call:
5235 -- P : parms := (parm, parm, parm);
5237 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5239 -- procedure _clean is
5242 -- Cancel_Task_Entry_Call (C);
5249 -- (<acceptor-task>, -- Acceptor
5250 -- <entry-index>, -- E
5251 -- P'Address, -- Uninterpreted_Data
5252 -- Asynchronous_Call, -- Mode
5253 -- B); -- Rendezvous_Successful
5260 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5263 -- when Abort_Signal => Abort_Undefer;
5270 -- <triggered-statements>
5274 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5275 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5279 -- P : parms := (parm, parm, parm);
5281 -- Call_Simple (acceptor-task, entry-index, P'Address);
5287 -- so the task at hand is to convert the latter expansion into the former
5289 -- If the trigger is a protected entry call, the select is implemented
5290 -- with Protected_Entry_Call:
5293 -- P : E1_Params := (param, param, param);
5294 -- Bnn : Communications_Block;
5299 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5301 -- procedure _clean is
5304 -- if Enqueued (Bnn) then
5305 -- Cancel_Protected_Entry_Call (Bnn);
5312 -- Protected_Entry_Call
5313 -- (po._object'Access, -- Object
5314 -- <entry index>, -- E
5315 -- P'Address, -- Uninterpreted_Data
5316 -- Asynchronous_Call, -- Mode
5319 -- if Enqueued (Bnn) then
5323 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5326 -- when Abort_Signal => Abort_Undefer;
5329 -- if not Cancelled (Bnn) then
5330 -- <triggered-statements>
5334 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5338 -- P : E1_Params := (param, param, param);
5339 -- Bnn : Communications_Block;
5342 -- Protected_Entry_Call
5343 -- (po._object'Access, -- Object
5344 -- <entry index>, -- E
5345 -- P'Address, -- Uninterpreted_Data
5346 -- Simple_Call, -- Mode
5353 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5357 -- B : Boolean := False;
5358 -- Bnn : Communication_Block;
5359 -- C : Ada.Tags.Prim_Op_Kind;
5360 -- D : System.Storage_Elements.Dummy_Communication_Block;
5361 -- K : Ada.Tags.Tagged_Kind :=
5362 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5363 -- P : Parameters := (Param1 .. ParamN);
5368 -- if K = Ada.Tags.TK_Limited_Tagged then
5369 -- <dispatching-call>;
5370 -- <triggering-statements>;
5374 -- Ada.Tags.Get_Offset_Index
5375 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5377 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5379 -- if C = POK_Protected_Entry then
5381 -- procedure _clean is
5383 -- if Enqueued (Bnn) then
5384 -- Cancel_Protected_Entry_Call (Bnn);
5390 -- _Disp_Asynchronous_Select
5391 -- (<object>, S, P'Address, D, B);
5392 -- Bnn := Communication_Block (D);
5394 -- Param1 := P.Param1;
5396 -- ParamN := P.ParamN;
5398 -- if Enqueued (Bnn) then
5399 -- <abortable-statements>
5402 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5405 -- when Abort_Signal => Abort_Undefer;
5408 -- if not Cancelled (Bnn) then
5409 -- <triggering-statements>
5412 -- elsif C = POK_Task_Entry then
5414 -- procedure _clean is
5416 -- Cancel_Task_Entry_Call (U);
5422 -- _Disp_Asynchronous_Select
5423 -- (<object>, S, P'Address, D, B);
5424 -- Bnn := Communication_Bloc (D);
5426 -- Param1 := P.Param1;
5428 -- ParamN := P.ParamN;
5433 -- <abortable-statements>
5435 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5438 -- when Abort_Signal => Abort_Undefer;
5442 -- <triggering-statements>
5447 -- <dispatching-call>;
5448 -- <triggering-statements>
5453 -- The job is to convert this to the asynchronous form
5455 -- If the trigger is a delay statement, it will have been expanded into a
5456 -- call to one of the GNARL delay procedures. This routine will convert
5457 -- this into a protected entry call on a delay object and then continue
5458 -- processing as for a protected entry call trigger. This requires
5459 -- declaring a Delay_Block object and adding a pointer to this object to
5460 -- the parameter list of the delay procedure to form the parameter list of
5461 -- the entry call. This object is used by the runtime to queue the delay
5464 -- For a description of the use of P and the assignments after the call,
5465 -- see Expand_N_Entry_Call_Statement.
5467 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5468 Loc : constant Source_Ptr := Sloc (N);
5469 Abrt : constant Node_Id := Abortable_Part (N);
5470 Astats : constant List_Id := Statements (Abrt);
5471 Trig : constant Node_Id := Triggering_Alternative (N);
5472 Tstats : constant List_Id := Statements (Trig);
5474 Abort_Block_Ent : Entity_Id;
5475 Abortable_Block : Node_Id;
5477 Blk_Ent : Entity_Id;
5478 Blk_Typ : Entity_Id;
5480 Call_Ent : Entity_Id;
5481 Cancel_Param : Entity_Id;
5482 Cleanup_Block : Node_Id;
5483 Cleanup_Block_Ent : Entity_Id;
5484 Cleanup_Stmts : List_Id;
5485 Conc_Typ_Stmts : List_Id;
5487 Dblock_Ent : Entity_Id;
5492 Enqueue_Call : Node_Id;
5496 Lim_Typ_Stmts : List_Id;
5502 ProtE_Stmts : List_Id;
5503 ProtP_Stmts : List_Id;
5506 Target_Undefer : RE_Id;
5507 TaskE_Stmts : List_Id;
5508 Undefer_Args : List_Id := No_List;
5510 B : Entity_Id; -- Call status flag
5511 Bnn : Entity_Id; -- Communication block
5512 C : Entity_Id; -- Call kind
5513 K : Entity_Id; -- Tagged kind
5514 P : Entity_Id; -- Parameter block
5515 S : Entity_Id; -- Primitive operation slot
5516 T : Entity_Id; -- Additional status flag
5519 Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5520 Ecall := Triggering_Statement (Trig);
5522 -- The arguments in the call may require dynamic allocation, and the
5523 -- call statement may have been transformed into a block. The block
5524 -- may contain additional declarations for internal entities, and the
5525 -- original call is found by sequential search.
5527 if Nkind (Ecall) = N_Block_Statement then
5528 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5529 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5530 N_Entry_Call_Statement)
5536 -- This is either a dispatching call or a delay statement used as a
5537 -- trigger which was expanded into a procedure call.
5539 if Nkind (Ecall) = N_Procedure_Call_Statement then
5540 if Ada_Version >= Ada_05
5542 (No (Original_Node (Ecall))
5543 or else not Nkind_In (Original_Node (Ecall),
5544 N_Delay_Relative_Statement,
5545 N_Delay_Until_Statement))
5547 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5552 -- Call status flag processing, generate:
5553 -- B : Boolean := False;
5555 B := Build_B (Loc, Decls);
5557 -- Communication block processing, generate:
5558 -- Bnn : Communication_Block;
5560 Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
5563 Make_Object_Declaration (Loc,
5564 Defining_Identifier =>
5566 Object_Definition =>
5567 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5569 -- Call kind processing, generate:
5570 -- C : Ada.Tags.Prim_Op_Kind;
5572 C := Build_C (Loc, Decls);
5574 -- Tagged kind processing, generate:
5575 -- K : Ada.Tags.Tagged_Kind :=
5576 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5578 -- Dummy communication block, generate:
5579 -- D : Dummy_Communication_Block;
5582 Make_Object_Declaration (Loc,
5583 Defining_Identifier =>
5584 Make_Defining_Identifier (Loc, Name_uD),
5585 Object_Definition =>
5587 RTE (RE_Dummy_Communication_Block), Loc)));
5589 K := Build_K (Loc, Decls, Obj);
5591 -- Parameter block processing
5593 Blk_Typ := Build_Parameter_Block
5594 (Loc, Actuals, Formals, Decls);
5595 P := Parameter_Block_Pack
5596 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5598 -- Dispatch table slot processing, generate:
5601 S := Build_S (Loc, Decls);
5603 -- Additional status flag processing, generate:
5605 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
5608 Make_Object_Declaration (Loc,
5609 Defining_Identifier =>
5611 Object_Definition =>
5612 New_Reference_To (Standard_Boolean, Loc)));
5614 ------------------------------
5615 -- Protected entry handling --
5616 ------------------------------
5619 -- Param1 := P.Param1;
5621 -- ParamN := P.ParamN;
5623 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5626 -- Bnn := Communication_Block (D);
5628 Prepend_To (Cleanup_Stmts,
5629 Make_Assignment_Statement (Loc,
5631 New_Reference_To (Bnn, Loc),
5633 Make_Unchecked_Type_Conversion (Loc,
5635 New_Reference_To (RTE (RE_Communication_Block), Loc),
5637 Make_Identifier (Loc, Name_uD))));
5640 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5642 Prepend_To (Cleanup_Stmts,
5643 Make_Procedure_Call_Statement (Loc,
5646 Find_Prim_Op (Etype (Etype (Obj)),
5647 Name_uDisp_Asynchronous_Select),
5649 Parameter_Associations =>
5651 New_Copy_Tree (Obj), -- <object>
5652 New_Reference_To (S, Loc), -- S
5653 Make_Attribute_Reference (Loc, -- P'Address
5655 New_Reference_To (P, Loc),
5658 Make_Identifier (Loc, Name_uD), -- D
5659 New_Reference_To (B, Loc)))); -- B
5662 -- if Enqueued (Bnn) then
5663 -- <abortable-statements>
5666 Append_To (Cleanup_Stmts,
5667 Make_If_Statement (Loc,
5669 Make_Function_Call (Loc,
5671 New_Reference_To (RTE (RE_Enqueued), Loc),
5672 Parameter_Associations =>
5674 New_Reference_To (Bnn, Loc))),
5677 New_Copy_List_Tree (Astats)));
5679 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5680 -- will then generate a _clean for the communication block Bnn.
5684 -- procedure _clean is
5686 -- if Enqueued (Bnn) then
5687 -- Cancel_Protected_Entry_Call (Bnn);
5696 Cleanup_Block_Ent :=
5697 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5700 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5702 -- Wrap the cleanup block in an exception handling block
5708 -- when Abort_Signal => Abort_Undefer;
5712 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5716 Make_Implicit_Label_Declaration (Loc,
5717 Defining_Identifier =>
5721 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5724 -- if not Cancelled (Bnn) then
5725 -- <triggering-statements>
5728 Append_To (ProtE_Stmts,
5729 Make_If_Statement (Loc,
5733 Make_Function_Call (Loc,
5735 New_Reference_To (RTE (RE_Cancelled), Loc),
5736 Parameter_Associations =>
5738 New_Reference_To (Bnn, Loc)))),
5741 New_Copy_List_Tree (Tstats)));
5743 -------------------------
5744 -- Task entry handling --
5745 -------------------------
5748 -- Param1 := P.Param1;
5750 -- ParamN := P.ParamN;
5752 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5755 -- Bnn := Communication_Block (D);
5757 Append_To (TaskE_Stmts,
5758 Make_Assignment_Statement (Loc,
5760 New_Reference_To (Bnn, Loc),
5762 Make_Unchecked_Type_Conversion (Loc,
5764 New_Reference_To (RTE (RE_Communication_Block), Loc),
5766 Make_Identifier (Loc, Name_uD))));
5769 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5771 Prepend_To (TaskE_Stmts,
5772 Make_Procedure_Call_Statement (Loc,
5775 Find_Prim_Op (Etype (Etype (Obj)),
5776 Name_uDisp_Asynchronous_Select),
5778 Parameter_Associations =>
5780 New_Copy_Tree (Obj), -- <object>
5781 New_Reference_To (S, Loc), -- S
5782 Make_Attribute_Reference (Loc, -- P'Address
5784 New_Reference_To (P, Loc),
5787 Make_Identifier (Loc, Name_uD), -- D
5788 New_Reference_To (B, Loc)))); -- B
5793 Prepend_To (TaskE_Stmts,
5794 Make_Procedure_Call_Statement (Loc,
5796 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5797 Parameter_Associations =>
5802 -- <abortable-statements>
5804 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5806 Prepend_To (Cleanup_Stmts,
5807 Make_Procedure_Call_Statement (Loc,
5809 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5810 Parameter_Associations =>
5813 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5814 -- will generate a _clean for the additional status flag.
5818 -- procedure _clean is
5820 -- Cancel_Task_Entry_Call (U);
5828 Cleanup_Block_Ent :=
5829 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5832 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
5834 -- Wrap the cleanup block in an exception handling block
5840 -- when Abort_Signal => Abort_Undefer;
5844 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5846 Append_To (TaskE_Stmts,
5847 Make_Implicit_Label_Declaration (Loc,
5848 Defining_Identifier =>
5851 Append_To (TaskE_Stmts,
5853 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5857 -- <triggering-statements>
5860 Append_To (TaskE_Stmts,
5861 Make_If_Statement (Loc,
5865 New_Reference_To (T, Loc)),
5868 New_Copy_List_Tree (Tstats)));
5870 ----------------------------------
5871 -- Protected procedure handling --
5872 ----------------------------------
5875 -- <dispatching-call>;
5876 -- <triggering-statements>
5878 ProtP_Stmts := New_Copy_List_Tree (Tstats);
5879 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
5882 -- S := Ada.Tags.Get_Offset_Index
5883 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
5886 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
5889 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5891 Append_To (Conc_Typ_Stmts,
5892 Make_Procedure_Call_Statement (Loc,
5895 Find_Prim_Op (Etype (Etype (Obj)),
5896 Name_uDisp_Get_Prim_Op_Kind),
5898 Parameter_Associations =>
5900 New_Copy_Tree (Obj),
5901 New_Reference_To (S, Loc),
5902 New_Reference_To (C, Loc))));
5905 -- if C = POK_Procedure_Entry then
5907 -- elsif C = POK_Task_Entry then
5913 Append_To (Conc_Typ_Stmts,
5914 Make_If_Statement (Loc,
5918 New_Reference_To (C, Loc),
5920 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
5927 Make_Elsif_Part (Loc,
5931 New_Reference_To (C, Loc),
5933 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
5942 -- <dispatching-call>;
5943 -- <triggering-statements>
5945 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
5946 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
5949 -- if K = Ada.Tags.TK_Limited_Tagged then
5956 Make_If_Statement (Loc,
5960 New_Reference_To (K, Loc),
5962 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
5971 Make_Block_Statement (Loc,
5974 Handled_Statement_Sequence =>
5975 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5980 -- Delay triggering statement processing
5983 -- Add a Delay_Block object to the parameter list of the delay
5984 -- procedure to form the parameter list of the Wait entry call.
5987 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
5989 Pdef := Entity (Name (Ecall));
5991 if Is_RTE (Pdef, RO_CA_Delay_For) then
5993 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
5995 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
5997 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
5999 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6000 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6003 Append_To (Parameter_Associations (Ecall),
6004 Make_Attribute_Reference (Loc,
6005 Prefix => New_Reference_To (Dblock_Ent, Loc),
6006 Attribute_Name => Name_Unchecked_Access));
6008 -- Create the inner block to protect the abortable part
6011 Make_Implicit_Exception_Handler (Loc,
6012 Exception_Choices =>
6013 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6014 Statements => New_List (
6015 Make_Procedure_Call_Statement (Loc,
6016 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6019 Make_Procedure_Call_Statement (Loc,
6020 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6023 Make_Block_Statement (Loc,
6024 Identifier => New_Reference_To (Blk_Ent, Loc),
6025 Handled_Statement_Sequence =>
6026 Make_Handled_Sequence_Of_Statements (Loc,
6027 Statements => Astats),
6028 Has_Created_Identifier => True,
6029 Is_Asynchronous_Call_Block => True);
6031 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6034 Make_Implicit_If_Statement (N,
6035 Condition => Make_Function_Call (Loc,
6036 Name => Enqueue_Call,
6037 Parameter_Associations => Parameter_Associations (Ecall)),
6039 New_List (Make_Block_Statement (Loc,
6040 Handled_Statement_Sequence =>
6041 Make_Handled_Sequence_Of_Statements (Loc,
6042 Statements => New_List (
6043 Make_Implicit_Label_Declaration (Loc,
6044 Defining_Identifier => Blk_Ent,
6045 Label_Construct => Abortable_Block),
6047 Exception_Handlers => Hdle)))));
6049 Stmts := New_List (Ecall);
6051 -- Construct statement sequence for new block
6054 Make_Implicit_If_Statement (N,
6055 Condition => Make_Function_Call (Loc,
6056 Name => New_Reference_To (
6057 RTE (RE_Timed_Out), Loc),
6058 Parameter_Associations => New_List (
6059 Make_Attribute_Reference (Loc,
6060 Prefix => New_Reference_To (Dblock_Ent, Loc),
6061 Attribute_Name => Name_Unchecked_Access))),
6062 Then_Statements => Tstats));
6064 -- The result is the new block
6066 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6069 Make_Block_Statement (Loc,
6070 Declarations => New_List (
6071 Make_Object_Declaration (Loc,
6072 Defining_Identifier => Dblock_Ent,
6073 Aliased_Present => True,
6074 Object_Definition => New_Reference_To (
6075 RTE (RE_Delay_Block), Loc))),
6077 Handled_Statement_Sequence =>
6078 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6088 Extract_Entry (Ecall, Concval, Ename, Index);
6089 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6091 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6092 Decls := Declarations (Ecall);
6094 if Is_Protected_Type (Etype (Concval)) then
6096 -- Get the declarations of the block expanded from the entry call
6098 Decl := First (Decls);
6099 while Present (Decl)
6101 (Nkind (Decl) /= N_Object_Declaration
6102 or else not Is_RTE (Etype (Object_Definition (Decl)),
6103 RE_Communication_Block))
6108 pragma Assert (Present (Decl));
6109 Cancel_Param := Defining_Identifier (Decl);
6111 -- Change the mode of the Protected_Entry_Call call
6113 -- Protected_Entry_Call (
6114 -- Object => po._object'Access,
6115 -- E => <entry index>;
6116 -- Uninterpreted_Data => P'Address;
6117 -- Mode => Asynchronous_Call;
6120 Stmt := First (Stmts);
6122 -- Skip assignments to temporaries created for in-out parameters
6124 -- This makes unwarranted assumptions about the shape of the expanded
6125 -- tree for the call, and should be cleaned up ???
6127 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6133 Param := First (Parameter_Associations (Call));
6134 while Present (Param)
6135 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6140 pragma Assert (Present (Param));
6141 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6144 -- Append an if statement to execute the abortable part
6147 -- if Enqueued (Bnn) then
6150 Make_Implicit_If_Statement (N,
6151 Condition => Make_Function_Call (Loc,
6152 Name => New_Reference_To (
6153 RTE (RE_Enqueued), Loc),
6154 Parameter_Associations => New_List (
6155 New_Reference_To (Cancel_Param, Loc))),
6156 Then_Statements => Astats));
6159 Make_Block_Statement (Loc,
6160 Identifier => New_Reference_To (Blk_Ent, Loc),
6161 Handled_Statement_Sequence =>
6162 Make_Handled_Sequence_Of_Statements (Loc,
6163 Statements => Stmts),
6164 Has_Created_Identifier => True,
6165 Is_Asynchronous_Call_Block => True);
6167 -- For the VM call Update_Exception instead of Abort_Undefer.
6168 -- See 4jexcept.ads for an explanation.
6170 if VM_Target = No_VM then
6171 Target_Undefer := RE_Abort_Undefer;
6173 Target_Undefer := RE_Update_Exception;
6175 New_List (Make_Function_Call (Loc,
6176 Name => New_Occurrence_Of
6177 (RTE (RE_Current_Target_Exception), Loc)));
6181 Make_Block_Statement (Loc,
6182 Handled_Statement_Sequence =>
6183 Make_Handled_Sequence_Of_Statements (Loc,
6184 Statements => New_List (
6185 Make_Implicit_Label_Declaration (Loc,
6186 Defining_Identifier => Blk_Ent,
6187 Label_Construct => Abortable_Block),
6192 Exception_Handlers => New_List (
6193 Make_Implicit_Exception_Handler (Loc,
6195 -- when Abort_Signal =>
6196 -- Abort_Undefer.all;
6198 Exception_Choices =>
6199 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6200 Statements => New_List (
6201 Make_Procedure_Call_Statement (Loc,
6202 Name => New_Reference_To (
6203 RTE (Target_Undefer), Loc),
6204 Parameter_Associations => Undefer_Args)))))),
6206 -- if not Cancelled (Bnn) then
6207 -- triggered statements
6210 Make_Implicit_If_Statement (N,
6211 Condition => Make_Op_Not (Loc,
6213 Make_Function_Call (Loc,
6214 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6215 Parameter_Associations => New_List (
6216 New_Occurrence_Of (Cancel_Param, Loc)))),
6217 Then_Statements => Tstats));
6219 -- Asynchronous task entry call
6226 B := Make_Defining_Identifier (Loc, Name_uB);
6228 -- Insert declaration of B in declarations of existing block
6231 Make_Object_Declaration (Loc,
6232 Defining_Identifier => B,
6233 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6235 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6237 -- Insert declaration of C in declarations of existing block
6240 Make_Object_Declaration (Loc,
6241 Defining_Identifier => Cancel_Param,
6242 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6244 -- Remove and save the call to Call_Simple
6246 Stmt := First (Stmts);
6248 -- Skip assignments to temporaries created for in-out parameters.
6249 -- This makes unwarranted assumptions about the shape of the expanded
6250 -- tree for the call, and should be cleaned up ???
6252 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6258 -- Create the inner block to protect the abortable part
6261 Make_Implicit_Exception_Handler (Loc,
6262 Exception_Choices =>
6263 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6266 Make_Procedure_Call_Statement (Loc,
6267 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6270 Make_Procedure_Call_Statement (Loc,
6271 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6274 Make_Block_Statement (Loc,
6275 Identifier => New_Reference_To (Blk_Ent, Loc),
6276 Handled_Statement_Sequence =>
6277 Make_Handled_Sequence_Of_Statements (Loc,
6278 Statements => Astats),
6279 Has_Created_Identifier => True,
6280 Is_Asynchronous_Call_Block => True);
6283 Make_Block_Statement (Loc,
6284 Handled_Statement_Sequence =>
6285 Make_Handled_Sequence_Of_Statements (Loc,
6286 Statements => New_List (
6287 Make_Implicit_Label_Declaration (Loc,
6288 Defining_Identifier =>
6293 Exception_Handlers => Hdle)));
6295 -- Create new call statement
6297 Params := Parameter_Associations (Call);
6300 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6302 New_Reference_To (B, Loc));
6305 Make_Procedure_Call_Statement (Loc,
6307 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6308 Parameter_Associations => Params));
6310 -- Construct statement sequence for new block
6313 Make_Implicit_If_Statement (N,
6316 New_Reference_To (Cancel_Param, Loc)),
6317 Then_Statements => Tstats));
6319 -- Protected the call against abort
6322 Make_Procedure_Call_Statement (Loc,
6323 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6324 Parameter_Associations => Empty_List));
6327 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6329 -- The result is the new block
6332 Make_Block_Statement (Loc,
6333 Declarations => Decls,
6334 Handled_Statement_Sequence =>
6335 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6338 end Expand_N_Asynchronous_Select;
6340 -------------------------------------
6341 -- Expand_N_Conditional_Entry_Call --
6342 -------------------------------------
6344 -- The conditional task entry call is converted to a call to
6349 -- P : parms := (parm, parm, parm);
6353 -- (<acceptor-task>, -- Acceptor
6354 -- <entry-index>, -- E
6355 -- P'Address, -- Uninterpreted_Data
6356 -- Conditional_Call, -- Mode
6357 -- B); -- Rendezvous_Successful
6362 -- normal-statements
6368 -- For a description of the use of P and the assignments after the call,
6369 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6370 -- conditional entry call has already been expanded (by the Expand_N_Entry
6371 -- _Call_Statement procedure) as follows:
6374 -- P : parms := (parm, parm, parm);
6376 -- ... info for in-out parameters
6377 -- Call_Simple (acceptor-task, entry-index, P'Address);
6383 -- so the task at hand is to convert the latter expansion into the former
6385 -- The conditional protected entry call is converted to a call to
6386 -- Protected_Entry_Call:
6389 -- P : parms := (parm, parm, parm);
6390 -- Bnn : Communications_Block;
6393 -- Protected_Entry_Call
6394 -- (po._object'Access, -- Object
6395 -- <entry index>, -- E
6396 -- P'Address, -- Uninterpreted_Data
6397 -- Conditional_Call, -- Mode
6402 -- if Cancelled (Bnn) then
6405 -- normal-statements
6409 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6413 -- B : Boolean := False;
6414 -- C : Ada.Tags.Prim_Op_Kind;
6415 -- K : Ada.Tags.Tagged_Kind :=
6416 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6417 -- P : Parameters := (Param1 .. ParamN);
6421 -- if K = Ada.Tags.TK_Limited_Tagged then
6422 -- <dispatching-call>;
6423 -- <triggering-statements>
6427 -- Ada.Tags.Get_Offset_Index
6428 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6430 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6432 -- if C = POK_Protected_Entry
6433 -- or else C = POK_Task_Entry
6435 -- Param1 := P.Param1;
6437 -- ParamN := P.ParamN;
6441 -- if C = POK_Procedure
6442 -- or else C = POK_Protected_Procedure
6443 -- or else C = POK_Task_Procedure
6445 -- <dispatching-call>;
6448 -- <triggering-statements>
6450 -- <else-statements>
6455 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6456 Loc : constant Source_Ptr := Sloc (N);
6457 Alt : constant Node_Id := Entry_Call_Alternative (N);
6458 Blk : Node_Id := Entry_Call_Statement (Alt);
6461 Blk_Typ : Entity_Id;
6463 Call_Ent : Entity_Id;
6464 Conc_Typ_Stmts : List_Id;
6468 Lim_Typ_Stmts : List_Id;
6475 Transient_Blk : Node_Id;
6478 B : Entity_Id; -- Call status flag
6479 C : Entity_Id; -- Call kind
6480 K : Entity_Id; -- Tagged kind
6481 P : Entity_Id; -- Parameter block
6482 S : Entity_Id; -- Primitive operation slot
6485 if Ada_Version >= Ada_05
6486 and then Nkind (Blk) = N_Procedure_Call_Statement
6488 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6493 -- Call status flag processing, generate:
6494 -- B : Boolean := False;
6496 B := Build_B (Loc, Decls);
6498 -- Call kind processing, generate:
6499 -- C : Ada.Tags.Prim_Op_Kind;
6501 C := Build_C (Loc, Decls);
6503 -- Tagged kind processing, generate:
6504 -- K : Ada.Tags.Tagged_Kind :=
6505 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6507 K := Build_K (Loc, Decls, Obj);
6509 -- Parameter block processing
6511 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6512 P := Parameter_Block_Pack
6513 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6515 -- Dispatch table slot processing, generate:
6518 S := Build_S (Loc, Decls);
6521 -- S := Ada.Tags.Get_Offset_Index
6522 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6525 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6528 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6530 Append_To (Conc_Typ_Stmts,
6531 Make_Procedure_Call_Statement (Loc,
6534 Find_Prim_Op (Etype (Etype (Obj)),
6535 Name_uDisp_Conditional_Select),
6537 Parameter_Associations =>
6539 New_Copy_Tree (Obj), -- <object>
6540 New_Reference_To (S, Loc), -- S
6541 Make_Attribute_Reference (Loc, -- P'Address
6543 New_Reference_To (P, Loc),
6546 New_Reference_To (C, Loc), -- C
6547 New_Reference_To (B, Loc)))); -- B
6550 -- if C = POK_Protected_Entry
6551 -- or else C = POK_Task_Entry
6553 -- Param1 := P.Param1;
6555 -- ParamN := P.ParamN;
6558 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6560 -- Generate the if statement only when the packed parameters need
6561 -- explicit assignments to their corresponding actuals.
6563 if Present (Unpack) then
6564 Append_To (Conc_Typ_Stmts,
6565 Make_If_Statement (Loc,
6572 New_Reference_To (C, Loc),
6574 New_Reference_To (RTE (
6575 RE_POK_Protected_Entry), Loc)),
6579 New_Reference_To (C, Loc),
6581 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6589 -- if C = POK_Procedure
6590 -- or else C = POK_Protected_Procedure
6591 -- or else C = POK_Task_Procedure
6593 -- <dispatching-call>
6595 -- <normal-statements>
6597 -- <else-statements>
6600 N_Stats := New_Copy_List_Tree (Statements (Alt));
6602 Prepend_To (N_Stats,
6603 Make_If_Statement (Loc,
6609 New_Reference_To (C, Loc),
6611 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6618 New_Reference_To (C, Loc),
6620 New_Reference_To (RTE (
6621 RE_POK_Protected_Procedure), Loc)),
6626 New_Reference_To (C, Loc),
6628 New_Reference_To (RTE (
6629 RE_POK_Task_Procedure), Loc)))),
6634 Append_To (Conc_Typ_Stmts,
6635 Make_If_Statement (Loc,
6636 Condition => New_Reference_To (B, Loc),
6637 Then_Statements => N_Stats,
6638 Else_Statements => Else_Statements (N)));
6641 -- <dispatching-call>;
6642 -- <triggering-statements>
6644 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6645 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6648 -- if K = Ada.Tags.TK_Limited_Tagged then
6655 Make_If_Statement (Loc,
6659 New_Reference_To (K, Loc),
6661 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6670 Make_Block_Statement (Loc,
6673 Handled_Statement_Sequence =>
6674 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6676 -- As described above, The entry alternative is transformed into a
6677 -- block that contains the gnulli call, and possibly assignment
6678 -- statements for in-out parameters. The gnulli call may itself be
6679 -- rewritten into a transient block if some unconstrained parameters
6680 -- require it. We need to retrieve the call to complete its parameter
6685 First_Real_Statement (Handled_Statement_Sequence (Blk));
6687 if Present (Transient_Blk)
6688 and then Nkind (Transient_Blk) = N_Block_Statement
6690 Blk := Transient_Blk;
6693 Stmts := Statements (Handled_Statement_Sequence (Blk));
6694 Stmt := First (Stmts);
6695 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6700 Params := Parameter_Associations (Call);
6702 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6704 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6706 Param := First (Params);
6707 while Present (Param)
6708 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6713 pragma Assert (Present (Param));
6714 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6718 -- Find the Communication_Block parameter for the call to the
6719 -- Cancelled function.
6721 Decl := First (Declarations (Blk));
6722 while Present (Decl)
6723 and then not Is_RTE (Etype (Object_Definition (Decl)),
6724 RE_Communication_Block)
6729 -- Add an if statement to execute the else part if the call
6730 -- does not succeed (as indicated by the Cancelled predicate).
6733 Make_Implicit_If_Statement (N,
6734 Condition => Make_Function_Call (Loc,
6735 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6736 Parameter_Associations => New_List (
6737 New_Reference_To (Defining_Identifier (Decl), Loc))),
6738 Then_Statements => Else_Statements (N),
6739 Else_Statements => Statements (Alt)));
6742 B := Make_Defining_Identifier (Loc, Name_uB);
6744 -- Insert declaration of B in declarations of existing block
6746 if No (Declarations (Blk)) then
6747 Set_Declarations (Blk, New_List);
6750 Prepend_To (Declarations (Blk),
6751 Make_Object_Declaration (Loc,
6752 Defining_Identifier => B,
6753 Object_Definition =>
6754 New_Reference_To (Standard_Boolean, Loc)));
6756 -- Create new call statement
6759 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6760 Append_To (Params, New_Reference_To (B, Loc));
6763 Make_Procedure_Call_Statement (Loc,
6764 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6765 Parameter_Associations => Params));
6767 -- Construct statement sequence for new block
6770 Make_Implicit_If_Statement (N,
6771 Condition => New_Reference_To (B, Loc),
6772 Then_Statements => Statements (Alt),
6773 Else_Statements => Else_Statements (N)));
6776 -- The result is the new block
6779 Make_Block_Statement (Loc,
6780 Declarations => Declarations (Blk),
6781 Handled_Statement_Sequence =>
6782 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6786 end Expand_N_Conditional_Entry_Call;
6788 ---------------------------------------
6789 -- Expand_N_Delay_Relative_Statement --
6790 ---------------------------------------
6792 -- Delay statement is implemented as a procedure call to Delay_For
6793 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6794 -- simple delays imposed by the use of Protected Objects.
6796 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6797 Loc : constant Source_Ptr := Sloc (N);
6800 Make_Procedure_Call_Statement (Loc,
6801 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6802 Parameter_Associations => New_List (Expression (N))));
6804 end Expand_N_Delay_Relative_Statement;
6806 ------------------------------------
6807 -- Expand_N_Delay_Until_Statement --
6808 ------------------------------------
6810 -- Delay Until statement is implemented as a procedure call to
6811 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6813 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6814 Loc : constant Source_Ptr := Sloc (N);
6818 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6819 Typ := RTE (RO_CA_Delay_Until);
6821 Typ := RTE (RO_RT_Delay_Until);
6825 Make_Procedure_Call_Statement (Loc,
6826 Name => New_Reference_To (Typ, Loc),
6827 Parameter_Associations => New_List (Expression (N))));
6830 end Expand_N_Delay_Until_Statement;
6832 -------------------------
6833 -- Expand_N_Entry_Body --
6834 -------------------------
6836 procedure Expand_N_Entry_Body (N : Node_Id) is
6838 -- Associate discriminals with the next protected operation body to be
6841 if Present (Next_Protected_Operation (N)) then
6842 Set_Discriminals (Parent (Current_Scope));
6844 end Expand_N_Entry_Body;
6846 -----------------------------------
6847 -- Expand_N_Entry_Call_Statement --
6848 -----------------------------------
6850 -- An entry call is expanded into GNARLI calls to implement a simple entry
6851 -- call (see Build_Simple_Entry_Call).
6853 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
6859 if No_Run_Time_Mode then
6860 Error_Msg_CRT ("entry call", N);
6864 -- If this entry call is part of an asynchronous select, don't expand it
6865 -- here; it will be expanded with the select statement. Don't expand
6866 -- timed entry calls either, as they are translated into asynchronous
6869 -- ??? This whole approach is questionable; it may be better to go back
6870 -- to allowing the expansion to take place and then attempting to fix it
6871 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6872 -- whether the expanded call is on a task or protected entry.
6874 if (Nkind (Parent (N)) /= N_Triggering_Alternative
6875 or else N /= Triggering_Statement (Parent (N)))
6876 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
6877 or else N /= Entry_Call_Statement (Parent (N))
6878 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
6880 Extract_Entry (N, Concval, Ename, Index);
6881 Build_Simple_Entry_Call (N, Concval, Ename, Index);
6883 end Expand_N_Entry_Call_Statement;
6885 --------------------------------
6886 -- Expand_N_Entry_Declaration --
6887 --------------------------------
6889 -- If there are parameters, then first, each of the formals is marked by
6890 -- setting Is_Entry_Formal. Next a record type is built which is used to
6891 -- hold the parameter values. The name of this record type is entryP where
6892 -- entry is the name of the entry, with an additional corresponding access
6893 -- type called entryPA. The record type has matching components for each
6894 -- formal (the component names are the same as the formal names). For
6895 -- elementary types, the component type matches the formal type. For
6896 -- composite types, an access type is declared (with the name formalA)
6897 -- which designates the formal type, and the type of the component is this
6898 -- access type. Finally the Entry_Component of each formal is set to
6899 -- reference the corresponding record component.
6901 procedure Expand_N_Entry_Declaration (N : Node_Id) is
6902 Loc : constant Source_Ptr := Sloc (N);
6903 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
6904 Components : List_Id;
6907 Last_Decl : Node_Id;
6908 Component : Entity_Id;
6911 Rec_Ent : Entity_Id;
6912 Acc_Ent : Entity_Id;
6915 Formal := First_Formal (Entry_Ent);
6918 -- Most processing is done only if parameters are present
6920 if Present (Formal) then
6921 Components := New_List;
6923 -- Loop through formals
6925 while Present (Formal) loop
6926 Set_Is_Entry_Formal (Formal);
6928 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
6929 Set_Entry_Component (Formal, Component);
6930 Set_Entry_Formal (Component, Formal);
6931 Ftype := Etype (Formal);
6933 -- Declare new access type and then append
6936 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6939 Make_Full_Type_Declaration (Loc,
6940 Defining_Identifier => Ctype,
6942 Make_Access_To_Object_Definition (Loc,
6943 All_Present => True,
6944 Constant_Present => Ekind (Formal) = E_In_Parameter,
6945 Subtype_Indication => New_Reference_To (Ftype, Loc)));
6947 Insert_After (Last_Decl, Decl);
6950 Append_To (Components,
6951 Make_Component_Declaration (Loc,
6952 Defining_Identifier => Component,
6953 Component_Definition =>
6954 Make_Component_Definition (Loc,
6955 Aliased_Present => False,
6956 Subtype_Indication => New_Reference_To (Ctype, Loc))));
6958 Next_Formal_With_Extras (Formal);
6961 -- Create the Entry_Parameter_Record declaration
6964 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
6967 Make_Full_Type_Declaration (Loc,
6968 Defining_Identifier => Rec_Ent,
6970 Make_Record_Definition (Loc,
6972 Make_Component_List (Loc,
6973 Component_Items => Components)));
6975 Insert_After (Last_Decl, Decl);
6978 -- Construct and link in the corresponding access type
6981 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6983 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
6986 Make_Full_Type_Declaration (Loc,
6987 Defining_Identifier => Acc_Ent,
6989 Make_Access_To_Object_Definition (Loc,
6990 All_Present => True,
6991 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
6993 Insert_After (Last_Decl, Decl);
6996 end Expand_N_Entry_Declaration;
6998 -----------------------------
6999 -- Expand_N_Protected_Body --
7000 -----------------------------
7002 -- Protected bodies are expanded to the completion of the subprograms
7003 -- created for the corresponding protected type. These are a protected and
7004 -- unprotected version of each protected subprogram in the object, a
7005 -- function to calculate each entry barrier, and a procedure to execute the
7006 -- sequence of statements of each protected entry body. For example, for
7007 -- protected type ptype:
7010 -- (O : System.Address;
7011 -- E : Protected_Entry_Index)
7014 -- <discriminant renamings>
7015 -- <private object renamings>
7017 -- return <barrier expression>;
7020 -- procedure pprocN (_object : in out poV;...) is
7021 -- <discriminant renamings>
7022 -- <private object renamings>
7024 -- <sequence of statements>
7027 -- procedure pprocP (_object : in out poV;...) is
7028 -- procedure _clean is
7031 -- ptypeS (_object, Pn);
7032 -- Unlock (_object._object'Access);
7033 -- Abort_Undefer.all;
7038 -- Lock (_object._object'Access);
7039 -- pprocN (_object;...);
7044 -- function pfuncN (_object : poV;...) return Return_Type is
7045 -- <discriminant renamings>
7046 -- <private object renamings>
7048 -- <sequence of statements>
7051 -- function pfuncP (_object : poV) return Return_Type is
7052 -- procedure _clean is
7054 -- Unlock (_object._object'Access);
7055 -- Abort_Undefer.all;
7060 -- Lock (_object._object'Access);
7061 -- return pfuncN (_object);
7068 -- (O : System.Address;
7069 -- P : System.Address;
7070 -- E : Protected_Entry_Index)
7072 -- <discriminant renamings>
7073 -- <private object renamings>
7074 -- type poVP is access poV;
7075 -- _Object : ptVP := ptVP!(O);
7079 -- <statement sequence>
7080 -- Complete_Entry_Body (_Object._Object);
7082 -- when all others =>
7083 -- Exceptional_Complete_Entry_Body (
7084 -- _Object._Object, Get_GNAT_Exception);
7088 -- The type poV is the record created for the protected type to hold
7089 -- the state of the protected object.
7091 procedure Expand_N_Protected_Body (N : Node_Id) is
7092 Loc : constant Source_Ptr := Sloc (N);
7093 Pid : constant Entity_Id := Corresponding_Spec (N);
7095 Current_Node : Node_Id;
7096 Disp_Op_Body : Node_Id;
7097 New_Op_Body : Node_Id;
7098 Num_Entries : Natural := 0;
7103 Chain : Entity_Id := Empty;
7104 -- Finalization chain that may be attached to new body
7106 function Build_Dispatching_Subprogram_Body
7109 Prot_Bod : Node_Id) return Node_Id;
7110 -- Build a dispatching version of the protected subprogram body. The
7111 -- newly generated subprogram contains a call to the original protected
7112 -- body. The following code is generated:
7114 -- function <protected-function-name> (Param1 .. ParamN) return
7117 -- return <protected-function-name>P (Param1 .. ParamN);
7118 -- end <protected-function-name>;
7122 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7124 -- <protected-procedure-name>P (Param1 .. ParamN);
7125 -- end <protected-procedure-name>
7127 ---------------------------------------
7128 -- Build_Dispatching_Subprogram_Body --
7129 ---------------------------------------
7131 function Build_Dispatching_Subprogram_Body
7134 Prot_Bod : Node_Id) return Node_Id
7136 Loc : constant Source_Ptr := Sloc (N);
7143 -- Generate a specification without a letter suffix in order to
7144 -- override an interface function or procedure.
7147 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7149 -- The formal parameters become the actuals of the protected
7150 -- function or procedure call.
7152 Actuals := New_List;
7153 Formal := First (Parameter_Specifications (Spec));
7154 while Present (Formal) loop
7156 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7161 if Nkind (Spec) = N_Procedure_Specification then
7164 Make_Procedure_Call_Statement (Loc,
7166 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7167 Parameter_Associations => Actuals));
7169 pragma Assert (Nkind (Spec) = N_Function_Specification);
7173 Make_Simple_Return_Statement (Loc,
7175 Make_Function_Call (Loc,
7177 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7178 Parameter_Associations => Actuals)));
7182 Make_Subprogram_Body (Loc,
7183 Declarations => Empty_List,
7184 Specification => Spec,
7185 Handled_Statement_Sequence =>
7186 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7187 end Build_Dispatching_Subprogram_Body;
7189 -- Start of processing for Expand_N_Protected_Body
7192 if No_Run_Time_Mode then
7193 Error_Msg_CRT ("protected body", N);
7197 -- This is the proper body corresponding to a stub. The declarations
7198 -- must be inserted at the point of the stub, which in turn is in the
7199 -- declarative part of the parent unit.
7201 if Nkind (Parent (N)) = N_Subunit then
7202 Current_Node := Corresponding_Stub (Parent (N));
7207 Op_Body := First (Declarations (N));
7209 -- The protected body is replaced with the bodies of its
7210 -- protected operations, and the declarations for internal objects
7211 -- that may have been created for entry family bounds.
7213 Rewrite (N, Make_Null_Statement (Sloc (N)));
7216 while Present (Op_Body) loop
7217 case Nkind (Op_Body) is
7218 when N_Subprogram_Declaration =>
7221 when N_Subprogram_Body =>
7223 -- Exclude functions created to analyze defaults
7225 if not Is_Eliminated (Defining_Entity (Op_Body))
7226 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7229 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7231 -- Propagate the finalization chain to the new body.
7232 -- In the unlikely event that the subprogram contains a
7233 -- declaration or allocator for an object that requires
7234 -- finalization, the corresponding chain is created when
7235 -- analyzing the body, and attached to its entity. This
7236 -- entity is not further elaborated, and so the chain
7237 -- properly belongs to the newly created subprogram body.
7240 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7242 if Present (Chain) then
7243 Set_Finalization_Chain_Entity
7244 (Protected_Body_Subprogram
7245 (Corresponding_Spec (Op_Body)), Chain);
7247 (Handled_Statement_Sequence (New_Op_Body), False);
7250 Insert_After (Current_Node, New_Op_Body);
7251 Current_Node := New_Op_Body;
7252 Analyze (New_Op_Body);
7254 -- Build the corresponding protected operation. It may
7255 -- appear that this is needed only if this is a visible
7256 -- operation of the type, or if it is an interrupt handler,
7257 -- and this was the strategy used previously in GNAT.
7258 -- However, the operation may be exported through a
7259 -- 'Access to an external caller. This is the common idiom
7260 -- in code that uses the Ada 2005 Timing_Events package
7261 -- As a result we need to produce the protected body for
7262 -- both visible and private operations.
7264 if Present (Corresponding_Spec (Op_Body)) then
7266 Unit_Declaration_Node (Corresponding_Spec (Op_Body));
7268 if Nkind (Parent (Op_Decl)) =
7269 N_Protected_Definition
7272 Build_Protected_Subprogram_Body (
7273 Op_Body, Pid, Specification (New_Op_Body));
7275 Insert_After (Current_Node, New_Op_Body);
7276 Analyze (New_Op_Body);
7278 Current_Node := New_Op_Body;
7280 -- Generate an overriding primitive operation body for
7281 -- this subprogram if the protected type implements
7284 if Ada_Version >= Ada_05
7285 and then Present (Interfaces (
7286 Corresponding_Record_Type (Pid)))
7289 Build_Dispatching_Subprogram_Body (
7290 Op_Body, Pid, New_Op_Body);
7292 Insert_After (Current_Node, Disp_Op_Body);
7293 Analyze (Disp_Op_Body);
7295 Current_Node := Disp_Op_Body;
7301 when N_Entry_Body =>
7302 Op_Id := Defining_Identifier (Op_Body);
7303 Num_Entries := Num_Entries + 1;
7305 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7307 Insert_After (Current_Node, New_Op_Body);
7308 Current_Node := New_Op_Body;
7309 Analyze (New_Op_Body);
7311 when N_Implicit_Label_Declaration =>
7314 when N_Itype_Reference =>
7315 Insert_After (Current_Node, New_Copy (Op_Body));
7317 when N_Freeze_Entity =>
7318 New_Op_Body := New_Copy (Op_Body);
7320 if Present (Entity (Op_Body))
7321 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7323 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7326 Insert_After (Current_Node, New_Op_Body);
7327 Current_Node := New_Op_Body;
7328 Analyze (New_Op_Body);
7331 New_Op_Body := New_Copy (Op_Body);
7332 Insert_After (Current_Node, New_Op_Body);
7333 Current_Node := New_Op_Body;
7334 Analyze (New_Op_Body);
7336 when N_Object_Declaration =>
7337 pragma Assert (not Comes_From_Source (Op_Body));
7338 New_Op_Body := New_Copy (Op_Body);
7339 Insert_After (Current_Node, New_Op_Body);
7340 Current_Node := New_Op_Body;
7341 Analyze (New_Op_Body);
7344 raise Program_Error;
7351 -- Finally, create the body of the function that maps an entry index
7352 -- into the corresponding body index, except when there is no entry,
7353 -- or in a ravenscar-like profile.
7355 if Corresponding_Runtime_Package (Pid) =
7356 System_Tasking_Protected_Objects_Entries
7358 New_Op_Body := Build_Find_Body_Index (Pid);
7359 Insert_After (Current_Node, New_Op_Body);
7360 Current_Node := New_Op_Body;
7361 Analyze (New_Op_Body);
7364 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7365 -- protected body. At this point all wrapper specs have been created,
7366 -- frozen and included in the dispatch table for the protected type.
7368 if Ada_Version >= Ada_05 then
7369 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7371 end Expand_N_Protected_Body;
7373 -----------------------------------------
7374 -- Expand_N_Protected_Type_Declaration --
7375 -----------------------------------------
7377 -- First we create a corresponding record type declaration used to
7378 -- represent values of this protected type.
7379 -- The general form of this type declaration is
7381 -- type poV (discriminants) is record
7382 -- _Object : aliased <kind>Protection
7383 -- [(<entry count> [, <handler count>])];
7384 -- [entry_family : array (bounds) of Void;]
7385 -- <private data fields>
7388 -- The discriminants are present only if the corresponding protected type
7389 -- has discriminants, and they exactly mirror the protected type
7390 -- discriminants. The private data fields similarly mirror the private
7391 -- declarations of the protected type.
7393 -- The Object field is always present. It contains RTS specific data used
7394 -- to control the protected object. It is declared as Aliased so that it
7395 -- can be passed as a pointer to the RTS. This allows the protected record
7396 -- to be referenced within RTS data structures. An appropriate Protection
7397 -- type and discriminant are generated.
7399 -- The Service field is present for protected objects with entries. It
7400 -- contains sufficient information to allow the entry service procedure for
7401 -- this object to be called when the object is not known till runtime.
7403 -- One entry_family component is present for each entry family in the
7404 -- task definition (see Expand_N_Task_Type_Declaration).
7406 -- When a protected object is declared, an instance of the protected type
7407 -- value record is created. The elaboration of this declaration creates the
7408 -- correct bounds for the entry families, and also evaluates the priority
7409 -- expression if needed. The initialization routine for the protected type
7410 -- itself then calls Initialize_Protection with appropriate parameters to
7411 -- initialize the value of the Task_Id field. Install_Handlers may be also
7412 -- called if a pragma Attach_Handler applies.
7414 -- Note: this record is passed to the subprograms created by the expansion
7415 -- of protected subprograms and entries. It is an in parameter to protected
7416 -- functions and an in out parameter to procedures and entry bodies. The
7417 -- Entity_Id for this created record type is placed in the
7418 -- Corresponding_Record_Type field of the associated protected type entity.
7420 -- Next we create a procedure specifications for protected subprograms and
7421 -- entry bodies. For each protected subprograms two subprograms are
7422 -- created, an unprotected and a protected version. The unprotected version
7423 -- is called from within other operations of the same protected object.
7425 -- We also build the call to register the procedure if a pragma
7426 -- Interrupt_Handler applies.
7428 -- A single subprogram is created to service all entry bodies; it has an
7429 -- additional boolean out parameter indicating that the previous entry call
7430 -- made by the current task was serviced immediately, i.e. not by proxy.
7431 -- The O parameter contains a pointer to a record object of the type
7432 -- described above. An untyped interface is used here to allow this
7433 -- procedure to be called in places where the type of the object to be
7434 -- serviced is not known. This must be done, for example, when a call that
7435 -- may have been requeued is cancelled; the corresponding object must be
7436 -- serviced, but which object that is not known till runtime.
7439 -- (O : System.Address; P : out Boolean);
7440 -- procedure pprocN (_object : in out poV);
7441 -- procedure pproc (_object : in out poV);
7442 -- function pfuncN (_object : poV);
7443 -- function pfunc (_object : poV);
7446 -- Note that this must come after the record type declaration, since
7447 -- the specs refer to this type.
7449 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7450 Loc : constant Source_Ptr := Sloc (N);
7451 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7453 Pdef : constant Node_Id := Protected_Definition (N);
7454 -- This contains two lists; one for visible and one for private decls
7458 Discr_Map : constant Elist_Id := New_Elmt_List;
7462 Comp_Id : Entity_Id;
7464 Current_Node : Node_Id := N;
7465 Bdef : Entity_Id := Empty; -- avoid uninit warning
7466 Edef : Entity_Id := Empty; -- avoid uninit warning
7467 Entries_Aggr : Node_Id;
7468 Body_Id : Entity_Id;
7471 Object_Comp : Node_Id;
7473 procedure Check_Inlining (Subp : Entity_Id);
7474 -- If the original operation has a pragma Inline, propagate the flag
7475 -- to the internal body, for possible inlining later on. The source
7476 -- operation is invisible to the back-end and is never actually called.
7478 procedure Register_Handler;
7479 -- For a protected operation that is an interrupt handler, add the
7480 -- freeze action that will register it as such.
7482 --------------------
7483 -- Check_Inlining --
7484 --------------------
7486 procedure Check_Inlining (Subp : Entity_Id) is
7488 if Is_Inlined (Subp) then
7489 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7490 Set_Is_Inlined (Subp, False);
7494 ----------------------
7495 -- Register_Handler --
7496 ----------------------
7498 procedure Register_Handler is
7500 -- All semantic checks already done in Sem_Prag
7502 Prot_Proc : constant Entity_Id :=
7504 (Specification (Current_Node));
7506 Proc_Address : constant Node_Id :=
7507 Make_Attribute_Reference (Loc,
7508 Prefix => New_Reference_To (Prot_Proc, Loc),
7509 Attribute_Name => Name_Address);
7511 RTS_Call : constant Entity_Id :=
7512 Make_Procedure_Call_Statement (Loc,
7515 RTE (RE_Register_Interrupt_Handler), Loc),
7516 Parameter_Associations =>
7517 New_List (Proc_Address));
7519 Append_Freeze_Action (Prot_Proc, RTS_Call);
7520 end Register_Handler;
7522 -- Start of processing for Expand_N_Protected_Type_Declaration
7525 if Present (Corresponding_Record_Type (Prot_Typ)) then
7528 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7531 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7533 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7534 -- of implemented interfaces.
7536 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
7538 Qualify_Entity_Names (N);
7540 -- If the type has discriminants, their occurrences in the declaration
7541 -- have been replaced by the corresponding discriminals. For components
7542 -- that are constrained by discriminants, their homologues in the
7543 -- corresponding record type must refer to the discriminants of that
7544 -- record, so we must apply a new renaming to subtypes_indications:
7546 -- protected discriminant => discriminal => record discriminant
7548 -- This replacement is not applied to default expressions, for which
7549 -- the discriminal is correct.
7551 if Has_Discriminants (Prot_Typ) then
7557 Disc := First_Discriminant (Prot_Typ);
7558 Decl := First (Discriminant_Specifications (Rec_Decl));
7559 while Present (Disc) loop
7560 Append_Elmt (Discriminal (Disc), Discr_Map);
7561 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7562 Next_Discriminant (Disc);
7568 -- Fill in the component declarations
7570 -- Add components for entry families. For each entry family, create an
7571 -- anonymous type declaration with the same size, and analyze the type.
7573 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7575 -- Prepend the _Object field with the right type to the component list.
7576 -- We need to compute the number of entries, and in some cases the
7577 -- number of Attach_Handler pragmas.
7581 Num_Attach_Handler : Int := 0;
7582 Protection_Subtype : Node_Id;
7583 Entry_Count_Expr : constant Node_Id :=
7584 Build_Entry_Count_Expression
7585 (Prot_Typ, Cdecls, Loc);
7588 -- Could this be simplified using Corresponding_Runtime_Package???
7590 if Has_Attach_Handler (Prot_Typ) then
7591 Ritem := First_Rep_Item (Prot_Typ);
7592 while Present (Ritem) loop
7593 if Nkind (Ritem) = N_Pragma
7594 and then Pragma_Name (Ritem) = Name_Attach_Handler
7596 Num_Attach_Handler := Num_Attach_Handler + 1;
7599 Next_Rep_Item (Ritem);
7602 if Restricted_Profile then
7603 if Has_Entries (Prot_Typ) then
7604 Protection_Subtype :=
7605 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7607 Protection_Subtype :=
7608 New_Reference_To (RTE (RE_Protection), Loc);
7611 Protection_Subtype :=
7612 Make_Subtype_Indication
7616 (RTE (RE_Static_Interrupt_Protection), Loc),
7618 Make_Index_Or_Discriminant_Constraint (
7620 Constraints => New_List (
7622 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7625 elsif Has_Interrupt_Handler (Prot_Typ) then
7626 Protection_Subtype :=
7627 Make_Subtype_Indication (
7629 Subtype_Mark => New_Reference_To
7630 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7632 Make_Index_Or_Discriminant_Constraint (
7634 Constraints => New_List (Entry_Count_Expr)));
7636 -- Type has explicit entries or generated primitive entry wrappers
7638 elsif Has_Entries (Prot_Typ)
7639 or else (Ada_Version >= Ada_05
7640 and then Present (Interface_List (N)))
7642 case Corresponding_Runtime_Package (Prot_Typ) is
7643 when System_Tasking_Protected_Objects_Entries =>
7644 Protection_Subtype :=
7645 Make_Subtype_Indication (Loc,
7647 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7649 Make_Index_Or_Discriminant_Constraint (
7651 Constraints => New_List (Entry_Count_Expr)));
7653 when System_Tasking_Protected_Objects_Single_Entry =>
7654 Protection_Subtype :=
7655 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7658 raise Program_Error;
7662 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7666 Make_Component_Declaration (Loc,
7667 Defining_Identifier =>
7668 Make_Defining_Identifier (Loc, Name_uObject),
7669 Component_Definition =>
7670 Make_Component_Definition (Loc,
7671 Aliased_Present => True,
7672 Subtype_Indication => Protection_Subtype));
7675 pragma Assert (Present (Pdef));
7677 -- Add private field components
7679 if Present (Private_Declarations (Pdef)) then
7680 Priv := First (Private_Declarations (Pdef));
7682 while Present (Priv) loop
7684 if Nkind (Priv) = N_Component_Declaration then
7686 -- The component definition consists of a subtype indication,
7687 -- or (in Ada 2005) an access definition. Make a copy of the
7688 -- proper definition.
7691 Old_Comp : constant Node_Id := Component_Definition (Priv);
7692 Pent : constant Entity_Id := Defining_Identifier (Priv);
7696 if Present (Subtype_Indication (Old_Comp)) then
7698 Make_Component_Definition (Sloc (Pent),
7699 Aliased_Present => False,
7700 Subtype_Indication =>
7701 New_Copy_Tree (Subtype_Indication (Old_Comp),
7705 Make_Component_Definition (Sloc (Pent),
7706 Aliased_Present => False,
7707 Access_Definition =>
7708 New_Copy_Tree (Access_Definition (Old_Comp),
7713 Make_Component_Declaration (Loc,
7714 Defining_Identifier =>
7715 Make_Defining_Identifier (Sloc (Pent), Chars (Pent)),
7716 Component_Definition => New_Comp,
7717 Expression => Expression (Priv));
7719 Append_To (Cdecls, New_Priv);
7722 elsif Nkind (Priv) = N_Subprogram_Declaration then
7724 -- Make the unprotected version of the subprogram available
7725 -- for expansion of intra object calls. There is need for
7726 -- a protected version only if the subprogram is an interrupt
7727 -- handler, otherwise this operation can only be called from
7731 Make_Subprogram_Declaration (Loc,
7733 Build_Protected_Sub_Specification
7734 (Priv, Prot_Typ, Unprotected_Mode));
7736 Insert_After (Current_Node, Sub);
7739 Set_Protected_Body_Subprogram
7740 (Defining_Unit_Name (Specification (Priv)),
7741 Defining_Unit_Name (Specification (Sub)));
7742 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
7743 Current_Node := Sub;
7746 Make_Subprogram_Declaration (Loc,
7748 Build_Protected_Sub_Specification
7749 (Priv, Prot_Typ, Protected_Mode));
7751 Insert_After (Current_Node, Sub);
7753 Current_Node := Sub;
7755 if Is_Interrupt_Handler
7756 (Defining_Unit_Name (Specification (Priv)))
7758 if not Restricted_Profile then
7768 -- Put the _Object component after the private component so that it
7769 -- be finalized early as required by 9.4 (20)
7771 Append_To (Cdecls, Object_Comp);
7773 Insert_After (Current_Node, Rec_Decl);
7774 Current_Node := Rec_Decl;
7776 -- Analyze the record declaration immediately after construction,
7777 -- because the initialization procedure is needed for single object
7778 -- declarations before the next entity is analyzed (the freeze call
7779 -- that generates this initialization procedure is found below).
7781 Analyze (Rec_Decl, Suppress => All_Checks);
7783 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7784 -- the corresponding record is frozen. If any wrappers are generated,
7785 -- Current_Node is updated accordingly.
7787 if Ada_Version >= Ada_05 then
7788 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
7791 -- Collect pointers to entry bodies and their barriers, to be placed
7792 -- in the Entry_Bodies_Array for the type. For each entry/family we
7793 -- add an expression to the aggregate which is the initial value of
7794 -- this array. The array is declared after all protected subprograms.
7796 if Has_Entries (Prot_Typ) then
7797 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
7799 Entries_Aggr := Empty;
7802 -- Build two new procedure specifications for each protected subprogram;
7803 -- one to call from outside the object and one to call from inside.
7804 -- Build a barrier function and an entry body action procedure
7805 -- specification for each protected entry. Initialize the entry body
7806 -- array. If subprogram is flagged as eliminated, do not generate any
7807 -- internal operations.
7811 Comp := First (Visible_Declarations (Pdef));
7813 while Present (Comp) loop
7814 if Nkind (Comp) = N_Subprogram_Declaration
7815 and then not Is_Eliminated (Defining_Entity (Comp))
7818 Make_Subprogram_Declaration (Loc,
7820 Build_Protected_Sub_Specification
7821 (Comp, Prot_Typ, Unprotected_Mode));
7823 Insert_After (Current_Node, Sub);
7826 Set_Protected_Body_Subprogram
7827 (Defining_Unit_Name (Specification (Comp)),
7828 Defining_Unit_Name (Specification (Sub)));
7829 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
7831 -- Make the protected version of the subprogram available for
7832 -- expansion of external calls.
7834 Current_Node := Sub;
7837 Make_Subprogram_Declaration (Loc,
7839 Build_Protected_Sub_Specification
7840 (Comp, Prot_Typ, Protected_Mode));
7842 Insert_After (Current_Node, Sub);
7845 Current_Node := Sub;
7847 -- Generate an overriding primitive operation specification for
7848 -- this subprogram if the protected type implements an interface.
7850 if Ada_Version >= Ada_05
7852 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
7855 Make_Subprogram_Declaration (Loc,
7857 Build_Protected_Sub_Specification
7858 (Comp, Prot_Typ, Dispatching_Mode));
7860 Insert_After (Current_Node, Sub);
7863 Current_Node := Sub;
7866 -- If a pragma Interrupt_Handler applies, build and add a call to
7867 -- Register_Interrupt_Handler to the freezing actions of the
7868 -- protected version (Current_Node) of the subprogram:
7870 -- system.interrupts.register_interrupt_handler
7871 -- (prot_procP'address);
7873 if not Restricted_Profile
7874 and then Is_Interrupt_Handler
7875 (Defining_Unit_Name (Specification (Comp)))
7880 elsif Nkind (Comp) = N_Entry_Declaration then
7881 E_Count := E_Count + 1;
7882 Comp_Id := Defining_Identifier (Comp);
7885 Make_Defining_Identifier (Loc,
7886 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
7888 Make_Subprogram_Declaration (Loc,
7890 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
7892 Insert_After (Current_Node, Sub);
7895 Set_Protected_Body_Subprogram
7896 (Defining_Identifier (Comp),
7897 Defining_Unit_Name (Specification (Sub)));
7899 Current_Node := Sub;
7902 Make_Defining_Identifier (Loc,
7903 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
7905 Make_Subprogram_Declaration (Loc,
7907 Build_Barrier_Function_Specification (Loc, Bdef));
7909 Insert_After (Current_Node, Sub);
7911 Set_Protected_Body_Subprogram (Bdef, Bdef);
7912 Set_Barrier_Function (Comp_Id, Bdef);
7913 Set_Scope (Bdef, Scope (Comp_Id));
7914 Current_Node := Sub;
7916 -- Collect pointers to the protected subprogram and the barrier
7917 -- of the current entry, for insertion into Entry_Bodies_Array.
7920 Make_Aggregate (Loc,
7921 Expressions => New_List (
7922 Make_Attribute_Reference (Loc,
7923 Prefix => New_Reference_To (Bdef, Loc),
7924 Attribute_Name => Name_Unrestricted_Access),
7925 Make_Attribute_Reference (Loc,
7926 Prefix => New_Reference_To (Edef, Loc),
7927 Attribute_Name => Name_Unrestricted_Access))),
7928 Expressions (Entries_Aggr));
7935 -- If there are some private entry declarations, expand it as if they
7936 -- were visible entries.
7938 if Present (Private_Declarations (Pdef)) then
7939 Comp := First (Private_Declarations (Pdef));
7940 while Present (Comp) loop
7941 if Nkind (Comp) = N_Entry_Declaration then
7942 E_Count := E_Count + 1;
7943 Comp_Id := Defining_Identifier (Comp);
7946 Make_Defining_Identifier (Loc,
7947 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
7949 Make_Subprogram_Declaration (Loc,
7951 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
7953 Insert_After (Current_Node, Sub);
7956 Set_Protected_Body_Subprogram
7957 (Defining_Identifier (Comp),
7958 Defining_Unit_Name (Specification (Sub)));
7960 Current_Node := Sub;
7963 Make_Defining_Identifier (Loc,
7964 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
7967 Make_Subprogram_Declaration (Loc,
7969 Build_Barrier_Function_Specification (Loc, Bdef));
7971 Insert_After (Current_Node, Sub);
7973 Set_Protected_Body_Subprogram (Bdef, Bdef);
7974 Set_Barrier_Function (Comp_Id, Bdef);
7975 Set_Scope (Bdef, Scope (Comp_Id));
7976 Current_Node := Sub;
7978 -- Collect pointers to the protected subprogram and the barrier
7979 -- of the current entry, for insertion into Entry_Bodies_Array.
7981 Append_To (Expressions (Entries_Aggr),
7982 Make_Aggregate (Loc,
7983 Expressions => New_List (
7984 Make_Attribute_Reference (Loc,
7985 Prefix => New_Reference_To (Bdef, Loc),
7986 Attribute_Name => Name_Unrestricted_Access),
7987 Make_Attribute_Reference (Loc,
7988 Prefix => New_Reference_To (Edef, Loc),
7989 Attribute_Name => Name_Unrestricted_Access))));
7996 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
7997 -- all protected subprograms have been collected.
7999 if Has_Entries (Prot_Typ) then
8001 Make_Defining_Identifier (Sloc (Prot_Typ),
8002 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8004 case Corresponding_Runtime_Package (Prot_Typ) is
8005 when System_Tasking_Protected_Objects_Entries =>
8006 Body_Arr := Make_Object_Declaration (Loc,
8007 Defining_Identifier => Body_Id,
8008 Aliased_Present => True,
8009 Object_Definition =>
8010 Make_Subtype_Indication (Loc,
8011 Subtype_Mark => New_Reference_To (
8012 RTE (RE_Protected_Entry_Body_Array), Loc),
8014 Make_Index_Or_Discriminant_Constraint (Loc,
8015 Constraints => New_List (
8017 Make_Integer_Literal (Loc, 1),
8018 Make_Integer_Literal (Loc, E_Count))))),
8019 Expression => Entries_Aggr);
8021 when System_Tasking_Protected_Objects_Single_Entry =>
8022 Body_Arr := Make_Object_Declaration (Loc,
8023 Defining_Identifier => Body_Id,
8024 Aliased_Present => True,
8025 Object_Definition => New_Reference_To
8026 (RTE (RE_Entry_Body), Loc),
8028 Make_Aggregate (Loc,
8029 Expressions => New_List (
8030 Make_Attribute_Reference (Loc,
8031 Prefix => New_Reference_To (Bdef, Loc),
8032 Attribute_Name => Name_Unrestricted_Access),
8033 Make_Attribute_Reference (Loc,
8034 Prefix => New_Reference_To (Edef, Loc),
8035 Attribute_Name => Name_Unrestricted_Access))));
8038 raise Program_Error;
8041 -- A pointer to this array will be placed in the corresponding record
8042 -- by its initialization procedure so this needs to be analyzed here.
8044 Insert_After (Current_Node, Body_Arr);
8045 Current_Node := Body_Arr;
8048 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8050 -- Finally, build the function that maps an entry index into the
8051 -- corresponding body. A pointer to this function is placed in each
8052 -- object of the type. Except for a ravenscar-like profile (no abort,
8053 -- no entry queue, 1 entry)
8055 if Corresponding_Runtime_Package (Prot_Typ) =
8056 System_Tasking_Protected_Objects_Entries
8059 Make_Subprogram_Declaration (Loc,
8060 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8061 Insert_After (Current_Node, Sub);
8065 end Expand_N_Protected_Type_Declaration;
8067 --------------------------------
8068 -- Expand_N_Requeue_Statement --
8069 --------------------------------
8071 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8072 -- operations, depending on the source and destination (task or protected
8073 -- object). A dispatching requeue statement is expanded into a call to the
8074 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8075 -- jump around the remainder of processing for the original entry and, if
8076 -- the destination is (different) protected object, to attempt to service
8077 -- it. The following illustrates the various cases:
8080 -- (O : System.Address;
8081 -- P : System.Address;
8082 -- E : Protected_Entry_Index)
8084 -- <discriminant renamings>
8085 -- <private object renamings>
8086 -- type poVP is access poV;
8087 -- _object : ptVP := ptVP!(O);
8091 -- <start of statement sequence for entry>
8093 -- -- Requeue from one protected entry body to another protected
8096 -- Requeue_Protected_Entry (
8097 -- _object._object'Access,
8098 -- new._object'Access,
8103 -- <some more of the statement sequence for entry>
8105 -- -- Requeue from an entry body to a task entry
8107 -- Requeue_Protected_To_Task_Entry (
8113 -- <rest of statement sequence for entry>
8114 -- Complete_Entry_Body (_object._object);
8117 -- when all others =>
8118 -- Exceptional_Complete_Entry_Body (
8119 -- _object._object, Get_GNAT_Exception);
8123 -- Requeue of a task entry call to a task entry
8125 -- Accept_Call (E, Ann);
8126 -- <start of statement sequence for accept statement>
8127 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8129 -- <rest of statement sequence for accept statement>
8131 -- Complete_Rendezvous;
8134 -- when all others =>
8135 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8137 -- Requeue of a task entry call to a protected entry
8139 -- Accept_Call (E, Ann);
8140 -- <start of statement sequence for accept statement>
8141 -- Requeue_Task_To_Protected_Entry (
8142 -- new._object'Access,
8147 -- <rest of statement sequence for accept statement>
8149 -- Complete_Rendezvous;
8152 -- when all others =>
8153 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8155 -- Ada 2005 (AI05-0030): Dispatching requeue from protected to interface
8159 -- (O : System.Address;
8160 -- P : System.Address;
8161 -- E : Protected_Entry_Index)
8163 -- <discriminant renamings>
8164 -- <private object renamings>
8165 -- type poVP is access poV;
8166 -- _object : ptVP := ptVP!(O);
8170 -- <start of statement sequence for entry>
8173 -- (<interface class-wide object>,
8176 -- Ada.Tags.Get_Offset_Index
8178 -- <interface dispatch table index of target entry>),
8182 -- <rest of statement sequence for entry>
8183 -- Complete_Entry_Body (_object._object);
8186 -- when all others =>
8187 -- Exceptional_Complete_Entry_Body (
8188 -- _object._object, Get_GNAT_Exception);
8192 -- Ada 2005 (AI05-0030): Dispatching requeue from task to interface
8195 -- Accept_Call (E, Ann);
8196 -- <start of statement sequence for accept statement>
8198 -- (<interface class-wide object>,
8201 -- Ada.Tags.Get_Offset_Index
8203 -- <interface dispatch table index of target entrt>),
8207 -- <rest of statement sequence for accept statement>
8209 -- Complete_Rendezvous;
8212 -- when all others =>
8213 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8215 -- Further details on these expansions can be found in Expand_N_Protected_
8216 -- Body and Expand_N_Accept_Statement.
8218 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8219 Loc : constant Source_Ptr := Sloc (N);
8220 Abortable : Node_Id;
8222 Conc_Typ : Entity_Id;
8227 New_Param : Node_Id;
8228 Old_Typ : Entity_Id;
8231 RTS_Call : Entity_Id;
8232 Self_Param : Node_Id;
8233 Skip_Stat : Node_Id;
8237 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
8239 -- Extract the components of the entry call
8241 Extract_Entry (N, Concval, Ename, Index);
8242 Conc_Typ := Etype (Concval);
8244 -- Examine the scope stack in order to find nearest enclosing protected
8245 -- or task type. This will constitute our invocation source.
8247 Old_Typ := Current_Scope;
8248 while Present (Old_Typ)
8249 and then not Is_Protected_Type (Old_Typ)
8250 and then not Is_Task_Type (Old_Typ)
8252 Old_Typ := Scope (Old_Typ);
8255 -- Generate the parameter list for all cases. The abortable flag is
8256 -- common among dispatching and regular requeue.
8258 Params := New_List (Abortable);
8260 -- Ada 2005 (AI05-0030): We have a dispatching requeue of the form
8261 -- Concval.Ename where the type of Concval is class-wide concurrent
8264 if Ada_Version >= Ada_05
8265 and then Present (Concval)
8266 and then Is_Class_Wide_Type (Conc_Typ)
8267 and then Is_Concurrent_Interface (Conc_Typ)
8269 RTS_Call := Make_Identifier (Loc, Name_uDisp_Requeue);
8272 -- Ada.Tags.Get_Offset_Index
8273 -- (Ada.Tags.Tag (Concval),
8274 -- <interface dispatch table position of Ename>)
8277 Make_Function_Call (Loc,
8279 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8280 Parameter_Associations =>
8282 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8283 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8285 -- Specific actuals for protected to interface class-wide type
8288 if Is_Protected_Type (Old_Typ) then
8290 Make_Attribute_Reference (Loc, -- _object'Address
8292 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8295 Prepend_To (Params, -- True
8296 New_Reference_To (Standard_True, Loc));
8298 -- Specific actuals for task to interface class-wide type requeue
8301 pragma Assert (Is_Task_Type (Old_Typ));
8303 Prepend_To (Params, -- null
8304 New_Reference_To (RTE (RE_Null_Address), Loc));
8305 Prepend_To (Params, -- False
8306 New_Reference_To (Standard_False, Loc));
8309 -- Finally, add the common object parameter
8311 Prepend_To (Params, New_Copy_Tree (Concval));
8313 -- Regular requeue processing
8316 New_Param := Concurrent_Ref (Concval);
8318 -- The index expression is common among all four cases
8321 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8323 if Is_Protected_Type (Old_Typ) then
8325 Make_Attribute_Reference (Loc,
8327 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8329 Name_Unchecked_Access);
8331 -- Protected to protected requeue
8333 if Is_Protected_Type (Conc_Typ) then
8335 New_Reference_To (RTE (RE_Requeue_Protected_Entry), Loc);
8338 Make_Attribute_Reference (Loc,
8342 Name_Unchecked_Access);
8344 -- Protected to task requeue
8347 pragma Assert (Is_Task_Type (Conc_Typ));
8350 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8353 Prepend (New_Param, Params);
8354 Prepend (Self_Param, Params);
8357 pragma Assert (Is_Task_Type (Old_Typ));
8359 -- Task to protected requeue
8361 if Is_Protected_Type (Conc_Typ) then
8364 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8367 Make_Attribute_Reference (Loc,
8371 Name_Unchecked_Access);
8373 -- Task to task requeue
8376 pragma Assert (Is_Task_Type (Conc_Typ));
8378 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8381 Prepend (New_Param, Params);
8385 -- Create the GNARLI or predefined primitive call
8388 Make_Procedure_Call_Statement (Loc,
8390 Parameter_Associations => Params);
8395 if Is_Protected_Type (Old_Typ) then
8397 -- Build the return statement to skip the rest of the entry body
8399 Skip_Stat := Make_Simple_Return_Statement (Loc);
8402 -- If the requeue is within a task, find the end label of the
8403 -- enclosing accept statement.
8405 Acc_Stat := Parent (N);
8406 while Nkind (Acc_Stat) /= N_Accept_Statement loop
8407 Acc_Stat := Parent (Acc_Stat);
8410 -- The last statement is the second label, used for completing the
8411 -- rendezvous the usual way. The label we are looking for is right
8415 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
8417 pragma Assert (Nkind (Lab_Node) = N_Label);
8419 -- Build the goto statement to skip the rest of the accept
8423 Make_Goto_Statement (Loc,
8424 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
8427 Set_Analyzed (Skip_Stat);
8429 Insert_After (N, Skip_Stat);
8430 end Expand_N_Requeue_Statement;
8432 -------------------------------
8433 -- Expand_N_Selective_Accept --
8434 -------------------------------
8436 procedure Expand_N_Selective_Accept (N : Node_Id) is
8437 Loc : constant Source_Ptr := Sloc (N);
8438 Alts : constant List_Id := Select_Alternatives (N);
8440 -- Note: in the below declarations a lot of new lists are allocated
8441 -- unconditionally which may well not end up being used. That's
8442 -- not a good idea since it wastes space gratuitously ???
8444 Accept_Case : List_Id;
8445 Accept_List : constant List_Id := New_List;
8448 Alt_List : constant List_Id := New_List;
8449 Alt_Stats : List_Id;
8450 Ann : Entity_Id := Empty;
8453 Check_Guard : Boolean := True;
8455 Decls : constant List_Id := New_List;
8456 Stats : constant List_Id := New_List;
8457 Body_List : constant List_Id := New_List;
8458 Trailing_List : constant List_Id := New_List;
8461 Else_Present : Boolean := False;
8462 Terminate_Alt : Node_Id := Empty;
8463 Select_Mode : Node_Id;
8465 Delay_Case : List_Id;
8466 Delay_Count : Integer := 0;
8467 Delay_Val : Entity_Id;
8468 Delay_Index : Entity_Id;
8469 Delay_Min : Entity_Id;
8470 Delay_Num : Int := 1;
8471 Delay_Alt_List : List_Id := New_List;
8472 Delay_List : constant List_Id := New_List;
8476 First_Delay : Boolean := True;
8477 Guard_Open : Entity_Id;
8483 Num_Accept : Nat := 0;
8486 Time_Type : Entity_Id;
8488 Select_Call : Node_Id;
8490 Qnam : constant Entity_Id :=
8491 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
8493 Xnam : constant Entity_Id :=
8494 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
8496 -----------------------
8497 -- Local subprograms --
8498 -----------------------
8500 function Accept_Or_Raise return List_Id;
8501 -- For the rare case where delay alternatives all have guards, and
8502 -- all of them are closed, it is still possible that there were open
8503 -- accept alternatives with no callers. We must reexamine the
8504 -- Accept_List, and execute a selective wait with no else if some
8505 -- accept is open. If none, we raise program_error.
8507 procedure Add_Accept (Alt : Node_Id);
8508 -- Process a single accept statement in a select alternative. Build
8509 -- procedure for body of accept, and add entry to dispatch table with
8510 -- expression for guard, in preparation for call to run time select.
8512 function Make_And_Declare_Label (Num : Int) return Node_Id;
8513 -- Manufacture a label using Num as a serial number and declare it.
8514 -- The declaration is appended to Decls. The label marks the trailing
8515 -- statements of an accept or delay alternative.
8517 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
8518 -- Build call to Selective_Wait runtime routine
8520 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
8521 -- Add code to compare value of delay with previous values, and
8522 -- generate case entry for trailing statements.
8524 procedure Process_Accept_Alternative
8528 -- Add code to call corresponding procedure, and branch to
8529 -- trailing statements, if any.
8531 ---------------------
8532 -- Accept_Or_Raise --
8533 ---------------------
8535 function Accept_Or_Raise return List_Id is
8538 J : constant Entity_Id := Make_Defining_Identifier (Loc,
8539 New_Internal_Name ('J'));
8542 -- We generate the following:
8544 -- for J in q'range loop
8545 -- if q(J).S /=null_task_entry then
8546 -- selective_wait (simple_mode,...);
8552 -- if no rendez_vous then
8553 -- raise program_error;
8556 -- Note that the code needs to know that the selector name
8557 -- in an Accept_Alternative is named S.
8559 Cond := Make_Op_Ne (Loc,
8561 Make_Selected_Component (Loc,
8562 Prefix => Make_Indexed_Component (Loc,
8563 Prefix => New_Reference_To (Qnam, Loc),
8564 Expressions => New_List (New_Reference_To (J, Loc))),
8565 Selector_Name => Make_Identifier (Loc, Name_S)),
8567 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
8570 Make_Implicit_Loop_Statement (N,
8571 Identifier => Empty,
8573 Make_Iteration_Scheme (Loc,
8574 Loop_Parameter_Specification =>
8575 Make_Loop_Parameter_Specification (Loc,
8576 Defining_Identifier => J,
8577 Discrete_Subtype_Definition =>
8578 Make_Attribute_Reference (Loc,
8579 Prefix => New_Reference_To (Qnam, Loc),
8580 Attribute_Name => Name_Range,
8581 Expressions => New_List (
8582 Make_Integer_Literal (Loc, 1))))),
8584 Statements => New_List (
8585 Make_Implicit_If_Statement (N,
8587 Then_Statements => New_List (
8589 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
8590 Make_Exit_Statement (Loc))))));
8593 Make_Raise_Program_Error (Loc,
8594 Condition => Make_Op_Eq (Loc,
8595 Left_Opnd => New_Reference_To (Xnam, Loc),
8597 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8598 Reason => PE_All_Guards_Closed));
8601 end Accept_Or_Raise;
8607 procedure Add_Accept (Alt : Node_Id) is
8608 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
8609 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
8610 Eloc : constant Source_Ptr := Sloc (Ename);
8611 Eent : constant Entity_Id := Entity (Ename);
8612 Index : constant Node_Id := Entry_Index (Acc_Stm);
8613 Null_Body : Node_Id;
8614 Proc_Body : Node_Id;
8621 Ann := Node (Last_Elmt (Accept_Address (Eent)));
8624 if Present (Condition (Alt)) then
8626 Make_Conditional_Expression (Eloc, New_List (
8628 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
8629 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
8632 Entry_Index_Expression
8633 (Eloc, Eent, Index, Scope (Eent));
8636 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8637 Null_Body := New_Reference_To (Standard_False, Eloc);
8639 if Abort_Allowed then
8640 Call := Make_Procedure_Call_Statement (Eloc,
8641 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
8642 Insert_Before (First (Statements (Handled_Statement_Sequence (
8643 Accept_Statement (Alt)))), Call);
8648 Make_Defining_Identifier (Eloc,
8649 New_External_Name (Chars (Ename), 'A', Num_Accept));
8651 if Comes_From_Source (Alt) then
8652 Set_Debug_Info_Needed (PB_Ent);
8656 Make_Subprogram_Body (Eloc,
8658 Make_Procedure_Specification (Eloc,
8659 Defining_Unit_Name => PB_Ent),
8660 Declarations => Declarations (Acc_Stm),
8661 Handled_Statement_Sequence =>
8662 Build_Accept_Body (Accept_Statement (Alt)));
8664 -- During the analysis of the body of the accept statement, any
8665 -- zero cost exception handler records were collected in the
8666 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8667 -- This is where we move them to where they belong, namely the
8668 -- newly created procedure.
8670 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8671 Append (Proc_Body, Body_List);
8674 Null_Body := New_Reference_To (Standard_True, Eloc);
8676 -- if accept statement has declarations, insert above, given that
8677 -- we are not creating a body for the accept.
8679 if Present (Declarations (Acc_Stm)) then
8680 Insert_Actions (N, Declarations (Acc_Stm));
8684 Append_To (Accept_List,
8685 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
8687 Num_Accept := Num_Accept + 1;
8690 ----------------------------
8691 -- Make_And_Declare_Label --
8692 ----------------------------
8694 function Make_And_Declare_Label (Num : Int) return Node_Id is
8698 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8700 Make_Label (Loc, Lab_Id);
8703 Make_Implicit_Label_Declaration (Loc,
8704 Defining_Identifier =>
8705 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8706 Label_Construct => Lab));
8709 end Make_And_Declare_Label;
8711 ----------------------
8712 -- Make_Select_Call --
8713 ----------------------
8715 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8716 Params : constant List_Id := New_List;
8720 Make_Attribute_Reference (Loc,
8721 Prefix => New_Reference_To (Qnam, Loc),
8722 Attribute_Name => Name_Unchecked_Access),
8724 Append (Select_Mode, Params);
8725 Append (New_Reference_To (Ann, Loc), Params);
8726 Append (New_Reference_To (Xnam, Loc), Params);
8729 Make_Procedure_Call_Statement (Loc,
8730 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8731 Parameter_Associations => Params);
8732 end Make_Select_Call;
8734 --------------------------------
8735 -- Process_Accept_Alternative --
8736 --------------------------------
8738 procedure Process_Accept_Alternative
8743 Choices : List_Id := No_List;
8744 Alt_Stats : List_Id;
8747 Adjust_Condition (Condition (Alt));
8748 Alt_Stats := No_List;
8750 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8751 Choices := New_List (
8752 Make_Integer_Literal (Loc, Index));
8754 Alt_Stats := New_List (
8755 Make_Procedure_Call_Statement (Sloc (Proc),
8756 Name => New_Reference_To (
8757 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
8760 if Statements (Alt) /= Empty_List then
8762 if No (Alt_Stats) then
8764 -- Accept with no body, followed by trailing statements
8766 Choices := New_List (
8767 Make_Integer_Literal (Loc, Index));
8769 Alt_Stats := New_List;
8772 -- After the call, if any, branch to trailing statements. We
8773 -- create a label for each, as well as the corresponding label
8776 Lab := Make_And_Declare_Label (Index);
8777 Append_To (Alt_Stats,
8778 Make_Goto_Statement (Loc,
8779 Name => New_Copy (Identifier (Lab))));
8781 Append (Lab, Trailing_List);
8782 Append_List (Statements (Alt), Trailing_List);
8783 Append_To (Trailing_List,
8784 Make_Goto_Statement (Loc,
8785 Name => New_Copy (Identifier (End_Lab))));
8788 if Present (Alt_Stats) then
8790 -- Procedure call. and/or trailing statements
8792 Append_To (Alt_List,
8793 Make_Case_Statement_Alternative (Loc,
8794 Discrete_Choices => Choices,
8795 Statements => Alt_Stats));
8797 end Process_Accept_Alternative;
8799 -------------------------------
8800 -- Process_Delay_Alternative --
8801 -------------------------------
8803 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
8806 Delay_Alt : List_Id;
8809 -- Deal with C/Fortran boolean as delay condition
8811 Adjust_Condition (Condition (Alt));
8813 -- Determine the smallest specified delay
8815 -- for each delay alternative generate:
8817 -- if guard-expression then
8818 -- Delay_Val := delay-expression;
8819 -- Guard_Open := True;
8820 -- if Delay_Val < Delay_Min then
8821 -- Delay_Min := Delay_Val;
8822 -- Delay_Index := Index;
8826 -- The enclosing if-statement is omitted if there is no guard
8831 First_Delay := False;
8833 Delay_Alt := New_List (
8834 Make_Assignment_Statement (Loc,
8835 Name => New_Reference_To (Delay_Min, Loc),
8836 Expression => Expression (Delay_Statement (Alt))));
8838 if Delay_Count > 1 then
8839 Append_To (Delay_Alt,
8840 Make_Assignment_Statement (Loc,
8841 Name => New_Reference_To (Delay_Index, Loc),
8842 Expression => Make_Integer_Literal (Loc, Index)));
8846 Delay_Alt := New_List (
8847 Make_Assignment_Statement (Loc,
8848 Name => New_Reference_To (Delay_Val, Loc),
8849 Expression => Expression (Delay_Statement (Alt))));
8851 if Time_Type = Standard_Duration then
8854 Left_Opnd => New_Reference_To (Delay_Val, Loc),
8855 Right_Opnd => New_Reference_To (Delay_Min, Loc));
8858 -- The scope of the time type must define a comparison
8859 -- operator. The scope itself may not be visible, so we
8860 -- construct a node with entity information to insure that
8861 -- semantic analysis can find the proper operator.
8864 Make_Function_Call (Loc,
8865 Name => Make_Selected_Component (Loc,
8866 Prefix => New_Reference_To (Scope (Time_Type), Loc),
8868 Make_Operator_Symbol (Loc,
8869 Chars => Name_Op_Lt,
8870 Strval => No_String)),
8871 Parameter_Associations =>
8873 New_Reference_To (Delay_Val, Loc),
8874 New_Reference_To (Delay_Min, Loc)));
8876 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
8879 Append_To (Delay_Alt,
8880 Make_Implicit_If_Statement (N,
8882 Then_Statements => New_List (
8883 Make_Assignment_Statement (Loc,
8884 Name => New_Reference_To (Delay_Min, Loc),
8885 Expression => New_Reference_To (Delay_Val, Loc)),
8887 Make_Assignment_Statement (Loc,
8888 Name => New_Reference_To (Delay_Index, Loc),
8889 Expression => Make_Integer_Literal (Loc, Index)))));
8893 Append_To (Delay_Alt,
8894 Make_Assignment_Statement (Loc,
8895 Name => New_Reference_To (Guard_Open, Loc),
8896 Expression => New_Reference_To (Standard_True, Loc)));
8899 if Present (Condition (Alt)) then
8900 Delay_Alt := New_List (
8901 Make_Implicit_If_Statement (N,
8902 Condition => Condition (Alt),
8903 Then_Statements => Delay_Alt));
8906 Append_List (Delay_Alt, Delay_List);
8908 -- If the delay alternative has a statement part, add choice to the
8909 -- case statements for delays.
8911 if Present (Statements (Alt)) then
8913 if Delay_Count = 1 then
8914 Append_List (Statements (Alt), Delay_Alt_List);
8917 Choices := New_List (
8918 Make_Integer_Literal (Loc, Index));
8920 Append_To (Delay_Alt_List,
8921 Make_Case_Statement_Alternative (Loc,
8922 Discrete_Choices => Choices,
8923 Statements => Statements (Alt)));
8926 elsif Delay_Count = 1 then
8928 -- If the single delay has no trailing statements, add a branch
8929 -- to the exit label to the selective wait.
8931 Delay_Alt_List := New_List (
8932 Make_Goto_Statement (Loc,
8933 Name => New_Copy (Identifier (End_Lab))));
8936 end Process_Delay_Alternative;
8938 -- Start of processing for Expand_N_Selective_Accept
8941 -- First insert some declarations before the select. The first is:
8945 -- This variable holds the parameters passed to the accept body. This
8946 -- declaration has already been inserted by the time we get here by
8947 -- a call to Expand_Accept_Declarations made from the semantics when
8948 -- processing the first accept statement contained in the select. We
8949 -- can find this entity as Accept_Address (E), where E is any of the
8950 -- entries references by contained accept statements.
8952 -- The first step is to scan the list of Selective_Accept_Statements
8953 -- to find this entity, and also count the number of accepts, and
8954 -- determine if terminated, delay or else is present:
8958 Alt := First (Alts);
8959 while Present (Alt) loop
8961 if Nkind (Alt) = N_Accept_Alternative then
8964 elsif Nkind (Alt) = N_Delay_Alternative then
8965 Delay_Count := Delay_Count + 1;
8967 -- If the delays are relative delays, the delay expressions have
8968 -- type Standard_Duration. Otherwise they must have some time type
8969 -- recognized by GNAT.
8971 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
8972 Time_Type := Standard_Duration;
8974 Time_Type := Etype (Expression (Delay_Statement (Alt)));
8976 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
8977 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
8982 "& is not a time type (RM 9.6(6))",
8983 Expression (Delay_Statement (Alt)), Time_Type);
8984 Time_Type := Standard_Duration;
8985 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
8989 if No (Condition (Alt)) then
8991 -- This guard will always be open
8993 Check_Guard := False;
8996 elsif Nkind (Alt) = N_Terminate_Alternative then
8997 Adjust_Condition (Condition (Alt));
8998 Terminate_Alt := Alt;
9001 Num_Alts := Num_Alts + 1;
9005 Else_Present := Present (Else_Statements (N));
9007 -- At the same time (see procedure Add_Accept) we build the accept list:
9009 -- Qnn : Accept_List (1 .. num-select) := (
9010 -- (null-body, entry-index),
9011 -- (null-body, entry-index),
9013 -- (null_body, entry-index));
9015 -- In the above declaration, null-body is True if the corresponding
9016 -- accept has no body, and false otherwise. The entry is either the
9017 -- entry index expression if there is no guard, or if a guard is
9018 -- present, then a conditional expression of the form:
9020 -- (if guard then entry-index else Null_Task_Entry)
9022 -- If a guard is statically known to be false, the entry can simply
9023 -- be omitted from the accept list.
9026 Make_Object_Declaration (Loc,
9027 Defining_Identifier => Qnam,
9028 Object_Definition =>
9029 New_Reference_To (RTE (RE_Accept_List), Loc),
9030 Aliased_Present => True,
9033 Make_Qualified_Expression (Loc,
9035 New_Reference_To (RTE (RE_Accept_List), Loc),
9037 Make_Aggregate (Loc, Expressions => Accept_List)));
9041 -- Then we declare the variable that holds the index for the accept
9042 -- that will be selected for service:
9044 -- Xnn : Select_Index;
9047 Make_Object_Declaration (Loc,
9048 Defining_Identifier => Xnam,
9049 Object_Definition =>
9050 New_Reference_To (RTE (RE_Select_Index), Loc),
9052 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9056 -- After this follow procedure declarations for each accept body
9063 -- where the ... are statements from the corresponding procedure body.
9064 -- No parameters are involved, since the parameters are passed via Ann
9065 -- and the parameter references have already been expanded to be direct
9066 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9067 -- any embedded tasking statements (which would normally be illegal in
9068 -- procedures), have been converted to calls to the tasking runtime so
9069 -- there is no problem in putting them into procedures.
9071 -- The original accept statement has been expanded into a block in
9072 -- the same fashion as for simple accepts (see Build_Accept_Body).
9074 -- Note: we don't really need to build these procedures for the case
9075 -- where no delay statement is present, but it is just as easy to
9076 -- build them unconditionally, and not significantly inefficient,
9077 -- since if they are short they will be inlined anyway.
9079 -- The procedure declarations have been assembled in Body_List
9081 -- If delays are present, we must compute the required delay.
9082 -- We first generate the declarations:
9084 -- Delay_Index : Boolean := 0;
9085 -- Delay_Min : Some_Time_Type.Time;
9086 -- Delay_Val : Some_Time_Type.Time;
9088 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9089 -- active delay that is actually chosen as the basis for the possible
9090 -- delay if an immediate rendez-vous is not possible.
9092 -- In the most common case there is a single delay statement, and this
9093 -- is handled specially.
9095 if Delay_Count > 0 then
9097 -- Generate the required declarations
9100 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9102 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9104 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9107 Make_Object_Declaration (Loc,
9108 Defining_Identifier => Delay_Val,
9109 Object_Definition => New_Reference_To (Time_Type, Loc)));
9112 Make_Object_Declaration (Loc,
9113 Defining_Identifier => Delay_Index,
9114 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9115 Expression => Make_Integer_Literal (Loc, 0)));
9118 Make_Object_Declaration (Loc,
9119 Defining_Identifier => Delay_Min,
9120 Object_Definition => New_Reference_To (Time_Type, Loc),
9122 Unchecked_Convert_To (Time_Type,
9123 Make_Attribute_Reference (Loc,
9125 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9126 Attribute_Name => Name_Last))));
9128 -- Create Duration and Delay_Mode objects used for passing a delay
9131 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
9132 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
9138 -- Note that these values are defined in s-osprim.ads and must
9141 -- Relative : constant := 0;
9142 -- Absolute_Calendar : constant := 1;
9143 -- Absolute_RT : constant := 2;
9145 if Time_Type = Standard_Duration then
9146 Discr := Make_Integer_Literal (Loc, 0);
9148 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9149 Discr := Make_Integer_Literal (Loc, 1);
9153 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9154 Discr := Make_Integer_Literal (Loc, 2);
9158 Make_Object_Declaration (Loc,
9159 Defining_Identifier => D,
9160 Object_Definition =>
9161 New_Reference_To (Standard_Duration, Loc)));
9164 Make_Object_Declaration (Loc,
9165 Defining_Identifier => M,
9166 Object_Definition =>
9167 New_Reference_To (Standard_Integer, Loc),
9168 Expression => Discr));
9173 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9176 Make_Object_Declaration (Loc,
9177 Defining_Identifier => Guard_Open,
9178 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9179 Expression => New_Reference_To (Standard_False, Loc)));
9182 -- Delay_Count is zero, don't need M and D set (suppress warning)
9189 if Present (Terminate_Alt) then
9191 -- If the terminate alternative guard is False, use
9192 -- Simple_Mode; otherwise use Terminate_Mode.
9194 if Present (Condition (Terminate_Alt)) then
9195 Select_Mode := Make_Conditional_Expression (Loc,
9196 New_List (Condition (Terminate_Alt),
9197 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9198 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9200 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9203 elsif Else_Present or Delay_Count > 0 then
9204 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9207 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9210 Select_Call := Make_Select_Call (Select_Mode);
9211 Append (Select_Call, Stats);
9213 -- Now generate code to act on the result. There is an entry
9214 -- in this case for each accept statement with a non-null body,
9215 -- followed by a branch to the statements that follow the Accept.
9216 -- In the absence of delay alternatives, we generate:
9219 -- when No_Rendezvous => -- omitted if simple mode
9234 -- Lab0: Else_Statements;
9237 -- Lab1: Trailing_Statements1;
9240 -- Lab2: Trailing_Statements2;
9245 -- Generate label for common exit
9247 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9249 -- First entry is the default case, when no rendezvous is possible
9251 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9253 if Else_Present then
9255 -- If no rendezvous is possible, the else part is executed
9257 Lab := Make_And_Declare_Label (0);
9258 Alt_Stats := New_List (
9259 Make_Goto_Statement (Loc,
9260 Name => New_Copy (Identifier (Lab))));
9262 Append (Lab, Trailing_List);
9263 Append_List (Else_Statements (N), Trailing_List);
9264 Append_To (Trailing_List,
9265 Make_Goto_Statement (Loc,
9266 Name => New_Copy (Identifier (End_Lab))));
9268 Alt_Stats := New_List (
9269 Make_Goto_Statement (Loc,
9270 Name => New_Copy (Identifier (End_Lab))));
9273 Append_To (Alt_List,
9274 Make_Case_Statement_Alternative (Loc,
9275 Discrete_Choices => Choices,
9276 Statements => Alt_Stats));
9278 -- We make use of the fact that Accept_Index is an integer type, and
9279 -- generate successive literals for entries for each accept. Only those
9280 -- for which there is a body or trailing statements get a case entry.
9282 Alt := First (Select_Alternatives (N));
9283 Proc := First (Body_List);
9284 while Present (Alt) loop
9286 if Nkind (Alt) = N_Accept_Alternative then
9287 Process_Accept_Alternative (Alt, Index, Proc);
9291 (Handled_Statement_Sequence (Accept_Statement (Alt)))
9296 elsif Nkind (Alt) = N_Delay_Alternative then
9297 Process_Delay_Alternative (Alt, Delay_Num);
9298 Delay_Num := Delay_Num + 1;
9304 -- An others choice is always added to the main case, as well
9305 -- as the delay case (to satisfy the compiler).
9307 Append_To (Alt_List,
9308 Make_Case_Statement_Alternative (Loc,
9310 New_List (Make_Others_Choice (Loc)),
9312 New_List (Make_Goto_Statement (Loc,
9313 Name => New_Copy (Identifier (End_Lab))))));
9315 Accept_Case := New_List (
9316 Make_Case_Statement (Loc,
9317 Expression => New_Reference_To (Xnam, Loc),
9318 Alternatives => Alt_List));
9320 Append_List (Trailing_List, Accept_Case);
9321 Append (End_Lab, Accept_Case);
9322 Append_List (Body_List, Decls);
9324 -- Construct case statement for trailing statements of delay
9325 -- alternatives, if there are several of them.
9327 if Delay_Count > 1 then
9328 Append_To (Delay_Alt_List,
9329 Make_Case_Statement_Alternative (Loc,
9331 New_List (Make_Others_Choice (Loc)),
9333 New_List (Make_Null_Statement (Loc))));
9335 Delay_Case := New_List (
9336 Make_Case_Statement (Loc,
9337 Expression => New_Reference_To (Delay_Index, Loc),
9338 Alternatives => Delay_Alt_List));
9340 Delay_Case := Delay_Alt_List;
9343 -- If there are no delay alternatives, we append the case statement
9344 -- to the statement list.
9346 if Delay_Count = 0 then
9347 Append_List (Accept_Case, Stats);
9349 -- Delay alternatives present
9352 -- If delay alternatives are present we generate:
9354 -- find minimum delay.
9355 -- DX := minimum delay;
9356 -- M := <delay mode>;
9357 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9360 -- if X = No_Rendezvous then
9361 -- case statement for delay statements.
9363 -- case statement for accept alternatives.
9374 -- The type of the delay expression is known to be legal
9376 if Time_Type = Standard_Duration then
9377 Conv := New_Reference_To (Delay_Min, Loc);
9379 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9380 Conv := Make_Function_Call (Loc,
9381 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9382 New_List (New_Reference_To (Delay_Min, Loc)));
9386 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9388 Conv := Make_Function_Call (Loc,
9389 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9390 New_List (New_Reference_To (Delay_Min, Loc)));
9393 Stmt := Make_Assignment_Statement (Loc,
9394 Name => New_Reference_To (D, Loc),
9395 Expression => Conv);
9397 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
9399 Parms := Parameter_Associations (Select_Call);
9400 Parm := First (Parms);
9402 while Present (Parm)
9403 and then Parm /= Select_Mode
9408 pragma Assert (Present (Parm));
9409 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
9412 -- Prepare two new parameters of Duration and Delay_Mode type
9413 -- which represent the value and the mode of the minimum delay.
9416 Insert_After (Parm, New_Reference_To (M, Loc));
9417 Insert_After (Parm, New_Reference_To (D, Loc));
9419 -- Create a call to RTS
9421 Rewrite (Select_Call,
9422 Make_Procedure_Call_Statement (Loc,
9423 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
9424 Parameter_Associations => Parms));
9426 -- This new call should follow the calculation of the minimum
9429 Insert_List_Before (Select_Call, Delay_List);
9433 Make_Implicit_If_Statement (N,
9434 Condition => New_Reference_To (Guard_Open, Loc),
9436 New_List (New_Copy_Tree (Stmt),
9437 New_Copy_Tree (Select_Call)),
9438 Else_Statements => Accept_Or_Raise);
9439 Rewrite (Select_Call, Stmt);
9441 Insert_Before (Select_Call, Stmt);
9445 Make_Implicit_If_Statement (N,
9446 Condition => Make_Op_Eq (Loc,
9447 Left_Opnd => New_Reference_To (Xnam, Loc),
9449 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9451 Then_Statements => Delay_Case,
9452 Else_Statements => Accept_Case);
9454 Append (Cases, Stats);
9458 -- Replace accept statement with appropriate block
9461 Make_Block_Statement (Loc,
9462 Declarations => Decls,
9463 Handled_Statement_Sequence =>
9464 Make_Handled_Sequence_Of_Statements (Loc,
9465 Statements => Stats));
9470 -- Note: have to worry more about abort deferral in above code ???
9472 -- Final step is to unstack the Accept_Address entries for all accept
9473 -- statements appearing in accept alternatives in the select statement
9475 Alt := First (Alts);
9476 while Present (Alt) loop
9477 if Nkind (Alt) = N_Accept_Alternative then
9478 Remove_Last_Elmt (Accept_Address
9479 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
9484 end Expand_N_Selective_Accept;
9486 --------------------------------------
9487 -- Expand_N_Single_Task_Declaration --
9488 --------------------------------------
9490 -- Single task declarations should never be present after semantic
9491 -- analysis, since we expect them to be replaced by a declaration of an
9492 -- anonymous task type, followed by a declaration of the task object. We
9493 -- include this routine to make sure that is happening!
9495 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
9497 raise Program_Error;
9498 end Expand_N_Single_Task_Declaration;
9500 ------------------------
9501 -- Expand_N_Task_Body --
9502 ------------------------
9504 -- Given a task body
9506 -- task body tname is
9512 -- This expansion routine converts it into a procedure and sets the
9513 -- elaboration flag for the procedure to true, to represent the fact
9514 -- that the task body is now elaborated:
9516 -- procedure tnameB (_Task : access tnameV) is
9517 -- discriminal : dtype renames _Task.discriminant;
9519 -- procedure _clean is
9523 -- Abort_Undefer.all;
9528 -- Abort_Undefer.all;
9530 -- System.Task_Stages.Complete_Activation;
9538 -- In addition, if the task body is an activator, then a call to activate
9539 -- tasks is added at the start of the statements, before the call to
9540 -- Complete_Activation, and if in addition the task is a master then it
9541 -- must be established as a master. These calls are inserted and analyzed
9542 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9545 -- There is one discriminal declaration line generated for each
9546 -- discriminant that is present to provide an easy reference point for
9547 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9549 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9550 -- task body procedures have a profile (Arg : System.Address). That is
9551 -- needed because GNARLI has to use the same access-to-subprogram type
9552 -- for all task types. We depend here on knowing that in GNAT, passing
9553 -- an address argument by value is identical to passing a record value
9554 -- by access (in either case a single pointer is passed), so even though
9555 -- this procedure has the wrong profile. In fact it's all OK, since the
9556 -- callings sequence is identical.
9558 procedure Expand_N_Task_Body (N : Node_Id) is
9559 Loc : constant Source_Ptr := Sloc (N);
9560 Ttyp : constant Entity_Id := Corresponding_Spec (N);
9564 Insert_Nod : Node_Id;
9565 -- Used to determine the proper location of wrapper body insertions
9568 -- Add renaming declarations for discriminals and a declaration for the
9569 -- entry family index (if applicable).
9571 Install_Private_Data_Declarations
9572 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
9574 -- Add a call to Abort_Undefer at the very beginning of the task
9575 -- body since this body is called with abort still deferred.
9577 if Abort_Allowed then
9578 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
9580 (First (Statements (Handled_Statement_Sequence (N))), Call);
9584 -- The statement part has already been protected with an at_end and
9585 -- cleanup actions. The call to Complete_Activation must be placed
9586 -- at the head of the sequence of statements of that block. The
9587 -- declarations have been merged in this sequence of statements but
9588 -- the first real statement is accessible from the First_Real_Statement
9589 -- field (which was set for exactly this purpose).
9591 if Restricted_Profile then
9592 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
9594 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
9598 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
9602 Make_Subprogram_Body (Loc,
9603 Specification => Build_Task_Proc_Specification (Ttyp),
9604 Declarations => Declarations (N),
9605 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
9607 -- If the task contains generic instantiations, cleanup actions are
9608 -- delayed until after instantiation. Transfer the activation chain to
9609 -- the subprogram, to insure that the activation call is properly
9610 -- generated. It the task body contains inner tasks, indicate that the
9611 -- subprogram is a task master.
9613 if Delay_Cleanups (Ttyp) then
9614 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
9615 Set_Is_Task_Master (New_N, Is_Task_Master (N));
9621 -- Set elaboration flag immediately after task body. If the body is a
9622 -- subunit, the flag is set in the declarative part containing the stub.
9624 if Nkind (Parent (N)) /= N_Subunit then
9626 Make_Assignment_Statement (Loc,
9628 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
9629 Expression => New_Reference_To (Standard_True, Loc)));
9632 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9633 -- the task body. At this point all wrapper specs have been created,
9634 -- frozen and included in the dispatch table for the task type.
9636 if Ada_Version >= Ada_05 then
9637 if Nkind (Parent (N)) = N_Subunit then
9638 Insert_Nod := Corresponding_Stub (Parent (N));
9643 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
9645 end Expand_N_Task_Body;
9647 ------------------------------------
9648 -- Expand_N_Task_Type_Declaration --
9649 ------------------------------------
9651 -- We have several things to do. First we must create a Boolean flag used
9652 -- to mark if the body is elaborated yet. This variable gets set to True
9653 -- when the body of the task is elaborated (we can't rely on the normal
9654 -- ABE mechanism for the task body, since we need to pass an access to
9655 -- this elaboration boolean to the runtime routines).
9657 -- taskE : aliased Boolean := False;
9659 -- Next a variable is declared to hold the task stack size (either the
9660 -- default : Unspecified_Size, or a value that is set by a pragma
9661 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9662 -- the variable is initialized with this value:
9664 -- taskZ : Size_Type := Unspecified_Size;
9666 -- taskZ : Size_Type := Size_Type (size_expression);
9668 -- Note: No variable is needed to hold the task relative deadline since
9669 -- its value would never be static because the parameter is of a private
9670 -- type (Ada.Real_Time.Time_Span).
9672 -- Next we create a corresponding record type declaration used to represent
9673 -- values of this task. The general form of this type declaration is
9675 -- type taskV (discriminants) is record
9676 -- _Task_Id : Task_Id;
9677 -- entry_family : array (bounds) of Void;
9678 -- _Priority : Integer := priority_expression;
9679 -- _Size : Size_Type := Size_Type (size_expression);
9680 -- _Task_Info : Task_Info_Type := task_info_expression;
9683 -- The discriminants are present only if the corresponding task type has
9684 -- discriminants, and they exactly mirror the task type discriminants.
9686 -- The Id field is always present. It contains the Task_Id value, as set by
9687 -- the call to Create_Task. Note that although the task is limited, the
9688 -- task value record type is not limited, so there is no problem in passing
9689 -- this field as an out parameter to Create_Task.
9691 -- One entry_family component is present for each entry family in the task
9692 -- definition. The bounds correspond to the bounds of the entry family
9693 -- (which may depend on discriminants). The element type is void, since we
9694 -- only need the bounds information for determining the entry index. Note
9695 -- that the use of an anonymous array would normally be illegal in this
9696 -- context, but this is a parser check, and the semantics is quite prepared
9697 -- to handle such a case.
9699 -- The _Size field is present only if a Storage_Size pragma appears in the
9700 -- task definition. The expression captures the argument that was present
9701 -- in the pragma, and is used to override the task stack size otherwise
9702 -- associated with the task type.
9704 -- The _Priority field is present only if a Priority or Interrupt_Priority
9705 -- pragma appears in the task definition. The expression captures the
9706 -- argument that was present in the pragma, and is used to provide the Size
9707 -- parameter to the call to Create_Task.
9709 -- The _Task_Info field is present only if a Task_Info pragma appears in
9710 -- the task definition. The expression captures the argument that was
9711 -- present in the pragma, and is used to provide the Task_Image parameter
9712 -- to the call to Create_Task.
9714 -- The _Relative_Deadline field is present only if a Relative_Deadline
9715 -- pragma appears in the task definition. The expression captures the
9716 -- argument that was present in the pragma, and is used to provide the
9717 -- Relative_Deadline parameter to the call to Create_Task.
9719 -- When a task is declared, an instance of the task value record is
9720 -- created. The elaboration of this declaration creates the correct bounds
9721 -- for the entry families, and also evaluates the size, priority, and
9722 -- task_Info expressions if needed. The initialization routine for the task
9723 -- type itself then calls Create_Task with appropriate parameters to
9724 -- initialize the value of the Task_Id field.
9726 -- Note: the address of this record is passed as the "Discriminants"
9727 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9728 -- body procedure, it does not matter that it does not quite match the
9729 -- GNARLI model of what is being passed (the record contains more than just
9730 -- the discriminants, but the discriminants can be found from the record
9733 -- The Entity_Id for this created record type is placed in the
9734 -- Corresponding_Record_Type field of the associated task type entity.
9736 -- Next we create a procedure specification for the task body procedure:
9738 -- procedure taskB (_Task : access taskV);
9740 -- Note that this must come after the record type declaration, since
9741 -- the spec refers to this type. It turns out that the initialization
9742 -- procedure for the value type references the task body spec, but that's
9743 -- fine, since it won't be generated till the freeze point for the type,
9744 -- which is certainly after the task body spec declaration.
9746 -- Finally, we set the task index value field of the entry attribute in
9747 -- the case of a simple entry.
9749 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9750 Loc : constant Source_Ptr := Sloc (N);
9751 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9752 Tasknm : constant Name_Id := Chars (Tasktyp);
9753 Taskdef : constant Node_Id := Task_Definition (N);
9755 Proc_Spec : Node_Id;
9757 Rec_Ent : Entity_Id;
9759 Elab_Decl : Node_Id;
9760 Size_Decl : Node_Id;
9761 Body_Decl : Node_Id;
9762 Task_Size : Node_Id;
9763 Ent_Stack : Entity_Id;
9764 Decl_Stack : Node_Id;
9767 -- If already expanded, nothing to do
9769 if Present (Corresponding_Record_Type (Tasktyp)) then
9773 -- Here we will do the expansion
9775 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9777 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9778 -- of implemented interfaces.
9780 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9782 Rec_Ent := Defining_Identifier (Rec_Decl);
9783 Cdecls := Component_Items (Component_List
9784 (Type_Definition (Rec_Decl)));
9786 Qualify_Entity_Names (N);
9788 -- First create the elaboration variable
9791 Make_Object_Declaration (Loc,
9792 Defining_Identifier =>
9793 Make_Defining_Identifier (Sloc (Tasktyp),
9794 Chars => New_External_Name (Tasknm, 'E')),
9795 Aliased_Present => True,
9796 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9797 Expression => New_Reference_To (Standard_False, Loc));
9798 Insert_After (N, Elab_Decl);
9800 -- Next create the declaration of the size variable (tasknmZ)
9802 Set_Storage_Size_Variable (Tasktyp,
9803 Make_Defining_Identifier (Sloc (Tasktyp),
9804 Chars => New_External_Name (Tasknm, 'Z')));
9806 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
9807 Is_Static_Expression (Expression (First (
9808 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
9809 Taskdef, Name_Storage_Size)))))
9812 Make_Object_Declaration (Loc,
9813 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9814 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9816 Convert_To (RTE (RE_Size_Type),
9819 Pragma_Argument_Associations (
9820 Find_Task_Or_Protected_Pragma
9821 (Taskdef, Name_Storage_Size)))))));
9825 Make_Object_Declaration (Loc,
9826 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9827 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9828 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
9831 Insert_After (Elab_Decl, Size_Decl);
9833 -- Next build the rest of the corresponding record declaration. This is
9834 -- done last, since the corresponding record initialization procedure
9835 -- will reference the previously created entities.
9837 -- Fill in the component declarations -- first the _Task_Id field
9840 Make_Component_Declaration (Loc,
9841 Defining_Identifier =>
9842 Make_Defining_Identifier (Loc, Name_uTask_Id),
9843 Component_Definition =>
9844 Make_Component_Definition (Loc,
9845 Aliased_Present => False,
9846 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
9849 -- Declare static ATCB (that is, created by the expander) if we are
9850 -- using the Restricted run time.
9852 if Restricted_Profile then
9854 Make_Component_Declaration (Loc,
9855 Defining_Identifier =>
9856 Make_Defining_Identifier (Loc, Name_uATCB),
9858 Component_Definition =>
9859 Make_Component_Definition (Loc,
9860 Aliased_Present => True,
9861 Subtype_Indication => Make_Subtype_Indication (Loc,
9862 Subtype_Mark => New_Occurrence_Of
9863 (RTE (RE_Ada_Task_Control_Block), Loc),
9866 Make_Index_Or_Discriminant_Constraint (Loc,
9868 New_List (Make_Integer_Literal (Loc, 0)))))));
9872 -- Declare static stack (that is, created by the expander) if we are
9873 -- using the Restricted run time on a bare board configuration.
9875 if Restricted_Profile
9876 and then Preallocated_Stacks_On_Target
9878 -- First we need to extract the appropriate stack size
9880 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
9882 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
9884 Expr_N : constant Node_Id :=
9886 Pragma_Argument_Associations (
9887 Find_Task_Or_Protected_Pragma
9888 (Taskdef, Name_Storage_Size))));
9889 Etyp : constant Entity_Id := Etype (Expr_N);
9890 P : constant Node_Id := Parent (Expr_N);
9893 -- The stack is defined inside the corresponding record.
9894 -- Therefore if the size of the stack is set by means of
9895 -- a discriminant, we must reference the discriminant of the
9896 -- corresponding record type.
9898 if Nkind (Expr_N) in N_Has_Entity
9899 and then Present (Discriminal_Link (Entity (Expr_N)))
9903 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
9905 Set_Parent (Task_Size, P);
9906 Set_Etype (Task_Size, Etyp);
9907 Set_Analyzed (Task_Size);
9910 Task_Size := Relocate_Node (Expr_N);
9916 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
9919 Decl_Stack := Make_Component_Declaration (Loc,
9920 Defining_Identifier => Ent_Stack,
9922 Component_Definition =>
9923 Make_Component_Definition (Loc,
9924 Aliased_Present => True,
9925 Subtype_Indication => Make_Subtype_Indication (Loc,
9927 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
9930 Make_Index_Or_Discriminant_Constraint (Loc,
9931 Constraints => New_List (Make_Range (Loc,
9932 Low_Bound => Make_Integer_Literal (Loc, 1),
9933 High_Bound => Convert_To (RTE (RE_Storage_Offset),
9936 Append_To (Cdecls, Decl_Stack);
9938 -- The appropriate alignment for the stack is ensured by the run-time
9939 -- code in charge of task creation.
9943 -- Add components for entry families
9945 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
9947 -- Add the _Priority component if a Priority pragma is present
9949 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
9951 Prag : constant Node_Id :=
9952 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
9956 Expr := First (Pragma_Argument_Associations (Prag));
9958 if Nkind (Expr) = N_Pragma_Argument_Association then
9959 Expr := Expression (Expr);
9962 Expr := New_Copy_Tree (Expr);
9964 -- Add conversion to proper type to do range check if required
9965 -- Note that for runtime units, we allow out of range interrupt
9966 -- priority values to be used in a priority pragma. This is for
9967 -- the benefit of some versions of System.Interrupts which use
9968 -- a special server task with maximum interrupt priority.
9970 if Pragma_Name (Prag) = Name_Priority
9971 and then not GNAT_Mode
9973 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
9975 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
9979 Make_Component_Declaration (Loc,
9980 Defining_Identifier =>
9981 Make_Defining_Identifier (Loc, Name_uPriority),
9982 Component_Definition =>
9983 Make_Component_Definition (Loc,
9984 Aliased_Present => False,
9985 Subtype_Indication => New_Reference_To (Standard_Integer,
9987 Expression => Expr));
9991 -- Add the _Task_Size component if a Storage_Size pragma is present
9993 if Present (Taskdef)
9994 and then Has_Storage_Size_Pragma (Taskdef)
9997 Make_Component_Declaration (Loc,
9998 Defining_Identifier =>
9999 Make_Defining_Identifier (Loc, Name_uSize),
10001 Component_Definition =>
10002 Make_Component_Definition (Loc,
10003 Aliased_Present => False,
10004 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10008 Convert_To (RTE (RE_Size_Type),
10010 Expression (First (
10011 Pragma_Argument_Associations (
10012 Find_Task_Or_Protected_Pragma
10013 (Taskdef, Name_Storage_Size))))))));
10016 -- Add the _Task_Info component if a Task_Info pragma is present
10018 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10020 Make_Component_Declaration (Loc,
10021 Defining_Identifier =>
10022 Make_Defining_Identifier (Loc, Name_uTask_Info),
10024 Component_Definition =>
10025 Make_Component_Definition (Loc,
10026 Aliased_Present => False,
10027 Subtype_Indication =>
10028 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10030 Expression => New_Copy (
10031 Expression (First (
10032 Pragma_Argument_Associations (
10033 Find_Task_Or_Protected_Pragma
10034 (Taskdef, Name_Task_Info)))))));
10037 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10038 -- present. If we are using a restricted run time this component will
10039 -- not be added (deadlines are not allowed by the Ravenscar profile).
10041 if not Restricted_Profile
10042 and then Present (Taskdef)
10043 and then Has_Relative_Deadline_Pragma (Taskdef)
10046 Make_Component_Declaration (Loc,
10047 Defining_Identifier =>
10048 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10050 Component_Definition =>
10051 Make_Component_Definition (Loc,
10052 Aliased_Present => False,
10053 Subtype_Indication =>
10054 New_Reference_To (RTE (RE_Time_Span), Loc)),
10057 Convert_To (RTE (RE_Time_Span),
10059 Expression (First (
10060 Pragma_Argument_Associations (
10061 Find_Task_Or_Protected_Pragma
10062 (Taskdef, Name_Relative_Deadline))))))));
10065 Insert_After (Size_Decl, Rec_Decl);
10067 -- Analyze the record declaration immediately after construction,
10068 -- because the initialization procedure is needed for single task
10069 -- declarations before the next entity is analyzed.
10071 Analyze (Rec_Decl);
10073 -- Create the declaration of the task body procedure
10075 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10077 Make_Subprogram_Declaration (Loc,
10078 Specification => Proc_Spec);
10080 Insert_After (Rec_Decl, Body_Decl);
10082 -- The subprogram does not comes from source, so we have to indicate the
10083 -- need for debugging information explicitly.
10085 if Comes_From_Source (Original_Node (N)) then
10086 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10089 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10090 -- the corresponding record has been frozen.
10092 if Ada_Version >= Ada_05 then
10093 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10096 -- Ada 2005 (AI-345): We must defer freezing to allow further
10097 -- declaration of primitive subprograms covering task interfaces
10099 if Ada_Version <= Ada_95 then
10101 -- Now we can freeze the corresponding record. This needs manually
10102 -- freezing, since it is really part of the task type, and the task
10103 -- type is frozen at this stage. We of course need the initialization
10104 -- procedure for this corresponding record type and we won't get it
10105 -- in time if we don't freeze now.
10108 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
10110 if Is_Non_Empty_List (L) then
10111 Insert_List_After (Body_Decl, L);
10116 -- Complete the expansion of access types to the current task type, if
10117 -- any were declared.
10119 Expand_Previous_Access_Type (Tasktyp);
10120 end Expand_N_Task_Type_Declaration;
10122 -------------------------------
10123 -- Expand_N_Timed_Entry_Call --
10124 -------------------------------
10126 -- A timed entry call in normal case is not implemented using ATC mechanism
10127 -- anymore for efficiency reason.
10137 -- is expanded as follow:
10139 -- 1) When T.E is a task entry_call;
10143 -- X : Task_Entry_Index := <entry index>;
10144 -- DX : Duration := To_Duration (D);
10145 -- M : Delay_Mode := <discriminant>;
10146 -- P : parms := (parm, parm, parm);
10149 -- Timed_Protected_Entry_Call
10150 -- (<acceptor-task>, X, P'Address, DX, M, B);
10158 -- 2) When T.E is a protected entry_call;
10162 -- X : Protected_Entry_Index := <entry index>;
10163 -- DX : Duration := To_Duration (D);
10164 -- M : Delay_Mode := <discriminant>;
10165 -- P : parms := (parm, parm, parm);
10168 -- Timed_Protected_Entry_Call
10169 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10177 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10180 -- B : Boolean := False;
10181 -- C : Ada.Tags.Prim_Op_Kind;
10182 -- DX : Duration := To_Duration (D)
10183 -- K : Ada.Tags.Tagged_Kind :=
10184 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10185 -- M : Integer :=...;
10186 -- P : Parameters := (Param1 .. ParamN);
10190 -- if K = Ada.Tags.TK_Limited_Tagged then
10191 -- <dispatching-call>;
10192 -- <triggering-statements>
10196 -- Ada.Tags.Get_Offset_Index
10197 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10199 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10201 -- if C = POK_Protected_Entry
10202 -- or else C = POK_Task_Entry
10204 -- Param1 := P.Param1;
10206 -- ParamN := P.ParamN;
10210 -- if C = POK_Procedure
10211 -- or else C = POK_Protected_Procedure
10212 -- or else C = POK_Task_Procedure
10214 -- <dispatching-call>;
10217 -- <triggering-statements>
10219 -- <timed-statements>
10224 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10225 Loc : constant Source_Ptr := Sloc (N);
10227 E_Call : Node_Id :=
10228 Entry_Call_Statement (Entry_Call_Alternative (N));
10229 E_Stats : constant List_Id :=
10230 Statements (Entry_Call_Alternative (N));
10231 D_Stat : Node_Id :=
10232 Delay_Statement (Delay_Alternative (N));
10233 D_Stats : constant List_Id :=
10234 Statements (Delay_Alternative (N));
10237 Blk_Typ : Entity_Id;
10239 Call_Ent : Entity_Id;
10240 Conc_Typ_Stmts : List_Id;
10244 D_Type : Entity_Id;
10250 Is_Disp_Select : Boolean;
10251 Lim_Typ_Stmts : List_Id;
10260 B : Entity_Id; -- Call status flag
10261 C : Entity_Id; -- Call kind
10262 D : Entity_Id; -- Delay
10263 K : Entity_Id; -- Tagged kind
10264 M : Entity_Id; -- Delay mode
10265 P : Entity_Id; -- Parameter block
10266 S : Entity_Id; -- Primitive operation slot
10269 -- The arguments in the call may require dynamic allocation, and the
10270 -- call statement may have been transformed into a block. The block
10271 -- may contain additional declarations for internal entities, and the
10272 -- original call is found by sequential search.
10274 if Nkind (E_Call) = N_Block_Statement then
10275 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10276 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10277 N_Entry_Call_Statement)
10284 Ada_Version >= Ada_05
10285 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10287 if Is_Disp_Select then
10288 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
10294 -- B : Boolean := False;
10296 B := Build_B (Loc, Decls);
10299 -- C : Ada.Tags.Prim_Op_Kind;
10301 C := Build_C (Loc, Decls);
10303 -- Because the analysis of all statements was disabled, manually
10304 -- analyze the delay statement.
10307 D_Stat := Original_Node (D_Stat);
10310 -- Build an entry call using Simple_Entry_Call
10312 Extract_Entry (E_Call, Concval, Ename, Index);
10313 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
10315 Decls := Declarations (E_Call);
10316 Stmts := Statements (Handled_Statement_Sequence (E_Call));
10325 B := Make_Defining_Identifier (Loc, Name_uB);
10328 Make_Object_Declaration (Loc,
10329 Defining_Identifier =>
10331 Object_Definition =>
10332 New_Reference_To (Standard_Boolean, Loc)));
10335 -- Duration and mode processing
10337 D_Type := Base_Type (Etype (Expression (D_Stat)));
10339 -- Use the type of the delay expression (Calendar or Real_Time) to
10340 -- generate the appropriate conversion.
10342 if Nkind (D_Stat) = N_Delay_Relative_Statement then
10343 D_Disc := Make_Integer_Literal (Loc, 0);
10344 D_Conv := Relocate_Node (Expression (D_Stat));
10346 elsif Is_RTE (D_Type, RO_CA_Time) then
10347 D_Disc := Make_Integer_Literal (Loc, 1);
10348 D_Conv := Make_Function_Call (Loc,
10349 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10350 New_List (New_Copy (Expression (D_Stat))));
10352 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
10353 D_Disc := Make_Integer_Literal (Loc, 2);
10354 D_Conv := Make_Function_Call (Loc,
10355 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10356 New_List (New_Copy (Expression (D_Stat))));
10359 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
10365 Make_Object_Declaration (Loc,
10366 Defining_Identifier =>
10368 Object_Definition =>
10369 New_Reference_To (Standard_Duration, Loc)));
10371 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
10374 -- M : Integer := (0 | 1 | 2);
10377 Make_Object_Declaration (Loc,
10378 Defining_Identifier =>
10380 Object_Definition =>
10381 New_Reference_To (Standard_Integer, Loc),
10385 -- Do the assignment at this stage only because the evaluation of the
10386 -- expression must not occur before (see ACVC C97302A).
10389 Make_Assignment_Statement (Loc,
10391 New_Reference_To (D, Loc),
10395 -- Parameter block processing
10397 -- Manually create the parameter block for dispatching calls. In the
10398 -- case of entries, the block has already been created during the call
10399 -- to Build_Simple_Entry_Call.
10401 if Is_Disp_Select then
10403 -- Tagged kind processing, generate:
10404 -- K : Ada.Tags.Tagged_Kind :=
10405 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
10407 K := Build_K (Loc, Decls, Obj);
10409 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
10410 P := Parameter_Block_Pack
10411 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
10413 -- Dispatch table slot processing, generate:
10416 S := Build_S (Loc, Decls);
10419 -- S := Ada.Tags.Get_Offset_Index
10420 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
10423 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
10426 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
10428 -- where Obj is the controlling formal parameter, S is the dispatch
10429 -- table slot number of the dispatching operation, P is the wrapped
10430 -- parameter block, D is the duration, M is the duration mode, C is
10431 -- the call kind and B is the call status.
10433 Params := New_List;
10435 Append_To (Params, New_Copy_Tree (Obj));
10436 Append_To (Params, New_Reference_To (S, Loc));
10437 Append_To (Params, Make_Attribute_Reference (Loc,
10438 Prefix => New_Reference_To (P, Loc),
10439 Attribute_Name => Name_Address));
10440 Append_To (Params, New_Reference_To (D, Loc));
10441 Append_To (Params, New_Reference_To (M, Loc));
10442 Append_To (Params, New_Reference_To (C, Loc));
10443 Append_To (Params, New_Reference_To (B, Loc));
10445 Append_To (Conc_Typ_Stmts,
10446 Make_Procedure_Call_Statement (Loc,
10449 Find_Prim_Op (Etype (Etype (Obj)),
10450 Name_uDisp_Timed_Select),
10452 Parameter_Associations =>
10456 -- if C = POK_Protected_Entry
10457 -- or else C = POK_Task_Entry
10459 -- Param1 := P.Param1;
10461 -- ParamN := P.ParamN;
10464 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
10466 -- Generate the if statement only when the packed parameters need
10467 -- explicit assignments to their corresponding actuals.
10469 if Present (Unpack) then
10470 Append_To (Conc_Typ_Stmts,
10471 Make_If_Statement (Loc,
10478 New_Reference_To (C, Loc),
10480 New_Reference_To (RTE (
10481 RE_POK_Protected_Entry), Loc)),
10485 New_Reference_To (C, Loc),
10487 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
10496 -- if C = POK_Procedure
10497 -- or else C = POK_Protected_Procedure
10498 -- or else C = POK_Task_Procedure
10500 -- <dispatching-call>
10502 -- <triggering-statements>
10504 -- <timed-statements>
10507 N_Stats := New_Copy_List_Tree (E_Stats);
10509 Prepend_To (N_Stats,
10510 Make_If_Statement (Loc,
10517 New_Reference_To (C, Loc),
10519 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
10525 New_Reference_To (C, Loc),
10527 New_Reference_To (RTE (
10528 RE_POK_Protected_Procedure), Loc)),
10532 New_Reference_To (C, Loc),
10534 New_Reference_To (RTE (
10535 RE_POK_Task_Procedure), Loc)))),
10538 New_List (E_Call)));
10540 Append_To (Conc_Typ_Stmts,
10541 Make_If_Statement (Loc,
10542 Condition => New_Reference_To (B, Loc),
10543 Then_Statements => N_Stats,
10544 Else_Statements => D_Stats));
10547 -- <dispatching-call>;
10548 -- <triggering-statements>
10550 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
10551 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
10554 -- if K = Ada.Tags.TK_Limited_Tagged then
10561 Make_If_Statement (Loc,
10565 New_Reference_To (K, Loc),
10567 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
10576 -- Skip assignments to temporaries created for in-out parameters.
10577 -- This makes unwarranted assumptions about the shape of the expanded
10578 -- tree for the call, and should be cleaned up ???
10580 Stmt := First (Stmts);
10581 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
10585 -- Do the assignment at this stage only because the evaluation
10586 -- of the expression must not occur before (see ACVC C97302A).
10588 Insert_Before (Stmt,
10589 Make_Assignment_Statement (Loc,
10590 Name => New_Reference_To (D, Loc),
10591 Expression => D_Conv));
10594 Params := Parameter_Associations (Call);
10596 -- For a protected type, we build a Timed_Protected_Entry_Call
10598 if Is_Protected_Type (Etype (Concval)) then
10600 -- Create a new call statement
10602 Param := First (Params);
10603 while Present (Param)
10604 and then not Is_RTE (Etype (Param), RE_Call_Modes)
10609 Dummy := Remove_Next (Next (Param));
10611 -- Remove garbage is following the Cancel_Param if present
10613 Dummy := Next (Param);
10615 -- Remove the mode of the Protected_Entry_Call call, then remove
10616 -- the Communication_Block of the Protected_Entry_Call call, and
10617 -- finally add Duration and a Delay_Mode parameter
10619 pragma Assert (Present (Param));
10620 Rewrite (Param, New_Reference_To (D, Loc));
10622 Rewrite (Dummy, New_Reference_To (M, Loc));
10624 -- Add a Boolean flag for successful entry call
10626 Append_To (Params, New_Reference_To (B, Loc));
10628 case Corresponding_Runtime_Package (Etype (Concval)) is
10629 when System_Tasking_Protected_Objects_Entries =>
10631 Make_Procedure_Call_Statement (Loc,
10634 (RTE (RE_Timed_Protected_Entry_Call), Loc),
10635 Parameter_Associations => Params));
10637 when System_Tasking_Protected_Objects_Single_Entry =>
10638 Param := First (Params);
10639 while Present (Param)
10641 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
10649 Make_Procedure_Call_Statement (Loc,
10650 Name => New_Reference_To (
10651 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
10652 Parameter_Associations => Params));
10655 raise Program_Error;
10658 -- For the task case, build a Timed_Task_Entry_Call
10661 -- Create a new call statement
10663 Append_To (Params, New_Reference_To (D, Loc));
10664 Append_To (Params, New_Reference_To (M, Loc));
10665 Append_To (Params, New_Reference_To (B, Loc));
10668 Make_Procedure_Call_Statement (Loc,
10670 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
10671 Parameter_Associations => Params));
10675 Make_Implicit_If_Statement (N,
10676 Condition => New_Reference_To (B, Loc),
10677 Then_Statements => E_Stats,
10678 Else_Statements => D_Stats));
10682 Make_Block_Statement (Loc,
10683 Declarations => Decls,
10684 Handled_Statement_Sequence =>
10685 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
10688 end Expand_N_Timed_Entry_Call;
10690 ----------------------------------------
10691 -- Expand_Protected_Body_Declarations --
10692 ----------------------------------------
10694 procedure Expand_Protected_Body_Declarations
10696 Spec_Id : Entity_Id)
10699 if No_Run_Time_Mode then
10700 Error_Msg_CRT ("protected body", N);
10703 elsif Expander_Active then
10705 -- Associate discriminals with the first subprogram or entry body to
10708 if Present (First_Protected_Operation (Declarations (N))) then
10709 Set_Discriminals (Parent (Spec_Id));
10712 end Expand_Protected_Body_Declarations;
10714 -------------------------
10715 -- External_Subprogram --
10716 -------------------------
10718 function External_Subprogram (E : Entity_Id) return Entity_Id is
10719 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10722 -- The internal and external subprograms follow each other on the entity
10723 -- chain. Note that previously private operations had no separate
10724 -- external subprogram. We now create one in all cases, because a
10725 -- private operation may actually appear in an external call, through
10726 -- a 'Access reference used for a callback.
10728 -- If the operation is a function that returns an anonymous access type,
10729 -- the corresponding itype appears before the operation, and must be
10732 -- This mechanism is fragile, there should be a real link between the
10733 -- two versions of the operation, but there is no place to put it ???
10735 if Is_Access_Type (Next_Entity (Subp)) then
10736 return Next_Entity (Next_Entity (Subp));
10738 return Next_Entity (Subp);
10740 end External_Subprogram;
10742 ------------------------------
10743 -- Extract_Dispatching_Call --
10744 ------------------------------
10746 procedure Extract_Dispatching_Call
10748 Call_Ent : out Entity_Id;
10749 Object : out Entity_Id;
10750 Actuals : out List_Id;
10751 Formals : out List_Id)
10753 Call_Nam : Node_Id;
10756 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10758 if Present (Original_Node (N)) then
10759 Call_Nam := Name (Original_Node (N));
10761 Call_Nam := Name (N);
10764 -- Retrieve the name of the dispatching procedure. It contains the
10765 -- dispatch table slot number.
10768 case Nkind (Call_Nam) is
10769 when N_Identifier =>
10772 when N_Selected_Component =>
10773 Call_Nam := Selector_Name (Call_Nam);
10776 raise Program_Error;
10781 Actuals := Parameter_Associations (N);
10782 Call_Ent := Entity (Call_Nam);
10783 Formals := Parameter_Specifications (Parent (Call_Ent));
10784 Object := First (Actuals);
10786 if Present (Original_Node (Object)) then
10787 Object := Original_Node (Object);
10789 end Extract_Dispatching_Call;
10791 -------------------
10792 -- Extract_Entry --
10793 -------------------
10795 procedure Extract_Entry
10797 Concval : out Node_Id;
10798 Ename : out Node_Id;
10799 Index : out Node_Id)
10801 Nam : constant Node_Id := Name (N);
10804 -- For a simple entry, the name is a selected component, with the
10805 -- prefix being the task value, and the selector being the entry.
10807 if Nkind (Nam) = N_Selected_Component then
10808 Concval := Prefix (Nam);
10809 Ename := Selector_Name (Nam);
10812 -- For a member of an entry family, the name is an indexed component
10813 -- where the prefix is a selected component, whose prefix in turn is
10814 -- the task value, and whose selector is the entry family. The single
10815 -- expression in the expressions list of the indexed component is the
10816 -- subscript for the family.
10818 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
10819 Concval := Prefix (Prefix (Nam));
10820 Ename := Selector_Name (Prefix (Nam));
10821 Index := First (Expressions (Nam));
10825 -------------------
10826 -- Family_Offset --
10827 -------------------
10829 function Family_Offset
10834 Cap : Boolean) return Node_Id
10840 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
10841 -- If one of the bounds is a reference to a discriminant, replace with
10842 -- corresponding discriminal of type. Within the body of a task retrieve
10843 -- the renamed discriminant by simple visibility, using its generated
10844 -- name. Within a protected object, find the original discriminant and
10845 -- replace it with the discriminal of the current protected operation.
10847 ------------------------------
10848 -- Convert_Discriminant_Ref --
10849 ------------------------------
10851 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
10852 Loc : constant Source_Ptr := Sloc (Bound);
10857 if Is_Entity_Name (Bound)
10858 and then Ekind (Entity (Bound)) = E_Discriminant
10860 if Is_Task_Type (Ttyp)
10861 and then Has_Completion (Ttyp)
10863 B := Make_Identifier (Loc, Chars (Entity (Bound)));
10864 Find_Direct_Name (B);
10866 elsif Is_Protected_Type (Ttyp) then
10867 D := First_Discriminant (Ttyp);
10868 while Chars (D) /= Chars (Entity (Bound)) loop
10869 Next_Discriminant (D);
10872 B := New_Reference_To (Discriminal (D), Loc);
10875 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
10878 elsif Nkind (Bound) = N_Attribute_Reference then
10882 B := New_Copy_Tree (Bound);
10886 Make_Attribute_Reference (Loc,
10887 Attribute_Name => Name_Pos,
10888 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
10889 Expressions => New_List (B));
10890 end Convert_Discriminant_Ref;
10892 -- Start of processing for Family_Offset
10895 Real_Hi := Convert_Discriminant_Ref (Hi);
10896 Real_Lo := Convert_Discriminant_Ref (Lo);
10899 if Is_Task_Type (Ttyp) then
10900 Ityp := RTE (RE_Task_Entry_Index);
10902 Ityp := RTE (RE_Protected_Entry_Index);
10906 Make_Attribute_Reference (Loc,
10907 Prefix => New_Reference_To (Ityp, Loc),
10908 Attribute_Name => Name_Min,
10909 Expressions => New_List (
10911 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
10914 Make_Attribute_Reference (Loc,
10915 Prefix => New_Reference_To (Ityp, Loc),
10916 Attribute_Name => Name_Max,
10917 Expressions => New_List (
10919 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
10922 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
10929 function Family_Size
10934 Cap : Boolean) return Node_Id
10939 if Is_Task_Type (Ttyp) then
10940 Ityp := RTE (RE_Task_Entry_Index);
10942 Ityp := RTE (RE_Protected_Entry_Index);
10946 Make_Attribute_Reference (Loc,
10947 Prefix => New_Reference_To (Ityp, Loc),
10948 Attribute_Name => Name_Max,
10949 Expressions => New_List (
10952 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
10954 Make_Integer_Literal (Loc, 1)),
10955 Make_Integer_Literal (Loc, 0)));
10958 -----------------------------------
10959 -- Find_Task_Or_Protected_Pragma --
10960 -----------------------------------
10962 function Find_Task_Or_Protected_Pragma
10964 P : Name_Id) return Node_Id
10969 N := First (Visible_Declarations (T));
10970 while Present (N) loop
10971 if Nkind (N) = N_Pragma then
10972 if Pragma_Name (N) = P then
10975 elsif P = Name_Priority
10976 and then Pragma_Name (N) = Name_Interrupt_Priority
10989 N := First (Private_Declarations (T));
10990 while Present (N) loop
10991 if Nkind (N) = N_Pragma then
10992 if Pragma_Name (N) = P then
10995 elsif P = Name_Priority
10996 and then Pragma_Name (N) = Name_Interrupt_Priority
11009 raise Program_Error;
11010 end Find_Task_Or_Protected_Pragma;
11012 -------------------------------
11013 -- First_Protected_Operation --
11014 -------------------------------
11016 function First_Protected_Operation (D : List_Id) return Node_Id is
11017 First_Op : Node_Id;
11020 First_Op := First (D);
11021 while Present (First_Op)
11022 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11028 end First_Protected_Operation;
11030 ---------------------------------------
11031 -- Install_Private_Data_Declarations --
11032 ---------------------------------------
11034 procedure Install_Private_Data_Declarations
11036 Spec_Id : Entity_Id;
11037 Conc_Typ : Entity_Id;
11038 Body_Nod : Node_Id;
11040 Barrier : Boolean := False;
11041 Family : Boolean := False)
11043 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11046 Insert_Node : Node_Id := Empty;
11047 Obj_Ent : Entity_Id;
11049 procedure Add (Decl : Node_Id);
11050 -- Add a single declaration after Insert_Node. If this is the first
11051 -- addition, Decl is added to the front of Decls and it becomes the
11054 function Replace_Bound (Bound : Node_Id) return Node_Id;
11055 -- The bounds of an entry index may depend on discriminants, create a
11056 -- reference to the corresponding prival. Otherwise return a duplicate
11057 -- of the original bound.
11063 procedure Add (Decl : Node_Id) is
11065 if No (Insert_Node) then
11066 Prepend_To (Decls, Decl);
11068 Insert_After (Insert_Node, Decl);
11071 Insert_Node := Decl;
11074 --------------------------
11075 -- Replace_Discriminant --
11076 --------------------------
11078 function Replace_Bound (Bound : Node_Id) return Node_Id is
11080 if Nkind (Bound) = N_Identifier
11081 and then Is_Discriminal (Entity (Bound))
11083 return Make_Identifier (Loc, Chars (Entity (Bound)));
11085 return Duplicate_Subexpr (Bound);
11089 -- Start of processing for Install_Private_Data_Declarations
11092 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11093 -- formal parameter _O, _object or _task depending on the context.
11095 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11097 -- Special processing of _O for barrier functions, protected entries
11104 (Ekind (Spec_Id) = E_Entry
11105 or else Ekind (Spec_Id) = E_Entry_Family))
11108 Conc_Rec : constant Entity_Id :=
11109 Corresponding_Record_Type (Conc_Typ);
11110 Typ_Id : constant Entity_Id :=
11111 Make_Defining_Identifier (Loc,
11112 New_External_Name (Chars (Conc_Rec), 'P'));
11115 -- type prot_typVP is access prot_typV;
11118 Make_Full_Type_Declaration (Loc,
11119 Defining_Identifier => Typ_Id,
11121 Make_Access_To_Object_Definition (Loc,
11122 Subtype_Indication =>
11123 New_Reference_To (Conc_Rec, Loc)));
11127 -- _object : prot_typVP := prot_typV (_O);
11130 Make_Object_Declaration (Loc,
11131 Defining_Identifier =>
11132 Make_Defining_Identifier (Loc, Name_uObject),
11133 Object_Definition => New_Reference_To (Typ_Id, Loc),
11135 Unchecked_Convert_To (Typ_Id,
11136 New_Reference_To (Obj_Ent, Loc)));
11139 -- Set the reference to the concurrent object
11141 Obj_Ent := Defining_Identifier (Decl);
11145 -- Step 2: Create the Protection object and build its declaration for
11146 -- any protected entry (family) of subprogram.
11148 if Is_Protected then
11150 Prot_Ent : constant Entity_Id :=
11151 Make_Defining_Identifier (Loc,
11152 New_Internal_Name ('R'));
11156 Set_Protection_Object (Spec_Id, Prot_Ent);
11158 -- Determine the proper protection type
11160 if Has_Attach_Handler (Conc_Typ)
11161 and then not Restricted_Profile
11163 Prot_Typ := RE_Static_Interrupt_Protection;
11165 elsif Has_Interrupt_Handler (Conc_Typ) then
11166 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11168 -- The type has explicit entries or generated primitive entry
11171 elsif Has_Entries (Conc_Typ)
11173 (Ada_Version >= Ada_05
11174 and then Present (Interface_List (Parent (Conc_Typ))))
11176 case Corresponding_Runtime_Package (Conc_Typ) is
11177 when System_Tasking_Protected_Objects_Entries =>
11178 Prot_Typ := RE_Protection_Entries;
11180 when System_Tasking_Protected_Objects_Single_Entry =>
11181 Prot_Typ := RE_Protection_Entry;
11184 raise Program_Error;
11188 Prot_Typ := RE_Protection;
11192 -- conc_typR : protection_typ renames _object._object;
11195 Make_Object_Renaming_Declaration (Loc,
11196 Defining_Identifier => Prot_Ent,
11198 New_Reference_To (RTE (Prot_Typ), Loc),
11200 Make_Selected_Component (Loc,
11202 New_Reference_To (Obj_Ent, Loc),
11204 Make_Identifier (Loc, Name_uObject)));
11209 -- Step 3: Add discriminant renamings (if any)
11211 if Has_Discriminants (Conc_Typ) then
11216 D := First_Discriminant (Conc_Typ);
11217 while Present (D) loop
11219 -- Adjust the source location
11221 Set_Sloc (Discriminal (D), Loc);
11224 -- discr_name : discr_typ renames _object.discr_name;
11226 -- discr_name : discr_typ renames _task.discr_name;
11229 Make_Object_Renaming_Declaration (Loc,
11230 Defining_Identifier => Discriminal (D),
11231 Subtype_Mark => New_Reference_To (Etype (D), Loc),
11233 Make_Selected_Component (Loc,
11234 Prefix => New_Reference_To (Obj_Ent, Loc),
11235 Selector_Name => Make_Identifier (Loc, Chars (D))));
11238 Next_Discriminant (D);
11243 -- Step 4: Add private component renamings (if any)
11245 if Is_Protected then
11246 Def := Protected_Definition (Parent (Conc_Typ));
11248 if Present (Private_Declarations (Def)) then
11251 Comp_Id : Entity_Id;
11252 Decl_Id : Entity_Id;
11255 Comp := First (Private_Declarations (Def));
11256 while Present (Comp) loop
11257 if Nkind (Comp) = N_Component_Declaration then
11258 Comp_Id := Defining_Identifier (Comp);
11260 Make_Defining_Identifier (Loc, Chars (Comp_Id));
11262 -- Minimal decoration
11264 if Ekind (Spec_Id) = E_Function then
11265 Set_Ekind (Decl_Id, E_Constant);
11267 Set_Ekind (Decl_Id, E_Variable);
11270 Set_Prival (Comp_Id, Decl_Id);
11271 Set_Prival_Link (Decl_Id, Comp_Id);
11272 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
11275 -- comp_name : comp_typ renames _object.comp_name;
11278 Make_Object_Renaming_Declaration (Loc,
11279 Defining_Identifier => Decl_Id,
11281 New_Reference_To (Etype (Comp_Id), Loc),
11283 Make_Selected_Component (Loc,
11285 New_Reference_To (Obj_Ent, Loc),
11287 Make_Identifier (Loc, Chars (Comp_Id))));
11297 -- Step 5: Add the declaration of the entry index and the associated
11298 -- type for barrier functions and entry families.
11300 if (Barrier and then Family)
11301 or else Ekind (Spec_Id) = E_Entry_Family
11304 E : constant Entity_Id := Index_Object (Spec_Id);
11305 Index : constant Entity_Id :=
11306 Defining_Identifier (
11307 Entry_Index_Specification (
11308 Entry_Body_Formal_Part (Body_Nod)));
11309 Index_Con : constant Entity_Id :=
11310 Make_Defining_Identifier (Loc, Chars (Index));
11312 Index_Typ : Entity_Id;
11316 -- Minimal decoration
11318 Set_Ekind (Index_Con, E_Constant);
11319 Set_Entry_Index_Constant (Index, Index_Con);
11320 Set_Discriminal_Link (Index_Con, Index);
11322 -- Retrieve the bounds of the entry family
11324 High := Type_High_Bound (Etype (Index));
11325 Low := Type_Low_Bound (Etype (Index));
11327 -- In the simple case the entry family is given by a subtype
11328 -- mark and the index constant has the same type.
11330 if Is_Entity_Name (Original_Node (
11331 Discrete_Subtype_Definition (Parent (Index))))
11333 Index_Typ := Etype (Index);
11335 -- Otherwise a new subtype declaration is required
11338 High := Replace_Bound (High);
11339 Low := Replace_Bound (Low);
11342 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
11345 -- subtype Jnn is <Etype of Index> range Low .. High;
11348 Make_Subtype_Declaration (Loc,
11349 Defining_Identifier => Index_Typ,
11350 Subtype_Indication =>
11351 Make_Subtype_Indication (Loc,
11353 New_Reference_To (Base_Type (Etype (Index)), Loc),
11355 Make_Range_Constraint (Loc,
11356 Range_Expression =>
11357 Make_Range (Loc, Low, High))));
11361 Set_Etype (Index_Con, Index_Typ);
11363 -- Create the object which designates the index:
11364 -- J : constant Jnn :=
11365 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
11367 -- where Jnn is the subtype created above or the original type of
11368 -- the index, _E is a formal of the protected body subprogram and
11369 -- <index expr> is the index of the first family member.
11372 Make_Object_Declaration (Loc,
11373 Defining_Identifier => Index_Con,
11374 Constant_Present => True,
11375 Object_Definition =>
11376 New_Reference_To (Index_Typ, Loc),
11379 Make_Attribute_Reference (Loc,
11381 New_Reference_To (Index_Typ, Loc),
11382 Attribute_Name => Name_Val,
11384 Expressions => New_List (
11388 Make_Op_Subtract (Loc,
11390 New_Reference_To (E, Loc),
11392 Entry_Index_Expression (Loc,
11393 Defining_Identifier (Body_Nod),
11397 Make_Attribute_Reference (Loc,
11399 New_Reference_To (Index_Typ, Loc),
11400 Attribute_Name => Name_Pos,
11401 Expressions => New_List (
11402 Make_Attribute_Reference (Loc,
11404 New_Reference_To (Index_Typ, Loc),
11405 Attribute_Name => Name_First)))))));
11409 end Install_Private_Data_Declarations;
11411 ---------------------------------
11412 -- Is_Potentially_Large_Family --
11413 ---------------------------------
11415 function Is_Potentially_Large_Family
11416 (Base_Index : Entity_Id;
11417 Conctyp : Entity_Id;
11419 Hi : Node_Id) return Boolean
11422 return Scope (Base_Index) = Standard_Standard
11423 and then Base_Index = Base_Type (Standard_Integer)
11424 and then Has_Discriminants (Conctyp)
11426 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
11428 (Denotes_Discriminant (Lo, True)
11429 or else Denotes_Discriminant (Hi, True));
11430 end Is_Potentially_Large_Family;
11432 -------------------------------------
11433 -- Is_Private_Primitive_Subprogram --
11434 -------------------------------------
11436 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
11439 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
11440 and then Is_Private_Primitive (Id);
11441 end Is_Private_Primitive_Subprogram;
11447 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
11448 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
11449 Formal : Entity_Id;
11452 Formal := First_Formal (Bod_Subp);
11453 while Present (Formal) loop
11455 -- Look for formal parameter _E
11457 if Chars (Formal) = Name_uE then
11461 Next_Formal (Formal);
11464 -- A protected body subprogram should always have the parameter in
11467 raise Program_Error;
11470 --------------------------------
11471 -- Make_Initialize_Protection --
11472 --------------------------------
11474 function Make_Initialize_Protection
11475 (Protect_Rec : Entity_Id) return List_Id
11477 Loc : constant Source_Ptr := Sloc (Protect_Rec);
11481 Ptyp : constant Node_Id :=
11482 Corresponding_Concurrent_Type (Protect_Rec);
11484 L : constant List_Id := New_List;
11485 Has_Entry : constant Boolean := Has_Entries (Ptyp);
11486 Restricted : constant Boolean := Restricted_Profile;
11489 -- We may need two calls to properly initialize the object, one to
11490 -- Initialize_Protection, and possibly one to Install_Handlers if we
11491 -- have a pragma Attach_Handler.
11493 -- Get protected declaration. In the case of a task type declaration,
11494 -- this is simply the parent of the protected type entity. In the single
11495 -- protected object declaration, this parent will be the implicit type,
11496 -- and we can find the corresponding single protected object declaration
11497 -- by searching forward in the declaration list in the tree.
11499 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
11500 -- of this type should have been removed during semantic analysis.
11502 Pdec := Parent (Ptyp);
11503 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
11504 N_Single_Protected_Declaration)
11509 -- Now we can find the object definition from this declaration
11511 Pdef := Protected_Definition (Pdec);
11513 -- Build the parameter list for the call. Note that _Init is the name
11514 -- of the formal for the object to be initialized, which is the task
11515 -- value record itself.
11519 -- Object parameter. This is a pointer to the object of type
11520 -- Protection used by the GNARL to control the protected object.
11523 Make_Attribute_Reference (Loc,
11525 Make_Selected_Component (Loc,
11526 Prefix => Make_Identifier (Loc, Name_uInit),
11527 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11528 Attribute_Name => Name_Unchecked_Access));
11530 -- Priority parameter. Set to Unspecified_Priority unless there is a
11531 -- priority pragma, in which case we take the value from the pragma,
11532 -- or there is an interrupt pragma and no priority pragma, and we
11533 -- set the ceiling to Interrupt_Priority'Last, an implementation-
11534 -- defined value, see D.3(10).
11537 and then Has_Priority_Pragma (Pdef)
11540 Prio : constant Node_Id :=
11543 (Pragma_Argument_Associations
11544 (Find_Task_Or_Protected_Pragma
11545 (Pdef, Name_Priority))));
11549 -- If priority is a static expression, then we can duplicate it
11550 -- with no problem and simply append it to the argument list.
11552 if Is_Static_Expression (Prio) then
11554 Duplicate_Subexpr_No_Checks (Prio));
11556 -- Otherwise, the priority may be a per-object expression, if it
11557 -- depends on a discriminant of the type. In this case, create
11558 -- local variable to capture the expression. Note that it is
11559 -- really necessary to create this variable explicitly. It might
11560 -- be thought that removing side effects would the appropriate
11561 -- approach, but that could generate declarations improperly
11562 -- placed in the enclosing scope.
11564 -- Note: Use System.Any_Priority as the expected type for the
11565 -- non-static priority expression, in case the expression has not
11566 -- been analyzed yet (as occurs for example with pragma
11567 -- Interrupt_Priority).
11571 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
11574 Make_Object_Declaration (Loc,
11575 Defining_Identifier => Temp,
11576 Object_Definition =>
11577 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
11578 Expression => Relocate_Node (Prio)));
11580 Append_To (Args, New_Occurrence_Of (Temp, Loc));
11584 -- When no priority is specified but an xx_Handler pragma is, we default
11585 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
11587 elsif Has_Interrupt_Handler (Ptyp)
11588 or else Has_Attach_Handler (Ptyp)
11591 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
11593 -- Normal case, no priority or xx_Handler specified, default priority
11597 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11600 -- Test for Compiler_Info parameter. This parameter allows entry body
11601 -- procedures and barrier functions to be called from the runtime. It
11602 -- is a pointer to the record generated by the compiler to represent
11603 -- the protected object.
11606 or else Has_Interrupt_Handler (Ptyp)
11607 or else Has_Attach_Handler (Ptyp)
11608 or else Has_Interfaces (Protect_Rec)
11611 Pkg_Id : constant RTU_Id :=
11612 Corresponding_Runtime_Package (Ptyp);
11613 Called_Subp : RE_Id;
11617 when System_Tasking_Protected_Objects_Entries =>
11618 Called_Subp := RE_Initialize_Protection_Entries;
11620 when System_Tasking_Protected_Objects =>
11621 Called_Subp := RE_Initialize_Protection;
11623 when System_Tasking_Protected_Objects_Single_Entry =>
11624 Called_Subp := RE_Initialize_Protection_Entry;
11627 raise Program_Error;
11630 if Has_Entry or else not Restricted then
11632 Make_Attribute_Reference (Loc,
11633 Prefix => Make_Identifier (Loc, Name_uInit),
11634 Attribute_Name => Name_Address));
11637 -- Entry_Bodies parameter. This is a pointer to an array of
11638 -- pointers to the entry body procedures and barrier functions of
11639 -- the object. If the protected type has no entries this object
11640 -- will not exist, in this case, pass a null.
11643 P_Arr := Entry_Bodies_Array (Ptyp);
11646 Make_Attribute_Reference (Loc,
11647 Prefix => New_Reference_To (P_Arr, Loc),
11648 Attribute_Name => Name_Unrestricted_Access));
11650 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
11652 -- Find index mapping function (clumsy but ok for now)
11654 while Ekind (P_Arr) /= E_Function loop
11655 Next_Entity (P_Arr);
11659 Make_Attribute_Reference (Loc,
11661 New_Reference_To (P_Arr, Loc),
11662 Attribute_Name => Name_Unrestricted_Access));
11664 -- Build_Entry_Names generation flag. When set to true, the
11665 -- runtime will allocate an array to hold the string names
11666 -- of protected entries.
11668 if not Restricted_Profile then
11669 if Entry_Names_OK then
11671 New_Reference_To (Standard_True, Loc));
11674 New_Reference_To (Standard_False, Loc));
11679 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
11680 Append_To (Args, Make_Null (Loc));
11682 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
11683 Append_To (Args, Make_Null (Loc));
11684 Append_To (Args, Make_Null (Loc));
11685 Append_To (Args, New_Reference_To (Standard_False, Loc));
11689 Make_Procedure_Call_Statement (Loc,
11690 Name => New_Reference_To (RTE (Called_Subp), Loc),
11691 Parameter_Associations => Args));
11695 Make_Procedure_Call_Statement (Loc,
11696 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
11697 Parameter_Associations => Args));
11700 if Has_Attach_Handler (Ptyp) then
11702 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
11703 -- make the following call:
11705 -- Install_Handlers (_object,
11706 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11708 -- or, in the case of Ravenscar:
11710 -- Install_Restricted_Handlers
11711 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11714 Args : constant List_Id := New_List;
11715 Table : constant List_Id := New_List;
11716 Ritem : Node_Id := First_Rep_Item (Ptyp);
11719 -- Build the Attach_Handler table argument
11721 while Present (Ritem) loop
11722 if Nkind (Ritem) = N_Pragma
11723 and then Pragma_Name (Ritem) = Name_Attach_Handler
11726 Handler : constant Node_Id :=
11727 First (Pragma_Argument_Associations (Ritem));
11729 Interrupt : constant Node_Id := Next (Handler);
11730 Expr : constant Node_Id := Expression (Interrupt);
11734 Make_Aggregate (Loc, Expressions => New_List (
11735 Unchecked_Convert_To
11736 (RTE (RE_System_Interrupt_Id), Expr),
11737 Make_Attribute_Reference (Loc,
11738 Prefix => Make_Selected_Component (Loc,
11739 Make_Identifier (Loc, Name_uInit),
11740 Duplicate_Subexpr_No_Checks
11741 (Expression (Handler))),
11742 Attribute_Name => Name_Access))));
11746 Next_Rep_Item (Ritem);
11749 -- Append the table argument we just built
11751 Append_To (Args, Make_Aggregate (Loc, Table));
11753 -- Append the Install_Handlers (or Install_Restricted_Handlers)
11754 -- call to the statements.
11757 -- Call a simplified version of Install_Handlers to be used
11758 -- when the Ravenscar restrictions are in effect
11759 -- (Install_Restricted_Handlers).
11762 Make_Procedure_Call_Statement (Loc,
11765 (RTE (RE_Install_Restricted_Handlers), Loc),
11766 Parameter_Associations => Args));
11769 -- First, prepends the _object argument
11772 Make_Attribute_Reference (Loc,
11774 Make_Selected_Component (Loc,
11775 Prefix => Make_Identifier (Loc, Name_uInit),
11776 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11777 Attribute_Name => Name_Unchecked_Access));
11779 -- Then, insert call to Install_Handlers
11782 Make_Procedure_Call_Statement (Loc,
11783 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
11784 Parameter_Associations => Args));
11790 end Make_Initialize_Protection;
11792 ---------------------------
11793 -- Make_Task_Create_Call --
11794 ---------------------------
11796 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
11797 Loc : constant Source_Ptr := Sloc (Task_Rec);
11807 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
11808 Tnam := Chars (Ttyp);
11810 -- Get task declaration. In the case of a task type declaration, this is
11811 -- simply the parent of the task type entity. In the single task
11812 -- declaration, this parent will be the implicit type, and we can find
11813 -- the corresponding single task declaration by searching forward in the
11814 -- declaration list in the tree.
11816 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
11817 -- this type should have been removed during semantic analysis.
11819 Tdec := Parent (Ttyp);
11820 while not Nkind_In (Tdec, N_Task_Type_Declaration,
11821 N_Single_Task_Declaration)
11826 -- Now we can find the task definition from this declaration
11828 Tdef := Task_Definition (Tdec);
11830 -- Build the parameter list for the call. Note that _Init is the name
11831 -- of the formal for the object to be initialized, which is the task
11832 -- value record itself.
11836 -- Priority parameter. Set to Unspecified_Priority unless there is a
11837 -- priority pragma, in which case we take the value from the pragma.
11839 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
11841 Make_Selected_Component (Loc,
11842 Prefix => Make_Identifier (Loc, Name_uInit),
11843 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
11846 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11849 -- Optional Stack parameter
11851 if Restricted_Profile then
11853 -- If the stack has been preallocated by the expander then
11854 -- pass its address. Otherwise, pass a null address.
11856 if Preallocated_Stacks_On_Target then
11858 Make_Attribute_Reference (Loc,
11859 Prefix => Make_Selected_Component (Loc,
11860 Prefix => Make_Identifier (Loc, Name_uInit),
11862 Make_Identifier (Loc, Name_uStack)),
11863 Attribute_Name => Name_Address));
11867 New_Reference_To (RTE (RE_Null_Address), Loc));
11871 -- Size parameter. If no Storage_Size pragma is present, then
11872 -- the size is taken from the taskZ variable for the type, which
11873 -- is either Unspecified_Size, or has been reset by the use of
11874 -- a Storage_Size attribute definition clause. If a pragma is
11875 -- present, then the size is taken from the _Size field of the
11876 -- task value record, which was set from the pragma value.
11879 and then Has_Storage_Size_Pragma (Tdef)
11882 Make_Selected_Component (Loc,
11883 Prefix => Make_Identifier (Loc, Name_uInit),
11884 Selector_Name => Make_Identifier (Loc, Name_uSize)));
11888 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
11891 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
11892 -- Task_Info pragma, in which case we take the value from the pragma.
11895 and then Has_Task_Info_Pragma (Tdef)
11898 Make_Selected_Component (Loc,
11899 Prefix => Make_Identifier (Loc, Name_uInit),
11900 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
11904 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
11907 if not Restricted_Profile then
11909 -- Deadline parameter. If no Relative_Deadline pragma is present,
11910 -- then the deadline is Time_Span_Zero. If a pragma is present, then
11911 -- the deadline is taken from the _Relative_Deadline field of the
11912 -- task value record, which was set from the pragma value. Note that
11913 -- this parameter must not be generated for the restricted profiles
11914 -- since Ravenscar does not allow deadlines.
11916 -- Case where pragma Relative_Deadline applies: use given value
11918 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
11920 Make_Selected_Component (Loc,
11921 Prefix => Make_Identifier (Loc, Name_uInit),
11923 Make_Identifier (Loc, Name_uRelative_Deadline)));
11925 -- No pragma Relative_Deadline apply to the task
11929 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
11932 -- Number of entries. This is an expression of the form:
11934 -- n + _Init.a'Length + _Init.a'B'Length + ...
11936 -- where a,b... are the entry family names for the task definition
11939 Build_Entry_Count_Expression
11944 (Parent (Corresponding_Record_Type (Ttyp))))),
11946 Append_To (Args, Ecount);
11948 -- Master parameter. This is a reference to the _Master parameter of
11949 -- the initialization procedure, except in the case of the pragma
11950 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
11951 -- See comments in System.Tasking.Initialization.Init_RTS for the
11954 if Restriction_Active (No_Task_Hierarchy) = False then
11955 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
11957 Append_To (Args, Make_Integer_Literal (Loc, 3));
11961 -- State parameter. This is a pointer to the task body procedure. The
11962 -- required value is obtained by taking 'Unrestricted_Access of the task
11963 -- body procedure and converting it (with an unchecked conversion) to
11964 -- the type required by the task kernel. For further details, see the
11965 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
11966 -- than 'Address in order to avoid creating trampolines.
11969 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
11970 Subp_Ptr_Typ : constant Node_Id :=
11971 Create_Itype (E_Access_Subprogram_Type, Tdec);
11972 Ref : constant Node_Id := Make_Itype_Reference (Loc);
11975 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
11976 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
11978 -- Be sure to freeze a reference to the access-to-subprogram type,
11979 -- otherwise gigi will complain that it's in the wrong scope, because
11980 -- it's actually inside the init procedure for the record type that
11981 -- corresponds to the task type.
11983 -- This processing is causing a crash in the .NET/JVM back ends that
11984 -- is not yet understood, so skip it in these cases ???
11986 if VM_Target = No_VM then
11987 Set_Itype (Ref, Subp_Ptr_Typ);
11988 Append_Freeze_Action (Task_Rec, Ref);
11991 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
11992 Make_Qualified_Expression (Loc,
11993 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
11995 Make_Attribute_Reference (Loc,
11997 New_Occurrence_Of (Body_Proc, Loc),
11998 Attribute_Name => Name_Unrestricted_Access))));
12000 -- For the .NET/JVM cases revert to the original code below ???
12004 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12005 Make_Attribute_Reference (Loc,
12007 New_Occurrence_Of (Body_Proc, Loc),
12008 Attribute_Name => Name_Address)));
12012 -- Discriminants parameter. This is just the address of the task
12013 -- value record itself (which contains the discriminant values
12016 Make_Attribute_Reference (Loc,
12017 Prefix => Make_Identifier (Loc, Name_uInit),
12018 Attribute_Name => Name_Address));
12020 -- Elaborated parameter. This is an access to the elaboration Boolean
12023 Make_Attribute_Reference (Loc,
12024 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12025 Attribute_Name => Name_Unchecked_Access));
12027 -- Chain parameter. This is a reference to the _Chain parameter of
12028 -- the initialization procedure.
12030 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12032 -- Task name parameter. Take this from the _Task_Id parameter to the
12033 -- init call unless there is a Task_Name pragma, in which case we take
12034 -- the value from the pragma.
12037 and then Has_Task_Name_Pragma (Tdef)
12039 -- Copy expression in full, because it may be dynamic and have
12045 (Pragma_Argument_Associations
12046 (Find_Task_Or_Protected_Pragma
12047 (Tdef, Name_Task_Name))))));
12050 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12053 -- Created_Task parameter. This is the _Task_Id field of the task
12057 Make_Selected_Component (Loc,
12058 Prefix => Make_Identifier (Loc, Name_uInit),
12059 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12061 -- Build_Entry_Names generation flag. When set to true, the runtime
12062 -- will allocate an array to hold the string names of task entries.
12064 if not Restricted_Profile then
12065 if Has_Entries (Ttyp)
12066 and then Entry_Names_OK
12068 Append_To (Args, New_Reference_To (Standard_True, Loc));
12070 Append_To (Args, New_Reference_To (Standard_False, Loc));
12074 if Restricted_Profile then
12075 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12077 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12081 Make_Procedure_Call_Statement (Loc,
12083 Parameter_Associations => Args);
12084 end Make_Task_Create_Call;
12086 ------------------------------
12087 -- Next_Protected_Operation --
12088 ------------------------------
12090 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12094 Next_Op := Next (N);
12095 while Present (Next_Op)
12096 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12102 end Next_Protected_Operation;
12104 ---------------------
12105 -- Null_Statements --
12106 ---------------------
12108 function Null_Statements (Stats : List_Id) return Boolean is
12112 Stmt := First (Stats);
12113 while Nkind (Stmt) /= N_Empty
12114 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12116 (Nkind (Stmt) = N_Pragma
12117 and then (Pragma_Name (Stmt) = Name_Unreferenced
12119 Pragma_Name (Stmt) = Name_Unmodified
12121 Pragma_Name (Stmt) = Name_Warnings)))
12126 return Nkind (Stmt) = N_Empty;
12127 end Null_Statements;
12129 --------------------------
12130 -- Parameter_Block_Pack --
12131 --------------------------
12133 function Parameter_Block_Pack
12135 Blk_Typ : Entity_Id;
12139 Stmts : List_Id) return Node_Id
12141 Actual : Entity_Id;
12142 Expr : Node_Id := Empty;
12143 Formal : Entity_Id;
12144 Has_Param : Boolean := False;
12147 Temp_Asn : Node_Id;
12148 Temp_Nam : Node_Id;
12151 Actual := First (Actuals);
12152 Formal := Defining_Identifier (First (Formals));
12153 Params := New_List;
12155 while Present (Actual) loop
12156 if Is_By_Copy_Type (Etype (Actual)) then
12158 -- Jnn : aliased <formal-type>
12161 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
12164 Make_Object_Declaration (Loc,
12167 Defining_Identifier =>
12169 Object_Definition =>
12170 New_Reference_To (Etype (Formal), Loc)));
12172 if Ekind (Formal) /= E_Out_Parameter then
12178 New_Reference_To (Temp_Nam, Loc);
12180 Set_Assignment_OK (Temp_Asn);
12183 Make_Assignment_Statement (Loc,
12187 New_Copy_Tree (Actual)));
12191 -- Jnn'unchecked_access
12194 Make_Attribute_Reference (Loc,
12196 Name_Unchecked_Access,
12198 New_Reference_To (Temp_Nam, Loc)));
12202 -- The controlling parameter is omitted
12205 if not Is_Controlling_Actual (Actual) then
12207 Make_Reference (Loc, New_Copy_Tree (Actual)));
12213 Next_Actual (Actual);
12214 Next_Formal_With_Extras (Formal);
12218 Expr := Make_Aggregate (Loc, Params);
12223 -- J1'unchecked_access;
12224 -- <actual2>'reference;
12227 P := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
12230 Make_Object_Declaration (Loc,
12231 Defining_Identifier =>
12233 Object_Definition =>
12234 New_Reference_To (Blk_Typ, Loc),
12239 end Parameter_Block_Pack;
12241 ----------------------------
12242 -- Parameter_Block_Unpack --
12243 ----------------------------
12245 function Parameter_Block_Unpack
12249 Formals : List_Id) return List_Id
12251 Actual : Entity_Id;
12253 Formal : Entity_Id;
12254 Has_Asnmt : Boolean := False;
12255 Result : constant List_Id := New_List;
12258 Actual := First (Actuals);
12259 Formal := Defining_Identifier (First (Formals));
12260 while Present (Actual) loop
12261 if Is_By_Copy_Type (Etype (Actual))
12262 and then Ekind (Formal) /= E_In_Parameter
12265 -- <actual> := P.<formal>;
12268 Make_Assignment_Statement (Loc,
12272 Make_Explicit_Dereference (Loc,
12273 Make_Selected_Component (Loc,
12275 New_Reference_To (P, Loc),
12277 Make_Identifier (Loc, Chars (Formal)))));
12279 Set_Assignment_OK (Name (Asnmt));
12280 Append_To (Result, Asnmt);
12285 Next_Actual (Actual);
12286 Next_Formal_With_Extras (Formal);
12292 return New_List (Make_Null_Statement (Loc));
12294 end Parameter_Block_Unpack;
12296 ----------------------
12297 -- Set_Discriminals --
12298 ----------------------
12300 procedure Set_Discriminals (Dec : Node_Id) is
12303 D_Minal : Entity_Id;
12306 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
12307 Pdef := Defining_Identifier (Dec);
12309 if Has_Discriminants (Pdef) then
12310 D := First_Discriminant (Pdef);
12311 while Present (D) loop
12313 Make_Defining_Identifier (Sloc (D),
12314 Chars => New_External_Name (Chars (D), 'D'));
12316 Set_Ekind (D_Minal, E_Constant);
12317 Set_Etype (D_Minal, Etype (D));
12318 Set_Scope (D_Minal, Pdef);
12319 Set_Discriminal (D, D_Minal);
12320 Set_Discriminal_Link (D_Minal, D);
12322 Next_Discriminant (D);
12325 end Set_Discriminals;
12327 -----------------------
12328 -- Trivial_Accept_OK --
12329 -----------------------
12331 function Trivial_Accept_OK return Boolean is
12333 case Opt.Task_Dispatching_Policy is
12335 -- If we have the default task dispatching policy in effect, we can
12336 -- definitely do the optimization (one way of looking at this is to
12337 -- think of the formal definition of the default policy being allowed
12338 -- to run any task it likes after a rendezvous, so even if notionally
12339 -- a full rescheduling occurs, we can say that our dispatching policy
12340 -- (i.e. the default dispatching policy) reorders the queue to be the
12341 -- same as just before the call.
12346 -- FIFO_Within_Priorities certainly does not permit this
12347 -- optimization since the Rendezvous is a scheduling action that may
12348 -- require some other task to be run.
12353 -- For now, disallow the optimization for all other policies. This
12354 -- may be over-conservative, but it is certainly not incorrect.
12360 end Trivial_Accept_OK;