1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Ch3; use Exp_Ch3;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Ch6; use Exp_Ch6;
35 with Exp_Dbug; use Exp_Dbug;
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 Nlists; use Nlists;
43 with Nmake; use Nmake;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
49 with Sem_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch11; use Sem_Ch11;
52 with Sem_Elab; use Sem_Elab;
53 with Sem_Res; use Sem_Res;
54 with Sem_Util; use Sem_Util;
55 with Sinfo; use Sinfo;
56 with Snames; use Snames;
57 with Stand; use Stand;
58 with Targparm; use Targparm;
59 with Tbuild; use Tbuild;
60 with Uintp; use Uintp;
62 package body Exp_Ch9 is
64 -- The following constant establishes the upper bound for the index of
65 -- an entry family. It is used to limit the allocated size of protected
66 -- types with defaulted discriminant of an integer type, when the bound
67 -- of some entry family depends on a discriminant. The limitation to
68 -- entry families of 128K should be reasonable in all cases, and is a
69 -- documented implementation restriction. It will be lifted when protected
70 -- entry families are re-implemented as a single ordered queue.
72 Entry_Family_Bound : constant Int := 2**16;
74 -----------------------
75 -- Local Subprograms --
76 -----------------------
78 function Actual_Index_Expression
82 Tsk : Entity_Id) return Node_Id;
83 -- Compute the index position for an entry call. Tsk is the target
84 -- task. If the bounds of some entry family depend on discriminants,
85 -- the expression computed by this function uses the discriminants
86 -- of the target task.
88 procedure Add_Object_Pointer
92 -- Prepend an object pointer declaration to the declaration list
93 -- Decls. This object pointer is initialized to a type conversion
94 -- of the System.Address pointer passed to entry barrier functions
95 -- and entry body procedures.
97 procedure Add_Formal_Renamings
102 -- Create renaming declarations for the formals, inside the procedure
103 -- that implements an entry body. The renamings make the original names
104 -- of the formals accessible to gdb, and serve no other purpose.
105 -- Spec is the specification of the procedure being built.
106 -- Decls is the list of declarations to be enhanced.
107 -- Ent is the entity for the original entry body.
109 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
110 -- Transform accept statement into a block with added exception handler.
111 -- Used both for simple accept statements and for accept alternatives in
112 -- select statements. Astat is the accept statement.
114 function Build_Barrier_Function
117 Pid : Node_Id) return Node_Id;
118 -- Build the function body returning the value of the barrier expression
119 -- for the specified entry body.
121 function Build_Barrier_Function_Specification
123 Loc : Source_Ptr) return Node_Id;
124 -- Build a specification for a function implementing
125 -- the protected entry barrier of the specified entry body.
127 function Build_Entry_Count_Expression
128 (Concurrent_Type : Node_Id;
129 Component_List : List_Id;
130 Loc : Source_Ptr) return Node_Id;
131 -- Compute number of entries for concurrent object. This is a count of
132 -- simple entries, followed by an expression that computes the length
133 -- of the range of each entry family. A single array with that size is
134 -- allocated for each concurrent object of the type.
136 function Build_Parameter_Block
140 Decls : List_Id) return Entity_Id;
141 -- Generate an access type for each actual parameter in the list Actuals.
142 -- Cleate an encapsulating record that contains all the actuals and return
143 -- its type. Generate:
144 -- type Ann1 is access all <actual1-type>
146 -- type AnnN is access all <actualN-type>
147 -- type Pnn is record
153 function Build_Wrapper_Body
155 Proc_Nam : Entity_Id;
157 Formals : List_Id) return Node_Id;
158 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
159 -- associated with a protected or task type. This is required to implement
160 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
161 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
162 -- handle object notation, Formals are the original entry formals that will
163 -- be explicitly replicated.
165 function Build_Wrapper_Spec
167 Proc_Nam : Entity_Id;
169 Formals : List_Id) return Node_Id;
170 -- Ada 2005 (AI-345): Build the specification of a primitive operation
171 -- associated with a protected or task type. This is required implement
172 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
173 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
174 -- handle object notation, Formals are the original entry formals that will
175 -- be explicitly replicated.
177 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
178 -- Build the function that translates the entry index in the call
179 -- (which depends on the size of entry families) into an index into the
180 -- Entry_Bodies_Array, to determine the body and barrier function used
181 -- in a protected entry call. A pointer to this function appears in every
184 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
185 -- Build subprogram declaration for previous one
187 function Build_Protected_Entry
190 Pid : Node_Id) return Node_Id;
191 -- Build the procedure implementing the statement sequence of
192 -- the specified entry body.
194 function Build_Protected_Entry_Specification
197 Loc : Source_Ptr) return Node_Id;
198 -- Build a specification for a procedure implementing
199 -- the statement sequence of the specified entry body.
200 -- Add attributes associating it with the entry defining identifier
203 function Build_Protected_Subprogram_Body
206 N_Op_Spec : Node_Id) return Node_Id;
207 -- This function is used to construct the protected version of a protected
208 -- subprogram. Its statement sequence first defers abort, then locks
209 -- the associated protected object, and then enters a block that contains
210 -- a call to the unprotected version of the subprogram (for details, see
211 -- Build_Unprotected_Subprogram_Body). This block statement requires
212 -- a cleanup handler that unlocks the object in all cases.
213 -- (see Exp_Ch7.Expand_Cleanup_Actions).
215 function Build_Protected_Spec
217 Obj_Type : Entity_Id;
218 Unprotected : Boolean := False;
219 Ident : Entity_Id) return List_Id;
220 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
221 -- Subprogram_Type. Builds signature of protected subprogram, adding the
222 -- formal that corresponds to the object itself. For an access to protected
223 -- subprogram, there is no object type to specify, so the additional
224 -- parameter has type Address and mode In. An indirect call through such
225 -- a pointer converts the address to a reference to the actual object.
226 -- The object is a limited record and therefore a by_reference type.
228 function Build_Selected_Name
230 Selector : Entity_Id;
231 Append_Char : Character := ' ') return Name_Id;
232 -- Build a name in the form of Prefix__Selector, with an optional
233 -- character appended. This is used for internal subprograms generated
234 -- for operations of protected types, including barrier functions.
235 -- For the subprograms generated for entry bodies and entry barriers,
236 -- the generated name includes a sequence number that makes names
237 -- unique in the presence of entry overloading. This is necessary
238 -- because entry body procedures and barrier functions all have the
241 procedure Build_Simple_Entry_Call
246 -- Some comments here would be useful ???
248 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
249 -- This routine constructs a specification for the procedure that we will
250 -- build for the task body for task type T. The spec has the form:
252 -- procedure tnameB (_Task : access tnameV);
254 -- where name is the character name taken from the task type entity that
255 -- is passed as the argument to the procedure, and tnameV is the task
256 -- value type that is associated with the task type.
258 function Build_Unprotected_Subprogram_Body
260 Pid : Node_Id) return Node_Id;
261 -- This routine constructs the unprotected version of a protected
262 -- subprogram body, which is contains all of the code in the
263 -- original, unexpanded body. This is the version of the protected
264 -- subprogram that is called from all protected operations on the same
265 -- object, including the protected version of the same subprogram.
267 procedure Collect_Entry_Families
270 Current_Node : in out Node_Id;
271 Conctyp : Entity_Id);
272 -- For each entry family in a concurrent type, create an anonymous array
273 -- type of the right size, and add a component to the corresponding_record.
275 function Copy_Result_Type (Res : Node_Id) return Node_Id;
276 -- Copy the result type of a function specification, when building the
277 -- internal operation corresponding to a protected function, or when
278 -- expanding an access to protected function. If the result is an anonymous
279 -- access to subprogram itself, we need to create a new signature with the
280 -- same parameter names and the same resolved types, but with new entities
283 function Family_Offset
288 Cap : Boolean) return Node_Id;
289 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
290 -- an accept statement, or the upper bound in the discrete subtype of
291 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
292 -- the concurrent type of the entry. If Cap is true, the result is
293 -- capped according to Entry_Family_Bound.
300 Cap : Boolean) return Node_Id;
301 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
302 -- a family, and handle properly the superflat case. This is equivalent
303 -- to the use of 'Length on the index type, but must use Family_Offset
304 -- to handle properly the case of bounds that depend on discriminants.
305 -- If Cap is true, the result is capped according to Entry_Family_Bound.
307 procedure Extract_Dispatching_Call
309 Call_Ent : out Entity_Id;
310 Object : out Entity_Id;
311 Actuals : out List_Id;
312 Formals : out List_Id);
313 -- Given a dispatching call, extract the entity of the name of the call,
314 -- its object parameter, its actual parameters and the formal parameters
315 -- of the overriden interface-level version.
317 procedure Extract_Entry
319 Concval : out Node_Id;
321 Index : out Node_Id);
322 -- Given an entry call, returns the associated concurrent object,
323 -- the entry name, and the entry family index.
325 function Find_Task_Or_Protected_Pragma
327 P : Name_Id) return Node_Id;
328 -- Searches the task or protected definition T for the first occurrence
329 -- of the pragma whose name is given by P. The caller has ensured that
330 -- the pragma is present in the task definition. A special case is that
331 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
332 -- ??? Should be implemented with the rep item chain mechanism.
334 function Index_Constant_Declaration
336 Index_Id : Entity_Id;
337 Prot : Entity_Id) return List_Id;
338 -- For an entry family and its barrier function, we define a local entity
339 -- that maps the index in the call into the entry index into the object:
341 -- I : constant Index_Type := Index_Type'Val (
342 -- E - <<index of first family member>> +
343 -- Protected_Entry_Index (Index_Type'Pos (Index_Type'First)));
345 function Is_Potentially_Large_Family
346 (Base_Index : Entity_Id;
349 Hi : Node_Id) return Boolean;
351 function Parameter_Block_Pack
357 Stmts : List_Id) return Entity_Id;
358 -- Set the components of the generated parameter block with the values of
359 -- the actual parameters. Generate aliased temporaries to capture the
360 -- values for types that are passed by copy. Otherwise generate a reference
361 -- to the actual's value. Return the address of the aggregate block.
363 -- Jnn1 : alias <formal-type1>;
364 -- Jnn1 := <actual1>;
367 -- Jnn1'unchecked_access;
368 -- <actual2>'reference;
371 function Parameter_Block_Unpack
375 Formals : List_Id) return List_Id;
376 -- Retrieve the values of the components from the parameter block and
377 -- assign then to the original actual parameters. Generate:
378 -- <actual1> := P.<formal1>;
380 -- <actualN> := P.<formalN>;
382 procedure Update_Prival_Subtypes (N : Node_Id);
383 -- The actual subtypes of the privals will differ from the type of the
384 -- private declaration in the original protected type, if the protected
385 -- type has discriminants or if the prival has constrained components.
386 -- This is because the privals are generated out of sequence w.r.t. the
387 -- analysis of a protected body. After generating the bodies for protected
388 -- operations, we set correctly the type of all references to privals, by
389 -- means of a recursive tree traversal, which is heavy-handed but
392 -----------------------------
393 -- Actual_Index_Expression --
394 -----------------------------
396 function Actual_Index_Expression
400 Tsk : Entity_Id) return Node_Id
402 Ttyp : constant Entity_Id := Etype (Tsk);
410 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
411 -- Compute difference between bounds of entry family
413 --------------------------
414 -- Actual_Family_Offset --
415 --------------------------
417 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
419 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
420 -- Replace a reference to a discriminant with a selected component
421 -- denoting the discriminant of the target task.
423 -----------------------------
424 -- Actual_Discriminant_Ref --
425 -----------------------------
427 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
428 Typ : constant Entity_Id := Etype (Bound);
432 if not Is_Entity_Name (Bound)
433 or else Ekind (Entity (Bound)) /= E_Discriminant
435 if Nkind (Bound) = N_Attribute_Reference then
438 B := New_Copy_Tree (Bound);
443 Make_Selected_Component (Sloc,
444 Prefix => New_Copy_Tree (Tsk),
445 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
447 Analyze_And_Resolve (B, Typ);
451 Make_Attribute_Reference (Sloc,
452 Attribute_Name => Name_Pos,
453 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
454 Expressions => New_List (B));
455 end Actual_Discriminant_Ref;
457 -- Start of processing for Actual_Family_Offset
461 Make_Op_Subtract (Sloc,
462 Left_Opnd => Actual_Discriminant_Ref (Hi),
463 Right_Opnd => Actual_Discriminant_Ref (Lo));
464 end Actual_Family_Offset;
466 -- Start of processing for Actual_Index_Expression
469 -- The queues of entries and entry families appear in textual order in
470 -- the associated record. The entry index is computed as the sum of the
471 -- number of queues for all entries that precede the designated one, to
472 -- which is added the index expression, if this expression denotes a
473 -- member of a family.
475 -- The following is a place holder for the count of simple entries
477 Num := Make_Integer_Literal (Sloc, 1);
479 -- We construct an expression which is a series of addition operations.
480 -- See comments in Entry_Index_Expression, which is identical in
483 if Present (Index) then
484 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
491 Actual_Family_Offset (
492 Make_Attribute_Reference (Sloc,
493 Attribute_Name => Name_Pos,
494 Prefix => New_Reference_To (Base_Type (S), Sloc),
495 Expressions => New_List (Relocate_Node (Index))),
496 Type_Low_Bound (S)));
501 -- Now add lengths of preceding entries and entry families
503 Prev := First_Entity (Ttyp);
505 while Chars (Prev) /= Chars (Ent)
506 or else (Ekind (Prev) /= Ekind (Ent))
507 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
509 if Ekind (Prev) = E_Entry then
510 Set_Intval (Num, Intval (Num) + 1);
512 elsif Ekind (Prev) = E_Entry_Family then
514 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
515 Lo := Type_Low_Bound (S);
516 Hi := Type_High_Bound (S);
524 Actual_Family_Offset (Hi, Lo),
526 Make_Integer_Literal (Sloc, 1)));
528 -- Other components are anonymous types to be ignored
538 end Actual_Index_Expression;
540 ----------------------------------
541 -- Add_Discriminal_Declarations --
542 ----------------------------------
544 procedure Add_Discriminal_Declarations
553 if Has_Discriminants (Typ) then
554 D := First_Discriminant (Typ);
556 while Present (D) loop
559 Make_Object_Renaming_Declaration (Loc,
560 Defining_Identifier => Discriminal (D),
561 Subtype_Mark => New_Reference_To (Etype (D), Loc),
563 Make_Selected_Component (Loc,
564 Prefix => Make_Identifier (Loc, Name),
565 Selector_Name => Make_Identifier (Loc, Chars (D)))));
567 Next_Discriminant (D);
570 end Add_Discriminal_Declarations;
572 ------------------------
573 -- Add_Object_Pointer --
574 ------------------------
576 procedure Add_Object_Pointer
585 -- Prepend the declaration of _object. This must be first in the
586 -- declaration list, since it is used by the discriminal and
587 -- prival declarations.
588 -- ??? An attempt to make this a renaming was unsuccessful.
590 -- type poVP is access poV;
591 -- _object : poVP := poVP!O;
594 Make_Defining_Identifier (Loc,
597 (Chars (Corresponding_Record_Type (Pid)), 'P'));
600 Make_Object_Declaration (Loc,
601 Defining_Identifier =>
602 Make_Defining_Identifier (Loc, Name_uObject),
603 Object_Definition => New_Reference_To (Obj_Ptr, Loc),
605 Unchecked_Convert_To (Obj_Ptr,
606 Make_Identifier (Loc, Name_uO)));
607 Set_Needs_Debug_Info (Defining_Identifier (Decl));
608 Prepend_To (Decls, Decl);
611 Make_Full_Type_Declaration (Loc,
612 Defining_Identifier => Obj_Ptr,
613 Type_Definition => Make_Access_To_Object_Definition (Loc,
614 Subtype_Indication =>
615 New_Reference_To (Corresponding_Record_Type (Pid), Loc))));
616 end Add_Object_Pointer;
618 --------------------------
619 -- Add_Formal_Renamings --
620 --------------------------
622 procedure Add_Formal_Renamings
628 Ptr : constant Entity_Id :=
630 (Next (First (Parameter_Specifications (Spec))));
631 -- The name of the formal that holds the address of the parameter block
640 Formal := First_Formal (Ent);
641 while Present (Formal) loop
642 Comp := Entry_Component (Formal);
644 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
645 Set_Etype (New_F, Etype (Formal));
646 Set_Scope (New_F, Ent);
647 Set_Needs_Debug_Info (New_F); -- That's the whole point.
649 if Ekind (Formal) = E_In_Parameter then
650 Set_Ekind (New_F, E_Constant);
652 Set_Ekind (New_F, E_Variable);
653 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
656 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
659 Make_Object_Renaming_Declaration (Loc,
660 Defining_Identifier => New_F,
661 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
663 Make_Explicit_Dereference (Loc,
664 Make_Selected_Component (Loc,
666 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
667 Make_Identifier (Loc, Chars (Ptr))),
669 New_Reference_To (Comp, Loc))));
671 Append (Decl, Decls);
672 Set_Renamed_Object (Formal, New_F);
673 Next_Formal (Formal);
675 end Add_Formal_Renamings;
677 ------------------------------
678 -- Add_Private_Declarations --
679 ------------------------------
681 procedure Add_Private_Declarations
687 Def : constant Node_Id := Protected_Definition (Parent (Typ));
689 Body_Ent : constant Entity_Id := Corresponding_Body (Parent (Typ));
694 pragma Assert (Nkind (Def) = N_Protected_Definition);
696 if Present (Private_Declarations (Def)) then
697 P := First (Private_Declarations (Def));
698 while Present (P) loop
699 if Nkind (P) = N_Component_Declaration then
700 Pdef := Defining_Identifier (P);
702 -- The privals are declared before the current body is
703 -- analyzed. for visibility reasons. Set their Sloc so
704 -- that it is consistent with their renaming declaration,
705 -- to prevent anomalies in gdb.
707 -- This kludgy model for privals should be redesigned ???
709 Set_Sloc (Prival (Pdef), Loc);
712 Make_Object_Renaming_Declaration (Loc,
713 Defining_Identifier => Prival (Pdef),
714 Subtype_Mark => New_Reference_To (Etype (Pdef), Loc),
716 Make_Selected_Component (Loc,
717 Prefix => Make_Identifier (Loc, Name),
718 Selector_Name => Make_Identifier (Loc, Chars (Pdef))));
719 Set_Needs_Debug_Info (Defining_Identifier (Decl));
720 Prepend_To (Decls, Decl);
727 -- One more "prival" for object itself, with the right protection type
730 Protection_Type : RE_Id;
733 if Has_Attach_Handler (Typ) then
734 if Restricted_Profile then
735 if Has_Entries (Typ) then
736 Protection_Type := RE_Protection_Entry;
738 Protection_Type := RE_Protection;
741 Protection_Type := RE_Static_Interrupt_Protection;
744 elsif Has_Interrupt_Handler (Typ) then
745 Protection_Type := RE_Dynamic_Interrupt_Protection;
747 -- The type has explicit entries or generated primitive entry
750 elsif Has_Entries (Typ)
751 or else (Ada_Version >= Ada_05
752 and then Present (Interface_List (Parent (Typ))))
755 or else Restriction_Active (No_Entry_Queue) = False
756 or else Number_Entries (Typ) > 1
758 Protection_Type := RE_Protection_Entries;
760 Protection_Type := RE_Protection_Entry;
764 Protection_Type := RE_Protection;
767 -- Adjust Sloc, as for the other privals
769 Set_Sloc (Object_Ref (Body_Ent), Loc);
772 Make_Object_Renaming_Declaration (Loc,
773 Defining_Identifier => Object_Ref (Body_Ent),
774 Subtype_Mark => New_Reference_To (RTE (Protection_Type), Loc),
776 Make_Selected_Component (Loc,
777 Prefix => Make_Identifier (Loc, Name),
778 Selector_Name => Make_Identifier (Loc, Name_uObject)));
779 Set_Needs_Debug_Info (Defining_Identifier (Decl));
780 Prepend_To (Decls, Decl);
782 end Add_Private_Declarations;
784 -----------------------
785 -- Build_Accept_Body --
786 -----------------------
788 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
789 Loc : constant Source_Ptr := Sloc (Astat);
790 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
797 -- At the end of the statement sequence, Complete_Rendezvous is called.
798 -- A label skipping the Complete_Rendezvous, and all other accept
799 -- processing, has already been added for the expansion of requeue
802 Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous);
803 Insert_Before (Last (Statements (Stats)), Call);
806 -- If exception handlers are present, then append Complete_Rendezvous
807 -- calls to the handlers, and construct the required outer block.
809 if Present (Exception_Handlers (Stats)) then
810 Hand := First (Exception_Handlers (Stats));
812 while Present (Hand) loop
813 Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous);
814 Append (Call, Statements (Hand));
820 Make_Handled_Sequence_Of_Statements (Loc,
821 Statements => New_List (
822 Make_Block_Statement (Loc,
823 Handled_Statement_Sequence => Stats)));
829 -- At this stage we know that the new statement sequence does not
830 -- have an exception handler part, so we supply one to call
831 -- Exceptional_Complete_Rendezvous. This handler is
833 -- when all others =>
834 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
836 -- We handle Abort_Signal to make sure that we properly catch the abort
837 -- case and wake up the caller.
839 Ohandle := Make_Others_Choice (Loc);
840 Set_All_Others (Ohandle);
842 Set_Exception_Handlers (New_S,
844 Make_Implicit_Exception_Handler (Loc,
845 Exception_Choices => New_List (Ohandle),
847 Statements => New_List (
848 Make_Procedure_Call_Statement (Loc,
849 Name => New_Reference_To (
850 RTE (RE_Exceptional_Complete_Rendezvous), Loc),
851 Parameter_Associations => New_List (
852 Make_Function_Call (Loc,
853 Name => New_Reference_To (
854 RTE (RE_Get_GNAT_Exception), Loc))))))));
856 Set_Parent (New_S, Astat); -- temp parent for Analyze call
857 Analyze_Exception_Handlers (Exception_Handlers (New_S));
858 Expand_Exception_Handlers (New_S);
860 -- Exceptional_Complete_Rendezvous must be called with abort
861 -- still deferred, which is the case for a "when all others" handler.
864 end Build_Accept_Body;
866 -----------------------------------
867 -- Build_Activation_Chain_Entity --
868 -----------------------------------
870 procedure Build_Activation_Chain_Entity (N : Node_Id) is
876 -- Loop to find enclosing construct containing activation chain variable
880 while Nkind (P) /= N_Subprogram_Body
881 and then Nkind (P) /= N_Package_Declaration
882 and then Nkind (P) /= N_Package_Body
883 and then Nkind (P) /= N_Block_Statement
884 and then Nkind (P) /= N_Task_Body
885 and then Nkind (P) /= N_Extended_Return_Statement
890 -- If we are in a package body, the activation chain variable is
891 -- declared in the body, but the Activation_Chain_Entity is attached to
894 if Nkind (P) = N_Package_Body then
895 Decls := Declarations (P);
896 P := Unit_Declaration_Node (Corresponding_Spec (P));
898 elsif Nkind (P) = N_Package_Declaration then
899 Decls := Visible_Declarations (Specification (P));
901 elsif Nkind (P) = N_Extended_Return_Statement then
902 Decls := Return_Object_Declarations (P);
905 Decls := Declarations (P);
908 -- If activation chain entity not already declared, declare it
910 if Nkind (P) = N_Extended_Return_Statement
911 or else No (Activation_Chain_Entity (P))
913 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
915 -- Note: An extended return statement is not really a task activator,
916 -- but it does have an activation chain on which to store the tasks
917 -- temporarily. On successful return, the tasks on this chain are
918 -- moved to the chain passed in by the caller. We do not build an
919 -- Activatation_Chain_Entity for an N_Extended_Return_Statement,
920 -- because we do not want to build a call to Activate_Tasks. Task
921 -- activation is the responsibility of the caller.
923 if Nkind (P) /= N_Extended_Return_Statement then
924 Set_Activation_Chain_Entity (P, Chain);
928 Make_Object_Declaration (Sloc (P),
929 Defining_Identifier => Chain,
930 Aliased_Present => True,
932 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
934 Analyze (First (Decls));
936 end Build_Activation_Chain_Entity;
938 ----------------------------
939 -- Build_Barrier_Function --
940 ----------------------------
942 function Build_Barrier_Function
945 Pid : Node_Id) return Node_Id
947 Loc : constant Source_Ptr := Sloc (N);
948 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
949 Index_Spec : constant Node_Id := Entry_Index_Specification
951 Op_Decls : constant List_Id := New_List;
958 Make_Defining_Identifier (Loc,
959 Chars => Chars (Barrier_Function (Ent)));
960 Bspec := Build_Barrier_Function_Specification (Bdef, Loc);
962 -- <object pointer declaration>
963 -- <discriminant renamings>
964 -- <private object renamings>
965 -- Add discriminal and private renamings. These names have
966 -- already been used to expand references to discriminants
969 Add_Discriminal_Declarations (Op_Decls, Pid, Name_uObject, Loc);
970 Add_Private_Declarations (Op_Decls, Pid, Name_uObject, Loc);
971 Add_Object_Pointer (Op_Decls, Pid, Loc);
973 -- If this is the barrier for an entry family, the entry index is
974 -- visible in the body of the barrier. Create a local variable that
975 -- converts the entry index (which is the last formal of the barrier
976 -- function) into the appropriate offset into the entry array. The
977 -- entry index constant must be set, as for the entry body, so that
978 -- local references to the entry index are correctly replaced with
979 -- the local variable. This parallels what is done for entry bodies.
981 if Present (Index_Spec) then
983 Index_Id : constant Entity_Id := Defining_Identifier (Index_Spec);
984 Index_Con : constant Entity_Id :=
985 Make_Defining_Identifier (Loc,
986 Chars => New_Internal_Name ('J'));
988 Set_Entry_Index_Constant (Index_Id, Index_Con);
989 Append_List_To (Op_Decls,
990 Index_Constant_Declaration (N, Index_Id, Pid));
994 -- Note: the condition in the barrier function needs to be properly
995 -- processed for the C/Fortran boolean possibility, but this happens
996 -- automatically since the return statement does this normalization.
999 Make_Subprogram_Body (Loc,
1000 Specification => Bspec,
1001 Declarations => Op_Decls,
1002 Handled_Statement_Sequence =>
1003 Make_Handled_Sequence_Of_Statements (Loc,
1004 Statements => New_List (
1005 Make_Return_Statement (Loc,
1006 Expression => Condition (Ent_Formals)))));
1007 Set_Is_Entry_Barrier_Function (EBF);
1009 end Build_Barrier_Function;
1011 ------------------------------------------
1012 -- Build_Barrier_Function_Specification --
1013 ------------------------------------------
1015 function Build_Barrier_Function_Specification
1016 (Def_Id : Entity_Id;
1017 Loc : Source_Ptr) return Node_Id
1020 Set_Needs_Debug_Info (Def_Id);
1021 return Make_Function_Specification (Loc,
1022 Defining_Unit_Name => Def_Id,
1023 Parameter_Specifications => New_List (
1024 Make_Parameter_Specification (Loc,
1025 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
1027 New_Reference_To (RTE (RE_Address), Loc)),
1029 Make_Parameter_Specification (Loc,
1030 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE),
1032 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1034 Result_Definition => New_Reference_To (Standard_Boolean, Loc));
1035 end Build_Barrier_Function_Specification;
1037 --------------------------
1038 -- Build_Call_With_Task --
1039 --------------------------
1041 function Build_Call_With_Task
1043 E : Entity_Id) return Node_Id
1045 Loc : constant Source_Ptr := Sloc (N);
1048 Make_Function_Call (Loc,
1049 Name => New_Reference_To (E, Loc),
1050 Parameter_Associations => New_List (Concurrent_Ref (N)));
1051 end Build_Call_With_Task;
1053 --------------------------------
1054 -- Build_Corresponding_Record --
1055 --------------------------------
1057 function Build_Corresponding_Record
1060 Loc : Source_Ptr) return Node_Id
1062 Rec_Ent : constant Entity_Id :=
1063 Make_Defining_Identifier
1064 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1067 New_Disc : Entity_Id;
1071 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1072 Set_Ekind (Rec_Ent, E_Record_Type);
1073 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1074 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1075 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1076 Set_Stored_Constraint (Rec_Ent, No_Elist);
1079 -- Use discriminals to create list of discriminants for record, and
1080 -- create new discriminals for use in default expressions, etc. It is
1081 -- worth noting that a task discriminant gives rise to 5 entities;
1083 -- a) The original discriminant.
1084 -- b) The discriminal for use in the task.
1085 -- c) The discriminant of the corresponding record.
1086 -- d) The discriminal for the init proc of the corresponding record.
1087 -- e) The local variable that renames the discriminant in the procedure
1088 -- for the task body.
1090 -- In fact the discriminals b) are used in the renaming declarations
1091 -- for e). See details in einfo (Handling of Discriminants).
1093 if Present (Discriminant_Specifications (N)) then
1095 Disc := First_Discriminant (Ctyp);
1097 while Present (Disc) loop
1098 New_Disc := CR_Discriminant (Disc);
1101 Make_Discriminant_Specification (Loc,
1102 Defining_Identifier => New_Disc,
1103 Discriminant_Type =>
1104 New_Occurrence_Of (Etype (Disc), Loc),
1106 New_Copy (Discriminant_Default_Value (Disc))));
1108 Next_Discriminant (Disc);
1115 -- Now we can construct the record type declaration. Note that this
1116 -- record is "limited tagged". It is "limited" to reflect the underlying
1117 -- limitedness of the task or protected object that it represents, and
1118 -- ensuring for example that it is properly passed by reference. It is
1119 -- "tagged" to give support to dispatching calls through interfaces (Ada
1123 Make_Full_Type_Declaration (Loc,
1124 Defining_Identifier => Rec_Ent,
1125 Discriminant_Specifications => Dlist,
1127 Make_Record_Definition (Loc,
1129 Make_Component_List (Loc,
1130 Component_Items => Cdecls),
1132 Ada_Version >= Ada_05 and then Is_Tagged_Type (Ctyp),
1133 Limited_Present => True));
1134 end Build_Corresponding_Record;
1136 ----------------------------------
1137 -- Build_Entry_Count_Expression --
1138 ----------------------------------
1140 function Build_Entry_Count_Expression
1141 (Concurrent_Type : Node_Id;
1142 Component_List : List_Id;
1143 Loc : Source_Ptr) return Node_Id
1155 -- Count number of non-family entries
1158 Ent := First_Entity (Concurrent_Type);
1159 while Present (Ent) loop
1160 if Ekind (Ent) = E_Entry then
1167 Ecount := Make_Integer_Literal (Loc, Eindx);
1169 -- Loop through entry families building the addition nodes
1171 Ent := First_Entity (Concurrent_Type);
1172 Comp := First (Component_List);
1173 while Present (Ent) loop
1174 if Ekind (Ent) = E_Entry_Family then
1175 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1179 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1180 Hi := Type_High_Bound (Typ);
1181 Lo := Type_Low_Bound (Typ);
1182 Large := Is_Potentially_Large_Family
1183 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1186 Left_Opnd => Ecount,
1187 Right_Opnd => Family_Size
1188 (Loc, Hi, Lo, Concurrent_Type, Large));
1195 end Build_Entry_Count_Expression;
1197 ---------------------------
1198 -- Build_Parameter_Block --
1199 ---------------------------
1201 function Build_Parameter_Block
1205 Decls : List_Id) return Entity_Id
1211 Has_Comp : Boolean := False;
1215 Actual := First (Actuals);
1217 Formal := Defining_Identifier (First (Formals));
1219 while Present (Actual) loop
1220 if not Is_Controlling_Actual (Actual) then
1223 -- type Ann is access all <actual-type>
1226 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
1229 Make_Full_Type_Declaration (Loc,
1230 Defining_Identifier =>
1233 Make_Access_To_Object_Definition (Loc,
1237 Ekind (Formal) = E_In_Parameter,
1238 Subtype_Indication =>
1239 New_Reference_To (Etype (Actual), Loc))));
1245 Make_Component_Declaration (Loc,
1246 Defining_Identifier =>
1247 Make_Defining_Identifier (Loc, Chars (Formal)),
1248 Component_Definition =>
1249 Make_Component_Definition (Loc,
1252 Subtype_Indication =>
1253 New_Reference_To (Comp_Nam, Loc))));
1258 Next_Actual (Actual);
1259 Next_Formal_With_Extras (Formal);
1263 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
1268 -- type Pnn is record
1273 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1274 -- the original parameter names and Ann1 .. AnnN are the access to
1278 Make_Full_Type_Declaration (Loc,
1279 Defining_Identifier =>
1282 Make_Record_Definition (Loc,
1284 Make_Component_List (Loc, Comps))));
1287 -- type Pnn is null record;
1290 Make_Full_Type_Declaration (Loc,
1291 Defining_Identifier =>
1294 Make_Record_Definition (Loc,
1295 Null_Present => True,
1296 Component_List => Empty)));
1300 end Build_Parameter_Block;
1302 ------------------------
1303 -- Build_Wrapper_Body --
1304 ------------------------
1306 function Build_Wrapper_Body
1308 Proc_Nam : Entity_Id;
1309 Obj_Typ : Entity_Id;
1310 Formals : List_Id) return Node_Id
1312 Actuals : List_Id := No_List;
1313 Body_Spec : Node_Id;
1315 First_Formal : Node_Id;
1319 Body_Spec := Build_Wrapper_Spec (Loc, Proc_Nam, Obj_Typ, Formals);
1321 -- If we did not generate the specification do have nothing else to do
1323 if Body_Spec = Empty then
1327 -- Map formals to actuals. Use the list built for the wrapper spec,
1328 -- skipping the object notation parameter.
1330 First_Formal := First (Parameter_Specifications (Body_Spec));
1332 Formal := First_Formal;
1335 if Present (Formal) then
1336 Actuals := New_List;
1338 while Present (Formal) loop
1340 Make_Identifier (Loc, Chars =>
1341 Chars (Defining_Identifier (Formal))));
1347 -- An access-to-variable first parameter will require an explicit
1348 -- dereference in the unchecked conversion. This case occurs when
1349 -- a protected entry wrapper must override an interface-level
1350 -- procedure with interface access as first parameter.
1352 -- SubprgName (O.all).Proc_Nam (Formal_1 .. Formal_N)
1354 if Nkind (Parameter_Type (First_Formal)) = N_Access_Definition then
1356 Make_Explicit_Dereference (Loc,
1358 Make_Identifier (Loc, Chars => Name_uO));
1361 Make_Identifier (Loc, Chars => Name_uO);
1364 if Ekind (Proc_Nam) = E_Function then
1366 Make_Subprogram_Body (Loc,
1367 Specification => Body_Spec,
1368 Declarations => Empty_List,
1369 Handled_Statement_Sequence =>
1370 Make_Handled_Sequence_Of_Statements (Loc,
1373 Make_Return_Statement (Loc,
1374 Make_Function_Call (Loc,
1376 Make_Selected_Component (Loc,
1378 Unchecked_Convert_To (
1379 Corresponding_Concurrent_Type (Obj_Typ),
1382 New_Reference_To (Proc_Nam, Loc)),
1383 Parameter_Associations => Actuals)))));
1386 Make_Subprogram_Body (Loc,
1387 Specification => Body_Spec,
1388 Declarations => Empty_List,
1389 Handled_Statement_Sequence =>
1390 Make_Handled_Sequence_Of_Statements (Loc,
1393 Make_Procedure_Call_Statement (Loc,
1395 Make_Selected_Component (Loc,
1397 Unchecked_Convert_To (
1398 Corresponding_Concurrent_Type (Obj_Typ),
1401 New_Reference_To (Proc_Nam, Loc)),
1402 Parameter_Associations => Actuals))));
1404 end Build_Wrapper_Body;
1406 ------------------------
1407 -- Build_Wrapper_Spec --
1408 ------------------------
1410 function Build_Wrapper_Spec
1412 Proc_Nam : Entity_Id;
1413 Obj_Typ : Entity_Id;
1414 Formals : List_Id) return Node_Id
1416 New_Name_Id : constant Entity_Id :=
1417 Make_Defining_Identifier (Loc, Chars (Proc_Nam));
1419 First_Param : Node_Id := Empty;
1421 Iface_Elmt : Elmt_Id := No_Elmt;
1422 New_Formals : List_Id;
1423 Obj_Param : Node_Id;
1424 Obj_Param_Typ : Node_Id;
1425 Iface_Prim_Op : Entity_Id;
1426 Iface_Prim_Op_Elmt : Elmt_Id;
1428 function Overriding_Possible
1429 (Iface_Prim_Op : Entity_Id;
1430 Proc_Nam : Entity_Id) return Boolean;
1431 -- Determine whether a primitive operation can be overriden by the
1432 -- wrapper. Iface_Prim_Op is the candidate primitive operation of an
1433 -- abstract interface type, Proc_Nam is the generated entry wrapper.
1435 function Replicate_Entry_Formals
1437 Formals : List_Id) return List_Id;
1438 -- An explicit parameter replication is required due to the
1439 -- Is_Entry_Formal flag being set for all the formals. The explicit
1440 -- replication removes the flag that would otherwise cause a different
1441 -- path of analysis.
1443 -------------------------
1444 -- Overriding_Possible --
1445 -------------------------
1447 function Overriding_Possible
1448 (Iface_Prim_Op : Entity_Id;
1449 Proc_Nam : Entity_Id) return Boolean
1451 Prim_Op_Spec : constant Node_Id := Parent (Iface_Prim_Op);
1452 Proc_Spec : constant Node_Id := Parent (Proc_Nam);
1454 Is_Access_To_Variable : Boolean;
1455 Is_Out_Present : Boolean;
1457 function Type_Conformant_Parameters
1458 (Prim_Op_Param_Specs : List_Id;
1459 Proc_Param_Specs : List_Id) return Boolean;
1460 -- Determine whether the parameters of the generated entry wrapper
1461 -- and those of a primitive operation are type conformant. During
1462 -- this check, the first parameter of the primitive operation is
1465 --------------------------------
1466 -- Type_Conformant_Parameters --
1467 --------------------------------
1469 function Type_Conformant_Parameters
1470 (Prim_Op_Param_Specs : List_Id;
1471 Proc_Param_Specs : List_Id) return Boolean
1473 Prim_Op_Param : Node_Id;
1474 Prim_Op_Typ : Entity_Id;
1475 Proc_Param : Node_Id;
1476 Proc_Typ : Entity_Id;
1478 function Find_Parameter_Type (Param : Node_Id) return Entity_Id;
1479 -- Return the controlling type denoted by a formal parameter
1481 -------------------------
1482 -- Find_Parameter_Type --
1483 -------------------------
1485 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
1487 if Nkind (Param) /= N_Parameter_Specification then
1490 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
1491 return Etype (Subtype_Mark (Parameter_Type (Param)));
1494 return Etype (Parameter_Type (Param));
1496 end Find_Parameter_Type;
1498 -- Start of processing for Type_Conformant_Parameters
1501 -- Skip the first parameter of the primitive operation
1503 Prim_Op_Param := Next (First (Prim_Op_Param_Specs));
1504 Proc_Param := First (Proc_Param_Specs);
1505 while Present (Prim_Op_Param)
1506 and then Present (Proc_Param)
1508 Prim_Op_Typ := Find_Parameter_Type (Prim_Op_Param);
1509 Proc_Typ := Find_Parameter_Type (Proc_Param);
1511 -- The two parameters must be mode conformant
1513 if not Conforming_Types
1514 (Prim_Op_Typ, Proc_Typ, Mode_Conformant)
1519 Next (Prim_Op_Param);
1523 -- One of the lists is longer than the other
1525 if Present (Prim_Op_Param) or else Present (Proc_Param) then
1530 end Type_Conformant_Parameters;
1532 -- Start of processing for Overriding_Possible
1535 if Chars (Iface_Prim_Op) /= Chars (Proc_Nam) then
1539 -- Special check for protected procedures: If an inherited subprogram
1540 -- is implemented by a protected procedure or an entry, then the
1541 -- first parameter of the inherited subprogram shall be of mode OUT
1542 -- or IN OUT, or an access-to-variable parameter.
1544 if Ekind (Iface_Prim_Op) = E_Procedure then
1547 Present (Parameter_Specifications (Prim_Op_Spec))
1549 Out_Present (First (Parameter_Specifications (Prim_Op_Spec)));
1551 Is_Access_To_Variable :=
1552 Present (Parameter_Specifications (Prim_Op_Spec))
1554 Nkind (Parameter_Type
1556 (Parameter_Specifications (Prim_Op_Spec))))
1557 = N_Access_Definition;
1559 if not Is_Out_Present
1560 and then not Is_Access_To_Variable
1566 return Type_Conformant_Parameters (
1567 Parameter_Specifications (Prim_Op_Spec),
1568 Parameter_Specifications (Proc_Spec));
1569 end Overriding_Possible;
1571 -----------------------------
1572 -- Replicate_Entry_Formals --
1573 -----------------------------
1575 function Replicate_Entry_Formals
1577 Formals : List_Id) return List_Id
1579 New_Formals : constant List_Id := New_List;
1583 Formal := First (Formals);
1584 while Present (Formal) loop
1586 -- Create an explicit copy of the entry parameter
1588 Append_To (New_Formals,
1589 Make_Parameter_Specification (Loc,
1590 Defining_Identifier =>
1591 Make_Defining_Identifier (Loc,
1592 Chars => Chars (Defining_Identifier (Formal))),
1593 In_Present => In_Present (Formal),
1594 Out_Present => Out_Present (Formal),
1595 Parameter_Type => New_Reference_To (Etype (
1596 Parameter_Type (Formal)), Loc)));
1602 end Replicate_Entry_Formals;
1604 -- Start of processing for Build_Wrapper_Spec
1607 -- The mode is determined by the first parameter of the interface-level
1608 -- procedure that the current entry is trying to override.
1610 pragma Assert (Is_Non_Empty_List (Abstract_Interface_List (Obj_Typ)));
1612 -- We must examine all the protected operations of the implemented
1613 -- interfaces in order to discover a possible overriding candidate.
1615 Iface := Etype (First (Abstract_Interface_List (Obj_Typ)));
1617 Examine_Parents : loop
1618 if Present (Primitive_Operations (Iface)) then
1619 Iface_Prim_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
1620 while Present (Iface_Prim_Op_Elmt) loop
1621 Iface_Prim_Op := Node (Iface_Prim_Op_Elmt);
1623 if not Is_Predefined_Dispatching_Operation (Iface_Prim_Op) then
1624 while Present (Alias (Iface_Prim_Op)) loop
1625 Iface_Prim_Op := Alias (Iface_Prim_Op);
1628 -- The current primitive operation can be overriden by the
1629 -- generated entry wrapper.
1631 if Overriding_Possible (Iface_Prim_Op, Proc_Nam) then
1632 First_Param := First (Parameter_Specifications
1633 (Parent (Iface_Prim_Op)));
1639 Next_Elmt (Iface_Prim_Op_Elmt);
1643 exit Examine_Parents when Etype (Iface) = Iface;
1645 Iface := Etype (Iface);
1646 end loop Examine_Parents;
1648 if Present (Abstract_Interfaces
1649 (Corresponding_Record_Type (Scope (Proc_Nam))))
1651 Iface_Elmt := First_Elmt
1652 (Abstract_Interfaces
1653 (Corresponding_Record_Type (Scope (Proc_Nam))));
1654 Examine_Interfaces : while Present (Iface_Elmt) loop
1655 Iface := Node (Iface_Elmt);
1657 if Present (Primitive_Operations (Iface)) then
1658 Iface_Prim_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
1659 while Present (Iface_Prim_Op_Elmt) loop
1660 Iface_Prim_Op := Node (Iface_Prim_Op_Elmt);
1662 if not Is_Predefined_Dispatching_Operation
1665 while Present (Alias (Iface_Prim_Op)) loop
1666 Iface_Prim_Op := Alias (Iface_Prim_Op);
1669 -- The current primitive operation can be overriden by
1670 -- the generated entry wrapper.
1672 if Overriding_Possible (Iface_Prim_Op, Proc_Nam) then
1673 First_Param := First (Parameter_Specifications
1674 (Parent (Iface_Prim_Op)));
1680 Next_Elmt (Iface_Prim_Op_Elmt);
1684 Next_Elmt (Iface_Elmt);
1685 end loop Examine_Interfaces;
1688 -- Return if no interface primitive can be overriden
1694 New_Formals := Replicate_Entry_Formals (Loc, Formals);
1696 -- ??? Certain source packages contain protected or task types that do
1697 -- not implement any interfaces and are compiled with the -gnat05
1698 -- switch. In this case, a default first parameter is created.
1700 if Present (First_Param) then
1701 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
1703 Make_Access_Definition (Loc,
1705 New_Reference_To (Obj_Typ, Loc));
1707 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
1711 Make_Parameter_Specification (Loc,
1712 Defining_Identifier =>
1713 Make_Defining_Identifier (Loc, Name_uO),
1714 In_Present => In_Present (First_Param),
1715 Out_Present => Out_Present (First_Param),
1716 Parameter_Type => Obj_Param_Typ);
1720 Make_Parameter_Specification (Loc,
1721 Defining_Identifier =>
1722 Make_Defining_Identifier (Loc, Name_uO),
1724 Out_Present => True,
1725 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
1728 Prepend_To (New_Formals, Obj_Param);
1730 -- Minimum decoration needed to catch the entity in
1731 -- Sem_Ch6.Override_Dispatching_Operation
1733 if Ekind (Proc_Nam) = E_Procedure
1734 or else Ekind (Proc_Nam) = E_Entry
1736 Set_Ekind (New_Name_Id, E_Procedure);
1737 Set_Is_Primitive_Wrapper (New_Name_Id);
1738 Set_Wrapped_Entity (New_Name_Id, Proc_Nam);
1741 Make_Procedure_Specification (Loc,
1742 Defining_Unit_Name => New_Name_Id,
1743 Parameter_Specifications => New_Formals);
1745 else pragma Assert (Ekind (Proc_Nam) = E_Function);
1746 Set_Ekind (New_Name_Id, E_Function);
1749 Make_Function_Specification (Loc,
1750 Defining_Unit_Name => New_Name_Id,
1751 Parameter_Specifications => New_Formals,
1752 Result_Definition =>
1753 New_Copy (Result_Definition (Parent (Proc_Nam))));
1755 end Build_Wrapper_Spec;
1757 ---------------------------
1758 -- Build_Find_Body_Index --
1759 ---------------------------
1761 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
1762 Loc : constant Source_Ptr := Sloc (Typ);
1765 Has_F : Boolean := False;
1767 If_St : Node_Id := Empty;
1770 Decls : List_Id := New_List;
1773 Siz : Node_Id := Empty;
1775 procedure Add_If_Clause (Expr : Node_Id);
1776 -- Add test for range of current entry
1778 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
1779 -- If a bound of an entry is given by a discriminant, retrieve the
1780 -- actual value of the discriminant from the enclosing object.
1786 procedure Add_If_Clause (Expr : Node_Id) is
1788 Stats : constant List_Id :=
1790 Make_Return_Statement (Loc,
1791 Expression => Make_Integer_Literal (Loc, Index + 1)));
1794 -- Index for current entry body
1798 -- Compute total length of entry queues so far
1806 Right_Opnd => Expr);
1811 Left_Opnd => Make_Identifier (Loc, Name_uE),
1814 -- Map entry queue indices in the range of the current family
1815 -- into the current index, that designates the entry body.
1819 Make_Implicit_If_Statement (Typ,
1821 Then_Statements => Stats,
1822 Elsif_Parts => New_List);
1828 Make_Elsif_Part (Loc,
1830 Then_Statements => Stats),
1831 Elsif_Parts (If_St));
1835 ------------------------------
1836 -- Convert_Discriminant_Ref --
1837 ------------------------------
1839 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
1843 if Is_Entity_Name (Bound)
1844 and then Ekind (Entity (Bound)) = E_Discriminant
1847 Make_Selected_Component (Loc,
1849 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
1850 Make_Explicit_Dereference (Loc,
1851 Make_Identifier (Loc, Name_uObject))),
1852 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
1853 Set_Etype (B, Etype (Entity (Bound)));
1855 B := New_Copy_Tree (Bound);
1859 end Convert_Discriminant_Ref;
1861 -- Start of processing for Build_Find_Body_Index
1864 Spec := Build_Find_Body_Index_Spec (Typ);
1866 Ent := First_Entity (Typ);
1867 while Present (Ent) loop
1868 if Ekind (Ent) = E_Entry_Family then
1878 -- If the protected type has no entry families, there is a one-one
1879 -- correspondence between entry queue and entry body.
1882 Make_Return_Statement (Loc,
1883 Expression => Make_Identifier (Loc, Name_uE));
1886 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
1889 -- if E <= l1 then return 1;
1890 -- elsif E <= l1 + l2 then return 2;
1895 Ent := First_Entity (Typ);
1897 Add_Object_Pointer (Decls, Typ, Loc);
1899 while Present (Ent) loop
1901 if Ekind (Ent) = E_Entry then
1902 Add_If_Clause (Make_Integer_Literal (Loc, 1));
1904 elsif Ekind (Ent) = E_Entry_Family then
1906 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1907 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
1908 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
1909 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
1918 Make_Return_Statement (Loc,
1919 Expression => Make_Integer_Literal (Loc, 1));
1921 elsif Nkind (Ret) = N_If_Statement then
1923 -- Ranges are in increasing order, so last one doesn't need guard
1926 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
1929 Set_Else_Statements (Ret, Then_Statements (Nod));
1935 Make_Subprogram_Body (Loc,
1936 Specification => Spec,
1937 Declarations => Decls,
1938 Handled_Statement_Sequence =>
1939 Make_Handled_Sequence_Of_Statements (Loc,
1940 Statements => New_List (Ret)));
1941 end Build_Find_Body_Index;
1943 --------------------------------
1944 -- Build_Find_Body_Index_Spec --
1945 --------------------------------
1947 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
1948 Loc : constant Source_Ptr := Sloc (Typ);
1949 Id : constant Entity_Id :=
1950 Make_Defining_Identifier (Loc,
1951 Chars => New_External_Name (Chars (Typ), 'F'));
1952 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
1953 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
1957 Make_Function_Specification (Loc,
1958 Defining_Unit_Name => Id,
1959 Parameter_Specifications => New_List (
1960 Make_Parameter_Specification (Loc,
1961 Defining_Identifier => Parm1,
1963 New_Reference_To (RTE (RE_Address), Loc)),
1965 Make_Parameter_Specification (Loc,
1966 Defining_Identifier => Parm2,
1968 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1969 Result_Definition => New_Occurrence_Of (
1970 RTE (RE_Protected_Entry_Index), Loc));
1971 end Build_Find_Body_Index_Spec;
1973 -------------------------
1974 -- Build_Master_Entity --
1975 -------------------------
1977 procedure Build_Master_Entity (E : Entity_Id) is
1978 Loc : constant Source_Ptr := Sloc (E);
1986 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
1987 -- in internal scopes, unless present already.. Required for nested
1988 -- limited aggregates. This could use some more explanation ????
1990 if Ada_Version >= Ada_05 then
1991 while Is_Internal (S) loop
1996 -- Nothing to do if we already built a master entity for this scope
1997 -- or if there is no task hierarchy.
1999 if Has_Master_Entity (S)
2000 or else Restriction_Active (No_Task_Hierarchy)
2005 -- Otherwise first build the master entity
2006 -- _Master : constant Master_Id := Current_Master.all;
2007 -- and insert it just before the current declaration
2010 Make_Object_Declaration (Loc,
2011 Defining_Identifier =>
2012 Make_Defining_Identifier (Loc, Name_uMaster),
2013 Constant_Present => True,
2014 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2016 Make_Explicit_Dereference (Loc,
2017 New_Reference_To (RTE (RE_Current_Master), Loc)));
2020 Insert_Before (P, Decl);
2023 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2024 -- non-internal scope selected above.
2026 if Ada_Version >= Ada_05 then
2027 Set_Has_Master_Entity (S);
2029 Set_Has_Master_Entity (Scope (E));
2032 -- Now mark the containing scope as a task master
2034 while Nkind (P) /= N_Compilation_Unit loop
2037 -- If we fall off the top, we are at the outer level, and the
2038 -- environment task is our effective master, so nothing to mark.
2040 if Nkind (P) = N_Task_Body
2041 or else Nkind (P) = N_Block_Statement
2042 or else Nkind (P) = N_Subprogram_Body
2044 Set_Is_Task_Master (P, True);
2047 elsif Nkind (Parent (P)) = N_Subunit then
2048 P := Corresponding_Stub (Parent (P));
2051 end Build_Master_Entity;
2053 ---------------------------
2054 -- Build_Protected_Entry --
2055 ---------------------------
2057 function Build_Protected_Entry
2060 Pid : Node_Id) return Node_Id
2062 Loc : constant Source_Ptr := Sloc (N);
2064 End_Lab : constant Node_Id :=
2065 End_Label (Handled_Statement_Sequence (N));
2066 End_Loc : constant Source_Ptr :=
2067 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2068 -- Used for the generated call to Complete_Entry_Body
2070 Han_Loc : Source_Ptr;
2071 -- Used for the exception handler, inserted at end of the body
2073 Op_Decls : constant List_Id := New_List;
2081 -- Set the source location on the exception handler only when debugging
2082 -- the expanded code (see Make_Implicit_Exception_Handler).
2084 if Debug_Generated_Code then
2087 Han_Loc := No_Location;
2091 Make_Defining_Identifier (Loc,
2092 Chars => Chars (Protected_Body_Subprogram (Ent)));
2093 Espec := Build_Protected_Entry_Specification (Edef, Empty, Loc);
2095 -- <object pointer declaration>
2097 -- Add object pointer declaration. This is needed by the discriminal and
2098 -- prival renamings, which should already have been inserted into the
2099 -- declaration list.
2101 Add_Object_Pointer (Op_Decls, Pid, Loc);
2103 -- Add renamings for formals for use by debugger
2105 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2108 or else Restriction_Active (No_Entry_Queue) = False
2109 or else Number_Entries (Pid) > 1
2110 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile)
2112 Complete := New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2115 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2118 Op_Stats := New_List (
2119 Make_Block_Statement (Loc,
2120 Declarations => Declarations (N),
2121 Handled_Statement_Sequence =>
2122 Handled_Statement_Sequence (N)),
2124 Make_Procedure_Call_Statement (End_Loc,
2126 Parameter_Associations => New_List (
2127 Make_Attribute_Reference (End_Loc,
2129 Make_Selected_Component (End_Loc,
2131 Make_Identifier (End_Loc, Name_uObject),
2134 Make_Identifier (End_Loc, Name_uObject)),
2135 Attribute_Name => Name_Unchecked_Access))));
2137 -- When exceptions can not be propagated, we never need to call
2138 -- Exception_Complete_Entry_Body
2140 if No_Exception_Handlers_Set then
2142 Make_Subprogram_Body (Loc,
2143 Specification => Espec,
2144 Declarations => Op_Decls,
2145 Handled_Statement_Sequence =>
2146 Make_Handled_Sequence_Of_Statements (Loc,
2148 End_Label => End_Lab));
2151 Ohandle := Make_Others_Choice (Loc);
2152 Set_All_Others (Ohandle);
2155 or else Restriction_Active (No_Entry_Queue) = False
2156 or else Number_Entries (Pid) > 1
2157 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile)
2160 New_Reference_To (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2163 Complete := New_Reference_To (
2164 RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2167 -- Create body of entry procedure. The renaming declarations are
2168 -- placed ahead of the block that contains the actual entry body.
2171 Make_Subprogram_Body (Loc,
2172 Specification => Espec,
2173 Declarations => Op_Decls,
2174 Handled_Statement_Sequence =>
2175 Make_Handled_Sequence_Of_Statements (Loc,
2176 Statements => Op_Stats,
2177 End_Label => End_Lab,
2178 Exception_Handlers => New_List (
2179 Make_Implicit_Exception_Handler (Han_Loc,
2180 Exception_Choices => New_List (Ohandle),
2182 Statements => New_List (
2183 Make_Procedure_Call_Statement (Han_Loc,
2185 Parameter_Associations => New_List (
2186 Make_Attribute_Reference (Han_Loc,
2188 Make_Selected_Component (Han_Loc,
2190 Make_Identifier (Han_Loc, Name_uObject),
2192 Make_Identifier (Han_Loc, Name_uObject)),
2193 Attribute_Name => Name_Unchecked_Access),
2195 Make_Function_Call (Han_Loc,
2196 Name => New_Reference_To (
2197 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2199 end Build_Protected_Entry;
2201 -----------------------------------------
2202 -- Build_Protected_Entry_Specification --
2203 -----------------------------------------
2205 function Build_Protected_Entry_Specification
2206 (Def_Id : Entity_Id;
2208 Loc : Source_Ptr) return Node_Id
2213 Set_Needs_Debug_Info (Def_Id);
2214 P := Make_Defining_Identifier (Loc, Name_uP);
2216 if Present (Ent_Id) then
2217 Append_Elmt (P, Accept_Address (Ent_Id));
2220 return Make_Procedure_Specification (Loc,
2221 Defining_Unit_Name => Def_Id,
2222 Parameter_Specifications => New_List (
2223 Make_Parameter_Specification (Loc,
2224 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2226 New_Reference_To (RTE (RE_Address), Loc)),
2228 Make_Parameter_Specification (Loc,
2229 Defining_Identifier => P,
2231 New_Reference_To (RTE (RE_Address), Loc)),
2233 Make_Parameter_Specification (Loc,
2234 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE),
2236 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2237 end Build_Protected_Entry_Specification;
2239 --------------------------
2240 -- Build_Protected_Spec --
2241 --------------------------
2243 function Build_Protected_Spec
2245 Obj_Type : Entity_Id;
2246 Unprotected : Boolean := False;
2247 Ident : Entity_Id) return List_Id
2249 Loc : constant Source_Ptr := Sloc (N);
2252 New_Plist : List_Id;
2253 New_Param : Node_Id;
2256 New_Plist := New_List;
2257 Formal := First_Formal (Ident);
2258 while Present (Formal) loop
2260 Make_Parameter_Specification (Loc,
2261 Defining_Identifier =>
2262 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2263 In_Present => In_Present (Parent (Formal)),
2264 Out_Present => Out_Present (Parent (Formal)),
2266 New_Reference_To (Etype (Formal), Loc));
2269 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2272 Append (New_Param, New_Plist);
2273 Next_Formal (Formal);
2276 -- If the subprogram is a procedure and the context is not an access
2277 -- to protected subprogram, the parameter is in-out. Otherwise it is
2281 Make_Parameter_Specification (Loc,
2282 Defining_Identifier =>
2283 Make_Defining_Identifier (Loc, Name_uObject),
2286 (Etype (Ident) = Standard_Void_Type
2287 and then not Is_RTE (Obj_Type, RE_Address)),
2288 Parameter_Type => New_Reference_To (Obj_Type, Loc));
2289 Set_Needs_Debug_Info (Defining_Identifier (Decl));
2290 Prepend_To (New_Plist, Decl);
2293 end Build_Protected_Spec;
2295 ---------------------------------------
2296 -- Build_Protected_Sub_Specification --
2297 ---------------------------------------
2299 function Build_Protected_Sub_Specification
2301 Prottyp : Entity_Id;
2302 Mode : Subprogram_Protection_Mode) return Node_Id
2304 Loc : constant Source_Ptr := Sloc (N);
2308 New_Plist : List_Id;
2311 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2312 (Dispatching_Mode => ' ',
2313 Protected_Mode => 'P',
2314 Unprotected_Mode => 'N');
2318 (Defining_Unit_Name (Specification (N))) = E_Subprogram_Body
2320 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2325 Ident := Defining_Unit_Name (Specification (Decl));
2328 Build_Protected_Spec (Decl,
2329 Corresponding_Record_Type (Prottyp),
2330 Mode = Unprotected_Mode, Ident);
2333 Make_Defining_Identifier (Loc,
2334 Chars => Build_Selected_Name (Prottyp, Ident, Append_Chr (Mode)));
2336 -- The unprotected operation carries the user code, and debugging
2337 -- information must be generated for it, even though this spec does
2338 -- not come from source. It is also convenient to allow gdb to step
2339 -- into the protected operation, even though it only contains lock/
2342 Set_Needs_Debug_Info (New_Id);
2344 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2346 Make_Procedure_Specification (Loc,
2347 Defining_Unit_Name => New_Id,
2348 Parameter_Specifications => New_Plist);
2351 -- We need to create a new specification for the anonymous
2355 Make_Function_Specification (Loc,
2356 Defining_Unit_Name => New_Id,
2357 Parameter_Specifications => New_Plist,
2358 Result_Definition =>
2359 Copy_Result_Type (Result_Definition (Specification (Decl))));
2361 Set_Return_Present (Defining_Unit_Name (New_Spec));
2364 end Build_Protected_Sub_Specification;
2366 -------------------------------------
2367 -- Build_Protected_Subprogram_Body --
2368 -------------------------------------
2370 function Build_Protected_Subprogram_Body
2373 N_Op_Spec : Node_Id) return Node_Id
2375 Loc : constant Source_Ptr := Sloc (N);
2377 P_Op_Spec : Node_Id;
2380 Unprot_Call : Node_Id;
2382 Lock_Name : Node_Id;
2383 Lock_Stmt : Node_Id;
2384 Service_Name : Node_Id;
2386 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2387 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2389 Object_Parm : Node_Id;
2392 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2393 -- Tell whether a given subprogram cannot raise an exception
2395 -----------------------
2396 -- Is_Exception_Safe --
2397 -----------------------
2399 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2401 function Has_Side_Effect (N : Node_Id) return Boolean;
2402 -- Return True whenever encountering a subprogram call or raise
2403 -- statement of any kind in the sequence of statements
2405 ---------------------
2406 -- Has_Side_Effect --
2407 ---------------------
2409 -- What is this doing buried two levels down in exp_ch9. It seems
2410 -- like a generally useful function, and indeed there may be code
2411 -- duplication going on here ???
2413 function Has_Side_Effect (N : Node_Id) return Boolean is
2417 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
2418 -- Indicate whether N is a subprogram call or a raise statement
2420 ----------------------
2421 -- Is_Call_Or_Raise --
2422 ----------------------
2424 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
2426 return Nkind (N) = N_Procedure_Call_Statement
2427 or else Nkind (N) = N_Function_Call
2428 or else Nkind (N) = N_Raise_Statement
2429 or else Nkind (N) = N_Raise_Constraint_Error
2430 or else Nkind (N) = N_Raise_Program_Error
2431 or else Nkind (N) = N_Raise_Storage_Error;
2432 end Is_Call_Or_Raise;
2434 -- Start of processing for Has_Side_Effect
2438 while Present (Stmt) loop
2439 if Is_Call_Or_Raise (Stmt) then
2443 -- An object declaration can also contain a function call
2444 -- or a raise statement
2446 if Nkind (Stmt) = N_Object_Declaration then
2447 Expr := Expression (Stmt);
2449 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
2458 end Has_Side_Effect;
2460 -- Start of processing for Is_Exception_Safe
2463 -- If the checks handled by the back end are not disabled, we cannot
2464 -- ensure that no exception will be raised.
2466 if not Access_Checks_Suppressed (Empty)
2467 or else not Discriminant_Checks_Suppressed (Empty)
2468 or else not Range_Checks_Suppressed (Empty)
2469 or else not Index_Checks_Suppressed (Empty)
2470 or else Opt.Stack_Checking_Enabled
2475 if Has_Side_Effect (First (Declarations (Subprogram)))
2478 First (Statements (Handled_Statement_Sequence (Subprogram))))
2484 end Is_Exception_Safe;
2486 -- Start of processing for Build_Protected_Subprogram_Body
2489 Op_Spec := Specification (N);
2490 Exc_Safe := Is_Exception_Safe (N);
2493 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
2495 -- Build a list of the formal parameters of the protected version of
2496 -- the subprogram to use as the actual parameters of the unprotected
2499 Uactuals := New_List;
2500 Pformal := First (Parameter_Specifications (P_Op_Spec));
2501 while Present (Pformal) loop
2503 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
2508 -- Make a call to the unprotected version of the subprogram built above
2509 -- for use by the protected version built below.
2511 if Nkind (Op_Spec) = N_Function_Specification then
2513 R := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2515 Make_Object_Declaration (Loc,
2516 Defining_Identifier => R,
2517 Constant_Present => True,
2518 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
2520 Make_Function_Call (Loc,
2521 Name => Make_Identifier (Loc,
2522 Chars (Defining_Unit_Name (N_Op_Spec))),
2523 Parameter_Associations => Uactuals));
2524 Return_Stmt := Make_Return_Statement (Loc,
2525 Expression => New_Reference_To (R, Loc));
2528 Unprot_Call := Make_Return_Statement (Loc,
2529 Expression => Make_Function_Call (Loc,
2531 Make_Identifier (Loc,
2532 Chars (Defining_Unit_Name (N_Op_Spec))),
2533 Parameter_Associations => Uactuals));
2537 Unprot_Call := Make_Procedure_Call_Statement (Loc,
2539 Make_Identifier (Loc,
2540 Chars (Defining_Unit_Name (N_Op_Spec))),
2541 Parameter_Associations => Uactuals);
2544 -- Wrap call in block that will be covered by an at_end handler
2546 if not Exc_Safe then
2547 Unprot_Call := Make_Block_Statement (Loc,
2548 Handled_Statement_Sequence =>
2549 Make_Handled_Sequence_Of_Statements (Loc,
2550 Statements => New_List (Unprot_Call)));
2553 -- Make the protected subprogram body. This locks the protected
2554 -- object and calls the unprotected version of the subprogram.
2556 -- If the protected object is controlled (i.e it has entries or
2557 -- needs finalization for interrupt handling), call Lock_Entries,
2558 -- except if the protected object follows the Ravenscar profile, in
2559 -- which case call Lock_Entry, otherwise call the simplified version,
2562 if Has_Entries (Pid)
2563 or else Has_Interrupt_Handler (Pid)
2564 or else (Has_Attach_Handler (Pid)
2565 and then not Restricted_Profile)
2566 or else (Ada_Version >= Ada_05
2567 and then Present (Interface_List (Parent (Pid))))
2570 or else Restriction_Active (No_Entry_Queue) = False
2571 or else Number_Entries (Pid) > 1
2572 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile)
2574 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
2575 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
2578 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
2579 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
2583 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
2584 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
2588 Make_Attribute_Reference (Loc,
2590 Make_Selected_Component (Loc,
2592 Make_Identifier (Loc, Name_uObject),
2594 Make_Identifier (Loc, Name_uObject)),
2595 Attribute_Name => Name_Unchecked_Access);
2597 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
2599 Parameter_Associations => New_List (Object_Parm));
2601 if Abort_Allowed then
2603 Make_Procedure_Call_Statement (Loc,
2604 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
2605 Parameter_Associations => Empty_List),
2609 Stmts := New_List (Lock_Stmt);
2612 if not Exc_Safe then
2613 Append (Unprot_Call, Stmts);
2615 if Nkind (Op_Spec) = N_Function_Specification then
2617 Stmts := Empty_List;
2619 Append (Unprot_Call, Stmts);
2623 Make_Procedure_Call_Statement (Loc,
2624 Name => Service_Name,
2625 Parameter_Associations =>
2626 New_List (New_Copy_Tree (Object_Parm))),
2629 if Abort_Allowed then
2631 Make_Procedure_Call_Statement (Loc,
2632 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
2633 Parameter_Associations => Empty_List),
2637 if Nkind (Op_Spec) = N_Function_Specification then
2638 Append (Return_Stmt, Stmts);
2639 Append (Make_Block_Statement (Loc,
2640 Declarations => New_List (Unprot_Call),
2641 Handled_Statement_Sequence =>
2642 Make_Handled_Sequence_Of_Statements (Loc,
2643 Statements => Stmts)), Pre_Stmts);
2649 Make_Subprogram_Body (Loc,
2650 Declarations => Empty_List,
2651 Specification => P_Op_Spec,
2652 Handled_Statement_Sequence =>
2653 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
2655 if not Exc_Safe then
2656 Set_Is_Protected_Subprogram_Body (Sub_Body);
2660 end Build_Protected_Subprogram_Body;
2662 -------------------------------------
2663 -- Build_Protected_Subprogram_Call --
2664 -------------------------------------
2666 procedure Build_Protected_Subprogram_Call
2670 External : Boolean := True)
2672 Loc : constant Source_Ptr := Sloc (N);
2673 Sub : constant Entity_Id := Entity (Name);
2679 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
2682 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
2685 if Present (Parameter_Associations (N)) then
2686 Params := New_Copy_List_Tree (Parameter_Associations (N));
2691 Prepend (Rec, Params);
2693 if Ekind (Sub) = E_Procedure then
2695 Make_Procedure_Call_Statement (Loc,
2697 Parameter_Associations => Params));
2700 pragma Assert (Ekind (Sub) = E_Function);
2702 Make_Function_Call (Loc,
2704 Parameter_Associations => Params));
2708 and then Nkind (Rec) = N_Unchecked_Type_Conversion
2709 and then Is_Entity_Name (Expression (Rec))
2710 and then Is_Shared_Passive (Entity (Expression (Rec)))
2712 Add_Shared_Var_Lock_Procs (N);
2714 end Build_Protected_Subprogram_Call;
2716 -------------------------
2717 -- Build_Selected_Name --
2718 -------------------------
2720 function Build_Selected_Name
2721 (Prefix : Entity_Id;
2722 Selector : Entity_Id;
2723 Append_Char : Character := ' ') return Name_Id
2725 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
2726 Select_Len : Natural;
2729 Get_Name_String (Chars (Selector));
2730 Select_Len := Name_Len;
2731 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
2732 Get_Name_String (Chars (Prefix));
2734 -- If scope is anonymous type, discard suffix to recover name of
2735 -- single protected object. Otherwise use protected type name.
2737 if Name_Buffer (Name_Len) = 'T' then
2738 Name_Len := Name_Len - 1;
2741 Name_Buffer (Name_Len + 1) := '_';
2742 Name_Buffer (Name_Len + 2) := '_';
2744 Name_Len := Name_Len + 2;
2745 for J in 1 .. Select_Len loop
2746 Name_Len := Name_Len + 1;
2747 Name_Buffer (Name_Len) := Select_Buffer (J);
2750 -- Now add the Append_Char if specified. The encoding to follow
2751 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
2752 -- then the entity is associated to a protected type subprogram.
2753 -- Otherwise, it is a protected type entry. For each case, the
2754 -- encoding to follow for the suffix is documented in exp_dbug.ads.
2756 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
2758 if Append_Char /= ' ' then
2759 if Append_Char = 'P' or Append_Char = 'N' then
2760 Name_Len := Name_Len + 1;
2761 Name_Buffer (Name_Len) := Append_Char;
2764 Name_Buffer (Name_Len + 1) := '_';
2765 Name_Buffer (Name_Len + 2) := Append_Char;
2766 Name_Len := Name_Len + 2;
2767 return New_External_Name (Name_Find, ' ', -1);
2772 end Build_Selected_Name;
2774 -----------------------------
2775 -- Build_Simple_Entry_Call --
2776 -----------------------------
2778 -- A task entry call is converted to a call to Call_Simple
2781 -- P : parms := (parm, parm, parm);
2783 -- Call_Simple (acceptor-task, entry-index, P'Address);
2789 -- Here Pnn is an aggregate of the type constructed for the entry to hold
2790 -- the parameters, and the constructed aggregate value contains either the
2791 -- parameters or, in the case of non-elementary types, references to these
2792 -- parameters. Then the address of this aggregate is passed to the runtime
2793 -- routine, along with the task id value and the task entry index value.
2794 -- Pnn is only required if parameters are present.
2796 -- The assignments after the call are present only in the case of in-out
2797 -- or out parameters for elementary types, and are used to assign back the
2798 -- resulting values of such parameters.
2800 -- Note: the reason that we insert a block here is that in the context
2801 -- of selects, conditional entry calls etc. the entry call statement
2802 -- appears on its own, not as an element of a list.
2804 -- A protected entry call is converted to a Protected_Entry_Call:
2807 -- P : E1_Params := (param, param, param);
2809 -- Bnn : Communications_Block;
2812 -- P : E1_Params := (param, param, param);
2813 -- Bnn : Communications_Block;
2816 -- Protected_Entry_Call (
2817 -- Object => po._object'Access,
2818 -- E => <entry index>;
2819 -- Uninterpreted_Data => P'Address;
2820 -- Mode => Simple_Call;
2827 procedure Build_Simple_Entry_Call
2836 -- If call has been inlined, nothing left to do
2838 if Nkind (N) = N_Block_Statement then
2842 -- Convert entry call to Call_Simple call
2845 Loc : constant Source_Ptr := Sloc (N);
2846 Parms : constant List_Id := Parameter_Associations (N);
2847 Stats : constant List_Id := New_List;
2850 Comm_Name : Entity_Id;
2854 Ent_Acc : Entity_Id;
2856 Iface_Tag : Entity_Id;
2857 Iface_Typ : Entity_Id;
2870 -- Simple entry and entry family cases merge here
2872 Ent := Entity (Ename);
2873 Ent_Acc := Entry_Parameters_Type (Ent);
2874 Conctyp := Etype (Concval);
2876 -- If prefix is an access type, dereference to obtain the task type
2878 if Is_Access_Type (Conctyp) then
2879 Conctyp := Designated_Type (Conctyp);
2882 -- Special case for protected subprogram calls
2884 if Is_Protected_Type (Conctyp)
2885 and then Is_Subprogram (Entity (Ename))
2887 if not Is_Eliminated (Entity (Ename)) then
2888 Build_Protected_Subprogram_Call
2889 (N, Ename, Convert_Concurrent (Concval, Conctyp));
2896 -- First parameter is the Task_Id value from the task value or the
2897 -- Object from the protected object value, obtained by selecting
2898 -- the _Task_Id or _Object from the result of doing an unchecked
2899 -- conversion to convert the value to the corresponding record type.
2901 Parm1 := Concurrent_Ref (Concval);
2903 -- Second parameter is the entry index, computed by the routine
2904 -- provided for this purpose. The value of this expression is
2905 -- assigned to an intermediate variable to assure that any entry
2906 -- family index expressions are evaluated before the entry
2910 or else Restriction_Active (No_Entry_Queue) = False
2911 or else not Is_Protected_Type (Conctyp)
2912 or else Number_Entries (Conctyp) > 1
2913 or else (Has_Attach_Handler (Conctyp)
2914 and then not Restricted_Profile)
2916 X := Make_Defining_Identifier (Loc, Name_uX);
2919 Make_Object_Declaration (Loc,
2920 Defining_Identifier => X,
2921 Object_Definition =>
2922 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2923 Expression => Actual_Index_Expression (
2924 Loc, Entity (Ename), Index, Concval));
2926 Decls := New_List (Xdecl);
2927 Parm2 := New_Reference_To (X, Loc);
2935 -- The third parameter is the packaged parameters. If there are
2936 -- none, then it is just the null address, since nothing is passed.
2939 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
2942 -- Case of parameters present, where third argument is the address
2943 -- of a packaged record containing the required parameter values.
2946 -- First build a list of parameter values, which are references to
2947 -- objects of the parameter types.
2951 Actual := First_Actual (N);
2952 Formal := First_Formal (Ent);
2954 while Present (Actual) loop
2956 -- If it is a by_copy_type, copy it to a new variable. The
2957 -- packaged record has a field that points to this variable.
2959 if Is_By_Copy_Type (Etype (Actual)) then
2961 Make_Object_Declaration (Loc,
2962 Defining_Identifier =>
2963 Make_Defining_Identifier (Loc,
2964 Chars => New_Internal_Name ('J')),
2965 Aliased_Present => True,
2966 Object_Definition =>
2967 New_Reference_To (Etype (Formal), Loc));
2969 -- Mark the object as not needing initialization since the
2970 -- initialization is performed separately, avoiding errors
2971 -- on cases such as formals of null-excluding access types.
2973 Set_No_Initialization (N_Node);
2975 -- We have to make an assignment statement separate for the
2976 -- case of limited type. We cannot assign it unless the
2977 -- Assignment_OK flag is set first.
2979 if Ekind (Formal) /= E_Out_Parameter then
2981 New_Reference_To (Defining_Identifier (N_Node), Loc);
2982 Set_Assignment_OK (N_Var);
2984 Make_Assignment_Statement (Loc,
2986 Expression => Relocate_Node (Actual)));
2989 Append (N_Node, Decls);
2992 Make_Attribute_Reference (Loc,
2993 Attribute_Name => Name_Unchecked_Access,
2995 New_Reference_To (Defining_Identifier (N_Node), Loc)));
2997 -- Interface class-wide formal
2999 if Ada_Version >= Ada_05
3000 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3001 and then Is_Interface (Etype (Formal))
3003 Iface_Typ := Etype (Etype (Formal));
3006 -- formal_iface_type! (actual.iface_tag)'reference
3009 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3010 pragma Assert (Present (Iface_Tag));
3013 Make_Reference (Loc,
3014 Unchecked_Convert_To (Iface_Typ,
3015 Make_Selected_Component (Loc,
3017 Relocate_Node (Actual),
3019 New_Reference_To (Iface_Tag, Loc)))));
3025 Make_Reference (Loc, Relocate_Node (Actual)));
3029 Next_Actual (Actual);
3030 Next_Formal_With_Extras (Formal);
3033 -- Now build the declaration of parameters initialized with the
3034 -- aggregate containing this constructed parameter list.
3036 P := Make_Defining_Identifier (Loc, Name_uP);
3039 Make_Object_Declaration (Loc,
3040 Defining_Identifier => P,
3041 Object_Definition =>
3042 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3044 Make_Aggregate (Loc, Expressions => Plist));
3047 Make_Attribute_Reference (Loc,
3048 Attribute_Name => Name_Address,
3049 Prefix => New_Reference_To (P, Loc));
3051 Append (Pdecl, Decls);
3054 -- Now we can create the call, case of protected type
3056 if Is_Protected_Type (Conctyp) then
3058 or else Restriction_Active (No_Entry_Queue) = False
3059 or else Number_Entries (Conctyp) > 1
3060 or else (Has_Attach_Handler (Conctyp)
3061 and then not Restricted_Profile)
3063 -- Change the type of the index declaration
3065 Set_Object_Definition (Xdecl,
3066 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3068 -- Some additional declarations for protected entry calls
3074 -- Bnn : Communications_Block;
3077 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3080 Make_Object_Declaration (Loc,
3081 Defining_Identifier => Comm_Name,
3082 Object_Definition =>
3083 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3085 -- Some additional statements for protected entry calls
3087 -- Protected_Entry_Call (
3088 -- Object => po._object'Access,
3089 -- E => <entry index>;
3090 -- Uninterpreted_Data => P'Address;
3091 -- Mode => Simple_Call;
3095 Make_Procedure_Call_Statement (Loc,
3097 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3099 Parameter_Associations => New_List (
3100 Make_Attribute_Reference (Loc,
3101 Attribute_Name => Name_Unchecked_Access,
3105 New_Reference_To (RTE (RE_Simple_Call), Loc),
3106 New_Occurrence_Of (Comm_Name, Loc)));
3109 -- Protected_Single_Entry_Call (
3110 -- Object => po._object'Access,
3111 -- Uninterpreted_Data => P'Address;
3112 -- Mode => Simple_Call);
3115 Make_Procedure_Call_Statement (Loc,
3116 Name => New_Reference_To (
3117 RTE (RE_Protected_Single_Entry_Call), Loc),
3119 Parameter_Associations => New_List (
3120 Make_Attribute_Reference (Loc,
3121 Attribute_Name => Name_Unchecked_Access,
3124 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3127 -- Case of task type
3131 Make_Procedure_Call_Statement (Loc,
3132 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3133 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3137 Append_To (Stats, Call);
3139 -- If there are out or in/out parameters by copy add assignment
3140 -- statements for the result values.
3142 if Present (Parms) then
3143 Actual := First_Actual (N);
3144 Formal := First_Formal (Ent);
3146 Set_Assignment_OK (Actual);
3147 while Present (Actual) loop
3148 if Is_By_Copy_Type (Etype (Actual))
3149 and then Ekind (Formal) /= E_In_Parameter
3152 Make_Assignment_Statement (Loc,
3153 Name => New_Copy (Actual),
3155 Make_Explicit_Dereference (Loc,
3156 Make_Selected_Component (Loc,
3157 Prefix => New_Reference_To (P, Loc),
3159 Make_Identifier (Loc, Chars (Formal)))));
3161 -- In all cases (including limited private types) we want
3162 -- the assignment to be valid.
3164 Set_Assignment_OK (Name (N_Node));
3166 -- If the call is the triggering alternative in an
3167 -- asynchronous select, or the entry_call alternative of a
3168 -- conditional entry call, the assignments for in-out
3169 -- parameters are incorporated into the statement list that
3170 -- follows, so that there are executed only if the entry
3173 if (Nkind (Parent (N)) = N_Triggering_Alternative
3174 and then N = Triggering_Statement (Parent (N)))
3176 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3177 and then N = Entry_Call_Statement (Parent (N)))
3179 if No (Statements (Parent (N))) then
3180 Set_Statements (Parent (N), New_List);
3183 Prepend (N_Node, Statements (Parent (N)));
3186 Insert_After (Call, N_Node);
3190 Next_Actual (Actual);
3191 Next_Formal_With_Extras (Formal);
3195 -- Finally, create block and analyze it
3198 Make_Block_Statement (Loc,
3199 Declarations => Decls,
3200 Handled_Statement_Sequence =>
3201 Make_Handled_Sequence_Of_Statements (Loc,
3202 Statements => Stats)));
3206 end Build_Simple_Entry_Call;
3208 --------------------------------
3209 -- Build_Task_Activation_Call --
3210 --------------------------------
3212 procedure Build_Task_Activation_Call (N : Node_Id) is
3213 Loc : constant Source_Ptr := Sloc (N);
3220 -- Get the activation chain entity. Except in the case of a package
3221 -- body, this is in the node that was passed. For a package body, we
3222 -- have to find the corresponding package declaration node.
3224 if Nkind (N) = N_Package_Body then
3225 P := Corresponding_Spec (N);
3228 exit when Nkind (P) = N_Package_Declaration;
3231 Chain := Activation_Chain_Entity (P);
3234 Chain := Activation_Chain_Entity (N);
3237 if Present (Chain) then
3238 if Restricted_Profile then
3239 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3241 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3245 Make_Procedure_Call_Statement (Loc,
3247 Parameter_Associations =>
3248 New_List (Make_Attribute_Reference (Loc,
3249 Prefix => New_Occurrence_Of (Chain, Loc),
3250 Attribute_Name => Name_Unchecked_Access)));
3252 if Nkind (N) = N_Package_Declaration then
3253 if Present (Corresponding_Body (N)) then
3256 elsif Present (Private_Declarations (Specification (N))) then
3257 Append (Call, Private_Declarations (Specification (N)));
3260 Append (Call, Visible_Declarations (Specification (N)));
3264 if Present (Handled_Statement_Sequence (N)) then
3266 -- The call goes at the start of the statement sequence
3267 -- after the start of exception range label if one is present.
3273 Stm := First (Statements (Handled_Statement_Sequence (N)));
3275 -- A special case, skip exception range label if one is
3276 -- present (from front end zcx processing).
3278 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3282 -- Another special case, if the first statement is a block
3283 -- from optimization of a local raise to a goto, then the
3284 -- call goes inside this block.
3286 if Nkind (Stm) = N_Block_Statement
3287 and then Exception_Junk (Stm)
3290 First (Statements (Handled_Statement_Sequence (Stm)));
3293 -- Insertion point is after any exception label pushes,
3294 -- since we want it covered by any local handlers.
3296 while Nkind (Stm) in N_Push_xxx_Label loop
3300 -- Now we have the proper insertion point
3302 Insert_Before (Stm, Call);
3306 Set_Handled_Statement_Sequence (N,
3307 Make_Handled_Sequence_Of_Statements (Loc,
3308 Statements => New_List (Call)));
3313 Check_Task_Activation (N);
3315 end Build_Task_Activation_Call;
3317 -------------------------------
3318 -- Build_Task_Allocate_Block --
3319 -------------------------------
3321 procedure Build_Task_Allocate_Block
3326 T : constant Entity_Id := Entity (Expression (N));
3327 Init : constant Entity_Id := Base_Init_Proc (T);
3328 Loc : constant Source_Ptr := Sloc (N);
3329 Chain : constant Entity_Id :=
3330 Make_Defining_Identifier (Loc, Name_uChain);
3336 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3339 Make_Block_Statement (Loc,
3340 Identifier => New_Reference_To (Blkent, Loc),
3341 Declarations => New_List (
3343 -- _Chain : Activation_Chain;
3345 Make_Object_Declaration (Loc,
3346 Defining_Identifier => Chain,
3347 Aliased_Present => True,
3348 Object_Definition =>
3349 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3351 Handled_Statement_Sequence =>
3352 Make_Handled_Sequence_Of_Statements (Loc,
3354 Statements => New_List (
3358 Make_Procedure_Call_Statement (Loc,
3359 Name => New_Reference_To (Init, Loc),
3360 Parameter_Associations => Args),
3362 -- Activate_Tasks (_Chain);
3364 Make_Procedure_Call_Statement (Loc,
3365 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3366 Parameter_Associations => New_List (
3367 Make_Attribute_Reference (Loc,
3368 Prefix => New_Reference_To (Chain, Loc),
3369 Attribute_Name => Name_Unchecked_Access))))),
3371 Has_Created_Identifier => True,
3372 Is_Task_Allocation_Block => True);
3375 Make_Implicit_Label_Declaration (Loc,
3376 Defining_Identifier => Blkent,
3377 Label_Construct => Block));
3379 Append_To (Actions, Block);
3381 Set_Activation_Chain_Entity (Block, Chain);
3382 end Build_Task_Allocate_Block;
3384 -----------------------------------------------
3385 -- Build_Task_Allocate_Block_With_Init_Stmts --
3386 -----------------------------------------------
3388 procedure Build_Task_Allocate_Block_With_Init_Stmts
3391 Init_Stmts : List_Id)
3393 Loc : constant Source_Ptr := Sloc (N);
3394 Chain : constant Entity_Id :=
3395 Make_Defining_Identifier (Loc, Name_uChain);
3400 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3402 Append_To (Init_Stmts,
3403 Make_Procedure_Call_Statement (Loc,
3404 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3405 Parameter_Associations => New_List (
3406 Make_Attribute_Reference (Loc,
3407 Prefix => New_Reference_To (Chain, Loc),
3408 Attribute_Name => Name_Unchecked_Access))));
3411 Make_Block_Statement (Loc,
3412 Identifier => New_Reference_To (Blkent, Loc),
3413 Declarations => New_List (
3415 -- _Chain : Activation_Chain;
3417 Make_Object_Declaration (Loc,
3418 Defining_Identifier => Chain,
3419 Aliased_Present => True,
3420 Object_Definition =>
3421 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3423 Handled_Statement_Sequence =>
3424 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
3426 Has_Created_Identifier => True,
3427 Is_Task_Allocation_Block => True);
3430 Make_Implicit_Label_Declaration (Loc,
3431 Defining_Identifier => Blkent,
3432 Label_Construct => Block));
3434 Append_To (Actions, Block);
3436 Set_Activation_Chain_Entity (Block, Chain);
3437 end Build_Task_Allocate_Block_With_Init_Stmts;
3439 -----------------------------------
3440 -- Build_Task_Proc_Specification --
3441 -----------------------------------
3443 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
3444 Loc : constant Source_Ptr := Sloc (T);
3445 Nam : constant Name_Id := Chars (T);
3450 Make_Defining_Identifier (Loc,
3451 Chars => New_External_Name (Nam, 'B'));
3452 Set_Is_Internal (Ent);
3454 -- Associate the procedure with the task, if this is the declaration
3455 -- (and not the body) of the procedure.
3457 if No (Task_Body_Procedure (T)) then
3458 Set_Task_Body_Procedure (T, Ent);
3462 Make_Procedure_Specification (Loc,
3463 Defining_Unit_Name => Ent,
3464 Parameter_Specifications =>
3466 Make_Parameter_Specification (Loc,
3467 Defining_Identifier =>
3468 Make_Defining_Identifier (Loc, Name_uTask),
3470 Make_Access_Definition (Loc,
3473 (Corresponding_Record_Type (T), Loc)))));
3474 end Build_Task_Proc_Specification;
3476 ---------------------------------------
3477 -- Build_Unprotected_Subprogram_Body --
3478 ---------------------------------------
3480 function Build_Unprotected_Subprogram_Body
3482 Pid : Node_Id) return Node_Id
3484 Loc : constant Source_Ptr := Sloc (N);
3485 N_Op_Spec : Node_Id;
3489 -- Make an unprotected version of the subprogram for use within the same
3490 -- object, with a new name and an additional parameter representing the
3493 Op_Decls := Declarations (N);
3495 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode);
3498 Make_Subprogram_Body (Loc,
3499 Specification => N_Op_Spec,
3500 Declarations => Op_Decls,
3501 Handled_Statement_Sequence =>
3502 Handled_Statement_Sequence (N));
3503 end Build_Unprotected_Subprogram_Body;
3505 ----------------------------
3506 -- Collect_Entry_Families --
3507 ----------------------------
3509 procedure Collect_Entry_Families
3512 Current_Node : in out Node_Id;
3513 Conctyp : Entity_Id)
3516 Efam_Decl : Node_Id;
3517 Efam_Type : Entity_Id;
3520 Efam := First_Entity (Conctyp);
3522 while Present (Efam) loop
3524 if Ekind (Efam) = E_Entry_Family then
3526 Make_Defining_Identifier (Loc,
3527 Chars => New_Internal_Name ('F'));
3532 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
3533 Bas_Decl : Node_Id := Empty;
3538 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
3540 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
3542 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3544 Make_Subtype_Declaration (Loc,
3545 Defining_Identifier => Bas,
3546 Subtype_Indication =>
3547 Make_Subtype_Indication (Loc,
3549 New_Occurrence_Of (Standard_Integer, Loc),
3551 Make_Range_Constraint (Loc,
3552 Range_Expression => Make_Range (Loc,
3553 Make_Integer_Literal
3554 (Loc, -Entry_Family_Bound),
3555 Make_Integer_Literal
3556 (Loc, Entry_Family_Bound - 1)))));
3558 Insert_After (Current_Node, Bas_Decl);
3559 Current_Node := Bas_Decl;
3564 Make_Full_Type_Declaration (Loc,
3565 Defining_Identifier => Efam_Type,
3567 Make_Unconstrained_Array_Definition (Loc,
3569 (New_List (New_Occurrence_Of (Bas, Loc))),
3571 Component_Definition =>
3572 Make_Component_Definition (Loc,
3573 Aliased_Present => False,
3574 Subtype_Indication =>
3575 New_Reference_To (Standard_Character, Loc))));
3578 Insert_After (Current_Node, Efam_Decl);
3579 Current_Node := Efam_Decl;
3580 Analyze (Efam_Decl);
3583 Make_Component_Declaration (Loc,
3584 Defining_Identifier =>
3585 Make_Defining_Identifier (Loc, Chars (Efam)),
3587 Component_Definition =>
3588 Make_Component_Definition (Loc,
3589 Aliased_Present => False,
3590 Subtype_Indication =>
3591 Make_Subtype_Indication (Loc,
3593 New_Occurrence_Of (Efam_Type, Loc),
3596 Make_Index_Or_Discriminant_Constraint (Loc,
3597 Constraints => New_List (
3599 (Etype (Discrete_Subtype_Definition
3600 (Parent (Efam))), Loc)))))));
3606 end Collect_Entry_Families;
3608 ----------------------
3609 -- Copy_Result_Type --
3610 ----------------------
3612 function Copy_Result_Type (Res : Node_Id) return Node_Id is
3613 New_Res : constant Node_Id := New_Copy_Tree (Res);
3618 if Nkind (New_Res) = N_Access_Definition then
3620 -- Provide new entities for the formals
3622 Par_Spec := First (Parameter_Specifications
3623 (Access_To_Subprogram_Definition (New_Res)));
3624 while Present (Par_Spec) loop
3625 Formal := Defining_Identifier (Par_Spec);
3626 Set_Defining_Identifier (Par_Spec,
3627 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
3633 end Copy_Result_Type;
3635 --------------------
3636 -- Concurrent_Ref --
3637 --------------------
3639 -- The expression returned for a reference to a concurrent object has the
3642 -- taskV!(name)._Task_Id
3646 -- objectV!(name)._Object
3648 -- for a protected object. For the case of an access to a concurrent
3649 -- object, there is an extra explicit dereference:
3651 -- taskV!(name.all)._Task_Id
3652 -- objectV!(name.all)._Object
3654 -- here taskV and objectV are the types for the associated records, which
3655 -- contain the required _Task_Id and _Object fields for tasks and protected
3656 -- objects, respectively.
3658 -- For the case of a task type name, the expression is
3662 -- i.e. a call to the Self function which returns precisely this Task_Id
3664 -- For the case of a protected type name, the expression is
3668 -- which is a renaming of the _object field of the current object object
3669 -- record, passed into protected operations as a parameter.
3671 function Concurrent_Ref (N : Node_Id) return Node_Id is
3672 Loc : constant Source_Ptr := Sloc (N);
3673 Ntyp : constant Entity_Id := Etype (N);
3677 function Is_Current_Task (T : Entity_Id) return Boolean;
3678 -- Check whether the reference is to the immediately enclosing task
3679 -- type, or to an outer one (rare but legal).
3681 ---------------------
3682 -- Is_Current_Task --
3683 ---------------------
3685 function Is_Current_Task (T : Entity_Id) return Boolean is
3689 Scop := Current_Scope;
3690 while Present (Scop)
3691 and then Scop /= Standard_Standard
3697 elsif Is_Task_Type (Scop) then
3700 -- If this is a procedure nested within the task type, we must
3701 -- assume that it can be called from an inner task, and therefore
3702 -- cannot treat it as a local reference.
3704 elsif Is_Overloadable (Scop)
3705 and then In_Open_Scopes (T)
3710 Scop := Scope (Scop);
3714 -- We know that we are within the task body, so should have found it
3717 raise Program_Error;
3718 end Is_Current_Task;
3720 -- Start of processing for Concurrent_Ref
3723 if Is_Access_Type (Ntyp) then
3724 Dtyp := Designated_Type (Ntyp);
3726 if Is_Protected_Type (Dtyp) then
3727 Sel := Name_uObject;
3729 Sel := Name_uTask_Id;
3733 Make_Selected_Component (Loc,
3735 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
3736 Make_Explicit_Dereference (Loc, N)),
3737 Selector_Name => Make_Identifier (Loc, Sel));
3739 elsif Is_Entity_Name (N)
3740 and then Is_Concurrent_Type (Entity (N))
3742 if Is_Task_Type (Entity (N)) then
3744 if Is_Current_Task (Entity (N)) then
3746 Make_Function_Call (Loc,
3747 Name => New_Reference_To (RTE (RE_Self), Loc));
3752 T_Self : constant Entity_Id :=
3753 Make_Defining_Identifier (Loc,
3754 Chars => New_Internal_Name ('T'));
3755 T_Body : constant Node_Id :=
3756 Parent (Corresponding_Body (Parent (Entity (N))));
3759 Decl := Make_Object_Declaration (Loc,
3760 Defining_Identifier => T_Self,
3761 Object_Definition =>
3762 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
3764 Make_Function_Call (Loc,
3765 Name => New_Reference_To (RTE (RE_Self), Loc)));
3766 Prepend (Decl, Declarations (T_Body));
3768 Set_Scope (T_Self, Entity (N));
3769 return New_Occurrence_Of (T_Self, Loc);
3774 pragma Assert (Is_Protected_Type (Entity (N)));
3777 Object_Ref (Corresponding_Body (Parent (Base_Type (Ntyp)))),
3782 pragma Assert (Is_Concurrent_Type (Ntyp));
3784 if Is_Protected_Type (Ntyp) then
3785 Sel := Name_uObject;
3787 Sel := Name_uTask_Id;
3791 Make_Selected_Component (Loc,
3793 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
3795 Selector_Name => Make_Identifier (Loc, Sel));
3799 ------------------------
3800 -- Convert_Concurrent --
3801 ------------------------
3803 function Convert_Concurrent
3805 Typ : Entity_Id) return Node_Id
3808 if not Is_Concurrent_Type (Typ) then
3812 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
3815 end Convert_Concurrent;
3817 ----------------------------
3818 -- Entry_Index_Expression --
3819 ----------------------------
3821 function Entry_Index_Expression
3825 Ttyp : Entity_Id) return Node_Id
3835 -- The queues of entries and entry families appear in textual order in
3836 -- the associated record. The entry index is computed as the sum of the
3837 -- number of queues for all entries that precede the designated one, to
3838 -- which is added the index expression, if this expression denotes a
3839 -- member of a family.
3841 -- The following is a place holder for the count of simple entries
3843 Num := Make_Integer_Literal (Sloc, 1);
3845 -- We construct an expression which is a series of addition operations.
3846 -- The first operand is the number of single entries that precede this
3847 -- one, the second operand is the index value relative to the start of
3848 -- the referenced family, and the remaining operands are the lengths of
3849 -- the entry families that precede this entry, i.e. the constructed
3852 -- number_simple_entries +
3853 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
3854 -- family'length + ...
3856 -- where index-value is the given index value, and s is the index
3857 -- subtype (we have to use pos because the subtype might be an
3858 -- enumeration type preventing direct subtraction). Note that the task
3859 -- entry array is one-indexed.
3861 -- The upper bound of the entry family may be a discriminant, so we
3862 -- retrieve the lower bound explicitly to compute offset, rather than
3863 -- using the index subtype which may mention a discriminant.
3865 if Present (Index) then
3866 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
3875 Make_Attribute_Reference (Sloc,
3876 Attribute_Name => Name_Pos,
3877 Prefix => New_Reference_To (Base_Type (S), Sloc),
3878 Expressions => New_List (Relocate_Node (Index))),
3886 -- Now add lengths of preceding entries and entry families
3888 Prev := First_Entity (Ttyp);
3890 while Chars (Prev) /= Chars (Ent)
3891 or else (Ekind (Prev) /= Ekind (Ent))
3892 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
3894 if Ekind (Prev) = E_Entry then
3895 Set_Intval (Num, Intval (Num) + 1);
3897 elsif Ekind (Prev) = E_Entry_Family then
3899 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
3900 Lo := Type_Low_Bound (S);
3901 Hi := Type_High_Bound (S);
3906 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
3908 -- Other components are anonymous types to be ignored
3918 end Entry_Index_Expression;
3920 ---------------------------
3921 -- Establish_Task_Master --
3922 ---------------------------
3924 procedure Establish_Task_Master (N : Node_Id) is
3927 if Restriction_Active (No_Task_Hierarchy) = False then
3928 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
3929 Prepend_To (Declarations (N), Call);
3932 end Establish_Task_Master;
3934 --------------------------------
3935 -- Expand_Accept_Declarations --
3936 --------------------------------
3938 -- Part of the expansion of an accept statement involves the creation of
3939 -- a declaration that can be referenced from the statement sequence of
3944 -- This declaration is inserted immediately before the accept statement
3945 -- and it is important that it be inserted before the statements of the
3946 -- statement sequence are analyzed. Thus it would be too late to create
3947 -- this declaration in the Expand_N_Accept_Statement routine, which is
3948 -- why there is a separate procedure to be called directly from Sem_Ch9.
3950 -- Ann is used to hold the address of the record containing the parameters
3951 -- (see Expand_N_Entry_Call for more details on how this record is built).
3952 -- References to the parameters do an unchecked conversion of this address
3953 -- to a pointer to the required record type, and then access the field that
3954 -- holds the value of the required parameter. The entity for the address
3955 -- variable is held as the top stack element (i.e. the last element) of the
3956 -- Accept_Address stack in the corresponding entry entity, and this element
3957 -- must be set in place before the statements are processed.
3959 -- The above description applies to the case of a stand alone accept
3960 -- statement, i.e. one not appearing as part of a select alternative.
3962 -- For the case of an accept that appears as part of a select alternative
3963 -- of a selective accept, we must still create the declaration right away,
3964 -- since Ann is needed immediately, but there is an important difference:
3966 -- The declaration is inserted before the selective accept, not before
3967 -- the accept statement (which is not part of a list anyway, and so would
3968 -- not accommodate inserted declarations)
3970 -- We only need one address variable for the entire selective accept. So
3971 -- the Ann declaration is created only for the first accept alternative,
3972 -- and subsequent accept alternatives reference the same Ann variable.
3974 -- We can distinguish the two cases by seeing whether the accept statement
3975 -- is part of a list. If not, then it must be in an accept alternative.
3977 -- To expand the requeue statement, a label is provided at the end of the
3978 -- accept statement or alternative of which it is a part, so that the
3979 -- statement can be skipped after the requeue is complete. This label is
3980 -- created here rather than during the expansion of the accept statement,
3981 -- because it will be needed by any requeue statements within the accept,
3982 -- which are expanded before the accept.
3984 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
3985 Loc : constant Source_Ptr := Sloc (N);
3986 Ann : Entity_Id := Empty;
3994 if Expander_Active then
3996 -- If we have no handled statement sequence, then build a dummy
3997 -- sequence consisting of a null statement. This is only done if
3998 -- pragma FIFO_Within_Priorities is specified. The issue here is
3999 -- that even a null accept body has an effect on the called task
4000 -- in terms of its position in the queue, so we cannot optimize
4001 -- the context switch away. However, if FIFO_Within_Priorities
4002 -- is not active, the optimization is legitimate, since we can
4003 -- say that our dispatching policy (i.e. the default dispatching
4004 -- policy) reorders the queue to be the same as just before the
4005 -- call. In the absence of a specified dispatching policy, we are
4006 -- allowed to modify queue orders for a given priority at will!
4008 if Opt.Task_Dispatching_Policy = 'F' and then
4009 No (Handled_Statement_Sequence (N))
4011 Set_Handled_Statement_Sequence (N,
4012 Make_Handled_Sequence_Of_Statements (Loc,
4013 New_List (Make_Null_Statement (Loc))));
4016 -- Create and declare two labels to be placed at the end of the
4017 -- accept statement. The first label is used to allow requeues to
4018 -- skip the remainder of entry processing. The second label is used
4019 -- to skip the remainder of entry processing if the rendezvous
4020 -- completes in the middle of the accept body.
4022 if Present (Handled_Statement_Sequence (N)) then
4023 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4025 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4026 Lab := Make_Label (Loc, Lab_Id);
4028 Make_Implicit_Label_Declaration (Loc,
4029 Defining_Identifier => Entity (Lab_Id),
4030 Label_Construct => Lab);
4031 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4033 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4035 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4036 Lab := Make_Label (Loc, Lab_Id);
4038 Make_Implicit_Label_Declaration (Loc,
4039 Defining_Identifier => Entity (Lab_Id),
4040 Label_Construct => Lab);
4041 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4048 -- Case of stand alone accept statement
4050 if Is_List_Member (N) then
4052 if Present (Handled_Statement_Sequence (N)) then
4054 Make_Defining_Identifier (Loc,
4055 Chars => New_Internal_Name ('A'));
4058 Make_Object_Declaration (Loc,
4059 Defining_Identifier => Ann,
4060 Object_Definition =>
4061 New_Reference_To (RTE (RE_Address), Loc));
4063 Insert_Before (N, Adecl);
4066 Insert_Before (N, Ldecl);
4069 Insert_Before (N, Ldecl2);
4073 -- Case of accept statement which is in an accept alternative
4077 Acc_Alt : constant Node_Id := Parent (N);
4078 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4082 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4083 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4085 -- ??? Consider a single label for select statements
4087 if Present (Handled_Statement_Sequence (N)) then
4089 Statements (Handled_Statement_Sequence (N)));
4093 Statements (Handled_Statement_Sequence (N)));
4097 -- Find first accept alternative of the selective accept. A
4098 -- valid selective accept must have at least one accept in it.
4100 Alt := First (Select_Alternatives (Sel_Acc));
4102 while Nkind (Alt) /= N_Accept_Alternative loop
4106 -- If we are the first accept statement, then we have to create
4107 -- the Ann variable, as for the stand alone case, except that
4108 -- it is inserted before the selective accept. Similarly, a
4109 -- label for requeue expansion must be declared.
4111 if N = Accept_Statement (Alt) then
4113 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4116 Make_Object_Declaration (Loc,
4117 Defining_Identifier => Ann,
4118 Object_Definition =>
4119 New_Reference_To (RTE (RE_Address), Loc));
4121 Insert_Before (Sel_Acc, Adecl);
4124 -- If we are not the first accept statement, then find the Ann
4125 -- variable allocated by the first accept and use it.
4129 Node (Last_Elmt (Accept_Address
4130 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4135 -- Merge here with Ann either created or referenced, and Adecl
4136 -- pointing to the corresponding declaration. Remaining processing
4137 -- is the same for the two cases.
4139 if Present (Ann) then
4140 Append_Elmt (Ann, Accept_Address (Ent));
4141 Set_Needs_Debug_Info (Ann);
4144 -- Create renaming declarations for the entry formals. Each reference
4145 -- to a formal becomes a dereference of a component of the parameter
4146 -- block, whose address is held in Ann. These declarations are
4147 -- eventually inserted into the accept block, and analyzed there so
4148 -- that they have the proper scope for gdb and do not conflict with
4149 -- other declarations.
4151 if Present (Parameter_Specifications (N))
4152 and then Present (Handled_Statement_Sequence (N))
4162 Formal := First_Formal (Ent);
4164 while Present (Formal) loop
4165 Comp := Entry_Component (Formal);
4167 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
4169 Set_Etype (New_F, Etype (Formal));
4170 Set_Scope (New_F, Ent);
4171 Set_Needs_Debug_Info (New_F); -- That's the whole point.
4173 if Ekind (Formal) = E_In_Parameter then
4174 Set_Ekind (New_F, E_Constant);
4176 Set_Ekind (New_F, E_Variable);
4177 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4180 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4183 Make_Object_Renaming_Declaration (Loc,
4184 Defining_Identifier =>
4187 New_Reference_To (Etype (Formal), Loc),
4189 Make_Explicit_Dereference (Loc,
4190 Make_Selected_Component (Loc,
4192 Unchecked_Convert_To (
4193 Entry_Parameters_Type (Ent),
4194 New_Reference_To (Ann, Loc)),
4196 New_Reference_To (Comp, Loc))));
4198 if No (Declarations (N)) then
4199 Set_Declarations (N, New_List);
4202 Append (Decl, Declarations (N));
4203 Set_Renamed_Object (Formal, New_F);
4204 Next_Formal (Formal);
4211 end Expand_Accept_Declarations;
4213 ---------------------------------------------
4214 -- Expand_Access_Protected_Subprogram_Type --
4215 ---------------------------------------------
4217 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4218 Loc : constant Source_Ptr := Sloc (N);
4220 T : constant Entity_Id := Defining_Identifier (N);
4221 D_T : constant Entity_Id := Designated_Type (T);
4222 D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc,
4223 Chars => New_Internal_Name ('D'));
4224 E_T : constant Entity_Id := Make_Defining_Identifier (Loc,
4225 Chars => New_Internal_Name ('E'));
4226 P_List : constant List_Id := Build_Protected_Spec
4227 (N, RTE (RE_Address), False, D_T);
4233 -- Create access to protected subprogram with full signature
4235 if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
4237 Make_Access_Function_Definition (Loc,
4238 Parameter_Specifications => P_List,
4239 Result_Definition =>
4240 Copy_Result_Type (Result_Definition (Type_Definition (N))));
4244 Make_Access_Procedure_Definition (Loc,
4245 Parameter_Specifications => P_List);
4249 Make_Full_Type_Declaration (Loc,
4250 Defining_Identifier => D_T2,
4251 Type_Definition => Def1);
4254 Insert_After (N, Decl1);
4256 -- Create Equivalent_Type, a record with two components for an access to
4257 -- object and an access to subprogram.
4260 Make_Component_Declaration (Loc,
4261 Defining_Identifier =>
4262 Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
4263 Component_Definition =>
4264 Make_Component_Definition (Loc,
4265 Aliased_Present => False,
4266 Subtype_Indication =>
4267 New_Occurrence_Of (RTE (RE_Address), Loc))),
4269 Make_Component_Declaration (Loc,
4270 Defining_Identifier =>
4271 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4272 Component_Definition =>
4273 Make_Component_Definition (Loc,
4274 Aliased_Present => False,
4275 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4278 Make_Full_Type_Declaration (Loc,
4279 Defining_Identifier => E_T,
4281 Make_Record_Definition (Loc,
4283 Make_Component_List (Loc,
4284 Component_Items => Comps)));
4287 Insert_After (Decl1, Decl2);
4288 Set_Equivalent_Type (T, E_T);
4289 end Expand_Access_Protected_Subprogram_Type;
4291 --------------------------
4292 -- Expand_Entry_Barrier --
4293 --------------------------
4295 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4296 Loc : constant Source_Ptr := Sloc (N);
4297 Prot : constant Entity_Id := Scope (Ent);
4298 Spec_Decl : constant Node_Id := Parent (Prot);
4299 Cond : constant Node_Id :=
4300 Condition (Entry_Body_Formal_Part (N));
4303 Body_Decl : Node_Id;
4306 if No_Run_Time_Mode then
4307 Error_Msg_CRT ("entry barrier", N);
4311 -- The body of the entry barrier must be analyzed in the context of the
4312 -- protected object, but its scope is external to it, just as any other
4313 -- unprotected version of a protected operation. The specification has
4314 -- been produced when the protected type declaration was elaborated. We
4315 -- build the body, insert it in the enclosing scope, but analyze it in
4316 -- the current context. A more uniform approach would be to treat
4317 -- barrier just as a protected function, and discard the protected
4318 -- version of it because it is never called.
4320 if Expander_Active then
4321 B_F := Build_Barrier_Function (N, Ent, Prot);
4322 Func := Barrier_Function (Ent);
4323 Set_Corresponding_Spec (B_F, Func);
4325 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
4327 if Nkind (Parent (Body_Decl)) = N_Subunit then
4328 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
4331 Insert_Before_And_Analyze (Body_Decl, B_F);
4333 Update_Prival_Subtypes (B_F);
4335 Set_Privals (Spec_Decl, N, Loc, After_Barrier => True);
4336 Set_Discriminals (Spec_Decl);
4337 Set_Scope (Func, Scope (Prot));
4340 Analyze_And_Resolve (Cond, Any_Boolean);
4343 -- The Ravenscar profile restricts barriers to simple variables declared
4344 -- within the protected object. We also allow Boolean constants, since
4345 -- these appear in several published examples and are also allowed by
4346 -- the Aonix compiler.
4348 -- Note that after analysis variables in this context will be replaced
4349 -- by the corresponding prival, that is to say a renaming of a selected
4350 -- component of the form _Object.Var. If expansion is disabled, as
4351 -- within a generic, we check that the entity appears in the current
4354 if Is_Entity_Name (Cond) then
4355 if Entity (Cond) = Standard_False
4357 Entity (Cond) = Standard_True
4361 elsif not Expander_Active
4362 and then Scope (Entity (Cond)) = Current_Scope
4366 -- Check for case of _object.all.field (note that the explicit
4367 -- dereference gets inserted by analyze/expand of _object.field)
4369 elsif Present (Renamed_Object (Entity (Cond)))
4371 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
4375 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
4381 -- It is not a boolean variable or literal, so check the restriction
4383 Check_Restriction (Simple_Barriers, Cond);
4384 end Expand_Entry_Barrier;
4386 ------------------------------------
4387 -- Expand_Entry_Body_Declarations --
4388 ------------------------------------
4390 procedure Expand_Entry_Body_Declarations (N : Node_Id) is
4391 Loc : constant Source_Ptr := Sloc (N);
4392 Index_Spec : Node_Id;
4395 if Expander_Active then
4397 -- Expand entry bodies corresponding to entry families
4398 -- by assigning a placeholder for the constant that will
4399 -- be used to expand references to the entry index parameter.
4402 Entry_Index_Specification (Entry_Body_Formal_Part (N));
4404 if Present (Index_Spec) then
4405 Set_Entry_Index_Constant (
4406 Defining_Identifier (Index_Spec),
4407 Make_Defining_Identifier (Loc, New_Internal_Name ('J')));
4410 end Expand_Entry_Body_Declarations;
4412 ------------------------------
4413 -- Expand_N_Abort_Statement --
4414 ------------------------------
4416 -- Expand abort T1, T2, .. Tn; into:
4417 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
4419 procedure Expand_N_Abort_Statement (N : Node_Id) is
4420 Loc : constant Source_Ptr := Sloc (N);
4421 Tlist : constant List_Id := Names (N);
4427 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
4430 Tasknm := First (Tlist);
4432 while Present (Tasknm) loop
4435 -- A task interface class-wide type object is being aborted.
4436 -- Retrieve its _task_id by calling a dispatching routine.
4438 if Ada_Version >= Ada_05
4439 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
4440 and then Is_Interface (Etype (Tasknm))
4441 and then Is_Task_Interface (Etype (Tasknm))
4443 Append_To (Component_Associations (Aggr),
4444 Make_Component_Association (Loc,
4445 Choices => New_List (
4446 Make_Integer_Literal (Loc, Count)),
4449 -- Task_Id (Tasknm._disp_get_task_id)
4451 Make_Unchecked_Type_Conversion (Loc,
4453 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
4455 Make_Selected_Component (Loc,
4457 New_Copy_Tree (Tasknm),
4459 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
4462 Append_To (Component_Associations (Aggr),
4463 Make_Component_Association (Loc,
4464 Choices => New_List (
4465 Make_Integer_Literal (Loc, Count)),
4466 Expression => Concurrent_Ref (Tasknm)));
4473 Make_Procedure_Call_Statement (Loc,
4474 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
4475 Parameter_Associations => New_List (
4476 Make_Qualified_Expression (Loc,
4477 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
4478 Expression => Aggr))));
4481 end Expand_N_Abort_Statement;
4483 -------------------------------
4484 -- Expand_N_Accept_Statement --
4485 -------------------------------
4487 -- This procedure handles expansion of accept statements that stand
4488 -- alone, i.e. they are not part of an accept alternative. The expansion
4489 -- of accept statement in accept alternatives is handled by the routines
4490 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
4491 -- following description applies only to stand alone accept statements.
4493 -- If there is no handled statement sequence, or only null statements,
4494 -- then this is called a trivial accept, and the expansion is:
4496 -- Accept_Trivial (entry-index)
4498 -- If there is a handled statement sequence, then the expansion is:
4505 -- Accept_Call (entry-index, Ann);
4506 -- Renaming_Declarations for formals
4507 -- <statement sequence from N_Accept_Statement node>
4508 -- Complete_Rendezvous;
4513 -- <exception handler from N_Accept_Statement node>
4514 -- Complete_Rendezvous;
4516 -- <exception handler from N_Accept_Statement node>
4517 -- Complete_Rendezvous;
4522 -- when all others =>
4523 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
4526 -- The first three declarations were already inserted ahead of the accept
4527 -- statement by the Expand_Accept_Declarations procedure, which was called
4528 -- directly from the semantics during analysis of the accept. statement,
4529 -- before analyzing its contained statements.
4531 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
4532 -- from possible expansion activity (the original source of course does
4533 -- not have any declarations associated with the accept statement, since
4534 -- an accept statement has no declarative part). In particular, if the
4535 -- expander is active, the first such declaration is the declaration of
4536 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
4538 -- The two blocks are merged into a single block if the inner block has
4539 -- no exception handlers, but otherwise two blocks are required, since
4540 -- exceptions might be raised in the exception handlers of the inner
4541 -- block, and Exceptional_Complete_Rendezvous must be called.
4543 procedure Expand_N_Accept_Statement (N : Node_Id) is
4544 Loc : constant Source_Ptr := Sloc (N);
4545 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4546 Ename : constant Node_Id := Entry_Direct_Name (N);
4547 Eindx : constant Node_Id := Entry_Index (N);
4548 Eent : constant Entity_Id := Entity (Ename);
4549 Acstack : constant Elist_Id := Accept_Address (Eent);
4550 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
4551 Ttyp : constant Entity_Id := Etype (Scope (Eent));
4556 function Null_Statements (Stats : List_Id) return Boolean;
4557 -- Check for null statement sequence (i.e a list of labels and
4558 -- null statements).
4560 ---------------------
4561 -- Null_Statements --
4562 ---------------------
4564 function Null_Statements (Stats : List_Id) return Boolean is
4568 Stmt := First (Stats);
4569 while Nkind (Stmt) /= N_Empty
4570 and then (Nkind (Stmt) = N_Null_Statement
4572 Nkind (Stmt) = N_Label)
4577 return Nkind (Stmt) = N_Empty;
4578 end Null_Statements;
4580 -- Start of processing for Expand_N_Accept_Statement
4583 -- If accept statement is not part of a list, then its parent must be
4584 -- an accept alternative, and, as described above, we do not do any
4585 -- expansion for such accept statements at this level.
4587 if not Is_List_Member (N) then
4588 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
4591 -- Trivial accept case (no statement sequence, or null statements).
4592 -- If the accept statement has declarations, then just insert them
4593 -- before the procedure call.
4595 -- We avoid this optimization when FIFO_Within_Priorities is active,
4596 -- since it is not correct according to annex D semantics. The problem
4597 -- is that the call is required to reorder the acceptors position on
4598 -- its ready queue, even though there is nothing to be done. However,
4599 -- if no policy is specified, then we decide that our dispatching
4600 -- policy always reorders the queue right after the RV to look the
4601 -- way they were just before the RV. Since we are allowed to freely
4602 -- reorder same-priority queues (this is part of what dispatching
4603 -- policies are all about), the optimization is legitimate.
4605 elsif Opt.Task_Dispatching_Policy /= 'F'
4606 and then (No (Stats) or else Null_Statements (Statements (Stats)))
4608 -- Remove declarations for renamings, because the parameter block
4609 -- will not be assigned.
4616 D := First (Declarations (N));
4618 while Present (D) loop
4620 if Nkind (D) = N_Object_Renaming_Declaration then
4628 if Present (Declarations (N)) then
4629 Insert_Actions (N, Declarations (N));
4633 Make_Procedure_Call_Statement (Loc,
4634 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
4635 Parameter_Associations => New_List (
4636 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
4640 -- Discard Entry_Address that was created for it, so it will not be
4641 -- emitted if this accept statement is in the statement part of a
4642 -- delay alternative.
4644 if Present (Stats) then
4645 Remove_Last_Elmt (Acstack);
4648 -- Case of statement sequence present
4651 -- Construct the block, using the declarations from the accept
4652 -- statement if any to initialize the declarations of the block.
4654 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4655 Set_Ekind (Blkent, E_Block);
4656 Set_Etype (Blkent, Standard_Void_Type);
4657 Set_Scope (Blkent, Current_Scope);
4660 Make_Block_Statement (Loc,
4661 Identifier => New_Reference_To (Blkent, Loc),
4662 Declarations => Declarations (N),
4663 Handled_Statement_Sequence => Build_Accept_Body (N));
4665 -- Prepend call to Accept_Call to main statement sequence If the
4666 -- accept has exception handlers, the statement sequence is wrapped
4667 -- in a block. Insert call and renaming declarations in the
4668 -- declarations of the block, so they are elaborated before the
4672 Make_Procedure_Call_Statement (Loc,
4673 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
4674 Parameter_Associations => New_List (
4675 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
4676 New_Reference_To (Ann, Loc)));
4678 if Parent (Stats) = N then
4679 Prepend (Call, Statements (Stats));
4688 Push_Scope (Blkent);
4696 D := First (Declarations (N));
4697 while Present (D) loop
4700 if Nkind (D) = N_Object_Renaming_Declaration then
4702 -- The renaming declarations for the formals were created
4703 -- during analysis of the accept statement, and attached to
4704 -- the list of declarations. Place them now in the context
4705 -- of the accept block or subprogram.
4708 Typ := Entity (Subtype_Mark (D));
4709 Insert_After (Call, D);
4712 -- If the formal is class_wide, it does not have an actual
4713 -- subtype. The analysis of the renaming declaration creates
4714 -- one, but we need to retain the class-wide nature of the
4717 if Is_Class_Wide_Type (Typ) then
4718 Set_Etype (Defining_Identifier (D), Typ);
4729 -- Replace the accept statement by the new block
4734 -- Last step is to unstack the Accept_Address value
4736 Remove_Last_Elmt (Acstack);
4738 end Expand_N_Accept_Statement;
4740 ----------------------------------
4741 -- Expand_N_Asynchronous_Select --
4742 ----------------------------------
4744 -- This procedure assumes that the trigger statement is an entry call or
4745 -- a dispatching procedure call. A delay alternative should already have
4746 -- been expanded into an entry call to the appropriate delay object Wait
4749 -- If the trigger is a task entry call, the select is implemented with
4750 -- a Task_Entry_Call:
4755 -- P : parms := (parm, parm, parm);
4757 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
4759 -- procedure _clean is
4762 -- Cancel_Task_Entry_Call (C);
4772 -- Asynchronous_Call,
4780 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions.
4783 -- when Abort_Signal => Abort_Undefer;
4790 -- <triggered-statements>
4794 -- Note that Build_Simple_Entry_Call is used to expand the entry
4795 -- of the asynchronous entry call (by the
4796 -- Expand_N_Entry_Call_Statement procedure) as follows:
4799 -- P : parms := (parm, parm, parm);
4801 -- Call_Simple (acceptor-task, entry-index, P'Address);
4807 -- so the task at hand is to convert the latter expansion into the former
4809 -- If the trigger is a protected entry call, the select is
4810 -- implemented with Protected_Entry_Call:
4813 -- P : E1_Params := (param, param, param);
4814 -- Bnn : Communications_Block;
4818 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions.
4819 -- procedure _clean is
4822 -- if Enqueued (Bnn) then
4823 -- Cancel_Protected_Entry_Call (Bnn);
4830 -- Protected_Entry_Call (
4831 -- Object => po._object'Access,
4832 -- E => <entry index>;
4833 -- Uninterpreted_Data => P'Address;
4834 -- Mode => Asynchronous_Call;
4836 -- if Enqueued (Bnn) then
4840 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions.
4843 -- when Abort_Signal => Abort_Undefer;
4846 -- if not Cancelled (Bnn) then
4847 -- <triggered-statements>
4851 -- Build_Simple_Entry_Call is used to expand the all to a simple
4852 -- protected entry call:
4855 -- P : E1_Params := (param, param, param);
4856 -- Bnn : Communications_Block;
4859 -- Protected_Entry_Call (
4860 -- Object => po._object'Access,
4861 -- E => <entry index>;
4862 -- Uninterpreted_Data => P'Address;
4863 -- Mode => Simple_Call;
4870 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
4874 -- B : Boolean := False;
4875 -- Bnn : Communication_Block;
4876 -- C : Ada.Tags.Prim_Op_Kind;
4877 -- D : Dummy_Communication_Block;
4878 -- K : Ada.Tags.Tagged_Kind :=
4879 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
4880 -- P : Parameters := (Param1 .. ParamN);
4885 -- if K = Ada.Tags.TK_Limited_Tagged then
4886 -- <dispatching-call>;
4887 -- <triggering-statements>;
4890 -- S := Ada.Tags.Get_Offset_Index (Ada.Tags.Tag (<object>),
4891 -- DT_Position (<dispatching-call>));
4893 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
4895 -- if C = POK_Protected_Entry then
4897 -- procedure _clean is
4899 -- if Enqueued (Bnn) then
4900 -- Cancel_Protected_Entry_Call (Bnn);
4906 -- _Disp_Asynchronous_Select
4907 -- (<object>, S, P'address, D, B);
4908 -- Bnn := Communication_Block (D);
4910 -- Param1 := P.Param1;
4912 -- ParamN := P.ParamN;
4914 -- if Enqueued (Bnn) then
4915 -- <abortable-statements>
4921 -- when Abort_Signal => Abort_Undefer;
4924 -- if not Cancelled (Bnn) then
4925 -- <triggering-statements>
4928 -- elsif C = POK_Task_Entry then
4930 -- procedure _clean is
4932 -- Cancel_Task_Entry_Call (U);
4938 -- _Disp_Asynchronous_Select
4939 -- (<object>, S, P'address, D, B);
4940 -- Bnn := Communication_Bloc (D);
4942 -- Param1 := P.Param1;
4944 -- ParamN := P.ParamN;
4949 -- <abortable-statements>
4954 -- when Abort_Signal => Abort_Undefer;
4958 -- <triggering-statements>
4963 -- <dispatching-call>;
4964 -- <triggering-statements>
4969 -- The job is to convert this to the asynchronous form
4971 -- If the trigger is a delay statement, it will have been expanded into a
4972 -- call to one of the GNARL delay procedures. This routine will convert
4973 -- this into a protected entry call on a delay object and then continue
4974 -- processing as for a protected entry call trigger. This requires
4975 -- declaring a Delay_Block object and adding a pointer to this object to
4976 -- the parameter list of the delay procedure to form the parameter list of
4977 -- the entry call. This object is used by the runtime to queue the delay
4980 -- For a description of the use of P and the assignments after the
4981 -- call, see Expand_N_Entry_Call_Statement.
4983 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
4984 Loc : constant Source_Ptr := Sloc (N);
4985 Abrt : constant Node_Id := Abortable_Part (N);
4986 Astats : constant List_Id := Statements (Abrt);
4987 Trig : constant Node_Id := Triggering_Alternative (N);
4988 Tstats : constant List_Id := Statements (Trig);
4990 Abort_Block_Ent : Entity_Id;
4991 Abortable_Block : Node_Id;
4993 Blk_Ent : Entity_Id;
4994 Blk_Typ : Entity_Id;
4996 Call_Ent : Entity_Id;
4997 Cancel_Param : Entity_Id;
4998 Cleanup_Block : Node_Id;
4999 Cleanup_Block_Ent : Entity_Id;
5000 Cleanup_Stmts : List_Id;
5001 Conc_Typ_Stmts : List_Id;
5003 Dblock_Ent : Entity_Id;
5008 Enqueue_Call : Node_Id;
5012 Lim_Typ_Stmts : List_Id;
5018 ProtE_Stmts : List_Id;
5019 ProtP_Stmts : List_Id;
5022 Target_Undefer : RE_Id;
5023 TaskE_Stmts : List_Id;
5024 Undefer_Args : List_Id := No_List;
5026 B : Entity_Id; -- Call status flag
5027 Bnn : Entity_Id; -- Communication block
5028 C : Entity_Id; -- Call kind
5029 K : Entity_Id; -- Tagged kind
5030 P : Entity_Id; -- Parameter block
5031 S : Entity_Id; -- Primitive operation slot
5032 T : Entity_Id; -- Additional status flag
5035 Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5036 Ecall := Triggering_Statement (Trig);
5038 -- The arguments in the call may require dynamic allocation, and the
5039 -- call statement may have been transformed into a block. The block
5040 -- may contain additional declarations for internal entities, and the
5041 -- original call is found by sequential search.
5043 if Nkind (Ecall) = N_Block_Statement then
5044 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5045 while Nkind (Ecall) /= N_Procedure_Call_Statement
5046 and then Nkind (Ecall) /= N_Entry_Call_Statement
5052 -- This is either a dispatching call or a delay statement used as a
5053 -- trigger which was expanded into a procedure call.
5055 if Nkind (Ecall) = N_Procedure_Call_Statement then
5056 if Ada_Version >= Ada_05
5058 (No (Original_Node (Ecall))
5060 (Nkind (Original_Node (Ecall)) /= N_Delay_Relative_Statement
5062 Nkind (Original_Node (Ecall)) /= N_Delay_Until_Statement))
5064 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5069 -- Call status flag processing, generate:
5070 -- B : Boolean := False;
5072 B := Build_B (Loc, Decls);
5074 -- Communication block processing, generate:
5075 -- Bnn : Communication_Block;
5077 Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
5080 Make_Object_Declaration (Loc,
5081 Defining_Identifier =>
5083 Object_Definition =>
5084 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5086 -- Call kind processing, generate:
5087 -- C : Ada.Tags.Prim_Op_Kind;
5089 C := Build_C (Loc, Decls);
5091 -- Tagged kind processing, generate:
5092 -- K : Ada.Tags.Tagged_Kind :=
5093 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5095 -- Dummy communication block, generate:
5096 -- D : Dummy_Communication_Block;
5099 Make_Object_Declaration (Loc,
5100 Defining_Identifier =>
5101 Make_Defining_Identifier (Loc, Name_uD),
5102 Object_Definition =>
5104 RTE (RE_Dummy_Communication_Block), Loc)));
5106 K := Build_K (Loc, Decls, Obj);
5108 -- Parameter block processing
5110 Blk_Typ := Build_Parameter_Block
5111 (Loc, Actuals, Formals, Decls);
5112 P := Parameter_Block_Pack
5113 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5115 -- Dispatch table slot processing, generate:
5118 S := Build_S (Loc, Decls);
5120 -- Additional status flag processing, generate:
5122 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
5125 Make_Object_Declaration (Loc,
5126 Defining_Identifier =>
5128 Object_Definition =>
5129 New_Reference_To (Standard_Boolean, Loc)));
5131 -- ---------------------------------------------------------------
5132 -- Protected entry handling
5135 -- Param1 := P.Param1;
5137 -- ParamN := P.ParamN;
5139 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5142 -- Bnn := Communication_Block (D);
5144 Prepend_To (Cleanup_Stmts,
5145 Make_Assignment_Statement (Loc,
5147 New_Reference_To (Bnn, Loc),
5149 Make_Unchecked_Type_Conversion (Loc,
5151 New_Reference_To (RTE (RE_Communication_Block), Loc),
5153 Make_Identifier (Loc, Name_uD))));
5156 -- _Disp_Asynchronous_Select (<object>, S, P'address, D, B);
5158 Prepend_To (Cleanup_Stmts,
5159 Make_Procedure_Call_Statement (Loc,
5162 Find_Prim_Op (Etype (Etype (Obj)),
5163 Name_uDisp_Asynchronous_Select),
5165 Parameter_Associations =>
5167 New_Copy_Tree (Obj),
5168 New_Reference_To (S, Loc),
5169 Make_Attribute_Reference (Loc,
5170 Prefix => New_Reference_To (P, Loc),
5171 Attribute_Name => Name_Address),
5172 Make_Identifier (Loc, Name_uD),
5173 New_Reference_To (B, Loc))));
5176 -- if Enqueued (Bnn) then
5177 -- <abortable-statements>
5180 Append_To (Cleanup_Stmts,
5181 Make_If_Statement (Loc,
5183 Make_Function_Call (Loc,
5185 New_Reference_To (RTE (RE_Enqueued), Loc),
5186 Parameter_Associations =>
5188 New_Reference_To (Bnn, Loc))),
5191 New_Copy_List_Tree (Astats)));
5193 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5194 -- will then generate a _clean for the communication block Bnn.
5198 -- procedure _clean is
5200 -- if Enqueued (Bnn) then
5201 -- Cancel_Protected_Entry_Call (Bnn);
5210 Cleanup_Block_Ent :=
5211 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5214 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5216 -- Wrap the cleanup block in an exception handling block
5222 -- when Abort_Signal => Abort_Undefer;
5226 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5230 Make_Implicit_Label_Declaration (Loc,
5231 Defining_Identifier => Abort_Block_Ent),
5234 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5237 -- if not Cancelled (Bnn) then
5238 -- <triggering-statements>
5241 Append_To (ProtE_Stmts,
5242 Make_If_Statement (Loc,
5246 Make_Function_Call (Loc,
5248 New_Reference_To (RTE (RE_Cancelled), Loc),
5249 Parameter_Associations =>
5251 New_Reference_To (Bnn, Loc)))),
5254 New_Copy_List_Tree (Tstats)));
5256 -- ---------------------------------------------------------------
5257 -- Task entry handling
5260 -- Param1 := P.Param1;
5262 -- ParamN := P.ParamN;
5264 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5267 -- Bnn := Communication_Block (D);
5269 Append_To (TaskE_Stmts,
5270 Make_Assignment_Statement (Loc,
5272 New_Reference_To (Bnn, Loc),
5274 Make_Unchecked_Type_Conversion (Loc,
5276 New_Reference_To (RTE (RE_Communication_Block), Loc),
5278 Make_Identifier (Loc, Name_uD))));
5281 -- _Disp_Asynchronous_Select (<object>, S, P'address, D, B);
5283 Prepend_To (TaskE_Stmts,
5284 Make_Procedure_Call_Statement (Loc,
5287 Find_Prim_Op (Etype (Etype (Obj)),
5288 Name_uDisp_Asynchronous_Select),
5290 Parameter_Associations =>
5292 New_Copy_Tree (Obj),
5293 New_Reference_To (S, Loc),
5294 Make_Attribute_Reference (Loc,
5295 Prefix => New_Reference_To (P, Loc),
5296 Attribute_Name => Name_Address),
5297 Make_Identifier (Loc, Name_uD),
5298 New_Reference_To (B, Loc))));
5303 Prepend_To (TaskE_Stmts,
5304 Make_Procedure_Call_Statement (Loc,
5306 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5307 Parameter_Associations =>
5312 -- <abortable-statements>
5314 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5316 Prepend_To (Cleanup_Stmts,
5317 Make_Procedure_Call_Statement (Loc,
5319 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5320 Parameter_Associations =>
5323 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5324 -- will generate a _clean for the additional status flag.
5328 -- procedure _clean is
5330 -- Cancel_Task_Entry_Call (U);
5338 Cleanup_Block_Ent :=
5339 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5342 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
5344 -- Wrap the cleanup block in an exception handling block
5350 -- when Abort_Signal => Abort_Undefer;
5354 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5356 Append_To (TaskE_Stmts,
5357 Make_Implicit_Label_Declaration (Loc,
5358 Defining_Identifier => Abort_Block_Ent));
5360 Append_To (TaskE_Stmts,
5362 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5366 -- <triggering-statements>
5369 Append_To (TaskE_Stmts,
5370 Make_If_Statement (Loc,
5374 New_Reference_To (T, Loc)),
5377 New_Copy_List_Tree (Tstats)));
5379 -------------------------------------------------------------------
5380 -- Protected procedure handling
5383 -- <dispatching-call>;
5384 -- <triggering-statements>
5386 ProtP_Stmts := New_Copy_List_Tree (Tstats);
5387 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
5390 -- S := Ada.Tags.Get_Offset_Index (
5391 -- Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
5393 Conc_Typ_Stmts := New_List (
5394 Build_S_Assignment (Loc, S, Obj, Call_Ent));
5397 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5399 Append_To (Conc_Typ_Stmts,
5400 Make_Procedure_Call_Statement (Loc,
5403 Find_Prim_Op (Etype (Etype (Obj)),
5404 Name_uDisp_Get_Prim_Op_Kind),
5406 Parameter_Associations =>
5408 New_Copy_Tree (Obj),
5409 New_Reference_To (S, Loc),
5410 New_Reference_To (C, Loc))));
5413 -- if C = POK_Procedure_Entry then
5415 -- elsif C = POK_Task_Entry then
5421 Append_To (Conc_Typ_Stmts,
5422 Make_If_Statement (Loc,
5426 New_Reference_To (C, Loc),
5428 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
5435 Make_Elsif_Part (Loc,
5439 New_Reference_To (C, Loc),
5441 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
5450 -- <dispatching-call>;
5451 -- <triggering-statements>
5453 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
5454 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
5457 -- if K = Ada.Tags.TK_Limited_Tagged then
5464 Make_If_Statement (Loc,
5468 New_Reference_To (K, Loc),
5470 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
5479 Make_Block_Statement (Loc,
5482 Handled_Statement_Sequence =>
5483 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5488 -- Delay triggering statement processing
5491 -- Add a Delay_Block object to the parameter list of the delay
5492 -- procedure to form the parameter list of the Wait entry call.
5495 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
5497 Pdef := Entity (Name (Ecall));
5499 if Is_RTE (Pdef, RO_CA_Delay_For) then
5501 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
5503 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
5505 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
5507 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
5508 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
5511 Append_To (Parameter_Associations (Ecall),
5512 Make_Attribute_Reference (Loc,
5513 Prefix => New_Reference_To (Dblock_Ent, Loc),
5514 Attribute_Name => Name_Unchecked_Access));
5516 -- Create the inner block to protect the abortable part
5519 Make_Implicit_Exception_Handler (Loc,
5520 Exception_Choices =>
5521 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5522 Statements => New_List (
5523 Make_Procedure_Call_Statement (Loc,
5524 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
5527 Make_Procedure_Call_Statement (Loc,
5528 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
5531 Make_Block_Statement (Loc,
5532 Identifier => New_Reference_To (Blk_Ent, Loc),
5533 Handled_Statement_Sequence =>
5534 Make_Handled_Sequence_Of_Statements (Loc,
5535 Statements => Astats),
5536 Has_Created_Identifier => True,
5537 Is_Asynchronous_Call_Block => True);
5539 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
5542 Make_Implicit_If_Statement (N,
5543 Condition => Make_Function_Call (Loc,
5544 Name => Enqueue_Call,
5545 Parameter_Associations => Parameter_Associations (Ecall)),
5547 New_List (Make_Block_Statement (Loc,
5548 Handled_Statement_Sequence =>
5549 Make_Handled_Sequence_Of_Statements (Loc,
5550 Statements => New_List (
5551 Make_Implicit_Label_Declaration (Loc,
5552 Defining_Identifier => Blk_Ent,
5553 Label_Construct => Abortable_Block),
5555 Exception_Handlers => Hdle)))));
5557 Stmts := New_List (Ecall);
5559 -- Construct statement sequence for new block
5562 Make_Implicit_If_Statement (N,
5563 Condition => Make_Function_Call (Loc,
5564 Name => New_Reference_To (
5565 RTE (RE_Timed_Out), Loc),
5566 Parameter_Associations => New_List (
5567 Make_Attribute_Reference (Loc,
5568 Prefix => New_Reference_To (Dblock_Ent, Loc),
5569 Attribute_Name => Name_Unchecked_Access))),
5570 Then_Statements => Tstats));
5572 -- The result is the new block
5574 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
5577 Make_Block_Statement (Loc,
5578 Declarations => New_List (
5579 Make_Object_Declaration (Loc,
5580 Defining_Identifier => Dblock_Ent,
5581 Aliased_Present => True,
5582 Object_Definition => New_Reference_To (
5583 RTE (RE_Delay_Block), Loc))),
5585 Handled_Statement_Sequence =>
5586 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5596 Extract_Entry (Ecall, Concval, Ename, Index);
5597 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
5599 Stmts := Statements (Handled_Statement_Sequence (Ecall));
5600 Decls := Declarations (Ecall);
5602 if Is_Protected_Type (Etype (Concval)) then
5604 -- Get the declarations of the block expanded from the entry call
5606 Decl := First (Decls);
5607 while Present (Decl)
5609 (Nkind (Decl) /= N_Object_Declaration
5610 or else not Is_RTE (Etype (Object_Definition (Decl)),
5611 RE_Communication_Block))
5616 pragma Assert (Present (Decl));
5617 Cancel_Param := Defining_Identifier (Decl);
5619 -- Change the mode of the Protected_Entry_Call call
5621 -- Protected_Entry_Call (
5622 -- Object => po._object'Access,
5623 -- E => <entry index>;
5624 -- Uninterpreted_Data => P'Address;
5625 -- Mode => Asynchronous_Call;
5628 Stmt := First (Stmts);
5630 -- Skip assignments to temporaries created for in-out parameters
5632 -- This makes unwarranted assumptions about the shape of the expanded
5633 -- tree for the call, and should be cleaned up ???
5635 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
5641 Param := First (Parameter_Associations (Call));
5642 while Present (Param)
5643 and then not Is_RTE (Etype (Param), RE_Call_Modes)
5648 pragma Assert (Present (Param));
5649 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
5652 -- Append an if statement to execute the abortable part
5655 -- if Enqueued (Bnn) then
5658 Make_Implicit_If_Statement (N,
5659 Condition => Make_Function_Call (Loc,
5660 Name => New_Reference_To (
5661 RTE (RE_Enqueued), Loc),
5662 Parameter_Associations => New_List (
5663 New_Reference_To (Cancel_Param, Loc))),
5664 Then_Statements => Astats));
5667 Make_Block_Statement (Loc,
5668 Identifier => New_Reference_To (Blk_Ent, Loc),
5669 Handled_Statement_Sequence =>
5670 Make_Handled_Sequence_Of_Statements (Loc,
5671 Statements => Stmts),
5672 Has_Created_Identifier => True,
5673 Is_Asynchronous_Call_Block => True);
5675 -- For the VM call Update_Exception instead of Abort_Undefer.
5676 -- See 4jexcept.ads for an explanation.
5678 if VM_Target = No_VM then
5679 Target_Undefer := RE_Abort_Undefer;
5681 Target_Undefer := RE_Update_Exception;
5683 New_List (Make_Function_Call (Loc,
5684 Name => New_Occurrence_Of
5685 (RTE (RE_Current_Target_Exception), Loc)));
5689 Make_Block_Statement (Loc,
5690 Handled_Statement_Sequence =>
5691 Make_Handled_Sequence_Of_Statements (Loc,
5692 Statements => New_List (
5693 Make_Implicit_Label_Declaration (Loc,
5694 Defining_Identifier => Blk_Ent,
5695 Label_Construct => Abortable_Block),
5700 Exception_Handlers => New_List (
5701 Make_Implicit_Exception_Handler (Loc,
5703 -- when Abort_Signal =>
5704 -- Abort_Undefer.all;
5706 Exception_Choices =>
5707 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5708 Statements => New_List (
5709 Make_Procedure_Call_Statement (Loc,
5710 Name => New_Reference_To (
5711 RTE (Target_Undefer), Loc),
5712 Parameter_Associations => Undefer_Args)))))),
5714 -- if not Cancelled (Bnn) then
5715 -- triggered statements
5718 Make_Implicit_If_Statement (N,
5719 Condition => Make_Op_Not (Loc,
5721 Make_Function_Call (Loc,
5722 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
5723 Parameter_Associations => New_List (
5724 New_Occurrence_Of (Cancel_Param, Loc)))),
5725 Then_Statements => Tstats));
5727 -- Asynchronous task entry call
5734 B := Make_Defining_Identifier (Loc, Name_uB);
5736 -- Insert declaration of B in declarations of existing block
5739 Make_Object_Declaration (Loc,
5740 Defining_Identifier => B,
5741 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
5743 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
5745 -- Insert declaration of C in declarations of existing block
5748 Make_Object_Declaration (Loc,
5749 Defining_Identifier => Cancel_Param,
5750 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
5752 -- Remove and save the call to Call_Simple
5754 Stmt := First (Stmts);
5756 -- Skip assignments to temporaries created for in-out parameters.
5757 -- This makes unwarranted assumptions about the shape of the expanded
5758 -- tree for the call, and should be cleaned up ???
5760 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
5766 -- Create the inner block to protect the abortable part
5769 Make_Implicit_Exception_Handler (Loc,
5770 Exception_Choices =>
5771 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5772 Statements => New_List (
5773 Make_Procedure_Call_Statement (Loc,
5774 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
5777 Make_Procedure_Call_Statement (Loc,
5778 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
5781 Make_Block_Statement (Loc,
5782 Identifier => New_Reference_To (Blk_Ent, Loc),
5783 Handled_Statement_Sequence =>
5784 Make_Handled_Sequence_Of_Statements (Loc,
5785 Statements => Astats),
5786 Has_Created_Identifier => True,
5787 Is_Asynchronous_Call_Block => True);
5790 Make_Block_Statement (Loc,
5791 Handled_Statement_Sequence =>
5792 Make_Handled_Sequence_Of_Statements (Loc,
5793 Statements => New_List (
5794 Make_Implicit_Label_Declaration (Loc,
5795 Defining_Identifier => Blk_Ent,
5796 Label_Construct => Abortable_Block),
5798 Exception_Handlers => Hdle)));
5800 -- Create new call statement
5802 Params := Parameter_Associations (Call);
5805 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
5807 New_Reference_To (B, Loc));
5810 Make_Procedure_Call_Statement (Loc,
5812 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
5813 Parameter_Associations => Params));
5815 -- Construct statement sequence for new block
5818 Make_Implicit_If_Statement (N,
5821 New_Reference_To (Cancel_Param, Loc)),
5822 Then_Statements => Tstats));
5824 -- Protected the call against abort
5827 Make_Procedure_Call_Statement (Loc,
5828 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
5829 Parameter_Associations => Empty_List));
5832 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
5834 -- The result is the new block
5837 Make_Block_Statement (Loc,
5838 Declarations => Decls,
5839 Handled_Statement_Sequence =>
5840 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5843 end Expand_N_Asynchronous_Select;
5845 -------------------------------------
5846 -- Expand_N_Conditional_Entry_Call --
5847 -------------------------------------
5849 -- The conditional task entry call is converted to a call to
5854 -- P : parms := (parm, parm, parm);
5861 -- Conditional_Call,
5867 -- normal-statements
5873 -- For a description of the use of P and the assignments after the
5874 -- call, see Expand_N_Entry_Call_Statement. Note that the entry call
5875 -- of the conditional entry call has already been expanded (by the
5876 -- Expand_N_Entry_Call_Statement procedure) as follows:
5879 -- P : parms := (parm, parm, parm);
5881 -- ... info for in-out parameters
5882 -- Call_Simple (acceptor-task, entry-index, P'Address);
5888 -- so the task at hand is to convert the latter expansion into the former
5890 -- The conditional protected entry call is converted to a call to
5891 -- Protected_Entry_Call:
5894 -- P : parms := (parm, parm, parm);
5895 -- Bnn : Communications_Block;
5898 -- Protected_Entry_Call (
5899 -- Object => po._object'Access,
5900 -- E => <entry index>;
5901 -- Uninterpreted_Data => P'Address;
5902 -- Mode => Conditional_Call;
5907 -- if Cancelled (Bnn) then
5910 -- normal-statements
5914 -- As for tasks, the entry call of the conditional entry call has
5915 -- already been expanded (by the Expand_N_Entry_Call_Statement procedure)
5919 -- P : E1_Params := (param, param, param);
5920 -- Bnn : Communications_Block;
5923 -- Protected_Entry_Call (
5924 -- Object => po._object'Access,
5925 -- E => <entry index>;
5926 -- Uninterpreted_Data => P'Address;
5927 -- Mode => Simple_Call;
5934 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
5938 -- B : Boolean := False;
5939 -- C : Ada.Tags.Prim_Op_Kind;
5940 -- K : Ada.Tags.Tagged_Kind :=
5941 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5942 -- P : Parameters := (Param1 .. ParamN);
5946 -- if K = Ada.Tags.TK_Limited_Tagged then
5947 -- <dispatching-call>;
5948 -- <triggering-statements>
5951 -- S := Ada.Tags.Get_Offset_Index (Ada.Tags.Tag (<object>),
5952 -- DT_Position (<dispatching-call>));
5954 -- _Disp_Conditional_Select (<object>, S, P'address, C, B);
5956 -- if C = POK_Protected_Entry
5957 -- or else C = POK_Task_Entry
5959 -- Param1 := P.Param1;
5961 -- ParamN := P.ParamN;
5965 -- if C = POK_Procedure
5966 -- or else C = POK_Protected_Procedure
5967 -- or else C = POK_Task_Procedure
5969 -- <dispatching-call>;
5972 -- <triggering-statements>
5974 -- <else-statements>
5979 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
5980 Loc : constant Source_Ptr := Sloc (N);
5981 Alt : constant Node_Id := Entry_Call_Alternative (N);
5982 Blk : Node_Id := Entry_Call_Statement (Alt);
5983 Transient_Blk : Node_Id;
5986 Blk_Typ : Entity_Id;
5988 Call_Ent : Entity_Id;
5989 Conc_Typ_Stmts : List_Id;
5993 Lim_Typ_Stmts : List_Id;
6002 B : Entity_Id; -- Call status flag
6003 C : Entity_Id; -- Call kind
6004 K : Entity_Id; -- Tagged kind
6005 P : Entity_Id; -- Parameter block
6006 S : Entity_Id; -- Primitive operation slot
6009 if Ada_Version >= Ada_05
6010 and then Nkind (Blk) = N_Procedure_Call_Statement
6012 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6017 -- Call status flag processing, generate:
6018 -- B : Boolean := False;
6020 B := Build_B (Loc, Decls);
6022 -- Call kind processing, generate:
6023 -- C : Ada.Tags.Prim_Op_Kind;
6025 C := Build_C (Loc, Decls);
6027 -- Tagged kind processing, generate:
6028 -- K : Ada.Tags.Tagged_Kind :=
6029 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6031 K := Build_K (Loc, Decls, Obj);
6033 -- Parameter block processing
6035 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6036 P := Parameter_Block_Pack
6037 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6039 -- Dispatch table slot processing, generate:
6042 S := Build_S (Loc, Decls);
6045 -- S := Ada.Tags.Get_Offset_Index (
6046 -- Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6048 Conc_Typ_Stmts := New_List (
6049 Build_S_Assignment (Loc, S, Obj, Call_Ent));
6052 -- _Disp_Conditional_Select (<object>, S, P'address, C, B);
6054 Append_To (Conc_Typ_Stmts,
6055 Make_Procedure_Call_Statement (Loc,
6058 Find_Prim_Op (Etype (Etype (Obj)),
6059 Name_uDisp_Conditional_Select),
6061 Parameter_Associations =>
6063 New_Copy_Tree (Obj),
6064 New_Reference_To (S, Loc),
6065 Make_Attribute_Reference (Loc,
6066 Prefix => New_Reference_To (P, Loc),
6067 Attribute_Name => Name_Address),
6068 New_Reference_To (C, Loc),
6069 New_Reference_To (B, Loc))));
6072 -- if C = POK_Protected_Entry
6073 -- or else C = POK_Task_Entry
6075 -- Param1 := P.Param1;
6077 -- ParamN := P.ParamN;
6080 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6082 -- Generate the if statement only when the packed parameters need
6083 -- explicit assignments to their corresponding actuals.
6085 if Present (Unpack) then
6086 Append_To (Conc_Typ_Stmts,
6087 Make_If_Statement (Loc,
6094 New_Reference_To (C, Loc),
6096 New_Reference_To (RTE (
6097 RE_POK_Protected_Entry), Loc)),
6101 New_Reference_To (C, Loc),
6103 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6111 -- if C = POK_Procedure
6112 -- or else C = POK_Protected_Procedure
6113 -- or else C = POK_Task_Procedure
6115 -- <dispatching-call>
6117 -- <normal-statements>
6119 -- <else-statements>
6122 N_Stats := New_Copy_List_Tree (Statements (Alt));
6124 Prepend_To (N_Stats,
6125 Make_If_Statement (Loc,
6131 New_Reference_To (C, Loc),
6133 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6140 New_Reference_To (C, Loc),
6142 New_Reference_To (RTE (
6143 RE_POK_Protected_Procedure), Loc)),
6148 New_Reference_To (C, Loc),
6150 New_Reference_To (RTE (
6151 RE_POK_Task_Procedure), Loc)))),
6156 Append_To (Conc_Typ_Stmts,
6157 Make_If_Statement (Loc,
6158 Condition => New_Reference_To (B, Loc),
6159 Then_Statements => N_Stats,
6160 Else_Statements => Else_Statements (N)));
6163 -- <dispatching-call>;
6164 -- <triggering-statements>
6166 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6167 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6170 -- if K = Ada.Tags.TK_Limited_Tagged then
6177 Make_If_Statement (Loc,
6181 New_Reference_To (K, Loc),
6183 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6192 Make_Block_Statement (Loc,
6193 Declarations => Decls,
6194 Handled_Statement_Sequence =>
6195 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6197 -- As described above, The entry alternative is transformed into a
6198 -- block that contains the gnulli call, and possibly assignment
6199 -- statements for in-out parameters. The gnulli call may itself be
6200 -- rewritten into a transient block if some unconstrained parameters
6201 -- require it. We need to retrieve the call to complete its parameter
6206 First_Real_Statement (Handled_Statement_Sequence (Blk));
6208 if Present (Transient_Blk)
6209 and then Nkind (Transient_Blk) = N_Block_Statement
6211 Blk := Transient_Blk;
6214 Stmts := Statements (Handled_Statement_Sequence (Blk));
6215 Stmt := First (Stmts);
6216 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6221 Params := Parameter_Associations (Call);
6223 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6225 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6227 Param := First (Params);
6228 while Present (Param)
6229 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6234 pragma Assert (Present (Param));
6235 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6239 -- Find the Communication_Block parameter for the call to the
6240 -- Cancelled function.
6242 Decl := First (Declarations (Blk));
6243 while Present (Decl)
6244 and then not Is_RTE (Etype (Object_Definition (Decl)),
6245 RE_Communication_Block)
6250 -- Add an if statement to execute the else part if the call
6251 -- does not succeed (as indicated by the Cancelled predicate).
6254 Make_Implicit_If_Statement (N,
6255 Condition => Make_Function_Call (Loc,
6256 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6257 Parameter_Associations => New_List (
6258 New_Reference_To (Defining_Identifier (Decl), Loc))),
6259 Then_Statements => Else_Statements (N),
6260 Else_Statements => Statements (Alt)));
6263 B := Make_Defining_Identifier (Loc, Name_uB);
6265 -- Insert declaration of B in declarations of existing block
6267 if No (Declarations (Blk)) then
6268 Set_Declarations (Blk, New_List);
6271 Prepend_To (Declarations (Blk),
6272 Make_Object_Declaration (Loc,
6273 Defining_Identifier => B,
6274 Object_Definition =>
6275 New_Reference_To (Standard_Boolean, Loc)));
6277 -- Create new call statement
6280 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6281 Append_To (Params, New_Reference_To (B, Loc));
6284 Make_Procedure_Call_Statement (Loc,
6285 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6286 Parameter_Associations => Params));
6288 -- Construct statement sequence for new block
6291 Make_Implicit_If_Statement (N,
6292 Condition => New_Reference_To (B, Loc),
6293 Then_Statements => Statements (Alt),
6294 Else_Statements => Else_Statements (N)));
6297 -- The result is the new block
6300 Make_Block_Statement (Loc,
6301 Declarations => Declarations (Blk),
6302 Handled_Statement_Sequence =>
6303 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6307 end Expand_N_Conditional_Entry_Call;
6309 ---------------------------------------
6310 -- Expand_N_Delay_Relative_Statement --
6311 ---------------------------------------
6313 -- Delay statement is implemented as a procedure call to Delay_For
6314 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6315 -- simple delays imposed by the use of Protected Objects.
6317 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6318 Loc : constant Source_Ptr := Sloc (N);
6321 Make_Procedure_Call_Statement (Loc,
6322 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6323 Parameter_Associations => New_List (Expression (N))));
6325 end Expand_N_Delay_Relative_Statement;
6327 ------------------------------------
6328 -- Expand_N_Delay_Until_Statement --
6329 ------------------------------------
6331 -- Delay Until statement is implemented as a procedure call to
6332 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6334 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6335 Loc : constant Source_Ptr := Sloc (N);
6339 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6340 Typ := RTE (RO_CA_Delay_Until);
6342 Typ := RTE (RO_RT_Delay_Until);
6346 Make_Procedure_Call_Statement (Loc,
6347 Name => New_Reference_To (Typ, Loc),
6348 Parameter_Associations => New_List (Expression (N))));
6351 end Expand_N_Delay_Until_Statement;
6353 -------------------------
6354 -- Expand_N_Entry_Body --
6355 -------------------------
6357 procedure Expand_N_Entry_Body (N : Node_Id) is
6358 Loc : constant Source_Ptr := Sloc (N);
6359 Dec : constant Node_Id := Parent (Current_Scope);
6360 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
6361 Index_Spec : constant Node_Id :=
6362 Entry_Index_Specification (Ent_Formals);
6364 First_Decl : constant Node_Id := First (Declarations (N));
6365 Index_Decl : List_Id;
6368 -- Add the renamings for private declarations and discriminants
6370 Add_Discriminal_Declarations
6371 (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc);
6372 Add_Private_Declarations
6373 (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc);
6375 if Present (Index_Spec) then
6377 Index_Constant_Declaration
6379 Defining_Identifier (Index_Spec), Defining_Identifier (Dec));
6381 -- If the entry has local declarations, insert index declaration
6382 -- before them, because the index may be used therein.
6384 if Present (First_Decl) then
6385 Insert_List_Before (First_Decl, Index_Decl);
6387 Append_List_To (Declarations (N), Index_Decl);
6391 -- Associate privals and discriminals with the next protected operation
6392 -- body to be expanded. These are used to expand references to private
6393 -- data objects and discriminants, respectively.
6395 Next_Op := Next_Protected_Operation (N);
6397 if Present (Next_Op) then
6398 Set_Privals (Dec, Next_Op, Loc);
6399 Set_Discriminals (Dec);
6401 end Expand_N_Entry_Body;
6403 -----------------------------------
6404 -- Expand_N_Entry_Call_Statement --
6405 -----------------------------------
6407 -- An entry call is expanded into GNARLI calls to implement
6408 -- a simple entry call (see Build_Simple_Entry_Call).
6410 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
6416 if No_Run_Time_Mode then
6417 Error_Msg_CRT ("entry call", N);
6421 -- If this entry call is part of an asynchronous select, don't expand it
6422 -- here; it will be expanded with the select statement. Don't expand
6423 -- timed entry calls either, as they are translated into asynchronous
6426 -- ??? This whole approach is questionable; it may be better to go back
6427 -- to allowing the expansion to take place and then attempting to fix it
6428 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6429 -- whether the expanded call is on a task or protected entry.
6431 if (Nkind (Parent (N)) /= N_Triggering_Alternative
6432 or else N /= Triggering_Statement (Parent (N)))
6433 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
6434 or else N /= Entry_Call_Statement (Parent (N))
6435 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
6437 Extract_Entry (N, Concval, Ename, Index);
6438 Build_Simple_Entry_Call (N, Concval, Ename, Index);
6440 end Expand_N_Entry_Call_Statement;
6442 --------------------------------
6443 -- Expand_N_Entry_Declaration --
6444 --------------------------------
6446 -- If there are parameters, then first, each of the formals is marked by
6447 -- setting Is_Entry_Formal. Next a record type is built which is used to
6448 -- hold the parameter values. The name of this record type is entryP where
6449 -- entry is the name of the entry, with an additional corresponding access
6450 -- type called entryPA. The record type has matching components for each
6451 -- formal (the component names are the same as the formal names). For
6452 -- elementary types, the component type matches the formal type. For
6453 -- composite types, an access type is declared (with the name formalA)
6454 -- which designates the formal type, and the type of the component is this
6455 -- access type. Finally the Entry_Component of each formal is set to
6456 -- reference the corresponding record component.
6458 procedure Expand_N_Entry_Declaration (N : Node_Id) is
6459 Loc : constant Source_Ptr := Sloc (N);
6460 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
6461 Components : List_Id;
6464 Last_Decl : Node_Id;
6465 Component : Entity_Id;
6468 Rec_Ent : Entity_Id;
6469 Acc_Ent : Entity_Id;
6472 Formal := First_Formal (Entry_Ent);
6475 -- Most processing is done only if parameters are present
6477 if Present (Formal) then
6478 Components := New_List;
6480 -- Loop through formals
6482 while Present (Formal) loop
6483 Set_Is_Entry_Formal (Formal);
6485 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
6486 Set_Entry_Component (Formal, Component);
6487 Set_Entry_Formal (Component, Formal);
6488 Ftype := Etype (Formal);
6490 -- Declare new access type and then append
6493 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6496 Make_Full_Type_Declaration (Loc,
6497 Defining_Identifier => Ctype,
6499 Make_Access_To_Object_Definition (Loc,
6500 All_Present => True,
6501 Constant_Present => Ekind (Formal) = E_In_Parameter,
6502 Subtype_Indication => New_Reference_To (Ftype, Loc)));
6504 Insert_After (Last_Decl, Decl);
6507 Append_To (Components,
6508 Make_Component_Declaration (Loc,
6509 Defining_Identifier => Component,
6510 Component_Definition =>
6511 Make_Component_Definition (Loc,
6512 Aliased_Present => False,
6513 Subtype_Indication => New_Reference_To (Ctype, Loc))));
6515 Next_Formal_With_Extras (Formal);
6518 -- Create the Entry_Parameter_Record declaration
6521 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
6524 Make_Full_Type_Declaration (Loc,
6525 Defining_Identifier => Rec_Ent,
6527 Make_Record_Definition (Loc,
6529 Make_Component_List (Loc,
6530 Component_Items => Components)));
6532 Insert_After (Last_Decl, Decl);
6535 -- Construct and link in the corresponding access type
6538 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6540 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
6543 Make_Full_Type_Declaration (Loc,
6544 Defining_Identifier => Acc_Ent,
6546 Make_Access_To_Object_Definition (Loc,
6547 All_Present => True,
6548 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
6550 Insert_After (Last_Decl, Decl);
6553 end Expand_N_Entry_Declaration;
6555 -----------------------------
6556 -- Expand_N_Protected_Body --
6557 -----------------------------
6559 -- Protected bodies are expanded to the completion of the subprograms
6560 -- created for the corresponding protected type. These are a protected and
6561 -- unprotected version of each protected subprogram in the object, a
6562 -- function to calculate each entry barrier, and a procedure to execute the
6563 -- sequence of statements of each protected entry body. For example, for
6564 -- protected type ptype:
6567 -- (O : System.Address;
6568 -- E : Protected_Entry_Index)
6571 -- <discriminant renamings>
6572 -- <private object renamings>
6574 -- return <barrier expression>;
6577 -- procedure pprocN (_object : in out poV;...) is
6578 -- <discriminant renamings>
6579 -- <private object renamings>
6581 -- <sequence of statements>
6584 -- procedure pprocP (_object : in out poV;...) is
6585 -- procedure _clean is
6588 -- ptypeS (_object, Pn);
6589 -- Unlock (_object._object'Access);
6590 -- Abort_Undefer.all;
6595 -- Lock (_object._object'Access);
6596 -- pprocN (_object;...);
6601 -- function pfuncN (_object : poV;...) return Return_Type is
6602 -- <discriminant renamings>
6603 -- <private object renamings>
6605 -- <sequence of statements>
6608 -- function pfuncP (_object : poV) return Return_Type is
6609 -- procedure _clean is
6611 -- Unlock (_object._object'Access);
6612 -- Abort_Undefer.all;
6617 -- Lock (_object._object'Access);
6618 -- return pfuncN (_object);
6625 -- (O : System.Address;
6626 -- P : System.Address;
6627 -- E : Protected_Entry_Index)
6629 -- <discriminant renamings>
6630 -- <private object renamings>
6631 -- type poVP is access poV;
6632 -- _Object : ptVP := ptVP!(O);
6636 -- <statement sequence>
6637 -- Complete_Entry_Body (_Object._Object);
6639 -- when all others =>
6640 -- Exceptional_Complete_Entry_Body (
6641 -- _Object._Object, Get_GNAT_Exception);
6645 -- The type poV is the record created for the protected type to hold
6646 -- the state of the protected object.
6648 procedure Expand_N_Protected_Body (N : Node_Id) is
6649 Loc : constant Source_Ptr := Sloc (N);
6650 Pid : constant Entity_Id := Corresponding_Spec (N);
6651 Has_Entries : Boolean := False;
6655 Disp_Op_Body : Node_Id;
6656 New_Op_Body : Node_Id;
6657 Current_Node : Node_Id;
6658 Num_Entries : Natural := 0;
6660 function Build_Dispatching_Subprogram_Body
6663 Prot_Bod : Node_Id) return Node_Id;
6664 -- Build a dispatching version of the protected subprogram body. The
6665 -- newly generated subprogram contains a call to the original protected
6666 -- body. The following code is generated:
6668 -- function <protected-function-name> (Param1 .. ParamN) return
6671 -- return <protected-function-name>P (Param1 .. ParamN);
6672 -- end <protected-function-name>;
6676 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
6678 -- <protected-procedure-name>P (Param1 .. ParamN);
6679 -- end <protected-procedure-name>
6681 ---------------------------------------
6682 -- Build_Dispatching_Subprogram_Body --
6683 ---------------------------------------
6685 function Build_Dispatching_Subprogram_Body
6688 Prot_Bod : Node_Id) return Node_Id
6690 Loc : constant Source_Ptr := Sloc (N);
6697 -- Generate a specification without a letter suffix in order to
6698 -- override an interface function or procedure.
6701 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
6703 -- The formal parameters become the actuals of the protected
6704 -- function or procedure call.
6706 Actuals := New_List;
6707 Formal := First (Parameter_Specifications (Spec));
6708 while Present (Formal) loop
6710 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
6715 if Nkind (Spec) = N_Procedure_Specification then
6718 Make_Procedure_Call_Statement (Loc,
6720 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
6721 Parameter_Associations => Actuals));
6723 pragma Assert (Nkind (Spec) = N_Function_Specification);
6727 Make_Return_Statement (Loc,
6729 Make_Function_Call (Loc,
6731 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
6732 Parameter_Associations => Actuals)));
6736 Make_Subprogram_Body (Loc,
6737 Declarations => Empty_List,
6738 Specification => Spec,
6739 Handled_Statement_Sequence =>
6740 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
6741 end Build_Dispatching_Subprogram_Body;
6743 -- Start of processing for Expand_N_Protected_Body
6746 if No_Run_Time_Mode then
6747 Error_Msg_CRT ("protected body", N);
6751 if Nkind (Parent (N)) = N_Subunit then
6753 -- This is the proper body corresponding to a stub. The declarations
6754 -- must be inserted at the point of the stub, which is in the decla-
6755 -- rative part of the parent unit.
6757 Current_Node := Corresponding_Stub (Parent (N));
6763 Op_Body := First (Declarations (N));
6765 -- The protected body is replaced with the bodies of its
6766 -- protected operations, and the declarations for internal objects
6767 -- that may have been created for entry family bounds.
6769 Rewrite (N, Make_Null_Statement (Sloc (N)));
6772 while Present (Op_Body) loop
6773 case Nkind (Op_Body) is
6774 when N_Subprogram_Declaration =>
6777 when N_Subprogram_Body =>
6779 -- Exclude functions created to analyze defaults
6781 if not Is_Eliminated (Defining_Entity (Op_Body))
6782 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
6785 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
6787 -- Propagate the finalization chain to the new body.
6788 -- In the unlikely event that the subprogram contains a
6789 -- declaration or allocator for an object that requires
6790 -- finalization, the corresponding chain is created when
6791 -- analyzing the body, and attached to its entity. This
6792 -- entity is not further elaborated, and so the chain
6793 -- properly belongs to the newly created subprogram body.
6796 (Finalization_Chain_Entity (Defining_Entity (Op_Body)))
6798 Set_Finalization_Chain_Entity
6799 (Protected_Body_Subprogram
6800 (Corresponding_Spec (Op_Body)),
6801 Finalization_Chain_Entity (Defining_Entity (Op_Body)));
6803 (Handled_Statement_Sequence (New_Op_Body), False);
6806 Insert_After (Current_Node, New_Op_Body);
6807 Current_Node := New_Op_Body;
6808 Analyze (New_Op_Body);
6810 Update_Prival_Subtypes (New_Op_Body);
6812 -- Build the corresponding protected operation. It may
6813 -- appear that this is needed only this is a visible
6814 -- operation of the type, or if it is an interrupt handler,
6815 -- and this was the strategy used previously in GNAT.
6816 -- However, the operation may be exported through a
6817 -- 'Access to an external caller. This is the common idiom
6818 -- in code that uses the Ada 2005 Timing_Events package
6819 -- As a result we need to produce the protected body for
6820 -- both visible and private operations.
6822 if Present (Corresponding_Spec (Op_Body)) then
6824 Unit_Declaration_Node (Corresponding_Spec (Op_Body));
6827 Nkind (Parent (Op_Decl)) = N_Protected_Definition
6830 Build_Protected_Subprogram_Body (
6831 Op_Body, Pid, Specification (New_Op_Body));
6833 Insert_After (Current_Node, New_Op_Body);
6834 Analyze (New_Op_Body);
6836 Current_Node := New_Op_Body;
6838 -- Generate an overriding primitive operation body for
6839 -- this subprogram if the protected type implements
6842 if Ada_Version >= Ada_05
6843 and then Present (Abstract_Interfaces (
6844 Corresponding_Record_Type (Pid)))
6847 Build_Dispatching_Subprogram_Body (
6848 Op_Body, Pid, New_Op_Body);
6850 Insert_After (Current_Node, Disp_Op_Body);
6851 Analyze (Disp_Op_Body);
6853 Current_Node := Disp_Op_Body;
6859 when N_Entry_Body =>
6860 Op_Id := Defining_Identifier (Op_Body);
6861 Has_Entries := True;
6862 Num_Entries := Num_Entries + 1;
6864 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
6866 Insert_After (Current_Node, New_Op_Body);
6867 Current_Node := New_Op_Body;
6868 Analyze (New_Op_Body);
6870 Update_Prival_Subtypes (New_Op_Body);
6872 when N_Implicit_Label_Declaration =>
6875 when N_Itype_Reference =>
6876 Insert_After (Current_Node, New_Copy (Op_Body));
6878 when N_Freeze_Entity =>
6879 New_Op_Body := New_Copy (Op_Body);
6881 if Present (Entity (Op_Body))
6882 and then Freeze_Node (Entity (Op_Body)) = Op_Body
6884 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
6887 Insert_After (Current_Node, New_Op_Body);
6888 Current_Node := New_Op_Body;
6889 Analyze (New_Op_Body);
6892 New_Op_Body := New_Copy (Op_Body);
6893 Insert_After (Current_Node, New_Op_Body);
6894 Current_Node := New_Op_Body;
6895 Analyze (New_Op_Body);
6897 when N_Object_Declaration =>
6898 pragma Assert (not Comes_From_Source (Op_Body));
6899 New_Op_Body := New_Copy (Op_Body);
6900 Insert_After (Current_Node, New_Op_Body);
6901 Current_Node := New_Op_Body;
6902 Analyze (New_Op_Body);
6905 raise Program_Error;
6912 -- Finally, create the body of the function that maps an entry index
6913 -- into the corresponding body index, except when there is no entry,
6914 -- or in a ravenscar-like profile (no abort, no entry queue, 1 entry)
6917 and then (Abort_Allowed
6918 or else Restriction_Active (No_Entry_Queue) = False
6919 or else Num_Entries > 1
6920 or else (Has_Attach_Handler (Pid)
6921 and then not Restricted_Profile))
6923 New_Op_Body := Build_Find_Body_Index (Pid);
6924 Insert_After (Current_Node, New_Op_Body);
6925 Current_Node := New_Op_Body;
6926 Analyze (New_Op_Body);
6929 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
6930 -- the protected body. At this point the entry specs have been created,
6931 -- frozen and included in the dispatch table for the protected type.
6933 pragma Assert (Present (Corresponding_Record_Type (Pid)));
6935 if Ada_Version >= Ada_05
6936 and then Present (Protected_Definition (Parent (Pid)))
6937 and then Present (Abstract_Interfaces
6938 (Corresponding_Record_Type (Pid)))
6941 Vis_Decl : Node_Id :=
6942 First (Visible_Declarations
6943 (Protected_Definition (Parent (Pid))));
6944 Wrap_Body : Node_Id;
6947 -- Examine the visible declarations of the protected type, looking
6948 -- for an entry declaration. We do not consider entry families
6949 -- since they cannot have dispatching operations, thus they do not
6950 -- need entry wrappers.
6952 while Present (Vis_Decl) loop
6953 if Nkind (Vis_Decl) = N_Entry_Declaration then
6955 Build_Wrapper_Body (Loc,
6956 Proc_Nam => Defining_Identifier (Vis_Decl),
6957 Obj_Typ => Corresponding_Record_Type (Pid),
6958 Formals => Parameter_Specifications (Vis_Decl));
6960 if Wrap_Body /= Empty then
6961 Insert_After (Current_Node, Wrap_Body);
6962 Current_Node := Wrap_Body;
6964 Analyze (Wrap_Body);
6967 elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then
6969 Build_Wrapper_Body (Loc,
6970 Proc_Nam => Defining_Unit_Name
6971 (Specification (Vis_Decl)),
6972 Obj_Typ => Corresponding_Record_Type (Pid),
6973 Formals => Parameter_Specifications
6974 (Specification (Vis_Decl)));
6976 if Wrap_Body /= Empty then
6977 Insert_After (Current_Node, Wrap_Body);
6978 Current_Node := Wrap_Body;
6980 Analyze (Wrap_Body);
6988 end Expand_N_Protected_Body;
6990 -----------------------------------------
6991 -- Expand_N_Protected_Type_Declaration --
6992 -----------------------------------------
6994 -- First we create a corresponding record type declaration used to
6995 -- represent values of this protected type.
6996 -- The general form of this type declaration is
6998 -- type poV (discriminants) is record
6999 -- _Object : aliased <kind>Protection
7000 -- [(<entry count> [, <handler count>])];
7001 -- [entry_family : array (bounds) of Void;]
7002 -- <private data fields>
7005 -- The discriminants are present only if the corresponding protected type
7006 -- has discriminants, and they exactly mirror the protected type
7007 -- discriminants. The private data fields similarly mirror the private
7008 -- declarations of the protected type.
7010 -- The Object field is always present. It contains RTS specific data used
7011 -- to control the protected object. It is declared as Aliased so that it
7012 -- can be passed as a pointer to the RTS. This allows the protected record
7013 -- to be referenced within RTS data structures. An appropriate Protection
7014 -- type and discriminant are generated.
7016 -- The Service field is present for protected objects with entries. It
7017 -- contains sufficient information to allow the entry service procedure for
7018 -- this object to be called when the object is not known till runtime.
7020 -- One entry_family component is present for each entry family in the
7021 -- task definition (see Expand_N_Task_Type_Declaration).
7023 -- When a protected object is declared, an instance of the protected type
7024 -- value record is created. The elaboration of this declaration creates the
7025 -- correct bounds for the entry families, and also evaluates the priority
7026 -- expression if needed. The initialization routine for the protected type
7027 -- itself then calls Initialize_Protection with appropriate parameters to
7028 -- initialize the value of the Task_Id field. Install_Handlers may be also
7029 -- called if a pragma Attach_Handler applies.
7031 -- Note: this record is passed to the subprograms created by the expansion
7032 -- of protected subprograms and entries. It is an in parameter to protected
7033 -- functions and an in out parameter to procedures and entry bodies. The
7034 -- Entity_Id for this created record type is placed in the
7035 -- Corresponding_Record_Type field of the associated protected type entity.
7037 -- Next we create a procedure specifications for protected subprograms and
7038 -- entry bodies. For each protected subprograms two subprograms are
7039 -- created, an unprotected and a protected version. The unprotected version
7040 -- is called from within other operations of the same protected object.
7042 -- We also build the call to register the procedure if a pragma
7043 -- Interrupt_Handler applies.
7045 -- A single subprogram is created to service all entry bodies; it has an
7046 -- additional boolean out parameter indicating that the previous entry call
7047 -- made by the current task was serviced immediately, i.e. not by proxy.
7048 -- The O parameter contains a pointer to a record object of the type
7049 -- described above. An untyped interface is used here to allow this
7050 -- procedure to be called in places where the type of the object to be
7051 -- serviced is not known. This must be done, for example, when a call that
7052 -- may have been requeued is cancelled; the corresponding object must be
7053 -- serviced, but which object that is not known till runtime.
7056 -- (O : System.Address; P : out Boolean);
7057 -- procedure pprocN (_object : in out poV);
7058 -- procedure pproc (_object : in out poV);
7059 -- function pfuncN (_object : poV);
7060 -- function pfunc (_object : poV);
7063 -- Note that this must come after the record type declaration, since
7064 -- the specs refer to this type.
7066 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7067 Loc : constant Source_Ptr := Sloc (N);
7068 Prottyp : constant Entity_Id := Defining_Identifier (N);
7070 Pdef : constant Node_Id := Protected_Definition (N);
7071 -- This contains two lists; one for visible and one for private decls
7075 Discr_Map : constant Elist_Id := New_Elmt_List;
7079 Comp_Id : Entity_Id;
7081 Current_Node : Node_Id := N;
7082 Bdef : Entity_Id := Empty; -- avoid uninit warning
7083 Edef : Entity_Id := Empty; -- avoid uninit warning
7084 Entries_Aggr : Node_Id;
7085 Body_Id : Entity_Id;
7088 Object_Comp : Node_Id;
7090 procedure Register_Handler;
7091 -- For a protected operation that is an interrupt handler, add the
7092 -- freeze action that will register it as such.
7094 ----------------------
7095 -- Register_Handler --
7096 ----------------------
7098 procedure Register_Handler is
7100 -- All semantic checks already done in Sem_Prag
7102 Prot_Proc : constant Entity_Id :=
7104 (Specification (Current_Node));
7106 Proc_Address : constant Node_Id :=
7107 Make_Attribute_Reference (Loc,
7108 Prefix => New_Reference_To (Prot_Proc, Loc),
7109 Attribute_Name => Name_Address);
7111 RTS_Call : constant Entity_Id :=
7112 Make_Procedure_Call_Statement (Loc,
7115 RTE (RE_Register_Interrupt_Handler), Loc),
7116 Parameter_Associations =>
7117 New_List (Proc_Address));
7119 Append_Freeze_Action (Prot_Proc, RTS_Call);
7120 end Register_Handler;
7122 -- Start of processing for Expand_N_Protected_Type_Declaration
7125 if Present (Corresponding_Record_Type (Prottyp)) then
7128 Rec_Decl := Build_Corresponding_Record (N, Prottyp, Loc);
7131 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7133 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7134 -- of implemented interfaces.
7136 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
7138 Qualify_Entity_Names (N);
7140 -- If the type has discriminants, their occurrences in the declaration
7141 -- have been replaced by the corresponding discriminals. For components
7142 -- that are constrained by discriminants, their homologues in the
7143 -- corresponding record type must refer to the discriminants of that
7144 -- record, so we must apply a new renaming to subtypes_indications:
7146 -- protected discriminant => discriminal => record discriminant
7148 -- This replacement is not applied to default expressions, for which
7149 -- the discriminal is correct.
7151 if Has_Discriminants (Prottyp) then
7156 Disc := First_Discriminant (Prottyp);
7157 Decl := First (Discriminant_Specifications (Rec_Decl));
7158 while Present (Disc) loop
7159 Append_Elmt (Discriminal (Disc), Discr_Map);
7160 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7161 Next_Discriminant (Disc);
7167 -- Fill in the component declarations
7169 -- Add components for entry families. For each entry family, create an
7170 -- anonymous type declaration with the same size, and analyze the type.
7172 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prottyp);
7174 -- Prepend the _Object field with the right type to the component list.
7175 -- We need to compute the number of entries, and in some cases the
7176 -- number of Attach_Handler pragmas.
7180 Num_Attach_Handler : Int := 0;
7181 Protection_Subtype : Node_Id;
7182 Entry_Count_Expr : constant Node_Id :=
7183 Build_Entry_Count_Expression
7184 (Prottyp, Cdecls, Loc);
7187 if Has_Attach_Handler (Prottyp) then
7188 Ritem := First_Rep_Item (Prottyp);
7189 while Present (Ritem) loop
7190 if Nkind (Ritem) = N_Pragma
7191 and then Chars (Ritem) = Name_Attach_Handler
7193 Num_Attach_Handler := Num_Attach_Handler + 1;
7196 Next_Rep_Item (Ritem);
7199 if Restricted_Profile then
7200 if Has_Entries (Prottyp) then
7201 Protection_Subtype :=
7202 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7204 Protection_Subtype :=
7205 New_Reference_To (RTE (RE_Protection), Loc);
7208 Protection_Subtype :=
7209 Make_Subtype_Indication
7213 (RTE (RE_Static_Interrupt_Protection), Loc),
7215 Make_Index_Or_Discriminant_Constraint (
7217 Constraints => New_List (
7219 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7222 elsif Has_Interrupt_Handler (Prottyp) then
7223 Protection_Subtype :=
7224 Make_Subtype_Indication (
7226 Subtype_Mark => New_Reference_To
7227 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7229 Make_Index_Or_Discriminant_Constraint (
7231 Constraints => New_List (Entry_Count_Expr)));
7233 -- Type has explicit entries or generated primitive entry wrappers
7235 elsif Has_Entries (Prottyp)
7236 or else (Ada_Version >= Ada_05
7237 and then Present (Interface_List (N)))
7240 or else Restriction_Active (No_Entry_Queue) = False
7241 or else Number_Entries (Prottyp) > 1
7243 Protection_Subtype :=
7244 Make_Subtype_Indication (
7247 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7249 Make_Index_Or_Discriminant_Constraint (
7251 Constraints => New_List (Entry_Count_Expr)));
7254 Protection_Subtype :=
7255 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7259 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7263 Make_Component_Declaration (Loc,
7264 Defining_Identifier =>
7265 Make_Defining_Identifier (Loc, Name_uObject),
7266 Component_Definition =>
7267 Make_Component_Definition (Loc,
7268 Aliased_Present => True,
7269 Subtype_Indication => Protection_Subtype));
7272 pragma Assert (Present (Pdef));
7274 -- Add private field components
7276 if Present (Private_Declarations (Pdef)) then
7277 Priv := First (Private_Declarations (Pdef));
7279 while Present (Priv) loop
7281 if Nkind (Priv) = N_Component_Declaration then
7283 -- The component definition consists of a subtype indication,
7284 -- or (in Ada 2005) an access definition. Make a copy of the
7285 -- proper definition.
7288 Old_Comp : constant Node_Id := Component_Definition (Priv);
7289 Pent : constant Entity_Id := Defining_Identifier (Priv);
7293 if Present (Subtype_Indication (Old_Comp)) then
7295 Make_Component_Definition (Sloc (Pent),
7296 Aliased_Present => False,
7297 Subtype_Indication =>
7298 New_Copy_Tree (Subtype_Indication (Old_Comp),
7302 Make_Component_Definition (Sloc (Pent),
7303 Aliased_Present => False,
7304 Access_Definition =>
7305 New_Copy_Tree (Access_Definition (Old_Comp),
7310 Make_Component_Declaration (Loc,
7311 Defining_Identifier =>
7312 Make_Defining_Identifier (Sloc (Pent), Chars (Pent)),
7313 Component_Definition => New_Comp,
7314 Expression => Expression (Priv));
7316 Append_To (Cdecls, New_Priv);
7319 elsif Nkind (Priv) = N_Subprogram_Declaration then
7321 -- Make the unprotected version of the subprogram available
7322 -- for expansion of intra object calls. There is need for
7323 -- a protected version only if the subprogram is an interrupt
7324 -- handler, otherwise this operation can only be called from
7328 Make_Subprogram_Declaration (Loc,
7330 Build_Protected_Sub_Specification
7331 (Priv, Prottyp, Unprotected_Mode));
7333 Insert_After (Current_Node, Sub);
7336 Set_Protected_Body_Subprogram
7337 (Defining_Unit_Name (Specification (Priv)),
7338 Defining_Unit_Name (Specification (Sub)));
7340 Current_Node := Sub;
7343 Make_Subprogram_Declaration (Loc,
7345 Build_Protected_Sub_Specification
7346 (Priv, Prottyp, Protected_Mode));
7348 Insert_After (Current_Node, Sub);
7350 Current_Node := Sub;
7352 if Is_Interrupt_Handler
7353 (Defining_Unit_Name (Specification (Priv)))
7355 if not Restricted_Profile then
7365 -- Put the _Object component after the private component so that it
7366 -- be finalized early as required by 9.4 (20)
7368 Append_To (Cdecls, Object_Comp);
7370 Insert_After (Current_Node, Rec_Decl);
7371 Current_Node := Rec_Decl;
7373 -- Analyze the record declaration immediately after construction,
7374 -- because the initialization procedure is needed for single object
7375 -- declarations before the next entity is analyzed (the freeze call
7376 -- that generates this initialization procedure is found below).
7378 Analyze (Rec_Decl, Suppress => All_Checks);
7380 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7381 -- the corresponding record is frozen
7383 if Ada_Version >= Ada_05
7384 and then Present (Visible_Declarations (Pdef))
7385 and then Present (Corresponding_Record_Type
7386 (Defining_Identifier (Parent (Pdef))))
7387 and then Present (Abstract_Interfaces
7388 (Corresponding_Record_Type
7389 (Defining_Identifier (Parent (Pdef)))))
7392 Current_Node : Node_Id := Rec_Decl;
7394 Wrap_Spec : Node_Id;
7398 -- Examine the visible declarations of the protected type, looking
7399 -- for declarations of entries, and subprograms. We do not
7400 -- consider entry families since they cannot have dispatching
7401 -- operations, thus they do not need entry wrappers.
7403 Vis_Decl := First (Visible_Declarations (Pdef));
7405 while Present (Vis_Decl) loop
7409 if Nkind (Vis_Decl) = N_Entry_Declaration
7410 and then No (Discrete_Subtype_Definition (Vis_Decl))
7413 Build_Wrapper_Spec (Loc,
7414 Proc_Nam => Defining_Identifier (Vis_Decl),
7415 Obj_Typ => Defining_Identifier (Rec_Decl),
7416 Formals => Parameter_Specifications (Vis_Decl));
7418 elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then
7420 Build_Wrapper_Spec (Loc,
7421 Proc_Nam => Defining_Unit_Name
7422 (Specification (Vis_Decl)),
7423 Obj_Typ => Defining_Identifier (Rec_Decl),
7424 Formals => Parameter_Specifications
7425 (Specification (Vis_Decl)));
7429 if Wrap_Spec /= Empty then
7430 New_N := Make_Subprogram_Declaration (Loc,
7431 Specification => Wrap_Spec);
7433 Insert_After (Current_Node, New_N);
7434 Current_Node := New_N;
7444 -- Collect pointers to entry bodies and their barriers, to be placed
7445 -- in the Entry_Bodies_Array for the type. For each entry/family we
7446 -- add an expression to the aggregate which is the initial value of
7447 -- this array. The array is declared after all protected subprograms.
7449 if Has_Entries (Prottyp) then
7451 Make_Aggregate (Loc, Expressions => New_List);
7454 Entries_Aggr := Empty;
7457 -- Build two new procedure specifications for each protected subprogram;
7458 -- one to call from outside the object and one to call from inside.
7459 -- Build a barrier function and an entry body action procedure
7460 -- specification for each protected entry. Initialize the entry body
7461 -- array. If subprogram is flagged as eliminated, do not generate any
7462 -- internal operations.
7466 Comp := First (Visible_Declarations (Pdef));
7468 while Present (Comp) loop
7469 if Nkind (Comp) = N_Subprogram_Declaration
7470 and then not Is_Eliminated (Defining_Entity (Comp))
7473 Make_Subprogram_Declaration (Loc,
7475 Build_Protected_Sub_Specification
7476 (Comp, Prottyp, Unprotected_Mode));
7478 Insert_After (Current_Node, Sub);
7481 Set_Protected_Body_Subprogram
7482 (Defining_Unit_Name (Specification (Comp)),
7483 Defining_Unit_Name (Specification (Sub)));
7485 -- Make the protected version of the subprogram available for
7486 -- expansion of external calls.
7488 Current_Node := Sub;
7491 Make_Subprogram_Declaration (Loc,
7493 Build_Protected_Sub_Specification
7494 (Comp, Prottyp, Protected_Mode));
7496 Insert_After (Current_Node, Sub);
7499 Current_Node := Sub;
7501 -- Generate an overriding primitive operation specification for
7502 -- this subprogram if the protected type implements an inerface.
7504 if Ada_Version >= Ada_05
7506 Present (Abstract_Interfaces
7507 (Corresponding_Record_Type (Prottyp)))
7510 Make_Subprogram_Declaration (Loc,
7512 Build_Protected_Sub_Specification
7513 (Comp, Prottyp, Dispatching_Mode));
7515 Insert_After (Current_Node, Sub);
7518 Current_Node := Sub;
7521 -- If a pragma Interrupt_Handler applies, build and add a call to
7522 -- Register_Interrupt_Handler to the freezing actions of the
7523 -- protected version (Current_Node) of the subprogram:
7525 -- system.interrupts.register_interrupt_handler
7526 -- (prot_procP'address);
7528 if not Restricted_Profile
7529 and then Is_Interrupt_Handler
7530 (Defining_Unit_Name (Specification (Comp)))
7535 elsif Nkind (Comp) = N_Entry_Declaration then
7536 E_Count := E_Count + 1;
7537 Comp_Id := Defining_Identifier (Comp);
7538 Set_Privals_Chain (Comp_Id, New_Elmt_List);
7540 Make_Defining_Identifier (Loc,
7541 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7543 Make_Subprogram_Declaration (Loc,
7545 Build_Protected_Entry_Specification (Edef, Comp_Id, Loc));
7547 Insert_After (Current_Node, Sub);
7550 Set_Protected_Body_Subprogram (
7551 Defining_Identifier (Comp),
7552 Defining_Unit_Name (Specification (Sub)));
7554 Current_Node := Sub;
7557 Make_Defining_Identifier (Loc,
7558 Build_Selected_Name (Prottyp, Comp_Id, 'B'));
7560 Make_Subprogram_Declaration (Loc,
7562 Build_Barrier_Function_Specification (Bdef, Loc));
7564 Insert_After (Current_Node, Sub);
7566 Set_Protected_Body_Subprogram (Bdef, Bdef);
7567 Set_Barrier_Function (Comp_Id, Bdef);
7568 Set_Scope (Bdef, Scope (Comp_Id));
7569 Current_Node := Sub;
7571 -- Collect pointers to the protected subprogram and the barrier
7572 -- of the current entry, for insertion into Entry_Bodies_Array.
7575 Make_Aggregate (Loc,
7576 Expressions => New_List (
7577 Make_Attribute_Reference (Loc,
7578 Prefix => New_Reference_To (Bdef, Loc),
7579 Attribute_Name => Name_Unrestricted_Access),
7580 Make_Attribute_Reference (Loc,
7581 Prefix => New_Reference_To (Edef, Loc),
7582 Attribute_Name => Name_Unrestricted_Access))),
7583 Expressions (Entries_Aggr));
7590 -- If there are some private entry declarations, expand it as if they
7591 -- were visible entries.
7593 if Present (Private_Declarations (Pdef)) then
7594 Comp := First (Private_Declarations (Pdef));
7595 while Present (Comp) loop
7596 if Nkind (Comp) = N_Entry_Declaration then
7597 E_Count := E_Count + 1;
7598 Comp_Id := Defining_Identifier (Comp);
7599 Set_Privals_Chain (Comp_Id, New_Elmt_List);
7601 Make_Defining_Identifier (Loc,
7602 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7605 Make_Subprogram_Declaration (Loc,
7607 Build_Protected_Entry_Specification (Edef, Comp_Id, Loc));
7609 Insert_After (Current_Node, Sub);
7612 Set_Protected_Body_Subprogram (
7613 Defining_Identifier (Comp),
7614 Defining_Unit_Name (Specification (Sub)));
7616 Current_Node := Sub;
7619 Make_Defining_Identifier (Loc,
7620 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7623 Make_Subprogram_Declaration (Loc,
7625 Build_Barrier_Function_Specification (Bdef, Loc));
7627 Insert_After (Current_Node, Sub);
7629 Set_Protected_Body_Subprogram (Bdef, Bdef);
7630 Set_Barrier_Function (Comp_Id, Bdef);
7631 Set_Scope (Bdef, Scope (Comp_Id));
7632 Current_Node := Sub;
7634 -- Collect pointers to the protected subprogram and the barrier
7635 -- of the current entry, for insertion into Entry_Bodies_Array.
7638 Make_Aggregate (Loc,
7639 Expressions => New_List (
7640 Make_Attribute_Reference (Loc,
7641 Prefix => New_Reference_To (Bdef, Loc),
7642 Attribute_Name => Name_Unrestricted_Access),
7643 Make_Attribute_Reference (Loc,
7644 Prefix => New_Reference_To (Edef, Loc),
7645 Attribute_Name => Name_Unrestricted_Access))),
7646 Expressions (Entries_Aggr));
7653 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
7654 -- all protected subprograms have been collected.
7656 if Has_Entries (Prottyp) then
7657 Body_Id := Make_Defining_Identifier (Sloc (Prottyp),
7658 New_External_Name (Chars (Prottyp), 'A'));
7661 or else Restriction_Active (No_Entry_Queue) = False
7663 or else (Has_Attach_Handler (Prottyp)
7664 and then not Restricted_Profile)
7666 Body_Arr := Make_Object_Declaration (Loc,
7667 Defining_Identifier => Body_Id,
7668 Aliased_Present => True,
7669 Object_Definition =>
7670 Make_Subtype_Indication (Loc,
7671 Subtype_Mark => New_Reference_To (
7672 RTE (RE_Protected_Entry_Body_Array), Loc),
7674 Make_Index_Or_Discriminant_Constraint (Loc,
7675 Constraints => New_List (
7677 Make_Integer_Literal (Loc, 1),
7678 Make_Integer_Literal (Loc, E_Count))))),
7679 Expression => Entries_Aggr);
7682 Body_Arr := Make_Object_Declaration (Loc,
7683 Defining_Identifier => Body_Id,
7684 Aliased_Present => True,
7685 Object_Definition => New_Reference_To (RTE (RE_Entry_Body), Loc),
7687 Make_Aggregate (Loc,
7688 Expressions => New_List (
7689 Make_Attribute_Reference (Loc,
7690 Prefix => New_Reference_To (Bdef, Loc),
7691 Attribute_Name => Name_Unrestricted_Access),
7692 Make_Attribute_Reference (Loc,
7693 Prefix => New_Reference_To (Edef, Loc),
7694 Attribute_Name => Name_Unrestricted_Access))));
7697 -- A pointer to this array will be placed in the corresponding record
7698 -- by its initialization procedure so this needs to be analyzed here.
7700 Insert_After (Current_Node, Body_Arr);
7701 Current_Node := Body_Arr;
7704 Set_Entry_Bodies_Array (Prottyp, Body_Id);
7706 -- Finally, build the function that maps an entry index into the
7707 -- corresponding body. A pointer to this function is placed in each
7708 -- object of the type. Except for a ravenscar-like profile (no abort,
7709 -- no entry queue, 1 entry)
7712 or else Restriction_Active (No_Entry_Queue) = False
7714 or else (Has_Attach_Handler (Prottyp)
7715 and then not Restricted_Profile)
7718 Make_Subprogram_Declaration (Loc,
7719 Specification => Build_Find_Body_Index_Spec (Prottyp));
7720 Insert_After (Current_Node, Sub);
7724 end Expand_N_Protected_Type_Declaration;
7726 --------------------------------
7727 -- Expand_N_Requeue_Statement --
7728 --------------------------------
7730 -- A requeue statement is expanded into one of four GNARLI operations,
7731 -- depending on the source and destination (task or protected object). In
7732 -- addition, code must be generated to jump around the remainder of
7733 -- processing for the original entry and, if the destination is (different)
7734 -- protected object, to attempt to service it. The following illustrates
7735 -- the various cases:
7738 -- (O : System.Address;
7739 -- P : System.Address;
7740 -- E : Protected_Entry_Index)
7742 -- <discriminant renamings>
7743 -- <private object renamings>
7744 -- type poVP is access poV;
7745 -- _Object : ptVP := ptVP!(O);
7749 -- <start of statement sequence for entry>
7751 -- -- Requeue from one protected entry body to another protected
7754 -- Requeue_Protected_Entry (
7755 -- _object._object'Access,
7756 -- new._object'Access,
7761 -- <some more of the statement sequence for entry>
7763 -- -- Requeue from an entry body to a task entry
7765 -- Requeue_Protected_To_Task_Entry (
7771 -- <rest of statement sequence for entry>
7772 -- Complete_Entry_Body (_Object._Object);
7775 -- when all others =>
7776 -- Exceptional_Complete_Entry_Body (
7777 -- _Object._Object, Get_GNAT_Exception);
7781 -- Requeue of a task entry call to a task entry
7783 -- Accept_Call (E, Ann);
7784 -- <start of statement sequence for accept statement>
7785 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
7787 -- <rest of statement sequence for accept statement>
7789 -- Complete_Rendezvous;
7792 -- when all others =>
7793 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
7795 -- Requeue of a task entry call to a protected entry
7797 -- Accept_Call (E, Ann);
7798 -- <start of statement sequence for accept statement>
7799 -- Requeue_Task_To_Protected_Entry (
7800 -- new._object'Access,
7805 -- <rest of statement sequence for accept statement>
7807 -- Complete_Rendezvous;
7810 -- when all others =>
7811 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
7813 -- Further details on these expansions can be found in
7814 -- Expand_N_Protected_Body and Expand_N_Accept_Statement.
7816 procedure Expand_N_Requeue_Statement (N : Node_Id) is
7817 Loc : constant Source_Ptr := Sloc (N);
7822 Conctyp : Entity_Id;
7826 Abortable : Node_Id;
7827 Skip_Stat : Node_Id;
7828 Self_Param : Node_Id;
7829 New_Param : Node_Id;
7831 RTS_Call : Entity_Id;
7835 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
7837 -- Set up the target object
7839 Extract_Entry (N, Concval, Ename, Index);
7840 Conctyp := Etype (Concval);
7841 New_Param := Concurrent_Ref (Concval);
7843 -- The target entry index and abortable flag are the same for all cases
7845 Params := New_List (
7846 Entry_Index_Expression (Loc, Entity (Ename), Index, Conctyp),
7849 -- Determine proper GNARLI call and required additional parameters
7850 -- Loop to find nearest enclosing task type or protected type
7852 Oldtyp := Current_Scope;
7854 if Is_Task_Type (Oldtyp) then
7855 if Is_Task_Type (Conctyp) then
7856 RTS_Call := RTE (RE_Requeue_Task_Entry);
7859 pragma Assert (Is_Protected_Type (Conctyp));
7860 RTS_Call := RTE (RE_Requeue_Task_To_Protected_Entry);
7862 Make_Attribute_Reference (Loc,
7863 Prefix => New_Param,
7864 Attribute_Name => Name_Unchecked_Access);
7867 Prepend (New_Param, Params);
7870 elsif Is_Protected_Type (Oldtyp) then
7872 Make_Attribute_Reference (Loc,
7873 Prefix => Concurrent_Ref (New_Occurrence_Of (Oldtyp, Loc)),
7874 Attribute_Name => Name_Unchecked_Access);
7876 if Is_Task_Type (Conctyp) then
7877 RTS_Call := RTE (RE_Requeue_Protected_To_Task_Entry);
7880 pragma Assert (Is_Protected_Type (Conctyp));
7881 RTS_Call := RTE (RE_Requeue_Protected_Entry);
7883 Make_Attribute_Reference (Loc,
7884 Prefix => New_Param,
7885 Attribute_Name => Name_Unchecked_Access);
7888 Prepend (New_Param, Params);
7889 Prepend (Self_Param, Params);
7892 -- If neither task type or protected type, must be in some inner
7893 -- enclosing block, so move on out
7896 Oldtyp := Scope (Oldtyp);
7900 -- Create the GNARLI call
7902 Rcall := Make_Procedure_Call_Statement (Loc,
7904 New_Occurrence_Of (RTS_Call, Loc),
7905 Parameter_Associations => Params);
7910 if Is_Protected_Type (Oldtyp) then
7912 -- Build the return statement to skip the rest of the entry body
7914 Skip_Stat := Make_Return_Statement (Loc);
7917 -- If the requeue is within a task, find the end label of the
7918 -- enclosing accept statement.
7920 Acc_Stat := Parent (N);
7921 while Nkind (Acc_Stat) /= N_Accept_Statement loop
7922 Acc_Stat := Parent (Acc_Stat);
7925 -- The last statement is the second label, used for completing the
7926 -- rendezvous the usual way. The label we are looking for is right
7930 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
7932 pragma Assert (Nkind (Lab_Node) = N_Label);
7934 -- Build the goto statement to skip the rest of the accept
7938 Make_Goto_Statement (Loc,
7939 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
7942 Set_Analyzed (Skip_Stat);
7944 Insert_After (N, Skip_Stat);
7945 end Expand_N_Requeue_Statement;
7947 -------------------------------
7948 -- Expand_N_Selective_Accept --
7949 -------------------------------
7951 procedure Expand_N_Selective_Accept (N : Node_Id) is
7952 Loc : constant Source_Ptr := Sloc (N);
7953 Alts : constant List_Id := Select_Alternatives (N);
7955 -- Note: in the below declarations a lot of new lists are allocated
7956 -- unconditionally which may well not end up being used. That's
7957 -- not a good idea since it wastes space gratuitously ???
7959 Accept_Case : List_Id;
7960 Accept_List : constant List_Id := New_List;
7963 Alt_List : constant List_Id := New_List;
7964 Alt_Stats : List_Id;
7965 Ann : Entity_Id := Empty;
7968 Check_Guard : Boolean := True;
7970 Decls : constant List_Id := New_List;
7971 Stats : constant List_Id := New_List;
7972 Body_List : constant List_Id := New_List;
7973 Trailing_List : constant List_Id := New_List;
7976 Else_Present : Boolean := False;
7977 Terminate_Alt : Node_Id := Empty;
7978 Select_Mode : Node_Id;
7980 Delay_Case : List_Id;
7981 Delay_Count : Integer := 0;
7982 Delay_Val : Entity_Id;
7983 Delay_Index : Entity_Id;
7984 Delay_Min : Entity_Id;
7985 Delay_Num : Int := 1;
7986 Delay_Alt_List : List_Id := New_List;
7987 Delay_List : constant List_Id := New_List;
7991 First_Delay : Boolean := True;
7992 Guard_Open : Entity_Id;
7998 Num_Accept : Nat := 0;
8001 Time_Type : Entity_Id;
8003 Select_Call : Node_Id;
8005 Qnam : constant Entity_Id :=
8006 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
8008 Xnam : constant Entity_Id :=
8009 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
8011 -----------------------
8012 -- Local subprograms --
8013 -----------------------
8015 function Accept_Or_Raise return List_Id;
8016 -- For the rare case where delay alternatives all have guards, and
8017 -- all of them are closed, it is still possible that there were open
8018 -- accept alternatives with no callers. We must reexamine the
8019 -- Accept_List, and execute a selective wait with no else if some
8020 -- accept is open. If none, we raise program_error.
8022 procedure Add_Accept (Alt : Node_Id);
8023 -- Process a single accept statement in a select alternative. Build
8024 -- procedure for body of accept, and add entry to dispatch table with
8025 -- expression for guard, in preparation for call to run time select.
8027 function Make_And_Declare_Label (Num : Int) return Node_Id;
8028 -- Manufacture a label using Num as a serial number and declare it.
8029 -- The declaration is appended to Decls. The label marks the trailing
8030 -- statements of an accept or delay alternative.
8032 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
8033 -- Build call to Selective_Wait runtime routine
8035 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
8036 -- Add code to compare value of delay with previous values, and
8037 -- generate case entry for trailing statements.
8039 procedure Process_Accept_Alternative
8043 -- Add code to call corresponding procedure, and branch to
8044 -- trailing statements, if any.
8046 ---------------------
8047 -- Accept_Or_Raise --
8048 ---------------------
8050 function Accept_Or_Raise return List_Id is
8053 J : constant Entity_Id := Make_Defining_Identifier (Loc,
8054 New_Internal_Name ('J'));
8057 -- We generate the following:
8059 -- for J in q'range loop
8060 -- if q(J).S /=null_task_entry then
8061 -- selective_wait (simple_mode,...);
8067 -- if no rendez_vous then
8068 -- raise program_error;
8071 -- Note that the code needs to know that the selector name
8072 -- in an Accept_Alternative is named S.
8074 Cond := Make_Op_Ne (Loc,
8076 Make_Selected_Component (Loc,
8077 Prefix => Make_Indexed_Component (Loc,
8078 Prefix => New_Reference_To (Qnam, Loc),
8079 Expressions => New_List (New_Reference_To (J, Loc))),
8080 Selector_Name => Make_Identifier (Loc, Name_S)),
8082 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
8085 Make_Implicit_Loop_Statement (N,
8086 Identifier => Empty,
8088 Make_Iteration_Scheme (Loc,
8089 Loop_Parameter_Specification =>
8090 Make_Loop_Parameter_Specification (Loc,
8091 Defining_Identifier => J,
8092 Discrete_Subtype_Definition =>
8093 Make_Attribute_Reference (Loc,
8094 Prefix => New_Reference_To (Qnam, Loc),
8095 Attribute_Name => Name_Range,
8096 Expressions => New_List (
8097 Make_Integer_Literal (Loc, 1))))),
8099 Statements => New_List (
8100 Make_Implicit_If_Statement (N,
8102 Then_Statements => New_List (
8104 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
8105 Make_Exit_Statement (Loc))))));
8108 Make_Raise_Program_Error (Loc,
8109 Condition => Make_Op_Eq (Loc,
8110 Left_Opnd => New_Reference_To (Xnam, Loc),
8112 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8113 Reason => PE_All_Guards_Closed));
8116 end Accept_Or_Raise;
8122 procedure Add_Accept (Alt : Node_Id) is
8123 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
8124 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
8125 Eent : constant Entity_Id := Entity (Ename);
8126 Index : constant Node_Id := Entry_Index (Acc_Stm);
8127 Null_Body : Node_Id;
8128 Proc_Body : Node_Id;
8135 Ann := Node (Last_Elmt (Accept_Address (Eent)));
8138 if Present (Condition (Alt)) then
8140 Make_Conditional_Expression (Loc, New_List (
8142 Entry_Index_Expression (Loc, Eent, Index, Scope (Eent)),
8143 New_Reference_To (RTE (RE_Null_Task_Entry), Loc)));
8146 Entry_Index_Expression
8147 (Loc, Eent, Index, Scope (Eent));
8150 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8151 Null_Body := New_Reference_To (Standard_False, Loc);
8153 if Abort_Allowed then
8154 Call := Make_Procedure_Call_Statement (Loc,
8155 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc));
8156 Insert_Before (First (Statements (Handled_Statement_Sequence (
8157 Accept_Statement (Alt)))), Call);
8162 Make_Defining_Identifier (Sloc (Ename),
8163 New_External_Name (Chars (Ename), 'A', Num_Accept));
8165 Set_Needs_Debug_Info (PB_Ent, Comes_From_Source (Alt));
8168 Make_Subprogram_Body (Loc,
8170 Make_Procedure_Specification (Loc,
8171 Defining_Unit_Name => PB_Ent),
8172 Declarations => Declarations (Acc_Stm),
8173 Handled_Statement_Sequence =>
8174 Build_Accept_Body (Accept_Statement (Alt)));
8176 -- During the analysis of the body of the accept statement, any
8177 -- zero cost exception handler records were collected in the
8178 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8179 -- This is where we move them to where they belong, namely the
8180 -- newly created procedure.
8182 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8183 Append (Proc_Body, Body_List);
8186 Null_Body := New_Reference_To (Standard_True, Loc);
8188 -- if accept statement has declarations, insert above, given that
8189 -- we are not creating a body for the accept.
8191 if Present (Declarations (Acc_Stm)) then
8192 Insert_Actions (N, Declarations (Acc_Stm));
8196 Append_To (Accept_List,
8197 Make_Aggregate (Loc, Expressions => New_List (Null_Body, Expr)));
8199 Num_Accept := Num_Accept + 1;
8202 ----------------------------
8203 -- Make_And_Declare_Label --
8204 ----------------------------
8206 function Make_And_Declare_Label (Num : Int) return Node_Id is
8210 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8212 Make_Label (Loc, Lab_Id);
8215 Make_Implicit_Label_Declaration (Loc,
8216 Defining_Identifier =>
8217 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8218 Label_Construct => Lab));
8221 end Make_And_Declare_Label;
8223 ----------------------
8224 -- Make_Select_Call --
8225 ----------------------
8227 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8228 Params : constant List_Id := New_List;
8232 Make_Attribute_Reference (Loc,
8233 Prefix => New_Reference_To (Qnam, Loc),
8234 Attribute_Name => Name_Unchecked_Access),
8236 Append (Select_Mode, Params);
8237 Append (New_Reference_To (Ann, Loc), Params);
8238 Append (New_Reference_To (Xnam, Loc), Params);
8241 Make_Procedure_Call_Statement (Loc,
8242 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8243 Parameter_Associations => Params);
8244 end Make_Select_Call;
8246 --------------------------------
8247 -- Process_Accept_Alternative --
8248 --------------------------------
8250 procedure Process_Accept_Alternative
8255 Choices : List_Id := No_List;
8256 Alt_Stats : List_Id;
8259 Adjust_Condition (Condition (Alt));
8260 Alt_Stats := No_List;
8262 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8263 Choices := New_List (
8264 Make_Integer_Literal (Loc, Index));
8266 Alt_Stats := New_List (
8267 Make_Procedure_Call_Statement (Loc,
8268 Name => New_Reference_To (
8269 Defining_Unit_Name (Specification (Proc)), Loc)));
8272 if Statements (Alt) /= Empty_List then
8274 if No (Alt_Stats) then
8276 -- Accept with no body, followed by trailing statements
8278 Choices := New_List (
8279 Make_Integer_Literal (Loc, Index));
8281 Alt_Stats := New_List;
8284 -- After the call, if any, branch to to trailing statements. We
8285 -- create a label for each, as well as the corresponding label
8288 Lab := Make_And_Declare_Label (Index);
8289 Append_To (Alt_Stats,
8290 Make_Goto_Statement (Loc,
8291 Name => New_Copy (Identifier (Lab))));
8293 Append (Lab, Trailing_List);
8294 Append_List (Statements (Alt), Trailing_List);
8295 Append_To (Trailing_List,
8296 Make_Goto_Statement (Loc,
8297 Name => New_Copy (Identifier (End_Lab))));
8300 if Present (Alt_Stats) then
8302 -- Procedure call. and/or trailing statements
8304 Append_To (Alt_List,
8305 Make_Case_Statement_Alternative (Loc,
8306 Discrete_Choices => Choices,
8307 Statements => Alt_Stats));
8309 end Process_Accept_Alternative;
8311 -------------------------------
8312 -- Process_Delay_Alternative --
8313 -------------------------------
8315 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
8318 Delay_Alt : List_Id;
8321 -- Deal with C/Fortran boolean as delay condition
8323 Adjust_Condition (Condition (Alt));
8325 -- Determine the smallest specified delay
8327 -- for each delay alternative generate:
8329 -- if guard-expression then
8330 -- Delay_Val := delay-expression;
8331 -- Guard_Open := True;
8332 -- if Delay_Val < Delay_Min then
8333 -- Delay_Min := Delay_Val;
8334 -- Delay_Index := Index;
8338 -- The enclosing if-statement is omitted if there is no guard
8343 First_Delay := False;
8345 Delay_Alt := New_List (
8346 Make_Assignment_Statement (Loc,
8347 Name => New_Reference_To (Delay_Min, Loc),
8348 Expression => Expression (Delay_Statement (Alt))));
8350 if Delay_Count > 1 then
8351 Append_To (Delay_Alt,
8352 Make_Assignment_Statement (Loc,
8353 Name => New_Reference_To (Delay_Index, Loc),
8354 Expression => Make_Integer_Literal (Loc, Index)));
8358 Delay_Alt := New_List (
8359 Make_Assignment_Statement (Loc,
8360 Name => New_Reference_To (Delay_Val, Loc),
8361 Expression => Expression (Delay_Statement (Alt))));
8363 if Time_Type = Standard_Duration then
8366 Left_Opnd => New_Reference_To (Delay_Val, Loc),
8367 Right_Opnd => New_Reference_To (Delay_Min, Loc));
8370 -- The scope of the time type must define a comparison
8371 -- operator. The scope itself may not be visible, so we
8372 -- construct a node with entity information to insure that
8373 -- semantic analysis can find the proper operator.
8376 Make_Function_Call (Loc,
8377 Name => Make_Selected_Component (Loc,
8378 Prefix => New_Reference_To (Scope (Time_Type), Loc),
8380 Make_Operator_Symbol (Loc,
8381 Chars => Name_Op_Lt,
8382 Strval => No_String)),
8383 Parameter_Associations =>
8385 New_Reference_To (Delay_Val, Loc),
8386 New_Reference_To (Delay_Min, Loc)));
8388 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
8391 Append_To (Delay_Alt,
8392 Make_Implicit_If_Statement (N,
8394 Then_Statements => New_List (
8395 Make_Assignment_Statement (Loc,
8396 Name => New_Reference_To (Delay_Min, Loc),
8397 Expression => New_Reference_To (Delay_Val, Loc)),
8399 Make_Assignment_Statement (Loc,
8400 Name => New_Reference_To (Delay_Index, Loc),
8401 Expression => Make_Integer_Literal (Loc, Index)))));
8405 Append_To (Delay_Alt,
8406 Make_Assignment_Statement (Loc,
8407 Name => New_Reference_To (Guard_Open, Loc),
8408 Expression => New_Reference_To (Standard_True, Loc)));
8411 if Present (Condition (Alt)) then
8412 Delay_Alt := New_List (
8413 Make_Implicit_If_Statement (N,
8414 Condition => Condition (Alt),
8415 Then_Statements => Delay_Alt));
8418 Append_List (Delay_Alt, Delay_List);
8420 -- If the delay alternative has a statement part, add choice to the
8421 -- case statements for delays.
8423 if Present (Statements (Alt)) then
8425 if Delay_Count = 1 then
8426 Append_List (Statements (Alt), Delay_Alt_List);
8429 Choices := New_List (
8430 Make_Integer_Literal (Loc, Index));
8432 Append_To (Delay_Alt_List,
8433 Make_Case_Statement_Alternative (Loc,
8434 Discrete_Choices => Choices,
8435 Statements => Statements (Alt)));
8438 elsif Delay_Count = 1 then
8440 -- If the single delay has no trailing statements, add a branch
8441 -- to the exit label to the selective wait.
8443 Delay_Alt_List := New_List (
8444 Make_Goto_Statement (Loc,
8445 Name => New_Copy (Identifier (End_Lab))));
8448 end Process_Delay_Alternative;
8450 -- Start of processing for Expand_N_Selective_Accept
8453 -- First insert some declarations before the select. The first is:
8457 -- This variable holds the parameters passed to the accept body. This
8458 -- declaration has already been inserted by the time we get here by
8459 -- a call to Expand_Accept_Declarations made from the semantics when
8460 -- processing the first accept statement contained in the select. We
8461 -- can find this entity as Accept_Address (E), where E is any of the
8462 -- entries references by contained accept statements.
8464 -- The first step is to scan the list of Selective_Accept_Statements
8465 -- to find this entity, and also count the number of accepts, and
8466 -- determine if terminated, delay or else is present:
8470 Alt := First (Alts);
8471 while Present (Alt) loop
8473 if Nkind (Alt) = N_Accept_Alternative then
8476 elsif Nkind (Alt) = N_Delay_Alternative then
8477 Delay_Count := Delay_Count + 1;
8479 -- If the delays are relative delays, the delay expressions have
8480 -- type Standard_Duration. Otherwise they must have some time type
8481 -- recognized by GNAT.
8483 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
8484 Time_Type := Standard_Duration;
8486 Time_Type := Etype (Expression (Delay_Statement (Alt)));
8488 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
8489 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
8494 "& is not a time type ('R'M 9.6(6))",
8495 Expression (Delay_Statement (Alt)), Time_Type);
8496 Time_Type := Standard_Duration;
8497 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
8501 if No (Condition (Alt)) then
8503 -- This guard will always be open
8505 Check_Guard := False;
8508 elsif Nkind (Alt) = N_Terminate_Alternative then
8509 Adjust_Condition (Condition (Alt));
8510 Terminate_Alt := Alt;
8513 Num_Alts := Num_Alts + 1;
8517 Else_Present := Present (Else_Statements (N));
8519 -- At the same time (see procedure Add_Accept) we build the accept list:
8521 -- Qnn : Accept_List (1 .. num-select) := (
8522 -- (null-body, entry-index),
8523 -- (null-body, entry-index),
8525 -- (null_body, entry-index));
8527 -- In the above declaration, null-body is True if the corresponding
8528 -- accept has no body, and false otherwise. The entry is either the
8529 -- entry index expression if there is no guard, or if a guard is
8530 -- present, then a conditional expression of the form:
8532 -- (if guard then entry-index else Null_Task_Entry)
8534 -- If a guard is statically known to be false, the entry can simply
8535 -- be omitted from the accept list.
8538 Make_Object_Declaration (Loc,
8539 Defining_Identifier => Qnam,
8540 Object_Definition =>
8541 New_Reference_To (RTE (RE_Accept_List), Loc),
8542 Aliased_Present => True,
8545 Make_Qualified_Expression (Loc,
8547 New_Reference_To (RTE (RE_Accept_List), Loc),
8549 Make_Aggregate (Loc, Expressions => Accept_List)));
8553 -- Then we declare the variable that holds the index for the accept
8554 -- that will be selected for service:
8556 -- Xnn : Select_Index;
8559 Make_Object_Declaration (Loc,
8560 Defining_Identifier => Xnam,
8561 Object_Definition =>
8562 New_Reference_To (RTE (RE_Select_Index), Loc),
8564 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
8568 -- After this follow procedure declarations for each accept body
8575 -- where the ... are statements from the corresponding procedure body.
8576 -- No parameters are involved, since the parameters are passed via Ann
8577 -- and the parameter references have already been expanded to be direct
8578 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
8579 -- any embedded tasking statements (which would normally be illegal in
8580 -- procedures), have been converted to calls to the tasking runtime so
8581 -- there is no problem in putting them into procedures.
8583 -- The original accept statement has been expanded into a block in
8584 -- the same fashion as for simple accepts (see Build_Accept_Body).
8586 -- Note: we don't really need to build these procedures for the case
8587 -- where no delay statement is present, but it is just as easy to
8588 -- build them unconditionally, and not significantly inefficient,
8589 -- since if they are short they will be inlined anyway.
8591 -- The procedure declarations have been assembled in Body_List
8593 -- If delays are present, we must compute the required delay.
8594 -- We first generate the declarations:
8596 -- Delay_Index : Boolean := 0;
8597 -- Delay_Min : Some_Time_Type.Time;
8598 -- Delay_Val : Some_Time_Type.Time;
8600 -- Delay_Index will be set to the index of the minimum delay, i.e. the
8601 -- active delay that is actually chosen as the basis for the possible
8602 -- delay if an immediate rendez-vous is not possible.
8604 -- In the most common case there is a single delay statement, and this
8605 -- is handled specially.
8607 if Delay_Count > 0 then
8609 -- Generate the required declarations
8612 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
8614 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
8616 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
8619 Make_Object_Declaration (Loc,
8620 Defining_Identifier => Delay_Val,
8621 Object_Definition => New_Reference_To (Time_Type, Loc)));
8624 Make_Object_Declaration (Loc,
8625 Defining_Identifier => Delay_Index,
8626 Object_Definition => New_Reference_To (Standard_Integer, Loc),
8627 Expression => Make_Integer_Literal (Loc, 0)));
8630 Make_Object_Declaration (Loc,
8631 Defining_Identifier => Delay_Min,
8632 Object_Definition => New_Reference_To (Time_Type, Loc),
8634 Unchecked_Convert_To (Time_Type,
8635 Make_Attribute_Reference (Loc,
8637 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
8638 Attribute_Name => Name_Last))));
8640 -- Create Duration and Delay_Mode objects used for passing a delay
8643 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
8644 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
8650 -- Note that these values are defined in s-osprim.ads and must
8653 -- Relative : constant := 0;
8654 -- Absolute_Calendar : constant := 1;
8655 -- Absolute_RT : constant := 2;
8657 if Time_Type = Standard_Duration then
8658 Discr := Make_Integer_Literal (Loc, 0);
8660 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
8661 Discr := Make_Integer_Literal (Loc, 1);
8665 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
8666 Discr := Make_Integer_Literal (Loc, 2);
8670 Make_Object_Declaration (Loc,
8671 Defining_Identifier => D,
8672 Object_Definition =>
8673 New_Reference_To (Standard_Duration, Loc)));
8676 Make_Object_Declaration (Loc,
8677 Defining_Identifier => M,
8678 Object_Definition =>
8679 New_Reference_To (Standard_Integer, Loc),
8680 Expression => Discr));
8685 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
8688 Make_Object_Declaration (Loc,
8689 Defining_Identifier => Guard_Open,
8690 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
8691 Expression => New_Reference_To (Standard_False, Loc)));
8694 -- Delay_Count is zero, don't need M and D set (suppress warning)
8701 if Present (Terminate_Alt) then
8703 -- If the terminate alternative guard is False, use
8704 -- Simple_Mode; otherwise use Terminate_Mode.
8706 if Present (Condition (Terminate_Alt)) then
8707 Select_Mode := Make_Conditional_Expression (Loc,
8708 New_List (Condition (Terminate_Alt),
8709 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
8710 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
8712 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
8715 elsif Else_Present or Delay_Count > 0 then
8716 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
8719 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
8722 Select_Call := Make_Select_Call (Select_Mode);
8723 Append (Select_Call, Stats);
8725 -- Now generate code to act on the result. There is an entry
8726 -- in this case for each accept statement with a non-null body,
8727 -- followed by a branch to the statements that follow the Accept.
8728 -- In the absence of delay alternatives, we generate:
8731 -- when No_Rendezvous => -- omitted if simple mode
8746 -- Lab0: Else_Statements;
8749 -- Lab1: Trailing_Statements1;
8752 -- Lab2: Trailing_Statements2;
8757 -- Generate label for common exit
8759 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
8761 -- First entry is the default case, when no rendezvous is possible
8763 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
8765 if Else_Present then
8767 -- If no rendezvous is possible, the else part is executed
8769 Lab := Make_And_Declare_Label (0);
8770 Alt_Stats := New_List (
8771 Make_Goto_Statement (Loc,
8772 Name => New_Copy (Identifier (Lab))));
8774 Append (Lab, Trailing_List);
8775 Append_List (Else_Statements (N), Trailing_List);
8776 Append_To (Trailing_List,
8777 Make_Goto_Statement (Loc,
8778 Name => New_Copy (Identifier (End_Lab))));
8780 Alt_Stats := New_List (
8781 Make_Goto_Statement (Loc,
8782 Name => New_Copy (Identifier (End_Lab))));
8785 Append_To (Alt_List,
8786 Make_Case_Statement_Alternative (Loc,
8787 Discrete_Choices => Choices,
8788 Statements => Alt_Stats));
8790 -- We make use of the fact that Accept_Index is an integer type, and
8791 -- generate successive literals for entries for each accept. Only those
8792 -- for which there is a body or trailing statements get a case entry.
8794 Alt := First (Select_Alternatives (N));
8795 Proc := First (Body_List);
8796 while Present (Alt) loop
8798 if Nkind (Alt) = N_Accept_Alternative then
8799 Process_Accept_Alternative (Alt, Index, Proc);
8803 (Handled_Statement_Sequence (Accept_Statement (Alt)))
8808 elsif Nkind (Alt) = N_Delay_Alternative then
8809 Process_Delay_Alternative (Alt, Delay_Num);
8810 Delay_Num := Delay_Num + 1;
8816 -- An others choice is always added to the main case, as well
8817 -- as the delay case (to satisfy the compiler).
8819 Append_To (Alt_List,
8820 Make_Case_Statement_Alternative (Loc,
8822 New_List (Make_Others_Choice (Loc)),
8824 New_List (Make_Goto_Statement (Loc,
8825 Name => New_Copy (Identifier (End_Lab))))));
8827 Accept_Case := New_List (
8828 Make_Case_Statement (Loc,
8829 Expression => New_Reference_To (Xnam, Loc),
8830 Alternatives => Alt_List));
8832 Append_List (Trailing_List, Accept_Case);
8833 Append (End_Lab, Accept_Case);
8834 Append_List (Body_List, Decls);
8836 -- Construct case statement for trailing statements of delay
8837 -- alternatives, if there are several of them.
8839 if Delay_Count > 1 then
8840 Append_To (Delay_Alt_List,
8841 Make_Case_Statement_Alternative (Loc,
8843 New_List (Make_Others_Choice (Loc)),
8845 New_List (Make_Null_Statement (Loc))));
8847 Delay_Case := New_List (
8848 Make_Case_Statement (Loc,
8849 Expression => New_Reference_To (Delay_Index, Loc),
8850 Alternatives => Delay_Alt_List));
8852 Delay_Case := Delay_Alt_List;
8855 -- If there are no delay alternatives, we append the case statement
8856 -- to the statement list.
8858 if Delay_Count = 0 then
8859 Append_List (Accept_Case, Stats);
8861 -- Delay alternatives present
8864 -- If delay alternatives are present we generate:
8866 -- find minimum delay.
8867 -- DX := minimum delay;
8868 -- M := <delay mode>;
8869 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
8872 -- if X = No_Rendezvous then
8873 -- case statement for delay statements.
8875 -- case statement for accept alternatives.
8886 -- The type of the delay expression is known to be legal
8888 if Time_Type = Standard_Duration then
8889 Conv := New_Reference_To (Delay_Min, Loc);
8891 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
8892 Conv := Make_Function_Call (Loc,
8893 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
8894 New_List (New_Reference_To (Delay_Min, Loc)));
8898 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
8900 Conv := Make_Function_Call (Loc,
8901 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
8902 New_List (New_Reference_To (Delay_Min, Loc)));
8905 Stmt := Make_Assignment_Statement (Loc,
8906 Name => New_Reference_To (D, Loc),
8907 Expression => Conv);
8909 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
8911 Parms := Parameter_Associations (Select_Call);
8912 Parm := First (Parms);
8914 while Present (Parm)
8915 and then Parm /= Select_Mode
8920 pragma Assert (Present (Parm));
8921 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
8924 -- Prepare two new parameters of Duration and Delay_Mode type
8925 -- which represent the value and the mode of the minimum delay.
8928 Insert_After (Parm, New_Reference_To (M, Loc));
8929 Insert_After (Parm, New_Reference_To (D, Loc));
8931 -- Create a call to RTS
8933 Rewrite (Select_Call,
8934 Make_Procedure_Call_Statement (Loc,
8935 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
8936 Parameter_Associations => Parms));
8938 -- This new call should follow the calculation of the minimum
8941 Insert_List_Before (Select_Call, Delay_List);
8945 Make_Implicit_If_Statement (N,
8946 Condition => New_Reference_To (Guard_Open, Loc),
8948 New_List (New_Copy_Tree (Stmt),
8949 New_Copy_Tree (Select_Call)),
8950 Else_Statements => Accept_Or_Raise);
8951 Rewrite (Select_Call, Stmt);
8953 Insert_Before (Select_Call, Stmt);
8957 Make_Implicit_If_Statement (N,
8958 Condition => Make_Op_Eq (Loc,
8959 Left_Opnd => New_Reference_To (Xnam, Loc),
8961 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8963 Then_Statements => Delay_Case,
8964 Else_Statements => Accept_Case);
8966 Append (Cases, Stats);
8970 -- Replace accept statement with appropriate block
8973 Make_Block_Statement (Loc,
8974 Declarations => Decls,
8975 Handled_Statement_Sequence =>
8976 Make_Handled_Sequence_Of_Statements (Loc,
8977 Statements => Stats));
8982 -- Note: have to worry more about abort deferral in above code ???
8984 -- Final step is to unstack the Accept_Address entries for all accept
8985 -- statements appearing in accept alternatives in the select statement
8987 Alt := First (Alts);
8988 while Present (Alt) loop
8989 if Nkind (Alt) = N_Accept_Alternative then
8990 Remove_Last_Elmt (Accept_Address
8991 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
8996 end Expand_N_Selective_Accept;
8998 --------------------------------------
8999 -- Expand_N_Single_Task_Declaration --
9000 --------------------------------------
9002 -- Single task declarations should never be present after semantic
9003 -- analysis, since we expect them to be replaced by a declaration of an
9004 -- anonymous task type, followed by a declaration of the task object. We
9005 -- include this routine to make sure that is happening!
9007 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
9009 raise Program_Error;
9010 end Expand_N_Single_Task_Declaration;
9012 ------------------------
9013 -- Expand_N_Task_Body --
9014 ------------------------
9016 -- Given a task body
9018 -- task body tname is
9024 -- This expansion routine converts it into a procedure and sets the
9025 -- elaboration flag for the procedure to true, to represent the fact
9026 -- that the task body is now elaborated:
9028 -- procedure tnameB (_Task : access tnameV) is
9029 -- discriminal : dtype renames _Task.discriminant;
9031 -- procedure _clean is
9035 -- Abort_Undefer.all;
9040 -- Abort_Undefer.all;
9042 -- System.Task_Stages.Complete_Activation;
9050 -- In addition, if the task body is an activator, then a call to activate
9051 -- tasks is added at the start of the statements, before the call to
9052 -- Complete_Activation, and if in addition the task is a master then it
9053 -- must be established as a master. These calls are inserted and analyzed
9054 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9057 -- There is one discriminal declaration line generated for each
9058 -- discriminant that is present to provide an easy reference point for
9059 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9061 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9062 -- task body procedures have a profile (Arg : System.Address). That is
9063 -- needed because GNARLI has to use the same access-to-subprogram type
9064 -- for all task types. We depend here on knowing that in GNAT, passing
9065 -- an address argument by value is identical to passing a record value
9066 -- by access (in either case a single pointer is passed), so even though
9067 -- this procedure has the wrong profile. In fact it's all OK, since the
9068 -- callings sequence is identical.
9070 procedure Expand_N_Task_Body (N : Node_Id) is
9071 Loc : constant Source_Ptr := Sloc (N);
9072 Ttyp : constant Entity_Id := Corresponding_Spec (N);
9077 -- Here we start the expansion by generating discriminal declarations
9079 Add_Discriminal_Declarations (Declarations (N), Ttyp, Name_uTask, Loc);
9081 -- Add a call to Abort_Undefer at the very beginning of the task
9082 -- body since this body is called with abort still deferred.
9084 if Abort_Allowed then
9085 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
9087 (First (Statements (Handled_Statement_Sequence (N))), Call);
9091 -- The statement part has already been protected with an at_end and
9092 -- cleanup actions. The call to Complete_Activation must be placed
9093 -- at the head of the sequence of statements of that block. The
9094 -- declarations have been merged in this sequence of statements but
9095 -- the first real statement is accessible from the First_Real_Statement
9096 -- field (which was set for exactly this purpose).
9098 if Restricted_Profile then
9099 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
9101 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
9105 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
9109 Make_Subprogram_Body (Loc,
9110 Specification => Build_Task_Proc_Specification (Ttyp),
9111 Declarations => Declarations (N),
9112 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
9114 -- If the task contains generic instantiations, cleanup actions
9115 -- are delayed until after instantiation. Transfer the activation
9116 -- chain to the subprogram, to insure that the activation call is
9117 -- properly generated. It the task body contains inner tasks, indicate
9118 -- that the subprogram is a task master.
9120 if Delay_Cleanups (Ttyp) then
9121 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
9122 Set_Is_Task_Master (New_N, Is_Task_Master (N));
9128 -- Set elaboration flag immediately after task body. If the body is a
9129 -- subunit, the flag is set in the declarative part containing the stub.
9131 if Nkind (Parent (N)) /= N_Subunit then
9133 Make_Assignment_Statement (Loc,
9135 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
9136 Expression => New_Reference_To (Standard_True, Loc)));
9139 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9140 -- the task body. At this point the entry specs have been created,
9141 -- frozen and included in the dispatch table for the task type.
9143 pragma Assert (Present (Corresponding_Record_Type (Ttyp)));
9145 if Ada_Version >= Ada_05
9146 and then Present (Task_Definition (Parent (Ttyp)))
9147 and then Present (Abstract_Interfaces
9148 (Corresponding_Record_Type (Ttyp)))
9151 Current_Node : Node_Id;
9152 Vis_Decl : Node_Id :=
9153 First (Visible_Declarations (Task_Definition (Parent (Ttyp))));
9154 Wrap_Body : Node_Id;
9157 if Nkind (Parent (N)) = N_Subunit then
9158 Current_Node := Corresponding_Stub (Parent (N));
9163 -- Examine the visible declarations of the task type, looking for
9164 -- an entry declaration. We do not consider entry families since
9165 -- they cannot have dispatching operations, thus they do not need
9168 while Present (Vis_Decl) loop
9169 if Nkind (Vis_Decl) = N_Entry_Declaration
9170 and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry
9173 -- Create the specification of the wrapper
9176 Build_Wrapper_Body (Loc,
9177 Proc_Nam => Defining_Identifier (Vis_Decl),
9178 Obj_Typ => Corresponding_Record_Type (Ttyp),
9179 Formals => Parameter_Specifications (Vis_Decl));
9181 if Wrap_Body /= Empty then
9182 Insert_After (Current_Node, Wrap_Body);
9183 Current_Node := Wrap_Body;
9185 Analyze (Wrap_Body);
9193 end Expand_N_Task_Body;
9195 ------------------------------------
9196 -- Expand_N_Task_Type_Declaration --
9197 ------------------------------------
9199 -- We have several things to do. First we must create a Boolean flag used
9200 -- to mark if the body is elaborated yet. This variable gets set to True
9201 -- when the body of the task is elaborated (we can't rely on the normal
9202 -- ABE mechanism for the task body, since we need to pass an access to
9203 -- this elaboration boolean to the runtime routines).
9205 -- taskE : aliased Boolean := False;
9207 -- Next a variable is declared to hold the task stack size (either the
9208 -- default : Unspecified_Size, or a value that is set by a pragma
9209 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9210 -- the variable is initialized with this value:
9212 -- taskZ : Size_Type := Unspecified_Size;
9214 -- taskZ : Size_Type := Size_Type (size_expression);
9216 -- Next we create a corresponding record type declaration used to represent
9217 -- values of this task. The general form of this type declaration is
9219 -- type taskV (discriminants) is record
9220 -- _Task_Id : Task_Id;
9221 -- entry_family : array (bounds) of Void;
9222 -- _Priority : Integer := priority_expression;
9223 -- _Size : Size_Type := Size_Type (size_expression);
9224 -- _Task_Info : Task_Info_Type := task_info_expression;
9227 -- The discriminants are present only if the corresponding task type has
9228 -- discriminants, and they exactly mirror the task type discriminants.
9230 -- The Id field is always present. It contains the Task_Id value, as set by
9231 -- the call to Create_Task. Note that although the task is limited, the
9232 -- task value record type is not limited, so there is no problem in passing
9233 -- this field as an out parameter to Create_Task.
9235 -- One entry_family component is present for each entry family in the task
9236 -- definition. The bounds correspond to the bounds of the entry family
9237 -- (which may depend on discriminants). The element type is void, since we
9238 -- only need the bounds information for determining the entry index. Note
9239 -- that the use of an anonymous array would normally be illegal in this
9240 -- context, but this is a parser check, and the semantics is quite prepared
9241 -- to handle such a case.
9243 -- The _Size field is present only if a Storage_Size pragma appears in the
9244 -- task definition. The expression captures the argument that was present
9245 -- in the pragma, and is used to override the task stack size otherwise
9246 -- associated with the task type.
9248 -- The _Priority field is present only if a Priority or Interrupt_Priority
9249 -- pragma appears in the task definition. The expression captures the
9250 -- argument that was present in the pragma, and is used to provide the Size
9251 -- parameter to the call to Create_Task.
9253 -- The _Task_Info field is present only if a Task_Info pragma appears in
9254 -- the task definition. The expression captures the argument that was
9255 -- present in the pragma, and is used to provide the Task_Image parameter
9256 -- to the call to Create_Task.
9258 -- When a task is declared, an instance of the task value record is
9259 -- created. The elaboration of this declaration creates the correct bounds
9260 -- for the entry families, and also evaluates the size, priority, and
9261 -- task_Info expressions if needed. The initialization routine for the task
9262 -- type itself then calls Create_Task with appropriate parameters to
9263 -- initialize the value of the Task_Id field.
9265 -- Note: the address of this record is passed as the "Discriminants"
9266 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9267 -- body procedure, it does not matter that it does not quite match the
9268 -- GNARLI model of what is being passed (the record contains more than just
9269 -- the discriminants, but the discriminants can be found from the record
9272 -- The Entity_Id for this created record type is placed in the
9273 -- Corresponding_Record_Type field of the associated task type entity.
9275 -- Next we create a procedure specification for the task body procedure:
9277 -- procedure taskB (_Task : access taskV);
9279 -- Note that this must come after the record type declaration, since
9280 -- the spec refers to this type. It turns out that the initialization
9281 -- procedure for the value type references the task body spec, but that's
9282 -- fine, since it won't be generated till the freeze point for the type,
9283 -- which is certainly after the task body spec declaration.
9285 -- Finally, we set the task index value field of the entry attribute in
9286 -- the case of a simple entry.
9288 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9289 Loc : constant Source_Ptr := Sloc (N);
9290 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9291 Tasknm : constant Name_Id := Chars (Tasktyp);
9292 Taskdef : constant Node_Id := Task_Definition (N);
9294 Proc_Spec : Node_Id;
9296 Rec_Ent : Entity_Id;
9298 Elab_Decl : Node_Id;
9299 Size_Decl : Node_Id;
9300 Body_Decl : Node_Id;
9301 Task_Size : Node_Id;
9302 Ent_Stack : Entity_Id;
9303 Decl_Stack : Node_Id;
9306 -- If already expanded, nothing to do
9308 if Present (Corresponding_Record_Type (Tasktyp)) then
9312 -- Here we will do the expansion
9314 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9316 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9317 -- of implemented interfaces.
9319 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9321 Rec_Ent := Defining_Identifier (Rec_Decl);
9322 Cdecls := Component_Items (Component_List
9323 (Type_Definition (Rec_Decl)));
9325 Qualify_Entity_Names (N);
9327 -- First create the elaboration variable
9330 Make_Object_Declaration (Loc,
9331 Defining_Identifier =>
9332 Make_Defining_Identifier (Sloc (Tasktyp),
9333 Chars => New_External_Name (Tasknm, 'E')),
9334 Aliased_Present => True,
9335 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9336 Expression => New_Reference_To (Standard_False, Loc));
9337 Insert_After (N, Elab_Decl);
9339 -- Next create the declaration of the size variable (tasknmZ)
9341 Set_Storage_Size_Variable (Tasktyp,
9342 Make_Defining_Identifier (Sloc (Tasktyp),
9343 Chars => New_External_Name (Tasknm, 'Z')));
9345 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
9346 Is_Static_Expression (Expression (First (
9347 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
9348 Taskdef, Name_Storage_Size)))))
9351 Make_Object_Declaration (Loc,
9352 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9353 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9355 Convert_To (RTE (RE_Size_Type),
9358 Pragma_Argument_Associations (
9359 Find_Task_Or_Protected_Pragma
9360 (Taskdef, Name_Storage_Size)))))));
9364 Make_Object_Declaration (Loc,
9365 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9366 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9367 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
9370 Insert_After (Elab_Decl, Size_Decl);
9372 -- Next build the rest of the corresponding record declaration. This is
9373 -- done last, since the corresponding record initialization procedure
9374 -- will reference the previously created entities.
9376 -- Fill in the component declarations -- first the _Task_Id field
9379 Make_Component_Declaration (Loc,
9380 Defining_Identifier =>
9381 Make_Defining_Identifier (Loc, Name_uTask_Id),
9382 Component_Definition =>
9383 Make_Component_Definition (Loc,
9384 Aliased_Present => False,
9385 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
9388 -- Declare static ATCB (that is, created by the expander) if we are
9389 -- using the Restricted run time.
9391 if Restricted_Profile then
9393 Make_Component_Declaration (Loc,
9394 Defining_Identifier =>
9395 Make_Defining_Identifier (Loc, Name_uATCB),
9397 Component_Definition =>
9398 Make_Component_Definition (Loc,
9399 Aliased_Present => True,
9400 Subtype_Indication => Make_Subtype_Indication (Loc,
9401 Subtype_Mark => New_Occurrence_Of
9402 (RTE (RE_Ada_Task_Control_Block), Loc),
9405 Make_Index_Or_Discriminant_Constraint (Loc,
9407 New_List (Make_Integer_Literal (Loc, 0)))))));
9411 -- Declare static stack (that is, created by the expander) if we are
9412 -- using the Restricted run time on a bare board configuration.
9414 if Restricted_Profile
9415 and then Preallocated_Stacks_On_Target
9417 -- First we need to extract the appropriate stack size
9419 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
9421 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
9423 Expr_N : constant Node_Id :=
9425 Pragma_Argument_Associations (
9426 Find_Task_Or_Protected_Pragma
9427 (Taskdef, Name_Storage_Size))));
9428 Etyp : constant Entity_Id := Etype (Expr_N);
9429 P : constant Node_Id := Parent (Expr_N);
9432 -- The stack is defined inside the corresponding record.
9433 -- Therefore if the size of the stack is set by means of
9434 -- a discriminant, we must reference the discriminant of the
9435 -- corresponding record type.
9437 if Nkind (Expr_N) in N_Has_Entity
9438 and then Present (Discriminal_Link (Entity (Expr_N)))
9442 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
9444 Set_Parent (Task_Size, P);
9445 Set_Etype (Task_Size, Etyp);
9446 Set_Analyzed (Task_Size);
9449 Task_Size := Relocate_Node (Expr_N);
9455 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
9458 Decl_Stack := Make_Component_Declaration (Loc,
9459 Defining_Identifier => Ent_Stack,
9461 Component_Definition =>
9462 Make_Component_Definition (Loc,
9463 Aliased_Present => True,
9464 Subtype_Indication => Make_Subtype_Indication (Loc,
9466 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
9469 Make_Index_Or_Discriminant_Constraint (Loc,
9470 Constraints => New_List (Make_Range (Loc,
9471 Low_Bound => Make_Integer_Literal (Loc, 1),
9472 High_Bound => Convert_To (RTE (RE_Storage_Offset),
9475 Append_To (Cdecls, Decl_Stack);
9477 -- The appropriate alignment for the stack is ensured by the run-time
9478 -- code in charge of task creation.
9482 -- Add components for entry families
9484 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
9486 -- Add the _Priority component if a Priority pragma is present
9488 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
9490 Prag : constant Node_Id :=
9491 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
9495 Expr := First (Pragma_Argument_Associations (Prag));
9497 if Nkind (Expr) = N_Pragma_Argument_Association then
9498 Expr := Expression (Expr);
9501 Expr := New_Copy_Tree (Expr);
9503 -- Add conversion to proper type to do range check if required
9504 -- Note that for runtime units, we allow out of range interrupt
9505 -- priority values to be used in a priority pragma. This is for
9506 -- the benefit of some versions of System.Interrupts which use
9507 -- a special server task with maximum interrupt priority.
9509 if Chars (Prag) = Name_Priority
9510 and then not GNAT_Mode
9512 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
9514 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
9518 Make_Component_Declaration (Loc,
9519 Defining_Identifier =>
9520 Make_Defining_Identifier (Loc, Name_uPriority),
9521 Component_Definition =>
9522 Make_Component_Definition (Loc,
9523 Aliased_Present => False,
9524 Subtype_Indication => New_Reference_To (Standard_Integer,
9526 Expression => Expr));
9530 -- Add the _Task_Size component if a Storage_Size pragma is present
9532 if Present (Taskdef)
9533 and then Has_Storage_Size_Pragma (Taskdef)
9536 Make_Component_Declaration (Loc,
9537 Defining_Identifier =>
9538 Make_Defining_Identifier (Loc, Name_uSize),
9540 Component_Definition =>
9541 Make_Component_Definition (Loc,
9542 Aliased_Present => False,
9543 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
9547 Convert_To (RTE (RE_Size_Type),
9550 Pragma_Argument_Associations (
9551 Find_Task_Or_Protected_Pragma
9552 (Taskdef, Name_Storage_Size))))))));
9555 -- Add the _Task_Info component if a Task_Info pragma is present
9557 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
9559 Make_Component_Declaration (Loc,
9560 Defining_Identifier =>
9561 Make_Defining_Identifier (Loc, Name_uTask_Info),
9563 Component_Definition =>
9564 Make_Component_Definition (Loc,
9565 Aliased_Present => False,
9566 Subtype_Indication =>
9567 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
9569 Expression => New_Copy (
9571 Pragma_Argument_Associations (
9572 Find_Task_Or_Protected_Pragma
9573 (Taskdef, Name_Task_Info)))))));
9576 Insert_After (Size_Decl, Rec_Decl);
9578 -- Analyze the record declaration immediately after construction,
9579 -- because the initialization procedure is needed for single task
9580 -- declarations before the next entity is analyzed.
9584 -- Create the declaration of the task body procedure
9586 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
9588 Make_Subprogram_Declaration (Loc,
9589 Specification => Proc_Spec);
9591 Insert_After (Rec_Decl, Body_Decl);
9593 -- The subprogram does not comes from source, so we have to indicate the
9594 -- need for debugging information explicitly.
9596 Set_Needs_Debug_Info
9597 (Defining_Entity (Proc_Spec), Comes_From_Source (Original_Node (N)));
9599 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
9600 -- the corresponding record has been frozen.
9602 if Ada_Version >= Ada_05
9603 and then Present (Taskdef)
9604 and then Present (Corresponding_Record_Type
9605 (Defining_Identifier (Parent (Taskdef))))
9606 and then Present (Abstract_Interfaces
9607 (Corresponding_Record_Type
9608 (Defining_Identifier (Parent (Taskdef)))))
9611 Current_Node : Node_Id := Rec_Decl;
9612 Vis_Decl : Node_Id := First (Visible_Declarations (Taskdef));
9613 Wrap_Spec : Node_Id;
9617 -- Examine the visible declarations of the task type, looking for
9618 -- an entry declaration. We do not consider entry families since
9619 -- they cannot have dispatching operations, thus they do not need
9622 while Present (Vis_Decl) loop
9623 if Nkind (Vis_Decl) = N_Entry_Declaration
9624 and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry
9627 Build_Wrapper_Spec (Loc,
9628 Proc_Nam => Defining_Identifier (Vis_Decl),
9629 Obj_Typ => Etype (Rec_Ent),
9630 Formals => Parameter_Specifications (Vis_Decl));
9632 if Wrap_Spec /= Empty then
9634 Make_Subprogram_Declaration (Loc,
9635 Specification => Wrap_Spec);
9637 Insert_After (Current_Node, New_N);
9638 Current_Node := New_N;
9649 -- Ada 2005 (AI-345): We must defer freezing to allow further
9650 -- declaration of primitive subprograms covering task interfaces
9652 if Ada_Version <= Ada_95 then
9654 -- Now we can freeze the corresponding record. This needs manually
9655 -- freezing, since it is really part of the task type, and the task
9656 -- type is frozen at this stage. We of course need the initialization
9657 -- procedure for this corresponding record type and we won't get it
9658 -- in time if we don't freeze now.
9661 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
9664 if Is_Non_Empty_List (L) then
9665 Insert_List_After (Body_Decl, L);
9670 -- Complete the expansion of access types to the current task type, if
9671 -- any were declared.
9673 Expand_Previous_Access_Type (Tasktyp);
9674 end Expand_N_Task_Type_Declaration;
9676 -------------------------------
9677 -- Expand_N_Timed_Entry_Call --
9678 -------------------------------
9680 -- A timed entry call in normal case is not implemented using ATC mechanism
9681 -- anymore for efficiency reason.
9691 -- is expanded as follow:
9693 -- 1) When T.E is a task entry_call;
9697 -- X : Task_Entry_Index := <entry index>;
9698 -- DX : Duration := To_Duration (D);
9699 -- M : Delay_Mode := <discriminant>;
9700 -- P : parms := (parm, parm, parm);
9703 -- Timed_Protected_Entry_Call (<acceptor-task>, X, P'Address,
9712 -- 2) When T.E is a protected entry_call;
9716 -- X : Protected_Entry_Index := <entry index>;
9717 -- DX : Duration := To_Duration (D);
9718 -- M : Delay_Mode := <discriminant>;
9719 -- P : parms := (parm, parm, parm);
9722 -- Timed_Protected_Entry_Call (<object>'unchecked_access, X,
9723 -- P'Address, DX, M, B);
9731 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
9734 -- B : Boolean := False;
9735 -- C : Ada.Tags.Prim_Op_Kind;
9736 -- DX : Duration := To_Duration (D)
9737 -- K : Ada.Tags.Tagged_Kind :=
9738 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
9739 -- M : Integer :=...;
9740 -- P : Parameters := (Param1 .. ParamN);
9744 -- if K = Ada.Tags.TK_Limited_Tagged then
9745 -- <dispatching-call>;
9746 -- <triggering-statements>
9749 -- S := Ada.Tags.Get_Offset_Index (Ada.Tags.Tag (<object>),
9750 -- DT_Position (<dispatching-call>));
9752 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
9754 -- if C = POK_Protected_Entry
9755 -- or else C = POK_Task_Entry
9757 -- Param1 := P.Param1;
9759 -- ParamN := P.ParamN;
9763 -- if C = POK_Procedure
9764 -- or else C = POK_Protected_Procedure
9765 -- or else C = POK_Task_Procedure
9767 -- <dispatching-call>;
9770 -- <triggering-statements>
9772 -- <timed-statements>
9777 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
9778 Loc : constant Source_Ptr := Sloc (N);
9781 Entry_Call_Statement (Entry_Call_Alternative (N));
9782 E_Stats : constant List_Id :=
9783 Statements (Entry_Call_Alternative (N));
9784 D_Stat : constant Node_Id :=
9785 Delay_Statement (Delay_Alternative (N));
9786 D_Stats : constant List_Id :=
9787 Statements (Delay_Alternative (N));
9790 Blk_Typ : Entity_Id;
9792 Call_Ent : Entity_Id;
9793 Conc_Typ_Stmts : List_Id;
9803 Lim_Typ_Stmts : List_Id;
9812 B : Entity_Id; -- Call status flag
9813 C : Entity_Id; -- Call kind
9814 D : Entity_Id; -- Delay
9815 K : Entity_Id; -- Tagged kind
9816 M : Entity_Id; -- Delay mode
9817 P : Entity_Id; -- Parameter block
9818 S : Entity_Id; -- Primitive operation slot
9821 -- The arguments in the call may require dynamic allocation, and the
9822 -- call statement may have been transformed into a block. The block
9823 -- may contain additional declarations for internal entities, and the
9824 -- original call is found by sequential search.
9826 if Nkind (E_Call) = N_Block_Statement then
9827 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
9828 while Nkind (E_Call) /= N_Procedure_Call_Statement
9829 and then Nkind (E_Call) /= N_Entry_Call_Statement
9835 if Ada_Version >= Ada_05
9836 and then Nkind (E_Call) = N_Procedure_Call_Statement
9838 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
9844 -- Build an entry call using Simple_Entry_Call
9846 Extract_Entry (E_Call, Concval, Ename, Index);
9847 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
9849 Decls := Declarations (E_Call);
9850 Stmts := Statements (Handled_Statement_Sequence (E_Call));
9857 -- Call status flag processing
9859 if Ada_Version >= Ada_05
9860 and then Nkind (E_Call) = N_Procedure_Call_Statement
9863 -- B : Boolean := False;
9865 B := Build_B (Loc, Decls);
9871 B := Make_Defining_Identifier (Loc, Name_uB);
9874 Make_Object_Declaration (Loc,
9875 Defining_Identifier =>
9877 Object_Definition =>
9878 New_Reference_To (Standard_Boolean, Loc)));
9881 -- Call kind processing
9883 if Ada_Version >= Ada_05
9884 and then Nkind (E_Call) = N_Procedure_Call_Statement
9887 -- C : Ada.Tags.Prim_Op_Kind;
9889 C := Build_C (Loc, Decls);
9892 -- Duration and mode processing
9894 D_Type := Base_Type (Etype (Expression (D_Stat)));
9896 -- Use the type of the delay expression (Calendar or Real_Time)
9897 -- to generate the appropriate conversion.
9899 if Nkind (D_Stat) = N_Delay_Relative_Statement then
9900 D_Disc := Make_Integer_Literal (Loc, 0);
9901 D_Conv := Relocate_Node (Expression (D_Stat));
9903 elsif Is_RTE (D_Type, RO_CA_Time) then
9904 D_Disc := Make_Integer_Literal (Loc, 1);
9905 D_Conv := Make_Function_Call (Loc,
9906 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9907 New_List (New_Copy (Expression (D_Stat))));
9909 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
9910 D_Disc := Make_Integer_Literal (Loc, 2);
9911 D_Conv := Make_Function_Call (Loc,
9912 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9913 New_List (New_Copy (Expression (D_Stat))));
9916 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
9922 Make_Object_Declaration (Loc,
9923 Defining_Identifier =>
9925 Object_Definition =>
9926 New_Reference_To (Standard_Duration, Loc)));
9928 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
9931 -- M : Integer := (0 | 1 | 2);
9934 Make_Object_Declaration (Loc,
9935 Defining_Identifier =>
9937 Object_Definition =>
9938 New_Reference_To (Standard_Integer, Loc),
9942 -- Do the assignement at this stage only because the evaluation of the
9943 -- expression must not occur before (see ACVC C97302A).
9946 Make_Assignment_Statement (Loc,
9948 New_Reference_To (D, Loc),
9952 -- Parameter block processing
9954 -- Manually create the parameter block for dispatching calls. In the
9955 -- case of entries, the block has already been created during the call
9956 -- to Build_Simple_Entry_Call.
9958 if Ada_Version >= Ada_05
9959 and then Nkind (E_Call) = N_Procedure_Call_Statement
9961 -- Tagged kind processing, generate:
9962 -- K : Ada.Tags.Tagged_Kind :=
9963 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
9965 K := Build_K (Loc, Decls, Obj);
9967 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
9968 P := Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals,
9971 -- Dispatch table slot processing, generate:
9974 S := Build_S (Loc, Decls);
9977 -- S := Ada.Tags.Get_Offset_Index (
9978 -- Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
9980 Conc_Typ_Stmts := New_List (
9981 Build_S_Assignment (Loc, S, Obj, Call_Ent));
9984 -- _Disp_Timed_Select (<object>, S, P'address, D, M, C, B);
9986 -- where Obj is the controlling formal parameter, S is the dispatch
9987 -- table slot number of the dispatching operation, P is the wrapped
9988 -- parameter block, D is the duration, M is the duration mode, C is
9989 -- the call kind and B is the call status.
9993 Append_To (Params, New_Copy_Tree (Obj));
9994 Append_To (Params, New_Reference_To (S, Loc));
9995 Append_To (Params, Make_Attribute_Reference (Loc,
9996 Prefix => New_Reference_To (P, Loc),
9997 Attribute_Name => Name_Address));
9998 Append_To (Params, New_Reference_To (D, Loc));
9999 Append_To (Params, New_Reference_To (M, Loc));
10000 Append_To (Params, New_Reference_To (C, Loc));
10001 Append_To (Params, New_Reference_To (B, Loc));
10003 Append_To (Conc_Typ_Stmts,
10004 Make_Procedure_Call_Statement (Loc,
10007 Find_Prim_Op (Etype (Etype (Obj)),
10008 Name_uDisp_Timed_Select),
10010 Parameter_Associations =>
10014 -- if C = POK_Protected_Entry
10015 -- or else C = POK_Task_Entry
10017 -- Param1 := P.Param1;
10019 -- ParamN := P.ParamN;
10022 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
10024 -- Generate the if statement only when the packed parameters need
10025 -- explicit assignments to their corresponding actuals.
10027 if Present (Unpack) then
10028 Append_To (Conc_Typ_Stmts,
10029 Make_If_Statement (Loc,
10036 New_Reference_To (C, Loc),
10038 New_Reference_To (RTE (
10039 RE_POK_Protected_Entry), Loc)),
10043 New_Reference_To (C, Loc),
10045 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
10054 -- if C = POK_Procedure
10055 -- or else C = POK_Protected_Procedure
10056 -- or else C = POK_Task_Procedure
10058 -- <dispatching-call>
10060 -- <triggering-statements>
10062 -- <timed-statements>
10065 N_Stats := New_Copy_List_Tree (E_Stats);
10067 Prepend_To (N_Stats,
10068 Make_If_Statement (Loc,
10075 New_Reference_To (C, Loc),
10077 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
10083 New_Reference_To (C, Loc),
10085 New_Reference_To (RTE (
10086 RE_POK_Protected_Procedure), Loc)),
10090 New_Reference_To (C, Loc),
10092 New_Reference_To (RTE (
10093 RE_POK_Task_Procedure), Loc)))),
10096 New_List (E_Call)));
10098 Append_To (Conc_Typ_Stmts,
10099 Make_If_Statement (Loc,
10100 Condition => New_Reference_To (B, Loc),
10101 Then_Statements => N_Stats,
10102 Else_Statements => D_Stats));
10105 -- <dispatching-call>;
10106 -- <triggering-statements>
10108 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
10109 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
10112 -- if K = Ada.Tags.TK_Limited_Tagged then
10119 Make_If_Statement (Loc,
10123 New_Reference_To (K, Loc),
10125 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
10134 -- Skip assignments to temporaries created for in-out parameters.
10135 -- This makes unwarranted assumptions about the shape of the expanded
10136 -- tree for the call, and should be cleaned up ???
10138 Stmt := First (Stmts);
10139 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
10143 -- Do the assignement at this stage only because the evaluation
10144 -- of the expression must not occur before (see ACVC C97302A).
10146 Insert_Before (Stmt,
10147 Make_Assignment_Statement (Loc,
10148 Name => New_Reference_To (D, Loc),
10149 Expression => D_Conv));
10152 Params := Parameter_Associations (Call);
10154 -- For a protected type, we build a Timed_Protected_Entry_Call
10156 if Is_Protected_Type (Etype (Concval)) then
10158 -- Create a new call statement
10160 Param := First (Params);
10161 while Present (Param)
10162 and then not Is_RTE (Etype (Param), RE_Call_Modes)
10167 Dummy := Remove_Next (Next (Param));
10169 -- Remove garbage is following the Cancel_Param if present
10171 Dummy := Next (Param);
10173 -- Remove the mode of the Protected_Entry_Call call, then remove
10174 -- the Communication_Block of the Protected_Entry_Call call, and
10175 -- finally add Duration and a Delay_Mode parameter
10177 pragma Assert (Present (Param));
10178 Rewrite (Param, New_Reference_To (D, Loc));
10180 Rewrite (Dummy, New_Reference_To (M, Loc));
10182 -- Add a Boolean flag for successful entry call
10184 Append_To (Params, New_Reference_To (B, Loc));
10187 or else Restriction_Active (No_Entry_Queue) = False
10188 or else Number_Entries (Etype (Concval)) > 1
10191 Make_Procedure_Call_Statement (Loc,
10193 New_Reference_To (RTE (
10194 RE_Timed_Protected_Entry_Call), Loc),
10195 Parameter_Associations => Params));
10197 Param := First (Params);
10198 while Present (Param)
10199 and then not Is_RTE (Etype (Param), RE_Protected_Entry_Index)
10207 Make_Procedure_Call_Statement (Loc,
10208 Name => New_Reference_To (
10209 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
10210 Parameter_Associations => Params));
10213 -- For the task case, build a Timed_Task_Entry_Call
10216 -- Create a new call statement
10218 Append_To (Params, New_Reference_To (D, Loc));
10219 Append_To (Params, New_Reference_To (M, Loc));
10220 Append_To (Params, New_Reference_To (B, Loc));
10223 Make_Procedure_Call_Statement (Loc,
10225 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
10226 Parameter_Associations => Params));
10230 Make_Implicit_If_Statement (N,
10231 Condition => New_Reference_To (B, Loc),
10232 Then_Statements => E_Stats,
10233 Else_Statements => D_Stats));
10237 Make_Block_Statement (Loc,
10238 Declarations => Decls,
10239 Handled_Statement_Sequence =>
10240 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
10243 end Expand_N_Timed_Entry_Call;
10245 ----------------------------------------
10246 -- Expand_Protected_Body_Declarations --
10247 ----------------------------------------
10249 -- Part of the expansion of a protected body involves the creation of a
10250 -- declaration that can be referenced from the statement sequences of the
10255 -- This declaration is inserted in the declarations of the service entries
10256 -- procedure for the protected body, and it is important that it be
10257 -- inserted before the statements of the entry body statement sequences are
10258 -- analyzed. Thus it would be too late to create this declaration in the
10259 -- Expand_N_Protected_Body routine, which is why there is a separate
10260 -- procedure to be called directly from Sem_Ch9.
10262 -- Ann is used to hold the address of the record containing the parameters
10263 -- (see Expand_N_Entry_Call for more details on how this record is built).
10264 -- References to the parameters do an unchecked conversion of this address
10265 -- to a pointer to the required record type, and then access the field that
10266 -- holds the value of the required parameter. The entity for the address
10267 -- variable is held as the top stack element (i.e. the last element) of the
10268 -- Accept_Address stack in the corresponding entry entity, and this element
10269 -- must be set in place before the statements are processed.
10271 -- No stack is needed for entry bodies, since they cannot be nested, but it
10272 -- is kept for consistency between protected and task entries. The stack
10273 -- will never contain more than one element. There is also only one such
10274 -- variable for a given protected body, but this is placed on the
10275 -- Accept_Address stack of all of the entries, again for consistency.
10277 -- To expand the requeue statement, a label is provided at the end of the
10278 -- loop in the entry service routine created by the expander (see
10279 -- Expand_N_Protected_Body for details), so that the statement can be
10280 -- skipped after the requeue is complete. This label is created during the
10281 -- expansion of the entry body, which will take place after the expansion
10282 -- of the requeue statements that it contains, so a placeholder defining
10283 -- identifier is associated with the task type here.
10285 -- Another label is provided following case statement created by the
10286 -- expander. This label is need for implementing return statement from
10287 -- entry body so that a return can be expanded as a goto to this label.
10288 -- This label is created during the expansion of the entry body, which
10289 -- will take place after the expansion of the return statements that it
10290 -- contains. Therefore, just like the label for expanding requeues, we
10291 -- need another placeholder for the label.
10293 procedure Expand_Protected_Body_Declarations
10295 Spec_Id : Entity_Id)
10300 if No_Run_Time_Mode then
10301 Error_Msg_CRT ("protected body", N);
10304 elsif Expander_Active then
10306 -- Associate privals with the first subprogram or entry body to be
10307 -- expanded. These are used to expand references to private data
10310 Op := First_Protected_Operation (Declarations (N));
10312 if Present (Op) then
10313 Set_Discriminals (Parent (Spec_Id));
10314 Set_Privals (Parent (Spec_Id), Op, Sloc (N));
10317 end Expand_Protected_Body_Declarations;
10319 -------------------------
10320 -- External_Subprogram --
10321 -------------------------
10323 function External_Subprogram (E : Entity_Id) return Entity_Id is
10324 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10327 -- The internal and external subprograms follow each other on the entity
10328 -- chain. Note that previously private operations had no separate
10329 -- external subprogram. We now create one in all cases, because a
10330 -- private operation may actually appear in an external call, through
10331 -- a 'Access reference used for a callback.
10333 -- If the operation is a function that returns an anonymous access type,
10334 -- the corresponding itype appears before the operation, and must be
10337 -- This mechanism is fragile, there should be a real link between the
10338 -- two versions of the operation, but there is no place to put it ???
10340 if Is_Access_Type (Next_Entity (Subp)) then
10341 return Next_Entity (Next_Entity (Subp));
10343 return Next_Entity (Subp);
10345 end External_Subprogram;
10347 ------------------------------
10348 -- Extract_Dispatching_Call --
10349 ------------------------------
10351 procedure Extract_Dispatching_Call
10353 Call_Ent : out Entity_Id;
10354 Object : out Entity_Id;
10355 Actuals : out List_Id;
10356 Formals : out List_Id)
10358 Call_Nam : Node_Id;
10361 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10363 if Present (Original_Node (N)) then
10364 Call_Nam := Name (Original_Node (N));
10366 Call_Nam := Name (N);
10369 -- Retrieve the name of the dispatching procedure. It contains the
10370 -- dispatch table slot number.
10373 case Nkind (Call_Nam) is
10374 when N_Identifier =>
10377 when N_Selected_Component =>
10378 Call_Nam := Selector_Name (Call_Nam);
10381 raise Program_Error;
10386 Actuals := Parameter_Associations (N);
10387 Call_Ent := Entity (Call_Nam);
10388 Formals := Parameter_Specifications (Parent (Call_Ent));
10389 Object := First (Actuals);
10391 if Present (Original_Node (Object)) then
10392 Object := Original_Node (Object);
10394 end Extract_Dispatching_Call;
10396 -------------------
10397 -- Extract_Entry --
10398 -------------------
10400 procedure Extract_Entry
10402 Concval : out Node_Id;
10403 Ename : out Node_Id;
10404 Index : out Node_Id)
10406 Nam : constant Node_Id := Name (N);
10409 -- For a simple entry, the name is a selected component, with the
10410 -- prefix being the task value, and the selector being the entry.
10412 if Nkind (Nam) = N_Selected_Component then
10413 Concval := Prefix (Nam);
10414 Ename := Selector_Name (Nam);
10417 -- For a member of an entry family, the name is an indexed component
10418 -- where the prefix is a selected component, whose prefix in turn is
10419 -- the task value, and whose selector is the entry family. The single
10420 -- expression in the expressions list of the indexed component is the
10421 -- subscript for the family.
10423 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
10424 Concval := Prefix (Prefix (Nam));
10425 Ename := Selector_Name (Prefix (Nam));
10426 Index := First (Expressions (Nam));
10430 -------------------
10431 -- Family_Offset --
10432 -------------------
10434 function Family_Offset
10439 Cap : Boolean) return Node_Id
10445 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
10446 -- If one of the bounds is a reference to a discriminant, replace with
10447 -- corresponding discriminal of type. Within the body of a task retrieve
10448 -- the renamed discriminant by simple visibility, using its generated
10449 -- name. Within a protected object, find the original discriminant and
10450 -- replace it with the discriminal of the current protected operation.
10452 ------------------------------
10453 -- Convert_Discriminant_Ref --
10454 ------------------------------
10456 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
10457 Loc : constant Source_Ptr := Sloc (Bound);
10462 if Is_Entity_Name (Bound)
10463 and then Ekind (Entity (Bound)) = E_Discriminant
10465 if Is_Task_Type (Ttyp)
10466 and then Has_Completion (Ttyp)
10468 B := Make_Identifier (Loc, Chars (Entity (Bound)));
10469 Find_Direct_Name (B);
10471 elsif Is_Protected_Type (Ttyp) then
10472 D := First_Discriminant (Ttyp);
10473 while Chars (D) /= Chars (Entity (Bound)) loop
10474 Next_Discriminant (D);
10477 B := New_Reference_To (Discriminal (D), Loc);
10480 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
10483 elsif Nkind (Bound) = N_Attribute_Reference then
10487 B := New_Copy_Tree (Bound);
10491 Make_Attribute_Reference (Loc,
10492 Attribute_Name => Name_Pos,
10493 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
10494 Expressions => New_List (B));
10495 end Convert_Discriminant_Ref;
10497 -- Start of processing for Family_Offset
10500 Real_Hi := Convert_Discriminant_Ref (Hi);
10501 Real_Lo := Convert_Discriminant_Ref (Lo);
10504 if Is_Task_Type (Ttyp) then
10505 Ityp := RTE (RE_Task_Entry_Index);
10507 Ityp := RTE (RE_Protected_Entry_Index);
10511 Make_Attribute_Reference (Loc,
10512 Prefix => New_Reference_To (Ityp, Loc),
10513 Attribute_Name => Name_Min,
10514 Expressions => New_List (
10516 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
10519 Make_Attribute_Reference (Loc,
10520 Prefix => New_Reference_To (Ityp, Loc),
10521 Attribute_Name => Name_Max,
10522 Expressions => New_List (
10524 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
10527 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
10534 function Family_Size
10539 Cap : Boolean) return Node_Id
10544 if Is_Task_Type (Ttyp) then
10545 Ityp := RTE (RE_Task_Entry_Index);
10547 Ityp := RTE (RE_Protected_Entry_Index);
10551 Make_Attribute_Reference (Loc,
10552 Prefix => New_Reference_To (Ityp, Loc),
10553 Attribute_Name => Name_Max,
10554 Expressions => New_List (
10557 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
10559 Make_Integer_Literal (Loc, 1)),
10560 Make_Integer_Literal (Loc, 0)));
10563 -----------------------------------
10564 -- Find_Task_Or_Protected_Pragma --
10565 -----------------------------------
10567 function Find_Task_Or_Protected_Pragma
10569 P : Name_Id) return Node_Id
10574 N := First (Visible_Declarations (T));
10575 while Present (N) loop
10576 if Nkind (N) = N_Pragma then
10577 if Chars (N) = P then
10580 elsif P = Name_Priority
10581 and then Chars (N) = Name_Interrupt_Priority
10594 N := First (Private_Declarations (T));
10595 while Present (N) loop
10596 if Nkind (N) = N_Pragma then
10597 if Chars (N) = P then
10600 elsif P = Name_Priority
10601 and then Chars (N) = Name_Interrupt_Priority
10614 raise Program_Error;
10615 end Find_Task_Or_Protected_Pragma;
10617 -------------------------------
10618 -- First_Protected_Operation --
10619 -------------------------------
10621 function First_Protected_Operation (D : List_Id) return Node_Id is
10622 First_Op : Node_Id;
10625 First_Op := First (D);
10626 while Present (First_Op)
10627 and then Nkind (First_Op) /= N_Subprogram_Body
10628 and then Nkind (First_Op) /= N_Entry_Body
10634 end First_Protected_Operation;
10636 ---------------------------------
10637 -- Is_Potentially_Large_Family --
10638 ---------------------------------
10640 function Is_Potentially_Large_Family
10641 (Base_Index : Entity_Id;
10642 Conctyp : Entity_Id;
10644 Hi : Node_Id) return Boolean
10647 return Scope (Base_Index) = Standard_Standard
10648 and then Base_Index = Base_Type (Standard_Integer)
10649 and then Has_Discriminants (Conctyp)
10651 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
10653 (Denotes_Discriminant (Lo, True)
10654 or else Denotes_Discriminant (Hi, True));
10655 end Is_Potentially_Large_Family;
10657 --------------------------------
10658 -- Index_Constant_Declaration --
10659 --------------------------------
10661 function Index_Constant_Declaration
10663 Index_Id : Entity_Id;
10664 Prot : Entity_Id) return List_Id
10666 Loc : constant Source_Ptr := Sloc (N);
10667 Decls : constant List_Id := New_List;
10668 Index_Con : constant Entity_Id := Entry_Index_Constant (Index_Id);
10669 Index_Typ : Entity_Id;
10671 Hi : Node_Id := Type_High_Bound (Etype (Index_Id));
10672 Lo : Node_Id := Type_Low_Bound (Etype (Index_Id));
10674 function Replace_Discriminant (Bound : Node_Id) return Node_Id;
10675 -- The bounds of the entry index may depend on discriminants, so each
10676 -- declaration of an entry_index_constant must have its own subtype
10677 -- declaration, using the local renaming of the object discriminant.
10679 --------------------------
10680 -- Replace_Discriminant --
10681 --------------------------
10683 function Replace_Discriminant (Bound : Node_Id) return Node_Id is
10685 if Nkind (Bound) = N_Identifier
10686 and then Ekind (Entity (Bound)) = E_Constant
10687 and then Present (Discriminal_Link (Entity (Bound)))
10689 return Make_Identifier (Loc, Chars (Entity (Bound)));
10691 return Duplicate_Subexpr (Bound);
10693 end Replace_Discriminant;
10695 -- Start of processing for Index_Constant_Declaration
10698 Set_Discriminal_Link (Index_Con, Index_Id);
10700 if Is_Entity_Name (
10701 Original_Node (Discrete_Subtype_Definition (Parent (Index_Id))))
10703 -- Simple case: entry family is given by a subtype mark, and index
10704 -- constant has the same type, no replacement needed.
10706 Index_Typ := Etype (Index_Id);
10709 Hi := Replace_Discriminant (Hi);
10710 Lo := Replace_Discriminant (Lo);
10712 Index_Typ := Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
10715 Make_Subtype_Declaration (Loc,
10716 Defining_Identifier => Index_Typ,
10717 Subtype_Indication =>
10718 Make_Subtype_Indication (Loc,
10720 New_Occurrence_Of (Base_Type (Etype (Index_Id)), Loc),
10722 Make_Range_Constraint (Loc,
10723 Range_Expression => Make_Range (Loc, Lo, Hi)))),
10729 Make_Object_Declaration (Loc,
10730 Defining_Identifier => Index_Con,
10731 Constant_Present => True,
10732 Object_Definition => New_Occurrence_Of (Index_Typ, Loc),
10735 Make_Attribute_Reference (Loc,
10736 Prefix => New_Reference_To (Index_Typ, Loc),
10737 Attribute_Name => Name_Val,
10739 Expressions => New_List (
10743 Make_Op_Subtract (Loc,
10744 Left_Opnd => Make_Identifier (Loc, Name_uE),
10746 Entry_Index_Expression (Loc,
10747 Defining_Identifier (N), Empty, Prot)),
10750 Make_Attribute_Reference (Loc,
10751 Prefix => New_Reference_To (Index_Typ, Loc),
10752 Attribute_Name => Name_Pos,
10753 Expressions => New_List (
10754 Make_Attribute_Reference (Loc,
10755 Prefix => New_Reference_To (Index_Typ, Loc),
10756 Attribute_Name => Name_First))))))),
10760 end Index_Constant_Declaration;
10762 --------------------------------
10763 -- Make_Initialize_Protection --
10764 --------------------------------
10766 function Make_Initialize_Protection
10767 (Protect_Rec : Entity_Id) return List_Id
10769 Loc : constant Source_Ptr := Sloc (Protect_Rec);
10773 Ptyp : constant Node_Id :=
10774 Corresponding_Concurrent_Type (Protect_Rec);
10776 L : constant List_Id := New_List;
10777 Has_Entry : constant Boolean := Has_Entries (Ptyp);
10778 Restricted : constant Boolean := Restricted_Profile;
10781 -- We may need two calls to properly initialize the object, one to
10782 -- Initialize_Protection, and possibly one to Install_Handlers if we
10783 -- have a pragma Attach_Handler.
10785 -- Get protected declaration. In the case of a task type declaration,
10786 -- this is simply the parent of the protected type entity. In the single
10787 -- protected object declaration, this parent will be the implicit type,
10788 -- and we can find the corresponding single protected object declaration
10789 -- by searching forward in the declaration list in the tree.
10791 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
10792 -- of this type should have been removed during semantic analysis.
10794 Pdec := Parent (Ptyp);
10795 while Nkind (Pdec) /= N_Protected_Type_Declaration
10796 and then Nkind (Pdec) /= N_Single_Protected_Declaration
10801 -- Now we can find the object definition from this declaration
10803 Pdef := Protected_Definition (Pdec);
10805 -- Build the parameter list for the call. Note that _Init is the name
10806 -- of the formal for the object to be initialized, which is the task
10807 -- value record itself.
10811 -- Object parameter. This is a pointer to the object of type
10812 -- Protection used by the GNARL to control the protected object.
10815 Make_Attribute_Reference (Loc,
10817 Make_Selected_Component (Loc,
10818 Prefix => Make_Identifier (Loc, Name_uInit),
10819 Selector_Name => Make_Identifier (Loc, Name_uObject)),
10820 Attribute_Name => Name_Unchecked_Access));
10822 -- Priority parameter. Set to Unspecified_Priority unless there is a
10823 -- priority pragma, in which case we take the value from the pragma,
10824 -- or there is an interrupt pragma and no priority pragma, and we
10825 -- set the ceiling to Interrupt_Priority'Last, an implementation-
10826 -- defined value, see D.3(10).
10829 and then Has_Priority_Pragma (Pdef)
10832 Prio : constant Node_Id :=
10835 (Pragma_Argument_Associations
10836 (Find_Task_Or_Protected_Pragma
10837 (Pdef, Name_Priority))));
10841 -- If priority is a static expression, then we can duplicate it
10842 -- with no problem and simply append it to the argument list.
10844 if Is_Static_Expression (Prio) then
10846 Duplicate_Subexpr_No_Checks (Prio));
10848 -- Otherwise, the priority may be a per-object expression, if it
10849 -- depends on a discriminant of the type. In this case, create
10850 -- local variable to capture the expression. Note that it is
10851 -- really necessary to create this variable explicitly. It might
10852 -- be thought that removing side effects would the appropriate
10853 -- approach, but that could generate declarations improperly
10854 -- placed in the enclosing scope.
10856 -- Note: Use System.Any_Priority as the expected type for the
10857 -- non-static priority expression, in case the expression has not
10858 -- been analyzed yet (as occurs for example with pragma
10859 -- Interrupt_Priority).
10863 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
10866 Make_Object_Declaration (Loc,
10867 Defining_Identifier => Temp,
10868 Object_Definition =>
10869 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
10870 Expression => Relocate_Node (Prio)));
10872 Append_To (Args, New_Occurrence_Of (Temp, Loc));
10876 -- When no priority is specified but an xx_Handler pragma is, we default
10877 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
10879 elsif Has_Interrupt_Handler (Ptyp)
10880 or else Has_Attach_Handler (Ptyp)
10883 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
10885 -- Normal case, no priority or xx_Handler specified, default priority
10889 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
10892 -- Test for Compiler_Info parameter. This parameter allows entry body
10893 -- procedures and barrier functions to be called from the runtime. It
10894 -- is a pointer to the record generated by the compiler to represent
10895 -- the protected object.
10898 or else Has_Interrupt_Handler (Ptyp)
10899 or else Has_Attach_Handler (Ptyp)
10900 or else (Ada_Version >= Ada_05
10901 and then Present (Interface_List (Parent (Ptyp))))
10903 if Has_Entry or else not Restricted then
10905 Make_Attribute_Reference (Loc,
10906 Prefix => Make_Identifier (Loc, Name_uInit),
10907 Attribute_Name => Name_Address));
10910 -- Entry_Bodies parameter. This is a pointer to an array of pointers
10911 -- to the entry body procedures and barrier functions of the object.
10912 -- If the protected type has no entries this object will not exist;
10913 -- in this case, pass a null.
10916 P_Arr := Entry_Bodies_Array (Ptyp);
10919 Make_Attribute_Reference (Loc,
10920 Prefix => New_Reference_To (P_Arr, Loc),
10921 Attribute_Name => Name_Unrestricted_Access));
10924 or else Restriction_Active (No_Entry_Queue) = False
10925 or else Number_Entries (Ptyp) > 1
10926 or else (Has_Attach_Handler (Ptyp) and then not Restricted)
10928 -- Find index mapping function (clumsy but ok for now)
10930 while Ekind (P_Arr) /= E_Function loop
10931 Next_Entity (P_Arr);
10935 Make_Attribute_Reference (Loc,
10937 New_Reference_To (P_Arr, Loc),
10938 Attribute_Name => Name_Unrestricted_Access));
10941 elsif not Restricted then
10942 Append_To (Args, Make_Null (Loc));
10943 Append_To (Args, Make_Null (Loc));
10947 or else Restriction_Active (No_Entry_Queue) = False
10948 or else Number_Entries (Ptyp) > 1
10949 or else (Has_Attach_Handler (Ptyp)
10950 and then not Restricted)
10953 Make_Procedure_Call_Statement (Loc,
10954 Name => New_Reference_To (
10955 RTE (RE_Initialize_Protection_Entries), Loc),
10956 Parameter_Associations => Args));
10958 elsif not Has_Entry and then Restricted then
10960 Make_Procedure_Call_Statement (Loc,
10961 Name => New_Reference_To (
10962 RTE (RE_Initialize_Protection), Loc),
10963 Parameter_Associations => Args));
10967 Make_Procedure_Call_Statement (Loc,
10968 Name => New_Reference_To (
10969 RTE (RE_Initialize_Protection_Entry), Loc),
10970 Parameter_Associations => Args));
10975 Make_Procedure_Call_Statement (Loc,
10976 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
10977 Parameter_Associations => Args));
10980 if Has_Attach_Handler (Ptyp) then
10982 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
10983 -- make the following call:
10985 -- Install_Handlers (_object,
10986 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
10988 -- or, in the case of Ravenscar:
10990 -- Install_Handlers
10991 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
10994 Args : constant List_Id := New_List;
10995 Table : constant List_Id := New_List;
10996 Ritem : Node_Id := First_Rep_Item (Ptyp);
10999 if not Restricted then
11001 -- Appends the _object argument
11004 Make_Attribute_Reference (Loc,
11006 Make_Selected_Component (Loc,
11007 Prefix => Make_Identifier (Loc, Name_uInit),
11008 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11009 Attribute_Name => Name_Unchecked_Access));
11012 -- Build the Attach_Handler table argument
11014 while Present (Ritem) loop
11015 if Nkind (Ritem) = N_Pragma
11016 and then Chars (Ritem) = Name_Attach_Handler
11019 Handler : constant Node_Id :=
11020 First (Pragma_Argument_Associations (Ritem));
11022 Interrupt : constant Node_Id := Next (Handler);
11023 Expr : constant Node_Id := Expression (Interrupt);
11027 Make_Aggregate (Loc, Expressions => New_List (
11028 Unchecked_Convert_To
11029 (RTE (RE_System_Interrupt_Id), Expr),
11030 Make_Attribute_Reference (Loc,
11031 Prefix => Make_Selected_Component (Loc,
11032 Make_Identifier (Loc, Name_uInit),
11033 Duplicate_Subexpr_No_Checks
11034 (Expression (Handler))),
11035 Attribute_Name => Name_Access))));
11039 Next_Rep_Item (Ritem);
11042 -- Append the table argument we just built
11044 Append_To (Args, Make_Aggregate (Loc, Table));
11046 -- Append the Install_Handler call to the statements
11049 Make_Procedure_Call_Statement (Loc,
11050 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
11051 Parameter_Associations => Args));
11056 end Make_Initialize_Protection;
11058 ---------------------------
11059 -- Make_Task_Create_Call --
11060 ---------------------------
11062 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
11063 Loc : constant Source_Ptr := Sloc (Task_Rec);
11073 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
11074 Tnam := Chars (Ttyp);
11076 -- Get task declaration. In the case of a task type declaration, this is
11077 -- simply the parent of the task type entity. In the single task
11078 -- declaration, this parent will be the implicit type, and we can find
11079 -- the corresponding single task declaration by searching forward in the
11080 -- declaration list in the tree.
11082 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
11083 -- this type should have been removed during semantic analysis.
11085 Tdec := Parent (Ttyp);
11086 while Nkind (Tdec) /= N_Task_Type_Declaration
11087 and then Nkind (Tdec) /= N_Single_Task_Declaration
11092 -- Now we can find the task definition from this declaration
11094 Tdef := Task_Definition (Tdec);
11096 -- Build the parameter list for the call. Note that _Init is the name
11097 -- of the formal for the object to be initialized, which is the task
11098 -- value record itself.
11102 -- Priority parameter. Set to Unspecified_Priority unless there is a
11103 -- priority pragma, in which case we take the value from the pragma.
11105 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
11107 Make_Selected_Component (Loc,
11108 Prefix => Make_Identifier (Loc, Name_uInit),
11109 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
11112 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11115 -- Optional Stack parameter
11117 if Restricted_Profile then
11119 -- If the stack has been preallocated by the expander then
11120 -- pass its address. Otherwise, pass a null address.
11122 if Preallocated_Stacks_On_Target then
11124 Make_Attribute_Reference (Loc,
11125 Prefix => Make_Selected_Component (Loc,
11126 Prefix => Make_Identifier (Loc, Name_uInit),
11128 Make_Identifier (Loc, Name_uStack)),
11129 Attribute_Name => Name_Address));
11133 New_Reference_To (RTE (RE_Null_Address), Loc));
11137 -- Size parameter. If no Storage_Size pragma is present, then
11138 -- the size is taken from the taskZ variable for the type, which
11139 -- is either Unspecified_Size, or has been reset by the use of
11140 -- a Storage_Size attribute definition clause. If a pragma is
11141 -- present, then the size is taken from the _Size field of the
11142 -- task value record, which was set from the pragma value.
11145 and then Has_Storage_Size_Pragma (Tdef)
11148 Make_Selected_Component (Loc,
11149 Prefix => Make_Identifier (Loc, Name_uInit),
11150 Selector_Name => Make_Identifier (Loc, Name_uSize)));
11154 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
11157 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
11158 -- Task_Info pragma, in which case we take the value from the pragma.
11161 and then Has_Task_Info_Pragma (Tdef)
11164 Make_Selected_Component (Loc,
11165 Prefix => Make_Identifier (Loc, Name_uInit),
11166 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
11170 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
11173 if not Restricted_Profile then
11175 -- Number of entries. This is an expression of the form:
11177 -- n + _Init.a'Length + _Init.a'B'Length + ...
11179 -- where a,b... are the entry family names for the task definition
11181 Ecount := Build_Entry_Count_Expression (
11183 Component_Items (Component_List (
11184 Type_Definition (Parent (
11185 Corresponding_Record_Type (Ttyp))))),
11187 Append_To (Args, Ecount);
11189 -- Master parameter. This is a reference to the _Master parameter of
11190 -- the initialization procedure, except in the case of the pragma
11191 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
11192 -- See comments in System.Tasking.Initialization.Init_RTS for the
11195 if Restriction_Active (No_Task_Hierarchy) = False then
11196 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
11198 Append_To (Args, Make_Integer_Literal (Loc, 3));
11202 -- State parameter. This is a pointer to the task body procedure. The
11203 -- required value is obtained by taking the address of the task body
11204 -- procedure and converting it (with an unchecked conversion) to the
11205 -- type required by the task kernel. For further details, see the
11206 -- description of Expand_Task_Body
11209 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
11210 Make_Attribute_Reference (Loc,
11212 New_Occurrence_Of (Get_Task_Body_Procedure (Ttyp), Loc),
11213 Attribute_Name => Name_Address)));
11215 -- Discriminants parameter. This is just the address of the task
11216 -- value record itself (which contains the discriminant values
11219 Make_Attribute_Reference (Loc,
11220 Prefix => Make_Identifier (Loc, Name_uInit),
11221 Attribute_Name => Name_Address));
11223 -- Elaborated parameter. This is an access to the elaboration Boolean
11226 Make_Attribute_Reference (Loc,
11227 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
11228 Attribute_Name => Name_Unchecked_Access));
11230 -- Chain parameter. This is a reference to the _Chain parameter of
11231 -- the initialization procedure.
11233 Append_To (Args, Make_Identifier (Loc, Name_uChain));
11235 -- Task name parameter. Take this from the _Task_Id parameter to the
11236 -- init call unless there is a Task_Name pragma, in which case we take
11237 -- the value from the pragma.
11240 and then Has_Task_Name_Pragma (Tdef)
11244 Expression (First (
11245 Pragma_Argument_Associations (
11246 Find_Task_Or_Protected_Pragma
11247 (Tdef, Name_Task_Name))))));
11250 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
11253 -- Created_Task parameter. This is the _Task_Id field of the task
11257 Make_Selected_Component (Loc,
11258 Prefix => Make_Identifier (Loc, Name_uInit),
11259 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
11261 if Restricted_Profile then
11262 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
11264 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
11267 return Make_Procedure_Call_Statement (Loc,
11268 Name => Name, Parameter_Associations => Args);
11269 end Make_Task_Create_Call;
11271 ------------------------------
11272 -- Next_Protected_Operation --
11273 ------------------------------
11275 function Next_Protected_Operation (N : Node_Id) return Node_Id is
11279 Next_Op := Next (N);
11280 while Present (Next_Op)
11281 and then Nkind (Next_Op) /= N_Subprogram_Body
11282 and then Nkind (Next_Op) /= N_Entry_Body
11288 end Next_Protected_Operation;
11290 --------------------------
11291 -- Parameter_Block_Pack --
11292 --------------------------
11294 function Parameter_Block_Pack
11296 Blk_Typ : Entity_Id;
11300 Stmts : List_Id) return Node_Id
11302 Actual : Entity_Id;
11303 Expr : Node_Id := Empty;
11304 Formal : Entity_Id;
11305 Has_Param : Boolean := False;
11308 Temp_Asn : Node_Id;
11309 Temp_Nam : Node_Id;
11312 Actual := First (Actuals);
11313 Formal := Defining_Identifier (First (Formals));
11314 Params := New_List;
11316 while Present (Actual) loop
11317 if Is_By_Copy_Type (Etype (Actual)) then
11319 -- Jnn : aliased <formal-type>
11322 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
11325 Make_Object_Declaration (Loc,
11328 Defining_Identifier =>
11330 Object_Definition =>
11331 New_Reference_To (Etype (Formal), Loc)));
11333 if Ekind (Formal) /= E_Out_Parameter then
11339 New_Reference_To (Temp_Nam, Loc);
11341 Set_Assignment_OK (Temp_Asn);
11344 Make_Assignment_Statement (Loc,
11348 New_Copy_Tree (Actual)));
11352 -- Jnn'unchecked_access
11355 Make_Attribute_Reference (Loc,
11357 Name_Unchecked_Access,
11359 New_Reference_To (Temp_Nam, Loc)));
11363 -- The controlling parameter is omitted
11366 if not Is_Controlling_Actual (Actual) then
11368 Make_Reference (Loc, New_Copy_Tree (Actual)));
11374 Next_Actual (Actual);
11375 Next_Formal_With_Extras (Formal);
11379 Expr := Make_Aggregate (Loc, Params);
11384 -- J1'unchecked_access;
11385 -- <actual2>'reference;
11388 P := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
11391 Make_Object_Declaration (Loc,
11392 Defining_Identifier =>
11394 Object_Definition =>
11395 New_Reference_To (Blk_Typ, Loc),
11400 end Parameter_Block_Pack;
11402 ----------------------------
11403 -- Parameter_Block_Unpack --
11404 ----------------------------
11406 function Parameter_Block_Unpack
11410 Formals : List_Id) return List_Id
11412 Actual : Entity_Id;
11414 Formal : Entity_Id;
11415 Has_Asnmt : Boolean := False;
11416 Result : constant List_Id := New_List;
11419 Actual := First (Actuals);
11420 Formal := Defining_Identifier (First (Formals));
11421 while Present (Actual) loop
11422 if Is_By_Copy_Type (Etype (Actual))
11423 and then Ekind (Formal) /= E_In_Parameter
11426 -- <actual> := P.<formal>;
11429 Make_Assignment_Statement (Loc,
11433 Make_Explicit_Dereference (Loc,
11434 Make_Selected_Component (Loc,
11436 New_Reference_To (P, Loc),
11438 Make_Identifier (Loc, Chars (Formal)))));
11440 Set_Assignment_OK (Name (Asnmt));
11441 Append_To (Result, Asnmt);
11446 Next_Actual (Actual);
11447 Next_Formal_With_Extras (Formal);
11453 return New_List (Make_Null_Statement (Loc));
11455 end Parameter_Block_Unpack;
11457 ----------------------
11458 -- Set_Discriminals --
11459 ----------------------
11461 procedure Set_Discriminals (Dec : Node_Id) is
11464 D_Minal : Entity_Id;
11467 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
11468 Pdef := Defining_Identifier (Dec);
11470 if Has_Discriminants (Pdef) then
11471 D := First_Discriminant (Pdef);
11472 while Present (D) loop
11474 Make_Defining_Identifier (Sloc (D),
11475 Chars => New_External_Name (Chars (D), 'D'));
11477 Set_Ekind (D_Minal, E_Constant);
11478 Set_Etype (D_Minal, Etype (D));
11479 Set_Scope (D_Minal, Pdef);
11480 Set_Discriminal (D, D_Minal);
11481 Set_Discriminal_Link (D_Minal, D);
11483 Next_Discriminant (D);
11486 end Set_Discriminals;
11492 procedure Set_Privals
11496 After_Barrier : Boolean := False)
11502 Body_Ent : Entity_Id;
11503 For_Barrier : constant Boolean :=
11504 Nkind (Op) = N_Entry_Body and then not After_Barrier;
11506 Prec_Decl : constant Node_Id :=
11507 Parent (Corresponding_Record_Type
11508 (Defining_Identifier (Dec)));
11509 Prec_Def : constant Entity_Id := Type_Definition (Prec_Decl);
11510 Obj_Decl : Node_Id;
11511 P_Subtype : Entity_Id;
11512 Assoc_L : constant Elist_Id := New_Elmt_List;
11516 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
11518 (Nkind (Op) = N_Subprogram_Body or else Nkind (Op) = N_Entry_Body);
11520 Def := Protected_Definition (Dec);
11522 if Present (Private_Declarations (Def)) then
11523 P_Decl := First (Private_Declarations (Def));
11524 while Present (P_Decl) loop
11525 if Nkind (P_Decl) = N_Component_Declaration then
11526 P_Id := Defining_Identifier (P_Decl);
11528 if For_Barrier then
11530 Make_Defining_Identifier (Loc,
11531 Chars => New_External_Name (Chars (P_Id), 'P'));
11534 Make_Defining_Identifier (Loc,
11535 Chars => New_External_Name (Chars (P_Id)));
11538 Set_Ekind (Priv, E_Variable);
11539 Set_Etype (Priv, Etype (P_Id));
11540 Set_Scope (Priv, Scope (P_Id));
11541 Set_Esize (Priv, Esize (Etype (P_Id)));
11542 Set_Alignment (Priv, Alignment (Etype (P_Id)));
11544 -- If the type of the component is an itype, we must create a
11545 -- new itype for the corresponding prival in each protected
11546 -- operation, to avoid scoping problems. We create new itypes
11547 -- by copying the tree for the component definition.
11548 -- (Ada 2005) If the itype is an anonymous access type created
11549 -- for an access definition for a component, it is declared in
11550 -- the enclosing scope, and we do no create a local version of
11551 -- it, to prevent scoping anomalies in gigi.
11553 if Is_Itype (Etype (P_Id))
11555 (Is_Access_Type (Etype (P_Id))
11556 and then Is_Local_Anonymous_Access (Etype (P_Id)))
11558 Append_Elmt (P_Id, Assoc_L);
11559 Append_Elmt (Priv, Assoc_L);
11561 if Nkind (Op) = N_Entry_Body then
11562 Op_Id := Defining_Identifier (Op);
11564 Op_Id := Defining_Unit_Name (Specification (Op));
11568 (New_Copy_Tree (P_Decl, Assoc_L, New_Scope => Op_Id));
11571 Set_Protected_Operation (P_Id, Op);
11572 Set_Prival (P_Id, Priv);
11579 -- There is one more implicit private decl: the object itself. "prival"
11580 -- for this is attached to the protected body defining identifier.
11582 Body_Ent := Corresponding_Body (Dec);
11585 Make_Defining_Identifier (Sloc (Body_Ent),
11586 Chars => New_External_Name (Chars (Body_Ent), 'R'));
11588 -- Set the Etype to the implicit subtype of Protection created when
11589 -- the protected type declaration was expanded. This node will not
11590 -- be analyzed until it is used as the defining identifier for the
11591 -- renaming declaration in the protected operation body, and it will
11592 -- be needed in the references expanded before that body is expanded.
11593 -- Since the Protection field is aliased, set Is_Aliased as well.
11595 Obj_Decl := First (Component_Items (Component_List (Prec_Def)));
11596 while Chars (Defining_Identifier (Obj_Decl)) /= Name_uObject loop
11600 P_Subtype := Etype (Defining_Identifier (Obj_Decl));
11601 Set_Ekind (Priv, E_Variable);
11602 Set_Etype (Priv, P_Subtype);
11603 Set_Is_Aliased (Priv);
11604 Set_Object_Ref (Body_Ent, Priv);
11607 ----------------------------
11608 -- Update_Prival_Subtypes --
11609 ----------------------------
11611 procedure Update_Prival_Subtypes (N : Node_Id) is
11613 function Process (N : Node_Id) return Traverse_Result;
11614 -- Update the etype of occurrences of privals whose etype does not
11615 -- match the current Etype of the prival entity itself.
11617 procedure Update_Array_Bounds (E : Entity_Id);
11618 -- Itypes generated for array expressions may depend on the
11619 -- determinants of the protected object, and need to be processed
11620 -- separately because they are not attached to the tree.
11622 procedure Update_Index_Types (N : Node_Id);
11623 -- Similarly, update the types of expressions in indexed components
11624 -- which may depend on other discriminants.
11630 function Process (N : Node_Id) return Traverse_Result is
11632 if Is_Entity_Name (N) then
11634 E : constant Entity_Id := Entity (N);
11637 and then (Ekind (E) = E_Constant
11638 or else Ekind (E) = E_Variable)
11639 and then Nkind (Parent (E)) = N_Object_Renaming_Declaration
11640 and then not Is_Scalar_Type (Etype (E))
11641 and then Etype (N) /= Etype (E)
11644 -- Ensure that reference and entity have the same Etype,
11645 -- to prevent back-end inconsistencies.
11647 Set_Etype (N, Etype (E));
11648 Update_Index_Types (N);
11651 and then Ekind (E) = E_Constant
11652 and then Present (Discriminal_Link (E))
11654 Set_Etype (N, Etype (E));
11660 elsif Nkind (N) = N_Defining_Identifier
11661 or else Nkind (N) = N_Defining_Operator_Symbol
11662 or else Nkind (N) = N_Defining_Character_Literal
11666 elsif Nkind (N) = N_String_Literal then
11668 -- Array type, but bounds are constant
11672 elsif Nkind (N) = N_Object_Declaration
11673 and then Is_Itype (Etype (Defining_Identifier (N)))
11674 and then Is_Array_Type (Etype (Defining_Identifier (N)))
11676 Update_Array_Bounds (Etype (Defining_Identifier (N)));
11679 -- For array components of discriminated records, use the base type
11680 -- directly, because it may depend indirectly on the discriminants of
11681 -- the protected type.
11683 -- Cleaner would be a systematic mechanism to compute actual subtypes
11684 -- of private components???
11686 elsif Nkind (N) in N_Has_Etype
11687 and then Present (Etype (N))
11688 and then Is_Array_Type (Etype (N))
11689 and then Nkind (N) = N_Selected_Component
11690 and then Has_Discriminants (Etype (Prefix (N)))
11692 Set_Etype (N, Base_Type (Etype (N)));
11693 Update_Index_Types (N);
11697 if Nkind (N) in N_Has_Etype
11698 and then Present (Etype (N))
11699 and then Is_Itype (Etype (N)) then
11701 if Is_Array_Type (Etype (N)) then
11702 Update_Array_Bounds (Etype (N));
11704 elsif Is_Scalar_Type (Etype (N)) then
11705 Update_Prival_Subtypes (Type_Low_Bound (Etype (N)));
11706 Update_Prival_Subtypes (Type_High_Bound (Etype (N)));
11714 -------------------------
11715 -- Update_Array_Bounds --
11716 -------------------------
11718 procedure Update_Array_Bounds (E : Entity_Id) is
11721 Ind := First_Index (E);
11722 while Present (Ind) loop
11723 Update_Prival_Subtypes (Type_Low_Bound (Etype (Ind)));
11724 Update_Prival_Subtypes (Type_High_Bound (Etype (Ind)));
11727 end Update_Array_Bounds;
11729 ------------------------
11730 -- Update_Index_Types --
11731 ------------------------
11733 procedure Update_Index_Types (N : Node_Id) is
11738 -- If the prefix has an actual subtype that is different from the
11739 -- nominal one, update the types of the indices, so that the proper
11740 -- constraints are applied. Do not apply this transformation to a
11741 -- packed array, where the index type is computed for a byte array
11742 -- and is different from the source index.
11744 if Nkind (Parent (N)) = N_Indexed_Component
11746 not Is_Bit_Packed_Array (Etype (Prefix (Parent (N))))
11748 Indx1 := First (Expressions (Parent (N)));
11749 I_Typ := First_Index (Etype (N));
11751 while Present (Indx1) and then Present (I_Typ) loop
11753 if not Is_Entity_Name (Indx1) then
11754 Set_Etype (Indx1, Base_Type (Etype (I_Typ)));
11758 Next_Index (I_Typ);
11761 end Update_Index_Types;
11763 procedure Traverse is new Traverse_Proc (Process);
11765 -- Start of processing for Update_Prival_Subtypes
11769 end Update_Prival_Subtypes;