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;
2183 procedure Scan_Declarations (L : List_Id);
2184 -- Common processing for visible and private declarations
2185 -- of a protected type.
2187 procedure Scan_Declarations (L : List_Id) is
2189 Wrap_Decl : Node_Id;
2190 Wrap_Spec : Node_Id;
2198 while Present (Decl) loop
2201 if Nkind (Decl) = N_Entry_Declaration
2202 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2206 (Subp_Id => Defining_Identifier (Decl),
2208 Formals => Parameter_Specifications (Decl));
2210 elsif Nkind (Decl) = N_Subprogram_Declaration then
2213 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2216 Parameter_Specifications (Specification (Decl)));
2219 if Present (Wrap_Spec) then
2221 Make_Subprogram_Declaration (Loc,
2222 Specification => Wrap_Spec);
2224 Insert_After (N, Wrap_Decl);
2227 Analyze (Wrap_Decl);
2232 end Scan_Declarations;
2234 -- start of processing for Build_Wrapper_Specs
2237 if Is_Protected_Type (Typ) then
2238 Def := Protected_Definition (Parent (Typ));
2239 else pragma Assert (Is_Task_Type (Typ));
2240 Def := Task_Definition (Parent (Typ));
2243 Rec_Typ := Corresponding_Record_Type (Typ);
2245 -- Generate wrapper specs for a concurrent type which implements an
2246 -- interface. Operations in both the visible and private parts may
2247 -- implement progenitor operations.
2249 if Present (Interfaces (Rec_Typ))
2250 and then Present (Def)
2252 Scan_Declarations (Visible_Declarations (Def));
2253 Scan_Declarations (Private_Declarations (Def));
2255 end Build_Wrapper_Specs;
2257 ---------------------------
2258 -- Build_Find_Body_Index --
2259 ---------------------------
2261 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2262 Loc : constant Source_Ptr := Sloc (Typ);
2265 Has_F : Boolean := False;
2267 If_St : Node_Id := Empty;
2270 Decls : List_Id := New_List;
2273 Siz : Node_Id := Empty;
2275 procedure Add_If_Clause (Expr : Node_Id);
2276 -- Add test for range of current entry
2278 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2279 -- If a bound of an entry is given by a discriminant, retrieve the
2280 -- actual value of the discriminant from the enclosing object.
2286 procedure Add_If_Clause (Expr : Node_Id) is
2288 Stats : constant List_Id :=
2290 Make_Simple_Return_Statement (Loc,
2291 Expression => Make_Integer_Literal (Loc, Index + 1)));
2294 -- Index for current entry body
2298 -- Compute total length of entry queues so far
2306 Right_Opnd => Expr);
2311 Left_Opnd => Make_Identifier (Loc, Name_uE),
2314 -- Map entry queue indices in the range of the current family
2315 -- into the current index, that designates the entry body.
2319 Make_Implicit_If_Statement (Typ,
2321 Then_Statements => Stats,
2322 Elsif_Parts => New_List);
2328 Make_Elsif_Part (Loc,
2330 Then_Statements => Stats),
2331 Elsif_Parts (If_St));
2335 ------------------------------
2336 -- Convert_Discriminant_Ref --
2337 ------------------------------
2339 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2343 if Is_Entity_Name (Bound)
2344 and then Ekind (Entity (Bound)) = E_Discriminant
2347 Make_Selected_Component (Loc,
2349 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2350 Make_Explicit_Dereference (Loc,
2351 Make_Identifier (Loc, Name_uObject))),
2352 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2353 Set_Etype (B, Etype (Entity (Bound)));
2355 B := New_Copy_Tree (Bound);
2359 end Convert_Discriminant_Ref;
2361 -- Start of processing for Build_Find_Body_Index
2364 Spec := Build_Find_Body_Index_Spec (Typ);
2366 Ent := First_Entity (Typ);
2367 while Present (Ent) loop
2368 if Ekind (Ent) = E_Entry_Family then
2378 -- If the protected type has no entry families, there is a one-one
2379 -- correspondence between entry queue and entry body.
2382 Make_Simple_Return_Statement (Loc,
2383 Expression => Make_Identifier (Loc, Name_uE));
2386 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2389 -- if E <= l1 then return 1;
2390 -- elsif E <= l1 + l2 then return 2;
2395 Ent := First_Entity (Typ);
2397 Add_Object_Pointer (Loc, Typ, Decls);
2399 while Present (Ent) loop
2401 if Ekind (Ent) = E_Entry then
2402 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2404 elsif Ekind (Ent) = E_Entry_Family then
2406 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2407 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2408 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2409 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2418 Make_Simple_Return_Statement (Loc,
2419 Expression => Make_Integer_Literal (Loc, 1));
2421 elsif Nkind (Ret) = N_If_Statement then
2423 -- Ranges are in increasing order, so last one doesn't need guard
2426 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2429 Set_Else_Statements (Ret, Then_Statements (Nod));
2435 Make_Subprogram_Body (Loc,
2436 Specification => Spec,
2437 Declarations => Decls,
2438 Handled_Statement_Sequence =>
2439 Make_Handled_Sequence_Of_Statements (Loc,
2440 Statements => New_List (Ret)));
2441 end Build_Find_Body_Index;
2443 --------------------------------
2444 -- Build_Find_Body_Index_Spec --
2445 --------------------------------
2447 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2448 Loc : constant Source_Ptr := Sloc (Typ);
2449 Id : constant Entity_Id :=
2450 Make_Defining_Identifier (Loc,
2451 Chars => New_External_Name (Chars (Typ), 'F'));
2452 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2453 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2457 Make_Function_Specification (Loc,
2458 Defining_Unit_Name => Id,
2459 Parameter_Specifications => New_List (
2460 Make_Parameter_Specification (Loc,
2461 Defining_Identifier => Parm1,
2463 New_Reference_To (RTE (RE_Address), Loc)),
2465 Make_Parameter_Specification (Loc,
2466 Defining_Identifier => Parm2,
2468 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2469 Result_Definition => New_Occurrence_Of (
2470 RTE (RE_Protected_Entry_Index), Loc));
2471 end Build_Find_Body_Index_Spec;
2473 -------------------------
2474 -- Build_Master_Entity --
2475 -------------------------
2477 procedure Build_Master_Entity (E : Entity_Id) is
2478 Loc : constant Source_Ptr := Sloc (E);
2486 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2487 -- in internal scopes, unless present already.. Required for nested
2488 -- limited aggregates, where the expansion of task components may
2489 -- generate inner blocks. If the block is the rewriting of a call
2490 -- or the scope is an extended return statement this is valid master.
2491 -- The master in an extended return is only used within the return,
2492 -- and is subsequently overwritten in Move_Activation_Chain, but it
2495 if Ada_Version >= Ada_05 then
2496 while Is_Internal (S) loop
2497 if Nkind (Parent (S)) = N_Block_Statement
2499 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
2502 elsif Ekind (S) = E_Return_Statement then
2510 -- Nothing to do if we already built a master entity for this scope
2511 -- or if there is no task hierarchy.
2513 if Has_Master_Entity (S)
2514 or else Restriction_Active (No_Task_Hierarchy)
2519 -- Otherwise first build the master entity
2520 -- _Master : constant Master_Id := Current_Master.all;
2521 -- and insert it just before the current declaration
2524 Make_Object_Declaration (Loc,
2525 Defining_Identifier =>
2526 Make_Defining_Identifier (Loc, Name_uMaster),
2527 Constant_Present => True,
2528 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2530 Make_Explicit_Dereference (Loc,
2531 New_Reference_To (RTE (RE_Current_Master), Loc)));
2534 Insert_Before (P, Decl);
2537 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2538 -- non-internal scope selected above.
2540 if Ada_Version >= Ada_05 then
2541 Set_Has_Master_Entity (S);
2543 Set_Has_Master_Entity (Scope (E));
2546 -- Now mark the containing scope as a task master
2548 while Nkind (P) /= N_Compilation_Unit loop
2551 -- If we fall off the top, we are at the outer level, and the
2552 -- environment task is our effective master, so nothing to mark.
2555 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2557 Set_Is_Task_Master (P, True);
2560 elsif Nkind (Parent (P)) = N_Subunit then
2561 P := Corresponding_Stub (Parent (P));
2564 end Build_Master_Entity;
2566 -----------------------------------------
2567 -- Build_Private_Protected_Declaration --
2568 -----------------------------------------
2570 function Build_Private_Protected_Declaration
2571 (N : Node_Id) return Entity_Id
2573 Loc : constant Source_Ptr := Sloc (N);
2574 Body_Id : constant Entity_Id := Defining_Entity (N);
2579 Spec_Id : Entity_Id;
2582 Formal := First_Formal (Body_Id);
2584 -- The protected operation always has at least one formal, namely the
2585 -- object itself, but it is only placed in the parameter list if
2586 -- expansion is enabled.
2588 if Present (Formal) or else Expander_Active then
2589 Plist := Copy_Parameter_List (Body_Id);
2594 if Nkind (Specification (N)) = N_Procedure_Specification then
2596 Make_Procedure_Specification (Loc,
2597 Defining_Unit_Name =>
2598 Make_Defining_Identifier (Sloc (Body_Id),
2599 Chars => Chars (Body_Id)),
2600 Parameter_Specifications =>
2604 Make_Function_Specification (Loc,
2605 Defining_Unit_Name =>
2606 Make_Defining_Identifier (Sloc (Body_Id),
2607 Chars => Chars (Body_Id)),
2608 Parameter_Specifications => Plist,
2609 Result_Definition =>
2610 New_Occurrence_Of (Etype (Body_Id), Loc));
2613 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2614 Insert_Before (N, Decl);
2615 Spec_Id := Defining_Unit_Name (New_Spec);
2617 -- Indicate that the entity comes from source, to ensure that cross-
2618 -- reference information is properly generated. The body itself is
2619 -- rewritten during expansion, and the body entity will not appear in
2620 -- calls to the operation.
2622 Set_Comes_From_Source (Spec_Id, True);
2624 Set_Has_Completion (Spec_Id);
2625 Set_Convention (Spec_Id, Convention_Protected);
2627 end Build_Private_Protected_Declaration;
2629 ---------------------------
2630 -- Build_Protected_Entry --
2631 ---------------------------
2633 function Build_Protected_Entry
2636 Pid : Node_Id) return Node_Id
2638 Loc : constant Source_Ptr := Sloc (N);
2640 Decls : constant List_Id := Declarations (N);
2641 End_Lab : constant Node_Id :=
2642 End_Label (Handled_Statement_Sequence (N));
2643 End_Loc : constant Source_Ptr :=
2644 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2645 -- Used for the generated call to Complete_Entry_Body
2647 Han_Loc : Source_Ptr;
2648 -- Used for the exception handler, inserted at end of the body
2650 Op_Decls : constant List_Id := New_List;
2658 -- Set the source location on the exception handler only when debugging
2659 -- the expanded code (see Make_Implicit_Exception_Handler).
2661 if Debug_Generated_Code then
2664 -- Otherwise the inserted code should not be visible to the debugger
2667 Han_Loc := No_Location;
2671 Make_Defining_Identifier (Loc,
2672 Chars => Chars (Protected_Body_Subprogram (Ent)));
2674 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2676 -- Add the following declarations:
2677 -- type poVP is access poV;
2678 -- _object : poVP := poVP (_O);
2680 -- where _O is the formal parameter associated with the concurrent
2681 -- object. These declarations are needed for Complete_Entry_Body.
2683 Add_Object_Pointer (Loc, Pid, Op_Decls);
2685 -- Add renamings for all formals, the Protection object, discriminals,
2686 -- privals and the entry index constant for use by debugger.
2688 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2689 Debug_Private_Data_Declarations (Decls);
2691 case Corresponding_Runtime_Package (Pid) is
2692 when System_Tasking_Protected_Objects_Entries =>
2694 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2696 when System_Tasking_Protected_Objects_Single_Entry =>
2698 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2701 raise Program_Error;
2704 Op_Stats := New_List (
2705 Make_Block_Statement (Loc,
2706 Declarations => Decls,
2707 Handled_Statement_Sequence =>
2708 Handled_Statement_Sequence (N)),
2710 Make_Procedure_Call_Statement (End_Loc,
2712 Parameter_Associations => New_List (
2713 Make_Attribute_Reference (End_Loc,
2715 Make_Selected_Component (End_Loc,
2717 Make_Identifier (End_Loc, Name_uObject),
2719 Make_Identifier (End_Loc, Name_uObject)),
2720 Attribute_Name => Name_Unchecked_Access))));
2722 -- When exceptions can not be propagated, we never need to call
2723 -- Exception_Complete_Entry_Body
2725 if No_Exception_Handlers_Set then
2727 Make_Subprogram_Body (Loc,
2728 Specification => Espec,
2729 Declarations => Op_Decls,
2730 Handled_Statement_Sequence =>
2731 Make_Handled_Sequence_Of_Statements (Loc,
2732 Statements => Op_Stats,
2733 End_Label => End_Lab));
2736 Ohandle := Make_Others_Choice (Loc);
2737 Set_All_Others (Ohandle);
2739 case Corresponding_Runtime_Package (Pid) is
2740 when System_Tasking_Protected_Objects_Entries =>
2743 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2745 when System_Tasking_Protected_Objects_Single_Entry =>
2748 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2751 raise Program_Error;
2754 -- Create body of entry procedure. The renaming declarations are
2755 -- placed ahead of the block that contains the actual entry body.
2758 Make_Subprogram_Body (Loc,
2759 Specification => Espec,
2760 Declarations => Op_Decls,
2761 Handled_Statement_Sequence =>
2762 Make_Handled_Sequence_Of_Statements (Loc,
2763 Statements => Op_Stats,
2764 End_Label => End_Lab,
2765 Exception_Handlers => New_List (
2766 Make_Implicit_Exception_Handler (Han_Loc,
2767 Exception_Choices => New_List (Ohandle),
2769 Statements => New_List (
2770 Make_Procedure_Call_Statement (Han_Loc,
2772 Parameter_Associations => New_List (
2773 Make_Attribute_Reference (Han_Loc,
2775 Make_Selected_Component (Han_Loc,
2777 Make_Identifier (Han_Loc, Name_uObject),
2779 Make_Identifier (Han_Loc, Name_uObject)),
2780 Attribute_Name => Name_Unchecked_Access),
2782 Make_Function_Call (Han_Loc,
2783 Name => New_Reference_To (
2784 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2786 end Build_Protected_Entry;
2788 -----------------------------------------
2789 -- Build_Protected_Entry_Specification --
2790 -----------------------------------------
2792 function Build_Protected_Entry_Specification
2795 Ent_Id : Entity_Id) return Node_Id
2797 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2800 Set_Debug_Info_Needed (Def_Id);
2802 if Present (Ent_Id) then
2803 Append_Elmt (P, Accept_Address (Ent_Id));
2807 Make_Procedure_Specification (Loc,
2808 Defining_Unit_Name => Def_Id,
2809 Parameter_Specifications => New_List (
2810 Make_Parameter_Specification (Loc,
2811 Defining_Identifier =>
2812 Make_Defining_Identifier (Loc, Name_uO),
2814 New_Reference_To (RTE (RE_Address), Loc)),
2816 Make_Parameter_Specification (Loc,
2817 Defining_Identifier => P,
2819 New_Reference_To (RTE (RE_Address), Loc)),
2821 Make_Parameter_Specification (Loc,
2822 Defining_Identifier =>
2823 Make_Defining_Identifier (Loc, Name_uE),
2825 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2826 end Build_Protected_Entry_Specification;
2828 --------------------------
2829 -- Build_Protected_Spec --
2830 --------------------------
2832 function Build_Protected_Spec
2834 Obj_Type : Entity_Id;
2836 Unprotected : Boolean := False) return List_Id
2838 Loc : constant Source_Ptr := Sloc (N);
2841 New_Plist : List_Id;
2842 New_Param : Node_Id;
2845 New_Plist := New_List;
2847 Formal := First_Formal (Ident);
2848 while Present (Formal) loop
2850 Make_Parameter_Specification (Loc,
2851 Defining_Identifier =>
2852 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2853 In_Present => In_Present (Parent (Formal)),
2854 Out_Present => Out_Present (Parent (Formal)),
2855 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
2858 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2861 Append (New_Param, New_Plist);
2862 Next_Formal (Formal);
2865 -- If the subprogram is a procedure and the context is not an access
2866 -- to protected subprogram, the parameter is in-out. Otherwise it is
2870 Make_Parameter_Specification (Loc,
2871 Defining_Identifier =>
2872 Make_Defining_Identifier (Loc, Name_uObject),
2875 (Etype (Ident) = Standard_Void_Type
2876 and then not Is_RTE (Obj_Type, RE_Address)),
2878 New_Reference_To (Obj_Type, Loc));
2879 Set_Debug_Info_Needed (Defining_Identifier (Decl));
2880 Prepend_To (New_Plist, Decl);
2883 end Build_Protected_Spec;
2885 ---------------------------------------
2886 -- Build_Protected_Sub_Specification --
2887 ---------------------------------------
2889 function Build_Protected_Sub_Specification
2891 Prot_Typ : Entity_Id;
2892 Mode : Subprogram_Protection_Mode) return Node_Id
2894 Loc : constant Source_Ptr := Sloc (N);
2898 New_Plist : List_Id;
2901 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2902 (Dispatching_Mode => ' ',
2903 Protected_Mode => 'P',
2904 Unprotected_Mode => 'N');
2907 if Ekind (Defining_Unit_Name (Specification (N))) =
2910 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2915 Def_Id := Defining_Unit_Name (Specification (Decl));
2918 Build_Protected_Spec
2919 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
2920 Mode = Unprotected_Mode);
2922 Make_Defining_Identifier (Loc,
2923 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
2925 -- The unprotected operation carries the user code, and debugging
2926 -- information must be generated for it, even though this spec does
2927 -- not come from source. It is also convenient to allow gdb to step
2928 -- into the protected operation, even though it only contains lock/
2931 Set_Debug_Info_Needed (New_Id);
2933 -- If a pragma Eliminate applies to the source entity, the internal
2934 -- subprograms will be eliminated as well.
2936 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
2938 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2940 Make_Procedure_Specification (Loc,
2941 Defining_Unit_Name => New_Id,
2942 Parameter_Specifications => New_Plist);
2944 -- Create a new specification for the anonymous subprogram type
2948 Make_Function_Specification (Loc,
2949 Defining_Unit_Name => New_Id,
2950 Parameter_Specifications => New_Plist,
2951 Result_Definition =>
2952 Copy_Result_Type (Result_Definition (Specification (Decl))));
2954 Set_Return_Present (Defining_Unit_Name (New_Spec));
2958 end Build_Protected_Sub_Specification;
2960 -------------------------------------
2961 -- Build_Protected_Subprogram_Body --
2962 -------------------------------------
2964 function Build_Protected_Subprogram_Body
2967 N_Op_Spec : Node_Id) return Node_Id
2969 Loc : constant Source_Ptr := Sloc (N);
2971 P_Op_Spec : Node_Id;
2974 Unprot_Call : Node_Id;
2976 Lock_Name : Node_Id;
2977 Lock_Stmt : Node_Id;
2978 Service_Name : Node_Id;
2980 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2981 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2983 Object_Parm : Node_Id;
2986 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2987 -- Tell whether a given subprogram cannot raise an exception
2989 -----------------------
2990 -- Is_Exception_Safe --
2991 -----------------------
2993 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2995 function Has_Side_Effect (N : Node_Id) return Boolean;
2996 -- Return True whenever encountering a subprogram call or raise
2997 -- statement of any kind in the sequence of statements
2999 ---------------------
3000 -- Has_Side_Effect --
3001 ---------------------
3003 -- What is this doing buried two levels down in exp_ch9. It seems
3004 -- like a generally useful function, and indeed there may be code
3005 -- duplication going on here ???
3007 function Has_Side_Effect (N : Node_Id) return Boolean is
3011 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3012 -- Indicate whether N is a subprogram call or a raise statement
3014 ----------------------
3015 -- Is_Call_Or_Raise --
3016 ----------------------
3018 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3020 return Nkind_In (N, N_Procedure_Call_Statement,
3023 N_Raise_Constraint_Error,
3024 N_Raise_Program_Error,
3025 N_Raise_Storage_Error);
3026 end Is_Call_Or_Raise;
3028 -- Start of processing for Has_Side_Effect
3032 while Present (Stmt) loop
3033 if Is_Call_Or_Raise (Stmt) then
3037 -- An object declaration can also contain a function call
3038 -- or a raise statement
3040 if Nkind (Stmt) = N_Object_Declaration then
3041 Expr := Expression (Stmt);
3043 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3052 end Has_Side_Effect;
3054 -- Start of processing for Is_Exception_Safe
3057 -- If the checks handled by the back end are not disabled, we cannot
3058 -- ensure that no exception will be raised.
3060 if not Access_Checks_Suppressed (Empty)
3061 or else not Discriminant_Checks_Suppressed (Empty)
3062 or else not Range_Checks_Suppressed (Empty)
3063 or else not Index_Checks_Suppressed (Empty)
3064 or else Opt.Stack_Checking_Enabled
3069 if Has_Side_Effect (First (Declarations (Subprogram)))
3072 First (Statements (Handled_Statement_Sequence (Subprogram))))
3078 end Is_Exception_Safe;
3080 -- Start of processing for Build_Protected_Subprogram_Body
3083 Op_Spec := Specification (N);
3084 Exc_Safe := Is_Exception_Safe (N);
3087 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3089 -- Build a list of the formal parameters of the protected version of
3090 -- the subprogram to use as the actual parameters of the unprotected
3093 Uactuals := New_List;
3094 Pformal := First (Parameter_Specifications (P_Op_Spec));
3095 while Present (Pformal) loop
3097 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
3102 -- Make a call to the unprotected version of the subprogram built above
3103 -- for use by the protected version built below.
3105 if Nkind (Op_Spec) = N_Function_Specification then
3107 R := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
3109 Make_Object_Declaration (Loc,
3110 Defining_Identifier => R,
3111 Constant_Present => True,
3112 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3114 Make_Function_Call (Loc,
3115 Name => Make_Identifier (Loc,
3116 Chars (Defining_Unit_Name (N_Op_Spec))),
3117 Parameter_Associations => Uactuals));
3118 Return_Stmt := Make_Simple_Return_Statement (Loc,
3119 Expression => New_Reference_To (R, Loc));
3122 Unprot_Call := Make_Simple_Return_Statement (Loc,
3123 Expression => Make_Function_Call (Loc,
3125 Make_Identifier (Loc,
3126 Chars (Defining_Unit_Name (N_Op_Spec))),
3127 Parameter_Associations => Uactuals));
3132 Make_Procedure_Call_Statement (Loc,
3134 Make_Identifier (Loc,
3135 Chars (Defining_Unit_Name (N_Op_Spec))),
3136 Parameter_Associations => Uactuals);
3139 -- Wrap call in block that will be covered by an at_end handler
3141 if not Exc_Safe then
3142 Unprot_Call := Make_Block_Statement (Loc,
3143 Handled_Statement_Sequence =>
3144 Make_Handled_Sequence_Of_Statements (Loc,
3145 Statements => New_List (Unprot_Call)));
3148 -- Make the protected subprogram body. This locks the protected
3149 -- object and calls the unprotected version of the subprogram.
3151 case Corresponding_Runtime_Package (Pid) is
3152 when System_Tasking_Protected_Objects_Entries =>
3153 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3154 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3156 when System_Tasking_Protected_Objects_Single_Entry =>
3157 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3158 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3160 when System_Tasking_Protected_Objects =>
3161 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3162 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3165 raise Program_Error;
3169 Make_Attribute_Reference (Loc,
3171 Make_Selected_Component (Loc,
3173 Make_Identifier (Loc, Name_uObject),
3175 Make_Identifier (Loc, Name_uObject)),
3176 Attribute_Name => Name_Unchecked_Access);
3178 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3180 Parameter_Associations => New_List (Object_Parm));
3182 if Abort_Allowed then
3184 Make_Procedure_Call_Statement (Loc,
3185 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3186 Parameter_Associations => Empty_List),
3190 Stmts := New_List (Lock_Stmt);
3193 if not Exc_Safe then
3194 Append (Unprot_Call, Stmts);
3196 if Nkind (Op_Spec) = N_Function_Specification then
3198 Stmts := Empty_List;
3200 Append (Unprot_Call, Stmts);
3204 Make_Procedure_Call_Statement (Loc,
3205 Name => Service_Name,
3206 Parameter_Associations =>
3207 New_List (New_Copy_Tree (Object_Parm))),
3210 if Abort_Allowed then
3212 Make_Procedure_Call_Statement (Loc,
3213 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3214 Parameter_Associations => Empty_List),
3218 if Nkind (Op_Spec) = N_Function_Specification then
3219 Append (Return_Stmt, Stmts);
3220 Append (Make_Block_Statement (Loc,
3221 Declarations => New_List (Unprot_Call),
3222 Handled_Statement_Sequence =>
3223 Make_Handled_Sequence_Of_Statements (Loc,
3224 Statements => Stmts)), Pre_Stmts);
3230 Make_Subprogram_Body (Loc,
3231 Declarations => Empty_List,
3232 Specification => P_Op_Spec,
3233 Handled_Statement_Sequence =>
3234 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3236 if not Exc_Safe then
3237 Set_Is_Protected_Subprogram_Body (Sub_Body);
3241 end Build_Protected_Subprogram_Body;
3243 -------------------------------------
3244 -- Build_Protected_Subprogram_Call --
3245 -------------------------------------
3247 procedure Build_Protected_Subprogram_Call
3251 External : Boolean := True)
3253 Loc : constant Source_Ptr := Sloc (N);
3254 Sub : constant Entity_Id := Entity (Name);
3260 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3263 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3266 if Present (Parameter_Associations (N)) then
3267 Params := New_Copy_List_Tree (Parameter_Associations (N));
3272 -- If the type is an untagged derived type, convert to the root type,
3273 -- which is the one on which the operations are defined.
3275 if Nkind (Rec) = N_Unchecked_Type_Conversion
3276 and then not Is_Tagged_Type (Etype (Rec))
3277 and then Is_Derived_Type (Etype (Rec))
3279 Set_Etype (Rec, Root_Type (Etype (Rec)));
3280 Set_Subtype_Mark (Rec,
3281 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3284 Prepend (Rec, Params);
3286 if Ekind (Sub) = E_Procedure then
3288 Make_Procedure_Call_Statement (Loc,
3290 Parameter_Associations => Params));
3293 pragma Assert (Ekind (Sub) = E_Function);
3295 Make_Function_Call (Loc,
3297 Parameter_Associations => Params));
3301 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3302 and then Is_Entity_Name (Expression (Rec))
3303 and then Is_Shared_Passive (Entity (Expression (Rec)))
3305 Add_Shared_Var_Lock_Procs (N);
3307 end Build_Protected_Subprogram_Call;
3309 -------------------------
3310 -- Build_Selected_Name --
3311 -------------------------
3313 function Build_Selected_Name
3314 (Prefix : Entity_Id;
3315 Selector : Entity_Id;
3316 Append_Char : Character := ' ') return Name_Id
3318 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3319 Select_Len : Natural;
3322 Get_Name_String (Chars (Selector));
3323 Select_Len := Name_Len;
3324 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3325 Get_Name_String (Chars (Prefix));
3327 -- If scope is anonymous type, discard suffix to recover name of
3328 -- single protected object. Otherwise use protected type name.
3330 if Name_Buffer (Name_Len) = 'T' then
3331 Name_Len := Name_Len - 1;
3334 Add_Str_To_Name_Buffer ("__");
3335 for J in 1 .. Select_Len loop
3336 Add_Char_To_Name_Buffer (Select_Buffer (J));
3339 -- Now add the Append_Char if specified. The encoding to follow
3340 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3341 -- then the entity is associated to a protected type subprogram.
3342 -- Otherwise, it is a protected type entry. For each case, the
3343 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3345 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3347 if Append_Char /= ' ' then
3348 if Append_Char = 'P' or Append_Char = 'N' then
3349 Add_Char_To_Name_Buffer (Append_Char);
3352 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3353 return New_External_Name (Name_Find, ' ', -1);
3358 end Build_Selected_Name;
3360 -----------------------------
3361 -- Build_Simple_Entry_Call --
3362 -----------------------------
3364 -- A task entry call is converted to a call to Call_Simple
3367 -- P : parms := (parm, parm, parm);
3369 -- Call_Simple (acceptor-task, entry-index, P'Address);
3375 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3376 -- the parameters, and the constructed aggregate value contains either the
3377 -- parameters or, in the case of non-elementary types, references to these
3378 -- parameters. Then the address of this aggregate is passed to the runtime
3379 -- routine, along with the task id value and the task entry index value.
3380 -- Pnn is only required if parameters are present.
3382 -- The assignments after the call are present only in the case of in-out
3383 -- or out parameters for elementary types, and are used to assign back the
3384 -- resulting values of such parameters.
3386 -- Note: the reason that we insert a block here is that in the context
3387 -- of selects, conditional entry calls etc. the entry call statement
3388 -- appears on its own, not as an element of a list.
3390 -- A protected entry call is converted to a Protected_Entry_Call:
3393 -- P : E1_Params := (param, param, param);
3395 -- Bnn : Communications_Block;
3398 -- P : E1_Params := (param, param, param);
3399 -- Bnn : Communications_Block;
3402 -- Protected_Entry_Call (
3403 -- Object => po._object'Access,
3404 -- E => <entry index>;
3405 -- Uninterpreted_Data => P'Address;
3406 -- Mode => Simple_Call;
3413 procedure Build_Simple_Entry_Call
3422 -- If call has been inlined, nothing left to do
3424 if Nkind (N) = N_Block_Statement then
3428 -- Convert entry call to Call_Simple call
3431 Loc : constant Source_Ptr := Sloc (N);
3432 Parms : constant List_Id := Parameter_Associations (N);
3433 Stats : constant List_Id := New_List;
3436 Comm_Name : Entity_Id;
3440 Ent_Acc : Entity_Id;
3442 Iface_Tag : Entity_Id;
3443 Iface_Typ : Entity_Id;
3456 -- Simple entry and entry family cases merge here
3458 Ent := Entity (Ename);
3459 Ent_Acc := Entry_Parameters_Type (Ent);
3460 Conctyp := Etype (Concval);
3462 -- If prefix is an access type, dereference to obtain the task type
3464 if Is_Access_Type (Conctyp) then
3465 Conctyp := Designated_Type (Conctyp);
3468 -- Special case for protected subprogram calls
3470 if Is_Protected_Type (Conctyp)
3471 and then Is_Subprogram (Entity (Ename))
3473 if not Is_Eliminated (Entity (Ename)) then
3474 Build_Protected_Subprogram_Call
3475 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3482 -- First parameter is the Task_Id value from the task value or the
3483 -- Object from the protected object value, obtained by selecting
3484 -- the _Task_Id or _Object from the result of doing an unchecked
3485 -- conversion to convert the value to the corresponding record type.
3487 if Nkind (Concval) = N_Function_Call
3488 and then Is_Task_Type (Conctyp)
3489 and then Ada_Version >= Ada_05
3492 Obj : constant Entity_Id :=
3493 Make_Defining_Identifier (Loc, New_Internal_Name ('F'));
3498 Make_Object_Declaration (Loc,
3499 Defining_Identifier => Obj,
3500 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3501 Expression => Relocate_Node (Concval));
3502 Set_Etype (Obj, Conctyp);
3503 Decls := New_List (Decl);
3504 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3511 Parm1 := Concurrent_Ref (Concval);
3513 -- Second parameter is the entry index, computed by the routine
3514 -- provided for this purpose. The value of this expression is
3515 -- assigned to an intermediate variable to assure that any entry
3516 -- family index expressions are evaluated before the entry
3520 or else Restriction_Active (No_Entry_Queue) = False
3521 or else not Is_Protected_Type (Conctyp)
3522 or else Number_Entries (Conctyp) > 1
3523 or else (Has_Attach_Handler (Conctyp)
3524 and then not Restricted_Profile)
3526 X := Make_Defining_Identifier (Loc, Name_uX);
3529 Make_Object_Declaration (Loc,
3530 Defining_Identifier => X,
3531 Object_Definition =>
3532 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3533 Expression => Actual_Index_Expression (
3534 Loc, Entity (Ename), Index, Concval));
3536 Append_To (Decls, Xdecl);
3537 Parm2 := New_Reference_To (X, Loc);
3544 -- The third parameter is the packaged parameters. If there are
3545 -- none, then it is just the null address, since nothing is passed.
3548 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3551 -- Case of parameters present, where third argument is the address
3552 -- of a packaged record containing the required parameter values.
3555 -- First build a list of parameter values, which are references to
3556 -- objects of the parameter types.
3560 Actual := First_Actual (N);
3561 Formal := First_Formal (Ent);
3563 while Present (Actual) loop
3565 -- If it is a by_copy_type, copy it to a new variable. The
3566 -- packaged record has a field that points to this variable.
3568 if Is_By_Copy_Type (Etype (Actual)) then
3570 Make_Object_Declaration (Loc,
3571 Defining_Identifier =>
3572 Make_Defining_Identifier (Loc,
3573 Chars => New_Internal_Name ('J')),
3574 Aliased_Present => True,
3575 Object_Definition =>
3576 New_Reference_To (Etype (Formal), Loc));
3578 -- Mark the object as not needing initialization since the
3579 -- initialization is performed separately, avoiding errors
3580 -- on cases such as formals of null-excluding access types.
3582 Set_No_Initialization (N_Node);
3584 -- We must make an assignment statement separate for the
3585 -- case of limited type. We cannot assign it unless the
3586 -- Assignment_OK flag is set first. An out formal of an
3587 -- access type must also be initialized from the actual,
3588 -- as stated in RM 6.4.1 (13).
3590 if Ekind (Formal) /= E_Out_Parameter
3591 or else Is_Access_Type (Etype (Formal))
3594 New_Reference_To (Defining_Identifier (N_Node), Loc);
3595 Set_Assignment_OK (N_Var);
3597 Make_Assignment_Statement (Loc,
3599 Expression => Relocate_Node (Actual)));
3602 Append (N_Node, Decls);
3605 Make_Attribute_Reference (Loc,
3606 Attribute_Name => Name_Unchecked_Access,
3608 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3610 -- Interface class-wide formal
3612 if Ada_Version >= Ada_05
3613 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3614 and then Is_Interface (Etype (Formal))
3616 Iface_Typ := Etype (Etype (Formal));
3619 -- formal_iface_type! (actual.iface_tag)'reference
3622 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3623 pragma Assert (Present (Iface_Tag));
3626 Make_Reference (Loc,
3627 Unchecked_Convert_To (Iface_Typ,
3628 Make_Selected_Component (Loc,
3630 Relocate_Node (Actual),
3632 New_Reference_To (Iface_Tag, Loc)))));
3638 Make_Reference (Loc, Relocate_Node (Actual)));
3642 Next_Actual (Actual);
3643 Next_Formal_With_Extras (Formal);
3646 -- Now build the declaration of parameters initialized with the
3647 -- aggregate containing this constructed parameter list.
3649 P := Make_Defining_Identifier (Loc, Name_uP);
3652 Make_Object_Declaration (Loc,
3653 Defining_Identifier => P,
3654 Object_Definition =>
3655 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3657 Make_Aggregate (Loc, Expressions => Plist));
3660 Make_Attribute_Reference (Loc,
3661 Prefix => New_Reference_To (P, Loc),
3662 Attribute_Name => Name_Address);
3664 Append (Pdecl, Decls);
3667 -- Now we can create the call, case of protected type
3669 if Is_Protected_Type (Conctyp) then
3670 case Corresponding_Runtime_Package (Conctyp) is
3671 when System_Tasking_Protected_Objects_Entries =>
3673 -- Change the type of the index declaration
3675 Set_Object_Definition (Xdecl,
3676 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3678 -- Some additional declarations for protected entry calls
3684 -- Bnn : Communications_Block;
3687 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3690 Make_Object_Declaration (Loc,
3691 Defining_Identifier => Comm_Name,
3692 Object_Definition =>
3693 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3695 -- Some additional statements for protected entry calls
3697 -- Protected_Entry_Call (
3698 -- Object => po._object'Access,
3699 -- E => <entry index>;
3700 -- Uninterpreted_Data => P'Address;
3701 -- Mode => Simple_Call;
3705 Make_Procedure_Call_Statement (Loc,
3707 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3709 Parameter_Associations => New_List (
3710 Make_Attribute_Reference (Loc,
3711 Attribute_Name => Name_Unchecked_Access,
3715 New_Reference_To (RTE (RE_Simple_Call), Loc),
3716 New_Occurrence_Of (Comm_Name, Loc)));
3718 when System_Tasking_Protected_Objects_Single_Entry =>
3719 -- Protected_Single_Entry_Call (
3720 -- Object => po._object'Access,
3721 -- Uninterpreted_Data => P'Address;
3722 -- Mode => Simple_Call);
3725 Make_Procedure_Call_Statement (Loc,
3726 Name => New_Reference_To (
3727 RTE (RE_Protected_Single_Entry_Call), Loc),
3729 Parameter_Associations => New_List (
3730 Make_Attribute_Reference (Loc,
3731 Attribute_Name => Name_Unchecked_Access,
3734 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3737 raise Program_Error;
3740 -- Case of task type
3744 Make_Procedure_Call_Statement (Loc,
3745 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3746 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3750 Append_To (Stats, Call);
3752 -- If there are out or in/out parameters by copy add assignment
3753 -- statements for the result values.
3755 if Present (Parms) then
3756 Actual := First_Actual (N);
3757 Formal := First_Formal (Ent);
3759 Set_Assignment_OK (Actual);
3760 while Present (Actual) loop
3761 if Is_By_Copy_Type (Etype (Actual))
3762 and then Ekind (Formal) /= E_In_Parameter
3765 Make_Assignment_Statement (Loc,
3766 Name => New_Copy (Actual),
3768 Make_Explicit_Dereference (Loc,
3769 Make_Selected_Component (Loc,
3770 Prefix => New_Reference_To (P, Loc),
3772 Make_Identifier (Loc, Chars (Formal)))));
3774 -- In all cases (including limited private types) we want
3775 -- the assignment to be valid.
3777 Set_Assignment_OK (Name (N_Node));
3779 -- If the call is the triggering alternative in an
3780 -- asynchronous select, or the entry_call alternative of a
3781 -- conditional entry call, the assignments for in-out
3782 -- parameters are incorporated into the statement list that
3783 -- follows, so that there are executed only if the entry
3786 if (Nkind (Parent (N)) = N_Triggering_Alternative
3787 and then N = Triggering_Statement (Parent (N)))
3789 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3790 and then N = Entry_Call_Statement (Parent (N)))
3792 if No (Statements (Parent (N))) then
3793 Set_Statements (Parent (N), New_List);
3796 Prepend (N_Node, Statements (Parent (N)));
3799 Insert_After (Call, N_Node);
3803 Next_Actual (Actual);
3804 Next_Formal_With_Extras (Formal);
3808 -- Finally, create block and analyze it
3811 Make_Block_Statement (Loc,
3812 Declarations => Decls,
3813 Handled_Statement_Sequence =>
3814 Make_Handled_Sequence_Of_Statements (Loc,
3815 Statements => Stats)));
3819 end Build_Simple_Entry_Call;
3821 --------------------------------
3822 -- Build_Task_Activation_Call --
3823 --------------------------------
3825 procedure Build_Task_Activation_Call (N : Node_Id) is
3826 Loc : constant Source_Ptr := Sloc (N);
3833 -- Get the activation chain entity. Except in the case of a package
3834 -- body, this is in the node that was passed. For a package body, we
3835 -- have to find the corresponding package declaration node.
3837 if Nkind (N) = N_Package_Body then
3838 P := Corresponding_Spec (N);
3841 exit when Nkind (P) = N_Package_Declaration;
3844 Chain := Activation_Chain_Entity (P);
3847 Chain := Activation_Chain_Entity (N);
3850 if Present (Chain) then
3851 if Restricted_Profile then
3852 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3854 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3858 Make_Procedure_Call_Statement (Loc,
3860 Parameter_Associations =>
3861 New_List (Make_Attribute_Reference (Loc,
3862 Prefix => New_Occurrence_Of (Chain, Loc),
3863 Attribute_Name => Name_Unchecked_Access)));
3865 if Nkind (N) = N_Package_Declaration then
3866 if Present (Corresponding_Body (N)) then
3869 elsif Present (Private_Declarations (Specification (N))) then
3870 Append (Call, Private_Declarations (Specification (N)));
3873 Append (Call, Visible_Declarations (Specification (N)));
3877 if Present (Handled_Statement_Sequence (N)) then
3879 -- The call goes at the start of the statement sequence
3880 -- after the start of exception range label if one is present.
3886 Stm := First (Statements (Handled_Statement_Sequence (N)));
3888 -- A special case, skip exception range label if one is
3889 -- present (from front end zcx processing).
3891 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3895 -- Another special case, if the first statement is a block
3896 -- from optimization of a local raise to a goto, then the
3897 -- call goes inside this block.
3899 if Nkind (Stm) = N_Block_Statement
3900 and then Exception_Junk (Stm)
3903 First (Statements (Handled_Statement_Sequence (Stm)));
3906 -- Insertion point is after any exception label pushes,
3907 -- since we want it covered by any local handlers.
3909 while Nkind (Stm) in N_Push_xxx_Label loop
3913 -- Now we have the proper insertion point
3915 Insert_Before (Stm, Call);
3919 Set_Handled_Statement_Sequence (N,
3920 Make_Handled_Sequence_Of_Statements (Loc,
3921 Statements => New_List (Call)));
3926 Check_Task_Activation (N);
3928 end Build_Task_Activation_Call;
3930 -------------------------------
3931 -- Build_Task_Allocate_Block --
3932 -------------------------------
3934 procedure Build_Task_Allocate_Block
3939 T : constant Entity_Id := Entity (Expression (N));
3940 Init : constant Entity_Id := Base_Init_Proc (T);
3941 Loc : constant Source_Ptr := Sloc (N);
3942 Chain : constant Entity_Id :=
3943 Make_Defining_Identifier (Loc, Name_uChain);
3949 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3952 Make_Block_Statement (Loc,
3953 Identifier => New_Reference_To (Blkent, Loc),
3954 Declarations => New_List (
3956 -- _Chain : Activation_Chain;
3958 Make_Object_Declaration (Loc,
3959 Defining_Identifier => Chain,
3960 Aliased_Present => True,
3961 Object_Definition =>
3962 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3964 Handled_Statement_Sequence =>
3965 Make_Handled_Sequence_Of_Statements (Loc,
3967 Statements => New_List (
3971 Make_Procedure_Call_Statement (Loc,
3972 Name => New_Reference_To (Init, Loc),
3973 Parameter_Associations => Args),
3975 -- Activate_Tasks (_Chain);
3977 Make_Procedure_Call_Statement (Loc,
3978 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3979 Parameter_Associations => New_List (
3980 Make_Attribute_Reference (Loc,
3981 Prefix => New_Reference_To (Chain, Loc),
3982 Attribute_Name => Name_Unchecked_Access))))),
3984 Has_Created_Identifier => True,
3985 Is_Task_Allocation_Block => True);
3988 Make_Implicit_Label_Declaration (Loc,
3989 Defining_Identifier => Blkent,
3990 Label_Construct => Block));
3992 Append_To (Actions, Block);
3994 Set_Activation_Chain_Entity (Block, Chain);
3995 end Build_Task_Allocate_Block;
3997 -----------------------------------------------
3998 -- Build_Task_Allocate_Block_With_Init_Stmts --
3999 -----------------------------------------------
4001 procedure Build_Task_Allocate_Block_With_Init_Stmts
4004 Init_Stmts : List_Id)
4006 Loc : constant Source_Ptr := Sloc (N);
4007 Chain : constant Entity_Id :=
4008 Make_Defining_Identifier (Loc, Name_uChain);
4013 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4015 Append_To (Init_Stmts,
4016 Make_Procedure_Call_Statement (Loc,
4017 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4018 Parameter_Associations => New_List (
4019 Make_Attribute_Reference (Loc,
4020 Prefix => New_Reference_To (Chain, Loc),
4021 Attribute_Name => Name_Unchecked_Access))));
4024 Make_Block_Statement (Loc,
4025 Identifier => New_Reference_To (Blkent, Loc),
4026 Declarations => New_List (
4028 -- _Chain : Activation_Chain;
4030 Make_Object_Declaration (Loc,
4031 Defining_Identifier => Chain,
4032 Aliased_Present => True,
4033 Object_Definition =>
4034 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4036 Handled_Statement_Sequence =>
4037 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4039 Has_Created_Identifier => True,
4040 Is_Task_Allocation_Block => True);
4043 Make_Implicit_Label_Declaration (Loc,
4044 Defining_Identifier => Blkent,
4045 Label_Construct => Block));
4047 Append_To (Actions, Block);
4049 Set_Activation_Chain_Entity (Block, Chain);
4050 end Build_Task_Allocate_Block_With_Init_Stmts;
4052 -----------------------------------
4053 -- Build_Task_Proc_Specification --
4054 -----------------------------------
4056 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4057 Loc : constant Source_Ptr := Sloc (T);
4058 Spec_Id : Entity_Id;
4061 -- Case of explicit task type, suffix TB
4063 if Comes_From_Source (T) then
4065 Make_Defining_Identifier (Loc,
4066 Chars => New_External_Name (Chars (T), "TB"));
4068 -- Case of anonymous task type, suffix B
4072 Make_Defining_Identifier (Loc,
4073 Chars => New_External_Name (Chars (T), 'B'));
4076 Set_Is_Internal (Spec_Id);
4078 -- Associate the procedure with the task, if this is the declaration
4079 -- (and not the body) of the procedure.
4081 if No (Task_Body_Procedure (T)) then
4082 Set_Task_Body_Procedure (T, Spec_Id);
4086 Make_Procedure_Specification (Loc,
4087 Defining_Unit_Name => Spec_Id,
4088 Parameter_Specifications => New_List (
4089 Make_Parameter_Specification (Loc,
4090 Defining_Identifier =>
4091 Make_Defining_Identifier (Loc, Name_uTask),
4093 Make_Access_Definition (Loc,
4095 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4096 end Build_Task_Proc_Specification;
4098 ---------------------------------------
4099 -- Build_Unprotected_Subprogram_Body --
4100 ---------------------------------------
4102 function Build_Unprotected_Subprogram_Body
4104 Pid : Node_Id) return Node_Id
4106 Decls : constant List_Id := Declarations (N);
4109 -- Add renamings for the Protection object, discriminals, privals and
4110 -- the entry index constant for use by debugger.
4112 Debug_Private_Data_Declarations (Decls);
4114 -- Make an unprotected version of the subprogram for use within the same
4115 -- object, with a new name and an additional parameter representing the
4119 Make_Subprogram_Body (Sloc (N),
4121 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4122 Declarations => Decls,
4123 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4124 end Build_Unprotected_Subprogram_Body;
4126 ----------------------------
4127 -- Collect_Entry_Families --
4128 ----------------------------
4130 procedure Collect_Entry_Families
4133 Current_Node : in out Node_Id;
4134 Conctyp : Entity_Id)
4137 Efam_Decl : Node_Id;
4138 Efam_Type : Entity_Id;
4141 Efam := First_Entity (Conctyp);
4142 while Present (Efam) loop
4143 if Ekind (Efam) = E_Entry_Family then
4145 Make_Defining_Identifier (Loc,
4146 Chars => New_Internal_Name ('F'));
4151 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4153 Bas_Decl : Node_Id := Empty;
4158 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4160 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4162 Make_Defining_Identifier (Loc,
4163 Chars => New_Internal_Name ('B'));
4166 Make_Subtype_Declaration (Loc,
4167 Defining_Identifier => Bas,
4168 Subtype_Indication =>
4169 Make_Subtype_Indication (Loc,
4171 New_Occurrence_Of (Standard_Integer, Loc),
4173 Make_Range_Constraint (Loc,
4174 Range_Expression => Make_Range (Loc,
4175 Make_Integer_Literal
4176 (Loc, -Entry_Family_Bound),
4177 Make_Integer_Literal
4178 (Loc, Entry_Family_Bound - 1)))));
4180 Insert_After (Current_Node, Bas_Decl);
4181 Current_Node := Bas_Decl;
4186 Make_Full_Type_Declaration (Loc,
4187 Defining_Identifier => Efam_Type,
4189 Make_Unconstrained_Array_Definition (Loc,
4191 (New_List (New_Occurrence_Of (Bas, Loc))),
4193 Component_Definition =>
4194 Make_Component_Definition (Loc,
4195 Aliased_Present => False,
4196 Subtype_Indication =>
4197 New_Reference_To (Standard_Character, Loc))));
4200 Insert_After (Current_Node, Efam_Decl);
4201 Current_Node := Efam_Decl;
4202 Analyze (Efam_Decl);
4205 Make_Component_Declaration (Loc,
4206 Defining_Identifier =>
4207 Make_Defining_Identifier (Loc, Chars (Efam)),
4209 Component_Definition =>
4210 Make_Component_Definition (Loc,
4211 Aliased_Present => False,
4212 Subtype_Indication =>
4213 Make_Subtype_Indication (Loc,
4215 New_Occurrence_Of (Efam_Type, Loc),
4218 Make_Index_Or_Discriminant_Constraint (Loc,
4219 Constraints => New_List (
4221 (Etype (Discrete_Subtype_Definition
4222 (Parent (Efam))), Loc)))))));
4228 end Collect_Entry_Families;
4230 -----------------------
4231 -- Concurrent_Object --
4232 -----------------------
4234 function Concurrent_Object
4235 (Spec_Id : Entity_Id;
4236 Conc_Typ : Entity_Id) return Entity_Id
4239 -- Parameter _O or _object
4241 if Is_Protected_Type (Conc_Typ) then
4242 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4247 pragma Assert (Is_Task_Type (Conc_Typ));
4248 return First_Formal (Task_Body_Procedure (Conc_Typ));
4250 end Concurrent_Object;
4252 ----------------------
4253 -- Copy_Result_Type --
4254 ----------------------
4256 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4257 New_Res : constant Node_Id := New_Copy_Tree (Res);
4262 -- If the result type is an access_to_subprogram, we must create
4263 -- new entities for its spec.
4265 if Nkind (New_Res) = N_Access_Definition
4266 and then Present (Access_To_Subprogram_Definition (New_Res))
4268 -- Provide new entities for the formals
4270 Par_Spec := First (Parameter_Specifications
4271 (Access_To_Subprogram_Definition (New_Res)));
4272 while Present (Par_Spec) loop
4273 Formal := Defining_Identifier (Par_Spec);
4274 Set_Defining_Identifier (Par_Spec,
4275 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4281 end Copy_Result_Type;
4283 --------------------
4284 -- Concurrent_Ref --
4285 --------------------
4287 -- The expression returned for a reference to a concurrent object has the
4290 -- taskV!(name)._Task_Id
4294 -- objectV!(name)._Object
4296 -- for a protected object. For the case of an access to a concurrent
4297 -- object, there is an extra explicit dereference:
4299 -- taskV!(name.all)._Task_Id
4300 -- objectV!(name.all)._Object
4302 -- here taskV and objectV are the types for the associated records, which
4303 -- contain the required _Task_Id and _Object fields for tasks and protected
4304 -- objects, respectively.
4306 -- For the case of a task type name, the expression is
4310 -- i.e. a call to the Self function which returns precisely this Task_Id
4312 -- For the case of a protected type name, the expression is
4316 -- which is a renaming of the _object field of the current object
4317 -- record, passed into protected operations as a parameter.
4319 function Concurrent_Ref (N : Node_Id) return Node_Id is
4320 Loc : constant Source_Ptr := Sloc (N);
4321 Ntyp : constant Entity_Id := Etype (N);
4325 function Is_Current_Task (T : Entity_Id) return Boolean;
4326 -- Check whether the reference is to the immediately enclosing task
4327 -- type, or to an outer one (rare but legal).
4329 ---------------------
4330 -- Is_Current_Task --
4331 ---------------------
4333 function Is_Current_Task (T : Entity_Id) return Boolean is
4337 Scop := Current_Scope;
4338 while Present (Scop)
4339 and then Scop /= Standard_Standard
4345 elsif Is_Task_Type (Scop) then
4348 -- If this is a procedure nested within the task type, we must
4349 -- assume that it can be called from an inner task, and therefore
4350 -- cannot treat it as a local reference.
4352 elsif Is_Overloadable (Scop)
4353 and then In_Open_Scopes (T)
4358 Scop := Scope (Scop);
4362 -- We know that we are within the task body, so should have found it
4365 raise Program_Error;
4366 end Is_Current_Task;
4368 -- Start of processing for Concurrent_Ref
4371 if Is_Access_Type (Ntyp) then
4372 Dtyp := Designated_Type (Ntyp);
4374 if Is_Protected_Type (Dtyp) then
4375 Sel := Name_uObject;
4377 Sel := Name_uTask_Id;
4381 Make_Selected_Component (Loc,
4383 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4384 Make_Explicit_Dereference (Loc, N)),
4385 Selector_Name => Make_Identifier (Loc, Sel));
4387 elsif Is_Entity_Name (N)
4388 and then Is_Concurrent_Type (Entity (N))
4390 if Is_Task_Type (Entity (N)) then
4392 if Is_Current_Task (Entity (N)) then
4394 Make_Function_Call (Loc,
4395 Name => New_Reference_To (RTE (RE_Self), Loc));
4400 T_Self : constant Entity_Id :=
4401 Make_Defining_Identifier (Loc,
4402 Chars => New_Internal_Name ('T'));
4403 T_Body : constant Node_Id :=
4404 Parent (Corresponding_Body (Parent (Entity (N))));
4407 Decl := Make_Object_Declaration (Loc,
4408 Defining_Identifier => T_Self,
4409 Object_Definition =>
4410 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4412 Make_Function_Call (Loc,
4413 Name => New_Reference_To (RTE (RE_Self), Loc)));
4414 Prepend (Decl, Declarations (T_Body));
4416 Set_Scope (T_Self, Entity (N));
4417 return New_Occurrence_Of (T_Self, Loc);
4422 pragma Assert (Is_Protected_Type (Entity (N)));
4425 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4429 if Is_Protected_Type (Ntyp) then
4430 Sel := Name_uObject;
4432 elsif Is_Task_Type (Ntyp) then
4433 Sel := Name_uTask_Id;
4436 raise Program_Error;
4440 Make_Selected_Component (Loc,
4442 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4444 Selector_Name => Make_Identifier (Loc, Sel));
4448 ------------------------
4449 -- Convert_Concurrent --
4450 ------------------------
4452 function Convert_Concurrent
4454 Typ : Entity_Id) return Node_Id
4457 if not Is_Concurrent_Type (Typ) then
4461 Unchecked_Convert_To
4462 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4464 end Convert_Concurrent;
4466 -------------------------------------
4467 -- Debug_Private_Data_Declarations --
4468 -------------------------------------
4470 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4471 Debug_Nod : Node_Id;
4475 Decl := First (Decls);
4476 while Present (Decl)
4477 and then not Comes_From_Source (Decl)
4479 -- Declaration for concurrent entity _object and its access type,
4480 -- along with the entry index subtype:
4481 -- type prot_typVP is access prot_typV;
4482 -- _object : prot_typVP := prot_typV (_O);
4483 -- subtype Jnn is <Type of Index> range Low .. High;
4485 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4486 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4488 -- Declaration for the Protection object, discriminals, privals and
4489 -- entry index constant:
4490 -- conc_typR : protection_typ renames _object._object;
4491 -- discr_nameD : discr_typ renames _object.discr_name;
4492 -- discr_nameD : discr_typ renames _task.discr_name;
4493 -- prival_name : comp_typ renames _object.comp_name;
4494 -- J : constant Jnn :=
4495 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4497 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4498 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4499 Debug_Nod := Debug_Renaming_Declaration (Decl);
4501 if Present (Debug_Nod) then
4502 Insert_After (Decl, Debug_Nod);
4508 end Debug_Private_Data_Declarations;
4510 ----------------------------
4511 -- Entry_Index_Expression --
4512 ----------------------------
4514 function Entry_Index_Expression
4518 Ttyp : Entity_Id) return Node_Id
4528 -- The queues of entries and entry families appear in textual order in
4529 -- the associated record. The entry index is computed as the sum of the
4530 -- number of queues for all entries that precede the designated one, to
4531 -- which is added the index expression, if this expression denotes a
4532 -- member of a family.
4534 -- The following is a place holder for the count of simple entries
4536 Num := Make_Integer_Literal (Sloc, 1);
4538 -- We construct an expression which is a series of addition operations.
4539 -- The first operand is the number of single entries that precede this
4540 -- one, the second operand is the index value relative to the start of
4541 -- the referenced family, and the remaining operands are the lengths of
4542 -- the entry families that precede this entry, i.e. the constructed
4545 -- number_simple_entries +
4546 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4547 -- family'length + ...
4549 -- where index-value is the given index value, and s is the index
4550 -- subtype (we have to use pos because the subtype might be an
4551 -- enumeration type preventing direct subtraction). Note that the task
4552 -- entry array is one-indexed.
4554 -- The upper bound of the entry family may be a discriminant, so we
4555 -- retrieve the lower bound explicitly to compute offset, rather than
4556 -- using the index subtype which may mention a discriminant.
4558 if Present (Index) then
4559 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4568 Make_Attribute_Reference (Sloc,
4569 Attribute_Name => Name_Pos,
4570 Prefix => New_Reference_To (Base_Type (S), Sloc),
4571 Expressions => New_List (Relocate_Node (Index))),
4579 -- Now add lengths of preceding entries and entry families
4581 Prev := First_Entity (Ttyp);
4583 while Chars (Prev) /= Chars (Ent)
4584 or else (Ekind (Prev) /= Ekind (Ent))
4585 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4587 if Ekind (Prev) = E_Entry then
4588 Set_Intval (Num, Intval (Num) + 1);
4590 elsif Ekind (Prev) = E_Entry_Family then
4592 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4593 Lo := Type_Low_Bound (S);
4594 Hi := Type_High_Bound (S);
4599 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4601 -- Other components are anonymous types to be ignored
4611 end Entry_Index_Expression;
4613 ---------------------------
4614 -- Establish_Task_Master --
4615 ---------------------------
4617 procedure Establish_Task_Master (N : Node_Id) is
4620 if Restriction_Active (No_Task_Hierarchy) = False then
4621 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4622 Prepend_To (Declarations (N), Call);
4625 end Establish_Task_Master;
4627 --------------------------------
4628 -- Expand_Accept_Declarations --
4629 --------------------------------
4631 -- Part of the expansion of an accept statement involves the creation of
4632 -- a declaration that can be referenced from the statement sequence of
4637 -- This declaration is inserted immediately before the accept statement
4638 -- and it is important that it be inserted before the statements of the
4639 -- statement sequence are analyzed. Thus it would be too late to create
4640 -- this declaration in the Expand_N_Accept_Statement routine, which is
4641 -- why there is a separate procedure to be called directly from Sem_Ch9.
4643 -- Ann is used to hold the address of the record containing the parameters
4644 -- (see Expand_N_Entry_Call for more details on how this record is built).
4645 -- References to the parameters do an unchecked conversion of this address
4646 -- to a pointer to the required record type, and then access the field that
4647 -- holds the value of the required parameter. The entity for the address
4648 -- variable is held as the top stack element (i.e. the last element) of the
4649 -- Accept_Address stack in the corresponding entry entity, and this element
4650 -- must be set in place before the statements are processed.
4652 -- The above description applies to the case of a stand alone accept
4653 -- statement, i.e. one not appearing as part of a select alternative.
4655 -- For the case of an accept that appears as part of a select alternative
4656 -- of a selective accept, we must still create the declaration right away,
4657 -- since Ann is needed immediately, but there is an important difference:
4659 -- The declaration is inserted before the selective accept, not before
4660 -- the accept statement (which is not part of a list anyway, and so would
4661 -- not accommodate inserted declarations)
4663 -- We only need one address variable for the entire selective accept. So
4664 -- the Ann declaration is created only for the first accept alternative,
4665 -- and subsequent accept alternatives reference the same Ann variable.
4667 -- We can distinguish the two cases by seeing whether the accept statement
4668 -- is part of a list. If not, then it must be in an accept alternative.
4670 -- To expand the requeue statement, a label is provided at the end of the
4671 -- accept statement or alternative of which it is a part, so that the
4672 -- statement can be skipped after the requeue is complete. This label is
4673 -- created here rather than during the expansion of the accept statement,
4674 -- because it will be needed by any requeue statements within the accept,
4675 -- which are expanded before the accept.
4677 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4678 Loc : constant Source_Ptr := Sloc (N);
4679 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4680 Ann : Entity_Id := Empty;
4688 if Expander_Active then
4690 -- If we have no handled statement sequence, we may need to build
4691 -- a dummy sequence consisting of a null statement. This can be
4692 -- skipped if the trivial accept optimization is permitted.
4694 if not Trivial_Accept_OK
4696 (No (Stats) or else Null_Statements (Statements (Stats)))
4698 Set_Handled_Statement_Sequence (N,
4699 Make_Handled_Sequence_Of_Statements (Loc,
4700 New_List (Make_Null_Statement (Loc))));
4703 -- Create and declare two labels to be placed at the end of the
4704 -- accept statement. The first label is used to allow requeues to
4705 -- skip the remainder of entry processing. The second label is used
4706 -- to skip the remainder of entry processing if the rendezvous
4707 -- completes in the middle of the accept body.
4709 if Present (Handled_Statement_Sequence (N)) then
4710 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4712 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4713 Lab := Make_Label (Loc, Lab_Id);
4715 Make_Implicit_Label_Declaration (Loc,
4716 Defining_Identifier => Entity (Lab_Id),
4717 Label_Construct => Lab);
4718 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4720 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4722 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4723 Lab := Make_Label (Loc, Lab_Id);
4725 Make_Implicit_Label_Declaration (Loc,
4726 Defining_Identifier => Entity (Lab_Id),
4727 Label_Construct => Lab);
4728 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4735 -- Case of stand alone accept statement
4737 if Is_List_Member (N) then
4739 if Present (Handled_Statement_Sequence (N)) then
4741 Make_Defining_Identifier (Loc,
4742 Chars => New_Internal_Name ('A'));
4745 Make_Object_Declaration (Loc,
4746 Defining_Identifier => Ann,
4747 Object_Definition =>
4748 New_Reference_To (RTE (RE_Address), Loc));
4750 Insert_Before (N, Adecl);
4753 Insert_Before (N, Ldecl);
4756 Insert_Before (N, Ldecl2);
4760 -- Case of accept statement which is in an accept alternative
4764 Acc_Alt : constant Node_Id := Parent (N);
4765 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4769 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4770 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4772 -- ??? Consider a single label for select statements
4774 if Present (Handled_Statement_Sequence (N)) then
4776 Statements (Handled_Statement_Sequence (N)));
4780 Statements (Handled_Statement_Sequence (N)));
4784 -- Find first accept alternative of the selective accept. A
4785 -- valid selective accept must have at least one accept in it.
4787 Alt := First (Select_Alternatives (Sel_Acc));
4789 while Nkind (Alt) /= N_Accept_Alternative loop
4793 -- If we are the first accept statement, then we have to create
4794 -- the Ann variable, as for the stand alone case, except that
4795 -- it is inserted before the selective accept. Similarly, a
4796 -- label for requeue expansion must be declared.
4798 if N = Accept_Statement (Alt) then
4800 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4803 Make_Object_Declaration (Loc,
4804 Defining_Identifier => Ann,
4805 Object_Definition =>
4806 New_Reference_To (RTE (RE_Address), Loc));
4808 Insert_Before (Sel_Acc, Adecl);
4811 -- If we are not the first accept statement, then find the Ann
4812 -- variable allocated by the first accept and use it.
4816 Node (Last_Elmt (Accept_Address
4817 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4822 -- Merge here with Ann either created or referenced, and Adecl
4823 -- pointing to the corresponding declaration. Remaining processing
4824 -- is the same for the two cases.
4826 if Present (Ann) then
4827 Append_Elmt (Ann, Accept_Address (Ent));
4828 Set_Debug_Info_Needed (Ann);
4831 -- Create renaming declarations for the entry formals. Each reference
4832 -- to a formal becomes a dereference of a component of the parameter
4833 -- block, whose address is held in Ann. These declarations are
4834 -- eventually inserted into the accept block, and analyzed there so
4835 -- that they have the proper scope for gdb and do not conflict with
4836 -- other declarations.
4838 if Present (Parameter_Specifications (N))
4839 and then Present (Handled_Statement_Sequence (N))
4849 Formal := First_Formal (Ent);
4851 while Present (Formal) loop
4852 Comp := Entry_Component (Formal);
4854 Make_Defining_Identifier (Loc, Chars (Formal));
4856 Set_Etype (New_F, Etype (Formal));
4857 Set_Scope (New_F, Ent);
4859 -- Now we set debug info needed on New_F even though it does
4860 -- not come from source, so that the debugger will get the
4861 -- right information for these generated names.
4863 Set_Debug_Info_Needed (New_F);
4865 if Ekind (Formal) = E_In_Parameter then
4866 Set_Ekind (New_F, E_Constant);
4868 Set_Ekind (New_F, E_Variable);
4869 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4872 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4875 Make_Object_Renaming_Declaration (Loc,
4876 Defining_Identifier =>
4879 New_Reference_To (Etype (Formal), Loc),
4881 Make_Explicit_Dereference (Loc,
4882 Make_Selected_Component (Loc,
4884 Unchecked_Convert_To (
4885 Entry_Parameters_Type (Ent),
4886 New_Reference_To (Ann, Loc)),
4888 New_Reference_To (Comp, Loc))));
4890 if No (Declarations (N)) then
4891 Set_Declarations (N, New_List);
4894 Append (Decl, Declarations (N));
4895 Set_Renamed_Object (Formal, New_F);
4896 Next_Formal (Formal);
4903 end Expand_Accept_Declarations;
4905 ---------------------------------------------
4906 -- Expand_Access_Protected_Subprogram_Type --
4907 ---------------------------------------------
4909 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4910 Loc : constant Source_Ptr := Sloc (N);
4912 T : constant Entity_Id := Defining_Identifier (N);
4913 D_T : constant Entity_Id := Designated_Type (T);
4914 D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc,
4915 Chars => New_Internal_Name ('D'));
4916 E_T : constant Entity_Id := Make_Defining_Identifier (Loc,
4917 Chars => New_Internal_Name ('E'));
4918 P_List : constant List_Id := Build_Protected_Spec
4919 (N, RTE (RE_Address), D_T, False);
4925 -- Create access to subprogram with full signature
4927 if Etype (D_T) /= Standard_Void_Type then
4929 Make_Access_Function_Definition (Loc,
4930 Parameter_Specifications => P_List,
4931 Result_Definition =>
4932 Copy_Result_Type (Result_Definition (Type_Definition (N))));
4936 Make_Access_Procedure_Definition (Loc,
4937 Parameter_Specifications => P_List);
4941 Make_Full_Type_Declaration (Loc,
4942 Defining_Identifier => D_T2,
4943 Type_Definition => Def1);
4945 Insert_After (N, Decl1);
4948 -- Create Equivalent_Type, a record with two components for an access to
4949 -- object and an access to subprogram.
4952 Make_Component_Declaration (Loc,
4953 Defining_Identifier =>
4954 Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
4955 Component_Definition =>
4956 Make_Component_Definition (Loc,
4957 Aliased_Present => False,
4958 Subtype_Indication =>
4959 New_Occurrence_Of (RTE (RE_Address), Loc))),
4961 Make_Component_Declaration (Loc,
4962 Defining_Identifier =>
4963 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4964 Component_Definition =>
4965 Make_Component_Definition (Loc,
4966 Aliased_Present => False,
4967 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4970 Make_Full_Type_Declaration (Loc,
4971 Defining_Identifier => E_T,
4973 Make_Record_Definition (Loc,
4975 Make_Component_List (Loc,
4976 Component_Items => Comps)));
4978 Insert_After (Decl1, Decl2);
4980 Set_Equivalent_Type (T, E_T);
4981 end Expand_Access_Protected_Subprogram_Type;
4983 --------------------------
4984 -- Expand_Entry_Barrier --
4985 --------------------------
4987 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4988 Cond : constant Node_Id :=
4989 Condition (Entry_Body_Formal_Part (N));
4990 Prot : constant Entity_Id := Scope (Ent);
4991 Spec_Decl : constant Node_Id := Parent (Prot);
4994 Body_Decl : Node_Id;
4997 if No_Run_Time_Mode then
4998 Error_Msg_CRT ("entry barrier", N);
5002 -- The body of the entry barrier must be analyzed in the context of the
5003 -- protected object, but its scope is external to it, just as any other
5004 -- unprotected version of a protected operation. The specification has
5005 -- been produced when the protected type declaration was elaborated. We
5006 -- build the body, insert it in the enclosing scope, but analyze it in
5007 -- the current context. A more uniform approach would be to treat the
5008 -- barrier just as a protected function, and discard the protected
5009 -- version of it because it is never called.
5011 if Expander_Active then
5012 B_F := Build_Barrier_Function (N, Ent, Prot);
5013 Func := Barrier_Function (Ent);
5014 Set_Corresponding_Spec (B_F, Func);
5016 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5018 if Nkind (Parent (Body_Decl)) = N_Subunit then
5019 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5022 Insert_Before_And_Analyze (Body_Decl, B_F);
5024 Set_Discriminals (Spec_Decl);
5025 Set_Scope (Func, Scope (Prot));
5028 Analyze_And_Resolve (Cond, Any_Boolean);
5031 -- The Ravenscar profile restricts barriers to simple variables declared
5032 -- within the protected object. We also allow Boolean constants, since
5033 -- these appear in several published examples and are also allowed by
5034 -- the Aonix compiler.
5036 -- Note that after analysis variables in this context will be replaced
5037 -- by the corresponding prival, that is to say a renaming of a selected
5038 -- component of the form _Object.Var. If expansion is disabled, as
5039 -- within a generic, we check that the entity appears in the current
5042 if Is_Entity_Name (Cond) then
5044 -- A small optimization of useless renamings. If the scope of the
5045 -- entity of the condition is not the barrier function, then the
5046 -- condition does not reference any of the generated renamings
5047 -- within the function.
5050 and then Scope (Entity (Cond)) /= Func
5052 Set_Declarations (B_F, Empty_List);
5055 if Entity (Cond) = Standard_False
5057 Entity (Cond) = Standard_True
5061 elsif not Expander_Active
5062 and then Scope (Entity (Cond)) = Current_Scope
5066 -- Check for case of _object.all.field (note that the explicit
5067 -- dereference gets inserted by analyze/expand of _object.field)
5069 elsif Present (Renamed_Object (Entity (Cond)))
5071 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5075 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5081 -- It is not a boolean variable or literal, so check the restriction
5083 Check_Restriction (Simple_Barriers, Cond);
5084 end Expand_Entry_Barrier;
5086 ------------------------------
5087 -- Expand_N_Abort_Statement --
5088 ------------------------------
5090 -- Expand abort T1, T2, .. Tn; into:
5091 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5093 procedure Expand_N_Abort_Statement (N : Node_Id) is
5094 Loc : constant Source_Ptr := Sloc (N);
5095 Tlist : constant List_Id := Names (N);
5101 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5104 Tasknm := First (Tlist);
5106 while Present (Tasknm) loop
5109 -- A task interface class-wide type object is being aborted.
5110 -- Retrieve its _task_id by calling a dispatching routine.
5112 if Ada_Version >= Ada_05
5113 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5114 and then Is_Interface (Etype (Tasknm))
5115 and then Is_Task_Interface (Etype (Tasknm))
5117 Append_To (Component_Associations (Aggr),
5118 Make_Component_Association (Loc,
5119 Choices => New_List (
5120 Make_Integer_Literal (Loc, Count)),
5123 -- Task_Id (Tasknm._disp_get_task_id)
5125 Make_Unchecked_Type_Conversion (Loc,
5127 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5129 Make_Selected_Component (Loc,
5131 New_Copy_Tree (Tasknm),
5133 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5136 Append_To (Component_Associations (Aggr),
5137 Make_Component_Association (Loc,
5138 Choices => New_List (
5139 Make_Integer_Literal (Loc, Count)),
5140 Expression => Concurrent_Ref (Tasknm)));
5147 Make_Procedure_Call_Statement (Loc,
5148 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5149 Parameter_Associations => New_List (
5150 Make_Qualified_Expression (Loc,
5151 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5152 Expression => Aggr))));
5155 end Expand_N_Abort_Statement;
5157 -------------------------------
5158 -- Expand_N_Accept_Statement --
5159 -------------------------------
5161 -- This procedure handles expansion of accept statements that stand
5162 -- alone, i.e. they are not part of an accept alternative. The expansion
5163 -- of accept statement in accept alternatives is handled by the routines
5164 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5165 -- following description applies only to stand alone accept statements.
5167 -- If there is no handled statement sequence, or only null statements,
5168 -- then this is called a trivial accept, and the expansion is:
5170 -- Accept_Trivial (entry-index)
5172 -- If there is a handled statement sequence, then the expansion is:
5179 -- Accept_Call (entry-index, Ann);
5180 -- Renaming_Declarations for formals
5181 -- <statement sequence from N_Accept_Statement node>
5182 -- Complete_Rendezvous;
5187 -- <exception handler from N_Accept_Statement node>
5188 -- Complete_Rendezvous;
5190 -- <exception handler from N_Accept_Statement node>
5191 -- Complete_Rendezvous;
5196 -- when all others =>
5197 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5200 -- The first three declarations were already inserted ahead of the accept
5201 -- statement by the Expand_Accept_Declarations procedure, which was called
5202 -- directly from the semantics during analysis of the accept statement,
5203 -- before analyzing its contained statements.
5205 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5206 -- from possible expansion activity (the original source of course does
5207 -- not have any declarations associated with the accept statement, since
5208 -- an accept statement has no declarative part). In particular, if the
5209 -- expander is active, the first such declaration is the declaration of
5210 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5212 -- The two blocks are merged into a single block if the inner block has
5213 -- no exception handlers, but otherwise two blocks are required, since
5214 -- exceptions might be raised in the exception handlers of the inner
5215 -- block, and Exceptional_Complete_Rendezvous must be called.
5217 procedure Expand_N_Accept_Statement (N : Node_Id) is
5218 Loc : constant Source_Ptr := Sloc (N);
5219 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5220 Ename : constant Node_Id := Entry_Direct_Name (N);
5221 Eindx : constant Node_Id := Entry_Index (N);
5222 Eent : constant Entity_Id := Entity (Ename);
5223 Acstack : constant Elist_Id := Accept_Address (Eent);
5224 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5225 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5230 -- Start of processing for Expand_N_Accept_Statement
5233 -- If accept statement is not part of a list, then its parent must be
5234 -- an accept alternative, and, as described above, we do not do any
5235 -- expansion for such accept statements at this level.
5237 if not Is_List_Member (N) then
5238 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5241 -- Trivial accept case (no statement sequence, or null statements).
5242 -- If the accept statement has declarations, then just insert them
5243 -- before the procedure call.
5245 elsif Trivial_Accept_OK
5246 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5248 -- Remove declarations for renamings, because the parameter block
5249 -- will not be assigned.
5256 D := First (Declarations (N));
5258 while Present (D) loop
5260 if Nkind (D) = N_Object_Renaming_Declaration then
5268 if Present (Declarations (N)) then
5269 Insert_Actions (N, Declarations (N));
5273 Make_Procedure_Call_Statement (Loc,
5274 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5275 Parameter_Associations => New_List (
5276 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5280 -- Discard Entry_Address that was created for it, so it will not be
5281 -- emitted if this accept statement is in the statement part of a
5282 -- delay alternative.
5284 if Present (Stats) then
5285 Remove_Last_Elmt (Acstack);
5288 -- Case of statement sequence present
5291 -- Construct the block, using the declarations from the accept
5292 -- statement if any to initialize the declarations of the block.
5294 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5295 Set_Ekind (Blkent, E_Block);
5296 Set_Etype (Blkent, Standard_Void_Type);
5297 Set_Scope (Blkent, Current_Scope);
5300 Make_Block_Statement (Loc,
5301 Identifier => New_Reference_To (Blkent, Loc),
5302 Declarations => Declarations (N),
5303 Handled_Statement_Sequence => Build_Accept_Body (N));
5305 -- Prepend call to Accept_Call to main statement sequence If the
5306 -- accept has exception handlers, the statement sequence is wrapped
5307 -- in a block. Insert call and renaming declarations in the
5308 -- declarations of the block, so they are elaborated before the
5312 Make_Procedure_Call_Statement (Loc,
5313 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5314 Parameter_Associations => New_List (
5315 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5316 New_Reference_To (Ann, Loc)));
5318 if Parent (Stats) = N then
5319 Prepend (Call, Statements (Stats));
5328 Push_Scope (Blkent);
5336 D := First (Declarations (N));
5337 while Present (D) loop
5340 if Nkind (D) = N_Object_Renaming_Declaration then
5342 -- The renaming declarations for the formals were created
5343 -- during analysis of the accept statement, and attached to
5344 -- the list of declarations. Place them now in the context
5345 -- of the accept block or subprogram.
5348 Typ := Entity (Subtype_Mark (D));
5349 Insert_After (Call, D);
5352 -- If the formal is class_wide, it does not have an actual
5353 -- subtype. The analysis of the renaming declaration creates
5354 -- one, but we need to retain the class-wide nature of the
5357 if Is_Class_Wide_Type (Typ) then
5358 Set_Etype (Defining_Identifier (D), Typ);
5369 -- Replace the accept statement by the new block
5374 -- Last step is to unstack the Accept_Address value
5376 Remove_Last_Elmt (Acstack);
5378 end Expand_N_Accept_Statement;
5380 ----------------------------------
5381 -- Expand_N_Asynchronous_Select --
5382 ----------------------------------
5384 -- This procedure assumes that the trigger statement is an entry call or
5385 -- a dispatching procedure call. A delay alternative should already have
5386 -- been expanded into an entry call to the appropriate delay object Wait
5389 -- If the trigger is a task entry call, the select is implemented with
5390 -- a Task_Entry_Call:
5395 -- P : parms := (parm, parm, parm);
5397 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5399 -- procedure _clean is
5402 -- Cancel_Task_Entry_Call (C);
5409 -- (<acceptor-task>, -- Acceptor
5410 -- <entry-index>, -- E
5411 -- P'Address, -- Uninterpreted_Data
5412 -- Asynchronous_Call, -- Mode
5413 -- B); -- Rendezvous_Successful
5420 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5423 -- when Abort_Signal => Abort_Undefer;
5430 -- <triggered-statements>
5434 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5435 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5439 -- P : parms := (parm, parm, parm);
5441 -- Call_Simple (acceptor-task, entry-index, P'Address);
5447 -- so the task at hand is to convert the latter expansion into the former
5449 -- If the trigger is a protected entry call, the select is implemented
5450 -- with Protected_Entry_Call:
5453 -- P : E1_Params := (param, param, param);
5454 -- Bnn : Communications_Block;
5459 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5461 -- procedure _clean is
5464 -- if Enqueued (Bnn) then
5465 -- Cancel_Protected_Entry_Call (Bnn);
5472 -- Protected_Entry_Call
5473 -- (po._object'Access, -- Object
5474 -- <entry index>, -- E
5475 -- P'Address, -- Uninterpreted_Data
5476 -- Asynchronous_Call, -- Mode
5479 -- if Enqueued (Bnn) then
5483 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5486 -- when Abort_Signal => Abort_Undefer;
5489 -- if not Cancelled (Bnn) then
5490 -- <triggered-statements>
5494 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5498 -- P : E1_Params := (param, param, param);
5499 -- Bnn : Communications_Block;
5502 -- Protected_Entry_Call
5503 -- (po._object'Access, -- Object
5504 -- <entry index>, -- E
5505 -- P'Address, -- Uninterpreted_Data
5506 -- Simple_Call, -- Mode
5513 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5517 -- B : Boolean := False;
5518 -- Bnn : Communication_Block;
5519 -- C : Ada.Tags.Prim_Op_Kind;
5520 -- D : System.Storage_Elements.Dummy_Communication_Block;
5521 -- K : Ada.Tags.Tagged_Kind :=
5522 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5523 -- P : Parameters := (Param1 .. ParamN);
5528 -- if K = Ada.Tags.TK_Limited_Tagged then
5529 -- <dispatching-call>;
5530 -- <triggering-statements>;
5534 -- Ada.Tags.Get_Offset_Index
5535 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5537 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5539 -- if C = POK_Protected_Entry then
5541 -- procedure _clean is
5543 -- if Enqueued (Bnn) then
5544 -- Cancel_Protected_Entry_Call (Bnn);
5550 -- _Disp_Asynchronous_Select
5551 -- (<object>, S, P'Address, D, B);
5552 -- Bnn := Communication_Block (D);
5554 -- Param1 := P.Param1;
5556 -- ParamN := P.ParamN;
5558 -- if Enqueued (Bnn) then
5559 -- <abortable-statements>
5562 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5565 -- when Abort_Signal => Abort_Undefer;
5568 -- if not Cancelled (Bnn) then
5569 -- <triggering-statements>
5572 -- elsif C = POK_Task_Entry then
5574 -- procedure _clean is
5576 -- Cancel_Task_Entry_Call (U);
5582 -- _Disp_Asynchronous_Select
5583 -- (<object>, S, P'Address, D, B);
5584 -- Bnn := Communication_Bloc (D);
5586 -- Param1 := P.Param1;
5588 -- ParamN := P.ParamN;
5593 -- <abortable-statements>
5595 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5598 -- when Abort_Signal => Abort_Undefer;
5602 -- <triggering-statements>
5607 -- <dispatching-call>;
5608 -- <triggering-statements>
5613 -- The job is to convert this to the asynchronous form
5615 -- If the trigger is a delay statement, it will have been expanded into a
5616 -- call to one of the GNARL delay procedures. This routine will convert
5617 -- this into a protected entry call on a delay object and then continue
5618 -- processing as for a protected entry call trigger. This requires
5619 -- declaring a Delay_Block object and adding a pointer to this object to
5620 -- the parameter list of the delay procedure to form the parameter list of
5621 -- the entry call. This object is used by the runtime to queue the delay
5624 -- For a description of the use of P and the assignments after the call,
5625 -- see Expand_N_Entry_Call_Statement.
5627 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5628 Loc : constant Source_Ptr := Sloc (N);
5629 Abrt : constant Node_Id := Abortable_Part (N);
5630 Astats : constant List_Id := Statements (Abrt);
5631 Trig : constant Node_Id := Triggering_Alternative (N);
5632 Tstats : constant List_Id := Statements (Trig);
5634 Abort_Block_Ent : Entity_Id;
5635 Abortable_Block : Node_Id;
5637 Blk_Ent : Entity_Id;
5638 Blk_Typ : Entity_Id;
5640 Call_Ent : Entity_Id;
5641 Cancel_Param : Entity_Id;
5642 Cleanup_Block : Node_Id;
5643 Cleanup_Block_Ent : Entity_Id;
5644 Cleanup_Stmts : List_Id;
5645 Conc_Typ_Stmts : List_Id;
5647 Dblock_Ent : Entity_Id;
5652 Enqueue_Call : Node_Id;
5656 Lim_Typ_Stmts : List_Id;
5662 ProtE_Stmts : List_Id;
5663 ProtP_Stmts : List_Id;
5666 Target_Undefer : RE_Id;
5667 TaskE_Stmts : List_Id;
5668 Undefer_Args : List_Id := No_List;
5670 B : Entity_Id; -- Call status flag
5671 Bnn : Entity_Id; -- Communication block
5672 C : Entity_Id; -- Call kind
5673 K : Entity_Id; -- Tagged kind
5674 P : Entity_Id; -- Parameter block
5675 S : Entity_Id; -- Primitive operation slot
5676 T : Entity_Id; -- Additional status flag
5679 Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5680 Ecall := Triggering_Statement (Trig);
5682 -- The arguments in the call may require dynamic allocation, and the
5683 -- call statement may have been transformed into a block. The block
5684 -- may contain additional declarations for internal entities, and the
5685 -- original call is found by sequential search.
5687 if Nkind (Ecall) = N_Block_Statement then
5688 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5689 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5690 N_Entry_Call_Statement)
5696 -- This is either a dispatching call or a delay statement used as a
5697 -- trigger which was expanded into a procedure call.
5699 if Nkind (Ecall) = N_Procedure_Call_Statement then
5700 if Ada_Version >= Ada_05
5702 (No (Original_Node (Ecall))
5703 or else not Nkind_In (Original_Node (Ecall),
5704 N_Delay_Relative_Statement,
5705 N_Delay_Until_Statement))
5707 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5712 -- Call status flag processing, generate:
5713 -- B : Boolean := False;
5715 B := Build_B (Loc, Decls);
5717 -- Communication block processing, generate:
5718 -- Bnn : Communication_Block;
5720 Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
5723 Make_Object_Declaration (Loc,
5724 Defining_Identifier =>
5726 Object_Definition =>
5727 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5729 -- Call kind processing, generate:
5730 -- C : Ada.Tags.Prim_Op_Kind;
5732 C := Build_C (Loc, Decls);
5734 -- Tagged kind processing, generate:
5735 -- K : Ada.Tags.Tagged_Kind :=
5736 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5738 -- Dummy communication block, generate:
5739 -- D : Dummy_Communication_Block;
5742 Make_Object_Declaration (Loc,
5743 Defining_Identifier =>
5744 Make_Defining_Identifier (Loc, Name_uD),
5745 Object_Definition =>
5747 RTE (RE_Dummy_Communication_Block), Loc)));
5749 K := Build_K (Loc, Decls, Obj);
5751 -- Parameter block processing
5753 Blk_Typ := Build_Parameter_Block
5754 (Loc, Actuals, Formals, Decls);
5755 P := Parameter_Block_Pack
5756 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5758 -- Dispatch table slot processing, generate:
5761 S := Build_S (Loc, Decls);
5763 -- Additional status flag processing, generate:
5765 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
5768 Make_Object_Declaration (Loc,
5769 Defining_Identifier =>
5771 Object_Definition =>
5772 New_Reference_To (Standard_Boolean, Loc)));
5774 ------------------------------
5775 -- Protected entry handling --
5776 ------------------------------
5779 -- Param1 := P.Param1;
5781 -- ParamN := P.ParamN;
5783 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5786 -- Bnn := Communication_Block (D);
5788 Prepend_To (Cleanup_Stmts,
5789 Make_Assignment_Statement (Loc,
5791 New_Reference_To (Bnn, Loc),
5793 Make_Unchecked_Type_Conversion (Loc,
5795 New_Reference_To (RTE (RE_Communication_Block), Loc),
5797 Make_Identifier (Loc, Name_uD))));
5800 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5802 Prepend_To (Cleanup_Stmts,
5803 Make_Procedure_Call_Statement (Loc,
5806 Find_Prim_Op (Etype (Etype (Obj)),
5807 Name_uDisp_Asynchronous_Select),
5809 Parameter_Associations =>
5811 New_Copy_Tree (Obj), -- <object>
5812 New_Reference_To (S, Loc), -- S
5813 Make_Attribute_Reference (Loc, -- P'Address
5815 New_Reference_To (P, Loc),
5818 Make_Identifier (Loc, Name_uD), -- D
5819 New_Reference_To (B, Loc)))); -- B
5822 -- if Enqueued (Bnn) then
5823 -- <abortable-statements>
5826 Append_To (Cleanup_Stmts,
5827 Make_If_Statement (Loc,
5829 Make_Function_Call (Loc,
5831 New_Reference_To (RTE (RE_Enqueued), Loc),
5832 Parameter_Associations =>
5834 New_Reference_To (Bnn, Loc))),
5837 New_Copy_List_Tree (Astats)));
5839 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5840 -- will then generate a _clean for the communication block Bnn.
5844 -- procedure _clean is
5846 -- if Enqueued (Bnn) then
5847 -- Cancel_Protected_Entry_Call (Bnn);
5856 Cleanup_Block_Ent :=
5857 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5860 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5862 -- Wrap the cleanup block in an exception handling block
5868 -- when Abort_Signal => Abort_Undefer;
5872 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5876 Make_Implicit_Label_Declaration (Loc,
5877 Defining_Identifier =>
5881 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5884 -- if not Cancelled (Bnn) then
5885 -- <triggering-statements>
5888 Append_To (ProtE_Stmts,
5889 Make_If_Statement (Loc,
5893 Make_Function_Call (Loc,
5895 New_Reference_To (RTE (RE_Cancelled), Loc),
5896 Parameter_Associations =>
5898 New_Reference_To (Bnn, Loc)))),
5901 New_Copy_List_Tree (Tstats)));
5903 -------------------------
5904 -- Task entry handling --
5905 -------------------------
5908 -- Param1 := P.Param1;
5910 -- ParamN := P.ParamN;
5912 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5915 -- Bnn := Communication_Block (D);
5917 Append_To (TaskE_Stmts,
5918 Make_Assignment_Statement (Loc,
5920 New_Reference_To (Bnn, Loc),
5922 Make_Unchecked_Type_Conversion (Loc,
5924 New_Reference_To (RTE (RE_Communication_Block), Loc),
5926 Make_Identifier (Loc, Name_uD))));
5929 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5931 Prepend_To (TaskE_Stmts,
5932 Make_Procedure_Call_Statement (Loc,
5935 Find_Prim_Op (Etype (Etype (Obj)),
5936 Name_uDisp_Asynchronous_Select),
5938 Parameter_Associations =>
5940 New_Copy_Tree (Obj), -- <object>
5941 New_Reference_To (S, Loc), -- S
5942 Make_Attribute_Reference (Loc, -- P'Address
5944 New_Reference_To (P, Loc),
5947 Make_Identifier (Loc, Name_uD), -- D
5948 New_Reference_To (B, Loc)))); -- B
5953 Prepend_To (TaskE_Stmts,
5954 Make_Procedure_Call_Statement (Loc,
5956 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5957 Parameter_Associations =>
5962 -- <abortable-statements>
5964 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5966 Prepend_To (Cleanup_Stmts,
5967 Make_Procedure_Call_Statement (Loc,
5969 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5970 Parameter_Associations =>
5973 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5974 -- will generate a _clean for the additional status flag.
5978 -- procedure _clean is
5980 -- Cancel_Task_Entry_Call (U);
5988 Cleanup_Block_Ent :=
5989 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5992 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
5994 -- Wrap the cleanup block in an exception handling block
6000 -- when Abort_Signal => Abort_Undefer;
6004 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6006 Append_To (TaskE_Stmts,
6007 Make_Implicit_Label_Declaration (Loc,
6008 Defining_Identifier =>
6011 Append_To (TaskE_Stmts,
6013 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6017 -- <triggering-statements>
6020 Append_To (TaskE_Stmts,
6021 Make_If_Statement (Loc,
6025 New_Reference_To (T, Loc)),
6028 New_Copy_List_Tree (Tstats)));
6030 ----------------------------------
6031 -- Protected procedure handling --
6032 ----------------------------------
6035 -- <dispatching-call>;
6036 -- <triggering-statements>
6038 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6039 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6042 -- S := Ada.Tags.Get_Offset_Index
6043 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6046 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6049 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6051 Append_To (Conc_Typ_Stmts,
6052 Make_Procedure_Call_Statement (Loc,
6055 Find_Prim_Op (Etype (Etype (Obj)),
6056 Name_uDisp_Get_Prim_Op_Kind),
6058 Parameter_Associations =>
6060 New_Copy_Tree (Obj),
6061 New_Reference_To (S, Loc),
6062 New_Reference_To (C, Loc))));
6065 -- if C = POK_Procedure_Entry then
6067 -- elsif C = POK_Task_Entry then
6073 Append_To (Conc_Typ_Stmts,
6074 Make_If_Statement (Loc,
6078 New_Reference_To (C, Loc),
6080 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6087 Make_Elsif_Part (Loc,
6091 New_Reference_To (C, Loc),
6093 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6102 -- <dispatching-call>;
6103 -- <triggering-statements>
6105 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6106 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6109 -- if K = Ada.Tags.TK_Limited_Tagged then
6116 Make_If_Statement (Loc,
6120 New_Reference_To (K, Loc),
6122 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6131 Make_Block_Statement (Loc,
6134 Handled_Statement_Sequence =>
6135 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6140 -- Delay triggering statement processing
6143 -- Add a Delay_Block object to the parameter list of the delay
6144 -- procedure to form the parameter list of the Wait entry call.
6147 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
6149 Pdef := Entity (Name (Ecall));
6151 if Is_RTE (Pdef, RO_CA_Delay_For) then
6153 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6155 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6157 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6159 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6160 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6163 Append_To (Parameter_Associations (Ecall),
6164 Make_Attribute_Reference (Loc,
6165 Prefix => New_Reference_To (Dblock_Ent, Loc),
6166 Attribute_Name => Name_Unchecked_Access));
6168 -- Create the inner block to protect the abortable part
6171 Make_Implicit_Exception_Handler (Loc,
6172 Exception_Choices =>
6173 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6174 Statements => New_List (
6175 Make_Procedure_Call_Statement (Loc,
6176 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6179 Make_Procedure_Call_Statement (Loc,
6180 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6183 Make_Block_Statement (Loc,
6184 Identifier => New_Reference_To (Blk_Ent, Loc),
6185 Handled_Statement_Sequence =>
6186 Make_Handled_Sequence_Of_Statements (Loc,
6187 Statements => Astats),
6188 Has_Created_Identifier => True,
6189 Is_Asynchronous_Call_Block => True);
6191 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6194 Make_Implicit_If_Statement (N,
6195 Condition => Make_Function_Call (Loc,
6196 Name => Enqueue_Call,
6197 Parameter_Associations => Parameter_Associations (Ecall)),
6199 New_List (Make_Block_Statement (Loc,
6200 Handled_Statement_Sequence =>
6201 Make_Handled_Sequence_Of_Statements (Loc,
6202 Statements => New_List (
6203 Make_Implicit_Label_Declaration (Loc,
6204 Defining_Identifier => Blk_Ent,
6205 Label_Construct => Abortable_Block),
6207 Exception_Handlers => Hdle)))));
6209 Stmts := New_List (Ecall);
6211 -- Construct statement sequence for new block
6214 Make_Implicit_If_Statement (N,
6215 Condition => Make_Function_Call (Loc,
6216 Name => New_Reference_To (
6217 RTE (RE_Timed_Out), Loc),
6218 Parameter_Associations => New_List (
6219 Make_Attribute_Reference (Loc,
6220 Prefix => New_Reference_To (Dblock_Ent, Loc),
6221 Attribute_Name => Name_Unchecked_Access))),
6222 Then_Statements => Tstats));
6224 -- The result is the new block
6226 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6229 Make_Block_Statement (Loc,
6230 Declarations => New_List (
6231 Make_Object_Declaration (Loc,
6232 Defining_Identifier => Dblock_Ent,
6233 Aliased_Present => True,
6234 Object_Definition => New_Reference_To (
6235 RTE (RE_Delay_Block), Loc))),
6237 Handled_Statement_Sequence =>
6238 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6248 Extract_Entry (Ecall, Concval, Ename, Index);
6249 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6251 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6252 Decls := Declarations (Ecall);
6254 if Is_Protected_Type (Etype (Concval)) then
6256 -- Get the declarations of the block expanded from the entry call
6258 Decl := First (Decls);
6259 while Present (Decl)
6261 (Nkind (Decl) /= N_Object_Declaration
6262 or else not Is_RTE (Etype (Object_Definition (Decl)),
6263 RE_Communication_Block))
6268 pragma Assert (Present (Decl));
6269 Cancel_Param := Defining_Identifier (Decl);
6271 -- Change the mode of the Protected_Entry_Call call
6273 -- Protected_Entry_Call (
6274 -- Object => po._object'Access,
6275 -- E => <entry index>;
6276 -- Uninterpreted_Data => P'Address;
6277 -- Mode => Asynchronous_Call;
6280 Stmt := First (Stmts);
6282 -- Skip assignments to temporaries created for in-out parameters
6284 -- This makes unwarranted assumptions about the shape of the expanded
6285 -- tree for the call, and should be cleaned up ???
6287 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6293 Param := First (Parameter_Associations (Call));
6294 while Present (Param)
6295 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6300 pragma Assert (Present (Param));
6301 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6304 -- Append an if statement to execute the abortable part
6307 -- if Enqueued (Bnn) then
6310 Make_Implicit_If_Statement (N,
6311 Condition => Make_Function_Call (Loc,
6312 Name => New_Reference_To (
6313 RTE (RE_Enqueued), Loc),
6314 Parameter_Associations => New_List (
6315 New_Reference_To (Cancel_Param, Loc))),
6316 Then_Statements => Astats));
6319 Make_Block_Statement (Loc,
6320 Identifier => New_Reference_To (Blk_Ent, Loc),
6321 Handled_Statement_Sequence =>
6322 Make_Handled_Sequence_Of_Statements (Loc,
6323 Statements => Stmts),
6324 Has_Created_Identifier => True,
6325 Is_Asynchronous_Call_Block => True);
6327 -- For the VM call Update_Exception instead of Abort_Undefer.
6328 -- See 4jexcept.ads for an explanation.
6330 if VM_Target = No_VM then
6331 Target_Undefer := RE_Abort_Undefer;
6333 Target_Undefer := RE_Update_Exception;
6335 New_List (Make_Function_Call (Loc,
6336 Name => New_Occurrence_Of
6337 (RTE (RE_Current_Target_Exception), Loc)));
6341 Make_Block_Statement (Loc,
6342 Handled_Statement_Sequence =>
6343 Make_Handled_Sequence_Of_Statements (Loc,
6344 Statements => New_List (
6345 Make_Implicit_Label_Declaration (Loc,
6346 Defining_Identifier => Blk_Ent,
6347 Label_Construct => Abortable_Block),
6352 Exception_Handlers => New_List (
6353 Make_Implicit_Exception_Handler (Loc,
6355 -- when Abort_Signal =>
6356 -- Abort_Undefer.all;
6358 Exception_Choices =>
6359 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6360 Statements => New_List (
6361 Make_Procedure_Call_Statement (Loc,
6362 Name => New_Reference_To (
6363 RTE (Target_Undefer), Loc),
6364 Parameter_Associations => Undefer_Args)))))),
6366 -- if not Cancelled (Bnn) then
6367 -- triggered statements
6370 Make_Implicit_If_Statement (N,
6371 Condition => Make_Op_Not (Loc,
6373 Make_Function_Call (Loc,
6374 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6375 Parameter_Associations => New_List (
6376 New_Occurrence_Of (Cancel_Param, Loc)))),
6377 Then_Statements => Tstats));
6379 -- Asynchronous task entry call
6386 B := Make_Defining_Identifier (Loc, Name_uB);
6388 -- Insert declaration of B in declarations of existing block
6391 Make_Object_Declaration (Loc,
6392 Defining_Identifier => B,
6393 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6395 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6397 -- Insert declaration of C in declarations of existing block
6400 Make_Object_Declaration (Loc,
6401 Defining_Identifier => Cancel_Param,
6402 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6404 -- Remove and save the call to Call_Simple
6406 Stmt := First (Stmts);
6408 -- Skip assignments to temporaries created for in-out parameters.
6409 -- This makes unwarranted assumptions about the shape of the expanded
6410 -- tree for the call, and should be cleaned up ???
6412 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6418 -- Create the inner block to protect the abortable part
6421 Make_Implicit_Exception_Handler (Loc,
6422 Exception_Choices =>
6423 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6426 Make_Procedure_Call_Statement (Loc,
6427 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6430 Make_Procedure_Call_Statement (Loc,
6431 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6434 Make_Block_Statement (Loc,
6435 Identifier => New_Reference_To (Blk_Ent, Loc),
6436 Handled_Statement_Sequence =>
6437 Make_Handled_Sequence_Of_Statements (Loc,
6438 Statements => Astats),
6439 Has_Created_Identifier => True,
6440 Is_Asynchronous_Call_Block => True);
6443 Make_Block_Statement (Loc,
6444 Handled_Statement_Sequence =>
6445 Make_Handled_Sequence_Of_Statements (Loc,
6446 Statements => New_List (
6447 Make_Implicit_Label_Declaration (Loc,
6448 Defining_Identifier =>
6453 Exception_Handlers => Hdle)));
6455 -- Create new call statement
6457 Params := Parameter_Associations (Call);
6460 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6462 New_Reference_To (B, Loc));
6465 Make_Procedure_Call_Statement (Loc,
6467 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6468 Parameter_Associations => Params));
6470 -- Construct statement sequence for new block
6473 Make_Implicit_If_Statement (N,
6476 New_Reference_To (Cancel_Param, Loc)),
6477 Then_Statements => Tstats));
6479 -- Protected the call against abort
6482 Make_Procedure_Call_Statement (Loc,
6483 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6484 Parameter_Associations => Empty_List));
6487 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6489 -- The result is the new block
6492 Make_Block_Statement (Loc,
6493 Declarations => Decls,
6494 Handled_Statement_Sequence =>
6495 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6498 end Expand_N_Asynchronous_Select;
6500 -------------------------------------
6501 -- Expand_N_Conditional_Entry_Call --
6502 -------------------------------------
6504 -- The conditional task entry call is converted to a call to
6509 -- P : parms := (parm, parm, parm);
6513 -- (<acceptor-task>, -- Acceptor
6514 -- <entry-index>, -- E
6515 -- P'Address, -- Uninterpreted_Data
6516 -- Conditional_Call, -- Mode
6517 -- B); -- Rendezvous_Successful
6522 -- normal-statements
6528 -- For a description of the use of P and the assignments after the call,
6529 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6530 -- conditional entry call has already been expanded (by the Expand_N_Entry
6531 -- _Call_Statement procedure) as follows:
6534 -- P : parms := (parm, parm, parm);
6536 -- ... info for in-out parameters
6537 -- Call_Simple (acceptor-task, entry-index, P'Address);
6543 -- so the task at hand is to convert the latter expansion into the former
6545 -- The conditional protected entry call is converted to a call to
6546 -- Protected_Entry_Call:
6549 -- P : parms := (parm, parm, parm);
6550 -- Bnn : Communications_Block;
6553 -- Protected_Entry_Call
6554 -- (po._object'Access, -- Object
6555 -- <entry index>, -- E
6556 -- P'Address, -- Uninterpreted_Data
6557 -- Conditional_Call, -- Mode
6562 -- if Cancelled (Bnn) then
6565 -- normal-statements
6569 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6573 -- B : Boolean := False;
6574 -- C : Ada.Tags.Prim_Op_Kind;
6575 -- K : Ada.Tags.Tagged_Kind :=
6576 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6577 -- P : Parameters := (Param1 .. ParamN);
6581 -- if K = Ada.Tags.TK_Limited_Tagged then
6582 -- <dispatching-call>;
6583 -- <triggering-statements>
6587 -- Ada.Tags.Get_Offset_Index
6588 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6590 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6592 -- if C = POK_Protected_Entry
6593 -- or else C = POK_Task_Entry
6595 -- Param1 := P.Param1;
6597 -- ParamN := P.ParamN;
6601 -- if C = POK_Procedure
6602 -- or else C = POK_Protected_Procedure
6603 -- or else C = POK_Task_Procedure
6605 -- <dispatching-call>;
6608 -- <triggering-statements>
6610 -- <else-statements>
6615 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6616 Loc : constant Source_Ptr := Sloc (N);
6617 Alt : constant Node_Id := Entry_Call_Alternative (N);
6618 Blk : Node_Id := Entry_Call_Statement (Alt);
6621 Blk_Typ : Entity_Id;
6623 Call_Ent : Entity_Id;
6624 Conc_Typ_Stmts : List_Id;
6628 Lim_Typ_Stmts : List_Id;
6635 Transient_Blk : Node_Id;
6638 B : Entity_Id; -- Call status flag
6639 C : Entity_Id; -- Call kind
6640 K : Entity_Id; -- Tagged kind
6641 P : Entity_Id; -- Parameter block
6642 S : Entity_Id; -- Primitive operation slot
6645 if Ada_Version >= Ada_05
6646 and then Nkind (Blk) = N_Procedure_Call_Statement
6648 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6653 -- Call status flag processing, generate:
6654 -- B : Boolean := False;
6656 B := Build_B (Loc, Decls);
6658 -- Call kind processing, generate:
6659 -- C : Ada.Tags.Prim_Op_Kind;
6661 C := Build_C (Loc, Decls);
6663 -- Tagged kind processing, generate:
6664 -- K : Ada.Tags.Tagged_Kind :=
6665 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6667 K := Build_K (Loc, Decls, Obj);
6669 -- Parameter block processing
6671 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6672 P := Parameter_Block_Pack
6673 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6675 -- Dispatch table slot processing, generate:
6678 S := Build_S (Loc, Decls);
6681 -- S := Ada.Tags.Get_Offset_Index
6682 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6685 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6688 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6690 Append_To (Conc_Typ_Stmts,
6691 Make_Procedure_Call_Statement (Loc,
6694 Find_Prim_Op (Etype (Etype (Obj)),
6695 Name_uDisp_Conditional_Select),
6697 Parameter_Associations =>
6699 New_Copy_Tree (Obj), -- <object>
6700 New_Reference_To (S, Loc), -- S
6701 Make_Attribute_Reference (Loc, -- P'Address
6703 New_Reference_To (P, Loc),
6706 New_Reference_To (C, Loc), -- C
6707 New_Reference_To (B, Loc)))); -- B
6710 -- if C = POK_Protected_Entry
6711 -- or else C = POK_Task_Entry
6713 -- Param1 := P.Param1;
6715 -- ParamN := P.ParamN;
6718 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6720 -- Generate the if statement only when the packed parameters need
6721 -- explicit assignments to their corresponding actuals.
6723 if Present (Unpack) then
6724 Append_To (Conc_Typ_Stmts,
6725 Make_If_Statement (Loc,
6732 New_Reference_To (C, Loc),
6734 New_Reference_To (RTE (
6735 RE_POK_Protected_Entry), Loc)),
6739 New_Reference_To (C, Loc),
6741 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6749 -- if C = POK_Procedure
6750 -- or else C = POK_Protected_Procedure
6751 -- or else C = POK_Task_Procedure
6753 -- <dispatching-call>
6755 -- <normal-statements>
6757 -- <else-statements>
6760 N_Stats := New_Copy_List_Tree (Statements (Alt));
6762 Prepend_To (N_Stats,
6763 Make_If_Statement (Loc,
6769 New_Reference_To (C, Loc),
6771 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6778 New_Reference_To (C, Loc),
6780 New_Reference_To (RTE (
6781 RE_POK_Protected_Procedure), Loc)),
6786 New_Reference_To (C, Loc),
6788 New_Reference_To (RTE (
6789 RE_POK_Task_Procedure), Loc)))),
6794 Append_To (Conc_Typ_Stmts,
6795 Make_If_Statement (Loc,
6796 Condition => New_Reference_To (B, Loc),
6797 Then_Statements => N_Stats,
6798 Else_Statements => Else_Statements (N)));
6801 -- <dispatching-call>;
6802 -- <triggering-statements>
6804 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6805 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6808 -- if K = Ada.Tags.TK_Limited_Tagged then
6815 Make_If_Statement (Loc,
6819 New_Reference_To (K, Loc),
6821 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6830 Make_Block_Statement (Loc,
6833 Handled_Statement_Sequence =>
6834 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6836 -- As described above, The entry alternative is transformed into a
6837 -- block that contains the gnulli call, and possibly assignment
6838 -- statements for in-out parameters. The gnulli call may itself be
6839 -- rewritten into a transient block if some unconstrained parameters
6840 -- require it. We need to retrieve the call to complete its parameter
6845 First_Real_Statement (Handled_Statement_Sequence (Blk));
6847 if Present (Transient_Blk)
6848 and then Nkind (Transient_Blk) = N_Block_Statement
6850 Blk := Transient_Blk;
6853 Stmts := Statements (Handled_Statement_Sequence (Blk));
6854 Stmt := First (Stmts);
6855 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6860 Params := Parameter_Associations (Call);
6862 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6864 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6866 Param := First (Params);
6867 while Present (Param)
6868 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6873 pragma Assert (Present (Param));
6874 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6878 -- Find the Communication_Block parameter for the call to the
6879 -- Cancelled function.
6881 Decl := First (Declarations (Blk));
6882 while Present (Decl)
6883 and then not Is_RTE (Etype (Object_Definition (Decl)),
6884 RE_Communication_Block)
6889 -- Add an if statement to execute the else part if the call
6890 -- does not succeed (as indicated by the Cancelled predicate).
6893 Make_Implicit_If_Statement (N,
6894 Condition => Make_Function_Call (Loc,
6895 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6896 Parameter_Associations => New_List (
6897 New_Reference_To (Defining_Identifier (Decl), Loc))),
6898 Then_Statements => Else_Statements (N),
6899 Else_Statements => Statements (Alt)));
6902 B := Make_Defining_Identifier (Loc, Name_uB);
6904 -- Insert declaration of B in declarations of existing block
6906 if No (Declarations (Blk)) then
6907 Set_Declarations (Blk, New_List);
6910 Prepend_To (Declarations (Blk),
6911 Make_Object_Declaration (Loc,
6912 Defining_Identifier => B,
6913 Object_Definition =>
6914 New_Reference_To (Standard_Boolean, Loc)));
6916 -- Create new call statement
6919 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6920 Append_To (Params, New_Reference_To (B, Loc));
6923 Make_Procedure_Call_Statement (Loc,
6924 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6925 Parameter_Associations => Params));
6927 -- Construct statement sequence for new block
6930 Make_Implicit_If_Statement (N,
6931 Condition => New_Reference_To (B, Loc),
6932 Then_Statements => Statements (Alt),
6933 Else_Statements => Else_Statements (N)));
6936 -- The result is the new block
6939 Make_Block_Statement (Loc,
6940 Declarations => Declarations (Blk),
6941 Handled_Statement_Sequence =>
6942 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6946 end Expand_N_Conditional_Entry_Call;
6948 ---------------------------------------
6949 -- Expand_N_Delay_Relative_Statement --
6950 ---------------------------------------
6952 -- Delay statement is implemented as a procedure call to Delay_For
6953 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6954 -- simple delays imposed by the use of Protected Objects.
6956 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6957 Loc : constant Source_Ptr := Sloc (N);
6960 Make_Procedure_Call_Statement (Loc,
6961 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6962 Parameter_Associations => New_List (Expression (N))));
6964 end Expand_N_Delay_Relative_Statement;
6966 ------------------------------------
6967 -- Expand_N_Delay_Until_Statement --
6968 ------------------------------------
6970 -- Delay Until statement is implemented as a procedure call to
6971 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6973 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6974 Loc : constant Source_Ptr := Sloc (N);
6978 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6979 Typ := RTE (RO_CA_Delay_Until);
6981 Typ := RTE (RO_RT_Delay_Until);
6985 Make_Procedure_Call_Statement (Loc,
6986 Name => New_Reference_To (Typ, Loc),
6987 Parameter_Associations => New_List (Expression (N))));
6990 end Expand_N_Delay_Until_Statement;
6992 -------------------------
6993 -- Expand_N_Entry_Body --
6994 -------------------------
6996 procedure Expand_N_Entry_Body (N : Node_Id) is
6998 -- Associate discriminals with the next protected operation body to be
7001 if Present (Next_Protected_Operation (N)) then
7002 Set_Discriminals (Parent (Current_Scope));
7004 end Expand_N_Entry_Body;
7006 -----------------------------------
7007 -- Expand_N_Entry_Call_Statement --
7008 -----------------------------------
7010 -- An entry call is expanded into GNARLI calls to implement a simple entry
7011 -- call (see Build_Simple_Entry_Call).
7013 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7019 if No_Run_Time_Mode then
7020 Error_Msg_CRT ("entry call", N);
7024 -- If this entry call is part of an asynchronous select, don't expand it
7025 -- here; it will be expanded with the select statement. Don't expand
7026 -- timed entry calls either, as they are translated into asynchronous
7029 -- ??? This whole approach is questionable; it may be better to go back
7030 -- to allowing the expansion to take place and then attempting to fix it
7031 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7032 -- whether the expanded call is on a task or protected entry.
7034 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7035 or else N /= Triggering_Statement (Parent (N)))
7036 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7037 or else N /= Entry_Call_Statement (Parent (N))
7038 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7040 Extract_Entry (N, Concval, Ename, Index);
7041 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7043 end Expand_N_Entry_Call_Statement;
7045 --------------------------------
7046 -- Expand_N_Entry_Declaration --
7047 --------------------------------
7049 -- If there are parameters, then first, each of the formals is marked by
7050 -- setting Is_Entry_Formal. Next a record type is built which is used to
7051 -- hold the parameter values. The name of this record type is entryP where
7052 -- entry is the name of the entry, with an additional corresponding access
7053 -- type called entryPA. The record type has matching components for each
7054 -- formal (the component names are the same as the formal names). For
7055 -- elementary types, the component type matches the formal type. For
7056 -- composite types, an access type is declared (with the name formalA)
7057 -- which designates the formal type, and the type of the component is this
7058 -- access type. Finally the Entry_Component of each formal is set to
7059 -- reference the corresponding record component.
7061 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7062 Loc : constant Source_Ptr := Sloc (N);
7063 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7064 Components : List_Id;
7067 Last_Decl : Node_Id;
7068 Component : Entity_Id;
7071 Rec_Ent : Entity_Id;
7072 Acc_Ent : Entity_Id;
7075 Formal := First_Formal (Entry_Ent);
7078 -- Most processing is done only if parameters are present
7080 if Present (Formal) then
7081 Components := New_List;
7083 -- Loop through formals
7085 while Present (Formal) loop
7086 Set_Is_Entry_Formal (Formal);
7088 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7089 Set_Entry_Component (Formal, Component);
7090 Set_Entry_Formal (Component, Formal);
7091 Ftype := Etype (Formal);
7093 -- Declare new access type and then append
7096 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7099 Make_Full_Type_Declaration (Loc,
7100 Defining_Identifier => Ctype,
7102 Make_Access_To_Object_Definition (Loc,
7103 All_Present => True,
7104 Constant_Present => Ekind (Formal) = E_In_Parameter,
7105 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7107 Insert_After (Last_Decl, Decl);
7110 Append_To (Components,
7111 Make_Component_Declaration (Loc,
7112 Defining_Identifier => Component,
7113 Component_Definition =>
7114 Make_Component_Definition (Loc,
7115 Aliased_Present => False,
7116 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7118 Next_Formal_With_Extras (Formal);
7121 -- Create the Entry_Parameter_Record declaration
7124 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
7127 Make_Full_Type_Declaration (Loc,
7128 Defining_Identifier => Rec_Ent,
7130 Make_Record_Definition (Loc,
7132 Make_Component_List (Loc,
7133 Component_Items => Components)));
7135 Insert_After (Last_Decl, Decl);
7138 -- Construct and link in the corresponding access type
7141 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
7143 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7146 Make_Full_Type_Declaration (Loc,
7147 Defining_Identifier => Acc_Ent,
7149 Make_Access_To_Object_Definition (Loc,
7150 All_Present => True,
7151 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7153 Insert_After (Last_Decl, Decl);
7156 end Expand_N_Entry_Declaration;
7158 -----------------------------
7159 -- Expand_N_Protected_Body --
7160 -----------------------------
7162 -- Protected bodies are expanded to the completion of the subprograms
7163 -- created for the corresponding protected type. These are a protected and
7164 -- unprotected version of each protected subprogram in the object, a
7165 -- function to calculate each entry barrier, and a procedure to execute the
7166 -- sequence of statements of each protected entry body. For example, for
7167 -- protected type ptype:
7170 -- (O : System.Address;
7171 -- E : Protected_Entry_Index)
7174 -- <discriminant renamings>
7175 -- <private object renamings>
7177 -- return <barrier expression>;
7180 -- procedure pprocN (_object : in out poV;...) is
7181 -- <discriminant renamings>
7182 -- <private object renamings>
7184 -- <sequence of statements>
7187 -- procedure pprocP (_object : in out poV;...) is
7188 -- procedure _clean is
7191 -- ptypeS (_object, Pn);
7192 -- Unlock (_object._object'Access);
7193 -- Abort_Undefer.all;
7198 -- Lock (_object._object'Access);
7199 -- pprocN (_object;...);
7204 -- function pfuncN (_object : poV;...) return Return_Type is
7205 -- <discriminant renamings>
7206 -- <private object renamings>
7208 -- <sequence of statements>
7211 -- function pfuncP (_object : poV) return Return_Type is
7212 -- procedure _clean is
7214 -- Unlock (_object._object'Access);
7215 -- Abort_Undefer.all;
7220 -- Lock (_object._object'Access);
7221 -- return pfuncN (_object);
7228 -- (O : System.Address;
7229 -- P : System.Address;
7230 -- E : Protected_Entry_Index)
7232 -- <discriminant renamings>
7233 -- <private object renamings>
7234 -- type poVP is access poV;
7235 -- _Object : ptVP := ptVP!(O);
7239 -- <statement sequence>
7240 -- Complete_Entry_Body (_Object._Object);
7242 -- when all others =>
7243 -- Exceptional_Complete_Entry_Body (
7244 -- _Object._Object, Get_GNAT_Exception);
7248 -- The type poV is the record created for the protected type to hold
7249 -- the state of the protected object.
7251 procedure Expand_N_Protected_Body (N : Node_Id) is
7252 Loc : constant Source_Ptr := Sloc (N);
7253 Pid : constant Entity_Id := Corresponding_Spec (N);
7255 Current_Node : Node_Id;
7256 Disp_Op_Body : Node_Id;
7257 New_Op_Body : Node_Id;
7258 Num_Entries : Natural := 0;
7262 Chain : Entity_Id := Empty;
7263 -- Finalization chain that may be attached to new body
7265 function Build_Dispatching_Subprogram_Body
7268 Prot_Bod : Node_Id) return Node_Id;
7269 -- Build a dispatching version of the protected subprogram body. The
7270 -- newly generated subprogram contains a call to the original protected
7271 -- body. The following code is generated:
7273 -- function <protected-function-name> (Param1 .. ParamN) return
7276 -- return <protected-function-name>P (Param1 .. ParamN);
7277 -- end <protected-function-name>;
7281 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7283 -- <protected-procedure-name>P (Param1 .. ParamN);
7284 -- end <protected-procedure-name>
7286 ---------------------------------------
7287 -- Build_Dispatching_Subprogram_Body --
7288 ---------------------------------------
7290 function Build_Dispatching_Subprogram_Body
7293 Prot_Bod : Node_Id) return Node_Id
7295 Loc : constant Source_Ptr := Sloc (N);
7302 -- Generate a specification without a letter suffix in order to
7303 -- override an interface function or procedure.
7306 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7308 -- The formal parameters become the actuals of the protected
7309 -- function or procedure call.
7311 Actuals := New_List;
7312 Formal := First (Parameter_Specifications (Spec));
7313 while Present (Formal) loop
7315 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7320 if Nkind (Spec) = N_Procedure_Specification then
7323 Make_Procedure_Call_Statement (Loc,
7325 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7326 Parameter_Associations => Actuals));
7328 pragma Assert (Nkind (Spec) = N_Function_Specification);
7332 Make_Simple_Return_Statement (Loc,
7334 Make_Function_Call (Loc,
7336 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7337 Parameter_Associations => Actuals)));
7341 Make_Subprogram_Body (Loc,
7342 Declarations => Empty_List,
7343 Specification => Spec,
7344 Handled_Statement_Sequence =>
7345 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7346 end Build_Dispatching_Subprogram_Body;
7348 -- Start of processing for Expand_N_Protected_Body
7351 if No_Run_Time_Mode then
7352 Error_Msg_CRT ("protected body", N);
7356 -- This is the proper body corresponding to a stub. The declarations
7357 -- must be inserted at the point of the stub, which in turn is in the
7358 -- declarative part of the parent unit.
7360 if Nkind (Parent (N)) = N_Subunit then
7361 Current_Node := Corresponding_Stub (Parent (N));
7366 Op_Body := First (Declarations (N));
7368 -- The protected body is replaced with the bodies of its
7369 -- protected operations, and the declarations for internal objects
7370 -- that may have been created for entry family bounds.
7372 Rewrite (N, Make_Null_Statement (Sloc (N)));
7375 while Present (Op_Body) loop
7376 case Nkind (Op_Body) is
7377 when N_Subprogram_Declaration =>
7380 when N_Subprogram_Body =>
7382 -- Do not create bodies for eliminated operations
7384 if not Is_Eliminated (Defining_Entity (Op_Body))
7385 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7388 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7390 -- Propagate the finalization chain to the new body. In the
7391 -- unlikely event that the subprogram contains a declaration
7392 -- or allocator for an object that requires finalization,
7393 -- the corresponding chain is created when analyzing the
7394 -- body, and attached to its entity. This entity is not
7395 -- further elaborated, and so the chain properly belongs to
7396 -- the newly created subprogram body.
7399 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7401 if Present (Chain) then
7402 Set_Finalization_Chain_Entity
7403 (Protected_Body_Subprogram
7404 (Corresponding_Spec (Op_Body)), Chain);
7406 (Handled_Statement_Sequence (New_Op_Body), False);
7409 Insert_After (Current_Node, New_Op_Body);
7410 Current_Node := New_Op_Body;
7411 Analyze (New_Op_Body);
7413 -- Build the corresponding protected operation. It may
7414 -- appear that this is needed only if this is a visible
7415 -- operation of the type, or if it is an interrupt handler,
7416 -- and this was the strategy used previously in GNAT.
7417 -- However, the operation may be exported through a 'Access
7418 -- to an external caller. This is the common idiom in code
7419 -- that uses the Ada 2005 Timing_Events package. As a result
7420 -- we need to produce the protected body for both visible
7421 -- and private operations, as well as operations that only
7422 -- have a body in the source, and for which we create a
7423 -- declaration in the protected body itself.
7425 if Present (Corresponding_Spec (Op_Body)) then
7427 Build_Protected_Subprogram_Body (
7428 Op_Body, Pid, Specification (New_Op_Body));
7430 Insert_After (Current_Node, New_Op_Body);
7431 Analyze (New_Op_Body);
7433 Current_Node := New_Op_Body;
7435 -- Generate an overriding primitive operation body for
7436 -- this subprogram if the protected type implements an
7439 if Ada_Version >= Ada_05
7441 Present (Interfaces (Corresponding_Record_Type (Pid)))
7444 Build_Dispatching_Subprogram_Body
7445 (Op_Body, Pid, New_Op_Body);
7447 Insert_After (Current_Node, Disp_Op_Body);
7448 Analyze (Disp_Op_Body);
7450 Current_Node := Disp_Op_Body;
7455 when N_Entry_Body =>
7456 Op_Id := Defining_Identifier (Op_Body);
7457 Num_Entries := Num_Entries + 1;
7459 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7461 Insert_After (Current_Node, New_Op_Body);
7462 Current_Node := New_Op_Body;
7463 Analyze (New_Op_Body);
7465 when N_Implicit_Label_Declaration =>
7468 when N_Itype_Reference =>
7469 Insert_After (Current_Node, New_Copy (Op_Body));
7471 when N_Freeze_Entity =>
7472 New_Op_Body := New_Copy (Op_Body);
7474 if Present (Entity (Op_Body))
7475 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7477 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7480 Insert_After (Current_Node, New_Op_Body);
7481 Current_Node := New_Op_Body;
7482 Analyze (New_Op_Body);
7485 New_Op_Body := New_Copy (Op_Body);
7486 Insert_After (Current_Node, New_Op_Body);
7487 Current_Node := New_Op_Body;
7488 Analyze (New_Op_Body);
7490 when N_Object_Declaration =>
7491 pragma Assert (not Comes_From_Source (Op_Body));
7492 New_Op_Body := New_Copy (Op_Body);
7493 Insert_After (Current_Node, New_Op_Body);
7494 Current_Node := New_Op_Body;
7495 Analyze (New_Op_Body);
7498 raise Program_Error;
7505 -- Finally, create the body of the function that maps an entry index
7506 -- into the corresponding body index, except when there is no entry, or
7507 -- in a Ravenscar-like profile.
7509 if Corresponding_Runtime_Package (Pid) =
7510 System_Tasking_Protected_Objects_Entries
7512 New_Op_Body := Build_Find_Body_Index (Pid);
7513 Insert_After (Current_Node, New_Op_Body);
7514 Current_Node := New_Op_Body;
7515 Analyze (New_Op_Body);
7518 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7519 -- protected body. At this point all wrapper specs have been created,
7520 -- frozen and included in the dispatch table for the protected type.
7522 if Ada_Version >= Ada_05 then
7523 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7525 end Expand_N_Protected_Body;
7527 -----------------------------------------
7528 -- Expand_N_Protected_Type_Declaration --
7529 -----------------------------------------
7531 -- First we create a corresponding record type declaration used to
7532 -- represent values of this protected type.
7533 -- The general form of this type declaration is
7535 -- type poV (discriminants) is record
7536 -- _Object : aliased <kind>Protection
7537 -- [(<entry count> [, <handler count>])];
7538 -- [entry_family : array (bounds) of Void;]
7539 -- <private data fields>
7542 -- The discriminants are present only if the corresponding protected type
7543 -- has discriminants, and they exactly mirror the protected type
7544 -- discriminants. The private data fields similarly mirror the private
7545 -- declarations of the protected type.
7547 -- The Object field is always present. It contains RTS specific data used
7548 -- to control the protected object. It is declared as Aliased so that it
7549 -- can be passed as a pointer to the RTS. This allows the protected record
7550 -- to be referenced within RTS data structures. An appropriate Protection
7551 -- type and discriminant are generated.
7553 -- The Service field is present for protected objects with entries. It
7554 -- contains sufficient information to allow the entry service procedure for
7555 -- this object to be called when the object is not known till runtime.
7557 -- One entry_family component is present for each entry family in the
7558 -- task definition (see Expand_N_Task_Type_Declaration).
7560 -- When a protected object is declared, an instance of the protected type
7561 -- value record is created. The elaboration of this declaration creates the
7562 -- correct bounds for the entry families, and also evaluates the priority
7563 -- expression if needed. The initialization routine for the protected type
7564 -- itself then calls Initialize_Protection with appropriate parameters to
7565 -- initialize the value of the Task_Id field. Install_Handlers may be also
7566 -- called if a pragma Attach_Handler applies.
7568 -- Note: this record is passed to the subprograms created by the expansion
7569 -- of protected subprograms and entries. It is an in parameter to protected
7570 -- functions and an in out parameter to procedures and entry bodies. The
7571 -- Entity_Id for this created record type is placed in the
7572 -- Corresponding_Record_Type field of the associated protected type entity.
7574 -- Next we create a procedure specifications for protected subprograms and
7575 -- entry bodies. For each protected subprograms two subprograms are
7576 -- created, an unprotected and a protected version. The unprotected version
7577 -- is called from within other operations of the same protected object.
7579 -- We also build the call to register the procedure if a pragma
7580 -- Interrupt_Handler applies.
7582 -- A single subprogram is created to service all entry bodies; it has an
7583 -- additional boolean out parameter indicating that the previous entry call
7584 -- made by the current task was serviced immediately, i.e. not by proxy.
7585 -- The O parameter contains a pointer to a record object of the type
7586 -- described above. An untyped interface is used here to allow this
7587 -- procedure to be called in places where the type of the object to be
7588 -- serviced is not known. This must be done, for example, when a call that
7589 -- may have been requeued is cancelled; the corresponding object must be
7590 -- serviced, but which object that is not known till runtime.
7593 -- (O : System.Address; P : out Boolean);
7594 -- procedure pprocN (_object : in out poV);
7595 -- procedure pproc (_object : in out poV);
7596 -- function pfuncN (_object : poV);
7597 -- function pfunc (_object : poV);
7600 -- Note that this must come after the record type declaration, since
7601 -- the specs refer to this type.
7603 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7604 Loc : constant Source_Ptr := Sloc (N);
7605 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7607 Pdef : constant Node_Id := Protected_Definition (N);
7608 -- This contains two lists; one for visible and one for private decls
7612 Discr_Map : constant Elist_Id := New_Elmt_List;
7616 Comp_Id : Entity_Id;
7618 Current_Node : Node_Id := N;
7619 Bdef : Entity_Id := Empty; -- avoid uninit warning
7620 Edef : Entity_Id := Empty; -- avoid uninit warning
7621 Entries_Aggr : Node_Id;
7622 Body_Id : Entity_Id;
7625 Object_Comp : Node_Id;
7627 procedure Check_Inlining (Subp : Entity_Id);
7628 -- If the original operation has a pragma Inline, propagate the flag
7629 -- to the internal body, for possible inlining later on. The source
7630 -- operation is invisible to the back-end and is never actually called.
7632 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7633 -- When compiling under the Ravenscar profile, private components must
7634 -- have a static size, or else a protected object will require heap
7635 -- allocation, violating the corresponding restriction. It is preferable
7636 -- to make this check here, because it provides a better error message
7637 -- than the back-end, which refers to the object as a whole.
7639 procedure Register_Handler;
7640 -- For a protected operation that is an interrupt handler, add the
7641 -- freeze action that will register it as such.
7643 --------------------
7644 -- Check_Inlining --
7645 --------------------
7647 procedure Check_Inlining (Subp : Entity_Id) is
7649 if Is_Inlined (Subp) then
7650 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7651 Set_Is_Inlined (Subp, False);
7655 ---------------------------------
7656 -- Check_Static_Component_Size --
7657 ---------------------------------
7659 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7660 Typ : constant Entity_Id := Etype (Comp);
7664 if Is_Scalar_Type (Typ) then
7667 elsif Is_Array_Type (Typ) then
7668 return Compile_Time_Known_Bounds (Typ);
7670 elsif Is_Record_Type (Typ) then
7671 C := First_Component (Typ);
7672 while Present (C) loop
7673 if not Static_Component_Size (C) then
7682 -- Any other types will be checked by the back-end
7687 end Static_Component_Size;
7689 ----------------------
7690 -- Register_Handler --
7691 ----------------------
7693 procedure Register_Handler is
7695 -- All semantic checks already done in Sem_Prag
7697 Prot_Proc : constant Entity_Id :=
7699 (Specification (Current_Node));
7701 Proc_Address : constant Node_Id :=
7702 Make_Attribute_Reference (Loc,
7703 Prefix => New_Reference_To (Prot_Proc, Loc),
7704 Attribute_Name => Name_Address);
7706 RTS_Call : constant Entity_Id :=
7707 Make_Procedure_Call_Statement (Loc,
7710 RTE (RE_Register_Interrupt_Handler), Loc),
7711 Parameter_Associations =>
7712 New_List (Proc_Address));
7714 Append_Freeze_Action (Prot_Proc, RTS_Call);
7715 end Register_Handler;
7717 -- Start of processing for Expand_N_Protected_Type_Declaration
7720 if Present (Corresponding_Record_Type (Prot_Typ)) then
7723 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7726 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7728 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7729 -- of implemented interfaces.
7731 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
7733 Qualify_Entity_Names (N);
7735 -- If the type has discriminants, their occurrences in the declaration
7736 -- have been replaced by the corresponding discriminals. For components
7737 -- that are constrained by discriminants, their homologues in the
7738 -- corresponding record type must refer to the discriminants of that
7739 -- record, so we must apply a new renaming to subtypes_indications:
7741 -- protected discriminant => discriminal => record discriminant
7743 -- This replacement is not applied to default expressions, for which
7744 -- the discriminal is correct.
7746 if Has_Discriminants (Prot_Typ) then
7752 Disc := First_Discriminant (Prot_Typ);
7753 Decl := First (Discriminant_Specifications (Rec_Decl));
7754 while Present (Disc) loop
7755 Append_Elmt (Discriminal (Disc), Discr_Map);
7756 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7757 Next_Discriminant (Disc);
7763 -- Fill in the component declarations
7765 -- Add components for entry families. For each entry family, create an
7766 -- anonymous type declaration with the same size, and analyze the type.
7768 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7770 -- Prepend the _Object field with the right type to the component list.
7771 -- We need to compute the number of entries, and in some cases the
7772 -- number of Attach_Handler pragmas.
7776 Num_Attach_Handler : Int := 0;
7777 Protection_Subtype : Node_Id;
7778 Entry_Count_Expr : constant Node_Id :=
7779 Build_Entry_Count_Expression
7780 (Prot_Typ, Cdecls, Loc);
7783 -- Could this be simplified using Corresponding_Runtime_Package???
7785 if Has_Attach_Handler (Prot_Typ) then
7786 Ritem := First_Rep_Item (Prot_Typ);
7787 while Present (Ritem) loop
7788 if Nkind (Ritem) = N_Pragma
7789 and then Pragma_Name (Ritem) = Name_Attach_Handler
7791 Num_Attach_Handler := Num_Attach_Handler + 1;
7794 Next_Rep_Item (Ritem);
7797 if Restricted_Profile then
7798 if Has_Entries (Prot_Typ) then
7799 Protection_Subtype :=
7800 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7802 Protection_Subtype :=
7803 New_Reference_To (RTE (RE_Protection), Loc);
7806 Protection_Subtype :=
7807 Make_Subtype_Indication
7811 (RTE (RE_Static_Interrupt_Protection), Loc),
7813 Make_Index_Or_Discriminant_Constraint (
7815 Constraints => New_List (
7817 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7820 elsif Has_Interrupt_Handler (Prot_Typ) then
7821 Protection_Subtype :=
7822 Make_Subtype_Indication (
7824 Subtype_Mark => New_Reference_To
7825 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7827 Make_Index_Or_Discriminant_Constraint (
7829 Constraints => New_List (Entry_Count_Expr)));
7831 -- Type has explicit entries or generated primitive entry wrappers
7833 elsif Has_Entries (Prot_Typ)
7834 or else (Ada_Version >= Ada_05
7835 and then Present (Interface_List (N)))
7837 case Corresponding_Runtime_Package (Prot_Typ) is
7838 when System_Tasking_Protected_Objects_Entries =>
7839 Protection_Subtype :=
7840 Make_Subtype_Indication (Loc,
7842 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7844 Make_Index_Or_Discriminant_Constraint (
7846 Constraints => New_List (Entry_Count_Expr)));
7848 when System_Tasking_Protected_Objects_Single_Entry =>
7849 Protection_Subtype :=
7850 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7853 raise Program_Error;
7857 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7861 Make_Component_Declaration (Loc,
7862 Defining_Identifier =>
7863 Make_Defining_Identifier (Loc, Name_uObject),
7864 Component_Definition =>
7865 Make_Component_Definition (Loc,
7866 Aliased_Present => True,
7867 Subtype_Indication => Protection_Subtype));
7870 pragma Assert (Present (Pdef));
7872 -- Add private field components
7874 if Present (Private_Declarations (Pdef)) then
7875 Priv := First (Private_Declarations (Pdef));
7877 while Present (Priv) loop
7879 if Nkind (Priv) = N_Component_Declaration then
7880 if not Static_Component_Size (Defining_Identifier (Priv)) then
7882 -- When compiling for a restricted profile, the private
7883 -- components must have a static size. If not, this is an
7884 -- error for a single protected declaration, and rates a
7885 -- warning on a protected type declaration.
7887 if not Comes_From_Source (Prot_Typ) then
7888 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
7890 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
7891 Error_Msg_N ("component has non-static size?", Priv);
7893 ("\creation of protected object of type& will violate"
7894 & " restriction No_Implicit_Heap_Allocations?",
7899 -- The component definition consists of a subtype indication,
7900 -- or (in Ada 2005) an access definition. Make a copy of the
7901 -- proper definition.
7904 Old_Comp : constant Node_Id := Component_Definition (Priv);
7905 Oent : constant Entity_Id := Defining_Identifier (Priv);
7907 Nent : constant Entity_Id :=
7908 Make_Defining_Identifier (Sloc (Oent),
7909 Chars => Chars (Oent));
7912 if Present (Subtype_Indication (Old_Comp)) then
7914 Make_Component_Definition (Sloc (Oent),
7915 Aliased_Present => False,
7916 Subtype_Indication =>
7917 New_Copy_Tree (Subtype_Indication (Old_Comp),
7921 Make_Component_Definition (Sloc (Oent),
7922 Aliased_Present => False,
7923 Access_Definition =>
7924 New_Copy_Tree (Access_Definition (Old_Comp),
7929 Make_Component_Declaration (Loc,
7930 Defining_Identifier => Nent,
7931 Component_Definition => New_Comp,
7932 Expression => Expression (Priv));
7934 Set_Has_Per_Object_Constraint (Nent,
7935 Has_Per_Object_Constraint (Oent));
7937 Append_To (Cdecls, New_Priv);
7940 elsif Nkind (Priv) = N_Subprogram_Declaration then
7942 -- Make the unprotected version of the subprogram available
7943 -- for expansion of intra object calls. There is need for
7944 -- a protected version only if the subprogram is an interrupt
7945 -- handler, otherwise this operation can only be called from
7949 Make_Subprogram_Declaration (Loc,
7951 Build_Protected_Sub_Specification
7952 (Priv, Prot_Typ, Unprotected_Mode));
7954 Insert_After (Current_Node, Sub);
7957 Set_Protected_Body_Subprogram
7958 (Defining_Unit_Name (Specification (Priv)),
7959 Defining_Unit_Name (Specification (Sub)));
7960 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
7961 Current_Node := Sub;
7964 Make_Subprogram_Declaration (Loc,
7966 Build_Protected_Sub_Specification
7967 (Priv, Prot_Typ, Protected_Mode));
7969 Insert_After (Current_Node, Sub);
7971 Current_Node := Sub;
7973 if Is_Interrupt_Handler
7974 (Defining_Unit_Name (Specification (Priv)))
7976 if not Restricted_Profile then
7986 -- Put the _Object component after the private component so that it
7987 -- be finalized early as required by 9.4 (20)
7989 Append_To (Cdecls, Object_Comp);
7991 Insert_After (Current_Node, Rec_Decl);
7992 Current_Node := Rec_Decl;
7994 -- Analyze the record declaration immediately after construction,
7995 -- because the initialization procedure is needed for single object
7996 -- declarations before the next entity is analyzed (the freeze call
7997 -- that generates this initialization procedure is found below).
7999 Analyze (Rec_Decl, Suppress => All_Checks);
8001 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8002 -- the corresponding record is frozen. If any wrappers are generated,
8003 -- Current_Node is updated accordingly.
8005 if Ada_Version >= Ada_05 then
8006 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8009 -- Collect pointers to entry bodies and their barriers, to be placed
8010 -- in the Entry_Bodies_Array for the type. For each entry/family we
8011 -- add an expression to the aggregate which is the initial value of
8012 -- this array. The array is declared after all protected subprograms.
8014 if Has_Entries (Prot_Typ) then
8015 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8017 Entries_Aggr := Empty;
8020 -- Build two new procedure specifications for each protected subprogram;
8021 -- one to call from outside the object and one to call from inside.
8022 -- Build a barrier function and an entry body action procedure
8023 -- specification for each protected entry. Initialize the entry body
8024 -- array. If subprogram is flagged as eliminated, do not generate any
8025 -- internal operations.
8029 Comp := First (Visible_Declarations (Pdef));
8031 while Present (Comp) loop
8032 if Nkind (Comp) = N_Subprogram_Declaration then
8034 Make_Subprogram_Declaration (Loc,
8036 Build_Protected_Sub_Specification
8037 (Comp, Prot_Typ, Unprotected_Mode));
8039 Insert_After (Current_Node, Sub);
8042 Set_Protected_Body_Subprogram
8043 (Defining_Unit_Name (Specification (Comp)),
8044 Defining_Unit_Name (Specification (Sub)));
8045 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8047 -- Make the protected version of the subprogram available for
8048 -- expansion of external calls.
8050 Current_Node := Sub;
8053 Make_Subprogram_Declaration (Loc,
8055 Build_Protected_Sub_Specification
8056 (Comp, Prot_Typ, Protected_Mode));
8058 Insert_After (Current_Node, Sub);
8061 Current_Node := Sub;
8063 -- Generate an overriding primitive operation specification for
8064 -- this subprogram if the protected type implements an interface.
8066 if Ada_Version >= Ada_05
8068 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8071 Make_Subprogram_Declaration (Loc,
8073 Build_Protected_Sub_Specification
8074 (Comp, Prot_Typ, Dispatching_Mode));
8076 Insert_After (Current_Node, Sub);
8079 Current_Node := Sub;
8082 -- If a pragma Interrupt_Handler applies, build and add a call to
8083 -- Register_Interrupt_Handler to the freezing actions of the
8084 -- protected version (Current_Node) of the subprogram:
8086 -- system.interrupts.register_interrupt_handler
8087 -- (prot_procP'address);
8089 if not Restricted_Profile
8090 and then Is_Interrupt_Handler
8091 (Defining_Unit_Name (Specification (Comp)))
8096 elsif Nkind (Comp) = N_Entry_Declaration then
8097 E_Count := E_Count + 1;
8098 Comp_Id := Defining_Identifier (Comp);
8101 Make_Defining_Identifier (Loc,
8102 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8104 Make_Subprogram_Declaration (Loc,
8106 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8108 Insert_After (Current_Node, Sub);
8111 Set_Protected_Body_Subprogram
8112 (Defining_Identifier (Comp),
8113 Defining_Unit_Name (Specification (Sub)));
8115 Current_Node := Sub;
8118 Make_Defining_Identifier (Loc,
8119 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8121 Make_Subprogram_Declaration (Loc,
8123 Build_Barrier_Function_Specification (Loc, Bdef));
8125 Insert_After (Current_Node, Sub);
8127 Set_Protected_Body_Subprogram (Bdef, Bdef);
8128 Set_Barrier_Function (Comp_Id, Bdef);
8129 Set_Scope (Bdef, Scope (Comp_Id));
8130 Current_Node := Sub;
8132 -- Collect pointers to the protected subprogram and the barrier
8133 -- of the current entry, for insertion into Entry_Bodies_Array.
8136 Make_Aggregate (Loc,
8137 Expressions => New_List (
8138 Make_Attribute_Reference (Loc,
8139 Prefix => New_Reference_To (Bdef, Loc),
8140 Attribute_Name => Name_Unrestricted_Access),
8141 Make_Attribute_Reference (Loc,
8142 Prefix => New_Reference_To (Edef, Loc),
8143 Attribute_Name => Name_Unrestricted_Access))),
8144 Expressions (Entries_Aggr));
8151 -- If there are some private entry declarations, expand it as if they
8152 -- were visible entries.
8154 if Present (Private_Declarations (Pdef)) then
8155 Comp := First (Private_Declarations (Pdef));
8156 while Present (Comp) loop
8157 if Nkind (Comp) = N_Entry_Declaration then
8158 E_Count := E_Count + 1;
8159 Comp_Id := Defining_Identifier (Comp);
8162 Make_Defining_Identifier (Loc,
8163 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8165 Make_Subprogram_Declaration (Loc,
8167 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8169 Insert_After (Current_Node, Sub);
8172 Set_Protected_Body_Subprogram
8173 (Defining_Identifier (Comp),
8174 Defining_Unit_Name (Specification (Sub)));
8176 Current_Node := Sub;
8179 Make_Defining_Identifier (Loc,
8180 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8183 Make_Subprogram_Declaration (Loc,
8185 Build_Barrier_Function_Specification (Loc, Bdef));
8187 Insert_After (Current_Node, Sub);
8189 Set_Protected_Body_Subprogram (Bdef, Bdef);
8190 Set_Barrier_Function (Comp_Id, Bdef);
8191 Set_Scope (Bdef, Scope (Comp_Id));
8192 Current_Node := Sub;
8194 -- Collect pointers to the protected subprogram and the barrier
8195 -- of the current entry, for insertion into Entry_Bodies_Array.
8197 Append_To (Expressions (Entries_Aggr),
8198 Make_Aggregate (Loc,
8199 Expressions => New_List (
8200 Make_Attribute_Reference (Loc,
8201 Prefix => New_Reference_To (Bdef, Loc),
8202 Attribute_Name => Name_Unrestricted_Access),
8203 Make_Attribute_Reference (Loc,
8204 Prefix => New_Reference_To (Edef, Loc),
8205 Attribute_Name => Name_Unrestricted_Access))));
8212 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8213 -- all protected subprograms have been collected.
8215 if Has_Entries (Prot_Typ) then
8217 Make_Defining_Identifier (Sloc (Prot_Typ),
8218 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8220 case Corresponding_Runtime_Package (Prot_Typ) is
8221 when System_Tasking_Protected_Objects_Entries =>
8222 Body_Arr := Make_Object_Declaration (Loc,
8223 Defining_Identifier => Body_Id,
8224 Aliased_Present => True,
8225 Object_Definition =>
8226 Make_Subtype_Indication (Loc,
8227 Subtype_Mark => New_Reference_To (
8228 RTE (RE_Protected_Entry_Body_Array), Loc),
8230 Make_Index_Or_Discriminant_Constraint (Loc,
8231 Constraints => New_List (
8233 Make_Integer_Literal (Loc, 1),
8234 Make_Integer_Literal (Loc, E_Count))))),
8235 Expression => Entries_Aggr);
8237 when System_Tasking_Protected_Objects_Single_Entry =>
8238 Body_Arr := Make_Object_Declaration (Loc,
8239 Defining_Identifier => Body_Id,
8240 Aliased_Present => True,
8241 Object_Definition => New_Reference_To
8242 (RTE (RE_Entry_Body), Loc),
8244 Make_Aggregate (Loc,
8245 Expressions => New_List (
8246 Make_Attribute_Reference (Loc,
8247 Prefix => New_Reference_To (Bdef, Loc),
8248 Attribute_Name => Name_Unrestricted_Access),
8249 Make_Attribute_Reference (Loc,
8250 Prefix => New_Reference_To (Edef, Loc),
8251 Attribute_Name => Name_Unrestricted_Access))));
8254 raise Program_Error;
8257 -- A pointer to this array will be placed in the corresponding record
8258 -- by its initialization procedure so this needs to be analyzed here.
8260 Insert_After (Current_Node, Body_Arr);
8261 Current_Node := Body_Arr;
8264 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8266 -- Finally, build the function that maps an entry index into the
8267 -- corresponding body. A pointer to this function is placed in each
8268 -- object of the type. Except for a ravenscar-like profile (no abort,
8269 -- no entry queue, 1 entry)
8271 if Corresponding_Runtime_Package (Prot_Typ) =
8272 System_Tasking_Protected_Objects_Entries
8275 Make_Subprogram_Declaration (Loc,
8276 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8277 Insert_After (Current_Node, Sub);
8281 end Expand_N_Protected_Type_Declaration;
8283 --------------------------------
8284 -- Expand_N_Requeue_Statement --
8285 --------------------------------
8287 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8288 -- operations, depending on the source and destination (task or protected
8289 -- object). A dispatching requeue statement is expanded into a call to the
8290 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8291 -- jump around the remainder of processing for the original entry and, if
8292 -- the destination is (different) protected object, to attempt to service
8293 -- it. The following illustrates the various cases:
8296 -- (O : System.Address;
8297 -- P : System.Address;
8298 -- E : Protected_Entry_Index)
8300 -- <discriminant renamings>
8301 -- <private object renamings>
8302 -- type poVP is access poV;
8303 -- _object : ptVP := ptVP!(O);
8307 -- <start of statement sequence for entry>
8309 -- -- Requeue from one protected entry body to another protected
8312 -- Requeue_Protected_Entry (
8313 -- _object._object'Access,
8314 -- new._object'Access,
8319 -- <some more of the statement sequence for entry>
8321 -- -- Requeue from an entry body to a task entry
8323 -- Requeue_Protected_To_Task_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 -- Requeue of a task entry call to a task entry
8341 -- Accept_Call (E, Ann);
8342 -- <start of statement sequence for accept statement>
8343 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8345 -- <rest of statement sequence for accept statement>
8347 -- Complete_Rendezvous;
8350 -- when all others =>
8351 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8353 -- Requeue of a task entry call to a protected entry
8355 -- Accept_Call (E, Ann);
8356 -- <start of statement sequence for accept statement>
8357 -- Requeue_Task_To_Protected_Entry (
8358 -- new._object'Access,
8363 -- <rest of statement sequence for accept statement>
8365 -- Complete_Rendezvous;
8368 -- when all others =>
8369 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8371 -- Ada 2005 (AI05-0030): Dispatching requeue from protected to interface
8375 -- (O : System.Address;
8376 -- P : System.Address;
8377 -- E : Protected_Entry_Index)
8379 -- <discriminant renamings>
8380 -- <private object renamings>
8381 -- type poVP is access poV;
8382 -- _object : ptVP := ptVP!(O);
8386 -- <start of statement sequence for entry>
8389 -- (<interface class-wide object>,
8392 -- Ada.Tags.Get_Offset_Index
8394 -- <interface dispatch table index of target entry>),
8398 -- <rest of statement sequence for entry>
8399 -- Complete_Entry_Body (_object._object);
8402 -- when all others =>
8403 -- Exceptional_Complete_Entry_Body (
8404 -- _object._object, Get_GNAT_Exception);
8408 -- Ada 2005 (AI05-0030): Dispatching requeue from task to interface
8411 -- Accept_Call (E, Ann);
8412 -- <start of statement sequence for accept statement>
8414 -- (<interface class-wide object>,
8417 -- Ada.Tags.Get_Offset_Index
8419 -- <interface dispatch table index of target entrt>),
8423 -- <rest of statement sequence for accept statement>
8425 -- Complete_Rendezvous;
8428 -- when all others =>
8429 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8431 -- Further details on these expansions can be found in Expand_N_Protected_
8432 -- Body and Expand_N_Accept_Statement.
8434 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8435 Loc : constant Source_Ptr := Sloc (N);
8436 Abortable : Node_Id;
8438 Conc_Typ : Entity_Id;
8443 New_Param : Node_Id;
8444 Old_Typ : Entity_Id;
8447 RTS_Call : Entity_Id;
8448 Self_Param : Node_Id;
8449 Skip_Stat : Node_Id;
8453 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
8455 -- Extract the components of the entry call
8457 Extract_Entry (N, Concval, Ename, Index);
8458 Conc_Typ := Etype (Concval);
8460 -- Examine the scope stack in order to find nearest enclosing protected
8461 -- or task type. This will constitute our invocation source.
8463 Old_Typ := Current_Scope;
8464 while Present (Old_Typ)
8465 and then not Is_Protected_Type (Old_Typ)
8466 and then not Is_Task_Type (Old_Typ)
8468 Old_Typ := Scope (Old_Typ);
8471 -- Generate the parameter list for all cases. The abortable flag is
8472 -- common among dispatching and regular requeue.
8474 Params := New_List (Abortable);
8476 -- Ada 2005 (AI05-0030): We have a dispatching requeue of the form
8477 -- Concval.Ename where the type of Concval is class-wide concurrent
8480 if Ada_Version >= Ada_05
8481 and then Present (Concval)
8482 and then Is_Class_Wide_Type (Conc_Typ)
8483 and then Is_Concurrent_Interface (Conc_Typ)
8485 RTS_Call := Make_Identifier (Loc, Name_uDisp_Requeue);
8488 -- Ada.Tags.Get_Offset_Index
8489 -- (Ada.Tags.Tag (Concval),
8490 -- <interface dispatch table position of Ename>)
8493 Make_Function_Call (Loc,
8495 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8496 Parameter_Associations =>
8498 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8499 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8501 -- Specific actuals for protected to interface class-wide type
8504 if Is_Protected_Type (Old_Typ) then
8506 Make_Attribute_Reference (Loc, -- _object'Address
8508 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8511 Prepend_To (Params, -- True
8512 New_Reference_To (Standard_True, Loc));
8514 -- Specific actuals for task to interface class-wide type requeue
8517 pragma Assert (Is_Task_Type (Old_Typ));
8519 Prepend_To (Params, -- null
8520 New_Reference_To (RTE (RE_Null_Address), Loc));
8521 Prepend_To (Params, -- False
8522 New_Reference_To (Standard_False, Loc));
8525 -- Finally, add the common object parameter
8527 Prepend_To (Params, New_Copy_Tree (Concval));
8529 -- Regular requeue processing
8532 New_Param := Concurrent_Ref (Concval);
8534 -- The index expression is common among all four cases
8537 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8539 if Is_Protected_Type (Old_Typ) then
8541 Make_Attribute_Reference (Loc,
8543 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8545 Name_Unchecked_Access);
8547 -- Protected to protected requeue
8549 if Is_Protected_Type (Conc_Typ) then
8551 New_Reference_To (RTE (RE_Requeue_Protected_Entry), Loc);
8554 Make_Attribute_Reference (Loc,
8558 Name_Unchecked_Access);
8560 -- Protected to task requeue
8563 pragma Assert (Is_Task_Type (Conc_Typ));
8566 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8569 Prepend (New_Param, Params);
8570 Prepend (Self_Param, Params);
8573 pragma Assert (Is_Task_Type (Old_Typ));
8575 -- Task to protected requeue
8577 if Is_Protected_Type (Conc_Typ) then
8580 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8583 Make_Attribute_Reference (Loc,
8587 Name_Unchecked_Access);
8589 -- Task to task requeue
8592 pragma Assert (Is_Task_Type (Conc_Typ));
8594 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8597 Prepend (New_Param, Params);
8601 -- Create the GNARLI or predefined primitive call
8604 Make_Procedure_Call_Statement (Loc,
8606 Parameter_Associations => Params);
8611 if Is_Protected_Type (Old_Typ) then
8613 -- Build the return statement to skip the rest of the entry body
8615 Skip_Stat := Make_Simple_Return_Statement (Loc);
8618 -- If the requeue is within a task, find the end label of the
8619 -- enclosing accept statement.
8621 Acc_Stat := Parent (N);
8622 while Nkind (Acc_Stat) /= N_Accept_Statement loop
8623 Acc_Stat := Parent (Acc_Stat);
8626 -- The last statement is the second label, used for completing the
8627 -- rendezvous the usual way. The label we are looking for is right
8631 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
8633 pragma Assert (Nkind (Lab_Node) = N_Label);
8635 -- Build the goto statement to skip the rest of the accept
8639 Make_Goto_Statement (Loc,
8640 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
8643 Set_Analyzed (Skip_Stat);
8645 Insert_After (N, Skip_Stat);
8646 end Expand_N_Requeue_Statement;
8648 -------------------------------
8649 -- Expand_N_Selective_Accept --
8650 -------------------------------
8652 procedure Expand_N_Selective_Accept (N : Node_Id) is
8653 Loc : constant Source_Ptr := Sloc (N);
8654 Alts : constant List_Id := Select_Alternatives (N);
8656 -- Note: in the below declarations a lot of new lists are allocated
8657 -- unconditionally which may well not end up being used. That's
8658 -- not a good idea since it wastes space gratuitously ???
8660 Accept_Case : List_Id;
8661 Accept_List : constant List_Id := New_List;
8664 Alt_List : constant List_Id := New_List;
8665 Alt_Stats : List_Id;
8666 Ann : Entity_Id := Empty;
8669 Check_Guard : Boolean := True;
8671 Decls : constant List_Id := New_List;
8672 Stats : constant List_Id := New_List;
8673 Body_List : constant List_Id := New_List;
8674 Trailing_List : constant List_Id := New_List;
8677 Else_Present : Boolean := False;
8678 Terminate_Alt : Node_Id := Empty;
8679 Select_Mode : Node_Id;
8681 Delay_Case : List_Id;
8682 Delay_Count : Integer := 0;
8683 Delay_Val : Entity_Id;
8684 Delay_Index : Entity_Id;
8685 Delay_Min : Entity_Id;
8686 Delay_Num : Int := 1;
8687 Delay_Alt_List : List_Id := New_List;
8688 Delay_List : constant List_Id := New_List;
8692 First_Delay : Boolean := True;
8693 Guard_Open : Entity_Id;
8699 Num_Accept : Nat := 0;
8702 Time_Type : Entity_Id;
8704 Select_Call : Node_Id;
8706 Qnam : constant Entity_Id :=
8707 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
8709 Xnam : constant Entity_Id :=
8710 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
8712 -----------------------
8713 -- Local subprograms --
8714 -----------------------
8716 function Accept_Or_Raise return List_Id;
8717 -- For the rare case where delay alternatives all have guards, and
8718 -- all of them are closed, it is still possible that there were open
8719 -- accept alternatives with no callers. We must reexamine the
8720 -- Accept_List, and execute a selective wait with no else if some
8721 -- accept is open. If none, we raise program_error.
8723 procedure Add_Accept (Alt : Node_Id);
8724 -- Process a single accept statement in a select alternative. Build
8725 -- procedure for body of accept, and add entry to dispatch table with
8726 -- expression for guard, in preparation for call to run time select.
8728 function Make_And_Declare_Label (Num : Int) return Node_Id;
8729 -- Manufacture a label using Num as a serial number and declare it.
8730 -- The declaration is appended to Decls. The label marks the trailing
8731 -- statements of an accept or delay alternative.
8733 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
8734 -- Build call to Selective_Wait runtime routine
8736 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
8737 -- Add code to compare value of delay with previous values, and
8738 -- generate case entry for trailing statements.
8740 procedure Process_Accept_Alternative
8744 -- Add code to call corresponding procedure, and branch to
8745 -- trailing statements, if any.
8747 ---------------------
8748 -- Accept_Or_Raise --
8749 ---------------------
8751 function Accept_Or_Raise return List_Id is
8754 J : constant Entity_Id := Make_Defining_Identifier (Loc,
8755 New_Internal_Name ('J'));
8758 -- We generate the following:
8760 -- for J in q'range loop
8761 -- if q(J).S /=null_task_entry then
8762 -- selective_wait (simple_mode,...);
8768 -- if no rendez_vous then
8769 -- raise program_error;
8772 -- Note that the code needs to know that the selector name
8773 -- in an Accept_Alternative is named S.
8775 Cond := Make_Op_Ne (Loc,
8777 Make_Selected_Component (Loc,
8778 Prefix => Make_Indexed_Component (Loc,
8779 Prefix => New_Reference_To (Qnam, Loc),
8780 Expressions => New_List (New_Reference_To (J, Loc))),
8781 Selector_Name => Make_Identifier (Loc, Name_S)),
8783 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
8786 Make_Implicit_Loop_Statement (N,
8787 Identifier => Empty,
8789 Make_Iteration_Scheme (Loc,
8790 Loop_Parameter_Specification =>
8791 Make_Loop_Parameter_Specification (Loc,
8792 Defining_Identifier => J,
8793 Discrete_Subtype_Definition =>
8794 Make_Attribute_Reference (Loc,
8795 Prefix => New_Reference_To (Qnam, Loc),
8796 Attribute_Name => Name_Range,
8797 Expressions => New_List (
8798 Make_Integer_Literal (Loc, 1))))),
8800 Statements => New_List (
8801 Make_Implicit_If_Statement (N,
8803 Then_Statements => New_List (
8805 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
8806 Make_Exit_Statement (Loc))))));
8809 Make_Raise_Program_Error (Loc,
8810 Condition => Make_Op_Eq (Loc,
8811 Left_Opnd => New_Reference_To (Xnam, Loc),
8813 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8814 Reason => PE_All_Guards_Closed));
8817 end Accept_Or_Raise;
8823 procedure Add_Accept (Alt : Node_Id) is
8824 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
8825 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
8826 Eloc : constant Source_Ptr := Sloc (Ename);
8827 Eent : constant Entity_Id := Entity (Ename);
8828 Index : constant Node_Id := Entry_Index (Acc_Stm);
8829 Null_Body : Node_Id;
8830 Proc_Body : Node_Id;
8837 Ann := Node (Last_Elmt (Accept_Address (Eent)));
8840 if Present (Condition (Alt)) then
8842 Make_Conditional_Expression (Eloc, New_List (
8844 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
8845 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
8848 Entry_Index_Expression
8849 (Eloc, Eent, Index, Scope (Eent));
8852 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8853 Null_Body := New_Reference_To (Standard_False, Eloc);
8855 if Abort_Allowed then
8856 Call := Make_Procedure_Call_Statement (Eloc,
8857 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
8858 Insert_Before (First (Statements (Handled_Statement_Sequence (
8859 Accept_Statement (Alt)))), Call);
8864 Make_Defining_Identifier (Eloc,
8865 New_External_Name (Chars (Ename), 'A', Num_Accept));
8867 if Comes_From_Source (Alt) then
8868 Set_Debug_Info_Needed (PB_Ent);
8872 Make_Subprogram_Body (Eloc,
8874 Make_Procedure_Specification (Eloc,
8875 Defining_Unit_Name => PB_Ent),
8876 Declarations => Declarations (Acc_Stm),
8877 Handled_Statement_Sequence =>
8878 Build_Accept_Body (Accept_Statement (Alt)));
8880 -- During the analysis of the body of the accept statement, any
8881 -- zero cost exception handler records were collected in the
8882 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8883 -- This is where we move them to where they belong, namely the
8884 -- newly created procedure.
8886 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8887 Append (Proc_Body, Body_List);
8890 Null_Body := New_Reference_To (Standard_True, Eloc);
8892 -- if accept statement has declarations, insert above, given that
8893 -- we are not creating a body for the accept.
8895 if Present (Declarations (Acc_Stm)) then
8896 Insert_Actions (N, Declarations (Acc_Stm));
8900 Append_To (Accept_List,
8901 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
8903 Num_Accept := Num_Accept + 1;
8906 ----------------------------
8907 -- Make_And_Declare_Label --
8908 ----------------------------
8910 function Make_And_Declare_Label (Num : Int) return Node_Id is
8914 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8916 Make_Label (Loc, Lab_Id);
8919 Make_Implicit_Label_Declaration (Loc,
8920 Defining_Identifier =>
8921 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8922 Label_Construct => Lab));
8925 end Make_And_Declare_Label;
8927 ----------------------
8928 -- Make_Select_Call --
8929 ----------------------
8931 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8932 Params : constant List_Id := New_List;
8936 Make_Attribute_Reference (Loc,
8937 Prefix => New_Reference_To (Qnam, Loc),
8938 Attribute_Name => Name_Unchecked_Access),
8940 Append (Select_Mode, Params);
8941 Append (New_Reference_To (Ann, Loc), Params);
8942 Append (New_Reference_To (Xnam, Loc), Params);
8945 Make_Procedure_Call_Statement (Loc,
8946 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8947 Parameter_Associations => Params);
8948 end Make_Select_Call;
8950 --------------------------------
8951 -- Process_Accept_Alternative --
8952 --------------------------------
8954 procedure Process_Accept_Alternative
8959 Choices : List_Id := No_List;
8960 Alt_Stats : List_Id;
8963 Adjust_Condition (Condition (Alt));
8964 Alt_Stats := No_List;
8966 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8967 Choices := New_List (
8968 Make_Integer_Literal (Loc, Index));
8970 Alt_Stats := New_List (
8971 Make_Procedure_Call_Statement (Sloc (Proc),
8972 Name => New_Reference_To (
8973 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
8976 if Statements (Alt) /= Empty_List then
8978 if No (Alt_Stats) then
8980 -- Accept with no body, followed by trailing statements
8982 Choices := New_List (
8983 Make_Integer_Literal (Loc, Index));
8985 Alt_Stats := New_List;
8988 -- After the call, if any, branch to trailing statements. We
8989 -- create a label for each, as well as the corresponding label
8992 Lab := Make_And_Declare_Label (Index);
8993 Append_To (Alt_Stats,
8994 Make_Goto_Statement (Loc,
8995 Name => New_Copy (Identifier (Lab))));
8997 Append (Lab, Trailing_List);
8998 Append_List (Statements (Alt), Trailing_List);
8999 Append_To (Trailing_List,
9000 Make_Goto_Statement (Loc,
9001 Name => New_Copy (Identifier (End_Lab))));
9004 if Present (Alt_Stats) then
9006 -- Procedure call. and/or trailing statements
9008 Append_To (Alt_List,
9009 Make_Case_Statement_Alternative (Loc,
9010 Discrete_Choices => Choices,
9011 Statements => Alt_Stats));
9013 end Process_Accept_Alternative;
9015 -------------------------------
9016 -- Process_Delay_Alternative --
9017 -------------------------------
9019 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9022 Delay_Alt : List_Id;
9025 -- Deal with C/Fortran boolean as delay condition
9027 Adjust_Condition (Condition (Alt));
9029 -- Determine the smallest specified delay
9031 -- for each delay alternative generate:
9033 -- if guard-expression then
9034 -- Delay_Val := delay-expression;
9035 -- Guard_Open := True;
9036 -- if Delay_Val < Delay_Min then
9037 -- Delay_Min := Delay_Val;
9038 -- Delay_Index := Index;
9042 -- The enclosing if-statement is omitted if there is no guard
9047 First_Delay := False;
9049 Delay_Alt := New_List (
9050 Make_Assignment_Statement (Loc,
9051 Name => New_Reference_To (Delay_Min, Loc),
9052 Expression => Expression (Delay_Statement (Alt))));
9054 if Delay_Count > 1 then
9055 Append_To (Delay_Alt,
9056 Make_Assignment_Statement (Loc,
9057 Name => New_Reference_To (Delay_Index, Loc),
9058 Expression => Make_Integer_Literal (Loc, Index)));
9062 Delay_Alt := New_List (
9063 Make_Assignment_Statement (Loc,
9064 Name => New_Reference_To (Delay_Val, Loc),
9065 Expression => Expression (Delay_Statement (Alt))));
9067 if Time_Type = Standard_Duration then
9070 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9071 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9074 -- The scope of the time type must define a comparison
9075 -- operator. The scope itself may not be visible, so we
9076 -- construct a node with entity information to insure that
9077 -- semantic analysis can find the proper operator.
9080 Make_Function_Call (Loc,
9081 Name => Make_Selected_Component (Loc,
9082 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9084 Make_Operator_Symbol (Loc,
9085 Chars => Name_Op_Lt,
9086 Strval => No_String)),
9087 Parameter_Associations =>
9089 New_Reference_To (Delay_Val, Loc),
9090 New_Reference_To (Delay_Min, Loc)));
9092 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9095 Append_To (Delay_Alt,
9096 Make_Implicit_If_Statement (N,
9098 Then_Statements => New_List (
9099 Make_Assignment_Statement (Loc,
9100 Name => New_Reference_To (Delay_Min, Loc),
9101 Expression => New_Reference_To (Delay_Val, Loc)),
9103 Make_Assignment_Statement (Loc,
9104 Name => New_Reference_To (Delay_Index, Loc),
9105 Expression => Make_Integer_Literal (Loc, Index)))));
9109 Append_To (Delay_Alt,
9110 Make_Assignment_Statement (Loc,
9111 Name => New_Reference_To (Guard_Open, Loc),
9112 Expression => New_Reference_To (Standard_True, Loc)));
9115 if Present (Condition (Alt)) then
9116 Delay_Alt := New_List (
9117 Make_Implicit_If_Statement (N,
9118 Condition => Condition (Alt),
9119 Then_Statements => Delay_Alt));
9122 Append_List (Delay_Alt, Delay_List);
9124 -- If the delay alternative has a statement part, add choice to the
9125 -- case statements for delays.
9127 if Present (Statements (Alt)) then
9129 if Delay_Count = 1 then
9130 Append_List (Statements (Alt), Delay_Alt_List);
9133 Choices := New_List (
9134 Make_Integer_Literal (Loc, Index));
9136 Append_To (Delay_Alt_List,
9137 Make_Case_Statement_Alternative (Loc,
9138 Discrete_Choices => Choices,
9139 Statements => Statements (Alt)));
9142 elsif Delay_Count = 1 then
9144 -- If the single delay has no trailing statements, add a branch
9145 -- to the exit label to the selective wait.
9147 Delay_Alt_List := New_List (
9148 Make_Goto_Statement (Loc,
9149 Name => New_Copy (Identifier (End_Lab))));
9152 end Process_Delay_Alternative;
9154 -- Start of processing for Expand_N_Selective_Accept
9157 -- First insert some declarations before the select. The first is:
9161 -- This variable holds the parameters passed to the accept body. This
9162 -- declaration has already been inserted by the time we get here by
9163 -- a call to Expand_Accept_Declarations made from the semantics when
9164 -- processing the first accept statement contained in the select. We
9165 -- can find this entity as Accept_Address (E), where E is any of the
9166 -- entries references by contained accept statements.
9168 -- The first step is to scan the list of Selective_Accept_Statements
9169 -- to find this entity, and also count the number of accepts, and
9170 -- determine if terminated, delay or else is present:
9174 Alt := First (Alts);
9175 while Present (Alt) loop
9177 if Nkind (Alt) = N_Accept_Alternative then
9180 elsif Nkind (Alt) = N_Delay_Alternative then
9181 Delay_Count := Delay_Count + 1;
9183 -- If the delays are relative delays, the delay expressions have
9184 -- type Standard_Duration. Otherwise they must have some time type
9185 -- recognized by GNAT.
9187 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9188 Time_Type := Standard_Duration;
9190 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9192 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9193 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9198 "& is not a time type (RM 9.6(6))",
9199 Expression (Delay_Statement (Alt)), Time_Type);
9200 Time_Type := Standard_Duration;
9201 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9205 if No (Condition (Alt)) then
9207 -- This guard will always be open
9209 Check_Guard := False;
9212 elsif Nkind (Alt) = N_Terminate_Alternative then
9213 Adjust_Condition (Condition (Alt));
9214 Terminate_Alt := Alt;
9217 Num_Alts := Num_Alts + 1;
9221 Else_Present := Present (Else_Statements (N));
9223 -- At the same time (see procedure Add_Accept) we build the accept list:
9225 -- Qnn : Accept_List (1 .. num-select) := (
9226 -- (null-body, entry-index),
9227 -- (null-body, entry-index),
9229 -- (null_body, entry-index));
9231 -- In the above declaration, null-body is True if the corresponding
9232 -- accept has no body, and false otherwise. The entry is either the
9233 -- entry index expression if there is no guard, or if a guard is
9234 -- present, then a conditional expression of the form:
9236 -- (if guard then entry-index else Null_Task_Entry)
9238 -- If a guard is statically known to be false, the entry can simply
9239 -- be omitted from the accept list.
9242 Make_Object_Declaration (Loc,
9243 Defining_Identifier => Qnam,
9244 Object_Definition =>
9245 New_Reference_To (RTE (RE_Accept_List), Loc),
9246 Aliased_Present => True,
9249 Make_Qualified_Expression (Loc,
9251 New_Reference_To (RTE (RE_Accept_List), Loc),
9253 Make_Aggregate (Loc, Expressions => Accept_List)));
9257 -- Then we declare the variable that holds the index for the accept
9258 -- that will be selected for service:
9260 -- Xnn : Select_Index;
9263 Make_Object_Declaration (Loc,
9264 Defining_Identifier => Xnam,
9265 Object_Definition =>
9266 New_Reference_To (RTE (RE_Select_Index), Loc),
9268 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9272 -- After this follow procedure declarations for each accept body
9279 -- where the ... are statements from the corresponding procedure body.
9280 -- No parameters are involved, since the parameters are passed via Ann
9281 -- and the parameter references have already been expanded to be direct
9282 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9283 -- any embedded tasking statements (which would normally be illegal in
9284 -- procedures), have been converted to calls to the tasking runtime so
9285 -- there is no problem in putting them into procedures.
9287 -- The original accept statement has been expanded into a block in
9288 -- the same fashion as for simple accepts (see Build_Accept_Body).
9290 -- Note: we don't really need to build these procedures for the case
9291 -- where no delay statement is present, but it is just as easy to
9292 -- build them unconditionally, and not significantly inefficient,
9293 -- since if they are short they will be inlined anyway.
9295 -- The procedure declarations have been assembled in Body_List
9297 -- If delays are present, we must compute the required delay.
9298 -- We first generate the declarations:
9300 -- Delay_Index : Boolean := 0;
9301 -- Delay_Min : Some_Time_Type.Time;
9302 -- Delay_Val : Some_Time_Type.Time;
9304 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9305 -- active delay that is actually chosen as the basis for the possible
9306 -- delay if an immediate rendez-vous is not possible.
9308 -- In the most common case there is a single delay statement, and this
9309 -- is handled specially.
9311 if Delay_Count > 0 then
9313 -- Generate the required declarations
9316 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9318 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9320 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9323 Make_Object_Declaration (Loc,
9324 Defining_Identifier => Delay_Val,
9325 Object_Definition => New_Reference_To (Time_Type, Loc)));
9328 Make_Object_Declaration (Loc,
9329 Defining_Identifier => Delay_Index,
9330 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9331 Expression => Make_Integer_Literal (Loc, 0)));
9334 Make_Object_Declaration (Loc,
9335 Defining_Identifier => Delay_Min,
9336 Object_Definition => New_Reference_To (Time_Type, Loc),
9338 Unchecked_Convert_To (Time_Type,
9339 Make_Attribute_Reference (Loc,
9341 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9342 Attribute_Name => Name_Last))));
9344 -- Create Duration and Delay_Mode objects used for passing a delay
9347 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
9348 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
9354 -- Note that these values are defined in s-osprim.ads and must
9357 -- Relative : constant := 0;
9358 -- Absolute_Calendar : constant := 1;
9359 -- Absolute_RT : constant := 2;
9361 if Time_Type = Standard_Duration then
9362 Discr := Make_Integer_Literal (Loc, 0);
9364 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9365 Discr := Make_Integer_Literal (Loc, 1);
9369 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9370 Discr := Make_Integer_Literal (Loc, 2);
9374 Make_Object_Declaration (Loc,
9375 Defining_Identifier => D,
9376 Object_Definition =>
9377 New_Reference_To (Standard_Duration, Loc)));
9380 Make_Object_Declaration (Loc,
9381 Defining_Identifier => M,
9382 Object_Definition =>
9383 New_Reference_To (Standard_Integer, Loc),
9384 Expression => Discr));
9389 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9392 Make_Object_Declaration (Loc,
9393 Defining_Identifier => Guard_Open,
9394 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9395 Expression => New_Reference_To (Standard_False, Loc)));
9398 -- Delay_Count is zero, don't need M and D set (suppress warning)
9405 if Present (Terminate_Alt) then
9407 -- If the terminate alternative guard is False, use
9408 -- Simple_Mode; otherwise use Terminate_Mode.
9410 if Present (Condition (Terminate_Alt)) then
9411 Select_Mode := Make_Conditional_Expression (Loc,
9412 New_List (Condition (Terminate_Alt),
9413 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9414 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9416 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9419 elsif Else_Present or Delay_Count > 0 then
9420 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9423 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9426 Select_Call := Make_Select_Call (Select_Mode);
9427 Append (Select_Call, Stats);
9429 -- Now generate code to act on the result. There is an entry
9430 -- in this case for each accept statement with a non-null body,
9431 -- followed by a branch to the statements that follow the Accept.
9432 -- In the absence of delay alternatives, we generate:
9435 -- when No_Rendezvous => -- omitted if simple mode
9450 -- Lab0: Else_Statements;
9453 -- Lab1: Trailing_Statements1;
9456 -- Lab2: Trailing_Statements2;
9461 -- Generate label for common exit
9463 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9465 -- First entry is the default case, when no rendezvous is possible
9467 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9469 if Else_Present then
9471 -- If no rendezvous is possible, the else part is executed
9473 Lab := Make_And_Declare_Label (0);
9474 Alt_Stats := New_List (
9475 Make_Goto_Statement (Loc,
9476 Name => New_Copy (Identifier (Lab))));
9478 Append (Lab, Trailing_List);
9479 Append_List (Else_Statements (N), Trailing_List);
9480 Append_To (Trailing_List,
9481 Make_Goto_Statement (Loc,
9482 Name => New_Copy (Identifier (End_Lab))));
9484 Alt_Stats := New_List (
9485 Make_Goto_Statement (Loc,
9486 Name => New_Copy (Identifier (End_Lab))));
9489 Append_To (Alt_List,
9490 Make_Case_Statement_Alternative (Loc,
9491 Discrete_Choices => Choices,
9492 Statements => Alt_Stats));
9494 -- We make use of the fact that Accept_Index is an integer type, and
9495 -- generate successive literals for entries for each accept. Only those
9496 -- for which there is a body or trailing statements get a case entry.
9498 Alt := First (Select_Alternatives (N));
9499 Proc := First (Body_List);
9500 while Present (Alt) loop
9502 if Nkind (Alt) = N_Accept_Alternative then
9503 Process_Accept_Alternative (Alt, Index, Proc);
9507 (Handled_Statement_Sequence (Accept_Statement (Alt)))
9512 elsif Nkind (Alt) = N_Delay_Alternative then
9513 Process_Delay_Alternative (Alt, Delay_Num);
9514 Delay_Num := Delay_Num + 1;
9520 -- An others choice is always added to the main case, as well
9521 -- as the delay case (to satisfy the compiler).
9523 Append_To (Alt_List,
9524 Make_Case_Statement_Alternative (Loc,
9526 New_List (Make_Others_Choice (Loc)),
9528 New_List (Make_Goto_Statement (Loc,
9529 Name => New_Copy (Identifier (End_Lab))))));
9531 Accept_Case := New_List (
9532 Make_Case_Statement (Loc,
9533 Expression => New_Reference_To (Xnam, Loc),
9534 Alternatives => Alt_List));
9536 Append_List (Trailing_List, Accept_Case);
9537 Append (End_Lab, Accept_Case);
9538 Append_List (Body_List, Decls);
9540 -- Construct case statement for trailing statements of delay
9541 -- alternatives, if there are several of them.
9543 if Delay_Count > 1 then
9544 Append_To (Delay_Alt_List,
9545 Make_Case_Statement_Alternative (Loc,
9547 New_List (Make_Others_Choice (Loc)),
9549 New_List (Make_Null_Statement (Loc))));
9551 Delay_Case := New_List (
9552 Make_Case_Statement (Loc,
9553 Expression => New_Reference_To (Delay_Index, Loc),
9554 Alternatives => Delay_Alt_List));
9556 Delay_Case := Delay_Alt_List;
9559 -- If there are no delay alternatives, we append the case statement
9560 -- to the statement list.
9562 if Delay_Count = 0 then
9563 Append_List (Accept_Case, Stats);
9565 -- Delay alternatives present
9568 -- If delay alternatives are present we generate:
9570 -- find minimum delay.
9571 -- DX := minimum delay;
9572 -- M := <delay mode>;
9573 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9576 -- if X = No_Rendezvous then
9577 -- case statement for delay statements.
9579 -- case statement for accept alternatives.
9590 -- The type of the delay expression is known to be legal
9592 if Time_Type = Standard_Duration then
9593 Conv := New_Reference_To (Delay_Min, Loc);
9595 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9596 Conv := Make_Function_Call (Loc,
9597 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9598 New_List (New_Reference_To (Delay_Min, Loc)));
9602 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9604 Conv := Make_Function_Call (Loc,
9605 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9606 New_List (New_Reference_To (Delay_Min, Loc)));
9609 Stmt := Make_Assignment_Statement (Loc,
9610 Name => New_Reference_To (D, Loc),
9611 Expression => Conv);
9613 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
9615 Parms := Parameter_Associations (Select_Call);
9616 Parm := First (Parms);
9618 while Present (Parm)
9619 and then Parm /= Select_Mode
9624 pragma Assert (Present (Parm));
9625 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
9628 -- Prepare two new parameters of Duration and Delay_Mode type
9629 -- which represent the value and the mode of the minimum delay.
9632 Insert_After (Parm, New_Reference_To (M, Loc));
9633 Insert_After (Parm, New_Reference_To (D, Loc));
9635 -- Create a call to RTS
9637 Rewrite (Select_Call,
9638 Make_Procedure_Call_Statement (Loc,
9639 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
9640 Parameter_Associations => Parms));
9642 -- This new call should follow the calculation of the minimum
9645 Insert_List_Before (Select_Call, Delay_List);
9649 Make_Implicit_If_Statement (N,
9650 Condition => New_Reference_To (Guard_Open, Loc),
9652 New_List (New_Copy_Tree (Stmt),
9653 New_Copy_Tree (Select_Call)),
9654 Else_Statements => Accept_Or_Raise);
9655 Rewrite (Select_Call, Stmt);
9657 Insert_Before (Select_Call, Stmt);
9661 Make_Implicit_If_Statement (N,
9662 Condition => Make_Op_Eq (Loc,
9663 Left_Opnd => New_Reference_To (Xnam, Loc),
9665 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9667 Then_Statements => Delay_Case,
9668 Else_Statements => Accept_Case);
9670 Append (Cases, Stats);
9674 -- Replace accept statement with appropriate block
9677 Make_Block_Statement (Loc,
9678 Declarations => Decls,
9679 Handled_Statement_Sequence =>
9680 Make_Handled_Sequence_Of_Statements (Loc,
9681 Statements => Stats));
9686 -- Note: have to worry more about abort deferral in above code ???
9688 -- Final step is to unstack the Accept_Address entries for all accept
9689 -- statements appearing in accept alternatives in the select statement
9691 Alt := First (Alts);
9692 while Present (Alt) loop
9693 if Nkind (Alt) = N_Accept_Alternative then
9694 Remove_Last_Elmt (Accept_Address
9695 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
9700 end Expand_N_Selective_Accept;
9702 --------------------------------------
9703 -- Expand_N_Single_Task_Declaration --
9704 --------------------------------------
9706 -- Single task declarations should never be present after semantic
9707 -- analysis, since we expect them to be replaced by a declaration of an
9708 -- anonymous task type, followed by a declaration of the task object. We
9709 -- include this routine to make sure that is happening!
9711 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
9713 raise Program_Error;
9714 end Expand_N_Single_Task_Declaration;
9716 ------------------------
9717 -- Expand_N_Task_Body --
9718 ------------------------
9720 -- Given a task body
9722 -- task body tname is
9728 -- This expansion routine converts it into a procedure and sets the
9729 -- elaboration flag for the procedure to true, to represent the fact
9730 -- that the task body is now elaborated:
9732 -- procedure tnameB (_Task : access tnameV) is
9733 -- discriminal : dtype renames _Task.discriminant;
9735 -- procedure _clean is
9739 -- Abort_Undefer.all;
9744 -- Abort_Undefer.all;
9746 -- System.Task_Stages.Complete_Activation;
9754 -- In addition, if the task body is an activator, then a call to activate
9755 -- tasks is added at the start of the statements, before the call to
9756 -- Complete_Activation, and if in addition the task is a master then it
9757 -- must be established as a master. These calls are inserted and analyzed
9758 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9761 -- There is one discriminal declaration line generated for each
9762 -- discriminant that is present to provide an easy reference point for
9763 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9765 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9766 -- task body procedures have a profile (Arg : System.Address). That is
9767 -- needed because GNARLI has to use the same access-to-subprogram type
9768 -- for all task types. We depend here on knowing that in GNAT, passing
9769 -- an address argument by value is identical to passing a record value
9770 -- by access (in either case a single pointer is passed), so even though
9771 -- this procedure has the wrong profile. In fact it's all OK, since the
9772 -- callings sequence is identical.
9774 procedure Expand_N_Task_Body (N : Node_Id) is
9775 Loc : constant Source_Ptr := Sloc (N);
9776 Ttyp : constant Entity_Id := Corresponding_Spec (N);
9780 Insert_Nod : Node_Id;
9781 -- Used to determine the proper location of wrapper body insertions
9784 -- Add renaming declarations for discriminals and a declaration for the
9785 -- entry family index (if applicable).
9787 Install_Private_Data_Declarations
9788 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
9790 -- Add a call to Abort_Undefer at the very beginning of the task
9791 -- body since this body is called with abort still deferred.
9793 if Abort_Allowed then
9794 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
9796 (First (Statements (Handled_Statement_Sequence (N))), Call);
9800 -- The statement part has already been protected with an at_end and
9801 -- cleanup actions. The call to Complete_Activation must be placed
9802 -- at the head of the sequence of statements of that block. The
9803 -- declarations have been merged in this sequence of statements but
9804 -- the first real statement is accessible from the First_Real_Statement
9805 -- field (which was set for exactly this purpose).
9807 if Restricted_Profile then
9808 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
9810 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
9814 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
9818 Make_Subprogram_Body (Loc,
9819 Specification => Build_Task_Proc_Specification (Ttyp),
9820 Declarations => Declarations (N),
9821 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
9823 -- If the task contains generic instantiations, cleanup actions are
9824 -- delayed until after instantiation. Transfer the activation chain to
9825 -- the subprogram, to insure that the activation call is properly
9826 -- generated. It the task body contains inner tasks, indicate that the
9827 -- subprogram is a task master.
9829 if Delay_Cleanups (Ttyp) then
9830 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
9831 Set_Is_Task_Master (New_N, Is_Task_Master (N));
9837 -- Set elaboration flag immediately after task body. If the body is a
9838 -- subunit, the flag is set in the declarative part containing the stub.
9840 if Nkind (Parent (N)) /= N_Subunit then
9842 Make_Assignment_Statement (Loc,
9844 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
9845 Expression => New_Reference_To (Standard_True, Loc)));
9848 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9849 -- the task body. At this point all wrapper specs have been created,
9850 -- frozen and included in the dispatch table for the task type.
9852 if Ada_Version >= Ada_05 then
9853 if Nkind (Parent (N)) = N_Subunit then
9854 Insert_Nod := Corresponding_Stub (Parent (N));
9859 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
9861 end Expand_N_Task_Body;
9863 ------------------------------------
9864 -- Expand_N_Task_Type_Declaration --
9865 ------------------------------------
9867 -- We have several things to do. First we must create a Boolean flag used
9868 -- to mark if the body is elaborated yet. This variable gets set to True
9869 -- when the body of the task is elaborated (we can't rely on the normal
9870 -- ABE mechanism for the task body, since we need to pass an access to
9871 -- this elaboration boolean to the runtime routines).
9873 -- taskE : aliased Boolean := False;
9875 -- Next a variable is declared to hold the task stack size (either the
9876 -- default : Unspecified_Size, or a value that is set by a pragma
9877 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9878 -- the variable is initialized with this value:
9880 -- taskZ : Size_Type := Unspecified_Size;
9882 -- taskZ : Size_Type := Size_Type (size_expression);
9884 -- Note: No variable is needed to hold the task relative deadline since
9885 -- its value would never be static because the parameter is of a private
9886 -- type (Ada.Real_Time.Time_Span).
9888 -- Next we create a corresponding record type declaration used to represent
9889 -- values of this task. The general form of this type declaration is
9891 -- type taskV (discriminants) is record
9892 -- _Task_Id : Task_Id;
9893 -- entry_family : array (bounds) of Void;
9894 -- _Priority : Integer := priority_expression;
9895 -- _Size : Size_Type := Size_Type (size_expression);
9896 -- _Task_Info : Task_Info_Type := task_info_expression;
9899 -- The discriminants are present only if the corresponding task type has
9900 -- discriminants, and they exactly mirror the task type discriminants.
9902 -- The Id field is always present. It contains the Task_Id value, as set by
9903 -- the call to Create_Task. Note that although the task is limited, the
9904 -- task value record type is not limited, so there is no problem in passing
9905 -- this field as an out parameter to Create_Task.
9907 -- One entry_family component is present for each entry family in the task
9908 -- definition. The bounds correspond to the bounds of the entry family
9909 -- (which may depend on discriminants). The element type is void, since we
9910 -- only need the bounds information for determining the entry index. Note
9911 -- that the use of an anonymous array would normally be illegal in this
9912 -- context, but this is a parser check, and the semantics is quite prepared
9913 -- to handle such a case.
9915 -- The _Size field is present only if a Storage_Size pragma appears in the
9916 -- task definition. The expression captures the argument that was present
9917 -- in the pragma, and is used to override the task stack size otherwise
9918 -- associated with the task type.
9920 -- The _Priority field is present only if a Priority or Interrupt_Priority
9921 -- pragma appears in the task definition. The expression captures the
9922 -- argument that was present in the pragma, and is used to provide the Size
9923 -- parameter to the call to Create_Task.
9925 -- The _Task_Info field is present only if a Task_Info pragma appears in
9926 -- the task definition. The expression captures the argument that was
9927 -- present in the pragma, and is used to provide the Task_Image parameter
9928 -- to the call to Create_Task.
9930 -- The _Relative_Deadline field is present only if a Relative_Deadline
9931 -- pragma appears in the task definition. The expression captures the
9932 -- argument that was present in the pragma, and is used to provide the
9933 -- Relative_Deadline parameter to the call to Create_Task.
9935 -- When a task is declared, an instance of the task value record is
9936 -- created. The elaboration of this declaration creates the correct bounds
9937 -- for the entry families, and also evaluates the size, priority, and
9938 -- task_Info expressions if needed. The initialization routine for the task
9939 -- type itself then calls Create_Task with appropriate parameters to
9940 -- initialize the value of the Task_Id field.
9942 -- Note: the address of this record is passed as the "Discriminants"
9943 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9944 -- body procedure, it does not matter that it does not quite match the
9945 -- GNARLI model of what is being passed (the record contains more than just
9946 -- the discriminants, but the discriminants can be found from the record
9949 -- The Entity_Id for this created record type is placed in the
9950 -- Corresponding_Record_Type field of the associated task type entity.
9952 -- Next we create a procedure specification for the task body procedure:
9954 -- procedure taskB (_Task : access taskV);
9956 -- Note that this must come after the record type declaration, since
9957 -- the spec refers to this type. It turns out that the initialization
9958 -- procedure for the value type references the task body spec, but that's
9959 -- fine, since it won't be generated till the freeze point for the type,
9960 -- which is certainly after the task body spec declaration.
9962 -- Finally, we set the task index value field of the entry attribute in
9963 -- the case of a simple entry.
9965 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9966 Loc : constant Source_Ptr := Sloc (N);
9967 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9968 Tasknm : constant Name_Id := Chars (Tasktyp);
9969 Taskdef : constant Node_Id := Task_Definition (N);
9971 Proc_Spec : Node_Id;
9973 Rec_Ent : Entity_Id;
9975 Elab_Decl : Node_Id;
9976 Size_Decl : Node_Id;
9977 Body_Decl : Node_Id;
9978 Task_Size : Node_Id;
9979 Ent_Stack : Entity_Id;
9980 Decl_Stack : Node_Id;
9983 -- If already expanded, nothing to do
9985 if Present (Corresponding_Record_Type (Tasktyp)) then
9989 -- Here we will do the expansion
9991 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9993 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9994 -- of implemented interfaces.
9996 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9998 Rec_Ent := Defining_Identifier (Rec_Decl);
9999 Cdecls := Component_Items (Component_List
10000 (Type_Definition (Rec_Decl)));
10002 Qualify_Entity_Names (N);
10004 -- First create the elaboration variable
10007 Make_Object_Declaration (Loc,
10008 Defining_Identifier =>
10009 Make_Defining_Identifier (Sloc (Tasktyp),
10010 Chars => New_External_Name (Tasknm, 'E')),
10011 Aliased_Present => True,
10012 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10013 Expression => New_Reference_To (Standard_False, Loc));
10014 Insert_After (N, Elab_Decl);
10016 -- Next create the declaration of the size variable (tasknmZ)
10018 Set_Storage_Size_Variable (Tasktyp,
10019 Make_Defining_Identifier (Sloc (Tasktyp),
10020 Chars => New_External_Name (Tasknm, 'Z')));
10022 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
10023 Is_Static_Expression (Expression (First (
10024 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
10025 Taskdef, Name_Storage_Size)))))
10028 Make_Object_Declaration (Loc,
10029 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10030 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10032 Convert_To (RTE (RE_Size_Type),
10034 Expression (First (
10035 Pragma_Argument_Associations (
10036 Find_Task_Or_Protected_Pragma
10037 (Taskdef, Name_Storage_Size)))))));
10041 Make_Object_Declaration (Loc,
10042 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10043 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10044 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10047 Insert_After (Elab_Decl, Size_Decl);
10049 -- Next build the rest of the corresponding record declaration. This is
10050 -- done last, since the corresponding record initialization procedure
10051 -- will reference the previously created entities.
10053 -- Fill in the component declarations -- first the _Task_Id field
10056 Make_Component_Declaration (Loc,
10057 Defining_Identifier =>
10058 Make_Defining_Identifier (Loc, Name_uTask_Id),
10059 Component_Definition =>
10060 Make_Component_Definition (Loc,
10061 Aliased_Present => False,
10062 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10065 -- Declare static ATCB (that is, created by the expander) if we are
10066 -- using the Restricted run time.
10068 if Restricted_Profile then
10070 Make_Component_Declaration (Loc,
10071 Defining_Identifier =>
10072 Make_Defining_Identifier (Loc, Name_uATCB),
10074 Component_Definition =>
10075 Make_Component_Definition (Loc,
10076 Aliased_Present => True,
10077 Subtype_Indication => Make_Subtype_Indication (Loc,
10078 Subtype_Mark => New_Occurrence_Of
10079 (RTE (RE_Ada_Task_Control_Block), Loc),
10082 Make_Index_Or_Discriminant_Constraint (Loc,
10084 New_List (Make_Integer_Literal (Loc, 0)))))));
10088 -- Declare static stack (that is, created by the expander) if we are
10089 -- using the Restricted run time on a bare board configuration.
10091 if Restricted_Profile
10092 and then Preallocated_Stacks_On_Target
10094 -- First we need to extract the appropriate stack size
10096 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10098 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10100 Expr_N : constant Node_Id :=
10101 Expression (First (
10102 Pragma_Argument_Associations (
10103 Find_Task_Or_Protected_Pragma
10104 (Taskdef, Name_Storage_Size))));
10105 Etyp : constant Entity_Id := Etype (Expr_N);
10106 P : constant Node_Id := Parent (Expr_N);
10109 -- The stack is defined inside the corresponding record.
10110 -- Therefore if the size of the stack is set by means of
10111 -- a discriminant, we must reference the discriminant of the
10112 -- corresponding record type.
10114 if Nkind (Expr_N) in N_Has_Entity
10115 and then Present (Discriminal_Link (Entity (Expr_N)))
10119 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10121 Set_Parent (Task_Size, P);
10122 Set_Etype (Task_Size, Etyp);
10123 Set_Analyzed (Task_Size);
10126 Task_Size := Relocate_Node (Expr_N);
10132 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10135 Decl_Stack := Make_Component_Declaration (Loc,
10136 Defining_Identifier => Ent_Stack,
10138 Component_Definition =>
10139 Make_Component_Definition (Loc,
10140 Aliased_Present => True,
10141 Subtype_Indication => Make_Subtype_Indication (Loc,
10143 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10146 Make_Index_Or_Discriminant_Constraint (Loc,
10147 Constraints => New_List (Make_Range (Loc,
10148 Low_Bound => Make_Integer_Literal (Loc, 1),
10149 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10152 Append_To (Cdecls, Decl_Stack);
10154 -- The appropriate alignment for the stack is ensured by the run-time
10155 -- code in charge of task creation.
10159 -- Add components for entry families
10161 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10163 -- Add the _Priority component if a Priority pragma is present
10165 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
10167 Prag : constant Node_Id :=
10168 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10172 Expr := First (Pragma_Argument_Associations (Prag));
10174 if Nkind (Expr) = N_Pragma_Argument_Association then
10175 Expr := Expression (Expr);
10178 Expr := New_Copy_Tree (Expr);
10180 -- Add conversion to proper type to do range check if required
10181 -- Note that for runtime units, we allow out of range interrupt
10182 -- priority values to be used in a priority pragma. This is for
10183 -- the benefit of some versions of System.Interrupts which use
10184 -- a special server task with maximum interrupt priority.
10186 if Pragma_Name (Prag) = Name_Priority
10187 and then not GNAT_Mode
10189 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10191 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10195 Make_Component_Declaration (Loc,
10196 Defining_Identifier =>
10197 Make_Defining_Identifier (Loc, Name_uPriority),
10198 Component_Definition =>
10199 Make_Component_Definition (Loc,
10200 Aliased_Present => False,
10201 Subtype_Indication => New_Reference_To (Standard_Integer,
10203 Expression => Expr));
10207 -- Add the _Task_Size component if a Storage_Size pragma is present
10209 if Present (Taskdef)
10210 and then Has_Storage_Size_Pragma (Taskdef)
10213 Make_Component_Declaration (Loc,
10214 Defining_Identifier =>
10215 Make_Defining_Identifier (Loc, Name_uSize),
10217 Component_Definition =>
10218 Make_Component_Definition (Loc,
10219 Aliased_Present => False,
10220 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10224 Convert_To (RTE (RE_Size_Type),
10226 Expression (First (
10227 Pragma_Argument_Associations (
10228 Find_Task_Or_Protected_Pragma
10229 (Taskdef, Name_Storage_Size))))))));
10232 -- Add the _Task_Info component if a Task_Info pragma is present
10234 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10236 Make_Component_Declaration (Loc,
10237 Defining_Identifier =>
10238 Make_Defining_Identifier (Loc, Name_uTask_Info),
10240 Component_Definition =>
10241 Make_Component_Definition (Loc,
10242 Aliased_Present => False,
10243 Subtype_Indication =>
10244 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10246 Expression => New_Copy (
10247 Expression (First (
10248 Pragma_Argument_Associations (
10249 Find_Task_Or_Protected_Pragma
10250 (Taskdef, Name_Task_Info)))))));
10253 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10254 -- present. If we are using a restricted run time this component will
10255 -- not be added (deadlines are not allowed by the Ravenscar profile).
10257 if not Restricted_Profile
10258 and then Present (Taskdef)
10259 and then Has_Relative_Deadline_Pragma (Taskdef)
10262 Make_Component_Declaration (Loc,
10263 Defining_Identifier =>
10264 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10266 Component_Definition =>
10267 Make_Component_Definition (Loc,
10268 Aliased_Present => False,
10269 Subtype_Indication =>
10270 New_Reference_To (RTE (RE_Time_Span), Loc)),
10273 Convert_To (RTE (RE_Time_Span),
10275 Expression (First (
10276 Pragma_Argument_Associations (
10277 Find_Task_Or_Protected_Pragma
10278 (Taskdef, Name_Relative_Deadline))))))));
10281 Insert_After (Size_Decl, Rec_Decl);
10283 -- Analyze the record declaration immediately after construction,
10284 -- because the initialization procedure is needed for single task
10285 -- declarations before the next entity is analyzed.
10287 Analyze (Rec_Decl);
10289 -- Create the declaration of the task body procedure
10291 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10293 Make_Subprogram_Declaration (Loc,
10294 Specification => Proc_Spec);
10296 Insert_After (Rec_Decl, Body_Decl);
10298 -- The subprogram does not comes from source, so we have to indicate the
10299 -- need for debugging information explicitly.
10301 if Comes_From_Source (Original_Node (N)) then
10302 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10305 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10306 -- the corresponding record has been frozen.
10308 if Ada_Version >= Ada_05 then
10309 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10312 -- Ada 2005 (AI-345): We must defer freezing to allow further
10313 -- declaration of primitive subprograms covering task interfaces
10315 if Ada_Version <= Ada_95 then
10317 -- Now we can freeze the corresponding record. This needs manually
10318 -- freezing, since it is really part of the task type, and the task
10319 -- type is frozen at this stage. We of course need the initialization
10320 -- procedure for this corresponding record type and we won't get it
10321 -- in time if we don't freeze now.
10324 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
10326 if Is_Non_Empty_List (L) then
10327 Insert_List_After (Body_Decl, L);
10332 -- Complete the expansion of access types to the current task type, if
10333 -- any were declared.
10335 Expand_Previous_Access_Type (Tasktyp);
10336 end Expand_N_Task_Type_Declaration;
10338 -------------------------------
10339 -- Expand_N_Timed_Entry_Call --
10340 -------------------------------
10342 -- A timed entry call in normal case is not implemented using ATC mechanism
10343 -- anymore for efficiency reason.
10353 -- is expanded as follow:
10355 -- 1) When T.E is a task entry_call;
10359 -- X : Task_Entry_Index := <entry index>;
10360 -- DX : Duration := To_Duration (D);
10361 -- M : Delay_Mode := <discriminant>;
10362 -- P : parms := (parm, parm, parm);
10365 -- Timed_Protected_Entry_Call
10366 -- (<acceptor-task>, X, P'Address, DX, M, B);
10374 -- 2) When T.E is a protected entry_call;
10378 -- X : Protected_Entry_Index := <entry index>;
10379 -- DX : Duration := To_Duration (D);
10380 -- M : Delay_Mode := <discriminant>;
10381 -- P : parms := (parm, parm, parm);
10384 -- Timed_Protected_Entry_Call
10385 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10393 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10396 -- B : Boolean := False;
10397 -- C : Ada.Tags.Prim_Op_Kind;
10398 -- DX : Duration := To_Duration (D)
10399 -- K : Ada.Tags.Tagged_Kind :=
10400 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10401 -- M : Integer :=...;
10402 -- P : Parameters := (Param1 .. ParamN);
10406 -- if K = Ada.Tags.TK_Limited_Tagged then
10407 -- <dispatching-call>;
10408 -- <triggering-statements>
10412 -- Ada.Tags.Get_Offset_Index
10413 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10415 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10417 -- if C = POK_Protected_Entry
10418 -- or else C = POK_Task_Entry
10420 -- Param1 := P.Param1;
10422 -- ParamN := P.ParamN;
10426 -- if C = POK_Procedure
10427 -- or else C = POK_Protected_Procedure
10428 -- or else C = POK_Task_Procedure
10430 -- <dispatching-call>;
10433 -- <triggering-statements>
10435 -- <timed-statements>
10440 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10441 Loc : constant Source_Ptr := Sloc (N);
10443 E_Call : Node_Id :=
10444 Entry_Call_Statement (Entry_Call_Alternative (N));
10445 E_Stats : constant List_Id :=
10446 Statements (Entry_Call_Alternative (N));
10447 D_Stat : Node_Id :=
10448 Delay_Statement (Delay_Alternative (N));
10449 D_Stats : constant List_Id :=
10450 Statements (Delay_Alternative (N));
10453 Blk_Typ : Entity_Id;
10455 Call_Ent : Entity_Id;
10456 Conc_Typ_Stmts : List_Id;
10460 D_Type : Entity_Id;
10466 Is_Disp_Select : Boolean;
10467 Lim_Typ_Stmts : List_Id;
10476 B : Entity_Id; -- Call status flag
10477 C : Entity_Id; -- Call kind
10478 D : Entity_Id; -- Delay
10479 K : Entity_Id; -- Tagged kind
10480 M : Entity_Id; -- Delay mode
10481 P : Entity_Id; -- Parameter block
10482 S : Entity_Id; -- Primitive operation slot
10485 -- Under the Ravenscar profile, timed entry calls are excluded. An error
10486 -- was already reported on spec, so do not attempt to expand the call.
10488 if Restriction_Active (No_Select_Statements) then
10492 -- The arguments in the call may require dynamic allocation, and the
10493 -- call statement may have been transformed into a block. The block
10494 -- may contain additional declarations for internal entities, and the
10495 -- original call is found by sequential search.
10497 if Nkind (E_Call) = N_Block_Statement then
10498 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10499 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10500 N_Entry_Call_Statement)
10507 Ada_Version >= Ada_05
10508 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10510 if Is_Disp_Select then
10511 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
10517 -- B : Boolean := False;
10519 B := Build_B (Loc, Decls);
10522 -- C : Ada.Tags.Prim_Op_Kind;
10524 C := Build_C (Loc, Decls);
10526 -- Because the analysis of all statements was disabled, manually
10527 -- analyze the delay statement.
10530 D_Stat := Original_Node (D_Stat);
10533 -- Build an entry call using Simple_Entry_Call
10535 Extract_Entry (E_Call, Concval, Ename, Index);
10536 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
10538 Decls := Declarations (E_Call);
10539 Stmts := Statements (Handled_Statement_Sequence (E_Call));
10548 B := Make_Defining_Identifier (Loc, Name_uB);
10551 Make_Object_Declaration (Loc,
10552 Defining_Identifier =>
10554 Object_Definition =>
10555 New_Reference_To (Standard_Boolean, Loc)));
10558 -- Duration and mode processing
10560 D_Type := Base_Type (Etype (Expression (D_Stat)));
10562 -- Use the type of the delay expression (Calendar or Real_Time) to
10563 -- generate the appropriate conversion.
10565 if Nkind (D_Stat) = N_Delay_Relative_Statement then
10566 D_Disc := Make_Integer_Literal (Loc, 0);
10567 D_Conv := Relocate_Node (Expression (D_Stat));
10569 elsif Is_RTE (D_Type, RO_CA_Time) then
10570 D_Disc := Make_Integer_Literal (Loc, 1);
10571 D_Conv := Make_Function_Call (Loc,
10572 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10573 New_List (New_Copy (Expression (D_Stat))));
10575 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
10576 D_Disc := Make_Integer_Literal (Loc, 2);
10577 D_Conv := Make_Function_Call (Loc,
10578 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10579 New_List (New_Copy (Expression (D_Stat))));
10582 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
10588 Make_Object_Declaration (Loc,
10589 Defining_Identifier =>
10591 Object_Definition =>
10592 New_Reference_To (Standard_Duration, Loc)));
10594 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
10597 -- M : Integer := (0 | 1 | 2);
10600 Make_Object_Declaration (Loc,
10601 Defining_Identifier =>
10603 Object_Definition =>
10604 New_Reference_To (Standard_Integer, Loc),
10608 -- Do the assignment at this stage only because the evaluation of the
10609 -- expression must not occur before (see ACVC C97302A).
10612 Make_Assignment_Statement (Loc,
10614 New_Reference_To (D, Loc),
10618 -- Parameter block processing
10620 -- Manually create the parameter block for dispatching calls. In the
10621 -- case of entries, the block has already been created during the call
10622 -- to Build_Simple_Entry_Call.
10624 if Is_Disp_Select then
10626 -- Tagged kind processing, generate:
10627 -- K : Ada.Tags.Tagged_Kind :=
10628 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
10630 K := Build_K (Loc, Decls, Obj);
10632 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
10633 P := Parameter_Block_Pack
10634 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
10636 -- Dispatch table slot processing, generate:
10639 S := Build_S (Loc, Decls);
10642 -- S := Ada.Tags.Get_Offset_Index
10643 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
10646 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
10649 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
10651 -- where Obj is the controlling formal parameter, S is the dispatch
10652 -- table slot number of the dispatching operation, P is the wrapped
10653 -- parameter block, D is the duration, M is the duration mode, C is
10654 -- the call kind and B is the call status.
10656 Params := New_List;
10658 Append_To (Params, New_Copy_Tree (Obj));
10659 Append_To (Params, New_Reference_To (S, Loc));
10660 Append_To (Params, Make_Attribute_Reference (Loc,
10661 Prefix => New_Reference_To (P, Loc),
10662 Attribute_Name => Name_Address));
10663 Append_To (Params, New_Reference_To (D, Loc));
10664 Append_To (Params, New_Reference_To (M, Loc));
10665 Append_To (Params, New_Reference_To (C, Loc));
10666 Append_To (Params, New_Reference_To (B, Loc));
10668 Append_To (Conc_Typ_Stmts,
10669 Make_Procedure_Call_Statement (Loc,
10672 Find_Prim_Op (Etype (Etype (Obj)),
10673 Name_uDisp_Timed_Select),
10675 Parameter_Associations =>
10679 -- if C = POK_Protected_Entry
10680 -- or else C = POK_Task_Entry
10682 -- Param1 := P.Param1;
10684 -- ParamN := P.ParamN;
10687 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
10689 -- Generate the if statement only when the packed parameters need
10690 -- explicit assignments to their corresponding actuals.
10692 if Present (Unpack) then
10693 Append_To (Conc_Typ_Stmts,
10694 Make_If_Statement (Loc,
10701 New_Reference_To (C, Loc),
10703 New_Reference_To (RTE (
10704 RE_POK_Protected_Entry), Loc)),
10708 New_Reference_To (C, Loc),
10710 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
10719 -- if C = POK_Procedure
10720 -- or else C = POK_Protected_Procedure
10721 -- or else C = POK_Task_Procedure
10723 -- <dispatching-call>
10725 -- <triggering-statements>
10727 -- <timed-statements>
10730 N_Stats := New_Copy_List_Tree (E_Stats);
10732 Prepend_To (N_Stats,
10733 Make_If_Statement (Loc,
10740 New_Reference_To (C, Loc),
10742 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
10748 New_Reference_To (C, Loc),
10750 New_Reference_To (RTE (
10751 RE_POK_Protected_Procedure), Loc)),
10755 New_Reference_To (C, Loc),
10757 New_Reference_To (RTE (
10758 RE_POK_Task_Procedure), Loc)))),
10761 New_List (E_Call)));
10763 Append_To (Conc_Typ_Stmts,
10764 Make_If_Statement (Loc,
10765 Condition => New_Reference_To (B, Loc),
10766 Then_Statements => N_Stats,
10767 Else_Statements => D_Stats));
10770 -- <dispatching-call>;
10771 -- <triggering-statements>
10773 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
10774 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
10777 -- if K = Ada.Tags.TK_Limited_Tagged then
10784 Make_If_Statement (Loc,
10788 New_Reference_To (K, Loc),
10790 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
10799 -- Skip assignments to temporaries created for in-out parameters.
10800 -- This makes unwarranted assumptions about the shape of the expanded
10801 -- tree for the call, and should be cleaned up ???
10803 Stmt := First (Stmts);
10804 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
10808 -- Do the assignment at this stage only because the evaluation
10809 -- of the expression must not occur before (see ACVC C97302A).
10811 Insert_Before (Stmt,
10812 Make_Assignment_Statement (Loc,
10813 Name => New_Reference_To (D, Loc),
10814 Expression => D_Conv));
10817 Params := Parameter_Associations (Call);
10819 -- For a protected type, we build a Timed_Protected_Entry_Call
10821 if Is_Protected_Type (Etype (Concval)) then
10823 -- Create a new call statement
10825 Param := First (Params);
10826 while Present (Param)
10827 and then not Is_RTE (Etype (Param), RE_Call_Modes)
10832 Dummy := Remove_Next (Next (Param));
10834 -- Remove garbage is following the Cancel_Param if present
10836 Dummy := Next (Param);
10838 -- Remove the mode of the Protected_Entry_Call call, then remove
10839 -- the Communication_Block of the Protected_Entry_Call call, and
10840 -- finally add Duration and a Delay_Mode parameter
10842 pragma Assert (Present (Param));
10843 Rewrite (Param, New_Reference_To (D, Loc));
10845 Rewrite (Dummy, New_Reference_To (M, Loc));
10847 -- Add a Boolean flag for successful entry call
10849 Append_To (Params, New_Reference_To (B, Loc));
10851 case Corresponding_Runtime_Package (Etype (Concval)) is
10852 when System_Tasking_Protected_Objects_Entries =>
10854 Make_Procedure_Call_Statement (Loc,
10857 (RTE (RE_Timed_Protected_Entry_Call), Loc),
10858 Parameter_Associations => Params));
10860 when System_Tasking_Protected_Objects_Single_Entry =>
10861 Param := First (Params);
10862 while Present (Param)
10864 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
10872 Make_Procedure_Call_Statement (Loc,
10873 Name => New_Reference_To (
10874 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
10875 Parameter_Associations => Params));
10878 raise Program_Error;
10881 -- For the task case, build a Timed_Task_Entry_Call
10884 -- Create a new call statement
10886 Append_To (Params, New_Reference_To (D, Loc));
10887 Append_To (Params, New_Reference_To (M, Loc));
10888 Append_To (Params, New_Reference_To (B, Loc));
10891 Make_Procedure_Call_Statement (Loc,
10893 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
10894 Parameter_Associations => Params));
10898 Make_Implicit_If_Statement (N,
10899 Condition => New_Reference_To (B, Loc),
10900 Then_Statements => E_Stats,
10901 Else_Statements => D_Stats));
10905 Make_Block_Statement (Loc,
10906 Declarations => Decls,
10907 Handled_Statement_Sequence =>
10908 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
10911 end Expand_N_Timed_Entry_Call;
10913 ----------------------------------------
10914 -- Expand_Protected_Body_Declarations --
10915 ----------------------------------------
10917 procedure Expand_Protected_Body_Declarations
10919 Spec_Id : Entity_Id)
10922 if No_Run_Time_Mode then
10923 Error_Msg_CRT ("protected body", N);
10926 elsif Expander_Active then
10928 -- Associate discriminals with the first subprogram or entry body to
10931 if Present (First_Protected_Operation (Declarations (N))) then
10932 Set_Discriminals (Parent (Spec_Id));
10935 end Expand_Protected_Body_Declarations;
10937 -------------------------
10938 -- External_Subprogram --
10939 -------------------------
10941 function External_Subprogram (E : Entity_Id) return Entity_Id is
10942 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10945 -- The internal and external subprograms follow each other on the entity
10946 -- chain. Note that previously private operations had no separate
10947 -- external subprogram. We now create one in all cases, because a
10948 -- private operation may actually appear in an external call, through
10949 -- a 'Access reference used for a callback.
10951 -- If the operation is a function that returns an anonymous access type,
10952 -- the corresponding itype appears before the operation, and must be
10955 -- This mechanism is fragile, there should be a real link between the
10956 -- two versions of the operation, but there is no place to put it ???
10958 if Is_Access_Type (Next_Entity (Subp)) then
10959 return Next_Entity (Next_Entity (Subp));
10961 return Next_Entity (Subp);
10963 end External_Subprogram;
10965 ------------------------------
10966 -- Extract_Dispatching_Call --
10967 ------------------------------
10969 procedure Extract_Dispatching_Call
10971 Call_Ent : out Entity_Id;
10972 Object : out Entity_Id;
10973 Actuals : out List_Id;
10974 Formals : out List_Id)
10976 Call_Nam : Node_Id;
10979 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10981 if Present (Original_Node (N)) then
10982 Call_Nam := Name (Original_Node (N));
10984 Call_Nam := Name (N);
10987 -- Retrieve the name of the dispatching procedure. It contains the
10988 -- dispatch table slot number.
10991 case Nkind (Call_Nam) is
10992 when N_Identifier =>
10995 when N_Selected_Component =>
10996 Call_Nam := Selector_Name (Call_Nam);
10999 raise Program_Error;
11004 Actuals := Parameter_Associations (N);
11005 Call_Ent := Entity (Call_Nam);
11006 Formals := Parameter_Specifications (Parent (Call_Ent));
11007 Object := First (Actuals);
11009 if Present (Original_Node (Object)) then
11010 Object := Original_Node (Object);
11012 end Extract_Dispatching_Call;
11014 -------------------
11015 -- Extract_Entry --
11016 -------------------
11018 procedure Extract_Entry
11020 Concval : out Node_Id;
11021 Ename : out Node_Id;
11022 Index : out Node_Id)
11024 Nam : constant Node_Id := Name (N);
11027 -- For a simple entry, the name is a selected component, with the
11028 -- prefix being the task value, and the selector being the entry.
11030 if Nkind (Nam) = N_Selected_Component then
11031 Concval := Prefix (Nam);
11032 Ename := Selector_Name (Nam);
11035 -- For a member of an entry family, the name is an indexed component
11036 -- where the prefix is a selected component, whose prefix in turn is
11037 -- the task value, and whose selector is the entry family. The single
11038 -- expression in the expressions list of the indexed component is the
11039 -- subscript for the family.
11041 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11042 Concval := Prefix (Prefix (Nam));
11043 Ename := Selector_Name (Prefix (Nam));
11044 Index := First (Expressions (Nam));
11048 -------------------
11049 -- Family_Offset --
11050 -------------------
11052 function Family_Offset
11057 Cap : Boolean) return Node_Id
11063 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11064 -- If one of the bounds is a reference to a discriminant, replace with
11065 -- corresponding discriminal of type. Within the body of a task retrieve
11066 -- the renamed discriminant by simple visibility, using its generated
11067 -- name. Within a protected object, find the original discriminant and
11068 -- replace it with the discriminal of the current protected operation.
11070 ------------------------------
11071 -- Convert_Discriminant_Ref --
11072 ------------------------------
11074 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11075 Loc : constant Source_Ptr := Sloc (Bound);
11080 if Is_Entity_Name (Bound)
11081 and then Ekind (Entity (Bound)) = E_Discriminant
11083 if Is_Task_Type (Ttyp)
11084 and then Has_Completion (Ttyp)
11086 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11087 Find_Direct_Name (B);
11089 elsif Is_Protected_Type (Ttyp) then
11090 D := First_Discriminant (Ttyp);
11091 while Chars (D) /= Chars (Entity (Bound)) loop
11092 Next_Discriminant (D);
11095 B := New_Reference_To (Discriminal (D), Loc);
11098 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11101 elsif Nkind (Bound) = N_Attribute_Reference then
11105 B := New_Copy_Tree (Bound);
11109 Make_Attribute_Reference (Loc,
11110 Attribute_Name => Name_Pos,
11111 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11112 Expressions => New_List (B));
11113 end Convert_Discriminant_Ref;
11115 -- Start of processing for Family_Offset
11118 Real_Hi := Convert_Discriminant_Ref (Hi);
11119 Real_Lo := Convert_Discriminant_Ref (Lo);
11122 if Is_Task_Type (Ttyp) then
11123 Ityp := RTE (RE_Task_Entry_Index);
11125 Ityp := RTE (RE_Protected_Entry_Index);
11129 Make_Attribute_Reference (Loc,
11130 Prefix => New_Reference_To (Ityp, Loc),
11131 Attribute_Name => Name_Min,
11132 Expressions => New_List (
11134 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11137 Make_Attribute_Reference (Loc,
11138 Prefix => New_Reference_To (Ityp, Loc),
11139 Attribute_Name => Name_Max,
11140 Expressions => New_List (
11142 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11145 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11152 function Family_Size
11157 Cap : Boolean) return Node_Id
11162 if Is_Task_Type (Ttyp) then
11163 Ityp := RTE (RE_Task_Entry_Index);
11165 Ityp := RTE (RE_Protected_Entry_Index);
11169 Make_Attribute_Reference (Loc,
11170 Prefix => New_Reference_To (Ityp, Loc),
11171 Attribute_Name => Name_Max,
11172 Expressions => New_List (
11175 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11177 Make_Integer_Literal (Loc, 1)),
11178 Make_Integer_Literal (Loc, 0)));
11181 -----------------------------------
11182 -- Find_Task_Or_Protected_Pragma --
11183 -----------------------------------
11185 function Find_Task_Or_Protected_Pragma
11187 P : Name_Id) return Node_Id
11192 N := First (Visible_Declarations (T));
11193 while Present (N) loop
11194 if Nkind (N) = N_Pragma then
11195 if Pragma_Name (N) = P then
11198 elsif P = Name_Priority
11199 and then Pragma_Name (N) = Name_Interrupt_Priority
11212 N := First (Private_Declarations (T));
11213 while Present (N) loop
11214 if Nkind (N) = N_Pragma then
11215 if Pragma_Name (N) = P then
11218 elsif P = Name_Priority
11219 and then Pragma_Name (N) = Name_Interrupt_Priority
11232 raise Program_Error;
11233 end Find_Task_Or_Protected_Pragma;
11235 -------------------------------
11236 -- First_Protected_Operation --
11237 -------------------------------
11239 function First_Protected_Operation (D : List_Id) return Node_Id is
11240 First_Op : Node_Id;
11243 First_Op := First (D);
11244 while Present (First_Op)
11245 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11251 end First_Protected_Operation;
11253 ---------------------------------------
11254 -- Install_Private_Data_Declarations --
11255 ---------------------------------------
11257 procedure Install_Private_Data_Declarations
11259 Spec_Id : Entity_Id;
11260 Conc_Typ : Entity_Id;
11261 Body_Nod : Node_Id;
11263 Barrier : Boolean := False;
11264 Family : Boolean := False)
11266 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11269 Insert_Node : Node_Id := Empty;
11270 Obj_Ent : Entity_Id;
11272 procedure Add (Decl : Node_Id);
11273 -- Add a single declaration after Insert_Node. If this is the first
11274 -- addition, Decl is added to the front of Decls and it becomes the
11277 function Replace_Bound (Bound : Node_Id) return Node_Id;
11278 -- The bounds of an entry index may depend on discriminants, create a
11279 -- reference to the corresponding prival. Otherwise return a duplicate
11280 -- of the original bound.
11286 procedure Add (Decl : Node_Id) is
11288 if No (Insert_Node) then
11289 Prepend_To (Decls, Decl);
11291 Insert_After (Insert_Node, Decl);
11294 Insert_Node := Decl;
11297 --------------------------
11298 -- Replace_Discriminant --
11299 --------------------------
11301 function Replace_Bound (Bound : Node_Id) return Node_Id is
11303 if Nkind (Bound) = N_Identifier
11304 and then Is_Discriminal (Entity (Bound))
11306 return Make_Identifier (Loc, Chars (Entity (Bound)));
11308 return Duplicate_Subexpr (Bound);
11312 -- Start of processing for Install_Private_Data_Declarations
11315 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11316 -- formal parameter _O, _object or _task depending on the context.
11318 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11320 -- Special processing of _O for barrier functions, protected entries
11327 (Ekind (Spec_Id) = E_Entry
11328 or else Ekind (Spec_Id) = E_Entry_Family))
11331 Conc_Rec : constant Entity_Id :=
11332 Corresponding_Record_Type (Conc_Typ);
11333 Typ_Id : constant Entity_Id :=
11334 Make_Defining_Identifier (Loc,
11335 New_External_Name (Chars (Conc_Rec), 'P'));
11338 -- type prot_typVP is access prot_typV;
11341 Make_Full_Type_Declaration (Loc,
11342 Defining_Identifier => Typ_Id,
11344 Make_Access_To_Object_Definition (Loc,
11345 Subtype_Indication =>
11346 New_Reference_To (Conc_Rec, Loc)));
11350 -- _object : prot_typVP := prot_typV (_O);
11353 Make_Object_Declaration (Loc,
11354 Defining_Identifier =>
11355 Make_Defining_Identifier (Loc, Name_uObject),
11356 Object_Definition => New_Reference_To (Typ_Id, Loc),
11358 Unchecked_Convert_To (Typ_Id,
11359 New_Reference_To (Obj_Ent, Loc)));
11362 -- Set the reference to the concurrent object
11364 Obj_Ent := Defining_Identifier (Decl);
11368 -- Step 2: Create the Protection object and build its declaration for
11369 -- any protected entry (family) of subprogram.
11371 if Is_Protected then
11373 Prot_Ent : constant Entity_Id :=
11374 Make_Defining_Identifier (Loc,
11375 New_Internal_Name ('R'));
11379 Set_Protection_Object (Spec_Id, Prot_Ent);
11381 -- Determine the proper protection type
11383 if Has_Attach_Handler (Conc_Typ)
11384 and then not Restricted_Profile
11386 Prot_Typ := RE_Static_Interrupt_Protection;
11388 elsif Has_Interrupt_Handler (Conc_Typ) then
11389 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11391 -- The type has explicit entries or generated primitive entry
11394 elsif Has_Entries (Conc_Typ)
11396 (Ada_Version >= Ada_05
11397 and then Present (Interface_List (Parent (Conc_Typ))))
11399 case Corresponding_Runtime_Package (Conc_Typ) is
11400 when System_Tasking_Protected_Objects_Entries =>
11401 Prot_Typ := RE_Protection_Entries;
11403 when System_Tasking_Protected_Objects_Single_Entry =>
11404 Prot_Typ := RE_Protection_Entry;
11407 raise Program_Error;
11411 Prot_Typ := RE_Protection;
11415 -- conc_typR : protection_typ renames _object._object;
11418 Make_Object_Renaming_Declaration (Loc,
11419 Defining_Identifier => Prot_Ent,
11421 New_Reference_To (RTE (Prot_Typ), Loc),
11423 Make_Selected_Component (Loc,
11425 New_Reference_To (Obj_Ent, Loc),
11427 Make_Identifier (Loc, Name_uObject)));
11432 -- Step 3: Add discriminant renamings (if any)
11434 if Has_Discriminants (Conc_Typ) then
11439 D := First_Discriminant (Conc_Typ);
11440 while Present (D) loop
11442 -- Adjust the source location
11444 Set_Sloc (Discriminal (D), Loc);
11447 -- discr_name : discr_typ renames _object.discr_name;
11449 -- discr_name : discr_typ renames _task.discr_name;
11452 Make_Object_Renaming_Declaration (Loc,
11453 Defining_Identifier => Discriminal (D),
11454 Subtype_Mark => New_Reference_To (Etype (D), Loc),
11456 Make_Selected_Component (Loc,
11457 Prefix => New_Reference_To (Obj_Ent, Loc),
11458 Selector_Name => Make_Identifier (Loc, Chars (D))));
11461 Next_Discriminant (D);
11466 -- Step 4: Add private component renamings (if any)
11468 if Is_Protected then
11469 Def := Protected_Definition (Parent (Conc_Typ));
11471 if Present (Private_Declarations (Def)) then
11474 Comp_Id : Entity_Id;
11475 Decl_Id : Entity_Id;
11478 Comp := First (Private_Declarations (Def));
11479 while Present (Comp) loop
11480 if Nkind (Comp) = N_Component_Declaration then
11481 Comp_Id := Defining_Identifier (Comp);
11483 Make_Defining_Identifier (Loc, Chars (Comp_Id));
11485 -- Minimal decoration
11487 if Ekind (Spec_Id) = E_Function then
11488 Set_Ekind (Decl_Id, E_Constant);
11490 Set_Ekind (Decl_Id, E_Variable);
11493 Set_Prival (Comp_Id, Decl_Id);
11494 Set_Prival_Link (Decl_Id, Comp_Id);
11495 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
11498 -- comp_name : comp_typ renames _object.comp_name;
11501 Make_Object_Renaming_Declaration (Loc,
11502 Defining_Identifier => Decl_Id,
11504 New_Reference_To (Etype (Comp_Id), Loc),
11506 Make_Selected_Component (Loc,
11508 New_Reference_To (Obj_Ent, Loc),
11510 Make_Identifier (Loc, Chars (Comp_Id))));
11520 -- Step 5: Add the declaration of the entry index and the associated
11521 -- type for barrier functions and entry families.
11523 if (Barrier and then Family)
11524 or else Ekind (Spec_Id) = E_Entry_Family
11527 E : constant Entity_Id := Index_Object (Spec_Id);
11528 Index : constant Entity_Id :=
11529 Defining_Identifier (
11530 Entry_Index_Specification (
11531 Entry_Body_Formal_Part (Body_Nod)));
11532 Index_Con : constant Entity_Id :=
11533 Make_Defining_Identifier (Loc, Chars (Index));
11535 Index_Typ : Entity_Id;
11539 -- Minimal decoration
11541 Set_Ekind (Index_Con, E_Constant);
11542 Set_Entry_Index_Constant (Index, Index_Con);
11543 Set_Discriminal_Link (Index_Con, Index);
11545 -- Retrieve the bounds of the entry family
11547 High := Type_High_Bound (Etype (Index));
11548 Low := Type_Low_Bound (Etype (Index));
11550 -- In the simple case the entry family is given by a subtype
11551 -- mark and the index constant has the same type.
11553 if Is_Entity_Name (Original_Node (
11554 Discrete_Subtype_Definition (Parent (Index))))
11556 Index_Typ := Etype (Index);
11558 -- Otherwise a new subtype declaration is required
11561 High := Replace_Bound (High);
11562 Low := Replace_Bound (Low);
11565 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
11568 -- subtype Jnn is <Etype of Index> range Low .. High;
11571 Make_Subtype_Declaration (Loc,
11572 Defining_Identifier => Index_Typ,
11573 Subtype_Indication =>
11574 Make_Subtype_Indication (Loc,
11576 New_Reference_To (Base_Type (Etype (Index)), Loc),
11578 Make_Range_Constraint (Loc,
11579 Range_Expression =>
11580 Make_Range (Loc, Low, High))));
11584 Set_Etype (Index_Con, Index_Typ);
11586 -- Create the object which designates the index:
11587 -- J : constant Jnn :=
11588 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
11590 -- where Jnn is the subtype created above or the original type of
11591 -- the index, _E is a formal of the protected body subprogram and
11592 -- <index expr> is the index of the first family member.
11595 Make_Object_Declaration (Loc,
11596 Defining_Identifier => Index_Con,
11597 Constant_Present => True,
11598 Object_Definition =>
11599 New_Reference_To (Index_Typ, Loc),
11602 Make_Attribute_Reference (Loc,
11604 New_Reference_To (Index_Typ, Loc),
11605 Attribute_Name => Name_Val,
11607 Expressions => New_List (
11611 Make_Op_Subtract (Loc,
11613 New_Reference_To (E, Loc),
11615 Entry_Index_Expression (Loc,
11616 Defining_Identifier (Body_Nod),
11620 Make_Attribute_Reference (Loc,
11622 New_Reference_To (Index_Typ, Loc),
11623 Attribute_Name => Name_Pos,
11624 Expressions => New_List (
11625 Make_Attribute_Reference (Loc,
11627 New_Reference_To (Index_Typ, Loc),
11628 Attribute_Name => Name_First)))))));
11632 end Install_Private_Data_Declarations;
11634 ---------------------------------
11635 -- Is_Potentially_Large_Family --
11636 ---------------------------------
11638 function Is_Potentially_Large_Family
11639 (Base_Index : Entity_Id;
11640 Conctyp : Entity_Id;
11642 Hi : Node_Id) return Boolean
11645 return Scope (Base_Index) = Standard_Standard
11646 and then Base_Index = Base_Type (Standard_Integer)
11647 and then Has_Discriminants (Conctyp)
11649 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
11651 (Denotes_Discriminant (Lo, True)
11652 or else Denotes_Discriminant (Hi, True));
11653 end Is_Potentially_Large_Family;
11655 -------------------------------------
11656 -- Is_Private_Primitive_Subprogram --
11657 -------------------------------------
11659 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
11662 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
11663 and then Is_Private_Primitive (Id);
11664 end Is_Private_Primitive_Subprogram;
11670 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
11671 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
11672 Formal : Entity_Id;
11675 Formal := First_Formal (Bod_Subp);
11676 while Present (Formal) loop
11678 -- Look for formal parameter _E
11680 if Chars (Formal) = Name_uE then
11684 Next_Formal (Formal);
11687 -- A protected body subprogram should always have the parameter in
11690 raise Program_Error;
11693 --------------------------------
11694 -- Make_Initialize_Protection --
11695 --------------------------------
11697 function Make_Initialize_Protection
11698 (Protect_Rec : Entity_Id) return List_Id
11700 Loc : constant Source_Ptr := Sloc (Protect_Rec);
11704 Ptyp : constant Node_Id :=
11705 Corresponding_Concurrent_Type (Protect_Rec);
11707 L : constant List_Id := New_List;
11708 Has_Entry : constant Boolean := Has_Entries (Ptyp);
11709 Restricted : constant Boolean := Restricted_Profile;
11712 -- We may need two calls to properly initialize the object, one to
11713 -- Initialize_Protection, and possibly one to Install_Handlers if we
11714 -- have a pragma Attach_Handler.
11716 -- Get protected declaration. In the case of a task type declaration,
11717 -- this is simply the parent of the protected type entity. In the single
11718 -- protected object declaration, this parent will be the implicit type,
11719 -- and we can find the corresponding single protected object declaration
11720 -- by searching forward in the declaration list in the tree.
11722 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
11723 -- of this type should have been removed during semantic analysis.
11725 Pdec := Parent (Ptyp);
11726 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
11727 N_Single_Protected_Declaration)
11732 -- Now we can find the object definition from this declaration
11734 Pdef := Protected_Definition (Pdec);
11736 -- Build the parameter list for the call. Note that _Init is the name
11737 -- of the formal for the object to be initialized, which is the task
11738 -- value record itself.
11742 -- Object parameter. This is a pointer to the object of type
11743 -- Protection used by the GNARL to control the protected object.
11746 Make_Attribute_Reference (Loc,
11748 Make_Selected_Component (Loc,
11749 Prefix => Make_Identifier (Loc, Name_uInit),
11750 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11751 Attribute_Name => Name_Unchecked_Access));
11753 -- Priority parameter. Set to Unspecified_Priority unless there is a
11754 -- priority pragma, in which case we take the value from the pragma,
11755 -- or there is an interrupt pragma and no priority pragma, and we
11756 -- set the ceiling to Interrupt_Priority'Last, an implementation-
11757 -- defined value, see D.3(10).
11760 and then Has_Priority_Pragma (Pdef)
11763 Prio : constant Node_Id :=
11766 (Pragma_Argument_Associations
11767 (Find_Task_Or_Protected_Pragma
11768 (Pdef, Name_Priority))));
11772 -- If priority is a static expression, then we can duplicate it
11773 -- with no problem and simply append it to the argument list.
11775 if Is_Static_Expression (Prio) then
11777 Duplicate_Subexpr_No_Checks (Prio));
11779 -- Otherwise, the priority may be a per-object expression, if it
11780 -- depends on a discriminant of the type. In this case, create
11781 -- local variable to capture the expression. Note that it is
11782 -- really necessary to create this variable explicitly. It might
11783 -- be thought that removing side effects would the appropriate
11784 -- approach, but that could generate declarations improperly
11785 -- placed in the enclosing scope.
11787 -- Note: Use System.Any_Priority as the expected type for the
11788 -- non-static priority expression, in case the expression has not
11789 -- been analyzed yet (as occurs for example with pragma
11790 -- Interrupt_Priority).
11794 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
11797 Make_Object_Declaration (Loc,
11798 Defining_Identifier => Temp,
11799 Object_Definition =>
11800 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
11801 Expression => Relocate_Node (Prio)));
11803 Append_To (Args, New_Occurrence_Of (Temp, Loc));
11807 -- When no priority is specified but an xx_Handler pragma is, we default
11808 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
11810 elsif Has_Interrupt_Handler (Ptyp)
11811 or else Has_Attach_Handler (Ptyp)
11814 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
11816 -- Normal case, no priority or xx_Handler specified, default priority
11820 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11823 -- Test for Compiler_Info parameter. This parameter allows entry body
11824 -- procedures and barrier functions to be called from the runtime. It
11825 -- is a pointer to the record generated by the compiler to represent
11826 -- the protected object.
11829 or else Has_Interrupt_Handler (Ptyp)
11830 or else Has_Attach_Handler (Ptyp)
11831 or else Has_Interfaces (Protect_Rec)
11834 Pkg_Id : constant RTU_Id :=
11835 Corresponding_Runtime_Package (Ptyp);
11836 Called_Subp : RE_Id;
11840 when System_Tasking_Protected_Objects_Entries =>
11841 Called_Subp := RE_Initialize_Protection_Entries;
11843 when System_Tasking_Protected_Objects =>
11844 Called_Subp := RE_Initialize_Protection;
11846 when System_Tasking_Protected_Objects_Single_Entry =>
11847 Called_Subp := RE_Initialize_Protection_Entry;
11850 raise Program_Error;
11853 if Has_Entry or else not Restricted then
11855 Make_Attribute_Reference (Loc,
11856 Prefix => Make_Identifier (Loc, Name_uInit),
11857 Attribute_Name => Name_Address));
11860 -- Entry_Bodies parameter. This is a pointer to an array of
11861 -- pointers to the entry body procedures and barrier functions of
11862 -- the object. If the protected type has no entries this object
11863 -- will not exist, in this case, pass a null.
11866 P_Arr := Entry_Bodies_Array (Ptyp);
11869 Make_Attribute_Reference (Loc,
11870 Prefix => New_Reference_To (P_Arr, Loc),
11871 Attribute_Name => Name_Unrestricted_Access));
11873 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
11875 -- Find index mapping function (clumsy but ok for now)
11877 while Ekind (P_Arr) /= E_Function loop
11878 Next_Entity (P_Arr);
11882 Make_Attribute_Reference (Loc,
11884 New_Reference_To (P_Arr, Loc),
11885 Attribute_Name => Name_Unrestricted_Access));
11887 -- Build_Entry_Names generation flag. When set to true, the
11888 -- runtime will allocate an array to hold the string names
11889 -- of protected entries.
11891 if not Restricted_Profile then
11892 if Entry_Names_OK then
11894 New_Reference_To (Standard_True, Loc));
11897 New_Reference_To (Standard_False, Loc));
11902 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
11903 Append_To (Args, Make_Null (Loc));
11905 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
11906 Append_To (Args, Make_Null (Loc));
11907 Append_To (Args, Make_Null (Loc));
11908 Append_To (Args, New_Reference_To (Standard_False, Loc));
11912 Make_Procedure_Call_Statement (Loc,
11913 Name => New_Reference_To (RTE (Called_Subp), Loc),
11914 Parameter_Associations => Args));
11918 Make_Procedure_Call_Statement (Loc,
11919 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
11920 Parameter_Associations => Args));
11923 if Has_Attach_Handler (Ptyp) then
11925 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
11926 -- make the following call:
11928 -- Install_Handlers (_object,
11929 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11931 -- or, in the case of Ravenscar:
11933 -- Install_Restricted_Handlers
11934 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11937 Args : constant List_Id := New_List;
11938 Table : constant List_Id := New_List;
11939 Ritem : Node_Id := First_Rep_Item (Ptyp);
11942 -- Build the Attach_Handler table argument
11944 while Present (Ritem) loop
11945 if Nkind (Ritem) = N_Pragma
11946 and then Pragma_Name (Ritem) = Name_Attach_Handler
11949 Handler : constant Node_Id :=
11950 First (Pragma_Argument_Associations (Ritem));
11952 Interrupt : constant Node_Id := Next (Handler);
11953 Expr : constant Node_Id := Expression (Interrupt);
11957 Make_Aggregate (Loc, Expressions => New_List (
11958 Unchecked_Convert_To
11959 (RTE (RE_System_Interrupt_Id), Expr),
11960 Make_Attribute_Reference (Loc,
11961 Prefix => Make_Selected_Component (Loc,
11962 Make_Identifier (Loc, Name_uInit),
11963 Duplicate_Subexpr_No_Checks
11964 (Expression (Handler))),
11965 Attribute_Name => Name_Access))));
11969 Next_Rep_Item (Ritem);
11972 -- Append the table argument we just built
11974 Append_To (Args, Make_Aggregate (Loc, Table));
11976 -- Append the Install_Handlers (or Install_Restricted_Handlers)
11977 -- call to the statements.
11980 -- Call a simplified version of Install_Handlers to be used
11981 -- when the Ravenscar restrictions are in effect
11982 -- (Install_Restricted_Handlers).
11985 Make_Procedure_Call_Statement (Loc,
11988 (RTE (RE_Install_Restricted_Handlers), Loc),
11989 Parameter_Associations => Args));
11992 -- First, prepends the _object argument
11995 Make_Attribute_Reference (Loc,
11997 Make_Selected_Component (Loc,
11998 Prefix => Make_Identifier (Loc, Name_uInit),
11999 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12000 Attribute_Name => Name_Unchecked_Access));
12002 -- Then, insert call to Install_Handlers
12005 Make_Procedure_Call_Statement (Loc,
12006 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
12007 Parameter_Associations => Args));
12013 end Make_Initialize_Protection;
12015 ---------------------------
12016 -- Make_Task_Create_Call --
12017 ---------------------------
12019 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
12020 Loc : constant Source_Ptr := Sloc (Task_Rec);
12030 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
12031 Tnam := Chars (Ttyp);
12033 -- Get task declaration. In the case of a task type declaration, this is
12034 -- simply the parent of the task type entity. In the single task
12035 -- declaration, this parent will be the implicit type, and we can find
12036 -- the corresponding single task declaration by searching forward in the
12037 -- declaration list in the tree.
12039 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12040 -- this type should have been removed during semantic analysis.
12042 Tdec := Parent (Ttyp);
12043 while not Nkind_In (Tdec, N_Task_Type_Declaration,
12044 N_Single_Task_Declaration)
12049 -- Now we can find the task definition from this declaration
12051 Tdef := Task_Definition (Tdec);
12053 -- Build the parameter list for the call. Note that _Init is the name
12054 -- of the formal for the object to be initialized, which is the task
12055 -- value record itself.
12059 -- Priority parameter. Set to Unspecified_Priority unless there is a
12060 -- priority pragma, in which case we take the value from the pragma.
12062 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
12064 Make_Selected_Component (Loc,
12065 Prefix => Make_Identifier (Loc, Name_uInit),
12066 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12069 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12072 -- Optional Stack parameter
12074 if Restricted_Profile then
12076 -- If the stack has been preallocated by the expander then
12077 -- pass its address. Otherwise, pass a null address.
12079 if Preallocated_Stacks_On_Target then
12081 Make_Attribute_Reference (Loc,
12082 Prefix => Make_Selected_Component (Loc,
12083 Prefix => Make_Identifier (Loc, Name_uInit),
12085 Make_Identifier (Loc, Name_uStack)),
12086 Attribute_Name => Name_Address));
12090 New_Reference_To (RTE (RE_Null_Address), Loc));
12094 -- Size parameter. If no Storage_Size pragma is present, then
12095 -- the size is taken from the taskZ variable for the type, which
12096 -- is either Unspecified_Size, or has been reset by the use of
12097 -- a Storage_Size attribute definition clause. If a pragma is
12098 -- present, then the size is taken from the _Size field of the
12099 -- task value record, which was set from the pragma value.
12102 and then Has_Storage_Size_Pragma (Tdef)
12105 Make_Selected_Component (Loc,
12106 Prefix => Make_Identifier (Loc, Name_uInit),
12107 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12111 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12114 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12115 -- Task_Info pragma, in which case we take the value from the pragma.
12118 and then Has_Task_Info_Pragma (Tdef)
12121 Make_Selected_Component (Loc,
12122 Prefix => Make_Identifier (Loc, Name_uInit),
12123 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12127 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12130 if not Restricted_Profile then
12132 -- Deadline parameter. If no Relative_Deadline pragma is present,
12133 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12134 -- the deadline is taken from the _Relative_Deadline field of the
12135 -- task value record, which was set from the pragma value. Note that
12136 -- this parameter must not be generated for the restricted profiles
12137 -- since Ravenscar does not allow deadlines.
12139 -- Case where pragma Relative_Deadline applies: use given value
12141 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12143 Make_Selected_Component (Loc,
12144 Prefix => Make_Identifier (Loc, Name_uInit),
12146 Make_Identifier (Loc, Name_uRelative_Deadline)));
12148 -- No pragma Relative_Deadline apply to the task
12152 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12155 -- Number of entries. This is an expression of the form:
12157 -- n + _Init.a'Length + _Init.a'B'Length + ...
12159 -- where a,b... are the entry family names for the task definition
12162 Build_Entry_Count_Expression
12167 (Parent (Corresponding_Record_Type (Ttyp))))),
12169 Append_To (Args, Ecount);
12171 -- Master parameter. This is a reference to the _Master parameter of
12172 -- the initialization procedure, except in the case of the pragma
12173 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
12174 -- See comments in System.Tasking.Initialization.Init_RTS for the
12177 if Restriction_Active (No_Task_Hierarchy) = False then
12178 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12180 Append_To (Args, Make_Integer_Literal (Loc, 3));
12184 -- State parameter. This is a pointer to the task body procedure. The
12185 -- required value is obtained by taking 'Unrestricted_Access of the task
12186 -- body procedure and converting it (with an unchecked conversion) to
12187 -- the type required by the task kernel. For further details, see the
12188 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12189 -- than 'Address in order to avoid creating trampolines.
12192 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12193 Subp_Ptr_Typ : constant Node_Id :=
12194 Create_Itype (E_Access_Subprogram_Type, Tdec);
12195 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12198 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12199 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12201 -- Be sure to freeze a reference to the access-to-subprogram type,
12202 -- otherwise gigi will complain that it's in the wrong scope, because
12203 -- it's actually inside the init procedure for the record type that
12204 -- corresponds to the task type.
12206 -- This processing is causing a crash in the .NET/JVM back ends that
12207 -- is not yet understood, so skip it in these cases ???
12209 if VM_Target = No_VM then
12210 Set_Itype (Ref, Subp_Ptr_Typ);
12211 Append_Freeze_Action (Task_Rec, Ref);
12214 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12215 Make_Qualified_Expression (Loc,
12216 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12218 Make_Attribute_Reference (Loc,
12220 New_Occurrence_Of (Body_Proc, Loc),
12221 Attribute_Name => Name_Unrestricted_Access))));
12223 -- For the .NET/JVM cases revert to the original code below ???
12227 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12228 Make_Attribute_Reference (Loc,
12230 New_Occurrence_Of (Body_Proc, Loc),
12231 Attribute_Name => Name_Address)));
12235 -- Discriminants parameter. This is just the address of the task
12236 -- value record itself (which contains the discriminant values
12239 Make_Attribute_Reference (Loc,
12240 Prefix => Make_Identifier (Loc, Name_uInit),
12241 Attribute_Name => Name_Address));
12243 -- Elaborated parameter. This is an access to the elaboration Boolean
12246 Make_Attribute_Reference (Loc,
12247 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12248 Attribute_Name => Name_Unchecked_Access));
12250 -- Chain parameter. This is a reference to the _Chain parameter of
12251 -- the initialization procedure.
12253 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12255 -- Task name parameter. Take this from the _Task_Id parameter to the
12256 -- init call unless there is a Task_Name pragma, in which case we take
12257 -- the value from the pragma.
12260 and then Has_Task_Name_Pragma (Tdef)
12262 -- Copy expression in full, because it may be dynamic and have
12268 (Pragma_Argument_Associations
12269 (Find_Task_Or_Protected_Pragma
12270 (Tdef, Name_Task_Name))))));
12273 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12276 -- Created_Task parameter. This is the _Task_Id field of the task
12280 Make_Selected_Component (Loc,
12281 Prefix => Make_Identifier (Loc, Name_uInit),
12282 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12284 -- Build_Entry_Names generation flag. When set to true, the runtime
12285 -- will allocate an array to hold the string names of task entries.
12287 if not Restricted_Profile then
12288 if Has_Entries (Ttyp)
12289 and then Entry_Names_OK
12291 Append_To (Args, New_Reference_To (Standard_True, Loc));
12293 Append_To (Args, New_Reference_To (Standard_False, Loc));
12297 if Restricted_Profile then
12298 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12300 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12304 Make_Procedure_Call_Statement (Loc,
12306 Parameter_Associations => Args);
12307 end Make_Task_Create_Call;
12309 ------------------------------
12310 -- Next_Protected_Operation --
12311 ------------------------------
12313 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12317 Next_Op := Next (N);
12318 while Present (Next_Op)
12319 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12325 end Next_Protected_Operation;
12327 ---------------------
12328 -- Null_Statements --
12329 ---------------------
12331 function Null_Statements (Stats : List_Id) return Boolean is
12335 Stmt := First (Stats);
12336 while Nkind (Stmt) /= N_Empty
12337 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12339 (Nkind (Stmt) = N_Pragma
12340 and then (Pragma_Name (Stmt) = Name_Unreferenced
12342 Pragma_Name (Stmt) = Name_Unmodified
12344 Pragma_Name (Stmt) = Name_Warnings)))
12349 return Nkind (Stmt) = N_Empty;
12350 end Null_Statements;
12352 --------------------------
12353 -- Parameter_Block_Pack --
12354 --------------------------
12356 function Parameter_Block_Pack
12358 Blk_Typ : Entity_Id;
12362 Stmts : List_Id) return Node_Id
12364 Actual : Entity_Id;
12365 Expr : Node_Id := Empty;
12366 Formal : Entity_Id;
12367 Has_Param : Boolean := False;
12370 Temp_Asn : Node_Id;
12371 Temp_Nam : Node_Id;
12374 Actual := First (Actuals);
12375 Formal := Defining_Identifier (First (Formals));
12376 Params := New_List;
12378 while Present (Actual) loop
12379 if Is_By_Copy_Type (Etype (Actual)) then
12381 -- Jnn : aliased <formal-type>
12384 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
12387 Make_Object_Declaration (Loc,
12390 Defining_Identifier =>
12392 Object_Definition =>
12393 New_Reference_To (Etype (Formal), Loc)));
12395 if Ekind (Formal) /= E_Out_Parameter then
12401 New_Reference_To (Temp_Nam, Loc);
12403 Set_Assignment_OK (Temp_Asn);
12406 Make_Assignment_Statement (Loc,
12410 New_Copy_Tree (Actual)));
12414 -- Jnn'unchecked_access
12417 Make_Attribute_Reference (Loc,
12419 Name_Unchecked_Access,
12421 New_Reference_To (Temp_Nam, Loc)));
12425 -- The controlling parameter is omitted
12428 if not Is_Controlling_Actual (Actual) then
12430 Make_Reference (Loc, New_Copy_Tree (Actual)));
12436 Next_Actual (Actual);
12437 Next_Formal_With_Extras (Formal);
12441 Expr := Make_Aggregate (Loc, Params);
12446 -- J1'unchecked_access;
12447 -- <actual2>'reference;
12450 P := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
12453 Make_Object_Declaration (Loc,
12454 Defining_Identifier =>
12456 Object_Definition =>
12457 New_Reference_To (Blk_Typ, Loc),
12462 end Parameter_Block_Pack;
12464 ----------------------------
12465 -- Parameter_Block_Unpack --
12466 ----------------------------
12468 function Parameter_Block_Unpack
12472 Formals : List_Id) return List_Id
12474 Actual : Entity_Id;
12476 Formal : Entity_Id;
12477 Has_Asnmt : Boolean := False;
12478 Result : constant List_Id := New_List;
12481 Actual := First (Actuals);
12482 Formal := Defining_Identifier (First (Formals));
12483 while Present (Actual) loop
12484 if Is_By_Copy_Type (Etype (Actual))
12485 and then Ekind (Formal) /= E_In_Parameter
12488 -- <actual> := P.<formal>;
12491 Make_Assignment_Statement (Loc,
12495 Make_Explicit_Dereference (Loc,
12496 Make_Selected_Component (Loc,
12498 New_Reference_To (P, Loc),
12500 Make_Identifier (Loc, Chars (Formal)))));
12502 Set_Assignment_OK (Name (Asnmt));
12503 Append_To (Result, Asnmt);
12508 Next_Actual (Actual);
12509 Next_Formal_With_Extras (Formal);
12515 return New_List (Make_Null_Statement (Loc));
12517 end Parameter_Block_Unpack;
12519 ----------------------
12520 -- Set_Discriminals --
12521 ----------------------
12523 procedure Set_Discriminals (Dec : Node_Id) is
12526 D_Minal : Entity_Id;
12529 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
12530 Pdef := Defining_Identifier (Dec);
12532 if Has_Discriminants (Pdef) then
12533 D := First_Discriminant (Pdef);
12534 while Present (D) loop
12536 Make_Defining_Identifier (Sloc (D),
12537 Chars => New_External_Name (Chars (D), 'D'));
12539 Set_Ekind (D_Minal, E_Constant);
12540 Set_Etype (D_Minal, Etype (D));
12541 Set_Scope (D_Minal, Pdef);
12542 Set_Discriminal (D, D_Minal);
12543 Set_Discriminal_Link (D_Minal, D);
12545 Next_Discriminant (D);
12548 end Set_Discriminals;
12550 -----------------------
12551 -- Trivial_Accept_OK --
12552 -----------------------
12554 function Trivial_Accept_OK return Boolean is
12556 case Opt.Task_Dispatching_Policy is
12558 -- If we have the default task dispatching policy in effect, we can
12559 -- definitely do the optimization (one way of looking at this is to
12560 -- think of the formal definition of the default policy being allowed
12561 -- to run any task it likes after a rendezvous, so even if notionally
12562 -- a full rescheduling occurs, we can say that our dispatching policy
12563 -- (i.e. the default dispatching policy) reorders the queue to be the
12564 -- same as just before the call.
12569 -- FIFO_Within_Priorities certainly does not permit this
12570 -- optimization since the Rendezvous is a scheduling action that may
12571 -- require some other task to be run.
12576 -- For now, disallow the optimization for all other policies. This
12577 -- may be over-conservative, but it is certainly not incorrect.
12583 end Trivial_Accept_OK;