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 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Ch3; use Exp_Ch3;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Ch6; use Exp_Ch6;
34 with Exp_Dbug; use Exp_Dbug;
35 with Exp_Sel; use Exp_Sel;
36 with Exp_Smem; use Exp_Smem;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Freeze; use Freeze;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
48 with Sem_Ch6; use Sem_Ch6;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Ch11; use Sem_Ch11;
51 with Sem_Elab; use Sem_Elab;
52 with Sem_Res; use Sem_Res;
53 with Sem_Util; use Sem_Util;
54 with Sinfo; use Sinfo;
55 with Snames; use Snames;
56 with Stand; use Stand;
57 with Targparm; use Targparm;
58 with Tbuild; use Tbuild;
59 with Uintp; use Uintp;
61 package body Exp_Ch9 is
63 -- The following constant establishes the upper bound for the index of
64 -- an entry family. It is used to limit the allocated size of protected
65 -- types with defaulted discriminant of an integer type, when the bound
66 -- of some entry family depends on a discriminant. The limitation to
67 -- entry families of 128K should be reasonable in all cases, and is a
68 -- documented implementation restriction. It will be lifted when protected
69 -- entry families are re-implemented as a single ordered queue.
71 Entry_Family_Bound : constant Int := 2**16;
73 -----------------------
74 -- Local Subprograms --
75 -----------------------
77 function Actual_Index_Expression
81 Tsk : Entity_Id) return Node_Id;
82 -- Compute the index position for an entry call. Tsk is the target
83 -- task. If the bounds of some entry family depend on discriminants,
84 -- the expression computed by this function uses the discriminants
85 -- of the target task.
87 procedure Add_Object_Pointer
91 -- Prepend an object pointer declaration to the declaration list
92 -- Decls. This object pointer is initialized to a type conversion
93 -- of the System.Address pointer passed to entry barrier functions
94 -- and entry body procedures.
96 procedure Add_Formal_Renamings
101 -- Create renaming declarations for the formals, inside the procedure
102 -- that implements an entry body. The renamings make the original names
103 -- of the formals accessible to gdb, and serve no other purpose.
104 -- Spec is the specification of the procedure being built.
105 -- Decls is the list of declarations to be enhanced.
106 -- Ent is the entity for the original entry body.
108 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
109 -- Transform accept statement into a block with added exception handler.
110 -- Used both for simple accept statements and for accept alternatives in
111 -- select statements. Astat is the accept statement.
113 function Build_Barrier_Function
116 Pid : Node_Id) return Node_Id;
117 -- Build the function body returning the value of the barrier expression
118 -- for the specified entry body.
120 function Build_Barrier_Function_Specification
122 Loc : Source_Ptr) return Node_Id;
123 -- Build a specification for a function implementing
124 -- the protected entry barrier of the specified entry body.
126 function Build_Entry_Count_Expression
127 (Concurrent_Type : Node_Id;
128 Component_List : List_Id;
129 Loc : Source_Ptr) return Node_Id;
130 -- Compute number of entries for concurrent object. This is a count of
131 -- simple entries, followed by an expression that computes the length
132 -- of the range of each entry family. A single array with that size is
133 -- allocated for each concurrent object of the type.
135 function Build_Parameter_Block
139 Decls : List_Id) return Entity_Id;
140 -- Generate an access type for each actual parameter in the list Actuals.
141 -- Create an encapsulating record that contains all the actuals and return
142 -- its type. Generate:
143 -- type Ann1 is access all <actual1-type>
145 -- type AnnN is access all <actualN-type>
146 -- type Pnn is record
152 function Build_Wrapper_Body
154 Proc_Nam : Entity_Id;
156 Formals : List_Id) return Node_Id;
157 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
158 -- associated with a protected or task type. This is required to implement
159 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
160 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
161 -- handle object notation, Formals are the original entry formals that will
162 -- be explicitly replicated.
164 function Build_Wrapper_Spec
166 Proc_Nam : Entity_Id;
168 Formals : List_Id) return Node_Id;
169 -- Ada 2005 (AI-345): Build the specification of a primitive operation
170 -- associated with a protected or task type. This is required implement
171 -- dispatching calls through interfaces. Proc_Nam is the entry name to be
172 -- wrapped, Obj_Typ is the type of the newly added formal parameter to
173 -- handle object notation, Formals are the original entry formals that will
174 -- be explicitly replicated.
176 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
177 -- Build the function that translates the entry index in the call
178 -- (which depends on the size of entry families) into an index into the
179 -- Entry_Bodies_Array, to determine the body and barrier function used
180 -- in a protected entry call. A pointer to this function appears in every
183 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
184 -- Build subprogram declaration for previous one
186 function Build_Protected_Entry
189 Pid : Node_Id) return Node_Id;
190 -- Build the procedure implementing the statement sequence of
191 -- the specified entry body.
193 function Build_Protected_Entry_Specification
196 Loc : Source_Ptr) return Node_Id;
197 -- Build a specification for a procedure implementing
198 -- the statement sequence of the specified entry body.
199 -- Add attributes associating it with the entry defining identifier
202 function Build_Protected_Subprogram_Body
205 N_Op_Spec : Node_Id) return Node_Id;
206 -- This function is used to construct the protected version of a protected
207 -- subprogram. Its statement sequence first defers abort, then locks
208 -- the associated protected object, and then enters a block that contains
209 -- a call to the unprotected version of the subprogram (for details, see
210 -- Build_Unprotected_Subprogram_Body). This block statement requires
211 -- a cleanup handler that unlocks the object in all cases.
212 -- (see Exp_Ch7.Expand_Cleanup_Actions).
214 function Build_Protected_Spec
216 Obj_Type : Entity_Id;
217 Unprotected : Boolean := False;
218 Ident : Entity_Id) return List_Id;
219 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
220 -- Subprogram_Type. Builds signature of protected subprogram, adding the
221 -- formal that corresponds to the object itself. For an access to protected
222 -- subprogram, there is no object type to specify, so the additional
223 -- parameter has type Address and mode In. An indirect call through such
224 -- a pointer converts the address to a reference to the actual object.
225 -- The object is a limited record and therefore a by_reference type.
227 function Build_Selected_Name
229 Selector : Entity_Id;
230 Append_Char : Character := ' ') return Name_Id;
231 -- Build a name in the form of Prefix__Selector, with an optional
232 -- character appended. This is used for internal subprograms generated
233 -- for operations of protected types, including barrier functions.
234 -- For the subprograms generated for entry bodies and entry barriers,
235 -- the generated name includes a sequence number that makes names
236 -- unique in the presence of entry overloading. This is necessary
237 -- because entry body procedures and barrier functions all have the
240 procedure Build_Simple_Entry_Call
245 -- Some comments here would be useful ???
247 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
248 -- This routine constructs a specification for the procedure that we will
249 -- build for the task body for task type T. The spec has the form:
251 -- procedure tnameB (_Task : access tnameV);
253 -- where name is the character name taken from the task type entity that
254 -- is passed as the argument to the procedure, and tnameV is the task
255 -- value type that is associated with the task type.
257 function Build_Unprotected_Subprogram_Body
259 Pid : Node_Id) return Node_Id;
260 -- This routine constructs the unprotected version of a protected
261 -- subprogram body, which is contains all of the code in the
262 -- original, unexpanded body. This is the version of the protected
263 -- subprogram that is called from all protected operations on the same
264 -- object, including the protected version of the same subprogram.
266 procedure Collect_Entry_Families
269 Current_Node : in out Node_Id;
270 Conctyp : Entity_Id);
271 -- For each entry family in a concurrent type, create an anonymous array
272 -- type of the right size, and add a component to the corresponding_record.
274 function Copy_Result_Type (Res : Node_Id) return Node_Id;
275 -- Copy the result type of a function specification, when building the
276 -- internal operation corresponding to a protected function, or when
277 -- expanding an access to protected function. If the result is an anonymous
278 -- access to subprogram itself, we need to create a new signature with the
279 -- same parameter names and the same resolved types, but with new entities
282 function Family_Offset
287 Cap : Boolean) return Node_Id;
288 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
289 -- an accept statement, or the upper bound in the discrete subtype of
290 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
291 -- the concurrent type of the entry. If Cap is true, the result is
292 -- capped according to Entry_Family_Bound.
299 Cap : Boolean) return Node_Id;
300 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
301 -- a family, and handle properly the superflat case. This is equivalent
302 -- to the use of 'Length on the index type, but must use Family_Offset
303 -- to handle properly the case of bounds that depend on discriminants.
304 -- If Cap is true, the result is capped according to Entry_Family_Bound.
306 procedure Extract_Dispatching_Call
308 Call_Ent : out Entity_Id;
309 Object : out Entity_Id;
310 Actuals : out List_Id;
311 Formals : out List_Id);
312 -- Given a dispatching call, extract the entity of the name of the call,
313 -- its object parameter, its actual parameters and the formal parameters
314 -- of the overridden interface-level version.
316 procedure Extract_Entry
318 Concval : out Node_Id;
320 Index : out Node_Id);
321 -- Given an entry call, returns the associated concurrent object,
322 -- the entry name, and the entry family index.
324 function Find_Task_Or_Protected_Pragma
326 P : Name_Id) return Node_Id;
327 -- Searches the task or protected definition T for the first occurrence
328 -- of the pragma whose name is given by P. The caller has ensured that
329 -- the pragma is present in the task definition. A special case is that
330 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
331 -- ??? Should be implemented with the rep item chain mechanism.
333 function Index_Constant_Declaration
335 Index_Id : Entity_Id;
336 Prot : Entity_Id) return List_Id;
337 -- For an entry family and its barrier function, we define a local entity
338 -- that maps the index in the call into the entry index into the object:
340 -- I : constant Index_Type := Index_Type'Val (
341 -- E - <<index of first family member>> +
342 -- Protected_Entry_Index (Index_Type'Pos (Index_Type'First)));
344 function Is_Potentially_Large_Family
345 (Base_Index : Entity_Id;
348 Hi : Node_Id) return Boolean;
350 function Null_Statements (Stats : List_Id) return Boolean;
351 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
352 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
353 -- well to still count as null. Returns True for a null sequence. The
354 -- argument is the list of statements from the DO-END sequence.
356 function Parameter_Block_Pack
362 Stmts : List_Id) return Entity_Id;
363 -- Set the components of the generated parameter block with the values of
364 -- the actual parameters. Generate aliased temporaries to capture the
365 -- values for types that are passed by copy. Otherwise generate a reference
366 -- to the actual's value. Return the address of the aggregate block.
368 -- Jnn1 : alias <formal-type1>;
369 -- Jnn1 := <actual1>;
372 -- Jnn1'unchecked_access;
373 -- <actual2>'reference;
376 function Parameter_Block_Unpack
380 Formals : List_Id) return List_Id;
381 -- Retrieve the values of the components from the parameter block and
382 -- assign then to the original actual parameters. Generate:
383 -- <actual1> := P.<formal1>;
385 -- <actualN> := P.<formalN>;
387 function Trivial_Accept_OK return Boolean;
388 -- If there is no DO-END block for an accept, or if the DO-END block has
389 -- only null statements, then it is possible to do the Rendezvous with much
390 -- less overhead using the Accept_Trivial routine in the run-time library.
391 -- However, this is not always a valid optimization. Whether it is valid or
392 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
393 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
394 -- a rescheduling is required, so this optimization is not allowed. This
395 -- function returns True if the optimization is permitted.
397 procedure Update_Prival_Subtypes (N : Node_Id);
398 -- The actual subtypes of the privals will differ from the type of the
399 -- private declaration in the original protected type, if the protected
400 -- type has discriminants or if the prival has constrained components.
401 -- This is because the privals are generated out of sequence w.r.t. the
402 -- analysis of a protected body. After generating the bodies for protected
403 -- operations, we set correctly the type of all references to privals, by
404 -- means of a recursive tree traversal, which is heavy-handed but
407 -----------------------------
408 -- Actual_Index_Expression --
409 -----------------------------
411 function Actual_Index_Expression
415 Tsk : Entity_Id) return Node_Id
417 Ttyp : constant Entity_Id := Etype (Tsk);
425 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
426 -- Compute difference between bounds of entry family
428 --------------------------
429 -- Actual_Family_Offset --
430 --------------------------
432 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
434 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
435 -- Replace a reference to a discriminant with a selected component
436 -- denoting the discriminant of the target task.
438 -----------------------------
439 -- Actual_Discriminant_Ref --
440 -----------------------------
442 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
443 Typ : constant Entity_Id := Etype (Bound);
447 if not Is_Entity_Name (Bound)
448 or else Ekind (Entity (Bound)) /= E_Discriminant
450 if Nkind (Bound) = N_Attribute_Reference then
453 B := New_Copy_Tree (Bound);
458 Make_Selected_Component (Sloc,
459 Prefix => New_Copy_Tree (Tsk),
460 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
462 Analyze_And_Resolve (B, Typ);
466 Make_Attribute_Reference (Sloc,
467 Attribute_Name => Name_Pos,
468 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
469 Expressions => New_List (B));
470 end Actual_Discriminant_Ref;
472 -- Start of processing for Actual_Family_Offset
476 Make_Op_Subtract (Sloc,
477 Left_Opnd => Actual_Discriminant_Ref (Hi),
478 Right_Opnd => Actual_Discriminant_Ref (Lo));
479 end Actual_Family_Offset;
481 -- Start of processing for Actual_Index_Expression
484 -- The queues of entries and entry families appear in textual order in
485 -- the associated record. The entry index is computed as the sum of the
486 -- number of queues for all entries that precede the designated one, to
487 -- which is added the index expression, if this expression denotes a
488 -- member of a family.
490 -- The following is a place holder for the count of simple entries
492 Num := Make_Integer_Literal (Sloc, 1);
494 -- We construct an expression which is a series of addition operations.
495 -- See comments in Entry_Index_Expression, which is identical in
498 if Present (Index) then
499 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
506 Actual_Family_Offset (
507 Make_Attribute_Reference (Sloc,
508 Attribute_Name => Name_Pos,
509 Prefix => New_Reference_To (Base_Type (S), Sloc),
510 Expressions => New_List (Relocate_Node (Index))),
511 Type_Low_Bound (S)));
516 -- Now add lengths of preceding entries and entry families
518 Prev := First_Entity (Ttyp);
520 while Chars (Prev) /= Chars (Ent)
521 or else (Ekind (Prev) /= Ekind (Ent))
522 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
524 if Ekind (Prev) = E_Entry then
525 Set_Intval (Num, Intval (Num) + 1);
527 elsif Ekind (Prev) = E_Entry_Family then
529 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
531 -- The need for the following full view retrieval stems from
532 -- this complex case of nested generics and tasking:
535 -- type Formal_Index is range <>;
538 -- type Index is private;
545 -- type Index is new Formal_Index range 1 .. 10;
548 -- package body Outer is
550 -- entry Fam (Index); -- (2)
553 -- package body Inner is -- (3)
561 -- We are currently building the index expression for the entry
562 -- call "T.E" (1). Part of the expansion must mention the range
563 -- of the discrete type "Index" (2) of entry family "Fam".
564 -- However only the private view of type "Index" is available to
565 -- the inner generic (3) because there was no prior mention of
566 -- the type inside "Inner". This visibility requirement is
567 -- implicit and cannot be detected during the construction of
568 -- the generic trees and needs special handling.
571 and then Is_Private_Type (S)
572 and then Present (Full_View (S))
577 Lo := Type_Low_Bound (S);
578 Hi := Type_High_Bound (S);
586 Actual_Family_Offset (Hi, Lo),
588 Make_Integer_Literal (Sloc, 1)));
590 -- Other components are anonymous types to be ignored
600 end Actual_Index_Expression;
602 ----------------------------------
603 -- Add_Discriminal_Declarations --
604 ----------------------------------
606 procedure Add_Discriminal_Declarations
615 if Has_Discriminants (Typ) then
616 D := First_Discriminant (Typ);
618 while Present (D) loop
621 Make_Object_Renaming_Declaration (Loc,
622 Defining_Identifier => Discriminal (D),
623 Subtype_Mark => New_Reference_To (Etype (D), Loc),
625 Make_Selected_Component (Loc,
626 Prefix => Make_Identifier (Loc, Name),
627 Selector_Name => Make_Identifier (Loc, Chars (D)))));
629 Next_Discriminant (D);
632 end Add_Discriminal_Declarations;
634 ------------------------
635 -- Add_Object_Pointer --
636 ------------------------
638 procedure Add_Object_Pointer
647 -- Prepend the declaration of _object. This must be first in the
648 -- declaration list, since it is used by the discriminal and
649 -- prival declarations.
650 -- ??? An attempt to make this a renaming was unsuccessful.
652 -- type poVP is access poV;
653 -- _object : poVP := poVP!O;
656 Make_Defining_Identifier (Loc,
659 (Chars (Corresponding_Record_Type (Pid)), 'P'));
662 Make_Object_Declaration (Loc,
663 Defining_Identifier =>
664 Make_Defining_Identifier (Loc, Name_uObject),
665 Object_Definition => New_Reference_To (Obj_Ptr, Loc),
667 Unchecked_Convert_To (Obj_Ptr,
668 Make_Identifier (Loc, Name_uO)));
669 Set_Needs_Debug_Info (Defining_Identifier (Decl));
670 Prepend_To (Decls, Decl);
673 Make_Full_Type_Declaration (Loc,
674 Defining_Identifier => Obj_Ptr,
675 Type_Definition => Make_Access_To_Object_Definition (Loc,
676 Subtype_Indication =>
677 New_Reference_To (Corresponding_Record_Type (Pid), Loc))));
678 end Add_Object_Pointer;
680 --------------------------
681 -- Add_Formal_Renamings --
682 --------------------------
684 procedure Add_Formal_Renamings
690 Ptr : constant Entity_Id :=
692 (Next (First (Parameter_Specifications (Spec))));
693 -- The name of the formal that holds the address of the parameter block
702 Formal := First_Formal (Ent);
703 while Present (Formal) loop
704 Comp := Entry_Component (Formal);
706 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
707 Set_Etype (New_F, Etype (Formal));
708 Set_Scope (New_F, Ent);
709 Set_Needs_Debug_Info (New_F); -- That's the whole point.
711 if Ekind (Formal) = E_In_Parameter then
712 Set_Ekind (New_F, E_Constant);
714 Set_Ekind (New_F, E_Variable);
715 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
718 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
721 Make_Object_Renaming_Declaration (Loc,
722 Defining_Identifier => New_F,
723 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
725 Make_Explicit_Dereference (Loc,
726 Make_Selected_Component (Loc,
728 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
729 Make_Identifier (Loc, Chars (Ptr))),
731 New_Reference_To (Comp, Loc))));
733 Append (Decl, Decls);
734 Set_Renamed_Object (Formal, New_F);
735 Next_Formal (Formal);
737 end Add_Formal_Renamings;
739 ------------------------------
740 -- Add_Private_Declarations --
741 ------------------------------
743 procedure Add_Private_Declarations
749 Body_Ent : constant Entity_Id := Corresponding_Body (Parent (Typ));
750 Def : constant Node_Id := Protected_Definition (Parent (Typ));
757 pragma Assert (Nkind (Def) = N_Protected_Definition);
759 if Present (Private_Declarations (Def)) then
760 P := First (Private_Declarations (Def));
761 while Present (P) loop
762 if Nkind (P) = N_Component_Declaration then
763 Pdef := Defining_Identifier (P);
765 -- The privals are declared before the current body is
766 -- analyzed, for visibility reasons. Set their Sloc so
767 -- that it is consistent with their renaming declaration,
768 -- to prevent anomalies in gdb.
770 -- This kludgy model for privals should be redesigned ???
772 Set_Sloc (Prival (Pdef), Loc);
775 Make_Object_Renaming_Declaration (Loc,
776 Defining_Identifier => Prival (Pdef),
777 Subtype_Mark => New_Reference_To (Etype (Pdef), Loc),
779 Make_Selected_Component (Loc,
780 Prefix => Make_Identifier (Loc, Name),
781 Selector_Name => Make_Identifier (Loc, Chars (Pdef))));
782 Set_Needs_Debug_Info (Defining_Identifier (Decl));
783 Prepend_To (Decls, Decl);
790 -- One more "prival" for object itself, with the right protection type
793 Protection_Type : RE_Id;
796 if Has_Attach_Handler (Typ) then
797 if Restricted_Profile then
798 if Has_Entries (Typ) then
799 Protection_Type := RE_Protection_Entry;
801 Protection_Type := RE_Protection;
804 Protection_Type := RE_Static_Interrupt_Protection;
807 elsif Has_Interrupt_Handler (Typ) then
808 Protection_Type := RE_Dynamic_Interrupt_Protection;
810 -- The type has explicit entries or generated primitive entry
813 elsif Has_Entries (Typ)
814 or else (Ada_Version >= Ada_05
815 and then Present (Interface_List (Parent (Typ))))
818 or else Restriction_Active (No_Entry_Queue) = False
819 or else Number_Entries (Typ) > 1
821 Protection_Type := RE_Protection_Entries;
823 Protection_Type := RE_Protection_Entry;
827 Protection_Type := RE_Protection;
830 -- Adjust Sloc, as for the other privals
832 Set_Sloc (Object_Ref (Body_Ent), Loc);
835 Make_Object_Renaming_Declaration (Loc,
836 Defining_Identifier => Object_Ref (Body_Ent),
837 Subtype_Mark => New_Reference_To (RTE (Protection_Type), Loc),
839 Make_Selected_Component (Loc,
840 Prefix => Make_Identifier (Loc, Name),
841 Selector_Name => Make_Identifier (Loc, Name_uObject)));
842 Set_Needs_Debug_Info (Defining_Identifier (Decl));
843 Prepend_To (Decls, Decl);
845 end Add_Private_Declarations;
847 -----------------------
848 -- Build_Accept_Body --
849 -----------------------
851 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
852 Loc : constant Source_Ptr := Sloc (Astat);
853 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
860 -- At the end of the statement sequence, Complete_Rendezvous is called.
861 -- A label skipping the Complete_Rendezvous, and all other accept
862 -- processing, has already been added for the expansion of requeue
865 Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous);
866 Insert_Before (Last (Statements (Stats)), Call);
869 -- If exception handlers are present, then append Complete_Rendezvous
870 -- calls to the handlers, and construct the required outer block.
872 if Present (Exception_Handlers (Stats)) then
873 Hand := First (Exception_Handlers (Stats));
875 while Present (Hand) loop
876 Call := Build_Runtime_Call (Loc, RE_Complete_Rendezvous);
877 Append (Call, Statements (Hand));
883 Make_Handled_Sequence_Of_Statements (Loc,
884 Statements => New_List (
885 Make_Block_Statement (Loc,
886 Handled_Statement_Sequence => Stats)));
892 -- At this stage we know that the new statement sequence does not
893 -- have an exception handler part, so we supply one to call
894 -- Exceptional_Complete_Rendezvous. This handler is
896 -- when all others =>
897 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
899 -- We handle Abort_Signal to make sure that we properly catch the abort
900 -- case and wake up the caller.
902 Ohandle := Make_Others_Choice (Loc);
903 Set_All_Others (Ohandle);
905 Set_Exception_Handlers (New_S,
907 Make_Implicit_Exception_Handler (Loc,
908 Exception_Choices => New_List (Ohandle),
910 Statements => New_List (
911 Make_Procedure_Call_Statement (Loc,
912 Name => New_Reference_To (
913 RTE (RE_Exceptional_Complete_Rendezvous), Loc),
914 Parameter_Associations => New_List (
915 Make_Function_Call (Loc,
916 Name => New_Reference_To (
917 RTE (RE_Get_GNAT_Exception), Loc))))))));
919 Set_Parent (New_S, Astat); -- temp parent for Analyze call
920 Analyze_Exception_Handlers (Exception_Handlers (New_S));
921 Expand_Exception_Handlers (New_S);
923 -- Exceptional_Complete_Rendezvous must be called with abort
924 -- still deferred, which is the case for a "when all others" handler.
927 end Build_Accept_Body;
929 -----------------------------------
930 -- Build_Activation_Chain_Entity --
931 -----------------------------------
933 procedure Build_Activation_Chain_Entity (N : Node_Id) is
939 -- Loop to find enclosing construct containing activation chain variable
943 while not Nkind_In (P, N_Subprogram_Body,
944 N_Package_Declaration,
948 N_Extended_Return_Statement)
953 -- If we are in a package body, the activation chain variable is
954 -- declared in the body, but the Activation_Chain_Entity is attached to
957 if Nkind (P) = N_Package_Body then
958 Decls := Declarations (P);
959 P := Unit_Declaration_Node (Corresponding_Spec (P));
961 elsif Nkind (P) = N_Package_Declaration then
962 Decls := Visible_Declarations (Specification (P));
964 elsif Nkind (P) = N_Extended_Return_Statement then
965 Decls := Return_Object_Declarations (P);
968 Decls := Declarations (P);
971 -- If activation chain entity not already declared, declare it
973 if Nkind (P) = N_Extended_Return_Statement
974 or else No (Activation_Chain_Entity (P))
976 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
978 -- Note: An extended return statement is not really a task activator,
979 -- but it does have an activation chain on which to store the tasks
980 -- temporarily. On successful return, the tasks on this chain are
981 -- moved to the chain passed in by the caller. We do not build an
982 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
983 -- because we do not want to build a call to Activate_Tasks. Task
984 -- activation is the responsibility of the caller.
986 if Nkind (P) /= N_Extended_Return_Statement then
987 Set_Activation_Chain_Entity (P, Chain);
991 Make_Object_Declaration (Sloc (P),
992 Defining_Identifier => Chain,
993 Aliased_Present => True,
995 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
997 Analyze (First (Decls));
999 end Build_Activation_Chain_Entity;
1001 ----------------------------
1002 -- Build_Barrier_Function --
1003 ----------------------------
1005 function Build_Barrier_Function
1008 Pid : Node_Id) return Node_Id
1010 Loc : constant Source_Ptr := Sloc (N);
1011 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
1012 Index_Spec : constant Node_Id := Entry_Index_Specification
1014 Op_Decls : constant List_Id := New_List;
1021 Make_Defining_Identifier (Loc,
1022 Chars => Chars (Barrier_Function (Ent)));
1023 Bspec := Build_Barrier_Function_Specification (Bdef, Loc);
1025 -- <object pointer declaration>
1026 -- <discriminant renamings>
1027 -- <private object renamings>
1028 -- Add discriminal and private renamings. These names have
1029 -- already been used to expand references to discriminants
1030 -- and private data.
1032 Add_Discriminal_Declarations (Op_Decls, Pid, Name_uObject, Loc);
1033 Add_Private_Declarations (Op_Decls, Pid, Name_uObject, Loc);
1034 Add_Object_Pointer (Op_Decls, Pid, Loc);
1036 -- If this is the barrier for an entry family, the entry index is
1037 -- visible in the body of the barrier. Create a local variable that
1038 -- converts the entry index (which is the last formal of the barrier
1039 -- function) into the appropriate offset into the entry array. The
1040 -- entry index constant must be set, as for the entry body, so that
1041 -- local references to the entry index are correctly replaced with
1042 -- the local variable. This parallels what is done for entry bodies.
1044 if Present (Index_Spec) then
1046 Index_Id : constant Entity_Id := Defining_Identifier (Index_Spec);
1047 Index_Con : constant Entity_Id :=
1048 Make_Defining_Identifier (Loc,
1049 Chars => New_Internal_Name ('J'));
1051 Set_Entry_Index_Constant (Index_Id, Index_Con);
1052 Append_List_To (Op_Decls,
1053 Index_Constant_Declaration (N, Index_Id, Pid));
1057 -- Note: the condition in the barrier function needs to be properly
1058 -- processed for the C/Fortran boolean possibility, but this happens
1059 -- automatically since the return statement does this normalization.
1062 Make_Subprogram_Body (Loc,
1063 Specification => Bspec,
1064 Declarations => Op_Decls,
1065 Handled_Statement_Sequence =>
1066 Make_Handled_Sequence_Of_Statements (Loc,
1067 Statements => New_List (
1068 Make_Simple_Return_Statement (Loc,
1069 Expression => Condition (Ent_Formals)))));
1070 Set_Is_Entry_Barrier_Function (EBF);
1072 end Build_Barrier_Function;
1074 ------------------------------------------
1075 -- Build_Barrier_Function_Specification --
1076 ------------------------------------------
1078 function Build_Barrier_Function_Specification
1079 (Def_Id : Entity_Id;
1080 Loc : Source_Ptr) return Node_Id
1083 Set_Needs_Debug_Info (Def_Id);
1084 return Make_Function_Specification (Loc,
1085 Defining_Unit_Name => Def_Id,
1086 Parameter_Specifications => New_List (
1087 Make_Parameter_Specification (Loc,
1088 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
1090 New_Reference_To (RTE (RE_Address), Loc)),
1092 Make_Parameter_Specification (Loc,
1093 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE),
1095 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1097 Result_Definition => New_Reference_To (Standard_Boolean, Loc));
1098 end Build_Barrier_Function_Specification;
1100 --------------------------
1101 -- Build_Call_With_Task --
1102 --------------------------
1104 function Build_Call_With_Task
1106 E : Entity_Id) return Node_Id
1108 Loc : constant Source_Ptr := Sloc (N);
1111 Make_Function_Call (Loc,
1112 Name => New_Reference_To (E, Loc),
1113 Parameter_Associations => New_List (Concurrent_Ref (N)));
1114 end Build_Call_With_Task;
1116 --------------------------------
1117 -- Build_Corresponding_Record --
1118 --------------------------------
1120 function Build_Corresponding_Record
1123 Loc : Source_Ptr) return Node_Id
1125 Rec_Ent : constant Entity_Id :=
1126 Make_Defining_Identifier
1127 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1130 New_Disc : Entity_Id;
1134 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1135 Set_Ekind (Rec_Ent, E_Record_Type);
1136 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1137 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1138 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1139 Set_Stored_Constraint (Rec_Ent, No_Elist);
1142 -- Use discriminals to create list of discriminants for record, and
1143 -- create new discriminals for use in default expressions, etc. It is
1144 -- worth noting that a task discriminant gives rise to 5 entities;
1146 -- a) The original discriminant.
1147 -- b) The discriminal for use in the task.
1148 -- c) The discriminant of the corresponding record.
1149 -- d) The discriminal for the init proc of the corresponding record.
1150 -- e) The local variable that renames the discriminant in the procedure
1151 -- for the task body.
1153 -- In fact the discriminals b) are used in the renaming declarations
1154 -- for e). See details in einfo (Handling of Discriminants).
1156 if Present (Discriminant_Specifications (N)) then
1158 Disc := First_Discriminant (Ctyp);
1160 while Present (Disc) loop
1161 New_Disc := CR_Discriminant (Disc);
1164 Make_Discriminant_Specification (Loc,
1165 Defining_Identifier => New_Disc,
1166 Discriminant_Type =>
1167 New_Occurrence_Of (Etype (Disc), Loc),
1169 New_Copy (Discriminant_Default_Value (Disc))));
1171 Next_Discriminant (Disc);
1178 -- Now we can construct the record type declaration. Note that this
1179 -- record is "limited tagged". It is "limited" to reflect the underlying
1180 -- limitedness of the task or protected object that it represents, and
1181 -- ensuring for example that it is properly passed by reference. It is
1182 -- "tagged" to give support to dispatching calls through interfaces (Ada
1186 Make_Full_Type_Declaration (Loc,
1187 Defining_Identifier => Rec_Ent,
1188 Discriminant_Specifications => Dlist,
1190 Make_Record_Definition (Loc,
1192 Make_Component_List (Loc,
1193 Component_Items => Cdecls),
1195 Ada_Version >= Ada_05 and then Is_Tagged_Type (Ctyp),
1196 Limited_Present => True));
1197 end Build_Corresponding_Record;
1199 ----------------------------------
1200 -- Build_Entry_Count_Expression --
1201 ----------------------------------
1203 function Build_Entry_Count_Expression
1204 (Concurrent_Type : Node_Id;
1205 Component_List : List_Id;
1206 Loc : Source_Ptr) return Node_Id
1218 -- Count number of non-family entries
1221 Ent := First_Entity (Concurrent_Type);
1222 while Present (Ent) loop
1223 if Ekind (Ent) = E_Entry then
1230 Ecount := Make_Integer_Literal (Loc, Eindx);
1232 -- Loop through entry families building the addition nodes
1234 Ent := First_Entity (Concurrent_Type);
1235 Comp := First (Component_List);
1236 while Present (Ent) loop
1237 if Ekind (Ent) = E_Entry_Family then
1238 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1242 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1243 Hi := Type_High_Bound (Typ);
1244 Lo := Type_Low_Bound (Typ);
1245 Large := Is_Potentially_Large_Family
1246 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1249 Left_Opnd => Ecount,
1250 Right_Opnd => Family_Size
1251 (Loc, Hi, Lo, Concurrent_Type, Large));
1258 end Build_Entry_Count_Expression;
1260 ---------------------------
1261 -- Build_Parameter_Block --
1262 ---------------------------
1264 function Build_Parameter_Block
1268 Decls : List_Id) return Entity_Id
1274 Has_Comp : Boolean := False;
1278 Actual := First (Actuals);
1280 Formal := Defining_Identifier (First (Formals));
1282 while Present (Actual) loop
1283 if not Is_Controlling_Actual (Actual) then
1286 -- type Ann is access all <actual-type>
1289 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
1292 Make_Full_Type_Declaration (Loc,
1293 Defining_Identifier =>
1296 Make_Access_To_Object_Definition (Loc,
1300 Ekind (Formal) = E_In_Parameter,
1301 Subtype_Indication =>
1302 New_Reference_To (Etype (Actual), Loc))));
1308 Make_Component_Declaration (Loc,
1309 Defining_Identifier =>
1310 Make_Defining_Identifier (Loc, Chars (Formal)),
1311 Component_Definition =>
1312 Make_Component_Definition (Loc,
1315 Subtype_Indication =>
1316 New_Reference_To (Comp_Nam, Loc))));
1321 Next_Actual (Actual);
1322 Next_Formal_With_Extras (Formal);
1326 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
1331 -- type Pnn is record
1336 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1337 -- the original parameter names and Ann1 .. AnnN are the access to
1341 Make_Full_Type_Declaration (Loc,
1342 Defining_Identifier =>
1345 Make_Record_Definition (Loc,
1347 Make_Component_List (Loc, Comps))));
1350 -- type Pnn is null record;
1353 Make_Full_Type_Declaration (Loc,
1354 Defining_Identifier =>
1357 Make_Record_Definition (Loc,
1358 Null_Present => True,
1359 Component_List => Empty)));
1363 end Build_Parameter_Block;
1365 ------------------------
1366 -- Build_Wrapper_Body --
1367 ------------------------
1369 function Build_Wrapper_Body
1371 Proc_Nam : Entity_Id;
1372 Obj_Typ : Entity_Id;
1373 Formals : List_Id) return Node_Id
1375 Actuals : List_Id := No_List;
1376 Body_Spec : Node_Id;
1378 First_Formal : Node_Id;
1382 Body_Spec := Build_Wrapper_Spec (Loc, Proc_Nam, Obj_Typ, Formals);
1384 -- If we did not generate the specification do have nothing else to do
1386 if Body_Spec = Empty then
1390 -- Map formals to actuals. Use the list built for the wrapper spec,
1391 -- skipping the object notation parameter.
1393 First_Formal := First (Parameter_Specifications (Body_Spec));
1395 Formal := First_Formal;
1398 if Present (Formal) then
1399 Actuals := New_List;
1401 while Present (Formal) loop
1403 Make_Identifier (Loc, Chars =>
1404 Chars (Defining_Identifier (Formal))));
1410 -- An access-to-variable first parameter will require an explicit
1411 -- dereference in the unchecked conversion. This case occurs when
1412 -- a protected entry wrapper must override an interface-level
1413 -- procedure with interface access as first parameter.
1415 -- SubprgName (O.all).Proc_Nam (Formal_1 .. Formal_N)
1417 if Nkind (Parameter_Type (First_Formal)) = N_Access_Definition then
1419 Make_Explicit_Dereference (Loc,
1421 Make_Identifier (Loc, Chars => Name_uO));
1424 Make_Identifier (Loc, Chars => Name_uO);
1427 if Ekind (Proc_Nam) = E_Function then
1429 Make_Subprogram_Body (Loc,
1430 Specification => Body_Spec,
1431 Declarations => Empty_List,
1432 Handled_Statement_Sequence =>
1433 Make_Handled_Sequence_Of_Statements (Loc,
1436 Make_Simple_Return_Statement (Loc,
1437 Make_Function_Call (Loc,
1439 Make_Selected_Component (Loc,
1441 Unchecked_Convert_To (
1442 Corresponding_Concurrent_Type (Obj_Typ),
1445 New_Reference_To (Proc_Nam, Loc)),
1446 Parameter_Associations => Actuals)))));
1449 Make_Subprogram_Body (Loc,
1450 Specification => Body_Spec,
1451 Declarations => Empty_List,
1452 Handled_Statement_Sequence =>
1453 Make_Handled_Sequence_Of_Statements (Loc,
1456 Make_Procedure_Call_Statement (Loc,
1458 Make_Selected_Component (Loc,
1460 Unchecked_Convert_To (
1461 Corresponding_Concurrent_Type (Obj_Typ),
1464 New_Reference_To (Proc_Nam, Loc)),
1465 Parameter_Associations => Actuals))));
1467 end Build_Wrapper_Body;
1469 ------------------------
1470 -- Build_Wrapper_Spec --
1471 ------------------------
1473 function Build_Wrapper_Spec
1475 Proc_Nam : Entity_Id;
1476 Obj_Typ : Entity_Id;
1477 Formals : List_Id) return Node_Id
1479 New_Name_Id : constant Entity_Id :=
1480 Make_Defining_Identifier (Loc, Chars (Proc_Nam));
1482 First_Param : Node_Id := Empty;
1484 Iface_Elmt : Elmt_Id := No_Elmt;
1485 New_Formals : List_Id;
1486 Obj_Param : Node_Id;
1487 Obj_Param_Typ : Node_Id;
1488 Iface_Prim_Op : Entity_Id;
1489 Iface_Prim_Op_Elmt : Elmt_Id;
1491 function Overriding_Possible
1492 (Iface_Prim_Op : Entity_Id;
1493 Proc_Nam : Entity_Id) return Boolean;
1494 -- Determine whether a primitive operation can be overridden by the
1495 -- wrapper. Iface_Prim_Op is the candidate primitive operation of an
1496 -- abstract interface type, Proc_Nam is the generated entry wrapper.
1498 function Replicate_Entry_Formals
1500 Formals : List_Id) return List_Id;
1501 -- An explicit parameter replication is required due to the
1502 -- Is_Entry_Formal flag being set for all the formals. The explicit
1503 -- replication removes the flag that would otherwise cause a different
1504 -- path of analysis.
1506 -------------------------
1507 -- Overriding_Possible --
1508 -------------------------
1510 function Overriding_Possible
1511 (Iface_Prim_Op : Entity_Id;
1512 Proc_Nam : Entity_Id) return Boolean
1514 Prim_Op_Spec : constant Node_Id := Parent (Iface_Prim_Op);
1515 Proc_Spec : constant Node_Id := Parent (Proc_Nam);
1517 Is_Access_To_Variable : Boolean;
1518 Is_Out_Present : Boolean;
1520 function Type_Conformant_Parameters
1521 (Prim_Op_Param_Specs : List_Id;
1522 Proc_Param_Specs : List_Id) return Boolean;
1523 -- Determine whether the parameters of the generated entry wrapper
1524 -- and those of a primitive operation are type conformant. During
1525 -- this check, the first parameter of the primitive operation is
1528 --------------------------------
1529 -- Type_Conformant_Parameters --
1530 --------------------------------
1532 function Type_Conformant_Parameters
1533 (Prim_Op_Param_Specs : List_Id;
1534 Proc_Param_Specs : List_Id) return Boolean
1536 Prim_Op_Param : Node_Id;
1537 Prim_Op_Typ : Entity_Id;
1538 Proc_Param : Node_Id;
1539 Proc_Typ : Entity_Id;
1542 -- Skip the first parameter of the primitive operation
1544 Prim_Op_Param := Next (First (Prim_Op_Param_Specs));
1545 Proc_Param := First (Proc_Param_Specs);
1546 while Present (Prim_Op_Param)
1547 and then Present (Proc_Param)
1549 Prim_Op_Typ := Find_Parameter_Type (Prim_Op_Param);
1550 Proc_Typ := Find_Parameter_Type (Proc_Param);
1552 -- The two parameters must be mode conformant
1554 if not Conforming_Types
1555 (Prim_Op_Typ, Proc_Typ, Mode_Conformant)
1560 Next (Prim_Op_Param);
1564 -- One of the lists is longer than the other
1566 if Present (Prim_Op_Param) or else Present (Proc_Param) then
1571 end Type_Conformant_Parameters;
1573 -- Start of processing for Overriding_Possible
1576 if Chars (Iface_Prim_Op) /= Chars (Proc_Nam) then
1580 -- Special check for protected procedures: If an inherited subprogram
1581 -- is implemented by a protected procedure or an entry, then the
1582 -- first parameter of the inherited subprogram shall be of mode OUT
1583 -- or IN OUT, or an access-to-variable parameter.
1585 if Ekind (Iface_Prim_Op) = E_Procedure then
1588 Present (Parameter_Specifications (Prim_Op_Spec))
1590 Out_Present (First (Parameter_Specifications (Prim_Op_Spec)));
1592 Is_Access_To_Variable :=
1593 Present (Parameter_Specifications (Prim_Op_Spec))
1595 Nkind (Parameter_Type
1597 (Parameter_Specifications (Prim_Op_Spec)))) =
1598 N_Access_Definition;
1600 if not Is_Out_Present
1601 and then not Is_Access_To_Variable
1607 return Type_Conformant_Parameters (
1608 Parameter_Specifications (Prim_Op_Spec),
1609 Parameter_Specifications (Proc_Spec));
1610 end Overriding_Possible;
1612 -----------------------------
1613 -- Replicate_Entry_Formals --
1614 -----------------------------
1616 function Replicate_Entry_Formals
1618 Formals : List_Id) return List_Id
1620 New_Formals : constant List_Id := New_List;
1624 Formal := First (Formals);
1625 while Present (Formal) loop
1627 -- Create an explicit copy of the entry parameter
1629 Append_To (New_Formals,
1630 Make_Parameter_Specification (Loc,
1631 Defining_Identifier =>
1632 Make_Defining_Identifier (Loc,
1633 Chars => Chars (Defining_Identifier (Formal))),
1634 In_Present => In_Present (Formal),
1635 Out_Present => Out_Present (Formal),
1636 Parameter_Type => New_Reference_To (Etype (
1637 Parameter_Type (Formal)), Loc)));
1643 end Replicate_Entry_Formals;
1645 -- Start of processing for Build_Wrapper_Spec
1648 -- The mode is determined by the first parameter of the interface-level
1649 -- procedure that the current entry is trying to override.
1651 pragma Assert (Is_Non_Empty_List (Abstract_Interface_List (Obj_Typ)));
1653 -- We must examine all the protected operations of the implemented
1654 -- interfaces in order to discover a possible overriding candidate.
1656 Iface := Etype (First (Abstract_Interface_List (Obj_Typ)));
1658 Examine_Parents : loop
1659 if Present (Primitive_Operations (Iface)) then
1660 Iface_Prim_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
1661 while Present (Iface_Prim_Op_Elmt) loop
1662 Iface_Prim_Op := Node (Iface_Prim_Op_Elmt);
1664 if not Is_Predefined_Dispatching_Operation (Iface_Prim_Op) then
1665 while Present (Alias (Iface_Prim_Op)) loop
1666 Iface_Prim_Op := Alias (Iface_Prim_Op);
1669 -- The current primitive operation can be overridden by the
1670 -- 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 exit Examine_Parents when Etype (Iface) = Iface;
1686 Iface := Etype (Iface);
1687 end loop Examine_Parents;
1689 if Present (Abstract_Interfaces
1690 (Corresponding_Record_Type (Scope (Proc_Nam))))
1692 Iface_Elmt := First_Elmt
1693 (Abstract_Interfaces
1694 (Corresponding_Record_Type (Scope (Proc_Nam))));
1695 Examine_Interfaces : while Present (Iface_Elmt) loop
1696 Iface := Node (Iface_Elmt);
1698 if Present (Primitive_Operations (Iface)) then
1699 Iface_Prim_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
1700 while Present (Iface_Prim_Op_Elmt) loop
1701 Iface_Prim_Op := Node (Iface_Prim_Op_Elmt);
1703 if not Is_Predefined_Dispatching_Operation
1706 while Present (Alias (Iface_Prim_Op)) loop
1707 Iface_Prim_Op := Alias (Iface_Prim_Op);
1710 -- The current primitive operation can be overridden by
1711 -- the generated entry wrapper.
1713 if Overriding_Possible (Iface_Prim_Op, Proc_Nam) then
1714 First_Param := First (Parameter_Specifications
1715 (Parent (Iface_Prim_Op)));
1721 Next_Elmt (Iface_Prim_Op_Elmt);
1725 Next_Elmt (Iface_Elmt);
1726 end loop Examine_Interfaces;
1729 -- Return if no interface primitive can be overridden
1735 New_Formals := Replicate_Entry_Formals (Loc, Formals);
1737 -- ??? Certain source packages contain protected or task types that do
1738 -- not implement any interfaces and are compiled with the -gnat05
1739 -- switch. In this case, a default first parameter is created.
1741 if Present (First_Param) then
1742 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
1744 Make_Access_Definition (Loc,
1746 New_Reference_To (Obj_Typ, Loc));
1748 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
1752 Make_Parameter_Specification (Loc,
1753 Defining_Identifier =>
1754 Make_Defining_Identifier (Loc, Name_uO),
1755 In_Present => In_Present (First_Param),
1756 Out_Present => Out_Present (First_Param),
1757 Parameter_Type => Obj_Param_Typ);
1761 Make_Parameter_Specification (Loc,
1762 Defining_Identifier =>
1763 Make_Defining_Identifier (Loc, Name_uO),
1765 Out_Present => True,
1766 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
1769 Prepend_To (New_Formals, Obj_Param);
1771 -- Minimum decoration needed to catch the entity in
1772 -- Sem_Ch6.Override_Dispatching_Operation
1774 if Ekind (Proc_Nam) = E_Procedure
1775 or else Ekind (Proc_Nam) = E_Entry
1777 Set_Ekind (New_Name_Id, E_Procedure);
1778 Set_Is_Primitive_Wrapper (New_Name_Id);
1779 Set_Wrapped_Entity (New_Name_Id, Proc_Nam);
1782 Make_Procedure_Specification (Loc,
1783 Defining_Unit_Name => New_Name_Id,
1784 Parameter_Specifications => New_Formals);
1786 else pragma Assert (Ekind (Proc_Nam) = E_Function);
1787 Set_Ekind (New_Name_Id, E_Function);
1790 Make_Function_Specification (Loc,
1791 Defining_Unit_Name => New_Name_Id,
1792 Parameter_Specifications => New_Formals,
1793 Result_Definition =>
1794 New_Copy (Result_Definition (Parent (Proc_Nam))));
1796 end Build_Wrapper_Spec;
1798 ---------------------------
1799 -- Build_Find_Body_Index --
1800 ---------------------------
1802 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
1803 Loc : constant Source_Ptr := Sloc (Typ);
1806 Has_F : Boolean := False;
1808 If_St : Node_Id := Empty;
1811 Decls : List_Id := New_List;
1814 Siz : Node_Id := Empty;
1816 procedure Add_If_Clause (Expr : Node_Id);
1817 -- Add test for range of current entry
1819 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
1820 -- If a bound of an entry is given by a discriminant, retrieve the
1821 -- actual value of the discriminant from the enclosing object.
1827 procedure Add_If_Clause (Expr : Node_Id) is
1829 Stats : constant List_Id :=
1831 Make_Simple_Return_Statement (Loc,
1832 Expression => Make_Integer_Literal (Loc, Index + 1)));
1835 -- Index for current entry body
1839 -- Compute total length of entry queues so far
1847 Right_Opnd => Expr);
1852 Left_Opnd => Make_Identifier (Loc, Name_uE),
1855 -- Map entry queue indices in the range of the current family
1856 -- into the current index, that designates the entry body.
1860 Make_Implicit_If_Statement (Typ,
1862 Then_Statements => Stats,
1863 Elsif_Parts => New_List);
1869 Make_Elsif_Part (Loc,
1871 Then_Statements => Stats),
1872 Elsif_Parts (If_St));
1876 ------------------------------
1877 -- Convert_Discriminant_Ref --
1878 ------------------------------
1880 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
1884 if Is_Entity_Name (Bound)
1885 and then Ekind (Entity (Bound)) = E_Discriminant
1888 Make_Selected_Component (Loc,
1890 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
1891 Make_Explicit_Dereference (Loc,
1892 Make_Identifier (Loc, Name_uObject))),
1893 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
1894 Set_Etype (B, Etype (Entity (Bound)));
1896 B := New_Copy_Tree (Bound);
1900 end Convert_Discriminant_Ref;
1902 -- Start of processing for Build_Find_Body_Index
1905 Spec := Build_Find_Body_Index_Spec (Typ);
1907 Ent := First_Entity (Typ);
1908 while Present (Ent) loop
1909 if Ekind (Ent) = E_Entry_Family then
1919 -- If the protected type has no entry families, there is a one-one
1920 -- correspondence between entry queue and entry body.
1923 Make_Simple_Return_Statement (Loc,
1924 Expression => Make_Identifier (Loc, Name_uE));
1927 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
1930 -- if E <= l1 then return 1;
1931 -- elsif E <= l1 + l2 then return 2;
1936 Ent := First_Entity (Typ);
1938 Add_Object_Pointer (Decls, Typ, Loc);
1940 while Present (Ent) loop
1942 if Ekind (Ent) = E_Entry then
1943 Add_If_Clause (Make_Integer_Literal (Loc, 1));
1945 elsif Ekind (Ent) = E_Entry_Family then
1947 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1948 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
1949 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
1950 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
1959 Make_Simple_Return_Statement (Loc,
1960 Expression => Make_Integer_Literal (Loc, 1));
1962 elsif Nkind (Ret) = N_If_Statement then
1964 -- Ranges are in increasing order, so last one doesn't need guard
1967 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
1970 Set_Else_Statements (Ret, Then_Statements (Nod));
1976 Make_Subprogram_Body (Loc,
1977 Specification => Spec,
1978 Declarations => Decls,
1979 Handled_Statement_Sequence =>
1980 Make_Handled_Sequence_Of_Statements (Loc,
1981 Statements => New_List (Ret)));
1982 end Build_Find_Body_Index;
1984 --------------------------------
1985 -- Build_Find_Body_Index_Spec --
1986 --------------------------------
1988 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
1989 Loc : constant Source_Ptr := Sloc (Typ);
1990 Id : constant Entity_Id :=
1991 Make_Defining_Identifier (Loc,
1992 Chars => New_External_Name (Chars (Typ), 'F'));
1993 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
1994 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
1998 Make_Function_Specification (Loc,
1999 Defining_Unit_Name => Id,
2000 Parameter_Specifications => New_List (
2001 Make_Parameter_Specification (Loc,
2002 Defining_Identifier => Parm1,
2004 New_Reference_To (RTE (RE_Address), Loc)),
2006 Make_Parameter_Specification (Loc,
2007 Defining_Identifier => Parm2,
2009 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2010 Result_Definition => New_Occurrence_Of (
2011 RTE (RE_Protected_Entry_Index), Loc));
2012 end Build_Find_Body_Index_Spec;
2014 -------------------------
2015 -- Build_Master_Entity --
2016 -------------------------
2018 procedure Build_Master_Entity (E : Entity_Id) is
2019 Loc : constant Source_Ptr := Sloc (E);
2027 -- Ada 2005 (AI-287): Do not set/get the has_master_entity reminder
2028 -- in internal scopes, unless present already.. Required for nested
2029 -- limited aggregates. This could use some more explanation ????
2031 if Ada_Version >= Ada_05 then
2032 while Is_Internal (S) loop
2037 -- Nothing to do if we already built a master entity for this scope
2038 -- or if there is no task hierarchy.
2040 if Has_Master_Entity (S)
2041 or else Restriction_Active (No_Task_Hierarchy)
2046 -- Otherwise first build the master entity
2047 -- _Master : constant Master_Id := Current_Master.all;
2048 -- and insert it just before the current declaration
2051 Make_Object_Declaration (Loc,
2052 Defining_Identifier =>
2053 Make_Defining_Identifier (Loc, Name_uMaster),
2054 Constant_Present => True,
2055 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2057 Make_Explicit_Dereference (Loc,
2058 New_Reference_To (RTE (RE_Current_Master), Loc)));
2061 Insert_Before (P, Decl);
2064 -- Ada 2005 (AI-287): Set the has_master_entity reminder in the
2065 -- non-internal scope selected above.
2067 if Ada_Version >= Ada_05 then
2068 Set_Has_Master_Entity (S);
2070 Set_Has_Master_Entity (Scope (E));
2073 -- Now mark the containing scope as a task master
2075 while Nkind (P) /= N_Compilation_Unit loop
2078 -- If we fall off the top, we are at the outer level, and the
2079 -- environment task is our effective master, so nothing to mark.
2082 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2084 Set_Is_Task_Master (P, True);
2087 elsif Nkind (Parent (P)) = N_Subunit then
2088 P := Corresponding_Stub (Parent (P));
2091 end Build_Master_Entity;
2093 ---------------------------
2094 -- Build_Protected_Entry --
2095 ---------------------------
2097 function Build_Protected_Entry
2100 Pid : Node_Id) return Node_Id
2102 Loc : constant Source_Ptr := Sloc (N);
2104 End_Lab : constant Node_Id :=
2105 End_Label (Handled_Statement_Sequence (N));
2106 End_Loc : constant Source_Ptr :=
2107 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2108 -- Used for the generated call to Complete_Entry_Body
2110 Han_Loc : Source_Ptr;
2111 -- Used for the exception handler, inserted at end of the body
2113 Op_Decls : constant List_Id := New_List;
2121 -- Set the source location on the exception handler only when debugging
2122 -- the expanded code (see Make_Implicit_Exception_Handler).
2124 if Debug_Generated_Code then
2127 -- Otherwise the inserted code should not be visible to the debugger
2130 Han_Loc := No_Location;
2134 Make_Defining_Identifier (Loc,
2135 Chars => Chars (Protected_Body_Subprogram (Ent)));
2136 Espec := Build_Protected_Entry_Specification (Edef, Empty, Loc);
2138 -- <object pointer declaration>
2140 -- Add object pointer declaration. This is needed by the discriminal and
2141 -- prival renamings, which should already have been inserted into the
2142 -- declaration list.
2144 Add_Object_Pointer (Op_Decls, Pid, Loc);
2146 -- Add renamings for formals for use by debugger
2148 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2151 or else Restriction_Active (No_Entry_Queue) = False
2152 or else Number_Entries (Pid) > 1
2153 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile)
2155 Complete := New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2158 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2161 Op_Stats := New_List (
2162 Make_Block_Statement (Loc,
2163 Declarations => Declarations (N),
2164 Handled_Statement_Sequence =>
2165 Handled_Statement_Sequence (N)),
2167 Make_Procedure_Call_Statement (End_Loc,
2169 Parameter_Associations => New_List (
2170 Make_Attribute_Reference (End_Loc,
2172 Make_Selected_Component (End_Loc,
2174 Make_Identifier (End_Loc, Name_uObject),
2177 Make_Identifier (End_Loc, Name_uObject)),
2178 Attribute_Name => Name_Unchecked_Access))));
2180 -- When exceptions can not be propagated, we never need to call
2181 -- Exception_Complete_Entry_Body
2183 if No_Exception_Handlers_Set then
2185 Make_Subprogram_Body (Loc,
2186 Specification => Espec,
2187 Declarations => Op_Decls,
2188 Handled_Statement_Sequence =>
2189 Make_Handled_Sequence_Of_Statements (Loc,
2191 End_Label => End_Lab));
2194 Ohandle := Make_Others_Choice (Loc);
2195 Set_All_Others (Ohandle);
2198 or else Restriction_Active (No_Entry_Queue) = False
2199 or else Number_Entries (Pid) > 1
2200 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile)
2203 New_Reference_To (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2206 Complete := New_Reference_To (
2207 RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2210 -- Create body of entry procedure. The renaming declarations are
2211 -- placed ahead of the block that contains the actual entry body.
2214 Make_Subprogram_Body (Loc,
2215 Specification => Espec,
2216 Declarations => Op_Decls,
2217 Handled_Statement_Sequence =>
2218 Make_Handled_Sequence_Of_Statements (Loc,
2219 Statements => Op_Stats,
2220 End_Label => End_Lab,
2221 Exception_Handlers => New_List (
2222 Make_Implicit_Exception_Handler (Han_Loc,
2223 Exception_Choices => New_List (Ohandle),
2225 Statements => New_List (
2226 Make_Procedure_Call_Statement (Han_Loc,
2228 Parameter_Associations => New_List (
2229 Make_Attribute_Reference (Han_Loc,
2231 Make_Selected_Component (Han_Loc,
2233 Make_Identifier (Han_Loc, Name_uObject),
2235 Make_Identifier (Han_Loc, Name_uObject)),
2236 Attribute_Name => Name_Unchecked_Access),
2238 Make_Function_Call (Han_Loc,
2239 Name => New_Reference_To (
2240 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2242 end Build_Protected_Entry;
2244 -----------------------------------------
2245 -- Build_Protected_Entry_Specification --
2246 -----------------------------------------
2248 function Build_Protected_Entry_Specification
2249 (Def_Id : Entity_Id;
2251 Loc : Source_Ptr) return Node_Id
2256 Set_Needs_Debug_Info (Def_Id);
2257 P := Make_Defining_Identifier (Loc, Name_uP);
2259 if Present (Ent_Id) then
2260 Append_Elmt (P, Accept_Address (Ent_Id));
2263 return Make_Procedure_Specification (Loc,
2264 Defining_Unit_Name => Def_Id,
2265 Parameter_Specifications => New_List (
2266 Make_Parameter_Specification (Loc,
2267 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2269 New_Reference_To (RTE (RE_Address), Loc)),
2271 Make_Parameter_Specification (Loc,
2272 Defining_Identifier => P,
2274 New_Reference_To (RTE (RE_Address), Loc)),
2276 Make_Parameter_Specification (Loc,
2277 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uE),
2279 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2280 end Build_Protected_Entry_Specification;
2282 --------------------------
2283 -- Build_Protected_Spec --
2284 --------------------------
2286 function Build_Protected_Spec
2288 Obj_Type : Entity_Id;
2289 Unprotected : Boolean := False;
2290 Ident : Entity_Id) return List_Id
2292 Loc : constant Source_Ptr := Sloc (N);
2295 New_Plist : List_Id;
2296 New_Param : Node_Id;
2299 New_Plist := New_List;
2300 Formal := First_Formal (Ident);
2301 while Present (Formal) loop
2303 Make_Parameter_Specification (Loc,
2304 Defining_Identifier =>
2305 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2306 In_Present => In_Present (Parent (Formal)),
2307 Out_Present => Out_Present (Parent (Formal)),
2309 New_Reference_To (Etype (Formal), Loc));
2312 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2315 Append (New_Param, New_Plist);
2316 Next_Formal (Formal);
2319 -- If the subprogram is a procedure and the context is not an access
2320 -- to protected subprogram, the parameter is in-out. Otherwise it is
2324 Make_Parameter_Specification (Loc,
2325 Defining_Identifier =>
2326 Make_Defining_Identifier (Loc, Name_uObject),
2329 (Etype (Ident) = Standard_Void_Type
2330 and then not Is_RTE (Obj_Type, RE_Address)),
2331 Parameter_Type => New_Reference_To (Obj_Type, Loc));
2332 Set_Needs_Debug_Info (Defining_Identifier (Decl));
2333 Prepend_To (New_Plist, Decl);
2336 end Build_Protected_Spec;
2338 ---------------------------------------
2339 -- Build_Protected_Sub_Specification --
2340 ---------------------------------------
2342 function Build_Protected_Sub_Specification
2344 Prottyp : Entity_Id;
2345 Mode : Subprogram_Protection_Mode) return Node_Id
2347 Loc : constant Source_Ptr := Sloc (N);
2351 New_Plist : List_Id;
2354 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
2355 (Dispatching_Mode => ' ',
2356 Protected_Mode => 'P',
2357 Unprotected_Mode => 'N');
2361 (Defining_Unit_Name (Specification (N))) = E_Subprogram_Body
2363 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
2368 Ident := Defining_Unit_Name (Specification (Decl));
2371 Build_Protected_Spec (Decl,
2372 Corresponding_Record_Type (Prottyp),
2373 Mode = Unprotected_Mode, Ident);
2376 Make_Defining_Identifier (Loc,
2377 Chars => Build_Selected_Name (Prottyp, Ident, Append_Chr (Mode)));
2379 -- The unprotected operation carries the user code, and debugging
2380 -- information must be generated for it, even though this spec does
2381 -- not come from source. It is also convenient to allow gdb to step
2382 -- into the protected operation, even though it only contains lock/
2385 Set_Needs_Debug_Info (New_Id);
2387 if Nkind (Specification (Decl)) = N_Procedure_Specification then
2389 Make_Procedure_Specification (Loc,
2390 Defining_Unit_Name => New_Id,
2391 Parameter_Specifications => New_Plist);
2394 -- We need to create a new specification for the anonymous
2398 Make_Function_Specification (Loc,
2399 Defining_Unit_Name => New_Id,
2400 Parameter_Specifications => New_Plist,
2401 Result_Definition =>
2402 Copy_Result_Type (Result_Definition (Specification (Decl))));
2404 Set_Return_Present (Defining_Unit_Name (New_Spec));
2407 end Build_Protected_Sub_Specification;
2409 -------------------------------------
2410 -- Build_Protected_Subprogram_Body --
2411 -------------------------------------
2413 function Build_Protected_Subprogram_Body
2416 N_Op_Spec : Node_Id) return Node_Id
2418 Loc : constant Source_Ptr := Sloc (N);
2420 P_Op_Spec : Node_Id;
2423 Unprot_Call : Node_Id;
2425 Lock_Name : Node_Id;
2426 Lock_Stmt : Node_Id;
2427 Service_Name : Node_Id;
2429 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
2430 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
2432 Object_Parm : Node_Id;
2435 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
2436 -- Tell whether a given subprogram cannot raise an exception
2438 -----------------------
2439 -- Is_Exception_Safe --
2440 -----------------------
2442 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
2444 function Has_Side_Effect (N : Node_Id) return Boolean;
2445 -- Return True whenever encountering a subprogram call or raise
2446 -- statement of any kind in the sequence of statements
2448 ---------------------
2449 -- Has_Side_Effect --
2450 ---------------------
2452 -- What is this doing buried two levels down in exp_ch9. It seems
2453 -- like a generally useful function, and indeed there may be code
2454 -- duplication going on here ???
2456 function Has_Side_Effect (N : Node_Id) return Boolean is
2460 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
2461 -- Indicate whether N is a subprogram call or a raise statement
2463 ----------------------
2464 -- Is_Call_Or_Raise --
2465 ----------------------
2467 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
2469 return Nkind_In (N, N_Procedure_Call_Statement,
2472 N_Raise_Constraint_Error,
2473 N_Raise_Program_Error,
2474 N_Raise_Storage_Error);
2475 end Is_Call_Or_Raise;
2477 -- Start of processing for Has_Side_Effect
2481 while Present (Stmt) loop
2482 if Is_Call_Or_Raise (Stmt) then
2486 -- An object declaration can also contain a function call
2487 -- or a raise statement
2489 if Nkind (Stmt) = N_Object_Declaration then
2490 Expr := Expression (Stmt);
2492 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
2501 end Has_Side_Effect;
2503 -- Start of processing for Is_Exception_Safe
2506 -- If the checks handled by the back end are not disabled, we cannot
2507 -- ensure that no exception will be raised.
2509 if not Access_Checks_Suppressed (Empty)
2510 or else not Discriminant_Checks_Suppressed (Empty)
2511 or else not Range_Checks_Suppressed (Empty)
2512 or else not Index_Checks_Suppressed (Empty)
2513 or else Opt.Stack_Checking_Enabled
2518 if Has_Side_Effect (First (Declarations (Subprogram)))
2521 First (Statements (Handled_Statement_Sequence (Subprogram))))
2527 end Is_Exception_Safe;
2529 -- Start of processing for Build_Protected_Subprogram_Body
2532 Op_Spec := Specification (N);
2533 Exc_Safe := Is_Exception_Safe (N);
2536 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
2538 -- Build a list of the formal parameters of the protected version of
2539 -- the subprogram to use as the actual parameters of the unprotected
2542 Uactuals := New_List;
2543 Pformal := First (Parameter_Specifications (P_Op_Spec));
2544 while Present (Pformal) loop
2546 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
2551 -- Make a call to the unprotected version of the subprogram built above
2552 -- for use by the protected version built below.
2554 if Nkind (Op_Spec) = N_Function_Specification then
2556 R := Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
2558 Make_Object_Declaration (Loc,
2559 Defining_Identifier => R,
2560 Constant_Present => True,
2561 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
2563 Make_Function_Call (Loc,
2564 Name => Make_Identifier (Loc,
2565 Chars (Defining_Unit_Name (N_Op_Spec))),
2566 Parameter_Associations => Uactuals));
2567 Return_Stmt := Make_Simple_Return_Statement (Loc,
2568 Expression => New_Reference_To (R, Loc));
2571 Unprot_Call := Make_Simple_Return_Statement (Loc,
2572 Expression => Make_Function_Call (Loc,
2574 Make_Identifier (Loc,
2575 Chars (Defining_Unit_Name (N_Op_Spec))),
2576 Parameter_Associations => Uactuals));
2580 Unprot_Call := Make_Procedure_Call_Statement (Loc,
2582 Make_Identifier (Loc,
2583 Chars (Defining_Unit_Name (N_Op_Spec))),
2584 Parameter_Associations => Uactuals);
2587 -- Wrap call in block that will be covered by an at_end handler
2589 if not Exc_Safe then
2590 Unprot_Call := Make_Block_Statement (Loc,
2591 Handled_Statement_Sequence =>
2592 Make_Handled_Sequence_Of_Statements (Loc,
2593 Statements => New_List (Unprot_Call)));
2596 -- Make the protected subprogram body. This locks the protected
2597 -- object and calls the unprotected version of the subprogram.
2599 -- If the protected object is controlled (i.e it has entries or
2600 -- needs finalization for interrupt handling), call Lock_Entries,
2601 -- except if the protected object follows the Ravenscar profile, in
2602 -- which case call Lock_Entry, otherwise call the simplified version,
2605 if Has_Entries (Pid)
2606 or else Has_Interrupt_Handler (Pid)
2607 or else (Has_Attach_Handler (Pid)
2608 and then not Restricted_Profile)
2609 or else (Ada_Version >= Ada_05
2610 and then Present (Interface_List (Parent (Pid))))
2613 or else Restriction_Active (No_Entry_Queue) = False
2614 or else Number_Entries (Pid) > 1
2615 or else (Has_Attach_Handler (Pid) and then not Restricted_Profile)
2617 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
2618 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
2621 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
2622 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
2626 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
2627 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
2631 Make_Attribute_Reference (Loc,
2633 Make_Selected_Component (Loc,
2635 Make_Identifier (Loc, Name_uObject),
2637 Make_Identifier (Loc, Name_uObject)),
2638 Attribute_Name => Name_Unchecked_Access);
2640 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
2642 Parameter_Associations => New_List (Object_Parm));
2644 if Abort_Allowed then
2646 Make_Procedure_Call_Statement (Loc,
2647 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
2648 Parameter_Associations => Empty_List),
2652 Stmts := New_List (Lock_Stmt);
2655 if not Exc_Safe then
2656 Append (Unprot_Call, Stmts);
2658 if Nkind (Op_Spec) = N_Function_Specification then
2660 Stmts := Empty_List;
2662 Append (Unprot_Call, Stmts);
2666 Make_Procedure_Call_Statement (Loc,
2667 Name => Service_Name,
2668 Parameter_Associations =>
2669 New_List (New_Copy_Tree (Object_Parm))),
2672 if Abort_Allowed then
2674 Make_Procedure_Call_Statement (Loc,
2675 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
2676 Parameter_Associations => Empty_List),
2680 if Nkind (Op_Spec) = N_Function_Specification then
2681 Append (Return_Stmt, Stmts);
2682 Append (Make_Block_Statement (Loc,
2683 Declarations => New_List (Unprot_Call),
2684 Handled_Statement_Sequence =>
2685 Make_Handled_Sequence_Of_Statements (Loc,
2686 Statements => Stmts)), Pre_Stmts);
2692 Make_Subprogram_Body (Loc,
2693 Declarations => Empty_List,
2694 Specification => P_Op_Spec,
2695 Handled_Statement_Sequence =>
2696 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
2698 if not Exc_Safe then
2699 Set_Is_Protected_Subprogram_Body (Sub_Body);
2703 end Build_Protected_Subprogram_Body;
2705 -------------------------------------
2706 -- Build_Protected_Subprogram_Call --
2707 -------------------------------------
2709 procedure Build_Protected_Subprogram_Call
2713 External : Boolean := True)
2715 Loc : constant Source_Ptr := Sloc (N);
2716 Sub : constant Entity_Id := Entity (Name);
2722 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
2725 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
2728 if Present (Parameter_Associations (N)) then
2729 Params := New_Copy_List_Tree (Parameter_Associations (N));
2734 Prepend (Rec, Params);
2736 if Ekind (Sub) = E_Procedure then
2738 Make_Procedure_Call_Statement (Loc,
2740 Parameter_Associations => Params));
2743 pragma Assert (Ekind (Sub) = E_Function);
2745 Make_Function_Call (Loc,
2747 Parameter_Associations => Params));
2751 and then Nkind (Rec) = N_Unchecked_Type_Conversion
2752 and then Is_Entity_Name (Expression (Rec))
2753 and then Is_Shared_Passive (Entity (Expression (Rec)))
2755 Add_Shared_Var_Lock_Procs (N);
2757 end Build_Protected_Subprogram_Call;
2759 -------------------------
2760 -- Build_Selected_Name --
2761 -------------------------
2763 function Build_Selected_Name
2764 (Prefix : Entity_Id;
2765 Selector : Entity_Id;
2766 Append_Char : Character := ' ') return Name_Id
2768 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
2769 Select_Len : Natural;
2772 Get_Name_String (Chars (Selector));
2773 Select_Len := Name_Len;
2774 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
2775 Get_Name_String (Chars (Prefix));
2777 -- If scope is anonymous type, discard suffix to recover name of
2778 -- single protected object. Otherwise use protected type name.
2780 if Name_Buffer (Name_Len) = 'T' then
2781 Name_Len := Name_Len - 1;
2784 Name_Buffer (Name_Len + 1) := '_';
2785 Name_Buffer (Name_Len + 2) := '_';
2787 Name_Len := Name_Len + 2;
2788 for J in 1 .. Select_Len loop
2789 Name_Len := Name_Len + 1;
2790 Name_Buffer (Name_Len) := Select_Buffer (J);
2793 -- Now add the Append_Char if specified. The encoding to follow
2794 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
2795 -- then the entity is associated to a protected type subprogram.
2796 -- Otherwise, it is a protected type entry. For each case, the
2797 -- encoding to follow for the suffix is documented in exp_dbug.ads.
2799 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
2801 if Append_Char /= ' ' then
2802 if Append_Char = 'P' or Append_Char = 'N' then
2803 Name_Len := Name_Len + 1;
2804 Name_Buffer (Name_Len) := Append_Char;
2807 Name_Buffer (Name_Len + 1) := '_';
2808 Name_Buffer (Name_Len + 2) := Append_Char;
2809 Name_Len := Name_Len + 2;
2810 return New_External_Name (Name_Find, ' ', -1);
2815 end Build_Selected_Name;
2817 -----------------------------
2818 -- Build_Simple_Entry_Call --
2819 -----------------------------
2821 -- A task entry call is converted to a call to Call_Simple
2824 -- P : parms := (parm, parm, parm);
2826 -- Call_Simple (acceptor-task, entry-index, P'Address);
2832 -- Here Pnn is an aggregate of the type constructed for the entry to hold
2833 -- the parameters, and the constructed aggregate value contains either the
2834 -- parameters or, in the case of non-elementary types, references to these
2835 -- parameters. Then the address of this aggregate is passed to the runtime
2836 -- routine, along with the task id value and the task entry index value.
2837 -- Pnn is only required if parameters are present.
2839 -- The assignments after the call are present only in the case of in-out
2840 -- or out parameters for elementary types, and are used to assign back the
2841 -- resulting values of such parameters.
2843 -- Note: the reason that we insert a block here is that in the context
2844 -- of selects, conditional entry calls etc. the entry call statement
2845 -- appears on its own, not as an element of a list.
2847 -- A protected entry call is converted to a Protected_Entry_Call:
2850 -- P : E1_Params := (param, param, param);
2852 -- Bnn : Communications_Block;
2855 -- P : E1_Params := (param, param, param);
2856 -- Bnn : Communications_Block;
2859 -- Protected_Entry_Call (
2860 -- Object => po._object'Access,
2861 -- E => <entry index>;
2862 -- Uninterpreted_Data => P'Address;
2863 -- Mode => Simple_Call;
2870 procedure Build_Simple_Entry_Call
2879 -- If call has been inlined, nothing left to do
2881 if Nkind (N) = N_Block_Statement then
2885 -- Convert entry call to Call_Simple call
2888 Loc : constant Source_Ptr := Sloc (N);
2889 Parms : constant List_Id := Parameter_Associations (N);
2890 Stats : constant List_Id := New_List;
2893 Comm_Name : Entity_Id;
2897 Ent_Acc : Entity_Id;
2899 Iface_Tag : Entity_Id;
2900 Iface_Typ : Entity_Id;
2913 -- Simple entry and entry family cases merge here
2915 Ent := Entity (Ename);
2916 Ent_Acc := Entry_Parameters_Type (Ent);
2917 Conctyp := Etype (Concval);
2919 -- If prefix is an access type, dereference to obtain the task type
2921 if Is_Access_Type (Conctyp) then
2922 Conctyp := Designated_Type (Conctyp);
2925 -- Special case for protected subprogram calls
2927 if Is_Protected_Type (Conctyp)
2928 and then Is_Subprogram (Entity (Ename))
2930 if not Is_Eliminated (Entity (Ename)) then
2931 Build_Protected_Subprogram_Call
2932 (N, Ename, Convert_Concurrent (Concval, Conctyp));
2939 -- First parameter is the Task_Id value from the task value or the
2940 -- Object from the protected object value, obtained by selecting
2941 -- the _Task_Id or _Object from the result of doing an unchecked
2942 -- conversion to convert the value to the corresponding record type.
2944 Parm1 := Concurrent_Ref (Concval);
2946 -- Second parameter is the entry index, computed by the routine
2947 -- provided for this purpose. The value of this expression is
2948 -- assigned to an intermediate variable to assure that any entry
2949 -- family index expressions are evaluated before the entry
2953 or else Restriction_Active (No_Entry_Queue) = False
2954 or else not Is_Protected_Type (Conctyp)
2955 or else Number_Entries (Conctyp) > 1
2956 or else (Has_Attach_Handler (Conctyp)
2957 and then not Restricted_Profile)
2959 X := Make_Defining_Identifier (Loc, Name_uX);
2962 Make_Object_Declaration (Loc,
2963 Defining_Identifier => X,
2964 Object_Definition =>
2965 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2966 Expression => Actual_Index_Expression (
2967 Loc, Entity (Ename), Index, Concval));
2969 Decls := New_List (Xdecl);
2970 Parm2 := New_Reference_To (X, Loc);
2978 -- The third parameter is the packaged parameters. If there are
2979 -- none, then it is just the null address, since nothing is passed.
2982 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
2985 -- Case of parameters present, where third argument is the address
2986 -- of a packaged record containing the required parameter values.
2989 -- First build a list of parameter values, which are references to
2990 -- objects of the parameter types.
2994 Actual := First_Actual (N);
2995 Formal := First_Formal (Ent);
2997 while Present (Actual) loop
2999 -- If it is a by_copy_type, copy it to a new variable. The
3000 -- packaged record has a field that points to this variable.
3002 if Is_By_Copy_Type (Etype (Actual)) then
3004 Make_Object_Declaration (Loc,
3005 Defining_Identifier =>
3006 Make_Defining_Identifier (Loc,
3007 Chars => New_Internal_Name ('J')),
3008 Aliased_Present => True,
3009 Object_Definition =>
3010 New_Reference_To (Etype (Formal), Loc));
3012 -- Mark the object as not needing initialization since the
3013 -- initialization is performed separately, avoiding errors
3014 -- on cases such as formals of null-excluding access types.
3016 Set_No_Initialization (N_Node);
3018 -- We must make an assignment statement separate for the
3019 -- case of limited type. We cannot assign it unless the
3020 -- Assignment_OK flag is set first. An out formal of an
3021 -- access type must also be initialized from the actual,
3022 -- as stated in RM 6.4.1 (13).
3024 if Ekind (Formal) /= E_Out_Parameter
3025 or else Is_Access_Type (Etype (Formal))
3028 New_Reference_To (Defining_Identifier (N_Node), Loc);
3029 Set_Assignment_OK (N_Var);
3031 Make_Assignment_Statement (Loc,
3033 Expression => Relocate_Node (Actual)));
3036 Append (N_Node, Decls);
3039 Make_Attribute_Reference (Loc,
3040 Attribute_Name => Name_Unchecked_Access,
3042 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3044 -- Interface class-wide formal
3046 if Ada_Version >= Ada_05
3047 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3048 and then Is_Interface (Etype (Formal))
3050 Iface_Typ := Etype (Etype (Formal));
3053 -- formal_iface_type! (actual.iface_tag)'reference
3056 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3057 pragma Assert (Present (Iface_Tag));
3060 Make_Reference (Loc,
3061 Unchecked_Convert_To (Iface_Typ,
3062 Make_Selected_Component (Loc,
3064 Relocate_Node (Actual),
3066 New_Reference_To (Iface_Tag, Loc)))));
3072 Make_Reference (Loc, Relocate_Node (Actual)));
3076 Next_Actual (Actual);
3077 Next_Formal_With_Extras (Formal);
3080 -- Now build the declaration of parameters initialized with the
3081 -- aggregate containing this constructed parameter list.
3083 P := Make_Defining_Identifier (Loc, Name_uP);
3086 Make_Object_Declaration (Loc,
3087 Defining_Identifier => P,
3088 Object_Definition =>
3089 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3091 Make_Aggregate (Loc, Expressions => Plist));
3094 Make_Attribute_Reference (Loc,
3095 Prefix => New_Reference_To (P, Loc),
3096 Attribute_Name => Name_Address);
3098 Append (Pdecl, Decls);
3101 -- Now we can create the call, case of protected type
3103 if Is_Protected_Type (Conctyp) then
3105 or else Restriction_Active (No_Entry_Queue) = False
3106 or else Number_Entries (Conctyp) > 1
3107 or else (Has_Attach_Handler (Conctyp)
3108 and then not Restricted_Profile)
3110 -- Change the type of the index declaration
3112 Set_Object_Definition (Xdecl,
3113 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3115 -- Some additional declarations for protected entry calls
3121 -- Bnn : Communications_Block;
3124 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3127 Make_Object_Declaration (Loc,
3128 Defining_Identifier => Comm_Name,
3129 Object_Definition =>
3130 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3132 -- Some additional statements for protected entry calls
3134 -- Protected_Entry_Call (
3135 -- Object => po._object'Access,
3136 -- E => <entry index>;
3137 -- Uninterpreted_Data => P'Address;
3138 -- Mode => Simple_Call;
3142 Make_Procedure_Call_Statement (Loc,
3144 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3146 Parameter_Associations => New_List (
3147 Make_Attribute_Reference (Loc,
3148 Attribute_Name => Name_Unchecked_Access,
3152 New_Reference_To (RTE (RE_Simple_Call), Loc),
3153 New_Occurrence_Of (Comm_Name, Loc)));
3156 -- Protected_Single_Entry_Call (
3157 -- Object => po._object'Access,
3158 -- Uninterpreted_Data => P'Address;
3159 -- Mode => Simple_Call);
3162 Make_Procedure_Call_Statement (Loc,
3163 Name => New_Reference_To (
3164 RTE (RE_Protected_Single_Entry_Call), Loc),
3166 Parameter_Associations => New_List (
3167 Make_Attribute_Reference (Loc,
3168 Attribute_Name => Name_Unchecked_Access,
3171 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3174 -- Case of task type
3178 Make_Procedure_Call_Statement (Loc,
3179 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3180 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3184 Append_To (Stats, Call);
3186 -- If there are out or in/out parameters by copy add assignment
3187 -- statements for the result values.
3189 if Present (Parms) then
3190 Actual := First_Actual (N);
3191 Formal := First_Formal (Ent);
3193 Set_Assignment_OK (Actual);
3194 while Present (Actual) loop
3195 if Is_By_Copy_Type (Etype (Actual))
3196 and then Ekind (Formal) /= E_In_Parameter
3199 Make_Assignment_Statement (Loc,
3200 Name => New_Copy (Actual),
3202 Make_Explicit_Dereference (Loc,
3203 Make_Selected_Component (Loc,
3204 Prefix => New_Reference_To (P, Loc),
3206 Make_Identifier (Loc, Chars (Formal)))));
3208 -- In all cases (including limited private types) we want
3209 -- the assignment to be valid.
3211 Set_Assignment_OK (Name (N_Node));
3213 -- If the call is the triggering alternative in an
3214 -- asynchronous select, or the entry_call alternative of a
3215 -- conditional entry call, the assignments for in-out
3216 -- parameters are incorporated into the statement list that
3217 -- follows, so that there are executed only if the entry
3220 if (Nkind (Parent (N)) = N_Triggering_Alternative
3221 and then N = Triggering_Statement (Parent (N)))
3223 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3224 and then N = Entry_Call_Statement (Parent (N)))
3226 if No (Statements (Parent (N))) then
3227 Set_Statements (Parent (N), New_List);
3230 Prepend (N_Node, Statements (Parent (N)));
3233 Insert_After (Call, N_Node);
3237 Next_Actual (Actual);
3238 Next_Formal_With_Extras (Formal);
3242 -- Finally, create block and analyze it
3245 Make_Block_Statement (Loc,
3246 Declarations => Decls,
3247 Handled_Statement_Sequence =>
3248 Make_Handled_Sequence_Of_Statements (Loc,
3249 Statements => Stats)));
3253 end Build_Simple_Entry_Call;
3255 --------------------------------
3256 -- Build_Task_Activation_Call --
3257 --------------------------------
3259 procedure Build_Task_Activation_Call (N : Node_Id) is
3260 Loc : constant Source_Ptr := Sloc (N);
3267 -- Get the activation chain entity. Except in the case of a package
3268 -- body, this is in the node that was passed. For a package body, we
3269 -- have to find the corresponding package declaration node.
3271 if Nkind (N) = N_Package_Body then
3272 P := Corresponding_Spec (N);
3275 exit when Nkind (P) = N_Package_Declaration;
3278 Chain := Activation_Chain_Entity (P);
3281 Chain := Activation_Chain_Entity (N);
3284 if Present (Chain) then
3285 if Restricted_Profile then
3286 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3288 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3292 Make_Procedure_Call_Statement (Loc,
3294 Parameter_Associations =>
3295 New_List (Make_Attribute_Reference (Loc,
3296 Prefix => New_Occurrence_Of (Chain, Loc),
3297 Attribute_Name => Name_Unchecked_Access)));
3299 if Nkind (N) = N_Package_Declaration then
3300 if Present (Corresponding_Body (N)) then
3303 elsif Present (Private_Declarations (Specification (N))) then
3304 Append (Call, Private_Declarations (Specification (N)));
3307 Append (Call, Visible_Declarations (Specification (N)));
3311 if Present (Handled_Statement_Sequence (N)) then
3313 -- The call goes at the start of the statement sequence
3314 -- after the start of exception range label if one is present.
3320 Stm := First (Statements (Handled_Statement_Sequence (N)));
3322 -- A special case, skip exception range label if one is
3323 -- present (from front end zcx processing).
3325 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
3329 -- Another special case, if the first statement is a block
3330 -- from optimization of a local raise to a goto, then the
3331 -- call goes inside this block.
3333 if Nkind (Stm) = N_Block_Statement
3334 and then Exception_Junk (Stm)
3337 First (Statements (Handled_Statement_Sequence (Stm)));
3340 -- Insertion point is after any exception label pushes,
3341 -- since we want it covered by any local handlers.
3343 while Nkind (Stm) in N_Push_xxx_Label loop
3347 -- Now we have the proper insertion point
3349 Insert_Before (Stm, Call);
3353 Set_Handled_Statement_Sequence (N,
3354 Make_Handled_Sequence_Of_Statements (Loc,
3355 Statements => New_List (Call)));
3360 Check_Task_Activation (N);
3362 end Build_Task_Activation_Call;
3364 -------------------------------
3365 -- Build_Task_Allocate_Block --
3366 -------------------------------
3368 procedure Build_Task_Allocate_Block
3373 T : constant Entity_Id := Entity (Expression (N));
3374 Init : constant Entity_Id := Base_Init_Proc (T);
3375 Loc : constant Source_Ptr := Sloc (N);
3376 Chain : constant Entity_Id :=
3377 Make_Defining_Identifier (Loc, Name_uChain);
3383 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3386 Make_Block_Statement (Loc,
3387 Identifier => New_Reference_To (Blkent, Loc),
3388 Declarations => New_List (
3390 -- _Chain : Activation_Chain;
3392 Make_Object_Declaration (Loc,
3393 Defining_Identifier => Chain,
3394 Aliased_Present => True,
3395 Object_Definition =>
3396 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3398 Handled_Statement_Sequence =>
3399 Make_Handled_Sequence_Of_Statements (Loc,
3401 Statements => New_List (
3405 Make_Procedure_Call_Statement (Loc,
3406 Name => New_Reference_To (Init, Loc),
3407 Parameter_Associations => Args),
3409 -- Activate_Tasks (_Chain);
3411 Make_Procedure_Call_Statement (Loc,
3412 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3413 Parameter_Associations => New_List (
3414 Make_Attribute_Reference (Loc,
3415 Prefix => New_Reference_To (Chain, Loc),
3416 Attribute_Name => Name_Unchecked_Access))))),
3418 Has_Created_Identifier => True,
3419 Is_Task_Allocation_Block => True);
3422 Make_Implicit_Label_Declaration (Loc,
3423 Defining_Identifier => Blkent,
3424 Label_Construct => Block));
3426 Append_To (Actions, Block);
3428 Set_Activation_Chain_Entity (Block, Chain);
3429 end Build_Task_Allocate_Block;
3431 -----------------------------------------------
3432 -- Build_Task_Allocate_Block_With_Init_Stmts --
3433 -----------------------------------------------
3435 procedure Build_Task_Allocate_Block_With_Init_Stmts
3438 Init_Stmts : List_Id)
3440 Loc : constant Source_Ptr := Sloc (N);
3441 Chain : constant Entity_Id :=
3442 Make_Defining_Identifier (Loc, Name_uChain);
3447 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
3449 Append_To (Init_Stmts,
3450 Make_Procedure_Call_Statement (Loc,
3451 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
3452 Parameter_Associations => New_List (
3453 Make_Attribute_Reference (Loc,
3454 Prefix => New_Reference_To (Chain, Loc),
3455 Attribute_Name => Name_Unchecked_Access))));
3458 Make_Block_Statement (Loc,
3459 Identifier => New_Reference_To (Blkent, Loc),
3460 Declarations => New_List (
3462 -- _Chain : Activation_Chain;
3464 Make_Object_Declaration (Loc,
3465 Defining_Identifier => Chain,
3466 Aliased_Present => True,
3467 Object_Definition =>
3468 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
3470 Handled_Statement_Sequence =>
3471 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
3473 Has_Created_Identifier => True,
3474 Is_Task_Allocation_Block => True);
3477 Make_Implicit_Label_Declaration (Loc,
3478 Defining_Identifier => Blkent,
3479 Label_Construct => Block));
3481 Append_To (Actions, Block);
3483 Set_Activation_Chain_Entity (Block, Chain);
3484 end Build_Task_Allocate_Block_With_Init_Stmts;
3486 -----------------------------------
3487 -- Build_Task_Proc_Specification --
3488 -----------------------------------
3490 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
3491 Loc : constant Source_Ptr := Sloc (T);
3492 Nam : constant Name_Id := Chars (T);
3497 Make_Defining_Identifier (Loc,
3498 Chars => New_External_Name (Nam, 'B'));
3499 Set_Is_Internal (Ent);
3501 -- Associate the procedure with the task, if this is the declaration
3502 -- (and not the body) of the procedure.
3504 if No (Task_Body_Procedure (T)) then
3505 Set_Task_Body_Procedure (T, Ent);
3509 Make_Procedure_Specification (Loc,
3510 Defining_Unit_Name => Ent,
3511 Parameter_Specifications =>
3513 Make_Parameter_Specification (Loc,
3514 Defining_Identifier =>
3515 Make_Defining_Identifier (Loc, Name_uTask),
3517 Make_Access_Definition (Loc,
3520 (Corresponding_Record_Type (T), Loc)))));
3521 end Build_Task_Proc_Specification;
3523 ---------------------------------------
3524 -- Build_Unprotected_Subprogram_Body --
3525 ---------------------------------------
3527 function Build_Unprotected_Subprogram_Body
3529 Pid : Node_Id) return Node_Id
3531 Loc : constant Source_Ptr := Sloc (N);
3532 N_Op_Spec : Node_Id;
3536 -- Make an unprotected version of the subprogram for use within the same
3537 -- object, with a new name and an additional parameter representing the
3540 Op_Decls := Declarations (N);
3542 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode);
3545 Make_Subprogram_Body (Loc,
3546 Specification => N_Op_Spec,
3547 Declarations => Op_Decls,
3548 Handled_Statement_Sequence =>
3549 Handled_Statement_Sequence (N));
3550 end Build_Unprotected_Subprogram_Body;
3552 ----------------------------
3553 -- Collect_Entry_Families --
3554 ----------------------------
3556 procedure Collect_Entry_Families
3559 Current_Node : in out Node_Id;
3560 Conctyp : Entity_Id)
3563 Efam_Decl : Node_Id;
3564 Efam_Type : Entity_Id;
3567 Efam := First_Entity (Conctyp);
3569 while Present (Efam) loop
3571 if Ekind (Efam) = E_Entry_Family then
3573 Make_Defining_Identifier (Loc,
3574 Chars => New_Internal_Name ('F'));
3579 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
3580 Bas_Decl : Node_Id := Empty;
3585 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
3587 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
3589 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
3591 Make_Subtype_Declaration (Loc,
3592 Defining_Identifier => Bas,
3593 Subtype_Indication =>
3594 Make_Subtype_Indication (Loc,
3596 New_Occurrence_Of (Standard_Integer, Loc),
3598 Make_Range_Constraint (Loc,
3599 Range_Expression => Make_Range (Loc,
3600 Make_Integer_Literal
3601 (Loc, -Entry_Family_Bound),
3602 Make_Integer_Literal
3603 (Loc, Entry_Family_Bound - 1)))));
3605 Insert_After (Current_Node, Bas_Decl);
3606 Current_Node := Bas_Decl;
3611 Make_Full_Type_Declaration (Loc,
3612 Defining_Identifier => Efam_Type,
3614 Make_Unconstrained_Array_Definition (Loc,
3616 (New_List (New_Occurrence_Of (Bas, Loc))),
3618 Component_Definition =>
3619 Make_Component_Definition (Loc,
3620 Aliased_Present => False,
3621 Subtype_Indication =>
3622 New_Reference_To (Standard_Character, Loc))));
3625 Insert_After (Current_Node, Efam_Decl);
3626 Current_Node := Efam_Decl;
3627 Analyze (Efam_Decl);
3630 Make_Component_Declaration (Loc,
3631 Defining_Identifier =>
3632 Make_Defining_Identifier (Loc, Chars (Efam)),
3634 Component_Definition =>
3635 Make_Component_Definition (Loc,
3636 Aliased_Present => False,
3637 Subtype_Indication =>
3638 Make_Subtype_Indication (Loc,
3640 New_Occurrence_Of (Efam_Type, Loc),
3643 Make_Index_Or_Discriminant_Constraint (Loc,
3644 Constraints => New_List (
3646 (Etype (Discrete_Subtype_Definition
3647 (Parent (Efam))), Loc)))))));
3653 end Collect_Entry_Families;
3655 ----------------------
3656 -- Copy_Result_Type --
3657 ----------------------
3659 function Copy_Result_Type (Res : Node_Id) return Node_Id is
3660 New_Res : constant Node_Id := New_Copy_Tree (Res);
3665 -- If the result type is an access_to_subprogram, we must create
3666 -- new entities for its spec.
3668 if Nkind (New_Res) = N_Access_Definition
3669 and then Present (Access_To_Subprogram_Definition (New_Res))
3671 -- Provide new entities for the formals
3673 Par_Spec := First (Parameter_Specifications
3674 (Access_To_Subprogram_Definition (New_Res)));
3675 while Present (Par_Spec) loop
3676 Formal := Defining_Identifier (Par_Spec);
3677 Set_Defining_Identifier (Par_Spec,
3678 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
3684 end Copy_Result_Type;
3686 --------------------
3687 -- Concurrent_Ref --
3688 --------------------
3690 -- The expression returned for a reference to a concurrent object has the
3693 -- taskV!(name)._Task_Id
3697 -- objectV!(name)._Object
3699 -- for a protected object. For the case of an access to a concurrent
3700 -- object, there is an extra explicit dereference:
3702 -- taskV!(name.all)._Task_Id
3703 -- objectV!(name.all)._Object
3705 -- here taskV and objectV are the types for the associated records, which
3706 -- contain the required _Task_Id and _Object fields for tasks and protected
3707 -- objects, respectively.
3709 -- For the case of a task type name, the expression is
3713 -- i.e. a call to the Self function which returns precisely this Task_Id
3715 -- For the case of a protected type name, the expression is
3719 -- which is a renaming of the _object field of the current object object
3720 -- record, passed into protected operations as a parameter.
3722 function Concurrent_Ref (N : Node_Id) return Node_Id is
3723 Loc : constant Source_Ptr := Sloc (N);
3724 Ntyp : constant Entity_Id := Etype (N);
3728 function Is_Current_Task (T : Entity_Id) return Boolean;
3729 -- Check whether the reference is to the immediately enclosing task
3730 -- type, or to an outer one (rare but legal).
3732 ---------------------
3733 -- Is_Current_Task --
3734 ---------------------
3736 function Is_Current_Task (T : Entity_Id) return Boolean is
3740 Scop := Current_Scope;
3741 while Present (Scop)
3742 and then Scop /= Standard_Standard
3748 elsif Is_Task_Type (Scop) then
3751 -- If this is a procedure nested within the task type, we must
3752 -- assume that it can be called from an inner task, and therefore
3753 -- cannot treat it as a local reference.
3755 elsif Is_Overloadable (Scop)
3756 and then In_Open_Scopes (T)
3761 Scop := Scope (Scop);
3765 -- We know that we are within the task body, so should have found it
3768 raise Program_Error;
3769 end Is_Current_Task;
3771 -- Start of processing for Concurrent_Ref
3774 if Is_Access_Type (Ntyp) then
3775 Dtyp := Designated_Type (Ntyp);
3777 if Is_Protected_Type (Dtyp) then
3778 Sel := Name_uObject;
3780 Sel := Name_uTask_Id;
3784 Make_Selected_Component (Loc,
3786 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
3787 Make_Explicit_Dereference (Loc, N)),
3788 Selector_Name => Make_Identifier (Loc, Sel));
3790 elsif Is_Entity_Name (N)
3791 and then Is_Concurrent_Type (Entity (N))
3793 if Is_Task_Type (Entity (N)) then
3795 if Is_Current_Task (Entity (N)) then
3797 Make_Function_Call (Loc,
3798 Name => New_Reference_To (RTE (RE_Self), Loc));
3803 T_Self : constant Entity_Id :=
3804 Make_Defining_Identifier (Loc,
3805 Chars => New_Internal_Name ('T'));
3806 T_Body : constant Node_Id :=
3807 Parent (Corresponding_Body (Parent (Entity (N))));
3810 Decl := Make_Object_Declaration (Loc,
3811 Defining_Identifier => T_Self,
3812 Object_Definition =>
3813 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
3815 Make_Function_Call (Loc,
3816 Name => New_Reference_To (RTE (RE_Self), Loc)));
3817 Prepend (Decl, Declarations (T_Body));
3819 Set_Scope (T_Self, Entity (N));
3820 return New_Occurrence_Of (T_Self, Loc);
3825 pragma Assert (Is_Protected_Type (Entity (N)));
3828 Object_Ref (Corresponding_Body (Parent (Base_Type (Ntyp)))),
3833 if Is_Protected_Type (Ntyp) then
3834 Sel := Name_uObject;
3836 elsif Is_Task_Type (Ntyp) then
3837 Sel := Name_uTask_Id;
3840 raise Program_Error;
3844 Make_Selected_Component (Loc,
3846 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
3848 Selector_Name => Make_Identifier (Loc, Sel));
3852 ------------------------
3853 -- Convert_Concurrent --
3854 ------------------------
3856 function Convert_Concurrent
3858 Typ : Entity_Id) return Node_Id
3861 if not Is_Concurrent_Type (Typ) then
3865 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
3868 end Convert_Concurrent;
3870 ----------------------------
3871 -- Entry_Index_Expression --
3872 ----------------------------
3874 function Entry_Index_Expression
3878 Ttyp : Entity_Id) return Node_Id
3888 -- The queues of entries and entry families appear in textual order in
3889 -- the associated record. The entry index is computed as the sum of the
3890 -- number of queues for all entries that precede the designated one, to
3891 -- which is added the index expression, if this expression denotes a
3892 -- member of a family.
3894 -- The following is a place holder for the count of simple entries
3896 Num := Make_Integer_Literal (Sloc, 1);
3898 -- We construct an expression which is a series of addition operations.
3899 -- The first operand is the number of single entries that precede this
3900 -- one, the second operand is the index value relative to the start of
3901 -- the referenced family, and the remaining operands are the lengths of
3902 -- the entry families that precede this entry, i.e. the constructed
3905 -- number_simple_entries +
3906 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
3907 -- family'length + ...
3909 -- where index-value is the given index value, and s is the index
3910 -- subtype (we have to use pos because the subtype might be an
3911 -- enumeration type preventing direct subtraction). Note that the task
3912 -- entry array is one-indexed.
3914 -- The upper bound of the entry family may be a discriminant, so we
3915 -- retrieve the lower bound explicitly to compute offset, rather than
3916 -- using the index subtype which may mention a discriminant.
3918 if Present (Index) then
3919 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
3928 Make_Attribute_Reference (Sloc,
3929 Attribute_Name => Name_Pos,
3930 Prefix => New_Reference_To (Base_Type (S), Sloc),
3931 Expressions => New_List (Relocate_Node (Index))),
3939 -- Now add lengths of preceding entries and entry families
3941 Prev := First_Entity (Ttyp);
3943 while Chars (Prev) /= Chars (Ent)
3944 or else (Ekind (Prev) /= Ekind (Ent))
3945 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
3947 if Ekind (Prev) = E_Entry then
3948 Set_Intval (Num, Intval (Num) + 1);
3950 elsif Ekind (Prev) = E_Entry_Family then
3952 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
3953 Lo := Type_Low_Bound (S);
3954 Hi := Type_High_Bound (S);
3959 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
3961 -- Other components are anonymous types to be ignored
3971 end Entry_Index_Expression;
3973 ---------------------------
3974 -- Establish_Task_Master --
3975 ---------------------------
3977 procedure Establish_Task_Master (N : Node_Id) is
3980 if Restriction_Active (No_Task_Hierarchy) = False then
3981 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
3982 Prepend_To (Declarations (N), Call);
3985 end Establish_Task_Master;
3987 --------------------------------
3988 -- Expand_Accept_Declarations --
3989 --------------------------------
3991 -- Part of the expansion of an accept statement involves the creation of
3992 -- a declaration that can be referenced from the statement sequence of
3997 -- This declaration is inserted immediately before the accept statement
3998 -- and it is important that it be inserted before the statements of the
3999 -- statement sequence are analyzed. Thus it would be too late to create
4000 -- this declaration in the Expand_N_Accept_Statement routine, which is
4001 -- why there is a separate procedure to be called directly from Sem_Ch9.
4003 -- Ann is used to hold the address of the record containing the parameters
4004 -- (see Expand_N_Entry_Call for more details on how this record is built).
4005 -- References to the parameters do an unchecked conversion of this address
4006 -- to a pointer to the required record type, and then access the field that
4007 -- holds the value of the required parameter. The entity for the address
4008 -- variable is held as the top stack element (i.e. the last element) of the
4009 -- Accept_Address stack in the corresponding entry entity, and this element
4010 -- must be set in place before the statements are processed.
4012 -- The above description applies to the case of a stand alone accept
4013 -- statement, i.e. one not appearing as part of a select alternative.
4015 -- For the case of an accept that appears as part of a select alternative
4016 -- of a selective accept, we must still create the declaration right away,
4017 -- since Ann is needed immediately, but there is an important difference:
4019 -- The declaration is inserted before the selective accept, not before
4020 -- the accept statement (which is not part of a list anyway, and so would
4021 -- not accommodate inserted declarations)
4023 -- We only need one address variable for the entire selective accept. So
4024 -- the Ann declaration is created only for the first accept alternative,
4025 -- and subsequent accept alternatives reference the same Ann variable.
4027 -- We can distinguish the two cases by seeing whether the accept statement
4028 -- is part of a list. If not, then it must be in an accept alternative.
4030 -- To expand the requeue statement, a label is provided at the end of the
4031 -- accept statement or alternative of which it is a part, so that the
4032 -- statement can be skipped after the requeue is complete. This label is
4033 -- created here rather than during the expansion of the accept statement,
4034 -- because it will be needed by any requeue statements within the accept,
4035 -- which are expanded before the accept.
4037 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4038 Loc : constant Source_Ptr := Sloc (N);
4039 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4040 Ann : Entity_Id := Empty;
4048 if Expander_Active then
4050 -- If we have no handled statement sequence, we may need to build
4051 -- a dummy sequence consisting of a null statement. This can be
4052 -- skipped if the trivial accept optimization is permitted.
4054 if not Trivial_Accept_OK
4056 (No (Stats) or else Null_Statements (Statements (Stats)))
4058 Set_Handled_Statement_Sequence (N,
4059 Make_Handled_Sequence_Of_Statements (Loc,
4060 New_List (Make_Null_Statement (Loc))));
4063 -- Create and declare two labels to be placed at the end of the
4064 -- accept statement. The first label is used to allow requeues to
4065 -- skip the remainder of entry processing. The second label is used
4066 -- to skip the remainder of entry processing if the rendezvous
4067 -- completes in the middle of the accept body.
4069 if Present (Handled_Statement_Sequence (N)) then
4070 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4072 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4073 Lab := Make_Label (Loc, Lab_Id);
4075 Make_Implicit_Label_Declaration (Loc,
4076 Defining_Identifier => Entity (Lab_Id),
4077 Label_Construct => Lab);
4078 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4080 Lab_Id := Make_Identifier (Loc, New_Internal_Name ('L'));
4082 Make_Defining_Identifier (Loc, Chars (Lab_Id)));
4083 Lab := Make_Label (Loc, Lab_Id);
4085 Make_Implicit_Label_Declaration (Loc,
4086 Defining_Identifier => Entity (Lab_Id),
4087 Label_Construct => Lab);
4088 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4095 -- Case of stand alone accept statement
4097 if Is_List_Member (N) then
4099 if Present (Handled_Statement_Sequence (N)) then
4101 Make_Defining_Identifier (Loc,
4102 Chars => New_Internal_Name ('A'));
4105 Make_Object_Declaration (Loc,
4106 Defining_Identifier => Ann,
4107 Object_Definition =>
4108 New_Reference_To (RTE (RE_Address), Loc));
4110 Insert_Before (N, Adecl);
4113 Insert_Before (N, Ldecl);
4116 Insert_Before (N, Ldecl2);
4120 -- Case of accept statement which is in an accept alternative
4124 Acc_Alt : constant Node_Id := Parent (N);
4125 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4129 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4130 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4132 -- ??? Consider a single label for select statements
4134 if Present (Handled_Statement_Sequence (N)) then
4136 Statements (Handled_Statement_Sequence (N)));
4140 Statements (Handled_Statement_Sequence (N)));
4144 -- Find first accept alternative of the selective accept. A
4145 -- valid selective accept must have at least one accept in it.
4147 Alt := First (Select_Alternatives (Sel_Acc));
4149 while Nkind (Alt) /= N_Accept_Alternative loop
4153 -- If we are the first accept statement, then we have to create
4154 -- the Ann variable, as for the stand alone case, except that
4155 -- it is inserted before the selective accept. Similarly, a
4156 -- label for requeue expansion must be declared.
4158 if N = Accept_Statement (Alt) then
4160 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4163 Make_Object_Declaration (Loc,
4164 Defining_Identifier => Ann,
4165 Object_Definition =>
4166 New_Reference_To (RTE (RE_Address), Loc));
4168 Insert_Before (Sel_Acc, Adecl);
4171 -- If we are not the first accept statement, then find the Ann
4172 -- variable allocated by the first accept and use it.
4176 Node (Last_Elmt (Accept_Address
4177 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4182 -- Merge here with Ann either created or referenced, and Adecl
4183 -- pointing to the corresponding declaration. Remaining processing
4184 -- is the same for the two cases.
4186 if Present (Ann) then
4187 Append_Elmt (Ann, Accept_Address (Ent));
4188 Set_Needs_Debug_Info (Ann);
4191 -- Create renaming declarations for the entry formals. Each reference
4192 -- to a formal becomes a dereference of a component of the parameter
4193 -- block, whose address is held in Ann. These declarations are
4194 -- eventually inserted into the accept block, and analyzed there so
4195 -- that they have the proper scope for gdb and do not conflict with
4196 -- other declarations.
4198 if Present (Parameter_Specifications (N))
4199 and then Present (Handled_Statement_Sequence (N))
4209 Formal := First_Formal (Ent);
4211 while Present (Formal) loop
4212 Comp := Entry_Component (Formal);
4214 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
4216 Set_Etype (New_F, Etype (Formal));
4217 Set_Scope (New_F, Ent);
4218 Set_Needs_Debug_Info (New_F); -- That's the whole point.
4220 if Ekind (Formal) = E_In_Parameter then
4221 Set_Ekind (New_F, E_Constant);
4223 Set_Ekind (New_F, E_Variable);
4224 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4227 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4230 Make_Object_Renaming_Declaration (Loc,
4231 Defining_Identifier =>
4234 New_Reference_To (Etype (Formal), Loc),
4236 Make_Explicit_Dereference (Loc,
4237 Make_Selected_Component (Loc,
4239 Unchecked_Convert_To (
4240 Entry_Parameters_Type (Ent),
4241 New_Reference_To (Ann, Loc)),
4243 New_Reference_To (Comp, Loc))));
4245 if No (Declarations (N)) then
4246 Set_Declarations (N, New_List);
4249 Append (Decl, Declarations (N));
4250 Set_Renamed_Object (Formal, New_F);
4251 Next_Formal (Formal);
4258 end Expand_Accept_Declarations;
4260 ---------------------------------------------
4261 -- Expand_Access_Protected_Subprogram_Type --
4262 ---------------------------------------------
4264 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
4265 Loc : constant Source_Ptr := Sloc (N);
4267 T : constant Entity_Id := Defining_Identifier (N);
4268 D_T : constant Entity_Id := Designated_Type (T);
4269 D_T2 : constant Entity_Id := Make_Defining_Identifier (Loc,
4270 Chars => New_Internal_Name ('D'));
4271 E_T : constant Entity_Id := Make_Defining_Identifier (Loc,
4272 Chars => New_Internal_Name ('E'));
4273 P_List : constant List_Id := Build_Protected_Spec
4274 (N, RTE (RE_Address), False, D_T);
4280 -- Create access to protected subprogram with full signature
4282 if Nkind (Type_Definition (N)) = N_Access_Function_Definition then
4284 Make_Access_Function_Definition (Loc,
4285 Parameter_Specifications => P_List,
4286 Result_Definition =>
4287 Copy_Result_Type (Result_Definition (Type_Definition (N))));
4291 Make_Access_Procedure_Definition (Loc,
4292 Parameter_Specifications => P_List);
4296 Make_Full_Type_Declaration (Loc,
4297 Defining_Identifier => D_T2,
4298 Type_Definition => Def1);
4301 Insert_After (N, Decl1);
4303 -- Create Equivalent_Type, a record with two components for an access to
4304 -- object and an access to subprogram.
4307 Make_Component_Declaration (Loc,
4308 Defining_Identifier =>
4309 Make_Defining_Identifier (Loc, New_Internal_Name ('P')),
4310 Component_Definition =>
4311 Make_Component_Definition (Loc,
4312 Aliased_Present => False,
4313 Subtype_Indication =>
4314 New_Occurrence_Of (RTE (RE_Address), Loc))),
4316 Make_Component_Declaration (Loc,
4317 Defining_Identifier =>
4318 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
4319 Component_Definition =>
4320 Make_Component_Definition (Loc,
4321 Aliased_Present => False,
4322 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
4325 Make_Full_Type_Declaration (Loc,
4326 Defining_Identifier => E_T,
4328 Make_Record_Definition (Loc,
4330 Make_Component_List (Loc,
4331 Component_Items => Comps)));
4334 Insert_After (Decl1, Decl2);
4335 Set_Equivalent_Type (T, E_T);
4336 end Expand_Access_Protected_Subprogram_Type;
4338 --------------------------
4339 -- Expand_Entry_Barrier --
4340 --------------------------
4342 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
4343 Loc : constant Source_Ptr := Sloc (N);
4344 Prot : constant Entity_Id := Scope (Ent);
4345 Spec_Decl : constant Node_Id := Parent (Prot);
4346 Cond : constant Node_Id :=
4347 Condition (Entry_Body_Formal_Part (N));
4350 Body_Decl : Node_Id;
4353 if No_Run_Time_Mode then
4354 Error_Msg_CRT ("entry barrier", N);
4358 -- The body of the entry barrier must be analyzed in the context of the
4359 -- protected object, but its scope is external to it, just as any other
4360 -- unprotected version of a protected operation. The specification has
4361 -- been produced when the protected type declaration was elaborated. We
4362 -- build the body, insert it in the enclosing scope, but analyze it in
4363 -- the current context. A more uniform approach would be to treat
4364 -- barrier just as a protected function, and discard the protected
4365 -- version of it because it is never called.
4367 if Expander_Active then
4368 B_F := Build_Barrier_Function (N, Ent, Prot);
4369 Func := Barrier_Function (Ent);
4370 Set_Corresponding_Spec (B_F, Func);
4372 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
4374 if Nkind (Parent (Body_Decl)) = N_Subunit then
4375 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
4378 Insert_Before_And_Analyze (Body_Decl, B_F);
4380 Update_Prival_Subtypes (B_F);
4382 Set_Privals (Spec_Decl, N, Loc, After_Barrier => True);
4383 Set_Discriminals (Spec_Decl);
4384 Set_Scope (Func, Scope (Prot));
4387 Analyze_And_Resolve (Cond, Any_Boolean);
4390 -- The Ravenscar profile restricts barriers to simple variables declared
4391 -- within the protected object. We also allow Boolean constants, since
4392 -- these appear in several published examples and are also allowed by
4393 -- the Aonix compiler.
4395 -- Note that after analysis variables in this context will be replaced
4396 -- by the corresponding prival, that is to say a renaming of a selected
4397 -- component of the form _Object.Var. If expansion is disabled, as
4398 -- within a generic, we check that the entity appears in the current
4401 if Is_Entity_Name (Cond) then
4403 -- A small optimization of useless renamings. If the scope of the
4404 -- entity of the condition is not the barrier function, then the
4405 -- condition does not reference any of the generated renamings
4406 -- within the function.
4409 and then Scope (Entity (Cond)) /= Func
4411 Set_Declarations (B_F, Empty_List);
4414 if Entity (Cond) = Standard_False
4416 Entity (Cond) = Standard_True
4420 elsif not Expander_Active
4421 and then Scope (Entity (Cond)) = Current_Scope
4425 -- Check for case of _object.all.field (note that the explicit
4426 -- dereference gets inserted by analyze/expand of _object.field)
4428 elsif Present (Renamed_Object (Entity (Cond)))
4430 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
4434 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
4440 -- It is not a boolean variable or literal, so check the restriction
4442 Check_Restriction (Simple_Barriers, Cond);
4443 end Expand_Entry_Barrier;
4445 ------------------------------------
4446 -- Expand_Entry_Body_Declarations --
4447 ------------------------------------
4449 procedure Expand_Entry_Body_Declarations (N : Node_Id) is
4450 Loc : constant Source_Ptr := Sloc (N);
4451 Index_Spec : Node_Id;
4454 if Expander_Active then
4456 -- Expand entry bodies corresponding to entry families
4457 -- by assigning a placeholder for the constant that will
4458 -- be used to expand references to the entry index parameter.
4461 Entry_Index_Specification (Entry_Body_Formal_Part (N));
4463 if Present (Index_Spec) then
4465 Index_Con : constant Entity_Id :=
4466 Make_Defining_Identifier (Loc,
4467 Chars => New_Internal_Name ('J'));
4469 -- Mark the index constant as having a valid value since it
4470 -- will act as a renaming of the original entry index which
4471 -- is known to be valid.
4473 Set_Is_Known_Valid (Index_Con);
4475 Set_Entry_Index_Constant
4476 (Defining_Identifier (Index_Spec), Index_Con);
4480 end Expand_Entry_Body_Declarations;
4482 ------------------------------
4483 -- Expand_N_Abort_Statement --
4484 ------------------------------
4486 -- Expand abort T1, T2, .. Tn; into:
4487 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
4489 procedure Expand_N_Abort_Statement (N : Node_Id) is
4490 Loc : constant Source_Ptr := Sloc (N);
4491 Tlist : constant List_Id := Names (N);
4497 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
4500 Tasknm := First (Tlist);
4502 while Present (Tasknm) loop
4505 -- A task interface class-wide type object is being aborted.
4506 -- Retrieve its _task_id by calling a dispatching routine.
4508 if Ada_Version >= Ada_05
4509 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
4510 and then Is_Interface (Etype (Tasknm))
4511 and then Is_Task_Interface (Etype (Tasknm))
4513 Append_To (Component_Associations (Aggr),
4514 Make_Component_Association (Loc,
4515 Choices => New_List (
4516 Make_Integer_Literal (Loc, Count)),
4519 -- Task_Id (Tasknm._disp_get_task_id)
4521 Make_Unchecked_Type_Conversion (Loc,
4523 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
4525 Make_Selected_Component (Loc,
4527 New_Copy_Tree (Tasknm),
4529 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
4532 Append_To (Component_Associations (Aggr),
4533 Make_Component_Association (Loc,
4534 Choices => New_List (
4535 Make_Integer_Literal (Loc, Count)),
4536 Expression => Concurrent_Ref (Tasknm)));
4543 Make_Procedure_Call_Statement (Loc,
4544 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
4545 Parameter_Associations => New_List (
4546 Make_Qualified_Expression (Loc,
4547 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
4548 Expression => Aggr))));
4551 end Expand_N_Abort_Statement;
4553 -------------------------------
4554 -- Expand_N_Accept_Statement --
4555 -------------------------------
4557 -- This procedure handles expansion of accept statements that stand
4558 -- alone, i.e. they are not part of an accept alternative. The expansion
4559 -- of accept statement in accept alternatives is handled by the routines
4560 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
4561 -- following description applies only to stand alone accept statements.
4563 -- If there is no handled statement sequence, or only null statements,
4564 -- then this is called a trivial accept, and the expansion is:
4566 -- Accept_Trivial (entry-index)
4568 -- If there is a handled statement sequence, then the expansion is:
4575 -- Accept_Call (entry-index, Ann);
4576 -- Renaming_Declarations for formals
4577 -- <statement sequence from N_Accept_Statement node>
4578 -- Complete_Rendezvous;
4583 -- <exception handler from N_Accept_Statement node>
4584 -- Complete_Rendezvous;
4586 -- <exception handler from N_Accept_Statement node>
4587 -- Complete_Rendezvous;
4592 -- when all others =>
4593 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
4596 -- The first three declarations were already inserted ahead of the accept
4597 -- statement by the Expand_Accept_Declarations procedure, which was called
4598 -- directly from the semantics during analysis of the accept statement,
4599 -- before analyzing its contained statements.
4601 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
4602 -- from possible expansion activity (the original source of course does
4603 -- not have any declarations associated with the accept statement, since
4604 -- an accept statement has no declarative part). In particular, if the
4605 -- expander is active, the first such declaration is the declaration of
4606 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
4608 -- The two blocks are merged into a single block if the inner block has
4609 -- no exception handlers, but otherwise two blocks are required, since
4610 -- exceptions might be raised in the exception handlers of the inner
4611 -- block, and Exceptional_Complete_Rendezvous must be called.
4613 procedure Expand_N_Accept_Statement (N : Node_Id) is
4614 Loc : constant Source_Ptr := Sloc (N);
4615 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4616 Ename : constant Node_Id := Entry_Direct_Name (N);
4617 Eindx : constant Node_Id := Entry_Index (N);
4618 Eent : constant Entity_Id := Entity (Ename);
4619 Acstack : constant Elist_Id := Accept_Address (Eent);
4620 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
4621 Ttyp : constant Entity_Id := Etype (Scope (Eent));
4626 -- Start of processing for Expand_N_Accept_Statement
4629 -- If accept statement is not part of a list, then its parent must be
4630 -- an accept alternative, and, as described above, we do not do any
4631 -- expansion for such accept statements at this level.
4633 if not Is_List_Member (N) then
4634 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
4637 -- Trivial accept case (no statement sequence, or null statements).
4638 -- If the accept statement has declarations, then just insert them
4639 -- before the procedure call.
4641 elsif Trivial_Accept_OK
4642 and then (No (Stats) or else Null_Statements (Statements (Stats)))
4644 -- Remove declarations for renamings, because the parameter block
4645 -- will not be assigned.
4652 D := First (Declarations (N));
4654 while Present (D) loop
4656 if Nkind (D) = N_Object_Renaming_Declaration then
4664 if Present (Declarations (N)) then
4665 Insert_Actions (N, Declarations (N));
4669 Make_Procedure_Call_Statement (Loc,
4670 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
4671 Parameter_Associations => New_List (
4672 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
4676 -- Discard Entry_Address that was created for it, so it will not be
4677 -- emitted if this accept statement is in the statement part of a
4678 -- delay alternative.
4680 if Present (Stats) then
4681 Remove_Last_Elmt (Acstack);
4684 -- Case of statement sequence present
4687 -- Construct the block, using the declarations from the accept
4688 -- statement if any to initialize the declarations of the block.
4690 Blkent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
4691 Set_Ekind (Blkent, E_Block);
4692 Set_Etype (Blkent, Standard_Void_Type);
4693 Set_Scope (Blkent, Current_Scope);
4696 Make_Block_Statement (Loc,
4697 Identifier => New_Reference_To (Blkent, Loc),
4698 Declarations => Declarations (N),
4699 Handled_Statement_Sequence => Build_Accept_Body (N));
4701 -- Prepend call to Accept_Call to main statement sequence If the
4702 -- accept has exception handlers, the statement sequence is wrapped
4703 -- in a block. Insert call and renaming declarations in the
4704 -- declarations of the block, so they are elaborated before the
4708 Make_Procedure_Call_Statement (Loc,
4709 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
4710 Parameter_Associations => New_List (
4711 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
4712 New_Reference_To (Ann, Loc)));
4714 if Parent (Stats) = N then
4715 Prepend (Call, Statements (Stats));
4724 Push_Scope (Blkent);
4732 D := First (Declarations (N));
4733 while Present (D) loop
4736 if Nkind (D) = N_Object_Renaming_Declaration then
4738 -- The renaming declarations for the formals were created
4739 -- during analysis of the accept statement, and attached to
4740 -- the list of declarations. Place them now in the context
4741 -- of the accept block or subprogram.
4744 Typ := Entity (Subtype_Mark (D));
4745 Insert_After (Call, D);
4748 -- If the formal is class_wide, it does not have an actual
4749 -- subtype. The analysis of the renaming declaration creates
4750 -- one, but we need to retain the class-wide nature of the
4753 if Is_Class_Wide_Type (Typ) then
4754 Set_Etype (Defining_Identifier (D), Typ);
4765 -- Replace the accept statement by the new block
4770 -- Last step is to unstack the Accept_Address value
4772 Remove_Last_Elmt (Acstack);
4774 end Expand_N_Accept_Statement;
4776 ----------------------------------
4777 -- Expand_N_Asynchronous_Select --
4778 ----------------------------------
4780 -- This procedure assumes that the trigger statement is an entry call or
4781 -- a dispatching procedure call. A delay alternative should already have
4782 -- been expanded into an entry call to the appropriate delay object Wait
4785 -- If the trigger is a task entry call, the select is implemented with
4786 -- a Task_Entry_Call:
4791 -- P : parms := (parm, parm, parm);
4793 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
4795 -- procedure _clean is
4798 -- Cancel_Task_Entry_Call (C);
4805 -- (<acceptor-task>, -- Acceptor
4806 -- <entry-index>, -- E
4807 -- P'Address, -- Uninterpreted_Data
4808 -- Asynchronous_Call, -- Mode
4809 -- B); -- Rendezvous_Successful
4816 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
4819 -- when Abort_Signal => Abort_Undefer;
4826 -- <triggered-statements>
4830 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
4831 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
4835 -- P : parms := (parm, parm, parm);
4837 -- Call_Simple (acceptor-task, entry-index, P'Address);
4843 -- so the task at hand is to convert the latter expansion into the former
4845 -- If the trigger is a protected entry call, the select is implemented
4846 -- with Protected_Entry_Call:
4849 -- P : E1_Params := (param, param, param);
4850 -- Bnn : Communications_Block;
4855 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
4857 -- procedure _clean is
4860 -- if Enqueued (Bnn) then
4861 -- Cancel_Protected_Entry_Call (Bnn);
4868 -- Protected_Entry_Call
4869 -- (po._object'Access, -- Object
4870 -- <entry index>, -- E
4871 -- P'Address, -- Uninterpreted_Data
4872 -- Asynchronous_Call, -- Mode
4875 -- if Enqueued (Bnn) then
4879 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
4882 -- when Abort_Signal => Abort_Undefer;
4885 -- if not Cancelled (Bnn) then
4886 -- <triggered-statements>
4890 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
4894 -- P : E1_Params := (param, param, param);
4895 -- Bnn : Communications_Block;
4898 -- Protected_Entry_Call
4899 -- (po._object'Access, -- Object
4900 -- <entry index>, -- E
4901 -- P'Address, -- Uninterpreted_Data
4902 -- Simple_Call, -- Mode
4909 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
4913 -- B : Boolean := False;
4914 -- Bnn : Communication_Block;
4915 -- C : Ada.Tags.Prim_Op_Kind;
4916 -- D : System.Storage_Elements.Dummy_Communication_Block;
4917 -- K : Ada.Tags.Tagged_Kind :=
4918 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
4919 -- P : Parameters := (Param1 .. ParamN);
4924 -- if K = Ada.Tags.TK_Limited_Tagged then
4925 -- <dispatching-call>;
4926 -- <triggering-statements>;
4930 -- Ada.Tags.Get_Offset_Index
4931 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
4933 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
4935 -- if C = POK_Protected_Entry then
4937 -- procedure _clean is
4939 -- if Enqueued (Bnn) then
4940 -- Cancel_Protected_Entry_Call (Bnn);
4946 -- _Disp_Asynchronous_Select
4947 -- (<object>, S, P'Address, D, B);
4948 -- Bnn := Communication_Block (D);
4950 -- Param1 := P.Param1;
4952 -- ParamN := P.ParamN;
4954 -- if Enqueued (Bnn) then
4955 -- <abortable-statements>
4958 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
4961 -- when Abort_Signal => Abort_Undefer;
4964 -- if not Cancelled (Bnn) then
4965 -- <triggering-statements>
4968 -- elsif C = POK_Task_Entry then
4970 -- procedure _clean is
4972 -- Cancel_Task_Entry_Call (U);
4978 -- _Disp_Asynchronous_Select
4979 -- (<object>, S, P'Address, D, B);
4980 -- Bnn := Communication_Bloc (D);
4982 -- Param1 := P.Param1;
4984 -- ParamN := P.ParamN;
4989 -- <abortable-statements>
4991 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
4994 -- when Abort_Signal => Abort_Undefer;
4998 -- <triggering-statements>
5003 -- <dispatching-call>;
5004 -- <triggering-statements>
5009 -- The job is to convert this to the asynchronous form
5011 -- If the trigger is a delay statement, it will have been expanded into a
5012 -- call to one of the GNARL delay procedures. This routine will convert
5013 -- this into a protected entry call on a delay object and then continue
5014 -- processing as for a protected entry call trigger. This requires
5015 -- declaring a Delay_Block object and adding a pointer to this object to
5016 -- the parameter list of the delay procedure to form the parameter list of
5017 -- the entry call. This object is used by the runtime to queue the delay
5020 -- For a description of the use of P and the assignments after the call,
5021 -- see Expand_N_Entry_Call_Statement.
5023 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5024 Loc : constant Source_Ptr := Sloc (N);
5025 Abrt : constant Node_Id := Abortable_Part (N);
5026 Astats : constant List_Id := Statements (Abrt);
5027 Trig : constant Node_Id := Triggering_Alternative (N);
5028 Tstats : constant List_Id := Statements (Trig);
5030 Abort_Block_Ent : Entity_Id;
5031 Abortable_Block : Node_Id;
5033 Blk_Ent : Entity_Id;
5034 Blk_Typ : Entity_Id;
5036 Call_Ent : Entity_Id;
5037 Cancel_Param : Entity_Id;
5038 Cleanup_Block : Node_Id;
5039 Cleanup_Block_Ent : Entity_Id;
5040 Cleanup_Stmts : List_Id;
5041 Conc_Typ_Stmts : List_Id;
5043 Dblock_Ent : Entity_Id;
5048 Enqueue_Call : Node_Id;
5052 Lim_Typ_Stmts : List_Id;
5058 ProtE_Stmts : List_Id;
5059 ProtP_Stmts : List_Id;
5062 Target_Undefer : RE_Id;
5063 TaskE_Stmts : List_Id;
5064 Undefer_Args : List_Id := No_List;
5066 B : Entity_Id; -- Call status flag
5067 Bnn : Entity_Id; -- Communication block
5068 C : Entity_Id; -- Call kind
5069 K : Entity_Id; -- Tagged kind
5070 P : Entity_Id; -- Parameter block
5071 S : Entity_Id; -- Primitive operation slot
5072 T : Entity_Id; -- Additional status flag
5075 Blk_Ent := Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5076 Ecall := Triggering_Statement (Trig);
5078 -- The arguments in the call may require dynamic allocation, and the
5079 -- call statement may have been transformed into a block. The block
5080 -- may contain additional declarations for internal entities, and the
5081 -- original call is found by sequential search.
5083 if Nkind (Ecall) = N_Block_Statement then
5084 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5085 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5086 N_Entry_Call_Statement)
5092 -- This is either a dispatching call or a delay statement used as a
5093 -- trigger which was expanded into a procedure call.
5095 if Nkind (Ecall) = N_Procedure_Call_Statement then
5096 if Ada_Version >= Ada_05
5098 (No (Original_Node (Ecall))
5099 or else not Nkind_In (Original_Node (Ecall),
5100 N_Delay_Relative_Statement,
5101 N_Delay_Until_Statement))
5103 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5108 -- Call status flag processing, generate:
5109 -- B : Boolean := False;
5111 B := Build_B (Loc, Decls);
5113 -- Communication block processing, generate:
5114 -- Bnn : Communication_Block;
5116 Bnn := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
5119 Make_Object_Declaration (Loc,
5120 Defining_Identifier =>
5122 Object_Definition =>
5123 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5125 -- Call kind processing, generate:
5126 -- C : Ada.Tags.Prim_Op_Kind;
5128 C := Build_C (Loc, Decls);
5130 -- Tagged kind processing, generate:
5131 -- K : Ada.Tags.Tagged_Kind :=
5132 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5134 -- Dummy communication block, generate:
5135 -- D : Dummy_Communication_Block;
5138 Make_Object_Declaration (Loc,
5139 Defining_Identifier =>
5140 Make_Defining_Identifier (Loc, Name_uD),
5141 Object_Definition =>
5143 RTE (RE_Dummy_Communication_Block), Loc)));
5145 K := Build_K (Loc, Decls, Obj);
5147 -- Parameter block processing
5149 Blk_Typ := Build_Parameter_Block
5150 (Loc, Actuals, Formals, Decls);
5151 P := Parameter_Block_Pack
5152 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5154 -- Dispatch table slot processing, generate:
5157 S := Build_S (Loc, Decls);
5159 -- Additional status flag processing, generate:
5161 T := Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
5164 Make_Object_Declaration (Loc,
5165 Defining_Identifier =>
5167 Object_Definition =>
5168 New_Reference_To (Standard_Boolean, Loc)));
5170 ------------------------------
5171 -- Protected entry handling --
5172 ------------------------------
5175 -- Param1 := P.Param1;
5177 -- ParamN := P.ParamN;
5179 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5182 -- Bnn := Communication_Block (D);
5184 Prepend_To (Cleanup_Stmts,
5185 Make_Assignment_Statement (Loc,
5187 New_Reference_To (Bnn, Loc),
5189 Make_Unchecked_Type_Conversion (Loc,
5191 New_Reference_To (RTE (RE_Communication_Block), Loc),
5193 Make_Identifier (Loc, Name_uD))));
5196 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5198 Prepend_To (Cleanup_Stmts,
5199 Make_Procedure_Call_Statement (Loc,
5202 Find_Prim_Op (Etype (Etype (Obj)),
5203 Name_uDisp_Asynchronous_Select),
5205 Parameter_Associations =>
5207 New_Copy_Tree (Obj), -- <object>
5208 New_Reference_To (S, Loc), -- S
5209 Make_Attribute_Reference (Loc, -- P'Address
5211 New_Reference_To (P, Loc),
5214 Make_Identifier (Loc, Name_uD), -- D
5215 New_Reference_To (B, Loc)))); -- B
5218 -- if Enqueued (Bnn) then
5219 -- <abortable-statements>
5222 Append_To (Cleanup_Stmts,
5223 Make_If_Statement (Loc,
5225 Make_Function_Call (Loc,
5227 New_Reference_To (RTE (RE_Enqueued), Loc),
5228 Parameter_Associations =>
5230 New_Reference_To (Bnn, Loc))),
5233 New_Copy_List_Tree (Astats)));
5235 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5236 -- will then generate a _clean for the communication block Bnn.
5240 -- procedure _clean is
5242 -- if Enqueued (Bnn) then
5243 -- Cancel_Protected_Entry_Call (Bnn);
5252 Cleanup_Block_Ent :=
5253 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5256 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5258 -- Wrap the cleanup block in an exception handling block
5264 -- when Abort_Signal => Abort_Undefer;
5268 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5272 Make_Implicit_Label_Declaration (Loc,
5273 Defining_Identifier =>
5277 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5280 -- if not Cancelled (Bnn) then
5281 -- <triggering-statements>
5284 Append_To (ProtE_Stmts,
5285 Make_If_Statement (Loc,
5289 Make_Function_Call (Loc,
5291 New_Reference_To (RTE (RE_Cancelled), Loc),
5292 Parameter_Associations =>
5294 New_Reference_To (Bnn, Loc)))),
5297 New_Copy_List_Tree (Tstats)));
5299 -------------------------
5300 -- Task entry handling --
5301 -------------------------
5304 -- Param1 := P.Param1;
5306 -- ParamN := P.ParamN;
5308 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5311 -- Bnn := Communication_Block (D);
5313 Append_To (TaskE_Stmts,
5314 Make_Assignment_Statement (Loc,
5316 New_Reference_To (Bnn, Loc),
5318 Make_Unchecked_Type_Conversion (Loc,
5320 New_Reference_To (RTE (RE_Communication_Block), Loc),
5322 Make_Identifier (Loc, Name_uD))));
5325 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5327 Prepend_To (TaskE_Stmts,
5328 Make_Procedure_Call_Statement (Loc,
5331 Find_Prim_Op (Etype (Etype (Obj)),
5332 Name_uDisp_Asynchronous_Select),
5334 Parameter_Associations =>
5336 New_Copy_Tree (Obj), -- <object>
5337 New_Reference_To (S, Loc), -- S
5338 Make_Attribute_Reference (Loc, -- P'Address
5340 New_Reference_To (P, Loc),
5343 Make_Identifier (Loc, Name_uD), -- D
5344 New_Reference_To (B, Loc)))); -- B
5349 Prepend_To (TaskE_Stmts,
5350 Make_Procedure_Call_Statement (Loc,
5352 New_Reference_To (RTE (RE_Abort_Defer), Loc),
5353 Parameter_Associations =>
5358 -- <abortable-statements>
5360 Cleanup_Stmts := New_Copy_List_Tree (Astats);
5362 Prepend_To (Cleanup_Stmts,
5363 Make_Procedure_Call_Statement (Loc,
5365 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
5366 Parameter_Associations =>
5369 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5370 -- will generate a _clean for the additional status flag.
5374 -- procedure _clean is
5376 -- Cancel_Task_Entry_Call (U);
5384 Cleanup_Block_Ent :=
5385 Make_Defining_Identifier (Loc, New_Internal_Name ('C'));
5388 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
5390 -- Wrap the cleanup block in an exception handling block
5396 -- when Abort_Signal => Abort_Undefer;
5400 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
5402 Append_To (TaskE_Stmts,
5403 Make_Implicit_Label_Declaration (Loc,
5404 Defining_Identifier =>
5407 Append_To (TaskE_Stmts,
5409 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5413 -- <triggering-statements>
5416 Append_To (TaskE_Stmts,
5417 Make_If_Statement (Loc,
5421 New_Reference_To (T, Loc)),
5424 New_Copy_List_Tree (Tstats)));
5426 ----------------------------------
5427 -- Protected procedure handling --
5428 ----------------------------------
5431 -- <dispatching-call>;
5432 -- <triggering-statements>
5434 ProtP_Stmts := New_Copy_List_Tree (Tstats);
5435 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
5438 -- S := Ada.Tags.Get_Offset_Index
5439 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
5442 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
5445 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5447 Append_To (Conc_Typ_Stmts,
5448 Make_Procedure_Call_Statement (Loc,
5451 Find_Prim_Op (Etype (Etype (Obj)),
5452 Name_uDisp_Get_Prim_Op_Kind),
5454 Parameter_Associations =>
5456 New_Copy_Tree (Obj),
5457 New_Reference_To (S, Loc),
5458 New_Reference_To (C, Loc))));
5461 -- if C = POK_Procedure_Entry then
5463 -- elsif C = POK_Task_Entry then
5469 Append_To (Conc_Typ_Stmts,
5470 Make_If_Statement (Loc,
5474 New_Reference_To (C, Loc),
5476 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
5483 Make_Elsif_Part (Loc,
5487 New_Reference_To (C, Loc),
5489 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
5498 -- <dispatching-call>;
5499 -- <triggering-statements>
5501 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
5502 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
5505 -- if K = Ada.Tags.TK_Limited_Tagged then
5512 Make_If_Statement (Loc,
5516 New_Reference_To (K, Loc),
5518 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
5527 Make_Block_Statement (Loc,
5530 Handled_Statement_Sequence =>
5531 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5536 -- Delay triggering statement processing
5539 -- Add a Delay_Block object to the parameter list of the delay
5540 -- procedure to form the parameter list of the Wait entry call.
5543 Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
5545 Pdef := Entity (Name (Ecall));
5547 if Is_RTE (Pdef, RO_CA_Delay_For) then
5549 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
5551 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
5553 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
5555 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
5556 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
5559 Append_To (Parameter_Associations (Ecall),
5560 Make_Attribute_Reference (Loc,
5561 Prefix => New_Reference_To (Dblock_Ent, Loc),
5562 Attribute_Name => Name_Unchecked_Access));
5564 -- Create the inner block to protect the abortable part
5567 Make_Implicit_Exception_Handler (Loc,
5568 Exception_Choices =>
5569 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5570 Statements => New_List (
5571 Make_Procedure_Call_Statement (Loc,
5572 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
5575 Make_Procedure_Call_Statement (Loc,
5576 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
5579 Make_Block_Statement (Loc,
5580 Identifier => New_Reference_To (Blk_Ent, Loc),
5581 Handled_Statement_Sequence =>
5582 Make_Handled_Sequence_Of_Statements (Loc,
5583 Statements => Astats),
5584 Has_Created_Identifier => True,
5585 Is_Asynchronous_Call_Block => True);
5587 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
5590 Make_Implicit_If_Statement (N,
5591 Condition => Make_Function_Call (Loc,
5592 Name => Enqueue_Call,
5593 Parameter_Associations => Parameter_Associations (Ecall)),
5595 New_List (Make_Block_Statement (Loc,
5596 Handled_Statement_Sequence =>
5597 Make_Handled_Sequence_Of_Statements (Loc,
5598 Statements => New_List (
5599 Make_Implicit_Label_Declaration (Loc,
5600 Defining_Identifier => Blk_Ent,
5601 Label_Construct => Abortable_Block),
5603 Exception_Handlers => Hdle)))));
5605 Stmts := New_List (Ecall);
5607 -- Construct statement sequence for new block
5610 Make_Implicit_If_Statement (N,
5611 Condition => Make_Function_Call (Loc,
5612 Name => New_Reference_To (
5613 RTE (RE_Timed_Out), Loc),
5614 Parameter_Associations => New_List (
5615 Make_Attribute_Reference (Loc,
5616 Prefix => New_Reference_To (Dblock_Ent, Loc),
5617 Attribute_Name => Name_Unchecked_Access))),
5618 Then_Statements => Tstats));
5620 -- The result is the new block
5622 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
5625 Make_Block_Statement (Loc,
5626 Declarations => New_List (
5627 Make_Object_Declaration (Loc,
5628 Defining_Identifier => Dblock_Ent,
5629 Aliased_Present => True,
5630 Object_Definition => New_Reference_To (
5631 RTE (RE_Delay_Block), Loc))),
5633 Handled_Statement_Sequence =>
5634 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5644 Extract_Entry (Ecall, Concval, Ename, Index);
5645 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
5647 Stmts := Statements (Handled_Statement_Sequence (Ecall));
5648 Decls := Declarations (Ecall);
5650 if Is_Protected_Type (Etype (Concval)) then
5652 -- Get the declarations of the block expanded from the entry call
5654 Decl := First (Decls);
5655 while Present (Decl)
5657 (Nkind (Decl) /= N_Object_Declaration
5658 or else not Is_RTE (Etype (Object_Definition (Decl)),
5659 RE_Communication_Block))
5664 pragma Assert (Present (Decl));
5665 Cancel_Param := Defining_Identifier (Decl);
5667 -- Change the mode of the Protected_Entry_Call call
5669 -- Protected_Entry_Call (
5670 -- Object => po._object'Access,
5671 -- E => <entry index>;
5672 -- Uninterpreted_Data => P'Address;
5673 -- Mode => Asynchronous_Call;
5676 Stmt := First (Stmts);
5678 -- Skip assignments to temporaries created for in-out parameters
5680 -- This makes unwarranted assumptions about the shape of the expanded
5681 -- tree for the call, and should be cleaned up ???
5683 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
5689 Param := First (Parameter_Associations (Call));
5690 while Present (Param)
5691 and then not Is_RTE (Etype (Param), RE_Call_Modes)
5696 pragma Assert (Present (Param));
5697 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
5700 -- Append an if statement to execute the abortable part
5703 -- if Enqueued (Bnn) then
5706 Make_Implicit_If_Statement (N,
5707 Condition => Make_Function_Call (Loc,
5708 Name => New_Reference_To (
5709 RTE (RE_Enqueued), Loc),
5710 Parameter_Associations => New_List (
5711 New_Reference_To (Cancel_Param, Loc))),
5712 Then_Statements => Astats));
5715 Make_Block_Statement (Loc,
5716 Identifier => New_Reference_To (Blk_Ent, Loc),
5717 Handled_Statement_Sequence =>
5718 Make_Handled_Sequence_Of_Statements (Loc,
5719 Statements => Stmts),
5720 Has_Created_Identifier => True,
5721 Is_Asynchronous_Call_Block => True);
5723 -- For the VM call Update_Exception instead of Abort_Undefer.
5724 -- See 4jexcept.ads for an explanation.
5726 if VM_Target = No_VM then
5727 Target_Undefer := RE_Abort_Undefer;
5729 Target_Undefer := RE_Update_Exception;
5731 New_List (Make_Function_Call (Loc,
5732 Name => New_Occurrence_Of
5733 (RTE (RE_Current_Target_Exception), Loc)));
5737 Make_Block_Statement (Loc,
5738 Handled_Statement_Sequence =>
5739 Make_Handled_Sequence_Of_Statements (Loc,
5740 Statements => New_List (
5741 Make_Implicit_Label_Declaration (Loc,
5742 Defining_Identifier => Blk_Ent,
5743 Label_Construct => Abortable_Block),
5748 Exception_Handlers => New_List (
5749 Make_Implicit_Exception_Handler (Loc,
5751 -- when Abort_Signal =>
5752 -- Abort_Undefer.all;
5754 Exception_Choices =>
5755 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5756 Statements => New_List (
5757 Make_Procedure_Call_Statement (Loc,
5758 Name => New_Reference_To (
5759 RTE (Target_Undefer), Loc),
5760 Parameter_Associations => Undefer_Args)))))),
5762 -- if not Cancelled (Bnn) then
5763 -- triggered statements
5766 Make_Implicit_If_Statement (N,
5767 Condition => Make_Op_Not (Loc,
5769 Make_Function_Call (Loc,
5770 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
5771 Parameter_Associations => New_List (
5772 New_Occurrence_Of (Cancel_Param, Loc)))),
5773 Then_Statements => Tstats));
5775 -- Asynchronous task entry call
5782 B := Make_Defining_Identifier (Loc, Name_uB);
5784 -- Insert declaration of B in declarations of existing block
5787 Make_Object_Declaration (Loc,
5788 Defining_Identifier => B,
5789 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
5791 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
5793 -- Insert declaration of C in declarations of existing block
5796 Make_Object_Declaration (Loc,
5797 Defining_Identifier => Cancel_Param,
5798 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
5800 -- Remove and save the call to Call_Simple
5802 Stmt := First (Stmts);
5804 -- Skip assignments to temporaries created for in-out parameters.
5805 -- This makes unwarranted assumptions about the shape of the expanded
5806 -- tree for the call, and should be cleaned up ???
5808 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
5814 -- Create the inner block to protect the abortable part
5817 Make_Implicit_Exception_Handler (Loc,
5818 Exception_Choices =>
5819 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
5822 Make_Procedure_Call_Statement (Loc,
5823 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
5826 Make_Procedure_Call_Statement (Loc,
5827 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
5830 Make_Block_Statement (Loc,
5831 Identifier => New_Reference_To (Blk_Ent, Loc),
5832 Handled_Statement_Sequence =>
5833 Make_Handled_Sequence_Of_Statements (Loc,
5834 Statements => Astats),
5835 Has_Created_Identifier => True,
5836 Is_Asynchronous_Call_Block => True);
5839 Make_Block_Statement (Loc,
5840 Handled_Statement_Sequence =>
5841 Make_Handled_Sequence_Of_Statements (Loc,
5842 Statements => New_List (
5843 Make_Implicit_Label_Declaration (Loc,
5844 Defining_Identifier =>
5849 Exception_Handlers => Hdle)));
5851 -- Create new call statement
5853 Params := Parameter_Associations (Call);
5856 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
5858 New_Reference_To (B, Loc));
5861 Make_Procedure_Call_Statement (Loc,
5863 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
5864 Parameter_Associations => Params));
5866 -- Construct statement sequence for new block
5869 Make_Implicit_If_Statement (N,
5872 New_Reference_To (Cancel_Param, Loc)),
5873 Then_Statements => Tstats));
5875 -- Protected the call against abort
5878 Make_Procedure_Call_Statement (Loc,
5879 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
5880 Parameter_Associations => Empty_List));
5883 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
5885 -- The result is the new block
5888 Make_Block_Statement (Loc,
5889 Declarations => Decls,
5890 Handled_Statement_Sequence =>
5891 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
5894 end Expand_N_Asynchronous_Select;
5896 -------------------------------------
5897 -- Expand_N_Conditional_Entry_Call --
5898 -------------------------------------
5900 -- The conditional task entry call is converted to a call to
5905 -- P : parms := (parm, parm, parm);
5909 -- (<acceptor-task>, -- Acceptor
5910 -- <entry-index>, -- E
5911 -- P'Address, -- Uninterpreted_Data
5912 -- Conditional_Call, -- Mode
5913 -- B); -- Rendezvous_Successful
5918 -- normal-statements
5924 -- For a description of the use of P and the assignments after the call,
5925 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
5926 -- conditional entry call has already been expanded (by the Expand_N_Entry
5927 -- _Call_Statement procedure) as follows:
5930 -- P : parms := (parm, parm, parm);
5932 -- ... info for in-out parameters
5933 -- Call_Simple (acceptor-task, entry-index, P'Address);
5939 -- so the task at hand is to convert the latter expansion into the former
5941 -- The conditional protected entry call is converted to a call to
5942 -- Protected_Entry_Call:
5945 -- P : parms := (parm, parm, parm);
5946 -- Bnn : Communications_Block;
5949 -- Protected_Entry_Call
5950 -- (po._object'Access, -- Object
5951 -- <entry index>, -- E
5952 -- P'Address, -- Uninterpreted_Data
5953 -- Conditional_Call, -- Mode
5958 -- if Cancelled (Bnn) then
5961 -- normal-statements
5965 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
5969 -- B : Boolean := False;
5970 -- C : Ada.Tags.Prim_Op_Kind;
5971 -- K : Ada.Tags.Tagged_Kind :=
5972 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5973 -- P : Parameters := (Param1 .. ParamN);
5977 -- if K = Ada.Tags.TK_Limited_Tagged then
5978 -- <dispatching-call>;
5979 -- <triggering-statements>
5983 -- Ada.Tags.Get_Offset_Index
5984 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5986 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
5988 -- if C = POK_Protected_Entry
5989 -- or else C = POK_Task_Entry
5991 -- Param1 := P.Param1;
5993 -- ParamN := P.ParamN;
5997 -- if C = POK_Procedure
5998 -- or else C = POK_Protected_Procedure
5999 -- or else C = POK_Task_Procedure
6001 -- <dispatching-call>;
6004 -- <triggering-statements>
6006 -- <else-statements>
6011 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6012 Loc : constant Source_Ptr := Sloc (N);
6013 Alt : constant Node_Id := Entry_Call_Alternative (N);
6014 Blk : Node_Id := Entry_Call_Statement (Alt);
6017 Blk_Typ : Entity_Id;
6019 Call_Ent : Entity_Id;
6020 Conc_Typ_Stmts : List_Id;
6024 Lim_Typ_Stmts : List_Id;
6031 Transient_Blk : Node_Id;
6034 B : Entity_Id; -- Call status flag
6035 C : Entity_Id; -- Call kind
6036 K : Entity_Id; -- Tagged kind
6037 P : Entity_Id; -- Parameter block
6038 S : Entity_Id; -- Primitive operation slot
6041 if Ada_Version >= Ada_05
6042 and then Nkind (Blk) = N_Procedure_Call_Statement
6044 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6049 -- Call status flag processing, generate:
6050 -- B : Boolean := False;
6052 B := Build_B (Loc, Decls);
6054 -- Call kind processing, generate:
6055 -- C : Ada.Tags.Prim_Op_Kind;
6057 C := Build_C (Loc, Decls);
6059 -- Tagged kind processing, generate:
6060 -- K : Ada.Tags.Tagged_Kind :=
6061 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6063 K := Build_K (Loc, Decls, Obj);
6065 -- Parameter block processing
6067 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6068 P := Parameter_Block_Pack
6069 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6071 -- Dispatch table slot processing, generate:
6074 S := Build_S (Loc, Decls);
6077 -- S := Ada.Tags.Get_Offset_Index
6078 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6081 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6084 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6086 Append_To (Conc_Typ_Stmts,
6087 Make_Procedure_Call_Statement (Loc,
6090 Find_Prim_Op (Etype (Etype (Obj)),
6091 Name_uDisp_Conditional_Select),
6093 Parameter_Associations =>
6095 New_Copy_Tree (Obj), -- <object>
6096 New_Reference_To (S, Loc), -- S
6097 Make_Attribute_Reference (Loc, -- P'Address
6099 New_Reference_To (P, Loc),
6102 New_Reference_To (C, Loc), -- C
6103 New_Reference_To (B, Loc)))); -- B
6106 -- if C = POK_Protected_Entry
6107 -- or else C = POK_Task_Entry
6109 -- Param1 := P.Param1;
6111 -- ParamN := P.ParamN;
6114 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6116 -- Generate the if statement only when the packed parameters need
6117 -- explicit assignments to their corresponding actuals.
6119 if Present (Unpack) then
6120 Append_To (Conc_Typ_Stmts,
6121 Make_If_Statement (Loc,
6128 New_Reference_To (C, Loc),
6130 New_Reference_To (RTE (
6131 RE_POK_Protected_Entry), Loc)),
6135 New_Reference_To (C, Loc),
6137 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6145 -- if C = POK_Procedure
6146 -- or else C = POK_Protected_Procedure
6147 -- or else C = POK_Task_Procedure
6149 -- <dispatching-call>
6151 -- <normal-statements>
6153 -- <else-statements>
6156 N_Stats := New_Copy_List_Tree (Statements (Alt));
6158 Prepend_To (N_Stats,
6159 Make_If_Statement (Loc,
6165 New_Reference_To (C, Loc),
6167 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6174 New_Reference_To (C, Loc),
6176 New_Reference_To (RTE (
6177 RE_POK_Protected_Procedure), Loc)),
6182 New_Reference_To (C, Loc),
6184 New_Reference_To (RTE (
6185 RE_POK_Task_Procedure), Loc)))),
6190 Append_To (Conc_Typ_Stmts,
6191 Make_If_Statement (Loc,
6192 Condition => New_Reference_To (B, Loc),
6193 Then_Statements => N_Stats,
6194 Else_Statements => Else_Statements (N)));
6197 -- <dispatching-call>;
6198 -- <triggering-statements>
6200 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6201 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6204 -- if K = Ada.Tags.TK_Limited_Tagged then
6211 Make_If_Statement (Loc,
6215 New_Reference_To (K, Loc),
6217 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6226 Make_Block_Statement (Loc,
6229 Handled_Statement_Sequence =>
6230 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6232 -- As described above, The entry alternative is transformed into a
6233 -- block that contains the gnulli call, and possibly assignment
6234 -- statements for in-out parameters. The gnulli call may itself be
6235 -- rewritten into a transient block if some unconstrained parameters
6236 -- require it. We need to retrieve the call to complete its parameter
6241 First_Real_Statement (Handled_Statement_Sequence (Blk));
6243 if Present (Transient_Blk)
6244 and then Nkind (Transient_Blk) = N_Block_Statement
6246 Blk := Transient_Blk;
6249 Stmts := Statements (Handled_Statement_Sequence (Blk));
6250 Stmt := First (Stmts);
6251 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6256 Params := Parameter_Associations (Call);
6258 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6260 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6262 Param := First (Params);
6263 while Present (Param)
6264 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6269 pragma Assert (Present (Param));
6270 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6274 -- Find the Communication_Block parameter for the call to the
6275 -- Cancelled function.
6277 Decl := First (Declarations (Blk));
6278 while Present (Decl)
6279 and then not Is_RTE (Etype (Object_Definition (Decl)),
6280 RE_Communication_Block)
6285 -- Add an if statement to execute the else part if the call
6286 -- does not succeed (as indicated by the Cancelled predicate).
6289 Make_Implicit_If_Statement (N,
6290 Condition => Make_Function_Call (Loc,
6291 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6292 Parameter_Associations => New_List (
6293 New_Reference_To (Defining_Identifier (Decl), Loc))),
6294 Then_Statements => Else_Statements (N),
6295 Else_Statements => Statements (Alt)));
6298 B := Make_Defining_Identifier (Loc, Name_uB);
6300 -- Insert declaration of B in declarations of existing block
6302 if No (Declarations (Blk)) then
6303 Set_Declarations (Blk, New_List);
6306 Prepend_To (Declarations (Blk),
6307 Make_Object_Declaration (Loc,
6308 Defining_Identifier => B,
6309 Object_Definition =>
6310 New_Reference_To (Standard_Boolean, Loc)));
6312 -- Create new call statement
6315 New_Reference_To (RTE (RE_Conditional_Call), Loc));
6316 Append_To (Params, New_Reference_To (B, Loc));
6319 Make_Procedure_Call_Statement (Loc,
6320 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6321 Parameter_Associations => Params));
6323 -- Construct statement sequence for new block
6326 Make_Implicit_If_Statement (N,
6327 Condition => New_Reference_To (B, Loc),
6328 Then_Statements => Statements (Alt),
6329 Else_Statements => Else_Statements (N)));
6332 -- The result is the new block
6335 Make_Block_Statement (Loc,
6336 Declarations => Declarations (Blk),
6337 Handled_Statement_Sequence =>
6338 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6342 end Expand_N_Conditional_Entry_Call;
6344 ---------------------------------------
6345 -- Expand_N_Delay_Relative_Statement --
6346 ---------------------------------------
6348 -- Delay statement is implemented as a procedure call to Delay_For
6349 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
6350 -- simple delays imposed by the use of Protected Objects.
6352 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
6353 Loc : constant Source_Ptr := Sloc (N);
6356 Make_Procedure_Call_Statement (Loc,
6357 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
6358 Parameter_Associations => New_List (Expression (N))));
6360 end Expand_N_Delay_Relative_Statement;
6362 ------------------------------------
6363 -- Expand_N_Delay_Until_Statement --
6364 ------------------------------------
6366 -- Delay Until statement is implemented as a procedure call to
6367 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
6369 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
6370 Loc : constant Source_Ptr := Sloc (N);
6374 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
6375 Typ := RTE (RO_CA_Delay_Until);
6377 Typ := RTE (RO_RT_Delay_Until);
6381 Make_Procedure_Call_Statement (Loc,
6382 Name => New_Reference_To (Typ, Loc),
6383 Parameter_Associations => New_List (Expression (N))));
6386 end Expand_N_Delay_Until_Statement;
6388 -------------------------
6389 -- Expand_N_Entry_Body --
6390 -------------------------
6392 procedure Expand_N_Entry_Body (N : Node_Id) is
6393 Loc : constant Source_Ptr := Sloc (N);
6394 Dec : constant Node_Id := Parent (Current_Scope);
6395 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
6396 Index_Spec : constant Node_Id :=
6397 Entry_Index_Specification (Ent_Formals);
6399 First_Decl : constant Node_Id := First (Declarations (N));
6400 Index_Decl : List_Id;
6403 -- Add the renamings for private declarations and discriminants
6405 Add_Discriminal_Declarations
6406 (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc);
6407 Add_Private_Declarations
6408 (Declarations (N), Defining_Identifier (Dec), Name_uObject, Loc);
6410 if Present (Index_Spec) then
6412 Index_Constant_Declaration
6414 Defining_Identifier (Index_Spec), Defining_Identifier (Dec));
6416 -- If the entry has local declarations, insert index declaration
6417 -- before them, because the index may be used therein.
6419 if Present (First_Decl) then
6420 Insert_List_Before (First_Decl, Index_Decl);
6422 Append_List_To (Declarations (N), Index_Decl);
6426 -- Associate privals and discriminals with the next protected operation
6427 -- body to be expanded. These are used to expand references to private
6428 -- data objects and discriminants, respectively.
6430 Next_Op := Next_Protected_Operation (N);
6432 if Present (Next_Op) then
6433 Set_Privals (Dec, Next_Op, Loc);
6434 Set_Discriminals (Dec);
6436 end Expand_N_Entry_Body;
6438 -----------------------------------
6439 -- Expand_N_Entry_Call_Statement --
6440 -----------------------------------
6442 -- An entry call is expanded into GNARLI calls to implement
6443 -- a simple entry call (see Build_Simple_Entry_Call).
6445 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
6451 if No_Run_Time_Mode then
6452 Error_Msg_CRT ("entry call", N);
6456 -- If this entry call is part of an asynchronous select, don't expand it
6457 -- here; it will be expanded with the select statement. Don't expand
6458 -- timed entry calls either, as they are translated into asynchronous
6461 -- ??? This whole approach is questionable; it may be better to go back
6462 -- to allowing the expansion to take place and then attempting to fix it
6463 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
6464 -- whether the expanded call is on a task or protected entry.
6466 if (Nkind (Parent (N)) /= N_Triggering_Alternative
6467 or else N /= Triggering_Statement (Parent (N)))
6468 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
6469 or else N /= Entry_Call_Statement (Parent (N))
6470 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
6472 Extract_Entry (N, Concval, Ename, Index);
6473 Build_Simple_Entry_Call (N, Concval, Ename, Index);
6475 end Expand_N_Entry_Call_Statement;
6477 --------------------------------
6478 -- Expand_N_Entry_Declaration --
6479 --------------------------------
6481 -- If there are parameters, then first, each of the formals is marked by
6482 -- setting Is_Entry_Formal. Next a record type is built which is used to
6483 -- hold the parameter values. The name of this record type is entryP where
6484 -- entry is the name of the entry, with an additional corresponding access
6485 -- type called entryPA. The record type has matching components for each
6486 -- formal (the component names are the same as the formal names). For
6487 -- elementary types, the component type matches the formal type. For
6488 -- composite types, an access type is declared (with the name formalA)
6489 -- which designates the formal type, and the type of the component is this
6490 -- access type. Finally the Entry_Component of each formal is set to
6491 -- reference the corresponding record component.
6493 procedure Expand_N_Entry_Declaration (N : Node_Id) is
6494 Loc : constant Source_Ptr := Sloc (N);
6495 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
6496 Components : List_Id;
6499 Last_Decl : Node_Id;
6500 Component : Entity_Id;
6503 Rec_Ent : Entity_Id;
6504 Acc_Ent : Entity_Id;
6507 Formal := First_Formal (Entry_Ent);
6510 -- Most processing is done only if parameters are present
6512 if Present (Formal) then
6513 Components := New_List;
6515 -- Loop through formals
6517 while Present (Formal) loop
6518 Set_Is_Entry_Formal (Formal);
6520 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
6521 Set_Entry_Component (Formal, Component);
6522 Set_Entry_Formal (Component, Formal);
6523 Ftype := Etype (Formal);
6525 -- Declare new access type and then append
6528 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6531 Make_Full_Type_Declaration (Loc,
6532 Defining_Identifier => Ctype,
6534 Make_Access_To_Object_Definition (Loc,
6535 All_Present => True,
6536 Constant_Present => Ekind (Formal) = E_In_Parameter,
6537 Subtype_Indication => New_Reference_To (Ftype, Loc)));
6539 Insert_After (Last_Decl, Decl);
6542 Append_To (Components,
6543 Make_Component_Declaration (Loc,
6544 Defining_Identifier => Component,
6545 Component_Definition =>
6546 Make_Component_Definition (Loc,
6547 Aliased_Present => False,
6548 Subtype_Indication => New_Reference_To (Ctype, Loc))));
6550 Next_Formal_With_Extras (Formal);
6553 -- Create the Entry_Parameter_Record declaration
6556 Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
6559 Make_Full_Type_Declaration (Loc,
6560 Defining_Identifier => Rec_Ent,
6562 Make_Record_Definition (Loc,
6564 Make_Component_List (Loc,
6565 Component_Items => Components)));
6567 Insert_After (Last_Decl, Decl);
6570 -- Construct and link in the corresponding access type
6573 Make_Defining_Identifier (Loc, New_Internal_Name ('A'));
6575 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
6578 Make_Full_Type_Declaration (Loc,
6579 Defining_Identifier => Acc_Ent,
6581 Make_Access_To_Object_Definition (Loc,
6582 All_Present => True,
6583 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
6585 Insert_After (Last_Decl, Decl);
6588 end Expand_N_Entry_Declaration;
6590 -----------------------------
6591 -- Expand_N_Protected_Body --
6592 -----------------------------
6594 -- Protected bodies are expanded to the completion of the subprograms
6595 -- created for the corresponding protected type. These are a protected and
6596 -- unprotected version of each protected subprogram in the object, a
6597 -- function to calculate each entry barrier, and a procedure to execute the
6598 -- sequence of statements of each protected entry body. For example, for
6599 -- protected type ptype:
6602 -- (O : System.Address;
6603 -- E : Protected_Entry_Index)
6606 -- <discriminant renamings>
6607 -- <private object renamings>
6609 -- return <barrier expression>;
6612 -- procedure pprocN (_object : in out poV;...) is
6613 -- <discriminant renamings>
6614 -- <private object renamings>
6616 -- <sequence of statements>
6619 -- procedure pprocP (_object : in out poV;...) is
6620 -- procedure _clean is
6623 -- ptypeS (_object, Pn);
6624 -- Unlock (_object._object'Access);
6625 -- Abort_Undefer.all;
6630 -- Lock (_object._object'Access);
6631 -- pprocN (_object;...);
6636 -- function pfuncN (_object : poV;...) return Return_Type is
6637 -- <discriminant renamings>
6638 -- <private object renamings>
6640 -- <sequence of statements>
6643 -- function pfuncP (_object : poV) return Return_Type is
6644 -- procedure _clean is
6646 -- Unlock (_object._object'Access);
6647 -- Abort_Undefer.all;
6652 -- Lock (_object._object'Access);
6653 -- return pfuncN (_object);
6660 -- (O : System.Address;
6661 -- P : System.Address;
6662 -- E : Protected_Entry_Index)
6664 -- <discriminant renamings>
6665 -- <private object renamings>
6666 -- type poVP is access poV;
6667 -- _Object : ptVP := ptVP!(O);
6671 -- <statement sequence>
6672 -- Complete_Entry_Body (_Object._Object);
6674 -- when all others =>
6675 -- Exceptional_Complete_Entry_Body (
6676 -- _Object._Object, Get_GNAT_Exception);
6680 -- The type poV is the record created for the protected type to hold
6681 -- the state of the protected object.
6683 procedure Expand_N_Protected_Body (N : Node_Id) is
6684 Loc : constant Source_Ptr := Sloc (N);
6685 Pid : constant Entity_Id := Corresponding_Spec (N);
6686 Has_Entries : Boolean := False;
6690 Disp_Op_Body : Node_Id;
6691 New_Op_Body : Node_Id;
6692 Current_Node : Node_Id;
6693 Num_Entries : Natural := 0;
6695 function Build_Dispatching_Subprogram_Body
6698 Prot_Bod : Node_Id) return Node_Id;
6699 -- Build a dispatching version of the protected subprogram body. The
6700 -- newly generated subprogram contains a call to the original protected
6701 -- body. The following code is generated:
6703 -- function <protected-function-name> (Param1 .. ParamN) return
6706 -- return <protected-function-name>P (Param1 .. ParamN);
6707 -- end <protected-function-name>;
6711 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
6713 -- <protected-procedure-name>P (Param1 .. ParamN);
6714 -- end <protected-procedure-name>
6716 ---------------------------------------
6717 -- Build_Dispatching_Subprogram_Body --
6718 ---------------------------------------
6720 function Build_Dispatching_Subprogram_Body
6723 Prot_Bod : Node_Id) return Node_Id
6725 Loc : constant Source_Ptr := Sloc (N);
6732 -- Generate a specification without a letter suffix in order to
6733 -- override an interface function or procedure.
6736 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
6738 -- The formal parameters become the actuals of the protected
6739 -- function or procedure call.
6741 Actuals := New_List;
6742 Formal := First (Parameter_Specifications (Spec));
6743 while Present (Formal) loop
6745 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
6750 if Nkind (Spec) = N_Procedure_Specification then
6753 Make_Procedure_Call_Statement (Loc,
6755 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
6756 Parameter_Associations => Actuals));
6758 pragma Assert (Nkind (Spec) = N_Function_Specification);
6762 Make_Simple_Return_Statement (Loc,
6764 Make_Function_Call (Loc,
6766 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
6767 Parameter_Associations => Actuals)));
6771 Make_Subprogram_Body (Loc,
6772 Declarations => Empty_List,
6773 Specification => Spec,
6774 Handled_Statement_Sequence =>
6775 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
6776 end Build_Dispatching_Subprogram_Body;
6778 -- Start of processing for Expand_N_Protected_Body
6781 if No_Run_Time_Mode then
6782 Error_Msg_CRT ("protected body", N);
6786 if Nkind (Parent (N)) = N_Subunit then
6788 -- This is the proper body corresponding to a stub. The declarations
6789 -- must be inserted at the point of the stub, which is in the decla-
6790 -- rative part of the parent unit.
6792 Current_Node := Corresponding_Stub (Parent (N));
6798 Op_Body := First (Declarations (N));
6800 -- The protected body is replaced with the bodies of its
6801 -- protected operations, and the declarations for internal objects
6802 -- that may have been created for entry family bounds.
6804 Rewrite (N, Make_Null_Statement (Sloc (N)));
6807 while Present (Op_Body) loop
6808 case Nkind (Op_Body) is
6809 when N_Subprogram_Declaration =>
6812 when N_Subprogram_Body =>
6814 -- Exclude functions created to analyze defaults
6816 if not Is_Eliminated (Defining_Entity (Op_Body))
6817 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
6820 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
6822 -- Propagate the finalization chain to the new body.
6823 -- In the unlikely event that the subprogram contains a
6824 -- declaration or allocator for an object that requires
6825 -- finalization, the corresponding chain is created when
6826 -- analyzing the body, and attached to its entity. This
6827 -- entity is not further elaborated, and so the chain
6828 -- properly belongs to the newly created subprogram body.
6831 (Finalization_Chain_Entity (Defining_Entity (Op_Body)))
6833 Set_Finalization_Chain_Entity
6834 (Protected_Body_Subprogram
6835 (Corresponding_Spec (Op_Body)),
6836 Finalization_Chain_Entity (Defining_Entity (Op_Body)));
6838 (Handled_Statement_Sequence (New_Op_Body), False);
6841 Insert_After (Current_Node, New_Op_Body);
6842 Current_Node := New_Op_Body;
6843 Analyze (New_Op_Body);
6845 Update_Prival_Subtypes (New_Op_Body);
6847 -- Build the corresponding protected operation. It may
6848 -- appear that this is needed only this is a visible
6849 -- operation of the type, or if it is an interrupt handler,
6850 -- and this was the strategy used previously in GNAT.
6851 -- However, the operation may be exported through a
6852 -- 'Access to an external caller. This is the common idiom
6853 -- in code that uses the Ada 2005 Timing_Events package
6854 -- As a result we need to produce the protected body for
6855 -- both visible and private operations.
6857 if Present (Corresponding_Spec (Op_Body)) then
6859 Unit_Declaration_Node (Corresponding_Spec (Op_Body));
6862 Nkind (Parent (Op_Decl)) = N_Protected_Definition
6865 Build_Protected_Subprogram_Body (
6866 Op_Body, Pid, Specification (New_Op_Body));
6868 Insert_After (Current_Node, New_Op_Body);
6869 Analyze (New_Op_Body);
6871 Current_Node := New_Op_Body;
6873 -- Generate an overriding primitive operation body for
6874 -- this subprogram if the protected type implements
6877 if Ada_Version >= Ada_05
6878 and then Present (Abstract_Interfaces (
6879 Corresponding_Record_Type (Pid)))
6882 Build_Dispatching_Subprogram_Body (
6883 Op_Body, Pid, New_Op_Body);
6885 Insert_After (Current_Node, Disp_Op_Body);
6886 Analyze (Disp_Op_Body);
6888 Current_Node := Disp_Op_Body;
6894 when N_Entry_Body =>
6895 Op_Id := Defining_Identifier (Op_Body);
6896 Has_Entries := True;
6897 Num_Entries := Num_Entries + 1;
6899 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
6901 Insert_After (Current_Node, New_Op_Body);
6902 Current_Node := New_Op_Body;
6903 Analyze (New_Op_Body);
6905 Update_Prival_Subtypes (New_Op_Body);
6907 when N_Implicit_Label_Declaration =>
6910 when N_Itype_Reference =>
6911 Insert_After (Current_Node, New_Copy (Op_Body));
6913 when N_Freeze_Entity =>
6914 New_Op_Body := New_Copy (Op_Body);
6916 if Present (Entity (Op_Body))
6917 and then Freeze_Node (Entity (Op_Body)) = Op_Body
6919 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
6922 Insert_After (Current_Node, New_Op_Body);
6923 Current_Node := New_Op_Body;
6924 Analyze (New_Op_Body);
6927 New_Op_Body := New_Copy (Op_Body);
6928 Insert_After (Current_Node, New_Op_Body);
6929 Current_Node := New_Op_Body;
6930 Analyze (New_Op_Body);
6932 when N_Object_Declaration =>
6933 pragma Assert (not Comes_From_Source (Op_Body));
6934 New_Op_Body := New_Copy (Op_Body);
6935 Insert_After (Current_Node, New_Op_Body);
6936 Current_Node := New_Op_Body;
6937 Analyze (New_Op_Body);
6940 raise Program_Error;
6947 -- Finally, create the body of the function that maps an entry index
6948 -- into the corresponding body index, except when there is no entry,
6949 -- or in a ravenscar-like profile (no abort, no entry queue, 1 entry)
6952 and then (Abort_Allowed
6953 or else Restriction_Active (No_Entry_Queue) = False
6954 or else Num_Entries > 1
6955 or else (Has_Attach_Handler (Pid)
6956 and then not Restricted_Profile))
6958 New_Op_Body := Build_Find_Body_Index (Pid);
6959 Insert_After (Current_Node, New_Op_Body);
6960 Current_Node := New_Op_Body;
6961 Analyze (New_Op_Body);
6964 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
6965 -- the protected body. At this point the entry specs have been created,
6966 -- frozen and included in the dispatch table for the protected type.
6968 pragma Assert (Present (Corresponding_Record_Type (Pid)));
6970 if Ada_Version >= Ada_05
6971 and then Present (Protected_Definition (Parent (Pid)))
6972 and then Present (Abstract_Interfaces
6973 (Corresponding_Record_Type (Pid)))
6976 Vis_Decl : Node_Id :=
6977 First (Visible_Declarations
6978 (Protected_Definition (Parent (Pid))));
6979 Wrap_Body : Node_Id;
6982 -- Examine the visible declarations of the protected type, looking
6983 -- for an entry declaration. We do not consider entry families
6984 -- since they cannot have dispatching operations, thus they do not
6985 -- need entry wrappers.
6987 while Present (Vis_Decl) loop
6988 if Nkind (Vis_Decl) = N_Entry_Declaration then
6990 Build_Wrapper_Body (Loc,
6991 Proc_Nam => Defining_Identifier (Vis_Decl),
6992 Obj_Typ => Corresponding_Record_Type (Pid),
6993 Formals => Parameter_Specifications (Vis_Decl));
6995 if Wrap_Body /= Empty then
6996 Insert_After (Current_Node, Wrap_Body);
6997 Current_Node := Wrap_Body;
6999 Analyze (Wrap_Body);
7002 elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then
7004 Build_Wrapper_Body (Loc,
7005 Proc_Nam => Defining_Unit_Name
7006 (Specification (Vis_Decl)),
7007 Obj_Typ => Corresponding_Record_Type (Pid),
7008 Formals => Parameter_Specifications
7009 (Specification (Vis_Decl)));
7011 if Wrap_Body /= Empty then
7012 Insert_After (Current_Node, Wrap_Body);
7013 Current_Node := Wrap_Body;
7015 Analyze (Wrap_Body);
7023 end Expand_N_Protected_Body;
7025 -----------------------------------------
7026 -- Expand_N_Protected_Type_Declaration --
7027 -----------------------------------------
7029 -- First we create a corresponding record type declaration used to
7030 -- represent values of this protected type.
7031 -- The general form of this type declaration is
7033 -- type poV (discriminants) is record
7034 -- _Object : aliased <kind>Protection
7035 -- [(<entry count> [, <handler count>])];
7036 -- [entry_family : array (bounds) of Void;]
7037 -- <private data fields>
7040 -- The discriminants are present only if the corresponding protected type
7041 -- has discriminants, and they exactly mirror the protected type
7042 -- discriminants. The private data fields similarly mirror the private
7043 -- declarations of the protected type.
7045 -- The Object field is always present. It contains RTS specific data used
7046 -- to control the protected object. It is declared as Aliased so that it
7047 -- can be passed as a pointer to the RTS. This allows the protected record
7048 -- to be referenced within RTS data structures. An appropriate Protection
7049 -- type and discriminant are generated.
7051 -- The Service field is present for protected objects with entries. It
7052 -- contains sufficient information to allow the entry service procedure for
7053 -- this object to be called when the object is not known till runtime.
7055 -- One entry_family component is present for each entry family in the
7056 -- task definition (see Expand_N_Task_Type_Declaration).
7058 -- When a protected object is declared, an instance of the protected type
7059 -- value record is created. The elaboration of this declaration creates the
7060 -- correct bounds for the entry families, and also evaluates the priority
7061 -- expression if needed. The initialization routine for the protected type
7062 -- itself then calls Initialize_Protection with appropriate parameters to
7063 -- initialize the value of the Task_Id field. Install_Handlers may be also
7064 -- called if a pragma Attach_Handler applies.
7066 -- Note: this record is passed to the subprograms created by the expansion
7067 -- of protected subprograms and entries. It is an in parameter to protected
7068 -- functions and an in out parameter to procedures and entry bodies. The
7069 -- Entity_Id for this created record type is placed in the
7070 -- Corresponding_Record_Type field of the associated protected type entity.
7072 -- Next we create a procedure specifications for protected subprograms and
7073 -- entry bodies. For each protected subprograms two subprograms are
7074 -- created, an unprotected and a protected version. The unprotected version
7075 -- is called from within other operations of the same protected object.
7077 -- We also build the call to register the procedure if a pragma
7078 -- Interrupt_Handler applies.
7080 -- A single subprogram is created to service all entry bodies; it has an
7081 -- additional boolean out parameter indicating that the previous entry call
7082 -- made by the current task was serviced immediately, i.e. not by proxy.
7083 -- The O parameter contains a pointer to a record object of the type
7084 -- described above. An untyped interface is used here to allow this
7085 -- procedure to be called in places where the type of the object to be
7086 -- serviced is not known. This must be done, for example, when a call that
7087 -- may have been requeued is cancelled; the corresponding object must be
7088 -- serviced, but which object that is not known till runtime.
7091 -- (O : System.Address; P : out Boolean);
7092 -- procedure pprocN (_object : in out poV);
7093 -- procedure pproc (_object : in out poV);
7094 -- function pfuncN (_object : poV);
7095 -- function pfunc (_object : poV);
7098 -- Note that this must come after the record type declaration, since
7099 -- the specs refer to this type.
7101 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7102 Loc : constant Source_Ptr := Sloc (N);
7103 Prottyp : constant Entity_Id := Defining_Identifier (N);
7105 Pdef : constant Node_Id := Protected_Definition (N);
7106 -- This contains two lists; one for visible and one for private decls
7110 Discr_Map : constant Elist_Id := New_Elmt_List;
7114 Comp_Id : Entity_Id;
7116 Current_Node : Node_Id := N;
7117 Bdef : Entity_Id := Empty; -- avoid uninit warning
7118 Edef : Entity_Id := Empty; -- avoid uninit warning
7119 Entries_Aggr : Node_Id;
7120 Body_Id : Entity_Id;
7123 Object_Comp : Node_Id;
7125 procedure Register_Handler;
7126 -- For a protected operation that is an interrupt handler, add the
7127 -- freeze action that will register it as such.
7129 ----------------------
7130 -- Register_Handler --
7131 ----------------------
7133 procedure Register_Handler is
7135 -- All semantic checks already done in Sem_Prag
7137 Prot_Proc : constant Entity_Id :=
7139 (Specification (Current_Node));
7141 Proc_Address : constant Node_Id :=
7142 Make_Attribute_Reference (Loc,
7143 Prefix => New_Reference_To (Prot_Proc, Loc),
7144 Attribute_Name => Name_Address);
7146 RTS_Call : constant Entity_Id :=
7147 Make_Procedure_Call_Statement (Loc,
7150 RTE (RE_Register_Interrupt_Handler), Loc),
7151 Parameter_Associations =>
7152 New_List (Proc_Address));
7154 Append_Freeze_Action (Prot_Proc, RTS_Call);
7155 end Register_Handler;
7157 -- Start of processing for Expand_N_Protected_Type_Declaration
7160 if Present (Corresponding_Record_Type (Prottyp)) then
7163 Rec_Decl := Build_Corresponding_Record (N, Prottyp, Loc);
7166 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7168 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
7169 -- of implemented interfaces.
7171 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
7173 Qualify_Entity_Names (N);
7175 -- If the type has discriminants, their occurrences in the declaration
7176 -- have been replaced by the corresponding discriminals. For components
7177 -- that are constrained by discriminants, their homologues in the
7178 -- corresponding record type must refer to the discriminants of that
7179 -- record, so we must apply a new renaming to subtypes_indications:
7181 -- protected discriminant => discriminal => record discriminant
7183 -- This replacement is not applied to default expressions, for which
7184 -- the discriminal is correct.
7186 if Has_Discriminants (Prottyp) then
7191 Disc := First_Discriminant (Prottyp);
7192 Decl := First (Discriminant_Specifications (Rec_Decl));
7193 while Present (Disc) loop
7194 Append_Elmt (Discriminal (Disc), Discr_Map);
7195 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7196 Next_Discriminant (Disc);
7202 -- Fill in the component declarations
7204 -- Add components for entry families. For each entry family, create an
7205 -- anonymous type declaration with the same size, and analyze the type.
7207 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prottyp);
7209 -- Prepend the _Object field with the right type to the component list.
7210 -- We need to compute the number of entries, and in some cases the
7211 -- number of Attach_Handler pragmas.
7215 Num_Attach_Handler : Int := 0;
7216 Protection_Subtype : Node_Id;
7217 Entry_Count_Expr : constant Node_Id :=
7218 Build_Entry_Count_Expression
7219 (Prottyp, Cdecls, Loc);
7222 if Has_Attach_Handler (Prottyp) then
7223 Ritem := First_Rep_Item (Prottyp);
7224 while Present (Ritem) loop
7225 if Nkind (Ritem) = N_Pragma
7226 and then Chars (Ritem) = Name_Attach_Handler
7228 Num_Attach_Handler := Num_Attach_Handler + 1;
7231 Next_Rep_Item (Ritem);
7234 if Restricted_Profile then
7235 if Has_Entries (Prottyp) then
7236 Protection_Subtype :=
7237 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7239 Protection_Subtype :=
7240 New_Reference_To (RTE (RE_Protection), Loc);
7243 Protection_Subtype :=
7244 Make_Subtype_Indication
7248 (RTE (RE_Static_Interrupt_Protection), Loc),
7250 Make_Index_Or_Discriminant_Constraint (
7252 Constraints => New_List (
7254 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7257 elsif Has_Interrupt_Handler (Prottyp) then
7258 Protection_Subtype :=
7259 Make_Subtype_Indication (
7261 Subtype_Mark => New_Reference_To
7262 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7264 Make_Index_Or_Discriminant_Constraint (
7266 Constraints => New_List (Entry_Count_Expr)));
7268 -- Type has explicit entries or generated primitive entry wrappers
7270 elsif Has_Entries (Prottyp)
7271 or else (Ada_Version >= Ada_05
7272 and then Present (Interface_List (N)))
7275 or else Restriction_Active (No_Entry_Queue) = False
7276 or else Number_Entries (Prottyp) > 1
7278 Protection_Subtype :=
7279 Make_Subtype_Indication (
7282 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7284 Make_Index_Or_Discriminant_Constraint (
7286 Constraints => New_List (Entry_Count_Expr)));
7289 Protection_Subtype :=
7290 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7294 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7298 Make_Component_Declaration (Loc,
7299 Defining_Identifier =>
7300 Make_Defining_Identifier (Loc, Name_uObject),
7301 Component_Definition =>
7302 Make_Component_Definition (Loc,
7303 Aliased_Present => True,
7304 Subtype_Indication => Protection_Subtype));
7307 pragma Assert (Present (Pdef));
7309 -- Add private field components
7311 if Present (Private_Declarations (Pdef)) then
7312 Priv := First (Private_Declarations (Pdef));
7314 while Present (Priv) loop
7316 if Nkind (Priv) = N_Component_Declaration then
7318 -- The component definition consists of a subtype indication,
7319 -- or (in Ada 2005) an access definition. Make a copy of the
7320 -- proper definition.
7323 Old_Comp : constant Node_Id := Component_Definition (Priv);
7324 Pent : constant Entity_Id := Defining_Identifier (Priv);
7328 if Present (Subtype_Indication (Old_Comp)) then
7330 Make_Component_Definition (Sloc (Pent),
7331 Aliased_Present => False,
7332 Subtype_Indication =>
7333 New_Copy_Tree (Subtype_Indication (Old_Comp),
7337 Make_Component_Definition (Sloc (Pent),
7338 Aliased_Present => False,
7339 Access_Definition =>
7340 New_Copy_Tree (Access_Definition (Old_Comp),
7345 Make_Component_Declaration (Loc,
7346 Defining_Identifier =>
7347 Make_Defining_Identifier (Sloc (Pent), Chars (Pent)),
7348 Component_Definition => New_Comp,
7349 Expression => Expression (Priv));
7351 Append_To (Cdecls, New_Priv);
7354 elsif Nkind (Priv) = N_Subprogram_Declaration then
7356 -- Make the unprotected version of the subprogram available
7357 -- for expansion of intra object calls. There is need for
7358 -- a protected version only if the subprogram is an interrupt
7359 -- handler, otherwise this operation can only be called from
7363 Make_Subprogram_Declaration (Loc,
7365 Build_Protected_Sub_Specification
7366 (Priv, Prottyp, Unprotected_Mode));
7368 Insert_After (Current_Node, Sub);
7371 Set_Protected_Body_Subprogram
7372 (Defining_Unit_Name (Specification (Priv)),
7373 Defining_Unit_Name (Specification (Sub)));
7375 Current_Node := Sub;
7378 Make_Subprogram_Declaration (Loc,
7380 Build_Protected_Sub_Specification
7381 (Priv, Prottyp, Protected_Mode));
7383 Insert_After (Current_Node, Sub);
7385 Current_Node := Sub;
7387 if Is_Interrupt_Handler
7388 (Defining_Unit_Name (Specification (Priv)))
7390 if not Restricted_Profile then
7400 -- Put the _Object component after the private component so that it
7401 -- be finalized early as required by 9.4 (20)
7403 Append_To (Cdecls, Object_Comp);
7405 Insert_After (Current_Node, Rec_Decl);
7406 Current_Node := Rec_Decl;
7408 -- Analyze the record declaration immediately after construction,
7409 -- because the initialization procedure is needed for single object
7410 -- declarations before the next entity is analyzed (the freeze call
7411 -- that generates this initialization procedure is found below).
7413 Analyze (Rec_Decl, Suppress => All_Checks);
7415 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
7416 -- the corresponding record is frozen
7418 if Ada_Version >= Ada_05
7419 and then Present (Visible_Declarations (Pdef))
7420 and then Present (Corresponding_Record_Type
7421 (Defining_Identifier (Parent (Pdef))))
7422 and then Present (Abstract_Interfaces
7423 (Corresponding_Record_Type
7424 (Defining_Identifier (Parent (Pdef)))))
7427 Current_Node : Node_Id := Rec_Decl;
7429 Wrap_Spec : Node_Id;
7433 -- Examine the visible declarations of the protected type, looking
7434 -- for declarations of entries, and subprograms. We do not
7435 -- consider entry families since they cannot have dispatching
7436 -- operations, thus they do not need entry wrappers.
7438 Vis_Decl := First (Visible_Declarations (Pdef));
7440 while Present (Vis_Decl) loop
7444 if Nkind (Vis_Decl) = N_Entry_Declaration
7445 and then No (Discrete_Subtype_Definition (Vis_Decl))
7448 Build_Wrapper_Spec (Loc,
7449 Proc_Nam => Defining_Identifier (Vis_Decl),
7450 Obj_Typ => Defining_Identifier (Rec_Decl),
7451 Formals => Parameter_Specifications (Vis_Decl));
7453 elsif Nkind (Vis_Decl) = N_Subprogram_Declaration then
7455 Build_Wrapper_Spec (Loc,
7456 Proc_Nam => Defining_Unit_Name
7457 (Specification (Vis_Decl)),
7458 Obj_Typ => Defining_Identifier (Rec_Decl),
7459 Formals => Parameter_Specifications
7460 (Specification (Vis_Decl)));
7464 if Wrap_Spec /= Empty then
7465 New_N := Make_Subprogram_Declaration (Loc,
7466 Specification => Wrap_Spec);
7468 Insert_After (Current_Node, New_N);
7469 Current_Node := New_N;
7479 -- Collect pointers to entry bodies and their barriers, to be placed
7480 -- in the Entry_Bodies_Array for the type. For each entry/family we
7481 -- add an expression to the aggregate which is the initial value of
7482 -- this array. The array is declared after all protected subprograms.
7484 if Has_Entries (Prottyp) then
7486 Make_Aggregate (Loc, Expressions => New_List);
7489 Entries_Aggr := Empty;
7492 -- Build two new procedure specifications for each protected subprogram;
7493 -- one to call from outside the object and one to call from inside.
7494 -- Build a barrier function and an entry body action procedure
7495 -- specification for each protected entry. Initialize the entry body
7496 -- array. If subprogram is flagged as eliminated, do not generate any
7497 -- internal operations.
7501 Comp := First (Visible_Declarations (Pdef));
7503 while Present (Comp) loop
7504 if Nkind (Comp) = N_Subprogram_Declaration
7505 and then not Is_Eliminated (Defining_Entity (Comp))
7508 Make_Subprogram_Declaration (Loc,
7510 Build_Protected_Sub_Specification
7511 (Comp, Prottyp, Unprotected_Mode));
7513 Insert_After (Current_Node, Sub);
7516 Set_Protected_Body_Subprogram
7517 (Defining_Unit_Name (Specification (Comp)),
7518 Defining_Unit_Name (Specification (Sub)));
7520 -- Make the protected version of the subprogram available for
7521 -- expansion of external calls.
7523 Current_Node := Sub;
7526 Make_Subprogram_Declaration (Loc,
7528 Build_Protected_Sub_Specification
7529 (Comp, Prottyp, Protected_Mode));
7531 Insert_After (Current_Node, Sub);
7534 Current_Node := Sub;
7536 -- Generate an overriding primitive operation specification for
7537 -- this subprogram if the protected type implements an interface.
7539 if Ada_Version >= Ada_05
7541 Present (Abstract_Interfaces
7542 (Corresponding_Record_Type (Prottyp)))
7545 Make_Subprogram_Declaration (Loc,
7547 Build_Protected_Sub_Specification
7548 (Comp, Prottyp, Dispatching_Mode));
7550 Insert_After (Current_Node, Sub);
7553 Current_Node := Sub;
7556 -- If a pragma Interrupt_Handler applies, build and add a call to
7557 -- Register_Interrupt_Handler to the freezing actions of the
7558 -- protected version (Current_Node) of the subprogram:
7560 -- system.interrupts.register_interrupt_handler
7561 -- (prot_procP'address);
7563 if not Restricted_Profile
7564 and then Is_Interrupt_Handler
7565 (Defining_Unit_Name (Specification (Comp)))
7570 elsif Nkind (Comp) = N_Entry_Declaration then
7571 E_Count := E_Count + 1;
7572 Comp_Id := Defining_Identifier (Comp);
7573 Set_Privals_Chain (Comp_Id, New_Elmt_List);
7575 Make_Defining_Identifier (Loc,
7576 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7578 Make_Subprogram_Declaration (Loc,
7580 Build_Protected_Entry_Specification (Edef, Comp_Id, Loc));
7582 Insert_After (Current_Node, Sub);
7585 Set_Protected_Body_Subprogram (
7586 Defining_Identifier (Comp),
7587 Defining_Unit_Name (Specification (Sub)));
7589 Current_Node := Sub;
7592 Make_Defining_Identifier (Loc,
7593 Build_Selected_Name (Prottyp, Comp_Id, 'B'));
7595 Make_Subprogram_Declaration (Loc,
7597 Build_Barrier_Function_Specification (Bdef, Loc));
7599 Insert_After (Current_Node, Sub);
7601 Set_Protected_Body_Subprogram (Bdef, Bdef);
7602 Set_Barrier_Function (Comp_Id, Bdef);
7603 Set_Scope (Bdef, Scope (Comp_Id));
7604 Current_Node := Sub;
7606 -- Collect pointers to the protected subprogram and the barrier
7607 -- of the current entry, for insertion into Entry_Bodies_Array.
7610 Make_Aggregate (Loc,
7611 Expressions => New_List (
7612 Make_Attribute_Reference (Loc,
7613 Prefix => New_Reference_To (Bdef, Loc),
7614 Attribute_Name => Name_Unrestricted_Access),
7615 Make_Attribute_Reference (Loc,
7616 Prefix => New_Reference_To (Edef, Loc),
7617 Attribute_Name => Name_Unrestricted_Access))),
7618 Expressions (Entries_Aggr));
7625 -- If there are some private entry declarations, expand it as if they
7626 -- were visible entries.
7628 if Present (Private_Declarations (Pdef)) then
7629 Comp := First (Private_Declarations (Pdef));
7630 while Present (Comp) loop
7631 if Nkind (Comp) = N_Entry_Declaration then
7632 E_Count := E_Count + 1;
7633 Comp_Id := Defining_Identifier (Comp);
7634 Set_Privals_Chain (Comp_Id, New_Elmt_List);
7636 Make_Defining_Identifier (Loc,
7637 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7640 Make_Subprogram_Declaration (Loc,
7642 Build_Protected_Entry_Specification (Edef, Comp_Id, Loc));
7644 Insert_After (Current_Node, Sub);
7647 Set_Protected_Body_Subprogram (
7648 Defining_Identifier (Comp),
7649 Defining_Unit_Name (Specification (Sub)));
7651 Current_Node := Sub;
7654 Make_Defining_Identifier (Loc,
7655 Build_Selected_Name (Prottyp, Comp_Id, 'E'));
7658 Make_Subprogram_Declaration (Loc,
7660 Build_Barrier_Function_Specification (Bdef, Loc));
7662 Insert_After (Current_Node, Sub);
7664 Set_Protected_Body_Subprogram (Bdef, Bdef);
7665 Set_Barrier_Function (Comp_Id, Bdef);
7666 Set_Scope (Bdef, Scope (Comp_Id));
7667 Current_Node := Sub;
7669 -- Collect pointers to the protected subprogram and the barrier
7670 -- of the current entry, for insertion into Entry_Bodies_Array.
7673 Make_Aggregate (Loc,
7674 Expressions => New_List (
7675 Make_Attribute_Reference (Loc,
7676 Prefix => New_Reference_To (Bdef, Loc),
7677 Attribute_Name => Name_Unrestricted_Access),
7678 Make_Attribute_Reference (Loc,
7679 Prefix => New_Reference_To (Edef, Loc),
7680 Attribute_Name => Name_Unrestricted_Access))),
7681 Expressions (Entries_Aggr));
7688 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
7689 -- all protected subprograms have been collected.
7691 if Has_Entries (Prottyp) then
7692 Body_Id := Make_Defining_Identifier (Sloc (Prottyp),
7693 New_External_Name (Chars (Prottyp), 'A'));
7696 or else Restriction_Active (No_Entry_Queue) = False
7698 or else (Has_Attach_Handler (Prottyp)
7699 and then not Restricted_Profile)
7701 Body_Arr := Make_Object_Declaration (Loc,
7702 Defining_Identifier => Body_Id,
7703 Aliased_Present => True,
7704 Object_Definition =>
7705 Make_Subtype_Indication (Loc,
7706 Subtype_Mark => New_Reference_To (
7707 RTE (RE_Protected_Entry_Body_Array), Loc),
7709 Make_Index_Or_Discriminant_Constraint (Loc,
7710 Constraints => New_List (
7712 Make_Integer_Literal (Loc, 1),
7713 Make_Integer_Literal (Loc, E_Count))))),
7714 Expression => Entries_Aggr);
7717 Body_Arr := Make_Object_Declaration (Loc,
7718 Defining_Identifier => Body_Id,
7719 Aliased_Present => True,
7720 Object_Definition => New_Reference_To (RTE (RE_Entry_Body), Loc),
7722 Make_Aggregate (Loc,
7723 Expressions => New_List (
7724 Make_Attribute_Reference (Loc,
7725 Prefix => New_Reference_To (Bdef, Loc),
7726 Attribute_Name => Name_Unrestricted_Access),
7727 Make_Attribute_Reference (Loc,
7728 Prefix => New_Reference_To (Edef, Loc),
7729 Attribute_Name => Name_Unrestricted_Access))));
7732 -- A pointer to this array will be placed in the corresponding record
7733 -- by its initialization procedure so this needs to be analyzed here.
7735 Insert_After (Current_Node, Body_Arr);
7736 Current_Node := Body_Arr;
7739 Set_Entry_Bodies_Array (Prottyp, Body_Id);
7741 -- Finally, build the function that maps an entry index into the
7742 -- corresponding body. A pointer to this function is placed in each
7743 -- object of the type. Except for a ravenscar-like profile (no abort,
7744 -- no entry queue, 1 entry)
7747 or else Restriction_Active (No_Entry_Queue) = False
7749 or else (Has_Attach_Handler (Prottyp)
7750 and then not Restricted_Profile)
7753 Make_Subprogram_Declaration (Loc,
7754 Specification => Build_Find_Body_Index_Spec (Prottyp));
7755 Insert_After (Current_Node, Sub);
7759 end Expand_N_Protected_Type_Declaration;
7761 --------------------------------
7762 -- Expand_N_Requeue_Statement --
7763 --------------------------------
7765 -- A non-dispatching requeue statement is expanded into one of four GNARLI
7766 -- operations, depending on the source and destination (task or protected
7767 -- object). A dispatching requeue statement is expanded into a call to the
7768 -- predefined primitive _Disp_Requeue. In addition, code is generated to
7769 -- jump around the remainder of processing for the original entry and, if
7770 -- the destination is (different) protected object, to attempt to service
7771 -- it. The following illustrates the various cases:
7774 -- (O : System.Address;
7775 -- P : System.Address;
7776 -- E : Protected_Entry_Index)
7778 -- <discriminant renamings>
7779 -- <private object renamings>
7780 -- type poVP is access poV;
7781 -- _object : ptVP := ptVP!(O);
7785 -- <start of statement sequence for entry>
7787 -- -- Requeue from one protected entry body to another protected
7790 -- Requeue_Protected_Entry (
7791 -- _object._object'Access,
7792 -- new._object'Access,
7797 -- <some more of the statement sequence for entry>
7799 -- -- Requeue from an entry body to a task entry
7801 -- Requeue_Protected_To_Task_Entry (
7807 -- <rest of statement sequence for entry>
7808 -- Complete_Entry_Body (_object._object);
7811 -- when all others =>
7812 -- Exceptional_Complete_Entry_Body (
7813 -- _object._object, Get_GNAT_Exception);
7817 -- Requeue of a task entry call to a task entry
7819 -- Accept_Call (E, Ann);
7820 -- <start of statement sequence for accept statement>
7821 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
7823 -- <rest of statement sequence for accept statement>
7825 -- Complete_Rendezvous;
7828 -- when all others =>
7829 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
7831 -- Requeue of a task entry call to a protected entry
7833 -- Accept_Call (E, Ann);
7834 -- <start of statement sequence for accept statement>
7835 -- Requeue_Task_To_Protected_Entry (
7836 -- new._object'Access,
7841 -- <rest of statement sequence for accept statement>
7843 -- Complete_Rendezvous;
7846 -- when all others =>
7847 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
7849 -- Ada 2005 (AI05-0030): Dispatching requeue from protected to interface
7853 -- (O : System.Address;
7854 -- P : System.Address;
7855 -- E : Protected_Entry_Index)
7857 -- <discriminant renamings>
7858 -- <private object renamings>
7859 -- type poVP is access poV;
7860 -- _object : ptVP := ptVP!(O);
7864 -- <start of statement sequence for entry>
7867 -- (<interface class-wide object>,
7870 -- Ada.Tags.Get_Offset_Index
7872 -- <interface dispatch table index of target entry>),
7876 -- <rest of statement sequence for entry>
7877 -- Complete_Entry_Body (_object._object);
7880 -- when all others =>
7881 -- Exceptional_Complete_Entry_Body (
7882 -- _object._object, Get_GNAT_Exception);
7886 -- Ada 2005 (AI05-0030): Dispatching requeue from task to interface
7889 -- Accept_Call (E, Ann);
7890 -- <start of statement sequence for accept statement>
7892 -- (<interface class-wide object>,
7895 -- Ada.Tags.Get_Offset_Index
7897 -- <interface dispatch table index of target entrt>),
7901 -- <rest of statement sequence for accept statement>
7903 -- Complete_Rendezvous;
7906 -- when all others =>
7907 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
7909 -- Further details on these expansions can be found in Expand_N_Protected_
7910 -- Body and Expand_N_Accept_Statement.
7912 procedure Expand_N_Requeue_Statement (N : Node_Id) is
7913 Loc : constant Source_Ptr := Sloc (N);
7914 Abortable : Node_Id;
7916 Conc_Typ : Entity_Id;
7921 New_Param : Node_Id;
7922 Old_Typ : Entity_Id;
7925 RTS_Call : Entity_Id;
7926 Self_Param : Node_Id;
7927 Skip_Stat : Node_Id;
7931 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc);
7933 -- Extract the components of the entry call
7935 Extract_Entry (N, Concval, Ename, Index);
7936 Conc_Typ := Etype (Concval);
7938 -- Examine the scope stack in order to find nearest enclosing protected
7939 -- or task type. This will constitute our invocation source.
7941 Old_Typ := Current_Scope;
7942 while Present (Old_Typ)
7943 and then not Is_Protected_Type (Old_Typ)
7944 and then not Is_Task_Type (Old_Typ)
7946 Old_Typ := Scope (Old_Typ);
7949 -- Generate the parameter list for all cases. The abortable flag is
7950 -- common among dispatching and regular requeue.
7952 Params := New_List (Abortable);
7954 -- Ada 2005 (AI05-0030): We have a dispatching requeue of the form
7955 -- Concval.Ename where the type of Concval is class-wide concurrent
7958 if Ada_Version >= Ada_05
7959 and then Present (Concval)
7960 and then Is_Class_Wide_Type (Conc_Typ)
7961 and then Is_Concurrent_Interface (Conc_Typ)
7963 RTS_Call := Make_Identifier (Loc, Name_uDisp_Requeue);
7966 -- Ada.Tags.Get_Offset_Index
7967 -- (Ada.Tags.Tag (Concval),
7968 -- <interface dispatch table position of Ename>)
7971 Make_Function_Call (Loc,
7973 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
7974 Parameter_Associations =>
7976 Unchecked_Convert_To (RTE (RE_Tag), Concval),
7977 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
7979 -- Specific actuals for protected to interface class-wide type
7982 if Is_Protected_Type (Old_Typ) then
7984 Make_Attribute_Reference (Loc, -- _object'Address
7986 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
7989 Prepend_To (Params, -- True
7990 New_Reference_To (Standard_True, Loc));
7992 -- Specific actuals for task to interface class-wide type requeue
7995 pragma Assert (Is_Task_Type (Old_Typ));
7997 Prepend_To (Params, -- null
7998 New_Reference_To (RTE (RE_Null_Address), Loc));
7999 Prepend_To (Params, -- False
8000 New_Reference_To (Standard_False, Loc));
8003 -- Finally, add the common object parameter
8005 Prepend_To (Params, New_Copy_Tree (Concval));
8007 -- Regular requeue processing
8010 New_Param := Concurrent_Ref (Concval);
8012 -- The index expression is common among all four cases
8015 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8017 if Is_Protected_Type (Old_Typ) then
8019 Make_Attribute_Reference (Loc,
8021 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8023 Name_Unchecked_Access);
8025 -- Protected to protected requeue
8027 if Is_Protected_Type (Conc_Typ) then
8029 New_Reference_To (RTE (RE_Requeue_Protected_Entry), Loc);
8032 Make_Attribute_Reference (Loc,
8036 Name_Unchecked_Access);
8038 -- Protected to task requeue
8041 pragma Assert (Is_Task_Type (Conc_Typ));
8044 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8047 Prepend (New_Param, Params);
8048 Prepend (Self_Param, Params);
8051 pragma Assert (Is_Task_Type (Old_Typ));
8053 -- Task to protected requeue
8055 if Is_Protected_Type (Conc_Typ) then
8058 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8061 Make_Attribute_Reference (Loc,
8065 Name_Unchecked_Access);
8067 -- Task to task requeue
8070 pragma Assert (Is_Task_Type (Conc_Typ));
8072 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8075 Prepend (New_Param, Params);
8079 -- Create the GNARLI or predefined primitive call
8082 Make_Procedure_Call_Statement (Loc,
8084 Parameter_Associations => Params);
8089 if Is_Protected_Type (Old_Typ) then
8091 -- Build the return statement to skip the rest of the entry body
8093 Skip_Stat := Make_Simple_Return_Statement (Loc);
8096 -- If the requeue is within a task, find the end label of the
8097 -- enclosing accept statement.
8099 Acc_Stat := Parent (N);
8100 while Nkind (Acc_Stat) /= N_Accept_Statement loop
8101 Acc_Stat := Parent (Acc_Stat);
8104 -- The last statement is the second label, used for completing the
8105 -- rendezvous the usual way. The label we are looking for is right
8109 Prev (Last (Statements (Handled_Statement_Sequence (Acc_Stat))));
8111 pragma Assert (Nkind (Lab_Node) = N_Label);
8113 -- Build the goto statement to skip the rest of the accept
8117 Make_Goto_Statement (Loc,
8118 Name => New_Occurrence_Of (Entity (Identifier (Lab_Node)), Loc));
8121 Set_Analyzed (Skip_Stat);
8123 Insert_After (N, Skip_Stat);
8124 end Expand_N_Requeue_Statement;
8126 -------------------------------
8127 -- Expand_N_Selective_Accept --
8128 -------------------------------
8130 procedure Expand_N_Selective_Accept (N : Node_Id) is
8131 Loc : constant Source_Ptr := Sloc (N);
8132 Alts : constant List_Id := Select_Alternatives (N);
8134 -- Note: in the below declarations a lot of new lists are allocated
8135 -- unconditionally which may well not end up being used. That's
8136 -- not a good idea since it wastes space gratuitously ???
8138 Accept_Case : List_Id;
8139 Accept_List : constant List_Id := New_List;
8142 Alt_List : constant List_Id := New_List;
8143 Alt_Stats : List_Id;
8144 Ann : Entity_Id := Empty;
8147 Check_Guard : Boolean := True;
8149 Decls : constant List_Id := New_List;
8150 Stats : constant List_Id := New_List;
8151 Body_List : constant List_Id := New_List;
8152 Trailing_List : constant List_Id := New_List;
8155 Else_Present : Boolean := False;
8156 Terminate_Alt : Node_Id := Empty;
8157 Select_Mode : Node_Id;
8159 Delay_Case : List_Id;
8160 Delay_Count : Integer := 0;
8161 Delay_Val : Entity_Id;
8162 Delay_Index : Entity_Id;
8163 Delay_Min : Entity_Id;
8164 Delay_Num : Int := 1;
8165 Delay_Alt_List : List_Id := New_List;
8166 Delay_List : constant List_Id := New_List;
8170 First_Delay : Boolean := True;
8171 Guard_Open : Entity_Id;
8177 Num_Accept : Nat := 0;
8180 Time_Type : Entity_Id;
8182 Select_Call : Node_Id;
8184 Qnam : constant Entity_Id :=
8185 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
8187 Xnam : constant Entity_Id :=
8188 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
8190 -----------------------
8191 -- Local subprograms --
8192 -----------------------
8194 function Accept_Or_Raise return List_Id;
8195 -- For the rare case where delay alternatives all have guards, and
8196 -- all of them are closed, it is still possible that there were open
8197 -- accept alternatives with no callers. We must reexamine the
8198 -- Accept_List, and execute a selective wait with no else if some
8199 -- accept is open. If none, we raise program_error.
8201 procedure Add_Accept (Alt : Node_Id);
8202 -- Process a single accept statement in a select alternative. Build
8203 -- procedure for body of accept, and add entry to dispatch table with
8204 -- expression for guard, in preparation for call to run time select.
8206 function Make_And_Declare_Label (Num : Int) return Node_Id;
8207 -- Manufacture a label using Num as a serial number and declare it.
8208 -- The declaration is appended to Decls. The label marks the trailing
8209 -- statements of an accept or delay alternative.
8211 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
8212 -- Build call to Selective_Wait runtime routine
8214 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
8215 -- Add code to compare value of delay with previous values, and
8216 -- generate case entry for trailing statements.
8218 procedure Process_Accept_Alternative
8222 -- Add code to call corresponding procedure, and branch to
8223 -- trailing statements, if any.
8225 ---------------------
8226 -- Accept_Or_Raise --
8227 ---------------------
8229 function Accept_Or_Raise return List_Id is
8232 J : constant Entity_Id := Make_Defining_Identifier (Loc,
8233 New_Internal_Name ('J'));
8236 -- We generate the following:
8238 -- for J in q'range loop
8239 -- if q(J).S /=null_task_entry then
8240 -- selective_wait (simple_mode,...);
8246 -- if no rendez_vous then
8247 -- raise program_error;
8250 -- Note that the code needs to know that the selector name
8251 -- in an Accept_Alternative is named S.
8253 Cond := Make_Op_Ne (Loc,
8255 Make_Selected_Component (Loc,
8256 Prefix => Make_Indexed_Component (Loc,
8257 Prefix => New_Reference_To (Qnam, Loc),
8258 Expressions => New_List (New_Reference_To (J, Loc))),
8259 Selector_Name => Make_Identifier (Loc, Name_S)),
8261 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
8264 Make_Implicit_Loop_Statement (N,
8265 Identifier => Empty,
8267 Make_Iteration_Scheme (Loc,
8268 Loop_Parameter_Specification =>
8269 Make_Loop_Parameter_Specification (Loc,
8270 Defining_Identifier => J,
8271 Discrete_Subtype_Definition =>
8272 Make_Attribute_Reference (Loc,
8273 Prefix => New_Reference_To (Qnam, Loc),
8274 Attribute_Name => Name_Range,
8275 Expressions => New_List (
8276 Make_Integer_Literal (Loc, 1))))),
8278 Statements => New_List (
8279 Make_Implicit_If_Statement (N,
8281 Then_Statements => New_List (
8283 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
8284 Make_Exit_Statement (Loc))))));
8287 Make_Raise_Program_Error (Loc,
8288 Condition => Make_Op_Eq (Loc,
8289 Left_Opnd => New_Reference_To (Xnam, Loc),
8291 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
8292 Reason => PE_All_Guards_Closed));
8295 end Accept_Or_Raise;
8301 procedure Add_Accept (Alt : Node_Id) is
8302 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
8303 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
8304 Eent : constant Entity_Id := Entity (Ename);
8305 Index : constant Node_Id := Entry_Index (Acc_Stm);
8306 Null_Body : Node_Id;
8307 Proc_Body : Node_Id;
8314 Ann := Node (Last_Elmt (Accept_Address (Eent)));
8317 if Present (Condition (Alt)) then
8319 Make_Conditional_Expression (Loc, New_List (
8321 Entry_Index_Expression (Loc, Eent, Index, Scope (Eent)),
8322 New_Reference_To (RTE (RE_Null_Task_Entry), Loc)));
8325 Entry_Index_Expression
8326 (Loc, Eent, Index, Scope (Eent));
8329 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8330 Null_Body := New_Reference_To (Standard_False, Loc);
8332 if Abort_Allowed then
8333 Call := Make_Procedure_Call_Statement (Loc,
8334 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc));
8335 Insert_Before (First (Statements (Handled_Statement_Sequence (
8336 Accept_Statement (Alt)))), Call);
8341 Make_Defining_Identifier (Sloc (Ename),
8342 New_External_Name (Chars (Ename), 'A', Num_Accept));
8344 Set_Needs_Debug_Info (PB_Ent, Comes_From_Source (Alt));
8347 Make_Subprogram_Body (Loc,
8349 Make_Procedure_Specification (Loc,
8350 Defining_Unit_Name => PB_Ent),
8351 Declarations => Declarations (Acc_Stm),
8352 Handled_Statement_Sequence =>
8353 Build_Accept_Body (Accept_Statement (Alt)));
8355 -- During the analysis of the body of the accept statement, any
8356 -- zero cost exception handler records were collected in the
8357 -- Accept_Handler_Records field of the N_Accept_Alternative node.
8358 -- This is where we move them to where they belong, namely the
8359 -- newly created procedure.
8361 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
8362 Append (Proc_Body, Body_List);
8365 Null_Body := New_Reference_To (Standard_True, Loc);
8367 -- if accept statement has declarations, insert above, given that
8368 -- we are not creating a body for the accept.
8370 if Present (Declarations (Acc_Stm)) then
8371 Insert_Actions (N, Declarations (Acc_Stm));
8375 Append_To (Accept_List,
8376 Make_Aggregate (Loc, Expressions => New_List (Null_Body, Expr)));
8378 Num_Accept := Num_Accept + 1;
8381 ----------------------------
8382 -- Make_And_Declare_Label --
8383 ----------------------------
8385 function Make_And_Declare_Label (Num : Int) return Node_Id is
8389 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
8391 Make_Label (Loc, Lab_Id);
8394 Make_Implicit_Label_Declaration (Loc,
8395 Defining_Identifier =>
8396 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
8397 Label_Construct => Lab));
8400 end Make_And_Declare_Label;
8402 ----------------------
8403 -- Make_Select_Call --
8404 ----------------------
8406 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
8407 Params : constant List_Id := New_List;
8411 Make_Attribute_Reference (Loc,
8412 Prefix => New_Reference_To (Qnam, Loc),
8413 Attribute_Name => Name_Unchecked_Access),
8415 Append (Select_Mode, Params);
8416 Append (New_Reference_To (Ann, Loc), Params);
8417 Append (New_Reference_To (Xnam, Loc), Params);
8420 Make_Procedure_Call_Statement (Loc,
8421 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
8422 Parameter_Associations => Params);
8423 end Make_Select_Call;
8425 --------------------------------
8426 -- Process_Accept_Alternative --
8427 --------------------------------
8429 procedure Process_Accept_Alternative
8434 Choices : List_Id := No_List;
8435 Alt_Stats : List_Id;
8438 Adjust_Condition (Condition (Alt));
8439 Alt_Stats := No_List;
8441 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
8442 Choices := New_List (
8443 Make_Integer_Literal (Loc, Index));
8445 Alt_Stats := New_List (
8446 Make_Procedure_Call_Statement (Loc,
8447 Name => New_Reference_To (
8448 Defining_Unit_Name (Specification (Proc)), Loc)));
8451 if Statements (Alt) /= Empty_List then
8453 if No (Alt_Stats) then
8455 -- Accept with no body, followed by trailing statements
8457 Choices := New_List (
8458 Make_Integer_Literal (Loc, Index));
8460 Alt_Stats := New_List;
8463 -- After the call, if any, branch to to trailing statements. We
8464 -- create a label for each, as well as the corresponding label
8467 Lab := Make_And_Declare_Label (Index);
8468 Append_To (Alt_Stats,
8469 Make_Goto_Statement (Loc,
8470 Name => New_Copy (Identifier (Lab))));
8472 Append (Lab, Trailing_List);
8473 Append_List (Statements (Alt), Trailing_List);
8474 Append_To (Trailing_List,
8475 Make_Goto_Statement (Loc,
8476 Name => New_Copy (Identifier (End_Lab))));
8479 if Present (Alt_Stats) then
8481 -- Procedure call. and/or trailing statements
8483 Append_To (Alt_List,
8484 Make_Case_Statement_Alternative (Loc,
8485 Discrete_Choices => Choices,
8486 Statements => Alt_Stats));
8488 end Process_Accept_Alternative;
8490 -------------------------------
8491 -- Process_Delay_Alternative --
8492 -------------------------------
8494 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
8497 Delay_Alt : List_Id;
8500 -- Deal with C/Fortran boolean as delay condition
8502 Adjust_Condition (Condition (Alt));
8504 -- Determine the smallest specified delay
8506 -- for each delay alternative generate:
8508 -- if guard-expression then
8509 -- Delay_Val := delay-expression;
8510 -- Guard_Open := True;
8511 -- if Delay_Val < Delay_Min then
8512 -- Delay_Min := Delay_Val;
8513 -- Delay_Index := Index;
8517 -- The enclosing if-statement is omitted if there is no guard
8522 First_Delay := False;
8524 Delay_Alt := New_List (
8525 Make_Assignment_Statement (Loc,
8526 Name => New_Reference_To (Delay_Min, Loc),
8527 Expression => Expression (Delay_Statement (Alt))));
8529 if Delay_Count > 1 then
8530 Append_To (Delay_Alt,
8531 Make_Assignment_Statement (Loc,
8532 Name => New_Reference_To (Delay_Index, Loc),
8533 Expression => Make_Integer_Literal (Loc, Index)));
8537 Delay_Alt := New_List (
8538 Make_Assignment_Statement (Loc,
8539 Name => New_Reference_To (Delay_Val, Loc),
8540 Expression => Expression (Delay_Statement (Alt))));
8542 if Time_Type = Standard_Duration then
8545 Left_Opnd => New_Reference_To (Delay_Val, Loc),
8546 Right_Opnd => New_Reference_To (Delay_Min, Loc));
8549 -- The scope of the time type must define a comparison
8550 -- operator. The scope itself may not be visible, so we
8551 -- construct a node with entity information to insure that
8552 -- semantic analysis can find the proper operator.
8555 Make_Function_Call (Loc,
8556 Name => Make_Selected_Component (Loc,
8557 Prefix => New_Reference_To (Scope (Time_Type), Loc),
8559 Make_Operator_Symbol (Loc,
8560 Chars => Name_Op_Lt,
8561 Strval => No_String)),
8562 Parameter_Associations =>
8564 New_Reference_To (Delay_Val, Loc),
8565 New_Reference_To (Delay_Min, Loc)));
8567 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
8570 Append_To (Delay_Alt,
8571 Make_Implicit_If_Statement (N,
8573 Then_Statements => New_List (
8574 Make_Assignment_Statement (Loc,
8575 Name => New_Reference_To (Delay_Min, Loc),
8576 Expression => New_Reference_To (Delay_Val, Loc)),
8578 Make_Assignment_Statement (Loc,
8579 Name => New_Reference_To (Delay_Index, Loc),
8580 Expression => Make_Integer_Literal (Loc, Index)))));
8584 Append_To (Delay_Alt,
8585 Make_Assignment_Statement (Loc,
8586 Name => New_Reference_To (Guard_Open, Loc),
8587 Expression => New_Reference_To (Standard_True, Loc)));
8590 if Present (Condition (Alt)) then
8591 Delay_Alt := New_List (
8592 Make_Implicit_If_Statement (N,
8593 Condition => Condition (Alt),
8594 Then_Statements => Delay_Alt));
8597 Append_List (Delay_Alt, Delay_List);
8599 -- If the delay alternative has a statement part, add choice to the
8600 -- case statements for delays.
8602 if Present (Statements (Alt)) then
8604 if Delay_Count = 1 then
8605 Append_List (Statements (Alt), Delay_Alt_List);
8608 Choices := New_List (
8609 Make_Integer_Literal (Loc, Index));
8611 Append_To (Delay_Alt_List,
8612 Make_Case_Statement_Alternative (Loc,
8613 Discrete_Choices => Choices,
8614 Statements => Statements (Alt)));
8617 elsif Delay_Count = 1 then
8619 -- If the single delay has no trailing statements, add a branch
8620 -- to the exit label to the selective wait.
8622 Delay_Alt_List := New_List (
8623 Make_Goto_Statement (Loc,
8624 Name => New_Copy (Identifier (End_Lab))));
8627 end Process_Delay_Alternative;
8629 -- Start of processing for Expand_N_Selective_Accept
8632 -- First insert some declarations before the select. The first is:
8636 -- This variable holds the parameters passed to the accept body. This
8637 -- declaration has already been inserted by the time we get here by
8638 -- a call to Expand_Accept_Declarations made from the semantics when
8639 -- processing the first accept statement contained in the select. We
8640 -- can find this entity as Accept_Address (E), where E is any of the
8641 -- entries references by contained accept statements.
8643 -- The first step is to scan the list of Selective_Accept_Statements
8644 -- to find this entity, and also count the number of accepts, and
8645 -- determine if terminated, delay or else is present:
8649 Alt := First (Alts);
8650 while Present (Alt) loop
8652 if Nkind (Alt) = N_Accept_Alternative then
8655 elsif Nkind (Alt) = N_Delay_Alternative then
8656 Delay_Count := Delay_Count + 1;
8658 -- If the delays are relative delays, the delay expressions have
8659 -- type Standard_Duration. Otherwise they must have some time type
8660 -- recognized by GNAT.
8662 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
8663 Time_Type := Standard_Duration;
8665 Time_Type := Etype (Expression (Delay_Statement (Alt)));
8667 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
8668 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
8673 "& is not a time type (RM 9.6(6))",
8674 Expression (Delay_Statement (Alt)), Time_Type);
8675 Time_Type := Standard_Duration;
8676 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
8680 if No (Condition (Alt)) then
8682 -- This guard will always be open
8684 Check_Guard := False;
8687 elsif Nkind (Alt) = N_Terminate_Alternative then
8688 Adjust_Condition (Condition (Alt));
8689 Terminate_Alt := Alt;
8692 Num_Alts := Num_Alts + 1;
8696 Else_Present := Present (Else_Statements (N));
8698 -- At the same time (see procedure Add_Accept) we build the accept list:
8700 -- Qnn : Accept_List (1 .. num-select) := (
8701 -- (null-body, entry-index),
8702 -- (null-body, entry-index),
8704 -- (null_body, entry-index));
8706 -- In the above declaration, null-body is True if the corresponding
8707 -- accept has no body, and false otherwise. The entry is either the
8708 -- entry index expression if there is no guard, or if a guard is
8709 -- present, then a conditional expression of the form:
8711 -- (if guard then entry-index else Null_Task_Entry)
8713 -- If a guard is statically known to be false, the entry can simply
8714 -- be omitted from the accept list.
8717 Make_Object_Declaration (Loc,
8718 Defining_Identifier => Qnam,
8719 Object_Definition =>
8720 New_Reference_To (RTE (RE_Accept_List), Loc),
8721 Aliased_Present => True,
8724 Make_Qualified_Expression (Loc,
8726 New_Reference_To (RTE (RE_Accept_List), Loc),
8728 Make_Aggregate (Loc, Expressions => Accept_List)));
8732 -- Then we declare the variable that holds the index for the accept
8733 -- that will be selected for service:
8735 -- Xnn : Select_Index;
8738 Make_Object_Declaration (Loc,
8739 Defining_Identifier => Xnam,
8740 Object_Definition =>
8741 New_Reference_To (RTE (RE_Select_Index), Loc),
8743 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
8747 -- After this follow procedure declarations for each accept body
8754 -- where the ... are statements from the corresponding procedure body.
8755 -- No parameters are involved, since the parameters are passed via Ann
8756 -- and the parameter references have already been expanded to be direct
8757 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
8758 -- any embedded tasking statements (which would normally be illegal in
8759 -- procedures), have been converted to calls to the tasking runtime so
8760 -- there is no problem in putting them into procedures.
8762 -- The original accept statement has been expanded into a block in
8763 -- the same fashion as for simple accepts (see Build_Accept_Body).
8765 -- Note: we don't really need to build these procedures for the case
8766 -- where no delay statement is present, but it is just as easy to
8767 -- build them unconditionally, and not significantly inefficient,
8768 -- since if they are short they will be inlined anyway.
8770 -- The procedure declarations have been assembled in Body_List
8772 -- If delays are present, we must compute the required delay.
8773 -- We first generate the declarations:
8775 -- Delay_Index : Boolean := 0;
8776 -- Delay_Min : Some_Time_Type.Time;
8777 -- Delay_Val : Some_Time_Type.Time;
8779 -- Delay_Index will be set to the index of the minimum delay, i.e. the
8780 -- active delay that is actually chosen as the basis for the possible
8781 -- delay if an immediate rendez-vous is not possible.
8783 -- In the most common case there is a single delay statement, and this
8784 -- is handled specially.
8786 if Delay_Count > 0 then
8788 -- Generate the required declarations
8791 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
8793 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
8795 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
8798 Make_Object_Declaration (Loc,
8799 Defining_Identifier => Delay_Val,
8800 Object_Definition => New_Reference_To (Time_Type, Loc)));
8803 Make_Object_Declaration (Loc,
8804 Defining_Identifier => Delay_Index,
8805 Object_Definition => New_Reference_To (Standard_Integer, Loc),
8806 Expression => Make_Integer_Literal (Loc, 0)));
8809 Make_Object_Declaration (Loc,
8810 Defining_Identifier => Delay_Min,
8811 Object_Definition => New_Reference_To (Time_Type, Loc),
8813 Unchecked_Convert_To (Time_Type,
8814 Make_Attribute_Reference (Loc,
8816 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
8817 Attribute_Name => Name_Last))));
8819 -- Create Duration and Delay_Mode objects used for passing a delay
8822 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
8823 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
8829 -- Note that these values are defined in s-osprim.ads and must
8832 -- Relative : constant := 0;
8833 -- Absolute_Calendar : constant := 1;
8834 -- Absolute_RT : constant := 2;
8836 if Time_Type = Standard_Duration then
8837 Discr := Make_Integer_Literal (Loc, 0);
8839 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
8840 Discr := Make_Integer_Literal (Loc, 1);
8844 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
8845 Discr := Make_Integer_Literal (Loc, 2);
8849 Make_Object_Declaration (Loc,
8850 Defining_Identifier => D,
8851 Object_Definition =>
8852 New_Reference_To (Standard_Duration, Loc)));
8855 Make_Object_Declaration (Loc,
8856 Defining_Identifier => M,
8857 Object_Definition =>
8858 New_Reference_To (Standard_Integer, Loc),
8859 Expression => Discr));
8864 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
8867 Make_Object_Declaration (Loc,
8868 Defining_Identifier => Guard_Open,
8869 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
8870 Expression => New_Reference_To (Standard_False, Loc)));
8873 -- Delay_Count is zero, don't need M and D set (suppress warning)
8880 if Present (Terminate_Alt) then
8882 -- If the terminate alternative guard is False, use
8883 -- Simple_Mode; otherwise use Terminate_Mode.
8885 if Present (Condition (Terminate_Alt)) then
8886 Select_Mode := Make_Conditional_Expression (Loc,
8887 New_List (Condition (Terminate_Alt),
8888 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
8889 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
8891 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
8894 elsif Else_Present or Delay_Count > 0 then
8895 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
8898 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
8901 Select_Call := Make_Select_Call (Select_Mode);
8902 Append (Select_Call, Stats);
8904 -- Now generate code to act on the result. There is an entry
8905 -- in this case for each accept statement with a non-null body,
8906 -- followed by a branch to the statements that follow the Accept.
8907 -- In the absence of delay alternatives, we generate:
8910 -- when No_Rendezvous => -- omitted if simple mode
8925 -- Lab0: Else_Statements;
8928 -- Lab1: Trailing_Statements1;
8931 -- Lab2: Trailing_Statements2;
8936 -- Generate label for common exit
8938 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
8940 -- First entry is the default case, when no rendezvous is possible
8942 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
8944 if Else_Present then
8946 -- If no rendezvous is possible, the else part is executed
8948 Lab := Make_And_Declare_Label (0);
8949 Alt_Stats := New_List (
8950 Make_Goto_Statement (Loc,
8951 Name => New_Copy (Identifier (Lab))));
8953 Append (Lab, Trailing_List);
8954 Append_List (Else_Statements (N), Trailing_List);
8955 Append_To (Trailing_List,
8956 Make_Goto_Statement (Loc,
8957 Name => New_Copy (Identifier (End_Lab))));
8959 Alt_Stats := New_List (
8960 Make_Goto_Statement (Loc,
8961 Name => New_Copy (Identifier (End_Lab))));
8964 Append_To (Alt_List,
8965 Make_Case_Statement_Alternative (Loc,
8966 Discrete_Choices => Choices,
8967 Statements => Alt_Stats));
8969 -- We make use of the fact that Accept_Index is an integer type, and
8970 -- generate successive literals for entries for each accept. Only those
8971 -- for which there is a body or trailing statements get a case entry.
8973 Alt := First (Select_Alternatives (N));
8974 Proc := First (Body_List);
8975 while Present (Alt) loop
8977 if Nkind (Alt) = N_Accept_Alternative then
8978 Process_Accept_Alternative (Alt, Index, Proc);
8982 (Handled_Statement_Sequence (Accept_Statement (Alt)))
8987 elsif Nkind (Alt) = N_Delay_Alternative then
8988 Process_Delay_Alternative (Alt, Delay_Num);
8989 Delay_Num := Delay_Num + 1;
8995 -- An others choice is always added to the main case, as well
8996 -- as the delay case (to satisfy the compiler).
8998 Append_To (Alt_List,
8999 Make_Case_Statement_Alternative (Loc,
9001 New_List (Make_Others_Choice (Loc)),
9003 New_List (Make_Goto_Statement (Loc,
9004 Name => New_Copy (Identifier (End_Lab))))));
9006 Accept_Case := New_List (
9007 Make_Case_Statement (Loc,
9008 Expression => New_Reference_To (Xnam, Loc),
9009 Alternatives => Alt_List));
9011 Append_List (Trailing_List, Accept_Case);
9012 Append (End_Lab, Accept_Case);
9013 Append_List (Body_List, Decls);
9015 -- Construct case statement for trailing statements of delay
9016 -- alternatives, if there are several of them.
9018 if Delay_Count > 1 then
9019 Append_To (Delay_Alt_List,
9020 Make_Case_Statement_Alternative (Loc,
9022 New_List (Make_Others_Choice (Loc)),
9024 New_List (Make_Null_Statement (Loc))));
9026 Delay_Case := New_List (
9027 Make_Case_Statement (Loc,
9028 Expression => New_Reference_To (Delay_Index, Loc),
9029 Alternatives => Delay_Alt_List));
9031 Delay_Case := Delay_Alt_List;
9034 -- If there are no delay alternatives, we append the case statement
9035 -- to the statement list.
9037 if Delay_Count = 0 then
9038 Append_List (Accept_Case, Stats);
9040 -- Delay alternatives present
9043 -- If delay alternatives are present we generate:
9045 -- find minimum delay.
9046 -- DX := minimum delay;
9047 -- M := <delay mode>;
9048 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9051 -- if X = No_Rendezvous then
9052 -- case statement for delay statements.
9054 -- case statement for accept alternatives.
9065 -- The type of the delay expression is known to be legal
9067 if Time_Type = Standard_Duration then
9068 Conv := New_Reference_To (Delay_Min, Loc);
9070 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9071 Conv := Make_Function_Call (Loc,
9072 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
9073 New_List (New_Reference_To (Delay_Min, Loc)));
9077 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9079 Conv := Make_Function_Call (Loc,
9080 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
9081 New_List (New_Reference_To (Delay_Min, Loc)));
9084 Stmt := Make_Assignment_Statement (Loc,
9085 Name => New_Reference_To (D, Loc),
9086 Expression => Conv);
9088 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
9090 Parms := Parameter_Associations (Select_Call);
9091 Parm := First (Parms);
9093 while Present (Parm)
9094 and then Parm /= Select_Mode
9099 pragma Assert (Present (Parm));
9100 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
9103 -- Prepare two new parameters of Duration and Delay_Mode type
9104 -- which represent the value and the mode of the minimum delay.
9107 Insert_After (Parm, New_Reference_To (M, Loc));
9108 Insert_After (Parm, New_Reference_To (D, Loc));
9110 -- Create a call to RTS
9112 Rewrite (Select_Call,
9113 Make_Procedure_Call_Statement (Loc,
9114 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
9115 Parameter_Associations => Parms));
9117 -- This new call should follow the calculation of the minimum
9120 Insert_List_Before (Select_Call, Delay_List);
9124 Make_Implicit_If_Statement (N,
9125 Condition => New_Reference_To (Guard_Open, Loc),
9127 New_List (New_Copy_Tree (Stmt),
9128 New_Copy_Tree (Select_Call)),
9129 Else_Statements => Accept_Or_Raise);
9130 Rewrite (Select_Call, Stmt);
9132 Insert_Before (Select_Call, Stmt);
9136 Make_Implicit_If_Statement (N,
9137 Condition => Make_Op_Eq (Loc,
9138 Left_Opnd => New_Reference_To (Xnam, Loc),
9140 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9142 Then_Statements => Delay_Case,
9143 Else_Statements => Accept_Case);
9145 Append (Cases, Stats);
9149 -- Replace accept statement with appropriate block
9152 Make_Block_Statement (Loc,
9153 Declarations => Decls,
9154 Handled_Statement_Sequence =>
9155 Make_Handled_Sequence_Of_Statements (Loc,
9156 Statements => Stats));
9161 -- Note: have to worry more about abort deferral in above code ???
9163 -- Final step is to unstack the Accept_Address entries for all accept
9164 -- statements appearing in accept alternatives in the select statement
9166 Alt := First (Alts);
9167 while Present (Alt) loop
9168 if Nkind (Alt) = N_Accept_Alternative then
9169 Remove_Last_Elmt (Accept_Address
9170 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
9175 end Expand_N_Selective_Accept;
9177 --------------------------------------
9178 -- Expand_N_Single_Task_Declaration --
9179 --------------------------------------
9181 -- Single task declarations should never be present after semantic
9182 -- analysis, since we expect them to be replaced by a declaration of an
9183 -- anonymous task type, followed by a declaration of the task object. We
9184 -- include this routine to make sure that is happening!
9186 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
9188 raise Program_Error;
9189 end Expand_N_Single_Task_Declaration;
9191 ------------------------
9192 -- Expand_N_Task_Body --
9193 ------------------------
9195 -- Given a task body
9197 -- task body tname is
9203 -- This expansion routine converts it into a procedure and sets the
9204 -- elaboration flag for the procedure to true, to represent the fact
9205 -- that the task body is now elaborated:
9207 -- procedure tnameB (_Task : access tnameV) is
9208 -- discriminal : dtype renames _Task.discriminant;
9210 -- procedure _clean is
9214 -- Abort_Undefer.all;
9219 -- Abort_Undefer.all;
9221 -- System.Task_Stages.Complete_Activation;
9229 -- In addition, if the task body is an activator, then a call to activate
9230 -- tasks is added at the start of the statements, before the call to
9231 -- Complete_Activation, and if in addition the task is a master then it
9232 -- must be established as a master. These calls are inserted and analyzed
9233 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
9236 -- There is one discriminal declaration line generated for each
9237 -- discriminant that is present to provide an easy reference point for
9238 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
9240 -- Note on relationship to GNARLI definition. In the GNARLI definition,
9241 -- task body procedures have a profile (Arg : System.Address). That is
9242 -- needed because GNARLI has to use the same access-to-subprogram type
9243 -- for all task types. We depend here on knowing that in GNAT, passing
9244 -- an address argument by value is identical to passing a record value
9245 -- by access (in either case a single pointer is passed), so even though
9246 -- this procedure has the wrong profile. In fact it's all OK, since the
9247 -- callings sequence is identical.
9249 procedure Expand_N_Task_Body (N : Node_Id) is
9250 Loc : constant Source_Ptr := Sloc (N);
9251 Ttyp : constant Entity_Id := Corresponding_Spec (N);
9256 -- Here we start the expansion by generating discriminal declarations
9258 Add_Discriminal_Declarations (Declarations (N), Ttyp, Name_uTask, Loc);
9260 -- Add a call to Abort_Undefer at the very beginning of the task
9261 -- body since this body is called with abort still deferred.
9263 if Abort_Allowed then
9264 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
9266 (First (Statements (Handled_Statement_Sequence (N))), Call);
9270 -- The statement part has already been protected with an at_end and
9271 -- cleanup actions. The call to Complete_Activation must be placed
9272 -- at the head of the sequence of statements of that block. The
9273 -- declarations have been merged in this sequence of statements but
9274 -- the first real statement is accessible from the First_Real_Statement
9275 -- field (which was set for exactly this purpose).
9277 if Restricted_Profile then
9278 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
9280 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
9284 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
9288 Make_Subprogram_Body (Loc,
9289 Specification => Build_Task_Proc_Specification (Ttyp),
9290 Declarations => Declarations (N),
9291 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
9293 -- If the task contains generic instantiations, cleanup actions
9294 -- are delayed until after instantiation. Transfer the activation
9295 -- chain to the subprogram, to insure that the activation call is
9296 -- properly generated. It the task body contains inner tasks, indicate
9297 -- that the subprogram is a task master.
9299 if Delay_Cleanups (Ttyp) then
9300 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
9301 Set_Is_Task_Master (New_N, Is_Task_Master (N));
9307 -- Set elaboration flag immediately after task body. If the body is a
9308 -- subunit, the flag is set in the declarative part containing the stub.
9310 if Nkind (Parent (N)) /= N_Subunit then
9312 Make_Assignment_Statement (Loc,
9314 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
9315 Expression => New_Reference_To (Standard_True, Loc)));
9318 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
9319 -- the task body. At this point the entry specs have been created,
9320 -- frozen and included in the dispatch table for the task type.
9322 pragma Assert (Present (Corresponding_Record_Type (Ttyp)));
9324 if Ada_Version >= Ada_05
9325 and then Present (Task_Definition (Parent (Ttyp)))
9326 and then Present (Abstract_Interfaces
9327 (Corresponding_Record_Type (Ttyp)))
9330 Current_Node : Node_Id;
9331 Vis_Decl : Node_Id :=
9332 First (Visible_Declarations (Task_Definition (Parent (Ttyp))));
9333 Wrap_Body : Node_Id;
9336 if Nkind (Parent (N)) = N_Subunit then
9337 Current_Node := Corresponding_Stub (Parent (N));
9342 -- Examine the visible declarations of the task type, looking for
9343 -- an entry declaration. We do not consider entry families since
9344 -- they cannot have dispatching operations, thus they do not need
9347 while Present (Vis_Decl) loop
9348 if Nkind (Vis_Decl) = N_Entry_Declaration
9349 and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry
9352 -- Create the specification of the wrapper
9355 Build_Wrapper_Body (Loc,
9356 Proc_Nam => Defining_Identifier (Vis_Decl),
9357 Obj_Typ => Corresponding_Record_Type (Ttyp),
9358 Formals => Parameter_Specifications (Vis_Decl));
9360 if Wrap_Body /= Empty then
9361 Insert_After (Current_Node, Wrap_Body);
9362 Current_Node := Wrap_Body;
9364 Analyze (Wrap_Body);
9372 end Expand_N_Task_Body;
9374 ------------------------------------
9375 -- Expand_N_Task_Type_Declaration --
9376 ------------------------------------
9378 -- We have several things to do. First we must create a Boolean flag used
9379 -- to mark if the body is elaborated yet. This variable gets set to True
9380 -- when the body of the task is elaborated (we can't rely on the normal
9381 -- ABE mechanism for the task body, since we need to pass an access to
9382 -- this elaboration boolean to the runtime routines).
9384 -- taskE : aliased Boolean := False;
9386 -- Next a variable is declared to hold the task stack size (either the
9387 -- default : Unspecified_Size, or a value that is set by a pragma
9388 -- Storage_Size). If the value of the pragma Storage_Size is static, then
9389 -- the variable is initialized with this value:
9391 -- taskZ : Size_Type := Unspecified_Size;
9393 -- taskZ : Size_Type := Size_Type (size_expression);
9395 -- Next we create a corresponding record type declaration used to represent
9396 -- values of this task. The general form of this type declaration is
9398 -- type taskV (discriminants) is record
9399 -- _Task_Id : Task_Id;
9400 -- entry_family : array (bounds) of Void;
9401 -- _Priority : Integer := priority_expression;
9402 -- _Size : Size_Type := Size_Type (size_expression);
9403 -- _Task_Info : Task_Info_Type := task_info_expression;
9406 -- The discriminants are present only if the corresponding task type has
9407 -- discriminants, and they exactly mirror the task type discriminants.
9409 -- The Id field is always present. It contains the Task_Id value, as set by
9410 -- the call to Create_Task. Note that although the task is limited, the
9411 -- task value record type is not limited, so there is no problem in passing
9412 -- this field as an out parameter to Create_Task.
9414 -- One entry_family component is present for each entry family in the task
9415 -- definition. The bounds correspond to the bounds of the entry family
9416 -- (which may depend on discriminants). The element type is void, since we
9417 -- only need the bounds information for determining the entry index. Note
9418 -- that the use of an anonymous array would normally be illegal in this
9419 -- context, but this is a parser check, and the semantics is quite prepared
9420 -- to handle such a case.
9422 -- The _Size field is present only if a Storage_Size pragma appears in the
9423 -- task definition. The expression captures the argument that was present
9424 -- in the pragma, and is used to override the task stack size otherwise
9425 -- associated with the task type.
9427 -- The _Priority field is present only if a Priority or Interrupt_Priority
9428 -- pragma appears in the task definition. The expression captures the
9429 -- argument that was present in the pragma, and is used to provide the Size
9430 -- parameter to the call to Create_Task.
9432 -- The _Task_Info field is present only if a Task_Info pragma appears in
9433 -- the task definition. The expression captures the argument that was
9434 -- present in the pragma, and is used to provide the Task_Image parameter
9435 -- to the call to Create_Task.
9437 -- When a task is declared, an instance of the task value record is
9438 -- created. The elaboration of this declaration creates the correct bounds
9439 -- for the entry families, and also evaluates the size, priority, and
9440 -- task_Info expressions if needed. The initialization routine for the task
9441 -- type itself then calls Create_Task with appropriate parameters to
9442 -- initialize the value of the Task_Id field.
9444 -- Note: the address of this record is passed as the "Discriminants"
9445 -- parameter for Create_Task. Since Create_Task merely passes this onto the
9446 -- body procedure, it does not matter that it does not quite match the
9447 -- GNARLI model of what is being passed (the record contains more than just
9448 -- the discriminants, but the discriminants can be found from the record
9451 -- The Entity_Id for this created record type is placed in the
9452 -- Corresponding_Record_Type field of the associated task type entity.
9454 -- Next we create a procedure specification for the task body procedure:
9456 -- procedure taskB (_Task : access taskV);
9458 -- Note that this must come after the record type declaration, since
9459 -- the spec refers to this type. It turns out that the initialization
9460 -- procedure for the value type references the task body spec, but that's
9461 -- fine, since it won't be generated till the freeze point for the type,
9462 -- which is certainly after the task body spec declaration.
9464 -- Finally, we set the task index value field of the entry attribute in
9465 -- the case of a simple entry.
9467 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
9468 Loc : constant Source_Ptr := Sloc (N);
9469 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
9470 Tasknm : constant Name_Id := Chars (Tasktyp);
9471 Taskdef : constant Node_Id := Task_Definition (N);
9473 Proc_Spec : Node_Id;
9475 Rec_Ent : Entity_Id;
9477 Elab_Decl : Node_Id;
9478 Size_Decl : Node_Id;
9479 Body_Decl : Node_Id;
9480 Task_Size : Node_Id;
9481 Ent_Stack : Entity_Id;
9482 Decl_Stack : Node_Id;
9485 -- If already expanded, nothing to do
9487 if Present (Corresponding_Record_Type (Tasktyp)) then
9491 -- Here we will do the expansion
9493 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
9495 -- Ada 2005 (AI-345): Propagate the attribute that contains the list
9496 -- of implemented interfaces.
9498 Set_Interface_List (Type_Definition (Rec_Decl), Interface_List (N));
9500 Rec_Ent := Defining_Identifier (Rec_Decl);
9501 Cdecls := Component_Items (Component_List
9502 (Type_Definition (Rec_Decl)));
9504 Qualify_Entity_Names (N);
9506 -- First create the elaboration variable
9509 Make_Object_Declaration (Loc,
9510 Defining_Identifier =>
9511 Make_Defining_Identifier (Sloc (Tasktyp),
9512 Chars => New_External_Name (Tasknm, 'E')),
9513 Aliased_Present => True,
9514 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9515 Expression => New_Reference_To (Standard_False, Loc));
9516 Insert_After (N, Elab_Decl);
9518 -- Next create the declaration of the size variable (tasknmZ)
9520 Set_Storage_Size_Variable (Tasktyp,
9521 Make_Defining_Identifier (Sloc (Tasktyp),
9522 Chars => New_External_Name (Tasknm, 'Z')));
9524 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
9525 Is_Static_Expression (Expression (First (
9526 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
9527 Taskdef, Name_Storage_Size)))))
9530 Make_Object_Declaration (Loc,
9531 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9532 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9534 Convert_To (RTE (RE_Size_Type),
9537 Pragma_Argument_Associations (
9538 Find_Task_Or_Protected_Pragma
9539 (Taskdef, Name_Storage_Size)))))));
9543 Make_Object_Declaration (Loc,
9544 Defining_Identifier => Storage_Size_Variable (Tasktyp),
9545 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
9546 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
9549 Insert_After (Elab_Decl, Size_Decl);
9551 -- Next build the rest of the corresponding record declaration. This is
9552 -- done last, since the corresponding record initialization procedure
9553 -- will reference the previously created entities.
9555 -- Fill in the component declarations -- first the _Task_Id field
9558 Make_Component_Declaration (Loc,
9559 Defining_Identifier =>
9560 Make_Defining_Identifier (Loc, Name_uTask_Id),
9561 Component_Definition =>
9562 Make_Component_Definition (Loc,
9563 Aliased_Present => False,
9564 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
9567 -- Declare static ATCB (that is, created by the expander) if we are
9568 -- using the Restricted run time.
9570 if Restricted_Profile then
9572 Make_Component_Declaration (Loc,
9573 Defining_Identifier =>
9574 Make_Defining_Identifier (Loc, Name_uATCB),
9576 Component_Definition =>
9577 Make_Component_Definition (Loc,
9578 Aliased_Present => True,
9579 Subtype_Indication => Make_Subtype_Indication (Loc,
9580 Subtype_Mark => New_Occurrence_Of
9581 (RTE (RE_Ada_Task_Control_Block), Loc),
9584 Make_Index_Or_Discriminant_Constraint (Loc,
9586 New_List (Make_Integer_Literal (Loc, 0)))))));
9590 -- Declare static stack (that is, created by the expander) if we are
9591 -- using the Restricted run time on a bare board configuration.
9593 if Restricted_Profile
9594 and then Preallocated_Stacks_On_Target
9596 -- First we need to extract the appropriate stack size
9598 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
9600 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
9602 Expr_N : constant Node_Id :=
9604 Pragma_Argument_Associations (
9605 Find_Task_Or_Protected_Pragma
9606 (Taskdef, Name_Storage_Size))));
9607 Etyp : constant Entity_Id := Etype (Expr_N);
9608 P : constant Node_Id := Parent (Expr_N);
9611 -- The stack is defined inside the corresponding record.
9612 -- Therefore if the size of the stack is set by means of
9613 -- a discriminant, we must reference the discriminant of the
9614 -- corresponding record type.
9616 if Nkind (Expr_N) in N_Has_Entity
9617 and then Present (Discriminal_Link (Entity (Expr_N)))
9621 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
9623 Set_Parent (Task_Size, P);
9624 Set_Etype (Task_Size, Etyp);
9625 Set_Analyzed (Task_Size);
9628 Task_Size := Relocate_Node (Expr_N);
9634 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
9637 Decl_Stack := Make_Component_Declaration (Loc,
9638 Defining_Identifier => Ent_Stack,
9640 Component_Definition =>
9641 Make_Component_Definition (Loc,
9642 Aliased_Present => True,
9643 Subtype_Indication => Make_Subtype_Indication (Loc,
9645 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
9648 Make_Index_Or_Discriminant_Constraint (Loc,
9649 Constraints => New_List (Make_Range (Loc,
9650 Low_Bound => Make_Integer_Literal (Loc, 1),
9651 High_Bound => Convert_To (RTE (RE_Storage_Offset),
9654 Append_To (Cdecls, Decl_Stack);
9656 -- The appropriate alignment for the stack is ensured by the run-time
9657 -- code in charge of task creation.
9661 -- Add components for entry families
9663 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
9665 -- Add the _Priority component if a Priority pragma is present
9667 if Present (Taskdef) and then Has_Priority_Pragma (Taskdef) then
9669 Prag : constant Node_Id :=
9670 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
9674 Expr := First (Pragma_Argument_Associations (Prag));
9676 if Nkind (Expr) = N_Pragma_Argument_Association then
9677 Expr := Expression (Expr);
9680 Expr := New_Copy_Tree (Expr);
9682 -- Add conversion to proper type to do range check if required
9683 -- Note that for runtime units, we allow out of range interrupt
9684 -- priority values to be used in a priority pragma. This is for
9685 -- the benefit of some versions of System.Interrupts which use
9686 -- a special server task with maximum interrupt priority.
9688 if Chars (Prag) = Name_Priority
9689 and then not GNAT_Mode
9691 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
9693 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
9697 Make_Component_Declaration (Loc,
9698 Defining_Identifier =>
9699 Make_Defining_Identifier (Loc, Name_uPriority),
9700 Component_Definition =>
9701 Make_Component_Definition (Loc,
9702 Aliased_Present => False,
9703 Subtype_Indication => New_Reference_To (Standard_Integer,
9705 Expression => Expr));
9709 -- Add the _Task_Size component if a Storage_Size pragma is present
9711 if Present (Taskdef)
9712 and then Has_Storage_Size_Pragma (Taskdef)
9715 Make_Component_Declaration (Loc,
9716 Defining_Identifier =>
9717 Make_Defining_Identifier (Loc, Name_uSize),
9719 Component_Definition =>
9720 Make_Component_Definition (Loc,
9721 Aliased_Present => False,
9722 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
9726 Convert_To (RTE (RE_Size_Type),
9729 Pragma_Argument_Associations (
9730 Find_Task_Or_Protected_Pragma
9731 (Taskdef, Name_Storage_Size))))))));
9734 -- Add the _Task_Info component if a Task_Info pragma is present
9736 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
9738 Make_Component_Declaration (Loc,
9739 Defining_Identifier =>
9740 Make_Defining_Identifier (Loc, Name_uTask_Info),
9742 Component_Definition =>
9743 Make_Component_Definition (Loc,
9744 Aliased_Present => False,
9745 Subtype_Indication =>
9746 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
9748 Expression => New_Copy (
9750 Pragma_Argument_Associations (
9751 Find_Task_Or_Protected_Pragma
9752 (Taskdef, Name_Task_Info)))))));
9755 Insert_After (Size_Decl, Rec_Decl);
9757 -- Analyze the record declaration immediately after construction,
9758 -- because the initialization procedure is needed for single task
9759 -- declarations before the next entity is analyzed.
9763 -- Create the declaration of the task body procedure
9765 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
9767 Make_Subprogram_Declaration (Loc,
9768 Specification => Proc_Spec);
9770 Insert_After (Rec_Decl, Body_Decl);
9772 -- The subprogram does not comes from source, so we have to indicate the
9773 -- need for debugging information explicitly.
9775 Set_Needs_Debug_Info
9776 (Defining_Entity (Proc_Spec), Comes_From_Source (Original_Node (N)));
9778 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
9779 -- the corresponding record has been frozen.
9781 if Ada_Version >= Ada_05
9782 and then Present (Taskdef)
9783 and then Present (Corresponding_Record_Type
9784 (Defining_Identifier (Parent (Taskdef))))
9785 and then Present (Abstract_Interfaces
9786 (Corresponding_Record_Type
9787 (Defining_Identifier (Parent (Taskdef)))))
9790 Current_Node : Node_Id := Rec_Decl;
9791 Vis_Decl : Node_Id := First (Visible_Declarations (Taskdef));
9792 Wrap_Spec : Node_Id;
9796 -- Examine the visible declarations of the task type, looking for
9797 -- an entry declaration. We do not consider entry families since
9798 -- they cannot have dispatching operations, thus they do not need
9801 while Present (Vis_Decl) loop
9802 if Nkind (Vis_Decl) = N_Entry_Declaration
9803 and then Ekind (Defining_Identifier (Vis_Decl)) = E_Entry
9806 Build_Wrapper_Spec (Loc,
9807 Proc_Nam => Defining_Identifier (Vis_Decl),
9808 Obj_Typ => Etype (Rec_Ent),
9809 Formals => Parameter_Specifications (Vis_Decl));
9811 if Wrap_Spec /= Empty then
9813 Make_Subprogram_Declaration (Loc,
9814 Specification => Wrap_Spec);
9816 Insert_After (Current_Node, New_N);
9817 Current_Node := New_N;
9828 -- Ada 2005 (AI-345): We must defer freezing to allow further
9829 -- declaration of primitive subprograms covering task interfaces
9831 if Ada_Version <= Ada_95 then
9833 -- Now we can freeze the corresponding record. This needs manually
9834 -- freezing, since it is really part of the task type, and the task
9835 -- type is frozen at this stage. We of course need the initialization
9836 -- procedure for this corresponding record type and we won't get it
9837 -- in time if we don't freeze now.
9840 L : constant List_Id := Freeze_Entity (Rec_Ent, Loc);
9843 if Is_Non_Empty_List (L) then
9844 Insert_List_After (Body_Decl, L);
9849 -- Complete the expansion of access types to the current task type, if
9850 -- any were declared.
9852 Expand_Previous_Access_Type (Tasktyp);
9853 end Expand_N_Task_Type_Declaration;
9855 -------------------------------
9856 -- Expand_N_Timed_Entry_Call --
9857 -------------------------------
9859 -- A timed entry call in normal case is not implemented using ATC mechanism
9860 -- anymore for efficiency reason.
9870 -- is expanded as follow:
9872 -- 1) When T.E is a task entry_call;
9876 -- X : Task_Entry_Index := <entry index>;
9877 -- DX : Duration := To_Duration (D);
9878 -- M : Delay_Mode := <discriminant>;
9879 -- P : parms := (parm, parm, parm);
9882 -- Timed_Protected_Entry_Call
9883 -- (<acceptor-task>, X, P'Address, DX, M, B);
9891 -- 2) When T.E is a protected entry_call;
9895 -- X : Protected_Entry_Index := <entry index>;
9896 -- DX : Duration := To_Duration (D);
9897 -- M : Delay_Mode := <discriminant>;
9898 -- P : parms := (parm, parm, parm);
9901 -- Timed_Protected_Entry_Call
9902 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
9910 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
9913 -- B : Boolean := False;
9914 -- C : Ada.Tags.Prim_Op_Kind;
9915 -- DX : Duration := To_Duration (D)
9916 -- K : Ada.Tags.Tagged_Kind :=
9917 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
9918 -- M : Integer :=...;
9919 -- P : Parameters := (Param1 .. ParamN);
9923 -- if K = Ada.Tags.TK_Limited_Tagged then
9924 -- <dispatching-call>;
9925 -- <triggering-statements>
9929 -- Ada.Tags.Get_Offset_Index
9930 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
9932 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
9934 -- if C = POK_Protected_Entry
9935 -- or else C = POK_Task_Entry
9937 -- Param1 := P.Param1;
9939 -- ParamN := P.ParamN;
9943 -- if C = POK_Procedure
9944 -- or else C = POK_Protected_Procedure
9945 -- or else C = POK_Task_Procedure
9947 -- <dispatching-call>;
9950 -- <triggering-statements>
9952 -- <timed-statements>
9957 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
9958 Loc : constant Source_Ptr := Sloc (N);
9961 Entry_Call_Statement (Entry_Call_Alternative (N));
9962 E_Stats : constant List_Id :=
9963 Statements (Entry_Call_Alternative (N));
9965 Delay_Statement (Delay_Alternative (N));
9966 D_Stats : constant List_Id :=
9967 Statements (Delay_Alternative (N));
9970 Blk_Typ : Entity_Id;
9972 Call_Ent : Entity_Id;
9973 Conc_Typ_Stmts : List_Id;
9983 Is_Disp_Select : Boolean;
9984 Lim_Typ_Stmts : List_Id;
9993 B : Entity_Id; -- Call status flag
9994 C : Entity_Id; -- Call kind
9995 D : Entity_Id; -- Delay
9996 K : Entity_Id; -- Tagged kind
9997 M : Entity_Id; -- Delay mode
9998 P : Entity_Id; -- Parameter block
9999 S : Entity_Id; -- Primitive operation slot
10002 -- The arguments in the call may require dynamic allocation, and the
10003 -- call statement may have been transformed into a block. The block
10004 -- may contain additional declarations for internal entities, and the
10005 -- original call is found by sequential search.
10007 if Nkind (E_Call) = N_Block_Statement then
10008 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10009 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10010 N_Entry_Call_Statement)
10017 Ada_Version >= Ada_05
10018 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10020 if Is_Disp_Select then
10021 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
10027 -- B : Boolean := False;
10029 B := Build_B (Loc, Decls);
10032 -- C : Ada.Tags.Prim_Op_Kind;
10034 C := Build_C (Loc, Decls);
10036 -- Because the analysis of all statements was disabled, manually
10037 -- analyze the delay statement.
10040 D_Stat := Original_Node (D_Stat);
10043 -- Build an entry call using Simple_Entry_Call
10045 Extract_Entry (E_Call, Concval, Ename, Index);
10046 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
10048 Decls := Declarations (E_Call);
10049 Stmts := Statements (Handled_Statement_Sequence (E_Call));
10058 B := Make_Defining_Identifier (Loc, Name_uB);
10061 Make_Object_Declaration (Loc,
10062 Defining_Identifier =>
10064 Object_Definition =>
10065 New_Reference_To (Standard_Boolean, Loc)));
10068 -- Duration and mode processing
10070 D_Type := Base_Type (Etype (Expression (D_Stat)));
10072 -- Use the type of the delay expression (Calendar or Real_Time) to
10073 -- generate the appropriate conversion.
10075 if Nkind (D_Stat) = N_Delay_Relative_Statement then
10076 D_Disc := Make_Integer_Literal (Loc, 0);
10077 D_Conv := Relocate_Node (Expression (D_Stat));
10079 elsif Is_RTE (D_Type, RO_CA_Time) then
10080 D_Disc := Make_Integer_Literal (Loc, 1);
10081 D_Conv := Make_Function_Call (Loc,
10082 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10083 New_List (New_Copy (Expression (D_Stat))));
10085 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
10086 D_Disc := Make_Integer_Literal (Loc, 2);
10087 D_Conv := Make_Function_Call (Loc,
10088 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10089 New_List (New_Copy (Expression (D_Stat))));
10092 D := Make_Defining_Identifier (Loc, New_Internal_Name ('D'));
10098 Make_Object_Declaration (Loc,
10099 Defining_Identifier =>
10101 Object_Definition =>
10102 New_Reference_To (Standard_Duration, Loc)));
10104 M := Make_Defining_Identifier (Loc, New_Internal_Name ('M'));
10107 -- M : Integer := (0 | 1 | 2);
10110 Make_Object_Declaration (Loc,
10111 Defining_Identifier =>
10113 Object_Definition =>
10114 New_Reference_To (Standard_Integer, Loc),
10118 -- Do the assignment at this stage only because the evaluation of the
10119 -- expression must not occur before (see ACVC C97302A).
10122 Make_Assignment_Statement (Loc,
10124 New_Reference_To (D, Loc),
10128 -- Parameter block processing
10130 -- Manually create the parameter block for dispatching calls. In the
10131 -- case of entries, the block has already been created during the call
10132 -- to Build_Simple_Entry_Call.
10134 if Is_Disp_Select then
10136 -- Tagged kind processing, generate:
10137 -- K : Ada.Tags.Tagged_Kind :=
10138 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
10140 K := Build_K (Loc, Decls, Obj);
10142 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
10143 P := Parameter_Block_Pack
10144 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
10146 -- Dispatch table slot processing, generate:
10149 S := Build_S (Loc, Decls);
10152 -- S := Ada.Tags.Get_Offset_Index
10153 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
10156 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
10159 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
10161 -- where Obj is the controlling formal parameter, S is the dispatch
10162 -- table slot number of the dispatching operation, P is the wrapped
10163 -- parameter block, D is the duration, M is the duration mode, C is
10164 -- the call kind and B is the call status.
10166 Params := New_List;
10168 Append_To (Params, New_Copy_Tree (Obj));
10169 Append_To (Params, New_Reference_To (S, Loc));
10170 Append_To (Params, Make_Attribute_Reference (Loc,
10171 Prefix => New_Reference_To (P, Loc),
10172 Attribute_Name => Name_Address));
10173 Append_To (Params, New_Reference_To (D, Loc));
10174 Append_To (Params, New_Reference_To (M, Loc));
10175 Append_To (Params, New_Reference_To (C, Loc));
10176 Append_To (Params, New_Reference_To (B, Loc));
10178 Append_To (Conc_Typ_Stmts,
10179 Make_Procedure_Call_Statement (Loc,
10182 Find_Prim_Op (Etype (Etype (Obj)),
10183 Name_uDisp_Timed_Select),
10185 Parameter_Associations =>
10189 -- if C = POK_Protected_Entry
10190 -- or else C = POK_Task_Entry
10192 -- Param1 := P.Param1;
10194 -- ParamN := P.ParamN;
10197 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
10199 -- Generate the if statement only when the packed parameters need
10200 -- explicit assignments to their corresponding actuals.
10202 if Present (Unpack) then
10203 Append_To (Conc_Typ_Stmts,
10204 Make_If_Statement (Loc,
10211 New_Reference_To (C, Loc),
10213 New_Reference_To (RTE (
10214 RE_POK_Protected_Entry), Loc)),
10218 New_Reference_To (C, Loc),
10220 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
10229 -- if C = POK_Procedure
10230 -- or else C = POK_Protected_Procedure
10231 -- or else C = POK_Task_Procedure
10233 -- <dispatching-call>
10235 -- <triggering-statements>
10237 -- <timed-statements>
10240 N_Stats := New_Copy_List_Tree (E_Stats);
10242 Prepend_To (N_Stats,
10243 Make_If_Statement (Loc,
10250 New_Reference_To (C, Loc),
10252 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
10258 New_Reference_To (C, Loc),
10260 New_Reference_To (RTE (
10261 RE_POK_Protected_Procedure), Loc)),
10265 New_Reference_To (C, Loc),
10267 New_Reference_To (RTE (
10268 RE_POK_Task_Procedure), Loc)))),
10271 New_List (E_Call)));
10273 Append_To (Conc_Typ_Stmts,
10274 Make_If_Statement (Loc,
10275 Condition => New_Reference_To (B, Loc),
10276 Then_Statements => N_Stats,
10277 Else_Statements => D_Stats));
10280 -- <dispatching-call>;
10281 -- <triggering-statements>
10283 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
10284 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
10287 -- if K = Ada.Tags.TK_Limited_Tagged then
10294 Make_If_Statement (Loc,
10298 New_Reference_To (K, Loc),
10300 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
10309 -- Skip assignments to temporaries created for in-out parameters.
10310 -- This makes unwarranted assumptions about the shape of the expanded
10311 -- tree for the call, and should be cleaned up ???
10313 Stmt := First (Stmts);
10314 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
10318 -- Do the assignment at this stage only because the evaluation
10319 -- of the expression must not occur before (see ACVC C97302A).
10321 Insert_Before (Stmt,
10322 Make_Assignment_Statement (Loc,
10323 Name => New_Reference_To (D, Loc),
10324 Expression => D_Conv));
10327 Params := Parameter_Associations (Call);
10329 -- For a protected type, we build a Timed_Protected_Entry_Call
10331 if Is_Protected_Type (Etype (Concval)) then
10333 -- Create a new call statement
10335 Param := First (Params);
10336 while Present (Param)
10337 and then not Is_RTE (Etype (Param), RE_Call_Modes)
10342 Dummy := Remove_Next (Next (Param));
10344 -- Remove garbage is following the Cancel_Param if present
10346 Dummy := Next (Param);
10348 -- Remove the mode of the Protected_Entry_Call call, then remove
10349 -- the Communication_Block of the Protected_Entry_Call call, and
10350 -- finally add Duration and a Delay_Mode parameter
10352 pragma Assert (Present (Param));
10353 Rewrite (Param, New_Reference_To (D, Loc));
10355 Rewrite (Dummy, New_Reference_To (M, Loc));
10357 -- Add a Boolean flag for successful entry call
10359 Append_To (Params, New_Reference_To (B, Loc));
10362 or else Restriction_Active (No_Entry_Queue) = False
10363 or else Number_Entries (Etype (Concval)) > 1
10366 Make_Procedure_Call_Statement (Loc,
10368 New_Reference_To (RTE (
10369 RE_Timed_Protected_Entry_Call), Loc),
10370 Parameter_Associations => Params));
10372 Param := First (Params);
10373 while Present (Param)
10374 and then not Is_RTE (Etype (Param), RE_Protected_Entry_Index)
10382 Make_Procedure_Call_Statement (Loc,
10383 Name => New_Reference_To (
10384 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
10385 Parameter_Associations => Params));
10388 -- For the task case, build a Timed_Task_Entry_Call
10391 -- Create a new call statement
10393 Append_To (Params, New_Reference_To (D, Loc));
10394 Append_To (Params, New_Reference_To (M, Loc));
10395 Append_To (Params, New_Reference_To (B, Loc));
10398 Make_Procedure_Call_Statement (Loc,
10400 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
10401 Parameter_Associations => Params));
10405 Make_Implicit_If_Statement (N,
10406 Condition => New_Reference_To (B, Loc),
10407 Then_Statements => E_Stats,
10408 Else_Statements => D_Stats));
10412 Make_Block_Statement (Loc,
10413 Declarations => Decls,
10414 Handled_Statement_Sequence =>
10415 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
10418 end Expand_N_Timed_Entry_Call;
10420 ----------------------------------------
10421 -- Expand_Protected_Body_Declarations --
10422 ----------------------------------------
10424 -- Part of the expansion of a protected body involves the creation of a
10425 -- declaration that can be referenced from the statement sequences of the
10430 -- This declaration is inserted in the declarations of the service entries
10431 -- procedure for the protected body, and it is important that it be
10432 -- inserted before the statements of the entry body statement sequences are
10433 -- analyzed. Thus it would be too late to create this declaration in the
10434 -- Expand_N_Protected_Body routine, which is why there is a separate
10435 -- procedure to be called directly from Sem_Ch9.
10437 -- Ann is used to hold the address of the record containing the parameters
10438 -- (see Expand_N_Entry_Call for more details on how this record is built).
10439 -- References to the parameters do an unchecked conversion of this address
10440 -- to a pointer to the required record type, and then access the field that
10441 -- holds the value of the required parameter. The entity for the address
10442 -- variable is held as the top stack element (i.e. the last element) of the
10443 -- Accept_Address stack in the corresponding entry entity, and this element
10444 -- must be set in place before the statements are processed.
10446 -- No stack is needed for entry bodies, since they cannot be nested, but it
10447 -- is kept for consistency between protected and task entries. The stack
10448 -- will never contain more than one element. There is also only one such
10449 -- variable for a given protected body, but this is placed on the
10450 -- Accept_Address stack of all of the entries, again for consistency.
10452 -- To expand the requeue statement, a label is provided at the end of the
10453 -- loop in the entry service routine created by the expander (see
10454 -- Expand_N_Protected_Body for details), so that the statement can be
10455 -- skipped after the requeue is complete. This label is created during the
10456 -- expansion of the entry body, which will take place after the expansion
10457 -- of the requeue statements that it contains, so a placeholder defining
10458 -- identifier is associated with the task type here.
10460 -- Another label is provided following case statement created by the
10461 -- expander. This label is need for implementing return statement from
10462 -- entry body so that a return can be expanded as a goto to this label.
10463 -- This label is created during the expansion of the entry body, which
10464 -- will take place after the expansion of the return statements that it
10465 -- contains. Therefore, just like the label for expanding requeues, we
10466 -- need another placeholder for the label.
10468 procedure Expand_Protected_Body_Declarations
10470 Spec_Id : Entity_Id)
10475 if No_Run_Time_Mode then
10476 Error_Msg_CRT ("protected body", N);
10479 elsif Expander_Active then
10481 -- Associate privals with the first subprogram or entry body to be
10482 -- expanded. These are used to expand references to private data
10485 Op := First_Protected_Operation (Declarations (N));
10487 if Present (Op) then
10488 Set_Discriminals (Parent (Spec_Id));
10489 Set_Privals (Parent (Spec_Id), Op, Sloc (N));
10492 end Expand_Protected_Body_Declarations;
10494 -------------------------
10495 -- External_Subprogram --
10496 -------------------------
10498 function External_Subprogram (E : Entity_Id) return Entity_Id is
10499 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
10502 -- The internal and external subprograms follow each other on the entity
10503 -- chain. Note that previously private operations had no separate
10504 -- external subprogram. We now create one in all cases, because a
10505 -- private operation may actually appear in an external call, through
10506 -- a 'Access reference used for a callback.
10508 -- If the operation is a function that returns an anonymous access type,
10509 -- the corresponding itype appears before the operation, and must be
10512 -- This mechanism is fragile, there should be a real link between the
10513 -- two versions of the operation, but there is no place to put it ???
10515 if Is_Access_Type (Next_Entity (Subp)) then
10516 return Next_Entity (Next_Entity (Subp));
10518 return Next_Entity (Subp);
10520 end External_Subprogram;
10522 ------------------------------
10523 -- Extract_Dispatching_Call --
10524 ------------------------------
10526 procedure Extract_Dispatching_Call
10528 Call_Ent : out Entity_Id;
10529 Object : out Entity_Id;
10530 Actuals : out List_Id;
10531 Formals : out List_Id)
10533 Call_Nam : Node_Id;
10536 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
10538 if Present (Original_Node (N)) then
10539 Call_Nam := Name (Original_Node (N));
10541 Call_Nam := Name (N);
10544 -- Retrieve the name of the dispatching procedure. It contains the
10545 -- dispatch table slot number.
10548 case Nkind (Call_Nam) is
10549 when N_Identifier =>
10552 when N_Selected_Component =>
10553 Call_Nam := Selector_Name (Call_Nam);
10556 raise Program_Error;
10561 Actuals := Parameter_Associations (N);
10562 Call_Ent := Entity (Call_Nam);
10563 Formals := Parameter_Specifications (Parent (Call_Ent));
10564 Object := First (Actuals);
10566 if Present (Original_Node (Object)) then
10567 Object := Original_Node (Object);
10569 end Extract_Dispatching_Call;
10571 -------------------
10572 -- Extract_Entry --
10573 -------------------
10575 procedure Extract_Entry
10577 Concval : out Node_Id;
10578 Ename : out Node_Id;
10579 Index : out Node_Id)
10581 Nam : constant Node_Id := Name (N);
10584 -- For a simple entry, the name is a selected component, with the
10585 -- prefix being the task value, and the selector being the entry.
10587 if Nkind (Nam) = N_Selected_Component then
10588 Concval := Prefix (Nam);
10589 Ename := Selector_Name (Nam);
10592 -- For a member of an entry family, the name is an indexed component
10593 -- where the prefix is a selected component, whose prefix in turn is
10594 -- the task value, and whose selector is the entry family. The single
10595 -- expression in the expressions list of the indexed component is the
10596 -- subscript for the family.
10598 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
10599 Concval := Prefix (Prefix (Nam));
10600 Ename := Selector_Name (Prefix (Nam));
10601 Index := First (Expressions (Nam));
10605 -------------------
10606 -- Family_Offset --
10607 -------------------
10609 function Family_Offset
10614 Cap : Boolean) return Node_Id
10620 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
10621 -- If one of the bounds is a reference to a discriminant, replace with
10622 -- corresponding discriminal of type. Within the body of a task retrieve
10623 -- the renamed discriminant by simple visibility, using its generated
10624 -- name. Within a protected object, find the original discriminant and
10625 -- replace it with the discriminal of the current protected operation.
10627 ------------------------------
10628 -- Convert_Discriminant_Ref --
10629 ------------------------------
10631 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
10632 Loc : constant Source_Ptr := Sloc (Bound);
10637 if Is_Entity_Name (Bound)
10638 and then Ekind (Entity (Bound)) = E_Discriminant
10640 if Is_Task_Type (Ttyp)
10641 and then Has_Completion (Ttyp)
10643 B := Make_Identifier (Loc, Chars (Entity (Bound)));
10644 Find_Direct_Name (B);
10646 elsif Is_Protected_Type (Ttyp) then
10647 D := First_Discriminant (Ttyp);
10648 while Chars (D) /= Chars (Entity (Bound)) loop
10649 Next_Discriminant (D);
10652 B := New_Reference_To (Discriminal (D), Loc);
10655 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
10658 elsif Nkind (Bound) = N_Attribute_Reference then
10662 B := New_Copy_Tree (Bound);
10666 Make_Attribute_Reference (Loc,
10667 Attribute_Name => Name_Pos,
10668 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
10669 Expressions => New_List (B));
10670 end Convert_Discriminant_Ref;
10672 -- Start of processing for Family_Offset
10675 Real_Hi := Convert_Discriminant_Ref (Hi);
10676 Real_Lo := Convert_Discriminant_Ref (Lo);
10679 if Is_Task_Type (Ttyp) then
10680 Ityp := RTE (RE_Task_Entry_Index);
10682 Ityp := RTE (RE_Protected_Entry_Index);
10686 Make_Attribute_Reference (Loc,
10687 Prefix => New_Reference_To (Ityp, Loc),
10688 Attribute_Name => Name_Min,
10689 Expressions => New_List (
10691 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
10694 Make_Attribute_Reference (Loc,
10695 Prefix => New_Reference_To (Ityp, Loc),
10696 Attribute_Name => Name_Max,
10697 Expressions => New_List (
10699 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
10702 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
10709 function Family_Size
10714 Cap : Boolean) return Node_Id
10719 if Is_Task_Type (Ttyp) then
10720 Ityp := RTE (RE_Task_Entry_Index);
10722 Ityp := RTE (RE_Protected_Entry_Index);
10726 Make_Attribute_Reference (Loc,
10727 Prefix => New_Reference_To (Ityp, Loc),
10728 Attribute_Name => Name_Max,
10729 Expressions => New_List (
10732 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
10734 Make_Integer_Literal (Loc, 1)),
10735 Make_Integer_Literal (Loc, 0)));
10738 -----------------------------------
10739 -- Find_Task_Or_Protected_Pragma --
10740 -----------------------------------
10742 function Find_Task_Or_Protected_Pragma
10744 P : Name_Id) return Node_Id
10749 N := First (Visible_Declarations (T));
10750 while Present (N) loop
10751 if Nkind (N) = N_Pragma then
10752 if Chars (N) = P then
10755 elsif P = Name_Priority
10756 and then Chars (N) = Name_Interrupt_Priority
10769 N := First (Private_Declarations (T));
10770 while Present (N) loop
10771 if Nkind (N) = N_Pragma then
10772 if Chars (N) = P then
10775 elsif P = Name_Priority
10776 and then Chars (N) = Name_Interrupt_Priority
10789 raise Program_Error;
10790 end Find_Task_Or_Protected_Pragma;
10792 -------------------------------
10793 -- First_Protected_Operation --
10794 -------------------------------
10796 function First_Protected_Operation (D : List_Id) return Node_Id is
10797 First_Op : Node_Id;
10800 First_Op := First (D);
10801 while Present (First_Op)
10802 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
10808 end First_Protected_Operation;
10810 ---------------------------------
10811 -- Is_Potentially_Large_Family --
10812 ---------------------------------
10814 function Is_Potentially_Large_Family
10815 (Base_Index : Entity_Id;
10816 Conctyp : Entity_Id;
10818 Hi : Node_Id) return Boolean
10821 return Scope (Base_Index) = Standard_Standard
10822 and then Base_Index = Base_Type (Standard_Integer)
10823 and then Has_Discriminants (Conctyp)
10825 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
10827 (Denotes_Discriminant (Lo, True)
10828 or else Denotes_Discriminant (Hi, True));
10829 end Is_Potentially_Large_Family;
10831 --------------------------------
10832 -- Index_Constant_Declaration --
10833 --------------------------------
10835 function Index_Constant_Declaration
10837 Index_Id : Entity_Id;
10838 Prot : Entity_Id) return List_Id
10840 Loc : constant Source_Ptr := Sloc (N);
10841 Decls : constant List_Id := New_List;
10842 Index_Con : constant Entity_Id := Entry_Index_Constant (Index_Id);
10843 Index_Typ : Entity_Id;
10845 Hi : Node_Id := Type_High_Bound (Etype (Index_Id));
10846 Lo : Node_Id := Type_Low_Bound (Etype (Index_Id));
10848 function Replace_Discriminant (Bound : Node_Id) return Node_Id;
10849 -- The bounds of the entry index may depend on discriminants, so each
10850 -- declaration of an entry_index_constant must have its own subtype
10851 -- declaration, using the local renaming of the object discriminant.
10853 --------------------------
10854 -- Replace_Discriminant --
10855 --------------------------
10857 function Replace_Discriminant (Bound : Node_Id) return Node_Id is
10859 if Nkind (Bound) = N_Identifier
10860 and then Ekind (Entity (Bound)) = E_Constant
10861 and then Present (Discriminal_Link (Entity (Bound)))
10863 return Make_Identifier (Loc, Chars (Entity (Bound)));
10865 return Duplicate_Subexpr (Bound);
10867 end Replace_Discriminant;
10869 -- Start of processing for Index_Constant_Declaration
10872 Set_Discriminal_Link (Index_Con, Index_Id);
10874 if Is_Entity_Name (
10875 Original_Node (Discrete_Subtype_Definition (Parent (Index_Id))))
10877 -- Simple case: entry family is given by a subtype mark, and index
10878 -- constant has the same type, no replacement needed.
10880 Index_Typ := Etype (Index_Id);
10883 Hi := Replace_Discriminant (Hi);
10884 Lo := Replace_Discriminant (Lo);
10886 Index_Typ := Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
10889 Make_Subtype_Declaration (Loc,
10890 Defining_Identifier => Index_Typ,
10891 Subtype_Indication =>
10892 Make_Subtype_Indication (Loc,
10894 New_Occurrence_Of (Base_Type (Etype (Index_Id)), Loc),
10896 Make_Range_Constraint (Loc,
10897 Range_Expression => Make_Range (Loc, Lo, Hi)))),
10903 Make_Object_Declaration (Loc,
10904 Defining_Identifier => Index_Con,
10905 Constant_Present => True,
10906 Object_Definition => New_Occurrence_Of (Index_Typ, Loc),
10909 Make_Attribute_Reference (Loc,
10910 Prefix => New_Reference_To (Index_Typ, Loc),
10911 Attribute_Name => Name_Val,
10913 Expressions => New_List (
10917 Make_Op_Subtract (Loc,
10918 Left_Opnd => Make_Identifier (Loc, Name_uE),
10920 Entry_Index_Expression (Loc,
10921 Defining_Identifier (N), Empty, Prot)),
10924 Make_Attribute_Reference (Loc,
10925 Prefix => New_Reference_To (Index_Typ, Loc),
10926 Attribute_Name => Name_Pos,
10927 Expressions => New_List (
10928 Make_Attribute_Reference (Loc,
10929 Prefix => New_Reference_To (Index_Typ, Loc),
10930 Attribute_Name => Name_First))))))),
10934 end Index_Constant_Declaration;
10936 --------------------------------
10937 -- Make_Initialize_Protection --
10938 --------------------------------
10940 function Make_Initialize_Protection
10941 (Protect_Rec : Entity_Id) return List_Id
10943 Loc : constant Source_Ptr := Sloc (Protect_Rec);
10947 Ptyp : constant Node_Id :=
10948 Corresponding_Concurrent_Type (Protect_Rec);
10950 L : constant List_Id := New_List;
10951 Has_Entry : constant Boolean := Has_Entries (Ptyp);
10952 Restricted : constant Boolean := Restricted_Profile;
10955 -- We may need two calls to properly initialize the object, one to
10956 -- Initialize_Protection, and possibly one to Install_Handlers if we
10957 -- have a pragma Attach_Handler.
10959 -- Get protected declaration. In the case of a task type declaration,
10960 -- this is simply the parent of the protected type entity. In the single
10961 -- protected object declaration, this parent will be the implicit type,
10962 -- and we can find the corresponding single protected object declaration
10963 -- by searching forward in the declaration list in the tree.
10965 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
10966 -- of this type should have been removed during semantic analysis.
10968 Pdec := Parent (Ptyp);
10969 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
10970 N_Single_Protected_Declaration)
10975 -- Now we can find the object definition from this declaration
10977 Pdef := Protected_Definition (Pdec);
10979 -- Build the parameter list for the call. Note that _Init is the name
10980 -- of the formal for the object to be initialized, which is the task
10981 -- value record itself.
10985 -- Object parameter. This is a pointer to the object of type
10986 -- Protection used by the GNARL to control the protected object.
10989 Make_Attribute_Reference (Loc,
10991 Make_Selected_Component (Loc,
10992 Prefix => Make_Identifier (Loc, Name_uInit),
10993 Selector_Name => Make_Identifier (Loc, Name_uObject)),
10994 Attribute_Name => Name_Unchecked_Access));
10996 -- Priority parameter. Set to Unspecified_Priority unless there is a
10997 -- priority pragma, in which case we take the value from the pragma,
10998 -- or there is an interrupt pragma and no priority pragma, and we
10999 -- set the ceiling to Interrupt_Priority'Last, an implementation-
11000 -- defined value, see D.3(10).
11003 and then Has_Priority_Pragma (Pdef)
11006 Prio : constant Node_Id :=
11009 (Pragma_Argument_Associations
11010 (Find_Task_Or_Protected_Pragma
11011 (Pdef, Name_Priority))));
11015 -- If priority is a static expression, then we can duplicate it
11016 -- with no problem and simply append it to the argument list.
11018 if Is_Static_Expression (Prio) then
11020 Duplicate_Subexpr_No_Checks (Prio));
11022 -- Otherwise, the priority may be a per-object expression, if it
11023 -- depends on a discriminant of the type. In this case, create
11024 -- local variable to capture the expression. Note that it is
11025 -- really necessary to create this variable explicitly. It might
11026 -- be thought that removing side effects would the appropriate
11027 -- approach, but that could generate declarations improperly
11028 -- placed in the enclosing scope.
11030 -- Note: Use System.Any_Priority as the expected type for the
11031 -- non-static priority expression, in case the expression has not
11032 -- been analyzed yet (as occurs for example with pragma
11033 -- Interrupt_Priority).
11037 Make_Defining_Identifier (Loc, New_Internal_Name ('R'));
11040 Make_Object_Declaration (Loc,
11041 Defining_Identifier => Temp,
11042 Object_Definition =>
11043 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
11044 Expression => Relocate_Node (Prio)));
11046 Append_To (Args, New_Occurrence_Of (Temp, Loc));
11050 -- When no priority is specified but an xx_Handler pragma is, we default
11051 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
11053 elsif Has_Interrupt_Handler (Ptyp)
11054 or else Has_Attach_Handler (Ptyp)
11057 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
11059 -- Normal case, no priority or xx_Handler specified, default priority
11063 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11066 -- Test for Compiler_Info parameter. This parameter allows entry body
11067 -- procedures and barrier functions to be called from the runtime. It
11068 -- is a pointer to the record generated by the compiler to represent
11069 -- the protected object.
11072 or else Has_Interrupt_Handler (Ptyp)
11073 or else Has_Attach_Handler (Ptyp)
11074 or else (Ada_Version >= Ada_05
11075 and then Present (Interface_List (Parent (Ptyp))))
11077 if Has_Entry or else not Restricted then
11079 Make_Attribute_Reference (Loc,
11080 Prefix => Make_Identifier (Loc, Name_uInit),
11081 Attribute_Name => Name_Address));
11084 -- Entry_Bodies parameter. This is a pointer to an array of pointers
11085 -- to the entry body procedures and barrier functions of the object.
11086 -- If the protected type has no entries this object will not exist;
11087 -- in this case, pass a null.
11090 P_Arr := Entry_Bodies_Array (Ptyp);
11093 Make_Attribute_Reference (Loc,
11094 Prefix => New_Reference_To (P_Arr, Loc),
11095 Attribute_Name => Name_Unrestricted_Access));
11098 or else Restriction_Active (No_Entry_Queue) = False
11099 or else Number_Entries (Ptyp) > 1
11100 or else (Has_Attach_Handler (Ptyp) and then not Restricted)
11102 -- Find index mapping function (clumsy but ok for now)
11104 while Ekind (P_Arr) /= E_Function loop
11105 Next_Entity (P_Arr);
11109 Make_Attribute_Reference (Loc,
11111 New_Reference_To (P_Arr, Loc),
11112 Attribute_Name => Name_Unrestricted_Access));
11115 elsif not Restricted then
11116 Append_To (Args, Make_Null (Loc));
11117 Append_To (Args, Make_Null (Loc));
11121 or else Restriction_Active (No_Entry_Queue) = False
11122 or else Number_Entries (Ptyp) > 1
11123 or else (Has_Attach_Handler (Ptyp)
11124 and then not Restricted)
11127 Make_Procedure_Call_Statement (Loc,
11128 Name => New_Reference_To (
11129 RTE (RE_Initialize_Protection_Entries), Loc),
11130 Parameter_Associations => Args));
11132 elsif not Has_Entry and then Restricted then
11134 Make_Procedure_Call_Statement (Loc,
11135 Name => New_Reference_To (
11136 RTE (RE_Initialize_Protection), Loc),
11137 Parameter_Associations => Args));
11141 Make_Procedure_Call_Statement (Loc,
11142 Name => New_Reference_To (
11143 RTE (RE_Initialize_Protection_Entry), Loc),
11144 Parameter_Associations => Args));
11149 Make_Procedure_Call_Statement (Loc,
11150 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
11151 Parameter_Associations => Args));
11154 if Has_Attach_Handler (Ptyp) then
11156 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
11157 -- make the following call:
11159 -- Install_Handlers (_object,
11160 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11162 -- or, in the case of Ravenscar:
11164 -- Install_Handlers
11165 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
11168 Args : constant List_Id := New_List;
11169 Table : constant List_Id := New_List;
11170 Ritem : Node_Id := First_Rep_Item (Ptyp);
11173 if not Restricted then
11175 -- Appends the _object argument
11178 Make_Attribute_Reference (Loc,
11180 Make_Selected_Component (Loc,
11181 Prefix => Make_Identifier (Loc, Name_uInit),
11182 Selector_Name => Make_Identifier (Loc, Name_uObject)),
11183 Attribute_Name => Name_Unchecked_Access));
11186 -- Build the Attach_Handler table argument
11188 while Present (Ritem) loop
11189 if Nkind (Ritem) = N_Pragma
11190 and then Chars (Ritem) = Name_Attach_Handler
11193 Handler : constant Node_Id :=
11194 First (Pragma_Argument_Associations (Ritem));
11196 Interrupt : constant Node_Id := Next (Handler);
11197 Expr : constant Node_Id := Expression (Interrupt);
11201 Make_Aggregate (Loc, Expressions => New_List (
11202 Unchecked_Convert_To
11203 (RTE (RE_System_Interrupt_Id), Expr),
11204 Make_Attribute_Reference (Loc,
11205 Prefix => Make_Selected_Component (Loc,
11206 Make_Identifier (Loc, Name_uInit),
11207 Duplicate_Subexpr_No_Checks
11208 (Expression (Handler))),
11209 Attribute_Name => Name_Access))));
11213 Next_Rep_Item (Ritem);
11216 -- Append the table argument we just built
11218 Append_To (Args, Make_Aggregate (Loc, Table));
11220 -- Append the Install_Handler call to the statements
11223 Make_Procedure_Call_Statement (Loc,
11224 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
11225 Parameter_Associations => Args));
11230 end Make_Initialize_Protection;
11232 ---------------------------
11233 -- Make_Task_Create_Call --
11234 ---------------------------
11236 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
11237 Loc : constant Source_Ptr := Sloc (Task_Rec);
11247 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
11248 Tnam := Chars (Ttyp);
11250 -- Get task declaration. In the case of a task type declaration, this is
11251 -- simply the parent of the task type entity. In the single task
11252 -- declaration, this parent will be the implicit type, and we can find
11253 -- the corresponding single task declaration by searching forward in the
11254 -- declaration list in the tree.
11256 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
11257 -- this type should have been removed during semantic analysis.
11259 Tdec := Parent (Ttyp);
11260 while not Nkind_In (Tdec, N_Task_Type_Declaration,
11261 N_Single_Task_Declaration)
11266 -- Now we can find the task definition from this declaration
11268 Tdef := Task_Definition (Tdec);
11270 -- Build the parameter list for the call. Note that _Init is the name
11271 -- of the formal for the object to be initialized, which is the task
11272 -- value record itself.
11276 -- Priority parameter. Set to Unspecified_Priority unless there is a
11277 -- priority pragma, in which case we take the value from the pragma.
11279 if Present (Tdef) and then Has_Priority_Pragma (Tdef) then
11281 Make_Selected_Component (Loc,
11282 Prefix => Make_Identifier (Loc, Name_uInit),
11283 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
11286 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
11289 -- Optional Stack parameter
11291 if Restricted_Profile then
11293 -- If the stack has been preallocated by the expander then
11294 -- pass its address. Otherwise, pass a null address.
11296 if Preallocated_Stacks_On_Target then
11298 Make_Attribute_Reference (Loc,
11299 Prefix => Make_Selected_Component (Loc,
11300 Prefix => Make_Identifier (Loc, Name_uInit),
11302 Make_Identifier (Loc, Name_uStack)),
11303 Attribute_Name => Name_Address));
11307 New_Reference_To (RTE (RE_Null_Address), Loc));
11311 -- Size parameter. If no Storage_Size pragma is present, then
11312 -- the size is taken from the taskZ variable for the type, which
11313 -- is either Unspecified_Size, or has been reset by the use of
11314 -- a Storage_Size attribute definition clause. If a pragma is
11315 -- present, then the size is taken from the _Size field of the
11316 -- task value record, which was set from the pragma value.
11319 and then Has_Storage_Size_Pragma (Tdef)
11322 Make_Selected_Component (Loc,
11323 Prefix => Make_Identifier (Loc, Name_uInit),
11324 Selector_Name => Make_Identifier (Loc, Name_uSize)));
11328 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
11331 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
11332 -- Task_Info pragma, in which case we take the value from the pragma.
11335 and then Has_Task_Info_Pragma (Tdef)
11338 Make_Selected_Component (Loc,
11339 Prefix => Make_Identifier (Loc, Name_uInit),
11340 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
11344 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
11347 if not Restricted_Profile then
11349 -- Number of entries. This is an expression of the form:
11351 -- n + _Init.a'Length + _Init.a'B'Length + ...
11353 -- where a,b... are the entry family names for the task definition
11355 Ecount := Build_Entry_Count_Expression (
11357 Component_Items (Component_List (
11358 Type_Definition (Parent (
11359 Corresponding_Record_Type (Ttyp))))),
11361 Append_To (Args, Ecount);
11363 -- Master parameter. This is a reference to the _Master parameter of
11364 -- the initialization procedure, except in the case of the pragma
11365 -- Restrictions (No_Task_Hierarchy) where the value is fixed to 3.
11366 -- See comments in System.Tasking.Initialization.Init_RTS for the
11369 if Restriction_Active (No_Task_Hierarchy) = False then
11370 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
11372 Append_To (Args, Make_Integer_Literal (Loc, 3));
11376 -- State parameter. This is a pointer to the task body procedure. The
11377 -- required value is obtained by taking the address of the task body
11378 -- procedure and converting it (with an unchecked conversion) to the
11379 -- type required by the task kernel. For further details, see the
11380 -- description of Expand_N_Task_Body
11383 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
11384 Make_Attribute_Reference (Loc,
11386 New_Occurrence_Of (Get_Task_Body_Procedure (Ttyp), Loc),
11387 Attribute_Name => Name_Address)));
11389 -- Discriminants parameter. This is just the address of the task
11390 -- value record itself (which contains the discriminant values
11393 Make_Attribute_Reference (Loc,
11394 Prefix => Make_Identifier (Loc, Name_uInit),
11395 Attribute_Name => Name_Address));
11397 -- Elaborated parameter. This is an access to the elaboration Boolean
11400 Make_Attribute_Reference (Loc,
11401 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
11402 Attribute_Name => Name_Unchecked_Access));
11404 -- Chain parameter. This is a reference to the _Chain parameter of
11405 -- the initialization procedure.
11407 Append_To (Args, Make_Identifier (Loc, Name_uChain));
11409 -- Task name parameter. Take this from the _Task_Id parameter to the
11410 -- init call unless there is a Task_Name pragma, in which case we take
11411 -- the value from the pragma.
11414 and then Has_Task_Name_Pragma (Tdef)
11418 Expression (First (
11419 Pragma_Argument_Associations (
11420 Find_Task_Or_Protected_Pragma
11421 (Tdef, Name_Task_Name))))));
11424 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
11427 -- Created_Task parameter. This is the _Task_Id field of the task
11431 Make_Selected_Component (Loc,
11432 Prefix => Make_Identifier (Loc, Name_uInit),
11433 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
11435 if Restricted_Profile then
11436 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
11438 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
11441 return Make_Procedure_Call_Statement (Loc,
11442 Name => Name, Parameter_Associations => Args);
11443 end Make_Task_Create_Call;
11445 ------------------------------
11446 -- Next_Protected_Operation --
11447 ------------------------------
11449 function Next_Protected_Operation (N : Node_Id) return Node_Id is
11453 Next_Op := Next (N);
11454 while Present (Next_Op)
11455 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
11461 end Next_Protected_Operation;
11463 ---------------------
11464 -- Null_Statements --
11465 ---------------------
11467 function Null_Statements (Stats : List_Id) return Boolean is
11471 Stmt := First (Stats);
11472 while Nkind (Stmt) /= N_Empty
11473 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
11475 (Nkind (Stmt) = N_Pragma
11476 and then (Chars (Stmt) = Name_Unreferenced
11478 Chars (Stmt) = Name_Warnings)))
11483 return Nkind (Stmt) = N_Empty;
11484 end Null_Statements;
11486 --------------------------
11487 -- Parameter_Block_Pack --
11488 --------------------------
11490 function Parameter_Block_Pack
11492 Blk_Typ : Entity_Id;
11496 Stmts : List_Id) return Node_Id
11498 Actual : Entity_Id;
11499 Expr : Node_Id := Empty;
11500 Formal : Entity_Id;
11501 Has_Param : Boolean := False;
11504 Temp_Asn : Node_Id;
11505 Temp_Nam : Node_Id;
11508 Actual := First (Actuals);
11509 Formal := Defining_Identifier (First (Formals));
11510 Params := New_List;
11512 while Present (Actual) loop
11513 if Is_By_Copy_Type (Etype (Actual)) then
11515 -- Jnn : aliased <formal-type>
11518 Make_Defining_Identifier (Loc, New_Internal_Name ('J'));
11521 Make_Object_Declaration (Loc,
11524 Defining_Identifier =>
11526 Object_Definition =>
11527 New_Reference_To (Etype (Formal), Loc)));
11529 if Ekind (Formal) /= E_Out_Parameter then
11535 New_Reference_To (Temp_Nam, Loc);
11537 Set_Assignment_OK (Temp_Asn);
11540 Make_Assignment_Statement (Loc,
11544 New_Copy_Tree (Actual)));
11548 -- Jnn'unchecked_access
11551 Make_Attribute_Reference (Loc,
11553 Name_Unchecked_Access,
11555 New_Reference_To (Temp_Nam, Loc)));
11559 -- The controlling parameter is omitted
11562 if not Is_Controlling_Actual (Actual) then
11564 Make_Reference (Loc, New_Copy_Tree (Actual)));
11570 Next_Actual (Actual);
11571 Next_Formal_With_Extras (Formal);
11575 Expr := Make_Aggregate (Loc, Params);
11580 -- J1'unchecked_access;
11581 -- <actual2>'reference;
11584 P := Make_Defining_Identifier (Loc, New_Internal_Name ('P'));
11587 Make_Object_Declaration (Loc,
11588 Defining_Identifier =>
11590 Object_Definition =>
11591 New_Reference_To (Blk_Typ, Loc),
11596 end Parameter_Block_Pack;
11598 ----------------------------
11599 -- Parameter_Block_Unpack --
11600 ----------------------------
11602 function Parameter_Block_Unpack
11606 Formals : List_Id) return List_Id
11608 Actual : Entity_Id;
11610 Formal : Entity_Id;
11611 Has_Asnmt : Boolean := False;
11612 Result : constant List_Id := New_List;
11615 Actual := First (Actuals);
11616 Formal := Defining_Identifier (First (Formals));
11617 while Present (Actual) loop
11618 if Is_By_Copy_Type (Etype (Actual))
11619 and then Ekind (Formal) /= E_In_Parameter
11622 -- <actual> := P.<formal>;
11625 Make_Assignment_Statement (Loc,
11629 Make_Explicit_Dereference (Loc,
11630 Make_Selected_Component (Loc,
11632 New_Reference_To (P, Loc),
11634 Make_Identifier (Loc, Chars (Formal)))));
11636 Set_Assignment_OK (Name (Asnmt));
11637 Append_To (Result, Asnmt);
11642 Next_Actual (Actual);
11643 Next_Formal_With_Extras (Formal);
11649 return New_List (Make_Null_Statement (Loc));
11651 end Parameter_Block_Unpack;
11653 ----------------------
11654 -- Set_Discriminals --
11655 ----------------------
11657 procedure Set_Discriminals (Dec : Node_Id) is
11660 D_Minal : Entity_Id;
11663 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
11664 Pdef := Defining_Identifier (Dec);
11666 if Has_Discriminants (Pdef) then
11667 D := First_Discriminant (Pdef);
11668 while Present (D) loop
11670 Make_Defining_Identifier (Sloc (D),
11671 Chars => New_External_Name (Chars (D), 'D'));
11673 Set_Ekind (D_Minal, E_Constant);
11674 Set_Etype (D_Minal, Etype (D));
11675 Set_Scope (D_Minal, Pdef);
11676 Set_Discriminal (D, D_Minal);
11677 Set_Discriminal_Link (D_Minal, D);
11679 Next_Discriminant (D);
11682 end Set_Discriminals;
11688 procedure Set_Privals
11692 After_Barrier : Boolean := False)
11698 Body_Ent : Entity_Id;
11699 For_Barrier : constant Boolean :=
11700 Nkind (Op) = N_Entry_Body and then not After_Barrier;
11702 Prec_Decl : constant Node_Id :=
11703 Parent (Corresponding_Record_Type
11704 (Defining_Identifier (Dec)));
11705 Prec_Def : constant Entity_Id := Type_Definition (Prec_Decl);
11706 Obj_Decl : Node_Id;
11707 P_Subtype : Entity_Id;
11708 Assoc_L : constant Elist_Id := New_Elmt_List;
11712 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
11713 pragma Assert (Nkind_In (Op, N_Subprogram_Body, N_Entry_Body));
11715 Def := Protected_Definition (Dec);
11717 if Present (Private_Declarations (Def)) then
11718 P_Decl := First (Private_Declarations (Def));
11719 while Present (P_Decl) loop
11720 if Nkind (P_Decl) = N_Component_Declaration then
11721 P_Id := Defining_Identifier (P_Decl);
11723 if For_Barrier then
11725 Make_Defining_Identifier (Loc,
11726 Chars => New_External_Name (Chars (P_Id), 'P'));
11729 Make_Defining_Identifier (Loc,
11730 Chars => New_External_Name (Chars (P_Id)));
11733 Set_Ekind (Priv, E_Variable);
11734 Set_Etype (Priv, Etype (P_Id));
11735 Set_Scope (Priv, Scope (P_Id));
11736 Set_Esize (Priv, Esize (Etype (P_Id)));
11737 Set_Is_Aliased (Priv, Is_Aliased (P_Id));
11738 Set_Alignment (Priv, Alignment (Etype (P_Id)));
11740 -- If the type of the component is an itype, we must create a
11741 -- new itype for the corresponding prival in each protected
11742 -- operation, to avoid scoping problems. We create new itypes
11743 -- by copying the tree for the component definition.
11744 -- (Ada 2005) If the itype is an anonymous access type created
11745 -- for an access definition for a component, it is declared in
11746 -- the enclosing scope, and we do no create a local version of
11747 -- it, to prevent scoping anomalies in gigi.
11749 if Is_Itype (Etype (P_Id))
11751 (Is_Access_Type (Etype (P_Id))
11752 and then Is_Local_Anonymous_Access (Etype (P_Id)))
11754 Append_Elmt (P_Id, Assoc_L);
11755 Append_Elmt (Priv, Assoc_L);
11757 if Nkind (Op) = N_Entry_Body then
11758 Op_Id := Defining_Identifier (Op);
11760 Op_Id := Defining_Unit_Name (Specification (Op));
11764 (New_Copy_Tree (P_Decl, Assoc_L, New_Scope => Op_Id));
11767 Set_Protected_Operation (P_Id, Op);
11768 Set_Prival (P_Id, Priv);
11775 -- There is one more implicit private decl: the object itself. "prival"
11776 -- for this is attached to the protected body defining identifier.
11778 Body_Ent := Corresponding_Body (Dec);
11781 Make_Defining_Identifier (Sloc (Body_Ent),
11782 Chars => New_External_Name (Chars (Body_Ent), 'R'));
11784 -- Set the Etype to the implicit subtype of Protection created when
11785 -- the protected type declaration was expanded. This node will not
11786 -- be analyzed until it is used as the defining identifier for the
11787 -- renaming declaration in the protected operation body, and it will
11788 -- be needed in the references expanded before that body is expanded.
11789 -- Since the Protection field is aliased, set Is_Aliased as well.
11791 Obj_Decl := First (Component_Items (Component_List (Prec_Def)));
11792 while Chars (Defining_Identifier (Obj_Decl)) /= Name_uObject loop
11796 P_Subtype := Etype (Defining_Identifier (Obj_Decl));
11797 Set_Ekind (Priv, E_Variable);
11798 Set_Etype (Priv, P_Subtype);
11799 Set_Is_Aliased (Priv);
11800 Set_Object_Ref (Body_Ent, Priv);
11803 -----------------------
11804 -- Trivial_Accept_OK --
11805 -----------------------
11807 function Trivial_Accept_OK return Boolean is
11809 case Opt.Task_Dispatching_Policy is
11811 -- If we have the default task dispatching policy in effect, we can
11812 -- definitely do the optimization (one way of looking at this is to
11813 -- think of the formal definition of the default policy being allowed
11814 -- to run any task it likes after a rendezvous, so even if notionally
11815 -- a full rescheduling occurs, we can say that our dispatching policy
11816 -- (i.e. the default dispatching policy) reorders the queue to be the
11817 -- same as just before the call.
11822 -- FIFO_Within_Priorities certainly certainly does not permit this
11823 -- optimization since the Rendezvous is a scheduling action that may
11824 -- require some other task to be run.
11829 -- For now, disallow the optimization for all other policies. This
11830 -- may be over-conservative, but it is certainly not incorrect.
11836 end Trivial_Accept_OK;
11838 ----------------------------
11839 -- Update_Prival_Subtypes --
11840 ----------------------------
11842 procedure Update_Prival_Subtypes (N : Node_Id) is
11844 function Process (N : Node_Id) return Traverse_Result;
11845 -- Update the etype of occurrences of privals whose etype does not
11846 -- match the current Etype of the prival entity itself.
11848 procedure Update_Array_Bounds (E : Entity_Id);
11849 -- Itypes generated for array expressions may depend on the
11850 -- determinants of the protected object, and need to be processed
11851 -- separately because they are not attached to the tree.
11853 procedure Update_Index_Types (N : Node_Id);
11854 -- Similarly, update the types of expressions in indexed components
11855 -- which may depend on other discriminants.
11861 function Process (N : Node_Id) return Traverse_Result is
11863 if Is_Entity_Name (N) then
11865 E : constant Entity_Id := Entity (N);
11868 and then (Ekind (E) = E_Constant
11869 or else Ekind (E) = E_Variable)
11870 and then Nkind (Parent (E)) = N_Object_Renaming_Declaration
11871 and then not Is_Scalar_Type (Etype (E))
11872 and then Etype (N) /= Etype (E)
11875 -- Ensure that reference and entity have the same Etype,
11876 -- to prevent back-end inconsistencies.
11878 Set_Etype (N, Etype (E));
11879 Update_Index_Types (N);
11882 and then Ekind (E) = E_Constant
11883 and then Present (Discriminal_Link (E))
11885 Set_Etype (N, Etype (E));
11891 elsif Nkind_In (N, N_Defining_Identifier,
11892 N_Defining_Operator_Symbol,
11893 N_Defining_Character_Literal)
11897 elsif Nkind (N) = N_String_Literal then
11899 -- Array type, but bounds are constant
11903 elsif Nkind (N) = N_Object_Declaration
11904 and then Is_Itype (Etype (Defining_Identifier (N)))
11905 and then Is_Array_Type (Etype (Defining_Identifier (N)))
11907 Update_Array_Bounds (Etype (Defining_Identifier (N)));
11910 -- For array components of discriminated records, use the base type
11911 -- directly, because it may depend indirectly on the discriminants of
11912 -- the protected type.
11914 -- Cleaner would be a systematic mechanism to compute actual subtypes
11915 -- of private components???
11917 elsif Nkind (N) in N_Has_Etype
11918 and then Present (Etype (N))
11919 and then Is_Array_Type (Etype (N))
11920 and then Nkind (N) = N_Selected_Component
11921 and then Has_Discriminants (Etype (Prefix (N)))
11923 Set_Etype (N, Base_Type (Etype (N)));
11924 Update_Index_Types (N);
11928 if Nkind (N) in N_Has_Etype
11929 and then Present (Etype (N))
11930 and then Is_Itype (Etype (N)) then
11932 if Is_Array_Type (Etype (N)) then
11933 Update_Array_Bounds (Etype (N));
11935 elsif Is_Scalar_Type (Etype (N)) then
11936 Update_Prival_Subtypes (Type_Low_Bound (Etype (N)));
11937 Update_Prival_Subtypes (Type_High_Bound (Etype (N)));
11945 -------------------------
11946 -- Update_Array_Bounds --
11947 -------------------------
11949 procedure Update_Array_Bounds (E : Entity_Id) is
11952 Ind := First_Index (E);
11953 while Present (Ind) loop
11954 Update_Prival_Subtypes (Type_Low_Bound (Etype (Ind)));
11955 Update_Prival_Subtypes (Type_High_Bound (Etype (Ind)));
11958 end Update_Array_Bounds;
11960 ------------------------
11961 -- Update_Index_Types --
11962 ------------------------
11964 procedure Update_Index_Types (N : Node_Id) is
11969 -- If the prefix has an actual subtype that is different from the
11970 -- nominal one, update the types of the indices, so that the proper
11971 -- constraints are applied. Do not apply this transformation to a
11972 -- packed array, where the index type is computed for a byte array
11973 -- and is different from the source index.
11975 if Nkind (Parent (N)) = N_Indexed_Component
11977 not Is_Bit_Packed_Array (Etype (Prefix (Parent (N))))
11979 Indx1 := First (Expressions (Parent (N)));
11980 I_Typ := First_Index (Etype (N));
11982 while Present (Indx1) and then Present (I_Typ) loop
11984 if not Is_Entity_Name (Indx1) then
11985 Set_Etype (Indx1, Base_Type (Etype (I_Typ)));
11989 Next_Index (I_Typ);
11992 end Update_Index_Types;
11994 procedure Traverse is new Traverse_Proc (Process);
11996 -- Start of processing for Update_Prival_Subtypes
12000 end Update_Prival_Subtypes;