1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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 function Build_Renamed_Formal_Declaration
177 Renamed_Formal : Node_Id) return Node_Id;
178 -- Create a renaming declaration for a formal, within a protected entry
179 -- body or an accept body. The renamed object is a component of the
180 -- parameter block that is a parameter in the entry call.
182 -- In Ada2012, If the formal is an incomplete tagged type, the renaming
183 -- does not dereference the corresponding component to prevent an illegal
184 -- use of the incomplete type (AI05-0151).
186 procedure Build_Wrapper_Bodies
190 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
191 -- record of a concurrent type. N is the insertion node where all bodies
192 -- will be placed. This routine builds the bodies of the subprograms which
193 -- serve as an indirection mechanism to overriding primitives of concurrent
194 -- types, entries and protected procedures. Any new body is analyzed.
196 procedure Build_Wrapper_Specs
200 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
201 -- record of a concurrent type. N is the insertion node where all specs
202 -- will be placed. This routine builds the specs of the subprograms which
203 -- serve as an indirection mechanism to overriding primitives of concurrent
204 -- types, entries and protected procedures. Any new spec is analyzed.
206 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
207 -- Build the function that translates the entry index in the call
208 -- (which depends on the size of entry families) into an index into the
209 -- Entry_Bodies_Array, to determine the body and barrier function used
210 -- in a protected entry call. A pointer to this function appears in every
213 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
214 -- Build subprogram declaration for previous one
216 function Build_Protected_Entry
219 Pid : Node_Id) return Node_Id;
220 -- Build the procedure implementing the statement sequence of the specified
223 function Build_Protected_Entry_Specification
226 Ent_Id : Entity_Id) return Node_Id;
227 -- Build a specification for the procedure implementing the statements of
228 -- the specified entry body. Add attributes associating it with the entry
229 -- defining identifier Ent_Id.
231 function Build_Protected_Spec
233 Obj_Type : Entity_Id;
235 Unprotected : Boolean := False) return List_Id;
236 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
237 -- Subprogram_Type. Builds signature of protected subprogram, adding the
238 -- formal that corresponds to the object itself. For an access to protected
239 -- subprogram, there is no object type to specify, so the parameter has
240 -- type Address and mode In. An indirect call through such a pointer will
241 -- convert the address to a reference to the actual object. The object is
242 -- a limited record and therefore a by_reference type.
244 function Build_Protected_Subprogram_Body
247 N_Op_Spec : Node_Id) return Node_Id;
248 -- This function is used to construct the protected version of a protected
249 -- subprogram. Its statement sequence first defers abort, then locks
250 -- the associated protected object, and then enters a block that contains
251 -- a call to the unprotected version of the subprogram (for details, see
252 -- Build_Unprotected_Subprogram_Body). This block statement requires
253 -- a cleanup handler that unlocks the object in all cases.
254 -- (see Exp_Ch7.Expand_Cleanup_Actions).
256 function Build_Selected_Name
258 Selector : Entity_Id;
259 Append_Char : Character := ' ') return Name_Id;
260 -- Build a name in the form of Prefix__Selector, with an optional
261 -- character appended. This is used for internal subprograms generated
262 -- for operations of protected types, including barrier functions.
263 -- For the subprograms generated for entry bodies and entry barriers,
264 -- the generated name includes a sequence number that makes names
265 -- unique in the presence of entry overloading. This is necessary
266 -- because entry body procedures and barrier functions all have the
269 procedure Build_Simple_Entry_Call
274 -- Some comments here would be useful ???
276 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
277 -- This routine constructs a specification for the procedure that we will
278 -- build for the task body for task type T. The spec has the form:
280 -- procedure tnameB (_Task : access tnameV);
282 -- where name is the character name taken from the task type entity that
283 -- is passed as the argument to the procedure, and tnameV is the task
284 -- value type that is associated with the task type.
286 function Build_Unprotected_Subprogram_Body
288 Pid : Node_Id) return Node_Id;
289 -- This routine constructs the unprotected version of a protected
290 -- subprogram body, which is contains all of the code in the
291 -- original, unexpanded body. This is the version of the protected
292 -- subprogram that is called from all protected operations on the same
293 -- object, including the protected version of the same subprogram.
295 procedure Collect_Entry_Families
298 Current_Node : in out Node_Id;
299 Conctyp : Entity_Id);
300 -- For each entry family in a concurrent type, create an anonymous array
301 -- type of the right size, and add a component to the corresponding_record.
303 function Concurrent_Object
304 (Spec_Id : Entity_Id;
305 Conc_Typ : Entity_Id) return Entity_Id;
306 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
307 -- the entity associated with the concurrent object in the Protected_Body_
308 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
309 -- denotes formal parameter _O, _object or _task.
311 function Copy_Result_Type (Res : Node_Id) return Node_Id;
312 -- Copy the result type of a function specification, when building the
313 -- internal operation corresponding to a protected function, or when
314 -- expanding an access to protected function. If the result is an anonymous
315 -- access to subprogram itself, we need to create a new signature with the
316 -- same parameter names and the same resolved types, but with new entities
319 procedure Debug_Private_Data_Declarations (Decls : List_Id);
320 -- Decls is a list which may contain the declarations created by Install_
321 -- Private_Data_Declarations. All generated entities are marked as needing
322 -- debug info and debug nodes are manually generation where necessary. This
323 -- step of the expansion must to be done after private data has been moved
324 -- to its final resting scope to ensure proper visibility of debug objects.
326 function Family_Offset
331 Cap : Boolean) return Node_Id;
332 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in
333 -- an accept statement, or the upper bound in the discrete subtype of
334 -- an entry declaration. Lo is the corresponding lower bound. Ttyp is
335 -- the concurrent type of the entry. If Cap is true, the result is
336 -- capped according to Entry_Family_Bound.
343 Cap : Boolean) return Node_Id;
344 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in
345 -- a family, and handle properly the superflat case. This is equivalent
346 -- to the use of 'Length on the index type, but must use Family_Offset
347 -- to handle properly the case of bounds that depend on discriminants.
348 -- If Cap is true, the result is capped according to Entry_Family_Bound.
350 procedure Extract_Dispatching_Call
352 Call_Ent : out Entity_Id;
353 Object : out Entity_Id;
354 Actuals : out List_Id;
355 Formals : out List_Id);
356 -- Given a dispatching call, extract the entity of the name of the call,
357 -- its actual dispatching object, its actual parameters and the formal
358 -- parameters of the overridden interface-level version. If the type of
359 -- the dispatching object is an access type then an explicit dereference
360 -- is returned in Object.
362 procedure Extract_Entry
364 Concval : out Node_Id;
366 Index : out Node_Id);
367 -- Given an entry call, returns the associated concurrent object,
368 -- the entry name, and the entry family index.
370 function Find_Task_Or_Protected_Pragma
372 P : Name_Id) return Node_Id;
373 -- Searches the task or protected definition T for the first occurrence
374 -- of the pragma whose name is given by P. The caller has ensured that
375 -- the pragma is present in the task definition. A special case is that
376 -- when P is Name_uPriority, the call will also find Interrupt_Priority.
377 -- ??? Should be implemented with the rep item chain mechanism.
379 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
380 -- Given a subprogram identifier, return the entity which is associated
381 -- with the protection entry index in the Protected_Body_Subprogram or the
382 -- Task_Body_Procedure of Spec_Id. The returned entity denotes formal
385 function Is_Potentially_Large_Family
386 (Base_Index : Entity_Id;
389 Hi : Node_Id) return Boolean;
391 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
392 -- Determine whether Id is a function or a procedure and is marked as a
393 -- private primitive.
395 function Null_Statements (Stats : List_Id) return Boolean;
396 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
397 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as
398 -- well to still count as null. Returns True for a null sequence. The
399 -- argument is the list of statements from the DO-END sequence.
401 function Parameter_Block_Pack
407 Stmts : List_Id) return Entity_Id;
408 -- Set the components of the generated parameter block with the values of
409 -- the actual parameters. Generate aliased temporaries to capture the
410 -- values for types that are passed by copy. Otherwise generate a reference
411 -- to the actual's value. Return the address of the aggregate block.
413 -- Jnn1 : alias <formal-type1>;
414 -- Jnn1 := <actual1>;
417 -- Jnn1'unchecked_access;
418 -- <actual2>'reference;
421 function Parameter_Block_Unpack
425 Formals : List_Id) return List_Id;
426 -- Retrieve the values of the components from the parameter block and
427 -- assign then to the original actual parameters. Generate:
428 -- <actual1> := P.<formal1>;
430 -- <actualN> := P.<formalN>;
432 function Trivial_Accept_OK return Boolean;
433 -- If there is no DO-END block for an accept, or if the DO-END block has
434 -- only null statements, then it is possible to do the Rendezvous with much
435 -- less overhead using the Accept_Trivial routine in the run-time library.
436 -- However, this is not always a valid optimization. Whether it is valid or
437 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
438 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
439 -- a rescheduling is required, so this optimization is not allowed. This
440 -- function returns True if the optimization is permitted.
442 -----------------------------
443 -- Actual_Index_Expression --
444 -----------------------------
446 function Actual_Index_Expression
450 Tsk : Entity_Id) return Node_Id
452 Ttyp : constant Entity_Id := Etype (Tsk);
460 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
461 -- Compute difference between bounds of entry family
463 --------------------------
464 -- Actual_Family_Offset --
465 --------------------------
467 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
469 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
470 -- Replace a reference to a discriminant with a selected component
471 -- denoting the discriminant of the target task.
473 -----------------------------
474 -- Actual_Discriminant_Ref --
475 -----------------------------
477 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
478 Typ : constant Entity_Id := Etype (Bound);
482 if not Is_Entity_Name (Bound)
483 or else Ekind (Entity (Bound)) /= E_Discriminant
485 if Nkind (Bound) = N_Attribute_Reference then
488 B := New_Copy_Tree (Bound);
493 Make_Selected_Component (Sloc,
494 Prefix => New_Copy_Tree (Tsk),
495 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
497 Analyze_And_Resolve (B, Typ);
501 Make_Attribute_Reference (Sloc,
502 Attribute_Name => Name_Pos,
503 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
504 Expressions => New_List (B));
505 end Actual_Discriminant_Ref;
507 -- Start of processing for Actual_Family_Offset
511 Make_Op_Subtract (Sloc,
512 Left_Opnd => Actual_Discriminant_Ref (Hi),
513 Right_Opnd => Actual_Discriminant_Ref (Lo));
514 end Actual_Family_Offset;
516 -- Start of processing for Actual_Index_Expression
519 -- The queues of entries and entry families appear in textual order in
520 -- the associated record. The entry index is computed as the sum of the
521 -- number of queues for all entries that precede the designated one, to
522 -- which is added the index expression, if this expression denotes a
523 -- member of a family.
525 -- The following is a place holder for the count of simple entries
527 Num := Make_Integer_Literal (Sloc, 1);
529 -- We construct an expression which is a series of addition operations.
530 -- See comments in Entry_Index_Expression, which is identical in
533 if Present (Index) then
534 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
541 Actual_Family_Offset (
542 Make_Attribute_Reference (Sloc,
543 Attribute_Name => Name_Pos,
544 Prefix => New_Reference_To (Base_Type (S), Sloc),
545 Expressions => New_List (Relocate_Node (Index))),
546 Type_Low_Bound (S)));
551 -- Now add lengths of preceding entries and entry families
553 Prev := First_Entity (Ttyp);
555 while Chars (Prev) /= Chars (Ent)
556 or else (Ekind (Prev) /= Ekind (Ent))
557 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
559 if Ekind (Prev) = E_Entry then
560 Set_Intval (Num, Intval (Num) + 1);
562 elsif Ekind (Prev) = E_Entry_Family then
564 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
566 -- The need for the following full view retrieval stems from
567 -- this complex case of nested generics and tasking:
570 -- type Formal_Index is range <>;
573 -- type Index is private;
580 -- type Index is new Formal_Index range 1 .. 10;
583 -- package body Outer is
585 -- entry Fam (Index); -- (2)
588 -- package body Inner is -- (3)
596 -- We are currently building the index expression for the entry
597 -- call "T.E" (1). Part of the expansion must mention the range
598 -- of the discrete type "Index" (2) of entry family "Fam".
599 -- However only the private view of type "Index" is available to
600 -- the inner generic (3) because there was no prior mention of
601 -- the type inside "Inner". This visibility requirement is
602 -- implicit and cannot be detected during the construction of
603 -- the generic trees and needs special handling.
606 and then Is_Private_Type (S)
607 and then Present (Full_View (S))
612 Lo := Type_Low_Bound (S);
613 Hi := Type_High_Bound (S);
621 Actual_Family_Offset (Hi, Lo),
623 Make_Integer_Literal (Sloc, 1)));
625 -- Other components are anonymous types to be ignored
635 end Actual_Index_Expression;
637 --------------------------
638 -- Add_Formal_Renamings --
639 --------------------------
641 procedure Add_Formal_Renamings
647 Ptr : constant Entity_Id :=
649 (Next (First (Parameter_Specifications (Spec))));
650 -- The name of the formal that holds the address of the parameter block
657 Renamed_Formal : Node_Id;
660 Formal := First_Formal (Ent);
661 while Present (Formal) loop
662 Comp := Entry_Component (Formal);
664 Make_Defining_Identifier (Sloc (Formal),
665 Chars => Chars (Formal));
666 Set_Etype (New_F, Etype (Formal));
667 Set_Scope (New_F, Ent);
669 -- Now we set debug info needed on New_F even though it does not
670 -- come from source, so that the debugger will get the right
671 -- information for these generated names.
673 Set_Debug_Info_Needed (New_F);
675 if Ekind (Formal) = E_In_Parameter then
676 Set_Ekind (New_F, E_Constant);
678 Set_Ekind (New_F, E_Variable);
679 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
682 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
685 Make_Selected_Component (Loc,
687 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
688 Make_Identifier (Loc, Chars (Ptr))),
689 Selector_Name => New_Reference_To (Comp, Loc));
692 Build_Renamed_Formal_Declaration
693 (New_F, Formal, Comp, Renamed_Formal);
695 Append (Decl, Decls);
696 Set_Renamed_Object (Formal, New_F);
697 Next_Formal (Formal);
699 end Add_Formal_Renamings;
701 ------------------------
702 -- Add_Object_Pointer --
703 ------------------------
705 procedure Add_Object_Pointer
707 Conc_Typ : Entity_Id;
710 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
715 -- Create the renaming declaration for the Protection object of a
716 -- protected type. _Object is used by Complete_Entry_Body.
717 -- ??? An attempt to make this a renaming was unsuccessful.
719 -- Build the entity for the access type
722 Make_Defining_Identifier (Loc,
723 New_External_Name (Chars (Rec_Typ), 'P'));
726 -- _object : poVP := poVP!O;
729 Make_Object_Declaration (Loc,
730 Defining_Identifier =>
731 Make_Defining_Identifier (Loc, Name_uObject),
733 New_Reference_To (Obj_Ptr, Loc),
735 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
736 Set_Debug_Info_Needed (Defining_Identifier (Decl));
737 Prepend_To (Decls, Decl);
740 -- type poVP is access poV;
743 Make_Full_Type_Declaration (Loc,
744 Defining_Identifier =>
747 Make_Access_To_Object_Definition (Loc,
748 Subtype_Indication =>
749 New_Reference_To (Rec_Typ, Loc)));
750 Set_Debug_Info_Needed (Defining_Identifier (Decl));
751 Prepend_To (Decls, Decl);
752 end Add_Object_Pointer;
754 -----------------------
755 -- Build_Accept_Body --
756 -----------------------
758 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
759 Loc : constant Source_Ptr := Sloc (Astat);
760 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
767 -- At the end of the statement sequence, Complete_Rendezvous is called.
768 -- A label skipping the Complete_Rendezvous, and all other accept
769 -- processing, has already been added for the expansion of requeue
770 -- statements. The Sloc is copied from the last statement since it
771 -- is really part of this last statement.
775 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
776 Insert_Before (Last (Statements (Stats)), Call);
779 -- If exception handlers are present, then append Complete_Rendezvous
780 -- calls to the handlers, and construct the required outer block. As
781 -- above, the Sloc is copied from the last statement in the sequence.
783 if Present (Exception_Handlers (Stats)) then
784 Hand := First (Exception_Handlers (Stats));
785 while Present (Hand) loop
788 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
789 Append (Call, Statements (Hand));
795 Make_Handled_Sequence_Of_Statements (Loc,
796 Statements => New_List (
797 Make_Block_Statement (Loc,
798 Handled_Statement_Sequence => Stats)));
804 -- At this stage we know that the new statement sequence does not
805 -- have an exception handler part, so we supply one to call
806 -- Exceptional_Complete_Rendezvous. This handler is
808 -- when all others =>
809 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
811 -- We handle Abort_Signal to make sure that we properly catch the abort
812 -- case and wake up the caller.
814 Ohandle := Make_Others_Choice (Loc);
815 Set_All_Others (Ohandle);
817 Set_Exception_Handlers (New_S,
819 Make_Implicit_Exception_Handler (Loc,
820 Exception_Choices => New_List (Ohandle),
822 Statements => New_List (
823 Make_Procedure_Call_Statement (Sloc (Stats),
824 Name => New_Reference_To (
825 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
826 Parameter_Associations => New_List (
827 Make_Function_Call (Sloc (Stats),
828 Name => New_Reference_To (
829 RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
831 Set_Parent (New_S, Astat); -- temp parent for Analyze call
832 Analyze_Exception_Handlers (Exception_Handlers (New_S));
833 Expand_Exception_Handlers (New_S);
835 -- Exceptional_Complete_Rendezvous must be called with abort
836 -- still deferred, which is the case for a "when all others" handler.
839 end Build_Accept_Body;
841 -----------------------------------
842 -- Build_Activation_Chain_Entity --
843 -----------------------------------
845 procedure Build_Activation_Chain_Entity (N : Node_Id) is
851 -- Loop to find enclosing construct containing activation chain variable
852 -- The construct is a body, a block, or an extended return.
856 while not Nkind_In (P, N_Subprogram_Body,
858 N_Package_Declaration,
862 N_Extended_Return_Statement)
867 -- If we are in a package body, the activation chain variable is
868 -- declared in the body, but the Activation_Chain_Entity is attached
871 if Nkind (P) = N_Package_Body then
872 Decls := Declarations (P);
873 P := Unit_Declaration_Node (Corresponding_Spec (P));
875 elsif Nkind (P) = N_Package_Declaration then
876 Decls := Visible_Declarations (Specification (P));
878 elsif Nkind (P) = N_Extended_Return_Statement then
879 Decls := Return_Object_Declarations (P);
882 Decls := Declarations (P);
885 -- If activation chain entity not already declared, declare it
887 if Nkind (P) = N_Extended_Return_Statement
888 or else No (Activation_Chain_Entity (P))
890 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
892 -- Note: An extended return statement is not really a task activator,
893 -- but it does have an activation chain on which to store the tasks
894 -- temporarily. On successful return, the tasks on this chain are
895 -- moved to the chain passed in by the caller. We do not build an
896 -- Activation_Chain_Entity for an N_Extended_Return_Statement,
897 -- because we do not want to build a call to Activate_Tasks. Task
898 -- activation is the responsibility of the caller.
900 if Nkind (P) /= N_Extended_Return_Statement then
901 Set_Activation_Chain_Entity (P, Chain);
905 Make_Object_Declaration (Sloc (P),
906 Defining_Identifier => Chain,
907 Aliased_Present => True,
909 New_Reference_To (RTE (RE_Activation_Chain), Sloc (P))));
911 Analyze (First (Decls));
913 end Build_Activation_Chain_Entity;
915 ----------------------------
916 -- Build_Barrier_Function --
917 ----------------------------
919 function Build_Barrier_Function
922 Pid : Node_Id) return Node_Id
924 Loc : constant Source_Ptr := Sloc (N);
925 Func_Id : constant Entity_Id := Barrier_Function (Ent);
926 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
927 Op_Decls : constant List_Id := New_List;
931 -- Add a declaration for the Protection object, renaming declarations
932 -- for the discriminals and privals and finally a declaration for the
933 -- entry family index (if applicable).
935 Install_Private_Data_Declarations
936 (Loc, Func_Id, Pid, N, Op_Decls, True, Ekind (Ent) = E_Entry_Family);
938 -- Note: the condition in the barrier function needs to be properly
939 -- processed for the C/Fortran boolean possibility, but this happens
940 -- automatically since the return statement does this normalization.
943 Make_Subprogram_Body (Loc,
945 Build_Barrier_Function_Specification (Loc,
946 Make_Defining_Identifier (Loc, Chars (Func_Id))),
947 Declarations => Op_Decls,
948 Handled_Statement_Sequence =>
949 Make_Handled_Sequence_Of_Statements (Loc,
950 Statements => New_List (
951 Make_Simple_Return_Statement (Loc,
952 Expression => Condition (Ent_Formals)))));
953 Set_Is_Entry_Barrier_Function (Func_Body);
956 end Build_Barrier_Function;
958 ------------------------------------------
959 -- Build_Barrier_Function_Specification --
960 ------------------------------------------
962 function Build_Barrier_Function_Specification
964 Def_Id : Entity_Id) return Node_Id
967 Set_Debug_Info_Needed (Def_Id);
969 return Make_Function_Specification (Loc,
970 Defining_Unit_Name => Def_Id,
971 Parameter_Specifications => New_List (
972 Make_Parameter_Specification (Loc,
973 Defining_Identifier =>
974 Make_Defining_Identifier (Loc, Name_uO),
976 New_Reference_To (RTE (RE_Address), Loc)),
978 Make_Parameter_Specification (Loc,
979 Defining_Identifier =>
980 Make_Defining_Identifier (Loc, Name_uE),
982 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
985 New_Reference_To (Standard_Boolean, Loc));
986 end Build_Barrier_Function_Specification;
988 --------------------------
989 -- Build_Call_With_Task --
990 --------------------------
992 function Build_Call_With_Task
994 E : Entity_Id) return Node_Id
996 Loc : constant Source_Ptr := Sloc (N);
999 Make_Function_Call (Loc,
1000 Name => New_Reference_To (E, Loc),
1001 Parameter_Associations => New_List (Concurrent_Ref (N)));
1002 end Build_Call_With_Task;
1004 --------------------------------
1005 -- Build_Corresponding_Record --
1006 --------------------------------
1008 function Build_Corresponding_Record
1011 Loc : Source_Ptr) return Node_Id
1013 Rec_Ent : constant Entity_Id :=
1014 Make_Defining_Identifier
1015 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1018 New_Disc : Entity_Id;
1022 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1023 Set_Ekind (Rec_Ent, E_Record_Type);
1024 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1025 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1026 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1027 Set_Stored_Constraint (Rec_Ent, No_Elist);
1030 -- Use discriminals to create list of discriminants for record, and
1031 -- create new discriminals for use in default expressions, etc. It is
1032 -- worth noting that a task discriminant gives rise to 5 entities;
1034 -- a) The original discriminant.
1035 -- b) The discriminal for use in the task.
1036 -- c) The discriminant of the corresponding record.
1037 -- d) The discriminal for the init proc of the corresponding record.
1038 -- e) The local variable that renames the discriminant in the procedure
1039 -- for the task body.
1041 -- In fact the discriminals b) are used in the renaming declarations
1042 -- for e). See details in einfo (Handling of Discriminants).
1044 if Present (Discriminant_Specifications (N)) then
1046 Disc := First_Discriminant (Ctyp);
1048 while Present (Disc) loop
1049 New_Disc := CR_Discriminant (Disc);
1052 Make_Discriminant_Specification (Loc,
1053 Defining_Identifier => New_Disc,
1054 Discriminant_Type =>
1055 New_Occurrence_Of (Etype (Disc), Loc),
1057 New_Copy (Discriminant_Default_Value (Disc))));
1059 Next_Discriminant (Disc);
1066 -- Now we can construct the record type declaration. Note that this
1067 -- record is "limited tagged". It is "limited" to reflect the underlying
1068 -- limitedness of the task or protected object that it represents, and
1069 -- ensuring for example that it is properly passed by reference. It is
1070 -- "tagged" to give support to dispatching calls through interfaces. We
1071 -- propagate here the list of interfaces covered by the concurrent type
1072 -- (Ada 2005: AI-345).
1075 Make_Full_Type_Declaration (Loc,
1076 Defining_Identifier => Rec_Ent,
1077 Discriminant_Specifications => Dlist,
1079 Make_Record_Definition (Loc,
1081 Make_Component_List (Loc,
1082 Component_Items => Cdecls),
1084 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1085 Interface_List => Interface_List (N),
1086 Limited_Present => True));
1087 end Build_Corresponding_Record;
1089 ----------------------------------
1090 -- Build_Entry_Count_Expression --
1091 ----------------------------------
1093 function Build_Entry_Count_Expression
1094 (Concurrent_Type : Node_Id;
1095 Component_List : List_Id;
1096 Loc : Source_Ptr) return Node_Id
1108 -- Count number of non-family entries
1111 Ent := First_Entity (Concurrent_Type);
1112 while Present (Ent) loop
1113 if Ekind (Ent) = E_Entry then
1120 Ecount := Make_Integer_Literal (Loc, Eindx);
1122 -- Loop through entry families building the addition nodes
1124 Ent := First_Entity (Concurrent_Type);
1125 Comp := First (Component_List);
1126 while Present (Ent) loop
1127 if Ekind (Ent) = E_Entry_Family then
1128 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1132 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1133 Hi := Type_High_Bound (Typ);
1134 Lo := Type_Low_Bound (Typ);
1135 Large := Is_Potentially_Large_Family
1136 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1139 Left_Opnd => Ecount,
1140 Right_Opnd => Family_Size
1141 (Loc, Hi, Lo, Concurrent_Type, Large));
1148 end Build_Entry_Count_Expression;
1150 -----------------------
1151 -- Build_Entry_Names --
1152 -----------------------
1154 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1155 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1161 Typ : Entity_Id := Conc_Typ;
1163 procedure Build_Entry_Family_Name (Id : Entity_Id);
1165 -- for Lnn in Family_Low .. Family_High loop
1168 -- (_init._object <or> _init._task_id,
1170 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1172 -- Note that the bounds of the range may reference discriminants. The
1173 -- above construct is added directly to the statements of the block.
1175 procedure Build_Entry_Name (Id : Entity_Id);
1179 -- (_init._object <or>_init._task_id,
1181 -- new String ("<Entry name>");
1182 -- The above construct is added directly to the statements of the block.
1184 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1185 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1186 -- _init._task_id or _init._object, Inn and Arg3.
1188 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id;
1189 -- Given a protected type or its corresponding record, find the type of
1192 procedure Increment_Index (Stmts : List_Id);
1193 -- Generate the following and add it to Stmts
1196 -----------------------------
1197 -- Build_Entry_Family_Name --
1198 -----------------------------
1200 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1201 Def : constant Node_Id :=
1202 Discrete_Subtype_Definition (Parent (Id));
1203 L_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
1204 L_Stmts : constant List_Id := New_List;
1207 function Build_Range (Def : Node_Id) return Node_Id;
1208 -- Given a discrete subtype definition of an entry family, generate a
1209 -- range node which covers the range of Def's type.
1215 function Build_Range (Def : Node_Id) return Node_Id is
1216 High : Node_Id := Type_High_Bound (Etype (Def));
1217 Low : Node_Id := Type_Low_Bound (Etype (Def));
1220 -- If a bound references a discriminant, generate an identifier
1221 -- with the same name. Resolution will map it to the formals of
1224 if Is_Entity_Name (Low)
1225 and then Ekind (Entity (Low)) = E_Discriminant
1227 Low := Make_Identifier (Loc, Chars (Low));
1229 Low := New_Copy_Tree (Low);
1232 if Is_Entity_Name (High)
1233 and then Ekind (Entity (High)) = E_Discriminant
1235 High := Make_Identifier (Loc, Chars (High));
1237 High := New_Copy_Tree (High);
1243 High_Bound => High);
1246 -- Start of processing for Build_Entry_Family_Name
1249 Get_Name_String (Chars (Id));
1251 -- Add a leading '('
1253 Add_Char_To_Name_Buffer ('(');
1256 -- new String'("<Entry name>(" & Lnn'Img & ")");
1258 -- This is an implicit heap allocation, and Comes_From_Source is
1259 -- False, which ensures that it will get flagged as a violation of
1260 -- No_Implicit_Heap_Allocations when that restriction applies.
1263 Make_Allocator (Loc,
1264 Make_Qualified_Expression (Loc,
1266 New_Reference_To (Standard_String, Loc),
1268 Make_Op_Concat (Loc,
1270 Make_Op_Concat (Loc,
1272 Make_String_Literal (Loc,
1273 Strval => String_From_Name_Buffer),
1275 Make_Attribute_Reference (Loc,
1277 New_Reference_To (L_Id, Loc),
1278 Attribute_Name => Name_Img)),
1280 Make_String_Literal (Loc,
1283 Increment_Index (L_Stmts);
1284 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1287 -- for Lnn in Family_Low .. Family_High loop
1290 -- (_init._object <or> _init._task_id, Inn, <Val>);
1294 Make_Loop_Statement (Loc,
1296 Make_Iteration_Scheme (Loc,
1297 Loop_Parameter_Specification =>
1298 Make_Loop_Parameter_Specification (Loc,
1299 Defining_Identifier => L_Id,
1300 Discrete_Subtype_Definition => Build_Range (Def))),
1301 Statements => L_Stmts,
1302 End_Label => Empty));
1303 end Build_Entry_Family_Name;
1305 ----------------------
1306 -- Build_Entry_Name --
1307 ----------------------
1309 procedure Build_Entry_Name (Id : Entity_Id) is
1313 Get_Name_String (Chars (Id));
1315 -- This is an implicit heap allocation, and Comes_From_Source is
1316 -- False, which ensures that it will get flagged as a violation of
1317 -- No_Implicit_Heap_Allocations when that restriction applies.
1320 Make_Allocator (Loc,
1321 Make_Qualified_Expression (Loc,
1323 New_Reference_To (Standard_String, Loc),
1325 Make_String_Literal (Loc,
1326 String_From_Name_Buffer)));
1328 Increment_Index (B_Stmts);
1329 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1330 end Build_Entry_Name;
1332 -------------------------------
1333 -- Build_Set_Entry_Name_Call --
1334 -------------------------------
1336 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1341 -- Determine the proper name for the first argument and the RTS
1344 if Is_Protected_Type (Typ) then
1345 Arg1 := Name_uObject;
1346 Proc := RO_PE_Set_Entry_Name;
1348 else pragma Assert (Is_Task_Type (Typ));
1349 Arg1 := Name_uTask_Id;
1350 Proc := RO_TS_Set_Entry_Name;
1354 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1357 Make_Procedure_Call_Statement (Loc,
1359 New_Reference_To (RTE (Proc), Loc),
1360 Parameter_Associations => New_List (
1361 Make_Selected_Component (Loc, -- _init._object
1362 Prefix => -- _init._task_id
1363 Make_Identifier (Loc, Name_uInit),
1365 Make_Identifier (Loc, Arg1)),
1366 New_Reference_To (Index, Loc), -- Inn
1368 end Build_Set_Entry_Name_Call;
1370 --------------------------
1371 -- Find_Protection_Type --
1372 --------------------------
1374 function Find_Protection_Type (Conc_Typ : Entity_Id) return Entity_Id is
1376 Typ : Entity_Id := Conc_Typ;
1379 if Is_Concurrent_Type (Typ) then
1380 Typ := Corresponding_Record_Type (Typ);
1383 Comp := First_Component (Typ);
1384 while Present (Comp) loop
1385 if Chars (Comp) = Name_uObject then
1386 return Base_Type (Etype (Comp));
1389 Next_Component (Comp);
1392 -- The corresponding record of a protected type should always have an
1395 raise Program_Error;
1396 end Find_Protection_Type;
1398 ---------------------
1399 -- Increment_Index --
1400 ---------------------
1402 procedure Increment_Index (Stmts : List_Id) is
1408 Make_Assignment_Statement (Loc,
1410 New_Reference_To (Index, Loc),
1414 New_Reference_To (Index, Loc),
1416 Make_Integer_Literal (Loc, 1))));
1417 end Increment_Index;
1419 -- Start of processing for Build_Entry_Names
1422 -- Retrieve the original concurrent type
1424 if Is_Concurrent_Record_Type (Typ) then
1425 Typ := Corresponding_Concurrent_Type (Typ);
1428 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1430 -- Nothing to do if the type has no entries
1432 if not Has_Entries (Typ) then
1436 -- Avoid generating entry names for a protected type with only one entry
1438 if Is_Protected_Type (Typ)
1439 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1444 Index := Make_Temporary (Loc, 'I');
1446 -- Step 1: Generate the declaration of the index variable:
1447 -- Inn : Protected_Entry_Index := 0;
1449 -- Inn : Task_Entry_Index := 0;
1451 if Is_Protected_Type (Typ) then
1452 Index_Typ := RE_Protected_Entry_Index;
1454 Index_Typ := RE_Task_Entry_Index;
1457 B_Decls := New_List;
1459 Make_Object_Declaration (Loc,
1460 Defining_Identifier => Index,
1461 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1462 Expression => Make_Integer_Literal (Loc, 0)));
1464 B_Stmts := New_List;
1466 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1469 Comp := First_Entity (Typ);
1470 while Present (Comp) loop
1471 if Ekind (Comp) = E_Entry then
1472 Build_Entry_Name (Comp);
1474 elsif Ekind (Comp) = E_Entry_Family then
1475 Build_Entry_Family_Name (Comp);
1481 -- Step 3: Wrap the statements in a block
1484 Make_Block_Statement (Loc,
1485 Declarations => B_Decls,
1486 Handled_Statement_Sequence =>
1487 Make_Handled_Sequence_Of_Statements (Loc,
1488 Statements => B_Stmts));
1489 end Build_Entry_Names;
1491 ---------------------------
1492 -- Build_Parameter_Block --
1493 ---------------------------
1495 function Build_Parameter_Block
1499 Decls : List_Id) return Entity_Id
1505 Has_Comp : Boolean := False;
1509 Actual := First (Actuals);
1511 Formal := Defining_Identifier (First (Formals));
1513 while Present (Actual) loop
1514 if not Is_Controlling_Actual (Actual) then
1517 -- type Ann is access all <actual-type>
1519 Comp_Nam := Make_Temporary (Loc, 'A');
1522 Make_Full_Type_Declaration (Loc,
1523 Defining_Identifier => Comp_Nam,
1525 Make_Access_To_Object_Definition (Loc,
1526 All_Present => True,
1527 Constant_Present => Ekind (Formal) = E_In_Parameter,
1528 Subtype_Indication =>
1529 New_Reference_To (Etype (Actual), Loc))));
1535 Make_Component_Declaration (Loc,
1536 Defining_Identifier =>
1537 Make_Defining_Identifier (Loc, Chars (Formal)),
1538 Component_Definition =>
1539 Make_Component_Definition (Loc,
1542 Subtype_Indication =>
1543 New_Reference_To (Comp_Nam, Loc))));
1548 Next_Actual (Actual);
1549 Next_Formal_With_Extras (Formal);
1552 Rec_Nam := Make_Temporary (Loc, 'P');
1557 -- type Pnn is record
1562 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1563 -- the original parameter names and Ann1 .. AnnN are the access to
1567 Make_Full_Type_Declaration (Loc,
1568 Defining_Identifier =>
1571 Make_Record_Definition (Loc,
1573 Make_Component_List (Loc, Comps))));
1576 -- type Pnn is null record;
1579 Make_Full_Type_Declaration (Loc,
1580 Defining_Identifier =>
1583 Make_Record_Definition (Loc,
1584 Null_Present => True,
1585 Component_List => Empty)));
1589 end Build_Parameter_Block;
1591 --------------------------------------
1592 -- Build_Renamed_Formal_Declaration --
1593 --------------------------------------
1595 function Build_Renamed_Formal_Declaration
1599 Renamed_Formal : Node_Id) return Node_Id
1601 Loc : constant Source_Ptr := Sloc (New_F);
1605 -- If the formal is a tagged incomplete type, it is already passed
1606 -- by reference, so it is sufficient to rename the pointer component
1607 -- that corresponds to the actual. Otherwise we need to dereference
1608 -- the pointer component to obtain the actual.
1610 if Is_Incomplete_Type (Etype (Formal))
1611 and then Is_Tagged_Type (Etype (Formal))
1614 Make_Object_Renaming_Declaration (Loc,
1615 Defining_Identifier => New_F,
1616 Subtype_Mark => New_Reference_To (Etype (Comp), Loc),
1617 Name => Renamed_Formal);
1621 Make_Object_Renaming_Declaration (Loc,
1622 Defining_Identifier => New_F,
1623 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
1625 Make_Explicit_Dereference (Loc, Renamed_Formal));
1629 end Build_Renamed_Formal_Declaration;
1631 -----------------------
1632 -- Build_PPC_Wrapper --
1633 -----------------------
1635 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1636 Loc : constant Source_Ptr := Sloc (E);
1637 Synch_Type : constant Entity_Id := Scope (E);
1639 Wrapper_Id : constant Entity_Id :=
1640 Make_Defining_Identifier (Loc,
1641 Chars => New_External_Name (Chars (E), 'E'));
1642 -- the wrapper procedure name
1644 Wrapper_Body : Node_Id;
1646 Synch_Id : constant Entity_Id :=
1647 Make_Defining_Identifier (Loc,
1648 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1649 -- The parameter that designates the synchronized object in the call
1651 Actuals : constant List_Id := New_List;
1652 -- the actuals in the entry call.
1654 Decls : constant List_Id := New_List;
1656 Entry_Call : Node_Id;
1657 Entry_Name : Node_Id;
1660 -- The specification of the wrapper procedure
1664 -- Only build the wrapper if entry has pre/postconditions.
1665 -- Should this be done unconditionally instead ???
1671 P := Spec_PPC_List (E);
1676 -- Transfer ppc pragmas to the declarations of the wrapper
1678 while Present (P) loop
1679 if Pragma_Name (P) = Name_Precondition
1680 or else Pragma_Name (P) = Name_Postcondition
1682 Append (Relocate_Node (P), Decls);
1683 Set_Analyzed (Last (Decls), False);
1686 P := Next_Pragma (P);
1690 -- First formal is synchronized object
1693 Make_Parameter_Specification (Loc,
1694 Defining_Identifier => Synch_Id,
1695 Out_Present => True,
1697 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1700 Make_Selected_Component (Loc,
1701 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1702 Selector_Name => New_Occurrence_Of (E, Loc));
1704 -- If entity is entry family, second formal is the corresponding index,
1705 -- and entry name is an indexed component.
1707 if Ekind (E) = E_Entry_Family then
1709 Index : constant Entity_Id :=
1710 Make_Defining_Identifier (Loc, Name_I);
1713 Make_Parameter_Specification (Loc,
1714 Defining_Identifier => Index,
1716 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1719 Make_Indexed_Component (Loc,
1720 Prefix => Entry_Name,
1721 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
1726 Make_Procedure_Call_Statement (Loc,
1728 Parameter_Associations => Actuals);
1730 -- Now add formals that match those of the entry, and build actuals for
1731 -- the nested entry call.
1735 New_Form : Entity_Id;
1736 Parm_Spec : Node_Id;
1739 Form := First_Formal (E);
1740 while Present (Form) loop
1741 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
1743 Make_Parameter_Specification (Loc,
1744 Defining_Identifier => New_Form,
1745 Out_Present => Out_Present (Parent (Form)),
1746 In_Present => In_Present (Parent (Form)),
1747 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
1749 Append (Parm_Spec, Specs);
1750 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1755 -- Add renaming declarations for the discriminants of the enclosing
1756 -- type, which may be visible in the preconditions.
1758 if Has_Discriminants (Synch_Type) then
1764 D := First_Discriminant (Synch_Type);
1765 while Present (D) loop
1767 Make_Object_Renaming_Declaration (Loc,
1768 Defining_Identifier =>
1769 Make_Defining_Identifier (Loc, Chars (D)),
1770 Subtype_Mark => New_Reference_To (Etype (D), Loc),
1772 Make_Selected_Component (Loc,
1773 Prefix => New_Reference_To (Synch_Id, Loc),
1774 Selector_Name => Make_Identifier (Loc, Chars (D))));
1775 Prepend (Decl, Decls);
1776 Next_Discriminant (D);
1781 Set_PPC_Wrapper (E, Wrapper_Id);
1783 Make_Subprogram_Body (Loc,
1785 Make_Procedure_Specification (Loc,
1786 Defining_Unit_Name => Wrapper_Id,
1787 Parameter_Specifications => Specs),
1788 Declarations => Decls,
1789 Handled_Statement_Sequence =>
1790 Make_Handled_Sequence_Of_Statements (Loc,
1791 Statements => New_List (Entry_Call)));
1793 -- The wrapper body is analyzed when the enclosing type is frozen
1795 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1796 end Build_PPC_Wrapper;
1798 --------------------------
1799 -- Build_Wrapper_Bodies --
1800 --------------------------
1802 procedure Build_Wrapper_Bodies
1807 Rec_Typ : Entity_Id;
1809 function Build_Wrapper_Body
1811 Subp_Id : Entity_Id;
1812 Obj_Typ : Entity_Id;
1813 Formals : List_Id) return Node_Id;
1814 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1815 -- associated with a protected or task type. Subp_Id is the subprogram
1816 -- name which will be wrapped. Obj_Typ is the type of the new formal
1817 -- parameter which handles dispatching and object notation. Formals are
1818 -- the original formals of Subp_Id which will be explicitly replicated.
1820 ------------------------
1821 -- Build_Wrapper_Body --
1822 ------------------------
1824 function Build_Wrapper_Body
1826 Subp_Id : Entity_Id;
1827 Obj_Typ : Entity_Id;
1828 Formals : List_Id) return Node_Id
1830 Body_Spec : Node_Id;
1833 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1835 -- The subprogram is not overriding or is not a primitive declared
1836 -- between two views.
1838 if No (Body_Spec) then
1843 Actuals : List_Id := No_List;
1845 First_Form : Node_Id;
1850 -- Map formals to actuals. Use the list built for the wrapper
1851 -- spec, skipping the object notation parameter.
1853 First_Form := First (Parameter_Specifications (Body_Spec));
1855 Formal := First_Form;
1858 if Present (Formal) then
1859 Actuals := New_List;
1860 while Present (Formal) loop
1862 Make_Identifier (Loc,
1863 Chars => Chars (Defining_Identifier (Formal))));
1868 -- Special processing for primitives declared between a private
1869 -- type and its completion: the wrapper needs a properly typed
1870 -- parameter if the wrapped operation has a controlling first
1871 -- parameter. Note that this might not be the case for a function
1872 -- with a controlling result.
1874 if Is_Private_Primitive_Subprogram (Subp_Id) then
1875 if No (Actuals) then
1876 Actuals := New_List;
1879 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1880 Prepend_To (Actuals,
1881 Unchecked_Convert_To
1882 (Corresponding_Concurrent_Type (Obj_Typ),
1883 Make_Identifier (Loc, Name_uO)));
1886 Prepend_To (Actuals,
1887 Make_Identifier (Loc,
1888 Chars => Chars (Defining_Identifier (First_Form))));
1891 Nam := New_Reference_To (Subp_Id, Loc);
1893 -- An access-to-variable object parameter requires an explicit
1894 -- dereference in the unchecked conversion. This case occurs
1895 -- when a protected entry wrapper must override an interface
1896 -- level procedure with interface access as first parameter.
1898 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1900 if Nkind (Parameter_Type (First_Form)) =
1904 Make_Explicit_Dereference (Loc,
1905 Prefix => Make_Identifier (Loc, Name_uO));
1907 Conv_Id := Make_Identifier (Loc, Name_uO);
1911 Make_Selected_Component (Loc,
1913 Unchecked_Convert_To
1914 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
1915 Selector_Name => New_Reference_To (Subp_Id, Loc));
1918 -- Create the subprogram body. For a function, the call to the
1919 -- actual subprogram has to be converted to the corresponding
1920 -- record if it is a controlling result.
1922 if Ekind (Subp_Id) = E_Function then
1928 Make_Function_Call (Loc,
1930 Parameter_Associations => Actuals);
1932 if Has_Controlling_Result (Subp_Id) then
1934 Unchecked_Convert_To
1935 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1939 Make_Subprogram_Body (Loc,
1940 Specification => Body_Spec,
1941 Declarations => Empty_List,
1942 Handled_Statement_Sequence =>
1943 Make_Handled_Sequence_Of_Statements (Loc,
1944 Statements => New_List (
1945 Make_Simple_Return_Statement (Loc, Res))));
1950 Make_Subprogram_Body (Loc,
1951 Specification => Body_Spec,
1952 Declarations => Empty_List,
1953 Handled_Statement_Sequence =>
1954 Make_Handled_Sequence_Of_Statements (Loc,
1955 Statements => New_List (
1956 Make_Procedure_Call_Statement (Loc,
1958 Parameter_Associations => Actuals))));
1961 end Build_Wrapper_Body;
1963 -- Start of processing for Build_Wrapper_Bodies
1966 if Is_Concurrent_Type (Typ) then
1967 Rec_Typ := Corresponding_Record_Type (Typ);
1972 -- Generate wrapper bodies for a concurrent type which implements an
1975 if Present (Interfaces (Rec_Typ)) then
1977 Insert_Nod : Node_Id;
1979 Prim_Elmt : Elmt_Id;
1980 Prim_Decl : Node_Id;
1982 Wrap_Body : Node_Id;
1983 Wrap_Id : Entity_Id;
1988 -- Examine all primitive operations of the corresponding record
1989 -- type, looking for wrapper specs. Generate bodies in order to
1992 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1993 while Present (Prim_Elmt) loop
1994 Prim := Node (Prim_Elmt);
1996 if (Ekind (Prim) = E_Function
1997 or else Ekind (Prim) = E_Procedure)
1998 and then Is_Primitive_Wrapper (Prim)
2000 Subp := Wrapped_Entity (Prim);
2001 Prim_Decl := Parent (Parent (Prim));
2004 Build_Wrapper_Body (Loc,
2007 Formals => Parameter_Specifications (Parent (Subp)));
2008 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2010 Set_Corresponding_Spec (Wrap_Body, Prim);
2011 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2013 Insert_After (Insert_Nod, Wrap_Body);
2014 Insert_Nod := Wrap_Body;
2016 Analyze (Wrap_Body);
2019 Next_Elmt (Prim_Elmt);
2023 end Build_Wrapper_Bodies;
2025 ------------------------
2026 -- Build_Wrapper_Spec --
2027 ------------------------
2029 function Build_Wrapper_Spec
2030 (Subp_Id : Entity_Id;
2031 Obj_Typ : Entity_Id;
2032 Formals : List_Id) return Node_Id
2034 Loc : constant Source_Ptr := Sloc (Subp_Id);
2035 First_Param : Node_Id;
2037 Iface_Elmt : Elmt_Id;
2038 Iface_Op : Entity_Id;
2039 Iface_Op_Elmt : Elmt_Id;
2041 function Overriding_Possible
2042 (Iface_Op : Entity_Id;
2043 Wrapper : Entity_Id) return Boolean;
2044 -- Determine whether a primitive operation can be overridden by Wrapper.
2045 -- Iface_Op is the candidate primitive operation of an interface type,
2046 -- Wrapper is the generated entry wrapper.
2048 function Replicate_Formals
2050 Formals : List_Id) return List_Id;
2051 -- An explicit parameter replication is required due to the Is_Entry_
2052 -- Formal flag being set for all the formals of an entry. The explicit
2053 -- replication removes the flag that would otherwise cause a different
2054 -- path of analysis.
2056 -------------------------
2057 -- Overriding_Possible --
2058 -------------------------
2060 function Overriding_Possible
2061 (Iface_Op : Entity_Id;
2062 Wrapper : Entity_Id) return Boolean
2064 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2065 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2067 function Type_Conformant_Parameters
2068 (Iface_Op_Params : List_Id;
2069 Wrapper_Params : List_Id) return Boolean;
2070 -- Determine whether the parameters of the generated entry wrapper
2071 -- and those of a primitive operation are type conformant. During
2072 -- this check, the first parameter of the primitive operation is
2073 -- skipped if it is a controlling argument: protected functions
2074 -- may have a controlling result.
2076 --------------------------------
2077 -- Type_Conformant_Parameters --
2078 --------------------------------
2080 function Type_Conformant_Parameters
2081 (Iface_Op_Params : List_Id;
2082 Wrapper_Params : List_Id) return Boolean
2084 Iface_Op_Param : Node_Id;
2085 Iface_Op_Typ : Entity_Id;
2086 Wrapper_Param : Node_Id;
2087 Wrapper_Typ : Entity_Id;
2090 -- Skip the first (controlling) parameter of primitive operation
2092 Iface_Op_Param := First (Iface_Op_Params);
2094 if Present (First_Formal (Iface_Op))
2095 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2097 Iface_Op_Param := Next (Iface_Op_Param);
2100 Wrapper_Param := First (Wrapper_Params);
2101 while Present (Iface_Op_Param)
2102 and then Present (Wrapper_Param)
2104 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2105 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2107 -- The two parameters must be mode conformant
2109 if not Conforming_Types
2110 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2115 Next (Iface_Op_Param);
2116 Next (Wrapper_Param);
2119 -- One of the lists is longer than the other
2121 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2126 end Type_Conformant_Parameters;
2128 -- Start of processing for Overriding_Possible
2131 if Chars (Iface_Op) /= Chars (Wrapper) then
2135 -- If an inherited subprogram is implemented by a protected procedure
2136 -- or an entry, then the first parameter of the inherited subprogram
2137 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2139 if Ekind (Iface_Op) = E_Procedure
2140 and then Present (Parameter_Specifications (Iface_Op_Spec))
2143 Obj_Param : constant Node_Id :=
2144 First (Parameter_Specifications (Iface_Op_Spec));
2146 if not Out_Present (Obj_Param)
2147 and then Nkind (Parameter_Type (Obj_Param)) /=
2156 Type_Conformant_Parameters (
2157 Parameter_Specifications (Iface_Op_Spec),
2158 Parameter_Specifications (Wrapper_Spec));
2159 end Overriding_Possible;
2161 -----------------------
2162 -- Replicate_Formals --
2163 -----------------------
2165 function Replicate_Formals
2167 Formals : List_Id) return List_Id
2169 New_Formals : constant List_Id := New_List;
2171 Param_Type : Node_Id;
2174 Formal := First (Formals);
2176 -- Skip the object parameter when dealing with primitives declared
2177 -- between two views.
2179 if Is_Private_Primitive_Subprogram (Subp_Id)
2180 and then not Has_Controlling_Result (Subp_Id)
2182 Formal := Next (Formal);
2185 while Present (Formal) loop
2187 -- Create an explicit copy of the entry parameter
2189 -- When creating the wrapper subprogram for a primitive operation
2190 -- of a protected interface we must construct an equivalent
2191 -- signature to that of the overriding operation. For regular
2192 -- parameters we can just use the type of the formal, but for
2193 -- access to subprogram parameters we need to reanalyze the
2194 -- parameter type to create local entities for the signature of
2195 -- the subprogram type. Using the entities of the overriding
2196 -- subprogram will result in out-of-scope errors in the back-end.
2198 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2199 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2202 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
2205 Append_To (New_Formals,
2206 Make_Parameter_Specification (Loc,
2207 Defining_Identifier =>
2208 Make_Defining_Identifier (Loc,
2209 Chars => Chars (Defining_Identifier (Formal))),
2210 In_Present => In_Present (Formal),
2211 Out_Present => Out_Present (Formal),
2212 Parameter_Type => Param_Type));
2218 end Replicate_Formals;
2220 -- Start of processing for Build_Wrapper_Spec
2223 -- There is no point in building wrappers for non-tagged concurrent
2226 pragma Assert (Is_Tagged_Type (Obj_Typ));
2228 -- An entry or a protected procedure can override a routine where the
2229 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2230 -- type. Since the wrapper must have the exact same signature as that of
2231 -- the overridden subprogram, we try to find the overriding candidate
2232 -- and use its controlling formal.
2234 First_Param := Empty;
2236 -- Check every implemented interface
2238 if Present (Interfaces (Obj_Typ)) then
2239 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2240 Search : while Present (Iface_Elmt) loop
2241 Iface := Node (Iface_Elmt);
2243 -- Check every interface primitive
2245 if Present (Primitive_Operations (Iface)) then
2246 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2247 while Present (Iface_Op_Elmt) loop
2248 Iface_Op := Node (Iface_Op_Elmt);
2250 -- Ignore predefined primitives
2252 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2253 Iface_Op := Ultimate_Alias (Iface_Op);
2255 -- The current primitive operation can be overridden by
2256 -- the generated entry wrapper.
2258 if Overriding_Possible (Iface_Op, Subp_Id) then
2260 First (Parameter_Specifications (Parent (Iface_Op)));
2266 Next_Elmt (Iface_Op_Elmt);
2270 Next_Elmt (Iface_Elmt);
2274 -- If the subprogram to be wrapped is not overriding anything or is not
2275 -- a primitive declared between two views, do not produce anything. This
2276 -- avoids spurious errors involving overriding.
2279 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2285 Wrapper_Id : constant Entity_Id :=
2286 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2287 New_Formals : List_Id;
2288 Obj_Param : Node_Id;
2289 Obj_Param_Typ : Entity_Id;
2292 -- Minimum decoration is needed to catch the entity in
2293 -- Sem_Ch6.Override_Dispatching_Operation.
2295 if Ekind (Subp_Id) = E_Function then
2296 Set_Ekind (Wrapper_Id, E_Function);
2298 Set_Ekind (Wrapper_Id, E_Procedure);
2301 Set_Is_Primitive_Wrapper (Wrapper_Id);
2302 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2303 Set_Is_Private_Primitive (Wrapper_Id,
2304 Is_Private_Primitive_Subprogram (Subp_Id));
2306 -- Process the formals
2308 New_Formals := Replicate_Formals (Loc, Formals);
2310 -- A function with a controlling result and no first controlling
2311 -- formal needs no additional parameter.
2313 if Has_Controlling_Result (Subp_Id)
2315 (No (First_Formal (Subp_Id))
2316 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2320 -- Routine Subp_Id has been found to override an interface primitive.
2321 -- If the interface operation has an access parameter, create a copy
2322 -- of it, with the same null exclusion indicator if present.
2324 elsif Present (First_Param) then
2325 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2327 Make_Access_Definition (Loc,
2329 New_Reference_To (Obj_Typ, Loc));
2330 Set_Null_Exclusion_Present (Obj_Param_Typ,
2331 Null_Exclusion_Present (Parameter_Type (First_Param)));
2334 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2338 Make_Parameter_Specification (Loc,
2339 Defining_Identifier =>
2340 Make_Defining_Identifier (Loc,
2342 In_Present => In_Present (First_Param),
2343 Out_Present => Out_Present (First_Param),
2344 Parameter_Type => Obj_Param_Typ);
2346 Prepend_To (New_Formals, Obj_Param);
2348 -- If we are dealing with a primitive declared between two views,
2349 -- implemented by a synchronized operation, we need to create
2350 -- a default parameter. The mode of the parameter must match that
2351 -- of the primitive operation.
2354 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2356 Make_Parameter_Specification (Loc,
2357 Defining_Identifier =>
2358 Make_Defining_Identifier (Loc, Name_uO),
2359 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2360 Out_Present => Ekind (Subp_Id) /= E_Function,
2361 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2362 Prepend_To (New_Formals, Obj_Param);
2365 -- Build the final spec. If it is a function with a controlling
2366 -- result, it is a primitive operation of the corresponding
2367 -- record type, so mark the spec accordingly.
2369 if Ekind (Subp_Id) = E_Function then
2374 if Has_Controlling_Result (Subp_Id) then
2377 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2379 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2383 Make_Function_Specification (Loc,
2384 Defining_Unit_Name => Wrapper_Id,
2385 Parameter_Specifications => New_Formals,
2386 Result_Definition => Res_Def);
2390 Make_Procedure_Specification (Loc,
2391 Defining_Unit_Name => Wrapper_Id,
2392 Parameter_Specifications => New_Formals);
2395 end Build_Wrapper_Spec;
2397 -------------------------
2398 -- Build_Wrapper_Specs --
2399 -------------------------
2401 procedure Build_Wrapper_Specs
2407 Rec_Typ : Entity_Id;
2408 procedure Scan_Declarations (L : List_Id);
2409 -- Common processing for visible and private declarations
2410 -- of a protected type.
2412 procedure Scan_Declarations (L : List_Id) is
2414 Wrap_Decl : Node_Id;
2415 Wrap_Spec : Node_Id;
2423 while Present (Decl) loop
2426 if Nkind (Decl) = N_Entry_Declaration
2427 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2431 (Subp_Id => Defining_Identifier (Decl),
2433 Formals => Parameter_Specifications (Decl));
2435 elsif Nkind (Decl) = N_Subprogram_Declaration then
2438 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2441 Parameter_Specifications (Specification (Decl)));
2444 if Present (Wrap_Spec) then
2446 Make_Subprogram_Declaration (Loc,
2447 Specification => Wrap_Spec);
2449 Insert_After (N, Wrap_Decl);
2452 Analyze (Wrap_Decl);
2457 end Scan_Declarations;
2459 -- start of processing for Build_Wrapper_Specs
2462 if Is_Protected_Type (Typ) then
2463 Def := Protected_Definition (Parent (Typ));
2464 else pragma Assert (Is_Task_Type (Typ));
2465 Def := Task_Definition (Parent (Typ));
2468 Rec_Typ := Corresponding_Record_Type (Typ);
2470 -- Generate wrapper specs for a concurrent type which implements an
2471 -- interface. Operations in both the visible and private parts may
2472 -- implement progenitor operations.
2474 if Present (Interfaces (Rec_Typ))
2475 and then Present (Def)
2477 Scan_Declarations (Visible_Declarations (Def));
2478 Scan_Declarations (Private_Declarations (Def));
2480 end Build_Wrapper_Specs;
2482 ---------------------------
2483 -- Build_Find_Body_Index --
2484 ---------------------------
2486 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2487 Loc : constant Source_Ptr := Sloc (Typ);
2490 Has_F : Boolean := False;
2492 If_St : Node_Id := Empty;
2495 Decls : List_Id := New_List;
2498 Siz : Node_Id := Empty;
2500 procedure Add_If_Clause (Expr : Node_Id);
2501 -- Add test for range of current entry
2503 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2504 -- If a bound of an entry is given by a discriminant, retrieve the
2505 -- actual value of the discriminant from the enclosing object.
2511 procedure Add_If_Clause (Expr : Node_Id) is
2513 Stats : constant List_Id :=
2515 Make_Simple_Return_Statement (Loc,
2516 Expression => Make_Integer_Literal (Loc, Index + 1)));
2519 -- Index for current entry body
2523 -- Compute total length of entry queues so far
2531 Right_Opnd => Expr);
2536 Left_Opnd => Make_Identifier (Loc, Name_uE),
2539 -- Map entry queue indexes in the range of the current family
2540 -- into the current index, that designates the entry body.
2544 Make_Implicit_If_Statement (Typ,
2546 Then_Statements => Stats,
2547 Elsif_Parts => New_List);
2553 Make_Elsif_Part (Loc,
2555 Then_Statements => Stats),
2556 Elsif_Parts (If_St));
2560 ------------------------------
2561 -- Convert_Discriminant_Ref --
2562 ------------------------------
2564 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2568 if Is_Entity_Name (Bound)
2569 and then Ekind (Entity (Bound)) = E_Discriminant
2572 Make_Selected_Component (Loc,
2574 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2575 Make_Explicit_Dereference (Loc,
2576 Make_Identifier (Loc, Name_uObject))),
2577 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2578 Set_Etype (B, Etype (Entity (Bound)));
2580 B := New_Copy_Tree (Bound);
2584 end Convert_Discriminant_Ref;
2586 -- Start of processing for Build_Find_Body_Index
2589 Spec := Build_Find_Body_Index_Spec (Typ);
2591 Ent := First_Entity (Typ);
2592 while Present (Ent) loop
2593 if Ekind (Ent) = E_Entry_Family then
2603 -- If the protected type has no entry families, there is a one-one
2604 -- correspondence between entry queue and entry body.
2607 Make_Simple_Return_Statement (Loc,
2608 Expression => Make_Identifier (Loc, Name_uE));
2611 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2614 -- if E <= l1 then return 1;
2615 -- elsif E <= l1 + l2 then return 2;
2620 Ent := First_Entity (Typ);
2622 Add_Object_Pointer (Loc, Typ, Decls);
2624 while Present (Ent) loop
2625 if Ekind (Ent) = E_Entry then
2626 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2628 elsif Ekind (Ent) = E_Entry_Family then
2629 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2630 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2631 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2632 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2641 Make_Simple_Return_Statement (Loc,
2642 Expression => Make_Integer_Literal (Loc, 1));
2644 elsif Nkind (Ret) = N_If_Statement then
2646 -- Ranges are in increasing order, so last one doesn't need guard
2649 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2652 Set_Else_Statements (Ret, Then_Statements (Nod));
2658 Make_Subprogram_Body (Loc,
2659 Specification => Spec,
2660 Declarations => Decls,
2661 Handled_Statement_Sequence =>
2662 Make_Handled_Sequence_Of_Statements (Loc,
2663 Statements => New_List (Ret)));
2664 end Build_Find_Body_Index;
2666 --------------------------------
2667 -- Build_Find_Body_Index_Spec --
2668 --------------------------------
2670 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2671 Loc : constant Source_Ptr := Sloc (Typ);
2672 Id : constant Entity_Id :=
2673 Make_Defining_Identifier (Loc,
2674 Chars => New_External_Name (Chars (Typ), 'F'));
2675 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2676 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2680 Make_Function_Specification (Loc,
2681 Defining_Unit_Name => Id,
2682 Parameter_Specifications => New_List (
2683 Make_Parameter_Specification (Loc,
2684 Defining_Identifier => Parm1,
2686 New_Reference_To (RTE (RE_Address), Loc)),
2688 Make_Parameter_Specification (Loc,
2689 Defining_Identifier => Parm2,
2691 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2692 Result_Definition => New_Occurrence_Of (
2693 RTE (RE_Protected_Entry_Index), Loc));
2694 end Build_Find_Body_Index_Spec;
2696 -------------------------
2697 -- Build_Master_Entity --
2698 -------------------------
2700 procedure Build_Master_Entity (E : Entity_Id) is
2701 Loc : constant Source_Ptr := Sloc (E);
2707 S := Find_Master_Scope (E);
2709 -- Nothing to do if we already built a master entity for this scope
2710 -- or if there is no task hierarchy.
2712 if Has_Master_Entity (S)
2713 or else Restriction_Active (No_Task_Hierarchy)
2718 -- Otherwise first build the master entity
2719 -- _Master : constant Master_Id := Current_Master.all;
2720 -- and insert it just before the current declaration
2723 Make_Object_Declaration (Loc,
2724 Defining_Identifier =>
2725 Make_Defining_Identifier (Loc, Name_uMaster),
2726 Constant_Present => True,
2727 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2729 Make_Explicit_Dereference (Loc,
2730 New_Reference_To (RTE (RE_Current_Master), Loc)));
2733 Insert_Before (P, Decl);
2736 Set_Has_Master_Entity (S);
2738 -- Now mark the containing scope as a task master
2740 while Nkind (P) /= N_Compilation_Unit loop
2743 -- If we fall off the top, we are at the outer level, and the
2744 -- environment task is our effective master, so nothing to mark.
2747 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2749 Set_Is_Task_Master (P, True);
2752 elsif Nkind (Parent (P)) = N_Subunit then
2753 P := Corresponding_Stub (Parent (P));
2756 end Build_Master_Entity;
2758 -----------------------------------------
2759 -- Build_Private_Protected_Declaration --
2760 -----------------------------------------
2762 function Build_Private_Protected_Declaration
2763 (N : Node_Id) return Entity_Id
2765 Loc : constant Source_Ptr := Sloc (N);
2766 Body_Id : constant Entity_Id := Defining_Entity (N);
2771 Spec_Id : Entity_Id;
2774 Formal := First_Formal (Body_Id);
2776 -- The protected operation always has at least one formal, namely the
2777 -- object itself, but it is only placed in the parameter list if
2778 -- expansion is enabled.
2780 if Present (Formal) or else Expander_Active then
2781 Plist := Copy_Parameter_List (Body_Id);
2786 if Nkind (Specification (N)) = N_Procedure_Specification then
2788 Make_Procedure_Specification (Loc,
2789 Defining_Unit_Name =>
2790 Make_Defining_Identifier (Sloc (Body_Id),
2791 Chars => Chars (Body_Id)),
2792 Parameter_Specifications =>
2796 Make_Function_Specification (Loc,
2797 Defining_Unit_Name =>
2798 Make_Defining_Identifier (Sloc (Body_Id),
2799 Chars => Chars (Body_Id)),
2800 Parameter_Specifications => Plist,
2801 Result_Definition =>
2802 New_Occurrence_Of (Etype (Body_Id), Loc));
2805 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2806 Insert_Before (N, Decl);
2807 Spec_Id := Defining_Unit_Name (New_Spec);
2809 -- Indicate that the entity comes from source, to ensure that cross-
2810 -- reference information is properly generated. The body itself is
2811 -- rewritten during expansion, and the body entity will not appear in
2812 -- calls to the operation.
2814 Set_Comes_From_Source (Spec_Id, True);
2816 Set_Has_Completion (Spec_Id);
2817 Set_Convention (Spec_Id, Convention_Protected);
2819 end Build_Private_Protected_Declaration;
2821 ---------------------------
2822 -- Build_Protected_Entry --
2823 ---------------------------
2825 function Build_Protected_Entry
2828 Pid : Node_Id) return Node_Id
2830 Loc : constant Source_Ptr := Sloc (N);
2832 Decls : constant List_Id := Declarations (N);
2833 End_Lab : constant Node_Id :=
2834 End_Label (Handled_Statement_Sequence (N));
2835 End_Loc : constant Source_Ptr :=
2836 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2837 -- Used for the generated call to Complete_Entry_Body
2839 Han_Loc : Source_Ptr;
2840 -- Used for the exception handler, inserted at end of the body
2842 Op_Decls : constant List_Id := New_List;
2850 -- Set the source location on the exception handler only when debugging
2851 -- the expanded code (see Make_Implicit_Exception_Handler).
2853 if Debug_Generated_Code then
2856 -- Otherwise the inserted code should not be visible to the debugger
2859 Han_Loc := No_Location;
2863 Make_Defining_Identifier (Loc,
2864 Chars => Chars (Protected_Body_Subprogram (Ent)));
2866 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2868 -- Add the following declarations:
2869 -- type poVP is access poV;
2870 -- _object : poVP := poVP (_O);
2872 -- where _O is the formal parameter associated with the concurrent
2873 -- object. These declarations are needed for Complete_Entry_Body.
2875 Add_Object_Pointer (Loc, Pid, Op_Decls);
2877 -- Add renamings for all formals, the Protection object, discriminals,
2878 -- privals and the entry index constant for use by debugger.
2880 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2881 Debug_Private_Data_Declarations (Decls);
2883 case Corresponding_Runtime_Package (Pid) is
2884 when System_Tasking_Protected_Objects_Entries =>
2886 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2888 when System_Tasking_Protected_Objects_Single_Entry =>
2890 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2893 raise Program_Error;
2896 Op_Stats := New_List (
2897 Make_Block_Statement (Loc,
2898 Declarations => Decls,
2899 Handled_Statement_Sequence =>
2900 Handled_Statement_Sequence (N)),
2902 Make_Procedure_Call_Statement (End_Loc,
2904 Parameter_Associations => New_List (
2905 Make_Attribute_Reference (End_Loc,
2907 Make_Selected_Component (End_Loc,
2908 Prefix => Make_Identifier (End_Loc, Name_uObject),
2909 Selector_Name => Make_Identifier (End_Loc, Name_uObject)),
2910 Attribute_Name => Name_Unchecked_Access))));
2912 -- When exceptions can not be propagated, we never need to call
2913 -- Exception_Complete_Entry_Body
2915 if No_Exception_Handlers_Set then
2917 Make_Subprogram_Body (Loc,
2918 Specification => Espec,
2919 Declarations => Op_Decls,
2920 Handled_Statement_Sequence =>
2921 Make_Handled_Sequence_Of_Statements (Loc,
2922 Statements => Op_Stats,
2923 End_Label => End_Lab));
2926 Ohandle := Make_Others_Choice (Loc);
2927 Set_All_Others (Ohandle);
2929 case Corresponding_Runtime_Package (Pid) is
2930 when System_Tasking_Protected_Objects_Entries =>
2933 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2935 when System_Tasking_Protected_Objects_Single_Entry =>
2938 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2941 raise Program_Error;
2944 -- Establish link between subprogram body entity and source entry.
2946 Set_Corresponding_Protected_Entry (Edef, Ent);
2948 -- Create body of entry procedure. The renaming declarations are
2949 -- placed ahead of the block that contains the actual entry body.
2952 Make_Subprogram_Body (Loc,
2953 Specification => Espec,
2954 Declarations => Op_Decls,
2955 Handled_Statement_Sequence =>
2956 Make_Handled_Sequence_Of_Statements (Loc,
2957 Statements => Op_Stats,
2958 End_Label => End_Lab,
2959 Exception_Handlers => New_List (
2960 Make_Implicit_Exception_Handler (Han_Loc,
2961 Exception_Choices => New_List (Ohandle),
2963 Statements => New_List (
2964 Make_Procedure_Call_Statement (Han_Loc,
2966 Parameter_Associations => New_List (
2967 Make_Attribute_Reference (Han_Loc,
2969 Make_Selected_Component (Han_Loc,
2971 Make_Identifier (Han_Loc, Name_uObject),
2973 Make_Identifier (Han_Loc, Name_uObject)),
2974 Attribute_Name => Name_Unchecked_Access),
2976 Make_Function_Call (Han_Loc,
2977 Name => New_Reference_To (
2978 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2980 end Build_Protected_Entry;
2982 -----------------------------------------
2983 -- Build_Protected_Entry_Specification --
2984 -----------------------------------------
2986 function Build_Protected_Entry_Specification
2989 Ent_Id : Entity_Id) return Node_Id
2991 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2994 Set_Debug_Info_Needed (Def_Id);
2996 if Present (Ent_Id) then
2997 Append_Elmt (P, Accept_Address (Ent_Id));
3001 Make_Procedure_Specification (Loc,
3002 Defining_Unit_Name => Def_Id,
3003 Parameter_Specifications => New_List (
3004 Make_Parameter_Specification (Loc,
3005 Defining_Identifier =>
3006 Make_Defining_Identifier (Loc, Name_uO),
3008 New_Reference_To (RTE (RE_Address), Loc)),
3010 Make_Parameter_Specification (Loc,
3011 Defining_Identifier => P,
3013 New_Reference_To (RTE (RE_Address), Loc)),
3015 Make_Parameter_Specification (Loc,
3016 Defining_Identifier =>
3017 Make_Defining_Identifier (Loc, Name_uE),
3019 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
3020 end Build_Protected_Entry_Specification;
3022 --------------------------
3023 -- Build_Protected_Spec --
3024 --------------------------
3026 function Build_Protected_Spec
3028 Obj_Type : Entity_Id;
3030 Unprotected : Boolean := False) return List_Id
3032 Loc : constant Source_Ptr := Sloc (N);
3035 New_Plist : List_Id;
3036 New_Param : Node_Id;
3039 New_Plist := New_List;
3041 Formal := First_Formal (Ident);
3042 while Present (Formal) loop
3044 Make_Parameter_Specification (Loc,
3045 Defining_Identifier =>
3046 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
3047 In_Present => In_Present (Parent (Formal)),
3048 Out_Present => Out_Present (Parent (Formal)),
3049 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
3052 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3055 Append (New_Param, New_Plist);
3056 Next_Formal (Formal);
3059 -- If the subprogram is a procedure and the context is not an access
3060 -- to protected subprogram, the parameter is in-out. Otherwise it is
3064 Make_Parameter_Specification (Loc,
3065 Defining_Identifier =>
3066 Make_Defining_Identifier (Loc, Name_uObject),
3069 (Etype (Ident) = Standard_Void_Type
3070 and then not Is_RTE (Obj_Type, RE_Address)),
3072 New_Reference_To (Obj_Type, Loc));
3073 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3074 Prepend_To (New_Plist, Decl);
3077 end Build_Protected_Spec;
3079 ---------------------------------------
3080 -- Build_Protected_Sub_Specification --
3081 ---------------------------------------
3083 function Build_Protected_Sub_Specification
3085 Prot_Typ : Entity_Id;
3086 Mode : Subprogram_Protection_Mode) return Node_Id
3088 Loc : constant Source_Ptr := Sloc (N);
3092 New_Plist : List_Id;
3095 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3096 (Dispatching_Mode => ' ',
3097 Protected_Mode => 'P',
3098 Unprotected_Mode => 'N');
3101 if Ekind (Defining_Unit_Name (Specification (N))) =
3104 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3109 Def_Id := Defining_Unit_Name (Specification (Decl));
3112 Build_Protected_Spec
3113 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3114 Mode = Unprotected_Mode);
3116 Make_Defining_Identifier (Loc,
3117 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3119 -- The unprotected operation carries the user code, and debugging
3120 -- information must be generated for it, even though this spec does
3121 -- not come from source. It is also convenient to allow gdb to step
3122 -- into the protected operation, even though it only contains lock/
3125 Set_Debug_Info_Needed (New_Id);
3127 -- If a pragma Eliminate applies to the source entity, the internal
3128 -- subprograms will be eliminated as well.
3130 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3132 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3134 Make_Procedure_Specification (Loc,
3135 Defining_Unit_Name => New_Id,
3136 Parameter_Specifications => New_Plist);
3138 -- Create a new specification for the anonymous subprogram type
3142 Make_Function_Specification (Loc,
3143 Defining_Unit_Name => New_Id,
3144 Parameter_Specifications => New_Plist,
3145 Result_Definition =>
3146 Copy_Result_Type (Result_Definition (Specification (Decl))));
3148 Set_Return_Present (Defining_Unit_Name (New_Spec));
3152 end Build_Protected_Sub_Specification;
3154 -------------------------------------
3155 -- Build_Protected_Subprogram_Body --
3156 -------------------------------------
3158 function Build_Protected_Subprogram_Body
3161 N_Op_Spec : Node_Id) return Node_Id
3163 Loc : constant Source_Ptr := Sloc (N);
3165 P_Op_Spec : Node_Id;
3168 Unprot_Call : Node_Id;
3170 Lock_Name : Node_Id;
3171 Lock_Stmt : Node_Id;
3172 Service_Name : Node_Id;
3174 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3175 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3177 Object_Parm : Node_Id;
3180 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3181 -- Tell whether a given subprogram cannot raise an exception
3183 -----------------------
3184 -- Is_Exception_Safe --
3185 -----------------------
3187 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3189 function Has_Side_Effect (N : Node_Id) return Boolean;
3190 -- Return True whenever encountering a subprogram call or raise
3191 -- statement of any kind in the sequence of statements
3193 ---------------------
3194 -- Has_Side_Effect --
3195 ---------------------
3197 -- What is this doing buried two levels down in exp_ch9. It seems
3198 -- like a generally useful function, and indeed there may be code
3199 -- duplication going on here ???
3201 function Has_Side_Effect (N : Node_Id) return Boolean is
3205 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3206 -- Indicate whether N is a subprogram call or a raise statement
3208 ----------------------
3209 -- Is_Call_Or_Raise --
3210 ----------------------
3212 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3214 return Nkind_In (N, N_Procedure_Call_Statement,
3217 N_Raise_Constraint_Error,
3218 N_Raise_Program_Error,
3219 N_Raise_Storage_Error);
3220 end Is_Call_Or_Raise;
3222 -- Start of processing for Has_Side_Effect
3226 while Present (Stmt) loop
3227 if Is_Call_Or_Raise (Stmt) then
3231 -- An object declaration can also contain a function call
3232 -- or a raise statement
3234 if Nkind (Stmt) = N_Object_Declaration then
3235 Expr := Expression (Stmt);
3237 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3246 end Has_Side_Effect;
3248 -- Start of processing for Is_Exception_Safe
3251 -- If the checks handled by the back end are not disabled, we cannot
3252 -- ensure that no exception will be raised.
3254 if not Access_Checks_Suppressed (Empty)
3255 or else not Discriminant_Checks_Suppressed (Empty)
3256 or else not Range_Checks_Suppressed (Empty)
3257 or else not Index_Checks_Suppressed (Empty)
3258 or else Opt.Stack_Checking_Enabled
3263 if Has_Side_Effect (First (Declarations (Subprogram)))
3266 First (Statements (Handled_Statement_Sequence (Subprogram))))
3272 end Is_Exception_Safe;
3274 -- Start of processing for Build_Protected_Subprogram_Body
3277 Op_Spec := Specification (N);
3278 Exc_Safe := Is_Exception_Safe (N);
3281 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3283 -- Build a list of the formal parameters of the protected version of
3284 -- the subprogram to use as the actual parameters of the unprotected
3287 Uactuals := New_List;
3288 Pformal := First (Parameter_Specifications (P_Op_Spec));
3289 while Present (Pformal) loop
3290 Append_To (Uactuals,
3291 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
3295 -- Make a call to the unprotected version of the subprogram built above
3296 -- for use by the protected version built below.
3298 if Nkind (Op_Spec) = N_Function_Specification then
3300 R := Make_Temporary (Loc, 'R');
3302 Make_Object_Declaration (Loc,
3303 Defining_Identifier => R,
3304 Constant_Present => True,
3305 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3307 Make_Function_Call (Loc,
3308 Name => Make_Identifier (Loc,
3309 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3310 Parameter_Associations => Uactuals));
3313 Make_Simple_Return_Statement (Loc,
3314 Expression => New_Reference_To (R, Loc));
3317 Unprot_Call := Make_Simple_Return_Statement (Loc,
3318 Expression => Make_Function_Call (Loc,
3320 Make_Identifier (Loc,
3321 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3322 Parameter_Associations => Uactuals));
3327 Make_Procedure_Call_Statement (Loc,
3329 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3330 Parameter_Associations => Uactuals);
3333 -- Wrap call in block that will be covered by an at_end handler
3335 if not Exc_Safe then
3336 Unprot_Call := Make_Block_Statement (Loc,
3337 Handled_Statement_Sequence =>
3338 Make_Handled_Sequence_Of_Statements (Loc,
3339 Statements => New_List (Unprot_Call)));
3342 -- Make the protected subprogram body. This locks the protected
3343 -- object and calls the unprotected version of the subprogram.
3345 case Corresponding_Runtime_Package (Pid) is
3346 when System_Tasking_Protected_Objects_Entries =>
3347 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3348 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3350 when System_Tasking_Protected_Objects_Single_Entry =>
3351 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3352 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3354 when System_Tasking_Protected_Objects =>
3355 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3356 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3359 raise Program_Error;
3363 Make_Attribute_Reference (Loc,
3365 Make_Selected_Component (Loc,
3366 Prefix => Make_Identifier (Loc, Name_uObject),
3367 Selector_Name => Make_Identifier (Loc, Name_uObject)),
3368 Attribute_Name => Name_Unchecked_Access);
3370 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3372 Parameter_Associations => New_List (Object_Parm));
3374 if Abort_Allowed then
3376 Make_Procedure_Call_Statement (Loc,
3377 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3378 Parameter_Associations => Empty_List),
3382 Stmts := New_List (Lock_Stmt);
3385 if not Exc_Safe then
3386 Append (Unprot_Call, Stmts);
3388 if Nkind (Op_Spec) = N_Function_Specification then
3390 Stmts := Empty_List;
3392 Append (Unprot_Call, Stmts);
3396 Make_Procedure_Call_Statement (Loc,
3397 Name => Service_Name,
3398 Parameter_Associations =>
3399 New_List (New_Copy_Tree (Object_Parm))),
3402 if Abort_Allowed then
3404 Make_Procedure_Call_Statement (Loc,
3405 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3406 Parameter_Associations => Empty_List),
3410 if Nkind (Op_Spec) = N_Function_Specification then
3411 Append (Return_Stmt, Stmts);
3412 Append (Make_Block_Statement (Loc,
3413 Declarations => New_List (Unprot_Call),
3414 Handled_Statement_Sequence =>
3415 Make_Handled_Sequence_Of_Statements (Loc,
3416 Statements => Stmts)), Pre_Stmts);
3422 Make_Subprogram_Body (Loc,
3423 Declarations => Empty_List,
3424 Specification => P_Op_Spec,
3425 Handled_Statement_Sequence =>
3426 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3428 if not Exc_Safe then
3429 Set_Is_Protected_Subprogram_Body (Sub_Body);
3433 end Build_Protected_Subprogram_Body;
3435 -------------------------------------
3436 -- Build_Protected_Subprogram_Call --
3437 -------------------------------------
3439 procedure Build_Protected_Subprogram_Call
3443 External : Boolean := True)
3445 Loc : constant Source_Ptr := Sloc (N);
3446 Sub : constant Entity_Id := Entity (Name);
3452 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3455 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3458 if Present (Parameter_Associations (N)) then
3459 Params := New_Copy_List_Tree (Parameter_Associations (N));
3464 -- If the type is an untagged derived type, convert to the root type,
3465 -- which is the one on which the operations are defined.
3467 if Nkind (Rec) = N_Unchecked_Type_Conversion
3468 and then not Is_Tagged_Type (Etype (Rec))
3469 and then Is_Derived_Type (Etype (Rec))
3471 Set_Etype (Rec, Root_Type (Etype (Rec)));
3472 Set_Subtype_Mark (Rec,
3473 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3476 Prepend (Rec, Params);
3478 if Ekind (Sub) = E_Procedure then
3480 Make_Procedure_Call_Statement (Loc,
3482 Parameter_Associations => Params));
3485 pragma Assert (Ekind (Sub) = E_Function);
3487 Make_Function_Call (Loc,
3489 Parameter_Associations => Params));
3493 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3494 and then Is_Entity_Name (Expression (Rec))
3495 and then Is_Shared_Passive (Entity (Expression (Rec)))
3497 Add_Shared_Var_Lock_Procs (N);
3499 end Build_Protected_Subprogram_Call;
3501 -------------------------
3502 -- Build_Selected_Name --
3503 -------------------------
3505 function Build_Selected_Name
3506 (Prefix : Entity_Id;
3507 Selector : Entity_Id;
3508 Append_Char : Character := ' ') return Name_Id
3510 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3511 Select_Len : Natural;
3514 Get_Name_String (Chars (Selector));
3515 Select_Len := Name_Len;
3516 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3517 Get_Name_String (Chars (Prefix));
3519 -- If scope is anonymous type, discard suffix to recover name of
3520 -- single protected object. Otherwise use protected type name.
3522 if Name_Buffer (Name_Len) = 'T' then
3523 Name_Len := Name_Len - 1;
3526 Add_Str_To_Name_Buffer ("__");
3527 for J in 1 .. Select_Len loop
3528 Add_Char_To_Name_Buffer (Select_Buffer (J));
3531 -- Now add the Append_Char if specified. The encoding to follow
3532 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3533 -- then the entity is associated to a protected type subprogram.
3534 -- Otherwise, it is a protected type entry. For each case, the
3535 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3537 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3539 if Append_Char /= ' ' then
3540 if Append_Char = 'P' or Append_Char = 'N' then
3541 Add_Char_To_Name_Buffer (Append_Char);
3544 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3545 return New_External_Name (Name_Find, ' ', -1);
3550 end Build_Selected_Name;
3552 -----------------------------
3553 -- Build_Simple_Entry_Call --
3554 -----------------------------
3556 -- A task entry call is converted to a call to Call_Simple
3559 -- P : parms := (parm, parm, parm);
3561 -- Call_Simple (acceptor-task, entry-index, P'Address);
3567 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3568 -- the parameters, and the constructed aggregate value contains either the
3569 -- parameters or, in the case of non-elementary types, references to these
3570 -- parameters. Then the address of this aggregate is passed to the runtime
3571 -- routine, along with the task id value and the task entry index value.
3572 -- Pnn is only required if parameters are present.
3574 -- The assignments after the call are present only in the case of in-out
3575 -- or out parameters for elementary types, and are used to assign back the
3576 -- resulting values of such parameters.
3578 -- Note: the reason that we insert a block here is that in the context
3579 -- of selects, conditional entry calls etc. the entry call statement
3580 -- appears on its own, not as an element of a list.
3582 -- A protected entry call is converted to a Protected_Entry_Call:
3585 -- P : E1_Params := (param, param, param);
3587 -- Bnn : Communications_Block;
3590 -- P : E1_Params := (param, param, param);
3591 -- Bnn : Communications_Block;
3594 -- Protected_Entry_Call (
3595 -- Object => po._object'Access,
3596 -- E => <entry index>;
3597 -- Uninterpreted_Data => P'Address;
3598 -- Mode => Simple_Call;
3605 procedure Build_Simple_Entry_Call
3614 -- If call has been inlined, nothing left to do
3616 if Nkind (N) = N_Block_Statement then
3620 -- Convert entry call to Call_Simple call
3623 Loc : constant Source_Ptr := Sloc (N);
3624 Parms : constant List_Id := Parameter_Associations (N);
3625 Stats : constant List_Id := New_List;
3628 Comm_Name : Entity_Id;
3632 Ent_Acc : Entity_Id;
3634 Iface_Tag : Entity_Id;
3635 Iface_Typ : Entity_Id;
3648 -- Simple entry and entry family cases merge here
3650 Ent := Entity (Ename);
3651 Ent_Acc := Entry_Parameters_Type (Ent);
3652 Conctyp := Etype (Concval);
3654 -- If prefix is an access type, dereference to obtain the task type
3656 if Is_Access_Type (Conctyp) then
3657 Conctyp := Designated_Type (Conctyp);
3660 -- Special case for protected subprogram calls
3662 if Is_Protected_Type (Conctyp)
3663 and then Is_Subprogram (Entity (Ename))
3665 if not Is_Eliminated (Entity (Ename)) then
3666 Build_Protected_Subprogram_Call
3667 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3674 -- First parameter is the Task_Id value from the task value or the
3675 -- Object from the protected object value, obtained by selecting
3676 -- the _Task_Id or _Object from the result of doing an unchecked
3677 -- conversion to convert the value to the corresponding record type.
3679 if Nkind (Concval) = N_Function_Call
3680 and then Is_Task_Type (Conctyp)
3681 and then Ada_Version >= Ada_2005
3684 ExpR : constant Node_Id := Relocate_Node (Concval);
3685 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3690 Make_Object_Declaration (Loc,
3691 Defining_Identifier => Obj,
3692 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3693 Expression => ExpR);
3694 Set_Etype (Obj, Conctyp);
3695 Decls := New_List (Decl);
3696 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3703 Parm1 := Concurrent_Ref (Concval);
3705 -- Second parameter is the entry index, computed by the routine
3706 -- provided for this purpose. The value of this expression is
3707 -- assigned to an intermediate variable to assure that any entry
3708 -- family index expressions are evaluated before the entry
3712 or else Restriction_Active (No_Entry_Queue) = False
3713 or else not Is_Protected_Type (Conctyp)
3714 or else Number_Entries (Conctyp) > 1
3715 or else (Has_Attach_Handler (Conctyp)
3716 and then not Restricted_Profile)
3718 X := Make_Defining_Identifier (Loc, Name_uX);
3721 Make_Object_Declaration (Loc,
3722 Defining_Identifier => X,
3723 Object_Definition =>
3724 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3725 Expression => Actual_Index_Expression (
3726 Loc, Entity (Ename), Index, Concval));
3728 Append_To (Decls, Xdecl);
3729 Parm2 := New_Reference_To (X, Loc);
3736 -- The third parameter is the packaged parameters. If there are
3737 -- none, then it is just the null address, since nothing is passed.
3740 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3743 -- Case of parameters present, where third argument is the address
3744 -- of a packaged record containing the required parameter values.
3747 -- First build a list of parameter values, which are references to
3748 -- objects of the parameter types.
3752 Actual := First_Actual (N);
3753 Formal := First_Formal (Ent);
3755 while Present (Actual) loop
3757 -- If it is a by_copy_type, copy it to a new variable. The
3758 -- packaged record has a field that points to this variable.
3760 if Is_By_Copy_Type (Etype (Actual)) then
3762 Make_Object_Declaration (Loc,
3763 Defining_Identifier => Make_Temporary (Loc, 'J'),
3764 Aliased_Present => True,
3765 Object_Definition =>
3766 New_Reference_To (Etype (Formal), Loc));
3768 -- Mark the object as not needing initialization since the
3769 -- initialization is performed separately, avoiding errors
3770 -- on cases such as formals of null-excluding access types.
3772 Set_No_Initialization (N_Node);
3774 -- We must make an assignment statement separate for the
3775 -- case of limited type. We cannot assign it unless the
3776 -- Assignment_OK flag is set first. An out formal of an
3777 -- access type must also be initialized from the actual,
3778 -- as stated in RM 6.4.1 (13).
3780 if Ekind (Formal) /= E_Out_Parameter
3781 or else Is_Access_Type (Etype (Formal))
3784 New_Reference_To (Defining_Identifier (N_Node), Loc);
3785 Set_Assignment_OK (N_Var);
3787 Make_Assignment_Statement (Loc,
3789 Expression => Relocate_Node (Actual)));
3792 Append (N_Node, Decls);
3795 Make_Attribute_Reference (Loc,
3796 Attribute_Name => Name_Unchecked_Access,
3798 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3800 -- If it is a vm_by_copy_actual, copy it to a new variable
3802 elsif Is_VM_By_Copy_Actual (Actual) then
3804 Make_Object_Declaration (Loc,
3805 Defining_Identifier => Make_Temporary (Loc, 'J'),
3806 Aliased_Present => True,
3807 Object_Definition =>
3808 New_Reference_To (Etype (Formal), Loc),
3809 Expression => New_Copy_Tree (Actual));
3810 Set_Assignment_OK (N_Node);
3812 Append (N_Node, Decls);
3815 Make_Attribute_Reference (Loc,
3816 Attribute_Name => Name_Unchecked_Access,
3818 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3821 -- Interface class-wide formal
3823 if Ada_Version >= Ada_2005
3824 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3825 and then Is_Interface (Etype (Formal))
3827 Iface_Typ := Etype (Etype (Formal));
3830 -- formal_iface_type! (actual.iface_tag)'reference
3833 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3834 pragma Assert (Present (Iface_Tag));
3837 Make_Reference (Loc,
3838 Unchecked_Convert_To (Iface_Typ,
3839 Make_Selected_Component (Loc,
3841 Relocate_Node (Actual),
3843 New_Reference_To (Iface_Tag, Loc)))));
3849 Make_Reference (Loc, Relocate_Node (Actual)));
3853 Next_Actual (Actual);
3854 Next_Formal_With_Extras (Formal);
3857 -- Now build the declaration of parameters initialized with the
3858 -- aggregate containing this constructed parameter list.
3860 P := Make_Defining_Identifier (Loc, Name_uP);
3863 Make_Object_Declaration (Loc,
3864 Defining_Identifier => P,
3865 Object_Definition =>
3866 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3868 Make_Aggregate (Loc, Expressions => Plist));
3871 Make_Attribute_Reference (Loc,
3872 Prefix => New_Reference_To (P, Loc),
3873 Attribute_Name => Name_Address);
3875 Append (Pdecl, Decls);
3878 -- Now we can create the call, case of protected type
3880 if Is_Protected_Type (Conctyp) then
3881 case Corresponding_Runtime_Package (Conctyp) is
3882 when System_Tasking_Protected_Objects_Entries =>
3884 -- Change the type of the index declaration
3886 Set_Object_Definition (Xdecl,
3887 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3889 -- Some additional declarations for protected entry calls
3895 -- Bnn : Communications_Block;
3897 Comm_Name := Make_Temporary (Loc, 'B');
3900 Make_Object_Declaration (Loc,
3901 Defining_Identifier => Comm_Name,
3902 Object_Definition =>
3903 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3905 -- Some additional statements for protected entry calls
3907 -- Protected_Entry_Call (
3908 -- Object => po._object'Access,
3909 -- E => <entry index>;
3910 -- Uninterpreted_Data => P'Address;
3911 -- Mode => Simple_Call;
3915 Make_Procedure_Call_Statement (Loc,
3917 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3919 Parameter_Associations => New_List (
3920 Make_Attribute_Reference (Loc,
3921 Attribute_Name => Name_Unchecked_Access,
3925 New_Reference_To (RTE (RE_Simple_Call), Loc),
3926 New_Occurrence_Of (Comm_Name, Loc)));
3928 when System_Tasking_Protected_Objects_Single_Entry =>
3929 -- Protected_Single_Entry_Call (
3930 -- Object => po._object'Access,
3931 -- Uninterpreted_Data => P'Address;
3932 -- Mode => Simple_Call);
3935 Make_Procedure_Call_Statement (Loc,
3936 Name => New_Reference_To (
3937 RTE (RE_Protected_Single_Entry_Call), Loc),
3939 Parameter_Associations => New_List (
3940 Make_Attribute_Reference (Loc,
3941 Attribute_Name => Name_Unchecked_Access,
3944 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3947 raise Program_Error;
3950 -- Case of task type
3954 Make_Procedure_Call_Statement (Loc,
3955 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3956 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3960 Append_To (Stats, Call);
3962 -- If there are out or in/out parameters by copy add assignment
3963 -- statements for the result values.
3965 if Present (Parms) then
3966 Actual := First_Actual (N);
3967 Formal := First_Formal (Ent);
3969 Set_Assignment_OK (Actual);
3970 while Present (Actual) loop
3971 if (Is_By_Copy_Type (Etype (Actual))
3972 or else Is_VM_By_Copy_Actual (Actual))
3973 and then Ekind (Formal) /= E_In_Parameter
3976 Make_Assignment_Statement (Loc,
3977 Name => New_Copy (Actual),
3979 Make_Explicit_Dereference (Loc,
3980 Make_Selected_Component (Loc,
3981 Prefix => New_Reference_To (P, Loc),
3983 Make_Identifier (Loc, Chars (Formal)))));
3985 -- In all cases (including limited private types) we want
3986 -- the assignment to be valid.
3988 Set_Assignment_OK (Name (N_Node));
3990 -- If the call is the triggering alternative in an
3991 -- asynchronous select, or the entry_call alternative of a
3992 -- conditional entry call, the assignments for in-out
3993 -- parameters are incorporated into the statement list that
3994 -- follows, so that there are executed only if the entry
3997 if (Nkind (Parent (N)) = N_Triggering_Alternative
3998 and then N = Triggering_Statement (Parent (N)))
4000 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4001 and then N = Entry_Call_Statement (Parent (N)))
4003 if No (Statements (Parent (N))) then
4004 Set_Statements (Parent (N), New_List);
4007 Prepend (N_Node, Statements (Parent (N)));
4010 Insert_After (Call, N_Node);
4014 Next_Actual (Actual);
4015 Next_Formal_With_Extras (Formal);
4019 -- Finally, create block and analyze it
4022 Make_Block_Statement (Loc,
4023 Declarations => Decls,
4024 Handled_Statement_Sequence =>
4025 Make_Handled_Sequence_Of_Statements (Loc,
4026 Statements => Stats)));
4030 end Build_Simple_Entry_Call;
4032 --------------------------------
4033 -- Build_Task_Activation_Call --
4034 --------------------------------
4036 procedure Build_Task_Activation_Call (N : Node_Id) is
4037 Loc : constant Source_Ptr := Sloc (N);
4044 -- Get the activation chain entity. Except in the case of a package
4045 -- body, this is in the node that was passed. For a package body, we
4046 -- have to find the corresponding package declaration node.
4048 if Nkind (N) = N_Package_Body then
4049 P := Corresponding_Spec (N);
4052 exit when Nkind (P) = N_Package_Declaration;
4055 Chain := Activation_Chain_Entity (P);
4058 Chain := Activation_Chain_Entity (N);
4061 if Present (Chain) then
4062 if Restricted_Profile then
4063 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
4065 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4069 Make_Procedure_Call_Statement (Loc,
4071 Parameter_Associations =>
4072 New_List (Make_Attribute_Reference (Loc,
4073 Prefix => New_Occurrence_Of (Chain, Loc),
4074 Attribute_Name => Name_Unchecked_Access)));
4076 if Nkind (N) = N_Package_Declaration then
4077 if Present (Corresponding_Body (N)) then
4080 elsif Present (Private_Declarations (Specification (N))) then
4081 Append (Call, Private_Declarations (Specification (N)));
4084 Append (Call, Visible_Declarations (Specification (N)));
4088 if Present (Handled_Statement_Sequence (N)) then
4090 -- The call goes at the start of the statement sequence
4091 -- after the start of exception range label if one is present.
4097 Stm := First (Statements (Handled_Statement_Sequence (N)));
4099 -- A special case, skip exception range label if one is
4100 -- present (from front end zcx processing).
4102 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4106 -- Another special case, if the first statement is a block
4107 -- from optimization of a local raise to a goto, then the
4108 -- call goes inside this block.
4110 if Nkind (Stm) = N_Block_Statement
4111 and then Exception_Junk (Stm)
4114 First (Statements (Handled_Statement_Sequence (Stm)));
4117 -- Insertion point is after any exception label pushes,
4118 -- since we want it covered by any local handlers.
4120 while Nkind (Stm) in N_Push_xxx_Label loop
4124 -- Now we have the proper insertion point
4126 Insert_Before (Stm, Call);
4130 Set_Handled_Statement_Sequence (N,
4131 Make_Handled_Sequence_Of_Statements (Loc,
4132 Statements => New_List (Call)));
4137 Check_Task_Activation (N);
4139 end Build_Task_Activation_Call;
4141 -------------------------------
4142 -- Build_Task_Allocate_Block --
4143 -------------------------------
4145 procedure Build_Task_Allocate_Block
4150 T : constant Entity_Id := Entity (Expression (N));
4151 Init : constant Entity_Id := Base_Init_Proc (T);
4152 Loc : constant Source_Ptr := Sloc (N);
4153 Chain : constant Entity_Id :=
4154 Make_Defining_Identifier (Loc, Name_uChain);
4155 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4160 Make_Block_Statement (Loc,
4161 Identifier => New_Reference_To (Blkent, Loc),
4162 Declarations => New_List (
4164 -- _Chain : Activation_Chain;
4166 Make_Object_Declaration (Loc,
4167 Defining_Identifier => Chain,
4168 Aliased_Present => True,
4169 Object_Definition =>
4170 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4172 Handled_Statement_Sequence =>
4173 Make_Handled_Sequence_Of_Statements (Loc,
4175 Statements => New_List (
4179 Make_Procedure_Call_Statement (Loc,
4180 Name => New_Reference_To (Init, Loc),
4181 Parameter_Associations => Args),
4183 -- Activate_Tasks (_Chain);
4185 Make_Procedure_Call_Statement (Loc,
4186 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4187 Parameter_Associations => New_List (
4188 Make_Attribute_Reference (Loc,
4189 Prefix => New_Reference_To (Chain, Loc),
4190 Attribute_Name => Name_Unchecked_Access))))),
4192 Has_Created_Identifier => True,
4193 Is_Task_Allocation_Block => True);
4196 Make_Implicit_Label_Declaration (Loc,
4197 Defining_Identifier => Blkent,
4198 Label_Construct => Block));
4200 Append_To (Actions, Block);
4202 Set_Activation_Chain_Entity (Block, Chain);
4203 end Build_Task_Allocate_Block;
4205 -----------------------------------------------
4206 -- Build_Task_Allocate_Block_With_Init_Stmts --
4207 -----------------------------------------------
4209 procedure Build_Task_Allocate_Block_With_Init_Stmts
4212 Init_Stmts : List_Id)
4214 Loc : constant Source_Ptr := Sloc (N);
4215 Chain : constant Entity_Id :=
4216 Make_Defining_Identifier (Loc, Name_uChain);
4217 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4221 Append_To (Init_Stmts,
4222 Make_Procedure_Call_Statement (Loc,
4223 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4224 Parameter_Associations => New_List (
4225 Make_Attribute_Reference (Loc,
4226 Prefix => New_Reference_To (Chain, Loc),
4227 Attribute_Name => Name_Unchecked_Access))));
4230 Make_Block_Statement (Loc,
4231 Identifier => New_Reference_To (Blkent, Loc),
4232 Declarations => New_List (
4234 -- _Chain : Activation_Chain;
4236 Make_Object_Declaration (Loc,
4237 Defining_Identifier => Chain,
4238 Aliased_Present => True,
4239 Object_Definition =>
4240 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4242 Handled_Statement_Sequence =>
4243 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4245 Has_Created_Identifier => True,
4246 Is_Task_Allocation_Block => True);
4249 Make_Implicit_Label_Declaration (Loc,
4250 Defining_Identifier => Blkent,
4251 Label_Construct => Block));
4253 Append_To (Actions, Block);
4255 Set_Activation_Chain_Entity (Block, Chain);
4256 end Build_Task_Allocate_Block_With_Init_Stmts;
4258 -----------------------------------
4259 -- Build_Task_Proc_Specification --
4260 -----------------------------------
4262 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4263 Loc : constant Source_Ptr := Sloc (T);
4264 Spec_Id : Entity_Id;
4267 -- Case of explicit task type, suffix TB
4269 if Comes_From_Source (T) then
4271 Make_Defining_Identifier (Loc,
4272 Chars => New_External_Name (Chars (T), "TB"));
4274 -- Case of anonymous task type, suffix B
4278 Make_Defining_Identifier (Loc,
4279 Chars => New_External_Name (Chars (T), 'B'));
4282 Set_Is_Internal (Spec_Id);
4284 -- Associate the procedure with the task, if this is the declaration
4285 -- (and not the body) of the procedure.
4287 if No (Task_Body_Procedure (T)) then
4288 Set_Task_Body_Procedure (T, Spec_Id);
4292 Make_Procedure_Specification (Loc,
4293 Defining_Unit_Name => Spec_Id,
4294 Parameter_Specifications => New_List (
4295 Make_Parameter_Specification (Loc,
4296 Defining_Identifier =>
4297 Make_Defining_Identifier (Loc, Name_uTask),
4299 Make_Access_Definition (Loc,
4301 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4302 end Build_Task_Proc_Specification;
4304 ---------------------------------------
4305 -- Build_Unprotected_Subprogram_Body --
4306 ---------------------------------------
4308 function Build_Unprotected_Subprogram_Body
4310 Pid : Node_Id) return Node_Id
4312 Decls : constant List_Id := Declarations (N);
4315 -- Add renamings for the Protection object, discriminals, privals and
4316 -- the entry index constant for use by debugger.
4318 Debug_Private_Data_Declarations (Decls);
4320 -- Make an unprotected version of the subprogram for use within the same
4321 -- object, with a new name and an additional parameter representing the
4325 Make_Subprogram_Body (Sloc (N),
4327 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4328 Declarations => Decls,
4329 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4330 end Build_Unprotected_Subprogram_Body;
4332 ----------------------------
4333 -- Collect_Entry_Families --
4334 ----------------------------
4336 procedure Collect_Entry_Families
4339 Current_Node : in out Node_Id;
4340 Conctyp : Entity_Id)
4343 Efam_Decl : Node_Id;
4344 Efam_Type : Entity_Id;
4347 Efam := First_Entity (Conctyp);
4348 while Present (Efam) loop
4349 if Ekind (Efam) = E_Entry_Family then
4350 Efam_Type := Make_Temporary (Loc, 'F');
4355 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4357 Bas_Decl : Node_Id := Empty;
4362 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4364 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4365 Bas := Make_Temporary (Loc, 'B');
4368 Make_Subtype_Declaration (Loc,
4369 Defining_Identifier => Bas,
4370 Subtype_Indication =>
4371 Make_Subtype_Indication (Loc,
4373 New_Occurrence_Of (Standard_Integer, Loc),
4375 Make_Range_Constraint (Loc,
4376 Range_Expression => Make_Range (Loc,
4377 Make_Integer_Literal
4378 (Loc, -Entry_Family_Bound),
4379 Make_Integer_Literal
4380 (Loc, Entry_Family_Bound - 1)))));
4382 Insert_After (Current_Node, Bas_Decl);
4383 Current_Node := Bas_Decl;
4388 Make_Full_Type_Declaration (Loc,
4389 Defining_Identifier => Efam_Type,
4391 Make_Unconstrained_Array_Definition (Loc,
4393 (New_List (New_Occurrence_Of (Bas, Loc))),
4395 Component_Definition =>
4396 Make_Component_Definition (Loc,
4397 Aliased_Present => False,
4398 Subtype_Indication =>
4399 New_Reference_To (Standard_Character, Loc))));
4402 Insert_After (Current_Node, Efam_Decl);
4403 Current_Node := Efam_Decl;
4404 Analyze (Efam_Decl);
4407 Make_Component_Declaration (Loc,
4408 Defining_Identifier =>
4409 Make_Defining_Identifier (Loc, Chars (Efam)),
4411 Component_Definition =>
4412 Make_Component_Definition (Loc,
4413 Aliased_Present => False,
4414 Subtype_Indication =>
4415 Make_Subtype_Indication (Loc,
4417 New_Occurrence_Of (Efam_Type, Loc),
4420 Make_Index_Or_Discriminant_Constraint (Loc,
4421 Constraints => New_List (
4423 (Etype (Discrete_Subtype_Definition
4424 (Parent (Efam))), Loc)))))));
4430 end Collect_Entry_Families;
4432 -----------------------
4433 -- Concurrent_Object --
4434 -----------------------
4436 function Concurrent_Object
4437 (Spec_Id : Entity_Id;
4438 Conc_Typ : Entity_Id) return Entity_Id
4441 -- Parameter _O or _object
4443 if Is_Protected_Type (Conc_Typ) then
4444 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4449 pragma Assert (Is_Task_Type (Conc_Typ));
4450 return First_Formal (Task_Body_Procedure (Conc_Typ));
4452 end Concurrent_Object;
4454 ----------------------
4455 -- Copy_Result_Type --
4456 ----------------------
4458 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4459 New_Res : constant Node_Id := New_Copy_Tree (Res);
4464 -- If the result type is an access_to_subprogram, we must create
4465 -- new entities for its spec.
4467 if Nkind (New_Res) = N_Access_Definition
4468 and then Present (Access_To_Subprogram_Definition (New_Res))
4470 -- Provide new entities for the formals
4472 Par_Spec := First (Parameter_Specifications
4473 (Access_To_Subprogram_Definition (New_Res)));
4474 while Present (Par_Spec) loop
4475 Formal := Defining_Identifier (Par_Spec);
4476 Set_Defining_Identifier (Par_Spec,
4477 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4483 end Copy_Result_Type;
4485 --------------------
4486 -- Concurrent_Ref --
4487 --------------------
4489 -- The expression returned for a reference to a concurrent object has the
4492 -- taskV!(name)._Task_Id
4496 -- objectV!(name)._Object
4498 -- for a protected object. For the case of an access to a concurrent
4499 -- object, there is an extra explicit dereference:
4501 -- taskV!(name.all)._Task_Id
4502 -- objectV!(name.all)._Object
4504 -- here taskV and objectV are the types for the associated records, which
4505 -- contain the required _Task_Id and _Object fields for tasks and protected
4506 -- objects, respectively.
4508 -- For the case of a task type name, the expression is
4512 -- i.e. a call to the Self function which returns precisely this Task_Id
4514 -- For the case of a protected type name, the expression is
4518 -- which is a renaming of the _object field of the current object
4519 -- record, passed into protected operations as a parameter.
4521 function Concurrent_Ref (N : Node_Id) return Node_Id is
4522 Loc : constant Source_Ptr := Sloc (N);
4523 Ntyp : constant Entity_Id := Etype (N);
4527 function Is_Current_Task (T : Entity_Id) return Boolean;
4528 -- Check whether the reference is to the immediately enclosing task
4529 -- type, or to an outer one (rare but legal).
4531 ---------------------
4532 -- Is_Current_Task --
4533 ---------------------
4535 function Is_Current_Task (T : Entity_Id) return Boolean is
4539 Scop := Current_Scope;
4540 while Present (Scop)
4541 and then Scop /= Standard_Standard
4547 elsif Is_Task_Type (Scop) then
4550 -- If this is a procedure nested within the task type, we must
4551 -- assume that it can be called from an inner task, and therefore
4552 -- cannot treat it as a local reference.
4554 elsif Is_Overloadable (Scop)
4555 and then In_Open_Scopes (T)
4560 Scop := Scope (Scop);
4564 -- We know that we are within the task body, so should have found it
4567 raise Program_Error;
4568 end Is_Current_Task;
4570 -- Start of processing for Concurrent_Ref
4573 if Is_Access_Type (Ntyp) then
4574 Dtyp := Designated_Type (Ntyp);
4576 if Is_Protected_Type (Dtyp) then
4577 Sel := Name_uObject;
4579 Sel := Name_uTask_Id;
4583 Make_Selected_Component (Loc,
4585 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4586 Make_Explicit_Dereference (Loc, N)),
4587 Selector_Name => Make_Identifier (Loc, Sel));
4589 elsif Is_Entity_Name (N)
4590 and then Is_Concurrent_Type (Entity (N))
4592 if Is_Task_Type (Entity (N)) then
4594 if Is_Current_Task (Entity (N)) then
4596 Make_Function_Call (Loc,
4597 Name => New_Reference_To (RTE (RE_Self), Loc));
4602 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4603 T_Body : constant Node_Id :=
4604 Parent (Corresponding_Body (Parent (Entity (N))));
4608 Make_Object_Declaration (Loc,
4609 Defining_Identifier => T_Self,
4610 Object_Definition =>
4611 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4613 Make_Function_Call (Loc,
4614 Name => New_Reference_To (RTE (RE_Self), Loc)));
4615 Prepend (Decl, Declarations (T_Body));
4617 Set_Scope (T_Self, Entity (N));
4618 return New_Occurrence_Of (T_Self, Loc);
4623 pragma Assert (Is_Protected_Type (Entity (N)));
4626 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4630 if Is_Protected_Type (Ntyp) then
4631 Sel := Name_uObject;
4633 elsif Is_Task_Type (Ntyp) then
4634 Sel := Name_uTask_Id;
4637 raise Program_Error;
4641 Make_Selected_Component (Loc,
4643 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4645 Selector_Name => Make_Identifier (Loc, Sel));
4649 ------------------------
4650 -- Convert_Concurrent --
4651 ------------------------
4653 function Convert_Concurrent
4655 Typ : Entity_Id) return Node_Id
4658 if not Is_Concurrent_Type (Typ) then
4662 Unchecked_Convert_To
4663 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4665 end Convert_Concurrent;
4667 -------------------------------------
4668 -- Debug_Private_Data_Declarations --
4669 -------------------------------------
4671 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4672 Debug_Nod : Node_Id;
4676 Decl := First (Decls);
4677 while Present (Decl)
4678 and then not Comes_From_Source (Decl)
4680 -- Declaration for concurrent entity _object and its access type,
4681 -- along with the entry index subtype:
4682 -- type prot_typVP is access prot_typV;
4683 -- _object : prot_typVP := prot_typV (_O);
4684 -- subtype Jnn is <Type of Index> range Low .. High;
4686 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4687 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4689 -- Declaration for the Protection object, discriminals, privals and
4690 -- entry index constant:
4691 -- conc_typR : protection_typ renames _object._object;
4692 -- discr_nameD : discr_typ renames _object.discr_name;
4693 -- discr_nameD : discr_typ renames _task.discr_name;
4694 -- prival_name : comp_typ renames _object.comp_name;
4695 -- J : constant Jnn :=
4696 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4698 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4699 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4700 Debug_Nod := Debug_Renaming_Declaration (Decl);
4702 if Present (Debug_Nod) then
4703 Insert_After (Decl, Debug_Nod);
4709 end Debug_Private_Data_Declarations;
4711 ----------------------------
4712 -- Entry_Index_Expression --
4713 ----------------------------
4715 function Entry_Index_Expression
4719 Ttyp : Entity_Id) return Node_Id
4729 -- The queues of entries and entry families appear in textual order in
4730 -- the associated record. The entry index is computed as the sum of the
4731 -- number of queues for all entries that precede the designated one, to
4732 -- which is added the index expression, if this expression denotes a
4733 -- member of a family.
4735 -- The following is a place holder for the count of simple entries
4737 Num := Make_Integer_Literal (Sloc, 1);
4739 -- We construct an expression which is a series of addition operations.
4740 -- The first operand is the number of single entries that precede this
4741 -- one, the second operand is the index value relative to the start of
4742 -- the referenced family, and the remaining operands are the lengths of
4743 -- the entry families that precede this entry, i.e. the constructed
4746 -- number_simple_entries +
4747 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4748 -- family'length + ...
4750 -- where index-value is the given index value, and s is the index
4751 -- subtype (we have to use pos because the subtype might be an
4752 -- enumeration type preventing direct subtraction). Note that the task
4753 -- entry array is one-indexed.
4755 -- The upper bound of the entry family may be a discriminant, so we
4756 -- retrieve the lower bound explicitly to compute offset, rather than
4757 -- using the index subtype which may mention a discriminant.
4759 if Present (Index) then
4760 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4769 Make_Attribute_Reference (Sloc,
4770 Attribute_Name => Name_Pos,
4771 Prefix => New_Reference_To (Base_Type (S), Sloc),
4772 Expressions => New_List (Relocate_Node (Index))),
4780 -- Now add lengths of preceding entries and entry families
4782 Prev := First_Entity (Ttyp);
4784 while Chars (Prev) /= Chars (Ent)
4785 or else (Ekind (Prev) /= Ekind (Ent))
4786 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4788 if Ekind (Prev) = E_Entry then
4789 Set_Intval (Num, Intval (Num) + 1);
4791 elsif Ekind (Prev) = E_Entry_Family then
4793 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4794 Lo := Type_Low_Bound (S);
4795 Hi := Type_High_Bound (S);
4800 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4802 -- Other components are anonymous types to be ignored
4812 end Entry_Index_Expression;
4814 ---------------------------
4815 -- Establish_Task_Master --
4816 ---------------------------
4818 procedure Establish_Task_Master (N : Node_Id) is
4821 if Restriction_Active (No_Task_Hierarchy) = False then
4822 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4823 Prepend_To (Declarations (N), Call);
4826 end Establish_Task_Master;
4828 --------------------------------
4829 -- Expand_Accept_Declarations --
4830 --------------------------------
4832 -- Part of the expansion of an accept statement involves the creation of
4833 -- a declaration that can be referenced from the statement sequence of
4838 -- This declaration is inserted immediately before the accept statement
4839 -- and it is important that it be inserted before the statements of the
4840 -- statement sequence are analyzed. Thus it would be too late to create
4841 -- this declaration in the Expand_N_Accept_Statement routine, which is
4842 -- why there is a separate procedure to be called directly from Sem_Ch9.
4844 -- Ann is used to hold the address of the record containing the parameters
4845 -- (see Expand_N_Entry_Call for more details on how this record is built).
4846 -- References to the parameters do an unchecked conversion of this address
4847 -- to a pointer to the required record type, and then access the field that
4848 -- holds the value of the required parameter. The entity for the address
4849 -- variable is held as the top stack element (i.e. the last element) of the
4850 -- Accept_Address stack in the corresponding entry entity, and this element
4851 -- must be set in place before the statements are processed.
4853 -- The above description applies to the case of a stand alone accept
4854 -- statement, i.e. one not appearing as part of a select alternative.
4856 -- For the case of an accept that appears as part of a select alternative
4857 -- of a selective accept, we must still create the declaration right away,
4858 -- since Ann is needed immediately, but there is an important difference:
4860 -- The declaration is inserted before the selective accept, not before
4861 -- the accept statement (which is not part of a list anyway, and so would
4862 -- not accommodate inserted declarations)
4864 -- We only need one address variable for the entire selective accept. So
4865 -- the Ann declaration is created only for the first accept alternative,
4866 -- and subsequent accept alternatives reference the same Ann variable.
4868 -- We can distinguish the two cases by seeing whether the accept statement
4869 -- is part of a list. If not, then it must be in an accept alternative.
4871 -- To expand the requeue statement, a label is provided at the end of the
4872 -- accept statement or alternative of which it is a part, so that the
4873 -- statement can be skipped after the requeue is complete. This label is
4874 -- created here rather than during the expansion of the accept statement,
4875 -- because it will be needed by any requeue statements within the accept,
4876 -- which are expanded before the accept.
4878 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4879 Loc : constant Source_Ptr := Sloc (N);
4880 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4881 Ann : Entity_Id := Empty;
4889 if Expander_Active then
4891 -- If we have no handled statement sequence, we may need to build
4892 -- a dummy sequence consisting of a null statement. This can be
4893 -- skipped if the trivial accept optimization is permitted.
4895 if not Trivial_Accept_OK
4897 (No (Stats) or else Null_Statements (Statements (Stats)))
4899 Set_Handled_Statement_Sequence (N,
4900 Make_Handled_Sequence_Of_Statements (Loc,
4901 New_List (Make_Null_Statement (Loc))));
4904 -- Create and declare two labels to be placed at the end of the
4905 -- accept statement. The first label is used to allow requeues to
4906 -- skip the remainder of entry processing. The second label is used
4907 -- to skip the remainder of entry processing if the rendezvous
4908 -- completes in the middle of the accept body.
4910 if Present (Handled_Statement_Sequence (N)) then
4915 Ent := Make_Temporary (Loc, 'L');
4916 Lab_Id := New_Reference_To (Ent, Loc);
4917 Lab := Make_Label (Loc, Lab_Id);
4919 Make_Implicit_Label_Declaration (Loc,
4920 Defining_Identifier => Ent,
4921 Label_Construct => Lab);
4922 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4924 Ent := Make_Temporary (Loc, 'L');
4925 Lab_Id := New_Reference_To (Ent, Loc);
4926 Lab := Make_Label (Loc, Lab_Id);
4928 Make_Implicit_Label_Declaration (Loc,
4929 Defining_Identifier => Ent,
4930 Label_Construct => Lab);
4931 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4939 -- Case of stand alone accept statement
4941 if Is_List_Member (N) then
4943 if Present (Handled_Statement_Sequence (N)) then
4944 Ann := Make_Temporary (Loc, 'A');
4947 Make_Object_Declaration (Loc,
4948 Defining_Identifier => Ann,
4949 Object_Definition =>
4950 New_Reference_To (RTE (RE_Address), Loc));
4952 Insert_Before (N, Adecl);
4955 Insert_Before (N, Ldecl);
4958 Insert_Before (N, Ldecl2);
4962 -- Case of accept statement which is in an accept alternative
4966 Acc_Alt : constant Node_Id := Parent (N);
4967 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4971 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4972 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4974 -- ??? Consider a single label for select statements
4976 if Present (Handled_Statement_Sequence (N)) then
4978 Statements (Handled_Statement_Sequence (N)));
4982 Statements (Handled_Statement_Sequence (N)));
4986 -- Find first accept alternative of the selective accept. A
4987 -- valid selective accept must have at least one accept in it.
4989 Alt := First (Select_Alternatives (Sel_Acc));
4991 while Nkind (Alt) /= N_Accept_Alternative loop
4995 -- If we are the first accept statement, then we have to create
4996 -- the Ann variable, as for the stand alone case, except that
4997 -- it is inserted before the selective accept. Similarly, a
4998 -- label for requeue expansion must be declared.
5000 if N = Accept_Statement (Alt) then
5001 Ann := Make_Temporary (Loc, 'A');
5003 Make_Object_Declaration (Loc,
5004 Defining_Identifier => Ann,
5005 Object_Definition =>
5006 New_Reference_To (RTE (RE_Address), Loc));
5008 Insert_Before (Sel_Acc, Adecl);
5011 -- If we are not the first accept statement, then find the Ann
5012 -- variable allocated by the first accept and use it.
5016 Node (Last_Elmt (Accept_Address
5017 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
5022 -- Merge here with Ann either created or referenced, and Adecl
5023 -- pointing to the corresponding declaration. Remaining processing
5024 -- is the same for the two cases.
5026 if Present (Ann) then
5027 Append_Elmt (Ann, Accept_Address (Ent));
5028 Set_Debug_Info_Needed (Ann);
5031 -- Create renaming declarations for the entry formals. Each reference
5032 -- to a formal becomes a dereference of a component of the parameter
5033 -- block, whose address is held in Ann. These declarations are
5034 -- eventually inserted into the accept block, and analyzed there so
5035 -- that they have the proper scope for gdb and do not conflict with
5036 -- other declarations.
5038 if Present (Parameter_Specifications (N))
5039 and then Present (Handled_Statement_Sequence (N))
5046 Renamed_Formal : Node_Id;
5050 Formal := First_Formal (Ent);
5052 while Present (Formal) loop
5053 Comp := Entry_Component (Formal);
5055 Make_Defining_Identifier (Loc, Chars (Formal));
5057 Set_Etype (New_F, Etype (Formal));
5058 Set_Scope (New_F, Ent);
5060 -- Now we set debug info needed on New_F even though it does
5061 -- not come from source, so that the debugger will get the
5062 -- right information for these generated names.
5064 Set_Debug_Info_Needed (New_F);
5066 if Ekind (Formal) = E_In_Parameter then
5067 Set_Ekind (New_F, E_Constant);
5069 Set_Ekind (New_F, E_Variable);
5070 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5073 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5076 Make_Selected_Component (Loc,
5078 Unchecked_Convert_To (
5079 Entry_Parameters_Type (Ent),
5080 New_Reference_To (Ann, Loc)),
5082 New_Reference_To (Comp, Loc));
5085 Build_Renamed_Formal_Declaration
5086 (New_F, Formal, Comp, Renamed_Formal);
5088 if No (Declarations (N)) then
5089 Set_Declarations (N, New_List);
5092 Append (Decl, Declarations (N));
5093 Set_Renamed_Object (Formal, New_F);
5094 Next_Formal (Formal);
5101 end Expand_Accept_Declarations;
5103 ---------------------------------------------
5104 -- Expand_Access_Protected_Subprogram_Type --
5105 ---------------------------------------------
5107 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5108 Loc : constant Source_Ptr := Sloc (N);
5110 T : constant Entity_Id := Defining_Identifier (N);
5111 D_T : constant Entity_Id := Designated_Type (T);
5112 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5113 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5114 P_List : constant List_Id := Build_Protected_Spec
5115 (N, RTE (RE_Address), D_T, False);
5121 -- Create access to subprogram with full signature
5123 if Etype (D_T) /= Standard_Void_Type then
5125 Make_Access_Function_Definition (Loc,
5126 Parameter_Specifications => P_List,
5127 Result_Definition =>
5128 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5132 Make_Access_Procedure_Definition (Loc,
5133 Parameter_Specifications => P_List);
5137 Make_Full_Type_Declaration (Loc,
5138 Defining_Identifier => D_T2,
5139 Type_Definition => Def1);
5141 Insert_After (N, Decl1);
5144 -- Associate the access to subprogram with its original access to
5145 -- protected subprogram type. Needed by the backend to know that this
5146 -- type corresponds with an access to protected subprogram type.
5148 Set_Original_Access_Type (D_T2, T);
5150 -- Create Equivalent_Type, a record with two components for an access to
5151 -- object and an access to subprogram.
5154 Make_Component_Declaration (Loc,
5155 Defining_Identifier => Make_Temporary (Loc, 'P'),
5156 Component_Definition =>
5157 Make_Component_Definition (Loc,
5158 Aliased_Present => False,
5159 Subtype_Indication =>
5160 New_Occurrence_Of (RTE (RE_Address), Loc))),
5162 Make_Component_Declaration (Loc,
5163 Defining_Identifier => Make_Temporary (Loc, 'S'),
5164 Component_Definition =>
5165 Make_Component_Definition (Loc,
5166 Aliased_Present => False,
5167 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5170 Make_Full_Type_Declaration (Loc,
5171 Defining_Identifier => E_T,
5173 Make_Record_Definition (Loc,
5175 Make_Component_List (Loc,
5176 Component_Items => Comps)));
5178 Insert_After (Decl1, Decl2);
5180 Set_Equivalent_Type (T, E_T);
5181 end Expand_Access_Protected_Subprogram_Type;
5183 --------------------------
5184 -- Expand_Entry_Barrier --
5185 --------------------------
5187 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5188 Cond : constant Node_Id :=
5189 Condition (Entry_Body_Formal_Part (N));
5190 Prot : constant Entity_Id := Scope (Ent);
5191 Spec_Decl : constant Node_Id := Parent (Prot);
5194 Body_Decl : Node_Id;
5197 if No_Run_Time_Mode then
5198 Error_Msg_CRT ("entry barrier", N);
5202 -- The body of the entry barrier must be analyzed in the context of the
5203 -- protected object, but its scope is external to it, just as any other
5204 -- unprotected version of a protected operation. The specification has
5205 -- been produced when the protected type declaration was elaborated. We
5206 -- build the body, insert it in the enclosing scope, but analyze it in
5207 -- the current context. A more uniform approach would be to treat the
5208 -- barrier just as a protected function, and discard the protected
5209 -- version of it because it is never called.
5211 if Expander_Active then
5212 B_F := Build_Barrier_Function (N, Ent, Prot);
5213 Func := Barrier_Function (Ent);
5214 Set_Corresponding_Spec (B_F, Func);
5216 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5218 if Nkind (Parent (Body_Decl)) = N_Subunit then
5219 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5222 Insert_Before_And_Analyze (Body_Decl, B_F);
5224 Set_Discriminals (Spec_Decl);
5225 Set_Scope (Func, Scope (Prot));
5228 Analyze_And_Resolve (Cond, Any_Boolean);
5231 -- The Ravenscar profile restricts barriers to simple variables declared
5232 -- within the protected object. We also allow Boolean constants, since
5233 -- these appear in several published examples and are also allowed by
5234 -- the Aonix compiler.
5236 -- Note that after analysis variables in this context will be replaced
5237 -- by the corresponding prival, that is to say a renaming of a selected
5238 -- component of the form _Object.Var. If expansion is disabled, as
5239 -- within a generic, we check that the entity appears in the current
5242 if Is_Entity_Name (Cond) then
5244 -- A small optimization of useless renamings. If the scope of the
5245 -- entity of the condition is not the barrier function, then the
5246 -- condition does not reference any of the generated renamings
5247 -- within the function.
5250 and then Scope (Entity (Cond)) /= Func
5252 Set_Declarations (B_F, Empty_List);
5255 if Entity (Cond) = Standard_False
5257 Entity (Cond) = Standard_True
5261 elsif not Expander_Active
5262 and then Scope (Entity (Cond)) = Current_Scope
5266 -- Check for case of _object.all.field (note that the explicit
5267 -- dereference gets inserted by analyze/expand of _object.field)
5269 elsif Present (Renamed_Object (Entity (Cond)))
5271 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5275 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5281 -- It is not a boolean variable or literal, so check the restriction
5283 Check_Restriction (Simple_Barriers, Cond);
5284 end Expand_Entry_Barrier;
5286 ------------------------------
5287 -- Expand_N_Abort_Statement --
5288 ------------------------------
5290 -- Expand abort T1, T2, .. Tn; into:
5291 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5293 procedure Expand_N_Abort_Statement (N : Node_Id) is
5294 Loc : constant Source_Ptr := Sloc (N);
5295 Tlist : constant List_Id := Names (N);
5301 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5304 Tasknm := First (Tlist);
5306 while Present (Tasknm) loop
5309 -- A task interface class-wide type object is being aborted.
5310 -- Retrieve its _task_id by calling a dispatching routine.
5312 if Ada_Version >= Ada_2005
5313 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5314 and then Is_Interface (Etype (Tasknm))
5315 and then Is_Task_Interface (Etype (Tasknm))
5317 Append_To (Component_Associations (Aggr),
5318 Make_Component_Association (Loc,
5319 Choices => New_List (
5320 Make_Integer_Literal (Loc, Count)),
5323 -- Task_Id (Tasknm._disp_get_task_id)
5325 Make_Unchecked_Type_Conversion (Loc,
5327 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5329 Make_Selected_Component (Loc,
5330 Prefix => New_Copy_Tree (Tasknm),
5332 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5335 Append_To (Component_Associations (Aggr),
5336 Make_Component_Association (Loc,
5337 Choices => New_List (
5338 Make_Integer_Literal (Loc, Count)),
5339 Expression => Concurrent_Ref (Tasknm)));
5346 Make_Procedure_Call_Statement (Loc,
5347 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5348 Parameter_Associations => New_List (
5349 Make_Qualified_Expression (Loc,
5350 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5351 Expression => Aggr))));
5354 end Expand_N_Abort_Statement;
5356 -------------------------------
5357 -- Expand_N_Accept_Statement --
5358 -------------------------------
5360 -- This procedure handles expansion of accept statements that stand
5361 -- alone, i.e. they are not part of an accept alternative. The expansion
5362 -- of accept statement in accept alternatives is handled by the routines
5363 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5364 -- following description applies only to stand alone accept statements.
5366 -- If there is no handled statement sequence, or only null statements,
5367 -- then this is called a trivial accept, and the expansion is:
5369 -- Accept_Trivial (entry-index)
5371 -- If there is a handled statement sequence, then the expansion is:
5378 -- Accept_Call (entry-index, Ann);
5379 -- Renaming_Declarations for formals
5380 -- <statement sequence from N_Accept_Statement node>
5381 -- Complete_Rendezvous;
5386 -- <exception handler from N_Accept_Statement node>
5387 -- Complete_Rendezvous;
5389 -- <exception handler from N_Accept_Statement node>
5390 -- Complete_Rendezvous;
5395 -- when all others =>
5396 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5399 -- The first three declarations were already inserted ahead of the accept
5400 -- statement by the Expand_Accept_Declarations procedure, which was called
5401 -- directly from the semantics during analysis of the accept statement,
5402 -- before analyzing its contained statements.
5404 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5405 -- from possible expansion activity (the original source of course does
5406 -- not have any declarations associated with the accept statement, since
5407 -- an accept statement has no declarative part). In particular, if the
5408 -- expander is active, the first such declaration is the declaration of
5409 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5411 -- The two blocks are merged into a single block if the inner block has
5412 -- no exception handlers, but otherwise two blocks are required, since
5413 -- exceptions might be raised in the exception handlers of the inner
5414 -- block, and Exceptional_Complete_Rendezvous must be called.
5416 procedure Expand_N_Accept_Statement (N : Node_Id) is
5417 Loc : constant Source_Ptr := Sloc (N);
5418 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5419 Ename : constant Node_Id := Entry_Direct_Name (N);
5420 Eindx : constant Node_Id := Entry_Index (N);
5421 Eent : constant Entity_Id := Entity (Ename);
5422 Acstack : constant Elist_Id := Accept_Address (Eent);
5423 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5424 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5429 -- Start of processing for Expand_N_Accept_Statement
5432 -- If accept statement is not part of a list, then its parent must be
5433 -- an accept alternative, and, as described above, we do not do any
5434 -- expansion for such accept statements at this level.
5436 if not Is_List_Member (N) then
5437 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5440 -- Trivial accept case (no statement sequence, or null statements).
5441 -- If the accept statement has declarations, then just insert them
5442 -- before the procedure call.
5444 elsif Trivial_Accept_OK
5445 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5447 -- Remove declarations for renamings, because the parameter block
5448 -- will not be assigned.
5455 D := First (Declarations (N));
5457 while Present (D) loop
5459 if Nkind (D) = N_Object_Renaming_Declaration then
5467 if Present (Declarations (N)) then
5468 Insert_Actions (N, Declarations (N));
5472 Make_Procedure_Call_Statement (Loc,
5473 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5474 Parameter_Associations => New_List (
5475 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5479 -- Discard Entry_Address that was created for it, so it will not be
5480 -- emitted if this accept statement is in the statement part of a
5481 -- delay alternative.
5483 if Present (Stats) then
5484 Remove_Last_Elmt (Acstack);
5487 -- Case of statement sequence present
5490 -- Construct the block, using the declarations from the accept
5491 -- statement if any to initialize the declarations of the block.
5493 Blkent := Make_Temporary (Loc, 'A');
5494 Set_Ekind (Blkent, E_Block);
5495 Set_Etype (Blkent, Standard_Void_Type);
5496 Set_Scope (Blkent, Current_Scope);
5499 Make_Block_Statement (Loc,
5500 Identifier => New_Reference_To (Blkent, Loc),
5501 Declarations => Declarations (N),
5502 Handled_Statement_Sequence => Build_Accept_Body (N));
5504 -- For the analysis of the generated declarations, the parent node
5505 -- must be properly set.
5507 Set_Parent (Block, Parent (N));
5509 -- Prepend call to Accept_Call to main statement sequence If the
5510 -- accept has exception handlers, the statement sequence is wrapped
5511 -- in a block. Insert call and renaming declarations in the
5512 -- declarations of the block, so they are elaborated before the
5516 Make_Procedure_Call_Statement (Loc,
5517 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5518 Parameter_Associations => New_List (
5519 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5520 New_Reference_To (Ann, Loc)));
5522 if Parent (Stats) = N then
5523 Prepend (Call, Statements (Stats));
5532 Push_Scope (Blkent);
5540 D := First (Declarations (N));
5541 while Present (D) loop
5544 if Nkind (D) = N_Object_Renaming_Declaration then
5546 -- The renaming declarations for the formals were created
5547 -- during analysis of the accept statement, and attached to
5548 -- the list of declarations. Place them now in the context
5549 -- of the accept block or subprogram.
5552 Typ := Entity (Subtype_Mark (D));
5553 Insert_After (Call, D);
5556 -- If the formal is class_wide, it does not have an actual
5557 -- subtype. The analysis of the renaming declaration creates
5558 -- one, but we need to retain the class-wide nature of the
5561 if Is_Class_Wide_Type (Typ) then
5562 Set_Etype (Defining_Identifier (D), Typ);
5573 -- Replace the accept statement by the new block
5578 -- Last step is to unstack the Accept_Address value
5580 Remove_Last_Elmt (Acstack);
5582 end Expand_N_Accept_Statement;
5584 ----------------------------------
5585 -- Expand_N_Asynchronous_Select --
5586 ----------------------------------
5588 -- This procedure assumes that the trigger statement is an entry call or
5589 -- a dispatching procedure call. A delay alternative should already have
5590 -- been expanded into an entry call to the appropriate delay object Wait
5593 -- If the trigger is a task entry call, the select is implemented with
5594 -- a Task_Entry_Call:
5599 -- P : parms := (parm, parm, parm);
5601 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5603 -- procedure _clean is
5606 -- Cancel_Task_Entry_Call (C);
5613 -- (<acceptor-task>, -- Acceptor
5614 -- <entry-index>, -- E
5615 -- P'Address, -- Uninterpreted_Data
5616 -- Asynchronous_Call, -- Mode
5617 -- B); -- Rendezvous_Successful
5624 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5627 -- when Abort_Signal => Abort_Undefer;
5634 -- <triggered-statements>
5638 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5639 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5643 -- P : parms := (parm, parm, parm);
5645 -- Call_Simple (acceptor-task, entry-index, P'Address);
5651 -- so the task at hand is to convert the latter expansion into the former
5653 -- If the trigger is a protected entry call, the select is implemented
5654 -- with Protected_Entry_Call:
5657 -- P : E1_Params := (param, param, param);
5658 -- Bnn : Communications_Block;
5663 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5665 -- procedure _clean is
5668 -- if Enqueued (Bnn) then
5669 -- Cancel_Protected_Entry_Call (Bnn);
5676 -- Protected_Entry_Call
5677 -- (po._object'Access, -- Object
5678 -- <entry index>, -- E
5679 -- P'Address, -- Uninterpreted_Data
5680 -- Asynchronous_Call, -- Mode
5683 -- if Enqueued (Bnn) then
5687 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5690 -- when Abort_Signal => Abort_Undefer;
5693 -- if not Cancelled (Bnn) then
5694 -- <triggered-statements>
5698 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5702 -- P : E1_Params := (param, param, param);
5703 -- Bnn : Communications_Block;
5706 -- Protected_Entry_Call
5707 -- (po._object'Access, -- Object
5708 -- <entry index>, -- E
5709 -- P'Address, -- Uninterpreted_Data
5710 -- Simple_Call, -- Mode
5717 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5721 -- B : Boolean := False;
5722 -- Bnn : Communication_Block;
5723 -- C : Ada.Tags.Prim_Op_Kind;
5724 -- D : System.Storage_Elements.Dummy_Communication_Block;
5725 -- K : Ada.Tags.Tagged_Kind :=
5726 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5727 -- P : Parameters := (Param1 .. ParamN);
5732 -- if K = Ada.Tags.TK_Limited_Tagged then
5733 -- <dispatching-call>;
5734 -- <triggering-statements>;
5738 -- Ada.Tags.Get_Offset_Index
5739 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5741 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5743 -- if C = POK_Protected_Entry then
5745 -- procedure _clean is
5747 -- if Enqueued (Bnn) then
5748 -- Cancel_Protected_Entry_Call (Bnn);
5754 -- _Disp_Asynchronous_Select
5755 -- (<object>, S, P'Address, D, B);
5756 -- Bnn := Communication_Block (D);
5758 -- Param1 := P.Param1;
5760 -- ParamN := P.ParamN;
5762 -- if Enqueued (Bnn) then
5763 -- <abortable-statements>
5766 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5769 -- when Abort_Signal => Abort_Undefer;
5772 -- if not Cancelled (Bnn) then
5773 -- <triggering-statements>
5776 -- elsif C = POK_Task_Entry then
5778 -- procedure _clean is
5780 -- Cancel_Task_Entry_Call (U);
5786 -- _Disp_Asynchronous_Select
5787 -- (<object>, S, P'Address, D, B);
5788 -- Bnn := Communication_Bloc (D);
5790 -- Param1 := P.Param1;
5792 -- ParamN := P.ParamN;
5797 -- <abortable-statements>
5799 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5802 -- when Abort_Signal => Abort_Undefer;
5806 -- <triggering-statements>
5811 -- <dispatching-call>;
5812 -- <triggering-statements>
5817 -- The job is to convert this to the asynchronous form
5819 -- If the trigger is a delay statement, it will have been expanded into a
5820 -- call to one of the GNARL delay procedures. This routine will convert
5821 -- this into a protected entry call on a delay object and then continue
5822 -- processing as for a protected entry call trigger. This requires
5823 -- declaring a Delay_Block object and adding a pointer to this object to
5824 -- the parameter list of the delay procedure to form the parameter list of
5825 -- the entry call. This object is used by the runtime to queue the delay
5828 -- For a description of the use of P and the assignments after the call,
5829 -- see Expand_N_Entry_Call_Statement.
5831 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5832 Loc : constant Source_Ptr := Sloc (N);
5833 Abrt : constant Node_Id := Abortable_Part (N);
5834 Astats : constant List_Id := Statements (Abrt);
5835 Trig : constant Node_Id := Triggering_Alternative (N);
5836 Tstats : constant List_Id := Statements (Trig);
5838 Abort_Block_Ent : Entity_Id;
5839 Abortable_Block : Node_Id;
5841 Blk_Ent : Entity_Id;
5842 Blk_Typ : Entity_Id;
5844 Call_Ent : Entity_Id;
5845 Cancel_Param : Entity_Id;
5846 Cleanup_Block : Node_Id;
5847 Cleanup_Block_Ent : Entity_Id;
5848 Cleanup_Stmts : List_Id;
5849 Conc_Typ_Stmts : List_Id;
5851 Dblock_Ent : Entity_Id;
5856 Enqueue_Call : Node_Id;
5860 Lim_Typ_Stmts : List_Id;
5866 ProtE_Stmts : List_Id;
5867 ProtP_Stmts : List_Id;
5870 Target_Undefer : RE_Id;
5871 TaskE_Stmts : List_Id;
5872 Undefer_Args : List_Id := No_List;
5874 B : Entity_Id; -- Call status flag
5875 Bnn : Entity_Id; -- Communication block
5876 C : Entity_Id; -- Call kind
5877 K : Entity_Id; -- Tagged kind
5878 P : Entity_Id; -- Parameter block
5879 S : Entity_Id; -- Primitive operation slot
5880 T : Entity_Id; -- Additional status flag
5883 Blk_Ent := Make_Temporary (Loc, 'A');
5884 Ecall := Triggering_Statement (Trig);
5886 -- The arguments in the call may require dynamic allocation, and the
5887 -- call statement may have been transformed into a block. The block
5888 -- may contain additional declarations for internal entities, and the
5889 -- original call is found by sequential search.
5891 if Nkind (Ecall) = N_Block_Statement then
5892 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5893 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5894 N_Entry_Call_Statement)
5900 -- This is either a dispatching call or a delay statement used as a
5901 -- trigger which was expanded into a procedure call.
5903 if Nkind (Ecall) = N_Procedure_Call_Statement then
5904 if Ada_Version >= Ada_2005
5906 (No (Original_Node (Ecall))
5907 or else not Nkind_In (Original_Node (Ecall),
5908 N_Delay_Relative_Statement,
5909 N_Delay_Until_Statement))
5911 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5916 -- Call status flag processing, generate:
5917 -- B : Boolean := False;
5919 B := Build_B (Loc, Decls);
5921 -- Communication block processing, generate:
5922 -- Bnn : Communication_Block;
5924 Bnn := Make_Temporary (Loc, 'B');
5926 Make_Object_Declaration (Loc,
5927 Defining_Identifier => Bnn,
5928 Object_Definition =>
5929 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5931 -- Call kind processing, generate:
5932 -- C : Ada.Tags.Prim_Op_Kind;
5934 C := Build_C (Loc, Decls);
5936 -- Tagged kind processing, generate:
5937 -- K : Ada.Tags.Tagged_Kind :=
5938 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5940 -- Dummy communication block, generate:
5941 -- D : Dummy_Communication_Block;
5944 Make_Object_Declaration (Loc,
5945 Defining_Identifier =>
5946 Make_Defining_Identifier (Loc, Name_uD),
5947 Object_Definition =>
5949 RTE (RE_Dummy_Communication_Block), Loc)));
5951 K := Build_K (Loc, Decls, Obj);
5953 -- Parameter block processing
5955 Blk_Typ := Build_Parameter_Block
5956 (Loc, Actuals, Formals, Decls);
5957 P := Parameter_Block_Pack
5958 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5960 -- Dispatch table slot processing, generate:
5963 S := Build_S (Loc, Decls);
5965 -- Additional status flag processing, generate:
5968 T := Make_Temporary (Loc, 'T');
5970 Make_Object_Declaration (Loc,
5971 Defining_Identifier => T,
5972 Object_Definition =>
5973 New_Reference_To (Standard_Boolean, Loc)));
5975 ------------------------------
5976 -- Protected entry handling --
5977 ------------------------------
5980 -- Param1 := P.Param1;
5982 -- ParamN := P.ParamN;
5984 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5987 -- Bnn := Communication_Block (D);
5989 Prepend_To (Cleanup_Stmts,
5990 Make_Assignment_Statement (Loc,
5992 New_Reference_To (Bnn, Loc),
5994 Make_Unchecked_Type_Conversion (Loc,
5996 New_Reference_To (RTE (RE_Communication_Block), Loc),
5997 Expression => Make_Identifier (Loc, Name_uD))));
6000 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6002 Prepend_To (Cleanup_Stmts,
6003 Make_Procedure_Call_Statement (Loc,
6006 Find_Prim_Op (Etype (Etype (Obj)),
6007 Name_uDisp_Asynchronous_Select),
6009 Parameter_Associations =>
6011 New_Copy_Tree (Obj), -- <object>
6012 New_Reference_To (S, Loc), -- S
6013 Make_Attribute_Reference (Loc, -- P'Address
6015 New_Reference_To (P, Loc),
6018 Make_Identifier (Loc, Name_uD), -- D
6019 New_Reference_To (B, Loc)))); -- B
6022 -- if Enqueued (Bnn) then
6023 -- <abortable-statements>
6026 Append_To (Cleanup_Stmts,
6027 Make_If_Statement (Loc,
6029 Make_Function_Call (Loc,
6031 New_Reference_To (RTE (RE_Enqueued), Loc),
6032 Parameter_Associations =>
6034 New_Reference_To (Bnn, Loc))),
6037 New_Copy_List_Tree (Astats)));
6039 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6040 -- will then generate a _clean for the communication block Bnn.
6044 -- procedure _clean is
6046 -- if Enqueued (Bnn) then
6047 -- Cancel_Protected_Entry_Call (Bnn);
6056 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6058 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6060 -- Wrap the cleanup block in an exception handling block
6066 -- when Abort_Signal => Abort_Undefer;
6069 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6072 Make_Implicit_Label_Declaration (Loc,
6073 Defining_Identifier =>
6077 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6080 -- if not Cancelled (Bnn) then
6081 -- <triggering-statements>
6084 Append_To (ProtE_Stmts,
6085 Make_If_Statement (Loc,
6089 Make_Function_Call (Loc,
6091 New_Reference_To (RTE (RE_Cancelled), Loc),
6092 Parameter_Associations =>
6094 New_Reference_To (Bnn, Loc)))),
6097 New_Copy_List_Tree (Tstats)));
6099 -------------------------
6100 -- Task entry handling --
6101 -------------------------
6104 -- Param1 := P.Param1;
6106 -- ParamN := P.ParamN;
6108 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6111 -- Bnn := Communication_Block (D);
6113 Append_To (TaskE_Stmts,
6114 Make_Assignment_Statement (Loc,
6116 New_Reference_To (Bnn, Loc),
6118 Make_Unchecked_Type_Conversion (Loc,
6120 New_Reference_To (RTE (RE_Communication_Block), Loc),
6121 Expression => Make_Identifier (Loc, Name_uD))));
6124 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6126 Prepend_To (TaskE_Stmts,
6127 Make_Procedure_Call_Statement (Loc,
6130 Find_Prim_Op (Etype (Etype (Obj)),
6131 Name_uDisp_Asynchronous_Select),
6133 Parameter_Associations =>
6135 New_Copy_Tree (Obj), -- <object>
6136 New_Reference_To (S, Loc), -- S
6137 Make_Attribute_Reference (Loc, -- P'Address
6139 New_Reference_To (P, Loc),
6142 Make_Identifier (Loc, Name_uD), -- D
6143 New_Reference_To (B, Loc)))); -- B
6148 Prepend_To (TaskE_Stmts,
6149 Make_Procedure_Call_Statement (Loc,
6151 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6152 Parameter_Associations =>
6157 -- <abortable-statements>
6159 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6161 Prepend_To (Cleanup_Stmts,
6162 Make_Procedure_Call_Statement (Loc,
6164 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6165 Parameter_Associations =>
6168 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6169 -- will generate a _clean for the additional status flag.
6173 -- procedure _clean is
6175 -- Cancel_Task_Entry_Call (U);
6183 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6185 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6187 -- Wrap the cleanup block in an exception handling block
6193 -- when Abort_Signal => Abort_Undefer;
6196 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6198 Append_To (TaskE_Stmts,
6199 Make_Implicit_Label_Declaration (Loc,
6200 Defining_Identifier => Abort_Block_Ent));
6202 Append_To (TaskE_Stmts,
6204 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6208 -- <triggering-statements>
6211 Append_To (TaskE_Stmts,
6212 Make_If_Statement (Loc,
6216 New_Reference_To (T, Loc)),
6219 New_Copy_List_Tree (Tstats)));
6221 ----------------------------------
6222 -- Protected procedure handling --
6223 ----------------------------------
6226 -- <dispatching-call>;
6227 -- <triggering-statements>
6229 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6230 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6233 -- S := Ada.Tags.Get_Offset_Index
6234 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6237 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6240 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6242 Append_To (Conc_Typ_Stmts,
6243 Make_Procedure_Call_Statement (Loc,
6246 Find_Prim_Op (Etype (Etype (Obj)),
6247 Name_uDisp_Get_Prim_Op_Kind),
6249 Parameter_Associations =>
6251 New_Copy_Tree (Obj),
6252 New_Reference_To (S, Loc),
6253 New_Reference_To (C, Loc))));
6256 -- if C = POK_Procedure_Entry then
6258 -- elsif C = POK_Task_Entry then
6264 Append_To (Conc_Typ_Stmts,
6265 Make_If_Statement (Loc,
6269 New_Reference_To (C, Loc),
6271 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6278 Make_Elsif_Part (Loc,
6282 New_Reference_To (C, Loc),
6284 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6293 -- <dispatching-call>;
6294 -- <triggering-statements>
6296 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6297 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6300 -- if K = Ada.Tags.TK_Limited_Tagged then
6307 Make_If_Statement (Loc,
6311 New_Reference_To (K, Loc),
6313 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6322 Make_Block_Statement (Loc,
6325 Handled_Statement_Sequence =>
6326 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6331 -- Delay triggering statement processing
6334 -- Add a Delay_Block object to the parameter list of the delay
6335 -- procedure to form the parameter list of the Wait entry call.
6337 Dblock_Ent := Make_Temporary (Loc, 'D');
6339 Pdef := Entity (Name (Ecall));
6341 if Is_RTE (Pdef, RO_CA_Delay_For) then
6343 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6345 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6347 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6349 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6350 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6353 Append_To (Parameter_Associations (Ecall),
6354 Make_Attribute_Reference (Loc,
6355 Prefix => New_Reference_To (Dblock_Ent, Loc),
6356 Attribute_Name => Name_Unchecked_Access));
6358 -- Create the inner block to protect the abortable part
6361 Make_Implicit_Exception_Handler (Loc,
6362 Exception_Choices =>
6363 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6364 Statements => New_List (
6365 Make_Procedure_Call_Statement (Loc,
6366 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6369 Make_Procedure_Call_Statement (Loc,
6370 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6373 Make_Block_Statement (Loc,
6374 Identifier => New_Reference_To (Blk_Ent, Loc),
6375 Handled_Statement_Sequence =>
6376 Make_Handled_Sequence_Of_Statements (Loc,
6377 Statements => Astats),
6378 Has_Created_Identifier => True,
6379 Is_Asynchronous_Call_Block => True);
6381 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6384 Make_Implicit_If_Statement (N,
6385 Condition => Make_Function_Call (Loc,
6386 Name => Enqueue_Call,
6387 Parameter_Associations => Parameter_Associations (Ecall)),
6389 New_List (Make_Block_Statement (Loc,
6390 Handled_Statement_Sequence =>
6391 Make_Handled_Sequence_Of_Statements (Loc,
6392 Statements => New_List (
6393 Make_Implicit_Label_Declaration (Loc,
6394 Defining_Identifier => Blk_Ent,
6395 Label_Construct => Abortable_Block),
6397 Exception_Handlers => Hdle)))));
6399 Stmts := New_List (Ecall);
6401 -- Construct statement sequence for new block
6404 Make_Implicit_If_Statement (N,
6405 Condition => Make_Function_Call (Loc,
6406 Name => New_Reference_To (
6407 RTE (RE_Timed_Out), Loc),
6408 Parameter_Associations => New_List (
6409 Make_Attribute_Reference (Loc,
6410 Prefix => New_Reference_To (Dblock_Ent, Loc),
6411 Attribute_Name => Name_Unchecked_Access))),
6412 Then_Statements => Tstats));
6414 -- The result is the new block
6416 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6419 Make_Block_Statement (Loc,
6420 Declarations => New_List (
6421 Make_Object_Declaration (Loc,
6422 Defining_Identifier => Dblock_Ent,
6423 Aliased_Present => True,
6424 Object_Definition => New_Reference_To (
6425 RTE (RE_Delay_Block), Loc))),
6427 Handled_Statement_Sequence =>
6428 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6438 Extract_Entry (Ecall, Concval, Ename, Index);
6439 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6441 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6442 Decls := Declarations (Ecall);
6444 if Is_Protected_Type (Etype (Concval)) then
6446 -- Get the declarations of the block expanded from the entry call
6448 Decl := First (Decls);
6449 while Present (Decl)
6451 (Nkind (Decl) /= N_Object_Declaration
6452 or else not Is_RTE (Etype (Object_Definition (Decl)),
6453 RE_Communication_Block))
6458 pragma Assert (Present (Decl));
6459 Cancel_Param := Defining_Identifier (Decl);
6461 -- Change the mode of the Protected_Entry_Call call
6463 -- Protected_Entry_Call (
6464 -- Object => po._object'Access,
6465 -- E => <entry index>;
6466 -- Uninterpreted_Data => P'Address;
6467 -- Mode => Asynchronous_Call;
6470 Stmt := First (Stmts);
6472 -- Skip assignments to temporaries created for in-out parameters
6474 -- This makes unwarranted assumptions about the shape of the expanded
6475 -- tree for the call, and should be cleaned up ???
6477 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6483 Param := First (Parameter_Associations (Call));
6484 while Present (Param)
6485 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6490 pragma Assert (Present (Param));
6491 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6494 -- Append an if statement to execute the abortable part
6497 -- if Enqueued (Bnn) then
6500 Make_Implicit_If_Statement (N,
6501 Condition => Make_Function_Call (Loc,
6502 Name => New_Reference_To (
6503 RTE (RE_Enqueued), Loc),
6504 Parameter_Associations => New_List (
6505 New_Reference_To (Cancel_Param, Loc))),
6506 Then_Statements => Astats));
6509 Make_Block_Statement (Loc,
6510 Identifier => New_Reference_To (Blk_Ent, Loc),
6511 Handled_Statement_Sequence =>
6512 Make_Handled_Sequence_Of_Statements (Loc,
6513 Statements => Stmts),
6514 Has_Created_Identifier => True,
6515 Is_Asynchronous_Call_Block => True);
6517 -- For the VM call Update_Exception instead of Abort_Undefer.
6518 -- See 4jexcept.ads for an explanation.
6520 if VM_Target = No_VM then
6521 Target_Undefer := RE_Abort_Undefer;
6523 Target_Undefer := RE_Update_Exception;
6525 New_List (Make_Function_Call (Loc,
6526 Name => New_Occurrence_Of
6527 (RTE (RE_Current_Target_Exception), Loc)));
6531 Make_Block_Statement (Loc,
6532 Handled_Statement_Sequence =>
6533 Make_Handled_Sequence_Of_Statements (Loc,
6534 Statements => New_List (
6535 Make_Implicit_Label_Declaration (Loc,
6536 Defining_Identifier => Blk_Ent,
6537 Label_Construct => Abortable_Block),
6542 Exception_Handlers => New_List (
6543 Make_Implicit_Exception_Handler (Loc,
6545 -- when Abort_Signal =>
6546 -- Abort_Undefer.all;
6548 Exception_Choices =>
6549 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6550 Statements => New_List (
6551 Make_Procedure_Call_Statement (Loc,
6552 Name => New_Reference_To (
6553 RTE (Target_Undefer), Loc),
6554 Parameter_Associations => Undefer_Args)))))),
6556 -- if not Cancelled (Bnn) then
6557 -- triggered statements
6560 Make_Implicit_If_Statement (N,
6561 Condition => Make_Op_Not (Loc,
6563 Make_Function_Call (Loc,
6564 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6565 Parameter_Associations => New_List (
6566 New_Occurrence_Of (Cancel_Param, Loc)))),
6567 Then_Statements => Tstats));
6569 -- Asynchronous task entry call
6576 B := Make_Defining_Identifier (Loc, Name_uB);
6578 -- Insert declaration of B in declarations of existing block
6581 Make_Object_Declaration (Loc,
6582 Defining_Identifier => B,
6583 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6585 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6587 -- Insert declaration of C in declarations of existing block
6590 Make_Object_Declaration (Loc,
6591 Defining_Identifier => Cancel_Param,
6592 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6594 -- Remove and save the call to Call_Simple
6596 Stmt := First (Stmts);
6598 -- Skip assignments to temporaries created for in-out parameters.
6599 -- This makes unwarranted assumptions about the shape of the expanded
6600 -- tree for the call, and should be cleaned up ???
6602 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6608 -- Create the inner block to protect the abortable part
6611 Make_Implicit_Exception_Handler (Loc,
6612 Exception_Choices =>
6613 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6616 Make_Procedure_Call_Statement (Loc,
6617 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6620 Make_Procedure_Call_Statement (Loc,
6621 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6624 Make_Block_Statement (Loc,
6625 Identifier => New_Reference_To (Blk_Ent, Loc),
6626 Handled_Statement_Sequence =>
6627 Make_Handled_Sequence_Of_Statements (Loc,
6628 Statements => Astats),
6629 Has_Created_Identifier => True,
6630 Is_Asynchronous_Call_Block => True);
6633 Make_Block_Statement (Loc,
6634 Handled_Statement_Sequence =>
6635 Make_Handled_Sequence_Of_Statements (Loc,
6636 Statements => New_List (
6637 Make_Implicit_Label_Declaration (Loc,
6638 Defining_Identifier =>
6643 Exception_Handlers => Hdle)));
6645 -- Create new call statement
6647 Params := Parameter_Associations (Call);
6650 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6652 New_Reference_To (B, Loc));
6655 Make_Procedure_Call_Statement (Loc,
6657 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6658 Parameter_Associations => Params));
6660 -- Construct statement sequence for new block
6663 Make_Implicit_If_Statement (N,
6666 New_Reference_To (Cancel_Param, Loc)),
6667 Then_Statements => Tstats));
6669 -- Protected the call against abort
6672 Make_Procedure_Call_Statement (Loc,
6673 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6674 Parameter_Associations => Empty_List));
6677 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6679 -- The result is the new block
6682 Make_Block_Statement (Loc,
6683 Declarations => Decls,
6684 Handled_Statement_Sequence =>
6685 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6688 end Expand_N_Asynchronous_Select;
6690 -------------------------------------
6691 -- Expand_N_Conditional_Entry_Call --
6692 -------------------------------------
6694 -- The conditional task entry call is converted to a call to
6699 -- P : parms := (parm, parm, parm);
6703 -- (<acceptor-task>, -- Acceptor
6704 -- <entry-index>, -- E
6705 -- P'Address, -- Uninterpreted_Data
6706 -- Conditional_Call, -- Mode
6707 -- B); -- Rendezvous_Successful
6712 -- normal-statements
6718 -- For a description of the use of P and the assignments after the call,
6719 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6720 -- conditional entry call has already been expanded (by the Expand_N_Entry
6721 -- _Call_Statement procedure) as follows:
6724 -- P : parms := (parm, parm, parm);
6726 -- ... info for in-out parameters
6727 -- Call_Simple (acceptor-task, entry-index, P'Address);
6733 -- so the task at hand is to convert the latter expansion into the former
6735 -- The conditional protected entry call is converted to a call to
6736 -- Protected_Entry_Call:
6739 -- P : parms := (parm, parm, parm);
6740 -- Bnn : Communications_Block;
6743 -- Protected_Entry_Call
6744 -- (po._object'Access, -- Object
6745 -- <entry index>, -- E
6746 -- P'Address, -- Uninterpreted_Data
6747 -- Conditional_Call, -- Mode
6752 -- if Cancelled (Bnn) then
6755 -- normal-statements
6759 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6763 -- B : Boolean := False;
6764 -- C : Ada.Tags.Prim_Op_Kind;
6765 -- K : Ada.Tags.Tagged_Kind :=
6766 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6767 -- P : Parameters := (Param1 .. ParamN);
6771 -- if K = Ada.Tags.TK_Limited_Tagged then
6772 -- <dispatching-call>;
6773 -- <triggering-statements>
6777 -- Ada.Tags.Get_Offset_Index
6778 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6780 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6782 -- if C = POK_Protected_Entry
6783 -- or else C = POK_Task_Entry
6785 -- Param1 := P.Param1;
6787 -- ParamN := P.ParamN;
6791 -- if C = POK_Procedure
6792 -- or else C = POK_Protected_Procedure
6793 -- or else C = POK_Task_Procedure
6795 -- <dispatching-call>;
6798 -- <triggering-statements>
6800 -- <else-statements>
6805 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6806 Loc : constant Source_Ptr := Sloc (N);
6807 Alt : constant Node_Id := Entry_Call_Alternative (N);
6808 Blk : Node_Id := Entry_Call_Statement (Alt);
6811 Blk_Typ : Entity_Id;
6813 Call_Ent : Entity_Id;
6814 Conc_Typ_Stmts : List_Id;
6818 Lim_Typ_Stmts : List_Id;
6825 Transient_Blk : Node_Id;
6828 B : Entity_Id; -- Call status flag
6829 C : Entity_Id; -- Call kind
6830 K : Entity_Id; -- Tagged kind
6831 P : Entity_Id; -- Parameter block
6832 S : Entity_Id; -- Primitive operation slot
6835 if Ada_Version >= Ada_2005
6836 and then Nkind (Blk) = N_Procedure_Call_Statement
6838 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6843 -- Call status flag processing, generate:
6844 -- B : Boolean := False;
6846 B := Build_B (Loc, Decls);
6848 -- Call kind processing, generate:
6849 -- C : Ada.Tags.Prim_Op_Kind;
6851 C := Build_C (Loc, Decls);
6853 -- Tagged kind processing, generate:
6854 -- K : Ada.Tags.Tagged_Kind :=
6855 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6857 K := Build_K (Loc, Decls, Obj);
6859 -- Parameter block processing
6861 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6862 P := Parameter_Block_Pack
6863 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6865 -- Dispatch table slot processing, generate:
6868 S := Build_S (Loc, Decls);
6871 -- S := Ada.Tags.Get_Offset_Index
6872 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6875 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6878 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6880 Append_To (Conc_Typ_Stmts,
6881 Make_Procedure_Call_Statement (Loc,
6884 Find_Prim_Op (Etype (Etype (Obj)),
6885 Name_uDisp_Conditional_Select),
6887 Parameter_Associations =>
6889 New_Copy_Tree (Obj), -- <object>
6890 New_Reference_To (S, Loc), -- S
6891 Make_Attribute_Reference (Loc, -- P'Address
6893 New_Reference_To (P, Loc),
6896 New_Reference_To (C, Loc), -- C
6897 New_Reference_To (B, Loc)))); -- B
6900 -- if C = POK_Protected_Entry
6901 -- or else C = POK_Task_Entry
6903 -- Param1 := P.Param1;
6905 -- ParamN := P.ParamN;
6908 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6910 -- Generate the if statement only when the packed parameters need
6911 -- explicit assignments to their corresponding actuals.
6913 if Present (Unpack) then
6914 Append_To (Conc_Typ_Stmts,
6915 Make_If_Statement (Loc,
6922 New_Reference_To (C, Loc),
6924 New_Reference_To (RTE (
6925 RE_POK_Protected_Entry), Loc)),
6929 New_Reference_To (C, Loc),
6931 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6939 -- if C = POK_Procedure
6940 -- or else C = POK_Protected_Procedure
6941 -- or else C = POK_Task_Procedure
6943 -- <dispatching-call>
6945 -- <normal-statements>
6947 -- <else-statements>
6950 N_Stats := New_Copy_List_Tree (Statements (Alt));
6952 Prepend_To (N_Stats,
6953 Make_If_Statement (Loc,
6959 New_Reference_To (C, Loc),
6961 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6968 New_Reference_To (C, Loc),
6970 New_Reference_To (RTE (
6971 RE_POK_Protected_Procedure), Loc)),
6976 New_Reference_To (C, Loc),
6978 New_Reference_To (RTE (
6979 RE_POK_Task_Procedure), Loc)))),
6984 Append_To (Conc_Typ_Stmts,
6985 Make_If_Statement (Loc,
6986 Condition => New_Reference_To (B, Loc),
6987 Then_Statements => N_Stats,
6988 Else_Statements => Else_Statements (N)));
6991 -- <dispatching-call>;
6992 -- <triggering-statements>
6994 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6995 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6998 -- if K = Ada.Tags.TK_Limited_Tagged then
7005 Make_If_Statement (Loc,
7009 New_Reference_To (K, Loc),
7011 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
7020 Make_Block_Statement (Loc,
7023 Handled_Statement_Sequence =>
7024 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7026 -- As described above, The entry alternative is transformed into a
7027 -- block that contains the gnulli call, and possibly assignment
7028 -- statements for in-out parameters. The gnulli call may itself be
7029 -- rewritten into a transient block if some unconstrained parameters
7030 -- require it. We need to retrieve the call to complete its parameter
7035 First_Real_Statement (Handled_Statement_Sequence (Blk));
7037 if Present (Transient_Blk)
7038 and then Nkind (Transient_Blk) = N_Block_Statement
7040 Blk := Transient_Blk;
7043 Stmts := Statements (Handled_Statement_Sequence (Blk));
7044 Stmt := First (Stmts);
7045 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7050 Params := Parameter_Associations (Call);
7052 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7054 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7056 Param := First (Params);
7057 while Present (Param)
7058 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7063 pragma Assert (Present (Param));
7064 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
7068 -- Find the Communication_Block parameter for the call to the
7069 -- Cancelled function.
7071 Decl := First (Declarations (Blk));
7072 while Present (Decl)
7073 and then not Is_RTE (Etype (Object_Definition (Decl)),
7074 RE_Communication_Block)
7079 -- Add an if statement to execute the else part if the call
7080 -- does not succeed (as indicated by the Cancelled predicate).
7083 Make_Implicit_If_Statement (N,
7084 Condition => Make_Function_Call (Loc,
7085 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
7086 Parameter_Associations => New_List (
7087 New_Reference_To (Defining_Identifier (Decl), Loc))),
7088 Then_Statements => Else_Statements (N),
7089 Else_Statements => Statements (Alt)));
7092 B := Make_Defining_Identifier (Loc, Name_uB);
7094 -- Insert declaration of B in declarations of existing block
7096 if No (Declarations (Blk)) then
7097 Set_Declarations (Blk, New_List);
7100 Prepend_To (Declarations (Blk),
7101 Make_Object_Declaration (Loc,
7102 Defining_Identifier => B,
7103 Object_Definition =>
7104 New_Reference_To (Standard_Boolean, Loc)));
7106 -- Create new call statement
7109 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7110 Append_To (Params, New_Reference_To (B, Loc));
7113 Make_Procedure_Call_Statement (Loc,
7114 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7115 Parameter_Associations => Params));
7117 -- Construct statement sequence for new block
7120 Make_Implicit_If_Statement (N,
7121 Condition => New_Reference_To (B, Loc),
7122 Then_Statements => Statements (Alt),
7123 Else_Statements => Else_Statements (N)));
7126 -- The result is the new block
7129 Make_Block_Statement (Loc,
7130 Declarations => Declarations (Blk),
7131 Handled_Statement_Sequence =>
7132 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7136 end Expand_N_Conditional_Entry_Call;
7138 ---------------------------------------
7139 -- Expand_N_Delay_Relative_Statement --
7140 ---------------------------------------
7142 -- Delay statement is implemented as a procedure call to Delay_For
7143 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7144 -- simple delays imposed by the use of Protected Objects.
7146 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7147 Loc : constant Source_Ptr := Sloc (N);
7150 Make_Procedure_Call_Statement (Loc,
7151 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7152 Parameter_Associations => New_List (Expression (N))));
7154 end Expand_N_Delay_Relative_Statement;
7156 ------------------------------------
7157 -- Expand_N_Delay_Until_Statement --
7158 ------------------------------------
7160 -- Delay Until statement is implemented as a procedure call to
7161 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7163 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7164 Loc : constant Source_Ptr := Sloc (N);
7168 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7169 Typ := RTE (RO_CA_Delay_Until);
7171 Typ := RTE (RO_RT_Delay_Until);
7175 Make_Procedure_Call_Statement (Loc,
7176 Name => New_Reference_To (Typ, Loc),
7177 Parameter_Associations => New_List (Expression (N))));
7180 end Expand_N_Delay_Until_Statement;
7182 -------------------------
7183 -- Expand_N_Entry_Body --
7184 -------------------------
7186 procedure Expand_N_Entry_Body (N : Node_Id) is
7188 -- Associate discriminals with the next protected operation body to be
7191 if Present (Next_Protected_Operation (N)) then
7192 Set_Discriminals (Parent (Current_Scope));
7194 end Expand_N_Entry_Body;
7196 -----------------------------------
7197 -- Expand_N_Entry_Call_Statement --
7198 -----------------------------------
7200 -- An entry call is expanded into GNARLI calls to implement a simple entry
7201 -- call (see Build_Simple_Entry_Call).
7203 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7209 if No_Run_Time_Mode then
7210 Error_Msg_CRT ("entry call", N);
7214 -- If this entry call is part of an asynchronous select, don't expand it
7215 -- here; it will be expanded with the select statement. Don't expand
7216 -- timed entry calls either, as they are translated into asynchronous
7219 -- ??? This whole approach is questionable; it may be better to go back
7220 -- to allowing the expansion to take place and then attempting to fix it
7221 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7222 -- whether the expanded call is on a task or protected entry.
7224 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7225 or else N /= Triggering_Statement (Parent (N)))
7226 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7227 or else N /= Entry_Call_Statement (Parent (N))
7228 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7230 Extract_Entry (N, Concval, Ename, Index);
7231 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7233 end Expand_N_Entry_Call_Statement;
7235 --------------------------------
7236 -- Expand_N_Entry_Declaration --
7237 --------------------------------
7239 -- If there are parameters, then first, each of the formals is marked by
7240 -- setting Is_Entry_Formal. Next a record type is built which is used to
7241 -- hold the parameter values. The name of this record type is entryP where
7242 -- entry is the name of the entry, with an additional corresponding access
7243 -- type called entryPA. The record type has matching components for each
7244 -- formal (the component names are the same as the formal names). For
7245 -- elementary types, the component type matches the formal type. For
7246 -- composite types, an access type is declared (with the name formalA)
7247 -- which designates the formal type, and the type of the component is this
7248 -- access type. Finally the Entry_Component of each formal is set to
7249 -- reference the corresponding record component.
7251 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7252 Loc : constant Source_Ptr := Sloc (N);
7253 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7254 Components : List_Id;
7257 Last_Decl : Node_Id;
7258 Component : Entity_Id;
7261 Rec_Ent : Entity_Id;
7262 Acc_Ent : Entity_Id;
7265 Formal := First_Formal (Entry_Ent);
7268 -- Most processing is done only if parameters are present
7270 if Present (Formal) then
7271 Components := New_List;
7273 -- Loop through formals
7275 while Present (Formal) loop
7276 Set_Is_Entry_Formal (Formal);
7278 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7279 Set_Entry_Component (Formal, Component);
7280 Set_Entry_Formal (Component, Formal);
7281 Ftype := Etype (Formal);
7283 -- Declare new access type and then append
7285 Ctype := Make_Temporary (Loc, 'A');
7288 Make_Full_Type_Declaration (Loc,
7289 Defining_Identifier => Ctype,
7291 Make_Access_To_Object_Definition (Loc,
7292 All_Present => True,
7293 Constant_Present => Ekind (Formal) = E_In_Parameter,
7294 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7296 Insert_After (Last_Decl, Decl);
7299 Append_To (Components,
7300 Make_Component_Declaration (Loc,
7301 Defining_Identifier => Component,
7302 Component_Definition =>
7303 Make_Component_Definition (Loc,
7304 Aliased_Present => False,
7305 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7307 Next_Formal_With_Extras (Formal);
7310 -- Create the Entry_Parameter_Record declaration
7312 Rec_Ent := Make_Temporary (Loc, 'P');
7315 Make_Full_Type_Declaration (Loc,
7316 Defining_Identifier => Rec_Ent,
7318 Make_Record_Definition (Loc,
7320 Make_Component_List (Loc,
7321 Component_Items => Components)));
7323 Insert_After (Last_Decl, Decl);
7326 -- Construct and link in the corresponding access type
7328 Acc_Ent := Make_Temporary (Loc, 'A');
7330 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7333 Make_Full_Type_Declaration (Loc,
7334 Defining_Identifier => Acc_Ent,
7336 Make_Access_To_Object_Definition (Loc,
7337 All_Present => True,
7338 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7340 Insert_After (Last_Decl, Decl);
7343 end Expand_N_Entry_Declaration;
7345 -----------------------------
7346 -- Expand_N_Protected_Body --
7347 -----------------------------
7349 -- Protected bodies are expanded to the completion of the subprograms
7350 -- created for the corresponding protected type. These are a protected and
7351 -- unprotected version of each protected subprogram in the object, a
7352 -- function to calculate each entry barrier, and a procedure to execute the
7353 -- sequence of statements of each protected entry body. For example, for
7354 -- protected type ptype:
7357 -- (O : System.Address;
7358 -- E : Protected_Entry_Index)
7361 -- <discriminant renamings>
7362 -- <private object renamings>
7364 -- return <barrier expression>;
7367 -- procedure pprocN (_object : in out poV;...) is
7368 -- <discriminant renamings>
7369 -- <private object renamings>
7371 -- <sequence of statements>
7374 -- procedure pprocP (_object : in out poV;...) is
7375 -- procedure _clean is
7378 -- ptypeS (_object, Pn);
7379 -- Unlock (_object._object'Access);
7380 -- Abort_Undefer.all;
7385 -- Lock (_object._object'Access);
7386 -- pprocN (_object;...);
7391 -- function pfuncN (_object : poV;...) return Return_Type is
7392 -- <discriminant renamings>
7393 -- <private object renamings>
7395 -- <sequence of statements>
7398 -- function pfuncP (_object : poV) return Return_Type is
7399 -- procedure _clean is
7401 -- Unlock (_object._object'Access);
7402 -- Abort_Undefer.all;
7407 -- Lock (_object._object'Access);
7408 -- return pfuncN (_object);
7415 -- (O : System.Address;
7416 -- P : System.Address;
7417 -- E : Protected_Entry_Index)
7419 -- <discriminant renamings>
7420 -- <private object renamings>
7421 -- type poVP is access poV;
7422 -- _Object : ptVP := ptVP!(O);
7426 -- <statement sequence>
7427 -- Complete_Entry_Body (_Object._Object);
7429 -- when all others =>
7430 -- Exceptional_Complete_Entry_Body (
7431 -- _Object._Object, Get_GNAT_Exception);
7435 -- The type poV is the record created for the protected type to hold
7436 -- the state of the protected object.
7438 procedure Expand_N_Protected_Body (N : Node_Id) is
7439 Loc : constant Source_Ptr := Sloc (N);
7440 Pid : constant Entity_Id := Corresponding_Spec (N);
7442 Current_Node : Node_Id;
7443 Disp_Op_Body : Node_Id;
7444 New_Op_Body : Node_Id;
7445 Num_Entries : Natural := 0;
7449 Chain : Entity_Id := Empty;
7450 -- Finalization chain that may be attached to new body
7452 function Build_Dispatching_Subprogram_Body
7455 Prot_Bod : Node_Id) return Node_Id;
7456 -- Build a dispatching version of the protected subprogram body. The
7457 -- newly generated subprogram contains a call to the original protected
7458 -- body. The following code is generated:
7460 -- function <protected-function-name> (Param1 .. ParamN) return
7463 -- return <protected-function-name>P (Param1 .. ParamN);
7464 -- end <protected-function-name>;
7468 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7470 -- <protected-procedure-name>P (Param1 .. ParamN);
7471 -- end <protected-procedure-name>
7473 ---------------------------------------
7474 -- Build_Dispatching_Subprogram_Body --
7475 ---------------------------------------
7477 function Build_Dispatching_Subprogram_Body
7480 Prot_Bod : Node_Id) return Node_Id
7482 Loc : constant Source_Ptr := Sloc (N);
7489 -- Generate a specification without a letter suffix in order to
7490 -- override an interface function or procedure.
7492 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7494 -- The formal parameters become the actuals of the protected function
7495 -- or procedure call.
7497 Actuals := New_List;
7498 Formal := First (Parameter_Specifications (Spec));
7499 while Present (Formal) loop
7501 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7506 if Nkind (Spec) = N_Procedure_Specification then
7509 Make_Procedure_Call_Statement (Loc,
7511 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7512 Parameter_Associations => Actuals));
7514 pragma Assert (Nkind (Spec) = N_Function_Specification);
7518 Make_Simple_Return_Statement (Loc,
7520 Make_Function_Call (Loc,
7522 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7523 Parameter_Associations => Actuals)));
7527 Make_Subprogram_Body (Loc,
7528 Declarations => Empty_List,
7529 Specification => Spec,
7530 Handled_Statement_Sequence =>
7531 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7532 end Build_Dispatching_Subprogram_Body;
7534 -- Start of processing for Expand_N_Protected_Body
7537 if No_Run_Time_Mode then
7538 Error_Msg_CRT ("protected body", N);
7542 -- This is the proper body corresponding to a stub. The declarations
7543 -- must be inserted at the point of the stub, which in turn is in the
7544 -- declarative part of the parent unit.
7546 if Nkind (Parent (N)) = N_Subunit then
7547 Current_Node := Corresponding_Stub (Parent (N));
7552 Op_Body := First (Declarations (N));
7554 -- The protected body is replaced with the bodies of its
7555 -- protected operations, and the declarations for internal objects
7556 -- that may have been created for entry family bounds.
7558 Rewrite (N, Make_Null_Statement (Sloc (N)));
7561 while Present (Op_Body) loop
7562 case Nkind (Op_Body) is
7563 when N_Subprogram_Declaration =>
7566 when N_Subprogram_Body =>
7568 -- Do not create bodies for eliminated operations
7570 if not Is_Eliminated (Defining_Entity (Op_Body))
7571 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7574 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7576 -- Propagate the finalization chain to the new body. In the
7577 -- unlikely event that the subprogram contains a declaration
7578 -- or allocator for an object that requires finalization,
7579 -- the corresponding chain is created when analyzing the
7580 -- body, and attached to its entity. This entity is not
7581 -- further elaborated, and so the chain properly belongs to
7582 -- the newly created subprogram body.
7585 Finalization_Chain_Entity (Defining_Entity (Op_Body));
7587 if Present (Chain) then
7588 Set_Finalization_Chain_Entity
7589 (Protected_Body_Subprogram
7590 (Corresponding_Spec (Op_Body)), Chain);
7592 (Handled_Statement_Sequence (New_Op_Body), False);
7595 Insert_After (Current_Node, New_Op_Body);
7596 Current_Node := New_Op_Body;
7597 Analyze (New_Op_Body);
7599 -- Build the corresponding protected operation. It may
7600 -- appear that this is needed only if this is a visible
7601 -- operation of the type, or if it is an interrupt handler,
7602 -- and this was the strategy used previously in GNAT.
7603 -- However, the operation may be exported through a 'Access
7604 -- to an external caller. This is the common idiom in code
7605 -- that uses the Ada 2005 Timing_Events package. As a result
7606 -- we need to produce the protected body for both visible
7607 -- and private operations, as well as operations that only
7608 -- have a body in the source, and for which we create a
7609 -- declaration in the protected body itself.
7611 if Present (Corresponding_Spec (Op_Body)) then
7613 Build_Protected_Subprogram_Body (
7614 Op_Body, Pid, Specification (New_Op_Body));
7616 Insert_After (Current_Node, New_Op_Body);
7617 Analyze (New_Op_Body);
7619 Current_Node := New_Op_Body;
7621 -- Generate an overriding primitive operation body for
7622 -- this subprogram if the protected type implements an
7625 if Ada_Version >= Ada_2005
7627 Present (Interfaces (Corresponding_Record_Type (Pid)))
7630 Build_Dispatching_Subprogram_Body
7631 (Op_Body, Pid, New_Op_Body);
7633 Insert_After (Current_Node, Disp_Op_Body);
7634 Analyze (Disp_Op_Body);
7636 Current_Node := Disp_Op_Body;
7641 when N_Entry_Body =>
7642 Op_Id := Defining_Identifier (Op_Body);
7643 Num_Entries := Num_Entries + 1;
7645 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7647 Insert_After (Current_Node, New_Op_Body);
7648 Current_Node := New_Op_Body;
7649 Analyze (New_Op_Body);
7651 when N_Implicit_Label_Declaration =>
7654 when N_Itype_Reference =>
7655 Insert_After (Current_Node, New_Copy (Op_Body));
7657 when N_Freeze_Entity =>
7658 New_Op_Body := New_Copy (Op_Body);
7660 if Present (Entity (Op_Body))
7661 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7663 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7666 Insert_After (Current_Node, New_Op_Body);
7667 Current_Node := New_Op_Body;
7668 Analyze (New_Op_Body);
7671 New_Op_Body := New_Copy (Op_Body);
7672 Insert_After (Current_Node, New_Op_Body);
7673 Current_Node := New_Op_Body;
7674 Analyze (New_Op_Body);
7676 when N_Object_Declaration =>
7677 pragma Assert (not Comes_From_Source (Op_Body));
7678 New_Op_Body := New_Copy (Op_Body);
7679 Insert_After (Current_Node, New_Op_Body);
7680 Current_Node := New_Op_Body;
7681 Analyze (New_Op_Body);
7684 raise Program_Error;
7691 -- Finally, create the body of the function that maps an entry index
7692 -- into the corresponding body index, except when there is no entry, or
7693 -- in a Ravenscar-like profile.
7695 if Corresponding_Runtime_Package (Pid) =
7696 System_Tasking_Protected_Objects_Entries
7698 New_Op_Body := Build_Find_Body_Index (Pid);
7699 Insert_After (Current_Node, New_Op_Body);
7700 Current_Node := New_Op_Body;
7701 Analyze (New_Op_Body);
7704 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7705 -- protected body. At this point all wrapper specs have been created,
7706 -- frozen and included in the dispatch table for the protected type.
7708 if Ada_Version >= Ada_2005 then
7709 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7711 end Expand_N_Protected_Body;
7713 -----------------------------------------
7714 -- Expand_N_Protected_Type_Declaration --
7715 -----------------------------------------
7717 -- First we create a corresponding record type declaration used to
7718 -- represent values of this protected type.
7719 -- The general form of this type declaration is
7721 -- type poV (discriminants) is record
7722 -- _Object : aliased <kind>Protection
7723 -- [(<entry count> [, <handler count>])];
7724 -- [entry_family : array (bounds) of Void;]
7725 -- <private data fields>
7728 -- The discriminants are present only if the corresponding protected type
7729 -- has discriminants, and they exactly mirror the protected type
7730 -- discriminants. The private data fields similarly mirror the private
7731 -- declarations of the protected type.
7733 -- The Object field is always present. It contains RTS specific data used
7734 -- to control the protected object. It is declared as Aliased so that it
7735 -- can be passed as a pointer to the RTS. This allows the protected record
7736 -- to be referenced within RTS data structures. An appropriate Protection
7737 -- type and discriminant are generated.
7739 -- The Service field is present for protected objects with entries. It
7740 -- contains sufficient information to allow the entry service procedure for
7741 -- this object to be called when the object is not known till runtime.
7743 -- One entry_family component is present for each entry family in the
7744 -- task definition (see Expand_N_Task_Type_Declaration).
7746 -- When a protected object is declared, an instance of the protected type
7747 -- value record is created. The elaboration of this declaration creates the
7748 -- correct bounds for the entry families, and also evaluates the priority
7749 -- expression if needed. The initialization routine for the protected type
7750 -- itself then calls Initialize_Protection with appropriate parameters to
7751 -- initialize the value of the Task_Id field. Install_Handlers may be also
7752 -- called if a pragma Attach_Handler applies.
7754 -- Note: this record is passed to the subprograms created by the expansion
7755 -- of protected subprograms and entries. It is an in parameter to protected
7756 -- functions and an in out parameter to procedures and entry bodies. The
7757 -- Entity_Id for this created record type is placed in the
7758 -- Corresponding_Record_Type field of the associated protected type entity.
7760 -- Next we create a procedure specifications for protected subprograms and
7761 -- entry bodies. For each protected subprograms two subprograms are
7762 -- created, an unprotected and a protected version. The unprotected version
7763 -- is called from within other operations of the same protected object.
7765 -- We also build the call to register the procedure if a pragma
7766 -- Interrupt_Handler applies.
7768 -- A single subprogram is created to service all entry bodies; it has an
7769 -- additional boolean out parameter indicating that the previous entry call
7770 -- made by the current task was serviced immediately, i.e. not by proxy.
7771 -- The O parameter contains a pointer to a record object of the type
7772 -- described above. An untyped interface is used here to allow this
7773 -- procedure to be called in places where the type of the object to be
7774 -- serviced is not known. This must be done, for example, when a call that
7775 -- may have been requeued is cancelled; the corresponding object must be
7776 -- serviced, but which object that is not known till runtime.
7779 -- (O : System.Address; P : out Boolean);
7780 -- procedure pprocN (_object : in out poV);
7781 -- procedure pproc (_object : in out poV);
7782 -- function pfuncN (_object : poV);
7783 -- function pfunc (_object : poV);
7786 -- Note that this must come after the record type declaration, since
7787 -- the specs refer to this type.
7789 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7790 Loc : constant Source_Ptr := Sloc (N);
7791 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7793 Pdef : constant Node_Id := Protected_Definition (N);
7794 -- This contains two lists; one for visible and one for private decls
7798 Discr_Map : constant Elist_Id := New_Elmt_List;
7802 Comp_Id : Entity_Id;
7804 Current_Node : Node_Id := N;
7805 Bdef : Entity_Id := Empty; -- avoid uninit warning
7806 Edef : Entity_Id := Empty; -- avoid uninit warning
7807 Entries_Aggr : Node_Id;
7808 Body_Id : Entity_Id;
7811 Object_Comp : Node_Id;
7813 procedure Check_Inlining (Subp : Entity_Id);
7814 -- If the original operation has a pragma Inline, propagate the flag
7815 -- to the internal body, for possible inlining later on. The source
7816 -- operation is invisible to the back-end and is never actually called.
7818 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7819 -- When compiling under the Ravenscar profile, private components must
7820 -- have a static size, or else a protected object will require heap
7821 -- allocation, violating the corresponding restriction. It is preferable
7822 -- to make this check here, because it provides a better error message
7823 -- than the back-end, which refers to the object as a whole.
7825 procedure Register_Handler;
7826 -- For a protected operation that is an interrupt handler, add the
7827 -- freeze action that will register it as such.
7829 --------------------
7830 -- Check_Inlining --
7831 --------------------
7833 procedure Check_Inlining (Subp : Entity_Id) is
7835 if Is_Inlined (Subp) then
7836 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7837 Set_Is_Inlined (Subp, False);
7841 ---------------------------------
7842 -- Check_Static_Component_Size --
7843 ---------------------------------
7845 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7846 Typ : constant Entity_Id := Etype (Comp);
7850 if Is_Scalar_Type (Typ) then
7853 elsif Is_Array_Type (Typ) then
7854 return Compile_Time_Known_Bounds (Typ);
7856 elsif Is_Record_Type (Typ) then
7857 C := First_Component (Typ);
7858 while Present (C) loop
7859 if not Static_Component_Size (C) then
7868 -- Any other types will be checked by the back-end
7873 end Static_Component_Size;
7875 ----------------------
7876 -- Register_Handler --
7877 ----------------------
7879 procedure Register_Handler is
7881 -- All semantic checks already done in Sem_Prag
7883 Prot_Proc : constant Entity_Id :=
7885 (Specification (Current_Node));
7887 Proc_Address : constant Node_Id :=
7888 Make_Attribute_Reference (Loc,
7889 Prefix => New_Reference_To (Prot_Proc, Loc),
7890 Attribute_Name => Name_Address);
7892 RTS_Call : constant Entity_Id :=
7893 Make_Procedure_Call_Statement (Loc,
7896 RTE (RE_Register_Interrupt_Handler), Loc),
7897 Parameter_Associations =>
7898 New_List (Proc_Address));
7900 Append_Freeze_Action (Prot_Proc, RTS_Call);
7901 end Register_Handler;
7903 -- Start of processing for Expand_N_Protected_Type_Declaration
7906 if Present (Corresponding_Record_Type (Prot_Typ)) then
7909 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7912 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7914 Qualify_Entity_Names (N);
7916 -- If the type has discriminants, their occurrences in the declaration
7917 -- have been replaced by the corresponding discriminals. For components
7918 -- that are constrained by discriminants, their homologues in the
7919 -- corresponding record type must refer to the discriminants of that
7920 -- record, so we must apply a new renaming to subtypes_indications:
7922 -- protected discriminant => discriminal => record discriminant
7924 -- This replacement is not applied to default expressions, for which
7925 -- the discriminal is correct.
7927 if Has_Discriminants (Prot_Typ) then
7933 Disc := First_Discriminant (Prot_Typ);
7934 Decl := First (Discriminant_Specifications (Rec_Decl));
7935 while Present (Disc) loop
7936 Append_Elmt (Discriminal (Disc), Discr_Map);
7937 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7938 Next_Discriminant (Disc);
7944 -- Fill in the component declarations
7946 -- Add components for entry families. For each entry family, create an
7947 -- anonymous type declaration with the same size, and analyze the type.
7949 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7951 -- Prepend the _Object field with the right type to the component list.
7952 -- We need to compute the number of entries, and in some cases the
7953 -- number of Attach_Handler pragmas.
7957 Num_Attach_Handler : Int := 0;
7958 Protection_Subtype : Node_Id;
7959 Entry_Count_Expr : constant Node_Id :=
7960 Build_Entry_Count_Expression
7961 (Prot_Typ, Cdecls, Loc);
7964 -- Could this be simplified using Corresponding_Runtime_Package???
7966 if Has_Attach_Handler (Prot_Typ) then
7967 Ritem := First_Rep_Item (Prot_Typ);
7968 while Present (Ritem) loop
7969 if Nkind (Ritem) = N_Pragma
7970 and then Pragma_Name (Ritem) = Name_Attach_Handler
7972 Num_Attach_Handler := Num_Attach_Handler + 1;
7975 Next_Rep_Item (Ritem);
7978 if Restricted_Profile then
7979 if Has_Entries (Prot_Typ) then
7980 Protection_Subtype :=
7981 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7983 Protection_Subtype :=
7984 New_Reference_To (RTE (RE_Protection), Loc);
7987 Protection_Subtype :=
7988 Make_Subtype_Indication
7992 (RTE (RE_Static_Interrupt_Protection), Loc),
7994 Make_Index_Or_Discriminant_Constraint (
7996 Constraints => New_List (
7998 Make_Integer_Literal (Loc, Num_Attach_Handler))));
8001 elsif Has_Interrupt_Handler (Prot_Typ) then
8002 Protection_Subtype :=
8003 Make_Subtype_Indication (
8005 Subtype_Mark => New_Reference_To
8006 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
8008 Make_Index_Or_Discriminant_Constraint (
8010 Constraints => New_List (Entry_Count_Expr)));
8012 -- Type has explicit entries or generated primitive entry wrappers
8014 elsif Has_Entries (Prot_Typ)
8015 or else (Ada_Version >= Ada_2005
8016 and then Present (Interface_List (N)))
8018 case Corresponding_Runtime_Package (Prot_Typ) is
8019 when System_Tasking_Protected_Objects_Entries =>
8020 Protection_Subtype :=
8021 Make_Subtype_Indication (Loc,
8023 New_Reference_To (RTE (RE_Protection_Entries), Loc),
8025 Make_Index_Or_Discriminant_Constraint (
8027 Constraints => New_List (Entry_Count_Expr)));
8029 when System_Tasking_Protected_Objects_Single_Entry =>
8030 Protection_Subtype :=
8031 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8034 raise Program_Error;
8038 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
8042 Make_Component_Declaration (Loc,
8043 Defining_Identifier =>
8044 Make_Defining_Identifier (Loc, Name_uObject),
8045 Component_Definition =>
8046 Make_Component_Definition (Loc,
8047 Aliased_Present => True,
8048 Subtype_Indication => Protection_Subtype));
8051 pragma Assert (Present (Pdef));
8053 -- Add private field components
8055 if Present (Private_Declarations (Pdef)) then
8056 Priv := First (Private_Declarations (Pdef));
8058 while Present (Priv) loop
8060 if Nkind (Priv) = N_Component_Declaration then
8061 if not Static_Component_Size (Defining_Identifier (Priv)) then
8063 -- When compiling for a restricted profile, the private
8064 -- components must have a static size. If not, this is an
8065 -- error for a single protected declaration, and rates a
8066 -- warning on a protected type declaration.
8068 if not Comes_From_Source (Prot_Typ) then
8069 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8071 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8072 Error_Msg_N ("component has non-static size?", Priv);
8074 ("\creation of protected object of type& will violate"
8075 & " restriction No_Implicit_Heap_Allocations?",
8080 -- The component definition consists of a subtype indication,
8081 -- or (in Ada 2005) an access definition. Make a copy of the
8082 -- proper definition.
8085 Old_Comp : constant Node_Id := Component_Definition (Priv);
8086 Oent : constant Entity_Id := Defining_Identifier (Priv);
8088 Nent : constant Entity_Id :=
8089 Make_Defining_Identifier (Sloc (Oent),
8090 Chars => Chars (Oent));
8093 if Present (Subtype_Indication (Old_Comp)) then
8095 Make_Component_Definition (Sloc (Oent),
8096 Aliased_Present => False,
8097 Subtype_Indication =>
8098 New_Copy_Tree (Subtype_Indication (Old_Comp),
8102 Make_Component_Definition (Sloc (Oent),
8103 Aliased_Present => False,
8104 Access_Definition =>
8105 New_Copy_Tree (Access_Definition (Old_Comp),
8110 Make_Component_Declaration (Loc,
8111 Defining_Identifier => Nent,
8112 Component_Definition => New_Comp,
8113 Expression => Expression (Priv));
8115 Set_Has_Per_Object_Constraint (Nent,
8116 Has_Per_Object_Constraint (Oent));
8118 Append_To (Cdecls, New_Priv);
8121 elsif Nkind (Priv) = N_Subprogram_Declaration then
8123 -- Make the unprotected version of the subprogram available
8124 -- for expansion of intra object calls. There is need for
8125 -- a protected version only if the subprogram is an interrupt
8126 -- handler, otherwise this operation can only be called from
8130 Make_Subprogram_Declaration (Loc,
8132 Build_Protected_Sub_Specification
8133 (Priv, Prot_Typ, Unprotected_Mode));
8135 Insert_After (Current_Node, Sub);
8138 Set_Protected_Body_Subprogram
8139 (Defining_Unit_Name (Specification (Priv)),
8140 Defining_Unit_Name (Specification (Sub)));
8141 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8142 Current_Node := Sub;
8145 Make_Subprogram_Declaration (Loc,
8147 Build_Protected_Sub_Specification
8148 (Priv, Prot_Typ, Protected_Mode));
8150 Insert_After (Current_Node, Sub);
8152 Current_Node := Sub;
8154 if Is_Interrupt_Handler
8155 (Defining_Unit_Name (Specification (Priv)))
8157 if not Restricted_Profile then
8167 -- Put the _Object component after the private component so that it
8168 -- be finalized early as required by 9.4 (20)
8170 Append_To (Cdecls, Object_Comp);
8172 Insert_After (Current_Node, Rec_Decl);
8173 Current_Node := Rec_Decl;
8175 -- Analyze the record declaration immediately after construction,
8176 -- because the initialization procedure is needed for single object
8177 -- declarations before the next entity is analyzed (the freeze call
8178 -- that generates this initialization procedure is found below).
8180 Analyze (Rec_Decl, Suppress => All_Checks);
8182 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8183 -- the corresponding record is frozen. If any wrappers are generated,
8184 -- Current_Node is updated accordingly.
8186 if Ada_Version >= Ada_2005 then
8187 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8190 -- Collect pointers to entry bodies and their barriers, to be placed
8191 -- in the Entry_Bodies_Array for the type. For each entry/family we
8192 -- add an expression to the aggregate which is the initial value of
8193 -- this array. The array is declared after all protected subprograms.
8195 if Has_Entries (Prot_Typ) then
8196 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8198 Entries_Aggr := Empty;
8201 -- Build two new procedure specifications for each protected subprogram;
8202 -- one to call from outside the object and one to call from inside.
8203 -- Build a barrier function and an entry body action procedure
8204 -- specification for each protected entry. Initialize the entry body
8205 -- array. If subprogram is flagged as eliminated, do not generate any
8206 -- internal operations.
8210 Comp := First (Visible_Declarations (Pdef));
8212 while Present (Comp) loop
8213 if Nkind (Comp) = N_Subprogram_Declaration then
8215 Make_Subprogram_Declaration (Loc,
8217 Build_Protected_Sub_Specification
8218 (Comp, Prot_Typ, Unprotected_Mode));
8220 Insert_After (Current_Node, Sub);
8223 Set_Protected_Body_Subprogram
8224 (Defining_Unit_Name (Specification (Comp)),
8225 Defining_Unit_Name (Specification (Sub)));
8226 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8228 -- Make the protected version of the subprogram available for
8229 -- expansion of external calls.
8231 Current_Node := Sub;
8234 Make_Subprogram_Declaration (Loc,
8236 Build_Protected_Sub_Specification
8237 (Comp, Prot_Typ, Protected_Mode));
8239 Insert_After (Current_Node, Sub);
8242 Current_Node := Sub;
8244 -- Generate an overriding primitive operation specification for
8245 -- this subprogram if the protected type implements an interface.
8247 if Ada_Version >= Ada_2005
8249 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8252 Make_Subprogram_Declaration (Loc,
8254 Build_Protected_Sub_Specification
8255 (Comp, Prot_Typ, Dispatching_Mode));
8257 Insert_After (Current_Node, Sub);
8260 Current_Node := Sub;
8263 -- If a pragma Interrupt_Handler applies, build and add a call to
8264 -- Register_Interrupt_Handler to the freezing actions of the
8265 -- protected version (Current_Node) of the subprogram:
8267 -- system.interrupts.register_interrupt_handler
8268 -- (prot_procP'address);
8270 if not Restricted_Profile
8271 and then Is_Interrupt_Handler
8272 (Defining_Unit_Name (Specification (Comp)))
8277 elsif Nkind (Comp) = N_Entry_Declaration then
8278 E_Count := E_Count + 1;
8279 Comp_Id := Defining_Identifier (Comp);
8282 Make_Defining_Identifier (Loc,
8283 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8285 Make_Subprogram_Declaration (Loc,
8287 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8289 Insert_After (Current_Node, Sub);
8292 -- build wrapper procedure for pre/postconditions.
8294 Build_PPC_Wrapper (Comp_Id, N);
8296 Set_Protected_Body_Subprogram
8297 (Defining_Identifier (Comp),
8298 Defining_Unit_Name (Specification (Sub)));
8300 Current_Node := Sub;
8303 Make_Defining_Identifier (Loc,
8304 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8306 Make_Subprogram_Declaration (Loc,
8308 Build_Barrier_Function_Specification (Loc, Bdef));
8310 Insert_After (Current_Node, Sub);
8312 Set_Protected_Body_Subprogram (Bdef, Bdef);
8313 Set_Barrier_Function (Comp_Id, Bdef);
8314 Set_Scope (Bdef, Scope (Comp_Id));
8315 Current_Node := Sub;
8317 -- Collect pointers to the protected subprogram and the barrier
8318 -- of the current entry, for insertion into Entry_Bodies_Array.
8321 Make_Aggregate (Loc,
8322 Expressions => New_List (
8323 Make_Attribute_Reference (Loc,
8324 Prefix => New_Reference_To (Bdef, Loc),
8325 Attribute_Name => Name_Unrestricted_Access),
8326 Make_Attribute_Reference (Loc,
8327 Prefix => New_Reference_To (Edef, Loc),
8328 Attribute_Name => Name_Unrestricted_Access))),
8329 Expressions (Entries_Aggr));
8336 -- If there are some private entry declarations, expand it as if they
8337 -- were visible entries.
8339 if Present (Private_Declarations (Pdef)) then
8340 Comp := First (Private_Declarations (Pdef));
8341 while Present (Comp) loop
8342 if Nkind (Comp) = N_Entry_Declaration then
8343 E_Count := E_Count + 1;
8344 Comp_Id := Defining_Identifier (Comp);
8347 Make_Defining_Identifier (Loc,
8348 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8350 Make_Subprogram_Declaration (Loc,
8352 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8354 Insert_After (Current_Node, Sub);
8357 Set_Protected_Body_Subprogram
8358 (Defining_Identifier (Comp),
8359 Defining_Unit_Name (Specification (Sub)));
8361 Current_Node := Sub;
8364 Make_Defining_Identifier (Loc,
8365 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8368 Make_Subprogram_Declaration (Loc,
8370 Build_Barrier_Function_Specification (Loc, Bdef));
8372 Insert_After (Current_Node, Sub);
8374 Set_Protected_Body_Subprogram (Bdef, Bdef);
8375 Set_Barrier_Function (Comp_Id, Bdef);
8376 Set_Scope (Bdef, Scope (Comp_Id));
8377 Current_Node := Sub;
8379 -- Collect pointers to the protected subprogram and the barrier
8380 -- of the current entry, for insertion into Entry_Bodies_Array.
8382 Append_To (Expressions (Entries_Aggr),
8383 Make_Aggregate (Loc,
8384 Expressions => New_List (
8385 Make_Attribute_Reference (Loc,
8386 Prefix => New_Reference_To (Bdef, Loc),
8387 Attribute_Name => Name_Unrestricted_Access),
8388 Make_Attribute_Reference (Loc,
8389 Prefix => New_Reference_To (Edef, Loc),
8390 Attribute_Name => Name_Unrestricted_Access))));
8397 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8398 -- all protected subprograms have been collected.
8400 if Has_Entries (Prot_Typ) then
8402 Make_Defining_Identifier (Sloc (Prot_Typ),
8403 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8405 case Corresponding_Runtime_Package (Prot_Typ) is
8406 when System_Tasking_Protected_Objects_Entries =>
8407 Body_Arr := Make_Object_Declaration (Loc,
8408 Defining_Identifier => Body_Id,
8409 Aliased_Present => True,
8410 Object_Definition =>
8411 Make_Subtype_Indication (Loc,
8412 Subtype_Mark => New_Reference_To (
8413 RTE (RE_Protected_Entry_Body_Array), Loc),
8415 Make_Index_Or_Discriminant_Constraint (Loc,
8416 Constraints => New_List (
8418 Make_Integer_Literal (Loc, 1),
8419 Make_Integer_Literal (Loc, E_Count))))),
8420 Expression => Entries_Aggr);
8422 when System_Tasking_Protected_Objects_Single_Entry =>
8423 Body_Arr := Make_Object_Declaration (Loc,
8424 Defining_Identifier => Body_Id,
8425 Aliased_Present => True,
8426 Object_Definition => New_Reference_To
8427 (RTE (RE_Entry_Body), Loc),
8429 Make_Aggregate (Loc,
8430 Expressions => New_List (
8431 Make_Attribute_Reference (Loc,
8432 Prefix => New_Reference_To (Bdef, Loc),
8433 Attribute_Name => Name_Unrestricted_Access),
8434 Make_Attribute_Reference (Loc,
8435 Prefix => New_Reference_To (Edef, Loc),
8436 Attribute_Name => Name_Unrestricted_Access))));
8439 raise Program_Error;
8442 -- A pointer to this array will be placed in the corresponding record
8443 -- by its initialization procedure so this needs to be analyzed here.
8445 Insert_After (Current_Node, Body_Arr);
8446 Current_Node := Body_Arr;
8449 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8451 -- Finally, build the function that maps an entry index into the
8452 -- corresponding body. A pointer to this function is placed in each
8453 -- object of the type. Except for a ravenscar-like profile (no abort,
8454 -- no entry queue, 1 entry)
8456 if Corresponding_Runtime_Package (Prot_Typ) =
8457 System_Tasking_Protected_Objects_Entries
8460 Make_Subprogram_Declaration (Loc,
8461 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8462 Insert_After (Current_Node, Sub);
8466 end Expand_N_Protected_Type_Declaration;
8468 --------------------------------
8469 -- Expand_N_Requeue_Statement --
8470 --------------------------------
8472 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8473 -- operations, depending on the source and destination (task or protected
8474 -- object). A dispatching requeue statement is expanded into a call to the
8475 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8476 -- jump around the remainder of processing for the original entry and, if
8477 -- the destination is (different) protected object, to attempt to service
8478 -- it. The following illustrates the various cases:
8481 -- (O : System.Address;
8482 -- P : System.Address;
8483 -- E : Protected_Entry_Index)
8485 -- <discriminant renamings>
8486 -- <private object renamings>
8487 -- type poVP is access poV;
8488 -- _object : ptVP := ptVP!(O);
8492 -- <start of statement sequence for entry>
8494 -- -- Requeue from one protected entry body to another protected
8497 -- Requeue_Protected_Entry (
8498 -- _object._object'Access,
8499 -- new._object'Access,
8504 -- <some more of the statement sequence for entry>
8506 -- -- Requeue from an entry body to a task entry
8508 -- Requeue_Protected_To_Task_Entry (
8514 -- <rest of statement sequence for entry>
8515 -- Complete_Entry_Body (_object._object);
8518 -- when all others =>
8519 -- Exceptional_Complete_Entry_Body (
8520 -- _object._object, Get_GNAT_Exception);
8524 -- Requeue of a task entry call to a task entry
8526 -- Accept_Call (E, Ann);
8527 -- <start of statement sequence for accept statement>
8528 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8530 -- <rest of statement sequence for accept statement>
8532 -- Complete_Rendezvous;
8535 -- when all others =>
8536 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8538 -- Requeue of a task entry call to a protected entry
8540 -- Accept_Call (E, Ann);
8541 -- <start of statement sequence for accept statement>
8542 -- Requeue_Task_To_Protected_Entry (
8543 -- new._object'Access,
8548 -- <rest of statement sequence for accept statement>
8550 -- Complete_Rendezvous;
8553 -- when all others =>
8554 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8556 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8557 -- marked by pragma Implemented (XXX, By_Entry).
8559 -- The requeue is inside a protected entry:
8562 -- (O : System.Address;
8563 -- P : System.Address;
8564 -- E : Protected_Entry_Index)
8566 -- <discriminant renamings>
8567 -- <private object renamings>
8568 -- type poVP is access poV;
8569 -- _object : ptVP := ptVP!(O);
8573 -- <start of statement sequence for entry>
8576 -- (<interface class-wide object>,
8579 -- Ada.Tags.Get_Offset_Index
8581 -- <interface dispatch table index of target entry>),
8585 -- <rest of statement sequence for entry>
8586 -- Complete_Entry_Body (_object._object);
8589 -- when all others =>
8590 -- Exceptional_Complete_Entry_Body (
8591 -- _object._object, Get_GNAT_Exception);
8595 -- The requeue is inside a task entry:
8597 -- Accept_Call (E, Ann);
8598 -- <start of statement sequence for accept statement>
8600 -- (<interface class-wide object>,
8603 -- Ada.Tags.Get_Offset_Index
8605 -- <interface dispatch table index of target entrt>),
8609 -- <rest of statement sequence for accept statement>
8611 -- Complete_Rendezvous;
8614 -- when all others =>
8615 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8617 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8618 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8619 -- statement is replaced by a dispatching call with actual parameters taken
8620 -- from the inner-most accept statement or entry body.
8622 -- Target.Primitive (Param1, ..., ParamN);
8624 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8625 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8628 -- S : constant Offset_Index :=
8629 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8630 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8633 -- if C = POK_Protected_Entry
8634 -- or else C = POK_Task_Entry
8636 -- <statements for dispatching requeue>
8638 -- elsif C = POK_Protected_Procedure then
8639 -- <dispatching call equivalent>
8642 -- raise Program_Error;
8646 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8647 Loc : constant Source_Ptr := Sloc (N);
8648 Conc_Typ : Entity_Id;
8652 Old_Typ : Entity_Id;
8654 function Build_Dispatching_Call_Equivalent return Node_Id;
8655 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8656 -- the form Concval.Ename. It is statically known that Ename is allowed
8657 -- to be implemented by a protected procedure. Create a dispatching call
8658 -- equivalent of Concval.Ename taking the actual parameters from the
8659 -- inner-most accept statement or entry body.
8661 function Build_Dispatching_Requeue return Node_Id;
8662 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8663 -- the form Concval.Ename. It is statically known that Ename is allowed
8664 -- to be implemented by a protected or a task entry. Create a call to
8665 -- primitive _Disp_Requeue which handles the low-level actions.
8667 function Build_Dispatching_Requeue_To_Any return Node_Id;
8668 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8669 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8670 -- (XXX, By_Any) or not marked at all. Create a block which determines
8671 -- at runtime whether Ename denotes an entry or a procedure and perform
8672 -- the appropriate kind of dispatching select.
8674 function Build_Normal_Requeue return Node_Id;
8675 -- N denotes a non-dispatching requeue statement to either a task or a
8676 -- protected entry. Build the appropriate runtime call to perform the
8679 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8680 -- For a protected entry, create a return statement to skip the rest of
8681 -- the entry body. Otherwise, create a goto statement to skip the rest
8682 -- of a task accept statement. The lookup for the enclosing entry body
8683 -- or accept statement starts from Search.
8685 ---------------------------------------
8686 -- Build_Dispatching_Call_Equivalent --
8687 ---------------------------------------
8689 function Build_Dispatching_Call_Equivalent return Node_Id is
8690 Call_Ent : constant Entity_Id := Entity (Ename);
8691 Obj : constant Node_Id := Original_Node (Concval);
8698 -- Climb the parent chain looking for the inner-most entry body or
8699 -- accept statement.
8702 while Present (Acc_Ent)
8703 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8706 Acc_Ent := Parent (Acc_Ent);
8709 -- A requeue statement should be housed inside an entry body or an
8710 -- accept statement at some level. If this is not the case, then the
8711 -- tree is malformed.
8713 pragma Assert (Present (Acc_Ent));
8715 -- Recover the list of formal parameters
8717 if Nkind (Acc_Ent) = N_Entry_Body then
8718 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8721 Formals := Parameter_Specifications (Acc_Ent);
8723 -- Create the actual parameters for the dispatching call. These are
8724 -- simply copies of the entry body or accept statement formals in the
8725 -- same order as they appear.
8729 if Present (Formals) then
8730 Actuals := New_List;
8731 Formal := First (Formals);
8732 while Present (Formal) loop
8734 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8740 -- Obj.Call_Ent (Actuals);
8743 Make_Procedure_Call_Statement (Loc,
8745 Make_Selected_Component (Loc,
8746 Prefix => Make_Identifier (Loc, Chars (Obj)),
8747 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
8749 Parameter_Associations => Actuals);
8750 end Build_Dispatching_Call_Equivalent;
8752 -------------------------------
8753 -- Build_Dispatching_Requeue --
8754 -------------------------------
8756 function Build_Dispatching_Requeue return Node_Id is
8757 Params : constant List_Id := New_List;
8760 -- Process the "with abort" parameter
8763 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8765 -- Process the entry wrapper's position in the primary dispatch
8766 -- table parameter. Generate:
8768 -- Ada.Tags.Get_Offset_Index
8769 -- (Ada.Tags.Tag (Concval),
8770 -- <interface dispatch table position of Ename>)
8772 if Tagged_Type_Expansion then
8774 Make_Function_Call (Loc,
8775 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8776 Parameter_Associations => New_List (
8777 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8778 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8784 Make_Function_Call (Loc,
8785 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8787 Parameter_Associations => New_List (
8791 Make_Attribute_Reference (Loc,
8793 Attribute_Name => Name_Tag),
8797 Make_Attribute_Reference (Loc,
8798 Prefix => New_Reference_To (Etype (Concval), Loc),
8799 Attribute_Name => Name_Tag),
8803 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8806 -- Specific actuals for protected to XXX requeue
8808 if Is_Protected_Type (Old_Typ) then
8810 Make_Attribute_Reference (Loc, -- _object'Address
8812 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8813 Attribute_Name => Name_Address));
8815 Prepend_To (Params, -- True
8816 New_Reference_To (Standard_True, Loc));
8818 -- Specific actuals for task to XXX requeue
8821 pragma Assert (Is_Task_Type (Old_Typ));
8823 Prepend_To (Params, -- null
8824 New_Reference_To (RTE (RE_Null_Address), Loc));
8826 Prepend_To (Params, -- False
8827 New_Reference_To (Standard_False, Loc));
8830 -- Add the object parameter
8832 Prepend_To (Params, New_Copy_Tree (Concval));
8835 -- _Disp_Requeue (<Params>);
8838 Make_Procedure_Call_Statement (Loc,
8839 Name => Make_Identifier (Loc, Name_uDisp_Requeue),
8840 Parameter_Associations => Params);
8841 end Build_Dispatching_Requeue;
8843 --------------------------------------
8844 -- Build_Dispatching_Requeue_To_Any --
8845 --------------------------------------
8847 function Build_Dispatching_Requeue_To_Any return Node_Id is
8848 Call_Ent : constant Entity_Id := Entity (Ename);
8849 Obj : constant Node_Id := Original_Node (Concval);
8850 Skip : constant Node_Id := Build_Skip_Statement (N);
8860 -- Dispatch table slot processing, generate:
8863 S := Build_S (Loc, Decls);
8865 -- Call kind processing, generate:
8866 -- C : Ada.Tags.Prim_Op_Kind;
8868 C := Build_C (Loc, Decls);
8871 -- S := Ada.Tags.Get_Offset_Index
8872 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
8874 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
8877 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
8880 Make_Procedure_Call_Statement (Loc,
8883 Find_Prim_Op (Etype (Etype (Obj)),
8884 Name_uDisp_Get_Prim_Op_Kind),
8886 Parameter_Associations => New_List (
8887 New_Copy_Tree (Obj),
8888 New_Reference_To (S, Loc),
8889 New_Reference_To (C, Loc))));
8893 -- if C = POK_Protected_Entry
8894 -- or else C = POK_Task_Entry
8897 Make_If_Statement (Loc,
8903 New_Reference_To (C, Loc),
8905 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
8910 New_Reference_To (C, Loc),
8912 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
8914 -- Dispatching requeue equivalent
8916 Then_Statements => New_List (
8917 Build_Dispatching_Requeue,
8920 -- elsif C = POK_Protected_Procedure then
8922 Elsif_Parts => New_List (
8923 Make_Elsif_Part (Loc,
8927 New_Reference_To (C, Loc),
8930 RTE (RE_POK_Protected_Procedure), Loc)),
8932 -- Dispatching call equivalent
8934 Then_Statements => New_List (
8935 Build_Dispatching_Call_Equivalent))),
8938 -- raise Program_Error;
8941 Else_Statements => New_List (
8942 Make_Raise_Program_Error (Loc,
8943 Reason => PE_Explicit_Raise))));
8945 -- Wrap everything into a block
8948 Make_Block_Statement (Loc,
8949 Declarations => Decls,
8950 Handled_Statement_Sequence =>
8951 Make_Handled_Sequence_Of_Statements (Loc,
8952 Statements => Stmts));
8953 end Build_Dispatching_Requeue_To_Any;
8955 --------------------------
8956 -- Build_Normal_Requeue --
8957 --------------------------
8959 function Build_Normal_Requeue return Node_Id is
8960 Params : constant List_Id := New_List;
8965 -- Process the "with abort" parameter
8968 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8970 -- Add the index expression to the parameters. It is common among all
8974 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8976 if Is_Protected_Type (Old_Typ) then
8978 Self_Param : Node_Id;
8982 Make_Attribute_Reference (Loc,
8984 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8986 Name_Unchecked_Access);
8988 -- Protected to protected requeue
8990 if Is_Protected_Type (Conc_Typ) then
8993 RTE (RE_Requeue_Protected_Entry), Loc);
8996 Make_Attribute_Reference (Loc,
8998 Concurrent_Ref (Concval),
9000 Name_Unchecked_Access);
9002 -- Protected to task requeue
9004 else pragma Assert (Is_Task_Type (Conc_Typ));
9007 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
9009 Param := Concurrent_Ref (Concval);
9012 Prepend_To (Params, Param);
9013 Prepend_To (Params, Self_Param);
9016 else pragma Assert (Is_Task_Type (Old_Typ));
9018 -- Task to protected requeue
9020 if Is_Protected_Type (Conc_Typ) then
9023 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
9026 Make_Attribute_Reference (Loc,
9028 Concurrent_Ref (Concval),
9030 Name_Unchecked_Access);
9032 -- Task to task requeue
9034 else pragma Assert (Is_Task_Type (Conc_Typ));
9036 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
9038 Param := Concurrent_Ref (Concval);
9041 Prepend_To (Params, Param);
9045 Make_Procedure_Call_Statement (Loc,
9047 Parameter_Associations => Params);
9048 end Build_Normal_Requeue;
9050 --------------------------
9051 -- Build_Skip_Statement --
9052 --------------------------
9054 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
9055 Skip_Stmt : Node_Id;
9058 -- Build a return statement to skip the rest of the entire body
9060 if Is_Protected_Type (Old_Typ) then
9061 Skip_Stmt := Make_Simple_Return_Statement (Loc);
9063 -- If the requeue is within a task, find the end label of the
9064 -- enclosing accept statement and create a goto statement to it.
9072 -- Climb the parent chain looking for the enclosing accept
9075 Acc := Parent (Search);
9077 and then Nkind (Acc) /= N_Accept_Statement
9079 Acc := Parent (Acc);
9082 -- The last statement is the second label used for completing
9083 -- the rendezvous the usual way. The label we are looking for
9084 -- is right before it.
9087 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
9089 pragma Assert (Nkind (Label) = N_Label);
9091 -- Generate a goto statement to skip the rest of the accept
9094 Make_Goto_Statement (Loc,
9096 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9100 Set_Analyzed (Skip_Stmt);
9103 end Build_Skip_Statement;
9105 -- Start of processing for Expand_N_Requeue_Statement
9108 -- Extract the components of the entry call
9110 Extract_Entry (N, Concval, Ename, Index);
9111 Conc_Typ := Etype (Concval);
9113 -- Examine the scope stack in order to find nearest enclosing protected
9114 -- or task type. This will constitute our invocation source.
9116 Old_Typ := Current_Scope;
9117 while Present (Old_Typ)
9118 and then not Is_Protected_Type (Old_Typ)
9119 and then not Is_Task_Type (Old_Typ)
9121 Old_Typ := Scope (Old_Typ);
9124 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9125 -- Concval.Ename where the type of Concval is class-wide concurrent
9128 if Ada_Version >= Ada_2012
9129 and then Present (Concval)
9130 and then Is_Class_Wide_Type (Conc_Typ)
9131 and then Is_Concurrent_Interface (Conc_Typ)
9134 Has_Impl : Boolean := False;
9135 Impl_Kind : Name_Id := No_Name;
9138 -- Check whether the Ename is flagged by pragma Implemented
9140 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9142 Impl_Kind := Implementation_Kind (Entity (Ename));
9145 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9146 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9149 and then Impl_Kind = Name_By_Entry
9151 Rewrite (N, Build_Dispatching_Requeue);
9153 Insert_After (N, Build_Skip_Statement (N));
9155 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9156 -- a protected procedure. In this case the requeue is transformed
9157 -- into a dispatching call.
9160 and then Impl_Kind = Name_By_Protected_Procedure
9162 Rewrite (N, Build_Dispatching_Call_Equivalent);
9165 -- The procedure_or_entry_NAME's implementation kind is either
9166 -- By_Any or pragma Implemented was not applied at all. In this
9167 -- case a runtime test determines whether Ename denotes an entry
9168 -- or a protected procedure and performs the appropriate call.
9171 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9176 -- Processing for regular (non-dispatching) requeues
9179 Rewrite (N, Build_Normal_Requeue);
9181 Insert_After (N, Build_Skip_Statement (N));
9183 end Expand_N_Requeue_Statement;
9185 -------------------------------
9186 -- Expand_N_Selective_Accept --
9187 -------------------------------
9189 procedure Expand_N_Selective_Accept (N : Node_Id) is
9190 Loc : constant Source_Ptr := Sloc (N);
9191 Alts : constant List_Id := Select_Alternatives (N);
9193 -- Note: in the below declarations a lot of new lists are allocated
9194 -- unconditionally which may well not end up being used. That's
9195 -- not a good idea since it wastes space gratuitously ???
9197 Accept_Case : List_Id;
9198 Accept_List : constant List_Id := New_List;
9201 Alt_List : constant List_Id := New_List;
9202 Alt_Stats : List_Id;
9203 Ann : Entity_Id := Empty;
9206 Check_Guard : Boolean := True;
9208 Decls : constant List_Id := New_List;
9209 Stats : constant List_Id := New_List;
9210 Body_List : constant List_Id := New_List;
9211 Trailing_List : constant List_Id := New_List;
9214 Else_Present : Boolean := False;
9215 Terminate_Alt : Node_Id := Empty;
9216 Select_Mode : Node_Id;
9218 Delay_Case : List_Id;
9219 Delay_Count : Integer := 0;
9220 Delay_Val : Entity_Id;
9221 Delay_Index : Entity_Id;
9222 Delay_Min : Entity_Id;
9223 Delay_Num : Int := 1;
9224 Delay_Alt_List : List_Id := New_List;
9225 Delay_List : constant List_Id := New_List;
9229 First_Delay : Boolean := True;
9230 Guard_Open : Entity_Id;
9236 Num_Accept : Nat := 0;
9239 Time_Type : Entity_Id;
9241 Select_Call : Node_Id;
9243 Qnam : constant Entity_Id :=
9244 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9246 Xnam : constant Entity_Id :=
9247 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9249 -----------------------
9250 -- Local subprograms --
9251 -----------------------
9253 function Accept_Or_Raise return List_Id;
9254 -- For the rare case where delay alternatives all have guards, and
9255 -- all of them are closed, it is still possible that there were open
9256 -- accept alternatives with no callers. We must reexamine the
9257 -- Accept_List, and execute a selective wait with no else if some
9258 -- accept is open. If none, we raise program_error.
9260 procedure Add_Accept (Alt : Node_Id);
9261 -- Process a single accept statement in a select alternative. Build
9262 -- procedure for body of accept, and add entry to dispatch table with
9263 -- expression for guard, in preparation for call to run time select.
9265 function Make_And_Declare_Label (Num : Int) return Node_Id;
9266 -- Manufacture a label using Num as a serial number and declare it.
9267 -- The declaration is appended to Decls. The label marks the trailing
9268 -- statements of an accept or delay alternative.
9270 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9271 -- Build call to Selective_Wait runtime routine
9273 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9274 -- Add code to compare value of delay with previous values, and
9275 -- generate case entry for trailing statements.
9277 procedure Process_Accept_Alternative
9281 -- Add code to call corresponding procedure, and branch to
9282 -- trailing statements, if any.
9284 ---------------------
9285 -- Accept_Or_Raise --
9286 ---------------------
9288 function Accept_Or_Raise return List_Id is
9291 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9294 -- We generate the following:
9296 -- for J in q'range loop
9297 -- if q(J).S /=null_task_entry then
9298 -- selective_wait (simple_mode,...);
9304 -- if no rendez_vous then
9305 -- raise program_error;
9308 -- Note that the code needs to know that the selector name
9309 -- in an Accept_Alternative is named S.
9311 Cond := Make_Op_Ne (Loc,
9313 Make_Selected_Component (Loc,
9315 Make_Indexed_Component (Loc,
9316 Prefix => New_Reference_To (Qnam, Loc),
9317 Expressions => New_List (New_Reference_To (J, Loc))),
9318 Selector_Name => Make_Identifier (Loc, Name_S)),
9320 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9323 Make_Implicit_Loop_Statement (N,
9324 Identifier => Empty,
9326 Make_Iteration_Scheme (Loc,
9327 Loop_Parameter_Specification =>
9328 Make_Loop_Parameter_Specification (Loc,
9329 Defining_Identifier => J,
9330 Discrete_Subtype_Definition =>
9331 Make_Attribute_Reference (Loc,
9332 Prefix => New_Reference_To (Qnam, Loc),
9333 Attribute_Name => Name_Range,
9334 Expressions => New_List (
9335 Make_Integer_Literal (Loc, 1))))),
9337 Statements => New_List (
9338 Make_Implicit_If_Statement (N,
9340 Then_Statements => New_List (
9342 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9343 Make_Exit_Statement (Loc))))));
9346 Make_Raise_Program_Error (Loc,
9347 Condition => Make_Op_Eq (Loc,
9348 Left_Opnd => New_Reference_To (Xnam, Loc),
9350 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9351 Reason => PE_All_Guards_Closed));
9354 end Accept_Or_Raise;
9360 procedure Add_Accept (Alt : Node_Id) is
9361 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9362 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9363 Eloc : constant Source_Ptr := Sloc (Ename);
9364 Eent : constant Entity_Id := Entity (Ename);
9365 Index : constant Node_Id := Entry_Index (Acc_Stm);
9366 Null_Body : Node_Id;
9367 Proc_Body : Node_Id;
9374 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9377 if Present (Condition (Alt)) then
9379 Make_Conditional_Expression (Eloc, New_List (
9381 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9382 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9385 Entry_Index_Expression
9386 (Eloc, Eent, Index, Scope (Eent));
9389 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9390 Null_Body := New_Reference_To (Standard_False, Eloc);
9392 if Abort_Allowed then
9393 Call := Make_Procedure_Call_Statement (Eloc,
9394 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9395 Insert_Before (First (Statements (Handled_Statement_Sequence (
9396 Accept_Statement (Alt)))), Call);
9401 Make_Defining_Identifier (Eloc,
9402 New_External_Name (Chars (Ename), 'A', Num_Accept));
9404 if Comes_From_Source (Alt) then
9405 Set_Debug_Info_Needed (PB_Ent);
9409 Make_Subprogram_Body (Eloc,
9411 Make_Procedure_Specification (Eloc,
9412 Defining_Unit_Name => PB_Ent),
9413 Declarations => Declarations (Acc_Stm),
9414 Handled_Statement_Sequence =>
9415 Build_Accept_Body (Accept_Statement (Alt)));
9417 -- During the analysis of the body of the accept statement, any
9418 -- zero cost exception handler records were collected in the
9419 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9420 -- This is where we move them to where they belong, namely the
9421 -- newly created procedure.
9423 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9424 Append (Proc_Body, Body_List);
9427 Null_Body := New_Reference_To (Standard_True, Eloc);
9429 -- if accept statement has declarations, insert above, given that
9430 -- we are not creating a body for the accept.
9432 if Present (Declarations (Acc_Stm)) then
9433 Insert_Actions (N, Declarations (Acc_Stm));
9437 Append_To (Accept_List,
9438 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9440 Num_Accept := Num_Accept + 1;
9443 ----------------------------
9444 -- Make_And_Declare_Label --
9445 ----------------------------
9447 function Make_And_Declare_Label (Num : Int) return Node_Id is
9451 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9453 Make_Label (Loc, Lab_Id);
9456 Make_Implicit_Label_Declaration (Loc,
9457 Defining_Identifier =>
9458 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9459 Label_Construct => Lab));
9462 end Make_And_Declare_Label;
9464 ----------------------
9465 -- Make_Select_Call --
9466 ----------------------
9468 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9469 Params : constant List_Id := New_List;
9473 Make_Attribute_Reference (Loc,
9474 Prefix => New_Reference_To (Qnam, Loc),
9475 Attribute_Name => Name_Unchecked_Access),
9477 Append (Select_Mode, Params);
9478 Append (New_Reference_To (Ann, Loc), Params);
9479 Append (New_Reference_To (Xnam, Loc), Params);
9482 Make_Procedure_Call_Statement (Loc,
9483 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9484 Parameter_Associations => Params);
9485 end Make_Select_Call;
9487 --------------------------------
9488 -- Process_Accept_Alternative --
9489 --------------------------------
9491 procedure Process_Accept_Alternative
9496 Choices : List_Id := No_List;
9497 Alt_Stats : List_Id;
9500 Adjust_Condition (Condition (Alt));
9501 Alt_Stats := No_List;
9503 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9504 Choices := New_List (
9505 Make_Integer_Literal (Loc, Index));
9507 Alt_Stats := New_List (
9508 Make_Procedure_Call_Statement (Sloc (Proc),
9509 Name => New_Reference_To (
9510 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9513 if Statements (Alt) /= Empty_List then
9515 if No (Alt_Stats) then
9517 -- Accept with no body, followed by trailing statements
9519 Choices := New_List (
9520 Make_Integer_Literal (Loc, Index));
9522 Alt_Stats := New_List;
9525 -- After the call, if any, branch to trailing statements. We
9526 -- create a label for each, as well as the corresponding label
9529 Lab := Make_And_Declare_Label (Index);
9530 Append_To (Alt_Stats,
9531 Make_Goto_Statement (Loc,
9532 Name => New_Copy (Identifier (Lab))));
9534 Append (Lab, Trailing_List);
9535 Append_List (Statements (Alt), Trailing_List);
9536 Append_To (Trailing_List,
9537 Make_Goto_Statement (Loc,
9538 Name => New_Copy (Identifier (End_Lab))));
9541 if Present (Alt_Stats) then
9543 -- Procedure call. and/or trailing statements
9545 Append_To (Alt_List,
9546 Make_Case_Statement_Alternative (Loc,
9547 Discrete_Choices => Choices,
9548 Statements => Alt_Stats));
9550 end Process_Accept_Alternative;
9552 -------------------------------
9553 -- Process_Delay_Alternative --
9554 -------------------------------
9556 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9559 Delay_Alt : List_Id;
9562 -- Deal with C/Fortran boolean as delay condition
9564 Adjust_Condition (Condition (Alt));
9566 -- Determine the smallest specified delay
9568 -- for each delay alternative generate:
9570 -- if guard-expression then
9571 -- Delay_Val := delay-expression;
9572 -- Guard_Open := True;
9573 -- if Delay_Val < Delay_Min then
9574 -- Delay_Min := Delay_Val;
9575 -- Delay_Index := Index;
9579 -- The enclosing if-statement is omitted if there is no guard
9584 First_Delay := False;
9586 Delay_Alt := New_List (
9587 Make_Assignment_Statement (Loc,
9588 Name => New_Reference_To (Delay_Min, Loc),
9589 Expression => Expression (Delay_Statement (Alt))));
9591 if Delay_Count > 1 then
9592 Append_To (Delay_Alt,
9593 Make_Assignment_Statement (Loc,
9594 Name => New_Reference_To (Delay_Index, Loc),
9595 Expression => Make_Integer_Literal (Loc, Index)));
9599 Delay_Alt := New_List (
9600 Make_Assignment_Statement (Loc,
9601 Name => New_Reference_To (Delay_Val, Loc),
9602 Expression => Expression (Delay_Statement (Alt))));
9604 if Time_Type = Standard_Duration then
9607 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9608 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9611 -- The scope of the time type must define a comparison
9612 -- operator. The scope itself may not be visible, so we
9613 -- construct a node with entity information to insure that
9614 -- semantic analysis can find the proper operator.
9617 Make_Function_Call (Loc,
9618 Name => Make_Selected_Component (Loc,
9619 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9621 Make_Operator_Symbol (Loc,
9622 Chars => Name_Op_Lt,
9623 Strval => No_String)),
9624 Parameter_Associations =>
9626 New_Reference_To (Delay_Val, Loc),
9627 New_Reference_To (Delay_Min, Loc)));
9629 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9632 Append_To (Delay_Alt,
9633 Make_Implicit_If_Statement (N,
9635 Then_Statements => New_List (
9636 Make_Assignment_Statement (Loc,
9637 Name => New_Reference_To (Delay_Min, Loc),
9638 Expression => New_Reference_To (Delay_Val, Loc)),
9640 Make_Assignment_Statement (Loc,
9641 Name => New_Reference_To (Delay_Index, Loc),
9642 Expression => Make_Integer_Literal (Loc, Index)))));
9646 Append_To (Delay_Alt,
9647 Make_Assignment_Statement (Loc,
9648 Name => New_Reference_To (Guard_Open, Loc),
9649 Expression => New_Reference_To (Standard_True, Loc)));
9652 if Present (Condition (Alt)) then
9653 Delay_Alt := New_List (
9654 Make_Implicit_If_Statement (N,
9655 Condition => Condition (Alt),
9656 Then_Statements => Delay_Alt));
9659 Append_List (Delay_Alt, Delay_List);
9661 -- If the delay alternative has a statement part, add choice to the
9662 -- case statements for delays.
9664 if Present (Statements (Alt)) then
9666 if Delay_Count = 1 then
9667 Append_List (Statements (Alt), Delay_Alt_List);
9670 Choices := New_List (
9671 Make_Integer_Literal (Loc, Index));
9673 Append_To (Delay_Alt_List,
9674 Make_Case_Statement_Alternative (Loc,
9675 Discrete_Choices => Choices,
9676 Statements => Statements (Alt)));
9679 elsif Delay_Count = 1 then
9681 -- If the single delay has no trailing statements, add a branch
9682 -- to the exit label to the selective wait.
9684 Delay_Alt_List := New_List (
9685 Make_Goto_Statement (Loc,
9686 Name => New_Copy (Identifier (End_Lab))));
9689 end Process_Delay_Alternative;
9691 -- Start of processing for Expand_N_Selective_Accept
9694 -- First insert some declarations before the select. The first is:
9698 -- This variable holds the parameters passed to the accept body. This
9699 -- declaration has already been inserted by the time we get here by
9700 -- a call to Expand_Accept_Declarations made from the semantics when
9701 -- processing the first accept statement contained in the select. We
9702 -- can find this entity as Accept_Address (E), where E is any of the
9703 -- entries references by contained accept statements.
9705 -- The first step is to scan the list of Selective_Accept_Statements
9706 -- to find this entity, and also count the number of accepts, and
9707 -- determine if terminated, delay or else is present:
9711 Alt := First (Alts);
9712 while Present (Alt) loop
9714 if Nkind (Alt) = N_Accept_Alternative then
9717 elsif Nkind (Alt) = N_Delay_Alternative then
9718 Delay_Count := Delay_Count + 1;
9720 -- If the delays are relative delays, the delay expressions have
9721 -- type Standard_Duration. Otherwise they must have some time type
9722 -- recognized by GNAT.
9724 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9725 Time_Type := Standard_Duration;
9727 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9729 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9730 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9735 "& is not a time type (RM 9.6(6))",
9736 Expression (Delay_Statement (Alt)), Time_Type);
9737 Time_Type := Standard_Duration;
9738 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9742 if No (Condition (Alt)) then
9744 -- This guard will always be open
9746 Check_Guard := False;
9749 elsif Nkind (Alt) = N_Terminate_Alternative then
9750 Adjust_Condition (Condition (Alt));
9751 Terminate_Alt := Alt;
9754 Num_Alts := Num_Alts + 1;
9758 Else_Present := Present (Else_Statements (N));
9760 -- At the same time (see procedure Add_Accept) we build the accept list:
9762 -- Qnn : Accept_List (1 .. num-select) := (
9763 -- (null-body, entry-index),
9764 -- (null-body, entry-index),
9766 -- (null_body, entry-index));
9768 -- In the above declaration, null-body is True if the corresponding
9769 -- accept has no body, and false otherwise. The entry is either the
9770 -- entry index expression if there is no guard, or if a guard is
9771 -- present, then a conditional expression of the form:
9773 -- (if guard then entry-index else Null_Task_Entry)
9775 -- If a guard is statically known to be false, the entry can simply
9776 -- be omitted from the accept list.
9779 Make_Object_Declaration (Loc,
9780 Defining_Identifier => Qnam,
9781 Object_Definition =>
9782 New_Reference_To (RTE (RE_Accept_List), Loc),
9783 Aliased_Present => True,
9786 Make_Qualified_Expression (Loc,
9788 New_Reference_To (RTE (RE_Accept_List), Loc),
9790 Make_Aggregate (Loc, Expressions => Accept_List)));
9794 -- Then we declare the variable that holds the index for the accept
9795 -- that will be selected for service:
9797 -- Xnn : Select_Index;
9800 Make_Object_Declaration (Loc,
9801 Defining_Identifier => Xnam,
9802 Object_Definition =>
9803 New_Reference_To (RTE (RE_Select_Index), Loc),
9805 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9809 -- After this follow procedure declarations for each accept body
9816 -- where the ... are statements from the corresponding procedure body.
9817 -- No parameters are involved, since the parameters are passed via Ann
9818 -- and the parameter references have already been expanded to be direct
9819 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9820 -- any embedded tasking statements (which would normally be illegal in
9821 -- procedures), have been converted to calls to the tasking runtime so
9822 -- there is no problem in putting them into procedures.
9824 -- The original accept statement has been expanded into a block in
9825 -- the same fashion as for simple accepts (see Build_Accept_Body).
9827 -- Note: we don't really need to build these procedures for the case
9828 -- where no delay statement is present, but it is just as easy to
9829 -- build them unconditionally, and not significantly inefficient,
9830 -- since if they are short they will be inlined anyway.
9832 -- The procedure declarations have been assembled in Body_List
9834 -- If delays are present, we must compute the required delay.
9835 -- We first generate the declarations:
9837 -- Delay_Index : Boolean := 0;
9838 -- Delay_Min : Some_Time_Type.Time;
9839 -- Delay_Val : Some_Time_Type.Time;
9841 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9842 -- active delay that is actually chosen as the basis for the possible
9843 -- delay if an immediate rendez-vous is not possible.
9845 -- In the most common case there is a single delay statement, and this
9846 -- is handled specially.
9848 if Delay_Count > 0 then
9850 -- Generate the required declarations
9853 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9855 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9857 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9860 Make_Object_Declaration (Loc,
9861 Defining_Identifier => Delay_Val,
9862 Object_Definition => New_Reference_To (Time_Type, Loc)));
9865 Make_Object_Declaration (Loc,
9866 Defining_Identifier => Delay_Index,
9867 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9868 Expression => Make_Integer_Literal (Loc, 0)));
9871 Make_Object_Declaration (Loc,
9872 Defining_Identifier => Delay_Min,
9873 Object_Definition => New_Reference_To (Time_Type, Loc),
9875 Unchecked_Convert_To (Time_Type,
9876 Make_Attribute_Reference (Loc,
9878 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9879 Attribute_Name => Name_Last))));
9881 -- Create Duration and Delay_Mode objects used for passing a delay
9884 D := Make_Temporary (Loc, 'D');
9885 M := Make_Temporary (Loc, 'M');
9891 -- Note that these values are defined in s-osprim.ads and must
9894 -- Relative : constant := 0;
9895 -- Absolute_Calendar : constant := 1;
9896 -- Absolute_RT : constant := 2;
9898 if Time_Type = Standard_Duration then
9899 Discr := Make_Integer_Literal (Loc, 0);
9901 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9902 Discr := Make_Integer_Literal (Loc, 1);
9906 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9907 Discr := Make_Integer_Literal (Loc, 2);
9911 Make_Object_Declaration (Loc,
9912 Defining_Identifier => D,
9913 Object_Definition =>
9914 New_Reference_To (Standard_Duration, Loc)));
9917 Make_Object_Declaration (Loc,
9918 Defining_Identifier => M,
9919 Object_Definition =>
9920 New_Reference_To (Standard_Integer, Loc),
9921 Expression => Discr));
9926 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9929 Make_Object_Declaration (Loc,
9930 Defining_Identifier => Guard_Open,
9931 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9932 Expression => New_Reference_To (Standard_False, Loc)));
9935 -- Delay_Count is zero, don't need M and D set (suppress warning)
9942 if Present (Terminate_Alt) then
9944 -- If the terminate alternative guard is False, use
9945 -- Simple_Mode; otherwise use Terminate_Mode.
9947 if Present (Condition (Terminate_Alt)) then
9948 Select_Mode := Make_Conditional_Expression (Loc,
9949 New_List (Condition (Terminate_Alt),
9950 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9951 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9953 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9956 elsif Else_Present or Delay_Count > 0 then
9957 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9960 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9963 Select_Call := Make_Select_Call (Select_Mode);
9964 Append (Select_Call, Stats);
9966 -- Now generate code to act on the result. There is an entry
9967 -- in this case for each accept statement with a non-null body,
9968 -- followed by a branch to the statements that follow the Accept.
9969 -- In the absence of delay alternatives, we generate:
9972 -- when No_Rendezvous => -- omitted if simple mode
9987 -- Lab0: Else_Statements;
9990 -- Lab1: Trailing_Statements1;
9993 -- Lab2: Trailing_Statements2;
9998 -- Generate label for common exit
10000 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
10002 -- First entry is the default case, when no rendezvous is possible
10004 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10006 if Else_Present then
10008 -- If no rendezvous is possible, the else part is executed
10010 Lab := Make_And_Declare_Label (0);
10011 Alt_Stats := New_List (
10012 Make_Goto_Statement (Loc,
10013 Name => New_Copy (Identifier (Lab))));
10015 Append (Lab, Trailing_List);
10016 Append_List (Else_Statements (N), Trailing_List);
10017 Append_To (Trailing_List,
10018 Make_Goto_Statement (Loc,
10019 Name => New_Copy (Identifier (End_Lab))));
10021 Alt_Stats := New_List (
10022 Make_Goto_Statement (Loc,
10023 Name => New_Copy (Identifier (End_Lab))));
10026 Append_To (Alt_List,
10027 Make_Case_Statement_Alternative (Loc,
10028 Discrete_Choices => Choices,
10029 Statements => Alt_Stats));
10031 -- We make use of the fact that Accept_Index is an integer type, and
10032 -- generate successive literals for entries for each accept. Only those
10033 -- for which there is a body or trailing statements get a case entry.
10035 Alt := First (Select_Alternatives (N));
10036 Proc := First (Body_List);
10037 while Present (Alt) loop
10039 if Nkind (Alt) = N_Accept_Alternative then
10040 Process_Accept_Alternative (Alt, Index, Proc);
10041 Index := Index + 1;
10044 (Handled_Statement_Sequence (Accept_Statement (Alt)))
10049 elsif Nkind (Alt) = N_Delay_Alternative then
10050 Process_Delay_Alternative (Alt, Delay_Num);
10051 Delay_Num := Delay_Num + 1;
10057 -- An others choice is always added to the main case, as well
10058 -- as the delay case (to satisfy the compiler).
10060 Append_To (Alt_List,
10061 Make_Case_Statement_Alternative (Loc,
10062 Discrete_Choices =>
10063 New_List (Make_Others_Choice (Loc)),
10065 New_List (Make_Goto_Statement (Loc,
10066 Name => New_Copy (Identifier (End_Lab))))));
10068 Accept_Case := New_List (
10069 Make_Case_Statement (Loc,
10070 Expression => New_Reference_To (Xnam, Loc),
10071 Alternatives => Alt_List));
10073 Append_List (Trailing_List, Accept_Case);
10074 Append (End_Lab, Accept_Case);
10075 Append_List (Body_List, Decls);
10077 -- Construct case statement for trailing statements of delay
10078 -- alternatives, if there are several of them.
10080 if Delay_Count > 1 then
10081 Append_To (Delay_Alt_List,
10082 Make_Case_Statement_Alternative (Loc,
10083 Discrete_Choices =>
10084 New_List (Make_Others_Choice (Loc)),
10086 New_List (Make_Null_Statement (Loc))));
10088 Delay_Case := New_List (
10089 Make_Case_Statement (Loc,
10090 Expression => New_Reference_To (Delay_Index, Loc),
10091 Alternatives => Delay_Alt_List));
10093 Delay_Case := Delay_Alt_List;
10096 -- If there are no delay alternatives, we append the case statement
10097 -- to the statement list.
10099 if Delay_Count = 0 then
10100 Append_List (Accept_Case, Stats);
10102 -- Delay alternatives present
10105 -- If delay alternatives are present we generate:
10107 -- find minimum delay.
10108 -- DX := minimum delay;
10109 -- M := <delay mode>;
10110 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10113 -- if X = No_Rendezvous then
10114 -- case statement for delay statements.
10116 -- case statement for accept alternatives.
10127 -- The type of the delay expression is known to be legal
10129 if Time_Type = Standard_Duration then
10130 Conv := New_Reference_To (Delay_Min, Loc);
10132 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10133 Conv := Make_Function_Call (Loc,
10134 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10135 New_List (New_Reference_To (Delay_Min, Loc)));
10139 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10141 Conv := Make_Function_Call (Loc,
10142 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10143 New_List (New_Reference_To (Delay_Min, Loc)));
10146 Stmt := Make_Assignment_Statement (Loc,
10147 Name => New_Reference_To (D, Loc),
10148 Expression => Conv);
10150 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10152 Parms := Parameter_Associations (Select_Call);
10153 Parm := First (Parms);
10155 while Present (Parm)
10156 and then Parm /= Select_Mode
10161 pragma Assert (Present (Parm));
10162 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10165 -- Prepare two new parameters of Duration and Delay_Mode type
10166 -- which represent the value and the mode of the minimum delay.
10169 Insert_After (Parm, New_Reference_To (M, Loc));
10170 Insert_After (Parm, New_Reference_To (D, Loc));
10172 -- Create a call to RTS
10174 Rewrite (Select_Call,
10175 Make_Procedure_Call_Statement (Loc,
10176 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10177 Parameter_Associations => Parms));
10179 -- This new call should follow the calculation of the minimum
10182 Insert_List_Before (Select_Call, Delay_List);
10184 if Check_Guard then
10186 Make_Implicit_If_Statement (N,
10187 Condition => New_Reference_To (Guard_Open, Loc),
10189 New_List (New_Copy_Tree (Stmt),
10190 New_Copy_Tree (Select_Call)),
10191 Else_Statements => Accept_Or_Raise);
10192 Rewrite (Select_Call, Stmt);
10194 Insert_Before (Select_Call, Stmt);
10198 Make_Implicit_If_Statement (N,
10199 Condition => Make_Op_Eq (Loc,
10200 Left_Opnd => New_Reference_To (Xnam, Loc),
10202 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10204 Then_Statements => Delay_Case,
10205 Else_Statements => Accept_Case);
10207 Append (Cases, Stats);
10211 -- Replace accept statement with appropriate block
10214 Make_Block_Statement (Loc,
10215 Declarations => Decls,
10216 Handled_Statement_Sequence =>
10217 Make_Handled_Sequence_Of_Statements (Loc,
10218 Statements => Stats));
10220 Rewrite (N, Block);
10223 -- Note: have to worry more about abort deferral in above code ???
10225 -- Final step is to unstack the Accept_Address entries for all accept
10226 -- statements appearing in accept alternatives in the select statement
10228 Alt := First (Alts);
10229 while Present (Alt) loop
10230 if Nkind (Alt) = N_Accept_Alternative then
10231 Remove_Last_Elmt (Accept_Address
10232 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10237 end Expand_N_Selective_Accept;
10239 --------------------------------------
10240 -- Expand_N_Single_Task_Declaration --
10241 --------------------------------------
10243 -- Single task declarations should never be present after semantic
10244 -- analysis, since we expect them to be replaced by a declaration of an
10245 -- anonymous task type, followed by a declaration of the task object. We
10246 -- include this routine to make sure that is happening!
10248 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10250 raise Program_Error;
10251 end Expand_N_Single_Task_Declaration;
10253 ------------------------
10254 -- Expand_N_Task_Body --
10255 ------------------------
10257 -- Given a task body
10259 -- task body tname is
10265 -- This expansion routine converts it into a procedure and sets the
10266 -- elaboration flag for the procedure to true, to represent the fact
10267 -- that the task body is now elaborated:
10269 -- procedure tnameB (_Task : access tnameV) is
10270 -- discriminal : dtype renames _Task.discriminant;
10272 -- procedure _clean is
10274 -- Abort_Defer.all;
10276 -- Abort_Undefer.all;
10281 -- Abort_Undefer.all;
10283 -- System.Task_Stages.Complete_Activation;
10291 -- In addition, if the task body is an activator, then a call to activate
10292 -- tasks is added at the start of the statements, before the call to
10293 -- Complete_Activation, and if in addition the task is a master then it
10294 -- must be established as a master. These calls are inserted and analyzed
10295 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10298 -- There is one discriminal declaration line generated for each
10299 -- discriminant that is present to provide an easy reference point for
10300 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10302 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10303 -- task body procedures have a profile (Arg : System.Address). That is
10304 -- needed because GNARLI has to use the same access-to-subprogram type
10305 -- for all task types. We depend here on knowing that in GNAT, passing
10306 -- an address argument by value is identical to passing a record value
10307 -- by access (in either case a single pointer is passed), so even though
10308 -- this procedure has the wrong profile. In fact it's all OK, since the
10309 -- callings sequence is identical.
10311 procedure Expand_N_Task_Body (N : Node_Id) is
10312 Loc : constant Source_Ptr := Sloc (N);
10313 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10317 Insert_Nod : Node_Id;
10318 -- Used to determine the proper location of wrapper body insertions
10321 -- Add renaming declarations for discriminals and a declaration for the
10322 -- entry family index (if applicable).
10324 Install_Private_Data_Declarations
10325 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10327 -- Add a call to Abort_Undefer at the very beginning of the task
10328 -- body since this body is called with abort still deferred.
10330 if Abort_Allowed then
10331 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10333 (First (Statements (Handled_Statement_Sequence (N))), Call);
10337 -- The statement part has already been protected with an at_end and
10338 -- cleanup actions. The call to Complete_Activation must be placed
10339 -- at the head of the sequence of statements of that block. The
10340 -- declarations have been merged in this sequence of statements but
10341 -- the first real statement is accessible from the First_Real_Statement
10342 -- field (which was set for exactly this purpose).
10344 if Restricted_Profile then
10345 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10347 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10351 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10355 Make_Subprogram_Body (Loc,
10356 Specification => Build_Task_Proc_Specification (Ttyp),
10357 Declarations => Declarations (N),
10358 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10360 -- If the task contains generic instantiations, cleanup actions are
10361 -- delayed until after instantiation. Transfer the activation chain to
10362 -- the subprogram, to insure that the activation call is properly
10363 -- generated. It the task body contains inner tasks, indicate that the
10364 -- subprogram is a task master.
10366 if Delay_Cleanups (Ttyp) then
10367 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10368 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10371 Rewrite (N, New_N);
10374 -- Set elaboration flag immediately after task body. If the body is a
10375 -- subunit, the flag is set in the declarative part containing the stub.
10377 if Nkind (Parent (N)) /= N_Subunit then
10379 Make_Assignment_Statement (Loc,
10381 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10382 Expression => New_Reference_To (Standard_True, Loc)));
10385 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10386 -- the task body. At this point all wrapper specs have been created,
10387 -- frozen and included in the dispatch table for the task type.
10389 if Ada_Version >= Ada_2005 then
10390 if Nkind (Parent (N)) = N_Subunit then
10391 Insert_Nod := Corresponding_Stub (Parent (N));
10396 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10398 end Expand_N_Task_Body;
10400 ------------------------------------
10401 -- Expand_N_Task_Type_Declaration --
10402 ------------------------------------
10404 -- We have several things to do. First we must create a Boolean flag used
10405 -- to mark if the body is elaborated yet. This variable gets set to True
10406 -- when the body of the task is elaborated (we can't rely on the normal
10407 -- ABE mechanism for the task body, since we need to pass an access to
10408 -- this elaboration boolean to the runtime routines).
10410 -- taskE : aliased Boolean := False;
10412 -- Next a variable is declared to hold the task stack size (either the
10413 -- default : Unspecified_Size, or a value that is set by a pragma
10414 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10415 -- the variable is initialized with this value:
10417 -- taskZ : Size_Type := Unspecified_Size;
10419 -- taskZ : Size_Type := Size_Type (size_expression);
10421 -- Note: No variable is needed to hold the task relative deadline since
10422 -- its value would never be static because the parameter is of a private
10423 -- type (Ada.Real_Time.Time_Span).
10425 -- Next we create a corresponding record type declaration used to represent
10426 -- values of this task. The general form of this type declaration is
10428 -- type taskV (discriminants) is record
10429 -- _Task_Id : Task_Id;
10430 -- entry_family : array (bounds) of Void;
10431 -- _Priority : Integer := priority_expression;
10432 -- _Size : Size_Type := Size_Type (size_expression);
10433 -- _Task_Info : Task_Info_Type := task_info_expression;
10434 -- _CPU : Integer := cpu_range_expression;
10437 -- The discriminants are present only if the corresponding task type has
10438 -- discriminants, and they exactly mirror the task type discriminants.
10440 -- The Id field is always present. It contains the Task_Id value, as set by
10441 -- the call to Create_Task. Note that although the task is limited, the
10442 -- task value record type is not limited, so there is no problem in passing
10443 -- this field as an out parameter to Create_Task.
10445 -- One entry_family component is present for each entry family in the task
10446 -- definition. The bounds correspond to the bounds of the entry family
10447 -- (which may depend on discriminants). The element type is void, since we
10448 -- only need the bounds information for determining the entry index. Note
10449 -- that the use of an anonymous array would normally be illegal in this
10450 -- context, but this is a parser check, and the semantics is quite prepared
10451 -- to handle such a case.
10453 -- The _Size field is present only if a Storage_Size pragma appears in the
10454 -- task definition. The expression captures the argument that was present
10455 -- in the pragma, and is used to override the task stack size otherwise
10456 -- associated with the task type.
10458 -- The _Priority field is present only if a Priority or Interrupt_Priority
10459 -- pragma appears in the task definition. The expression captures the
10460 -- argument that was present in the pragma, and is used to provide the Size
10461 -- parameter to the call to Create_Task.
10463 -- The _Task_Info field is present only if a Task_Info pragma appears in
10464 -- the task definition. The expression captures the argument that was
10465 -- present in the pragma, and is used to provide the Task_Image parameter
10466 -- to the call to Create_Task.
10468 -- The _CPU field is present only if a CPU pragma appears in the task
10469 -- definition. The expression captures the argument that was present in
10470 -- the pragma, and is used to provide the CPU parameter to the call to
10473 -- The _Relative_Deadline field is present only if a Relative_Deadline
10474 -- pragma appears in the task definition. The expression captures the
10475 -- argument that was present in the pragma, and is used to provide the
10476 -- Relative_Deadline parameter to the call to Create_Task.
10478 -- When a task is declared, an instance of the task value record is
10479 -- created. The elaboration of this declaration creates the correct bounds
10480 -- for the entry families, and also evaluates the size, priority, and
10481 -- task_Info expressions if needed. The initialization routine for the task
10482 -- type itself then calls Create_Task with appropriate parameters to
10483 -- initialize the value of the Task_Id field.
10485 -- Note: the address of this record is passed as the "Discriminants"
10486 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10487 -- body procedure, it does not matter that it does not quite match the
10488 -- GNARLI model of what is being passed (the record contains more than just
10489 -- the discriminants, but the discriminants can be found from the record
10492 -- The Entity_Id for this created record type is placed in the
10493 -- Corresponding_Record_Type field of the associated task type entity.
10495 -- Next we create a procedure specification for the task body procedure:
10497 -- procedure taskB (_Task : access taskV);
10499 -- Note that this must come after the record type declaration, since
10500 -- the spec refers to this type. It turns out that the initialization
10501 -- procedure for the value type references the task body spec, but that's
10502 -- fine, since it won't be generated till the freeze point for the type,
10503 -- which is certainly after the task body spec declaration.
10505 -- Finally, we set the task index value field of the entry attribute in
10506 -- the case of a simple entry.
10508 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10509 Loc : constant Source_Ptr := Sloc (N);
10510 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10511 Tasknm : constant Name_Id := Chars (Tasktyp);
10512 Taskdef : constant Node_Id := Task_Definition (N);
10514 Proc_Spec : Node_Id;
10515 Rec_Decl : Node_Id;
10516 Rec_Ent : Entity_Id;
10518 Elab_Decl : Node_Id;
10519 Size_Decl : Node_Id;
10520 Body_Decl : Node_Id;
10521 Task_Size : Node_Id;
10522 Ent_Stack : Entity_Id;
10523 Decl_Stack : Node_Id;
10526 -- If already expanded, nothing to do
10528 if Present (Corresponding_Record_Type (Tasktyp)) then
10532 -- Here we will do the expansion
10534 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10536 Rec_Ent := Defining_Identifier (Rec_Decl);
10537 Cdecls := Component_Items (Component_List
10538 (Type_Definition (Rec_Decl)));
10540 Qualify_Entity_Names (N);
10542 -- First create the elaboration variable
10545 Make_Object_Declaration (Loc,
10546 Defining_Identifier =>
10547 Make_Defining_Identifier (Sloc (Tasktyp),
10548 Chars => New_External_Name (Tasknm, 'E')),
10549 Aliased_Present => True,
10550 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10551 Expression => New_Reference_To (Standard_False, Loc));
10552 Insert_After (N, Elab_Decl);
10554 -- Next create the declaration of the size variable (tasknmZ)
10556 Set_Storage_Size_Variable (Tasktyp,
10557 Make_Defining_Identifier (Sloc (Tasktyp),
10558 Chars => New_External_Name (Tasknm, 'Z')));
10560 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
10561 Is_Static_Expression (Expression (First (
10562 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
10563 Taskdef, Name_Storage_Size)))))
10566 Make_Object_Declaration (Loc,
10567 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10568 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10570 Convert_To (RTE (RE_Size_Type),
10572 Expression (First (
10573 Pragma_Argument_Associations (
10574 Find_Task_Or_Protected_Pragma
10575 (Taskdef, Name_Storage_Size)))))));
10579 Make_Object_Declaration (Loc,
10580 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10581 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10582 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10585 Insert_After (Elab_Decl, Size_Decl);
10587 -- Next build the rest of the corresponding record declaration. This is
10588 -- done last, since the corresponding record initialization procedure
10589 -- will reference the previously created entities.
10591 -- Fill in the component declarations -- first the _Task_Id field
10594 Make_Component_Declaration (Loc,
10595 Defining_Identifier =>
10596 Make_Defining_Identifier (Loc, Name_uTask_Id),
10597 Component_Definition =>
10598 Make_Component_Definition (Loc,
10599 Aliased_Present => False,
10600 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10603 -- Declare static ATCB (that is, created by the expander) if we are
10604 -- using the Restricted run time.
10606 if Restricted_Profile then
10608 Make_Component_Declaration (Loc,
10609 Defining_Identifier =>
10610 Make_Defining_Identifier (Loc, Name_uATCB),
10612 Component_Definition =>
10613 Make_Component_Definition (Loc,
10614 Aliased_Present => True,
10615 Subtype_Indication => Make_Subtype_Indication (Loc,
10616 Subtype_Mark => New_Occurrence_Of
10617 (RTE (RE_Ada_Task_Control_Block), Loc),
10620 Make_Index_Or_Discriminant_Constraint (Loc,
10622 New_List (Make_Integer_Literal (Loc, 0)))))));
10626 -- Declare static stack (that is, created by the expander) if we are
10627 -- using the Restricted run time on a bare board configuration.
10629 if Restricted_Profile
10630 and then Preallocated_Stacks_On_Target
10632 -- First we need to extract the appropriate stack size
10634 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10636 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10638 Expr_N : constant Node_Id :=
10639 Expression (First (
10640 Pragma_Argument_Associations (
10641 Find_Task_Or_Protected_Pragma
10642 (Taskdef, Name_Storage_Size))));
10643 Etyp : constant Entity_Id := Etype (Expr_N);
10644 P : constant Node_Id := Parent (Expr_N);
10647 -- The stack is defined inside the corresponding record.
10648 -- Therefore if the size of the stack is set by means of
10649 -- a discriminant, we must reference the discriminant of the
10650 -- corresponding record type.
10652 if Nkind (Expr_N) in N_Has_Entity
10653 and then Present (Discriminal_Link (Entity (Expr_N)))
10657 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10659 Set_Parent (Task_Size, P);
10660 Set_Etype (Task_Size, Etyp);
10661 Set_Analyzed (Task_Size);
10664 Task_Size := Relocate_Node (Expr_N);
10670 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10673 Decl_Stack := Make_Component_Declaration (Loc,
10674 Defining_Identifier => Ent_Stack,
10676 Component_Definition =>
10677 Make_Component_Definition (Loc,
10678 Aliased_Present => True,
10679 Subtype_Indication => Make_Subtype_Indication (Loc,
10681 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10684 Make_Index_Or_Discriminant_Constraint (Loc,
10685 Constraints => New_List (Make_Range (Loc,
10686 Low_Bound => Make_Integer_Literal (Loc, 1),
10687 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10690 Append_To (Cdecls, Decl_Stack);
10692 -- The appropriate alignment for the stack is ensured by the run-time
10693 -- code in charge of task creation.
10697 -- Add components for entry families
10699 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10701 -- Add the _Priority component if a Priority pragma is present
10703 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10705 Prag : constant Node_Id :=
10706 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10710 Expr := First (Pragma_Argument_Associations (Prag));
10712 if Nkind (Expr) = N_Pragma_Argument_Association then
10713 Expr := Expression (Expr);
10716 Expr := New_Copy_Tree (Expr);
10718 -- Add conversion to proper type to do range check if required
10719 -- Note that for runtime units, we allow out of range interrupt
10720 -- priority values to be used in a priority pragma. This is for
10721 -- the benefit of some versions of System.Interrupts which use
10722 -- a special server task with maximum interrupt priority.
10724 if Pragma_Name (Prag) = Name_Priority
10725 and then not GNAT_Mode
10727 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10729 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10733 Make_Component_Declaration (Loc,
10734 Defining_Identifier =>
10735 Make_Defining_Identifier (Loc, Name_uPriority),
10736 Component_Definition =>
10737 Make_Component_Definition (Loc,
10738 Aliased_Present => False,
10739 Subtype_Indication => New_Reference_To (Standard_Integer,
10741 Expression => Expr));
10745 -- Add the _Task_Size component if a Storage_Size pragma is present
10747 if Present (Taskdef)
10748 and then Has_Storage_Size_Pragma (Taskdef)
10751 Make_Component_Declaration (Loc,
10752 Defining_Identifier =>
10753 Make_Defining_Identifier (Loc, Name_uSize),
10755 Component_Definition =>
10756 Make_Component_Definition (Loc,
10757 Aliased_Present => False,
10758 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10762 Convert_To (RTE (RE_Size_Type),
10764 Expression (First (
10765 Pragma_Argument_Associations (
10766 Find_Task_Or_Protected_Pragma
10767 (Taskdef, Name_Storage_Size))))))));
10770 -- Add the _Task_Info component if a Task_Info pragma is present
10772 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10774 Make_Component_Declaration (Loc,
10775 Defining_Identifier =>
10776 Make_Defining_Identifier (Loc, Name_uTask_Info),
10778 Component_Definition =>
10779 Make_Component_Definition (Loc,
10780 Aliased_Present => False,
10781 Subtype_Indication =>
10782 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10784 Expression => New_Copy (
10785 Expression (First (
10786 Pragma_Argument_Associations (
10787 Find_Task_Or_Protected_Pragma
10788 (Taskdef, Name_Task_Info)))))));
10791 -- Add the _CPU component if a CPU pragma is present
10793 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
10795 Make_Component_Declaration (Loc,
10796 Defining_Identifier =>
10797 Make_Defining_Identifier (Loc, Name_uCPU),
10799 Component_Definition =>
10800 Make_Component_Definition (Loc,
10801 Aliased_Present => False,
10802 Subtype_Indication =>
10803 New_Reference_To (RTE (RE_CPU_Range), Loc)),
10805 Expression => New_Copy (
10806 Expression (First (
10807 Pragma_Argument_Associations (
10808 Find_Task_Or_Protected_Pragma
10809 (Taskdef, Name_CPU)))))));
10812 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10813 -- present. If we are using a restricted run time this component will
10814 -- not be added (deadlines are not allowed by the Ravenscar profile).
10816 if not Restricted_Profile
10817 and then Present (Taskdef)
10818 and then Has_Relative_Deadline_Pragma (Taskdef)
10821 Make_Component_Declaration (Loc,
10822 Defining_Identifier =>
10823 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10825 Component_Definition =>
10826 Make_Component_Definition (Loc,
10827 Aliased_Present => False,
10828 Subtype_Indication =>
10829 New_Reference_To (RTE (RE_Time_Span), Loc)),
10832 Convert_To (RTE (RE_Time_Span),
10834 Expression (First (
10835 Pragma_Argument_Associations (
10836 Find_Task_Or_Protected_Pragma
10837 (Taskdef, Name_Relative_Deadline))))))));
10840 Insert_After (Size_Decl, Rec_Decl);
10842 -- Analyze the record declaration immediately after construction,
10843 -- because the initialization procedure is needed for single task
10844 -- declarations before the next entity is analyzed.
10846 Analyze (Rec_Decl);
10848 -- Create the declaration of the task body procedure
10850 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10852 Make_Subprogram_Declaration (Loc,
10853 Specification => Proc_Spec);
10855 Insert_After (Rec_Decl, Body_Decl);
10857 -- The subprogram does not comes from source, so we have to indicate the
10858 -- need for debugging information explicitly.
10860 if Comes_From_Source (Original_Node (N)) then
10861 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10864 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10865 -- the corresponding record has been frozen.
10867 if Ada_Version >= Ada_2005 then
10868 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10871 -- Ada 2005 (AI-345): We must defer freezing to allow further
10872 -- declaration of primitive subprograms covering task interfaces
10874 if Ada_Version <= Ada_95 then
10876 -- Now we can freeze the corresponding record. This needs manually
10877 -- freezing, since it is really part of the task type, and the task
10878 -- type is frozen at this stage. We of course need the initialization
10879 -- procedure for this corresponding record type and we won't get it
10880 -- in time if we don't freeze now.
10883 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
10885 if Is_Non_Empty_List (L) then
10886 Insert_List_After (Body_Decl, L);
10891 -- Complete the expansion of access types to the current task type, if
10892 -- any were declared.
10894 Expand_Previous_Access_Type (Tasktyp);
10896 -- Create wrappers for entries that have pre/postconditions
10902 Ent := First_Entity (Tasktyp);
10903 while Present (Ent) loop
10904 if Ekind_In (Ent, E_Entry, E_Entry_Family)
10905 and then Present (Spec_PPC_List (Ent))
10907 Build_PPC_Wrapper (Ent, N);
10913 end Expand_N_Task_Type_Declaration;
10915 -------------------------------
10916 -- Expand_N_Timed_Entry_Call --
10917 -------------------------------
10919 -- A timed entry call in normal case is not implemented using ATC mechanism
10920 -- anymore for efficiency reason.
10930 -- is expanded as follow:
10932 -- 1) When T.E is a task entry_call;
10936 -- X : Task_Entry_Index := <entry index>;
10937 -- DX : Duration := To_Duration (D);
10938 -- M : Delay_Mode := <discriminant>;
10939 -- P : parms := (parm, parm, parm);
10942 -- Timed_Protected_Entry_Call
10943 -- (<acceptor-task>, X, P'Address, DX, M, B);
10951 -- 2) When T.E is a protected entry_call;
10955 -- X : Protected_Entry_Index := <entry index>;
10956 -- DX : Duration := To_Duration (D);
10957 -- M : Delay_Mode := <discriminant>;
10958 -- P : parms := (parm, parm, parm);
10961 -- Timed_Protected_Entry_Call
10962 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10970 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10973 -- B : Boolean := False;
10974 -- C : Ada.Tags.Prim_Op_Kind;
10975 -- DX : Duration := To_Duration (D)
10976 -- K : Ada.Tags.Tagged_Kind :=
10977 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10978 -- M : Integer :=...;
10979 -- P : Parameters := (Param1 .. ParamN);
10983 -- if K = Ada.Tags.TK_Limited_Tagged then
10984 -- <dispatching-call>;
10985 -- <triggering-statements>
10989 -- Ada.Tags.Get_Offset_Index
10990 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10992 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10994 -- if C = POK_Protected_Entry
10995 -- or else C = POK_Task_Entry
10997 -- Param1 := P.Param1;
10999 -- ParamN := P.ParamN;
11003 -- if C = POK_Procedure
11004 -- or else C = POK_Protected_Procedure
11005 -- or else C = POK_Task_Procedure
11007 -- <dispatching-call>;
11010 -- <triggering-statements>
11012 -- <timed-statements>
11017 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
11018 Loc : constant Source_Ptr := Sloc (N);
11020 E_Call : Node_Id :=
11021 Entry_Call_Statement (Entry_Call_Alternative (N));
11022 E_Stats : constant List_Id :=
11023 Statements (Entry_Call_Alternative (N));
11024 D_Stat : Node_Id :=
11025 Delay_Statement (Delay_Alternative (N));
11026 D_Stats : constant List_Id :=
11027 Statements (Delay_Alternative (N));
11030 Blk_Typ : Entity_Id;
11032 Call_Ent : Entity_Id;
11033 Conc_Typ_Stmts : List_Id;
11037 D_Type : Entity_Id;
11043 Is_Disp_Select : Boolean;
11044 Lim_Typ_Stmts : List_Id;
11053 B : Entity_Id; -- Call status flag
11054 C : Entity_Id; -- Call kind
11055 D : Entity_Id; -- Delay
11056 K : Entity_Id; -- Tagged kind
11057 M : Entity_Id; -- Delay mode
11058 P : Entity_Id; -- Parameter block
11059 S : Entity_Id; -- Primitive operation slot
11062 -- Under the Ravenscar profile, timed entry calls are excluded. An error
11063 -- was already reported on spec, so do not attempt to expand the call.
11065 if Restriction_Active (No_Select_Statements) then
11069 -- The arguments in the call may require dynamic allocation, and the
11070 -- call statement may have been transformed into a block. The block
11071 -- may contain additional declarations for internal entities, and the
11072 -- original call is found by sequential search.
11074 if Nkind (E_Call) = N_Block_Statement then
11075 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
11076 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
11077 N_Entry_Call_Statement)
11084 Ada_Version >= Ada_2005
11085 and then Nkind (E_Call) = N_Procedure_Call_Statement;
11087 if Is_Disp_Select then
11088 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11094 -- B : Boolean := False;
11096 B := Build_B (Loc, Decls);
11099 -- C : Ada.Tags.Prim_Op_Kind;
11101 C := Build_C (Loc, Decls);
11103 -- Because the analysis of all statements was disabled, manually
11104 -- analyze the delay statement.
11107 D_Stat := Original_Node (D_Stat);
11110 -- Build an entry call using Simple_Entry_Call
11112 Extract_Entry (E_Call, Concval, Ename, Index);
11113 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11115 Decls := Declarations (E_Call);
11116 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11125 B := Make_Defining_Identifier (Loc, Name_uB);
11128 Make_Object_Declaration (Loc,
11129 Defining_Identifier =>
11131 Object_Definition =>
11132 New_Reference_To (Standard_Boolean, Loc)));
11135 -- Duration and mode processing
11137 D_Type := Base_Type (Etype (Expression (D_Stat)));
11139 -- Use the type of the delay expression (Calendar or Real_Time) to
11140 -- generate the appropriate conversion.
11142 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11143 D_Disc := Make_Integer_Literal (Loc, 0);
11144 D_Conv := Relocate_Node (Expression (D_Stat));
11146 elsif Is_RTE (D_Type, RO_CA_Time) then
11147 D_Disc := Make_Integer_Literal (Loc, 1);
11148 D_Conv := Make_Function_Call (Loc,
11149 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11150 New_List (New_Copy (Expression (D_Stat))));
11152 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11153 D_Disc := Make_Integer_Literal (Loc, 2);
11154 D_Conv := Make_Function_Call (Loc,
11155 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11156 New_List (New_Copy (Expression (D_Stat))));
11159 D := Make_Temporary (Loc, 'D');
11165 Make_Object_Declaration (Loc,
11166 Defining_Identifier =>
11168 Object_Definition =>
11169 New_Reference_To (Standard_Duration, Loc)));
11171 M := Make_Temporary (Loc, 'M');
11174 -- M : Integer := (0 | 1 | 2);
11177 Make_Object_Declaration (Loc,
11178 Defining_Identifier =>
11180 Object_Definition =>
11181 New_Reference_To (Standard_Integer, Loc),
11185 -- Do the assignment at this stage only because the evaluation of the
11186 -- expression must not occur before (see ACVC C97302A).
11189 Make_Assignment_Statement (Loc,
11191 New_Reference_To (D, Loc),
11195 -- Parameter block processing
11197 -- Manually create the parameter block for dispatching calls. In the
11198 -- case of entries, the block has already been created during the call
11199 -- to Build_Simple_Entry_Call.
11201 if Is_Disp_Select then
11203 -- Tagged kind processing, generate:
11204 -- K : Ada.Tags.Tagged_Kind :=
11205 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11207 K := Build_K (Loc, Decls, Obj);
11209 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11210 P := Parameter_Block_Pack
11211 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11213 -- Dispatch table slot processing, generate:
11216 S := Build_S (Loc, Decls);
11219 -- S := Ada.Tags.Get_Offset_Index
11220 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11223 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11226 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11228 -- where Obj is the controlling formal parameter, S is the dispatch
11229 -- table slot number of the dispatching operation, P is the wrapped
11230 -- parameter block, D is the duration, M is the duration mode, C is
11231 -- the call kind and B is the call status.
11233 Params := New_List;
11235 Append_To (Params, New_Copy_Tree (Obj));
11236 Append_To (Params, New_Reference_To (S, Loc));
11237 Append_To (Params, Make_Attribute_Reference (Loc,
11238 Prefix => New_Reference_To (P, Loc),
11239 Attribute_Name => Name_Address));
11240 Append_To (Params, New_Reference_To (D, Loc));
11241 Append_To (Params, New_Reference_To (M, Loc));
11242 Append_To (Params, New_Reference_To (C, Loc));
11243 Append_To (Params, New_Reference_To (B, Loc));
11245 Append_To (Conc_Typ_Stmts,
11246 Make_Procedure_Call_Statement (Loc,
11249 Find_Prim_Op (Etype (Etype (Obj)),
11250 Name_uDisp_Timed_Select),
11252 Parameter_Associations =>
11256 -- if C = POK_Protected_Entry
11257 -- or else C = POK_Task_Entry
11259 -- Param1 := P.Param1;
11261 -- ParamN := P.ParamN;
11264 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11266 -- Generate the if statement only when the packed parameters need
11267 -- explicit assignments to their corresponding actuals.
11269 if Present (Unpack) then
11270 Append_To (Conc_Typ_Stmts,
11271 Make_If_Statement (Loc,
11278 New_Reference_To (C, Loc),
11280 New_Reference_To (RTE (
11281 RE_POK_Protected_Entry), Loc)),
11285 New_Reference_To (C, Loc),
11287 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11296 -- if C = POK_Procedure
11297 -- or else C = POK_Protected_Procedure
11298 -- or else C = POK_Task_Procedure
11300 -- <dispatching-call>
11302 -- <triggering-statements>
11304 -- <timed-statements>
11307 N_Stats := New_Copy_List_Tree (E_Stats);
11309 Prepend_To (N_Stats,
11310 Make_If_Statement (Loc,
11317 New_Reference_To (C, Loc),
11319 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11325 New_Reference_To (C, Loc),
11327 New_Reference_To (RTE (
11328 RE_POK_Protected_Procedure), Loc)),
11332 New_Reference_To (C, Loc),
11334 New_Reference_To (RTE (
11335 RE_POK_Task_Procedure), Loc)))),
11338 New_List (E_Call)));
11340 Append_To (Conc_Typ_Stmts,
11341 Make_If_Statement (Loc,
11342 Condition => New_Reference_To (B, Loc),
11343 Then_Statements => N_Stats,
11344 Else_Statements => D_Stats));
11347 -- <dispatching-call>;
11348 -- <triggering-statements>
11350 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
11351 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11354 -- if K = Ada.Tags.TK_Limited_Tagged then
11361 Make_If_Statement (Loc,
11365 New_Reference_To (K, Loc),
11367 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11376 -- Skip assignments to temporaries created for in-out parameters.
11377 -- This makes unwarranted assumptions about the shape of the expanded
11378 -- tree for the call, and should be cleaned up ???
11380 Stmt := First (Stmts);
11381 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11385 -- Do the assignment at this stage only because the evaluation
11386 -- of the expression must not occur before (see ACVC C97302A).
11388 Insert_Before (Stmt,
11389 Make_Assignment_Statement (Loc,
11390 Name => New_Reference_To (D, Loc),
11391 Expression => D_Conv));
11394 Params := Parameter_Associations (Call);
11396 -- For a protected type, we build a Timed_Protected_Entry_Call
11398 if Is_Protected_Type (Etype (Concval)) then
11400 -- Create a new call statement
11402 Param := First (Params);
11403 while Present (Param)
11404 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11409 Dummy := Remove_Next (Next (Param));
11411 -- Remove garbage is following the Cancel_Param if present
11413 Dummy := Next (Param);
11415 -- Remove the mode of the Protected_Entry_Call call, then remove
11416 -- the Communication_Block of the Protected_Entry_Call call, and
11417 -- finally add Duration and a Delay_Mode parameter
11419 pragma Assert (Present (Param));
11420 Rewrite (Param, New_Reference_To (D, Loc));
11422 Rewrite (Dummy, New_Reference_To (M, Loc));
11424 -- Add a Boolean flag for successful entry call
11426 Append_To (Params, New_Reference_To (B, Loc));
11428 case Corresponding_Runtime_Package (Etype (Concval)) is
11429 when System_Tasking_Protected_Objects_Entries =>
11431 Make_Procedure_Call_Statement (Loc,
11434 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11435 Parameter_Associations => Params));
11437 when System_Tasking_Protected_Objects_Single_Entry =>
11438 Param := First (Params);
11439 while Present (Param)
11441 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11449 Make_Procedure_Call_Statement (Loc,
11450 Name => New_Reference_To (
11451 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11452 Parameter_Associations => Params));
11455 raise Program_Error;
11458 -- For the task case, build a Timed_Task_Entry_Call
11461 -- Create a new call statement
11463 Append_To (Params, New_Reference_To (D, Loc));
11464 Append_To (Params, New_Reference_To (M, Loc));
11465 Append_To (Params, New_Reference_To (B, Loc));
11468 Make_Procedure_Call_Statement (Loc,
11470 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11471 Parameter_Associations => Params));
11475 Make_Implicit_If_Statement (N,
11476 Condition => New_Reference_To (B, Loc),
11477 Then_Statements => E_Stats,
11478 Else_Statements => D_Stats));
11482 Make_Block_Statement (Loc,
11483 Declarations => Decls,
11484 Handled_Statement_Sequence =>
11485 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11488 end Expand_N_Timed_Entry_Call;
11490 ----------------------------------------
11491 -- Expand_Protected_Body_Declarations --
11492 ----------------------------------------
11494 procedure Expand_Protected_Body_Declarations
11496 Spec_Id : Entity_Id)
11499 if No_Run_Time_Mode then
11500 Error_Msg_CRT ("protected body", N);
11503 elsif Expander_Active then
11505 -- Associate discriminals with the first subprogram or entry body to
11508 if Present (First_Protected_Operation (Declarations (N))) then
11509 Set_Discriminals (Parent (Spec_Id));
11512 end Expand_Protected_Body_Declarations;
11514 -------------------------
11515 -- External_Subprogram --
11516 -------------------------
11518 function External_Subprogram (E : Entity_Id) return Entity_Id is
11519 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11522 -- The internal and external subprograms follow each other on the entity
11523 -- chain. Note that previously private operations had no separate
11524 -- external subprogram. We now create one in all cases, because a
11525 -- private operation may actually appear in an external call, through
11526 -- a 'Access reference used for a callback.
11528 -- If the operation is a function that returns an anonymous access type,
11529 -- the corresponding itype appears before the operation, and must be
11532 -- This mechanism is fragile, there should be a real link between the
11533 -- two versions of the operation, but there is no place to put it ???
11535 if Is_Access_Type (Next_Entity (Subp)) then
11536 return Next_Entity (Next_Entity (Subp));
11538 return Next_Entity (Subp);
11540 end External_Subprogram;
11542 ------------------------------
11543 -- Extract_Dispatching_Call --
11544 ------------------------------
11546 procedure Extract_Dispatching_Call
11548 Call_Ent : out Entity_Id;
11549 Object : out Entity_Id;
11550 Actuals : out List_Id;
11551 Formals : out List_Id)
11553 Call_Nam : Node_Id;
11556 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11558 if Present (Original_Node (N)) then
11559 Call_Nam := Name (Original_Node (N));
11561 Call_Nam := Name (N);
11564 -- Retrieve the name of the dispatching procedure. It contains the
11565 -- dispatch table slot number.
11568 case Nkind (Call_Nam) is
11569 when N_Identifier =>
11572 when N_Selected_Component =>
11573 Call_Nam := Selector_Name (Call_Nam);
11576 raise Program_Error;
11581 Actuals := Parameter_Associations (N);
11582 Call_Ent := Entity (Call_Nam);
11583 Formals := Parameter_Specifications (Parent (Call_Ent));
11584 Object := First (Actuals);
11586 if Present (Original_Node (Object)) then
11587 Object := Original_Node (Object);
11590 -- If the type of the dispatching object is an access type then return
11591 -- an explicit dereference.
11593 if Is_Access_Type (Etype (Object)) then
11594 Object := Make_Explicit_Dereference (Sloc (N), Object);
11597 end Extract_Dispatching_Call;
11599 -------------------
11600 -- Extract_Entry --
11601 -------------------
11603 procedure Extract_Entry
11605 Concval : out Node_Id;
11606 Ename : out Node_Id;
11607 Index : out Node_Id)
11609 Nam : constant Node_Id := Name (N);
11612 -- For a simple entry, the name is a selected component, with the
11613 -- prefix being the task value, and the selector being the entry.
11615 if Nkind (Nam) = N_Selected_Component then
11616 Concval := Prefix (Nam);
11617 Ename := Selector_Name (Nam);
11620 -- For a member of an entry family, the name is an indexed component
11621 -- where the prefix is a selected component, whose prefix in turn is
11622 -- the task value, and whose selector is the entry family. The single
11623 -- expression in the expressions list of the indexed component is the
11624 -- subscript for the family.
11626 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11627 Concval := Prefix (Prefix (Nam));
11628 Ename := Selector_Name (Prefix (Nam));
11629 Index := First (Expressions (Nam));
11633 -------------------
11634 -- Family_Offset --
11635 -------------------
11637 function Family_Offset
11642 Cap : Boolean) return Node_Id
11648 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11649 -- If one of the bounds is a reference to a discriminant, replace with
11650 -- corresponding discriminal of type. Within the body of a task retrieve
11651 -- the renamed discriminant by simple visibility, using its generated
11652 -- name. Within a protected object, find the original discriminant and
11653 -- replace it with the discriminal of the current protected operation.
11655 ------------------------------
11656 -- Convert_Discriminant_Ref --
11657 ------------------------------
11659 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11660 Loc : constant Source_Ptr := Sloc (Bound);
11665 if Is_Entity_Name (Bound)
11666 and then Ekind (Entity (Bound)) = E_Discriminant
11668 if Is_Task_Type (Ttyp)
11669 and then Has_Completion (Ttyp)
11671 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11672 Find_Direct_Name (B);
11674 elsif Is_Protected_Type (Ttyp) then
11675 D := First_Discriminant (Ttyp);
11676 while Chars (D) /= Chars (Entity (Bound)) loop
11677 Next_Discriminant (D);
11680 B := New_Reference_To (Discriminal (D), Loc);
11683 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11686 elsif Nkind (Bound) = N_Attribute_Reference then
11690 B := New_Copy_Tree (Bound);
11694 Make_Attribute_Reference (Loc,
11695 Attribute_Name => Name_Pos,
11696 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11697 Expressions => New_List (B));
11698 end Convert_Discriminant_Ref;
11700 -- Start of processing for Family_Offset
11703 Real_Hi := Convert_Discriminant_Ref (Hi);
11704 Real_Lo := Convert_Discriminant_Ref (Lo);
11707 if Is_Task_Type (Ttyp) then
11708 Ityp := RTE (RE_Task_Entry_Index);
11710 Ityp := RTE (RE_Protected_Entry_Index);
11714 Make_Attribute_Reference (Loc,
11715 Prefix => New_Reference_To (Ityp, Loc),
11716 Attribute_Name => Name_Min,
11717 Expressions => New_List (
11719 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11722 Make_Attribute_Reference (Loc,
11723 Prefix => New_Reference_To (Ityp, Loc),
11724 Attribute_Name => Name_Max,
11725 Expressions => New_List (
11727 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11730 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11737 function Family_Size
11742 Cap : Boolean) return Node_Id
11747 if Is_Task_Type (Ttyp) then
11748 Ityp := RTE (RE_Task_Entry_Index);
11750 Ityp := RTE (RE_Protected_Entry_Index);
11754 Make_Attribute_Reference (Loc,
11755 Prefix => New_Reference_To (Ityp, Loc),
11756 Attribute_Name => Name_Max,
11757 Expressions => New_List (
11760 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11762 Make_Integer_Literal (Loc, 1)),
11763 Make_Integer_Literal (Loc, 0)));
11766 -----------------------
11767 -- Find_Master_Scope --
11768 -----------------------
11770 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
11774 -- In Ada2005, the master is the innermost enclosing scope that is not
11775 -- transient. If the enclosing block is the rewriting of a call or the
11776 -- scope is an extended return statement this is valid master. The
11777 -- master in an extended return is only used within the return, and is
11778 -- subsequently overwritten in Move_Activation_Chain, but it must exist
11779 -- now before that overwriting occurs.
11783 if Ada_Version >= Ada_2005 then
11784 while Is_Internal (S) loop
11785 if Nkind (Parent (S)) = N_Block_Statement
11787 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
11791 elsif Ekind (S) = E_Return_Statement then
11801 end Find_Master_Scope;
11803 -----------------------------------
11804 -- Find_Task_Or_Protected_Pragma --
11805 -----------------------------------
11807 function Find_Task_Or_Protected_Pragma
11809 P : Name_Id) return Node_Id
11814 N := First (Visible_Declarations (T));
11815 while Present (N) loop
11816 if Nkind (N) = N_Pragma then
11817 if Pragma_Name (N) = P then
11820 elsif P = Name_Priority
11821 and then Pragma_Name (N) = Name_Interrupt_Priority
11834 N := First (Private_Declarations (T));
11835 while Present (N) loop
11836 if Nkind (N) = N_Pragma then
11837 if Pragma_Name (N) = P then
11840 elsif P = Name_Priority
11841 and then Pragma_Name (N) = Name_Interrupt_Priority
11854 raise Program_Error;
11855 end Find_Task_Or_Protected_Pragma;
11857 -------------------------------
11858 -- First_Protected_Operation --
11859 -------------------------------
11861 function First_Protected_Operation (D : List_Id) return Node_Id is
11862 First_Op : Node_Id;
11865 First_Op := First (D);
11866 while Present (First_Op)
11867 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11873 end First_Protected_Operation;
11875 ---------------------------------------
11876 -- Install_Private_Data_Declarations --
11877 ---------------------------------------
11879 procedure Install_Private_Data_Declarations
11881 Spec_Id : Entity_Id;
11882 Conc_Typ : Entity_Id;
11883 Body_Nod : Node_Id;
11885 Barrier : Boolean := False;
11886 Family : Boolean := False)
11888 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11891 Insert_Node : Node_Id := Empty;
11892 Obj_Ent : Entity_Id;
11894 procedure Add (Decl : Node_Id);
11895 -- Add a single declaration after Insert_Node. If this is the first
11896 -- addition, Decl is added to the front of Decls and it becomes the
11899 function Replace_Bound (Bound : Node_Id) return Node_Id;
11900 -- The bounds of an entry index may depend on discriminants, create a
11901 -- reference to the corresponding prival. Otherwise return a duplicate
11902 -- of the original bound.
11908 procedure Add (Decl : Node_Id) is
11910 if No (Insert_Node) then
11911 Prepend_To (Decls, Decl);
11913 Insert_After (Insert_Node, Decl);
11916 Insert_Node := Decl;
11919 --------------------------
11920 -- Replace_Discriminant --
11921 --------------------------
11923 function Replace_Bound (Bound : Node_Id) return Node_Id is
11925 if Nkind (Bound) = N_Identifier
11926 and then Is_Discriminal (Entity (Bound))
11928 return Make_Identifier (Loc, Chars (Entity (Bound)));
11930 return Duplicate_Subexpr (Bound);
11934 -- Start of processing for Install_Private_Data_Declarations
11937 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11938 -- formal parameter _O, _object or _task depending on the context.
11940 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11942 -- Special processing of _O for barrier functions, protected entries
11949 (Ekind (Spec_Id) = E_Entry
11950 or else Ekind (Spec_Id) = E_Entry_Family))
11953 Conc_Rec : constant Entity_Id :=
11954 Corresponding_Record_Type (Conc_Typ);
11955 Typ_Id : constant Entity_Id :=
11956 Make_Defining_Identifier (Loc,
11957 New_External_Name (Chars (Conc_Rec), 'P'));
11960 -- type prot_typVP is access prot_typV;
11963 Make_Full_Type_Declaration (Loc,
11964 Defining_Identifier => Typ_Id,
11966 Make_Access_To_Object_Definition (Loc,
11967 Subtype_Indication =>
11968 New_Reference_To (Conc_Rec, Loc)));
11972 -- _object : prot_typVP := prot_typV (_O);
11975 Make_Object_Declaration (Loc,
11976 Defining_Identifier =>
11977 Make_Defining_Identifier (Loc, Name_uObject),
11978 Object_Definition => New_Reference_To (Typ_Id, Loc),
11980 Unchecked_Convert_To (Typ_Id,
11981 New_Reference_To (Obj_Ent, Loc)));
11984 -- Set the reference to the concurrent object
11986 Obj_Ent := Defining_Identifier (Decl);
11990 -- Step 2: Create the Protection object and build its declaration for
11991 -- any protected entry (family) of subprogram.
11993 if Is_Protected then
11995 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
11999 Set_Protection_Object (Spec_Id, Prot_Ent);
12001 -- Determine the proper protection type
12003 if Has_Attach_Handler (Conc_Typ)
12004 and then not Restricted_Profile
12006 Prot_Typ := RE_Static_Interrupt_Protection;
12008 elsif Has_Interrupt_Handler (Conc_Typ) then
12009 Prot_Typ := RE_Dynamic_Interrupt_Protection;
12011 -- The type has explicit entries or generated primitive entry
12014 elsif Has_Entries (Conc_Typ)
12016 (Ada_Version >= Ada_2005
12017 and then Present (Interface_List (Parent (Conc_Typ))))
12019 case Corresponding_Runtime_Package (Conc_Typ) is
12020 when System_Tasking_Protected_Objects_Entries =>
12021 Prot_Typ := RE_Protection_Entries;
12023 when System_Tasking_Protected_Objects_Single_Entry =>
12024 Prot_Typ := RE_Protection_Entry;
12027 raise Program_Error;
12031 Prot_Typ := RE_Protection;
12035 -- conc_typR : protection_typ renames _object._object;
12038 Make_Object_Renaming_Declaration (Loc,
12039 Defining_Identifier => Prot_Ent,
12041 New_Reference_To (RTE (Prot_Typ), Loc),
12043 Make_Selected_Component (Loc,
12044 Prefix => New_Reference_To (Obj_Ent, Loc),
12045 Selector_Name => Make_Identifier (Loc, Name_uObject)));
12050 -- Step 3: Add discriminant renamings (if any)
12052 if Has_Discriminants (Conc_Typ) then
12057 D := First_Discriminant (Conc_Typ);
12058 while Present (D) loop
12060 -- Adjust the source location
12062 Set_Sloc (Discriminal (D), Loc);
12065 -- discr_name : discr_typ renames _object.discr_name;
12067 -- discr_name : discr_typ renames _task.discr_name;
12070 Make_Object_Renaming_Declaration (Loc,
12071 Defining_Identifier => Discriminal (D),
12072 Subtype_Mark => New_Reference_To (Etype (D), Loc),
12074 Make_Selected_Component (Loc,
12075 Prefix => New_Reference_To (Obj_Ent, Loc),
12076 Selector_Name => Make_Identifier (Loc, Chars (D))));
12079 Next_Discriminant (D);
12084 -- Step 4: Add private component renamings (if any)
12086 if Is_Protected then
12087 Def := Protected_Definition (Parent (Conc_Typ));
12089 if Present (Private_Declarations (Def)) then
12092 Comp_Id : Entity_Id;
12093 Decl_Id : Entity_Id;
12096 Comp := First (Private_Declarations (Def));
12097 while Present (Comp) loop
12098 if Nkind (Comp) = N_Component_Declaration then
12099 Comp_Id := Defining_Identifier (Comp);
12101 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12103 -- Minimal decoration
12105 if Ekind (Spec_Id) = E_Function then
12106 Set_Ekind (Decl_Id, E_Constant);
12108 Set_Ekind (Decl_Id, E_Variable);
12111 Set_Prival (Comp_Id, Decl_Id);
12112 Set_Prival_Link (Decl_Id, Comp_Id);
12113 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
12116 -- comp_name : comp_typ renames _object.comp_name;
12119 Make_Object_Renaming_Declaration (Loc,
12120 Defining_Identifier => Decl_Id,
12122 New_Reference_To (Etype (Comp_Id), Loc),
12124 Make_Selected_Component (Loc,
12126 New_Reference_To (Obj_Ent, Loc),
12128 Make_Identifier (Loc, Chars (Comp_Id))));
12138 -- Step 5: Add the declaration of the entry index and the associated
12139 -- type for barrier functions and entry families.
12141 if (Barrier and then Family)
12142 or else Ekind (Spec_Id) = E_Entry_Family
12145 E : constant Entity_Id := Index_Object (Spec_Id);
12146 Index : constant Entity_Id :=
12147 Defining_Identifier (
12148 Entry_Index_Specification (
12149 Entry_Body_Formal_Part (Body_Nod)));
12150 Index_Con : constant Entity_Id :=
12151 Make_Defining_Identifier (Loc, Chars (Index));
12153 Index_Typ : Entity_Id;
12157 -- Minimal decoration
12159 Set_Ekind (Index_Con, E_Constant);
12160 Set_Entry_Index_Constant (Index, Index_Con);
12161 Set_Discriminal_Link (Index_Con, Index);
12163 -- Retrieve the bounds of the entry family
12165 High := Type_High_Bound (Etype (Index));
12166 Low := Type_Low_Bound (Etype (Index));
12168 -- In the simple case the entry family is given by a subtype
12169 -- mark and the index constant has the same type.
12171 if Is_Entity_Name (Original_Node (
12172 Discrete_Subtype_Definition (Parent (Index))))
12174 Index_Typ := Etype (Index);
12176 -- Otherwise a new subtype declaration is required
12179 High := Replace_Bound (High);
12180 Low := Replace_Bound (Low);
12182 Index_Typ := Make_Temporary (Loc, 'J');
12185 -- subtype Jnn is <Etype of Index> range Low .. High;
12188 Make_Subtype_Declaration (Loc,
12189 Defining_Identifier => Index_Typ,
12190 Subtype_Indication =>
12191 Make_Subtype_Indication (Loc,
12193 New_Reference_To (Base_Type (Etype (Index)), Loc),
12195 Make_Range_Constraint (Loc,
12196 Range_Expression =>
12197 Make_Range (Loc, Low, High))));
12201 Set_Etype (Index_Con, Index_Typ);
12203 -- Create the object which designates the index:
12204 -- J : constant Jnn :=
12205 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12207 -- where Jnn is the subtype created above or the original type of
12208 -- the index, _E is a formal of the protected body subprogram and
12209 -- <index expr> is the index of the first family member.
12212 Make_Object_Declaration (Loc,
12213 Defining_Identifier => Index_Con,
12214 Constant_Present => True,
12215 Object_Definition =>
12216 New_Reference_To (Index_Typ, Loc),
12219 Make_Attribute_Reference (Loc,
12221 New_Reference_To (Index_Typ, Loc),
12222 Attribute_Name => Name_Val,
12224 Expressions => New_List (
12228 Make_Op_Subtract (Loc,
12230 New_Reference_To (E, Loc),
12232 Entry_Index_Expression (Loc,
12233 Defining_Identifier (Body_Nod),
12237 Make_Attribute_Reference (Loc,
12239 New_Reference_To (Index_Typ, Loc),
12240 Attribute_Name => Name_Pos,
12241 Expressions => New_List (
12242 Make_Attribute_Reference (Loc,
12244 New_Reference_To (Index_Typ, Loc),
12245 Attribute_Name => Name_First)))))));
12249 end Install_Private_Data_Declarations;
12251 ---------------------------------
12252 -- Is_Potentially_Large_Family --
12253 ---------------------------------
12255 function Is_Potentially_Large_Family
12256 (Base_Index : Entity_Id;
12257 Conctyp : Entity_Id;
12259 Hi : Node_Id) return Boolean
12262 return Scope (Base_Index) = Standard_Standard
12263 and then Base_Index = Base_Type (Standard_Integer)
12264 and then Has_Discriminants (Conctyp)
12266 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12268 (Denotes_Discriminant (Lo, True)
12269 or else Denotes_Discriminant (Hi, True));
12270 end Is_Potentially_Large_Family;
12272 -------------------------------------
12273 -- Is_Private_Primitive_Subprogram --
12274 -------------------------------------
12276 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12279 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12280 and then Is_Private_Primitive (Id);
12281 end Is_Private_Primitive_Subprogram;
12287 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12288 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12289 Formal : Entity_Id;
12292 Formal := First_Formal (Bod_Subp);
12293 while Present (Formal) loop
12295 -- Look for formal parameter _E
12297 if Chars (Formal) = Name_uE then
12301 Next_Formal (Formal);
12304 -- A protected body subprogram should always have the parameter in
12307 raise Program_Error;
12310 --------------------------------
12311 -- Make_Initialize_Protection --
12312 --------------------------------
12314 function Make_Initialize_Protection
12315 (Protect_Rec : Entity_Id) return List_Id
12317 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12321 Ptyp : constant Node_Id :=
12322 Corresponding_Concurrent_Type (Protect_Rec);
12324 L : constant List_Id := New_List;
12325 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12326 Restricted : constant Boolean := Restricted_Profile;
12329 -- We may need two calls to properly initialize the object, one to
12330 -- Initialize_Protection, and possibly one to Install_Handlers if we
12331 -- have a pragma Attach_Handler.
12333 -- Get protected declaration. In the case of a task type declaration,
12334 -- this is simply the parent of the protected type entity. In the single
12335 -- protected object declaration, this parent will be the implicit type,
12336 -- and we can find the corresponding single protected object declaration
12337 -- by searching forward in the declaration list in the tree.
12339 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12340 -- of this type should have been removed during semantic analysis.
12342 Pdec := Parent (Ptyp);
12343 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12344 N_Single_Protected_Declaration)
12349 -- Now we can find the object definition from this declaration
12351 Pdef := Protected_Definition (Pdec);
12353 -- Build the parameter list for the call. Note that _Init is the name
12354 -- of the formal for the object to be initialized, which is the task
12355 -- value record itself.
12359 -- Object parameter. This is a pointer to the object of type
12360 -- Protection used by the GNARL to control the protected object.
12363 Make_Attribute_Reference (Loc,
12365 Make_Selected_Component (Loc,
12366 Prefix => Make_Identifier (Loc, Name_uInit),
12367 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12368 Attribute_Name => Name_Unchecked_Access));
12370 -- Priority parameter. Set to Unspecified_Priority unless there is a
12371 -- priority pragma, in which case we take the value from the pragma,
12372 -- or there is an interrupt pragma and no priority pragma, and we
12373 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12374 -- defined value, see D.3(10).
12377 and then Has_Pragma_Priority (Pdef)
12380 Prio : constant Node_Id :=
12383 (Pragma_Argument_Associations
12384 (Find_Task_Or_Protected_Pragma
12385 (Pdef, Name_Priority))));
12389 -- If priority is a static expression, then we can duplicate it
12390 -- with no problem and simply append it to the argument list.
12392 if Is_Static_Expression (Prio) then
12394 Duplicate_Subexpr_No_Checks (Prio));
12396 -- Otherwise, the priority may be a per-object expression, if it
12397 -- depends on a discriminant of the type. In this case, create
12398 -- local variable to capture the expression. Note that it is
12399 -- really necessary to create this variable explicitly. It might
12400 -- be thought that removing side effects would the appropriate
12401 -- approach, but that could generate declarations improperly
12402 -- placed in the enclosing scope.
12404 -- Note: Use System.Any_Priority as the expected type for the
12405 -- non-static priority expression, in case the expression has not
12406 -- been analyzed yet (as occurs for example with pragma
12407 -- Interrupt_Priority).
12410 Temp := Make_Temporary (Loc, 'R', Prio);
12412 Make_Object_Declaration (Loc,
12413 Defining_Identifier => Temp,
12414 Object_Definition =>
12415 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12416 Expression => Relocate_Node (Prio)));
12418 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12422 -- When no priority is specified but an xx_Handler pragma is, we default
12423 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12425 elsif Has_Interrupt_Handler (Ptyp)
12426 or else Has_Attach_Handler (Ptyp)
12429 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12431 -- Normal case, no priority or xx_Handler specified, default priority
12435 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12438 -- Test for Compiler_Info parameter. This parameter allows entry body
12439 -- procedures and barrier functions to be called from the runtime. It
12440 -- is a pointer to the record generated by the compiler to represent
12441 -- the protected object.
12443 -- A protected type without entries that covers an interface and
12444 -- overrides the abstract routines with protected procedures is
12445 -- considered equivalent to a protected type with entries in the
12446 -- context of dispatching select statements.
12449 or else Has_Interrupt_Handler (Ptyp)
12450 or else Has_Attach_Handler (Ptyp)
12451 or else Has_Interfaces (Protect_Rec)
12454 Pkg_Id : constant RTU_Id :=
12455 Corresponding_Runtime_Package (Ptyp);
12456 Called_Subp : RE_Id;
12460 when System_Tasking_Protected_Objects_Entries =>
12461 Called_Subp := RE_Initialize_Protection_Entries;
12463 when System_Tasking_Protected_Objects =>
12464 Called_Subp := RE_Initialize_Protection;
12466 when System_Tasking_Protected_Objects_Single_Entry =>
12467 Called_Subp := RE_Initialize_Protection_Entry;
12470 raise Program_Error;
12474 or else not Restricted
12475 or else Has_Interfaces (Protect_Rec)
12478 Make_Attribute_Reference (Loc,
12479 Prefix => Make_Identifier (Loc, Name_uInit),
12480 Attribute_Name => Name_Address));
12483 -- Entry_Bodies parameter. This is a pointer to an array of
12484 -- pointers to the entry body procedures and barrier functions of
12485 -- the object. If the protected type has no entries this object
12486 -- will not exist, in this case, pass a null.
12489 P_Arr := Entry_Bodies_Array (Ptyp);
12492 Make_Attribute_Reference (Loc,
12493 Prefix => New_Reference_To (P_Arr, Loc),
12494 Attribute_Name => Name_Unrestricted_Access));
12496 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12498 -- Find index mapping function (clumsy but ok for now)
12500 while Ekind (P_Arr) /= E_Function loop
12501 Next_Entity (P_Arr);
12505 Make_Attribute_Reference (Loc,
12507 New_Reference_To (P_Arr, Loc),
12508 Attribute_Name => Name_Unrestricted_Access));
12510 -- Build_Entry_Names generation flag. When set to true, the
12511 -- runtime will allocate an array to hold the string names
12512 -- of protected entries.
12514 if not Restricted_Profile then
12515 if Entry_Names_OK then
12517 New_Reference_To (Standard_True, Loc));
12520 New_Reference_To (Standard_False, Loc));
12525 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12526 Append_To (Args, Make_Null (Loc));
12528 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12529 Append_To (Args, Make_Null (Loc));
12530 Append_To (Args, Make_Null (Loc));
12531 Append_To (Args, New_Reference_To (Standard_False, Loc));
12535 Make_Procedure_Call_Statement (Loc,
12536 Name => New_Reference_To (RTE (Called_Subp), Loc),
12537 Parameter_Associations => Args));
12541 Make_Procedure_Call_Statement (Loc,
12542 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12543 Parameter_Associations => Args));
12546 if Has_Attach_Handler (Ptyp) then
12548 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12549 -- make the following call:
12551 -- Install_Handlers (_object,
12552 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12554 -- or, in the case of Ravenscar:
12556 -- Install_Restricted_Handlers
12557 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12560 Args : constant List_Id := New_List;
12561 Table : constant List_Id := New_List;
12562 Ritem : Node_Id := First_Rep_Item (Ptyp);
12565 -- Build the Attach_Handler table argument
12567 while Present (Ritem) loop
12568 if Nkind (Ritem) = N_Pragma
12569 and then Pragma_Name (Ritem) = Name_Attach_Handler
12572 Handler : constant Node_Id :=
12573 First (Pragma_Argument_Associations (Ritem));
12575 Interrupt : constant Node_Id := Next (Handler);
12576 Expr : constant Node_Id := Expression (Interrupt);
12580 Make_Aggregate (Loc, Expressions => New_List (
12581 Unchecked_Convert_To
12582 (RTE (RE_System_Interrupt_Id), Expr),
12583 Make_Attribute_Reference (Loc,
12584 Prefix => Make_Selected_Component (Loc,
12585 Make_Identifier (Loc, Name_uInit),
12586 Duplicate_Subexpr_No_Checks
12587 (Expression (Handler))),
12588 Attribute_Name => Name_Access))));
12592 Next_Rep_Item (Ritem);
12595 -- Append the table argument we just built
12597 Append_To (Args, Make_Aggregate (Loc, Table));
12599 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12600 -- call to the statements.
12603 -- Call a simplified version of Install_Handlers to be used
12604 -- when the Ravenscar restrictions are in effect
12605 -- (Install_Restricted_Handlers).
12608 Make_Procedure_Call_Statement (Loc,
12611 (RTE (RE_Install_Restricted_Handlers), Loc),
12612 Parameter_Associations => Args));
12615 -- First, prepends the _object argument
12618 Make_Attribute_Reference (Loc,
12620 Make_Selected_Component (Loc,
12621 Prefix => Make_Identifier (Loc, Name_uInit),
12622 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12623 Attribute_Name => Name_Unchecked_Access));
12625 -- Then, insert call to Install_Handlers
12628 Make_Procedure_Call_Statement (Loc,
12629 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
12630 Parameter_Associations => Args));
12636 end Make_Initialize_Protection;
12638 ---------------------------
12639 -- Make_Task_Create_Call --
12640 ---------------------------
12642 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
12643 Loc : constant Source_Ptr := Sloc (Task_Rec);
12653 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
12654 Tnam := Chars (Ttyp);
12656 -- Get task declaration. In the case of a task type declaration, this is
12657 -- simply the parent of the task type entity. In the single task
12658 -- declaration, this parent will be the implicit type, and we can find
12659 -- the corresponding single task declaration by searching forward in the
12660 -- declaration list in the tree.
12662 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12663 -- this type should have been removed during semantic analysis.
12665 Tdec := Parent (Ttyp);
12666 while not Nkind_In (Tdec, N_Task_Type_Declaration,
12667 N_Single_Task_Declaration)
12672 -- Now we can find the task definition from this declaration
12674 Tdef := Task_Definition (Tdec);
12676 -- Build the parameter list for the call. Note that _Init is the name
12677 -- of the formal for the object to be initialized, which is the task
12678 -- value record itself.
12682 -- Priority parameter. Set to Unspecified_Priority unless there is a
12683 -- priority pragma, in which case we take the value from the pragma.
12685 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
12687 Make_Selected_Component (Loc,
12688 Prefix => Make_Identifier (Loc, Name_uInit),
12689 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12692 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12695 -- Optional Stack parameter
12697 if Restricted_Profile then
12699 -- If the stack has been preallocated by the expander then
12700 -- pass its address. Otherwise, pass a null address.
12702 if Preallocated_Stacks_On_Target then
12704 Make_Attribute_Reference (Loc,
12706 Make_Selected_Component (Loc,
12707 Prefix => Make_Identifier (Loc, Name_uInit),
12708 Selector_Name => Make_Identifier (Loc, Name_uStack)),
12709 Attribute_Name => Name_Address));
12713 New_Reference_To (RTE (RE_Null_Address), Loc));
12717 -- Size parameter. If no Storage_Size pragma is present, then
12718 -- the size is taken from the taskZ variable for the type, which
12719 -- is either Unspecified_Size, or has been reset by the use of
12720 -- a Storage_Size attribute definition clause. If a pragma is
12721 -- present, then the size is taken from the _Size field of the
12722 -- task value record, which was set from the pragma value.
12725 and then Has_Storage_Size_Pragma (Tdef)
12728 Make_Selected_Component (Loc,
12729 Prefix => Make_Identifier (Loc, Name_uInit),
12730 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12734 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12737 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12738 -- Task_Info pragma, in which case we take the value from the pragma.
12741 and then Has_Task_Info_Pragma (Tdef)
12744 Make_Selected_Component (Loc,
12745 Prefix => Make_Identifier (Loc, Name_uInit),
12746 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12750 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12753 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
12754 -- in which case we take the value from the pragma. The parameter is
12755 -- passed as an Integer because in the case of unspecified CPU the
12756 -- value is not in the range of CPU_Range.
12758 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
12760 Convert_To (Standard_Integer,
12761 Make_Selected_Component (Loc,
12762 Prefix => Make_Identifier (Loc, Name_uInit),
12763 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
12767 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
12770 if not Restricted_Profile then
12772 -- Deadline parameter. If no Relative_Deadline pragma is present,
12773 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12774 -- the deadline is taken from the _Relative_Deadline field of the
12775 -- task value record, which was set from the pragma value. Note that
12776 -- this parameter must not be generated for the restricted profiles
12777 -- since Ravenscar does not allow deadlines.
12779 -- Case where pragma Relative_Deadline applies: use given value
12781 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12783 Make_Selected_Component (Loc,
12785 Make_Identifier (Loc, Name_uInit),
12787 Make_Identifier (Loc, Name_uRelative_Deadline)));
12789 -- No pragma Relative_Deadline apply to the task
12793 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12796 -- Number of entries. This is an expression of the form:
12798 -- n + _Init.a'Length + _Init.a'B'Length + ...
12800 -- where a,b... are the entry family names for the task definition
12803 Build_Entry_Count_Expression
12808 (Parent (Corresponding_Record_Type (Ttyp))))),
12810 Append_To (Args, Ecount);
12812 -- Master parameter. This is a reference to the _Master parameter of
12813 -- the initialization procedure, except in the case of the pragma
12814 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
12815 -- System.Tasking.Library_Task_Level.
12817 if Restriction_Active (No_Task_Hierarchy) = False then
12818 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12821 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
12825 -- State parameter. This is a pointer to the task body procedure. The
12826 -- required value is obtained by taking 'Unrestricted_Access of the task
12827 -- body procedure and converting it (with an unchecked conversion) to
12828 -- the type required by the task kernel. For further details, see the
12829 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12830 -- than 'Address in order to avoid creating trampolines.
12833 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12834 Subp_Ptr_Typ : constant Node_Id :=
12835 Create_Itype (E_Access_Subprogram_Type, Tdec);
12836 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12839 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12840 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12842 -- Be sure to freeze a reference to the access-to-subprogram type,
12843 -- otherwise gigi will complain that it's in the wrong scope, because
12844 -- it's actually inside the init procedure for the record type that
12845 -- corresponds to the task type.
12847 -- This processing is causing a crash in the .NET/JVM back ends that
12848 -- is not yet understood, so skip it in these cases ???
12850 if VM_Target = No_VM then
12851 Set_Itype (Ref, Subp_Ptr_Typ);
12852 Append_Freeze_Action (Task_Rec, Ref);
12855 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12856 Make_Qualified_Expression (Loc,
12857 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12859 Make_Attribute_Reference (Loc,
12861 New_Occurrence_Of (Body_Proc, Loc),
12862 Attribute_Name => Name_Unrestricted_Access))));
12864 -- For the .NET/JVM cases revert to the original code below ???
12868 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12869 Make_Attribute_Reference (Loc,
12871 New_Occurrence_Of (Body_Proc, Loc),
12872 Attribute_Name => Name_Address)));
12876 -- Discriminants parameter. This is just the address of the task
12877 -- value record itself (which contains the discriminant values
12880 Make_Attribute_Reference (Loc,
12881 Prefix => Make_Identifier (Loc, Name_uInit),
12882 Attribute_Name => Name_Address));
12884 -- Elaborated parameter. This is an access to the elaboration Boolean
12887 Make_Attribute_Reference (Loc,
12888 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12889 Attribute_Name => Name_Unchecked_Access));
12891 -- Chain parameter. This is a reference to the _Chain parameter of
12892 -- the initialization procedure.
12894 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12896 -- Task name parameter. Take this from the _Task_Id parameter to the
12897 -- init call unless there is a Task_Name pragma, in which case we take
12898 -- the value from the pragma.
12901 and then Has_Task_Name_Pragma (Tdef)
12903 -- Copy expression in full, because it may be dynamic and have
12909 (Pragma_Argument_Associations
12910 (Find_Task_Or_Protected_Pragma
12911 (Tdef, Name_Task_Name))))));
12914 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12917 -- Created_Task parameter. This is the _Task_Id field of the task
12921 Make_Selected_Component (Loc,
12922 Prefix => Make_Identifier (Loc, Name_uInit),
12923 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12925 -- Build_Entry_Names generation flag. When set to true, the runtime
12926 -- will allocate an array to hold the string names of task entries.
12928 if not Restricted_Profile then
12929 if Has_Entries (Ttyp)
12930 and then Entry_Names_OK
12932 Append_To (Args, New_Reference_To (Standard_True, Loc));
12934 Append_To (Args, New_Reference_To (Standard_False, Loc));
12938 if Restricted_Profile then
12939 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12941 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12945 Make_Procedure_Call_Statement (Loc,
12947 Parameter_Associations => Args);
12948 end Make_Task_Create_Call;
12950 ------------------------------
12951 -- Next_Protected_Operation --
12952 ------------------------------
12954 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12958 Next_Op := Next (N);
12959 while Present (Next_Op)
12960 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12966 end Next_Protected_Operation;
12968 ---------------------
12969 -- Null_Statements --
12970 ---------------------
12972 function Null_Statements (Stats : List_Id) return Boolean is
12976 Stmt := First (Stats);
12977 while Nkind (Stmt) /= N_Empty
12978 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12980 (Nkind (Stmt) = N_Pragma
12981 and then (Pragma_Name (Stmt) = Name_Unreferenced
12983 Pragma_Name (Stmt) = Name_Unmodified
12985 Pragma_Name (Stmt) = Name_Warnings)))
12990 return Nkind (Stmt) = N_Empty;
12991 end Null_Statements;
12993 --------------------------
12994 -- Parameter_Block_Pack --
12995 --------------------------
12997 function Parameter_Block_Pack
12999 Blk_Typ : Entity_Id;
13003 Stmts : List_Id) return Node_Id
13005 Actual : Entity_Id;
13006 Expr : Node_Id := Empty;
13007 Formal : Entity_Id;
13008 Has_Param : Boolean := False;
13011 Temp_Asn : Node_Id;
13012 Temp_Nam : Node_Id;
13015 Actual := First (Actuals);
13016 Formal := Defining_Identifier (First (Formals));
13017 Params := New_List;
13019 while Present (Actual) loop
13020 if Is_By_Copy_Type (Etype (Actual)) then
13022 -- Jnn : aliased <formal-type>
13024 Temp_Nam := Make_Temporary (Loc, 'J');
13027 Make_Object_Declaration (Loc,
13030 Defining_Identifier =>
13032 Object_Definition =>
13033 New_Reference_To (Etype (Formal), Loc)));
13035 if Ekind (Formal) /= E_Out_Parameter then
13041 New_Reference_To (Temp_Nam, Loc);
13043 Set_Assignment_OK (Temp_Asn);
13046 Make_Assignment_Statement (Loc,
13050 New_Copy_Tree (Actual)));
13054 -- Jnn'unchecked_access
13057 Make_Attribute_Reference (Loc,
13059 Name_Unchecked_Access,
13061 New_Reference_To (Temp_Nam, Loc)));
13065 -- The controlling parameter is omitted
13068 if not Is_Controlling_Actual (Actual) then
13070 Make_Reference (Loc, New_Copy_Tree (Actual)));
13076 Next_Actual (Actual);
13077 Next_Formal_With_Extras (Formal);
13081 Expr := Make_Aggregate (Loc, Params);
13086 -- J1'unchecked_access;
13087 -- <actual2>'reference;
13090 P := Make_Temporary (Loc, 'P');
13093 Make_Object_Declaration (Loc,
13094 Defining_Identifier =>
13096 Object_Definition =>
13097 New_Reference_To (Blk_Typ, Loc),
13102 end Parameter_Block_Pack;
13104 ----------------------------
13105 -- Parameter_Block_Unpack --
13106 ----------------------------
13108 function Parameter_Block_Unpack
13112 Formals : List_Id) return List_Id
13114 Actual : Entity_Id;
13116 Formal : Entity_Id;
13117 Has_Asnmt : Boolean := False;
13118 Result : constant List_Id := New_List;
13121 Actual := First (Actuals);
13122 Formal := Defining_Identifier (First (Formals));
13123 while Present (Actual) loop
13124 if Is_By_Copy_Type (Etype (Actual))
13125 and then Ekind (Formal) /= E_In_Parameter
13128 -- <actual> := P.<formal>;
13131 Make_Assignment_Statement (Loc,
13135 Make_Explicit_Dereference (Loc,
13136 Make_Selected_Component (Loc,
13138 New_Reference_To (P, Loc),
13140 Make_Identifier (Loc, Chars (Formal)))));
13142 Set_Assignment_OK (Name (Asnmt));
13143 Append_To (Result, Asnmt);
13148 Next_Actual (Actual);
13149 Next_Formal_With_Extras (Formal);
13155 return New_List (Make_Null_Statement (Loc));
13157 end Parameter_Block_Unpack;
13159 ----------------------
13160 -- Set_Discriminals --
13161 ----------------------
13163 procedure Set_Discriminals (Dec : Node_Id) is
13166 D_Minal : Entity_Id;
13169 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13170 Pdef := Defining_Identifier (Dec);
13172 if Has_Discriminants (Pdef) then
13173 D := First_Discriminant (Pdef);
13174 while Present (D) loop
13176 Make_Defining_Identifier (Sloc (D),
13177 Chars => New_External_Name (Chars (D), 'D'));
13179 Set_Ekind (D_Minal, E_Constant);
13180 Set_Etype (D_Minal, Etype (D));
13181 Set_Scope (D_Minal, Pdef);
13182 Set_Discriminal (D, D_Minal);
13183 Set_Discriminal_Link (D_Minal, D);
13185 Next_Discriminant (D);
13188 end Set_Discriminals;
13190 -----------------------
13191 -- Trivial_Accept_OK --
13192 -----------------------
13194 function Trivial_Accept_OK return Boolean is
13196 case Opt.Task_Dispatching_Policy is
13198 -- If we have the default task dispatching policy in effect, we can
13199 -- definitely do the optimization (one way of looking at this is to
13200 -- think of the formal definition of the default policy being allowed
13201 -- to run any task it likes after a rendezvous, so even if notionally
13202 -- a full rescheduling occurs, we can say that our dispatching policy
13203 -- (i.e. the default dispatching policy) reorders the queue to be the
13204 -- same as just before the call.
13209 -- FIFO_Within_Priorities certainly does not permit this
13210 -- optimization since the Rendezvous is a scheduling action that may
13211 -- require some other task to be run.
13216 -- For now, disallow the optimization for all other policies. This
13217 -- may be over-conservative, but it is certainly not incorrect.
13223 end Trivial_Accept_OK;