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 := Make_Temporary (Loc, 'L');
1172 L_Stmts : constant List_Id := New_List;
1175 function Build_Range (Def : Node_Id) return Node_Id;
1176 -- Given a discrete subtype definition of an entry family, generate a
1177 -- range node which covers the range of Def's type.
1183 function Build_Range (Def : Node_Id) return Node_Id is
1184 High : Node_Id := Type_High_Bound (Etype (Def));
1185 Low : Node_Id := Type_Low_Bound (Etype (Def));
1188 -- If a bound references a discriminant, generate an identifier
1189 -- with the same name. Resolution will map it to the formals of
1192 if Is_Entity_Name (Low)
1193 and then Ekind (Entity (Low)) = E_Discriminant
1195 Low := Make_Identifier (Loc, Chars (Low));
1197 Low := New_Copy_Tree (Low);
1200 if Is_Entity_Name (High)
1201 and then Ekind (Entity (High)) = E_Discriminant
1203 High := Make_Identifier (Loc, Chars (High));
1205 High := New_Copy_Tree (High);
1211 High_Bound => High);
1214 -- Start of processing for Build_Entry_Family_Name
1217 Get_Name_String (Chars (Id));
1219 -- Add a leading '('
1221 Add_Char_To_Name_Buffer ('(');
1224 -- new String'("<Entry name>(" & Lnn'Img & ")");
1226 -- This is an implicit heap allocation, and Comes_From_Source is
1227 -- False, which ensures that it will get flagged as a violation of
1228 -- No_Implicit_Heap_Allocations when that restriction applies.
1231 Make_Allocator (Loc,
1232 Make_Qualified_Expression (Loc,
1234 New_Reference_To (Standard_String, Loc),
1236 Make_Op_Concat (Loc,
1238 Make_Op_Concat (Loc,
1240 Make_String_Literal (Loc,
1241 Strval => String_From_Name_Buffer),
1243 Make_Attribute_Reference (Loc,
1245 New_Reference_To (L_Id, Loc),
1246 Attribute_Name => Name_Img)),
1248 Make_String_Literal (Loc,
1251 Increment_Index (L_Stmts);
1252 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1255 -- for Lnn in Family_Low .. Family_High loop
1258 -- (_init._object <or> _init._task_id, Inn, <Val>);
1262 Make_Loop_Statement (Loc,
1264 Make_Iteration_Scheme (Loc,
1265 Loop_Parameter_Specification =>
1266 Make_Loop_Parameter_Specification (Loc,
1267 Defining_Identifier => L_Id,
1268 Discrete_Subtype_Definition => Build_Range (Def))),
1269 Statements => L_Stmts,
1270 End_Label => Empty));
1271 end Build_Entry_Family_Name;
1273 ----------------------
1274 -- Build_Entry_Name --
1275 ----------------------
1277 procedure Build_Entry_Name (Id : Entity_Id) is
1281 Get_Name_String (Chars (Id));
1283 -- This is an implicit heap allocation, and Comes_From_Source is
1284 -- False, which ensures that it will get flagged as a violation of
1285 -- No_Implicit_Heap_Allocations when that restriction applies.
1288 Make_Allocator (Loc,
1289 Make_Qualified_Expression (Loc,
1291 New_Reference_To (Standard_String, Loc),
1293 Make_String_Literal (Loc,
1294 String_From_Name_Buffer)));
1296 Increment_Index (B_Stmts);
1297 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1298 end Build_Entry_Name;
1300 -------------------------------
1301 -- Build_Set_Entry_Name_Call --
1302 -------------------------------
1304 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1309 -- Determine the proper name for the first argument and the RTS
1312 if Is_Protected_Type (Typ) then
1313 Arg1 := Name_uObject;
1314 Proc := RO_PE_Set_Entry_Name;
1316 else pragma Assert (Is_Task_Type (Typ));
1317 Arg1 := Name_uTask_Id;
1318 Proc := RO_TS_Set_Entry_Name;
1322 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1325 Make_Procedure_Call_Statement (Loc,
1327 New_Reference_To (RTE (Proc), Loc),
1328 Parameter_Associations => New_List (
1329 Make_Selected_Component (Loc, -- _init._object
1330 Prefix => -- _init._task_id
1331 Make_Identifier (Loc, Name_uInit),
1333 Make_Identifier (Loc, Arg1)),
1334 New_Reference_To (Index, Loc), -- Inn
1336 end Build_Set_Entry_Name_Call;
1338 --------------------------
1339 -- Find_Protection_Type --
1340 --------------------------
1342 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
1344 Typ : Entity_Id := Conc_Typ;
1347 if Is_Concurrent_Type (Typ) then
1348 Typ := Corresponding_Record_Type (Typ);
1351 Comp := First_Component (Typ);
1352 while Present (Comp) loop
1353 if Chars (Comp) = Name_uObject then
1354 return Base_Type (Etype (Comp));
1357 Next_Component (Comp);
1360 -- The corresponding record of a protected type should always have an
1363 raise Program_Error;
1364 end Find_Protection_Type;
1366 ---------------------
1367 -- Increment_Index --
1368 ---------------------
1370 procedure Increment_Index (Stmts : List_Id) is
1376 Make_Assignment_Statement (Loc,
1378 New_Reference_To (Index, Loc),
1382 New_Reference_To (Index, Loc),
1384 Make_Integer_Literal (Loc, 1))));
1385 end Increment_Index;
1387 -- Start of processing for Build_Entry_Names
1390 -- Retrieve the original concurrent type
1392 if Is_Concurrent_Record_Type (Typ) then
1393 Typ := Corresponding_Concurrent_Type (Typ);
1396 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1398 -- Nothing to do if the type has no entries
1400 if not Has_Entries (Typ) then
1404 -- Avoid generating entry names for a protected type with only one entry
1406 if Is_Protected_Type (Typ)
1407 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1412 Index := Make_Temporary (Loc, 'I');
1414 -- Step 1: Generate the declaration of the index variable:
1415 -- Inn : Protected_Entry_Index := 0;
1417 -- Inn : Task_Entry_Index := 0;
1419 if Is_Protected_Type (Typ) then
1420 Index_Typ := RE_Protected_Entry_Index;
1422 Index_Typ := RE_Task_Entry_Index;
1425 B_Decls := New_List;
1427 Make_Object_Declaration (Loc,
1428 Defining_Identifier => Index,
1429 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1430 Expression => Make_Integer_Literal (Loc, 0)));
1432 B_Stmts := New_List;
1434 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1437 Comp := First_Entity (Typ);
1438 while Present (Comp) loop
1439 if Ekind (Comp) = E_Entry then
1440 Build_Entry_Name (Comp);
1442 elsif Ekind (Comp) = E_Entry_Family then
1443 Build_Entry_Family_Name (Comp);
1449 -- Step 3: Wrap the statements in a block
1452 Make_Block_Statement (Loc,
1453 Declarations => B_Decls,
1454 Handled_Statement_Sequence =>
1455 Make_Handled_Sequence_Of_Statements (Loc,
1456 Statements => B_Stmts));
1457 end Build_Entry_Names;
1459 ---------------------------
1460 -- Build_Parameter_Block --
1461 ---------------------------
1463 function Build_Parameter_Block
1467 Decls : List_Id) return Entity_Id
1473 Has_Comp : Boolean := False;
1477 Actual := First (Actuals);
1479 Formal := Defining_Identifier (First (Formals));
1481 while Present (Actual) loop
1482 if not Is_Controlling_Actual (Actual) then
1485 -- type Ann is access all <actual-type>
1487 Comp_Nam := Make_Temporary (Loc, 'A');
1490 Make_Full_Type_Declaration (Loc,
1491 Defining_Identifier => Comp_Nam,
1493 Make_Access_To_Object_Definition (Loc,
1494 All_Present => True,
1495 Constant_Present => Ekind (Formal) = E_In_Parameter,
1496 Subtype_Indication =>
1497 New_Reference_To (Etype (Actual), Loc))));
1503 Make_Component_Declaration (Loc,
1504 Defining_Identifier =>
1505 Make_Defining_Identifier (Loc, Chars (Formal)),
1506 Component_Definition =>
1507 Make_Component_Definition (Loc,
1510 Subtype_Indication =>
1511 New_Reference_To (Comp_Nam, Loc))));
1516 Next_Actual (Actual);
1517 Next_Formal_With_Extras (Formal);
1520 Rec_Nam := Make_Temporary (Loc, 'P');
1525 -- type Pnn is record
1530 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1531 -- the original parameter names and Ann1 .. AnnN are the access to
1535 Make_Full_Type_Declaration (Loc,
1536 Defining_Identifier =>
1539 Make_Record_Definition (Loc,
1541 Make_Component_List (Loc, Comps))));
1544 -- type Pnn is null record;
1547 Make_Full_Type_Declaration (Loc,
1548 Defining_Identifier =>
1551 Make_Record_Definition (Loc,
1552 Null_Present => True,
1553 Component_List => Empty)));
1557 end Build_Parameter_Block;
1559 --------------------------
1560 -- Build_Wrapper_Bodies --
1561 --------------------------
1563 procedure Build_Wrapper_Bodies
1568 Rec_Typ : Entity_Id;
1570 function Build_Wrapper_Body
1572 Subp_Id : Entity_Id;
1573 Obj_Typ : Entity_Id;
1574 Formals : List_Id) return Node_Id;
1575 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1576 -- associated with a protected or task type. Subp_Id is the subprogram
1577 -- name which will be wrapped. Obj_Typ is the type of the new formal
1578 -- parameter which handles dispatching and object notation. Formals are
1579 -- the original formals of Subp_Id which will be explicitly replicated.
1581 ------------------------
1582 -- Build_Wrapper_Body --
1583 ------------------------
1585 function Build_Wrapper_Body
1587 Subp_Id : Entity_Id;
1588 Obj_Typ : Entity_Id;
1589 Formals : List_Id) return Node_Id
1591 Body_Spec : Node_Id;
1594 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1596 -- The subprogram is not overriding or is not a primitive declared
1597 -- between two views.
1599 if No (Body_Spec) then
1604 Actuals : List_Id := No_List;
1606 First_Form : Node_Id;
1611 -- Map formals to actuals. Use the list built for the wrapper
1612 -- spec, skipping the object notation parameter.
1614 First_Form := First (Parameter_Specifications (Body_Spec));
1616 Formal := First_Form;
1619 if Present (Formal) then
1620 Actuals := New_List;
1622 while Present (Formal) loop
1624 Make_Identifier (Loc, Chars =>
1625 Chars (Defining_Identifier (Formal))));
1631 -- Special processing for primitives declared between a private
1632 -- type and its completion: the wrapper needs a properly typed
1633 -- parameter if the wrapped operation has a controlling first
1634 -- parameter. Note that this might not be the case for a function
1635 -- with a controlling result.
1637 if Is_Private_Primitive_Subprogram (Subp_Id) then
1638 if No (Actuals) then
1639 Actuals := New_List;
1642 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1643 Prepend_To (Actuals,
1644 Unchecked_Convert_To (
1645 Corresponding_Concurrent_Type (Obj_Typ),
1646 Make_Identifier (Loc, Name_uO)));
1649 Prepend_To (Actuals,
1650 Make_Identifier (Loc, Chars =>
1651 Chars (Defining_Identifier (First_Form))));
1654 Nam := New_Reference_To (Subp_Id, Loc);
1656 -- An access-to-variable object parameter requires an explicit
1657 -- dereference in the unchecked conversion. This case occurs
1658 -- when a protected entry wrapper must override an interface
1659 -- level procedure with interface access as first parameter.
1661 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1663 if Nkind (Parameter_Type (First_Form)) =
1667 Make_Explicit_Dereference (Loc,
1668 Prefix => Make_Identifier (Loc, Name_uO));
1670 Conv_Id := Make_Identifier (Loc, Name_uO);
1674 Make_Selected_Component (Loc,
1676 Unchecked_Convert_To (
1677 Corresponding_Concurrent_Type (Obj_Typ),
1680 New_Reference_To (Subp_Id, Loc));
1683 -- Create the subprogram body. For a function, the call to the
1684 -- actual subprogram has to be converted to the corresponding
1685 -- record if it is a controlling result.
1687 if Ekind (Subp_Id) = E_Function then
1693 Make_Function_Call (Loc,
1695 Parameter_Associations => Actuals);
1697 if Has_Controlling_Result (Subp_Id) then
1699 Unchecked_Convert_To
1700 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1704 Make_Subprogram_Body (Loc,
1705 Specification => Body_Spec,
1706 Declarations => Empty_List,
1707 Handled_Statement_Sequence =>
1708 Make_Handled_Sequence_Of_Statements (Loc,
1709 Statements => New_List (
1710 Make_Simple_Return_Statement (Loc, Res))));
1715 Make_Subprogram_Body (Loc,
1716 Specification => Body_Spec,
1717 Declarations => Empty_List,
1718 Handled_Statement_Sequence =>
1719 Make_Handled_Sequence_Of_Statements (Loc,
1720 Statements => New_List (
1721 Make_Procedure_Call_Statement (Loc,
1723 Parameter_Associations => Actuals))));
1726 end Build_Wrapper_Body;
1728 -- Start of processing for Build_Wrapper_Bodies
1731 if Is_Concurrent_Type (Typ) then
1732 Rec_Typ := Corresponding_Record_Type (Typ);
1737 -- Generate wrapper bodies for a concurrent type which implements an
1740 if Present (Interfaces (Rec_Typ)) then
1742 Insert_Nod : Node_Id;
1744 Prim_Elmt : Elmt_Id;
1745 Prim_Decl : Node_Id;
1747 Wrap_Body : Node_Id;
1748 Wrap_Id : Entity_Id;
1753 -- Examine all primitive operations of the corresponding record
1754 -- type, looking for wrapper specs. Generate bodies in order to
1757 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1758 while Present (Prim_Elmt) loop
1759 Prim := Node (Prim_Elmt);
1761 if (Ekind (Prim) = E_Function
1762 or else Ekind (Prim) = E_Procedure)
1763 and then Is_Primitive_Wrapper (Prim)
1765 Subp := Wrapped_Entity (Prim);
1766 Prim_Decl := Parent (Parent (Prim));
1769 Build_Wrapper_Body (Loc,
1772 Formals => Parameter_Specifications (Parent (Subp)));
1773 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
1775 Set_Corresponding_Spec (Wrap_Body, Prim);
1776 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
1778 Insert_After (Insert_Nod, Wrap_Body);
1779 Insert_Nod := Wrap_Body;
1781 Analyze (Wrap_Body);
1784 Next_Elmt (Prim_Elmt);
1788 end Build_Wrapper_Bodies;
1790 ------------------------
1791 -- Build_Wrapper_Spec --
1792 ------------------------
1794 function Build_Wrapper_Spec
1795 (Subp_Id : Entity_Id;
1796 Obj_Typ : Entity_Id;
1797 Formals : List_Id) return Node_Id
1799 Loc : constant Source_Ptr := Sloc (Subp_Id);
1800 First_Param : Node_Id;
1802 Iface_Elmt : Elmt_Id;
1803 Iface_Op : Entity_Id;
1804 Iface_Op_Elmt : Elmt_Id;
1806 function Overriding_Possible
1807 (Iface_Op : Entity_Id;
1808 Wrapper : Entity_Id) return Boolean;
1809 -- Determine whether a primitive operation can be overridden by Wrapper.
1810 -- Iface_Op is the candidate primitive operation of an interface type,
1811 -- Wrapper is the generated entry wrapper.
1813 function Replicate_Formals
1815 Formals : List_Id) return List_Id;
1816 -- An explicit parameter replication is required due to the Is_Entry_
1817 -- Formal flag being set for all the formals of an entry. The explicit
1818 -- replication removes the flag that would otherwise cause a different
1819 -- path of analysis.
1821 -------------------------
1822 -- Overriding_Possible --
1823 -------------------------
1825 function Overriding_Possible
1826 (Iface_Op : Entity_Id;
1827 Wrapper : Entity_Id) return Boolean
1829 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
1830 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
1832 function Type_Conformant_Parameters
1833 (Iface_Op_Params : List_Id;
1834 Wrapper_Params : List_Id) return Boolean;
1835 -- Determine whether the parameters of the generated entry wrapper
1836 -- and those of a primitive operation are type conformant. During
1837 -- this check, the first parameter of the primitive operation is
1838 -- skipped if it is a controlling argument: protected functions
1839 -- may have a controlling result.
1841 --------------------------------
1842 -- Type_Conformant_Parameters --
1843 --------------------------------
1845 function Type_Conformant_Parameters
1846 (Iface_Op_Params : List_Id;
1847 Wrapper_Params : List_Id) return Boolean
1849 Iface_Op_Param : Node_Id;
1850 Iface_Op_Typ : Entity_Id;
1851 Wrapper_Param : Node_Id;
1852 Wrapper_Typ : Entity_Id;
1855 -- Skip the first (controlling) parameter of primitive operation
1857 Iface_Op_Param := First (Iface_Op_Params);
1859 if Present (First_Formal (Iface_Op))
1860 and then Is_Controlling_Formal (First_Formal (Iface_Op))
1862 Iface_Op_Param := Next (Iface_Op_Param);
1865 Wrapper_Param := First (Wrapper_Params);
1866 while Present (Iface_Op_Param)
1867 and then Present (Wrapper_Param)
1869 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
1870 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
1872 -- The two parameters must be mode conformant
1874 if not Conforming_Types
1875 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
1880 Next (Iface_Op_Param);
1881 Next (Wrapper_Param);
1884 -- One of the lists is longer than the other
1886 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
1891 end Type_Conformant_Parameters;
1893 -- Start of processing for Overriding_Possible
1896 if Chars (Iface_Op) /= Chars (Wrapper) then
1900 -- If an inherited subprogram is implemented by a protected procedure
1901 -- or an entry, then the first parameter of the inherited subprogram
1902 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
1904 if Ekind (Iface_Op) = E_Procedure
1905 and then Present (Parameter_Specifications (Iface_Op_Spec))
1908 Obj_Param : constant Node_Id :=
1909 First (Parameter_Specifications (Iface_Op_Spec));
1911 if not Out_Present (Obj_Param)
1912 and then Nkind (Parameter_Type (Obj_Param)) /=
1921 Type_Conformant_Parameters (
1922 Parameter_Specifications (Iface_Op_Spec),
1923 Parameter_Specifications (Wrapper_Spec));
1924 end Overriding_Possible;
1926 -----------------------
1927 -- Replicate_Formals --
1928 -----------------------
1930 function Replicate_Formals
1932 Formals : List_Id) return List_Id
1934 New_Formals : constant List_Id := New_List;
1936 Param_Type : Node_Id;
1939 Formal := First (Formals);
1941 -- Skip the object parameter when dealing with primitives declared
1942 -- between two views.
1944 if Is_Private_Primitive_Subprogram (Subp_Id)
1945 and then not Has_Controlling_Result (Subp_Id)
1947 Formal := Next (Formal);
1950 while Present (Formal) loop
1952 -- Create an explicit copy of the entry parameter
1954 -- When creating the wrapper subprogram for a primitive operation
1955 -- of a protected interface we must construct an equivalent
1956 -- signature to that of the overriding operation. For regular
1957 -- parameters we can just use the type of the formal, but for
1958 -- access to subprogram parameters we need to reanalyze the
1959 -- parameter type to create local entities for the signature of
1960 -- the subprogram type. Using the entities of the overriding
1961 -- subprogram will result in out-of-scope errors in the back-end.
1963 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
1964 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
1967 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
1970 Append_To (New_Formals,
1971 Make_Parameter_Specification (Loc,
1972 Defining_Identifier =>
1973 Make_Defining_Identifier (Loc,
1974 Chars => Chars (Defining_Identifier (Formal))),
1975 In_Present => In_Present (Formal),
1976 Out_Present => Out_Present (Formal),
1977 Parameter_Type => Param_Type));
1983 end Replicate_Formals;
1985 -- Start of processing for Build_Wrapper_Spec
1988 -- There is no point in building wrappers for non-tagged concurrent
1991 pragma Assert (Is_Tagged_Type (Obj_Typ));
1993 -- An entry or a protected procedure can override a routine where the
1994 -- controlling formal is either IN OUT, OUT or is of access-to-variable
1995 -- type. Since the wrapper must have the exact same signature as that of
1996 -- the overridden subprogram, we try to find the overriding candidate
1997 -- and use its controlling formal.
1999 First_Param := Empty;
2001 -- Check every implemented interface
2003 if Present (Interfaces (Obj_Typ)) then
2004 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2005 Search : while Present (Iface_Elmt) loop
2006 Iface := Node (Iface_Elmt);
2008 -- Check every interface primitive
2010 if Present (Primitive_Operations (Iface)) then
2011 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2012 while Present (Iface_Op_Elmt) loop
2013 Iface_Op := Node (Iface_Op_Elmt);
2015 -- Ignore predefined primitives
2017 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2018 Iface_Op := Ultimate_Alias (Iface_Op);
2020 -- The current primitive operation can be overridden by
2021 -- the generated entry wrapper.
2023 if Overriding_Possible (Iface_Op, Subp_Id) then
2025 First (Parameter_Specifications (Parent (Iface_Op)));
2031 Next_Elmt (Iface_Op_Elmt);
2035 Next_Elmt (Iface_Elmt);
2039 -- If the subprogram to be wrapped is not overriding anything or is not
2040 -- a primitive declared between two views, do not produce anything. This
2041 -- avoids spurious errors involving overriding.
2044 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2050 Wrapper_Id : constant Entity_Id :=
2051 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2052 New_Formals : List_Id;
2053 Obj_Param : Node_Id;
2054 Obj_Param_Typ : Entity_Id;
2057 -- Minimum decoration is needed to catch the entity in
2058 -- Sem_Ch6.Override_Dispatching_Operation.
2060 if Ekind (Subp_Id) = E_Function then
2061 Set_Ekind (Wrapper_Id, E_Function);
2063 Set_Ekind (Wrapper_Id, E_Procedure);
2066 Set_Is_Primitive_Wrapper (Wrapper_Id);
2067 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2068 Set_Is_Private_Primitive (Wrapper_Id,
2069 Is_Private_Primitive_Subprogram (Subp_Id));
2071 -- Process the formals
2073 New_Formals := Replicate_Formals (Loc, Formals);
2075 -- A function with a controlling result and no first controlling
2076 -- formal needs no additional parameter.
2078 if Has_Controlling_Result (Subp_Id)
2080 (No (First_Formal (Subp_Id))
2081 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2085 -- Routine Subp_Id has been found to override an interface primitive.
2086 -- If the interface operation has an access parameter, create a copy
2087 -- of it, with the same null exclusion indicator if present.
2089 elsif Present (First_Param) then
2090 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2092 Make_Access_Definition (Loc,
2094 New_Reference_To (Obj_Typ, Loc));
2095 Set_Null_Exclusion_Present (Obj_Param_Typ,
2096 Null_Exclusion_Present (Parameter_Type (First_Param)));
2099 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2103 Make_Parameter_Specification (Loc,
2104 Defining_Identifier =>
2105 Make_Defining_Identifier (Loc,
2107 In_Present => In_Present (First_Param),
2108 Out_Present => Out_Present (First_Param),
2109 Parameter_Type => Obj_Param_Typ);
2111 Prepend_To (New_Formals, Obj_Param);
2113 -- If we are dealing with a primitive declared between two views,
2114 -- implemented by a synchronized operation, we need to create
2115 -- a default parameter. The mode of the parameter must match that
2116 -- of the primitive operation.
2119 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2121 Make_Parameter_Specification (Loc,
2122 Defining_Identifier =>
2123 Make_Defining_Identifier (Loc, Name_uO),
2124 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2125 Out_Present => Ekind (Subp_Id) /= E_Function,
2126 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2127 Prepend_To (New_Formals, Obj_Param);
2130 -- Build the final spec. If it is a function with a controlling
2131 -- result, it is a primitive operation of the corresponding
2132 -- record type, so mark the spec accordingly.
2134 if Ekind (Subp_Id) = E_Function then
2140 if Has_Controlling_Result (Subp_Id) then
2143 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2145 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2149 Make_Function_Specification (Loc,
2150 Defining_Unit_Name => Wrapper_Id,
2151 Parameter_Specifications => New_Formals,
2152 Result_Definition => Res_Def);
2156 Make_Procedure_Specification (Loc,
2157 Defining_Unit_Name => Wrapper_Id,
2158 Parameter_Specifications => New_Formals);
2161 end Build_Wrapper_Spec;
2163 -------------------------
2164 -- Build_Wrapper_Specs --
2165 -------------------------
2167 procedure Build_Wrapper_Specs
2173 Rec_Typ : Entity_Id;
2174 procedure Scan_Declarations (L : List_Id);
2175 -- Common processing for visible and private declarations
2176 -- of a protected type.
2178 procedure Scan_Declarations (L : List_Id) is
2180 Wrap_Decl : Node_Id;
2181 Wrap_Spec : Node_Id;
2189 while Present (Decl) loop
2192 if Nkind (Decl) = N_Entry_Declaration
2193 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2197 (Subp_Id => Defining_Identifier (Decl),
2199 Formals => Parameter_Specifications (Decl));
2201 elsif Nkind (Decl) = N_Subprogram_Declaration then
2204 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2207 Parameter_Specifications (Specification (Decl)));
2210 if Present (Wrap_Spec) then
2212 Make_Subprogram_Declaration (Loc,
2213 Specification => Wrap_Spec);
2215 Insert_After (N, Wrap_Decl);
2218 Analyze (Wrap_Decl);
2223 end Scan_Declarations;
2225 -- start of processing for Build_Wrapper_Specs
2228 if Is_Protected_Type (Typ) then
2229 Def := Protected_Definition (Parent (Typ));
2230 else pragma Assert (Is_Task_Type (Typ));
2231 Def := Task_Definition (Parent (Typ));
2234 Rec_Typ := Corresponding_Record_Type (Typ);
2236 -- Generate wrapper specs for a concurrent type which implements an
2237 -- interface. Operations in both the visible and private parts may
2238 -- implement progenitor operations.
2240 if Present (Interfaces (Rec_Typ))
2241 and then Present (Def)
2243 Scan_Declarations (Visible_Declarations (Def));
2244 Scan_Declarations (Private_Declarations (Def));
2246 end Build_Wrapper_Specs;
2248 ---------------------------
2249 -- Build_Find_Body_Index --
2250 ---------------------------
2252 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2253 Loc : constant Source_Ptr := Sloc (Typ);
2256 Has_F : Boolean := False;
2258 If_St : Node_Id := Empty;
2261 Decls : List_Id := New_List;
2264 Siz : Node_Id := Empty;
2266 procedure Add_If_Clause (Expr : Node_Id);
2267 -- Add test for range of current entry
2269 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2270 -- If a bound of an entry is given by a discriminant, retrieve the
2271 -- actual value of the discriminant from the enclosing object.
2277 procedure Add_If_Clause (Expr : Node_Id) is
2279 Stats : constant List_Id :=
2281 Make_Simple_Return_Statement (Loc,
2282 Expression => Make_Integer_Literal (Loc, Index + 1)));
2285 -- Index for current entry body
2289 -- Compute total length of entry queues so far
2297 Right_Opnd => Expr);
2302 Left_Opnd => Make_Identifier (Loc, Name_uE),
2305 -- Map entry queue indices in the range of the current family
2306 -- into the current index, that designates the entry body.
2310 Make_Implicit_If_Statement (Typ,
2312 Then_Statements => Stats,
2313 Elsif_Parts => New_List);
2319 Make_Elsif_Part (Loc,
2321 Then_Statements => Stats),
2322 Elsif_Parts (If_St));
2326 ------------------------------
2327 -- Convert_Discriminant_Ref --
2328 ------------------------------
2330 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2334 if Is_Entity_Name (Bound)
2335 and then Ekind (Entity (Bound)) = E_Discriminant
2338 Make_Selected_Component (Loc,
2340 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2341 Make_Explicit_Dereference (Loc,
2342 Make_Identifier (Loc, Name_uObject))),
2343 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2344 Set_Etype (B, Etype (Entity (Bound)));
2346 B := New_Copy_Tree (Bound);
2350 end Convert_Discriminant_Ref;
2352 -- Start of processing for Build_Find_Body_Index
2355 Spec := Build_Find_Body_Index_Spec (Typ);
2357 Ent := First_Entity (Typ);
2358 while Present (Ent) loop
2359 if Ekind (Ent) = E_Entry_Family then
2369 -- If the protected type has no entry families, there is a one-one
2370 -- correspondence between entry queue and entry body.
2373 Make_Simple_Return_Statement (Loc,
2374 Expression => Make_Identifier (Loc, Name_uE));
2377 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2380 -- if E <= l1 then return 1;
2381 -- elsif E <= l1 + l2 then return 2;
2386 Ent := First_Entity (Typ);
2388 Add_Object_Pointer (Loc, Typ, Decls);
2390 while Present (Ent) loop
2392 if Ekind (Ent) = E_Entry then
2393 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2395 elsif Ekind (Ent) = E_Entry_Family then
2397 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2398 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2399 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2400 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2409 Make_Simple_Return_Statement (Loc,
2410 Expression => Make_Integer_Literal (Loc, 1));
2412 elsif Nkind (Ret) = N_If_Statement then
2414 -- Ranges are in increasing order, so last one doesn't need guard
2417 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2420 Set_Else_Statements (Ret, Then_Statements (Nod));
2426 Make_Subprogram_Body (Loc,
2427 Specification => Spec,
2428 Declarations => Decls,
2429 Handled_Statement_Sequence =>
2430 Make_Handled_Sequence_Of_Statements (Loc,
2431 Statements => New_List (Ret)));
2432 end Build_Find_Body_Index;
2434 --------------------------------
2435 -- Build_Find_Body_Index_Spec --
2436 --------------------------------
2438 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2439 Loc : constant Source_Ptr := Sloc (Typ);
2440 Id : constant Entity_Id :=
2441 Make_Defining_Identifier (Loc,
2442 Chars => New_External_Name (Chars (Typ), 'F'));
2443 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2444 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2448 Make_Function_Specification (Loc,
2449 Defining_Unit_Name => Id,
2450 Parameter_Specifications => New_List (
2451 Make_Parameter_Specification (Loc,
2452 Defining_Identifier => Parm1,
2454 New_Reference_To (RTE (RE_Address), Loc)),
2456 Make_Parameter_Specification (Loc,
2457 Defining_Identifier => Parm2,
2459 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2460 Result_Definition => New_Occurrence_Of (
2461 RTE (RE_Protected_Entry_Index), Loc));
2462 end Build_Find_Body_Index_Spec;
2464 -------------------------
2465 -- Build_Master_Entity --
2466 -------------------------
2468 procedure Build_Master_Entity (E : Entity_Id) is
2469 Loc : constant Source_Ptr := Sloc (E);
2477 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2478 -- in internal scopes, unless present already.. Required for nested
2479 -- limited aggregates, where the expansion of task components may
2480 -- generate inner blocks. If the block is the rewriting of a call
2481 -- or the scope is an extended return statement this is valid master.
2482 -- The master in an extended return is only used within the return,
2483 -- and is subsequently overwritten in Move_Activation_Chain, but it
2486 if Ada_Version >= Ada_05 then
2487 while Is_Internal (S) loop
2488 if Nkind (Parent (S)) = N_Block_Statement
2490 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
2493 elsif Ekind (S) = E_Return_Statement then
2501 -- Nothing to do if we already built a master entity for this scope
2502 -- or if there is no task hierarchy.
2504 if Has_Master_Entity (S)
2505 or else Restriction_Active (No_Task_Hierarchy)
2510 -- Otherwise first build the master entity
2511 -- _Master : constant Master_Id := Current_Master.all;
2512 -- and insert it just before the current declaration
2515 Make_Object_Declaration (Loc,
2516 Defining_Identifier =>
2517 Make_Defining_Identifier (Loc, Name_uMaster),
2518 Constant_Present => True,
2519 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2521 Make_Explicit_Dereference (Loc,
2522 New_Reference_To (RTE (RE_Current_Master), Loc)));
2525 Insert_Before (P, Decl);
2528 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2529 -- non-internal scope selected above.
2531 if Ada_Version >= Ada_05 then
2532 Set_Has_Master_Entity (S);
2534 Set_Has_Master_Entity (Scope (E));
2537 -- Now mark the containing scope as a task master
2539 while Nkind (P) /= N_Compilation_Unit loop
2542 -- If we fall off the top, we are at the outer level, and the
2543 -- environment task is our effective master, so nothing to mark.
2546 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2548 Set_Is_Task_Master (P, True);
2551 elsif Nkind (Parent (P)) = N_Subunit then
2552 P := Corresponding_Stub (Parent (P));
2555 end Build_Master_Entity;
2557 -----------------------------------------
2558 -- Build_Private_Protected_Declaration --
2559 -----------------------------------------
2561 function Build_Private_Protected_Declaration
2562 (N : Node_Id) return Entity_Id
2564 Loc : constant Source_Ptr := Sloc (N);
2565 Body_Id : constant Entity_Id := Defining_Entity (N);
2570 Spec_Id : Entity_Id;
2573 Formal := First_Formal (Body_Id);
2575 -- The protected operation always has at least one formal, namely the
2576 -- object itself, but it is only placed in the parameter list if
2577 -- expansion is enabled.
2579 if Present (Formal) or else Expander_Active then
2580 Plist := Copy_Parameter_List (Body_Id);
2585 if Nkind (Specification (N)) = N_Procedure_Specification then
2587 Make_Procedure_Specification (Loc,
2588 Defining_Unit_Name =>
2589 Make_Defining_Identifier (Sloc (Body_Id),
2590 Chars => Chars (Body_Id)),
2591 Parameter_Specifications =>
2595 Make_Function_Specification (Loc,
2596 Defining_Unit_Name =>
2597 Make_Defining_Identifier (Sloc (Body_Id),
2598 Chars => Chars (Body_Id)),
2599 Parameter_Specifications => Plist,
2600 Result_Definition =>
2601 New_Occurrence_Of (Etype (Body_Id), Loc));
2604 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2605 Insert_Before (N, Decl);
2606 Spec_Id := Defining_Unit_Name (New_Spec);
2608 -- Indicate that the entity comes from source, to ensure that cross-
2609 -- reference information is properly generated. The body itself is
2610 -- rewritten during expansion, and the body entity will not appear in
2611 -- calls to the operation.
2613 Set_Comes_From_Source (Spec_Id, True);
2615 Set_Has_Completion (Spec_Id);
2616 Set_Convention (Spec_Id, Convention_Protected);
2618 end Build_Private_Protected_Declaration;
2620 ---------------------------
2621 -- Build_Protected_Entry --
2622 ---------------------------
2624 function Build_Protected_Entry
2627 Pid : Node_Id) return Node_Id
2629 Loc : constant Source_Ptr := Sloc (N);
2631 Decls : constant List_Id := Declarations (N);
2632 End_Lab : constant Node_Id :=
2633 End_Label (Handled_Statement_Sequence (N));
2634 End_Loc : constant Source_Ptr :=
2635 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2636 -- Used for the generated call to Complete_Entry_Body
2638 Han_Loc : Source_Ptr;
2639 -- Used for the exception handler, inserted at end of the body
2641 Op_Decls : constant List_Id := New_List;
2649 -- Set the source location on the exception handler only when debugging
2650 -- the expanded code (see Make_Implicit_Exception_Handler).
2652 if Debug_Generated_Code then
2655 -- Otherwise the inserted code should not be visible to the debugger
2658 Han_Loc := No_Location;
2662 Make_Defining_Identifier (Loc,
2663 Chars => Chars (Protected_Body_Subprogram (Ent)));
2665 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2667 -- Add the following declarations:
2668 -- type poVP is access poV;
2669 -- _object : poVP := poVP (_O);
2671 -- where _O is the formal parameter associated with the concurrent
2672 -- object. These declarations are needed for Complete_Entry_Body.
2674 Add_Object_Pointer (Loc, Pid, Op_Decls);
2676 -- Add renamings for all formals, the Protection object, discriminals,
2677 -- privals and the entry index constant for use by debugger.
2679 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2680 Debug_Private_Data_Declarations (Decls);
2682 case Corresponding_Runtime_Package (Pid) is
2683 when System_Tasking_Protected_Objects_Entries =>
2685 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2687 when System_Tasking_Protected_Objects_Single_Entry =>
2689 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2692 raise Program_Error;
2695 Op_Stats := New_List (
2696 Make_Block_Statement (Loc,
2697 Declarations => Decls,
2698 Handled_Statement_Sequence =>
2699 Handled_Statement_Sequence (N)),
2701 Make_Procedure_Call_Statement (End_Loc,
2703 Parameter_Associations => New_List (
2704 Make_Attribute_Reference (End_Loc,
2706 Make_Selected_Component (End_Loc,
2708 Make_Identifier (End_Loc, Name_uObject),
2710 Make_Identifier (End_Loc, Name_uObject)),
2711 Attribute_Name => Name_Unchecked_Access))));
2713 -- When exceptions can not be propagated, we never need to call
2714 -- Exception_Complete_Entry_Body
2716 if No_Exception_Handlers_Set then
2718 Make_Subprogram_Body (Loc,
2719 Specification => Espec,
2720 Declarations => Op_Decls,
2721 Handled_Statement_Sequence =>
2722 Make_Handled_Sequence_Of_Statements (Loc,
2723 Statements => Op_Stats,
2724 End_Label => End_Lab));
2727 Ohandle := Make_Others_Choice (Loc);
2728 Set_All_Others (Ohandle);
2730 case Corresponding_Runtime_Package (Pid) is
2731 when System_Tasking_Protected_Objects_Entries =>
2734 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2736 when System_Tasking_Protected_Objects_Single_Entry =>
2739 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2742 raise Program_Error;
2745 -- Create body of entry procedure. The renaming declarations are
2746 -- placed ahead of the block that contains the actual entry body.
2749 Make_Subprogram_Body (Loc,
2750 Specification => Espec,
2751 Declarations => Op_Decls,
2752 Handled_Statement_Sequence =>
2753 Make_Handled_Sequence_Of_Statements (Loc,
2754 Statements => Op_Stats,
2755 End_Label => End_Lab,
2756 Exception_Handlers => New_List (
2757 Make_Implicit_Exception_Handler (Han_Loc,
2758 Exception_Choices => New_List (Ohandle),
2760 Statements => New_List (
2761 Make_Procedure_Call_Statement (Han_Loc,
2763 Parameter_Associations => New_List (
2764 Make_Attribute_Reference (Han_Loc,
2766 Make_Selected_Component (Han_Loc,
2768 Make_Identifier (Han_Loc, Name_uObject),
2770 Make_Identifier (Han_Loc, Name_uObject)),
2771 Attribute_Name => Name_Unchecked_Access),
2773 Make_Function_Call (Han_Loc,
2774 Name => New_Reference_To (
2775 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2777 end Build_Protected_Entry;
2779 -----------------------------------------
2780 -- Build_Protected_Entry_Specification --
2781 -----------------------------------------
2783 function Build_Protected_Entry_Specification
2786 Ent_Id : Entity_Id) return Node_Id
2788 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2791 Set_Debug_Info_Needed (Def_Id);
2793 if Present (Ent_Id) then
2794 Append_Elmt (P, Accept_Address (Ent_Id));
2798 Make_Procedure_Specification (Loc,
2799 Defining_Unit_Name => Def_Id,
2800 Parameter_Specifications => New_List (
2801 Make_Parameter_Specification (Loc,
2802 Defining_Identifier =>
2803 Make_Defining_Identifier (Loc, Name_uO),
2805 New_Reference_To (RTE (RE_Address), Loc)),
2807 Make_Parameter_Specification (Loc,
2808 Defining_Identifier => P,
2810 New_Reference_To (RTE (RE_Address), Loc)),
2812 Make_Parameter_Specification (Loc,
2813 Defining_Identifier =>
2814 Make_Defining_Identifier (Loc, Name_uE),
2816 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2817 end Build_Protected_Entry_Specification;
2819 --------------------------
2820 -- Build_Protected_Spec --
2821 --------------------------
2823 function Build_Protected_Spec
2825 Obj_Type : Entity_Id;
2827 Unprotected : Boolean := False) return List_Id
2829 Loc : constant Source_Ptr := Sloc (N);
2832 New_Plist : List_Id;
2833 New_Param : Node_Id;
2836 New_Plist := New_List;
2838 Formal := First_Formal (Ident);
2839 while Present (Formal) loop
2841 Make_Parameter_Specification (Loc,
2842 Defining_Identifier =>
2843 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2844 In_Present => In_Present (Parent (Formal)),
2845 Out_Present => Out_Present (Parent (Formal)),
2846 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
2849 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2852 Append (New_Param, New_Plist);
2853 Next_Formal (Formal);
2856 -- If the subprogram is a procedure and the context is not an access
2857 -- to protected subprogram, the parameter is in-out. Otherwise it is
2861 Make_Parameter_Specification (Loc,
2862 Defining_Identifier =>
2863 Make_Defining_Identifier (Loc, Name_uObject),
2866 (Etype (Ident) = Standard_Void_Type
2867 and then not Is_RTE (Obj_Type, RE_Address)),
2869 New_Reference_To (Obj_Type, Loc));
2870 Set_Debug_Info_Needed (Defining_Identifier (Decl));
2871 Prepend_To (New_Plist, Decl);
2874 end Build_Protected_Spec;
2876 ---------------------------------------
2877 -- Build_Protected_Sub_Specification --
2878 ---------------------------------------
2880 function Build_Protected_Sub_Specification
2882 Prot_Typ : Entity_Id;
2883 Mode : Subprogram_Protection_Mode) return Node_Id
2885 Loc : constant Source_Ptr := Sloc (N);
2889 New_Plist : List_Id;
2892 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2893 (Dispatching_Mode => ' ',
2894 Protected_Mode => 'P',
2895 Unprotected_Mode => 'N');
2898 if Ekind (Defining_Unit_Name (Specification (N))) =
2901 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2906 Def_Id := Defining_Unit_Name (Specification (Decl));
2909 Build_Protected_Spec
2910 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
2911 Mode = Unprotected_Mode);
2913 Make_Defining_Identifier (Loc,
2914 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
2916 -- The unprotected operation carries the user code, and debugging
2917 -- information must be generated for it, even though this spec does
2918 -- not come from source. It is also convenient to allow gdb to step
2919 -- into the protected operation, even though it only contains lock/
2922 Set_Debug_Info_Needed (New_Id);
2924 -- If a pragma Eliminate applies to the source entity, the internal
2925 -- subprograms will be eliminated as well.
2927 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
2929 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2931 Make_Procedure_Specification (Loc,
2932 Defining_Unit_Name => New_Id,
2933 Parameter_Specifications => New_Plist);
2935 -- Create a new specification for the anonymous subprogram type
2939 Make_Function_Specification (Loc,
2940 Defining_Unit_Name => New_Id,
2941 Parameter_Specifications => New_Plist,
2942 Result_Definition =>
2943 Copy_Result_Type (Result_Definition (Specification (Decl))));
2945 Set_Return_Present (Defining_Unit_Name (New_Spec));
2949 end Build_Protected_Sub_Specification;
2951 -------------------------------------
2952 -- Build_Protected_Subprogram_Body --
2953 -------------------------------------
2955 function Build_Protected_Subprogram_Body
2958 N_Op_Spec : Node_Id) return Node_Id
2960 Loc : constant Source_Ptr := Sloc (N);
2962 P_Op_Spec : Node_Id;
2965 Unprot_Call : Node_Id;
2967 Lock_Name : Node_Id;
2968 Lock_Stmt : Node_Id;
2969 Service_Name : Node_Id;
2971 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2972 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2974 Object_Parm : Node_Id;
2977 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2978 -- Tell whether a given subprogram cannot raise an exception
2980 -----------------------
2981 -- Is_Exception_Safe --
2982 -----------------------
2984 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2986 function Has_Side_Effect (N : Node_Id) return Boolean;
2987 -- Return True whenever encountering a subprogram call or raise
2988 -- statement of any kind in the sequence of statements
2990 ---------------------
2991 -- Has_Side_Effect --
2992 ---------------------
2994 -- What is this doing buried two levels down in exp_ch9. It seems
2995 -- like a generally useful function, and indeed there may be code
2996 -- duplication going on here ???
2998 function Has_Side_Effect (N : Node_Id) return Boolean is
3002 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3003 -- Indicate whether N is a subprogram call or a raise statement
3005 ----------------------
3006 -- Is_Call_Or_Raise --
3007 ----------------------
3009 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3011 return Nkind_In (N, N_Procedure_Call_Statement,
3014 N_Raise_Constraint_Error,
3015 N_Raise_Program_Error,
3016 N_Raise_Storage_Error);
3017 end Is_Call_Or_Raise;
3019 -- Start of processing for Has_Side_Effect
3023 while Present (Stmt) loop
3024 if Is_Call_Or_Raise (Stmt) then
3028 -- An object declaration can also contain a function call
3029 -- or a raise statement
3031 if Nkind (Stmt) = N_Object_Declaration then
3032 Expr := Expression (Stmt);
3034 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3043 end Has_Side_Effect;
3045 -- Start of processing for Is_Exception_Safe
3048 -- If the checks handled by the back end are not disabled, we cannot
3049 -- ensure that no exception will be raised.
3051 if not Access_Checks_Suppressed (Empty)
3052 or else not Discriminant_Checks_Suppressed (Empty)
3053 or else not Range_Checks_Suppressed (Empty)
3054 or else not Index_Checks_Suppressed (Empty)
3055 or else Opt.Stack_Checking_Enabled
3060 if Has_Side_Effect (First (Declarations (Subprogram)))
3063 First (Statements (Handled_Statement_Sequence (Subprogram))))
3069 end Is_Exception_Safe;
3071 -- Start of processing for Build_Protected_Subprogram_Body
3074 Op_Spec := Specification (N);
3075 Exc_Safe := Is_Exception_Safe (N);
3078 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3080 -- Build a list of the formal parameters of the protected version of
3081 -- the subprogram to use as the actual parameters of the unprotected
3084 Uactuals := New_List;
3085 Pformal := First (Parameter_Specifications (P_Op_Spec));
3086 while Present (Pformal) loop
3088 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
3093 -- Make a call to the unprotected version of the subprogram built above
3094 -- for use by the protected version built below.
3096 if Nkind (Op_Spec) = N_Function_Specification then
3098 R := Make_Temporary (Loc, 'R');
3100 Make_Object_Declaration (Loc,
3101 Defining_Identifier => R,
3102 Constant_Present => True,
3103 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3105 Make_Function_Call (Loc,
3106 Name => Make_Identifier (Loc,
3107 Chars (Defining_Unit_Name (N_Op_Spec))),
3108 Parameter_Associations => Uactuals));
3111 Make_Simple_Return_Statement (Loc,
3112 Expression => New_Reference_To (R, Loc));
3115 Unprot_Call := Make_Simple_Return_Statement (Loc,
3116 Expression => Make_Function_Call (Loc,
3118 Make_Identifier (Loc,
3119 Chars (Defining_Unit_Name (N_Op_Spec))),
3120 Parameter_Associations => Uactuals));
3125 Make_Procedure_Call_Statement (Loc,
3127 Make_Identifier (Loc,
3128 Chars (Defining_Unit_Name (N_Op_Spec))),
3129 Parameter_Associations => Uactuals);
3132 -- Wrap call in block that will be covered by an at_end handler
3134 if not Exc_Safe then
3135 Unprot_Call := Make_Block_Statement (Loc,
3136 Handled_Statement_Sequence =>
3137 Make_Handled_Sequence_Of_Statements (Loc,
3138 Statements => New_List (Unprot_Call)));
3141 -- Make the protected subprogram body. This locks the protected
3142 -- object and calls the unprotected version of the subprogram.
3144 case Corresponding_Runtime_Package (Pid) is
3145 when System_Tasking_Protected_Objects_Entries =>
3146 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3147 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3149 when System_Tasking_Protected_Objects_Single_Entry =>
3150 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3151 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3153 when System_Tasking_Protected_Objects =>
3154 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3155 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3158 raise Program_Error;
3162 Make_Attribute_Reference (Loc,
3164 Make_Selected_Component (Loc,
3166 Make_Identifier (Loc, Name_uObject),
3168 Make_Identifier (Loc, Name_uObject)),
3169 Attribute_Name => Name_Unchecked_Access);
3171 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3173 Parameter_Associations => New_List (Object_Parm));
3175 if Abort_Allowed then
3177 Make_Procedure_Call_Statement (Loc,
3178 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3179 Parameter_Associations => Empty_List),
3183 Stmts := New_List (Lock_Stmt);
3186 if not Exc_Safe then
3187 Append (Unprot_Call, Stmts);
3189 if Nkind (Op_Spec) = N_Function_Specification then
3191 Stmts := Empty_List;
3193 Append (Unprot_Call, Stmts);
3197 Make_Procedure_Call_Statement (Loc,
3198 Name => Service_Name,
3199 Parameter_Associations =>
3200 New_List (New_Copy_Tree (Object_Parm))),
3203 if Abort_Allowed then
3205 Make_Procedure_Call_Statement (Loc,
3206 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3207 Parameter_Associations => Empty_List),
3211 if Nkind (Op_Spec) = N_Function_Specification then
3212 Append (Return_Stmt, Stmts);
3213 Append (Make_Block_Statement (Loc,
3214 Declarations => New_List (Unprot_Call),
3215 Handled_Statement_Sequence =>
3216 Make_Handled_Sequence_Of_Statements (Loc,
3217 Statements => Stmts)), Pre_Stmts);
3223 Make_Subprogram_Body (Loc,
3224 Declarations => Empty_List,
3225 Specification => P_Op_Spec,
3226 Handled_Statement_Sequence =>
3227 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3229 if not Exc_Safe then
3230 Set_Is_Protected_Subprogram_Body (Sub_Body);
3234 end Build_Protected_Subprogram_Body;
3236 -------------------------------------
3237 -- Build_Protected_Subprogram_Call --
3238 -------------------------------------
3240 procedure Build_Protected_Subprogram_Call
3244 External : Boolean := True)
3246 Loc : constant Source_Ptr := Sloc (N);
3247 Sub : constant Entity_Id := Entity (Name);
3253 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3256 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3259 if Present (Parameter_Associations (N)) then
3260 Params := New_Copy_List_Tree (Parameter_Associations (N));
3265 -- If the type is an untagged derived type, convert to the root type,
3266 -- which is the one on which the operations are defined.
3268 if Nkind (Rec) = N_Unchecked_Type_Conversion
3269 and then not Is_Tagged_Type (Etype (Rec))
3270 and then Is_Derived_Type (Etype (Rec))
3272 Set_Etype (Rec, Root_Type (Etype (Rec)));
3273 Set_Subtype_Mark (Rec,
3274 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3277 Prepend (Rec, Params);
3279 if Ekind (Sub) = E_Procedure then
3281 Make_Procedure_Call_Statement (Loc,
3283 Parameter_Associations => Params));
3286 pragma Assert (Ekind (Sub) = E_Function);
3288 Make_Function_Call (Loc,
3290 Parameter_Associations => Params));
3294 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3295 and then Is_Entity_Name (Expression (Rec))
3296 and then Is_Shared_Passive (Entity (Expression (Rec)))
3298 Add_Shared_Var_Lock_Procs (N);
3300 end Build_Protected_Subprogram_Call;
3302 -------------------------
3303 -- Build_Selected_Name --
3304 -------------------------
3306 function Build_Selected_Name
3307 (Prefix : Entity_Id;
3308 Selector : Entity_Id;
3309 Append_Char : Character := ' ') return Name_Id
3311 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3312 Select_Len : Natural;
3315 Get_Name_String (Chars (Selector));
3316 Select_Len := Name_Len;
3317 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3318 Get_Name_String (Chars (Prefix));
3320 -- If scope is anonymous type, discard suffix to recover name of
3321 -- single protected object. Otherwise use protected type name.
3323 if Name_Buffer (Name_Len) = 'T' then
3324 Name_Len := Name_Len - 1;
3327 Add_Str_To_Name_Buffer ("__");
3328 for J in 1 .. Select_Len loop
3329 Add_Char_To_Name_Buffer (Select_Buffer (J));
3332 -- Now add the Append_Char if specified. The encoding to follow
3333 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3334 -- then the entity is associated to a protected type subprogram.
3335 -- Otherwise, it is a protected type entry. For each case, the
3336 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3338 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3340 if Append_Char /= ' ' then
3341 if Append_Char = 'P' or Append_Char = 'N' then
3342 Add_Char_To_Name_Buffer (Append_Char);
3345 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3346 return New_External_Name (Name_Find, ' ', -1);
3351 end Build_Selected_Name;
3353 -----------------------------
3354 -- Build_Simple_Entry_Call --
3355 -----------------------------
3357 -- A task entry call is converted to a call to Call_Simple
3360 -- P : parms := (parm, parm, parm);
3362 -- Call_Simple (acceptor-task, entry-index, P'Address);
3368 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3369 -- the parameters, and the constructed aggregate value contains either the
3370 -- parameters or, in the case of non-elementary types, references to these
3371 -- parameters. Then the address of this aggregate is passed to the runtime
3372 -- routine, along with the task id value and the task entry index value.
3373 -- Pnn is only required if parameters are present.
3375 -- The assignments after the call are present only in the case of in-out
3376 -- or out parameters for elementary types, and are used to assign back the
3377 -- resulting values of such parameters.
3379 -- Note: the reason that we insert a block here is that in the context
3380 -- of selects, conditional entry calls etc. the entry call statement
3381 -- appears on its own, not as an element of a list.
3383 -- A protected entry call is converted to a Protected_Entry_Call:
3386 -- P : E1_Params := (param, param, param);
3388 -- Bnn : Communications_Block;
3391 -- P : E1_Params := (param, param, param);
3392 -- Bnn : Communications_Block;
3395 -- Protected_Entry_Call (
3396 -- Object => po._object'Access,
3397 -- E => <entry index>;
3398 -- Uninterpreted_Data => P'Address;
3399 -- Mode => Simple_Call;
3406 procedure Build_Simple_Entry_Call
3415 -- If call has been inlined, nothing left to do
3417 if Nkind (N) = N_Block_Statement then
3421 -- Convert entry call to Call_Simple call
3424 Loc : constant Source_Ptr := Sloc (N);
3425 Parms : constant List_Id := Parameter_Associations (N);
3426 Stats : constant List_Id := New_List;
3429 Comm_Name : Entity_Id;
3433 Ent_Acc : Entity_Id;
3435 Iface_Tag : Entity_Id;
3436 Iface_Typ : Entity_Id;
3449 -- Simple entry and entry family cases merge here
3451 Ent := Entity (Ename);
3452 Ent_Acc := Entry_Parameters_Type (Ent);
3453 Conctyp := Etype (Concval);
3455 -- If prefix is an access type, dereference to obtain the task type
3457 if Is_Access_Type (Conctyp) then
3458 Conctyp := Designated_Type (Conctyp);
3461 -- Special case for protected subprogram calls
3463 if Is_Protected_Type (Conctyp)
3464 and then Is_Subprogram (Entity (Ename))
3466 if not Is_Eliminated (Entity (Ename)) then
3467 Build_Protected_Subprogram_Call
3468 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3475 -- First parameter is the Task_Id value from the task value or the
3476 -- Object from the protected object value, obtained by selecting
3477 -- the _Task_Id or _Object from the result of doing an unchecked
3478 -- conversion to convert the value to the corresponding record type.
3480 if Nkind (Concval) = N_Function_Call
3481 and then Is_Task_Type (Conctyp)
3482 and then Ada_Version >= Ada_05
3485 ExpR : constant Node_Id := Relocate_Node (Concval);
3486 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3491 Make_Object_Declaration (Loc,
3492 Defining_Identifier => Obj,
3493 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3494 Expression => ExpR);
3495 Set_Etype (Obj, Conctyp);
3496 Decls := New_List (Decl);
3497 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3504 Parm1 := Concurrent_Ref (Concval);
3506 -- Second parameter is the entry index, computed by the routine
3507 -- provided for this purpose. The value of this expression is
3508 -- assigned to an intermediate variable to assure that any entry
3509 -- family index expressions are evaluated before the entry
3513 or else Restriction_Active (No_Entry_Queue) = False
3514 or else not Is_Protected_Type (Conctyp)
3515 or else Number_Entries (Conctyp) > 1
3516 or else (Has_Attach_Handler (Conctyp)
3517 and then not Restricted_Profile)
3519 X := Make_Defining_Identifier (Loc, Name_uX);
3522 Make_Object_Declaration (Loc,
3523 Defining_Identifier => X,
3524 Object_Definition =>
3525 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3526 Expression => Actual_Index_Expression (
3527 Loc, Entity (Ename), Index, Concval));
3529 Append_To (Decls, Xdecl);
3530 Parm2 := New_Reference_To (X, Loc);
3537 -- The third parameter is the packaged parameters. If there are
3538 -- none, then it is just the null address, since nothing is passed.
3541 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3544 -- Case of parameters present, where third argument is the address
3545 -- of a packaged record containing the required parameter values.
3548 -- First build a list of parameter values, which are references to
3549 -- objects of the parameter types.
3553 Actual := First_Actual (N);
3554 Formal := First_Formal (Ent);
3556 while Present (Actual) loop
3558 -- If it is a by_copy_type, copy it to a new variable. The
3559 -- packaged record has a field that points to this variable.
3561 if Is_By_Copy_Type (Etype (Actual)) then
3563 Make_Object_Declaration (Loc,
3564 Defining_Identifier => Make_Temporary (Loc, 'J'),
3565 Aliased_Present => True,
3566 Object_Definition =>
3567 New_Reference_To (Etype (Formal), Loc));
3569 -- Mark the object as not needing initialization since the
3570 -- initialization is performed separately, avoiding errors
3571 -- on cases such as formals of null-excluding access types.
3573 Set_No_Initialization (N_Node);
3575 -- We must make an assignment statement separate for the
3576 -- case of limited type. We cannot assign it unless the
3577 -- Assignment_OK flag is set first. An out formal of an
3578 -- access type must also be initialized from the actual,
3579 -- as stated in RM 6.4.1 (13).
3581 if Ekind (Formal) /= E_Out_Parameter
3582 or else Is_Access_Type (Etype (Formal))
3585 New_Reference_To (Defining_Identifier (N_Node), Loc);
3586 Set_Assignment_OK (N_Var);
3588 Make_Assignment_Statement (Loc,
3590 Expression => Relocate_Node (Actual)));
3593 Append (N_Node, Decls);
3596 Make_Attribute_Reference (Loc,
3597 Attribute_Name => Name_Unchecked_Access,
3599 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3601 -- Interface class-wide formal
3603 if Ada_Version >= Ada_05
3604 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3605 and then Is_Interface (Etype (Formal))
3607 Iface_Typ := Etype (Etype (Formal));
3610 -- formal_iface_type! (actual.iface_tag)'reference
3613 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3614 pragma Assert (Present (Iface_Tag));
3617 Make_Reference (Loc,
3618 Unchecked_Convert_To (Iface_Typ,
3619 Make_Selected_Component (Loc,
3621 Relocate_Node (Actual),
3623 New_Reference_To (Iface_Tag, Loc)))));
3629 Make_Reference (Loc, Relocate_Node (Actual)));
3633 Next_Actual (Actual);
3634 Next_Formal_With_Extras (Formal);
3637 -- Now build the declaration of parameters initialized with the
3638 -- aggregate containing this constructed parameter list.
3640 P := Make_Defining_Identifier (Loc, Name_uP);
3643 Make_Object_Declaration (Loc,
3644 Defining_Identifier => P,
3645 Object_Definition =>
3646 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3648 Make_Aggregate (Loc, Expressions => Plist));
3651 Make_Attribute_Reference (Loc,
3652 Prefix => New_Reference_To (P, Loc),
3653 Attribute_Name => Name_Address);
3655 Append (Pdecl, Decls);
3658 -- Now we can create the call, case of protected type
3660 if Is_Protected_Type (Conctyp) then
3661 case Corresponding_Runtime_Package (Conctyp) is
3662 when System_Tasking_Protected_Objects_Entries =>
3664 -- Change the type of the index declaration
3666 Set_Object_Definition (Xdecl,
3667 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3669 -- Some additional declarations for protected entry calls
3675 -- Bnn : Communications_Block;
3677 Comm_Name := Make_Temporary (Loc, 'B');
3680 Make_Object_Declaration (Loc,
3681 Defining_Identifier => Comm_Name,
3682 Object_Definition =>
3683 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3685 -- Some additional statements for protected entry calls
3687 -- Protected_Entry_Call (
3688 -- Object => po._object'Access,
3689 -- E => <entry index>;
3690 -- Uninterpreted_Data => P'Address;
3691 -- Mode => Simple_Call;
3695 Make_Procedure_Call_Statement (Loc,
3697 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3699 Parameter_Associations => New_List (
3700 Make_Attribute_Reference (Loc,
3701 Attribute_Name => Name_Unchecked_Access,
3705 New_Reference_To (RTE (RE_Simple_Call), Loc),
3706 New_Occurrence_Of (Comm_Name, Loc)));
3708 when System_Tasking_Protected_Objects_Single_Entry =>
3709 -- Protected_Single_Entry_Call (
3710 -- Object => po._object'Access,
3711 -- Uninterpreted_Data => P'Address;
3712 -- Mode => Simple_Call);
3715 Make_Procedure_Call_Statement (Loc,
3716 Name => New_Reference_To (
3717 RTE (RE_Protected_Single_Entry_Call), Loc),
3719 Parameter_Associations => New_List (
3720 Make_Attribute_Reference (Loc,
3721 Attribute_Name => Name_Unchecked_Access,
3724 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3727 raise Program_Error;
3730 -- Case of task type
3734 Make_Procedure_Call_Statement (Loc,
3735 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3736 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3740 Append_To (Stats, Call);
3742 -- If there are out or in/out parameters by copy add assignment
3743 -- statements for the result values.
3745 if Present (Parms) then
3746 Actual := First_Actual (N);
3747 Formal := First_Formal (Ent);
3749 Set_Assignment_OK (Actual);
3750 while Present (Actual) loop
3751 if Is_By_Copy_Type (Etype (Actual))
3752 and then Ekind (Formal) /= E_In_Parameter
3755 Make_Assignment_Statement (Loc,
3756 Name => New_Copy (Actual),
3758 Make_Explicit_Dereference (Loc,
3759 Make_Selected_Component (Loc,
3760 Prefix => New_Reference_To (P, Loc),
3762 Make_Identifier (Loc, Chars (Formal)))));
3764 -- In all cases (including limited private types) we want
3765 -- the assignment to be valid.
3767 Set_Assignment_OK (Name (N_Node));
3769 -- If the call is the triggering alternative in an
3770 -- asynchronous select, or the entry_call alternative of a
3771 -- conditional entry call, the assignments for in-out
3772 -- parameters are incorporated into the statement list that
3773 -- follows, so that there are executed only if the entry
3776 if (Nkind (Parent (N)) = N_Triggering_Alternative
3777 and then N = Triggering_Statement (Parent (N)))
3779 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3780 and then N = Entry_Call_Statement (Parent (N)))
3782 if No (Statements (Parent (N))) then
3783 Set_Statements (Parent (N), New_List);
3786 Prepend (N_Node, Statements (Parent (N)));
3789 Insert_After (Call, N_Node);
3793 Next_Actual (Actual);
3794 Next_Formal_With_Extras (Formal);
3798 -- Finally, create block and analyze it
3801 Make_Block_Statement (Loc,
3802 Declarations => Decls,
3803 Handled_Statement_Sequence =>
3804 Make_Handled_Sequence_Of_Statements (Loc,
3805 Statements => Stats)));
3809 end Build_Simple_Entry_Call;
3811 --------------------------------
3812 -- Build_Task_Activation_Call --
3813 --------------------------------
3815 procedure Build_Task_Activation_Call (N : Node_Id) is
3816 Loc : constant Source_Ptr := Sloc (N);
3823 -- Get the activation chain entity. Except in the case of a package
3824 -- body, this is in the node that was passed. For a package body, we
3825 -- have to find the corresponding package declaration node.
3827 if Nkind (N) = N_Package_Body then
3828 P := Corresponding_Spec (N);
3831 exit when Nkind (P) = N_Package_Declaration;
3834 Chain := Activation_Chain_Entity (P);
3837 Chain := Activation_Chain_Entity (N);
3840 if Present (Chain) then
3841 if Restricted_Profile then
3842 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3844 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3848 Make_Procedure_Call_Statement (Loc,
3850 Parameter_Associations =>
3851 New_List (Make_Attribute_Reference (Loc,
3852 Prefix => New_Occurrence_Of (Chain, Loc),
3853 Attribute_Name => Name_Unchecked_Access)));
3855 if Nkind (N) = N_Package_Declaration then
3856 if Present (Corresponding_Body (N)) then
3859 elsif Present (Private_Declarations (Specification (N))) then
3860 Append (Call, Private_Declarations (Specification (N)));
3863 Append (Call, Visible_Declarations (Specification (N)));
3867 if Present (Handled_Statement_Sequence (N)) then
3869 -- The call goes at the start of the statement sequence
3870 -- after the start of exception range label if one is present.
3876 Stm := First (Statements (Handled_Statement_Sequence (N)));
3878 -- A special case, skip exception range label if one is
3879 -- present (from front end zcx processing).
3881 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3885 -- Another special case, if the first statement is a block
3886 -- from optimization of a local raise to a goto, then the
3887 -- call goes inside this block.
3889 if Nkind (Stm) = N_Block_Statement
3890 and then Exception_Junk (Stm)
3893 First (Statements (Handled_Statement_Sequence (Stm)));
3896 -- Insertion point is after any exception label pushes,
3897 -- since we want it covered by any local handlers.
3899 while Nkind (Stm) in N_Push_xxx_Label loop
3903 -- Now we have the proper insertion point
3905 Insert_Before (Stm, Call);
3909 Set_Handled_Statement_Sequence (N,
3910 Make_Handled_Sequence_Of_Statements (Loc,
3911 Statements => New_List (Call)));
3916 Check_Task_Activation (N);
3918 end Build_Task_Activation_Call;
3920 -------------------------------
3921 -- Build_Task_Allocate_Block --
3922 -------------------------------
3924 procedure Build_Task_Allocate_Block
3929 T : constant Entity_Id := Entity (Expression (N));
3930 Init : constant Entity_Id := Base_Init_Proc (T);
3931 Loc : constant Source_Ptr := Sloc (N);
3932 Chain : constant Entity_Id :=
3933 Make_Defining_Identifier (Loc, Name_uChain);
3934 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
3939 Make_Block_Statement (Loc,
3940 Identifier => New_Reference_To (Blkent, Loc),
3941 Declarations => New_List (
3943 -- _Chain : Activation_Chain;
3945 Make_Object_Declaration (Loc,
3946 Defining_Identifier => Chain,
3947 Aliased_Present => True,
3948 Object_Definition =>
3949 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3951 Handled_Statement_Sequence =>
3952 Make_Handled_Sequence_Of_Statements (Loc,
3954 Statements => New_List (
3958 Make_Procedure_Call_Statement (Loc,
3959 Name => New_Reference_To (Init, Loc),
3960 Parameter_Associations => Args),
3962 -- Activate_Tasks (_Chain);
3964 Make_Procedure_Call_Statement (Loc,
3965 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3966 Parameter_Associations => New_List (
3967 Make_Attribute_Reference (Loc,
3968 Prefix => New_Reference_To (Chain, Loc),
3969 Attribute_Name => Name_Unchecked_Access))))),
3971 Has_Created_Identifier => True,
3972 Is_Task_Allocation_Block => True);
3975 Make_Implicit_Label_Declaration (Loc,
3976 Defining_Identifier => Blkent,
3977 Label_Construct => Block));
3979 Append_To (Actions, Block);
3981 Set_Activation_Chain_Entity (Block, Chain);
3982 end Build_Task_Allocate_Block;
3984 -----------------------------------------------
3985 -- Build_Task_Allocate_Block_With_Init_Stmts --
3986 -----------------------------------------------
3988 procedure Build_Task_Allocate_Block_With_Init_Stmts
3991 Init_Stmts : List_Id)
3993 Loc : constant Source_Ptr := Sloc (N);
3994 Chain : constant Entity_Id :=
3995 Make_Defining_Identifier (Loc, Name_uChain);
3996 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4000 Append_To (Init_Stmts,
4001 Make_Procedure_Call_Statement (Loc,
4002 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4003 Parameter_Associations => New_List (
4004 Make_Attribute_Reference (Loc,
4005 Prefix => New_Reference_To (Chain, Loc),
4006 Attribute_Name => Name_Unchecked_Access))));
4009 Make_Block_Statement (Loc,
4010 Identifier => New_Reference_To (Blkent, Loc),
4011 Declarations => New_List (
4013 -- _Chain : Activation_Chain;
4015 Make_Object_Declaration (Loc,
4016 Defining_Identifier => Chain,
4017 Aliased_Present => True,
4018 Object_Definition =>
4019 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4021 Handled_Statement_Sequence =>
4022 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4024 Has_Created_Identifier => True,
4025 Is_Task_Allocation_Block => True);
4028 Make_Implicit_Label_Declaration (Loc,
4029 Defining_Identifier => Blkent,
4030 Label_Construct => Block));
4032 Append_To (Actions, Block);
4034 Set_Activation_Chain_Entity (Block, Chain);
4035 end Build_Task_Allocate_Block_With_Init_Stmts;
4037 -----------------------------------
4038 -- Build_Task_Proc_Specification --
4039 -----------------------------------
4041 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4042 Loc : constant Source_Ptr := Sloc (T);
4043 Spec_Id : Entity_Id;
4046 -- Case of explicit task type, suffix TB
4048 if Comes_From_Source (T) then
4050 Make_Defining_Identifier (Loc,
4051 Chars => New_External_Name (Chars (T), "TB"));
4053 -- Case of anonymous task type, suffix B
4057 Make_Defining_Identifier (Loc,
4058 Chars => New_External_Name (Chars (T), 'B'));
4061 Set_Is_Internal (Spec_Id);
4063 -- Associate the procedure with the task, if this is the declaration
4064 -- (and not the body) of the procedure.
4066 if No (Task_Body_Procedure (T)) then
4067 Set_Task_Body_Procedure (T, Spec_Id);
4071 Make_Procedure_Specification (Loc,
4072 Defining_Unit_Name => Spec_Id,
4073 Parameter_Specifications => New_List (
4074 Make_Parameter_Specification (Loc,
4075 Defining_Identifier =>
4076 Make_Defining_Identifier (Loc, Name_uTask),
4078 Make_Access_Definition (Loc,
4080 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4081 end Build_Task_Proc_Specification;
4083 ---------------------------------------
4084 -- Build_Unprotected_Subprogram_Body --
4085 ---------------------------------------
4087 function Build_Unprotected_Subprogram_Body
4089 Pid : Node_Id) return Node_Id
4091 Decls : constant List_Id := Declarations (N);
4094 -- Add renamings for the Protection object, discriminals, privals and
4095 -- the entry index constant for use by debugger.
4097 Debug_Private_Data_Declarations (Decls);
4099 -- Make an unprotected version of the subprogram for use within the same
4100 -- object, with a new name and an additional parameter representing the
4104 Make_Subprogram_Body (Sloc (N),
4106 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4107 Declarations => Decls,
4108 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4109 end Build_Unprotected_Subprogram_Body;
4111 ----------------------------
4112 -- Collect_Entry_Families --
4113 ----------------------------
4115 procedure Collect_Entry_Families
4118 Current_Node : in out Node_Id;
4119 Conctyp : Entity_Id)
4122 Efam_Decl : Node_Id;
4123 Efam_Type : Entity_Id;
4126 Efam := First_Entity (Conctyp);
4127 while Present (Efam) loop
4128 if Ekind (Efam) = E_Entry_Family then
4129 Efam_Type := Make_Temporary (Loc, 'F');
4134 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4136 Bas_Decl : Node_Id := Empty;
4141 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4143 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4144 Bas := Make_Temporary (Loc, 'B');
4147 Make_Subtype_Declaration (Loc,
4148 Defining_Identifier => Bas,
4149 Subtype_Indication =>
4150 Make_Subtype_Indication (Loc,
4152 New_Occurrence_Of (Standard_Integer, Loc),
4154 Make_Range_Constraint (Loc,
4155 Range_Expression => Make_Range (Loc,
4156 Make_Integer_Literal
4157 (Loc, -Entry_Family_Bound),
4158 Make_Integer_Literal
4159 (Loc, Entry_Family_Bound - 1)))));
4161 Insert_After (Current_Node, Bas_Decl);
4162 Current_Node := Bas_Decl;
4167 Make_Full_Type_Declaration (Loc,
4168 Defining_Identifier => Efam_Type,
4170 Make_Unconstrained_Array_Definition (Loc,
4172 (New_List (New_Occurrence_Of (Bas, Loc))),
4174 Component_Definition =>
4175 Make_Component_Definition (Loc,
4176 Aliased_Present => False,
4177 Subtype_Indication =>
4178 New_Reference_To (Standard_Character, Loc))));
4181 Insert_After (Current_Node, Efam_Decl);
4182 Current_Node := Efam_Decl;
4183 Analyze (Efam_Decl);
4186 Make_Component_Declaration (Loc,
4187 Defining_Identifier =>
4188 Make_Defining_Identifier (Loc, Chars (Efam)),
4190 Component_Definition =>
4191 Make_Component_Definition (Loc,
4192 Aliased_Present => False,
4193 Subtype_Indication =>
4194 Make_Subtype_Indication (Loc,
4196 New_Occurrence_Of (Efam_Type, Loc),
4199 Make_Index_Or_Discriminant_Constraint (Loc,
4200 Constraints => New_List (
4202 (Etype (Discrete_Subtype_Definition
4203 (Parent (Efam))), Loc)))))));
4209 end Collect_Entry_Families;
4211 -----------------------
4212 -- Concurrent_Object --
4213 -----------------------
4215 function Concurrent_Object
4216 (Spec_Id : Entity_Id;
4217 Conc_Typ : Entity_Id) return Entity_Id
4220 -- Parameter _O or _object
4222 if Is_Protected_Type (Conc_Typ) then
4223 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4228 pragma Assert (Is_Task_Type (Conc_Typ));
4229 return First_Formal (Task_Body_Procedure (Conc_Typ));
4231 end Concurrent_Object;
4233 ----------------------
4234 -- Copy_Result_Type --
4235 ----------------------
4237 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4238 New_Res : constant Node_Id := New_Copy_Tree (Res);
4243 -- If the result type is an access_to_subprogram, we must create
4244 -- new entities for its spec.
4246 if Nkind (New_Res) = N_Access_Definition
4247 and then Present (Access_To_Subprogram_Definition (New_Res))
4249 -- Provide new entities for the formals
4251 Par_Spec := First (Parameter_Specifications
4252 (Access_To_Subprogram_Definition (New_Res)));
4253 while Present (Par_Spec) loop
4254 Formal := Defining_Identifier (Par_Spec);
4255 Set_Defining_Identifier (Par_Spec,
4256 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4262 end Copy_Result_Type;
4264 --------------------
4265 -- Concurrent_Ref --
4266 --------------------
4268 -- The expression returned for a reference to a concurrent object has the
4271 -- taskV!(name)._Task_Id
4275 -- objectV!(name)._Object
4277 -- for a protected object. For the case of an access to a concurrent
4278 -- object, there is an extra explicit dereference:
4280 -- taskV!(name.all)._Task_Id
4281 -- objectV!(name.all)._Object
4283 -- here taskV and objectV are the types for the associated records, which
4284 -- contain the required _Task_Id and _Object fields for tasks and protected
4285 -- objects, respectively.
4287 -- For the case of a task type name, the expression is
4291 -- i.e. a call to the Self function which returns precisely this Task_Id
4293 -- For the case of a protected type name, the expression is
4297 -- which is a renaming of the _object field of the current object
4298 -- record, passed into protected operations as a parameter.
4300 function Concurrent_Ref (N : Node_Id) return Node_Id is
4301 Loc : constant Source_Ptr := Sloc (N);
4302 Ntyp : constant Entity_Id := Etype (N);
4306 function Is_Current_Task (T : Entity_Id) return Boolean;
4307 -- Check whether the reference is to the immediately enclosing task
4308 -- type, or to an outer one (rare but legal).
4310 ---------------------
4311 -- Is_Current_Task --
4312 ---------------------
4314 function Is_Current_Task (T : Entity_Id) return Boolean is
4318 Scop := Current_Scope;
4319 while Present (Scop)
4320 and then Scop /= Standard_Standard
4326 elsif Is_Task_Type (Scop) then
4329 -- If this is a procedure nested within the task type, we must
4330 -- assume that it can be called from an inner task, and therefore
4331 -- cannot treat it as a local reference.
4333 elsif Is_Overloadable (Scop)
4334 and then In_Open_Scopes (T)
4339 Scop := Scope (Scop);
4343 -- We know that we are within the task body, so should have found it
4346 raise Program_Error;
4347 end Is_Current_Task;
4349 -- Start of processing for Concurrent_Ref
4352 if Is_Access_Type (Ntyp) then
4353 Dtyp := Designated_Type (Ntyp);
4355 if Is_Protected_Type (Dtyp) then
4356 Sel := Name_uObject;
4358 Sel := Name_uTask_Id;
4362 Make_Selected_Component (Loc,
4364 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4365 Make_Explicit_Dereference (Loc, N)),
4366 Selector_Name => Make_Identifier (Loc, Sel));
4368 elsif Is_Entity_Name (N)
4369 and then Is_Concurrent_Type (Entity (N))
4371 if Is_Task_Type (Entity (N)) then
4373 if Is_Current_Task (Entity (N)) then
4375 Make_Function_Call (Loc,
4376 Name => New_Reference_To (RTE (RE_Self), Loc));
4381 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4382 T_Body : constant Node_Id :=
4383 Parent (Corresponding_Body (Parent (Entity (N))));
4387 Make_Object_Declaration (Loc,
4388 Defining_Identifier => T_Self,
4389 Object_Definition =>
4390 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4392 Make_Function_Call (Loc,
4393 Name => New_Reference_To (RTE (RE_Self), Loc)));
4394 Prepend (Decl, Declarations (T_Body));
4396 Set_Scope (T_Self, Entity (N));
4397 return New_Occurrence_Of (T_Self, Loc);
4402 pragma Assert (Is_Protected_Type (Entity (N)));
4405 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4409 if Is_Protected_Type (Ntyp) then
4410 Sel := Name_uObject;
4412 elsif Is_Task_Type (Ntyp) then
4413 Sel := Name_uTask_Id;
4416 raise Program_Error;
4420 Make_Selected_Component (Loc,
4422 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4424 Selector_Name => Make_Identifier (Loc, Sel));
4428 ------------------------
4429 -- Convert_Concurrent --
4430 ------------------------
4432 function Convert_Concurrent
4434 Typ : Entity_Id) return Node_Id
4437 if not Is_Concurrent_Type (Typ) then
4441 Unchecked_Convert_To
4442 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4444 end Convert_Concurrent;
4446 -------------------------------------
4447 -- Debug_Private_Data_Declarations --
4448 -------------------------------------
4450 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4451 Debug_Nod : Node_Id;
4455 Decl := First (Decls);
4456 while Present (Decl)
4457 and then not Comes_From_Source (Decl)
4459 -- Declaration for concurrent entity _object and its access type,
4460 -- along with the entry index subtype:
4461 -- type prot_typVP is access prot_typV;
4462 -- _object : prot_typVP := prot_typV (_O);
4463 -- subtype Jnn is <Type of Index> range Low .. High;
4465 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4466 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4468 -- Declaration for the Protection object, discriminals, privals and
4469 -- entry index constant:
4470 -- conc_typR : protection_typ renames _object._object;
4471 -- discr_nameD : discr_typ renames _object.discr_name;
4472 -- discr_nameD : discr_typ renames _task.discr_name;
4473 -- prival_name : comp_typ renames _object.comp_name;
4474 -- J : constant Jnn :=
4475 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4477 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4478 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4479 Debug_Nod := Debug_Renaming_Declaration (Decl);
4481 if Present (Debug_Nod) then
4482 Insert_After (Decl, Debug_Nod);
4488 end Debug_Private_Data_Declarations;
4490 ----------------------------
4491 -- Entry_Index_Expression --
4492 ----------------------------
4494 function Entry_Index_Expression
4498 Ttyp : Entity_Id) return Node_Id
4508 -- The queues of entries and entry families appear in textual order in
4509 -- the associated record. The entry index is computed as the sum of the
4510 -- number of queues for all entries that precede the designated one, to
4511 -- which is added the index expression, if this expression denotes a
4512 -- member of a family.
4514 -- The following is a place holder for the count of simple entries
4516 Num := Make_Integer_Literal (Sloc, 1);
4518 -- We construct an expression which is a series of addition operations.
4519 -- The first operand is the number of single entries that precede this
4520 -- one, the second operand is the index value relative to the start of
4521 -- the referenced family, and the remaining operands are the lengths of
4522 -- the entry families that precede this entry, i.e. the constructed
4525 -- number_simple_entries +
4526 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4527 -- family'length + ...
4529 -- where index-value is the given index value, and s is the index
4530 -- subtype (we have to use pos because the subtype might be an
4531 -- enumeration type preventing direct subtraction). Note that the task
4532 -- entry array is one-indexed.
4534 -- The upper bound of the entry family may be a discriminant, so we
4535 -- retrieve the lower bound explicitly to compute offset, rather than
4536 -- using the index subtype which may mention a discriminant.
4538 if Present (Index) then
4539 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4548 Make_Attribute_Reference (Sloc,
4549 Attribute_Name => Name_Pos,
4550 Prefix => New_Reference_To (Base_Type (S), Sloc),
4551 Expressions => New_List (Relocate_Node (Index))),
4559 -- Now add lengths of preceding entries and entry families
4561 Prev := First_Entity (Ttyp);
4563 while Chars (Prev) /= Chars (Ent)
4564 or else (Ekind (Prev) /= Ekind (Ent))
4565 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4567 if Ekind (Prev) = E_Entry then
4568 Set_Intval (Num, Intval (Num) + 1);
4570 elsif Ekind (Prev) = E_Entry_Family then
4572 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4573 Lo := Type_Low_Bound (S);
4574 Hi := Type_High_Bound (S);
4579 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4581 -- Other components are anonymous types to be ignored
4591 end Entry_Index_Expression;
4593 ---------------------------
4594 -- Establish_Task_Master --
4595 ---------------------------
4597 procedure Establish_Task_Master (N : Node_Id) is
4600 if Restriction_Active (No_Task_Hierarchy) = False then
4601 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4602 Prepend_To (Declarations (N), Call);
4605 end Establish_Task_Master;
4607 --------------------------------
4608 -- Expand_Accept_Declarations --
4609 --------------------------------
4611 -- Part of the expansion of an accept statement involves the creation of
4612 -- a declaration that can be referenced from the statement sequence of
4617 -- This declaration is inserted immediately before the accept statement
4618 -- and it is important that it be inserted before the statements of the
4619 -- statement sequence are analyzed. Thus it would be too late to create
4620 -- this declaration in the Expand_N_Accept_Statement routine, which is
4621 -- why there is a separate procedure to be called directly from Sem_Ch9.
4623 -- Ann is used to hold the address of the record containing the parameters
4624 -- (see Expand_N_Entry_Call for more details on how this record is built).
4625 -- References to the parameters do an unchecked conversion of this address
4626 -- to a pointer to the required record type, and then access the field that
4627 -- holds the value of the required parameter. The entity for the address
4628 -- variable is held as the top stack element (i.e. the last element) of the
4629 -- Accept_Address stack in the corresponding entry entity, and this element
4630 -- must be set in place before the statements are processed.
4632 -- The above description applies to the case of a stand alone accept
4633 -- statement, i.e. one not appearing as part of a select alternative.
4635 -- For the case of an accept that appears as part of a select alternative
4636 -- of a selective accept, we must still create the declaration right away,
4637 -- since Ann is needed immediately, but there is an important difference:
4639 -- The declaration is inserted before the selective accept, not before
4640 -- the accept statement (which is not part of a list anyway, and so would
4641 -- not accommodate inserted declarations)
4643 -- We only need one address variable for the entire selective accept. So
4644 -- the Ann declaration is created only for the first accept alternative,
4645 -- and subsequent accept alternatives reference the same Ann variable.
4647 -- We can distinguish the two cases by seeing whether the accept statement
4648 -- is part of a list. If not, then it must be in an accept alternative.
4650 -- To expand the requeue statement, a label is provided at the end of the
4651 -- accept statement or alternative of which it is a part, so that the
4652 -- statement can be skipped after the requeue is complete. This label is
4653 -- created here rather than during the expansion of the accept statement,
4654 -- because it will be needed by any requeue statements within the accept,
4655 -- which are expanded before the accept.
4657 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4658 Loc : constant Source_Ptr := Sloc (N);
4659 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4660 Ann : Entity_Id := Empty;
4668 if Expander_Active then
4670 -- If we have no handled statement sequence, we may need to build
4671 -- a dummy sequence consisting of a null statement. This can be
4672 -- skipped if the trivial accept optimization is permitted.
4674 if not Trivial_Accept_OK
4676 (No (Stats) or else Null_Statements (Statements (Stats)))
4678 Set_Handled_Statement_Sequence (N,
4679 Make_Handled_Sequence_Of_Statements (Loc,
4680 New_List (Make_Null_Statement (Loc))));
4683 -- Create and declare two labels to be placed at the end of the
4684 -- accept statement. The first label is used to allow requeues to
4685 -- skip the remainder of entry processing. The second label is used
4686 -- to skip the remainder of entry processing if the rendezvous
4687 -- completes in the middle of the accept body.
4689 if Present (Handled_Statement_Sequence (N)) then
4694 Ent := Make_Temporary (Loc, 'L');
4695 Lab_Id := New_Reference_To (Ent, Loc);
4696 Lab := Make_Label (Loc, Lab_Id);
4698 Make_Implicit_Label_Declaration (Loc,
4699 Defining_Identifier => Ent,
4700 Label_Construct => Lab);
4701 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4703 Ent := Make_Temporary (Loc, 'L');
4704 Lab_Id := New_Reference_To (Ent, Loc);
4705 Lab := Make_Label (Loc, Lab_Id);
4707 Make_Implicit_Label_Declaration (Loc,
4708 Defining_Identifier => Ent,
4709 Label_Construct => Lab);
4710 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4718 -- Case of stand alone accept statement
4720 if Is_List_Member (N) then
4722 if Present (Handled_Statement_Sequence (N)) then
4723 Ann := Make_Temporary (Loc, 'A');
4726 Make_Object_Declaration (Loc,
4727 Defining_Identifier => Ann,
4728 Object_Definition =>
4729 New_Reference_To (RTE (RE_Address), Loc));
4731 Insert_Before (N, Adecl);
4734 Insert_Before (N, Ldecl);
4737 Insert_Before (N, Ldecl2);
4741 -- Case of accept statement which is in an accept alternative
4745 Acc_Alt : constant Node_Id := Parent (N);
4746 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4750 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4751 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4753 -- ??? Consider a single label for select statements
4755 if Present (Handled_Statement_Sequence (N)) then
4757 Statements (Handled_Statement_Sequence (N)));
4761 Statements (Handled_Statement_Sequence (N)));
4765 -- Find first accept alternative of the selective accept. A
4766 -- valid selective accept must have at least one accept in it.
4768 Alt := First (Select_Alternatives (Sel_Acc));
4770 while Nkind (Alt) /= N_Accept_Alternative loop
4774 -- If we are the first accept statement, then we have to create
4775 -- the Ann variable, as for the stand alone case, except that
4776 -- it is inserted before the selective accept. Similarly, a
4777 -- label for requeue expansion must be declared.
4779 if N = Accept_Statement (Alt) then
4780 Ann := Make_Temporary (Loc, 'A');
4782 Make_Object_Declaration (Loc,
4783 Defining_Identifier => Ann,
4784 Object_Definition =>
4785 New_Reference_To (RTE (RE_Address), Loc));
4787 Insert_Before (Sel_Acc, Adecl);
4790 -- If we are not the first accept statement, then find the Ann
4791 -- variable allocated by the first accept and use it.
4795 Node (Last_Elmt (Accept_Address
4796 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4801 -- Merge here with Ann either created or referenced, and Adecl
4802 -- pointing to the corresponding declaration. Remaining processing
4803 -- is the same for the two cases.
4805 if Present (Ann) then
4806 Append_Elmt (Ann, Accept_Address (Ent));
4807 Set_Debug_Info_Needed (Ann);
4810 -- Create renaming declarations for the entry formals. Each reference
4811 -- to a formal becomes a dereference of a component of the parameter
4812 -- block, whose address is held in Ann. These declarations are
4813 -- eventually inserted into the accept block, and analyzed there so
4814 -- that they have the proper scope for gdb and do not conflict with
4815 -- other declarations.
4817 if Present (Parameter_Specifications (N))
4818 and then Present (Handled_Statement_Sequence (N))
4828 Formal := First_Formal (Ent);
4830 while Present (Formal) loop
4831 Comp := Entry_Component (Formal);
4833 Make_Defining_Identifier (Loc, Chars (Formal));
4835 Set_Etype (New_F, Etype (Formal));
4836 Set_Scope (New_F, Ent);
4838 -- Now we set debug info needed on New_F even though it does
4839 -- not come from source, so that the debugger will get the
4840 -- right information for these generated names.
4842 Set_Debug_Info_Needed (New_F);
4844 if Ekind (Formal) = E_In_Parameter then
4845 Set_Ekind (New_F, E_Constant);
4847 Set_Ekind (New_F, E_Variable);
4848 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4851 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4854 Make_Object_Renaming_Declaration (Loc,
4855 Defining_Identifier =>
4858 New_Reference_To (Etype (Formal), Loc),
4860 Make_Explicit_Dereference (Loc,
4861 Make_Selected_Component (Loc,
4863 Unchecked_Convert_To (
4864 Entry_Parameters_Type (Ent),
4865 New_Reference_To (Ann, Loc)),
4867 New_Reference_To (Comp, Loc))));
4869 if No (Declarations (N)) then
4870 Set_Declarations (N, New_List);
4873 Append (Decl, Declarations (N));
4874 Set_Renamed_Object (Formal, New_F);
4875 Next_Formal (Formal);
4882 end Expand_Accept_Declarations;
4884 ---------------------------------------------
4885 -- Expand_Access_Protected_Subprogram_Type --
4886 ---------------------------------------------
4888 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4889 Loc : constant Source_Ptr := Sloc (N);
4891 T : constant Entity_Id := Defining_Identifier (N);
4892 D_T : constant Entity_Id := Designated_Type (T);
4893 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
4894 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
4895 P_List : constant List_Id := Build_Protected_Spec
4896 (N, RTE (RE_Address), D_T, False);
4902 -- Create access to subprogram with full signature
4904 if Etype (D_T) /= Standard_Void_Type then
4906 Make_Access_Function_Definition (Loc,
4907 Parameter_Specifications => P_List,
4908 Result_Definition =>
4909 Copy_Result_Type (Result_Definition (Type_Definition (N))));
4913 Make_Access_Procedure_Definition (Loc,
4914 Parameter_Specifications => P_List);
4918 Make_Full_Type_Declaration (Loc,
4919 Defining_Identifier => D_T2,
4920 Type_Definition => Def1);
4922 Insert_After (N, Decl1);
4925 -- Create Equivalent_Type, a record with two components for an access to
4926 -- object and an access to subprogram.
4929 Make_Component_Declaration (Loc,
4930 Defining_Identifier => Make_Temporary (Loc, 'P'),
4931 Component_Definition =>
4932 Make_Component_Definition (Loc,
4933 Aliased_Present => False,
4934 Subtype_Indication =>
4935 New_Occurrence_Of (RTE (RE_Address), Loc))),
4937 Make_Component_Declaration (Loc,
4938 Defining_Identifier => Make_Temporary (Loc, 'S'),
4939 Component_Definition =>
4940 Make_Component_Definition (Loc,
4941 Aliased_Present => False,
4942 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4945 Make_Full_Type_Declaration (Loc,
4946 Defining_Identifier => E_T,
4948 Make_Record_Definition (Loc,
4950 Make_Component_List (Loc,
4951 Component_Items => Comps)));
4953 Insert_After (Decl1, Decl2);
4955 Set_Equivalent_Type (T, E_T);
4956 end Expand_Access_Protected_Subprogram_Type;
4958 --------------------------
4959 -- Expand_Entry_Barrier --
4960 --------------------------
4962 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4963 Cond : constant Node_Id :=
4964 Condition (Entry_Body_Formal_Part (N));
4965 Prot : constant Entity_Id := Scope (Ent);
4966 Spec_Decl : constant Node_Id := Parent (Prot);
4969 Body_Decl : Node_Id;
4972 if No_Run_Time_Mode then
4973 Error_Msg_CRT ("entry barrier", N);
4977 -- The body of the entry barrier must be analyzed in the context of the
4978 -- protected object, but its scope is external to it, just as any other
4979 -- unprotected version of a protected operation. The specification has
4980 -- been produced when the protected type declaration was elaborated. We
4981 -- build the body, insert it in the enclosing scope, but analyze it in
4982 -- the current context. A more uniform approach would be to treat the
4983 -- barrier just as a protected function, and discard the protected
4984 -- version of it because it is never called.
4986 if Expander_Active then
4987 B_F := Build_Barrier_Function (N, Ent, Prot);
4988 Func := Barrier_Function (Ent);
4989 Set_Corresponding_Spec (B_F, Func);
4991 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
4993 if Nkind (Parent (Body_Decl)) = N_Subunit then
4994 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
4997 Insert_Before_And_Analyze (Body_Decl, B_F);
4999 Set_Discriminals (Spec_Decl);
5000 Set_Scope (Func, Scope (Prot));
5003 Analyze_And_Resolve (Cond, Any_Boolean);
5006 -- The Ravenscar profile restricts barriers to simple variables declared
5007 -- within the protected object. We also allow Boolean constants, since
5008 -- these appear in several published examples and are also allowed by
5009 -- the Aonix compiler.
5011 -- Note that after analysis variables in this context will be replaced
5012 -- by the corresponding prival, that is to say a renaming of a selected
5013 -- component of the form _Object.Var. If expansion is disabled, as
5014 -- within a generic, we check that the entity appears in the current
5017 if Is_Entity_Name (Cond) then
5019 -- A small optimization of useless renamings. If the scope of the
5020 -- entity of the condition is not the barrier function, then the
5021 -- condition does not reference any of the generated renamings
5022 -- within the function.
5025 and then Scope (Entity (Cond)) /= Func
5027 Set_Declarations (B_F, Empty_List);
5030 if Entity (Cond) = Standard_False
5032 Entity (Cond) = Standard_True
5036 elsif not Expander_Active
5037 and then Scope (Entity (Cond)) = Current_Scope
5041 -- Check for case of _object.all.field (note that the explicit
5042 -- dereference gets inserted by analyze/expand of _object.field)
5044 elsif Present (Renamed_Object (Entity (Cond)))
5046 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5050 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5056 -- It is not a boolean variable or literal, so check the restriction
5058 Check_Restriction (Simple_Barriers, Cond);
5059 end Expand_Entry_Barrier;
5061 ------------------------------
5062 -- Expand_N_Abort_Statement --
5063 ------------------------------
5065 -- Expand abort T1, T2, .. Tn; into:
5066 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5068 procedure Expand_N_Abort_Statement (N : Node_Id) is
5069 Loc : constant Source_Ptr := Sloc (N);
5070 Tlist : constant List_Id := Names (N);
5076 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5079 Tasknm := First (Tlist);
5081 while Present (Tasknm) loop
5084 -- A task interface class-wide type object is being aborted.
5085 -- Retrieve its _task_id by calling a dispatching routine.
5087 if Ada_Version >= Ada_05
5088 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5089 and then Is_Interface (Etype (Tasknm))
5090 and then Is_Task_Interface (Etype (Tasknm))
5092 Append_To (Component_Associations (Aggr),
5093 Make_Component_Association (Loc,
5094 Choices => New_List (
5095 Make_Integer_Literal (Loc, Count)),
5098 -- Task_Id (Tasknm._disp_get_task_id)
5100 Make_Unchecked_Type_Conversion (Loc,
5102 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5104 Make_Selected_Component (Loc,
5106 New_Copy_Tree (Tasknm),
5108 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5111 Append_To (Component_Associations (Aggr),
5112 Make_Component_Association (Loc,
5113 Choices => New_List (
5114 Make_Integer_Literal (Loc, Count)),
5115 Expression => Concurrent_Ref (Tasknm)));
5122 Make_Procedure_Call_Statement (Loc,
5123 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5124 Parameter_Associations => New_List (
5125 Make_Qualified_Expression (Loc,
5126 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5127 Expression => Aggr))));
5130 end Expand_N_Abort_Statement;
5132 -------------------------------
5133 -- Expand_N_Accept_Statement --
5134 -------------------------------
5136 -- This procedure handles expansion of accept statements that stand
5137 -- alone, i.e. they are not part of an accept alternative. The expansion
5138 -- of accept statement in accept alternatives is handled by the routines
5139 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5140 -- following description applies only to stand alone accept statements.
5142 -- If there is no handled statement sequence, or only null statements,
5143 -- then this is called a trivial accept, and the expansion is:
5145 -- Accept_Trivial (entry-index)
5147 -- If there is a handled statement sequence, then the expansion is:
5154 -- Accept_Call (entry-index, Ann);
5155 -- Renaming_Declarations for formals
5156 -- <statement sequence from N_Accept_Statement node>
5157 -- Complete_Rendezvous;
5162 -- <exception handler from N_Accept_Statement node>
5163 -- Complete_Rendezvous;
5165 -- <exception handler from N_Accept_Statement node>
5166 -- Complete_Rendezvous;
5171 -- when all others =>
5172 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5175 -- The first three declarations were already inserted ahead of the accept
5176 -- statement by the Expand_Accept_Declarations procedure, which was called
5177 -- directly from the semantics during analysis of the accept statement,
5178 -- before analyzing its contained statements.
5180 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5181 -- from possible expansion activity (the original source of course does
5182 -- not have any declarations associated with the accept statement, since
5183 -- an accept statement has no declarative part). In particular, if the
5184 -- expander is active, the first such declaration is the declaration of
5185 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5187 -- The two blocks are merged into a single block if the inner block has
5188 -- no exception handlers, but otherwise two blocks are required, since
5189 -- exceptions might be raised in the exception handlers of the inner
5190 -- block, and Exceptional_Complete_Rendezvous must be called.
5192 procedure Expand_N_Accept_Statement (N : Node_Id) is
5193 Loc : constant Source_Ptr := Sloc (N);
5194 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5195 Ename : constant Node_Id := Entry_Direct_Name (N);
5196 Eindx : constant Node_Id := Entry_Index (N);
5197 Eent : constant Entity_Id := Entity (Ename);
5198 Acstack : constant Elist_Id := Accept_Address (Eent);
5199 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5200 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5205 -- Start of processing for Expand_N_Accept_Statement
5208 -- If accept statement is not part of a list, then its parent must be
5209 -- an accept alternative, and, as described above, we do not do any
5210 -- expansion for such accept statements at this level.
5212 if not Is_List_Member (N) then
5213 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5216 -- Trivial accept case (no statement sequence, or null statements).
5217 -- If the accept statement has declarations, then just insert them
5218 -- before the procedure call.
5220 elsif Trivial_Accept_OK
5221 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5223 -- Remove declarations for renamings, because the parameter block
5224 -- will not be assigned.
5231 D := First (Declarations (N));
5233 while Present (D) loop
5235 if Nkind (D) = N_Object_Renaming_Declaration then
5243 if Present (Declarations (N)) then
5244 Insert_Actions (N, Declarations (N));
5248 Make_Procedure_Call_Statement (Loc,
5249 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5250 Parameter_Associations => New_List (
5251 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5255 -- Discard Entry_Address that was created for it, so it will not be
5256 -- emitted if this accept statement is in the statement part of a
5257 -- delay alternative.
5259 if Present (Stats) then
5260 Remove_Last_Elmt (Acstack);
5263 -- Case of statement sequence present
5266 -- Construct the block, using the declarations from the accept
5267 -- statement if any to initialize the declarations of the block.
5269 Blkent := Make_Temporary (Loc, 'A');
5270 Set_Ekind (Blkent, E_Block);
5271 Set_Etype (Blkent, Standard_Void_Type);
5272 Set_Scope (Blkent, Current_Scope);
5275 Make_Block_Statement (Loc,
5276 Identifier => New_Reference_To (Blkent, Loc),
5277 Declarations => Declarations (N),
5278 Handled_Statement_Sequence => Build_Accept_Body (N));
5280 -- Prepend call to Accept_Call to main statement sequence If the
5281 -- accept has exception handlers, the statement sequence is wrapped
5282 -- in a block. Insert call and renaming declarations in the
5283 -- declarations of the block, so they are elaborated before the
5287 Make_Procedure_Call_Statement (Loc,
5288 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5289 Parameter_Associations => New_List (
5290 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5291 New_Reference_To (Ann, Loc)));
5293 if Parent (Stats) = N then
5294 Prepend (Call, Statements (Stats));
5303 Push_Scope (Blkent);
5311 D := First (Declarations (N));
5312 while Present (D) loop
5315 if Nkind (D) = N_Object_Renaming_Declaration then
5317 -- The renaming declarations for the formals were created
5318 -- during analysis of the accept statement, and attached to
5319 -- the list of declarations. Place them now in the context
5320 -- of the accept block or subprogram.
5323 Typ := Entity (Subtype_Mark (D));
5324 Insert_After (Call, D);
5327 -- If the formal is class_wide, it does not have an actual
5328 -- subtype. The analysis of the renaming declaration creates
5329 -- one, but we need to retain the class-wide nature of the
5332 if Is_Class_Wide_Type (Typ) then
5333 Set_Etype (Defining_Identifier (D), Typ);
5344 -- Replace the accept statement by the new block
5349 -- Last step is to unstack the Accept_Address value
5351 Remove_Last_Elmt (Acstack);
5353 end Expand_N_Accept_Statement;
5355 ----------------------------------
5356 -- Expand_N_Asynchronous_Select --
5357 ----------------------------------
5359 -- This procedure assumes that the trigger statement is an entry call or
5360 -- a dispatching procedure call. A delay alternative should already have
5361 -- been expanded into an entry call to the appropriate delay object Wait
5364 -- If the trigger is a task entry call, the select is implemented with
5365 -- a Task_Entry_Call:
5370 -- P : parms := (parm, parm, parm);
5372 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5374 -- procedure _clean is
5377 -- Cancel_Task_Entry_Call (C);
5384 -- (<acceptor-task>, -- Acceptor
5385 -- <entry-index>, -- E
5386 -- P'Address, -- Uninterpreted_Data
5387 -- Asynchronous_Call, -- Mode
5388 -- B); -- Rendezvous_Successful
5395 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5398 -- when Abort_Signal => Abort_Undefer;
5405 -- <triggered-statements>
5409 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5410 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5414 -- P : parms := (parm, parm, parm);
5416 -- Call_Simple (acceptor-task, entry-index, P'Address);
5422 -- so the task at hand is to convert the latter expansion into the former
5424 -- If the trigger is a protected entry call, the select is implemented
5425 -- with Protected_Entry_Call:
5428 -- P : E1_Params := (param, param, param);
5429 -- Bnn : Communications_Block;
5434 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5436 -- procedure _clean is
5439 -- if Enqueued (Bnn) then
5440 -- Cancel_Protected_Entry_Call (Bnn);
5447 -- Protected_Entry_Call
5448 -- (po._object'Access, -- Object
5449 -- <entry index>, -- E
5450 -- P'Address, -- Uninterpreted_Data
5451 -- Asynchronous_Call, -- Mode
5454 -- if Enqueued (Bnn) then
5458 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5461 -- when Abort_Signal => Abort_Undefer;
5464 -- if not Cancelled (Bnn) then
5465 -- <triggered-statements>
5469 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5473 -- P : E1_Params := (param, param, param);
5474 -- Bnn : Communications_Block;
5477 -- Protected_Entry_Call
5478 -- (po._object'Access, -- Object
5479 -- <entry index>, -- E
5480 -- P'Address, -- Uninterpreted_Data
5481 -- Simple_Call, -- Mode
5488 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5492 -- B : Boolean := False;
5493 -- Bnn : Communication_Block;
5494 -- C : Ada.Tags.Prim_Op_Kind;
5495 -- D : System.Storage_Elements.Dummy_Communication_Block;
5496 -- K : Ada.Tags.Tagged_Kind :=
5497 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5498 -- P : Parameters := (Param1 .. ParamN);
5503 -- if K = Ada.Tags.TK_Limited_Tagged then
5504 -- <dispatching-call>;
5505 -- <triggering-statements>;
5509 -- Ada.Tags.Get_Offset_Index
5510 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5512 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5514 -- if C = POK_Protected_Entry then
5516 -- procedure _clean is
5518 -- if Enqueued (Bnn) then
5519 -- Cancel_Protected_Entry_Call (Bnn);
5525 -- _Disp_Asynchronous_Select
5526 -- (<object>, S, P'Address, D, B);
5527 -- Bnn := Communication_Block (D);
5529 -- Param1 := P.Param1;
5531 -- ParamN := P.ParamN;
5533 -- if Enqueued (Bnn) then
5534 -- <abortable-statements>
5537 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5540 -- when Abort_Signal => Abort_Undefer;
5543 -- if not Cancelled (Bnn) then
5544 -- <triggering-statements>
5547 -- elsif C = POK_Task_Entry then
5549 -- procedure _clean is
5551 -- Cancel_Task_Entry_Call (U);
5557 -- _Disp_Asynchronous_Select
5558 -- (<object>, S, P'Address, D, B);
5559 -- Bnn := Communication_Bloc (D);
5561 -- Param1 := P.Param1;
5563 -- ParamN := P.ParamN;
5568 -- <abortable-statements>
5570 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5573 -- when Abort_Signal => Abort_Undefer;
5577 -- <triggering-statements>
5582 -- <dispatching-call>;
5583 -- <triggering-statements>
5588 -- The job is to convert this to the asynchronous form
5590 -- If the trigger is a delay statement, it will have been expanded into a
5591 -- call to one of the GNARL delay procedures. This routine will convert
5592 -- this into a protected entry call on a delay object and then continue
5593 -- processing as for a protected entry call trigger. This requires
5594 -- declaring a Delay_Block object and adding a pointer to this object to
5595 -- the parameter list of the delay procedure to form the parameter list of
5596 -- the entry call. This object is used by the runtime to queue the delay
5599 -- For a description of the use of P and the assignments after the call,
5600 -- see Expand_N_Entry_Call_Statement.
5602 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5603 Loc : constant Source_Ptr := Sloc (N);
5604 Abrt : constant Node_Id := Abortable_Part (N);
5605 Astats : constant List_Id := Statements (Abrt);
5606 Trig : constant Node_Id := Triggering_Alternative (N);
5607 Tstats : constant List_Id := Statements (Trig);
5609 Abort_Block_Ent : Entity_Id;
5610 Abortable_Block : Node_Id;
5612 Blk_Ent : Entity_Id;
5613 Blk_Typ : Entity_Id;
5615 Call_Ent : Entity_Id;
5616 Cancel_Param : Entity_Id;
5617 Cleanup_Block : Node_Id;
5618 Cleanup_Block_Ent : Entity_Id;
5619 Cleanup_Stmts : List_Id;
5620 Conc_Typ_Stmts : List_Id;
5622 Dblock_Ent : Entity_Id;
5627 Enqueue_Call : Node_Id;
5631 Lim_Typ_Stmts : List_Id;
5637 ProtE_Stmts : List_Id;
5638 ProtP_Stmts : List_Id;
5641 Target_Undefer : RE_Id;
5642 TaskE_Stmts : List_Id;
5643 Undefer_Args : List_Id := No_List;
5645 B : Entity_Id; -- Call status flag
5646 Bnn : Entity_Id; -- Communication block
5647 C : Entity_Id; -- Call kind
5648 K : Entity_Id; -- Tagged kind
5649 P : Entity_Id; -- Parameter block
5650 S : Entity_Id; -- Primitive operation slot
5651 T : Entity_Id; -- Additional status flag
5654 Blk_Ent := Make_Temporary (Loc, 'A');
5655 Ecall := Triggering_Statement (Trig);
5657 -- The arguments in the call may require dynamic allocation, and the
5658 -- call statement may have been transformed into a block. The block
5659 -- may contain additional declarations for internal entities, and the
5660 -- original call is found by sequential search.
5662 if Nkind (Ecall) = N_Block_Statement then
5663 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5664 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5665 N_Entry_Call_Statement)
5671 -- This is either a dispatching call or a delay statement used as a
5672 -- trigger which was expanded into a procedure call.
5674 if Nkind (Ecall) = N_Procedure_Call_Statement then
5675 if Ada_Version >= Ada_05
5677 (No (Original_Node (Ecall))
5678 or else not Nkind_In (Original_Node (Ecall),
5679 N_Delay_Relative_Statement,
5680 N_Delay_Until_Statement))
5682 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5687 -- Call status flag processing, generate:
5688 -- B : Boolean := False;
5690 B := Build_B (Loc, Decls);
5692 -- Communication block processing, generate:
5693 -- Bnn : Communication_Block;
5695 Bnn := Make_Temporary (Loc, 'B');
5697 Make_Object_Declaration (Loc,
5698 Defining_Identifier => Bnn,
5699 Object_Definition =>
5700 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5702 -- Call kind processing, generate:
5703 -- C : Ada.Tags.Prim_Op_Kind;
5705 C := Build_C (Loc, Decls);
5707 -- Tagged kind processing, generate:
5708 -- K : Ada.Tags.Tagged_Kind :=
5709 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5711 -- Dummy communication block, generate:
5712 -- D : Dummy_Communication_Block;
5715 Make_Object_Declaration (Loc,
5716 Defining_Identifier =>
5717 Make_Defining_Identifier (Loc, Name_uD),
5718 Object_Definition =>
5720 RTE (RE_Dummy_Communication_Block), Loc)));
5722 K := Build_K (Loc, Decls, Obj);
5724 -- Parameter block processing
5726 Blk_Typ := Build_Parameter_Block
5727 (Loc, Actuals, Formals, Decls);
5728 P := Parameter_Block_Pack
5729 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5731 -- Dispatch table slot processing, generate:
5734 S := Build_S (Loc, Decls);
5736 -- Additional status flag processing, generate:
5739 T := Make_Temporary (Loc, 'T');
5741 Make_Object_Declaration (Loc,
5742 Defining_Identifier => T,
5743 Object_Definition =>
5744 New_Reference_To (Standard_Boolean, Loc)));
5746 ------------------------------
5747 -- Protected entry handling --
5748 ------------------------------
5751 -- Param1 := P.Param1;
5753 -- ParamN := P.ParamN;
5755 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5758 -- Bnn := Communication_Block (D);
5760 Prepend_To (Cleanup_Stmts,
5761 Make_Assignment_Statement (Loc,
5763 New_Reference_To (Bnn, Loc),
5765 Make_Unchecked_Type_Conversion (Loc,
5767 New_Reference_To (RTE (RE_Communication_Block), Loc),
5769 Make_Identifier (Loc, Name_uD))));
5772 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5774 Prepend_To (Cleanup_Stmts,
5775 Make_Procedure_Call_Statement (Loc,
5778 Find_Prim_Op (Etype (Etype (Obj)),
5779 Name_uDisp_Asynchronous_Select),
5781 Parameter_Associations =>
5783 New_Copy_Tree (Obj), -- <object>
5784 New_Reference_To (S, Loc), -- S
5785 Make_Attribute_Reference (Loc, -- P'Address
5787 New_Reference_To (P, Loc),
5790 Make_Identifier (Loc, Name_uD), -- D
5791 New_Reference_To (B, Loc)))); -- B
5794 -- if Enqueued (Bnn) then
5795 -- <abortable-statements>
5798 Append_To (Cleanup_Stmts,
5799 Make_If_Statement (Loc,
5801 Make_Function_Call (Loc,
5803 New_Reference_To (RTE (RE_Enqueued), Loc),
5804 Parameter_Associations =>
5806 New_Reference_To (Bnn, Loc))),
5809 New_Copy_List_Tree (Astats)));
5811 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5812 -- will then generate a _clean for the communication block Bnn.
5816 -- procedure _clean is
5818 -- if Enqueued (Bnn) then
5819 -- Cancel_Protected_Entry_Call (Bnn);
5828 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
5830 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5832 -- Wrap the cleanup block in an exception handling block
5838 -- when Abort_Signal => Abort_Undefer;
5841 Abort_Block_Ent := Make_Temporary (Loc, 'A');
5844 Make_Implicit_Label_Declaration (Loc,
5845 Defining_Identifier =>
5849 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5852 -- if not Cancelled (Bnn) then
5853 -- <triggering-statements>
5856 Append_To (ProtE_Stmts,
5857 Make_If_Statement (Loc,
5861 Make_Function_Call (Loc,
5863 New_Reference_To (RTE (RE_Cancelled), Loc),
5864 Parameter_Associations =>
5866 New_Reference_To (Bnn, Loc)))),
5869 New_Copy_List_Tree (Tstats)));
5871 -------------------------
5872 -- Task entry handling --
5873 -------------------------
5876 -- Param1 := P.Param1;
5878 -- ParamN := P.ParamN;
5880 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5883 -- Bnn := Communication_Block (D);
5885 Append_To (TaskE_Stmts,
5886 Make_Assignment_Statement (Loc,
5888 New_Reference_To (Bnn, Loc),
5890 Make_Unchecked_Type_Conversion (Loc,
5892 New_Reference_To (RTE (RE_Communication_Block), Loc),
5894 Make_Identifier (Loc, Name_uD))));
5897 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5899 Prepend_To (TaskE_Stmts,
5900 Make_Procedure_Call_Statement (Loc,
5903 Find_Prim_Op (Etype (Etype (Obj)),
5904 Name_uDisp_Asynchronous_Select),
5906 Parameter_Associations =>
5908 New_Copy_Tree (Obj), -- <object>
5909 New_Reference_To (S, Loc), -- S
5910 Make_Attribute_Reference (Loc, -- P'Address
5912 New_Reference_To (P, Loc),
5915 Make_Identifier (Loc, Name_uD), -- D
5916 New_Reference_To (B, Loc)))); -- B
5921 Prepend_To (TaskE_Stmts,
5922 Make_Procedure_Call_Statement (Loc,
5924 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5925 Parameter_Associations =>
5930 -- <abortable-statements>
5932 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5934 Prepend_To (Cleanup_Stmts,
5935 Make_Procedure_Call_Statement (Loc,
5937 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5938 Parameter_Associations =>
5941 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5942 -- will generate a _clean for the additional status flag.
5946 -- procedure _clean is
5948 -- Cancel_Task_Entry_Call (U);
5956 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
5958 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
5960 -- Wrap the cleanup block in an exception handling block
5966 -- when Abort_Signal => Abort_Undefer;
5969 Abort_Block_Ent := Make_Temporary (Loc, 'A');
5971 Append_To (TaskE_Stmts,
5972 Make_Implicit_Label_Declaration (Loc,
5973 Defining_Identifier => Abort_Block_Ent));
5975 Append_To (TaskE_Stmts,
5977 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5981 -- <triggering-statements>
5984 Append_To (TaskE_Stmts,
5985 Make_If_Statement (Loc,
5989 New_Reference_To (T, Loc)),
5992 New_Copy_List_Tree (Tstats)));
5994 ----------------------------------
5995 -- Protected procedure handling --
5996 ----------------------------------
5999 -- <dispatching-call>;
6000 -- <triggering-statements>
6002 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6003 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6006 -- S := Ada.Tags.Get_Offset_Index
6007 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6010 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6013 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6015 Append_To (Conc_Typ_Stmts,
6016 Make_Procedure_Call_Statement (Loc,
6019 Find_Prim_Op (Etype (Etype (Obj)),
6020 Name_uDisp_Get_Prim_Op_Kind),
6022 Parameter_Associations =>
6024 New_Copy_Tree (Obj),
6025 New_Reference_To (S, Loc),
6026 New_Reference_To (C, Loc))));
6029 -- if C = POK_Procedure_Entry then
6031 -- elsif C = POK_Task_Entry then
6037 Append_To (Conc_Typ_Stmts,
6038 Make_If_Statement (Loc,
6042 New_Reference_To (C, Loc),
6044 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6051 Make_Elsif_Part (Loc,
6055 New_Reference_To (C, Loc),
6057 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6066 -- <dispatching-call>;
6067 -- <triggering-statements>
6069 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6070 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6073 -- if K = Ada.Tags.TK_Limited_Tagged then
6080 Make_If_Statement (Loc,
6084 New_Reference_To (K, Loc),
6086 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6095 Make_Block_Statement (Loc,
6098 Handled_Statement_Sequence =>
6099 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6104 -- Delay triggering statement processing
6107 -- Add a Delay_Block object to the parameter list of the delay
6108 -- procedure to form the parameter list of the Wait entry call.
6110 Dblock_Ent := Make_Temporary (Loc, 'D');
6112 Pdef := Entity (Name (Ecall));
6114 if Is_RTE (Pdef, RO_CA_Delay_For) then
6116 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6118 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6120 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6122 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6123 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6126 Append_To (Parameter_Associations (Ecall),
6127 Make_Attribute_Reference (Loc,
6128 Prefix => New_Reference_To (Dblock_Ent, Loc),
6129 Attribute_Name => Name_Unchecked_Access));
6131 -- Create the inner block to protect the abortable part
6134 Make_Implicit_Exception_Handler (Loc,
6135 Exception_Choices =>
6136 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6137 Statements => New_List (
6138 Make_Procedure_Call_Statement (Loc,
6139 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6142 Make_Procedure_Call_Statement (Loc,
6143 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6146 Make_Block_Statement (Loc,
6147 Identifier => New_Reference_To (Blk_Ent, Loc),
6148 Handled_Statement_Sequence =>
6149 Make_Handled_Sequence_Of_Statements (Loc,
6150 Statements => Astats),
6151 Has_Created_Identifier => True,
6152 Is_Asynchronous_Call_Block => True);
6154 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6157 Make_Implicit_If_Statement (N,
6158 Condition => Make_Function_Call (Loc,
6159 Name => Enqueue_Call,
6160 Parameter_Associations => Parameter_Associations (Ecall)),
6162 New_List (Make_Block_Statement (Loc,
6163 Handled_Statement_Sequence =>
6164 Make_Handled_Sequence_Of_Statements (Loc,
6165 Statements => New_List (
6166 Make_Implicit_Label_Declaration (Loc,
6167 Defining_Identifier => Blk_Ent,
6168 Label_Construct => Abortable_Block),
6170 Exception_Handlers => Hdle)))));
6172 Stmts := New_List (Ecall);
6174 -- Construct statement sequence for new block
6177 Make_Implicit_If_Statement (N,
6178 Condition => Make_Function_Call (Loc,
6179 Name => New_Reference_To (
6180 RTE (RE_Timed_Out), Loc),
6181 Parameter_Associations => New_List (
6182 Make_Attribute_Reference (Loc,
6183 Prefix => New_Reference_To (Dblock_Ent, Loc),
6184 Attribute_Name => Name_Unchecked_Access))),
6185 Then_Statements => Tstats));
6187 -- The result is the new block
6189 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6192 Make_Block_Statement (Loc,
6193 Declarations => New_List (
6194 Make_Object_Declaration (Loc,
6195 Defining_Identifier => Dblock_Ent,
6196 Aliased_Present => True,
6197 Object_Definition => New_Reference_To (
6198 RTE (RE_Delay_Block), Loc))),
6200 Handled_Statement_Sequence =>
6201 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6211 Extract_Entry (Ecall, Concval, Ename, Index);
6212 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6214 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6215 Decls := Declarations (Ecall);
6217 if Is_Protected_Type (Etype (Concval)) then
6219 -- Get the declarations of the block expanded from the entry call
6221 Decl := First (Decls);
6222 while Present (Decl)
6224 (Nkind (Decl) /= N_Object_Declaration
6225 or else not Is_RTE (Etype (Object_Definition (Decl)),
6226 RE_Communication_Block))
6231 pragma Assert (Present (Decl));
6232 Cancel_Param := Defining_Identifier (Decl);
6234 -- Change the mode of the Protected_Entry_Call call
6236 -- Protected_Entry_Call (
6237 -- Object => po._object'Access,
6238 -- E => <entry index>;
6239 -- Uninterpreted_Data => P'Address;
6240 -- Mode => Asynchronous_Call;
6243 Stmt := First (Stmts);
6245 -- Skip assignments to temporaries created for in-out parameters
6247 -- This makes unwarranted assumptions about the shape of the expanded
6248 -- tree for the call, and should be cleaned up ???
6250 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6256 Param := First (Parameter_Associations (Call));
6257 while Present (Param)
6258 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6263 pragma Assert (Present (Param));
6264 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6267 -- Append an if statement to execute the abortable part
6270 -- if Enqueued (Bnn) then
6273 Make_Implicit_If_Statement (N,
6274 Condition => Make_Function_Call (Loc,
6275 Name => New_Reference_To (
6276 RTE (RE_Enqueued), Loc),
6277 Parameter_Associations => New_List (
6278 New_Reference_To (Cancel_Param, Loc))),
6279 Then_Statements => Astats));
6282 Make_Block_Statement (Loc,
6283 Identifier => New_Reference_To (Blk_Ent, Loc),
6284 Handled_Statement_Sequence =>
6285 Make_Handled_Sequence_Of_Statements (Loc,
6286 Statements => Stmts),
6287 Has_Created_Identifier => True,
6288 Is_Asynchronous_Call_Block => True);
6290 -- For the VM call Update_Exception instead of Abort_Undefer.
6291 -- See 4jexcept.ads for an explanation.
6293 if VM_Target = No_VM then
6294 Target_Undefer := RE_Abort_Undefer;
6296 Target_Undefer := RE_Update_Exception;
6298 New_List (Make_Function_Call (Loc,
6299 Name => New_Occurrence_Of
6300 (RTE (RE_Current_Target_Exception), Loc)));
6304 Make_Block_Statement (Loc,
6305 Handled_Statement_Sequence =>
6306 Make_Handled_Sequence_Of_Statements (Loc,
6307 Statements => New_List (
6308 Make_Implicit_Label_Declaration (Loc,
6309 Defining_Identifier => Blk_Ent,
6310 Label_Construct => Abortable_Block),
6315 Exception_Handlers => New_List (
6316 Make_Implicit_Exception_Handler (Loc,
6318 -- when Abort_Signal =>
6319 -- Abort_Undefer.all;
6321 Exception_Choices =>
6322 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6323 Statements => New_List (
6324 Make_Procedure_Call_Statement (Loc,
6325 Name => New_Reference_To (
6326 RTE (Target_Undefer), Loc),
6327 Parameter_Associations => Undefer_Args)))))),
6329 -- if not Cancelled (Bnn) then
6330 -- triggered statements
6333 Make_Implicit_If_Statement (N,
6334 Condition => Make_Op_Not (Loc,
6336 Make_Function_Call (Loc,
6337 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6338 Parameter_Associations => New_List (
6339 New_Occurrence_Of (Cancel_Param, Loc)))),
6340 Then_Statements => Tstats));
6342 -- Asynchronous task entry call
6349 B := Make_Defining_Identifier (Loc, Name_uB);
6351 -- Insert declaration of B in declarations of existing block
6354 Make_Object_Declaration (Loc,
6355 Defining_Identifier => B,
6356 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6358 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6360 -- Insert declaration of C in declarations of existing block
6363 Make_Object_Declaration (Loc,
6364 Defining_Identifier => Cancel_Param,
6365 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6367 -- Remove and save the call to Call_Simple
6369 Stmt := First (Stmts);
6371 -- Skip assignments to temporaries created for in-out parameters.
6372 -- This makes unwarranted assumptions about the shape of the expanded
6373 -- tree for the call, and should be cleaned up ???
6375 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6381 -- Create the inner block to protect the abortable part
6384 Make_Implicit_Exception_Handler (Loc,
6385 Exception_Choices =>
6386 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6389 Make_Procedure_Call_Statement (Loc,
6390 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6393 Make_Procedure_Call_Statement (Loc,
6394 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6397 Make_Block_Statement (Loc,
6398 Identifier => New_Reference_To (Blk_Ent, Loc),
6399 Handled_Statement_Sequence =>
6400 Make_Handled_Sequence_Of_Statements (Loc,
6401 Statements => Astats),
6402 Has_Created_Identifier => True,
6403 Is_Asynchronous_Call_Block => True);
6406 Make_Block_Statement (Loc,
6407 Handled_Statement_Sequence =>
6408 Make_Handled_Sequence_Of_Statements (Loc,
6409 Statements => New_List (
6410 Make_Implicit_Label_Declaration (Loc,
6411 Defining_Identifier =>
6416 Exception_Handlers => Hdle)));
6418 -- Create new call statement
6420 Params := Parameter_Associations (Call);
6423 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6425 New_Reference_To (B, Loc));
6428 Make_Procedure_Call_Statement (Loc,
6430 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6431 Parameter_Associations => Params));
6433 -- Construct statement sequence for new block
6436 Make_Implicit_If_Statement (N,
6439 New_Reference_To (Cancel_Param, Loc)),
6440 Then_Statements => Tstats));
6442 -- Protected the call against abort
6445 Make_Procedure_Call_Statement (Loc,
6446 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6447 Parameter_Associations => Empty_List));
6450 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6452 -- The result is the new block
6455 Make_Block_Statement (Loc,
6456 Declarations => Decls,
6457 Handled_Statement_Sequence =>
6458 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6461 end Expand_N_Asynchronous_Select;
6463 -------------------------------------
6464 -- Expand_N_Conditional_Entry_Call --
6465 -------------------------------------
6467 -- The conditional task entry call is converted to a call to
6472 -- P : parms := (parm, parm, parm);
6476 -- (<acceptor-task>, -- Acceptor
6477 -- <entry-index>, -- E
6478 -- P'Address, -- Uninterpreted_Data
6479 -- Conditional_Call, -- Mode
6480 -- B); -- Rendezvous_Successful
6485 -- normal-statements
6491 -- For a description of the use of P and the assignments after the call,
6492 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6493 -- conditional entry call has already been expanded (by the Expand_N_Entry
6494 -- _Call_Statement procedure) as follows:
6497 -- P : parms := (parm, parm, parm);
6499 -- ... info for in-out parameters
6500 -- Call_Simple (acceptor-task, entry-index, P'Address);
6506 -- so the task at hand is to convert the latter expansion into the former
6508 -- The conditional protected entry call is converted to a call to
6509 -- Protected_Entry_Call:
6512 -- P : parms := (parm, parm, parm);
6513 -- Bnn : Communications_Block;
6516 -- Protected_Entry_Call
6517 -- (po._object'Access, -- Object
6518 -- <entry index>, -- E
6519 -- P'Address, -- Uninterpreted_Data
6520 -- Conditional_Call, -- Mode
6525 -- if Cancelled (Bnn) then
6528 -- normal-statements
6532 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6536 -- B : Boolean := False;
6537 -- C : Ada.Tags.Prim_Op_Kind;
6538 -- K : Ada.Tags.Tagged_Kind :=
6539 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6540 -- P : Parameters := (Param1 .. ParamN);
6544 -- if K = Ada.Tags.TK_Limited_Tagged then
6545 -- <dispatching-call>;
6546 -- <triggering-statements>
6550 -- Ada.Tags.Get_Offset_Index
6551 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6553 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6555 -- if C = POK_Protected_Entry
6556 -- or else C = POK_Task_Entry
6558 -- Param1 := P.Param1;
6560 -- ParamN := P.ParamN;
6564 -- if C = POK_Procedure
6565 -- or else C = POK_Protected_Procedure
6566 -- or else C = POK_Task_Procedure
6568 -- <dispatching-call>;
6571 -- <triggering-statements>
6573 -- <else-statements>
6578 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6579 Loc : constant Source_Ptr := Sloc (N);
6580 Alt : constant Node_Id := Entry_Call_Alternative (N);
6581 Blk : Node_Id := Entry_Call_Statement (Alt);
6584 Blk_Typ : Entity_Id;
6586 Call_Ent : Entity_Id;
6587 Conc_Typ_Stmts : List_Id;
6591 Lim_Typ_Stmts : List_Id;
6598 Transient_Blk : Node_Id;
6601 B : Entity_Id; -- Call status flag
6602 C : Entity_Id; -- Call kind
6603 K : Entity_Id; -- Tagged kind
6604 P : Entity_Id; -- Parameter block
6605 S : Entity_Id; -- Primitive operation slot
6608 if Ada_Version >= Ada_05
6609 and then Nkind (Blk) = N_Procedure_Call_Statement
6611 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6616 -- Call status flag processing, generate:
6617 -- B : Boolean := False;
6619 B := Build_B (Loc, Decls);
6621 -- Call kind processing, generate:
6622 -- C : Ada.Tags.Prim_Op_Kind;
6624 C := Build_C (Loc, Decls);
6626 -- Tagged kind processing, generate:
6627 -- K : Ada.Tags.Tagged_Kind :=
6628 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6630 K := Build_K (Loc, Decls, Obj);
6632 -- Parameter block processing
6634 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6635 P := Parameter_Block_Pack
6636 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6638 -- Dispatch table slot processing, generate:
6641 S := Build_S (Loc, Decls);
6644 -- S := Ada.Tags.Get_Offset_Index
6645 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6648 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6651 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6653 Append_To (Conc_Typ_Stmts,
6654 Make_Procedure_Call_Statement (Loc,
6657 Find_Prim_Op (Etype (Etype (Obj)),
6658 Name_uDisp_Conditional_Select),
6660 Parameter_Associations =>
6662 New_Copy_Tree (Obj), -- <object>
6663 New_Reference_To (S, Loc), -- S
6664 Make_Attribute_Reference (Loc, -- P'Address
6666 New_Reference_To (P, Loc),
6669 New_Reference_To (C, Loc), -- C
6670 New_Reference_To (B, Loc)))); -- B
6673 -- if C = POK_Protected_Entry
6674 -- or else C = POK_Task_Entry
6676 -- Param1 := P.Param1;
6678 -- ParamN := P.ParamN;
6681 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6683 -- Generate the if statement only when the packed parameters need
6684 -- explicit assignments to their corresponding actuals.
6686 if Present (Unpack) then
6687 Append_To (Conc_Typ_Stmts,
6688 Make_If_Statement (Loc,
6695 New_Reference_To (C, Loc),
6697 New_Reference_To (RTE (
6698 RE_POK_Protected_Entry), Loc)),
6702 New_Reference_To (C, Loc),
6704 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6712 -- if C = POK_Procedure
6713 -- or else C = POK_Protected_Procedure
6714 -- or else C = POK_Task_Procedure
6716 -- <dispatching-call>
6718 -- <normal-statements>
6720 -- <else-statements>
6723 N_Stats := New_Copy_List_Tree (Statements (Alt));
6725 Prepend_To (N_Stats,
6726 Make_If_Statement (Loc,
6732 New_Reference_To (C, Loc),
6734 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6741 New_Reference_To (C, Loc),
6743 New_Reference_To (RTE (
6744 RE_POK_Protected_Procedure), Loc)),
6749 New_Reference_To (C, Loc),
6751 New_Reference_To (RTE (
6752 RE_POK_Task_Procedure), Loc)))),
6757 Append_To (Conc_Typ_Stmts,
6758 Make_If_Statement (Loc,
6759 Condition => New_Reference_To (B, Loc),
6760 Then_Statements => N_Stats,
6761 Else_Statements => Else_Statements (N)));
6764 -- <dispatching-call>;
6765 -- <triggering-statements>
6767 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6768 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6771 -- if K = Ada.Tags.TK_Limited_Tagged then
6778 Make_If_Statement (Loc,
6782 New_Reference_To (K, Loc),
6784 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6793 Make_Block_Statement (Loc,
6796 Handled_Statement_Sequence =>
6797 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6799 -- As described above, The entry alternative is transformed into a
6800 -- block that contains the gnulli call, and possibly assignment
6801 -- statements for in-out parameters. The gnulli call may itself be
6802 -- rewritten into a transient block if some unconstrained parameters
6803 -- require it. We need to retrieve the call to complete its parameter
6808 First_Real_Statement (Handled_Statement_Sequence (Blk));
6810 if Present (Transient_Blk)
6811 and then Nkind (Transient_Blk) = N_Block_Statement
6813 Blk := Transient_Blk;
6816 Stmts := Statements (Handled_Statement_Sequence (Blk));
6817 Stmt := First (Stmts);
6818 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6823 Params := Parameter_Associations (Call);
6825 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6827 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6829 Param := First (Params);
6830 while Present (Param)
6831 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6836 pragma Assert (Present (Param));
6837 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6841 -- Find the Communication_Block parameter for the call to the
6842 -- Cancelled function.
6844 Decl := First (Declarations (Blk));
6845 while Present (Decl)
6846 and then not Is_RTE (Etype (Object_Definition (Decl)),
6847 RE_Communication_Block)
6852 -- Add an if statement to execute the else part if the call
6853 -- does not succeed (as indicated by the Cancelled predicate).
6856 Make_Implicit_If_Statement (N,
6857 Condition => Make_Function_Call (Loc,
6858 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6859 Parameter_Associations => New_List (
6860 New_Reference_To (Defining_Identifier (Decl), Loc))),
6861 Then_Statements => Else_Statements (N),
6862 Else_Statements => Statements (Alt)));
6865 B := Make_Defining_Identifier (Loc, Name_uB);
6867 -- Insert declaration of B in declarations of existing block
6869 if No (Declarations (Blk)) then
6870 Set_Declarations (Blk, New_List);
6873 Prepend_To (Declarations (Blk),
6874 Make_Object_Declaration (Loc,
6875 Defining_Identifier => B,
6876 Object_Definition =>
6877 New_Reference_To (Standard_Boolean, Loc)));
6879 -- Create new call statement
6882 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6883 Append_To (Params, New_Reference_To (B, Loc));
6886 Make_Procedure_Call_Statement (Loc,
6887 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6888 Parameter_Associations => Params));
6890 -- Construct statement sequence for new block
6893 Make_Implicit_If_Statement (N,
6894 Condition => New_Reference_To (B, Loc),
6895 Then_Statements => Statements (Alt),
6896 Else_Statements => Else_Statements (N)));
6899 -- The result is the new block
6902 Make_Block_Statement (Loc,
6903 Declarations => Declarations (Blk),
6904 Handled_Statement_Sequence =>
6905 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6909 end Expand_N_Conditional_Entry_Call;
6911 ---------------------------------------
6912 -- Expand_N_Delay_Relative_Statement --
6913 ---------------------------------------
6915 -- Delay statement is implemented as a procedure call to Delay_For
6916 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6917 -- simple delays imposed by the use of Protected Objects.
6919 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6920 Loc : constant Source_Ptr := Sloc (N);
6923 Make_Procedure_Call_Statement (Loc,
6924 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6925 Parameter_Associations => New_List (Expression (N))));
6927 end Expand_N_Delay_Relative_Statement;
6929 ------------------------------------
6930 -- Expand_N_Delay_Until_Statement --
6931 ------------------------------------
6933 -- Delay Until statement is implemented as a procedure call to
6934 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6936 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6937 Loc : constant Source_Ptr := Sloc (N);
6941 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6942 Typ := RTE (RO_CA_Delay_Until);
6944 Typ := RTE (RO_RT_Delay_Until);
6948 Make_Procedure_Call_Statement (Loc,
6949 Name => New_Reference_To (Typ, Loc),
6950 Parameter_Associations => New_List (Expression (N))));
6953 end Expand_N_Delay_Until_Statement;
6955 -------------------------
6956 -- Expand_N_Entry_Body --
6957 -------------------------
6959 procedure Expand_N_Entry_Body (N : Node_Id) is
6961 -- Associate discriminals with the next protected operation body to be
6964 if Present (Next_Protected_Operation (N)) then
6965 Set_Discriminals (Parent (Current_Scope));
6967 end Expand_N_Entry_Body;
6969 -----------------------------------
6970 -- Expand_N_Entry_Call_Statement --
6971 -----------------------------------
6973 -- An entry call is expanded into GNARLI calls to implement a simple entry
6974 -- call (see Build_Simple_Entry_Call).
6976 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
6982 if No_Run_Time_Mode then
6983 Error_Msg_CRT ("entry call", N);
6987 -- If this entry call is part of an asynchronous select, don't expand it
6988 -- here; it will be expanded with the select statement. Don't expand
6989 -- timed entry calls either, as they are translated into asynchronous
6992 -- ??? This whole approach is questionable; it may be better to go back
6993 -- to allowing the expansion to take place and then attempting to fix it
6994 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6995 -- whether the expanded call is on a task or protected entry.
6997 if (Nkind (Parent (N)) /= N_Triggering_Alternative
6998 or else N /= Triggering_Statement (Parent (N)))
6999 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7000 or else N /= Entry_Call_Statement (Parent (N))
7001 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7003 Extract_Entry (N, Concval, Ename, Index);
7004 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7006 end Expand_N_Entry_Call_Statement;
7008 --------------------------------
7009 -- Expand_N_Entry_Declaration --
7010 --------------------------------
7012 -- If there are parameters, then first, each of the formals is marked by
7013 -- setting Is_Entry_Formal. Next a record type is built which is used to
7014 -- hold the parameter values. The name of this record type is entryP where
7015 -- entry is the name of the entry, with an additional corresponding access
7016 -- type called entryPA. The record type has matching components for each
7017 -- formal (the component names are the same as the formal names). For
7018 -- elementary types, the component type matches the formal type. For
7019 -- composite types, an access type is declared (with the name formalA)
7020 -- which designates the formal type, and the type of the component is this
7021 -- access type. Finally the Entry_Component of each formal is set to
7022 -- reference the corresponding record component.
7024 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7025 Loc : constant Source_Ptr := Sloc (N);
7026 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7027 Components : List_Id;
7030 Last_Decl : Node_Id;
7031 Component : Entity_Id;
7034 Rec_Ent : Entity_Id;
7035 Acc_Ent : Entity_Id;
7038 Formal := First_Formal (Entry_Ent);
7041 -- Most processing is done only if parameters are present
7043 if Present (Formal) then
7044 Components := New_List;
7046 -- Loop through formals
7048 while Present (Formal) loop
7049 Set_Is_Entry_Formal (Formal);
7051 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7052 Set_Entry_Component (Formal, Component);
7053 Set_Entry_Formal (Component, Formal);
7054 Ftype := Etype (Formal);
7056 -- Declare new access type and then append
7058 Ctype := Make_Temporary (Loc, 'A');
7061 Make_Full_Type_Declaration (Loc,
7062 Defining_Identifier => Ctype,
7064 Make_Access_To_Object_Definition (Loc,
7065 All_Present => True,
7066 Constant_Present => Ekind (Formal) = E_In_Parameter,
7067 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7069 Insert_After (Last_Decl, Decl);
7072 Append_To (Components,
7073 Make_Component_Declaration (Loc,
7074 Defining_Identifier => Component,
7075 Component_Definition =>
7076 Make_Component_Definition (Loc,
7077 Aliased_Present => False,
7078 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7080 Next_Formal_With_Extras (Formal);
7083 -- Create the Entry_Parameter_Record declaration
7085 Rec_Ent := Make_Temporary (Loc, 'P');
7088 Make_Full_Type_Declaration (Loc,
7089 Defining_Identifier => Rec_Ent,
7091 Make_Record_Definition (Loc,
7093 Make_Component_List (Loc,
7094 Component_Items => Components)));
7096 Insert_After (Last_Decl, Decl);
7099 -- Construct and link in the corresponding access type
7101 Acc_Ent := Make_Temporary (Loc, 'A');
7103 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7106 Make_Full_Type_Declaration (Loc,
7107 Defining_Identifier => Acc_Ent,
7109 Make_Access_To_Object_Definition (Loc,
7110 All_Present => True,
7111 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7113 Insert_After (Last_Decl, Decl);
7116 end Expand_N_Entry_Declaration;
7118 -----------------------------
7119 -- Expand_N_Protected_Body --
7120 -----------------------------
7122 -- Protected bodies are expanded to the completion of the subprograms
7123 -- created for the corresponding protected type. These are a protected and
7124 -- unprotected version of each protected subprogram in the object, a
7125 -- function to calculate each entry barrier, and a procedure to execute the
7126 -- sequence of statements of each protected entry body. For example, for
7127 -- protected type ptype:
7130 -- (O : System.Address;
7131 -- E : Protected_Entry_Index)
7134 -- <discriminant renamings>
7135 -- <private object renamings>
7137 -- return <barrier expression>;
7140 -- procedure pprocN (_object : in out poV;...) is
7141 -- <discriminant renamings>
7142 -- <private object renamings>
7144 -- <sequence of statements>
7147 -- procedure pprocP (_object : in out poV;...) is
7148 -- procedure _clean is
7151 -- ptypeS (_object, Pn);
7152 -- Unlock (_object._object'Access);
7153 -- Abort_Undefer.all;
7158 -- Lock (_object._object'Access);
7159 -- pprocN (_object;...);
7164 -- function pfuncN (_object : poV;...) return Return_Type is
7165 -- <discriminant renamings>
7166 -- <private object renamings>
7168 -- <sequence of statements>
7171 -- function pfuncP (_object : poV) return Return_Type is
7172 -- procedure _clean is
7174 -- Unlock (_object._object'Access);
7175 -- Abort_Undefer.all;
7180 -- Lock (_object._object'Access);
7181 -- return pfuncN (_object);
7188 -- (O : System.Address;
7189 -- P : System.Address;
7190 -- E : Protected_Entry_Index)
7192 -- <discriminant renamings>
7193 -- <private object renamings>
7194 -- type poVP is access poV;
7195 -- _Object : ptVP := ptVP!(O);
7199 -- <statement sequence>
7200 -- Complete_Entry_Body (_Object._Object);
7202 -- when all others =>
7203 -- Exceptional_Complete_Entry_Body (
7204 -- _Object._Object, Get_GNAT_Exception);
7208 -- The type poV is the record created for the protected type to hold
7209 -- the state of the protected object.
7211 procedure Expand_N_Protected_Body (N : Node_Id) is
7212 Loc : constant Source_Ptr := Sloc (N);
7213 Pid : constant Entity_Id := Corresponding_Spec (N);
7215 Current_Node : Node_Id;
7216 Disp_Op_Body : Node_Id;
7217 New_Op_Body : Node_Id;
7218 Num_Entries : Natural := 0;
7222 Chain : Entity_Id := Empty;
7223 -- Finalization chain that may be attached to new body
7225 function Build_Dispatching_Subprogram_Body
7228 Prot_Bod : Node_Id) return Node_Id;
7229 -- Build a dispatching version of the protected subprogram body. The
7230 -- newly generated subprogram contains a call to the original protected
7231 -- body. The following code is generated:
7233 -- function <protected-function-name> (Param1 .. ParamN) return
7236 -- return <protected-function-name>P (Param1 .. ParamN);
7237 -- end <protected-function-name>;
7241 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7243 -- <protected-procedure-name>P (Param1 .. ParamN);
7244 -- end <protected-procedure-name>
7246 ---------------------------------------
7247 -- Build_Dispatching_Subprogram_Body --
7248 ---------------------------------------
7250 function Build_Dispatching_Subprogram_Body
7253 Prot_Bod : Node_Id) return Node_Id
7255 Loc : constant Source_Ptr := Sloc (N);
7262 -- Generate a specification without a letter suffix in order to
7263 -- override an interface function or procedure.
7266 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7268 -- The formal parameters become the actuals of the protected
7269 -- function or procedure call.
7271 Actuals := New_List;
7272 Formal := First (Parameter_Specifications (Spec));
7273 while Present (Formal) loop
7275 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7280 if Nkind (Spec) = N_Procedure_Specification then
7283 Make_Procedure_Call_Statement (Loc,
7285 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7286 Parameter_Associations => Actuals));
7288 pragma Assert (Nkind (Spec) = N_Function_Specification);
7292 Make_Simple_Return_Statement (Loc,
7294 Make_Function_Call (Loc,
7296 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7297 Parameter_Associations => Actuals)));
7301 Make_Subprogram_Body (Loc,
7302 Declarations => Empty_List,
7303 Specification => Spec,
7304 Handled_Statement_Sequence =>
7305 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7306 end Build_Dispatching_Subprogram_Body;
7308 -- Start of processing for Expand_N_Protected_Body
7311 if No_Run_Time_Mode then
7312 Error_Msg_CRT ("protected body", N);
7316 -- This is the proper body corresponding to a stub. The declarations
7317 -- must be inserted at the point of the stub, which in turn is in the
7318 -- declarative part of the parent unit.
7320 if Nkind (Parent (N)) = N_Subunit then
7321 Current_Node := Corresponding_Stub (Parent (N));
7326 Op_Body := First (Declarations (N));
7328 -- The protected body is replaced with the bodies of its
7329 -- protected operations, and the declarations for internal objects
7330 -- that may have been created for entry family bounds.
7332 Rewrite (N, Make_Null_Statement (Sloc (N)));
7335 while Present (Op_Body) loop
7336 case Nkind (Op_Body) is
7337 when N_Subprogram_Declaration =>
7340 when N_Subprogram_Body =>
7342 -- Do not create bodies for eliminated operations
7344 if not Is_Eliminated (Defining_Entity (Op_Body))
7345 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7348 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7350 -- Propagate the finalization chain to the new body. In the
7351 -- unlikely event that the subprogram contains a declaration
7352 -- or allocator for an object that requires finalization,
7353 -- the corresponding chain is created when analyzing the
7354 -- body, and attached to its entity. This entity is not
7355 -- further elaborated, and so the chain properly belongs to
7356 -- the newly created subprogram body.
7359 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7361 if Present (Chain) then
7362 Set_Finalization_Chain_Entity
7363 (Protected_Body_Subprogram
7364 (Corresponding_Spec (Op_Body)), Chain);
7366 (Handled_Statement_Sequence (New_Op_Body), False);
7369 Insert_After (Current_Node, New_Op_Body);
7370 Current_Node := New_Op_Body;
7371 Analyze (New_Op_Body);
7373 -- Build the corresponding protected operation. It may
7374 -- appear that this is needed only if this is a visible
7375 -- operation of the type, or if it is an interrupt handler,
7376 -- and this was the strategy used previously in GNAT.
7377 -- However, the operation may be exported through a 'Access
7378 -- to an external caller. This is the common idiom in code
7379 -- that uses the Ada 2005 Timing_Events package. As a result
7380 -- we need to produce the protected body for both visible
7381 -- and private operations, as well as operations that only
7382 -- have a body in the source, and for which we create a
7383 -- declaration in the protected body itself.
7385 if Present (Corresponding_Spec (Op_Body)) then
7387 Build_Protected_Subprogram_Body (
7388 Op_Body, Pid, Specification (New_Op_Body));
7390 Insert_After (Current_Node, New_Op_Body);
7391 Analyze (New_Op_Body);
7393 Current_Node := New_Op_Body;
7395 -- Generate an overriding primitive operation body for
7396 -- this subprogram if the protected type implements an
7399 if Ada_Version >= Ada_05
7401 Present (Interfaces (Corresponding_Record_Type (Pid)))
7404 Build_Dispatching_Subprogram_Body
7405 (Op_Body, Pid, New_Op_Body);
7407 Insert_After (Current_Node, Disp_Op_Body);
7408 Analyze (Disp_Op_Body);
7410 Current_Node := Disp_Op_Body;
7415 when N_Entry_Body =>
7416 Op_Id := Defining_Identifier (Op_Body);
7417 Num_Entries := Num_Entries + 1;
7419 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7421 Insert_After (Current_Node, New_Op_Body);
7422 Current_Node := New_Op_Body;
7423 Analyze (New_Op_Body);
7425 when N_Implicit_Label_Declaration =>
7428 when N_Itype_Reference =>
7429 Insert_After (Current_Node, New_Copy (Op_Body));
7431 when N_Freeze_Entity =>
7432 New_Op_Body := New_Copy (Op_Body);
7434 if Present (Entity (Op_Body))
7435 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7437 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7440 Insert_After (Current_Node, New_Op_Body);
7441 Current_Node := New_Op_Body;
7442 Analyze (New_Op_Body);
7445 New_Op_Body := New_Copy (Op_Body);
7446 Insert_After (Current_Node, New_Op_Body);
7447 Current_Node := New_Op_Body;
7448 Analyze (New_Op_Body);
7450 when N_Object_Declaration =>
7451 pragma Assert (not Comes_From_Source (Op_Body));
7452 New_Op_Body := New_Copy (Op_Body);
7453 Insert_After (Current_Node, New_Op_Body);
7454 Current_Node := New_Op_Body;
7455 Analyze (New_Op_Body);
7458 raise Program_Error;
7465 -- Finally, create the body of the function that maps an entry index
7466 -- into the corresponding body index, except when there is no entry, or
7467 -- in a Ravenscar-like profile.
7469 if Corresponding_Runtime_Package (Pid) =
7470 System_Tasking_Protected_Objects_Entries
7472 New_Op_Body := Build_Find_Body_Index (Pid);
7473 Insert_After (Current_Node, New_Op_Body);
7474 Current_Node := New_Op_Body;
7475 Analyze (New_Op_Body);
7478 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7479 -- protected body. At this point all wrapper specs have been created,
7480 -- frozen and included in the dispatch table for the protected type.
7482 if Ada_Version >= Ada_05 then
7483 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7485 end Expand_N_Protected_Body;
7487 -----------------------------------------
7488 -- Expand_N_Protected_Type_Declaration --
7489 -----------------------------------------
7491 -- First we create a corresponding record type declaration used to
7492 -- represent values of this protected type.
7493 -- The general form of this type declaration is
7495 -- type poV (discriminants) is record
7496 -- _Object : aliased <kind>Protection
7497 -- [(<entry count> [, <handler count>])];
7498 -- [entry_family : array (bounds) of Void;]
7499 -- <private data fields>
7502 -- The discriminants are present only if the corresponding protected type
7503 -- has discriminants, and they exactly mirror the protected type
7504 -- discriminants. The private data fields similarly mirror the private
7505 -- declarations of the protected type.
7507 -- The Object field is always present. It contains RTS specific data used
7508 -- to control the protected object. It is declared as Aliased so that it
7509 -- can be passed as a pointer to the RTS. This allows the protected record
7510 -- to be referenced within RTS data structures. An appropriate Protection
7511 -- type and discriminant are generated.
7513 -- The Service field is present for protected objects with entries. It
7514 -- contains sufficient information to allow the entry service procedure for
7515 -- this object to be called when the object is not known till runtime.
7517 -- One entry_family component is present for each entry family in the
7518 -- task definition (see Expand_N_Task_Type_Declaration).
7520 -- When a protected object is declared, an instance of the protected type
7521 -- value record is created. The elaboration of this declaration creates the
7522 -- correct bounds for the entry families, and also evaluates the priority
7523 -- expression if needed. The initialization routine for the protected type
7524 -- itself then calls Initialize_Protection with appropriate parameters to
7525 -- initialize the value of the Task_Id field. Install_Handlers may be also
7526 -- called if a pragma Attach_Handler applies.
7528 -- Note: this record is passed to the subprograms created by the expansion
7529 -- of protected subprograms and entries. It is an in parameter to protected
7530 -- functions and an in out parameter to procedures and entry bodies. The
7531 -- Entity_Id for this created record type is placed in the
7532 -- Corresponding_Record_Type field of the associated protected type entity.
7534 -- Next we create a procedure specifications for protected subprograms and
7535 -- entry bodies. For each protected subprograms two subprograms are
7536 -- created, an unprotected and a protected version. The unprotected version
7537 -- is called from within other operations of the same protected object.
7539 -- We also build the call to register the procedure if a pragma
7540 -- Interrupt_Handler applies.
7542 -- A single subprogram is created to service all entry bodies; it has an
7543 -- additional boolean out parameter indicating that the previous entry call
7544 -- made by the current task was serviced immediately, i.e. not by proxy.
7545 -- The O parameter contains a pointer to a record object of the type
7546 -- described above. An untyped interface is used here to allow this
7547 -- procedure to be called in places where the type of the object to be
7548 -- serviced is not known. This must be done, for example, when a call that
7549 -- may have been requeued is cancelled; the corresponding object must be
7550 -- serviced, but which object that is not known till runtime.
7553 -- (O : System.Address; P : out Boolean);
7554 -- procedure pprocN (_object : in out poV);
7555 -- procedure pproc (_object : in out poV);
7556 -- function pfuncN (_object : poV);
7557 -- function pfunc (_object : poV);
7560 -- Note that this must come after the record type declaration, since
7561 -- the specs refer to this type.
7563 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7564 Loc : constant Source_Ptr := Sloc (N);
7565 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7567 Pdef : constant Node_Id := Protected_Definition (N);
7568 -- This contains two lists; one for visible and one for private decls
7572 Discr_Map : constant Elist_Id := New_Elmt_List;
7576 Comp_Id : Entity_Id;
7578 Current_Node : Node_Id := N;
7579 Bdef : Entity_Id := Empty; -- avoid uninit warning
7580 Edef : Entity_Id := Empty; -- avoid uninit warning
7581 Entries_Aggr : Node_Id;
7582 Body_Id : Entity_Id;
7585 Object_Comp : Node_Id;
7587 procedure Check_Inlining (Subp : Entity_Id);
7588 -- If the original operation has a pragma Inline, propagate the flag
7589 -- to the internal body, for possible inlining later on. The source
7590 -- operation is invisible to the back-end and is never actually called.
7592 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7593 -- When compiling under the Ravenscar profile, private components must
7594 -- have a static size, or else a protected object will require heap
7595 -- allocation, violating the corresponding restriction. It is preferable
7596 -- to make this check here, because it provides a better error message
7597 -- than the back-end, which refers to the object as a whole.
7599 procedure Register_Handler;
7600 -- For a protected operation that is an interrupt handler, add the
7601 -- freeze action that will register it as such.
7603 --------------------
7604 -- Check_Inlining --
7605 --------------------
7607 procedure Check_Inlining (Subp : Entity_Id) is
7609 if Is_Inlined (Subp) then
7610 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7611 Set_Is_Inlined (Subp, False);
7615 ---------------------------------
7616 -- Check_Static_Component_Size --
7617 ---------------------------------
7619 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7620 Typ : constant Entity_Id := Etype (Comp);
7624 if Is_Scalar_Type (Typ) then
7627 elsif Is_Array_Type (Typ) then
7628 return Compile_Time_Known_Bounds (Typ);
7630 elsif Is_Record_Type (Typ) then
7631 C := First_Component (Typ);
7632 while Present (C) loop
7633 if not Static_Component_Size (C) then
7642 -- Any other types will be checked by the back-end
7647 end Static_Component_Size;
7649 ----------------------
7650 -- Register_Handler --
7651 ----------------------
7653 procedure Register_Handler is
7655 -- All semantic checks already done in Sem_Prag
7657 Prot_Proc : constant Entity_Id :=
7659 (Specification (Current_Node));
7661 Proc_Address : constant Node_Id :=
7662 Make_Attribute_Reference (Loc,
7663 Prefix => New_Reference_To (Prot_Proc, Loc),
7664 Attribute_Name => Name_Address);
7666 RTS_Call : constant Entity_Id :=
7667 Make_Procedure_Call_Statement (Loc,
7670 RTE (RE_Register_Interrupt_Handler), Loc),
7671 Parameter_Associations =>
7672 New_List (Proc_Address));
7674 Append_Freeze_Action (Prot_Proc, RTS_Call);
7675 end Register_Handler;
7677 -- Start of processing for Expand_N_Protected_Type_Declaration
7680 if Present (Corresponding_Record_Type (Prot_Typ)) then
7683 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7686 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7688 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7689 -- of implemented interfaces.
7691 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
7693 Qualify_Entity_Names (N);
7695 -- If the type has discriminants, their occurrences in the declaration
7696 -- have been replaced by the corresponding discriminals. For components
7697 -- that are constrained by discriminants, their homologues in the
7698 -- corresponding record type must refer to the discriminants of that
7699 -- record, so we must apply a new renaming to subtypes_indications:
7701 -- protected discriminant => discriminal => record discriminant
7703 -- This replacement is not applied to default expressions, for which
7704 -- the discriminal is correct.
7706 if Has_Discriminants (Prot_Typ) then
7712 Disc := First_Discriminant (Prot_Typ);
7713 Decl := First (Discriminant_Specifications (Rec_Decl));
7714 while Present (Disc) loop
7715 Append_Elmt (Discriminal (Disc), Discr_Map);
7716 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7717 Next_Discriminant (Disc);
7723 -- Fill in the component declarations
7725 -- Add components for entry families. For each entry family, create an
7726 -- anonymous type declaration with the same size, and analyze the type.
7728 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7730 -- Prepend the _Object field with the right type to the component list.
7731 -- We need to compute the number of entries, and in some cases the
7732 -- number of Attach_Handler pragmas.
7736 Num_Attach_Handler : Int := 0;
7737 Protection_Subtype : Node_Id;
7738 Entry_Count_Expr : constant Node_Id :=
7739 Build_Entry_Count_Expression
7740 (Prot_Typ, Cdecls, Loc);
7743 -- Could this be simplified using Corresponding_Runtime_Package???
7745 if Has_Attach_Handler (Prot_Typ) then
7746 Ritem := First_Rep_Item (Prot_Typ);
7747 while Present (Ritem) loop
7748 if Nkind (Ritem) = N_Pragma
7749 and then Pragma_Name (Ritem) = Name_Attach_Handler
7751 Num_Attach_Handler := Num_Attach_Handler + 1;
7754 Next_Rep_Item (Ritem);
7757 if Restricted_Profile then
7758 if Has_Entries (Prot_Typ) then
7759 Protection_Subtype :=
7760 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7762 Protection_Subtype :=
7763 New_Reference_To (RTE (RE_Protection), Loc);
7766 Protection_Subtype :=
7767 Make_Subtype_Indication
7771 (RTE (RE_Static_Interrupt_Protection), Loc),
7773 Make_Index_Or_Discriminant_Constraint (
7775 Constraints => New_List (
7777 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7780 elsif Has_Interrupt_Handler (Prot_Typ) then
7781 Protection_Subtype :=
7782 Make_Subtype_Indication (
7784 Subtype_Mark => New_Reference_To
7785 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7787 Make_Index_Or_Discriminant_Constraint (
7789 Constraints => New_List (Entry_Count_Expr)));
7791 -- Type has explicit entries or generated primitive entry wrappers
7793 elsif Has_Entries (Prot_Typ)
7794 or else (Ada_Version >= Ada_05
7795 and then Present (Interface_List (N)))
7797 case Corresponding_Runtime_Package (Prot_Typ) is
7798 when System_Tasking_Protected_Objects_Entries =>
7799 Protection_Subtype :=
7800 Make_Subtype_Indication (Loc,
7802 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7804 Make_Index_Or_Discriminant_Constraint (
7806 Constraints => New_List (Entry_Count_Expr)));
7808 when System_Tasking_Protected_Objects_Single_Entry =>
7809 Protection_Subtype :=
7810 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7813 raise Program_Error;
7817 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7821 Make_Component_Declaration (Loc,
7822 Defining_Identifier =>
7823 Make_Defining_Identifier (Loc, Name_uObject),
7824 Component_Definition =>
7825 Make_Component_Definition (Loc,
7826 Aliased_Present => True,
7827 Subtype_Indication => Protection_Subtype));
7830 pragma Assert (Present (Pdef));
7832 -- Add private field components
7834 if Present (Private_Declarations (Pdef)) then
7835 Priv := First (Private_Declarations (Pdef));
7837 while Present (Priv) loop
7839 if Nkind (Priv) = N_Component_Declaration then
7840 if not Static_Component_Size (Defining_Identifier (Priv)) then
7842 -- When compiling for a restricted profile, the private
7843 -- components must have a static size. If not, this is an
7844 -- error for a single protected declaration, and rates a
7845 -- warning on a protected type declaration.
7847 if not Comes_From_Source (Prot_Typ) then
7848 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
7850 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
7851 Error_Msg_N ("component has non-static size?", Priv);
7853 ("\creation of protected object of type& will violate"
7854 & " restriction No_Implicit_Heap_Allocations?",
7859 -- The component definition consists of a subtype indication,
7860 -- or (in Ada 2005) an access definition. Make a copy of the
7861 -- proper definition.
7864 Old_Comp : constant Node_Id := Component_Definition (Priv);
7865 Oent : constant Entity_Id := Defining_Identifier (Priv);
7867 Nent : constant Entity_Id :=
7868 Make_Defining_Identifier (Sloc (Oent),
7869 Chars => Chars (Oent));
7872 if Present (Subtype_Indication (Old_Comp)) then
7874 Make_Component_Definition (Sloc (Oent),
7875 Aliased_Present => False,
7876 Subtype_Indication =>
7877 New_Copy_Tree (Subtype_Indication (Old_Comp),
7881 Make_Component_Definition (Sloc (Oent),
7882 Aliased_Present => False,
7883 Access_Definition =>
7884 New_Copy_Tree (Access_Definition (Old_Comp),
7889 Make_Component_Declaration (Loc,
7890 Defining_Identifier => Nent,
7891 Component_Definition => New_Comp,
7892 Expression => Expression (Priv));
7894 Set_Has_Per_Object_Constraint (Nent,
7895 Has_Per_Object_Constraint (Oent));
7897 Append_To (Cdecls, New_Priv);
7900 elsif Nkind (Priv) = N_Subprogram_Declaration then
7902 -- Make the unprotected version of the subprogram available
7903 -- for expansion of intra object calls. There is need for
7904 -- a protected version only if the subprogram is an interrupt
7905 -- handler, otherwise this operation can only be called from
7909 Make_Subprogram_Declaration (Loc,
7911 Build_Protected_Sub_Specification
7912 (Priv, Prot_Typ, Unprotected_Mode));
7914 Insert_After (Current_Node, Sub);
7917 Set_Protected_Body_Subprogram
7918 (Defining_Unit_Name (Specification (Priv)),
7919 Defining_Unit_Name (Specification (Sub)));
7920 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
7921 Current_Node := Sub;
7924 Make_Subprogram_Declaration (Loc,
7926 Build_Protected_Sub_Specification
7927 (Priv, Prot_Typ, Protected_Mode));
7929 Insert_After (Current_Node, Sub);
7931 Current_Node := Sub;
7933 if Is_Interrupt_Handler
7934 (Defining_Unit_Name (Specification (Priv)))
7936 if not Restricted_Profile then
7946 -- Put the _Object component after the private component so that it
7947 -- be finalized early as required by 9.4 (20)
7949 Append_To (Cdecls, Object_Comp);
7951 Insert_After (Current_Node, Rec_Decl);
7952 Current_Node := Rec_Decl;
7954 -- Analyze the record declaration immediately after construction,
7955 -- because the initialization procedure is needed for single object
7956 -- declarations before the next entity is analyzed (the freeze call
7957 -- that generates this initialization procedure is found below).
7959 Analyze (Rec_Decl, Suppress => All_Checks);
7961 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7962 -- the corresponding record is frozen. If any wrappers are generated,
7963 -- Current_Node is updated accordingly.
7965 if Ada_Version >= Ada_05 then
7966 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
7969 -- Collect pointers to entry bodies and their barriers, to be placed
7970 -- in the Entry_Bodies_Array for the type. For each entry/family we
7971 -- add an expression to the aggregate which is the initial value of
7972 -- this array. The array is declared after all protected subprograms.
7974 if Has_Entries (Prot_Typ) then
7975 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
7977 Entries_Aggr := Empty;
7980 -- Build two new procedure specifications for each protected subprogram;
7981 -- one to call from outside the object and one to call from inside.
7982 -- Build a barrier function and an entry body action procedure
7983 -- specification for each protected entry. Initialize the entry body
7984 -- array. If subprogram is flagged as eliminated, do not generate any
7985 -- internal operations.
7989 Comp := First (Visible_Declarations (Pdef));
7991 while Present (Comp) loop
7992 if Nkind (Comp) = N_Subprogram_Declaration then
7994 Make_Subprogram_Declaration (Loc,
7996 Build_Protected_Sub_Specification
7997 (Comp, Prot_Typ, Unprotected_Mode));
7999 Insert_After (Current_Node, Sub);
8002 Set_Protected_Body_Subprogram
8003 (Defining_Unit_Name (Specification (Comp)),
8004 Defining_Unit_Name (Specification (Sub)));
8005 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8007 -- Make the protected version of the subprogram available for
8008 -- expansion of external calls.
8010 Current_Node := Sub;
8013 Make_Subprogram_Declaration (Loc,
8015 Build_Protected_Sub_Specification
8016 (Comp, Prot_Typ, Protected_Mode));
8018 Insert_After (Current_Node, Sub);
8021 Current_Node := Sub;
8023 -- Generate an overriding primitive operation specification for
8024 -- this subprogram if the protected type implements an interface.
8026 if Ada_Version >= Ada_05
8028 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8031 Make_Subprogram_Declaration (Loc,
8033 Build_Protected_Sub_Specification
8034 (Comp, Prot_Typ, Dispatching_Mode));
8036 Insert_After (Current_Node, Sub);
8039 Current_Node := Sub;
8042 -- If a pragma Interrupt_Handler applies, build and add a call to
8043 -- Register_Interrupt_Handler to the freezing actions of the
8044 -- protected version (Current_Node) of the subprogram:
8046 -- system.interrupts.register_interrupt_handler
8047 -- (prot_procP'address);
8049 if not Restricted_Profile
8050 and then Is_Interrupt_Handler
8051 (Defining_Unit_Name (Specification (Comp)))
8056 elsif Nkind (Comp) = N_Entry_Declaration then
8057 E_Count := E_Count + 1;
8058 Comp_Id := Defining_Identifier (Comp);
8061 Make_Defining_Identifier (Loc,
8062 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8064 Make_Subprogram_Declaration (Loc,
8066 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8068 Insert_After (Current_Node, Sub);
8071 Set_Protected_Body_Subprogram
8072 (Defining_Identifier (Comp),
8073 Defining_Unit_Name (Specification (Sub)));
8075 Current_Node := Sub;
8078 Make_Defining_Identifier (Loc,
8079 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8081 Make_Subprogram_Declaration (Loc,
8083 Build_Barrier_Function_Specification (Loc, Bdef));
8085 Insert_After (Current_Node, Sub);
8087 Set_Protected_Body_Subprogram (Bdef, Bdef);
8088 Set_Barrier_Function (Comp_Id, Bdef);
8089 Set_Scope (Bdef, Scope (Comp_Id));
8090 Current_Node := Sub;
8092 -- Collect pointers to the protected subprogram and the barrier
8093 -- of the current entry, for insertion into Entry_Bodies_Array.
8096 Make_Aggregate (Loc,
8097 Expressions => New_List (
8098 Make_Attribute_Reference (Loc,
8099 Prefix => New_Reference_To (Bdef, Loc),
8100 Attribute_Name => Name_Unrestricted_Access),
8101 Make_Attribute_Reference (Loc,
8102 Prefix => New_Reference_To (Edef, Loc),
8103 Attribute_Name => Name_Unrestricted_Access))),
8104 Expressions (Entries_Aggr));
8111 -- If there are some private entry declarations, expand it as if they
8112 -- were visible entries.
8114 if Present (Private_Declarations (Pdef)) then
8115 Comp := First (Private_Declarations (Pdef));
8116 while Present (Comp) loop
8117 if Nkind (Comp) = N_Entry_Declaration then
8118 E_Count := E_Count + 1;
8119 Comp_Id := Defining_Identifier (Comp);
8122 Make_Defining_Identifier (Loc,
8123 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8125 Make_Subprogram_Declaration (Loc,
8127 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8129 Insert_After (Current_Node, Sub);
8132 Set_Protected_Body_Subprogram
8133 (Defining_Identifier (Comp),
8134 Defining_Unit_Name (Specification (Sub)));
8136 Current_Node := Sub;
8139 Make_Defining_Identifier (Loc,
8140 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8143 Make_Subprogram_Declaration (Loc,
8145 Build_Barrier_Function_Specification (Loc, Bdef));
8147 Insert_After (Current_Node, Sub);
8149 Set_Protected_Body_Subprogram (Bdef, Bdef);
8150 Set_Barrier_Function (Comp_Id, Bdef);
8151 Set_Scope (Bdef, Scope (Comp_Id));
8152 Current_Node := Sub;
8154 -- Collect pointers to the protected subprogram and the barrier
8155 -- of the current entry, for insertion into Entry_Bodies_Array.
8157 Append_To (Expressions (Entries_Aggr),
8158 Make_Aggregate (Loc,
8159 Expressions => New_List (
8160 Make_Attribute_Reference (Loc,
8161 Prefix => New_Reference_To (Bdef, Loc),
8162 Attribute_Name => Name_Unrestricted_Access),
8163 Make_Attribute_Reference (Loc,
8164 Prefix => New_Reference_To (Edef, Loc),
8165 Attribute_Name => Name_Unrestricted_Access))));
8172 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8173 -- all protected subprograms have been collected.
8175 if Has_Entries (Prot_Typ) then
8177 Make_Defining_Identifier (Sloc (Prot_Typ),
8178 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8180 case Corresponding_Runtime_Package (Prot_Typ) is
8181 when System_Tasking_Protected_Objects_Entries =>
8182 Body_Arr := Make_Object_Declaration (Loc,
8183 Defining_Identifier => Body_Id,
8184 Aliased_Present => True,
8185 Object_Definition =>
8186 Make_Subtype_Indication (Loc,
8187 Subtype_Mark => New_Reference_To (
8188 RTE (RE_Protected_Entry_Body_Array), Loc),
8190 Make_Index_Or_Discriminant_Constraint (Loc,
8191 Constraints => New_List (
8193 Make_Integer_Literal (Loc, 1),
8194 Make_Integer_Literal (Loc, E_Count))))),
8195 Expression => Entries_Aggr);
8197 when System_Tasking_Protected_Objects_Single_Entry =>
8198 Body_Arr := Make_Object_Declaration (Loc,
8199 Defining_Identifier => Body_Id,
8200 Aliased_Present => True,
8201 Object_Definition => New_Reference_To
8202 (RTE (RE_Entry_Body), Loc),
8204 Make_Aggregate (Loc,
8205 Expressions => New_List (
8206 Make_Attribute_Reference (Loc,
8207 Prefix => New_Reference_To (Bdef, Loc),
8208 Attribute_Name => Name_Unrestricted_Access),
8209 Make_Attribute_Reference (Loc,
8210 Prefix => New_Reference_To (Edef, Loc),
8211 Attribute_Name => Name_Unrestricted_Access))));
8214 raise Program_Error;
8217 -- A pointer to this array will be placed in the corresponding record
8218 -- by its initialization procedure so this needs to be analyzed here.
8220 Insert_After (Current_Node, Body_Arr);
8221 Current_Node := Body_Arr;
8224 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8226 -- Finally, build the function that maps an entry index into the
8227 -- corresponding body. A pointer to this function is placed in each
8228 -- object of the type. Except for a ravenscar-like profile (no abort,
8229 -- no entry queue, 1 entry)
8231 if Corresponding_Runtime_Package (Prot_Typ) =
8232 System_Tasking_Protected_Objects_Entries
8235 Make_Subprogram_Declaration (Loc,
8236 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8237 Insert_After (Current_Node, Sub);
8241 end Expand_N_Protected_Type_Declaration;
8243 --------------------------------
8244 -- Expand_N_Requeue_Statement --
8245 --------------------------------
8247 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8248 -- operations, depending on the source and destination (task or protected
8249 -- object). A dispatching requeue statement is expanded into a call to the
8250 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8251 -- jump around the remainder of processing for the original entry and, if
8252 -- the destination is (different) protected object, to attempt to service
8253 -- it. The following illustrates the various cases:
8256 -- (O : System.Address;
8257 -- P : System.Address;
8258 -- E : Protected_Entry_Index)
8260 -- <discriminant renamings>
8261 -- <private object renamings>
8262 -- type poVP is access poV;
8263 -- _object : ptVP := ptVP!(O);
8267 -- <start of statement sequence for entry>
8269 -- -- Requeue from one protected entry body to another protected
8272 -- Requeue_Protected_Entry (
8273 -- _object._object'Access,
8274 -- new._object'Access,
8279 -- <some more of the statement sequence for entry>
8281 -- -- Requeue from an entry body to a task entry
8283 -- Requeue_Protected_To_Task_Entry (
8289 -- <rest of statement sequence for entry>
8290 -- Complete_Entry_Body (_object._object);
8293 -- when all others =>
8294 -- Exceptional_Complete_Entry_Body (
8295 -- _object._object, Get_GNAT_Exception);
8299 -- Requeue of a task entry call to a task entry
8301 -- Accept_Call (E, Ann);
8302 -- <start of statement sequence for accept statement>
8303 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8305 -- <rest of statement sequence for accept statement>
8307 -- Complete_Rendezvous;
8310 -- when all others =>
8311 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8313 -- Requeue of a task entry call to a protected entry
8315 -- Accept_Call (E, Ann);
8316 -- <start of statement sequence for accept statement>
8317 -- Requeue_Task_To_Protected_Entry (
8318 -- new._object'Access,
8323 -- <rest of statement sequence for accept statement>
8325 -- Complete_Rendezvous;
8328 -- when all others =>
8329 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8331 -- Ada 2005 (AI05-0030): Dispatching requeue from protected to interface
8335 -- (O : System.Address;
8336 -- P : System.Address;
8337 -- E : Protected_Entry_Index)
8339 -- <discriminant renamings>
8340 -- <private object renamings>
8341 -- type poVP is access poV;
8342 -- _object : ptVP := ptVP!(O);
8346 -- <start of statement sequence for entry>
8349 -- (<interface class-wide object>,
8352 -- Ada.Tags.Get_Offset_Index
8354 -- <interface dispatch table index of target entry>),
8358 -- <rest of statement sequence for entry>
8359 -- Complete_Entry_Body (_object._object);
8362 -- when all others =>
8363 -- Exceptional_Complete_Entry_Body (
8364 -- _object._object, Get_GNAT_Exception);
8368 -- Ada 2005 (AI05-0030): Dispatching requeue from task to interface
8371 -- Accept_Call (E, Ann);
8372 -- <start of statement sequence for accept statement>
8374 -- (<interface class-wide object>,
8377 -- Ada.Tags.Get_Offset_Index
8379 -- <interface dispatch table index of target entrt>),
8383 -- <rest of statement sequence for accept statement>
8385 -- Complete_Rendezvous;
8388 -- when all others =>
8389 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8391 -- Further details on these expansions can be found in Expand_N_Protected_
8392 -- Body and Expand_N_Accept_Statement.
8394 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8395 Loc : constant Source_Ptr := Sloc (N);
8396 Abortable : Node_Id;
8398 Conc_Typ : Entity_Id;
8403 New_Param : Node_Id;
8404 Old_Typ : Entity_Id;
8407 RTS_Call : Entity_Id;
8408 Self_Param : Node_Id;
8409 Skip_Stat : Node_Id;
8413 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
8415 -- Extract the components of the entry call
8417 Extract_Entry (N, Concval, Ename, Index);
8418 Conc_Typ := Etype (Concval);
8420 -- Examine the scope stack in order to find nearest enclosing protected
8421 -- or task type. This will constitute our invocation source.
8423 Old_Typ := Current_Scope;
8424 while Present (Old_Typ)
8425 and then not Is_Protected_Type (Old_Typ)
8426 and then not Is_Task_Type (Old_Typ)
8428 Old_Typ := Scope (Old_Typ);
8431 -- Generate the parameter list for all cases. The abortable flag is
8432 -- common among dispatching and regular requeue.
8434 Params := New_List (Abortable);
8436 -- Ada 2005 (AI05-0030): We have a dispatching requeue of the form
8437 -- Concval.Ename where the type of Concval is class-wide concurrent
8440 if Ada_Version >= Ada_05
8441 and then Present (Concval)
8442 and then Is_Class_Wide_Type (Conc_Typ)
8443 and then Is_Concurrent_Interface (Conc_Typ)
8445 RTS_Call := Make_Identifier (Loc, Name_uDisp_Requeue);
8448 -- Ada.Tags.Get_Offset_Index
8449 -- (Ada.Tags.Tag (Concval),
8450 -- <interface dispatch table position of Ename>)
8453 Make_Function_Call (Loc,
8455 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8456 Parameter_Associations =>
8458 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8459 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8461 -- Specific actuals for protected to interface class-wide type
8464 if Is_Protected_Type (Old_Typ) then
8466 Make_Attribute_Reference (Loc, -- _object'Address
8468 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8471 Prepend_To (Params, -- True
8472 New_Reference_To (Standard_True, Loc));
8474 -- Specific actuals for task to interface class-wide type requeue
8477 pragma Assert (Is_Task_Type (Old_Typ));
8479 Prepend_To (Params, -- null
8480 New_Reference_To (RTE (RE_Null_Address), Loc));
8481 Prepend_To (Params, -- False
8482 New_Reference_To (Standard_False, Loc));
8485 -- Finally, add the common object parameter
8487 Prepend_To (Params, New_Copy_Tree (Concval));
8489 -- Regular requeue processing
8492 New_Param := Concurrent_Ref (Concval);
8494 -- The index expression is common among all four cases
8497 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8499 if Is_Protected_Type (Old_Typ) then
8501 Make_Attribute_Reference (Loc,
8503 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8505 Name_Unchecked_Access);
8507 -- Protected to protected requeue
8509 if Is_Protected_Type (Conc_Typ) then
8511 New_Reference_To (RTE (RE_Requeue_Protected_Entry), Loc);
8514 Make_Attribute_Reference (Loc,
8518 Name_Unchecked_Access);
8520 -- Protected to task requeue
8523 pragma Assert (Is_Task_Type (Conc_Typ));
8526 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8529 Prepend (New_Param, Params);
8530 Prepend (Self_Param, Params);
8533 pragma Assert (Is_Task_Type (Old_Typ));
8535 -- Task to protected requeue
8537 if Is_Protected_Type (Conc_Typ) then
8540 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8543 Make_Attribute_Reference (Loc,
8547 Name_Unchecked_Access);
8549 -- Task to task requeue
8552 pragma Assert (Is_Task_Type (Conc_Typ));
8554 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8557 Prepend (New_Param, Params);
8561 -- Create the GNARLI or predefined primitive call
8564 Make_Procedure_Call_Statement (Loc,
8566 Parameter_Associations => Params);
8571 if Is_Protected_Type (Old_Typ) then
8573 -- Build the return statement to skip the rest of the entry body
8575 Skip_Stat := Make_Simple_Return_Statement (Loc);
8578 -- If the requeue is within a task, find the end label of the
8579 -- enclosing accept statement.
8581 Acc_Stat := Parent (N);
8582 while Nkind (Acc_Stat) /= N_Accept_Statement loop
8583 Acc_Stat := Parent (Acc_Stat);
8586 -- The last statement is the second label, used for completing the
8587 -- rendezvous the usual way. The label we are looking for is right
8591 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
8593 pragma Assert (Nkind (Lab_Node) = N_Label);
8595 -- Build the goto statement to skip the rest of the accept
8599 Make_Goto_Statement (Loc,
8600 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
8603 Set_Analyzed (Skip_Stat);
8605 Insert_After (N, Skip_Stat);
8606 end Expand_N_Requeue_Statement;
8608 -------------------------------
8609 -- Expand_N_Selective_Accept --
8610 -------------------------------
8612 procedure Expand_N_Selective_Accept (N : Node_Id) is
8613 Loc : constant Source_Ptr := Sloc (N);
8614 Alts : constant List_Id := Select_Alternatives (N);
8616 -- Note: in the below declarations a lot of new lists are allocated
8617 -- unconditionally which may well not end up being used. That's
8618 -- not a good idea since it wastes space gratuitously ???
8620 Accept_Case : List_Id;
8621 Accept_List : constant List_Id := New_List;
8624 Alt_List : constant List_Id := New_List;
8625 Alt_Stats : List_Id;
8626 Ann : Entity_Id := Empty;
8629 Check_Guard : Boolean := True;
8631 Decls : constant List_Id := New_List;
8632 Stats : constant List_Id := New_List;
8633 Body_List : constant List_Id := New_List;
8634 Trailing_List : constant List_Id := New_List;
8637 Else_Present : Boolean := False;
8638 Terminate_Alt : Node_Id := Empty;
8639 Select_Mode : Node_Id;
8641 Delay_Case : List_Id;
8642 Delay_Count : Integer := 0;
8643 Delay_Val : Entity_Id;
8644 Delay_Index : Entity_Id;
8645 Delay_Min : Entity_Id;
8646 Delay_Num : Int := 1;
8647 Delay_Alt_List : List_Id := New_List;
8648 Delay_List : constant List_Id := New_List;
8652 First_Delay : Boolean := True;
8653 Guard_Open : Entity_Id;
8659 Num_Accept : Nat := 0;
8662 Time_Type : Entity_Id;
8664 Select_Call : Node_Id;
8666 Qnam : constant Entity_Id :=
8667 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
8669 Xnam : constant Entity_Id :=
8670 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
8672 -----------------------
8673 -- Local subprograms --
8674 -----------------------
8676 function Accept_Or_Raise return List_Id;
8677 -- For the rare case where delay alternatives all have guards, and
8678 -- all of them are closed, it is still possible that there were open
8679 -- accept alternatives with no callers. We must reexamine the
8680 -- Accept_List, and execute a selective wait with no else if some
8681 -- accept is open. If none, we raise program_error.
8683 procedure Add_Accept (Alt : Node_Id);
8684 -- Process a single accept statement in a select alternative. Build
8685 -- procedure for body of accept, and add entry to dispatch table with
8686 -- expression for guard, in preparation for call to run time select.
8688 function Make_And_Declare_Label (Num : Int) return Node_Id;
8689 -- Manufacture a label using Num as a serial number and declare it.
8690 -- The declaration is appended to Decls. The label marks the trailing
8691 -- statements of an accept or delay alternative.
8693 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
8694 -- Build call to Selective_Wait runtime routine
8696 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
8697 -- Add code to compare value of delay with previous values, and
8698 -- generate case entry for trailing statements.
8700 procedure Process_Accept_Alternative
8704 -- Add code to call corresponding procedure, and branch to
8705 -- trailing statements, if any.
8707 ---------------------
8708 -- Accept_Or_Raise --
8709 ---------------------
8711 function Accept_Or_Raise return List_Id is
8714 J : constant Entity_Id := Make_Temporary (Loc, 'J');
8717 -- We generate the following:
8719 -- for J in q'range loop
8720 -- if q(J).S /=null_task_entry then
8721 -- selective_wait (simple_mode,...);
8727 -- if no rendez_vous then
8728 -- raise program_error;
8731 -- Note that the code needs to know that the selector name
8732 -- in an Accept_Alternative is named S.
8734 Cond := Make_Op_Ne (Loc,
8736 Make_Selected_Component (Loc,
8737 Prefix => Make_Indexed_Component (Loc,
8738 Prefix => New_Reference_To (Qnam, Loc),
8739 Expressions => New_List (New_Reference_To (J, Loc))),
8740 Selector_Name => Make_Identifier (Loc, Name_S)),
8742 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
8745 Make_Implicit_Loop_Statement (N,
8746 Identifier => Empty,
8748 Make_Iteration_Scheme (Loc,
8749 Loop_Parameter_Specification =>
8750 Make_Loop_Parameter_Specification (Loc,
8751 Defining_Identifier => J,
8752 Discrete_Subtype_Definition =>
8753 Make_Attribute_Reference (Loc,
8754 Prefix => New_Reference_To (Qnam, Loc),
8755 Attribute_Name => Name_Range,
8756 Expressions => New_List (
8757 Make_Integer_Literal (Loc, 1))))),
8759 Statements => New_List (
8760 Make_Implicit_If_Statement (N,
8762 Then_Statements => New_List (
8764 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
8765 Make_Exit_Statement (Loc))))));
8768 Make_Raise_Program_Error (Loc,
8769 Condition => Make_Op_Eq (Loc,
8770 Left_Opnd => New_Reference_To (Xnam, Loc),
8772 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8773 Reason => PE_All_Guards_Closed));
8776 end Accept_Or_Raise;
8782 procedure Add_Accept (Alt : Node_Id) is
8783 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
8784 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
8785 Eloc : constant Source_Ptr := Sloc (Ename);
8786 Eent : constant Entity_Id := Entity (Ename);
8787 Index : constant Node_Id := Entry_Index (Acc_Stm);
8788 Null_Body : Node_Id;
8789 Proc_Body : Node_Id;
8796 Ann := Node (Last_Elmt (Accept_Address (Eent)));
8799 if Present (Condition (Alt)) then
8801 Make_Conditional_Expression (Eloc, New_List (
8803 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
8804 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
8807 Entry_Index_Expression
8808 (Eloc, Eent, Index, Scope (Eent));
8811 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8812 Null_Body := New_Reference_To (Standard_False, Eloc);
8814 if Abort_Allowed then
8815 Call := Make_Procedure_Call_Statement (Eloc,
8816 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
8817 Insert_Before (First (Statements (Handled_Statement_Sequence (
8818 Accept_Statement (Alt)))), Call);
8823 Make_Defining_Identifier (Eloc,
8824 New_External_Name (Chars (Ename), 'A', Num_Accept));
8826 if Comes_From_Source (Alt) then
8827 Set_Debug_Info_Needed (PB_Ent);
8831 Make_Subprogram_Body (Eloc,
8833 Make_Procedure_Specification (Eloc,
8834 Defining_Unit_Name => PB_Ent),
8835 Declarations => Declarations (Acc_Stm),
8836 Handled_Statement_Sequence =>
8837 Build_Accept_Body (Accept_Statement (Alt)));
8839 -- During the analysis of the body of the accept statement, any
8840 -- zero cost exception handler records were collected in the
8841 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8842 -- This is where we move them to where they belong, namely the
8843 -- newly created procedure.
8845 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8846 Append (Proc_Body, Body_List);
8849 Null_Body := New_Reference_To (Standard_True, Eloc);
8851 -- if accept statement has declarations, insert above, given that
8852 -- we are not creating a body for the accept.
8854 if Present (Declarations (Acc_Stm)) then
8855 Insert_Actions (N, Declarations (Acc_Stm));
8859 Append_To (Accept_List,
8860 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
8862 Num_Accept := Num_Accept + 1;
8865 ----------------------------
8866 -- Make_And_Declare_Label --
8867 ----------------------------
8869 function Make_And_Declare_Label (Num : Int) return Node_Id is
8873 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8875 Make_Label (Loc, Lab_Id);
8878 Make_Implicit_Label_Declaration (Loc,
8879 Defining_Identifier =>
8880 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8881 Label_Construct => Lab));
8884 end Make_And_Declare_Label;
8886 ----------------------
8887 -- Make_Select_Call --
8888 ----------------------
8890 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8891 Params : constant List_Id := New_List;
8895 Make_Attribute_Reference (Loc,
8896 Prefix => New_Reference_To (Qnam, Loc),
8897 Attribute_Name => Name_Unchecked_Access),
8899 Append (Select_Mode, Params);
8900 Append (New_Reference_To (Ann, Loc), Params);
8901 Append (New_Reference_To (Xnam, Loc), Params);
8904 Make_Procedure_Call_Statement (Loc,
8905 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8906 Parameter_Associations => Params);
8907 end Make_Select_Call;
8909 --------------------------------
8910 -- Process_Accept_Alternative --
8911 --------------------------------
8913 procedure Process_Accept_Alternative
8918 Choices : List_Id := No_List;
8919 Alt_Stats : List_Id;
8922 Adjust_Condition (Condition (Alt));
8923 Alt_Stats := No_List;
8925 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8926 Choices := New_List (
8927 Make_Integer_Literal (Loc, Index));
8929 Alt_Stats := New_List (
8930 Make_Procedure_Call_Statement (Sloc (Proc),
8931 Name => New_Reference_To (
8932 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
8935 if Statements (Alt) /= Empty_List then
8937 if No (Alt_Stats) then
8939 -- Accept with no body, followed by trailing statements
8941 Choices := New_List (
8942 Make_Integer_Literal (Loc, Index));
8944 Alt_Stats := New_List;
8947 -- After the call, if any, branch to trailing statements. We
8948 -- create a label for each, as well as the corresponding label
8951 Lab := Make_And_Declare_Label (Index);
8952 Append_To (Alt_Stats,
8953 Make_Goto_Statement (Loc,
8954 Name => New_Copy (Identifier (Lab))));
8956 Append (Lab, Trailing_List);
8957 Append_List (Statements (Alt), Trailing_List);
8958 Append_To (Trailing_List,
8959 Make_Goto_Statement (Loc,
8960 Name => New_Copy (Identifier (End_Lab))));
8963 if Present (Alt_Stats) then
8965 -- Procedure call. and/or trailing statements
8967 Append_To (Alt_List,
8968 Make_Case_Statement_Alternative (Loc,
8969 Discrete_Choices => Choices,
8970 Statements => Alt_Stats));
8972 end Process_Accept_Alternative;
8974 -------------------------------
8975 -- Process_Delay_Alternative --
8976 -------------------------------
8978 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
8981 Delay_Alt : List_Id;
8984 -- Deal with C/Fortran boolean as delay condition
8986 Adjust_Condition (Condition (Alt));
8988 -- Determine the smallest specified delay
8990 -- for each delay alternative generate:
8992 -- if guard-expression then
8993 -- Delay_Val := delay-expression;
8994 -- Guard_Open := True;
8995 -- if Delay_Val < Delay_Min then
8996 -- Delay_Min := Delay_Val;
8997 -- Delay_Index := Index;
9001 -- The enclosing if-statement is omitted if there is no guard
9006 First_Delay := False;
9008 Delay_Alt := New_List (
9009 Make_Assignment_Statement (Loc,
9010 Name => New_Reference_To (Delay_Min, Loc),
9011 Expression => Expression (Delay_Statement (Alt))));
9013 if Delay_Count > 1 then
9014 Append_To (Delay_Alt,
9015 Make_Assignment_Statement (Loc,
9016 Name => New_Reference_To (Delay_Index, Loc),
9017 Expression => Make_Integer_Literal (Loc, Index)));
9021 Delay_Alt := New_List (
9022 Make_Assignment_Statement (Loc,
9023 Name => New_Reference_To (Delay_Val, Loc),
9024 Expression => Expression (Delay_Statement (Alt))));
9026 if Time_Type = Standard_Duration then
9029 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9030 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9033 -- The scope of the time type must define a comparison
9034 -- operator. The scope itself may not be visible, so we
9035 -- construct a node with entity information to insure that
9036 -- semantic analysis can find the proper operator.
9039 Make_Function_Call (Loc,
9040 Name => Make_Selected_Component (Loc,
9041 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9043 Make_Operator_Symbol (Loc,
9044 Chars => Name_Op_Lt,
9045 Strval => No_String)),
9046 Parameter_Associations =>
9048 New_Reference_To (Delay_Val, Loc),
9049 New_Reference_To (Delay_Min, Loc)));
9051 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9054 Append_To (Delay_Alt,
9055 Make_Implicit_If_Statement (N,
9057 Then_Statements => New_List (
9058 Make_Assignment_Statement (Loc,
9059 Name => New_Reference_To (Delay_Min, Loc),
9060 Expression => New_Reference_To (Delay_Val, Loc)),
9062 Make_Assignment_Statement (Loc,
9063 Name => New_Reference_To (Delay_Index, Loc),
9064 Expression => Make_Integer_Literal (Loc, Index)))));
9068 Append_To (Delay_Alt,
9069 Make_Assignment_Statement (Loc,
9070 Name => New_Reference_To (Guard_Open, Loc),
9071 Expression => New_Reference_To (Standard_True, Loc)));
9074 if Present (Condition (Alt)) then
9075 Delay_Alt := New_List (
9076 Make_Implicit_If_Statement (N,
9077 Condition => Condition (Alt),
9078 Then_Statements => Delay_Alt));
9081 Append_List (Delay_Alt, Delay_List);
9083 -- If the delay alternative has a statement part, add choice to the
9084 -- case statements for delays.
9086 if Present (Statements (Alt)) then
9088 if Delay_Count = 1 then
9089 Append_List (Statements (Alt), Delay_Alt_List);
9092 Choices := New_List (
9093 Make_Integer_Literal (Loc, Index));
9095 Append_To (Delay_Alt_List,
9096 Make_Case_Statement_Alternative (Loc,
9097 Discrete_Choices => Choices,
9098 Statements => Statements (Alt)));
9101 elsif Delay_Count = 1 then
9103 -- If the single delay has no trailing statements, add a branch
9104 -- to the exit label to the selective wait.
9106 Delay_Alt_List := New_List (
9107 Make_Goto_Statement (Loc,
9108 Name => New_Copy (Identifier (End_Lab))));
9111 end Process_Delay_Alternative;
9113 -- Start of processing for Expand_N_Selective_Accept
9116 -- First insert some declarations before the select. The first is:
9120 -- This variable holds the parameters passed to the accept body. This
9121 -- declaration has already been inserted by the time we get here by
9122 -- a call to Expand_Accept_Declarations made from the semantics when
9123 -- processing the first accept statement contained in the select. We
9124 -- can find this entity as Accept_Address (E), where E is any of the
9125 -- entries references by contained accept statements.
9127 -- The first step is to scan the list of Selective_Accept_Statements
9128 -- to find this entity, and also count the number of accepts, and
9129 -- determine if terminated, delay or else is present:
9133 Alt := First (Alts);
9134 while Present (Alt) loop
9136 if Nkind (Alt) = N_Accept_Alternative then
9139 elsif Nkind (Alt) = N_Delay_Alternative then
9140 Delay_Count := Delay_Count + 1;
9142 -- If the delays are relative delays, the delay expressions have
9143 -- type Standard_Duration. Otherwise they must have some time type
9144 -- recognized by GNAT.
9146 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9147 Time_Type := Standard_Duration;
9149 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9151 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9152 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9157 "& is not a time type (RM 9.6(6))",
9158 Expression (Delay_Statement (Alt)), Time_Type);
9159 Time_Type := Standard_Duration;
9160 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9164 if No (Condition (Alt)) then
9166 -- This guard will always be open
9168 Check_Guard := False;
9171 elsif Nkind (Alt) = N_Terminate_Alternative then
9172 Adjust_Condition (Condition (Alt));
9173 Terminate_Alt := Alt;
9176 Num_Alts := Num_Alts + 1;
9180 Else_Present := Present (Else_Statements (N));
9182 -- At the same time (see procedure Add_Accept) we build the accept list:
9184 -- Qnn : Accept_List (1 .. num-select) := (
9185 -- (null-body, entry-index),
9186 -- (null-body, entry-index),
9188 -- (null_body, entry-index));
9190 -- In the above declaration, null-body is True if the corresponding
9191 -- accept has no body, and false otherwise. The entry is either the
9192 -- entry index expression if there is no guard, or if a guard is
9193 -- present, then a conditional expression of the form:
9195 -- (if guard then entry-index else Null_Task_Entry)
9197 -- If a guard is statically known to be false, the entry can simply
9198 -- be omitted from the accept list.
9201 Make_Object_Declaration (Loc,
9202 Defining_Identifier => Qnam,
9203 Object_Definition =>
9204 New_Reference_To (RTE (RE_Accept_List), Loc),
9205 Aliased_Present => True,
9208 Make_Qualified_Expression (Loc,
9210 New_Reference_To (RTE (RE_Accept_List), Loc),
9212 Make_Aggregate (Loc, Expressions => Accept_List)));
9216 -- Then we declare the variable that holds the index for the accept
9217 -- that will be selected for service:
9219 -- Xnn : Select_Index;
9222 Make_Object_Declaration (Loc,
9223 Defining_Identifier => Xnam,
9224 Object_Definition =>
9225 New_Reference_To (RTE (RE_Select_Index), Loc),
9227 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9231 -- After this follow procedure declarations for each accept body
9238 -- where the ... are statements from the corresponding procedure body.
9239 -- No parameters are involved, since the parameters are passed via Ann
9240 -- and the parameter references have already been expanded to be direct
9241 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9242 -- any embedded tasking statements (which would normally be illegal in
9243 -- procedures), have been converted to calls to the tasking runtime so
9244 -- there is no problem in putting them into procedures.
9246 -- The original accept statement has been expanded into a block in
9247 -- the same fashion as for simple accepts (see Build_Accept_Body).
9249 -- Note: we don't really need to build these procedures for the case
9250 -- where no delay statement is present, but it is just as easy to
9251 -- build them unconditionally, and not significantly inefficient,
9252 -- since if they are short they will be inlined anyway.
9254 -- The procedure declarations have been assembled in Body_List
9256 -- If delays are present, we must compute the required delay.
9257 -- We first generate the declarations:
9259 -- Delay_Index : Boolean := 0;
9260 -- Delay_Min : Some_Time_Type.Time;
9261 -- Delay_Val : Some_Time_Type.Time;
9263 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9264 -- active delay that is actually chosen as the basis for the possible
9265 -- delay if an immediate rendez-vous is not possible.
9267 -- In the most common case there is a single delay statement, and this
9268 -- is handled specially.
9270 if Delay_Count > 0 then
9272 -- Generate the required declarations
9275 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9277 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9279 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9282 Make_Object_Declaration (Loc,
9283 Defining_Identifier => Delay_Val,
9284 Object_Definition => New_Reference_To (Time_Type, Loc)));
9287 Make_Object_Declaration (Loc,
9288 Defining_Identifier => Delay_Index,
9289 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9290 Expression => Make_Integer_Literal (Loc, 0)));
9293 Make_Object_Declaration (Loc,
9294 Defining_Identifier => Delay_Min,
9295 Object_Definition => New_Reference_To (Time_Type, Loc),
9297 Unchecked_Convert_To (Time_Type,
9298 Make_Attribute_Reference (Loc,
9300 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9301 Attribute_Name => Name_Last))));
9303 -- Create Duration and Delay_Mode objects used for passing a delay
9306 D := Make_Temporary (Loc, 'D');
9307 M := Make_Temporary (Loc, 'M');
9313 -- Note that these values are defined in s-osprim.ads and must
9316 -- Relative : constant := 0;
9317 -- Absolute_Calendar : constant := 1;
9318 -- Absolute_RT : constant := 2;
9320 if Time_Type = Standard_Duration then
9321 Discr := Make_Integer_Literal (Loc, 0);
9323 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9324 Discr := Make_Integer_Literal (Loc, 1);
9328 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9329 Discr := Make_Integer_Literal (Loc, 2);
9333 Make_Object_Declaration (Loc,
9334 Defining_Identifier => D,
9335 Object_Definition =>
9336 New_Reference_To (Standard_Duration, Loc)));
9339 Make_Object_Declaration (Loc,
9340 Defining_Identifier => M,
9341 Object_Definition =>
9342 New_Reference_To (Standard_Integer, Loc),
9343 Expression => Discr));
9348 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9351 Make_Object_Declaration (Loc,
9352 Defining_Identifier => Guard_Open,
9353 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9354 Expression => New_Reference_To (Standard_False, Loc)));
9357 -- Delay_Count is zero, don't need M and D set (suppress warning)
9364 if Present (Terminate_Alt) then
9366 -- If the terminate alternative guard is False, use
9367 -- Simple_Mode; otherwise use Terminate_Mode.
9369 if Present (Condition (Terminate_Alt)) then
9370 Select_Mode := Make_Conditional_Expression (Loc,
9371 New_List (Condition (Terminate_Alt),
9372 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9373 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9375 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9378 elsif Else_Present or Delay_Count > 0 then
9379 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9382 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9385 Select_Call := Make_Select_Call (Select_Mode);
9386 Append (Select_Call, Stats);
9388 -- Now generate code to act on the result. There is an entry
9389 -- in this case for each accept statement with a non-null body,
9390 -- followed by a branch to the statements that follow the Accept.
9391 -- In the absence of delay alternatives, we generate:
9394 -- when No_Rendezvous => -- omitted if simple mode
9409 -- Lab0: Else_Statements;
9412 -- Lab1: Trailing_Statements1;
9415 -- Lab2: Trailing_Statements2;
9420 -- Generate label for common exit
9422 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9424 -- First entry is the default case, when no rendezvous is possible
9426 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9428 if Else_Present then
9430 -- If no rendezvous is possible, the else part is executed
9432 Lab := Make_And_Declare_Label (0);
9433 Alt_Stats := New_List (
9434 Make_Goto_Statement (Loc,
9435 Name => New_Copy (Identifier (Lab))));
9437 Append (Lab, Trailing_List);
9438 Append_List (Else_Statements (N), Trailing_List);
9439 Append_To (Trailing_List,
9440 Make_Goto_Statement (Loc,
9441 Name => New_Copy (Identifier (End_Lab))));
9443 Alt_Stats := New_List (
9444 Make_Goto_Statement (Loc,
9445 Name => New_Copy (Identifier (End_Lab))));
9448 Append_To (Alt_List,
9449 Make_Case_Statement_Alternative (Loc,
9450 Discrete_Choices => Choices,
9451 Statements => Alt_Stats));
9453 -- We make use of the fact that Accept_Index is an integer type, and
9454 -- generate successive literals for entries for each accept. Only those
9455 -- for which there is a body or trailing statements get a case entry.
9457 Alt := First (Select_Alternatives (N));
9458 Proc := First (Body_List);
9459 while Present (Alt) loop
9461 if Nkind (Alt) = N_Accept_Alternative then
9462 Process_Accept_Alternative (Alt, Index, Proc);
9466 (Handled_Statement_Sequence (Accept_Statement (Alt)))
9471 elsif Nkind (Alt) = N_Delay_Alternative then
9472 Process_Delay_Alternative (Alt, Delay_Num);
9473 Delay_Num := Delay_Num + 1;
9479 -- An others choice is always added to the main case, as well
9480 -- as the delay case (to satisfy the compiler).
9482 Append_To (Alt_List,
9483 Make_Case_Statement_Alternative (Loc,
9485 New_List (Make_Others_Choice (Loc)),
9487 New_List (Make_Goto_Statement (Loc,
9488 Name => New_Copy (Identifier (End_Lab))))));
9490 Accept_Case := New_List (
9491 Make_Case_Statement (Loc,
9492 Expression => New_Reference_To (Xnam, Loc),
9493 Alternatives => Alt_List));
9495 Append_List (Trailing_List, Accept_Case);
9496 Append (End_Lab, Accept_Case);
9497 Append_List (Body_List, Decls);
9499 -- Construct case statement for trailing statements of delay
9500 -- alternatives, if there are several of them.
9502 if Delay_Count > 1 then
9503 Append_To (Delay_Alt_List,
9504 Make_Case_Statement_Alternative (Loc,
9506 New_List (Make_Others_Choice (Loc)),
9508 New_List (Make_Null_Statement (Loc))));
9510 Delay_Case := New_List (
9511 Make_Case_Statement (Loc,
9512 Expression => New_Reference_To (Delay_Index, Loc),
9513 Alternatives => Delay_Alt_List));
9515 Delay_Case := Delay_Alt_List;
9518 -- If there are no delay alternatives, we append the case statement
9519 -- to the statement list.
9521 if Delay_Count = 0 then
9522 Append_List (Accept_Case, Stats);
9524 -- Delay alternatives present
9527 -- If delay alternatives are present we generate:
9529 -- find minimum delay.
9530 -- DX := minimum delay;
9531 -- M := <delay mode>;
9532 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9535 -- if X = No_Rendezvous then
9536 -- case statement for delay statements.
9538 -- case statement for accept alternatives.
9549 -- The type of the delay expression is known to be legal
9551 if Time_Type = Standard_Duration then
9552 Conv := New_Reference_To (Delay_Min, Loc);
9554 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9555 Conv := Make_Function_Call (Loc,
9556 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9557 New_List (New_Reference_To (Delay_Min, Loc)));
9561 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9563 Conv := Make_Function_Call (Loc,
9564 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9565 New_List (New_Reference_To (Delay_Min, Loc)));
9568 Stmt := Make_Assignment_Statement (Loc,
9569 Name => New_Reference_To (D, Loc),
9570 Expression => Conv);
9572 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
9574 Parms := Parameter_Associations (Select_Call);
9575 Parm := First (Parms);
9577 while Present (Parm)
9578 and then Parm /= Select_Mode
9583 pragma Assert (Present (Parm));
9584 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
9587 -- Prepare two new parameters of Duration and Delay_Mode type
9588 -- which represent the value and the mode of the minimum delay.
9591 Insert_After (Parm, New_Reference_To (M, Loc));
9592 Insert_After (Parm, New_Reference_To (D, Loc));
9594 -- Create a call to RTS
9596 Rewrite (Select_Call,
9597 Make_Procedure_Call_Statement (Loc,
9598 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
9599 Parameter_Associations => Parms));
9601 -- This new call should follow the calculation of the minimum
9604 Insert_List_Before (Select_Call, Delay_List);
9608 Make_Implicit_If_Statement (N,
9609 Condition => New_Reference_To (Guard_Open, Loc),
9611 New_List (New_Copy_Tree (Stmt),
9612 New_Copy_Tree (Select_Call)),
9613 Else_Statements => Accept_Or_Raise);
9614 Rewrite (Select_Call, Stmt);
9616 Insert_Before (Select_Call, Stmt);
9620 Make_Implicit_If_Statement (N,
9621 Condition => Make_Op_Eq (Loc,
9622 Left_Opnd => New_Reference_To (Xnam, Loc),
9624 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9626 Then_Statements => Delay_Case,
9627 Else_Statements => Accept_Case);
9629 Append (Cases, Stats);
9633 -- Replace accept statement with appropriate block
9636 Make_Block_Statement (Loc,
9637 Declarations => Decls,
9638 Handled_Statement_Sequence =>
9639 Make_Handled_Sequence_Of_Statements (Loc,
9640 Statements => Stats));
9645 -- Note: have to worry more about abort deferral in above code ???
9647 -- Final step is to unstack the Accept_Address entries for all accept
9648 -- statements appearing in accept alternatives in the select statement
9650 Alt := First (Alts);
9651 while Present (Alt) loop
9652 if Nkind (Alt) = N_Accept_Alternative then
9653 Remove_Last_Elmt (Accept_Address
9654 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
9659 end Expand_N_Selective_Accept;
9661 --------------------------------------
9662 -- Expand_N_Single_Task_Declaration --
9663 --------------------------------------
9665 -- Single task declarations should never be present after semantic
9666 -- analysis, since we expect them to be replaced by a declaration of an
9667 -- anonymous task type, followed by a declaration of the task object. We
9668 -- include this routine to make sure that is happening!
9670 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
9672 raise Program_Error;
9673 end Expand_N_Single_Task_Declaration;
9675 ------------------------
9676 -- Expand_N_Task_Body --
9677 ------------------------
9679 -- Given a task body
9681 -- task body tname is
9687 -- This expansion routine converts it into a procedure and sets the
9688 -- elaboration flag for the procedure to true, to represent the fact
9689 -- that the task body is now elaborated:
9691 -- procedure tnameB (_Task : access tnameV) is
9692 -- discriminal : dtype renames _Task.discriminant;
9694 -- procedure _clean is
9698 -- Abort_Undefer.all;
9703 -- Abort_Undefer.all;
9705 -- System.Task_Stages.Complete_Activation;
9713 -- In addition, if the task body is an activator, then a call to activate
9714 -- tasks is added at the start of the statements, before the call to
9715 -- Complete_Activation, and if in addition the task is a master then it
9716 -- must be established as a master. These calls are inserted and analyzed
9717 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9720 -- There is one discriminal declaration line generated for each
9721 -- discriminant that is present to provide an easy reference point for
9722 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9724 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9725 -- task body procedures have a profile (Arg : System.Address). That is
9726 -- needed because GNARLI has to use the same access-to-subprogram type
9727 -- for all task types. We depend here on knowing that in GNAT, passing
9728 -- an address argument by value is identical to passing a record value
9729 -- by access (in either case a single pointer is passed), so even though
9730 -- this procedure has the wrong profile. In fact it's all OK, since the
9731 -- callings sequence is identical.
9733 procedure Expand_N_Task_Body (N : Node_Id) is
9734 Loc : constant Source_Ptr := Sloc (N);
9735 Ttyp : constant Entity_Id := Corresponding_Spec (N);
9739 Insert_Nod : Node_Id;
9740 -- Used to determine the proper location of wrapper body insertions
9743 -- Add renaming declarations for discriminals and a declaration for the
9744 -- entry family index (if applicable).
9746 Install_Private_Data_Declarations
9747 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
9749 -- Add a call to Abort_Undefer at the very beginning of the task
9750 -- body since this body is called with abort still deferred.
9752 if Abort_Allowed then
9753 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
9755 (First (Statements (Handled_Statement_Sequence (N))), Call);
9759 -- The statement part has already been protected with an at_end and
9760 -- cleanup actions. The call to Complete_Activation must be placed
9761 -- at the head of the sequence of statements of that block. The
9762 -- declarations have been merged in this sequence of statements but
9763 -- the first real statement is accessible from the First_Real_Statement
9764 -- field (which was set for exactly this purpose).
9766 if Restricted_Profile then
9767 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
9769 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
9773 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
9777 Make_Subprogram_Body (Loc,
9778 Specification => Build_Task_Proc_Specification (Ttyp),
9779 Declarations => Declarations (N),
9780 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
9782 -- If the task contains generic instantiations, cleanup actions are
9783 -- delayed until after instantiation. Transfer the activation chain to
9784 -- the subprogram, to insure that the activation call is properly
9785 -- generated. It the task body contains inner tasks, indicate that the
9786 -- subprogram is a task master.
9788 if Delay_Cleanups (Ttyp) then
9789 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
9790 Set_Is_Task_Master (New_N, Is_Task_Master (N));
9796 -- Set elaboration flag immediately after task body. If the body is a
9797 -- subunit, the flag is set in the declarative part containing the stub.
9799 if Nkind (Parent (N)) /= N_Subunit then
9801 Make_Assignment_Statement (Loc,
9803 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
9804 Expression => New_Reference_To (Standard_True, Loc)));
9807 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9808 -- the task body. At this point all wrapper specs have been created,
9809 -- frozen and included in the dispatch table for the task type.
9811 if Ada_Version >= Ada_05 then
9812 if Nkind (Parent (N)) = N_Subunit then
9813 Insert_Nod := Corresponding_Stub (Parent (N));
9818 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
9820 end Expand_N_Task_Body;
9822 ------------------------------------
9823 -- Expand_N_Task_Type_Declaration --
9824 ------------------------------------
9826 -- We have several things to do. First we must create a Boolean flag used
9827 -- to mark if the body is elaborated yet. This variable gets set to True
9828 -- when the body of the task is elaborated (we can't rely on the normal
9829 -- ABE mechanism for the task body, since we need to pass an access to
9830 -- this elaboration boolean to the runtime routines).
9832 -- taskE : aliased Boolean := False;
9834 -- Next a variable is declared to hold the task stack size (either the
9835 -- default : Unspecified_Size, or a value that is set by a pragma
9836 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9837 -- the variable is initialized with this value:
9839 -- taskZ : Size_Type := Unspecified_Size;
9841 -- taskZ : Size_Type := Size_Type (size_expression);
9843 -- Note: No variable is needed to hold the task relative deadline since
9844 -- its value would never be static because the parameter is of a private
9845 -- type (Ada.Real_Time.Time_Span).
9847 -- Next we create a corresponding record type declaration used to represent
9848 -- values of this task. The general form of this type declaration is
9850 -- type taskV (discriminants) is record
9851 -- _Task_Id : Task_Id;
9852 -- entry_family : array (bounds) of Void;
9853 -- _Priority : Integer := priority_expression;
9854 -- _Size : Size_Type := Size_Type (size_expression);
9855 -- _Task_Info : Task_Info_Type := task_info_expression;
9858 -- The discriminants are present only if the corresponding task type has
9859 -- discriminants, and they exactly mirror the task type discriminants.
9861 -- The Id field is always present. It contains the Task_Id value, as set by
9862 -- the call to Create_Task. Note that although the task is limited, the
9863 -- task value record type is not limited, so there is no problem in passing
9864 -- this field as an out parameter to Create_Task.
9866 -- One entry_family component is present for each entry family in the task
9867 -- definition. The bounds correspond to the bounds of the entry family
9868 -- (which may depend on discriminants). The element type is void, since we
9869 -- only need the bounds information for determining the entry index. Note
9870 -- that the use of an anonymous array would normally be illegal in this
9871 -- context, but this is a parser check, and the semantics is quite prepared
9872 -- to handle such a case.
9874 -- The _Size field is present only if a Storage_Size pragma appears in the
9875 -- task definition. The expression captures the argument that was present
9876 -- in the pragma, and is used to override the task stack size otherwise
9877 -- associated with the task type.
9879 -- The _Priority field is present only if a Priority or Interrupt_Priority
9880 -- pragma appears in the task definition. The expression captures the
9881 -- argument that was present in the pragma, and is used to provide the Size
9882 -- parameter to the call to Create_Task.
9884 -- The _Task_Info field is present only if a Task_Info pragma appears in
9885 -- the task definition. The expression captures the argument that was
9886 -- present in the pragma, and is used to provide the Task_Image parameter
9887 -- to the call to Create_Task.
9889 -- The _Relative_Deadline field is present only if a Relative_Deadline
9890 -- pragma appears in the task definition. The expression captures the
9891 -- argument that was present in the pragma, and is used to provide the
9892 -- Relative_Deadline parameter to the call to Create_Task.
9894 -- When a task is declared, an instance of the task value record is
9895 -- created. The elaboration of this declaration creates the correct bounds
9896 -- for the entry families, and also evaluates the size, priority, and
9897 -- task_Info expressions if needed. The initialization routine for the task
9898 -- type itself then calls Create_Task with appropriate parameters to
9899 -- initialize the value of the Task_Id field.
9901 -- Note: the address of this record is passed as the "Discriminants"
9902 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9903 -- body procedure, it does not matter that it does not quite match the
9904 -- GNARLI model of what is being passed (the record contains more than just
9905 -- the discriminants, but the discriminants can be found from the record
9908 -- The Entity_Id for this created record type is placed in the
9909 -- Corresponding_Record_Type field of the associated task type entity.
9911 -- Next we create a procedure specification for the task body procedure:
9913 -- procedure taskB (_Task : access taskV);
9915 -- Note that this must come after the record type declaration, since
9916 -- the spec refers to this type. It turns out that the initialization
9917 -- procedure for the value type references the task body spec, but that's
9918 -- fine, since it won't be generated till the freeze point for the type,
9919 -- which is certainly after the task body spec declaration.
9921 -- Finally, we set the task index value field of the entry attribute in
9922 -- the case of a simple entry.
9924 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9925 Loc : constant Source_Ptr := Sloc (N);
9926 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9927 Tasknm : constant Name_Id := Chars (Tasktyp);
9928 Taskdef : constant Node_Id := Task_Definition (N);
9930 Proc_Spec : Node_Id;
9932 Rec_Ent : Entity_Id;
9934 Elab_Decl : Node_Id;
9935 Size_Decl : Node_Id;
9936 Body_Decl : Node_Id;
9937 Task_Size : Node_Id;
9938 Ent_Stack : Entity_Id;
9939 Decl_Stack : Node_Id;
9942 -- If already expanded, nothing to do
9944 if Present (Corresponding_Record_Type (Tasktyp)) then
9948 -- Here we will do the expansion
9950 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9952 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9953 -- of implemented interfaces.
9955 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9957 Rec_Ent := Defining_Identifier (Rec_Decl);
9958 Cdecls := Component_Items (Component_List
9959 (Type_Definition (Rec_Decl)));
9961 Qualify_Entity_Names (N);
9963 -- First create the elaboration variable
9966 Make_Object_Declaration (Loc,
9967 Defining_Identifier =>
9968 Make_Defining_Identifier (Sloc (Tasktyp),
9969 Chars => New_External_Name (Tasknm, 'E')),
9970 Aliased_Present => True,
9971 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9972 Expression => New_Reference_To (Standard_False, Loc));
9973 Insert_After (N, Elab_Decl);
9975 -- Next create the declaration of the size variable (tasknmZ)
9977 Set_Storage_Size_Variable (Tasktyp,
9978 Make_Defining_Identifier (Sloc (Tasktyp),
9979 Chars => New_External_Name (Tasknm, 'Z')));
9981 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
9982 Is_Static_Expression (Expression (First (
9983 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
9984 Taskdef, Name_Storage_Size)))))
9987 Make_Object_Declaration (Loc,
9988 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9989 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9991 Convert_To (RTE (RE_Size_Type),
9994 Pragma_Argument_Associations (
9995 Find_Task_Or_Protected_Pragma
9996 (Taskdef, Name_Storage_Size)))))));
10000 Make_Object_Declaration (Loc,
10001 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10002 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10003 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10006 Insert_After (Elab_Decl, Size_Decl);
10008 -- Next build the rest of the corresponding record declaration. This is
10009 -- done last, since the corresponding record initialization procedure
10010 -- will reference the previously created entities.
10012 -- Fill in the component declarations -- first the _Task_Id field
10015 Make_Component_Declaration (Loc,
10016 Defining_Identifier =>
10017 Make_Defining_Identifier (Loc, Name_uTask_Id),
10018 Component_Definition =>
10019 Make_Component_Definition (Loc,
10020 Aliased_Present => False,
10021 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10024 -- Declare static ATCB (that is, created by the expander) if we are
10025 -- using the Restricted run time.
10027 if Restricted_Profile then
10029 Make_Component_Declaration (Loc,
10030 Defining_Identifier =>
10031 Make_Defining_Identifier (Loc, Name_uATCB),
10033 Component_Definition =>
10034 Make_Component_Definition (Loc,
10035 Aliased_Present => True,
10036 Subtype_Indication => Make_Subtype_Indication (Loc,
10037 Subtype_Mark => New_Occurrence_Of
10038 (RTE (RE_Ada_Task_Control_Block), Loc),
10041 Make_Index_Or_Discriminant_Constraint (Loc,
10043 New_List (Make_Integer_Literal (Loc, 0)))))));
10047 -- Declare static stack (that is, created by the expander) if we are
10048 -- using the Restricted run time on a bare board configuration.
10050 if Restricted_Profile
10051 and then Preallocated_Stacks_On_Target
10053 -- First we need to extract the appropriate stack size
10055 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10057 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10059 Expr_N : constant Node_Id :=
10060 Expression (First (
10061 Pragma_Argument_Associations (
10062 Find_Task_Or_Protected_Pragma
10063 (Taskdef, Name_Storage_Size))));
10064 Etyp : constant Entity_Id := Etype (Expr_N);
10065 P : constant Node_Id := Parent (Expr_N);
10068 -- The stack is defined inside the corresponding record.
10069 -- Therefore if the size of the stack is set by means of
10070 -- a discriminant, we must reference the discriminant of the
10071 -- corresponding record type.
10073 if Nkind (Expr_N) in N_Has_Entity
10074 and then Present (Discriminal_Link (Entity (Expr_N)))
10078 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10080 Set_Parent (Task_Size, P);
10081 Set_Etype (Task_Size, Etyp);
10082 Set_Analyzed (Task_Size);
10085 Task_Size := Relocate_Node (Expr_N);
10091 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10094 Decl_Stack := Make_Component_Declaration (Loc,
10095 Defining_Identifier => Ent_Stack,
10097 Component_Definition =>
10098 Make_Component_Definition (Loc,
10099 Aliased_Present => True,
10100 Subtype_Indication => Make_Subtype_Indication (Loc,
10102 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10105 Make_Index_Or_Discriminant_Constraint (Loc,
10106 Constraints => New_List (Make_Range (Loc,
10107 Low_Bound => Make_Integer_Literal (Loc, 1),
10108 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10111 Append_To (Cdecls, Decl_Stack);
10113 -- The appropriate alignment for the stack is ensured by the run-time
10114 -- code in charge of task creation.
10118 -- Add components for entry families
10120 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10122 -- Add the _Priority component if a Priority pragma is present
10124 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
10126 Prag : constant Node_Id :=
10127 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10131 Expr := First (Pragma_Argument_Associations (Prag));
10133 if Nkind (Expr) = N_Pragma_Argument_Association then
10134 Expr := Expression (Expr);
10137 Expr := New_Copy_Tree (Expr);
10139 -- Add conversion to proper type to do range check if required
10140 -- Note that for runtime units, we allow out of range interrupt
10141 -- priority values to be used in a priority pragma. This is for
10142 -- the benefit of some versions of System.Interrupts which use
10143 -- a special server task with maximum interrupt priority.
10145 if Pragma_Name (Prag) = Name_Priority
10146 and then not GNAT_Mode
10148 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10150 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10154 Make_Component_Declaration (Loc,
10155 Defining_Identifier =>
10156 Make_Defining_Identifier (Loc, Name_uPriority),
10157 Component_Definition =>
10158 Make_Component_Definition (Loc,
10159 Aliased_Present => False,
10160 Subtype_Indication => New_Reference_To (Standard_Integer,
10162 Expression => Expr));
10166 -- Add the _Task_Size component if a Storage_Size pragma is present
10168 if Present (Taskdef)
10169 and then Has_Storage_Size_Pragma (Taskdef)
10172 Make_Component_Declaration (Loc,
10173 Defining_Identifier =>
10174 Make_Defining_Identifier (Loc, Name_uSize),
10176 Component_Definition =>
10177 Make_Component_Definition (Loc,
10178 Aliased_Present => False,
10179 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10183 Convert_To (RTE (RE_Size_Type),
10185 Expression (First (
10186 Pragma_Argument_Associations (
10187 Find_Task_Or_Protected_Pragma
10188 (Taskdef, Name_Storage_Size))))))));
10191 -- Add the _Task_Info component if a Task_Info pragma is present
10193 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10195 Make_Component_Declaration (Loc,
10196 Defining_Identifier =>
10197 Make_Defining_Identifier (Loc, Name_uTask_Info),
10199 Component_Definition =>
10200 Make_Component_Definition (Loc,
10201 Aliased_Present => False,
10202 Subtype_Indication =>
10203 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10205 Expression => New_Copy (
10206 Expression (First (
10207 Pragma_Argument_Associations (
10208 Find_Task_Or_Protected_Pragma
10209 (Taskdef, Name_Task_Info)))))));
10212 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10213 -- present. If we are using a restricted run time this component will
10214 -- not be added (deadlines are not allowed by the Ravenscar profile).
10216 if not Restricted_Profile
10217 and then Present (Taskdef)
10218 and then Has_Relative_Deadline_Pragma (Taskdef)
10221 Make_Component_Declaration (Loc,
10222 Defining_Identifier =>
10223 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10225 Component_Definition =>
10226 Make_Component_Definition (Loc,
10227 Aliased_Present => False,
10228 Subtype_Indication =>
10229 New_Reference_To (RTE (RE_Time_Span), Loc)),
10232 Convert_To (RTE (RE_Time_Span),
10234 Expression (First (
10235 Pragma_Argument_Associations (
10236 Find_Task_Or_Protected_Pragma
10237 (Taskdef, Name_Relative_Deadline))))))));
10240 Insert_After (Size_Decl, Rec_Decl);
10242 -- Analyze the record declaration immediately after construction,
10243 -- because the initialization procedure is needed for single task
10244 -- declarations before the next entity is analyzed.
10246 Analyze (Rec_Decl);
10248 -- Create the declaration of the task body procedure
10250 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10252 Make_Subprogram_Declaration (Loc,
10253 Specification => Proc_Spec);
10255 Insert_After (Rec_Decl, Body_Decl);
10257 -- The subprogram does not comes from source, so we have to indicate the
10258 -- need for debugging information explicitly.
10260 if Comes_From_Source (Original_Node (N)) then
10261 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10264 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10265 -- the corresponding record has been frozen.
10267 if Ada_Version >= Ada_05 then
10268 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10271 -- Ada 2005 (AI-345): We must defer freezing to allow further
10272 -- declaration of primitive subprograms covering task interfaces
10274 if Ada_Version <= Ada_95 then
10276 -- Now we can freeze the corresponding record. This needs manually
10277 -- freezing, since it is really part of the task type, and the task
10278 -- type is frozen at this stage. We of course need the initialization
10279 -- procedure for this corresponding record type and we won't get it
10280 -- in time if we don't freeze now.
10283 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
10285 if Is_Non_Empty_List (L) then
10286 Insert_List_After (Body_Decl, L);
10291 -- Complete the expansion of access types to the current task type, if
10292 -- any were declared.
10294 Expand_Previous_Access_Type (Tasktyp);
10295 end Expand_N_Task_Type_Declaration;
10297 -------------------------------
10298 -- Expand_N_Timed_Entry_Call --
10299 -------------------------------
10301 -- A timed entry call in normal case is not implemented using ATC mechanism
10302 -- anymore for efficiency reason.
10312 -- is expanded as follow:
10314 -- 1) When T.E is a task entry_call;
10318 -- X : Task_Entry_Index := <entry index>;
10319 -- DX : Duration := To_Duration (D);
10320 -- M : Delay_Mode := <discriminant>;
10321 -- P : parms := (parm, parm, parm);
10324 -- Timed_Protected_Entry_Call
10325 -- (<acceptor-task>, X, P'Address, DX, M, B);
10333 -- 2) When T.E is a protected entry_call;
10337 -- X : Protected_Entry_Index := <entry index>;
10338 -- DX : Duration := To_Duration (D);
10339 -- M : Delay_Mode := <discriminant>;
10340 -- P : parms := (parm, parm, parm);
10343 -- Timed_Protected_Entry_Call
10344 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10352 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10355 -- B : Boolean := False;
10356 -- C : Ada.Tags.Prim_Op_Kind;
10357 -- DX : Duration := To_Duration (D)
10358 -- K : Ada.Tags.Tagged_Kind :=
10359 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10360 -- M : Integer :=...;
10361 -- P : Parameters := (Param1 .. ParamN);
10365 -- if K = Ada.Tags.TK_Limited_Tagged then
10366 -- <dispatching-call>;
10367 -- <triggering-statements>
10371 -- Ada.Tags.Get_Offset_Index
10372 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10374 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10376 -- if C = POK_Protected_Entry
10377 -- or else C = POK_Task_Entry
10379 -- Param1 := P.Param1;
10381 -- ParamN := P.ParamN;
10385 -- if C = POK_Procedure
10386 -- or else C = POK_Protected_Procedure
10387 -- or else C = POK_Task_Procedure
10389 -- <dispatching-call>;
10392 -- <triggering-statements>
10394 -- <timed-statements>
10399 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10400 Loc : constant Source_Ptr := Sloc (N);
10402 E_Call : Node_Id :=
10403 Entry_Call_Statement (Entry_Call_Alternative (N));
10404 E_Stats : constant List_Id :=
10405 Statements (Entry_Call_Alternative (N));
10406 D_Stat : Node_Id :=
10407 Delay_Statement (Delay_Alternative (N));
10408 D_Stats : constant List_Id :=
10409 Statements (Delay_Alternative (N));
10412 Blk_Typ : Entity_Id;
10414 Call_Ent : Entity_Id;
10415 Conc_Typ_Stmts : List_Id;
10419 D_Type : Entity_Id;
10425 Is_Disp_Select : Boolean;
10426 Lim_Typ_Stmts : List_Id;
10435 B : Entity_Id; -- Call status flag
10436 C : Entity_Id; -- Call kind
10437 D : Entity_Id; -- Delay
10438 K : Entity_Id; -- Tagged kind
10439 M : Entity_Id; -- Delay mode
10440 P : Entity_Id; -- Parameter block
10441 S : Entity_Id; -- Primitive operation slot
10444 -- Under the Ravenscar profile, timed entry calls are excluded. An error
10445 -- was already reported on spec, so do not attempt to expand the call.
10447 if Restriction_Active (No_Select_Statements) then
10451 -- The arguments in the call may require dynamic allocation, and the
10452 -- call statement may have been transformed into a block. The block
10453 -- may contain additional declarations for internal entities, and the
10454 -- original call is found by sequential search.
10456 if Nkind (E_Call) = N_Block_Statement then
10457 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10458 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10459 N_Entry_Call_Statement)
10466 Ada_Version >= Ada_05
10467 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10469 if Is_Disp_Select then
10470 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
10476 -- B : Boolean := False;
10478 B := Build_B (Loc, Decls);
10481 -- C : Ada.Tags.Prim_Op_Kind;
10483 C := Build_C (Loc, Decls);
10485 -- Because the analysis of all statements was disabled, manually
10486 -- analyze the delay statement.
10489 D_Stat := Original_Node (D_Stat);
10492 -- Build an entry call using Simple_Entry_Call
10494 Extract_Entry (E_Call, Concval, Ename, Index);
10495 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
10497 Decls := Declarations (E_Call);
10498 Stmts := Statements (Handled_Statement_Sequence (E_Call));
10507 B := Make_Defining_Identifier (Loc, Name_uB);
10510 Make_Object_Declaration (Loc,
10511 Defining_Identifier =>
10513 Object_Definition =>
10514 New_Reference_To (Standard_Boolean, Loc)));
10517 -- Duration and mode processing
10519 D_Type := Base_Type (Etype (Expression (D_Stat)));
10521 -- Use the type of the delay expression (Calendar or Real_Time) to
10522 -- generate the appropriate conversion.
10524 if Nkind (D_Stat) = N_Delay_Relative_Statement then
10525 D_Disc := Make_Integer_Literal (Loc, 0);
10526 D_Conv := Relocate_Node (Expression (D_Stat));
10528 elsif Is_RTE (D_Type, RO_CA_Time) then
10529 D_Disc := Make_Integer_Literal (Loc, 1);
10530 D_Conv := Make_Function_Call (Loc,
10531 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10532 New_List (New_Copy (Expression (D_Stat))));
10534 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
10535 D_Disc := Make_Integer_Literal (Loc, 2);
10536 D_Conv := Make_Function_Call (Loc,
10537 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10538 New_List (New_Copy (Expression (D_Stat))));
10541 D := Make_Temporary (Loc, 'D');
10547 Make_Object_Declaration (Loc,
10548 Defining_Identifier =>
10550 Object_Definition =>
10551 New_Reference_To (Standard_Duration, Loc)));
10553 M := Make_Temporary (Loc, 'M');
10556 -- M : Integer := (0 | 1 | 2);
10559 Make_Object_Declaration (Loc,
10560 Defining_Identifier =>
10562 Object_Definition =>
10563 New_Reference_To (Standard_Integer, Loc),
10567 -- Do the assignment at this stage only because the evaluation of the
10568 -- expression must not occur before (see ACVC C97302A).
10571 Make_Assignment_Statement (Loc,
10573 New_Reference_To (D, Loc),
10577 -- Parameter block processing
10579 -- Manually create the parameter block for dispatching calls. In the
10580 -- case of entries, the block has already been created during the call
10581 -- to Build_Simple_Entry_Call.
10583 if Is_Disp_Select then
10585 -- Tagged kind processing, generate:
10586 -- K : Ada.Tags.Tagged_Kind :=
10587 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
10589 K := Build_K (Loc, Decls, Obj);
10591 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
10592 P := Parameter_Block_Pack
10593 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
10595 -- Dispatch table slot processing, generate:
10598 S := Build_S (Loc, Decls);
10601 -- S := Ada.Tags.Get_Offset_Index
10602 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
10605 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
10608 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
10610 -- where Obj is the controlling formal parameter, S is the dispatch
10611 -- table slot number of the dispatching operation, P is the wrapped
10612 -- parameter block, D is the duration, M is the duration mode, C is
10613 -- the call kind and B is the call status.
10615 Params := New_List;
10617 Append_To (Params, New_Copy_Tree (Obj));
10618 Append_To (Params, New_Reference_To (S, Loc));
10619 Append_To (Params, Make_Attribute_Reference (Loc,
10620 Prefix => New_Reference_To (P, Loc),
10621 Attribute_Name => Name_Address));
10622 Append_To (Params, New_Reference_To (D, Loc));
10623 Append_To (Params, New_Reference_To (M, Loc));
10624 Append_To (Params, New_Reference_To (C, Loc));
10625 Append_To (Params, New_Reference_To (B, Loc));
10627 Append_To (Conc_Typ_Stmts,
10628 Make_Procedure_Call_Statement (Loc,
10631 Find_Prim_Op (Etype (Etype (Obj)),
10632 Name_uDisp_Timed_Select),
10634 Parameter_Associations =>
10638 -- if C = POK_Protected_Entry
10639 -- or else C = POK_Task_Entry
10641 -- Param1 := P.Param1;
10643 -- ParamN := P.ParamN;
10646 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
10648 -- Generate the if statement only when the packed parameters need
10649 -- explicit assignments to their corresponding actuals.
10651 if Present (Unpack) then
10652 Append_To (Conc_Typ_Stmts,
10653 Make_If_Statement (Loc,
10660 New_Reference_To (C, Loc),
10662 New_Reference_To (RTE (
10663 RE_POK_Protected_Entry), Loc)),
10667 New_Reference_To (C, Loc),
10669 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
10678 -- if C = POK_Procedure
10679 -- or else C = POK_Protected_Procedure
10680 -- or else C = POK_Task_Procedure
10682 -- <dispatching-call>
10684 -- <triggering-statements>
10686 -- <timed-statements>
10689 N_Stats := New_Copy_List_Tree (E_Stats);
10691 Prepend_To (N_Stats,
10692 Make_If_Statement (Loc,
10699 New_Reference_To (C, Loc),
10701 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
10707 New_Reference_To (C, Loc),
10709 New_Reference_To (RTE (
10710 RE_POK_Protected_Procedure), Loc)),
10714 New_Reference_To (C, Loc),
10716 New_Reference_To (RTE (
10717 RE_POK_Task_Procedure), Loc)))),
10720 New_List (E_Call)));
10722 Append_To (Conc_Typ_Stmts,
10723 Make_If_Statement (Loc,
10724 Condition => New_Reference_To (B, Loc),
10725 Then_Statements => N_Stats,
10726 Else_Statements => D_Stats));
10729 -- <dispatching-call>;
10730 -- <triggering-statements>
10732 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
10733 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
10736 -- if K = Ada.Tags.TK_Limited_Tagged then
10743 Make_If_Statement (Loc,
10747 New_Reference_To (K, Loc),
10749 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
10758 -- Skip assignments to temporaries created for in-out parameters.
10759 -- This makes unwarranted assumptions about the shape of the expanded
10760 -- tree for the call, and should be cleaned up ???
10762 Stmt := First (Stmts);
10763 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
10767 -- Do the assignment at this stage only because the evaluation
10768 -- of the expression must not occur before (see ACVC C97302A).
10770 Insert_Before (Stmt,
10771 Make_Assignment_Statement (Loc,
10772 Name => New_Reference_To (D, Loc),
10773 Expression => D_Conv));
10776 Params := Parameter_Associations (Call);
10778 -- For a protected type, we build a Timed_Protected_Entry_Call
10780 if Is_Protected_Type (Etype (Concval)) then
10782 -- Create a new call statement
10784 Param := First (Params);
10785 while Present (Param)
10786 and then not Is_RTE (Etype (Param), RE_Call_Modes)
10791 Dummy := Remove_Next (Next (Param));
10793 -- Remove garbage is following the Cancel_Param if present
10795 Dummy := Next (Param);
10797 -- Remove the mode of the Protected_Entry_Call call, then remove
10798 -- the Communication_Block of the Protected_Entry_Call call, and
10799 -- finally add Duration and a Delay_Mode parameter
10801 pragma Assert (Present (Param));
10802 Rewrite (Param, New_Reference_To (D, Loc));
10804 Rewrite (Dummy, New_Reference_To (M, Loc));
10806 -- Add a Boolean flag for successful entry call
10808 Append_To (Params, New_Reference_To (B, Loc));
10810 case Corresponding_Runtime_Package (Etype (Concval)) is
10811 when System_Tasking_Protected_Objects_Entries =>
10813 Make_Procedure_Call_Statement (Loc,
10816 (RTE (RE_Timed_Protected_Entry_Call), Loc),
10817 Parameter_Associations => Params));
10819 when System_Tasking_Protected_Objects_Single_Entry =>
10820 Param := First (Params);
10821 while Present (Param)
10823 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
10831 Make_Procedure_Call_Statement (Loc,
10832 Name => New_Reference_To (
10833 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
10834 Parameter_Associations => Params));
10837 raise Program_Error;
10840 -- For the task case, build a Timed_Task_Entry_Call
10843 -- Create a new call statement
10845 Append_To (Params, New_Reference_To (D, Loc));
10846 Append_To (Params, New_Reference_To (M, Loc));
10847 Append_To (Params, New_Reference_To (B, Loc));
10850 Make_Procedure_Call_Statement (Loc,
10852 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
10853 Parameter_Associations => Params));
10857 Make_Implicit_If_Statement (N,
10858 Condition => New_Reference_To (B, Loc),
10859 Then_Statements => E_Stats,
10860 Else_Statements => D_Stats));
10864 Make_Block_Statement (Loc,
10865 Declarations => Decls,
10866 Handled_Statement_Sequence =>
10867 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
10870 end Expand_N_Timed_Entry_Call;
10872 ----------------------------------------
10873 -- Expand_Protected_Body_Declarations --
10874 ----------------------------------------
10876 procedure Expand_Protected_Body_Declarations
10878 Spec_Id : Entity_Id)
10881 if No_Run_Time_Mode then
10882 Error_Msg_CRT ("protected body", N);
10885 elsif Expander_Active then
10887 -- Associate discriminals with the first subprogram or entry body to
10890 if Present (First_Protected_Operation (Declarations (N))) then
10891 Set_Discriminals (Parent (Spec_Id));
10894 end Expand_Protected_Body_Declarations;
10896 -------------------------
10897 -- External_Subprogram --
10898 -------------------------
10900 function External_Subprogram (E : Entity_Id) return Entity_Id is
10901 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10904 -- The internal and external subprograms follow each other on the entity
10905 -- chain. Note that previously private operations had no separate
10906 -- external subprogram. We now create one in all cases, because a
10907 -- private operation may actually appear in an external call, through
10908 -- a 'Access reference used for a callback.
10910 -- If the operation is a function that returns an anonymous access type,
10911 -- the corresponding itype appears before the operation, and must be
10914 -- This mechanism is fragile, there should be a real link between the
10915 -- two versions of the operation, but there is no place to put it ???
10917 if Is_Access_Type (Next_Entity (Subp)) then
10918 return Next_Entity (Next_Entity (Subp));
10920 return Next_Entity (Subp);
10922 end External_Subprogram;
10924 ------------------------------
10925 -- Extract_Dispatching_Call --
10926 ------------------------------
10928 procedure Extract_Dispatching_Call
10930 Call_Ent : out Entity_Id;
10931 Object : out Entity_Id;
10932 Actuals : out List_Id;
10933 Formals : out List_Id)
10935 Call_Nam : Node_Id;
10938 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10940 if Present (Original_Node (N)) then
10941 Call_Nam := Name (Original_Node (N));
10943 Call_Nam := Name (N);
10946 -- Retrieve the name of the dispatching procedure. It contains the
10947 -- dispatch table slot number.
10950 case Nkind (Call_Nam) is
10951 when N_Identifier =>
10954 when N_Selected_Component =>
10955 Call_Nam := Selector_Name (Call_Nam);
10958 raise Program_Error;
10963 Actuals := Parameter_Associations (N);
10964 Call_Ent := Entity (Call_Nam);
10965 Formals := Parameter_Specifications (Parent (Call_Ent));
10966 Object := First (Actuals);
10968 if Present (Original_Node (Object)) then
10969 Object := Original_Node (Object);
10971 end Extract_Dispatching_Call;
10973 -------------------
10974 -- Extract_Entry --
10975 -------------------
10977 procedure Extract_Entry
10979 Concval : out Node_Id;
10980 Ename : out Node_Id;
10981 Index : out Node_Id)
10983 Nam : constant Node_Id := Name (N);
10986 -- For a simple entry, the name is a selected component, with the
10987 -- prefix being the task value, and the selector being the entry.
10989 if Nkind (Nam) = N_Selected_Component then
10990 Concval := Prefix (Nam);
10991 Ename := Selector_Name (Nam);
10994 -- For a member of an entry family, the name is an indexed component
10995 -- where the prefix is a selected component, whose prefix in turn is
10996 -- the task value, and whose selector is the entry family. The single
10997 -- expression in the expressions list of the indexed component is the
10998 -- subscript for the family.
11000 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11001 Concval := Prefix (Prefix (Nam));
11002 Ename := Selector_Name (Prefix (Nam));
11003 Index := First (Expressions (Nam));
11007 -------------------
11008 -- Family_Offset --
11009 -------------------
11011 function Family_Offset
11016 Cap : Boolean) return Node_Id
11022 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11023 -- If one of the bounds is a reference to a discriminant, replace with
11024 -- corresponding discriminal of type. Within the body of a task retrieve
11025 -- the renamed discriminant by simple visibility, using its generated
11026 -- name. Within a protected object, find the original discriminant and
11027 -- replace it with the discriminal of the current protected operation.
11029 ------------------------------
11030 -- Convert_Discriminant_Ref --
11031 ------------------------------
11033 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11034 Loc : constant Source_Ptr := Sloc (Bound);
11039 if Is_Entity_Name (Bound)
11040 and then Ekind (Entity (Bound)) = E_Discriminant
11042 if Is_Task_Type (Ttyp)
11043 and then Has_Completion (Ttyp)
11045 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11046 Find_Direct_Name (B);
11048 elsif Is_Protected_Type (Ttyp) then
11049 D := First_Discriminant (Ttyp);
11050 while Chars (D) /= Chars (Entity (Bound)) loop
11051 Next_Discriminant (D);
11054 B := New_Reference_To (Discriminal (D), Loc);
11057 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11060 elsif Nkind (Bound) = N_Attribute_Reference then
11064 B := New_Copy_Tree (Bound);
11068 Make_Attribute_Reference (Loc,
11069 Attribute_Name => Name_Pos,
11070 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11071 Expressions => New_List (B));
11072 end Convert_Discriminant_Ref;
11074 -- Start of processing for Family_Offset
11077 Real_Hi := Convert_Discriminant_Ref (Hi);
11078 Real_Lo := Convert_Discriminant_Ref (Lo);
11081 if Is_Task_Type (Ttyp) then
11082 Ityp := RTE (RE_Task_Entry_Index);
11084 Ityp := RTE (RE_Protected_Entry_Index);
11088 Make_Attribute_Reference (Loc,
11089 Prefix => New_Reference_To (Ityp, Loc),
11090 Attribute_Name => Name_Min,
11091 Expressions => New_List (
11093 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11096 Make_Attribute_Reference (Loc,
11097 Prefix => New_Reference_To (Ityp, Loc),
11098 Attribute_Name => Name_Max,
11099 Expressions => New_List (
11101 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11104 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11111 function Family_Size
11116 Cap : Boolean) return Node_Id
11121 if Is_Task_Type (Ttyp) then
11122 Ityp := RTE (RE_Task_Entry_Index);
11124 Ityp := RTE (RE_Protected_Entry_Index);
11128 Make_Attribute_Reference (Loc,
11129 Prefix => New_Reference_To (Ityp, Loc),
11130 Attribute_Name => Name_Max,
11131 Expressions => New_List (
11134 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11136 Make_Integer_Literal (Loc, 1)),
11137 Make_Integer_Literal (Loc, 0)));
11140 -----------------------------------
11141 -- Find_Task_Or_Protected_Pragma --
11142 -----------------------------------
11144 function Find_Task_Or_Protected_Pragma
11146 P : Name_Id) return Node_Id
11151 N := First (Visible_Declarations (T));
11152 while Present (N) loop
11153 if Nkind (N) = N_Pragma then
11154 if Pragma_Name (N) = P then
11157 elsif P = Name_Priority
11158 and then Pragma_Name (N) = Name_Interrupt_Priority
11171 N := First (Private_Declarations (T));
11172 while Present (N) loop
11173 if Nkind (N) = N_Pragma then
11174 if Pragma_Name (N) = P then
11177 elsif P = Name_Priority
11178 and then Pragma_Name (N) = Name_Interrupt_Priority
11191 raise Program_Error;
11192 end Find_Task_Or_Protected_Pragma;
11194 -------------------------------
11195 -- First_Protected_Operation --
11196 -------------------------------
11198 function First_Protected_Operation (D : List_Id) return Node_Id is
11199 First_Op : Node_Id;
11202 First_Op := First (D);
11203 while Present (First_Op)
11204 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11210 end First_Protected_Operation;
11212 ---------------------------------------
11213 -- Install_Private_Data_Declarations --
11214 ---------------------------------------
11216 procedure Install_Private_Data_Declarations
11218 Spec_Id : Entity_Id;
11219 Conc_Typ : Entity_Id;
11220 Body_Nod : Node_Id;
11222 Barrier : Boolean := False;
11223 Family : Boolean := False)
11225 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11228 Insert_Node : Node_Id := Empty;
11229 Obj_Ent : Entity_Id;
11231 procedure Add (Decl : Node_Id);
11232 -- Add a single declaration after Insert_Node. If this is the first
11233 -- addition, Decl is added to the front of Decls and it becomes the
11236 function Replace_Bound (Bound : Node_Id) return Node_Id;
11237 -- The bounds of an entry index may depend on discriminants, create a
11238 -- reference to the corresponding prival. Otherwise return a duplicate
11239 -- of the original bound.
11245 procedure Add (Decl : Node_Id) is
11247 if No (Insert_Node) then
11248 Prepend_To (Decls, Decl);
11250 Insert_After (Insert_Node, Decl);
11253 Insert_Node := Decl;
11256 --------------------------
11257 -- Replace_Discriminant --
11258 --------------------------
11260 function Replace_Bound (Bound : Node_Id) return Node_Id is
11262 if Nkind (Bound) = N_Identifier
11263 and then Is_Discriminal (Entity (Bound))
11265 return Make_Identifier (Loc, Chars (Entity (Bound)));
11267 return Duplicate_Subexpr (Bound);
11271 -- Start of processing for Install_Private_Data_Declarations
11274 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11275 -- formal parameter _O, _object or _task depending on the context.
11277 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11279 -- Special processing of _O for barrier functions, protected entries
11286 (Ekind (Spec_Id) = E_Entry
11287 or else Ekind (Spec_Id) = E_Entry_Family))
11290 Conc_Rec : constant Entity_Id :=
11291 Corresponding_Record_Type (Conc_Typ);
11292 Typ_Id : constant Entity_Id :=
11293 Make_Defining_Identifier (Loc,
11294 New_External_Name (Chars (Conc_Rec), 'P'));
11297 -- type prot_typVP is access prot_typV;
11300 Make_Full_Type_Declaration (Loc,
11301 Defining_Identifier => Typ_Id,
11303 Make_Access_To_Object_Definition (Loc,
11304 Subtype_Indication =>
11305 New_Reference_To (Conc_Rec, Loc)));
11309 -- _object : prot_typVP := prot_typV (_O);
11312 Make_Object_Declaration (Loc,
11313 Defining_Identifier =>
11314 Make_Defining_Identifier (Loc, Name_uObject),
11315 Object_Definition => New_Reference_To (Typ_Id, Loc),
11317 Unchecked_Convert_To (Typ_Id,
11318 New_Reference_To (Obj_Ent, Loc)));
11321 -- Set the reference to the concurrent object
11323 Obj_Ent := Defining_Identifier (Decl);
11327 -- Step 2: Create the Protection object and build its declaration for
11328 -- any protected entry (family) of subprogram.
11330 if Is_Protected then
11332 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
11336 Set_Protection_Object (Spec_Id, Prot_Ent);
11338 -- Determine the proper protection type
11340 if Has_Attach_Handler (Conc_Typ)
11341 and then not Restricted_Profile
11343 Prot_Typ := RE_Static_Interrupt_Protection;
11345 elsif Has_Interrupt_Handler (Conc_Typ) then
11346 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11348 -- The type has explicit entries or generated primitive entry
11351 elsif Has_Entries (Conc_Typ)
11353 (Ada_Version >= Ada_05
11354 and then Present (Interface_List (Parent (Conc_Typ))))
11356 case Corresponding_Runtime_Package (Conc_Typ) is
11357 when System_Tasking_Protected_Objects_Entries =>
11358 Prot_Typ := RE_Protection_Entries;
11360 when System_Tasking_Protected_Objects_Single_Entry =>
11361 Prot_Typ := RE_Protection_Entry;
11364 raise Program_Error;
11368 Prot_Typ := RE_Protection;
11372 -- conc_typR : protection_typ renames _object._object;
11375 Make_Object_Renaming_Declaration (Loc,
11376 Defining_Identifier => Prot_Ent,
11378 New_Reference_To (RTE (Prot_Typ), Loc),
11380 Make_Selected_Component (Loc,
11382 New_Reference_To (Obj_Ent, Loc),
11384 Make_Identifier (Loc, Name_uObject)));
11389 -- Step 3: Add discriminant renamings (if any)
11391 if Has_Discriminants (Conc_Typ) then
11396 D := First_Discriminant (Conc_Typ);
11397 while Present (D) loop
11399 -- Adjust the source location
11401 Set_Sloc (Discriminal (D), Loc);
11404 -- discr_name : discr_typ renames _object.discr_name;
11406 -- discr_name : discr_typ renames _task.discr_name;
11409 Make_Object_Renaming_Declaration (Loc,
11410 Defining_Identifier => Discriminal (D),
11411 Subtype_Mark => New_Reference_To (Etype (D), Loc),
11413 Make_Selected_Component (Loc,
11414 Prefix => New_Reference_To (Obj_Ent, Loc),
11415 Selector_Name => Make_Identifier (Loc, Chars (D))));
11418 Next_Discriminant (D);
11423 -- Step 4: Add private component renamings (if any)
11425 if Is_Protected then
11426 Def := Protected_Definition (Parent (Conc_Typ));
11428 if Present (Private_Declarations (Def)) then
11431 Comp_Id : Entity_Id;
11432 Decl_Id : Entity_Id;
11435 Comp := First (Private_Declarations (Def));
11436 while Present (Comp) loop
11437 if Nkind (Comp) = N_Component_Declaration then
11438 Comp_Id := Defining_Identifier (Comp);
11440 Make_Defining_Identifier (Loc, Chars (Comp_Id));
11442 -- Minimal decoration
11444 if Ekind (Spec_Id) = E_Function then
11445 Set_Ekind (Decl_Id, E_Constant);
11447 Set_Ekind (Decl_Id, E_Variable);
11450 Set_Prival (Comp_Id, Decl_Id);
11451 Set_Prival_Link (Decl_Id, Comp_Id);
11452 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
11455 -- comp_name : comp_typ renames _object.comp_name;
11458 Make_Object_Renaming_Declaration (Loc,
11459 Defining_Identifier => Decl_Id,
11461 New_Reference_To (Etype (Comp_Id), Loc),
11463 Make_Selected_Component (Loc,
11465 New_Reference_To (Obj_Ent, Loc),
11467 Make_Identifier (Loc, Chars (Comp_Id))));
11477 -- Step 5: Add the declaration of the entry index and the associated
11478 -- type for barrier functions and entry families.
11480 if (Barrier and then Family)
11481 or else Ekind (Spec_Id) = E_Entry_Family
11484 E : constant Entity_Id := Index_Object (Spec_Id);
11485 Index : constant Entity_Id :=
11486 Defining_Identifier (
11487 Entry_Index_Specification (
11488 Entry_Body_Formal_Part (Body_Nod)));
11489 Index_Con : constant Entity_Id :=
11490 Make_Defining_Identifier (Loc, Chars (Index));
11492 Index_Typ : Entity_Id;
11496 -- Minimal decoration
11498 Set_Ekind (Index_Con, E_Constant);
11499 Set_Entry_Index_Constant (Index, Index_Con);
11500 Set_Discriminal_Link (Index_Con, Index);
11502 -- Retrieve the bounds of the entry family
11504 High := Type_High_Bound (Etype (Index));
11505 Low := Type_Low_Bound (Etype (Index));
11507 -- In the simple case the entry family is given by a subtype
11508 -- mark and the index constant has the same type.
11510 if Is_Entity_Name (Original_Node (
11511 Discrete_Subtype_Definition (Parent (Index))))
11513 Index_Typ := Etype (Index);
11515 -- Otherwise a new subtype declaration is required
11518 High := Replace_Bound (High);
11519 Low := Replace_Bound (Low);
11521 Index_Typ := Make_Temporary (Loc, 'J');
11524 -- subtype Jnn is <Etype of Index> range Low .. High;
11527 Make_Subtype_Declaration (Loc,
11528 Defining_Identifier => Index_Typ,
11529 Subtype_Indication =>
11530 Make_Subtype_Indication (Loc,
11532 New_Reference_To (Base_Type (Etype (Index)), Loc),
11534 Make_Range_Constraint (Loc,
11535 Range_Expression =>
11536 Make_Range (Loc, Low, High))));
11540 Set_Etype (Index_Con, Index_Typ);
11542 -- Create the object which designates the index:
11543 -- J : constant Jnn :=
11544 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
11546 -- where Jnn is the subtype created above or the original type of
11547 -- the index, _E is a formal of the protected body subprogram and
11548 -- <index expr> is the index of the first family member.
11551 Make_Object_Declaration (Loc,
11552 Defining_Identifier => Index_Con,
11553 Constant_Present => True,
11554 Object_Definition =>
11555 New_Reference_To (Index_Typ, Loc),
11558 Make_Attribute_Reference (Loc,
11560 New_Reference_To (Index_Typ, Loc),
11561 Attribute_Name => Name_Val,
11563 Expressions => New_List (
11567 Make_Op_Subtract (Loc,
11569 New_Reference_To (E, Loc),
11571 Entry_Index_Expression (Loc,
11572 Defining_Identifier (Body_Nod),
11576 Make_Attribute_Reference (Loc,
11578 New_Reference_To (Index_Typ, Loc),
11579 Attribute_Name => Name_Pos,
11580 Expressions => New_List (
11581 Make_Attribute_Reference (Loc,
11583 New_Reference_To (Index_Typ, Loc),
11584 Attribute_Name => Name_First)))))));
11588 end Install_Private_Data_Declarations;
11590 ---------------------------------
11591 -- Is_Potentially_Large_Family --
11592 ---------------------------------
11594 function Is_Potentially_Large_Family
11595 (Base_Index : Entity_Id;
11596 Conctyp : Entity_Id;
11598 Hi : Node_Id) return Boolean
11601 return Scope (Base_Index) = Standard_Standard
11602 and then Base_Index = Base_Type (Standard_Integer)
11603 and then Has_Discriminants (Conctyp)
11605 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
11607 (Denotes_Discriminant (Lo, True)
11608 or else Denotes_Discriminant (Hi, True));
11609 end Is_Potentially_Large_Family;
11611 -------------------------------------
11612 -- Is_Private_Primitive_Subprogram --
11613 -------------------------------------
11615 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
11618 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
11619 and then Is_Private_Primitive (Id);
11620 end Is_Private_Primitive_Subprogram;
11626 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
11627 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
11628 Formal : Entity_Id;
11631 Formal := First_Formal (Bod_Subp);
11632 while Present (Formal) loop
11634 -- Look for formal parameter _E
11636 if Chars (Formal) = Name_uE then
11640 Next_Formal (Formal);
11643 -- A protected body subprogram should always have the parameter in
11646 raise Program_Error;
11649 --------------------------------
11650 -- Make_Initialize_Protection --
11651 --------------------------------
11653 function Make_Initialize_Protection
11654 (Protect_Rec : Entity_Id) return List_Id
11656 Loc : constant Source_Ptr := Sloc (Protect_Rec);
11660 Ptyp : constant Node_Id :=
11661 Corresponding_Concurrent_Type (Protect_Rec);
11663 L : constant List_Id := New_List;
11664 Has_Entry : constant Boolean := Has_Entries (Ptyp);
11665 Restricted : constant Boolean := Restricted_Profile;
11668 -- We may need two calls to properly initialize the object, one to
11669 -- Initialize_Protection, and possibly one to Install_Handlers if we
11670 -- have a pragma Attach_Handler.
11672 -- Get protected declaration. In the case of a task type declaration,
11673 -- this is simply the parent of the protected type entity. In the single
11674 -- protected object declaration, this parent will be the implicit type,
11675 -- and we can find the corresponding single protected object declaration
11676 -- by searching forward in the declaration list in the tree.
11678 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
11679 -- of this type should have been removed during semantic analysis.
11681 Pdec := Parent (Ptyp);
11682 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
11683 N_Single_Protected_Declaration)
11688 -- Now we can find the object definition from this declaration
11690 Pdef := Protected_Definition (Pdec);
11692 -- Build the parameter list for the call. Note that _Init is the name
11693 -- of the formal for the object to be initialized, which is the task
11694 -- value record itself.
11698 -- Object parameter. This is a pointer to the object of type
11699 -- Protection used by the GNARL to control the protected object.
11702 Make_Attribute_Reference (Loc,
11704 Make_Selected_Component (Loc,
11705 Prefix => Make_Identifier (Loc, Name_uInit),
11706 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11707 Attribute_Name => Name_Unchecked_Access));
11709 -- Priority parameter. Set to Unspecified_Priority unless there is a
11710 -- priority pragma, in which case we take the value from the pragma,
11711 -- or there is an interrupt pragma and no priority pragma, and we
11712 -- set the ceiling to Interrupt_Priority'Last, an implementation-
11713 -- defined value, see D.3(10).
11716 and then Has_Priority_Pragma (Pdef)
11719 Prio : constant Node_Id :=
11722 (Pragma_Argument_Associations
11723 (Find_Task_Or_Protected_Pragma
11724 (Pdef, Name_Priority))));
11728 -- If priority is a static expression, then we can duplicate it
11729 -- with no problem and simply append it to the argument list.
11731 if Is_Static_Expression (Prio) then
11733 Duplicate_Subexpr_No_Checks (Prio));
11735 -- Otherwise, the priority may be a per-object expression, if it
11736 -- depends on a discriminant of the type. In this case, create
11737 -- local variable to capture the expression. Note that it is
11738 -- really necessary to create this variable explicitly. It might
11739 -- be thought that removing side effects would the appropriate
11740 -- approach, but that could generate declarations improperly
11741 -- placed in the enclosing scope.
11743 -- Note: Use System.Any_Priority as the expected type for the
11744 -- non-static priority expression, in case the expression has not
11745 -- been analyzed yet (as occurs for example with pragma
11746 -- Interrupt_Priority).
11749 Temp := Make_Temporary (Loc, 'R', Prio);
11751 Make_Object_Declaration (Loc,
11752 Defining_Identifier => Temp,
11753 Object_Definition =>
11754 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
11755 Expression => Relocate_Node (Prio)));
11757 Append_To (Args, New_Occurrence_Of (Temp, Loc));
11761 -- When no priority is specified but an xx_Handler pragma is, we default
11762 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
11764 elsif Has_Interrupt_Handler (Ptyp)
11765 or else Has_Attach_Handler (Ptyp)
11768 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
11770 -- Normal case, no priority or xx_Handler specified, default priority
11774 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11777 -- Test for Compiler_Info parameter. This parameter allows entry body
11778 -- procedures and barrier functions to be called from the runtime. It
11779 -- is a pointer to the record generated by the compiler to represent
11780 -- the protected object.
11783 or else Has_Interrupt_Handler (Ptyp)
11784 or else Has_Attach_Handler (Ptyp)
11785 or else Has_Interfaces (Protect_Rec)
11788 Pkg_Id : constant RTU_Id :=
11789 Corresponding_Runtime_Package (Ptyp);
11790 Called_Subp : RE_Id;
11794 when System_Tasking_Protected_Objects_Entries =>
11795 Called_Subp := RE_Initialize_Protection_Entries;
11797 when System_Tasking_Protected_Objects =>
11798 Called_Subp := RE_Initialize_Protection;
11800 when System_Tasking_Protected_Objects_Single_Entry =>
11801 Called_Subp := RE_Initialize_Protection_Entry;
11804 raise Program_Error;
11807 if Has_Entry or else not Restricted then
11809 Make_Attribute_Reference (Loc,
11810 Prefix => Make_Identifier (Loc, Name_uInit),
11811 Attribute_Name => Name_Address));
11814 -- Entry_Bodies parameter. This is a pointer to an array of
11815 -- pointers to the entry body procedures and barrier functions of
11816 -- the object. If the protected type has no entries this object
11817 -- will not exist, in this case, pass a null.
11820 P_Arr := Entry_Bodies_Array (Ptyp);
11823 Make_Attribute_Reference (Loc,
11824 Prefix => New_Reference_To (P_Arr, Loc),
11825 Attribute_Name => Name_Unrestricted_Access));
11827 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
11829 -- Find index mapping function (clumsy but ok for now)
11831 while Ekind (P_Arr) /= E_Function loop
11832 Next_Entity (P_Arr);
11836 Make_Attribute_Reference (Loc,
11838 New_Reference_To (P_Arr, Loc),
11839 Attribute_Name => Name_Unrestricted_Access));
11841 -- Build_Entry_Names generation flag. When set to true, the
11842 -- runtime will allocate an array to hold the string names
11843 -- of protected entries.
11845 if not Restricted_Profile then
11846 if Entry_Names_OK then
11848 New_Reference_To (Standard_True, Loc));
11851 New_Reference_To (Standard_False, Loc));
11856 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
11857 Append_To (Args, Make_Null (Loc));
11859 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
11860 Append_To (Args, Make_Null (Loc));
11861 Append_To (Args, Make_Null (Loc));
11862 Append_To (Args, New_Reference_To (Standard_False, Loc));
11866 Make_Procedure_Call_Statement (Loc,
11867 Name => New_Reference_To (RTE (Called_Subp), Loc),
11868 Parameter_Associations => Args));
11872 Make_Procedure_Call_Statement (Loc,
11873 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
11874 Parameter_Associations => Args));
11877 if Has_Attach_Handler (Ptyp) then
11879 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
11880 -- make the following call:
11882 -- Install_Handlers (_object,
11883 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11885 -- or, in the case of Ravenscar:
11887 -- Install_Restricted_Handlers
11888 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11891 Args : constant List_Id := New_List;
11892 Table : constant List_Id := New_List;
11893 Ritem : Node_Id := First_Rep_Item (Ptyp);
11896 -- Build the Attach_Handler table argument
11898 while Present (Ritem) loop
11899 if Nkind (Ritem) = N_Pragma
11900 and then Pragma_Name (Ritem) = Name_Attach_Handler
11903 Handler : constant Node_Id :=
11904 First (Pragma_Argument_Associations (Ritem));
11906 Interrupt : constant Node_Id := Next (Handler);
11907 Expr : constant Node_Id := Expression (Interrupt);
11911 Make_Aggregate (Loc, Expressions => New_List (
11912 Unchecked_Convert_To
11913 (RTE (RE_System_Interrupt_Id), Expr),
11914 Make_Attribute_Reference (Loc,
11915 Prefix => Make_Selected_Component (Loc,
11916 Make_Identifier (Loc, Name_uInit),
11917 Duplicate_Subexpr_No_Checks
11918 (Expression (Handler))),
11919 Attribute_Name => Name_Access))));
11923 Next_Rep_Item (Ritem);
11926 -- Append the table argument we just built
11928 Append_To (Args, Make_Aggregate (Loc, Table));
11930 -- Append the Install_Handlers (or Install_Restricted_Handlers)
11931 -- call to the statements.
11934 -- Call a simplified version of Install_Handlers to be used
11935 -- when the Ravenscar restrictions are in effect
11936 -- (Install_Restricted_Handlers).
11939 Make_Procedure_Call_Statement (Loc,
11942 (RTE (RE_Install_Restricted_Handlers), Loc),
11943 Parameter_Associations => Args));
11946 -- First, prepends the _object argument
11949 Make_Attribute_Reference (Loc,
11951 Make_Selected_Component (Loc,
11952 Prefix => Make_Identifier (Loc, Name_uInit),
11953 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11954 Attribute_Name => Name_Unchecked_Access));
11956 -- Then, insert call to Install_Handlers
11959 Make_Procedure_Call_Statement (Loc,
11960 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
11961 Parameter_Associations => Args));
11967 end Make_Initialize_Protection;
11969 ---------------------------
11970 -- Make_Task_Create_Call --
11971 ---------------------------
11973 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
11974 Loc : constant Source_Ptr := Sloc (Task_Rec);
11984 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
11985 Tnam := Chars (Ttyp);
11987 -- Get task declaration. In the case of a task type declaration, this is
11988 -- simply the parent of the task type entity. In the single task
11989 -- declaration, this parent will be the implicit type, and we can find
11990 -- the corresponding single task declaration by searching forward in the
11991 -- declaration list in the tree.
11993 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
11994 -- this type should have been removed during semantic analysis.
11996 Tdec := Parent (Ttyp);
11997 while not Nkind_In (Tdec, N_Task_Type_Declaration,
11998 N_Single_Task_Declaration)
12003 -- Now we can find the task definition from this declaration
12005 Tdef := Task_Definition (Tdec);
12007 -- Build the parameter list for the call. Note that _Init is the name
12008 -- of the formal for the object to be initialized, which is the task
12009 -- value record itself.
12013 -- Priority parameter. Set to Unspecified_Priority unless there is a
12014 -- priority pragma, in which case we take the value from the pragma.
12016 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
12018 Make_Selected_Component (Loc,
12019 Prefix => Make_Identifier (Loc, Name_uInit),
12020 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12023 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12026 -- Optional Stack parameter
12028 if Restricted_Profile then
12030 -- If the stack has been preallocated by the expander then
12031 -- pass its address. Otherwise, pass a null address.
12033 if Preallocated_Stacks_On_Target then
12035 Make_Attribute_Reference (Loc,
12036 Prefix => Make_Selected_Component (Loc,
12037 Prefix => Make_Identifier (Loc, Name_uInit),
12039 Make_Identifier (Loc, Name_uStack)),
12040 Attribute_Name => Name_Address));
12044 New_Reference_To (RTE (RE_Null_Address), Loc));
12048 -- Size parameter. If no Storage_Size pragma is present, then
12049 -- the size is taken from the taskZ variable for the type, which
12050 -- is either Unspecified_Size, or has been reset by the use of
12051 -- a Storage_Size attribute definition clause. If a pragma is
12052 -- present, then the size is taken from the _Size field of the
12053 -- task value record, which was set from the pragma value.
12056 and then Has_Storage_Size_Pragma (Tdef)
12059 Make_Selected_Component (Loc,
12060 Prefix => Make_Identifier (Loc, Name_uInit),
12061 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12065 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12068 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12069 -- Task_Info pragma, in which case we take the value from the pragma.
12072 and then Has_Task_Info_Pragma (Tdef)
12075 Make_Selected_Component (Loc,
12076 Prefix => Make_Identifier (Loc, Name_uInit),
12077 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12081 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12084 if not Restricted_Profile then
12086 -- Deadline parameter. If no Relative_Deadline pragma is present,
12087 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12088 -- the deadline is taken from the _Relative_Deadline field of the
12089 -- task value record, which was set from the pragma value. Note that
12090 -- this parameter must not be generated for the restricted profiles
12091 -- since Ravenscar does not allow deadlines.
12093 -- Case where pragma Relative_Deadline applies: use given value
12095 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12097 Make_Selected_Component (Loc,
12098 Prefix => Make_Identifier (Loc, Name_uInit),
12100 Make_Identifier (Loc, Name_uRelative_Deadline)));
12102 -- No pragma Relative_Deadline apply to the task
12106 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12109 -- Number of entries. This is an expression of the form:
12111 -- n + _Init.a'Length + _Init.a'B'Length + ...
12113 -- where a,b... are the entry family names for the task definition
12116 Build_Entry_Count_Expression
12121 (Parent (Corresponding_Record_Type (Ttyp))))),
12123 Append_To (Args, Ecount);
12125 -- Master parameter. This is a reference to the _Master parameter of
12126 -- the initialization procedure, except in the case of the pragma
12127 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
12128 -- See comments in System.Tasking.Initialization.Init_RTS for the
12131 if Restriction_Active (No_Task_Hierarchy) = False then
12132 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12134 Append_To (Args, Make_Integer_Literal (Loc, 3));
12138 -- State parameter. This is a pointer to the task body procedure. The
12139 -- required value is obtained by taking 'Unrestricted_Access of the task
12140 -- body procedure and converting it (with an unchecked conversion) to
12141 -- the type required by the task kernel. For further details, see the
12142 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12143 -- than 'Address in order to avoid creating trampolines.
12146 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12147 Subp_Ptr_Typ : constant Node_Id :=
12148 Create_Itype (E_Access_Subprogram_Type, Tdec);
12149 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12152 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12153 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12155 -- Be sure to freeze a reference to the access-to-subprogram type,
12156 -- otherwise gigi will complain that it's in the wrong scope, because
12157 -- it's actually inside the init procedure for the record type that
12158 -- corresponds to the task type.
12160 -- This processing is causing a crash in the .NET/JVM back ends that
12161 -- is not yet understood, so skip it in these cases ???
12163 if VM_Target = No_VM then
12164 Set_Itype (Ref, Subp_Ptr_Typ);
12165 Append_Freeze_Action (Task_Rec, Ref);
12168 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12169 Make_Qualified_Expression (Loc,
12170 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12172 Make_Attribute_Reference (Loc,
12174 New_Occurrence_Of (Body_Proc, Loc),
12175 Attribute_Name => Name_Unrestricted_Access))));
12177 -- For the .NET/JVM cases revert to the original code below ???
12181 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12182 Make_Attribute_Reference (Loc,
12184 New_Occurrence_Of (Body_Proc, Loc),
12185 Attribute_Name => Name_Address)));
12189 -- Discriminants parameter. This is just the address of the task
12190 -- value record itself (which contains the discriminant values
12193 Make_Attribute_Reference (Loc,
12194 Prefix => Make_Identifier (Loc, Name_uInit),
12195 Attribute_Name => Name_Address));
12197 -- Elaborated parameter. This is an access to the elaboration Boolean
12200 Make_Attribute_Reference (Loc,
12201 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12202 Attribute_Name => Name_Unchecked_Access));
12204 -- Chain parameter. This is a reference to the _Chain parameter of
12205 -- the initialization procedure.
12207 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12209 -- Task name parameter. Take this from the _Task_Id parameter to the
12210 -- init call unless there is a Task_Name pragma, in which case we take
12211 -- the value from the pragma.
12214 and then Has_Task_Name_Pragma (Tdef)
12216 -- Copy expression in full, because it may be dynamic and have
12222 (Pragma_Argument_Associations
12223 (Find_Task_Or_Protected_Pragma
12224 (Tdef, Name_Task_Name))))));
12227 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12230 -- Created_Task parameter. This is the _Task_Id field of the task
12234 Make_Selected_Component (Loc,
12235 Prefix => Make_Identifier (Loc, Name_uInit),
12236 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12238 -- Build_Entry_Names generation flag. When set to true, the runtime
12239 -- will allocate an array to hold the string names of task entries.
12241 if not Restricted_Profile then
12242 if Has_Entries (Ttyp)
12243 and then Entry_Names_OK
12245 Append_To (Args, New_Reference_To (Standard_True, Loc));
12247 Append_To (Args, New_Reference_To (Standard_False, Loc));
12251 if Restricted_Profile then
12252 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12254 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12258 Make_Procedure_Call_Statement (Loc,
12260 Parameter_Associations => Args);
12261 end Make_Task_Create_Call;
12263 ------------------------------
12264 -- Next_Protected_Operation --
12265 ------------------------------
12267 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12271 Next_Op := Next (N);
12272 while Present (Next_Op)
12273 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12279 end Next_Protected_Operation;
12281 ---------------------
12282 -- Null_Statements --
12283 ---------------------
12285 function Null_Statements (Stats : List_Id) return Boolean is
12289 Stmt := First (Stats);
12290 while Nkind (Stmt) /= N_Empty
12291 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12293 (Nkind (Stmt) = N_Pragma
12294 and then (Pragma_Name (Stmt) = Name_Unreferenced
12296 Pragma_Name (Stmt) = Name_Unmodified
12298 Pragma_Name (Stmt) = Name_Warnings)))
12303 return Nkind (Stmt) = N_Empty;
12304 end Null_Statements;
12306 --------------------------
12307 -- Parameter_Block_Pack --
12308 --------------------------
12310 function Parameter_Block_Pack
12312 Blk_Typ : Entity_Id;
12316 Stmts : List_Id) return Node_Id
12318 Actual : Entity_Id;
12319 Expr : Node_Id := Empty;
12320 Formal : Entity_Id;
12321 Has_Param : Boolean := False;
12324 Temp_Asn : Node_Id;
12325 Temp_Nam : Node_Id;
12328 Actual := First (Actuals);
12329 Formal := Defining_Identifier (First (Formals));
12330 Params := New_List;
12332 while Present (Actual) loop
12333 if Is_By_Copy_Type (Etype (Actual)) then
12335 -- Jnn : aliased <formal-type>
12337 Temp_Nam := Make_Temporary (Loc, 'J');
12340 Make_Object_Declaration (Loc,
12343 Defining_Identifier =>
12345 Object_Definition =>
12346 New_Reference_To (Etype (Formal), Loc)));
12348 if Ekind (Formal) /= E_Out_Parameter then
12354 New_Reference_To (Temp_Nam, Loc);
12356 Set_Assignment_OK (Temp_Asn);
12359 Make_Assignment_Statement (Loc,
12363 New_Copy_Tree (Actual)));
12367 -- Jnn'unchecked_access
12370 Make_Attribute_Reference (Loc,
12372 Name_Unchecked_Access,
12374 New_Reference_To (Temp_Nam, Loc)));
12378 -- The controlling parameter is omitted
12381 if not Is_Controlling_Actual (Actual) then
12383 Make_Reference (Loc, New_Copy_Tree (Actual)));
12389 Next_Actual (Actual);
12390 Next_Formal_With_Extras (Formal);
12394 Expr := Make_Aggregate (Loc, Params);
12399 -- J1'unchecked_access;
12400 -- <actual2>'reference;
12403 P := Make_Temporary (Loc, 'P');
12406 Make_Object_Declaration (Loc,
12407 Defining_Identifier =>
12409 Object_Definition =>
12410 New_Reference_To (Blk_Typ, Loc),
12415 end Parameter_Block_Pack;
12417 ----------------------------
12418 -- Parameter_Block_Unpack --
12419 ----------------------------
12421 function Parameter_Block_Unpack
12425 Formals : List_Id) return List_Id
12427 Actual : Entity_Id;
12429 Formal : Entity_Id;
12430 Has_Asnmt : Boolean := False;
12431 Result : constant List_Id := New_List;
12434 Actual := First (Actuals);
12435 Formal := Defining_Identifier (First (Formals));
12436 while Present (Actual) loop
12437 if Is_By_Copy_Type (Etype (Actual))
12438 and then Ekind (Formal) /= E_In_Parameter
12441 -- <actual> := P.<formal>;
12444 Make_Assignment_Statement (Loc,
12448 Make_Explicit_Dereference (Loc,
12449 Make_Selected_Component (Loc,
12451 New_Reference_To (P, Loc),
12453 Make_Identifier (Loc, Chars (Formal)))));
12455 Set_Assignment_OK (Name (Asnmt));
12456 Append_To (Result, Asnmt);
12461 Next_Actual (Actual);
12462 Next_Formal_With_Extras (Formal);
12468 return New_List (Make_Null_Statement (Loc));
12470 end Parameter_Block_Unpack;
12472 ----------------------
12473 -- Set_Discriminals --
12474 ----------------------
12476 procedure Set_Discriminals (Dec : Node_Id) is
12479 D_Minal : Entity_Id;
12482 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
12483 Pdef := Defining_Identifier (Dec);
12485 if Has_Discriminants (Pdef) then
12486 D := First_Discriminant (Pdef);
12487 while Present (D) loop
12489 Make_Defining_Identifier (Sloc (D),
12490 Chars => New_External_Name (Chars (D), 'D'));
12492 Set_Ekind (D_Minal, E_Constant);
12493 Set_Etype (D_Minal, Etype (D));
12494 Set_Scope (D_Minal, Pdef);
12495 Set_Discriminal (D, D_Minal);
12496 Set_Discriminal_Link (D_Minal, D);
12498 Next_Discriminant (D);
12501 end Set_Discriminals;
12503 -----------------------
12504 -- Trivial_Accept_OK --
12505 -----------------------
12507 function Trivial_Accept_OK return Boolean is
12509 case Opt.Task_Dispatching_Policy is
12511 -- If we have the default task dispatching policy in effect, we can
12512 -- definitely do the optimization (one way of looking at this is to
12513 -- think of the formal definition of the default policy being allowed
12514 -- to run any task it likes after a rendezvous, so even if notionally
12515 -- a full rescheduling occurs, we can say that our dispatching policy
12516 -- (i.e. the default dispatching policy) reorders the queue to be the
12517 -- same as just before the call.
12522 -- FIFO_Within_Priorities certainly does not permit this
12523 -- optimization since the Rendezvous is a scheduling action that may
12524 -- require some other task to be run.
12529 -- For now, disallow the optimization for all other policies. This
12530 -- may be over-conservative, but it is certainly not incorrect.
12536 end Trivial_Accept_OK;