1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Ch3; use Exp_Ch3;
32 with Exp_Ch6; use Exp_Ch6;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Dbug; use Exp_Dbug;
35 with Exp_Disp; use Exp_Disp;
36 with Exp_Sel; use Exp_Sel;
37 with Exp_Smem; use Exp_Smem;
38 with Exp_Tss; use Exp_Tss;
39 with Exp_Util; use Exp_Util;
40 with Freeze; use Freeze;
42 with Itypes; use Itypes;
43 with Namet; use Namet;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Ch11; use Sem_Ch11;
55 with Sem_Elab; use Sem_Elab;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Res; use Sem_Res;
58 with Sem_Util; use Sem_Util;
59 with Sinfo; use Sinfo;
60 with Snames; use Snames;
61 with Stand; use Stand;
62 with Stringt; use Stringt;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Uintp; use Uintp;
67 package body Exp_Ch9 is
69 -- The following constant establishes the upper bound for the index of
70 -- an entry family. It is used to limit the allocated size of protected
71 -- types with defaulted discriminant of an integer type, when the bound
72 -- of some entry family depends on a discriminant. The limitation to
73 -- entry families of 128K should be reasonable in all cases, and is a
74 -- documented implementation restriction. It will be lifted when protected
75 -- entry families are re-implemented as a single ordered queue.
77 Entry_Family_Bound : constant Int := 2**16;
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 function Actual_Index_Expression
87 Tsk : Entity_Id) return Node_Id;
88 -- Compute the index position for an entry call. Tsk is the target task. If
89 -- the bounds of some entry family depend on discriminants, the expression
90 -- computed by this function uses the discriminants of the target task.
92 procedure Add_Object_Pointer
96 -- Prepend an object pointer declaration to the declaration list Decls.
97 -- This object pointer is initialized to a type conversion of the System.
98 -- Address pointer passed to entry barrier functions and entry body
101 procedure Add_Formal_Renamings
106 -- Create renaming declarations for the formals, inside the procedure that
107 -- implements an entry body. The renamings make the original names of the
108 -- formals accessible to gdb, and serve no other purpose.
109 -- Spec is the specification of the procedure being built.
110 -- Decls is the list of declarations to be enhanced.
111 -- Ent is the entity for the original entry body.
113 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
114 -- Transform accept statement into a block with added exception handler.
115 -- Used both for simple accept statements and for accept alternatives in
116 -- select statements. Astat is the accept statement.
118 function Build_Barrier_Function
121 Pid : Node_Id) return Node_Id;
122 -- Build the function body returning the value of the barrier expression
123 -- for the specified entry body.
125 function Build_Barrier_Function_Specification
127 Def_Id : Entity_Id) return Node_Id;
128 -- Build a specification for a function implementing the protected entry
129 -- barrier of the specified entry body.
131 function Build_Corresponding_Record
134 Loc : Source_Ptr) return Node_Id;
135 -- Common to tasks and protected types. Copy discriminant specifications,
136 -- build record declaration. N is the type declaration, Ctyp is the
137 -- concurrent entity (task type or protected type).
139 function Build_Entry_Count_Expression
140 (Concurrent_Type : Node_Id;
141 Component_List : List_Id;
142 Loc : Source_Ptr) return Node_Id;
143 -- Compute number of entries for concurrent object. This is a count of
144 -- simple entries, followed by an expression that computes the length
145 -- of the range of each entry family. A single array with that size is
146 -- allocated for each concurrent object of the type.
148 function Build_Parameter_Block
152 Decls : List_Id) return Entity_Id;
153 -- Generate an access type for each actual parameter in the list Actuals.
154 -- Create an encapsulating record that contains all the actuals and return
155 -- its type. Generate:
156 -- type Ann1 is access all <actual1-type>
158 -- type AnnN is access all <actualN-type>
159 -- type Pnn is record
165 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id);
166 -- Build body of wrapper procedure for an entry or entry family that has
167 -- pre/postconditions. The body gathers the PPC's and expands them in the
168 -- usual way, and performs the entry call itself. This way preconditions
169 -- are evaluated before the call is queued. E is the entry in question,
170 -- and Decl is the enclosing synchronized type declaration at whose
171 -- freeze point the generated body is analyzed.
173 procedure Build_Wrapper_Bodies
177 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
178 -- record of a concurrent type. N is the insertion node where all bodies
179 -- will be placed. This routine builds the bodies of the subprograms which
180 -- serve as an indirection mechanism to overriding primitives of concurrent
181 -- types, entries and protected procedures. Any new body is analyzed.
183 procedure Build_Wrapper_Specs
187 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
188 -- record of a concurrent type. N is the insertion node where all specs
189 -- will be placed. This routine builds the specs of the subprograms which
190 -- serve as an indirection mechanism to overriding primitives of concurrent
191 -- types, entries and protected procedures. Any new spec is analyzed.
193 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
194 -- Build the function that translates the entry index in the call
195 -- (which depends on the size of entry families) into an index into the
196 -- Entry_Bodies_Array, to determine the body and barrier function used
197 -- in a protected entry call. A pointer to this function appears in every
200 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
201 -- Build subprogram declaration for previous one
203 function Build_Protected_Entry
206 Pid : Node_Id) return Node_Id;
207 -- Build the procedure implementing the statement sequence of the specified
210 function Build_Protected_Entry_Specification
213 Ent_Id : Entity_Id) return Node_Id;
214 -- Build a specification for the procedure implementing the statements of
215 -- the specified entry body. Add attributes associating it with the entry
216 -- defining identifier Ent_Id.
218 function Build_Protected_Spec
220 Obj_Type : Entity_Id;
222 Unprotected : Boolean := False) return List_Id;
223 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
224 -- Subprogram_Type. Builds signature of protected subprogram, adding the
225 -- formal that corresponds to the object itself. For an access to protected
226 -- subprogram, there is no object type to specify, so the parameter has
227 -- type Address and mode In. An indirect call through such a pointer will
228 -- convert the address to a reference to the actual object. The object is
229 -- a limited record and therefore a by_reference type.
231 function Build_Protected_Subprogram_Body
234 N_Op_Spec : Node_Id) return Node_Id;
235 -- This function is used to construct the protected version of a protected
236 -- subprogram. Its statement sequence first defers abort, then locks
237 -- the associated protected object, and then enters a block that contains
238 -- a call to the unprotected version of the subprogram (for details, see
239 -- Build_Unprotected_Subprogram_Body). This block statement requires
240 -- a cleanup handler that unlocks the object in all cases.
241 -- (see Exp_Ch7.Expand_Cleanup_Actions).
243 function Build_Selected_Name
245 Selector : Entity_Id;
246 Append_Char : Character := ' ') return Name_Id;
247 -- Build a name in the form of Prefix__Selector, with an optional
248 -- character appended. This is used for internal subprograms generated
249 -- for operations of protected types, including barrier functions.
250 -- For the subprograms generated for entry bodies and entry barriers,
251 -- the generated name includes a sequence number that makes names
252 -- unique in the presence of entry overloading. This is necessary
253 -- because entry body procedures and barrier functions all have the
256 procedure Build_Simple_Entry_Call
261 -- Some comments here would be useful ???
263 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
264 -- This routine constructs a specification for the procedure that we will
265 -- build for the task body for task type T. The spec has the form:
267 -- procedure tnameB (_Task : access tnameV);
269 -- where name is the character name taken from the task type entity that
270 -- is passed as the argument to the procedure, and tnameV is the task
271 -- value type that is associated with the task type.
273 function Build_Unprotected_Subprogram_Body
275 Pid : Node_Id) return Node_Id;
276 -- This routine constructs the unprotected version of a protected
277 -- subprogram body, which is contains all of the code in the
278 -- original, unexpanded body. This is the version of the protected
279 -- subprogram that is called from all protected operations on the same
280 -- object, including the protected version of the same subprogram.
282 procedure Collect_Entry_Families
285 Current_Node : in out Node_Id;
286 Conctyp : Entity_Id);
287 -- For each entry family in a concurrent type, create an anonymous array
288 -- type of the right size, and add a component to the corresponding_record.
290 function Concurrent_Object
291 (Spec_Id : Entity_Id;
292 Conc_Typ : Entity_Id) return Entity_Id;
293 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
294 -- the entity associated with the concurrent object in the Protected_Body_
295 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
296 -- denotes formal parameter _O, _object or _task.
298 function Copy_Result_Type (Res : Node_Id) return Node_Id;
299 -- Copy the result type of a function specification, when building the
300 -- internal operation corresponding to a protected function, or when
301 -- expanding an access to protected function. If the result is an anonymous
302 -- access to subprogram itself, we need to create a new signature with the
303 -- same parameter names and the same resolved types, but with new entities
306 procedure Debug_Private_Data_Declarations (Decls : List_Id);
307 -- Decls is a list which may contain the declarations created by Install_
308 -- Private_Data_Declarations. All generated entities are marked as needing
309 -- debug info and debug nodes are manually generation where necessary. This
310 -- step of the expansion must to be done after private data has been moved
311 -- to its final resting scope to ensure proper visibility of debug objects.
313 function Family_Offset
318 Cap : Boolean) return Node_Id;
319 -- Compute (Hi - Lo) for two entry family indices. Hi is the index in
320 -- an accept statement, or the upper bound in the discrete subtype of
321 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
322 -- the concurrent type of the entry. If Cap is true, the result is
323 -- capped according to Entry_Family_Bound.
330 Cap : Boolean) return Node_Id;
331 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
332 -- a family, and handle properly the superflat case. This is equivalent
333 -- to the use of 'Length on the index type, but must use Family_Offset
334 -- to handle properly the case of bounds that depend on discriminants.
335 -- If Cap is true, the result is capped according to Entry_Family_Bound.
337 procedure Extract_Dispatching_Call
339 Call_Ent : out Entity_Id;
340 Object : out Entity_Id;
341 Actuals : out List_Id;
342 Formals : out List_Id);
343 -- Given a dispatching call, extract the entity of the name of the call,
344 -- its object parameter, its actual parameters and the formal parameters
345 -- of the overridden interface-level version.
347 procedure Extract_Entry
349 Concval : out Node_Id;
351 Index : out Node_Id);
352 -- Given an entry call, returns the associated concurrent object,
353 -- the entry name, and the entry family index.
355 function Find_Task_Or_Protected_Pragma
357 P : Name_Id) return Node_Id;
358 -- Searches the task or protected definition T for the first occurrence
359 -- of the pragma whose name is given by P. The caller has ensured that
360 -- the pragma is present in the task definition. A special case is that
361 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
362 -- ??? Should be implemented with the rep item chain mechanism.
364 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
365 -- Given a subprogram identifier, return the entity which is associated
366 -- with the protection entry index in the Protected_Body_Subprogram or the
367 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
370 function Is_Potentially_Large_Family
371 (Base_Index : Entity_Id;
374 Hi : Node_Id) return Boolean;
376 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
377 -- Determine whether Id is a function or a procedure and is marked as a
378 -- private primitive.
380 function Null_Statements (Stats : List_Id) return Boolean;
381 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
382 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
383 -- well to still count as null. Returns True for a null sequence. The
384 -- argument is the list of statements from the DO-END sequence.
386 function Parameter_Block_Pack
392 Stmts : List_Id) return Entity_Id;
393 -- Set the components of the generated parameter block with the values of
394 -- the actual parameters. Generate aliased temporaries to capture the
395 -- values for types that are passed by copy. Otherwise generate a reference
396 -- to the actual's value. Return the address of the aggregate block.
398 -- Jnn1 : alias <formal-type1>;
399 -- Jnn1 := <actual1>;
402 -- Jnn1'unchecked_access;
403 -- <actual2>'reference;
406 function Parameter_Block_Unpack
410 Formals : List_Id) return List_Id;
411 -- Retrieve the values of the components from the parameter block and
412 -- assign then to the original actual parameters. Generate:
413 -- <actual1> := P.<formal1>;
415 -- <actualN> := P.<formalN>;
417 function Trivial_Accept_OK return Boolean;
418 -- If there is no DO-END block for an accept, or if the DO-END block has
419 -- only null statements, then it is possible to do the Rendezvous with much
420 -- less overhead using the Accept_Trivial routine in the run-time library.
421 -- However, this is not always a valid optimization. Whether it is valid or
422 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
423 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
424 -- a rescheduling is required, so this optimization is not allowed. This
425 -- function returns True if the optimization is permitted.
427 -----------------------------
428 -- Actual_Index_Expression --
429 -----------------------------
431 function Actual_Index_Expression
435 Tsk : Entity_Id) return Node_Id
437 Ttyp : constant Entity_Id := Etype (Tsk);
445 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
446 -- Compute difference between bounds of entry family
448 --------------------------
449 -- Actual_Family_Offset --
450 --------------------------
452 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
454 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
455 -- Replace a reference to a discriminant with a selected component
456 -- denoting the discriminant of the target task.
458 -----------------------------
459 -- Actual_Discriminant_Ref --
460 -----------------------------
462 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
463 Typ : constant Entity_Id := Etype (Bound);
467 if not Is_Entity_Name (Bound)
468 or else Ekind (Entity (Bound)) /= E_Discriminant
470 if Nkind (Bound) = N_Attribute_Reference then
473 B := New_Copy_Tree (Bound);
478 Make_Selected_Component (Sloc,
479 Prefix => New_Copy_Tree (Tsk),
480 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
482 Analyze_And_Resolve (B, Typ);
486 Make_Attribute_Reference (Sloc,
487 Attribute_Name => Name_Pos,
488 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
489 Expressions => New_List (B));
490 end Actual_Discriminant_Ref;
492 -- Start of processing for Actual_Family_Offset
496 Make_Op_Subtract (Sloc,
497 Left_Opnd => Actual_Discriminant_Ref (Hi),
498 Right_Opnd => Actual_Discriminant_Ref (Lo));
499 end Actual_Family_Offset;
501 -- Start of processing for Actual_Index_Expression
504 -- The queues of entries and entry families appear in textual order in
505 -- the associated record. The entry index is computed as the sum of the
506 -- number of queues for all entries that precede the designated one, to
507 -- which is added the index expression, if this expression denotes a
508 -- member of a family.
510 -- The following is a place holder for the count of simple entries
512 Num := Make_Integer_Literal (Sloc, 1);
514 -- We construct an expression which is a series of addition operations.
515 -- See comments in Entry_Index_Expression, which is identical in
518 if Present (Index) then
519 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
526 Actual_Family_Offset (
527 Make_Attribute_Reference (Sloc,
528 Attribute_Name => Name_Pos,
529 Prefix => New_Reference_To (Base_Type (S), Sloc),
530 Expressions => New_List (Relocate_Node (Index))),
531 Type_Low_Bound (S)));
536 -- Now add lengths of preceding entries and entry families
538 Prev := First_Entity (Ttyp);
540 while Chars (Prev) /= Chars (Ent)
541 or else (Ekind (Prev) /= Ekind (Ent))
542 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
544 if Ekind (Prev) = E_Entry then
545 Set_Intval (Num, Intval (Num) + 1);
547 elsif Ekind (Prev) = E_Entry_Family then
549 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
551 -- The need for the following full view retrieval stems from
552 -- this complex case of nested generics and tasking:
555 -- type Formal_Index is range <>;
558 -- type Index is private;
565 -- type Index is new Formal_Index range 1 .. 10;
568 -- package body Outer is
570 -- entry Fam (Index); -- (2)
573 -- package body Inner is -- (3)
581 -- We are currently building the index expression for the entry
582 -- call "T.E" (1). Part of the expansion must mention the range
583 -- of the discrete type "Index" (2) of entry family "Fam".
584 -- However only the private view of type "Index" is available to
585 -- the inner generic (3) because there was no prior mention of
586 -- the type inside "Inner". This visibility requirement is
587 -- implicit and cannot be detected during the construction of
588 -- the generic trees and needs special handling.
591 and then Is_Private_Type (S)
592 and then Present (Full_View (S))
597 Lo := Type_Low_Bound (S);
598 Hi := Type_High_Bound (S);
606 Actual_Family_Offset (Hi, Lo),
608 Make_Integer_Literal (Sloc, 1)));
610 -- Other components are anonymous types to be ignored
620 end Actual_Index_Expression;
622 --------------------------
623 -- Add_Formal_Renamings --
624 --------------------------
626 procedure Add_Formal_Renamings
632 Ptr : constant Entity_Id :=
634 (Next (First (Parameter_Specifications (Spec))));
635 -- The name of the formal that holds the address of the parameter block
644 Formal := First_Formal (Ent);
645 while Present (Formal) loop
646 Comp := Entry_Component (Formal);
648 Make_Defining_Identifier (Sloc (Formal),
649 Chars => Chars (Formal));
650 Set_Etype (New_F, Etype (Formal));
651 Set_Scope (New_F, Ent);
653 -- Now we set debug info needed on New_F even though it does not
654 -- come from source, so that the debugger will get the right
655 -- information for these generated names.
657 Set_Debug_Info_Needed (New_F);
659 if Ekind (Formal) = E_In_Parameter then
660 Set_Ekind (New_F, E_Constant);
662 Set_Ekind (New_F, E_Variable);
663 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
666 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
669 Make_Object_Renaming_Declaration (Loc,
670 Defining_Identifier => New_F,
672 New_Reference_To (Etype (Formal), Loc),
674 Make_Explicit_Dereference (Loc,
675 Make_Selected_Component (Loc,
677 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
678 Make_Identifier (Loc, Chars (Ptr))),
680 New_Reference_To (Comp, Loc))));
682 Append (Decl, Decls);
683 Set_Renamed_Object (Formal, New_F);
684 Next_Formal (Formal);
686 end Add_Formal_Renamings;
688 ------------------------
689 -- Add_Object_Pointer --
690 ------------------------
692 procedure Add_Object_Pointer
694 Conc_Typ : Entity_Id;
697 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
702 -- Create the renaming declaration for the Protection object of a
703 -- protected type. _Object is used by Complete_Entry_Body.
704 -- ??? An attempt to make this a renaming was unsuccessful.
706 -- Build the entity for the access type
709 Make_Defining_Identifier (Loc,
710 New_External_Name (Chars (Rec_Typ), 'P'));
713 -- _object : poVP := poVP!O;
716 Make_Object_Declaration (Loc,
717 Defining_Identifier =>
718 Make_Defining_Identifier (Loc, Name_uObject),
720 New_Reference_To (Obj_Ptr, Loc),
722 Unchecked_Convert_To (Obj_Ptr,
723 Make_Identifier (Loc, Name_uO)));
724 Set_Debug_Info_Needed (Defining_Identifier (Decl));
725 Prepend_To (Decls, Decl);
728 -- type poVP is access poV;
731 Make_Full_Type_Declaration (Loc,
732 Defining_Identifier =>
735 Make_Access_To_Object_Definition (Loc,
736 Subtype_Indication =>
737 New_Reference_To (Rec_Typ, Loc)));
738 Set_Debug_Info_Needed (Defining_Identifier (Decl));
739 Prepend_To (Decls, Decl);
740 end Add_Object_Pointer;
742 -----------------------
743 -- Build_Accept_Body --
744 -----------------------
746 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
747 Loc : constant Source_Ptr := Sloc (Astat);
748 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
755 -- At the end of the statement sequence, Complete_Rendezvous is called.
756 -- A label skipping the Complete_Rendezvous, and all other accept
757 -- processing, has already been added for the expansion of requeue
758 -- statements. The Sloc is copied from the last statement since it
759 -- is really part of this last statement.
763 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
764 Insert_Before (Last (Statements (Stats)), Call);
767 -- If exception handlers are present, then append Complete_Rendezvous
768 -- calls to the handlers, and construct the required outer block. As
769 -- above, the Sloc is copied from the last statement in the sequence.
771 if Present (Exception_Handlers (Stats)) then
772 Hand := First (Exception_Handlers (Stats));
773 while Present (Hand) loop
776 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
777 Append (Call, Statements (Hand));
783 Make_Handled_Sequence_Of_Statements (Loc,
784 Statements => New_List (
785 Make_Block_Statement (Loc,
786 Handled_Statement_Sequence => Stats)));
792 -- At this stage we know that the new statement sequence does not
793 -- have an exception handler part, so we supply one to call
794 -- Exceptional_Complete_Rendezvous. This handler is
796 -- when all others =>
797 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
799 -- We handle Abort_Signal to make sure that we properly catch the abort
800 -- case and wake up the caller.
802 Ohandle := Make_Others_Choice (Loc);
803 Set_All_Others (Ohandle);
805 Set_Exception_Handlers (New_S,
807 Make_Implicit_Exception_Handler (Loc,
808 Exception_Choices => New_List (Ohandle),
810 Statements => New_List (
811 Make_Procedure_Call_Statement (Sloc (Stats),
812 Name => New_Reference_To (
813 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
814 Parameter_Associations => New_List (
815 Make_Function_Call (Sloc (Stats),
816 Name => New_Reference_To (
817 RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
819 Set_Parent (New_S, Astat); -- temp parent for Analyze call
820 Analyze_Exception_Handlers (Exception_Handlers (New_S));
821 Expand_Exception_Handlers (New_S);
823 -- Exceptional_Complete_Rendezvous must be called with abort
824 -- still deferred, which is the case for a "when all others" handler.
827 end Build_Accept_Body;
829 -----------------------------------
830 -- Build_Activation_Chain_Entity --
831 -----------------------------------
833 procedure Build_Activation_Chain_Entity (N : Node_Id) is
839 -- Loop to find enclosing construct containing activation chain variable
840 -- The construct is a body, a block, or an extended return.
844 while not Nkind_In (P, N_Subprogram_Body,
846 N_Package_Declaration,
850 N_Extended_Return_Statement)
855 -- If we are in a package body, the activation chain variable is
856 -- declared in the body, but the Activation_Chain_Entity is attached
859 if Nkind (P) = N_Package_Body then
860 Decls := Declarations (P);
861 P := Unit_Declaration_Node (Corresponding_Spec (P));
863 elsif Nkind (P) = N_Package_Declaration then
864 Decls := Visible_Declarations (Specification (P));
866 elsif Nkind (P) = N_Extended_Return_Statement then
867 Decls := Return_Object_Declarations (P);
870 Decls := Declarations (P);
873 -- If activation chain entity not already declared, declare it
875 if Nkind (P) = N_Extended_Return_Statement
876 or else No (Activation_Chain_Entity (P))
878 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
880 -- Note: An extended return statement is not really a task activator,
881 -- but it does have an activation chain on which to store the tasks
882 -- temporarily. On successful return, the tasks on this chain are
883 -- moved to the chain passed in by the caller. We do not build an
884 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
885 -- because we do not want to build a call to Activate_Tasks. Task
886 -- activation is the responsibility of the caller.
888 if Nkind (P) /= N_Extended_Return_Statement then
889 Set_Activation_Chain_Entity (P, Chain);
893 Make_Object_Declaration (Sloc (P),
894 Defining_Identifier => Chain,
895 Aliased_Present => True,
897 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
899 Analyze (First (Decls));
901 end Build_Activation_Chain_Entity;
903 ----------------------------
904 -- Build_Barrier_Function --
905 ----------------------------
907 function Build_Barrier_Function
910 Pid : Node_Id) return Node_Id
912 Loc : constant Source_Ptr := Sloc (N);
913 Func_Id : constant Entity_Id := Barrier_Function (Ent);
914 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
915 Op_Decls : constant List_Id := New_List;
919 -- Add a declaration for the Protection object, renaming declarations
920 -- for the discriminals and privals and finally a declaration for the
921 -- entry family index (if applicable).
923 Install_Private_Data_Declarations
924 (Loc, Func_Id, Pid, N, Op_Decls, True, Ekind (Ent) = E_Entry_Family);
926 -- Note: the condition in the barrier function needs to be properly
927 -- processed for the C/Fortran boolean possibility, but this happens
928 -- automatically since the return statement does this normalization.
931 Make_Subprogram_Body (Loc,
933 Build_Barrier_Function_Specification (Loc,
934 Make_Defining_Identifier (Loc, Chars (Func_Id))),
935 Declarations => Op_Decls,
936 Handled_Statement_Sequence =>
937 Make_Handled_Sequence_Of_Statements (Loc,
938 Statements => New_List (
939 Make_Simple_Return_Statement (Loc,
940 Expression => Condition (Ent_Formals)))));
941 Set_Is_Entry_Barrier_Function (Func_Body);
944 end Build_Barrier_Function;
946 ------------------------------------------
947 -- Build_Barrier_Function_Specification --
948 ------------------------------------------
950 function Build_Barrier_Function_Specification
952 Def_Id : Entity_Id) return Node_Id
955 Set_Debug_Info_Needed (Def_Id);
957 return Make_Function_Specification (Loc,
958 Defining_Unit_Name => Def_Id,
959 Parameter_Specifications => New_List (
960 Make_Parameter_Specification (Loc,
961 Defining_Identifier =>
962 Make_Defining_Identifier (Loc, Name_uO),
964 New_Reference_To (RTE (RE_Address), Loc)),
966 Make_Parameter_Specification (Loc,
967 Defining_Identifier =>
968 Make_Defining_Identifier (Loc, Name_uE),
970 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
973 New_Reference_To (Standard_Boolean, Loc));
974 end Build_Barrier_Function_Specification;
976 --------------------------
977 -- Build_Call_With_Task --
978 --------------------------
980 function Build_Call_With_Task
982 E : Entity_Id) return Node_Id
984 Loc : constant Source_Ptr := Sloc (N);
987 Make_Function_Call (Loc,
988 Name => New_Reference_To (E, Loc),
989 Parameter_Associations => New_List (Concurrent_Ref (N)));
990 end Build_Call_With_Task;
992 --------------------------------
993 -- Build_Corresponding_Record --
994 --------------------------------
996 function Build_Corresponding_Record
999 Loc : Source_Ptr) return Node_Id
1001 Rec_Ent : constant Entity_Id :=
1002 Make_Defining_Identifier
1003 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1006 New_Disc : Entity_Id;
1010 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1011 Set_Ekind (Rec_Ent, E_Record_Type);
1012 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1013 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1014 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1015 Set_Stored_Constraint (Rec_Ent, No_Elist);
1018 -- Use discriminals to create list of discriminants for record, and
1019 -- create new discriminals for use in default expressions, etc. It is
1020 -- worth noting that a task discriminant gives rise to 5 entities;
1022 -- a) The original discriminant.
1023 -- b) The discriminal for use in the task.
1024 -- c) The discriminant of the corresponding record.
1025 -- d) The discriminal for the init proc of the corresponding record.
1026 -- e) The local variable that renames the discriminant in the procedure
1027 -- for the task body.
1029 -- In fact the discriminals b) are used in the renaming declarations
1030 -- for e). See details in einfo (Handling of Discriminants).
1032 if Present (Discriminant_Specifications (N)) then
1034 Disc := First_Discriminant (Ctyp);
1036 while Present (Disc) loop
1037 New_Disc := CR_Discriminant (Disc);
1040 Make_Discriminant_Specification (Loc,
1041 Defining_Identifier => New_Disc,
1042 Discriminant_Type =>
1043 New_Occurrence_Of (Etype (Disc), Loc),
1045 New_Copy (Discriminant_Default_Value (Disc))));
1047 Next_Discriminant (Disc);
1054 -- Now we can construct the record type declaration. Note that this
1055 -- record is "limited tagged". It is "limited" to reflect the underlying
1056 -- limitedness of the task or protected object that it represents, and
1057 -- ensuring for example that it is properly passed by reference. It is
1058 -- "tagged" to give support to dispatching calls through interfaces. We
1059 -- propagate here the list of interfaces covered by the concurrent type
1060 -- (Ada 2005: AI-345).
1063 Make_Full_Type_Declaration (Loc,
1064 Defining_Identifier => Rec_Ent,
1065 Discriminant_Specifications => Dlist,
1067 Make_Record_Definition (Loc,
1069 Make_Component_List (Loc,
1070 Component_Items => Cdecls),
1072 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1073 Interface_List => Interface_List (N),
1074 Limited_Present => True));
1075 end Build_Corresponding_Record;
1077 ----------------------------------
1078 -- Build_Entry_Count_Expression --
1079 ----------------------------------
1081 function Build_Entry_Count_Expression
1082 (Concurrent_Type : Node_Id;
1083 Component_List : List_Id;
1084 Loc : Source_Ptr) return Node_Id
1096 -- Count number of non-family entries
1099 Ent := First_Entity (Concurrent_Type);
1100 while Present (Ent) loop
1101 if Ekind (Ent) = E_Entry then
1108 Ecount := Make_Integer_Literal (Loc, Eindx);
1110 -- Loop through entry families building the addition nodes
1112 Ent := First_Entity (Concurrent_Type);
1113 Comp := First (Component_List);
1114 while Present (Ent) loop
1115 if Ekind (Ent) = E_Entry_Family then
1116 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1120 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1121 Hi := Type_High_Bound (Typ);
1122 Lo := Type_Low_Bound (Typ);
1123 Large := Is_Potentially_Large_Family
1124 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1127 Left_Opnd => Ecount,
1128 Right_Opnd => Family_Size
1129 (Loc, Hi, Lo, Concurrent_Type, Large));
1136 end Build_Entry_Count_Expression;
1138 -----------------------
1139 -- Build_Entry_Names --
1140 -----------------------
1142 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1143 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1149 Typ : Entity_Id := Conc_Typ;
1151 procedure Build_Entry_Family_Name (Id : Entity_Id);
1153 -- for Lnn in Family_Low .. Family_High loop
1156 -- (_init._object <or> _init._task_id,
1158 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1160 -- Note that the bounds of the range may reference discriminants. The
1161 -- above construct is added directly to the statements of the block.
1163 procedure Build_Entry_Name (Id : Entity_Id);
1167 -- (_init._object <or>_init._task_id,
1169 -- new String ("<Entry name>");
1170 -- The above construct is added directly to the statements of the block.
1172 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1173 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1174 -- _init._task_id or _init._object, Inn and Arg3.
1176 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id;
1177 -- Given a protected type or its corresponding record, find the type of
1180 procedure Increment_Index (Stmts : List_Id);
1181 -- Generate the following and add it to Stmts
1184 -----------------------------
1185 -- Build_Entry_Family_Name --
1186 -----------------------------
1188 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1189 Def : constant Node_Id :=
1190 Discrete_Subtype_Definition (Parent (Id));
1191 L_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
1192 L_Stmts : constant List_Id := New_List;
1195 function Build_Range (Def : Node_Id) return Node_Id;
1196 -- Given a discrete subtype definition of an entry family, generate a
1197 -- range node which covers the range of Def's type.
1203 function Build_Range (Def : Node_Id) return Node_Id is
1204 High : Node_Id := Type_High_Bound (Etype (Def));
1205 Low : Node_Id := Type_Low_Bound (Etype (Def));
1208 -- If a bound references a discriminant, generate an identifier
1209 -- with the same name. Resolution will map it to the formals of
1212 if Is_Entity_Name (Low)
1213 and then Ekind (Entity (Low)) = E_Discriminant
1215 Low := Make_Identifier (Loc, Chars (Low));
1217 Low := New_Copy_Tree (Low);
1220 if Is_Entity_Name (High)
1221 and then Ekind (Entity (High)) = E_Discriminant
1223 High := Make_Identifier (Loc, Chars (High));
1225 High := New_Copy_Tree (High);
1231 High_Bound => High);
1234 -- Start of processing for Build_Entry_Family_Name
1237 Get_Name_String (Chars (Id));
1239 -- Add a leading '('
1241 Add_Char_To_Name_Buffer ('(');
1244 -- new String'("<Entry name>(" & Lnn'Img & ")");
1246 -- This is an implicit heap allocation, and Comes_From_Source is
1247 -- False, which ensures that it will get flagged as a violation of
1248 -- No_Implicit_Heap_Allocations when that restriction applies.
1251 Make_Allocator (Loc,
1252 Make_Qualified_Expression (Loc,
1254 New_Reference_To (Standard_String, Loc),
1256 Make_Op_Concat (Loc,
1258 Make_Op_Concat (Loc,
1260 Make_String_Literal (Loc,
1261 Strval => String_From_Name_Buffer),
1263 Make_Attribute_Reference (Loc,
1265 New_Reference_To (L_Id, Loc),
1266 Attribute_Name => Name_Img)),
1268 Make_String_Literal (Loc,
1271 Increment_Index (L_Stmts);
1272 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1275 -- for Lnn in Family_Low .. Family_High loop
1278 -- (_init._object <or> _init._task_id, Inn, <Val>);
1282 Make_Loop_Statement (Loc,
1284 Make_Iteration_Scheme (Loc,
1285 Loop_Parameter_Specification =>
1286 Make_Loop_Parameter_Specification (Loc,
1287 Defining_Identifier => L_Id,
1288 Discrete_Subtype_Definition => Build_Range (Def))),
1289 Statements => L_Stmts,
1290 End_Label => Empty));
1291 end Build_Entry_Family_Name;
1293 ----------------------
1294 -- Build_Entry_Name --
1295 ----------------------
1297 procedure Build_Entry_Name (Id : Entity_Id) is
1301 Get_Name_String (Chars (Id));
1303 -- This is an implicit heap allocation, and Comes_From_Source is
1304 -- False, which ensures that it will get flagged as a violation of
1305 -- No_Implicit_Heap_Allocations when that restriction applies.
1308 Make_Allocator (Loc,
1309 Make_Qualified_Expression (Loc,
1311 New_Reference_To (Standard_String, Loc),
1313 Make_String_Literal (Loc,
1314 String_From_Name_Buffer)));
1316 Increment_Index (B_Stmts);
1317 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1318 end Build_Entry_Name;
1320 -------------------------------
1321 -- Build_Set_Entry_Name_Call --
1322 -------------------------------
1324 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1329 -- Determine the proper name for the first argument and the RTS
1332 if Is_Protected_Type (Typ) then
1333 Arg1 := Name_uObject;
1334 Proc := RO_PE_Set_Entry_Name;
1336 else pragma Assert (Is_Task_Type (Typ));
1337 Arg1 := Name_uTask_Id;
1338 Proc := RO_TS_Set_Entry_Name;
1342 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1345 Make_Procedure_Call_Statement (Loc,
1347 New_Reference_To (RTE (Proc), Loc),
1348 Parameter_Associations => New_List (
1349 Make_Selected_Component (Loc, -- _init._object
1350 Prefix => -- _init._task_id
1351 Make_Identifier (Loc, Name_uInit),
1353 Make_Identifier (Loc, Arg1)),
1354 New_Reference_To (Index, Loc), -- Inn
1356 end Build_Set_Entry_Name_Call;
1358 --------------------------
1359 -- Find_Protection_Type --
1360 --------------------------
1362 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
1364 Typ : Entity_Id := Conc_Typ;
1367 if Is_Concurrent_Type (Typ) then
1368 Typ := Corresponding_Record_Type (Typ);
1371 Comp := First_Component (Typ);
1372 while Present (Comp) loop
1373 if Chars (Comp) = Name_uObject then
1374 return Base_Type (Etype (Comp));
1377 Next_Component (Comp);
1380 -- The corresponding record of a protected type should always have an
1383 raise Program_Error;
1384 end Find_Protection_Type;
1386 ---------------------
1387 -- Increment_Index --
1388 ---------------------
1390 procedure Increment_Index (Stmts : List_Id) is
1396 Make_Assignment_Statement (Loc,
1398 New_Reference_To (Index, Loc),
1402 New_Reference_To (Index, Loc),
1404 Make_Integer_Literal (Loc, 1))));
1405 end Increment_Index;
1407 -- Start of processing for Build_Entry_Names
1410 -- Retrieve the original concurrent type
1412 if Is_Concurrent_Record_Type (Typ) then
1413 Typ := Corresponding_Concurrent_Type (Typ);
1416 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1418 -- Nothing to do if the type has no entries
1420 if not Has_Entries (Typ) then
1424 -- Avoid generating entry names for a protected type with only one entry
1426 if Is_Protected_Type (Typ)
1427 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1432 Index := Make_Temporary (Loc, 'I');
1434 -- Step 1: Generate the declaration of the index variable:
1435 -- Inn : Protected_Entry_Index := 0;
1437 -- Inn : Task_Entry_Index := 0;
1439 if Is_Protected_Type (Typ) then
1440 Index_Typ := RE_Protected_Entry_Index;
1442 Index_Typ := RE_Task_Entry_Index;
1445 B_Decls := New_List;
1447 Make_Object_Declaration (Loc,
1448 Defining_Identifier => Index,
1449 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1450 Expression => Make_Integer_Literal (Loc, 0)));
1452 B_Stmts := New_List;
1454 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1457 Comp := First_Entity (Typ);
1458 while Present (Comp) loop
1459 if Ekind (Comp) = E_Entry then
1460 Build_Entry_Name (Comp);
1462 elsif Ekind (Comp) = E_Entry_Family then
1463 Build_Entry_Family_Name (Comp);
1469 -- Step 3: Wrap the statements in a block
1472 Make_Block_Statement (Loc,
1473 Declarations => B_Decls,
1474 Handled_Statement_Sequence =>
1475 Make_Handled_Sequence_Of_Statements (Loc,
1476 Statements => B_Stmts));
1477 end Build_Entry_Names;
1479 ---------------------------
1480 -- Build_Parameter_Block --
1481 ---------------------------
1483 function Build_Parameter_Block
1487 Decls : List_Id) return Entity_Id
1493 Has_Comp : Boolean := False;
1497 Actual := First (Actuals);
1499 Formal := Defining_Identifier (First (Formals));
1501 while Present (Actual) loop
1502 if not Is_Controlling_Actual (Actual) then
1505 -- type Ann is access all <actual-type>
1507 Comp_Nam := Make_Temporary (Loc, 'A');
1510 Make_Full_Type_Declaration (Loc,
1511 Defining_Identifier => Comp_Nam,
1513 Make_Access_To_Object_Definition (Loc,
1514 All_Present => True,
1515 Constant_Present => Ekind (Formal) = E_In_Parameter,
1516 Subtype_Indication =>
1517 New_Reference_To (Etype (Actual), Loc))));
1523 Make_Component_Declaration (Loc,
1524 Defining_Identifier =>
1525 Make_Defining_Identifier (Loc, Chars (Formal)),
1526 Component_Definition =>
1527 Make_Component_Definition (Loc,
1530 Subtype_Indication =>
1531 New_Reference_To (Comp_Nam, Loc))));
1536 Next_Actual (Actual);
1537 Next_Formal_With_Extras (Formal);
1540 Rec_Nam := Make_Temporary (Loc, 'P');
1545 -- type Pnn is record
1550 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1551 -- the original parameter names and Ann1 .. AnnN are the access to
1555 Make_Full_Type_Declaration (Loc,
1556 Defining_Identifier =>
1559 Make_Record_Definition (Loc,
1561 Make_Component_List (Loc, Comps))));
1564 -- type Pnn is null record;
1567 Make_Full_Type_Declaration (Loc,
1568 Defining_Identifier =>
1571 Make_Record_Definition (Loc,
1572 Null_Present => True,
1573 Component_List => Empty)));
1577 end Build_Parameter_Block;
1579 -----------------------
1580 -- Build_PPC_Wrapper --
1581 -----------------------
1583 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1584 Loc : constant Source_Ptr := Sloc (E);
1585 Synch_Type : constant Entity_Id := Scope (E);
1587 Wrapper_Id : constant Entity_Id :=
1588 Make_Defining_Identifier (Loc,
1589 Chars => New_External_Name (Chars (E), 'E'));
1590 -- the wrapper procedure name
1592 Wrapper_Body : Node_Id;
1594 Synch_Id : constant Entity_Id :=
1595 Make_Defining_Identifier (Loc,
1596 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1597 -- The parameter that designates the synchronized object in the call
1599 Actuals : constant List_Id := New_List;
1600 -- the actuals in the entry call.
1602 Entry_Call : constant Node_Id :=
1603 Make_Procedure_Call_Statement (Loc,
1605 Make_Selected_Component (Loc,
1606 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1607 Selector_Name => New_Occurrence_Of (E, Loc)),
1608 Parameter_Associations => Actuals);
1610 Decls : constant List_Id := New_List;
1613 -- The specification of the wrapper procedure
1617 -- Only build the wrapper if entry has pre/postconditions.
1618 -- Should this be done unconditionally instead ???
1624 P := Spec_PPC_List (E);
1629 -- Transfer ppc pragmas to the declarations of the wrapper
1631 while Present (P) loop
1632 if Pragma_Name (P) = Name_Precondition
1633 or else Pragma_Name (P) = Name_Postcondition
1635 Append (Relocate_Node (P), Decls);
1636 Set_Analyzed (Last (Decls), False);
1639 P := Next_Pragma (P);
1643 -- First formal is synchronized object
1646 Make_Parameter_Specification (Loc,
1647 Defining_Identifier => Synch_Id,
1648 Out_Present => True,
1650 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1652 -- Now add formals that match those of the entry, and build actuals
1653 -- for the nested entry call.
1657 New_Form : Entity_Id;
1658 Parm_Spec : Node_Id;
1661 Form := First_Formal (E);
1662 while Present (Form) loop
1663 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
1665 Make_Parameter_Specification (Loc,
1666 Defining_Identifier => New_Form,
1667 Out_Present => Out_Present (Parent (Form)),
1668 In_Present => In_Present (Parent (Form)),
1669 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
1671 Append (Parm_Spec, Specs);
1672 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1677 -- Add renaming declarations for the discriminants of the enclosing
1678 -- type, which may be visible in the preconditions.
1680 if Has_Discriminants (Synch_Type) then
1686 D := First_Discriminant (Synch_Type);
1687 while Present (D) loop
1689 Make_Object_Renaming_Declaration (Loc,
1690 Defining_Identifier =>
1691 Make_Defining_Identifier (Loc, Chars (D)),
1692 Subtype_Mark => New_Reference_To (Etype (D), Loc),
1694 Make_Selected_Component (Loc,
1695 Prefix => New_Reference_To (Synch_Id, Loc),
1696 Selector_Name => Make_Identifier (Loc, Chars (D))));
1697 Prepend (Decl, Decls);
1698 Next_Discriminant (D);
1703 Set_PPC_Wrapper (E, Wrapper_Id);
1705 Make_Subprogram_Body (Loc,
1707 Make_Procedure_Specification (Loc,
1708 Defining_Unit_Name => Wrapper_Id,
1709 Parameter_Specifications => Specs),
1710 Declarations => Decls,
1711 Handled_Statement_Sequence =>
1712 Make_Handled_Sequence_Of_Statements (Loc,
1713 Statements => New_List (Entry_Call)));
1715 -- The wrapper body is analyzed when the enclosing type is frozen.
1717 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1718 end Build_PPC_Wrapper;
1720 --------------------------
1721 -- Build_Wrapper_Bodies --
1722 --------------------------
1724 procedure Build_Wrapper_Bodies
1729 Rec_Typ : Entity_Id;
1731 function Build_Wrapper_Body
1733 Subp_Id : Entity_Id;
1734 Obj_Typ : Entity_Id;
1735 Formals : List_Id) return Node_Id;
1736 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1737 -- associated with a protected or task type. Subp_Id is the subprogram
1738 -- name which will be wrapped. Obj_Typ is the type of the new formal
1739 -- parameter which handles dispatching and object notation. Formals are
1740 -- the original formals of Subp_Id which will be explicitly replicated.
1742 ------------------------
1743 -- Build_Wrapper_Body --
1744 ------------------------
1746 function Build_Wrapper_Body
1748 Subp_Id : Entity_Id;
1749 Obj_Typ : Entity_Id;
1750 Formals : List_Id) return Node_Id
1752 Body_Spec : Node_Id;
1755 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1757 -- The subprogram is not overriding or is not a primitive declared
1758 -- between two views.
1760 if No (Body_Spec) then
1765 Actuals : List_Id := No_List;
1767 First_Form : Node_Id;
1772 -- Map formals to actuals. Use the list built for the wrapper
1773 -- spec, skipping the object notation parameter.
1775 First_Form := First (Parameter_Specifications (Body_Spec));
1777 Formal := First_Form;
1780 if Present (Formal) then
1781 Actuals := New_List;
1782 while Present (Formal) loop
1784 Make_Identifier (Loc, Chars =>
1785 Chars (Defining_Identifier (Formal))));
1791 -- Special processing for primitives declared between a private
1792 -- type and its completion: the wrapper needs a properly typed
1793 -- parameter if the wrapped operation has a controlling first
1794 -- parameter. Note that this might not be the case for a function
1795 -- with a controlling result.
1797 if Is_Private_Primitive_Subprogram (Subp_Id) then
1798 if No (Actuals) then
1799 Actuals := New_List;
1802 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1803 Prepend_To (Actuals,
1804 Unchecked_Convert_To
1805 (Corresponding_Concurrent_Type (Obj_Typ),
1806 Make_Identifier (Loc, Name_uO)));
1809 Prepend_To (Actuals,
1810 Make_Identifier (Loc, Chars =>
1811 Chars (Defining_Identifier (First_Form))));
1814 Nam := New_Reference_To (Subp_Id, Loc);
1816 -- An access-to-variable object parameter requires an explicit
1817 -- dereference in the unchecked conversion. This case occurs
1818 -- when a protected entry wrapper must override an interface
1819 -- level procedure with interface access as first parameter.
1821 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1823 if Nkind (Parameter_Type (First_Form)) =
1827 Make_Explicit_Dereference (Loc,
1828 Prefix => Make_Identifier (Loc, Name_uO));
1830 Conv_Id := Make_Identifier (Loc, Name_uO);
1834 Make_Selected_Component (Loc,
1836 Unchecked_Convert_To
1837 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
1838 Selector_Name => New_Reference_To (Subp_Id, Loc));
1841 -- Create the subprogram body. For a function, the call to the
1842 -- actual subprogram has to be converted to the corresponding
1843 -- record if it is a controlling result.
1845 if Ekind (Subp_Id) = E_Function then
1851 Make_Function_Call (Loc,
1853 Parameter_Associations => Actuals);
1855 if Has_Controlling_Result (Subp_Id) then
1857 Unchecked_Convert_To
1858 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1862 Make_Subprogram_Body (Loc,
1863 Specification => Body_Spec,
1864 Declarations => Empty_List,
1865 Handled_Statement_Sequence =>
1866 Make_Handled_Sequence_Of_Statements (Loc,
1867 Statements => New_List (
1868 Make_Simple_Return_Statement (Loc, Res))));
1873 Make_Subprogram_Body (Loc,
1874 Specification => Body_Spec,
1875 Declarations => Empty_List,
1876 Handled_Statement_Sequence =>
1877 Make_Handled_Sequence_Of_Statements (Loc,
1878 Statements => New_List (
1879 Make_Procedure_Call_Statement (Loc,
1881 Parameter_Associations => Actuals))));
1884 end Build_Wrapper_Body;
1886 -- Start of processing for Build_Wrapper_Bodies
1889 if Is_Concurrent_Type (Typ) then
1890 Rec_Typ := Corresponding_Record_Type (Typ);
1895 -- Generate wrapper bodies for a concurrent type which implements an
1898 if Present (Interfaces (Rec_Typ)) then
1900 Insert_Nod : Node_Id;
1902 Prim_Elmt : Elmt_Id;
1903 Prim_Decl : Node_Id;
1905 Wrap_Body : Node_Id;
1906 Wrap_Id : Entity_Id;
1911 -- Examine all primitive operations of the corresponding record
1912 -- type, looking for wrapper specs. Generate bodies in order to
1915 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1916 while Present (Prim_Elmt) loop
1917 Prim := Node (Prim_Elmt);
1919 if (Ekind (Prim) = E_Function
1920 or else Ekind (Prim) = E_Procedure)
1921 and then Is_Primitive_Wrapper (Prim)
1923 Subp := Wrapped_Entity (Prim);
1924 Prim_Decl := Parent (Parent (Prim));
1927 Build_Wrapper_Body (Loc,
1930 Formals => Parameter_Specifications (Parent (Subp)));
1931 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
1933 Set_Corresponding_Spec (Wrap_Body, Prim);
1934 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
1936 Insert_After (Insert_Nod, Wrap_Body);
1937 Insert_Nod := Wrap_Body;
1939 Analyze (Wrap_Body);
1942 Next_Elmt (Prim_Elmt);
1946 end Build_Wrapper_Bodies;
1948 ------------------------
1949 -- Build_Wrapper_Spec --
1950 ------------------------
1952 function Build_Wrapper_Spec
1953 (Subp_Id : Entity_Id;
1954 Obj_Typ : Entity_Id;
1955 Formals : List_Id) return Node_Id
1957 Loc : constant Source_Ptr := Sloc (Subp_Id);
1958 First_Param : Node_Id;
1960 Iface_Elmt : Elmt_Id;
1961 Iface_Op : Entity_Id;
1962 Iface_Op_Elmt : Elmt_Id;
1964 function Overriding_Possible
1965 (Iface_Op : Entity_Id;
1966 Wrapper : Entity_Id) return Boolean;
1967 -- Determine whether a primitive operation can be overridden by Wrapper.
1968 -- Iface_Op is the candidate primitive operation of an interface type,
1969 -- Wrapper is the generated entry wrapper.
1971 function Replicate_Formals
1973 Formals : List_Id) return List_Id;
1974 -- An explicit parameter replication is required due to the Is_Entry_
1975 -- Formal flag being set for all the formals of an entry. The explicit
1976 -- replication removes the flag that would otherwise cause a different
1977 -- path of analysis.
1979 -------------------------
1980 -- Overriding_Possible --
1981 -------------------------
1983 function Overriding_Possible
1984 (Iface_Op : Entity_Id;
1985 Wrapper : Entity_Id) return Boolean
1987 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
1988 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
1990 function Type_Conformant_Parameters
1991 (Iface_Op_Params : List_Id;
1992 Wrapper_Params : List_Id) return Boolean;
1993 -- Determine whether the parameters of the generated entry wrapper
1994 -- and those of a primitive operation are type conformant. During
1995 -- this check, the first parameter of the primitive operation is
1996 -- skipped if it is a controlling argument: protected functions
1997 -- may have a controlling result.
1999 --------------------------------
2000 -- Type_Conformant_Parameters --
2001 --------------------------------
2003 function Type_Conformant_Parameters
2004 (Iface_Op_Params : List_Id;
2005 Wrapper_Params : List_Id) return Boolean
2007 Iface_Op_Param : Node_Id;
2008 Iface_Op_Typ : Entity_Id;
2009 Wrapper_Param : Node_Id;
2010 Wrapper_Typ : Entity_Id;
2013 -- Skip the first (controlling) parameter of primitive operation
2015 Iface_Op_Param := First (Iface_Op_Params);
2017 if Present (First_Formal (Iface_Op))
2018 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2020 Iface_Op_Param := Next (Iface_Op_Param);
2023 Wrapper_Param := First (Wrapper_Params);
2024 while Present (Iface_Op_Param)
2025 and then Present (Wrapper_Param)
2027 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2028 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2030 -- The two parameters must be mode conformant
2032 if not Conforming_Types
2033 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2038 Next (Iface_Op_Param);
2039 Next (Wrapper_Param);
2042 -- One of the lists is longer than the other
2044 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2049 end Type_Conformant_Parameters;
2051 -- Start of processing for Overriding_Possible
2054 if Chars (Iface_Op) /= Chars (Wrapper) then
2058 -- If an inherited subprogram is implemented by a protected procedure
2059 -- or an entry, then the first parameter of the inherited subprogram
2060 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2062 if Ekind (Iface_Op) = E_Procedure
2063 and then Present (Parameter_Specifications (Iface_Op_Spec))
2066 Obj_Param : constant Node_Id :=
2067 First (Parameter_Specifications (Iface_Op_Spec));
2069 if not Out_Present (Obj_Param)
2070 and then Nkind (Parameter_Type (Obj_Param)) /=
2079 Type_Conformant_Parameters (
2080 Parameter_Specifications (Iface_Op_Spec),
2081 Parameter_Specifications (Wrapper_Spec));
2082 end Overriding_Possible;
2084 -----------------------
2085 -- Replicate_Formals --
2086 -----------------------
2088 function Replicate_Formals
2090 Formals : List_Id) return List_Id
2092 New_Formals : constant List_Id := New_List;
2094 Param_Type : Node_Id;
2097 Formal := First (Formals);
2099 -- Skip the object parameter when dealing with primitives declared
2100 -- between two views.
2102 if Is_Private_Primitive_Subprogram (Subp_Id)
2103 and then not Has_Controlling_Result (Subp_Id)
2105 Formal := Next (Formal);
2108 while Present (Formal) loop
2110 -- Create an explicit copy of the entry parameter
2112 -- When creating the wrapper subprogram for a primitive operation
2113 -- of a protected interface we must construct an equivalent
2114 -- signature to that of the overriding operation. For regular
2115 -- parameters we can just use the type of the formal, but for
2116 -- access to subprogram parameters we need to reanalyze the
2117 -- parameter type to create local entities for the signature of
2118 -- the subprogram type. Using the entities of the overriding
2119 -- subprogram will result in out-of-scope errors in the back-end.
2121 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2122 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2125 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
2128 Append_To (New_Formals,
2129 Make_Parameter_Specification (Loc,
2130 Defining_Identifier =>
2131 Make_Defining_Identifier (Loc,
2132 Chars => Chars (Defining_Identifier (Formal))),
2133 In_Present => In_Present (Formal),
2134 Out_Present => Out_Present (Formal),
2135 Parameter_Type => Param_Type));
2141 end Replicate_Formals;
2143 -- Start of processing for Build_Wrapper_Spec
2146 -- There is no point in building wrappers for non-tagged concurrent
2149 pragma Assert (Is_Tagged_Type (Obj_Typ));
2151 -- An entry or a protected procedure can override a routine where the
2152 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2153 -- type. Since the wrapper must have the exact same signature as that of
2154 -- the overridden subprogram, we try to find the overriding candidate
2155 -- and use its controlling formal.
2157 First_Param := Empty;
2159 -- Check every implemented interface
2161 if Present (Interfaces (Obj_Typ)) then
2162 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2163 Search : while Present (Iface_Elmt) loop
2164 Iface := Node (Iface_Elmt);
2166 -- Check every interface primitive
2168 if Present (Primitive_Operations (Iface)) then
2169 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2170 while Present (Iface_Op_Elmt) loop
2171 Iface_Op := Node (Iface_Op_Elmt);
2173 -- Ignore predefined primitives
2175 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2176 Iface_Op := Ultimate_Alias (Iface_Op);
2178 -- The current primitive operation can be overridden by
2179 -- the generated entry wrapper.
2181 if Overriding_Possible (Iface_Op, Subp_Id) then
2183 First (Parameter_Specifications (Parent (Iface_Op)));
2189 Next_Elmt (Iface_Op_Elmt);
2193 Next_Elmt (Iface_Elmt);
2197 -- If the subprogram to be wrapped is not overriding anything or is not
2198 -- a primitive declared between two views, do not produce anything. This
2199 -- avoids spurious errors involving overriding.
2202 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2208 Wrapper_Id : constant Entity_Id :=
2209 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2210 New_Formals : List_Id;
2211 Obj_Param : Node_Id;
2212 Obj_Param_Typ : Entity_Id;
2215 -- Minimum decoration is needed to catch the entity in
2216 -- Sem_Ch6.Override_Dispatching_Operation.
2218 if Ekind (Subp_Id) = E_Function then
2219 Set_Ekind (Wrapper_Id, E_Function);
2221 Set_Ekind (Wrapper_Id, E_Procedure);
2224 Set_Is_Primitive_Wrapper (Wrapper_Id);
2225 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2226 Set_Is_Private_Primitive (Wrapper_Id,
2227 Is_Private_Primitive_Subprogram (Subp_Id));
2229 -- Process the formals
2231 New_Formals := Replicate_Formals (Loc, Formals);
2233 -- A function with a controlling result and no first controlling
2234 -- formal needs no additional parameter.
2236 if Has_Controlling_Result (Subp_Id)
2238 (No (First_Formal (Subp_Id))
2239 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2243 -- Routine Subp_Id has been found to override an interface primitive.
2244 -- If the interface operation has an access parameter, create a copy
2245 -- of it, with the same null exclusion indicator if present.
2247 elsif Present (First_Param) then
2248 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2250 Make_Access_Definition (Loc,
2252 New_Reference_To (Obj_Typ, Loc));
2253 Set_Null_Exclusion_Present (Obj_Param_Typ,
2254 Null_Exclusion_Present (Parameter_Type (First_Param)));
2257 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2261 Make_Parameter_Specification (Loc,
2262 Defining_Identifier =>
2263 Make_Defining_Identifier (Loc,
2265 In_Present => In_Present (First_Param),
2266 Out_Present => Out_Present (First_Param),
2267 Parameter_Type => Obj_Param_Typ);
2269 Prepend_To (New_Formals, Obj_Param);
2271 -- If we are dealing with a primitive declared between two views,
2272 -- implemented by a synchronized operation, we need to create
2273 -- a default parameter. The mode of the parameter must match that
2274 -- of the primitive operation.
2277 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2279 Make_Parameter_Specification (Loc,
2280 Defining_Identifier =>
2281 Make_Defining_Identifier (Loc, Name_uO),
2282 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2283 Out_Present => Ekind (Subp_Id) /= E_Function,
2284 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2285 Prepend_To (New_Formals, Obj_Param);
2288 -- Build the final spec. If it is a function with a controlling
2289 -- result, it is a primitive operation of the corresponding
2290 -- record type, so mark the spec accordingly.
2292 if Ekind (Subp_Id) = E_Function then
2297 if Has_Controlling_Result (Subp_Id) then
2300 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2302 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2306 Make_Function_Specification (Loc,
2307 Defining_Unit_Name => Wrapper_Id,
2308 Parameter_Specifications => New_Formals,
2309 Result_Definition => Res_Def);
2313 Make_Procedure_Specification (Loc,
2314 Defining_Unit_Name => Wrapper_Id,
2315 Parameter_Specifications => New_Formals);
2318 end Build_Wrapper_Spec;
2320 -------------------------
2321 -- Build_Wrapper_Specs --
2322 -------------------------
2324 procedure Build_Wrapper_Specs
2330 Rec_Typ : Entity_Id;
2331 procedure Scan_Declarations (L : List_Id);
2332 -- Common processing for visible and private declarations
2333 -- of a protected type.
2335 procedure Scan_Declarations (L : List_Id) is
2337 Wrap_Decl : Node_Id;
2338 Wrap_Spec : Node_Id;
2346 while Present (Decl) loop
2349 if Nkind (Decl) = N_Entry_Declaration
2350 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2354 (Subp_Id => Defining_Identifier (Decl),
2356 Formals => Parameter_Specifications (Decl));
2358 elsif Nkind (Decl) = N_Subprogram_Declaration then
2361 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2364 Parameter_Specifications (Specification (Decl)));
2367 if Present (Wrap_Spec) then
2369 Make_Subprogram_Declaration (Loc,
2370 Specification => Wrap_Spec);
2372 Insert_After (N, Wrap_Decl);
2375 Analyze (Wrap_Decl);
2380 end Scan_Declarations;
2382 -- start of processing for Build_Wrapper_Specs
2385 if Is_Protected_Type (Typ) then
2386 Def := Protected_Definition (Parent (Typ));
2387 else pragma Assert (Is_Task_Type (Typ));
2388 Def := Task_Definition (Parent (Typ));
2391 Rec_Typ := Corresponding_Record_Type (Typ);
2393 -- Generate wrapper specs for a concurrent type which implements an
2394 -- interface. Operations in both the visible and private parts may
2395 -- implement progenitor operations.
2397 if Present (Interfaces (Rec_Typ))
2398 and then Present (Def)
2400 Scan_Declarations (Visible_Declarations (Def));
2401 Scan_Declarations (Private_Declarations (Def));
2403 end Build_Wrapper_Specs;
2405 ---------------------------
2406 -- Build_Find_Body_Index --
2407 ---------------------------
2409 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2410 Loc : constant Source_Ptr := Sloc (Typ);
2413 Has_F : Boolean := False;
2415 If_St : Node_Id := Empty;
2418 Decls : List_Id := New_List;
2421 Siz : Node_Id := Empty;
2423 procedure Add_If_Clause (Expr : Node_Id);
2424 -- Add test for range of current entry
2426 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2427 -- If a bound of an entry is given by a discriminant, retrieve the
2428 -- actual value of the discriminant from the enclosing object.
2434 procedure Add_If_Clause (Expr : Node_Id) is
2436 Stats : constant List_Id :=
2438 Make_Simple_Return_Statement (Loc,
2439 Expression => Make_Integer_Literal (Loc, Index + 1)));
2442 -- Index for current entry body
2446 -- Compute total length of entry queues so far
2454 Right_Opnd => Expr);
2459 Left_Opnd => Make_Identifier (Loc, Name_uE),
2462 -- Map entry queue indices in the range of the current family
2463 -- into the current index, that designates the entry body.
2467 Make_Implicit_If_Statement (Typ,
2469 Then_Statements => Stats,
2470 Elsif_Parts => New_List);
2476 Make_Elsif_Part (Loc,
2478 Then_Statements => Stats),
2479 Elsif_Parts (If_St));
2483 ------------------------------
2484 -- Convert_Discriminant_Ref --
2485 ------------------------------
2487 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2491 if Is_Entity_Name (Bound)
2492 and then Ekind (Entity (Bound)) = E_Discriminant
2495 Make_Selected_Component (Loc,
2497 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2498 Make_Explicit_Dereference (Loc,
2499 Make_Identifier (Loc, Name_uObject))),
2500 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2501 Set_Etype (B, Etype (Entity (Bound)));
2503 B := New_Copy_Tree (Bound);
2507 end Convert_Discriminant_Ref;
2509 -- Start of processing for Build_Find_Body_Index
2512 Spec := Build_Find_Body_Index_Spec (Typ);
2514 Ent := First_Entity (Typ);
2515 while Present (Ent) loop
2516 if Ekind (Ent) = E_Entry_Family then
2526 -- If the protected type has no entry families, there is a one-one
2527 -- correspondence between entry queue and entry body.
2530 Make_Simple_Return_Statement (Loc,
2531 Expression => Make_Identifier (Loc, Name_uE));
2534 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2537 -- if E <= l1 then return 1;
2538 -- elsif E <= l1 + l2 then return 2;
2543 Ent := First_Entity (Typ);
2545 Add_Object_Pointer (Loc, Typ, Decls);
2547 while Present (Ent) loop
2548 if Ekind (Ent) = E_Entry then
2549 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2551 elsif Ekind (Ent) = E_Entry_Family then
2552 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2553 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2554 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2555 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2564 Make_Simple_Return_Statement (Loc,
2565 Expression => Make_Integer_Literal (Loc, 1));
2567 elsif Nkind (Ret) = N_If_Statement then
2569 -- Ranges are in increasing order, so last one doesn't need guard
2572 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2575 Set_Else_Statements (Ret, Then_Statements (Nod));
2581 Make_Subprogram_Body (Loc,
2582 Specification => Spec,
2583 Declarations => Decls,
2584 Handled_Statement_Sequence =>
2585 Make_Handled_Sequence_Of_Statements (Loc,
2586 Statements => New_List (Ret)));
2587 end Build_Find_Body_Index;
2589 --------------------------------
2590 -- Build_Find_Body_Index_Spec --
2591 --------------------------------
2593 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2594 Loc : constant Source_Ptr := Sloc (Typ);
2595 Id : constant Entity_Id :=
2596 Make_Defining_Identifier (Loc,
2597 Chars => New_External_Name (Chars (Typ), 'F'));
2598 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2599 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2603 Make_Function_Specification (Loc,
2604 Defining_Unit_Name => Id,
2605 Parameter_Specifications => New_List (
2606 Make_Parameter_Specification (Loc,
2607 Defining_Identifier => Parm1,
2609 New_Reference_To (RTE (RE_Address), Loc)),
2611 Make_Parameter_Specification (Loc,
2612 Defining_Identifier => Parm2,
2614 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2615 Result_Definition => New_Occurrence_Of (
2616 RTE (RE_Protected_Entry_Index), Loc));
2617 end Build_Find_Body_Index_Spec;
2619 -------------------------
2620 -- Build_Master_Entity --
2621 -------------------------
2623 procedure Build_Master_Entity (E : Entity_Id) is
2624 Loc : constant Source_Ptr := Sloc (E);
2630 S := Find_Master_Scope (E);
2632 -- Nothing to do if we already built a master entity for this scope
2633 -- or if there is no task hierarchy.
2635 if Has_Master_Entity (S)
2636 or else Restriction_Active (No_Task_Hierarchy)
2641 -- Otherwise first build the master entity
2642 -- _Master : constant Master_Id := Current_Master.all;
2643 -- and insert it just before the current declaration
2646 Make_Object_Declaration (Loc,
2647 Defining_Identifier =>
2648 Make_Defining_Identifier (Loc, Name_uMaster),
2649 Constant_Present => True,
2650 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2652 Make_Explicit_Dereference (Loc,
2653 New_Reference_To (RTE (RE_Current_Master), Loc)));
2656 Insert_Before (P, Decl);
2659 Set_Has_Master_Entity (S);
2661 -- Now mark the containing scope as a task master
2663 while Nkind (P) /= N_Compilation_Unit loop
2666 -- If we fall off the top, we are at the outer level, and the
2667 -- environment task is our effective master, so nothing to mark.
2670 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2672 Set_Is_Task_Master (P, True);
2675 elsif Nkind (Parent (P)) = N_Subunit then
2676 P := Corresponding_Stub (Parent (P));
2679 end Build_Master_Entity;
2681 -----------------------------------------
2682 -- Build_Private_Protected_Declaration --
2683 -----------------------------------------
2685 function Build_Private_Protected_Declaration
2686 (N : Node_Id) return Entity_Id
2688 Loc : constant Source_Ptr := Sloc (N);
2689 Body_Id : constant Entity_Id := Defining_Entity (N);
2694 Spec_Id : Entity_Id;
2697 Formal := First_Formal (Body_Id);
2699 -- The protected operation always has at least one formal, namely the
2700 -- object itself, but it is only placed in the parameter list if
2701 -- expansion is enabled.
2703 if Present (Formal) or else Expander_Active then
2704 Plist := Copy_Parameter_List (Body_Id);
2709 if Nkind (Specification (N)) = N_Procedure_Specification then
2711 Make_Procedure_Specification (Loc,
2712 Defining_Unit_Name =>
2713 Make_Defining_Identifier (Sloc (Body_Id),
2714 Chars => Chars (Body_Id)),
2715 Parameter_Specifications =>
2719 Make_Function_Specification (Loc,
2720 Defining_Unit_Name =>
2721 Make_Defining_Identifier (Sloc (Body_Id),
2722 Chars => Chars (Body_Id)),
2723 Parameter_Specifications => Plist,
2724 Result_Definition =>
2725 New_Occurrence_Of (Etype (Body_Id), Loc));
2728 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2729 Insert_Before (N, Decl);
2730 Spec_Id := Defining_Unit_Name (New_Spec);
2732 -- Indicate that the entity comes from source, to ensure that cross-
2733 -- reference information is properly generated. The body itself is
2734 -- rewritten during expansion, and the body entity will not appear in
2735 -- calls to the operation.
2737 Set_Comes_From_Source (Spec_Id, True);
2739 Set_Has_Completion (Spec_Id);
2740 Set_Convention (Spec_Id, Convention_Protected);
2742 end Build_Private_Protected_Declaration;
2744 ---------------------------
2745 -- Build_Protected_Entry --
2746 ---------------------------
2748 function Build_Protected_Entry
2751 Pid : Node_Id) return Node_Id
2753 Loc : constant Source_Ptr := Sloc (N);
2755 Decls : constant List_Id := Declarations (N);
2756 End_Lab : constant Node_Id :=
2757 End_Label (Handled_Statement_Sequence (N));
2758 End_Loc : constant Source_Ptr :=
2759 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2760 -- Used for the generated call to Complete_Entry_Body
2762 Han_Loc : Source_Ptr;
2763 -- Used for the exception handler, inserted at end of the body
2765 Op_Decls : constant List_Id := New_List;
2773 -- Set the source location on the exception handler only when debugging
2774 -- the expanded code (see Make_Implicit_Exception_Handler).
2776 if Debug_Generated_Code then
2779 -- Otherwise the inserted code should not be visible to the debugger
2782 Han_Loc := No_Location;
2786 Make_Defining_Identifier (Loc,
2787 Chars => Chars (Protected_Body_Subprogram (Ent)));
2789 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2791 -- Add the following declarations:
2792 -- type poVP is access poV;
2793 -- _object : poVP := poVP (_O);
2795 -- where _O is the formal parameter associated with the concurrent
2796 -- object. These declarations are needed for Complete_Entry_Body.
2798 Add_Object_Pointer (Loc, Pid, Op_Decls);
2800 -- Add renamings for all formals, the Protection object, discriminals,
2801 -- privals and the entry index constant for use by debugger.
2803 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2804 Debug_Private_Data_Declarations (Decls);
2806 case Corresponding_Runtime_Package (Pid) is
2807 when System_Tasking_Protected_Objects_Entries =>
2809 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2811 when System_Tasking_Protected_Objects_Single_Entry =>
2813 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2816 raise Program_Error;
2819 Op_Stats := New_List (
2820 Make_Block_Statement (Loc,
2821 Declarations => Decls,
2822 Handled_Statement_Sequence =>
2823 Handled_Statement_Sequence (N)),
2825 Make_Procedure_Call_Statement (End_Loc,
2827 Parameter_Associations => New_List (
2828 Make_Attribute_Reference (End_Loc,
2830 Make_Selected_Component (End_Loc,
2832 Make_Identifier (End_Loc, Name_uObject),
2834 Make_Identifier (End_Loc, Name_uObject)),
2835 Attribute_Name => Name_Unchecked_Access))));
2837 -- When exceptions can not be propagated, we never need to call
2838 -- Exception_Complete_Entry_Body
2840 if No_Exception_Handlers_Set then
2842 Make_Subprogram_Body (Loc,
2843 Specification => Espec,
2844 Declarations => Op_Decls,
2845 Handled_Statement_Sequence =>
2846 Make_Handled_Sequence_Of_Statements (Loc,
2847 Statements => Op_Stats,
2848 End_Label => End_Lab));
2851 Ohandle := Make_Others_Choice (Loc);
2852 Set_All_Others (Ohandle);
2854 case Corresponding_Runtime_Package (Pid) is
2855 when System_Tasking_Protected_Objects_Entries =>
2858 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2860 when System_Tasking_Protected_Objects_Single_Entry =>
2863 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2866 raise Program_Error;
2869 -- Establish link between subprogram body entity and source entry.
2871 Set_Corresponding_Protected_Entry (Edef, Ent);
2873 -- Create body of entry procedure. The renaming declarations are
2874 -- placed ahead of the block that contains the actual entry body.
2877 Make_Subprogram_Body (Loc,
2878 Specification => Espec,
2879 Declarations => Op_Decls,
2880 Handled_Statement_Sequence =>
2881 Make_Handled_Sequence_Of_Statements (Loc,
2882 Statements => Op_Stats,
2883 End_Label => End_Lab,
2884 Exception_Handlers => New_List (
2885 Make_Implicit_Exception_Handler (Han_Loc,
2886 Exception_Choices => New_List (Ohandle),
2888 Statements => New_List (
2889 Make_Procedure_Call_Statement (Han_Loc,
2891 Parameter_Associations => New_List (
2892 Make_Attribute_Reference (Han_Loc,
2894 Make_Selected_Component (Han_Loc,
2896 Make_Identifier (Han_Loc, Name_uObject),
2898 Make_Identifier (Han_Loc, Name_uObject)),
2899 Attribute_Name => Name_Unchecked_Access),
2901 Make_Function_Call (Han_Loc,
2902 Name => New_Reference_To (
2903 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2905 end Build_Protected_Entry;
2907 -----------------------------------------
2908 -- Build_Protected_Entry_Specification --
2909 -----------------------------------------
2911 function Build_Protected_Entry_Specification
2914 Ent_Id : Entity_Id) return Node_Id
2916 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2919 Set_Debug_Info_Needed (Def_Id);
2921 if Present (Ent_Id) then
2922 Append_Elmt (P, Accept_Address (Ent_Id));
2926 Make_Procedure_Specification (Loc,
2927 Defining_Unit_Name => Def_Id,
2928 Parameter_Specifications => New_List (
2929 Make_Parameter_Specification (Loc,
2930 Defining_Identifier =>
2931 Make_Defining_Identifier (Loc, Name_uO),
2933 New_Reference_To (RTE (RE_Address), Loc)),
2935 Make_Parameter_Specification (Loc,
2936 Defining_Identifier => P,
2938 New_Reference_To (RTE (RE_Address), Loc)),
2940 Make_Parameter_Specification (Loc,
2941 Defining_Identifier =>
2942 Make_Defining_Identifier (Loc, Name_uE),
2944 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
2945 end Build_Protected_Entry_Specification;
2947 --------------------------
2948 -- Build_Protected_Spec --
2949 --------------------------
2951 function Build_Protected_Spec
2953 Obj_Type : Entity_Id;
2955 Unprotected : Boolean := False) return List_Id
2957 Loc : constant Source_Ptr := Sloc (N);
2960 New_Plist : List_Id;
2961 New_Param : Node_Id;
2964 New_Plist := New_List;
2966 Formal := First_Formal (Ident);
2967 while Present (Formal) loop
2969 Make_Parameter_Specification (Loc,
2970 Defining_Identifier =>
2971 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
2972 In_Present => In_Present (Parent (Formal)),
2973 Out_Present => Out_Present (Parent (Formal)),
2974 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
2977 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
2980 Append (New_Param, New_Plist);
2981 Next_Formal (Formal);
2984 -- If the subprogram is a procedure and the context is not an access
2985 -- to protected subprogram, the parameter is in-out. Otherwise it is
2989 Make_Parameter_Specification (Loc,
2990 Defining_Identifier =>
2991 Make_Defining_Identifier (Loc, Name_uObject),
2994 (Etype (Ident) = Standard_Void_Type
2995 and then not Is_RTE (Obj_Type, RE_Address)),
2997 New_Reference_To (Obj_Type, Loc));
2998 Set_Debug_Info_Needed (Defining_Identifier (Decl));
2999 Prepend_To (New_Plist, Decl);
3002 end Build_Protected_Spec;
3004 ---------------------------------------
3005 -- Build_Protected_Sub_Specification --
3006 ---------------------------------------
3008 function Build_Protected_Sub_Specification
3010 Prot_Typ : Entity_Id;
3011 Mode : Subprogram_Protection_Mode) return Node_Id
3013 Loc : constant Source_Ptr := Sloc (N);
3017 New_Plist : List_Id;
3020 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3021 (Dispatching_Mode => ' ',
3022 Protected_Mode => 'P',
3023 Unprotected_Mode => 'N');
3026 if Ekind (Defining_Unit_Name (Specification (N))) =
3029 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3034 Def_Id := Defining_Unit_Name (Specification (Decl));
3037 Build_Protected_Spec
3038 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3039 Mode = Unprotected_Mode);
3041 Make_Defining_Identifier (Loc,
3042 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3044 -- The unprotected operation carries the user code, and debugging
3045 -- information must be generated for it, even though this spec does
3046 -- not come from source. It is also convenient to allow gdb to step
3047 -- into the protected operation, even though it only contains lock/
3050 Set_Debug_Info_Needed (New_Id);
3052 -- If a pragma Eliminate applies to the source entity, the internal
3053 -- subprograms will be eliminated as well.
3055 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3057 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3059 Make_Procedure_Specification (Loc,
3060 Defining_Unit_Name => New_Id,
3061 Parameter_Specifications => New_Plist);
3063 -- Create a new specification for the anonymous subprogram type
3067 Make_Function_Specification (Loc,
3068 Defining_Unit_Name => New_Id,
3069 Parameter_Specifications => New_Plist,
3070 Result_Definition =>
3071 Copy_Result_Type (Result_Definition (Specification (Decl))));
3073 Set_Return_Present (Defining_Unit_Name (New_Spec));
3077 end Build_Protected_Sub_Specification;
3079 -------------------------------------
3080 -- Build_Protected_Subprogram_Body --
3081 -------------------------------------
3083 function Build_Protected_Subprogram_Body
3086 N_Op_Spec : Node_Id) return Node_Id
3088 Loc : constant Source_Ptr := Sloc (N);
3090 P_Op_Spec : Node_Id;
3093 Unprot_Call : Node_Id;
3095 Lock_Name : Node_Id;
3096 Lock_Stmt : Node_Id;
3097 Service_Name : Node_Id;
3099 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3100 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3102 Object_Parm : Node_Id;
3105 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3106 -- Tell whether a given subprogram cannot raise an exception
3108 -----------------------
3109 -- Is_Exception_Safe --
3110 -----------------------
3112 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3114 function Has_Side_Effect (N : Node_Id) return Boolean;
3115 -- Return True whenever encountering a subprogram call or raise
3116 -- statement of any kind in the sequence of statements
3118 ---------------------
3119 -- Has_Side_Effect --
3120 ---------------------
3122 -- What is this doing buried two levels down in exp_ch9. It seems
3123 -- like a generally useful function, and indeed there may be code
3124 -- duplication going on here ???
3126 function Has_Side_Effect (N : Node_Id) return Boolean is
3130 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3131 -- Indicate whether N is a subprogram call or a raise statement
3133 ----------------------
3134 -- Is_Call_Or_Raise --
3135 ----------------------
3137 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3139 return Nkind_In (N, N_Procedure_Call_Statement,
3142 N_Raise_Constraint_Error,
3143 N_Raise_Program_Error,
3144 N_Raise_Storage_Error);
3145 end Is_Call_Or_Raise;
3147 -- Start of processing for Has_Side_Effect
3151 while Present (Stmt) loop
3152 if Is_Call_Or_Raise (Stmt) then
3156 -- An object declaration can also contain a function call
3157 -- or a raise statement
3159 if Nkind (Stmt) = N_Object_Declaration then
3160 Expr := Expression (Stmt);
3162 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3171 end Has_Side_Effect;
3173 -- Start of processing for Is_Exception_Safe
3176 -- If the checks handled by the back end are not disabled, we cannot
3177 -- ensure that no exception will be raised.
3179 if not Access_Checks_Suppressed (Empty)
3180 or else not Discriminant_Checks_Suppressed (Empty)
3181 or else not Range_Checks_Suppressed (Empty)
3182 or else not Index_Checks_Suppressed (Empty)
3183 or else Opt.Stack_Checking_Enabled
3188 if Has_Side_Effect (First (Declarations (Subprogram)))
3191 First (Statements (Handled_Statement_Sequence (Subprogram))))
3197 end Is_Exception_Safe;
3199 -- Start of processing for Build_Protected_Subprogram_Body
3202 Op_Spec := Specification (N);
3203 Exc_Safe := Is_Exception_Safe (N);
3206 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3208 -- Build a list of the formal parameters of the protected version of
3209 -- the subprogram to use as the actual parameters of the unprotected
3212 Uactuals := New_List;
3213 Pformal := First (Parameter_Specifications (P_Op_Spec));
3214 while Present (Pformal) loop
3216 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))),
3221 -- Make a call to the unprotected version of the subprogram built above
3222 -- for use by the protected version built below.
3224 if Nkind (Op_Spec) = N_Function_Specification then
3226 R := Make_Temporary (Loc, 'R');
3228 Make_Object_Declaration (Loc,
3229 Defining_Identifier => R,
3230 Constant_Present => True,
3231 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3233 Make_Function_Call (Loc,
3234 Name => Make_Identifier (Loc,
3235 Chars (Defining_Unit_Name (N_Op_Spec))),
3236 Parameter_Associations => Uactuals));
3239 Make_Simple_Return_Statement (Loc,
3240 Expression => New_Reference_To (R, Loc));
3243 Unprot_Call := Make_Simple_Return_Statement (Loc,
3244 Expression => Make_Function_Call (Loc,
3246 Make_Identifier (Loc,
3247 Chars (Defining_Unit_Name (N_Op_Spec))),
3248 Parameter_Associations => Uactuals));
3253 Make_Procedure_Call_Statement (Loc,
3255 Make_Identifier (Loc,
3256 Chars (Defining_Unit_Name (N_Op_Spec))),
3257 Parameter_Associations => Uactuals);
3260 -- Wrap call in block that will be covered by an at_end handler
3262 if not Exc_Safe then
3263 Unprot_Call := Make_Block_Statement (Loc,
3264 Handled_Statement_Sequence =>
3265 Make_Handled_Sequence_Of_Statements (Loc,
3266 Statements => New_List (Unprot_Call)));
3269 -- Make the protected subprogram body. This locks the protected
3270 -- object and calls the unprotected version of the subprogram.
3272 case Corresponding_Runtime_Package (Pid) is
3273 when System_Tasking_Protected_Objects_Entries =>
3274 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3275 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3277 when System_Tasking_Protected_Objects_Single_Entry =>
3278 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3279 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3281 when System_Tasking_Protected_Objects =>
3282 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3283 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3286 raise Program_Error;
3290 Make_Attribute_Reference (Loc,
3292 Make_Selected_Component (Loc,
3294 Make_Identifier (Loc, Name_uObject),
3296 Make_Identifier (Loc, Name_uObject)),
3297 Attribute_Name => Name_Unchecked_Access);
3299 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3301 Parameter_Associations => New_List (Object_Parm));
3303 if Abort_Allowed then
3305 Make_Procedure_Call_Statement (Loc,
3306 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3307 Parameter_Associations => Empty_List),
3311 Stmts := New_List (Lock_Stmt);
3314 if not Exc_Safe then
3315 Append (Unprot_Call, Stmts);
3317 if Nkind (Op_Spec) = N_Function_Specification then
3319 Stmts := Empty_List;
3321 Append (Unprot_Call, Stmts);
3325 Make_Procedure_Call_Statement (Loc,
3326 Name => Service_Name,
3327 Parameter_Associations =>
3328 New_List (New_Copy_Tree (Object_Parm))),
3331 if Abort_Allowed then
3333 Make_Procedure_Call_Statement (Loc,
3334 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3335 Parameter_Associations => Empty_List),
3339 if Nkind (Op_Spec) = N_Function_Specification then
3340 Append (Return_Stmt, Stmts);
3341 Append (Make_Block_Statement (Loc,
3342 Declarations => New_List (Unprot_Call),
3343 Handled_Statement_Sequence =>
3344 Make_Handled_Sequence_Of_Statements (Loc,
3345 Statements => Stmts)), Pre_Stmts);
3351 Make_Subprogram_Body (Loc,
3352 Declarations => Empty_List,
3353 Specification => P_Op_Spec,
3354 Handled_Statement_Sequence =>
3355 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3357 if not Exc_Safe then
3358 Set_Is_Protected_Subprogram_Body (Sub_Body);
3362 end Build_Protected_Subprogram_Body;
3364 -------------------------------------
3365 -- Build_Protected_Subprogram_Call --
3366 -------------------------------------
3368 procedure Build_Protected_Subprogram_Call
3372 External : Boolean := True)
3374 Loc : constant Source_Ptr := Sloc (N);
3375 Sub : constant Entity_Id := Entity (Name);
3381 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3384 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3387 if Present (Parameter_Associations (N)) then
3388 Params := New_Copy_List_Tree (Parameter_Associations (N));
3393 -- If the type is an untagged derived type, convert to the root type,
3394 -- which is the one on which the operations are defined.
3396 if Nkind (Rec) = N_Unchecked_Type_Conversion
3397 and then not Is_Tagged_Type (Etype (Rec))
3398 and then Is_Derived_Type (Etype (Rec))
3400 Set_Etype (Rec, Root_Type (Etype (Rec)));
3401 Set_Subtype_Mark (Rec,
3402 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3405 Prepend (Rec, Params);
3407 if Ekind (Sub) = E_Procedure then
3409 Make_Procedure_Call_Statement (Loc,
3411 Parameter_Associations => Params));
3414 pragma Assert (Ekind (Sub) = E_Function);
3416 Make_Function_Call (Loc,
3418 Parameter_Associations => Params));
3422 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3423 and then Is_Entity_Name (Expression (Rec))
3424 and then Is_Shared_Passive (Entity (Expression (Rec)))
3426 Add_Shared_Var_Lock_Procs (N);
3428 end Build_Protected_Subprogram_Call;
3430 -------------------------
3431 -- Build_Selected_Name --
3432 -------------------------
3434 function Build_Selected_Name
3435 (Prefix : Entity_Id;
3436 Selector : Entity_Id;
3437 Append_Char : Character := ' ') return Name_Id
3439 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3440 Select_Len : Natural;
3443 Get_Name_String (Chars (Selector));
3444 Select_Len := Name_Len;
3445 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3446 Get_Name_String (Chars (Prefix));
3448 -- If scope is anonymous type, discard suffix to recover name of
3449 -- single protected object. Otherwise use protected type name.
3451 if Name_Buffer (Name_Len) = 'T' then
3452 Name_Len := Name_Len - 1;
3455 Add_Str_To_Name_Buffer ("__");
3456 for J in 1 .. Select_Len loop
3457 Add_Char_To_Name_Buffer (Select_Buffer (J));
3460 -- Now add the Append_Char if specified. The encoding to follow
3461 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3462 -- then the entity is associated to a protected type subprogram.
3463 -- Otherwise, it is a protected type entry. For each case, the
3464 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3466 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3468 if Append_Char /= ' ' then
3469 if Append_Char = 'P' or Append_Char = 'N' then
3470 Add_Char_To_Name_Buffer (Append_Char);
3473 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3474 return New_External_Name (Name_Find, ' ', -1);
3479 end Build_Selected_Name;
3481 -----------------------------
3482 -- Build_Simple_Entry_Call --
3483 -----------------------------
3485 -- A task entry call is converted to a call to Call_Simple
3488 -- P : parms := (parm, parm, parm);
3490 -- Call_Simple (acceptor-task, entry-index, P'Address);
3496 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3497 -- the parameters, and the constructed aggregate value contains either the
3498 -- parameters or, in the case of non-elementary types, references to these
3499 -- parameters. Then the address of this aggregate is passed to the runtime
3500 -- routine, along with the task id value and the task entry index value.
3501 -- Pnn is only required if parameters are present.
3503 -- The assignments after the call are present only in the case of in-out
3504 -- or out parameters for elementary types, and are used to assign back the
3505 -- resulting values of such parameters.
3507 -- Note: the reason that we insert a block here is that in the context
3508 -- of selects, conditional entry calls etc. the entry call statement
3509 -- appears on its own, not as an element of a list.
3511 -- A protected entry call is converted to a Protected_Entry_Call:
3514 -- P : E1_Params := (param, param, param);
3516 -- Bnn : Communications_Block;
3519 -- P : E1_Params := (param, param, param);
3520 -- Bnn : Communications_Block;
3523 -- Protected_Entry_Call (
3524 -- Object => po._object'Access,
3525 -- E => <entry index>;
3526 -- Uninterpreted_Data => P'Address;
3527 -- Mode => Simple_Call;
3534 procedure Build_Simple_Entry_Call
3543 -- If call has been inlined, nothing left to do
3545 if Nkind (N) = N_Block_Statement then
3549 -- Convert entry call to Call_Simple call
3552 Loc : constant Source_Ptr := Sloc (N);
3553 Parms : constant List_Id := Parameter_Associations (N);
3554 Stats : constant List_Id := New_List;
3557 Comm_Name : Entity_Id;
3561 Ent_Acc : Entity_Id;
3563 Iface_Tag : Entity_Id;
3564 Iface_Typ : Entity_Id;
3577 -- Simple entry and entry family cases merge here
3579 Ent := Entity (Ename);
3580 Ent_Acc := Entry_Parameters_Type (Ent);
3581 Conctyp := Etype (Concval);
3583 -- If prefix is an access type, dereference to obtain the task type
3585 if Is_Access_Type (Conctyp) then
3586 Conctyp := Designated_Type (Conctyp);
3589 -- Special case for protected subprogram calls
3591 if Is_Protected_Type (Conctyp)
3592 and then Is_Subprogram (Entity (Ename))
3594 if not Is_Eliminated (Entity (Ename)) then
3595 Build_Protected_Subprogram_Call
3596 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3603 -- First parameter is the Task_Id value from the task value or the
3604 -- Object from the protected object value, obtained by selecting
3605 -- the _Task_Id or _Object from the result of doing an unchecked
3606 -- conversion to convert the value to the corresponding record type.
3608 if Nkind (Concval) = N_Function_Call
3609 and then Is_Task_Type (Conctyp)
3610 and then Ada_Version >= Ada_2005
3613 ExpR : constant Node_Id := Relocate_Node (Concval);
3614 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3619 Make_Object_Declaration (Loc,
3620 Defining_Identifier => Obj,
3621 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3622 Expression => ExpR);
3623 Set_Etype (Obj, Conctyp);
3624 Decls := New_List (Decl);
3625 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3632 Parm1 := Concurrent_Ref (Concval);
3634 -- Second parameter is the entry index, computed by the routine
3635 -- provided for this purpose. The value of this expression is
3636 -- assigned to an intermediate variable to assure that any entry
3637 -- family index expressions are evaluated before the entry
3641 or else Restriction_Active (No_Entry_Queue) = False
3642 or else not Is_Protected_Type (Conctyp)
3643 or else Number_Entries (Conctyp) > 1
3644 or else (Has_Attach_Handler (Conctyp)
3645 and then not Restricted_Profile)
3647 X := Make_Defining_Identifier (Loc, Name_uX);
3650 Make_Object_Declaration (Loc,
3651 Defining_Identifier => X,
3652 Object_Definition =>
3653 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3654 Expression => Actual_Index_Expression (
3655 Loc, Entity (Ename), Index, Concval));
3657 Append_To (Decls, Xdecl);
3658 Parm2 := New_Reference_To (X, Loc);
3665 -- The third parameter is the packaged parameters. If there are
3666 -- none, then it is just the null address, since nothing is passed.
3669 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3672 -- Case of parameters present, where third argument is the address
3673 -- of a packaged record containing the required parameter values.
3676 -- First build a list of parameter values, which are references to
3677 -- objects of the parameter types.
3681 Actual := First_Actual (N);
3682 Formal := First_Formal (Ent);
3684 while Present (Actual) loop
3686 -- If it is a by_copy_type, copy it to a new variable. The
3687 -- packaged record has a field that points to this variable.
3689 if Is_By_Copy_Type (Etype (Actual)) then
3691 Make_Object_Declaration (Loc,
3692 Defining_Identifier => Make_Temporary (Loc, 'J'),
3693 Aliased_Present => True,
3694 Object_Definition =>
3695 New_Reference_To (Etype (Formal), Loc));
3697 -- Mark the object as not needing initialization since the
3698 -- initialization is performed separately, avoiding errors
3699 -- on cases such as formals of null-excluding access types.
3701 Set_No_Initialization (N_Node);
3703 -- We must make an assignment statement separate for the
3704 -- case of limited type. We cannot assign it unless the
3705 -- Assignment_OK flag is set first. An out formal of an
3706 -- access type must also be initialized from the actual,
3707 -- as stated in RM 6.4.1 (13).
3709 if Ekind (Formal) /= E_Out_Parameter
3710 or else Is_Access_Type (Etype (Formal))
3713 New_Reference_To (Defining_Identifier (N_Node), Loc);
3714 Set_Assignment_OK (N_Var);
3716 Make_Assignment_Statement (Loc,
3718 Expression => Relocate_Node (Actual)));
3721 Append (N_Node, Decls);
3724 Make_Attribute_Reference (Loc,
3725 Attribute_Name => Name_Unchecked_Access,
3727 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3729 -- Interface class-wide formal
3731 if Ada_Version >= Ada_2005
3732 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3733 and then Is_Interface (Etype (Formal))
3735 Iface_Typ := Etype (Etype (Formal));
3738 -- formal_iface_type! (actual.iface_tag)'reference
3741 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3742 pragma Assert (Present (Iface_Tag));
3745 Make_Reference (Loc,
3746 Unchecked_Convert_To (Iface_Typ,
3747 Make_Selected_Component (Loc,
3749 Relocate_Node (Actual),
3751 New_Reference_To (Iface_Tag, Loc)))));
3757 Make_Reference (Loc, Relocate_Node (Actual)));
3761 Next_Actual (Actual);
3762 Next_Formal_With_Extras (Formal);
3765 -- Now build the declaration of parameters initialized with the
3766 -- aggregate containing this constructed parameter list.
3768 P := Make_Defining_Identifier (Loc, Name_uP);
3771 Make_Object_Declaration (Loc,
3772 Defining_Identifier => P,
3773 Object_Definition =>
3774 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3776 Make_Aggregate (Loc, Expressions => Plist));
3779 Make_Attribute_Reference (Loc,
3780 Prefix => New_Reference_To (P, Loc),
3781 Attribute_Name => Name_Address);
3783 Append (Pdecl, Decls);
3786 -- Now we can create the call, case of protected type
3788 if Is_Protected_Type (Conctyp) then
3789 case Corresponding_Runtime_Package (Conctyp) is
3790 when System_Tasking_Protected_Objects_Entries =>
3792 -- Change the type of the index declaration
3794 Set_Object_Definition (Xdecl,
3795 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3797 -- Some additional declarations for protected entry calls
3803 -- Bnn : Communications_Block;
3805 Comm_Name := Make_Temporary (Loc, 'B');
3808 Make_Object_Declaration (Loc,
3809 Defining_Identifier => Comm_Name,
3810 Object_Definition =>
3811 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3813 -- Some additional statements for protected entry calls
3815 -- Protected_Entry_Call (
3816 -- Object => po._object'Access,
3817 -- E => <entry index>;
3818 -- Uninterpreted_Data => P'Address;
3819 -- Mode => Simple_Call;
3823 Make_Procedure_Call_Statement (Loc,
3825 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3827 Parameter_Associations => New_List (
3828 Make_Attribute_Reference (Loc,
3829 Attribute_Name => Name_Unchecked_Access,
3833 New_Reference_To (RTE (RE_Simple_Call), Loc),
3834 New_Occurrence_Of (Comm_Name, Loc)));
3836 when System_Tasking_Protected_Objects_Single_Entry =>
3837 -- Protected_Single_Entry_Call (
3838 -- Object => po._object'Access,
3839 -- Uninterpreted_Data => P'Address;
3840 -- Mode => Simple_Call);
3843 Make_Procedure_Call_Statement (Loc,
3844 Name => New_Reference_To (
3845 RTE (RE_Protected_Single_Entry_Call), Loc),
3847 Parameter_Associations => New_List (
3848 Make_Attribute_Reference (Loc,
3849 Attribute_Name => Name_Unchecked_Access,
3852 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3855 raise Program_Error;
3858 -- Case of task type
3862 Make_Procedure_Call_Statement (Loc,
3863 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3864 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3868 Append_To (Stats, Call);
3870 -- If there are out or in/out parameters by copy add assignment
3871 -- statements for the result values.
3873 if Present (Parms) then
3874 Actual := First_Actual (N);
3875 Formal := First_Formal (Ent);
3877 Set_Assignment_OK (Actual);
3878 while Present (Actual) loop
3879 if Is_By_Copy_Type (Etype (Actual))
3880 and then Ekind (Formal) /= E_In_Parameter
3883 Make_Assignment_Statement (Loc,
3884 Name => New_Copy (Actual),
3886 Make_Explicit_Dereference (Loc,
3887 Make_Selected_Component (Loc,
3888 Prefix => New_Reference_To (P, Loc),
3890 Make_Identifier (Loc, Chars (Formal)))));
3892 -- In all cases (including limited private types) we want
3893 -- the assignment to be valid.
3895 Set_Assignment_OK (Name (N_Node));
3897 -- If the call is the triggering alternative in an
3898 -- asynchronous select, or the entry_call alternative of a
3899 -- conditional entry call, the assignments for in-out
3900 -- parameters are incorporated into the statement list that
3901 -- follows, so that there are executed only if the entry
3904 if (Nkind (Parent (N)) = N_Triggering_Alternative
3905 and then N = Triggering_Statement (Parent (N)))
3907 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3908 and then N = Entry_Call_Statement (Parent (N)))
3910 if No (Statements (Parent (N))) then
3911 Set_Statements (Parent (N), New_List);
3914 Prepend (N_Node, Statements (Parent (N)));
3917 Insert_After (Call, N_Node);
3921 Next_Actual (Actual);
3922 Next_Formal_With_Extras (Formal);
3926 -- Finally, create block and analyze it
3929 Make_Block_Statement (Loc,
3930 Declarations => Decls,
3931 Handled_Statement_Sequence =>
3932 Make_Handled_Sequence_Of_Statements (Loc,
3933 Statements => Stats)));
3937 end Build_Simple_Entry_Call;
3939 --------------------------------
3940 -- Build_Task_Activation_Call --
3941 --------------------------------
3943 procedure Build_Task_Activation_Call (N : Node_Id) is
3944 Loc : constant Source_Ptr := Sloc (N);
3951 -- Get the activation chain entity. Except in the case of a package
3952 -- body, this is in the node that was passed. For a package body, we
3953 -- have to find the corresponding package declaration node.
3955 if Nkind (N) = N_Package_Body then
3956 P := Corresponding_Spec (N);
3959 exit when Nkind (P) = N_Package_Declaration;
3962 Chain := Activation_Chain_Entity (P);
3965 Chain := Activation_Chain_Entity (N);
3968 if Present (Chain) then
3969 if Restricted_Profile then
3970 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
3972 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
3976 Make_Procedure_Call_Statement (Loc,
3978 Parameter_Associations =>
3979 New_List (Make_Attribute_Reference (Loc,
3980 Prefix => New_Occurrence_Of (Chain, Loc),
3981 Attribute_Name => Name_Unchecked_Access)));
3983 if Nkind (N) = N_Package_Declaration then
3984 if Present (Corresponding_Body (N)) then
3987 elsif Present (Private_Declarations (Specification (N))) then
3988 Append (Call, Private_Declarations (Specification (N)));
3991 Append (Call, Visible_Declarations (Specification (N)));
3995 if Present (Handled_Statement_Sequence (N)) then
3997 -- The call goes at the start of the statement sequence
3998 -- after the start of exception range label if one is present.
4004 Stm := First (Statements (Handled_Statement_Sequence (N)));
4006 -- A special case, skip exception range label if one is
4007 -- present (from front end zcx processing).
4009 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4013 -- Another special case, if the first statement is a block
4014 -- from optimization of a local raise to a goto, then the
4015 -- call goes inside this block.
4017 if Nkind (Stm) = N_Block_Statement
4018 and then Exception_Junk (Stm)
4021 First (Statements (Handled_Statement_Sequence (Stm)));
4024 -- Insertion point is after any exception label pushes,
4025 -- since we want it covered by any local handlers.
4027 while Nkind (Stm) in N_Push_xxx_Label loop
4031 -- Now we have the proper insertion point
4033 Insert_Before (Stm, Call);
4037 Set_Handled_Statement_Sequence (N,
4038 Make_Handled_Sequence_Of_Statements (Loc,
4039 Statements => New_List (Call)));
4044 Check_Task_Activation (N);
4046 end Build_Task_Activation_Call;
4048 -------------------------------
4049 -- Build_Task_Allocate_Block --
4050 -------------------------------
4052 procedure Build_Task_Allocate_Block
4057 T : constant Entity_Id := Entity (Expression (N));
4058 Init : constant Entity_Id := Base_Init_Proc (T);
4059 Loc : constant Source_Ptr := Sloc (N);
4060 Chain : constant Entity_Id :=
4061 Make_Defining_Identifier (Loc, Name_uChain);
4062 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4067 Make_Block_Statement (Loc,
4068 Identifier => New_Reference_To (Blkent, Loc),
4069 Declarations => New_List (
4071 -- _Chain : Activation_Chain;
4073 Make_Object_Declaration (Loc,
4074 Defining_Identifier => Chain,
4075 Aliased_Present => True,
4076 Object_Definition =>
4077 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4079 Handled_Statement_Sequence =>
4080 Make_Handled_Sequence_Of_Statements (Loc,
4082 Statements => New_List (
4086 Make_Procedure_Call_Statement (Loc,
4087 Name => New_Reference_To (Init, Loc),
4088 Parameter_Associations => Args),
4090 -- Activate_Tasks (_Chain);
4092 Make_Procedure_Call_Statement (Loc,
4093 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4094 Parameter_Associations => New_List (
4095 Make_Attribute_Reference (Loc,
4096 Prefix => New_Reference_To (Chain, Loc),
4097 Attribute_Name => Name_Unchecked_Access))))),
4099 Has_Created_Identifier => True,
4100 Is_Task_Allocation_Block => True);
4103 Make_Implicit_Label_Declaration (Loc,
4104 Defining_Identifier => Blkent,
4105 Label_Construct => Block));
4107 Append_To (Actions, Block);
4109 Set_Activation_Chain_Entity (Block, Chain);
4110 end Build_Task_Allocate_Block;
4112 -----------------------------------------------
4113 -- Build_Task_Allocate_Block_With_Init_Stmts --
4114 -----------------------------------------------
4116 procedure Build_Task_Allocate_Block_With_Init_Stmts
4119 Init_Stmts : List_Id)
4121 Loc : constant Source_Ptr := Sloc (N);
4122 Chain : constant Entity_Id :=
4123 Make_Defining_Identifier (Loc, Name_uChain);
4124 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4128 Append_To (Init_Stmts,
4129 Make_Procedure_Call_Statement (Loc,
4130 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4131 Parameter_Associations => New_List (
4132 Make_Attribute_Reference (Loc,
4133 Prefix => New_Reference_To (Chain, Loc),
4134 Attribute_Name => Name_Unchecked_Access))));
4137 Make_Block_Statement (Loc,
4138 Identifier => New_Reference_To (Blkent, Loc),
4139 Declarations => New_List (
4141 -- _Chain : Activation_Chain;
4143 Make_Object_Declaration (Loc,
4144 Defining_Identifier => Chain,
4145 Aliased_Present => True,
4146 Object_Definition =>
4147 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4149 Handled_Statement_Sequence =>
4150 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4152 Has_Created_Identifier => True,
4153 Is_Task_Allocation_Block => True);
4156 Make_Implicit_Label_Declaration (Loc,
4157 Defining_Identifier => Blkent,
4158 Label_Construct => Block));
4160 Append_To (Actions, Block);
4162 Set_Activation_Chain_Entity (Block, Chain);
4163 end Build_Task_Allocate_Block_With_Init_Stmts;
4165 -----------------------------------
4166 -- Build_Task_Proc_Specification --
4167 -----------------------------------
4169 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4170 Loc : constant Source_Ptr := Sloc (T);
4171 Spec_Id : Entity_Id;
4174 -- Case of explicit task type, suffix TB
4176 if Comes_From_Source (T) then
4178 Make_Defining_Identifier (Loc,
4179 Chars => New_External_Name (Chars (T), "TB"));
4181 -- Case of anonymous task type, suffix B
4185 Make_Defining_Identifier (Loc,
4186 Chars => New_External_Name (Chars (T), 'B'));
4189 Set_Is_Internal (Spec_Id);
4191 -- Associate the procedure with the task, if this is the declaration
4192 -- (and not the body) of the procedure.
4194 if No (Task_Body_Procedure (T)) then
4195 Set_Task_Body_Procedure (T, Spec_Id);
4199 Make_Procedure_Specification (Loc,
4200 Defining_Unit_Name => Spec_Id,
4201 Parameter_Specifications => New_List (
4202 Make_Parameter_Specification (Loc,
4203 Defining_Identifier =>
4204 Make_Defining_Identifier (Loc, Name_uTask),
4206 Make_Access_Definition (Loc,
4208 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4209 end Build_Task_Proc_Specification;
4211 ---------------------------------------
4212 -- Build_Unprotected_Subprogram_Body --
4213 ---------------------------------------
4215 function Build_Unprotected_Subprogram_Body
4217 Pid : Node_Id) return Node_Id
4219 Decls : constant List_Id := Declarations (N);
4222 -- Add renamings for the Protection object, discriminals, privals and
4223 -- the entry index constant for use by debugger.
4225 Debug_Private_Data_Declarations (Decls);
4227 -- Make an unprotected version of the subprogram for use within the same
4228 -- object, with a new name and an additional parameter representing the
4232 Make_Subprogram_Body (Sloc (N),
4234 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4235 Declarations => Decls,
4236 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4237 end Build_Unprotected_Subprogram_Body;
4239 ----------------------------
4240 -- Collect_Entry_Families --
4241 ----------------------------
4243 procedure Collect_Entry_Families
4246 Current_Node : in out Node_Id;
4247 Conctyp : Entity_Id)
4250 Efam_Decl : Node_Id;
4251 Efam_Type : Entity_Id;
4254 Efam := First_Entity (Conctyp);
4255 while Present (Efam) loop
4256 if Ekind (Efam) = E_Entry_Family then
4257 Efam_Type := Make_Temporary (Loc, 'F');
4262 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4264 Bas_Decl : Node_Id := Empty;
4269 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4271 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4272 Bas := Make_Temporary (Loc, 'B');
4275 Make_Subtype_Declaration (Loc,
4276 Defining_Identifier => Bas,
4277 Subtype_Indication =>
4278 Make_Subtype_Indication (Loc,
4280 New_Occurrence_Of (Standard_Integer, Loc),
4282 Make_Range_Constraint (Loc,
4283 Range_Expression => Make_Range (Loc,
4284 Make_Integer_Literal
4285 (Loc, -Entry_Family_Bound),
4286 Make_Integer_Literal
4287 (Loc, Entry_Family_Bound - 1)))));
4289 Insert_After (Current_Node, Bas_Decl);
4290 Current_Node := Bas_Decl;
4295 Make_Full_Type_Declaration (Loc,
4296 Defining_Identifier => Efam_Type,
4298 Make_Unconstrained_Array_Definition (Loc,
4300 (New_List (New_Occurrence_Of (Bas, Loc))),
4302 Component_Definition =>
4303 Make_Component_Definition (Loc,
4304 Aliased_Present => False,
4305 Subtype_Indication =>
4306 New_Reference_To (Standard_Character, Loc))));
4309 Insert_After (Current_Node, Efam_Decl);
4310 Current_Node := Efam_Decl;
4311 Analyze (Efam_Decl);
4314 Make_Component_Declaration (Loc,
4315 Defining_Identifier =>
4316 Make_Defining_Identifier (Loc, Chars (Efam)),
4318 Component_Definition =>
4319 Make_Component_Definition (Loc,
4320 Aliased_Present => False,
4321 Subtype_Indication =>
4322 Make_Subtype_Indication (Loc,
4324 New_Occurrence_Of (Efam_Type, Loc),
4327 Make_Index_Or_Discriminant_Constraint (Loc,
4328 Constraints => New_List (
4330 (Etype (Discrete_Subtype_Definition
4331 (Parent (Efam))), Loc)))))));
4337 end Collect_Entry_Families;
4339 -----------------------
4340 -- Concurrent_Object --
4341 -----------------------
4343 function Concurrent_Object
4344 (Spec_Id : Entity_Id;
4345 Conc_Typ : Entity_Id) return Entity_Id
4348 -- Parameter _O or _object
4350 if Is_Protected_Type (Conc_Typ) then
4351 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4356 pragma Assert (Is_Task_Type (Conc_Typ));
4357 return First_Formal (Task_Body_Procedure (Conc_Typ));
4359 end Concurrent_Object;
4361 ----------------------
4362 -- Copy_Result_Type --
4363 ----------------------
4365 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4366 New_Res : constant Node_Id := New_Copy_Tree (Res);
4371 -- If the result type is an access_to_subprogram, we must create
4372 -- new entities for its spec.
4374 if Nkind (New_Res) = N_Access_Definition
4375 and then Present (Access_To_Subprogram_Definition (New_Res))
4377 -- Provide new entities for the formals
4379 Par_Spec := First (Parameter_Specifications
4380 (Access_To_Subprogram_Definition (New_Res)));
4381 while Present (Par_Spec) loop
4382 Formal := Defining_Identifier (Par_Spec);
4383 Set_Defining_Identifier (Par_Spec,
4384 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4390 end Copy_Result_Type;
4392 --------------------
4393 -- Concurrent_Ref --
4394 --------------------
4396 -- The expression returned for a reference to a concurrent object has the
4399 -- taskV!(name)._Task_Id
4403 -- objectV!(name)._Object
4405 -- for a protected object. For the case of an access to a concurrent
4406 -- object, there is an extra explicit dereference:
4408 -- taskV!(name.all)._Task_Id
4409 -- objectV!(name.all)._Object
4411 -- here taskV and objectV are the types for the associated records, which
4412 -- contain the required _Task_Id and _Object fields for tasks and protected
4413 -- objects, respectively.
4415 -- For the case of a task type name, the expression is
4419 -- i.e. a call to the Self function which returns precisely this Task_Id
4421 -- For the case of a protected type name, the expression is
4425 -- which is a renaming of the _object field of the current object
4426 -- record, passed into protected operations as a parameter.
4428 function Concurrent_Ref (N : Node_Id) return Node_Id is
4429 Loc : constant Source_Ptr := Sloc (N);
4430 Ntyp : constant Entity_Id := Etype (N);
4434 function Is_Current_Task (T : Entity_Id) return Boolean;
4435 -- Check whether the reference is to the immediately enclosing task
4436 -- type, or to an outer one (rare but legal).
4438 ---------------------
4439 -- Is_Current_Task --
4440 ---------------------
4442 function Is_Current_Task (T : Entity_Id) return Boolean is
4446 Scop := Current_Scope;
4447 while Present (Scop)
4448 and then Scop /= Standard_Standard
4454 elsif Is_Task_Type (Scop) then
4457 -- If this is a procedure nested within the task type, we must
4458 -- assume that it can be called from an inner task, and therefore
4459 -- cannot treat it as a local reference.
4461 elsif Is_Overloadable (Scop)
4462 and then In_Open_Scopes (T)
4467 Scop := Scope (Scop);
4471 -- We know that we are within the task body, so should have found it
4474 raise Program_Error;
4475 end Is_Current_Task;
4477 -- Start of processing for Concurrent_Ref
4480 if Is_Access_Type (Ntyp) then
4481 Dtyp := Designated_Type (Ntyp);
4483 if Is_Protected_Type (Dtyp) then
4484 Sel := Name_uObject;
4486 Sel := Name_uTask_Id;
4490 Make_Selected_Component (Loc,
4492 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4493 Make_Explicit_Dereference (Loc, N)),
4494 Selector_Name => Make_Identifier (Loc, Sel));
4496 elsif Is_Entity_Name (N)
4497 and then Is_Concurrent_Type (Entity (N))
4499 if Is_Task_Type (Entity (N)) then
4501 if Is_Current_Task (Entity (N)) then
4503 Make_Function_Call (Loc,
4504 Name => New_Reference_To (RTE (RE_Self), Loc));
4509 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4510 T_Body : constant Node_Id :=
4511 Parent (Corresponding_Body (Parent (Entity (N))));
4515 Make_Object_Declaration (Loc,
4516 Defining_Identifier => T_Self,
4517 Object_Definition =>
4518 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4520 Make_Function_Call (Loc,
4521 Name => New_Reference_To (RTE (RE_Self), Loc)));
4522 Prepend (Decl, Declarations (T_Body));
4524 Set_Scope (T_Self, Entity (N));
4525 return New_Occurrence_Of (T_Self, Loc);
4530 pragma Assert (Is_Protected_Type (Entity (N)));
4533 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4537 if Is_Protected_Type (Ntyp) then
4538 Sel := Name_uObject;
4540 elsif Is_Task_Type (Ntyp) then
4541 Sel := Name_uTask_Id;
4544 raise Program_Error;
4548 Make_Selected_Component (Loc,
4550 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4552 Selector_Name => Make_Identifier (Loc, Sel));
4556 ------------------------
4557 -- Convert_Concurrent --
4558 ------------------------
4560 function Convert_Concurrent
4562 Typ : Entity_Id) return Node_Id
4565 if not Is_Concurrent_Type (Typ) then
4569 Unchecked_Convert_To
4570 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4572 end Convert_Concurrent;
4574 -------------------------------------
4575 -- Debug_Private_Data_Declarations --
4576 -------------------------------------
4578 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4579 Debug_Nod : Node_Id;
4583 Decl := First (Decls);
4584 while Present (Decl)
4585 and then not Comes_From_Source (Decl)
4587 -- Declaration for concurrent entity _object and its access type,
4588 -- along with the entry index subtype:
4589 -- type prot_typVP is access prot_typV;
4590 -- _object : prot_typVP := prot_typV (_O);
4591 -- subtype Jnn is <Type of Index> range Low .. High;
4593 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4594 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4596 -- Declaration for the Protection object, discriminals, privals and
4597 -- entry index constant:
4598 -- conc_typR : protection_typ renames _object._object;
4599 -- discr_nameD : discr_typ renames _object.discr_name;
4600 -- discr_nameD : discr_typ renames _task.discr_name;
4601 -- prival_name : comp_typ renames _object.comp_name;
4602 -- J : constant Jnn :=
4603 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4605 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4606 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4607 Debug_Nod := Debug_Renaming_Declaration (Decl);
4609 if Present (Debug_Nod) then
4610 Insert_After (Decl, Debug_Nod);
4616 end Debug_Private_Data_Declarations;
4618 ----------------------------
4619 -- Entry_Index_Expression --
4620 ----------------------------
4622 function Entry_Index_Expression
4626 Ttyp : Entity_Id) return Node_Id
4636 -- The queues of entries and entry families appear in textual order in
4637 -- the associated record. The entry index is computed as the sum of the
4638 -- number of queues for all entries that precede the designated one, to
4639 -- which is added the index expression, if this expression denotes a
4640 -- member of a family.
4642 -- The following is a place holder for the count of simple entries
4644 Num := Make_Integer_Literal (Sloc, 1);
4646 -- We construct an expression which is a series of addition operations.
4647 -- The first operand is the number of single entries that precede this
4648 -- one, the second operand is the index value relative to the start of
4649 -- the referenced family, and the remaining operands are the lengths of
4650 -- the entry families that precede this entry, i.e. the constructed
4653 -- number_simple_entries +
4654 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4655 -- family'length + ...
4657 -- where index-value is the given index value, and s is the index
4658 -- subtype (we have to use pos because the subtype might be an
4659 -- enumeration type preventing direct subtraction). Note that the task
4660 -- entry array is one-indexed.
4662 -- The upper bound of the entry family may be a discriminant, so we
4663 -- retrieve the lower bound explicitly to compute offset, rather than
4664 -- using the index subtype which may mention a discriminant.
4666 if Present (Index) then
4667 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4676 Make_Attribute_Reference (Sloc,
4677 Attribute_Name => Name_Pos,
4678 Prefix => New_Reference_To (Base_Type (S), Sloc),
4679 Expressions => New_List (Relocate_Node (Index))),
4687 -- Now add lengths of preceding entries and entry families
4689 Prev := First_Entity (Ttyp);
4691 while Chars (Prev) /= Chars (Ent)
4692 or else (Ekind (Prev) /= Ekind (Ent))
4693 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4695 if Ekind (Prev) = E_Entry then
4696 Set_Intval (Num, Intval (Num) + 1);
4698 elsif Ekind (Prev) = E_Entry_Family then
4700 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4701 Lo := Type_Low_Bound (S);
4702 Hi := Type_High_Bound (S);
4707 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4709 -- Other components are anonymous types to be ignored
4719 end Entry_Index_Expression;
4721 ---------------------------
4722 -- Establish_Task_Master --
4723 ---------------------------
4725 procedure Establish_Task_Master (N : Node_Id) is
4728 if Restriction_Active (No_Task_Hierarchy) = False then
4729 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4730 Prepend_To (Declarations (N), Call);
4733 end Establish_Task_Master;
4735 --------------------------------
4736 -- Expand_Accept_Declarations --
4737 --------------------------------
4739 -- Part of the expansion of an accept statement involves the creation of
4740 -- a declaration that can be referenced from the statement sequence of
4745 -- This declaration is inserted immediately before the accept statement
4746 -- and it is important that it be inserted before the statements of the
4747 -- statement sequence are analyzed. Thus it would be too late to create
4748 -- this declaration in the Expand_N_Accept_Statement routine, which is
4749 -- why there is a separate procedure to be called directly from Sem_Ch9.
4751 -- Ann is used to hold the address of the record containing the parameters
4752 -- (see Expand_N_Entry_Call for more details on how this record is built).
4753 -- References to the parameters do an unchecked conversion of this address
4754 -- to a pointer to the required record type, and then access the field that
4755 -- holds the value of the required parameter. The entity for the address
4756 -- variable is held as the top stack element (i.e. the last element) of the
4757 -- Accept_Address stack in the corresponding entry entity, and this element
4758 -- must be set in place before the statements are processed.
4760 -- The above description applies to the case of a stand alone accept
4761 -- statement, i.e. one not appearing as part of a select alternative.
4763 -- For the case of an accept that appears as part of a select alternative
4764 -- of a selective accept, we must still create the declaration right away,
4765 -- since Ann is needed immediately, but there is an important difference:
4767 -- The declaration is inserted before the selective accept, not before
4768 -- the accept statement (which is not part of a list anyway, and so would
4769 -- not accommodate inserted declarations)
4771 -- We only need one address variable for the entire selective accept. So
4772 -- the Ann declaration is created only for the first accept alternative,
4773 -- and subsequent accept alternatives reference the same Ann variable.
4775 -- We can distinguish the two cases by seeing whether the accept statement
4776 -- is part of a list. If not, then it must be in an accept alternative.
4778 -- To expand the requeue statement, a label is provided at the end of the
4779 -- accept statement or alternative of which it is a part, so that the
4780 -- statement can be skipped after the requeue is complete. This label is
4781 -- created here rather than during the expansion of the accept statement,
4782 -- because it will be needed by any requeue statements within the accept,
4783 -- which are expanded before the accept.
4785 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4786 Loc : constant Source_Ptr := Sloc (N);
4787 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4788 Ann : Entity_Id := Empty;
4796 if Expander_Active then
4798 -- If we have no handled statement sequence, we may need to build
4799 -- a dummy sequence consisting of a null statement. This can be
4800 -- skipped if the trivial accept optimization is permitted.
4802 if not Trivial_Accept_OK
4804 (No (Stats) or else Null_Statements (Statements (Stats)))
4806 Set_Handled_Statement_Sequence (N,
4807 Make_Handled_Sequence_Of_Statements (Loc,
4808 New_List (Make_Null_Statement (Loc))));
4811 -- Create and declare two labels to be placed at the end of the
4812 -- accept statement. The first label is used to allow requeues to
4813 -- skip the remainder of entry processing. The second label is used
4814 -- to skip the remainder of entry processing if the rendezvous
4815 -- completes in the middle of the accept body.
4817 if Present (Handled_Statement_Sequence (N)) then
4822 Ent := Make_Temporary (Loc, 'L');
4823 Lab_Id := New_Reference_To (Ent, Loc);
4824 Lab := Make_Label (Loc, Lab_Id);
4826 Make_Implicit_Label_Declaration (Loc,
4827 Defining_Identifier => Ent,
4828 Label_Construct => Lab);
4829 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4831 Ent := Make_Temporary (Loc, 'L');
4832 Lab_Id := New_Reference_To (Ent, Loc);
4833 Lab := Make_Label (Loc, Lab_Id);
4835 Make_Implicit_Label_Declaration (Loc,
4836 Defining_Identifier => Ent,
4837 Label_Construct => Lab);
4838 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4846 -- Case of stand alone accept statement
4848 if Is_List_Member (N) then
4850 if Present (Handled_Statement_Sequence (N)) then
4851 Ann := Make_Temporary (Loc, 'A');
4854 Make_Object_Declaration (Loc,
4855 Defining_Identifier => Ann,
4856 Object_Definition =>
4857 New_Reference_To (RTE (RE_Address), Loc));
4859 Insert_Before (N, Adecl);
4862 Insert_Before (N, Ldecl);
4865 Insert_Before (N, Ldecl2);
4869 -- Case of accept statement which is in an accept alternative
4873 Acc_Alt : constant Node_Id := Parent (N);
4874 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4878 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4879 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4881 -- ??? Consider a single label for select statements
4883 if Present (Handled_Statement_Sequence (N)) then
4885 Statements (Handled_Statement_Sequence (N)));
4889 Statements (Handled_Statement_Sequence (N)));
4893 -- Find first accept alternative of the selective accept. A
4894 -- valid selective accept must have at least one accept in it.
4896 Alt := First (Select_Alternatives (Sel_Acc));
4898 while Nkind (Alt) /= N_Accept_Alternative loop
4902 -- If we are the first accept statement, then we have to create
4903 -- the Ann variable, as for the stand alone case, except that
4904 -- it is inserted before the selective accept. Similarly, a
4905 -- label for requeue expansion must be declared.
4907 if N = Accept_Statement (Alt) then
4908 Ann := Make_Temporary (Loc, 'A');
4910 Make_Object_Declaration (Loc,
4911 Defining_Identifier => Ann,
4912 Object_Definition =>
4913 New_Reference_To (RTE (RE_Address), Loc));
4915 Insert_Before (Sel_Acc, Adecl);
4918 -- If we are not the first accept statement, then find the Ann
4919 -- variable allocated by the first accept and use it.
4923 Node (Last_Elmt (Accept_Address
4924 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
4929 -- Merge here with Ann either created or referenced, and Adecl
4930 -- pointing to the corresponding declaration. Remaining processing
4931 -- is the same for the two cases.
4933 if Present (Ann) then
4934 Append_Elmt (Ann, Accept_Address (Ent));
4935 Set_Debug_Info_Needed (Ann);
4938 -- Create renaming declarations for the entry formals. Each reference
4939 -- to a formal becomes a dereference of a component of the parameter
4940 -- block, whose address is held in Ann. These declarations are
4941 -- eventually inserted into the accept block, and analyzed there so
4942 -- that they have the proper scope for gdb and do not conflict with
4943 -- other declarations.
4945 if Present (Parameter_Specifications (N))
4946 and then Present (Handled_Statement_Sequence (N))
4956 Formal := First_Formal (Ent);
4958 while Present (Formal) loop
4959 Comp := Entry_Component (Formal);
4961 Make_Defining_Identifier (Loc, Chars (Formal));
4963 Set_Etype (New_F, Etype (Formal));
4964 Set_Scope (New_F, Ent);
4966 -- Now we set debug info needed on New_F even though it does
4967 -- not come from source, so that the debugger will get the
4968 -- right information for these generated names.
4970 Set_Debug_Info_Needed (New_F);
4972 if Ekind (Formal) = E_In_Parameter then
4973 Set_Ekind (New_F, E_Constant);
4975 Set_Ekind (New_F, E_Variable);
4976 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
4979 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
4982 Make_Object_Renaming_Declaration (Loc,
4983 Defining_Identifier =>
4986 New_Reference_To (Etype (Formal), Loc),
4988 Make_Explicit_Dereference (Loc,
4989 Make_Selected_Component (Loc,
4991 Unchecked_Convert_To (
4992 Entry_Parameters_Type (Ent),
4993 New_Reference_To (Ann, Loc)),
4995 New_Reference_To (Comp, Loc))));
4997 if No (Declarations (N)) then
4998 Set_Declarations (N, New_List);
5001 Append (Decl, Declarations (N));
5002 Set_Renamed_Object (Formal, New_F);
5003 Next_Formal (Formal);
5010 end Expand_Accept_Declarations;
5012 ---------------------------------------------
5013 -- Expand_Access_Protected_Subprogram_Type --
5014 ---------------------------------------------
5016 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5017 Loc : constant Source_Ptr := Sloc (N);
5019 T : constant Entity_Id := Defining_Identifier (N);
5020 D_T : constant Entity_Id := Designated_Type (T);
5021 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5022 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5023 P_List : constant List_Id := Build_Protected_Spec
5024 (N, RTE (RE_Address), D_T, False);
5030 -- Create access to subprogram with full signature
5032 if Etype (D_T) /= Standard_Void_Type then
5034 Make_Access_Function_Definition (Loc,
5035 Parameter_Specifications => P_List,
5036 Result_Definition =>
5037 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5041 Make_Access_Procedure_Definition (Loc,
5042 Parameter_Specifications => P_List);
5046 Make_Full_Type_Declaration (Loc,
5047 Defining_Identifier => D_T2,
5048 Type_Definition => Def1);
5050 Insert_After (N, Decl1);
5053 -- Create Equivalent_Type, a record with two components for an access to
5054 -- object and an access to subprogram.
5057 Make_Component_Declaration (Loc,
5058 Defining_Identifier => Make_Temporary (Loc, 'P'),
5059 Component_Definition =>
5060 Make_Component_Definition (Loc,
5061 Aliased_Present => False,
5062 Subtype_Indication =>
5063 New_Occurrence_Of (RTE (RE_Address), Loc))),
5065 Make_Component_Declaration (Loc,
5066 Defining_Identifier => Make_Temporary (Loc, 'S'),
5067 Component_Definition =>
5068 Make_Component_Definition (Loc,
5069 Aliased_Present => False,
5070 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5073 Make_Full_Type_Declaration (Loc,
5074 Defining_Identifier => E_T,
5076 Make_Record_Definition (Loc,
5078 Make_Component_List (Loc,
5079 Component_Items => Comps)));
5081 Insert_After (Decl1, Decl2);
5083 Set_Equivalent_Type (T, E_T);
5084 end Expand_Access_Protected_Subprogram_Type;
5086 --------------------------
5087 -- Expand_Entry_Barrier --
5088 --------------------------
5090 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5091 Cond : constant Node_Id :=
5092 Condition (Entry_Body_Formal_Part (N));
5093 Prot : constant Entity_Id := Scope (Ent);
5094 Spec_Decl : constant Node_Id := Parent (Prot);
5097 Body_Decl : Node_Id;
5100 if No_Run_Time_Mode then
5101 Error_Msg_CRT ("entry barrier", N);
5105 -- The body of the entry barrier must be analyzed in the context of the
5106 -- protected object, but its scope is external to it, just as any other
5107 -- unprotected version of a protected operation. The specification has
5108 -- been produced when the protected type declaration was elaborated. We
5109 -- build the body, insert it in the enclosing scope, but analyze it in
5110 -- the current context. A more uniform approach would be to treat the
5111 -- barrier just as a protected function, and discard the protected
5112 -- version of it because it is never called.
5114 if Expander_Active then
5115 B_F := Build_Barrier_Function (N, Ent, Prot);
5116 Func := Barrier_Function (Ent);
5117 Set_Corresponding_Spec (B_F, Func);
5119 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5121 if Nkind (Parent (Body_Decl)) = N_Subunit then
5122 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5125 Insert_Before_And_Analyze (Body_Decl, B_F);
5127 Set_Discriminals (Spec_Decl);
5128 Set_Scope (Func, Scope (Prot));
5131 Analyze_And_Resolve (Cond, Any_Boolean);
5134 -- The Ravenscar profile restricts barriers to simple variables declared
5135 -- within the protected object. We also allow Boolean constants, since
5136 -- these appear in several published examples and are also allowed by
5137 -- the Aonix compiler.
5139 -- Note that after analysis variables in this context will be replaced
5140 -- by the corresponding prival, that is to say a renaming of a selected
5141 -- component of the form _Object.Var. If expansion is disabled, as
5142 -- within a generic, we check that the entity appears in the current
5145 if Is_Entity_Name (Cond) then
5147 -- A small optimization of useless renamings. If the scope of the
5148 -- entity of the condition is not the barrier function, then the
5149 -- condition does not reference any of the generated renamings
5150 -- within the function.
5153 and then Scope (Entity (Cond)) /= Func
5155 Set_Declarations (B_F, Empty_List);
5158 if Entity (Cond) = Standard_False
5160 Entity (Cond) = Standard_True
5164 elsif not Expander_Active
5165 and then Scope (Entity (Cond)) = Current_Scope
5169 -- Check for case of _object.all.field (note that the explicit
5170 -- dereference gets inserted by analyze/expand of _object.field)
5172 elsif Present (Renamed_Object (Entity (Cond)))
5174 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5178 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5184 -- It is not a boolean variable or literal, so check the restriction
5186 Check_Restriction (Simple_Barriers, Cond);
5187 end Expand_Entry_Barrier;
5189 ------------------------------
5190 -- Expand_N_Abort_Statement --
5191 ------------------------------
5193 -- Expand abort T1, T2, .. Tn; into:
5194 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5196 procedure Expand_N_Abort_Statement (N : Node_Id) is
5197 Loc : constant Source_Ptr := Sloc (N);
5198 Tlist : constant List_Id := Names (N);
5204 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5207 Tasknm := First (Tlist);
5209 while Present (Tasknm) loop
5212 -- A task interface class-wide type object is being aborted.
5213 -- Retrieve its _task_id by calling a dispatching routine.
5215 if Ada_Version >= Ada_2005
5216 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5217 and then Is_Interface (Etype (Tasknm))
5218 and then Is_Task_Interface (Etype (Tasknm))
5220 Append_To (Component_Associations (Aggr),
5221 Make_Component_Association (Loc,
5222 Choices => New_List (
5223 Make_Integer_Literal (Loc, Count)),
5226 -- Task_Id (Tasknm._disp_get_task_id)
5228 Make_Unchecked_Type_Conversion (Loc,
5230 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5232 Make_Selected_Component (Loc,
5234 New_Copy_Tree (Tasknm),
5236 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5239 Append_To (Component_Associations (Aggr),
5240 Make_Component_Association (Loc,
5241 Choices => New_List (
5242 Make_Integer_Literal (Loc, Count)),
5243 Expression => Concurrent_Ref (Tasknm)));
5250 Make_Procedure_Call_Statement (Loc,
5251 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5252 Parameter_Associations => New_List (
5253 Make_Qualified_Expression (Loc,
5254 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5255 Expression => Aggr))));
5258 end Expand_N_Abort_Statement;
5260 -------------------------------
5261 -- Expand_N_Accept_Statement --
5262 -------------------------------
5264 -- This procedure handles expansion of accept statements that stand
5265 -- alone, i.e. they are not part of an accept alternative. The expansion
5266 -- of accept statement in accept alternatives is handled by the routines
5267 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5268 -- following description applies only to stand alone accept statements.
5270 -- If there is no handled statement sequence, or only null statements,
5271 -- then this is called a trivial accept, and the expansion is:
5273 -- Accept_Trivial (entry-index)
5275 -- If there is a handled statement sequence, then the expansion is:
5282 -- Accept_Call (entry-index, Ann);
5283 -- Renaming_Declarations for formals
5284 -- <statement sequence from N_Accept_Statement node>
5285 -- Complete_Rendezvous;
5290 -- <exception handler from N_Accept_Statement node>
5291 -- Complete_Rendezvous;
5293 -- <exception handler from N_Accept_Statement node>
5294 -- Complete_Rendezvous;
5299 -- when all others =>
5300 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5303 -- The first three declarations were already inserted ahead of the accept
5304 -- statement by the Expand_Accept_Declarations procedure, which was called
5305 -- directly from the semantics during analysis of the accept statement,
5306 -- before analyzing its contained statements.
5308 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5309 -- from possible expansion activity (the original source of course does
5310 -- not have any declarations associated with the accept statement, since
5311 -- an accept statement has no declarative part). In particular, if the
5312 -- expander is active, the first such declaration is the declaration of
5313 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5315 -- The two blocks are merged into a single block if the inner block has
5316 -- no exception handlers, but otherwise two blocks are required, since
5317 -- exceptions might be raised in the exception handlers of the inner
5318 -- block, and Exceptional_Complete_Rendezvous must be called.
5320 procedure Expand_N_Accept_Statement (N : Node_Id) is
5321 Loc : constant Source_Ptr := Sloc (N);
5322 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5323 Ename : constant Node_Id := Entry_Direct_Name (N);
5324 Eindx : constant Node_Id := Entry_Index (N);
5325 Eent : constant Entity_Id := Entity (Ename);
5326 Acstack : constant Elist_Id := Accept_Address (Eent);
5327 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5328 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5333 -- Start of processing for Expand_N_Accept_Statement
5336 -- If accept statement is not part of a list, then its parent must be
5337 -- an accept alternative, and, as described above, we do not do any
5338 -- expansion for such accept statements at this level.
5340 if not Is_List_Member (N) then
5341 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5344 -- Trivial accept case (no statement sequence, or null statements).
5345 -- If the accept statement has declarations, then just insert them
5346 -- before the procedure call.
5348 elsif Trivial_Accept_OK
5349 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5351 -- Remove declarations for renamings, because the parameter block
5352 -- will not be assigned.
5359 D := First (Declarations (N));
5361 while Present (D) loop
5363 if Nkind (D) = N_Object_Renaming_Declaration then
5371 if Present (Declarations (N)) then
5372 Insert_Actions (N, Declarations (N));
5376 Make_Procedure_Call_Statement (Loc,
5377 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5378 Parameter_Associations => New_List (
5379 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5383 -- Discard Entry_Address that was created for it, so it will not be
5384 -- emitted if this accept statement is in the statement part of a
5385 -- delay alternative.
5387 if Present (Stats) then
5388 Remove_Last_Elmt (Acstack);
5391 -- Case of statement sequence present
5394 -- Construct the block, using the declarations from the accept
5395 -- statement if any to initialize the declarations of the block.
5397 Blkent := Make_Temporary (Loc, 'A');
5398 Set_Ekind (Blkent, E_Block);
5399 Set_Etype (Blkent, Standard_Void_Type);
5400 Set_Scope (Blkent, Current_Scope);
5403 Make_Block_Statement (Loc,
5404 Identifier => New_Reference_To (Blkent, Loc),
5405 Declarations => Declarations (N),
5406 Handled_Statement_Sequence => Build_Accept_Body (N));
5408 -- For the analysis of the generated declarations, the parent node
5409 -- must be properly set.
5411 Set_Parent (Block, Parent (N));
5413 -- Prepend call to Accept_Call to main statement sequence If the
5414 -- accept has exception handlers, the statement sequence is wrapped
5415 -- in a block. Insert call and renaming declarations in the
5416 -- declarations of the block, so they are elaborated before the
5420 Make_Procedure_Call_Statement (Loc,
5421 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5422 Parameter_Associations => New_List (
5423 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5424 New_Reference_To (Ann, Loc)));
5426 if Parent (Stats) = N then
5427 Prepend (Call, Statements (Stats));
5436 Push_Scope (Blkent);
5444 D := First (Declarations (N));
5445 while Present (D) loop
5448 if Nkind (D) = N_Object_Renaming_Declaration then
5450 -- The renaming declarations for the formals were created
5451 -- during analysis of the accept statement, and attached to
5452 -- the list of declarations. Place them now in the context
5453 -- of the accept block or subprogram.
5456 Typ := Entity (Subtype_Mark (D));
5457 Insert_After (Call, D);
5460 -- If the formal is class_wide, it does not have an actual
5461 -- subtype. The analysis of the renaming declaration creates
5462 -- one, but we need to retain the class-wide nature of the
5465 if Is_Class_Wide_Type (Typ) then
5466 Set_Etype (Defining_Identifier (D), Typ);
5477 -- Replace the accept statement by the new block
5482 -- Last step is to unstack the Accept_Address value
5484 Remove_Last_Elmt (Acstack);
5486 end Expand_N_Accept_Statement;
5488 ----------------------------------
5489 -- Expand_N_Asynchronous_Select --
5490 ----------------------------------
5492 -- This procedure assumes that the trigger statement is an entry call or
5493 -- a dispatching procedure call. A delay alternative should already have
5494 -- been expanded into an entry call to the appropriate delay object Wait
5497 -- If the trigger is a task entry call, the select is implemented with
5498 -- a Task_Entry_Call:
5503 -- P : parms := (parm, parm, parm);
5505 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5507 -- procedure _clean is
5510 -- Cancel_Task_Entry_Call (C);
5517 -- (<acceptor-task>, -- Acceptor
5518 -- <entry-index>, -- E
5519 -- P'Address, -- Uninterpreted_Data
5520 -- Asynchronous_Call, -- Mode
5521 -- B); -- Rendezvous_Successful
5528 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5531 -- when Abort_Signal => Abort_Undefer;
5538 -- <triggered-statements>
5542 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5543 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5547 -- P : parms := (parm, parm, parm);
5549 -- Call_Simple (acceptor-task, entry-index, P'Address);
5555 -- so the task at hand is to convert the latter expansion into the former
5557 -- If the trigger is a protected entry call, the select is implemented
5558 -- with Protected_Entry_Call:
5561 -- P : E1_Params := (param, param, param);
5562 -- Bnn : Communications_Block;
5567 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5569 -- procedure _clean is
5572 -- if Enqueued (Bnn) then
5573 -- Cancel_Protected_Entry_Call (Bnn);
5580 -- Protected_Entry_Call
5581 -- (po._object'Access, -- Object
5582 -- <entry index>, -- E
5583 -- P'Address, -- Uninterpreted_Data
5584 -- Asynchronous_Call, -- Mode
5587 -- if Enqueued (Bnn) then
5591 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5594 -- when Abort_Signal => Abort_Undefer;
5597 -- if not Cancelled (Bnn) then
5598 -- <triggered-statements>
5602 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5606 -- P : E1_Params := (param, param, param);
5607 -- Bnn : Communications_Block;
5610 -- Protected_Entry_Call
5611 -- (po._object'Access, -- Object
5612 -- <entry index>, -- E
5613 -- P'Address, -- Uninterpreted_Data
5614 -- Simple_Call, -- Mode
5621 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5625 -- B : Boolean := False;
5626 -- Bnn : Communication_Block;
5627 -- C : Ada.Tags.Prim_Op_Kind;
5628 -- D : System.Storage_Elements.Dummy_Communication_Block;
5629 -- K : Ada.Tags.Tagged_Kind :=
5630 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5631 -- P : Parameters := (Param1 .. ParamN);
5636 -- if K = Ada.Tags.TK_Limited_Tagged then
5637 -- <dispatching-call>;
5638 -- <triggering-statements>;
5642 -- Ada.Tags.Get_Offset_Index
5643 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5645 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5647 -- if C = POK_Protected_Entry then
5649 -- procedure _clean is
5651 -- if Enqueued (Bnn) then
5652 -- Cancel_Protected_Entry_Call (Bnn);
5658 -- _Disp_Asynchronous_Select
5659 -- (<object>, S, P'Address, D, B);
5660 -- Bnn := Communication_Block (D);
5662 -- Param1 := P.Param1;
5664 -- ParamN := P.ParamN;
5666 -- if Enqueued (Bnn) then
5667 -- <abortable-statements>
5670 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5673 -- when Abort_Signal => Abort_Undefer;
5676 -- if not Cancelled (Bnn) then
5677 -- <triggering-statements>
5680 -- elsif C = POK_Task_Entry then
5682 -- procedure _clean is
5684 -- Cancel_Task_Entry_Call (U);
5690 -- _Disp_Asynchronous_Select
5691 -- (<object>, S, P'Address, D, B);
5692 -- Bnn := Communication_Bloc (D);
5694 -- Param1 := P.Param1;
5696 -- ParamN := P.ParamN;
5701 -- <abortable-statements>
5703 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5706 -- when Abort_Signal => Abort_Undefer;
5710 -- <triggering-statements>
5715 -- <dispatching-call>;
5716 -- <triggering-statements>
5721 -- The job is to convert this to the asynchronous form
5723 -- If the trigger is a delay statement, it will have been expanded into a
5724 -- call to one of the GNARL delay procedures. This routine will convert
5725 -- this into a protected entry call on a delay object and then continue
5726 -- processing as for a protected entry call trigger. This requires
5727 -- declaring a Delay_Block object and adding a pointer to this object to
5728 -- the parameter list of the delay procedure to form the parameter list of
5729 -- the entry call. This object is used by the runtime to queue the delay
5732 -- For a description of the use of P and the assignments after the call,
5733 -- see Expand_N_Entry_Call_Statement.
5735 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5736 Loc : constant Source_Ptr := Sloc (N);
5737 Abrt : constant Node_Id := Abortable_Part (N);
5738 Astats : constant List_Id := Statements (Abrt);
5739 Trig : constant Node_Id := Triggering_Alternative (N);
5740 Tstats : constant List_Id := Statements (Trig);
5742 Abort_Block_Ent : Entity_Id;
5743 Abortable_Block : Node_Id;
5745 Blk_Ent : Entity_Id;
5746 Blk_Typ : Entity_Id;
5748 Call_Ent : Entity_Id;
5749 Cancel_Param : Entity_Id;
5750 Cleanup_Block : Node_Id;
5751 Cleanup_Block_Ent : Entity_Id;
5752 Cleanup_Stmts : List_Id;
5753 Conc_Typ_Stmts : List_Id;
5755 Dblock_Ent : Entity_Id;
5760 Enqueue_Call : Node_Id;
5764 Lim_Typ_Stmts : List_Id;
5770 ProtE_Stmts : List_Id;
5771 ProtP_Stmts : List_Id;
5774 Target_Undefer : RE_Id;
5775 TaskE_Stmts : List_Id;
5776 Undefer_Args : List_Id := No_List;
5778 B : Entity_Id; -- Call status flag
5779 Bnn : Entity_Id; -- Communication block
5780 C : Entity_Id; -- Call kind
5781 K : Entity_Id; -- Tagged kind
5782 P : Entity_Id; -- Parameter block
5783 S : Entity_Id; -- Primitive operation slot
5784 T : Entity_Id; -- Additional status flag
5787 Blk_Ent := Make_Temporary (Loc, 'A');
5788 Ecall := Triggering_Statement (Trig);
5790 -- The arguments in the call may require dynamic allocation, and the
5791 -- call statement may have been transformed into a block. The block
5792 -- may contain additional declarations for internal entities, and the
5793 -- original call is found by sequential search.
5795 if Nkind (Ecall) = N_Block_Statement then
5796 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5797 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5798 N_Entry_Call_Statement)
5804 -- This is either a dispatching call or a delay statement used as a
5805 -- trigger which was expanded into a procedure call.
5807 if Nkind (Ecall) = N_Procedure_Call_Statement then
5808 if Ada_Version >= Ada_2005
5810 (No (Original_Node (Ecall))
5811 or else not Nkind_In (Original_Node (Ecall),
5812 N_Delay_Relative_Statement,
5813 N_Delay_Until_Statement))
5815 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5820 -- Call status flag processing, generate:
5821 -- B : Boolean := False;
5823 B := Build_B (Loc, Decls);
5825 -- Communication block processing, generate:
5826 -- Bnn : Communication_Block;
5828 Bnn := Make_Temporary (Loc, 'B');
5830 Make_Object_Declaration (Loc,
5831 Defining_Identifier => Bnn,
5832 Object_Definition =>
5833 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5835 -- Call kind processing, generate:
5836 -- C : Ada.Tags.Prim_Op_Kind;
5838 C := Build_C (Loc, Decls);
5840 -- Tagged kind processing, generate:
5841 -- K : Ada.Tags.Tagged_Kind :=
5842 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5844 -- Dummy communication block, generate:
5845 -- D : Dummy_Communication_Block;
5848 Make_Object_Declaration (Loc,
5849 Defining_Identifier =>
5850 Make_Defining_Identifier (Loc, Name_uD),
5851 Object_Definition =>
5853 RTE (RE_Dummy_Communication_Block), Loc)));
5855 K := Build_K (Loc, Decls, Obj);
5857 -- Parameter block processing
5859 Blk_Typ := Build_Parameter_Block
5860 (Loc, Actuals, Formals, Decls);
5861 P := Parameter_Block_Pack
5862 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5864 -- Dispatch table slot processing, generate:
5867 S := Build_S (Loc, Decls);
5869 -- Additional status flag processing, generate:
5872 T := Make_Temporary (Loc, 'T');
5874 Make_Object_Declaration (Loc,
5875 Defining_Identifier => T,
5876 Object_Definition =>
5877 New_Reference_To (Standard_Boolean, Loc)));
5879 ------------------------------
5880 -- Protected entry handling --
5881 ------------------------------
5884 -- Param1 := P.Param1;
5886 -- ParamN := P.ParamN;
5888 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5891 -- Bnn := Communication_Block (D);
5893 Prepend_To (Cleanup_Stmts,
5894 Make_Assignment_Statement (Loc,
5896 New_Reference_To (Bnn, Loc),
5898 Make_Unchecked_Type_Conversion (Loc,
5900 New_Reference_To (RTE (RE_Communication_Block), Loc),
5902 Make_Identifier (Loc, Name_uD))));
5905 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5907 Prepend_To (Cleanup_Stmts,
5908 Make_Procedure_Call_Statement (Loc,
5911 Find_Prim_Op (Etype (Etype (Obj)),
5912 Name_uDisp_Asynchronous_Select),
5914 Parameter_Associations =>
5916 New_Copy_Tree (Obj), -- <object>
5917 New_Reference_To (S, Loc), -- S
5918 Make_Attribute_Reference (Loc, -- P'Address
5920 New_Reference_To (P, Loc),
5923 Make_Identifier (Loc, Name_uD), -- D
5924 New_Reference_To (B, Loc)))); -- B
5927 -- if Enqueued (Bnn) then
5928 -- <abortable-statements>
5931 Append_To (Cleanup_Stmts,
5932 Make_If_Statement (Loc,
5934 Make_Function_Call (Loc,
5936 New_Reference_To (RTE (RE_Enqueued), Loc),
5937 Parameter_Associations =>
5939 New_Reference_To (Bnn, Loc))),
5942 New_Copy_List_Tree (Astats)));
5944 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
5945 -- will then generate a _clean for the communication block Bnn.
5949 -- procedure _clean is
5951 -- if Enqueued (Bnn) then
5952 -- Cancel_Protected_Entry_Call (Bnn);
5961 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
5963 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
5965 -- Wrap the cleanup block in an exception handling block
5971 -- when Abort_Signal => Abort_Undefer;
5974 Abort_Block_Ent := Make_Temporary (Loc, 'A');
5977 Make_Implicit_Label_Declaration (Loc,
5978 Defining_Identifier =>
5982 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
5985 -- if not Cancelled (Bnn) then
5986 -- <triggering-statements>
5989 Append_To (ProtE_Stmts,
5990 Make_If_Statement (Loc,
5994 Make_Function_Call (Loc,
5996 New_Reference_To (RTE (RE_Cancelled), Loc),
5997 Parameter_Associations =>
5999 New_Reference_To (Bnn, Loc)))),
6002 New_Copy_List_Tree (Tstats)));
6004 -------------------------
6005 -- Task entry handling --
6006 -------------------------
6009 -- Param1 := P.Param1;
6011 -- ParamN := P.ParamN;
6013 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6016 -- Bnn := Communication_Block (D);
6018 Append_To (TaskE_Stmts,
6019 Make_Assignment_Statement (Loc,
6021 New_Reference_To (Bnn, Loc),
6023 Make_Unchecked_Type_Conversion (Loc,
6025 New_Reference_To (RTE (RE_Communication_Block), Loc),
6027 Make_Identifier (Loc, Name_uD))));
6030 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6032 Prepend_To (TaskE_Stmts,
6033 Make_Procedure_Call_Statement (Loc,
6036 Find_Prim_Op (Etype (Etype (Obj)),
6037 Name_uDisp_Asynchronous_Select),
6039 Parameter_Associations =>
6041 New_Copy_Tree (Obj), -- <object>
6042 New_Reference_To (S, Loc), -- S
6043 Make_Attribute_Reference (Loc, -- P'Address
6045 New_Reference_To (P, Loc),
6048 Make_Identifier (Loc, Name_uD), -- D
6049 New_Reference_To (B, Loc)))); -- B
6054 Prepend_To (TaskE_Stmts,
6055 Make_Procedure_Call_Statement (Loc,
6057 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6058 Parameter_Associations =>
6063 -- <abortable-statements>
6065 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6067 Prepend_To (Cleanup_Stmts,
6068 Make_Procedure_Call_Statement (Loc,
6070 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6071 Parameter_Associations =>
6074 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6075 -- will generate a _clean for the additional status flag.
6079 -- procedure _clean is
6081 -- Cancel_Task_Entry_Call (U);
6089 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6091 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6093 -- Wrap the cleanup block in an exception handling block
6099 -- when Abort_Signal => Abort_Undefer;
6102 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6104 Append_To (TaskE_Stmts,
6105 Make_Implicit_Label_Declaration (Loc,
6106 Defining_Identifier => Abort_Block_Ent));
6108 Append_To (TaskE_Stmts,
6110 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6114 -- <triggering-statements>
6117 Append_To (TaskE_Stmts,
6118 Make_If_Statement (Loc,
6122 New_Reference_To (T, Loc)),
6125 New_Copy_List_Tree (Tstats)));
6127 ----------------------------------
6128 -- Protected procedure handling --
6129 ----------------------------------
6132 -- <dispatching-call>;
6133 -- <triggering-statements>
6135 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6136 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6139 -- S := Ada.Tags.Get_Offset_Index
6140 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6143 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6146 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6148 Append_To (Conc_Typ_Stmts,
6149 Make_Procedure_Call_Statement (Loc,
6152 Find_Prim_Op (Etype (Etype (Obj)),
6153 Name_uDisp_Get_Prim_Op_Kind),
6155 Parameter_Associations =>
6157 New_Copy_Tree (Obj),
6158 New_Reference_To (S, Loc),
6159 New_Reference_To (C, Loc))));
6162 -- if C = POK_Procedure_Entry then
6164 -- elsif C = POK_Task_Entry then
6170 Append_To (Conc_Typ_Stmts,
6171 Make_If_Statement (Loc,
6175 New_Reference_To (C, Loc),
6177 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6184 Make_Elsif_Part (Loc,
6188 New_Reference_To (C, Loc),
6190 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6199 -- <dispatching-call>;
6200 -- <triggering-statements>
6202 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6203 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6206 -- if K = Ada.Tags.TK_Limited_Tagged then
6213 Make_If_Statement (Loc,
6217 New_Reference_To (K, Loc),
6219 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6228 Make_Block_Statement (Loc,
6231 Handled_Statement_Sequence =>
6232 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6237 -- Delay triggering statement processing
6240 -- Add a Delay_Block object to the parameter list of the delay
6241 -- procedure to form the parameter list of the Wait entry call.
6243 Dblock_Ent := Make_Temporary (Loc, 'D');
6245 Pdef := Entity (Name (Ecall));
6247 if Is_RTE (Pdef, RO_CA_Delay_For) then
6249 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6251 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6253 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6255 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6256 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6259 Append_To (Parameter_Associations (Ecall),
6260 Make_Attribute_Reference (Loc,
6261 Prefix => New_Reference_To (Dblock_Ent, Loc),
6262 Attribute_Name => Name_Unchecked_Access));
6264 -- Create the inner block to protect the abortable part
6267 Make_Implicit_Exception_Handler (Loc,
6268 Exception_Choices =>
6269 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6270 Statements => New_List (
6271 Make_Procedure_Call_Statement (Loc,
6272 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6275 Make_Procedure_Call_Statement (Loc,
6276 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6279 Make_Block_Statement (Loc,
6280 Identifier => New_Reference_To (Blk_Ent, Loc),
6281 Handled_Statement_Sequence =>
6282 Make_Handled_Sequence_Of_Statements (Loc,
6283 Statements => Astats),
6284 Has_Created_Identifier => True,
6285 Is_Asynchronous_Call_Block => True);
6287 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6290 Make_Implicit_If_Statement (N,
6291 Condition => Make_Function_Call (Loc,
6292 Name => Enqueue_Call,
6293 Parameter_Associations => Parameter_Associations (Ecall)),
6295 New_List (Make_Block_Statement (Loc,
6296 Handled_Statement_Sequence =>
6297 Make_Handled_Sequence_Of_Statements (Loc,
6298 Statements => New_List (
6299 Make_Implicit_Label_Declaration (Loc,
6300 Defining_Identifier => Blk_Ent,
6301 Label_Construct => Abortable_Block),
6303 Exception_Handlers => Hdle)))));
6305 Stmts := New_List (Ecall);
6307 -- Construct statement sequence for new block
6310 Make_Implicit_If_Statement (N,
6311 Condition => Make_Function_Call (Loc,
6312 Name => New_Reference_To (
6313 RTE (RE_Timed_Out), Loc),
6314 Parameter_Associations => New_List (
6315 Make_Attribute_Reference (Loc,
6316 Prefix => New_Reference_To (Dblock_Ent, Loc),
6317 Attribute_Name => Name_Unchecked_Access))),
6318 Then_Statements => Tstats));
6320 -- The result is the new block
6322 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6325 Make_Block_Statement (Loc,
6326 Declarations => New_List (
6327 Make_Object_Declaration (Loc,
6328 Defining_Identifier => Dblock_Ent,
6329 Aliased_Present => True,
6330 Object_Definition => New_Reference_To (
6331 RTE (RE_Delay_Block), Loc))),
6333 Handled_Statement_Sequence =>
6334 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6344 Extract_Entry (Ecall, Concval, Ename, Index);
6345 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6347 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6348 Decls := Declarations (Ecall);
6350 if Is_Protected_Type (Etype (Concval)) then
6352 -- Get the declarations of the block expanded from the entry call
6354 Decl := First (Decls);
6355 while Present (Decl)
6357 (Nkind (Decl) /= N_Object_Declaration
6358 or else not Is_RTE (Etype (Object_Definition (Decl)),
6359 RE_Communication_Block))
6364 pragma Assert (Present (Decl));
6365 Cancel_Param := Defining_Identifier (Decl);
6367 -- Change the mode of the Protected_Entry_Call call
6369 -- Protected_Entry_Call (
6370 -- Object => po._object'Access,
6371 -- E => <entry index>;
6372 -- Uninterpreted_Data => P'Address;
6373 -- Mode => Asynchronous_Call;
6376 Stmt := First (Stmts);
6378 -- Skip assignments to temporaries created for in-out parameters
6380 -- This makes unwarranted assumptions about the shape of the expanded
6381 -- tree for the call, and should be cleaned up ???
6383 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6389 Param := First (Parameter_Associations (Call));
6390 while Present (Param)
6391 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6396 pragma Assert (Present (Param));
6397 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6400 -- Append an if statement to execute the abortable part
6403 -- if Enqueued (Bnn) then
6406 Make_Implicit_If_Statement (N,
6407 Condition => Make_Function_Call (Loc,
6408 Name => New_Reference_To (
6409 RTE (RE_Enqueued), Loc),
6410 Parameter_Associations => New_List (
6411 New_Reference_To (Cancel_Param, Loc))),
6412 Then_Statements => Astats));
6415 Make_Block_Statement (Loc,
6416 Identifier => New_Reference_To (Blk_Ent, Loc),
6417 Handled_Statement_Sequence =>
6418 Make_Handled_Sequence_Of_Statements (Loc,
6419 Statements => Stmts),
6420 Has_Created_Identifier => True,
6421 Is_Asynchronous_Call_Block => True);
6423 -- For the VM call Update_Exception instead of Abort_Undefer.
6424 -- See 4jexcept.ads for an explanation.
6426 if VM_Target = No_VM then
6427 Target_Undefer := RE_Abort_Undefer;
6429 Target_Undefer := RE_Update_Exception;
6431 New_List (Make_Function_Call (Loc,
6432 Name => New_Occurrence_Of
6433 (RTE (RE_Current_Target_Exception), Loc)));
6437 Make_Block_Statement (Loc,
6438 Handled_Statement_Sequence =>
6439 Make_Handled_Sequence_Of_Statements (Loc,
6440 Statements => New_List (
6441 Make_Implicit_Label_Declaration (Loc,
6442 Defining_Identifier => Blk_Ent,
6443 Label_Construct => Abortable_Block),
6448 Exception_Handlers => New_List (
6449 Make_Implicit_Exception_Handler (Loc,
6451 -- when Abort_Signal =>
6452 -- Abort_Undefer.all;
6454 Exception_Choices =>
6455 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6456 Statements => New_List (
6457 Make_Procedure_Call_Statement (Loc,
6458 Name => New_Reference_To (
6459 RTE (Target_Undefer), Loc),
6460 Parameter_Associations => Undefer_Args)))))),
6462 -- if not Cancelled (Bnn) then
6463 -- triggered statements
6466 Make_Implicit_If_Statement (N,
6467 Condition => Make_Op_Not (Loc,
6469 Make_Function_Call (Loc,
6470 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6471 Parameter_Associations => New_List (
6472 New_Occurrence_Of (Cancel_Param, Loc)))),
6473 Then_Statements => Tstats));
6475 -- Asynchronous task entry call
6482 B := Make_Defining_Identifier (Loc, Name_uB);
6484 -- Insert declaration of B in declarations of existing block
6487 Make_Object_Declaration (Loc,
6488 Defining_Identifier => B,
6489 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6491 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6493 -- Insert declaration of C in declarations of existing block
6496 Make_Object_Declaration (Loc,
6497 Defining_Identifier => Cancel_Param,
6498 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6500 -- Remove and save the call to Call_Simple
6502 Stmt := First (Stmts);
6504 -- Skip assignments to temporaries created for in-out parameters.
6505 -- This makes unwarranted assumptions about the shape of the expanded
6506 -- tree for the call, and should be cleaned up ???
6508 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6514 -- Create the inner block to protect the abortable part
6517 Make_Implicit_Exception_Handler (Loc,
6518 Exception_Choices =>
6519 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6522 Make_Procedure_Call_Statement (Loc,
6523 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6526 Make_Procedure_Call_Statement (Loc,
6527 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6530 Make_Block_Statement (Loc,
6531 Identifier => New_Reference_To (Blk_Ent, Loc),
6532 Handled_Statement_Sequence =>
6533 Make_Handled_Sequence_Of_Statements (Loc,
6534 Statements => Astats),
6535 Has_Created_Identifier => True,
6536 Is_Asynchronous_Call_Block => True);
6539 Make_Block_Statement (Loc,
6540 Handled_Statement_Sequence =>
6541 Make_Handled_Sequence_Of_Statements (Loc,
6542 Statements => New_List (
6543 Make_Implicit_Label_Declaration (Loc,
6544 Defining_Identifier =>
6549 Exception_Handlers => Hdle)));
6551 -- Create new call statement
6553 Params := Parameter_Associations (Call);
6556 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6558 New_Reference_To (B, Loc));
6561 Make_Procedure_Call_Statement (Loc,
6563 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6564 Parameter_Associations => Params));
6566 -- Construct statement sequence for new block
6569 Make_Implicit_If_Statement (N,
6572 New_Reference_To (Cancel_Param, Loc)),
6573 Then_Statements => Tstats));
6575 -- Protected the call against abort
6578 Make_Procedure_Call_Statement (Loc,
6579 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6580 Parameter_Associations => Empty_List));
6583 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6585 -- The result is the new block
6588 Make_Block_Statement (Loc,
6589 Declarations => Decls,
6590 Handled_Statement_Sequence =>
6591 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6594 end Expand_N_Asynchronous_Select;
6596 -------------------------------------
6597 -- Expand_N_Conditional_Entry_Call --
6598 -------------------------------------
6600 -- The conditional task entry call is converted to a call to
6605 -- P : parms := (parm, parm, parm);
6609 -- (<acceptor-task>, -- Acceptor
6610 -- <entry-index>, -- E
6611 -- P'Address, -- Uninterpreted_Data
6612 -- Conditional_Call, -- Mode
6613 -- B); -- Rendezvous_Successful
6618 -- normal-statements
6624 -- For a description of the use of P and the assignments after the call,
6625 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6626 -- conditional entry call has already been expanded (by the Expand_N_Entry
6627 -- _Call_Statement procedure) as follows:
6630 -- P : parms := (parm, parm, parm);
6632 -- ... info for in-out parameters
6633 -- Call_Simple (acceptor-task, entry-index, P'Address);
6639 -- so the task at hand is to convert the latter expansion into the former
6641 -- The conditional protected entry call is converted to a call to
6642 -- Protected_Entry_Call:
6645 -- P : parms := (parm, parm, parm);
6646 -- Bnn : Communications_Block;
6649 -- Protected_Entry_Call
6650 -- (po._object'Access, -- Object
6651 -- <entry index>, -- E
6652 -- P'Address, -- Uninterpreted_Data
6653 -- Conditional_Call, -- Mode
6658 -- if Cancelled (Bnn) then
6661 -- normal-statements
6665 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6669 -- B : Boolean := False;
6670 -- C : Ada.Tags.Prim_Op_Kind;
6671 -- K : Ada.Tags.Tagged_Kind :=
6672 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6673 -- P : Parameters := (Param1 .. ParamN);
6677 -- if K = Ada.Tags.TK_Limited_Tagged then
6678 -- <dispatching-call>;
6679 -- <triggering-statements>
6683 -- Ada.Tags.Get_Offset_Index
6684 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6686 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6688 -- if C = POK_Protected_Entry
6689 -- or else C = POK_Task_Entry
6691 -- Param1 := P.Param1;
6693 -- ParamN := P.ParamN;
6697 -- if C = POK_Procedure
6698 -- or else C = POK_Protected_Procedure
6699 -- or else C = POK_Task_Procedure
6701 -- <dispatching-call>;
6704 -- <triggering-statements>
6706 -- <else-statements>
6711 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6712 Loc : constant Source_Ptr := Sloc (N);
6713 Alt : constant Node_Id := Entry_Call_Alternative (N);
6714 Blk : Node_Id := Entry_Call_Statement (Alt);
6717 Blk_Typ : Entity_Id;
6719 Call_Ent : Entity_Id;
6720 Conc_Typ_Stmts : List_Id;
6724 Lim_Typ_Stmts : List_Id;
6731 Transient_Blk : Node_Id;
6734 B : Entity_Id; -- Call status flag
6735 C : Entity_Id; -- Call kind
6736 K : Entity_Id; -- Tagged kind
6737 P : Entity_Id; -- Parameter block
6738 S : Entity_Id; -- Primitive operation slot
6741 if Ada_Version >= Ada_2005
6742 and then Nkind (Blk) = N_Procedure_Call_Statement
6744 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6749 -- Call status flag processing, generate:
6750 -- B : Boolean := False;
6752 B := Build_B (Loc, Decls);
6754 -- Call kind processing, generate:
6755 -- C : Ada.Tags.Prim_Op_Kind;
6757 C := Build_C (Loc, Decls);
6759 -- Tagged kind processing, generate:
6760 -- K : Ada.Tags.Tagged_Kind :=
6761 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6763 K := Build_K (Loc, Decls, Obj);
6765 -- Parameter block processing
6767 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6768 P := Parameter_Block_Pack
6769 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6771 -- Dispatch table slot processing, generate:
6774 S := Build_S (Loc, Decls);
6777 -- S := Ada.Tags.Get_Offset_Index
6778 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6781 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6784 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6786 Append_To (Conc_Typ_Stmts,
6787 Make_Procedure_Call_Statement (Loc,
6790 Find_Prim_Op (Etype (Etype (Obj)),
6791 Name_uDisp_Conditional_Select),
6793 Parameter_Associations =>
6795 New_Copy_Tree (Obj), -- <object>
6796 New_Reference_To (S, Loc), -- S
6797 Make_Attribute_Reference (Loc, -- P'Address
6799 New_Reference_To (P, Loc),
6802 New_Reference_To (C, Loc), -- C
6803 New_Reference_To (B, Loc)))); -- B
6806 -- if C = POK_Protected_Entry
6807 -- or else C = POK_Task_Entry
6809 -- Param1 := P.Param1;
6811 -- ParamN := P.ParamN;
6814 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6816 -- Generate the if statement only when the packed parameters need
6817 -- explicit assignments to their corresponding actuals.
6819 if Present (Unpack) then
6820 Append_To (Conc_Typ_Stmts,
6821 Make_If_Statement (Loc,
6828 New_Reference_To (C, Loc),
6830 New_Reference_To (RTE (
6831 RE_POK_Protected_Entry), Loc)),
6835 New_Reference_To (C, Loc),
6837 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6845 -- if C = POK_Procedure
6846 -- or else C = POK_Protected_Procedure
6847 -- or else C = POK_Task_Procedure
6849 -- <dispatching-call>
6851 -- <normal-statements>
6853 -- <else-statements>
6856 N_Stats := New_Copy_List_Tree (Statements (Alt));
6858 Prepend_To (N_Stats,
6859 Make_If_Statement (Loc,
6865 New_Reference_To (C, Loc),
6867 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6874 New_Reference_To (C, Loc),
6876 New_Reference_To (RTE (
6877 RE_POK_Protected_Procedure), Loc)),
6882 New_Reference_To (C, Loc),
6884 New_Reference_To (RTE (
6885 RE_POK_Task_Procedure), Loc)))),
6890 Append_To (Conc_Typ_Stmts,
6891 Make_If_Statement (Loc,
6892 Condition => New_Reference_To (B, Loc),
6893 Then_Statements => N_Stats,
6894 Else_Statements => Else_Statements (N)));
6897 -- <dispatching-call>;
6898 -- <triggering-statements>
6900 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6901 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6904 -- if K = Ada.Tags.TK_Limited_Tagged then
6911 Make_If_Statement (Loc,
6915 New_Reference_To (K, Loc),
6917 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6926 Make_Block_Statement (Loc,
6929 Handled_Statement_Sequence =>
6930 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6932 -- As described above, The entry alternative is transformed into a
6933 -- block that contains the gnulli call, and possibly assignment
6934 -- statements for in-out parameters. The gnulli call may itself be
6935 -- rewritten into a transient block if some unconstrained parameters
6936 -- require it. We need to retrieve the call to complete its parameter
6941 First_Real_Statement (Handled_Statement_Sequence (Blk));
6943 if Present (Transient_Blk)
6944 and then Nkind (Transient_Blk) = N_Block_Statement
6946 Blk := Transient_Blk;
6949 Stmts := Statements (Handled_Statement_Sequence (Blk));
6950 Stmt := First (Stmts);
6951 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6956 Params := Parameter_Associations (Call);
6958 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
6960 -- Substitute Conditional_Entry_Call for Simple_Call parameter
6962 Param := First (Params);
6963 while Present (Param)
6964 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6969 pragma Assert (Present (Param));
6970 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
6974 -- Find the Communication_Block parameter for the call to the
6975 -- Cancelled function.
6977 Decl := First (Declarations (Blk));
6978 while Present (Decl)
6979 and then not Is_RTE (Etype (Object_Definition (Decl)),
6980 RE_Communication_Block)
6985 -- Add an if statement to execute the else part if the call
6986 -- does not succeed (as indicated by the Cancelled predicate).
6989 Make_Implicit_If_Statement (N,
6990 Condition => Make_Function_Call (Loc,
6991 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
6992 Parameter_Associations => New_List (
6993 New_Reference_To (Defining_Identifier (Decl), Loc))),
6994 Then_Statements => Else_Statements (N),
6995 Else_Statements => Statements (Alt)));
6998 B := Make_Defining_Identifier (Loc, Name_uB);
7000 -- Insert declaration of B in declarations of existing block
7002 if No (Declarations (Blk)) then
7003 Set_Declarations (Blk, New_List);
7006 Prepend_To (Declarations (Blk),
7007 Make_Object_Declaration (Loc,
7008 Defining_Identifier => B,
7009 Object_Definition =>
7010 New_Reference_To (Standard_Boolean, Loc)));
7012 -- Create new call statement
7015 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7016 Append_To (Params, New_Reference_To (B, Loc));
7019 Make_Procedure_Call_Statement (Loc,
7020 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7021 Parameter_Associations => Params));
7023 -- Construct statement sequence for new block
7026 Make_Implicit_If_Statement (N,
7027 Condition => New_Reference_To (B, Loc),
7028 Then_Statements => Statements (Alt),
7029 Else_Statements => Else_Statements (N)));
7032 -- The result is the new block
7035 Make_Block_Statement (Loc,
7036 Declarations => Declarations (Blk),
7037 Handled_Statement_Sequence =>
7038 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7042 end Expand_N_Conditional_Entry_Call;
7044 ---------------------------------------
7045 -- Expand_N_Delay_Relative_Statement --
7046 ---------------------------------------
7048 -- Delay statement is implemented as a procedure call to Delay_For
7049 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7050 -- simple delays imposed by the use of Protected Objects.
7052 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7053 Loc : constant Source_Ptr := Sloc (N);
7056 Make_Procedure_Call_Statement (Loc,
7057 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7058 Parameter_Associations => New_List (Expression (N))));
7060 end Expand_N_Delay_Relative_Statement;
7062 ------------------------------------
7063 -- Expand_N_Delay_Until_Statement --
7064 ------------------------------------
7066 -- Delay Until statement is implemented as a procedure call to
7067 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7069 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7070 Loc : constant Source_Ptr := Sloc (N);
7074 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7075 Typ := RTE (RO_CA_Delay_Until);
7077 Typ := RTE (RO_RT_Delay_Until);
7081 Make_Procedure_Call_Statement (Loc,
7082 Name => New_Reference_To (Typ, Loc),
7083 Parameter_Associations => New_List (Expression (N))));
7086 end Expand_N_Delay_Until_Statement;
7088 -------------------------
7089 -- Expand_N_Entry_Body --
7090 -------------------------
7092 procedure Expand_N_Entry_Body (N : Node_Id) is
7094 -- Associate discriminals with the next protected operation body to be
7097 if Present (Next_Protected_Operation (N)) then
7098 Set_Discriminals (Parent (Current_Scope));
7100 end Expand_N_Entry_Body;
7102 -----------------------------------
7103 -- Expand_N_Entry_Call_Statement --
7104 -----------------------------------
7106 -- An entry call is expanded into GNARLI calls to implement a simple entry
7107 -- call (see Build_Simple_Entry_Call).
7109 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7115 if No_Run_Time_Mode then
7116 Error_Msg_CRT ("entry call", N);
7120 -- If this entry call is part of an asynchronous select, don't expand it
7121 -- here; it will be expanded with the select statement. Don't expand
7122 -- timed entry calls either, as they are translated into asynchronous
7125 -- ??? This whole approach is questionable; it may be better to go back
7126 -- to allowing the expansion to take place and then attempting to fix it
7127 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7128 -- whether the expanded call is on a task or protected entry.
7130 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7131 or else N /= Triggering_Statement (Parent (N)))
7132 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7133 or else N /= Entry_Call_Statement (Parent (N))
7134 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7136 Extract_Entry (N, Concval, Ename, Index);
7137 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7139 end Expand_N_Entry_Call_Statement;
7141 --------------------------------
7142 -- Expand_N_Entry_Declaration --
7143 --------------------------------
7145 -- If there are parameters, then first, each of the formals is marked by
7146 -- setting Is_Entry_Formal. Next a record type is built which is used to
7147 -- hold the parameter values. The name of this record type is entryP where
7148 -- entry is the name of the entry, with an additional corresponding access
7149 -- type called entryPA. The record type has matching components for each
7150 -- formal (the component names are the same as the formal names). For
7151 -- elementary types, the component type matches the formal type. For
7152 -- composite types, an access type is declared (with the name formalA)
7153 -- which designates the formal type, and the type of the component is this
7154 -- access type. Finally the Entry_Component of each formal is set to
7155 -- reference the corresponding record component.
7157 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7158 Loc : constant Source_Ptr := Sloc (N);
7159 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7160 Components : List_Id;
7163 Last_Decl : Node_Id;
7164 Component : Entity_Id;
7167 Rec_Ent : Entity_Id;
7168 Acc_Ent : Entity_Id;
7171 Formal := First_Formal (Entry_Ent);
7174 -- Most processing is done only if parameters are present
7176 if Present (Formal) then
7177 Components := New_List;
7179 -- Loop through formals
7181 while Present (Formal) loop
7182 Set_Is_Entry_Formal (Formal);
7184 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7185 Set_Entry_Component (Formal, Component);
7186 Set_Entry_Formal (Component, Formal);
7187 Ftype := Etype (Formal);
7189 -- Declare new access type and then append
7191 Ctype := Make_Temporary (Loc, 'A');
7194 Make_Full_Type_Declaration (Loc,
7195 Defining_Identifier => Ctype,
7197 Make_Access_To_Object_Definition (Loc,
7198 All_Present => True,
7199 Constant_Present => Ekind (Formal) = E_In_Parameter,
7200 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7202 Insert_After (Last_Decl, Decl);
7205 Append_To (Components,
7206 Make_Component_Declaration (Loc,
7207 Defining_Identifier => Component,
7208 Component_Definition =>
7209 Make_Component_Definition (Loc,
7210 Aliased_Present => False,
7211 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7213 Next_Formal_With_Extras (Formal);
7216 -- Create the Entry_Parameter_Record declaration
7218 Rec_Ent := Make_Temporary (Loc, 'P');
7221 Make_Full_Type_Declaration (Loc,
7222 Defining_Identifier => Rec_Ent,
7224 Make_Record_Definition (Loc,
7226 Make_Component_List (Loc,
7227 Component_Items => Components)));
7229 Insert_After (Last_Decl, Decl);
7232 -- Construct and link in the corresponding access type
7234 Acc_Ent := Make_Temporary (Loc, 'A');
7236 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7239 Make_Full_Type_Declaration (Loc,
7240 Defining_Identifier => Acc_Ent,
7242 Make_Access_To_Object_Definition (Loc,
7243 All_Present => True,
7244 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7246 Insert_After (Last_Decl, Decl);
7249 end Expand_N_Entry_Declaration;
7251 -----------------------------
7252 -- Expand_N_Protected_Body --
7253 -----------------------------
7255 -- Protected bodies are expanded to the completion of the subprograms
7256 -- created for the corresponding protected type. These are a protected and
7257 -- unprotected version of each protected subprogram in the object, a
7258 -- function to calculate each entry barrier, and a procedure to execute the
7259 -- sequence of statements of each protected entry body. For example, for
7260 -- protected type ptype:
7263 -- (O : System.Address;
7264 -- E : Protected_Entry_Index)
7267 -- <discriminant renamings>
7268 -- <private object renamings>
7270 -- return <barrier expression>;
7273 -- procedure pprocN (_object : in out poV;...) is
7274 -- <discriminant renamings>
7275 -- <private object renamings>
7277 -- <sequence of statements>
7280 -- procedure pprocP (_object : in out poV;...) is
7281 -- procedure _clean is
7284 -- ptypeS (_object, Pn);
7285 -- Unlock (_object._object'Access);
7286 -- Abort_Undefer.all;
7291 -- Lock (_object._object'Access);
7292 -- pprocN (_object;...);
7297 -- function pfuncN (_object : poV;...) return Return_Type is
7298 -- <discriminant renamings>
7299 -- <private object renamings>
7301 -- <sequence of statements>
7304 -- function pfuncP (_object : poV) return Return_Type is
7305 -- procedure _clean is
7307 -- Unlock (_object._object'Access);
7308 -- Abort_Undefer.all;
7313 -- Lock (_object._object'Access);
7314 -- return pfuncN (_object);
7321 -- (O : System.Address;
7322 -- P : System.Address;
7323 -- E : Protected_Entry_Index)
7325 -- <discriminant renamings>
7326 -- <private object renamings>
7327 -- type poVP is access poV;
7328 -- _Object : ptVP := ptVP!(O);
7332 -- <statement sequence>
7333 -- Complete_Entry_Body (_Object._Object);
7335 -- when all others =>
7336 -- Exceptional_Complete_Entry_Body (
7337 -- _Object._Object, Get_GNAT_Exception);
7341 -- The type poV is the record created for the protected type to hold
7342 -- the state of the protected object.
7344 procedure Expand_N_Protected_Body (N : Node_Id) is
7345 Loc : constant Source_Ptr := Sloc (N);
7346 Pid : constant Entity_Id := Corresponding_Spec (N);
7348 Current_Node : Node_Id;
7349 Disp_Op_Body : Node_Id;
7350 New_Op_Body : Node_Id;
7351 Num_Entries : Natural := 0;
7355 Chain : Entity_Id := Empty;
7356 -- Finalization chain that may be attached to new body
7358 function Build_Dispatching_Subprogram_Body
7361 Prot_Bod : Node_Id) return Node_Id;
7362 -- Build a dispatching version of the protected subprogram body. The
7363 -- newly generated subprogram contains a call to the original protected
7364 -- body. The following code is generated:
7366 -- function <protected-function-name> (Param1 .. ParamN) return
7369 -- return <protected-function-name>P (Param1 .. ParamN);
7370 -- end <protected-function-name>;
7374 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7376 -- <protected-procedure-name>P (Param1 .. ParamN);
7377 -- end <protected-procedure-name>
7379 ---------------------------------------
7380 -- Build_Dispatching_Subprogram_Body --
7381 ---------------------------------------
7383 function Build_Dispatching_Subprogram_Body
7386 Prot_Bod : Node_Id) return Node_Id
7388 Loc : constant Source_Ptr := Sloc (N);
7395 -- Generate a specification without a letter suffix in order to
7396 -- override an interface function or procedure.
7399 Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7401 -- The formal parameters become the actuals of the protected
7402 -- function or procedure call.
7404 Actuals := New_List;
7405 Formal := First (Parameter_Specifications (Spec));
7406 while Present (Formal) loop
7408 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7413 if Nkind (Spec) = N_Procedure_Specification then
7416 Make_Procedure_Call_Statement (Loc,
7418 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7419 Parameter_Associations => Actuals));
7421 pragma Assert (Nkind (Spec) = N_Function_Specification);
7425 Make_Simple_Return_Statement (Loc,
7427 Make_Function_Call (Loc,
7429 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7430 Parameter_Associations => Actuals)));
7434 Make_Subprogram_Body (Loc,
7435 Declarations => Empty_List,
7436 Specification => Spec,
7437 Handled_Statement_Sequence =>
7438 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7439 end Build_Dispatching_Subprogram_Body;
7441 -- Start of processing for Expand_N_Protected_Body
7444 if No_Run_Time_Mode then
7445 Error_Msg_CRT ("protected body", N);
7449 -- This is the proper body corresponding to a stub. The declarations
7450 -- must be inserted at the point of the stub, which in turn is in the
7451 -- declarative part of the parent unit.
7453 if Nkind (Parent (N)) = N_Subunit then
7454 Current_Node := Corresponding_Stub (Parent (N));
7459 Op_Body := First (Declarations (N));
7461 -- The protected body is replaced with the bodies of its
7462 -- protected operations, and the declarations for internal objects
7463 -- that may have been created for entry family bounds.
7465 Rewrite (N, Make_Null_Statement (Sloc (N)));
7468 while Present (Op_Body) loop
7469 case Nkind (Op_Body) is
7470 when N_Subprogram_Declaration =>
7473 when N_Subprogram_Body =>
7475 -- Do not create bodies for eliminated operations
7477 if not Is_Eliminated (Defining_Entity (Op_Body))
7478 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7481 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7483 -- Propagate the finalization chain to the new body. In the
7484 -- unlikely event that the subprogram contains a declaration
7485 -- or allocator for an object that requires finalization,
7486 -- the corresponding chain is created when analyzing the
7487 -- body, and attached to its entity. This entity is not
7488 -- further elaborated, and so the chain properly belongs to
7489 -- the newly created subprogram body.
7492 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7494 if Present (Chain) then
7495 Set_Finalization_Chain_Entity
7496 (Protected_Body_Subprogram
7497 (Corresponding_Spec (Op_Body)), Chain);
7499 (Handled_Statement_Sequence (New_Op_Body), False);
7502 Insert_After (Current_Node, New_Op_Body);
7503 Current_Node := New_Op_Body;
7504 Analyze (New_Op_Body);
7506 -- Build the corresponding protected operation. It may
7507 -- appear that this is needed only if this is a visible
7508 -- operation of the type, or if it is an interrupt handler,
7509 -- and this was the strategy used previously in GNAT.
7510 -- However, the operation may be exported through a 'Access
7511 -- to an external caller. This is the common idiom in code
7512 -- that uses the Ada 2005 Timing_Events package. As a result
7513 -- we need to produce the protected body for both visible
7514 -- and private operations, as well as operations that only
7515 -- have a body in the source, and for which we create a
7516 -- declaration in the protected body itself.
7518 if Present (Corresponding_Spec (Op_Body)) then
7520 Build_Protected_Subprogram_Body (
7521 Op_Body, Pid, Specification (New_Op_Body));
7523 Insert_After (Current_Node, New_Op_Body);
7524 Analyze (New_Op_Body);
7526 Current_Node := New_Op_Body;
7528 -- Generate an overriding primitive operation body for
7529 -- this subprogram if the protected type implements an
7532 if Ada_Version >= Ada_2005
7534 Present (Interfaces (Corresponding_Record_Type (Pid)))
7537 Build_Dispatching_Subprogram_Body
7538 (Op_Body, Pid, New_Op_Body);
7540 Insert_After (Current_Node, Disp_Op_Body);
7541 Analyze (Disp_Op_Body);
7543 Current_Node := Disp_Op_Body;
7548 when N_Entry_Body =>
7549 Op_Id := Defining_Identifier (Op_Body);
7550 Num_Entries := Num_Entries + 1;
7552 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7554 Insert_After (Current_Node, New_Op_Body);
7555 Current_Node := New_Op_Body;
7556 Analyze (New_Op_Body);
7558 when N_Implicit_Label_Declaration =>
7561 when N_Itype_Reference =>
7562 Insert_After (Current_Node, New_Copy (Op_Body));
7564 when N_Freeze_Entity =>
7565 New_Op_Body := New_Copy (Op_Body);
7567 if Present (Entity (Op_Body))
7568 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7570 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7573 Insert_After (Current_Node, New_Op_Body);
7574 Current_Node := New_Op_Body;
7575 Analyze (New_Op_Body);
7578 New_Op_Body := New_Copy (Op_Body);
7579 Insert_After (Current_Node, New_Op_Body);
7580 Current_Node := New_Op_Body;
7581 Analyze (New_Op_Body);
7583 when N_Object_Declaration =>
7584 pragma Assert (not Comes_From_Source (Op_Body));
7585 New_Op_Body := New_Copy (Op_Body);
7586 Insert_After (Current_Node, New_Op_Body);
7587 Current_Node := New_Op_Body;
7588 Analyze (New_Op_Body);
7591 raise Program_Error;
7598 -- Finally, create the body of the function that maps an entry index
7599 -- into the corresponding body index, except when there is no entry, or
7600 -- in a Ravenscar-like profile.
7602 if Corresponding_Runtime_Package (Pid) =
7603 System_Tasking_Protected_Objects_Entries
7605 New_Op_Body := Build_Find_Body_Index (Pid);
7606 Insert_After (Current_Node, New_Op_Body);
7607 Current_Node := New_Op_Body;
7608 Analyze (New_Op_Body);
7611 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7612 -- protected body. At this point all wrapper specs have been created,
7613 -- frozen and included in the dispatch table for the protected type.
7615 if Ada_Version >= Ada_2005 then
7616 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7618 end Expand_N_Protected_Body;
7620 -----------------------------------------
7621 -- Expand_N_Protected_Type_Declaration --
7622 -----------------------------------------
7624 -- First we create a corresponding record type declaration used to
7625 -- represent values of this protected type.
7626 -- The general form of this type declaration is
7628 -- type poV (discriminants) is record
7629 -- _Object : aliased <kind>Protection
7630 -- [(<entry count> [, <handler count>])];
7631 -- [entry_family : array (bounds) of Void;]
7632 -- <private data fields>
7635 -- The discriminants are present only if the corresponding protected type
7636 -- has discriminants, and they exactly mirror the protected type
7637 -- discriminants. The private data fields similarly mirror the private
7638 -- declarations of the protected type.
7640 -- The Object field is always present. It contains RTS specific data used
7641 -- to control the protected object. It is declared as Aliased so that it
7642 -- can be passed as a pointer to the RTS. This allows the protected record
7643 -- to be referenced within RTS data structures. An appropriate Protection
7644 -- type and discriminant are generated.
7646 -- The Service field is present for protected objects with entries. It
7647 -- contains sufficient information to allow the entry service procedure for
7648 -- this object to be called when the object is not known till runtime.
7650 -- One entry_family component is present for each entry family in the
7651 -- task definition (see Expand_N_Task_Type_Declaration).
7653 -- When a protected object is declared, an instance of the protected type
7654 -- value record is created. The elaboration of this declaration creates the
7655 -- correct bounds for the entry families, and also evaluates the priority
7656 -- expression if needed. The initialization routine for the protected type
7657 -- itself then calls Initialize_Protection with appropriate parameters to
7658 -- initialize the value of the Task_Id field. Install_Handlers may be also
7659 -- called if a pragma Attach_Handler applies.
7661 -- Note: this record is passed to the subprograms created by the expansion
7662 -- of protected subprograms and entries. It is an in parameter to protected
7663 -- functions and an in out parameter to procedures and entry bodies. The
7664 -- Entity_Id for this created record type is placed in the
7665 -- Corresponding_Record_Type field of the associated protected type entity.
7667 -- Next we create a procedure specifications for protected subprograms and
7668 -- entry bodies. For each protected subprograms two subprograms are
7669 -- created, an unprotected and a protected version. The unprotected version
7670 -- is called from within other operations of the same protected object.
7672 -- We also build the call to register the procedure if a pragma
7673 -- Interrupt_Handler applies.
7675 -- A single subprogram is created to service all entry bodies; it has an
7676 -- additional boolean out parameter indicating that the previous entry call
7677 -- made by the current task was serviced immediately, i.e. not by proxy.
7678 -- The O parameter contains a pointer to a record object of the type
7679 -- described above. An untyped interface is used here to allow this
7680 -- procedure to be called in places where the type of the object to be
7681 -- serviced is not known. This must be done, for example, when a call that
7682 -- may have been requeued is cancelled; the corresponding object must be
7683 -- serviced, but which object that is not known till runtime.
7686 -- (O : System.Address; P : out Boolean);
7687 -- procedure pprocN (_object : in out poV);
7688 -- procedure pproc (_object : in out poV);
7689 -- function pfuncN (_object : poV);
7690 -- function pfunc (_object : poV);
7693 -- Note that this must come after the record type declaration, since
7694 -- the specs refer to this type.
7696 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7697 Loc : constant Source_Ptr := Sloc (N);
7698 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7700 Pdef : constant Node_Id := Protected_Definition (N);
7701 -- This contains two lists; one for visible and one for private decls
7705 Discr_Map : constant Elist_Id := New_Elmt_List;
7709 Comp_Id : Entity_Id;
7711 Current_Node : Node_Id := N;
7712 Bdef : Entity_Id := Empty; -- avoid uninit warning
7713 Edef : Entity_Id := Empty; -- avoid uninit warning
7714 Entries_Aggr : Node_Id;
7715 Body_Id : Entity_Id;
7718 Object_Comp : Node_Id;
7720 procedure Check_Inlining (Subp : Entity_Id);
7721 -- If the original operation has a pragma Inline, propagate the flag
7722 -- to the internal body, for possible inlining later on. The source
7723 -- operation is invisible to the back-end and is never actually called.
7725 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7726 -- When compiling under the Ravenscar profile, private components must
7727 -- have a static size, or else a protected object will require heap
7728 -- allocation, violating the corresponding restriction. It is preferable
7729 -- to make this check here, because it provides a better error message
7730 -- than the back-end, which refers to the object as a whole.
7732 procedure Register_Handler;
7733 -- For a protected operation that is an interrupt handler, add the
7734 -- freeze action that will register it as such.
7736 --------------------
7737 -- Check_Inlining --
7738 --------------------
7740 procedure Check_Inlining (Subp : Entity_Id) is
7742 if Is_Inlined (Subp) then
7743 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7744 Set_Is_Inlined (Subp, False);
7748 ---------------------------------
7749 -- Check_Static_Component_Size --
7750 ---------------------------------
7752 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7753 Typ : constant Entity_Id := Etype (Comp);
7757 if Is_Scalar_Type (Typ) then
7760 elsif Is_Array_Type (Typ) then
7761 return Compile_Time_Known_Bounds (Typ);
7763 elsif Is_Record_Type (Typ) then
7764 C := First_Component (Typ);
7765 while Present (C) loop
7766 if not Static_Component_Size (C) then
7775 -- Any other types will be checked by the back-end
7780 end Static_Component_Size;
7782 ----------------------
7783 -- Register_Handler --
7784 ----------------------
7786 procedure Register_Handler is
7788 -- All semantic checks already done in Sem_Prag
7790 Prot_Proc : constant Entity_Id :=
7792 (Specification (Current_Node));
7794 Proc_Address : constant Node_Id :=
7795 Make_Attribute_Reference (Loc,
7796 Prefix => New_Reference_To (Prot_Proc, Loc),
7797 Attribute_Name => Name_Address);
7799 RTS_Call : constant Entity_Id :=
7800 Make_Procedure_Call_Statement (Loc,
7803 RTE (RE_Register_Interrupt_Handler), Loc),
7804 Parameter_Associations =>
7805 New_List (Proc_Address));
7807 Append_Freeze_Action (Prot_Proc, RTS_Call);
7808 end Register_Handler;
7810 -- Start of processing for Expand_N_Protected_Type_Declaration
7813 if Present (Corresponding_Record_Type (Prot_Typ)) then
7816 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7819 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7821 Qualify_Entity_Names (N);
7823 -- If the type has discriminants, their occurrences in the declaration
7824 -- have been replaced by the corresponding discriminals. For components
7825 -- that are constrained by discriminants, their homologues in the
7826 -- corresponding record type must refer to the discriminants of that
7827 -- record, so we must apply a new renaming to subtypes_indications:
7829 -- protected discriminant => discriminal => record discriminant
7831 -- This replacement is not applied to default expressions, for which
7832 -- the discriminal is correct.
7834 if Has_Discriminants (Prot_Typ) then
7840 Disc := First_Discriminant (Prot_Typ);
7841 Decl := First (Discriminant_Specifications (Rec_Decl));
7842 while Present (Disc) loop
7843 Append_Elmt (Discriminal (Disc), Discr_Map);
7844 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7845 Next_Discriminant (Disc);
7851 -- Fill in the component declarations
7853 -- Add components for entry families. For each entry family, create an
7854 -- anonymous type declaration with the same size, and analyze the type.
7856 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7858 -- Prepend the _Object field with the right type to the component list.
7859 -- We need to compute the number of entries, and in some cases the
7860 -- number of Attach_Handler pragmas.
7864 Num_Attach_Handler : Int := 0;
7865 Protection_Subtype : Node_Id;
7866 Entry_Count_Expr : constant Node_Id :=
7867 Build_Entry_Count_Expression
7868 (Prot_Typ, Cdecls, Loc);
7871 -- Could this be simplified using Corresponding_Runtime_Package???
7873 if Has_Attach_Handler (Prot_Typ) then
7874 Ritem := First_Rep_Item (Prot_Typ);
7875 while Present (Ritem) loop
7876 if Nkind (Ritem) = N_Pragma
7877 and then Pragma_Name (Ritem) = Name_Attach_Handler
7879 Num_Attach_Handler := Num_Attach_Handler + 1;
7882 Next_Rep_Item (Ritem);
7885 if Restricted_Profile then
7886 if Has_Entries (Prot_Typ) then
7887 Protection_Subtype :=
7888 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7890 Protection_Subtype :=
7891 New_Reference_To (RTE (RE_Protection), Loc);
7894 Protection_Subtype :=
7895 Make_Subtype_Indication
7899 (RTE (RE_Static_Interrupt_Protection), Loc),
7901 Make_Index_Or_Discriminant_Constraint (
7903 Constraints => New_List (
7905 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7908 elsif Has_Interrupt_Handler (Prot_Typ) then
7909 Protection_Subtype :=
7910 Make_Subtype_Indication (
7912 Subtype_Mark => New_Reference_To
7913 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7915 Make_Index_Or_Discriminant_Constraint (
7917 Constraints => New_List (Entry_Count_Expr)));
7919 -- Type has explicit entries or generated primitive entry wrappers
7921 elsif Has_Entries (Prot_Typ)
7922 or else (Ada_Version >= Ada_2005
7923 and then Present (Interface_List (N)))
7925 case Corresponding_Runtime_Package (Prot_Typ) is
7926 when System_Tasking_Protected_Objects_Entries =>
7927 Protection_Subtype :=
7928 Make_Subtype_Indication (Loc,
7930 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7932 Make_Index_Or_Discriminant_Constraint (
7934 Constraints => New_List (Entry_Count_Expr)));
7936 when System_Tasking_Protected_Objects_Single_Entry =>
7937 Protection_Subtype :=
7938 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7941 raise Program_Error;
7945 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
7949 Make_Component_Declaration (Loc,
7950 Defining_Identifier =>
7951 Make_Defining_Identifier (Loc, Name_uObject),
7952 Component_Definition =>
7953 Make_Component_Definition (Loc,
7954 Aliased_Present => True,
7955 Subtype_Indication => Protection_Subtype));
7958 pragma Assert (Present (Pdef));
7960 -- Add private field components
7962 if Present (Private_Declarations (Pdef)) then
7963 Priv := First (Private_Declarations (Pdef));
7965 while Present (Priv) loop
7967 if Nkind (Priv) = N_Component_Declaration then
7968 if not Static_Component_Size (Defining_Identifier (Priv)) then
7970 -- When compiling for a restricted profile, the private
7971 -- components must have a static size. If not, this is an
7972 -- error for a single protected declaration, and rates a
7973 -- warning on a protected type declaration.
7975 if not Comes_From_Source (Prot_Typ) then
7976 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
7978 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
7979 Error_Msg_N ("component has non-static size?", Priv);
7981 ("\creation of protected object of type& will violate"
7982 & " restriction No_Implicit_Heap_Allocations?",
7987 -- The component definition consists of a subtype indication,
7988 -- or (in Ada 2005) an access definition. Make a copy of the
7989 -- proper definition.
7992 Old_Comp : constant Node_Id := Component_Definition (Priv);
7993 Oent : constant Entity_Id := Defining_Identifier (Priv);
7995 Nent : constant Entity_Id :=
7996 Make_Defining_Identifier (Sloc (Oent),
7997 Chars => Chars (Oent));
8000 if Present (Subtype_Indication (Old_Comp)) then
8002 Make_Component_Definition (Sloc (Oent),
8003 Aliased_Present => False,
8004 Subtype_Indication =>
8005 New_Copy_Tree (Subtype_Indication (Old_Comp),
8009 Make_Component_Definition (Sloc (Oent),
8010 Aliased_Present => False,
8011 Access_Definition =>
8012 New_Copy_Tree (Access_Definition (Old_Comp),
8017 Make_Component_Declaration (Loc,
8018 Defining_Identifier => Nent,
8019 Component_Definition => New_Comp,
8020 Expression => Expression (Priv));
8022 Set_Has_Per_Object_Constraint (Nent,
8023 Has_Per_Object_Constraint (Oent));
8025 Append_To (Cdecls, New_Priv);
8028 elsif Nkind (Priv) = N_Subprogram_Declaration then
8030 -- Make the unprotected version of the subprogram available
8031 -- for expansion of intra object calls. There is need for
8032 -- a protected version only if the subprogram is an interrupt
8033 -- handler, otherwise this operation can only be called from
8037 Make_Subprogram_Declaration (Loc,
8039 Build_Protected_Sub_Specification
8040 (Priv, Prot_Typ, Unprotected_Mode));
8042 Insert_After (Current_Node, Sub);
8045 Set_Protected_Body_Subprogram
8046 (Defining_Unit_Name (Specification (Priv)),
8047 Defining_Unit_Name (Specification (Sub)));
8048 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8049 Current_Node := Sub;
8052 Make_Subprogram_Declaration (Loc,
8054 Build_Protected_Sub_Specification
8055 (Priv, Prot_Typ, Protected_Mode));
8057 Insert_After (Current_Node, Sub);
8059 Current_Node := Sub;
8061 if Is_Interrupt_Handler
8062 (Defining_Unit_Name (Specification (Priv)))
8064 if not Restricted_Profile then
8074 -- Put the _Object component after the private component so that it
8075 -- be finalized early as required by 9.4 (20)
8077 Append_To (Cdecls, Object_Comp);
8079 Insert_After (Current_Node, Rec_Decl);
8080 Current_Node := Rec_Decl;
8082 -- Analyze the record declaration immediately after construction,
8083 -- because the initialization procedure is needed for single object
8084 -- declarations before the next entity is analyzed (the freeze call
8085 -- that generates this initialization procedure is found below).
8087 Analyze (Rec_Decl, Suppress => All_Checks);
8089 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8090 -- the corresponding record is frozen. If any wrappers are generated,
8091 -- Current_Node is updated accordingly.
8093 if Ada_Version >= Ada_2005 then
8094 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8097 -- Collect pointers to entry bodies and their barriers, to be placed
8098 -- in the Entry_Bodies_Array for the type. For each entry/family we
8099 -- add an expression to the aggregate which is the initial value of
8100 -- this array. The array is declared after all protected subprograms.
8102 if Has_Entries (Prot_Typ) then
8103 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8105 Entries_Aggr := Empty;
8108 -- Build two new procedure specifications for each protected subprogram;
8109 -- one to call from outside the object and one to call from inside.
8110 -- Build a barrier function and an entry body action procedure
8111 -- specification for each protected entry. Initialize the entry body
8112 -- array. If subprogram is flagged as eliminated, do not generate any
8113 -- internal operations.
8117 Comp := First (Visible_Declarations (Pdef));
8119 while Present (Comp) loop
8120 if Nkind (Comp) = N_Subprogram_Declaration then
8122 Make_Subprogram_Declaration (Loc,
8124 Build_Protected_Sub_Specification
8125 (Comp, Prot_Typ, Unprotected_Mode));
8127 Insert_After (Current_Node, Sub);
8130 Set_Protected_Body_Subprogram
8131 (Defining_Unit_Name (Specification (Comp)),
8132 Defining_Unit_Name (Specification (Sub)));
8133 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8135 -- Make the protected version of the subprogram available for
8136 -- expansion of external calls.
8138 Current_Node := Sub;
8141 Make_Subprogram_Declaration (Loc,
8143 Build_Protected_Sub_Specification
8144 (Comp, Prot_Typ, Protected_Mode));
8146 Insert_After (Current_Node, Sub);
8149 Current_Node := Sub;
8151 -- Generate an overriding primitive operation specification for
8152 -- this subprogram if the protected type implements an interface.
8154 if Ada_Version >= Ada_2005
8156 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8159 Make_Subprogram_Declaration (Loc,
8161 Build_Protected_Sub_Specification
8162 (Comp, Prot_Typ, Dispatching_Mode));
8164 Insert_After (Current_Node, Sub);
8167 Current_Node := Sub;
8170 -- If a pragma Interrupt_Handler applies, build and add a call to
8171 -- Register_Interrupt_Handler to the freezing actions of the
8172 -- protected version (Current_Node) of the subprogram:
8174 -- system.interrupts.register_interrupt_handler
8175 -- (prot_procP'address);
8177 if not Restricted_Profile
8178 and then Is_Interrupt_Handler
8179 (Defining_Unit_Name (Specification (Comp)))
8184 elsif Nkind (Comp) = N_Entry_Declaration then
8185 E_Count := E_Count + 1;
8186 Comp_Id := Defining_Identifier (Comp);
8189 Make_Defining_Identifier (Loc,
8190 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8192 Make_Subprogram_Declaration (Loc,
8194 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8196 Insert_After (Current_Node, Sub);
8199 -- build wrapper procedure for pre/postconditions.
8201 Build_PPC_Wrapper (Comp_Id, N);
8203 Set_Protected_Body_Subprogram
8204 (Defining_Identifier (Comp),
8205 Defining_Unit_Name (Specification (Sub)));
8207 Current_Node := Sub;
8210 Make_Defining_Identifier (Loc,
8211 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8213 Make_Subprogram_Declaration (Loc,
8215 Build_Barrier_Function_Specification (Loc, Bdef));
8217 Insert_After (Current_Node, Sub);
8219 Set_Protected_Body_Subprogram (Bdef, Bdef);
8220 Set_Barrier_Function (Comp_Id, Bdef);
8221 Set_Scope (Bdef, Scope (Comp_Id));
8222 Current_Node := Sub;
8224 -- Collect pointers to the protected subprogram and the barrier
8225 -- of the current entry, for insertion into Entry_Bodies_Array.
8228 Make_Aggregate (Loc,
8229 Expressions => New_List (
8230 Make_Attribute_Reference (Loc,
8231 Prefix => New_Reference_To (Bdef, Loc),
8232 Attribute_Name => Name_Unrestricted_Access),
8233 Make_Attribute_Reference (Loc,
8234 Prefix => New_Reference_To (Edef, Loc),
8235 Attribute_Name => Name_Unrestricted_Access))),
8236 Expressions (Entries_Aggr));
8243 -- If there are some private entry declarations, expand it as if they
8244 -- were visible entries.
8246 if Present (Private_Declarations (Pdef)) then
8247 Comp := First (Private_Declarations (Pdef));
8248 while Present (Comp) loop
8249 if Nkind (Comp) = N_Entry_Declaration then
8250 E_Count := E_Count + 1;
8251 Comp_Id := Defining_Identifier (Comp);
8254 Make_Defining_Identifier (Loc,
8255 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8257 Make_Subprogram_Declaration (Loc,
8259 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8261 Insert_After (Current_Node, Sub);
8264 Set_Protected_Body_Subprogram
8265 (Defining_Identifier (Comp),
8266 Defining_Unit_Name (Specification (Sub)));
8268 Current_Node := Sub;
8271 Make_Defining_Identifier (Loc,
8272 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8275 Make_Subprogram_Declaration (Loc,
8277 Build_Barrier_Function_Specification (Loc, Bdef));
8279 Insert_After (Current_Node, Sub);
8281 Set_Protected_Body_Subprogram (Bdef, Bdef);
8282 Set_Barrier_Function (Comp_Id, Bdef);
8283 Set_Scope (Bdef, Scope (Comp_Id));
8284 Current_Node := Sub;
8286 -- Collect pointers to the protected subprogram and the barrier
8287 -- of the current entry, for insertion into Entry_Bodies_Array.
8289 Append_To (Expressions (Entries_Aggr),
8290 Make_Aggregate (Loc,
8291 Expressions => New_List (
8292 Make_Attribute_Reference (Loc,
8293 Prefix => New_Reference_To (Bdef, Loc),
8294 Attribute_Name => Name_Unrestricted_Access),
8295 Make_Attribute_Reference (Loc,
8296 Prefix => New_Reference_To (Edef, Loc),
8297 Attribute_Name => Name_Unrestricted_Access))));
8304 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8305 -- all protected subprograms have been collected.
8307 if Has_Entries (Prot_Typ) then
8309 Make_Defining_Identifier (Sloc (Prot_Typ),
8310 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8312 case Corresponding_Runtime_Package (Prot_Typ) is
8313 when System_Tasking_Protected_Objects_Entries =>
8314 Body_Arr := Make_Object_Declaration (Loc,
8315 Defining_Identifier => Body_Id,
8316 Aliased_Present => True,
8317 Object_Definition =>
8318 Make_Subtype_Indication (Loc,
8319 Subtype_Mark => New_Reference_To (
8320 RTE (RE_Protected_Entry_Body_Array), Loc),
8322 Make_Index_Or_Discriminant_Constraint (Loc,
8323 Constraints => New_List (
8325 Make_Integer_Literal (Loc, 1),
8326 Make_Integer_Literal (Loc, E_Count))))),
8327 Expression => Entries_Aggr);
8329 when System_Tasking_Protected_Objects_Single_Entry =>
8330 Body_Arr := Make_Object_Declaration (Loc,
8331 Defining_Identifier => Body_Id,
8332 Aliased_Present => True,
8333 Object_Definition => New_Reference_To
8334 (RTE (RE_Entry_Body), Loc),
8336 Make_Aggregate (Loc,
8337 Expressions => New_List (
8338 Make_Attribute_Reference (Loc,
8339 Prefix => New_Reference_To (Bdef, Loc),
8340 Attribute_Name => Name_Unrestricted_Access),
8341 Make_Attribute_Reference (Loc,
8342 Prefix => New_Reference_To (Edef, Loc),
8343 Attribute_Name => Name_Unrestricted_Access))));
8346 raise Program_Error;
8349 -- A pointer to this array will be placed in the corresponding record
8350 -- by its initialization procedure so this needs to be analyzed here.
8352 Insert_After (Current_Node, Body_Arr);
8353 Current_Node := Body_Arr;
8356 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8358 -- Finally, build the function that maps an entry index into the
8359 -- corresponding body. A pointer to this function is placed in each
8360 -- object of the type. Except for a ravenscar-like profile (no abort,
8361 -- no entry queue, 1 entry)
8363 if Corresponding_Runtime_Package (Prot_Typ) =
8364 System_Tasking_Protected_Objects_Entries
8367 Make_Subprogram_Declaration (Loc,
8368 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8369 Insert_After (Current_Node, Sub);
8373 end Expand_N_Protected_Type_Declaration;
8375 --------------------------------
8376 -- Expand_N_Requeue_Statement --
8377 --------------------------------
8379 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8380 -- operations, depending on the source and destination (task or protected
8381 -- object). A dispatching requeue statement is expanded into a call to the
8382 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8383 -- jump around the remainder of processing for the original entry and, if
8384 -- the destination is (different) protected object, to attempt to service
8385 -- it. The following illustrates the various cases:
8388 -- (O : System.Address;
8389 -- P : System.Address;
8390 -- E : Protected_Entry_Index)
8392 -- <discriminant renamings>
8393 -- <private object renamings>
8394 -- type poVP is access poV;
8395 -- _object : ptVP := ptVP!(O);
8399 -- <start of statement sequence for entry>
8401 -- -- Requeue from one protected entry body to another protected
8404 -- Requeue_Protected_Entry (
8405 -- _object._object'Access,
8406 -- new._object'Access,
8411 -- <some more of the statement sequence for entry>
8413 -- -- Requeue from an entry body to a task entry
8415 -- Requeue_Protected_To_Task_Entry (
8421 -- <rest of statement sequence for entry>
8422 -- Complete_Entry_Body (_object._object);
8425 -- when all others =>
8426 -- Exceptional_Complete_Entry_Body (
8427 -- _object._object, Get_GNAT_Exception);
8431 -- Requeue of a task entry call to a task entry
8433 -- Accept_Call (E, Ann);
8434 -- <start of statement sequence for accept statement>
8435 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8437 -- <rest of statement sequence for accept statement>
8439 -- Complete_Rendezvous;
8442 -- when all others =>
8443 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8445 -- Requeue of a task entry call to a protected entry
8447 -- Accept_Call (E, Ann);
8448 -- <start of statement sequence for accept statement>
8449 -- Requeue_Task_To_Protected_Entry (
8450 -- new._object'Access,
8455 -- <rest of statement sequence for accept statement>
8457 -- Complete_Rendezvous;
8460 -- when all others =>
8461 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8463 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8464 -- marked by pragma Implemented (XXX, By_Entry).
8466 -- The requeue is inside a protected entry:
8469 -- (O : System.Address;
8470 -- P : System.Address;
8471 -- E : Protected_Entry_Index)
8473 -- <discriminant renamings>
8474 -- <private object renamings>
8475 -- type poVP is access poV;
8476 -- _object : ptVP := ptVP!(O);
8480 -- <start of statement sequence for entry>
8483 -- (<interface class-wide object>,
8486 -- Ada.Tags.Get_Offset_Index
8488 -- <interface dispatch table index of target entry>),
8492 -- <rest of statement sequence for entry>
8493 -- Complete_Entry_Body (_object._object);
8496 -- when all others =>
8497 -- Exceptional_Complete_Entry_Body (
8498 -- _object._object, Get_GNAT_Exception);
8502 -- The requeue is inside a task entry:
8504 -- Accept_Call (E, Ann);
8505 -- <start of statement sequence for accept statement>
8507 -- (<interface class-wide object>,
8510 -- Ada.Tags.Get_Offset_Index
8512 -- <interface dispatch table index of target entrt>),
8516 -- <rest of statement sequence for accept statement>
8518 -- Complete_Rendezvous;
8521 -- when all others =>
8522 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8524 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8525 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8526 -- statement is replaced by a dispatching call with actual parameters taken
8527 -- from the inner-most accept statement or entry body.
8529 -- Target.Primitive (Param1, ..., ParamN);
8531 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8532 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8535 -- S : constant Offset_Index :=
8536 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8537 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8540 -- if C = POK_Protected_Entry
8541 -- or else C = POK_Task_Entry
8543 -- <statements for dispatching requeue>
8545 -- elsif C = POK_Protected_Procedure then
8546 -- <dispatching call equivalent>
8549 -- raise Program_Error;
8553 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8554 Loc : constant Source_Ptr := Sloc (N);
8555 Conc_Typ : Entity_Id;
8559 Old_Typ : Entity_Id;
8561 function Build_Dispatching_Call_Equivalent return Node_Id;
8562 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8563 -- the form Concval.Ename. It is statically known that Ename is allowed
8564 -- to be implemented by a protected procedure. Create a dispatching call
8565 -- equivalent of Concval.Ename taking the actual parameters from the
8566 -- inner-most accept statement or entry body.
8568 function Build_Dispatching_Requeue return Node_Id;
8569 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8570 -- the form Concval.Ename. It is statically known that Ename is allowed
8571 -- to be implemented by a protected or a task entry. Create a call to
8572 -- primitive _Disp_Requeue which handles the low-level actions.
8574 function Build_Dispatching_Requeue_To_Any return Node_Id;
8575 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8576 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8577 -- (XXX, By_Any) or not marked at all. Create a block which determines
8578 -- at runtime whether Ename denotes an entry or a procedure and perform
8579 -- the appropriate kind of dispatching select.
8581 function Build_Normal_Requeue return Node_Id;
8582 -- N denotes a non-dispatching requeue statement to either a task or a
8583 -- protected entry. Build the appropriate runtime call to perform the
8586 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8587 -- For a protected entry, create a return statement to skip the rest of
8588 -- the entry body. Otherwise, create a goto statement to skip the rest
8589 -- of a task accept statement. The lookup for the enclosing entry body
8590 -- or accept statement starts from Search.
8592 ---------------------------------------
8593 -- Build_Dispatching_Call_Equivalent --
8594 ---------------------------------------
8596 function Build_Dispatching_Call_Equivalent return Node_Id is
8597 Call_Ent : constant Entity_Id := Entity (Ename);
8598 Obj : constant Node_Id := Original_Node (Concval);
8605 -- Climb the parent chain looking for the inner-most entry body or
8606 -- accept statement.
8609 while Present (Acc_Ent)
8610 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8613 Acc_Ent := Parent (Acc_Ent);
8616 -- A requeue statement should be housed inside an entry body or an
8617 -- accept statement at some level. If this is not the case, then the
8618 -- tree is malformed.
8620 pragma Assert (Present (Acc_Ent));
8622 -- Recover the list of formal parameters
8624 if Nkind (Acc_Ent) = N_Entry_Body then
8625 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8628 Formals := Parameter_Specifications (Acc_Ent);
8630 -- Create the actual parameters for the dispatching call. These are
8631 -- simply copies of the entry body or accept statement formals in the
8632 -- same order as they appear.
8636 if Present (Formals) then
8637 Actuals := New_List;
8638 Formal := First (Formals);
8639 while Present (Formal) loop
8641 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8647 -- Obj.Call_Ent (Actuals);
8650 Make_Procedure_Call_Statement (Loc,
8652 Make_Selected_Component (Loc,
8654 Make_Identifier (Loc, Chars (Obj)),
8656 Make_Identifier (Loc, Chars (Call_Ent))),
8658 Parameter_Associations => Actuals);
8659 end Build_Dispatching_Call_Equivalent;
8661 -------------------------------
8662 -- Build_Dispatching_Requeue --
8663 -------------------------------
8665 function Build_Dispatching_Requeue return Node_Id is
8666 Params : constant List_Id := New_List;
8669 -- Process the "with abort" parameter
8672 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8674 -- Process the entry wrapper's position in the primary dispatch
8675 -- table parameter. Generate:
8677 -- Ada.Tags.Get_Offset_Index
8678 -- (Ada.Tags.Tag (Concval),
8679 -- <interface dispatch table position of Ename>)
8682 Make_Function_Call (Loc,
8684 New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8686 Parameter_Associations => New_List (
8687 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8688 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8690 -- Specific actuals for protected to XXX requeue
8692 if Is_Protected_Type (Old_Typ) then
8694 Make_Attribute_Reference (Loc, -- _object'Address
8696 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8697 Attribute_Name => Name_Address));
8699 Prepend_To (Params, -- True
8700 New_Reference_To (Standard_True, Loc));
8702 -- Specific actuals for task to XXX requeue
8705 pragma Assert (Is_Task_Type (Old_Typ));
8707 Prepend_To (Params, -- null
8708 New_Reference_To (RTE (RE_Null_Address), Loc));
8710 Prepend_To (Params, -- False
8711 New_Reference_To (Standard_False, Loc));
8714 -- Add the object parameter
8716 Prepend_To (Params, New_Copy_Tree (Concval));
8719 -- _Disp_Requeue (<Params>);
8722 Make_Procedure_Call_Statement (Loc,
8724 Make_Identifier (Loc, Name_uDisp_Requeue),
8725 Parameter_Associations => Params);
8726 end Build_Dispatching_Requeue;
8728 --------------------------------------
8729 -- Build_Dispatching_Requeue_To_Any --
8730 --------------------------------------
8732 function Build_Dispatching_Requeue_To_Any return Node_Id is
8733 Call_Ent : constant Entity_Id := Entity (Ename);
8734 Obj : constant Node_Id := Original_Node (Concval);
8735 Skip : constant Node_Id := Build_Skip_Statement (N);
8745 -- Dispatch table slot processing, generate:
8748 S := Build_S (Loc, Decls);
8750 -- Call kind processing, generate:
8751 -- C : Ada.Tags.Prim_Op_Kind;
8753 C := Build_C (Loc, Decls);
8756 -- S := Ada.Tags.Get_Offset_Index
8757 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
8759 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
8762 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
8765 Make_Procedure_Call_Statement (Loc,
8768 Find_Prim_Op (Etype (Etype (Obj)),
8769 Name_uDisp_Get_Prim_Op_Kind),
8771 Parameter_Associations => New_List (
8772 New_Copy_Tree (Obj),
8773 New_Reference_To (S, Loc),
8774 New_Reference_To (C, Loc))));
8778 -- if C = POK_Protected_Entry
8779 -- or else C = POK_Task_Entry
8782 Make_If_Statement (Loc,
8788 New_Reference_To (C, Loc),
8790 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
8795 New_Reference_To (C, Loc),
8797 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
8799 -- Dispatching requeue equivalent
8801 Then_Statements => New_List (
8802 Build_Dispatching_Requeue,
8805 -- elsif C = POK_Protected_Procedure then
8807 Elsif_Parts => New_List (
8808 Make_Elsif_Part (Loc,
8812 New_Reference_To (C, Loc),
8815 RTE (RE_POK_Protected_Procedure), Loc)),
8817 -- Dispatching call equivalent
8819 Then_Statements => New_List (
8820 Build_Dispatching_Call_Equivalent))),
8823 -- raise Program_Error;
8826 Else_Statements => New_List (
8827 Make_Raise_Program_Error (Loc,
8828 Reason => PE_Explicit_Raise))));
8830 -- Wrap everything into a block
8833 Make_Block_Statement (Loc,
8834 Declarations => Decls,
8835 Handled_Statement_Sequence =>
8836 Make_Handled_Sequence_Of_Statements (Loc,
8837 Statements => Stmts));
8838 end Build_Dispatching_Requeue_To_Any;
8840 --------------------------
8841 -- Build_Normal_Requeue --
8842 --------------------------
8844 function Build_Normal_Requeue return Node_Id is
8845 Params : constant List_Id := New_List;
8850 -- Process the "with abort" parameter
8853 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8855 -- Add the index expression to the parameters. It is common among all
8859 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8861 if Is_Protected_Type (Old_Typ) then
8863 Self_Param : Node_Id;
8867 Make_Attribute_Reference (Loc,
8869 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8871 Name_Unchecked_Access);
8873 -- Protected to protected requeue
8875 if Is_Protected_Type (Conc_Typ) then
8878 RTE (RE_Requeue_Protected_Entry), Loc);
8881 Make_Attribute_Reference (Loc,
8883 Concurrent_Ref (Concval),
8885 Name_Unchecked_Access);
8887 -- Protected to task requeue
8889 else pragma Assert (Is_Task_Type (Conc_Typ));
8892 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8894 Param := Concurrent_Ref (Concval);
8897 Prepend_To (Params, Param);
8898 Prepend_To (Params, Self_Param);
8901 else pragma Assert (Is_Task_Type (Old_Typ));
8903 -- Task to protected requeue
8905 if Is_Protected_Type (Conc_Typ) then
8908 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8911 Make_Attribute_Reference (Loc,
8913 Concurrent_Ref (Concval),
8915 Name_Unchecked_Access);
8917 -- Task to task requeue
8919 else pragma Assert (Is_Task_Type (Conc_Typ));
8921 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
8923 Param := Concurrent_Ref (Concval);
8926 Prepend_To (Params, Param);
8930 Make_Procedure_Call_Statement (Loc,
8932 Parameter_Associations => Params);
8933 end Build_Normal_Requeue;
8935 --------------------------
8936 -- Build_Skip_Statement --
8937 --------------------------
8939 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
8940 Skip_Stmt : Node_Id;
8943 -- Build a return statement to skip the rest of the entire body
8945 if Is_Protected_Type (Old_Typ) then
8946 Skip_Stmt := Make_Simple_Return_Statement (Loc);
8948 -- If the requeue is within a task, find the end label of the
8949 -- enclosing accept statement and create a goto statement to it.
8957 -- Climb the parent chain looking for the enclosing accept
8960 Acc := Parent (Search);
8962 and then Nkind (Acc) /= N_Accept_Statement
8964 Acc := Parent (Acc);
8967 -- The last statement is the second label used for completing
8968 -- the rendezvous the usual way. The label we are looking for
8969 -- is right before it.
8972 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
8974 pragma Assert (Nkind (Label) = N_Label);
8976 -- Generate a goto statement to skip the rest of the accept
8979 Make_Goto_Statement (Loc,
8981 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
8985 Set_Analyzed (Skip_Stmt);
8988 end Build_Skip_Statement;
8990 -- Start of processing for Expand_N_Requeue_Statement
8993 -- Extract the components of the entry call
8995 Extract_Entry (N, Concval, Ename, Index);
8996 Conc_Typ := Etype (Concval);
8998 -- Examine the scope stack in order to find nearest enclosing protected
8999 -- or task type. This will constitute our invocation source.
9001 Old_Typ := Current_Scope;
9002 while Present (Old_Typ)
9003 and then not Is_Protected_Type (Old_Typ)
9004 and then not Is_Task_Type (Old_Typ)
9006 Old_Typ := Scope (Old_Typ);
9009 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9010 -- Concval.Ename where the type of Concval is class-wide concurrent
9013 if Ada_Version >= Ada_2012
9014 and then Present (Concval)
9015 and then Is_Class_Wide_Type (Conc_Typ)
9016 and then Is_Concurrent_Interface (Conc_Typ)
9019 Has_Impl : Boolean := False;
9020 Impl_Kind : Name_Id := No_Name;
9023 -- Check whether the Ename is flagged by pragma Implemented
9025 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9027 Impl_Kind := Implementation_Kind (Entity (Ename));
9030 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9031 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9034 and then Impl_Kind = Name_By_Entry
9036 Rewrite (N, Build_Dispatching_Requeue);
9038 Insert_After (N, Build_Skip_Statement (N));
9040 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9041 -- a protected procedure. In this case the requeue is transformed
9042 -- into a dispatching call.
9045 and then Impl_Kind = Name_By_Protected_Procedure
9047 Rewrite (N, Build_Dispatching_Call_Equivalent);
9050 -- The procedure_or_entry_NAME's implementation kind is either
9051 -- By_Any or pragma Implemented was not applied at all. In this
9052 -- case a runtime test determines whether Ename denotes an entry
9053 -- or a protected procedure and performs the appropriate call.
9056 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9061 -- Processing for regular (non-dispatching) requeues
9064 Rewrite (N, Build_Normal_Requeue);
9066 Insert_After (N, Build_Skip_Statement (N));
9068 end Expand_N_Requeue_Statement;
9070 -------------------------------
9071 -- Expand_N_Selective_Accept --
9072 -------------------------------
9074 procedure Expand_N_Selective_Accept (N : Node_Id) is
9075 Loc : constant Source_Ptr := Sloc (N);
9076 Alts : constant List_Id := Select_Alternatives (N);
9078 -- Note: in the below declarations a lot of new lists are allocated
9079 -- unconditionally which may well not end up being used. That's
9080 -- not a good idea since it wastes space gratuitously ???
9082 Accept_Case : List_Id;
9083 Accept_List : constant List_Id := New_List;
9086 Alt_List : constant List_Id := New_List;
9087 Alt_Stats : List_Id;
9088 Ann : Entity_Id := Empty;
9091 Check_Guard : Boolean := True;
9093 Decls : constant List_Id := New_List;
9094 Stats : constant List_Id := New_List;
9095 Body_List : constant List_Id := New_List;
9096 Trailing_List : constant List_Id := New_List;
9099 Else_Present : Boolean := False;
9100 Terminate_Alt : Node_Id := Empty;
9101 Select_Mode : Node_Id;
9103 Delay_Case : List_Id;
9104 Delay_Count : Integer := 0;
9105 Delay_Val : Entity_Id;
9106 Delay_Index : Entity_Id;
9107 Delay_Min : Entity_Id;
9108 Delay_Num : Int := 1;
9109 Delay_Alt_List : List_Id := New_List;
9110 Delay_List : constant List_Id := New_List;
9114 First_Delay : Boolean := True;
9115 Guard_Open : Entity_Id;
9121 Num_Accept : Nat := 0;
9124 Time_Type : Entity_Id;
9126 Select_Call : Node_Id;
9128 Qnam : constant Entity_Id :=
9129 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9131 Xnam : constant Entity_Id :=
9132 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9134 -----------------------
9135 -- Local subprograms --
9136 -----------------------
9138 function Accept_Or_Raise return List_Id;
9139 -- For the rare case where delay alternatives all have guards, and
9140 -- all of them are closed, it is still possible that there were open
9141 -- accept alternatives with no callers. We must reexamine the
9142 -- Accept_List, and execute a selective wait with no else if some
9143 -- accept is open. If none, we raise program_error.
9145 procedure Add_Accept (Alt : Node_Id);
9146 -- Process a single accept statement in a select alternative. Build
9147 -- procedure for body of accept, and add entry to dispatch table with
9148 -- expression for guard, in preparation for call to run time select.
9150 function Make_And_Declare_Label (Num : Int) return Node_Id;
9151 -- Manufacture a label using Num as a serial number and declare it.
9152 -- The declaration is appended to Decls. The label marks the trailing
9153 -- statements of an accept or delay alternative.
9155 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9156 -- Build call to Selective_Wait runtime routine
9158 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9159 -- Add code to compare value of delay with previous values, and
9160 -- generate case entry for trailing statements.
9162 procedure Process_Accept_Alternative
9166 -- Add code to call corresponding procedure, and branch to
9167 -- trailing statements, if any.
9169 ---------------------
9170 -- Accept_Or_Raise --
9171 ---------------------
9173 function Accept_Or_Raise return List_Id is
9176 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9179 -- We generate the following:
9181 -- for J in q'range loop
9182 -- if q(J).S /=null_task_entry then
9183 -- selective_wait (simple_mode,...);
9189 -- if no rendez_vous then
9190 -- raise program_error;
9193 -- Note that the code needs to know that the selector name
9194 -- in an Accept_Alternative is named S.
9196 Cond := Make_Op_Ne (Loc,
9198 Make_Selected_Component (Loc,
9199 Prefix => Make_Indexed_Component (Loc,
9200 Prefix => New_Reference_To (Qnam, Loc),
9201 Expressions => New_List (New_Reference_To (J, Loc))),
9202 Selector_Name => Make_Identifier (Loc, Name_S)),
9204 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9207 Make_Implicit_Loop_Statement (N,
9208 Identifier => Empty,
9210 Make_Iteration_Scheme (Loc,
9211 Loop_Parameter_Specification =>
9212 Make_Loop_Parameter_Specification (Loc,
9213 Defining_Identifier => J,
9214 Discrete_Subtype_Definition =>
9215 Make_Attribute_Reference (Loc,
9216 Prefix => New_Reference_To (Qnam, Loc),
9217 Attribute_Name => Name_Range,
9218 Expressions => New_List (
9219 Make_Integer_Literal (Loc, 1))))),
9221 Statements => New_List (
9222 Make_Implicit_If_Statement (N,
9224 Then_Statements => New_List (
9226 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9227 Make_Exit_Statement (Loc))))));
9230 Make_Raise_Program_Error (Loc,
9231 Condition => Make_Op_Eq (Loc,
9232 Left_Opnd => New_Reference_To (Xnam, Loc),
9234 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9235 Reason => PE_All_Guards_Closed));
9238 end Accept_Or_Raise;
9244 procedure Add_Accept (Alt : Node_Id) is
9245 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9246 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9247 Eloc : constant Source_Ptr := Sloc (Ename);
9248 Eent : constant Entity_Id := Entity (Ename);
9249 Index : constant Node_Id := Entry_Index (Acc_Stm);
9250 Null_Body : Node_Id;
9251 Proc_Body : Node_Id;
9258 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9261 if Present (Condition (Alt)) then
9263 Make_Conditional_Expression (Eloc, New_List (
9265 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9266 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9269 Entry_Index_Expression
9270 (Eloc, Eent, Index, Scope (Eent));
9273 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9274 Null_Body := New_Reference_To (Standard_False, Eloc);
9276 if Abort_Allowed then
9277 Call := Make_Procedure_Call_Statement (Eloc,
9278 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9279 Insert_Before (First (Statements (Handled_Statement_Sequence (
9280 Accept_Statement (Alt)))), Call);
9285 Make_Defining_Identifier (Eloc,
9286 New_External_Name (Chars (Ename), 'A', Num_Accept));
9288 if Comes_From_Source (Alt) then
9289 Set_Debug_Info_Needed (PB_Ent);
9293 Make_Subprogram_Body (Eloc,
9295 Make_Procedure_Specification (Eloc,
9296 Defining_Unit_Name => PB_Ent),
9297 Declarations => Declarations (Acc_Stm),
9298 Handled_Statement_Sequence =>
9299 Build_Accept_Body (Accept_Statement (Alt)));
9301 -- During the analysis of the body of the accept statement, any
9302 -- zero cost exception handler records were collected in the
9303 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9304 -- This is where we move them to where they belong, namely the
9305 -- newly created procedure.
9307 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9308 Append (Proc_Body, Body_List);
9311 Null_Body := New_Reference_To (Standard_True, Eloc);
9313 -- if accept statement has declarations, insert above, given that
9314 -- we are not creating a body for the accept.
9316 if Present (Declarations (Acc_Stm)) then
9317 Insert_Actions (N, Declarations (Acc_Stm));
9321 Append_To (Accept_List,
9322 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9324 Num_Accept := Num_Accept + 1;
9327 ----------------------------
9328 -- Make_And_Declare_Label --
9329 ----------------------------
9331 function Make_And_Declare_Label (Num : Int) return Node_Id is
9335 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9337 Make_Label (Loc, Lab_Id);
9340 Make_Implicit_Label_Declaration (Loc,
9341 Defining_Identifier =>
9342 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9343 Label_Construct => Lab));
9346 end Make_And_Declare_Label;
9348 ----------------------
9349 -- Make_Select_Call --
9350 ----------------------
9352 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9353 Params : constant List_Id := New_List;
9357 Make_Attribute_Reference (Loc,
9358 Prefix => New_Reference_To (Qnam, Loc),
9359 Attribute_Name => Name_Unchecked_Access),
9361 Append (Select_Mode, Params);
9362 Append (New_Reference_To (Ann, Loc), Params);
9363 Append (New_Reference_To (Xnam, Loc), Params);
9366 Make_Procedure_Call_Statement (Loc,
9367 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9368 Parameter_Associations => Params);
9369 end Make_Select_Call;
9371 --------------------------------
9372 -- Process_Accept_Alternative --
9373 --------------------------------
9375 procedure Process_Accept_Alternative
9380 Choices : List_Id := No_List;
9381 Alt_Stats : List_Id;
9384 Adjust_Condition (Condition (Alt));
9385 Alt_Stats := No_List;
9387 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9388 Choices := New_List (
9389 Make_Integer_Literal (Loc, Index));
9391 Alt_Stats := New_List (
9392 Make_Procedure_Call_Statement (Sloc (Proc),
9393 Name => New_Reference_To (
9394 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9397 if Statements (Alt) /= Empty_List then
9399 if No (Alt_Stats) then
9401 -- Accept with no body, followed by trailing statements
9403 Choices := New_List (
9404 Make_Integer_Literal (Loc, Index));
9406 Alt_Stats := New_List;
9409 -- After the call, if any, branch to trailing statements. We
9410 -- create a label for each, as well as the corresponding label
9413 Lab := Make_And_Declare_Label (Index);
9414 Append_To (Alt_Stats,
9415 Make_Goto_Statement (Loc,
9416 Name => New_Copy (Identifier (Lab))));
9418 Append (Lab, Trailing_List);
9419 Append_List (Statements (Alt), Trailing_List);
9420 Append_To (Trailing_List,
9421 Make_Goto_Statement (Loc,
9422 Name => New_Copy (Identifier (End_Lab))));
9425 if Present (Alt_Stats) then
9427 -- Procedure call. and/or trailing statements
9429 Append_To (Alt_List,
9430 Make_Case_Statement_Alternative (Loc,
9431 Discrete_Choices => Choices,
9432 Statements => Alt_Stats));
9434 end Process_Accept_Alternative;
9436 -------------------------------
9437 -- Process_Delay_Alternative --
9438 -------------------------------
9440 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9443 Delay_Alt : List_Id;
9446 -- Deal with C/Fortran boolean as delay condition
9448 Adjust_Condition (Condition (Alt));
9450 -- Determine the smallest specified delay
9452 -- for each delay alternative generate:
9454 -- if guard-expression then
9455 -- Delay_Val := delay-expression;
9456 -- Guard_Open := True;
9457 -- if Delay_Val < Delay_Min then
9458 -- Delay_Min := Delay_Val;
9459 -- Delay_Index := Index;
9463 -- The enclosing if-statement is omitted if there is no guard
9468 First_Delay := False;
9470 Delay_Alt := New_List (
9471 Make_Assignment_Statement (Loc,
9472 Name => New_Reference_To (Delay_Min, Loc),
9473 Expression => Expression (Delay_Statement (Alt))));
9475 if Delay_Count > 1 then
9476 Append_To (Delay_Alt,
9477 Make_Assignment_Statement (Loc,
9478 Name => New_Reference_To (Delay_Index, Loc),
9479 Expression => Make_Integer_Literal (Loc, Index)));
9483 Delay_Alt := New_List (
9484 Make_Assignment_Statement (Loc,
9485 Name => New_Reference_To (Delay_Val, Loc),
9486 Expression => Expression (Delay_Statement (Alt))));
9488 if Time_Type = Standard_Duration then
9491 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9492 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9495 -- The scope of the time type must define a comparison
9496 -- operator. The scope itself may not be visible, so we
9497 -- construct a node with entity information to insure that
9498 -- semantic analysis can find the proper operator.
9501 Make_Function_Call (Loc,
9502 Name => Make_Selected_Component (Loc,
9503 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9505 Make_Operator_Symbol (Loc,
9506 Chars => Name_Op_Lt,
9507 Strval => No_String)),
9508 Parameter_Associations =>
9510 New_Reference_To (Delay_Val, Loc),
9511 New_Reference_To (Delay_Min, Loc)));
9513 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9516 Append_To (Delay_Alt,
9517 Make_Implicit_If_Statement (N,
9519 Then_Statements => New_List (
9520 Make_Assignment_Statement (Loc,
9521 Name => New_Reference_To (Delay_Min, Loc),
9522 Expression => New_Reference_To (Delay_Val, Loc)),
9524 Make_Assignment_Statement (Loc,
9525 Name => New_Reference_To (Delay_Index, Loc),
9526 Expression => Make_Integer_Literal (Loc, Index)))));
9530 Append_To (Delay_Alt,
9531 Make_Assignment_Statement (Loc,
9532 Name => New_Reference_To (Guard_Open, Loc),
9533 Expression => New_Reference_To (Standard_True, Loc)));
9536 if Present (Condition (Alt)) then
9537 Delay_Alt := New_List (
9538 Make_Implicit_If_Statement (N,
9539 Condition => Condition (Alt),
9540 Then_Statements => Delay_Alt));
9543 Append_List (Delay_Alt, Delay_List);
9545 -- If the delay alternative has a statement part, add choice to the
9546 -- case statements for delays.
9548 if Present (Statements (Alt)) then
9550 if Delay_Count = 1 then
9551 Append_List (Statements (Alt), Delay_Alt_List);
9554 Choices := New_List (
9555 Make_Integer_Literal (Loc, Index));
9557 Append_To (Delay_Alt_List,
9558 Make_Case_Statement_Alternative (Loc,
9559 Discrete_Choices => Choices,
9560 Statements => Statements (Alt)));
9563 elsif Delay_Count = 1 then
9565 -- If the single delay has no trailing statements, add a branch
9566 -- to the exit label to the selective wait.
9568 Delay_Alt_List := New_List (
9569 Make_Goto_Statement (Loc,
9570 Name => New_Copy (Identifier (End_Lab))));
9573 end Process_Delay_Alternative;
9575 -- Start of processing for Expand_N_Selective_Accept
9578 -- First insert some declarations before the select. The first is:
9582 -- This variable holds the parameters passed to the accept body. This
9583 -- declaration has already been inserted by the time we get here by
9584 -- a call to Expand_Accept_Declarations made from the semantics when
9585 -- processing the first accept statement contained in the select. We
9586 -- can find this entity as Accept_Address (E), where E is any of the
9587 -- entries references by contained accept statements.
9589 -- The first step is to scan the list of Selective_Accept_Statements
9590 -- to find this entity, and also count the number of accepts, and
9591 -- determine if terminated, delay or else is present:
9595 Alt := First (Alts);
9596 while Present (Alt) loop
9598 if Nkind (Alt) = N_Accept_Alternative then
9601 elsif Nkind (Alt) = N_Delay_Alternative then
9602 Delay_Count := Delay_Count + 1;
9604 -- If the delays are relative delays, the delay expressions have
9605 -- type Standard_Duration. Otherwise they must have some time type
9606 -- recognized by GNAT.
9608 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9609 Time_Type := Standard_Duration;
9611 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9613 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9614 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9619 "& is not a time type (RM 9.6(6))",
9620 Expression (Delay_Statement (Alt)), Time_Type);
9621 Time_Type := Standard_Duration;
9622 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9626 if No (Condition (Alt)) then
9628 -- This guard will always be open
9630 Check_Guard := False;
9633 elsif Nkind (Alt) = N_Terminate_Alternative then
9634 Adjust_Condition (Condition (Alt));
9635 Terminate_Alt := Alt;
9638 Num_Alts := Num_Alts + 1;
9642 Else_Present := Present (Else_Statements (N));
9644 -- At the same time (see procedure Add_Accept) we build the accept list:
9646 -- Qnn : Accept_List (1 .. num-select) := (
9647 -- (null-body, entry-index),
9648 -- (null-body, entry-index),
9650 -- (null_body, entry-index));
9652 -- In the above declaration, null-body is True if the corresponding
9653 -- accept has no body, and false otherwise. The entry is either the
9654 -- entry index expression if there is no guard, or if a guard is
9655 -- present, then a conditional expression of the form:
9657 -- (if guard then entry-index else Null_Task_Entry)
9659 -- If a guard is statically known to be false, the entry can simply
9660 -- be omitted from the accept list.
9663 Make_Object_Declaration (Loc,
9664 Defining_Identifier => Qnam,
9665 Object_Definition =>
9666 New_Reference_To (RTE (RE_Accept_List), Loc),
9667 Aliased_Present => True,
9670 Make_Qualified_Expression (Loc,
9672 New_Reference_To (RTE (RE_Accept_List), Loc),
9674 Make_Aggregate (Loc, Expressions => Accept_List)));
9678 -- Then we declare the variable that holds the index for the accept
9679 -- that will be selected for service:
9681 -- Xnn : Select_Index;
9684 Make_Object_Declaration (Loc,
9685 Defining_Identifier => Xnam,
9686 Object_Definition =>
9687 New_Reference_To (RTE (RE_Select_Index), Loc),
9689 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9693 -- After this follow procedure declarations for each accept body
9700 -- where the ... are statements from the corresponding procedure body.
9701 -- No parameters are involved, since the parameters are passed via Ann
9702 -- and the parameter references have already been expanded to be direct
9703 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9704 -- any embedded tasking statements (which would normally be illegal in
9705 -- procedures), have been converted to calls to the tasking runtime so
9706 -- there is no problem in putting them into procedures.
9708 -- The original accept statement has been expanded into a block in
9709 -- the same fashion as for simple accepts (see Build_Accept_Body).
9711 -- Note: we don't really need to build these procedures for the case
9712 -- where no delay statement is present, but it is just as easy to
9713 -- build them unconditionally, and not significantly inefficient,
9714 -- since if they are short they will be inlined anyway.
9716 -- The procedure declarations have been assembled in Body_List
9718 -- If delays are present, we must compute the required delay.
9719 -- We first generate the declarations:
9721 -- Delay_Index : Boolean := 0;
9722 -- Delay_Min : Some_Time_Type.Time;
9723 -- Delay_Val : Some_Time_Type.Time;
9725 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9726 -- active delay that is actually chosen as the basis for the possible
9727 -- delay if an immediate rendez-vous is not possible.
9729 -- In the most common case there is a single delay statement, and this
9730 -- is handled specially.
9732 if Delay_Count > 0 then
9734 -- Generate the required declarations
9737 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9739 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9741 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9744 Make_Object_Declaration (Loc,
9745 Defining_Identifier => Delay_Val,
9746 Object_Definition => New_Reference_To (Time_Type, Loc)));
9749 Make_Object_Declaration (Loc,
9750 Defining_Identifier => Delay_Index,
9751 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9752 Expression => Make_Integer_Literal (Loc, 0)));
9755 Make_Object_Declaration (Loc,
9756 Defining_Identifier => Delay_Min,
9757 Object_Definition => New_Reference_To (Time_Type, Loc),
9759 Unchecked_Convert_To (Time_Type,
9760 Make_Attribute_Reference (Loc,
9762 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9763 Attribute_Name => Name_Last))));
9765 -- Create Duration and Delay_Mode objects used for passing a delay
9768 D := Make_Temporary (Loc, 'D');
9769 M := Make_Temporary (Loc, 'M');
9775 -- Note that these values are defined in s-osprim.ads and must
9778 -- Relative : constant := 0;
9779 -- Absolute_Calendar : constant := 1;
9780 -- Absolute_RT : constant := 2;
9782 if Time_Type = Standard_Duration then
9783 Discr := Make_Integer_Literal (Loc, 0);
9785 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9786 Discr := Make_Integer_Literal (Loc, 1);
9790 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9791 Discr := Make_Integer_Literal (Loc, 2);
9795 Make_Object_Declaration (Loc,
9796 Defining_Identifier => D,
9797 Object_Definition =>
9798 New_Reference_To (Standard_Duration, Loc)));
9801 Make_Object_Declaration (Loc,
9802 Defining_Identifier => M,
9803 Object_Definition =>
9804 New_Reference_To (Standard_Integer, Loc),
9805 Expression => Discr));
9810 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9813 Make_Object_Declaration (Loc,
9814 Defining_Identifier => Guard_Open,
9815 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9816 Expression => New_Reference_To (Standard_False, Loc)));
9819 -- Delay_Count is zero, don't need M and D set (suppress warning)
9826 if Present (Terminate_Alt) then
9828 -- If the terminate alternative guard is False, use
9829 -- Simple_Mode; otherwise use Terminate_Mode.
9831 if Present (Condition (Terminate_Alt)) then
9832 Select_Mode := Make_Conditional_Expression (Loc,
9833 New_List (Condition (Terminate_Alt),
9834 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9835 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9837 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9840 elsif Else_Present or Delay_Count > 0 then
9841 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9844 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9847 Select_Call := Make_Select_Call (Select_Mode);
9848 Append (Select_Call, Stats);
9850 -- Now generate code to act on the result. There is an entry
9851 -- in this case for each accept statement with a non-null body,
9852 -- followed by a branch to the statements that follow the Accept.
9853 -- In the absence of delay alternatives, we generate:
9856 -- when No_Rendezvous => -- omitted if simple mode
9871 -- Lab0: Else_Statements;
9874 -- Lab1: Trailing_Statements1;
9877 -- Lab2: Trailing_Statements2;
9882 -- Generate label for common exit
9884 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9886 -- First entry is the default case, when no rendezvous is possible
9888 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9890 if Else_Present then
9892 -- If no rendezvous is possible, the else part is executed
9894 Lab := Make_And_Declare_Label (0);
9895 Alt_Stats := New_List (
9896 Make_Goto_Statement (Loc,
9897 Name => New_Copy (Identifier (Lab))));
9899 Append (Lab, Trailing_List);
9900 Append_List (Else_Statements (N), Trailing_List);
9901 Append_To (Trailing_List,
9902 Make_Goto_Statement (Loc,
9903 Name => New_Copy (Identifier (End_Lab))));
9905 Alt_Stats := New_List (
9906 Make_Goto_Statement (Loc,
9907 Name => New_Copy (Identifier (End_Lab))));
9910 Append_To (Alt_List,
9911 Make_Case_Statement_Alternative (Loc,
9912 Discrete_Choices => Choices,
9913 Statements => Alt_Stats));
9915 -- We make use of the fact that Accept_Index is an integer type, and
9916 -- generate successive literals for entries for each accept. Only those
9917 -- for which there is a body or trailing statements get a case entry.
9919 Alt := First (Select_Alternatives (N));
9920 Proc := First (Body_List);
9921 while Present (Alt) loop
9923 if Nkind (Alt) = N_Accept_Alternative then
9924 Process_Accept_Alternative (Alt, Index, Proc);
9928 (Handled_Statement_Sequence (Accept_Statement (Alt)))
9933 elsif Nkind (Alt) = N_Delay_Alternative then
9934 Process_Delay_Alternative (Alt, Delay_Num);
9935 Delay_Num := Delay_Num + 1;
9941 -- An others choice is always added to the main case, as well
9942 -- as the delay case (to satisfy the compiler).
9944 Append_To (Alt_List,
9945 Make_Case_Statement_Alternative (Loc,
9947 New_List (Make_Others_Choice (Loc)),
9949 New_List (Make_Goto_Statement (Loc,
9950 Name => New_Copy (Identifier (End_Lab))))));
9952 Accept_Case := New_List (
9953 Make_Case_Statement (Loc,
9954 Expression => New_Reference_To (Xnam, Loc),
9955 Alternatives => Alt_List));
9957 Append_List (Trailing_List, Accept_Case);
9958 Append (End_Lab, Accept_Case);
9959 Append_List (Body_List, Decls);
9961 -- Construct case statement for trailing statements of delay
9962 -- alternatives, if there are several of them.
9964 if Delay_Count > 1 then
9965 Append_To (Delay_Alt_List,
9966 Make_Case_Statement_Alternative (Loc,
9968 New_List (Make_Others_Choice (Loc)),
9970 New_List (Make_Null_Statement (Loc))));
9972 Delay_Case := New_List (
9973 Make_Case_Statement (Loc,
9974 Expression => New_Reference_To (Delay_Index, Loc),
9975 Alternatives => Delay_Alt_List));
9977 Delay_Case := Delay_Alt_List;
9980 -- If there are no delay alternatives, we append the case statement
9981 -- to the statement list.
9983 if Delay_Count = 0 then
9984 Append_List (Accept_Case, Stats);
9986 -- Delay alternatives present
9989 -- If delay alternatives are present we generate:
9991 -- find minimum delay.
9992 -- DX := minimum delay;
9993 -- M := <delay mode>;
9994 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
9997 -- if X = No_Rendezvous then
9998 -- case statement for delay statements.
10000 -- case statement for accept alternatives.
10011 -- The type of the delay expression is known to be legal
10013 if Time_Type = Standard_Duration then
10014 Conv := New_Reference_To (Delay_Min, Loc);
10016 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10017 Conv := Make_Function_Call (Loc,
10018 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10019 New_List (New_Reference_To (Delay_Min, Loc)));
10023 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10025 Conv := Make_Function_Call (Loc,
10026 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10027 New_List (New_Reference_To (Delay_Min, Loc)));
10030 Stmt := Make_Assignment_Statement (Loc,
10031 Name => New_Reference_To (D, Loc),
10032 Expression => Conv);
10034 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10036 Parms := Parameter_Associations (Select_Call);
10037 Parm := First (Parms);
10039 while Present (Parm)
10040 and then Parm /= Select_Mode
10045 pragma Assert (Present (Parm));
10046 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10049 -- Prepare two new parameters of Duration and Delay_Mode type
10050 -- which represent the value and the mode of the minimum delay.
10053 Insert_After (Parm, New_Reference_To (M, Loc));
10054 Insert_After (Parm, New_Reference_To (D, Loc));
10056 -- Create a call to RTS
10058 Rewrite (Select_Call,
10059 Make_Procedure_Call_Statement (Loc,
10060 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10061 Parameter_Associations => Parms));
10063 -- This new call should follow the calculation of the minimum
10066 Insert_List_Before (Select_Call, Delay_List);
10068 if Check_Guard then
10070 Make_Implicit_If_Statement (N,
10071 Condition => New_Reference_To (Guard_Open, Loc),
10073 New_List (New_Copy_Tree (Stmt),
10074 New_Copy_Tree (Select_Call)),
10075 Else_Statements => Accept_Or_Raise);
10076 Rewrite (Select_Call, Stmt);
10078 Insert_Before (Select_Call, Stmt);
10082 Make_Implicit_If_Statement (N,
10083 Condition => Make_Op_Eq (Loc,
10084 Left_Opnd => New_Reference_To (Xnam, Loc),
10086 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10088 Then_Statements => Delay_Case,
10089 Else_Statements => Accept_Case);
10091 Append (Cases, Stats);
10095 -- Replace accept statement with appropriate block
10098 Make_Block_Statement (Loc,
10099 Declarations => Decls,
10100 Handled_Statement_Sequence =>
10101 Make_Handled_Sequence_Of_Statements (Loc,
10102 Statements => Stats));
10104 Rewrite (N, Block);
10107 -- Note: have to worry more about abort deferral in above code ???
10109 -- Final step is to unstack the Accept_Address entries for all accept
10110 -- statements appearing in accept alternatives in the select statement
10112 Alt := First (Alts);
10113 while Present (Alt) loop
10114 if Nkind (Alt) = N_Accept_Alternative then
10115 Remove_Last_Elmt (Accept_Address
10116 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10121 end Expand_N_Selective_Accept;
10123 --------------------------------------
10124 -- Expand_N_Single_Task_Declaration --
10125 --------------------------------------
10127 -- Single task declarations should never be present after semantic
10128 -- analysis, since we expect them to be replaced by a declaration of an
10129 -- anonymous task type, followed by a declaration of the task object. We
10130 -- include this routine to make sure that is happening!
10132 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10134 raise Program_Error;
10135 end Expand_N_Single_Task_Declaration;
10137 ------------------------
10138 -- Expand_N_Task_Body --
10139 ------------------------
10141 -- Given a task body
10143 -- task body tname is
10149 -- This expansion routine converts it into a procedure and sets the
10150 -- elaboration flag for the procedure to true, to represent the fact
10151 -- that the task body is now elaborated:
10153 -- procedure tnameB (_Task : access tnameV) is
10154 -- discriminal : dtype renames _Task.discriminant;
10156 -- procedure _clean is
10158 -- Abort_Defer.all;
10160 -- Abort_Undefer.all;
10165 -- Abort_Undefer.all;
10167 -- System.Task_Stages.Complete_Activation;
10175 -- In addition, if the task body is an activator, then a call to activate
10176 -- tasks is added at the start of the statements, before the call to
10177 -- Complete_Activation, and if in addition the task is a master then it
10178 -- must be established as a master. These calls are inserted and analyzed
10179 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10182 -- There is one discriminal declaration line generated for each
10183 -- discriminant that is present to provide an easy reference point for
10184 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10186 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10187 -- task body procedures have a profile (Arg : System.Address). That is
10188 -- needed because GNARLI has to use the same access-to-subprogram type
10189 -- for all task types. We depend here on knowing that in GNAT, passing
10190 -- an address argument by value is identical to passing a record value
10191 -- by access (in either case a single pointer is passed), so even though
10192 -- this procedure has the wrong profile. In fact it's all OK, since the
10193 -- callings sequence is identical.
10195 procedure Expand_N_Task_Body (N : Node_Id) is
10196 Loc : constant Source_Ptr := Sloc (N);
10197 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10201 Insert_Nod : Node_Id;
10202 -- Used to determine the proper location of wrapper body insertions
10205 -- Add renaming declarations for discriminals and a declaration for the
10206 -- entry family index (if applicable).
10208 Install_Private_Data_Declarations
10209 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10211 -- Add a call to Abort_Undefer at the very beginning of the task
10212 -- body since this body is called with abort still deferred.
10214 if Abort_Allowed then
10215 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10217 (First (Statements (Handled_Statement_Sequence (N))), Call);
10221 -- The statement part has already been protected with an at_end and
10222 -- cleanup actions. The call to Complete_Activation must be placed
10223 -- at the head of the sequence of statements of that block. The
10224 -- declarations have been merged in this sequence of statements but
10225 -- the first real statement is accessible from the First_Real_Statement
10226 -- field (which was set for exactly this purpose).
10228 if Restricted_Profile then
10229 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10231 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10235 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10239 Make_Subprogram_Body (Loc,
10240 Specification => Build_Task_Proc_Specification (Ttyp),
10241 Declarations => Declarations (N),
10242 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10244 -- If the task contains generic instantiations, cleanup actions are
10245 -- delayed until after instantiation. Transfer the activation chain to
10246 -- the subprogram, to insure that the activation call is properly
10247 -- generated. It the task body contains inner tasks, indicate that the
10248 -- subprogram is a task master.
10250 if Delay_Cleanups (Ttyp) then
10251 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10252 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10255 Rewrite (N, New_N);
10258 -- Set elaboration flag immediately after task body. If the body is a
10259 -- subunit, the flag is set in the declarative part containing the stub.
10261 if Nkind (Parent (N)) /= N_Subunit then
10263 Make_Assignment_Statement (Loc,
10265 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10266 Expression => New_Reference_To (Standard_True, Loc)));
10269 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10270 -- the task body. At this point all wrapper specs have been created,
10271 -- frozen and included in the dispatch table for the task type.
10273 if Ada_Version >= Ada_2005 then
10274 if Nkind (Parent (N)) = N_Subunit then
10275 Insert_Nod := Corresponding_Stub (Parent (N));
10280 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10282 end Expand_N_Task_Body;
10284 ------------------------------------
10285 -- Expand_N_Task_Type_Declaration --
10286 ------------------------------------
10288 -- We have several things to do. First we must create a Boolean flag used
10289 -- to mark if the body is elaborated yet. This variable gets set to True
10290 -- when the body of the task is elaborated (we can't rely on the normal
10291 -- ABE mechanism for the task body, since we need to pass an access to
10292 -- this elaboration boolean to the runtime routines).
10294 -- taskE : aliased Boolean := False;
10296 -- Next a variable is declared to hold the task stack size (either the
10297 -- default : Unspecified_Size, or a value that is set by a pragma
10298 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10299 -- the variable is initialized with this value:
10301 -- taskZ : Size_Type := Unspecified_Size;
10303 -- taskZ : Size_Type := Size_Type (size_expression);
10305 -- Note: No variable is needed to hold the task relative deadline since
10306 -- its value would never be static because the parameter is of a private
10307 -- type (Ada.Real_Time.Time_Span).
10309 -- Next we create a corresponding record type declaration used to represent
10310 -- values of this task. The general form of this type declaration is
10312 -- type taskV (discriminants) is record
10313 -- _Task_Id : Task_Id;
10314 -- entry_family : array (bounds) of Void;
10315 -- _Priority : Integer := priority_expression;
10316 -- _Size : Size_Type := Size_Type (size_expression);
10317 -- _Task_Info : Task_Info_Type := task_info_expression;
10318 -- _CPU : Integer := cpu_range_expression;
10321 -- The discriminants are present only if the corresponding task type has
10322 -- discriminants, and they exactly mirror the task type discriminants.
10324 -- The Id field is always present. It contains the Task_Id value, as set by
10325 -- the call to Create_Task. Note that although the task is limited, the
10326 -- task value record type is not limited, so there is no problem in passing
10327 -- this field as an out parameter to Create_Task.
10329 -- One entry_family component is present for each entry family in the task
10330 -- definition. The bounds correspond to the bounds of the entry family
10331 -- (which may depend on discriminants). The element type is void, since we
10332 -- only need the bounds information for determining the entry index. Note
10333 -- that the use of an anonymous array would normally be illegal in this
10334 -- context, but this is a parser check, and the semantics is quite prepared
10335 -- to handle such a case.
10337 -- The _Size field is present only if a Storage_Size pragma appears in the
10338 -- task definition. The expression captures the argument that was present
10339 -- in the pragma, and is used to override the task stack size otherwise
10340 -- associated with the task type.
10342 -- The _Priority field is present only if a Priority or Interrupt_Priority
10343 -- pragma appears in the task definition. The expression captures the
10344 -- argument that was present in the pragma, and is used to provide the Size
10345 -- parameter to the call to Create_Task.
10347 -- The _Task_Info field is present only if a Task_Info pragma appears in
10348 -- the task definition. The expression captures the argument that was
10349 -- present in the pragma, and is used to provide the Task_Image parameter
10350 -- to the call to Create_Task.
10352 -- The _CPU field is present only if a CPU pragma appears in the task
10353 -- definition. The expression captures the argument that was present in
10354 -- the pragma, and is used to provide the CPU parameter to the call to
10357 -- The _Relative_Deadline field is present only if a Relative_Deadline
10358 -- pragma appears in the task definition. The expression captures the
10359 -- argument that was present in the pragma, and is used to provide the
10360 -- Relative_Deadline parameter to the call to Create_Task.
10362 -- When a task is declared, an instance of the task value record is
10363 -- created. The elaboration of this declaration creates the correct bounds
10364 -- for the entry families, and also evaluates the size, priority, and
10365 -- task_Info expressions if needed. The initialization routine for the task
10366 -- type itself then calls Create_Task with appropriate parameters to
10367 -- initialize the value of the Task_Id field.
10369 -- Note: the address of this record is passed as the "Discriminants"
10370 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10371 -- body procedure, it does not matter that it does not quite match the
10372 -- GNARLI model of what is being passed (the record contains more than just
10373 -- the discriminants, but the discriminants can be found from the record
10376 -- The Entity_Id for this created record type is placed in the
10377 -- Corresponding_Record_Type field of the associated task type entity.
10379 -- Next we create a procedure specification for the task body procedure:
10381 -- procedure taskB (_Task : access taskV);
10383 -- Note that this must come after the record type declaration, since
10384 -- the spec refers to this type. It turns out that the initialization
10385 -- procedure for the value type references the task body spec, but that's
10386 -- fine, since it won't be generated till the freeze point for the type,
10387 -- which is certainly after the task body spec declaration.
10389 -- Finally, we set the task index value field of the entry attribute in
10390 -- the case of a simple entry.
10392 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10393 Loc : constant Source_Ptr := Sloc (N);
10394 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10395 Tasknm : constant Name_Id := Chars (Tasktyp);
10396 Taskdef : constant Node_Id := Task_Definition (N);
10398 Proc_Spec : Node_Id;
10399 Rec_Decl : Node_Id;
10400 Rec_Ent : Entity_Id;
10402 Elab_Decl : Node_Id;
10403 Size_Decl : Node_Id;
10404 Body_Decl : Node_Id;
10405 Task_Size : Node_Id;
10406 Ent_Stack : Entity_Id;
10407 Decl_Stack : Node_Id;
10410 -- If already expanded, nothing to do
10412 if Present (Corresponding_Record_Type (Tasktyp)) then
10416 -- Here we will do the expansion
10418 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10420 Rec_Ent := Defining_Identifier (Rec_Decl);
10421 Cdecls := Component_Items (Component_List
10422 (Type_Definition (Rec_Decl)));
10424 Qualify_Entity_Names (N);
10426 -- First create the elaboration variable
10429 Make_Object_Declaration (Loc,
10430 Defining_Identifier =>
10431 Make_Defining_Identifier (Sloc (Tasktyp),
10432 Chars => New_External_Name (Tasknm, 'E')),
10433 Aliased_Present => True,
10434 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10435 Expression => New_Reference_To (Standard_False, Loc));
10436 Insert_After (N, Elab_Decl);
10438 -- Next create the declaration of the size variable (tasknmZ)
10440 Set_Storage_Size_Variable (Tasktyp,
10441 Make_Defining_Identifier (Sloc (Tasktyp),
10442 Chars => New_External_Name (Tasknm, 'Z')));
10444 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
10445 Is_Static_Expression (Expression (First (
10446 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
10447 Taskdef, Name_Storage_Size)))))
10450 Make_Object_Declaration (Loc,
10451 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10452 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10454 Convert_To (RTE (RE_Size_Type),
10456 Expression (First (
10457 Pragma_Argument_Associations (
10458 Find_Task_Or_Protected_Pragma
10459 (Taskdef, Name_Storage_Size)))))));
10463 Make_Object_Declaration (Loc,
10464 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10465 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10466 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10469 Insert_After (Elab_Decl, Size_Decl);
10471 -- Next build the rest of the corresponding record declaration. This is
10472 -- done last, since the corresponding record initialization procedure
10473 -- will reference the previously created entities.
10475 -- Fill in the component declarations -- first the _Task_Id field
10478 Make_Component_Declaration (Loc,
10479 Defining_Identifier =>
10480 Make_Defining_Identifier (Loc, Name_uTask_Id),
10481 Component_Definition =>
10482 Make_Component_Definition (Loc,
10483 Aliased_Present => False,
10484 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10487 -- Declare static ATCB (that is, created by the expander) if we are
10488 -- using the Restricted run time.
10490 if Restricted_Profile then
10492 Make_Component_Declaration (Loc,
10493 Defining_Identifier =>
10494 Make_Defining_Identifier (Loc, Name_uATCB),
10496 Component_Definition =>
10497 Make_Component_Definition (Loc,
10498 Aliased_Present => True,
10499 Subtype_Indication => Make_Subtype_Indication (Loc,
10500 Subtype_Mark => New_Occurrence_Of
10501 (RTE (RE_Ada_Task_Control_Block), Loc),
10504 Make_Index_Or_Discriminant_Constraint (Loc,
10506 New_List (Make_Integer_Literal (Loc, 0)))))));
10510 -- Declare static stack (that is, created by the expander) if we are
10511 -- using the Restricted run time on a bare board configuration.
10513 if Restricted_Profile
10514 and then Preallocated_Stacks_On_Target
10516 -- First we need to extract the appropriate stack size
10518 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10520 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10522 Expr_N : constant Node_Id :=
10523 Expression (First (
10524 Pragma_Argument_Associations (
10525 Find_Task_Or_Protected_Pragma
10526 (Taskdef, Name_Storage_Size))));
10527 Etyp : constant Entity_Id := Etype (Expr_N);
10528 P : constant Node_Id := Parent (Expr_N);
10531 -- The stack is defined inside the corresponding record.
10532 -- Therefore if the size of the stack is set by means of
10533 -- a discriminant, we must reference the discriminant of the
10534 -- corresponding record type.
10536 if Nkind (Expr_N) in N_Has_Entity
10537 and then Present (Discriminal_Link (Entity (Expr_N)))
10541 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10543 Set_Parent (Task_Size, P);
10544 Set_Etype (Task_Size, Etyp);
10545 Set_Analyzed (Task_Size);
10548 Task_Size := Relocate_Node (Expr_N);
10554 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10557 Decl_Stack := Make_Component_Declaration (Loc,
10558 Defining_Identifier => Ent_Stack,
10560 Component_Definition =>
10561 Make_Component_Definition (Loc,
10562 Aliased_Present => True,
10563 Subtype_Indication => Make_Subtype_Indication (Loc,
10565 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10568 Make_Index_Or_Discriminant_Constraint (Loc,
10569 Constraints => New_List (Make_Range (Loc,
10570 Low_Bound => Make_Integer_Literal (Loc, 1),
10571 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10574 Append_To (Cdecls, Decl_Stack);
10576 -- The appropriate alignment for the stack is ensured by the run-time
10577 -- code in charge of task creation.
10581 -- Add components for entry families
10583 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10585 -- Add the _Priority component if a Priority pragma is present
10587 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10589 Prag : constant Node_Id :=
10590 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10594 Expr := First (Pragma_Argument_Associations (Prag));
10596 if Nkind (Expr) = N_Pragma_Argument_Association then
10597 Expr := Expression (Expr);
10600 Expr := New_Copy_Tree (Expr);
10602 -- Add conversion to proper type to do range check if required
10603 -- Note that for runtime units, we allow out of range interrupt
10604 -- priority values to be used in a priority pragma. This is for
10605 -- the benefit of some versions of System.Interrupts which use
10606 -- a special server task with maximum interrupt priority.
10608 if Pragma_Name (Prag) = Name_Priority
10609 and then not GNAT_Mode
10611 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10613 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10617 Make_Component_Declaration (Loc,
10618 Defining_Identifier =>
10619 Make_Defining_Identifier (Loc, Name_uPriority),
10620 Component_Definition =>
10621 Make_Component_Definition (Loc,
10622 Aliased_Present => False,
10623 Subtype_Indication => New_Reference_To (Standard_Integer,
10625 Expression => Expr));
10629 -- Add the _Task_Size component if a Storage_Size pragma is present
10631 if Present (Taskdef)
10632 and then Has_Storage_Size_Pragma (Taskdef)
10635 Make_Component_Declaration (Loc,
10636 Defining_Identifier =>
10637 Make_Defining_Identifier (Loc, Name_uSize),
10639 Component_Definition =>
10640 Make_Component_Definition (Loc,
10641 Aliased_Present => False,
10642 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10646 Convert_To (RTE (RE_Size_Type),
10648 Expression (First (
10649 Pragma_Argument_Associations (
10650 Find_Task_Or_Protected_Pragma
10651 (Taskdef, Name_Storage_Size))))))));
10654 -- Add the _Task_Info component if a Task_Info pragma is present
10656 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10658 Make_Component_Declaration (Loc,
10659 Defining_Identifier =>
10660 Make_Defining_Identifier (Loc, Name_uTask_Info),
10662 Component_Definition =>
10663 Make_Component_Definition (Loc,
10664 Aliased_Present => False,
10665 Subtype_Indication =>
10666 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10668 Expression => New_Copy (
10669 Expression (First (
10670 Pragma_Argument_Associations (
10671 Find_Task_Or_Protected_Pragma
10672 (Taskdef, Name_Task_Info)))))));
10675 -- Add the _CPU component if a CPU pragma is present
10677 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
10679 Make_Component_Declaration (Loc,
10680 Defining_Identifier =>
10681 Make_Defining_Identifier (Loc, Name_uCPU),
10683 Component_Definition =>
10684 Make_Component_Definition (Loc,
10685 Aliased_Present => False,
10686 Subtype_Indication =>
10687 New_Reference_To (RTE (RE_CPU_Range), Loc)),
10689 Expression => New_Copy (
10690 Expression (First (
10691 Pragma_Argument_Associations (
10692 Find_Task_Or_Protected_Pragma
10693 (Taskdef, Name_CPU)))))));
10696 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10697 -- present. If we are using a restricted run time this component will
10698 -- not be added (deadlines are not allowed by the Ravenscar profile).
10700 if not Restricted_Profile
10701 and then Present (Taskdef)
10702 and then Has_Relative_Deadline_Pragma (Taskdef)
10705 Make_Component_Declaration (Loc,
10706 Defining_Identifier =>
10707 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10709 Component_Definition =>
10710 Make_Component_Definition (Loc,
10711 Aliased_Present => False,
10712 Subtype_Indication =>
10713 New_Reference_To (RTE (RE_Time_Span), Loc)),
10716 Convert_To (RTE (RE_Time_Span),
10718 Expression (First (
10719 Pragma_Argument_Associations (
10720 Find_Task_Or_Protected_Pragma
10721 (Taskdef, Name_Relative_Deadline))))))));
10724 Insert_After (Size_Decl, Rec_Decl);
10726 -- Analyze the record declaration immediately after construction,
10727 -- because the initialization procedure is needed for single task
10728 -- declarations before the next entity is analyzed.
10730 Analyze (Rec_Decl);
10732 -- Create the declaration of the task body procedure
10734 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10736 Make_Subprogram_Declaration (Loc,
10737 Specification => Proc_Spec);
10739 Insert_After (Rec_Decl, Body_Decl);
10741 -- The subprogram does not comes from source, so we have to indicate the
10742 -- need for debugging information explicitly.
10744 if Comes_From_Source (Original_Node (N)) then
10745 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10748 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10749 -- the corresponding record has been frozen.
10751 if Ada_Version >= Ada_2005 then
10752 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10755 -- Ada 2005 (AI-345): We must defer freezing to allow further
10756 -- declaration of primitive subprograms covering task interfaces
10758 if Ada_Version <= Ada_95 then
10760 -- Now we can freeze the corresponding record. This needs manually
10761 -- freezing, since it is really part of the task type, and the task
10762 -- type is frozen at this stage. We of course need the initialization
10763 -- procedure for this corresponding record type and we won't get it
10764 -- in time if we don't freeze now.
10767 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
10769 if Is_Non_Empty_List (L) then
10770 Insert_List_After (Body_Decl, L);
10775 -- Complete the expansion of access types to the current task type, if
10776 -- any were declared.
10778 Expand_Previous_Access_Type (Tasktyp);
10780 -- Create wrappers for entries that have pre/postconditions
10786 Ent := First_Entity (Tasktyp);
10787 while Present (Ent) loop
10788 if Ekind_In (Ent, E_Entry, E_Entry_Family)
10789 and then Present (Spec_PPC_List (Ent))
10791 Build_PPC_Wrapper (Ent, N);
10797 end Expand_N_Task_Type_Declaration;
10799 -------------------------------
10800 -- Expand_N_Timed_Entry_Call --
10801 -------------------------------
10803 -- A timed entry call in normal case is not implemented using ATC mechanism
10804 -- anymore for efficiency reason.
10814 -- is expanded as follow:
10816 -- 1) When T.E is a task entry_call;
10820 -- X : Task_Entry_Index := <entry index>;
10821 -- DX : Duration := To_Duration (D);
10822 -- M : Delay_Mode := <discriminant>;
10823 -- P : parms := (parm, parm, parm);
10826 -- Timed_Protected_Entry_Call
10827 -- (<acceptor-task>, X, P'Address, DX, M, B);
10835 -- 2) When T.E is a protected entry_call;
10839 -- X : Protected_Entry_Index := <entry index>;
10840 -- DX : Duration := To_Duration (D);
10841 -- M : Delay_Mode := <discriminant>;
10842 -- P : parms := (parm, parm, parm);
10845 -- Timed_Protected_Entry_Call
10846 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10854 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10857 -- B : Boolean := False;
10858 -- C : Ada.Tags.Prim_Op_Kind;
10859 -- DX : Duration := To_Duration (D)
10860 -- K : Ada.Tags.Tagged_Kind :=
10861 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10862 -- M : Integer :=...;
10863 -- P : Parameters := (Param1 .. ParamN);
10867 -- if K = Ada.Tags.TK_Limited_Tagged then
10868 -- <dispatching-call>;
10869 -- <triggering-statements>
10873 -- Ada.Tags.Get_Offset_Index
10874 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10876 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10878 -- if C = POK_Protected_Entry
10879 -- or else C = POK_Task_Entry
10881 -- Param1 := P.Param1;
10883 -- ParamN := P.ParamN;
10887 -- if C = POK_Procedure
10888 -- or else C = POK_Protected_Procedure
10889 -- or else C = POK_Task_Procedure
10891 -- <dispatching-call>;
10894 -- <triggering-statements>
10896 -- <timed-statements>
10901 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10902 Loc : constant Source_Ptr := Sloc (N);
10904 E_Call : Node_Id :=
10905 Entry_Call_Statement (Entry_Call_Alternative (N));
10906 E_Stats : constant List_Id :=
10907 Statements (Entry_Call_Alternative (N));
10908 D_Stat : Node_Id :=
10909 Delay_Statement (Delay_Alternative (N));
10910 D_Stats : constant List_Id :=
10911 Statements (Delay_Alternative (N));
10914 Blk_Typ : Entity_Id;
10916 Call_Ent : Entity_Id;
10917 Conc_Typ_Stmts : List_Id;
10921 D_Type : Entity_Id;
10927 Is_Disp_Select : Boolean;
10928 Lim_Typ_Stmts : List_Id;
10937 B : Entity_Id; -- Call status flag
10938 C : Entity_Id; -- Call kind
10939 D : Entity_Id; -- Delay
10940 K : Entity_Id; -- Tagged kind
10941 M : Entity_Id; -- Delay mode
10942 P : Entity_Id; -- Parameter block
10943 S : Entity_Id; -- Primitive operation slot
10946 -- Under the Ravenscar profile, timed entry calls are excluded. An error
10947 -- was already reported on spec, so do not attempt to expand the call.
10949 if Restriction_Active (No_Select_Statements) then
10953 -- The arguments in the call may require dynamic allocation, and the
10954 -- call statement may have been transformed into a block. The block
10955 -- may contain additional declarations for internal entities, and the
10956 -- original call is found by sequential search.
10958 if Nkind (E_Call) = N_Block_Statement then
10959 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
10960 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
10961 N_Entry_Call_Statement)
10968 Ada_Version >= Ada_2005
10969 and then Nkind (E_Call) = N_Procedure_Call_Statement;
10971 if Is_Disp_Select then
10972 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
10978 -- B : Boolean := False;
10980 B := Build_B (Loc, Decls);
10983 -- C : Ada.Tags.Prim_Op_Kind;
10985 C := Build_C (Loc, Decls);
10987 -- Because the analysis of all statements was disabled, manually
10988 -- analyze the delay statement.
10991 D_Stat := Original_Node (D_Stat);
10994 -- Build an entry call using Simple_Entry_Call
10996 Extract_Entry (E_Call, Concval, Ename, Index);
10997 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
10999 Decls := Declarations (E_Call);
11000 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11009 B := Make_Defining_Identifier (Loc, Name_uB);
11012 Make_Object_Declaration (Loc,
11013 Defining_Identifier =>
11015 Object_Definition =>
11016 New_Reference_To (Standard_Boolean, Loc)));
11019 -- Duration and mode processing
11021 D_Type := Base_Type (Etype (Expression (D_Stat)));
11023 -- Use the type of the delay expression (Calendar or Real_Time) to
11024 -- generate the appropriate conversion.
11026 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11027 D_Disc := Make_Integer_Literal (Loc, 0);
11028 D_Conv := Relocate_Node (Expression (D_Stat));
11030 elsif Is_RTE (D_Type, RO_CA_Time) then
11031 D_Disc := Make_Integer_Literal (Loc, 1);
11032 D_Conv := Make_Function_Call (Loc,
11033 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11034 New_List (New_Copy (Expression (D_Stat))));
11036 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11037 D_Disc := Make_Integer_Literal (Loc, 2);
11038 D_Conv := Make_Function_Call (Loc,
11039 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11040 New_List (New_Copy (Expression (D_Stat))));
11043 D := Make_Temporary (Loc, 'D');
11049 Make_Object_Declaration (Loc,
11050 Defining_Identifier =>
11052 Object_Definition =>
11053 New_Reference_To (Standard_Duration, Loc)));
11055 M := Make_Temporary (Loc, 'M');
11058 -- M : Integer := (0 | 1 | 2);
11061 Make_Object_Declaration (Loc,
11062 Defining_Identifier =>
11064 Object_Definition =>
11065 New_Reference_To (Standard_Integer, Loc),
11069 -- Do the assignment at this stage only because the evaluation of the
11070 -- expression must not occur before (see ACVC C97302A).
11073 Make_Assignment_Statement (Loc,
11075 New_Reference_To (D, Loc),
11079 -- Parameter block processing
11081 -- Manually create the parameter block for dispatching calls. In the
11082 -- case of entries, the block has already been created during the call
11083 -- to Build_Simple_Entry_Call.
11085 if Is_Disp_Select then
11087 -- Tagged kind processing, generate:
11088 -- K : Ada.Tags.Tagged_Kind :=
11089 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11091 K := Build_K (Loc, Decls, Obj);
11093 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11094 P := Parameter_Block_Pack
11095 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11097 -- Dispatch table slot processing, generate:
11100 S := Build_S (Loc, Decls);
11103 -- S := Ada.Tags.Get_Offset_Index
11104 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11107 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11110 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11112 -- where Obj is the controlling formal parameter, S is the dispatch
11113 -- table slot number of the dispatching operation, P is the wrapped
11114 -- parameter block, D is the duration, M is the duration mode, C is
11115 -- the call kind and B is the call status.
11117 Params := New_List;
11119 Append_To (Params, New_Copy_Tree (Obj));
11120 Append_To (Params, New_Reference_To (S, Loc));
11121 Append_To (Params, Make_Attribute_Reference (Loc,
11122 Prefix => New_Reference_To (P, Loc),
11123 Attribute_Name => Name_Address));
11124 Append_To (Params, New_Reference_To (D, Loc));
11125 Append_To (Params, New_Reference_To (M, Loc));
11126 Append_To (Params, New_Reference_To (C, Loc));
11127 Append_To (Params, New_Reference_To (B, Loc));
11129 Append_To (Conc_Typ_Stmts,
11130 Make_Procedure_Call_Statement (Loc,
11133 Find_Prim_Op (Etype (Etype (Obj)),
11134 Name_uDisp_Timed_Select),
11136 Parameter_Associations =>
11140 -- if C = POK_Protected_Entry
11141 -- or else C = POK_Task_Entry
11143 -- Param1 := P.Param1;
11145 -- ParamN := P.ParamN;
11148 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11150 -- Generate the if statement only when the packed parameters need
11151 -- explicit assignments to their corresponding actuals.
11153 if Present (Unpack) then
11154 Append_To (Conc_Typ_Stmts,
11155 Make_If_Statement (Loc,
11162 New_Reference_To (C, Loc),
11164 New_Reference_To (RTE (
11165 RE_POK_Protected_Entry), Loc)),
11169 New_Reference_To (C, Loc),
11171 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11180 -- if C = POK_Procedure
11181 -- or else C = POK_Protected_Procedure
11182 -- or else C = POK_Task_Procedure
11184 -- <dispatching-call>
11186 -- <triggering-statements>
11188 -- <timed-statements>
11191 N_Stats := New_Copy_List_Tree (E_Stats);
11193 Prepend_To (N_Stats,
11194 Make_If_Statement (Loc,
11201 New_Reference_To (C, Loc),
11203 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11209 New_Reference_To (C, Loc),
11211 New_Reference_To (RTE (
11212 RE_POK_Protected_Procedure), Loc)),
11216 New_Reference_To (C, Loc),
11218 New_Reference_To (RTE (
11219 RE_POK_Task_Procedure), Loc)))),
11222 New_List (E_Call)));
11224 Append_To (Conc_Typ_Stmts,
11225 Make_If_Statement (Loc,
11226 Condition => New_Reference_To (B, Loc),
11227 Then_Statements => N_Stats,
11228 Else_Statements => D_Stats));
11231 -- <dispatching-call>;
11232 -- <triggering-statements>
11234 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
11235 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11238 -- if K = Ada.Tags.TK_Limited_Tagged then
11245 Make_If_Statement (Loc,
11249 New_Reference_To (K, Loc),
11251 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11260 -- Skip assignments to temporaries created for in-out parameters.
11261 -- This makes unwarranted assumptions about the shape of the expanded
11262 -- tree for the call, and should be cleaned up ???
11264 Stmt := First (Stmts);
11265 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11269 -- Do the assignment at this stage only because the evaluation
11270 -- of the expression must not occur before (see ACVC C97302A).
11272 Insert_Before (Stmt,
11273 Make_Assignment_Statement (Loc,
11274 Name => New_Reference_To (D, Loc),
11275 Expression => D_Conv));
11278 Params := Parameter_Associations (Call);
11280 -- For a protected type, we build a Timed_Protected_Entry_Call
11282 if Is_Protected_Type (Etype (Concval)) then
11284 -- Create a new call statement
11286 Param := First (Params);
11287 while Present (Param)
11288 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11293 Dummy := Remove_Next (Next (Param));
11295 -- Remove garbage is following the Cancel_Param if present
11297 Dummy := Next (Param);
11299 -- Remove the mode of the Protected_Entry_Call call, then remove
11300 -- the Communication_Block of the Protected_Entry_Call call, and
11301 -- finally add Duration and a Delay_Mode parameter
11303 pragma Assert (Present (Param));
11304 Rewrite (Param, New_Reference_To (D, Loc));
11306 Rewrite (Dummy, New_Reference_To (M, Loc));
11308 -- Add a Boolean flag for successful entry call
11310 Append_To (Params, New_Reference_To (B, Loc));
11312 case Corresponding_Runtime_Package (Etype (Concval)) is
11313 when System_Tasking_Protected_Objects_Entries =>
11315 Make_Procedure_Call_Statement (Loc,
11318 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11319 Parameter_Associations => Params));
11321 when System_Tasking_Protected_Objects_Single_Entry =>
11322 Param := First (Params);
11323 while Present (Param)
11325 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11333 Make_Procedure_Call_Statement (Loc,
11334 Name => New_Reference_To (
11335 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11336 Parameter_Associations => Params));
11339 raise Program_Error;
11342 -- For the task case, build a Timed_Task_Entry_Call
11345 -- Create a new call statement
11347 Append_To (Params, New_Reference_To (D, Loc));
11348 Append_To (Params, New_Reference_To (M, Loc));
11349 Append_To (Params, New_Reference_To (B, Loc));
11352 Make_Procedure_Call_Statement (Loc,
11354 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11355 Parameter_Associations => Params));
11359 Make_Implicit_If_Statement (N,
11360 Condition => New_Reference_To (B, Loc),
11361 Then_Statements => E_Stats,
11362 Else_Statements => D_Stats));
11366 Make_Block_Statement (Loc,
11367 Declarations => Decls,
11368 Handled_Statement_Sequence =>
11369 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11372 end Expand_N_Timed_Entry_Call;
11374 ----------------------------------------
11375 -- Expand_Protected_Body_Declarations --
11376 ----------------------------------------
11378 procedure Expand_Protected_Body_Declarations
11380 Spec_Id : Entity_Id)
11383 if No_Run_Time_Mode then
11384 Error_Msg_CRT ("protected body", N);
11387 elsif Expander_Active then
11389 -- Associate discriminals with the first subprogram or entry body to
11392 if Present (First_Protected_Operation (Declarations (N))) then
11393 Set_Discriminals (Parent (Spec_Id));
11396 end Expand_Protected_Body_Declarations;
11398 -------------------------
11399 -- External_Subprogram --
11400 -------------------------
11402 function External_Subprogram (E : Entity_Id) return Entity_Id is
11403 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11406 -- The internal and external subprograms follow each other on the entity
11407 -- chain. Note that previously private operations had no separate
11408 -- external subprogram. We now create one in all cases, because a
11409 -- private operation may actually appear in an external call, through
11410 -- a 'Access reference used for a callback.
11412 -- If the operation is a function that returns an anonymous access type,
11413 -- the corresponding itype appears before the operation, and must be
11416 -- This mechanism is fragile, there should be a real link between the
11417 -- two versions of the operation, but there is no place to put it ???
11419 if Is_Access_Type (Next_Entity (Subp)) then
11420 return Next_Entity (Next_Entity (Subp));
11422 return Next_Entity (Subp);
11424 end External_Subprogram;
11426 ------------------------------
11427 -- Extract_Dispatching_Call --
11428 ------------------------------
11430 procedure Extract_Dispatching_Call
11432 Call_Ent : out Entity_Id;
11433 Object : out Entity_Id;
11434 Actuals : out List_Id;
11435 Formals : out List_Id)
11437 Call_Nam : Node_Id;
11440 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11442 if Present (Original_Node (N)) then
11443 Call_Nam := Name (Original_Node (N));
11445 Call_Nam := Name (N);
11448 -- Retrieve the name of the dispatching procedure. It contains the
11449 -- dispatch table slot number.
11452 case Nkind (Call_Nam) is
11453 when N_Identifier =>
11456 when N_Selected_Component =>
11457 Call_Nam := Selector_Name (Call_Nam);
11460 raise Program_Error;
11465 Actuals := Parameter_Associations (N);
11466 Call_Ent := Entity (Call_Nam);
11467 Formals := Parameter_Specifications (Parent (Call_Ent));
11468 Object := First (Actuals);
11470 if Present (Original_Node (Object)) then
11471 Object := Original_Node (Object);
11473 end Extract_Dispatching_Call;
11475 -------------------
11476 -- Extract_Entry --
11477 -------------------
11479 procedure Extract_Entry
11481 Concval : out Node_Id;
11482 Ename : out Node_Id;
11483 Index : out Node_Id)
11485 Nam : constant Node_Id := Name (N);
11488 -- For a simple entry, the name is a selected component, with the
11489 -- prefix being the task value, and the selector being the entry.
11491 if Nkind (Nam) = N_Selected_Component then
11492 Concval := Prefix (Nam);
11493 Ename := Selector_Name (Nam);
11496 -- For a member of an entry family, the name is an indexed component
11497 -- where the prefix is a selected component, whose prefix in turn is
11498 -- the task value, and whose selector is the entry family. The single
11499 -- expression in the expressions list of the indexed component is the
11500 -- subscript for the family.
11502 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11503 Concval := Prefix (Prefix (Nam));
11504 Ename := Selector_Name (Prefix (Nam));
11505 Index := First (Expressions (Nam));
11509 -------------------
11510 -- Family_Offset --
11511 -------------------
11513 function Family_Offset
11518 Cap : Boolean) return Node_Id
11524 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11525 -- If one of the bounds is a reference to a discriminant, replace with
11526 -- corresponding discriminal of type. Within the body of a task retrieve
11527 -- the renamed discriminant by simple visibility, using its generated
11528 -- name. Within a protected object, find the original discriminant and
11529 -- replace it with the discriminal of the current protected operation.
11531 ------------------------------
11532 -- Convert_Discriminant_Ref --
11533 ------------------------------
11535 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11536 Loc : constant Source_Ptr := Sloc (Bound);
11541 if Is_Entity_Name (Bound)
11542 and then Ekind (Entity (Bound)) = E_Discriminant
11544 if Is_Task_Type (Ttyp)
11545 and then Has_Completion (Ttyp)
11547 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11548 Find_Direct_Name (B);
11550 elsif Is_Protected_Type (Ttyp) then
11551 D := First_Discriminant (Ttyp);
11552 while Chars (D) /= Chars (Entity (Bound)) loop
11553 Next_Discriminant (D);
11556 B := New_Reference_To (Discriminal (D), Loc);
11559 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11562 elsif Nkind (Bound) = N_Attribute_Reference then
11566 B := New_Copy_Tree (Bound);
11570 Make_Attribute_Reference (Loc,
11571 Attribute_Name => Name_Pos,
11572 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11573 Expressions => New_List (B));
11574 end Convert_Discriminant_Ref;
11576 -- Start of processing for Family_Offset
11579 Real_Hi := Convert_Discriminant_Ref (Hi);
11580 Real_Lo := Convert_Discriminant_Ref (Lo);
11583 if Is_Task_Type (Ttyp) then
11584 Ityp := RTE (RE_Task_Entry_Index);
11586 Ityp := RTE (RE_Protected_Entry_Index);
11590 Make_Attribute_Reference (Loc,
11591 Prefix => New_Reference_To (Ityp, Loc),
11592 Attribute_Name => Name_Min,
11593 Expressions => New_List (
11595 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11598 Make_Attribute_Reference (Loc,
11599 Prefix => New_Reference_To (Ityp, Loc),
11600 Attribute_Name => Name_Max,
11601 Expressions => New_List (
11603 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11606 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11613 function Family_Size
11618 Cap : Boolean) return Node_Id
11623 if Is_Task_Type (Ttyp) then
11624 Ityp := RTE (RE_Task_Entry_Index);
11626 Ityp := RTE (RE_Protected_Entry_Index);
11630 Make_Attribute_Reference (Loc,
11631 Prefix => New_Reference_To (Ityp, Loc),
11632 Attribute_Name => Name_Max,
11633 Expressions => New_List (
11636 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11638 Make_Integer_Literal (Loc, 1)),
11639 Make_Integer_Literal (Loc, 0)));
11642 -----------------------
11643 -- Find_Master_Scope --
11644 -----------------------
11646 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
11650 -- In Ada2005, the master is the innermost enclosing scope that is not
11651 -- transient. If the enclosing block is the rewriting of a call or the
11652 -- scope is an extended return statement this is valid master. The
11653 -- master in an extended return is only used within the return, and is
11654 -- subsequently overwritten in Move_Activation_Chain, but it must exist
11655 -- now before that overwriting occurs.
11659 if Ada_Version >= Ada_2005 then
11660 while Is_Internal (S) loop
11661 if Nkind (Parent (S)) = N_Block_Statement
11663 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
11667 elsif Ekind (S) = E_Return_Statement then
11677 end Find_Master_Scope;
11679 -----------------------------------
11680 -- Find_Task_Or_Protected_Pragma --
11681 -----------------------------------
11683 function Find_Task_Or_Protected_Pragma
11685 P : Name_Id) return Node_Id
11690 N := First (Visible_Declarations (T));
11691 while Present (N) loop
11692 if Nkind (N) = N_Pragma then
11693 if Pragma_Name (N) = P then
11696 elsif P = Name_Priority
11697 and then Pragma_Name (N) = Name_Interrupt_Priority
11710 N := First (Private_Declarations (T));
11711 while Present (N) loop
11712 if Nkind (N) = N_Pragma then
11713 if Pragma_Name (N) = P then
11716 elsif P = Name_Priority
11717 and then Pragma_Name (N) = Name_Interrupt_Priority
11730 raise Program_Error;
11731 end Find_Task_Or_Protected_Pragma;
11733 -------------------------------
11734 -- First_Protected_Operation --
11735 -------------------------------
11737 function First_Protected_Operation (D : List_Id) return Node_Id is
11738 First_Op : Node_Id;
11741 First_Op := First (D);
11742 while Present (First_Op)
11743 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11749 end First_Protected_Operation;
11751 ---------------------------------------
11752 -- Install_Private_Data_Declarations --
11753 ---------------------------------------
11755 procedure Install_Private_Data_Declarations
11757 Spec_Id : Entity_Id;
11758 Conc_Typ : Entity_Id;
11759 Body_Nod : Node_Id;
11761 Barrier : Boolean := False;
11762 Family : Boolean := False)
11764 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11767 Insert_Node : Node_Id := Empty;
11768 Obj_Ent : Entity_Id;
11770 procedure Add (Decl : Node_Id);
11771 -- Add a single declaration after Insert_Node. If this is the first
11772 -- addition, Decl is added to the front of Decls and it becomes the
11775 function Replace_Bound (Bound : Node_Id) return Node_Id;
11776 -- The bounds of an entry index may depend on discriminants, create a
11777 -- reference to the corresponding prival. Otherwise return a duplicate
11778 -- of the original bound.
11784 procedure Add (Decl : Node_Id) is
11786 if No (Insert_Node) then
11787 Prepend_To (Decls, Decl);
11789 Insert_After (Insert_Node, Decl);
11792 Insert_Node := Decl;
11795 --------------------------
11796 -- Replace_Discriminant --
11797 --------------------------
11799 function Replace_Bound (Bound : Node_Id) return Node_Id is
11801 if Nkind (Bound) = N_Identifier
11802 and then Is_Discriminal (Entity (Bound))
11804 return Make_Identifier (Loc, Chars (Entity (Bound)));
11806 return Duplicate_Subexpr (Bound);
11810 -- Start of processing for Install_Private_Data_Declarations
11813 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11814 -- formal parameter _O, _object or _task depending on the context.
11816 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11818 -- Special processing of _O for barrier functions, protected entries
11825 (Ekind (Spec_Id) = E_Entry
11826 or else Ekind (Spec_Id) = E_Entry_Family))
11829 Conc_Rec : constant Entity_Id :=
11830 Corresponding_Record_Type (Conc_Typ);
11831 Typ_Id : constant Entity_Id :=
11832 Make_Defining_Identifier (Loc,
11833 New_External_Name (Chars (Conc_Rec), 'P'));
11836 -- type prot_typVP is access prot_typV;
11839 Make_Full_Type_Declaration (Loc,
11840 Defining_Identifier => Typ_Id,
11842 Make_Access_To_Object_Definition (Loc,
11843 Subtype_Indication =>
11844 New_Reference_To (Conc_Rec, Loc)));
11848 -- _object : prot_typVP := prot_typV (_O);
11851 Make_Object_Declaration (Loc,
11852 Defining_Identifier =>
11853 Make_Defining_Identifier (Loc, Name_uObject),
11854 Object_Definition => New_Reference_To (Typ_Id, Loc),
11856 Unchecked_Convert_To (Typ_Id,
11857 New_Reference_To (Obj_Ent, Loc)));
11860 -- Set the reference to the concurrent object
11862 Obj_Ent := Defining_Identifier (Decl);
11866 -- Step 2: Create the Protection object and build its declaration for
11867 -- any protected entry (family) of subprogram.
11869 if Is_Protected then
11871 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
11875 Set_Protection_Object (Spec_Id, Prot_Ent);
11877 -- Determine the proper protection type
11879 if Has_Attach_Handler (Conc_Typ)
11880 and then not Restricted_Profile
11882 Prot_Typ := RE_Static_Interrupt_Protection;
11884 elsif Has_Interrupt_Handler (Conc_Typ) then
11885 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11887 -- The type has explicit entries or generated primitive entry
11890 elsif Has_Entries (Conc_Typ)
11892 (Ada_Version >= Ada_2005
11893 and then Present (Interface_List (Parent (Conc_Typ))))
11895 case Corresponding_Runtime_Package (Conc_Typ) is
11896 when System_Tasking_Protected_Objects_Entries =>
11897 Prot_Typ := RE_Protection_Entries;
11899 when System_Tasking_Protected_Objects_Single_Entry =>
11900 Prot_Typ := RE_Protection_Entry;
11903 raise Program_Error;
11907 Prot_Typ := RE_Protection;
11911 -- conc_typR : protection_typ renames _object._object;
11914 Make_Object_Renaming_Declaration (Loc,
11915 Defining_Identifier => Prot_Ent,
11917 New_Reference_To (RTE (Prot_Typ), Loc),
11919 Make_Selected_Component (Loc,
11921 New_Reference_To (Obj_Ent, Loc),
11923 Make_Identifier (Loc, Name_uObject)));
11928 -- Step 3: Add discriminant renamings (if any)
11930 if Has_Discriminants (Conc_Typ) then
11935 D := First_Discriminant (Conc_Typ);
11936 while Present (D) loop
11938 -- Adjust the source location
11940 Set_Sloc (Discriminal (D), Loc);
11943 -- discr_name : discr_typ renames _object.discr_name;
11945 -- discr_name : discr_typ renames _task.discr_name;
11948 Make_Object_Renaming_Declaration (Loc,
11949 Defining_Identifier => Discriminal (D),
11950 Subtype_Mark => New_Reference_To (Etype (D), Loc),
11952 Make_Selected_Component (Loc,
11953 Prefix => New_Reference_To (Obj_Ent, Loc),
11954 Selector_Name => Make_Identifier (Loc, Chars (D))));
11957 Next_Discriminant (D);
11962 -- Step 4: Add private component renamings (if any)
11964 if Is_Protected then
11965 Def := Protected_Definition (Parent (Conc_Typ));
11967 if Present (Private_Declarations (Def)) then
11970 Comp_Id : Entity_Id;
11971 Decl_Id : Entity_Id;
11974 Comp := First (Private_Declarations (Def));
11975 while Present (Comp) loop
11976 if Nkind (Comp) = N_Component_Declaration then
11977 Comp_Id := Defining_Identifier (Comp);
11979 Make_Defining_Identifier (Loc, Chars (Comp_Id));
11981 -- Minimal decoration
11983 if Ekind (Spec_Id) = E_Function then
11984 Set_Ekind (Decl_Id, E_Constant);
11986 Set_Ekind (Decl_Id, E_Variable);
11989 Set_Prival (Comp_Id, Decl_Id);
11990 Set_Prival_Link (Decl_Id, Comp_Id);
11991 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
11994 -- comp_name : comp_typ renames _object.comp_name;
11997 Make_Object_Renaming_Declaration (Loc,
11998 Defining_Identifier => Decl_Id,
12000 New_Reference_To (Etype (Comp_Id), Loc),
12002 Make_Selected_Component (Loc,
12004 New_Reference_To (Obj_Ent, Loc),
12006 Make_Identifier (Loc, Chars (Comp_Id))));
12016 -- Step 5: Add the declaration of the entry index and the associated
12017 -- type for barrier functions and entry families.
12019 if (Barrier and then Family)
12020 or else Ekind (Spec_Id) = E_Entry_Family
12023 E : constant Entity_Id := Index_Object (Spec_Id);
12024 Index : constant Entity_Id :=
12025 Defining_Identifier (
12026 Entry_Index_Specification (
12027 Entry_Body_Formal_Part (Body_Nod)));
12028 Index_Con : constant Entity_Id :=
12029 Make_Defining_Identifier (Loc, Chars (Index));
12031 Index_Typ : Entity_Id;
12035 -- Minimal decoration
12037 Set_Ekind (Index_Con, E_Constant);
12038 Set_Entry_Index_Constant (Index, Index_Con);
12039 Set_Discriminal_Link (Index_Con, Index);
12041 -- Retrieve the bounds of the entry family
12043 High := Type_High_Bound (Etype (Index));
12044 Low := Type_Low_Bound (Etype (Index));
12046 -- In the simple case the entry family is given by a subtype
12047 -- mark and the index constant has the same type.
12049 if Is_Entity_Name (Original_Node (
12050 Discrete_Subtype_Definition (Parent (Index))))
12052 Index_Typ := Etype (Index);
12054 -- Otherwise a new subtype declaration is required
12057 High := Replace_Bound (High);
12058 Low := Replace_Bound (Low);
12060 Index_Typ := Make_Temporary (Loc, 'J');
12063 -- subtype Jnn is <Etype of Index> range Low .. High;
12066 Make_Subtype_Declaration (Loc,
12067 Defining_Identifier => Index_Typ,
12068 Subtype_Indication =>
12069 Make_Subtype_Indication (Loc,
12071 New_Reference_To (Base_Type (Etype (Index)), Loc),
12073 Make_Range_Constraint (Loc,
12074 Range_Expression =>
12075 Make_Range (Loc, Low, High))));
12079 Set_Etype (Index_Con, Index_Typ);
12081 -- Create the object which designates the index:
12082 -- J : constant Jnn :=
12083 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12085 -- where Jnn is the subtype created above or the original type of
12086 -- the index, _E is a formal of the protected body subprogram and
12087 -- <index expr> is the index of the first family member.
12090 Make_Object_Declaration (Loc,
12091 Defining_Identifier => Index_Con,
12092 Constant_Present => True,
12093 Object_Definition =>
12094 New_Reference_To (Index_Typ, Loc),
12097 Make_Attribute_Reference (Loc,
12099 New_Reference_To (Index_Typ, Loc),
12100 Attribute_Name => Name_Val,
12102 Expressions => New_List (
12106 Make_Op_Subtract (Loc,
12108 New_Reference_To (E, Loc),
12110 Entry_Index_Expression (Loc,
12111 Defining_Identifier (Body_Nod),
12115 Make_Attribute_Reference (Loc,
12117 New_Reference_To (Index_Typ, Loc),
12118 Attribute_Name => Name_Pos,
12119 Expressions => New_List (
12120 Make_Attribute_Reference (Loc,
12122 New_Reference_To (Index_Typ, Loc),
12123 Attribute_Name => Name_First)))))));
12127 end Install_Private_Data_Declarations;
12129 ---------------------------------
12130 -- Is_Potentially_Large_Family --
12131 ---------------------------------
12133 function Is_Potentially_Large_Family
12134 (Base_Index : Entity_Id;
12135 Conctyp : Entity_Id;
12137 Hi : Node_Id) return Boolean
12140 return Scope (Base_Index) = Standard_Standard
12141 and then Base_Index = Base_Type (Standard_Integer)
12142 and then Has_Discriminants (Conctyp)
12144 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12146 (Denotes_Discriminant (Lo, True)
12147 or else Denotes_Discriminant (Hi, True));
12148 end Is_Potentially_Large_Family;
12150 -------------------------------------
12151 -- Is_Private_Primitive_Subprogram --
12152 -------------------------------------
12154 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12157 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12158 and then Is_Private_Primitive (Id);
12159 end Is_Private_Primitive_Subprogram;
12165 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12166 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12167 Formal : Entity_Id;
12170 Formal := First_Formal (Bod_Subp);
12171 while Present (Formal) loop
12173 -- Look for formal parameter _E
12175 if Chars (Formal) = Name_uE then
12179 Next_Formal (Formal);
12182 -- A protected body subprogram should always have the parameter in
12185 raise Program_Error;
12188 --------------------------------
12189 -- Make_Initialize_Protection --
12190 --------------------------------
12192 function Make_Initialize_Protection
12193 (Protect_Rec : Entity_Id) return List_Id
12195 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12199 Ptyp : constant Node_Id :=
12200 Corresponding_Concurrent_Type (Protect_Rec);
12202 L : constant List_Id := New_List;
12203 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12204 Restricted : constant Boolean := Restricted_Profile;
12207 -- We may need two calls to properly initialize the object, one to
12208 -- Initialize_Protection, and possibly one to Install_Handlers if we
12209 -- have a pragma Attach_Handler.
12211 -- Get protected declaration. In the case of a task type declaration,
12212 -- this is simply the parent of the protected type entity. In the single
12213 -- protected object declaration, this parent will be the implicit type,
12214 -- and we can find the corresponding single protected object declaration
12215 -- by searching forward in the declaration list in the tree.
12217 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12218 -- of this type should have been removed during semantic analysis.
12220 Pdec := Parent (Ptyp);
12221 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12222 N_Single_Protected_Declaration)
12227 -- Now we can find the object definition from this declaration
12229 Pdef := Protected_Definition (Pdec);
12231 -- Build the parameter list for the call. Note that _Init is the name
12232 -- of the formal for the object to be initialized, which is the task
12233 -- value record itself.
12237 -- Object parameter. This is a pointer to the object of type
12238 -- Protection used by the GNARL to control the protected object.
12241 Make_Attribute_Reference (Loc,
12243 Make_Selected_Component (Loc,
12244 Prefix => Make_Identifier (Loc, Name_uInit),
12245 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12246 Attribute_Name => Name_Unchecked_Access));
12248 -- Priority parameter. Set to Unspecified_Priority unless there is a
12249 -- priority pragma, in which case we take the value from the pragma,
12250 -- or there is an interrupt pragma and no priority pragma, and we
12251 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12252 -- defined value, see D.3(10).
12255 and then Has_Pragma_Priority (Pdef)
12258 Prio : constant Node_Id :=
12261 (Pragma_Argument_Associations
12262 (Find_Task_Or_Protected_Pragma
12263 (Pdef, Name_Priority))));
12267 -- If priority is a static expression, then we can duplicate it
12268 -- with no problem and simply append it to the argument list.
12270 if Is_Static_Expression (Prio) then
12272 Duplicate_Subexpr_No_Checks (Prio));
12274 -- Otherwise, the priority may be a per-object expression, if it
12275 -- depends on a discriminant of the type. In this case, create
12276 -- local variable to capture the expression. Note that it is
12277 -- really necessary to create this variable explicitly. It might
12278 -- be thought that removing side effects would the appropriate
12279 -- approach, but that could generate declarations improperly
12280 -- placed in the enclosing scope.
12282 -- Note: Use System.Any_Priority as the expected type for the
12283 -- non-static priority expression, in case the expression has not
12284 -- been analyzed yet (as occurs for example with pragma
12285 -- Interrupt_Priority).
12288 Temp := Make_Temporary (Loc, 'R', Prio);
12290 Make_Object_Declaration (Loc,
12291 Defining_Identifier => Temp,
12292 Object_Definition =>
12293 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12294 Expression => Relocate_Node (Prio)));
12296 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12300 -- When no priority is specified but an xx_Handler pragma is, we default
12301 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12303 elsif Has_Interrupt_Handler (Ptyp)
12304 or else Has_Attach_Handler (Ptyp)
12307 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12309 -- Normal case, no priority or xx_Handler specified, default priority
12313 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12316 -- Test for Compiler_Info parameter. This parameter allows entry body
12317 -- procedures and barrier functions to be called from the runtime. It
12318 -- is a pointer to the record generated by the compiler to represent
12319 -- the protected object.
12322 or else Has_Interrupt_Handler (Ptyp)
12323 or else Has_Attach_Handler (Ptyp)
12324 or else Has_Interfaces (Protect_Rec)
12327 Pkg_Id : constant RTU_Id :=
12328 Corresponding_Runtime_Package (Ptyp);
12329 Called_Subp : RE_Id;
12333 when System_Tasking_Protected_Objects_Entries =>
12334 Called_Subp := RE_Initialize_Protection_Entries;
12336 when System_Tasking_Protected_Objects =>
12337 Called_Subp := RE_Initialize_Protection;
12339 when System_Tasking_Protected_Objects_Single_Entry =>
12340 Called_Subp := RE_Initialize_Protection_Entry;
12343 raise Program_Error;
12346 if Has_Entry or else not Restricted then
12348 Make_Attribute_Reference (Loc,
12349 Prefix => Make_Identifier (Loc, Name_uInit),
12350 Attribute_Name => Name_Address));
12353 -- Entry_Bodies parameter. This is a pointer to an array of
12354 -- pointers to the entry body procedures and barrier functions of
12355 -- the object. If the protected type has no entries this object
12356 -- will not exist, in this case, pass a null.
12359 P_Arr := Entry_Bodies_Array (Ptyp);
12362 Make_Attribute_Reference (Loc,
12363 Prefix => New_Reference_To (P_Arr, Loc),
12364 Attribute_Name => Name_Unrestricted_Access));
12366 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12368 -- Find index mapping function (clumsy but ok for now)
12370 while Ekind (P_Arr) /= E_Function loop
12371 Next_Entity (P_Arr);
12375 Make_Attribute_Reference (Loc,
12377 New_Reference_To (P_Arr, Loc),
12378 Attribute_Name => Name_Unrestricted_Access));
12380 -- Build_Entry_Names generation flag. When set to true, the
12381 -- runtime will allocate an array to hold the string names
12382 -- of protected entries.
12384 if not Restricted_Profile then
12385 if Entry_Names_OK then
12387 New_Reference_To (Standard_True, Loc));
12390 New_Reference_To (Standard_False, Loc));
12395 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12396 Append_To (Args, Make_Null (Loc));
12398 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12399 Append_To (Args, Make_Null (Loc));
12400 Append_To (Args, Make_Null (Loc));
12401 Append_To (Args, New_Reference_To (Standard_False, Loc));
12405 Make_Procedure_Call_Statement (Loc,
12406 Name => New_Reference_To (RTE (Called_Subp), Loc),
12407 Parameter_Associations => Args));
12411 Make_Procedure_Call_Statement (Loc,
12412 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12413 Parameter_Associations => Args));
12416 if Has_Attach_Handler (Ptyp) then
12418 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12419 -- make the following call:
12421 -- Install_Handlers (_object,
12422 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12424 -- or, in the case of Ravenscar:
12426 -- Install_Restricted_Handlers
12427 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12430 Args : constant List_Id := New_List;
12431 Table : constant List_Id := New_List;
12432 Ritem : Node_Id := First_Rep_Item (Ptyp);
12435 -- Build the Attach_Handler table argument
12437 while Present (Ritem) loop
12438 if Nkind (Ritem) = N_Pragma
12439 and then Pragma_Name (Ritem) = Name_Attach_Handler
12442 Handler : constant Node_Id :=
12443 First (Pragma_Argument_Associations (Ritem));
12445 Interrupt : constant Node_Id := Next (Handler);
12446 Expr : constant Node_Id := Expression (Interrupt);
12450 Make_Aggregate (Loc, Expressions => New_List (
12451 Unchecked_Convert_To
12452 (RTE (RE_System_Interrupt_Id), Expr),
12453 Make_Attribute_Reference (Loc,
12454 Prefix => Make_Selected_Component (Loc,
12455 Make_Identifier (Loc, Name_uInit),
12456 Duplicate_Subexpr_No_Checks
12457 (Expression (Handler))),
12458 Attribute_Name => Name_Access))));
12462 Next_Rep_Item (Ritem);
12465 -- Append the table argument we just built
12467 Append_To (Args, Make_Aggregate (Loc, Table));
12469 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12470 -- call to the statements.
12473 -- Call a simplified version of Install_Handlers to be used
12474 -- when the Ravenscar restrictions are in effect
12475 -- (Install_Restricted_Handlers).
12478 Make_Procedure_Call_Statement (Loc,
12481 (RTE (RE_Install_Restricted_Handlers), Loc),
12482 Parameter_Associations => Args));
12485 -- First, prepends the _object argument
12488 Make_Attribute_Reference (Loc,
12490 Make_Selected_Component (Loc,
12491 Prefix => Make_Identifier (Loc, Name_uInit),
12492 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12493 Attribute_Name => Name_Unchecked_Access));
12495 -- Then, insert call to Install_Handlers
12498 Make_Procedure_Call_Statement (Loc,
12499 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
12500 Parameter_Associations => Args));
12506 end Make_Initialize_Protection;
12508 ---------------------------
12509 -- Make_Task_Create_Call --
12510 ---------------------------
12512 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
12513 Loc : constant Source_Ptr := Sloc (Task_Rec);
12523 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
12524 Tnam := Chars (Ttyp);
12526 -- Get task declaration. In the case of a task type declaration, this is
12527 -- simply the parent of the task type entity. In the single task
12528 -- declaration, this parent will be the implicit type, and we can find
12529 -- the corresponding single task declaration by searching forward in the
12530 -- declaration list in the tree.
12532 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12533 -- this type should have been removed during semantic analysis.
12535 Tdec := Parent (Ttyp);
12536 while not Nkind_In (Tdec, N_Task_Type_Declaration,
12537 N_Single_Task_Declaration)
12542 -- Now we can find the task definition from this declaration
12544 Tdef := Task_Definition (Tdec);
12546 -- Build the parameter list for the call. Note that _Init is the name
12547 -- of the formal for the object to be initialized, which is the task
12548 -- value record itself.
12552 -- Priority parameter. Set to Unspecified_Priority unless there is a
12553 -- priority pragma, in which case we take the value from the pragma.
12555 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
12557 Make_Selected_Component (Loc,
12558 Prefix => Make_Identifier (Loc, Name_uInit),
12559 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12562 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12565 -- Optional Stack parameter
12567 if Restricted_Profile then
12569 -- If the stack has been preallocated by the expander then
12570 -- pass its address. Otherwise, pass a null address.
12572 if Preallocated_Stacks_On_Target then
12574 Make_Attribute_Reference (Loc,
12575 Prefix => Make_Selected_Component (Loc,
12576 Prefix => Make_Identifier (Loc, Name_uInit),
12578 Make_Identifier (Loc, Name_uStack)),
12579 Attribute_Name => Name_Address));
12583 New_Reference_To (RTE (RE_Null_Address), Loc));
12587 -- Size parameter. If no Storage_Size pragma is present, then
12588 -- the size is taken from the taskZ variable for the type, which
12589 -- is either Unspecified_Size, or has been reset by the use of
12590 -- a Storage_Size attribute definition clause. If a pragma is
12591 -- present, then the size is taken from the _Size field of the
12592 -- task value record, which was set from the pragma value.
12595 and then Has_Storage_Size_Pragma (Tdef)
12598 Make_Selected_Component (Loc,
12599 Prefix => Make_Identifier (Loc, Name_uInit),
12600 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12604 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12607 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12608 -- Task_Info pragma, in which case we take the value from the pragma.
12611 and then Has_Task_Info_Pragma (Tdef)
12614 Make_Selected_Component (Loc,
12615 Prefix => Make_Identifier (Loc, Name_uInit),
12616 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12620 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12623 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
12624 -- in which case we take the value from the pragma. The parameter is
12625 -- passed as an Integer because in the case of unspecified CPU the
12626 -- value is not in the range of CPU_Range.
12628 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
12630 Convert_To (Standard_Integer,
12631 Make_Selected_Component (Loc,
12632 Prefix => Make_Identifier (Loc, Name_uInit),
12633 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
12637 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
12640 if not Restricted_Profile then
12642 -- Deadline parameter. If no Relative_Deadline pragma is present,
12643 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12644 -- the deadline is taken from the _Relative_Deadline field of the
12645 -- task value record, which was set from the pragma value. Note that
12646 -- this parameter must not be generated for the restricted profiles
12647 -- since Ravenscar does not allow deadlines.
12649 -- Case where pragma Relative_Deadline applies: use given value
12651 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12653 Make_Selected_Component (Loc,
12654 Prefix => Make_Identifier (Loc, Name_uInit),
12656 Make_Identifier (Loc, Name_uRelative_Deadline)));
12658 -- No pragma Relative_Deadline apply to the task
12662 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12665 -- Number of entries. This is an expression of the form:
12667 -- n + _Init.a'Length + _Init.a'B'Length + ...
12669 -- where a,b... are the entry family names for the task definition
12672 Build_Entry_Count_Expression
12677 (Parent (Corresponding_Record_Type (Ttyp))))),
12679 Append_To (Args, Ecount);
12681 -- Master parameter. This is a reference to the _Master parameter of
12682 -- the initialization procedure, except in the case of the pragma
12683 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
12684 -- System.Tasking.Library_Task_Level.
12686 if Restriction_Active (No_Task_Hierarchy) = False then
12687 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12690 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
12694 -- State parameter. This is a pointer to the task body procedure. The
12695 -- required value is obtained by taking 'Unrestricted_Access of the task
12696 -- body procedure and converting it (with an unchecked conversion) to
12697 -- the type required by the task kernel. For further details, see the
12698 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12699 -- than 'Address in order to avoid creating trampolines.
12702 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12703 Subp_Ptr_Typ : constant Node_Id :=
12704 Create_Itype (E_Access_Subprogram_Type, Tdec);
12705 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12708 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12709 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12711 -- Be sure to freeze a reference to the access-to-subprogram type,
12712 -- otherwise gigi will complain that it's in the wrong scope, because
12713 -- it's actually inside the init procedure for the record type that
12714 -- corresponds to the task type.
12716 -- This processing is causing a crash in the .NET/JVM back ends that
12717 -- is not yet understood, so skip it in these cases ???
12719 if VM_Target = No_VM then
12720 Set_Itype (Ref, Subp_Ptr_Typ);
12721 Append_Freeze_Action (Task_Rec, Ref);
12724 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12725 Make_Qualified_Expression (Loc,
12726 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12728 Make_Attribute_Reference (Loc,
12730 New_Occurrence_Of (Body_Proc, Loc),
12731 Attribute_Name => Name_Unrestricted_Access))));
12733 -- For the .NET/JVM cases revert to the original code below ???
12737 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12738 Make_Attribute_Reference (Loc,
12740 New_Occurrence_Of (Body_Proc, Loc),
12741 Attribute_Name => Name_Address)));
12745 -- Discriminants parameter. This is just the address of the task
12746 -- value record itself (which contains the discriminant values
12749 Make_Attribute_Reference (Loc,
12750 Prefix => Make_Identifier (Loc, Name_uInit),
12751 Attribute_Name => Name_Address));
12753 -- Elaborated parameter. This is an access to the elaboration Boolean
12756 Make_Attribute_Reference (Loc,
12757 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12758 Attribute_Name => Name_Unchecked_Access));
12760 -- Chain parameter. This is a reference to the _Chain parameter of
12761 -- the initialization procedure.
12763 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12765 -- Task name parameter. Take this from the _Task_Id parameter to the
12766 -- init call unless there is a Task_Name pragma, in which case we take
12767 -- the value from the pragma.
12770 and then Has_Task_Name_Pragma (Tdef)
12772 -- Copy expression in full, because it may be dynamic and have
12778 (Pragma_Argument_Associations
12779 (Find_Task_Or_Protected_Pragma
12780 (Tdef, Name_Task_Name))))));
12783 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12786 -- Created_Task parameter. This is the _Task_Id field of the task
12790 Make_Selected_Component (Loc,
12791 Prefix => Make_Identifier (Loc, Name_uInit),
12792 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12794 -- Build_Entry_Names generation flag. When set to true, the runtime
12795 -- will allocate an array to hold the string names of task entries.
12797 if not Restricted_Profile then
12798 if Has_Entries (Ttyp)
12799 and then Entry_Names_OK
12801 Append_To (Args, New_Reference_To (Standard_True, Loc));
12803 Append_To (Args, New_Reference_To (Standard_False, Loc));
12807 if Restricted_Profile then
12808 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12810 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12814 Make_Procedure_Call_Statement (Loc,
12816 Parameter_Associations => Args);
12817 end Make_Task_Create_Call;
12819 ------------------------------
12820 -- Next_Protected_Operation --
12821 ------------------------------
12823 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12827 Next_Op := Next (N);
12828 while Present (Next_Op)
12829 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12835 end Next_Protected_Operation;
12837 ---------------------
12838 -- Null_Statements --
12839 ---------------------
12841 function Null_Statements (Stats : List_Id) return Boolean is
12845 Stmt := First (Stats);
12846 while Nkind (Stmt) /= N_Empty
12847 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12849 (Nkind (Stmt) = N_Pragma
12850 and then (Pragma_Name (Stmt) = Name_Unreferenced
12852 Pragma_Name (Stmt) = Name_Unmodified
12854 Pragma_Name (Stmt) = Name_Warnings)))
12859 return Nkind (Stmt) = N_Empty;
12860 end Null_Statements;
12862 --------------------------
12863 -- Parameter_Block_Pack --
12864 --------------------------
12866 function Parameter_Block_Pack
12868 Blk_Typ : Entity_Id;
12872 Stmts : List_Id) return Node_Id
12874 Actual : Entity_Id;
12875 Expr : Node_Id := Empty;
12876 Formal : Entity_Id;
12877 Has_Param : Boolean := False;
12880 Temp_Asn : Node_Id;
12881 Temp_Nam : Node_Id;
12884 Actual := First (Actuals);
12885 Formal := Defining_Identifier (First (Formals));
12886 Params := New_List;
12888 while Present (Actual) loop
12889 if Is_By_Copy_Type (Etype (Actual)) then
12891 -- Jnn : aliased <formal-type>
12893 Temp_Nam := Make_Temporary (Loc, 'J');
12896 Make_Object_Declaration (Loc,
12899 Defining_Identifier =>
12901 Object_Definition =>
12902 New_Reference_To (Etype (Formal), Loc)));
12904 if Ekind (Formal) /= E_Out_Parameter then
12910 New_Reference_To (Temp_Nam, Loc);
12912 Set_Assignment_OK (Temp_Asn);
12915 Make_Assignment_Statement (Loc,
12919 New_Copy_Tree (Actual)));
12923 -- Jnn'unchecked_access
12926 Make_Attribute_Reference (Loc,
12928 Name_Unchecked_Access,
12930 New_Reference_To (Temp_Nam, Loc)));
12934 -- The controlling parameter is omitted
12937 if not Is_Controlling_Actual (Actual) then
12939 Make_Reference (Loc, New_Copy_Tree (Actual)));
12945 Next_Actual (Actual);
12946 Next_Formal_With_Extras (Formal);
12950 Expr := Make_Aggregate (Loc, Params);
12955 -- J1'unchecked_access;
12956 -- <actual2>'reference;
12959 P := Make_Temporary (Loc, 'P');
12962 Make_Object_Declaration (Loc,
12963 Defining_Identifier =>
12965 Object_Definition =>
12966 New_Reference_To (Blk_Typ, Loc),
12971 end Parameter_Block_Pack;
12973 ----------------------------
12974 -- Parameter_Block_Unpack --
12975 ----------------------------
12977 function Parameter_Block_Unpack
12981 Formals : List_Id) return List_Id
12983 Actual : Entity_Id;
12985 Formal : Entity_Id;
12986 Has_Asnmt : Boolean := False;
12987 Result : constant List_Id := New_List;
12990 Actual := First (Actuals);
12991 Formal := Defining_Identifier (First (Formals));
12992 while Present (Actual) loop
12993 if Is_By_Copy_Type (Etype (Actual))
12994 and then Ekind (Formal) /= E_In_Parameter
12997 -- <actual> := P.<formal>;
13000 Make_Assignment_Statement (Loc,
13004 Make_Explicit_Dereference (Loc,
13005 Make_Selected_Component (Loc,
13007 New_Reference_To (P, Loc),
13009 Make_Identifier (Loc, Chars (Formal)))));
13011 Set_Assignment_OK (Name (Asnmt));
13012 Append_To (Result, Asnmt);
13017 Next_Actual (Actual);
13018 Next_Formal_With_Extras (Formal);
13024 return New_List (Make_Null_Statement (Loc));
13026 end Parameter_Block_Unpack;
13028 ----------------------
13029 -- Set_Discriminals --
13030 ----------------------
13032 procedure Set_Discriminals (Dec : Node_Id) is
13035 D_Minal : Entity_Id;
13038 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13039 Pdef := Defining_Identifier (Dec);
13041 if Has_Discriminants (Pdef) then
13042 D := First_Discriminant (Pdef);
13043 while Present (D) loop
13045 Make_Defining_Identifier (Sloc (D),
13046 Chars => New_External_Name (Chars (D), 'D'));
13048 Set_Ekind (D_Minal, E_Constant);
13049 Set_Etype (D_Minal, Etype (D));
13050 Set_Scope (D_Minal, Pdef);
13051 Set_Discriminal (D, D_Minal);
13052 Set_Discriminal_Link (D_Minal, D);
13054 Next_Discriminant (D);
13057 end Set_Discriminals;
13059 -----------------------
13060 -- Trivial_Accept_OK --
13061 -----------------------
13063 function Trivial_Accept_OK return Boolean is
13065 case Opt.Task_Dispatching_Policy is
13067 -- If we have the default task dispatching policy in effect, we can
13068 -- definitely do the optimization (one way of looking at this is to
13069 -- think of the formal definition of the default policy being allowed
13070 -- to run any task it likes after a rendezvous, so even if notionally
13071 -- a full rescheduling occurs, we can say that our dispatching policy
13072 -- (i.e. the default dispatching policy) reorders the queue to be the
13073 -- same as just before the call.
13078 -- FIFO_Within_Priorities certainly does not permit this
13079 -- optimization since the Rendezvous is a scheduling action that may
13080 -- require some other task to be run.
13085 -- For now, disallow the optimization for all other policies. This
13086 -- may be over-conservative, but it is certainly not incorrect.
13092 end Trivial_Accept_OK;