1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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. It will be lifted when protected
75 -- entry families are re-implemented as a single ordered queue.
77 Entry_Family_Bound : constant Int := 2**16;
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 function Actual_Index_Expression
87 Tsk : Entity_Id) return Node_Id;
88 -- Compute the index position for an entry call. Tsk is the target task. If
89 -- the bounds of some entry family depend on discriminants, the expression
90 -- computed by this function uses the discriminants of the target task.
92 procedure Add_Object_Pointer
96 -- Prepend an object pointer declaration to the declaration list Decls.
97 -- This object pointer is initialized to a type conversion of the System.
98 -- Address pointer passed to entry barrier functions and entry body
101 procedure Add_Formal_Renamings
106 -- Create renaming declarations for the formals, inside the procedure that
107 -- implements an entry body. The renamings make the original names of the
108 -- formals accessible to gdb, and serve no other purpose.
109 -- Spec is the specification of the procedure being built.
110 -- Decls is the list of declarations to be enhanced.
111 -- Ent is the entity for the original entry body.
113 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
114 -- Transform accept statement into a block with added exception handler.
115 -- Used both for simple accept statements and for accept alternatives in
116 -- select statements. Astat is the accept statement.
118 function Build_Barrier_Function
121 Pid : Node_Id) return Node_Id;
122 -- Build the function body returning the value of the barrier expression
123 -- for the specified entry body.
125 function Build_Barrier_Function_Specification
127 Def_Id : Entity_Id) return Node_Id;
128 -- Build a specification for a function implementing the protected entry
129 -- barrier of the specified entry body.
131 function Build_Corresponding_Record
134 Loc : Source_Ptr) return Node_Id;
135 -- Common to tasks and protected types. Copy discriminant specifications,
136 -- build record declaration. N is the type declaration, Ctyp is the
137 -- concurrent entity (task type or protected type).
139 function Build_Entry_Count_Expression
140 (Concurrent_Type : Node_Id;
141 Component_List : List_Id;
142 Loc : Source_Ptr) return Node_Id;
143 -- Compute number of entries for concurrent object. This is a count of
144 -- simple entries, followed by an expression that computes the length
145 -- of the range of each entry family. A single array with that size is
146 -- allocated for each concurrent object of the type.
148 function Build_Parameter_Block
152 Decls : List_Id) return Entity_Id;
153 -- Generate an access type for each actual parameter in the list Actuals.
154 -- Create an encapsulating record that contains all the actuals and return
155 -- its type. Generate:
156 -- type Ann1 is access all <actual1-type>
158 -- type AnnN is access all <actualN-type>
159 -- type Pnn is record
165 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id);
166 -- Build body of wrapper procedure for an entry or entry family that has
167 -- pre/postconditions. The body gathers the PPC's and expands them in the
168 -- usual way, and performs the entry call itself. This way preconditions
169 -- are evaluated before the call is queued. E is the entry in question,
170 -- and Decl is the enclosing synchronized type declaration at whose
171 -- freeze point the generated body is analyzed.
173 procedure Build_Wrapper_Bodies
177 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
178 -- record of a concurrent type. N is the insertion node where all bodies
179 -- will be placed. This routine builds the bodies of the subprograms which
180 -- serve as an indirection mechanism to overriding primitives of concurrent
181 -- types, entries and protected procedures. Any new body is analyzed.
183 procedure Build_Wrapper_Specs
187 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
188 -- record of a concurrent type. N is the insertion node where all specs
189 -- will be placed. This routine builds the specs of the subprograms which
190 -- serve as an indirection mechanism to overriding primitives of concurrent
191 -- types, entries and protected procedures. Any new spec is analyzed.
193 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
194 -- Build the function that translates the entry index in the call
195 -- (which depends on the size of entry families) into an index into the
196 -- Entry_Bodies_Array, to determine the body and barrier function used
197 -- in a protected entry call. A pointer to this function appears in every
200 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
201 -- Build subprogram declaration for previous one
203 function Build_Protected_Entry
206 Pid : Node_Id) return Node_Id;
207 -- Build the procedure implementing the statement sequence of the specified
210 function Build_Protected_Entry_Specification
213 Ent_Id : Entity_Id) return Node_Id;
214 -- Build a specification for the procedure implementing the statements of
215 -- the specified entry body. Add attributes associating it with the entry
216 -- defining identifier Ent_Id.
218 function Build_Protected_Spec
220 Obj_Type : Entity_Id;
222 Unprotected : Boolean := False) return List_Id;
223 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
224 -- Subprogram_Type. Builds signature of protected subprogram, adding the
225 -- formal that corresponds to the object itself. For an access to protected
226 -- subprogram, there is no object type to specify, so the parameter has
227 -- type Address and mode In. An indirect call through such a pointer will
228 -- convert the address to a reference to the actual object. The object is
229 -- a limited record and therefore a by_reference type.
231 function Build_Protected_Subprogram_Body
234 N_Op_Spec : Node_Id) return Node_Id;
235 -- This function is used to construct the protected version of a protected
236 -- subprogram. Its statement sequence first defers abort, then locks
237 -- the associated protected object, and then enters a block that contains
238 -- a call to the unprotected version of the subprogram (for details, see
239 -- Build_Unprotected_Subprogram_Body). This block statement requires
240 -- a cleanup handler that unlocks the object in all cases.
241 -- (see Exp_Ch7.Expand_Cleanup_Actions).
243 function Build_Selected_Name
245 Selector : Entity_Id;
246 Append_Char : Character := ' ') return Name_Id;
247 -- Build a name in the form of Prefix__Selector, with an optional
248 -- character appended. This is used for internal subprograms generated
249 -- for operations of protected types, including barrier functions.
250 -- For the subprograms generated for entry bodies and entry barriers,
251 -- the generated name includes a sequence number that makes names
252 -- unique in the presence of entry overloading. This is necessary
253 -- because entry body procedures and barrier functions all have the
256 procedure Build_Simple_Entry_Call
261 -- Some comments here would be useful ???
263 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
264 -- This routine constructs a specification for the procedure that we will
265 -- build for the task body for task type T. The spec has the form:
267 -- procedure tnameB (_Task : access tnameV);
269 -- where name is the character name taken from the task type entity that
270 -- is passed as the argument to the procedure, and tnameV is the task
271 -- value type that is associated with the task type.
273 function Build_Unprotected_Subprogram_Body
275 Pid : Node_Id) return Node_Id;
276 -- This routine constructs the unprotected version of a protected
277 -- subprogram body, which is contains all of the code in the
278 -- original, unexpanded body. This is the version of the protected
279 -- subprogram that is called from all protected operations on the same
280 -- object, including the protected version of the same subprogram.
282 procedure Collect_Entry_Families
285 Current_Node : in out Node_Id;
286 Conctyp : Entity_Id);
287 -- For each entry family in a concurrent type, create an anonymous array
288 -- type of the right size, and add a component to the corresponding_record.
290 function Concurrent_Object
291 (Spec_Id : Entity_Id;
292 Conc_Typ : Entity_Id) return Entity_Id;
293 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
294 -- the entity associated with the concurrent object in the Protected_Body_
295 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
296 -- denotes formal parameter _O, _object or _task.
298 function Copy_Result_Type (Res : Node_Id) return Node_Id;
299 -- Copy the result type of a function specification, when building the
300 -- internal operation corresponding to a protected function, or when
301 -- expanding an access to protected function. If the result is an anonymous
302 -- access to subprogram itself, we need to create a new signature with the
303 -- same parameter names and the same resolved types, but with new entities
306 procedure Debug_Private_Data_Declarations (Decls : List_Id);
307 -- Decls is a list which may contain the declarations created by Install_
308 -- Private_Data_Declarations. All generated entities are marked as needing
309 -- debug info and debug nodes are manually generation where necessary. This
310 -- step of the expansion must to be done after private data has been moved
311 -- to its final resting scope to ensure proper visibility of debug objects.
313 function Family_Offset
318 Cap : Boolean) return Node_Id;
319 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
320 -- an accept statement, or the upper bound in the discrete subtype of
321 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
322 -- the concurrent type of the entry. If Cap is true, the result is
323 -- capped according to Entry_Family_Bound.
330 Cap : Boolean) return Node_Id;
331 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
332 -- a family, and handle properly the superflat case. This is equivalent
333 -- to the use of 'Length on the index type, but must use Family_Offset
334 -- to handle properly the case of bounds that depend on discriminants.
335 -- If Cap is true, the result is capped according to Entry_Family_Bound.
337 procedure Extract_Dispatching_Call
339 Call_Ent : out Entity_Id;
340 Object : out Entity_Id;
341 Actuals : out List_Id;
342 Formals : out List_Id);
343 -- Given a dispatching call, extract the entity of the name of the call,
344 -- its object parameter, its actual parameters and the formal parameters
345 -- of the overridden interface-level version.
347 procedure Extract_Entry
349 Concval : out Node_Id;
351 Index : out Node_Id);
352 -- Given an entry call, returns the associated concurrent object,
353 -- the entry name, and the entry family index.
355 function Find_Task_Or_Protected_Pragma
357 P : Name_Id) return Node_Id;
358 -- Searches the task or protected definition T for the first occurrence
359 -- of the pragma whose name is given by P. The caller has ensured that
360 -- the pragma is present in the task definition. A special case is that
361 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
362 -- ??? Should be implemented with the rep item chain mechanism.
364 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
365 -- Given a subprogram identifier, return the entity which is associated
366 -- with the protection entry index in the Protected_Body_Subprogram or the
367 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
370 function Is_Potentially_Large_Family
371 (Base_Index : Entity_Id;
374 Hi : Node_Id) return Boolean;
376 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
377 -- Determine whether Id is a function or a procedure and is marked as a
378 -- private primitive.
380 function Null_Statements (Stats : List_Id) return Boolean;
381 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
382 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
383 -- well to still count as null. Returns True for a null sequence. The
384 -- argument is the list of statements from the DO-END sequence.
386 function Parameter_Block_Pack
392 Stmts : List_Id) return Entity_Id;
393 -- Set the components of the generated parameter block with the values of
394 -- the actual parameters. Generate aliased temporaries to capture the
395 -- values for types that are passed by copy. Otherwise generate a reference
396 -- to the actual's value. Return the address of the aggregate block.
398 -- Jnn1 : alias <formal-type1>;
399 -- Jnn1 := <actual1>;
402 -- Jnn1'unchecked_access;
403 -- <actual2>'reference;
406 function Parameter_Block_Unpack
410 Formals : List_Id) return List_Id;
411 -- Retrieve the values of the components from the parameter block and
412 -- assign then to the original actual parameters. Generate:
413 -- <actual1> := P.<formal1>;
415 -- <actualN> := P.<formalN>;
417 function Trivial_Accept_OK return Boolean;
418 -- If there is no DO-END block for an accept, or if the DO-END block has
419 -- only null statements, then it is possible to do the Rendezvous with much
420 -- less overhead using the Accept_Trivial routine in the run-time library.
421 -- However, this is not always a valid optimization. Whether it is valid or
422 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
423 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
424 -- a rescheduling is required, so this optimization is not allowed. This
425 -- function returns True if the optimization is permitted.
427 -----------------------------
428 -- Actual_Index_Expression --
429 -----------------------------
431 function Actual_Index_Expression
435 Tsk : Entity_Id) return Node_Id
437 Ttyp : constant Entity_Id := Etype (Tsk);
445 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
446 -- Compute difference between bounds of entry family
448 --------------------------
449 -- Actual_Family_Offset --
450 --------------------------
452 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
454 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
455 -- Replace a reference to a discriminant with a selected component
456 -- denoting the discriminant of the target task.
458 -----------------------------
459 -- Actual_Discriminant_Ref --
460 -----------------------------
462 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
463 Typ : constant Entity_Id := Etype (Bound);
467 if not Is_Entity_Name (Bound)
468 or else Ekind (Entity (Bound)) /= E_Discriminant
470 if Nkind (Bound) = N_Attribute_Reference then
473 B := New_Copy_Tree (Bound);
478 Make_Selected_Component (Sloc,
479 Prefix => New_Copy_Tree (Tsk),
480 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
482 Analyze_And_Resolve (B, Typ);
486 Make_Attribute_Reference (Sloc,
487 Attribute_Name => Name_Pos,
488 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
489 Expressions => New_List (B));
490 end Actual_Discriminant_Ref;
492 -- Start of processing for Actual_Family_Offset
496 Make_Op_Subtract (Sloc,
497 Left_Opnd => Actual_Discriminant_Ref (Hi),
498 Right_Opnd => Actual_Discriminant_Ref (Lo));
499 end Actual_Family_Offset;
501 -- Start of processing for Actual_Index_Expression
504 -- The queues of entries and entry families appear in textual order in
505 -- the associated record. The entry index is computed as the sum of the
506 -- number of queues for all entries that precede the designated one, to
507 -- which is added the index expression, if this expression denotes a
508 -- member of a family.
510 -- The following is a place holder for the count of simple entries
512 Num := Make_Integer_Literal (Sloc, 1);
514 -- We construct an expression which is a series of addition operations.
515 -- See comments in Entry_Index_Expression, which is identical in
518 if Present (Index) then
519 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
526 Actual_Family_Offset (
527 Make_Attribute_Reference (Sloc,
528 Attribute_Name => Name_Pos,
529 Prefix => New_Reference_To (Base_Type (S), Sloc),
530 Expressions => New_List (Relocate_Node (Index))),
531 Type_Low_Bound (S)));
536 -- Now add lengths of preceding entries and entry families
538 Prev := First_Entity (Ttyp);
540 while Chars (Prev) /= Chars (Ent)
541 or else (Ekind (Prev) /= Ekind (Ent))
542 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
544 if Ekind (Prev) = E_Entry then
545 Set_Intval (Num, Intval (Num) + 1);
547 elsif Ekind (Prev) = E_Entry_Family then
549 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
551 -- The need for the following full view retrieval stems from
552 -- this complex case of nested generics and tasking:
555 -- type Formal_Index is range <>;
558 -- type Index is private;
565 -- type Index is new Formal_Index range 1 .. 10;
568 -- package body Outer is
570 -- entry Fam (Index); -- (2)
573 -- package body Inner is -- (3)
581 -- We are currently building the index expression for the entry
582 -- call "T.E" (1). Part of the expansion must mention the range
583 -- of the discrete type "Index" (2) of entry family "Fam".
584 -- However only the private view of type "Index" is available to
585 -- the inner generic (3) because there was no prior mention of
586 -- the type inside "Inner". This visibility requirement is
587 -- implicit and cannot be detected during the construction of
588 -- the generic trees and needs special handling.
591 and then Is_Private_Type (S)
592 and then Present (Full_View (S))
597 Lo := Type_Low_Bound (S);
598 Hi := Type_High_Bound (S);
606 Actual_Family_Offset (Hi, Lo),
608 Make_Integer_Literal (Sloc, 1)));
610 -- Other components are anonymous types to be ignored
620 end Actual_Index_Expression;
622 --------------------------
623 -- Add_Formal_Renamings --
624 --------------------------
626 procedure Add_Formal_Renamings
632 Ptr : constant Entity_Id :=
634 (Next (First (Parameter_Specifications (Spec))));
635 -- The name of the formal that holds the address of the parameter block
644 Formal := First_Formal (Ent);
645 while Present (Formal) loop
646 Comp := Entry_Component (Formal);
648 Make_Defining_Identifier (Sloc (Formal),
649 Chars => Chars (Formal));
650 Set_Etype (New_F, Etype (Formal));
651 Set_Scope (New_F, Ent);
653 -- Now we set debug info needed on New_F even though it does not
654 -- come from source, so that the debugger will get the right
655 -- information for these generated names.
657 Set_Debug_Info_Needed (New_F);
659 if Ekind (Formal) = E_In_Parameter then
660 Set_Ekind (New_F, E_Constant);
662 Set_Ekind (New_F, E_Variable);
663 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
666 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
669 Make_Object_Renaming_Declaration (Loc,
670 Defining_Identifier => New_F,
672 New_Reference_To (Etype (Formal), Loc),
674 Make_Explicit_Dereference (Loc,
675 Make_Selected_Component (Loc,
677 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
678 Make_Identifier (Loc, Chars (Ptr))),
680 New_Reference_To (Comp, Loc))));
682 Append (Decl, Decls);
683 Set_Renamed_Object (Formal, New_F);
684 Next_Formal (Formal);
686 end Add_Formal_Renamings;
688 ------------------------
689 -- Add_Object_Pointer --
690 ------------------------
692 procedure Add_Object_Pointer
694 Conc_Typ : Entity_Id;
697 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
702 -- Create the renaming declaration for the Protection object of a
703 -- protected type. _Object is used by Complete_Entry_Body.
704 -- ??? An attempt to make this a renaming was unsuccessful.
706 -- Build the entity for the access type
709 Make_Defining_Identifier (Loc,
710 New_External_Name (Chars (Rec_Typ), 'P'));
713 -- _object : poVP := poVP!O;
716 Make_Object_Declaration (Loc,
717 Defining_Identifier =>
718 Make_Defining_Identifier (Loc, Name_uObject),
720 New_Reference_To (Obj_Ptr, Loc),
722 Unchecked_Convert_To (Obj_Ptr,
723 Make_Identifier (Loc, Name_uO)));
724 Set_Debug_Info_Needed (Defining_Identifier (Decl));
725 Prepend_To (Decls, Decl);
728 -- type poVP is access poV;
731 Make_Full_Type_Declaration (Loc,
732 Defining_Identifier =>
735 Make_Access_To_Object_Definition (Loc,
736 Subtype_Indication =>
737 New_Reference_To (Rec_Typ, Loc)));
738 Set_Debug_Info_Needed (Defining_Identifier (Decl));
739 Prepend_To (Decls, Decl);
740 end Add_Object_Pointer;
742 -----------------------
743 -- Build_Accept_Body --
744 -----------------------
746 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
747 Loc : constant Source_Ptr := Sloc (Astat);
748 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
755 -- At the end of the statement sequence, Complete_Rendezvous is called.
756 -- A label skipping the Complete_Rendezvous, and all other accept
757 -- processing, has already been added for the expansion of requeue
758 -- statements. The Sloc is copied from the last statement since it
759 -- is really part of this last statement.
763 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
764 Insert_Before (Last (Statements (Stats)), Call);
767 -- If exception handlers are present, then append Complete_Rendezvous
768 -- calls to the handlers, and construct the required outer block. As
769 -- above, the Sloc is copied from the last statement in the sequence.
771 if Present (Exception_Handlers (Stats)) then
772 Hand := First (Exception_Handlers (Stats));
773 while Present (Hand) loop
776 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
777 Append (Call, Statements (Hand));
783 Make_Handled_Sequence_Of_Statements (Loc,
784 Statements => New_List (
785 Make_Block_Statement (Loc,
786 Handled_Statement_Sequence => Stats)));
792 -- At this stage we know that the new statement sequence does not
793 -- have an exception handler part, so we supply one to call
794 -- Exceptional_Complete_Rendezvous. This handler is
796 -- when all others =>
797 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
799 -- We handle Abort_Signal to make sure that we properly catch the abort
800 -- case and wake up the caller.
802 Ohandle := Make_Others_Choice (Loc);
803 Set_All_Others (Ohandle);
805 Set_Exception_Handlers (New_S,
807 Make_Implicit_Exception_Handler (Loc,
808 Exception_Choices => New_List (Ohandle),
810 Statements => New_List (
811 Make_Procedure_Call_Statement (Sloc (Stats),
812 Name => New_Reference_To (
813 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
814 Parameter_Associations => New_List (
815 Make_Function_Call (Sloc (Stats),
816 Name => New_Reference_To (
817 RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
819 Set_Parent (New_S, Astat); -- temp parent for Analyze call
820 Analyze_Exception_Handlers (Exception_Handlers (New_S));
821 Expand_Exception_Handlers (New_S);
823 -- Exceptional_Complete_Rendezvous must be called with abort
824 -- still deferred, which is the case for a "when all others" handler.
827 end Build_Accept_Body;
829 -----------------------------------
830 -- Build_Activation_Chain_Entity --
831 -----------------------------------
833 procedure Build_Activation_Chain_Entity (N : Node_Id) is
839 -- Loop to find enclosing construct containing activation chain variable
840 -- The construct is a body, a block, or an extended return.
844 while not Nkind_In (P, N_Subprogram_Body,
846 N_Package_Declaration,
850 N_Extended_Return_Statement)
855 -- If we are in a package body, the activation chain variable is
856 -- declared in the body, but the Activation_Chain_Entity is attached
859 if Nkind (P) = N_Package_Body then
860 Decls := Declarations (P);
861 P := Unit_Declaration_Node (Corresponding_Spec (P));
863 elsif Nkind (P) = N_Package_Declaration then
864 Decls := Visible_Declarations (Specification (P));
866 elsif Nkind (P) = N_Extended_Return_Statement then
867 Decls := Return_Object_Declarations (P);
870 Decls := Declarations (P);
873 -- If activation chain entity not already declared, declare it
875 if Nkind (P) = N_Extended_Return_Statement
876 or else No (Activation_Chain_Entity (P))
878 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
880 -- Note: An extended return statement is not really a task activator,
881 -- but it does have an activation chain on which to store the tasks
882 -- temporarily. On successful return, the tasks on this chain are
883 -- moved to the chain passed in by the caller. We do not build an
884 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
885 -- because we do not want to build a call to Activate_Tasks. Task
886 -- activation is the responsibility of the caller.
888 if Nkind (P) /= N_Extended_Return_Statement then
889 Set_Activation_Chain_Entity (P, Chain);
893 Make_Object_Declaration (Sloc (P),
894 Defining_Identifier => Chain,
895 Aliased_Present => True,
897 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
899 Analyze (First (Decls));
901 end Build_Activation_Chain_Entity;
903 ----------------------------
904 -- Build_Barrier_Function --
905 ----------------------------
907 function Build_Barrier_Function
910 Pid : Node_Id) return Node_Id
912 Loc : constant Source_Ptr := Sloc (N);
913 Func_Id : constant Entity_Id := Barrier_Function (Ent);
914 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
915 Op_Decls : constant List_Id := New_List;
919 -- Add a declaration for the Protection object, renaming declarations
920 -- for the discriminals and privals and finally a declaration for the
921 -- entry family index (if applicable).
923 Install_Private_Data_Declarations
924 (Loc, Func_Id, Pid, N, Op_Decls, True, Ekind (Ent) = E_Entry_Family);
926 -- Note: the condition in the barrier function needs to be properly
927 -- processed for the C/Fortran boolean possibility, but this happens
928 -- automatically since the return statement does this normalization.
931 Make_Subprogram_Body (Loc,
933 Build_Barrier_Function_Specification (Loc,
934 Make_Defining_Identifier (Loc, Chars (Func_Id))),
935 Declarations => Op_Decls,
936 Handled_Statement_Sequence =>
937 Make_Handled_Sequence_Of_Statements (Loc,
938 Statements => New_List (
939 Make_Simple_Return_Statement (Loc,
940 Expression => Condition (Ent_Formals)))));
941 Set_Is_Entry_Barrier_Function (Func_Body);
944 end Build_Barrier_Function;
946 ------------------------------------------
947 -- Build_Barrier_Function_Specification --
948 ------------------------------------------
950 function Build_Barrier_Function_Specification
952 Def_Id : Entity_Id) return Node_Id
955 Set_Debug_Info_Needed (Def_Id);
957 return Make_Function_Specification (Loc,
958 Defining_Unit_Name => Def_Id,
959 Parameter_Specifications => New_List (
960 Make_Parameter_Specification (Loc,
961 Defining_Identifier =>
962 Make_Defining_Identifier (Loc, Name_uO),
964 New_Reference_To (RTE (RE_Address), Loc)),
966 Make_Parameter_Specification (Loc,
967 Defining_Identifier =>
968 Make_Defining_Identifier (Loc, Name_uE),
970 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
973 New_Reference_To (Standard_Boolean, Loc));
974 end Build_Barrier_Function_Specification;
976 --------------------------
977 -- Build_Call_With_Task --
978 --------------------------
980 function Build_Call_With_Task
982 E : Entity_Id) return Node_Id
984 Loc : constant Source_Ptr := Sloc (N);
987 Make_Function_Call (Loc,
988 Name => New_Reference_To (E, Loc),
989 Parameter_Associations => New_List (Concurrent_Ref (N)));
990 end Build_Call_With_Task;
992 --------------------------------
993 -- Build_Corresponding_Record --
994 --------------------------------
996 function Build_Corresponding_Record
999 Loc : Source_Ptr) return Node_Id
1001 Rec_Ent : constant Entity_Id :=
1002 Make_Defining_Identifier
1003 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1006 New_Disc : Entity_Id;
1010 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1011 Set_Ekind (Rec_Ent, E_Record_Type);
1012 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1013 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1014 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1015 Set_Stored_Constraint (Rec_Ent, No_Elist);
1018 -- Use discriminals to create list of discriminants for record, and
1019 -- create new discriminals for use in default expressions, etc. It is
1020 -- worth noting that a task discriminant gives rise to 5 entities;
1022 -- a) The original discriminant.
1023 -- b) The discriminal for use in the task.
1024 -- c) The discriminant of the corresponding record.
1025 -- d) The discriminal for the init proc of the corresponding record.
1026 -- e) The local variable that renames the discriminant in the procedure
1027 -- for the task body.
1029 -- In fact the discriminals b) are used in the renaming declarations
1030 -- for e). See details in einfo (Handling of Discriminants).
1032 if Present (Discriminant_Specifications (N)) then
1034 Disc := First_Discriminant (Ctyp);
1036 while Present (Disc) loop
1037 New_Disc := CR_Discriminant (Disc);
1040 Make_Discriminant_Specification (Loc,
1041 Defining_Identifier => New_Disc,
1042 Discriminant_Type =>
1043 New_Occurrence_Of (Etype (Disc), Loc),
1045 New_Copy (Discriminant_Default_Value (Disc))));
1047 Next_Discriminant (Disc);
1054 -- Now we can construct the record type declaration. Note that this
1055 -- record is "limited tagged". It is "limited" to reflect the underlying
1056 -- limitedness of the task or protected object that it represents, and
1057 -- ensuring for example that it is properly passed by reference. It is
1058 -- "tagged" to give support to dispatching calls through interfaces. We
1059 -- propagate here the list of interfaces covered by the concurrent type
1060 -- (Ada 2005: AI-345).
1063 Make_Full_Type_Declaration (Loc,
1064 Defining_Identifier => Rec_Ent,
1065 Discriminant_Specifications => Dlist,
1067 Make_Record_Definition (Loc,
1069 Make_Component_List (Loc,
1070 Component_Items => Cdecls),
1072 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1073 Interface_List => Interface_List (N),
1074 Limited_Present => True));
1075 end Build_Corresponding_Record;
1077 ----------------------------------
1078 -- Build_Entry_Count_Expression --
1079 ----------------------------------
1081 function Build_Entry_Count_Expression
1082 (Concurrent_Type : Node_Id;
1083 Component_List : List_Id;
1084 Loc : Source_Ptr) return Node_Id
1096 -- Count number of non-family entries
1099 Ent := First_Entity (Concurrent_Type);
1100 while Present (Ent) loop
1101 if Ekind (Ent) = E_Entry then
1108 Ecount := Make_Integer_Literal (Loc, Eindx);
1110 -- Loop through entry families building the addition nodes
1112 Ent := First_Entity (Concurrent_Type);
1113 Comp := First (Component_List);
1114 while Present (Ent) loop
1115 if Ekind (Ent) = E_Entry_Family then
1116 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1120 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1121 Hi := Type_High_Bound (Typ);
1122 Lo := Type_Low_Bound (Typ);
1123 Large := Is_Potentially_Large_Family
1124 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1127 Left_Opnd => Ecount,
1128 Right_Opnd => Family_Size
1129 (Loc, Hi, Lo, Concurrent_Type, Large));
1136 end Build_Entry_Count_Expression;
1138 -----------------------
1139 -- Build_Entry_Names --
1140 -----------------------
1142 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1143 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1149 Typ : Entity_Id := Conc_Typ;
1151 procedure Build_Entry_Family_Name (Id : Entity_Id);
1153 -- for Lnn in Family_Low .. Family_High loop
1156 -- (_init._object <or> _init._task_id,
1158 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1160 -- Note that the bounds of the range may reference discriminants. The
1161 -- above construct is added directly to the statements of the block.
1163 procedure Build_Entry_Name (Id : Entity_Id);
1167 -- (_init._object <or>_init._task_id,
1169 -- new String ("<Entry name>");
1170 -- The above construct is added directly to the statements of the block.
1172 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1173 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1174 -- _init._task_id or _init._object, Inn and Arg3.
1176 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id;
1177 -- Given a protected type or its corresponding record, find the type of
1180 procedure Increment_Index (Stmts : List_Id);
1181 -- Generate the following and add it to Stmts
1184 -----------------------------
1185 -- Build_Entry_Family_Name --
1186 -----------------------------
1188 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1189 Def : constant Node_Id :=
1190 Discrete_Subtype_Definition (Parent (Id));
1191 L_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
1192 L_Stmts : constant List_Id := New_List;
1195 function Build_Range (Def : Node_Id) return Node_Id;
1196 -- Given a discrete subtype definition of an entry family, generate a
1197 -- range node which covers the range of Def's type.
1203 function Build_Range (Def : Node_Id) return Node_Id is
1204 High : Node_Id := Type_High_Bound (Etype (Def));
1205 Low : Node_Id := Type_Low_Bound (Etype (Def));
1208 -- If a bound references a discriminant, generate an identifier
1209 -- with the same name. Resolution will map it to the formals of
1212 if Is_Entity_Name (Low)
1213 and then Ekind (Entity (Low)) = E_Discriminant
1215 Low := Make_Identifier (Loc, Chars (Low));
1217 Low := New_Copy_Tree (Low);
1220 if Is_Entity_Name (High)
1221 and then Ekind (Entity (High)) = E_Discriminant
1223 High := Make_Identifier (Loc, Chars (High));
1225 High := New_Copy_Tree (High);
1231 High_Bound => High);
1234 -- Start of processing for Build_Entry_Family_Name
1237 Get_Name_String (Chars (Id));
1239 -- Add a leading '('
1241 Add_Char_To_Name_Buffer ('(');
1244 -- new String'("<Entry name>(" & Lnn'Img & ")");
1246 -- This is an implicit heap allocation, and Comes_From_Source is
1247 -- False, which ensures that it will get flagged as a violation of
1248 -- No_Implicit_Heap_Allocations when that restriction applies.
1251 Make_Allocator (Loc,
1252 Make_Qualified_Expression (Loc,
1254 New_Reference_To (Standard_String, Loc),
1256 Make_Op_Concat (Loc,
1258 Make_Op_Concat (Loc,
1260 Make_String_Literal (Loc,
1261 Strval => String_From_Name_Buffer),
1263 Make_Attribute_Reference (Loc,
1265 New_Reference_To (L_Id, Loc),
1266 Attribute_Name => Name_Img)),
1268 Make_String_Literal (Loc,
1271 Increment_Index (L_Stmts);
1272 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1275 -- for Lnn in Family_Low .. Family_High loop
1278 -- (_init._object <or> _init._task_id, Inn, <Val>);
1282 Make_Loop_Statement (Loc,
1284 Make_Iteration_Scheme (Loc,
1285 Loop_Parameter_Specification =>
1286 Make_Loop_Parameter_Specification (Loc,
1287 Defining_Identifier => L_Id,
1288 Discrete_Subtype_Definition => Build_Range (Def))),
1289 Statements => L_Stmts,
1290 End_Label => Empty));
1291 end Build_Entry_Family_Name;
1293 ----------------------
1294 -- Build_Entry_Name --
1295 ----------------------
1297 procedure Build_Entry_Name (Id : Entity_Id) is
1301 Get_Name_String (Chars (Id));
1303 -- This is an implicit heap allocation, and Comes_From_Source is
1304 -- False, which ensures that it will get flagged as a violation of
1305 -- No_Implicit_Heap_Allocations when that restriction applies.
1308 Make_Allocator (Loc,
1309 Make_Qualified_Expression (Loc,
1311 New_Reference_To (Standard_String, Loc),
1313 Make_String_Literal (Loc,
1314 String_From_Name_Buffer)));
1316 Increment_Index (B_Stmts);
1317 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1318 end Build_Entry_Name;
1320 -------------------------------
1321 -- Build_Set_Entry_Name_Call --
1322 -------------------------------
1324 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1329 -- Determine the proper name for the first argument and the RTS
1332 if Is_Protected_Type (Typ) then
1333 Arg1 := Name_uObject;
1334 Proc := RO_PE_Set_Entry_Name;
1336 else pragma Assert (Is_Task_Type (Typ));
1337 Arg1 := Name_uTask_Id;
1338 Proc := RO_TS_Set_Entry_Name;
1342 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1345 Make_Procedure_Call_Statement (Loc,
1347 New_Reference_To (RTE (Proc), Loc),
1348 Parameter_Associations => New_List (
1349 Make_Selected_Component (Loc, -- _init._object
1350 Prefix => -- _init._task_id
1351 Make_Identifier (Loc, Name_uInit),
1353 Make_Identifier (Loc, Arg1)),
1354 New_Reference_To (Index, Loc), -- Inn
1356 end Build_Set_Entry_Name_Call;
1358 --------------------------
1359 -- Find_Protection_Type --
1360 --------------------------
1362 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
1364 Typ : Entity_Id := Conc_Typ;
1367 if Is_Concurrent_Type (Typ) then
1368 Typ := Corresponding_Record_Type (Typ);
1371 Comp := First_Component (Typ);
1372 while Present (Comp) loop
1373 if Chars (Comp) = Name_uObject then
1374 return Base_Type (Etype (Comp));
1377 Next_Component (Comp);
1380 -- The corresponding record of a protected type should always have an
1383 raise Program_Error;
1384 end Find_Protection_Type;
1386 ---------------------
1387 -- Increment_Index --
1388 ---------------------
1390 procedure Increment_Index (Stmts : List_Id) is
1396 Make_Assignment_Statement (Loc,
1398 New_Reference_To (Index, Loc),
1402 New_Reference_To (Index, Loc),
1404 Make_Integer_Literal (Loc, 1))));
1405 end Increment_Index;
1407 -- Start of processing for Build_Entry_Names
1410 -- Retrieve the original concurrent type
1412 if Is_Concurrent_Record_Type (Typ) then
1413 Typ := Corresponding_Concurrent_Type (Typ);
1416 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1418 -- Nothing to do if the type has no entries
1420 if not Has_Entries (Typ) then
1424 -- Avoid generating entry names for a protected type with only one entry
1426 if Is_Protected_Type (Typ)
1427 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1432 Index := Make_Temporary (Loc, 'I');
1434 -- Step 1: Generate the declaration of the index variable:
1435 -- Inn : Protected_Entry_Index := 0;
1437 -- Inn : Task_Entry_Index := 0;
1439 if Is_Protected_Type (Typ) then
1440 Index_Typ := RE_Protected_Entry_Index;
1442 Index_Typ := RE_Task_Entry_Index;
1445 B_Decls := New_List;
1447 Make_Object_Declaration (Loc,
1448 Defining_Identifier => Index,
1449 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1450 Expression => Make_Integer_Literal (Loc, 0)));
1452 B_Stmts := New_List;
1454 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1457 Comp := First_Entity (Typ);
1458 while Present (Comp) loop
1459 if Ekind (Comp) = E_Entry then
1460 Build_Entry_Name (Comp);
1462 elsif Ekind (Comp) = E_Entry_Family then
1463 Build_Entry_Family_Name (Comp);
1469 -- Step 3: Wrap the statements in a block
1472 Make_Block_Statement (Loc,
1473 Declarations => B_Decls,
1474 Handled_Statement_Sequence =>
1475 Make_Handled_Sequence_Of_Statements (Loc,
1476 Statements => B_Stmts));
1477 end Build_Entry_Names;
1479 ---------------------------
1480 -- Build_Parameter_Block --
1481 ---------------------------
1483 function Build_Parameter_Block
1487 Decls : List_Id) return Entity_Id
1493 Has_Comp : Boolean := False;
1497 Actual := First (Actuals);
1499 Formal := Defining_Identifier (First (Formals));
1501 while Present (Actual) loop
1502 if not Is_Controlling_Actual (Actual) then
1505 -- type Ann is access all <actual-type>
1507 Comp_Nam := Make_Temporary (Loc, 'A');
1510 Make_Full_Type_Declaration (Loc,
1511 Defining_Identifier => Comp_Nam,
1513 Make_Access_To_Object_Definition (Loc,
1514 All_Present => True,
1515 Constant_Present => Ekind (Formal) = E_In_Parameter,
1516 Subtype_Indication =>
1517 New_Reference_To (Etype (Actual), Loc))));
1523 Make_Component_Declaration (Loc,
1524 Defining_Identifier =>
1525 Make_Defining_Identifier (Loc, Chars (Formal)),
1526 Component_Definition =>
1527 Make_Component_Definition (Loc,
1530 Subtype_Indication =>
1531 New_Reference_To (Comp_Nam, Loc))));
1536 Next_Actual (Actual);
1537 Next_Formal_With_Extras (Formal);
1540 Rec_Nam := Make_Temporary (Loc, 'P');
1545 -- type Pnn is record
1550 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1551 -- the original parameter names and Ann1 .. AnnN are the access to
1555 Make_Full_Type_Declaration (Loc,
1556 Defining_Identifier =>
1559 Make_Record_Definition (Loc,
1561 Make_Component_List (Loc, Comps))));
1564 -- type Pnn is null record;
1567 Make_Full_Type_Declaration (Loc,
1568 Defining_Identifier =>
1571 Make_Record_Definition (Loc,
1572 Null_Present => True,
1573 Component_List => Empty)));
1577 end Build_Parameter_Block;
1579 -----------------------
1580 -- Build_PPC_Wrapper --
1581 -----------------------
1583 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1584 Loc : constant Source_Ptr := Sloc (E);
1585 Synch_Type : constant Entity_Id := Scope (E);
1587 Wrapper_Id : constant Entity_Id :=
1588 Make_Defining_Identifier (Loc,
1589 Chars => New_External_Name (Chars (E), 'E'));
1590 -- the wrapper procedure name
1592 Wrapper_Body : Node_Id;
1594 Synch_Id : constant Entity_Id :=
1595 Make_Defining_Identifier (Loc,
1596 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1597 -- The parameter that designates the synchronized object in the call
1599 Actuals : constant List_Id := New_List;
1600 -- the actuals in the entry call.
1602 Decls : constant List_Id := New_List;
1604 Entry_Call : Node_Id;
1605 Entry_Name : Node_Id;
1608 -- The specification of the wrapper procedure
1612 -- Only build the wrapper if entry has pre/postconditions.
1613 -- Should this be done unconditionally instead ???
1619 P := Spec_PPC_List (E);
1624 -- Transfer ppc pragmas to the declarations of the wrapper
1626 while Present (P) loop
1627 if Pragma_Name (P) = Name_Precondition
1628 or else Pragma_Name (P) = Name_Postcondition
1630 Append (Relocate_Node (P), Decls);
1631 Set_Analyzed (Last (Decls), False);
1634 P := Next_Pragma (P);
1638 -- First formal is synchronized object
1641 Make_Parameter_Specification (Loc,
1642 Defining_Identifier => Synch_Id,
1643 Out_Present => True,
1645 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1648 Make_Selected_Component (Loc,
1649 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1650 Selector_Name => New_Occurrence_Of (E, Loc));
1652 -- If entity is entry family, second formal is the corresponding index,
1653 -- and entry name is an indexed component.
1655 if Ekind (E) = E_Entry_Family then
1657 Index : constant Entity_Id :=
1658 Make_Defining_Identifier (Loc, Name_I);
1661 Make_Parameter_Specification (Loc,
1662 Defining_Identifier => Index,
1664 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1666 Entry_Name := Make_Indexed_Component (Loc,
1667 Prefix => Entry_Name,
1668 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
1673 Make_Procedure_Call_Statement (Loc,
1675 Parameter_Associations => Actuals);
1677 -- Now add formals that match those of the entry, and build actuals
1678 -- for the nested entry call.
1682 New_Form : Entity_Id;
1683 Parm_Spec : Node_Id;
1686 Form := First_Formal (E);
1687 while Present (Form) loop
1688 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
1690 Make_Parameter_Specification (Loc,
1691 Defining_Identifier => New_Form,
1692 Out_Present => Out_Present (Parent (Form)),
1693 In_Present => In_Present (Parent (Form)),
1694 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
1696 Append (Parm_Spec, Specs);
1697 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1702 -- Add renaming declarations for the discriminants of the enclosing
1703 -- type, which may be visible in the preconditions.
1705 if Has_Discriminants (Synch_Type) then
1711 D := First_Discriminant (Synch_Type);
1712 while Present (D) loop
1714 Make_Object_Renaming_Declaration (Loc,
1715 Defining_Identifier =>
1716 Make_Defining_Identifier (Loc, Chars (D)),
1717 Subtype_Mark => New_Reference_To (Etype (D), Loc),
1719 Make_Selected_Component (Loc,
1720 Prefix => New_Reference_To (Synch_Id, Loc),
1721 Selector_Name => Make_Identifier (Loc, Chars (D))));
1722 Prepend (Decl, Decls);
1723 Next_Discriminant (D);
1728 Set_PPC_Wrapper (E, Wrapper_Id);
1730 Make_Subprogram_Body (Loc,
1732 Make_Procedure_Specification (Loc,
1733 Defining_Unit_Name => Wrapper_Id,
1734 Parameter_Specifications => Specs),
1735 Declarations => Decls,
1736 Handled_Statement_Sequence =>
1737 Make_Handled_Sequence_Of_Statements (Loc,
1738 Statements => New_List (Entry_Call)));
1740 -- The wrapper body is analyzed when the enclosing type is frozen.
1742 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1743 end Build_PPC_Wrapper;
1745 --------------------------
1746 -- Build_Wrapper_Bodies --
1747 --------------------------
1749 procedure Build_Wrapper_Bodies
1754 Rec_Typ : Entity_Id;
1756 function Build_Wrapper_Body
1758 Subp_Id : Entity_Id;
1759 Obj_Typ : Entity_Id;
1760 Formals : List_Id) return Node_Id;
1761 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1762 -- associated with a protected or task type. Subp_Id is the subprogram
1763 -- name which will be wrapped. Obj_Typ is the type of the new formal
1764 -- parameter which handles dispatching and object notation. Formals are
1765 -- the original formals of Subp_Id which will be explicitly replicated.
1767 ------------------------
1768 -- Build_Wrapper_Body --
1769 ------------------------
1771 function Build_Wrapper_Body
1773 Subp_Id : Entity_Id;
1774 Obj_Typ : Entity_Id;
1775 Formals : List_Id) return Node_Id
1777 Body_Spec : Node_Id;
1780 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1782 -- The subprogram is not overriding or is not a primitive declared
1783 -- between two views.
1785 if No (Body_Spec) then
1790 Actuals : List_Id := No_List;
1792 First_Form : Node_Id;
1797 -- Map formals to actuals. Use the list built for the wrapper
1798 -- spec, skipping the object notation parameter.
1800 First_Form := First (Parameter_Specifications (Body_Spec));
1802 Formal := First_Form;
1805 if Present (Formal) then
1806 Actuals := New_List;
1807 while Present (Formal) loop
1809 Make_Identifier (Loc, Chars =>
1810 Chars (Defining_Identifier (Formal))));
1816 -- Special processing for primitives declared between a private
1817 -- type and its completion: the wrapper needs a properly typed
1818 -- parameter if the wrapped operation has a controlling first
1819 -- parameter. Note that this might not be the case for a function
1820 -- with a controlling result.
1822 if Is_Private_Primitive_Subprogram (Subp_Id) then
1823 if No (Actuals) then
1824 Actuals := New_List;
1827 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1828 Prepend_To (Actuals,
1829 Unchecked_Convert_To
1830 (Corresponding_Concurrent_Type (Obj_Typ),
1831 Make_Identifier (Loc, Name_uO)));
1834 Prepend_To (Actuals,
1835 Make_Identifier (Loc, Chars =>
1836 Chars (Defining_Identifier (First_Form))));
1839 Nam := New_Reference_To (Subp_Id, Loc);
1841 -- An access-to-variable object parameter requires an explicit
1842 -- dereference in the unchecked conversion. This case occurs
1843 -- when a protected entry wrapper must override an interface
1844 -- level procedure with interface access as first parameter.
1846 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1848 if Nkind (Parameter_Type (First_Form)) =
1852 Make_Explicit_Dereference (Loc,
1853 Prefix => Make_Identifier (Loc, Name_uO));
1855 Conv_Id := Make_Identifier (Loc, Name_uO);
1859 Make_Selected_Component (Loc,
1861 Unchecked_Convert_To
1862 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
1863 Selector_Name => New_Reference_To (Subp_Id, Loc));
1866 -- Create the subprogram body. For a function, the call to the
1867 -- actual subprogram has to be converted to the corresponding
1868 -- record if it is a controlling result.
1870 if Ekind (Subp_Id) = E_Function then
1876 Make_Function_Call (Loc,
1878 Parameter_Associations => Actuals);
1880 if Has_Controlling_Result (Subp_Id) then
1882 Unchecked_Convert_To
1883 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1887 Make_Subprogram_Body (Loc,
1888 Specification => Body_Spec,
1889 Declarations => Empty_List,
1890 Handled_Statement_Sequence =>
1891 Make_Handled_Sequence_Of_Statements (Loc,
1892 Statements => New_List (
1893 Make_Simple_Return_Statement (Loc, Res))));
1898 Make_Subprogram_Body (Loc,
1899 Specification => Body_Spec,
1900 Declarations => Empty_List,
1901 Handled_Statement_Sequence =>
1902 Make_Handled_Sequence_Of_Statements (Loc,
1903 Statements => New_List (
1904 Make_Procedure_Call_Statement (Loc,
1906 Parameter_Associations => Actuals))));
1909 end Build_Wrapper_Body;
1911 -- Start of processing for Build_Wrapper_Bodies
1914 if Is_Concurrent_Type (Typ) then
1915 Rec_Typ := Corresponding_Record_Type (Typ);
1920 -- Generate wrapper bodies for a concurrent type which implements an
1923 if Present (Interfaces (Rec_Typ)) then
1925 Insert_Nod : Node_Id;
1927 Prim_Elmt : Elmt_Id;
1928 Prim_Decl : Node_Id;
1930 Wrap_Body : Node_Id;
1931 Wrap_Id : Entity_Id;
1936 -- Examine all primitive operations of the corresponding record
1937 -- type, looking for wrapper specs. Generate bodies in order to
1940 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1941 while Present (Prim_Elmt) loop
1942 Prim := Node (Prim_Elmt);
1944 if (Ekind (Prim) = E_Function
1945 or else Ekind (Prim) = E_Procedure)
1946 and then Is_Primitive_Wrapper (Prim)
1948 Subp := Wrapped_Entity (Prim);
1949 Prim_Decl := Parent (Parent (Prim));
1952 Build_Wrapper_Body (Loc,
1955 Formals => Parameter_Specifications (Parent (Subp)));
1956 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
1958 Set_Corresponding_Spec (Wrap_Body, Prim);
1959 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
1961 Insert_After (Insert_Nod, Wrap_Body);
1962 Insert_Nod := Wrap_Body;
1964 Analyze (Wrap_Body);
1967 Next_Elmt (Prim_Elmt);
1971 end Build_Wrapper_Bodies;
1973 ------------------------
1974 -- Build_Wrapper_Spec --
1975 ------------------------
1977 function Build_Wrapper_Spec
1978 (Subp_Id : Entity_Id;
1979 Obj_Typ : Entity_Id;
1980 Formals : List_Id) return Node_Id
1982 Loc : constant Source_Ptr := Sloc (Subp_Id);
1983 First_Param : Node_Id;
1985 Iface_Elmt : Elmt_Id;
1986 Iface_Op : Entity_Id;
1987 Iface_Op_Elmt : Elmt_Id;
1989 function Overriding_Possible
1990 (Iface_Op : Entity_Id;
1991 Wrapper : Entity_Id) return Boolean;
1992 -- Determine whether a primitive operation can be overridden by Wrapper.
1993 -- Iface_Op is the candidate primitive operation of an interface type,
1994 -- Wrapper is the generated entry wrapper.
1996 function Replicate_Formals
1998 Formals : List_Id) return List_Id;
1999 -- An explicit parameter replication is required due to the Is_Entry_
2000 -- Formal flag being set for all the formals of an entry. The explicit
2001 -- replication removes the flag that would otherwise cause a different
2002 -- path of analysis.
2004 -------------------------
2005 -- Overriding_Possible --
2006 -------------------------
2008 function Overriding_Possible
2009 (Iface_Op : Entity_Id;
2010 Wrapper : Entity_Id) return Boolean
2012 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2013 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2015 function Type_Conformant_Parameters
2016 (Iface_Op_Params : List_Id;
2017 Wrapper_Params : List_Id) return Boolean;
2018 -- Determine whether the parameters of the generated entry wrapper
2019 -- and those of a primitive operation are type conformant. During
2020 -- this check, the first parameter of the primitive operation is
2021 -- skipped if it is a controlling argument: protected functions
2022 -- may have a controlling result.
2024 --------------------------------
2025 -- Type_Conformant_Parameters --
2026 --------------------------------
2028 function Type_Conformant_Parameters
2029 (Iface_Op_Params : List_Id;
2030 Wrapper_Params : List_Id) return Boolean
2032 Iface_Op_Param : Node_Id;
2033 Iface_Op_Typ : Entity_Id;
2034 Wrapper_Param : Node_Id;
2035 Wrapper_Typ : Entity_Id;
2038 -- Skip the first (controlling) parameter of primitive operation
2040 Iface_Op_Param := First (Iface_Op_Params);
2042 if Present (First_Formal (Iface_Op))
2043 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2045 Iface_Op_Param := Next (Iface_Op_Param);
2048 Wrapper_Param := First (Wrapper_Params);
2049 while Present (Iface_Op_Param)
2050 and then Present (Wrapper_Param)
2052 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2053 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2055 -- The two parameters must be mode conformant
2057 if not Conforming_Types
2058 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2063 Next (Iface_Op_Param);
2064 Next (Wrapper_Param);
2067 -- One of the lists is longer than the other
2069 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2074 end Type_Conformant_Parameters;
2076 -- Start of processing for Overriding_Possible
2079 if Chars (Iface_Op) /= Chars (Wrapper) then
2083 -- If an inherited subprogram is implemented by a protected procedure
2084 -- or an entry, then the first parameter of the inherited subprogram
2085 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2087 if Ekind (Iface_Op) = E_Procedure
2088 and then Present (Parameter_Specifications (Iface_Op_Spec))
2091 Obj_Param : constant Node_Id :=
2092 First (Parameter_Specifications (Iface_Op_Spec));
2094 if not Out_Present (Obj_Param)
2095 and then Nkind (Parameter_Type (Obj_Param)) /=
2104 Type_Conformant_Parameters (
2105 Parameter_Specifications (Iface_Op_Spec),
2106 Parameter_Specifications (Wrapper_Spec));
2107 end Overriding_Possible;
2109 -----------------------
2110 -- Replicate_Formals --
2111 -----------------------
2113 function Replicate_Formals
2115 Formals : List_Id) return List_Id
2117 New_Formals : constant List_Id := New_List;
2119 Param_Type : Node_Id;
2122 Formal := First (Formals);
2124 -- Skip the object parameter when dealing with primitives declared
2125 -- between two views.
2127 if Is_Private_Primitive_Subprogram (Subp_Id)
2128 and then not Has_Controlling_Result (Subp_Id)
2130 Formal := Next (Formal);
2133 while Present (Formal) loop
2135 -- Create an explicit copy of the entry parameter
2137 -- When creating the wrapper subprogram for a primitive operation
2138 -- of a protected interface we must construct an equivalent
2139 -- signature to that of the overriding operation. For regular
2140 -- parameters we can just use the type of the formal, but for
2141 -- access to subprogram parameters we need to reanalyze the
2142 -- parameter type to create local entities for the signature of
2143 -- the subprogram type. Using the entities of the overriding
2144 -- subprogram will result in out-of-scope errors in the back-end.
2146 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2147 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2150 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
2153 Append_To (New_Formals,
2154 Make_Parameter_Specification (Loc,
2155 Defining_Identifier =>
2156 Make_Defining_Identifier (Loc,
2157 Chars => Chars (Defining_Identifier (Formal))),
2158 In_Present => In_Present (Formal),
2159 Out_Present => Out_Present (Formal),
2160 Parameter_Type => Param_Type));
2166 end Replicate_Formals;
2168 -- Start of processing for Build_Wrapper_Spec
2171 -- There is no point in building wrappers for non-tagged concurrent
2174 pragma Assert (Is_Tagged_Type (Obj_Typ));
2176 -- An entry or a protected procedure can override a routine where the
2177 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2178 -- type. Since the wrapper must have the exact same signature as that of
2179 -- the overridden subprogram, we try to find the overriding candidate
2180 -- and use its controlling formal.
2182 First_Param := Empty;
2184 -- Check every implemented interface
2186 if Present (Interfaces (Obj_Typ)) then
2187 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2188 Search : while Present (Iface_Elmt) loop
2189 Iface := Node (Iface_Elmt);
2191 -- Check every interface primitive
2193 if Present (Primitive_Operations (Iface)) then
2194 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2195 while Present (Iface_Op_Elmt) loop
2196 Iface_Op := Node (Iface_Op_Elmt);
2198 -- Ignore predefined primitives
2200 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2201 Iface_Op := Ultimate_Alias (Iface_Op);
2203 -- The current primitive operation can be overridden by
2204 -- the generated entry wrapper.
2206 if Overriding_Possible (Iface_Op, Subp_Id) then
2208 First (Parameter_Specifications (Parent (Iface_Op)));
2214 Next_Elmt (Iface_Op_Elmt);
2218 Next_Elmt (Iface_Elmt);
2222 -- If the subprogram to be wrapped is not overriding anything or is not
2223 -- a primitive declared between two views, do not produce anything. This
2224 -- avoids spurious errors involving overriding.
2227 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2233 Wrapper_Id : constant Entity_Id :=
2234 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2235 New_Formals : List_Id;
2236 Obj_Param : Node_Id;
2237 Obj_Param_Typ : Entity_Id;
2240 -- Minimum decoration is needed to catch the entity in
2241 -- Sem_Ch6.Override_Dispatching_Operation.
2243 if Ekind (Subp_Id) = E_Function then
2244 Set_Ekind (Wrapper_Id, E_Function);
2246 Set_Ekind (Wrapper_Id, E_Procedure);
2249 Set_Is_Primitive_Wrapper (Wrapper_Id);
2250 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2251 Set_Is_Private_Primitive (Wrapper_Id,
2252 Is_Private_Primitive_Subprogram (Subp_Id));
2254 -- Process the formals
2256 New_Formals := Replicate_Formals (Loc, Formals);
2258 -- A function with a controlling result and no first controlling
2259 -- formal needs no additional parameter.
2261 if Has_Controlling_Result (Subp_Id)
2263 (No (First_Formal (Subp_Id))
2264 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2268 -- Routine Subp_Id has been found to override an interface primitive.
2269 -- If the interface operation has an access parameter, create a copy
2270 -- of it, with the same null exclusion indicator if present.
2272 elsif Present (First_Param) then
2273 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2275 Make_Access_Definition (Loc,
2277 New_Reference_To (Obj_Typ, Loc));
2278 Set_Null_Exclusion_Present (Obj_Param_Typ,
2279 Null_Exclusion_Present (Parameter_Type (First_Param)));
2282 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2286 Make_Parameter_Specification (Loc,
2287 Defining_Identifier =>
2288 Make_Defining_Identifier (Loc,
2290 In_Present => In_Present (First_Param),
2291 Out_Present => Out_Present (First_Param),
2292 Parameter_Type => Obj_Param_Typ);
2294 Prepend_To (New_Formals, Obj_Param);
2296 -- If we are dealing with a primitive declared between two views,
2297 -- implemented by a synchronized operation, we need to create
2298 -- a default parameter. The mode of the parameter must match that
2299 -- of the primitive operation.
2302 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2304 Make_Parameter_Specification (Loc,
2305 Defining_Identifier =>
2306 Make_Defining_Identifier (Loc, Name_uO),
2307 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2308 Out_Present => Ekind (Subp_Id) /= E_Function,
2309 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2310 Prepend_To (New_Formals, Obj_Param);
2313 -- Build the final spec. If it is a function with a controlling
2314 -- result, it is a primitive operation of the corresponding
2315 -- record type, so mark the spec accordingly.
2317 if Ekind (Subp_Id) = E_Function then
2322 if Has_Controlling_Result (Subp_Id) then
2325 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2327 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2331 Make_Function_Specification (Loc,
2332 Defining_Unit_Name => Wrapper_Id,
2333 Parameter_Specifications => New_Formals,
2334 Result_Definition => Res_Def);
2338 Make_Procedure_Specification (Loc,
2339 Defining_Unit_Name => Wrapper_Id,
2340 Parameter_Specifications => New_Formals);
2343 end Build_Wrapper_Spec;
2345 -------------------------
2346 -- Build_Wrapper_Specs --
2347 -------------------------
2349 procedure Build_Wrapper_Specs
2355 Rec_Typ : Entity_Id;
2356 procedure Scan_Declarations (L : List_Id);
2357 -- Common processing for visible and private declarations
2358 -- of a protected type.
2360 procedure Scan_Declarations (L : List_Id) is
2362 Wrap_Decl : Node_Id;
2363 Wrap_Spec : Node_Id;
2371 while Present (Decl) loop
2374 if Nkind (Decl) = N_Entry_Declaration
2375 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2379 (Subp_Id => Defining_Identifier (Decl),
2381 Formals => Parameter_Specifications (Decl));
2383 elsif Nkind (Decl) = N_Subprogram_Declaration then
2386 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2389 Parameter_Specifications (Specification (Decl)));
2392 if Present (Wrap_Spec) then
2394 Make_Subprogram_Declaration (Loc,
2395 Specification => Wrap_Spec);
2397 Insert_After (N, Wrap_Decl);
2400 Analyze (Wrap_Decl);
2405 end Scan_Declarations;
2407 -- start of processing for Build_Wrapper_Specs
2410 if Is_Protected_Type (Typ) then
2411 Def := Protected_Definition (Parent (Typ));
2412 else pragma Assert (Is_Task_Type (Typ));
2413 Def := Task_Definition (Parent (Typ));
2416 Rec_Typ := Corresponding_Record_Type (Typ);
2418 -- Generate wrapper specs for a concurrent type which implements an
2419 -- interface. Operations in both the visible and private parts may
2420 -- implement progenitor operations.
2422 if Present (Interfaces (Rec_Typ))
2423 and then Present (Def)
2425 Scan_Declarations (Visible_Declarations (Def));
2426 Scan_Declarations (Private_Declarations (Def));
2428 end Build_Wrapper_Specs;
2430 ---------------------------
2431 -- Build_Find_Body_Index --
2432 ---------------------------
2434 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2435 Loc : constant Source_Ptr := Sloc (Typ);
2438 Has_F : Boolean := False;
2440 If_St : Node_Id := Empty;
2443 Decls : List_Id := New_List;
2446 Siz : Node_Id := Empty;
2448 procedure Add_If_Clause (Expr : Node_Id);
2449 -- Add test for range of current entry
2451 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2452 -- If a bound of an entry is given by a discriminant, retrieve the
2453 -- actual value of the discriminant from the enclosing object.
2459 procedure Add_If_Clause (Expr : Node_Id) is
2461 Stats : constant List_Id :=
2463 Make_Simple_Return_Statement (Loc,
2464 Expression => Make_Integer_Literal (Loc, Index + 1)));
2467 -- Index for current entry body
2471 -- Compute total length of entry queues so far
2479 Right_Opnd => Expr);
2484 Left_Opnd => Make_Identifier (Loc, Name_uE),
2487 -- Map entry queue indices in the range of the current family
2488 -- into the current index, that designates the entry body.
2492 Make_Implicit_If_Statement (Typ,
2494 Then_Statements => Stats,
2495 Elsif_Parts => New_List);
2501 Make_Elsif_Part (Loc,
2503 Then_Statements => Stats),
2504 Elsif_Parts (If_St));
2508 ------------------------------
2509 -- Convert_Discriminant_Ref --
2510 ------------------------------
2512 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2516 if Is_Entity_Name (Bound)
2517 and then Ekind (Entity (Bound)) = E_Discriminant
2520 Make_Selected_Component (Loc,
2522 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2523 Make_Explicit_Dereference (Loc,
2524 Make_Identifier (Loc, Name_uObject))),
2525 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2526 Set_Etype (B, Etype (Entity (Bound)));
2528 B := New_Copy_Tree (Bound);
2532 end Convert_Discriminant_Ref;
2534 -- Start of processing for Build_Find_Body_Index
2537 Spec := Build_Find_Body_Index_Spec (Typ);
2539 Ent := First_Entity (Typ);
2540 while Present (Ent) loop
2541 if Ekind (Ent) = E_Entry_Family then
2551 -- If the protected type has no entry families, there is a one-one
2552 -- correspondence between entry queue and entry body.
2555 Make_Simple_Return_Statement (Loc,
2556 Expression => Make_Identifier (Loc, Name_uE));
2559 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2562 -- if E <= l1 then return 1;
2563 -- elsif E <= l1 + l2 then return 2;
2568 Ent := First_Entity (Typ);
2570 Add_Object_Pointer (Loc, Typ, Decls);
2572 while Present (Ent) loop
2573 if Ekind (Ent) = E_Entry then
2574 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2576 elsif Ekind (Ent) = E_Entry_Family then
2577 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2578 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2579 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2580 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2589 Make_Simple_Return_Statement (Loc,
2590 Expression => Make_Integer_Literal (Loc, 1));
2592 elsif Nkind (Ret) = N_If_Statement then
2594 -- Ranges are in increasing order, so last one doesn't need guard
2597 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2600 Set_Else_Statements (Ret, Then_Statements (Nod));
2606 Make_Subprogram_Body (Loc,
2607 Specification => Spec,
2608 Declarations => Decls,
2609 Handled_Statement_Sequence =>
2610 Make_Handled_Sequence_Of_Statements (Loc,
2611 Statements => New_List (Ret)));
2612 end Build_Find_Body_Index;
2614 --------------------------------
2615 -- Build_Find_Body_Index_Spec --
2616 --------------------------------
2618 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2619 Loc : constant Source_Ptr := Sloc (Typ);
2620 Id : constant Entity_Id :=
2621 Make_Defining_Identifier (Loc,
2622 Chars => New_External_Name (Chars (Typ), 'F'));
2623 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2624 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2628 Make_Function_Specification (Loc,
2629 Defining_Unit_Name => Id,
2630 Parameter_Specifications => New_List (
2631 Make_Parameter_Specification (Loc,
2632 Defining_Identifier => Parm1,
2634 New_Reference_To (RTE (RE_Address), Loc)),
2636 Make_Parameter_Specification (Loc,
2637 Defining_Identifier => Parm2,
2639 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2640 Result_Definition => New_Occurrence_Of (
2641 RTE (RE_Protected_Entry_Index), Loc));
2642 end Build_Find_Body_Index_Spec;
2644 -------------------------
2645 -- Build_Master_Entity --
2646 -------------------------
2648 procedure Build_Master_Entity (E : Entity_Id) is
2649 Loc : constant Source_Ptr := Sloc (E);
2655 S := Find_Master_Scope (E);
2657 -- Nothing to do if we already built a master entity for this scope
2658 -- or if there is no task hierarchy.
2660 if Has_Master_Entity (S)
2661 or else Restriction_Active (No_Task_Hierarchy)
2666 -- Otherwise first build the master entity
2667 -- _Master : constant Master_Id := Current_Master.all;
2668 -- and insert it just before the current declaration
2671 Make_Object_Declaration (Loc,
2672 Defining_Identifier =>
2673 Make_Defining_Identifier (Loc, Name_uMaster),
2674 Constant_Present => True,
2675 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2677 Make_Explicit_Dereference (Loc,
2678 New_Reference_To (RTE (RE_Current_Master), Loc)));
2681 Insert_Before (P, Decl);
2684 Set_Has_Master_Entity (S);
2686 -- Now mark the containing scope as a task master
2688 while Nkind (P) /= N_Compilation_Unit loop
2691 -- If we fall off the top, we are at the outer level, and the
2692 -- environment task is our effective master, so nothing to mark.
2695 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2697 Set_Is_Task_Master (P, True);
2700 elsif Nkind (Parent (P)) = N_Subunit then
2701 P := Corresponding_Stub (Parent (P));
2704 end Build_Master_Entity;
2706 -----------------------------------------
2707 -- Build_Private_Protected_Declaration --
2708 -----------------------------------------
2710 function Build_Private_Protected_Declaration
2711 (N : Node_Id) return Entity_Id
2713 Loc : constant Source_Ptr := Sloc (N);
2714 Body_Id : constant Entity_Id := Defining_Entity (N);
2719 Spec_Id : Entity_Id;
2722 Formal := First_Formal (Body_Id);
2724 -- The protected operation always has at least one formal, namely the
2725 -- object itself, but it is only placed in the parameter list if
2726 -- expansion is enabled.
2728 if Present (Formal) or else Expander_Active then
2729 Plist := Copy_Parameter_List (Body_Id);
2734 if Nkind (Specification (N)) = N_Procedure_Specification then
2736 Make_Procedure_Specification (Loc,
2737 Defining_Unit_Name =>
2738 Make_Defining_Identifier (Sloc (Body_Id),
2739 Chars => Chars (Body_Id)),
2740 Parameter_Specifications =>
2744 Make_Function_Specification (Loc,
2745 Defining_Unit_Name =>
2746 Make_Defining_Identifier (Sloc (Body_Id),
2747 Chars => Chars (Body_Id)),
2748 Parameter_Specifications => Plist,
2749 Result_Definition =>
2750 New_Occurrence_Of (Etype (Body_Id), Loc));
2753 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2754 Insert_Before (N, Decl);
2755 Spec_Id := Defining_Unit_Name (New_Spec);
2757 -- Indicate that the entity comes from source, to ensure that cross-
2758 -- reference information is properly generated. The body itself is
2759 -- rewritten during expansion, and the body entity will not appear in
2760 -- calls to the operation.
2762 Set_Comes_From_Source (Spec_Id, True);
2764 Set_Has_Completion (Spec_Id);
2765 Set_Convention (Spec_Id, Convention_Protected);
2767 end Build_Private_Protected_Declaration;
2769 ---------------------------
2770 -- Build_Protected_Entry --
2771 ---------------------------
2773 function Build_Protected_Entry
2776 Pid : Node_Id) return Node_Id
2778 Loc : constant Source_Ptr := Sloc (N);
2780 Decls : constant List_Id := Declarations (N);
2781 End_Lab : constant Node_Id :=
2782 End_Label (Handled_Statement_Sequence (N));
2783 End_Loc : constant Source_Ptr :=
2784 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2785 -- Used for the generated call to Complete_Entry_Body
2787 Han_Loc : Source_Ptr;
2788 -- Used for the exception handler, inserted at end of the body
2790 Op_Decls : constant List_Id := New_List;
2798 -- Set the source location on the exception handler only when debugging
2799 -- the expanded code (see Make_Implicit_Exception_Handler).
2801 if Debug_Generated_Code then
2804 -- Otherwise the inserted code should not be visible to the debugger
2807 Han_Loc := No_Location;
2811 Make_Defining_Identifier (Loc,
2812 Chars => Chars (Protected_Body_Subprogram (Ent)));
2814 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2816 -- Add the following declarations:
2817 -- type poVP is access poV;
2818 -- _object : poVP := poVP (_O);
2820 -- where _O is the formal parameter associated with the concurrent
2821 -- object. These declarations are needed for Complete_Entry_Body.
2823 Add_Object_Pointer (Loc, Pid, Op_Decls);
2825 -- Add renamings for all formals, the Protection object, discriminals,
2826 -- privals and the entry index constant for use by debugger.
2828 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2829 Debug_Private_Data_Declarations (Decls);
2831 case Corresponding_Runtime_Package (Pid) is
2832 when System_Tasking_Protected_Objects_Entries =>
2834 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2836 when System_Tasking_Protected_Objects_Single_Entry =>
2838 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2841 raise Program_Error;
2844 Op_Stats := New_List (
2845 Make_Block_Statement (Loc,
2846 Declarations => Decls,
2847 Handled_Statement_Sequence =>
2848 Handled_Statement_Sequence (N)),
2850 Make_Procedure_Call_Statement (End_Loc,
2852 Parameter_Associations => New_List (
2853 Make_Attribute_Reference (End_Loc,
2855 Make_Selected_Component (End_Loc,
2857 Make_Identifier (End_Loc, Name_uObject),
2859 Make_Identifier (End_Loc, Name_uObject)),
2860 Attribute_Name => Name_Unchecked_Access))));
2862 -- When exceptions can not be propagated, we never need to call
2863 -- Exception_Complete_Entry_Body
2865 if No_Exception_Handlers_Set then
2867 Make_Subprogram_Body (Loc,
2868 Specification => Espec,
2869 Declarations => Op_Decls,
2870 Handled_Statement_Sequence =>
2871 Make_Handled_Sequence_Of_Statements (Loc,
2872 Statements => Op_Stats,
2873 End_Label => End_Lab));
2876 Ohandle := Make_Others_Choice (Loc);
2877 Set_All_Others (Ohandle);
2879 case Corresponding_Runtime_Package (Pid) is
2880 when System_Tasking_Protected_Objects_Entries =>
2883 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2885 when System_Tasking_Protected_Objects_Single_Entry =>
2888 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2891 raise Program_Error;
2894 -- Establish link between subprogram body entity and source entry.
2896 Set_Corresponding_Protected_Entry (Edef, Ent);
2898 -- Create body of entry procedure. The renaming declarations are
2899 -- placed ahead of the block that contains the actual entry body.
2902 Make_Subprogram_Body (Loc,
2903 Specification => Espec,
2904 Declarations => Op_Decls,
2905 Handled_Statement_Sequence =>
2906 Make_Handled_Sequence_Of_Statements (Loc,
2907 Statements => Op_Stats,
2908 End_Label => End_Lab,
2909 Exception_Handlers => New_List (
2910 Make_Implicit_Exception_Handler (Han_Loc,
2911 Exception_Choices => New_List (Ohandle),
2913 Statements => New_List (
2914 Make_Procedure_Call_Statement (Han_Loc,
2916 Parameter_Associations => New_List (
2917 Make_Attribute_Reference (Han_Loc,
2919 Make_Selected_Component (Han_Loc,
2921 Make_Identifier (Han_Loc, Name_uObject),
2923 Make_Identifier (Han_Loc, Name_uObject)),
2924 Attribute_Name => Name_Unchecked_Access),
2926 Make_Function_Call (Han_Loc,
2927 Name => New_Reference_To (
2928 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2930 end Build_Protected_Entry;
2932 -----------------------------------------
2933 -- Build_Protected_Entry_Specification --
2934 -----------------------------------------
2936 function Build_Protected_Entry_Specification
2939 Ent_Id : Entity_Id) return Node_Id
2941 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2944 Set_Debug_Info_Needed (Def_Id);
2946 if Present (Ent_Id) then
2947 Append_Elmt (P, Accept_Address (Ent_Id));
2951 Make_Procedure_Specification (Loc,
2952 Defining_Unit_Name => Def_Id,
2953 Parameter_Specifications => New_List (
2954 Make_Parameter_Specification (Loc,
2955 Defining_Identifier =>
2956 Make_Defining_Identifier (Loc, Name_uO),
2958 New_Reference_To (RTE (RE_Address), Loc)),
2960 Make_Parameter_Specification (Loc,
2961 Defining_Identifier => P,
2963 New_Reference_To (RTE (RE_Address), Loc)),
2965 Make_Parameter_Specification (Loc,
2966 Defining_Identifier =>
2967 Make_Defining_Identifier (Loc, Name_uE),
2969 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2970 end Build_Protected_Entry_Specification;
2972 --------------------------
2973 -- Build_Protected_Spec --
2974 --------------------------
2976 function Build_Protected_Spec
2978 Obj_Type : Entity_Id;
2980 Unprotected : Boolean := False) return List_Id
2982 Loc : constant Source_Ptr := Sloc (N);
2985 New_Plist : List_Id;
2986 New_Param : Node_Id;
2989 New_Plist := New_List;
2991 Formal := First_Formal (Ident);
2992 while Present (Formal) loop
2994 Make_Parameter_Specification (Loc,
2995 Defining_Identifier =>
2996 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2997 In_Present => In_Present (Parent (Formal)),
2998 Out_Present => Out_Present (Parent (Formal)),
2999 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
3002 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3005 Append (New_Param, New_Plist);
3006 Next_Formal (Formal);
3009 -- If the subprogram is a procedure and the context is not an access
3010 -- to protected subprogram, the parameter is in-out. Otherwise it is
3014 Make_Parameter_Specification (Loc,
3015 Defining_Identifier =>
3016 Make_Defining_Identifier (Loc, Name_uObject),
3019 (Etype (Ident) = Standard_Void_Type
3020 and then not Is_RTE (Obj_Type, RE_Address)),
3022 New_Reference_To (Obj_Type, Loc));
3023 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3024 Prepend_To (New_Plist, Decl);
3027 end Build_Protected_Spec;
3029 ---------------------------------------
3030 -- Build_Protected_Sub_Specification --
3031 ---------------------------------------
3033 function Build_Protected_Sub_Specification
3035 Prot_Typ : Entity_Id;
3036 Mode : Subprogram_Protection_Mode) return Node_Id
3038 Loc : constant Source_Ptr := Sloc (N);
3042 New_Plist : List_Id;
3045 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3046 (Dispatching_Mode => ' ',
3047 Protected_Mode => 'P',
3048 Unprotected_Mode => 'N');
3051 if Ekind (Defining_Unit_Name (Specification (N))) =
3054 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3059 Def_Id := Defining_Unit_Name (Specification (Decl));
3062 Build_Protected_Spec
3063 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3064 Mode = Unprotected_Mode);
3066 Make_Defining_Identifier (Loc,
3067 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3069 -- The unprotected operation carries the user code, and debugging
3070 -- information must be generated for it, even though this spec does
3071 -- not come from source. It is also convenient to allow gdb to step
3072 -- into the protected operation, even though it only contains lock/
3075 Set_Debug_Info_Needed (New_Id);
3077 -- If a pragma Eliminate applies to the source entity, the internal
3078 -- subprograms will be eliminated as well.
3080 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3082 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3084 Make_Procedure_Specification (Loc,
3085 Defining_Unit_Name => New_Id,
3086 Parameter_Specifications => New_Plist);
3088 -- Create a new specification for the anonymous subprogram type
3092 Make_Function_Specification (Loc,
3093 Defining_Unit_Name => New_Id,
3094 Parameter_Specifications => New_Plist,
3095 Result_Definition =>
3096 Copy_Result_Type (Result_Definition (Specification (Decl))));
3098 Set_Return_Present (Defining_Unit_Name (New_Spec));
3102 end Build_Protected_Sub_Specification;
3104 -------------------------------------
3105 -- Build_Protected_Subprogram_Body --
3106 -------------------------------------
3108 function Build_Protected_Subprogram_Body
3111 N_Op_Spec : Node_Id) return Node_Id
3113 Loc : constant Source_Ptr := Sloc (N);
3115 P_Op_Spec : Node_Id;
3118 Unprot_Call : Node_Id;
3120 Lock_Name : Node_Id;
3121 Lock_Stmt : Node_Id;
3122 Service_Name : Node_Id;
3124 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3125 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3127 Object_Parm : Node_Id;
3130 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3131 -- Tell whether a given subprogram cannot raise an exception
3133 -----------------------
3134 -- Is_Exception_Safe --
3135 -----------------------
3137 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3139 function Has_Side_Effect (N : Node_Id) return Boolean;
3140 -- Return True whenever encountering a subprogram call or raise
3141 -- statement of any kind in the sequence of statements
3143 ---------------------
3144 -- Has_Side_Effect --
3145 ---------------------
3147 -- What is this doing buried two levels down in exp_ch9. It seems
3148 -- like a generally useful function, and indeed there may be code
3149 -- duplication going on here ???
3151 function Has_Side_Effect (N : Node_Id) return Boolean is
3155 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3156 -- Indicate whether N is a subprogram call or a raise statement
3158 ----------------------
3159 -- Is_Call_Or_Raise --
3160 ----------------------
3162 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3164 return Nkind_In (N, N_Procedure_Call_Statement,
3167 N_Raise_Constraint_Error,
3168 N_Raise_Program_Error,
3169 N_Raise_Storage_Error);
3170 end Is_Call_Or_Raise;
3172 -- Start of processing for Has_Side_Effect
3176 while Present (Stmt) loop
3177 if Is_Call_Or_Raise (Stmt) then
3181 -- An object declaration can also contain a function call
3182 -- or a raise statement
3184 if Nkind (Stmt) = N_Object_Declaration then
3185 Expr := Expression (Stmt);
3187 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3196 end Has_Side_Effect;
3198 -- Start of processing for Is_Exception_Safe
3201 -- If the checks handled by the back end are not disabled, we cannot
3202 -- ensure that no exception will be raised.
3204 if not Access_Checks_Suppressed (Empty)
3205 or else not Discriminant_Checks_Suppressed (Empty)
3206 or else not Range_Checks_Suppressed (Empty)
3207 or else not Index_Checks_Suppressed (Empty)
3208 or else Opt.Stack_Checking_Enabled
3213 if Has_Side_Effect (First (Declarations (Subprogram)))
3216 First (Statements (Handled_Statement_Sequence (Subprogram))))
3222 end Is_Exception_Safe;
3224 -- Start of processing for Build_Protected_Subprogram_Body
3227 Op_Spec := Specification (N);
3228 Exc_Safe := Is_Exception_Safe (N);
3231 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3233 -- Build a list of the formal parameters of the protected version of
3234 -- the subprogram to use as the actual parameters of the unprotected
3237 Uactuals := New_List;
3238 Pformal := First (Parameter_Specifications (P_Op_Spec));
3239 while Present (Pformal) loop
3241 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
3246 -- Make a call to the unprotected version of the subprogram built above
3247 -- for use by the protected version built below.
3249 if Nkind (Op_Spec) = N_Function_Specification then
3251 R := Make_Temporary (Loc, 'R');
3253 Make_Object_Declaration (Loc,
3254 Defining_Identifier => R,
3255 Constant_Present => True,
3256 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3258 Make_Function_Call (Loc,
3259 Name => Make_Identifier (Loc,
3260 Chars (Defining_Unit_Name (N_Op_Spec))),
3261 Parameter_Associations => Uactuals));
3264 Make_Simple_Return_Statement (Loc,
3265 Expression => New_Reference_To (R, Loc));
3268 Unprot_Call := Make_Simple_Return_Statement (Loc,
3269 Expression => Make_Function_Call (Loc,
3271 Make_Identifier (Loc,
3272 Chars (Defining_Unit_Name (N_Op_Spec))),
3273 Parameter_Associations => Uactuals));
3278 Make_Procedure_Call_Statement (Loc,
3280 Make_Identifier (Loc,
3281 Chars (Defining_Unit_Name (N_Op_Spec))),
3282 Parameter_Associations => Uactuals);
3285 -- Wrap call in block that will be covered by an at_end handler
3287 if not Exc_Safe then
3288 Unprot_Call := Make_Block_Statement (Loc,
3289 Handled_Statement_Sequence =>
3290 Make_Handled_Sequence_Of_Statements (Loc,
3291 Statements => New_List (Unprot_Call)));
3294 -- Make the protected subprogram body. This locks the protected
3295 -- object and calls the unprotected version of the subprogram.
3297 case Corresponding_Runtime_Package (Pid) is
3298 when System_Tasking_Protected_Objects_Entries =>
3299 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3300 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3302 when System_Tasking_Protected_Objects_Single_Entry =>
3303 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3304 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3306 when System_Tasking_Protected_Objects =>
3307 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3308 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3311 raise Program_Error;
3315 Make_Attribute_Reference (Loc,
3317 Make_Selected_Component (Loc,
3319 Make_Identifier (Loc, Name_uObject),
3321 Make_Identifier (Loc, Name_uObject)),
3322 Attribute_Name => Name_Unchecked_Access);
3324 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3326 Parameter_Associations => New_List (Object_Parm));
3328 if Abort_Allowed then
3330 Make_Procedure_Call_Statement (Loc,
3331 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3332 Parameter_Associations => Empty_List),
3336 Stmts := New_List (Lock_Stmt);
3339 if not Exc_Safe then
3340 Append (Unprot_Call, Stmts);
3342 if Nkind (Op_Spec) = N_Function_Specification then
3344 Stmts := Empty_List;
3346 Append (Unprot_Call, Stmts);
3350 Make_Procedure_Call_Statement (Loc,
3351 Name => Service_Name,
3352 Parameter_Associations =>
3353 New_List (New_Copy_Tree (Object_Parm))),
3356 if Abort_Allowed then
3358 Make_Procedure_Call_Statement (Loc,
3359 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3360 Parameter_Associations => Empty_List),
3364 if Nkind (Op_Spec) = N_Function_Specification then
3365 Append (Return_Stmt, Stmts);
3366 Append (Make_Block_Statement (Loc,
3367 Declarations => New_List (Unprot_Call),
3368 Handled_Statement_Sequence =>
3369 Make_Handled_Sequence_Of_Statements (Loc,
3370 Statements => Stmts)), Pre_Stmts);
3376 Make_Subprogram_Body (Loc,
3377 Declarations => Empty_List,
3378 Specification => P_Op_Spec,
3379 Handled_Statement_Sequence =>
3380 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3382 if not Exc_Safe then
3383 Set_Is_Protected_Subprogram_Body (Sub_Body);
3387 end Build_Protected_Subprogram_Body;
3389 -------------------------------------
3390 -- Build_Protected_Subprogram_Call --
3391 -------------------------------------
3393 procedure Build_Protected_Subprogram_Call
3397 External : Boolean := True)
3399 Loc : constant Source_Ptr := Sloc (N);
3400 Sub : constant Entity_Id := Entity (Name);
3406 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3409 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3412 if Present (Parameter_Associations (N)) then
3413 Params := New_Copy_List_Tree (Parameter_Associations (N));
3418 -- If the type is an untagged derived type, convert to the root type,
3419 -- which is the one on which the operations are defined.
3421 if Nkind (Rec) = N_Unchecked_Type_Conversion
3422 and then not Is_Tagged_Type (Etype (Rec))
3423 and then Is_Derived_Type (Etype (Rec))
3425 Set_Etype (Rec, Root_Type (Etype (Rec)));
3426 Set_Subtype_Mark (Rec,
3427 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3430 Prepend (Rec, Params);
3432 if Ekind (Sub) = E_Procedure then
3434 Make_Procedure_Call_Statement (Loc,
3436 Parameter_Associations => Params));
3439 pragma Assert (Ekind (Sub) = E_Function);
3441 Make_Function_Call (Loc,
3443 Parameter_Associations => Params));
3447 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3448 and then Is_Entity_Name (Expression (Rec))
3449 and then Is_Shared_Passive (Entity (Expression (Rec)))
3451 Add_Shared_Var_Lock_Procs (N);
3453 end Build_Protected_Subprogram_Call;
3455 -------------------------
3456 -- Build_Selected_Name --
3457 -------------------------
3459 function Build_Selected_Name
3460 (Prefix : Entity_Id;
3461 Selector : Entity_Id;
3462 Append_Char : Character := ' ') return Name_Id
3464 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3465 Select_Len : Natural;
3468 Get_Name_String (Chars (Selector));
3469 Select_Len := Name_Len;
3470 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3471 Get_Name_String (Chars (Prefix));
3473 -- If scope is anonymous type, discard suffix to recover name of
3474 -- single protected object. Otherwise use protected type name.
3476 if Name_Buffer (Name_Len) = 'T' then
3477 Name_Len := Name_Len - 1;
3480 Add_Str_To_Name_Buffer ("__");
3481 for J in 1 .. Select_Len loop
3482 Add_Char_To_Name_Buffer (Select_Buffer (J));
3485 -- Now add the Append_Char if specified. The encoding to follow
3486 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3487 -- then the entity is associated to a protected type subprogram.
3488 -- Otherwise, it is a protected type entry. For each case, the
3489 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3491 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3493 if Append_Char /= ' ' then
3494 if Append_Char = 'P' or Append_Char = 'N' then
3495 Add_Char_To_Name_Buffer (Append_Char);
3498 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3499 return New_External_Name (Name_Find, ' ', -1);
3504 end Build_Selected_Name;
3506 -----------------------------
3507 -- Build_Simple_Entry_Call --
3508 -----------------------------
3510 -- A task entry call is converted to a call to Call_Simple
3513 -- P : parms := (parm, parm, parm);
3515 -- Call_Simple (acceptor-task, entry-index, P'Address);
3521 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3522 -- the parameters, and the constructed aggregate value contains either the
3523 -- parameters or, in the case of non-elementary types, references to these
3524 -- parameters. Then the address of this aggregate is passed to the runtime
3525 -- routine, along with the task id value and the task entry index value.
3526 -- Pnn is only required if parameters are present.
3528 -- The assignments after the call are present only in the case of in-out
3529 -- or out parameters for elementary types, and are used to assign back the
3530 -- resulting values of such parameters.
3532 -- Note: the reason that we insert a block here is that in the context
3533 -- of selects, conditional entry calls etc. the entry call statement
3534 -- appears on its own, not as an element of a list.
3536 -- A protected entry call is converted to a Protected_Entry_Call:
3539 -- P : E1_Params := (param, param, param);
3541 -- Bnn : Communications_Block;
3544 -- P : E1_Params := (param, param, param);
3545 -- Bnn : Communications_Block;
3548 -- Protected_Entry_Call (
3549 -- Object => po._object'Access,
3550 -- E => <entry index>;
3551 -- Uninterpreted_Data => P'Address;
3552 -- Mode => Simple_Call;
3559 procedure Build_Simple_Entry_Call
3568 -- If call has been inlined, nothing left to do
3570 if Nkind (N) = N_Block_Statement then
3574 -- Convert entry call to Call_Simple call
3577 Loc : constant Source_Ptr := Sloc (N);
3578 Parms : constant List_Id := Parameter_Associations (N);
3579 Stats : constant List_Id := New_List;
3582 Comm_Name : Entity_Id;
3586 Ent_Acc : Entity_Id;
3588 Iface_Tag : Entity_Id;
3589 Iface_Typ : Entity_Id;
3602 -- Simple entry and entry family cases merge here
3604 Ent := Entity (Ename);
3605 Ent_Acc := Entry_Parameters_Type (Ent);
3606 Conctyp := Etype (Concval);
3608 -- If prefix is an access type, dereference to obtain the task type
3610 if Is_Access_Type (Conctyp) then
3611 Conctyp := Designated_Type (Conctyp);
3614 -- Special case for protected subprogram calls
3616 if Is_Protected_Type (Conctyp)
3617 and then Is_Subprogram (Entity (Ename))
3619 if not Is_Eliminated (Entity (Ename)) then
3620 Build_Protected_Subprogram_Call
3621 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3628 -- First parameter is the Task_Id value from the task value or the
3629 -- Object from the protected object value, obtained by selecting
3630 -- the _Task_Id or _Object from the result of doing an unchecked
3631 -- conversion to convert the value to the corresponding record type.
3633 if Nkind (Concval) = N_Function_Call
3634 and then Is_Task_Type (Conctyp)
3635 and then Ada_Version >= Ada_2005
3638 ExpR : constant Node_Id := Relocate_Node (Concval);
3639 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3644 Make_Object_Declaration (Loc,
3645 Defining_Identifier => Obj,
3646 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3647 Expression => ExpR);
3648 Set_Etype (Obj, Conctyp);
3649 Decls := New_List (Decl);
3650 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3657 Parm1 := Concurrent_Ref (Concval);
3659 -- Second parameter is the entry index, computed by the routine
3660 -- provided for this purpose. The value of this expression is
3661 -- assigned to an intermediate variable to assure that any entry
3662 -- family index expressions are evaluated before the entry
3666 or else Restriction_Active (No_Entry_Queue) = False
3667 or else not Is_Protected_Type (Conctyp)
3668 or else Number_Entries (Conctyp) > 1
3669 or else (Has_Attach_Handler (Conctyp)
3670 and then not Restricted_Profile)
3672 X := Make_Defining_Identifier (Loc, Name_uX);
3675 Make_Object_Declaration (Loc,
3676 Defining_Identifier => X,
3677 Object_Definition =>
3678 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3679 Expression => Actual_Index_Expression (
3680 Loc, Entity (Ename), Index, Concval));
3682 Append_To (Decls, Xdecl);
3683 Parm2 := New_Reference_To (X, Loc);
3690 -- The third parameter is the packaged parameters. If there are
3691 -- none, then it is just the null address, since nothing is passed.
3694 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3697 -- Case of parameters present, where third argument is the address
3698 -- of a packaged record containing the required parameter values.
3701 -- First build a list of parameter values, which are references to
3702 -- objects of the parameter types.
3706 Actual := First_Actual (N);
3707 Formal := First_Formal (Ent);
3709 while Present (Actual) loop
3711 -- If it is a by_copy_type, copy it to a new variable. The
3712 -- packaged record has a field that points to this variable.
3714 if Is_By_Copy_Type (Etype (Actual)) then
3716 Make_Object_Declaration (Loc,
3717 Defining_Identifier => Make_Temporary (Loc, 'J'),
3718 Aliased_Present => True,
3719 Object_Definition =>
3720 New_Reference_To (Etype (Formal), Loc));
3722 -- Mark the object as not needing initialization since the
3723 -- initialization is performed separately, avoiding errors
3724 -- on cases such as formals of null-excluding access types.
3726 Set_No_Initialization (N_Node);
3728 -- We must make an assignment statement separate for the
3729 -- case of limited type. We cannot assign it unless the
3730 -- Assignment_OK flag is set first. An out formal of an
3731 -- access type must also be initialized from the actual,
3732 -- as stated in RM 6.4.1 (13).
3734 if Ekind (Formal) /= E_Out_Parameter
3735 or else Is_Access_Type (Etype (Formal))
3738 New_Reference_To (Defining_Identifier (N_Node), Loc);
3739 Set_Assignment_OK (N_Var);
3741 Make_Assignment_Statement (Loc,
3743 Expression => Relocate_Node (Actual)));
3746 Append (N_Node, Decls);
3749 Make_Attribute_Reference (Loc,
3750 Attribute_Name => Name_Unchecked_Access,
3752 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3754 -- Interface class-wide formal
3756 if Ada_Version >= Ada_2005
3757 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3758 and then Is_Interface (Etype (Formal))
3760 Iface_Typ := Etype (Etype (Formal));
3763 -- formal_iface_type! (actual.iface_tag)'reference
3766 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3767 pragma Assert (Present (Iface_Tag));
3770 Make_Reference (Loc,
3771 Unchecked_Convert_To (Iface_Typ,
3772 Make_Selected_Component (Loc,
3774 Relocate_Node (Actual),
3776 New_Reference_To (Iface_Tag, Loc)))));
3782 Make_Reference (Loc, Relocate_Node (Actual)));
3786 Next_Actual (Actual);
3787 Next_Formal_With_Extras (Formal);
3790 -- Now build the declaration of parameters initialized with the
3791 -- aggregate containing this constructed parameter list.
3793 P := Make_Defining_Identifier (Loc, Name_uP);
3796 Make_Object_Declaration (Loc,
3797 Defining_Identifier => P,
3798 Object_Definition =>
3799 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3801 Make_Aggregate (Loc, Expressions => Plist));
3804 Make_Attribute_Reference (Loc,
3805 Prefix => New_Reference_To (P, Loc),
3806 Attribute_Name => Name_Address);
3808 Append (Pdecl, Decls);
3811 -- Now we can create the call, case of protected type
3813 if Is_Protected_Type (Conctyp) then
3814 case Corresponding_Runtime_Package (Conctyp) is
3815 when System_Tasking_Protected_Objects_Entries =>
3817 -- Change the type of the index declaration
3819 Set_Object_Definition (Xdecl,
3820 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3822 -- Some additional declarations for protected entry calls
3828 -- Bnn : Communications_Block;
3830 Comm_Name := Make_Temporary (Loc, 'B');
3833 Make_Object_Declaration (Loc,
3834 Defining_Identifier => Comm_Name,
3835 Object_Definition =>
3836 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3838 -- Some additional statements for protected entry calls
3840 -- Protected_Entry_Call (
3841 -- Object => po._object'Access,
3842 -- E => <entry index>;
3843 -- Uninterpreted_Data => P'Address;
3844 -- Mode => Simple_Call;
3848 Make_Procedure_Call_Statement (Loc,
3850 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3852 Parameter_Associations => New_List (
3853 Make_Attribute_Reference (Loc,
3854 Attribute_Name => Name_Unchecked_Access,
3858 New_Reference_To (RTE (RE_Simple_Call), Loc),
3859 New_Occurrence_Of (Comm_Name, Loc)));
3861 when System_Tasking_Protected_Objects_Single_Entry =>
3862 -- Protected_Single_Entry_Call (
3863 -- Object => po._object'Access,
3864 -- Uninterpreted_Data => P'Address;
3865 -- Mode => Simple_Call);
3868 Make_Procedure_Call_Statement (Loc,
3869 Name => New_Reference_To (
3870 RTE (RE_Protected_Single_Entry_Call), Loc),
3872 Parameter_Associations => New_List (
3873 Make_Attribute_Reference (Loc,
3874 Attribute_Name => Name_Unchecked_Access,
3877 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3880 raise Program_Error;
3883 -- Case of task type
3887 Make_Procedure_Call_Statement (Loc,
3888 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3889 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3893 Append_To (Stats, Call);
3895 -- If there are out or in/out parameters by copy add assignment
3896 -- statements for the result values.
3898 if Present (Parms) then
3899 Actual := First_Actual (N);
3900 Formal := First_Formal (Ent);
3902 Set_Assignment_OK (Actual);
3903 while Present (Actual) loop
3904 if Is_By_Copy_Type (Etype (Actual))
3905 and then Ekind (Formal) /= E_In_Parameter
3908 Make_Assignment_Statement (Loc,
3909 Name => New_Copy (Actual),
3911 Make_Explicit_Dereference (Loc,
3912 Make_Selected_Component (Loc,
3913 Prefix => New_Reference_To (P, Loc),
3915 Make_Identifier (Loc, Chars (Formal)))));
3917 -- In all cases (including limited private types) we want
3918 -- the assignment to be valid.
3920 Set_Assignment_OK (Name (N_Node));
3922 -- If the call is the triggering alternative in an
3923 -- asynchronous select, or the entry_call alternative of a
3924 -- conditional entry call, the assignments for in-out
3925 -- parameters are incorporated into the statement list that
3926 -- follows, so that there are executed only if the entry
3929 if (Nkind (Parent (N)) = N_Triggering_Alternative
3930 and then N = Triggering_Statement (Parent (N)))
3932 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3933 and then N = Entry_Call_Statement (Parent (N)))
3935 if No (Statements (Parent (N))) then
3936 Set_Statements (Parent (N), New_List);
3939 Prepend (N_Node, Statements (Parent (N)));
3942 Insert_After (Call, N_Node);
3946 Next_Actual (Actual);
3947 Next_Formal_With_Extras (Formal);
3951 -- Finally, create block and analyze it
3954 Make_Block_Statement (Loc,
3955 Declarations => Decls,
3956 Handled_Statement_Sequence =>
3957 Make_Handled_Sequence_Of_Statements (Loc,
3958 Statements => Stats)));
3962 end Build_Simple_Entry_Call;
3964 --------------------------------
3965 -- Build_Task_Activation_Call --
3966 --------------------------------
3968 procedure Build_Task_Activation_Call (N : Node_Id) is
3969 Loc : constant Source_Ptr := Sloc (N);
3976 -- Get the activation chain entity. Except in the case of a package
3977 -- body, this is in the node that was passed. For a package body, we
3978 -- have to find the corresponding package declaration node.
3980 if Nkind (N) = N_Package_Body then
3981 P := Corresponding_Spec (N);
3984 exit when Nkind (P) = N_Package_Declaration;
3987 Chain := Activation_Chain_Entity (P);
3990 Chain := Activation_Chain_Entity (N);
3993 if Present (Chain) then
3994 if Restricted_Profile then
3995 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3997 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4001 Make_Procedure_Call_Statement (Loc,
4003 Parameter_Associations =>
4004 New_List (Make_Attribute_Reference (Loc,
4005 Prefix => New_Occurrence_Of (Chain, Loc),
4006 Attribute_Name => Name_Unchecked_Access)));
4008 if Nkind (N) = N_Package_Declaration then
4009 if Present (Corresponding_Body (N)) then
4012 elsif Present (Private_Declarations (Specification (N))) then
4013 Append (Call, Private_Declarations (Specification (N)));
4016 Append (Call, Visible_Declarations (Specification (N)));
4020 if Present (Handled_Statement_Sequence (N)) then
4022 -- The call goes at the start of the statement sequence
4023 -- after the start of exception range label if one is present.
4029 Stm := First (Statements (Handled_Statement_Sequence (N)));
4031 -- A special case, skip exception range label if one is
4032 -- present (from front end zcx processing).
4034 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4038 -- Another special case, if the first statement is a block
4039 -- from optimization of a local raise to a goto, then the
4040 -- call goes inside this block.
4042 if Nkind (Stm) = N_Block_Statement
4043 and then Exception_Junk (Stm)
4046 First (Statements (Handled_Statement_Sequence (Stm)));
4049 -- Insertion point is after any exception label pushes,
4050 -- since we want it covered by any local handlers.
4052 while Nkind (Stm) in N_Push_xxx_Label loop
4056 -- Now we have the proper insertion point
4058 Insert_Before (Stm, Call);
4062 Set_Handled_Statement_Sequence (N,
4063 Make_Handled_Sequence_Of_Statements (Loc,
4064 Statements => New_List (Call)));
4069 Check_Task_Activation (N);
4071 end Build_Task_Activation_Call;
4073 -------------------------------
4074 -- Build_Task_Allocate_Block --
4075 -------------------------------
4077 procedure Build_Task_Allocate_Block
4082 T : constant Entity_Id := Entity (Expression (N));
4083 Init : constant Entity_Id := Base_Init_Proc (T);
4084 Loc : constant Source_Ptr := Sloc (N);
4085 Chain : constant Entity_Id :=
4086 Make_Defining_Identifier (Loc, Name_uChain);
4087 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4092 Make_Block_Statement (Loc,
4093 Identifier => New_Reference_To (Blkent, Loc),
4094 Declarations => New_List (
4096 -- _Chain : Activation_Chain;
4098 Make_Object_Declaration (Loc,
4099 Defining_Identifier => Chain,
4100 Aliased_Present => True,
4101 Object_Definition =>
4102 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4104 Handled_Statement_Sequence =>
4105 Make_Handled_Sequence_Of_Statements (Loc,
4107 Statements => New_List (
4111 Make_Procedure_Call_Statement (Loc,
4112 Name => New_Reference_To (Init, Loc),
4113 Parameter_Associations => Args),
4115 -- Activate_Tasks (_Chain);
4117 Make_Procedure_Call_Statement (Loc,
4118 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4119 Parameter_Associations => New_List (
4120 Make_Attribute_Reference (Loc,
4121 Prefix => New_Reference_To (Chain, Loc),
4122 Attribute_Name => Name_Unchecked_Access))))),
4124 Has_Created_Identifier => True,
4125 Is_Task_Allocation_Block => True);
4128 Make_Implicit_Label_Declaration (Loc,
4129 Defining_Identifier => Blkent,
4130 Label_Construct => Block));
4132 Append_To (Actions, Block);
4134 Set_Activation_Chain_Entity (Block, Chain);
4135 end Build_Task_Allocate_Block;
4137 -----------------------------------------------
4138 -- Build_Task_Allocate_Block_With_Init_Stmts --
4139 -----------------------------------------------
4141 procedure Build_Task_Allocate_Block_With_Init_Stmts
4144 Init_Stmts : List_Id)
4146 Loc : constant Source_Ptr := Sloc (N);
4147 Chain : constant Entity_Id :=
4148 Make_Defining_Identifier (Loc, Name_uChain);
4149 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4153 Append_To (Init_Stmts,
4154 Make_Procedure_Call_Statement (Loc,
4155 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4156 Parameter_Associations => New_List (
4157 Make_Attribute_Reference (Loc,
4158 Prefix => New_Reference_To (Chain, Loc),
4159 Attribute_Name => Name_Unchecked_Access))));
4162 Make_Block_Statement (Loc,
4163 Identifier => New_Reference_To (Blkent, Loc),
4164 Declarations => New_List (
4166 -- _Chain : Activation_Chain;
4168 Make_Object_Declaration (Loc,
4169 Defining_Identifier => Chain,
4170 Aliased_Present => True,
4171 Object_Definition =>
4172 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4174 Handled_Statement_Sequence =>
4175 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4177 Has_Created_Identifier => True,
4178 Is_Task_Allocation_Block => True);
4181 Make_Implicit_Label_Declaration (Loc,
4182 Defining_Identifier => Blkent,
4183 Label_Construct => Block));
4185 Append_To (Actions, Block);
4187 Set_Activation_Chain_Entity (Block, Chain);
4188 end Build_Task_Allocate_Block_With_Init_Stmts;
4190 -----------------------------------
4191 -- Build_Task_Proc_Specification --
4192 -----------------------------------
4194 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4195 Loc : constant Source_Ptr := Sloc (T);
4196 Spec_Id : Entity_Id;
4199 -- Case of explicit task type, suffix TB
4201 if Comes_From_Source (T) then
4203 Make_Defining_Identifier (Loc,
4204 Chars => New_External_Name (Chars (T), "TB"));
4206 -- Case of anonymous task type, suffix B
4210 Make_Defining_Identifier (Loc,
4211 Chars => New_External_Name (Chars (T), 'B'));
4214 Set_Is_Internal (Spec_Id);
4216 -- Associate the procedure with the task, if this is the declaration
4217 -- (and not the body) of the procedure.
4219 if No (Task_Body_Procedure (T)) then
4220 Set_Task_Body_Procedure (T, Spec_Id);
4224 Make_Procedure_Specification (Loc,
4225 Defining_Unit_Name => Spec_Id,
4226 Parameter_Specifications => New_List (
4227 Make_Parameter_Specification (Loc,
4228 Defining_Identifier =>
4229 Make_Defining_Identifier (Loc, Name_uTask),
4231 Make_Access_Definition (Loc,
4233 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4234 end Build_Task_Proc_Specification;
4236 ---------------------------------------
4237 -- Build_Unprotected_Subprogram_Body --
4238 ---------------------------------------
4240 function Build_Unprotected_Subprogram_Body
4242 Pid : Node_Id) return Node_Id
4244 Decls : constant List_Id := Declarations (N);
4247 -- Add renamings for the Protection object, discriminals, privals and
4248 -- the entry index constant for use by debugger.
4250 Debug_Private_Data_Declarations (Decls);
4252 -- Make an unprotected version of the subprogram for use within the same
4253 -- object, with a new name and an additional parameter representing the
4257 Make_Subprogram_Body (Sloc (N),
4259 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4260 Declarations => Decls,
4261 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4262 end Build_Unprotected_Subprogram_Body;
4264 ----------------------------
4265 -- Collect_Entry_Families --
4266 ----------------------------
4268 procedure Collect_Entry_Families
4271 Current_Node : in out Node_Id;
4272 Conctyp : Entity_Id)
4275 Efam_Decl : Node_Id;
4276 Efam_Type : Entity_Id;
4279 Efam := First_Entity (Conctyp);
4280 while Present (Efam) loop
4281 if Ekind (Efam) = E_Entry_Family then
4282 Efam_Type := Make_Temporary (Loc, 'F');
4287 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4289 Bas_Decl : Node_Id := Empty;
4294 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4296 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4297 Bas := Make_Temporary (Loc, 'B');
4300 Make_Subtype_Declaration (Loc,
4301 Defining_Identifier => Bas,
4302 Subtype_Indication =>
4303 Make_Subtype_Indication (Loc,
4305 New_Occurrence_Of (Standard_Integer, Loc),
4307 Make_Range_Constraint (Loc,
4308 Range_Expression => Make_Range (Loc,
4309 Make_Integer_Literal
4310 (Loc, -Entry_Family_Bound),
4311 Make_Integer_Literal
4312 (Loc, Entry_Family_Bound - 1)))));
4314 Insert_After (Current_Node, Bas_Decl);
4315 Current_Node := Bas_Decl;
4320 Make_Full_Type_Declaration (Loc,
4321 Defining_Identifier => Efam_Type,
4323 Make_Unconstrained_Array_Definition (Loc,
4325 (New_List (New_Occurrence_Of (Bas, Loc))),
4327 Component_Definition =>
4328 Make_Component_Definition (Loc,
4329 Aliased_Present => False,
4330 Subtype_Indication =>
4331 New_Reference_To (Standard_Character, Loc))));
4334 Insert_After (Current_Node, Efam_Decl);
4335 Current_Node := Efam_Decl;
4336 Analyze (Efam_Decl);
4339 Make_Component_Declaration (Loc,
4340 Defining_Identifier =>
4341 Make_Defining_Identifier (Loc, Chars (Efam)),
4343 Component_Definition =>
4344 Make_Component_Definition (Loc,
4345 Aliased_Present => False,
4346 Subtype_Indication =>
4347 Make_Subtype_Indication (Loc,
4349 New_Occurrence_Of (Efam_Type, Loc),
4352 Make_Index_Or_Discriminant_Constraint (Loc,
4353 Constraints => New_List (
4355 (Etype (Discrete_Subtype_Definition
4356 (Parent (Efam))), Loc)))))));
4362 end Collect_Entry_Families;
4364 -----------------------
4365 -- Concurrent_Object --
4366 -----------------------
4368 function Concurrent_Object
4369 (Spec_Id : Entity_Id;
4370 Conc_Typ : Entity_Id) return Entity_Id
4373 -- Parameter _O or _object
4375 if Is_Protected_Type (Conc_Typ) then
4376 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4381 pragma Assert (Is_Task_Type (Conc_Typ));
4382 return First_Formal (Task_Body_Procedure (Conc_Typ));
4384 end Concurrent_Object;
4386 ----------------------
4387 -- Copy_Result_Type --
4388 ----------------------
4390 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4391 New_Res : constant Node_Id := New_Copy_Tree (Res);
4396 -- If the result type is an access_to_subprogram, we must create
4397 -- new entities for its spec.
4399 if Nkind (New_Res) = N_Access_Definition
4400 and then Present (Access_To_Subprogram_Definition (New_Res))
4402 -- Provide new entities for the formals
4404 Par_Spec := First (Parameter_Specifications
4405 (Access_To_Subprogram_Definition (New_Res)));
4406 while Present (Par_Spec) loop
4407 Formal := Defining_Identifier (Par_Spec);
4408 Set_Defining_Identifier (Par_Spec,
4409 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4415 end Copy_Result_Type;
4417 --------------------
4418 -- Concurrent_Ref --
4419 --------------------
4421 -- The expression returned for a reference to a concurrent object has the
4424 -- taskV!(name)._Task_Id
4428 -- objectV!(name)._Object
4430 -- for a protected object. For the case of an access to a concurrent
4431 -- object, there is an extra explicit dereference:
4433 -- taskV!(name.all)._Task_Id
4434 -- objectV!(name.all)._Object
4436 -- here taskV and objectV are the types for the associated records, which
4437 -- contain the required _Task_Id and _Object fields for tasks and protected
4438 -- objects, respectively.
4440 -- For the case of a task type name, the expression is
4444 -- i.e. a call to the Self function which returns precisely this Task_Id
4446 -- For the case of a protected type name, the expression is
4450 -- which is a renaming of the _object field of the current object
4451 -- record, passed into protected operations as a parameter.
4453 function Concurrent_Ref (N : Node_Id) return Node_Id is
4454 Loc : constant Source_Ptr := Sloc (N);
4455 Ntyp : constant Entity_Id := Etype (N);
4459 function Is_Current_Task (T : Entity_Id) return Boolean;
4460 -- Check whether the reference is to the immediately enclosing task
4461 -- type, or to an outer one (rare but legal).
4463 ---------------------
4464 -- Is_Current_Task --
4465 ---------------------
4467 function Is_Current_Task (T : Entity_Id) return Boolean is
4471 Scop := Current_Scope;
4472 while Present (Scop)
4473 and then Scop /= Standard_Standard
4479 elsif Is_Task_Type (Scop) then
4482 -- If this is a procedure nested within the task type, we must
4483 -- assume that it can be called from an inner task, and therefore
4484 -- cannot treat it as a local reference.
4486 elsif Is_Overloadable (Scop)
4487 and then In_Open_Scopes (T)
4492 Scop := Scope (Scop);
4496 -- We know that we are within the task body, so should have found it
4499 raise Program_Error;
4500 end Is_Current_Task;
4502 -- Start of processing for Concurrent_Ref
4505 if Is_Access_Type (Ntyp) then
4506 Dtyp := Designated_Type (Ntyp);
4508 if Is_Protected_Type (Dtyp) then
4509 Sel := Name_uObject;
4511 Sel := Name_uTask_Id;
4515 Make_Selected_Component (Loc,
4517 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4518 Make_Explicit_Dereference (Loc, N)),
4519 Selector_Name => Make_Identifier (Loc, Sel));
4521 elsif Is_Entity_Name (N)
4522 and then Is_Concurrent_Type (Entity (N))
4524 if Is_Task_Type (Entity (N)) then
4526 if Is_Current_Task (Entity (N)) then
4528 Make_Function_Call (Loc,
4529 Name => New_Reference_To (RTE (RE_Self), Loc));
4534 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4535 T_Body : constant Node_Id :=
4536 Parent (Corresponding_Body (Parent (Entity (N))));
4540 Make_Object_Declaration (Loc,
4541 Defining_Identifier => T_Self,
4542 Object_Definition =>
4543 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4545 Make_Function_Call (Loc,
4546 Name => New_Reference_To (RTE (RE_Self), Loc)));
4547 Prepend (Decl, Declarations (T_Body));
4549 Set_Scope (T_Self, Entity (N));
4550 return New_Occurrence_Of (T_Self, Loc);
4555 pragma Assert (Is_Protected_Type (Entity (N)));
4558 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4562 if Is_Protected_Type (Ntyp) then
4563 Sel := Name_uObject;
4565 elsif Is_Task_Type (Ntyp) then
4566 Sel := Name_uTask_Id;
4569 raise Program_Error;
4573 Make_Selected_Component (Loc,
4575 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4577 Selector_Name => Make_Identifier (Loc, Sel));
4581 ------------------------
4582 -- Convert_Concurrent --
4583 ------------------------
4585 function Convert_Concurrent
4587 Typ : Entity_Id) return Node_Id
4590 if not Is_Concurrent_Type (Typ) then
4594 Unchecked_Convert_To
4595 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4597 end Convert_Concurrent;
4599 -------------------------------------
4600 -- Debug_Private_Data_Declarations --
4601 -------------------------------------
4603 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4604 Debug_Nod : Node_Id;
4608 Decl := First (Decls);
4609 while Present (Decl)
4610 and then not Comes_From_Source (Decl)
4612 -- Declaration for concurrent entity _object and its access type,
4613 -- along with the entry index subtype:
4614 -- type prot_typVP is access prot_typV;
4615 -- _object : prot_typVP := prot_typV (_O);
4616 -- subtype Jnn is <Type of Index> range Low .. High;
4618 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4619 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4621 -- Declaration for the Protection object, discriminals, privals and
4622 -- entry index constant:
4623 -- conc_typR : protection_typ renames _object._object;
4624 -- discr_nameD : discr_typ renames _object.discr_name;
4625 -- discr_nameD : discr_typ renames _task.discr_name;
4626 -- prival_name : comp_typ renames _object.comp_name;
4627 -- J : constant Jnn :=
4628 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4630 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4631 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4632 Debug_Nod := Debug_Renaming_Declaration (Decl);
4634 if Present (Debug_Nod) then
4635 Insert_After (Decl, Debug_Nod);
4641 end Debug_Private_Data_Declarations;
4643 ----------------------------
4644 -- Entry_Index_Expression --
4645 ----------------------------
4647 function Entry_Index_Expression
4651 Ttyp : Entity_Id) return Node_Id
4661 -- The queues of entries and entry families appear in textual order in
4662 -- the associated record. The entry index is computed as the sum of the
4663 -- number of queues for all entries that precede the designated one, to
4664 -- which is added the index expression, if this expression denotes a
4665 -- member of a family.
4667 -- The following is a place holder for the count of simple entries
4669 Num := Make_Integer_Literal (Sloc, 1);
4671 -- We construct an expression which is a series of addition operations.
4672 -- The first operand is the number of single entries that precede this
4673 -- one, the second operand is the index value relative to the start of
4674 -- the referenced family, and the remaining operands are the lengths of
4675 -- the entry families that precede this entry, i.e. the constructed
4678 -- number_simple_entries +
4679 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4680 -- family'length + ...
4682 -- where index-value is the given index value, and s is the index
4683 -- subtype (we have to use pos because the subtype might be an
4684 -- enumeration type preventing direct subtraction). Note that the task
4685 -- entry array is one-indexed.
4687 -- The upper bound of the entry family may be a discriminant, so we
4688 -- retrieve the lower bound explicitly to compute offset, rather than
4689 -- using the index subtype which may mention a discriminant.
4691 if Present (Index) then
4692 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4701 Make_Attribute_Reference (Sloc,
4702 Attribute_Name => Name_Pos,
4703 Prefix => New_Reference_To (Base_Type (S), Sloc),
4704 Expressions => New_List (Relocate_Node (Index))),
4712 -- Now add lengths of preceding entries and entry families
4714 Prev := First_Entity (Ttyp);
4716 while Chars (Prev) /= Chars (Ent)
4717 or else (Ekind (Prev) /= Ekind (Ent))
4718 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4720 if Ekind (Prev) = E_Entry then
4721 Set_Intval (Num, Intval (Num) + 1);
4723 elsif Ekind (Prev) = E_Entry_Family then
4725 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4726 Lo := Type_Low_Bound (S);
4727 Hi := Type_High_Bound (S);
4732 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4734 -- Other components are anonymous types to be ignored
4744 end Entry_Index_Expression;
4746 ---------------------------
4747 -- Establish_Task_Master --
4748 ---------------------------
4750 procedure Establish_Task_Master (N : Node_Id) is
4753 if Restriction_Active (No_Task_Hierarchy) = False then
4754 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4755 Prepend_To (Declarations (N), Call);
4758 end Establish_Task_Master;
4760 --------------------------------
4761 -- Expand_Accept_Declarations --
4762 --------------------------------
4764 -- Part of the expansion of an accept statement involves the creation of
4765 -- a declaration that can be referenced from the statement sequence of
4770 -- This declaration is inserted immediately before the accept statement
4771 -- and it is important that it be inserted before the statements of the
4772 -- statement sequence are analyzed. Thus it would be too late to create
4773 -- this declaration in the Expand_N_Accept_Statement routine, which is
4774 -- why there is a separate procedure to be called directly from Sem_Ch9.
4776 -- Ann is used to hold the address of the record containing the parameters
4777 -- (see Expand_N_Entry_Call for more details on how this record is built).
4778 -- References to the parameters do an unchecked conversion of this address
4779 -- to a pointer to the required record type, and then access the field that
4780 -- holds the value of the required parameter. The entity for the address
4781 -- variable is held as the top stack element (i.e. the last element) of the
4782 -- Accept_Address stack in the corresponding entry entity, and this element
4783 -- must be set in place before the statements are processed.
4785 -- The above description applies to the case of a stand alone accept
4786 -- statement, i.e. one not appearing as part of a select alternative.
4788 -- For the case of an accept that appears as part of a select alternative
4789 -- of a selective accept, we must still create the declaration right away,
4790 -- since Ann is needed immediately, but there is an important difference:
4792 -- The declaration is inserted before the selective accept, not before
4793 -- the accept statement (which is not part of a list anyway, and so would
4794 -- not accommodate inserted declarations)
4796 -- We only need one address variable for the entire selective accept. So
4797 -- the Ann declaration is created only for the first accept alternative,
4798 -- and subsequent accept alternatives reference the same Ann variable.
4800 -- We can distinguish the two cases by seeing whether the accept statement
4801 -- is part of a list. If not, then it must be in an accept alternative.
4803 -- To expand the requeue statement, a label is provided at the end of the
4804 -- accept statement or alternative of which it is a part, so that the
4805 -- statement can be skipped after the requeue is complete. This label is
4806 -- created here rather than during the expansion of the accept statement,
4807 -- because it will be needed by any requeue statements within the accept,
4808 -- which are expanded before the accept.
4810 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4811 Loc : constant Source_Ptr := Sloc (N);
4812 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4813 Ann : Entity_Id := Empty;
4821 if Expander_Active then
4823 -- If we have no handled statement sequence, we may need to build
4824 -- a dummy sequence consisting of a null statement. This can be
4825 -- skipped if the trivial accept optimization is permitted.
4827 if not Trivial_Accept_OK
4829 (No (Stats) or else Null_Statements (Statements (Stats)))
4831 Set_Handled_Statement_Sequence (N,
4832 Make_Handled_Sequence_Of_Statements (Loc,
4833 New_List (Make_Null_Statement (Loc))));
4836 -- Create and declare two labels to be placed at the end of the
4837 -- accept statement. The first label is used to allow requeues to
4838 -- skip the remainder of entry processing. The second label is used
4839 -- to skip the remainder of entry processing if the rendezvous
4840 -- completes in the middle of the accept body.
4842 if Present (Handled_Statement_Sequence (N)) then
4847 Ent := Make_Temporary (Loc, 'L');
4848 Lab_Id := New_Reference_To (Ent, Loc);
4849 Lab := Make_Label (Loc, Lab_Id);
4851 Make_Implicit_Label_Declaration (Loc,
4852 Defining_Identifier => Ent,
4853 Label_Construct => Lab);
4854 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4856 Ent := Make_Temporary (Loc, 'L');
4857 Lab_Id := New_Reference_To (Ent, Loc);
4858 Lab := Make_Label (Loc, Lab_Id);
4860 Make_Implicit_Label_Declaration (Loc,
4861 Defining_Identifier => Ent,
4862 Label_Construct => Lab);
4863 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4871 -- Case of stand alone accept statement
4873 if Is_List_Member (N) then
4875 if Present (Handled_Statement_Sequence (N)) then
4876 Ann := Make_Temporary (Loc, 'A');
4879 Make_Object_Declaration (Loc,
4880 Defining_Identifier => Ann,
4881 Object_Definition =>
4882 New_Reference_To (RTE (RE_Address), Loc));
4884 Insert_Before (N, Adecl);
4887 Insert_Before (N, Ldecl);
4890 Insert_Before (N, Ldecl2);
4894 -- Case of accept statement which is in an accept alternative
4898 Acc_Alt : constant Node_Id := Parent (N);
4899 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4903 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4904 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4906 -- ??? Consider a single label for select statements
4908 if Present (Handled_Statement_Sequence (N)) then
4910 Statements (Handled_Statement_Sequence (N)));
4914 Statements (Handled_Statement_Sequence (N)));
4918 -- Find first accept alternative of the selective accept. A
4919 -- valid selective accept must have at least one accept in it.
4921 Alt := First (Select_Alternatives (Sel_Acc));
4923 while Nkind (Alt) /= N_Accept_Alternative loop
4927 -- If we are the first accept statement, then we have to create
4928 -- the Ann variable, as for the stand alone case, except that
4929 -- it is inserted before the selective accept. Similarly, a
4930 -- label for requeue expansion must be declared.
4932 if N = Accept_Statement (Alt) then
4933 Ann := Make_Temporary (Loc, 'A');
4935 Make_Object_Declaration (Loc,
4936 Defining_Identifier => Ann,
4937 Object_Definition =>
4938 New_Reference_To (RTE (RE_Address), Loc));
4940 Insert_Before (Sel_Acc, Adecl);
4943 -- If we are not the first accept statement, then find the Ann
4944 -- variable allocated by the first accept and use it.
4948 Node (Last_Elmt (Accept_Address
4949 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4954 -- Merge here with Ann either created or referenced, and Adecl
4955 -- pointing to the corresponding declaration. Remaining processing
4956 -- is the same for the two cases.
4958 if Present (Ann) then
4959 Append_Elmt (Ann, Accept_Address (Ent));
4960 Set_Debug_Info_Needed (Ann);
4963 -- Create renaming declarations for the entry formals. Each reference
4964 -- to a formal becomes a dereference of a component of the parameter
4965 -- block, whose address is held in Ann. These declarations are
4966 -- eventually inserted into the accept block, and analyzed there so
4967 -- that they have the proper scope for gdb and do not conflict with
4968 -- other declarations.
4970 if Present (Parameter_Specifications (N))
4971 and then Present (Handled_Statement_Sequence (N))
4981 Formal := First_Formal (Ent);
4983 while Present (Formal) loop
4984 Comp := Entry_Component (Formal);
4986 Make_Defining_Identifier (Loc, Chars (Formal));
4988 Set_Etype (New_F, Etype (Formal));
4989 Set_Scope (New_F, Ent);
4991 -- Now we set debug info needed on New_F even though it does
4992 -- not come from source, so that the debugger will get the
4993 -- right information for these generated names.
4995 Set_Debug_Info_Needed (New_F);
4997 if Ekind (Formal) = E_In_Parameter then
4998 Set_Ekind (New_F, E_Constant);
5000 Set_Ekind (New_F, E_Variable);
5001 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5004 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5007 Make_Object_Renaming_Declaration (Loc,
5008 Defining_Identifier =>
5011 New_Reference_To (Etype (Formal), Loc),
5013 Make_Explicit_Dereference (Loc,
5014 Make_Selected_Component (Loc,
5016 Unchecked_Convert_To (
5017 Entry_Parameters_Type (Ent),
5018 New_Reference_To (Ann, Loc)),
5020 New_Reference_To (Comp, Loc))));
5022 if No (Declarations (N)) then
5023 Set_Declarations (N, New_List);
5026 Append (Decl, Declarations (N));
5027 Set_Renamed_Object (Formal, New_F);
5028 Next_Formal (Formal);
5035 end Expand_Accept_Declarations;
5037 ---------------------------------------------
5038 -- Expand_Access_Protected_Subprogram_Type --
5039 ---------------------------------------------
5041 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5042 Loc : constant Source_Ptr := Sloc (N);
5044 T : constant Entity_Id := Defining_Identifier (N);
5045 D_T : constant Entity_Id := Designated_Type (T);
5046 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5047 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5048 P_List : constant List_Id := Build_Protected_Spec
5049 (N, RTE (RE_Address), D_T, False);
5055 -- Create access to subprogram with full signature
5057 if Etype (D_T) /= Standard_Void_Type then
5059 Make_Access_Function_Definition (Loc,
5060 Parameter_Specifications => P_List,
5061 Result_Definition =>
5062 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5066 Make_Access_Procedure_Definition (Loc,
5067 Parameter_Specifications => P_List);
5071 Make_Full_Type_Declaration (Loc,
5072 Defining_Identifier => D_T2,
5073 Type_Definition => Def1);
5075 Insert_After (N, Decl1);
5078 -- Create Equivalent_Type, a record with two components for an access to
5079 -- object and an access to subprogram.
5082 Make_Component_Declaration (Loc,
5083 Defining_Identifier => Make_Temporary (Loc, 'P'),
5084 Component_Definition =>
5085 Make_Component_Definition (Loc,
5086 Aliased_Present => False,
5087 Subtype_Indication =>
5088 New_Occurrence_Of (RTE (RE_Address), Loc))),
5090 Make_Component_Declaration (Loc,
5091 Defining_Identifier => Make_Temporary (Loc, 'S'),
5092 Component_Definition =>
5093 Make_Component_Definition (Loc,
5094 Aliased_Present => False,
5095 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5098 Make_Full_Type_Declaration (Loc,
5099 Defining_Identifier => E_T,
5101 Make_Record_Definition (Loc,
5103 Make_Component_List (Loc,
5104 Component_Items => Comps)));
5106 Insert_After (Decl1, Decl2);
5108 Set_Equivalent_Type (T, E_T);
5109 end Expand_Access_Protected_Subprogram_Type;
5111 --------------------------
5112 -- Expand_Entry_Barrier --
5113 --------------------------
5115 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5116 Cond : constant Node_Id :=
5117 Condition (Entry_Body_Formal_Part (N));
5118 Prot : constant Entity_Id := Scope (Ent);
5119 Spec_Decl : constant Node_Id := Parent (Prot);
5122 Body_Decl : Node_Id;
5125 if No_Run_Time_Mode then
5126 Error_Msg_CRT ("entry barrier", N);
5130 -- The body of the entry barrier must be analyzed in the context of the
5131 -- protected object, but its scope is external to it, just as any other
5132 -- unprotected version of a protected operation. The specification has
5133 -- been produced when the protected type declaration was elaborated. We
5134 -- build the body, insert it in the enclosing scope, but analyze it in
5135 -- the current context. A more uniform approach would be to treat the
5136 -- barrier just as a protected function, and discard the protected
5137 -- version of it because it is never called.
5139 if Expander_Active then
5140 B_F := Build_Barrier_Function (N, Ent, Prot);
5141 Func := Barrier_Function (Ent);
5142 Set_Corresponding_Spec (B_F, Func);
5144 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5146 if Nkind (Parent (Body_Decl)) = N_Subunit then
5147 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5150 Insert_Before_And_Analyze (Body_Decl, B_F);
5152 Set_Discriminals (Spec_Decl);
5153 Set_Scope (Func, Scope (Prot));
5156 Analyze_And_Resolve (Cond, Any_Boolean);
5159 -- The Ravenscar profile restricts barriers to simple variables declared
5160 -- within the protected object. We also allow Boolean constants, since
5161 -- these appear in several published examples and are also allowed by
5162 -- the Aonix compiler.
5164 -- Note that after analysis variables in this context will be replaced
5165 -- by the corresponding prival, that is to say a renaming of a selected
5166 -- component of the form _Object.Var. If expansion is disabled, as
5167 -- within a generic, we check that the entity appears in the current
5170 if Is_Entity_Name (Cond) then
5172 -- A small optimization of useless renamings. If the scope of the
5173 -- entity of the condition is not the barrier function, then the
5174 -- condition does not reference any of the generated renamings
5175 -- within the function.
5178 and then Scope (Entity (Cond)) /= Func
5180 Set_Declarations (B_F, Empty_List);
5183 if Entity (Cond) = Standard_False
5185 Entity (Cond) = Standard_True
5189 elsif not Expander_Active
5190 and then Scope (Entity (Cond)) = Current_Scope
5194 -- Check for case of _object.all.field (note that the explicit
5195 -- dereference gets inserted by analyze/expand of _object.field)
5197 elsif Present (Renamed_Object (Entity (Cond)))
5199 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5203 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5209 -- It is not a boolean variable or literal, so check the restriction
5211 Check_Restriction (Simple_Barriers, Cond);
5212 end Expand_Entry_Barrier;
5214 ------------------------------
5215 -- Expand_N_Abort_Statement --
5216 ------------------------------
5218 -- Expand abort T1, T2, .. Tn; into:
5219 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5221 procedure Expand_N_Abort_Statement (N : Node_Id) is
5222 Loc : constant Source_Ptr := Sloc (N);
5223 Tlist : constant List_Id := Names (N);
5229 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5232 Tasknm := First (Tlist);
5234 while Present (Tasknm) loop
5237 -- A task interface class-wide type object is being aborted.
5238 -- Retrieve its _task_id by calling a dispatching routine.
5240 if Ada_Version >= Ada_2005
5241 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5242 and then Is_Interface (Etype (Tasknm))
5243 and then Is_Task_Interface (Etype (Tasknm))
5245 Append_To (Component_Associations (Aggr),
5246 Make_Component_Association (Loc,
5247 Choices => New_List (
5248 Make_Integer_Literal (Loc, Count)),
5251 -- Task_Id (Tasknm._disp_get_task_id)
5253 Make_Unchecked_Type_Conversion (Loc,
5255 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5257 Make_Selected_Component (Loc,
5259 New_Copy_Tree (Tasknm),
5261 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5264 Append_To (Component_Associations (Aggr),
5265 Make_Component_Association (Loc,
5266 Choices => New_List (
5267 Make_Integer_Literal (Loc, Count)),
5268 Expression => Concurrent_Ref (Tasknm)));
5275 Make_Procedure_Call_Statement (Loc,
5276 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5277 Parameter_Associations => New_List (
5278 Make_Qualified_Expression (Loc,
5279 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5280 Expression => Aggr))));
5283 end Expand_N_Abort_Statement;
5285 -------------------------------
5286 -- Expand_N_Accept_Statement --
5287 -------------------------------
5289 -- This procedure handles expansion of accept statements that stand
5290 -- alone, i.e. they are not part of an accept alternative. The expansion
5291 -- of accept statement in accept alternatives is handled by the routines
5292 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5293 -- following description applies only to stand alone accept statements.
5295 -- If there is no handled statement sequence, or only null statements,
5296 -- then this is called a trivial accept, and the expansion is:
5298 -- Accept_Trivial (entry-index)
5300 -- If there is a handled statement sequence, then the expansion is:
5307 -- Accept_Call (entry-index, Ann);
5308 -- Renaming_Declarations for formals
5309 -- <statement sequence from N_Accept_Statement node>
5310 -- Complete_Rendezvous;
5315 -- <exception handler from N_Accept_Statement node>
5316 -- Complete_Rendezvous;
5318 -- <exception handler from N_Accept_Statement node>
5319 -- Complete_Rendezvous;
5324 -- when all others =>
5325 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5328 -- The first three declarations were already inserted ahead of the accept
5329 -- statement by the Expand_Accept_Declarations procedure, which was called
5330 -- directly from the semantics during analysis of the accept statement,
5331 -- before analyzing its contained statements.
5333 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5334 -- from possible expansion activity (the original source of course does
5335 -- not have any declarations associated with the accept statement, since
5336 -- an accept statement has no declarative part). In particular, if the
5337 -- expander is active, the first such declaration is the declaration of
5338 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5340 -- The two blocks are merged into a single block if the inner block has
5341 -- no exception handlers, but otherwise two blocks are required, since
5342 -- exceptions might be raised in the exception handlers of the inner
5343 -- block, and Exceptional_Complete_Rendezvous must be called.
5345 procedure Expand_N_Accept_Statement (N : Node_Id) is
5346 Loc : constant Source_Ptr := Sloc (N);
5347 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5348 Ename : constant Node_Id := Entry_Direct_Name (N);
5349 Eindx : constant Node_Id := Entry_Index (N);
5350 Eent : constant Entity_Id := Entity (Ename);
5351 Acstack : constant Elist_Id := Accept_Address (Eent);
5352 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5353 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5358 -- Start of processing for Expand_N_Accept_Statement
5361 -- If accept statement is not part of a list, then its parent must be
5362 -- an accept alternative, and, as described above, we do not do any
5363 -- expansion for such accept statements at this level.
5365 if not Is_List_Member (N) then
5366 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5369 -- Trivial accept case (no statement sequence, or null statements).
5370 -- If the accept statement has declarations, then just insert them
5371 -- before the procedure call.
5373 elsif Trivial_Accept_OK
5374 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5376 -- Remove declarations for renamings, because the parameter block
5377 -- will not be assigned.
5384 D := First (Declarations (N));
5386 while Present (D) loop
5388 if Nkind (D) = N_Object_Renaming_Declaration then
5396 if Present (Declarations (N)) then
5397 Insert_Actions (N, Declarations (N));
5401 Make_Procedure_Call_Statement (Loc,
5402 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5403 Parameter_Associations => New_List (
5404 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5408 -- Discard Entry_Address that was created for it, so it will not be
5409 -- emitted if this accept statement is in the statement part of a
5410 -- delay alternative.
5412 if Present (Stats) then
5413 Remove_Last_Elmt (Acstack);
5416 -- Case of statement sequence present
5419 -- Construct the block, using the declarations from the accept
5420 -- statement if any to initialize the declarations of the block.
5422 Blkent := Make_Temporary (Loc, 'A');
5423 Set_Ekind (Blkent, E_Block);
5424 Set_Etype (Blkent, Standard_Void_Type);
5425 Set_Scope (Blkent, Current_Scope);
5428 Make_Block_Statement (Loc,
5429 Identifier => New_Reference_To (Blkent, Loc),
5430 Declarations => Declarations (N),
5431 Handled_Statement_Sequence => Build_Accept_Body (N));
5433 -- For the analysis of the generated declarations, the parent node
5434 -- must be properly set.
5436 Set_Parent (Block, Parent (N));
5438 -- Prepend call to Accept_Call to main statement sequence If the
5439 -- accept has exception handlers, the statement sequence is wrapped
5440 -- in a block. Insert call and renaming declarations in the
5441 -- declarations of the block, so they are elaborated before the
5445 Make_Procedure_Call_Statement (Loc,
5446 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5447 Parameter_Associations => New_List (
5448 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5449 New_Reference_To (Ann, Loc)));
5451 if Parent (Stats) = N then
5452 Prepend (Call, Statements (Stats));
5461 Push_Scope (Blkent);
5469 D := First (Declarations (N));
5470 while Present (D) loop
5473 if Nkind (D) = N_Object_Renaming_Declaration then
5475 -- The renaming declarations for the formals were created
5476 -- during analysis of the accept statement, and attached to
5477 -- the list of declarations. Place them now in the context
5478 -- of the accept block or subprogram.
5481 Typ := Entity (Subtype_Mark (D));
5482 Insert_After (Call, D);
5485 -- If the formal is class_wide, it does not have an actual
5486 -- subtype. The analysis of the renaming declaration creates
5487 -- one, but we need to retain the class-wide nature of the
5490 if Is_Class_Wide_Type (Typ) then
5491 Set_Etype (Defining_Identifier (D), Typ);
5502 -- Replace the accept statement by the new block
5507 -- Last step is to unstack the Accept_Address value
5509 Remove_Last_Elmt (Acstack);
5511 end Expand_N_Accept_Statement;
5513 ----------------------------------
5514 -- Expand_N_Asynchronous_Select --
5515 ----------------------------------
5517 -- This procedure assumes that the trigger statement is an entry call or
5518 -- a dispatching procedure call. A delay alternative should already have
5519 -- been expanded into an entry call to the appropriate delay object Wait
5522 -- If the trigger is a task entry call, the select is implemented with
5523 -- a Task_Entry_Call:
5528 -- P : parms := (parm, parm, parm);
5530 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5532 -- procedure _clean is
5535 -- Cancel_Task_Entry_Call (C);
5542 -- (<acceptor-task>, -- Acceptor
5543 -- <entry-index>, -- E
5544 -- P'Address, -- Uninterpreted_Data
5545 -- Asynchronous_Call, -- Mode
5546 -- B); -- Rendezvous_Successful
5553 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5556 -- when Abort_Signal => Abort_Undefer;
5563 -- <triggered-statements>
5567 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5568 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5572 -- P : parms := (parm, parm, parm);
5574 -- Call_Simple (acceptor-task, entry-index, P'Address);
5580 -- so the task at hand is to convert the latter expansion into the former
5582 -- If the trigger is a protected entry call, the select is implemented
5583 -- with Protected_Entry_Call:
5586 -- P : E1_Params := (param, param, param);
5587 -- Bnn : Communications_Block;
5592 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5594 -- procedure _clean is
5597 -- if Enqueued (Bnn) then
5598 -- Cancel_Protected_Entry_Call (Bnn);
5605 -- Protected_Entry_Call
5606 -- (po._object'Access, -- Object
5607 -- <entry index>, -- E
5608 -- P'Address, -- Uninterpreted_Data
5609 -- Asynchronous_Call, -- Mode
5612 -- if Enqueued (Bnn) then
5616 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5619 -- when Abort_Signal => Abort_Undefer;
5622 -- if not Cancelled (Bnn) then
5623 -- <triggered-statements>
5627 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5631 -- P : E1_Params := (param, param, param);
5632 -- Bnn : Communications_Block;
5635 -- Protected_Entry_Call
5636 -- (po._object'Access, -- Object
5637 -- <entry index>, -- E
5638 -- P'Address, -- Uninterpreted_Data
5639 -- Simple_Call, -- Mode
5646 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5650 -- B : Boolean := False;
5651 -- Bnn : Communication_Block;
5652 -- C : Ada.Tags.Prim_Op_Kind;
5653 -- D : System.Storage_Elements.Dummy_Communication_Block;
5654 -- K : Ada.Tags.Tagged_Kind :=
5655 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5656 -- P : Parameters := (Param1 .. ParamN);
5661 -- if K = Ada.Tags.TK_Limited_Tagged then
5662 -- <dispatching-call>;
5663 -- <triggering-statements>;
5667 -- Ada.Tags.Get_Offset_Index
5668 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5670 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5672 -- if C = POK_Protected_Entry then
5674 -- procedure _clean is
5676 -- if Enqueued (Bnn) then
5677 -- Cancel_Protected_Entry_Call (Bnn);
5683 -- _Disp_Asynchronous_Select
5684 -- (<object>, S, P'Address, D, B);
5685 -- Bnn := Communication_Block (D);
5687 -- Param1 := P.Param1;
5689 -- ParamN := P.ParamN;
5691 -- if Enqueued (Bnn) then
5692 -- <abortable-statements>
5695 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5698 -- when Abort_Signal => Abort_Undefer;
5701 -- if not Cancelled (Bnn) then
5702 -- <triggering-statements>
5705 -- elsif C = POK_Task_Entry then
5707 -- procedure _clean is
5709 -- Cancel_Task_Entry_Call (U);
5715 -- _Disp_Asynchronous_Select
5716 -- (<object>, S, P'Address, D, B);
5717 -- Bnn := Communication_Bloc (D);
5719 -- Param1 := P.Param1;
5721 -- ParamN := P.ParamN;
5726 -- <abortable-statements>
5728 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5731 -- when Abort_Signal => Abort_Undefer;
5735 -- <triggering-statements>
5740 -- <dispatching-call>;
5741 -- <triggering-statements>
5746 -- The job is to convert this to the asynchronous form
5748 -- If the trigger is a delay statement, it will have been expanded into a
5749 -- call to one of the GNARL delay procedures. This routine will convert
5750 -- this into a protected entry call on a delay object and then continue
5751 -- processing as for a protected entry call trigger. This requires
5752 -- declaring a Delay_Block object and adding a pointer to this object to
5753 -- the parameter list of the delay procedure to form the parameter list of
5754 -- the entry call. This object is used by the runtime to queue the delay
5757 -- For a description of the use of P and the assignments after the call,
5758 -- see Expand_N_Entry_Call_Statement.
5760 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5761 Loc : constant Source_Ptr := Sloc (N);
5762 Abrt : constant Node_Id := Abortable_Part (N);
5763 Astats : constant List_Id := Statements (Abrt);
5764 Trig : constant Node_Id := Triggering_Alternative (N);
5765 Tstats : constant List_Id := Statements (Trig);
5767 Abort_Block_Ent : Entity_Id;
5768 Abortable_Block : Node_Id;
5770 Blk_Ent : Entity_Id;
5771 Blk_Typ : Entity_Id;
5773 Call_Ent : Entity_Id;
5774 Cancel_Param : Entity_Id;
5775 Cleanup_Block : Node_Id;
5776 Cleanup_Block_Ent : Entity_Id;
5777 Cleanup_Stmts : List_Id;
5778 Conc_Typ_Stmts : List_Id;
5780 Dblock_Ent : Entity_Id;
5785 Enqueue_Call : Node_Id;
5789 Lim_Typ_Stmts : List_Id;
5795 ProtE_Stmts : List_Id;
5796 ProtP_Stmts : List_Id;
5799 Target_Undefer : RE_Id;
5800 TaskE_Stmts : List_Id;
5801 Undefer_Args : List_Id := No_List;
5803 B : Entity_Id; -- Call status flag
5804 Bnn : Entity_Id; -- Communication block
5805 C : Entity_Id; -- Call kind
5806 K : Entity_Id; -- Tagged kind
5807 P : Entity_Id; -- Parameter block
5808 S : Entity_Id; -- Primitive operation slot
5809 T : Entity_Id; -- Additional status flag
5812 Blk_Ent := Make_Temporary (Loc, 'A');
5813 Ecall := Triggering_Statement (Trig);
5815 -- The arguments in the call may require dynamic allocation, and the
5816 -- call statement may have been transformed into a block. The block
5817 -- may contain additional declarations for internal entities, and the
5818 -- original call is found by sequential search.
5820 if Nkind (Ecall) = N_Block_Statement then
5821 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5822 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5823 N_Entry_Call_Statement)
5829 -- This is either a dispatching call or a delay statement used as a
5830 -- trigger which was expanded into a procedure call.
5832 if Nkind (Ecall) = N_Procedure_Call_Statement then
5833 if Ada_Version >= Ada_2005
5835 (No (Original_Node (Ecall))
5836 or else not Nkind_In (Original_Node (Ecall),
5837 N_Delay_Relative_Statement,
5838 N_Delay_Until_Statement))
5840 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5845 -- Call status flag processing, generate:
5846 -- B : Boolean := False;
5848 B := Build_B (Loc, Decls);
5850 -- Communication block processing, generate:
5851 -- Bnn : Communication_Block;
5853 Bnn := Make_Temporary (Loc, 'B');
5855 Make_Object_Declaration (Loc,
5856 Defining_Identifier => Bnn,
5857 Object_Definition =>
5858 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5860 -- Call kind processing, generate:
5861 -- C : Ada.Tags.Prim_Op_Kind;
5863 C := Build_C (Loc, Decls);
5865 -- Tagged kind processing, generate:
5866 -- K : Ada.Tags.Tagged_Kind :=
5867 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5869 -- Dummy communication block, generate:
5870 -- D : Dummy_Communication_Block;
5873 Make_Object_Declaration (Loc,
5874 Defining_Identifier =>
5875 Make_Defining_Identifier (Loc, Name_uD),
5876 Object_Definition =>
5878 RTE (RE_Dummy_Communication_Block), Loc)));
5880 K := Build_K (Loc, Decls, Obj);
5882 -- Parameter block processing
5884 Blk_Typ := Build_Parameter_Block
5885 (Loc, Actuals, Formals, Decls);
5886 P := Parameter_Block_Pack
5887 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5889 -- Dispatch table slot processing, generate:
5892 S := Build_S (Loc, Decls);
5894 -- Additional status flag processing, generate:
5897 T := Make_Temporary (Loc, 'T');
5899 Make_Object_Declaration (Loc,
5900 Defining_Identifier => T,
5901 Object_Definition =>
5902 New_Reference_To (Standard_Boolean, Loc)));
5904 ------------------------------
5905 -- Protected entry handling --
5906 ------------------------------
5909 -- Param1 := P.Param1;
5911 -- ParamN := P.ParamN;
5913 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5916 -- Bnn := Communication_Block (D);
5918 Prepend_To (Cleanup_Stmts,
5919 Make_Assignment_Statement (Loc,
5921 New_Reference_To (Bnn, Loc),
5923 Make_Unchecked_Type_Conversion (Loc,
5925 New_Reference_To (RTE (RE_Communication_Block), Loc),
5927 Make_Identifier (Loc, Name_uD))));
5930 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5932 Prepend_To (Cleanup_Stmts,
5933 Make_Procedure_Call_Statement (Loc,
5936 Find_Prim_Op (Etype (Etype (Obj)),
5937 Name_uDisp_Asynchronous_Select),
5939 Parameter_Associations =>
5941 New_Copy_Tree (Obj), -- <object>
5942 New_Reference_To (S, Loc), -- S
5943 Make_Attribute_Reference (Loc, -- P'Address
5945 New_Reference_To (P, Loc),
5948 Make_Identifier (Loc, Name_uD), -- D
5949 New_Reference_To (B, Loc)))); -- B
5952 -- if Enqueued (Bnn) then
5953 -- <abortable-statements>
5956 Append_To (Cleanup_Stmts,
5957 Make_If_Statement (Loc,
5959 Make_Function_Call (Loc,
5961 New_Reference_To (RTE (RE_Enqueued), Loc),
5962 Parameter_Associations =>
5964 New_Reference_To (Bnn, Loc))),
5967 New_Copy_List_Tree (Astats)));
5969 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5970 -- will then generate a _clean for the communication block Bnn.
5974 -- procedure _clean is
5976 -- if Enqueued (Bnn) then
5977 -- Cancel_Protected_Entry_Call (Bnn);
5986 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
5988 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5990 -- Wrap the cleanup block in an exception handling block
5996 -- when Abort_Signal => Abort_Undefer;
5999 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6002 Make_Implicit_Label_Declaration (Loc,
6003 Defining_Identifier =>
6007 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6010 -- if not Cancelled (Bnn) then
6011 -- <triggering-statements>
6014 Append_To (ProtE_Stmts,
6015 Make_If_Statement (Loc,
6019 Make_Function_Call (Loc,
6021 New_Reference_To (RTE (RE_Cancelled), Loc),
6022 Parameter_Associations =>
6024 New_Reference_To (Bnn, Loc)))),
6027 New_Copy_List_Tree (Tstats)));
6029 -------------------------
6030 -- Task entry handling --
6031 -------------------------
6034 -- Param1 := P.Param1;
6036 -- ParamN := P.ParamN;
6038 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6041 -- Bnn := Communication_Block (D);
6043 Append_To (TaskE_Stmts,
6044 Make_Assignment_Statement (Loc,
6046 New_Reference_To (Bnn, Loc),
6048 Make_Unchecked_Type_Conversion (Loc,
6050 New_Reference_To (RTE (RE_Communication_Block), Loc),
6052 Make_Identifier (Loc, Name_uD))));
6055 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6057 Prepend_To (TaskE_Stmts,
6058 Make_Procedure_Call_Statement (Loc,
6061 Find_Prim_Op (Etype (Etype (Obj)),
6062 Name_uDisp_Asynchronous_Select),
6064 Parameter_Associations =>
6066 New_Copy_Tree (Obj), -- <object>
6067 New_Reference_To (S, Loc), -- S
6068 Make_Attribute_Reference (Loc, -- P'Address
6070 New_Reference_To (P, Loc),
6073 Make_Identifier (Loc, Name_uD), -- D
6074 New_Reference_To (B, Loc)))); -- B
6079 Prepend_To (TaskE_Stmts,
6080 Make_Procedure_Call_Statement (Loc,
6082 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6083 Parameter_Associations =>
6088 -- <abortable-statements>
6090 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6092 Prepend_To (Cleanup_Stmts,
6093 Make_Procedure_Call_Statement (Loc,
6095 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6096 Parameter_Associations =>
6099 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6100 -- will generate a _clean for the additional status flag.
6104 -- procedure _clean is
6106 -- Cancel_Task_Entry_Call (U);
6114 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6116 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6118 -- Wrap the cleanup block in an exception handling block
6124 -- when Abort_Signal => Abort_Undefer;
6127 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6129 Append_To (TaskE_Stmts,
6130 Make_Implicit_Label_Declaration (Loc,
6131 Defining_Identifier => Abort_Block_Ent));
6133 Append_To (TaskE_Stmts,
6135 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6139 -- <triggering-statements>
6142 Append_To (TaskE_Stmts,
6143 Make_If_Statement (Loc,
6147 New_Reference_To (T, Loc)),
6150 New_Copy_List_Tree (Tstats)));
6152 ----------------------------------
6153 -- Protected procedure handling --
6154 ----------------------------------
6157 -- <dispatching-call>;
6158 -- <triggering-statements>
6160 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6161 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6164 -- S := Ada.Tags.Get_Offset_Index
6165 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6168 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6171 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6173 Append_To (Conc_Typ_Stmts,
6174 Make_Procedure_Call_Statement (Loc,
6177 Find_Prim_Op (Etype (Etype (Obj)),
6178 Name_uDisp_Get_Prim_Op_Kind),
6180 Parameter_Associations =>
6182 New_Copy_Tree (Obj),
6183 New_Reference_To (S, Loc),
6184 New_Reference_To (C, Loc))));
6187 -- if C = POK_Procedure_Entry then
6189 -- elsif C = POK_Task_Entry then
6195 Append_To (Conc_Typ_Stmts,
6196 Make_If_Statement (Loc,
6200 New_Reference_To (C, Loc),
6202 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6209 Make_Elsif_Part (Loc,
6213 New_Reference_To (C, Loc),
6215 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6224 -- <dispatching-call>;
6225 -- <triggering-statements>
6227 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6228 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6231 -- if K = Ada.Tags.TK_Limited_Tagged then
6238 Make_If_Statement (Loc,
6242 New_Reference_To (K, Loc),
6244 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6253 Make_Block_Statement (Loc,
6256 Handled_Statement_Sequence =>
6257 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6262 -- Delay triggering statement processing
6265 -- Add a Delay_Block object to the parameter list of the delay
6266 -- procedure to form the parameter list of the Wait entry call.
6268 Dblock_Ent := Make_Temporary (Loc, 'D');
6270 Pdef := Entity (Name (Ecall));
6272 if Is_RTE (Pdef, RO_CA_Delay_For) then
6274 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6276 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6278 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6280 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6281 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6284 Append_To (Parameter_Associations (Ecall),
6285 Make_Attribute_Reference (Loc,
6286 Prefix => New_Reference_To (Dblock_Ent, Loc),
6287 Attribute_Name => Name_Unchecked_Access));
6289 -- Create the inner block to protect the abortable part
6292 Make_Implicit_Exception_Handler (Loc,
6293 Exception_Choices =>
6294 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6295 Statements => New_List (
6296 Make_Procedure_Call_Statement (Loc,
6297 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6300 Make_Procedure_Call_Statement (Loc,
6301 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6304 Make_Block_Statement (Loc,
6305 Identifier => New_Reference_To (Blk_Ent, Loc),
6306 Handled_Statement_Sequence =>
6307 Make_Handled_Sequence_Of_Statements (Loc,
6308 Statements => Astats),
6309 Has_Created_Identifier => True,
6310 Is_Asynchronous_Call_Block => True);
6312 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6315 Make_Implicit_If_Statement (N,
6316 Condition => Make_Function_Call (Loc,
6317 Name => Enqueue_Call,
6318 Parameter_Associations => Parameter_Associations (Ecall)),
6320 New_List (Make_Block_Statement (Loc,
6321 Handled_Statement_Sequence =>
6322 Make_Handled_Sequence_Of_Statements (Loc,
6323 Statements => New_List (
6324 Make_Implicit_Label_Declaration (Loc,
6325 Defining_Identifier => Blk_Ent,
6326 Label_Construct => Abortable_Block),
6328 Exception_Handlers => Hdle)))));
6330 Stmts := New_List (Ecall);
6332 -- Construct statement sequence for new block
6335 Make_Implicit_If_Statement (N,
6336 Condition => Make_Function_Call (Loc,
6337 Name => New_Reference_To (
6338 RTE (RE_Timed_Out), Loc),
6339 Parameter_Associations => New_List (
6340 Make_Attribute_Reference (Loc,
6341 Prefix => New_Reference_To (Dblock_Ent, Loc),
6342 Attribute_Name => Name_Unchecked_Access))),
6343 Then_Statements => Tstats));
6345 -- The result is the new block
6347 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6350 Make_Block_Statement (Loc,
6351 Declarations => New_List (
6352 Make_Object_Declaration (Loc,
6353 Defining_Identifier => Dblock_Ent,
6354 Aliased_Present => True,
6355 Object_Definition => New_Reference_To (
6356 RTE (RE_Delay_Block), Loc))),
6358 Handled_Statement_Sequence =>
6359 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6369 Extract_Entry (Ecall, Concval, Ename, Index);
6370 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6372 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6373 Decls := Declarations (Ecall);
6375 if Is_Protected_Type (Etype (Concval)) then
6377 -- Get the declarations of the block expanded from the entry call
6379 Decl := First (Decls);
6380 while Present (Decl)
6382 (Nkind (Decl) /= N_Object_Declaration
6383 or else not Is_RTE (Etype (Object_Definition (Decl)),
6384 RE_Communication_Block))
6389 pragma Assert (Present (Decl));
6390 Cancel_Param := Defining_Identifier (Decl);
6392 -- Change the mode of the Protected_Entry_Call call
6394 -- Protected_Entry_Call (
6395 -- Object => po._object'Access,
6396 -- E => <entry index>;
6397 -- Uninterpreted_Data => P'Address;
6398 -- Mode => Asynchronous_Call;
6401 Stmt := First (Stmts);
6403 -- Skip assignments to temporaries created for in-out parameters
6405 -- This makes unwarranted assumptions about the shape of the expanded
6406 -- tree for the call, and should be cleaned up ???
6408 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6414 Param := First (Parameter_Associations (Call));
6415 while Present (Param)
6416 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6421 pragma Assert (Present (Param));
6422 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6425 -- Append an if statement to execute the abortable part
6428 -- if Enqueued (Bnn) then
6431 Make_Implicit_If_Statement (N,
6432 Condition => Make_Function_Call (Loc,
6433 Name => New_Reference_To (
6434 RTE (RE_Enqueued), Loc),
6435 Parameter_Associations => New_List (
6436 New_Reference_To (Cancel_Param, Loc))),
6437 Then_Statements => Astats));
6440 Make_Block_Statement (Loc,
6441 Identifier => New_Reference_To (Blk_Ent, Loc),
6442 Handled_Statement_Sequence =>
6443 Make_Handled_Sequence_Of_Statements (Loc,
6444 Statements => Stmts),
6445 Has_Created_Identifier => True,
6446 Is_Asynchronous_Call_Block => True);
6448 -- For the VM call Update_Exception instead of Abort_Undefer.
6449 -- See 4jexcept.ads for an explanation.
6451 if VM_Target = No_VM then
6452 Target_Undefer := RE_Abort_Undefer;
6454 Target_Undefer := RE_Update_Exception;
6456 New_List (Make_Function_Call (Loc,
6457 Name => New_Occurrence_Of
6458 (RTE (RE_Current_Target_Exception), Loc)));
6462 Make_Block_Statement (Loc,
6463 Handled_Statement_Sequence =>
6464 Make_Handled_Sequence_Of_Statements (Loc,
6465 Statements => New_List (
6466 Make_Implicit_Label_Declaration (Loc,
6467 Defining_Identifier => Blk_Ent,
6468 Label_Construct => Abortable_Block),
6473 Exception_Handlers => New_List (
6474 Make_Implicit_Exception_Handler (Loc,
6476 -- when Abort_Signal =>
6477 -- Abort_Undefer.all;
6479 Exception_Choices =>
6480 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6481 Statements => New_List (
6482 Make_Procedure_Call_Statement (Loc,
6483 Name => New_Reference_To (
6484 RTE (Target_Undefer), Loc),
6485 Parameter_Associations => Undefer_Args)))))),
6487 -- if not Cancelled (Bnn) then
6488 -- triggered statements
6491 Make_Implicit_If_Statement (N,
6492 Condition => Make_Op_Not (Loc,
6494 Make_Function_Call (Loc,
6495 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6496 Parameter_Associations => New_List (
6497 New_Occurrence_Of (Cancel_Param, Loc)))),
6498 Then_Statements => Tstats));
6500 -- Asynchronous task entry call
6507 B := Make_Defining_Identifier (Loc, Name_uB);
6509 -- Insert declaration of B in declarations of existing block
6512 Make_Object_Declaration (Loc,
6513 Defining_Identifier => B,
6514 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6516 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6518 -- Insert declaration of C in declarations of existing block
6521 Make_Object_Declaration (Loc,
6522 Defining_Identifier => Cancel_Param,
6523 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6525 -- Remove and save the call to Call_Simple
6527 Stmt := First (Stmts);
6529 -- Skip assignments to temporaries created for in-out parameters.
6530 -- This makes unwarranted assumptions about the shape of the expanded
6531 -- tree for the call, and should be cleaned up ???
6533 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6539 -- Create the inner block to protect the abortable part
6542 Make_Implicit_Exception_Handler (Loc,
6543 Exception_Choices =>
6544 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6547 Make_Procedure_Call_Statement (Loc,
6548 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6551 Make_Procedure_Call_Statement (Loc,
6552 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6555 Make_Block_Statement (Loc,
6556 Identifier => New_Reference_To (Blk_Ent, Loc),
6557 Handled_Statement_Sequence =>
6558 Make_Handled_Sequence_Of_Statements (Loc,
6559 Statements => Astats),
6560 Has_Created_Identifier => True,
6561 Is_Asynchronous_Call_Block => True);
6564 Make_Block_Statement (Loc,
6565 Handled_Statement_Sequence =>
6566 Make_Handled_Sequence_Of_Statements (Loc,
6567 Statements => New_List (
6568 Make_Implicit_Label_Declaration (Loc,
6569 Defining_Identifier =>
6574 Exception_Handlers => Hdle)));
6576 -- Create new call statement
6578 Params := Parameter_Associations (Call);
6581 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6583 New_Reference_To (B, Loc));
6586 Make_Procedure_Call_Statement (Loc,
6588 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6589 Parameter_Associations => Params));
6591 -- Construct statement sequence for new block
6594 Make_Implicit_If_Statement (N,
6597 New_Reference_To (Cancel_Param, Loc)),
6598 Then_Statements => Tstats));
6600 -- Protected the call against abort
6603 Make_Procedure_Call_Statement (Loc,
6604 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6605 Parameter_Associations => Empty_List));
6608 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6610 -- The result is the new block
6613 Make_Block_Statement (Loc,
6614 Declarations => Decls,
6615 Handled_Statement_Sequence =>
6616 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6619 end Expand_N_Asynchronous_Select;
6621 -------------------------------------
6622 -- Expand_N_Conditional_Entry_Call --
6623 -------------------------------------
6625 -- The conditional task entry call is converted to a call to
6630 -- P : parms := (parm, parm, parm);
6634 -- (<acceptor-task>, -- Acceptor
6635 -- <entry-index>, -- E
6636 -- P'Address, -- Uninterpreted_Data
6637 -- Conditional_Call, -- Mode
6638 -- B); -- Rendezvous_Successful
6643 -- normal-statements
6649 -- For a description of the use of P and the assignments after the call,
6650 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6651 -- conditional entry call has already been expanded (by the Expand_N_Entry
6652 -- _Call_Statement procedure) as follows:
6655 -- P : parms := (parm, parm, parm);
6657 -- ... info for in-out parameters
6658 -- Call_Simple (acceptor-task, entry-index, P'Address);
6664 -- so the task at hand is to convert the latter expansion into the former
6666 -- The conditional protected entry call is converted to a call to
6667 -- Protected_Entry_Call:
6670 -- P : parms := (parm, parm, parm);
6671 -- Bnn : Communications_Block;
6674 -- Protected_Entry_Call
6675 -- (po._object'Access, -- Object
6676 -- <entry index>, -- E
6677 -- P'Address, -- Uninterpreted_Data
6678 -- Conditional_Call, -- Mode
6683 -- if Cancelled (Bnn) then
6686 -- normal-statements
6690 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6694 -- B : Boolean := False;
6695 -- C : Ada.Tags.Prim_Op_Kind;
6696 -- K : Ada.Tags.Tagged_Kind :=
6697 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6698 -- P : Parameters := (Param1 .. ParamN);
6702 -- if K = Ada.Tags.TK_Limited_Tagged then
6703 -- <dispatching-call>;
6704 -- <triggering-statements>
6708 -- Ada.Tags.Get_Offset_Index
6709 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6711 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6713 -- if C = POK_Protected_Entry
6714 -- or else C = POK_Task_Entry
6716 -- Param1 := P.Param1;
6718 -- ParamN := P.ParamN;
6722 -- if C = POK_Procedure
6723 -- or else C = POK_Protected_Procedure
6724 -- or else C = POK_Task_Procedure
6726 -- <dispatching-call>;
6729 -- <triggering-statements>
6731 -- <else-statements>
6736 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6737 Loc : constant Source_Ptr := Sloc (N);
6738 Alt : constant Node_Id := Entry_Call_Alternative (N);
6739 Blk : Node_Id := Entry_Call_Statement (Alt);
6742 Blk_Typ : Entity_Id;
6744 Call_Ent : Entity_Id;
6745 Conc_Typ_Stmts : List_Id;
6749 Lim_Typ_Stmts : List_Id;
6756 Transient_Blk : Node_Id;
6759 B : Entity_Id; -- Call status flag
6760 C : Entity_Id; -- Call kind
6761 K : Entity_Id; -- Tagged kind
6762 P : Entity_Id; -- Parameter block
6763 S : Entity_Id; -- Primitive operation slot
6766 if Ada_Version >= Ada_2005
6767 and then Nkind (Blk) = N_Procedure_Call_Statement
6769 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6774 -- Call status flag processing, generate:
6775 -- B : Boolean := False;
6777 B := Build_B (Loc, Decls);
6779 -- Call kind processing, generate:
6780 -- C : Ada.Tags.Prim_Op_Kind;
6782 C := Build_C (Loc, Decls);
6784 -- Tagged kind processing, generate:
6785 -- K : Ada.Tags.Tagged_Kind :=
6786 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6788 K := Build_K (Loc, Decls, Obj);
6790 -- Parameter block processing
6792 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6793 P := Parameter_Block_Pack
6794 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6796 -- Dispatch table slot processing, generate:
6799 S := Build_S (Loc, Decls);
6802 -- S := Ada.Tags.Get_Offset_Index
6803 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6806 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6809 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6811 Append_To (Conc_Typ_Stmts,
6812 Make_Procedure_Call_Statement (Loc,
6815 Find_Prim_Op (Etype (Etype (Obj)),
6816 Name_uDisp_Conditional_Select),
6818 Parameter_Associations =>
6820 New_Copy_Tree (Obj), -- <object>
6821 New_Reference_To (S, Loc), -- S
6822 Make_Attribute_Reference (Loc, -- P'Address
6824 New_Reference_To (P, Loc),
6827 New_Reference_To (C, Loc), -- C
6828 New_Reference_To (B, Loc)))); -- B
6831 -- if C = POK_Protected_Entry
6832 -- or else C = POK_Task_Entry
6834 -- Param1 := P.Param1;
6836 -- ParamN := P.ParamN;
6839 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6841 -- Generate the if statement only when the packed parameters need
6842 -- explicit assignments to their corresponding actuals.
6844 if Present (Unpack) then
6845 Append_To (Conc_Typ_Stmts,
6846 Make_If_Statement (Loc,
6853 New_Reference_To (C, Loc),
6855 New_Reference_To (RTE (
6856 RE_POK_Protected_Entry), Loc)),
6860 New_Reference_To (C, Loc),
6862 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6870 -- if C = POK_Procedure
6871 -- or else C = POK_Protected_Procedure
6872 -- or else C = POK_Task_Procedure
6874 -- <dispatching-call>
6876 -- <normal-statements>
6878 -- <else-statements>
6881 N_Stats := New_Copy_List_Tree (Statements (Alt));
6883 Prepend_To (N_Stats,
6884 Make_If_Statement (Loc,
6890 New_Reference_To (C, Loc),
6892 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6899 New_Reference_To (C, Loc),
6901 New_Reference_To (RTE (
6902 RE_POK_Protected_Procedure), Loc)),
6907 New_Reference_To (C, Loc),
6909 New_Reference_To (RTE (
6910 RE_POK_Task_Procedure), Loc)))),
6915 Append_To (Conc_Typ_Stmts,
6916 Make_If_Statement (Loc,
6917 Condition => New_Reference_To (B, Loc),
6918 Then_Statements => N_Stats,
6919 Else_Statements => Else_Statements (N)));
6922 -- <dispatching-call>;
6923 -- <triggering-statements>
6925 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6926 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6929 -- if K = Ada.Tags.TK_Limited_Tagged then
6936 Make_If_Statement (Loc,
6940 New_Reference_To (K, Loc),
6942 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6951 Make_Block_Statement (Loc,
6954 Handled_Statement_Sequence =>
6955 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6957 -- As described above, The entry alternative is transformed into a
6958 -- block that contains the gnulli call, and possibly assignment
6959 -- statements for in-out parameters. The gnulli call may itself be
6960 -- rewritten into a transient block if some unconstrained parameters
6961 -- require it. We need to retrieve the call to complete its parameter
6966 First_Real_Statement (Handled_Statement_Sequence (Blk));
6968 if Present (Transient_Blk)
6969 and then Nkind (Transient_Blk) = N_Block_Statement
6971 Blk := Transient_Blk;
6974 Stmts := Statements (Handled_Statement_Sequence (Blk));
6975 Stmt := First (Stmts);
6976 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6981 Params := Parameter_Associations (Call);
6983 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6985 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6987 Param := First (Params);
6988 while Present (Param)
6989 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6994 pragma Assert (Present (Param));
6995 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6999 -- Find the Communication_Block parameter for the call to the
7000 -- Cancelled function.
7002 Decl := First (Declarations (Blk));
7003 while Present (Decl)
7004 and then not Is_RTE (Etype (Object_Definition (Decl)),
7005 RE_Communication_Block)
7010 -- Add an if statement to execute the else part if the call
7011 -- does not succeed (as indicated by the Cancelled predicate).
7014 Make_Implicit_If_Statement (N,
7015 Condition => Make_Function_Call (Loc,
7016 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
7017 Parameter_Associations => New_List (
7018 New_Reference_To (Defining_Identifier (Decl), Loc))),
7019 Then_Statements => Else_Statements (N),
7020 Else_Statements => Statements (Alt)));
7023 B := Make_Defining_Identifier (Loc, Name_uB);
7025 -- Insert declaration of B in declarations of existing block
7027 if No (Declarations (Blk)) then
7028 Set_Declarations (Blk, New_List);
7031 Prepend_To (Declarations (Blk),
7032 Make_Object_Declaration (Loc,
7033 Defining_Identifier => B,
7034 Object_Definition =>
7035 New_Reference_To (Standard_Boolean, Loc)));
7037 -- Create new call statement
7040 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7041 Append_To (Params, New_Reference_To (B, Loc));
7044 Make_Procedure_Call_Statement (Loc,
7045 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7046 Parameter_Associations => Params));
7048 -- Construct statement sequence for new block
7051 Make_Implicit_If_Statement (N,
7052 Condition => New_Reference_To (B, Loc),
7053 Then_Statements => Statements (Alt),
7054 Else_Statements => Else_Statements (N)));
7057 -- The result is the new block
7060 Make_Block_Statement (Loc,
7061 Declarations => Declarations (Blk),
7062 Handled_Statement_Sequence =>
7063 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7067 end Expand_N_Conditional_Entry_Call;
7069 ---------------------------------------
7070 -- Expand_N_Delay_Relative_Statement --
7071 ---------------------------------------
7073 -- Delay statement is implemented as a procedure call to Delay_For
7074 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7075 -- simple delays imposed by the use of Protected Objects.
7077 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7078 Loc : constant Source_Ptr := Sloc (N);
7081 Make_Procedure_Call_Statement (Loc,
7082 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7083 Parameter_Associations => New_List (Expression (N))));
7085 end Expand_N_Delay_Relative_Statement;
7087 ------------------------------------
7088 -- Expand_N_Delay_Until_Statement --
7089 ------------------------------------
7091 -- Delay Until statement is implemented as a procedure call to
7092 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7094 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7095 Loc : constant Source_Ptr := Sloc (N);
7099 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7100 Typ := RTE (RO_CA_Delay_Until);
7102 Typ := RTE (RO_RT_Delay_Until);
7106 Make_Procedure_Call_Statement (Loc,
7107 Name => New_Reference_To (Typ, Loc),
7108 Parameter_Associations => New_List (Expression (N))));
7111 end Expand_N_Delay_Until_Statement;
7113 -------------------------
7114 -- Expand_N_Entry_Body --
7115 -------------------------
7117 procedure Expand_N_Entry_Body (N : Node_Id) is
7119 -- Associate discriminals with the next protected operation body to be
7122 if Present (Next_Protected_Operation (N)) then
7123 Set_Discriminals (Parent (Current_Scope));
7125 end Expand_N_Entry_Body;
7127 -----------------------------------
7128 -- Expand_N_Entry_Call_Statement --
7129 -----------------------------------
7131 -- An entry call is expanded into GNARLI calls to implement a simple entry
7132 -- call (see Build_Simple_Entry_Call).
7134 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7140 if No_Run_Time_Mode then
7141 Error_Msg_CRT ("entry call", N);
7145 -- If this entry call is part of an asynchronous select, don't expand it
7146 -- here; it will be expanded with the select statement. Don't expand
7147 -- timed entry calls either, as they are translated into asynchronous
7150 -- ??? This whole approach is questionable; it may be better to go back
7151 -- to allowing the expansion to take place and then attempting to fix it
7152 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7153 -- whether the expanded call is on a task or protected entry.
7155 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7156 or else N /= Triggering_Statement (Parent (N)))
7157 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7158 or else N /= Entry_Call_Statement (Parent (N))
7159 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7161 Extract_Entry (N, Concval, Ename, Index);
7162 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7164 end Expand_N_Entry_Call_Statement;
7166 --------------------------------
7167 -- Expand_N_Entry_Declaration --
7168 --------------------------------
7170 -- If there are parameters, then first, each of the formals is marked by
7171 -- setting Is_Entry_Formal. Next a record type is built which is used to
7172 -- hold the parameter values. The name of this record type is entryP where
7173 -- entry is the name of the entry, with an additional corresponding access
7174 -- type called entryPA. The record type has matching components for each
7175 -- formal (the component names are the same as the formal names). For
7176 -- elementary types, the component type matches the formal type. For
7177 -- composite types, an access type is declared (with the name formalA)
7178 -- which designates the formal type, and the type of the component is this
7179 -- access type. Finally the Entry_Component of each formal is set to
7180 -- reference the corresponding record component.
7182 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7183 Loc : constant Source_Ptr := Sloc (N);
7184 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7185 Components : List_Id;
7188 Last_Decl : Node_Id;
7189 Component : Entity_Id;
7192 Rec_Ent : Entity_Id;
7193 Acc_Ent : Entity_Id;
7196 Formal := First_Formal (Entry_Ent);
7199 -- Most processing is done only if parameters are present
7201 if Present (Formal) then
7202 Components := New_List;
7204 -- Loop through formals
7206 while Present (Formal) loop
7207 Set_Is_Entry_Formal (Formal);
7209 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7210 Set_Entry_Component (Formal, Component);
7211 Set_Entry_Formal (Component, Formal);
7212 Ftype := Etype (Formal);
7214 -- Declare new access type and then append
7216 Ctype := Make_Temporary (Loc, 'A');
7219 Make_Full_Type_Declaration (Loc,
7220 Defining_Identifier => Ctype,
7222 Make_Access_To_Object_Definition (Loc,
7223 All_Present => True,
7224 Constant_Present => Ekind (Formal) = E_In_Parameter,
7225 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7227 Insert_After (Last_Decl, Decl);
7230 Append_To (Components,
7231 Make_Component_Declaration (Loc,
7232 Defining_Identifier => Component,
7233 Component_Definition =>
7234 Make_Component_Definition (Loc,
7235 Aliased_Present => False,
7236 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7238 Next_Formal_With_Extras (Formal);
7241 -- Create the Entry_Parameter_Record declaration
7243 Rec_Ent := Make_Temporary (Loc, 'P');
7246 Make_Full_Type_Declaration (Loc,
7247 Defining_Identifier => Rec_Ent,
7249 Make_Record_Definition (Loc,
7251 Make_Component_List (Loc,
7252 Component_Items => Components)));
7254 Insert_After (Last_Decl, Decl);
7257 -- Construct and link in the corresponding access type
7259 Acc_Ent := Make_Temporary (Loc, 'A');
7261 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7264 Make_Full_Type_Declaration (Loc,
7265 Defining_Identifier => Acc_Ent,
7267 Make_Access_To_Object_Definition (Loc,
7268 All_Present => True,
7269 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7271 Insert_After (Last_Decl, Decl);
7274 end Expand_N_Entry_Declaration;
7276 -----------------------------
7277 -- Expand_N_Protected_Body --
7278 -----------------------------
7280 -- Protected bodies are expanded to the completion of the subprograms
7281 -- created for the corresponding protected type. These are a protected and
7282 -- unprotected version of each protected subprogram in the object, a
7283 -- function to calculate each entry barrier, and a procedure to execute the
7284 -- sequence of statements of each protected entry body. For example, for
7285 -- protected type ptype:
7288 -- (O : System.Address;
7289 -- E : Protected_Entry_Index)
7292 -- <discriminant renamings>
7293 -- <private object renamings>
7295 -- return <barrier expression>;
7298 -- procedure pprocN (_object : in out poV;...) is
7299 -- <discriminant renamings>
7300 -- <private object renamings>
7302 -- <sequence of statements>
7305 -- procedure pprocP (_object : in out poV;...) is
7306 -- procedure _clean is
7309 -- ptypeS (_object, Pn);
7310 -- Unlock (_object._object'Access);
7311 -- Abort_Undefer.all;
7316 -- Lock (_object._object'Access);
7317 -- pprocN (_object;...);
7322 -- function pfuncN (_object : poV;...) return Return_Type is
7323 -- <discriminant renamings>
7324 -- <private object renamings>
7326 -- <sequence of statements>
7329 -- function pfuncP (_object : poV) return Return_Type is
7330 -- procedure _clean is
7332 -- Unlock (_object._object'Access);
7333 -- Abort_Undefer.all;
7338 -- Lock (_object._object'Access);
7339 -- return pfuncN (_object);
7346 -- (O : System.Address;
7347 -- P : System.Address;
7348 -- E : Protected_Entry_Index)
7350 -- <discriminant renamings>
7351 -- <private object renamings>
7352 -- type poVP is access poV;
7353 -- _Object : ptVP := ptVP!(O);
7357 -- <statement sequence>
7358 -- Complete_Entry_Body (_Object._Object);
7360 -- when all others =>
7361 -- Exceptional_Complete_Entry_Body (
7362 -- _Object._Object, Get_GNAT_Exception);
7366 -- The type poV is the record created for the protected type to hold
7367 -- the state of the protected object.
7369 procedure Expand_N_Protected_Body (N : Node_Id) is
7370 Loc : constant Source_Ptr := Sloc (N);
7371 Pid : constant Entity_Id := Corresponding_Spec (N);
7373 Current_Node : Node_Id;
7374 Disp_Op_Body : Node_Id;
7375 New_Op_Body : Node_Id;
7376 Num_Entries : Natural := 0;
7380 Chain : Entity_Id := Empty;
7381 -- Finalization chain that may be attached to new body
7383 function Build_Dispatching_Subprogram_Body
7386 Prot_Bod : Node_Id) return Node_Id;
7387 -- Build a dispatching version of the protected subprogram body. The
7388 -- newly generated subprogram contains a call to the original protected
7389 -- body. The following code is generated:
7391 -- function <protected-function-name> (Param1 .. ParamN) return
7394 -- return <protected-function-name>P (Param1 .. ParamN);
7395 -- end <protected-function-name>;
7399 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7401 -- <protected-procedure-name>P (Param1 .. ParamN);
7402 -- end <protected-procedure-name>
7404 ---------------------------------------
7405 -- Build_Dispatching_Subprogram_Body --
7406 ---------------------------------------
7408 function Build_Dispatching_Subprogram_Body
7411 Prot_Bod : Node_Id) return Node_Id
7413 Loc : constant Source_Ptr := Sloc (N);
7420 -- Generate a specification without a letter suffix in order to
7421 -- override an interface function or procedure.
7424 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7426 -- The formal parameters become the actuals of the protected
7427 -- function or procedure call.
7429 Actuals := New_List;
7430 Formal := First (Parameter_Specifications (Spec));
7431 while Present (Formal) loop
7433 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7438 if Nkind (Spec) = N_Procedure_Specification then
7441 Make_Procedure_Call_Statement (Loc,
7443 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7444 Parameter_Associations => Actuals));
7446 pragma Assert (Nkind (Spec) = N_Function_Specification);
7450 Make_Simple_Return_Statement (Loc,
7452 Make_Function_Call (Loc,
7454 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7455 Parameter_Associations => Actuals)));
7459 Make_Subprogram_Body (Loc,
7460 Declarations => Empty_List,
7461 Specification => Spec,
7462 Handled_Statement_Sequence =>
7463 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7464 end Build_Dispatching_Subprogram_Body;
7466 -- Start of processing for Expand_N_Protected_Body
7469 if No_Run_Time_Mode then
7470 Error_Msg_CRT ("protected body", N);
7474 -- This is the proper body corresponding to a stub. The declarations
7475 -- must be inserted at the point of the stub, which in turn is in the
7476 -- declarative part of the parent unit.
7478 if Nkind (Parent (N)) = N_Subunit then
7479 Current_Node := Corresponding_Stub (Parent (N));
7484 Op_Body := First (Declarations (N));
7486 -- The protected body is replaced with the bodies of its
7487 -- protected operations, and the declarations for internal objects
7488 -- that may have been created for entry family bounds.
7490 Rewrite (N, Make_Null_Statement (Sloc (N)));
7493 while Present (Op_Body) loop
7494 case Nkind (Op_Body) is
7495 when N_Subprogram_Declaration =>
7498 when N_Subprogram_Body =>
7500 -- Do not create bodies for eliminated operations
7502 if not Is_Eliminated (Defining_Entity (Op_Body))
7503 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7506 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7508 -- Propagate the finalization chain to the new body. In the
7509 -- unlikely event that the subprogram contains a declaration
7510 -- or allocator for an object that requires finalization,
7511 -- the corresponding chain is created when analyzing the
7512 -- body, and attached to its entity. This entity is not
7513 -- further elaborated, and so the chain properly belongs to
7514 -- the newly created subprogram body.
7517 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7519 if Present (Chain) then
7520 Set_Finalization_Chain_Entity
7521 (Protected_Body_Subprogram
7522 (Corresponding_Spec (Op_Body)), Chain);
7524 (Handled_Statement_Sequence (New_Op_Body), False);
7527 Insert_After (Current_Node, New_Op_Body);
7528 Current_Node := New_Op_Body;
7529 Analyze (New_Op_Body);
7531 -- Build the corresponding protected operation. It may
7532 -- appear that this is needed only if this is a visible
7533 -- operation of the type, or if it is an interrupt handler,
7534 -- and this was the strategy used previously in GNAT.
7535 -- However, the operation may be exported through a 'Access
7536 -- to an external caller. This is the common idiom in code
7537 -- that uses the Ada 2005 Timing_Events package. As a result
7538 -- we need to produce the protected body for both visible
7539 -- and private operations, as well as operations that only
7540 -- have a body in the source, and for which we create a
7541 -- declaration in the protected body itself.
7543 if Present (Corresponding_Spec (Op_Body)) then
7545 Build_Protected_Subprogram_Body (
7546 Op_Body, Pid, Specification (New_Op_Body));
7548 Insert_After (Current_Node, New_Op_Body);
7549 Analyze (New_Op_Body);
7551 Current_Node := New_Op_Body;
7553 -- Generate an overriding primitive operation body for
7554 -- this subprogram if the protected type implements an
7557 if Ada_Version >= Ada_2005
7559 Present (Interfaces (Corresponding_Record_Type (Pid)))
7562 Build_Dispatching_Subprogram_Body
7563 (Op_Body, Pid, New_Op_Body);
7565 Insert_After (Current_Node, Disp_Op_Body);
7566 Analyze (Disp_Op_Body);
7568 Current_Node := Disp_Op_Body;
7573 when N_Entry_Body =>
7574 Op_Id := Defining_Identifier (Op_Body);
7575 Num_Entries := Num_Entries + 1;
7577 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7579 Insert_After (Current_Node, New_Op_Body);
7580 Current_Node := New_Op_Body;
7581 Analyze (New_Op_Body);
7583 when N_Implicit_Label_Declaration =>
7586 when N_Itype_Reference =>
7587 Insert_After (Current_Node, New_Copy (Op_Body));
7589 when N_Freeze_Entity =>
7590 New_Op_Body := New_Copy (Op_Body);
7592 if Present (Entity (Op_Body))
7593 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7595 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7598 Insert_After (Current_Node, New_Op_Body);
7599 Current_Node := New_Op_Body;
7600 Analyze (New_Op_Body);
7603 New_Op_Body := New_Copy (Op_Body);
7604 Insert_After (Current_Node, New_Op_Body);
7605 Current_Node := New_Op_Body;
7606 Analyze (New_Op_Body);
7608 when N_Object_Declaration =>
7609 pragma Assert (not Comes_From_Source (Op_Body));
7610 New_Op_Body := New_Copy (Op_Body);
7611 Insert_After (Current_Node, New_Op_Body);
7612 Current_Node := New_Op_Body;
7613 Analyze (New_Op_Body);
7616 raise Program_Error;
7623 -- Finally, create the body of the function that maps an entry index
7624 -- into the corresponding body index, except when there is no entry, or
7625 -- in a Ravenscar-like profile.
7627 if Corresponding_Runtime_Package (Pid) =
7628 System_Tasking_Protected_Objects_Entries
7630 New_Op_Body := Build_Find_Body_Index (Pid);
7631 Insert_After (Current_Node, New_Op_Body);
7632 Current_Node := New_Op_Body;
7633 Analyze (New_Op_Body);
7636 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7637 -- protected body. At this point all wrapper specs have been created,
7638 -- frozen and included in the dispatch table for the protected type.
7640 if Ada_Version >= Ada_2005 then
7641 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7643 end Expand_N_Protected_Body;
7645 -----------------------------------------
7646 -- Expand_N_Protected_Type_Declaration --
7647 -----------------------------------------
7649 -- First we create a corresponding record type declaration used to
7650 -- represent values of this protected type.
7651 -- The general form of this type declaration is
7653 -- type poV (discriminants) is record
7654 -- _Object : aliased <kind>Protection
7655 -- [(<entry count> [, <handler count>])];
7656 -- [entry_family : array (bounds) of Void;]
7657 -- <private data fields>
7660 -- The discriminants are present only if the corresponding protected type
7661 -- has discriminants, and they exactly mirror the protected type
7662 -- discriminants. The private data fields similarly mirror the private
7663 -- declarations of the protected type.
7665 -- The Object field is always present. It contains RTS specific data used
7666 -- to control the protected object. It is declared as Aliased so that it
7667 -- can be passed as a pointer to the RTS. This allows the protected record
7668 -- to be referenced within RTS data structures. An appropriate Protection
7669 -- type and discriminant are generated.
7671 -- The Service field is present for protected objects with entries. It
7672 -- contains sufficient information to allow the entry service procedure for
7673 -- this object to be called when the object is not known till runtime.
7675 -- One entry_family component is present for each entry family in the
7676 -- task definition (see Expand_N_Task_Type_Declaration).
7678 -- When a protected object is declared, an instance of the protected type
7679 -- value record is created. The elaboration of this declaration creates the
7680 -- correct bounds for the entry families, and also evaluates the priority
7681 -- expression if needed. The initialization routine for the protected type
7682 -- itself then calls Initialize_Protection with appropriate parameters to
7683 -- initialize the value of the Task_Id field. Install_Handlers may be also
7684 -- called if a pragma Attach_Handler applies.
7686 -- Note: this record is passed to the subprograms created by the expansion
7687 -- of protected subprograms and entries. It is an in parameter to protected
7688 -- functions and an in out parameter to procedures and entry bodies. The
7689 -- Entity_Id for this created record type is placed in the
7690 -- Corresponding_Record_Type field of the associated protected type entity.
7692 -- Next we create a procedure specifications for protected subprograms and
7693 -- entry bodies. For each protected subprograms two subprograms are
7694 -- created, an unprotected and a protected version. The unprotected version
7695 -- is called from within other operations of the same protected object.
7697 -- We also build the call to register the procedure if a pragma
7698 -- Interrupt_Handler applies.
7700 -- A single subprogram is created to service all entry bodies; it has an
7701 -- additional boolean out parameter indicating that the previous entry call
7702 -- made by the current task was serviced immediately, i.e. not by proxy.
7703 -- The O parameter contains a pointer to a record object of the type
7704 -- described above. An untyped interface is used here to allow this
7705 -- procedure to be called in places where the type of the object to be
7706 -- serviced is not known. This must be done, for example, when a call that
7707 -- may have been requeued is cancelled; the corresponding object must be
7708 -- serviced, but which object that is not known till runtime.
7711 -- (O : System.Address; P : out Boolean);
7712 -- procedure pprocN (_object : in out poV);
7713 -- procedure pproc (_object : in out poV);
7714 -- function pfuncN (_object : poV);
7715 -- function pfunc (_object : poV);
7718 -- Note that this must come after the record type declaration, since
7719 -- the specs refer to this type.
7721 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7722 Loc : constant Source_Ptr := Sloc (N);
7723 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7725 Pdef : constant Node_Id := Protected_Definition (N);
7726 -- This contains two lists; one for visible and one for private decls
7730 Discr_Map : constant Elist_Id := New_Elmt_List;
7734 Comp_Id : Entity_Id;
7736 Current_Node : Node_Id := N;
7737 Bdef : Entity_Id := Empty; -- avoid uninit warning
7738 Edef : Entity_Id := Empty; -- avoid uninit warning
7739 Entries_Aggr : Node_Id;
7740 Body_Id : Entity_Id;
7743 Object_Comp : Node_Id;
7745 procedure Check_Inlining (Subp : Entity_Id);
7746 -- If the original operation has a pragma Inline, propagate the flag
7747 -- to the internal body, for possible inlining later on. The source
7748 -- operation is invisible to the back-end and is never actually called.
7750 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7751 -- When compiling under the Ravenscar profile, private components must
7752 -- have a static size, or else a protected object will require heap
7753 -- allocation, violating the corresponding restriction. It is preferable
7754 -- to make this check here, because it provides a better error message
7755 -- than the back-end, which refers to the object as a whole.
7757 procedure Register_Handler;
7758 -- For a protected operation that is an interrupt handler, add the
7759 -- freeze action that will register it as such.
7761 --------------------
7762 -- Check_Inlining --
7763 --------------------
7765 procedure Check_Inlining (Subp : Entity_Id) is
7767 if Is_Inlined (Subp) then
7768 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7769 Set_Is_Inlined (Subp, False);
7773 ---------------------------------
7774 -- Check_Static_Component_Size --
7775 ---------------------------------
7777 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7778 Typ : constant Entity_Id := Etype (Comp);
7782 if Is_Scalar_Type (Typ) then
7785 elsif Is_Array_Type (Typ) then
7786 return Compile_Time_Known_Bounds (Typ);
7788 elsif Is_Record_Type (Typ) then
7789 C := First_Component (Typ);
7790 while Present (C) loop
7791 if not Static_Component_Size (C) then
7800 -- Any other types will be checked by the back-end
7805 end Static_Component_Size;
7807 ----------------------
7808 -- Register_Handler --
7809 ----------------------
7811 procedure Register_Handler is
7813 -- All semantic checks already done in Sem_Prag
7815 Prot_Proc : constant Entity_Id :=
7817 (Specification (Current_Node));
7819 Proc_Address : constant Node_Id :=
7820 Make_Attribute_Reference (Loc,
7821 Prefix => New_Reference_To (Prot_Proc, Loc),
7822 Attribute_Name => Name_Address);
7824 RTS_Call : constant Entity_Id :=
7825 Make_Procedure_Call_Statement (Loc,
7828 RTE (RE_Register_Interrupt_Handler), Loc),
7829 Parameter_Associations =>
7830 New_List (Proc_Address));
7832 Append_Freeze_Action (Prot_Proc, RTS_Call);
7833 end Register_Handler;
7835 -- Start of processing for Expand_N_Protected_Type_Declaration
7838 if Present (Corresponding_Record_Type (Prot_Typ)) then
7841 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7844 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7846 Qualify_Entity_Names (N);
7848 -- If the type has discriminants, their occurrences in the declaration
7849 -- have been replaced by the corresponding discriminals. For components
7850 -- that are constrained by discriminants, their homologues in the
7851 -- corresponding record type must refer to the discriminants of that
7852 -- record, so we must apply a new renaming to subtypes_indications:
7854 -- protected discriminant => discriminal => record discriminant
7856 -- This replacement is not applied to default expressions, for which
7857 -- the discriminal is correct.
7859 if Has_Discriminants (Prot_Typ) then
7865 Disc := First_Discriminant (Prot_Typ);
7866 Decl := First (Discriminant_Specifications (Rec_Decl));
7867 while Present (Disc) loop
7868 Append_Elmt (Discriminal (Disc), Discr_Map);
7869 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7870 Next_Discriminant (Disc);
7876 -- Fill in the component declarations
7878 -- Add components for entry families. For each entry family, create an
7879 -- anonymous type declaration with the same size, and analyze the type.
7881 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7883 -- Prepend the _Object field with the right type to the component list.
7884 -- We need to compute the number of entries, and in some cases the
7885 -- number of Attach_Handler pragmas.
7889 Num_Attach_Handler : Int := 0;
7890 Protection_Subtype : Node_Id;
7891 Entry_Count_Expr : constant Node_Id :=
7892 Build_Entry_Count_Expression
7893 (Prot_Typ, Cdecls, Loc);
7896 -- Could this be simplified using Corresponding_Runtime_Package???
7898 if Has_Attach_Handler (Prot_Typ) then
7899 Ritem := First_Rep_Item (Prot_Typ);
7900 while Present (Ritem) loop
7901 if Nkind (Ritem) = N_Pragma
7902 and then Pragma_Name (Ritem) = Name_Attach_Handler
7904 Num_Attach_Handler := Num_Attach_Handler + 1;
7907 Next_Rep_Item (Ritem);
7910 if Restricted_Profile then
7911 if Has_Entries (Prot_Typ) then
7912 Protection_Subtype :=
7913 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7915 Protection_Subtype :=
7916 New_Reference_To (RTE (RE_Protection), Loc);
7919 Protection_Subtype :=
7920 Make_Subtype_Indication
7924 (RTE (RE_Static_Interrupt_Protection), Loc),
7926 Make_Index_Or_Discriminant_Constraint (
7928 Constraints => New_List (
7930 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7933 elsif Has_Interrupt_Handler (Prot_Typ) then
7934 Protection_Subtype :=
7935 Make_Subtype_Indication (
7937 Subtype_Mark => New_Reference_To
7938 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7940 Make_Index_Or_Discriminant_Constraint (
7942 Constraints => New_List (Entry_Count_Expr)));
7944 -- Type has explicit entries or generated primitive entry wrappers
7946 elsif Has_Entries (Prot_Typ)
7947 or else (Ada_Version >= Ada_2005
7948 and then Present (Interface_List (N)))
7950 case Corresponding_Runtime_Package (Prot_Typ) is
7951 when System_Tasking_Protected_Objects_Entries =>
7952 Protection_Subtype :=
7953 Make_Subtype_Indication (Loc,
7955 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7957 Make_Index_Or_Discriminant_Constraint (
7959 Constraints => New_List (Entry_Count_Expr)));
7961 when System_Tasking_Protected_Objects_Single_Entry =>
7962 Protection_Subtype :=
7963 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7966 raise Program_Error;
7970 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7974 Make_Component_Declaration (Loc,
7975 Defining_Identifier =>
7976 Make_Defining_Identifier (Loc, Name_uObject),
7977 Component_Definition =>
7978 Make_Component_Definition (Loc,
7979 Aliased_Present => True,
7980 Subtype_Indication => Protection_Subtype));
7983 pragma Assert (Present (Pdef));
7985 -- Add private field components
7987 if Present (Private_Declarations (Pdef)) then
7988 Priv := First (Private_Declarations (Pdef));
7990 while Present (Priv) loop
7992 if Nkind (Priv) = N_Component_Declaration then
7993 if not Static_Component_Size (Defining_Identifier (Priv)) then
7995 -- When compiling for a restricted profile, the private
7996 -- components must have a static size. If not, this is an
7997 -- error for a single protected declaration, and rates a
7998 -- warning on a protected type declaration.
8000 if not Comes_From_Source (Prot_Typ) then
8001 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8003 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8004 Error_Msg_N ("component has non-static size?", Priv);
8006 ("\creation of protected object of type& will violate"
8007 & " restriction No_Implicit_Heap_Allocations?",
8012 -- The component definition consists of a subtype indication,
8013 -- or (in Ada 2005) an access definition. Make a copy of the
8014 -- proper definition.
8017 Old_Comp : constant Node_Id := Component_Definition (Priv);
8018 Oent : constant Entity_Id := Defining_Identifier (Priv);
8020 Nent : constant Entity_Id :=
8021 Make_Defining_Identifier (Sloc (Oent),
8022 Chars => Chars (Oent));
8025 if Present (Subtype_Indication (Old_Comp)) then
8027 Make_Component_Definition (Sloc (Oent),
8028 Aliased_Present => False,
8029 Subtype_Indication =>
8030 New_Copy_Tree (Subtype_Indication (Old_Comp),
8034 Make_Component_Definition (Sloc (Oent),
8035 Aliased_Present => False,
8036 Access_Definition =>
8037 New_Copy_Tree (Access_Definition (Old_Comp),
8042 Make_Component_Declaration (Loc,
8043 Defining_Identifier => Nent,
8044 Component_Definition => New_Comp,
8045 Expression => Expression (Priv));
8047 Set_Has_Per_Object_Constraint (Nent,
8048 Has_Per_Object_Constraint (Oent));
8050 Append_To (Cdecls, New_Priv);
8053 elsif Nkind (Priv) = N_Subprogram_Declaration then
8055 -- Make the unprotected version of the subprogram available
8056 -- for expansion of intra object calls. There is need for
8057 -- a protected version only if the subprogram is an interrupt
8058 -- handler, otherwise this operation can only be called from
8062 Make_Subprogram_Declaration (Loc,
8064 Build_Protected_Sub_Specification
8065 (Priv, Prot_Typ, Unprotected_Mode));
8067 Insert_After (Current_Node, Sub);
8070 Set_Protected_Body_Subprogram
8071 (Defining_Unit_Name (Specification (Priv)),
8072 Defining_Unit_Name (Specification (Sub)));
8073 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8074 Current_Node := Sub;
8077 Make_Subprogram_Declaration (Loc,
8079 Build_Protected_Sub_Specification
8080 (Priv, Prot_Typ, Protected_Mode));
8082 Insert_After (Current_Node, Sub);
8084 Current_Node := Sub;
8086 if Is_Interrupt_Handler
8087 (Defining_Unit_Name (Specification (Priv)))
8089 if not Restricted_Profile then
8099 -- Put the _Object component after the private component so that it
8100 -- be finalized early as required by 9.4 (20)
8102 Append_To (Cdecls, Object_Comp);
8104 Insert_After (Current_Node, Rec_Decl);
8105 Current_Node := Rec_Decl;
8107 -- Analyze the record declaration immediately after construction,
8108 -- because the initialization procedure is needed for single object
8109 -- declarations before the next entity is analyzed (the freeze call
8110 -- that generates this initialization procedure is found below).
8112 Analyze (Rec_Decl, Suppress => All_Checks);
8114 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8115 -- the corresponding record is frozen. If any wrappers are generated,
8116 -- Current_Node is updated accordingly.
8118 if Ada_Version >= Ada_2005 then
8119 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8122 -- Collect pointers to entry bodies and their barriers, to be placed
8123 -- in the Entry_Bodies_Array for the type. For each entry/family we
8124 -- add an expression to the aggregate which is the initial value of
8125 -- this array. The array is declared after all protected subprograms.
8127 if Has_Entries (Prot_Typ) then
8128 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8130 Entries_Aggr := Empty;
8133 -- Build two new procedure specifications for each protected subprogram;
8134 -- one to call from outside the object and one to call from inside.
8135 -- Build a barrier function and an entry body action procedure
8136 -- specification for each protected entry. Initialize the entry body
8137 -- array. If subprogram is flagged as eliminated, do not generate any
8138 -- internal operations.
8142 Comp := First (Visible_Declarations (Pdef));
8144 while Present (Comp) loop
8145 if Nkind (Comp) = N_Subprogram_Declaration then
8147 Make_Subprogram_Declaration (Loc,
8149 Build_Protected_Sub_Specification
8150 (Comp, Prot_Typ, Unprotected_Mode));
8152 Insert_After (Current_Node, Sub);
8155 Set_Protected_Body_Subprogram
8156 (Defining_Unit_Name (Specification (Comp)),
8157 Defining_Unit_Name (Specification (Sub)));
8158 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8160 -- Make the protected version of the subprogram available for
8161 -- expansion of external calls.
8163 Current_Node := Sub;
8166 Make_Subprogram_Declaration (Loc,
8168 Build_Protected_Sub_Specification
8169 (Comp, Prot_Typ, Protected_Mode));
8171 Insert_After (Current_Node, Sub);
8174 Current_Node := Sub;
8176 -- Generate an overriding primitive operation specification for
8177 -- this subprogram if the protected type implements an interface.
8179 if Ada_Version >= Ada_2005
8181 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8184 Make_Subprogram_Declaration (Loc,
8186 Build_Protected_Sub_Specification
8187 (Comp, Prot_Typ, Dispatching_Mode));
8189 Insert_After (Current_Node, Sub);
8192 Current_Node := Sub;
8195 -- If a pragma Interrupt_Handler applies, build and add a call to
8196 -- Register_Interrupt_Handler to the freezing actions of the
8197 -- protected version (Current_Node) of the subprogram:
8199 -- system.interrupts.register_interrupt_handler
8200 -- (prot_procP'address);
8202 if not Restricted_Profile
8203 and then Is_Interrupt_Handler
8204 (Defining_Unit_Name (Specification (Comp)))
8209 elsif Nkind (Comp) = N_Entry_Declaration then
8210 E_Count := E_Count + 1;
8211 Comp_Id := Defining_Identifier (Comp);
8214 Make_Defining_Identifier (Loc,
8215 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8217 Make_Subprogram_Declaration (Loc,
8219 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8221 Insert_After (Current_Node, Sub);
8224 -- build wrapper procedure for pre/postconditions.
8226 Build_PPC_Wrapper (Comp_Id, N);
8228 Set_Protected_Body_Subprogram
8229 (Defining_Identifier (Comp),
8230 Defining_Unit_Name (Specification (Sub)));
8232 Current_Node := Sub;
8235 Make_Defining_Identifier (Loc,
8236 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8238 Make_Subprogram_Declaration (Loc,
8240 Build_Barrier_Function_Specification (Loc, Bdef));
8242 Insert_After (Current_Node, Sub);
8244 Set_Protected_Body_Subprogram (Bdef, Bdef);
8245 Set_Barrier_Function (Comp_Id, Bdef);
8246 Set_Scope (Bdef, Scope (Comp_Id));
8247 Current_Node := Sub;
8249 -- Collect pointers to the protected subprogram and the barrier
8250 -- of the current entry, for insertion into Entry_Bodies_Array.
8253 Make_Aggregate (Loc,
8254 Expressions => New_List (
8255 Make_Attribute_Reference (Loc,
8256 Prefix => New_Reference_To (Bdef, Loc),
8257 Attribute_Name => Name_Unrestricted_Access),
8258 Make_Attribute_Reference (Loc,
8259 Prefix => New_Reference_To (Edef, Loc),
8260 Attribute_Name => Name_Unrestricted_Access))),
8261 Expressions (Entries_Aggr));
8268 -- If there are some private entry declarations, expand it as if they
8269 -- were visible entries.
8271 if Present (Private_Declarations (Pdef)) then
8272 Comp := First (Private_Declarations (Pdef));
8273 while Present (Comp) loop
8274 if Nkind (Comp) = N_Entry_Declaration then
8275 E_Count := E_Count + 1;
8276 Comp_Id := Defining_Identifier (Comp);
8279 Make_Defining_Identifier (Loc,
8280 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8282 Make_Subprogram_Declaration (Loc,
8284 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8286 Insert_After (Current_Node, Sub);
8289 Set_Protected_Body_Subprogram
8290 (Defining_Identifier (Comp),
8291 Defining_Unit_Name (Specification (Sub)));
8293 Current_Node := Sub;
8296 Make_Defining_Identifier (Loc,
8297 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8300 Make_Subprogram_Declaration (Loc,
8302 Build_Barrier_Function_Specification (Loc, Bdef));
8304 Insert_After (Current_Node, Sub);
8306 Set_Protected_Body_Subprogram (Bdef, Bdef);
8307 Set_Barrier_Function (Comp_Id, Bdef);
8308 Set_Scope (Bdef, Scope (Comp_Id));
8309 Current_Node := Sub;
8311 -- Collect pointers to the protected subprogram and the barrier
8312 -- of the current entry, for insertion into Entry_Bodies_Array.
8314 Append_To (Expressions (Entries_Aggr),
8315 Make_Aggregate (Loc,
8316 Expressions => New_List (
8317 Make_Attribute_Reference (Loc,
8318 Prefix => New_Reference_To (Bdef, Loc),
8319 Attribute_Name => Name_Unrestricted_Access),
8320 Make_Attribute_Reference (Loc,
8321 Prefix => New_Reference_To (Edef, Loc),
8322 Attribute_Name => Name_Unrestricted_Access))));
8329 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8330 -- all protected subprograms have been collected.
8332 if Has_Entries (Prot_Typ) then
8334 Make_Defining_Identifier (Sloc (Prot_Typ),
8335 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8337 case Corresponding_Runtime_Package (Prot_Typ) is
8338 when System_Tasking_Protected_Objects_Entries =>
8339 Body_Arr := Make_Object_Declaration (Loc,
8340 Defining_Identifier => Body_Id,
8341 Aliased_Present => True,
8342 Object_Definition =>
8343 Make_Subtype_Indication (Loc,
8344 Subtype_Mark => New_Reference_To (
8345 RTE (RE_Protected_Entry_Body_Array), Loc),
8347 Make_Index_Or_Discriminant_Constraint (Loc,
8348 Constraints => New_List (
8350 Make_Integer_Literal (Loc, 1),
8351 Make_Integer_Literal (Loc, E_Count))))),
8352 Expression => Entries_Aggr);
8354 when System_Tasking_Protected_Objects_Single_Entry =>
8355 Body_Arr := Make_Object_Declaration (Loc,
8356 Defining_Identifier => Body_Id,
8357 Aliased_Present => True,
8358 Object_Definition => New_Reference_To
8359 (RTE (RE_Entry_Body), Loc),
8361 Make_Aggregate (Loc,
8362 Expressions => New_List (
8363 Make_Attribute_Reference (Loc,
8364 Prefix => New_Reference_To (Bdef, Loc),
8365 Attribute_Name => Name_Unrestricted_Access),
8366 Make_Attribute_Reference (Loc,
8367 Prefix => New_Reference_To (Edef, Loc),
8368 Attribute_Name => Name_Unrestricted_Access))));
8371 raise Program_Error;
8374 -- A pointer to this array will be placed in the corresponding record
8375 -- by its initialization procedure so this needs to be analyzed here.
8377 Insert_After (Current_Node, Body_Arr);
8378 Current_Node := Body_Arr;
8381 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8383 -- Finally, build the function that maps an entry index into the
8384 -- corresponding body. A pointer to this function is placed in each
8385 -- object of the type. Except for a ravenscar-like profile (no abort,
8386 -- no entry queue, 1 entry)
8388 if Corresponding_Runtime_Package (Prot_Typ) =
8389 System_Tasking_Protected_Objects_Entries
8392 Make_Subprogram_Declaration (Loc,
8393 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8394 Insert_After (Current_Node, Sub);
8398 end Expand_N_Protected_Type_Declaration;
8400 --------------------------------
8401 -- Expand_N_Requeue_Statement --
8402 --------------------------------
8404 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8405 -- operations, depending on the source and destination (task or protected
8406 -- object). A dispatching requeue statement is expanded into a call to the
8407 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8408 -- jump around the remainder of processing for the original entry and, if
8409 -- the destination is (different) protected object, to attempt to service
8410 -- it. The following illustrates the various cases:
8413 -- (O : System.Address;
8414 -- P : System.Address;
8415 -- E : Protected_Entry_Index)
8417 -- <discriminant renamings>
8418 -- <private object renamings>
8419 -- type poVP is access poV;
8420 -- _object : ptVP := ptVP!(O);
8424 -- <start of statement sequence for entry>
8426 -- -- Requeue from one protected entry body to another protected
8429 -- Requeue_Protected_Entry (
8430 -- _object._object'Access,
8431 -- new._object'Access,
8436 -- <some more of the statement sequence for entry>
8438 -- -- Requeue from an entry body to a task entry
8440 -- Requeue_Protected_To_Task_Entry (
8446 -- <rest of statement sequence for entry>
8447 -- Complete_Entry_Body (_object._object);
8450 -- when all others =>
8451 -- Exceptional_Complete_Entry_Body (
8452 -- _object._object, Get_GNAT_Exception);
8456 -- Requeue of a task entry call to a task entry
8458 -- Accept_Call (E, Ann);
8459 -- <start of statement sequence for accept statement>
8460 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8462 -- <rest of statement sequence for accept statement>
8464 -- Complete_Rendezvous;
8467 -- when all others =>
8468 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8470 -- Requeue of a task entry call to a protected entry
8472 -- Accept_Call (E, Ann);
8473 -- <start of statement sequence for accept statement>
8474 -- Requeue_Task_To_Protected_Entry (
8475 -- new._object'Access,
8480 -- <rest of statement sequence for accept statement>
8482 -- Complete_Rendezvous;
8485 -- when all others =>
8486 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8488 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8489 -- marked by pragma Implemented (XXX, By_Entry).
8491 -- The requeue is inside a protected entry:
8494 -- (O : System.Address;
8495 -- P : System.Address;
8496 -- E : Protected_Entry_Index)
8498 -- <discriminant renamings>
8499 -- <private object renamings>
8500 -- type poVP is access poV;
8501 -- _object : ptVP := ptVP!(O);
8505 -- <start of statement sequence for entry>
8508 -- (<interface class-wide object>,
8511 -- Ada.Tags.Get_Offset_Index
8513 -- <interface dispatch table index of target entry>),
8517 -- <rest of statement sequence for entry>
8518 -- Complete_Entry_Body (_object._object);
8521 -- when all others =>
8522 -- Exceptional_Complete_Entry_Body (
8523 -- _object._object, Get_GNAT_Exception);
8527 -- The requeue is inside a task entry:
8529 -- Accept_Call (E, Ann);
8530 -- <start of statement sequence for accept statement>
8532 -- (<interface class-wide object>,
8535 -- Ada.Tags.Get_Offset_Index
8537 -- <interface dispatch table index of target entrt>),
8541 -- <rest of statement sequence for accept statement>
8543 -- Complete_Rendezvous;
8546 -- when all others =>
8547 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8549 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8550 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8551 -- statement is replaced by a dispatching call with actual parameters taken
8552 -- from the inner-most accept statement or entry body.
8554 -- Target.Primitive (Param1, ..., ParamN);
8556 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8557 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8560 -- S : constant Offset_Index :=
8561 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8562 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8565 -- if C = POK_Protected_Entry
8566 -- or else C = POK_Task_Entry
8568 -- <statements for dispatching requeue>
8570 -- elsif C = POK_Protected_Procedure then
8571 -- <dispatching call equivalent>
8574 -- raise Program_Error;
8578 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8579 Loc : constant Source_Ptr := Sloc (N);
8580 Conc_Typ : Entity_Id;
8584 Old_Typ : Entity_Id;
8586 function Build_Dispatching_Call_Equivalent return Node_Id;
8587 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8588 -- the form Concval.Ename. It is statically known that Ename is allowed
8589 -- to be implemented by a protected procedure. Create a dispatching call
8590 -- equivalent of Concval.Ename taking the actual parameters from the
8591 -- inner-most accept statement or entry body.
8593 function Build_Dispatching_Requeue return Node_Id;
8594 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8595 -- the form Concval.Ename. It is statically known that Ename is allowed
8596 -- to be implemented by a protected or a task entry. Create a call to
8597 -- primitive _Disp_Requeue which handles the low-level actions.
8599 function Build_Dispatching_Requeue_To_Any return Node_Id;
8600 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8601 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8602 -- (XXX, By_Any) or not marked at all. Create a block which determines
8603 -- at runtime whether Ename denotes an entry or a procedure and perform
8604 -- the appropriate kind of dispatching select.
8606 function Build_Normal_Requeue return Node_Id;
8607 -- N denotes a non-dispatching requeue statement to either a task or a
8608 -- protected entry. Build the appropriate runtime call to perform the
8611 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8612 -- For a protected entry, create a return statement to skip the rest of
8613 -- the entry body. Otherwise, create a goto statement to skip the rest
8614 -- of a task accept statement. The lookup for the enclosing entry body
8615 -- or accept statement starts from Search.
8617 ---------------------------------------
8618 -- Build_Dispatching_Call_Equivalent --
8619 ---------------------------------------
8621 function Build_Dispatching_Call_Equivalent return Node_Id is
8622 Call_Ent : constant Entity_Id := Entity (Ename);
8623 Obj : constant Node_Id := Original_Node (Concval);
8630 -- Climb the parent chain looking for the inner-most entry body or
8631 -- accept statement.
8634 while Present (Acc_Ent)
8635 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8638 Acc_Ent := Parent (Acc_Ent);
8641 -- A requeue statement should be housed inside an entry body or an
8642 -- accept statement at some level. If this is not the case, then the
8643 -- tree is malformed.
8645 pragma Assert (Present (Acc_Ent));
8647 -- Recover the list of formal parameters
8649 if Nkind (Acc_Ent) = N_Entry_Body then
8650 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8653 Formals := Parameter_Specifications (Acc_Ent);
8655 -- Create the actual parameters for the dispatching call. These are
8656 -- simply copies of the entry body or accept statement formals in the
8657 -- same order as they appear.
8661 if Present (Formals) then
8662 Actuals := New_List;
8663 Formal := First (Formals);
8664 while Present (Formal) loop
8666 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8672 -- Obj.Call_Ent (Actuals);
8675 Make_Procedure_Call_Statement (Loc,
8677 Make_Selected_Component (Loc,
8679 Make_Identifier (Loc, Chars (Obj)),
8681 Make_Identifier (Loc, Chars (Call_Ent))),
8683 Parameter_Associations => Actuals);
8684 end Build_Dispatching_Call_Equivalent;
8686 -------------------------------
8687 -- Build_Dispatching_Requeue --
8688 -------------------------------
8690 function Build_Dispatching_Requeue return Node_Id is
8691 Params : constant List_Id := New_List;
8694 -- Process the "with abort" parameter
8697 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8699 -- Process the entry wrapper's position in the primary dispatch
8700 -- table parameter. Generate:
8702 -- Ada.Tags.Get_Offset_Index
8703 -- (Ada.Tags.Tag (Concval),
8704 -- <interface dispatch table position of Ename>)
8707 Make_Function_Call (Loc,
8709 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8711 Parameter_Associations => New_List (
8712 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8713 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8715 -- Specific actuals for protected to XXX requeue
8717 if Is_Protected_Type (Old_Typ) then
8719 Make_Attribute_Reference (Loc, -- _object'Address
8721 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8722 Attribute_Name => Name_Address));
8724 Prepend_To (Params, -- True
8725 New_Reference_To (Standard_True, Loc));
8727 -- Specific actuals for task to XXX requeue
8730 pragma Assert (Is_Task_Type (Old_Typ));
8732 Prepend_To (Params, -- null
8733 New_Reference_To (RTE (RE_Null_Address), Loc));
8735 Prepend_To (Params, -- False
8736 New_Reference_To (Standard_False, Loc));
8739 -- Add the object parameter
8741 Prepend_To (Params, New_Copy_Tree (Concval));
8744 -- _Disp_Requeue (<Params>);
8747 Make_Procedure_Call_Statement (Loc,
8749 Make_Identifier (Loc, Name_uDisp_Requeue),
8750 Parameter_Associations => Params);
8751 end Build_Dispatching_Requeue;
8753 --------------------------------------
8754 -- Build_Dispatching_Requeue_To_Any --
8755 --------------------------------------
8757 function Build_Dispatching_Requeue_To_Any return Node_Id is
8758 Call_Ent : constant Entity_Id := Entity (Ename);
8759 Obj : constant Node_Id := Original_Node (Concval);
8760 Skip : constant Node_Id := Build_Skip_Statement (N);
8770 -- Dispatch table slot processing, generate:
8773 S := Build_S (Loc, Decls);
8775 -- Call kind processing, generate:
8776 -- C : Ada.Tags.Prim_Op_Kind;
8778 C := Build_C (Loc, Decls);
8781 -- S := Ada.Tags.Get_Offset_Index
8782 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
8784 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
8787 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
8790 Make_Procedure_Call_Statement (Loc,
8793 Find_Prim_Op (Etype (Etype (Obj)),
8794 Name_uDisp_Get_Prim_Op_Kind),
8796 Parameter_Associations => New_List (
8797 New_Copy_Tree (Obj),
8798 New_Reference_To (S, Loc),
8799 New_Reference_To (C, Loc))));
8803 -- if C = POK_Protected_Entry
8804 -- or else C = POK_Task_Entry
8807 Make_If_Statement (Loc,
8813 New_Reference_To (C, Loc),
8815 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
8820 New_Reference_To (C, Loc),
8822 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
8824 -- Dispatching requeue equivalent
8826 Then_Statements => New_List (
8827 Build_Dispatching_Requeue,
8830 -- elsif C = POK_Protected_Procedure then
8832 Elsif_Parts => New_List (
8833 Make_Elsif_Part (Loc,
8837 New_Reference_To (C, Loc),
8840 RTE (RE_POK_Protected_Procedure), Loc)),
8842 -- Dispatching call equivalent
8844 Then_Statements => New_List (
8845 Build_Dispatching_Call_Equivalent))),
8848 -- raise Program_Error;
8851 Else_Statements => New_List (
8852 Make_Raise_Program_Error (Loc,
8853 Reason => PE_Explicit_Raise))));
8855 -- Wrap everything into a block
8858 Make_Block_Statement (Loc,
8859 Declarations => Decls,
8860 Handled_Statement_Sequence =>
8861 Make_Handled_Sequence_Of_Statements (Loc,
8862 Statements => Stmts));
8863 end Build_Dispatching_Requeue_To_Any;
8865 --------------------------
8866 -- Build_Normal_Requeue --
8867 --------------------------
8869 function Build_Normal_Requeue return Node_Id is
8870 Params : constant List_Id := New_List;
8875 -- Process the "with abort" parameter
8878 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8880 -- Add the index expression to the parameters. It is common among all
8884 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8886 if Is_Protected_Type (Old_Typ) then
8888 Self_Param : Node_Id;
8892 Make_Attribute_Reference (Loc,
8894 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8896 Name_Unchecked_Access);
8898 -- Protected to protected requeue
8900 if Is_Protected_Type (Conc_Typ) then
8903 RTE (RE_Requeue_Protected_Entry), Loc);
8906 Make_Attribute_Reference (Loc,
8908 Concurrent_Ref (Concval),
8910 Name_Unchecked_Access);
8912 -- Protected to task requeue
8914 else pragma Assert (Is_Task_Type (Conc_Typ));
8917 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8919 Param := Concurrent_Ref (Concval);
8922 Prepend_To (Params, Param);
8923 Prepend_To (Params, Self_Param);
8926 else pragma Assert (Is_Task_Type (Old_Typ));
8928 -- Task to protected requeue
8930 if Is_Protected_Type (Conc_Typ) then
8933 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8936 Make_Attribute_Reference (Loc,
8938 Concurrent_Ref (Concval),
8940 Name_Unchecked_Access);
8942 -- Task to task requeue
8944 else pragma Assert (Is_Task_Type (Conc_Typ));
8946 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8948 Param := Concurrent_Ref (Concval);
8951 Prepend_To (Params, Param);
8955 Make_Procedure_Call_Statement (Loc,
8957 Parameter_Associations => Params);
8958 end Build_Normal_Requeue;
8960 --------------------------
8961 -- Build_Skip_Statement --
8962 --------------------------
8964 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
8965 Skip_Stmt : Node_Id;
8968 -- Build a return statement to skip the rest of the entire body
8970 if Is_Protected_Type (Old_Typ) then
8971 Skip_Stmt := Make_Simple_Return_Statement (Loc);
8973 -- If the requeue is within a task, find the end label of the
8974 -- enclosing accept statement and create a goto statement to it.
8982 -- Climb the parent chain looking for the enclosing accept
8985 Acc := Parent (Search);
8987 and then Nkind (Acc) /= N_Accept_Statement
8989 Acc := Parent (Acc);
8992 -- The last statement is the second label used for completing
8993 -- the rendezvous the usual way. The label we are looking for
8994 -- is right before it.
8997 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
8999 pragma Assert (Nkind (Label) = N_Label);
9001 -- Generate a goto statement to skip the rest of the accept
9004 Make_Goto_Statement (Loc,
9006 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9010 Set_Analyzed (Skip_Stmt);
9013 end Build_Skip_Statement;
9015 -- Start of processing for Expand_N_Requeue_Statement
9018 -- Extract the components of the entry call
9020 Extract_Entry (N, Concval, Ename, Index);
9021 Conc_Typ := Etype (Concval);
9023 -- Examine the scope stack in order to find nearest enclosing protected
9024 -- or task type. This will constitute our invocation source.
9026 Old_Typ := Current_Scope;
9027 while Present (Old_Typ)
9028 and then not Is_Protected_Type (Old_Typ)
9029 and then not Is_Task_Type (Old_Typ)
9031 Old_Typ := Scope (Old_Typ);
9034 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9035 -- Concval.Ename where the type of Concval is class-wide concurrent
9038 if Ada_Version >= Ada_2012
9039 and then Present (Concval)
9040 and then Is_Class_Wide_Type (Conc_Typ)
9041 and then Is_Concurrent_Interface (Conc_Typ)
9044 Has_Impl : Boolean := False;
9045 Impl_Kind : Name_Id := No_Name;
9048 -- Check whether the Ename is flagged by pragma Implemented
9050 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9052 Impl_Kind := Implementation_Kind (Entity (Ename));
9055 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9056 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9059 and then Impl_Kind = Name_By_Entry
9061 Rewrite (N, Build_Dispatching_Requeue);
9063 Insert_After (N, Build_Skip_Statement (N));
9065 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9066 -- a protected procedure. In this case the requeue is transformed
9067 -- into a dispatching call.
9070 and then Impl_Kind = Name_By_Protected_Procedure
9072 Rewrite (N, Build_Dispatching_Call_Equivalent);
9075 -- The procedure_or_entry_NAME's implementation kind is either
9076 -- By_Any or pragma Implemented was not applied at all. In this
9077 -- case a runtime test determines whether Ename denotes an entry
9078 -- or a protected procedure and performs the appropriate call.
9081 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9086 -- Processing for regular (non-dispatching) requeues
9089 Rewrite (N, Build_Normal_Requeue);
9091 Insert_After (N, Build_Skip_Statement (N));
9093 end Expand_N_Requeue_Statement;
9095 -------------------------------
9096 -- Expand_N_Selective_Accept --
9097 -------------------------------
9099 procedure Expand_N_Selective_Accept (N : Node_Id) is
9100 Loc : constant Source_Ptr := Sloc (N);
9101 Alts : constant List_Id := Select_Alternatives (N);
9103 -- Note: in the below declarations a lot of new lists are allocated
9104 -- unconditionally which may well not end up being used. That's
9105 -- not a good idea since it wastes space gratuitously ???
9107 Accept_Case : List_Id;
9108 Accept_List : constant List_Id := New_List;
9111 Alt_List : constant List_Id := New_List;
9112 Alt_Stats : List_Id;
9113 Ann : Entity_Id := Empty;
9116 Check_Guard : Boolean := True;
9118 Decls : constant List_Id := New_List;
9119 Stats : constant List_Id := New_List;
9120 Body_List : constant List_Id := New_List;
9121 Trailing_List : constant List_Id := New_List;
9124 Else_Present : Boolean := False;
9125 Terminate_Alt : Node_Id := Empty;
9126 Select_Mode : Node_Id;
9128 Delay_Case : List_Id;
9129 Delay_Count : Integer := 0;
9130 Delay_Val : Entity_Id;
9131 Delay_Index : Entity_Id;
9132 Delay_Min : Entity_Id;
9133 Delay_Num : Int := 1;
9134 Delay_Alt_List : List_Id := New_List;
9135 Delay_List : constant List_Id := New_List;
9139 First_Delay : Boolean := True;
9140 Guard_Open : Entity_Id;
9146 Num_Accept : Nat := 0;
9149 Time_Type : Entity_Id;
9151 Select_Call : Node_Id;
9153 Qnam : constant Entity_Id :=
9154 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9156 Xnam : constant Entity_Id :=
9157 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9159 -----------------------
9160 -- Local subprograms --
9161 -----------------------
9163 function Accept_Or_Raise return List_Id;
9164 -- For the rare case where delay alternatives all have guards, and
9165 -- all of them are closed, it is still possible that there were open
9166 -- accept alternatives with no callers. We must reexamine the
9167 -- Accept_List, and execute a selective wait with no else if some
9168 -- accept is open. If none, we raise program_error.
9170 procedure Add_Accept (Alt : Node_Id);
9171 -- Process a single accept statement in a select alternative. Build
9172 -- procedure for body of accept, and add entry to dispatch table with
9173 -- expression for guard, in preparation for call to run time select.
9175 function Make_And_Declare_Label (Num : Int) return Node_Id;
9176 -- Manufacture a label using Num as a serial number and declare it.
9177 -- The declaration is appended to Decls. The label marks the trailing
9178 -- statements of an accept or delay alternative.
9180 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9181 -- Build call to Selective_Wait runtime routine
9183 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9184 -- Add code to compare value of delay with previous values, and
9185 -- generate case entry for trailing statements.
9187 procedure Process_Accept_Alternative
9191 -- Add code to call corresponding procedure, and branch to
9192 -- trailing statements, if any.
9194 ---------------------
9195 -- Accept_Or_Raise --
9196 ---------------------
9198 function Accept_Or_Raise return List_Id is
9201 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9204 -- We generate the following:
9206 -- for J in q'range loop
9207 -- if q(J).S /=null_task_entry then
9208 -- selective_wait (simple_mode,...);
9214 -- if no rendez_vous then
9215 -- raise program_error;
9218 -- Note that the code needs to know that the selector name
9219 -- in an Accept_Alternative is named S.
9221 Cond := Make_Op_Ne (Loc,
9223 Make_Selected_Component (Loc,
9224 Prefix => Make_Indexed_Component (Loc,
9225 Prefix => New_Reference_To (Qnam, Loc),
9226 Expressions => New_List (New_Reference_To (J, Loc))),
9227 Selector_Name => Make_Identifier (Loc, Name_S)),
9229 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9232 Make_Implicit_Loop_Statement (N,
9233 Identifier => Empty,
9235 Make_Iteration_Scheme (Loc,
9236 Loop_Parameter_Specification =>
9237 Make_Loop_Parameter_Specification (Loc,
9238 Defining_Identifier => J,
9239 Discrete_Subtype_Definition =>
9240 Make_Attribute_Reference (Loc,
9241 Prefix => New_Reference_To (Qnam, Loc),
9242 Attribute_Name => Name_Range,
9243 Expressions => New_List (
9244 Make_Integer_Literal (Loc, 1))))),
9246 Statements => New_List (
9247 Make_Implicit_If_Statement (N,
9249 Then_Statements => New_List (
9251 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9252 Make_Exit_Statement (Loc))))));
9255 Make_Raise_Program_Error (Loc,
9256 Condition => Make_Op_Eq (Loc,
9257 Left_Opnd => New_Reference_To (Xnam, Loc),
9259 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9260 Reason => PE_All_Guards_Closed));
9263 end Accept_Or_Raise;
9269 procedure Add_Accept (Alt : Node_Id) is
9270 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9271 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9272 Eloc : constant Source_Ptr := Sloc (Ename);
9273 Eent : constant Entity_Id := Entity (Ename);
9274 Index : constant Node_Id := Entry_Index (Acc_Stm);
9275 Null_Body : Node_Id;
9276 Proc_Body : Node_Id;
9283 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9286 if Present (Condition (Alt)) then
9288 Make_Conditional_Expression (Eloc, New_List (
9290 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9291 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9294 Entry_Index_Expression
9295 (Eloc, Eent, Index, Scope (Eent));
9298 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9299 Null_Body := New_Reference_To (Standard_False, Eloc);
9301 if Abort_Allowed then
9302 Call := Make_Procedure_Call_Statement (Eloc,
9303 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9304 Insert_Before (First (Statements (Handled_Statement_Sequence (
9305 Accept_Statement (Alt)))), Call);
9310 Make_Defining_Identifier (Eloc,
9311 New_External_Name (Chars (Ename), 'A', Num_Accept));
9313 if Comes_From_Source (Alt) then
9314 Set_Debug_Info_Needed (PB_Ent);
9318 Make_Subprogram_Body (Eloc,
9320 Make_Procedure_Specification (Eloc,
9321 Defining_Unit_Name => PB_Ent),
9322 Declarations => Declarations (Acc_Stm),
9323 Handled_Statement_Sequence =>
9324 Build_Accept_Body (Accept_Statement (Alt)));
9326 -- During the analysis of the body of the accept statement, any
9327 -- zero cost exception handler records were collected in the
9328 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9329 -- This is where we move them to where they belong, namely the
9330 -- newly created procedure.
9332 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9333 Append (Proc_Body, Body_List);
9336 Null_Body := New_Reference_To (Standard_True, Eloc);
9338 -- if accept statement has declarations, insert above, given that
9339 -- we are not creating a body for the accept.
9341 if Present (Declarations (Acc_Stm)) then
9342 Insert_Actions (N, Declarations (Acc_Stm));
9346 Append_To (Accept_List,
9347 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9349 Num_Accept := Num_Accept + 1;
9352 ----------------------------
9353 -- Make_And_Declare_Label --
9354 ----------------------------
9356 function Make_And_Declare_Label (Num : Int) return Node_Id is
9360 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9362 Make_Label (Loc, Lab_Id);
9365 Make_Implicit_Label_Declaration (Loc,
9366 Defining_Identifier =>
9367 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9368 Label_Construct => Lab));
9371 end Make_And_Declare_Label;
9373 ----------------------
9374 -- Make_Select_Call --
9375 ----------------------
9377 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9378 Params : constant List_Id := New_List;
9382 Make_Attribute_Reference (Loc,
9383 Prefix => New_Reference_To (Qnam, Loc),
9384 Attribute_Name => Name_Unchecked_Access),
9386 Append (Select_Mode, Params);
9387 Append (New_Reference_To (Ann, Loc), Params);
9388 Append (New_Reference_To (Xnam, Loc), Params);
9391 Make_Procedure_Call_Statement (Loc,
9392 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9393 Parameter_Associations => Params);
9394 end Make_Select_Call;
9396 --------------------------------
9397 -- Process_Accept_Alternative --
9398 --------------------------------
9400 procedure Process_Accept_Alternative
9405 Choices : List_Id := No_List;
9406 Alt_Stats : List_Id;
9409 Adjust_Condition (Condition (Alt));
9410 Alt_Stats := No_List;
9412 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9413 Choices := New_List (
9414 Make_Integer_Literal (Loc, Index));
9416 Alt_Stats := New_List (
9417 Make_Procedure_Call_Statement (Sloc (Proc),
9418 Name => New_Reference_To (
9419 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9422 if Statements (Alt) /= Empty_List then
9424 if No (Alt_Stats) then
9426 -- Accept with no body, followed by trailing statements
9428 Choices := New_List (
9429 Make_Integer_Literal (Loc, Index));
9431 Alt_Stats := New_List;
9434 -- After the call, if any, branch to trailing statements. We
9435 -- create a label for each, as well as the corresponding label
9438 Lab := Make_And_Declare_Label (Index);
9439 Append_To (Alt_Stats,
9440 Make_Goto_Statement (Loc,
9441 Name => New_Copy (Identifier (Lab))));
9443 Append (Lab, Trailing_List);
9444 Append_List (Statements (Alt), Trailing_List);
9445 Append_To (Trailing_List,
9446 Make_Goto_Statement (Loc,
9447 Name => New_Copy (Identifier (End_Lab))));
9450 if Present (Alt_Stats) then
9452 -- Procedure call. and/or trailing statements
9454 Append_To (Alt_List,
9455 Make_Case_Statement_Alternative (Loc,
9456 Discrete_Choices => Choices,
9457 Statements => Alt_Stats));
9459 end Process_Accept_Alternative;
9461 -------------------------------
9462 -- Process_Delay_Alternative --
9463 -------------------------------
9465 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9468 Delay_Alt : List_Id;
9471 -- Deal with C/Fortran boolean as delay condition
9473 Adjust_Condition (Condition (Alt));
9475 -- Determine the smallest specified delay
9477 -- for each delay alternative generate:
9479 -- if guard-expression then
9480 -- Delay_Val := delay-expression;
9481 -- Guard_Open := True;
9482 -- if Delay_Val < Delay_Min then
9483 -- Delay_Min := Delay_Val;
9484 -- Delay_Index := Index;
9488 -- The enclosing if-statement is omitted if there is no guard
9493 First_Delay := False;
9495 Delay_Alt := New_List (
9496 Make_Assignment_Statement (Loc,
9497 Name => New_Reference_To (Delay_Min, Loc),
9498 Expression => Expression (Delay_Statement (Alt))));
9500 if Delay_Count > 1 then
9501 Append_To (Delay_Alt,
9502 Make_Assignment_Statement (Loc,
9503 Name => New_Reference_To (Delay_Index, Loc),
9504 Expression => Make_Integer_Literal (Loc, Index)));
9508 Delay_Alt := New_List (
9509 Make_Assignment_Statement (Loc,
9510 Name => New_Reference_To (Delay_Val, Loc),
9511 Expression => Expression (Delay_Statement (Alt))));
9513 if Time_Type = Standard_Duration then
9516 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9517 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9520 -- The scope of the time type must define a comparison
9521 -- operator. The scope itself may not be visible, so we
9522 -- construct a node with entity information to insure that
9523 -- semantic analysis can find the proper operator.
9526 Make_Function_Call (Loc,
9527 Name => Make_Selected_Component (Loc,
9528 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9530 Make_Operator_Symbol (Loc,
9531 Chars => Name_Op_Lt,
9532 Strval => No_String)),
9533 Parameter_Associations =>
9535 New_Reference_To (Delay_Val, Loc),
9536 New_Reference_To (Delay_Min, Loc)));
9538 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9541 Append_To (Delay_Alt,
9542 Make_Implicit_If_Statement (N,
9544 Then_Statements => New_List (
9545 Make_Assignment_Statement (Loc,
9546 Name => New_Reference_To (Delay_Min, Loc),
9547 Expression => New_Reference_To (Delay_Val, Loc)),
9549 Make_Assignment_Statement (Loc,
9550 Name => New_Reference_To (Delay_Index, Loc),
9551 Expression => Make_Integer_Literal (Loc, Index)))));
9555 Append_To (Delay_Alt,
9556 Make_Assignment_Statement (Loc,
9557 Name => New_Reference_To (Guard_Open, Loc),
9558 Expression => New_Reference_To (Standard_True, Loc)));
9561 if Present (Condition (Alt)) then
9562 Delay_Alt := New_List (
9563 Make_Implicit_If_Statement (N,
9564 Condition => Condition (Alt),
9565 Then_Statements => Delay_Alt));
9568 Append_List (Delay_Alt, Delay_List);
9570 -- If the delay alternative has a statement part, add choice to the
9571 -- case statements for delays.
9573 if Present (Statements (Alt)) then
9575 if Delay_Count = 1 then
9576 Append_List (Statements (Alt), Delay_Alt_List);
9579 Choices := New_List (
9580 Make_Integer_Literal (Loc, Index));
9582 Append_To (Delay_Alt_List,
9583 Make_Case_Statement_Alternative (Loc,
9584 Discrete_Choices => Choices,
9585 Statements => Statements (Alt)));
9588 elsif Delay_Count = 1 then
9590 -- If the single delay has no trailing statements, add a branch
9591 -- to the exit label to the selective wait.
9593 Delay_Alt_List := New_List (
9594 Make_Goto_Statement (Loc,
9595 Name => New_Copy (Identifier (End_Lab))));
9598 end Process_Delay_Alternative;
9600 -- Start of processing for Expand_N_Selective_Accept
9603 -- First insert some declarations before the select. The first is:
9607 -- This variable holds the parameters passed to the accept body. This
9608 -- declaration has already been inserted by the time we get here by
9609 -- a call to Expand_Accept_Declarations made from the semantics when
9610 -- processing the first accept statement contained in the select. We
9611 -- can find this entity as Accept_Address (E), where E is any of the
9612 -- entries references by contained accept statements.
9614 -- The first step is to scan the list of Selective_Accept_Statements
9615 -- to find this entity, and also count the number of accepts, and
9616 -- determine if terminated, delay or else is present:
9620 Alt := First (Alts);
9621 while Present (Alt) loop
9623 if Nkind (Alt) = N_Accept_Alternative then
9626 elsif Nkind (Alt) = N_Delay_Alternative then
9627 Delay_Count := Delay_Count + 1;
9629 -- If the delays are relative delays, the delay expressions have
9630 -- type Standard_Duration. Otherwise they must have some time type
9631 -- recognized by GNAT.
9633 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9634 Time_Type := Standard_Duration;
9636 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9638 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9639 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9644 "& is not a time type (RM 9.6(6))",
9645 Expression (Delay_Statement (Alt)), Time_Type);
9646 Time_Type := Standard_Duration;
9647 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9651 if No (Condition (Alt)) then
9653 -- This guard will always be open
9655 Check_Guard := False;
9658 elsif Nkind (Alt) = N_Terminate_Alternative then
9659 Adjust_Condition (Condition (Alt));
9660 Terminate_Alt := Alt;
9663 Num_Alts := Num_Alts + 1;
9667 Else_Present := Present (Else_Statements (N));
9669 -- At the same time (see procedure Add_Accept) we build the accept list:
9671 -- Qnn : Accept_List (1 .. num-select) := (
9672 -- (null-body, entry-index),
9673 -- (null-body, entry-index),
9675 -- (null_body, entry-index));
9677 -- In the above declaration, null-body is True if the corresponding
9678 -- accept has no body, and false otherwise. The entry is either the
9679 -- entry index expression if there is no guard, or if a guard is
9680 -- present, then a conditional expression of the form:
9682 -- (if guard then entry-index else Null_Task_Entry)
9684 -- If a guard is statically known to be false, the entry can simply
9685 -- be omitted from the accept list.
9688 Make_Object_Declaration (Loc,
9689 Defining_Identifier => Qnam,
9690 Object_Definition =>
9691 New_Reference_To (RTE (RE_Accept_List), Loc),
9692 Aliased_Present => True,
9695 Make_Qualified_Expression (Loc,
9697 New_Reference_To (RTE (RE_Accept_List), Loc),
9699 Make_Aggregate (Loc, Expressions => Accept_List)));
9703 -- Then we declare the variable that holds the index for the accept
9704 -- that will be selected for service:
9706 -- Xnn : Select_Index;
9709 Make_Object_Declaration (Loc,
9710 Defining_Identifier => Xnam,
9711 Object_Definition =>
9712 New_Reference_To (RTE (RE_Select_Index), Loc),
9714 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9718 -- After this follow procedure declarations for each accept body
9725 -- where the ... are statements from the corresponding procedure body.
9726 -- No parameters are involved, since the parameters are passed via Ann
9727 -- and the parameter references have already been expanded to be direct
9728 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9729 -- any embedded tasking statements (which would normally be illegal in
9730 -- procedures), have been converted to calls to the tasking runtime so
9731 -- there is no problem in putting them into procedures.
9733 -- The original accept statement has been expanded into a block in
9734 -- the same fashion as for simple accepts (see Build_Accept_Body).
9736 -- Note: we don't really need to build these procedures for the case
9737 -- where no delay statement is present, but it is just as easy to
9738 -- build them unconditionally, and not significantly inefficient,
9739 -- since if they are short they will be inlined anyway.
9741 -- The procedure declarations have been assembled in Body_List
9743 -- If delays are present, we must compute the required delay.
9744 -- We first generate the declarations:
9746 -- Delay_Index : Boolean := 0;
9747 -- Delay_Min : Some_Time_Type.Time;
9748 -- Delay_Val : Some_Time_Type.Time;
9750 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9751 -- active delay that is actually chosen as the basis for the possible
9752 -- delay if an immediate rendez-vous is not possible.
9754 -- In the most common case there is a single delay statement, and this
9755 -- is handled specially.
9757 if Delay_Count > 0 then
9759 -- Generate the required declarations
9762 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9764 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9766 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9769 Make_Object_Declaration (Loc,
9770 Defining_Identifier => Delay_Val,
9771 Object_Definition => New_Reference_To (Time_Type, Loc)));
9774 Make_Object_Declaration (Loc,
9775 Defining_Identifier => Delay_Index,
9776 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9777 Expression => Make_Integer_Literal (Loc, 0)));
9780 Make_Object_Declaration (Loc,
9781 Defining_Identifier => Delay_Min,
9782 Object_Definition => New_Reference_To (Time_Type, Loc),
9784 Unchecked_Convert_To (Time_Type,
9785 Make_Attribute_Reference (Loc,
9787 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9788 Attribute_Name => Name_Last))));
9790 -- Create Duration and Delay_Mode objects used for passing a delay
9793 D := Make_Temporary (Loc, 'D');
9794 M := Make_Temporary (Loc, 'M');
9800 -- Note that these values are defined in s-osprim.ads and must
9803 -- Relative : constant := 0;
9804 -- Absolute_Calendar : constant := 1;
9805 -- Absolute_RT : constant := 2;
9807 if Time_Type = Standard_Duration then
9808 Discr := Make_Integer_Literal (Loc, 0);
9810 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9811 Discr := Make_Integer_Literal (Loc, 1);
9815 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9816 Discr := Make_Integer_Literal (Loc, 2);
9820 Make_Object_Declaration (Loc,
9821 Defining_Identifier => D,
9822 Object_Definition =>
9823 New_Reference_To (Standard_Duration, Loc)));
9826 Make_Object_Declaration (Loc,
9827 Defining_Identifier => M,
9828 Object_Definition =>
9829 New_Reference_To (Standard_Integer, Loc),
9830 Expression => Discr));
9835 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9838 Make_Object_Declaration (Loc,
9839 Defining_Identifier => Guard_Open,
9840 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9841 Expression => New_Reference_To (Standard_False, Loc)));
9844 -- Delay_Count is zero, don't need M and D set (suppress warning)
9851 if Present (Terminate_Alt) then
9853 -- If the terminate alternative guard is False, use
9854 -- Simple_Mode; otherwise use Terminate_Mode.
9856 if Present (Condition (Terminate_Alt)) then
9857 Select_Mode := Make_Conditional_Expression (Loc,
9858 New_List (Condition (Terminate_Alt),
9859 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9860 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9862 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9865 elsif Else_Present or Delay_Count > 0 then
9866 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9869 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9872 Select_Call := Make_Select_Call (Select_Mode);
9873 Append (Select_Call, Stats);
9875 -- Now generate code to act on the result. There is an entry
9876 -- in this case for each accept statement with a non-null body,
9877 -- followed by a branch to the statements that follow the Accept.
9878 -- In the absence of delay alternatives, we generate:
9881 -- when No_Rendezvous => -- omitted if simple mode
9896 -- Lab0: Else_Statements;
9899 -- Lab1: Trailing_Statements1;
9902 -- Lab2: Trailing_Statements2;
9907 -- Generate label for common exit
9909 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9911 -- First entry is the default case, when no rendezvous is possible
9913 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9915 if Else_Present then
9917 -- If no rendezvous is possible, the else part is executed
9919 Lab := Make_And_Declare_Label (0);
9920 Alt_Stats := New_List (
9921 Make_Goto_Statement (Loc,
9922 Name => New_Copy (Identifier (Lab))));
9924 Append (Lab, Trailing_List);
9925 Append_List (Else_Statements (N), Trailing_List);
9926 Append_To (Trailing_List,
9927 Make_Goto_Statement (Loc,
9928 Name => New_Copy (Identifier (End_Lab))));
9930 Alt_Stats := New_List (
9931 Make_Goto_Statement (Loc,
9932 Name => New_Copy (Identifier (End_Lab))));
9935 Append_To (Alt_List,
9936 Make_Case_Statement_Alternative (Loc,
9937 Discrete_Choices => Choices,
9938 Statements => Alt_Stats));
9940 -- We make use of the fact that Accept_Index is an integer type, and
9941 -- generate successive literals for entries for each accept. Only those
9942 -- for which there is a body or trailing statements get a case entry.
9944 Alt := First (Select_Alternatives (N));
9945 Proc := First (Body_List);
9946 while Present (Alt) loop
9948 if Nkind (Alt) = N_Accept_Alternative then
9949 Process_Accept_Alternative (Alt, Index, Proc);
9953 (Handled_Statement_Sequence (Accept_Statement (Alt)))
9958 elsif Nkind (Alt) = N_Delay_Alternative then
9959 Process_Delay_Alternative (Alt, Delay_Num);
9960 Delay_Num := Delay_Num + 1;
9966 -- An others choice is always added to the main case, as well
9967 -- as the delay case (to satisfy the compiler).
9969 Append_To (Alt_List,
9970 Make_Case_Statement_Alternative (Loc,
9972 New_List (Make_Others_Choice (Loc)),
9974 New_List (Make_Goto_Statement (Loc,
9975 Name => New_Copy (Identifier (End_Lab))))));
9977 Accept_Case := New_List (
9978 Make_Case_Statement (Loc,
9979 Expression => New_Reference_To (Xnam, Loc),
9980 Alternatives => Alt_List));
9982 Append_List (Trailing_List, Accept_Case);
9983 Append (End_Lab, Accept_Case);
9984 Append_List (Body_List, Decls);
9986 -- Construct case statement for trailing statements of delay
9987 -- alternatives, if there are several of them.
9989 if Delay_Count > 1 then
9990 Append_To (Delay_Alt_List,
9991 Make_Case_Statement_Alternative (Loc,
9993 New_List (Make_Others_Choice (Loc)),
9995 New_List (Make_Null_Statement (Loc))));
9997 Delay_Case := New_List (
9998 Make_Case_Statement (Loc,
9999 Expression => New_Reference_To (Delay_Index, Loc),
10000 Alternatives => Delay_Alt_List));
10002 Delay_Case := Delay_Alt_List;
10005 -- If there are no delay alternatives, we append the case statement
10006 -- to the statement list.
10008 if Delay_Count = 0 then
10009 Append_List (Accept_Case, Stats);
10011 -- Delay alternatives present
10014 -- If delay alternatives are present we generate:
10016 -- find minimum delay.
10017 -- DX := minimum delay;
10018 -- M := <delay mode>;
10019 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10022 -- if X = No_Rendezvous then
10023 -- case statement for delay statements.
10025 -- case statement for accept alternatives.
10036 -- The type of the delay expression is known to be legal
10038 if Time_Type = Standard_Duration then
10039 Conv := New_Reference_To (Delay_Min, Loc);
10041 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10042 Conv := Make_Function_Call (Loc,
10043 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10044 New_List (New_Reference_To (Delay_Min, Loc)));
10048 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10050 Conv := Make_Function_Call (Loc,
10051 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10052 New_List (New_Reference_To (Delay_Min, Loc)));
10055 Stmt := Make_Assignment_Statement (Loc,
10056 Name => New_Reference_To (D, Loc),
10057 Expression => Conv);
10059 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10061 Parms := Parameter_Associations (Select_Call);
10062 Parm := First (Parms);
10064 while Present (Parm)
10065 and then Parm /= Select_Mode
10070 pragma Assert (Present (Parm));
10071 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10074 -- Prepare two new parameters of Duration and Delay_Mode type
10075 -- which represent the value and the mode of the minimum delay.
10078 Insert_After (Parm, New_Reference_To (M, Loc));
10079 Insert_After (Parm, New_Reference_To (D, Loc));
10081 -- Create a call to RTS
10083 Rewrite (Select_Call,
10084 Make_Procedure_Call_Statement (Loc,
10085 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10086 Parameter_Associations => Parms));
10088 -- This new call should follow the calculation of the minimum
10091 Insert_List_Before (Select_Call, Delay_List);
10093 if Check_Guard then
10095 Make_Implicit_If_Statement (N,
10096 Condition => New_Reference_To (Guard_Open, Loc),
10098 New_List (New_Copy_Tree (Stmt),
10099 New_Copy_Tree (Select_Call)),
10100 Else_Statements => Accept_Or_Raise);
10101 Rewrite (Select_Call, Stmt);
10103 Insert_Before (Select_Call, Stmt);
10107 Make_Implicit_If_Statement (N,
10108 Condition => Make_Op_Eq (Loc,
10109 Left_Opnd => New_Reference_To (Xnam, Loc),
10111 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10113 Then_Statements => Delay_Case,
10114 Else_Statements => Accept_Case);
10116 Append (Cases, Stats);
10120 -- Replace accept statement with appropriate block
10123 Make_Block_Statement (Loc,
10124 Declarations => Decls,
10125 Handled_Statement_Sequence =>
10126 Make_Handled_Sequence_Of_Statements (Loc,
10127 Statements => Stats));
10129 Rewrite (N, Block);
10132 -- Note: have to worry more about abort deferral in above code ???
10134 -- Final step is to unstack the Accept_Address entries for all accept
10135 -- statements appearing in accept alternatives in the select statement
10137 Alt := First (Alts);
10138 while Present (Alt) loop
10139 if Nkind (Alt) = N_Accept_Alternative then
10140 Remove_Last_Elmt (Accept_Address
10141 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10146 end Expand_N_Selective_Accept;
10148 --------------------------------------
10149 -- Expand_N_Single_Task_Declaration --
10150 --------------------------------------
10152 -- Single task declarations should never be present after semantic
10153 -- analysis, since we expect them to be replaced by a declaration of an
10154 -- anonymous task type, followed by a declaration of the task object. We
10155 -- include this routine to make sure that is happening!
10157 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10159 raise Program_Error;
10160 end Expand_N_Single_Task_Declaration;
10162 ------------------------
10163 -- Expand_N_Task_Body --
10164 ------------------------
10166 -- Given a task body
10168 -- task body tname is
10174 -- This expansion routine converts it into a procedure and sets the
10175 -- elaboration flag for the procedure to true, to represent the fact
10176 -- that the task body is now elaborated:
10178 -- procedure tnameB (_Task : access tnameV) is
10179 -- discriminal : dtype renames _Task.discriminant;
10181 -- procedure _clean is
10183 -- Abort_Defer.all;
10185 -- Abort_Undefer.all;
10190 -- Abort_Undefer.all;
10192 -- System.Task_Stages.Complete_Activation;
10200 -- In addition, if the task body is an activator, then a call to activate
10201 -- tasks is added at the start of the statements, before the call to
10202 -- Complete_Activation, and if in addition the task is a master then it
10203 -- must be established as a master. These calls are inserted and analyzed
10204 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10207 -- There is one discriminal declaration line generated for each
10208 -- discriminant that is present to provide an easy reference point for
10209 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10211 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10212 -- task body procedures have a profile (Arg : System.Address). That is
10213 -- needed because GNARLI has to use the same access-to-subprogram type
10214 -- for all task types. We depend here on knowing that in GNAT, passing
10215 -- an address argument by value is identical to passing a record value
10216 -- by access (in either case a single pointer is passed), so even though
10217 -- this procedure has the wrong profile. In fact it's all OK, since the
10218 -- callings sequence is identical.
10220 procedure Expand_N_Task_Body (N : Node_Id) is
10221 Loc : constant Source_Ptr := Sloc (N);
10222 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10226 Insert_Nod : Node_Id;
10227 -- Used to determine the proper location of wrapper body insertions
10230 -- Add renaming declarations for discriminals and a declaration for the
10231 -- entry family index (if applicable).
10233 Install_Private_Data_Declarations
10234 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10236 -- Add a call to Abort_Undefer at the very beginning of the task
10237 -- body since this body is called with abort still deferred.
10239 if Abort_Allowed then
10240 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10242 (First (Statements (Handled_Statement_Sequence (N))), Call);
10246 -- The statement part has already been protected with an at_end and
10247 -- cleanup actions. The call to Complete_Activation must be placed
10248 -- at the head of the sequence of statements of that block. The
10249 -- declarations have been merged in this sequence of statements but
10250 -- the first real statement is accessible from the First_Real_Statement
10251 -- field (which was set for exactly this purpose).
10253 if Restricted_Profile then
10254 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10256 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10260 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10264 Make_Subprogram_Body (Loc,
10265 Specification => Build_Task_Proc_Specification (Ttyp),
10266 Declarations => Declarations (N),
10267 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10269 -- If the task contains generic instantiations, cleanup actions are
10270 -- delayed until after instantiation. Transfer the activation chain to
10271 -- the subprogram, to insure that the activation call is properly
10272 -- generated. It the task body contains inner tasks, indicate that the
10273 -- subprogram is a task master.
10275 if Delay_Cleanups (Ttyp) then
10276 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10277 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10280 Rewrite (N, New_N);
10283 -- Set elaboration flag immediately after task body. If the body is a
10284 -- subunit, the flag is set in the declarative part containing the stub.
10286 if Nkind (Parent (N)) /= N_Subunit then
10288 Make_Assignment_Statement (Loc,
10290 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10291 Expression => New_Reference_To (Standard_True, Loc)));
10294 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10295 -- the task body. At this point all wrapper specs have been created,
10296 -- frozen and included in the dispatch table for the task type.
10298 if Ada_Version >= Ada_2005 then
10299 if Nkind (Parent (N)) = N_Subunit then
10300 Insert_Nod := Corresponding_Stub (Parent (N));
10305 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10307 end Expand_N_Task_Body;
10309 ------------------------------------
10310 -- Expand_N_Task_Type_Declaration --
10311 ------------------------------------
10313 -- We have several things to do. First we must create a Boolean flag used
10314 -- to mark if the body is elaborated yet. This variable gets set to True
10315 -- when the body of the task is elaborated (we can't rely on the normal
10316 -- ABE mechanism for the task body, since we need to pass an access to
10317 -- this elaboration boolean to the runtime routines).
10319 -- taskE : aliased Boolean := False;
10321 -- Next a variable is declared to hold the task stack size (either the
10322 -- default : Unspecified_Size, or a value that is set by a pragma
10323 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10324 -- the variable is initialized with this value:
10326 -- taskZ : Size_Type := Unspecified_Size;
10328 -- taskZ : Size_Type := Size_Type (size_expression);
10330 -- Note: No variable is needed to hold the task relative deadline since
10331 -- its value would never be static because the parameter is of a private
10332 -- type (Ada.Real_Time.Time_Span).
10334 -- Next we create a corresponding record type declaration used to represent
10335 -- values of this task. The general form of this type declaration is
10337 -- type taskV (discriminants) is record
10338 -- _Task_Id : Task_Id;
10339 -- entry_family : array (bounds) of Void;
10340 -- _Priority : Integer := priority_expression;
10341 -- _Size : Size_Type := Size_Type (size_expression);
10342 -- _Task_Info : Task_Info_Type := task_info_expression;
10343 -- _CPU : Integer := cpu_range_expression;
10346 -- The discriminants are present only if the corresponding task type has
10347 -- discriminants, and they exactly mirror the task type discriminants.
10349 -- The Id field is always present. It contains the Task_Id value, as set by
10350 -- the call to Create_Task. Note that although the task is limited, the
10351 -- task value record type is not limited, so there is no problem in passing
10352 -- this field as an out parameter to Create_Task.
10354 -- One entry_family component is present for each entry family in the task
10355 -- definition. The bounds correspond to the bounds of the entry family
10356 -- (which may depend on discriminants). The element type is void, since we
10357 -- only need the bounds information for determining the entry index. Note
10358 -- that the use of an anonymous array would normally be illegal in this
10359 -- context, but this is a parser check, and the semantics is quite prepared
10360 -- to handle such a case.
10362 -- The _Size field is present only if a Storage_Size pragma appears in the
10363 -- task definition. The expression captures the argument that was present
10364 -- in the pragma, and is used to override the task stack size otherwise
10365 -- associated with the task type.
10367 -- The _Priority field is present only if a Priority or Interrupt_Priority
10368 -- pragma appears in the task definition. The expression captures the
10369 -- argument that was present in the pragma, and is used to provide the Size
10370 -- parameter to the call to Create_Task.
10372 -- The _Task_Info field is present only if a Task_Info pragma appears in
10373 -- the task definition. The expression captures the argument that was
10374 -- present in the pragma, and is used to provide the Task_Image parameter
10375 -- to the call to Create_Task.
10377 -- The _CPU field is present only if a CPU pragma appears in the task
10378 -- definition. The expression captures the argument that was present in
10379 -- the pragma, and is used to provide the CPU parameter to the call to
10382 -- The _Relative_Deadline field is present only if a Relative_Deadline
10383 -- pragma appears in the task definition. The expression captures the
10384 -- argument that was present in the pragma, and is used to provide the
10385 -- Relative_Deadline parameter to the call to Create_Task.
10387 -- When a task is declared, an instance of the task value record is
10388 -- created. The elaboration of this declaration creates the correct bounds
10389 -- for the entry families, and also evaluates the size, priority, and
10390 -- task_Info expressions if needed. The initialization routine for the task
10391 -- type itself then calls Create_Task with appropriate parameters to
10392 -- initialize the value of the Task_Id field.
10394 -- Note: the address of this record is passed as the "Discriminants"
10395 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10396 -- body procedure, it does not matter that it does not quite match the
10397 -- GNARLI model of what is being passed (the record contains more than just
10398 -- the discriminants, but the discriminants can be found from the record
10401 -- The Entity_Id for this created record type is placed in the
10402 -- Corresponding_Record_Type field of the associated task type entity.
10404 -- Next we create a procedure specification for the task body procedure:
10406 -- procedure taskB (_Task : access taskV);
10408 -- Note that this must come after the record type declaration, since
10409 -- the spec refers to this type. It turns out that the initialization
10410 -- procedure for the value type references the task body spec, but that's
10411 -- fine, since it won't be generated till the freeze point for the type,
10412 -- which is certainly after the task body spec declaration.
10414 -- Finally, we set the task index value field of the entry attribute in
10415 -- the case of a simple entry.
10417 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10418 Loc : constant Source_Ptr := Sloc (N);
10419 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10420 Tasknm : constant Name_Id := Chars (Tasktyp);
10421 Taskdef : constant Node_Id := Task_Definition (N);
10423 Proc_Spec : Node_Id;
10424 Rec_Decl : Node_Id;
10425 Rec_Ent : Entity_Id;
10427 Elab_Decl : Node_Id;
10428 Size_Decl : Node_Id;
10429 Body_Decl : Node_Id;
10430 Task_Size : Node_Id;
10431 Ent_Stack : Entity_Id;
10432 Decl_Stack : Node_Id;
10435 -- If already expanded, nothing to do
10437 if Present (Corresponding_Record_Type (Tasktyp)) then
10441 -- Here we will do the expansion
10443 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10445 Rec_Ent := Defining_Identifier (Rec_Decl);
10446 Cdecls := Component_Items (Component_List
10447 (Type_Definition (Rec_Decl)));
10449 Qualify_Entity_Names (N);
10451 -- First create the elaboration variable
10454 Make_Object_Declaration (Loc,
10455 Defining_Identifier =>
10456 Make_Defining_Identifier (Sloc (Tasktyp),
10457 Chars => New_External_Name (Tasknm, 'E')),
10458 Aliased_Present => True,
10459 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10460 Expression => New_Reference_To (Standard_False, Loc));
10461 Insert_After (N, Elab_Decl);
10463 -- Next create the declaration of the size variable (tasknmZ)
10465 Set_Storage_Size_Variable (Tasktyp,
10466 Make_Defining_Identifier (Sloc (Tasktyp),
10467 Chars => New_External_Name (Tasknm, 'Z')));
10469 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
10470 Is_Static_Expression (Expression (First (
10471 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
10472 Taskdef, Name_Storage_Size)))))
10475 Make_Object_Declaration (Loc,
10476 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10477 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10479 Convert_To (RTE (RE_Size_Type),
10481 Expression (First (
10482 Pragma_Argument_Associations (
10483 Find_Task_Or_Protected_Pragma
10484 (Taskdef, Name_Storage_Size)))))));
10488 Make_Object_Declaration (Loc,
10489 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10490 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10491 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10494 Insert_After (Elab_Decl, Size_Decl);
10496 -- Next build the rest of the corresponding record declaration. This is
10497 -- done last, since the corresponding record initialization procedure
10498 -- will reference the previously created entities.
10500 -- Fill in the component declarations -- first the _Task_Id field
10503 Make_Component_Declaration (Loc,
10504 Defining_Identifier =>
10505 Make_Defining_Identifier (Loc, Name_uTask_Id),
10506 Component_Definition =>
10507 Make_Component_Definition (Loc,
10508 Aliased_Present => False,
10509 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10512 -- Declare static ATCB (that is, created by the expander) if we are
10513 -- using the Restricted run time.
10515 if Restricted_Profile then
10517 Make_Component_Declaration (Loc,
10518 Defining_Identifier =>
10519 Make_Defining_Identifier (Loc, Name_uATCB),
10521 Component_Definition =>
10522 Make_Component_Definition (Loc,
10523 Aliased_Present => True,
10524 Subtype_Indication => Make_Subtype_Indication (Loc,
10525 Subtype_Mark => New_Occurrence_Of
10526 (RTE (RE_Ada_Task_Control_Block), Loc),
10529 Make_Index_Or_Discriminant_Constraint (Loc,
10531 New_List (Make_Integer_Literal (Loc, 0)))))));
10535 -- Declare static stack (that is, created by the expander) if we are
10536 -- using the Restricted run time on a bare board configuration.
10538 if Restricted_Profile
10539 and then Preallocated_Stacks_On_Target
10541 -- First we need to extract the appropriate stack size
10543 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10545 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10547 Expr_N : constant Node_Id :=
10548 Expression (First (
10549 Pragma_Argument_Associations (
10550 Find_Task_Or_Protected_Pragma
10551 (Taskdef, Name_Storage_Size))));
10552 Etyp : constant Entity_Id := Etype (Expr_N);
10553 P : constant Node_Id := Parent (Expr_N);
10556 -- The stack is defined inside the corresponding record.
10557 -- Therefore if the size of the stack is set by means of
10558 -- a discriminant, we must reference the discriminant of the
10559 -- corresponding record type.
10561 if Nkind (Expr_N) in N_Has_Entity
10562 and then Present (Discriminal_Link (Entity (Expr_N)))
10566 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10568 Set_Parent (Task_Size, P);
10569 Set_Etype (Task_Size, Etyp);
10570 Set_Analyzed (Task_Size);
10573 Task_Size := Relocate_Node (Expr_N);
10579 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10582 Decl_Stack := Make_Component_Declaration (Loc,
10583 Defining_Identifier => Ent_Stack,
10585 Component_Definition =>
10586 Make_Component_Definition (Loc,
10587 Aliased_Present => True,
10588 Subtype_Indication => Make_Subtype_Indication (Loc,
10590 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10593 Make_Index_Or_Discriminant_Constraint (Loc,
10594 Constraints => New_List (Make_Range (Loc,
10595 Low_Bound => Make_Integer_Literal (Loc, 1),
10596 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10599 Append_To (Cdecls, Decl_Stack);
10601 -- The appropriate alignment for the stack is ensured by the run-time
10602 -- code in charge of task creation.
10606 -- Add components for entry families
10608 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10610 -- Add the _Priority component if a Priority pragma is present
10612 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10614 Prag : constant Node_Id :=
10615 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10619 Expr := First (Pragma_Argument_Associations (Prag));
10621 if Nkind (Expr) = N_Pragma_Argument_Association then
10622 Expr := Expression (Expr);
10625 Expr := New_Copy_Tree (Expr);
10627 -- Add conversion to proper type to do range check if required
10628 -- Note that for runtime units, we allow out of range interrupt
10629 -- priority values to be used in a priority pragma. This is for
10630 -- the benefit of some versions of System.Interrupts which use
10631 -- a special server task with maximum interrupt priority.
10633 if Pragma_Name (Prag) = Name_Priority
10634 and then not GNAT_Mode
10636 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10638 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10642 Make_Component_Declaration (Loc,
10643 Defining_Identifier =>
10644 Make_Defining_Identifier (Loc, Name_uPriority),
10645 Component_Definition =>
10646 Make_Component_Definition (Loc,
10647 Aliased_Present => False,
10648 Subtype_Indication => New_Reference_To (Standard_Integer,
10650 Expression => Expr));
10654 -- Add the _Task_Size component if a Storage_Size pragma is present
10656 if Present (Taskdef)
10657 and then Has_Storage_Size_Pragma (Taskdef)
10660 Make_Component_Declaration (Loc,
10661 Defining_Identifier =>
10662 Make_Defining_Identifier (Loc, Name_uSize),
10664 Component_Definition =>
10665 Make_Component_Definition (Loc,
10666 Aliased_Present => False,
10667 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10671 Convert_To (RTE (RE_Size_Type),
10673 Expression (First (
10674 Pragma_Argument_Associations (
10675 Find_Task_Or_Protected_Pragma
10676 (Taskdef, Name_Storage_Size))))))));
10679 -- Add the _Task_Info component if a Task_Info pragma is present
10681 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10683 Make_Component_Declaration (Loc,
10684 Defining_Identifier =>
10685 Make_Defining_Identifier (Loc, Name_uTask_Info),
10687 Component_Definition =>
10688 Make_Component_Definition (Loc,
10689 Aliased_Present => False,
10690 Subtype_Indication =>
10691 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10693 Expression => New_Copy (
10694 Expression (First (
10695 Pragma_Argument_Associations (
10696 Find_Task_Or_Protected_Pragma
10697 (Taskdef, Name_Task_Info)))))));
10700 -- Add the _CPU component if a CPU pragma is present
10702 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
10704 Make_Component_Declaration (Loc,
10705 Defining_Identifier =>
10706 Make_Defining_Identifier (Loc, Name_uCPU),
10708 Component_Definition =>
10709 Make_Component_Definition (Loc,
10710 Aliased_Present => False,
10711 Subtype_Indication =>
10712 New_Reference_To (RTE (RE_CPU_Range), Loc)),
10714 Expression => New_Copy (
10715 Expression (First (
10716 Pragma_Argument_Associations (
10717 Find_Task_Or_Protected_Pragma
10718 (Taskdef, Name_CPU)))))));
10721 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10722 -- present. If we are using a restricted run time this component will
10723 -- not be added (deadlines are not allowed by the Ravenscar profile).
10725 if not Restricted_Profile
10726 and then Present (Taskdef)
10727 and then Has_Relative_Deadline_Pragma (Taskdef)
10730 Make_Component_Declaration (Loc,
10731 Defining_Identifier =>
10732 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10734 Component_Definition =>
10735 Make_Component_Definition (Loc,
10736 Aliased_Present => False,
10737 Subtype_Indication =>
10738 New_Reference_To (RTE (RE_Time_Span), Loc)),
10741 Convert_To (RTE (RE_Time_Span),
10743 Expression (First (
10744 Pragma_Argument_Associations (
10745 Find_Task_Or_Protected_Pragma
10746 (Taskdef, Name_Relative_Deadline))))))));
10749 Insert_After (Size_Decl, Rec_Decl);
10751 -- Analyze the record declaration immediately after construction,
10752 -- because the initialization procedure is needed for single task
10753 -- declarations before the next entity is analyzed.
10755 Analyze (Rec_Decl);
10757 -- Create the declaration of the task body procedure
10759 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10761 Make_Subprogram_Declaration (Loc,
10762 Specification => Proc_Spec);
10764 Insert_After (Rec_Decl, Body_Decl);
10766 -- The subprogram does not comes from source, so we have to indicate the
10767 -- need for debugging information explicitly.
10769 if Comes_From_Source (Original_Node (N)) then
10770 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10773 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10774 -- the corresponding record has been frozen.
10776 if Ada_Version >= Ada_2005 then
10777 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10780 -- Ada 2005 (AI-345): We must defer freezing to allow further
10781 -- declaration of primitive subprograms covering task interfaces
10783 if Ada_Version <= Ada_95 then
10785 -- Now we can freeze the corresponding record. This needs manually
10786 -- freezing, since it is really part of the task type, and the task
10787 -- type is frozen at this stage. We of course need the initialization
10788 -- procedure for this corresponding record type and we won't get it
10789 -- in time if we don't freeze now.
10792 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
10794 if Is_Non_Empty_List (L) then
10795 Insert_List_After (Body_Decl, L);
10800 -- Complete the expansion of access types to the current task type, if
10801 -- any were declared.
10803 Expand_Previous_Access_Type (Tasktyp);
10805 -- Create wrappers for entries that have pre/postconditions
10811 Ent := First_Entity (Tasktyp);
10812 while Present (Ent) loop
10813 if Ekind_In (Ent, E_Entry, E_Entry_Family)
10814 and then Present (Spec_PPC_List (Ent))
10816 Build_PPC_Wrapper (Ent, N);
10822 end Expand_N_Task_Type_Declaration;
10824 -------------------------------
10825 -- Expand_N_Timed_Entry_Call --
10826 -------------------------------
10828 -- A timed entry call in normal case is not implemented using ATC mechanism
10829 -- anymore for efficiency reason.
10839 -- is expanded as follow:
10841 -- 1) When T.E is a task entry_call;
10845 -- X : Task_Entry_Index := <entry index>;
10846 -- DX : Duration := To_Duration (D);
10847 -- M : Delay_Mode := <discriminant>;
10848 -- P : parms := (parm, parm, parm);
10851 -- Timed_Protected_Entry_Call
10852 -- (<acceptor-task>, X, P'Address, DX, M, B);
10860 -- 2) When T.E is a protected entry_call;
10864 -- X : Protected_Entry_Index := <entry index>;
10865 -- DX : Duration := To_Duration (D);
10866 -- M : Delay_Mode := <discriminant>;
10867 -- P : parms := (parm, parm, parm);
10870 -- Timed_Protected_Entry_Call
10871 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10879 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10882 -- B : Boolean := False;
10883 -- C : Ada.Tags.Prim_Op_Kind;
10884 -- DX : Duration := To_Duration (D)
10885 -- K : Ada.Tags.Tagged_Kind :=
10886 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10887 -- M : Integer :=...;
10888 -- P : Parameters := (Param1 .. ParamN);
10892 -- if K = Ada.Tags.TK_Limited_Tagged then
10893 -- <dispatching-call>;
10894 -- <triggering-statements>
10898 -- Ada.Tags.Get_Offset_Index
10899 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10901 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10903 -- if C = POK_Protected_Entry
10904 -- or else C = POK_Task_Entry
10906 -- Param1 := P.Param1;
10908 -- ParamN := P.ParamN;
10912 -- if C = POK_Procedure
10913 -- or else C = POK_Protected_Procedure
10914 -- or else C = POK_Task_Procedure
10916 -- <dispatching-call>;
10919 -- <triggering-statements>
10921 -- <timed-statements>
10926 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10927 Loc : constant Source_Ptr := Sloc (N);
10929 E_Call : Node_Id :=
10930 Entry_Call_Statement (Entry_Call_Alternative (N));
10931 E_Stats : constant List_Id :=
10932 Statements (Entry_Call_Alternative (N));
10933 D_Stat : Node_Id :=
10934 Delay_Statement (Delay_Alternative (N));
10935 D_Stats : constant List_Id :=
10936 Statements (Delay_Alternative (N));
10939 Blk_Typ : Entity_Id;
10941 Call_Ent : Entity_Id;
10942 Conc_Typ_Stmts : List_Id;
10946 D_Type : Entity_Id;
10952 Is_Disp_Select : Boolean;
10953 Lim_Typ_Stmts : List_Id;
10962 B : Entity_Id; -- Call status flag
10963 C : Entity_Id; -- Call kind
10964 D : Entity_Id; -- Delay
10965 K : Entity_Id; -- Tagged kind
10966 M : Entity_Id; -- Delay mode
10967 P : Entity_Id; -- Parameter block
10968 S : Entity_Id; -- Primitive operation slot
10971 -- Under the Ravenscar profile, timed entry calls are excluded. An error
10972 -- was already reported on spec, so do not attempt to expand the call.
10974 if Restriction_Active (No_Select_Statements) then
10978 -- The arguments in the call may require dynamic allocation, and the
10979 -- call statement may have been transformed into a block. The block
10980 -- may contain additional declarations for internal entities, and the
10981 -- original call is found by sequential search.
10983 if Nkind (E_Call) = N_Block_Statement then
10984 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10985 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10986 N_Entry_Call_Statement)
10993 Ada_Version >= Ada_2005
10994 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10996 if Is_Disp_Select then
10997 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11003 -- B : Boolean := False;
11005 B := Build_B (Loc, Decls);
11008 -- C : Ada.Tags.Prim_Op_Kind;
11010 C := Build_C (Loc, Decls);
11012 -- Because the analysis of all statements was disabled, manually
11013 -- analyze the delay statement.
11016 D_Stat := Original_Node (D_Stat);
11019 -- Build an entry call using Simple_Entry_Call
11021 Extract_Entry (E_Call, Concval, Ename, Index);
11022 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11024 Decls := Declarations (E_Call);
11025 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11034 B := Make_Defining_Identifier (Loc, Name_uB);
11037 Make_Object_Declaration (Loc,
11038 Defining_Identifier =>
11040 Object_Definition =>
11041 New_Reference_To (Standard_Boolean, Loc)));
11044 -- Duration and mode processing
11046 D_Type := Base_Type (Etype (Expression (D_Stat)));
11048 -- Use the type of the delay expression (Calendar or Real_Time) to
11049 -- generate the appropriate conversion.
11051 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11052 D_Disc := Make_Integer_Literal (Loc, 0);
11053 D_Conv := Relocate_Node (Expression (D_Stat));
11055 elsif Is_RTE (D_Type, RO_CA_Time) then
11056 D_Disc := Make_Integer_Literal (Loc, 1);
11057 D_Conv := Make_Function_Call (Loc,
11058 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11059 New_List (New_Copy (Expression (D_Stat))));
11061 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11062 D_Disc := Make_Integer_Literal (Loc, 2);
11063 D_Conv := Make_Function_Call (Loc,
11064 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11065 New_List (New_Copy (Expression (D_Stat))));
11068 D := Make_Temporary (Loc, 'D');
11074 Make_Object_Declaration (Loc,
11075 Defining_Identifier =>
11077 Object_Definition =>
11078 New_Reference_To (Standard_Duration, Loc)));
11080 M := Make_Temporary (Loc, 'M');
11083 -- M : Integer := (0 | 1 | 2);
11086 Make_Object_Declaration (Loc,
11087 Defining_Identifier =>
11089 Object_Definition =>
11090 New_Reference_To (Standard_Integer, Loc),
11094 -- Do the assignment at this stage only because the evaluation of the
11095 -- expression must not occur before (see ACVC C97302A).
11098 Make_Assignment_Statement (Loc,
11100 New_Reference_To (D, Loc),
11104 -- Parameter block processing
11106 -- Manually create the parameter block for dispatching calls. In the
11107 -- case of entries, the block has already been created during the call
11108 -- to Build_Simple_Entry_Call.
11110 if Is_Disp_Select then
11112 -- Tagged kind processing, generate:
11113 -- K : Ada.Tags.Tagged_Kind :=
11114 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11116 K := Build_K (Loc, Decls, Obj);
11118 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11119 P := Parameter_Block_Pack
11120 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11122 -- Dispatch table slot processing, generate:
11125 S := Build_S (Loc, Decls);
11128 -- S := Ada.Tags.Get_Offset_Index
11129 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11132 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11135 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11137 -- where Obj is the controlling formal parameter, S is the dispatch
11138 -- table slot number of the dispatching operation, P is the wrapped
11139 -- parameter block, D is the duration, M is the duration mode, C is
11140 -- the call kind and B is the call status.
11142 Params := New_List;
11144 Append_To (Params, New_Copy_Tree (Obj));
11145 Append_To (Params, New_Reference_To (S, Loc));
11146 Append_To (Params, Make_Attribute_Reference (Loc,
11147 Prefix => New_Reference_To (P, Loc),
11148 Attribute_Name => Name_Address));
11149 Append_To (Params, New_Reference_To (D, Loc));
11150 Append_To (Params, New_Reference_To (M, Loc));
11151 Append_To (Params, New_Reference_To (C, Loc));
11152 Append_To (Params, New_Reference_To (B, Loc));
11154 Append_To (Conc_Typ_Stmts,
11155 Make_Procedure_Call_Statement (Loc,
11158 Find_Prim_Op (Etype (Etype (Obj)),
11159 Name_uDisp_Timed_Select),
11161 Parameter_Associations =>
11165 -- if C = POK_Protected_Entry
11166 -- or else C = POK_Task_Entry
11168 -- Param1 := P.Param1;
11170 -- ParamN := P.ParamN;
11173 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11175 -- Generate the if statement only when the packed parameters need
11176 -- explicit assignments to their corresponding actuals.
11178 if Present (Unpack) then
11179 Append_To (Conc_Typ_Stmts,
11180 Make_If_Statement (Loc,
11187 New_Reference_To (C, Loc),
11189 New_Reference_To (RTE (
11190 RE_POK_Protected_Entry), Loc)),
11194 New_Reference_To (C, Loc),
11196 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11205 -- if C = POK_Procedure
11206 -- or else C = POK_Protected_Procedure
11207 -- or else C = POK_Task_Procedure
11209 -- <dispatching-call>
11211 -- <triggering-statements>
11213 -- <timed-statements>
11216 N_Stats := New_Copy_List_Tree (E_Stats);
11218 Prepend_To (N_Stats,
11219 Make_If_Statement (Loc,
11226 New_Reference_To (C, Loc),
11228 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11234 New_Reference_To (C, Loc),
11236 New_Reference_To (RTE (
11237 RE_POK_Protected_Procedure), Loc)),
11241 New_Reference_To (C, Loc),
11243 New_Reference_To (RTE (
11244 RE_POK_Task_Procedure), Loc)))),
11247 New_List (E_Call)));
11249 Append_To (Conc_Typ_Stmts,
11250 Make_If_Statement (Loc,
11251 Condition => New_Reference_To (B, Loc),
11252 Then_Statements => N_Stats,
11253 Else_Statements => D_Stats));
11256 -- <dispatching-call>;
11257 -- <triggering-statements>
11259 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
11260 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11263 -- if K = Ada.Tags.TK_Limited_Tagged then
11270 Make_If_Statement (Loc,
11274 New_Reference_To (K, Loc),
11276 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11285 -- Skip assignments to temporaries created for in-out parameters.
11286 -- This makes unwarranted assumptions about the shape of the expanded
11287 -- tree for the call, and should be cleaned up ???
11289 Stmt := First (Stmts);
11290 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11294 -- Do the assignment at this stage only because the evaluation
11295 -- of the expression must not occur before (see ACVC C97302A).
11297 Insert_Before (Stmt,
11298 Make_Assignment_Statement (Loc,
11299 Name => New_Reference_To (D, Loc),
11300 Expression => D_Conv));
11303 Params := Parameter_Associations (Call);
11305 -- For a protected type, we build a Timed_Protected_Entry_Call
11307 if Is_Protected_Type (Etype (Concval)) then
11309 -- Create a new call statement
11311 Param := First (Params);
11312 while Present (Param)
11313 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11318 Dummy := Remove_Next (Next (Param));
11320 -- Remove garbage is following the Cancel_Param if present
11322 Dummy := Next (Param);
11324 -- Remove the mode of the Protected_Entry_Call call, then remove
11325 -- the Communication_Block of the Protected_Entry_Call call, and
11326 -- finally add Duration and a Delay_Mode parameter
11328 pragma Assert (Present (Param));
11329 Rewrite (Param, New_Reference_To (D, Loc));
11331 Rewrite (Dummy, New_Reference_To (M, Loc));
11333 -- Add a Boolean flag for successful entry call
11335 Append_To (Params, New_Reference_To (B, Loc));
11337 case Corresponding_Runtime_Package (Etype (Concval)) is
11338 when System_Tasking_Protected_Objects_Entries =>
11340 Make_Procedure_Call_Statement (Loc,
11343 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11344 Parameter_Associations => Params));
11346 when System_Tasking_Protected_Objects_Single_Entry =>
11347 Param := First (Params);
11348 while Present (Param)
11350 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11358 Make_Procedure_Call_Statement (Loc,
11359 Name => New_Reference_To (
11360 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11361 Parameter_Associations => Params));
11364 raise Program_Error;
11367 -- For the task case, build a Timed_Task_Entry_Call
11370 -- Create a new call statement
11372 Append_To (Params, New_Reference_To (D, Loc));
11373 Append_To (Params, New_Reference_To (M, Loc));
11374 Append_To (Params, New_Reference_To (B, Loc));
11377 Make_Procedure_Call_Statement (Loc,
11379 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11380 Parameter_Associations => Params));
11384 Make_Implicit_If_Statement (N,
11385 Condition => New_Reference_To (B, Loc),
11386 Then_Statements => E_Stats,
11387 Else_Statements => D_Stats));
11391 Make_Block_Statement (Loc,
11392 Declarations => Decls,
11393 Handled_Statement_Sequence =>
11394 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11397 end Expand_N_Timed_Entry_Call;
11399 ----------------------------------------
11400 -- Expand_Protected_Body_Declarations --
11401 ----------------------------------------
11403 procedure Expand_Protected_Body_Declarations
11405 Spec_Id : Entity_Id)
11408 if No_Run_Time_Mode then
11409 Error_Msg_CRT ("protected body", N);
11412 elsif Expander_Active then
11414 -- Associate discriminals with the first subprogram or entry body to
11417 if Present (First_Protected_Operation (Declarations (N))) then
11418 Set_Discriminals (Parent (Spec_Id));
11421 end Expand_Protected_Body_Declarations;
11423 -------------------------
11424 -- External_Subprogram --
11425 -------------------------
11427 function External_Subprogram (E : Entity_Id) return Entity_Id is
11428 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11431 -- The internal and external subprograms follow each other on the entity
11432 -- chain. Note that previously private operations had no separate
11433 -- external subprogram. We now create one in all cases, because a
11434 -- private operation may actually appear in an external call, through
11435 -- a 'Access reference used for a callback.
11437 -- If the operation is a function that returns an anonymous access type,
11438 -- the corresponding itype appears before the operation, and must be
11441 -- This mechanism is fragile, there should be a real link between the
11442 -- two versions of the operation, but there is no place to put it ???
11444 if Is_Access_Type (Next_Entity (Subp)) then
11445 return Next_Entity (Next_Entity (Subp));
11447 return Next_Entity (Subp);
11449 end External_Subprogram;
11451 ------------------------------
11452 -- Extract_Dispatching_Call --
11453 ------------------------------
11455 procedure Extract_Dispatching_Call
11457 Call_Ent : out Entity_Id;
11458 Object : out Entity_Id;
11459 Actuals : out List_Id;
11460 Formals : out List_Id)
11462 Call_Nam : Node_Id;
11465 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11467 if Present (Original_Node (N)) then
11468 Call_Nam := Name (Original_Node (N));
11470 Call_Nam := Name (N);
11473 -- Retrieve the name of the dispatching procedure. It contains the
11474 -- dispatch table slot number.
11477 case Nkind (Call_Nam) is
11478 when N_Identifier =>
11481 when N_Selected_Component =>
11482 Call_Nam := Selector_Name (Call_Nam);
11485 raise Program_Error;
11490 Actuals := Parameter_Associations (N);
11491 Call_Ent := Entity (Call_Nam);
11492 Formals := Parameter_Specifications (Parent (Call_Ent));
11493 Object := First (Actuals);
11495 if Present (Original_Node (Object)) then
11496 Object := Original_Node (Object);
11498 end Extract_Dispatching_Call;
11500 -------------------
11501 -- Extract_Entry --
11502 -------------------
11504 procedure Extract_Entry
11506 Concval : out Node_Id;
11507 Ename : out Node_Id;
11508 Index : out Node_Id)
11510 Nam : constant Node_Id := Name (N);
11513 -- For a simple entry, the name is a selected component, with the
11514 -- prefix being the task value, and the selector being the entry.
11516 if Nkind (Nam) = N_Selected_Component then
11517 Concval := Prefix (Nam);
11518 Ename := Selector_Name (Nam);
11521 -- For a member of an entry family, the name is an indexed component
11522 -- where the prefix is a selected component, whose prefix in turn is
11523 -- the task value, and whose selector is the entry family. The single
11524 -- expression in the expressions list of the indexed component is the
11525 -- subscript for the family.
11527 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11528 Concval := Prefix (Prefix (Nam));
11529 Ename := Selector_Name (Prefix (Nam));
11530 Index := First (Expressions (Nam));
11534 -------------------
11535 -- Family_Offset --
11536 -------------------
11538 function Family_Offset
11543 Cap : Boolean) return Node_Id
11549 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11550 -- If one of the bounds is a reference to a discriminant, replace with
11551 -- corresponding discriminal of type. Within the body of a task retrieve
11552 -- the renamed discriminant by simple visibility, using its generated
11553 -- name. Within a protected object, find the original discriminant and
11554 -- replace it with the discriminal of the current protected operation.
11556 ------------------------------
11557 -- Convert_Discriminant_Ref --
11558 ------------------------------
11560 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11561 Loc : constant Source_Ptr := Sloc (Bound);
11566 if Is_Entity_Name (Bound)
11567 and then Ekind (Entity (Bound)) = E_Discriminant
11569 if Is_Task_Type (Ttyp)
11570 and then Has_Completion (Ttyp)
11572 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11573 Find_Direct_Name (B);
11575 elsif Is_Protected_Type (Ttyp) then
11576 D := First_Discriminant (Ttyp);
11577 while Chars (D) /= Chars (Entity (Bound)) loop
11578 Next_Discriminant (D);
11581 B := New_Reference_To (Discriminal (D), Loc);
11584 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11587 elsif Nkind (Bound) = N_Attribute_Reference then
11591 B := New_Copy_Tree (Bound);
11595 Make_Attribute_Reference (Loc,
11596 Attribute_Name => Name_Pos,
11597 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11598 Expressions => New_List (B));
11599 end Convert_Discriminant_Ref;
11601 -- Start of processing for Family_Offset
11604 Real_Hi := Convert_Discriminant_Ref (Hi);
11605 Real_Lo := Convert_Discriminant_Ref (Lo);
11608 if Is_Task_Type (Ttyp) then
11609 Ityp := RTE (RE_Task_Entry_Index);
11611 Ityp := RTE (RE_Protected_Entry_Index);
11615 Make_Attribute_Reference (Loc,
11616 Prefix => New_Reference_To (Ityp, Loc),
11617 Attribute_Name => Name_Min,
11618 Expressions => New_List (
11620 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11623 Make_Attribute_Reference (Loc,
11624 Prefix => New_Reference_To (Ityp, Loc),
11625 Attribute_Name => Name_Max,
11626 Expressions => New_List (
11628 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11631 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11638 function Family_Size
11643 Cap : Boolean) return Node_Id
11648 if Is_Task_Type (Ttyp) then
11649 Ityp := RTE (RE_Task_Entry_Index);
11651 Ityp := RTE (RE_Protected_Entry_Index);
11655 Make_Attribute_Reference (Loc,
11656 Prefix => New_Reference_To (Ityp, Loc),
11657 Attribute_Name => Name_Max,
11658 Expressions => New_List (
11661 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11663 Make_Integer_Literal (Loc, 1)),
11664 Make_Integer_Literal (Loc, 0)));
11667 -----------------------
11668 -- Find_Master_Scope --
11669 -----------------------
11671 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
11675 -- In Ada2005, the master is the innermost enclosing scope that is not
11676 -- transient. If the enclosing block is the rewriting of a call or the
11677 -- scope is an extended return statement this is valid master. The
11678 -- master in an extended return is only used within the return, and is
11679 -- subsequently overwritten in Move_Activation_Chain, but it must exist
11680 -- now before that overwriting occurs.
11684 if Ada_Version >= Ada_2005 then
11685 while Is_Internal (S) loop
11686 if Nkind (Parent (S)) = N_Block_Statement
11688 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
11692 elsif Ekind (S) = E_Return_Statement then
11702 end Find_Master_Scope;
11704 -----------------------------------
11705 -- Find_Task_Or_Protected_Pragma --
11706 -----------------------------------
11708 function Find_Task_Or_Protected_Pragma
11710 P : Name_Id) return Node_Id
11715 N := First (Visible_Declarations (T));
11716 while Present (N) loop
11717 if Nkind (N) = N_Pragma then
11718 if Pragma_Name (N) = P then
11721 elsif P = Name_Priority
11722 and then Pragma_Name (N) = Name_Interrupt_Priority
11735 N := First (Private_Declarations (T));
11736 while Present (N) loop
11737 if Nkind (N) = N_Pragma then
11738 if Pragma_Name (N) = P then
11741 elsif P = Name_Priority
11742 and then Pragma_Name (N) = Name_Interrupt_Priority
11755 raise Program_Error;
11756 end Find_Task_Or_Protected_Pragma;
11758 -------------------------------
11759 -- First_Protected_Operation --
11760 -------------------------------
11762 function First_Protected_Operation (D : List_Id) return Node_Id is
11763 First_Op : Node_Id;
11766 First_Op := First (D);
11767 while Present (First_Op)
11768 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11774 end First_Protected_Operation;
11776 ---------------------------------------
11777 -- Install_Private_Data_Declarations --
11778 ---------------------------------------
11780 procedure Install_Private_Data_Declarations
11782 Spec_Id : Entity_Id;
11783 Conc_Typ : Entity_Id;
11784 Body_Nod : Node_Id;
11786 Barrier : Boolean := False;
11787 Family : Boolean := False)
11789 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11792 Insert_Node : Node_Id := Empty;
11793 Obj_Ent : Entity_Id;
11795 procedure Add (Decl : Node_Id);
11796 -- Add a single declaration after Insert_Node. If this is the first
11797 -- addition, Decl is added to the front of Decls and it becomes the
11800 function Replace_Bound (Bound : Node_Id) return Node_Id;
11801 -- The bounds of an entry index may depend on discriminants, create a
11802 -- reference to the corresponding prival. Otherwise return a duplicate
11803 -- of the original bound.
11809 procedure Add (Decl : Node_Id) is
11811 if No (Insert_Node) then
11812 Prepend_To (Decls, Decl);
11814 Insert_After (Insert_Node, Decl);
11817 Insert_Node := Decl;
11820 --------------------------
11821 -- Replace_Discriminant --
11822 --------------------------
11824 function Replace_Bound (Bound : Node_Id) return Node_Id is
11826 if Nkind (Bound) = N_Identifier
11827 and then Is_Discriminal (Entity (Bound))
11829 return Make_Identifier (Loc, Chars (Entity (Bound)));
11831 return Duplicate_Subexpr (Bound);
11835 -- Start of processing for Install_Private_Data_Declarations
11838 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11839 -- formal parameter _O, _object or _task depending on the context.
11841 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11843 -- Special processing of _O for barrier functions, protected entries
11850 (Ekind (Spec_Id) = E_Entry
11851 or else Ekind (Spec_Id) = E_Entry_Family))
11854 Conc_Rec : constant Entity_Id :=
11855 Corresponding_Record_Type (Conc_Typ);
11856 Typ_Id : constant Entity_Id :=
11857 Make_Defining_Identifier (Loc,
11858 New_External_Name (Chars (Conc_Rec), 'P'));
11861 -- type prot_typVP is access prot_typV;
11864 Make_Full_Type_Declaration (Loc,
11865 Defining_Identifier => Typ_Id,
11867 Make_Access_To_Object_Definition (Loc,
11868 Subtype_Indication =>
11869 New_Reference_To (Conc_Rec, Loc)));
11873 -- _object : prot_typVP := prot_typV (_O);
11876 Make_Object_Declaration (Loc,
11877 Defining_Identifier =>
11878 Make_Defining_Identifier (Loc, Name_uObject),
11879 Object_Definition => New_Reference_To (Typ_Id, Loc),
11881 Unchecked_Convert_To (Typ_Id,
11882 New_Reference_To (Obj_Ent, Loc)));
11885 -- Set the reference to the concurrent object
11887 Obj_Ent := Defining_Identifier (Decl);
11891 -- Step 2: Create the Protection object and build its declaration for
11892 -- any protected entry (family) of subprogram.
11894 if Is_Protected then
11896 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
11900 Set_Protection_Object (Spec_Id, Prot_Ent);
11902 -- Determine the proper protection type
11904 if Has_Attach_Handler (Conc_Typ)
11905 and then not Restricted_Profile
11907 Prot_Typ := RE_Static_Interrupt_Protection;
11909 elsif Has_Interrupt_Handler (Conc_Typ) then
11910 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11912 -- The type has explicit entries or generated primitive entry
11915 elsif Has_Entries (Conc_Typ)
11917 (Ada_Version >= Ada_2005
11918 and then Present (Interface_List (Parent (Conc_Typ))))
11920 case Corresponding_Runtime_Package (Conc_Typ) is
11921 when System_Tasking_Protected_Objects_Entries =>
11922 Prot_Typ := RE_Protection_Entries;
11924 when System_Tasking_Protected_Objects_Single_Entry =>
11925 Prot_Typ := RE_Protection_Entry;
11928 raise Program_Error;
11932 Prot_Typ := RE_Protection;
11936 -- conc_typR : protection_typ renames _object._object;
11939 Make_Object_Renaming_Declaration (Loc,
11940 Defining_Identifier => Prot_Ent,
11942 New_Reference_To (RTE (Prot_Typ), Loc),
11944 Make_Selected_Component (Loc,
11946 New_Reference_To (Obj_Ent, Loc),
11948 Make_Identifier (Loc, Name_uObject)));
11953 -- Step 3: Add discriminant renamings (if any)
11955 if Has_Discriminants (Conc_Typ) then
11960 D := First_Discriminant (Conc_Typ);
11961 while Present (D) loop
11963 -- Adjust the source location
11965 Set_Sloc (Discriminal (D), Loc);
11968 -- discr_name : discr_typ renames _object.discr_name;
11970 -- discr_name : discr_typ renames _task.discr_name;
11973 Make_Object_Renaming_Declaration (Loc,
11974 Defining_Identifier => Discriminal (D),
11975 Subtype_Mark => New_Reference_To (Etype (D), Loc),
11977 Make_Selected_Component (Loc,
11978 Prefix => New_Reference_To (Obj_Ent, Loc),
11979 Selector_Name => Make_Identifier (Loc, Chars (D))));
11982 Next_Discriminant (D);
11987 -- Step 4: Add private component renamings (if any)
11989 if Is_Protected then
11990 Def := Protected_Definition (Parent (Conc_Typ));
11992 if Present (Private_Declarations (Def)) then
11995 Comp_Id : Entity_Id;
11996 Decl_Id : Entity_Id;
11999 Comp := First (Private_Declarations (Def));
12000 while Present (Comp) loop
12001 if Nkind (Comp) = N_Component_Declaration then
12002 Comp_Id := Defining_Identifier (Comp);
12004 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12006 -- Minimal decoration
12008 if Ekind (Spec_Id) = E_Function then
12009 Set_Ekind (Decl_Id, E_Constant);
12011 Set_Ekind (Decl_Id, E_Variable);
12014 Set_Prival (Comp_Id, Decl_Id);
12015 Set_Prival_Link (Decl_Id, Comp_Id);
12016 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
12019 -- comp_name : comp_typ renames _object.comp_name;
12022 Make_Object_Renaming_Declaration (Loc,
12023 Defining_Identifier => Decl_Id,
12025 New_Reference_To (Etype (Comp_Id), Loc),
12027 Make_Selected_Component (Loc,
12029 New_Reference_To (Obj_Ent, Loc),
12031 Make_Identifier (Loc, Chars (Comp_Id))));
12041 -- Step 5: Add the declaration of the entry index and the associated
12042 -- type for barrier functions and entry families.
12044 if (Barrier and then Family)
12045 or else Ekind (Spec_Id) = E_Entry_Family
12048 E : constant Entity_Id := Index_Object (Spec_Id);
12049 Index : constant Entity_Id :=
12050 Defining_Identifier (
12051 Entry_Index_Specification (
12052 Entry_Body_Formal_Part (Body_Nod)));
12053 Index_Con : constant Entity_Id :=
12054 Make_Defining_Identifier (Loc, Chars (Index));
12056 Index_Typ : Entity_Id;
12060 -- Minimal decoration
12062 Set_Ekind (Index_Con, E_Constant);
12063 Set_Entry_Index_Constant (Index, Index_Con);
12064 Set_Discriminal_Link (Index_Con, Index);
12066 -- Retrieve the bounds of the entry family
12068 High := Type_High_Bound (Etype (Index));
12069 Low := Type_Low_Bound (Etype (Index));
12071 -- In the simple case the entry family is given by a subtype
12072 -- mark and the index constant has the same type.
12074 if Is_Entity_Name (Original_Node (
12075 Discrete_Subtype_Definition (Parent (Index))))
12077 Index_Typ := Etype (Index);
12079 -- Otherwise a new subtype declaration is required
12082 High := Replace_Bound (High);
12083 Low := Replace_Bound (Low);
12085 Index_Typ := Make_Temporary (Loc, 'J');
12088 -- subtype Jnn is <Etype of Index> range Low .. High;
12091 Make_Subtype_Declaration (Loc,
12092 Defining_Identifier => Index_Typ,
12093 Subtype_Indication =>
12094 Make_Subtype_Indication (Loc,
12096 New_Reference_To (Base_Type (Etype (Index)), Loc),
12098 Make_Range_Constraint (Loc,
12099 Range_Expression =>
12100 Make_Range (Loc, Low, High))));
12104 Set_Etype (Index_Con, Index_Typ);
12106 -- Create the object which designates the index:
12107 -- J : constant Jnn :=
12108 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12110 -- where Jnn is the subtype created above or the original type of
12111 -- the index, _E is a formal of the protected body subprogram and
12112 -- <index expr> is the index of the first family member.
12115 Make_Object_Declaration (Loc,
12116 Defining_Identifier => Index_Con,
12117 Constant_Present => True,
12118 Object_Definition =>
12119 New_Reference_To (Index_Typ, Loc),
12122 Make_Attribute_Reference (Loc,
12124 New_Reference_To (Index_Typ, Loc),
12125 Attribute_Name => Name_Val,
12127 Expressions => New_List (
12131 Make_Op_Subtract (Loc,
12133 New_Reference_To (E, Loc),
12135 Entry_Index_Expression (Loc,
12136 Defining_Identifier (Body_Nod),
12140 Make_Attribute_Reference (Loc,
12142 New_Reference_To (Index_Typ, Loc),
12143 Attribute_Name => Name_Pos,
12144 Expressions => New_List (
12145 Make_Attribute_Reference (Loc,
12147 New_Reference_To (Index_Typ, Loc),
12148 Attribute_Name => Name_First)))))));
12152 end Install_Private_Data_Declarations;
12154 ---------------------------------
12155 -- Is_Potentially_Large_Family --
12156 ---------------------------------
12158 function Is_Potentially_Large_Family
12159 (Base_Index : Entity_Id;
12160 Conctyp : Entity_Id;
12162 Hi : Node_Id) return Boolean
12165 return Scope (Base_Index) = Standard_Standard
12166 and then Base_Index = Base_Type (Standard_Integer)
12167 and then Has_Discriminants (Conctyp)
12169 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12171 (Denotes_Discriminant (Lo, True)
12172 or else Denotes_Discriminant (Hi, True));
12173 end Is_Potentially_Large_Family;
12175 -------------------------------------
12176 -- Is_Private_Primitive_Subprogram --
12177 -------------------------------------
12179 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12182 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12183 and then Is_Private_Primitive (Id);
12184 end Is_Private_Primitive_Subprogram;
12190 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12191 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12192 Formal : Entity_Id;
12195 Formal := First_Formal (Bod_Subp);
12196 while Present (Formal) loop
12198 -- Look for formal parameter _E
12200 if Chars (Formal) = Name_uE then
12204 Next_Formal (Formal);
12207 -- A protected body subprogram should always have the parameter in
12210 raise Program_Error;
12213 --------------------------------
12214 -- Make_Initialize_Protection --
12215 --------------------------------
12217 function Make_Initialize_Protection
12218 (Protect_Rec : Entity_Id) return List_Id
12220 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12224 Ptyp : constant Node_Id :=
12225 Corresponding_Concurrent_Type (Protect_Rec);
12227 L : constant List_Id := New_List;
12228 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12229 Restricted : constant Boolean := Restricted_Profile;
12232 -- We may need two calls to properly initialize the object, one to
12233 -- Initialize_Protection, and possibly one to Install_Handlers if we
12234 -- have a pragma Attach_Handler.
12236 -- Get protected declaration. In the case of a task type declaration,
12237 -- this is simply the parent of the protected type entity. In the single
12238 -- protected object declaration, this parent will be the implicit type,
12239 -- and we can find the corresponding single protected object declaration
12240 -- by searching forward in the declaration list in the tree.
12242 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12243 -- of this type should have been removed during semantic analysis.
12245 Pdec := Parent (Ptyp);
12246 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12247 N_Single_Protected_Declaration)
12252 -- Now we can find the object definition from this declaration
12254 Pdef := Protected_Definition (Pdec);
12256 -- Build the parameter list for the call. Note that _Init is the name
12257 -- of the formal for the object to be initialized, which is the task
12258 -- value record itself.
12262 -- Object parameter. This is a pointer to the object of type
12263 -- Protection used by the GNARL to control the protected object.
12266 Make_Attribute_Reference (Loc,
12268 Make_Selected_Component (Loc,
12269 Prefix => Make_Identifier (Loc, Name_uInit),
12270 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12271 Attribute_Name => Name_Unchecked_Access));
12273 -- Priority parameter. Set to Unspecified_Priority unless there is a
12274 -- priority pragma, in which case we take the value from the pragma,
12275 -- or there is an interrupt pragma and no priority pragma, and we
12276 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12277 -- defined value, see D.3(10).
12280 and then Has_Pragma_Priority (Pdef)
12283 Prio : constant Node_Id :=
12286 (Pragma_Argument_Associations
12287 (Find_Task_Or_Protected_Pragma
12288 (Pdef, Name_Priority))));
12292 -- If priority is a static expression, then we can duplicate it
12293 -- with no problem and simply append it to the argument list.
12295 if Is_Static_Expression (Prio) then
12297 Duplicate_Subexpr_No_Checks (Prio));
12299 -- Otherwise, the priority may be a per-object expression, if it
12300 -- depends on a discriminant of the type. In this case, create
12301 -- local variable to capture the expression. Note that it is
12302 -- really necessary to create this variable explicitly. It might
12303 -- be thought that removing side effects would the appropriate
12304 -- approach, but that could generate declarations improperly
12305 -- placed in the enclosing scope.
12307 -- Note: Use System.Any_Priority as the expected type for the
12308 -- non-static priority expression, in case the expression has not
12309 -- been analyzed yet (as occurs for example with pragma
12310 -- Interrupt_Priority).
12313 Temp := Make_Temporary (Loc, 'R', Prio);
12315 Make_Object_Declaration (Loc,
12316 Defining_Identifier => Temp,
12317 Object_Definition =>
12318 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12319 Expression => Relocate_Node (Prio)));
12321 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12325 -- When no priority is specified but an xx_Handler pragma is, we default
12326 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12328 elsif Has_Interrupt_Handler (Ptyp)
12329 or else Has_Attach_Handler (Ptyp)
12332 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12334 -- Normal case, no priority or xx_Handler specified, default priority
12338 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12341 -- Test for Compiler_Info parameter. This parameter allows entry body
12342 -- procedures and barrier functions to be called from the runtime. It
12343 -- is a pointer to the record generated by the compiler to represent
12344 -- the protected object.
12347 or else Has_Interrupt_Handler (Ptyp)
12348 or else Has_Attach_Handler (Ptyp)
12349 or else Has_Interfaces (Protect_Rec)
12352 Pkg_Id : constant RTU_Id :=
12353 Corresponding_Runtime_Package (Ptyp);
12354 Called_Subp : RE_Id;
12358 when System_Tasking_Protected_Objects_Entries =>
12359 Called_Subp := RE_Initialize_Protection_Entries;
12361 when System_Tasking_Protected_Objects =>
12362 Called_Subp := RE_Initialize_Protection;
12364 when System_Tasking_Protected_Objects_Single_Entry =>
12365 Called_Subp := RE_Initialize_Protection_Entry;
12368 raise Program_Error;
12371 if Has_Entry or else not Restricted then
12373 Make_Attribute_Reference (Loc,
12374 Prefix => Make_Identifier (Loc, Name_uInit),
12375 Attribute_Name => Name_Address));
12378 -- Entry_Bodies parameter. This is a pointer to an array of
12379 -- pointers to the entry body procedures and barrier functions of
12380 -- the object. If the protected type has no entries this object
12381 -- will not exist, in this case, pass a null.
12384 P_Arr := Entry_Bodies_Array (Ptyp);
12387 Make_Attribute_Reference (Loc,
12388 Prefix => New_Reference_To (P_Arr, Loc),
12389 Attribute_Name => Name_Unrestricted_Access));
12391 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12393 -- Find index mapping function (clumsy but ok for now)
12395 while Ekind (P_Arr) /= E_Function loop
12396 Next_Entity (P_Arr);
12400 Make_Attribute_Reference (Loc,
12402 New_Reference_To (P_Arr, Loc),
12403 Attribute_Name => Name_Unrestricted_Access));
12405 -- Build_Entry_Names generation flag. When set to true, the
12406 -- runtime will allocate an array to hold the string names
12407 -- of protected entries.
12409 if not Restricted_Profile then
12410 if Entry_Names_OK then
12412 New_Reference_To (Standard_True, Loc));
12415 New_Reference_To (Standard_False, Loc));
12420 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12421 Append_To (Args, Make_Null (Loc));
12423 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12424 Append_To (Args, Make_Null (Loc));
12425 Append_To (Args, Make_Null (Loc));
12426 Append_To (Args, New_Reference_To (Standard_False, Loc));
12430 Make_Procedure_Call_Statement (Loc,
12431 Name => New_Reference_To (RTE (Called_Subp), Loc),
12432 Parameter_Associations => Args));
12436 Make_Procedure_Call_Statement (Loc,
12437 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12438 Parameter_Associations => Args));
12441 if Has_Attach_Handler (Ptyp) then
12443 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12444 -- make the following call:
12446 -- Install_Handlers (_object,
12447 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12449 -- or, in the case of Ravenscar:
12451 -- Install_Restricted_Handlers
12452 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12455 Args : constant List_Id := New_List;
12456 Table : constant List_Id := New_List;
12457 Ritem : Node_Id := First_Rep_Item (Ptyp);
12460 -- Build the Attach_Handler table argument
12462 while Present (Ritem) loop
12463 if Nkind (Ritem) = N_Pragma
12464 and then Pragma_Name (Ritem) = Name_Attach_Handler
12467 Handler : constant Node_Id :=
12468 First (Pragma_Argument_Associations (Ritem));
12470 Interrupt : constant Node_Id := Next (Handler);
12471 Expr : constant Node_Id := Expression (Interrupt);
12475 Make_Aggregate (Loc, Expressions => New_List (
12476 Unchecked_Convert_To
12477 (RTE (RE_System_Interrupt_Id), Expr),
12478 Make_Attribute_Reference (Loc,
12479 Prefix => Make_Selected_Component (Loc,
12480 Make_Identifier (Loc, Name_uInit),
12481 Duplicate_Subexpr_No_Checks
12482 (Expression (Handler))),
12483 Attribute_Name => Name_Access))));
12487 Next_Rep_Item (Ritem);
12490 -- Append the table argument we just built
12492 Append_To (Args, Make_Aggregate (Loc, Table));
12494 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12495 -- call to the statements.
12498 -- Call a simplified version of Install_Handlers to be used
12499 -- when the Ravenscar restrictions are in effect
12500 -- (Install_Restricted_Handlers).
12503 Make_Procedure_Call_Statement (Loc,
12506 (RTE (RE_Install_Restricted_Handlers), Loc),
12507 Parameter_Associations => Args));
12510 -- First, prepends the _object argument
12513 Make_Attribute_Reference (Loc,
12515 Make_Selected_Component (Loc,
12516 Prefix => Make_Identifier (Loc, Name_uInit),
12517 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12518 Attribute_Name => Name_Unchecked_Access));
12520 -- Then, insert call to Install_Handlers
12523 Make_Procedure_Call_Statement (Loc,
12524 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
12525 Parameter_Associations => Args));
12531 end Make_Initialize_Protection;
12533 ---------------------------
12534 -- Make_Task_Create_Call --
12535 ---------------------------
12537 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
12538 Loc : constant Source_Ptr := Sloc (Task_Rec);
12548 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
12549 Tnam := Chars (Ttyp);
12551 -- Get task declaration. In the case of a task type declaration, this is
12552 -- simply the parent of the task type entity. In the single task
12553 -- declaration, this parent will be the implicit type, and we can find
12554 -- the corresponding single task declaration by searching forward in the
12555 -- declaration list in the tree.
12557 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12558 -- this type should have been removed during semantic analysis.
12560 Tdec := Parent (Ttyp);
12561 while not Nkind_In (Tdec, N_Task_Type_Declaration,
12562 N_Single_Task_Declaration)
12567 -- Now we can find the task definition from this declaration
12569 Tdef := Task_Definition (Tdec);
12571 -- Build the parameter list for the call. Note that _Init is the name
12572 -- of the formal for the object to be initialized, which is the task
12573 -- value record itself.
12577 -- Priority parameter. Set to Unspecified_Priority unless there is a
12578 -- priority pragma, in which case we take the value from the pragma.
12580 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
12582 Make_Selected_Component (Loc,
12583 Prefix => Make_Identifier (Loc, Name_uInit),
12584 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12587 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12590 -- Optional Stack parameter
12592 if Restricted_Profile then
12594 -- If the stack has been preallocated by the expander then
12595 -- pass its address. Otherwise, pass a null address.
12597 if Preallocated_Stacks_On_Target then
12599 Make_Attribute_Reference (Loc,
12600 Prefix => Make_Selected_Component (Loc,
12601 Prefix => Make_Identifier (Loc, Name_uInit),
12603 Make_Identifier (Loc, Name_uStack)),
12604 Attribute_Name => Name_Address));
12608 New_Reference_To (RTE (RE_Null_Address), Loc));
12612 -- Size parameter. If no Storage_Size pragma is present, then
12613 -- the size is taken from the taskZ variable for the type, which
12614 -- is either Unspecified_Size, or has been reset by the use of
12615 -- a Storage_Size attribute definition clause. If a pragma is
12616 -- present, then the size is taken from the _Size field of the
12617 -- task value record, which was set from the pragma value.
12620 and then Has_Storage_Size_Pragma (Tdef)
12623 Make_Selected_Component (Loc,
12624 Prefix => Make_Identifier (Loc, Name_uInit),
12625 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12629 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12632 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12633 -- Task_Info pragma, in which case we take the value from the pragma.
12636 and then Has_Task_Info_Pragma (Tdef)
12639 Make_Selected_Component (Loc,
12640 Prefix => Make_Identifier (Loc, Name_uInit),
12641 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12645 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12648 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
12649 -- in which case we take the value from the pragma. The parameter is
12650 -- passed as an Integer because in the case of unspecified CPU the
12651 -- value is not in the range of CPU_Range.
12653 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
12655 Convert_To (Standard_Integer,
12656 Make_Selected_Component (Loc,
12657 Prefix => Make_Identifier (Loc, Name_uInit),
12658 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
12662 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
12665 if not Restricted_Profile then
12667 -- Deadline parameter. If no Relative_Deadline pragma is present,
12668 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12669 -- the deadline is taken from the _Relative_Deadline field of the
12670 -- task value record, which was set from the pragma value. Note that
12671 -- this parameter must not be generated for the restricted profiles
12672 -- since Ravenscar does not allow deadlines.
12674 -- Case where pragma Relative_Deadline applies: use given value
12676 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12678 Make_Selected_Component (Loc,
12679 Prefix => Make_Identifier (Loc, Name_uInit),
12681 Make_Identifier (Loc, Name_uRelative_Deadline)));
12683 -- No pragma Relative_Deadline apply to the task
12687 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12690 -- Number of entries. This is an expression of the form:
12692 -- n + _Init.a'Length + _Init.a'B'Length + ...
12694 -- where a,b... are the entry family names for the task definition
12697 Build_Entry_Count_Expression
12702 (Parent (Corresponding_Record_Type (Ttyp))))),
12704 Append_To (Args, Ecount);
12706 -- Master parameter. This is a reference to the _Master parameter of
12707 -- the initialization procedure, except in the case of the pragma
12708 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
12709 -- System.Tasking.Library_Task_Level.
12711 if Restriction_Active (No_Task_Hierarchy) = False then
12712 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12715 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
12719 -- State parameter. This is a pointer to the task body procedure. The
12720 -- required value is obtained by taking 'Unrestricted_Access of the task
12721 -- body procedure and converting it (with an unchecked conversion) to
12722 -- the type required by the task kernel. For further details, see the
12723 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12724 -- than 'Address in order to avoid creating trampolines.
12727 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12728 Subp_Ptr_Typ : constant Node_Id :=
12729 Create_Itype (E_Access_Subprogram_Type, Tdec);
12730 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12733 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12734 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12736 -- Be sure to freeze a reference to the access-to-subprogram type,
12737 -- otherwise gigi will complain that it's in the wrong scope, because
12738 -- it's actually inside the init procedure for the record type that
12739 -- corresponds to the task type.
12741 -- This processing is causing a crash in the .NET/JVM back ends that
12742 -- is not yet understood, so skip it in these cases ???
12744 if VM_Target = No_VM then
12745 Set_Itype (Ref, Subp_Ptr_Typ);
12746 Append_Freeze_Action (Task_Rec, Ref);
12749 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12750 Make_Qualified_Expression (Loc,
12751 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12753 Make_Attribute_Reference (Loc,
12755 New_Occurrence_Of (Body_Proc, Loc),
12756 Attribute_Name => Name_Unrestricted_Access))));
12758 -- For the .NET/JVM cases revert to the original code below ???
12762 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12763 Make_Attribute_Reference (Loc,
12765 New_Occurrence_Of (Body_Proc, Loc),
12766 Attribute_Name => Name_Address)));
12770 -- Discriminants parameter. This is just the address of the task
12771 -- value record itself (which contains the discriminant values
12774 Make_Attribute_Reference (Loc,
12775 Prefix => Make_Identifier (Loc, Name_uInit),
12776 Attribute_Name => Name_Address));
12778 -- Elaborated parameter. This is an access to the elaboration Boolean
12781 Make_Attribute_Reference (Loc,
12782 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12783 Attribute_Name => Name_Unchecked_Access));
12785 -- Chain parameter. This is a reference to the _Chain parameter of
12786 -- the initialization procedure.
12788 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12790 -- Task name parameter. Take this from the _Task_Id parameter to the
12791 -- init call unless there is a Task_Name pragma, in which case we take
12792 -- the value from the pragma.
12795 and then Has_Task_Name_Pragma (Tdef)
12797 -- Copy expression in full, because it may be dynamic and have
12803 (Pragma_Argument_Associations
12804 (Find_Task_Or_Protected_Pragma
12805 (Tdef, Name_Task_Name))))));
12808 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12811 -- Created_Task parameter. This is the _Task_Id field of the task
12815 Make_Selected_Component (Loc,
12816 Prefix => Make_Identifier (Loc, Name_uInit),
12817 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12819 -- Build_Entry_Names generation flag. When set to true, the runtime
12820 -- will allocate an array to hold the string names of task entries.
12822 if not Restricted_Profile then
12823 if Has_Entries (Ttyp)
12824 and then Entry_Names_OK
12826 Append_To (Args, New_Reference_To (Standard_True, Loc));
12828 Append_To (Args, New_Reference_To (Standard_False, Loc));
12832 if Restricted_Profile then
12833 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12835 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12839 Make_Procedure_Call_Statement (Loc,
12841 Parameter_Associations => Args);
12842 end Make_Task_Create_Call;
12844 ------------------------------
12845 -- Next_Protected_Operation --
12846 ------------------------------
12848 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12852 Next_Op := Next (N);
12853 while Present (Next_Op)
12854 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12860 end Next_Protected_Operation;
12862 ---------------------
12863 -- Null_Statements --
12864 ---------------------
12866 function Null_Statements (Stats : List_Id) return Boolean is
12870 Stmt := First (Stats);
12871 while Nkind (Stmt) /= N_Empty
12872 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12874 (Nkind (Stmt) = N_Pragma
12875 and then (Pragma_Name (Stmt) = Name_Unreferenced
12877 Pragma_Name (Stmt) = Name_Unmodified
12879 Pragma_Name (Stmt) = Name_Warnings)))
12884 return Nkind (Stmt) = N_Empty;
12885 end Null_Statements;
12887 --------------------------
12888 -- Parameter_Block_Pack --
12889 --------------------------
12891 function Parameter_Block_Pack
12893 Blk_Typ : Entity_Id;
12897 Stmts : List_Id) return Node_Id
12899 Actual : Entity_Id;
12900 Expr : Node_Id := Empty;
12901 Formal : Entity_Id;
12902 Has_Param : Boolean := False;
12905 Temp_Asn : Node_Id;
12906 Temp_Nam : Node_Id;
12909 Actual := First (Actuals);
12910 Formal := Defining_Identifier (First (Formals));
12911 Params := New_List;
12913 while Present (Actual) loop
12914 if Is_By_Copy_Type (Etype (Actual)) then
12916 -- Jnn : aliased <formal-type>
12918 Temp_Nam := Make_Temporary (Loc, 'J');
12921 Make_Object_Declaration (Loc,
12924 Defining_Identifier =>
12926 Object_Definition =>
12927 New_Reference_To (Etype (Formal), Loc)));
12929 if Ekind (Formal) /= E_Out_Parameter then
12935 New_Reference_To (Temp_Nam, Loc);
12937 Set_Assignment_OK (Temp_Asn);
12940 Make_Assignment_Statement (Loc,
12944 New_Copy_Tree (Actual)));
12948 -- Jnn'unchecked_access
12951 Make_Attribute_Reference (Loc,
12953 Name_Unchecked_Access,
12955 New_Reference_To (Temp_Nam, Loc)));
12959 -- The controlling parameter is omitted
12962 if not Is_Controlling_Actual (Actual) then
12964 Make_Reference (Loc, New_Copy_Tree (Actual)));
12970 Next_Actual (Actual);
12971 Next_Formal_With_Extras (Formal);
12975 Expr := Make_Aggregate (Loc, Params);
12980 -- J1'unchecked_access;
12981 -- <actual2>'reference;
12984 P := Make_Temporary (Loc, 'P');
12987 Make_Object_Declaration (Loc,
12988 Defining_Identifier =>
12990 Object_Definition =>
12991 New_Reference_To (Blk_Typ, Loc),
12996 end Parameter_Block_Pack;
12998 ----------------------------
12999 -- Parameter_Block_Unpack --
13000 ----------------------------
13002 function Parameter_Block_Unpack
13006 Formals : List_Id) return List_Id
13008 Actual : Entity_Id;
13010 Formal : Entity_Id;
13011 Has_Asnmt : Boolean := False;
13012 Result : constant List_Id := New_List;
13015 Actual := First (Actuals);
13016 Formal := Defining_Identifier (First (Formals));
13017 while Present (Actual) loop
13018 if Is_By_Copy_Type (Etype (Actual))
13019 and then Ekind (Formal) /= E_In_Parameter
13022 -- <actual> := P.<formal>;
13025 Make_Assignment_Statement (Loc,
13029 Make_Explicit_Dereference (Loc,
13030 Make_Selected_Component (Loc,
13032 New_Reference_To (P, Loc),
13034 Make_Identifier (Loc, Chars (Formal)))));
13036 Set_Assignment_OK (Name (Asnmt));
13037 Append_To (Result, Asnmt);
13042 Next_Actual (Actual);
13043 Next_Formal_With_Extras (Formal);
13049 return New_List (Make_Null_Statement (Loc));
13051 end Parameter_Block_Unpack;
13053 ----------------------
13054 -- Set_Discriminals --
13055 ----------------------
13057 procedure Set_Discriminals (Dec : Node_Id) is
13060 D_Minal : Entity_Id;
13063 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13064 Pdef := Defining_Identifier (Dec);
13066 if Has_Discriminants (Pdef) then
13067 D := First_Discriminant (Pdef);
13068 while Present (D) loop
13070 Make_Defining_Identifier (Sloc (D),
13071 Chars => New_External_Name (Chars (D), 'D'));
13073 Set_Ekind (D_Minal, E_Constant);
13074 Set_Etype (D_Minal, Etype (D));
13075 Set_Scope (D_Minal, Pdef);
13076 Set_Discriminal (D, D_Minal);
13077 Set_Discriminal_Link (D_Minal, D);
13079 Next_Discriminant (D);
13082 end Set_Discriminals;
13084 -----------------------
13085 -- Trivial_Accept_OK --
13086 -----------------------
13088 function Trivial_Accept_OK return Boolean is
13090 case Opt.Task_Dispatching_Policy is
13092 -- If we have the default task dispatching policy in effect, we can
13093 -- definitely do the optimization (one way of looking at this is to
13094 -- think of the formal definition of the default policy being allowed
13095 -- to run any task it likes after a rendezvous, so even if notionally
13096 -- a full rescheduling occurs, we can say that our dispatching policy
13097 -- (i.e. the default dispatching policy) reorders the queue to be the
13098 -- same as just before the call.
13103 -- FIFO_Within_Priorities certainly does not permit this
13104 -- optimization since the Rendezvous is a scheduling action that may
13105 -- require some other task to be run.
13110 -- For now, disallow the optimization for all other policies. This
13111 -- may be over-conservative, but it is certainly not incorrect.
13117 end Trivial_Accept_OK;