1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Ch3; use Exp_Ch3;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Ch6; use Exp_Ch6;
34 with Exp_Dbug; use Exp_Dbug;
35 with Exp_Disp; use Exp_Disp;
36 with Exp_Sel; use Exp_Sel;
37 with Exp_Smem; use Exp_Smem;
38 with Exp_Tss; use Exp_Tss;
39 with Exp_Util; use Exp_Util;
40 with Freeze; use Freeze;
42 with Itypes; use Itypes;
43 with Namet; use Namet;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Ch11; use Sem_Ch11;
55 with Sem_Elab; use Sem_Elab;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Res; use Sem_Res;
58 with Sem_Util; use Sem_Util;
59 with Sinfo; use Sinfo;
60 with Snames; use Snames;
61 with Stand; use Stand;
62 with Stringt; use Stringt;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Uintp; use Uintp;
67 package body Exp_Ch9 is
69 -- The following constant establishes the upper bound for the index of
70 -- an entry family. It is used to limit the allocated size of protected
71 -- types with defaulted discriminant of an integer type, when the bound
72 -- of some entry family depends on a discriminant. The limitation to
73 -- entry families of 128K should be reasonable in all cases, and is a
74 -- documented implementation restriction. It will be lifted when protected
75 -- entry families are re-implemented as a single ordered queue.
77 Entry_Family_Bound : constant Int := 2**16;
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 function Actual_Index_Expression
87 Tsk : Entity_Id) return Node_Id;
88 -- Compute the index position for an entry call. Tsk is the target task. If
89 -- the bounds of some entry family depend on discriminants, the expression
90 -- computed by this function uses the discriminants of the target task.
92 procedure Add_Object_Pointer
96 -- Prepend an object pointer declaration to the declaration list Decls.
97 -- This object pointer is initialized to a type conversion of the System.
98 -- Address pointer passed to entry barrier functions and entry body
101 procedure Add_Formal_Renamings
106 -- Create renaming declarations for the formals, inside the procedure that
107 -- implements an entry body. The renamings make the original names of the
108 -- formals accessible to gdb, and serve no other purpose.
109 -- Spec is the specification of the procedure being built.
110 -- Decls is the list of declarations to be enhanced.
111 -- Ent is the entity for the original entry body.
113 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
114 -- Transform accept statement into a block with added exception handler.
115 -- Used both for simple accept statements and for accept alternatives in
116 -- select statements. Astat is the accept statement.
118 function Build_Barrier_Function
121 Pid : Node_Id) return Node_Id;
122 -- Build the function body returning the value of the barrier expression
123 -- for the specified entry body.
125 function Build_Barrier_Function_Specification
127 Def_Id : Entity_Id) return Node_Id;
128 -- Build a specification for a function implementing the protected entry
129 -- barrier of the specified entry body.
131 function Build_Entry_Count_Expression
132 (Concurrent_Type : Node_Id;
133 Component_List : List_Id;
134 Loc : Source_Ptr) return Node_Id;
135 -- Compute number of entries for concurrent object. This is a count of
136 -- simple entries, followed by an expression that computes the length
137 -- of the range of each entry family. A single array with that size is
138 -- allocated for each concurrent object of the type.
140 function Build_Parameter_Block
144 Decls : List_Id) return Entity_Id;
145 -- Generate an access type for each actual parameter in the list Actuals.
146 -- Create an encapsulating record that contains all the actuals and return
147 -- its type. Generate:
148 -- type Ann1 is access all <actual1-type>
150 -- type AnnN is access all <actualN-type>
151 -- type Pnn is record
157 procedure Build_Wrapper_Bodies
161 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
162 -- record of a concurrent type. N is the insertion node where all bodies
163 -- will be placed. This routine builds the bodies of the subprograms which
164 -- serve as an indirection mechanism to overriding primitives of concurrent
165 -- types, entries and protected procedures. Any new body is analyzed.
167 procedure Build_Wrapper_Specs
171 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
172 -- record of a concurrent type. N is the insertion node where all specs
173 -- will be placed. This routine builds the specs of the subprograms which
174 -- serve as an indirection mechanism to overriding primitives of concurrent
175 -- types, entries and protected procedures. Any new spec is analyzed.
177 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
178 -- Build the function that translates the entry index in the call
179 -- (which depends on the size of entry families) into an index into the
180 -- Entry_Bodies_Array, to determine the body and barrier function used
181 -- in a protected entry call. A pointer to this function appears in every
184 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
185 -- Build subprogram declaration for previous one
187 function Build_Protected_Entry
190 Pid : Node_Id) return Node_Id;
191 -- Build the procedure implementing the statement sequence of the specified
194 function Build_Protected_Entry_Specification
197 Ent_Id : Entity_Id) return Node_Id;
198 -- Build a specification for the procedure implementing the statements of
199 -- the specified entry body. Add attributes associating it with the entry
200 -- defining identifier Ent_Id.
202 function Build_Protected_Spec
204 Obj_Type : Entity_Id;
206 Unprotected : Boolean := False) return List_Id;
207 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
208 -- Subprogram_Type. Builds signature of protected subprogram, adding the
209 -- formal that corresponds to the object itself. For an access to protected
210 -- subprogram, there is no object type to specify, so the parameter has
211 -- type Address and mode In. An indirect call through such a pointer will
212 -- convert the address to a reference to the actual object. The object is
213 -- a limited record and therefore a by_reference type.
215 function Build_Protected_Subprogram_Body
218 N_Op_Spec : Node_Id) return Node_Id;
219 -- This function is used to construct the protected version of a protected
220 -- subprogram. Its statement sequence first defers abort, then locks
221 -- the associated protected object, and then enters a block that contains
222 -- a call to the unprotected version of the subprogram (for details, see
223 -- Build_Unprotected_Subprogram_Body). This block statement requires
224 -- a cleanup handler that unlocks the object in all cases.
225 -- (see Exp_Ch7.Expand_Cleanup_Actions).
227 function Build_Selected_Name
229 Selector : Entity_Id;
230 Append_Char : Character := ' ') return Name_Id;
231 -- Build a name in the form of Prefix__Selector, with an optional
232 -- character appended. This is used for internal subprograms generated
233 -- for operations of protected types, including barrier functions.
234 -- For the subprograms generated for entry bodies and entry barriers,
235 -- the generated name includes a sequence number that makes names
236 -- unique in the presence of entry overloading. This is necessary
237 -- because entry body procedures and barrier functions all have the
240 procedure Build_Simple_Entry_Call
245 -- Some comments here would be useful ???
247 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
248 -- This routine constructs a specification for the procedure that we will
249 -- build for the task body for task type T. The spec has the form:
251 -- procedure tnameB (_Task : access tnameV);
253 -- where name is the character name taken from the task type entity that
254 -- is passed as the argument to the procedure, and tnameV is the task
255 -- value type that is associated with the task type.
257 function Build_Unprotected_Subprogram_Body
259 Pid : Node_Id) return Node_Id;
260 -- This routine constructs the unprotected version of a protected
261 -- subprogram body, which is contains all of the code in the
262 -- original, unexpanded body. This is the version of the protected
263 -- subprogram that is called from all protected operations on the same
264 -- object, including the protected version of the same subprogram.
266 procedure Collect_Entry_Families
269 Current_Node : in out Node_Id;
270 Conctyp : Entity_Id);
271 -- For each entry family in a concurrent type, create an anonymous array
272 -- type of the right size, and add a component to the corresponding_record.
274 function Concurrent_Object
275 (Spec_Id : Entity_Id;
276 Conc_Typ : Entity_Id) return Entity_Id;
277 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
278 -- the entity associated with the concurrent object in the Protected_Body_
279 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
280 -- denotes formal parameter _O, _object or _task.
282 function Copy_Result_Type (Res : Node_Id) return Node_Id;
283 -- Copy the result type of a function specification, when building the
284 -- internal operation corresponding to a protected function, or when
285 -- expanding an access to protected function. If the result is an anonymous
286 -- access to subprogram itself, we need to create a new signature with the
287 -- same parameter names and the same resolved types, but with new entities
290 procedure Debug_Private_Data_Declarations (Decls : List_Id);
291 -- Decls is a list which may contain the declarations created by Install_
292 -- Private_Data_Declarations. All generated entities are marked as needing
293 -- debug info and debug nodes are manually generation where necessary. This
294 -- step of the expansion must to be done after private data has been moved
295 -- to its final resting scope to ensure proper visibility of debug objects.
297 function Family_Offset
302 Cap : Boolean) return Node_Id;
303 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
304 -- an accept statement, or the upper bound in the discrete subtype of
305 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
306 -- the concurrent type of the entry. If Cap is true, the result is
307 -- capped according to Entry_Family_Bound.
314 Cap : Boolean) return Node_Id;
315 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
316 -- a family, and handle properly the superflat case. This is equivalent
317 -- to the use of 'Length on the index type, but must use Family_Offset
318 -- to handle properly the case of bounds that depend on discriminants.
319 -- If Cap is true, the result is capped according to Entry_Family_Bound.
321 procedure Extract_Dispatching_Call
323 Call_Ent : out Entity_Id;
324 Object : out Entity_Id;
325 Actuals : out List_Id;
326 Formals : out List_Id);
327 -- Given a dispatching call, extract the entity of the name of the call,
328 -- its object parameter, its actual parameters and the formal parameters
329 -- of the overridden interface-level version.
331 procedure Extract_Entry
333 Concval : out Node_Id;
335 Index : out Node_Id);
336 -- Given an entry call, returns the associated concurrent object,
337 -- the entry name, and the entry family index.
339 function Find_Task_Or_Protected_Pragma
341 P : Name_Id) return Node_Id;
342 -- Searches the task or protected definition T for the first occurrence
343 -- of the pragma whose name is given by P. The caller has ensured that
344 -- the pragma is present in the task definition. A special case is that
345 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
346 -- ??? Should be implemented with the rep item chain mechanism.
348 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
349 -- Given a subprogram identifier, return the entity which is associated
350 -- with the protection entry index in the Protected_Body_Subprogram or the
351 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
354 function Is_Potentially_Large_Family
355 (Base_Index : Entity_Id;
358 Hi : Node_Id) return Boolean;
360 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
361 -- Determine whether Id is a function or a procedure and is marked as a
362 -- private primitive.
364 function Null_Statements (Stats : List_Id) return Boolean;
365 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
366 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
367 -- well to still count as null. Returns True for a null sequence. The
368 -- argument is the list of statements from the DO-END sequence.
370 function Parameter_Block_Pack
376 Stmts : List_Id) return Entity_Id;
377 -- Set the components of the generated parameter block with the values of
378 -- the actual parameters. Generate aliased temporaries to capture the
379 -- values for types that are passed by copy. Otherwise generate a reference
380 -- to the actual's value. Return the address of the aggregate block.
382 -- Jnn1 : alias <formal-type1>;
383 -- Jnn1 := <actual1>;
386 -- Jnn1'unchecked_access;
387 -- <actual2>'reference;
390 function Parameter_Block_Unpack
394 Formals : List_Id) return List_Id;
395 -- Retrieve the values of the components from the parameter block and
396 -- assign then to the original actual parameters. Generate:
397 -- <actual1> := P.<formal1>;
399 -- <actualN> := P.<formalN>;
401 function Trivial_Accept_OK return Boolean;
402 -- If there is no DO-END block for an accept, or if the DO-END block has
403 -- only null statements, then it is possible to do the Rendezvous with much
404 -- less overhead using the Accept_Trivial routine in the run-time library.
405 -- However, this is not always a valid optimization. Whether it is valid or
406 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
407 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
408 -- a rescheduling is required, so this optimization is not allowed. This
409 -- function returns True if the optimization is permitted.
411 -----------------------------
412 -- Actual_Index_Expression --
413 -----------------------------
415 function Actual_Index_Expression
419 Tsk : Entity_Id) return Node_Id
421 Ttyp : constant Entity_Id := Etype (Tsk);
429 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
430 -- Compute difference between bounds of entry family
432 --------------------------
433 -- Actual_Family_Offset --
434 --------------------------
436 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
438 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
439 -- Replace a reference to a discriminant with a selected component
440 -- denoting the discriminant of the target task.
442 -----------------------------
443 -- Actual_Discriminant_Ref --
444 -----------------------------
446 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
447 Typ : constant Entity_Id := Etype (Bound);
451 if not Is_Entity_Name (Bound)
452 or else Ekind (Entity (Bound)) /= E_Discriminant
454 if Nkind (Bound) = N_Attribute_Reference then
457 B := New_Copy_Tree (Bound);
462 Make_Selected_Component (Sloc,
463 Prefix => New_Copy_Tree (Tsk),
464 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
466 Analyze_And_Resolve (B, Typ);
470 Make_Attribute_Reference (Sloc,
471 Attribute_Name => Name_Pos,
472 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
473 Expressions => New_List (B));
474 end Actual_Discriminant_Ref;
476 -- Start of processing for Actual_Family_Offset
480 Make_Op_Subtract (Sloc,
481 Left_Opnd => Actual_Discriminant_Ref (Hi),
482 Right_Opnd => Actual_Discriminant_Ref (Lo));
483 end Actual_Family_Offset;
485 -- Start of processing for Actual_Index_Expression
488 -- The queues of entries and entry families appear in textual order in
489 -- the associated record. The entry index is computed as the sum of the
490 -- number of queues for all entries that precede the designated one, to
491 -- which is added the index expression, if this expression denotes a
492 -- member of a family.
494 -- The following is a place holder for the count of simple entries
496 Num := Make_Integer_Literal (Sloc, 1);
498 -- We construct an expression which is a series of addition operations.
499 -- See comments in Entry_Index_Expression, which is identical in
502 if Present (Index) then
503 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
510 Actual_Family_Offset (
511 Make_Attribute_Reference (Sloc,
512 Attribute_Name => Name_Pos,
513 Prefix => New_Reference_To (Base_Type (S), Sloc),
514 Expressions => New_List (Relocate_Node (Index))),
515 Type_Low_Bound (S)));
520 -- Now add lengths of preceding entries and entry families
522 Prev := First_Entity (Ttyp);
524 while Chars (Prev) /= Chars (Ent)
525 or else (Ekind (Prev) /= Ekind (Ent))
526 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
528 if Ekind (Prev) = E_Entry then
529 Set_Intval (Num, Intval (Num) + 1);
531 elsif Ekind (Prev) = E_Entry_Family then
533 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
535 -- The need for the following full view retrieval stems from
536 -- this complex case of nested generics and tasking:
539 -- type Formal_Index is range <>;
542 -- type Index is private;
549 -- type Index is new Formal_Index range 1 .. 10;
552 -- package body Outer is
554 -- entry Fam (Index); -- (2)
557 -- package body Inner is -- (3)
565 -- We are currently building the index expression for the entry
566 -- call "T.E" (1). Part of the expansion must mention the range
567 -- of the discrete type "Index" (2) of entry family "Fam".
568 -- However only the private view of type "Index" is available to
569 -- the inner generic (3) because there was no prior mention of
570 -- the type inside "Inner". This visibility requirement is
571 -- implicit and cannot be detected during the construction of
572 -- the generic trees and needs special handling.
575 and then Is_Private_Type (S)
576 and then Present (Full_View (S))
581 Lo := Type_Low_Bound (S);
582 Hi := Type_High_Bound (S);
590 Actual_Family_Offset (Hi, Lo),
592 Make_Integer_Literal (Sloc, 1)));
594 -- Other components are anonymous types to be ignored
604 end Actual_Index_Expression;
606 --------------------------
607 -- Add_Formal_Renamings --
608 --------------------------
610 procedure Add_Formal_Renamings
616 Ptr : constant Entity_Id :=
618 (Next (First (Parameter_Specifications (Spec))));
619 -- The name of the formal that holds the address of the parameter block
628 Formal := First_Formal (Ent);
629 while Present (Formal) loop
630 Comp := Entry_Component (Formal);
632 Make_Defining_Identifier (Sloc (Formal),
633 Chars => Chars (Formal));
634 Set_Etype (New_F, Etype (Formal));
635 Set_Scope (New_F, Ent);
637 -- Now we set debug info needed on New_F even though it does not
638 -- come from source, so that the debugger will get the right
639 -- information for these generated names.
641 Set_Debug_Info_Needed (New_F);
643 if Ekind (Formal) = E_In_Parameter then
644 Set_Ekind (New_F, E_Constant);
646 Set_Ekind (New_F, E_Variable);
647 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
650 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
653 Make_Object_Renaming_Declaration (Loc,
654 Defining_Identifier => New_F,
656 New_Reference_To (Etype (Formal), Loc),
658 Make_Explicit_Dereference (Loc,
659 Make_Selected_Component (Loc,
661 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
662 Make_Identifier (Loc, Chars (Ptr))),
664 New_Reference_To (Comp, Loc))));
666 Append (Decl, Decls);
667 Set_Renamed_Object (Formal, New_F);
668 Next_Formal (Formal);
670 end Add_Formal_Renamings;
672 ------------------------
673 -- Add_Object_Pointer --
674 ------------------------
676 procedure Add_Object_Pointer
678 Conc_Typ : Entity_Id;
681 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
686 -- Create the renaming declaration for the Protection object of a
687 -- protected type. _Object is used by Complete_Entry_Body.
688 -- ??? An attempt to make this a renaming was unsuccessful.
690 -- Build the entity for the access type
693 Make_Defining_Identifier (Loc,
694 New_External_Name (Chars (Rec_Typ), 'P'));
697 -- _object : poVP := poVP!O;
700 Make_Object_Declaration (Loc,
701 Defining_Identifier =>
702 Make_Defining_Identifier (Loc, Name_uObject),
704 New_Reference_To (Obj_Ptr, Loc),
706 Unchecked_Convert_To (Obj_Ptr,
707 Make_Identifier (Loc, Name_uO)));
708 Set_Debug_Info_Needed (Defining_Identifier (Decl));
709 Prepend_To (Decls, Decl);
712 -- type poVP is access poV;
715 Make_Full_Type_Declaration (Loc,
716 Defining_Identifier =>
719 Make_Access_To_Object_Definition (Loc,
720 Subtype_Indication =>
721 New_Reference_To (Rec_Typ, Loc)));
722 Set_Debug_Info_Needed (Defining_Identifier (Decl));
723 Prepend_To (Decls, Decl);
724 end Add_Object_Pointer;
726 -----------------------
727 -- Build_Accept_Body --
728 -----------------------
730 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
731 Loc : constant Source_Ptr := Sloc (Astat);
732 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
739 -- At the end of the statement sequence, Complete_Rendezvous is called.
740 -- A label skipping the Complete_Rendezvous, and all other accept
741 -- processing, has already been added for the expansion of requeue
742 -- statements. The Sloc is copied from the last statement since it
743 -- is really part of this last statement.
747 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
748 Insert_Before (Last (Statements (Stats)), Call);
751 -- If exception handlers are present, then append Complete_Rendezvous
752 -- calls to the handlers, and construct the required outer block. As
753 -- above, the Sloc is copied from the last statement in the sequence.
755 if Present (Exception_Handlers (Stats)) then
756 Hand := First (Exception_Handlers (Stats));
757 while Present (Hand) loop
760 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
761 Append (Call, Statements (Hand));
767 Make_Handled_Sequence_Of_Statements (Loc,
768 Statements => New_List (
769 Make_Block_Statement (Loc,
770 Handled_Statement_Sequence => Stats)));
776 -- At this stage we know that the new statement sequence does not
777 -- have an exception handler part, so we supply one to call
778 -- Exceptional_Complete_Rendezvous. This handler is
780 -- when all others =>
781 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
783 -- We handle Abort_Signal to make sure that we properly catch the abort
784 -- case and wake up the caller.
786 Ohandle := Make_Others_Choice (Loc);
787 Set_All_Others (Ohandle);
789 Set_Exception_Handlers (New_S,
791 Make_Implicit_Exception_Handler (Loc,
792 Exception_Choices => New_List (Ohandle),
794 Statements => New_List (
795 Make_Procedure_Call_Statement (Sloc (Stats),
796 Name => New_Reference_To (
797 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
798 Parameter_Associations => New_List (
799 Make_Function_Call (Sloc (Stats),
800 Name => New_Reference_To (
801 RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
803 Set_Parent (New_S, Astat); -- temp parent for Analyze call
804 Analyze_Exception_Handlers (Exception_Handlers (New_S));
805 Expand_Exception_Handlers (New_S);
807 -- Exceptional_Complete_Rendezvous must be called with abort
808 -- still deferred, which is the case for a "when all others" handler.
811 end Build_Accept_Body;
813 -----------------------------------
814 -- Build_Activation_Chain_Entity --
815 -----------------------------------
817 procedure Build_Activation_Chain_Entity (N : Node_Id) is
823 -- Loop to find enclosing construct containing activation chain variable
827 while not Nkind_In (P, N_Subprogram_Body,
828 N_Package_Declaration,
832 N_Extended_Return_Statement)
837 -- If we are in a package body, the activation chain variable is
838 -- declared in the body, but the Activation_Chain_Entity is attached
841 if Nkind (P) = N_Package_Body then
842 Decls := Declarations (P);
843 P := Unit_Declaration_Node (Corresponding_Spec (P));
845 elsif Nkind (P) = N_Package_Declaration then
846 Decls := Visible_Declarations (Specification (P));
848 elsif Nkind (P) = N_Extended_Return_Statement then
849 Decls := Return_Object_Declarations (P);
852 Decls := Declarations (P);
855 -- If activation chain entity not already declared, declare it
857 if Nkind (P) = N_Extended_Return_Statement
858 or else No (Activation_Chain_Entity (P))
860 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
862 -- Note: An extended return statement is not really a task activator,
863 -- but it does have an activation chain on which to store the tasks
864 -- temporarily. On successful return, the tasks on this chain are
865 -- moved to the chain passed in by the caller. We do not build an
866 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
867 -- because we do not want to build a call to Activate_Tasks. Task
868 -- activation is the responsibility of the caller.
870 if Nkind (P) /= N_Extended_Return_Statement then
871 Set_Activation_Chain_Entity (P, Chain);
875 Make_Object_Declaration (Sloc (P),
876 Defining_Identifier => Chain,
877 Aliased_Present => True,
879 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
881 Analyze (First (Decls));
883 end Build_Activation_Chain_Entity;
885 ----------------------------
886 -- Build_Barrier_Function --
887 ----------------------------
889 function Build_Barrier_Function
892 Pid : Node_Id) return Node_Id
894 Loc : constant Source_Ptr := Sloc (N);
895 Func_Id : constant Entity_Id := Barrier_Function (Ent);
896 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
897 Op_Decls : constant List_Id := New_List;
901 -- Add a declaration for the Protection object, renaming declarations
902 -- for the discriminals and privals and finally a declaration for the
903 -- entry family index (if applicable).
905 Install_Private_Data_Declarations
906 (Loc, Func_Id, Pid, N, Op_Decls, True, Ekind (Ent) = E_Entry_Family);
908 -- Note: the condition in the barrier function needs to be properly
909 -- processed for the C/Fortran boolean possibility, but this happens
910 -- automatically since the return statement does this normalization.
913 Make_Subprogram_Body (Loc,
915 Build_Barrier_Function_Specification (Loc,
916 Make_Defining_Identifier (Loc, Chars (Func_Id))),
917 Declarations => Op_Decls,
918 Handled_Statement_Sequence =>
919 Make_Handled_Sequence_Of_Statements (Loc,
920 Statements => New_List (
921 Make_Simple_Return_Statement (Loc,
922 Expression => Condition (Ent_Formals)))));
923 Set_Is_Entry_Barrier_Function (Func_Body);
926 end Build_Barrier_Function;
928 ------------------------------------------
929 -- Build_Barrier_Function_Specification --
930 ------------------------------------------
932 function Build_Barrier_Function_Specification
934 Def_Id : Entity_Id) return Node_Id
937 Set_Debug_Info_Needed (Def_Id);
939 return Make_Function_Specification (Loc,
940 Defining_Unit_Name => Def_Id,
941 Parameter_Specifications => New_List (
942 Make_Parameter_Specification (Loc,
943 Defining_Identifier =>
944 Make_Defining_Identifier (Loc, Name_uO),
946 New_Reference_To (RTE (RE_Address), Loc)),
948 Make_Parameter_Specification (Loc,
949 Defining_Identifier =>
950 Make_Defining_Identifier (Loc, Name_uE),
952 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
955 New_Reference_To (Standard_Boolean, Loc));
956 end Build_Barrier_Function_Specification;
958 --------------------------
959 -- Build_Call_With_Task --
960 --------------------------
962 function Build_Call_With_Task
964 E : Entity_Id) return Node_Id
966 Loc : constant Source_Ptr := Sloc (N);
969 Make_Function_Call (Loc,
970 Name => New_Reference_To (E, Loc),
971 Parameter_Associations => New_List (Concurrent_Ref (N)));
972 end Build_Call_With_Task;
974 --------------------------------
975 -- Build_Corresponding_Record --
976 --------------------------------
978 function Build_Corresponding_Record
981 Loc : Source_Ptr) return Node_Id
983 Rec_Ent : constant Entity_Id :=
984 Make_Defining_Identifier
985 (Loc, New_External_Name (Chars (Ctyp), 'V'));
988 New_Disc : Entity_Id;
992 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
993 Set_Ekind (Rec_Ent, E_Record_Type);
994 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
995 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
996 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
997 Set_Stored_Constraint (Rec_Ent, No_Elist);
1000 -- Use discriminals to create list of discriminants for record, and
1001 -- create new discriminals for use in default expressions, etc. It is
1002 -- worth noting that a task discriminant gives rise to 5 entities;
1004 -- a) The original discriminant.
1005 -- b) The discriminal for use in the task.
1006 -- c) The discriminant of the corresponding record.
1007 -- d) The discriminal for the init proc of the corresponding record.
1008 -- e) The local variable that renames the discriminant in the procedure
1009 -- for the task body.
1011 -- In fact the discriminals b) are used in the renaming declarations
1012 -- for e). See details in einfo (Handling of Discriminants).
1014 if Present (Discriminant_Specifications (N)) then
1016 Disc := First_Discriminant (Ctyp);
1018 while Present (Disc) loop
1019 New_Disc := CR_Discriminant (Disc);
1022 Make_Discriminant_Specification (Loc,
1023 Defining_Identifier => New_Disc,
1024 Discriminant_Type =>
1025 New_Occurrence_Of (Etype (Disc), Loc),
1027 New_Copy (Discriminant_Default_Value (Disc))));
1029 Next_Discriminant (Disc);
1036 -- Now we can construct the record type declaration. Note that this
1037 -- record is "limited tagged". It is "limited" to reflect the underlying
1038 -- limitedness of the task or protected object that it represents, and
1039 -- ensuring for example that it is properly passed by reference. It is
1040 -- "tagged" to give support to dispatching calls through interfaces (Ada
1044 Make_Full_Type_Declaration (Loc,
1045 Defining_Identifier => Rec_Ent,
1046 Discriminant_Specifications => Dlist,
1048 Make_Record_Definition (Loc,
1050 Make_Component_List (Loc,
1051 Component_Items => Cdecls),
1053 Ada_Version >= Ada_05 and then Is_Tagged_Type (Ctyp),
1054 Limited_Present => True));
1055 end Build_Corresponding_Record;
1057 ----------------------------------
1058 -- Build_Entry_Count_Expression --
1059 ----------------------------------
1061 function Build_Entry_Count_Expression
1062 (Concurrent_Type : Node_Id;
1063 Component_List : List_Id;
1064 Loc : Source_Ptr) return Node_Id
1076 -- Count number of non-family entries
1079 Ent := First_Entity (Concurrent_Type);
1080 while Present (Ent) loop
1081 if Ekind (Ent) = E_Entry then
1088 Ecount := Make_Integer_Literal (Loc, Eindx);
1090 -- Loop through entry families building the addition nodes
1092 Ent := First_Entity (Concurrent_Type);
1093 Comp := First (Component_List);
1094 while Present (Ent) loop
1095 if Ekind (Ent) = E_Entry_Family then
1096 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1100 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1101 Hi := Type_High_Bound (Typ);
1102 Lo := Type_Low_Bound (Typ);
1103 Large := Is_Potentially_Large_Family
1104 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1107 Left_Opnd => Ecount,
1108 Right_Opnd => Family_Size
1109 (Loc, Hi, Lo, Concurrent_Type, Large));
1116 end Build_Entry_Count_Expression;
1118 -----------------------
1119 -- Build_Entry_Names --
1120 -----------------------
1122 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1123 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1129 Typ : Entity_Id := Conc_Typ;
1131 procedure Build_Entry_Family_Name (Id : Entity_Id);
1133 -- for Lnn in Family_Low .. Family_High loop
1136 -- (_init._object <or> _init._task_id,
1138 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1140 -- Note that the bounds of the range may reference discriminants. The
1141 -- above construct is added directly to the statements of the block.
1143 procedure Build_Entry_Name (Id : Entity_Id);
1147 -- (_init._object <or>_init._task_id,
1149 -- new String ("<Entry name>");
1150 -- The above construct is added directly to the statements of the block.
1152 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1153 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1154 -- _init._task_id or _init._object, Inn and Arg3.
1156 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id;
1157 -- Given a protected type or its corresponding record, find the type of
1160 procedure Increment_Index (Stmts : List_Id);
1161 -- Generate the following and add it to Stmts
1164 -----------------------------
1165 -- Build_Entry_Family_Name --
1166 -----------------------------
1168 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1169 Def : constant Node_Id :=
1170 Discrete_Subtype_Definition (Parent (Id));
1171 L_Id : constant Entity_Id :=
1172 Make_Defining_Identifier (Loc, New_Internal_Name ('L'));
1173 L_Stmts : constant List_Id := New_List;
1176 function Build_Range (Def : Node_Id) return Node_Id;
1177 -- Given a discrete subtype definition of an entry family, generate a
1178 -- range node which covers the range of Def's type.
1184 function Build_Range (Def : Node_Id) return Node_Id is
1185 High : Node_Id := Type_High_Bound (Etype (Def));
1186 Low : Node_Id := Type_Low_Bound (Etype (Def));
1189 -- If a bound references a discriminant, generate an identifier
1190 -- with the same name. Resolution will map it to the formals of
1193 if Is_Entity_Name (Low)
1194 and then Ekind (Entity (Low)) = E_Discriminant
1196 Low := Make_Identifier (Loc, Chars (Low));
1198 Low := New_Copy_Tree (Low);
1201 if Is_Entity_Name (High)
1202 and then Ekind (Entity (High)) = E_Discriminant
1204 High := Make_Identifier (Loc, Chars (High));
1206 High := New_Copy_Tree (High);
1212 High_Bound => High);
1215 -- Start of processing for Build_Entry_Family_Name
1218 Get_Name_String (Chars (Id));
1220 -- Add a leading '('
1222 Add_Char_To_Name_Buffer ('(');
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 (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_Form : Node_Id;
1620 -- Map formals to actuals. Use the list built for the wrapper
1621 -- spec, skipping the object notation parameter.
1623 First_Form := First (Parameter_Specifications (Body_Spec));
1625 Formal := First_Form;
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: the wrapper needs a properly typed
1642 -- parameter if the wrapped operation has a controlling first
1643 -- parameter. Note that this might not be the case for a function
1644 -- with a controlling result.
1646 if Is_Private_Primitive_Subprogram (Subp_Id) then
1647 if No (Actuals) then
1648 Actuals := New_List;
1651 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1652 Prepend_To (Actuals,
1653 Unchecked_Convert_To (
1654 Corresponding_Concurrent_Type (Obj_Typ),
1655 Make_Identifier (Loc, Name_uO)));
1658 Prepend_To (Actuals,
1659 Make_Identifier (Loc, Chars =>
1660 Chars (Defining_Identifier (First_Form))));
1663 Nam := New_Reference_To (Subp_Id, Loc);
1665 -- An access-to-variable object parameter requires an explicit
1666 -- dereference in the unchecked conversion. This case occurs
1667 -- when a protected entry wrapper must override an interface
1668 -- level procedure with interface access as first parameter.
1670 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1672 if Nkind (Parameter_Type (First_Form)) =
1676 Make_Explicit_Dereference (Loc,
1677 Prefix => Make_Identifier (Loc, Name_uO));
1679 Conv_Id := Make_Identifier (Loc, Name_uO);
1683 Make_Selected_Component (Loc,
1685 Unchecked_Convert_To (
1686 Corresponding_Concurrent_Type (Obj_Typ),
1689 New_Reference_To (Subp_Id, Loc));
1692 -- Create the subprogram body. For a function, the call to the
1693 -- actual subprogram has to be converted to the corresponding
1694 -- record if it is a controlling result.
1696 if Ekind (Subp_Id) = E_Function then
1702 Make_Function_Call (Loc,
1704 Parameter_Associations => Actuals);
1706 if Has_Controlling_Result (Subp_Id) then
1708 Unchecked_Convert_To
1709 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1713 Make_Subprogram_Body (Loc,
1714 Specification => Body_Spec,
1715 Declarations => Empty_List,
1716 Handled_Statement_Sequence =>
1717 Make_Handled_Sequence_Of_Statements (Loc,
1718 Statements => New_List (
1719 Make_Simple_Return_Statement (Loc, Res))));
1724 Make_Subprogram_Body (Loc,
1725 Specification => Body_Spec,
1726 Declarations => Empty_List,
1727 Handled_Statement_Sequence =>
1728 Make_Handled_Sequence_Of_Statements (Loc,
1729 Statements => New_List (
1730 Make_Procedure_Call_Statement (Loc,
1732 Parameter_Associations => Actuals))));
1735 end Build_Wrapper_Body;
1737 -- Start of processing for Build_Wrapper_Bodies
1740 if Is_Concurrent_Type (Typ) then
1741 Rec_Typ := Corresponding_Record_Type (Typ);
1746 -- Generate wrapper bodies for a concurrent type which implements an
1749 if Present (Interfaces (Rec_Typ)) then
1751 Insert_Nod : Node_Id;
1753 Prim_Elmt : Elmt_Id;
1754 Prim_Decl : Node_Id;
1756 Wrap_Body : Node_Id;
1757 Wrap_Id : Entity_Id;
1762 -- Examine all primitive operations of the corresponding record
1763 -- type, looking for wrapper specs. Generate bodies in order to
1766 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1767 while Present (Prim_Elmt) loop
1768 Prim := Node (Prim_Elmt);
1770 if (Ekind (Prim) = E_Function
1771 or else Ekind (Prim) = E_Procedure)
1772 and then Is_Primitive_Wrapper (Prim)
1774 Subp := Wrapped_Entity (Prim);
1775 Prim_Decl := Parent (Parent (Prim));
1778 Build_Wrapper_Body (Loc,
1781 Formals => Parameter_Specifications (Parent (Subp)));
1782 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
1784 Set_Corresponding_Spec (Wrap_Body, Prim);
1785 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
1787 Insert_After (Insert_Nod, Wrap_Body);
1788 Insert_Nod := Wrap_Body;
1790 Analyze (Wrap_Body);
1793 Next_Elmt (Prim_Elmt);
1797 end Build_Wrapper_Bodies;
1799 ------------------------
1800 -- Build_Wrapper_Spec --
1801 ------------------------
1803 function Build_Wrapper_Spec
1804 (Subp_Id : Entity_Id;
1805 Obj_Typ : Entity_Id;
1806 Formals : List_Id) return Node_Id
1808 Loc : constant Source_Ptr := Sloc (Subp_Id);
1809 First_Param : Node_Id;
1811 Iface_Elmt : Elmt_Id;
1812 Iface_Op : Entity_Id;
1813 Iface_Op_Elmt : Elmt_Id;
1815 function Overriding_Possible
1816 (Iface_Op : Entity_Id;
1817 Wrapper : Entity_Id) return Boolean;
1818 -- Determine whether a primitive operation can be overridden by Wrapper.
1819 -- Iface_Op is the candidate primitive operation of an interface type,
1820 -- Wrapper is the generated entry wrapper.
1822 function Replicate_Formals
1824 Formals : List_Id) return List_Id;
1825 -- An explicit parameter replication is required due to the Is_Entry_
1826 -- Formal flag being set for all the formals of an entry. The explicit
1827 -- replication removes the flag that would otherwise cause a different
1828 -- path of analysis.
1830 -------------------------
1831 -- Overriding_Possible --
1832 -------------------------
1834 function Overriding_Possible
1835 (Iface_Op : Entity_Id;
1836 Wrapper : Entity_Id) return Boolean
1838 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
1839 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
1841 function Type_Conformant_Parameters
1842 (Iface_Op_Params : List_Id;
1843 Wrapper_Params : List_Id) return Boolean;
1844 -- Determine whether the parameters of the generated entry wrapper
1845 -- and those of a primitive operation are type conformant. During
1846 -- this check, the first parameter of the primitive operation is
1847 -- skipped if it is a controlling argument: protected functions
1848 -- may have a controlling result.
1850 --------------------------------
1851 -- Type_Conformant_Parameters --
1852 --------------------------------
1854 function Type_Conformant_Parameters
1855 (Iface_Op_Params : List_Id;
1856 Wrapper_Params : List_Id) return Boolean
1858 Iface_Op_Param : Node_Id;
1859 Iface_Op_Typ : Entity_Id;
1860 Wrapper_Param : Node_Id;
1861 Wrapper_Typ : Entity_Id;
1864 -- Skip the first (controlling) parameter of primitive operation
1866 Iface_Op_Param := First (Iface_Op_Params);
1868 if Present (First_Formal (Iface_Op))
1869 and then Is_Controlling_Formal (First_Formal (Iface_Op))
1871 Iface_Op_Param := Next (Iface_Op_Param);
1874 Wrapper_Param := First (Wrapper_Params);
1875 while Present (Iface_Op_Param)
1876 and then Present (Wrapper_Param)
1878 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
1879 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
1881 -- The two parameters must be mode conformant
1883 if not Conforming_Types
1884 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
1889 Next (Iface_Op_Param);
1890 Next (Wrapper_Param);
1893 -- One of the lists is longer than the other
1895 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
1900 end Type_Conformant_Parameters;
1902 -- Start of processing for Overriding_Possible
1905 if Chars (Iface_Op) /= Chars (Wrapper) then
1909 -- If an inherited subprogram is implemented by a protected procedure
1910 -- or an entry, then the first parameter of the inherited subprogram
1911 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
1913 if Ekind (Iface_Op) = E_Procedure
1914 and then Present (Parameter_Specifications (Iface_Op_Spec))
1917 Obj_Param : constant Node_Id :=
1918 First (Parameter_Specifications (Iface_Op_Spec));
1920 if not Out_Present (Obj_Param)
1921 and then Nkind (Parameter_Type (Obj_Param)) /=
1930 Type_Conformant_Parameters (
1931 Parameter_Specifications (Iface_Op_Spec),
1932 Parameter_Specifications (Wrapper_Spec));
1933 end Overriding_Possible;
1935 -----------------------
1936 -- Replicate_Formals --
1937 -----------------------
1939 function Replicate_Formals
1941 Formals : List_Id) return List_Id
1943 New_Formals : constant List_Id := New_List;
1945 Param_Type : Node_Id;
1948 Formal := First (Formals);
1950 -- Skip the object parameter when dealing with primitives declared
1951 -- between two views.
1953 if Is_Private_Primitive_Subprogram (Subp_Id)
1954 and then not Has_Controlling_Result (Subp_Id)
1956 Formal := Next (Formal);
1959 while Present (Formal) loop
1961 -- Create an explicit copy of the entry parameter
1963 -- When creating the wrapper subprogram for a primitive operation
1964 -- of a protected interface we must construct an equivalent
1965 -- signature to that of the overriding operation. For regular
1966 -- parameters we can just use the type of the formal, but for
1967 -- access to subprogram parameters we need to reanalyze the
1968 -- parameter type to create local entities for the signature of
1969 -- the subprogram type. Using the entities of the overriding
1970 -- subprogram will result in out-of-scope errors in the back-end.
1972 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
1973 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
1976 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
1979 Append_To (New_Formals,
1980 Make_Parameter_Specification (Loc,
1981 Defining_Identifier =>
1982 Make_Defining_Identifier (Loc,
1983 Chars => Chars (Defining_Identifier (Formal))),
1984 In_Present => In_Present (Formal),
1985 Out_Present => Out_Present (Formal),
1986 Parameter_Type => Param_Type));
1992 end Replicate_Formals;
1994 -- Start of processing for Build_Wrapper_Spec
1997 -- There is no point in building wrappers for non-tagged concurrent
2000 pragma Assert (Is_Tagged_Type (Obj_Typ));
2002 -- An entry or a protected procedure can override a routine where the
2003 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2004 -- type. Since the wrapper must have the exact same signature as that of
2005 -- the overridden subprogram, we try to find the overriding candidate
2006 -- and use its controlling formal.
2008 First_Param := Empty;
2010 -- Check every implemented interface
2012 if Present (Interfaces (Obj_Typ)) then
2013 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2014 Search : while Present (Iface_Elmt) loop
2015 Iface := Node (Iface_Elmt);
2017 -- Check every interface primitive
2019 if Present (Primitive_Operations (Iface)) then
2020 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2021 while Present (Iface_Op_Elmt) loop
2022 Iface_Op := Node (Iface_Op_Elmt);
2024 -- Ignore predefined primitives
2026 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2027 Iface_Op := Ultimate_Alias (Iface_Op);
2029 -- The current primitive operation can be overridden by
2030 -- the generated entry wrapper.
2032 if Overriding_Possible (Iface_Op, Subp_Id) then
2034 First (Parameter_Specifications (Parent (Iface_Op)));
2040 Next_Elmt (Iface_Op_Elmt);
2044 Next_Elmt (Iface_Elmt);
2048 -- If the subprogram to be wrapped is not overriding anything or is not
2049 -- a primitive declared between two views, do not produce anything. This
2050 -- avoids spurious errors involving overriding.
2053 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2059 Wrapper_Id : constant Entity_Id :=
2060 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2061 New_Formals : List_Id;
2062 Obj_Param : Node_Id;
2063 Obj_Param_Typ : Entity_Id;
2066 -- Minimum decoration is needed to catch the entity in
2067 -- Sem_Ch6.Override_Dispatching_Operation.
2069 if Ekind (Subp_Id) = E_Function then
2070 Set_Ekind (Wrapper_Id, E_Function);
2072 Set_Ekind (Wrapper_Id, E_Procedure);
2075 Set_Is_Primitive_Wrapper (Wrapper_Id);
2076 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2077 Set_Is_Private_Primitive (Wrapper_Id,
2078 Is_Private_Primitive_Subprogram (Subp_Id));
2080 -- Process the formals
2082 New_Formals := Replicate_Formals (Loc, Formals);
2084 -- A function with a controlling result and no first controlling
2085 -- formal needs no additional parameter.
2087 if Has_Controlling_Result (Subp_Id)
2089 (No (First_Formal (Subp_Id))
2090 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2094 -- Routine Subp_Id has been found to override an interface primitive.
2095 -- If the interface operation has an access parameter, create a copy
2096 -- of it, with the same null exclusion indicator if present.
2098 elsif Present (First_Param) then
2099 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2101 Make_Access_Definition (Loc,
2103 New_Reference_To (Obj_Typ, Loc));
2104 Set_Null_Exclusion_Present (Obj_Param_Typ,
2105 Null_Exclusion_Present (Parameter_Type (First_Param)));
2108 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2112 Make_Parameter_Specification (Loc,
2113 Defining_Identifier =>
2114 Make_Defining_Identifier (Loc,
2116 In_Present => In_Present (First_Param),
2117 Out_Present => Out_Present (First_Param),
2118 Parameter_Type => Obj_Param_Typ);
2120 Prepend_To (New_Formals, Obj_Param);
2122 -- If we are dealing with a primitive declared between two views,
2123 -- implemented by a synchronized operation, we need to create
2124 -- a default parameter. The mode of the parameter must match that
2125 -- of the primitive operation.
2128 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2130 Make_Parameter_Specification (Loc,
2131 Defining_Identifier =>
2132 Make_Defining_Identifier (Loc, Name_uO),
2133 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2134 Out_Present => Ekind (Subp_Id) /= E_Function,
2135 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2136 Prepend_To (New_Formals, Obj_Param);
2139 -- Build the final spec. If it is a function with a controlling
2140 -- result, it is a primitive operation of the corresponding
2141 -- record type, so mark the spec accordingly.
2143 if Ekind (Subp_Id) = E_Function then
2149 if Has_Controlling_Result (Subp_Id) then
2152 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2154 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2158 Make_Function_Specification (Loc,
2159 Defining_Unit_Name => Wrapper_Id,
2160 Parameter_Specifications => New_Formals,
2161 Result_Definition => Res_Def);
2165 Make_Procedure_Specification (Loc,
2166 Defining_Unit_Name => Wrapper_Id,
2167 Parameter_Specifications => New_Formals);
2170 end Build_Wrapper_Spec;
2172 -------------------------
2173 -- Build_Wrapper_Specs --
2174 -------------------------
2176 procedure Build_Wrapper_Specs
2182 Rec_Typ : Entity_Id;
2185 if Is_Protected_Type (Typ) then
2186 Def := Protected_Definition (Parent (Typ));
2187 else pragma Assert (Is_Task_Type (Typ));
2188 Def := Task_Definition (Parent (Typ));
2191 Rec_Typ := Corresponding_Record_Type (Typ);
2193 -- Generate wrapper specs for a concurrent type which implements an
2194 -- interface and has visible entries and/or protected procedures.
2196 if Present (Interfaces (Rec_Typ))
2197 and then Present (Def)
2198 and then Present (Visible_Declarations (Def))
2202 Wrap_Decl : Node_Id;
2203 Wrap_Spec : Node_Id;
2206 Decl := First (Visible_Declarations (Def));
2207 while Present (Decl) loop
2210 if Nkind (Decl) = N_Entry_Declaration
2211 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2215 (Subp_Id => Defining_Identifier (Decl),
2217 Formals => Parameter_Specifications (Decl));
2219 elsif Nkind (Decl) = N_Subprogram_Declaration then
2222 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2225 Parameter_Specifications (Specification (Decl)));
2228 if Present (Wrap_Spec) then
2230 Make_Subprogram_Declaration (Loc,
2231 Specification => Wrap_Spec);
2233 Insert_After (N, Wrap_Decl);
2236 Analyze (Wrap_Decl);
2243 end Build_Wrapper_Specs;
2245 ---------------------------
2246 -- Build_Find_Body_Index --
2247 ---------------------------
2249 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2250 Loc : constant Source_Ptr := Sloc (Typ);
2253 Has_F : Boolean := False;
2255 If_St : Node_Id := Empty;
2258 Decls : List_Id := New_List;
2261 Siz : Node_Id := Empty;
2263 procedure Add_If_Clause (Expr : Node_Id);
2264 -- Add test for range of current entry
2266 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2267 -- If a bound of an entry is given by a discriminant, retrieve the
2268 -- actual value of the discriminant from the enclosing object.
2274 procedure Add_If_Clause (Expr : Node_Id) is
2276 Stats : constant List_Id :=
2278 Make_Simple_Return_Statement (Loc,
2279 Expression => Make_Integer_Literal (Loc, Index + 1)));
2282 -- Index for current entry body
2286 -- Compute total length of entry queues so far
2294 Right_Opnd => Expr);
2299 Left_Opnd => Make_Identifier (Loc, Name_uE),
2302 -- Map entry queue indices in the range of the current family
2303 -- into the current index, that designates the entry body.
2307 Make_Implicit_If_Statement (Typ,
2309 Then_Statements => Stats,
2310 Elsif_Parts => New_List);
2316 Make_Elsif_Part (Loc,
2318 Then_Statements => Stats),
2319 Elsif_Parts (If_St));
2323 ------------------------------
2324 -- Convert_Discriminant_Ref --
2325 ------------------------------
2327 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2331 if Is_Entity_Name (Bound)
2332 and then Ekind (Entity (Bound)) = E_Discriminant
2335 Make_Selected_Component (Loc,
2337 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2338 Make_Explicit_Dereference (Loc,
2339 Make_Identifier (Loc, Name_uObject))),
2340 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2341 Set_Etype (B, Etype (Entity (Bound)));
2343 B := New_Copy_Tree (Bound);
2347 end Convert_Discriminant_Ref;
2349 -- Start of processing for Build_Find_Body_Index
2352 Spec := Build_Find_Body_Index_Spec (Typ);
2354 Ent := First_Entity (Typ);
2355 while Present (Ent) loop
2356 if Ekind (Ent) = E_Entry_Family then
2366 -- If the protected type has no entry families, there is a one-one
2367 -- correspondence between entry queue and entry body.
2370 Make_Simple_Return_Statement (Loc,
2371 Expression => Make_Identifier (Loc, Name_uE));
2374 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2377 -- if E <= l1 then return 1;
2378 -- elsif E <= l1 + l2 then return 2;
2383 Ent := First_Entity (Typ);
2385 Add_Object_Pointer (Loc, Typ, Decls);
2387 while Present (Ent) loop
2389 if Ekind (Ent) = E_Entry then
2390 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2392 elsif Ekind (Ent) = E_Entry_Family then
2394 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2395 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2396 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2397 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2406 Make_Simple_Return_Statement (Loc,
2407 Expression => Make_Integer_Literal (Loc, 1));
2409 elsif Nkind (Ret) = N_If_Statement then
2411 -- Ranges are in increasing order, so last one doesn't need guard
2414 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2417 Set_Else_Statements (Ret, Then_Statements (Nod));
2423 Make_Subprogram_Body (Loc,
2424 Specification => Spec,
2425 Declarations => Decls,
2426 Handled_Statement_Sequence =>
2427 Make_Handled_Sequence_Of_Statements (Loc,
2428 Statements => New_List (Ret)));
2429 end Build_Find_Body_Index;
2431 --------------------------------
2432 -- Build_Find_Body_Index_Spec --
2433 --------------------------------
2435 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2436 Loc : constant Source_Ptr := Sloc (Typ);
2437 Id : constant Entity_Id :=
2438 Make_Defining_Identifier (Loc,
2439 Chars => New_External_Name (Chars (Typ), 'F'));
2440 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2441 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2445 Make_Function_Specification (Loc,
2446 Defining_Unit_Name => Id,
2447 Parameter_Specifications => New_List (
2448 Make_Parameter_Specification (Loc,
2449 Defining_Identifier => Parm1,
2451 New_Reference_To (RTE (RE_Address), Loc)),
2453 Make_Parameter_Specification (Loc,
2454 Defining_Identifier => Parm2,
2456 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2457 Result_Definition => New_Occurrence_Of (
2458 RTE (RE_Protected_Entry_Index), Loc));
2459 end Build_Find_Body_Index_Spec;
2461 -------------------------
2462 -- Build_Master_Entity --
2463 -------------------------
2465 procedure Build_Master_Entity (E : Entity_Id) is
2466 Loc : constant Source_Ptr := Sloc (E);
2474 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2475 -- in internal scopes, unless present already.. Required for nested
2476 -- limited aggregates, where the expansion of task components may
2477 -- generate inner blocks. If the block is the rewriting of a call
2478 -- or the scope is an extended return statement this is valid master.
2479 -- The master in an extended return is only used within the return,
2480 -- and is subsequently overwritten in Move_Activation_Chain, but it
2483 if Ada_Version >= Ada_05 then
2484 while Is_Internal (S) loop
2485 if Nkind (Parent (S)) = N_Block_Statement
2487 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
2490 elsif Ekind (S) = E_Return_Statement then
2498 -- Nothing to do if we already built a master entity for this scope
2499 -- or if there is no task hierarchy.
2501 if Has_Master_Entity (S)
2502 or else Restriction_Active (No_Task_Hierarchy)
2507 -- Otherwise first build the master entity
2508 -- _Master : constant Master_Id := Current_Master.all;
2509 -- and insert it just before the current declaration
2512 Make_Object_Declaration (Loc,
2513 Defining_Identifier =>
2514 Make_Defining_Identifier (Loc, Name_uMaster),
2515 Constant_Present => True,
2516 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2518 Make_Explicit_Dereference (Loc,
2519 New_Reference_To (RTE (RE_Current_Master), Loc)));
2522 Insert_Before (P, Decl);
2525 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2526 -- non-internal scope selected above.
2528 if Ada_Version >= Ada_05 then
2529 Set_Has_Master_Entity (S);
2531 Set_Has_Master_Entity (Scope (E));
2534 -- Now mark the containing scope as a task master
2536 while Nkind (P) /= N_Compilation_Unit loop
2539 -- If we fall off the top, we are at the outer level, and the
2540 -- environment task is our effective master, so nothing to mark.
2543 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2545 Set_Is_Task_Master (P, True);
2548 elsif Nkind (Parent (P)) = N_Subunit then
2549 P := Corresponding_Stub (Parent (P));
2552 end Build_Master_Entity;
2554 ---------------------------
2555 -- Build_Protected_Entry --
2556 ---------------------------
2558 function Build_Protected_Entry
2561 Pid : Node_Id) return Node_Id
2563 Loc : constant Source_Ptr := Sloc (N);
2565 Decls : constant List_Id := Declarations (N);
2566 End_Lab : constant Node_Id :=
2567 End_Label (Handled_Statement_Sequence (N));
2568 End_Loc : constant Source_Ptr :=
2569 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2570 -- Used for the generated call to Complete_Entry_Body
2572 Han_Loc : Source_Ptr;
2573 -- Used for the exception handler, inserted at end of the body
2575 Op_Decls : constant List_Id := New_List;
2583 -- Set the source location on the exception handler only when debugging
2584 -- the expanded code (see Make_Implicit_Exception_Handler).
2586 if Debug_Generated_Code then
2589 -- Otherwise the inserted code should not be visible to the debugger
2592 Han_Loc := No_Location;
2596 Make_Defining_Identifier (Loc,
2597 Chars => Chars (Protected_Body_Subprogram (Ent)));
2599 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2601 -- Add the following declarations:
2602 -- type poVP is access poV;
2603 -- _object : poVP := poVP (_O);
2605 -- where _O is the formal parameter associated with the concurrent
2606 -- object. These declarations are needed for Complete_Entry_Body.
2608 Add_Object_Pointer (Loc, Pid, Op_Decls);
2610 -- Add renamings for all formals, the Protection object, discriminals,
2611 -- privals and the entry index constant for use by debugger.
2613 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2614 Debug_Private_Data_Declarations (Decls);
2616 case Corresponding_Runtime_Package (Pid) is
2617 when System_Tasking_Protected_Objects_Entries =>
2619 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2621 when System_Tasking_Protected_Objects_Single_Entry =>
2623 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2626 raise Program_Error;
2629 Op_Stats := New_List (
2630 Make_Block_Statement (Loc,
2631 Declarations => Decls,
2632 Handled_Statement_Sequence =>
2633 Handled_Statement_Sequence (N)),
2635 Make_Procedure_Call_Statement (End_Loc,
2637 Parameter_Associations => New_List (
2638 Make_Attribute_Reference (End_Loc,
2640 Make_Selected_Component (End_Loc,
2642 Make_Identifier (End_Loc, Name_uObject),
2644 Make_Identifier (End_Loc, Name_uObject)),
2645 Attribute_Name => Name_Unchecked_Access))));
2647 -- When exceptions can not be propagated, we never need to call
2648 -- Exception_Complete_Entry_Body
2650 if No_Exception_Handlers_Set then
2652 Make_Subprogram_Body (Loc,
2653 Specification => Espec,
2654 Declarations => Op_Decls,
2655 Handled_Statement_Sequence =>
2656 Make_Handled_Sequence_Of_Statements (Loc,
2657 Statements => Op_Stats,
2658 End_Label => End_Lab));
2661 Ohandle := Make_Others_Choice (Loc);
2662 Set_All_Others (Ohandle);
2664 case Corresponding_Runtime_Package (Pid) is
2665 when System_Tasking_Protected_Objects_Entries =>
2668 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2670 when System_Tasking_Protected_Objects_Single_Entry =>
2673 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2676 raise Program_Error;
2679 -- Create body of entry procedure. The renaming declarations are
2680 -- placed ahead of the block that contains the actual entry body.
2683 Make_Subprogram_Body (Loc,
2684 Specification => Espec,
2685 Declarations => Op_Decls,
2686 Handled_Statement_Sequence =>
2687 Make_Handled_Sequence_Of_Statements (Loc,
2688 Statements => Op_Stats,
2689 End_Label => End_Lab,
2690 Exception_Handlers => New_List (
2691 Make_Implicit_Exception_Handler (Han_Loc,
2692 Exception_Choices => New_List (Ohandle),
2694 Statements => New_List (
2695 Make_Procedure_Call_Statement (Han_Loc,
2697 Parameter_Associations => New_List (
2698 Make_Attribute_Reference (Han_Loc,
2700 Make_Selected_Component (Han_Loc,
2702 Make_Identifier (Han_Loc, Name_uObject),
2704 Make_Identifier (Han_Loc, Name_uObject)),
2705 Attribute_Name => Name_Unchecked_Access),
2707 Make_Function_Call (Han_Loc,
2708 Name => New_Reference_To (
2709 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2711 end Build_Protected_Entry;
2713 -----------------------------------------
2714 -- Build_Protected_Entry_Specification --
2715 -----------------------------------------
2717 function Build_Protected_Entry_Specification
2720 Ent_Id : Entity_Id) return Node_Id
2722 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2725 Set_Debug_Info_Needed (Def_Id);
2727 if Present (Ent_Id) then
2728 Append_Elmt (P, Accept_Address (Ent_Id));
2732 Make_Procedure_Specification (Loc,
2733 Defining_Unit_Name => Def_Id,
2734 Parameter_Specifications => New_List (
2735 Make_Parameter_Specification (Loc,
2736 Defining_Identifier =>
2737 Make_Defining_Identifier (Loc, Name_uO),
2739 New_Reference_To (RTE (RE_Address), Loc)),
2741 Make_Parameter_Specification (Loc,
2742 Defining_Identifier => P,
2744 New_Reference_To (RTE (RE_Address), Loc)),
2746 Make_Parameter_Specification (Loc,
2747 Defining_Identifier =>
2748 Make_Defining_Identifier (Loc, Name_uE),
2750 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2751 end Build_Protected_Entry_Specification;
2753 --------------------------
2754 -- Build_Protected_Spec --
2755 --------------------------
2757 function Build_Protected_Spec
2759 Obj_Type : Entity_Id;
2761 Unprotected : Boolean := False) return List_Id
2763 Loc : constant Source_Ptr := Sloc (N);
2766 New_Plist : List_Id;
2767 New_Param : Node_Id;
2770 New_Plist := New_List;
2772 Formal := First_Formal (Ident);
2773 while Present (Formal) loop
2775 Make_Parameter_Specification (Loc,
2776 Defining_Identifier =>
2777 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2778 In_Present => In_Present (Parent (Formal)),
2779 Out_Present => Out_Present (Parent (Formal)),
2780 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
2783 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2786 Append (New_Param, New_Plist);
2787 Next_Formal (Formal);
2790 -- If the subprogram is a procedure and the context is not an access
2791 -- to protected subprogram, the parameter is in-out. Otherwise it is
2795 Make_Parameter_Specification (Loc,
2796 Defining_Identifier =>
2797 Make_Defining_Identifier (Loc, Name_uObject),
2800 (Etype (Ident) = Standard_Void_Type
2801 and then not Is_RTE (Obj_Type, RE_Address)),
2803 New_Reference_To (Obj_Type, Loc));
2804 Set_Debug_Info_Needed (Defining_Identifier (Decl));
2805 Prepend_To (New_Plist, Decl);
2808 end Build_Protected_Spec;
2810 ---------------------------------------
2811 -- Build_Protected_Sub_Specification --
2812 ---------------------------------------
2814 function Build_Protected_Sub_Specification
2816 Prot_Typ : Entity_Id;
2817 Mode : Subprogram_Protection_Mode) return Node_Id
2819 Loc : constant Source_Ptr := Sloc (N);
2823 New_Plist : List_Id;
2826 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2827 (Dispatching_Mode => ' ',
2828 Protected_Mode => 'P',
2829 Unprotected_Mode => 'N');
2832 if Ekind (Defining_Unit_Name (Specification (N))) =
2835 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2840 Def_Id := Defining_Unit_Name (Specification (Decl));
2843 Build_Protected_Spec
2844 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
2845 Mode = Unprotected_Mode);
2847 Make_Defining_Identifier (Loc,
2848 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
2850 -- The unprotected operation carries the user code, and debugging
2851 -- information must be generated for it, even though this spec does
2852 -- not come from source. It is also convenient to allow gdb to step
2853 -- into the protected operation, even though it only contains lock/
2856 Set_Debug_Info_Needed (New_Id);
2858 -- If a pragma Eliminate applies to the source entity, the internal
2859 -- subprograms will be eliminated as well.
2861 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
2863 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2865 Make_Procedure_Specification (Loc,
2866 Defining_Unit_Name => New_Id,
2867 Parameter_Specifications => New_Plist);
2869 -- Create a new specification for the anonymous subprogram type
2873 Make_Function_Specification (Loc,
2874 Defining_Unit_Name => New_Id,
2875 Parameter_Specifications => New_Plist,
2876 Result_Definition =>
2877 Copy_Result_Type (Result_Definition (Specification (Decl))));
2879 Set_Return_Present (Defining_Unit_Name (New_Spec));
2883 end Build_Protected_Sub_Specification;
2885 -------------------------------------
2886 -- Build_Protected_Subprogram_Body --
2887 -------------------------------------
2889 function Build_Protected_Subprogram_Body
2892 N_Op_Spec : Node_Id) return Node_Id
2894 Loc : constant Source_Ptr := Sloc (N);
2896 P_Op_Spec : Node_Id;
2899 Unprot_Call : Node_Id;
2901 Lock_Name : Node_Id;
2902 Lock_Stmt : Node_Id;
2903 Service_Name : Node_Id;
2905 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2906 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2908 Object_Parm : Node_Id;
2911 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2912 -- Tell whether a given subprogram cannot raise an exception
2914 -----------------------
2915 -- Is_Exception_Safe --
2916 -----------------------
2918 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2920 function Has_Side_Effect (N : Node_Id) return Boolean;
2921 -- Return True whenever encountering a subprogram call or raise
2922 -- statement of any kind in the sequence of statements
2924 ---------------------
2925 -- Has_Side_Effect --
2926 ---------------------
2928 -- What is this doing buried two levels down in exp_ch9. It seems
2929 -- like a generally useful function, and indeed there may be code
2930 -- duplication going on here ???
2932 function Has_Side_Effect (N : Node_Id) return Boolean is
2936 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
2937 -- Indicate whether N is a subprogram call or a raise statement
2939 ----------------------
2940 -- Is_Call_Or_Raise --
2941 ----------------------
2943 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
2945 return Nkind_In (N, N_Procedure_Call_Statement,
2948 N_Raise_Constraint_Error,
2949 N_Raise_Program_Error,
2950 N_Raise_Storage_Error);
2951 end Is_Call_Or_Raise;
2953 -- Start of processing for Has_Side_Effect
2957 while Present (Stmt) loop
2958 if Is_Call_Or_Raise (Stmt) then
2962 -- An object declaration can also contain a function call
2963 -- or a raise statement
2965 if Nkind (Stmt) = N_Object_Declaration then
2966 Expr := Expression (Stmt);
2968 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
2977 end Has_Side_Effect;
2979 -- Start of processing for Is_Exception_Safe
2982 -- If the checks handled by the back end are not disabled, we cannot
2983 -- ensure that no exception will be raised.
2985 if not Access_Checks_Suppressed (Empty)
2986 or else not Discriminant_Checks_Suppressed (Empty)
2987 or else not Range_Checks_Suppressed (Empty)
2988 or else not Index_Checks_Suppressed (Empty)
2989 or else Opt.Stack_Checking_Enabled
2994 if Has_Side_Effect (First (Declarations (Subprogram)))
2997 First (Statements (Handled_Statement_Sequence (Subprogram))))
3003 end Is_Exception_Safe;
3005 -- Start of processing for Build_Protected_Subprogram_Body
3008 Op_Spec := Specification (N);
3009 Exc_Safe := Is_Exception_Safe (N);
3012 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3014 -- Build a list of the formal parameters of the protected version of
3015 -- the subprogram to use as the actual parameters of the unprotected
3018 Uactuals := New_List;
3019 Pformal := First (Parameter_Specifications (P_Op_Spec));
3020 while Present (Pformal) loop
3022 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
3027 -- Make a call to the unprotected version of the subprogram built above
3028 -- for use by the protected version built below.
3030 if Nkind (Op_Spec) = N_Function_Specification then
3032 R := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
3034 Make_Object_Declaration (Loc,
3035 Defining_Identifier => R,
3036 Constant_Present => True,
3037 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3039 Make_Function_Call (Loc,
3040 Name => Make_Identifier (Loc,
3041 Chars (Defining_Unit_Name (N_Op_Spec))),
3042 Parameter_Associations => Uactuals));
3043 Return_Stmt := Make_Simple_Return_Statement (Loc,
3044 Expression => New_Reference_To (R, Loc));
3047 Unprot_Call := Make_Simple_Return_Statement (Loc,
3048 Expression => Make_Function_Call (Loc,
3050 Make_Identifier (Loc,
3051 Chars (Defining_Unit_Name (N_Op_Spec))),
3052 Parameter_Associations => Uactuals));
3057 Make_Procedure_Call_Statement (Loc,
3059 Make_Identifier (Loc,
3060 Chars (Defining_Unit_Name (N_Op_Spec))),
3061 Parameter_Associations => Uactuals);
3064 -- Wrap call in block that will be covered by an at_end handler
3066 if not Exc_Safe then
3067 Unprot_Call := Make_Block_Statement (Loc,
3068 Handled_Statement_Sequence =>
3069 Make_Handled_Sequence_Of_Statements (Loc,
3070 Statements => New_List (Unprot_Call)));
3073 -- Make the protected subprogram body. This locks the protected
3074 -- object and calls the unprotected version of the subprogram.
3076 case Corresponding_Runtime_Package (Pid) is
3077 when System_Tasking_Protected_Objects_Entries =>
3078 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3079 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3081 when System_Tasking_Protected_Objects_Single_Entry =>
3082 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3083 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3085 when System_Tasking_Protected_Objects =>
3086 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3087 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3090 raise Program_Error;
3094 Make_Attribute_Reference (Loc,
3096 Make_Selected_Component (Loc,
3098 Make_Identifier (Loc, Name_uObject),
3100 Make_Identifier (Loc, Name_uObject)),
3101 Attribute_Name => Name_Unchecked_Access);
3103 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3105 Parameter_Associations => New_List (Object_Parm));
3107 if Abort_Allowed then
3109 Make_Procedure_Call_Statement (Loc,
3110 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3111 Parameter_Associations => Empty_List),
3115 Stmts := New_List (Lock_Stmt);
3118 if not Exc_Safe then
3119 Append (Unprot_Call, Stmts);
3121 if Nkind (Op_Spec) = N_Function_Specification then
3123 Stmts := Empty_List;
3125 Append (Unprot_Call, Stmts);
3129 Make_Procedure_Call_Statement (Loc,
3130 Name => Service_Name,
3131 Parameter_Associations =>
3132 New_List (New_Copy_Tree (Object_Parm))),
3135 if Abort_Allowed then
3137 Make_Procedure_Call_Statement (Loc,
3138 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3139 Parameter_Associations => Empty_List),
3143 if Nkind (Op_Spec) = N_Function_Specification then
3144 Append (Return_Stmt, Stmts);
3145 Append (Make_Block_Statement (Loc,
3146 Declarations => New_List (Unprot_Call),
3147 Handled_Statement_Sequence =>
3148 Make_Handled_Sequence_Of_Statements (Loc,
3149 Statements => Stmts)), Pre_Stmts);
3155 Make_Subprogram_Body (Loc,
3156 Declarations => Empty_List,
3157 Specification => P_Op_Spec,
3158 Handled_Statement_Sequence =>
3159 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3161 if not Exc_Safe then
3162 Set_Is_Protected_Subprogram_Body (Sub_Body);
3166 end Build_Protected_Subprogram_Body;
3168 -------------------------------------
3169 -- Build_Protected_Subprogram_Call --
3170 -------------------------------------
3172 procedure Build_Protected_Subprogram_Call
3176 External : Boolean := True)
3178 Loc : constant Source_Ptr := Sloc (N);
3179 Sub : constant Entity_Id := Entity (Name);
3185 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3188 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3191 if Present (Parameter_Associations (N)) then
3192 Params := New_Copy_List_Tree (Parameter_Associations (N));
3197 -- If the type is an untagged derived type, convert to the root type,
3198 -- which is the one on which the operations are defined.
3200 if Nkind (Rec) = N_Unchecked_Type_Conversion
3201 and then not Is_Tagged_Type (Etype (Rec))
3202 and then Is_Derived_Type (Etype (Rec))
3204 Set_Etype (Rec, Root_Type (Etype (Rec)));
3205 Set_Subtype_Mark (Rec,
3206 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3209 Prepend (Rec, Params);
3211 if Ekind (Sub) = E_Procedure then
3213 Make_Procedure_Call_Statement (Loc,
3215 Parameter_Associations => Params));
3218 pragma Assert (Ekind (Sub) = E_Function);
3220 Make_Function_Call (Loc,
3222 Parameter_Associations => Params));
3226 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3227 and then Is_Entity_Name (Expression (Rec))
3228 and then Is_Shared_Passive (Entity (Expression (Rec)))
3230 Add_Shared_Var_Lock_Procs (N);
3232 end Build_Protected_Subprogram_Call;
3234 -------------------------
3235 -- Build_Selected_Name --
3236 -------------------------
3238 function Build_Selected_Name
3239 (Prefix : Entity_Id;
3240 Selector : Entity_Id;
3241 Append_Char : Character := ' ') return Name_Id
3243 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3244 Select_Len : Natural;
3247 Get_Name_String (Chars (Selector));
3248 Select_Len := Name_Len;
3249 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3250 Get_Name_String (Chars (Prefix));
3252 -- If scope is anonymous type, discard suffix to recover name of
3253 -- single protected object. Otherwise use protected type name.
3255 if Name_Buffer (Name_Len) = 'T' then
3256 Name_Len := Name_Len - 1;
3259 Add_Str_To_Name_Buffer ("__");
3260 for J in 1 .. Select_Len loop
3261 Add_Char_To_Name_Buffer (Select_Buffer (J));
3264 -- Now add the Append_Char if specified. The encoding to follow
3265 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3266 -- then the entity is associated to a protected type subprogram.
3267 -- Otherwise, it is a protected type entry. For each case, the
3268 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3270 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3272 if Append_Char /= ' ' then
3273 if Append_Char = 'P' or Append_Char = 'N' then
3274 Add_Char_To_Name_Buffer (Append_Char);
3277 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3278 return New_External_Name (Name_Find, ' ', -1);
3283 end Build_Selected_Name;
3285 -----------------------------
3286 -- Build_Simple_Entry_Call --
3287 -----------------------------
3289 -- A task entry call is converted to a call to Call_Simple
3292 -- P : parms := (parm, parm, parm);
3294 -- Call_Simple (acceptor-task, entry-index, P'Address);
3300 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3301 -- the parameters, and the constructed aggregate value contains either the
3302 -- parameters or, in the case of non-elementary types, references to these
3303 -- parameters. Then the address of this aggregate is passed to the runtime
3304 -- routine, along with the task id value and the task entry index value.
3305 -- Pnn is only required if parameters are present.
3307 -- The assignments after the call are present only in the case of in-out
3308 -- or out parameters for elementary types, and are used to assign back the
3309 -- resulting values of such parameters.
3311 -- Note: the reason that we insert a block here is that in the context
3312 -- of selects, conditional entry calls etc. the entry call statement
3313 -- appears on its own, not as an element of a list.
3315 -- A protected entry call is converted to a Protected_Entry_Call:
3318 -- P : E1_Params := (param, param, param);
3320 -- Bnn : Communications_Block;
3323 -- P : E1_Params := (param, param, param);
3324 -- Bnn : Communications_Block;
3327 -- Protected_Entry_Call (
3328 -- Object => po._object'Access,
3329 -- E => <entry index>;
3330 -- Uninterpreted_Data => P'Address;
3331 -- Mode => Simple_Call;
3338 procedure Build_Simple_Entry_Call
3347 -- If call has been inlined, nothing left to do
3349 if Nkind (N) = N_Block_Statement then
3353 -- Convert entry call to Call_Simple call
3356 Loc : constant Source_Ptr := Sloc (N);
3357 Parms : constant List_Id := Parameter_Associations (N);
3358 Stats : constant List_Id := New_List;
3361 Comm_Name : Entity_Id;
3365 Ent_Acc : Entity_Id;
3367 Iface_Tag : Entity_Id;
3368 Iface_Typ : Entity_Id;
3381 -- Simple entry and entry family cases merge here
3383 Ent := Entity (Ename);
3384 Ent_Acc := Entry_Parameters_Type (Ent);
3385 Conctyp := Etype (Concval);
3387 -- If prefix is an access type, dereference to obtain the task type
3389 if Is_Access_Type (Conctyp) then
3390 Conctyp := Designated_Type (Conctyp);
3393 -- Special case for protected subprogram calls
3395 if Is_Protected_Type (Conctyp)
3396 and then Is_Subprogram (Entity (Ename))
3398 if not Is_Eliminated (Entity (Ename)) then
3399 Build_Protected_Subprogram_Call
3400 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3407 -- First parameter is the Task_Id value from the task value or the
3408 -- Object from the protected object value, obtained by selecting
3409 -- the _Task_Id or _Object from the result of doing an unchecked
3410 -- conversion to convert the value to the corresponding record type.
3412 if Nkind (Concval) = N_Function_Call
3413 and then Is_Task_Type (Conctyp)
3414 and then Ada_Version >= Ada_05
3417 Obj : constant Entity_Id :=
3418 Make_Defining_Identifier (Loc, New_Internal_Name ('F'));
3423 Make_Object_Declaration (Loc,
3424 Defining_Identifier => Obj,
3425 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3426 Expression => Relocate_Node (Concval));
3427 Set_Etype (Obj, Conctyp);
3428 Decls := New_List (Decl);
3429 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3436 Parm1 := Concurrent_Ref (Concval);
3438 -- Second parameter is the entry index, computed by the routine
3439 -- provided for this purpose. The value of this expression is
3440 -- assigned to an intermediate variable to assure that any entry
3441 -- family index expressions are evaluated before the entry
3445 or else Restriction_Active (No_Entry_Queue) = False
3446 or else not Is_Protected_Type (Conctyp)
3447 or else Number_Entries (Conctyp) > 1
3448 or else (Has_Attach_Handler (Conctyp)
3449 and then not Restricted_Profile)
3451 X := Make_Defining_Identifier (Loc, Name_uX);
3454 Make_Object_Declaration (Loc,
3455 Defining_Identifier => X,
3456 Object_Definition =>
3457 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3458 Expression => Actual_Index_Expression (
3459 Loc, Entity (Ename), Index, Concval));
3461 Append_To (Decls, Xdecl);
3462 Parm2 := New_Reference_To (X, Loc);
3469 -- The third parameter is the packaged parameters. If there are
3470 -- none, then it is just the null address, since nothing is passed.
3473 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3476 -- Case of parameters present, where third argument is the address
3477 -- of a packaged record containing the required parameter values.
3480 -- First build a list of parameter values, which are references to
3481 -- objects of the parameter types.
3485 Actual := First_Actual (N);
3486 Formal := First_Formal (Ent);
3488 while Present (Actual) loop
3490 -- If it is a by_copy_type, copy it to a new variable. The
3491 -- packaged record has a field that points to this variable.
3493 if Is_By_Copy_Type (Etype (Actual)) then
3495 Make_Object_Declaration (Loc,
3496 Defining_Identifier =>
3497 Make_Defining_Identifier (Loc,
3498 Chars => New_Internal_Name ('J')),
3499 Aliased_Present => True,
3500 Object_Definition =>
3501 New_Reference_To (Etype (Formal), Loc));
3503 -- Mark the object as not needing initialization since the
3504 -- initialization is performed separately, avoiding errors
3505 -- on cases such as formals of null-excluding access types.
3507 Set_No_Initialization (N_Node);
3509 -- We must make an assignment statement separate for the
3510 -- case of limited type. We cannot assign it unless the
3511 -- Assignment_OK flag is set first. An out formal of an
3512 -- access type must also be initialized from the actual,
3513 -- as stated in RM 6.4.1 (13).
3515 if Ekind (Formal) /= E_Out_Parameter
3516 or else Is_Access_Type (Etype (Formal))
3519 New_Reference_To (Defining_Identifier (N_Node), Loc);
3520 Set_Assignment_OK (N_Var);
3522 Make_Assignment_Statement (Loc,
3524 Expression => Relocate_Node (Actual)));
3527 Append (N_Node, Decls);
3530 Make_Attribute_Reference (Loc,
3531 Attribute_Name => Name_Unchecked_Access,
3533 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3535 -- Interface class-wide formal
3537 if Ada_Version >= Ada_05
3538 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3539 and then Is_Interface (Etype (Formal))
3541 Iface_Typ := Etype (Etype (Formal));
3544 -- formal_iface_type! (actual.iface_tag)'reference
3547 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3548 pragma Assert (Present (Iface_Tag));
3551 Make_Reference (Loc,
3552 Unchecked_Convert_To (Iface_Typ,
3553 Make_Selected_Component (Loc,
3555 Relocate_Node (Actual),
3557 New_Reference_To (Iface_Tag, Loc)))));
3563 Make_Reference (Loc, Relocate_Node (Actual)));
3567 Next_Actual (Actual);
3568 Next_Formal_With_Extras (Formal);
3571 -- Now build the declaration of parameters initialized with the
3572 -- aggregate containing this constructed parameter list.
3574 P := Make_Defining_Identifier (Loc, Name_uP);
3577 Make_Object_Declaration (Loc,
3578 Defining_Identifier => P,
3579 Object_Definition =>
3580 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3582 Make_Aggregate (Loc, Expressions => Plist));
3585 Make_Attribute_Reference (Loc,
3586 Prefix => New_Reference_To (P, Loc),
3587 Attribute_Name => Name_Address);
3589 Append (Pdecl, Decls);
3592 -- Now we can create the call, case of protected type
3594 if Is_Protected_Type (Conctyp) then
3595 case Corresponding_Runtime_Package (Conctyp) is
3596 when System_Tasking_Protected_Objects_Entries =>
3598 -- Change the type of the index declaration
3600 Set_Object_Definition (Xdecl,
3601 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3603 -- Some additional declarations for protected entry calls
3609 -- Bnn : Communications_Block;
3612 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3615 Make_Object_Declaration (Loc,
3616 Defining_Identifier => Comm_Name,
3617 Object_Definition =>
3618 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3620 -- Some additional statements for protected entry calls
3622 -- Protected_Entry_Call (
3623 -- Object => po._object'Access,
3624 -- E => <entry index>;
3625 -- Uninterpreted_Data => P'Address;
3626 -- Mode => Simple_Call;
3630 Make_Procedure_Call_Statement (Loc,
3632 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3634 Parameter_Associations => New_List (
3635 Make_Attribute_Reference (Loc,
3636 Attribute_Name => Name_Unchecked_Access,
3640 New_Reference_To (RTE (RE_Simple_Call), Loc),
3641 New_Occurrence_Of (Comm_Name, Loc)));
3643 when System_Tasking_Protected_Objects_Single_Entry =>
3644 -- Protected_Single_Entry_Call (
3645 -- Object => po._object'Access,
3646 -- Uninterpreted_Data => P'Address;
3647 -- Mode => Simple_Call);
3650 Make_Procedure_Call_Statement (Loc,
3651 Name => New_Reference_To (
3652 RTE (RE_Protected_Single_Entry_Call), Loc),
3654 Parameter_Associations => New_List (
3655 Make_Attribute_Reference (Loc,
3656 Attribute_Name => Name_Unchecked_Access,
3659 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3662 raise Program_Error;
3665 -- Case of task type
3669 Make_Procedure_Call_Statement (Loc,
3670 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3671 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3675 Append_To (Stats, Call);
3677 -- If there are out or in/out parameters by copy add assignment
3678 -- statements for the result values.
3680 if Present (Parms) then
3681 Actual := First_Actual (N);
3682 Formal := First_Formal (Ent);
3684 Set_Assignment_OK (Actual);
3685 while Present (Actual) loop
3686 if Is_By_Copy_Type (Etype (Actual))
3687 and then Ekind (Formal) /= E_In_Parameter
3690 Make_Assignment_Statement (Loc,
3691 Name => New_Copy (Actual),
3693 Make_Explicit_Dereference (Loc,
3694 Make_Selected_Component (Loc,
3695 Prefix => New_Reference_To (P, Loc),
3697 Make_Identifier (Loc, Chars (Formal)))));
3699 -- In all cases (including limited private types) we want
3700 -- the assignment to be valid.
3702 Set_Assignment_OK (Name (N_Node));
3704 -- If the call is the triggering alternative in an
3705 -- asynchronous select, or the entry_call alternative of a
3706 -- conditional entry call, the assignments for in-out
3707 -- parameters are incorporated into the statement list that
3708 -- follows, so that there are executed only if the entry
3711 if (Nkind (Parent (N)) = N_Triggering_Alternative
3712 and then N = Triggering_Statement (Parent (N)))
3714 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3715 and then N = Entry_Call_Statement (Parent (N)))
3717 if No (Statements (Parent (N))) then
3718 Set_Statements (Parent (N), New_List);
3721 Prepend (N_Node, Statements (Parent (N)));
3724 Insert_After (Call, N_Node);
3728 Next_Actual (Actual);
3729 Next_Formal_With_Extras (Formal);
3733 -- Finally, create block and analyze it
3736 Make_Block_Statement (Loc,
3737 Declarations => Decls,
3738 Handled_Statement_Sequence =>
3739 Make_Handled_Sequence_Of_Statements (Loc,
3740 Statements => Stats)));
3744 end Build_Simple_Entry_Call;
3746 --------------------------------
3747 -- Build_Task_Activation_Call --
3748 --------------------------------
3750 procedure Build_Task_Activation_Call (N : Node_Id) is
3751 Loc : constant Source_Ptr := Sloc (N);
3758 -- Get the activation chain entity. Except in the case of a package
3759 -- body, this is in the node that was passed. For a package body, we
3760 -- have to find the corresponding package declaration node.
3762 if Nkind (N) = N_Package_Body then
3763 P := Corresponding_Spec (N);
3766 exit when Nkind (P) = N_Package_Declaration;
3769 Chain := Activation_Chain_Entity (P);
3772 Chain := Activation_Chain_Entity (N);
3775 if Present (Chain) then
3776 if Restricted_Profile then
3777 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3779 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3783 Make_Procedure_Call_Statement (Loc,
3785 Parameter_Associations =>
3786 New_List (Make_Attribute_Reference (Loc,
3787 Prefix => New_Occurrence_Of (Chain, Loc),
3788 Attribute_Name => Name_Unchecked_Access)));
3790 if Nkind (N) = N_Package_Declaration then
3791 if Present (Corresponding_Body (N)) then
3794 elsif Present (Private_Declarations (Specification (N))) then
3795 Append (Call, Private_Declarations (Specification (N)));
3798 Append (Call, Visible_Declarations (Specification (N)));
3802 if Present (Handled_Statement_Sequence (N)) then
3804 -- The call goes at the start of the statement sequence
3805 -- after the start of exception range label if one is present.
3811 Stm := First (Statements (Handled_Statement_Sequence (N)));
3813 -- A special case, skip exception range label if one is
3814 -- present (from front end zcx processing).
3816 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3820 -- Another special case, if the first statement is a block
3821 -- from optimization of a local raise to a goto, then the
3822 -- call goes inside this block.
3824 if Nkind (Stm) = N_Block_Statement
3825 and then Exception_Junk (Stm)
3828 First (Statements (Handled_Statement_Sequence (Stm)));
3831 -- Insertion point is after any exception label pushes,
3832 -- since we want it covered by any local handlers.
3834 while Nkind (Stm) in N_Push_xxx_Label loop
3838 -- Now we have the proper insertion point
3840 Insert_Before (Stm, Call);
3844 Set_Handled_Statement_Sequence (N,
3845 Make_Handled_Sequence_Of_Statements (Loc,
3846 Statements => New_List (Call)));
3851 Check_Task_Activation (N);
3853 end Build_Task_Activation_Call;
3855 -------------------------------
3856 -- Build_Task_Allocate_Block --
3857 -------------------------------
3859 procedure Build_Task_Allocate_Block
3864 T : constant Entity_Id := Entity (Expression (N));
3865 Init : constant Entity_Id := Base_Init_Proc (T);
3866 Loc : constant Source_Ptr := Sloc (N);
3867 Chain : constant Entity_Id :=
3868 Make_Defining_Identifier (Loc, Name_uChain);
3874 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3877 Make_Block_Statement (Loc,
3878 Identifier => New_Reference_To (Blkent, Loc),
3879 Declarations => New_List (
3881 -- _Chain : Activation_Chain;
3883 Make_Object_Declaration (Loc,
3884 Defining_Identifier => Chain,
3885 Aliased_Present => True,
3886 Object_Definition =>
3887 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3889 Handled_Statement_Sequence =>
3890 Make_Handled_Sequence_Of_Statements (Loc,
3892 Statements => New_List (
3896 Make_Procedure_Call_Statement (Loc,
3897 Name => New_Reference_To (Init, Loc),
3898 Parameter_Associations => Args),
3900 -- Activate_Tasks (_Chain);
3902 Make_Procedure_Call_Statement (Loc,
3903 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3904 Parameter_Associations => New_List (
3905 Make_Attribute_Reference (Loc,
3906 Prefix => New_Reference_To (Chain, Loc),
3907 Attribute_Name => Name_Unchecked_Access))))),
3909 Has_Created_Identifier => True,
3910 Is_Task_Allocation_Block => True);
3913 Make_Implicit_Label_Declaration (Loc,
3914 Defining_Identifier => Blkent,
3915 Label_Construct => Block));
3917 Append_To (Actions, Block);
3919 Set_Activation_Chain_Entity (Block, Chain);
3920 end Build_Task_Allocate_Block;
3922 -----------------------------------------------
3923 -- Build_Task_Allocate_Block_With_Init_Stmts --
3924 -----------------------------------------------
3926 procedure Build_Task_Allocate_Block_With_Init_Stmts
3929 Init_Stmts : List_Id)
3931 Loc : constant Source_Ptr := Sloc (N);
3932 Chain : constant Entity_Id :=
3933 Make_Defining_Identifier (Loc, Name_uChain);
3938 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3940 Append_To (Init_Stmts,
3941 Make_Procedure_Call_Statement (Loc,
3942 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3943 Parameter_Associations => New_List (
3944 Make_Attribute_Reference (Loc,
3945 Prefix => New_Reference_To (Chain, Loc),
3946 Attribute_Name => Name_Unchecked_Access))));
3949 Make_Block_Statement (Loc,
3950 Identifier => New_Reference_To (Blkent, Loc),
3951 Declarations => New_List (
3953 -- _Chain : Activation_Chain;
3955 Make_Object_Declaration (Loc,
3956 Defining_Identifier => Chain,
3957 Aliased_Present => True,
3958 Object_Definition =>
3959 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3961 Handled_Statement_Sequence =>
3962 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
3964 Has_Created_Identifier => True,
3965 Is_Task_Allocation_Block => True);
3968 Make_Implicit_Label_Declaration (Loc,
3969 Defining_Identifier => Blkent,
3970 Label_Construct => Block));
3972 Append_To (Actions, Block);
3974 Set_Activation_Chain_Entity (Block, Chain);
3975 end Build_Task_Allocate_Block_With_Init_Stmts;
3977 -----------------------------------
3978 -- Build_Task_Proc_Specification --
3979 -----------------------------------
3981 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
3982 Loc : constant Source_Ptr := Sloc (T);
3983 Spec_Id : Entity_Id;
3986 -- Case of explicit task type, suffix TB
3988 if Comes_From_Source (T) then
3990 Make_Defining_Identifier (Loc,
3991 Chars => New_External_Name (Chars (T), "TB"));
3993 -- Case of anonymous task type, suffix B
3997 Make_Defining_Identifier (Loc,
3998 Chars => New_External_Name (Chars (T), 'B'));
4001 Set_Is_Internal (Spec_Id);
4003 -- Associate the procedure with the task, if this is the declaration
4004 -- (and not the body) of the procedure.
4006 if No (Task_Body_Procedure (T)) then
4007 Set_Task_Body_Procedure (T, Spec_Id);
4011 Make_Procedure_Specification (Loc,
4012 Defining_Unit_Name => Spec_Id,
4013 Parameter_Specifications => New_List (
4014 Make_Parameter_Specification (Loc,
4015 Defining_Identifier =>
4016 Make_Defining_Identifier (Loc, Name_uTask),
4018 Make_Access_Definition (Loc,
4020 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4021 end Build_Task_Proc_Specification;
4023 ---------------------------------------
4024 -- Build_Unprotected_Subprogram_Body --
4025 ---------------------------------------
4027 function Build_Unprotected_Subprogram_Body
4029 Pid : Node_Id) return Node_Id
4031 Decls : constant List_Id := Declarations (N);
4034 -- Add renamings for the Protection object, discriminals, privals and
4035 -- the entry index constant for use by debugger.
4037 Debug_Private_Data_Declarations (Decls);
4039 -- Make an unprotected version of the subprogram for use within the same
4040 -- object, with a new name and an additional parameter representing the
4044 Make_Subprogram_Body (Sloc (N),
4046 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4047 Declarations => Decls,
4048 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4049 end Build_Unprotected_Subprogram_Body;
4051 ----------------------------
4052 -- Collect_Entry_Families --
4053 ----------------------------
4055 procedure Collect_Entry_Families
4058 Current_Node : in out Node_Id;
4059 Conctyp : Entity_Id)
4062 Efam_Decl : Node_Id;
4063 Efam_Type : Entity_Id;
4066 Efam := First_Entity (Conctyp);
4067 while Present (Efam) loop
4068 if Ekind (Efam) = E_Entry_Family then
4070 Make_Defining_Identifier (Loc,
4071 Chars => New_Internal_Name ('F'));
4076 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4078 Bas_Decl : Node_Id := Empty;
4083 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4085 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4087 Make_Defining_Identifier (Loc,
4088 Chars => New_Internal_Name ('B'));
4091 Make_Subtype_Declaration (Loc,
4092 Defining_Identifier => Bas,
4093 Subtype_Indication =>
4094 Make_Subtype_Indication (Loc,
4096 New_Occurrence_Of (Standard_Integer, Loc),
4098 Make_Range_Constraint (Loc,
4099 Range_Expression => Make_Range (Loc,
4100 Make_Integer_Literal
4101 (Loc, -Entry_Family_Bound),
4102 Make_Integer_Literal
4103 (Loc, Entry_Family_Bound - 1)))));
4105 Insert_After (Current_Node, Bas_Decl);
4106 Current_Node := Bas_Decl;
4111 Make_Full_Type_Declaration (Loc,
4112 Defining_Identifier => Efam_Type,
4114 Make_Unconstrained_Array_Definition (Loc,
4116 (New_List (New_Occurrence_Of (Bas, Loc))),
4118 Component_Definition =>
4119 Make_Component_Definition (Loc,
4120 Aliased_Present => False,
4121 Subtype_Indication =>
4122 New_Reference_To (Standard_Character, Loc))));
4125 Insert_After (Current_Node, Efam_Decl);
4126 Current_Node := Efam_Decl;
4127 Analyze (Efam_Decl);
4130 Make_Component_Declaration (Loc,
4131 Defining_Identifier =>
4132 Make_Defining_Identifier (Loc, Chars (Efam)),
4134 Component_Definition =>
4135 Make_Component_Definition (Loc,
4136 Aliased_Present => False,
4137 Subtype_Indication =>
4138 Make_Subtype_Indication (Loc,
4140 New_Occurrence_Of (Efam_Type, Loc),
4143 Make_Index_Or_Discriminant_Constraint (Loc,
4144 Constraints => New_List (
4146 (Etype (Discrete_Subtype_Definition
4147 (Parent (Efam))), Loc)))))));
4153 end Collect_Entry_Families;
4155 -----------------------
4156 -- Concurrent_Object --
4157 -----------------------
4159 function Concurrent_Object
4160 (Spec_Id : Entity_Id;
4161 Conc_Typ : Entity_Id) return Entity_Id
4164 -- Parameter _O or _object
4166 if Is_Protected_Type (Conc_Typ) then
4167 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4172 pragma Assert (Is_Task_Type (Conc_Typ));
4173 return First_Formal (Task_Body_Procedure (Conc_Typ));
4175 end Concurrent_Object;
4177 ----------------------
4178 -- Copy_Result_Type --
4179 ----------------------
4181 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4182 New_Res : constant Node_Id := New_Copy_Tree (Res);
4187 -- If the result type is an access_to_subprogram, we must create
4188 -- new entities for its spec.
4190 if Nkind (New_Res) = N_Access_Definition
4191 and then Present (Access_To_Subprogram_Definition (New_Res))
4193 -- Provide new entities for the formals
4195 Par_Spec := First (Parameter_Specifications
4196 (Access_To_Subprogram_Definition (New_Res)));
4197 while Present (Par_Spec) loop
4198 Formal := Defining_Identifier (Par_Spec);
4199 Set_Defining_Identifier (Par_Spec,
4200 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4206 end Copy_Result_Type;
4208 --------------------
4209 -- Concurrent_Ref --
4210 --------------------
4212 -- The expression returned for a reference to a concurrent object has the
4215 -- taskV!(name)._Task_Id
4219 -- objectV!(name)._Object
4221 -- for a protected object. For the case of an access to a concurrent
4222 -- object, there is an extra explicit dereference:
4224 -- taskV!(name.all)._Task_Id
4225 -- objectV!(name.all)._Object
4227 -- here taskV and objectV are the types for the associated records, which
4228 -- contain the required _Task_Id and _Object fields for tasks and protected
4229 -- objects, respectively.
4231 -- For the case of a task type name, the expression is
4235 -- i.e. a call to the Self function which returns precisely this Task_Id
4237 -- For the case of a protected type name, the expression is
4241 -- which is a renaming of the _object field of the current object
4242 -- record, passed into protected operations as a parameter.
4244 function Concurrent_Ref (N : Node_Id) return Node_Id is
4245 Loc : constant Source_Ptr := Sloc (N);
4246 Ntyp : constant Entity_Id := Etype (N);
4250 function Is_Current_Task (T : Entity_Id) return Boolean;
4251 -- Check whether the reference is to the immediately enclosing task
4252 -- type, or to an outer one (rare but legal).
4254 ---------------------
4255 -- Is_Current_Task --
4256 ---------------------
4258 function Is_Current_Task (T : Entity_Id) return Boolean is
4262 Scop := Current_Scope;
4263 while Present (Scop)
4264 and then Scop /= Standard_Standard
4270 elsif Is_Task_Type (Scop) then
4273 -- If this is a procedure nested within the task type, we must
4274 -- assume that it can be called from an inner task, and therefore
4275 -- cannot treat it as a local reference.
4277 elsif Is_Overloadable (Scop)
4278 and then In_Open_Scopes (T)
4283 Scop := Scope (Scop);
4287 -- We know that we are within the task body, so should have found it
4290 raise Program_Error;
4291 end Is_Current_Task;
4293 -- Start of processing for Concurrent_Ref
4296 if Is_Access_Type (Ntyp) then
4297 Dtyp := Designated_Type (Ntyp);
4299 if Is_Protected_Type (Dtyp) then
4300 Sel := Name_uObject;
4302 Sel := Name_uTask_Id;
4306 Make_Selected_Component (Loc,
4308 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4309 Make_Explicit_Dereference (Loc, N)),
4310 Selector_Name => Make_Identifier (Loc, Sel));
4312 elsif Is_Entity_Name (N)
4313 and then Is_Concurrent_Type (Entity (N))
4315 if Is_Task_Type (Entity (N)) then
4317 if Is_Current_Task (Entity (N)) then
4319 Make_Function_Call (Loc,
4320 Name => New_Reference_To (RTE (RE_Self), Loc));
4325 T_Self : constant Entity_Id :=
4326 Make_Defining_Identifier (Loc,
4327 Chars => New_Internal_Name ('T'));
4328 T_Body : constant Node_Id :=
4329 Parent (Corresponding_Body (Parent (Entity (N))));
4332 Decl := Make_Object_Declaration (Loc,
4333 Defining_Identifier => T_Self,
4334 Object_Definition =>
4335 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4337 Make_Function_Call (Loc,
4338 Name => New_Reference_To (RTE (RE_Self), Loc)));
4339 Prepend (Decl, Declarations (T_Body));
4341 Set_Scope (T_Self, Entity (N));
4342 return New_Occurrence_Of (T_Self, Loc);
4347 pragma Assert (Is_Protected_Type (Entity (N)));
4350 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4354 if Is_Protected_Type (Ntyp) then
4355 Sel := Name_uObject;
4357 elsif Is_Task_Type (Ntyp) then
4358 Sel := Name_uTask_Id;
4361 raise Program_Error;
4365 Make_Selected_Component (Loc,
4367 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4369 Selector_Name => Make_Identifier (Loc, Sel));
4373 ------------------------
4374 -- Convert_Concurrent --
4375 ------------------------
4377 function Convert_Concurrent
4379 Typ : Entity_Id) return Node_Id
4382 if not Is_Concurrent_Type (Typ) then
4386 Unchecked_Convert_To
4387 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4389 end Convert_Concurrent;
4391 -------------------------------------
4392 -- Debug_Private_Data_Declarations --
4393 -------------------------------------
4395 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4396 Debug_Nod : Node_Id;
4400 Decl := First (Decls);
4401 while Present (Decl)
4402 and then not Comes_From_Source (Decl)
4404 -- Declaration for concurrent entity _object and its access type,
4405 -- along with the entry index subtype:
4406 -- type prot_typVP is access prot_typV;
4407 -- _object : prot_typVP := prot_typV (_O);
4408 -- subtype Jnn is <Type of Index> range Low .. High;
4410 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4411 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4413 -- Declaration for the Protection object, discriminals, privals and
4414 -- entry index constant:
4415 -- conc_typR : protection_typ renames _object._object;
4416 -- discr_nameD : discr_typ renames _object.discr_name;
4417 -- discr_nameD : discr_typ renames _task.discr_name;
4418 -- prival_name : comp_typ renames _object.comp_name;
4419 -- J : constant Jnn :=
4420 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4422 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4423 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4424 Debug_Nod := Debug_Renaming_Declaration (Decl);
4426 if Present (Debug_Nod) then
4427 Insert_After (Decl, Debug_Nod);
4433 end Debug_Private_Data_Declarations;
4435 ----------------------------
4436 -- Entry_Index_Expression --
4437 ----------------------------
4439 function Entry_Index_Expression
4443 Ttyp : Entity_Id) return Node_Id
4453 -- The queues of entries and entry families appear in textual order in
4454 -- the associated record. The entry index is computed as the sum of the
4455 -- number of queues for all entries that precede the designated one, to
4456 -- which is added the index expression, if this expression denotes a
4457 -- member of a family.
4459 -- The following is a place holder for the count of simple entries
4461 Num := Make_Integer_Literal (Sloc, 1);
4463 -- We construct an expression which is a series of addition operations.
4464 -- The first operand is the number of single entries that precede this
4465 -- one, the second operand is the index value relative to the start of
4466 -- the referenced family, and the remaining operands are the lengths of
4467 -- the entry families that precede this entry, i.e. the constructed
4470 -- number_simple_entries +
4471 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4472 -- family'length + ...
4474 -- where index-value is the given index value, and s is the index
4475 -- subtype (we have to use pos because the subtype might be an
4476 -- enumeration type preventing direct subtraction). Note that the task
4477 -- entry array is one-indexed.
4479 -- The upper bound of the entry family may be a discriminant, so we
4480 -- retrieve the lower bound explicitly to compute offset, rather than
4481 -- using the index subtype which may mention a discriminant.
4483 if Present (Index) then
4484 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4493 Make_Attribute_Reference (Sloc,
4494 Attribute_Name => Name_Pos,
4495 Prefix => New_Reference_To (Base_Type (S), Sloc),
4496 Expressions => New_List (Relocate_Node (Index))),
4504 -- Now add lengths of preceding entries and entry families
4506 Prev := First_Entity (Ttyp);
4508 while Chars (Prev) /= Chars (Ent)
4509 or else (Ekind (Prev) /= Ekind (Ent))
4510 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4512 if Ekind (Prev) = E_Entry then
4513 Set_Intval (Num, Intval (Num) + 1);
4515 elsif Ekind (Prev) = E_Entry_Family then
4517 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4518 Lo := Type_Low_Bound (S);
4519 Hi := Type_High_Bound (S);
4524 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4526 -- Other components are anonymous types to be ignored
4536 end Entry_Index_Expression;
4538 ---------------------------
4539 -- Establish_Task_Master --
4540 ---------------------------
4542 procedure Establish_Task_Master (N : Node_Id) is
4545 if Restriction_Active (No_Task_Hierarchy) = False then
4546 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4547 Prepend_To (Declarations (N), Call);
4550 end Establish_Task_Master;
4552 --------------------------------
4553 -- Expand_Accept_Declarations --
4554 --------------------------------
4556 -- Part of the expansion of an accept statement involves the creation of
4557 -- a declaration that can be referenced from the statement sequence of
4562 -- This declaration is inserted immediately before the accept statement
4563 -- and it is important that it be inserted before the statements of the
4564 -- statement sequence are analyzed. Thus it would be too late to create
4565 -- this declaration in the Expand_N_Accept_Statement routine, which is
4566 -- why there is a separate procedure to be called directly from Sem_Ch9.
4568 -- Ann is used to hold the address of the record containing the parameters
4569 -- (see Expand_N_Entry_Call for more details on how this record is built).
4570 -- References to the parameters do an unchecked conversion of this address
4571 -- to a pointer to the required record type, and then access the field that
4572 -- holds the value of the required parameter. The entity for the address
4573 -- variable is held as the top stack element (i.e. the last element) of the
4574 -- Accept_Address stack in the corresponding entry entity, and this element
4575 -- must be set in place before the statements are processed.
4577 -- The above description applies to the case of a stand alone accept
4578 -- statement, i.e. one not appearing as part of a select alternative.
4580 -- For the case of an accept that appears as part of a select alternative
4581 -- of a selective accept, we must still create the declaration right away,
4582 -- since Ann is needed immediately, but there is an important difference:
4584 -- The declaration is inserted before the selective accept, not before
4585 -- the accept statement (which is not part of a list anyway, and so would
4586 -- not accommodate inserted declarations)
4588 -- We only need one address variable for the entire selective accept. So
4589 -- the Ann declaration is created only for the first accept alternative,
4590 -- and subsequent accept alternatives reference the same Ann variable.
4592 -- We can distinguish the two cases by seeing whether the accept statement
4593 -- is part of a list. If not, then it must be in an accept alternative.
4595 -- To expand the requeue statement, a label is provided at the end of the
4596 -- accept statement or alternative of which it is a part, so that the
4597 -- statement can be skipped after the requeue is complete. This label is
4598 -- created here rather than during the expansion of the accept statement,
4599 -- because it will be needed by any requeue statements within the accept,
4600 -- which are expanded before the accept.
4602 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4603 Loc : constant Source_Ptr := Sloc (N);
4604 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4605 Ann : Entity_Id := Empty;
4613 if Expander_Active then
4615 -- If we have no handled statement sequence, we may need to build
4616 -- a dummy sequence consisting of a null statement. This can be
4617 -- skipped if the trivial accept optimization is permitted.
4619 if not Trivial_Accept_OK
4621 (No (Stats) or else Null_Statements (Statements (Stats)))
4623 Set_Handled_Statement_Sequence (N,
4624 Make_Handled_Sequence_Of_Statements (Loc,
4625 New_List (Make_Null_Statement (Loc))));
4628 -- Create and declare two labels to be placed at the end of the
4629 -- accept statement. The first label is used to allow requeues to
4630 -- skip the remainder of entry processing. The second label is used
4631 -- to skip the remainder of entry processing if the rendezvous
4632 -- completes in the middle of the accept body.
4634 if Present (Handled_Statement_Sequence (N)) then
4635 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4637 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4638 Lab := Make_Label (Loc, Lab_Id);
4640 Make_Implicit_Label_Declaration (Loc,
4641 Defining_Identifier => Entity (Lab_Id),
4642 Label_Construct => Lab);
4643 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4645 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4647 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4648 Lab := Make_Label (Loc, Lab_Id);
4650 Make_Implicit_Label_Declaration (Loc,
4651 Defining_Identifier => Entity (Lab_Id),
4652 Label_Construct => Lab);
4653 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4660 -- Case of stand alone accept statement
4662 if Is_List_Member (N) then
4664 if Present (Handled_Statement_Sequence (N)) then
4666 Make_Defining_Identifier (Loc,
4667 Chars => New_Internal_Name ('A'));
4670 Make_Object_Declaration (Loc,
4671 Defining_Identifier => Ann,
4672 Object_Definition =>
4673 New_Reference_To (RTE (RE_Address), Loc));
4675 Insert_Before (N, Adecl);
4678 Insert_Before (N, Ldecl);
4681 Insert_Before (N, Ldecl2);
4685 -- Case of accept statement which is in an accept alternative
4689 Acc_Alt : constant Node_Id := Parent (N);
4690 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4694 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4695 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4697 -- ??? Consider a single label for select statements
4699 if Present (Handled_Statement_Sequence (N)) then
4701 Statements (Handled_Statement_Sequence (N)));
4705 Statements (Handled_Statement_Sequence (N)));
4709 -- Find first accept alternative of the selective accept. A
4710 -- valid selective accept must have at least one accept in it.
4712 Alt := First (Select_Alternatives (Sel_Acc));
4714 while Nkind (Alt) /= N_Accept_Alternative loop
4718 -- If we are the first accept statement, then we have to create
4719 -- the Ann variable, as for the stand alone case, except that
4720 -- it is inserted before the selective accept. Similarly, a
4721 -- label for requeue expansion must be declared.
4723 if N = Accept_Statement (Alt) then
4725 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4728 Make_Object_Declaration (Loc,
4729 Defining_Identifier => Ann,
4730 Object_Definition =>
4731 New_Reference_To (RTE (RE_Address), Loc));
4733 Insert_Before (Sel_Acc, Adecl);
4736 -- If we are not the first accept statement, then find the Ann
4737 -- variable allocated by the first accept and use it.
4741 Node (Last_Elmt (Accept_Address
4742 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4747 -- Merge here with Ann either created or referenced, and Adecl
4748 -- pointing to the corresponding declaration. Remaining processing
4749 -- is the same for the two cases.
4751 if Present (Ann) then
4752 Append_Elmt (Ann, Accept_Address (Ent));
4753 Set_Debug_Info_Needed (Ann);
4756 -- Create renaming declarations for the entry formals. Each reference
4757 -- to a formal becomes a dereference of a component of the parameter
4758 -- block, whose address is held in Ann. These declarations are
4759 -- eventually inserted into the accept block, and analyzed there so
4760 -- that they have the proper scope for gdb and do not conflict with
4761 -- other declarations.
4763 if Present (Parameter_Specifications (N))
4764 and then Present (Handled_Statement_Sequence (N))
4774 Formal := First_Formal (Ent);
4776 while Present (Formal) loop
4777 Comp := Entry_Component (Formal);
4779 Make_Defining_Identifier (Loc, Chars (Formal));
4781 Set_Etype (New_F, Etype (Formal));
4782 Set_Scope (New_F, Ent);
4784 -- Now we set debug info needed on New_F even though it does
4785 -- not come from source, so that the debugger will get the
4786 -- right information for these generated names.
4788 Set_Debug_Info_Needed (New_F);
4790 if Ekind (Formal) = E_In_Parameter then
4791 Set_Ekind (New_F, E_Constant);
4793 Set_Ekind (New_F, E_Variable);
4794 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4797 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4800 Make_Object_Renaming_Declaration (Loc,
4801 Defining_Identifier =>
4804 New_Reference_To (Etype (Formal), Loc),
4806 Make_Explicit_Dereference (Loc,
4807 Make_Selected_Component (Loc,
4809 Unchecked_Convert_To (
4810 Entry_Parameters_Type (Ent),
4811 New_Reference_To (Ann, Loc)),
4813 New_Reference_To (Comp, Loc))));
4815 if No (Declarations (N)) then
4816 Set_Declarations (N, New_List);
4819 Append (Decl, Declarations (N));
4820 Set_Renamed_Object (Formal, New_F);
4821 Next_Formal (Formal);
4828 end Expand_Accept_Declarations;
4830 ---------------------------------------------
4831 -- Expand_Access_Protected_Subprogram_Type --
4832 ---------------------------------------------
4834 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4835 Loc : constant Source_Ptr := Sloc (N);
4837 T : constant Entity_Id := Defining_Identifier (N);
4838 D_T : constant Entity_Id := Designated_Type (T);
4839 D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc,
4840 Chars => New_Internal_Name ('D'));
4841 E_T : constant Entity_Id := Make_Defining_Identifier (Loc,
4842 Chars => New_Internal_Name ('E'));
4843 P_List : constant List_Id := Build_Protected_Spec
4844 (N, RTE (RE_Address), D_T, False);
4850 -- Create access to subprogram with full signature
4852 if Etype (D_T) /= Standard_Void_Type then
4854 Make_Access_Function_Definition (Loc,
4855 Parameter_Specifications => P_List,
4856 Result_Definition =>
4857 Copy_Result_Type (Result_Definition (Type_Definition (N))));
4861 Make_Access_Procedure_Definition (Loc,
4862 Parameter_Specifications => P_List);
4866 Make_Full_Type_Declaration (Loc,
4867 Defining_Identifier => D_T2,
4868 Type_Definition => Def1);
4870 Insert_After (N, Decl1);
4873 -- Create Equivalent_Type, a record with two components for an access to
4874 -- object and an access to subprogram.
4877 Make_Component_Declaration (Loc,
4878 Defining_Identifier =>
4879 Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
4880 Component_Definition =>
4881 Make_Component_Definition (Loc,
4882 Aliased_Present => False,
4883 Subtype_Indication =>
4884 New_Occurrence_Of (RTE (RE_Address), Loc))),
4886 Make_Component_Declaration (Loc,
4887 Defining_Identifier =>
4888 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4889 Component_Definition =>
4890 Make_Component_Definition (Loc,
4891 Aliased_Present => False,
4892 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4895 Make_Full_Type_Declaration (Loc,
4896 Defining_Identifier => E_T,
4898 Make_Record_Definition (Loc,
4900 Make_Component_List (Loc,
4901 Component_Items => Comps)));
4903 Insert_After (Decl1, Decl2);
4905 Set_Equivalent_Type (T, E_T);
4906 end Expand_Access_Protected_Subprogram_Type;
4908 --------------------------
4909 -- Expand_Entry_Barrier --
4910 --------------------------
4912 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4913 Cond : constant Node_Id :=
4914 Condition (Entry_Body_Formal_Part (N));
4915 Prot : constant Entity_Id := Scope (Ent);
4916 Spec_Decl : constant Node_Id := Parent (Prot);
4919 Body_Decl : Node_Id;
4922 if No_Run_Time_Mode then
4923 Error_Msg_CRT ("entry barrier", N);
4927 -- The body of the entry barrier must be analyzed in the context of the
4928 -- protected object, but its scope is external to it, just as any other
4929 -- unprotected version of a protected operation. The specification has
4930 -- been produced when the protected type declaration was elaborated. We
4931 -- build the body, insert it in the enclosing scope, but analyze it in
4932 -- the current context. A more uniform approach would be to treat the
4933 -- barrier just as a protected function, and discard the protected
4934 -- version of it because it is never called.
4936 if Expander_Active then
4937 B_F := Build_Barrier_Function (N, Ent, Prot);
4938 Func := Barrier_Function (Ent);
4939 Set_Corresponding_Spec (B_F, Func);
4941 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
4943 if Nkind (Parent (Body_Decl)) = N_Subunit then
4944 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
4947 Insert_Before_And_Analyze (Body_Decl, B_F);
4949 Set_Discriminals (Spec_Decl);
4950 Set_Scope (Func, Scope (Prot));
4953 Analyze_And_Resolve (Cond, Any_Boolean);
4956 -- The Ravenscar profile restricts barriers to simple variables declared
4957 -- within the protected object. We also allow Boolean constants, since
4958 -- these appear in several published examples and are also allowed by
4959 -- the Aonix compiler.
4961 -- Note that after analysis variables in this context will be replaced
4962 -- by the corresponding prival, that is to say a renaming of a selected
4963 -- component of the form _Object.Var. If expansion is disabled, as
4964 -- within a generic, we check that the entity appears in the current
4967 if Is_Entity_Name (Cond) then
4969 -- A small optimization of useless renamings. If the scope of the
4970 -- entity of the condition is not the barrier function, then the
4971 -- condition does not reference any of the generated renamings
4972 -- within the function.
4975 and then Scope (Entity (Cond)) /= Func
4977 Set_Declarations (B_F, Empty_List);
4980 if Entity (Cond) = Standard_False
4982 Entity (Cond) = Standard_True
4986 elsif not Expander_Active
4987 and then Scope (Entity (Cond)) = Current_Scope
4991 -- Check for case of _object.all.field (note that the explicit
4992 -- dereference gets inserted by analyze/expand of _object.field)
4994 elsif Present (Renamed_Object (Entity (Cond)))
4996 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5000 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5006 -- It is not a boolean variable or literal, so check the restriction
5008 Check_Restriction (Simple_Barriers, Cond);
5009 end Expand_Entry_Barrier;
5011 ------------------------------
5012 -- Expand_N_Abort_Statement --
5013 ------------------------------
5015 -- Expand abort T1, T2, .. Tn; into:
5016 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5018 procedure Expand_N_Abort_Statement (N : Node_Id) is
5019 Loc : constant Source_Ptr := Sloc (N);
5020 Tlist : constant List_Id := Names (N);
5026 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5029 Tasknm := First (Tlist);
5031 while Present (Tasknm) loop
5034 -- A task interface class-wide type object is being aborted.
5035 -- Retrieve its _task_id by calling a dispatching routine.
5037 if Ada_Version >= Ada_05
5038 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5039 and then Is_Interface (Etype (Tasknm))
5040 and then Is_Task_Interface (Etype (Tasknm))
5042 Append_To (Component_Associations (Aggr),
5043 Make_Component_Association (Loc,
5044 Choices => New_List (
5045 Make_Integer_Literal (Loc, Count)),
5048 -- Task_Id (Tasknm._disp_get_task_id)
5050 Make_Unchecked_Type_Conversion (Loc,
5052 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5054 Make_Selected_Component (Loc,
5056 New_Copy_Tree (Tasknm),
5058 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5061 Append_To (Component_Associations (Aggr),
5062 Make_Component_Association (Loc,
5063 Choices => New_List (
5064 Make_Integer_Literal (Loc, Count)),
5065 Expression => Concurrent_Ref (Tasknm)));
5072 Make_Procedure_Call_Statement (Loc,
5073 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5074 Parameter_Associations => New_List (
5075 Make_Qualified_Expression (Loc,
5076 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5077 Expression => Aggr))));
5080 end Expand_N_Abort_Statement;
5082 -------------------------------
5083 -- Expand_N_Accept_Statement --
5084 -------------------------------
5086 -- This procedure handles expansion of accept statements that stand
5087 -- alone, i.e. they are not part of an accept alternative. The expansion
5088 -- of accept statement in accept alternatives is handled by the routines
5089 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5090 -- following description applies only to stand alone accept statements.
5092 -- If there is no handled statement sequence, or only null statements,
5093 -- then this is called a trivial accept, and the expansion is:
5095 -- Accept_Trivial (entry-index)
5097 -- If there is a handled statement sequence, then the expansion is:
5104 -- Accept_Call (entry-index, Ann);
5105 -- Renaming_Declarations for formals
5106 -- <statement sequence from N_Accept_Statement node>
5107 -- Complete_Rendezvous;
5112 -- <exception handler from N_Accept_Statement node>
5113 -- Complete_Rendezvous;
5115 -- <exception handler from N_Accept_Statement node>
5116 -- Complete_Rendezvous;
5121 -- when all others =>
5122 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5125 -- The first three declarations were already inserted ahead of the accept
5126 -- statement by the Expand_Accept_Declarations procedure, which was called
5127 -- directly from the semantics during analysis of the accept statement,
5128 -- before analyzing its contained statements.
5130 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5131 -- from possible expansion activity (the original source of course does
5132 -- not have any declarations associated with the accept statement, since
5133 -- an accept statement has no declarative part). In particular, if the
5134 -- expander is active, the first such declaration is the declaration of
5135 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5137 -- The two blocks are merged into a single block if the inner block has
5138 -- no exception handlers, but otherwise two blocks are required, since
5139 -- exceptions might be raised in the exception handlers of the inner
5140 -- block, and Exceptional_Complete_Rendezvous must be called.
5142 procedure Expand_N_Accept_Statement (N : Node_Id) is
5143 Loc : constant Source_Ptr := Sloc (N);
5144 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5145 Ename : constant Node_Id := Entry_Direct_Name (N);
5146 Eindx : constant Node_Id := Entry_Index (N);
5147 Eent : constant Entity_Id := Entity (Ename);
5148 Acstack : constant Elist_Id := Accept_Address (Eent);
5149 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5150 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5155 -- Start of processing for Expand_N_Accept_Statement
5158 -- If accept statement is not part of a list, then its parent must be
5159 -- an accept alternative, and, as described above, we do not do any
5160 -- expansion for such accept statements at this level.
5162 if not Is_List_Member (N) then
5163 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5166 -- Trivial accept case (no statement sequence, or null statements).
5167 -- If the accept statement has declarations, then just insert them
5168 -- before the procedure call.
5170 elsif Trivial_Accept_OK
5171 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5173 -- Remove declarations for renamings, because the parameter block
5174 -- will not be assigned.
5181 D := First (Declarations (N));
5183 while Present (D) loop
5185 if Nkind (D) = N_Object_Renaming_Declaration then
5193 if Present (Declarations (N)) then
5194 Insert_Actions (N, Declarations (N));
5198 Make_Procedure_Call_Statement (Loc,
5199 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5200 Parameter_Associations => New_List (
5201 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5205 -- Discard Entry_Address that was created for it, so it will not be
5206 -- emitted if this accept statement is in the statement part of a
5207 -- delay alternative.
5209 if Present (Stats) then
5210 Remove_Last_Elmt (Acstack);
5213 -- Case of statement sequence present
5216 -- Construct the block, using the declarations from the accept
5217 -- statement if any to initialize the declarations of the block.
5219 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5220 Set_Ekind (Blkent, E_Block);
5221 Set_Etype (Blkent, Standard_Void_Type);
5222 Set_Scope (Blkent, Current_Scope);
5225 Make_Block_Statement (Loc,
5226 Identifier => New_Reference_To (Blkent, Loc),
5227 Declarations => Declarations (N),
5228 Handled_Statement_Sequence => Build_Accept_Body (N));
5230 -- Prepend call to Accept_Call to main statement sequence If the
5231 -- accept has exception handlers, the statement sequence is wrapped
5232 -- in a block. Insert call and renaming declarations in the
5233 -- declarations of the block, so they are elaborated before the
5237 Make_Procedure_Call_Statement (Loc,
5238 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5239 Parameter_Associations => New_List (
5240 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5241 New_Reference_To (Ann, Loc)));
5243 if Parent (Stats) = N then
5244 Prepend (Call, Statements (Stats));
5253 Push_Scope (Blkent);
5261 D := First (Declarations (N));
5262 while Present (D) loop
5265 if Nkind (D) = N_Object_Renaming_Declaration then
5267 -- The renaming declarations for the formals were created
5268 -- during analysis of the accept statement, and attached to
5269 -- the list of declarations. Place them now in the context
5270 -- of the accept block or subprogram.
5273 Typ := Entity (Subtype_Mark (D));
5274 Insert_After (Call, D);
5277 -- If the formal is class_wide, it does not have an actual
5278 -- subtype. The analysis of the renaming declaration creates
5279 -- one, but we need to retain the class-wide nature of the
5282 if Is_Class_Wide_Type (Typ) then
5283 Set_Etype (Defining_Identifier (D), Typ);
5294 -- Replace the accept statement by the new block
5299 -- Last step is to unstack the Accept_Address value
5301 Remove_Last_Elmt (Acstack);
5303 end Expand_N_Accept_Statement;
5305 ----------------------------------
5306 -- Expand_N_Asynchronous_Select --
5307 ----------------------------------
5309 -- This procedure assumes that the trigger statement is an entry call or
5310 -- a dispatching procedure call. A delay alternative should already have
5311 -- been expanded into an entry call to the appropriate delay object Wait
5314 -- If the trigger is a task entry call, the select is implemented with
5315 -- a Task_Entry_Call:
5320 -- P : parms := (parm, parm, parm);
5322 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5324 -- procedure _clean is
5327 -- Cancel_Task_Entry_Call (C);
5334 -- (<acceptor-task>, -- Acceptor
5335 -- <entry-index>, -- E
5336 -- P'Address, -- Uninterpreted_Data
5337 -- Asynchronous_Call, -- Mode
5338 -- B); -- Rendezvous_Successful
5345 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5348 -- when Abort_Signal => Abort_Undefer;
5355 -- <triggered-statements>
5359 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5360 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5364 -- P : parms := (parm, parm, parm);
5366 -- Call_Simple (acceptor-task, entry-index, P'Address);
5372 -- so the task at hand is to convert the latter expansion into the former
5374 -- If the trigger is a protected entry call, the select is implemented
5375 -- with Protected_Entry_Call:
5378 -- P : E1_Params := (param, param, param);
5379 -- Bnn : Communications_Block;
5384 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5386 -- procedure _clean is
5389 -- if Enqueued (Bnn) then
5390 -- Cancel_Protected_Entry_Call (Bnn);
5397 -- Protected_Entry_Call
5398 -- (po._object'Access, -- Object
5399 -- <entry index>, -- E
5400 -- P'Address, -- Uninterpreted_Data
5401 -- Asynchronous_Call, -- Mode
5404 -- if Enqueued (Bnn) then
5408 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5411 -- when Abort_Signal => Abort_Undefer;
5414 -- if not Cancelled (Bnn) then
5415 -- <triggered-statements>
5419 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5423 -- P : E1_Params := (param, param, param);
5424 -- Bnn : Communications_Block;
5427 -- Protected_Entry_Call
5428 -- (po._object'Access, -- Object
5429 -- <entry index>, -- E
5430 -- P'Address, -- Uninterpreted_Data
5431 -- Simple_Call, -- Mode
5438 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5442 -- B : Boolean := False;
5443 -- Bnn : Communication_Block;
5444 -- C : Ada.Tags.Prim_Op_Kind;
5445 -- D : System.Storage_Elements.Dummy_Communication_Block;
5446 -- K : Ada.Tags.Tagged_Kind :=
5447 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5448 -- P : Parameters := (Param1 .. ParamN);
5453 -- if K = Ada.Tags.TK_Limited_Tagged then
5454 -- <dispatching-call>;
5455 -- <triggering-statements>;
5459 -- Ada.Tags.Get_Offset_Index
5460 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5462 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5464 -- if C = POK_Protected_Entry then
5466 -- procedure _clean is
5468 -- if Enqueued (Bnn) then
5469 -- Cancel_Protected_Entry_Call (Bnn);
5475 -- _Disp_Asynchronous_Select
5476 -- (<object>, S, P'Address, D, B);
5477 -- Bnn := Communication_Block (D);
5479 -- Param1 := P.Param1;
5481 -- ParamN := P.ParamN;
5483 -- if Enqueued (Bnn) then
5484 -- <abortable-statements>
5487 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5490 -- when Abort_Signal => Abort_Undefer;
5493 -- if not Cancelled (Bnn) then
5494 -- <triggering-statements>
5497 -- elsif C = POK_Task_Entry then
5499 -- procedure _clean is
5501 -- Cancel_Task_Entry_Call (U);
5507 -- _Disp_Asynchronous_Select
5508 -- (<object>, S, P'Address, D, B);
5509 -- Bnn := Communication_Bloc (D);
5511 -- Param1 := P.Param1;
5513 -- ParamN := P.ParamN;
5518 -- <abortable-statements>
5520 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5523 -- when Abort_Signal => Abort_Undefer;
5527 -- <triggering-statements>
5532 -- <dispatching-call>;
5533 -- <triggering-statements>
5538 -- The job is to convert this to the asynchronous form
5540 -- If the trigger is a delay statement, it will have been expanded into a
5541 -- call to one of the GNARL delay procedures. This routine will convert
5542 -- this into a protected entry call on a delay object and then continue
5543 -- processing as for a protected entry call trigger. This requires
5544 -- declaring a Delay_Block object and adding a pointer to this object to
5545 -- the parameter list of the delay procedure to form the parameter list of
5546 -- the entry call. This object is used by the runtime to queue the delay
5549 -- For a description of the use of P and the assignments after the call,
5550 -- see Expand_N_Entry_Call_Statement.
5552 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5553 Loc : constant Source_Ptr := Sloc (N);
5554 Abrt : constant Node_Id := Abortable_Part (N);
5555 Astats : constant List_Id := Statements (Abrt);
5556 Trig : constant Node_Id := Triggering_Alternative (N);
5557 Tstats : constant List_Id := Statements (Trig);
5559 Abort_Block_Ent : Entity_Id;
5560 Abortable_Block : Node_Id;
5562 Blk_Ent : Entity_Id;
5563 Blk_Typ : Entity_Id;
5565 Call_Ent : Entity_Id;
5566 Cancel_Param : Entity_Id;
5567 Cleanup_Block : Node_Id;
5568 Cleanup_Block_Ent : Entity_Id;
5569 Cleanup_Stmts : List_Id;
5570 Conc_Typ_Stmts : List_Id;
5572 Dblock_Ent : Entity_Id;
5577 Enqueue_Call : Node_Id;
5581 Lim_Typ_Stmts : List_Id;
5587 ProtE_Stmts : List_Id;
5588 ProtP_Stmts : List_Id;
5591 Target_Undefer : RE_Id;
5592 TaskE_Stmts : List_Id;
5593 Undefer_Args : List_Id := No_List;
5595 B : Entity_Id; -- Call status flag
5596 Bnn : Entity_Id; -- Communication block
5597 C : Entity_Id; -- Call kind
5598 K : Entity_Id; -- Tagged kind
5599 P : Entity_Id; -- Parameter block
5600 S : Entity_Id; -- Primitive operation slot
5601 T : Entity_Id; -- Additional status flag
5604 Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5605 Ecall := Triggering_Statement (Trig);
5607 -- The arguments in the call may require dynamic allocation, and the
5608 -- call statement may have been transformed into a block. The block
5609 -- may contain additional declarations for internal entities, and the
5610 -- original call is found by sequential search.
5612 if Nkind (Ecall) = N_Block_Statement then
5613 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5614 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5615 N_Entry_Call_Statement)
5621 -- This is either a dispatching call or a delay statement used as a
5622 -- trigger which was expanded into a procedure call.
5624 if Nkind (Ecall) = N_Procedure_Call_Statement then
5625 if Ada_Version >= Ada_05
5627 (No (Original_Node (Ecall))
5628 or else not Nkind_In (Original_Node (Ecall),
5629 N_Delay_Relative_Statement,
5630 N_Delay_Until_Statement))
5632 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5637 -- Call status flag processing, generate:
5638 -- B : Boolean := False;
5640 B := Build_B (Loc, Decls);
5642 -- Communication block processing, generate:
5643 -- Bnn : Communication_Block;
5645 Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
5648 Make_Object_Declaration (Loc,
5649 Defining_Identifier =>
5651 Object_Definition =>
5652 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5654 -- Call kind processing, generate:
5655 -- C : Ada.Tags.Prim_Op_Kind;
5657 C := Build_C (Loc, Decls);
5659 -- Tagged kind processing, generate:
5660 -- K : Ada.Tags.Tagged_Kind :=
5661 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5663 -- Dummy communication block, generate:
5664 -- D : Dummy_Communication_Block;
5667 Make_Object_Declaration (Loc,
5668 Defining_Identifier =>
5669 Make_Defining_Identifier (Loc, Name_uD),
5670 Object_Definition =>
5672 RTE (RE_Dummy_Communication_Block), Loc)));
5674 K := Build_K (Loc, Decls, Obj);
5676 -- Parameter block processing
5678 Blk_Typ := Build_Parameter_Block
5679 (Loc, Actuals, Formals, Decls);
5680 P := Parameter_Block_Pack
5681 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5683 -- Dispatch table slot processing, generate:
5686 S := Build_S (Loc, Decls);
5688 -- Additional status flag processing, generate:
5690 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
5693 Make_Object_Declaration (Loc,
5694 Defining_Identifier =>
5696 Object_Definition =>
5697 New_Reference_To (Standard_Boolean, Loc)));
5699 ------------------------------
5700 -- Protected entry handling --
5701 ------------------------------
5704 -- Param1 := P.Param1;
5706 -- ParamN := P.ParamN;
5708 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5711 -- Bnn := Communication_Block (D);
5713 Prepend_To (Cleanup_Stmts,
5714 Make_Assignment_Statement (Loc,
5716 New_Reference_To (Bnn, Loc),
5718 Make_Unchecked_Type_Conversion (Loc,
5720 New_Reference_To (RTE (RE_Communication_Block), Loc),
5722 Make_Identifier (Loc, Name_uD))));
5725 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5727 Prepend_To (Cleanup_Stmts,
5728 Make_Procedure_Call_Statement (Loc,
5731 Find_Prim_Op (Etype (Etype (Obj)),
5732 Name_uDisp_Asynchronous_Select),
5734 Parameter_Associations =>
5736 New_Copy_Tree (Obj), -- <object>
5737 New_Reference_To (S, Loc), -- S
5738 Make_Attribute_Reference (Loc, -- P'Address
5740 New_Reference_To (P, Loc),
5743 Make_Identifier (Loc, Name_uD), -- D
5744 New_Reference_To (B, Loc)))); -- B
5747 -- if Enqueued (Bnn) then
5748 -- <abortable-statements>
5751 Append_To (Cleanup_Stmts,
5752 Make_If_Statement (Loc,
5754 Make_Function_Call (Loc,
5756 New_Reference_To (RTE (RE_Enqueued), Loc),
5757 Parameter_Associations =>
5759 New_Reference_To (Bnn, Loc))),
5762 New_Copy_List_Tree (Astats)));
5764 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5765 -- will then generate a _clean for the communication block Bnn.
5769 -- procedure _clean is
5771 -- if Enqueued (Bnn) then
5772 -- Cancel_Protected_Entry_Call (Bnn);
5781 Cleanup_Block_Ent :=
5782 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5785 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5787 -- Wrap the cleanup block in an exception handling block
5793 -- when Abort_Signal => Abort_Undefer;
5797 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5801 Make_Implicit_Label_Declaration (Loc,
5802 Defining_Identifier =>
5806 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5809 -- if not Cancelled (Bnn) then
5810 -- <triggering-statements>
5813 Append_To (ProtE_Stmts,
5814 Make_If_Statement (Loc,
5818 Make_Function_Call (Loc,
5820 New_Reference_To (RTE (RE_Cancelled), Loc),
5821 Parameter_Associations =>
5823 New_Reference_To (Bnn, Loc)))),
5826 New_Copy_List_Tree (Tstats)));
5828 -------------------------
5829 -- Task entry handling --
5830 -------------------------
5833 -- Param1 := P.Param1;
5835 -- ParamN := P.ParamN;
5837 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5840 -- Bnn := Communication_Block (D);
5842 Append_To (TaskE_Stmts,
5843 Make_Assignment_Statement (Loc,
5845 New_Reference_To (Bnn, Loc),
5847 Make_Unchecked_Type_Conversion (Loc,
5849 New_Reference_To (RTE (RE_Communication_Block), Loc),
5851 Make_Identifier (Loc, Name_uD))));
5854 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5856 Prepend_To (TaskE_Stmts,
5857 Make_Procedure_Call_Statement (Loc,
5860 Find_Prim_Op (Etype (Etype (Obj)),
5861 Name_uDisp_Asynchronous_Select),
5863 Parameter_Associations =>
5865 New_Copy_Tree (Obj), -- <object>
5866 New_Reference_To (S, Loc), -- S
5867 Make_Attribute_Reference (Loc, -- P'Address
5869 New_Reference_To (P, Loc),
5872 Make_Identifier (Loc, Name_uD), -- D
5873 New_Reference_To (B, Loc)))); -- B
5878 Prepend_To (TaskE_Stmts,
5879 Make_Procedure_Call_Statement (Loc,
5881 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5882 Parameter_Associations =>
5887 -- <abortable-statements>
5889 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5891 Prepend_To (Cleanup_Stmts,
5892 Make_Procedure_Call_Statement (Loc,
5894 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5895 Parameter_Associations =>
5898 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5899 -- will generate a _clean for the additional status flag.
5903 -- procedure _clean is
5905 -- Cancel_Task_Entry_Call (U);
5913 Cleanup_Block_Ent :=
5914 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5917 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
5919 -- Wrap the cleanup block in an exception handling block
5925 -- when Abort_Signal => Abort_Undefer;
5929 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5931 Append_To (TaskE_Stmts,
5932 Make_Implicit_Label_Declaration (Loc,
5933 Defining_Identifier =>
5936 Append_To (TaskE_Stmts,
5938 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5942 -- <triggering-statements>
5945 Append_To (TaskE_Stmts,
5946 Make_If_Statement (Loc,
5950 New_Reference_To (T, Loc)),
5953 New_Copy_List_Tree (Tstats)));
5955 ----------------------------------
5956 -- Protected procedure handling --
5957 ----------------------------------
5960 -- <dispatching-call>;
5961 -- <triggering-statements>
5963 ProtP_Stmts := New_Copy_List_Tree (Tstats);
5964 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
5967 -- S := Ada.Tags.Get_Offset_Index
5968 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
5971 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
5974 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5976 Append_To (Conc_Typ_Stmts,
5977 Make_Procedure_Call_Statement (Loc,
5980 Find_Prim_Op (Etype (Etype (Obj)),
5981 Name_uDisp_Get_Prim_Op_Kind),
5983 Parameter_Associations =>
5985 New_Copy_Tree (Obj),
5986 New_Reference_To (S, Loc),
5987 New_Reference_To (C, Loc))));
5990 -- if C = POK_Procedure_Entry then
5992 -- elsif C = POK_Task_Entry then
5998 Append_To (Conc_Typ_Stmts,
5999 Make_If_Statement (Loc,
6003 New_Reference_To (C, Loc),
6005 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6012 Make_Elsif_Part (Loc,
6016 New_Reference_To (C, Loc),
6018 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6027 -- <dispatching-call>;
6028 -- <triggering-statements>
6030 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6031 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6034 -- if K = Ada.Tags.TK_Limited_Tagged then
6041 Make_If_Statement (Loc,
6045 New_Reference_To (K, Loc),
6047 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6056 Make_Block_Statement (Loc,
6059 Handled_Statement_Sequence =>
6060 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6065 -- Delay triggering statement processing
6068 -- Add a Delay_Block object to the parameter list of the delay
6069 -- procedure to form the parameter list of the Wait entry call.
6072 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
6074 Pdef := Entity (Name (Ecall));
6076 if Is_RTE (Pdef, RO_CA_Delay_For) then
6078 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6080 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6082 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6084 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6085 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6088 Append_To (Parameter_Associations (Ecall),
6089 Make_Attribute_Reference (Loc,
6090 Prefix => New_Reference_To (Dblock_Ent, Loc),
6091 Attribute_Name => Name_Unchecked_Access));
6093 -- Create the inner block to protect the abortable part
6096 Make_Implicit_Exception_Handler (Loc,
6097 Exception_Choices =>
6098 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6099 Statements => New_List (
6100 Make_Procedure_Call_Statement (Loc,
6101 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6104 Make_Procedure_Call_Statement (Loc,
6105 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6108 Make_Block_Statement (Loc,
6109 Identifier => New_Reference_To (Blk_Ent, Loc),
6110 Handled_Statement_Sequence =>
6111 Make_Handled_Sequence_Of_Statements (Loc,
6112 Statements => Astats),
6113 Has_Created_Identifier => True,
6114 Is_Asynchronous_Call_Block => True);
6116 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6119 Make_Implicit_If_Statement (N,
6120 Condition => Make_Function_Call (Loc,
6121 Name => Enqueue_Call,
6122 Parameter_Associations => Parameter_Associations (Ecall)),
6124 New_List (Make_Block_Statement (Loc,
6125 Handled_Statement_Sequence =>
6126 Make_Handled_Sequence_Of_Statements (Loc,
6127 Statements => New_List (
6128 Make_Implicit_Label_Declaration (Loc,
6129 Defining_Identifier => Blk_Ent,
6130 Label_Construct => Abortable_Block),
6132 Exception_Handlers => Hdle)))));
6134 Stmts := New_List (Ecall);
6136 -- Construct statement sequence for new block
6139 Make_Implicit_If_Statement (N,
6140 Condition => Make_Function_Call (Loc,
6141 Name => New_Reference_To (
6142 RTE (RE_Timed_Out), Loc),
6143 Parameter_Associations => New_List (
6144 Make_Attribute_Reference (Loc,
6145 Prefix => New_Reference_To (Dblock_Ent, Loc),
6146 Attribute_Name => Name_Unchecked_Access))),
6147 Then_Statements => Tstats));
6149 -- The result is the new block
6151 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6154 Make_Block_Statement (Loc,
6155 Declarations => New_List (
6156 Make_Object_Declaration (Loc,
6157 Defining_Identifier => Dblock_Ent,
6158 Aliased_Present => True,
6159 Object_Definition => New_Reference_To (
6160 RTE (RE_Delay_Block), Loc))),
6162 Handled_Statement_Sequence =>
6163 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6173 Extract_Entry (Ecall, Concval, Ename, Index);
6174 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6176 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6177 Decls := Declarations (Ecall);
6179 if Is_Protected_Type (Etype (Concval)) then
6181 -- Get the declarations of the block expanded from the entry call
6183 Decl := First (Decls);
6184 while Present (Decl)
6186 (Nkind (Decl) /= N_Object_Declaration
6187 or else not Is_RTE (Etype (Object_Definition (Decl)),
6188 RE_Communication_Block))
6193 pragma Assert (Present (Decl));
6194 Cancel_Param := Defining_Identifier (Decl);
6196 -- Change the mode of the Protected_Entry_Call call
6198 -- Protected_Entry_Call (
6199 -- Object => po._object'Access,
6200 -- E => <entry index>;
6201 -- Uninterpreted_Data => P'Address;
6202 -- Mode => Asynchronous_Call;
6205 Stmt := First (Stmts);
6207 -- Skip assignments to temporaries created for in-out parameters
6209 -- This makes unwarranted assumptions about the shape of the expanded
6210 -- tree for the call, and should be cleaned up ???
6212 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6218 Param := First (Parameter_Associations (Call));
6219 while Present (Param)
6220 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6225 pragma Assert (Present (Param));
6226 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6229 -- Append an if statement to execute the abortable part
6232 -- if Enqueued (Bnn) then
6235 Make_Implicit_If_Statement (N,
6236 Condition => Make_Function_Call (Loc,
6237 Name => New_Reference_To (
6238 RTE (RE_Enqueued), Loc),
6239 Parameter_Associations => New_List (
6240 New_Reference_To (Cancel_Param, Loc))),
6241 Then_Statements => Astats));
6244 Make_Block_Statement (Loc,
6245 Identifier => New_Reference_To (Blk_Ent, Loc),
6246 Handled_Statement_Sequence =>
6247 Make_Handled_Sequence_Of_Statements (Loc,
6248 Statements => Stmts),
6249 Has_Created_Identifier => True,
6250 Is_Asynchronous_Call_Block => True);
6252 -- For the VM call Update_Exception instead of Abort_Undefer.
6253 -- See 4jexcept.ads for an explanation.
6255 if VM_Target = No_VM then
6256 Target_Undefer := RE_Abort_Undefer;
6258 Target_Undefer := RE_Update_Exception;
6260 New_List (Make_Function_Call (Loc,
6261 Name => New_Occurrence_Of
6262 (RTE (RE_Current_Target_Exception), Loc)));
6266 Make_Block_Statement (Loc,
6267 Handled_Statement_Sequence =>
6268 Make_Handled_Sequence_Of_Statements (Loc,
6269 Statements => New_List (
6270 Make_Implicit_Label_Declaration (Loc,
6271 Defining_Identifier => Blk_Ent,
6272 Label_Construct => Abortable_Block),
6277 Exception_Handlers => New_List (
6278 Make_Implicit_Exception_Handler (Loc,
6280 -- when Abort_Signal =>
6281 -- Abort_Undefer.all;
6283 Exception_Choices =>
6284 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6285 Statements => New_List (
6286 Make_Procedure_Call_Statement (Loc,
6287 Name => New_Reference_To (
6288 RTE (Target_Undefer), Loc),
6289 Parameter_Associations => Undefer_Args)))))),
6291 -- if not Cancelled (Bnn) then
6292 -- triggered statements
6295 Make_Implicit_If_Statement (N,
6296 Condition => Make_Op_Not (Loc,
6298 Make_Function_Call (Loc,
6299 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6300 Parameter_Associations => New_List (
6301 New_Occurrence_Of (Cancel_Param, Loc)))),
6302 Then_Statements => Tstats));
6304 -- Asynchronous task entry call
6311 B := Make_Defining_Identifier (Loc, Name_uB);
6313 -- Insert declaration of B in declarations of existing block
6316 Make_Object_Declaration (Loc,
6317 Defining_Identifier => B,
6318 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6320 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6322 -- Insert declaration of C in declarations of existing block
6325 Make_Object_Declaration (Loc,
6326 Defining_Identifier => Cancel_Param,
6327 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6329 -- Remove and save the call to Call_Simple
6331 Stmt := First (Stmts);
6333 -- Skip assignments to temporaries created for in-out parameters.
6334 -- This makes unwarranted assumptions about the shape of the expanded
6335 -- tree for the call, and should be cleaned up ???
6337 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6343 -- Create the inner block to protect the abortable part
6346 Make_Implicit_Exception_Handler (Loc,
6347 Exception_Choices =>
6348 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6351 Make_Procedure_Call_Statement (Loc,
6352 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6355 Make_Procedure_Call_Statement (Loc,
6356 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6359 Make_Block_Statement (Loc,
6360 Identifier => New_Reference_To (Blk_Ent, Loc),
6361 Handled_Statement_Sequence =>
6362 Make_Handled_Sequence_Of_Statements (Loc,
6363 Statements => Astats),
6364 Has_Created_Identifier => True,
6365 Is_Asynchronous_Call_Block => True);
6368 Make_Block_Statement (Loc,
6369 Handled_Statement_Sequence =>
6370 Make_Handled_Sequence_Of_Statements (Loc,
6371 Statements => New_List (
6372 Make_Implicit_Label_Declaration (Loc,
6373 Defining_Identifier =>
6378 Exception_Handlers => Hdle)));
6380 -- Create new call statement
6382 Params := Parameter_Associations (Call);
6385 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6387 New_Reference_To (B, Loc));
6390 Make_Procedure_Call_Statement (Loc,
6392 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6393 Parameter_Associations => Params));
6395 -- Construct statement sequence for new block
6398 Make_Implicit_If_Statement (N,
6401 New_Reference_To (Cancel_Param, Loc)),
6402 Then_Statements => Tstats));
6404 -- Protected the call against abort
6407 Make_Procedure_Call_Statement (Loc,
6408 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6409 Parameter_Associations => Empty_List));
6412 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6414 -- The result is the new block
6417 Make_Block_Statement (Loc,
6418 Declarations => Decls,
6419 Handled_Statement_Sequence =>
6420 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6423 end Expand_N_Asynchronous_Select;
6425 -------------------------------------
6426 -- Expand_N_Conditional_Entry_Call --
6427 -------------------------------------
6429 -- The conditional task entry call is converted to a call to
6434 -- P : parms := (parm, parm, parm);
6438 -- (<acceptor-task>, -- Acceptor
6439 -- <entry-index>, -- E
6440 -- P'Address, -- Uninterpreted_Data
6441 -- Conditional_Call, -- Mode
6442 -- B); -- Rendezvous_Successful
6447 -- normal-statements
6453 -- For a description of the use of P and the assignments after the call,
6454 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6455 -- conditional entry call has already been expanded (by the Expand_N_Entry
6456 -- _Call_Statement procedure) as follows:
6459 -- P : parms := (parm, parm, parm);
6461 -- ... info for in-out parameters
6462 -- Call_Simple (acceptor-task, entry-index, P'Address);
6468 -- so the task at hand is to convert the latter expansion into the former
6470 -- The conditional protected entry call is converted to a call to
6471 -- Protected_Entry_Call:
6474 -- P : parms := (parm, parm, parm);
6475 -- Bnn : Communications_Block;
6478 -- Protected_Entry_Call
6479 -- (po._object'Access, -- Object
6480 -- <entry index>, -- E
6481 -- P'Address, -- Uninterpreted_Data
6482 -- Conditional_Call, -- Mode
6487 -- if Cancelled (Bnn) then
6490 -- normal-statements
6494 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6498 -- B : Boolean := False;
6499 -- C : Ada.Tags.Prim_Op_Kind;
6500 -- K : Ada.Tags.Tagged_Kind :=
6501 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6502 -- P : Parameters := (Param1 .. ParamN);
6506 -- if K = Ada.Tags.TK_Limited_Tagged then
6507 -- <dispatching-call>;
6508 -- <triggering-statements>
6512 -- Ada.Tags.Get_Offset_Index
6513 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6515 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6517 -- if C = POK_Protected_Entry
6518 -- or else C = POK_Task_Entry
6520 -- Param1 := P.Param1;
6522 -- ParamN := P.ParamN;
6526 -- if C = POK_Procedure
6527 -- or else C = POK_Protected_Procedure
6528 -- or else C = POK_Task_Procedure
6530 -- <dispatching-call>;
6533 -- <triggering-statements>
6535 -- <else-statements>
6540 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6541 Loc : constant Source_Ptr := Sloc (N);
6542 Alt : constant Node_Id := Entry_Call_Alternative (N);
6543 Blk : Node_Id := Entry_Call_Statement (Alt);
6546 Blk_Typ : Entity_Id;
6548 Call_Ent : Entity_Id;
6549 Conc_Typ_Stmts : List_Id;
6553 Lim_Typ_Stmts : List_Id;
6560 Transient_Blk : Node_Id;
6563 B : Entity_Id; -- Call status flag
6564 C : Entity_Id; -- Call kind
6565 K : Entity_Id; -- Tagged kind
6566 P : Entity_Id; -- Parameter block
6567 S : Entity_Id; -- Primitive operation slot
6570 if Ada_Version >= Ada_05
6571 and then Nkind (Blk) = N_Procedure_Call_Statement
6573 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6578 -- Call status flag processing, generate:
6579 -- B : Boolean := False;
6581 B := Build_B (Loc, Decls);
6583 -- Call kind processing, generate:
6584 -- C : Ada.Tags.Prim_Op_Kind;
6586 C := Build_C (Loc, Decls);
6588 -- Tagged kind processing, generate:
6589 -- K : Ada.Tags.Tagged_Kind :=
6590 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6592 K := Build_K (Loc, Decls, Obj);
6594 -- Parameter block processing
6596 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6597 P := Parameter_Block_Pack
6598 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6600 -- Dispatch table slot processing, generate:
6603 S := Build_S (Loc, Decls);
6606 -- S := Ada.Tags.Get_Offset_Index
6607 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6610 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6613 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6615 Append_To (Conc_Typ_Stmts,
6616 Make_Procedure_Call_Statement (Loc,
6619 Find_Prim_Op (Etype (Etype (Obj)),
6620 Name_uDisp_Conditional_Select),
6622 Parameter_Associations =>
6624 New_Copy_Tree (Obj), -- <object>
6625 New_Reference_To (S, Loc), -- S
6626 Make_Attribute_Reference (Loc, -- P'Address
6628 New_Reference_To (P, Loc),
6631 New_Reference_To (C, Loc), -- C
6632 New_Reference_To (B, Loc)))); -- B
6635 -- if C = POK_Protected_Entry
6636 -- or else C = POK_Task_Entry
6638 -- Param1 := P.Param1;
6640 -- ParamN := P.ParamN;
6643 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6645 -- Generate the if statement only when the packed parameters need
6646 -- explicit assignments to their corresponding actuals.
6648 if Present (Unpack) then
6649 Append_To (Conc_Typ_Stmts,
6650 Make_If_Statement (Loc,
6657 New_Reference_To (C, Loc),
6659 New_Reference_To (RTE (
6660 RE_POK_Protected_Entry), Loc)),
6664 New_Reference_To (C, Loc),
6666 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6674 -- if C = POK_Procedure
6675 -- or else C = POK_Protected_Procedure
6676 -- or else C = POK_Task_Procedure
6678 -- <dispatching-call>
6680 -- <normal-statements>
6682 -- <else-statements>
6685 N_Stats := New_Copy_List_Tree (Statements (Alt));
6687 Prepend_To (N_Stats,
6688 Make_If_Statement (Loc,
6694 New_Reference_To (C, Loc),
6696 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6703 New_Reference_To (C, Loc),
6705 New_Reference_To (RTE (
6706 RE_POK_Protected_Procedure), Loc)),
6711 New_Reference_To (C, Loc),
6713 New_Reference_To (RTE (
6714 RE_POK_Task_Procedure), Loc)))),
6719 Append_To (Conc_Typ_Stmts,
6720 Make_If_Statement (Loc,
6721 Condition => New_Reference_To (B, Loc),
6722 Then_Statements => N_Stats,
6723 Else_Statements => Else_Statements (N)));
6726 -- <dispatching-call>;
6727 -- <triggering-statements>
6729 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6730 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6733 -- if K = Ada.Tags.TK_Limited_Tagged then
6740 Make_If_Statement (Loc,
6744 New_Reference_To (K, Loc),
6746 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6755 Make_Block_Statement (Loc,
6758 Handled_Statement_Sequence =>
6759 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6761 -- As described above, The entry alternative is transformed into a
6762 -- block that contains the gnulli call, and possibly assignment
6763 -- statements for in-out parameters. The gnulli call may itself be
6764 -- rewritten into a transient block if some unconstrained parameters
6765 -- require it. We need to retrieve the call to complete its parameter
6770 First_Real_Statement (Handled_Statement_Sequence (Blk));
6772 if Present (Transient_Blk)
6773 and then Nkind (Transient_Blk) = N_Block_Statement
6775 Blk := Transient_Blk;
6778 Stmts := Statements (Handled_Statement_Sequence (Blk));
6779 Stmt := First (Stmts);
6780 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6785 Params := Parameter_Associations (Call);
6787 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6789 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6791 Param := First (Params);
6792 while Present (Param)
6793 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6798 pragma Assert (Present (Param));
6799 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6803 -- Find the Communication_Block parameter for the call to the
6804 -- Cancelled function.
6806 Decl := First (Declarations (Blk));
6807 while Present (Decl)
6808 and then not Is_RTE (Etype (Object_Definition (Decl)),
6809 RE_Communication_Block)
6814 -- Add an if statement to execute the else part if the call
6815 -- does not succeed (as indicated by the Cancelled predicate).
6818 Make_Implicit_If_Statement (N,
6819 Condition => Make_Function_Call (Loc,
6820 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6821 Parameter_Associations => New_List (
6822 New_Reference_To (Defining_Identifier (Decl), Loc))),
6823 Then_Statements => Else_Statements (N),
6824 Else_Statements => Statements (Alt)));
6827 B := Make_Defining_Identifier (Loc, Name_uB);
6829 -- Insert declaration of B in declarations of existing block
6831 if No (Declarations (Blk)) then
6832 Set_Declarations (Blk, New_List);
6835 Prepend_To (Declarations (Blk),
6836 Make_Object_Declaration (Loc,
6837 Defining_Identifier => B,
6838 Object_Definition =>
6839 New_Reference_To (Standard_Boolean, Loc)));
6841 -- Create new call statement
6844 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6845 Append_To (Params, New_Reference_To (B, Loc));
6848 Make_Procedure_Call_Statement (Loc,
6849 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6850 Parameter_Associations => Params));
6852 -- Construct statement sequence for new block
6855 Make_Implicit_If_Statement (N,
6856 Condition => New_Reference_To (B, Loc),
6857 Then_Statements => Statements (Alt),
6858 Else_Statements => Else_Statements (N)));
6861 -- The result is the new block
6864 Make_Block_Statement (Loc,
6865 Declarations => Declarations (Blk),
6866 Handled_Statement_Sequence =>
6867 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6871 end Expand_N_Conditional_Entry_Call;
6873 ---------------------------------------
6874 -- Expand_N_Delay_Relative_Statement --
6875 ---------------------------------------
6877 -- Delay statement is implemented as a procedure call to Delay_For
6878 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6879 -- simple delays imposed by the use of Protected Objects.
6881 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6882 Loc : constant Source_Ptr := Sloc (N);
6885 Make_Procedure_Call_Statement (Loc,
6886 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6887 Parameter_Associations => New_List (Expression (N))));
6889 end Expand_N_Delay_Relative_Statement;
6891 ------------------------------------
6892 -- Expand_N_Delay_Until_Statement --
6893 ------------------------------------
6895 -- Delay Until statement is implemented as a procedure call to
6896 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6898 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6899 Loc : constant Source_Ptr := Sloc (N);
6903 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6904 Typ := RTE (RO_CA_Delay_Until);
6906 Typ := RTE (RO_RT_Delay_Until);
6910 Make_Procedure_Call_Statement (Loc,
6911 Name => New_Reference_To (Typ, Loc),
6912 Parameter_Associations => New_List (Expression (N))));
6915 end Expand_N_Delay_Until_Statement;
6917 -------------------------
6918 -- Expand_N_Entry_Body --
6919 -------------------------
6921 procedure Expand_N_Entry_Body (N : Node_Id) is
6923 -- Associate discriminals with the next protected operation body to be
6926 if Present (Next_Protected_Operation (N)) then
6927 Set_Discriminals (Parent (Current_Scope));
6929 end Expand_N_Entry_Body;
6931 -----------------------------------
6932 -- Expand_N_Entry_Call_Statement --
6933 -----------------------------------
6935 -- An entry call is expanded into GNARLI calls to implement a simple entry
6936 -- call (see Build_Simple_Entry_Call).
6938 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
6944 if No_Run_Time_Mode then
6945 Error_Msg_CRT ("entry call", N);
6949 -- If this entry call is part of an asynchronous select, don't expand it
6950 -- here; it will be expanded with the select statement. Don't expand
6951 -- timed entry calls either, as they are translated into asynchronous
6954 -- ??? This whole approach is questionable; it may be better to go back
6955 -- to allowing the expansion to take place and then attempting to fix it
6956 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6957 -- whether the expanded call is on a task or protected entry.
6959 if (Nkind (Parent (N)) /= N_Triggering_Alternative
6960 or else N /= Triggering_Statement (Parent (N)))
6961 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
6962 or else N /= Entry_Call_Statement (Parent (N))
6963 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
6965 Extract_Entry (N, Concval, Ename, Index);
6966 Build_Simple_Entry_Call (N, Concval, Ename, Index);
6968 end Expand_N_Entry_Call_Statement;
6970 --------------------------------
6971 -- Expand_N_Entry_Declaration --
6972 --------------------------------
6974 -- If there are parameters, then first, each of the formals is marked by
6975 -- setting Is_Entry_Formal. Next a record type is built which is used to
6976 -- hold the parameter values. The name of this record type is entryP where
6977 -- entry is the name of the entry, with an additional corresponding access
6978 -- type called entryPA. The record type has matching components for each
6979 -- formal (the component names are the same as the formal names). For
6980 -- elementary types, the component type matches the formal type. For
6981 -- composite types, an access type is declared (with the name formalA)
6982 -- which designates the formal type, and the type of the component is this
6983 -- access type. Finally the Entry_Component of each formal is set to
6984 -- reference the corresponding record component.
6986 procedure Expand_N_Entry_Declaration (N : Node_Id) is
6987 Loc : constant Source_Ptr := Sloc (N);
6988 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
6989 Components : List_Id;
6992 Last_Decl : Node_Id;
6993 Component : Entity_Id;
6996 Rec_Ent : Entity_Id;
6997 Acc_Ent : Entity_Id;
7000 Formal := First_Formal (Entry_Ent);
7003 -- Most processing is done only if parameters are present
7005 if Present (Formal) then
7006 Components := New_List;
7008 -- Loop through formals
7010 while Present (Formal) loop
7011 Set_Is_Entry_Formal (Formal);
7013 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7014 Set_Entry_Component (Formal, Component);
7015 Set_Entry_Formal (Component, Formal);
7016 Ftype := Etype (Formal);
7018 -- Declare new access type and then append
7021 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7024 Make_Full_Type_Declaration (Loc,
7025 Defining_Identifier => Ctype,
7027 Make_Access_To_Object_Definition (Loc,
7028 All_Present => True,
7029 Constant_Present => Ekind (Formal) = E_In_Parameter,
7030 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7032 Insert_After (Last_Decl, Decl);
7035 Append_To (Components,
7036 Make_Component_Declaration (Loc,
7037 Defining_Identifier => Component,
7038 Component_Definition =>
7039 Make_Component_Definition (Loc,
7040 Aliased_Present => False,
7041 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7043 Next_Formal_With_Extras (Formal);
7046 -- Create the Entry_Parameter_Record declaration
7049 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
7052 Make_Full_Type_Declaration (Loc,
7053 Defining_Identifier => Rec_Ent,
7055 Make_Record_Definition (Loc,
7057 Make_Component_List (Loc,
7058 Component_Items => Components)));
7060 Insert_After (Last_Decl, Decl);
7063 -- Construct and link in the corresponding access type
7066 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7068 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7071 Make_Full_Type_Declaration (Loc,
7072 Defining_Identifier => Acc_Ent,
7074 Make_Access_To_Object_Definition (Loc,
7075 All_Present => True,
7076 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7078 Insert_After (Last_Decl, Decl);
7081 end Expand_N_Entry_Declaration;
7083 -----------------------------
7084 -- Expand_N_Protected_Body --
7085 -----------------------------
7087 -- Protected bodies are expanded to the completion of the subprograms
7088 -- created for the corresponding protected type. These are a protected and
7089 -- unprotected version of each protected subprogram in the object, a
7090 -- function to calculate each entry barrier, and a procedure to execute the
7091 -- sequence of statements of each protected entry body. For example, for
7092 -- protected type ptype:
7095 -- (O : System.Address;
7096 -- E : Protected_Entry_Index)
7099 -- <discriminant renamings>
7100 -- <private object renamings>
7102 -- return <barrier expression>;
7105 -- procedure pprocN (_object : in out poV;...) is
7106 -- <discriminant renamings>
7107 -- <private object renamings>
7109 -- <sequence of statements>
7112 -- procedure pprocP (_object : in out poV;...) is
7113 -- procedure _clean is
7116 -- ptypeS (_object, Pn);
7117 -- Unlock (_object._object'Access);
7118 -- Abort_Undefer.all;
7123 -- Lock (_object._object'Access);
7124 -- pprocN (_object;...);
7129 -- function pfuncN (_object : poV;...) return Return_Type is
7130 -- <discriminant renamings>
7131 -- <private object renamings>
7133 -- <sequence of statements>
7136 -- function pfuncP (_object : poV) return Return_Type is
7137 -- procedure _clean is
7139 -- Unlock (_object._object'Access);
7140 -- Abort_Undefer.all;
7145 -- Lock (_object._object'Access);
7146 -- return pfuncN (_object);
7153 -- (O : System.Address;
7154 -- P : System.Address;
7155 -- E : Protected_Entry_Index)
7157 -- <discriminant renamings>
7158 -- <private object renamings>
7159 -- type poVP is access poV;
7160 -- _Object : ptVP := ptVP!(O);
7164 -- <statement sequence>
7165 -- Complete_Entry_Body (_Object._Object);
7167 -- when all others =>
7168 -- Exceptional_Complete_Entry_Body (
7169 -- _Object._Object, Get_GNAT_Exception);
7173 -- The type poV is the record created for the protected type to hold
7174 -- the state of the protected object.
7176 procedure Expand_N_Protected_Body (N : Node_Id) is
7177 Loc : constant Source_Ptr := Sloc (N);
7178 Pid : constant Entity_Id := Corresponding_Spec (N);
7180 Current_Node : Node_Id;
7181 Disp_Op_Body : Node_Id;
7182 New_Op_Body : Node_Id;
7183 Num_Entries : Natural := 0;
7188 Chain : Entity_Id := Empty;
7189 -- Finalization chain that may be attached to new body
7191 function Build_Dispatching_Subprogram_Body
7194 Prot_Bod : Node_Id) return Node_Id;
7195 -- Build a dispatching version of the protected subprogram body. The
7196 -- newly generated subprogram contains a call to the original protected
7197 -- body. The following code is generated:
7199 -- function <protected-function-name> (Param1 .. ParamN) return
7202 -- return <protected-function-name>P (Param1 .. ParamN);
7203 -- end <protected-function-name>;
7207 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7209 -- <protected-procedure-name>P (Param1 .. ParamN);
7210 -- end <protected-procedure-name>
7212 ---------------------------------------
7213 -- Build_Dispatching_Subprogram_Body --
7214 ---------------------------------------
7216 function Build_Dispatching_Subprogram_Body
7219 Prot_Bod : Node_Id) return Node_Id
7221 Loc : constant Source_Ptr := Sloc (N);
7228 -- Generate a specification without a letter suffix in order to
7229 -- override an interface function or procedure.
7232 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7234 -- The formal parameters become the actuals of the protected
7235 -- function or procedure call.
7237 Actuals := New_List;
7238 Formal := First (Parameter_Specifications (Spec));
7239 while Present (Formal) loop
7241 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7246 if Nkind (Spec) = N_Procedure_Specification then
7249 Make_Procedure_Call_Statement (Loc,
7251 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7252 Parameter_Associations => Actuals));
7254 pragma Assert (Nkind (Spec) = N_Function_Specification);
7258 Make_Simple_Return_Statement (Loc,
7260 Make_Function_Call (Loc,
7262 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7263 Parameter_Associations => Actuals)));
7267 Make_Subprogram_Body (Loc,
7268 Declarations => Empty_List,
7269 Specification => Spec,
7270 Handled_Statement_Sequence =>
7271 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7272 end Build_Dispatching_Subprogram_Body;
7274 -- Start of processing for Expand_N_Protected_Body
7277 if No_Run_Time_Mode then
7278 Error_Msg_CRT ("protected body", N);
7282 -- This is the proper body corresponding to a stub. The declarations
7283 -- must be inserted at the point of the stub, which in turn is in the
7284 -- declarative part of the parent unit.
7286 if Nkind (Parent (N)) = N_Subunit then
7287 Current_Node := Corresponding_Stub (Parent (N));
7292 Op_Body := First (Declarations (N));
7294 -- The protected body is replaced with the bodies of its
7295 -- protected operations, and the declarations for internal objects
7296 -- that may have been created for entry family bounds.
7298 Rewrite (N, Make_Null_Statement (Sloc (N)));
7301 while Present (Op_Body) loop
7302 case Nkind (Op_Body) is
7303 when N_Subprogram_Declaration =>
7306 when N_Subprogram_Body =>
7308 -- Do not create bodies for eliminated operations
7310 if not Is_Eliminated (Defining_Entity (Op_Body))
7311 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7314 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7316 -- Propagate the finalization chain to the new body. In the
7317 -- unlikely event that the subprogram contains a declaration
7318 -- or allocator for an object that requires finalization,
7319 -- the corresponding chain is created when analyzing the
7320 -- body, and attached to its entity. This entity is not
7321 -- further elaborated, and so the chain properly belongs to
7322 -- the newly created subprogram body.
7325 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7327 if Present (Chain) then
7328 Set_Finalization_Chain_Entity
7329 (Protected_Body_Subprogram
7330 (Corresponding_Spec (Op_Body)), Chain);
7332 (Handled_Statement_Sequence (New_Op_Body), False);
7335 Insert_After (Current_Node, New_Op_Body);
7336 Current_Node := New_Op_Body;
7337 Analyze (New_Op_Body);
7339 -- Build the corresponding protected operation. It may
7340 -- appear that this is needed only if this is a visible
7341 -- operation of the type, or if it is an interrupt handler,
7342 -- and this was the strategy used previously in GNAT.
7343 -- However, the operation may be exported through a 'Access
7344 -- to an external caller. This is the common idiom in code
7345 -- that uses the Ada 2005 Timing_Events package. As a result
7346 -- we need to produce the protected body for both visible
7347 -- and private operations.
7349 if Present (Corresponding_Spec (Op_Body)) then
7351 Unit_Declaration_Node (Corresponding_Spec (Op_Body));
7353 if Nkind (Parent (Op_Decl)) =
7354 N_Protected_Definition
7357 Build_Protected_Subprogram_Body (
7358 Op_Body, Pid, Specification (New_Op_Body));
7360 Insert_After (Current_Node, New_Op_Body);
7361 Analyze (New_Op_Body);
7363 Current_Node := New_Op_Body;
7365 -- Generate an overriding primitive operation body for
7366 -- this subprogram if the protected type implements
7369 if Ada_Version >= Ada_05
7370 and then Present (Interfaces (
7371 Corresponding_Record_Type (Pid)))
7374 Build_Dispatching_Subprogram_Body (
7375 Op_Body, Pid, New_Op_Body);
7377 Insert_After (Current_Node, Disp_Op_Body);
7378 Analyze (Disp_Op_Body);
7380 Current_Node := Disp_Op_Body;
7386 when N_Entry_Body =>
7387 Op_Id := Defining_Identifier (Op_Body);
7388 Num_Entries := Num_Entries + 1;
7390 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7392 Insert_After (Current_Node, New_Op_Body);
7393 Current_Node := New_Op_Body;
7394 Analyze (New_Op_Body);
7396 when N_Implicit_Label_Declaration =>
7399 when N_Itype_Reference =>
7400 Insert_After (Current_Node, New_Copy (Op_Body));
7402 when N_Freeze_Entity =>
7403 New_Op_Body := New_Copy (Op_Body);
7405 if Present (Entity (Op_Body))
7406 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7408 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7411 Insert_After (Current_Node, New_Op_Body);
7412 Current_Node := New_Op_Body;
7413 Analyze (New_Op_Body);
7416 New_Op_Body := New_Copy (Op_Body);
7417 Insert_After (Current_Node, New_Op_Body);
7418 Current_Node := New_Op_Body;
7419 Analyze (New_Op_Body);
7421 when N_Object_Declaration =>
7422 pragma Assert (not Comes_From_Source (Op_Body));
7423 New_Op_Body := New_Copy (Op_Body);
7424 Insert_After (Current_Node, New_Op_Body);
7425 Current_Node := New_Op_Body;
7426 Analyze (New_Op_Body);
7429 raise Program_Error;
7436 -- Finally, create the body of the function that maps an entry index
7437 -- into the corresponding body index, except when there is no entry,
7438 -- or in a ravenscar-like profile.
7440 if Corresponding_Runtime_Package (Pid) =
7441 System_Tasking_Protected_Objects_Entries
7443 New_Op_Body := Build_Find_Body_Index (Pid);
7444 Insert_After (Current_Node, New_Op_Body);
7445 Current_Node := New_Op_Body;
7446 Analyze (New_Op_Body);
7449 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7450 -- protected body. At this point all wrapper specs have been created,
7451 -- frozen and included in the dispatch table for the protected type.
7453 if Ada_Version >= Ada_05 then
7454 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7456 end Expand_N_Protected_Body;
7458 -----------------------------------------
7459 -- Expand_N_Protected_Type_Declaration --
7460 -----------------------------------------
7462 -- First we create a corresponding record type declaration used to
7463 -- represent values of this protected type.
7464 -- The general form of this type declaration is
7466 -- type poV (discriminants) is record
7467 -- _Object : aliased <kind>Protection
7468 -- [(<entry count> [, <handler count>])];
7469 -- [entry_family : array (bounds) of Void;]
7470 -- <private data fields>
7473 -- The discriminants are present only if the corresponding protected type
7474 -- has discriminants, and they exactly mirror the protected type
7475 -- discriminants. The private data fields similarly mirror the private
7476 -- declarations of the protected type.
7478 -- The Object field is always present. It contains RTS specific data used
7479 -- to control the protected object. It is declared as Aliased so that it
7480 -- can be passed as a pointer to the RTS. This allows the protected record
7481 -- to be referenced within RTS data structures. An appropriate Protection
7482 -- type and discriminant are generated.
7484 -- The Service field is present for protected objects with entries. It
7485 -- contains sufficient information to allow the entry service procedure for
7486 -- this object to be called when the object is not known till runtime.
7488 -- One entry_family component is present for each entry family in the
7489 -- task definition (see Expand_N_Task_Type_Declaration).
7491 -- When a protected object is declared, an instance of the protected type
7492 -- value record is created. The elaboration of this declaration creates the
7493 -- correct bounds for the entry families, and also evaluates the priority
7494 -- expression if needed. The initialization routine for the protected type
7495 -- itself then calls Initialize_Protection with appropriate parameters to
7496 -- initialize the value of the Task_Id field. Install_Handlers may be also
7497 -- called if a pragma Attach_Handler applies.
7499 -- Note: this record is passed to the subprograms created by the expansion
7500 -- of protected subprograms and entries. It is an in parameter to protected
7501 -- functions and an in out parameter to procedures and entry bodies. The
7502 -- Entity_Id for this created record type is placed in the
7503 -- Corresponding_Record_Type field of the associated protected type entity.
7505 -- Next we create a procedure specifications for protected subprograms and
7506 -- entry bodies. For each protected subprograms two subprograms are
7507 -- created, an unprotected and a protected version. The unprotected version
7508 -- is called from within other operations of the same protected object.
7510 -- We also build the call to register the procedure if a pragma
7511 -- Interrupt_Handler applies.
7513 -- A single subprogram is created to service all entry bodies; it has an
7514 -- additional boolean out parameter indicating that the previous entry call
7515 -- made by the current task was serviced immediately, i.e. not by proxy.
7516 -- The O parameter contains a pointer to a record object of the type
7517 -- described above. An untyped interface is used here to allow this
7518 -- procedure to be called in places where the type of the object to be
7519 -- serviced is not known. This must be done, for example, when a call that
7520 -- may have been requeued is cancelled; the corresponding object must be
7521 -- serviced, but which object that is not known till runtime.
7524 -- (O : System.Address; P : out Boolean);
7525 -- procedure pprocN (_object : in out poV);
7526 -- procedure pproc (_object : in out poV);
7527 -- function pfuncN (_object : poV);
7528 -- function pfunc (_object : poV);
7531 -- Note that this must come after the record type declaration, since
7532 -- the specs refer to this type.
7534 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7535 Loc : constant Source_Ptr := Sloc (N);
7536 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7538 Pdef : constant Node_Id := Protected_Definition (N);
7539 -- This contains two lists; one for visible and one for private decls
7543 Discr_Map : constant Elist_Id := New_Elmt_List;
7547 Comp_Id : Entity_Id;
7549 Current_Node : Node_Id := N;
7550 Bdef : Entity_Id := Empty; -- avoid uninit warning
7551 Edef : Entity_Id := Empty; -- avoid uninit warning
7552 Entries_Aggr : Node_Id;
7553 Body_Id : Entity_Id;
7556 Object_Comp : Node_Id;
7558 procedure Check_Inlining (Subp : Entity_Id);
7559 -- If the original operation has a pragma Inline, propagate the flag
7560 -- to the internal body, for possible inlining later on. The source
7561 -- operation is invisible to the back-end and is never actually called.
7563 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7564 -- When compiling under the Ravenscar profile, private components must
7565 -- have a static size, or else a protected object will require heap
7566 -- allocation, violating the corresponding restriction. It is preferable
7567 -- to make this check here, because it provides a better error message
7568 -- than the back-end, which refers to the object as a whole.
7570 procedure Register_Handler;
7571 -- For a protected operation that is an interrupt handler, add the
7572 -- freeze action that will register it as such.
7574 --------------------
7575 -- Check_Inlining --
7576 --------------------
7578 procedure Check_Inlining (Subp : Entity_Id) is
7580 if Is_Inlined (Subp) then
7581 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7582 Set_Is_Inlined (Subp, False);
7586 ---------------------------------
7587 -- Check_Static_Component_Size --
7588 ---------------------------------
7590 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7591 Typ : constant Entity_Id := Etype (Comp);
7595 if Is_Scalar_Type (Typ) then
7598 elsif Is_Array_Type (Typ) then
7599 return Compile_Time_Known_Bounds (Typ);
7601 elsif Is_Record_Type (Typ) then
7602 C := First_Component (Typ);
7603 while Present (C) loop
7604 if not Static_Component_Size (C) then
7613 -- Any other types will be checked by the back-end
7618 end Static_Component_Size;
7620 ----------------------
7621 -- Register_Handler --
7622 ----------------------
7624 procedure Register_Handler is
7626 -- All semantic checks already done in Sem_Prag
7628 Prot_Proc : constant Entity_Id :=
7630 (Specification (Current_Node));
7632 Proc_Address : constant Node_Id :=
7633 Make_Attribute_Reference (Loc,
7634 Prefix => New_Reference_To (Prot_Proc, Loc),
7635 Attribute_Name => Name_Address);
7637 RTS_Call : constant Entity_Id :=
7638 Make_Procedure_Call_Statement (Loc,
7641 RTE (RE_Register_Interrupt_Handler), Loc),
7642 Parameter_Associations =>
7643 New_List (Proc_Address));
7645 Append_Freeze_Action (Prot_Proc, RTS_Call);
7646 end Register_Handler;
7648 -- Start of processing for Expand_N_Protected_Type_Declaration
7651 if Present (Corresponding_Record_Type (Prot_Typ)) then
7654 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7657 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7659 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7660 -- of implemented interfaces.
7662 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
7664 Qualify_Entity_Names (N);
7666 -- If the type has discriminants, their occurrences in the declaration
7667 -- have been replaced by the corresponding discriminals. For components
7668 -- that are constrained by discriminants, their homologues in the
7669 -- corresponding record type must refer to the discriminants of that
7670 -- record, so we must apply a new renaming to subtypes_indications:
7672 -- protected discriminant => discriminal => record discriminant
7674 -- This replacement is not applied to default expressions, for which
7675 -- the discriminal is correct.
7677 if Has_Discriminants (Prot_Typ) then
7683 Disc := First_Discriminant (Prot_Typ);
7684 Decl := First (Discriminant_Specifications (Rec_Decl));
7685 while Present (Disc) loop
7686 Append_Elmt (Discriminal (Disc), Discr_Map);
7687 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7688 Next_Discriminant (Disc);
7694 -- Fill in the component declarations
7696 -- Add components for entry families. For each entry family, create an
7697 -- anonymous type declaration with the same size, and analyze the type.
7699 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7701 -- Prepend the _Object field with the right type to the component list.
7702 -- We need to compute the number of entries, and in some cases the
7703 -- number of Attach_Handler pragmas.
7707 Num_Attach_Handler : Int := 0;
7708 Protection_Subtype : Node_Id;
7709 Entry_Count_Expr : constant Node_Id :=
7710 Build_Entry_Count_Expression
7711 (Prot_Typ, Cdecls, Loc);
7714 -- Could this be simplified using Corresponding_Runtime_Package???
7716 if Has_Attach_Handler (Prot_Typ) then
7717 Ritem := First_Rep_Item (Prot_Typ);
7718 while Present (Ritem) loop
7719 if Nkind (Ritem) = N_Pragma
7720 and then Pragma_Name (Ritem) = Name_Attach_Handler
7722 Num_Attach_Handler := Num_Attach_Handler + 1;
7725 Next_Rep_Item (Ritem);
7728 if Restricted_Profile then
7729 if Has_Entries (Prot_Typ) then
7730 Protection_Subtype :=
7731 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7733 Protection_Subtype :=
7734 New_Reference_To (RTE (RE_Protection), Loc);
7737 Protection_Subtype :=
7738 Make_Subtype_Indication
7742 (RTE (RE_Static_Interrupt_Protection), Loc),
7744 Make_Index_Or_Discriminant_Constraint (
7746 Constraints => New_List (
7748 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7751 elsif Has_Interrupt_Handler (Prot_Typ) then
7752 Protection_Subtype :=
7753 Make_Subtype_Indication (
7755 Subtype_Mark => New_Reference_To
7756 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7758 Make_Index_Or_Discriminant_Constraint (
7760 Constraints => New_List (Entry_Count_Expr)));
7762 -- Type has explicit entries or generated primitive entry wrappers
7764 elsif Has_Entries (Prot_Typ)
7765 or else (Ada_Version >= Ada_05
7766 and then Present (Interface_List (N)))
7768 case Corresponding_Runtime_Package (Prot_Typ) is
7769 when System_Tasking_Protected_Objects_Entries =>
7770 Protection_Subtype :=
7771 Make_Subtype_Indication (Loc,
7773 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7775 Make_Index_Or_Discriminant_Constraint (
7777 Constraints => New_List (Entry_Count_Expr)));
7779 when System_Tasking_Protected_Objects_Single_Entry =>
7780 Protection_Subtype :=
7781 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7784 raise Program_Error;
7788 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7792 Make_Component_Declaration (Loc,
7793 Defining_Identifier =>
7794 Make_Defining_Identifier (Loc, Name_uObject),
7795 Component_Definition =>
7796 Make_Component_Definition (Loc,
7797 Aliased_Present => True,
7798 Subtype_Indication => Protection_Subtype));
7801 pragma Assert (Present (Pdef));
7803 -- Add private field components
7805 if Present (Private_Declarations (Pdef)) then
7806 Priv := First (Private_Declarations (Pdef));
7808 while Present (Priv) loop
7810 if Nkind (Priv) = N_Component_Declaration then
7811 if not Static_Component_Size (Defining_Identifier (Priv)) then
7813 -- When compiling for a restricted profile, the private
7814 -- components must have a static size. If not, this is an
7815 -- error for a single protected declaration, and rates a
7816 -- warning on a protected type declaration.
7818 if not Comes_From_Source (Prot_Typ) then
7819 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
7821 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
7822 Error_Msg_N ("component has non-static size?", Priv);
7824 ("\creation of protected object of type& will violate"
7825 & " restriction No_Implicit_Heap_Allocations?",
7830 -- The component definition consists of a subtype indication,
7831 -- or (in Ada 2005) an access definition. Make a copy of the
7832 -- proper definition.
7835 Old_Comp : constant Node_Id := Component_Definition (Priv);
7836 Oent : constant Entity_Id := Defining_Identifier (Priv);
7838 Nent : constant Entity_Id :=
7839 Make_Defining_Identifier (Sloc (Oent),
7840 Chars => Chars (Oent));
7843 if Present (Subtype_Indication (Old_Comp)) then
7845 Make_Component_Definition (Sloc (Oent),
7846 Aliased_Present => False,
7847 Subtype_Indication =>
7848 New_Copy_Tree (Subtype_Indication (Old_Comp),
7852 Make_Component_Definition (Sloc (Oent),
7853 Aliased_Present => False,
7854 Access_Definition =>
7855 New_Copy_Tree (Access_Definition (Old_Comp),
7860 Make_Component_Declaration (Loc,
7861 Defining_Identifier => Nent,
7862 Component_Definition => New_Comp,
7863 Expression => Expression (Priv));
7865 Set_Has_Per_Object_Constraint (Nent,
7866 Has_Per_Object_Constraint (Oent));
7868 Append_To (Cdecls, New_Priv);
7871 elsif Nkind (Priv) = N_Subprogram_Declaration then
7873 -- Make the unprotected version of the subprogram available
7874 -- for expansion of intra object calls. There is need for
7875 -- a protected version only if the subprogram is an interrupt
7876 -- handler, otherwise this operation can only be called from
7880 Make_Subprogram_Declaration (Loc,
7882 Build_Protected_Sub_Specification
7883 (Priv, Prot_Typ, Unprotected_Mode));
7885 Insert_After (Current_Node, Sub);
7888 Set_Protected_Body_Subprogram
7889 (Defining_Unit_Name (Specification (Priv)),
7890 Defining_Unit_Name (Specification (Sub)));
7891 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
7892 Current_Node := Sub;
7895 Make_Subprogram_Declaration (Loc,
7897 Build_Protected_Sub_Specification
7898 (Priv, Prot_Typ, Protected_Mode));
7900 Insert_After (Current_Node, Sub);
7902 Current_Node := Sub;
7904 if Is_Interrupt_Handler
7905 (Defining_Unit_Name (Specification (Priv)))
7907 if not Restricted_Profile then
7917 -- Put the _Object component after the private component so that it
7918 -- be finalized early as required by 9.4 (20)
7920 Append_To (Cdecls, Object_Comp);
7922 Insert_After (Current_Node, Rec_Decl);
7923 Current_Node := Rec_Decl;
7925 -- Analyze the record declaration immediately after construction,
7926 -- because the initialization procedure is needed for single object
7927 -- declarations before the next entity is analyzed (the freeze call
7928 -- that generates this initialization procedure is found below).
7930 Analyze (Rec_Decl, Suppress => All_Checks);
7932 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7933 -- the corresponding record is frozen. If any wrappers are generated,
7934 -- Current_Node is updated accordingly.
7936 if Ada_Version >= Ada_05 then
7937 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
7940 -- Collect pointers to entry bodies and their barriers, to be placed
7941 -- in the Entry_Bodies_Array for the type. For each entry/family we
7942 -- add an expression to the aggregate which is the initial value of
7943 -- this array. The array is declared after all protected subprograms.
7945 if Has_Entries (Prot_Typ) then
7946 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
7948 Entries_Aggr := Empty;
7951 -- Build two new procedure specifications for each protected subprogram;
7952 -- one to call from outside the object and one to call from inside.
7953 -- Build a barrier function and an entry body action procedure
7954 -- specification for each protected entry. Initialize the entry body
7955 -- array. If subprogram is flagged as eliminated, do not generate any
7956 -- internal operations.
7960 Comp := First (Visible_Declarations (Pdef));
7962 while Present (Comp) loop
7963 if Nkind (Comp) = N_Subprogram_Declaration then
7965 Make_Subprogram_Declaration (Loc,
7967 Build_Protected_Sub_Specification
7968 (Comp, Prot_Typ, Unprotected_Mode));
7970 Insert_After (Current_Node, Sub);
7973 Set_Protected_Body_Subprogram
7974 (Defining_Unit_Name (Specification (Comp)),
7975 Defining_Unit_Name (Specification (Sub)));
7976 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
7978 -- Make the protected version of the subprogram available for
7979 -- expansion of external calls.
7981 Current_Node := Sub;
7984 Make_Subprogram_Declaration (Loc,
7986 Build_Protected_Sub_Specification
7987 (Comp, Prot_Typ, Protected_Mode));
7989 Insert_After (Current_Node, Sub);
7992 Current_Node := Sub;
7994 -- Generate an overriding primitive operation specification for
7995 -- this subprogram if the protected type implements an interface.
7997 if Ada_Version >= Ada_05
7999 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8002 Make_Subprogram_Declaration (Loc,
8004 Build_Protected_Sub_Specification
8005 (Comp, Prot_Typ, Dispatching_Mode));
8007 Insert_After (Current_Node, Sub);
8010 Current_Node := Sub;
8013 -- If a pragma Interrupt_Handler applies, build and add a call to
8014 -- Register_Interrupt_Handler to the freezing actions of the
8015 -- protected version (Current_Node) of the subprogram:
8017 -- system.interrupts.register_interrupt_handler
8018 -- (prot_procP'address);
8020 if not Restricted_Profile
8021 and then Is_Interrupt_Handler
8022 (Defining_Unit_Name (Specification (Comp)))
8027 elsif Nkind (Comp) = N_Entry_Declaration then
8028 E_Count := E_Count + 1;
8029 Comp_Id := Defining_Identifier (Comp);
8032 Make_Defining_Identifier (Loc,
8033 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8035 Make_Subprogram_Declaration (Loc,
8037 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8039 Insert_After (Current_Node, Sub);
8042 Set_Protected_Body_Subprogram
8043 (Defining_Identifier (Comp),
8044 Defining_Unit_Name (Specification (Sub)));
8046 Current_Node := Sub;
8049 Make_Defining_Identifier (Loc,
8050 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8052 Make_Subprogram_Declaration (Loc,
8054 Build_Barrier_Function_Specification (Loc, Bdef));
8056 Insert_After (Current_Node, Sub);
8058 Set_Protected_Body_Subprogram (Bdef, Bdef);
8059 Set_Barrier_Function (Comp_Id, Bdef);
8060 Set_Scope (Bdef, Scope (Comp_Id));
8061 Current_Node := Sub;
8063 -- Collect pointers to the protected subprogram and the barrier
8064 -- of the current entry, for insertion into Entry_Bodies_Array.
8067 Make_Aggregate (Loc,
8068 Expressions => New_List (
8069 Make_Attribute_Reference (Loc,
8070 Prefix => New_Reference_To (Bdef, Loc),
8071 Attribute_Name => Name_Unrestricted_Access),
8072 Make_Attribute_Reference (Loc,
8073 Prefix => New_Reference_To (Edef, Loc),
8074 Attribute_Name => Name_Unrestricted_Access))),
8075 Expressions (Entries_Aggr));
8082 -- If there are some private entry declarations, expand it as if they
8083 -- were visible entries.
8085 if Present (Private_Declarations (Pdef)) then
8086 Comp := First (Private_Declarations (Pdef));
8087 while Present (Comp) loop
8088 if Nkind (Comp) = N_Entry_Declaration then
8089 E_Count := E_Count + 1;
8090 Comp_Id := Defining_Identifier (Comp);
8093 Make_Defining_Identifier (Loc,
8094 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8096 Make_Subprogram_Declaration (Loc,
8098 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8100 Insert_After (Current_Node, Sub);
8103 Set_Protected_Body_Subprogram
8104 (Defining_Identifier (Comp),
8105 Defining_Unit_Name (Specification (Sub)));
8107 Current_Node := Sub;
8110 Make_Defining_Identifier (Loc,
8111 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8114 Make_Subprogram_Declaration (Loc,
8116 Build_Barrier_Function_Specification (Loc, Bdef));
8118 Insert_After (Current_Node, Sub);
8120 Set_Protected_Body_Subprogram (Bdef, Bdef);
8121 Set_Barrier_Function (Comp_Id, Bdef);
8122 Set_Scope (Bdef, Scope (Comp_Id));
8123 Current_Node := Sub;
8125 -- Collect pointers to the protected subprogram and the barrier
8126 -- of the current entry, for insertion into Entry_Bodies_Array.
8128 Append_To (Expressions (Entries_Aggr),
8129 Make_Aggregate (Loc,
8130 Expressions => New_List (
8131 Make_Attribute_Reference (Loc,
8132 Prefix => New_Reference_To (Bdef, Loc),
8133 Attribute_Name => Name_Unrestricted_Access),
8134 Make_Attribute_Reference (Loc,
8135 Prefix => New_Reference_To (Edef, Loc),
8136 Attribute_Name => Name_Unrestricted_Access))));
8143 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8144 -- all protected subprograms have been collected.
8146 if Has_Entries (Prot_Typ) then
8148 Make_Defining_Identifier (Sloc (Prot_Typ),
8149 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8151 case Corresponding_Runtime_Package (Prot_Typ) is
8152 when System_Tasking_Protected_Objects_Entries =>
8153 Body_Arr := Make_Object_Declaration (Loc,
8154 Defining_Identifier => Body_Id,
8155 Aliased_Present => True,
8156 Object_Definition =>
8157 Make_Subtype_Indication (Loc,
8158 Subtype_Mark => New_Reference_To (
8159 RTE (RE_Protected_Entry_Body_Array), Loc),
8161 Make_Index_Or_Discriminant_Constraint (Loc,
8162 Constraints => New_List (
8164 Make_Integer_Literal (Loc, 1),
8165 Make_Integer_Literal (Loc, E_Count))))),
8166 Expression => Entries_Aggr);
8168 when System_Tasking_Protected_Objects_Single_Entry =>
8169 Body_Arr := Make_Object_Declaration (Loc,
8170 Defining_Identifier => Body_Id,
8171 Aliased_Present => True,
8172 Object_Definition => New_Reference_To
8173 (RTE (RE_Entry_Body), Loc),
8175 Make_Aggregate (Loc,
8176 Expressions => New_List (
8177 Make_Attribute_Reference (Loc,
8178 Prefix => New_Reference_To (Bdef, Loc),
8179 Attribute_Name => Name_Unrestricted_Access),
8180 Make_Attribute_Reference (Loc,
8181 Prefix => New_Reference_To (Edef, Loc),
8182 Attribute_Name => Name_Unrestricted_Access))));
8185 raise Program_Error;
8188 -- A pointer to this array will be placed in the corresponding record
8189 -- by its initialization procedure so this needs to be analyzed here.
8191 Insert_After (Current_Node, Body_Arr);
8192 Current_Node := Body_Arr;
8195 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8197 -- Finally, build the function that maps an entry index into the
8198 -- corresponding body. A pointer to this function is placed in each
8199 -- object of the type. Except for a ravenscar-like profile (no abort,
8200 -- no entry queue, 1 entry)
8202 if Corresponding_Runtime_Package (Prot_Typ) =
8203 System_Tasking_Protected_Objects_Entries
8206 Make_Subprogram_Declaration (Loc,
8207 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8208 Insert_After (Current_Node, Sub);
8212 end Expand_N_Protected_Type_Declaration;
8214 --------------------------------
8215 -- Expand_N_Requeue_Statement --
8216 --------------------------------
8218 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8219 -- operations, depending on the source and destination (task or protected
8220 -- object). A dispatching requeue statement is expanded into a call to the
8221 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8222 -- jump around the remainder of processing for the original entry and, if
8223 -- the destination is (different) protected object, to attempt to service
8224 -- it. The following illustrates the various cases:
8227 -- (O : System.Address;
8228 -- P : System.Address;
8229 -- E : Protected_Entry_Index)
8231 -- <discriminant renamings>
8232 -- <private object renamings>
8233 -- type poVP is access poV;
8234 -- _object : ptVP := ptVP!(O);
8238 -- <start of statement sequence for entry>
8240 -- -- Requeue from one protected entry body to another protected
8243 -- Requeue_Protected_Entry (
8244 -- _object._object'Access,
8245 -- new._object'Access,
8250 -- <some more of the statement sequence for entry>
8252 -- -- Requeue from an entry body to a task entry
8254 -- Requeue_Protected_To_Task_Entry (
8260 -- <rest of statement sequence for entry>
8261 -- Complete_Entry_Body (_object._object);
8264 -- when all others =>
8265 -- Exceptional_Complete_Entry_Body (
8266 -- _object._object, Get_GNAT_Exception);
8270 -- Requeue of a task entry call to a task entry
8272 -- Accept_Call (E, Ann);
8273 -- <start of statement sequence for accept statement>
8274 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8276 -- <rest of statement sequence for accept statement>
8278 -- Complete_Rendezvous;
8281 -- when all others =>
8282 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8284 -- Requeue of a task entry call to a protected entry
8286 -- Accept_Call (E, Ann);
8287 -- <start of statement sequence for accept statement>
8288 -- Requeue_Task_To_Protected_Entry (
8289 -- new._object'Access,
8294 -- <rest of statement sequence for accept statement>
8296 -- Complete_Rendezvous;
8299 -- when all others =>
8300 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8302 -- Ada 2005 (AI05-0030): Dispatching requeue from protected to interface
8306 -- (O : System.Address;
8307 -- P : System.Address;
8308 -- E : Protected_Entry_Index)
8310 -- <discriminant renamings>
8311 -- <private object renamings>
8312 -- type poVP is access poV;
8313 -- _object : ptVP := ptVP!(O);
8317 -- <start of statement sequence for entry>
8320 -- (<interface class-wide object>,
8323 -- Ada.Tags.Get_Offset_Index
8325 -- <interface dispatch table index of target entry>),
8329 -- <rest of statement sequence for entry>
8330 -- Complete_Entry_Body (_object._object);
8333 -- when all others =>
8334 -- Exceptional_Complete_Entry_Body (
8335 -- _object._object, Get_GNAT_Exception);
8339 -- Ada 2005 (AI05-0030): Dispatching requeue from task to interface
8342 -- Accept_Call (E, Ann);
8343 -- <start of statement sequence for accept statement>
8345 -- (<interface class-wide object>,
8348 -- Ada.Tags.Get_Offset_Index
8350 -- <interface dispatch table index of target entrt>),
8354 -- <rest of statement sequence for accept statement>
8356 -- Complete_Rendezvous;
8359 -- when all others =>
8360 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8362 -- Further details on these expansions can be found in Expand_N_Protected_
8363 -- Body and Expand_N_Accept_Statement.
8365 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8366 Loc : constant Source_Ptr := Sloc (N);
8367 Abortable : Node_Id;
8369 Conc_Typ : Entity_Id;
8374 New_Param : Node_Id;
8375 Old_Typ : Entity_Id;
8378 RTS_Call : Entity_Id;
8379 Self_Param : Node_Id;
8380 Skip_Stat : Node_Id;
8384 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
8386 -- Extract the components of the entry call
8388 Extract_Entry (N, Concval, Ename, Index);
8389 Conc_Typ := Etype (Concval);
8391 -- Examine the scope stack in order to find nearest enclosing protected
8392 -- or task type. This will constitute our invocation source.
8394 Old_Typ := Current_Scope;
8395 while Present (Old_Typ)
8396 and then not Is_Protected_Type (Old_Typ)
8397 and then not Is_Task_Type (Old_Typ)
8399 Old_Typ := Scope (Old_Typ);
8402 -- Generate the parameter list for all cases. The abortable flag is
8403 -- common among dispatching and regular requeue.
8405 Params := New_List (Abortable);
8407 -- Ada 2005 (AI05-0030): We have a dispatching requeue of the form
8408 -- Concval.Ename where the type of Concval is class-wide concurrent
8411 if Ada_Version >= Ada_05
8412 and then Present (Concval)
8413 and then Is_Class_Wide_Type (Conc_Typ)
8414 and then Is_Concurrent_Interface (Conc_Typ)
8416 RTS_Call := Make_Identifier (Loc, Name_uDisp_Requeue);
8419 -- Ada.Tags.Get_Offset_Index
8420 -- (Ada.Tags.Tag (Concval),
8421 -- <interface dispatch table position of Ename>)
8424 Make_Function_Call (Loc,
8426 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8427 Parameter_Associations =>
8429 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8430 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8432 -- Specific actuals for protected to interface class-wide type
8435 if Is_Protected_Type (Old_Typ) then
8437 Make_Attribute_Reference (Loc, -- _object'Address
8439 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8442 Prepend_To (Params, -- True
8443 New_Reference_To (Standard_True, Loc));
8445 -- Specific actuals for task to interface class-wide type requeue
8448 pragma Assert (Is_Task_Type (Old_Typ));
8450 Prepend_To (Params, -- null
8451 New_Reference_To (RTE (RE_Null_Address), Loc));
8452 Prepend_To (Params, -- False
8453 New_Reference_To (Standard_False, Loc));
8456 -- Finally, add the common object parameter
8458 Prepend_To (Params, New_Copy_Tree (Concval));
8460 -- Regular requeue processing
8463 New_Param := Concurrent_Ref (Concval);
8465 -- The index expression is common among all four cases
8468 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8470 if Is_Protected_Type (Old_Typ) then
8472 Make_Attribute_Reference (Loc,
8474 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8476 Name_Unchecked_Access);
8478 -- Protected to protected requeue
8480 if Is_Protected_Type (Conc_Typ) then
8482 New_Reference_To (RTE (RE_Requeue_Protected_Entry), Loc);
8485 Make_Attribute_Reference (Loc,
8489 Name_Unchecked_Access);
8491 -- Protected to task requeue
8494 pragma Assert (Is_Task_Type (Conc_Typ));
8497 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8500 Prepend (New_Param, Params);
8501 Prepend (Self_Param, Params);
8504 pragma Assert (Is_Task_Type (Old_Typ));
8506 -- Task to protected requeue
8508 if Is_Protected_Type (Conc_Typ) then
8511 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8514 Make_Attribute_Reference (Loc,
8518 Name_Unchecked_Access);
8520 -- Task to task requeue
8523 pragma Assert (Is_Task_Type (Conc_Typ));
8525 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8528 Prepend (New_Param, Params);
8532 -- Create the GNARLI or predefined primitive call
8535 Make_Procedure_Call_Statement (Loc,
8537 Parameter_Associations => Params);
8542 if Is_Protected_Type (Old_Typ) then
8544 -- Build the return statement to skip the rest of the entry body
8546 Skip_Stat := Make_Simple_Return_Statement (Loc);
8549 -- If the requeue is within a task, find the end label of the
8550 -- enclosing accept statement.
8552 Acc_Stat := Parent (N);
8553 while Nkind (Acc_Stat) /= N_Accept_Statement loop
8554 Acc_Stat := Parent (Acc_Stat);
8557 -- The last statement is the second label, used for completing the
8558 -- rendezvous the usual way. The label we are looking for is right
8562 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
8564 pragma Assert (Nkind (Lab_Node) = N_Label);
8566 -- Build the goto statement to skip the rest of the accept
8570 Make_Goto_Statement (Loc,
8571 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
8574 Set_Analyzed (Skip_Stat);
8576 Insert_After (N, Skip_Stat);
8577 end Expand_N_Requeue_Statement;
8579 -------------------------------
8580 -- Expand_N_Selective_Accept --
8581 -------------------------------
8583 procedure Expand_N_Selective_Accept (N : Node_Id) is
8584 Loc : constant Source_Ptr := Sloc (N);
8585 Alts : constant List_Id := Select_Alternatives (N);
8587 -- Note: in the below declarations a lot of new lists are allocated
8588 -- unconditionally which may well not end up being used. That's
8589 -- not a good idea since it wastes space gratuitously ???
8591 Accept_Case : List_Id;
8592 Accept_List : constant List_Id := New_List;
8595 Alt_List : constant List_Id := New_List;
8596 Alt_Stats : List_Id;
8597 Ann : Entity_Id := Empty;
8600 Check_Guard : Boolean := True;
8602 Decls : constant List_Id := New_List;
8603 Stats : constant List_Id := New_List;
8604 Body_List : constant List_Id := New_List;
8605 Trailing_List : constant List_Id := New_List;
8608 Else_Present : Boolean := False;
8609 Terminate_Alt : Node_Id := Empty;
8610 Select_Mode : Node_Id;
8612 Delay_Case : List_Id;
8613 Delay_Count : Integer := 0;
8614 Delay_Val : Entity_Id;
8615 Delay_Index : Entity_Id;
8616 Delay_Min : Entity_Id;
8617 Delay_Num : Int := 1;
8618 Delay_Alt_List : List_Id := New_List;
8619 Delay_List : constant List_Id := New_List;
8623 First_Delay : Boolean := True;
8624 Guard_Open : Entity_Id;
8630 Num_Accept : Nat := 0;
8633 Time_Type : Entity_Id;
8635 Select_Call : Node_Id;
8637 Qnam : constant Entity_Id :=
8638 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
8640 Xnam : constant Entity_Id :=
8641 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
8643 -----------------------
8644 -- Local subprograms --
8645 -----------------------
8647 function Accept_Or_Raise return List_Id;
8648 -- For the rare case where delay alternatives all have guards, and
8649 -- all of them are closed, it is still possible that there were open
8650 -- accept alternatives with no callers. We must reexamine the
8651 -- Accept_List, and execute a selective wait with no else if some
8652 -- accept is open. If none, we raise program_error.
8654 procedure Add_Accept (Alt : Node_Id);
8655 -- Process a single accept statement in a select alternative. Build
8656 -- procedure for body of accept, and add entry to dispatch table with
8657 -- expression for guard, in preparation for call to run time select.
8659 function Make_And_Declare_Label (Num : Int) return Node_Id;
8660 -- Manufacture a label using Num as a serial number and declare it.
8661 -- The declaration is appended to Decls. The label marks the trailing
8662 -- statements of an accept or delay alternative.
8664 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
8665 -- Build call to Selective_Wait runtime routine
8667 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
8668 -- Add code to compare value of delay with previous values, and
8669 -- generate case entry for trailing statements.
8671 procedure Process_Accept_Alternative
8675 -- Add code to call corresponding procedure, and branch to
8676 -- trailing statements, if any.
8678 ---------------------
8679 -- Accept_Or_Raise --
8680 ---------------------
8682 function Accept_Or_Raise return List_Id is
8685 J : constant Entity_Id := Make_Defining_Identifier (Loc,
8686 New_Internal_Name ('J'));
8689 -- We generate the following:
8691 -- for J in q'range loop
8692 -- if q(J).S /=null_task_entry then
8693 -- selective_wait (simple_mode,...);
8699 -- if no rendez_vous then
8700 -- raise program_error;
8703 -- Note that the code needs to know that the selector name
8704 -- in an Accept_Alternative is named S.
8706 Cond := Make_Op_Ne (Loc,
8708 Make_Selected_Component (Loc,
8709 Prefix => Make_Indexed_Component (Loc,
8710 Prefix => New_Reference_To (Qnam, Loc),
8711 Expressions => New_List (New_Reference_To (J, Loc))),
8712 Selector_Name => Make_Identifier (Loc, Name_S)),
8714 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
8717 Make_Implicit_Loop_Statement (N,
8718 Identifier => Empty,
8720 Make_Iteration_Scheme (Loc,
8721 Loop_Parameter_Specification =>
8722 Make_Loop_Parameter_Specification (Loc,
8723 Defining_Identifier => J,
8724 Discrete_Subtype_Definition =>
8725 Make_Attribute_Reference (Loc,
8726 Prefix => New_Reference_To (Qnam, Loc),
8727 Attribute_Name => Name_Range,
8728 Expressions => New_List (
8729 Make_Integer_Literal (Loc, 1))))),
8731 Statements => New_List (
8732 Make_Implicit_If_Statement (N,
8734 Then_Statements => New_List (
8736 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
8737 Make_Exit_Statement (Loc))))));
8740 Make_Raise_Program_Error (Loc,
8741 Condition => Make_Op_Eq (Loc,
8742 Left_Opnd => New_Reference_To (Xnam, Loc),
8744 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8745 Reason => PE_All_Guards_Closed));
8748 end Accept_Or_Raise;
8754 procedure Add_Accept (Alt : Node_Id) is
8755 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
8756 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
8757 Eloc : constant Source_Ptr := Sloc (Ename);
8758 Eent : constant Entity_Id := Entity (Ename);
8759 Index : constant Node_Id := Entry_Index (Acc_Stm);
8760 Null_Body : Node_Id;
8761 Proc_Body : Node_Id;
8768 Ann := Node (Last_Elmt (Accept_Address (Eent)));
8771 if Present (Condition (Alt)) then
8773 Make_Conditional_Expression (Eloc, New_List (
8775 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
8776 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
8779 Entry_Index_Expression
8780 (Eloc, Eent, Index, Scope (Eent));
8783 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8784 Null_Body := New_Reference_To (Standard_False, Eloc);
8786 if Abort_Allowed then
8787 Call := Make_Procedure_Call_Statement (Eloc,
8788 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
8789 Insert_Before (First (Statements (Handled_Statement_Sequence (
8790 Accept_Statement (Alt)))), Call);
8795 Make_Defining_Identifier (Eloc,
8796 New_External_Name (Chars (Ename), 'A', Num_Accept));
8798 if Comes_From_Source (Alt) then
8799 Set_Debug_Info_Needed (PB_Ent);
8803 Make_Subprogram_Body (Eloc,
8805 Make_Procedure_Specification (Eloc,
8806 Defining_Unit_Name => PB_Ent),
8807 Declarations => Declarations (Acc_Stm),
8808 Handled_Statement_Sequence =>
8809 Build_Accept_Body (Accept_Statement (Alt)));
8811 -- During the analysis of the body of the accept statement, any
8812 -- zero cost exception handler records were collected in the
8813 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8814 -- This is where we move them to where they belong, namely the
8815 -- newly created procedure.
8817 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8818 Append (Proc_Body, Body_List);
8821 Null_Body := New_Reference_To (Standard_True, Eloc);
8823 -- if accept statement has declarations, insert above, given that
8824 -- we are not creating a body for the accept.
8826 if Present (Declarations (Acc_Stm)) then
8827 Insert_Actions (N, Declarations (Acc_Stm));
8831 Append_To (Accept_List,
8832 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
8834 Num_Accept := Num_Accept + 1;
8837 ----------------------------
8838 -- Make_And_Declare_Label --
8839 ----------------------------
8841 function Make_And_Declare_Label (Num : Int) return Node_Id is
8845 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8847 Make_Label (Loc, Lab_Id);
8850 Make_Implicit_Label_Declaration (Loc,
8851 Defining_Identifier =>
8852 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8853 Label_Construct => Lab));
8856 end Make_And_Declare_Label;
8858 ----------------------
8859 -- Make_Select_Call --
8860 ----------------------
8862 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8863 Params : constant List_Id := New_List;
8867 Make_Attribute_Reference (Loc,
8868 Prefix => New_Reference_To (Qnam, Loc),
8869 Attribute_Name => Name_Unchecked_Access),
8871 Append (Select_Mode, Params);
8872 Append (New_Reference_To (Ann, Loc), Params);
8873 Append (New_Reference_To (Xnam, Loc), Params);
8876 Make_Procedure_Call_Statement (Loc,
8877 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8878 Parameter_Associations => Params);
8879 end Make_Select_Call;
8881 --------------------------------
8882 -- Process_Accept_Alternative --
8883 --------------------------------
8885 procedure Process_Accept_Alternative
8890 Choices : List_Id := No_List;
8891 Alt_Stats : List_Id;
8894 Adjust_Condition (Condition (Alt));
8895 Alt_Stats := No_List;
8897 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8898 Choices := New_List (
8899 Make_Integer_Literal (Loc, Index));
8901 Alt_Stats := New_List (
8902 Make_Procedure_Call_Statement (Sloc (Proc),
8903 Name => New_Reference_To (
8904 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
8907 if Statements (Alt) /= Empty_List then
8909 if No (Alt_Stats) then
8911 -- Accept with no body, followed by trailing statements
8913 Choices := New_List (
8914 Make_Integer_Literal (Loc, Index));
8916 Alt_Stats := New_List;
8919 -- After the call, if any, branch to trailing statements. We
8920 -- create a label for each, as well as the corresponding label
8923 Lab := Make_And_Declare_Label (Index);
8924 Append_To (Alt_Stats,
8925 Make_Goto_Statement (Loc,
8926 Name => New_Copy (Identifier (Lab))));
8928 Append (Lab, Trailing_List);
8929 Append_List (Statements (Alt), Trailing_List);
8930 Append_To (Trailing_List,
8931 Make_Goto_Statement (Loc,
8932 Name => New_Copy (Identifier (End_Lab))));
8935 if Present (Alt_Stats) then
8937 -- Procedure call. and/or trailing statements
8939 Append_To (Alt_List,
8940 Make_Case_Statement_Alternative (Loc,
8941 Discrete_Choices => Choices,
8942 Statements => Alt_Stats));
8944 end Process_Accept_Alternative;
8946 -------------------------------
8947 -- Process_Delay_Alternative --
8948 -------------------------------
8950 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
8953 Delay_Alt : List_Id;
8956 -- Deal with C/Fortran boolean as delay condition
8958 Adjust_Condition (Condition (Alt));
8960 -- Determine the smallest specified delay
8962 -- for each delay alternative generate:
8964 -- if guard-expression then
8965 -- Delay_Val := delay-expression;
8966 -- Guard_Open := True;
8967 -- if Delay_Val < Delay_Min then
8968 -- Delay_Min := Delay_Val;
8969 -- Delay_Index := Index;
8973 -- The enclosing if-statement is omitted if there is no guard
8978 First_Delay := False;
8980 Delay_Alt := New_List (
8981 Make_Assignment_Statement (Loc,
8982 Name => New_Reference_To (Delay_Min, Loc),
8983 Expression => Expression (Delay_Statement (Alt))));
8985 if Delay_Count > 1 then
8986 Append_To (Delay_Alt,
8987 Make_Assignment_Statement (Loc,
8988 Name => New_Reference_To (Delay_Index, Loc),
8989 Expression => Make_Integer_Literal (Loc, Index)));
8993 Delay_Alt := New_List (
8994 Make_Assignment_Statement (Loc,
8995 Name => New_Reference_To (Delay_Val, Loc),
8996 Expression => Expression (Delay_Statement (Alt))));
8998 if Time_Type = Standard_Duration then
9001 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9002 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9005 -- The scope of the time type must define a comparison
9006 -- operator. The scope itself may not be visible, so we
9007 -- construct a node with entity information to insure that
9008 -- semantic analysis can find the proper operator.
9011 Make_Function_Call (Loc,
9012 Name => Make_Selected_Component (Loc,
9013 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9015 Make_Operator_Symbol (Loc,
9016 Chars => Name_Op_Lt,
9017 Strval => No_String)),
9018 Parameter_Associations =>
9020 New_Reference_To (Delay_Val, Loc),
9021 New_Reference_To (Delay_Min, Loc)));
9023 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9026 Append_To (Delay_Alt,
9027 Make_Implicit_If_Statement (N,
9029 Then_Statements => New_List (
9030 Make_Assignment_Statement (Loc,
9031 Name => New_Reference_To (Delay_Min, Loc),
9032 Expression => New_Reference_To (Delay_Val, Loc)),
9034 Make_Assignment_Statement (Loc,
9035 Name => New_Reference_To (Delay_Index, Loc),
9036 Expression => Make_Integer_Literal (Loc, Index)))));
9040 Append_To (Delay_Alt,
9041 Make_Assignment_Statement (Loc,
9042 Name => New_Reference_To (Guard_Open, Loc),
9043 Expression => New_Reference_To (Standard_True, Loc)));
9046 if Present (Condition (Alt)) then
9047 Delay_Alt := New_List (
9048 Make_Implicit_If_Statement (N,
9049 Condition => Condition (Alt),
9050 Then_Statements => Delay_Alt));
9053 Append_List (Delay_Alt, Delay_List);
9055 -- If the delay alternative has a statement part, add choice to the
9056 -- case statements for delays.
9058 if Present (Statements (Alt)) then
9060 if Delay_Count = 1 then
9061 Append_List (Statements (Alt), Delay_Alt_List);
9064 Choices := New_List (
9065 Make_Integer_Literal (Loc, Index));
9067 Append_To (Delay_Alt_List,
9068 Make_Case_Statement_Alternative (Loc,
9069 Discrete_Choices => Choices,
9070 Statements => Statements (Alt)));
9073 elsif Delay_Count = 1 then
9075 -- If the single delay has no trailing statements, add a branch
9076 -- to the exit label to the selective wait.
9078 Delay_Alt_List := New_List (
9079 Make_Goto_Statement (Loc,
9080 Name => New_Copy (Identifier (End_Lab))));
9083 end Process_Delay_Alternative;
9085 -- Start of processing for Expand_N_Selective_Accept
9088 -- First insert some declarations before the select. The first is:
9092 -- This variable holds the parameters passed to the accept body. This
9093 -- declaration has already been inserted by the time we get here by
9094 -- a call to Expand_Accept_Declarations made from the semantics when
9095 -- processing the first accept statement contained in the select. We
9096 -- can find this entity as Accept_Address (E), where E is any of the
9097 -- entries references by contained accept statements.
9099 -- The first step is to scan the list of Selective_Accept_Statements
9100 -- to find this entity, and also count the number of accepts, and
9101 -- determine if terminated, delay or else is present:
9105 Alt := First (Alts);
9106 while Present (Alt) loop
9108 if Nkind (Alt) = N_Accept_Alternative then
9111 elsif Nkind (Alt) = N_Delay_Alternative then
9112 Delay_Count := Delay_Count + 1;
9114 -- If the delays are relative delays, the delay expressions have
9115 -- type Standard_Duration. Otherwise they must have some time type
9116 -- recognized by GNAT.
9118 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9119 Time_Type := Standard_Duration;
9121 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9123 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9124 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9129 "& is not a time type (RM 9.6(6))",
9130 Expression (Delay_Statement (Alt)), Time_Type);
9131 Time_Type := Standard_Duration;
9132 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9136 if No (Condition (Alt)) then
9138 -- This guard will always be open
9140 Check_Guard := False;
9143 elsif Nkind (Alt) = N_Terminate_Alternative then
9144 Adjust_Condition (Condition (Alt));
9145 Terminate_Alt := Alt;
9148 Num_Alts := Num_Alts + 1;
9152 Else_Present := Present (Else_Statements (N));
9154 -- At the same time (see procedure Add_Accept) we build the accept list:
9156 -- Qnn : Accept_List (1 .. num-select) := (
9157 -- (null-body, entry-index),
9158 -- (null-body, entry-index),
9160 -- (null_body, entry-index));
9162 -- In the above declaration, null-body is True if the corresponding
9163 -- accept has no body, and false otherwise. The entry is either the
9164 -- entry index expression if there is no guard, or if a guard is
9165 -- present, then a conditional expression of the form:
9167 -- (if guard then entry-index else Null_Task_Entry)
9169 -- If a guard is statically known to be false, the entry can simply
9170 -- be omitted from the accept list.
9173 Make_Object_Declaration (Loc,
9174 Defining_Identifier => Qnam,
9175 Object_Definition =>
9176 New_Reference_To (RTE (RE_Accept_List), Loc),
9177 Aliased_Present => True,
9180 Make_Qualified_Expression (Loc,
9182 New_Reference_To (RTE (RE_Accept_List), Loc),
9184 Make_Aggregate (Loc, Expressions => Accept_List)));
9188 -- Then we declare the variable that holds the index for the accept
9189 -- that will be selected for service:
9191 -- Xnn : Select_Index;
9194 Make_Object_Declaration (Loc,
9195 Defining_Identifier => Xnam,
9196 Object_Definition =>
9197 New_Reference_To (RTE (RE_Select_Index), Loc),
9199 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9203 -- After this follow procedure declarations for each accept body
9210 -- where the ... are statements from the corresponding procedure body.
9211 -- No parameters are involved, since the parameters are passed via Ann
9212 -- and the parameter references have already been expanded to be direct
9213 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9214 -- any embedded tasking statements (which would normally be illegal in
9215 -- procedures), have been converted to calls to the tasking runtime so
9216 -- there is no problem in putting them into procedures.
9218 -- The original accept statement has been expanded into a block in
9219 -- the same fashion as for simple accepts (see Build_Accept_Body).
9221 -- Note: we don't really need to build these procedures for the case
9222 -- where no delay statement is present, but it is just as easy to
9223 -- build them unconditionally, and not significantly inefficient,
9224 -- since if they are short they will be inlined anyway.
9226 -- The procedure declarations have been assembled in Body_List
9228 -- If delays are present, we must compute the required delay.
9229 -- We first generate the declarations:
9231 -- Delay_Index : Boolean := 0;
9232 -- Delay_Min : Some_Time_Type.Time;
9233 -- Delay_Val : Some_Time_Type.Time;
9235 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9236 -- active delay that is actually chosen as the basis for the possible
9237 -- delay if an immediate rendez-vous is not possible.
9239 -- In the most common case there is a single delay statement, and this
9240 -- is handled specially.
9242 if Delay_Count > 0 then
9244 -- Generate the required declarations
9247 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9249 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9251 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9254 Make_Object_Declaration (Loc,
9255 Defining_Identifier => Delay_Val,
9256 Object_Definition => New_Reference_To (Time_Type, Loc)));
9259 Make_Object_Declaration (Loc,
9260 Defining_Identifier => Delay_Index,
9261 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9262 Expression => Make_Integer_Literal (Loc, 0)));
9265 Make_Object_Declaration (Loc,
9266 Defining_Identifier => Delay_Min,
9267 Object_Definition => New_Reference_To (Time_Type, Loc),
9269 Unchecked_Convert_To (Time_Type,
9270 Make_Attribute_Reference (Loc,
9272 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9273 Attribute_Name => Name_Last))));
9275 -- Create Duration and Delay_Mode objects used for passing a delay
9278 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
9279 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
9285 -- Note that these values are defined in s-osprim.ads and must
9288 -- Relative : constant := 0;
9289 -- Absolute_Calendar : constant := 1;
9290 -- Absolute_RT : constant := 2;
9292 if Time_Type = Standard_Duration then
9293 Discr := Make_Integer_Literal (Loc, 0);
9295 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9296 Discr := Make_Integer_Literal (Loc, 1);
9300 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9301 Discr := Make_Integer_Literal (Loc, 2);
9305 Make_Object_Declaration (Loc,
9306 Defining_Identifier => D,
9307 Object_Definition =>
9308 New_Reference_To (Standard_Duration, Loc)));
9311 Make_Object_Declaration (Loc,
9312 Defining_Identifier => M,
9313 Object_Definition =>
9314 New_Reference_To (Standard_Integer, Loc),
9315 Expression => Discr));
9320 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9323 Make_Object_Declaration (Loc,
9324 Defining_Identifier => Guard_Open,
9325 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9326 Expression => New_Reference_To (Standard_False, Loc)));
9329 -- Delay_Count is zero, don't need M and D set (suppress warning)
9336 if Present (Terminate_Alt) then
9338 -- If the terminate alternative guard is False, use
9339 -- Simple_Mode; otherwise use Terminate_Mode.
9341 if Present (Condition (Terminate_Alt)) then
9342 Select_Mode := Make_Conditional_Expression (Loc,
9343 New_List (Condition (Terminate_Alt),
9344 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9345 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9347 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9350 elsif Else_Present or Delay_Count > 0 then
9351 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9354 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9357 Select_Call := Make_Select_Call (Select_Mode);
9358 Append (Select_Call, Stats);
9360 -- Now generate code to act on the result. There is an entry
9361 -- in this case for each accept statement with a non-null body,
9362 -- followed by a branch to the statements that follow the Accept.
9363 -- In the absence of delay alternatives, we generate:
9366 -- when No_Rendezvous => -- omitted if simple mode
9381 -- Lab0: Else_Statements;
9384 -- Lab1: Trailing_Statements1;
9387 -- Lab2: Trailing_Statements2;
9392 -- Generate label for common exit
9394 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9396 -- First entry is the default case, when no rendezvous is possible
9398 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9400 if Else_Present then
9402 -- If no rendezvous is possible, the else part is executed
9404 Lab := Make_And_Declare_Label (0);
9405 Alt_Stats := New_List (
9406 Make_Goto_Statement (Loc,
9407 Name => New_Copy (Identifier (Lab))));
9409 Append (Lab, Trailing_List);
9410 Append_List (Else_Statements (N), Trailing_List);
9411 Append_To (Trailing_List,
9412 Make_Goto_Statement (Loc,
9413 Name => New_Copy (Identifier (End_Lab))));
9415 Alt_Stats := New_List (
9416 Make_Goto_Statement (Loc,
9417 Name => New_Copy (Identifier (End_Lab))));
9420 Append_To (Alt_List,
9421 Make_Case_Statement_Alternative (Loc,
9422 Discrete_Choices => Choices,
9423 Statements => Alt_Stats));
9425 -- We make use of the fact that Accept_Index is an integer type, and
9426 -- generate successive literals for entries for each accept. Only those
9427 -- for which there is a body or trailing statements get a case entry.
9429 Alt := First (Select_Alternatives (N));
9430 Proc := First (Body_List);
9431 while Present (Alt) loop
9433 if Nkind (Alt) = N_Accept_Alternative then
9434 Process_Accept_Alternative (Alt, Index, Proc);
9438 (Handled_Statement_Sequence (Accept_Statement (Alt)))
9443 elsif Nkind (Alt) = N_Delay_Alternative then
9444 Process_Delay_Alternative (Alt, Delay_Num);
9445 Delay_Num := Delay_Num + 1;
9451 -- An others choice is always added to the main case, as well
9452 -- as the delay case (to satisfy the compiler).
9454 Append_To (Alt_List,
9455 Make_Case_Statement_Alternative (Loc,
9457 New_List (Make_Others_Choice (Loc)),
9459 New_List (Make_Goto_Statement (Loc,
9460 Name => New_Copy (Identifier (End_Lab))))));
9462 Accept_Case := New_List (
9463 Make_Case_Statement (Loc,
9464 Expression => New_Reference_To (Xnam, Loc),
9465 Alternatives => Alt_List));
9467 Append_List (Trailing_List, Accept_Case);
9468 Append (End_Lab, Accept_Case);
9469 Append_List (Body_List, Decls);
9471 -- Construct case statement for trailing statements of delay
9472 -- alternatives, if there are several of them.
9474 if Delay_Count > 1 then
9475 Append_To (Delay_Alt_List,
9476 Make_Case_Statement_Alternative (Loc,
9478 New_List (Make_Others_Choice (Loc)),
9480 New_List (Make_Null_Statement (Loc))));
9482 Delay_Case := New_List (
9483 Make_Case_Statement (Loc,
9484 Expression => New_Reference_To (Delay_Index, Loc),
9485 Alternatives => Delay_Alt_List));
9487 Delay_Case := Delay_Alt_List;
9490 -- If there are no delay alternatives, we append the case statement
9491 -- to the statement list.
9493 if Delay_Count = 0 then
9494 Append_List (Accept_Case, Stats);
9496 -- Delay alternatives present
9499 -- If delay alternatives are present we generate:
9501 -- find minimum delay.
9502 -- DX := minimum delay;
9503 -- M := <delay mode>;
9504 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9507 -- if X = No_Rendezvous then
9508 -- case statement for delay statements.
9510 -- case statement for accept alternatives.
9521 -- The type of the delay expression is known to be legal
9523 if Time_Type = Standard_Duration then
9524 Conv := New_Reference_To (Delay_Min, Loc);
9526 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9527 Conv := Make_Function_Call (Loc,
9528 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9529 New_List (New_Reference_To (Delay_Min, Loc)));
9533 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9535 Conv := Make_Function_Call (Loc,
9536 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9537 New_List (New_Reference_To (Delay_Min, Loc)));
9540 Stmt := Make_Assignment_Statement (Loc,
9541 Name => New_Reference_To (D, Loc),
9542 Expression => Conv);
9544 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
9546 Parms := Parameter_Associations (Select_Call);
9547 Parm := First (Parms);
9549 while Present (Parm)
9550 and then Parm /= Select_Mode
9555 pragma Assert (Present (Parm));
9556 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
9559 -- Prepare two new parameters of Duration and Delay_Mode type
9560 -- which represent the value and the mode of the minimum delay.
9563 Insert_After (Parm, New_Reference_To (M, Loc));
9564 Insert_After (Parm, New_Reference_To (D, Loc));
9566 -- Create a call to RTS
9568 Rewrite (Select_Call,
9569 Make_Procedure_Call_Statement (Loc,
9570 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
9571 Parameter_Associations => Parms));
9573 -- This new call should follow the calculation of the minimum
9576 Insert_List_Before (Select_Call, Delay_List);
9580 Make_Implicit_If_Statement (N,
9581 Condition => New_Reference_To (Guard_Open, Loc),
9583 New_List (New_Copy_Tree (Stmt),
9584 New_Copy_Tree (Select_Call)),
9585 Else_Statements => Accept_Or_Raise);
9586 Rewrite (Select_Call, Stmt);
9588 Insert_Before (Select_Call, Stmt);
9592 Make_Implicit_If_Statement (N,
9593 Condition => Make_Op_Eq (Loc,
9594 Left_Opnd => New_Reference_To (Xnam, Loc),
9596 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9598 Then_Statements => Delay_Case,
9599 Else_Statements => Accept_Case);
9601 Append (Cases, Stats);
9605 -- Replace accept statement with appropriate block
9608 Make_Block_Statement (Loc,
9609 Declarations => Decls,
9610 Handled_Statement_Sequence =>
9611 Make_Handled_Sequence_Of_Statements (Loc,
9612 Statements => Stats));
9617 -- Note: have to worry more about abort deferral in above code ???
9619 -- Final step is to unstack the Accept_Address entries for all accept
9620 -- statements appearing in accept alternatives in the select statement
9622 Alt := First (Alts);
9623 while Present (Alt) loop
9624 if Nkind (Alt) = N_Accept_Alternative then
9625 Remove_Last_Elmt (Accept_Address
9626 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
9631 end Expand_N_Selective_Accept;
9633 --------------------------------------
9634 -- Expand_N_Single_Task_Declaration --
9635 --------------------------------------
9637 -- Single task declarations should never be present after semantic
9638 -- analysis, since we expect them to be replaced by a declaration of an
9639 -- anonymous task type, followed by a declaration of the task object. We
9640 -- include this routine to make sure that is happening!
9642 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
9644 raise Program_Error;
9645 end Expand_N_Single_Task_Declaration;
9647 ------------------------
9648 -- Expand_N_Task_Body --
9649 ------------------------
9651 -- Given a task body
9653 -- task body tname is
9659 -- This expansion routine converts it into a procedure and sets the
9660 -- elaboration flag for the procedure to true, to represent the fact
9661 -- that the task body is now elaborated:
9663 -- procedure tnameB (_Task : access tnameV) is
9664 -- discriminal : dtype renames _Task.discriminant;
9666 -- procedure _clean is
9670 -- Abort_Undefer.all;
9675 -- Abort_Undefer.all;
9677 -- System.Task_Stages.Complete_Activation;
9685 -- In addition, if the task body is an activator, then a call to activate
9686 -- tasks is added at the start of the statements, before the call to
9687 -- Complete_Activation, and if in addition the task is a master then it
9688 -- must be established as a master. These calls are inserted and analyzed
9689 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9692 -- There is one discriminal declaration line generated for each
9693 -- discriminant that is present to provide an easy reference point for
9694 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9696 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9697 -- task body procedures have a profile (Arg : System.Address). That is
9698 -- needed because GNARLI has to use the same access-to-subprogram type
9699 -- for all task types. We depend here on knowing that in GNAT, passing
9700 -- an address argument by value is identical to passing a record value
9701 -- by access (in either case a single pointer is passed), so even though
9702 -- this procedure has the wrong profile. In fact it's all OK, since the
9703 -- callings sequence is identical.
9705 procedure Expand_N_Task_Body (N : Node_Id) is
9706 Loc : constant Source_Ptr := Sloc (N);
9707 Ttyp : constant Entity_Id := Corresponding_Spec (N);
9711 Insert_Nod : Node_Id;
9712 -- Used to determine the proper location of wrapper body insertions
9715 -- Add renaming declarations for discriminals and a declaration for the
9716 -- entry family index (if applicable).
9718 Install_Private_Data_Declarations
9719 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
9721 -- Add a call to Abort_Undefer at the very beginning of the task
9722 -- body since this body is called with abort still deferred.
9724 if Abort_Allowed then
9725 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
9727 (First (Statements (Handled_Statement_Sequence (N))), Call);
9731 -- The statement part has already been protected with an at_end and
9732 -- cleanup actions. The call to Complete_Activation must be placed
9733 -- at the head of the sequence of statements of that block. The
9734 -- declarations have been merged in this sequence of statements but
9735 -- the first real statement is accessible from the First_Real_Statement
9736 -- field (which was set for exactly this purpose).
9738 if Restricted_Profile then
9739 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
9741 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
9745 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
9749 Make_Subprogram_Body (Loc,
9750 Specification => Build_Task_Proc_Specification (Ttyp),
9751 Declarations => Declarations (N),
9752 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
9754 -- If the task contains generic instantiations, cleanup actions are
9755 -- delayed until after instantiation. Transfer the activation chain to
9756 -- the subprogram, to insure that the activation call is properly
9757 -- generated. It the task body contains inner tasks, indicate that the
9758 -- subprogram is a task master.
9760 if Delay_Cleanups (Ttyp) then
9761 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
9762 Set_Is_Task_Master (New_N, Is_Task_Master (N));
9768 -- Set elaboration flag immediately after task body. If the body is a
9769 -- subunit, the flag is set in the declarative part containing the stub.
9771 if Nkind (Parent (N)) /= N_Subunit then
9773 Make_Assignment_Statement (Loc,
9775 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
9776 Expression => New_Reference_To (Standard_True, Loc)));
9779 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9780 -- the task body. At this point all wrapper specs have been created,
9781 -- frozen and included in the dispatch table for the task type.
9783 if Ada_Version >= Ada_05 then
9784 if Nkind (Parent (N)) = N_Subunit then
9785 Insert_Nod := Corresponding_Stub (Parent (N));
9790 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
9792 end Expand_N_Task_Body;
9794 ------------------------------------
9795 -- Expand_N_Task_Type_Declaration --
9796 ------------------------------------
9798 -- We have several things to do. First we must create a Boolean flag used
9799 -- to mark if the body is elaborated yet. This variable gets set to True
9800 -- when the body of the task is elaborated (we can't rely on the normal
9801 -- ABE mechanism for the task body, since we need to pass an access to
9802 -- this elaboration boolean to the runtime routines).
9804 -- taskE : aliased Boolean := False;
9806 -- Next a variable is declared to hold the task stack size (either the
9807 -- default : Unspecified_Size, or a value that is set by a pragma
9808 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9809 -- the variable is initialized with this value:
9811 -- taskZ : Size_Type := Unspecified_Size;
9813 -- taskZ : Size_Type := Size_Type (size_expression);
9815 -- Note: No variable is needed to hold the task relative deadline since
9816 -- its value would never be static because the parameter is of a private
9817 -- type (Ada.Real_Time.Time_Span).
9819 -- Next we create a corresponding record type declaration used to represent
9820 -- values of this task. The general form of this type declaration is
9822 -- type taskV (discriminants) is record
9823 -- _Task_Id : Task_Id;
9824 -- entry_family : array (bounds) of Void;
9825 -- _Priority : Integer := priority_expression;
9826 -- _Size : Size_Type := Size_Type (size_expression);
9827 -- _Task_Info : Task_Info_Type := task_info_expression;
9830 -- The discriminants are present only if the corresponding task type has
9831 -- discriminants, and they exactly mirror the task type discriminants.
9833 -- The Id field is always present. It contains the Task_Id value, as set by
9834 -- the call to Create_Task. Note that although the task is limited, the
9835 -- task value record type is not limited, so there is no problem in passing
9836 -- this field as an out parameter to Create_Task.
9838 -- One entry_family component is present for each entry family in the task
9839 -- definition. The bounds correspond to the bounds of the entry family
9840 -- (which may depend on discriminants). The element type is void, since we
9841 -- only need the bounds information for determining the entry index. Note
9842 -- that the use of an anonymous array would normally be illegal in this
9843 -- context, but this is a parser check, and the semantics is quite prepared
9844 -- to handle such a case.
9846 -- The _Size field is present only if a Storage_Size pragma appears in the
9847 -- task definition. The expression captures the argument that was present
9848 -- in the pragma, and is used to override the task stack size otherwise
9849 -- associated with the task type.
9851 -- The _Priority field is present only if a Priority or Interrupt_Priority
9852 -- pragma appears in the task definition. The expression captures the
9853 -- argument that was present in the pragma, and is used to provide the Size
9854 -- parameter to the call to Create_Task.
9856 -- The _Task_Info field is present only if a Task_Info pragma appears in
9857 -- the task definition. The expression captures the argument that was
9858 -- present in the pragma, and is used to provide the Task_Image parameter
9859 -- to the call to Create_Task.
9861 -- The _Relative_Deadline field is present only if a Relative_Deadline
9862 -- pragma appears in the task definition. The expression captures the
9863 -- argument that was present in the pragma, and is used to provide the
9864 -- Relative_Deadline parameter to the call to Create_Task.
9866 -- When a task is declared, an instance of the task value record is
9867 -- created. The elaboration of this declaration creates the correct bounds
9868 -- for the entry families, and also evaluates the size, priority, and
9869 -- task_Info expressions if needed. The initialization routine for the task
9870 -- type itself then calls Create_Task with appropriate parameters to
9871 -- initialize the value of the Task_Id field.
9873 -- Note: the address of this record is passed as the "Discriminants"
9874 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9875 -- body procedure, it does not matter that it does not quite match the
9876 -- GNARLI model of what is being passed (the record contains more than just
9877 -- the discriminants, but the discriminants can be found from the record
9880 -- The Entity_Id for this created record type is placed in the
9881 -- Corresponding_Record_Type field of the associated task type entity.
9883 -- Next we create a procedure specification for the task body procedure:
9885 -- procedure taskB (_Task : access taskV);
9887 -- Note that this must come after the record type declaration, since
9888 -- the spec refers to this type. It turns out that the initialization
9889 -- procedure for the value type references the task body spec, but that's
9890 -- fine, since it won't be generated till the freeze point for the type,
9891 -- which is certainly after the task body spec declaration.
9893 -- Finally, we set the task index value field of the entry attribute in
9894 -- the case of a simple entry.
9896 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9897 Loc : constant Source_Ptr := Sloc (N);
9898 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9899 Tasknm : constant Name_Id := Chars (Tasktyp);
9900 Taskdef : constant Node_Id := Task_Definition (N);
9902 Proc_Spec : Node_Id;
9904 Rec_Ent : Entity_Id;
9906 Elab_Decl : Node_Id;
9907 Size_Decl : Node_Id;
9908 Body_Decl : Node_Id;
9909 Task_Size : Node_Id;
9910 Ent_Stack : Entity_Id;
9911 Decl_Stack : Node_Id;
9914 -- If already expanded, nothing to do
9916 if Present (Corresponding_Record_Type (Tasktyp)) then
9920 -- Here we will do the expansion
9922 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9924 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9925 -- of implemented interfaces.
9927 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9929 Rec_Ent := Defining_Identifier (Rec_Decl);
9930 Cdecls := Component_Items (Component_List
9931 (Type_Definition (Rec_Decl)));
9933 Qualify_Entity_Names (N);
9935 -- First create the elaboration variable
9938 Make_Object_Declaration (Loc,
9939 Defining_Identifier =>
9940 Make_Defining_Identifier (Sloc (Tasktyp),
9941 Chars => New_External_Name (Tasknm, 'E')),
9942 Aliased_Present => True,
9943 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9944 Expression => New_Reference_To (Standard_False, Loc));
9945 Insert_After (N, Elab_Decl);
9947 -- Next create the declaration of the size variable (tasknmZ)
9949 Set_Storage_Size_Variable (Tasktyp,
9950 Make_Defining_Identifier (Sloc (Tasktyp),
9951 Chars => New_External_Name (Tasknm, 'Z')));
9953 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
9954 Is_Static_Expression (Expression (First (
9955 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
9956 Taskdef, Name_Storage_Size)))))
9959 Make_Object_Declaration (Loc,
9960 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9961 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9963 Convert_To (RTE (RE_Size_Type),
9966 Pragma_Argument_Associations (
9967 Find_Task_Or_Protected_Pragma
9968 (Taskdef, Name_Storage_Size)))))));
9972 Make_Object_Declaration (Loc,
9973 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9974 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9975 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
9978 Insert_After (Elab_Decl, Size_Decl);
9980 -- Next build the rest of the corresponding record declaration. This is
9981 -- done last, since the corresponding record initialization procedure
9982 -- will reference the previously created entities.
9984 -- Fill in the component declarations -- first the _Task_Id field
9987 Make_Component_Declaration (Loc,
9988 Defining_Identifier =>
9989 Make_Defining_Identifier (Loc, Name_uTask_Id),
9990 Component_Definition =>
9991 Make_Component_Definition (Loc,
9992 Aliased_Present => False,
9993 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
9996 -- Declare static ATCB (that is, created by the expander) if we are
9997 -- using the Restricted run time.
9999 if Restricted_Profile then
10001 Make_Component_Declaration (Loc,
10002 Defining_Identifier =>
10003 Make_Defining_Identifier (Loc, Name_uATCB),
10005 Component_Definition =>
10006 Make_Component_Definition (Loc,
10007 Aliased_Present => True,
10008 Subtype_Indication => Make_Subtype_Indication (Loc,
10009 Subtype_Mark => New_Occurrence_Of
10010 (RTE (RE_Ada_Task_Control_Block), Loc),
10013 Make_Index_Or_Discriminant_Constraint (Loc,
10015 New_List (Make_Integer_Literal (Loc, 0)))))));
10019 -- Declare static stack (that is, created by the expander) if we are
10020 -- using the Restricted run time on a bare board configuration.
10022 if Restricted_Profile
10023 and then Preallocated_Stacks_On_Target
10025 -- First we need to extract the appropriate stack size
10027 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10029 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10031 Expr_N : constant Node_Id :=
10032 Expression (First (
10033 Pragma_Argument_Associations (
10034 Find_Task_Or_Protected_Pragma
10035 (Taskdef, Name_Storage_Size))));
10036 Etyp : constant Entity_Id := Etype (Expr_N);
10037 P : constant Node_Id := Parent (Expr_N);
10040 -- The stack is defined inside the corresponding record.
10041 -- Therefore if the size of the stack is set by means of
10042 -- a discriminant, we must reference the discriminant of the
10043 -- corresponding record type.
10045 if Nkind (Expr_N) in N_Has_Entity
10046 and then Present (Discriminal_Link (Entity (Expr_N)))
10050 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10052 Set_Parent (Task_Size, P);
10053 Set_Etype (Task_Size, Etyp);
10054 Set_Analyzed (Task_Size);
10057 Task_Size := Relocate_Node (Expr_N);
10063 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10066 Decl_Stack := Make_Component_Declaration (Loc,
10067 Defining_Identifier => Ent_Stack,
10069 Component_Definition =>
10070 Make_Component_Definition (Loc,
10071 Aliased_Present => True,
10072 Subtype_Indication => Make_Subtype_Indication (Loc,
10074 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10077 Make_Index_Or_Discriminant_Constraint (Loc,
10078 Constraints => New_List (Make_Range (Loc,
10079 Low_Bound => Make_Integer_Literal (Loc, 1),
10080 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10083 Append_To (Cdecls, Decl_Stack);
10085 -- The appropriate alignment for the stack is ensured by the run-time
10086 -- code in charge of task creation.
10090 -- Add components for entry families
10092 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10094 -- Add the _Priority component if a Priority pragma is present
10096 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
10098 Prag : constant Node_Id :=
10099 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10103 Expr := First (Pragma_Argument_Associations (Prag));
10105 if Nkind (Expr) = N_Pragma_Argument_Association then
10106 Expr := Expression (Expr);
10109 Expr := New_Copy_Tree (Expr);
10111 -- Add conversion to proper type to do range check if required
10112 -- Note that for runtime units, we allow out of range interrupt
10113 -- priority values to be used in a priority pragma. This is for
10114 -- the benefit of some versions of System.Interrupts which use
10115 -- a special server task with maximum interrupt priority.
10117 if Pragma_Name (Prag) = Name_Priority
10118 and then not GNAT_Mode
10120 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10122 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10126 Make_Component_Declaration (Loc,
10127 Defining_Identifier =>
10128 Make_Defining_Identifier (Loc, Name_uPriority),
10129 Component_Definition =>
10130 Make_Component_Definition (Loc,
10131 Aliased_Present => False,
10132 Subtype_Indication => New_Reference_To (Standard_Integer,
10134 Expression => Expr));
10138 -- Add the _Task_Size component if a Storage_Size pragma is present
10140 if Present (Taskdef)
10141 and then Has_Storage_Size_Pragma (Taskdef)
10144 Make_Component_Declaration (Loc,
10145 Defining_Identifier =>
10146 Make_Defining_Identifier (Loc, Name_uSize),
10148 Component_Definition =>
10149 Make_Component_Definition (Loc,
10150 Aliased_Present => False,
10151 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10155 Convert_To (RTE (RE_Size_Type),
10157 Expression (First (
10158 Pragma_Argument_Associations (
10159 Find_Task_Or_Protected_Pragma
10160 (Taskdef, Name_Storage_Size))))))));
10163 -- Add the _Task_Info component if a Task_Info pragma is present
10165 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10167 Make_Component_Declaration (Loc,
10168 Defining_Identifier =>
10169 Make_Defining_Identifier (Loc, Name_uTask_Info),
10171 Component_Definition =>
10172 Make_Component_Definition (Loc,
10173 Aliased_Present => False,
10174 Subtype_Indication =>
10175 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10177 Expression => New_Copy (
10178 Expression (First (
10179 Pragma_Argument_Associations (
10180 Find_Task_Or_Protected_Pragma
10181 (Taskdef, Name_Task_Info)))))));
10184 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10185 -- present. If we are using a restricted run time this component will
10186 -- not be added (deadlines are not allowed by the Ravenscar profile).
10188 if not Restricted_Profile
10189 and then Present (Taskdef)
10190 and then Has_Relative_Deadline_Pragma (Taskdef)
10193 Make_Component_Declaration (Loc,
10194 Defining_Identifier =>
10195 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10197 Component_Definition =>
10198 Make_Component_Definition (Loc,
10199 Aliased_Present => False,
10200 Subtype_Indication =>
10201 New_Reference_To (RTE (RE_Time_Span), Loc)),
10204 Convert_To (RTE (RE_Time_Span),
10206 Expression (First (
10207 Pragma_Argument_Associations (
10208 Find_Task_Or_Protected_Pragma
10209 (Taskdef, Name_Relative_Deadline))))))));
10212 Insert_After (Size_Decl, Rec_Decl);
10214 -- Analyze the record declaration immediately after construction,
10215 -- because the initialization procedure is needed for single task
10216 -- declarations before the next entity is analyzed.
10218 Analyze (Rec_Decl);
10220 -- Create the declaration of the task body procedure
10222 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10224 Make_Subprogram_Declaration (Loc,
10225 Specification => Proc_Spec);
10227 Insert_After (Rec_Decl, Body_Decl);
10229 -- The subprogram does not comes from source, so we have to indicate the
10230 -- need for debugging information explicitly.
10232 if Comes_From_Source (Original_Node (N)) then
10233 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10236 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10237 -- the corresponding record has been frozen.
10239 if Ada_Version >= Ada_05 then
10240 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10243 -- Ada 2005 (AI-345): We must defer freezing to allow further
10244 -- declaration of primitive subprograms covering task interfaces
10246 if Ada_Version <= Ada_95 then
10248 -- Now we can freeze the corresponding record. This needs manually
10249 -- freezing, since it is really part of the task type, and the task
10250 -- type is frozen at this stage. We of course need the initialization
10251 -- procedure for this corresponding record type and we won't get it
10252 -- in time if we don't freeze now.
10255 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
10257 if Is_Non_Empty_List (L) then
10258 Insert_List_After (Body_Decl, L);
10263 -- Complete the expansion of access types to the current task type, if
10264 -- any were declared.
10266 Expand_Previous_Access_Type (Tasktyp);
10267 end Expand_N_Task_Type_Declaration;
10269 -------------------------------
10270 -- Expand_N_Timed_Entry_Call --
10271 -------------------------------
10273 -- A timed entry call in normal case is not implemented using ATC mechanism
10274 -- anymore for efficiency reason.
10284 -- is expanded as follow:
10286 -- 1) When T.E is a task entry_call;
10290 -- X : Task_Entry_Index := <entry index>;
10291 -- DX : Duration := To_Duration (D);
10292 -- M : Delay_Mode := <discriminant>;
10293 -- P : parms := (parm, parm, parm);
10296 -- Timed_Protected_Entry_Call
10297 -- (<acceptor-task>, X, P'Address, DX, M, B);
10305 -- 2) When T.E is a protected entry_call;
10309 -- X : Protected_Entry_Index := <entry index>;
10310 -- DX : Duration := To_Duration (D);
10311 -- M : Delay_Mode := <discriminant>;
10312 -- P : parms := (parm, parm, parm);
10315 -- Timed_Protected_Entry_Call
10316 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10324 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10327 -- B : Boolean := False;
10328 -- C : Ada.Tags.Prim_Op_Kind;
10329 -- DX : Duration := To_Duration (D)
10330 -- K : Ada.Tags.Tagged_Kind :=
10331 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10332 -- M : Integer :=...;
10333 -- P : Parameters := (Param1 .. ParamN);
10337 -- if K = Ada.Tags.TK_Limited_Tagged then
10338 -- <dispatching-call>;
10339 -- <triggering-statements>
10343 -- Ada.Tags.Get_Offset_Index
10344 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10346 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10348 -- if C = POK_Protected_Entry
10349 -- or else C = POK_Task_Entry
10351 -- Param1 := P.Param1;
10353 -- ParamN := P.ParamN;
10357 -- if C = POK_Procedure
10358 -- or else C = POK_Protected_Procedure
10359 -- or else C = POK_Task_Procedure
10361 -- <dispatching-call>;
10364 -- <triggering-statements>
10366 -- <timed-statements>
10371 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10372 Loc : constant Source_Ptr := Sloc (N);
10374 E_Call : Node_Id :=
10375 Entry_Call_Statement (Entry_Call_Alternative (N));
10376 E_Stats : constant List_Id :=
10377 Statements (Entry_Call_Alternative (N));
10378 D_Stat : Node_Id :=
10379 Delay_Statement (Delay_Alternative (N));
10380 D_Stats : constant List_Id :=
10381 Statements (Delay_Alternative (N));
10384 Blk_Typ : Entity_Id;
10386 Call_Ent : Entity_Id;
10387 Conc_Typ_Stmts : List_Id;
10391 D_Type : Entity_Id;
10397 Is_Disp_Select : Boolean;
10398 Lim_Typ_Stmts : List_Id;
10407 B : Entity_Id; -- Call status flag
10408 C : Entity_Id; -- Call kind
10409 D : Entity_Id; -- Delay
10410 K : Entity_Id; -- Tagged kind
10411 M : Entity_Id; -- Delay mode
10412 P : Entity_Id; -- Parameter block
10413 S : Entity_Id; -- Primitive operation slot
10416 -- Under the Ravenscar profile, timed entry calls are excluded. An error
10417 -- was already reported on spec, so do not attempt to expand the call.
10419 if Restriction_Active (No_Select_Statements) then
10423 -- The arguments in the call may require dynamic allocation, and the
10424 -- call statement may have been transformed into a block. The block
10425 -- may contain additional declarations for internal entities, and the
10426 -- original call is found by sequential search.
10428 if Nkind (E_Call) = N_Block_Statement then
10429 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10430 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10431 N_Entry_Call_Statement)
10438 Ada_Version >= Ada_05
10439 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10441 if Is_Disp_Select then
10442 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
10448 -- B : Boolean := False;
10450 B := Build_B (Loc, Decls);
10453 -- C : Ada.Tags.Prim_Op_Kind;
10455 C := Build_C (Loc, Decls);
10457 -- Because the analysis of all statements was disabled, manually
10458 -- analyze the delay statement.
10461 D_Stat := Original_Node (D_Stat);
10464 -- Build an entry call using Simple_Entry_Call
10466 Extract_Entry (E_Call, Concval, Ename, Index);
10467 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
10469 Decls := Declarations (E_Call);
10470 Stmts := Statements (Handled_Statement_Sequence (E_Call));
10479 B := Make_Defining_Identifier (Loc, Name_uB);
10482 Make_Object_Declaration (Loc,
10483 Defining_Identifier =>
10485 Object_Definition =>
10486 New_Reference_To (Standard_Boolean, Loc)));
10489 -- Duration and mode processing
10491 D_Type := Base_Type (Etype (Expression (D_Stat)));
10493 -- Use the type of the delay expression (Calendar or Real_Time) to
10494 -- generate the appropriate conversion.
10496 if Nkind (D_Stat) = N_Delay_Relative_Statement then
10497 D_Disc := Make_Integer_Literal (Loc, 0);
10498 D_Conv := Relocate_Node (Expression (D_Stat));
10500 elsif Is_RTE (D_Type, RO_CA_Time) then
10501 D_Disc := Make_Integer_Literal (Loc, 1);
10502 D_Conv := Make_Function_Call (Loc,
10503 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10504 New_List (New_Copy (Expression (D_Stat))));
10506 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
10507 D_Disc := Make_Integer_Literal (Loc, 2);
10508 D_Conv := Make_Function_Call (Loc,
10509 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10510 New_List (New_Copy (Expression (D_Stat))));
10513 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
10519 Make_Object_Declaration (Loc,
10520 Defining_Identifier =>
10522 Object_Definition =>
10523 New_Reference_To (Standard_Duration, Loc)));
10525 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
10528 -- M : Integer := (0 | 1 | 2);
10531 Make_Object_Declaration (Loc,
10532 Defining_Identifier =>
10534 Object_Definition =>
10535 New_Reference_To (Standard_Integer, Loc),
10539 -- Do the assignment at this stage only because the evaluation of the
10540 -- expression must not occur before (see ACVC C97302A).
10543 Make_Assignment_Statement (Loc,
10545 New_Reference_To (D, Loc),
10549 -- Parameter block processing
10551 -- Manually create the parameter block for dispatching calls. In the
10552 -- case of entries, the block has already been created during the call
10553 -- to Build_Simple_Entry_Call.
10555 if Is_Disp_Select then
10557 -- Tagged kind processing, generate:
10558 -- K : Ada.Tags.Tagged_Kind :=
10559 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
10561 K := Build_K (Loc, Decls, Obj);
10563 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
10564 P := Parameter_Block_Pack
10565 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
10567 -- Dispatch table slot processing, generate:
10570 S := Build_S (Loc, Decls);
10573 -- S := Ada.Tags.Get_Offset_Index
10574 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
10577 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
10580 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
10582 -- where Obj is the controlling formal parameter, S is the dispatch
10583 -- table slot number of the dispatching operation, P is the wrapped
10584 -- parameter block, D is the duration, M is the duration mode, C is
10585 -- the call kind and B is the call status.
10587 Params := New_List;
10589 Append_To (Params, New_Copy_Tree (Obj));
10590 Append_To (Params, New_Reference_To (S, Loc));
10591 Append_To (Params, Make_Attribute_Reference (Loc,
10592 Prefix => New_Reference_To (P, Loc),
10593 Attribute_Name => Name_Address));
10594 Append_To (Params, New_Reference_To (D, Loc));
10595 Append_To (Params, New_Reference_To (M, Loc));
10596 Append_To (Params, New_Reference_To (C, Loc));
10597 Append_To (Params, New_Reference_To (B, Loc));
10599 Append_To (Conc_Typ_Stmts,
10600 Make_Procedure_Call_Statement (Loc,
10603 Find_Prim_Op (Etype (Etype (Obj)),
10604 Name_uDisp_Timed_Select),
10606 Parameter_Associations =>
10610 -- if C = POK_Protected_Entry
10611 -- or else C = POK_Task_Entry
10613 -- Param1 := P.Param1;
10615 -- ParamN := P.ParamN;
10618 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
10620 -- Generate the if statement only when the packed parameters need
10621 -- explicit assignments to their corresponding actuals.
10623 if Present (Unpack) then
10624 Append_To (Conc_Typ_Stmts,
10625 Make_If_Statement (Loc,
10632 New_Reference_To (C, Loc),
10634 New_Reference_To (RTE (
10635 RE_POK_Protected_Entry), Loc)),
10639 New_Reference_To (C, Loc),
10641 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
10650 -- if C = POK_Procedure
10651 -- or else C = POK_Protected_Procedure
10652 -- or else C = POK_Task_Procedure
10654 -- <dispatching-call>
10656 -- <triggering-statements>
10658 -- <timed-statements>
10661 N_Stats := New_Copy_List_Tree (E_Stats);
10663 Prepend_To (N_Stats,
10664 Make_If_Statement (Loc,
10671 New_Reference_To (C, Loc),
10673 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
10679 New_Reference_To (C, Loc),
10681 New_Reference_To (RTE (
10682 RE_POK_Protected_Procedure), Loc)),
10686 New_Reference_To (C, Loc),
10688 New_Reference_To (RTE (
10689 RE_POK_Task_Procedure), Loc)))),
10692 New_List (E_Call)));
10694 Append_To (Conc_Typ_Stmts,
10695 Make_If_Statement (Loc,
10696 Condition => New_Reference_To (B, Loc),
10697 Then_Statements => N_Stats,
10698 Else_Statements => D_Stats));
10701 -- <dispatching-call>;
10702 -- <triggering-statements>
10704 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
10705 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
10708 -- if K = Ada.Tags.TK_Limited_Tagged then
10715 Make_If_Statement (Loc,
10719 New_Reference_To (K, Loc),
10721 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
10730 -- Skip assignments to temporaries created for in-out parameters.
10731 -- This makes unwarranted assumptions about the shape of the expanded
10732 -- tree for the call, and should be cleaned up ???
10734 Stmt := First (Stmts);
10735 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
10739 -- Do the assignment at this stage only because the evaluation
10740 -- of the expression must not occur before (see ACVC C97302A).
10742 Insert_Before (Stmt,
10743 Make_Assignment_Statement (Loc,
10744 Name => New_Reference_To (D, Loc),
10745 Expression => D_Conv));
10748 Params := Parameter_Associations (Call);
10750 -- For a protected type, we build a Timed_Protected_Entry_Call
10752 if Is_Protected_Type (Etype (Concval)) then
10754 -- Create a new call statement
10756 Param := First (Params);
10757 while Present (Param)
10758 and then not Is_RTE (Etype (Param), RE_Call_Modes)
10763 Dummy := Remove_Next (Next (Param));
10765 -- Remove garbage is following the Cancel_Param if present
10767 Dummy := Next (Param);
10769 -- Remove the mode of the Protected_Entry_Call call, then remove
10770 -- the Communication_Block of the Protected_Entry_Call call, and
10771 -- finally add Duration and a Delay_Mode parameter
10773 pragma Assert (Present (Param));
10774 Rewrite (Param, New_Reference_To (D, Loc));
10776 Rewrite (Dummy, New_Reference_To (M, Loc));
10778 -- Add a Boolean flag for successful entry call
10780 Append_To (Params, New_Reference_To (B, Loc));
10782 case Corresponding_Runtime_Package (Etype (Concval)) is
10783 when System_Tasking_Protected_Objects_Entries =>
10785 Make_Procedure_Call_Statement (Loc,
10788 (RTE (RE_Timed_Protected_Entry_Call), Loc),
10789 Parameter_Associations => Params));
10791 when System_Tasking_Protected_Objects_Single_Entry =>
10792 Param := First (Params);
10793 while Present (Param)
10795 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
10803 Make_Procedure_Call_Statement (Loc,
10804 Name => New_Reference_To (
10805 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
10806 Parameter_Associations => Params));
10809 raise Program_Error;
10812 -- For the task case, build a Timed_Task_Entry_Call
10815 -- Create a new call statement
10817 Append_To (Params, New_Reference_To (D, Loc));
10818 Append_To (Params, New_Reference_To (M, Loc));
10819 Append_To (Params, New_Reference_To (B, Loc));
10822 Make_Procedure_Call_Statement (Loc,
10824 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
10825 Parameter_Associations => Params));
10829 Make_Implicit_If_Statement (N,
10830 Condition => New_Reference_To (B, Loc),
10831 Then_Statements => E_Stats,
10832 Else_Statements => D_Stats));
10836 Make_Block_Statement (Loc,
10837 Declarations => Decls,
10838 Handled_Statement_Sequence =>
10839 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
10842 end Expand_N_Timed_Entry_Call;
10844 ----------------------------------------
10845 -- Expand_Protected_Body_Declarations --
10846 ----------------------------------------
10848 procedure Expand_Protected_Body_Declarations
10850 Spec_Id : Entity_Id)
10853 if No_Run_Time_Mode then
10854 Error_Msg_CRT ("protected body", N);
10857 elsif Expander_Active then
10859 -- Associate discriminals with the first subprogram or entry body to
10862 if Present (First_Protected_Operation (Declarations (N))) then
10863 Set_Discriminals (Parent (Spec_Id));
10866 end Expand_Protected_Body_Declarations;
10868 -------------------------
10869 -- External_Subprogram --
10870 -------------------------
10872 function External_Subprogram (E : Entity_Id) return Entity_Id is
10873 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10876 -- The internal and external subprograms follow each other on the entity
10877 -- chain. Note that previously private operations had no separate
10878 -- external subprogram. We now create one in all cases, because a
10879 -- private operation may actually appear in an external call, through
10880 -- a 'Access reference used for a callback.
10882 -- If the operation is a function that returns an anonymous access type,
10883 -- the corresponding itype appears before the operation, and must be
10886 -- This mechanism is fragile, there should be a real link between the
10887 -- two versions of the operation, but there is no place to put it ???
10889 if Is_Access_Type (Next_Entity (Subp)) then
10890 return Next_Entity (Next_Entity (Subp));
10892 return Next_Entity (Subp);
10894 end External_Subprogram;
10896 ------------------------------
10897 -- Extract_Dispatching_Call --
10898 ------------------------------
10900 procedure Extract_Dispatching_Call
10902 Call_Ent : out Entity_Id;
10903 Object : out Entity_Id;
10904 Actuals : out List_Id;
10905 Formals : out List_Id)
10907 Call_Nam : Node_Id;
10910 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10912 if Present (Original_Node (N)) then
10913 Call_Nam := Name (Original_Node (N));
10915 Call_Nam := Name (N);
10918 -- Retrieve the name of the dispatching procedure. It contains the
10919 -- dispatch table slot number.
10922 case Nkind (Call_Nam) is
10923 when N_Identifier =>
10926 when N_Selected_Component =>
10927 Call_Nam := Selector_Name (Call_Nam);
10930 raise Program_Error;
10935 Actuals := Parameter_Associations (N);
10936 Call_Ent := Entity (Call_Nam);
10937 Formals := Parameter_Specifications (Parent (Call_Ent));
10938 Object := First (Actuals);
10940 if Present (Original_Node (Object)) then
10941 Object := Original_Node (Object);
10943 end Extract_Dispatching_Call;
10945 -------------------
10946 -- Extract_Entry --
10947 -------------------
10949 procedure Extract_Entry
10951 Concval : out Node_Id;
10952 Ename : out Node_Id;
10953 Index : out Node_Id)
10955 Nam : constant Node_Id := Name (N);
10958 -- For a simple entry, the name is a selected component, with the
10959 -- prefix being the task value, and the selector being the entry.
10961 if Nkind (Nam) = N_Selected_Component then
10962 Concval := Prefix (Nam);
10963 Ename := Selector_Name (Nam);
10966 -- For a member of an entry family, the name is an indexed component
10967 -- where the prefix is a selected component, whose prefix in turn is
10968 -- the task value, and whose selector is the entry family. The single
10969 -- expression in the expressions list of the indexed component is the
10970 -- subscript for the family.
10972 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
10973 Concval := Prefix (Prefix (Nam));
10974 Ename := Selector_Name (Prefix (Nam));
10975 Index := First (Expressions (Nam));
10979 -------------------
10980 -- Family_Offset --
10981 -------------------
10983 function Family_Offset
10988 Cap : Boolean) return Node_Id
10994 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
10995 -- If one of the bounds is a reference to a discriminant, replace with
10996 -- corresponding discriminal of type. Within the body of a task retrieve
10997 -- the renamed discriminant by simple visibility, using its generated
10998 -- name. Within a protected object, find the original discriminant and
10999 -- replace it with the discriminal of the current protected operation.
11001 ------------------------------
11002 -- Convert_Discriminant_Ref --
11003 ------------------------------
11005 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11006 Loc : constant Source_Ptr := Sloc (Bound);
11011 if Is_Entity_Name (Bound)
11012 and then Ekind (Entity (Bound)) = E_Discriminant
11014 if Is_Task_Type (Ttyp)
11015 and then Has_Completion (Ttyp)
11017 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11018 Find_Direct_Name (B);
11020 elsif Is_Protected_Type (Ttyp) then
11021 D := First_Discriminant (Ttyp);
11022 while Chars (D) /= Chars (Entity (Bound)) loop
11023 Next_Discriminant (D);
11026 B := New_Reference_To (Discriminal (D), Loc);
11029 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11032 elsif Nkind (Bound) = N_Attribute_Reference then
11036 B := New_Copy_Tree (Bound);
11040 Make_Attribute_Reference (Loc,
11041 Attribute_Name => Name_Pos,
11042 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11043 Expressions => New_List (B));
11044 end Convert_Discriminant_Ref;
11046 -- Start of processing for Family_Offset
11049 Real_Hi := Convert_Discriminant_Ref (Hi);
11050 Real_Lo := Convert_Discriminant_Ref (Lo);
11053 if Is_Task_Type (Ttyp) then
11054 Ityp := RTE (RE_Task_Entry_Index);
11056 Ityp := RTE (RE_Protected_Entry_Index);
11060 Make_Attribute_Reference (Loc,
11061 Prefix => New_Reference_To (Ityp, Loc),
11062 Attribute_Name => Name_Min,
11063 Expressions => New_List (
11065 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11068 Make_Attribute_Reference (Loc,
11069 Prefix => New_Reference_To (Ityp, Loc),
11070 Attribute_Name => Name_Max,
11071 Expressions => New_List (
11073 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11076 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11083 function Family_Size
11088 Cap : Boolean) return Node_Id
11093 if Is_Task_Type (Ttyp) then
11094 Ityp := RTE (RE_Task_Entry_Index);
11096 Ityp := RTE (RE_Protected_Entry_Index);
11100 Make_Attribute_Reference (Loc,
11101 Prefix => New_Reference_To (Ityp, Loc),
11102 Attribute_Name => Name_Max,
11103 Expressions => New_List (
11106 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11108 Make_Integer_Literal (Loc, 1)),
11109 Make_Integer_Literal (Loc, 0)));
11112 -----------------------------------
11113 -- Find_Task_Or_Protected_Pragma --
11114 -----------------------------------
11116 function Find_Task_Or_Protected_Pragma
11118 P : Name_Id) return Node_Id
11123 N := First (Visible_Declarations (T));
11124 while Present (N) loop
11125 if Nkind (N) = N_Pragma then
11126 if Pragma_Name (N) = P then
11129 elsif P = Name_Priority
11130 and then Pragma_Name (N) = Name_Interrupt_Priority
11143 N := First (Private_Declarations (T));
11144 while Present (N) loop
11145 if Nkind (N) = N_Pragma then
11146 if Pragma_Name (N) = P then
11149 elsif P = Name_Priority
11150 and then Pragma_Name (N) = Name_Interrupt_Priority
11163 raise Program_Error;
11164 end Find_Task_Or_Protected_Pragma;
11166 -------------------------------
11167 -- First_Protected_Operation --
11168 -------------------------------
11170 function First_Protected_Operation (D : List_Id) return Node_Id is
11171 First_Op : Node_Id;
11174 First_Op := First (D);
11175 while Present (First_Op)
11176 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11182 end First_Protected_Operation;
11184 ---------------------------------------
11185 -- Install_Private_Data_Declarations --
11186 ---------------------------------------
11188 procedure Install_Private_Data_Declarations
11190 Spec_Id : Entity_Id;
11191 Conc_Typ : Entity_Id;
11192 Body_Nod : Node_Id;
11194 Barrier : Boolean := False;
11195 Family : Boolean := False)
11197 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11200 Insert_Node : Node_Id := Empty;
11201 Obj_Ent : Entity_Id;
11203 procedure Add (Decl : Node_Id);
11204 -- Add a single declaration after Insert_Node. If this is the first
11205 -- addition, Decl is added to the front of Decls and it becomes the
11208 function Replace_Bound (Bound : Node_Id) return Node_Id;
11209 -- The bounds of an entry index may depend on discriminants, create a
11210 -- reference to the corresponding prival. Otherwise return a duplicate
11211 -- of the original bound.
11217 procedure Add (Decl : Node_Id) is
11219 if No (Insert_Node) then
11220 Prepend_To (Decls, Decl);
11222 Insert_After (Insert_Node, Decl);
11225 Insert_Node := Decl;
11228 --------------------------
11229 -- Replace_Discriminant --
11230 --------------------------
11232 function Replace_Bound (Bound : Node_Id) return Node_Id is
11234 if Nkind (Bound) = N_Identifier
11235 and then Is_Discriminal (Entity (Bound))
11237 return Make_Identifier (Loc, Chars (Entity (Bound)));
11239 return Duplicate_Subexpr (Bound);
11243 -- Start of processing for Install_Private_Data_Declarations
11246 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11247 -- formal parameter _O, _object or _task depending on the context.
11249 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11251 -- Special processing of _O for barrier functions, protected entries
11258 (Ekind (Spec_Id) = E_Entry
11259 or else Ekind (Spec_Id) = E_Entry_Family))
11262 Conc_Rec : constant Entity_Id :=
11263 Corresponding_Record_Type (Conc_Typ);
11264 Typ_Id : constant Entity_Id :=
11265 Make_Defining_Identifier (Loc,
11266 New_External_Name (Chars (Conc_Rec), 'P'));
11269 -- type prot_typVP is access prot_typV;
11272 Make_Full_Type_Declaration (Loc,
11273 Defining_Identifier => Typ_Id,
11275 Make_Access_To_Object_Definition (Loc,
11276 Subtype_Indication =>
11277 New_Reference_To (Conc_Rec, Loc)));
11281 -- _object : prot_typVP := prot_typV (_O);
11284 Make_Object_Declaration (Loc,
11285 Defining_Identifier =>
11286 Make_Defining_Identifier (Loc, Name_uObject),
11287 Object_Definition => New_Reference_To (Typ_Id, Loc),
11289 Unchecked_Convert_To (Typ_Id,
11290 New_Reference_To (Obj_Ent, Loc)));
11293 -- Set the reference to the concurrent object
11295 Obj_Ent := Defining_Identifier (Decl);
11299 -- Step 2: Create the Protection object and build its declaration for
11300 -- any protected entry (family) of subprogram.
11302 if Is_Protected then
11304 Prot_Ent : constant Entity_Id :=
11305 Make_Defining_Identifier (Loc,
11306 New_Internal_Name ('R'));
11310 Set_Protection_Object (Spec_Id, Prot_Ent);
11312 -- Determine the proper protection type
11314 if Has_Attach_Handler (Conc_Typ)
11315 and then not Restricted_Profile
11317 Prot_Typ := RE_Static_Interrupt_Protection;
11319 elsif Has_Interrupt_Handler (Conc_Typ) then
11320 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11322 -- The type has explicit entries or generated primitive entry
11325 elsif Has_Entries (Conc_Typ)
11327 (Ada_Version >= Ada_05
11328 and then Present (Interface_List (Parent (Conc_Typ))))
11330 case Corresponding_Runtime_Package (Conc_Typ) is
11331 when System_Tasking_Protected_Objects_Entries =>
11332 Prot_Typ := RE_Protection_Entries;
11334 when System_Tasking_Protected_Objects_Single_Entry =>
11335 Prot_Typ := RE_Protection_Entry;
11338 raise Program_Error;
11342 Prot_Typ := RE_Protection;
11346 -- conc_typR : protection_typ renames _object._object;
11349 Make_Object_Renaming_Declaration (Loc,
11350 Defining_Identifier => Prot_Ent,
11352 New_Reference_To (RTE (Prot_Typ), Loc),
11354 Make_Selected_Component (Loc,
11356 New_Reference_To (Obj_Ent, Loc),
11358 Make_Identifier (Loc, Name_uObject)));
11363 -- Step 3: Add discriminant renamings (if any)
11365 if Has_Discriminants (Conc_Typ) then
11370 D := First_Discriminant (Conc_Typ);
11371 while Present (D) loop
11373 -- Adjust the source location
11375 Set_Sloc (Discriminal (D), Loc);
11378 -- discr_name : discr_typ renames _object.discr_name;
11380 -- discr_name : discr_typ renames _task.discr_name;
11383 Make_Object_Renaming_Declaration (Loc,
11384 Defining_Identifier => Discriminal (D),
11385 Subtype_Mark => New_Reference_To (Etype (D), Loc),
11387 Make_Selected_Component (Loc,
11388 Prefix => New_Reference_To (Obj_Ent, Loc),
11389 Selector_Name => Make_Identifier (Loc, Chars (D))));
11392 Next_Discriminant (D);
11397 -- Step 4: Add private component renamings (if any)
11399 if Is_Protected then
11400 Def := Protected_Definition (Parent (Conc_Typ));
11402 if Present (Private_Declarations (Def)) then
11405 Comp_Id : Entity_Id;
11406 Decl_Id : Entity_Id;
11409 Comp := First (Private_Declarations (Def));
11410 while Present (Comp) loop
11411 if Nkind (Comp) = N_Component_Declaration then
11412 Comp_Id := Defining_Identifier (Comp);
11414 Make_Defining_Identifier (Loc, Chars (Comp_Id));
11416 -- Minimal decoration
11418 if Ekind (Spec_Id) = E_Function then
11419 Set_Ekind (Decl_Id, E_Constant);
11421 Set_Ekind (Decl_Id, E_Variable);
11424 Set_Prival (Comp_Id, Decl_Id);
11425 Set_Prival_Link (Decl_Id, Comp_Id);
11426 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
11429 -- comp_name : comp_typ renames _object.comp_name;
11432 Make_Object_Renaming_Declaration (Loc,
11433 Defining_Identifier => Decl_Id,
11435 New_Reference_To (Etype (Comp_Id), Loc),
11437 Make_Selected_Component (Loc,
11439 New_Reference_To (Obj_Ent, Loc),
11441 Make_Identifier (Loc, Chars (Comp_Id))));
11451 -- Step 5: Add the declaration of the entry index and the associated
11452 -- type for barrier functions and entry families.
11454 if (Barrier and then Family)
11455 or else Ekind (Spec_Id) = E_Entry_Family
11458 E : constant Entity_Id := Index_Object (Spec_Id);
11459 Index : constant Entity_Id :=
11460 Defining_Identifier (
11461 Entry_Index_Specification (
11462 Entry_Body_Formal_Part (Body_Nod)));
11463 Index_Con : constant Entity_Id :=
11464 Make_Defining_Identifier (Loc, Chars (Index));
11466 Index_Typ : Entity_Id;
11470 -- Minimal decoration
11472 Set_Ekind (Index_Con, E_Constant);
11473 Set_Entry_Index_Constant (Index, Index_Con);
11474 Set_Discriminal_Link (Index_Con, Index);
11476 -- Retrieve the bounds of the entry family
11478 High := Type_High_Bound (Etype (Index));
11479 Low := Type_Low_Bound (Etype (Index));
11481 -- In the simple case the entry family is given by a subtype
11482 -- mark and the index constant has the same type.
11484 if Is_Entity_Name (Original_Node (
11485 Discrete_Subtype_Definition (Parent (Index))))
11487 Index_Typ := Etype (Index);
11489 -- Otherwise a new subtype declaration is required
11492 High := Replace_Bound (High);
11493 Low := Replace_Bound (Low);
11496 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
11499 -- subtype Jnn is <Etype of Index> range Low .. High;
11502 Make_Subtype_Declaration (Loc,
11503 Defining_Identifier => Index_Typ,
11504 Subtype_Indication =>
11505 Make_Subtype_Indication (Loc,
11507 New_Reference_To (Base_Type (Etype (Index)), Loc),
11509 Make_Range_Constraint (Loc,
11510 Range_Expression =>
11511 Make_Range (Loc, Low, High))));
11515 Set_Etype (Index_Con, Index_Typ);
11517 -- Create the object which designates the index:
11518 -- J : constant Jnn :=
11519 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
11521 -- where Jnn is the subtype created above or the original type of
11522 -- the index, _E is a formal of the protected body subprogram and
11523 -- <index expr> is the index of the first family member.
11526 Make_Object_Declaration (Loc,
11527 Defining_Identifier => Index_Con,
11528 Constant_Present => True,
11529 Object_Definition =>
11530 New_Reference_To (Index_Typ, Loc),
11533 Make_Attribute_Reference (Loc,
11535 New_Reference_To (Index_Typ, Loc),
11536 Attribute_Name => Name_Val,
11538 Expressions => New_List (
11542 Make_Op_Subtract (Loc,
11544 New_Reference_To (E, Loc),
11546 Entry_Index_Expression (Loc,
11547 Defining_Identifier (Body_Nod),
11551 Make_Attribute_Reference (Loc,
11553 New_Reference_To (Index_Typ, Loc),
11554 Attribute_Name => Name_Pos,
11555 Expressions => New_List (
11556 Make_Attribute_Reference (Loc,
11558 New_Reference_To (Index_Typ, Loc),
11559 Attribute_Name => Name_First)))))));
11563 end Install_Private_Data_Declarations;
11565 ---------------------------------
11566 -- Is_Potentially_Large_Family --
11567 ---------------------------------
11569 function Is_Potentially_Large_Family
11570 (Base_Index : Entity_Id;
11571 Conctyp : Entity_Id;
11573 Hi : Node_Id) return Boolean
11576 return Scope (Base_Index) = Standard_Standard
11577 and then Base_Index = Base_Type (Standard_Integer)
11578 and then Has_Discriminants (Conctyp)
11580 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
11582 (Denotes_Discriminant (Lo, True)
11583 or else Denotes_Discriminant (Hi, True));
11584 end Is_Potentially_Large_Family;
11586 -------------------------------------
11587 -- Is_Private_Primitive_Subprogram --
11588 -------------------------------------
11590 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
11593 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
11594 and then Is_Private_Primitive (Id);
11595 end Is_Private_Primitive_Subprogram;
11601 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
11602 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
11603 Formal : Entity_Id;
11606 Formal := First_Formal (Bod_Subp);
11607 while Present (Formal) loop
11609 -- Look for formal parameter _E
11611 if Chars (Formal) = Name_uE then
11615 Next_Formal (Formal);
11618 -- A protected body subprogram should always have the parameter in
11621 raise Program_Error;
11624 --------------------------------
11625 -- Make_Initialize_Protection --
11626 --------------------------------
11628 function Make_Initialize_Protection
11629 (Protect_Rec : Entity_Id) return List_Id
11631 Loc : constant Source_Ptr := Sloc (Protect_Rec);
11635 Ptyp : constant Node_Id :=
11636 Corresponding_Concurrent_Type (Protect_Rec);
11638 L : constant List_Id := New_List;
11639 Has_Entry : constant Boolean := Has_Entries (Ptyp);
11640 Restricted : constant Boolean := Restricted_Profile;
11643 -- We may need two calls to properly initialize the object, one to
11644 -- Initialize_Protection, and possibly one to Install_Handlers if we
11645 -- have a pragma Attach_Handler.
11647 -- Get protected declaration. In the case of a task type declaration,
11648 -- this is simply the parent of the protected type entity. In the single
11649 -- protected object declaration, this parent will be the implicit type,
11650 -- and we can find the corresponding single protected object declaration
11651 -- by searching forward in the declaration list in the tree.
11653 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
11654 -- of this type should have been removed during semantic analysis.
11656 Pdec := Parent (Ptyp);
11657 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
11658 N_Single_Protected_Declaration)
11663 -- Now we can find the object definition from this declaration
11665 Pdef := Protected_Definition (Pdec);
11667 -- Build the parameter list for the call. Note that _Init is the name
11668 -- of the formal for the object to be initialized, which is the task
11669 -- value record itself.
11673 -- Object parameter. This is a pointer to the object of type
11674 -- Protection used by the GNARL to control the protected object.
11677 Make_Attribute_Reference (Loc,
11679 Make_Selected_Component (Loc,
11680 Prefix => Make_Identifier (Loc, Name_uInit),
11681 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11682 Attribute_Name => Name_Unchecked_Access));
11684 -- Priority parameter. Set to Unspecified_Priority unless there is a
11685 -- priority pragma, in which case we take the value from the pragma,
11686 -- or there is an interrupt pragma and no priority pragma, and we
11687 -- set the ceiling to Interrupt_Priority'Last, an implementation-
11688 -- defined value, see D.3(10).
11691 and then Has_Priority_Pragma (Pdef)
11694 Prio : constant Node_Id :=
11697 (Pragma_Argument_Associations
11698 (Find_Task_Or_Protected_Pragma
11699 (Pdef, Name_Priority))));
11703 -- If priority is a static expression, then we can duplicate it
11704 -- with no problem and simply append it to the argument list.
11706 if Is_Static_Expression (Prio) then
11708 Duplicate_Subexpr_No_Checks (Prio));
11710 -- Otherwise, the priority may be a per-object expression, if it
11711 -- depends on a discriminant of the type. In this case, create
11712 -- local variable to capture the expression. Note that it is
11713 -- really necessary to create this variable explicitly. It might
11714 -- be thought that removing side effects would the appropriate
11715 -- approach, but that could generate declarations improperly
11716 -- placed in the enclosing scope.
11718 -- Note: Use System.Any_Priority as the expected type for the
11719 -- non-static priority expression, in case the expression has not
11720 -- been analyzed yet (as occurs for example with pragma
11721 -- Interrupt_Priority).
11725 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
11728 Make_Object_Declaration (Loc,
11729 Defining_Identifier => Temp,
11730 Object_Definition =>
11731 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
11732 Expression => Relocate_Node (Prio)));
11734 Append_To (Args, New_Occurrence_Of (Temp, Loc));
11738 -- When no priority is specified but an xx_Handler pragma is, we default
11739 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
11741 elsif Has_Interrupt_Handler (Ptyp)
11742 or else Has_Attach_Handler (Ptyp)
11745 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
11747 -- Normal case, no priority or xx_Handler specified, default priority
11751 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11754 -- Test for Compiler_Info parameter. This parameter allows entry body
11755 -- procedures and barrier functions to be called from the runtime. It
11756 -- is a pointer to the record generated by the compiler to represent
11757 -- the protected object.
11760 or else Has_Interrupt_Handler (Ptyp)
11761 or else Has_Attach_Handler (Ptyp)
11762 or else Has_Interfaces (Protect_Rec)
11765 Pkg_Id : constant RTU_Id :=
11766 Corresponding_Runtime_Package (Ptyp);
11767 Called_Subp : RE_Id;
11771 when System_Tasking_Protected_Objects_Entries =>
11772 Called_Subp := RE_Initialize_Protection_Entries;
11774 when System_Tasking_Protected_Objects =>
11775 Called_Subp := RE_Initialize_Protection;
11777 when System_Tasking_Protected_Objects_Single_Entry =>
11778 Called_Subp := RE_Initialize_Protection_Entry;
11781 raise Program_Error;
11784 if Has_Entry or else not Restricted then
11786 Make_Attribute_Reference (Loc,
11787 Prefix => Make_Identifier (Loc, Name_uInit),
11788 Attribute_Name => Name_Address));
11791 -- Entry_Bodies parameter. This is a pointer to an array of
11792 -- pointers to the entry body procedures and barrier functions of
11793 -- the object. If the protected type has no entries this object
11794 -- will not exist, in this case, pass a null.
11797 P_Arr := Entry_Bodies_Array (Ptyp);
11800 Make_Attribute_Reference (Loc,
11801 Prefix => New_Reference_To (P_Arr, Loc),
11802 Attribute_Name => Name_Unrestricted_Access));
11804 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
11806 -- Find index mapping function (clumsy but ok for now)
11808 while Ekind (P_Arr) /= E_Function loop
11809 Next_Entity (P_Arr);
11813 Make_Attribute_Reference (Loc,
11815 New_Reference_To (P_Arr, Loc),
11816 Attribute_Name => Name_Unrestricted_Access));
11818 -- Build_Entry_Names generation flag. When set to true, the
11819 -- runtime will allocate an array to hold the string names
11820 -- of protected entries.
11822 if not Restricted_Profile then
11823 if Entry_Names_OK then
11825 New_Reference_To (Standard_True, Loc));
11828 New_Reference_To (Standard_False, Loc));
11833 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
11834 Append_To (Args, Make_Null (Loc));
11836 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
11837 Append_To (Args, Make_Null (Loc));
11838 Append_To (Args, Make_Null (Loc));
11839 Append_To (Args, New_Reference_To (Standard_False, Loc));
11843 Make_Procedure_Call_Statement (Loc,
11844 Name => New_Reference_To (RTE (Called_Subp), Loc),
11845 Parameter_Associations => Args));
11849 Make_Procedure_Call_Statement (Loc,
11850 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
11851 Parameter_Associations => Args));
11854 if Has_Attach_Handler (Ptyp) then
11856 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
11857 -- make the following call:
11859 -- Install_Handlers (_object,
11860 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11862 -- or, in the case of Ravenscar:
11864 -- Install_Restricted_Handlers
11865 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11868 Args : constant List_Id := New_List;
11869 Table : constant List_Id := New_List;
11870 Ritem : Node_Id := First_Rep_Item (Ptyp);
11873 -- Build the Attach_Handler table argument
11875 while Present (Ritem) loop
11876 if Nkind (Ritem) = N_Pragma
11877 and then Pragma_Name (Ritem) = Name_Attach_Handler
11880 Handler : constant Node_Id :=
11881 First (Pragma_Argument_Associations (Ritem));
11883 Interrupt : constant Node_Id := Next (Handler);
11884 Expr : constant Node_Id := Expression (Interrupt);
11888 Make_Aggregate (Loc, Expressions => New_List (
11889 Unchecked_Convert_To
11890 (RTE (RE_System_Interrupt_Id), Expr),
11891 Make_Attribute_Reference (Loc,
11892 Prefix => Make_Selected_Component (Loc,
11893 Make_Identifier (Loc, Name_uInit),
11894 Duplicate_Subexpr_No_Checks
11895 (Expression (Handler))),
11896 Attribute_Name => Name_Access))));
11900 Next_Rep_Item (Ritem);
11903 -- Append the table argument we just built
11905 Append_To (Args, Make_Aggregate (Loc, Table));
11907 -- Append the Install_Handlers (or Install_Restricted_Handlers)
11908 -- call to the statements.
11911 -- Call a simplified version of Install_Handlers to be used
11912 -- when the Ravenscar restrictions are in effect
11913 -- (Install_Restricted_Handlers).
11916 Make_Procedure_Call_Statement (Loc,
11919 (RTE (RE_Install_Restricted_Handlers), Loc),
11920 Parameter_Associations => Args));
11923 -- First, prepends the _object argument
11926 Make_Attribute_Reference (Loc,
11928 Make_Selected_Component (Loc,
11929 Prefix => Make_Identifier (Loc, Name_uInit),
11930 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11931 Attribute_Name => Name_Unchecked_Access));
11933 -- Then, insert call to Install_Handlers
11936 Make_Procedure_Call_Statement (Loc,
11937 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
11938 Parameter_Associations => Args));
11944 end Make_Initialize_Protection;
11946 ---------------------------
11947 -- Make_Task_Create_Call --
11948 ---------------------------
11950 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
11951 Loc : constant Source_Ptr := Sloc (Task_Rec);
11961 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
11962 Tnam := Chars (Ttyp);
11964 -- Get task declaration. In the case of a task type declaration, this is
11965 -- simply the parent of the task type entity. In the single task
11966 -- declaration, this parent will be the implicit type, and we can find
11967 -- the corresponding single task declaration by searching forward in the
11968 -- declaration list in the tree.
11970 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
11971 -- this type should have been removed during semantic analysis.
11973 Tdec := Parent (Ttyp);
11974 while not Nkind_In (Tdec, N_Task_Type_Declaration,
11975 N_Single_Task_Declaration)
11980 -- Now we can find the task definition from this declaration
11982 Tdef := Task_Definition (Tdec);
11984 -- Build the parameter list for the call. Note that _Init is the name
11985 -- of the formal for the object to be initialized, which is the task
11986 -- value record itself.
11990 -- Priority parameter. Set to Unspecified_Priority unless there is a
11991 -- priority pragma, in which case we take the value from the pragma.
11993 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
11995 Make_Selected_Component (Loc,
11996 Prefix => Make_Identifier (Loc, Name_uInit),
11997 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12000 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12003 -- Optional Stack parameter
12005 if Restricted_Profile then
12007 -- If the stack has been preallocated by the expander then
12008 -- pass its address. Otherwise, pass a null address.
12010 if Preallocated_Stacks_On_Target then
12012 Make_Attribute_Reference (Loc,
12013 Prefix => Make_Selected_Component (Loc,
12014 Prefix => Make_Identifier (Loc, Name_uInit),
12016 Make_Identifier (Loc, Name_uStack)),
12017 Attribute_Name => Name_Address));
12021 New_Reference_To (RTE (RE_Null_Address), Loc));
12025 -- Size parameter. If no Storage_Size pragma is present, then
12026 -- the size is taken from the taskZ variable for the type, which
12027 -- is either Unspecified_Size, or has been reset by the use of
12028 -- a Storage_Size attribute definition clause. If a pragma is
12029 -- present, then the size is taken from the _Size field of the
12030 -- task value record, which was set from the pragma value.
12033 and then Has_Storage_Size_Pragma (Tdef)
12036 Make_Selected_Component (Loc,
12037 Prefix => Make_Identifier (Loc, Name_uInit),
12038 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12042 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12045 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12046 -- Task_Info pragma, in which case we take the value from the pragma.
12049 and then Has_Task_Info_Pragma (Tdef)
12052 Make_Selected_Component (Loc,
12053 Prefix => Make_Identifier (Loc, Name_uInit),
12054 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12058 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12061 if not Restricted_Profile then
12063 -- Deadline parameter. If no Relative_Deadline pragma is present,
12064 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12065 -- the deadline is taken from the _Relative_Deadline field of the
12066 -- task value record, which was set from the pragma value. Note that
12067 -- this parameter must not be generated for the restricted profiles
12068 -- since Ravenscar does not allow deadlines.
12070 -- Case where pragma Relative_Deadline applies: use given value
12072 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12074 Make_Selected_Component (Loc,
12075 Prefix => Make_Identifier (Loc, Name_uInit),
12077 Make_Identifier (Loc, Name_uRelative_Deadline)));
12079 -- No pragma Relative_Deadline apply to the task
12083 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12086 -- Number of entries. This is an expression of the form:
12088 -- n + _Init.a'Length + _Init.a'B'Length + ...
12090 -- where a,b... are the entry family names for the task definition
12093 Build_Entry_Count_Expression
12098 (Parent (Corresponding_Record_Type (Ttyp))))),
12100 Append_To (Args, Ecount);
12102 -- Master parameter. This is a reference to the _Master parameter of
12103 -- the initialization procedure, except in the case of the pragma
12104 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
12105 -- See comments in System.Tasking.Initialization.Init_RTS for the
12108 if Restriction_Active (No_Task_Hierarchy) = False then
12109 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12111 Append_To (Args, Make_Integer_Literal (Loc, 3));
12115 -- State parameter. This is a pointer to the task body procedure. The
12116 -- required value is obtained by taking 'Unrestricted_Access of the task
12117 -- body procedure and converting it (with an unchecked conversion) to
12118 -- the type required by the task kernel. For further details, see the
12119 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12120 -- than 'Address in order to avoid creating trampolines.
12123 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12124 Subp_Ptr_Typ : constant Node_Id :=
12125 Create_Itype (E_Access_Subprogram_Type, Tdec);
12126 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12129 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12130 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12132 -- Be sure to freeze a reference to the access-to-subprogram type,
12133 -- otherwise gigi will complain that it's in the wrong scope, because
12134 -- it's actually inside the init procedure for the record type that
12135 -- corresponds to the task type.
12137 -- This processing is causing a crash in the .NET/JVM back ends that
12138 -- is not yet understood, so skip it in these cases ???
12140 if VM_Target = No_VM then
12141 Set_Itype (Ref, Subp_Ptr_Typ);
12142 Append_Freeze_Action (Task_Rec, Ref);
12145 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12146 Make_Qualified_Expression (Loc,
12147 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12149 Make_Attribute_Reference (Loc,
12151 New_Occurrence_Of (Body_Proc, Loc),
12152 Attribute_Name => Name_Unrestricted_Access))));
12154 -- For the .NET/JVM cases revert to the original code below ???
12158 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12159 Make_Attribute_Reference (Loc,
12161 New_Occurrence_Of (Body_Proc, Loc),
12162 Attribute_Name => Name_Address)));
12166 -- Discriminants parameter. This is just the address of the task
12167 -- value record itself (which contains the discriminant values
12170 Make_Attribute_Reference (Loc,
12171 Prefix => Make_Identifier (Loc, Name_uInit),
12172 Attribute_Name => Name_Address));
12174 -- Elaborated parameter. This is an access to the elaboration Boolean
12177 Make_Attribute_Reference (Loc,
12178 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12179 Attribute_Name => Name_Unchecked_Access));
12181 -- Chain parameter. This is a reference to the _Chain parameter of
12182 -- the initialization procedure.
12184 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12186 -- Task name parameter. Take this from the _Task_Id parameter to the
12187 -- init call unless there is a Task_Name pragma, in which case we take
12188 -- the value from the pragma.
12191 and then Has_Task_Name_Pragma (Tdef)
12193 -- Copy expression in full, because it may be dynamic and have
12199 (Pragma_Argument_Associations
12200 (Find_Task_Or_Protected_Pragma
12201 (Tdef, Name_Task_Name))))));
12204 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12207 -- Created_Task parameter. This is the _Task_Id field of the task
12211 Make_Selected_Component (Loc,
12212 Prefix => Make_Identifier (Loc, Name_uInit),
12213 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12215 -- Build_Entry_Names generation flag. When set to true, the runtime
12216 -- will allocate an array to hold the string names of task entries.
12218 if not Restricted_Profile then
12219 if Has_Entries (Ttyp)
12220 and then Entry_Names_OK
12222 Append_To (Args, New_Reference_To (Standard_True, Loc));
12224 Append_To (Args, New_Reference_To (Standard_False, Loc));
12228 if Restricted_Profile then
12229 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12231 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12235 Make_Procedure_Call_Statement (Loc,
12237 Parameter_Associations => Args);
12238 end Make_Task_Create_Call;
12240 ------------------------------
12241 -- Next_Protected_Operation --
12242 ------------------------------
12244 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12248 Next_Op := Next (N);
12249 while Present (Next_Op)
12250 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12256 end Next_Protected_Operation;
12258 ---------------------
12259 -- Null_Statements --
12260 ---------------------
12262 function Null_Statements (Stats : List_Id) return Boolean is
12266 Stmt := First (Stats);
12267 while Nkind (Stmt) /= N_Empty
12268 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12270 (Nkind (Stmt) = N_Pragma
12271 and then (Pragma_Name (Stmt) = Name_Unreferenced
12273 Pragma_Name (Stmt) = Name_Unmodified
12275 Pragma_Name (Stmt) = Name_Warnings)))
12280 return Nkind (Stmt) = N_Empty;
12281 end Null_Statements;
12283 --------------------------
12284 -- Parameter_Block_Pack --
12285 --------------------------
12287 function Parameter_Block_Pack
12289 Blk_Typ : Entity_Id;
12293 Stmts : List_Id) return Node_Id
12295 Actual : Entity_Id;
12296 Expr : Node_Id := Empty;
12297 Formal : Entity_Id;
12298 Has_Param : Boolean := False;
12301 Temp_Asn : Node_Id;
12302 Temp_Nam : Node_Id;
12305 Actual := First (Actuals);
12306 Formal := Defining_Identifier (First (Formals));
12307 Params := New_List;
12309 while Present (Actual) loop
12310 if Is_By_Copy_Type (Etype (Actual)) then
12312 -- Jnn : aliased <formal-type>
12315 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
12318 Make_Object_Declaration (Loc,
12321 Defining_Identifier =>
12323 Object_Definition =>
12324 New_Reference_To (Etype (Formal), Loc)));
12326 if Ekind (Formal) /= E_Out_Parameter then
12332 New_Reference_To (Temp_Nam, Loc);
12334 Set_Assignment_OK (Temp_Asn);
12337 Make_Assignment_Statement (Loc,
12341 New_Copy_Tree (Actual)));
12345 -- Jnn'unchecked_access
12348 Make_Attribute_Reference (Loc,
12350 Name_Unchecked_Access,
12352 New_Reference_To (Temp_Nam, Loc)));
12356 -- The controlling parameter is omitted
12359 if not Is_Controlling_Actual (Actual) then
12361 Make_Reference (Loc, New_Copy_Tree (Actual)));
12367 Next_Actual (Actual);
12368 Next_Formal_With_Extras (Formal);
12372 Expr := Make_Aggregate (Loc, Params);
12377 -- J1'unchecked_access;
12378 -- <actual2>'reference;
12381 P := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
12384 Make_Object_Declaration (Loc,
12385 Defining_Identifier =>
12387 Object_Definition =>
12388 New_Reference_To (Blk_Typ, Loc),
12393 end Parameter_Block_Pack;
12395 ----------------------------
12396 -- Parameter_Block_Unpack --
12397 ----------------------------
12399 function Parameter_Block_Unpack
12403 Formals : List_Id) return List_Id
12405 Actual : Entity_Id;
12407 Formal : Entity_Id;
12408 Has_Asnmt : Boolean := False;
12409 Result : constant List_Id := New_List;
12412 Actual := First (Actuals);
12413 Formal := Defining_Identifier (First (Formals));
12414 while Present (Actual) loop
12415 if Is_By_Copy_Type (Etype (Actual))
12416 and then Ekind (Formal) /= E_In_Parameter
12419 -- <actual> := P.<formal>;
12422 Make_Assignment_Statement (Loc,
12426 Make_Explicit_Dereference (Loc,
12427 Make_Selected_Component (Loc,
12429 New_Reference_To (P, Loc),
12431 Make_Identifier (Loc, Chars (Formal)))));
12433 Set_Assignment_OK (Name (Asnmt));
12434 Append_To (Result, Asnmt);
12439 Next_Actual (Actual);
12440 Next_Formal_With_Extras (Formal);
12446 return New_List (Make_Null_Statement (Loc));
12448 end Parameter_Block_Unpack;
12450 ----------------------
12451 -- Set_Discriminals --
12452 ----------------------
12454 procedure Set_Discriminals (Dec : Node_Id) is
12457 D_Minal : Entity_Id;
12460 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
12461 Pdef := Defining_Identifier (Dec);
12463 if Has_Discriminants (Pdef) then
12464 D := First_Discriminant (Pdef);
12465 while Present (D) loop
12467 Make_Defining_Identifier (Sloc (D),
12468 Chars => New_External_Name (Chars (D), 'D'));
12470 Set_Ekind (D_Minal, E_Constant);
12471 Set_Etype (D_Minal, Etype (D));
12472 Set_Scope (D_Minal, Pdef);
12473 Set_Discriminal (D, D_Minal);
12474 Set_Discriminal_Link (D_Minal, D);
12476 Next_Discriminant (D);
12479 end Set_Discriminals;
12481 -----------------------
12482 -- Trivial_Accept_OK --
12483 -----------------------
12485 function Trivial_Accept_OK return Boolean is
12487 case Opt.Task_Dispatching_Policy is
12489 -- If we have the default task dispatching policy in effect, we can
12490 -- definitely do the optimization (one way of looking at this is to
12491 -- think of the formal definition of the default policy being allowed
12492 -- to run any task it likes after a rendezvous, so even if notionally
12493 -- a full rescheduling occurs, we can say that our dispatching policy
12494 -- (i.e. the default dispatching policy) reorders the queue to be the
12495 -- same as just before the call.
12500 -- FIFO_Within_Priorities certainly does not permit this
12501 -- optimization since the Rendezvous is a scheduling action that may
12502 -- require some other task to be run.
12507 -- For now, disallow the optimization for all other policies. This
12508 -- may be over-conservative, but it is certainly not incorrect.
12514 end Trivial_Accept_OK;