1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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_Ch6; use Exp_Ch6;
33 with Exp_Ch11; use Exp_Ch11;
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.
76 Entry_Family_Bound : constant Int := 2**16;
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 function Actual_Index_Expression
86 Tsk : Entity_Id) return Node_Id;
87 -- Compute the index position for an entry call. Tsk is the target task. If
88 -- the bounds of some entry family depend on discriminants, the expression
89 -- computed by this function uses the discriminants of the target task.
91 procedure Add_Object_Pointer
95 -- Prepend an object pointer declaration to the declaration list Decls.
96 -- This object pointer is initialized to a type conversion of the System.
97 -- Address pointer passed to entry barrier functions and entry body
100 procedure Add_Formal_Renamings
105 -- Create renaming declarations for the formals, inside the procedure that
106 -- implements an entry body. The renamings make the original names of the
107 -- formals accessible to gdb, and serve no other purpose.
108 -- Spec is the specification of the procedure being built.
109 -- Decls is the list of declarations to be enhanced.
110 -- Ent is the entity for the original entry body.
112 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
113 -- Transform accept statement into a block with added exception handler.
114 -- Used both for simple accept statements and for accept alternatives in
115 -- select statements. Astat is the accept statement.
117 function Build_Barrier_Function
120 Pid : Node_Id) return Node_Id;
121 -- Build the function body returning the value of the barrier expression
122 -- for the specified entry body.
124 function Build_Barrier_Function_Specification
126 Def_Id : Entity_Id) return Node_Id;
127 -- Build a specification for a function implementing the protected entry
128 -- barrier of the specified entry body.
130 function Build_Corresponding_Record
133 Loc : Source_Ptr) return Node_Id;
134 -- Common to tasks and protected types. Copy discriminant specifications,
135 -- build record declaration. N is the type declaration, Ctyp is the
136 -- concurrent entity (task type or protected type).
138 function Build_Entry_Count_Expression
139 (Concurrent_Type : Node_Id;
140 Component_List : List_Id;
141 Loc : Source_Ptr) return Node_Id;
142 -- Compute number of entries for concurrent object. This is a count of
143 -- simple entries, followed by an expression that computes the length
144 -- of the range of each entry family. A single array with that size is
145 -- allocated for each concurrent object of the type.
147 function Build_Parameter_Block
151 Decls : List_Id) return Entity_Id;
152 -- Generate an access type for each actual parameter in the list Actuals.
153 -- Create an encapsulating record that contains all the actuals and return
154 -- its type. Generate:
155 -- type Ann1 is access all <actual1-type>
157 -- type AnnN is access all <actualN-type>
158 -- type Pnn is record
164 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id);
165 -- Build body of wrapper procedure for an entry or entry family that has
166 -- pre/postconditions. The body gathers the PPC's and expands them in the
167 -- usual way, and performs the entry call itself. This way preconditions
168 -- are evaluated before the call is queued. E is the entry in question,
169 -- and Decl is the enclosing synchronized type declaration at whose
170 -- freeze point the generated body is analyzed.
172 function Build_Renamed_Formal_Declaration
176 Renamed_Formal : Node_Id) return Node_Id;
177 -- Create a renaming declaration for a formal, within a protected entry
178 -- body or an accept body. The renamed object is a component of the
179 -- parameter block that is a parameter in the entry call.
181 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
182 -- does not dereference the corresponding component to prevent an illegal
183 -- use of the incomplete type (AI05-0151).
185 procedure Build_Wrapper_Bodies
189 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
190 -- record of a concurrent type. N is the insertion node where all bodies
191 -- will be placed. This routine builds the bodies of the subprograms which
192 -- serve as an indirection mechanism to overriding primitives of concurrent
193 -- types, entries and protected procedures. Any new body is analyzed.
195 procedure Build_Wrapper_Specs
199 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
200 -- record of a concurrent type. N is the insertion node where all specs
201 -- will be placed. This routine builds the specs of the subprograms which
202 -- serve as an indirection mechanism to overriding primitives of concurrent
203 -- types, entries and protected procedures. Any new spec is analyzed.
205 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
206 -- Build the function that translates the entry index in the call
207 -- (which depends on the size of entry families) into an index into the
208 -- Entry_Bodies_Array, to determine the body and barrier function used
209 -- in a protected entry call. A pointer to this function appears in every
212 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
213 -- Build subprogram declaration for previous one
215 function Build_Protected_Entry
218 Pid : Node_Id) return Node_Id;
219 -- Build the procedure implementing the statement sequence of the specified
222 function Build_Protected_Entry_Specification
225 Ent_Id : Entity_Id) return Node_Id;
226 -- Build a specification for the procedure implementing the statements of
227 -- the specified entry body. Add attributes associating it with the entry
228 -- defining identifier Ent_Id.
230 function Build_Protected_Spec
232 Obj_Type : Entity_Id;
234 Unprotected : Boolean := False) return List_Id;
235 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
236 -- Subprogram_Type. Builds signature of protected subprogram, adding the
237 -- formal that corresponds to the object itself. For an access to protected
238 -- subprogram, there is no object type to specify, so the parameter has
239 -- type Address and mode In. An indirect call through such a pointer will
240 -- convert the address to a reference to the actual object. The object is
241 -- a limited record and therefore a by_reference type.
243 function Build_Protected_Subprogram_Body
246 N_Op_Spec : Node_Id) return Node_Id;
247 -- This function is used to construct the protected version of a protected
248 -- subprogram. Its statement sequence first defers abort, then locks
249 -- the associated protected object, and then enters a block that contains
250 -- a call to the unprotected version of the subprogram (for details, see
251 -- Build_Unprotected_Subprogram_Body). This block statement requires
252 -- a cleanup handler that unlocks the object in all cases.
253 -- (see Exp_Ch7.Expand_Cleanup_Actions).
255 function Build_Selected_Name
257 Selector : Entity_Id;
258 Append_Char : Character := ' ') return Name_Id;
259 -- Build a name in the form of Prefix__Selector, with an optional
260 -- character appended. This is used for internal subprograms generated
261 -- for operations of protected types, including barrier functions.
262 -- For the subprograms generated for entry bodies and entry barriers,
263 -- the generated name includes a sequence number that makes names
264 -- unique in the presence of entry overloading. This is necessary
265 -- because entry body procedures and barrier functions all have the
268 procedure Build_Simple_Entry_Call
273 -- Some comments here would be useful ???
275 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
276 -- This routine constructs a specification for the procedure that we will
277 -- build for the task body for task type T. The spec has the form:
279 -- procedure tnameB (_Task : access tnameV);
281 -- where name is the character name taken from the task type entity that
282 -- is passed as the argument to the procedure, and tnameV is the task
283 -- value type that is associated with the task type.
285 function Build_Unprotected_Subprogram_Body
287 Pid : Node_Id) return Node_Id;
288 -- This routine constructs the unprotected version of a protected
289 -- subprogram body, which is contains all of the code in the
290 -- original, unexpanded body. This is the version of the protected
291 -- subprogram that is called from all protected operations on the same
292 -- object, including the protected version of the same subprogram.
294 procedure Collect_Entry_Families
297 Current_Node : in out Node_Id;
298 Conctyp : Entity_Id);
299 -- For each entry family in a concurrent type, create an anonymous array
300 -- type of the right size, and add a component to the corresponding_record.
302 function Concurrent_Object
303 (Spec_Id : Entity_Id;
304 Conc_Typ : Entity_Id) return Entity_Id;
305 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
306 -- the entity associated with the concurrent object in the Protected_Body_
307 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
308 -- denotes formal parameter _O, _object or _task.
310 function Copy_Result_Type (Res : Node_Id) return Node_Id;
311 -- Copy the result type of a function specification, when building the
312 -- internal operation corresponding to a protected function, or when
313 -- expanding an access to protected function. If the result is an anonymous
314 -- access to subprogram itself, we need to create a new signature with the
315 -- same parameter names and the same resolved types, but with new entities
318 procedure Debug_Private_Data_Declarations (Decls : List_Id);
319 -- Decls is a list which may contain the declarations created by Install_
320 -- Private_Data_Declarations. All generated entities are marked as needing
321 -- debug info and debug nodes are manually generation where necessary. This
322 -- step of the expansion must to be done after private data has been moved
323 -- to its final resting scope to ensure proper visibility of debug objects.
325 function Family_Offset
330 Cap : Boolean) return Node_Id;
331 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in
332 -- an accept statement, or the upper bound in the discrete subtype of
333 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
334 -- the concurrent type of the entry. If Cap is true, the result is
335 -- capped according to Entry_Family_Bound.
342 Cap : Boolean) return Node_Id;
343 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
344 -- a family, and handle properly the superflat case. This is equivalent
345 -- to the use of 'Length on the index type, but must use Family_Offset
346 -- to handle properly the case of bounds that depend on discriminants.
347 -- If Cap is true, the result is capped according to Entry_Family_Bound.
349 procedure Find_Enclosing_Context
351 Context : out Node_Id;
352 Context_Id : out Entity_Id;
353 Context_Decls : out List_Id);
354 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
355 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
356 -- nearest enclosing body, block, package or return statement and return
357 -- its constituents. Context is the enclosing construct, Context_Id is
358 -- the scope of Context_Id and Context_Decls is the declarative list of
361 procedure Extract_Dispatching_Call
363 Call_Ent : out Entity_Id;
364 Object : out Entity_Id;
365 Actuals : out List_Id;
366 Formals : out List_Id);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
373 procedure Extract_Entry
375 Concval : out Node_Id;
377 Index : out Node_Id);
378 -- Given an entry call, returns the associated concurrent object,
379 -- the entry name, and the entry family index.
381 function Find_Task_Or_Protected_Pragma
383 P : Name_Id) return Node_Id;
384 -- Searches the task or protected definition T for the first occurrence
385 -- of the pragma whose name is given by P. The caller has ensured that
386 -- the pragma is present in the task definition. A special case is that
387 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
388 -- ??? Should be implemented with the rep item chain mechanism.
390 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
391 -- Given a subprogram identifier, return the entity which is associated
392 -- with the protection entry index in the Protected_Body_Subprogram or the
393 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
396 function Is_Potentially_Large_Family
397 (Base_Index : Entity_Id;
400 Hi : Node_Id) return Boolean;
402 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
403 -- Determine whether Id is a function or a procedure and is marked as a
404 -- private primitive.
406 function Null_Statements (Stats : List_Id) return Boolean;
407 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
408 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
409 -- well to still count as null. Returns True for a null sequence. The
410 -- argument is the list of statements from the DO-END sequence.
412 function Parameter_Block_Pack
418 Stmts : List_Id) return Entity_Id;
419 -- Set the components of the generated parameter block with the values of
420 -- the actual parameters. Generate aliased temporaries to capture the
421 -- values for types that are passed by copy. Otherwise generate a reference
422 -- to the actual's value. Return the address of the aggregate block.
424 -- Jnn1 : alias <formal-type1>;
425 -- Jnn1 := <actual1>;
428 -- Jnn1'unchecked_access;
429 -- <actual2>'reference;
432 function Parameter_Block_Unpack
436 Formals : List_Id) return List_Id;
437 -- Retrieve the values of the components from the parameter block and
438 -- assign then to the original actual parameters. Generate:
439 -- <actual1> := P.<formal1>;
441 -- <actualN> := P.<formalN>;
443 function Trivial_Accept_OK return Boolean;
444 -- If there is no DO-END block for an accept, or if the DO-END block has
445 -- only null statements, then it is possible to do the Rendezvous with much
446 -- less overhead using the Accept_Trivial routine in the run-time library.
447 -- However, this is not always a valid optimization. Whether it is valid or
448 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
449 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
450 -- a rescheduling is required, so this optimization is not allowed. This
451 -- function returns True if the optimization is permitted.
453 -----------------------------
454 -- Actual_Index_Expression --
455 -----------------------------
457 function Actual_Index_Expression
461 Tsk : Entity_Id) return Node_Id
463 Ttyp : constant Entity_Id := Etype (Tsk);
471 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
472 -- Compute difference between bounds of entry family
474 --------------------------
475 -- Actual_Family_Offset --
476 --------------------------
478 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
480 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
481 -- Replace a reference to a discriminant with a selected component
482 -- denoting the discriminant of the target task.
484 -----------------------------
485 -- Actual_Discriminant_Ref --
486 -----------------------------
488 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
489 Typ : constant Entity_Id := Etype (Bound);
493 if not Is_Entity_Name (Bound)
494 or else Ekind (Entity (Bound)) /= E_Discriminant
496 if Nkind (Bound) = N_Attribute_Reference then
499 B := New_Copy_Tree (Bound);
504 Make_Selected_Component (Sloc,
505 Prefix => New_Copy_Tree (Tsk),
506 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
508 Analyze_And_Resolve (B, Typ);
512 Make_Attribute_Reference (Sloc,
513 Attribute_Name => Name_Pos,
514 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
515 Expressions => New_List (B));
516 end Actual_Discriminant_Ref;
518 -- Start of processing for Actual_Family_Offset
522 Make_Op_Subtract (Sloc,
523 Left_Opnd => Actual_Discriminant_Ref (Hi),
524 Right_Opnd => Actual_Discriminant_Ref (Lo));
525 end Actual_Family_Offset;
527 -- Start of processing for Actual_Index_Expression
530 -- The queues of entries and entry families appear in textual order in
531 -- the associated record. The entry index is computed as the sum of the
532 -- number of queues for all entries that precede the designated one, to
533 -- which is added the index expression, if this expression denotes a
534 -- member of a family.
536 -- The following is a place holder for the count of simple entries
538 Num := Make_Integer_Literal (Sloc, 1);
540 -- We construct an expression which is a series of addition operations.
541 -- See comments in Entry_Index_Expression, which is identical in
544 if Present (Index) then
545 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
552 Actual_Family_Offset (
553 Make_Attribute_Reference (Sloc,
554 Attribute_Name => Name_Pos,
555 Prefix => New_Reference_To (Base_Type (S), Sloc),
556 Expressions => New_List (Relocate_Node (Index))),
557 Type_Low_Bound (S)));
562 -- Now add lengths of preceding entries and entry families
564 Prev := First_Entity (Ttyp);
566 while Chars (Prev) /= Chars (Ent)
567 or else (Ekind (Prev) /= Ekind (Ent))
568 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
570 if Ekind (Prev) = E_Entry then
571 Set_Intval (Num, Intval (Num) + 1);
573 elsif Ekind (Prev) = E_Entry_Family then
575 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
577 -- The need for the following full view retrieval stems from
578 -- this complex case of nested generics and tasking:
581 -- type Formal_Index is range <>;
584 -- type Index is private;
591 -- type Index is new Formal_Index range 1 .. 10;
594 -- package body Outer is
596 -- entry Fam (Index); -- (2)
599 -- package body Inner is -- (3)
607 -- We are currently building the index expression for the entry
608 -- call "T.E" (1). Part of the expansion must mention the range
609 -- of the discrete type "Index" (2) of entry family "Fam".
610 -- However only the private view of type "Index" is available to
611 -- the inner generic (3) because there was no prior mention of
612 -- the type inside "Inner". This visibility requirement is
613 -- implicit and cannot be detected during the construction of
614 -- the generic trees and needs special handling.
617 and then Is_Private_Type (S)
618 and then Present (Full_View (S))
623 Lo := Type_Low_Bound (S);
624 Hi := Type_High_Bound (S);
632 Actual_Family_Offset (Hi, Lo),
634 Make_Integer_Literal (Sloc, 1)));
636 -- Other components are anonymous types to be ignored
646 end Actual_Index_Expression;
648 --------------------------
649 -- Add_Formal_Renamings --
650 --------------------------
652 procedure Add_Formal_Renamings
658 Ptr : constant Entity_Id :=
660 (Next (First (Parameter_Specifications (Spec))));
661 -- The name of the formal that holds the address of the parameter block
668 Renamed_Formal : Node_Id;
671 Formal := First_Formal (Ent);
672 while Present (Formal) loop
673 Comp := Entry_Component (Formal);
675 Make_Defining_Identifier (Sloc (Formal),
676 Chars => Chars (Formal));
677 Set_Etype (New_F, Etype (Formal));
678 Set_Scope (New_F, Ent);
680 -- Now we set debug info needed on New_F even though it does not
681 -- come from source, so that the debugger will get the right
682 -- information for these generated names.
684 Set_Debug_Info_Needed (New_F);
686 if Ekind (Formal) = E_In_Parameter then
687 Set_Ekind (New_F, E_Constant);
689 Set_Ekind (New_F, E_Variable);
690 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
693 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
696 Make_Selected_Component (Loc,
698 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
699 Make_Identifier (Loc, Chars (Ptr))),
700 Selector_Name => New_Reference_To (Comp, Loc));
703 Build_Renamed_Formal_Declaration
704 (New_F, Formal, Comp, Renamed_Formal);
706 Append (Decl, Decls);
707 Set_Renamed_Object (Formal, New_F);
708 Next_Formal (Formal);
710 end Add_Formal_Renamings;
712 ------------------------
713 -- Add_Object_Pointer --
714 ------------------------
716 procedure Add_Object_Pointer
718 Conc_Typ : Entity_Id;
721 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
726 -- Create the renaming declaration for the Protection object of a
727 -- protected type. _Object is used by Complete_Entry_Body.
728 -- ??? An attempt to make this a renaming was unsuccessful.
730 -- Build the entity for the access type
733 Make_Defining_Identifier (Loc,
734 New_External_Name (Chars (Rec_Typ), 'P'));
737 -- _object : poVP := poVP!O;
740 Make_Object_Declaration (Loc,
741 Defining_Identifier =>
742 Make_Defining_Identifier (Loc, Name_uObject),
744 New_Reference_To (Obj_Ptr, Loc),
746 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
747 Set_Debug_Info_Needed (Defining_Identifier (Decl));
748 Prepend_To (Decls, Decl);
751 -- type poVP is access poV;
754 Make_Full_Type_Declaration (Loc,
755 Defining_Identifier =>
758 Make_Access_To_Object_Definition (Loc,
759 Subtype_Indication =>
760 New_Reference_To (Rec_Typ, Loc)));
761 Set_Debug_Info_Needed (Defining_Identifier (Decl));
762 Prepend_To (Decls, Decl);
763 end Add_Object_Pointer;
765 -----------------------
766 -- Build_Accept_Body --
767 -----------------------
769 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
770 Loc : constant Source_Ptr := Sloc (Astat);
771 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
778 -- At the end of the statement sequence, Complete_Rendezvous is called.
779 -- A label skipping the Complete_Rendezvous, and all other accept
780 -- processing, has already been added for the expansion of requeue
781 -- statements. The Sloc is copied from the last statement since it
782 -- is really part of this last statement.
786 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
787 Insert_Before (Last (Statements (Stats)), Call);
790 -- If exception handlers are present, then append Complete_Rendezvous
791 -- calls to the handlers, and construct the required outer block. As
792 -- above, the Sloc is copied from the last statement in the sequence.
794 if Present (Exception_Handlers (Stats)) then
795 Hand := First (Exception_Handlers (Stats));
796 while Present (Hand) loop
799 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
800 Append (Call, Statements (Hand));
806 Make_Handled_Sequence_Of_Statements (Loc,
807 Statements => New_List (
808 Make_Block_Statement (Loc,
809 Handled_Statement_Sequence => Stats)));
815 -- At this stage we know that the new statement sequence does not
816 -- have an exception handler part, so we supply one to call
817 -- Exceptional_Complete_Rendezvous. This handler is
819 -- when all others =>
820 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
822 -- We handle Abort_Signal to make sure that we properly catch the abort
823 -- case and wake up the caller.
825 Ohandle := Make_Others_Choice (Loc);
826 Set_All_Others (Ohandle);
828 Set_Exception_Handlers (New_S,
830 Make_Implicit_Exception_Handler (Loc,
831 Exception_Choices => New_List (Ohandle),
833 Statements => New_List (
834 Make_Procedure_Call_Statement (Sloc (Stats),
835 Name => New_Reference_To (
836 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
837 Parameter_Associations => New_List (
838 Make_Function_Call (Sloc (Stats),
839 Name => New_Reference_To (
840 RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
842 Set_Parent (New_S, Astat); -- temp parent for Analyze call
843 Analyze_Exception_Handlers (Exception_Handlers (New_S));
844 Expand_Exception_Handlers (New_S);
846 -- Exceptional_Complete_Rendezvous must be called with abort
847 -- still deferred, which is the case for a "when all others" handler.
850 end Build_Accept_Body;
852 -----------------------------------
853 -- Build_Activation_Chain_Entity --
854 -----------------------------------
856 procedure Build_Activation_Chain_Entity (N : Node_Id) is
857 function Has_Activation_Chain (Stmt : Node_Id) return Boolean;
858 -- Determine whether an extended return statement has an activation
861 --------------------------
862 -- Has_Activation_Chain --
863 --------------------------
865 function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
869 Decl := First (Return_Object_Declarations (Stmt));
870 while Present (Decl) loop
871 if Nkind (Decl) = N_Object_Declaration
872 and then Chars (Defining_Identifier (Decl)) = Name_uChain
881 end Has_Activation_Chain;
886 Context_Id : Entity_Id;
889 -- Start of processing for Build_Activation_Chain_Entity
892 Find_Enclosing_Context (N, Context, Context_Id, Decls);
894 -- If an activation chain entity has not been declared already, create
897 if Nkind (Context) = N_Extended_Return_Statement
898 or else No (Activation_Chain_Entity (Context))
900 -- Since extended return statements do not store the entity of the
901 -- chain, examine the return object declarations to avoid creating
904 if Nkind (Context) = N_Extended_Return_Statement
905 and then Has_Activation_Chain (Context)
911 Loc : constant Source_Ptr := Sloc (Context);
916 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
918 -- Note: An extended return statement is not really a task
919 -- activator, but it does have an activation chain on which to
920 -- store the tasks temporarily. On successful return, the tasks
921 -- on this chain are moved to the chain passed in by the caller.
922 -- We do not build an Activation_Chain_Entity for an extended
923 -- return statement, because we do not want to build a call to
924 -- Activate_Tasks. Task activation is the responsibility of the
927 if Nkind (Context) /= N_Extended_Return_Statement then
928 Set_Activation_Chain_Entity (Context, Chain);
932 Make_Object_Declaration (Loc,
933 Defining_Identifier => Chain,
934 Aliased_Present => True,
936 New_Reference_To (RTE (RE_Activation_Chain), Loc));
938 Prepend_To (Decls, Decl);
940 -- Ensure that the _chain appears in the proper scope of the
943 if Context_Id /= Current_Scope then
944 Push_Scope (Context_Id);
952 end Build_Activation_Chain_Entity;
954 ----------------------------
955 -- Build_Barrier_Function --
956 ----------------------------
958 function Build_Barrier_Function
961 Pid : Node_Id) return Node_Id
963 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
964 Cond : constant Node_Id := Condition (Ent_Formals);
965 Loc : constant Source_Ptr := Sloc (Cond);
966 Func_Id : constant Entity_Id := Barrier_Function (Ent);
967 Op_Decls : constant List_Id := New_List;
972 -- Add a declaration for the Protection object, renaming declarations
973 -- for the discriminals and privals and finally a declaration for the
974 -- entry family index (if applicable).
976 Install_Private_Data_Declarations (Sloc (N),
982 Family => Ekind (Ent) = E_Entry_Family);
984 -- If compiling with -fpreserve-control-flow, make sure we insert an
985 -- IF statement so that the back-end knows to generate a conditional
986 -- branch instruction, even if the condition is just the name of a
989 if Opt.Suppress_Control_Flow_Optimizations then
990 Stmt := Make_Implicit_If_Statement (Cond,
992 Then_Statements => New_List (
993 Make_Simple_Return_Statement (Loc,
994 New_Occurrence_Of (Standard_True, Loc))),
995 Else_Statements => New_List (
996 Make_Simple_Return_Statement (Loc,
997 New_Occurrence_Of (Standard_False, Loc))));
1000 Stmt := Make_Simple_Return_Statement (Loc, Cond);
1003 -- Note: the condition in the barrier function needs to be properly
1004 -- processed for the C/Fortran boolean possibility, but this happens
1005 -- automatically since the return statement does this normalization.
1008 Make_Subprogram_Body (Loc,
1010 Build_Barrier_Function_Specification (Loc,
1011 Make_Defining_Identifier (Loc, Chars (Func_Id))),
1012 Declarations => Op_Decls,
1013 Handled_Statement_Sequence =>
1014 Make_Handled_Sequence_Of_Statements (Loc,
1015 Statements => New_List (Stmt)));
1016 Set_Is_Entry_Barrier_Function (Func_Body);
1019 end Build_Barrier_Function;
1021 ------------------------------------------
1022 -- Build_Barrier_Function_Specification --
1023 ------------------------------------------
1025 function Build_Barrier_Function_Specification
1027 Def_Id : Entity_Id) return Node_Id
1030 Set_Debug_Info_Needed (Def_Id);
1032 return Make_Function_Specification (Loc,
1033 Defining_Unit_Name => Def_Id,
1034 Parameter_Specifications => New_List (
1035 Make_Parameter_Specification (Loc,
1036 Defining_Identifier =>
1037 Make_Defining_Identifier (Loc, Name_uO),
1039 New_Reference_To (RTE (RE_Address), Loc)),
1041 Make_Parameter_Specification (Loc,
1042 Defining_Identifier =>
1043 Make_Defining_Identifier (Loc, Name_uE),
1045 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1047 Result_Definition =>
1048 New_Reference_To (Standard_Boolean, Loc));
1049 end Build_Barrier_Function_Specification;
1051 --------------------------
1052 -- Build_Call_With_Task --
1053 --------------------------
1055 function Build_Call_With_Task
1057 E : Entity_Id) return Node_Id
1059 Loc : constant Source_Ptr := Sloc (N);
1062 Make_Function_Call (Loc,
1063 Name => New_Reference_To (E, Loc),
1064 Parameter_Associations => New_List (Concurrent_Ref (N)));
1065 end Build_Call_With_Task;
1067 -----------------------------
1068 -- Build_Class_Wide_Master --
1069 -----------------------------
1071 procedure Build_Class_Wide_Master (Typ : Entity_Id) is
1072 Loc : constant Source_Ptr := Sloc (Typ);
1073 Master_Id : Entity_Id;
1074 Master_Scope : Entity_Id;
1076 Related_Node : Node_Id;
1080 -- Nothing to do if there is no task hierarchy
1082 if Restriction_Active (No_Task_Hierarchy) then
1086 -- Find the declaration that created the access type. It is either a
1087 -- type declaration, or an object declaration with an access definition,
1088 -- in which case the type is anonymous.
1090 if Is_Itype (Typ) then
1091 Related_Node := Associated_Node_For_Itype (Typ);
1093 Related_Node := Parent (Typ);
1096 Master_Scope := Find_Master_Scope (Typ);
1098 -- Nothing to do if the master scope already contains a _master entity.
1099 -- The only exception to this is the following scenario:
1102 -- Transient_Scope_1
1105 -- Transient_Scope_2
1108 -- In this case the source scope is marked as having the master entity
1109 -- even though the actual declaration appears inside an inner scope. If
1110 -- the second transient scope requires a _master, it cannot use the one
1111 -- already declared because the entity is not visible.
1113 Name_Id := Make_Identifier (Loc, Name_uMaster);
1115 if not Has_Master_Entity (Master_Scope)
1116 or else No (Current_Entity_In_Scope (Name_Id))
1119 Master_Decl : Node_Id;
1122 Set_Has_Master_Entity (Master_Scope);
1125 -- _master : constant Integer := Current_Master.all;
1128 Make_Object_Declaration (Loc,
1129 Defining_Identifier =>
1130 Make_Defining_Identifier (Loc, Name_uMaster),
1131 Constant_Present => True,
1132 Object_Definition =>
1133 New_Reference_To (Standard_Integer, Loc),
1135 Make_Explicit_Dereference (Loc,
1136 New_Reference_To (RTE (RE_Current_Master), Loc)));
1138 Insert_Action (Related_Node, Master_Decl);
1139 Analyze (Master_Decl);
1141 -- Mark the containing scope as a task master. Masters associated
1142 -- with return statements are already marked at this stage (see
1143 -- Analyze_Subprogram_Body).
1145 if Ekind (Current_Scope) /= E_Return_Statement then
1147 Par : Node_Id := Related_Node;
1150 while Nkind (Par) /= N_Compilation_Unit loop
1151 Par := Parent (Par);
1153 -- If we fall off the top, we are at the outer level, and
1154 -- the environment task is our effective master, so
1157 if Nkind_In (Par, N_Block_Statement,
1161 Set_Is_Task_Master (Par);
1171 Make_Defining_Identifier (Loc,
1172 New_External_Name (Chars (Typ), 'M'));
1175 -- Mnn renames _master;
1178 Make_Object_Renaming_Declaration (Loc,
1179 Defining_Identifier => Master_Id,
1180 Subtype_Mark => New_Reference_To (Standard_Integer, Loc),
1183 Insert_Action (Related_Node, Ren_Decl);
1185 Set_Master_Id (Typ, Master_Id);
1186 end Build_Class_Wide_Master;
1188 --------------------------------
1189 -- Build_Corresponding_Record --
1190 --------------------------------
1192 function Build_Corresponding_Record
1195 Loc : Source_Ptr) return Node_Id
1197 Rec_Ent : constant Entity_Id :=
1198 Make_Defining_Identifier
1199 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1202 New_Disc : Entity_Id;
1206 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1207 Set_Ekind (Rec_Ent, E_Record_Type);
1208 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1209 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1210 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1211 Set_Stored_Constraint (Rec_Ent, No_Elist);
1214 -- Use discriminals to create list of discriminants for record, and
1215 -- create new discriminals for use in default expressions, etc. It is
1216 -- worth noting that a task discriminant gives rise to 5 entities;
1218 -- a) The original discriminant.
1219 -- b) The discriminal for use in the task.
1220 -- c) The discriminant of the corresponding record.
1221 -- d) The discriminal for the init proc of the corresponding record.
1222 -- e) The local variable that renames the discriminant in the procedure
1223 -- for the task body.
1225 -- In fact the discriminals b) are used in the renaming declarations
1226 -- for e). See details in einfo (Handling of Discriminants).
1228 if Present (Discriminant_Specifications (N)) then
1230 Disc := First_Discriminant (Ctyp);
1232 while Present (Disc) loop
1233 New_Disc := CR_Discriminant (Disc);
1236 Make_Discriminant_Specification (Loc,
1237 Defining_Identifier => New_Disc,
1238 Discriminant_Type =>
1239 New_Occurrence_Of (Etype (Disc), Loc),
1241 New_Copy (Discriminant_Default_Value (Disc))));
1243 Next_Discriminant (Disc);
1250 -- Now we can construct the record type declaration. Note that this
1251 -- record is "limited tagged". It is "limited" to reflect the underlying
1252 -- limitedness of the task or protected object that it represents, and
1253 -- ensuring for example that it is properly passed by reference. It is
1254 -- "tagged" to give support to dispatching calls through interfaces. We
1255 -- propagate here the list of interfaces covered by the concurrent type
1256 -- (Ada 2005: AI-345).
1259 Make_Full_Type_Declaration (Loc,
1260 Defining_Identifier => Rec_Ent,
1261 Discriminant_Specifications => Dlist,
1263 Make_Record_Definition (Loc,
1265 Make_Component_List (Loc,
1266 Component_Items => Cdecls),
1268 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1269 Interface_List => Interface_List (N),
1270 Limited_Present => True));
1271 end Build_Corresponding_Record;
1273 ----------------------------------
1274 -- Build_Entry_Count_Expression --
1275 ----------------------------------
1277 function Build_Entry_Count_Expression
1278 (Concurrent_Type : Node_Id;
1279 Component_List : List_Id;
1280 Loc : Source_Ptr) return Node_Id
1292 -- Count number of non-family entries
1295 Ent := First_Entity (Concurrent_Type);
1296 while Present (Ent) loop
1297 if Ekind (Ent) = E_Entry then
1304 Ecount := Make_Integer_Literal (Loc, Eindx);
1306 -- Loop through entry families building the addition nodes
1308 Ent := First_Entity (Concurrent_Type);
1309 Comp := First (Component_List);
1310 while Present (Ent) loop
1311 if Ekind (Ent) = E_Entry_Family then
1312 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1316 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1317 Hi := Type_High_Bound (Typ);
1318 Lo := Type_Low_Bound (Typ);
1319 Large := Is_Potentially_Large_Family
1320 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1323 Left_Opnd => Ecount,
1324 Right_Opnd => Family_Size
1325 (Loc, Hi, Lo, Concurrent_Type, Large));
1332 end Build_Entry_Count_Expression;
1334 -----------------------
1335 -- Build_Entry_Names --
1336 -----------------------
1338 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1339 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1345 Typ : Entity_Id := Conc_Typ;
1347 procedure Build_Entry_Family_Name (Id : Entity_Id);
1349 -- for Lnn in Family_Low .. Family_High loop
1352 -- (_init._object <or> _init._task_id,
1354 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1356 -- Note that the bounds of the range may reference discriminants. The
1357 -- above construct is added directly to the statements of the block.
1359 procedure Build_Entry_Name (Id : Entity_Id);
1363 -- (_init._object <or>_init._task_id,
1365 -- new String ("<Entry name>");
1366 -- The above construct is added directly to the statements of the block.
1368 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1369 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1370 -- _init._task_id or _init._object, Inn and Arg3.
1372 procedure Increment_Index (Stmts : List_Id);
1373 -- Generate the following and add it to Stmts
1376 -----------------------------
1377 -- Build_Entry_Family_Name --
1378 -----------------------------
1380 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1381 Def : constant Node_Id :=
1382 Discrete_Subtype_Definition (Parent (Id));
1383 L_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
1384 L_Stmts : constant List_Id := New_List;
1387 function Build_Range (Def : Node_Id) return Node_Id;
1388 -- Given a discrete subtype definition of an entry family, generate a
1389 -- range node which covers the range of Def's type.
1395 function Build_Range (Def : Node_Id) return Node_Id is
1396 High : Node_Id := Type_High_Bound (Etype (Def));
1397 Low : Node_Id := Type_Low_Bound (Etype (Def));
1400 -- If a bound references a discriminant, generate an identifier
1401 -- with the same name. Resolution will map it to the formals of
1404 if Is_Entity_Name (Low)
1405 and then Ekind (Entity (Low)) = E_Discriminant
1407 Low := Make_Identifier (Loc, Chars (Low));
1409 Low := New_Copy_Tree (Low);
1412 if Is_Entity_Name (High)
1413 and then Ekind (Entity (High)) = E_Discriminant
1415 High := Make_Identifier (Loc, Chars (High));
1417 High := New_Copy_Tree (High);
1423 High_Bound => High);
1426 -- Start of processing for Build_Entry_Family_Name
1429 Get_Name_String (Chars (Id));
1431 -- Add a leading '('
1433 Add_Char_To_Name_Buffer ('(');
1436 -- new String'("<Entry name>(" & Lnn'Img & ")");
1438 -- This is an implicit heap allocation, and Comes_From_Source is
1439 -- False, which ensures that it will get flagged as a violation of
1440 -- No_Implicit_Heap_Allocations when that restriction applies.
1443 Make_Allocator (Loc,
1444 Make_Qualified_Expression (Loc,
1446 New_Reference_To (Standard_String, Loc),
1448 Make_Op_Concat (Loc,
1450 Make_Op_Concat (Loc,
1452 Make_String_Literal (Loc,
1453 Strval => String_From_Name_Buffer),
1455 Make_Attribute_Reference (Loc,
1457 New_Reference_To (L_Id, Loc),
1458 Attribute_Name => Name_Img)),
1460 Make_String_Literal (Loc,
1463 Increment_Index (L_Stmts);
1464 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1467 -- for Lnn in Family_Low .. Family_High loop
1470 -- (_init._object <or> _init._task_id, Inn, <Val>);
1474 Make_Loop_Statement (Loc,
1476 Make_Iteration_Scheme (Loc,
1477 Loop_Parameter_Specification =>
1478 Make_Loop_Parameter_Specification (Loc,
1479 Defining_Identifier => L_Id,
1480 Discrete_Subtype_Definition => Build_Range (Def))),
1481 Statements => L_Stmts,
1482 End_Label => Empty));
1483 end Build_Entry_Family_Name;
1485 ----------------------
1486 -- Build_Entry_Name --
1487 ----------------------
1489 procedure Build_Entry_Name (Id : Entity_Id) is
1493 Get_Name_String (Chars (Id));
1495 -- This is an implicit heap allocation, and Comes_From_Source is
1496 -- False, which ensures that it will get flagged as a violation of
1497 -- No_Implicit_Heap_Allocations when that restriction applies.
1500 Make_Allocator (Loc,
1501 Make_Qualified_Expression (Loc,
1503 New_Reference_To (Standard_String, Loc),
1505 Make_String_Literal (Loc,
1506 String_From_Name_Buffer)));
1508 Increment_Index (B_Stmts);
1509 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1510 end Build_Entry_Name;
1512 -------------------------------
1513 -- Build_Set_Entry_Name_Call --
1514 -------------------------------
1516 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1521 -- Determine the proper name for the first argument and the RTS
1524 if Is_Protected_Type (Typ) then
1525 Arg1 := Name_uObject;
1526 Proc := RO_PE_Set_Entry_Name;
1528 else pragma Assert (Is_Task_Type (Typ));
1529 Arg1 := Name_uTask_Id;
1530 Proc := RO_TS_Set_Entry_Name;
1534 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1537 Make_Procedure_Call_Statement (Loc,
1539 New_Reference_To (RTE (Proc), Loc),
1540 Parameter_Associations => New_List (
1541 Make_Selected_Component (Loc, -- _init._object
1542 Prefix => -- _init._task_id
1543 Make_Identifier (Loc, Name_uInit),
1545 Make_Identifier (Loc, Arg1)),
1546 New_Reference_To (Index, Loc), -- Inn
1548 end Build_Set_Entry_Name_Call;
1550 ---------------------
1551 -- Increment_Index --
1552 ---------------------
1554 procedure Increment_Index (Stmts : List_Id) is
1560 Make_Assignment_Statement (Loc,
1562 New_Reference_To (Index, Loc),
1566 New_Reference_To (Index, Loc),
1568 Make_Integer_Literal (Loc, 1))));
1569 end Increment_Index;
1571 -- Start of processing for Build_Entry_Names
1574 -- Retrieve the original concurrent type
1576 if Is_Concurrent_Record_Type (Typ) then
1577 Typ := Corresponding_Concurrent_Type (Typ);
1580 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1582 -- Nothing to do if the type has no entries
1584 if not Has_Entries (Typ) then
1588 -- Avoid generating entry names for a protected type with only one entry
1590 if Is_Protected_Type (Typ)
1591 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1596 Index := Make_Temporary (Loc, 'I');
1598 -- Step 1: Generate the declaration of the index variable:
1599 -- Inn : Protected_Entry_Index := 0;
1601 -- Inn : Task_Entry_Index := 0;
1603 if Is_Protected_Type (Typ) then
1604 Index_Typ := RE_Protected_Entry_Index;
1606 Index_Typ := RE_Task_Entry_Index;
1609 B_Decls := New_List;
1611 Make_Object_Declaration (Loc,
1612 Defining_Identifier => Index,
1613 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1614 Expression => Make_Integer_Literal (Loc, 0)));
1616 B_Stmts := New_List;
1618 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1621 Comp := First_Entity (Typ);
1622 while Present (Comp) loop
1623 if Ekind (Comp) = E_Entry then
1624 Build_Entry_Name (Comp);
1626 elsif Ekind (Comp) = E_Entry_Family then
1627 Build_Entry_Family_Name (Comp);
1633 -- Step 3: Wrap the statements in a block
1636 Make_Block_Statement (Loc,
1637 Declarations => B_Decls,
1638 Handled_Statement_Sequence =>
1639 Make_Handled_Sequence_Of_Statements (Loc,
1640 Statements => B_Stmts));
1641 end Build_Entry_Names;
1643 ---------------------------
1644 -- Build_Parameter_Block --
1645 ---------------------------
1647 function Build_Parameter_Block
1651 Decls : List_Id) return Entity_Id
1657 Has_Comp : Boolean := False;
1661 Actual := First (Actuals);
1663 Formal := Defining_Identifier (First (Formals));
1665 while Present (Actual) loop
1666 if not Is_Controlling_Actual (Actual) then
1669 -- type Ann is access all <actual-type>
1671 Comp_Nam := Make_Temporary (Loc, 'A');
1674 Make_Full_Type_Declaration (Loc,
1675 Defining_Identifier => Comp_Nam,
1677 Make_Access_To_Object_Definition (Loc,
1678 All_Present => True,
1679 Constant_Present => Ekind (Formal) = E_In_Parameter,
1680 Subtype_Indication =>
1681 New_Reference_To (Etype (Actual), Loc))));
1687 Make_Component_Declaration (Loc,
1688 Defining_Identifier =>
1689 Make_Defining_Identifier (Loc, Chars (Formal)),
1690 Component_Definition =>
1691 Make_Component_Definition (Loc,
1694 Subtype_Indication =>
1695 New_Reference_To (Comp_Nam, Loc))));
1700 Next_Actual (Actual);
1701 Next_Formal_With_Extras (Formal);
1704 Rec_Nam := Make_Temporary (Loc, 'P');
1709 -- type Pnn is record
1714 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1715 -- the original parameter names and Ann1 .. AnnN are the access to
1719 Make_Full_Type_Declaration (Loc,
1720 Defining_Identifier =>
1723 Make_Record_Definition (Loc,
1725 Make_Component_List (Loc, Comps))));
1728 -- type Pnn is null record;
1731 Make_Full_Type_Declaration (Loc,
1732 Defining_Identifier =>
1735 Make_Record_Definition (Loc,
1736 Null_Present => True,
1737 Component_List => Empty)));
1741 end Build_Parameter_Block;
1743 --------------------------------------
1744 -- Build_Renamed_Formal_Declaration --
1745 --------------------------------------
1747 function Build_Renamed_Formal_Declaration
1751 Renamed_Formal : Node_Id) return Node_Id
1753 Loc : constant Source_Ptr := Sloc (New_F);
1757 -- If the formal is a tagged incomplete type, it is already passed
1758 -- by reference, so it is sufficient to rename the pointer component
1759 -- that corresponds to the actual. Otherwise we need to dereference
1760 -- the pointer component to obtain the actual.
1762 if Is_Incomplete_Type (Etype (Formal))
1763 and then Is_Tagged_Type (Etype (Formal))
1766 Make_Object_Renaming_Declaration (Loc,
1767 Defining_Identifier => New_F,
1768 Subtype_Mark => New_Reference_To (Etype (Comp), Loc),
1769 Name => Renamed_Formal);
1773 Make_Object_Renaming_Declaration (Loc,
1774 Defining_Identifier => New_F,
1775 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
1777 Make_Explicit_Dereference (Loc, Renamed_Formal));
1781 end Build_Renamed_Formal_Declaration;
1783 -----------------------
1784 -- Build_PPC_Wrapper --
1785 -----------------------
1787 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1788 Loc : constant Source_Ptr := Sloc (E);
1789 Synch_Type : constant Entity_Id := Scope (E);
1791 Wrapper_Id : constant Entity_Id :=
1792 Make_Defining_Identifier (Loc,
1793 Chars => New_External_Name (Chars (E), 'E'));
1794 -- the wrapper procedure name
1796 Wrapper_Body : Node_Id;
1798 Synch_Id : constant Entity_Id :=
1799 Make_Defining_Identifier (Loc,
1800 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1801 -- The parameter that designates the synchronized object in the call
1803 Actuals : constant List_Id := New_List;
1804 -- The actuals in the entry call
1806 Decls : constant List_Id := New_List;
1808 Entry_Call : Node_Id;
1809 Entry_Name : Node_Id;
1812 -- The specification of the wrapper procedure
1816 -- Only build the wrapper if entry has pre/postconditions.
1817 -- Should this be done unconditionally instead ???
1823 P := Spec_PPC_List (Contract (E));
1828 -- Transfer ppc pragmas to the declarations of the wrapper
1830 while Present (P) loop
1831 if Pragma_Name (P) = Name_Precondition
1832 or else Pragma_Name (P) = Name_Postcondition
1834 Append (Relocate_Node (P), Decls);
1835 Set_Analyzed (Last (Decls), False);
1838 P := Next_Pragma (P);
1842 -- First formal is synchronized object
1845 Make_Parameter_Specification (Loc,
1846 Defining_Identifier => Synch_Id,
1847 Out_Present => True,
1849 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1852 Make_Selected_Component (Loc,
1853 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1854 Selector_Name => New_Occurrence_Of (E, Loc));
1856 -- If entity is entry family, second formal is the corresponding index,
1857 -- and entry name is an indexed component.
1859 if Ekind (E) = E_Entry_Family then
1861 Index : constant Entity_Id :=
1862 Make_Defining_Identifier (Loc, Name_I);
1865 Make_Parameter_Specification (Loc,
1866 Defining_Identifier => Index,
1868 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1871 Make_Indexed_Component (Loc,
1872 Prefix => Entry_Name,
1873 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
1878 Make_Procedure_Call_Statement (Loc,
1880 Parameter_Associations => Actuals);
1882 -- Now add formals that match those of the entry, and build actuals for
1883 -- the nested entry call.
1887 New_Form : Entity_Id;
1888 Parm_Spec : Node_Id;
1891 Form := First_Formal (E);
1892 while Present (Form) loop
1893 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
1895 Make_Parameter_Specification (Loc,
1896 Defining_Identifier => New_Form,
1897 Out_Present => Out_Present (Parent (Form)),
1898 In_Present => In_Present (Parent (Form)),
1899 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
1901 Append (Parm_Spec, Specs);
1902 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1907 -- Add renaming declarations for the discriminants of the enclosing
1908 -- type, which may be visible in the preconditions.
1910 if Has_Discriminants (Synch_Type) then
1916 D := First_Discriminant (Synch_Type);
1917 while Present (D) loop
1919 Make_Object_Renaming_Declaration (Loc,
1920 Defining_Identifier =>
1921 Make_Defining_Identifier (Loc, Chars (D)),
1922 Subtype_Mark => New_Reference_To (Etype (D), Loc),
1924 Make_Selected_Component (Loc,
1925 Prefix => New_Reference_To (Synch_Id, Loc),
1926 Selector_Name => Make_Identifier (Loc, Chars (D))));
1927 Prepend (Decl, Decls);
1928 Next_Discriminant (D);
1933 Set_PPC_Wrapper (E, Wrapper_Id);
1935 Make_Subprogram_Body (Loc,
1937 Make_Procedure_Specification (Loc,
1938 Defining_Unit_Name => Wrapper_Id,
1939 Parameter_Specifications => Specs),
1940 Declarations => Decls,
1941 Handled_Statement_Sequence =>
1942 Make_Handled_Sequence_Of_Statements (Loc,
1943 Statements => New_List (Entry_Call)));
1945 -- The wrapper body is analyzed when the enclosing type is frozen
1947 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1948 end Build_PPC_Wrapper;
1950 --------------------------
1951 -- Build_Wrapper_Bodies --
1952 --------------------------
1954 procedure Build_Wrapper_Bodies
1959 Rec_Typ : Entity_Id;
1961 function Build_Wrapper_Body
1963 Subp_Id : Entity_Id;
1964 Obj_Typ : Entity_Id;
1965 Formals : List_Id) return Node_Id;
1966 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1967 -- associated with a protected or task type. Subp_Id is the subprogram
1968 -- name which will be wrapped. Obj_Typ is the type of the new formal
1969 -- parameter which handles dispatching and object notation. Formals are
1970 -- the original formals of Subp_Id which will be explicitly replicated.
1972 ------------------------
1973 -- Build_Wrapper_Body --
1974 ------------------------
1976 function Build_Wrapper_Body
1978 Subp_Id : Entity_Id;
1979 Obj_Typ : Entity_Id;
1980 Formals : List_Id) return Node_Id
1982 Body_Spec : Node_Id;
1985 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1987 -- The subprogram is not overriding or is not a primitive declared
1988 -- between two views.
1990 if No (Body_Spec) then
1995 Actuals : List_Id := No_List;
1997 First_Form : Node_Id;
2002 -- Map formals to actuals. Use the list built for the wrapper
2003 -- spec, skipping the object notation parameter.
2005 First_Form := First (Parameter_Specifications (Body_Spec));
2007 Formal := First_Form;
2010 if Present (Formal) then
2011 Actuals := New_List;
2012 while Present (Formal) loop
2014 Make_Identifier (Loc,
2015 Chars => Chars (Defining_Identifier (Formal))));
2020 -- Special processing for primitives declared between a private
2021 -- type and its completion: the wrapper needs a properly typed
2022 -- parameter if the wrapped operation has a controlling first
2023 -- parameter. Note that this might not be the case for a function
2024 -- with a controlling result.
2026 if Is_Private_Primitive_Subprogram (Subp_Id) then
2027 if No (Actuals) then
2028 Actuals := New_List;
2031 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
2032 Prepend_To (Actuals,
2033 Unchecked_Convert_To
2034 (Corresponding_Concurrent_Type (Obj_Typ),
2035 Make_Identifier (Loc, Name_uO)));
2038 Prepend_To (Actuals,
2039 Make_Identifier (Loc,
2040 Chars => Chars (Defining_Identifier (First_Form))));
2043 Nam := New_Reference_To (Subp_Id, Loc);
2045 -- An access-to-variable object parameter requires an explicit
2046 -- dereference in the unchecked conversion. This case occurs
2047 -- when a protected entry wrapper must override an interface
2048 -- level procedure with interface access as first parameter.
2050 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2052 if Nkind (Parameter_Type (First_Form)) =
2056 Make_Explicit_Dereference (Loc,
2057 Prefix => Make_Identifier (Loc, Name_uO));
2059 Conv_Id := Make_Identifier (Loc, Name_uO);
2063 Make_Selected_Component (Loc,
2065 Unchecked_Convert_To
2066 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
2067 Selector_Name => New_Reference_To (Subp_Id, Loc));
2070 -- Create the subprogram body. For a function, the call to the
2071 -- actual subprogram has to be converted to the corresponding
2072 -- record if it is a controlling result.
2074 if Ekind (Subp_Id) = E_Function then
2080 Make_Function_Call (Loc,
2082 Parameter_Associations => Actuals);
2084 if Has_Controlling_Result (Subp_Id) then
2086 Unchecked_Convert_To
2087 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
2091 Make_Subprogram_Body (Loc,
2092 Specification => Body_Spec,
2093 Declarations => Empty_List,
2094 Handled_Statement_Sequence =>
2095 Make_Handled_Sequence_Of_Statements (Loc,
2096 Statements => New_List (
2097 Make_Simple_Return_Statement (Loc, Res))));
2102 Make_Subprogram_Body (Loc,
2103 Specification => Body_Spec,
2104 Declarations => Empty_List,
2105 Handled_Statement_Sequence =>
2106 Make_Handled_Sequence_Of_Statements (Loc,
2107 Statements => New_List (
2108 Make_Procedure_Call_Statement (Loc,
2110 Parameter_Associations => Actuals))));
2113 end Build_Wrapper_Body;
2115 -- Start of processing for Build_Wrapper_Bodies
2118 if Is_Concurrent_Type (Typ) then
2119 Rec_Typ := Corresponding_Record_Type (Typ);
2124 -- Generate wrapper bodies for a concurrent type which implements an
2127 if Present (Interfaces (Rec_Typ)) then
2129 Insert_Nod : Node_Id;
2131 Prim_Elmt : Elmt_Id;
2132 Prim_Decl : Node_Id;
2134 Wrap_Body : Node_Id;
2135 Wrap_Id : Entity_Id;
2140 -- Examine all primitive operations of the corresponding record
2141 -- type, looking for wrapper specs. Generate bodies in order to
2144 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
2145 while Present (Prim_Elmt) loop
2146 Prim := Node (Prim_Elmt);
2148 if (Ekind (Prim) = E_Function
2149 or else Ekind (Prim) = E_Procedure)
2150 and then Is_Primitive_Wrapper (Prim)
2152 Subp := Wrapped_Entity (Prim);
2153 Prim_Decl := Parent (Parent (Prim));
2156 Build_Wrapper_Body (Loc,
2159 Formals => Parameter_Specifications (Parent (Subp)));
2160 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2162 Set_Corresponding_Spec (Wrap_Body, Prim);
2163 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2165 Insert_After (Insert_Nod, Wrap_Body);
2166 Insert_Nod := Wrap_Body;
2168 Analyze (Wrap_Body);
2171 Next_Elmt (Prim_Elmt);
2175 end Build_Wrapper_Bodies;
2177 ------------------------
2178 -- Build_Wrapper_Spec --
2179 ------------------------
2181 function Build_Wrapper_Spec
2182 (Subp_Id : Entity_Id;
2183 Obj_Typ : Entity_Id;
2184 Formals : List_Id) return Node_Id
2186 Loc : constant Source_Ptr := Sloc (Subp_Id);
2187 First_Param : Node_Id;
2189 Iface_Elmt : Elmt_Id;
2190 Iface_Op : Entity_Id;
2191 Iface_Op_Elmt : Elmt_Id;
2193 function Overriding_Possible
2194 (Iface_Op : Entity_Id;
2195 Wrapper : Entity_Id) return Boolean;
2196 -- Determine whether a primitive operation can be overridden by Wrapper.
2197 -- Iface_Op is the candidate primitive operation of an interface type,
2198 -- Wrapper is the generated entry wrapper.
2200 function Replicate_Formals
2202 Formals : List_Id) return List_Id;
2203 -- An explicit parameter replication is required due to the Is_Entry_
2204 -- Formal flag being set for all the formals of an entry. The explicit
2205 -- replication removes the flag that would otherwise cause a different
2206 -- path of analysis.
2208 -------------------------
2209 -- Overriding_Possible --
2210 -------------------------
2212 function Overriding_Possible
2213 (Iface_Op : Entity_Id;
2214 Wrapper : Entity_Id) return Boolean
2216 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2217 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2219 function Type_Conformant_Parameters
2220 (Iface_Op_Params : List_Id;
2221 Wrapper_Params : List_Id) return Boolean;
2222 -- Determine whether the parameters of the generated entry wrapper
2223 -- and those of a primitive operation are type conformant. During
2224 -- this check, the first parameter of the primitive operation is
2225 -- skipped if it is a controlling argument: protected functions
2226 -- may have a controlling result.
2228 --------------------------------
2229 -- Type_Conformant_Parameters --
2230 --------------------------------
2232 function Type_Conformant_Parameters
2233 (Iface_Op_Params : List_Id;
2234 Wrapper_Params : List_Id) return Boolean
2236 Iface_Op_Param : Node_Id;
2237 Iface_Op_Typ : Entity_Id;
2238 Wrapper_Param : Node_Id;
2239 Wrapper_Typ : Entity_Id;
2242 -- Skip the first (controlling) parameter of primitive operation
2244 Iface_Op_Param := First (Iface_Op_Params);
2246 if Present (First_Formal (Iface_Op))
2247 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2249 Iface_Op_Param := Next (Iface_Op_Param);
2252 Wrapper_Param := First (Wrapper_Params);
2253 while Present (Iface_Op_Param)
2254 and then Present (Wrapper_Param)
2256 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2257 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2259 -- The two parameters must be mode conformant
2261 if not Conforming_Types
2262 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2267 Next (Iface_Op_Param);
2268 Next (Wrapper_Param);
2271 -- One of the lists is longer than the other
2273 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2278 end Type_Conformant_Parameters;
2280 -- Start of processing for Overriding_Possible
2283 if Chars (Iface_Op) /= Chars (Wrapper) then
2287 -- If an inherited subprogram is implemented by a protected procedure
2288 -- or an entry, then the first parameter of the inherited subprogram
2289 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2291 if Ekind (Iface_Op) = E_Procedure
2292 and then Present (Parameter_Specifications (Iface_Op_Spec))
2295 Obj_Param : constant Node_Id :=
2296 First (Parameter_Specifications (Iface_Op_Spec));
2298 if not Out_Present (Obj_Param)
2299 and then Nkind (Parameter_Type (Obj_Param)) /=
2308 Type_Conformant_Parameters (
2309 Parameter_Specifications (Iface_Op_Spec),
2310 Parameter_Specifications (Wrapper_Spec));
2311 end Overriding_Possible;
2313 -----------------------
2314 -- Replicate_Formals --
2315 -----------------------
2317 function Replicate_Formals
2319 Formals : List_Id) return List_Id
2321 New_Formals : constant List_Id := New_List;
2323 Param_Type : Node_Id;
2326 Formal := First (Formals);
2328 -- Skip the object parameter when dealing with primitives declared
2329 -- between two views.
2331 if Is_Private_Primitive_Subprogram (Subp_Id)
2332 and then not Has_Controlling_Result (Subp_Id)
2334 Formal := Next (Formal);
2337 while Present (Formal) loop
2339 -- Create an explicit copy of the entry parameter
2341 -- When creating the wrapper subprogram for a primitive operation
2342 -- of a protected interface we must construct an equivalent
2343 -- signature to that of the overriding operation. For regular
2344 -- parameters we can just use the type of the formal, but for
2345 -- access to subprogram parameters we need to reanalyze the
2346 -- parameter type to create local entities for the signature of
2347 -- the subprogram type. Using the entities of the overriding
2348 -- subprogram will result in out-of-scope errors in the back-end.
2350 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2351 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2354 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
2357 Append_To (New_Formals,
2358 Make_Parameter_Specification (Loc,
2359 Defining_Identifier =>
2360 Make_Defining_Identifier (Loc,
2361 Chars => Chars (Defining_Identifier (Formal))),
2362 In_Present => In_Present (Formal),
2363 Out_Present => Out_Present (Formal),
2364 Parameter_Type => Param_Type));
2370 end Replicate_Formals;
2372 -- Start of processing for Build_Wrapper_Spec
2375 -- There is no point in building wrappers for non-tagged concurrent
2378 pragma Assert (Is_Tagged_Type (Obj_Typ));
2380 -- An entry or a protected procedure can override a routine where the
2381 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2382 -- type. Since the wrapper must have the exact same signature as that of
2383 -- the overridden subprogram, we try to find the overriding candidate
2384 -- and use its controlling formal.
2386 First_Param := Empty;
2388 -- Check every implemented interface
2390 if Present (Interfaces (Obj_Typ)) then
2391 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2392 Search : while Present (Iface_Elmt) loop
2393 Iface := Node (Iface_Elmt);
2395 -- Check every interface primitive
2397 if Present (Primitive_Operations (Iface)) then
2398 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2399 while Present (Iface_Op_Elmt) loop
2400 Iface_Op := Node (Iface_Op_Elmt);
2402 -- Ignore predefined primitives
2404 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2405 Iface_Op := Ultimate_Alias (Iface_Op);
2407 -- The current primitive operation can be overridden by
2408 -- the generated entry wrapper.
2410 if Overriding_Possible (Iface_Op, Subp_Id) then
2412 First (Parameter_Specifications (Parent (Iface_Op)));
2418 Next_Elmt (Iface_Op_Elmt);
2422 Next_Elmt (Iface_Elmt);
2426 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2427 -- this subprogram and this is not a primitive declared between two
2428 -- views then force the generation of a wrapper. As an optimization,
2429 -- previous versions of the frontend avoid generating the wrapper;
2430 -- however, the wrapper facilitates locating and reporting an error
2431 -- when a duplicate declaration is found later. See example in
2435 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2438 (Corresponding_Concurrent_Type (Obj_Typ))
2441 Make_Parameter_Specification (Loc,
2442 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2444 Out_Present => False,
2445 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2447 -- For entries and procedures of protected types the mode of
2448 -- the controlling argument must be in-out.
2452 Make_Parameter_Specification (Loc,
2453 Defining_Identifier =>
2454 Make_Defining_Identifier (Loc,
2457 Out_Present => (Ekind (Subp_Id) /= E_Function),
2458 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2463 Wrapper_Id : constant Entity_Id :=
2464 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2465 New_Formals : List_Id;
2466 Obj_Param : Node_Id;
2467 Obj_Param_Typ : Entity_Id;
2470 -- Minimum decoration is needed to catch the entity in
2471 -- Sem_Ch6.Override_Dispatching_Operation.
2473 if Ekind (Subp_Id) = E_Function then
2474 Set_Ekind (Wrapper_Id, E_Function);
2476 Set_Ekind (Wrapper_Id, E_Procedure);
2479 Set_Is_Primitive_Wrapper (Wrapper_Id);
2480 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2481 Set_Is_Private_Primitive (Wrapper_Id,
2482 Is_Private_Primitive_Subprogram (Subp_Id));
2484 -- Process the formals
2486 New_Formals := Replicate_Formals (Loc, Formals);
2488 -- A function with a controlling result and no first controlling
2489 -- formal needs no additional parameter.
2491 if Has_Controlling_Result (Subp_Id)
2493 (No (First_Formal (Subp_Id))
2494 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2498 -- Routine Subp_Id has been found to override an interface primitive.
2499 -- If the interface operation has an access parameter, create a copy
2500 -- of it, with the same null exclusion indicator if present.
2502 elsif Present (First_Param) then
2503 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2505 Make_Access_Definition (Loc,
2507 New_Reference_To (Obj_Typ, Loc));
2508 Set_Null_Exclusion_Present (Obj_Param_Typ,
2509 Null_Exclusion_Present (Parameter_Type (First_Param)));
2512 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2516 Make_Parameter_Specification (Loc,
2517 Defining_Identifier =>
2518 Make_Defining_Identifier (Loc,
2520 In_Present => In_Present (First_Param),
2521 Out_Present => Out_Present (First_Param),
2522 Parameter_Type => Obj_Param_Typ);
2524 Prepend_To (New_Formals, Obj_Param);
2526 -- If we are dealing with a primitive declared between two views,
2527 -- implemented by a synchronized operation, we need to create
2528 -- a default parameter. The mode of the parameter must match that
2529 -- of the primitive operation.
2532 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2534 Make_Parameter_Specification (Loc,
2535 Defining_Identifier =>
2536 Make_Defining_Identifier (Loc, Name_uO),
2537 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2538 Out_Present => Ekind (Subp_Id) /= E_Function,
2539 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2540 Prepend_To (New_Formals, Obj_Param);
2543 -- Build the final spec. If it is a function with a controlling
2544 -- result, it is a primitive operation of the corresponding
2545 -- record type, so mark the spec accordingly.
2547 if Ekind (Subp_Id) = E_Function then
2552 if Has_Controlling_Result (Subp_Id) then
2555 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2557 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2561 Make_Function_Specification (Loc,
2562 Defining_Unit_Name => Wrapper_Id,
2563 Parameter_Specifications => New_Formals,
2564 Result_Definition => Res_Def);
2568 Make_Procedure_Specification (Loc,
2569 Defining_Unit_Name => Wrapper_Id,
2570 Parameter_Specifications => New_Formals);
2573 end Build_Wrapper_Spec;
2575 -------------------------
2576 -- Build_Wrapper_Specs --
2577 -------------------------
2579 procedure Build_Wrapper_Specs
2585 Rec_Typ : Entity_Id;
2586 procedure Scan_Declarations (L : List_Id);
2587 -- Common processing for visible and private declarations
2588 -- of a protected type.
2590 procedure Scan_Declarations (L : List_Id) is
2592 Wrap_Decl : Node_Id;
2593 Wrap_Spec : Node_Id;
2601 while Present (Decl) loop
2604 if Nkind (Decl) = N_Entry_Declaration
2605 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2609 (Subp_Id => Defining_Identifier (Decl),
2611 Formals => Parameter_Specifications (Decl));
2613 elsif Nkind (Decl) = N_Subprogram_Declaration then
2616 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2619 Parameter_Specifications (Specification (Decl)));
2622 if Present (Wrap_Spec) then
2624 Make_Subprogram_Declaration (Loc,
2625 Specification => Wrap_Spec);
2627 Insert_After (N, Wrap_Decl);
2630 Analyze (Wrap_Decl);
2635 end Scan_Declarations;
2637 -- start of processing for Build_Wrapper_Specs
2640 if Is_Protected_Type (Typ) then
2641 Def := Protected_Definition (Parent (Typ));
2642 else pragma Assert (Is_Task_Type (Typ));
2643 Def := Task_Definition (Parent (Typ));
2646 Rec_Typ := Corresponding_Record_Type (Typ);
2648 -- Generate wrapper specs for a concurrent type which implements an
2649 -- interface. Operations in both the visible and private parts may
2650 -- implement progenitor operations.
2652 if Present (Interfaces (Rec_Typ))
2653 and then Present (Def)
2655 Scan_Declarations (Visible_Declarations (Def));
2656 Scan_Declarations (Private_Declarations (Def));
2658 end Build_Wrapper_Specs;
2660 ---------------------------
2661 -- Build_Find_Body_Index --
2662 ---------------------------
2664 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2665 Loc : constant Source_Ptr := Sloc (Typ);
2668 Has_F : Boolean := False;
2670 If_St : Node_Id := Empty;
2673 Decls : List_Id := New_List;
2676 Siz : Node_Id := Empty;
2678 procedure Add_If_Clause (Expr : Node_Id);
2679 -- Add test for range of current entry
2681 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2682 -- If a bound of an entry is given by a discriminant, retrieve the
2683 -- actual value of the discriminant from the enclosing object.
2689 procedure Add_If_Clause (Expr : Node_Id) is
2691 Stats : constant List_Id :=
2693 Make_Simple_Return_Statement (Loc,
2694 Expression => Make_Integer_Literal (Loc, Index + 1)));
2697 -- Index for current entry body
2701 -- Compute total length of entry queues so far
2709 Right_Opnd => Expr);
2714 Left_Opnd => Make_Identifier (Loc, Name_uE),
2717 -- Map entry queue indexes in the range of the current family
2718 -- into the current index, that designates the entry body.
2722 Make_Implicit_If_Statement (Typ,
2724 Then_Statements => Stats,
2725 Elsif_Parts => New_List);
2731 Make_Elsif_Part (Loc,
2733 Then_Statements => Stats),
2734 Elsif_Parts (If_St));
2738 ------------------------------
2739 -- Convert_Discriminant_Ref --
2740 ------------------------------
2742 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2746 if Is_Entity_Name (Bound)
2747 and then Ekind (Entity (Bound)) = E_Discriminant
2750 Make_Selected_Component (Loc,
2752 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2753 Make_Explicit_Dereference (Loc,
2754 Make_Identifier (Loc, Name_uObject))),
2755 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2756 Set_Etype (B, Etype (Entity (Bound)));
2758 B := New_Copy_Tree (Bound);
2762 end Convert_Discriminant_Ref;
2764 -- Start of processing for Build_Find_Body_Index
2767 Spec := Build_Find_Body_Index_Spec (Typ);
2769 Ent := First_Entity (Typ);
2770 while Present (Ent) loop
2771 if Ekind (Ent) = E_Entry_Family then
2781 -- If the protected type has no entry families, there is a one-one
2782 -- correspondence between entry queue and entry body.
2785 Make_Simple_Return_Statement (Loc,
2786 Expression => Make_Identifier (Loc, Name_uE));
2789 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2792 -- if E <= l1 then return 1;
2793 -- elsif E <= l1 + l2 then return 2;
2798 Ent := First_Entity (Typ);
2800 Add_Object_Pointer (Loc, Typ, Decls);
2802 while Present (Ent) loop
2803 if Ekind (Ent) = E_Entry then
2804 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2806 elsif Ekind (Ent) = E_Entry_Family then
2807 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2808 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2809 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2810 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2819 Make_Simple_Return_Statement (Loc,
2820 Expression => Make_Integer_Literal (Loc, 1));
2822 elsif Nkind (Ret) = N_If_Statement then
2824 -- Ranges are in increasing order, so last one doesn't need guard
2827 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2830 Set_Else_Statements (Ret, Then_Statements (Nod));
2836 Make_Subprogram_Body (Loc,
2837 Specification => Spec,
2838 Declarations => Decls,
2839 Handled_Statement_Sequence =>
2840 Make_Handled_Sequence_Of_Statements (Loc,
2841 Statements => New_List (Ret)));
2842 end Build_Find_Body_Index;
2844 --------------------------------
2845 -- Build_Find_Body_Index_Spec --
2846 --------------------------------
2848 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2849 Loc : constant Source_Ptr := Sloc (Typ);
2850 Id : constant Entity_Id :=
2851 Make_Defining_Identifier (Loc,
2852 Chars => New_External_Name (Chars (Typ), 'F'));
2853 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2854 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2858 Make_Function_Specification (Loc,
2859 Defining_Unit_Name => Id,
2860 Parameter_Specifications => New_List (
2861 Make_Parameter_Specification (Loc,
2862 Defining_Identifier => Parm1,
2864 New_Reference_To (RTE (RE_Address), Loc)),
2866 Make_Parameter_Specification (Loc,
2867 Defining_Identifier => Parm2,
2869 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2870 Result_Definition => New_Occurrence_Of (
2871 RTE (RE_Protected_Entry_Index), Loc));
2872 end Build_Find_Body_Index_Spec;
2874 -------------------------
2875 -- Build_Master_Entity --
2876 -------------------------
2878 procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
2879 Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
2881 Context_Id : Entity_Id;
2887 if Is_Itype (Obj_Or_Typ) then
2888 Par := Associated_Node_For_Itype (Obj_Or_Typ);
2890 Par := Parent (Obj_Or_Typ);
2893 -- When creating a master for a record component which is either a task
2894 -- or access-to-task, the enclosing record is the master scope and the
2895 -- proper insertion point is the component list.
2897 if Is_Record_Type (Current_Scope) then
2899 Context_Id := Current_Scope;
2900 Decls := List_Containing (Context);
2902 -- Default case for object declarations and access types. Note that the
2903 -- context is updated to the nearest enclosing body, block, package or
2904 -- return statement.
2907 Find_Enclosing_Context (Par, Context, Context_Id, Decls);
2910 -- Do not create a master if one already exists or there is no task
2913 if Has_Master_Entity (Context_Id)
2914 or else Restriction_Active (No_Task_Hierarchy)
2919 -- Create a master, generate:
2920 -- _Master : constant Master_Id := Current_Master.all;
2923 Make_Object_Declaration (Loc,
2924 Defining_Identifier =>
2925 Make_Defining_Identifier (Loc, Name_uMaster),
2926 Constant_Present => True,
2927 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2929 Make_Explicit_Dereference (Loc,
2930 New_Reference_To (RTE (RE_Current_Master), Loc)));
2932 -- The master is inserted at the start of the declarative list of the
2935 Prepend_To (Decls, Decl);
2937 -- In certain cases where transient scopes are involved, the immediate
2938 -- scope is not always the proper master scope. Ensure that the master
2939 -- declaration and entity appear in the same context.
2941 if Context_Id /= Current_Scope then
2942 Push_Scope (Context_Id);
2949 -- Mark the enclosing scope and its associated construct as being task
2952 Set_Has_Master_Entity (Context_Id);
2954 while Present (Context)
2955 and then Nkind (Context) /= N_Compilation_Unit
2957 if Nkind_In (Context, N_Block_Statement,
2961 Set_Is_Task_Master (Context);
2964 elsif Nkind (Parent (Context)) = N_Subunit then
2965 Context := Corresponding_Stub (Parent (Context));
2968 Context := Parent (Context);
2970 end Build_Master_Entity;
2972 ---------------------------
2973 -- Build_Master_Renaming --
2974 ---------------------------
2976 procedure Build_Master_Renaming
2977 (Ptr_Typ : Entity_Id;
2978 Ins_Nod : Node_Id := Empty)
2980 Loc : constant Source_Ptr := Sloc (Ptr_Typ);
2982 Master_Decl : Node_Id;
2983 Master_Id : Entity_Id;
2986 -- Nothing to do if there is no task hierarchy
2988 if Restriction_Active (No_Task_Hierarchy) then
2992 -- Determine the proper context to insert the master renaming
2994 if Present (Ins_Nod) then
2996 elsif Is_Itype (Ptr_Typ) then
2997 Context := Associated_Node_For_Itype (Ptr_Typ);
2999 Context := Parent (Ptr_Typ);
3003 -- <Ptr_Typ>M : Master_Id renames _Master;
3006 Make_Defining_Identifier (Loc,
3007 New_External_Name (Chars (Ptr_Typ), 'M'));
3010 Make_Object_Renaming_Declaration (Loc,
3011 Defining_Identifier => Master_Id,
3012 Subtype_Mark => New_Reference_To (RTE (RE_Master_Id), Loc),
3013 Name => Make_Identifier (Loc, Name_uMaster));
3015 Insert_Action (Context, Master_Decl);
3017 -- The renamed master now services the access type
3019 Set_Master_Id (Ptr_Typ, Master_Id);
3020 end Build_Master_Renaming;
3022 -----------------------------------------
3023 -- Build_Private_Protected_Declaration --
3024 -----------------------------------------
3026 function Build_Private_Protected_Declaration
3027 (N : Node_Id) return Entity_Id
3029 Loc : constant Source_Ptr := Sloc (N);
3030 Body_Id : constant Entity_Id := Defining_Entity (N);
3035 Spec_Id : Entity_Id;
3038 Formal := First_Formal (Body_Id);
3040 -- The protected operation always has at least one formal, namely the
3041 -- object itself, but it is only placed in the parameter list if
3042 -- expansion is enabled.
3044 if Present (Formal) or else Expander_Active then
3045 Plist := Copy_Parameter_List (Body_Id);
3050 if Nkind (Specification (N)) = N_Procedure_Specification then
3052 Make_Procedure_Specification (Loc,
3053 Defining_Unit_Name =>
3054 Make_Defining_Identifier (Sloc (Body_Id),
3055 Chars => Chars (Body_Id)),
3056 Parameter_Specifications =>
3060 Make_Function_Specification (Loc,
3061 Defining_Unit_Name =>
3062 Make_Defining_Identifier (Sloc (Body_Id),
3063 Chars => Chars (Body_Id)),
3064 Parameter_Specifications => Plist,
3065 Result_Definition =>
3066 New_Occurrence_Of (Etype (Body_Id), Loc));
3069 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
3070 Insert_Before (N, Decl);
3071 Spec_Id := Defining_Unit_Name (New_Spec);
3073 -- Indicate that the entity comes from source, to ensure that cross-
3074 -- reference information is properly generated. The body itself is
3075 -- rewritten during expansion, and the body entity will not appear in
3076 -- calls to the operation.
3078 Set_Comes_From_Source (Spec_Id, True);
3080 Set_Has_Completion (Spec_Id);
3081 Set_Convention (Spec_Id, Convention_Protected);
3083 end Build_Private_Protected_Declaration;
3085 ---------------------------
3086 -- Build_Protected_Entry --
3087 ---------------------------
3089 function Build_Protected_Entry
3092 Pid : Node_Id) return Node_Id
3094 Loc : constant Source_Ptr := Sloc (N);
3096 Decls : constant List_Id := Declarations (N);
3097 End_Lab : constant Node_Id :=
3098 End_Label (Handled_Statement_Sequence (N));
3099 End_Loc : constant Source_Ptr :=
3100 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
3101 -- Used for the generated call to Complete_Entry_Body
3103 Han_Loc : Source_Ptr;
3104 -- Used for the exception handler, inserted at end of the body
3106 Op_Decls : constant List_Id := New_List;
3114 -- Set the source location on the exception handler only when debugging
3115 -- the expanded code (see Make_Implicit_Exception_Handler).
3117 if Debug_Generated_Code then
3120 -- Otherwise the inserted code should not be visible to the debugger
3123 Han_Loc := No_Location;
3127 Make_Defining_Identifier (Loc,
3128 Chars => Chars (Protected_Body_Subprogram (Ent)));
3130 Build_Protected_Entry_Specification (Loc, Edef, Empty);
3132 -- Add the following declarations:
3133 -- type poVP is access poV;
3134 -- _object : poVP := poVP (_O);
3136 -- where _O is the formal parameter associated with the concurrent
3137 -- object. These declarations are needed for Complete_Entry_Body.
3139 Add_Object_Pointer (Loc, Pid, Op_Decls);
3141 -- Add renamings for all formals, the Protection object, discriminals,
3142 -- privals and the entry index constant for use by debugger.
3144 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
3145 Debug_Private_Data_Declarations (Decls);
3147 case Corresponding_Runtime_Package (Pid) is
3148 when System_Tasking_Protected_Objects_Entries =>
3150 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
3152 when System_Tasking_Protected_Objects_Single_Entry =>
3154 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
3157 raise Program_Error;
3160 Op_Stats := New_List (
3161 Make_Block_Statement (Loc,
3162 Declarations => Decls,
3163 Handled_Statement_Sequence =>
3164 Handled_Statement_Sequence (N)),
3166 Make_Procedure_Call_Statement (End_Loc,
3168 Parameter_Associations => New_List (
3169 Make_Attribute_Reference (End_Loc,
3171 Make_Selected_Component (End_Loc,
3172 Prefix => Make_Identifier (End_Loc, Name_uObject),
3173 Selector_Name => Make_Identifier (End_Loc, Name_uObject)),
3174 Attribute_Name => Name_Unchecked_Access))));
3176 -- When exceptions can not be propagated, we never need to call
3177 -- Exception_Complete_Entry_Body
3179 if No_Exception_Handlers_Set then
3181 Make_Subprogram_Body (Loc,
3182 Specification => Espec,
3183 Declarations => Op_Decls,
3184 Handled_Statement_Sequence =>
3185 Make_Handled_Sequence_Of_Statements (Loc,
3186 Statements => Op_Stats,
3187 End_Label => End_Lab));
3190 Ohandle := Make_Others_Choice (Loc);
3191 Set_All_Others (Ohandle);
3193 case Corresponding_Runtime_Package (Pid) is
3194 when System_Tasking_Protected_Objects_Entries =>
3197 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
3199 when System_Tasking_Protected_Objects_Single_Entry =>
3202 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
3205 raise Program_Error;
3208 -- Establish link between subprogram body entity and source entry
3210 Set_Corresponding_Protected_Entry (Edef, Ent);
3212 -- Create body of entry procedure. The renaming declarations are
3213 -- placed ahead of the block that contains the actual entry body.
3216 Make_Subprogram_Body (Loc,
3217 Specification => Espec,
3218 Declarations => Op_Decls,
3219 Handled_Statement_Sequence =>
3220 Make_Handled_Sequence_Of_Statements (Loc,
3221 Statements => Op_Stats,
3222 End_Label => End_Lab,
3223 Exception_Handlers => New_List (
3224 Make_Implicit_Exception_Handler (Han_Loc,
3225 Exception_Choices => New_List (Ohandle),
3227 Statements => New_List (
3228 Make_Procedure_Call_Statement (Han_Loc,
3230 Parameter_Associations => New_List (
3231 Make_Attribute_Reference (Han_Loc,
3233 Make_Selected_Component (Han_Loc,
3235 Make_Identifier (Han_Loc, Name_uObject),
3237 Make_Identifier (Han_Loc, Name_uObject)),
3238 Attribute_Name => Name_Unchecked_Access),
3240 Make_Function_Call (Han_Loc,
3241 Name => New_Reference_To (
3242 RTE (RE_Get_GNAT_Exception), Loc)))))))));
3244 end Build_Protected_Entry;
3246 -----------------------------------------
3247 -- Build_Protected_Entry_Specification --
3248 -----------------------------------------
3250 function Build_Protected_Entry_Specification
3253 Ent_Id : Entity_Id) return Node_Id
3255 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3258 Set_Debug_Info_Needed (Def_Id);
3260 if Present (Ent_Id) then
3261 Append_Elmt (P, Accept_Address (Ent_Id));
3265 Make_Procedure_Specification (Loc,
3266 Defining_Unit_Name => Def_Id,
3267 Parameter_Specifications => New_List (
3268 Make_Parameter_Specification (Loc,
3269 Defining_Identifier =>
3270 Make_Defining_Identifier (Loc, Name_uO),
3272 New_Reference_To (RTE (RE_Address), Loc)),
3274 Make_Parameter_Specification (Loc,
3275 Defining_Identifier => P,
3277 New_Reference_To (RTE (RE_Address), Loc)),
3279 Make_Parameter_Specification (Loc,
3280 Defining_Identifier =>
3281 Make_Defining_Identifier (Loc, Name_uE),
3283 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
3284 end Build_Protected_Entry_Specification;
3286 --------------------------
3287 -- Build_Protected_Spec --
3288 --------------------------
3290 function Build_Protected_Spec
3292 Obj_Type : Entity_Id;
3294 Unprotected : Boolean := False) return List_Id
3296 Loc : constant Source_Ptr := Sloc (N);
3299 New_Plist : List_Id;
3300 New_Param : Node_Id;
3303 New_Plist := New_List;
3305 Formal := First_Formal (Ident);
3306 while Present (Formal) loop
3308 Make_Parameter_Specification (Loc,
3309 Defining_Identifier =>
3310 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
3311 In_Present => In_Present (Parent (Formal)),
3312 Out_Present => Out_Present (Parent (Formal)),
3313 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
3316 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3319 Append (New_Param, New_Plist);
3320 Next_Formal (Formal);
3323 -- If the subprogram is a procedure and the context is not an access
3324 -- to protected subprogram, the parameter is in-out. Otherwise it is
3328 Make_Parameter_Specification (Loc,
3329 Defining_Identifier =>
3330 Make_Defining_Identifier (Loc, Name_uObject),
3333 (Etype (Ident) = Standard_Void_Type
3334 and then not Is_RTE (Obj_Type, RE_Address)),
3336 New_Reference_To (Obj_Type, Loc));
3337 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3338 Prepend_To (New_Plist, Decl);
3341 end Build_Protected_Spec;
3343 ---------------------------------------
3344 -- Build_Protected_Sub_Specification --
3345 ---------------------------------------
3347 function Build_Protected_Sub_Specification
3349 Prot_Typ : Entity_Id;
3350 Mode : Subprogram_Protection_Mode) return Node_Id
3352 Loc : constant Source_Ptr := Sloc (N);
3356 New_Plist : List_Id;
3359 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3360 (Dispatching_Mode => ' ',
3361 Protected_Mode => 'P',
3362 Unprotected_Mode => 'N');
3365 if Ekind (Defining_Unit_Name (Specification (N))) =
3368 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3373 Def_Id := Defining_Unit_Name (Specification (Decl));
3376 Build_Protected_Spec
3377 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3378 Mode = Unprotected_Mode);
3380 Make_Defining_Identifier (Loc,
3381 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3383 -- The unprotected operation carries the user code, and debugging
3384 -- information must be generated for it, even though this spec does
3385 -- not come from source. It is also convenient to allow gdb to step
3386 -- into the protected operation, even though it only contains lock/
3389 Set_Debug_Info_Needed (New_Id);
3391 -- If a pragma Eliminate applies to the source entity, the internal
3392 -- subprograms will be eliminated as well.
3394 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3396 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3398 Make_Procedure_Specification (Loc,
3399 Defining_Unit_Name => New_Id,
3400 Parameter_Specifications => New_Plist);
3402 -- Create a new specification for the anonymous subprogram type
3406 Make_Function_Specification (Loc,
3407 Defining_Unit_Name => New_Id,
3408 Parameter_Specifications => New_Plist,
3409 Result_Definition =>
3410 Copy_Result_Type (Result_Definition (Specification (Decl))));
3412 Set_Return_Present (Defining_Unit_Name (New_Spec));
3416 end Build_Protected_Sub_Specification;
3418 -------------------------------------
3419 -- Build_Protected_Subprogram_Body --
3420 -------------------------------------
3422 function Build_Protected_Subprogram_Body
3425 N_Op_Spec : Node_Id) return Node_Id
3427 Loc : constant Source_Ptr := Sloc (N);
3429 P_Op_Spec : Node_Id;
3432 Unprot_Call : Node_Id;
3434 Lock_Name : Node_Id;
3435 Lock_Stmt : Node_Id;
3436 Service_Name : Node_Id;
3438 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3439 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3441 Object_Parm : Node_Id;
3445 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3446 -- Tell whether a given subprogram cannot raise an exception
3448 -----------------------
3449 -- Is_Exception_Safe --
3450 -----------------------
3452 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3454 function Has_Side_Effect (N : Node_Id) return Boolean;
3455 -- Return True whenever encountering a subprogram call or raise
3456 -- statement of any kind in the sequence of statements
3458 ---------------------
3459 -- Has_Side_Effect --
3460 ---------------------
3462 -- What is this doing buried two levels down in exp_ch9. It seems
3463 -- like a generally useful function, and indeed there may be code
3464 -- duplication going on here ???
3466 function Has_Side_Effect (N : Node_Id) return Boolean is
3470 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3471 -- Indicate whether N is a subprogram call or a raise statement
3473 ----------------------
3474 -- Is_Call_Or_Raise --
3475 ----------------------
3477 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3479 return Nkind_In (N, N_Procedure_Call_Statement,
3482 N_Raise_Constraint_Error,
3483 N_Raise_Program_Error,
3484 N_Raise_Storage_Error);
3485 end Is_Call_Or_Raise;
3487 -- Start of processing for Has_Side_Effect
3491 while Present (Stmt) loop
3492 if Is_Call_Or_Raise (Stmt) then
3496 -- An object declaration can also contain a function call
3497 -- or a raise statement
3499 if Nkind (Stmt) = N_Object_Declaration then
3500 Expr := Expression (Stmt);
3502 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3511 end Has_Side_Effect;
3513 -- Start of processing for Is_Exception_Safe
3516 -- If the checks handled by the back end are not disabled, we cannot
3517 -- ensure that no exception will be raised.
3519 if not Access_Checks_Suppressed (Empty)
3520 or else not Discriminant_Checks_Suppressed (Empty)
3521 or else not Range_Checks_Suppressed (Empty)
3522 or else not Index_Checks_Suppressed (Empty)
3523 or else Opt.Stack_Checking_Enabled
3528 if Has_Side_Effect (First (Declarations (Subprogram)))
3531 First (Statements (Handled_Statement_Sequence (Subprogram))))
3537 end Is_Exception_Safe;
3539 -- Start of processing for Build_Protected_Subprogram_Body
3542 Op_Spec := Specification (N);
3543 Exc_Safe := Is_Exception_Safe (N);
3546 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3548 -- Build a list of the formal parameters of the protected version of
3549 -- the subprogram to use as the actual parameters of the unprotected
3552 Uactuals := New_List;
3553 Pformal := First (Parameter_Specifications (P_Op_Spec));
3554 while Present (Pformal) loop
3555 Append_To (Uactuals,
3556 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
3560 -- Make a call to the unprotected version of the subprogram built above
3561 -- for use by the protected version built below.
3563 if Nkind (Op_Spec) = N_Function_Specification then
3565 R := Make_Temporary (Loc, 'R');
3567 Make_Object_Declaration (Loc,
3568 Defining_Identifier => R,
3569 Constant_Present => True,
3570 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3572 Make_Function_Call (Loc,
3573 Name => Make_Identifier (Loc,
3574 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3575 Parameter_Associations => Uactuals));
3578 Make_Simple_Return_Statement (Loc,
3579 Expression => New_Reference_To (R, Loc));
3582 Unprot_Call := Make_Simple_Return_Statement (Loc,
3583 Expression => Make_Function_Call (Loc,
3585 Make_Identifier (Loc,
3586 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3587 Parameter_Associations => Uactuals));
3590 Lock_Kind := RE_Lock_Read_Only;
3594 Make_Procedure_Call_Statement (Loc,
3596 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3597 Parameter_Associations => Uactuals);
3599 Lock_Kind := RE_Lock;
3602 -- Wrap call in block that will be covered by an at_end handler
3604 if not Exc_Safe then
3605 Unprot_Call := Make_Block_Statement (Loc,
3606 Handled_Statement_Sequence =>
3607 Make_Handled_Sequence_Of_Statements (Loc,
3608 Statements => New_List (Unprot_Call)));
3611 -- Make the protected subprogram body. This locks the protected
3612 -- object and calls the unprotected version of the subprogram.
3614 case Corresponding_Runtime_Package (Pid) is
3615 when System_Tasking_Protected_Objects_Entries =>
3616 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3617 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3619 when System_Tasking_Protected_Objects_Single_Entry =>
3620 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3621 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3623 when System_Tasking_Protected_Objects =>
3624 Lock_Name := New_Reference_To (RTE (Lock_Kind), Loc);
3625 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3628 raise Program_Error;
3632 Make_Attribute_Reference (Loc,
3634 Make_Selected_Component (Loc,
3635 Prefix => Make_Identifier (Loc, Name_uObject),
3636 Selector_Name => Make_Identifier (Loc, Name_uObject)),
3637 Attribute_Name => Name_Unchecked_Access);
3639 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3641 Parameter_Associations => New_List (Object_Parm));
3643 if Abort_Allowed then
3645 Make_Procedure_Call_Statement (Loc,
3646 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3647 Parameter_Associations => Empty_List),
3651 Stmts := New_List (Lock_Stmt);
3654 if not Exc_Safe then
3655 Append (Unprot_Call, Stmts);
3657 if Nkind (Op_Spec) = N_Function_Specification then
3659 Stmts := Empty_List;
3661 Append (Unprot_Call, Stmts);
3665 Make_Procedure_Call_Statement (Loc,
3666 Name => Service_Name,
3667 Parameter_Associations =>
3668 New_List (New_Copy_Tree (Object_Parm))),
3671 if Abort_Allowed then
3673 Make_Procedure_Call_Statement (Loc,
3674 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3675 Parameter_Associations => Empty_List),
3679 if Nkind (Op_Spec) = N_Function_Specification then
3680 Append (Return_Stmt, Stmts);
3681 Append (Make_Block_Statement (Loc,
3682 Declarations => New_List (Unprot_Call),
3683 Handled_Statement_Sequence =>
3684 Make_Handled_Sequence_Of_Statements (Loc,
3685 Statements => Stmts)), Pre_Stmts);
3691 Make_Subprogram_Body (Loc,
3692 Declarations => Empty_List,
3693 Specification => P_Op_Spec,
3694 Handled_Statement_Sequence =>
3695 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3697 if not Exc_Safe then
3698 Set_Is_Protected_Subprogram_Body (Sub_Body);
3702 end Build_Protected_Subprogram_Body;
3704 -------------------------------------
3705 -- Build_Protected_Subprogram_Call --
3706 -------------------------------------
3708 procedure Build_Protected_Subprogram_Call
3712 External : Boolean := True)
3714 Loc : constant Source_Ptr := Sloc (N);
3715 Sub : constant Entity_Id := Entity (Name);
3721 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3724 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3727 if Present (Parameter_Associations (N)) then
3728 Params := New_Copy_List_Tree (Parameter_Associations (N));
3733 -- If the type is an untagged derived type, convert to the root type,
3734 -- which is the one on which the operations are defined.
3736 if Nkind (Rec) = N_Unchecked_Type_Conversion
3737 and then not Is_Tagged_Type (Etype (Rec))
3738 and then Is_Derived_Type (Etype (Rec))
3740 Set_Etype (Rec, Root_Type (Etype (Rec)));
3741 Set_Subtype_Mark (Rec,
3742 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3745 Prepend (Rec, Params);
3747 if Ekind (Sub) = E_Procedure then
3749 Make_Procedure_Call_Statement (Loc,
3751 Parameter_Associations => Params));
3754 pragma Assert (Ekind (Sub) = E_Function);
3756 Make_Function_Call (Loc,
3758 Parameter_Associations => Params));
3762 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3763 and then Is_Entity_Name (Expression (Rec))
3764 and then Is_Shared_Passive (Entity (Expression (Rec)))
3766 Add_Shared_Var_Lock_Procs (N);
3768 end Build_Protected_Subprogram_Call;
3770 -------------------------
3771 -- Build_Selected_Name --
3772 -------------------------
3774 function Build_Selected_Name
3775 (Prefix : Entity_Id;
3776 Selector : Entity_Id;
3777 Append_Char : Character := ' ') return Name_Id
3779 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3780 Select_Len : Natural;
3783 Get_Name_String (Chars (Selector));
3784 Select_Len := Name_Len;
3785 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3786 Get_Name_String (Chars (Prefix));
3788 -- If scope is anonymous type, discard suffix to recover name of
3789 -- single protected object. Otherwise use protected type name.
3791 if Name_Buffer (Name_Len) = 'T' then
3792 Name_Len := Name_Len - 1;
3795 Add_Str_To_Name_Buffer ("__");
3796 for J in 1 .. Select_Len loop
3797 Add_Char_To_Name_Buffer (Select_Buffer (J));
3800 -- Now add the Append_Char if specified. The encoding to follow
3801 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3802 -- then the entity is associated to a protected type subprogram.
3803 -- Otherwise, it is a protected type entry. For each case, the
3804 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3806 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3808 if Append_Char /= ' ' then
3809 if Append_Char = 'P' or Append_Char = 'N' then
3810 Add_Char_To_Name_Buffer (Append_Char);
3813 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3814 return New_External_Name (Name_Find, ' ', -1);
3819 end Build_Selected_Name;
3821 -----------------------------
3822 -- Build_Simple_Entry_Call --
3823 -----------------------------
3825 -- A task entry call is converted to a call to Call_Simple
3828 -- P : parms := (parm, parm, parm);
3830 -- Call_Simple (acceptor-task, entry-index, P'Address);
3836 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3837 -- the parameters, and the constructed aggregate value contains either the
3838 -- parameters or, in the case of non-elementary types, references to these
3839 -- parameters. Then the address of this aggregate is passed to the runtime
3840 -- routine, along with the task id value and the task entry index value.
3841 -- Pnn is only required if parameters are present.
3843 -- The assignments after the call are present only in the case of in-out
3844 -- or out parameters for elementary types, and are used to assign back the
3845 -- resulting values of such parameters.
3847 -- Note: the reason that we insert a block here is that in the context
3848 -- of selects, conditional entry calls etc. the entry call statement
3849 -- appears on its own, not as an element of a list.
3851 -- A protected entry call is converted to a Protected_Entry_Call:
3854 -- P : E1_Params := (param, param, param);
3856 -- Bnn : Communications_Block;
3859 -- P : E1_Params := (param, param, param);
3860 -- Bnn : Communications_Block;
3863 -- Protected_Entry_Call (
3864 -- Object => po._object'Access,
3865 -- E => <entry index>;
3866 -- Uninterpreted_Data => P'Address;
3867 -- Mode => Simple_Call;
3874 procedure Build_Simple_Entry_Call
3883 -- If call has been inlined, nothing left to do
3885 if Nkind (N) = N_Block_Statement then
3889 -- Convert entry call to Call_Simple call
3892 Loc : constant Source_Ptr := Sloc (N);
3893 Parms : constant List_Id := Parameter_Associations (N);
3894 Stats : constant List_Id := New_List;
3897 Comm_Name : Entity_Id;
3901 Ent_Acc : Entity_Id;
3903 Iface_Tag : Entity_Id;
3904 Iface_Typ : Entity_Id;
3917 -- Simple entry and entry family cases merge here
3919 Ent := Entity (Ename);
3920 Ent_Acc := Entry_Parameters_Type (Ent);
3921 Conctyp := Etype (Concval);
3923 -- If prefix is an access type, dereference to obtain the task type
3925 if Is_Access_Type (Conctyp) then
3926 Conctyp := Designated_Type (Conctyp);
3929 -- Special case for protected subprogram calls
3931 if Is_Protected_Type (Conctyp)
3932 and then Is_Subprogram (Entity (Ename))
3934 if not Is_Eliminated (Entity (Ename)) then
3935 Build_Protected_Subprogram_Call
3936 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3943 -- First parameter is the Task_Id value from the task value or the
3944 -- Object from the protected object value, obtained by selecting
3945 -- the _Task_Id or _Object from the result of doing an unchecked
3946 -- conversion to convert the value to the corresponding record type.
3948 if Nkind (Concval) = N_Function_Call
3949 and then Is_Task_Type (Conctyp)
3950 and then Ada_Version >= Ada_2005
3953 ExpR : constant Node_Id := Relocate_Node (Concval);
3954 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3959 Make_Object_Declaration (Loc,
3960 Defining_Identifier => Obj,
3961 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3962 Expression => ExpR);
3963 Set_Etype (Obj, Conctyp);
3964 Decls := New_List (Decl);
3965 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3972 Parm1 := Concurrent_Ref (Concval);
3974 -- Second parameter is the entry index, computed by the routine
3975 -- provided for this purpose. The value of this expression is
3976 -- assigned to an intermediate variable to assure that any entry
3977 -- family index expressions are evaluated before the entry
3981 or else Restriction_Active (No_Entry_Queue) = False
3982 or else not Is_Protected_Type (Conctyp)
3983 or else Number_Entries (Conctyp) > 1
3984 or else (Has_Attach_Handler (Conctyp)
3985 and then not Restricted_Profile)
3987 X := Make_Defining_Identifier (Loc, Name_uX);
3990 Make_Object_Declaration (Loc,
3991 Defining_Identifier => X,
3992 Object_Definition =>
3993 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3994 Expression => Actual_Index_Expression (
3995 Loc, Entity (Ename), Index, Concval));
3997 Append_To (Decls, Xdecl);
3998 Parm2 := New_Reference_To (X, Loc);
4005 -- The third parameter is the packaged parameters. If there are
4006 -- none, then it is just the null address, since nothing is passed.
4009 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
4012 -- Case of parameters present, where third argument is the address
4013 -- of a packaged record containing the required parameter values.
4016 -- First build a list of parameter values, which are references to
4017 -- objects of the parameter types.
4021 Actual := First_Actual (N);
4022 Formal := First_Formal (Ent);
4024 while Present (Actual) loop
4026 -- If it is a by_copy_type, copy it to a new variable. The
4027 -- packaged record has a field that points to this variable.
4029 if Is_By_Copy_Type (Etype (Actual)) then
4031 Make_Object_Declaration (Loc,
4032 Defining_Identifier => Make_Temporary (Loc, 'J'),
4033 Aliased_Present => True,
4034 Object_Definition =>
4035 New_Reference_To (Etype (Formal), Loc));
4037 -- Mark the object as not needing initialization since the
4038 -- initialization is performed separately, avoiding errors
4039 -- on cases such as formals of null-excluding access types.
4041 Set_No_Initialization (N_Node);
4043 -- We must make an assignment statement separate for the
4044 -- case of limited type. We cannot assign it unless the
4045 -- Assignment_OK flag is set first. An out formal of an
4046 -- access type must also be initialized from the actual,
4047 -- as stated in RM 6.4.1 (13).
4049 if Ekind (Formal) /= E_Out_Parameter
4050 or else Is_Access_Type (Etype (Formal))
4053 New_Reference_To (Defining_Identifier (N_Node), Loc);
4054 Set_Assignment_OK (N_Var);
4056 Make_Assignment_Statement (Loc,
4058 Expression => Relocate_Node (Actual)));
4061 Append (N_Node, Decls);
4064 Make_Attribute_Reference (Loc,
4065 Attribute_Name => Name_Unchecked_Access,
4067 New_Reference_To (Defining_Identifier (N_Node), Loc)));
4069 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4071 elsif Is_VM_By_Copy_Actual (Actual) then
4073 Make_Object_Declaration (Loc,
4074 Defining_Identifier => Make_Temporary (Loc, 'J'),
4075 Aliased_Present => True,
4076 Object_Definition =>
4077 New_Reference_To (Etype (Formal), Loc),
4078 Expression => New_Copy_Tree (Actual));
4079 Set_Assignment_OK (N_Node);
4081 Append (N_Node, Decls);
4084 Make_Attribute_Reference (Loc,
4085 Attribute_Name => Name_Unchecked_Access,
4087 New_Reference_To (Defining_Identifier (N_Node), Loc)));
4090 -- Interface class-wide formal
4092 if Ada_Version >= Ada_2005
4093 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
4094 and then Is_Interface (Etype (Formal))
4096 Iface_Typ := Etype (Etype (Formal));
4099 -- formal_iface_type! (actual.iface_tag)'reference
4102 Find_Interface_Tag (Etype (Actual), Iface_Typ);
4103 pragma Assert (Present (Iface_Tag));
4106 Make_Reference (Loc,
4107 Unchecked_Convert_To (Iface_Typ,
4108 Make_Selected_Component (Loc,
4110 Relocate_Node (Actual),
4112 New_Reference_To (Iface_Tag, Loc)))));
4118 Make_Reference (Loc, Relocate_Node (Actual)));
4122 Next_Actual (Actual);
4123 Next_Formal_With_Extras (Formal);
4126 -- Now build the declaration of parameters initialized with the
4127 -- aggregate containing this constructed parameter list.
4129 P := Make_Defining_Identifier (Loc, Name_uP);
4132 Make_Object_Declaration (Loc,
4133 Defining_Identifier => P,
4134 Object_Definition =>
4135 New_Reference_To (Designated_Type (Ent_Acc), Loc),
4137 Make_Aggregate (Loc, Expressions => Plist));
4140 Make_Attribute_Reference (Loc,
4141 Prefix => New_Reference_To (P, Loc),
4142 Attribute_Name => Name_Address);
4144 Append (Pdecl, Decls);
4147 -- Now we can create the call, case of protected type
4149 if Is_Protected_Type (Conctyp) then
4150 case Corresponding_Runtime_Package (Conctyp) is
4151 when System_Tasking_Protected_Objects_Entries =>
4153 -- Change the type of the index declaration
4155 Set_Object_Definition (Xdecl,
4156 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
4158 -- Some additional declarations for protected entry calls
4164 -- Bnn : Communications_Block;
4166 Comm_Name := Make_Temporary (Loc, 'B');
4169 Make_Object_Declaration (Loc,
4170 Defining_Identifier => Comm_Name,
4171 Object_Definition =>
4172 New_Reference_To (RTE (RE_Communication_Block), Loc)));
4174 -- Some additional statements for protected entry calls
4176 -- Protected_Entry_Call (
4177 -- Object => po._object'Access,
4178 -- E => <entry index>;
4179 -- Uninterpreted_Data => P'Address;
4180 -- Mode => Simple_Call;
4184 Make_Procedure_Call_Statement (Loc,
4186 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
4188 Parameter_Associations => New_List (
4189 Make_Attribute_Reference (Loc,
4190 Attribute_Name => Name_Unchecked_Access,
4194 New_Reference_To (RTE (RE_Simple_Call), Loc),
4195 New_Occurrence_Of (Comm_Name, Loc)));
4197 when System_Tasking_Protected_Objects_Single_Entry =>
4198 -- Protected_Single_Entry_Call (
4199 -- Object => po._object'Access,
4200 -- Uninterpreted_Data => P'Address;
4201 -- Mode => Simple_Call);
4204 Make_Procedure_Call_Statement (Loc,
4205 Name => New_Reference_To (
4206 RTE (RE_Protected_Single_Entry_Call), Loc),
4208 Parameter_Associations => New_List (
4209 Make_Attribute_Reference (Loc,
4210 Attribute_Name => Name_Unchecked_Access,
4213 New_Reference_To (RTE (RE_Simple_Call), Loc)));
4216 raise Program_Error;
4219 -- Case of task type
4223 Make_Procedure_Call_Statement (Loc,
4224 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
4225 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
4229 Append_To (Stats, Call);
4231 -- If there are out or in/out parameters by copy add assignment
4232 -- statements for the result values.
4234 if Present (Parms) then
4235 Actual := First_Actual (N);
4236 Formal := First_Formal (Ent);
4238 Set_Assignment_OK (Actual);
4239 while Present (Actual) loop
4240 if (Is_By_Copy_Type (Etype (Actual))
4241 or else Is_VM_By_Copy_Actual (Actual))
4242 and then Ekind (Formal) /= E_In_Parameter
4245 Make_Assignment_Statement (Loc,
4246 Name => New_Copy (Actual),
4248 Make_Explicit_Dereference (Loc,
4249 Make_Selected_Component (Loc,
4250 Prefix => New_Reference_To (P, Loc),
4252 Make_Identifier (Loc, Chars (Formal)))));
4254 -- In all cases (including limited private types) we want
4255 -- the assignment to be valid.
4257 Set_Assignment_OK (Name (N_Node));
4259 -- If the call is the triggering alternative in an
4260 -- asynchronous select, or the entry_call alternative of a
4261 -- conditional entry call, the assignments for in-out
4262 -- parameters are incorporated into the statement list that
4263 -- follows, so that there are executed only if the entry
4266 if (Nkind (Parent (N)) = N_Triggering_Alternative
4267 and then N = Triggering_Statement (Parent (N)))
4269 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4270 and then N = Entry_Call_Statement (Parent (N)))
4272 if No (Statements (Parent (N))) then
4273 Set_Statements (Parent (N), New_List);
4276 Prepend (N_Node, Statements (Parent (N)));
4279 Insert_After (Call, N_Node);
4283 Next_Actual (Actual);
4284 Next_Formal_With_Extras (Formal);
4288 -- Finally, create block and analyze it
4291 Make_Block_Statement (Loc,
4292 Declarations => Decls,
4293 Handled_Statement_Sequence =>
4294 Make_Handled_Sequence_Of_Statements (Loc,
4295 Statements => Stats)));
4299 end Build_Simple_Entry_Call;
4301 --------------------------------
4302 -- Build_Task_Activation_Call --
4303 --------------------------------
4305 procedure Build_Task_Activation_Call (N : Node_Id) is
4306 Loc : constant Source_Ptr := Sloc (N);
4313 -- Get the activation chain entity. Except in the case of a package
4314 -- body, this is in the node that was passed. For a package body, we
4315 -- have to find the corresponding package declaration node.
4317 if Nkind (N) = N_Package_Body then
4318 P := Corresponding_Spec (N);
4321 exit when Nkind (P) = N_Package_Declaration;
4324 Chain := Activation_Chain_Entity (P);
4327 Chain := Activation_Chain_Entity (N);
4330 if Present (Chain) then
4331 if Restricted_Profile then
4332 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
4334 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4338 Make_Procedure_Call_Statement (Loc,
4340 Parameter_Associations =>
4341 New_List (Make_Attribute_Reference (Loc,
4342 Prefix => New_Occurrence_Of (Chain, Loc),
4343 Attribute_Name => Name_Unchecked_Access)));
4345 if Nkind (N) = N_Package_Declaration then
4346 if Present (Corresponding_Body (N)) then
4349 elsif Present (Private_Declarations (Specification (N))) then
4350 Append (Call, Private_Declarations (Specification (N)));
4353 Append (Call, Visible_Declarations (Specification (N)));
4357 if Present (Handled_Statement_Sequence (N)) then
4359 -- The call goes at the start of the statement sequence
4360 -- after the start of exception range label if one is present.
4366 Stm := First (Statements (Handled_Statement_Sequence (N)));
4368 -- A special case, skip exception range label if one is
4369 -- present (from front end zcx processing).
4371 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4375 -- Another special case, if the first statement is a block
4376 -- from optimization of a local raise to a goto, then the
4377 -- call goes inside this block.
4379 if Nkind (Stm) = N_Block_Statement
4380 and then Exception_Junk (Stm)
4383 First (Statements (Handled_Statement_Sequence (Stm)));
4386 -- Insertion point is after any exception label pushes,
4387 -- since we want it covered by any local handlers.
4389 while Nkind (Stm) in N_Push_xxx_Label loop
4393 -- Now we have the proper insertion point
4395 Insert_Before (Stm, Call);
4399 Set_Handled_Statement_Sequence (N,
4400 Make_Handled_Sequence_Of_Statements (Loc,
4401 Statements => New_List (Call)));
4406 Check_Task_Activation (N);
4408 end Build_Task_Activation_Call;
4410 -------------------------------
4411 -- Build_Task_Allocate_Block --
4412 -------------------------------
4414 procedure Build_Task_Allocate_Block
4419 T : constant Entity_Id := Entity (Expression (N));
4420 Init : constant Entity_Id := Base_Init_Proc (T);
4421 Loc : constant Source_Ptr := Sloc (N);
4422 Chain : constant Entity_Id :=
4423 Make_Defining_Identifier (Loc, Name_uChain);
4424 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4429 Make_Block_Statement (Loc,
4430 Identifier => New_Reference_To (Blkent, Loc),
4431 Declarations => New_List (
4433 -- _Chain : Activation_Chain;
4435 Make_Object_Declaration (Loc,
4436 Defining_Identifier => Chain,
4437 Aliased_Present => True,
4438 Object_Definition =>
4439 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4441 Handled_Statement_Sequence =>
4442 Make_Handled_Sequence_Of_Statements (Loc,
4444 Statements => New_List (
4448 Make_Procedure_Call_Statement (Loc,
4449 Name => New_Reference_To (Init, Loc),
4450 Parameter_Associations => Args),
4452 -- Activate_Tasks (_Chain);
4454 Make_Procedure_Call_Statement (Loc,
4455 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4456 Parameter_Associations => New_List (
4457 Make_Attribute_Reference (Loc,
4458 Prefix => New_Reference_To (Chain, Loc),
4459 Attribute_Name => Name_Unchecked_Access))))),
4461 Has_Created_Identifier => True,
4462 Is_Task_Allocation_Block => True);
4465 Make_Implicit_Label_Declaration (Loc,
4466 Defining_Identifier => Blkent,
4467 Label_Construct => Block));
4469 Append_To (Actions, Block);
4471 Set_Activation_Chain_Entity (Block, Chain);
4472 end Build_Task_Allocate_Block;
4474 -----------------------------------------------
4475 -- Build_Task_Allocate_Block_With_Init_Stmts --
4476 -----------------------------------------------
4478 procedure Build_Task_Allocate_Block_With_Init_Stmts
4481 Init_Stmts : List_Id)
4483 Loc : constant Source_Ptr := Sloc (N);
4484 Chain : constant Entity_Id :=
4485 Make_Defining_Identifier (Loc, Name_uChain);
4486 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4490 Append_To (Init_Stmts,
4491 Make_Procedure_Call_Statement (Loc,
4492 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4493 Parameter_Associations => New_List (
4494 Make_Attribute_Reference (Loc,
4495 Prefix => New_Reference_To (Chain, Loc),
4496 Attribute_Name => Name_Unchecked_Access))));
4499 Make_Block_Statement (Loc,
4500 Identifier => New_Reference_To (Blkent, Loc),
4501 Declarations => New_List (
4503 -- _Chain : Activation_Chain;
4505 Make_Object_Declaration (Loc,
4506 Defining_Identifier => Chain,
4507 Aliased_Present => True,
4508 Object_Definition =>
4509 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4511 Handled_Statement_Sequence =>
4512 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4514 Has_Created_Identifier => True,
4515 Is_Task_Allocation_Block => True);
4518 Make_Implicit_Label_Declaration (Loc,
4519 Defining_Identifier => Blkent,
4520 Label_Construct => Block));
4522 Append_To (Actions, Block);
4524 Set_Activation_Chain_Entity (Block, Chain);
4525 end Build_Task_Allocate_Block_With_Init_Stmts;
4527 -----------------------------------
4528 -- Build_Task_Proc_Specification --
4529 -----------------------------------
4531 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4532 Loc : constant Source_Ptr := Sloc (T);
4533 Spec_Id : Entity_Id;
4536 -- Case of explicit task type, suffix TB
4538 if Comes_From_Source (T) then
4540 Make_Defining_Identifier (Loc,
4541 Chars => New_External_Name (Chars (T), "TB"));
4543 -- Case of anonymous task type, suffix B
4547 Make_Defining_Identifier (Loc,
4548 Chars => New_External_Name (Chars (T), 'B'));
4551 Set_Is_Internal (Spec_Id);
4553 -- Associate the procedure with the task, if this is the declaration
4554 -- (and not the body) of the procedure.
4556 if No (Task_Body_Procedure (T)) then
4557 Set_Task_Body_Procedure (T, Spec_Id);
4561 Make_Procedure_Specification (Loc,
4562 Defining_Unit_Name => Spec_Id,
4563 Parameter_Specifications => New_List (
4564 Make_Parameter_Specification (Loc,
4565 Defining_Identifier =>
4566 Make_Defining_Identifier (Loc, Name_uTask),
4568 Make_Access_Definition (Loc,
4570 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4571 end Build_Task_Proc_Specification;
4573 ---------------------------------------
4574 -- Build_Unprotected_Subprogram_Body --
4575 ---------------------------------------
4577 function Build_Unprotected_Subprogram_Body
4579 Pid : Node_Id) return Node_Id
4581 Decls : constant List_Id := Declarations (N);
4584 -- Add renamings for the Protection object, discriminals, privals and
4585 -- the entry index constant for use by debugger.
4587 Debug_Private_Data_Declarations (Decls);
4589 -- Make an unprotected version of the subprogram for use within the same
4590 -- object, with a new name and an additional parameter representing the
4594 Make_Subprogram_Body (Sloc (N),
4596 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4597 Declarations => Decls,
4598 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4599 end Build_Unprotected_Subprogram_Body;
4601 ----------------------------
4602 -- Collect_Entry_Families --
4603 ----------------------------
4605 procedure Collect_Entry_Families
4608 Current_Node : in out Node_Id;
4609 Conctyp : Entity_Id)
4612 Efam_Decl : Node_Id;
4613 Efam_Type : Entity_Id;
4616 Efam := First_Entity (Conctyp);
4617 while Present (Efam) loop
4618 if Ekind (Efam) = E_Entry_Family then
4619 Efam_Type := Make_Temporary (Loc, 'F');
4624 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4626 Bas_Decl : Node_Id := Empty;
4631 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4633 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4634 Bas := Make_Temporary (Loc, 'B');
4637 Make_Subtype_Declaration (Loc,
4638 Defining_Identifier => Bas,
4639 Subtype_Indication =>
4640 Make_Subtype_Indication (Loc,
4642 New_Occurrence_Of (Standard_Integer, Loc),
4644 Make_Range_Constraint (Loc,
4645 Range_Expression => Make_Range (Loc,
4646 Make_Integer_Literal
4647 (Loc, -Entry_Family_Bound),
4648 Make_Integer_Literal
4649 (Loc, Entry_Family_Bound - 1)))));
4651 Insert_After (Current_Node, Bas_Decl);
4652 Current_Node := Bas_Decl;
4657 Make_Full_Type_Declaration (Loc,
4658 Defining_Identifier => Efam_Type,
4660 Make_Unconstrained_Array_Definition (Loc,
4662 (New_List (New_Occurrence_Of (Bas, Loc))),
4664 Component_Definition =>
4665 Make_Component_Definition (Loc,
4666 Aliased_Present => False,
4667 Subtype_Indication =>
4668 New_Reference_To (Standard_Character, Loc))));
4671 Insert_After (Current_Node, Efam_Decl);
4672 Current_Node := Efam_Decl;
4673 Analyze (Efam_Decl);
4676 Make_Component_Declaration (Loc,
4677 Defining_Identifier =>
4678 Make_Defining_Identifier (Loc, Chars (Efam)),
4680 Component_Definition =>
4681 Make_Component_Definition (Loc,
4682 Aliased_Present => False,
4683 Subtype_Indication =>
4684 Make_Subtype_Indication (Loc,
4686 New_Occurrence_Of (Efam_Type, Loc),
4689 Make_Index_Or_Discriminant_Constraint (Loc,
4690 Constraints => New_List (
4692 (Etype (Discrete_Subtype_Definition
4693 (Parent (Efam))), Loc)))))));
4699 end Collect_Entry_Families;
4701 -----------------------
4702 -- Concurrent_Object --
4703 -----------------------
4705 function Concurrent_Object
4706 (Spec_Id : Entity_Id;
4707 Conc_Typ : Entity_Id) return Entity_Id
4710 -- Parameter _O or _object
4712 if Is_Protected_Type (Conc_Typ) then
4713 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4718 pragma Assert (Is_Task_Type (Conc_Typ));
4719 return First_Formal (Task_Body_Procedure (Conc_Typ));
4721 end Concurrent_Object;
4723 ----------------------
4724 -- Copy_Result_Type --
4725 ----------------------
4727 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4728 New_Res : constant Node_Id := New_Copy_Tree (Res);
4733 -- If the result type is an access_to_subprogram, we must create
4734 -- new entities for its spec.
4736 if Nkind (New_Res) = N_Access_Definition
4737 and then Present (Access_To_Subprogram_Definition (New_Res))
4739 -- Provide new entities for the formals
4741 Par_Spec := First (Parameter_Specifications
4742 (Access_To_Subprogram_Definition (New_Res)));
4743 while Present (Par_Spec) loop
4744 Formal := Defining_Identifier (Par_Spec);
4745 Set_Defining_Identifier (Par_Spec,
4746 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4752 end Copy_Result_Type;
4754 --------------------
4755 -- Concurrent_Ref --
4756 --------------------
4758 -- The expression returned for a reference to a concurrent object has the
4761 -- taskV!(name)._Task_Id
4765 -- objectV!(name)._Object
4767 -- for a protected object. For the case of an access to a concurrent
4768 -- object, there is an extra explicit dereference:
4770 -- taskV!(name.all)._Task_Id
4771 -- objectV!(name.all)._Object
4773 -- here taskV and objectV are the types for the associated records, which
4774 -- contain the required _Task_Id and _Object fields for tasks and protected
4775 -- objects, respectively.
4777 -- For the case of a task type name, the expression is
4781 -- i.e. a call to the Self function which returns precisely this Task_Id
4783 -- For the case of a protected type name, the expression is
4787 -- which is a renaming of the _object field of the current object
4788 -- record, passed into protected operations as a parameter.
4790 function Concurrent_Ref (N : Node_Id) return Node_Id is
4791 Loc : constant Source_Ptr := Sloc (N);
4792 Ntyp : constant Entity_Id := Etype (N);
4796 function Is_Current_Task (T : Entity_Id) return Boolean;
4797 -- Check whether the reference is to the immediately enclosing task
4798 -- type, or to an outer one (rare but legal).
4800 ---------------------
4801 -- Is_Current_Task --
4802 ---------------------
4804 function Is_Current_Task (T : Entity_Id) return Boolean is
4808 Scop := Current_Scope;
4809 while Present (Scop)
4810 and then Scop /= Standard_Standard
4816 elsif Is_Task_Type (Scop) then
4819 -- If this is a procedure nested within the task type, we must
4820 -- assume that it can be called from an inner task, and therefore
4821 -- cannot treat it as a local reference.
4823 elsif Is_Overloadable (Scop)
4824 and then In_Open_Scopes (T)
4829 Scop := Scope (Scop);
4833 -- We know that we are within the task body, so should have found it
4836 raise Program_Error;
4837 end Is_Current_Task;
4839 -- Start of processing for Concurrent_Ref
4842 if Is_Access_Type (Ntyp) then
4843 Dtyp := Designated_Type (Ntyp);
4845 if Is_Protected_Type (Dtyp) then
4846 Sel := Name_uObject;
4848 Sel := Name_uTask_Id;
4852 Make_Selected_Component (Loc,
4854 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4855 Make_Explicit_Dereference (Loc, N)),
4856 Selector_Name => Make_Identifier (Loc, Sel));
4858 elsif Is_Entity_Name (N)
4859 and then Is_Concurrent_Type (Entity (N))
4861 if Is_Task_Type (Entity (N)) then
4863 if Is_Current_Task (Entity (N)) then
4865 Make_Function_Call (Loc,
4866 Name => New_Reference_To (RTE (RE_Self), Loc));
4871 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4872 T_Body : constant Node_Id :=
4873 Parent (Corresponding_Body (Parent (Entity (N))));
4877 Make_Object_Declaration (Loc,
4878 Defining_Identifier => T_Self,
4879 Object_Definition =>
4880 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4882 Make_Function_Call (Loc,
4883 Name => New_Reference_To (RTE (RE_Self), Loc)));
4884 Prepend (Decl, Declarations (T_Body));
4886 Set_Scope (T_Self, Entity (N));
4887 return New_Occurrence_Of (T_Self, Loc);
4892 pragma Assert (Is_Protected_Type (Entity (N)));
4895 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4899 if Is_Protected_Type (Ntyp) then
4900 Sel := Name_uObject;
4902 elsif Is_Task_Type (Ntyp) then
4903 Sel := Name_uTask_Id;
4906 raise Program_Error;
4910 Make_Selected_Component (Loc,
4912 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4914 Selector_Name => Make_Identifier (Loc, Sel));
4918 ------------------------
4919 -- Convert_Concurrent --
4920 ------------------------
4922 function Convert_Concurrent
4924 Typ : Entity_Id) return Node_Id
4927 if not Is_Concurrent_Type (Typ) then
4931 Unchecked_Convert_To
4932 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4934 end Convert_Concurrent;
4936 -------------------------------------
4937 -- Debug_Private_Data_Declarations --
4938 -------------------------------------
4940 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4941 Debug_Nod : Node_Id;
4945 Decl := First (Decls);
4946 while Present (Decl)
4947 and then not Comes_From_Source (Decl)
4949 -- Declaration for concurrent entity _object and its access type,
4950 -- along with the entry index subtype:
4951 -- type prot_typVP is access prot_typV;
4952 -- _object : prot_typVP := prot_typV (_O);
4953 -- subtype Jnn is <Type of Index> range Low .. High;
4955 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4956 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4958 -- Declaration for the Protection object, discriminals, privals and
4959 -- entry index constant:
4960 -- conc_typR : protection_typ renames _object._object;
4961 -- discr_nameD : discr_typ renames _object.discr_name;
4962 -- discr_nameD : discr_typ renames _task.discr_name;
4963 -- prival_name : comp_typ renames _object.comp_name;
4964 -- J : constant Jnn :=
4965 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4967 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4968 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4969 Debug_Nod := Debug_Renaming_Declaration (Decl);
4971 if Present (Debug_Nod) then
4972 Insert_After (Decl, Debug_Nod);
4978 end Debug_Private_Data_Declarations;
4980 ----------------------------
4981 -- Entry_Index_Expression --
4982 ----------------------------
4984 function Entry_Index_Expression
4988 Ttyp : Entity_Id) return Node_Id
4998 -- The queues of entries and entry families appear in textual order in
4999 -- the associated record. The entry index is computed as the sum of the
5000 -- number of queues for all entries that precede the designated one, to
5001 -- which is added the index expression, if this expression denotes a
5002 -- member of a family.
5004 -- The following is a place holder for the count of simple entries
5006 Num := Make_Integer_Literal (Sloc, 1);
5008 -- We construct an expression which is a series of addition operations.
5009 -- The first operand is the number of single entries that precede this
5010 -- one, the second operand is the index value relative to the start of
5011 -- the referenced family, and the remaining operands are the lengths of
5012 -- the entry families that precede this entry, i.e. the constructed
5015 -- number_simple_entries +
5016 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5017 -- family'length + ...
5019 -- where index-value is the given index value, and s is the index
5020 -- subtype (we have to use pos because the subtype might be an
5021 -- enumeration type preventing direct subtraction). Note that the task
5022 -- entry array is one-indexed.
5024 -- The upper bound of the entry family may be a discriminant, so we
5025 -- retrieve the lower bound explicitly to compute offset, rather than
5026 -- using the index subtype which may mention a discriminant.
5028 if Present (Index) then
5029 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
5038 Make_Attribute_Reference (Sloc,
5039 Attribute_Name => Name_Pos,
5040 Prefix => New_Reference_To (Base_Type (S), Sloc),
5041 Expressions => New_List (Relocate_Node (Index))),
5049 -- Now add lengths of preceding entries and entry families
5051 Prev := First_Entity (Ttyp);
5053 while Chars (Prev) /= Chars (Ent)
5054 or else (Ekind (Prev) /= Ekind (Ent))
5055 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
5057 if Ekind (Prev) = E_Entry then
5058 Set_Intval (Num, Intval (Num) + 1);
5060 elsif Ekind (Prev) = E_Entry_Family then
5062 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
5063 Lo := Type_Low_Bound (S);
5064 Hi := Type_High_Bound (S);
5069 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
5071 -- Other components are anonymous types to be ignored
5081 end Entry_Index_Expression;
5083 ---------------------------
5084 -- Establish_Task_Master --
5085 ---------------------------
5087 procedure Establish_Task_Master (N : Node_Id) is
5091 if Restriction_Active (No_Task_Hierarchy) = False then
5092 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
5094 -- The block may have no declarations, and nevertheless be a task
5095 -- master, if it contains a call that may return an object that
5098 if No (Declarations (N)) then
5099 Set_Declarations (N, New_List (Call));
5101 Prepend_To (Declarations (N), Call);
5106 end Establish_Task_Master;
5108 --------------------------------
5109 -- Expand_Accept_Declarations --
5110 --------------------------------
5112 -- Part of the expansion of an accept statement involves the creation of
5113 -- a declaration that can be referenced from the statement sequence of
5118 -- This declaration is inserted immediately before the accept statement
5119 -- and it is important that it be inserted before the statements of the
5120 -- statement sequence are analyzed. Thus it would be too late to create
5121 -- this declaration in the Expand_N_Accept_Statement routine, which is
5122 -- why there is a separate procedure to be called directly from Sem_Ch9.
5124 -- Ann is used to hold the address of the record containing the parameters
5125 -- (see Expand_N_Entry_Call for more details on how this record is built).
5126 -- References to the parameters do an unchecked conversion of this address
5127 -- to a pointer to the required record type, and then access the field that
5128 -- holds the value of the required parameter. The entity for the address
5129 -- variable is held as the top stack element (i.e. the last element) of the
5130 -- Accept_Address stack in the corresponding entry entity, and this element
5131 -- must be set in place before the statements are processed.
5133 -- The above description applies to the case of a stand alone accept
5134 -- statement, i.e. one not appearing as part of a select alternative.
5136 -- For the case of an accept that appears as part of a select alternative
5137 -- of a selective accept, we must still create the declaration right away,
5138 -- since Ann is needed immediately, but there is an important difference:
5140 -- The declaration is inserted before the selective accept, not before
5141 -- the accept statement (which is not part of a list anyway, and so would
5142 -- not accommodate inserted declarations)
5144 -- We only need one address variable for the entire selective accept. So
5145 -- the Ann declaration is created only for the first accept alternative,
5146 -- and subsequent accept alternatives reference the same Ann variable.
5148 -- We can distinguish the two cases by seeing whether the accept statement
5149 -- is part of a list. If not, then it must be in an accept alternative.
5151 -- To expand the requeue statement, a label is provided at the end of the
5152 -- accept statement or alternative of which it is a part, so that the
5153 -- statement can be skipped after the requeue is complete. This label is
5154 -- created here rather than during the expansion of the accept statement,
5155 -- because it will be needed by any requeue statements within the accept,
5156 -- which are expanded before the accept.
5158 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
5159 Loc : constant Source_Ptr := Sloc (N);
5160 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5161 Ann : Entity_Id := Empty;
5169 if Full_Expander_Active then
5171 -- If we have no handled statement sequence, we may need to build
5172 -- a dummy sequence consisting of a null statement. This can be
5173 -- skipped if the trivial accept optimization is permitted.
5175 if not Trivial_Accept_OK
5177 (No (Stats) or else Null_Statements (Statements (Stats)))
5179 Set_Handled_Statement_Sequence (N,
5180 Make_Handled_Sequence_Of_Statements (Loc,
5181 Statements => New_List (Make_Null_Statement (Loc))));
5184 -- Create and declare two labels to be placed at the end of the
5185 -- accept statement. The first label is used to allow requeues to
5186 -- skip the remainder of entry processing. The second label is used
5187 -- to skip the remainder of entry processing if the rendezvous
5188 -- completes in the middle of the accept body.
5190 if Present (Handled_Statement_Sequence (N)) then
5195 Ent := Make_Temporary (Loc, 'L');
5196 Lab_Id := New_Reference_To (Ent, Loc);
5197 Lab := Make_Label (Loc, Lab_Id);
5199 Make_Implicit_Label_Declaration (Loc,
5200 Defining_Identifier => Ent,
5201 Label_Construct => Lab);
5202 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5204 Ent := Make_Temporary (Loc, 'L');
5205 Lab_Id := New_Reference_To (Ent, Loc);
5206 Lab := Make_Label (Loc, Lab_Id);
5208 Make_Implicit_Label_Declaration (Loc,
5209 Defining_Identifier => Ent,
5210 Label_Construct => Lab);
5211 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5219 -- Case of stand alone accept statement
5221 if Is_List_Member (N) then
5223 if Present (Handled_Statement_Sequence (N)) then
5224 Ann := Make_Temporary (Loc, 'A');
5227 Make_Object_Declaration (Loc,
5228 Defining_Identifier => Ann,
5229 Object_Definition =>
5230 New_Reference_To (RTE (RE_Address), Loc));
5232 Insert_Before (N, Adecl);
5235 Insert_Before (N, Ldecl);
5238 Insert_Before (N, Ldecl2);
5242 -- Case of accept statement which is in an accept alternative
5246 Acc_Alt : constant Node_Id := Parent (N);
5247 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
5251 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
5252 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
5254 -- ??? Consider a single label for select statements
5256 if Present (Handled_Statement_Sequence (N)) then
5258 Statements (Handled_Statement_Sequence (N)));
5262 Statements (Handled_Statement_Sequence (N)));
5266 -- Find first accept alternative of the selective accept. A
5267 -- valid selective accept must have at least one accept in it.
5269 Alt := First (Select_Alternatives (Sel_Acc));
5271 while Nkind (Alt) /= N_Accept_Alternative loop
5275 -- If we are the first accept statement, then we have to create
5276 -- the Ann variable, as for the stand alone case, except that
5277 -- it is inserted before the selective accept. Similarly, a
5278 -- label for requeue expansion must be declared.
5280 if N = Accept_Statement (Alt) then
5281 Ann := Make_Temporary (Loc, 'A');
5283 Make_Object_Declaration (Loc,
5284 Defining_Identifier => Ann,
5285 Object_Definition =>
5286 New_Reference_To (RTE (RE_Address), Loc));
5288 Insert_Before (Sel_Acc, Adecl);
5291 -- If we are not the first accept statement, then find the Ann
5292 -- variable allocated by the first accept and use it.
5296 Node (Last_Elmt (Accept_Address
5297 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
5302 -- Merge here with Ann either created or referenced, and Adecl
5303 -- pointing to the corresponding declaration. Remaining processing
5304 -- is the same for the two cases.
5306 if Present (Ann) then
5307 Append_Elmt (Ann, Accept_Address (Ent));
5308 Set_Debug_Info_Needed (Ann);
5311 -- Create renaming declarations for the entry formals. Each reference
5312 -- to a formal becomes a dereference of a component of the parameter
5313 -- block, whose address is held in Ann. These declarations are
5314 -- eventually inserted into the accept block, and analyzed there so
5315 -- that they have the proper scope for gdb and do not conflict with
5316 -- other declarations.
5318 if Present (Parameter_Specifications (N))
5319 and then Present (Handled_Statement_Sequence (N))
5326 Renamed_Formal : Node_Id;
5330 Formal := First_Formal (Ent);
5332 while Present (Formal) loop
5333 Comp := Entry_Component (Formal);
5335 Make_Defining_Identifier (Loc, Chars (Formal));
5337 Set_Etype (New_F, Etype (Formal));
5338 Set_Scope (New_F, Ent);
5340 -- Now we set debug info needed on New_F even though it does
5341 -- not come from source, so that the debugger will get the
5342 -- right information for these generated names.
5344 Set_Debug_Info_Needed (New_F);
5346 if Ekind (Formal) = E_In_Parameter then
5347 Set_Ekind (New_F, E_Constant);
5349 Set_Ekind (New_F, E_Variable);
5350 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5353 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5356 Make_Selected_Component (Loc,
5358 Unchecked_Convert_To (
5359 Entry_Parameters_Type (Ent),
5360 New_Reference_To (Ann, Loc)),
5362 New_Reference_To (Comp, Loc));
5365 Build_Renamed_Formal_Declaration
5366 (New_F, Formal, Comp, Renamed_Formal);
5368 if No (Declarations (N)) then
5369 Set_Declarations (N, New_List);
5372 Append (Decl, Declarations (N));
5373 Set_Renamed_Object (Formal, New_F);
5374 Next_Formal (Formal);
5381 end Expand_Accept_Declarations;
5383 ---------------------------------------------
5384 -- Expand_Access_Protected_Subprogram_Type --
5385 ---------------------------------------------
5387 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5388 Loc : constant Source_Ptr := Sloc (N);
5390 T : constant Entity_Id := Defining_Identifier (N);
5391 D_T : constant Entity_Id := Designated_Type (T);
5392 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5393 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5394 P_List : constant List_Id := Build_Protected_Spec
5395 (N, RTE (RE_Address), D_T, False);
5401 -- Create access to subprogram with full signature
5403 if Etype (D_T) /= Standard_Void_Type then
5405 Make_Access_Function_Definition (Loc,
5406 Parameter_Specifications => P_List,
5407 Result_Definition =>
5408 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5412 Make_Access_Procedure_Definition (Loc,
5413 Parameter_Specifications => P_List);
5417 Make_Full_Type_Declaration (Loc,
5418 Defining_Identifier => D_T2,
5419 Type_Definition => Def1);
5421 Insert_After (N, Decl1);
5424 -- Associate the access to subprogram with its original access to
5425 -- protected subprogram type. Needed by the backend to know that this
5426 -- type corresponds with an access to protected subprogram type.
5428 Set_Original_Access_Type (D_T2, T);
5430 -- Create Equivalent_Type, a record with two components for an access to
5431 -- object and an access to subprogram.
5434 Make_Component_Declaration (Loc,
5435 Defining_Identifier => Make_Temporary (Loc, 'P'),
5436 Component_Definition =>
5437 Make_Component_Definition (Loc,
5438 Aliased_Present => False,
5439 Subtype_Indication =>
5440 New_Occurrence_Of (RTE (RE_Address), Loc))),
5442 Make_Component_Declaration (Loc,
5443 Defining_Identifier => Make_Temporary (Loc, 'S'),
5444 Component_Definition =>
5445 Make_Component_Definition (Loc,
5446 Aliased_Present => False,
5447 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5450 Make_Full_Type_Declaration (Loc,
5451 Defining_Identifier => E_T,
5453 Make_Record_Definition (Loc,
5455 Make_Component_List (Loc, Component_Items => Comps)));
5457 Insert_After (Decl1, Decl2);
5459 Set_Equivalent_Type (T, E_T);
5460 end Expand_Access_Protected_Subprogram_Type;
5462 --------------------------
5463 -- Expand_Entry_Barrier --
5464 --------------------------
5466 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5467 Cond : constant Node_Id :=
5468 Condition (Entry_Body_Formal_Part (N));
5469 Prot : constant Entity_Id := Scope (Ent);
5470 Spec_Decl : constant Node_Id := Parent (Prot);
5473 Body_Decl : Node_Id;
5476 if No_Run_Time_Mode then
5477 Error_Msg_CRT ("entry barrier", N);
5481 -- The body of the entry barrier must be analyzed in the context of the
5482 -- protected object, but its scope is external to it, just as any other
5483 -- unprotected version of a protected operation. The specification has
5484 -- been produced when the protected type declaration was elaborated. We
5485 -- build the body, insert it in the enclosing scope, but analyze it in
5486 -- the current context. A more uniform approach would be to treat the
5487 -- barrier just as a protected function, and discard the protected
5488 -- version of it because it is never called.
5490 if Full_Expander_Active then
5491 B_F := Build_Barrier_Function (N, Ent, Prot);
5492 Func := Barrier_Function (Ent);
5493 Set_Corresponding_Spec (B_F, Func);
5495 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5497 if Nkind (Parent (Body_Decl)) = N_Subunit then
5498 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5501 Insert_Before_And_Analyze (Body_Decl, B_F);
5503 Set_Discriminals (Spec_Decl);
5504 Set_Scope (Func, Scope (Prot));
5507 Analyze_And_Resolve (Cond, Any_Boolean);
5510 -- The Ravenscar profile restricts barriers to simple variables declared
5511 -- within the protected object. We also allow Boolean constants, since
5512 -- these appear in several published examples and are also allowed by
5513 -- the Aonix compiler.
5515 -- Note that after analysis variables in this context will be replaced
5516 -- by the corresponding prival, that is to say a renaming of a selected
5517 -- component of the form _Object.Var. If expansion is disabled, as
5518 -- within a generic, we check that the entity appears in the current
5521 if Is_Entity_Name (Cond) then
5523 -- A small optimization of useless renamings. If the scope of the
5524 -- entity of the condition is not the barrier function, then the
5525 -- condition does not reference any of the generated renamings
5526 -- within the function.
5528 if Full_Expander_Active
5529 and then Scope (Entity (Cond)) /= Func
5531 Set_Declarations (B_F, Empty_List);
5534 if Entity (Cond) = Standard_False
5536 Entity (Cond) = Standard_True
5540 elsif not Expander_Active
5541 and then Scope (Entity (Cond)) = Current_Scope
5545 -- Check for case of _object.all.field (note that the explicit
5546 -- dereference gets inserted by analyze/expand of _object.field)
5548 elsif Present (Renamed_Object (Entity (Cond)))
5550 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5554 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5560 -- It is not a boolean variable or literal, so check the restriction
5562 Check_Restriction (Simple_Barriers, Cond);
5563 end Expand_Entry_Barrier;
5565 ------------------------------
5566 -- Expand_N_Abort_Statement --
5567 ------------------------------
5569 -- Expand abort T1, T2, .. Tn; into:
5570 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5572 procedure Expand_N_Abort_Statement (N : Node_Id) is
5573 Loc : constant Source_Ptr := Sloc (N);
5574 Tlist : constant List_Id := Names (N);
5580 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5583 Tasknm := First (Tlist);
5585 while Present (Tasknm) loop
5588 -- A task interface class-wide type object is being aborted.
5589 -- Retrieve its _task_id by calling a dispatching routine.
5591 if Ada_Version >= Ada_2005
5592 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5593 and then Is_Interface (Etype (Tasknm))
5594 and then Is_Task_Interface (Etype (Tasknm))
5596 Append_To (Component_Associations (Aggr),
5597 Make_Component_Association (Loc,
5598 Choices => New_List (
5599 Make_Integer_Literal (Loc, Count)),
5602 -- Task_Id (Tasknm._disp_get_task_id)
5604 Make_Unchecked_Type_Conversion (Loc,
5606 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5608 Make_Selected_Component (Loc,
5609 Prefix => New_Copy_Tree (Tasknm),
5611 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5614 Append_To (Component_Associations (Aggr),
5615 Make_Component_Association (Loc,
5616 Choices => New_List (
5617 Make_Integer_Literal (Loc, Count)),
5618 Expression => Concurrent_Ref (Tasknm)));
5625 Make_Procedure_Call_Statement (Loc,
5626 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5627 Parameter_Associations => New_List (
5628 Make_Qualified_Expression (Loc,
5629 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5630 Expression => Aggr))));
5633 end Expand_N_Abort_Statement;
5635 -------------------------------
5636 -- Expand_N_Accept_Statement --
5637 -------------------------------
5639 -- This procedure handles expansion of accept statements that stand
5640 -- alone, i.e. they are not part of an accept alternative. The expansion
5641 -- of accept statement in accept alternatives is handled by the routines
5642 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5643 -- following description applies only to stand alone accept statements.
5645 -- If there is no handled statement sequence, or only null statements,
5646 -- then this is called a trivial accept, and the expansion is:
5648 -- Accept_Trivial (entry-index)
5650 -- If there is a handled statement sequence, then the expansion is:
5657 -- Accept_Call (entry-index, Ann);
5658 -- Renaming_Declarations for formals
5659 -- <statement sequence from N_Accept_Statement node>
5660 -- Complete_Rendezvous;
5665 -- <exception handler from N_Accept_Statement node>
5666 -- Complete_Rendezvous;
5668 -- <exception handler from N_Accept_Statement node>
5669 -- Complete_Rendezvous;
5674 -- when all others =>
5675 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5678 -- The first three declarations were already inserted ahead of the accept
5679 -- statement by the Expand_Accept_Declarations procedure, which was called
5680 -- directly from the semantics during analysis of the accept statement,
5681 -- before analyzing its contained statements.
5683 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5684 -- from possible expansion activity (the original source of course does
5685 -- not have any declarations associated with the accept statement, since
5686 -- an accept statement has no declarative part). In particular, if the
5687 -- expander is active, the first such declaration is the declaration of
5688 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5690 -- The two blocks are merged into a single block if the inner block has
5691 -- no exception handlers, but otherwise two blocks are required, since
5692 -- exceptions might be raised in the exception handlers of the inner
5693 -- block, and Exceptional_Complete_Rendezvous must be called.
5695 procedure Expand_N_Accept_Statement (N : Node_Id) is
5696 Loc : constant Source_Ptr := Sloc (N);
5697 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5698 Ename : constant Node_Id := Entry_Direct_Name (N);
5699 Eindx : constant Node_Id := Entry_Index (N);
5700 Eent : constant Entity_Id := Entity (Ename);
5701 Acstack : constant Elist_Id := Accept_Address (Eent);
5702 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5703 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5708 -- Start of processing for Expand_N_Accept_Statement
5711 -- If accept statement is not part of a list, then its parent must be
5712 -- an accept alternative, and, as described above, we do not do any
5713 -- expansion for such accept statements at this level.
5715 if not Is_List_Member (N) then
5716 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5719 -- Trivial accept case (no statement sequence, or null statements).
5720 -- If the accept statement has declarations, then just insert them
5721 -- before the procedure call.
5723 elsif Trivial_Accept_OK
5724 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5726 -- Remove declarations for renamings, because the parameter block
5727 -- will not be assigned.
5734 D := First (Declarations (N));
5736 while Present (D) loop
5738 if Nkind (D) = N_Object_Renaming_Declaration then
5746 if Present (Declarations (N)) then
5747 Insert_Actions (N, Declarations (N));
5751 Make_Procedure_Call_Statement (Loc,
5752 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5753 Parameter_Associations => New_List (
5754 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5758 -- Discard Entry_Address that was created for it, so it will not be
5759 -- emitted if this accept statement is in the statement part of a
5760 -- delay alternative.
5762 if Present (Stats) then
5763 Remove_Last_Elmt (Acstack);
5766 -- Case of statement sequence present
5769 -- Construct the block, using the declarations from the accept
5770 -- statement if any to initialize the declarations of the block.
5772 Blkent := Make_Temporary (Loc, 'A');
5773 Set_Ekind (Blkent, E_Block);
5774 Set_Etype (Blkent, Standard_Void_Type);
5775 Set_Scope (Blkent, Current_Scope);
5778 Make_Block_Statement (Loc,
5779 Identifier => New_Reference_To (Blkent, Loc),
5780 Declarations => Declarations (N),
5781 Handled_Statement_Sequence => Build_Accept_Body (N));
5783 -- For the analysis of the generated declarations, the parent node
5784 -- must be properly set.
5786 Set_Parent (Block, Parent (N));
5788 -- Prepend call to Accept_Call to main statement sequence If the
5789 -- accept has exception handlers, the statement sequence is wrapped
5790 -- in a block. Insert call and renaming declarations in the
5791 -- declarations of the block, so they are elaborated before the
5795 Make_Procedure_Call_Statement (Loc,
5796 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5797 Parameter_Associations => New_List (
5798 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5799 New_Reference_To (Ann, Loc)));
5801 if Parent (Stats) = N then
5802 Prepend (Call, Statements (Stats));
5811 Push_Scope (Blkent);
5819 D := First (Declarations (N));
5820 while Present (D) loop
5823 if Nkind (D) = N_Object_Renaming_Declaration then
5825 -- The renaming declarations for the formals were created
5826 -- during analysis of the accept statement, and attached to
5827 -- the list of declarations. Place them now in the context
5828 -- of the accept block or subprogram.
5831 Typ := Entity (Subtype_Mark (D));
5832 Insert_After (Call, D);
5835 -- If the formal is class_wide, it does not have an actual
5836 -- subtype. The analysis of the renaming declaration creates
5837 -- one, but we need to retain the class-wide nature of the
5840 if Is_Class_Wide_Type (Typ) then
5841 Set_Etype (Defining_Identifier (D), Typ);
5852 -- Replace the accept statement by the new block
5857 -- Last step is to unstack the Accept_Address value
5859 Remove_Last_Elmt (Acstack);
5861 end Expand_N_Accept_Statement;
5863 ----------------------------------
5864 -- Expand_N_Asynchronous_Select --
5865 ----------------------------------
5867 -- This procedure assumes that the trigger statement is an entry call or
5868 -- a dispatching procedure call. A delay alternative should already have
5869 -- been expanded into an entry call to the appropriate delay object Wait
5872 -- If the trigger is a task entry call, the select is implemented with
5873 -- a Task_Entry_Call:
5878 -- P : parms := (parm, parm, parm);
5880 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5882 -- procedure _clean is
5885 -- Cancel_Task_Entry_Call (C);
5892 -- (<acceptor-task>, -- Acceptor
5893 -- <entry-index>, -- E
5894 -- P'Address, -- Uninterpreted_Data
5895 -- Asynchronous_Call, -- Mode
5896 -- B); -- Rendezvous_Successful
5903 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5906 -- when Abort_Signal => Abort_Undefer;
5913 -- <triggered-statements>
5917 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5918 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5922 -- P : parms := (parm, parm, parm);
5924 -- Call_Simple (acceptor-task, entry-index, P'Address);
5930 -- so the task at hand is to convert the latter expansion into the former
5932 -- If the trigger is a protected entry call, the select is implemented
5933 -- with Protected_Entry_Call:
5936 -- P : E1_Params := (param, param, param);
5937 -- Bnn : Communications_Block;
5942 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5944 -- procedure _clean is
5947 -- if Enqueued (Bnn) then
5948 -- Cancel_Protected_Entry_Call (Bnn);
5955 -- Protected_Entry_Call
5956 -- (po._object'Access, -- Object
5957 -- <entry index>, -- E
5958 -- P'Address, -- Uninterpreted_Data
5959 -- Asynchronous_Call, -- Mode
5962 -- if Enqueued (Bnn) then
5966 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5969 -- when Abort_Signal => Abort_Undefer;
5972 -- if not Cancelled (Bnn) then
5973 -- <triggered-statements>
5977 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5981 -- P : E1_Params := (param, param, param);
5982 -- Bnn : Communications_Block;
5985 -- Protected_Entry_Call
5986 -- (po._object'Access, -- Object
5987 -- <entry index>, -- E
5988 -- P'Address, -- Uninterpreted_Data
5989 -- Simple_Call, -- Mode
5996 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6000 -- B : Boolean := False;
6001 -- Bnn : Communication_Block;
6002 -- C : Ada.Tags.Prim_Op_Kind;
6003 -- D : System.Storage_Elements.Dummy_Communication_Block;
6004 -- K : Ada.Tags.Tagged_Kind :=
6005 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6006 -- P : Parameters := (Param1 .. ParamN);
6011 -- if K = Ada.Tags.TK_Limited_Tagged then
6012 -- <dispatching-call>;
6013 -- <triggering-statements>;
6017 -- Ada.Tags.Get_Offset_Index
6018 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6020 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6022 -- if C = POK_Protected_Entry then
6024 -- procedure _clean is
6026 -- if Enqueued (Bnn) then
6027 -- Cancel_Protected_Entry_Call (Bnn);
6033 -- _Disp_Asynchronous_Select
6034 -- (<object>, S, P'Address, D, B);
6035 -- Bnn := Communication_Block (D);
6037 -- Param1 := P.Param1;
6039 -- ParamN := P.ParamN;
6041 -- if Enqueued (Bnn) then
6042 -- <abortable-statements>
6045 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6048 -- when Abort_Signal => Abort_Undefer;
6051 -- if not Cancelled (Bnn) then
6052 -- <triggering-statements>
6055 -- elsif C = POK_Task_Entry then
6057 -- procedure _clean is
6059 -- Cancel_Task_Entry_Call (U);
6065 -- _Disp_Asynchronous_Select
6066 -- (<object>, S, P'Address, D, B);
6067 -- Bnn := Communication_Bloc (D);
6069 -- Param1 := P.Param1;
6071 -- ParamN := P.ParamN;
6076 -- <abortable-statements>
6078 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6081 -- when Abort_Signal => Abort_Undefer;
6085 -- <triggering-statements>
6090 -- <dispatching-call>;
6091 -- <triggering-statements>
6096 -- The job is to convert this to the asynchronous form
6098 -- If the trigger is a delay statement, it will have been expanded into a
6099 -- call to one of the GNARL delay procedures. This routine will convert
6100 -- this into a protected entry call on a delay object and then continue
6101 -- processing as for a protected entry call trigger. This requires
6102 -- declaring a Delay_Block object and adding a pointer to this object to
6103 -- the parameter list of the delay procedure to form the parameter list of
6104 -- the entry call. This object is used by the runtime to queue the delay
6107 -- For a description of the use of P and the assignments after the call,
6108 -- see Expand_N_Entry_Call_Statement.
6110 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
6111 Loc : constant Source_Ptr := Sloc (N);
6112 Abrt : constant Node_Id := Abortable_Part (N);
6113 Astats : constant List_Id := Statements (Abrt);
6114 Trig : constant Node_Id := Triggering_Alternative (N);
6115 Tstats : constant List_Id := Statements (Trig);
6117 Abort_Block_Ent : Entity_Id;
6118 Abortable_Block : Node_Id;
6120 Blk_Ent : Entity_Id;
6121 Blk_Typ : Entity_Id;
6123 Call_Ent : Entity_Id;
6124 Cancel_Param : Entity_Id;
6125 Cleanup_Block : Node_Id;
6126 Cleanup_Block_Ent : Entity_Id;
6127 Cleanup_Stmts : List_Id;
6128 Conc_Typ_Stmts : List_Id;
6130 Dblock_Ent : Entity_Id;
6135 Enqueue_Call : Node_Id;
6138 Handler_Stmt : Node_Id;
6140 Lim_Typ_Stmts : List_Id;
6146 ProtE_Stmts : List_Id;
6147 ProtP_Stmts : List_Id;
6150 TaskE_Stmts : List_Id;
6152 B : Entity_Id; -- Call status flag
6153 Bnn : Entity_Id; -- Communication block
6154 C : Entity_Id; -- Call kind
6155 K : Entity_Id; -- Tagged kind
6156 P : Entity_Id; -- Parameter block
6157 S : Entity_Id; -- Primitive operation slot
6158 T : Entity_Id; -- Additional status flag
6161 Process_Statements_For_Controlled_Objects (Trig);
6162 Process_Statements_For_Controlled_Objects (Abrt);
6164 Blk_Ent := Make_Temporary (Loc, 'A');
6165 Ecall := Triggering_Statement (Trig);
6167 -- The arguments in the call may require dynamic allocation, and the
6168 -- call statement may have been transformed into a block. The block
6169 -- may contain additional declarations for internal entities, and the
6170 -- original call is found by sequential search.
6172 if Nkind (Ecall) = N_Block_Statement then
6173 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
6174 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
6175 N_Entry_Call_Statement)
6181 -- This is either a dispatching call or a delay statement used as a
6182 -- trigger which was expanded into a procedure call.
6184 if Nkind (Ecall) = N_Procedure_Call_Statement then
6185 if Ada_Version >= Ada_2005
6187 (No (Original_Node (Ecall))
6188 or else not Nkind_In (Original_Node (Ecall),
6189 N_Delay_Relative_Statement,
6190 N_Delay_Until_Statement))
6192 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
6197 -- Call status flag processing, generate:
6198 -- B : Boolean := False;
6200 B := Build_B (Loc, Decls);
6202 -- Communication block processing, generate:
6203 -- Bnn : Communication_Block;
6205 Bnn := Make_Temporary (Loc, 'B');
6207 Make_Object_Declaration (Loc,
6208 Defining_Identifier => Bnn,
6209 Object_Definition =>
6210 New_Reference_To (RTE (RE_Communication_Block), Loc)));
6212 -- Call kind processing, generate:
6213 -- C : Ada.Tags.Prim_Op_Kind;
6215 C := Build_C (Loc, Decls);
6217 -- Tagged kind processing, generate:
6218 -- K : Ada.Tags.Tagged_Kind :=
6219 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6221 -- Dummy communication block, generate:
6222 -- D : Dummy_Communication_Block;
6225 Make_Object_Declaration (Loc,
6226 Defining_Identifier =>
6227 Make_Defining_Identifier (Loc, Name_uD),
6228 Object_Definition =>
6230 RTE (RE_Dummy_Communication_Block), Loc)));
6232 K := Build_K (Loc, Decls, Obj);
6234 -- Parameter block processing
6236 Blk_Typ := Build_Parameter_Block
6237 (Loc, Actuals, Formals, Decls);
6238 P := Parameter_Block_Pack
6239 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6241 -- Dispatch table slot processing, generate:
6244 S := Build_S (Loc, Decls);
6246 -- Additional status flag processing, generate:
6249 T := Make_Temporary (Loc, 'T');
6251 Make_Object_Declaration (Loc,
6252 Defining_Identifier => T,
6253 Object_Definition =>
6254 New_Reference_To (Standard_Boolean, Loc)));
6256 ------------------------------
6257 -- Protected entry handling --
6258 ------------------------------
6261 -- Param1 := P.Param1;
6263 -- ParamN := P.ParamN;
6265 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6268 -- Bnn := Communication_Block (D);
6270 Prepend_To (Cleanup_Stmts,
6271 Make_Assignment_Statement (Loc,
6273 New_Reference_To (Bnn, Loc),
6275 Make_Unchecked_Type_Conversion (Loc,
6277 New_Reference_To (RTE (RE_Communication_Block), Loc),
6278 Expression => Make_Identifier (Loc, Name_uD))));
6281 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6283 Prepend_To (Cleanup_Stmts,
6284 Make_Procedure_Call_Statement (Loc,
6287 Find_Prim_Op (Etype (Etype (Obj)),
6288 Name_uDisp_Asynchronous_Select),
6290 Parameter_Associations =>
6292 New_Copy_Tree (Obj), -- <object>
6293 New_Reference_To (S, Loc), -- S
6294 Make_Attribute_Reference (Loc, -- P'Address
6296 New_Reference_To (P, Loc),
6299 Make_Identifier (Loc, Name_uD), -- D
6300 New_Reference_To (B, Loc)))); -- B
6303 -- if Enqueued (Bnn) then
6304 -- <abortable-statements>
6307 Append_To (Cleanup_Stmts,
6308 Make_If_Statement (Loc,
6310 Make_Function_Call (Loc,
6312 New_Reference_To (RTE (RE_Enqueued), Loc),
6313 Parameter_Associations =>
6315 New_Reference_To (Bnn, Loc))),
6318 New_Copy_List_Tree (Astats)));
6320 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6321 -- will then generate a _clean for the communication block Bnn.
6325 -- procedure _clean is
6327 -- if Enqueued (Bnn) then
6328 -- Cancel_Protected_Entry_Call (Bnn);
6337 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6339 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6341 -- Wrap the cleanup block in an exception handling block
6347 -- when Abort_Signal => Abort_Undefer;
6350 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6353 Make_Implicit_Label_Declaration (Loc,
6354 Defining_Identifier =>
6358 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6361 -- if not Cancelled (Bnn) then
6362 -- <triggering-statements>
6365 Append_To (ProtE_Stmts,
6366 Make_If_Statement (Loc,
6370 Make_Function_Call (Loc,
6372 New_Reference_To (RTE (RE_Cancelled), Loc),
6373 Parameter_Associations =>
6375 New_Reference_To (Bnn, Loc)))),
6378 New_Copy_List_Tree (Tstats)));
6380 -------------------------
6381 -- Task entry handling --
6382 -------------------------
6385 -- Param1 := P.Param1;
6387 -- ParamN := P.ParamN;
6389 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6392 -- Bnn := Communication_Block (D);
6394 Append_To (TaskE_Stmts,
6395 Make_Assignment_Statement (Loc,
6397 New_Reference_To (Bnn, Loc),
6399 Make_Unchecked_Type_Conversion (Loc,
6401 New_Reference_To (RTE (RE_Communication_Block), Loc),
6402 Expression => Make_Identifier (Loc, Name_uD))));
6405 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6407 Prepend_To (TaskE_Stmts,
6408 Make_Procedure_Call_Statement (Loc,
6411 Find_Prim_Op (Etype (Etype (Obj)),
6412 Name_uDisp_Asynchronous_Select),
6414 Parameter_Associations =>
6416 New_Copy_Tree (Obj), -- <object>
6417 New_Reference_To (S, Loc), -- S
6418 Make_Attribute_Reference (Loc, -- P'Address
6420 New_Reference_To (P, Loc),
6423 Make_Identifier (Loc, Name_uD), -- D
6424 New_Reference_To (B, Loc)))); -- B
6429 Prepend_To (TaskE_Stmts,
6430 Make_Procedure_Call_Statement (Loc,
6432 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6433 Parameter_Associations =>
6438 -- <abortable-statements>
6440 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6442 Prepend_To (Cleanup_Stmts,
6443 Make_Procedure_Call_Statement (Loc,
6445 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6446 Parameter_Associations =>
6449 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6450 -- will generate a _clean for the additional status flag.
6454 -- procedure _clean is
6456 -- Cancel_Task_Entry_Call (U);
6464 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6466 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6468 -- Wrap the cleanup block in an exception handling block
6474 -- when Abort_Signal => Abort_Undefer;
6477 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6479 Append_To (TaskE_Stmts,
6480 Make_Implicit_Label_Declaration (Loc,
6481 Defining_Identifier => Abort_Block_Ent));
6483 Append_To (TaskE_Stmts,
6485 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6489 -- <triggering-statements>
6492 Append_To (TaskE_Stmts,
6493 Make_If_Statement (Loc,
6497 New_Reference_To (T, Loc)),
6500 New_Copy_List_Tree (Tstats)));
6502 ----------------------------------
6503 -- Protected procedure handling --
6504 ----------------------------------
6507 -- <dispatching-call>;
6508 -- <triggering-statements>
6510 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6511 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6514 -- S := Ada.Tags.Get_Offset_Index
6515 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6518 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6521 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6523 Append_To (Conc_Typ_Stmts,
6524 Make_Procedure_Call_Statement (Loc,
6527 Find_Prim_Op (Etype (Etype (Obj)),
6528 Name_uDisp_Get_Prim_Op_Kind),
6530 Parameter_Associations =>
6532 New_Copy_Tree (Obj),
6533 New_Reference_To (S, Loc),
6534 New_Reference_To (C, Loc))));
6537 -- if C = POK_Procedure_Entry then
6539 -- elsif C = POK_Task_Entry then
6545 Append_To (Conc_Typ_Stmts,
6546 Make_If_Statement (Loc,
6550 New_Reference_To (C, Loc),
6552 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6559 Make_Elsif_Part (Loc,
6563 New_Reference_To (C, Loc),
6565 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6574 -- <dispatching-call>;
6575 -- <triggering-statements>
6577 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6578 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6581 -- if K = Ada.Tags.TK_Limited_Tagged then
6588 Make_If_Statement (Loc,
6592 New_Reference_To (K, Loc),
6594 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6603 Make_Block_Statement (Loc,
6606 Handled_Statement_Sequence =>
6607 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6612 -- Delay triggering statement processing
6615 -- Add a Delay_Block object to the parameter list of the delay
6616 -- procedure to form the parameter list of the Wait entry call.
6618 Dblock_Ent := Make_Temporary (Loc, 'D');
6620 Pdef := Entity (Name (Ecall));
6622 if Is_RTE (Pdef, RO_CA_Delay_For) then
6624 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6626 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6628 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6630 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6631 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6634 Append_To (Parameter_Associations (Ecall),
6635 Make_Attribute_Reference (Loc,
6636 Prefix => New_Reference_To (Dblock_Ent, Loc),
6637 Attribute_Name => Name_Unchecked_Access));
6639 -- Create the inner block to protect the abortable part
6641 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6644 Make_Procedure_Call_Statement (Loc,
6645 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6648 Make_Block_Statement (Loc,
6649 Identifier => New_Reference_To (Blk_Ent, Loc),
6650 Handled_Statement_Sequence =>
6651 Make_Handled_Sequence_Of_Statements (Loc,
6652 Statements => Astats),
6653 Has_Created_Identifier => True,
6654 Is_Asynchronous_Call_Block => True);
6656 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6659 Make_Implicit_If_Statement (N,
6660 Condition => Make_Function_Call (Loc,
6661 Name => Enqueue_Call,
6662 Parameter_Associations => Parameter_Associations (Ecall)),
6664 New_List (Make_Block_Statement (Loc,
6665 Handled_Statement_Sequence =>
6666 Make_Handled_Sequence_Of_Statements (Loc,
6667 Statements => New_List (
6668 Make_Implicit_Label_Declaration (Loc,
6669 Defining_Identifier => Blk_Ent,
6670 Label_Construct => Abortable_Block),
6672 Exception_Handlers => Hdle)))));
6674 Stmts := New_List (Ecall);
6676 -- Construct statement sequence for new block
6679 Make_Implicit_If_Statement (N,
6680 Condition => Make_Function_Call (Loc,
6681 Name => New_Reference_To (
6682 RTE (RE_Timed_Out), Loc),
6683 Parameter_Associations => New_List (
6684 Make_Attribute_Reference (Loc,
6685 Prefix => New_Reference_To (Dblock_Ent, Loc),
6686 Attribute_Name => Name_Unchecked_Access))),
6687 Then_Statements => Tstats));
6689 -- The result is the new block
6691 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6694 Make_Block_Statement (Loc,
6695 Declarations => New_List (
6696 Make_Object_Declaration (Loc,
6697 Defining_Identifier => Dblock_Ent,
6698 Aliased_Present => True,
6699 Object_Definition => New_Reference_To (
6700 RTE (RE_Delay_Block), Loc))),
6702 Handled_Statement_Sequence =>
6703 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6713 Extract_Entry (Ecall, Concval, Ename, Index);
6714 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6716 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6717 Decls := Declarations (Ecall);
6719 if Is_Protected_Type (Etype (Concval)) then
6721 -- Get the declarations of the block expanded from the entry call
6723 Decl := First (Decls);
6724 while Present (Decl)
6726 (Nkind (Decl) /= N_Object_Declaration
6727 or else not Is_RTE (Etype (Object_Definition (Decl)),
6728 RE_Communication_Block))
6733 pragma Assert (Present (Decl));
6734 Cancel_Param := Defining_Identifier (Decl);
6736 -- Change the mode of the Protected_Entry_Call call
6738 -- Protected_Entry_Call (
6739 -- Object => po._object'Access,
6740 -- E => <entry index>;
6741 -- Uninterpreted_Data => P'Address;
6742 -- Mode => Asynchronous_Call;
6745 Stmt := First (Stmts);
6747 -- Skip assignments to temporaries created for in-out parameters
6749 -- This makes unwarranted assumptions about the shape of the expanded
6750 -- tree for the call, and should be cleaned up ???
6752 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6758 Param := First (Parameter_Associations (Call));
6759 while Present (Param)
6760 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6765 pragma Assert (Present (Param));
6766 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6769 -- Append an if statement to execute the abortable part
6772 -- if Enqueued (Bnn) then
6775 Make_Implicit_If_Statement (N,
6776 Condition => Make_Function_Call (Loc,
6777 Name => New_Reference_To (RTE (RE_Enqueued), Loc),
6778 Parameter_Associations => New_List (
6779 New_Reference_To (Cancel_Param, Loc))),
6780 Then_Statements => Astats));
6783 Make_Block_Statement (Loc,
6784 Identifier => New_Reference_To (Blk_Ent, Loc),
6785 Handled_Statement_Sequence =>
6786 Make_Handled_Sequence_Of_Statements (Loc,
6787 Statements => Stmts),
6788 Has_Created_Identifier => True,
6789 Is_Asynchronous_Call_Block => True);
6791 -- For the VM call Update_Exception instead of Abort_Undefer.
6792 -- See 4jexcept.ads for an explanation.
6794 if VM_Target = No_VM then
6795 if Exception_Mechanism = Back_End_Exceptions then
6797 -- Aborts are not deferred at beginning of exception handlers
6800 Handler_Stmt := Make_Null_Statement (Loc);
6803 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6804 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6805 Parameter_Associations => No_List);
6808 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6809 Name => New_Reference_To (RTE (RE_Update_Exception), Loc),
6810 Parameter_Associations => New_List (
6811 Make_Function_Call (Loc,
6812 Name => New_Occurrence_Of
6813 (RTE (RE_Current_Target_Exception), Loc))));
6817 Make_Block_Statement (Loc,
6818 Handled_Statement_Sequence =>
6819 Make_Handled_Sequence_Of_Statements (Loc,
6820 Statements => New_List (
6821 Make_Implicit_Label_Declaration (Loc,
6822 Defining_Identifier => Blk_Ent,
6823 Label_Construct => Abortable_Block),
6828 Exception_Handlers => New_List (
6829 Make_Implicit_Exception_Handler (Loc,
6831 -- when Abort_Signal =>
6832 -- Abort_Undefer.all;
6834 Exception_Choices =>
6835 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6836 Statements => New_List (Handler_Stmt))))),
6838 -- if not Cancelled (Bnn) then
6839 -- triggered statements
6842 Make_Implicit_If_Statement (N,
6843 Condition => Make_Op_Not (Loc,
6845 Make_Function_Call (Loc,
6846 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6847 Parameter_Associations => New_List (
6848 New_Occurrence_Of (Cancel_Param, Loc)))),
6849 Then_Statements => Tstats));
6851 -- Asynchronous task entry call
6858 B := Make_Defining_Identifier (Loc, Name_uB);
6860 -- Insert declaration of B in declarations of existing block
6863 Make_Object_Declaration (Loc,
6864 Defining_Identifier => B,
6865 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6867 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6869 -- Insert declaration of C in declarations of existing block
6872 Make_Object_Declaration (Loc,
6873 Defining_Identifier => Cancel_Param,
6874 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6876 -- Remove and save the call to Call_Simple
6878 Stmt := First (Stmts);
6880 -- Skip assignments to temporaries created for in-out parameters.
6881 -- This makes unwarranted assumptions about the shape of the expanded
6882 -- tree for the call, and should be cleaned up ???
6884 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6890 -- Create the inner block to protect the abortable part
6892 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6895 Make_Procedure_Call_Statement (Loc,
6896 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6899 Make_Block_Statement (Loc,
6900 Identifier => New_Reference_To (Blk_Ent, Loc),
6901 Handled_Statement_Sequence =>
6902 Make_Handled_Sequence_Of_Statements (Loc,
6903 Statements => Astats),
6904 Has_Created_Identifier => True,
6905 Is_Asynchronous_Call_Block => True);
6908 Make_Block_Statement (Loc,
6909 Handled_Statement_Sequence =>
6910 Make_Handled_Sequence_Of_Statements (Loc,
6911 Statements => New_List (
6912 Make_Implicit_Label_Declaration (Loc,
6913 Defining_Identifier =>
6918 Exception_Handlers => Hdle)));
6920 -- Create new call statement
6922 Params := Parameter_Associations (Call);
6925 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6927 New_Reference_To (B, Loc));
6930 Make_Procedure_Call_Statement (Loc,
6932 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6933 Parameter_Associations => Params));
6935 -- Construct statement sequence for new block
6938 Make_Implicit_If_Statement (N,
6941 New_Reference_To (Cancel_Param, Loc)),
6942 Then_Statements => Tstats));
6944 -- Protected the call against abort
6947 Make_Procedure_Call_Statement (Loc,
6948 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6949 Parameter_Associations => Empty_List));
6952 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6954 -- The result is the new block
6957 Make_Block_Statement (Loc,
6958 Declarations => Decls,
6959 Handled_Statement_Sequence =>
6960 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6963 end Expand_N_Asynchronous_Select;
6965 -------------------------------------
6966 -- Expand_N_Conditional_Entry_Call --
6967 -------------------------------------
6969 -- The conditional task entry call is converted to a call to
6974 -- P : parms := (parm, parm, parm);
6978 -- (<acceptor-task>, -- Acceptor
6979 -- <entry-index>, -- E
6980 -- P'Address, -- Uninterpreted_Data
6981 -- Conditional_Call, -- Mode
6982 -- B); -- Rendezvous_Successful
6987 -- normal-statements
6993 -- For a description of the use of P and the assignments after the call,
6994 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6995 -- conditional entry call has already been expanded (by the Expand_N_Entry
6996 -- _Call_Statement procedure) as follows:
6999 -- P : parms := (parm, parm, parm);
7001 -- ... info for in-out parameters
7002 -- Call_Simple (acceptor-task, entry-index, P'Address);
7008 -- so the task at hand is to convert the latter expansion into the former
7010 -- The conditional protected entry call is converted to a call to
7011 -- Protected_Entry_Call:
7014 -- P : parms := (parm, parm, parm);
7015 -- Bnn : Communications_Block;
7018 -- Protected_Entry_Call
7019 -- (po._object'Access, -- Object
7020 -- <entry index>, -- E
7021 -- P'Address, -- Uninterpreted_Data
7022 -- Conditional_Call, -- Mode
7027 -- if Cancelled (Bnn) then
7030 -- normal-statements
7034 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7038 -- B : Boolean := False;
7039 -- C : Ada.Tags.Prim_Op_Kind;
7040 -- K : Ada.Tags.Tagged_Kind :=
7041 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7042 -- P : Parameters := (Param1 .. ParamN);
7046 -- if K = Ada.Tags.TK_Limited_Tagged then
7047 -- <dispatching-call>;
7048 -- <triggering-statements>
7052 -- Ada.Tags.Get_Offset_Index
7053 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7055 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7057 -- if C = POK_Protected_Entry
7058 -- or else C = POK_Task_Entry
7060 -- Param1 := P.Param1;
7062 -- ParamN := P.ParamN;
7066 -- if C = POK_Procedure
7067 -- or else C = POK_Protected_Procedure
7068 -- or else C = POK_Task_Procedure
7070 -- <dispatching-call>;
7073 -- <triggering-statements>
7075 -- <else-statements>
7080 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
7081 Loc : constant Source_Ptr := Sloc (N);
7082 Alt : constant Node_Id := Entry_Call_Alternative (N);
7083 Blk : Node_Id := Entry_Call_Statement (Alt);
7086 Blk_Typ : Entity_Id;
7088 Call_Ent : Entity_Id;
7089 Conc_Typ_Stmts : List_Id;
7093 Lim_Typ_Stmts : List_Id;
7100 Transient_Blk : Node_Id;
7103 B : Entity_Id; -- Call status flag
7104 C : Entity_Id; -- Call kind
7105 K : Entity_Id; -- Tagged kind
7106 P : Entity_Id; -- Parameter block
7107 S : Entity_Id; -- Primitive operation slot
7110 Process_Statements_For_Controlled_Objects (N);
7112 if Ada_Version >= Ada_2005
7113 and then Nkind (Blk) = N_Procedure_Call_Statement
7115 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7120 -- Call status flag processing, generate:
7121 -- B : Boolean := False;
7123 B := Build_B (Loc, Decls);
7125 -- Call kind processing, generate:
7126 -- C : Ada.Tags.Prim_Op_Kind;
7128 C := Build_C (Loc, Decls);
7130 -- Tagged kind processing, generate:
7131 -- K : Ada.Tags.Tagged_Kind :=
7132 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7134 K := Build_K (Loc, Decls, Obj);
7136 -- Parameter block processing
7138 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7139 P := Parameter_Block_Pack
7140 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7142 -- Dispatch table slot processing, generate:
7145 S := Build_S (Loc, Decls);
7148 -- S := Ada.Tags.Get_Offset_Index
7149 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7152 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7155 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7157 Append_To (Conc_Typ_Stmts,
7158 Make_Procedure_Call_Statement (Loc,
7161 Find_Prim_Op (Etype (Etype (Obj)),
7162 Name_uDisp_Conditional_Select),
7164 Parameter_Associations =>
7166 New_Copy_Tree (Obj), -- <object>
7167 New_Reference_To (S, Loc), -- S
7168 Make_Attribute_Reference (Loc, -- P'Address
7170 New_Reference_To (P, Loc),
7173 New_Reference_To (C, Loc), -- C
7174 New_Reference_To (B, Loc)))); -- B
7177 -- if C = POK_Protected_Entry
7178 -- or else C = POK_Task_Entry
7180 -- Param1 := P.Param1;
7182 -- ParamN := P.ParamN;
7185 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7187 -- Generate the if statement only when the packed parameters need
7188 -- explicit assignments to their corresponding actuals.
7190 if Present (Unpack) then
7191 Append_To (Conc_Typ_Stmts,
7192 Make_If_Statement (Loc,
7199 New_Reference_To (C, Loc),
7201 New_Reference_To (RTE (
7202 RE_POK_Protected_Entry), Loc)),
7206 New_Reference_To (C, Loc),
7208 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
7216 -- if C = POK_Procedure
7217 -- or else C = POK_Protected_Procedure
7218 -- or else C = POK_Task_Procedure
7220 -- <dispatching-call>
7222 -- <normal-statements>
7224 -- <else-statements>
7227 N_Stats := New_Copy_List_Tree (Statements (Alt));
7229 Prepend_To (N_Stats,
7230 Make_If_Statement (Loc,
7236 New_Reference_To (C, Loc),
7238 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
7245 New_Reference_To (C, Loc),
7247 New_Reference_To (RTE (
7248 RE_POK_Protected_Procedure), Loc)),
7253 New_Reference_To (C, Loc),
7255 New_Reference_To (RTE (
7256 RE_POK_Task_Procedure), Loc)))),
7261 Append_To (Conc_Typ_Stmts,
7262 Make_If_Statement (Loc,
7263 Condition => New_Reference_To (B, Loc),
7264 Then_Statements => N_Stats,
7265 Else_Statements => Else_Statements (N)));
7268 -- <dispatching-call>;
7269 -- <triggering-statements>
7271 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
7272 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
7275 -- if K = Ada.Tags.TK_Limited_Tagged then
7282 Make_If_Statement (Loc,
7286 New_Reference_To (K, Loc),
7288 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
7297 Make_Block_Statement (Loc,
7300 Handled_Statement_Sequence =>
7301 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7303 -- As described above, The entry alternative is transformed into a
7304 -- block that contains the gnulli call, and possibly assignment
7305 -- statements for in-out parameters. The gnulli call may itself be
7306 -- rewritten into a transient block if some unconstrained parameters
7307 -- require it. We need to retrieve the call to complete its parameter
7312 First_Real_Statement (Handled_Statement_Sequence (Blk));
7314 if Present (Transient_Blk)
7315 and then Nkind (Transient_Blk) = N_Block_Statement
7317 Blk := Transient_Blk;
7320 Stmts := Statements (Handled_Statement_Sequence (Blk));
7321 Stmt := First (Stmts);
7322 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7327 Params := Parameter_Associations (Call);
7329 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7331 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7333 Param := First (Params);
7334 while Present (Param)
7335 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7340 pragma Assert (Present (Param));
7341 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
7345 -- Find the Communication_Block parameter for the call to the
7346 -- Cancelled function.
7348 Decl := First (Declarations (Blk));
7349 while Present (Decl)
7350 and then not Is_RTE (Etype (Object_Definition (Decl)),
7351 RE_Communication_Block)
7356 -- Add an if statement to execute the else part if the call
7357 -- does not succeed (as indicated by the Cancelled predicate).
7360 Make_Implicit_If_Statement (N,
7361 Condition => Make_Function_Call (Loc,
7362 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
7363 Parameter_Associations => New_List (
7364 New_Reference_To (Defining_Identifier (Decl), Loc))),
7365 Then_Statements => Else_Statements (N),
7366 Else_Statements => Statements (Alt)));
7369 B := Make_Defining_Identifier (Loc, Name_uB);
7371 -- Insert declaration of B in declarations of existing block
7373 if No (Declarations (Blk)) then
7374 Set_Declarations (Blk, New_List);
7377 Prepend_To (Declarations (Blk),
7378 Make_Object_Declaration (Loc,
7379 Defining_Identifier => B,
7380 Object_Definition =>
7381 New_Reference_To (Standard_Boolean, Loc)));
7383 -- Create new call statement
7386 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7387 Append_To (Params, New_Reference_To (B, Loc));
7390 Make_Procedure_Call_Statement (Loc,
7391 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7392 Parameter_Associations => Params));
7394 -- Construct statement sequence for new block
7397 Make_Implicit_If_Statement (N,
7398 Condition => New_Reference_To (B, Loc),
7399 Then_Statements => Statements (Alt),
7400 Else_Statements => Else_Statements (N)));
7403 -- The result is the new block
7406 Make_Block_Statement (Loc,
7407 Declarations => Declarations (Blk),
7408 Handled_Statement_Sequence =>
7409 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7413 end Expand_N_Conditional_Entry_Call;
7415 ---------------------------------------
7416 -- Expand_N_Delay_Relative_Statement --
7417 ---------------------------------------
7419 -- Delay statement is implemented as a procedure call to Delay_For
7420 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7421 -- simple delays imposed by the use of Protected Objects.
7423 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7424 Loc : constant Source_Ptr := Sloc (N);
7427 Make_Procedure_Call_Statement (Loc,
7428 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7429 Parameter_Associations => New_List (Expression (N))));
7431 end Expand_N_Delay_Relative_Statement;
7433 ------------------------------------
7434 -- Expand_N_Delay_Until_Statement --
7435 ------------------------------------
7437 -- Delay Until statement is implemented as a procedure call to
7438 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7440 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7441 Loc : constant Source_Ptr := Sloc (N);
7445 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7446 Typ := RTE (RO_CA_Delay_Until);
7448 Typ := RTE (RO_RT_Delay_Until);
7452 Make_Procedure_Call_Statement (Loc,
7453 Name => New_Reference_To (Typ, Loc),
7454 Parameter_Associations => New_List (Expression (N))));
7457 end Expand_N_Delay_Until_Statement;
7459 -------------------------
7460 -- Expand_N_Entry_Body --
7461 -------------------------
7463 procedure Expand_N_Entry_Body (N : Node_Id) is
7465 -- Associate discriminals with the next protected operation body to be
7468 if Present (Next_Protected_Operation (N)) then
7469 Set_Discriminals (Parent (Current_Scope));
7471 end Expand_N_Entry_Body;
7473 -----------------------------------
7474 -- Expand_N_Entry_Call_Statement --
7475 -----------------------------------
7477 -- An entry call is expanded into GNARLI calls to implement a simple entry
7478 -- call (see Build_Simple_Entry_Call).
7480 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7486 if No_Run_Time_Mode then
7487 Error_Msg_CRT ("entry call", N);
7491 -- If this entry call is part of an asynchronous select, don't expand it
7492 -- here; it will be expanded with the select statement. Don't expand
7493 -- timed entry calls either, as they are translated into asynchronous
7496 -- ??? This whole approach is questionable; it may be better to go back
7497 -- to allowing the expansion to take place and then attempting to fix it
7498 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7499 -- whether the expanded call is on a task or protected entry.
7501 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7502 or else N /= Triggering_Statement (Parent (N)))
7503 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7504 or else N /= Entry_Call_Statement (Parent (N))
7505 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7507 Extract_Entry (N, Concval, Ename, Index);
7508 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7510 end Expand_N_Entry_Call_Statement;
7512 --------------------------------
7513 -- Expand_N_Entry_Declaration --
7514 --------------------------------
7516 -- If there are parameters, then first, each of the formals is marked by
7517 -- setting Is_Entry_Formal. Next a record type is built which is used to
7518 -- hold the parameter values. The name of this record type is entryP where
7519 -- entry is the name of the entry, with an additional corresponding access
7520 -- type called entryPA. The record type has matching components for each
7521 -- formal (the component names are the same as the formal names). For
7522 -- elementary types, the component type matches the formal type. For
7523 -- composite types, an access type is declared (with the name formalA)
7524 -- which designates the formal type, and the type of the component is this
7525 -- access type. Finally the Entry_Component of each formal is set to
7526 -- reference the corresponding record component.
7528 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7529 Loc : constant Source_Ptr := Sloc (N);
7530 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7531 Components : List_Id;
7534 Last_Decl : Node_Id;
7535 Component : Entity_Id;
7538 Rec_Ent : Entity_Id;
7539 Acc_Ent : Entity_Id;
7542 Formal := First_Formal (Entry_Ent);
7545 -- Most processing is done only if parameters are present
7547 if Present (Formal) then
7548 Components := New_List;
7550 -- Loop through formals
7552 while Present (Formal) loop
7553 Set_Is_Entry_Formal (Formal);
7555 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7556 Set_Entry_Component (Formal, Component);
7557 Set_Entry_Formal (Component, Formal);
7558 Ftype := Etype (Formal);
7560 -- Declare new access type and then append
7562 Ctype := Make_Temporary (Loc, 'A');
7565 Make_Full_Type_Declaration (Loc,
7566 Defining_Identifier => Ctype,
7568 Make_Access_To_Object_Definition (Loc,
7569 All_Present => True,
7570 Constant_Present => Ekind (Formal) = E_In_Parameter,
7571 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7573 Insert_After (Last_Decl, Decl);
7576 Append_To (Components,
7577 Make_Component_Declaration (Loc,
7578 Defining_Identifier => Component,
7579 Component_Definition =>
7580 Make_Component_Definition (Loc,
7581 Aliased_Present => False,
7582 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7584 Next_Formal_With_Extras (Formal);
7587 -- Create the Entry_Parameter_Record declaration
7589 Rec_Ent := Make_Temporary (Loc, 'P');
7592 Make_Full_Type_Declaration (Loc,
7593 Defining_Identifier => Rec_Ent,
7595 Make_Record_Definition (Loc,
7597 Make_Component_List (Loc,
7598 Component_Items => Components)));
7600 Insert_After (Last_Decl, Decl);
7603 -- Construct and link in the corresponding access type
7605 Acc_Ent := Make_Temporary (Loc, 'A');
7607 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7610 Make_Full_Type_Declaration (Loc,
7611 Defining_Identifier => Acc_Ent,
7613 Make_Access_To_Object_Definition (Loc,
7614 All_Present => True,
7615 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7617 Insert_After (Last_Decl, Decl);
7619 end Expand_N_Entry_Declaration;
7621 -----------------------------
7622 -- Expand_N_Protected_Body --
7623 -----------------------------
7625 -- Protected bodies are expanded to the completion of the subprograms
7626 -- created for the corresponding protected type. These are a protected and
7627 -- unprotected version of each protected subprogram in the object, a
7628 -- function to calculate each entry barrier, and a procedure to execute the
7629 -- sequence of statements of each protected entry body. For example, for
7630 -- protected type ptype:
7633 -- (O : System.Address;
7634 -- E : Protected_Entry_Index)
7637 -- <discriminant renamings>
7638 -- <private object renamings>
7640 -- return <barrier expression>;
7643 -- procedure pprocN (_object : in out poV;...) is
7644 -- <discriminant renamings>
7645 -- <private object renamings>
7647 -- <sequence of statements>
7650 -- procedure pprocP (_object : in out poV;...) is
7651 -- procedure _clean is
7654 -- ptypeS (_object, Pn);
7655 -- Unlock (_object._object'Access);
7656 -- Abort_Undefer.all;
7661 -- Lock (_object._object'Access);
7662 -- pprocN (_object;...);
7667 -- function pfuncN (_object : poV;...) return Return_Type is
7668 -- <discriminant renamings>
7669 -- <private object renamings>
7671 -- <sequence of statements>
7674 -- function pfuncP (_object : poV) return Return_Type is
7675 -- procedure _clean is
7677 -- Unlock (_object._object'Access);
7678 -- Abort_Undefer.all;
7683 -- Lock (_object._object'Access);
7684 -- return pfuncN (_object);
7691 -- (O : System.Address;
7692 -- P : System.Address;
7693 -- E : Protected_Entry_Index)
7695 -- <discriminant renamings>
7696 -- <private object renamings>
7697 -- type poVP is access poV;
7698 -- _Object : ptVP := ptVP!(O);
7702 -- <statement sequence>
7703 -- Complete_Entry_Body (_Object._Object);
7705 -- when all others =>
7706 -- Exceptional_Complete_Entry_Body (
7707 -- _Object._Object, Get_GNAT_Exception);
7711 -- The type poV is the record created for the protected type to hold
7712 -- the state of the protected object.
7714 procedure Expand_N_Protected_Body (N : Node_Id) is
7715 Loc : constant Source_Ptr := Sloc (N);
7716 Pid : constant Entity_Id := Corresponding_Spec (N);
7718 Current_Node : Node_Id;
7719 Disp_Op_Body : Node_Id;
7720 New_Op_Body : Node_Id;
7721 Num_Entries : Natural := 0;
7725 function Build_Dispatching_Subprogram_Body
7728 Prot_Bod : Node_Id) return Node_Id;
7729 -- Build a dispatching version of the protected subprogram body. The
7730 -- newly generated subprogram contains a call to the original protected
7731 -- body. The following code is generated:
7733 -- function <protected-function-name> (Param1 .. ParamN) return
7736 -- return <protected-function-name>P (Param1 .. ParamN);
7737 -- end <protected-function-name>;
7741 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7743 -- <protected-procedure-name>P (Param1 .. ParamN);
7744 -- end <protected-procedure-name>
7746 ---------------------------------------
7747 -- Build_Dispatching_Subprogram_Body --
7748 ---------------------------------------
7750 function Build_Dispatching_Subprogram_Body
7753 Prot_Bod : Node_Id) return Node_Id
7755 Loc : constant Source_Ptr := Sloc (N);
7762 -- Generate a specification without a letter suffix in order to
7763 -- override an interface function or procedure.
7765 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7767 -- The formal parameters become the actuals of the protected function
7768 -- or procedure call.
7770 Actuals := New_List;
7771 Formal := First (Parameter_Specifications (Spec));
7772 while Present (Formal) loop
7774 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7779 if Nkind (Spec) = N_Procedure_Specification then
7782 Make_Procedure_Call_Statement (Loc,
7784 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7785 Parameter_Associations => Actuals));
7787 pragma Assert (Nkind (Spec) = N_Function_Specification);
7791 Make_Simple_Return_Statement (Loc,
7793 Make_Function_Call (Loc,
7795 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7796 Parameter_Associations => Actuals)));
7800 Make_Subprogram_Body (Loc,
7801 Declarations => Empty_List,
7802 Specification => Spec,
7803 Handled_Statement_Sequence =>
7804 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7805 end Build_Dispatching_Subprogram_Body;
7807 -- Start of processing for Expand_N_Protected_Body
7810 if No_Run_Time_Mode then
7811 Error_Msg_CRT ("protected body", N);
7815 -- This is the proper body corresponding to a stub. The declarations
7816 -- must be inserted at the point of the stub, which in turn is in the
7817 -- declarative part of the parent unit.
7819 if Nkind (Parent (N)) = N_Subunit then
7820 Current_Node := Corresponding_Stub (Parent (N));
7825 Op_Body := First (Declarations (N));
7827 -- The protected body is replaced with the bodies of its
7828 -- protected operations, and the declarations for internal objects
7829 -- that may have been created for entry family bounds.
7831 Rewrite (N, Make_Null_Statement (Sloc (N)));
7834 while Present (Op_Body) loop
7835 case Nkind (Op_Body) is
7836 when N_Subprogram_Declaration =>
7839 when N_Subprogram_Body =>
7841 -- Do not create bodies for eliminated operations
7843 if not Is_Eliminated (Defining_Entity (Op_Body))
7844 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7847 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7849 Insert_After (Current_Node, New_Op_Body);
7850 Current_Node := New_Op_Body;
7851 Analyze (New_Op_Body);
7853 -- Build the corresponding protected operation. It may
7854 -- appear that this is needed only if this is a visible
7855 -- operation of the type, or if it is an interrupt handler,
7856 -- and this was the strategy used previously in GNAT.
7857 -- However, the operation may be exported through a 'Access
7858 -- to an external caller. This is the common idiom in code
7859 -- that uses the Ada 2005 Timing_Events package. As a result
7860 -- we need to produce the protected body for both visible
7861 -- and private operations, as well as operations that only
7862 -- have a body in the source, and for which we create a
7863 -- declaration in the protected body itself.
7865 if Present (Corresponding_Spec (Op_Body)) then
7867 Build_Protected_Subprogram_Body (
7868 Op_Body, Pid, Specification (New_Op_Body));
7870 Insert_After (Current_Node, New_Op_Body);
7871 Analyze (New_Op_Body);
7873 Current_Node := New_Op_Body;
7875 -- Generate an overriding primitive operation body for
7876 -- this subprogram if the protected type implements an
7879 if Ada_Version >= Ada_2005
7881 Present (Interfaces (Corresponding_Record_Type (Pid)))
7884 Build_Dispatching_Subprogram_Body
7885 (Op_Body, Pid, New_Op_Body);
7887 Insert_After (Current_Node, Disp_Op_Body);
7888 Analyze (Disp_Op_Body);
7890 Current_Node := Disp_Op_Body;
7895 when N_Entry_Body =>
7896 Op_Id := Defining_Identifier (Op_Body);
7897 Num_Entries := Num_Entries + 1;
7899 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7901 Insert_After (Current_Node, New_Op_Body);
7902 Current_Node := New_Op_Body;
7903 Analyze (New_Op_Body);
7905 when N_Implicit_Label_Declaration =>
7908 when N_Itype_Reference =>
7909 Insert_After (Current_Node, New_Copy (Op_Body));
7911 when N_Freeze_Entity =>
7912 New_Op_Body := New_Copy (Op_Body);
7914 if Present (Entity (Op_Body))
7915 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7917 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7920 Insert_After (Current_Node, New_Op_Body);
7921 Current_Node := New_Op_Body;
7922 Analyze (New_Op_Body);
7925 New_Op_Body := New_Copy (Op_Body);
7926 Insert_After (Current_Node, New_Op_Body);
7927 Current_Node := New_Op_Body;
7928 Analyze (New_Op_Body);
7930 when N_Object_Declaration =>
7931 pragma Assert (not Comes_From_Source (Op_Body));
7932 New_Op_Body := New_Copy (Op_Body);
7933 Insert_After (Current_Node, New_Op_Body);
7934 Current_Node := New_Op_Body;
7935 Analyze (New_Op_Body);
7938 raise Program_Error;
7945 -- Finally, create the body of the function that maps an entry index
7946 -- into the corresponding body index, except when there is no entry, or
7947 -- in a Ravenscar-like profile.
7949 if Corresponding_Runtime_Package (Pid) =
7950 System_Tasking_Protected_Objects_Entries
7952 New_Op_Body := Build_Find_Body_Index (Pid);
7953 Insert_After (Current_Node, New_Op_Body);
7954 Current_Node := New_Op_Body;
7955 Analyze (New_Op_Body);
7958 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7959 -- protected body. At this point all wrapper specs have been created,
7960 -- frozen and included in the dispatch table for the protected type.
7962 if Ada_Version >= Ada_2005 then
7963 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7965 end Expand_N_Protected_Body;
7967 -----------------------------------------
7968 -- Expand_N_Protected_Type_Declaration --
7969 -----------------------------------------
7971 -- First we create a corresponding record type declaration used to
7972 -- represent values of this protected type.
7973 -- The general form of this type declaration is
7975 -- type poV (discriminants) is record
7976 -- _Object : aliased <kind>Protection
7977 -- [(<entry count> [, <handler count>])];
7978 -- [entry_family : array (bounds) of Void;]
7979 -- <private data fields>
7982 -- The discriminants are present only if the corresponding protected type
7983 -- has discriminants, and they exactly mirror the protected type
7984 -- discriminants. The private data fields similarly mirror the private
7985 -- declarations of the protected type.
7987 -- The Object field is always present. It contains RTS specific data used
7988 -- to control the protected object. It is declared as Aliased so that it
7989 -- can be passed as a pointer to the RTS. This allows the protected record
7990 -- to be referenced within RTS data structures. An appropriate Protection
7991 -- type and discriminant are generated.
7993 -- The Service field is present for protected objects with entries. It
7994 -- contains sufficient information to allow the entry service procedure for
7995 -- this object to be called when the object is not known till runtime.
7997 -- One entry_family component is present for each entry family in the
7998 -- task definition (see Expand_N_Task_Type_Declaration).
8000 -- When a protected object is declared, an instance of the protected type
8001 -- value record is created. The elaboration of this declaration creates the
8002 -- correct bounds for the entry families, and also evaluates the priority
8003 -- expression if needed. The initialization routine for the protected type
8004 -- itself then calls Initialize_Protection with appropriate parameters to
8005 -- initialize the value of the Task_Id field. Install_Handlers may be also
8006 -- called if a pragma Attach_Handler applies.
8008 -- Note: this record is passed to the subprograms created by the expansion
8009 -- of protected subprograms and entries. It is an in parameter to protected
8010 -- functions and an in out parameter to procedures and entry bodies. The
8011 -- Entity_Id for this created record type is placed in the
8012 -- Corresponding_Record_Type field of the associated protected type entity.
8014 -- Next we create a procedure specifications for protected subprograms and
8015 -- entry bodies. For each protected subprograms two subprograms are
8016 -- created, an unprotected and a protected version. The unprotected version
8017 -- is called from within other operations of the same protected object.
8019 -- We also build the call to register the procedure if a pragma
8020 -- Interrupt_Handler applies.
8022 -- A single subprogram is created to service all entry bodies; it has an
8023 -- additional boolean out parameter indicating that the previous entry call
8024 -- made by the current task was serviced immediately, i.e. not by proxy.
8025 -- The O parameter contains a pointer to a record object of the type
8026 -- described above. An untyped interface is used here to allow this
8027 -- procedure to be called in places where the type of the object to be
8028 -- serviced is not known. This must be done, for example, when a call that
8029 -- may have been requeued is cancelled; the corresponding object must be
8030 -- serviced, but which object that is not known till runtime.
8033 -- (O : System.Address; P : out Boolean);
8034 -- procedure pprocN (_object : in out poV);
8035 -- procedure pproc (_object : in out poV);
8036 -- function pfuncN (_object : poV);
8037 -- function pfunc (_object : poV);
8040 -- Note that this must come after the record type declaration, since
8041 -- the specs refer to this type.
8043 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
8044 Loc : constant Source_Ptr := Sloc (N);
8045 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
8047 Pdef : constant Node_Id := Protected_Definition (N);
8048 -- This contains two lists; one for visible and one for private decls
8052 Discr_Map : constant Elist_Id := New_Elmt_List;
8056 Comp_Id : Entity_Id;
8058 Current_Node : Node_Id := N;
8059 Bdef : Entity_Id := Empty; -- avoid uninit warning
8060 Edef : Entity_Id := Empty; -- avoid uninit warning
8061 Entries_Aggr : Node_Id;
8062 Body_Id : Entity_Id;
8065 Object_Comp : Node_Id;
8067 procedure Check_Inlining (Subp : Entity_Id);
8068 -- If the original operation has a pragma Inline, propagate the flag
8069 -- to the internal body, for possible inlining later on. The source
8070 -- operation is invisible to the back-end and is never actually called.
8072 function Static_Component_Size (Comp : Entity_Id) return Boolean;
8073 -- When compiling under the Ravenscar profile, private components must
8074 -- have a static size, or else a protected object will require heap
8075 -- allocation, violating the corresponding restriction. It is preferable
8076 -- to make this check here, because it provides a better error message
8077 -- than the back-end, which refers to the object as a whole.
8079 procedure Register_Handler;
8080 -- For a protected operation that is an interrupt handler, add the
8081 -- freeze action that will register it as such.
8083 --------------------
8084 -- Check_Inlining --
8085 --------------------
8087 procedure Check_Inlining (Subp : Entity_Id) is
8089 if Is_Inlined (Subp) then
8090 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8091 Set_Is_Inlined (Subp, False);
8095 ---------------------------------
8096 -- Check_Static_Component_Size --
8097 ---------------------------------
8099 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8100 Typ : constant Entity_Id := Etype (Comp);
8104 if Is_Scalar_Type (Typ) then
8107 elsif Is_Array_Type (Typ) then
8108 return Compile_Time_Known_Bounds (Typ);
8110 elsif Is_Record_Type (Typ) then
8111 C := First_Component (Typ);
8112 while Present (C) loop
8113 if not Static_Component_Size (C) then
8122 -- Any other types will be checked by the back-end
8127 end Static_Component_Size;
8129 ----------------------
8130 -- Register_Handler --
8131 ----------------------
8133 procedure Register_Handler is
8135 -- All semantic checks already done in Sem_Prag
8137 Prot_Proc : constant Entity_Id :=
8139 (Specification (Current_Node));
8141 Proc_Address : constant Node_Id :=
8142 Make_Attribute_Reference (Loc,
8143 Prefix => New_Reference_To (Prot_Proc, Loc),
8144 Attribute_Name => Name_Address);
8146 RTS_Call : constant Entity_Id :=
8147 Make_Procedure_Call_Statement (Loc,
8150 RTE (RE_Register_Interrupt_Handler), Loc),
8151 Parameter_Associations =>
8152 New_List (Proc_Address));
8154 Append_Freeze_Action (Prot_Proc, RTS_Call);
8155 end Register_Handler;
8157 -- Start of processing for Expand_N_Protected_Type_Declaration
8160 if Present (Corresponding_Record_Type (Prot_Typ)) then
8163 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
8166 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
8168 Qualify_Entity_Names (N);
8170 -- If the type has discriminants, their occurrences in the declaration
8171 -- have been replaced by the corresponding discriminals. For components
8172 -- that are constrained by discriminants, their homologues in the
8173 -- corresponding record type must refer to the discriminants of that
8174 -- record, so we must apply a new renaming to subtypes_indications:
8176 -- protected discriminant => discriminal => record discriminant
8178 -- This replacement is not applied to default expressions, for which
8179 -- the discriminal is correct.
8181 if Has_Discriminants (Prot_Typ) then
8187 Disc := First_Discriminant (Prot_Typ);
8188 Decl := First (Discriminant_Specifications (Rec_Decl));
8189 while Present (Disc) loop
8190 Append_Elmt (Discriminal (Disc), Discr_Map);
8191 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
8192 Next_Discriminant (Disc);
8198 -- Fill in the component declarations
8200 -- Add components for entry families. For each entry family, create an
8201 -- anonymous type declaration with the same size, and analyze the type.
8203 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
8205 -- Prepend the _Object field with the right type to the component list.
8206 -- We need to compute the number of entries, and in some cases the
8207 -- number of Attach_Handler pragmas.
8211 Num_Attach_Handler : Int := 0;
8212 Protection_Subtype : Node_Id;
8213 Entry_Count_Expr : constant Node_Id :=
8214 Build_Entry_Count_Expression
8215 (Prot_Typ, Cdecls, Loc);
8218 -- Could this be simplified using Corresponding_Runtime_Package???
8220 if Has_Attach_Handler (Prot_Typ) then
8221 Ritem := First_Rep_Item (Prot_Typ);
8222 while Present (Ritem) loop
8223 if Nkind (Ritem) = N_Pragma
8224 and then Pragma_Name (Ritem) = Name_Attach_Handler
8226 Num_Attach_Handler := Num_Attach_Handler + 1;
8229 Next_Rep_Item (Ritem);
8232 if Restricted_Profile then
8233 if Has_Entries (Prot_Typ) then
8234 Protection_Subtype :=
8235 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8237 Protection_Subtype :=
8238 New_Reference_To (RTE (RE_Protection), Loc);
8241 Protection_Subtype :=
8242 Make_Subtype_Indication
8246 (RTE (RE_Static_Interrupt_Protection), Loc),
8248 Make_Index_Or_Discriminant_Constraint (
8250 Constraints => New_List (
8252 Make_Integer_Literal (Loc, Num_Attach_Handler))));
8255 elsif Has_Interrupt_Handler (Prot_Typ)
8256 and then not Restriction_Active (No_Dynamic_Attachment)
8258 Protection_Subtype :=
8259 Make_Subtype_Indication (
8261 Subtype_Mark => New_Reference_To
8262 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
8264 Make_Index_Or_Discriminant_Constraint (
8266 Constraints => New_List (Entry_Count_Expr)));
8268 -- Type has explicit entries or generated primitive entry wrappers
8270 elsif Has_Entries (Prot_Typ)
8271 or else (Ada_Version >= Ada_2005
8272 and then Present (Interface_List (N)))
8274 case Corresponding_Runtime_Package (Prot_Typ) is
8275 when System_Tasking_Protected_Objects_Entries =>
8276 Protection_Subtype :=
8277 Make_Subtype_Indication (Loc,
8279 New_Reference_To (RTE (RE_Protection_Entries), Loc),
8281 Make_Index_Or_Discriminant_Constraint (
8283 Constraints => New_List (Entry_Count_Expr)));
8285 when System_Tasking_Protected_Objects_Single_Entry =>
8286 Protection_Subtype :=
8287 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8290 raise Program_Error;
8294 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
8298 Make_Component_Declaration (Loc,
8299 Defining_Identifier =>
8300 Make_Defining_Identifier (Loc, Name_uObject),
8301 Component_Definition =>
8302 Make_Component_Definition (Loc,
8303 Aliased_Present => True,
8304 Subtype_Indication => Protection_Subtype));
8307 pragma Assert (Present (Pdef));
8309 -- Add private field components
8311 if Present (Private_Declarations (Pdef)) then
8312 Priv := First (Private_Declarations (Pdef));
8314 while Present (Priv) loop
8316 if Nkind (Priv) = N_Component_Declaration then
8317 if not Static_Component_Size (Defining_Identifier (Priv)) then
8319 -- When compiling for a restricted profile, the private
8320 -- components must have a static size. If not, this is an
8321 -- error for a single protected declaration, and rates a
8322 -- warning on a protected type declaration.
8324 if not Comes_From_Source (Prot_Typ) then
8325 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8327 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8328 Error_Msg_N ("component has non-static size?", Priv);
8330 ("\creation of protected object of type& will violate"
8331 & " restriction No_Implicit_Heap_Allocations?",
8336 -- The component definition consists of a subtype indication,
8337 -- or (in Ada 2005) an access definition. Make a copy of the
8338 -- proper definition.
8341 Old_Comp : constant Node_Id := Component_Definition (Priv);
8342 Oent : constant Entity_Id := Defining_Identifier (Priv);
8344 Nent : constant Entity_Id :=
8345 Make_Defining_Identifier (Sloc (Oent),
8346 Chars => Chars (Oent));
8349 if Present (Subtype_Indication (Old_Comp)) then
8351 Make_Component_Definition (Sloc (Oent),
8352 Aliased_Present => False,
8353 Subtype_Indication =>
8354 New_Copy_Tree (Subtype_Indication (Old_Comp),
8358 Make_Component_Definition (Sloc (Oent),
8359 Aliased_Present => False,
8360 Access_Definition =>
8361 New_Copy_Tree (Access_Definition (Old_Comp),
8366 Make_Component_Declaration (Loc,
8367 Defining_Identifier => Nent,
8368 Component_Definition => New_Comp,
8369 Expression => Expression (Priv));
8371 Set_Has_Per_Object_Constraint (Nent,
8372 Has_Per_Object_Constraint (Oent));
8374 Append_To (Cdecls, New_Priv);
8377 elsif Nkind (Priv) = N_Subprogram_Declaration then
8379 -- Make the unprotected version of the subprogram available
8380 -- for expansion of intra object calls. There is need for
8381 -- a protected version only if the subprogram is an interrupt
8382 -- handler, otherwise this operation can only be called from
8386 Make_Subprogram_Declaration (Loc,
8388 Build_Protected_Sub_Specification
8389 (Priv, Prot_Typ, Unprotected_Mode));
8391 Insert_After (Current_Node, Sub);
8394 Set_Protected_Body_Subprogram
8395 (Defining_Unit_Name (Specification (Priv)),
8396 Defining_Unit_Name (Specification (Sub)));
8397 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8398 Current_Node := Sub;
8401 Make_Subprogram_Declaration (Loc,
8403 Build_Protected_Sub_Specification
8404 (Priv, Prot_Typ, Protected_Mode));
8406 Insert_After (Current_Node, Sub);
8408 Current_Node := Sub;
8410 if Is_Interrupt_Handler
8411 (Defining_Unit_Name (Specification (Priv)))
8413 if not Restricted_Profile then
8423 -- Put the _Object component after the private component so that it
8424 -- be finalized early as required by 9.4 (20)
8426 Append_To (Cdecls, Object_Comp);
8428 Insert_After (Current_Node, Rec_Decl);
8429 Current_Node := Rec_Decl;
8431 -- Analyze the record declaration immediately after construction,
8432 -- because the initialization procedure is needed for single object
8433 -- declarations before the next entity is analyzed (the freeze call
8434 -- that generates this initialization procedure is found below).
8436 Analyze (Rec_Decl, Suppress => All_Checks);
8438 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8439 -- the corresponding record is frozen. If any wrappers are generated,
8440 -- Current_Node is updated accordingly.
8442 if Ada_Version >= Ada_2005 then
8443 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8446 -- Collect pointers to entry bodies and their barriers, to be placed
8447 -- in the Entry_Bodies_Array for the type. For each entry/family we
8448 -- add an expression to the aggregate which is the initial value of
8449 -- this array. The array is declared after all protected subprograms.
8451 if Has_Entries (Prot_Typ) then
8452 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8454 Entries_Aggr := Empty;
8457 -- Build two new procedure specifications for each protected subprogram;
8458 -- one to call from outside the object and one to call from inside.
8459 -- Build a barrier function and an entry body action procedure
8460 -- specification for each protected entry. Initialize the entry body
8461 -- array. If subprogram is flagged as eliminated, do not generate any
8462 -- internal operations.
8466 Comp := First (Visible_Declarations (Pdef));
8468 while Present (Comp) loop
8469 if Nkind (Comp) = N_Subprogram_Declaration then
8471 Make_Subprogram_Declaration (Loc,
8473 Build_Protected_Sub_Specification
8474 (Comp, Prot_Typ, Unprotected_Mode));
8476 Insert_After (Current_Node, Sub);
8479 Set_Protected_Body_Subprogram
8480 (Defining_Unit_Name (Specification (Comp)),
8481 Defining_Unit_Name (Specification (Sub)));
8482 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8484 -- Make the protected version of the subprogram available for
8485 -- expansion of external calls.
8487 Current_Node := Sub;
8490 Make_Subprogram_Declaration (Loc,
8492 Build_Protected_Sub_Specification
8493 (Comp, Prot_Typ, Protected_Mode));
8495 Insert_After (Current_Node, Sub);
8498 Current_Node := Sub;
8500 -- Generate an overriding primitive operation specification for
8501 -- this subprogram if the protected type implements an interface.
8503 if Ada_Version >= Ada_2005
8505 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8508 Make_Subprogram_Declaration (Loc,
8510 Build_Protected_Sub_Specification
8511 (Comp, Prot_Typ, Dispatching_Mode));
8513 Insert_After (Current_Node, Sub);
8516 Current_Node := Sub;
8519 -- If a pragma Interrupt_Handler applies, build and add a call to
8520 -- Register_Interrupt_Handler to the freezing actions of the
8521 -- protected version (Current_Node) of the subprogram:
8523 -- system.interrupts.register_interrupt_handler
8524 -- (prot_procP'address);
8526 if not Restricted_Profile
8527 and then Is_Interrupt_Handler
8528 (Defining_Unit_Name (Specification (Comp)))
8533 elsif Nkind (Comp) = N_Entry_Declaration then
8534 E_Count := E_Count + 1;
8535 Comp_Id := Defining_Identifier (Comp);
8538 Make_Defining_Identifier (Loc,
8539 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8541 Make_Subprogram_Declaration (Loc,
8543 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8545 Insert_After (Current_Node, Sub);
8548 -- Build wrapper procedure for pre/postconditions
8550 Build_PPC_Wrapper (Comp_Id, N);
8552 Set_Protected_Body_Subprogram
8553 (Defining_Identifier (Comp),
8554 Defining_Unit_Name (Specification (Sub)));
8556 Current_Node := Sub;
8559 Make_Defining_Identifier (Loc,
8560 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8562 Make_Subprogram_Declaration (Loc,
8564 Build_Barrier_Function_Specification (Loc, Bdef));
8566 Insert_After (Current_Node, Sub);
8568 Set_Protected_Body_Subprogram (Bdef, Bdef);
8569 Set_Barrier_Function (Comp_Id, Bdef);
8570 Set_Scope (Bdef, Scope (Comp_Id));
8571 Current_Node := Sub;
8573 -- Collect pointers to the protected subprogram and the barrier
8574 -- of the current entry, for insertion into Entry_Bodies_Array.
8577 Make_Aggregate (Loc,
8578 Expressions => New_List (
8579 Make_Attribute_Reference (Loc,
8580 Prefix => New_Reference_To (Bdef, Loc),
8581 Attribute_Name => Name_Unrestricted_Access),
8582 Make_Attribute_Reference (Loc,
8583 Prefix => New_Reference_To (Edef, Loc),
8584 Attribute_Name => Name_Unrestricted_Access))),
8585 Expressions (Entries_Aggr));
8592 -- If there are some private entry declarations, expand it as if they
8593 -- were visible entries.
8595 if Present (Private_Declarations (Pdef)) then
8596 Comp := First (Private_Declarations (Pdef));
8597 while Present (Comp) loop
8598 if Nkind (Comp) = N_Entry_Declaration then
8599 E_Count := E_Count + 1;
8600 Comp_Id := Defining_Identifier (Comp);
8603 Make_Defining_Identifier (Loc,
8604 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8606 Make_Subprogram_Declaration (Loc,
8608 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8610 Insert_After (Current_Node, Sub);
8613 Set_Protected_Body_Subprogram
8614 (Defining_Identifier (Comp),
8615 Defining_Unit_Name (Specification (Sub)));
8617 Current_Node := Sub;
8620 Make_Defining_Identifier (Loc,
8621 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8624 Make_Subprogram_Declaration (Loc,
8626 Build_Barrier_Function_Specification (Loc, Bdef));
8628 Insert_After (Current_Node, Sub);
8630 Set_Protected_Body_Subprogram (Bdef, Bdef);
8631 Set_Barrier_Function (Comp_Id, Bdef);
8632 Set_Scope (Bdef, Scope (Comp_Id));
8633 Current_Node := Sub;
8635 -- Collect pointers to the protected subprogram and the barrier
8636 -- of the current entry, for insertion into Entry_Bodies_Array.
8638 Append_To (Expressions (Entries_Aggr),
8639 Make_Aggregate (Loc,
8640 Expressions => New_List (
8641 Make_Attribute_Reference (Loc,
8642 Prefix => New_Reference_To (Bdef, Loc),
8643 Attribute_Name => Name_Unrestricted_Access),
8644 Make_Attribute_Reference (Loc,
8645 Prefix => New_Reference_To (Edef, Loc),
8646 Attribute_Name => Name_Unrestricted_Access))));
8653 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8654 -- all protected subprograms have been collected.
8656 if Has_Entries (Prot_Typ) then
8658 Make_Defining_Identifier (Sloc (Prot_Typ),
8659 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8661 case Corresponding_Runtime_Package (Prot_Typ) is
8662 when System_Tasking_Protected_Objects_Entries =>
8663 Body_Arr := Make_Object_Declaration (Loc,
8664 Defining_Identifier => Body_Id,
8665 Aliased_Present => True,
8666 Object_Definition =>
8667 Make_Subtype_Indication (Loc,
8668 Subtype_Mark => New_Reference_To (
8669 RTE (RE_Protected_Entry_Body_Array), Loc),
8671 Make_Index_Or_Discriminant_Constraint (Loc,
8672 Constraints => New_List (
8674 Make_Integer_Literal (Loc, 1),
8675 Make_Integer_Literal (Loc, E_Count))))),
8676 Expression => Entries_Aggr);
8678 when System_Tasking_Protected_Objects_Single_Entry =>
8679 Body_Arr := Make_Object_Declaration (Loc,
8680 Defining_Identifier => Body_Id,
8681 Aliased_Present => True,
8682 Object_Definition => New_Reference_To
8683 (RTE (RE_Entry_Body), Loc),
8685 Make_Aggregate (Loc,
8686 Expressions => New_List (
8687 Make_Attribute_Reference (Loc,
8688 Prefix => New_Reference_To (Bdef, Loc),
8689 Attribute_Name => Name_Unrestricted_Access),
8690 Make_Attribute_Reference (Loc,
8691 Prefix => New_Reference_To (Edef, Loc),
8692 Attribute_Name => Name_Unrestricted_Access))));
8695 raise Program_Error;
8698 -- A pointer to this array will be placed in the corresponding record
8699 -- by its initialization procedure so this needs to be analyzed here.
8701 Insert_After (Current_Node, Body_Arr);
8702 Current_Node := Body_Arr;
8705 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8707 -- Finally, build the function that maps an entry index into the
8708 -- corresponding body. A pointer to this function is placed in each
8709 -- object of the type. Except for a ravenscar-like profile (no abort,
8710 -- no entry queue, 1 entry)
8712 if Corresponding_Runtime_Package (Prot_Typ) =
8713 System_Tasking_Protected_Objects_Entries
8716 Make_Subprogram_Declaration (Loc,
8717 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8718 Insert_After (Current_Node, Sub);
8722 end Expand_N_Protected_Type_Declaration;
8724 --------------------------------
8725 -- Expand_N_Requeue_Statement --
8726 --------------------------------
8728 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8729 -- operations, depending on the source and destination (task or protected
8730 -- object). A dispatching requeue statement is expanded into a call to the
8731 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8732 -- jump around the remainder of processing for the original entry and, if
8733 -- the destination is (different) protected object, to attempt to service
8734 -- it. The following illustrates the various cases:
8737 -- (O : System.Address;
8738 -- P : System.Address;
8739 -- E : Protected_Entry_Index)
8741 -- <discriminant renamings>
8742 -- <private object renamings>
8743 -- type poVP is access poV;
8744 -- _object : ptVP := ptVP!(O);
8748 -- <start of statement sequence for entry>
8750 -- -- Requeue from one protected entry body to another protected
8753 -- Requeue_Protected_Entry (
8754 -- _object._object'Access,
8755 -- new._object'Access,
8760 -- <some more of the statement sequence for entry>
8762 -- -- Requeue from an entry body to a task entry
8764 -- Requeue_Protected_To_Task_Entry (
8770 -- <rest of statement sequence for entry>
8771 -- Complete_Entry_Body (_object._object);
8774 -- when all others =>
8775 -- Exceptional_Complete_Entry_Body (
8776 -- _object._object, Get_GNAT_Exception);
8780 -- Requeue of a task entry call to a task entry
8782 -- Accept_Call (E, Ann);
8783 -- <start of statement sequence for accept statement>
8784 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8786 -- <rest of statement sequence for accept statement>
8788 -- Complete_Rendezvous;
8791 -- when all others =>
8792 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8794 -- Requeue of a task entry call to a protected entry
8796 -- Accept_Call (E, Ann);
8797 -- <start of statement sequence for accept statement>
8798 -- Requeue_Task_To_Protected_Entry (
8799 -- new._object'Access,
8804 -- <rest of statement sequence for accept statement>
8806 -- Complete_Rendezvous;
8809 -- when all others =>
8810 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8812 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8813 -- marked by pragma Implemented (XXX, By_Entry).
8815 -- The requeue is inside a protected entry:
8818 -- (O : System.Address;
8819 -- P : System.Address;
8820 -- E : Protected_Entry_Index)
8822 -- <discriminant renamings>
8823 -- <private object renamings>
8824 -- type poVP is access poV;
8825 -- _object : ptVP := ptVP!(O);
8829 -- <start of statement sequence for entry>
8832 -- (<interface class-wide object>,
8835 -- Ada.Tags.Get_Offset_Index
8837 -- <interface dispatch table index of target entry>),
8841 -- <rest of statement sequence for entry>
8842 -- Complete_Entry_Body (_object._object);
8845 -- when all others =>
8846 -- Exceptional_Complete_Entry_Body (
8847 -- _object._object, Get_GNAT_Exception);
8851 -- The requeue is inside a task entry:
8853 -- Accept_Call (E, Ann);
8854 -- <start of statement sequence for accept statement>
8856 -- (<interface class-wide object>,
8859 -- Ada.Tags.Get_Offset_Index
8861 -- <interface dispatch table index of target entrt>),
8865 -- <rest of statement sequence for accept statement>
8867 -- Complete_Rendezvous;
8870 -- when all others =>
8871 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8873 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8874 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8875 -- statement is replaced by a dispatching call with actual parameters taken
8876 -- from the inner-most accept statement or entry body.
8878 -- Target.Primitive (Param1, ..., ParamN);
8880 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8881 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
8885 -- S : constant Offset_Index :=
8886 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8887 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8890 -- if C = POK_Protected_Entry
8891 -- or else C = POK_Task_Entry
8893 -- <statements for dispatching requeue>
8895 -- elsif C = POK_Protected_Procedure then
8896 -- <dispatching call equivalent>
8899 -- raise Program_Error;
8903 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8904 Loc : constant Source_Ptr := Sloc (N);
8905 Conc_Typ : Entity_Id;
8909 Old_Typ : Entity_Id;
8911 function Build_Dispatching_Call_Equivalent return Node_Id;
8912 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8913 -- the form Concval.Ename. It is statically known that Ename is allowed
8914 -- to be implemented by a protected procedure. Create a dispatching call
8915 -- equivalent of Concval.Ename taking the actual parameters from the
8916 -- inner-most accept statement or entry body.
8918 function Build_Dispatching_Requeue return Node_Id;
8919 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8920 -- the form Concval.Ename. It is statically known that Ename is allowed
8921 -- to be implemented by a protected or a task entry. Create a call to
8922 -- primitive _Disp_Requeue which handles the low-level actions.
8924 function Build_Dispatching_Requeue_To_Any return Node_Id;
8925 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8926 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8927 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
8928 -- determines at runtime whether Ename denotes an entry or a procedure
8929 -- and perform the appropriate kind of dispatching select.
8931 function Build_Normal_Requeue return Node_Id;
8932 -- N denotes a non-dispatching requeue statement to either a task or a
8933 -- protected entry. Build the appropriate runtime call to perform the
8936 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8937 -- For a protected entry, create a return statement to skip the rest of
8938 -- the entry body. Otherwise, create a goto statement to skip the rest
8939 -- of a task accept statement. The lookup for the enclosing entry body
8940 -- or accept statement starts from Search.
8942 ---------------------------------------
8943 -- Build_Dispatching_Call_Equivalent --
8944 ---------------------------------------
8946 function Build_Dispatching_Call_Equivalent return Node_Id is
8947 Call_Ent : constant Entity_Id := Entity (Ename);
8948 Obj : constant Node_Id := Original_Node (Concval);
8955 -- Climb the parent chain looking for the inner-most entry body or
8956 -- accept statement.
8959 while Present (Acc_Ent)
8960 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8963 Acc_Ent := Parent (Acc_Ent);
8966 -- A requeue statement should be housed inside an entry body or an
8967 -- accept statement at some level. If this is not the case, then the
8968 -- tree is malformed.
8970 pragma Assert (Present (Acc_Ent));
8972 -- Recover the list of formal parameters
8974 if Nkind (Acc_Ent) = N_Entry_Body then
8975 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8978 Formals := Parameter_Specifications (Acc_Ent);
8980 -- Create the actual parameters for the dispatching call. These are
8981 -- simply copies of the entry body or accept statement formals in the
8982 -- same order as they appear.
8986 if Present (Formals) then
8987 Actuals := New_List;
8988 Formal := First (Formals);
8989 while Present (Formal) loop
8991 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8997 -- Obj.Call_Ent (Actuals);
9000 Make_Procedure_Call_Statement (Loc,
9002 Make_Selected_Component (Loc,
9003 Prefix => Make_Identifier (Loc, Chars (Obj)),
9004 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
9006 Parameter_Associations => Actuals);
9007 end Build_Dispatching_Call_Equivalent;
9009 -------------------------------
9010 -- Build_Dispatching_Requeue --
9011 -------------------------------
9013 function Build_Dispatching_Requeue return Node_Id is
9014 Params : constant List_Id := New_List;
9017 -- Process the "with abort" parameter
9020 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
9022 -- Process the entry wrapper's position in the primary dispatch
9023 -- table parameter. Generate:
9025 -- Ada.Tags.Get_Entry_Index
9026 -- (T => To_Tag_Ptr (Obj'Address).all,
9028 -- Ada.Tags.Get_Offset_Index
9029 -- (Ada.Tags.Tag (Concval),
9030 -- <interface dispatch table position of Ename>));
9032 -- Note that Obj'Address is recursively expanded into a call to
9033 -- Base_Address (Obj).
9035 if Tagged_Type_Expansion then
9037 Make_Function_Call (Loc,
9038 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
9039 Parameter_Associations => New_List (
9041 Make_Explicit_Dereference (Loc,
9042 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
9043 Make_Attribute_Reference (Loc,
9044 Prefix => New_Copy_Tree (Concval),
9045 Attribute_Name => Name_Address))),
9047 Make_Function_Call (Loc,
9048 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
9049 Parameter_Associations => New_List (
9050 Unchecked_Convert_To (RTE (RE_Tag), Concval),
9051 Make_Integer_Literal (Loc,
9052 DT_Position (Entity (Ename))))))));
9058 Make_Function_Call (Loc,
9059 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
9060 Parameter_Associations => New_List (
9062 Make_Attribute_Reference (Loc,
9064 Attribute_Name => Name_Tag),
9066 Make_Function_Call (Loc,
9067 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
9069 Parameter_Associations => New_List (
9073 Make_Attribute_Reference (Loc,
9075 Attribute_Name => Name_Tag),
9079 Make_Attribute_Reference (Loc,
9080 Prefix => New_Reference_To (Etype (Concval), Loc),
9081 Attribute_Name => Name_Tag),
9085 Make_Integer_Literal (Loc,
9086 DT_Position (Entity (Ename))))))));
9089 -- Specific actuals for protected to XXX requeue
9091 if Is_Protected_Type (Old_Typ) then
9093 Make_Attribute_Reference (Loc, -- _object'Address
9095 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9096 Attribute_Name => Name_Address));
9098 Prepend_To (Params, -- True
9099 New_Reference_To (Standard_True, Loc));
9101 -- Specific actuals for task to XXX requeue
9104 pragma Assert (Is_Task_Type (Old_Typ));
9106 Prepend_To (Params, -- null
9107 New_Reference_To (RTE (RE_Null_Address), Loc));
9109 Prepend_To (Params, -- False
9110 New_Reference_To (Standard_False, Loc));
9113 -- Add the object parameter
9115 Prepend_To (Params, New_Copy_Tree (Concval));
9118 -- _Disp_Requeue (<Params>);
9120 -- Find entity for Disp_Requeue operation, which belongs to
9121 -- the type and may not be directly visible.
9128 Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
9129 while Present (Elmt) loop
9131 exit when Chars (Op) = Name_uDisp_Requeue;
9136 Make_Procedure_Call_Statement (Loc,
9137 Name => New_Occurrence_Of (Op, Loc),
9138 Parameter_Associations => Params);
9140 end Build_Dispatching_Requeue;
9142 --------------------------------------
9143 -- Build_Dispatching_Requeue_To_Any --
9144 --------------------------------------
9146 function Build_Dispatching_Requeue_To_Any return Node_Id is
9147 Call_Ent : constant Entity_Id := Entity (Ename);
9148 Obj : constant Node_Id := Original_Node (Concval);
9149 Skip : constant Node_Id := Build_Skip_Statement (N);
9159 -- Dispatch table slot processing, generate:
9162 S := Build_S (Loc, Decls);
9164 -- Call kind processing, generate:
9165 -- C : Ada.Tags.Prim_Op_Kind;
9167 C := Build_C (Loc, Decls);
9170 -- S := Ada.Tags.Get_Offset_Index
9171 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9173 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
9176 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9179 Make_Procedure_Call_Statement (Loc,
9182 Find_Prim_Op (Etype (Etype (Obj)),
9183 Name_uDisp_Get_Prim_Op_Kind),
9185 Parameter_Associations => New_List (
9186 New_Copy_Tree (Obj),
9187 New_Reference_To (S, Loc),
9188 New_Reference_To (C, Loc))));
9192 -- if C = POK_Protected_Entry
9193 -- or else C = POK_Task_Entry
9196 Make_If_Statement (Loc,
9202 New_Reference_To (C, Loc),
9204 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
9209 New_Reference_To (C, Loc),
9211 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
9213 -- Dispatching requeue equivalent
9215 Then_Statements => New_List (
9216 Build_Dispatching_Requeue,
9219 -- elsif C = POK_Protected_Procedure then
9221 Elsif_Parts => New_List (
9222 Make_Elsif_Part (Loc,
9226 New_Reference_To (C, Loc),
9229 RTE (RE_POK_Protected_Procedure), Loc)),
9231 -- Dispatching call equivalent
9233 Then_Statements => New_List (
9234 Build_Dispatching_Call_Equivalent))),
9237 -- raise Program_Error;
9240 Else_Statements => New_List (
9241 Make_Raise_Program_Error (Loc,
9242 Reason => PE_Explicit_Raise))));
9244 -- Wrap everything into a block
9247 Make_Block_Statement (Loc,
9248 Declarations => Decls,
9249 Handled_Statement_Sequence =>
9250 Make_Handled_Sequence_Of_Statements (Loc,
9251 Statements => Stmts));
9252 end Build_Dispatching_Requeue_To_Any;
9254 --------------------------
9255 -- Build_Normal_Requeue --
9256 --------------------------
9258 function Build_Normal_Requeue return Node_Id is
9259 Params : constant List_Id := New_List;
9264 -- Process the "with abort" parameter
9267 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
9269 -- Add the index expression to the parameters. It is common among all
9273 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
9275 if Is_Protected_Type (Old_Typ) then
9277 Self_Param : Node_Id;
9281 Make_Attribute_Reference (Loc,
9283 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9285 Name_Unchecked_Access);
9287 -- Protected to protected requeue
9289 if Is_Protected_Type (Conc_Typ) then
9292 RTE (RE_Requeue_Protected_Entry), Loc);
9295 Make_Attribute_Reference (Loc,
9297 Concurrent_Ref (Concval),
9299 Name_Unchecked_Access);
9301 -- Protected to task requeue
9303 else pragma Assert (Is_Task_Type (Conc_Typ));
9306 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
9308 Param := Concurrent_Ref (Concval);
9311 Prepend_To (Params, Param);
9312 Prepend_To (Params, Self_Param);
9315 else pragma Assert (Is_Task_Type (Old_Typ));
9317 -- Task to protected requeue
9319 if Is_Protected_Type (Conc_Typ) then
9322 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
9325 Make_Attribute_Reference (Loc,
9327 Concurrent_Ref (Concval),
9329 Name_Unchecked_Access);
9331 -- Task to task requeue
9333 else pragma Assert (Is_Task_Type (Conc_Typ));
9335 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
9337 Param := Concurrent_Ref (Concval);
9340 Prepend_To (Params, Param);
9344 Make_Procedure_Call_Statement (Loc,
9346 Parameter_Associations => Params);
9347 end Build_Normal_Requeue;
9349 --------------------------
9350 -- Build_Skip_Statement --
9351 --------------------------
9353 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
9354 Skip_Stmt : Node_Id;
9357 -- Build a return statement to skip the rest of the entire body
9359 if Is_Protected_Type (Old_Typ) then
9360 Skip_Stmt := Make_Simple_Return_Statement (Loc);
9362 -- If the requeue is within a task, find the end label of the
9363 -- enclosing accept statement and create a goto statement to it.
9371 -- Climb the parent chain looking for the enclosing accept
9374 Acc := Parent (Search);
9376 and then Nkind (Acc) /= N_Accept_Statement
9378 Acc := Parent (Acc);
9381 -- The last statement is the second label used for completing
9382 -- the rendezvous the usual way. The label we are looking for
9383 -- is right before it.
9386 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
9388 pragma Assert (Nkind (Label) = N_Label);
9390 -- Generate a goto statement to skip the rest of the accept
9393 Make_Goto_Statement (Loc,
9395 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9399 Set_Analyzed (Skip_Stmt);
9402 end Build_Skip_Statement;
9404 -- Start of processing for Expand_N_Requeue_Statement
9407 -- Extract the components of the entry call
9409 Extract_Entry (N, Concval, Ename, Index);
9410 Conc_Typ := Etype (Concval);
9412 -- If the prefix is an access to class-wide type, dereference to get
9413 -- object and entry type.
9415 if Is_Access_Type (Conc_Typ) then
9416 Conc_Typ := Designated_Type (Conc_Typ);
9418 Make_Explicit_Dereference (Loc, Relocate_Node (Concval)));
9419 Analyze_And_Resolve (Concval, Conc_Typ);
9422 -- Examine the scope stack in order to find nearest enclosing protected
9423 -- or task type. This will constitute our invocation source.
9425 Old_Typ := Current_Scope;
9426 while Present (Old_Typ)
9427 and then not Is_Protected_Type (Old_Typ)
9428 and then not Is_Task_Type (Old_Typ)
9430 Old_Typ := Scope (Old_Typ);
9433 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9434 -- Concval.Ename where the type of Concval is class-wide concurrent
9437 if Ada_Version >= Ada_2012
9438 and then Present (Concval)
9439 and then Is_Class_Wide_Type (Conc_Typ)
9440 and then Is_Concurrent_Interface (Conc_Typ)
9443 Has_Impl : Boolean := False;
9444 Impl_Kind : Name_Id := No_Name;
9447 -- Check whether the Ename is flagged by pragma Implemented
9449 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9451 Impl_Kind := Implementation_Kind (Entity (Ename));
9454 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9455 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9458 and then Impl_Kind = Name_By_Entry
9460 Rewrite (N, Build_Dispatching_Requeue);
9462 Insert_After (N, Build_Skip_Statement (N));
9464 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9465 -- a protected procedure. In this case the requeue is transformed
9466 -- into a dispatching call.
9469 and then Impl_Kind = Name_By_Protected_Procedure
9471 Rewrite (N, Build_Dispatching_Call_Equivalent);
9474 -- The procedure_or_entry_NAME's implementation kind is either
9475 -- By_Any, Optional, or pragma Implemented was not applied at all.
9476 -- In this case a runtime test determines whether Ename denotes an
9477 -- entry or a protected procedure and performs the appropriate
9481 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9486 -- Processing for regular (non-dispatching) requeues
9489 Rewrite (N, Build_Normal_Requeue);
9491 Insert_After (N, Build_Skip_Statement (N));
9493 end Expand_N_Requeue_Statement;
9495 -------------------------------
9496 -- Expand_N_Selective_Accept --
9497 -------------------------------
9499 procedure Expand_N_Selective_Accept (N : Node_Id) is
9500 Loc : constant Source_Ptr := Sloc (N);
9501 Alts : constant List_Id := Select_Alternatives (N);
9503 -- Note: in the below declarations a lot of new lists are allocated
9504 -- unconditionally which may well not end up being used. That's
9505 -- not a good idea since it wastes space gratuitously ???
9507 Accept_Case : List_Id;
9508 Accept_List : constant List_Id := New_List;
9511 Alt_List : constant List_Id := New_List;
9512 Alt_Stats : List_Id;
9513 Ann : Entity_Id := Empty;
9516 Check_Guard : Boolean := True;
9518 Decls : constant List_Id := New_List;
9519 Stats : constant List_Id := New_List;
9520 Body_List : constant List_Id := New_List;
9521 Trailing_List : constant List_Id := New_List;
9524 Else_Present : Boolean := False;
9525 Terminate_Alt : Node_Id := Empty;
9526 Select_Mode : Node_Id;
9528 Delay_Case : List_Id;
9529 Delay_Count : Integer := 0;
9530 Delay_Val : Entity_Id;
9531 Delay_Index : Entity_Id;
9532 Delay_Min : Entity_Id;
9533 Delay_Num : Int := 1;
9534 Delay_Alt_List : List_Id := New_List;
9535 Delay_List : constant List_Id := New_List;
9539 First_Delay : Boolean := True;
9540 Guard_Open : Entity_Id;
9546 Num_Accept : Nat := 0;
9549 Time_Type : Entity_Id;
9551 Select_Call : Node_Id;
9553 Qnam : constant Entity_Id :=
9554 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9556 Xnam : constant Entity_Id :=
9557 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9559 -----------------------
9560 -- Local subprograms --
9561 -----------------------
9563 function Accept_Or_Raise return List_Id;
9564 -- For the rare case where delay alternatives all have guards, and
9565 -- all of them are closed, it is still possible that there were open
9566 -- accept alternatives with no callers. We must reexamine the
9567 -- Accept_List, and execute a selective wait with no else if some
9568 -- accept is open. If none, we raise program_error.
9570 procedure Add_Accept (Alt : Node_Id);
9571 -- Process a single accept statement in a select alternative. Build
9572 -- procedure for body of accept, and add entry to dispatch table with
9573 -- expression for guard, in preparation for call to run time select.
9575 function Make_And_Declare_Label (Num : Int) return Node_Id;
9576 -- Manufacture a label using Num as a serial number and declare it.
9577 -- The declaration is appended to Decls. The label marks the trailing
9578 -- statements of an accept or delay alternative.
9580 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9581 -- Build call to Selective_Wait runtime routine
9583 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9584 -- Add code to compare value of delay with previous values, and
9585 -- generate case entry for trailing statements.
9587 procedure Process_Accept_Alternative
9591 -- Add code to call corresponding procedure, and branch to
9592 -- trailing statements, if any.
9594 ---------------------
9595 -- Accept_Or_Raise --
9596 ---------------------
9598 function Accept_Or_Raise return List_Id is
9601 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9604 -- We generate the following:
9606 -- for J in q'range loop
9607 -- if q(J).S /=null_task_entry then
9608 -- selective_wait (simple_mode,...);
9614 -- if no rendez_vous then
9615 -- raise program_error;
9618 -- Note that the code needs to know that the selector name
9619 -- in an Accept_Alternative is named S.
9621 Cond := Make_Op_Ne (Loc,
9623 Make_Selected_Component (Loc,
9625 Make_Indexed_Component (Loc,
9626 Prefix => New_Reference_To (Qnam, Loc),
9627 Expressions => New_List (New_Reference_To (J, Loc))),
9628 Selector_Name => Make_Identifier (Loc, Name_S)),
9630 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9633 Make_Implicit_Loop_Statement (N,
9634 Identifier => Empty,
9636 Make_Iteration_Scheme (Loc,
9637 Loop_Parameter_Specification =>
9638 Make_Loop_Parameter_Specification (Loc,
9639 Defining_Identifier => J,
9640 Discrete_Subtype_Definition =>
9641 Make_Attribute_Reference (Loc,
9642 Prefix => New_Reference_To (Qnam, Loc),
9643 Attribute_Name => Name_Range,
9644 Expressions => New_List (
9645 Make_Integer_Literal (Loc, 1))))),
9647 Statements => New_List (
9648 Make_Implicit_If_Statement (N,
9650 Then_Statements => New_List (
9652 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9653 Make_Exit_Statement (Loc))))));
9656 Make_Raise_Program_Error (Loc,
9657 Condition => Make_Op_Eq (Loc,
9658 Left_Opnd => New_Reference_To (Xnam, Loc),
9660 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9661 Reason => PE_All_Guards_Closed));
9664 end Accept_Or_Raise;
9670 procedure Add_Accept (Alt : Node_Id) is
9671 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9672 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9673 Eloc : constant Source_Ptr := Sloc (Ename);
9674 Eent : constant Entity_Id := Entity (Ename);
9675 Index : constant Node_Id := Entry_Index (Acc_Stm);
9676 Null_Body : Node_Id;
9677 Proc_Body : Node_Id;
9684 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9687 if Present (Condition (Alt)) then
9689 Make_Conditional_Expression (Eloc, New_List (
9691 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9692 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9695 Entry_Index_Expression
9696 (Eloc, Eent, Index, Scope (Eent));
9699 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9700 Null_Body := New_Reference_To (Standard_False, Eloc);
9702 if Abort_Allowed then
9703 Call := Make_Procedure_Call_Statement (Eloc,
9704 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9705 Insert_Before (First (Statements (Handled_Statement_Sequence (
9706 Accept_Statement (Alt)))), Call);
9711 Make_Defining_Identifier (Eloc,
9712 New_External_Name (Chars (Ename), 'A', Num_Accept));
9714 if Comes_From_Source (Alt) then
9715 Set_Debug_Info_Needed (PB_Ent);
9719 Make_Subprogram_Body (Eloc,
9721 Make_Procedure_Specification (Eloc,
9722 Defining_Unit_Name => PB_Ent),
9723 Declarations => Declarations (Acc_Stm),
9724 Handled_Statement_Sequence =>
9725 Build_Accept_Body (Accept_Statement (Alt)));
9727 -- During the analysis of the body of the accept statement, any
9728 -- zero cost exception handler records were collected in the
9729 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9730 -- This is where we move them to where they belong, namely the
9731 -- newly created procedure.
9733 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9734 Append (Proc_Body, Body_List);
9737 Null_Body := New_Reference_To (Standard_True, Eloc);
9739 -- if accept statement has declarations, insert above, given that
9740 -- we are not creating a body for the accept.
9742 if Present (Declarations (Acc_Stm)) then
9743 Insert_Actions (N, Declarations (Acc_Stm));
9747 Append_To (Accept_List,
9748 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9750 Num_Accept := Num_Accept + 1;
9753 ----------------------------
9754 -- Make_And_Declare_Label --
9755 ----------------------------
9757 function Make_And_Declare_Label (Num : Int) return Node_Id is
9761 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9763 Make_Label (Loc, Lab_Id);
9766 Make_Implicit_Label_Declaration (Loc,
9767 Defining_Identifier =>
9768 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9769 Label_Construct => Lab));
9772 end Make_And_Declare_Label;
9774 ----------------------
9775 -- Make_Select_Call --
9776 ----------------------
9778 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9779 Params : constant List_Id := New_List;
9783 Make_Attribute_Reference (Loc,
9784 Prefix => New_Reference_To (Qnam, Loc),
9785 Attribute_Name => Name_Unchecked_Access),
9787 Append (Select_Mode, Params);
9788 Append (New_Reference_To (Ann, Loc), Params);
9789 Append (New_Reference_To (Xnam, Loc), Params);
9792 Make_Procedure_Call_Statement (Loc,
9793 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9794 Parameter_Associations => Params);
9795 end Make_Select_Call;
9797 --------------------------------
9798 -- Process_Accept_Alternative --
9799 --------------------------------
9801 procedure Process_Accept_Alternative
9806 Choices : List_Id := No_List;
9807 Alt_Stats : List_Id;
9810 Adjust_Condition (Condition (Alt));
9811 Alt_Stats := No_List;
9813 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9814 Choices := New_List (
9815 Make_Integer_Literal (Loc, Index));
9817 Alt_Stats := New_List (
9818 Make_Procedure_Call_Statement (Sloc (Proc),
9819 Name => New_Reference_To (
9820 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9823 if Statements (Alt) /= Empty_List then
9825 if No (Alt_Stats) then
9827 -- Accept with no body, followed by trailing statements
9829 Choices := New_List (
9830 Make_Integer_Literal (Loc, Index));
9832 Alt_Stats := New_List;
9835 -- After the call, if any, branch to trailing statements. We
9836 -- create a label for each, as well as the corresponding label
9839 Lab := Make_And_Declare_Label (Index);
9840 Append_To (Alt_Stats,
9841 Make_Goto_Statement (Loc,
9842 Name => New_Copy (Identifier (Lab))));
9844 Append (Lab, Trailing_List);
9845 Append_List (Statements (Alt), Trailing_List);
9846 Append_To (Trailing_List,
9847 Make_Goto_Statement (Loc,
9848 Name => New_Copy (Identifier (End_Lab))));
9851 if Present (Alt_Stats) then
9853 -- Procedure call. and/or trailing statements
9855 Append_To (Alt_List,
9856 Make_Case_Statement_Alternative (Loc,
9857 Discrete_Choices => Choices,
9858 Statements => Alt_Stats));
9860 end Process_Accept_Alternative;
9862 -------------------------------
9863 -- Process_Delay_Alternative --
9864 -------------------------------
9866 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9869 Delay_Alt : List_Id;
9872 -- Deal with C/Fortran boolean as delay condition
9874 Adjust_Condition (Condition (Alt));
9876 -- Determine the smallest specified delay
9878 -- for each delay alternative generate:
9880 -- if guard-expression then
9881 -- Delay_Val := delay-expression;
9882 -- Guard_Open := True;
9883 -- if Delay_Val < Delay_Min then
9884 -- Delay_Min := Delay_Val;
9885 -- Delay_Index := Index;
9889 -- The enclosing if-statement is omitted if there is no guard
9894 First_Delay := False;
9896 Delay_Alt := New_List (
9897 Make_Assignment_Statement (Loc,
9898 Name => New_Reference_To (Delay_Min, Loc),
9899 Expression => Expression (Delay_Statement (Alt))));
9901 if Delay_Count > 1 then
9902 Append_To (Delay_Alt,
9903 Make_Assignment_Statement (Loc,
9904 Name => New_Reference_To (Delay_Index, Loc),
9905 Expression => Make_Integer_Literal (Loc, Index)));
9909 Delay_Alt := New_List (
9910 Make_Assignment_Statement (Loc,
9911 Name => New_Reference_To (Delay_Val, Loc),
9912 Expression => Expression (Delay_Statement (Alt))));
9914 if Time_Type = Standard_Duration then
9917 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9918 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9921 -- The scope of the time type must define a comparison
9922 -- operator. The scope itself may not be visible, so we
9923 -- construct a node with entity information to insure that
9924 -- semantic analysis can find the proper operator.
9927 Make_Function_Call (Loc,
9928 Name => Make_Selected_Component (Loc,
9929 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9931 Make_Operator_Symbol (Loc,
9932 Chars => Name_Op_Lt,
9933 Strval => No_String)),
9934 Parameter_Associations =>
9936 New_Reference_To (Delay_Val, Loc),
9937 New_Reference_To (Delay_Min, Loc)));
9939 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9942 Append_To (Delay_Alt,
9943 Make_Implicit_If_Statement (N,
9945 Then_Statements => New_List (
9946 Make_Assignment_Statement (Loc,
9947 Name => New_Reference_To (Delay_Min, Loc),
9948 Expression => New_Reference_To (Delay_Val, Loc)),
9950 Make_Assignment_Statement (Loc,
9951 Name => New_Reference_To (Delay_Index, Loc),
9952 Expression => Make_Integer_Literal (Loc, Index)))));
9956 Append_To (Delay_Alt,
9957 Make_Assignment_Statement (Loc,
9958 Name => New_Reference_To (Guard_Open, Loc),
9959 Expression => New_Reference_To (Standard_True, Loc)));
9962 if Present (Condition (Alt)) then
9963 Delay_Alt := New_List (
9964 Make_Implicit_If_Statement (N,
9965 Condition => Condition (Alt),
9966 Then_Statements => Delay_Alt));
9969 Append_List (Delay_Alt, Delay_List);
9971 -- If the delay alternative has a statement part, add choice to the
9972 -- case statements for delays.
9974 if Present (Statements (Alt)) then
9976 if Delay_Count = 1 then
9977 Append_List (Statements (Alt), Delay_Alt_List);
9980 Choices := New_List (
9981 Make_Integer_Literal (Loc, Index));
9983 Append_To (Delay_Alt_List,
9984 Make_Case_Statement_Alternative (Loc,
9985 Discrete_Choices => Choices,
9986 Statements => Statements (Alt)));
9989 elsif Delay_Count = 1 then
9991 -- If the single delay has no trailing statements, add a branch
9992 -- to the exit label to the selective wait.
9994 Delay_Alt_List := New_List (
9995 Make_Goto_Statement (Loc,
9996 Name => New_Copy (Identifier (End_Lab))));
9999 end Process_Delay_Alternative;
10001 -- Start of processing for Expand_N_Selective_Accept
10004 Process_Statements_For_Controlled_Objects (N);
10006 -- First insert some declarations before the select. The first is:
10010 -- This variable holds the parameters passed to the accept body. This
10011 -- declaration has already been inserted by the time we get here by
10012 -- a call to Expand_Accept_Declarations made from the semantics when
10013 -- processing the first accept statement contained in the select. We
10014 -- can find this entity as Accept_Address (E), where E is any of the
10015 -- entries references by contained accept statements.
10017 -- The first step is to scan the list of Selective_Accept_Statements
10018 -- to find this entity, and also count the number of accepts, and
10019 -- determine if terminated, delay or else is present:
10023 Alt := First (Alts);
10024 while Present (Alt) loop
10025 Process_Statements_For_Controlled_Objects (Alt);
10027 if Nkind (Alt) = N_Accept_Alternative then
10030 elsif Nkind (Alt) = N_Delay_Alternative then
10031 Delay_Count := Delay_Count + 1;
10033 -- If the delays are relative delays, the delay expressions have
10034 -- type Standard_Duration. Otherwise they must have some time type
10035 -- recognized by GNAT.
10037 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
10038 Time_Type := Standard_Duration;
10040 Time_Type := Etype (Expression (Delay_Statement (Alt)));
10042 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
10043 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
10048 "& is not a time type (RM 9.6(6))",
10049 Expression (Delay_Statement (Alt)), Time_Type);
10050 Time_Type := Standard_Duration;
10051 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
10055 if No (Condition (Alt)) then
10057 -- This guard will always be open
10059 Check_Guard := False;
10062 elsif Nkind (Alt) = N_Terminate_Alternative then
10063 Adjust_Condition (Condition (Alt));
10064 Terminate_Alt := Alt;
10067 Num_Alts := Num_Alts + 1;
10071 Else_Present := Present (Else_Statements (N));
10073 -- At the same time (see procedure Add_Accept) we build the accept list:
10075 -- Qnn : Accept_List (1 .. num-select) := (
10076 -- (null-body, entry-index),
10077 -- (null-body, entry-index),
10079 -- (null_body, entry-index));
10081 -- In the above declaration, null-body is True if the corresponding
10082 -- accept has no body, and false otherwise. The entry is either the
10083 -- entry index expression if there is no guard, or if a guard is
10084 -- present, then a conditional expression of the form:
10086 -- (if guard then entry-index else Null_Task_Entry)
10088 -- If a guard is statically known to be false, the entry can simply
10089 -- be omitted from the accept list.
10092 Make_Object_Declaration (Loc,
10093 Defining_Identifier => Qnam,
10094 Object_Definition =>
10095 New_Reference_To (RTE (RE_Accept_List), Loc),
10096 Aliased_Present => True,
10099 Make_Qualified_Expression (Loc,
10101 New_Reference_To (RTE (RE_Accept_List), Loc),
10103 Make_Aggregate (Loc, Expressions => Accept_List)));
10107 -- Then we declare the variable that holds the index for the accept
10108 -- that will be selected for service:
10110 -- Xnn : Select_Index;
10113 Make_Object_Declaration (Loc,
10114 Defining_Identifier => Xnam,
10115 Object_Definition =>
10116 New_Reference_To (RTE (RE_Select_Index), Loc),
10118 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10122 -- After this follow procedure declarations for each accept body
10124 -- procedure Pnn is
10129 -- where the ... are statements from the corresponding procedure body.
10130 -- No parameters are involved, since the parameters are passed via Ann
10131 -- and the parameter references have already been expanded to be direct
10132 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10133 -- any embedded tasking statements (which would normally be illegal in
10134 -- procedures), have been converted to calls to the tasking runtime so
10135 -- there is no problem in putting them into procedures.
10137 -- The original accept statement has been expanded into a block in
10138 -- the same fashion as for simple accepts (see Build_Accept_Body).
10140 -- Note: we don't really need to build these procedures for the case
10141 -- where no delay statement is present, but it is just as easy to
10142 -- build them unconditionally, and not significantly inefficient,
10143 -- since if they are short they will be inlined anyway.
10145 -- The procedure declarations have been assembled in Body_List
10147 -- If delays are present, we must compute the required delay.
10148 -- We first generate the declarations:
10150 -- Delay_Index : Boolean := 0;
10151 -- Delay_Min : Some_Time_Type.Time;
10152 -- Delay_Val : Some_Time_Type.Time;
10154 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10155 -- active delay that is actually chosen as the basis for the possible
10156 -- delay if an immediate rendez-vous is not possible.
10158 -- In the most common case there is a single delay statement, and this
10159 -- is handled specially.
10161 if Delay_Count > 0 then
10163 -- Generate the required declarations
10166 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
10168 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
10170 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
10173 Make_Object_Declaration (Loc,
10174 Defining_Identifier => Delay_Val,
10175 Object_Definition => New_Reference_To (Time_Type, Loc)));
10178 Make_Object_Declaration (Loc,
10179 Defining_Identifier => Delay_Index,
10180 Object_Definition => New_Reference_To (Standard_Integer, Loc),
10181 Expression => Make_Integer_Literal (Loc, 0)));
10184 Make_Object_Declaration (Loc,
10185 Defining_Identifier => Delay_Min,
10186 Object_Definition => New_Reference_To (Time_Type, Loc),
10188 Unchecked_Convert_To (Time_Type,
10189 Make_Attribute_Reference (Loc,
10191 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
10192 Attribute_Name => Name_Last))));
10194 -- Create Duration and Delay_Mode objects used for passing a delay
10197 D := Make_Temporary (Loc, 'D');
10198 M := Make_Temporary (Loc, 'M');
10204 -- Note that these values are defined in s-osprim.ads and must
10205 -- be kept in sync:
10207 -- Relative : constant := 0;
10208 -- Absolute_Calendar : constant := 1;
10209 -- Absolute_RT : constant := 2;
10211 if Time_Type = Standard_Duration then
10212 Discr := Make_Integer_Literal (Loc, 0);
10214 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10215 Discr := Make_Integer_Literal (Loc, 1);
10219 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10220 Discr := Make_Integer_Literal (Loc, 2);
10224 Make_Object_Declaration (Loc,
10225 Defining_Identifier => D,
10226 Object_Definition =>
10227 New_Reference_To (Standard_Duration, Loc)));
10230 Make_Object_Declaration (Loc,
10231 Defining_Identifier => M,
10232 Object_Definition =>
10233 New_Reference_To (Standard_Integer, Loc),
10234 Expression => Discr));
10237 if Check_Guard then
10239 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
10242 Make_Object_Declaration (Loc,
10243 Defining_Identifier => Guard_Open,
10244 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10245 Expression => New_Reference_To (Standard_False, Loc)));
10248 -- Delay_Count is zero, don't need M and D set (suppress warning)
10255 if Present (Terminate_Alt) then
10257 -- If the terminate alternative guard is False, use
10258 -- Simple_Mode; otherwise use Terminate_Mode.
10260 if Present (Condition (Terminate_Alt)) then
10261 Select_Mode := Make_Conditional_Expression (Loc,
10262 New_List (Condition (Terminate_Alt),
10263 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
10264 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
10266 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
10269 elsif Else_Present or Delay_Count > 0 then
10270 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
10273 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
10276 Select_Call := Make_Select_Call (Select_Mode);
10277 Append (Select_Call, Stats);
10279 -- Now generate code to act on the result. There is an entry
10280 -- in this case for each accept statement with a non-null body,
10281 -- followed by a branch to the statements that follow the Accept.
10282 -- In the absence of delay alternatives, we generate:
10285 -- when No_Rendezvous => -- omitted if simple mode
10300 -- Lab0: Else_Statements;
10303 -- Lab1: Trailing_Statements1;
10306 -- Lab2: Trailing_Statements2;
10311 -- Generate label for common exit
10313 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
10315 -- First entry is the default case, when no rendezvous is possible
10317 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10319 if Else_Present then
10321 -- If no rendezvous is possible, the else part is executed
10323 Lab := Make_And_Declare_Label (0);
10324 Alt_Stats := New_List (
10325 Make_Goto_Statement (Loc,
10326 Name => New_Copy (Identifier (Lab))));
10328 Append (Lab, Trailing_List);
10329 Append_List (Else_Statements (N), Trailing_List);
10330 Append_To (Trailing_List,
10331 Make_Goto_Statement (Loc,
10332 Name => New_Copy (Identifier (End_Lab))));
10334 Alt_Stats := New_List (
10335 Make_Goto_Statement (Loc,
10336 Name => New_Copy (Identifier (End_Lab))));
10339 Append_To (Alt_List,
10340 Make_Case_Statement_Alternative (Loc,
10341 Discrete_Choices => Choices,
10342 Statements => Alt_Stats));
10344 -- We make use of the fact that Accept_Index is an integer type, and
10345 -- generate successive literals for entries for each accept. Only those
10346 -- for which there is a body or trailing statements get a case entry.
10348 Alt := First (Select_Alternatives (N));
10349 Proc := First (Body_List);
10350 while Present (Alt) loop
10352 if Nkind (Alt) = N_Accept_Alternative then
10353 Process_Accept_Alternative (Alt, Index, Proc);
10354 Index := Index + 1;
10357 (Handled_Statement_Sequence (Accept_Statement (Alt)))
10362 elsif Nkind (Alt) = N_Delay_Alternative then
10363 Process_Delay_Alternative (Alt, Delay_Num);
10364 Delay_Num := Delay_Num + 1;
10370 -- An others choice is always added to the main case, as well
10371 -- as the delay case (to satisfy the compiler).
10373 Append_To (Alt_List,
10374 Make_Case_Statement_Alternative (Loc,
10375 Discrete_Choices =>
10376 New_List (Make_Others_Choice (Loc)),
10378 New_List (Make_Goto_Statement (Loc,
10379 Name => New_Copy (Identifier (End_Lab))))));
10381 Accept_Case := New_List (
10382 Make_Case_Statement (Loc,
10383 Expression => New_Reference_To (Xnam, Loc),
10384 Alternatives => Alt_List));
10386 Append_List (Trailing_List, Accept_Case);
10387 Append (End_Lab, Accept_Case);
10388 Append_List (Body_List, Decls);
10390 -- Construct case statement for trailing statements of delay
10391 -- alternatives, if there are several of them.
10393 if Delay_Count > 1 then
10394 Append_To (Delay_Alt_List,
10395 Make_Case_Statement_Alternative (Loc,
10396 Discrete_Choices =>
10397 New_List (Make_Others_Choice (Loc)),
10399 New_List (Make_Null_Statement (Loc))));
10401 Delay_Case := New_List (
10402 Make_Case_Statement (Loc,
10403 Expression => New_Reference_To (Delay_Index, Loc),
10404 Alternatives => Delay_Alt_List));
10406 Delay_Case := Delay_Alt_List;
10409 -- If there are no delay alternatives, we append the case statement
10410 -- to the statement list.
10412 if Delay_Count = 0 then
10413 Append_List (Accept_Case, Stats);
10415 -- Delay alternatives present
10418 -- If delay alternatives are present we generate:
10420 -- find minimum delay.
10421 -- DX := minimum delay;
10422 -- M := <delay mode>;
10423 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10426 -- if X = No_Rendezvous then
10427 -- case statement for delay statements.
10429 -- case statement for accept alternatives.
10440 -- The type of the delay expression is known to be legal
10442 if Time_Type = Standard_Duration then
10443 Conv := New_Reference_To (Delay_Min, Loc);
10445 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10446 Conv := Make_Function_Call (Loc,
10447 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10448 New_List (New_Reference_To (Delay_Min, Loc)));
10452 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10454 Conv := Make_Function_Call (Loc,
10455 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10456 New_List (New_Reference_To (Delay_Min, Loc)));
10459 Stmt := Make_Assignment_Statement (Loc,
10460 Name => New_Reference_To (D, Loc),
10461 Expression => Conv);
10463 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10465 Parms := Parameter_Associations (Select_Call);
10466 Parm := First (Parms);
10468 while Present (Parm)
10469 and then Parm /= Select_Mode
10474 pragma Assert (Present (Parm));
10475 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10478 -- Prepare two new parameters of Duration and Delay_Mode type
10479 -- which represent the value and the mode of the minimum delay.
10482 Insert_After (Parm, New_Reference_To (M, Loc));
10483 Insert_After (Parm, New_Reference_To (D, Loc));
10485 -- Create a call to RTS
10487 Rewrite (Select_Call,
10488 Make_Procedure_Call_Statement (Loc,
10489 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10490 Parameter_Associations => Parms));
10492 -- This new call should follow the calculation of the minimum
10495 Insert_List_Before (Select_Call, Delay_List);
10497 if Check_Guard then
10499 Make_Implicit_If_Statement (N,
10500 Condition => New_Reference_To (Guard_Open, Loc),
10502 New_List (New_Copy_Tree (Stmt),
10503 New_Copy_Tree (Select_Call)),
10504 Else_Statements => Accept_Or_Raise);
10505 Rewrite (Select_Call, Stmt);
10507 Insert_Before (Select_Call, Stmt);
10511 Make_Implicit_If_Statement (N,
10512 Condition => Make_Op_Eq (Loc,
10513 Left_Opnd => New_Reference_To (Xnam, Loc),
10515 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10517 Then_Statements => Delay_Case,
10518 Else_Statements => Accept_Case);
10520 Append (Cases, Stats);
10524 -- Replace accept statement with appropriate block
10527 Make_Block_Statement (Loc,
10528 Declarations => Decls,
10529 Handled_Statement_Sequence =>
10530 Make_Handled_Sequence_Of_Statements (Loc,
10531 Statements => Stats));
10533 Rewrite (N, Block);
10536 -- Note: have to worry more about abort deferral in above code ???
10538 -- Final step is to unstack the Accept_Address entries for all accept
10539 -- statements appearing in accept alternatives in the select statement
10541 Alt := First (Alts);
10542 while Present (Alt) loop
10543 if Nkind (Alt) = N_Accept_Alternative then
10544 Remove_Last_Elmt (Accept_Address
10545 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10550 end Expand_N_Selective_Accept;
10552 --------------------------------------
10553 -- Expand_N_Single_Task_Declaration --
10554 --------------------------------------
10556 -- Single task declarations should never be present after semantic
10557 -- analysis, since we expect them to be replaced by a declaration of an
10558 -- anonymous task type, followed by a declaration of the task object. We
10559 -- include this routine to make sure that is happening!
10561 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10563 raise Program_Error;
10564 end Expand_N_Single_Task_Declaration;
10566 ------------------------
10567 -- Expand_N_Task_Body --
10568 ------------------------
10570 -- Given a task body
10572 -- task body tname is
10578 -- This expansion routine converts it into a procedure and sets the
10579 -- elaboration flag for the procedure to true, to represent the fact
10580 -- that the task body is now elaborated:
10582 -- procedure tnameB (_Task : access tnameV) is
10583 -- discriminal : dtype renames _Task.discriminant;
10585 -- procedure _clean is
10587 -- Abort_Defer.all;
10589 -- Abort_Undefer.all;
10594 -- Abort_Undefer.all;
10596 -- System.Task_Stages.Complete_Activation;
10604 -- In addition, if the task body is an activator, then a call to activate
10605 -- tasks is added at the start of the statements, before the call to
10606 -- Complete_Activation, and if in addition the task is a master then it
10607 -- must be established as a master. These calls are inserted and analyzed
10608 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10611 -- There is one discriminal declaration line generated for each
10612 -- discriminant that is present to provide an easy reference point for
10613 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10615 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10616 -- task body procedures have a profile (Arg : System.Address). That is
10617 -- needed because GNARLI has to use the same access-to-subprogram type
10618 -- for all task types. We depend here on knowing that in GNAT, passing
10619 -- an address argument by value is identical to passing a record value
10620 -- by access (in either case a single pointer is passed), so even though
10621 -- this procedure has the wrong profile. In fact it's all OK, since the
10622 -- callings sequence is identical.
10624 procedure Expand_N_Task_Body (N : Node_Id) is
10625 Loc : constant Source_Ptr := Sloc (N);
10626 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10630 Insert_Nod : Node_Id;
10631 -- Used to determine the proper location of wrapper body insertions
10634 -- Add renaming declarations for discriminals and a declaration for the
10635 -- entry family index (if applicable).
10637 Install_Private_Data_Declarations
10638 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10640 -- Add a call to Abort_Undefer at the very beginning of the task
10641 -- body since this body is called with abort still deferred.
10643 if Abort_Allowed then
10644 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10646 (First (Statements (Handled_Statement_Sequence (N))), Call);
10650 -- The statement part has already been protected with an at_end and
10651 -- cleanup actions. The call to Complete_Activation must be placed
10652 -- at the head of the sequence of statements of that block. The
10653 -- declarations have been merged in this sequence of statements but
10654 -- the first real statement is accessible from the First_Real_Statement
10655 -- field (which was set for exactly this purpose).
10657 if Restricted_Profile then
10658 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10660 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10664 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10668 Make_Subprogram_Body (Loc,
10669 Specification => Build_Task_Proc_Specification (Ttyp),
10670 Declarations => Declarations (N),
10671 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10673 -- If the task contains generic instantiations, cleanup actions are
10674 -- delayed until after instantiation. Transfer the activation chain to
10675 -- the subprogram, to insure that the activation call is properly
10676 -- generated. It the task body contains inner tasks, indicate that the
10677 -- subprogram is a task master.
10679 if Delay_Cleanups (Ttyp) then
10680 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10681 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10684 Rewrite (N, New_N);
10687 -- Set elaboration flag immediately after task body. If the body is a
10688 -- subunit, the flag is set in the declarative part containing the stub.
10690 if Nkind (Parent (N)) /= N_Subunit then
10692 Make_Assignment_Statement (Loc,
10694 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10695 Expression => New_Reference_To (Standard_True, Loc)));
10698 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10699 -- the task body. At this point all wrapper specs have been created,
10700 -- frozen and included in the dispatch table for the task type.
10702 if Ada_Version >= Ada_2005 then
10703 if Nkind (Parent (N)) = N_Subunit then
10704 Insert_Nod := Corresponding_Stub (Parent (N));
10709 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10711 end Expand_N_Task_Body;
10713 ------------------------------------
10714 -- Expand_N_Task_Type_Declaration --
10715 ------------------------------------
10717 -- We have several things to do. First we must create a Boolean flag used
10718 -- to mark if the body is elaborated yet. This variable gets set to True
10719 -- when the body of the task is elaborated (we can't rely on the normal
10720 -- ABE mechanism for the task body, since we need to pass an access to
10721 -- this elaboration boolean to the runtime routines).
10723 -- taskE : aliased Boolean := False;
10725 -- Next a variable is declared to hold the task stack size (either the
10726 -- default : Unspecified_Size, or a value that is set by a pragma
10727 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10728 -- the variable is initialized with this value:
10730 -- taskZ : Size_Type := Unspecified_Size;
10732 -- taskZ : Size_Type := Size_Type (size_expression);
10734 -- Note: No variable is needed to hold the task relative deadline since
10735 -- its value would never be static because the parameter is of a private
10736 -- type (Ada.Real_Time.Time_Span).
10738 -- Next we create a corresponding record type declaration used to represent
10739 -- values of this task. The general form of this type declaration is
10741 -- type taskV (discriminants) is record
10742 -- _Task_Id : Task_Id;
10743 -- entry_family : array (bounds) of Void;
10744 -- _Priority : Integer := priority_expression;
10745 -- _Size : Size_Type := size_expression;
10746 -- _Task_Info : Task_Info_Type := task_info_expression;
10747 -- _CPU : Integer := cpu_range_expression;
10748 -- _Relative_Deadline : Time_Span := time_span_expression;
10749 -- _Domain : Dispatching_Domain := dd_expression;
10752 -- The discriminants are present only if the corresponding task type has
10753 -- discriminants, and they exactly mirror the task type discriminants.
10755 -- The Id field is always present. It contains the Task_Id value, as set by
10756 -- the call to Create_Task. Note that although the task is limited, the
10757 -- task value record type is not limited, so there is no problem in passing
10758 -- this field as an out parameter to Create_Task.
10760 -- One entry_family component is present for each entry family in the task
10761 -- definition. The bounds correspond to the bounds of the entry family
10762 -- (which may depend on discriminants). The element type is void, since we
10763 -- only need the bounds information for determining the entry index. Note
10764 -- that the use of an anonymous array would normally be illegal in this
10765 -- context, but this is a parser check, and the semantics is quite prepared
10766 -- to handle such a case.
10768 -- The _Size field is present only if a Storage_Size pragma appears in the
10769 -- task definition. The expression captures the argument that was present
10770 -- in the pragma, and is used to override the task stack size otherwise
10771 -- associated with the task type.
10773 -- The _Priority field is present only if a Priority or Interrupt_Priority
10774 -- pragma appears in the task definition. The expression captures the
10775 -- argument that was present in the pragma, and is used to provide the Size
10776 -- parameter to the call to Create_Task.
10778 -- The _Task_Info field is present only if a Task_Info pragma appears in
10779 -- the task definition. The expression captures the argument that was
10780 -- present in the pragma, and is used to provide the Task_Image parameter
10781 -- to the call to Create_Task.
10783 -- The _CPU field is present only if a CPU pragma appears in the task
10784 -- definition. The expression captures the argument that was present in
10785 -- the pragma, and is used to provide the CPU parameter to the call to
10788 -- The _Relative_Deadline field is present only if a Relative_Deadline
10789 -- pragma appears in the task definition. The expression captures the
10790 -- argument that was present in the pragma, and is used to provide the
10791 -- Relative_Deadline parameter to the call to Create_Task.
10793 -- The _Domain field is present only if a Dispatching_Domain pragma or
10794 -- aspect appears in the task definition. The expression captures the
10795 -- argument that was present in the pragma or aspect, and is used to
10796 -- provide the Dispatching_Domain parameter to the call to Create_Task.
10798 -- When a task is declared, an instance of the task value record is
10799 -- created. The elaboration of this declaration creates the correct bounds
10800 -- for the entry families, and also evaluates the size, priority, and
10801 -- task_Info expressions if needed. The initialization routine for the task
10802 -- type itself then calls Create_Task with appropriate parameters to
10803 -- initialize the value of the Task_Id field.
10805 -- Note: the address of this record is passed as the "Discriminants"
10806 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10807 -- body procedure, it does not matter that it does not quite match the
10808 -- GNARLI model of what is being passed (the record contains more than just
10809 -- the discriminants, but the discriminants can be found from the record
10812 -- The Entity_Id for this created record type is placed in the
10813 -- Corresponding_Record_Type field of the associated task type entity.
10815 -- Next we create a procedure specification for the task body procedure:
10817 -- procedure taskB (_Task : access taskV);
10819 -- Note that this must come after the record type declaration, since
10820 -- the spec refers to this type. It turns out that the initialization
10821 -- procedure for the value type references the task body spec, but that's
10822 -- fine, since it won't be generated till the freeze point for the type,
10823 -- which is certainly after the task body spec declaration.
10825 -- Finally, we set the task index value field of the entry attribute in
10826 -- the case of a simple entry.
10828 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10829 Loc : constant Source_Ptr := Sloc (N);
10830 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10831 Tasknm : constant Name_Id := Chars (Tasktyp);
10832 Taskdef : constant Node_Id := Task_Definition (N);
10834 Proc_Spec : Node_Id;
10835 Rec_Decl : Node_Id;
10836 Rec_Ent : Entity_Id;
10838 Elab_Decl : Node_Id;
10839 Size_Decl : Node_Id;
10840 Body_Decl : Node_Id;
10841 Task_Size : Node_Id;
10842 Ent_Stack : Entity_Id;
10843 Decl_Stack : Node_Id;
10846 -- If already expanded, nothing to do
10848 if Present (Corresponding_Record_Type (Tasktyp)) then
10852 -- Here we will do the expansion
10854 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10856 Rec_Ent := Defining_Identifier (Rec_Decl);
10857 Cdecls := Component_Items (Component_List
10858 (Type_Definition (Rec_Decl)));
10860 Qualify_Entity_Names (N);
10862 -- First create the elaboration variable
10865 Make_Object_Declaration (Loc,
10866 Defining_Identifier =>
10867 Make_Defining_Identifier (Sloc (Tasktyp),
10868 Chars => New_External_Name (Tasknm, 'E')),
10869 Aliased_Present => True,
10870 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10871 Expression => New_Reference_To (Standard_False, Loc));
10872 Insert_After (N, Elab_Decl);
10874 -- Next create the declaration of the size variable (tasknmZ)
10876 Set_Storage_Size_Variable (Tasktyp,
10877 Make_Defining_Identifier (Sloc (Tasktyp),
10878 Chars => New_External_Name (Tasknm, 'Z')));
10880 if Present (Taskdef)
10881 and then Has_Storage_Size_Pragma (Taskdef)
10883 Is_Static_Expression
10885 (First (Pragma_Argument_Associations
10886 (Find_Task_Or_Protected_Pragma
10887 (Taskdef, Name_Storage_Size)))))
10890 Make_Object_Declaration (Loc,
10891 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10892 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10894 Convert_To (RTE (RE_Size_Type),
10896 (Expression (First (Pragma_Argument_Associations
10897 (Find_Task_Or_Protected_Pragma
10898 (Taskdef, Name_Storage_Size)))))));
10902 Make_Object_Declaration (Loc,
10903 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10904 Object_Definition =>
10905 New_Reference_To (RTE (RE_Size_Type), Loc),
10907 New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10910 Insert_After (Elab_Decl, Size_Decl);
10912 -- Next build the rest of the corresponding record declaration. This is
10913 -- done last, since the corresponding record initialization procedure
10914 -- will reference the previously created entities.
10916 -- Fill in the component declarations -- first the _Task_Id field
10919 Make_Component_Declaration (Loc,
10920 Defining_Identifier =>
10921 Make_Defining_Identifier (Loc, Name_uTask_Id),
10922 Component_Definition =>
10923 Make_Component_Definition (Loc,
10924 Aliased_Present => False,
10925 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10928 -- Declare static ATCB (that is, created by the expander) if we are
10929 -- using the Restricted run time.
10931 if Restricted_Profile then
10933 Make_Component_Declaration (Loc,
10934 Defining_Identifier =>
10935 Make_Defining_Identifier (Loc, Name_uATCB),
10937 Component_Definition =>
10938 Make_Component_Definition (Loc,
10939 Aliased_Present => True,
10940 Subtype_Indication => Make_Subtype_Indication (Loc,
10942 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
10945 Make_Index_Or_Discriminant_Constraint (Loc,
10947 New_List (Make_Integer_Literal (Loc, 0)))))));
10951 -- Declare static stack (that is, created by the expander) if we are
10952 -- using the Restricted run time on a bare board configuration.
10954 if Restricted_Profile
10955 and then Preallocated_Stacks_On_Target
10957 -- First we need to extract the appropriate stack size
10959 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10961 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10963 Expr_N : constant Node_Id :=
10964 Expression (First (
10965 Pragma_Argument_Associations (
10966 Find_Task_Or_Protected_Pragma
10967 (Taskdef, Name_Storage_Size))));
10968 Etyp : constant Entity_Id := Etype (Expr_N);
10969 P : constant Node_Id := Parent (Expr_N);
10972 -- The stack is defined inside the corresponding record.
10973 -- Therefore if the size of the stack is set by means of
10974 -- a discriminant, we must reference the discriminant of the
10975 -- corresponding record type.
10977 if Nkind (Expr_N) in N_Has_Entity
10978 and then Present (Discriminal_Link (Entity (Expr_N)))
10982 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10984 Set_Parent (Task_Size, P);
10985 Set_Etype (Task_Size, Etyp);
10986 Set_Analyzed (Task_Size);
10989 Task_Size := Relocate_Node (Expr_N);
10995 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10998 Decl_Stack := Make_Component_Declaration (Loc,
10999 Defining_Identifier => Ent_Stack,
11001 Component_Definition =>
11002 Make_Component_Definition (Loc,
11003 Aliased_Present => True,
11004 Subtype_Indication => Make_Subtype_Indication (Loc,
11006 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
11009 Make_Index_Or_Discriminant_Constraint (Loc,
11010 Constraints => New_List (Make_Range (Loc,
11011 Low_Bound => Make_Integer_Literal (Loc, 1),
11012 High_Bound => Convert_To (RTE (RE_Storage_Offset),
11015 Append_To (Cdecls, Decl_Stack);
11017 -- The appropriate alignment for the stack is ensured by the run-time
11018 -- code in charge of task creation.
11022 -- Add components for entry families
11024 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
11026 -- Add the _Priority component if a Priority pragma is present
11028 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
11030 Prag : constant Node_Id :=
11031 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
11035 Expr := First (Pragma_Argument_Associations (Prag));
11037 if Nkind (Expr) = N_Pragma_Argument_Association then
11038 Expr := Expression (Expr);
11041 Expr := New_Copy_Tree (Expr);
11043 -- Add conversion to proper type to do range check if required
11044 -- Note that for runtime units, we allow out of range interrupt
11045 -- priority values to be used in a priority pragma. This is for
11046 -- the benefit of some versions of System.Interrupts which use
11047 -- a special server task with maximum interrupt priority.
11049 if Pragma_Name (Prag) = Name_Priority
11050 and then not GNAT_Mode
11052 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
11054 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
11058 Make_Component_Declaration (Loc,
11059 Defining_Identifier =>
11060 Make_Defining_Identifier (Loc, Name_uPriority),
11061 Component_Definition =>
11062 Make_Component_Definition (Loc,
11063 Aliased_Present => False,
11064 Subtype_Indication => New_Reference_To (Standard_Integer,
11066 Expression => Expr));
11070 -- Add the _Task_Size component if a Storage_Size pragma is present
11072 if Present (Taskdef)
11073 and then Has_Storage_Size_Pragma (Taskdef)
11076 Make_Component_Declaration (Loc,
11077 Defining_Identifier =>
11078 Make_Defining_Identifier (Loc, Name_uSize),
11080 Component_Definition =>
11081 Make_Component_Definition (Loc,
11082 Aliased_Present => False,
11083 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
11087 Convert_To (RTE (RE_Size_Type),
11089 Expression (First (
11090 Pragma_Argument_Associations (
11091 Find_Task_Or_Protected_Pragma
11092 (Taskdef, Name_Storage_Size))))))));
11095 -- Add the _Task_Info component if a Task_Info pragma is present
11097 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
11099 Make_Component_Declaration (Loc,
11100 Defining_Identifier =>
11101 Make_Defining_Identifier (Loc, Name_uTask_Info),
11103 Component_Definition =>
11104 Make_Component_Definition (Loc,
11105 Aliased_Present => False,
11106 Subtype_Indication =>
11107 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
11109 Expression => New_Copy (
11110 Expression (First (
11111 Pragma_Argument_Associations (
11112 Find_Task_Or_Protected_Pragma
11113 (Taskdef, Name_Task_Info)))))));
11116 -- Add the _CPU component if a CPU pragma is present
11118 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
11120 Make_Component_Declaration (Loc,
11121 Defining_Identifier =>
11122 Make_Defining_Identifier (Loc, Name_uCPU),
11124 Component_Definition =>
11125 Make_Component_Definition (Loc,
11126 Aliased_Present => False,
11127 Subtype_Indication =>
11128 New_Reference_To (RTE (RE_CPU_Range), Loc)),
11130 Expression => New_Copy (
11131 Expression (First (
11132 Pragma_Argument_Associations (
11133 Find_Task_Or_Protected_Pragma
11134 (Taskdef, Name_CPU)))))));
11137 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11138 -- present. If we are using a restricted run time this component will
11139 -- not be added (deadlines are not allowed by the Ravenscar profile).
11141 if not Restricted_Profile
11142 and then Present (Taskdef)
11143 and then Has_Relative_Deadline_Pragma (Taskdef)
11146 Make_Component_Declaration (Loc,
11147 Defining_Identifier =>
11148 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
11150 Component_Definition =>
11151 Make_Component_Definition (Loc,
11152 Aliased_Present => False,
11153 Subtype_Indication =>
11154 New_Reference_To (RTE (RE_Time_Span), Loc)),
11157 Convert_To (RTE (RE_Time_Span),
11159 Expression (First (
11160 Pragma_Argument_Associations (
11161 Find_Task_Or_Protected_Pragma
11162 (Taskdef, Name_Relative_Deadline))))))));
11165 -- Add the _Dispatching_Domain component if a Dispatching_Domain pragma
11166 -- or aspect is present. If we are using a restricted run time this
11167 -- component will not be added (dispatching domains are not allowed by
11168 -- the Ravenscar profile).
11170 if not Restricted_Profile
11171 and then Present (Taskdef)
11172 and then Has_Pragma_Dispatching_Domain (Taskdef)
11175 Make_Component_Declaration (Loc,
11176 Defining_Identifier =>
11177 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
11179 Component_Definition =>
11180 Make_Component_Definition (Loc,
11181 Aliased_Present => False,
11182 Subtype_Indication =>
11184 (RTE (RE_Dispatching_Domain_Access), Loc)),
11187 Unchecked_Convert_To (RTE (RE_Dispatching_Domain_Access),
11191 (Pragma_Argument_Associations
11192 (Find_Task_Or_Protected_Pragma
11193 (Taskdef, Name_Dispatching_Domain))))))));
11196 Insert_After (Size_Decl, Rec_Decl);
11198 -- Analyze the record declaration immediately after construction,
11199 -- because the initialization procedure is needed for single task
11200 -- declarations before the next entity is analyzed.
11202 Analyze (Rec_Decl);
11204 -- Create the declaration of the task body procedure
11206 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
11208 Make_Subprogram_Declaration (Loc,
11209 Specification => Proc_Spec);
11211 Insert_After (Rec_Decl, Body_Decl);
11213 -- The subprogram does not comes from source, so we have to indicate the
11214 -- need for debugging information explicitly.
11216 if Comes_From_Source (Original_Node (N)) then
11217 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
11220 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11221 -- the corresponding record has been frozen.
11223 if Ada_Version >= Ada_2005 then
11224 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
11227 -- Ada 2005 (AI-345): We must defer freezing to allow further
11228 -- declaration of primitive subprograms covering task interfaces
11230 if Ada_Version <= Ada_95 then
11232 -- Now we can freeze the corresponding record. This needs manually
11233 -- freezing, since it is really part of the task type, and the task
11234 -- type is frozen at this stage. We of course need the initialization
11235 -- procedure for this corresponding record type and we won't get it
11236 -- in time if we don't freeze now.
11239 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
11241 if Is_Non_Empty_List (L) then
11242 Insert_List_After (Body_Decl, L);
11247 -- Complete the expansion of access types to the current task type, if
11248 -- any were declared.
11250 Expand_Previous_Access_Type (Tasktyp);
11252 -- Create wrappers for entries that have pre/postconditions
11258 Ent := First_Entity (Tasktyp);
11259 while Present (Ent) loop
11260 if Ekind_In (Ent, E_Entry, E_Entry_Family)
11261 and then Present (Spec_PPC_List (Contract (Ent)))
11263 Build_PPC_Wrapper (Ent, N);
11269 end Expand_N_Task_Type_Declaration;
11271 -------------------------------
11272 -- Expand_N_Timed_Entry_Call --
11273 -------------------------------
11275 -- A timed entry call in normal case is not implemented using ATC mechanism
11276 -- anymore for efficiency reason.
11286 -- is expanded as follow:
11288 -- 1) When T.E is a task entry_call;
11292 -- X : Task_Entry_Index := <entry index>;
11293 -- DX : Duration := To_Duration (D);
11294 -- M : Delay_Mode := <discriminant>;
11295 -- P : parms := (parm, parm, parm);
11298 -- Timed_Protected_Entry_Call
11299 -- (<acceptor-task>, X, P'Address, DX, M, B);
11307 -- 2) When T.E is a protected entry_call;
11311 -- X : Protected_Entry_Index := <entry index>;
11312 -- DX : Duration := To_Duration (D);
11313 -- M : Delay_Mode := <discriminant>;
11314 -- P : parms := (parm, parm, parm);
11317 -- Timed_Protected_Entry_Call
11318 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
11326 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
11329 -- B : Boolean := False;
11330 -- C : Ada.Tags.Prim_Op_Kind;
11331 -- DX : Duration := To_Duration (D)
11332 -- K : Ada.Tags.Tagged_Kind :=
11333 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
11334 -- M : Integer :=...;
11335 -- P : Parameters := (Param1 .. ParamN);
11339 -- if K = Ada.Tags.TK_Limited_Tagged then
11340 -- <dispatching-call>;
11341 -- <triggering-statements>
11345 -- Ada.Tags.Get_Offset_Index
11346 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
11348 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
11350 -- if C = POK_Protected_Entry
11351 -- or else C = POK_Task_Entry
11353 -- Param1 := P.Param1;
11355 -- ParamN := P.ParamN;
11359 -- if C = POK_Procedure
11360 -- or else C = POK_Protected_Procedure
11361 -- or else C = POK_Task_Procedure
11363 -- <dispatching-call>;
11366 -- <triggering-statements>
11368 -- <timed-statements>
11373 -- The triggering statement and the sequence of timed statements have not
11374 -- been analyzed yet (see Analyzed_Timed_Entry_Call). They may contain
11375 -- local declarations, and therefore the copies that are made during
11376 -- expansion must be disjoint, as for any other inlining.
11378 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
11379 Loc : constant Source_Ptr := Sloc (N);
11381 E_Call : Node_Id :=
11382 Entry_Call_Statement (Entry_Call_Alternative (N));
11383 E_Stats : constant List_Id :=
11384 Statements (Entry_Call_Alternative (N));
11385 D_Stat : Node_Id :=
11386 Delay_Statement (Delay_Alternative (N));
11387 D_Stats : constant List_Id :=
11388 Statements (Delay_Alternative (N));
11391 Blk_Typ : Entity_Id;
11393 Call_Ent : Entity_Id;
11394 Conc_Typ_Stmts : List_Id;
11398 D_Type : Entity_Id;
11404 Is_Disp_Select : Boolean;
11405 Lim_Typ_Stmts : List_Id;
11414 B : Entity_Id; -- Call status flag
11415 C : Entity_Id; -- Call kind
11416 D : Entity_Id; -- Delay
11417 K : Entity_Id; -- Tagged kind
11418 M : Entity_Id; -- Delay mode
11419 P : Entity_Id; -- Parameter block
11420 S : Entity_Id; -- Primitive operation slot
11423 -- Under the Ravenscar profile, timed entry calls are excluded. An error
11424 -- was already reported on spec, so do not attempt to expand the call.
11426 if Restriction_Active (No_Select_Statements) then
11430 Process_Statements_For_Controlled_Objects (Entry_Call_Alternative (N));
11431 Process_Statements_For_Controlled_Objects (Delay_Alternative (N));
11433 -- The arguments in the call may require dynamic allocation, and the
11434 -- call statement may have been transformed into a block. The block
11435 -- may contain additional declarations for internal entities, and the
11436 -- original call is found by sequential search.
11438 if Nkind (E_Call) = N_Block_Statement then
11439 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
11440 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
11441 N_Entry_Call_Statement)
11448 Ada_Version >= Ada_2005
11449 and then Nkind (E_Call) = N_Procedure_Call_Statement;
11451 if Is_Disp_Select then
11452 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11458 -- B : Boolean := False;
11460 B := Build_B (Loc, Decls);
11463 -- C : Ada.Tags.Prim_Op_Kind;
11465 C := Build_C (Loc, Decls);
11467 -- Because the analysis of all statements was disabled, manually
11468 -- analyze the delay statement.
11471 D_Stat := Original_Node (D_Stat);
11474 -- Build an entry call using Simple_Entry_Call
11476 Extract_Entry (E_Call, Concval, Ename, Index);
11477 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11479 Decls := Declarations (E_Call);
11480 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11489 B := Make_Defining_Identifier (Loc, Name_uB);
11492 Make_Object_Declaration (Loc,
11493 Defining_Identifier => B,
11494 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
11497 -- Duration and mode processing
11499 D_Type := Base_Type (Etype (Expression (D_Stat)));
11501 -- Use the type of the delay expression (Calendar or Real_Time) to
11502 -- generate the appropriate conversion.
11504 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11505 D_Disc := Make_Integer_Literal (Loc, 0);
11506 D_Conv := Relocate_Node (Expression (D_Stat));
11508 elsif Is_RTE (D_Type, RO_CA_Time) then
11509 D_Disc := Make_Integer_Literal (Loc, 1);
11511 Make_Function_Call (Loc,
11512 Name => New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11513 Parameter_Associations =>
11514 New_List (New_Copy (Expression (D_Stat))));
11516 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11517 D_Disc := Make_Integer_Literal (Loc, 2);
11519 Make_Function_Call (Loc,
11520 Name => New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11521 Parameter_Associations =>
11522 New_List (New_Copy (Expression (D_Stat))));
11525 D := Make_Temporary (Loc, 'D');
11531 Make_Object_Declaration (Loc,
11532 Defining_Identifier => D,
11533 Object_Definition => New_Reference_To (Standard_Duration, Loc)));
11535 M := Make_Temporary (Loc, 'M');
11538 -- M : Integer := (0 | 1 | 2);
11541 Make_Object_Declaration (Loc,
11542 Defining_Identifier => M,
11543 Object_Definition => New_Reference_To (Standard_Integer, Loc),
11544 Expression => D_Disc));
11546 -- Do the assignment at this stage only because the evaluation of the
11547 -- expression must not occur before (see ACVC C97302A).
11550 Make_Assignment_Statement (Loc,
11551 Name => New_Reference_To (D, Loc),
11552 Expression => D_Conv));
11554 -- Parameter block processing
11556 -- Manually create the parameter block for dispatching calls. In the
11557 -- case of entries, the block has already been created during the call
11558 -- to Build_Simple_Entry_Call.
11560 if Is_Disp_Select then
11562 -- Tagged kind processing, generate:
11563 -- K : Ada.Tags.Tagged_Kind :=
11564 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11566 K := Build_K (Loc, Decls, Obj);
11568 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11570 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11572 -- Dispatch table slot processing, generate:
11575 S := Build_S (Loc, Decls);
11578 -- S := Ada.Tags.Get_Offset_Index
11579 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11582 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11585 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11587 -- where Obj is the controlling formal parameter, S is the dispatch
11588 -- table slot number of the dispatching operation, P is the wrapped
11589 -- parameter block, D is the duration, M is the duration mode, C is
11590 -- the call kind and B is the call status.
11592 Params := New_List;
11594 Append_To (Params, New_Copy_Tree (Obj));
11595 Append_To (Params, New_Reference_To (S, Loc));
11597 Make_Attribute_Reference (Loc,
11598 Prefix => New_Reference_To (P, Loc),
11599 Attribute_Name => Name_Address));
11600 Append_To (Params, New_Reference_To (D, Loc));
11601 Append_To (Params, New_Reference_To (M, Loc));
11602 Append_To (Params, New_Reference_To (C, Loc));
11603 Append_To (Params, New_Reference_To (B, Loc));
11605 Append_To (Conc_Typ_Stmts,
11606 Make_Procedure_Call_Statement (Loc,
11610 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
11611 Parameter_Associations => Params));
11614 -- if C = POK_Protected_Entry
11615 -- or else C = POK_Task_Entry
11617 -- Param1 := P.Param1;
11619 -- ParamN := P.ParamN;
11622 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11624 -- Generate the if statement only when the packed parameters need
11625 -- explicit assignments to their corresponding actuals.
11627 if Present (Unpack) then
11628 Append_To (Conc_Typ_Stmts,
11629 Make_If_Statement (Loc,
11635 Left_Opnd => New_Reference_To (C, Loc),
11638 (RTE (RE_POK_Protected_Entry), Loc)),
11642 Left_Opnd => New_Reference_To (C, Loc),
11644 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11646 Then_Statements => Unpack));
11652 -- if C = POK_Procedure
11653 -- or else C = POK_Protected_Procedure
11654 -- or else C = POK_Task_Procedure
11656 -- <dispatching-call>
11658 -- <triggering-statements>
11660 -- <timed-statements>
11663 N_Stats := Copy_Separate_List (E_Stats);
11665 Prepend_To (N_Stats,
11666 Make_If_Statement (Loc,
11672 Left_Opnd => New_Reference_To (C, Loc),
11674 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11680 Left_Opnd => New_Reference_To (C, Loc),
11682 New_Reference_To (RTE (
11683 RE_POK_Protected_Procedure), Loc)),
11686 Left_Opnd => New_Reference_To (C, Loc),
11689 (RTE (RE_POK_Task_Procedure), Loc)))),
11691 Then_Statements => New_List (E_Call)));
11693 Append_To (Conc_Typ_Stmts,
11694 Make_If_Statement (Loc,
11695 Condition => New_Reference_To (B, Loc),
11696 Then_Statements => N_Stats,
11697 Else_Statements => D_Stats));
11700 -- <dispatching-call>;
11701 -- <triggering-statements>
11703 Lim_Typ_Stmts := Copy_Separate_List (E_Stats);
11704 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11707 -- if K = Ada.Tags.TK_Limited_Tagged then
11714 Make_If_Statement (Loc,
11717 Left_Opnd => New_Reference_To (K, Loc),
11719 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11720 Then_Statements => Lim_Typ_Stmts,
11721 Else_Statements => Conc_Typ_Stmts));
11724 -- Skip assignments to temporaries created for in-out parameters.
11725 -- This makes unwarranted assumptions about the shape of the expanded
11726 -- tree for the call, and should be cleaned up ???
11728 Stmt := First (Stmts);
11729 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11733 -- Do the assignment at this stage only because the evaluation
11734 -- of the expression must not occur before (see ACVC C97302A).
11736 Insert_Before (Stmt,
11737 Make_Assignment_Statement (Loc,
11738 Name => New_Reference_To (D, Loc),
11739 Expression => D_Conv));
11742 Params := Parameter_Associations (Call);
11744 -- For a protected type, we build a Timed_Protected_Entry_Call
11746 if Is_Protected_Type (Etype (Concval)) then
11748 -- Create a new call statement
11750 Param := First (Params);
11751 while Present (Param)
11752 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11757 Dummy := Remove_Next (Next (Param));
11759 -- Remove garbage is following the Cancel_Param if present
11761 Dummy := Next (Param);
11763 -- Remove the mode of the Protected_Entry_Call call, then remove
11764 -- the Communication_Block of the Protected_Entry_Call call, and
11765 -- finally add Duration and a Delay_Mode parameter
11767 pragma Assert (Present (Param));
11768 Rewrite (Param, New_Reference_To (D, Loc));
11770 Rewrite (Dummy, New_Reference_To (M, Loc));
11772 -- Add a Boolean flag for successful entry call
11774 Append_To (Params, New_Reference_To (B, Loc));
11776 case Corresponding_Runtime_Package (Etype (Concval)) is
11777 when System_Tasking_Protected_Objects_Entries =>
11779 Make_Procedure_Call_Statement (Loc,
11782 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11783 Parameter_Associations => Params));
11785 when System_Tasking_Protected_Objects_Single_Entry =>
11786 Param := First (Params);
11787 while Present (Param)
11789 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11797 Make_Procedure_Call_Statement (Loc,
11800 (RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11801 Parameter_Associations => Params));
11804 raise Program_Error;
11807 -- For the task case, build a Timed_Task_Entry_Call
11810 -- Create a new call statement
11812 Append_To (Params, New_Reference_To (D, Loc));
11813 Append_To (Params, New_Reference_To (M, Loc));
11814 Append_To (Params, New_Reference_To (B, Loc));
11817 Make_Procedure_Call_Statement (Loc,
11819 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11820 Parameter_Associations => Params));
11824 Make_Implicit_If_Statement (N,
11825 Condition => New_Reference_To (B, Loc),
11826 Then_Statements => E_Stats,
11827 Else_Statements => D_Stats));
11831 Make_Block_Statement (Loc,
11832 Declarations => Decls,
11833 Handled_Statement_Sequence =>
11834 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11837 end Expand_N_Timed_Entry_Call;
11839 ----------------------------------------
11840 -- Expand_Protected_Body_Declarations --
11841 ----------------------------------------
11843 procedure Expand_Protected_Body_Declarations
11845 Spec_Id : Entity_Id)
11848 if No_Run_Time_Mode then
11849 Error_Msg_CRT ("protected body", N);
11852 elsif Full_Expander_Active then
11854 -- Associate discriminals with the first subprogram or entry body to
11857 if Present (First_Protected_Operation (Declarations (N))) then
11858 Set_Discriminals (Parent (Spec_Id));
11861 end Expand_Protected_Body_Declarations;
11863 -------------------------
11864 -- External_Subprogram --
11865 -------------------------
11867 function External_Subprogram (E : Entity_Id) return Entity_Id is
11868 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11871 -- The internal and external subprograms follow each other on the entity
11872 -- chain. Note that previously private operations had no separate
11873 -- external subprogram. We now create one in all cases, because a
11874 -- private operation may actually appear in an external call, through
11875 -- a 'Access reference used for a callback.
11877 -- If the operation is a function that returns an anonymous access type,
11878 -- the corresponding itype appears before the operation, and must be
11881 -- This mechanism is fragile, there should be a real link between the
11882 -- two versions of the operation, but there is no place to put it ???
11884 if Is_Access_Type (Next_Entity (Subp)) then
11885 return Next_Entity (Next_Entity (Subp));
11887 return Next_Entity (Subp);
11889 end External_Subprogram;
11891 ------------------------------
11892 -- Extract_Dispatching_Call --
11893 ------------------------------
11895 procedure Extract_Dispatching_Call
11897 Call_Ent : out Entity_Id;
11898 Object : out Entity_Id;
11899 Actuals : out List_Id;
11900 Formals : out List_Id)
11902 Call_Nam : Node_Id;
11905 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11907 if Present (Original_Node (N)) then
11908 Call_Nam := Name (Original_Node (N));
11910 Call_Nam := Name (N);
11913 -- Retrieve the name of the dispatching procedure. It contains the
11914 -- dispatch table slot number.
11917 case Nkind (Call_Nam) is
11918 when N_Identifier =>
11921 when N_Selected_Component =>
11922 Call_Nam := Selector_Name (Call_Nam);
11925 raise Program_Error;
11930 Actuals := Parameter_Associations (N);
11931 Call_Ent := Entity (Call_Nam);
11932 Formals := Parameter_Specifications (Parent (Call_Ent));
11933 Object := First (Actuals);
11935 if Present (Original_Node (Object)) then
11936 Object := Original_Node (Object);
11939 -- If the type of the dispatching object is an access type then return
11940 -- an explicit dereference.
11942 if Is_Access_Type (Etype (Object)) then
11943 Object := Make_Explicit_Dereference (Sloc (N), Object);
11946 end Extract_Dispatching_Call;
11948 -------------------
11949 -- Extract_Entry --
11950 -------------------
11952 procedure Extract_Entry
11954 Concval : out Node_Id;
11955 Ename : out Node_Id;
11956 Index : out Node_Id)
11958 Nam : constant Node_Id := Name (N);
11961 -- For a simple entry, the name is a selected component, with the
11962 -- prefix being the task value, and the selector being the entry.
11964 if Nkind (Nam) = N_Selected_Component then
11965 Concval := Prefix (Nam);
11966 Ename := Selector_Name (Nam);
11969 -- For a member of an entry family, the name is an indexed component
11970 -- where the prefix is a selected component, whose prefix in turn is
11971 -- the task value, and whose selector is the entry family. The single
11972 -- expression in the expressions list of the indexed component is the
11973 -- subscript for the family.
11975 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11976 Concval := Prefix (Prefix (Nam));
11977 Ename := Selector_Name (Prefix (Nam));
11978 Index := First (Expressions (Nam));
11982 -------------------
11983 -- Family_Offset --
11984 -------------------
11986 function Family_Offset
11991 Cap : Boolean) return Node_Id
11997 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11998 -- If one of the bounds is a reference to a discriminant, replace with
11999 -- corresponding discriminal of type. Within the body of a task retrieve
12000 -- the renamed discriminant by simple visibility, using its generated
12001 -- name. Within a protected object, find the original discriminant and
12002 -- replace it with the discriminal of the current protected operation.
12004 ------------------------------
12005 -- Convert_Discriminant_Ref --
12006 ------------------------------
12008 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
12009 Loc : constant Source_Ptr := Sloc (Bound);
12014 if Is_Entity_Name (Bound)
12015 and then Ekind (Entity (Bound)) = E_Discriminant
12017 if Is_Task_Type (Ttyp)
12018 and then Has_Completion (Ttyp)
12020 B := Make_Identifier (Loc, Chars (Entity (Bound)));
12021 Find_Direct_Name (B);
12023 elsif Is_Protected_Type (Ttyp) then
12024 D := First_Discriminant (Ttyp);
12025 while Chars (D) /= Chars (Entity (Bound)) loop
12026 Next_Discriminant (D);
12029 B := New_Reference_To (Discriminal (D), Loc);
12032 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
12035 elsif Nkind (Bound) = N_Attribute_Reference then
12039 B := New_Copy_Tree (Bound);
12043 Make_Attribute_Reference (Loc,
12044 Attribute_Name => Name_Pos,
12045 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
12046 Expressions => New_List (B));
12047 end Convert_Discriminant_Ref;
12049 -- Start of processing for Family_Offset
12052 Real_Hi := Convert_Discriminant_Ref (Hi);
12053 Real_Lo := Convert_Discriminant_Ref (Lo);
12056 if Is_Task_Type (Ttyp) then
12057 Ityp := RTE (RE_Task_Entry_Index);
12059 Ityp := RTE (RE_Protected_Entry_Index);
12063 Make_Attribute_Reference (Loc,
12064 Prefix => New_Reference_To (Ityp, Loc),
12065 Attribute_Name => Name_Min,
12066 Expressions => New_List (
12068 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12071 Make_Attribute_Reference (Loc,
12072 Prefix => New_Reference_To (Ityp, Loc),
12073 Attribute_Name => Name_Max,
12074 Expressions => New_List (
12076 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12079 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12086 function Family_Size
12091 Cap : Boolean) return Node_Id
12096 if Is_Task_Type (Ttyp) then
12097 Ityp := RTE (RE_Task_Entry_Index);
12099 Ityp := RTE (RE_Protected_Entry_Index);
12103 Make_Attribute_Reference (Loc,
12104 Prefix => New_Reference_To (Ityp, Loc),
12105 Attribute_Name => Name_Max,
12106 Expressions => New_List (
12109 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
12111 Make_Integer_Literal (Loc, 1)),
12112 Make_Integer_Literal (Loc, 0)));
12115 ----------------------------
12116 -- Find_Enclosing_Context --
12117 ----------------------------
12119 procedure Find_Enclosing_Context
12121 Context : out Node_Id;
12122 Context_Id : out Entity_Id;
12123 Context_Decls : out List_Id)
12126 -- Traverse the parent chain looking for an enclosing body, block,
12127 -- package or return statement.
12129 Context := Parent (N);
12130 while not Nkind_In (Context, N_Block_Statement,
12132 N_Extended_Return_Statement,
12134 N_Package_Declaration,
12138 Context := Parent (Context);
12141 -- Extract the constituents of the context
12143 if Nkind (Context) = N_Extended_Return_Statement then
12144 Context_Decls := Return_Object_Declarations (Context);
12145 Context_Id := Return_Statement_Entity (Context);
12147 -- Package declarations and bodies use a common library-level activation
12148 -- chain or task master, therefore return the package declaration as the
12149 -- proper carrier for the appropriate flag.
12151 elsif Nkind (Context) = N_Package_Body then
12152 Context_Decls := Declarations (Context);
12153 Context_Id := Corresponding_Spec (Context);
12154 Context := Parent (Context_Id);
12156 if Nkind (Context) = N_Defining_Program_Unit_Name then
12157 Context := Parent (Parent (Context));
12159 Context := Parent (Context);
12162 elsif Nkind (Context) = N_Package_Declaration then
12163 Context_Decls := Visible_Declarations (Specification (Context));
12164 Context_Id := Defining_Unit_Name (Specification (Context));
12166 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12167 Context_Id := Defining_Identifier (Context_Id);
12171 Context_Decls := Declarations (Context);
12173 if Nkind (Context) = N_Block_Statement then
12174 Context_Id := Entity (Identifier (Context));
12176 elsif Nkind (Context) = N_Entry_Body then
12177 Context_Id := Defining_Identifier (Context);
12179 elsif Nkind (Context) = N_Subprogram_Body then
12180 if Present (Corresponding_Spec (Context)) then
12181 Context_Id := Corresponding_Spec (Context);
12183 Context_Id := Defining_Unit_Name (Specification (Context));
12185 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12186 Context_Id := Defining_Identifier (Context_Id);
12190 elsif Nkind (Context) = N_Task_Body then
12191 Context_Id := Corresponding_Spec (Context);
12194 raise Program_Error;
12198 pragma Assert (Present (Context));
12199 pragma Assert (Present (Context_Id));
12200 pragma Assert (Present (Context_Decls));
12201 end Find_Enclosing_Context;
12203 -----------------------
12204 -- Find_Master_Scope --
12205 -----------------------
12207 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
12211 -- In Ada 2005, the master is the innermost enclosing scope that is not
12212 -- transient. If the enclosing block is the rewriting of a call or the
12213 -- scope is an extended return statement this is valid master. The
12214 -- master in an extended return is only used within the return, and is
12215 -- subsequently overwritten in Move_Activation_Chain, but it must exist
12216 -- now before that overwriting occurs.
12220 if Ada_Version >= Ada_2005 then
12221 while Is_Internal (S) loop
12222 if Nkind (Parent (S)) = N_Block_Statement
12224 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
12228 elsif Ekind (S) = E_Return_Statement then
12238 end Find_Master_Scope;
12240 -----------------------------------
12241 -- Find_Task_Or_Protected_Pragma --
12242 -----------------------------------
12244 function Find_Task_Or_Protected_Pragma
12246 P : Name_Id) return Node_Id
12251 N := First (Visible_Declarations (T));
12252 while Present (N) loop
12253 if Nkind (N) = N_Pragma then
12254 if Pragma_Name (N) = P then
12257 elsif P = Name_Priority
12258 and then Pragma_Name (N) = Name_Interrupt_Priority
12271 N := First (Private_Declarations (T));
12272 while Present (N) loop
12273 if Nkind (N) = N_Pragma then
12274 if Pragma_Name (N) = P then
12277 elsif P = Name_Priority
12278 and then Pragma_Name (N) = Name_Interrupt_Priority
12291 raise Program_Error;
12292 end Find_Task_Or_Protected_Pragma;
12294 -------------------------------
12295 -- First_Protected_Operation --
12296 -------------------------------
12298 function First_Protected_Operation (D : List_Id) return Node_Id is
12299 First_Op : Node_Id;
12302 First_Op := First (D);
12303 while Present (First_Op)
12304 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
12310 end First_Protected_Operation;
12312 ---------------------------------------
12313 -- Install_Private_Data_Declarations --
12314 ---------------------------------------
12316 procedure Install_Private_Data_Declarations
12318 Spec_Id : Entity_Id;
12319 Conc_Typ : Entity_Id;
12320 Body_Nod : Node_Id;
12322 Barrier : Boolean := False;
12323 Family : Boolean := False)
12325 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
12328 Insert_Node : Node_Id := Empty;
12329 Obj_Ent : Entity_Id;
12331 procedure Add (Decl : Node_Id);
12332 -- Add a single declaration after Insert_Node. If this is the first
12333 -- addition, Decl is added to the front of Decls and it becomes the
12336 function Replace_Bound (Bound : Node_Id) return Node_Id;
12337 -- The bounds of an entry index may depend on discriminants, create a
12338 -- reference to the corresponding prival. Otherwise return a duplicate
12339 -- of the original bound.
12345 procedure Add (Decl : Node_Id) is
12347 if No (Insert_Node) then
12348 Prepend_To (Decls, Decl);
12350 Insert_After (Insert_Node, Decl);
12353 Insert_Node := Decl;
12356 --------------------------
12357 -- Replace_Discriminant --
12358 --------------------------
12360 function Replace_Bound (Bound : Node_Id) return Node_Id is
12362 if Nkind (Bound) = N_Identifier
12363 and then Is_Discriminal (Entity (Bound))
12365 return Make_Identifier (Loc, Chars (Entity (Bound)));
12367 return Duplicate_Subexpr (Bound);
12371 -- Start of processing for Install_Private_Data_Declarations
12374 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
12375 -- formal parameter _O, _object or _task depending on the context.
12377 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
12379 -- Special processing of _O for barrier functions, protected entries
12386 (Ekind (Spec_Id) = E_Entry
12387 or else Ekind (Spec_Id) = E_Entry_Family))
12390 Conc_Rec : constant Entity_Id :=
12391 Corresponding_Record_Type (Conc_Typ);
12392 Typ_Id : constant Entity_Id :=
12393 Make_Defining_Identifier (Loc,
12394 New_External_Name (Chars (Conc_Rec), 'P'));
12397 -- type prot_typVP is access prot_typV;
12400 Make_Full_Type_Declaration (Loc,
12401 Defining_Identifier => Typ_Id,
12403 Make_Access_To_Object_Definition (Loc,
12404 Subtype_Indication =>
12405 New_Reference_To (Conc_Rec, Loc)));
12409 -- _object : prot_typVP := prot_typV (_O);
12412 Make_Object_Declaration (Loc,
12413 Defining_Identifier =>
12414 Make_Defining_Identifier (Loc, Name_uObject),
12415 Object_Definition => New_Reference_To (Typ_Id, Loc),
12417 Unchecked_Convert_To (Typ_Id,
12418 New_Reference_To (Obj_Ent, Loc)));
12421 -- Set the reference to the concurrent object
12423 Obj_Ent := Defining_Identifier (Decl);
12427 -- Step 2: Create the Protection object and build its declaration for
12428 -- any protected entry (family) of subprogram.
12430 if Is_Protected then
12432 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
12436 Set_Protection_Object (Spec_Id, Prot_Ent);
12438 -- Determine the proper protection type
12440 if Has_Attach_Handler (Conc_Typ)
12441 and then not Restricted_Profile
12442 and then not Restriction_Active (No_Dynamic_Attachment)
12444 Prot_Typ := RE_Static_Interrupt_Protection;
12446 elsif Has_Interrupt_Handler (Conc_Typ)
12447 and then not Restriction_Active (No_Dynamic_Attachment)
12449 Prot_Typ := RE_Dynamic_Interrupt_Protection;
12451 -- The type has explicit entries or generated primitive entry
12454 elsif Has_Entries (Conc_Typ)
12456 (Ada_Version >= Ada_2005
12457 and then Present (Interface_List (Parent (Conc_Typ))))
12459 case Corresponding_Runtime_Package (Conc_Typ) is
12460 when System_Tasking_Protected_Objects_Entries =>
12461 Prot_Typ := RE_Protection_Entries;
12463 when System_Tasking_Protected_Objects_Single_Entry =>
12464 Prot_Typ := RE_Protection_Entry;
12467 raise Program_Error;
12471 Prot_Typ := RE_Protection;
12475 -- conc_typR : protection_typ renames _object._object;
12478 Make_Object_Renaming_Declaration (Loc,
12479 Defining_Identifier => Prot_Ent,
12481 New_Reference_To (RTE (Prot_Typ), Loc),
12483 Make_Selected_Component (Loc,
12484 Prefix => New_Reference_To (Obj_Ent, Loc),
12485 Selector_Name => Make_Identifier (Loc, Name_uObject)));
12490 -- Step 3: Add discriminant renamings (if any)
12492 if Has_Discriminants (Conc_Typ) then
12497 D := First_Discriminant (Conc_Typ);
12498 while Present (D) loop
12500 -- Adjust the source location
12502 Set_Sloc (Discriminal (D), Loc);
12505 -- discr_name : discr_typ renames _object.discr_name;
12507 -- discr_name : discr_typ renames _task.discr_name;
12510 Make_Object_Renaming_Declaration (Loc,
12511 Defining_Identifier => Discriminal (D),
12512 Subtype_Mark => New_Reference_To (Etype (D), Loc),
12514 Make_Selected_Component (Loc,
12515 Prefix => New_Reference_To (Obj_Ent, Loc),
12516 Selector_Name => Make_Identifier (Loc, Chars (D))));
12519 Next_Discriminant (D);
12524 -- Step 4: Add private component renamings (if any)
12526 if Is_Protected then
12527 Def := Protected_Definition (Parent (Conc_Typ));
12529 if Present (Private_Declarations (Def)) then
12532 Comp_Id : Entity_Id;
12533 Decl_Id : Entity_Id;
12536 Comp := First (Private_Declarations (Def));
12537 while Present (Comp) loop
12538 if Nkind (Comp) = N_Component_Declaration then
12539 Comp_Id := Defining_Identifier (Comp);
12541 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12543 -- Minimal decoration
12545 if Ekind (Spec_Id) = E_Function then
12546 Set_Ekind (Decl_Id, E_Constant);
12548 Set_Ekind (Decl_Id, E_Variable);
12551 Set_Prival (Comp_Id, Decl_Id);
12552 Set_Prival_Link (Decl_Id, Comp_Id);
12553 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
12556 -- comp_name : comp_typ renames _object.comp_name;
12559 Make_Object_Renaming_Declaration (Loc,
12560 Defining_Identifier => Decl_Id,
12562 New_Reference_To (Etype (Comp_Id), Loc),
12564 Make_Selected_Component (Loc,
12566 New_Reference_To (Obj_Ent, Loc),
12568 Make_Identifier (Loc, Chars (Comp_Id))));
12578 -- Step 5: Add the declaration of the entry index and the associated
12579 -- type for barrier functions and entry families.
12581 if (Barrier and then Family)
12582 or else Ekind (Spec_Id) = E_Entry_Family
12585 E : constant Entity_Id := Index_Object (Spec_Id);
12586 Index : constant Entity_Id :=
12587 Defining_Identifier (
12588 Entry_Index_Specification (
12589 Entry_Body_Formal_Part (Body_Nod)));
12590 Index_Con : constant Entity_Id :=
12591 Make_Defining_Identifier (Loc, Chars (Index));
12593 Index_Typ : Entity_Id;
12597 -- Minimal decoration
12599 Set_Ekind (Index_Con, E_Constant);
12600 Set_Entry_Index_Constant (Index, Index_Con);
12601 Set_Discriminal_Link (Index_Con, Index);
12603 -- Retrieve the bounds of the entry family
12605 High := Type_High_Bound (Etype (Index));
12606 Low := Type_Low_Bound (Etype (Index));
12608 -- In the simple case the entry family is given by a subtype
12609 -- mark and the index constant has the same type.
12611 if Is_Entity_Name (Original_Node (
12612 Discrete_Subtype_Definition (Parent (Index))))
12614 Index_Typ := Etype (Index);
12616 -- Otherwise a new subtype declaration is required
12619 High := Replace_Bound (High);
12620 Low := Replace_Bound (Low);
12622 Index_Typ := Make_Temporary (Loc, 'J');
12625 -- subtype Jnn is <Etype of Index> range Low .. High;
12628 Make_Subtype_Declaration (Loc,
12629 Defining_Identifier => Index_Typ,
12630 Subtype_Indication =>
12631 Make_Subtype_Indication (Loc,
12633 New_Reference_To (Base_Type (Etype (Index)), Loc),
12635 Make_Range_Constraint (Loc,
12636 Range_Expression =>
12637 Make_Range (Loc, Low, High))));
12641 Set_Etype (Index_Con, Index_Typ);
12643 -- Create the object which designates the index:
12644 -- J : constant Jnn :=
12645 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12647 -- where Jnn is the subtype created above or the original type of
12648 -- the index, _E is a formal of the protected body subprogram and
12649 -- <index expr> is the index of the first family member.
12652 Make_Object_Declaration (Loc,
12653 Defining_Identifier => Index_Con,
12654 Constant_Present => True,
12655 Object_Definition =>
12656 New_Reference_To (Index_Typ, Loc),
12659 Make_Attribute_Reference (Loc,
12661 New_Reference_To (Index_Typ, Loc),
12662 Attribute_Name => Name_Val,
12664 Expressions => New_List (
12668 Make_Op_Subtract (Loc,
12670 New_Reference_To (E, Loc),
12672 Entry_Index_Expression (Loc,
12673 Defining_Identifier (Body_Nod),
12677 Make_Attribute_Reference (Loc,
12679 New_Reference_To (Index_Typ, Loc),
12680 Attribute_Name => Name_Pos,
12681 Expressions => New_List (
12682 Make_Attribute_Reference (Loc,
12684 New_Reference_To (Index_Typ, Loc),
12685 Attribute_Name => Name_First)))))));
12689 end Install_Private_Data_Declarations;
12691 ---------------------------------
12692 -- Is_Potentially_Large_Family --
12693 ---------------------------------
12695 function Is_Potentially_Large_Family
12696 (Base_Index : Entity_Id;
12697 Conctyp : Entity_Id;
12699 Hi : Node_Id) return Boolean
12702 return Scope (Base_Index) = Standard_Standard
12703 and then Base_Index = Base_Type (Standard_Integer)
12704 and then Has_Discriminants (Conctyp)
12706 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12708 (Denotes_Discriminant (Lo, True)
12709 or else Denotes_Discriminant (Hi, True));
12710 end Is_Potentially_Large_Family;
12712 -------------------------------------
12713 -- Is_Private_Primitive_Subprogram --
12714 -------------------------------------
12716 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12719 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12720 and then Is_Private_Primitive (Id);
12721 end Is_Private_Primitive_Subprogram;
12727 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12728 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12729 Formal : Entity_Id;
12732 Formal := First_Formal (Bod_Subp);
12733 while Present (Formal) loop
12735 -- Look for formal parameter _E
12737 if Chars (Formal) = Name_uE then
12741 Next_Formal (Formal);
12744 -- A protected body subprogram should always have the parameter in
12747 raise Program_Error;
12750 --------------------------------
12751 -- Make_Initialize_Protection --
12752 --------------------------------
12754 function Make_Initialize_Protection
12755 (Protect_Rec : Entity_Id) return List_Id
12757 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12761 Ptyp : constant Node_Id :=
12762 Corresponding_Concurrent_Type (Protect_Rec);
12764 L : constant List_Id := New_List;
12765 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12766 Restricted : constant Boolean := Restricted_Profile;
12769 -- We may need two calls to properly initialize the object, one to
12770 -- Initialize_Protection, and possibly one to Install_Handlers if we
12771 -- have a pragma Attach_Handler.
12773 -- Get protected declaration. In the case of a task type declaration,
12774 -- this is simply the parent of the protected type entity. In the single
12775 -- protected object declaration, this parent will be the implicit type,
12776 -- and we can find the corresponding single protected object declaration
12777 -- by searching forward in the declaration list in the tree.
12779 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12780 -- of this type should have been removed during semantic analysis.
12782 Pdec := Parent (Ptyp);
12783 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12784 N_Single_Protected_Declaration)
12789 -- Now we can find the object definition from this declaration
12791 Pdef := Protected_Definition (Pdec);
12793 -- Build the parameter list for the call. Note that _Init is the name
12794 -- of the formal for the object to be initialized, which is the task
12795 -- value record itself.
12799 -- Object parameter. This is a pointer to the object of type
12800 -- Protection used by the GNARL to control the protected object.
12803 Make_Attribute_Reference (Loc,
12805 Make_Selected_Component (Loc,
12806 Prefix => Make_Identifier (Loc, Name_uInit),
12807 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12808 Attribute_Name => Name_Unchecked_Access));
12810 -- Priority parameter. Set to Unspecified_Priority unless there is a
12811 -- priority pragma, in which case we take the value from the pragma,
12812 -- or there is an interrupt pragma and no priority pragma, and we
12813 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12814 -- defined value, see D.3(10).
12817 and then Has_Pragma_Priority (Pdef)
12820 Prio : constant Node_Id :=
12823 (Pragma_Argument_Associations
12824 (Find_Task_Or_Protected_Pragma
12825 (Pdef, Name_Priority))));
12829 -- If priority is a static expression, then we can duplicate it
12830 -- with no problem and simply append it to the argument list.
12832 if Is_Static_Expression (Prio) then
12834 Duplicate_Subexpr_No_Checks (Prio));
12836 -- Otherwise, the priority may be a per-object expression, if it
12837 -- depends on a discriminant of the type. In this case, create
12838 -- local variable to capture the expression. Note that it is
12839 -- really necessary to create this variable explicitly. It might
12840 -- be thought that removing side effects would the appropriate
12841 -- approach, but that could generate declarations improperly
12842 -- placed in the enclosing scope.
12844 -- Note: Use System.Any_Priority as the expected type for the
12845 -- non-static priority expression, in case the expression has not
12846 -- been analyzed yet (as occurs for example with pragma
12847 -- Interrupt_Priority).
12850 Temp := Make_Temporary (Loc, 'R', Prio);
12852 Make_Object_Declaration (Loc,
12853 Defining_Identifier => Temp,
12854 Object_Definition =>
12855 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12856 Expression => Relocate_Node (Prio)));
12858 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12862 -- When no priority is specified but an xx_Handler pragma is, we default
12863 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12865 elsif Has_Attach_Handler (Ptyp)
12866 or else Has_Interrupt_Handler (Ptyp)
12869 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12871 -- Normal case, no priority or xx_Handler specified, default priority
12875 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12878 -- Test for Compiler_Info parameter. This parameter allows entry body
12879 -- procedures and barrier functions to be called from the runtime. It
12880 -- is a pointer to the record generated by the compiler to represent
12881 -- the protected object.
12883 -- A protected type without entries that covers an interface and
12884 -- overrides the abstract routines with protected procedures is
12885 -- considered equivalent to a protected type with entries in the
12886 -- context of dispatching select statements.
12889 or else Has_Interfaces (Protect_Rec)
12891 ((Has_Attach_Handler (Ptyp) or else Has_Interrupt_Handler (Ptyp))
12892 and then not Restriction_Active (No_Dynamic_Attachment))
12895 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
12897 Called_Subp : RE_Id;
12901 when System_Tasking_Protected_Objects_Entries =>
12902 Called_Subp := RE_Initialize_Protection_Entries;
12904 when System_Tasking_Protected_Objects =>
12905 Called_Subp := RE_Initialize_Protection;
12907 when System_Tasking_Protected_Objects_Single_Entry =>
12908 Called_Subp := RE_Initialize_Protection_Entry;
12911 raise Program_Error;
12915 or else not Restricted
12916 or else Has_Interfaces (Protect_Rec)
12919 Make_Attribute_Reference (Loc,
12920 Prefix => Make_Identifier (Loc, Name_uInit),
12921 Attribute_Name => Name_Address));
12924 -- Entry_Bodies parameter. This is a pointer to an array of
12925 -- pointers to the entry body procedures and barrier functions of
12926 -- the object. If the protected type has no entries this object
12927 -- will not exist, in this case, pass a null.
12930 P_Arr := Entry_Bodies_Array (Ptyp);
12933 Make_Attribute_Reference (Loc,
12934 Prefix => New_Reference_To (P_Arr, Loc),
12935 Attribute_Name => Name_Unrestricted_Access));
12937 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12939 -- Find index mapping function (clumsy but ok for now)
12941 while Ekind (P_Arr) /= E_Function loop
12942 Next_Entity (P_Arr);
12946 Make_Attribute_Reference (Loc,
12947 Prefix => New_Reference_To (P_Arr, Loc),
12948 Attribute_Name => Name_Unrestricted_Access));
12950 -- Build_Entry_Names generation flag. When set to true, the
12951 -- runtime will allocate an array to hold the string names
12952 -- of protected entries.
12954 if not Restricted_Profile then
12955 if Entry_Names_OK then
12957 New_Reference_To (Standard_True, Loc));
12960 New_Reference_To (Standard_False, Loc));
12965 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12966 Append_To (Args, Make_Null (Loc));
12968 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12969 Append_To (Args, Make_Null (Loc));
12970 Append_To (Args, Make_Null (Loc));
12971 Append_To (Args, New_Reference_To (Standard_False, Loc));
12975 Make_Procedure_Call_Statement (Loc,
12976 Name => New_Reference_To (RTE (Called_Subp), Loc),
12977 Parameter_Associations => Args));
12981 Make_Procedure_Call_Statement (Loc,
12982 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12983 Parameter_Associations => Args));
12986 if Has_Attach_Handler (Ptyp) then
12988 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12989 -- make the following call:
12991 -- Install_Handlers (_object,
12992 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12994 -- or, in the case of Ravenscar:
12996 -- Install_Restricted_Handlers
12997 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13000 Args : constant List_Id := New_List;
13001 Table : constant List_Id := New_List;
13002 Ritem : Node_Id := First_Rep_Item (Ptyp);
13005 -- Build the Attach_Handler table argument
13007 while Present (Ritem) loop
13008 if Nkind (Ritem) = N_Pragma
13009 and then Pragma_Name (Ritem) = Name_Attach_Handler
13012 Handler : constant Node_Id :=
13013 First (Pragma_Argument_Associations (Ritem));
13015 Interrupt : constant Node_Id := Next (Handler);
13016 Expr : constant Node_Id := Expression (Interrupt);
13020 Make_Aggregate (Loc, Expressions => New_List (
13021 Unchecked_Convert_To
13022 (RTE (RE_System_Interrupt_Id), Expr),
13023 Make_Attribute_Reference (Loc,
13024 Prefix => Make_Selected_Component (Loc,
13025 Make_Identifier (Loc, Name_uInit),
13026 Duplicate_Subexpr_No_Checks
13027 (Expression (Handler))),
13028 Attribute_Name => Name_Access))));
13032 Next_Rep_Item (Ritem);
13035 -- Append the table argument we just built
13037 Append_To (Args, Make_Aggregate (Loc, Table));
13039 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13040 -- call to the statements.
13043 -- Call a simplified version of Install_Handlers to be used
13044 -- when the Ravenscar restrictions are in effect
13045 -- (Install_Restricted_Handlers).
13048 Make_Procedure_Call_Statement (Loc,
13051 (RTE (RE_Install_Restricted_Handlers), Loc),
13052 Parameter_Associations => Args));
13055 -- First, prepends the _object argument
13058 Make_Attribute_Reference (Loc,
13060 Make_Selected_Component (Loc,
13061 Prefix => Make_Identifier (Loc, Name_uInit),
13062 Selector_Name => Make_Identifier (Loc, Name_uObject)),
13063 Attribute_Name => Name_Unchecked_Access));
13065 -- Then, insert call to Install_Handlers
13068 Make_Procedure_Call_Statement (Loc,
13069 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
13070 Parameter_Associations => Args));
13076 end Make_Initialize_Protection;
13078 ---------------------------
13079 -- Make_Task_Create_Call --
13080 ---------------------------
13082 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
13083 Loc : constant Source_Ptr := Sloc (Task_Rec);
13093 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
13094 Tnam := Chars (Ttyp);
13096 -- Get task declaration. In the case of a task type declaration, this is
13097 -- simply the parent of the task type entity. In the single task
13098 -- declaration, this parent will be the implicit type, and we can find
13099 -- the corresponding single task declaration by searching forward in the
13100 -- declaration list in the tree.
13102 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13103 -- this type should have been removed during semantic analysis.
13105 Tdec := Parent (Ttyp);
13106 while not Nkind_In (Tdec, N_Task_Type_Declaration,
13107 N_Single_Task_Declaration)
13112 -- Now we can find the task definition from this declaration
13114 Tdef := Task_Definition (Tdec);
13116 -- Build the parameter list for the call. Note that _Init is the name
13117 -- of the formal for the object to be initialized, which is the task
13118 -- value record itself.
13122 -- Priority parameter. Set to Unspecified_Priority unless there is a
13123 -- priority pragma, in which case we take the value from the pragma.
13125 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
13127 Make_Selected_Component (Loc,
13128 Prefix => Make_Identifier (Loc, Name_uInit),
13129 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
13132 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
13135 -- Optional Stack parameter
13137 if Restricted_Profile then
13139 -- If the stack has been preallocated by the expander then
13140 -- pass its address. Otherwise, pass a null address.
13142 if Preallocated_Stacks_On_Target then
13144 Make_Attribute_Reference (Loc,
13146 Make_Selected_Component (Loc,
13147 Prefix => Make_Identifier (Loc, Name_uInit),
13148 Selector_Name => Make_Identifier (Loc, Name_uStack)),
13149 Attribute_Name => Name_Address));
13153 New_Reference_To (RTE (RE_Null_Address), Loc));
13157 -- Size parameter. If no Storage_Size pragma is present, then
13158 -- the size is taken from the taskZ variable for the type, which
13159 -- is either Unspecified_Size, or has been reset by the use of
13160 -- a Storage_Size attribute definition clause. If a pragma is
13161 -- present, then the size is taken from the _Size field of the
13162 -- task value record, which was set from the pragma value.
13165 and then Has_Storage_Size_Pragma (Tdef)
13168 Make_Selected_Component (Loc,
13169 Prefix => Make_Identifier (Loc, Name_uInit),
13170 Selector_Name => Make_Identifier (Loc, Name_uSize)));
13174 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
13177 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
13178 -- Task_Info pragma, in which case we take the value from the pragma.
13181 and then Has_Task_Info_Pragma (Tdef)
13184 Make_Selected_Component (Loc,
13185 Prefix => Make_Identifier (Loc, Name_uInit),
13186 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
13190 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
13193 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
13194 -- in which case we take the value from the pragma. The parameter is
13195 -- passed as an Integer because in the case of unspecified CPU the
13196 -- value is not in the range of CPU_Range.
13198 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
13200 Convert_To (Standard_Integer,
13201 Make_Selected_Component (Loc,
13202 Prefix => Make_Identifier (Loc, Name_uInit),
13203 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
13207 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
13210 if not Restricted_Profile then
13212 -- Deadline parameter. If no Relative_Deadline pragma is present,
13213 -- then the deadline is Time_Span_Zero. If a pragma is present, then
13214 -- the deadline is taken from the _Relative_Deadline field of the
13215 -- task value record, which was set from the pragma value. Note that
13216 -- this parameter must not be generated for the restricted profiles
13217 -- since Ravenscar does not allow deadlines.
13219 -- Case where pragma Relative_Deadline applies: use given value
13221 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
13223 Make_Selected_Component (Loc,
13225 Make_Identifier (Loc, Name_uInit),
13227 Make_Identifier (Loc, Name_uRelative_Deadline)));
13229 -- No pragma Relative_Deadline apply to the task
13233 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
13236 -- Dispatching_Domain parameter. If no Dispatching_Domain pragma or
13237 -- aspect is present, then the dispatching domain is null. If a
13238 -- pragma or aspect is present, then the dispatching domain is taken
13239 -- from the _Dispatching_Domain field of the task value record,
13240 -- which was set from the pragma value. Note that this parameter
13241 -- must not be generated for the restricted profiles since Ravenscar
13242 -- does not allow dispatching domains.
13244 -- Case where pragma or aspect Dispatching_Domain applies: use given
13247 if Present (Tdef) and then Has_Pragma_Dispatching_Domain (Tdef) then
13249 Make_Selected_Component (Loc,
13251 Make_Identifier (Loc, Name_uInit),
13253 Make_Identifier (Loc, Name_uDispatching_Domain)));
13255 -- No pragma or aspect Dispatching_Domain apply to the task
13258 Append_To (Args, Make_Null (Loc));
13261 -- Number of entries. This is an expression of the form:
13263 -- n + _Init.a'Length + _Init.a'B'Length + ...
13265 -- where a,b... are the entry family names for the task definition
13268 Build_Entry_Count_Expression
13273 (Parent (Corresponding_Record_Type (Ttyp))))),
13275 Append_To (Args, Ecount);
13277 -- Master parameter. This is a reference to the _Master parameter of
13278 -- the initialization procedure, except in the case of the pragma
13279 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
13280 -- System.Tasking.Library_Task_Level.
13282 if Restriction_Active (No_Task_Hierarchy) = False then
13283 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
13286 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
13290 -- State parameter. This is a pointer to the task body procedure. The
13291 -- required value is obtained by taking 'Unrestricted_Access of the task
13292 -- body procedure and converting it (with an unchecked conversion) to
13293 -- the type required by the task kernel. For further details, see the
13294 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
13295 -- than 'Address in order to avoid creating trampolines.
13298 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
13299 Subp_Ptr_Typ : constant Node_Id :=
13300 Create_Itype (E_Access_Subprogram_Type, Tdec);
13301 Ref : constant Node_Id := Make_Itype_Reference (Loc);
13304 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
13305 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
13307 -- Be sure to freeze a reference to the access-to-subprogram type,
13308 -- otherwise gigi will complain that it's in the wrong scope, because
13309 -- it's actually inside the init procedure for the record type that
13310 -- corresponds to the task type.
13312 -- This processing is causing a crash in the .NET/JVM back ends that
13313 -- is not yet understood, so skip it in these cases ???
13315 if VM_Target = No_VM then
13316 Set_Itype (Ref, Subp_Ptr_Typ);
13317 Append_Freeze_Action (Task_Rec, Ref);
13320 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
13321 Make_Qualified_Expression (Loc,
13322 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
13324 Make_Attribute_Reference (Loc,
13326 New_Occurrence_Of (Body_Proc, Loc),
13327 Attribute_Name => Name_Unrestricted_Access))));
13329 -- For the .NET/JVM cases revert to the original code below ???
13333 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
13334 Make_Attribute_Reference (Loc,
13336 New_Occurrence_Of (Body_Proc, Loc),
13337 Attribute_Name => Name_Address)));
13341 -- Discriminants parameter. This is just the address of the task
13342 -- value record itself (which contains the discriminant values
13345 Make_Attribute_Reference (Loc,
13346 Prefix => Make_Identifier (Loc, Name_uInit),
13347 Attribute_Name => Name_Address));
13349 -- Elaborated parameter. This is an access to the elaboration Boolean
13352 Make_Attribute_Reference (Loc,
13353 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
13354 Attribute_Name => Name_Unchecked_Access));
13356 -- Chain parameter. This is a reference to the _Chain parameter of
13357 -- the initialization procedure.
13359 Append_To (Args, Make_Identifier (Loc, Name_uChain));
13361 -- Task name parameter. Take this from the _Task_Id parameter to the
13362 -- init call unless there is a Task_Name pragma, in which case we take
13363 -- the value from the pragma.
13366 and then Has_Task_Name_Pragma (Tdef)
13368 -- Copy expression in full, because it may be dynamic and have
13374 (Pragma_Argument_Associations
13375 (Find_Task_Or_Protected_Pragma
13376 (Tdef, Name_Task_Name))))));
13379 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
13382 -- Created_Task parameter. This is the _Task_Id field of the task
13386 Make_Selected_Component (Loc,
13387 Prefix => Make_Identifier (Loc, Name_uInit),
13388 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
13390 -- Build_Entry_Names generation flag. When set to true, the runtime
13391 -- will allocate an array to hold the string names of task entries.
13393 if not Restricted_Profile then
13394 if Has_Entries (Ttyp)
13395 and then Entry_Names_OK
13397 Append_To (Args, New_Reference_To (Standard_True, Loc));
13399 Append_To (Args, New_Reference_To (Standard_False, Loc));
13403 if Restricted_Profile then
13404 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
13406 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
13410 Make_Procedure_Call_Statement (Loc,
13412 Parameter_Associations => Args);
13413 end Make_Task_Create_Call;
13415 ------------------------------
13416 -- Next_Protected_Operation --
13417 ------------------------------
13419 function Next_Protected_Operation (N : Node_Id) return Node_Id is
13423 Next_Op := Next (N);
13424 while Present (Next_Op)
13425 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
13431 end Next_Protected_Operation;
13433 ---------------------
13434 -- Null_Statements --
13435 ---------------------
13437 function Null_Statements (Stats : List_Id) return Boolean is
13441 Stmt := First (Stats);
13442 while Nkind (Stmt) /= N_Empty
13443 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
13445 (Nkind (Stmt) = N_Pragma
13446 and then (Pragma_Name (Stmt) = Name_Unreferenced
13448 Pragma_Name (Stmt) = Name_Unmodified
13450 Pragma_Name (Stmt) = Name_Warnings)))
13455 return Nkind (Stmt) = N_Empty;
13456 end Null_Statements;
13458 --------------------------
13459 -- Parameter_Block_Pack --
13460 --------------------------
13462 function Parameter_Block_Pack
13464 Blk_Typ : Entity_Id;
13468 Stmts : List_Id) return Node_Id
13470 Actual : Entity_Id;
13471 Expr : Node_Id := Empty;
13472 Formal : Entity_Id;
13473 Has_Param : Boolean := False;
13476 Temp_Asn : Node_Id;
13477 Temp_Nam : Node_Id;
13480 Actual := First (Actuals);
13481 Formal := Defining_Identifier (First (Formals));
13482 Params := New_List;
13484 while Present (Actual) loop
13485 if Is_By_Copy_Type (Etype (Actual)) then
13487 -- Jnn : aliased <formal-type>
13489 Temp_Nam := Make_Temporary (Loc, 'J');
13492 Make_Object_Declaration (Loc,
13495 Defining_Identifier =>
13497 Object_Definition =>
13498 New_Reference_To (Etype (Formal), Loc)));
13500 if Ekind (Formal) /= E_Out_Parameter then
13506 New_Reference_To (Temp_Nam, Loc);
13508 Set_Assignment_OK (Temp_Asn);
13511 Make_Assignment_Statement (Loc,
13515 New_Copy_Tree (Actual)));
13519 -- Jnn'unchecked_access
13522 Make_Attribute_Reference (Loc,
13524 Name_Unchecked_Access,
13526 New_Reference_To (Temp_Nam, Loc)));
13530 -- The controlling parameter is omitted
13533 if not Is_Controlling_Actual (Actual) then
13535 Make_Reference (Loc, New_Copy_Tree (Actual)));
13541 Next_Actual (Actual);
13542 Next_Formal_With_Extras (Formal);
13546 Expr := Make_Aggregate (Loc, Params);
13551 -- J1'unchecked_access;
13552 -- <actual2>'reference;
13555 P := Make_Temporary (Loc, 'P');
13558 Make_Object_Declaration (Loc,
13559 Defining_Identifier =>
13561 Object_Definition =>
13562 New_Reference_To (Blk_Typ, Loc),
13567 end Parameter_Block_Pack;
13569 ----------------------------
13570 -- Parameter_Block_Unpack --
13571 ----------------------------
13573 function Parameter_Block_Unpack
13577 Formals : List_Id) return List_Id
13579 Actual : Entity_Id;
13581 Formal : Entity_Id;
13582 Has_Asnmt : Boolean := False;
13583 Result : constant List_Id := New_List;
13586 Actual := First (Actuals);
13587 Formal := Defining_Identifier (First (Formals));
13588 while Present (Actual) loop
13589 if Is_By_Copy_Type (Etype (Actual))
13590 and then Ekind (Formal) /= E_In_Parameter
13593 -- <actual> := P.<formal>;
13596 Make_Assignment_Statement (Loc,
13600 Make_Explicit_Dereference (Loc,
13601 Make_Selected_Component (Loc,
13603 New_Reference_To (P, Loc),
13605 Make_Identifier (Loc, Chars (Formal)))));
13607 Set_Assignment_OK (Name (Asnmt));
13608 Append_To (Result, Asnmt);
13613 Next_Actual (Actual);
13614 Next_Formal_With_Extras (Formal);
13620 return New_List (Make_Null_Statement (Loc));
13622 end Parameter_Block_Unpack;
13624 ----------------------
13625 -- Set_Discriminals --
13626 ----------------------
13628 procedure Set_Discriminals (Dec : Node_Id) is
13631 D_Minal : Entity_Id;
13634 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13635 Pdef := Defining_Identifier (Dec);
13637 if Has_Discriminants (Pdef) then
13638 D := First_Discriminant (Pdef);
13639 while Present (D) loop
13641 Make_Defining_Identifier (Sloc (D),
13642 Chars => New_External_Name (Chars (D), 'D'));
13644 Set_Ekind (D_Minal, E_Constant);
13645 Set_Etype (D_Minal, Etype (D));
13646 Set_Scope (D_Minal, Pdef);
13647 Set_Discriminal (D, D_Minal);
13648 Set_Discriminal_Link (D_Minal, D);
13650 Next_Discriminant (D);
13653 end Set_Discriminals;
13655 -----------------------
13656 -- Trivial_Accept_OK --
13657 -----------------------
13659 function Trivial_Accept_OK return Boolean is
13661 case Opt.Task_Dispatching_Policy is
13663 -- If we have the default task dispatching policy in effect, we can
13664 -- definitely do the optimization (one way of looking at this is to
13665 -- think of the formal definition of the default policy being allowed
13666 -- to run any task it likes after a rendezvous, so even if notionally
13667 -- a full rescheduling occurs, we can say that our dispatching policy
13668 -- (i.e. the default dispatching policy) reorders the queue to be the
13669 -- same as just before the call.
13674 -- FIFO_Within_Priorities certainly does not permit this
13675 -- optimization since the Rendezvous is a scheduling action that may
13676 -- require some other task to be run.
13681 -- For now, disallow the optimization for all other policies. This
13682 -- may be over-conservative, but it is certainly not incorrect.
13688 end Trivial_Accept_OK;