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 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
925 Cond : constant Node_Id := Condition (Ent_Formals);
926 Loc : constant Source_Ptr := Sloc (Cond);
927 Func_Id : constant Entity_Id := Barrier_Function (Ent);
928 Op_Decls : constant List_Id := New_List;
933 -- Add a declaration for the Protection object, renaming declarations
934 -- for the discriminals and privals and finally a declaration for the
935 -- entry family index (if applicable).
937 Install_Private_Data_Declarations (Sloc (N),
943 Family => Ekind (Ent) = E_Entry_Family);
945 -- If compiling with -fpreserve-control-flow, make sure we insert an
946 -- IF statement so that the back-end knows to generate a conditional
947 -- branch instruction, even if the condition is just the name of a
950 if Opt.Suppress_Control_Flow_Optimizations then
951 Stmt := Make_Implicit_If_Statement (Cond,
953 Then_Statements => New_List (
954 Make_Simple_Return_Statement (Loc,
955 New_Occurrence_Of (Standard_True, Loc))),
956 Else_Statements => New_List (
957 Make_Simple_Return_Statement (Loc,
958 New_Occurrence_Of (Standard_False, Loc))));
961 Stmt := Make_Simple_Return_Statement (Loc, Cond);
964 -- Note: the condition in the barrier function needs to be properly
965 -- processed for the C/Fortran boolean possibility, but this happens
966 -- automatically since the return statement does this normalization.
969 Make_Subprogram_Body (Loc,
971 Build_Barrier_Function_Specification (Loc,
972 Make_Defining_Identifier (Loc, Chars (Func_Id))),
973 Declarations => Op_Decls,
974 Handled_Statement_Sequence =>
975 Make_Handled_Sequence_Of_Statements (Loc,
976 Statements => New_List (Stmt)));
977 Set_Is_Entry_Barrier_Function (Func_Body);
980 end Build_Barrier_Function;
982 ------------------------------------------
983 -- Build_Barrier_Function_Specification --
984 ------------------------------------------
986 function Build_Barrier_Function_Specification
988 Def_Id : Entity_Id) return Node_Id
991 Set_Debug_Info_Needed (Def_Id);
993 return Make_Function_Specification (Loc,
994 Defining_Unit_Name => Def_Id,
995 Parameter_Specifications => New_List (
996 Make_Parameter_Specification (Loc,
997 Defining_Identifier =>
998 Make_Defining_Identifier (Loc, Name_uO),
1000 New_Reference_To (RTE (RE_Address), Loc)),
1002 Make_Parameter_Specification (Loc,
1003 Defining_Identifier =>
1004 Make_Defining_Identifier (Loc, Name_uE),
1006 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1008 Result_Definition =>
1009 New_Reference_To (Standard_Boolean, Loc));
1010 end Build_Barrier_Function_Specification;
1012 --------------------------
1013 -- Build_Call_With_Task --
1014 --------------------------
1016 function Build_Call_With_Task
1018 E : Entity_Id) return Node_Id
1020 Loc : constant Source_Ptr := Sloc (N);
1023 Make_Function_Call (Loc,
1024 Name => New_Reference_To (E, Loc),
1025 Parameter_Associations => New_List (Concurrent_Ref (N)));
1026 end Build_Call_With_Task;
1028 --------------------------------
1029 -- Build_Corresponding_Record --
1030 --------------------------------
1032 function Build_Corresponding_Record
1035 Loc : Source_Ptr) return Node_Id
1037 Rec_Ent : constant Entity_Id :=
1038 Make_Defining_Identifier
1039 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1042 New_Disc : Entity_Id;
1046 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1047 Set_Ekind (Rec_Ent, E_Record_Type);
1048 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1049 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1050 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1051 Set_Stored_Constraint (Rec_Ent, No_Elist);
1054 -- Use discriminals to create list of discriminants for record, and
1055 -- create new discriminals for use in default expressions, etc. It is
1056 -- worth noting that a task discriminant gives rise to 5 entities;
1058 -- a) The original discriminant.
1059 -- b) The discriminal for use in the task.
1060 -- c) The discriminant of the corresponding record.
1061 -- d) The discriminal for the init proc of the corresponding record.
1062 -- e) The local variable that renames the discriminant in the procedure
1063 -- for the task body.
1065 -- In fact the discriminals b) are used in the renaming declarations
1066 -- for e). See details in einfo (Handling of Discriminants).
1068 if Present (Discriminant_Specifications (N)) then
1070 Disc := First_Discriminant (Ctyp);
1072 while Present (Disc) loop
1073 New_Disc := CR_Discriminant (Disc);
1076 Make_Discriminant_Specification (Loc,
1077 Defining_Identifier => New_Disc,
1078 Discriminant_Type =>
1079 New_Occurrence_Of (Etype (Disc), Loc),
1081 New_Copy (Discriminant_Default_Value (Disc))));
1083 Next_Discriminant (Disc);
1090 -- Now we can construct the record type declaration. Note that this
1091 -- record is "limited tagged". It is "limited" to reflect the underlying
1092 -- limitedness of the task or protected object that it represents, and
1093 -- ensuring for example that it is properly passed by reference. It is
1094 -- "tagged" to give support to dispatching calls through interfaces. We
1095 -- propagate here the list of interfaces covered by the concurrent type
1096 -- (Ada 2005: AI-345).
1099 Make_Full_Type_Declaration (Loc,
1100 Defining_Identifier => Rec_Ent,
1101 Discriminant_Specifications => Dlist,
1103 Make_Record_Definition (Loc,
1105 Make_Component_List (Loc,
1106 Component_Items => Cdecls),
1108 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1109 Interface_List => Interface_List (N),
1110 Limited_Present => True));
1111 end Build_Corresponding_Record;
1113 ----------------------------------
1114 -- Build_Entry_Count_Expression --
1115 ----------------------------------
1117 function Build_Entry_Count_Expression
1118 (Concurrent_Type : Node_Id;
1119 Component_List : List_Id;
1120 Loc : Source_Ptr) return Node_Id
1132 -- Count number of non-family entries
1135 Ent := First_Entity (Concurrent_Type);
1136 while Present (Ent) loop
1137 if Ekind (Ent) = E_Entry then
1144 Ecount := Make_Integer_Literal (Loc, Eindx);
1146 -- Loop through entry families building the addition nodes
1148 Ent := First_Entity (Concurrent_Type);
1149 Comp := First (Component_List);
1150 while Present (Ent) loop
1151 if Ekind (Ent) = E_Entry_Family then
1152 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1156 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1157 Hi := Type_High_Bound (Typ);
1158 Lo := Type_Low_Bound (Typ);
1159 Large := Is_Potentially_Large_Family
1160 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1163 Left_Opnd => Ecount,
1164 Right_Opnd => Family_Size
1165 (Loc, Hi, Lo, Concurrent_Type, Large));
1172 end Build_Entry_Count_Expression;
1174 -----------------------
1175 -- Build_Entry_Names --
1176 -----------------------
1178 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1179 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1185 Typ : Entity_Id := Conc_Typ;
1187 procedure Build_Entry_Family_Name (Id : Entity_Id);
1189 -- for Lnn in Family_Low .. Family_High loop
1192 -- (_init._object <or> _init._task_id,
1194 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1196 -- Note that the bounds of the range may reference discriminants. The
1197 -- above construct is added directly to the statements of the block.
1199 procedure Build_Entry_Name (Id : Entity_Id);
1203 -- (_init._object <or>_init._task_id,
1205 -- new String ("<Entry name>");
1206 -- The above construct is added directly to the statements of the block.
1208 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1209 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1210 -- _init._task_id or _init._object, Inn and Arg3.
1212 procedure Increment_Index (Stmts : List_Id);
1213 -- Generate the following and add it to Stmts
1216 -----------------------------
1217 -- Build_Entry_Family_Name --
1218 -----------------------------
1220 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1221 Def : constant Node_Id :=
1222 Discrete_Subtype_Definition (Parent (Id));
1223 L_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
1224 L_Stmts : constant List_Id := New_List;
1227 function Build_Range (Def : Node_Id) return Node_Id;
1228 -- Given a discrete subtype definition of an entry family, generate a
1229 -- range node which covers the range of Def's type.
1235 function Build_Range (Def : Node_Id) return Node_Id is
1236 High : Node_Id := Type_High_Bound (Etype (Def));
1237 Low : Node_Id := Type_Low_Bound (Etype (Def));
1240 -- If a bound references a discriminant, generate an identifier
1241 -- with the same name. Resolution will map it to the formals of
1244 if Is_Entity_Name (Low)
1245 and then Ekind (Entity (Low)) = E_Discriminant
1247 Low := Make_Identifier (Loc, Chars (Low));
1249 Low := New_Copy_Tree (Low);
1252 if Is_Entity_Name (High)
1253 and then Ekind (Entity (High)) = E_Discriminant
1255 High := Make_Identifier (Loc, Chars (High));
1257 High := New_Copy_Tree (High);
1263 High_Bound => High);
1266 -- Start of processing for Build_Entry_Family_Name
1269 Get_Name_String (Chars (Id));
1271 -- Add a leading '('
1273 Add_Char_To_Name_Buffer ('(');
1276 -- new String'("<Entry name>(" & Lnn'Img & ")");
1278 -- This is an implicit heap allocation, and Comes_From_Source is
1279 -- False, which ensures that it will get flagged as a violation of
1280 -- No_Implicit_Heap_Allocations when that restriction applies.
1283 Make_Allocator (Loc,
1284 Make_Qualified_Expression (Loc,
1286 New_Reference_To (Standard_String, Loc),
1288 Make_Op_Concat (Loc,
1290 Make_Op_Concat (Loc,
1292 Make_String_Literal (Loc,
1293 Strval => String_From_Name_Buffer),
1295 Make_Attribute_Reference (Loc,
1297 New_Reference_To (L_Id, Loc),
1298 Attribute_Name => Name_Img)),
1300 Make_String_Literal (Loc,
1303 Increment_Index (L_Stmts);
1304 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1307 -- for Lnn in Family_Low .. Family_High loop
1310 -- (_init._object <or> _init._task_id, Inn, <Val>);
1314 Make_Loop_Statement (Loc,
1316 Make_Iteration_Scheme (Loc,
1317 Loop_Parameter_Specification =>
1318 Make_Loop_Parameter_Specification (Loc,
1319 Defining_Identifier => L_Id,
1320 Discrete_Subtype_Definition => Build_Range (Def))),
1321 Statements => L_Stmts,
1322 End_Label => Empty));
1323 end Build_Entry_Family_Name;
1325 ----------------------
1326 -- Build_Entry_Name --
1327 ----------------------
1329 procedure Build_Entry_Name (Id : Entity_Id) is
1333 Get_Name_String (Chars (Id));
1335 -- This is an implicit heap allocation, and Comes_From_Source is
1336 -- False, which ensures that it will get flagged as a violation of
1337 -- No_Implicit_Heap_Allocations when that restriction applies.
1340 Make_Allocator (Loc,
1341 Make_Qualified_Expression (Loc,
1343 New_Reference_To (Standard_String, Loc),
1345 Make_String_Literal (Loc,
1346 String_From_Name_Buffer)));
1348 Increment_Index (B_Stmts);
1349 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1350 end Build_Entry_Name;
1352 -------------------------------
1353 -- Build_Set_Entry_Name_Call --
1354 -------------------------------
1356 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1361 -- Determine the proper name for the first argument and the RTS
1364 if Is_Protected_Type (Typ) then
1365 Arg1 := Name_uObject;
1366 Proc := RO_PE_Set_Entry_Name;
1368 else pragma Assert (Is_Task_Type (Typ));
1369 Arg1 := Name_uTask_Id;
1370 Proc := RO_TS_Set_Entry_Name;
1374 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1377 Make_Procedure_Call_Statement (Loc,
1379 New_Reference_To (RTE (Proc), Loc),
1380 Parameter_Associations => New_List (
1381 Make_Selected_Component (Loc, -- _init._object
1382 Prefix => -- _init._task_id
1383 Make_Identifier (Loc, Name_uInit),
1385 Make_Identifier (Loc, Arg1)),
1386 New_Reference_To (Index, Loc), -- Inn
1388 end Build_Set_Entry_Name_Call;
1390 ---------------------
1391 -- Increment_Index --
1392 ---------------------
1394 procedure Increment_Index (Stmts : List_Id) is
1400 Make_Assignment_Statement (Loc,
1402 New_Reference_To (Index, Loc),
1406 New_Reference_To (Index, Loc),
1408 Make_Integer_Literal (Loc, 1))));
1409 end Increment_Index;
1411 -- Start of processing for Build_Entry_Names
1414 -- Retrieve the original concurrent type
1416 if Is_Concurrent_Record_Type (Typ) then
1417 Typ := Corresponding_Concurrent_Type (Typ);
1420 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1422 -- Nothing to do if the type has no entries
1424 if not Has_Entries (Typ) then
1428 -- Avoid generating entry names for a protected type with only one entry
1430 if Is_Protected_Type (Typ)
1431 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1436 Index := Make_Temporary (Loc, 'I');
1438 -- Step 1: Generate the declaration of the index variable:
1439 -- Inn : Protected_Entry_Index := 0;
1441 -- Inn : Task_Entry_Index := 0;
1443 if Is_Protected_Type (Typ) then
1444 Index_Typ := RE_Protected_Entry_Index;
1446 Index_Typ := RE_Task_Entry_Index;
1449 B_Decls := New_List;
1451 Make_Object_Declaration (Loc,
1452 Defining_Identifier => Index,
1453 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1454 Expression => Make_Integer_Literal (Loc, 0)));
1456 B_Stmts := New_List;
1458 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1461 Comp := First_Entity (Typ);
1462 while Present (Comp) loop
1463 if Ekind (Comp) = E_Entry then
1464 Build_Entry_Name (Comp);
1466 elsif Ekind (Comp) = E_Entry_Family then
1467 Build_Entry_Family_Name (Comp);
1473 -- Step 3: Wrap the statements in a block
1476 Make_Block_Statement (Loc,
1477 Declarations => B_Decls,
1478 Handled_Statement_Sequence =>
1479 Make_Handled_Sequence_Of_Statements (Loc,
1480 Statements => B_Stmts));
1481 end Build_Entry_Names;
1483 ---------------------------
1484 -- Build_Parameter_Block --
1485 ---------------------------
1487 function Build_Parameter_Block
1491 Decls : List_Id) return Entity_Id
1497 Has_Comp : Boolean := False;
1501 Actual := First (Actuals);
1503 Formal := Defining_Identifier (First (Formals));
1505 while Present (Actual) loop
1506 if not Is_Controlling_Actual (Actual) then
1509 -- type Ann is access all <actual-type>
1511 Comp_Nam := Make_Temporary (Loc, 'A');
1514 Make_Full_Type_Declaration (Loc,
1515 Defining_Identifier => Comp_Nam,
1517 Make_Access_To_Object_Definition (Loc,
1518 All_Present => True,
1519 Constant_Present => Ekind (Formal) = E_In_Parameter,
1520 Subtype_Indication =>
1521 New_Reference_To (Etype (Actual), Loc))));
1527 Make_Component_Declaration (Loc,
1528 Defining_Identifier =>
1529 Make_Defining_Identifier (Loc, Chars (Formal)),
1530 Component_Definition =>
1531 Make_Component_Definition (Loc,
1534 Subtype_Indication =>
1535 New_Reference_To (Comp_Nam, Loc))));
1540 Next_Actual (Actual);
1541 Next_Formal_With_Extras (Formal);
1544 Rec_Nam := Make_Temporary (Loc, 'P');
1549 -- type Pnn is record
1554 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1555 -- the original parameter names and Ann1 .. AnnN are the access to
1559 Make_Full_Type_Declaration (Loc,
1560 Defining_Identifier =>
1563 Make_Record_Definition (Loc,
1565 Make_Component_List (Loc, Comps))));
1568 -- type Pnn is null record;
1571 Make_Full_Type_Declaration (Loc,
1572 Defining_Identifier =>
1575 Make_Record_Definition (Loc,
1576 Null_Present => True,
1577 Component_List => Empty)));
1581 end Build_Parameter_Block;
1583 --------------------------------------
1584 -- Build_Renamed_Formal_Declaration --
1585 --------------------------------------
1587 function Build_Renamed_Formal_Declaration
1591 Renamed_Formal : Node_Id) return Node_Id
1593 Loc : constant Source_Ptr := Sloc (New_F);
1597 -- If the formal is a tagged incomplete type, it is already passed
1598 -- by reference, so it is sufficient to rename the pointer component
1599 -- that corresponds to the actual. Otherwise we need to dereference
1600 -- the pointer component to obtain the actual.
1602 if Is_Incomplete_Type (Etype (Formal))
1603 and then Is_Tagged_Type (Etype (Formal))
1606 Make_Object_Renaming_Declaration (Loc,
1607 Defining_Identifier => New_F,
1608 Subtype_Mark => New_Reference_To (Etype (Comp), Loc),
1609 Name => Renamed_Formal);
1613 Make_Object_Renaming_Declaration (Loc,
1614 Defining_Identifier => New_F,
1615 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
1617 Make_Explicit_Dereference (Loc, Renamed_Formal));
1621 end Build_Renamed_Formal_Declaration;
1623 -----------------------
1624 -- Build_PPC_Wrapper --
1625 -----------------------
1627 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1628 Loc : constant Source_Ptr := Sloc (E);
1629 Synch_Type : constant Entity_Id := Scope (E);
1631 Wrapper_Id : constant Entity_Id :=
1632 Make_Defining_Identifier (Loc,
1633 Chars => New_External_Name (Chars (E), 'E'));
1634 -- the wrapper procedure name
1636 Wrapper_Body : Node_Id;
1638 Synch_Id : constant Entity_Id :=
1639 Make_Defining_Identifier (Loc,
1640 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1641 -- The parameter that designates the synchronized object in the call
1643 Actuals : constant List_Id := New_List;
1644 -- the actuals in the entry call.
1646 Decls : constant List_Id := New_List;
1648 Entry_Call : Node_Id;
1649 Entry_Name : Node_Id;
1652 -- The specification of the wrapper procedure
1656 -- Only build the wrapper if entry has pre/postconditions.
1657 -- Should this be done unconditionally instead ???
1663 P := Spec_PPC_List (Contract (E));
1668 -- Transfer ppc pragmas to the declarations of the wrapper
1670 while Present (P) loop
1671 if Pragma_Name (P) = Name_Precondition
1672 or else Pragma_Name (P) = Name_Postcondition
1674 Append (Relocate_Node (P), Decls);
1675 Set_Analyzed (Last (Decls), False);
1678 P := Next_Pragma (P);
1682 -- First formal is synchronized object
1685 Make_Parameter_Specification (Loc,
1686 Defining_Identifier => Synch_Id,
1687 Out_Present => True,
1689 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1692 Make_Selected_Component (Loc,
1693 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1694 Selector_Name => New_Occurrence_Of (E, Loc));
1696 -- If entity is entry family, second formal is the corresponding index,
1697 -- and entry name is an indexed component.
1699 if Ekind (E) = E_Entry_Family then
1701 Index : constant Entity_Id :=
1702 Make_Defining_Identifier (Loc, Name_I);
1705 Make_Parameter_Specification (Loc,
1706 Defining_Identifier => Index,
1708 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1711 Make_Indexed_Component (Loc,
1712 Prefix => Entry_Name,
1713 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
1718 Make_Procedure_Call_Statement (Loc,
1720 Parameter_Associations => Actuals);
1722 -- Now add formals that match those of the entry, and build actuals for
1723 -- the nested entry call.
1727 New_Form : Entity_Id;
1728 Parm_Spec : Node_Id;
1731 Form := First_Formal (E);
1732 while Present (Form) loop
1733 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
1735 Make_Parameter_Specification (Loc,
1736 Defining_Identifier => New_Form,
1737 Out_Present => Out_Present (Parent (Form)),
1738 In_Present => In_Present (Parent (Form)),
1739 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
1741 Append (Parm_Spec, Specs);
1742 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1747 -- Add renaming declarations for the discriminants of the enclosing
1748 -- type, which may be visible in the preconditions.
1750 if Has_Discriminants (Synch_Type) then
1756 D := First_Discriminant (Synch_Type);
1757 while Present (D) loop
1759 Make_Object_Renaming_Declaration (Loc,
1760 Defining_Identifier =>
1761 Make_Defining_Identifier (Loc, Chars (D)),
1762 Subtype_Mark => New_Reference_To (Etype (D), Loc),
1764 Make_Selected_Component (Loc,
1765 Prefix => New_Reference_To (Synch_Id, Loc),
1766 Selector_Name => Make_Identifier (Loc, Chars (D))));
1767 Prepend (Decl, Decls);
1768 Next_Discriminant (D);
1773 Set_PPC_Wrapper (E, Wrapper_Id);
1775 Make_Subprogram_Body (Loc,
1777 Make_Procedure_Specification (Loc,
1778 Defining_Unit_Name => Wrapper_Id,
1779 Parameter_Specifications => Specs),
1780 Declarations => Decls,
1781 Handled_Statement_Sequence =>
1782 Make_Handled_Sequence_Of_Statements (Loc,
1783 Statements => New_List (Entry_Call)));
1785 -- The wrapper body is analyzed when the enclosing type is frozen
1787 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1788 end Build_PPC_Wrapper;
1790 --------------------------
1791 -- Build_Wrapper_Bodies --
1792 --------------------------
1794 procedure Build_Wrapper_Bodies
1799 Rec_Typ : Entity_Id;
1801 function Build_Wrapper_Body
1803 Subp_Id : Entity_Id;
1804 Obj_Typ : Entity_Id;
1805 Formals : List_Id) return Node_Id;
1806 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1807 -- associated with a protected or task type. Subp_Id is the subprogram
1808 -- name which will be wrapped. Obj_Typ is the type of the new formal
1809 -- parameter which handles dispatching and object notation. Formals are
1810 -- the original formals of Subp_Id which will be explicitly replicated.
1812 ------------------------
1813 -- Build_Wrapper_Body --
1814 ------------------------
1816 function Build_Wrapper_Body
1818 Subp_Id : Entity_Id;
1819 Obj_Typ : Entity_Id;
1820 Formals : List_Id) return Node_Id
1822 Body_Spec : Node_Id;
1825 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1827 -- The subprogram is not overriding or is not a primitive declared
1828 -- between two views.
1830 if No (Body_Spec) then
1835 Actuals : List_Id := No_List;
1837 First_Form : Node_Id;
1842 -- Map formals to actuals. Use the list built for the wrapper
1843 -- spec, skipping the object notation parameter.
1845 First_Form := First (Parameter_Specifications (Body_Spec));
1847 Formal := First_Form;
1850 if Present (Formal) then
1851 Actuals := New_List;
1852 while Present (Formal) loop
1854 Make_Identifier (Loc,
1855 Chars => Chars (Defining_Identifier (Formal))));
1860 -- Special processing for primitives declared between a private
1861 -- type and its completion: the wrapper needs a properly typed
1862 -- parameter if the wrapped operation has a controlling first
1863 -- parameter. Note that this might not be the case for a function
1864 -- with a controlling result.
1866 if Is_Private_Primitive_Subprogram (Subp_Id) then
1867 if No (Actuals) then
1868 Actuals := New_List;
1871 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1872 Prepend_To (Actuals,
1873 Unchecked_Convert_To
1874 (Corresponding_Concurrent_Type (Obj_Typ),
1875 Make_Identifier (Loc, Name_uO)));
1878 Prepend_To (Actuals,
1879 Make_Identifier (Loc,
1880 Chars => Chars (Defining_Identifier (First_Form))));
1883 Nam := New_Reference_To (Subp_Id, Loc);
1885 -- An access-to-variable object parameter requires an explicit
1886 -- dereference in the unchecked conversion. This case occurs
1887 -- when a protected entry wrapper must override an interface
1888 -- level procedure with interface access as first parameter.
1890 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1892 if Nkind (Parameter_Type (First_Form)) =
1896 Make_Explicit_Dereference (Loc,
1897 Prefix => Make_Identifier (Loc, Name_uO));
1899 Conv_Id := Make_Identifier (Loc, Name_uO);
1903 Make_Selected_Component (Loc,
1905 Unchecked_Convert_To
1906 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
1907 Selector_Name => New_Reference_To (Subp_Id, Loc));
1910 -- Create the subprogram body. For a function, the call to the
1911 -- actual subprogram has to be converted to the corresponding
1912 -- record if it is a controlling result.
1914 if Ekind (Subp_Id) = E_Function then
1920 Make_Function_Call (Loc,
1922 Parameter_Associations => Actuals);
1924 if Has_Controlling_Result (Subp_Id) then
1926 Unchecked_Convert_To
1927 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1931 Make_Subprogram_Body (Loc,
1932 Specification => Body_Spec,
1933 Declarations => Empty_List,
1934 Handled_Statement_Sequence =>
1935 Make_Handled_Sequence_Of_Statements (Loc,
1936 Statements => New_List (
1937 Make_Simple_Return_Statement (Loc, Res))));
1942 Make_Subprogram_Body (Loc,
1943 Specification => Body_Spec,
1944 Declarations => Empty_List,
1945 Handled_Statement_Sequence =>
1946 Make_Handled_Sequence_Of_Statements (Loc,
1947 Statements => New_List (
1948 Make_Procedure_Call_Statement (Loc,
1950 Parameter_Associations => Actuals))));
1953 end Build_Wrapper_Body;
1955 -- Start of processing for Build_Wrapper_Bodies
1958 if Is_Concurrent_Type (Typ) then
1959 Rec_Typ := Corresponding_Record_Type (Typ);
1964 -- Generate wrapper bodies for a concurrent type which implements an
1967 if Present (Interfaces (Rec_Typ)) then
1969 Insert_Nod : Node_Id;
1971 Prim_Elmt : Elmt_Id;
1972 Prim_Decl : Node_Id;
1974 Wrap_Body : Node_Id;
1975 Wrap_Id : Entity_Id;
1980 -- Examine all primitive operations of the corresponding record
1981 -- type, looking for wrapper specs. Generate bodies in order to
1984 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1985 while Present (Prim_Elmt) loop
1986 Prim := Node (Prim_Elmt);
1988 if (Ekind (Prim) = E_Function
1989 or else Ekind (Prim) = E_Procedure)
1990 and then Is_Primitive_Wrapper (Prim)
1992 Subp := Wrapped_Entity (Prim);
1993 Prim_Decl := Parent (Parent (Prim));
1996 Build_Wrapper_Body (Loc,
1999 Formals => Parameter_Specifications (Parent (Subp)));
2000 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2002 Set_Corresponding_Spec (Wrap_Body, Prim);
2003 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2005 Insert_After (Insert_Nod, Wrap_Body);
2006 Insert_Nod := Wrap_Body;
2008 Analyze (Wrap_Body);
2011 Next_Elmt (Prim_Elmt);
2015 end Build_Wrapper_Bodies;
2017 ------------------------
2018 -- Build_Wrapper_Spec --
2019 ------------------------
2021 function Build_Wrapper_Spec
2022 (Subp_Id : Entity_Id;
2023 Obj_Typ : Entity_Id;
2024 Formals : List_Id) return Node_Id
2026 Loc : constant Source_Ptr := Sloc (Subp_Id);
2027 First_Param : Node_Id;
2029 Iface_Elmt : Elmt_Id;
2030 Iface_Op : Entity_Id;
2031 Iface_Op_Elmt : Elmt_Id;
2033 function Overriding_Possible
2034 (Iface_Op : Entity_Id;
2035 Wrapper : Entity_Id) return Boolean;
2036 -- Determine whether a primitive operation can be overridden by Wrapper.
2037 -- Iface_Op is the candidate primitive operation of an interface type,
2038 -- Wrapper is the generated entry wrapper.
2040 function Replicate_Formals
2042 Formals : List_Id) return List_Id;
2043 -- An explicit parameter replication is required due to the Is_Entry_
2044 -- Formal flag being set for all the formals of an entry. The explicit
2045 -- replication removes the flag that would otherwise cause a different
2046 -- path of analysis.
2048 -------------------------
2049 -- Overriding_Possible --
2050 -------------------------
2052 function Overriding_Possible
2053 (Iface_Op : Entity_Id;
2054 Wrapper : Entity_Id) return Boolean
2056 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2057 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2059 function Type_Conformant_Parameters
2060 (Iface_Op_Params : List_Id;
2061 Wrapper_Params : List_Id) return Boolean;
2062 -- Determine whether the parameters of the generated entry wrapper
2063 -- and those of a primitive operation are type conformant. During
2064 -- this check, the first parameter of the primitive operation is
2065 -- skipped if it is a controlling argument: protected functions
2066 -- may have a controlling result.
2068 --------------------------------
2069 -- Type_Conformant_Parameters --
2070 --------------------------------
2072 function Type_Conformant_Parameters
2073 (Iface_Op_Params : List_Id;
2074 Wrapper_Params : List_Id) return Boolean
2076 Iface_Op_Param : Node_Id;
2077 Iface_Op_Typ : Entity_Id;
2078 Wrapper_Param : Node_Id;
2079 Wrapper_Typ : Entity_Id;
2082 -- Skip the first (controlling) parameter of primitive operation
2084 Iface_Op_Param := First (Iface_Op_Params);
2086 if Present (First_Formal (Iface_Op))
2087 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2089 Iface_Op_Param := Next (Iface_Op_Param);
2092 Wrapper_Param := First (Wrapper_Params);
2093 while Present (Iface_Op_Param)
2094 and then Present (Wrapper_Param)
2096 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2097 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2099 -- The two parameters must be mode conformant
2101 if not Conforming_Types
2102 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2107 Next (Iface_Op_Param);
2108 Next (Wrapper_Param);
2111 -- One of the lists is longer than the other
2113 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2118 end Type_Conformant_Parameters;
2120 -- Start of processing for Overriding_Possible
2123 if Chars (Iface_Op) /= Chars (Wrapper) then
2127 -- If an inherited subprogram is implemented by a protected procedure
2128 -- or an entry, then the first parameter of the inherited subprogram
2129 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2131 if Ekind (Iface_Op) = E_Procedure
2132 and then Present (Parameter_Specifications (Iface_Op_Spec))
2135 Obj_Param : constant Node_Id :=
2136 First (Parameter_Specifications (Iface_Op_Spec));
2138 if not Out_Present (Obj_Param)
2139 and then Nkind (Parameter_Type (Obj_Param)) /=
2148 Type_Conformant_Parameters (
2149 Parameter_Specifications (Iface_Op_Spec),
2150 Parameter_Specifications (Wrapper_Spec));
2151 end Overriding_Possible;
2153 -----------------------
2154 -- Replicate_Formals --
2155 -----------------------
2157 function Replicate_Formals
2159 Formals : List_Id) return List_Id
2161 New_Formals : constant List_Id := New_List;
2163 Param_Type : Node_Id;
2166 Formal := First (Formals);
2168 -- Skip the object parameter when dealing with primitives declared
2169 -- between two views.
2171 if Is_Private_Primitive_Subprogram (Subp_Id)
2172 and then not Has_Controlling_Result (Subp_Id)
2174 Formal := Next (Formal);
2177 while Present (Formal) loop
2179 -- Create an explicit copy of the entry parameter
2181 -- When creating the wrapper subprogram for a primitive operation
2182 -- of a protected interface we must construct an equivalent
2183 -- signature to that of the overriding operation. For regular
2184 -- parameters we can just use the type of the formal, but for
2185 -- access to subprogram parameters we need to reanalyze the
2186 -- parameter type to create local entities for the signature of
2187 -- the subprogram type. Using the entities of the overriding
2188 -- subprogram will result in out-of-scope errors in the back-end.
2190 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2191 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2194 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
2197 Append_To (New_Formals,
2198 Make_Parameter_Specification (Loc,
2199 Defining_Identifier =>
2200 Make_Defining_Identifier (Loc,
2201 Chars => Chars (Defining_Identifier (Formal))),
2202 In_Present => In_Present (Formal),
2203 Out_Present => Out_Present (Formal),
2204 Parameter_Type => Param_Type));
2210 end Replicate_Formals;
2212 -- Start of processing for Build_Wrapper_Spec
2215 -- There is no point in building wrappers for non-tagged concurrent
2218 pragma Assert (Is_Tagged_Type (Obj_Typ));
2220 -- An entry or a protected procedure can override a routine where the
2221 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2222 -- type. Since the wrapper must have the exact same signature as that of
2223 -- the overridden subprogram, we try to find the overriding candidate
2224 -- and use its controlling formal.
2226 First_Param := Empty;
2228 -- Check every implemented interface
2230 if Present (Interfaces (Obj_Typ)) then
2231 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2232 Search : while Present (Iface_Elmt) loop
2233 Iface := Node (Iface_Elmt);
2235 -- Check every interface primitive
2237 if Present (Primitive_Operations (Iface)) then
2238 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2239 while Present (Iface_Op_Elmt) loop
2240 Iface_Op := Node (Iface_Op_Elmt);
2242 -- Ignore predefined primitives
2244 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2245 Iface_Op := Ultimate_Alias (Iface_Op);
2247 -- The current primitive operation can be overridden by
2248 -- the generated entry wrapper.
2250 if Overriding_Possible (Iface_Op, Subp_Id) then
2252 First (Parameter_Specifications (Parent (Iface_Op)));
2258 Next_Elmt (Iface_Op_Elmt);
2262 Next_Elmt (Iface_Elmt);
2266 -- If the subprogram to be wrapped is not overriding anything or is not
2267 -- a primitive declared between two views, do not produce anything. This
2268 -- avoids spurious errors involving overriding.
2271 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2277 Wrapper_Id : constant Entity_Id :=
2278 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2279 New_Formals : List_Id;
2280 Obj_Param : Node_Id;
2281 Obj_Param_Typ : Entity_Id;
2284 -- Minimum decoration is needed to catch the entity in
2285 -- Sem_Ch6.Override_Dispatching_Operation.
2287 if Ekind (Subp_Id) = E_Function then
2288 Set_Ekind (Wrapper_Id, E_Function);
2290 Set_Ekind (Wrapper_Id, E_Procedure);
2293 Set_Is_Primitive_Wrapper (Wrapper_Id);
2294 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2295 Set_Is_Private_Primitive (Wrapper_Id,
2296 Is_Private_Primitive_Subprogram (Subp_Id));
2298 -- Process the formals
2300 New_Formals := Replicate_Formals (Loc, Formals);
2302 -- A function with a controlling result and no first controlling
2303 -- formal needs no additional parameter.
2305 if Has_Controlling_Result (Subp_Id)
2307 (No (First_Formal (Subp_Id))
2308 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2312 -- Routine Subp_Id has been found to override an interface primitive.
2313 -- If the interface operation has an access parameter, create a copy
2314 -- of it, with the same null exclusion indicator if present.
2316 elsif Present (First_Param) then
2317 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2319 Make_Access_Definition (Loc,
2321 New_Reference_To (Obj_Typ, Loc));
2322 Set_Null_Exclusion_Present (Obj_Param_Typ,
2323 Null_Exclusion_Present (Parameter_Type (First_Param)));
2326 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2330 Make_Parameter_Specification (Loc,
2331 Defining_Identifier =>
2332 Make_Defining_Identifier (Loc,
2334 In_Present => In_Present (First_Param),
2335 Out_Present => Out_Present (First_Param),
2336 Parameter_Type => Obj_Param_Typ);
2338 Prepend_To (New_Formals, Obj_Param);
2340 -- If we are dealing with a primitive declared between two views,
2341 -- implemented by a synchronized operation, we need to create
2342 -- a default parameter. The mode of the parameter must match that
2343 -- of the primitive operation.
2346 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2348 Make_Parameter_Specification (Loc,
2349 Defining_Identifier =>
2350 Make_Defining_Identifier (Loc, Name_uO),
2351 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2352 Out_Present => Ekind (Subp_Id) /= E_Function,
2353 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2354 Prepend_To (New_Formals, Obj_Param);
2357 -- Build the final spec. If it is a function with a controlling
2358 -- result, it is a primitive operation of the corresponding
2359 -- record type, so mark the spec accordingly.
2361 if Ekind (Subp_Id) = E_Function then
2366 if Has_Controlling_Result (Subp_Id) then
2369 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2371 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2375 Make_Function_Specification (Loc,
2376 Defining_Unit_Name => Wrapper_Id,
2377 Parameter_Specifications => New_Formals,
2378 Result_Definition => Res_Def);
2382 Make_Procedure_Specification (Loc,
2383 Defining_Unit_Name => Wrapper_Id,
2384 Parameter_Specifications => New_Formals);
2387 end Build_Wrapper_Spec;
2389 -------------------------
2390 -- Build_Wrapper_Specs --
2391 -------------------------
2393 procedure Build_Wrapper_Specs
2399 Rec_Typ : Entity_Id;
2400 procedure Scan_Declarations (L : List_Id);
2401 -- Common processing for visible and private declarations
2402 -- of a protected type.
2404 procedure Scan_Declarations (L : List_Id) is
2406 Wrap_Decl : Node_Id;
2407 Wrap_Spec : Node_Id;
2415 while Present (Decl) loop
2418 if Nkind (Decl) = N_Entry_Declaration
2419 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2423 (Subp_Id => Defining_Identifier (Decl),
2425 Formals => Parameter_Specifications (Decl));
2427 elsif Nkind (Decl) = N_Subprogram_Declaration then
2430 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2433 Parameter_Specifications (Specification (Decl)));
2436 if Present (Wrap_Spec) then
2438 Make_Subprogram_Declaration (Loc,
2439 Specification => Wrap_Spec);
2441 Insert_After (N, Wrap_Decl);
2444 Analyze (Wrap_Decl);
2449 end Scan_Declarations;
2451 -- start of processing for Build_Wrapper_Specs
2454 if Is_Protected_Type (Typ) then
2455 Def := Protected_Definition (Parent (Typ));
2456 else pragma Assert (Is_Task_Type (Typ));
2457 Def := Task_Definition (Parent (Typ));
2460 Rec_Typ := Corresponding_Record_Type (Typ);
2462 -- Generate wrapper specs for a concurrent type which implements an
2463 -- interface. Operations in both the visible and private parts may
2464 -- implement progenitor operations.
2466 if Present (Interfaces (Rec_Typ))
2467 and then Present (Def)
2469 Scan_Declarations (Visible_Declarations (Def));
2470 Scan_Declarations (Private_Declarations (Def));
2472 end Build_Wrapper_Specs;
2474 ---------------------------
2475 -- Build_Find_Body_Index --
2476 ---------------------------
2478 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2479 Loc : constant Source_Ptr := Sloc (Typ);
2482 Has_F : Boolean := False;
2484 If_St : Node_Id := Empty;
2487 Decls : List_Id := New_List;
2490 Siz : Node_Id := Empty;
2492 procedure Add_If_Clause (Expr : Node_Id);
2493 -- Add test for range of current entry
2495 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2496 -- If a bound of an entry is given by a discriminant, retrieve the
2497 -- actual value of the discriminant from the enclosing object.
2503 procedure Add_If_Clause (Expr : Node_Id) is
2505 Stats : constant List_Id :=
2507 Make_Simple_Return_Statement (Loc,
2508 Expression => Make_Integer_Literal (Loc, Index + 1)));
2511 -- Index for current entry body
2515 -- Compute total length of entry queues so far
2523 Right_Opnd => Expr);
2528 Left_Opnd => Make_Identifier (Loc, Name_uE),
2531 -- Map entry queue indexes in the range of the current family
2532 -- into the current index, that designates the entry body.
2536 Make_Implicit_If_Statement (Typ,
2538 Then_Statements => Stats,
2539 Elsif_Parts => New_List);
2545 Make_Elsif_Part (Loc,
2547 Then_Statements => Stats),
2548 Elsif_Parts (If_St));
2552 ------------------------------
2553 -- Convert_Discriminant_Ref --
2554 ------------------------------
2556 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2560 if Is_Entity_Name (Bound)
2561 and then Ekind (Entity (Bound)) = E_Discriminant
2564 Make_Selected_Component (Loc,
2566 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2567 Make_Explicit_Dereference (Loc,
2568 Make_Identifier (Loc, Name_uObject))),
2569 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2570 Set_Etype (B, Etype (Entity (Bound)));
2572 B := New_Copy_Tree (Bound);
2576 end Convert_Discriminant_Ref;
2578 -- Start of processing for Build_Find_Body_Index
2581 Spec := Build_Find_Body_Index_Spec (Typ);
2583 Ent := First_Entity (Typ);
2584 while Present (Ent) loop
2585 if Ekind (Ent) = E_Entry_Family then
2595 -- If the protected type has no entry families, there is a one-one
2596 -- correspondence between entry queue and entry body.
2599 Make_Simple_Return_Statement (Loc,
2600 Expression => Make_Identifier (Loc, Name_uE));
2603 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2606 -- if E <= l1 then return 1;
2607 -- elsif E <= l1 + l2 then return 2;
2612 Ent := First_Entity (Typ);
2614 Add_Object_Pointer (Loc, Typ, Decls);
2616 while Present (Ent) loop
2617 if Ekind (Ent) = E_Entry then
2618 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2620 elsif Ekind (Ent) = E_Entry_Family then
2621 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2622 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2623 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2624 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2633 Make_Simple_Return_Statement (Loc,
2634 Expression => Make_Integer_Literal (Loc, 1));
2636 elsif Nkind (Ret) = N_If_Statement then
2638 -- Ranges are in increasing order, so last one doesn't need guard
2641 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2644 Set_Else_Statements (Ret, Then_Statements (Nod));
2650 Make_Subprogram_Body (Loc,
2651 Specification => Spec,
2652 Declarations => Decls,
2653 Handled_Statement_Sequence =>
2654 Make_Handled_Sequence_Of_Statements (Loc,
2655 Statements => New_List (Ret)));
2656 end Build_Find_Body_Index;
2658 --------------------------------
2659 -- Build_Find_Body_Index_Spec --
2660 --------------------------------
2662 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2663 Loc : constant Source_Ptr := Sloc (Typ);
2664 Id : constant Entity_Id :=
2665 Make_Defining_Identifier (Loc,
2666 Chars => New_External_Name (Chars (Typ), 'F'));
2667 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2668 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2672 Make_Function_Specification (Loc,
2673 Defining_Unit_Name => Id,
2674 Parameter_Specifications => New_List (
2675 Make_Parameter_Specification (Loc,
2676 Defining_Identifier => Parm1,
2678 New_Reference_To (RTE (RE_Address), Loc)),
2680 Make_Parameter_Specification (Loc,
2681 Defining_Identifier => Parm2,
2683 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2684 Result_Definition => New_Occurrence_Of (
2685 RTE (RE_Protected_Entry_Index), Loc));
2686 end Build_Find_Body_Index_Spec;
2688 -------------------------
2689 -- Build_Master_Entity --
2690 -------------------------
2692 procedure Build_Master_Entity (E : Entity_Id) is
2693 Loc : constant Source_Ptr := Sloc (E);
2699 S := Find_Master_Scope (E);
2701 -- Nothing to do if we already built a master entity for this scope
2702 -- or if there is no task hierarchy.
2704 if Has_Master_Entity (S)
2705 or else Restriction_Active (No_Task_Hierarchy)
2710 -- Otherwise first build the master entity
2711 -- _Master : constant Master_Id := Current_Master.all;
2712 -- and insert it just before the current declaration
2715 Make_Object_Declaration (Loc,
2716 Defining_Identifier =>
2717 Make_Defining_Identifier (Loc, Name_uMaster),
2718 Constant_Present => True,
2719 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2721 Make_Explicit_Dereference (Loc,
2722 New_Reference_To (RTE (RE_Current_Master), Loc)));
2725 Insert_Before (P, Decl);
2728 Set_Has_Master_Entity (S);
2730 -- Now mark the containing scope as a task master
2732 while Nkind (P) /= N_Compilation_Unit loop
2735 -- If we fall off the top, we are at the outer level, and the
2736 -- environment task is our effective master, so nothing to mark.
2739 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2741 Set_Is_Task_Master (P, True);
2744 elsif Nkind (Parent (P)) = N_Subunit then
2745 P := Corresponding_Stub (Parent (P));
2748 end Build_Master_Entity;
2750 -----------------------------------------
2751 -- Build_Private_Protected_Declaration --
2752 -----------------------------------------
2754 function Build_Private_Protected_Declaration
2755 (N : Node_Id) return Entity_Id
2757 Loc : constant Source_Ptr := Sloc (N);
2758 Body_Id : constant Entity_Id := Defining_Entity (N);
2763 Spec_Id : Entity_Id;
2766 Formal := First_Formal (Body_Id);
2768 -- The protected operation always has at least one formal, namely the
2769 -- object itself, but it is only placed in the parameter list if
2770 -- expansion is enabled.
2772 if Present (Formal) or else Expander_Active then
2773 Plist := Copy_Parameter_List (Body_Id);
2778 if Nkind (Specification (N)) = N_Procedure_Specification then
2780 Make_Procedure_Specification (Loc,
2781 Defining_Unit_Name =>
2782 Make_Defining_Identifier (Sloc (Body_Id),
2783 Chars => Chars (Body_Id)),
2784 Parameter_Specifications =>
2788 Make_Function_Specification (Loc,
2789 Defining_Unit_Name =>
2790 Make_Defining_Identifier (Sloc (Body_Id),
2791 Chars => Chars (Body_Id)),
2792 Parameter_Specifications => Plist,
2793 Result_Definition =>
2794 New_Occurrence_Of (Etype (Body_Id), Loc));
2797 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2798 Insert_Before (N, Decl);
2799 Spec_Id := Defining_Unit_Name (New_Spec);
2801 -- Indicate that the entity comes from source, to ensure that cross-
2802 -- reference information is properly generated. The body itself is
2803 -- rewritten during expansion, and the body entity will not appear in
2804 -- calls to the operation.
2806 Set_Comes_From_Source (Spec_Id, True);
2808 Set_Has_Completion (Spec_Id);
2809 Set_Convention (Spec_Id, Convention_Protected);
2811 end Build_Private_Protected_Declaration;
2813 ---------------------------
2814 -- Build_Protected_Entry --
2815 ---------------------------
2817 function Build_Protected_Entry
2820 Pid : Node_Id) return Node_Id
2822 Loc : constant Source_Ptr := Sloc (N);
2824 Decls : constant List_Id := Declarations (N);
2825 End_Lab : constant Node_Id :=
2826 End_Label (Handled_Statement_Sequence (N));
2827 End_Loc : constant Source_Ptr :=
2828 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2829 -- Used for the generated call to Complete_Entry_Body
2831 Han_Loc : Source_Ptr;
2832 -- Used for the exception handler, inserted at end of the body
2834 Op_Decls : constant List_Id := New_List;
2842 -- Set the source location on the exception handler only when debugging
2843 -- the expanded code (see Make_Implicit_Exception_Handler).
2845 if Debug_Generated_Code then
2848 -- Otherwise the inserted code should not be visible to the debugger
2851 Han_Loc := No_Location;
2855 Make_Defining_Identifier (Loc,
2856 Chars => Chars (Protected_Body_Subprogram (Ent)));
2858 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2860 -- Add the following declarations:
2861 -- type poVP is access poV;
2862 -- _object : poVP := poVP (_O);
2864 -- where _O is the formal parameter associated with the concurrent
2865 -- object. These declarations are needed for Complete_Entry_Body.
2867 Add_Object_Pointer (Loc, Pid, Op_Decls);
2869 -- Add renamings for all formals, the Protection object, discriminals,
2870 -- privals and the entry index constant for use by debugger.
2872 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2873 Debug_Private_Data_Declarations (Decls);
2875 case Corresponding_Runtime_Package (Pid) is
2876 when System_Tasking_Protected_Objects_Entries =>
2878 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2880 when System_Tasking_Protected_Objects_Single_Entry =>
2882 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2885 raise Program_Error;
2888 Op_Stats := New_List (
2889 Make_Block_Statement (Loc,
2890 Declarations => Decls,
2891 Handled_Statement_Sequence =>
2892 Handled_Statement_Sequence (N)),
2894 Make_Procedure_Call_Statement (End_Loc,
2896 Parameter_Associations => New_List (
2897 Make_Attribute_Reference (End_Loc,
2899 Make_Selected_Component (End_Loc,
2900 Prefix => Make_Identifier (End_Loc, Name_uObject),
2901 Selector_Name => Make_Identifier (End_Loc, Name_uObject)),
2902 Attribute_Name => Name_Unchecked_Access))));
2904 -- When exceptions can not be propagated, we never need to call
2905 -- Exception_Complete_Entry_Body
2907 if No_Exception_Handlers_Set then
2909 Make_Subprogram_Body (Loc,
2910 Specification => Espec,
2911 Declarations => Op_Decls,
2912 Handled_Statement_Sequence =>
2913 Make_Handled_Sequence_Of_Statements (Loc,
2914 Statements => Op_Stats,
2915 End_Label => End_Lab));
2918 Ohandle := Make_Others_Choice (Loc);
2919 Set_All_Others (Ohandle);
2921 case Corresponding_Runtime_Package (Pid) is
2922 when System_Tasking_Protected_Objects_Entries =>
2925 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2927 when System_Tasking_Protected_Objects_Single_Entry =>
2930 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2933 raise Program_Error;
2936 -- Establish link between subprogram body entity and source entry.
2938 Set_Corresponding_Protected_Entry (Edef, Ent);
2940 -- Create body of entry procedure. The renaming declarations are
2941 -- placed ahead of the block that contains the actual entry body.
2944 Make_Subprogram_Body (Loc,
2945 Specification => Espec,
2946 Declarations => Op_Decls,
2947 Handled_Statement_Sequence =>
2948 Make_Handled_Sequence_Of_Statements (Loc,
2949 Statements => Op_Stats,
2950 End_Label => End_Lab,
2951 Exception_Handlers => New_List (
2952 Make_Implicit_Exception_Handler (Han_Loc,
2953 Exception_Choices => New_List (Ohandle),
2955 Statements => New_List (
2956 Make_Procedure_Call_Statement (Han_Loc,
2958 Parameter_Associations => New_List (
2959 Make_Attribute_Reference (Han_Loc,
2961 Make_Selected_Component (Han_Loc,
2963 Make_Identifier (Han_Loc, Name_uObject),
2965 Make_Identifier (Han_Loc, Name_uObject)),
2966 Attribute_Name => Name_Unchecked_Access),
2968 Make_Function_Call (Han_Loc,
2969 Name => New_Reference_To (
2970 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2972 end Build_Protected_Entry;
2974 -----------------------------------------
2975 -- Build_Protected_Entry_Specification --
2976 -----------------------------------------
2978 function Build_Protected_Entry_Specification
2981 Ent_Id : Entity_Id) return Node_Id
2983 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2986 Set_Debug_Info_Needed (Def_Id);
2988 if Present (Ent_Id) then
2989 Append_Elmt (P, Accept_Address (Ent_Id));
2993 Make_Procedure_Specification (Loc,
2994 Defining_Unit_Name => Def_Id,
2995 Parameter_Specifications => New_List (
2996 Make_Parameter_Specification (Loc,
2997 Defining_Identifier =>
2998 Make_Defining_Identifier (Loc, Name_uO),
3000 New_Reference_To (RTE (RE_Address), Loc)),
3002 Make_Parameter_Specification (Loc,
3003 Defining_Identifier => P,
3005 New_Reference_To (RTE (RE_Address), Loc)),
3007 Make_Parameter_Specification (Loc,
3008 Defining_Identifier =>
3009 Make_Defining_Identifier (Loc, Name_uE),
3011 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
3012 end Build_Protected_Entry_Specification;
3014 --------------------------
3015 -- Build_Protected_Spec --
3016 --------------------------
3018 function Build_Protected_Spec
3020 Obj_Type : Entity_Id;
3022 Unprotected : Boolean := False) return List_Id
3024 Loc : constant Source_Ptr := Sloc (N);
3027 New_Plist : List_Id;
3028 New_Param : Node_Id;
3031 New_Plist := New_List;
3033 Formal := First_Formal (Ident);
3034 while Present (Formal) loop
3036 Make_Parameter_Specification (Loc,
3037 Defining_Identifier =>
3038 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
3039 In_Present => In_Present (Parent (Formal)),
3040 Out_Present => Out_Present (Parent (Formal)),
3041 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
3044 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3047 Append (New_Param, New_Plist);
3048 Next_Formal (Formal);
3051 -- If the subprogram is a procedure and the context is not an access
3052 -- to protected subprogram, the parameter is in-out. Otherwise it is
3056 Make_Parameter_Specification (Loc,
3057 Defining_Identifier =>
3058 Make_Defining_Identifier (Loc, Name_uObject),
3061 (Etype (Ident) = Standard_Void_Type
3062 and then not Is_RTE (Obj_Type, RE_Address)),
3064 New_Reference_To (Obj_Type, Loc));
3065 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3066 Prepend_To (New_Plist, Decl);
3069 end Build_Protected_Spec;
3071 ---------------------------------------
3072 -- Build_Protected_Sub_Specification --
3073 ---------------------------------------
3075 function Build_Protected_Sub_Specification
3077 Prot_Typ : Entity_Id;
3078 Mode : Subprogram_Protection_Mode) return Node_Id
3080 Loc : constant Source_Ptr := Sloc (N);
3084 New_Plist : List_Id;
3087 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3088 (Dispatching_Mode => ' ',
3089 Protected_Mode => 'P',
3090 Unprotected_Mode => 'N');
3093 if Ekind (Defining_Unit_Name (Specification (N))) =
3096 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3101 Def_Id := Defining_Unit_Name (Specification (Decl));
3104 Build_Protected_Spec
3105 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3106 Mode = Unprotected_Mode);
3108 Make_Defining_Identifier (Loc,
3109 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3111 -- The unprotected operation carries the user code, and debugging
3112 -- information must be generated for it, even though this spec does
3113 -- not come from source. It is also convenient to allow gdb to step
3114 -- into the protected operation, even though it only contains lock/
3117 Set_Debug_Info_Needed (New_Id);
3119 -- If a pragma Eliminate applies to the source entity, the internal
3120 -- subprograms will be eliminated as well.
3122 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3124 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3126 Make_Procedure_Specification (Loc,
3127 Defining_Unit_Name => New_Id,
3128 Parameter_Specifications => New_Plist);
3130 -- Create a new specification for the anonymous subprogram type
3134 Make_Function_Specification (Loc,
3135 Defining_Unit_Name => New_Id,
3136 Parameter_Specifications => New_Plist,
3137 Result_Definition =>
3138 Copy_Result_Type (Result_Definition (Specification (Decl))));
3140 Set_Return_Present (Defining_Unit_Name (New_Spec));
3144 end Build_Protected_Sub_Specification;
3146 -------------------------------------
3147 -- Build_Protected_Subprogram_Body --
3148 -------------------------------------
3150 function Build_Protected_Subprogram_Body
3153 N_Op_Spec : Node_Id) return Node_Id
3155 Loc : constant Source_Ptr := Sloc (N);
3157 P_Op_Spec : Node_Id;
3160 Unprot_Call : Node_Id;
3162 Lock_Name : Node_Id;
3163 Lock_Stmt : Node_Id;
3164 Service_Name : Node_Id;
3166 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3167 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3169 Object_Parm : Node_Id;
3172 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3173 -- Tell whether a given subprogram cannot raise an exception
3175 -----------------------
3176 -- Is_Exception_Safe --
3177 -----------------------
3179 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3181 function Has_Side_Effect (N : Node_Id) return Boolean;
3182 -- Return True whenever encountering a subprogram call or raise
3183 -- statement of any kind in the sequence of statements
3185 ---------------------
3186 -- Has_Side_Effect --
3187 ---------------------
3189 -- What is this doing buried two levels down in exp_ch9. It seems
3190 -- like a generally useful function, and indeed there may be code
3191 -- duplication going on here ???
3193 function Has_Side_Effect (N : Node_Id) return Boolean is
3197 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3198 -- Indicate whether N is a subprogram call or a raise statement
3200 ----------------------
3201 -- Is_Call_Or_Raise --
3202 ----------------------
3204 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3206 return Nkind_In (N, N_Procedure_Call_Statement,
3209 N_Raise_Constraint_Error,
3210 N_Raise_Program_Error,
3211 N_Raise_Storage_Error);
3212 end Is_Call_Or_Raise;
3214 -- Start of processing for Has_Side_Effect
3218 while Present (Stmt) loop
3219 if Is_Call_Or_Raise (Stmt) then
3223 -- An object declaration can also contain a function call
3224 -- or a raise statement
3226 if Nkind (Stmt) = N_Object_Declaration then
3227 Expr := Expression (Stmt);
3229 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3238 end Has_Side_Effect;
3240 -- Start of processing for Is_Exception_Safe
3243 -- If the checks handled by the back end are not disabled, we cannot
3244 -- ensure that no exception will be raised.
3246 if not Access_Checks_Suppressed (Empty)
3247 or else not Discriminant_Checks_Suppressed (Empty)
3248 or else not Range_Checks_Suppressed (Empty)
3249 or else not Index_Checks_Suppressed (Empty)
3250 or else Opt.Stack_Checking_Enabled
3255 if Has_Side_Effect (First (Declarations (Subprogram)))
3258 First (Statements (Handled_Statement_Sequence (Subprogram))))
3264 end Is_Exception_Safe;
3266 -- Start of processing for Build_Protected_Subprogram_Body
3269 Op_Spec := Specification (N);
3270 Exc_Safe := Is_Exception_Safe (N);
3273 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3275 -- Build a list of the formal parameters of the protected version of
3276 -- the subprogram to use as the actual parameters of the unprotected
3279 Uactuals := New_List;
3280 Pformal := First (Parameter_Specifications (P_Op_Spec));
3281 while Present (Pformal) loop
3282 Append_To (Uactuals,
3283 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
3287 -- Make a call to the unprotected version of the subprogram built above
3288 -- for use by the protected version built below.
3290 if Nkind (Op_Spec) = N_Function_Specification then
3292 R := Make_Temporary (Loc, 'R');
3294 Make_Object_Declaration (Loc,
3295 Defining_Identifier => R,
3296 Constant_Present => True,
3297 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3299 Make_Function_Call (Loc,
3300 Name => Make_Identifier (Loc,
3301 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3302 Parameter_Associations => Uactuals));
3305 Make_Simple_Return_Statement (Loc,
3306 Expression => New_Reference_To (R, Loc));
3309 Unprot_Call := Make_Simple_Return_Statement (Loc,
3310 Expression => Make_Function_Call (Loc,
3312 Make_Identifier (Loc,
3313 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3314 Parameter_Associations => Uactuals));
3319 Make_Procedure_Call_Statement (Loc,
3321 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3322 Parameter_Associations => Uactuals);
3325 -- Wrap call in block that will be covered by an at_end handler
3327 if not Exc_Safe then
3328 Unprot_Call := Make_Block_Statement (Loc,
3329 Handled_Statement_Sequence =>
3330 Make_Handled_Sequence_Of_Statements (Loc,
3331 Statements => New_List (Unprot_Call)));
3334 -- Make the protected subprogram body. This locks the protected
3335 -- object and calls the unprotected version of the subprogram.
3337 case Corresponding_Runtime_Package (Pid) is
3338 when System_Tasking_Protected_Objects_Entries =>
3339 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3340 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3342 when System_Tasking_Protected_Objects_Single_Entry =>
3343 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3344 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3346 when System_Tasking_Protected_Objects =>
3347 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3348 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3351 raise Program_Error;
3355 Make_Attribute_Reference (Loc,
3357 Make_Selected_Component (Loc,
3358 Prefix => Make_Identifier (Loc, Name_uObject),
3359 Selector_Name => Make_Identifier (Loc, Name_uObject)),
3360 Attribute_Name => Name_Unchecked_Access);
3362 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3364 Parameter_Associations => New_List (Object_Parm));
3366 if Abort_Allowed then
3368 Make_Procedure_Call_Statement (Loc,
3369 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3370 Parameter_Associations => Empty_List),
3374 Stmts := New_List (Lock_Stmt);
3377 if not Exc_Safe then
3378 Append (Unprot_Call, Stmts);
3380 if Nkind (Op_Spec) = N_Function_Specification then
3382 Stmts := Empty_List;
3384 Append (Unprot_Call, Stmts);
3388 Make_Procedure_Call_Statement (Loc,
3389 Name => Service_Name,
3390 Parameter_Associations =>
3391 New_List (New_Copy_Tree (Object_Parm))),
3394 if Abort_Allowed then
3396 Make_Procedure_Call_Statement (Loc,
3397 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3398 Parameter_Associations => Empty_List),
3402 if Nkind (Op_Spec) = N_Function_Specification then
3403 Append (Return_Stmt, Stmts);
3404 Append (Make_Block_Statement (Loc,
3405 Declarations => New_List (Unprot_Call),
3406 Handled_Statement_Sequence =>
3407 Make_Handled_Sequence_Of_Statements (Loc,
3408 Statements => Stmts)), Pre_Stmts);
3414 Make_Subprogram_Body (Loc,
3415 Declarations => Empty_List,
3416 Specification => P_Op_Spec,
3417 Handled_Statement_Sequence =>
3418 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3420 if not Exc_Safe then
3421 Set_Is_Protected_Subprogram_Body (Sub_Body);
3425 end Build_Protected_Subprogram_Body;
3427 -------------------------------------
3428 -- Build_Protected_Subprogram_Call --
3429 -------------------------------------
3431 procedure Build_Protected_Subprogram_Call
3435 External : Boolean := True)
3437 Loc : constant Source_Ptr := Sloc (N);
3438 Sub : constant Entity_Id := Entity (Name);
3444 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3447 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3450 if Present (Parameter_Associations (N)) then
3451 Params := New_Copy_List_Tree (Parameter_Associations (N));
3456 -- If the type is an untagged derived type, convert to the root type,
3457 -- which is the one on which the operations are defined.
3459 if Nkind (Rec) = N_Unchecked_Type_Conversion
3460 and then not Is_Tagged_Type (Etype (Rec))
3461 and then Is_Derived_Type (Etype (Rec))
3463 Set_Etype (Rec, Root_Type (Etype (Rec)));
3464 Set_Subtype_Mark (Rec,
3465 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3468 Prepend (Rec, Params);
3470 if Ekind (Sub) = E_Procedure then
3472 Make_Procedure_Call_Statement (Loc,
3474 Parameter_Associations => Params));
3477 pragma Assert (Ekind (Sub) = E_Function);
3479 Make_Function_Call (Loc,
3481 Parameter_Associations => Params));
3485 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3486 and then Is_Entity_Name (Expression (Rec))
3487 and then Is_Shared_Passive (Entity (Expression (Rec)))
3489 Add_Shared_Var_Lock_Procs (N);
3491 end Build_Protected_Subprogram_Call;
3493 -------------------------
3494 -- Build_Selected_Name --
3495 -------------------------
3497 function Build_Selected_Name
3498 (Prefix : Entity_Id;
3499 Selector : Entity_Id;
3500 Append_Char : Character := ' ') return Name_Id
3502 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3503 Select_Len : Natural;
3506 Get_Name_String (Chars (Selector));
3507 Select_Len := Name_Len;
3508 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3509 Get_Name_String (Chars (Prefix));
3511 -- If scope is anonymous type, discard suffix to recover name of
3512 -- single protected object. Otherwise use protected type name.
3514 if Name_Buffer (Name_Len) = 'T' then
3515 Name_Len := Name_Len - 1;
3518 Add_Str_To_Name_Buffer ("__");
3519 for J in 1 .. Select_Len loop
3520 Add_Char_To_Name_Buffer (Select_Buffer (J));
3523 -- Now add the Append_Char if specified. The encoding to follow
3524 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3525 -- then the entity is associated to a protected type subprogram.
3526 -- Otherwise, it is a protected type entry. For each case, the
3527 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3529 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3531 if Append_Char /= ' ' then
3532 if Append_Char = 'P' or Append_Char = 'N' then
3533 Add_Char_To_Name_Buffer (Append_Char);
3536 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3537 return New_External_Name (Name_Find, ' ', -1);
3542 end Build_Selected_Name;
3544 -----------------------------
3545 -- Build_Simple_Entry_Call --
3546 -----------------------------
3548 -- A task entry call is converted to a call to Call_Simple
3551 -- P : parms := (parm, parm, parm);
3553 -- Call_Simple (acceptor-task, entry-index, P'Address);
3559 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3560 -- the parameters, and the constructed aggregate value contains either the
3561 -- parameters or, in the case of non-elementary types, references to these
3562 -- parameters. Then the address of this aggregate is passed to the runtime
3563 -- routine, along with the task id value and the task entry index value.
3564 -- Pnn is only required if parameters are present.
3566 -- The assignments after the call are present only in the case of in-out
3567 -- or out parameters for elementary types, and are used to assign back the
3568 -- resulting values of such parameters.
3570 -- Note: the reason that we insert a block here is that in the context
3571 -- of selects, conditional entry calls etc. the entry call statement
3572 -- appears on its own, not as an element of a list.
3574 -- A protected entry call is converted to a Protected_Entry_Call:
3577 -- P : E1_Params := (param, param, param);
3579 -- Bnn : Communications_Block;
3582 -- P : E1_Params := (param, param, param);
3583 -- Bnn : Communications_Block;
3586 -- Protected_Entry_Call (
3587 -- Object => po._object'Access,
3588 -- E => <entry index>;
3589 -- Uninterpreted_Data => P'Address;
3590 -- Mode => Simple_Call;
3597 procedure Build_Simple_Entry_Call
3606 -- If call has been inlined, nothing left to do
3608 if Nkind (N) = N_Block_Statement then
3612 -- Convert entry call to Call_Simple call
3615 Loc : constant Source_Ptr := Sloc (N);
3616 Parms : constant List_Id := Parameter_Associations (N);
3617 Stats : constant List_Id := New_List;
3620 Comm_Name : Entity_Id;
3624 Ent_Acc : Entity_Id;
3626 Iface_Tag : Entity_Id;
3627 Iface_Typ : Entity_Id;
3640 -- Simple entry and entry family cases merge here
3642 Ent := Entity (Ename);
3643 Ent_Acc := Entry_Parameters_Type (Ent);
3644 Conctyp := Etype (Concval);
3646 -- If prefix is an access type, dereference to obtain the task type
3648 if Is_Access_Type (Conctyp) then
3649 Conctyp := Designated_Type (Conctyp);
3652 -- Special case for protected subprogram calls
3654 if Is_Protected_Type (Conctyp)
3655 and then Is_Subprogram (Entity (Ename))
3657 if not Is_Eliminated (Entity (Ename)) then
3658 Build_Protected_Subprogram_Call
3659 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3666 -- First parameter is the Task_Id value from the task value or the
3667 -- Object from the protected object value, obtained by selecting
3668 -- the _Task_Id or _Object from the result of doing an unchecked
3669 -- conversion to convert the value to the corresponding record type.
3671 if Nkind (Concval) = N_Function_Call
3672 and then Is_Task_Type (Conctyp)
3673 and then Ada_Version >= Ada_2005
3676 ExpR : constant Node_Id := Relocate_Node (Concval);
3677 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3682 Make_Object_Declaration (Loc,
3683 Defining_Identifier => Obj,
3684 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3685 Expression => ExpR);
3686 Set_Etype (Obj, Conctyp);
3687 Decls := New_List (Decl);
3688 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3695 Parm1 := Concurrent_Ref (Concval);
3697 -- Second parameter is the entry index, computed by the routine
3698 -- provided for this purpose. The value of this expression is
3699 -- assigned to an intermediate variable to assure that any entry
3700 -- family index expressions are evaluated before the entry
3704 or else Restriction_Active (No_Entry_Queue) = False
3705 or else not Is_Protected_Type (Conctyp)
3706 or else Number_Entries (Conctyp) > 1
3707 or else (Has_Attach_Handler (Conctyp)
3708 and then not Restricted_Profile)
3710 X := Make_Defining_Identifier (Loc, Name_uX);
3713 Make_Object_Declaration (Loc,
3714 Defining_Identifier => X,
3715 Object_Definition =>
3716 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3717 Expression => Actual_Index_Expression (
3718 Loc, Entity (Ename), Index, Concval));
3720 Append_To (Decls, Xdecl);
3721 Parm2 := New_Reference_To (X, Loc);
3728 -- The third parameter is the packaged parameters. If there are
3729 -- none, then it is just the null address, since nothing is passed.
3732 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3735 -- Case of parameters present, where third argument is the address
3736 -- of a packaged record containing the required parameter values.
3739 -- First build a list of parameter values, which are references to
3740 -- objects of the parameter types.
3744 Actual := First_Actual (N);
3745 Formal := First_Formal (Ent);
3747 while Present (Actual) loop
3749 -- If it is a by_copy_type, copy it to a new variable. The
3750 -- packaged record has a field that points to this variable.
3752 if Is_By_Copy_Type (Etype (Actual)) then
3754 Make_Object_Declaration (Loc,
3755 Defining_Identifier => Make_Temporary (Loc, 'J'),
3756 Aliased_Present => True,
3757 Object_Definition =>
3758 New_Reference_To (Etype (Formal), Loc));
3760 -- Mark the object as not needing initialization since the
3761 -- initialization is performed separately, avoiding errors
3762 -- on cases such as formals of null-excluding access types.
3764 Set_No_Initialization (N_Node);
3766 -- We must make an assignment statement separate for the
3767 -- case of limited type. We cannot assign it unless the
3768 -- Assignment_OK flag is set first. An out formal of an
3769 -- access type must also be initialized from the actual,
3770 -- as stated in RM 6.4.1 (13).
3772 if Ekind (Formal) /= E_Out_Parameter
3773 or else Is_Access_Type (Etype (Formal))
3776 New_Reference_To (Defining_Identifier (N_Node), Loc);
3777 Set_Assignment_OK (N_Var);
3779 Make_Assignment_Statement (Loc,
3781 Expression => Relocate_Node (Actual)));
3784 Append (N_Node, Decls);
3787 Make_Attribute_Reference (Loc,
3788 Attribute_Name => Name_Unchecked_Access,
3790 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3792 -- If it is a VM_By_Copy_Actual, copy it to a new variable
3794 elsif Is_VM_By_Copy_Actual (Actual) then
3796 Make_Object_Declaration (Loc,
3797 Defining_Identifier => Make_Temporary (Loc, 'J'),
3798 Aliased_Present => True,
3799 Object_Definition =>
3800 New_Reference_To (Etype (Formal), Loc),
3801 Expression => New_Copy_Tree (Actual));
3802 Set_Assignment_OK (N_Node);
3804 Append (N_Node, Decls);
3807 Make_Attribute_Reference (Loc,
3808 Attribute_Name => Name_Unchecked_Access,
3810 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3813 -- Interface class-wide formal
3815 if Ada_Version >= Ada_2005
3816 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3817 and then Is_Interface (Etype (Formal))
3819 Iface_Typ := Etype (Etype (Formal));
3822 -- formal_iface_type! (actual.iface_tag)'reference
3825 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3826 pragma Assert (Present (Iface_Tag));
3829 Make_Reference (Loc,
3830 Unchecked_Convert_To (Iface_Typ,
3831 Make_Selected_Component (Loc,
3833 Relocate_Node (Actual),
3835 New_Reference_To (Iface_Tag, Loc)))));
3841 Make_Reference (Loc, Relocate_Node (Actual)));
3845 Next_Actual (Actual);
3846 Next_Formal_With_Extras (Formal);
3849 -- Now build the declaration of parameters initialized with the
3850 -- aggregate containing this constructed parameter list.
3852 P := Make_Defining_Identifier (Loc, Name_uP);
3855 Make_Object_Declaration (Loc,
3856 Defining_Identifier => P,
3857 Object_Definition =>
3858 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3860 Make_Aggregate (Loc, Expressions => Plist));
3863 Make_Attribute_Reference (Loc,
3864 Prefix => New_Reference_To (P, Loc),
3865 Attribute_Name => Name_Address);
3867 Append (Pdecl, Decls);
3870 -- Now we can create the call, case of protected type
3872 if Is_Protected_Type (Conctyp) then
3873 case Corresponding_Runtime_Package (Conctyp) is
3874 when System_Tasking_Protected_Objects_Entries =>
3876 -- Change the type of the index declaration
3878 Set_Object_Definition (Xdecl,
3879 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3881 -- Some additional declarations for protected entry calls
3887 -- Bnn : Communications_Block;
3889 Comm_Name := Make_Temporary (Loc, 'B');
3892 Make_Object_Declaration (Loc,
3893 Defining_Identifier => Comm_Name,
3894 Object_Definition =>
3895 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3897 -- Some additional statements for protected entry calls
3899 -- Protected_Entry_Call (
3900 -- Object => po._object'Access,
3901 -- E => <entry index>;
3902 -- Uninterpreted_Data => P'Address;
3903 -- Mode => Simple_Call;
3907 Make_Procedure_Call_Statement (Loc,
3909 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3911 Parameter_Associations => New_List (
3912 Make_Attribute_Reference (Loc,
3913 Attribute_Name => Name_Unchecked_Access,
3917 New_Reference_To (RTE (RE_Simple_Call), Loc),
3918 New_Occurrence_Of (Comm_Name, Loc)));
3920 when System_Tasking_Protected_Objects_Single_Entry =>
3921 -- Protected_Single_Entry_Call (
3922 -- Object => po._object'Access,
3923 -- Uninterpreted_Data => P'Address;
3924 -- Mode => Simple_Call);
3927 Make_Procedure_Call_Statement (Loc,
3928 Name => New_Reference_To (
3929 RTE (RE_Protected_Single_Entry_Call), Loc),
3931 Parameter_Associations => New_List (
3932 Make_Attribute_Reference (Loc,
3933 Attribute_Name => Name_Unchecked_Access,
3936 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3939 raise Program_Error;
3942 -- Case of task type
3946 Make_Procedure_Call_Statement (Loc,
3947 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3948 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3952 Append_To (Stats, Call);
3954 -- If there are out or in/out parameters by copy add assignment
3955 -- statements for the result values.
3957 if Present (Parms) then
3958 Actual := First_Actual (N);
3959 Formal := First_Formal (Ent);
3961 Set_Assignment_OK (Actual);
3962 while Present (Actual) loop
3963 if (Is_By_Copy_Type (Etype (Actual))
3964 or else Is_VM_By_Copy_Actual (Actual))
3965 and then Ekind (Formal) /= E_In_Parameter
3968 Make_Assignment_Statement (Loc,
3969 Name => New_Copy (Actual),
3971 Make_Explicit_Dereference (Loc,
3972 Make_Selected_Component (Loc,
3973 Prefix => New_Reference_To (P, Loc),
3975 Make_Identifier (Loc, Chars (Formal)))));
3977 -- In all cases (including limited private types) we want
3978 -- the assignment to be valid.
3980 Set_Assignment_OK (Name (N_Node));
3982 -- If the call is the triggering alternative in an
3983 -- asynchronous select, or the entry_call alternative of a
3984 -- conditional entry call, the assignments for in-out
3985 -- parameters are incorporated into the statement list that
3986 -- follows, so that there are executed only if the entry
3989 if (Nkind (Parent (N)) = N_Triggering_Alternative
3990 and then N = Triggering_Statement (Parent (N)))
3992 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3993 and then N = Entry_Call_Statement (Parent (N)))
3995 if No (Statements (Parent (N))) then
3996 Set_Statements (Parent (N), New_List);
3999 Prepend (N_Node, Statements (Parent (N)));
4002 Insert_After (Call, N_Node);
4006 Next_Actual (Actual);
4007 Next_Formal_With_Extras (Formal);
4011 -- Finally, create block and analyze it
4014 Make_Block_Statement (Loc,
4015 Declarations => Decls,
4016 Handled_Statement_Sequence =>
4017 Make_Handled_Sequence_Of_Statements (Loc,
4018 Statements => Stats)));
4022 end Build_Simple_Entry_Call;
4024 --------------------------------
4025 -- Build_Task_Activation_Call --
4026 --------------------------------
4028 procedure Build_Task_Activation_Call (N : Node_Id) is
4029 Loc : constant Source_Ptr := Sloc (N);
4036 -- Get the activation chain entity. Except in the case of a package
4037 -- body, this is in the node that was passed. For a package body, we
4038 -- have to find the corresponding package declaration node.
4040 if Nkind (N) = N_Package_Body then
4041 P := Corresponding_Spec (N);
4044 exit when Nkind (P) = N_Package_Declaration;
4047 Chain := Activation_Chain_Entity (P);
4050 Chain := Activation_Chain_Entity (N);
4053 if Present (Chain) then
4054 if Restricted_Profile then
4055 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
4057 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4061 Make_Procedure_Call_Statement (Loc,
4063 Parameter_Associations =>
4064 New_List (Make_Attribute_Reference (Loc,
4065 Prefix => New_Occurrence_Of (Chain, Loc),
4066 Attribute_Name => Name_Unchecked_Access)));
4068 if Nkind (N) = N_Package_Declaration then
4069 if Present (Corresponding_Body (N)) then
4072 elsif Present (Private_Declarations (Specification (N))) then
4073 Append (Call, Private_Declarations (Specification (N)));
4076 Append (Call, Visible_Declarations (Specification (N)));
4080 if Present (Handled_Statement_Sequence (N)) then
4082 -- The call goes at the start of the statement sequence
4083 -- after the start of exception range label if one is present.
4089 Stm := First (Statements (Handled_Statement_Sequence (N)));
4091 -- A special case, skip exception range label if one is
4092 -- present (from front end zcx processing).
4094 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4098 -- Another special case, if the first statement is a block
4099 -- from optimization of a local raise to a goto, then the
4100 -- call goes inside this block.
4102 if Nkind (Stm) = N_Block_Statement
4103 and then Exception_Junk (Stm)
4106 First (Statements (Handled_Statement_Sequence (Stm)));
4109 -- Insertion point is after any exception label pushes,
4110 -- since we want it covered by any local handlers.
4112 while Nkind (Stm) in N_Push_xxx_Label loop
4116 -- Now we have the proper insertion point
4118 Insert_Before (Stm, Call);
4122 Set_Handled_Statement_Sequence (N,
4123 Make_Handled_Sequence_Of_Statements (Loc,
4124 Statements => New_List (Call)));
4129 Check_Task_Activation (N);
4131 end Build_Task_Activation_Call;
4133 -------------------------------
4134 -- Build_Task_Allocate_Block --
4135 -------------------------------
4137 procedure Build_Task_Allocate_Block
4142 T : constant Entity_Id := Entity (Expression (N));
4143 Init : constant Entity_Id := Base_Init_Proc (T);
4144 Loc : constant Source_Ptr := Sloc (N);
4145 Chain : constant Entity_Id :=
4146 Make_Defining_Identifier (Loc, Name_uChain);
4147 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4152 Make_Block_Statement (Loc,
4153 Identifier => New_Reference_To (Blkent, Loc),
4154 Declarations => New_List (
4156 -- _Chain : Activation_Chain;
4158 Make_Object_Declaration (Loc,
4159 Defining_Identifier => Chain,
4160 Aliased_Present => True,
4161 Object_Definition =>
4162 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4164 Handled_Statement_Sequence =>
4165 Make_Handled_Sequence_Of_Statements (Loc,
4167 Statements => New_List (
4171 Make_Procedure_Call_Statement (Loc,
4172 Name => New_Reference_To (Init, Loc),
4173 Parameter_Associations => Args),
4175 -- Activate_Tasks (_Chain);
4177 Make_Procedure_Call_Statement (Loc,
4178 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4179 Parameter_Associations => New_List (
4180 Make_Attribute_Reference (Loc,
4181 Prefix => New_Reference_To (Chain, Loc),
4182 Attribute_Name => Name_Unchecked_Access))))),
4184 Has_Created_Identifier => True,
4185 Is_Task_Allocation_Block => True);
4188 Make_Implicit_Label_Declaration (Loc,
4189 Defining_Identifier => Blkent,
4190 Label_Construct => Block));
4192 Append_To (Actions, Block);
4194 Set_Activation_Chain_Entity (Block, Chain);
4195 end Build_Task_Allocate_Block;
4197 -----------------------------------------------
4198 -- Build_Task_Allocate_Block_With_Init_Stmts --
4199 -----------------------------------------------
4201 procedure Build_Task_Allocate_Block_With_Init_Stmts
4204 Init_Stmts : List_Id)
4206 Loc : constant Source_Ptr := Sloc (N);
4207 Chain : constant Entity_Id :=
4208 Make_Defining_Identifier (Loc, Name_uChain);
4209 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4213 Append_To (Init_Stmts,
4214 Make_Procedure_Call_Statement (Loc,
4215 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4216 Parameter_Associations => New_List (
4217 Make_Attribute_Reference (Loc,
4218 Prefix => New_Reference_To (Chain, Loc),
4219 Attribute_Name => Name_Unchecked_Access))));
4222 Make_Block_Statement (Loc,
4223 Identifier => New_Reference_To (Blkent, Loc),
4224 Declarations => New_List (
4226 -- _Chain : Activation_Chain;
4228 Make_Object_Declaration (Loc,
4229 Defining_Identifier => Chain,
4230 Aliased_Present => True,
4231 Object_Definition =>
4232 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4234 Handled_Statement_Sequence =>
4235 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4237 Has_Created_Identifier => True,
4238 Is_Task_Allocation_Block => True);
4241 Make_Implicit_Label_Declaration (Loc,
4242 Defining_Identifier => Blkent,
4243 Label_Construct => Block));
4245 Append_To (Actions, Block);
4247 Set_Activation_Chain_Entity (Block, Chain);
4248 end Build_Task_Allocate_Block_With_Init_Stmts;
4250 -----------------------------------
4251 -- Build_Task_Proc_Specification --
4252 -----------------------------------
4254 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4255 Loc : constant Source_Ptr := Sloc (T);
4256 Spec_Id : Entity_Id;
4259 -- Case of explicit task type, suffix TB
4261 if Comes_From_Source (T) then
4263 Make_Defining_Identifier (Loc,
4264 Chars => New_External_Name (Chars (T), "TB"));
4266 -- Case of anonymous task type, suffix B
4270 Make_Defining_Identifier (Loc,
4271 Chars => New_External_Name (Chars (T), 'B'));
4274 Set_Is_Internal (Spec_Id);
4276 -- Associate the procedure with the task, if this is the declaration
4277 -- (and not the body) of the procedure.
4279 if No (Task_Body_Procedure (T)) then
4280 Set_Task_Body_Procedure (T, Spec_Id);
4284 Make_Procedure_Specification (Loc,
4285 Defining_Unit_Name => Spec_Id,
4286 Parameter_Specifications => New_List (
4287 Make_Parameter_Specification (Loc,
4288 Defining_Identifier =>
4289 Make_Defining_Identifier (Loc, Name_uTask),
4291 Make_Access_Definition (Loc,
4293 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4294 end Build_Task_Proc_Specification;
4296 ---------------------------------------
4297 -- Build_Unprotected_Subprogram_Body --
4298 ---------------------------------------
4300 function Build_Unprotected_Subprogram_Body
4302 Pid : Node_Id) return Node_Id
4304 Decls : constant List_Id := Declarations (N);
4307 -- Add renamings for the Protection object, discriminals, privals and
4308 -- the entry index constant for use by debugger.
4310 Debug_Private_Data_Declarations (Decls);
4312 -- Make an unprotected version of the subprogram for use within the same
4313 -- object, with a new name and an additional parameter representing the
4317 Make_Subprogram_Body (Sloc (N),
4319 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4320 Declarations => Decls,
4321 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4322 end Build_Unprotected_Subprogram_Body;
4324 ----------------------------
4325 -- Collect_Entry_Families --
4326 ----------------------------
4328 procedure Collect_Entry_Families
4331 Current_Node : in out Node_Id;
4332 Conctyp : Entity_Id)
4335 Efam_Decl : Node_Id;
4336 Efam_Type : Entity_Id;
4339 Efam := First_Entity (Conctyp);
4340 while Present (Efam) loop
4341 if Ekind (Efam) = E_Entry_Family then
4342 Efam_Type := Make_Temporary (Loc, 'F');
4347 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4349 Bas_Decl : Node_Id := Empty;
4354 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4356 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4357 Bas := Make_Temporary (Loc, 'B');
4360 Make_Subtype_Declaration (Loc,
4361 Defining_Identifier => Bas,
4362 Subtype_Indication =>
4363 Make_Subtype_Indication (Loc,
4365 New_Occurrence_Of (Standard_Integer, Loc),
4367 Make_Range_Constraint (Loc,
4368 Range_Expression => Make_Range (Loc,
4369 Make_Integer_Literal
4370 (Loc, -Entry_Family_Bound),
4371 Make_Integer_Literal
4372 (Loc, Entry_Family_Bound - 1)))));
4374 Insert_After (Current_Node, Bas_Decl);
4375 Current_Node := Bas_Decl;
4380 Make_Full_Type_Declaration (Loc,
4381 Defining_Identifier => Efam_Type,
4383 Make_Unconstrained_Array_Definition (Loc,
4385 (New_List (New_Occurrence_Of (Bas, Loc))),
4387 Component_Definition =>
4388 Make_Component_Definition (Loc,
4389 Aliased_Present => False,
4390 Subtype_Indication =>
4391 New_Reference_To (Standard_Character, Loc))));
4394 Insert_After (Current_Node, Efam_Decl);
4395 Current_Node := Efam_Decl;
4396 Analyze (Efam_Decl);
4399 Make_Component_Declaration (Loc,
4400 Defining_Identifier =>
4401 Make_Defining_Identifier (Loc, Chars (Efam)),
4403 Component_Definition =>
4404 Make_Component_Definition (Loc,
4405 Aliased_Present => False,
4406 Subtype_Indication =>
4407 Make_Subtype_Indication (Loc,
4409 New_Occurrence_Of (Efam_Type, Loc),
4412 Make_Index_Or_Discriminant_Constraint (Loc,
4413 Constraints => New_List (
4415 (Etype (Discrete_Subtype_Definition
4416 (Parent (Efam))), Loc)))))));
4422 end Collect_Entry_Families;
4424 -----------------------
4425 -- Concurrent_Object --
4426 -----------------------
4428 function Concurrent_Object
4429 (Spec_Id : Entity_Id;
4430 Conc_Typ : Entity_Id) return Entity_Id
4433 -- Parameter _O or _object
4435 if Is_Protected_Type (Conc_Typ) then
4436 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4441 pragma Assert (Is_Task_Type (Conc_Typ));
4442 return First_Formal (Task_Body_Procedure (Conc_Typ));
4444 end Concurrent_Object;
4446 ----------------------
4447 -- Copy_Result_Type --
4448 ----------------------
4450 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4451 New_Res : constant Node_Id := New_Copy_Tree (Res);
4456 -- If the result type is an access_to_subprogram, we must create
4457 -- new entities for its spec.
4459 if Nkind (New_Res) = N_Access_Definition
4460 and then Present (Access_To_Subprogram_Definition (New_Res))
4462 -- Provide new entities for the formals
4464 Par_Spec := First (Parameter_Specifications
4465 (Access_To_Subprogram_Definition (New_Res)));
4466 while Present (Par_Spec) loop
4467 Formal := Defining_Identifier (Par_Spec);
4468 Set_Defining_Identifier (Par_Spec,
4469 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4475 end Copy_Result_Type;
4477 --------------------
4478 -- Concurrent_Ref --
4479 --------------------
4481 -- The expression returned for a reference to a concurrent object has the
4484 -- taskV!(name)._Task_Id
4488 -- objectV!(name)._Object
4490 -- for a protected object. For the case of an access to a concurrent
4491 -- object, there is an extra explicit dereference:
4493 -- taskV!(name.all)._Task_Id
4494 -- objectV!(name.all)._Object
4496 -- here taskV and objectV are the types for the associated records, which
4497 -- contain the required _Task_Id and _Object fields for tasks and protected
4498 -- objects, respectively.
4500 -- For the case of a task type name, the expression is
4504 -- i.e. a call to the Self function which returns precisely this Task_Id
4506 -- For the case of a protected type name, the expression is
4510 -- which is a renaming of the _object field of the current object
4511 -- record, passed into protected operations as a parameter.
4513 function Concurrent_Ref (N : Node_Id) return Node_Id is
4514 Loc : constant Source_Ptr := Sloc (N);
4515 Ntyp : constant Entity_Id := Etype (N);
4519 function Is_Current_Task (T : Entity_Id) return Boolean;
4520 -- Check whether the reference is to the immediately enclosing task
4521 -- type, or to an outer one (rare but legal).
4523 ---------------------
4524 -- Is_Current_Task --
4525 ---------------------
4527 function Is_Current_Task (T : Entity_Id) return Boolean is
4531 Scop := Current_Scope;
4532 while Present (Scop)
4533 and then Scop /= Standard_Standard
4539 elsif Is_Task_Type (Scop) then
4542 -- If this is a procedure nested within the task type, we must
4543 -- assume that it can be called from an inner task, and therefore
4544 -- cannot treat it as a local reference.
4546 elsif Is_Overloadable (Scop)
4547 and then In_Open_Scopes (T)
4552 Scop := Scope (Scop);
4556 -- We know that we are within the task body, so should have found it
4559 raise Program_Error;
4560 end Is_Current_Task;
4562 -- Start of processing for Concurrent_Ref
4565 if Is_Access_Type (Ntyp) then
4566 Dtyp := Designated_Type (Ntyp);
4568 if Is_Protected_Type (Dtyp) then
4569 Sel := Name_uObject;
4571 Sel := Name_uTask_Id;
4575 Make_Selected_Component (Loc,
4577 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4578 Make_Explicit_Dereference (Loc, N)),
4579 Selector_Name => Make_Identifier (Loc, Sel));
4581 elsif Is_Entity_Name (N)
4582 and then Is_Concurrent_Type (Entity (N))
4584 if Is_Task_Type (Entity (N)) then
4586 if Is_Current_Task (Entity (N)) then
4588 Make_Function_Call (Loc,
4589 Name => New_Reference_To (RTE (RE_Self), Loc));
4594 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4595 T_Body : constant Node_Id :=
4596 Parent (Corresponding_Body (Parent (Entity (N))));
4600 Make_Object_Declaration (Loc,
4601 Defining_Identifier => T_Self,
4602 Object_Definition =>
4603 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4605 Make_Function_Call (Loc,
4606 Name => New_Reference_To (RTE (RE_Self), Loc)));
4607 Prepend (Decl, Declarations (T_Body));
4609 Set_Scope (T_Self, Entity (N));
4610 return New_Occurrence_Of (T_Self, Loc);
4615 pragma Assert (Is_Protected_Type (Entity (N)));
4618 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4622 if Is_Protected_Type (Ntyp) then
4623 Sel := Name_uObject;
4625 elsif Is_Task_Type (Ntyp) then
4626 Sel := Name_uTask_Id;
4629 raise Program_Error;
4633 Make_Selected_Component (Loc,
4635 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4637 Selector_Name => Make_Identifier (Loc, Sel));
4641 ------------------------
4642 -- Convert_Concurrent --
4643 ------------------------
4645 function Convert_Concurrent
4647 Typ : Entity_Id) return Node_Id
4650 if not Is_Concurrent_Type (Typ) then
4654 Unchecked_Convert_To
4655 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4657 end Convert_Concurrent;
4659 -------------------------------------
4660 -- Debug_Private_Data_Declarations --
4661 -------------------------------------
4663 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4664 Debug_Nod : Node_Id;
4668 Decl := First (Decls);
4669 while Present (Decl)
4670 and then not Comes_From_Source (Decl)
4672 -- Declaration for concurrent entity _object and its access type,
4673 -- along with the entry index subtype:
4674 -- type prot_typVP is access prot_typV;
4675 -- _object : prot_typVP := prot_typV (_O);
4676 -- subtype Jnn is <Type of Index> range Low .. High;
4678 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4679 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4681 -- Declaration for the Protection object, discriminals, privals and
4682 -- entry index constant:
4683 -- conc_typR : protection_typ renames _object._object;
4684 -- discr_nameD : discr_typ renames _object.discr_name;
4685 -- discr_nameD : discr_typ renames _task.discr_name;
4686 -- prival_name : comp_typ renames _object.comp_name;
4687 -- J : constant Jnn :=
4688 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4690 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4691 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4692 Debug_Nod := Debug_Renaming_Declaration (Decl);
4694 if Present (Debug_Nod) then
4695 Insert_After (Decl, Debug_Nod);
4701 end Debug_Private_Data_Declarations;
4703 ----------------------------
4704 -- Entry_Index_Expression --
4705 ----------------------------
4707 function Entry_Index_Expression
4711 Ttyp : Entity_Id) return Node_Id
4721 -- The queues of entries and entry families appear in textual order in
4722 -- the associated record. The entry index is computed as the sum of the
4723 -- number of queues for all entries that precede the designated one, to
4724 -- which is added the index expression, if this expression denotes a
4725 -- member of a family.
4727 -- The following is a place holder for the count of simple entries
4729 Num := Make_Integer_Literal (Sloc, 1);
4731 -- We construct an expression which is a series of addition operations.
4732 -- The first operand is the number of single entries that precede this
4733 -- one, the second operand is the index value relative to the start of
4734 -- the referenced family, and the remaining operands are the lengths of
4735 -- the entry families that precede this entry, i.e. the constructed
4738 -- number_simple_entries +
4739 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4740 -- family'length + ...
4742 -- where index-value is the given index value, and s is the index
4743 -- subtype (we have to use pos because the subtype might be an
4744 -- enumeration type preventing direct subtraction). Note that the task
4745 -- entry array is one-indexed.
4747 -- The upper bound of the entry family may be a discriminant, so we
4748 -- retrieve the lower bound explicitly to compute offset, rather than
4749 -- using the index subtype which may mention a discriminant.
4751 if Present (Index) then
4752 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4761 Make_Attribute_Reference (Sloc,
4762 Attribute_Name => Name_Pos,
4763 Prefix => New_Reference_To (Base_Type (S), Sloc),
4764 Expressions => New_List (Relocate_Node (Index))),
4772 -- Now add lengths of preceding entries and entry families
4774 Prev := First_Entity (Ttyp);
4776 while Chars (Prev) /= Chars (Ent)
4777 or else (Ekind (Prev) /= Ekind (Ent))
4778 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4780 if Ekind (Prev) = E_Entry then
4781 Set_Intval (Num, Intval (Num) + 1);
4783 elsif Ekind (Prev) = E_Entry_Family then
4785 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4786 Lo := Type_Low_Bound (S);
4787 Hi := Type_High_Bound (S);
4792 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4794 -- Other components are anonymous types to be ignored
4804 end Entry_Index_Expression;
4806 ---------------------------
4807 -- Establish_Task_Master --
4808 ---------------------------
4810 procedure Establish_Task_Master (N : Node_Id) is
4813 if Restriction_Active (No_Task_Hierarchy) = False then
4814 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4815 Prepend_To (Declarations (N), Call);
4818 end Establish_Task_Master;
4820 --------------------------------
4821 -- Expand_Accept_Declarations --
4822 --------------------------------
4824 -- Part of the expansion of an accept statement involves the creation of
4825 -- a declaration that can be referenced from the statement sequence of
4830 -- This declaration is inserted immediately before the accept statement
4831 -- and it is important that it be inserted before the statements of the
4832 -- statement sequence are analyzed. Thus it would be too late to create
4833 -- this declaration in the Expand_N_Accept_Statement routine, which is
4834 -- why there is a separate procedure to be called directly from Sem_Ch9.
4836 -- Ann is used to hold the address of the record containing the parameters
4837 -- (see Expand_N_Entry_Call for more details on how this record is built).
4838 -- References to the parameters do an unchecked conversion of this address
4839 -- to a pointer to the required record type, and then access the field that
4840 -- holds the value of the required parameter. The entity for the address
4841 -- variable is held as the top stack element (i.e. the last element) of the
4842 -- Accept_Address stack in the corresponding entry entity, and this element
4843 -- must be set in place before the statements are processed.
4845 -- The above description applies to the case of a stand alone accept
4846 -- statement, i.e. one not appearing as part of a select alternative.
4848 -- For the case of an accept that appears as part of a select alternative
4849 -- of a selective accept, we must still create the declaration right away,
4850 -- since Ann is needed immediately, but there is an important difference:
4852 -- The declaration is inserted before the selective accept, not before
4853 -- the accept statement (which is not part of a list anyway, and so would
4854 -- not accommodate inserted declarations)
4856 -- We only need one address variable for the entire selective accept. So
4857 -- the Ann declaration is created only for the first accept alternative,
4858 -- and subsequent accept alternatives reference the same Ann variable.
4860 -- We can distinguish the two cases by seeing whether the accept statement
4861 -- is part of a list. If not, then it must be in an accept alternative.
4863 -- To expand the requeue statement, a label is provided at the end of the
4864 -- accept statement or alternative of which it is a part, so that the
4865 -- statement can be skipped after the requeue is complete. This label is
4866 -- created here rather than during the expansion of the accept statement,
4867 -- because it will be needed by any requeue statements within the accept,
4868 -- which are expanded before the accept.
4870 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4871 Loc : constant Source_Ptr := Sloc (N);
4872 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4873 Ann : Entity_Id := Empty;
4881 if Expander_Active then
4883 -- If we have no handled statement sequence, we may need to build
4884 -- a dummy sequence consisting of a null statement. This can be
4885 -- skipped if the trivial accept optimization is permitted.
4887 if not Trivial_Accept_OK
4889 (No (Stats) or else Null_Statements (Statements (Stats)))
4891 Set_Handled_Statement_Sequence (N,
4892 Make_Handled_Sequence_Of_Statements (Loc,
4893 New_List (Make_Null_Statement (Loc))));
4896 -- Create and declare two labels to be placed at the end of the
4897 -- accept statement. The first label is used to allow requeues to
4898 -- skip the remainder of entry processing. The second label is used
4899 -- to skip the remainder of entry processing if the rendezvous
4900 -- completes in the middle of the accept body.
4902 if Present (Handled_Statement_Sequence (N)) then
4907 Ent := Make_Temporary (Loc, 'L');
4908 Lab_Id := New_Reference_To (Ent, Loc);
4909 Lab := Make_Label (Loc, Lab_Id);
4911 Make_Implicit_Label_Declaration (Loc,
4912 Defining_Identifier => Ent,
4913 Label_Construct => Lab);
4914 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4916 Ent := Make_Temporary (Loc, 'L');
4917 Lab_Id := New_Reference_To (Ent, Loc);
4918 Lab := Make_Label (Loc, Lab_Id);
4920 Make_Implicit_Label_Declaration (Loc,
4921 Defining_Identifier => Ent,
4922 Label_Construct => Lab);
4923 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4931 -- Case of stand alone accept statement
4933 if Is_List_Member (N) then
4935 if Present (Handled_Statement_Sequence (N)) then
4936 Ann := Make_Temporary (Loc, 'A');
4939 Make_Object_Declaration (Loc,
4940 Defining_Identifier => Ann,
4941 Object_Definition =>
4942 New_Reference_To (RTE (RE_Address), Loc));
4944 Insert_Before (N, Adecl);
4947 Insert_Before (N, Ldecl);
4950 Insert_Before (N, Ldecl2);
4954 -- Case of accept statement which is in an accept alternative
4958 Acc_Alt : constant Node_Id := Parent (N);
4959 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4963 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4964 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4966 -- ??? Consider a single label for select statements
4968 if Present (Handled_Statement_Sequence (N)) then
4970 Statements (Handled_Statement_Sequence (N)));
4974 Statements (Handled_Statement_Sequence (N)));
4978 -- Find first accept alternative of the selective accept. A
4979 -- valid selective accept must have at least one accept in it.
4981 Alt := First (Select_Alternatives (Sel_Acc));
4983 while Nkind (Alt) /= N_Accept_Alternative loop
4987 -- If we are the first accept statement, then we have to create
4988 -- the Ann variable, as for the stand alone case, except that
4989 -- it is inserted before the selective accept. Similarly, a
4990 -- label for requeue expansion must be declared.
4992 if N = Accept_Statement (Alt) then
4993 Ann := Make_Temporary (Loc, 'A');
4995 Make_Object_Declaration (Loc,
4996 Defining_Identifier => Ann,
4997 Object_Definition =>
4998 New_Reference_To (RTE (RE_Address), Loc));
5000 Insert_Before (Sel_Acc, Adecl);
5003 -- If we are not the first accept statement, then find the Ann
5004 -- variable allocated by the first accept and use it.
5008 Node (Last_Elmt (Accept_Address
5009 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
5014 -- Merge here with Ann either created or referenced, and Adecl
5015 -- pointing to the corresponding declaration. Remaining processing
5016 -- is the same for the two cases.
5018 if Present (Ann) then
5019 Append_Elmt (Ann, Accept_Address (Ent));
5020 Set_Debug_Info_Needed (Ann);
5023 -- Create renaming declarations for the entry formals. Each reference
5024 -- to a formal becomes a dereference of a component of the parameter
5025 -- block, whose address is held in Ann. These declarations are
5026 -- eventually inserted into the accept block, and analyzed there so
5027 -- that they have the proper scope for gdb and do not conflict with
5028 -- other declarations.
5030 if Present (Parameter_Specifications (N))
5031 and then Present (Handled_Statement_Sequence (N))
5038 Renamed_Formal : Node_Id;
5042 Formal := First_Formal (Ent);
5044 while Present (Formal) loop
5045 Comp := Entry_Component (Formal);
5047 Make_Defining_Identifier (Loc, Chars (Formal));
5049 Set_Etype (New_F, Etype (Formal));
5050 Set_Scope (New_F, Ent);
5052 -- Now we set debug info needed on New_F even though it does
5053 -- not come from source, so that the debugger will get the
5054 -- right information for these generated names.
5056 Set_Debug_Info_Needed (New_F);
5058 if Ekind (Formal) = E_In_Parameter then
5059 Set_Ekind (New_F, E_Constant);
5061 Set_Ekind (New_F, E_Variable);
5062 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5065 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5068 Make_Selected_Component (Loc,
5070 Unchecked_Convert_To (
5071 Entry_Parameters_Type (Ent),
5072 New_Reference_To (Ann, Loc)),
5074 New_Reference_To (Comp, Loc));
5077 Build_Renamed_Formal_Declaration
5078 (New_F, Formal, Comp, Renamed_Formal);
5080 if No (Declarations (N)) then
5081 Set_Declarations (N, New_List);
5084 Append (Decl, Declarations (N));
5085 Set_Renamed_Object (Formal, New_F);
5086 Next_Formal (Formal);
5093 end Expand_Accept_Declarations;
5095 ---------------------------------------------
5096 -- Expand_Access_Protected_Subprogram_Type --
5097 ---------------------------------------------
5099 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5100 Loc : constant Source_Ptr := Sloc (N);
5102 T : constant Entity_Id := Defining_Identifier (N);
5103 D_T : constant Entity_Id := Designated_Type (T);
5104 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5105 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5106 P_List : constant List_Id := Build_Protected_Spec
5107 (N, RTE (RE_Address), D_T, False);
5113 -- Create access to subprogram with full signature
5115 if Etype (D_T) /= Standard_Void_Type then
5117 Make_Access_Function_Definition (Loc,
5118 Parameter_Specifications => P_List,
5119 Result_Definition =>
5120 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5124 Make_Access_Procedure_Definition (Loc,
5125 Parameter_Specifications => P_List);
5129 Make_Full_Type_Declaration (Loc,
5130 Defining_Identifier => D_T2,
5131 Type_Definition => Def1);
5133 Insert_After (N, Decl1);
5136 -- Associate the access to subprogram with its original access to
5137 -- protected subprogram type. Needed by the backend to know that this
5138 -- type corresponds with an access to protected subprogram type.
5140 Set_Original_Access_Type (D_T2, T);
5142 -- Create Equivalent_Type, a record with two components for an access to
5143 -- object and an access to subprogram.
5146 Make_Component_Declaration (Loc,
5147 Defining_Identifier => Make_Temporary (Loc, 'P'),
5148 Component_Definition =>
5149 Make_Component_Definition (Loc,
5150 Aliased_Present => False,
5151 Subtype_Indication =>
5152 New_Occurrence_Of (RTE (RE_Address), Loc))),
5154 Make_Component_Declaration (Loc,
5155 Defining_Identifier => Make_Temporary (Loc, 'S'),
5156 Component_Definition =>
5157 Make_Component_Definition (Loc,
5158 Aliased_Present => False,
5159 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5162 Make_Full_Type_Declaration (Loc,
5163 Defining_Identifier => E_T,
5165 Make_Record_Definition (Loc,
5167 Make_Component_List (Loc,
5168 Component_Items => Comps)));
5170 Insert_After (Decl1, Decl2);
5172 Set_Equivalent_Type (T, E_T);
5173 end Expand_Access_Protected_Subprogram_Type;
5175 --------------------------
5176 -- Expand_Entry_Barrier --
5177 --------------------------
5179 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5180 Cond : constant Node_Id :=
5181 Condition (Entry_Body_Formal_Part (N));
5182 Prot : constant Entity_Id := Scope (Ent);
5183 Spec_Decl : constant Node_Id := Parent (Prot);
5186 Body_Decl : Node_Id;
5189 if No_Run_Time_Mode then
5190 Error_Msg_CRT ("entry barrier", N);
5194 -- The body of the entry barrier must be analyzed in the context of the
5195 -- protected object, but its scope is external to it, just as any other
5196 -- unprotected version of a protected operation. The specification has
5197 -- been produced when the protected type declaration was elaborated. We
5198 -- build the body, insert it in the enclosing scope, but analyze it in
5199 -- the current context. A more uniform approach would be to treat the
5200 -- barrier just as a protected function, and discard the protected
5201 -- version of it because it is never called.
5203 if Expander_Active then
5204 B_F := Build_Barrier_Function (N, Ent, Prot);
5205 Func := Barrier_Function (Ent);
5206 Set_Corresponding_Spec (B_F, Func);
5208 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5210 if Nkind (Parent (Body_Decl)) = N_Subunit then
5211 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5214 Insert_Before_And_Analyze (Body_Decl, B_F);
5216 Set_Discriminals (Spec_Decl);
5217 Set_Scope (Func, Scope (Prot));
5220 Analyze_And_Resolve (Cond, Any_Boolean);
5223 -- The Ravenscar profile restricts barriers to simple variables declared
5224 -- within the protected object. We also allow Boolean constants, since
5225 -- these appear in several published examples and are also allowed by
5226 -- the Aonix compiler.
5228 -- Note that after analysis variables in this context will be replaced
5229 -- by the corresponding prival, that is to say a renaming of a selected
5230 -- component of the form _Object.Var. If expansion is disabled, as
5231 -- within a generic, we check that the entity appears in the current
5234 if Is_Entity_Name (Cond) then
5236 -- A small optimization of useless renamings. If the scope of the
5237 -- entity of the condition is not the barrier function, then the
5238 -- condition does not reference any of the generated renamings
5239 -- within the function.
5242 and then Scope (Entity (Cond)) /= Func
5244 Set_Declarations (B_F, Empty_List);
5247 if Entity (Cond) = Standard_False
5249 Entity (Cond) = Standard_True
5253 elsif not Expander_Active
5254 and then Scope (Entity (Cond)) = Current_Scope
5258 -- Check for case of _object.all.field (note that the explicit
5259 -- dereference gets inserted by analyze/expand of _object.field)
5261 elsif Present (Renamed_Object (Entity (Cond)))
5263 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5267 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5273 -- It is not a boolean variable or literal, so check the restriction
5275 Check_Restriction (Simple_Barriers, Cond);
5276 end Expand_Entry_Barrier;
5278 ------------------------------
5279 -- Expand_N_Abort_Statement --
5280 ------------------------------
5282 -- Expand abort T1, T2, .. Tn; into:
5283 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5285 procedure Expand_N_Abort_Statement (N : Node_Id) is
5286 Loc : constant Source_Ptr := Sloc (N);
5287 Tlist : constant List_Id := Names (N);
5293 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5296 Tasknm := First (Tlist);
5298 while Present (Tasknm) loop
5301 -- A task interface class-wide type object is being aborted.
5302 -- Retrieve its _task_id by calling a dispatching routine.
5304 if Ada_Version >= Ada_2005
5305 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5306 and then Is_Interface (Etype (Tasknm))
5307 and then Is_Task_Interface (Etype (Tasknm))
5309 Append_To (Component_Associations (Aggr),
5310 Make_Component_Association (Loc,
5311 Choices => New_List (
5312 Make_Integer_Literal (Loc, Count)),
5315 -- Task_Id (Tasknm._disp_get_task_id)
5317 Make_Unchecked_Type_Conversion (Loc,
5319 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5321 Make_Selected_Component (Loc,
5322 Prefix => New_Copy_Tree (Tasknm),
5324 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5327 Append_To (Component_Associations (Aggr),
5328 Make_Component_Association (Loc,
5329 Choices => New_List (
5330 Make_Integer_Literal (Loc, Count)),
5331 Expression => Concurrent_Ref (Tasknm)));
5338 Make_Procedure_Call_Statement (Loc,
5339 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5340 Parameter_Associations => New_List (
5341 Make_Qualified_Expression (Loc,
5342 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5343 Expression => Aggr))));
5346 end Expand_N_Abort_Statement;
5348 -------------------------------
5349 -- Expand_N_Accept_Statement --
5350 -------------------------------
5352 -- This procedure handles expansion of accept statements that stand
5353 -- alone, i.e. they are not part of an accept alternative. The expansion
5354 -- of accept statement in accept alternatives is handled by the routines
5355 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5356 -- following description applies only to stand alone accept statements.
5358 -- If there is no handled statement sequence, or only null statements,
5359 -- then this is called a trivial accept, and the expansion is:
5361 -- Accept_Trivial (entry-index)
5363 -- If there is a handled statement sequence, then the expansion is:
5370 -- Accept_Call (entry-index, Ann);
5371 -- Renaming_Declarations for formals
5372 -- <statement sequence from N_Accept_Statement node>
5373 -- Complete_Rendezvous;
5378 -- <exception handler from N_Accept_Statement node>
5379 -- Complete_Rendezvous;
5381 -- <exception handler from N_Accept_Statement node>
5382 -- Complete_Rendezvous;
5387 -- when all others =>
5388 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5391 -- The first three declarations were already inserted ahead of the accept
5392 -- statement by the Expand_Accept_Declarations procedure, which was called
5393 -- directly from the semantics during analysis of the accept statement,
5394 -- before analyzing its contained statements.
5396 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5397 -- from possible expansion activity (the original source of course does
5398 -- not have any declarations associated with the accept statement, since
5399 -- an accept statement has no declarative part). In particular, if the
5400 -- expander is active, the first such declaration is the declaration of
5401 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5403 -- The two blocks are merged into a single block if the inner block has
5404 -- no exception handlers, but otherwise two blocks are required, since
5405 -- exceptions might be raised in the exception handlers of the inner
5406 -- block, and Exceptional_Complete_Rendezvous must be called.
5408 procedure Expand_N_Accept_Statement (N : Node_Id) is
5409 Loc : constant Source_Ptr := Sloc (N);
5410 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5411 Ename : constant Node_Id := Entry_Direct_Name (N);
5412 Eindx : constant Node_Id := Entry_Index (N);
5413 Eent : constant Entity_Id := Entity (Ename);
5414 Acstack : constant Elist_Id := Accept_Address (Eent);
5415 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5416 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5421 -- Start of processing for Expand_N_Accept_Statement
5424 -- If accept statement is not part of a list, then its parent must be
5425 -- an accept alternative, and, as described above, we do not do any
5426 -- expansion for such accept statements at this level.
5428 if not Is_List_Member (N) then
5429 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5432 -- Trivial accept case (no statement sequence, or null statements).
5433 -- If the accept statement has declarations, then just insert them
5434 -- before the procedure call.
5436 elsif Trivial_Accept_OK
5437 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5439 -- Remove declarations for renamings, because the parameter block
5440 -- will not be assigned.
5447 D := First (Declarations (N));
5449 while Present (D) loop
5451 if Nkind (D) = N_Object_Renaming_Declaration then
5459 if Present (Declarations (N)) then
5460 Insert_Actions (N, Declarations (N));
5464 Make_Procedure_Call_Statement (Loc,
5465 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5466 Parameter_Associations => New_List (
5467 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5471 -- Discard Entry_Address that was created for it, so it will not be
5472 -- emitted if this accept statement is in the statement part of a
5473 -- delay alternative.
5475 if Present (Stats) then
5476 Remove_Last_Elmt (Acstack);
5479 -- Case of statement sequence present
5482 -- Construct the block, using the declarations from the accept
5483 -- statement if any to initialize the declarations of the block.
5485 Blkent := Make_Temporary (Loc, 'A');
5486 Set_Ekind (Blkent, E_Block);
5487 Set_Etype (Blkent, Standard_Void_Type);
5488 Set_Scope (Blkent, Current_Scope);
5491 Make_Block_Statement (Loc,
5492 Identifier => New_Reference_To (Blkent, Loc),
5493 Declarations => Declarations (N),
5494 Handled_Statement_Sequence => Build_Accept_Body (N));
5496 -- For the analysis of the generated declarations, the parent node
5497 -- must be properly set.
5499 Set_Parent (Block, Parent (N));
5501 -- Prepend call to Accept_Call to main statement sequence If the
5502 -- accept has exception handlers, the statement sequence is wrapped
5503 -- in a block. Insert call and renaming declarations in the
5504 -- declarations of the block, so they are elaborated before the
5508 Make_Procedure_Call_Statement (Loc,
5509 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5510 Parameter_Associations => New_List (
5511 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5512 New_Reference_To (Ann, Loc)));
5514 if Parent (Stats) = N then
5515 Prepend (Call, Statements (Stats));
5524 Push_Scope (Blkent);
5532 D := First (Declarations (N));
5533 while Present (D) loop
5536 if Nkind (D) = N_Object_Renaming_Declaration then
5538 -- The renaming declarations for the formals were created
5539 -- during analysis of the accept statement, and attached to
5540 -- the list of declarations. Place them now in the context
5541 -- of the accept block or subprogram.
5544 Typ := Entity (Subtype_Mark (D));
5545 Insert_After (Call, D);
5548 -- If the formal is class_wide, it does not have an actual
5549 -- subtype. The analysis of the renaming declaration creates
5550 -- one, but we need to retain the class-wide nature of the
5553 if Is_Class_Wide_Type (Typ) then
5554 Set_Etype (Defining_Identifier (D), Typ);
5565 -- Replace the accept statement by the new block
5570 -- Last step is to unstack the Accept_Address value
5572 Remove_Last_Elmt (Acstack);
5574 end Expand_N_Accept_Statement;
5576 ----------------------------------
5577 -- Expand_N_Asynchronous_Select --
5578 ----------------------------------
5580 -- This procedure assumes that the trigger statement is an entry call or
5581 -- a dispatching procedure call. A delay alternative should already have
5582 -- been expanded into an entry call to the appropriate delay object Wait
5585 -- If the trigger is a task entry call, the select is implemented with
5586 -- a Task_Entry_Call:
5591 -- P : parms := (parm, parm, parm);
5593 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5595 -- procedure _clean is
5598 -- Cancel_Task_Entry_Call (C);
5605 -- (<acceptor-task>, -- Acceptor
5606 -- <entry-index>, -- E
5607 -- P'Address, -- Uninterpreted_Data
5608 -- Asynchronous_Call, -- Mode
5609 -- B); -- Rendezvous_Successful
5616 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5619 -- when Abort_Signal => Abort_Undefer;
5626 -- <triggered-statements>
5630 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5631 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5635 -- P : parms := (parm, parm, parm);
5637 -- Call_Simple (acceptor-task, entry-index, P'Address);
5643 -- so the task at hand is to convert the latter expansion into the former
5645 -- If the trigger is a protected entry call, the select is implemented
5646 -- with Protected_Entry_Call:
5649 -- P : E1_Params := (param, param, param);
5650 -- Bnn : Communications_Block;
5655 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5657 -- procedure _clean is
5660 -- if Enqueued (Bnn) then
5661 -- Cancel_Protected_Entry_Call (Bnn);
5668 -- Protected_Entry_Call
5669 -- (po._object'Access, -- Object
5670 -- <entry index>, -- E
5671 -- P'Address, -- Uninterpreted_Data
5672 -- Asynchronous_Call, -- Mode
5675 -- if Enqueued (Bnn) then
5679 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5682 -- when Abort_Signal => Abort_Undefer;
5685 -- if not Cancelled (Bnn) then
5686 -- <triggered-statements>
5690 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5694 -- P : E1_Params := (param, param, param);
5695 -- Bnn : Communications_Block;
5698 -- Protected_Entry_Call
5699 -- (po._object'Access, -- Object
5700 -- <entry index>, -- E
5701 -- P'Address, -- Uninterpreted_Data
5702 -- Simple_Call, -- Mode
5709 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5713 -- B : Boolean := False;
5714 -- Bnn : Communication_Block;
5715 -- C : Ada.Tags.Prim_Op_Kind;
5716 -- D : System.Storage_Elements.Dummy_Communication_Block;
5717 -- K : Ada.Tags.Tagged_Kind :=
5718 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5719 -- P : Parameters := (Param1 .. ParamN);
5724 -- if K = Ada.Tags.TK_Limited_Tagged then
5725 -- <dispatching-call>;
5726 -- <triggering-statements>;
5730 -- Ada.Tags.Get_Offset_Index
5731 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5733 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5735 -- if C = POK_Protected_Entry then
5737 -- procedure _clean is
5739 -- if Enqueued (Bnn) then
5740 -- Cancel_Protected_Entry_Call (Bnn);
5746 -- _Disp_Asynchronous_Select
5747 -- (<object>, S, P'Address, D, B);
5748 -- Bnn := Communication_Block (D);
5750 -- Param1 := P.Param1;
5752 -- ParamN := P.ParamN;
5754 -- if Enqueued (Bnn) then
5755 -- <abortable-statements>
5758 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5761 -- when Abort_Signal => Abort_Undefer;
5764 -- if not Cancelled (Bnn) then
5765 -- <triggering-statements>
5768 -- elsif C = POK_Task_Entry then
5770 -- procedure _clean is
5772 -- Cancel_Task_Entry_Call (U);
5778 -- _Disp_Asynchronous_Select
5779 -- (<object>, S, P'Address, D, B);
5780 -- Bnn := Communication_Bloc (D);
5782 -- Param1 := P.Param1;
5784 -- ParamN := P.ParamN;
5789 -- <abortable-statements>
5791 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5794 -- when Abort_Signal => Abort_Undefer;
5798 -- <triggering-statements>
5803 -- <dispatching-call>;
5804 -- <triggering-statements>
5809 -- The job is to convert this to the asynchronous form
5811 -- If the trigger is a delay statement, it will have been expanded into a
5812 -- call to one of the GNARL delay procedures. This routine will convert
5813 -- this into a protected entry call on a delay object and then continue
5814 -- processing as for a protected entry call trigger. This requires
5815 -- declaring a Delay_Block object and adding a pointer to this object to
5816 -- the parameter list of the delay procedure to form the parameter list of
5817 -- the entry call. This object is used by the runtime to queue the delay
5820 -- For a description of the use of P and the assignments after the call,
5821 -- see Expand_N_Entry_Call_Statement.
5823 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5824 Loc : constant Source_Ptr := Sloc (N);
5825 Abrt : constant Node_Id := Abortable_Part (N);
5826 Astats : constant List_Id := Statements (Abrt);
5827 Trig : constant Node_Id := Triggering_Alternative (N);
5828 Tstats : constant List_Id := Statements (Trig);
5830 Abort_Block_Ent : Entity_Id;
5831 Abortable_Block : Node_Id;
5833 Blk_Ent : Entity_Id;
5834 Blk_Typ : Entity_Id;
5836 Call_Ent : Entity_Id;
5837 Cancel_Param : Entity_Id;
5838 Cleanup_Block : Node_Id;
5839 Cleanup_Block_Ent : Entity_Id;
5840 Cleanup_Stmts : List_Id;
5841 Conc_Typ_Stmts : List_Id;
5843 Dblock_Ent : Entity_Id;
5848 Enqueue_Call : Node_Id;
5851 Handler_Stmt : Node_Id;
5853 Lim_Typ_Stmts : List_Id;
5859 ProtE_Stmts : List_Id;
5860 ProtP_Stmts : List_Id;
5863 TaskE_Stmts : List_Id;
5865 B : Entity_Id; -- Call status flag
5866 Bnn : Entity_Id; -- Communication block
5867 C : Entity_Id; -- Call kind
5868 K : Entity_Id; -- Tagged kind
5869 P : Entity_Id; -- Parameter block
5870 S : Entity_Id; -- Primitive operation slot
5871 T : Entity_Id; -- Additional status flag
5874 Process_Statements_For_Controlled_Objects (Trig);
5875 Process_Statements_For_Controlled_Objects (Abrt);
5877 Blk_Ent := Make_Temporary (Loc, 'A');
5878 Ecall := Triggering_Statement (Trig);
5880 -- The arguments in the call may require dynamic allocation, and the
5881 -- call statement may have been transformed into a block. The block
5882 -- may contain additional declarations for internal entities, and the
5883 -- original call is found by sequential search.
5885 if Nkind (Ecall) = N_Block_Statement then
5886 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5887 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5888 N_Entry_Call_Statement)
5894 -- This is either a dispatching call or a delay statement used as a
5895 -- trigger which was expanded into a procedure call.
5897 if Nkind (Ecall) = N_Procedure_Call_Statement then
5898 if Ada_Version >= Ada_2005
5900 (No (Original_Node (Ecall))
5901 or else not Nkind_In (Original_Node (Ecall),
5902 N_Delay_Relative_Statement,
5903 N_Delay_Until_Statement))
5905 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5910 -- Call status flag processing, generate:
5911 -- B : Boolean := False;
5913 B := Build_B (Loc, Decls);
5915 -- Communication block processing, generate:
5916 -- Bnn : Communication_Block;
5918 Bnn := Make_Temporary (Loc, 'B');
5920 Make_Object_Declaration (Loc,
5921 Defining_Identifier => Bnn,
5922 Object_Definition =>
5923 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5925 -- Call kind processing, generate:
5926 -- C : Ada.Tags.Prim_Op_Kind;
5928 C := Build_C (Loc, Decls);
5930 -- Tagged kind processing, generate:
5931 -- K : Ada.Tags.Tagged_Kind :=
5932 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5934 -- Dummy communication block, generate:
5935 -- D : Dummy_Communication_Block;
5938 Make_Object_Declaration (Loc,
5939 Defining_Identifier =>
5940 Make_Defining_Identifier (Loc, Name_uD),
5941 Object_Definition =>
5943 RTE (RE_Dummy_Communication_Block), Loc)));
5945 K := Build_K (Loc, Decls, Obj);
5947 -- Parameter block processing
5949 Blk_Typ := Build_Parameter_Block
5950 (Loc, Actuals, Formals, Decls);
5951 P := Parameter_Block_Pack
5952 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5954 -- Dispatch table slot processing, generate:
5957 S := Build_S (Loc, Decls);
5959 -- Additional status flag processing, generate:
5962 T := Make_Temporary (Loc, 'T');
5964 Make_Object_Declaration (Loc,
5965 Defining_Identifier => T,
5966 Object_Definition =>
5967 New_Reference_To (Standard_Boolean, Loc)));
5969 ------------------------------
5970 -- Protected entry handling --
5971 ------------------------------
5974 -- Param1 := P.Param1;
5976 -- ParamN := P.ParamN;
5978 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5981 -- Bnn := Communication_Block (D);
5983 Prepend_To (Cleanup_Stmts,
5984 Make_Assignment_Statement (Loc,
5986 New_Reference_To (Bnn, Loc),
5988 Make_Unchecked_Type_Conversion (Loc,
5990 New_Reference_To (RTE (RE_Communication_Block), Loc),
5991 Expression => Make_Identifier (Loc, Name_uD))));
5994 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5996 Prepend_To (Cleanup_Stmts,
5997 Make_Procedure_Call_Statement (Loc,
6000 Find_Prim_Op (Etype (Etype (Obj)),
6001 Name_uDisp_Asynchronous_Select),
6003 Parameter_Associations =>
6005 New_Copy_Tree (Obj), -- <object>
6006 New_Reference_To (S, Loc), -- S
6007 Make_Attribute_Reference (Loc, -- P'Address
6009 New_Reference_To (P, Loc),
6012 Make_Identifier (Loc, Name_uD), -- D
6013 New_Reference_To (B, Loc)))); -- B
6016 -- if Enqueued (Bnn) then
6017 -- <abortable-statements>
6020 Append_To (Cleanup_Stmts,
6021 Make_If_Statement (Loc,
6023 Make_Function_Call (Loc,
6025 New_Reference_To (RTE (RE_Enqueued), Loc),
6026 Parameter_Associations =>
6028 New_Reference_To (Bnn, Loc))),
6031 New_Copy_List_Tree (Astats)));
6033 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6034 -- will then generate a _clean for the communication block Bnn.
6038 -- procedure _clean is
6040 -- if Enqueued (Bnn) then
6041 -- Cancel_Protected_Entry_Call (Bnn);
6050 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6052 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6054 -- Wrap the cleanup block in an exception handling block
6060 -- when Abort_Signal => Abort_Undefer;
6063 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6066 Make_Implicit_Label_Declaration (Loc,
6067 Defining_Identifier =>
6071 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6074 -- if not Cancelled (Bnn) then
6075 -- <triggering-statements>
6078 Append_To (ProtE_Stmts,
6079 Make_If_Statement (Loc,
6083 Make_Function_Call (Loc,
6085 New_Reference_To (RTE (RE_Cancelled), Loc),
6086 Parameter_Associations =>
6088 New_Reference_To (Bnn, Loc)))),
6091 New_Copy_List_Tree (Tstats)));
6093 -------------------------
6094 -- Task entry handling --
6095 -------------------------
6098 -- Param1 := P.Param1;
6100 -- ParamN := P.ParamN;
6102 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6105 -- Bnn := Communication_Block (D);
6107 Append_To (TaskE_Stmts,
6108 Make_Assignment_Statement (Loc,
6110 New_Reference_To (Bnn, Loc),
6112 Make_Unchecked_Type_Conversion (Loc,
6114 New_Reference_To (RTE (RE_Communication_Block), Loc),
6115 Expression => Make_Identifier (Loc, Name_uD))));
6118 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6120 Prepend_To (TaskE_Stmts,
6121 Make_Procedure_Call_Statement (Loc,
6124 Find_Prim_Op (Etype (Etype (Obj)),
6125 Name_uDisp_Asynchronous_Select),
6127 Parameter_Associations =>
6129 New_Copy_Tree (Obj), -- <object>
6130 New_Reference_To (S, Loc), -- S
6131 Make_Attribute_Reference (Loc, -- P'Address
6133 New_Reference_To (P, Loc),
6136 Make_Identifier (Loc, Name_uD), -- D
6137 New_Reference_To (B, Loc)))); -- B
6142 Prepend_To (TaskE_Stmts,
6143 Make_Procedure_Call_Statement (Loc,
6145 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6146 Parameter_Associations =>
6151 -- <abortable-statements>
6153 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6155 Prepend_To (Cleanup_Stmts,
6156 Make_Procedure_Call_Statement (Loc,
6158 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6159 Parameter_Associations =>
6162 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6163 -- will generate a _clean for the additional status flag.
6167 -- procedure _clean is
6169 -- Cancel_Task_Entry_Call (U);
6177 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6179 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6181 -- Wrap the cleanup block in an exception handling block
6187 -- when Abort_Signal => Abort_Undefer;
6190 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6192 Append_To (TaskE_Stmts,
6193 Make_Implicit_Label_Declaration (Loc,
6194 Defining_Identifier => Abort_Block_Ent));
6196 Append_To (TaskE_Stmts,
6198 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6202 -- <triggering-statements>
6205 Append_To (TaskE_Stmts,
6206 Make_If_Statement (Loc,
6210 New_Reference_To (T, Loc)),
6213 New_Copy_List_Tree (Tstats)));
6215 ----------------------------------
6216 -- Protected procedure handling --
6217 ----------------------------------
6220 -- <dispatching-call>;
6221 -- <triggering-statements>
6223 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6224 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6227 -- S := Ada.Tags.Get_Offset_Index
6228 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6231 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6234 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6236 Append_To (Conc_Typ_Stmts,
6237 Make_Procedure_Call_Statement (Loc,
6240 Find_Prim_Op (Etype (Etype (Obj)),
6241 Name_uDisp_Get_Prim_Op_Kind),
6243 Parameter_Associations =>
6245 New_Copy_Tree (Obj),
6246 New_Reference_To (S, Loc),
6247 New_Reference_To (C, Loc))));
6250 -- if C = POK_Procedure_Entry then
6252 -- elsif C = POK_Task_Entry then
6258 Append_To (Conc_Typ_Stmts,
6259 Make_If_Statement (Loc,
6263 New_Reference_To (C, Loc),
6265 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6272 Make_Elsif_Part (Loc,
6276 New_Reference_To (C, Loc),
6278 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6287 -- <dispatching-call>;
6288 -- <triggering-statements>
6290 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6291 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6294 -- if K = Ada.Tags.TK_Limited_Tagged then
6301 Make_If_Statement (Loc,
6305 New_Reference_To (K, Loc),
6307 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6316 Make_Block_Statement (Loc,
6319 Handled_Statement_Sequence =>
6320 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6325 -- Delay triggering statement processing
6328 -- Add a Delay_Block object to the parameter list of the delay
6329 -- procedure to form the parameter list of the Wait entry call.
6331 Dblock_Ent := Make_Temporary (Loc, 'D');
6333 Pdef := Entity (Name (Ecall));
6335 if Is_RTE (Pdef, RO_CA_Delay_For) then
6337 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6339 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6341 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6343 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6344 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6347 Append_To (Parameter_Associations (Ecall),
6348 Make_Attribute_Reference (Loc,
6349 Prefix => New_Reference_To (Dblock_Ent, Loc),
6350 Attribute_Name => Name_Unchecked_Access));
6352 -- Create the inner block to protect the abortable part
6354 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6357 Make_Procedure_Call_Statement (Loc,
6358 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6361 Make_Block_Statement (Loc,
6362 Identifier => New_Reference_To (Blk_Ent, Loc),
6363 Handled_Statement_Sequence =>
6364 Make_Handled_Sequence_Of_Statements (Loc,
6365 Statements => Astats),
6366 Has_Created_Identifier => True,
6367 Is_Asynchronous_Call_Block => True);
6369 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6372 Make_Implicit_If_Statement (N,
6373 Condition => Make_Function_Call (Loc,
6374 Name => Enqueue_Call,
6375 Parameter_Associations => Parameter_Associations (Ecall)),
6377 New_List (Make_Block_Statement (Loc,
6378 Handled_Statement_Sequence =>
6379 Make_Handled_Sequence_Of_Statements (Loc,
6380 Statements => New_List (
6381 Make_Implicit_Label_Declaration (Loc,
6382 Defining_Identifier => Blk_Ent,
6383 Label_Construct => Abortable_Block),
6385 Exception_Handlers => Hdle)))));
6387 Stmts := New_List (Ecall);
6389 -- Construct statement sequence for new block
6392 Make_Implicit_If_Statement (N,
6393 Condition => Make_Function_Call (Loc,
6394 Name => New_Reference_To (
6395 RTE (RE_Timed_Out), Loc),
6396 Parameter_Associations => New_List (
6397 Make_Attribute_Reference (Loc,
6398 Prefix => New_Reference_To (Dblock_Ent, Loc),
6399 Attribute_Name => Name_Unchecked_Access))),
6400 Then_Statements => Tstats));
6402 -- The result is the new block
6404 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6407 Make_Block_Statement (Loc,
6408 Declarations => New_List (
6409 Make_Object_Declaration (Loc,
6410 Defining_Identifier => Dblock_Ent,
6411 Aliased_Present => True,
6412 Object_Definition => New_Reference_To (
6413 RTE (RE_Delay_Block), Loc))),
6415 Handled_Statement_Sequence =>
6416 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6426 Extract_Entry (Ecall, Concval, Ename, Index);
6427 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6429 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6430 Decls := Declarations (Ecall);
6432 if Is_Protected_Type (Etype (Concval)) then
6434 -- Get the declarations of the block expanded from the entry call
6436 Decl := First (Decls);
6437 while Present (Decl)
6439 (Nkind (Decl) /= N_Object_Declaration
6440 or else not Is_RTE (Etype (Object_Definition (Decl)),
6441 RE_Communication_Block))
6446 pragma Assert (Present (Decl));
6447 Cancel_Param := Defining_Identifier (Decl);
6449 -- Change the mode of the Protected_Entry_Call call
6451 -- Protected_Entry_Call (
6452 -- Object => po._object'Access,
6453 -- E => <entry index>;
6454 -- Uninterpreted_Data => P'Address;
6455 -- Mode => Asynchronous_Call;
6458 Stmt := First (Stmts);
6460 -- Skip assignments to temporaries created for in-out parameters
6462 -- This makes unwarranted assumptions about the shape of the expanded
6463 -- tree for the call, and should be cleaned up ???
6465 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6471 Param := First (Parameter_Associations (Call));
6472 while Present (Param)
6473 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6478 pragma Assert (Present (Param));
6479 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6482 -- Append an if statement to execute the abortable part
6485 -- if Enqueued (Bnn) then
6488 Make_Implicit_If_Statement (N,
6489 Condition => Make_Function_Call (Loc,
6490 Name => New_Reference_To (
6491 RTE (RE_Enqueued), Loc),
6492 Parameter_Associations => New_List (
6493 New_Reference_To (Cancel_Param, Loc))),
6494 Then_Statements => Astats));
6497 Make_Block_Statement (Loc,
6498 Identifier => New_Reference_To (Blk_Ent, Loc),
6499 Handled_Statement_Sequence =>
6500 Make_Handled_Sequence_Of_Statements (Loc,
6501 Statements => Stmts),
6502 Has_Created_Identifier => True,
6503 Is_Asynchronous_Call_Block => True);
6505 -- For the VM call Update_Exception instead of Abort_Undefer.
6506 -- See 4jexcept.ads for an explanation.
6508 if VM_Target = No_VM then
6509 if Exception_Mechanism = Back_End_Exceptions then
6510 -- Aborts are not deferred at beginning of exception handlers
6512 Handler_Stmt := Make_Null_Statement (Loc);
6514 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6515 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6516 Parameter_Associations => No_List);
6519 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6520 Name => New_Reference_To (RTE (RE_Update_Exception), Loc),
6521 Parameter_Associations => New_List (Make_Function_Call (Loc,
6522 Name => New_Occurrence_Of (RTE (RE_Current_Target_Exception),
6527 Make_Block_Statement (Loc,
6528 Handled_Statement_Sequence =>
6529 Make_Handled_Sequence_Of_Statements (Loc,
6530 Statements => New_List (
6531 Make_Implicit_Label_Declaration (Loc,
6532 Defining_Identifier => Blk_Ent,
6533 Label_Construct => Abortable_Block),
6538 Exception_Handlers => New_List (
6539 Make_Implicit_Exception_Handler (Loc,
6541 -- when Abort_Signal =>
6542 -- Abort_Undefer.all;
6544 Exception_Choices =>
6545 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6546 Statements => New_List (Handler_Stmt))))),
6548 -- if not Cancelled (Bnn) then
6549 -- triggered statements
6552 Make_Implicit_If_Statement (N,
6553 Condition => Make_Op_Not (Loc,
6555 Make_Function_Call (Loc,
6556 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6557 Parameter_Associations => New_List (
6558 New_Occurrence_Of (Cancel_Param, Loc)))),
6559 Then_Statements => Tstats));
6561 -- Asynchronous task entry call
6568 B := Make_Defining_Identifier (Loc, Name_uB);
6570 -- Insert declaration of B in declarations of existing block
6573 Make_Object_Declaration (Loc,
6574 Defining_Identifier => B,
6575 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6577 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6579 -- Insert declaration of C in declarations of existing block
6582 Make_Object_Declaration (Loc,
6583 Defining_Identifier => Cancel_Param,
6584 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6586 -- Remove and save the call to Call_Simple
6588 Stmt := First (Stmts);
6590 -- Skip assignments to temporaries created for in-out parameters.
6591 -- This makes unwarranted assumptions about the shape of the expanded
6592 -- tree for the call, and should be cleaned up ???
6594 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6600 -- Create the inner block to protect the abortable part
6602 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6605 Make_Procedure_Call_Statement (Loc,
6606 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6609 Make_Block_Statement (Loc,
6610 Identifier => New_Reference_To (Blk_Ent, Loc),
6611 Handled_Statement_Sequence =>
6612 Make_Handled_Sequence_Of_Statements (Loc,
6613 Statements => Astats),
6614 Has_Created_Identifier => True,
6615 Is_Asynchronous_Call_Block => True);
6618 Make_Block_Statement (Loc,
6619 Handled_Statement_Sequence =>
6620 Make_Handled_Sequence_Of_Statements (Loc,
6621 Statements => New_List (
6622 Make_Implicit_Label_Declaration (Loc,
6623 Defining_Identifier =>
6628 Exception_Handlers => Hdle)));
6630 -- Create new call statement
6632 Params := Parameter_Associations (Call);
6635 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6637 New_Reference_To (B, Loc));
6640 Make_Procedure_Call_Statement (Loc,
6642 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6643 Parameter_Associations => Params));
6645 -- Construct statement sequence for new block
6648 Make_Implicit_If_Statement (N,
6651 New_Reference_To (Cancel_Param, Loc)),
6652 Then_Statements => Tstats));
6654 -- Protected the call against abort
6657 Make_Procedure_Call_Statement (Loc,
6658 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6659 Parameter_Associations => Empty_List));
6662 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6664 -- The result is the new block
6667 Make_Block_Statement (Loc,
6668 Declarations => Decls,
6669 Handled_Statement_Sequence =>
6670 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6673 end Expand_N_Asynchronous_Select;
6675 -------------------------------------
6676 -- Expand_N_Conditional_Entry_Call --
6677 -------------------------------------
6679 -- The conditional task entry call is converted to a call to
6684 -- P : parms := (parm, parm, parm);
6688 -- (<acceptor-task>, -- Acceptor
6689 -- <entry-index>, -- E
6690 -- P'Address, -- Uninterpreted_Data
6691 -- Conditional_Call, -- Mode
6692 -- B); -- Rendezvous_Successful
6697 -- normal-statements
6703 -- For a description of the use of P and the assignments after the call,
6704 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6705 -- conditional entry call has already been expanded (by the Expand_N_Entry
6706 -- _Call_Statement procedure) as follows:
6709 -- P : parms := (parm, parm, parm);
6711 -- ... info for in-out parameters
6712 -- Call_Simple (acceptor-task, entry-index, P'Address);
6718 -- so the task at hand is to convert the latter expansion into the former
6720 -- The conditional protected entry call is converted to a call to
6721 -- Protected_Entry_Call:
6724 -- P : parms := (parm, parm, parm);
6725 -- Bnn : Communications_Block;
6728 -- Protected_Entry_Call
6729 -- (po._object'Access, -- Object
6730 -- <entry index>, -- E
6731 -- P'Address, -- Uninterpreted_Data
6732 -- Conditional_Call, -- Mode
6737 -- if Cancelled (Bnn) then
6740 -- normal-statements
6744 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6748 -- B : Boolean := False;
6749 -- C : Ada.Tags.Prim_Op_Kind;
6750 -- K : Ada.Tags.Tagged_Kind :=
6751 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6752 -- P : Parameters := (Param1 .. ParamN);
6756 -- if K = Ada.Tags.TK_Limited_Tagged then
6757 -- <dispatching-call>;
6758 -- <triggering-statements>
6762 -- Ada.Tags.Get_Offset_Index
6763 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6765 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6767 -- if C = POK_Protected_Entry
6768 -- or else C = POK_Task_Entry
6770 -- Param1 := P.Param1;
6772 -- ParamN := P.ParamN;
6776 -- if C = POK_Procedure
6777 -- or else C = POK_Protected_Procedure
6778 -- or else C = POK_Task_Procedure
6780 -- <dispatching-call>;
6783 -- <triggering-statements>
6785 -- <else-statements>
6790 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6791 Loc : constant Source_Ptr := Sloc (N);
6792 Alt : constant Node_Id := Entry_Call_Alternative (N);
6793 Blk : Node_Id := Entry_Call_Statement (Alt);
6796 Blk_Typ : Entity_Id;
6798 Call_Ent : Entity_Id;
6799 Conc_Typ_Stmts : List_Id;
6803 Lim_Typ_Stmts : List_Id;
6810 Transient_Blk : Node_Id;
6813 B : Entity_Id; -- Call status flag
6814 C : Entity_Id; -- Call kind
6815 K : Entity_Id; -- Tagged kind
6816 P : Entity_Id; -- Parameter block
6817 S : Entity_Id; -- Primitive operation slot
6820 Process_Statements_For_Controlled_Objects (N);
6822 if Ada_Version >= Ada_2005
6823 and then Nkind (Blk) = N_Procedure_Call_Statement
6825 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6830 -- Call status flag processing, generate:
6831 -- B : Boolean := False;
6833 B := Build_B (Loc, Decls);
6835 -- Call kind processing, generate:
6836 -- C : Ada.Tags.Prim_Op_Kind;
6838 C := Build_C (Loc, Decls);
6840 -- Tagged kind processing, generate:
6841 -- K : Ada.Tags.Tagged_Kind :=
6842 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6844 K := Build_K (Loc, Decls, Obj);
6846 -- Parameter block processing
6848 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6849 P := Parameter_Block_Pack
6850 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6852 -- Dispatch table slot processing, generate:
6855 S := Build_S (Loc, Decls);
6858 -- S := Ada.Tags.Get_Offset_Index
6859 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6862 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6865 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6867 Append_To (Conc_Typ_Stmts,
6868 Make_Procedure_Call_Statement (Loc,
6871 Find_Prim_Op (Etype (Etype (Obj)),
6872 Name_uDisp_Conditional_Select),
6874 Parameter_Associations =>
6876 New_Copy_Tree (Obj), -- <object>
6877 New_Reference_To (S, Loc), -- S
6878 Make_Attribute_Reference (Loc, -- P'Address
6880 New_Reference_To (P, Loc),
6883 New_Reference_To (C, Loc), -- C
6884 New_Reference_To (B, Loc)))); -- B
6887 -- if C = POK_Protected_Entry
6888 -- or else C = POK_Task_Entry
6890 -- Param1 := P.Param1;
6892 -- ParamN := P.ParamN;
6895 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6897 -- Generate the if statement only when the packed parameters need
6898 -- explicit assignments to their corresponding actuals.
6900 if Present (Unpack) then
6901 Append_To (Conc_Typ_Stmts,
6902 Make_If_Statement (Loc,
6909 New_Reference_To (C, Loc),
6911 New_Reference_To (RTE (
6912 RE_POK_Protected_Entry), Loc)),
6916 New_Reference_To (C, Loc),
6918 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6926 -- if C = POK_Procedure
6927 -- or else C = POK_Protected_Procedure
6928 -- or else C = POK_Task_Procedure
6930 -- <dispatching-call>
6932 -- <normal-statements>
6934 -- <else-statements>
6937 N_Stats := New_Copy_List_Tree (Statements (Alt));
6939 Prepend_To (N_Stats,
6940 Make_If_Statement (Loc,
6946 New_Reference_To (C, Loc),
6948 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6955 New_Reference_To (C, Loc),
6957 New_Reference_To (RTE (
6958 RE_POK_Protected_Procedure), Loc)),
6963 New_Reference_To (C, Loc),
6965 New_Reference_To (RTE (
6966 RE_POK_Task_Procedure), Loc)))),
6971 Append_To (Conc_Typ_Stmts,
6972 Make_If_Statement (Loc,
6973 Condition => New_Reference_To (B, Loc),
6974 Then_Statements => N_Stats,
6975 Else_Statements => Else_Statements (N)));
6978 -- <dispatching-call>;
6979 -- <triggering-statements>
6981 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6982 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6985 -- if K = Ada.Tags.TK_Limited_Tagged then
6992 Make_If_Statement (Loc,
6996 New_Reference_To (K, Loc),
6998 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
7007 Make_Block_Statement (Loc,
7010 Handled_Statement_Sequence =>
7011 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7013 -- As described above, The entry alternative is transformed into a
7014 -- block that contains the gnulli call, and possibly assignment
7015 -- statements for in-out parameters. The gnulli call may itself be
7016 -- rewritten into a transient block if some unconstrained parameters
7017 -- require it. We need to retrieve the call to complete its parameter
7022 First_Real_Statement (Handled_Statement_Sequence (Blk));
7024 if Present (Transient_Blk)
7025 and then Nkind (Transient_Blk) = N_Block_Statement
7027 Blk := Transient_Blk;
7030 Stmts := Statements (Handled_Statement_Sequence (Blk));
7031 Stmt := First (Stmts);
7032 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7037 Params := Parameter_Associations (Call);
7039 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7041 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7043 Param := First (Params);
7044 while Present (Param)
7045 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7050 pragma Assert (Present (Param));
7051 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
7055 -- Find the Communication_Block parameter for the call to the
7056 -- Cancelled function.
7058 Decl := First (Declarations (Blk));
7059 while Present (Decl)
7060 and then not Is_RTE (Etype (Object_Definition (Decl)),
7061 RE_Communication_Block)
7066 -- Add an if statement to execute the else part if the call
7067 -- does not succeed (as indicated by the Cancelled predicate).
7070 Make_Implicit_If_Statement (N,
7071 Condition => Make_Function_Call (Loc,
7072 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
7073 Parameter_Associations => New_List (
7074 New_Reference_To (Defining_Identifier (Decl), Loc))),
7075 Then_Statements => Else_Statements (N),
7076 Else_Statements => Statements (Alt)));
7079 B := Make_Defining_Identifier (Loc, Name_uB);
7081 -- Insert declaration of B in declarations of existing block
7083 if No (Declarations (Blk)) then
7084 Set_Declarations (Blk, New_List);
7087 Prepend_To (Declarations (Blk),
7088 Make_Object_Declaration (Loc,
7089 Defining_Identifier => B,
7090 Object_Definition =>
7091 New_Reference_To (Standard_Boolean, Loc)));
7093 -- Create new call statement
7096 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7097 Append_To (Params, New_Reference_To (B, Loc));
7100 Make_Procedure_Call_Statement (Loc,
7101 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7102 Parameter_Associations => Params));
7104 -- Construct statement sequence for new block
7107 Make_Implicit_If_Statement (N,
7108 Condition => New_Reference_To (B, Loc),
7109 Then_Statements => Statements (Alt),
7110 Else_Statements => Else_Statements (N)));
7113 -- The result is the new block
7116 Make_Block_Statement (Loc,
7117 Declarations => Declarations (Blk),
7118 Handled_Statement_Sequence =>
7119 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7123 end Expand_N_Conditional_Entry_Call;
7125 ---------------------------------------
7126 -- Expand_N_Delay_Relative_Statement --
7127 ---------------------------------------
7129 -- Delay statement is implemented as a procedure call to Delay_For
7130 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7131 -- simple delays imposed by the use of Protected Objects.
7133 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7134 Loc : constant Source_Ptr := Sloc (N);
7137 Make_Procedure_Call_Statement (Loc,
7138 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7139 Parameter_Associations => New_List (Expression (N))));
7141 end Expand_N_Delay_Relative_Statement;
7143 ------------------------------------
7144 -- Expand_N_Delay_Until_Statement --
7145 ------------------------------------
7147 -- Delay Until statement is implemented as a procedure call to
7148 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7150 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7151 Loc : constant Source_Ptr := Sloc (N);
7155 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7156 Typ := RTE (RO_CA_Delay_Until);
7158 Typ := RTE (RO_RT_Delay_Until);
7162 Make_Procedure_Call_Statement (Loc,
7163 Name => New_Reference_To (Typ, Loc),
7164 Parameter_Associations => New_List (Expression (N))));
7167 end Expand_N_Delay_Until_Statement;
7169 -------------------------
7170 -- Expand_N_Entry_Body --
7171 -------------------------
7173 procedure Expand_N_Entry_Body (N : Node_Id) is
7175 -- Associate discriminals with the next protected operation body to be
7178 if Present (Next_Protected_Operation (N)) then
7179 Set_Discriminals (Parent (Current_Scope));
7181 end Expand_N_Entry_Body;
7183 -----------------------------------
7184 -- Expand_N_Entry_Call_Statement --
7185 -----------------------------------
7187 -- An entry call is expanded into GNARLI calls to implement a simple entry
7188 -- call (see Build_Simple_Entry_Call).
7190 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7196 if No_Run_Time_Mode then
7197 Error_Msg_CRT ("entry call", N);
7201 -- If this entry call is part of an asynchronous select, don't expand it
7202 -- here; it will be expanded with the select statement. Don't expand
7203 -- timed entry calls either, as they are translated into asynchronous
7206 -- ??? This whole approach is questionable; it may be better to go back
7207 -- to allowing the expansion to take place and then attempting to fix it
7208 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7209 -- whether the expanded call is on a task or protected entry.
7211 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7212 or else N /= Triggering_Statement (Parent (N)))
7213 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7214 or else N /= Entry_Call_Statement (Parent (N))
7215 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7217 Extract_Entry (N, Concval, Ename, Index);
7218 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7220 end Expand_N_Entry_Call_Statement;
7222 --------------------------------
7223 -- Expand_N_Entry_Declaration --
7224 --------------------------------
7226 -- If there are parameters, then first, each of the formals is marked by
7227 -- setting Is_Entry_Formal. Next a record type is built which is used to
7228 -- hold the parameter values. The name of this record type is entryP where
7229 -- entry is the name of the entry, with an additional corresponding access
7230 -- type called entryPA. The record type has matching components for each
7231 -- formal (the component names are the same as the formal names). For
7232 -- elementary types, the component type matches the formal type. For
7233 -- composite types, an access type is declared (with the name formalA)
7234 -- which designates the formal type, and the type of the component is this
7235 -- access type. Finally the Entry_Component of each formal is set to
7236 -- reference the corresponding record component.
7238 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7239 Loc : constant Source_Ptr := Sloc (N);
7240 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7241 Components : List_Id;
7244 Last_Decl : Node_Id;
7245 Component : Entity_Id;
7248 Rec_Ent : Entity_Id;
7249 Acc_Ent : Entity_Id;
7252 Formal := First_Formal (Entry_Ent);
7255 -- Most processing is done only if parameters are present
7257 if Present (Formal) then
7258 Components := New_List;
7260 -- Loop through formals
7262 while Present (Formal) loop
7263 Set_Is_Entry_Formal (Formal);
7265 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7266 Set_Entry_Component (Formal, Component);
7267 Set_Entry_Formal (Component, Formal);
7268 Ftype := Etype (Formal);
7270 -- Declare new access type and then append
7272 Ctype := Make_Temporary (Loc, 'A');
7275 Make_Full_Type_Declaration (Loc,
7276 Defining_Identifier => Ctype,
7278 Make_Access_To_Object_Definition (Loc,
7279 All_Present => True,
7280 Constant_Present => Ekind (Formal) = E_In_Parameter,
7281 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7283 Insert_After (Last_Decl, Decl);
7286 Append_To (Components,
7287 Make_Component_Declaration (Loc,
7288 Defining_Identifier => Component,
7289 Component_Definition =>
7290 Make_Component_Definition (Loc,
7291 Aliased_Present => False,
7292 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7294 Next_Formal_With_Extras (Formal);
7297 -- Create the Entry_Parameter_Record declaration
7299 Rec_Ent := Make_Temporary (Loc, 'P');
7302 Make_Full_Type_Declaration (Loc,
7303 Defining_Identifier => Rec_Ent,
7305 Make_Record_Definition (Loc,
7307 Make_Component_List (Loc,
7308 Component_Items => Components)));
7310 Insert_After (Last_Decl, Decl);
7313 -- Construct and link in the corresponding access type
7315 Acc_Ent := Make_Temporary (Loc, 'A');
7317 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7320 Make_Full_Type_Declaration (Loc,
7321 Defining_Identifier => Acc_Ent,
7323 Make_Access_To_Object_Definition (Loc,
7324 All_Present => True,
7325 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7327 Insert_After (Last_Decl, Decl);
7329 end Expand_N_Entry_Declaration;
7331 -----------------------------
7332 -- Expand_N_Protected_Body --
7333 -----------------------------
7335 -- Protected bodies are expanded to the completion of the subprograms
7336 -- created for the corresponding protected type. These are a protected and
7337 -- unprotected version of each protected subprogram in the object, a
7338 -- function to calculate each entry barrier, and a procedure to execute the
7339 -- sequence of statements of each protected entry body. For example, for
7340 -- protected type ptype:
7343 -- (O : System.Address;
7344 -- E : Protected_Entry_Index)
7347 -- <discriminant renamings>
7348 -- <private object renamings>
7350 -- return <barrier expression>;
7353 -- procedure pprocN (_object : in out poV;...) is
7354 -- <discriminant renamings>
7355 -- <private object renamings>
7357 -- <sequence of statements>
7360 -- procedure pprocP (_object : in out poV;...) is
7361 -- procedure _clean is
7364 -- ptypeS (_object, Pn);
7365 -- Unlock (_object._object'Access);
7366 -- Abort_Undefer.all;
7371 -- Lock (_object._object'Access);
7372 -- pprocN (_object;...);
7377 -- function pfuncN (_object : poV;...) return Return_Type is
7378 -- <discriminant renamings>
7379 -- <private object renamings>
7381 -- <sequence of statements>
7384 -- function pfuncP (_object : poV) return Return_Type is
7385 -- procedure _clean is
7387 -- Unlock (_object._object'Access);
7388 -- Abort_Undefer.all;
7393 -- Lock (_object._object'Access);
7394 -- return pfuncN (_object);
7401 -- (O : System.Address;
7402 -- P : System.Address;
7403 -- E : Protected_Entry_Index)
7405 -- <discriminant renamings>
7406 -- <private object renamings>
7407 -- type poVP is access poV;
7408 -- _Object : ptVP := ptVP!(O);
7412 -- <statement sequence>
7413 -- Complete_Entry_Body (_Object._Object);
7415 -- when all others =>
7416 -- Exceptional_Complete_Entry_Body (
7417 -- _Object._Object, Get_GNAT_Exception);
7421 -- The type poV is the record created for the protected type to hold
7422 -- the state of the protected object.
7424 procedure Expand_N_Protected_Body (N : Node_Id) is
7425 Loc : constant Source_Ptr := Sloc (N);
7426 Pid : constant Entity_Id := Corresponding_Spec (N);
7428 Current_Node : Node_Id;
7429 Disp_Op_Body : Node_Id;
7430 New_Op_Body : Node_Id;
7431 Num_Entries : Natural := 0;
7435 function Build_Dispatching_Subprogram_Body
7438 Prot_Bod : Node_Id) return Node_Id;
7439 -- Build a dispatching version of the protected subprogram body. The
7440 -- newly generated subprogram contains a call to the original protected
7441 -- body. The following code is generated:
7443 -- function <protected-function-name> (Param1 .. ParamN) return
7446 -- return <protected-function-name>P (Param1 .. ParamN);
7447 -- end <protected-function-name>;
7451 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7453 -- <protected-procedure-name>P (Param1 .. ParamN);
7454 -- end <protected-procedure-name>
7456 ---------------------------------------
7457 -- Build_Dispatching_Subprogram_Body --
7458 ---------------------------------------
7460 function Build_Dispatching_Subprogram_Body
7463 Prot_Bod : Node_Id) return Node_Id
7465 Loc : constant Source_Ptr := Sloc (N);
7472 -- Generate a specification without a letter suffix in order to
7473 -- override an interface function or procedure.
7475 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7477 -- The formal parameters become the actuals of the protected function
7478 -- or procedure call.
7480 Actuals := New_List;
7481 Formal := First (Parameter_Specifications (Spec));
7482 while Present (Formal) loop
7484 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7489 if Nkind (Spec) = N_Procedure_Specification then
7492 Make_Procedure_Call_Statement (Loc,
7494 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7495 Parameter_Associations => Actuals));
7497 pragma Assert (Nkind (Spec) = N_Function_Specification);
7501 Make_Simple_Return_Statement (Loc,
7503 Make_Function_Call (Loc,
7505 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7506 Parameter_Associations => Actuals)));
7510 Make_Subprogram_Body (Loc,
7511 Declarations => Empty_List,
7512 Specification => Spec,
7513 Handled_Statement_Sequence =>
7514 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7515 end Build_Dispatching_Subprogram_Body;
7517 -- Start of processing for Expand_N_Protected_Body
7520 if No_Run_Time_Mode then
7521 Error_Msg_CRT ("protected body", N);
7525 -- This is the proper body corresponding to a stub. The declarations
7526 -- must be inserted at the point of the stub, which in turn is in the
7527 -- declarative part of the parent unit.
7529 if Nkind (Parent (N)) = N_Subunit then
7530 Current_Node := Corresponding_Stub (Parent (N));
7535 Op_Body := First (Declarations (N));
7537 -- The protected body is replaced with the bodies of its
7538 -- protected operations, and the declarations for internal objects
7539 -- that may have been created for entry family bounds.
7541 Rewrite (N, Make_Null_Statement (Sloc (N)));
7544 while Present (Op_Body) loop
7545 case Nkind (Op_Body) is
7546 when N_Subprogram_Declaration =>
7549 when N_Subprogram_Body =>
7551 -- Do not create bodies for eliminated operations
7553 if not Is_Eliminated (Defining_Entity (Op_Body))
7554 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7557 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7559 Insert_After (Current_Node, New_Op_Body);
7560 Current_Node := New_Op_Body;
7561 Analyze (New_Op_Body);
7563 -- Build the corresponding protected operation. It may
7564 -- appear that this is needed only if this is a visible
7565 -- operation of the type, or if it is an interrupt handler,
7566 -- and this was the strategy used previously in GNAT.
7567 -- However, the operation may be exported through a 'Access
7568 -- to an external caller. This is the common idiom in code
7569 -- that uses the Ada 2005 Timing_Events package. As a result
7570 -- we need to produce the protected body for both visible
7571 -- and private operations, as well as operations that only
7572 -- have a body in the source, and for which we create a
7573 -- declaration in the protected body itself.
7575 if Present (Corresponding_Spec (Op_Body)) then
7577 Build_Protected_Subprogram_Body (
7578 Op_Body, Pid, Specification (New_Op_Body));
7580 Insert_After (Current_Node, New_Op_Body);
7581 Analyze (New_Op_Body);
7583 Current_Node := New_Op_Body;
7585 -- Generate an overriding primitive operation body for
7586 -- this subprogram if the protected type implements an
7589 if Ada_Version >= Ada_2005
7591 Present (Interfaces (Corresponding_Record_Type (Pid)))
7594 Build_Dispatching_Subprogram_Body
7595 (Op_Body, Pid, New_Op_Body);
7597 Insert_After (Current_Node, Disp_Op_Body);
7598 Analyze (Disp_Op_Body);
7600 Current_Node := Disp_Op_Body;
7605 when N_Entry_Body =>
7606 Op_Id := Defining_Identifier (Op_Body);
7607 Num_Entries := Num_Entries + 1;
7609 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7611 Insert_After (Current_Node, New_Op_Body);
7612 Current_Node := New_Op_Body;
7613 Analyze (New_Op_Body);
7615 when N_Implicit_Label_Declaration =>
7618 when N_Itype_Reference =>
7619 Insert_After (Current_Node, New_Copy (Op_Body));
7621 when N_Freeze_Entity =>
7622 New_Op_Body := New_Copy (Op_Body);
7624 if Present (Entity (Op_Body))
7625 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7627 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7630 Insert_After (Current_Node, New_Op_Body);
7631 Current_Node := New_Op_Body;
7632 Analyze (New_Op_Body);
7635 New_Op_Body := New_Copy (Op_Body);
7636 Insert_After (Current_Node, New_Op_Body);
7637 Current_Node := New_Op_Body;
7638 Analyze (New_Op_Body);
7640 when N_Object_Declaration =>
7641 pragma Assert (not Comes_From_Source (Op_Body));
7642 New_Op_Body := New_Copy (Op_Body);
7643 Insert_After (Current_Node, New_Op_Body);
7644 Current_Node := New_Op_Body;
7645 Analyze (New_Op_Body);
7648 raise Program_Error;
7655 -- Finally, create the body of the function that maps an entry index
7656 -- into the corresponding body index, except when there is no entry, or
7657 -- in a Ravenscar-like profile.
7659 if Corresponding_Runtime_Package (Pid) =
7660 System_Tasking_Protected_Objects_Entries
7662 New_Op_Body := Build_Find_Body_Index (Pid);
7663 Insert_After (Current_Node, New_Op_Body);
7664 Current_Node := New_Op_Body;
7665 Analyze (New_Op_Body);
7668 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7669 -- protected body. At this point all wrapper specs have been created,
7670 -- frozen and included in the dispatch table for the protected type.
7672 if Ada_Version >= Ada_2005 then
7673 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7675 end Expand_N_Protected_Body;
7677 -----------------------------------------
7678 -- Expand_N_Protected_Type_Declaration --
7679 -----------------------------------------
7681 -- First we create a corresponding record type declaration used to
7682 -- represent values of this protected type.
7683 -- The general form of this type declaration is
7685 -- type poV (discriminants) is record
7686 -- _Object : aliased <kind>Protection
7687 -- [(<entry count> [, <handler count>])];
7688 -- [entry_family : array (bounds) of Void;]
7689 -- <private data fields>
7692 -- The discriminants are present only if the corresponding protected type
7693 -- has discriminants, and they exactly mirror the protected type
7694 -- discriminants. The private data fields similarly mirror the private
7695 -- declarations of the protected type.
7697 -- The Object field is always present. It contains RTS specific data used
7698 -- to control the protected object. It is declared as Aliased so that it
7699 -- can be passed as a pointer to the RTS. This allows the protected record
7700 -- to be referenced within RTS data structures. An appropriate Protection
7701 -- type and discriminant are generated.
7703 -- The Service field is present for protected objects with entries. It
7704 -- contains sufficient information to allow the entry service procedure for
7705 -- this object to be called when the object is not known till runtime.
7707 -- One entry_family component is present for each entry family in the
7708 -- task definition (see Expand_N_Task_Type_Declaration).
7710 -- When a protected object is declared, an instance of the protected type
7711 -- value record is created. The elaboration of this declaration creates the
7712 -- correct bounds for the entry families, and also evaluates the priority
7713 -- expression if needed. The initialization routine for the protected type
7714 -- itself then calls Initialize_Protection with appropriate parameters to
7715 -- initialize the value of the Task_Id field. Install_Handlers may be also
7716 -- called if a pragma Attach_Handler applies.
7718 -- Note: this record is passed to the subprograms created by the expansion
7719 -- of protected subprograms and entries. It is an in parameter to protected
7720 -- functions and an in out parameter to procedures and entry bodies. The
7721 -- Entity_Id for this created record type is placed in the
7722 -- Corresponding_Record_Type field of the associated protected type entity.
7724 -- Next we create a procedure specifications for protected subprograms and
7725 -- entry bodies. For each protected subprograms two subprograms are
7726 -- created, an unprotected and a protected version. The unprotected version
7727 -- is called from within other operations of the same protected object.
7729 -- We also build the call to register the procedure if a pragma
7730 -- Interrupt_Handler applies.
7732 -- A single subprogram is created to service all entry bodies; it has an
7733 -- additional boolean out parameter indicating that the previous entry call
7734 -- made by the current task was serviced immediately, i.e. not by proxy.
7735 -- The O parameter contains a pointer to a record object of the type
7736 -- described above. An untyped interface is used here to allow this
7737 -- procedure to be called in places where the type of the object to be
7738 -- serviced is not known. This must be done, for example, when a call that
7739 -- may have been requeued is cancelled; the corresponding object must be
7740 -- serviced, but which object that is not known till runtime.
7743 -- (O : System.Address; P : out Boolean);
7744 -- procedure pprocN (_object : in out poV);
7745 -- procedure pproc (_object : in out poV);
7746 -- function pfuncN (_object : poV);
7747 -- function pfunc (_object : poV);
7750 -- Note that this must come after the record type declaration, since
7751 -- the specs refer to this type.
7753 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7754 Loc : constant Source_Ptr := Sloc (N);
7755 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7757 Pdef : constant Node_Id := Protected_Definition (N);
7758 -- This contains two lists; one for visible and one for private decls
7762 Discr_Map : constant Elist_Id := New_Elmt_List;
7766 Comp_Id : Entity_Id;
7768 Current_Node : Node_Id := N;
7769 Bdef : Entity_Id := Empty; -- avoid uninit warning
7770 Edef : Entity_Id := Empty; -- avoid uninit warning
7771 Entries_Aggr : Node_Id;
7772 Body_Id : Entity_Id;
7775 Object_Comp : Node_Id;
7777 procedure Check_Inlining (Subp : Entity_Id);
7778 -- If the original operation has a pragma Inline, propagate the flag
7779 -- to the internal body, for possible inlining later on. The source
7780 -- operation is invisible to the back-end and is never actually called.
7782 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7783 -- When compiling under the Ravenscar profile, private components must
7784 -- have a static size, or else a protected object will require heap
7785 -- allocation, violating the corresponding restriction. It is preferable
7786 -- to make this check here, because it provides a better error message
7787 -- than the back-end, which refers to the object as a whole.
7789 procedure Register_Handler;
7790 -- For a protected operation that is an interrupt handler, add the
7791 -- freeze action that will register it as such.
7793 --------------------
7794 -- Check_Inlining --
7795 --------------------
7797 procedure Check_Inlining (Subp : Entity_Id) is
7799 if Is_Inlined (Subp) then
7800 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7801 Set_Is_Inlined (Subp, False);
7805 ---------------------------------
7806 -- Check_Static_Component_Size --
7807 ---------------------------------
7809 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7810 Typ : constant Entity_Id := Etype (Comp);
7814 if Is_Scalar_Type (Typ) then
7817 elsif Is_Array_Type (Typ) then
7818 return Compile_Time_Known_Bounds (Typ);
7820 elsif Is_Record_Type (Typ) then
7821 C := First_Component (Typ);
7822 while Present (C) loop
7823 if not Static_Component_Size (C) then
7832 -- Any other types will be checked by the back-end
7837 end Static_Component_Size;
7839 ----------------------
7840 -- Register_Handler --
7841 ----------------------
7843 procedure Register_Handler is
7845 -- All semantic checks already done in Sem_Prag
7847 Prot_Proc : constant Entity_Id :=
7849 (Specification (Current_Node));
7851 Proc_Address : constant Node_Id :=
7852 Make_Attribute_Reference (Loc,
7853 Prefix => New_Reference_To (Prot_Proc, Loc),
7854 Attribute_Name => Name_Address);
7856 RTS_Call : constant Entity_Id :=
7857 Make_Procedure_Call_Statement (Loc,
7860 RTE (RE_Register_Interrupt_Handler), Loc),
7861 Parameter_Associations =>
7862 New_List (Proc_Address));
7864 Append_Freeze_Action (Prot_Proc, RTS_Call);
7865 end Register_Handler;
7867 -- Start of processing for Expand_N_Protected_Type_Declaration
7870 if Present (Corresponding_Record_Type (Prot_Typ)) then
7873 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7876 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7878 Qualify_Entity_Names (N);
7880 -- If the type has discriminants, their occurrences in the declaration
7881 -- have been replaced by the corresponding discriminals. For components
7882 -- that are constrained by discriminants, their homologues in the
7883 -- corresponding record type must refer to the discriminants of that
7884 -- record, so we must apply a new renaming to subtypes_indications:
7886 -- protected discriminant => discriminal => record discriminant
7888 -- This replacement is not applied to default expressions, for which
7889 -- the discriminal is correct.
7891 if Has_Discriminants (Prot_Typ) then
7897 Disc := First_Discriminant (Prot_Typ);
7898 Decl := First (Discriminant_Specifications (Rec_Decl));
7899 while Present (Disc) loop
7900 Append_Elmt (Discriminal (Disc), Discr_Map);
7901 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7902 Next_Discriminant (Disc);
7908 -- Fill in the component declarations
7910 -- Add components for entry families. For each entry family, create an
7911 -- anonymous type declaration with the same size, and analyze the type.
7913 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7915 -- Prepend the _Object field with the right type to the component list.
7916 -- We need to compute the number of entries, and in some cases the
7917 -- number of Attach_Handler pragmas.
7921 Num_Attach_Handler : Int := 0;
7922 Protection_Subtype : Node_Id;
7923 Entry_Count_Expr : constant Node_Id :=
7924 Build_Entry_Count_Expression
7925 (Prot_Typ, Cdecls, Loc);
7928 -- Could this be simplified using Corresponding_Runtime_Package???
7930 if Has_Attach_Handler (Prot_Typ) then
7931 Ritem := First_Rep_Item (Prot_Typ);
7932 while Present (Ritem) loop
7933 if Nkind (Ritem) = N_Pragma
7934 and then Pragma_Name (Ritem) = Name_Attach_Handler
7936 Num_Attach_Handler := Num_Attach_Handler + 1;
7939 Next_Rep_Item (Ritem);
7942 if Restricted_Profile then
7943 if Has_Entries (Prot_Typ) then
7944 Protection_Subtype :=
7945 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7947 Protection_Subtype :=
7948 New_Reference_To (RTE (RE_Protection), Loc);
7951 Protection_Subtype :=
7952 Make_Subtype_Indication
7956 (RTE (RE_Static_Interrupt_Protection), Loc),
7958 Make_Index_Or_Discriminant_Constraint (
7960 Constraints => New_List (
7962 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7965 elsif Has_Interrupt_Handler (Prot_Typ) then
7966 Protection_Subtype :=
7967 Make_Subtype_Indication (
7969 Subtype_Mark => New_Reference_To
7970 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7972 Make_Index_Or_Discriminant_Constraint (
7974 Constraints => New_List (Entry_Count_Expr)));
7976 -- Type has explicit entries or generated primitive entry wrappers
7978 elsif Has_Entries (Prot_Typ)
7979 or else (Ada_Version >= Ada_2005
7980 and then Present (Interface_List (N)))
7982 case Corresponding_Runtime_Package (Prot_Typ) is
7983 when System_Tasking_Protected_Objects_Entries =>
7984 Protection_Subtype :=
7985 Make_Subtype_Indication (Loc,
7987 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7989 Make_Index_Or_Discriminant_Constraint (
7991 Constraints => New_List (Entry_Count_Expr)));
7993 when System_Tasking_Protected_Objects_Single_Entry =>
7994 Protection_Subtype :=
7995 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7998 raise Program_Error;
8002 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
8006 Make_Component_Declaration (Loc,
8007 Defining_Identifier =>
8008 Make_Defining_Identifier (Loc, Name_uObject),
8009 Component_Definition =>
8010 Make_Component_Definition (Loc,
8011 Aliased_Present => True,
8012 Subtype_Indication => Protection_Subtype));
8015 pragma Assert (Present (Pdef));
8017 -- Add private field components
8019 if Present (Private_Declarations (Pdef)) then
8020 Priv := First (Private_Declarations (Pdef));
8022 while Present (Priv) loop
8024 if Nkind (Priv) = N_Component_Declaration then
8025 if not Static_Component_Size (Defining_Identifier (Priv)) then
8027 -- When compiling for a restricted profile, the private
8028 -- components must have a static size. If not, this is an
8029 -- error for a single protected declaration, and rates a
8030 -- warning on a protected type declaration.
8032 if not Comes_From_Source (Prot_Typ) then
8033 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8035 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8036 Error_Msg_N ("component has non-static size?", Priv);
8038 ("\creation of protected object of type& will violate"
8039 & " restriction No_Implicit_Heap_Allocations?",
8044 -- The component definition consists of a subtype indication,
8045 -- or (in Ada 2005) an access definition. Make a copy of the
8046 -- proper definition.
8049 Old_Comp : constant Node_Id := Component_Definition (Priv);
8050 Oent : constant Entity_Id := Defining_Identifier (Priv);
8052 Nent : constant Entity_Id :=
8053 Make_Defining_Identifier (Sloc (Oent),
8054 Chars => Chars (Oent));
8057 if Present (Subtype_Indication (Old_Comp)) then
8059 Make_Component_Definition (Sloc (Oent),
8060 Aliased_Present => False,
8061 Subtype_Indication =>
8062 New_Copy_Tree (Subtype_Indication (Old_Comp),
8066 Make_Component_Definition (Sloc (Oent),
8067 Aliased_Present => False,
8068 Access_Definition =>
8069 New_Copy_Tree (Access_Definition (Old_Comp),
8074 Make_Component_Declaration (Loc,
8075 Defining_Identifier => Nent,
8076 Component_Definition => New_Comp,
8077 Expression => Expression (Priv));
8079 Set_Has_Per_Object_Constraint (Nent,
8080 Has_Per_Object_Constraint (Oent));
8082 Append_To (Cdecls, New_Priv);
8085 elsif Nkind (Priv) = N_Subprogram_Declaration then
8087 -- Make the unprotected version of the subprogram available
8088 -- for expansion of intra object calls. There is need for
8089 -- a protected version only if the subprogram is an interrupt
8090 -- handler, otherwise this operation can only be called from
8094 Make_Subprogram_Declaration (Loc,
8096 Build_Protected_Sub_Specification
8097 (Priv, Prot_Typ, Unprotected_Mode));
8099 Insert_After (Current_Node, Sub);
8102 Set_Protected_Body_Subprogram
8103 (Defining_Unit_Name (Specification (Priv)),
8104 Defining_Unit_Name (Specification (Sub)));
8105 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8106 Current_Node := Sub;
8109 Make_Subprogram_Declaration (Loc,
8111 Build_Protected_Sub_Specification
8112 (Priv, Prot_Typ, Protected_Mode));
8114 Insert_After (Current_Node, Sub);
8116 Current_Node := Sub;
8118 if Is_Interrupt_Handler
8119 (Defining_Unit_Name (Specification (Priv)))
8121 if not Restricted_Profile then
8131 -- Put the _Object component after the private component so that it
8132 -- be finalized early as required by 9.4 (20)
8134 Append_To (Cdecls, Object_Comp);
8136 Insert_After (Current_Node, Rec_Decl);
8137 Current_Node := Rec_Decl;
8139 -- Analyze the record declaration immediately after construction,
8140 -- because the initialization procedure is needed for single object
8141 -- declarations before the next entity is analyzed (the freeze call
8142 -- that generates this initialization procedure is found below).
8144 Analyze (Rec_Decl, Suppress => All_Checks);
8146 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8147 -- the corresponding record is frozen. If any wrappers are generated,
8148 -- Current_Node is updated accordingly.
8150 if Ada_Version >= Ada_2005 then
8151 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8154 -- Collect pointers to entry bodies and their barriers, to be placed
8155 -- in the Entry_Bodies_Array for the type. For each entry/family we
8156 -- add an expression to the aggregate which is the initial value of
8157 -- this array. The array is declared after all protected subprograms.
8159 if Has_Entries (Prot_Typ) then
8160 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8162 Entries_Aggr := Empty;
8165 -- Build two new procedure specifications for each protected subprogram;
8166 -- one to call from outside the object and one to call from inside.
8167 -- Build a barrier function and an entry body action procedure
8168 -- specification for each protected entry. Initialize the entry body
8169 -- array. If subprogram is flagged as eliminated, do not generate any
8170 -- internal operations.
8174 Comp := First (Visible_Declarations (Pdef));
8176 while Present (Comp) loop
8177 if Nkind (Comp) = N_Subprogram_Declaration then
8179 Make_Subprogram_Declaration (Loc,
8181 Build_Protected_Sub_Specification
8182 (Comp, Prot_Typ, Unprotected_Mode));
8184 Insert_After (Current_Node, Sub);
8187 Set_Protected_Body_Subprogram
8188 (Defining_Unit_Name (Specification (Comp)),
8189 Defining_Unit_Name (Specification (Sub)));
8190 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8192 -- Make the protected version of the subprogram available for
8193 -- expansion of external calls.
8195 Current_Node := Sub;
8198 Make_Subprogram_Declaration (Loc,
8200 Build_Protected_Sub_Specification
8201 (Comp, Prot_Typ, Protected_Mode));
8203 Insert_After (Current_Node, Sub);
8206 Current_Node := Sub;
8208 -- Generate an overriding primitive operation specification for
8209 -- this subprogram if the protected type implements an interface.
8211 if Ada_Version >= Ada_2005
8213 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8216 Make_Subprogram_Declaration (Loc,
8218 Build_Protected_Sub_Specification
8219 (Comp, Prot_Typ, Dispatching_Mode));
8221 Insert_After (Current_Node, Sub);
8224 Current_Node := Sub;
8227 -- If a pragma Interrupt_Handler applies, build and add a call to
8228 -- Register_Interrupt_Handler to the freezing actions of the
8229 -- protected version (Current_Node) of the subprogram:
8231 -- system.interrupts.register_interrupt_handler
8232 -- (prot_procP'address);
8234 if not Restricted_Profile
8235 and then Is_Interrupt_Handler
8236 (Defining_Unit_Name (Specification (Comp)))
8241 elsif Nkind (Comp) = N_Entry_Declaration then
8242 E_Count := E_Count + 1;
8243 Comp_Id := Defining_Identifier (Comp);
8246 Make_Defining_Identifier (Loc,
8247 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8249 Make_Subprogram_Declaration (Loc,
8251 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8253 Insert_After (Current_Node, Sub);
8256 -- build wrapper procedure for pre/postconditions.
8258 Build_PPC_Wrapper (Comp_Id, N);
8260 Set_Protected_Body_Subprogram
8261 (Defining_Identifier (Comp),
8262 Defining_Unit_Name (Specification (Sub)));
8264 Current_Node := Sub;
8267 Make_Defining_Identifier (Loc,
8268 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8270 Make_Subprogram_Declaration (Loc,
8272 Build_Barrier_Function_Specification (Loc, Bdef));
8274 Insert_After (Current_Node, Sub);
8276 Set_Protected_Body_Subprogram (Bdef, Bdef);
8277 Set_Barrier_Function (Comp_Id, Bdef);
8278 Set_Scope (Bdef, Scope (Comp_Id));
8279 Current_Node := Sub;
8281 -- Collect pointers to the protected subprogram and the barrier
8282 -- of the current entry, for insertion into Entry_Bodies_Array.
8285 Make_Aggregate (Loc,
8286 Expressions => New_List (
8287 Make_Attribute_Reference (Loc,
8288 Prefix => New_Reference_To (Bdef, Loc),
8289 Attribute_Name => Name_Unrestricted_Access),
8290 Make_Attribute_Reference (Loc,
8291 Prefix => New_Reference_To (Edef, Loc),
8292 Attribute_Name => Name_Unrestricted_Access))),
8293 Expressions (Entries_Aggr));
8300 -- If there are some private entry declarations, expand it as if they
8301 -- were visible entries.
8303 if Present (Private_Declarations (Pdef)) then
8304 Comp := First (Private_Declarations (Pdef));
8305 while Present (Comp) loop
8306 if Nkind (Comp) = N_Entry_Declaration then
8307 E_Count := E_Count + 1;
8308 Comp_Id := Defining_Identifier (Comp);
8311 Make_Defining_Identifier (Loc,
8312 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8314 Make_Subprogram_Declaration (Loc,
8316 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8318 Insert_After (Current_Node, Sub);
8321 Set_Protected_Body_Subprogram
8322 (Defining_Identifier (Comp),
8323 Defining_Unit_Name (Specification (Sub)));
8325 Current_Node := Sub;
8328 Make_Defining_Identifier (Loc,
8329 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8332 Make_Subprogram_Declaration (Loc,
8334 Build_Barrier_Function_Specification (Loc, Bdef));
8336 Insert_After (Current_Node, Sub);
8338 Set_Protected_Body_Subprogram (Bdef, Bdef);
8339 Set_Barrier_Function (Comp_Id, Bdef);
8340 Set_Scope (Bdef, Scope (Comp_Id));
8341 Current_Node := Sub;
8343 -- Collect pointers to the protected subprogram and the barrier
8344 -- of the current entry, for insertion into Entry_Bodies_Array.
8346 Append_To (Expressions (Entries_Aggr),
8347 Make_Aggregate (Loc,
8348 Expressions => New_List (
8349 Make_Attribute_Reference (Loc,
8350 Prefix => New_Reference_To (Bdef, Loc),
8351 Attribute_Name => Name_Unrestricted_Access),
8352 Make_Attribute_Reference (Loc,
8353 Prefix => New_Reference_To (Edef, Loc),
8354 Attribute_Name => Name_Unrestricted_Access))));
8361 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8362 -- all protected subprograms have been collected.
8364 if Has_Entries (Prot_Typ) then
8366 Make_Defining_Identifier (Sloc (Prot_Typ),
8367 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8369 case Corresponding_Runtime_Package (Prot_Typ) is
8370 when System_Tasking_Protected_Objects_Entries =>
8371 Body_Arr := Make_Object_Declaration (Loc,
8372 Defining_Identifier => Body_Id,
8373 Aliased_Present => True,
8374 Object_Definition =>
8375 Make_Subtype_Indication (Loc,
8376 Subtype_Mark => New_Reference_To (
8377 RTE (RE_Protected_Entry_Body_Array), Loc),
8379 Make_Index_Or_Discriminant_Constraint (Loc,
8380 Constraints => New_List (
8382 Make_Integer_Literal (Loc, 1),
8383 Make_Integer_Literal (Loc, E_Count))))),
8384 Expression => Entries_Aggr);
8386 when System_Tasking_Protected_Objects_Single_Entry =>
8387 Body_Arr := Make_Object_Declaration (Loc,
8388 Defining_Identifier => Body_Id,
8389 Aliased_Present => True,
8390 Object_Definition => New_Reference_To
8391 (RTE (RE_Entry_Body), Loc),
8393 Make_Aggregate (Loc,
8394 Expressions => New_List (
8395 Make_Attribute_Reference (Loc,
8396 Prefix => New_Reference_To (Bdef, Loc),
8397 Attribute_Name => Name_Unrestricted_Access),
8398 Make_Attribute_Reference (Loc,
8399 Prefix => New_Reference_To (Edef, Loc),
8400 Attribute_Name => Name_Unrestricted_Access))));
8403 raise Program_Error;
8406 -- A pointer to this array will be placed in the corresponding record
8407 -- by its initialization procedure so this needs to be analyzed here.
8409 Insert_After (Current_Node, Body_Arr);
8410 Current_Node := Body_Arr;
8413 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8415 -- Finally, build the function that maps an entry index into the
8416 -- corresponding body. A pointer to this function is placed in each
8417 -- object of the type. Except for a ravenscar-like profile (no abort,
8418 -- no entry queue, 1 entry)
8420 if Corresponding_Runtime_Package (Prot_Typ) =
8421 System_Tasking_Protected_Objects_Entries
8424 Make_Subprogram_Declaration (Loc,
8425 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8426 Insert_After (Current_Node, Sub);
8430 end Expand_N_Protected_Type_Declaration;
8432 --------------------------------
8433 -- Expand_N_Requeue_Statement --
8434 --------------------------------
8436 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8437 -- operations, depending on the source and destination (task or protected
8438 -- object). A dispatching requeue statement is expanded into a call to the
8439 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8440 -- jump around the remainder of processing for the original entry and, if
8441 -- the destination is (different) protected object, to attempt to service
8442 -- it. The following illustrates the various cases:
8445 -- (O : System.Address;
8446 -- P : System.Address;
8447 -- E : Protected_Entry_Index)
8449 -- <discriminant renamings>
8450 -- <private object renamings>
8451 -- type poVP is access poV;
8452 -- _object : ptVP := ptVP!(O);
8456 -- <start of statement sequence for entry>
8458 -- -- Requeue from one protected entry body to another protected
8461 -- Requeue_Protected_Entry (
8462 -- _object._object'Access,
8463 -- new._object'Access,
8468 -- <some more of the statement sequence for entry>
8470 -- -- Requeue from an entry body to a task entry
8472 -- Requeue_Protected_To_Task_Entry (
8478 -- <rest of statement sequence for entry>
8479 -- Complete_Entry_Body (_object._object);
8482 -- when all others =>
8483 -- Exceptional_Complete_Entry_Body (
8484 -- _object._object, Get_GNAT_Exception);
8488 -- Requeue of a task entry call to a task entry
8490 -- Accept_Call (E, Ann);
8491 -- <start of statement sequence for accept statement>
8492 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8494 -- <rest of statement sequence for accept statement>
8496 -- Complete_Rendezvous;
8499 -- when all others =>
8500 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8502 -- Requeue of a task entry call to a protected entry
8504 -- Accept_Call (E, Ann);
8505 -- <start of statement sequence for accept statement>
8506 -- Requeue_Task_To_Protected_Entry (
8507 -- new._object'Access,
8512 -- <rest of statement sequence for accept statement>
8514 -- Complete_Rendezvous;
8517 -- when all others =>
8518 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8520 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8521 -- marked by pragma Implemented (XXX, By_Entry).
8523 -- The requeue is inside a protected entry:
8526 -- (O : System.Address;
8527 -- P : System.Address;
8528 -- E : Protected_Entry_Index)
8530 -- <discriminant renamings>
8531 -- <private object renamings>
8532 -- type poVP is access poV;
8533 -- _object : ptVP := ptVP!(O);
8537 -- <start of statement sequence for entry>
8540 -- (<interface class-wide object>,
8543 -- Ada.Tags.Get_Offset_Index
8545 -- <interface dispatch table index of target entry>),
8549 -- <rest of statement sequence for entry>
8550 -- Complete_Entry_Body (_object._object);
8553 -- when all others =>
8554 -- Exceptional_Complete_Entry_Body (
8555 -- _object._object, Get_GNAT_Exception);
8559 -- The requeue is inside a task entry:
8561 -- Accept_Call (E, Ann);
8562 -- <start of statement sequence for accept statement>
8564 -- (<interface class-wide object>,
8567 -- Ada.Tags.Get_Offset_Index
8569 -- <interface dispatch table index of target entrt>),
8573 -- <rest of statement sequence for accept statement>
8575 -- Complete_Rendezvous;
8578 -- when all others =>
8579 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8581 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8582 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8583 -- statement is replaced by a dispatching call with actual parameters taken
8584 -- from the inner-most accept statement or entry body.
8586 -- Target.Primitive (Param1, ..., ParamN);
8588 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8589 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8592 -- S : constant Offset_Index :=
8593 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8594 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8597 -- if C = POK_Protected_Entry
8598 -- or else C = POK_Task_Entry
8600 -- <statements for dispatching requeue>
8602 -- elsif C = POK_Protected_Procedure then
8603 -- <dispatching call equivalent>
8606 -- raise Program_Error;
8610 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8611 Loc : constant Source_Ptr := Sloc (N);
8612 Conc_Typ : Entity_Id;
8616 Old_Typ : Entity_Id;
8618 function Build_Dispatching_Call_Equivalent return Node_Id;
8619 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8620 -- the form Concval.Ename. It is statically known that Ename is allowed
8621 -- to be implemented by a protected procedure. Create a dispatching call
8622 -- equivalent of Concval.Ename taking the actual parameters from the
8623 -- inner-most accept statement or entry body.
8625 function Build_Dispatching_Requeue return Node_Id;
8626 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8627 -- the form Concval.Ename. It is statically known that Ename is allowed
8628 -- to be implemented by a protected or a task entry. Create a call to
8629 -- primitive _Disp_Requeue which handles the low-level actions.
8631 function Build_Dispatching_Requeue_To_Any return Node_Id;
8632 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8633 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8634 -- (XXX, By_Any) or not marked at all. Create a block which determines
8635 -- at runtime whether Ename denotes an entry or a procedure and perform
8636 -- the appropriate kind of dispatching select.
8638 function Build_Normal_Requeue return Node_Id;
8639 -- N denotes a non-dispatching requeue statement to either a task or a
8640 -- protected entry. Build the appropriate runtime call to perform the
8643 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8644 -- For a protected entry, create a return statement to skip the rest of
8645 -- the entry body. Otherwise, create a goto statement to skip the rest
8646 -- of a task accept statement. The lookup for the enclosing entry body
8647 -- or accept statement starts from Search.
8649 ---------------------------------------
8650 -- Build_Dispatching_Call_Equivalent --
8651 ---------------------------------------
8653 function Build_Dispatching_Call_Equivalent return Node_Id is
8654 Call_Ent : constant Entity_Id := Entity (Ename);
8655 Obj : constant Node_Id := Original_Node (Concval);
8662 -- Climb the parent chain looking for the inner-most entry body or
8663 -- accept statement.
8666 while Present (Acc_Ent)
8667 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8670 Acc_Ent := Parent (Acc_Ent);
8673 -- A requeue statement should be housed inside an entry body or an
8674 -- accept statement at some level. If this is not the case, then the
8675 -- tree is malformed.
8677 pragma Assert (Present (Acc_Ent));
8679 -- Recover the list of formal parameters
8681 if Nkind (Acc_Ent) = N_Entry_Body then
8682 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8685 Formals := Parameter_Specifications (Acc_Ent);
8687 -- Create the actual parameters for the dispatching call. These are
8688 -- simply copies of the entry body or accept statement formals in the
8689 -- same order as they appear.
8693 if Present (Formals) then
8694 Actuals := New_List;
8695 Formal := First (Formals);
8696 while Present (Formal) loop
8698 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8704 -- Obj.Call_Ent (Actuals);
8707 Make_Procedure_Call_Statement (Loc,
8709 Make_Selected_Component (Loc,
8710 Prefix => Make_Identifier (Loc, Chars (Obj)),
8711 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
8713 Parameter_Associations => Actuals);
8714 end Build_Dispatching_Call_Equivalent;
8716 -------------------------------
8717 -- Build_Dispatching_Requeue --
8718 -------------------------------
8720 function Build_Dispatching_Requeue return Node_Id is
8721 Params : constant List_Id := New_List;
8724 -- Process the "with abort" parameter
8727 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8729 -- Process the entry wrapper's position in the primary dispatch
8730 -- table parameter. Generate:
8732 -- Ada.Tags.Get_Offset_Index
8733 -- (Ada.Tags.Tag (Concval),
8734 -- <interface dispatch table position of Ename>)
8736 if Tagged_Type_Expansion then
8738 Make_Function_Call (Loc,
8739 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8740 Parameter_Associations => New_List (
8741 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8742 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8748 Make_Function_Call (Loc,
8749 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8751 Parameter_Associations => New_List (
8755 Make_Attribute_Reference (Loc,
8757 Attribute_Name => Name_Tag),
8761 Make_Attribute_Reference (Loc,
8762 Prefix => New_Reference_To (Etype (Concval), Loc),
8763 Attribute_Name => Name_Tag),
8767 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8770 -- Specific actuals for protected to XXX requeue
8772 if Is_Protected_Type (Old_Typ) then
8774 Make_Attribute_Reference (Loc, -- _object'Address
8776 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8777 Attribute_Name => Name_Address));
8779 Prepend_To (Params, -- True
8780 New_Reference_To (Standard_True, Loc));
8782 -- Specific actuals for task to XXX requeue
8785 pragma Assert (Is_Task_Type (Old_Typ));
8787 Prepend_To (Params, -- null
8788 New_Reference_To (RTE (RE_Null_Address), Loc));
8790 Prepend_To (Params, -- False
8791 New_Reference_To (Standard_False, Loc));
8794 -- Add the object parameter
8796 Prepend_To (Params, New_Copy_Tree (Concval));
8799 -- _Disp_Requeue (<Params>);
8802 Make_Procedure_Call_Statement (Loc,
8803 Name => Make_Identifier (Loc, Name_uDisp_Requeue),
8804 Parameter_Associations => Params);
8805 end Build_Dispatching_Requeue;
8807 --------------------------------------
8808 -- Build_Dispatching_Requeue_To_Any --
8809 --------------------------------------
8811 function Build_Dispatching_Requeue_To_Any return Node_Id is
8812 Call_Ent : constant Entity_Id := Entity (Ename);
8813 Obj : constant Node_Id := Original_Node (Concval);
8814 Skip : constant Node_Id := Build_Skip_Statement (N);
8824 -- Dispatch table slot processing, generate:
8827 S := Build_S (Loc, Decls);
8829 -- Call kind processing, generate:
8830 -- C : Ada.Tags.Prim_Op_Kind;
8832 C := Build_C (Loc, Decls);
8835 -- S := Ada.Tags.Get_Offset_Index
8836 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
8838 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
8841 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
8844 Make_Procedure_Call_Statement (Loc,
8847 Find_Prim_Op (Etype (Etype (Obj)),
8848 Name_uDisp_Get_Prim_Op_Kind),
8850 Parameter_Associations => New_List (
8851 New_Copy_Tree (Obj),
8852 New_Reference_To (S, Loc),
8853 New_Reference_To (C, Loc))));
8857 -- if C = POK_Protected_Entry
8858 -- or else C = POK_Task_Entry
8861 Make_If_Statement (Loc,
8867 New_Reference_To (C, Loc),
8869 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
8874 New_Reference_To (C, Loc),
8876 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
8878 -- Dispatching requeue equivalent
8880 Then_Statements => New_List (
8881 Build_Dispatching_Requeue,
8884 -- elsif C = POK_Protected_Procedure then
8886 Elsif_Parts => New_List (
8887 Make_Elsif_Part (Loc,
8891 New_Reference_To (C, Loc),
8894 RTE (RE_POK_Protected_Procedure), Loc)),
8896 -- Dispatching call equivalent
8898 Then_Statements => New_List (
8899 Build_Dispatching_Call_Equivalent))),
8902 -- raise Program_Error;
8905 Else_Statements => New_List (
8906 Make_Raise_Program_Error (Loc,
8907 Reason => PE_Explicit_Raise))));
8909 -- Wrap everything into a block
8912 Make_Block_Statement (Loc,
8913 Declarations => Decls,
8914 Handled_Statement_Sequence =>
8915 Make_Handled_Sequence_Of_Statements (Loc,
8916 Statements => Stmts));
8917 end Build_Dispatching_Requeue_To_Any;
8919 --------------------------
8920 -- Build_Normal_Requeue --
8921 --------------------------
8923 function Build_Normal_Requeue return Node_Id is
8924 Params : constant List_Id := New_List;
8929 -- Process the "with abort" parameter
8932 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8934 -- Add the index expression to the parameters. It is common among all
8938 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8940 if Is_Protected_Type (Old_Typ) then
8942 Self_Param : Node_Id;
8946 Make_Attribute_Reference (Loc,
8948 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8950 Name_Unchecked_Access);
8952 -- Protected to protected requeue
8954 if Is_Protected_Type (Conc_Typ) then
8957 RTE (RE_Requeue_Protected_Entry), Loc);
8960 Make_Attribute_Reference (Loc,
8962 Concurrent_Ref (Concval),
8964 Name_Unchecked_Access);
8966 -- Protected to task requeue
8968 else pragma Assert (Is_Task_Type (Conc_Typ));
8971 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8973 Param := Concurrent_Ref (Concval);
8976 Prepend_To (Params, Param);
8977 Prepend_To (Params, Self_Param);
8980 else pragma Assert (Is_Task_Type (Old_Typ));
8982 -- Task to protected requeue
8984 if Is_Protected_Type (Conc_Typ) then
8987 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8990 Make_Attribute_Reference (Loc,
8992 Concurrent_Ref (Concval),
8994 Name_Unchecked_Access);
8996 -- Task to task requeue
8998 else pragma Assert (Is_Task_Type (Conc_Typ));
9000 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
9002 Param := Concurrent_Ref (Concval);
9005 Prepend_To (Params, Param);
9009 Make_Procedure_Call_Statement (Loc,
9011 Parameter_Associations => Params);
9012 end Build_Normal_Requeue;
9014 --------------------------
9015 -- Build_Skip_Statement --
9016 --------------------------
9018 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
9019 Skip_Stmt : Node_Id;
9022 -- Build a return statement to skip the rest of the entire body
9024 if Is_Protected_Type (Old_Typ) then
9025 Skip_Stmt := Make_Simple_Return_Statement (Loc);
9027 -- If the requeue is within a task, find the end label of the
9028 -- enclosing accept statement and create a goto statement to it.
9036 -- Climb the parent chain looking for the enclosing accept
9039 Acc := Parent (Search);
9041 and then Nkind (Acc) /= N_Accept_Statement
9043 Acc := Parent (Acc);
9046 -- The last statement is the second label used for completing
9047 -- the rendezvous the usual way. The label we are looking for
9048 -- is right before it.
9051 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
9053 pragma Assert (Nkind (Label) = N_Label);
9055 -- Generate a goto statement to skip the rest of the accept
9058 Make_Goto_Statement (Loc,
9060 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9064 Set_Analyzed (Skip_Stmt);
9067 end Build_Skip_Statement;
9069 -- Start of processing for Expand_N_Requeue_Statement
9072 -- Extract the components of the entry call
9074 Extract_Entry (N, Concval, Ename, Index);
9075 Conc_Typ := Etype (Concval);
9077 -- Examine the scope stack in order to find nearest enclosing protected
9078 -- or task type. This will constitute our invocation source.
9080 Old_Typ := Current_Scope;
9081 while Present (Old_Typ)
9082 and then not Is_Protected_Type (Old_Typ)
9083 and then not Is_Task_Type (Old_Typ)
9085 Old_Typ := Scope (Old_Typ);
9088 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9089 -- Concval.Ename where the type of Concval is class-wide concurrent
9092 if Ada_Version >= Ada_2012
9093 and then Present (Concval)
9094 and then Is_Class_Wide_Type (Conc_Typ)
9095 and then Is_Concurrent_Interface (Conc_Typ)
9098 Has_Impl : Boolean := False;
9099 Impl_Kind : Name_Id := No_Name;
9102 -- Check whether the Ename is flagged by pragma Implemented
9104 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9106 Impl_Kind := Implementation_Kind (Entity (Ename));
9109 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9110 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9113 and then Impl_Kind = Name_By_Entry
9115 Rewrite (N, Build_Dispatching_Requeue);
9117 Insert_After (N, Build_Skip_Statement (N));
9119 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9120 -- a protected procedure. In this case the requeue is transformed
9121 -- into a dispatching call.
9124 and then Impl_Kind = Name_By_Protected_Procedure
9126 Rewrite (N, Build_Dispatching_Call_Equivalent);
9129 -- The procedure_or_entry_NAME's implementation kind is either
9130 -- By_Any or pragma Implemented was not applied at all. In this
9131 -- case a runtime test determines whether Ename denotes an entry
9132 -- or a protected procedure and performs the appropriate call.
9135 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9140 -- Processing for regular (non-dispatching) requeues
9143 Rewrite (N, Build_Normal_Requeue);
9145 Insert_After (N, Build_Skip_Statement (N));
9147 end Expand_N_Requeue_Statement;
9149 -------------------------------
9150 -- Expand_N_Selective_Accept --
9151 -------------------------------
9153 procedure Expand_N_Selective_Accept (N : Node_Id) is
9154 Loc : constant Source_Ptr := Sloc (N);
9155 Alts : constant List_Id := Select_Alternatives (N);
9157 -- Note: in the below declarations a lot of new lists are allocated
9158 -- unconditionally which may well not end up being used. That's
9159 -- not a good idea since it wastes space gratuitously ???
9161 Accept_Case : List_Id;
9162 Accept_List : constant List_Id := New_List;
9165 Alt_List : constant List_Id := New_List;
9166 Alt_Stats : List_Id;
9167 Ann : Entity_Id := Empty;
9170 Check_Guard : Boolean := True;
9172 Decls : constant List_Id := New_List;
9173 Stats : constant List_Id := New_List;
9174 Body_List : constant List_Id := New_List;
9175 Trailing_List : constant List_Id := New_List;
9178 Else_Present : Boolean := False;
9179 Terminate_Alt : Node_Id := Empty;
9180 Select_Mode : Node_Id;
9182 Delay_Case : List_Id;
9183 Delay_Count : Integer := 0;
9184 Delay_Val : Entity_Id;
9185 Delay_Index : Entity_Id;
9186 Delay_Min : Entity_Id;
9187 Delay_Num : Int := 1;
9188 Delay_Alt_List : List_Id := New_List;
9189 Delay_List : constant List_Id := New_List;
9193 First_Delay : Boolean := True;
9194 Guard_Open : Entity_Id;
9200 Num_Accept : Nat := 0;
9203 Time_Type : Entity_Id;
9205 Select_Call : Node_Id;
9207 Qnam : constant Entity_Id :=
9208 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9210 Xnam : constant Entity_Id :=
9211 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9213 -----------------------
9214 -- Local subprograms --
9215 -----------------------
9217 function Accept_Or_Raise return List_Id;
9218 -- For the rare case where delay alternatives all have guards, and
9219 -- all of them are closed, it is still possible that there were open
9220 -- accept alternatives with no callers. We must reexamine the
9221 -- Accept_List, and execute a selective wait with no else if some
9222 -- accept is open. If none, we raise program_error.
9224 procedure Add_Accept (Alt : Node_Id);
9225 -- Process a single accept statement in a select alternative. Build
9226 -- procedure for body of accept, and add entry to dispatch table with
9227 -- expression for guard, in preparation for call to run time select.
9229 function Make_And_Declare_Label (Num : Int) return Node_Id;
9230 -- Manufacture a label using Num as a serial number and declare it.
9231 -- The declaration is appended to Decls. The label marks the trailing
9232 -- statements of an accept or delay alternative.
9234 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9235 -- Build call to Selective_Wait runtime routine
9237 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9238 -- Add code to compare value of delay with previous values, and
9239 -- generate case entry for trailing statements.
9241 procedure Process_Accept_Alternative
9245 -- Add code to call corresponding procedure, and branch to
9246 -- trailing statements, if any.
9248 ---------------------
9249 -- Accept_Or_Raise --
9250 ---------------------
9252 function Accept_Or_Raise return List_Id is
9255 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9258 -- We generate the following:
9260 -- for J in q'range loop
9261 -- if q(J).S /=null_task_entry then
9262 -- selective_wait (simple_mode,...);
9268 -- if no rendez_vous then
9269 -- raise program_error;
9272 -- Note that the code needs to know that the selector name
9273 -- in an Accept_Alternative is named S.
9275 Cond := Make_Op_Ne (Loc,
9277 Make_Selected_Component (Loc,
9279 Make_Indexed_Component (Loc,
9280 Prefix => New_Reference_To (Qnam, Loc),
9281 Expressions => New_List (New_Reference_To (J, Loc))),
9282 Selector_Name => Make_Identifier (Loc, Name_S)),
9284 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9287 Make_Implicit_Loop_Statement (N,
9288 Identifier => Empty,
9290 Make_Iteration_Scheme (Loc,
9291 Loop_Parameter_Specification =>
9292 Make_Loop_Parameter_Specification (Loc,
9293 Defining_Identifier => J,
9294 Discrete_Subtype_Definition =>
9295 Make_Attribute_Reference (Loc,
9296 Prefix => New_Reference_To (Qnam, Loc),
9297 Attribute_Name => Name_Range,
9298 Expressions => New_List (
9299 Make_Integer_Literal (Loc, 1))))),
9301 Statements => New_List (
9302 Make_Implicit_If_Statement (N,
9304 Then_Statements => New_List (
9306 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9307 Make_Exit_Statement (Loc))))));
9310 Make_Raise_Program_Error (Loc,
9311 Condition => Make_Op_Eq (Loc,
9312 Left_Opnd => New_Reference_To (Xnam, Loc),
9314 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9315 Reason => PE_All_Guards_Closed));
9318 end Accept_Or_Raise;
9324 procedure Add_Accept (Alt : Node_Id) is
9325 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9326 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9327 Eloc : constant Source_Ptr := Sloc (Ename);
9328 Eent : constant Entity_Id := Entity (Ename);
9329 Index : constant Node_Id := Entry_Index (Acc_Stm);
9330 Null_Body : Node_Id;
9331 Proc_Body : Node_Id;
9338 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9341 if Present (Condition (Alt)) then
9343 Make_Conditional_Expression (Eloc, New_List (
9345 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9346 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9349 Entry_Index_Expression
9350 (Eloc, Eent, Index, Scope (Eent));
9353 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9354 Null_Body := New_Reference_To (Standard_False, Eloc);
9356 if Abort_Allowed then
9357 Call := Make_Procedure_Call_Statement (Eloc,
9358 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9359 Insert_Before (First (Statements (Handled_Statement_Sequence (
9360 Accept_Statement (Alt)))), Call);
9365 Make_Defining_Identifier (Eloc,
9366 New_External_Name (Chars (Ename), 'A', Num_Accept));
9368 if Comes_From_Source (Alt) then
9369 Set_Debug_Info_Needed (PB_Ent);
9373 Make_Subprogram_Body (Eloc,
9375 Make_Procedure_Specification (Eloc,
9376 Defining_Unit_Name => PB_Ent),
9377 Declarations => Declarations (Acc_Stm),
9378 Handled_Statement_Sequence =>
9379 Build_Accept_Body (Accept_Statement (Alt)));
9381 -- During the analysis of the body of the accept statement, any
9382 -- zero cost exception handler records were collected in the
9383 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9384 -- This is where we move them to where they belong, namely the
9385 -- newly created procedure.
9387 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9388 Append (Proc_Body, Body_List);
9391 Null_Body := New_Reference_To (Standard_True, Eloc);
9393 -- if accept statement has declarations, insert above, given that
9394 -- we are not creating a body for the accept.
9396 if Present (Declarations (Acc_Stm)) then
9397 Insert_Actions (N, Declarations (Acc_Stm));
9401 Append_To (Accept_List,
9402 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9404 Num_Accept := Num_Accept + 1;
9407 ----------------------------
9408 -- Make_And_Declare_Label --
9409 ----------------------------
9411 function Make_And_Declare_Label (Num : Int) return Node_Id is
9415 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9417 Make_Label (Loc, Lab_Id);
9420 Make_Implicit_Label_Declaration (Loc,
9421 Defining_Identifier =>
9422 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9423 Label_Construct => Lab));
9426 end Make_And_Declare_Label;
9428 ----------------------
9429 -- Make_Select_Call --
9430 ----------------------
9432 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9433 Params : constant List_Id := New_List;
9437 Make_Attribute_Reference (Loc,
9438 Prefix => New_Reference_To (Qnam, Loc),
9439 Attribute_Name => Name_Unchecked_Access),
9441 Append (Select_Mode, Params);
9442 Append (New_Reference_To (Ann, Loc), Params);
9443 Append (New_Reference_To (Xnam, Loc), Params);
9446 Make_Procedure_Call_Statement (Loc,
9447 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9448 Parameter_Associations => Params);
9449 end Make_Select_Call;
9451 --------------------------------
9452 -- Process_Accept_Alternative --
9453 --------------------------------
9455 procedure Process_Accept_Alternative
9460 Choices : List_Id := No_List;
9461 Alt_Stats : List_Id;
9464 Adjust_Condition (Condition (Alt));
9465 Alt_Stats := No_List;
9467 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9468 Choices := New_List (
9469 Make_Integer_Literal (Loc, Index));
9471 Alt_Stats := New_List (
9472 Make_Procedure_Call_Statement (Sloc (Proc),
9473 Name => New_Reference_To (
9474 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9477 if Statements (Alt) /= Empty_List then
9479 if No (Alt_Stats) then
9481 -- Accept with no body, followed by trailing statements
9483 Choices := New_List (
9484 Make_Integer_Literal (Loc, Index));
9486 Alt_Stats := New_List;
9489 -- After the call, if any, branch to trailing statements. We
9490 -- create a label for each, as well as the corresponding label
9493 Lab := Make_And_Declare_Label (Index);
9494 Append_To (Alt_Stats,
9495 Make_Goto_Statement (Loc,
9496 Name => New_Copy (Identifier (Lab))));
9498 Append (Lab, Trailing_List);
9499 Append_List (Statements (Alt), Trailing_List);
9500 Append_To (Trailing_List,
9501 Make_Goto_Statement (Loc,
9502 Name => New_Copy (Identifier (End_Lab))));
9505 if Present (Alt_Stats) then
9507 -- Procedure call. and/or trailing statements
9509 Append_To (Alt_List,
9510 Make_Case_Statement_Alternative (Loc,
9511 Discrete_Choices => Choices,
9512 Statements => Alt_Stats));
9514 end Process_Accept_Alternative;
9516 -------------------------------
9517 -- Process_Delay_Alternative --
9518 -------------------------------
9520 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9523 Delay_Alt : List_Id;
9526 -- Deal with C/Fortran boolean as delay condition
9528 Adjust_Condition (Condition (Alt));
9530 -- Determine the smallest specified delay
9532 -- for each delay alternative generate:
9534 -- if guard-expression then
9535 -- Delay_Val := delay-expression;
9536 -- Guard_Open := True;
9537 -- if Delay_Val < Delay_Min then
9538 -- Delay_Min := Delay_Val;
9539 -- Delay_Index := Index;
9543 -- The enclosing if-statement is omitted if there is no guard
9548 First_Delay := False;
9550 Delay_Alt := New_List (
9551 Make_Assignment_Statement (Loc,
9552 Name => New_Reference_To (Delay_Min, Loc),
9553 Expression => Expression (Delay_Statement (Alt))));
9555 if Delay_Count > 1 then
9556 Append_To (Delay_Alt,
9557 Make_Assignment_Statement (Loc,
9558 Name => New_Reference_To (Delay_Index, Loc),
9559 Expression => Make_Integer_Literal (Loc, Index)));
9563 Delay_Alt := New_List (
9564 Make_Assignment_Statement (Loc,
9565 Name => New_Reference_To (Delay_Val, Loc),
9566 Expression => Expression (Delay_Statement (Alt))));
9568 if Time_Type = Standard_Duration then
9571 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9572 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9575 -- The scope of the time type must define a comparison
9576 -- operator. The scope itself may not be visible, so we
9577 -- construct a node with entity information to insure that
9578 -- semantic analysis can find the proper operator.
9581 Make_Function_Call (Loc,
9582 Name => Make_Selected_Component (Loc,
9583 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9585 Make_Operator_Symbol (Loc,
9586 Chars => Name_Op_Lt,
9587 Strval => No_String)),
9588 Parameter_Associations =>
9590 New_Reference_To (Delay_Val, Loc),
9591 New_Reference_To (Delay_Min, Loc)));
9593 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9596 Append_To (Delay_Alt,
9597 Make_Implicit_If_Statement (N,
9599 Then_Statements => New_List (
9600 Make_Assignment_Statement (Loc,
9601 Name => New_Reference_To (Delay_Min, Loc),
9602 Expression => New_Reference_To (Delay_Val, Loc)),
9604 Make_Assignment_Statement (Loc,
9605 Name => New_Reference_To (Delay_Index, Loc),
9606 Expression => Make_Integer_Literal (Loc, Index)))));
9610 Append_To (Delay_Alt,
9611 Make_Assignment_Statement (Loc,
9612 Name => New_Reference_To (Guard_Open, Loc),
9613 Expression => New_Reference_To (Standard_True, Loc)));
9616 if Present (Condition (Alt)) then
9617 Delay_Alt := New_List (
9618 Make_Implicit_If_Statement (N,
9619 Condition => Condition (Alt),
9620 Then_Statements => Delay_Alt));
9623 Append_List (Delay_Alt, Delay_List);
9625 -- If the delay alternative has a statement part, add choice to the
9626 -- case statements for delays.
9628 if Present (Statements (Alt)) then
9630 if Delay_Count = 1 then
9631 Append_List (Statements (Alt), Delay_Alt_List);
9634 Choices := New_List (
9635 Make_Integer_Literal (Loc, Index));
9637 Append_To (Delay_Alt_List,
9638 Make_Case_Statement_Alternative (Loc,
9639 Discrete_Choices => Choices,
9640 Statements => Statements (Alt)));
9643 elsif Delay_Count = 1 then
9645 -- If the single delay has no trailing statements, add a branch
9646 -- to the exit label to the selective wait.
9648 Delay_Alt_List := New_List (
9649 Make_Goto_Statement (Loc,
9650 Name => New_Copy (Identifier (End_Lab))));
9653 end Process_Delay_Alternative;
9655 -- Start of processing for Expand_N_Selective_Accept
9658 Process_Statements_For_Controlled_Objects (N);
9660 -- First insert some declarations before the select. The first is:
9664 -- This variable holds the parameters passed to the accept body. This
9665 -- declaration has already been inserted by the time we get here by
9666 -- a call to Expand_Accept_Declarations made from the semantics when
9667 -- processing the first accept statement contained in the select. We
9668 -- can find this entity as Accept_Address (E), where E is any of the
9669 -- entries references by contained accept statements.
9671 -- The first step is to scan the list of Selective_Accept_Statements
9672 -- to find this entity, and also count the number of accepts, and
9673 -- determine if terminated, delay or else is present:
9677 Alt := First (Alts);
9678 while Present (Alt) loop
9679 Process_Statements_For_Controlled_Objects (Alt);
9681 if Nkind (Alt) = N_Accept_Alternative then
9684 elsif Nkind (Alt) = N_Delay_Alternative then
9685 Delay_Count := Delay_Count + 1;
9687 -- If the delays are relative delays, the delay expressions have
9688 -- type Standard_Duration. Otherwise they must have some time type
9689 -- recognized by GNAT.
9691 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9692 Time_Type := Standard_Duration;
9694 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9696 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9697 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9702 "& is not a time type (RM 9.6(6))",
9703 Expression (Delay_Statement (Alt)), Time_Type);
9704 Time_Type := Standard_Duration;
9705 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9709 if No (Condition (Alt)) then
9711 -- This guard will always be open
9713 Check_Guard := False;
9716 elsif Nkind (Alt) = N_Terminate_Alternative then
9717 Adjust_Condition (Condition (Alt));
9718 Terminate_Alt := Alt;
9721 Num_Alts := Num_Alts + 1;
9725 Else_Present := Present (Else_Statements (N));
9727 -- At the same time (see procedure Add_Accept) we build the accept list:
9729 -- Qnn : Accept_List (1 .. num-select) := (
9730 -- (null-body, entry-index),
9731 -- (null-body, entry-index),
9733 -- (null_body, entry-index));
9735 -- In the above declaration, null-body is True if the corresponding
9736 -- accept has no body, and false otherwise. The entry is either the
9737 -- entry index expression if there is no guard, or if a guard is
9738 -- present, then a conditional expression of the form:
9740 -- (if guard then entry-index else Null_Task_Entry)
9742 -- If a guard is statically known to be false, the entry can simply
9743 -- be omitted from the accept list.
9746 Make_Object_Declaration (Loc,
9747 Defining_Identifier => Qnam,
9748 Object_Definition =>
9749 New_Reference_To (RTE (RE_Accept_List), Loc),
9750 Aliased_Present => True,
9753 Make_Qualified_Expression (Loc,
9755 New_Reference_To (RTE (RE_Accept_List), Loc),
9757 Make_Aggregate (Loc, Expressions => Accept_List)));
9761 -- Then we declare the variable that holds the index for the accept
9762 -- that will be selected for service:
9764 -- Xnn : Select_Index;
9767 Make_Object_Declaration (Loc,
9768 Defining_Identifier => Xnam,
9769 Object_Definition =>
9770 New_Reference_To (RTE (RE_Select_Index), Loc),
9772 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9776 -- After this follow procedure declarations for each accept body
9783 -- where the ... are statements from the corresponding procedure body.
9784 -- No parameters are involved, since the parameters are passed via Ann
9785 -- and the parameter references have already been expanded to be direct
9786 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9787 -- any embedded tasking statements (which would normally be illegal in
9788 -- procedures), have been converted to calls to the tasking runtime so
9789 -- there is no problem in putting them into procedures.
9791 -- The original accept statement has been expanded into a block in
9792 -- the same fashion as for simple accepts (see Build_Accept_Body).
9794 -- Note: we don't really need to build these procedures for the case
9795 -- where no delay statement is present, but it is just as easy to
9796 -- build them unconditionally, and not significantly inefficient,
9797 -- since if they are short they will be inlined anyway.
9799 -- The procedure declarations have been assembled in Body_List
9801 -- If delays are present, we must compute the required delay.
9802 -- We first generate the declarations:
9804 -- Delay_Index : Boolean := 0;
9805 -- Delay_Min : Some_Time_Type.Time;
9806 -- Delay_Val : Some_Time_Type.Time;
9808 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9809 -- active delay that is actually chosen as the basis for the possible
9810 -- delay if an immediate rendez-vous is not possible.
9812 -- In the most common case there is a single delay statement, and this
9813 -- is handled specially.
9815 if Delay_Count > 0 then
9817 -- Generate the required declarations
9820 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9822 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9824 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9827 Make_Object_Declaration (Loc,
9828 Defining_Identifier => Delay_Val,
9829 Object_Definition => New_Reference_To (Time_Type, Loc)));
9832 Make_Object_Declaration (Loc,
9833 Defining_Identifier => Delay_Index,
9834 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9835 Expression => Make_Integer_Literal (Loc, 0)));
9838 Make_Object_Declaration (Loc,
9839 Defining_Identifier => Delay_Min,
9840 Object_Definition => New_Reference_To (Time_Type, Loc),
9842 Unchecked_Convert_To (Time_Type,
9843 Make_Attribute_Reference (Loc,
9845 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9846 Attribute_Name => Name_Last))));
9848 -- Create Duration and Delay_Mode objects used for passing a delay
9851 D := Make_Temporary (Loc, 'D');
9852 M := Make_Temporary (Loc, 'M');
9858 -- Note that these values are defined in s-osprim.ads and must
9861 -- Relative : constant := 0;
9862 -- Absolute_Calendar : constant := 1;
9863 -- Absolute_RT : constant := 2;
9865 if Time_Type = Standard_Duration then
9866 Discr := Make_Integer_Literal (Loc, 0);
9868 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9869 Discr := Make_Integer_Literal (Loc, 1);
9873 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9874 Discr := Make_Integer_Literal (Loc, 2);
9878 Make_Object_Declaration (Loc,
9879 Defining_Identifier => D,
9880 Object_Definition =>
9881 New_Reference_To (Standard_Duration, Loc)));
9884 Make_Object_Declaration (Loc,
9885 Defining_Identifier => M,
9886 Object_Definition =>
9887 New_Reference_To (Standard_Integer, Loc),
9888 Expression => Discr));
9893 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9896 Make_Object_Declaration (Loc,
9897 Defining_Identifier => Guard_Open,
9898 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9899 Expression => New_Reference_To (Standard_False, Loc)));
9902 -- Delay_Count is zero, don't need M and D set (suppress warning)
9909 if Present (Terminate_Alt) then
9911 -- If the terminate alternative guard is False, use
9912 -- Simple_Mode; otherwise use Terminate_Mode.
9914 if Present (Condition (Terminate_Alt)) then
9915 Select_Mode := Make_Conditional_Expression (Loc,
9916 New_List (Condition (Terminate_Alt),
9917 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9918 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9920 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9923 elsif Else_Present or Delay_Count > 0 then
9924 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9927 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9930 Select_Call := Make_Select_Call (Select_Mode);
9931 Append (Select_Call, Stats);
9933 -- Now generate code to act on the result. There is an entry
9934 -- in this case for each accept statement with a non-null body,
9935 -- followed by a branch to the statements that follow the Accept.
9936 -- In the absence of delay alternatives, we generate:
9939 -- when No_Rendezvous => -- omitted if simple mode
9954 -- Lab0: Else_Statements;
9957 -- Lab1: Trailing_Statements1;
9960 -- Lab2: Trailing_Statements2;
9965 -- Generate label for common exit
9967 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9969 -- First entry is the default case, when no rendezvous is possible
9971 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9973 if Else_Present then
9975 -- If no rendezvous is possible, the else part is executed
9977 Lab := Make_And_Declare_Label (0);
9978 Alt_Stats := New_List (
9979 Make_Goto_Statement (Loc,
9980 Name => New_Copy (Identifier (Lab))));
9982 Append (Lab, Trailing_List);
9983 Append_List (Else_Statements (N), Trailing_List);
9984 Append_To (Trailing_List,
9985 Make_Goto_Statement (Loc,
9986 Name => New_Copy (Identifier (End_Lab))));
9988 Alt_Stats := New_List (
9989 Make_Goto_Statement (Loc,
9990 Name => New_Copy (Identifier (End_Lab))));
9993 Append_To (Alt_List,
9994 Make_Case_Statement_Alternative (Loc,
9995 Discrete_Choices => Choices,
9996 Statements => Alt_Stats));
9998 -- We make use of the fact that Accept_Index is an integer type, and
9999 -- generate successive literals for entries for each accept. Only those
10000 -- for which there is a body or trailing statements get a case entry.
10002 Alt := First (Select_Alternatives (N));
10003 Proc := First (Body_List);
10004 while Present (Alt) loop
10006 if Nkind (Alt) = N_Accept_Alternative then
10007 Process_Accept_Alternative (Alt, Index, Proc);
10008 Index := Index + 1;
10011 (Handled_Statement_Sequence (Accept_Statement (Alt)))
10016 elsif Nkind (Alt) = N_Delay_Alternative then
10017 Process_Delay_Alternative (Alt, Delay_Num);
10018 Delay_Num := Delay_Num + 1;
10024 -- An others choice is always added to the main case, as well
10025 -- as the delay case (to satisfy the compiler).
10027 Append_To (Alt_List,
10028 Make_Case_Statement_Alternative (Loc,
10029 Discrete_Choices =>
10030 New_List (Make_Others_Choice (Loc)),
10032 New_List (Make_Goto_Statement (Loc,
10033 Name => New_Copy (Identifier (End_Lab))))));
10035 Accept_Case := New_List (
10036 Make_Case_Statement (Loc,
10037 Expression => New_Reference_To (Xnam, Loc),
10038 Alternatives => Alt_List));
10040 Append_List (Trailing_List, Accept_Case);
10041 Append (End_Lab, Accept_Case);
10042 Append_List (Body_List, Decls);
10044 -- Construct case statement for trailing statements of delay
10045 -- alternatives, if there are several of them.
10047 if Delay_Count > 1 then
10048 Append_To (Delay_Alt_List,
10049 Make_Case_Statement_Alternative (Loc,
10050 Discrete_Choices =>
10051 New_List (Make_Others_Choice (Loc)),
10053 New_List (Make_Null_Statement (Loc))));
10055 Delay_Case := New_List (
10056 Make_Case_Statement (Loc,
10057 Expression => New_Reference_To (Delay_Index, Loc),
10058 Alternatives => Delay_Alt_List));
10060 Delay_Case := Delay_Alt_List;
10063 -- If there are no delay alternatives, we append the case statement
10064 -- to the statement list.
10066 if Delay_Count = 0 then
10067 Append_List (Accept_Case, Stats);
10069 -- Delay alternatives present
10072 -- If delay alternatives are present we generate:
10074 -- find minimum delay.
10075 -- DX := minimum delay;
10076 -- M := <delay mode>;
10077 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10080 -- if X = No_Rendezvous then
10081 -- case statement for delay statements.
10083 -- case statement for accept alternatives.
10094 -- The type of the delay expression is known to be legal
10096 if Time_Type = Standard_Duration then
10097 Conv := New_Reference_To (Delay_Min, Loc);
10099 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10100 Conv := Make_Function_Call (Loc,
10101 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10102 New_List (New_Reference_To (Delay_Min, Loc)));
10106 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10108 Conv := Make_Function_Call (Loc,
10109 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10110 New_List (New_Reference_To (Delay_Min, Loc)));
10113 Stmt := Make_Assignment_Statement (Loc,
10114 Name => New_Reference_To (D, Loc),
10115 Expression => Conv);
10117 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10119 Parms := Parameter_Associations (Select_Call);
10120 Parm := First (Parms);
10122 while Present (Parm)
10123 and then Parm /= Select_Mode
10128 pragma Assert (Present (Parm));
10129 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10132 -- Prepare two new parameters of Duration and Delay_Mode type
10133 -- which represent the value and the mode of the minimum delay.
10136 Insert_After (Parm, New_Reference_To (M, Loc));
10137 Insert_After (Parm, New_Reference_To (D, Loc));
10139 -- Create a call to RTS
10141 Rewrite (Select_Call,
10142 Make_Procedure_Call_Statement (Loc,
10143 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10144 Parameter_Associations => Parms));
10146 -- This new call should follow the calculation of the minimum
10149 Insert_List_Before (Select_Call, Delay_List);
10151 if Check_Guard then
10153 Make_Implicit_If_Statement (N,
10154 Condition => New_Reference_To (Guard_Open, Loc),
10156 New_List (New_Copy_Tree (Stmt),
10157 New_Copy_Tree (Select_Call)),
10158 Else_Statements => Accept_Or_Raise);
10159 Rewrite (Select_Call, Stmt);
10161 Insert_Before (Select_Call, Stmt);
10165 Make_Implicit_If_Statement (N,
10166 Condition => Make_Op_Eq (Loc,
10167 Left_Opnd => New_Reference_To (Xnam, Loc),
10169 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10171 Then_Statements => Delay_Case,
10172 Else_Statements => Accept_Case);
10174 Append (Cases, Stats);
10178 -- Replace accept statement with appropriate block
10181 Make_Block_Statement (Loc,
10182 Declarations => Decls,
10183 Handled_Statement_Sequence =>
10184 Make_Handled_Sequence_Of_Statements (Loc,
10185 Statements => Stats));
10187 Rewrite (N, Block);
10190 -- Note: have to worry more about abort deferral in above code ???
10192 -- Final step is to unstack the Accept_Address entries for all accept
10193 -- statements appearing in accept alternatives in the select statement
10195 Alt := First (Alts);
10196 while Present (Alt) loop
10197 if Nkind (Alt) = N_Accept_Alternative then
10198 Remove_Last_Elmt (Accept_Address
10199 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10204 end Expand_N_Selective_Accept;
10206 --------------------------------------
10207 -- Expand_N_Single_Task_Declaration --
10208 --------------------------------------
10210 -- Single task declarations should never be present after semantic
10211 -- analysis, since we expect them to be replaced by a declaration of an
10212 -- anonymous task type, followed by a declaration of the task object. We
10213 -- include this routine to make sure that is happening!
10215 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10217 raise Program_Error;
10218 end Expand_N_Single_Task_Declaration;
10220 ------------------------
10221 -- Expand_N_Task_Body --
10222 ------------------------
10224 -- Given a task body
10226 -- task body tname is
10232 -- This expansion routine converts it into a procedure and sets the
10233 -- elaboration flag for the procedure to true, to represent the fact
10234 -- that the task body is now elaborated:
10236 -- procedure tnameB (_Task : access tnameV) is
10237 -- discriminal : dtype renames _Task.discriminant;
10239 -- procedure _clean is
10241 -- Abort_Defer.all;
10243 -- Abort_Undefer.all;
10248 -- Abort_Undefer.all;
10250 -- System.Task_Stages.Complete_Activation;
10258 -- In addition, if the task body is an activator, then a call to activate
10259 -- tasks is added at the start of the statements, before the call to
10260 -- Complete_Activation, and if in addition the task is a master then it
10261 -- must be established as a master. These calls are inserted and analyzed
10262 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10265 -- There is one discriminal declaration line generated for each
10266 -- discriminant that is present to provide an easy reference point for
10267 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10269 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10270 -- task body procedures have a profile (Arg : System.Address). That is
10271 -- needed because GNARLI has to use the same access-to-subprogram type
10272 -- for all task types. We depend here on knowing that in GNAT, passing
10273 -- an address argument by value is identical to passing a record value
10274 -- by access (in either case a single pointer is passed), so even though
10275 -- this procedure has the wrong profile. In fact it's all OK, since the
10276 -- callings sequence is identical.
10278 procedure Expand_N_Task_Body (N : Node_Id) is
10279 Loc : constant Source_Ptr := Sloc (N);
10280 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10284 Insert_Nod : Node_Id;
10285 -- Used to determine the proper location of wrapper body insertions
10288 -- Add renaming declarations for discriminals and a declaration for the
10289 -- entry family index (if applicable).
10291 Install_Private_Data_Declarations
10292 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10294 -- Add a call to Abort_Undefer at the very beginning of the task
10295 -- body since this body is called with abort still deferred.
10297 if Abort_Allowed then
10298 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10300 (First (Statements (Handled_Statement_Sequence (N))), Call);
10304 -- The statement part has already been protected with an at_end and
10305 -- cleanup actions. The call to Complete_Activation must be placed
10306 -- at the head of the sequence of statements of that block. The
10307 -- declarations have been merged in this sequence of statements but
10308 -- the first real statement is accessible from the First_Real_Statement
10309 -- field (which was set for exactly this purpose).
10311 if Restricted_Profile then
10312 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10314 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10318 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10322 Make_Subprogram_Body (Loc,
10323 Specification => Build_Task_Proc_Specification (Ttyp),
10324 Declarations => Declarations (N),
10325 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10327 -- If the task contains generic instantiations, cleanup actions are
10328 -- delayed until after instantiation. Transfer the activation chain to
10329 -- the subprogram, to insure that the activation call is properly
10330 -- generated. It the task body contains inner tasks, indicate that the
10331 -- subprogram is a task master.
10333 if Delay_Cleanups (Ttyp) then
10334 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10335 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10338 Rewrite (N, New_N);
10341 -- Set elaboration flag immediately after task body. If the body is a
10342 -- subunit, the flag is set in the declarative part containing the stub.
10344 if Nkind (Parent (N)) /= N_Subunit then
10346 Make_Assignment_Statement (Loc,
10348 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10349 Expression => New_Reference_To (Standard_True, Loc)));
10352 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10353 -- the task body. At this point all wrapper specs have been created,
10354 -- frozen and included in the dispatch table for the task type.
10356 if Ada_Version >= Ada_2005 then
10357 if Nkind (Parent (N)) = N_Subunit then
10358 Insert_Nod := Corresponding_Stub (Parent (N));
10363 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10365 end Expand_N_Task_Body;
10367 ------------------------------------
10368 -- Expand_N_Task_Type_Declaration --
10369 ------------------------------------
10371 -- We have several things to do. First we must create a Boolean flag used
10372 -- to mark if the body is elaborated yet. This variable gets set to True
10373 -- when the body of the task is elaborated (we can't rely on the normal
10374 -- ABE mechanism for the task body, since we need to pass an access to
10375 -- this elaboration boolean to the runtime routines).
10377 -- taskE : aliased Boolean := False;
10379 -- Next a variable is declared to hold the task stack size (either the
10380 -- default : Unspecified_Size, or a value that is set by a pragma
10381 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10382 -- the variable is initialized with this value:
10384 -- taskZ : Size_Type := Unspecified_Size;
10386 -- taskZ : Size_Type := Size_Type (size_expression);
10388 -- Note: No variable is needed to hold the task relative deadline since
10389 -- its value would never be static because the parameter is of a private
10390 -- type (Ada.Real_Time.Time_Span).
10392 -- Next we create a corresponding record type declaration used to represent
10393 -- values of this task. The general form of this type declaration is
10395 -- type taskV (discriminants) is record
10396 -- _Task_Id : Task_Id;
10397 -- entry_family : array (bounds) of Void;
10398 -- _Priority : Integer := priority_expression;
10399 -- _Size : Size_Type := Size_Type (size_expression);
10400 -- _Task_Info : Task_Info_Type := task_info_expression;
10401 -- _CPU : Integer := cpu_range_expression;
10404 -- The discriminants are present only if the corresponding task type has
10405 -- discriminants, and they exactly mirror the task type discriminants.
10407 -- The Id field is always present. It contains the Task_Id value, as set by
10408 -- the call to Create_Task. Note that although the task is limited, the
10409 -- task value record type is not limited, so there is no problem in passing
10410 -- this field as an out parameter to Create_Task.
10412 -- One entry_family component is present for each entry family in the task
10413 -- definition. The bounds correspond to the bounds of the entry family
10414 -- (which may depend on discriminants). The element type is void, since we
10415 -- only need the bounds information for determining the entry index. Note
10416 -- that the use of an anonymous array would normally be illegal in this
10417 -- context, but this is a parser check, and the semantics is quite prepared
10418 -- to handle such a case.
10420 -- The _Size field is present only if a Storage_Size pragma appears in the
10421 -- task definition. The expression captures the argument that was present
10422 -- in the pragma, and is used to override the task stack size otherwise
10423 -- associated with the task type.
10425 -- The _Priority field is present only if a Priority or Interrupt_Priority
10426 -- pragma appears in the task definition. The expression captures the
10427 -- argument that was present in the pragma, and is used to provide the Size
10428 -- parameter to the call to Create_Task.
10430 -- The _Task_Info field is present only if a Task_Info pragma appears in
10431 -- the task definition. The expression captures the argument that was
10432 -- present in the pragma, and is used to provide the Task_Image parameter
10433 -- to the call to Create_Task.
10435 -- The _CPU field is present only if a CPU pragma appears in the task
10436 -- definition. The expression captures the argument that was present in
10437 -- the pragma, and is used to provide the CPU parameter to the call to
10440 -- The _Relative_Deadline field is present only if a Relative_Deadline
10441 -- pragma appears in the task definition. The expression captures the
10442 -- argument that was present in the pragma, and is used to provide the
10443 -- Relative_Deadline parameter to the call to Create_Task.
10445 -- When a task is declared, an instance of the task value record is
10446 -- created. The elaboration of this declaration creates the correct bounds
10447 -- for the entry families, and also evaluates the size, priority, and
10448 -- task_Info expressions if needed. The initialization routine for the task
10449 -- type itself then calls Create_Task with appropriate parameters to
10450 -- initialize the value of the Task_Id field.
10452 -- Note: the address of this record is passed as the "Discriminants"
10453 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10454 -- body procedure, it does not matter that it does not quite match the
10455 -- GNARLI model of what is being passed (the record contains more than just
10456 -- the discriminants, but the discriminants can be found from the record
10459 -- The Entity_Id for this created record type is placed in the
10460 -- Corresponding_Record_Type field of the associated task type entity.
10462 -- Next we create a procedure specification for the task body procedure:
10464 -- procedure taskB (_Task : access taskV);
10466 -- Note that this must come after the record type declaration, since
10467 -- the spec refers to this type. It turns out that the initialization
10468 -- procedure for the value type references the task body spec, but that's
10469 -- fine, since it won't be generated till the freeze point for the type,
10470 -- which is certainly after the task body spec declaration.
10472 -- Finally, we set the task index value field of the entry attribute in
10473 -- the case of a simple entry.
10475 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10476 Loc : constant Source_Ptr := Sloc (N);
10477 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10478 Tasknm : constant Name_Id := Chars (Tasktyp);
10479 Taskdef : constant Node_Id := Task_Definition (N);
10481 Proc_Spec : Node_Id;
10482 Rec_Decl : Node_Id;
10483 Rec_Ent : Entity_Id;
10485 Elab_Decl : Node_Id;
10486 Size_Decl : Node_Id;
10487 Body_Decl : Node_Id;
10488 Task_Size : Node_Id;
10489 Ent_Stack : Entity_Id;
10490 Decl_Stack : Node_Id;
10493 -- If already expanded, nothing to do
10495 if Present (Corresponding_Record_Type (Tasktyp)) then
10499 -- Here we will do the expansion
10501 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10503 Rec_Ent := Defining_Identifier (Rec_Decl);
10504 Cdecls := Component_Items (Component_List
10505 (Type_Definition (Rec_Decl)));
10507 Qualify_Entity_Names (N);
10509 -- First create the elaboration variable
10512 Make_Object_Declaration (Loc,
10513 Defining_Identifier =>
10514 Make_Defining_Identifier (Sloc (Tasktyp),
10515 Chars => New_External_Name (Tasknm, 'E')),
10516 Aliased_Present => True,
10517 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10518 Expression => New_Reference_To (Standard_False, Loc));
10519 Insert_After (N, Elab_Decl);
10521 -- Next create the declaration of the size variable (tasknmZ)
10523 Set_Storage_Size_Variable (Tasktyp,
10524 Make_Defining_Identifier (Sloc (Tasktyp),
10525 Chars => New_External_Name (Tasknm, 'Z')));
10527 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
10528 Is_Static_Expression (Expression (First (
10529 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
10530 Taskdef, Name_Storage_Size)))))
10533 Make_Object_Declaration (Loc,
10534 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10535 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10537 Convert_To (RTE (RE_Size_Type),
10539 Expression (First (
10540 Pragma_Argument_Associations (
10541 Find_Task_Or_Protected_Pragma
10542 (Taskdef, Name_Storage_Size)))))));
10546 Make_Object_Declaration (Loc,
10547 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10548 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10549 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10552 Insert_After (Elab_Decl, Size_Decl);
10554 -- Next build the rest of the corresponding record declaration. This is
10555 -- done last, since the corresponding record initialization procedure
10556 -- will reference the previously created entities.
10558 -- Fill in the component declarations -- first the _Task_Id field
10561 Make_Component_Declaration (Loc,
10562 Defining_Identifier =>
10563 Make_Defining_Identifier (Loc, Name_uTask_Id),
10564 Component_Definition =>
10565 Make_Component_Definition (Loc,
10566 Aliased_Present => False,
10567 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10570 -- Declare static ATCB (that is, created by the expander) if we are
10571 -- using the Restricted run time.
10573 if Restricted_Profile then
10575 Make_Component_Declaration (Loc,
10576 Defining_Identifier =>
10577 Make_Defining_Identifier (Loc, Name_uATCB),
10579 Component_Definition =>
10580 Make_Component_Definition (Loc,
10581 Aliased_Present => True,
10582 Subtype_Indication => Make_Subtype_Indication (Loc,
10583 Subtype_Mark => New_Occurrence_Of
10584 (RTE (RE_Ada_Task_Control_Block), Loc),
10587 Make_Index_Or_Discriminant_Constraint (Loc,
10589 New_List (Make_Integer_Literal (Loc, 0)))))));
10593 -- Declare static stack (that is, created by the expander) if we are
10594 -- using the Restricted run time on a bare board configuration.
10596 if Restricted_Profile
10597 and then Preallocated_Stacks_On_Target
10599 -- First we need to extract the appropriate stack size
10601 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10603 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10605 Expr_N : constant Node_Id :=
10606 Expression (First (
10607 Pragma_Argument_Associations (
10608 Find_Task_Or_Protected_Pragma
10609 (Taskdef, Name_Storage_Size))));
10610 Etyp : constant Entity_Id := Etype (Expr_N);
10611 P : constant Node_Id := Parent (Expr_N);
10614 -- The stack is defined inside the corresponding record.
10615 -- Therefore if the size of the stack is set by means of
10616 -- a discriminant, we must reference the discriminant of the
10617 -- corresponding record type.
10619 if Nkind (Expr_N) in N_Has_Entity
10620 and then Present (Discriminal_Link (Entity (Expr_N)))
10624 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10626 Set_Parent (Task_Size, P);
10627 Set_Etype (Task_Size, Etyp);
10628 Set_Analyzed (Task_Size);
10631 Task_Size := Relocate_Node (Expr_N);
10637 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10640 Decl_Stack := Make_Component_Declaration (Loc,
10641 Defining_Identifier => Ent_Stack,
10643 Component_Definition =>
10644 Make_Component_Definition (Loc,
10645 Aliased_Present => True,
10646 Subtype_Indication => Make_Subtype_Indication (Loc,
10648 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10651 Make_Index_Or_Discriminant_Constraint (Loc,
10652 Constraints => New_List (Make_Range (Loc,
10653 Low_Bound => Make_Integer_Literal (Loc, 1),
10654 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10657 Append_To (Cdecls, Decl_Stack);
10659 -- The appropriate alignment for the stack is ensured by the run-time
10660 -- code in charge of task creation.
10664 -- Add components for entry families
10666 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10668 -- Add the _Priority component if a Priority pragma is present
10670 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10672 Prag : constant Node_Id :=
10673 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10677 Expr := First (Pragma_Argument_Associations (Prag));
10679 if Nkind (Expr) = N_Pragma_Argument_Association then
10680 Expr := Expression (Expr);
10683 Expr := New_Copy_Tree (Expr);
10685 -- Add conversion to proper type to do range check if required
10686 -- Note that for runtime units, we allow out of range interrupt
10687 -- priority values to be used in a priority pragma. This is for
10688 -- the benefit of some versions of System.Interrupts which use
10689 -- a special server task with maximum interrupt priority.
10691 if Pragma_Name (Prag) = Name_Priority
10692 and then not GNAT_Mode
10694 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10696 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10700 Make_Component_Declaration (Loc,
10701 Defining_Identifier =>
10702 Make_Defining_Identifier (Loc, Name_uPriority),
10703 Component_Definition =>
10704 Make_Component_Definition (Loc,
10705 Aliased_Present => False,
10706 Subtype_Indication => New_Reference_To (Standard_Integer,
10708 Expression => Expr));
10712 -- Add the _Task_Size component if a Storage_Size pragma is present
10714 if Present (Taskdef)
10715 and then Has_Storage_Size_Pragma (Taskdef)
10718 Make_Component_Declaration (Loc,
10719 Defining_Identifier =>
10720 Make_Defining_Identifier (Loc, Name_uSize),
10722 Component_Definition =>
10723 Make_Component_Definition (Loc,
10724 Aliased_Present => False,
10725 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10729 Convert_To (RTE (RE_Size_Type),
10731 Expression (First (
10732 Pragma_Argument_Associations (
10733 Find_Task_Or_Protected_Pragma
10734 (Taskdef, Name_Storage_Size))))))));
10737 -- Add the _Task_Info component if a Task_Info pragma is present
10739 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10741 Make_Component_Declaration (Loc,
10742 Defining_Identifier =>
10743 Make_Defining_Identifier (Loc, Name_uTask_Info),
10745 Component_Definition =>
10746 Make_Component_Definition (Loc,
10747 Aliased_Present => False,
10748 Subtype_Indication =>
10749 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10751 Expression => New_Copy (
10752 Expression (First (
10753 Pragma_Argument_Associations (
10754 Find_Task_Or_Protected_Pragma
10755 (Taskdef, Name_Task_Info)))))));
10758 -- Add the _CPU component if a CPU pragma is present
10760 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
10762 Make_Component_Declaration (Loc,
10763 Defining_Identifier =>
10764 Make_Defining_Identifier (Loc, Name_uCPU),
10766 Component_Definition =>
10767 Make_Component_Definition (Loc,
10768 Aliased_Present => False,
10769 Subtype_Indication =>
10770 New_Reference_To (RTE (RE_CPU_Range), Loc)),
10772 Expression => New_Copy (
10773 Expression (First (
10774 Pragma_Argument_Associations (
10775 Find_Task_Or_Protected_Pragma
10776 (Taskdef, Name_CPU)))))));
10779 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10780 -- present. If we are using a restricted run time this component will
10781 -- not be added (deadlines are not allowed by the Ravenscar profile).
10783 if not Restricted_Profile
10784 and then Present (Taskdef)
10785 and then Has_Relative_Deadline_Pragma (Taskdef)
10788 Make_Component_Declaration (Loc,
10789 Defining_Identifier =>
10790 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10792 Component_Definition =>
10793 Make_Component_Definition (Loc,
10794 Aliased_Present => False,
10795 Subtype_Indication =>
10796 New_Reference_To (RTE (RE_Time_Span), Loc)),
10799 Convert_To (RTE (RE_Time_Span),
10801 Expression (First (
10802 Pragma_Argument_Associations (
10803 Find_Task_Or_Protected_Pragma
10804 (Taskdef, Name_Relative_Deadline))))))));
10807 Insert_After (Size_Decl, Rec_Decl);
10809 -- Analyze the record declaration immediately after construction,
10810 -- because the initialization procedure is needed for single task
10811 -- declarations before the next entity is analyzed.
10813 Analyze (Rec_Decl);
10815 -- Create the declaration of the task body procedure
10817 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10819 Make_Subprogram_Declaration (Loc,
10820 Specification => Proc_Spec);
10822 Insert_After (Rec_Decl, Body_Decl);
10824 -- The subprogram does not comes from source, so we have to indicate the
10825 -- need for debugging information explicitly.
10827 if Comes_From_Source (Original_Node (N)) then
10828 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10831 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10832 -- the corresponding record has been frozen.
10834 if Ada_Version >= Ada_2005 then
10835 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10838 -- Ada 2005 (AI-345): We must defer freezing to allow further
10839 -- declaration of primitive subprograms covering task interfaces
10841 if Ada_Version <= Ada_95 then
10843 -- Now we can freeze the corresponding record. This needs manually
10844 -- freezing, since it is really part of the task type, and the task
10845 -- type is frozen at this stage. We of course need the initialization
10846 -- procedure for this corresponding record type and we won't get it
10847 -- in time if we don't freeze now.
10850 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
10852 if Is_Non_Empty_List (L) then
10853 Insert_List_After (Body_Decl, L);
10858 -- Complete the expansion of access types to the current task type, if
10859 -- any were declared.
10861 Expand_Previous_Access_Type (Tasktyp);
10863 -- Create wrappers for entries that have pre/postconditions
10869 Ent := First_Entity (Tasktyp);
10870 while Present (Ent) loop
10871 if Ekind_In (Ent, E_Entry, E_Entry_Family)
10872 and then Present (Spec_PPC_List (Contract (Ent)))
10874 Build_PPC_Wrapper (Ent, N);
10880 end Expand_N_Task_Type_Declaration;
10882 -------------------------------
10883 -- Expand_N_Timed_Entry_Call --
10884 -------------------------------
10886 -- A timed entry call in normal case is not implemented using ATC mechanism
10887 -- anymore for efficiency reason.
10897 -- is expanded as follow:
10899 -- 1) When T.E is a task entry_call;
10903 -- X : Task_Entry_Index := <entry index>;
10904 -- DX : Duration := To_Duration (D);
10905 -- M : Delay_Mode := <discriminant>;
10906 -- P : parms := (parm, parm, parm);
10909 -- Timed_Protected_Entry_Call
10910 -- (<acceptor-task>, X, P'Address, DX, M, B);
10918 -- 2) When T.E is a protected entry_call;
10922 -- X : Protected_Entry_Index := <entry index>;
10923 -- DX : Duration := To_Duration (D);
10924 -- M : Delay_Mode := <discriminant>;
10925 -- P : parms := (parm, parm, parm);
10928 -- Timed_Protected_Entry_Call
10929 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10937 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10940 -- B : Boolean := False;
10941 -- C : Ada.Tags.Prim_Op_Kind;
10942 -- DX : Duration := To_Duration (D)
10943 -- K : Ada.Tags.Tagged_Kind :=
10944 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10945 -- M : Integer :=...;
10946 -- P : Parameters := (Param1 .. ParamN);
10950 -- if K = Ada.Tags.TK_Limited_Tagged then
10951 -- <dispatching-call>;
10952 -- <triggering-statements>
10956 -- Ada.Tags.Get_Offset_Index
10957 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10959 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10961 -- if C = POK_Protected_Entry
10962 -- or else C = POK_Task_Entry
10964 -- Param1 := P.Param1;
10966 -- ParamN := P.ParamN;
10970 -- if C = POK_Procedure
10971 -- or else C = POK_Protected_Procedure
10972 -- or else C = POK_Task_Procedure
10974 -- <dispatching-call>;
10977 -- <triggering-statements>
10979 -- <timed-statements>
10984 -- The triggering statement and the sequence of timed statements have not
10985 -- been analyzed yet (see Analyzed_Timed_Entry_Call). They may contain
10986 -- local declarations, and therefore the copies that are made during
10987 -- expansion must be disjoint, as for any other inlining.
10989 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10990 Loc : constant Source_Ptr := Sloc (N);
10992 E_Call : Node_Id :=
10993 Entry_Call_Statement (Entry_Call_Alternative (N));
10994 E_Stats : constant List_Id :=
10995 Statements (Entry_Call_Alternative (N));
10996 D_Stat : Node_Id :=
10997 Delay_Statement (Delay_Alternative (N));
10998 D_Stats : constant List_Id :=
10999 Statements (Delay_Alternative (N));
11002 Blk_Typ : Entity_Id;
11004 Call_Ent : Entity_Id;
11005 Conc_Typ_Stmts : List_Id;
11009 D_Type : Entity_Id;
11015 Is_Disp_Select : Boolean;
11016 Lim_Typ_Stmts : List_Id;
11025 B : Entity_Id; -- Call status flag
11026 C : Entity_Id; -- Call kind
11027 D : Entity_Id; -- Delay
11028 K : Entity_Id; -- Tagged kind
11029 M : Entity_Id; -- Delay mode
11030 P : Entity_Id; -- Parameter block
11031 S : Entity_Id; -- Primitive operation slot
11034 -- Under the Ravenscar profile, timed entry calls are excluded. An error
11035 -- was already reported on spec, so do not attempt to expand the call.
11037 if Restriction_Active (No_Select_Statements) then
11041 Process_Statements_For_Controlled_Objects (Entry_Call_Alternative (N));
11042 Process_Statements_For_Controlled_Objects (Delay_Alternative (N));
11044 -- The arguments in the call may require dynamic allocation, and the
11045 -- call statement may have been transformed into a block. The block
11046 -- may contain additional declarations for internal entities, and the
11047 -- original call is found by sequential search.
11049 if Nkind (E_Call) = N_Block_Statement then
11050 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
11051 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
11052 N_Entry_Call_Statement)
11059 Ada_Version >= Ada_2005
11060 and then Nkind (E_Call) = N_Procedure_Call_Statement;
11062 if Is_Disp_Select then
11063 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11069 -- B : Boolean := False;
11071 B := Build_B (Loc, Decls);
11074 -- C : Ada.Tags.Prim_Op_Kind;
11076 C := Build_C (Loc, Decls);
11078 -- Because the analysis of all statements was disabled, manually
11079 -- analyze the delay statement.
11082 D_Stat := Original_Node (D_Stat);
11085 -- Build an entry call using Simple_Entry_Call
11087 Extract_Entry (E_Call, Concval, Ename, Index);
11088 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11090 Decls := Declarations (E_Call);
11091 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11100 B := Make_Defining_Identifier (Loc, Name_uB);
11103 Make_Object_Declaration (Loc,
11104 Defining_Identifier =>
11106 Object_Definition =>
11107 New_Reference_To (Standard_Boolean, Loc)));
11110 -- Duration and mode processing
11112 D_Type := Base_Type (Etype (Expression (D_Stat)));
11114 -- Use the type of the delay expression (Calendar or Real_Time) to
11115 -- generate the appropriate conversion.
11117 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11118 D_Disc := Make_Integer_Literal (Loc, 0);
11119 D_Conv := Relocate_Node (Expression (D_Stat));
11121 elsif Is_RTE (D_Type, RO_CA_Time) then
11122 D_Disc := Make_Integer_Literal (Loc, 1);
11123 D_Conv := Make_Function_Call (Loc,
11124 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11125 New_List (New_Copy (Expression (D_Stat))));
11127 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11128 D_Disc := Make_Integer_Literal (Loc, 2);
11129 D_Conv := Make_Function_Call (Loc,
11130 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11131 New_List (New_Copy (Expression (D_Stat))));
11134 D := Make_Temporary (Loc, 'D');
11140 Make_Object_Declaration (Loc,
11141 Defining_Identifier =>
11143 Object_Definition =>
11144 New_Reference_To (Standard_Duration, Loc)));
11146 M := Make_Temporary (Loc, 'M');
11149 -- M : Integer := (0 | 1 | 2);
11152 Make_Object_Declaration (Loc,
11153 Defining_Identifier =>
11155 Object_Definition =>
11156 New_Reference_To (Standard_Integer, Loc),
11160 -- Do the assignment at this stage only because the evaluation of the
11161 -- expression must not occur before (see ACVC C97302A).
11164 Make_Assignment_Statement (Loc,
11166 New_Reference_To (D, Loc),
11170 -- Parameter block processing
11172 -- Manually create the parameter block for dispatching calls. In the
11173 -- case of entries, the block has already been created during the call
11174 -- to Build_Simple_Entry_Call.
11176 if Is_Disp_Select then
11178 -- Tagged kind processing, generate:
11179 -- K : Ada.Tags.Tagged_Kind :=
11180 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11182 K := Build_K (Loc, Decls, Obj);
11184 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11185 P := Parameter_Block_Pack
11186 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11188 -- Dispatch table slot processing, generate:
11191 S := Build_S (Loc, Decls);
11194 -- S := Ada.Tags.Get_Offset_Index
11195 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11198 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11201 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11203 -- where Obj is the controlling formal parameter, S is the dispatch
11204 -- table slot number of the dispatching operation, P is the wrapped
11205 -- parameter block, D is the duration, M is the duration mode, C is
11206 -- the call kind and B is the call status.
11208 Params := New_List;
11210 Append_To (Params, New_Copy_Tree (Obj));
11211 Append_To (Params, New_Reference_To (S, Loc));
11212 Append_To (Params, Make_Attribute_Reference (Loc,
11213 Prefix => New_Reference_To (P, Loc),
11214 Attribute_Name => Name_Address));
11215 Append_To (Params, New_Reference_To (D, Loc));
11216 Append_To (Params, New_Reference_To (M, Loc));
11217 Append_To (Params, New_Reference_To (C, Loc));
11218 Append_To (Params, New_Reference_To (B, Loc));
11220 Append_To (Conc_Typ_Stmts,
11221 Make_Procedure_Call_Statement (Loc,
11224 Find_Prim_Op (Etype (Etype (Obj)),
11225 Name_uDisp_Timed_Select),
11227 Parameter_Associations =>
11231 -- if C = POK_Protected_Entry
11232 -- or else C = POK_Task_Entry
11234 -- Param1 := P.Param1;
11236 -- ParamN := P.ParamN;
11239 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11241 -- Generate the if statement only when the packed parameters need
11242 -- explicit assignments to their corresponding actuals.
11244 if Present (Unpack) then
11245 Append_To (Conc_Typ_Stmts,
11246 Make_If_Statement (Loc,
11253 New_Reference_To (C, Loc),
11255 New_Reference_To (RTE (
11256 RE_POK_Protected_Entry), Loc)),
11260 New_Reference_To (C, Loc),
11262 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11271 -- if C = POK_Procedure
11272 -- or else C = POK_Protected_Procedure
11273 -- or else C = POK_Task_Procedure
11275 -- <dispatching-call>
11277 -- <triggering-statements>
11279 -- <timed-statements>
11282 N_Stats := Copy_Separate_List (E_Stats);
11284 Prepend_To (N_Stats,
11285 Make_If_Statement (Loc,
11292 New_Reference_To (C, Loc),
11294 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11300 New_Reference_To (C, Loc),
11302 New_Reference_To (RTE (
11303 RE_POK_Protected_Procedure), Loc)),
11307 New_Reference_To (C, Loc),
11309 New_Reference_To (RTE (
11310 RE_POK_Task_Procedure), Loc)))),
11313 New_List (E_Call)));
11315 Append_To (Conc_Typ_Stmts,
11316 Make_If_Statement (Loc,
11317 Condition => New_Reference_To (B, Loc),
11318 Then_Statements => N_Stats,
11319 Else_Statements => D_Stats));
11322 -- <dispatching-call>;
11323 -- <triggering-statements>
11325 Lim_Typ_Stmts := Copy_Separate_List (E_Stats);
11326 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11329 -- if K = Ada.Tags.TK_Limited_Tagged then
11336 Make_If_Statement (Loc,
11340 New_Reference_To (K, Loc),
11342 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11351 -- Skip assignments to temporaries created for in-out parameters.
11352 -- This makes unwarranted assumptions about the shape of the expanded
11353 -- tree for the call, and should be cleaned up ???
11355 Stmt := First (Stmts);
11356 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11360 -- Do the assignment at this stage only because the evaluation
11361 -- of the expression must not occur before (see ACVC C97302A).
11363 Insert_Before (Stmt,
11364 Make_Assignment_Statement (Loc,
11365 Name => New_Reference_To (D, Loc),
11366 Expression => D_Conv));
11369 Params := Parameter_Associations (Call);
11371 -- For a protected type, we build a Timed_Protected_Entry_Call
11373 if Is_Protected_Type (Etype (Concval)) then
11375 -- Create a new call statement
11377 Param := First (Params);
11378 while Present (Param)
11379 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11384 Dummy := Remove_Next (Next (Param));
11386 -- Remove garbage is following the Cancel_Param if present
11388 Dummy := Next (Param);
11390 -- Remove the mode of the Protected_Entry_Call call, then remove
11391 -- the Communication_Block of the Protected_Entry_Call call, and
11392 -- finally add Duration and a Delay_Mode parameter
11394 pragma Assert (Present (Param));
11395 Rewrite (Param, New_Reference_To (D, Loc));
11397 Rewrite (Dummy, New_Reference_To (M, Loc));
11399 -- Add a Boolean flag for successful entry call
11401 Append_To (Params, New_Reference_To (B, Loc));
11403 case Corresponding_Runtime_Package (Etype (Concval)) is
11404 when System_Tasking_Protected_Objects_Entries =>
11406 Make_Procedure_Call_Statement (Loc,
11409 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11410 Parameter_Associations => Params));
11412 when System_Tasking_Protected_Objects_Single_Entry =>
11413 Param := First (Params);
11414 while Present (Param)
11416 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11424 Make_Procedure_Call_Statement (Loc,
11425 Name => New_Reference_To (
11426 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11427 Parameter_Associations => Params));
11430 raise Program_Error;
11433 -- For the task case, build a Timed_Task_Entry_Call
11436 -- Create a new call statement
11438 Append_To (Params, New_Reference_To (D, Loc));
11439 Append_To (Params, New_Reference_To (M, Loc));
11440 Append_To (Params, New_Reference_To (B, Loc));
11443 Make_Procedure_Call_Statement (Loc,
11445 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11446 Parameter_Associations => Params));
11450 Make_Implicit_If_Statement (N,
11451 Condition => New_Reference_To (B, Loc),
11452 Then_Statements => E_Stats,
11453 Else_Statements => D_Stats));
11457 Make_Block_Statement (Loc,
11458 Declarations => Decls,
11459 Handled_Statement_Sequence =>
11460 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11463 end Expand_N_Timed_Entry_Call;
11465 ----------------------------------------
11466 -- Expand_Protected_Body_Declarations --
11467 ----------------------------------------
11469 procedure Expand_Protected_Body_Declarations
11471 Spec_Id : Entity_Id)
11474 if No_Run_Time_Mode then
11475 Error_Msg_CRT ("protected body", N);
11478 elsif Expander_Active then
11480 -- Associate discriminals with the first subprogram or entry body to
11483 if Present (First_Protected_Operation (Declarations (N))) then
11484 Set_Discriminals (Parent (Spec_Id));
11487 end Expand_Protected_Body_Declarations;
11489 -------------------------
11490 -- External_Subprogram --
11491 -------------------------
11493 function External_Subprogram (E : Entity_Id) return Entity_Id is
11494 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11497 -- The internal and external subprograms follow each other on the entity
11498 -- chain. Note that previously private operations had no separate
11499 -- external subprogram. We now create one in all cases, because a
11500 -- private operation may actually appear in an external call, through
11501 -- a 'Access reference used for a callback.
11503 -- If the operation is a function that returns an anonymous access type,
11504 -- the corresponding itype appears before the operation, and must be
11507 -- This mechanism is fragile, there should be a real link between the
11508 -- two versions of the operation, but there is no place to put it ???
11510 if Is_Access_Type (Next_Entity (Subp)) then
11511 return Next_Entity (Next_Entity (Subp));
11513 return Next_Entity (Subp);
11515 end External_Subprogram;
11517 ------------------------------
11518 -- Extract_Dispatching_Call --
11519 ------------------------------
11521 procedure Extract_Dispatching_Call
11523 Call_Ent : out Entity_Id;
11524 Object : out Entity_Id;
11525 Actuals : out List_Id;
11526 Formals : out List_Id)
11528 Call_Nam : Node_Id;
11531 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11533 if Present (Original_Node (N)) then
11534 Call_Nam := Name (Original_Node (N));
11536 Call_Nam := Name (N);
11539 -- Retrieve the name of the dispatching procedure. It contains the
11540 -- dispatch table slot number.
11543 case Nkind (Call_Nam) is
11544 when N_Identifier =>
11547 when N_Selected_Component =>
11548 Call_Nam := Selector_Name (Call_Nam);
11551 raise Program_Error;
11556 Actuals := Parameter_Associations (N);
11557 Call_Ent := Entity (Call_Nam);
11558 Formals := Parameter_Specifications (Parent (Call_Ent));
11559 Object := First (Actuals);
11561 if Present (Original_Node (Object)) then
11562 Object := Original_Node (Object);
11565 -- If the type of the dispatching object is an access type then return
11566 -- an explicit dereference.
11568 if Is_Access_Type (Etype (Object)) then
11569 Object := Make_Explicit_Dereference (Sloc (N), Object);
11572 end Extract_Dispatching_Call;
11574 -------------------
11575 -- Extract_Entry --
11576 -------------------
11578 procedure Extract_Entry
11580 Concval : out Node_Id;
11581 Ename : out Node_Id;
11582 Index : out Node_Id)
11584 Nam : constant Node_Id := Name (N);
11587 -- For a simple entry, the name is a selected component, with the
11588 -- prefix being the task value, and the selector being the entry.
11590 if Nkind (Nam) = N_Selected_Component then
11591 Concval := Prefix (Nam);
11592 Ename := Selector_Name (Nam);
11595 -- For a member of an entry family, the name is an indexed component
11596 -- where the prefix is a selected component, whose prefix in turn is
11597 -- the task value, and whose selector is the entry family. The single
11598 -- expression in the expressions list of the indexed component is the
11599 -- subscript for the family.
11601 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11602 Concval := Prefix (Prefix (Nam));
11603 Ename := Selector_Name (Prefix (Nam));
11604 Index := First (Expressions (Nam));
11608 -------------------
11609 -- Family_Offset --
11610 -------------------
11612 function Family_Offset
11617 Cap : Boolean) return Node_Id
11623 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11624 -- If one of the bounds is a reference to a discriminant, replace with
11625 -- corresponding discriminal of type. Within the body of a task retrieve
11626 -- the renamed discriminant by simple visibility, using its generated
11627 -- name. Within a protected object, find the original discriminant and
11628 -- replace it with the discriminal of the current protected operation.
11630 ------------------------------
11631 -- Convert_Discriminant_Ref --
11632 ------------------------------
11634 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11635 Loc : constant Source_Ptr := Sloc (Bound);
11640 if Is_Entity_Name (Bound)
11641 and then Ekind (Entity (Bound)) = E_Discriminant
11643 if Is_Task_Type (Ttyp)
11644 and then Has_Completion (Ttyp)
11646 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11647 Find_Direct_Name (B);
11649 elsif Is_Protected_Type (Ttyp) then
11650 D := First_Discriminant (Ttyp);
11651 while Chars (D) /= Chars (Entity (Bound)) loop
11652 Next_Discriminant (D);
11655 B := New_Reference_To (Discriminal (D), Loc);
11658 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11661 elsif Nkind (Bound) = N_Attribute_Reference then
11665 B := New_Copy_Tree (Bound);
11669 Make_Attribute_Reference (Loc,
11670 Attribute_Name => Name_Pos,
11671 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11672 Expressions => New_List (B));
11673 end Convert_Discriminant_Ref;
11675 -- Start of processing for Family_Offset
11678 Real_Hi := Convert_Discriminant_Ref (Hi);
11679 Real_Lo := Convert_Discriminant_Ref (Lo);
11682 if Is_Task_Type (Ttyp) then
11683 Ityp := RTE (RE_Task_Entry_Index);
11685 Ityp := RTE (RE_Protected_Entry_Index);
11689 Make_Attribute_Reference (Loc,
11690 Prefix => New_Reference_To (Ityp, Loc),
11691 Attribute_Name => Name_Min,
11692 Expressions => New_List (
11694 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11697 Make_Attribute_Reference (Loc,
11698 Prefix => New_Reference_To (Ityp, Loc),
11699 Attribute_Name => Name_Max,
11700 Expressions => New_List (
11702 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11705 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11712 function Family_Size
11717 Cap : Boolean) return Node_Id
11722 if Is_Task_Type (Ttyp) then
11723 Ityp := RTE (RE_Task_Entry_Index);
11725 Ityp := RTE (RE_Protected_Entry_Index);
11729 Make_Attribute_Reference (Loc,
11730 Prefix => New_Reference_To (Ityp, Loc),
11731 Attribute_Name => Name_Max,
11732 Expressions => New_List (
11735 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11737 Make_Integer_Literal (Loc, 1)),
11738 Make_Integer_Literal (Loc, 0)));
11741 -----------------------
11742 -- Find_Master_Scope --
11743 -----------------------
11745 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
11749 -- In Ada2005, the master is the innermost enclosing scope that is not
11750 -- transient. If the enclosing block is the rewriting of a call or the
11751 -- scope is an extended return statement this is valid master. The
11752 -- master in an extended return is only used within the return, and is
11753 -- subsequently overwritten in Move_Activation_Chain, but it must exist
11754 -- now before that overwriting occurs.
11758 if Ada_Version >= Ada_2005 then
11759 while Is_Internal (S) loop
11760 if Nkind (Parent (S)) = N_Block_Statement
11762 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
11766 elsif Ekind (S) = E_Return_Statement then
11776 end Find_Master_Scope;
11778 -----------------------------------
11779 -- Find_Task_Or_Protected_Pragma --
11780 -----------------------------------
11782 function Find_Task_Or_Protected_Pragma
11784 P : Name_Id) return Node_Id
11789 N := First (Visible_Declarations (T));
11790 while Present (N) loop
11791 if Nkind (N) = N_Pragma then
11792 if Pragma_Name (N) = P then
11795 elsif P = Name_Priority
11796 and then Pragma_Name (N) = Name_Interrupt_Priority
11809 N := First (Private_Declarations (T));
11810 while Present (N) loop
11811 if Nkind (N) = N_Pragma then
11812 if Pragma_Name (N) = P then
11815 elsif P = Name_Priority
11816 and then Pragma_Name (N) = Name_Interrupt_Priority
11829 raise Program_Error;
11830 end Find_Task_Or_Protected_Pragma;
11832 -------------------------------
11833 -- First_Protected_Operation --
11834 -------------------------------
11836 function First_Protected_Operation (D : List_Id) return Node_Id is
11837 First_Op : Node_Id;
11840 First_Op := First (D);
11841 while Present (First_Op)
11842 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11848 end First_Protected_Operation;
11850 ---------------------------------------
11851 -- Install_Private_Data_Declarations --
11852 ---------------------------------------
11854 procedure Install_Private_Data_Declarations
11856 Spec_Id : Entity_Id;
11857 Conc_Typ : Entity_Id;
11858 Body_Nod : Node_Id;
11860 Barrier : Boolean := False;
11861 Family : Boolean := False)
11863 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11866 Insert_Node : Node_Id := Empty;
11867 Obj_Ent : Entity_Id;
11869 procedure Add (Decl : Node_Id);
11870 -- Add a single declaration after Insert_Node. If this is the first
11871 -- addition, Decl is added to the front of Decls and it becomes the
11874 function Replace_Bound (Bound : Node_Id) return Node_Id;
11875 -- The bounds of an entry index may depend on discriminants, create a
11876 -- reference to the corresponding prival. Otherwise return a duplicate
11877 -- of the original bound.
11883 procedure Add (Decl : Node_Id) is
11885 if No (Insert_Node) then
11886 Prepend_To (Decls, Decl);
11888 Insert_After (Insert_Node, Decl);
11891 Insert_Node := Decl;
11894 --------------------------
11895 -- Replace_Discriminant --
11896 --------------------------
11898 function Replace_Bound (Bound : Node_Id) return Node_Id is
11900 if Nkind (Bound) = N_Identifier
11901 and then Is_Discriminal (Entity (Bound))
11903 return Make_Identifier (Loc, Chars (Entity (Bound)));
11905 return Duplicate_Subexpr (Bound);
11909 -- Start of processing for Install_Private_Data_Declarations
11912 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11913 -- formal parameter _O, _object or _task depending on the context.
11915 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11917 -- Special processing of _O for barrier functions, protected entries
11924 (Ekind (Spec_Id) = E_Entry
11925 or else Ekind (Spec_Id) = E_Entry_Family))
11928 Conc_Rec : constant Entity_Id :=
11929 Corresponding_Record_Type (Conc_Typ);
11930 Typ_Id : constant Entity_Id :=
11931 Make_Defining_Identifier (Loc,
11932 New_External_Name (Chars (Conc_Rec), 'P'));
11935 -- type prot_typVP is access prot_typV;
11938 Make_Full_Type_Declaration (Loc,
11939 Defining_Identifier => Typ_Id,
11941 Make_Access_To_Object_Definition (Loc,
11942 Subtype_Indication =>
11943 New_Reference_To (Conc_Rec, Loc)));
11947 -- _object : prot_typVP := prot_typV (_O);
11950 Make_Object_Declaration (Loc,
11951 Defining_Identifier =>
11952 Make_Defining_Identifier (Loc, Name_uObject),
11953 Object_Definition => New_Reference_To (Typ_Id, Loc),
11955 Unchecked_Convert_To (Typ_Id,
11956 New_Reference_To (Obj_Ent, Loc)));
11959 -- Set the reference to the concurrent object
11961 Obj_Ent := Defining_Identifier (Decl);
11965 -- Step 2: Create the Protection object and build its declaration for
11966 -- any protected entry (family) of subprogram.
11968 if Is_Protected then
11970 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
11974 Set_Protection_Object (Spec_Id, Prot_Ent);
11976 -- Determine the proper protection type
11978 if Has_Attach_Handler (Conc_Typ)
11979 and then not Restricted_Profile
11981 Prot_Typ := RE_Static_Interrupt_Protection;
11983 elsif Has_Interrupt_Handler (Conc_Typ) then
11984 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11986 -- The type has explicit entries or generated primitive entry
11989 elsif Has_Entries (Conc_Typ)
11991 (Ada_Version >= Ada_2005
11992 and then Present (Interface_List (Parent (Conc_Typ))))
11994 case Corresponding_Runtime_Package (Conc_Typ) is
11995 when System_Tasking_Protected_Objects_Entries =>
11996 Prot_Typ := RE_Protection_Entries;
11998 when System_Tasking_Protected_Objects_Single_Entry =>
11999 Prot_Typ := RE_Protection_Entry;
12002 raise Program_Error;
12006 Prot_Typ := RE_Protection;
12010 -- conc_typR : protection_typ renames _object._object;
12013 Make_Object_Renaming_Declaration (Loc,
12014 Defining_Identifier => Prot_Ent,
12016 New_Reference_To (RTE (Prot_Typ), Loc),
12018 Make_Selected_Component (Loc,
12019 Prefix => New_Reference_To (Obj_Ent, Loc),
12020 Selector_Name => Make_Identifier (Loc, Name_uObject)));
12025 -- Step 3: Add discriminant renamings (if any)
12027 if Has_Discriminants (Conc_Typ) then
12032 D := First_Discriminant (Conc_Typ);
12033 while Present (D) loop
12035 -- Adjust the source location
12037 Set_Sloc (Discriminal (D), Loc);
12040 -- discr_name : discr_typ renames _object.discr_name;
12042 -- discr_name : discr_typ renames _task.discr_name;
12045 Make_Object_Renaming_Declaration (Loc,
12046 Defining_Identifier => Discriminal (D),
12047 Subtype_Mark => New_Reference_To (Etype (D), Loc),
12049 Make_Selected_Component (Loc,
12050 Prefix => New_Reference_To (Obj_Ent, Loc),
12051 Selector_Name => Make_Identifier (Loc, Chars (D))));
12054 Next_Discriminant (D);
12059 -- Step 4: Add private component renamings (if any)
12061 if Is_Protected then
12062 Def := Protected_Definition (Parent (Conc_Typ));
12064 if Present (Private_Declarations (Def)) then
12067 Comp_Id : Entity_Id;
12068 Decl_Id : Entity_Id;
12071 Comp := First (Private_Declarations (Def));
12072 while Present (Comp) loop
12073 if Nkind (Comp) = N_Component_Declaration then
12074 Comp_Id := Defining_Identifier (Comp);
12076 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12078 -- Minimal decoration
12080 if Ekind (Spec_Id) = E_Function then
12081 Set_Ekind (Decl_Id, E_Constant);
12083 Set_Ekind (Decl_Id, E_Variable);
12086 Set_Prival (Comp_Id, Decl_Id);
12087 Set_Prival_Link (Decl_Id, Comp_Id);
12088 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
12091 -- comp_name : comp_typ renames _object.comp_name;
12094 Make_Object_Renaming_Declaration (Loc,
12095 Defining_Identifier => Decl_Id,
12097 New_Reference_To (Etype (Comp_Id), Loc),
12099 Make_Selected_Component (Loc,
12101 New_Reference_To (Obj_Ent, Loc),
12103 Make_Identifier (Loc, Chars (Comp_Id))));
12113 -- Step 5: Add the declaration of the entry index and the associated
12114 -- type for barrier functions and entry families.
12116 if (Barrier and then Family)
12117 or else Ekind (Spec_Id) = E_Entry_Family
12120 E : constant Entity_Id := Index_Object (Spec_Id);
12121 Index : constant Entity_Id :=
12122 Defining_Identifier (
12123 Entry_Index_Specification (
12124 Entry_Body_Formal_Part (Body_Nod)));
12125 Index_Con : constant Entity_Id :=
12126 Make_Defining_Identifier (Loc, Chars (Index));
12128 Index_Typ : Entity_Id;
12132 -- Minimal decoration
12134 Set_Ekind (Index_Con, E_Constant);
12135 Set_Entry_Index_Constant (Index, Index_Con);
12136 Set_Discriminal_Link (Index_Con, Index);
12138 -- Retrieve the bounds of the entry family
12140 High := Type_High_Bound (Etype (Index));
12141 Low := Type_Low_Bound (Etype (Index));
12143 -- In the simple case the entry family is given by a subtype
12144 -- mark and the index constant has the same type.
12146 if Is_Entity_Name (Original_Node (
12147 Discrete_Subtype_Definition (Parent (Index))))
12149 Index_Typ := Etype (Index);
12151 -- Otherwise a new subtype declaration is required
12154 High := Replace_Bound (High);
12155 Low := Replace_Bound (Low);
12157 Index_Typ := Make_Temporary (Loc, 'J');
12160 -- subtype Jnn is <Etype of Index> range Low .. High;
12163 Make_Subtype_Declaration (Loc,
12164 Defining_Identifier => Index_Typ,
12165 Subtype_Indication =>
12166 Make_Subtype_Indication (Loc,
12168 New_Reference_To (Base_Type (Etype (Index)), Loc),
12170 Make_Range_Constraint (Loc,
12171 Range_Expression =>
12172 Make_Range (Loc, Low, High))));
12176 Set_Etype (Index_Con, Index_Typ);
12178 -- Create the object which designates the index:
12179 -- J : constant Jnn :=
12180 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12182 -- where Jnn is the subtype created above or the original type of
12183 -- the index, _E is a formal of the protected body subprogram and
12184 -- <index expr> is the index of the first family member.
12187 Make_Object_Declaration (Loc,
12188 Defining_Identifier => Index_Con,
12189 Constant_Present => True,
12190 Object_Definition =>
12191 New_Reference_To (Index_Typ, Loc),
12194 Make_Attribute_Reference (Loc,
12196 New_Reference_To (Index_Typ, Loc),
12197 Attribute_Name => Name_Val,
12199 Expressions => New_List (
12203 Make_Op_Subtract (Loc,
12205 New_Reference_To (E, Loc),
12207 Entry_Index_Expression (Loc,
12208 Defining_Identifier (Body_Nod),
12212 Make_Attribute_Reference (Loc,
12214 New_Reference_To (Index_Typ, Loc),
12215 Attribute_Name => Name_Pos,
12216 Expressions => New_List (
12217 Make_Attribute_Reference (Loc,
12219 New_Reference_To (Index_Typ, Loc),
12220 Attribute_Name => Name_First)))))));
12224 end Install_Private_Data_Declarations;
12226 ---------------------------------
12227 -- Is_Potentially_Large_Family --
12228 ---------------------------------
12230 function Is_Potentially_Large_Family
12231 (Base_Index : Entity_Id;
12232 Conctyp : Entity_Id;
12234 Hi : Node_Id) return Boolean
12237 return Scope (Base_Index) = Standard_Standard
12238 and then Base_Index = Base_Type (Standard_Integer)
12239 and then Has_Discriminants (Conctyp)
12241 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12243 (Denotes_Discriminant (Lo, True)
12244 or else Denotes_Discriminant (Hi, True));
12245 end Is_Potentially_Large_Family;
12247 -------------------------------------
12248 -- Is_Private_Primitive_Subprogram --
12249 -------------------------------------
12251 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12254 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12255 and then Is_Private_Primitive (Id);
12256 end Is_Private_Primitive_Subprogram;
12262 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12263 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12264 Formal : Entity_Id;
12267 Formal := First_Formal (Bod_Subp);
12268 while Present (Formal) loop
12270 -- Look for formal parameter _E
12272 if Chars (Formal) = Name_uE then
12276 Next_Formal (Formal);
12279 -- A protected body subprogram should always have the parameter in
12282 raise Program_Error;
12285 --------------------------------
12286 -- Make_Initialize_Protection --
12287 --------------------------------
12289 function Make_Initialize_Protection
12290 (Protect_Rec : Entity_Id) return List_Id
12292 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12296 Ptyp : constant Node_Id :=
12297 Corresponding_Concurrent_Type (Protect_Rec);
12299 L : constant List_Id := New_List;
12300 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12301 Restricted : constant Boolean := Restricted_Profile;
12304 -- We may need two calls to properly initialize the object, one to
12305 -- Initialize_Protection, and possibly one to Install_Handlers if we
12306 -- have a pragma Attach_Handler.
12308 -- Get protected declaration. In the case of a task type declaration,
12309 -- this is simply the parent of the protected type entity. In the single
12310 -- protected object declaration, this parent will be the implicit type,
12311 -- and we can find the corresponding single protected object declaration
12312 -- by searching forward in the declaration list in the tree.
12314 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12315 -- of this type should have been removed during semantic analysis.
12317 Pdec := Parent (Ptyp);
12318 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12319 N_Single_Protected_Declaration)
12324 -- Now we can find the object definition from this declaration
12326 Pdef := Protected_Definition (Pdec);
12328 -- Build the parameter list for the call. Note that _Init is the name
12329 -- of the formal for the object to be initialized, which is the task
12330 -- value record itself.
12334 -- Object parameter. This is a pointer to the object of type
12335 -- Protection used by the GNARL to control the protected object.
12338 Make_Attribute_Reference (Loc,
12340 Make_Selected_Component (Loc,
12341 Prefix => Make_Identifier (Loc, Name_uInit),
12342 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12343 Attribute_Name => Name_Unchecked_Access));
12345 -- Priority parameter. Set to Unspecified_Priority unless there is a
12346 -- priority pragma, in which case we take the value from the pragma,
12347 -- or there is an interrupt pragma and no priority pragma, and we
12348 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12349 -- defined value, see D.3(10).
12352 and then Has_Pragma_Priority (Pdef)
12355 Prio : constant Node_Id :=
12358 (Pragma_Argument_Associations
12359 (Find_Task_Or_Protected_Pragma
12360 (Pdef, Name_Priority))));
12364 -- If priority is a static expression, then we can duplicate it
12365 -- with no problem and simply append it to the argument list.
12367 if Is_Static_Expression (Prio) then
12369 Duplicate_Subexpr_No_Checks (Prio));
12371 -- Otherwise, the priority may be a per-object expression, if it
12372 -- depends on a discriminant of the type. In this case, create
12373 -- local variable to capture the expression. Note that it is
12374 -- really necessary to create this variable explicitly. It might
12375 -- be thought that removing side effects would the appropriate
12376 -- approach, but that could generate declarations improperly
12377 -- placed in the enclosing scope.
12379 -- Note: Use System.Any_Priority as the expected type for the
12380 -- non-static priority expression, in case the expression has not
12381 -- been analyzed yet (as occurs for example with pragma
12382 -- Interrupt_Priority).
12385 Temp := Make_Temporary (Loc, 'R', Prio);
12387 Make_Object_Declaration (Loc,
12388 Defining_Identifier => Temp,
12389 Object_Definition =>
12390 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12391 Expression => Relocate_Node (Prio)));
12393 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12397 -- When no priority is specified but an xx_Handler pragma is, we default
12398 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12400 elsif Has_Interrupt_Handler (Ptyp)
12401 or else Has_Attach_Handler (Ptyp)
12404 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12406 -- Normal case, no priority or xx_Handler specified, default priority
12410 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12413 -- Test for Compiler_Info parameter. This parameter allows entry body
12414 -- procedures and barrier functions to be called from the runtime. It
12415 -- is a pointer to the record generated by the compiler to represent
12416 -- the protected object.
12418 -- A protected type without entries that covers an interface and
12419 -- overrides the abstract routines with protected procedures is
12420 -- considered equivalent to a protected type with entries in the
12421 -- context of dispatching select statements.
12424 or else Has_Interrupt_Handler (Ptyp)
12425 or else Has_Attach_Handler (Ptyp)
12426 or else Has_Interfaces (Protect_Rec)
12429 Pkg_Id : constant RTU_Id :=
12430 Corresponding_Runtime_Package (Ptyp);
12431 Called_Subp : RE_Id;
12435 when System_Tasking_Protected_Objects_Entries =>
12436 Called_Subp := RE_Initialize_Protection_Entries;
12438 when System_Tasking_Protected_Objects =>
12439 Called_Subp := RE_Initialize_Protection;
12441 when System_Tasking_Protected_Objects_Single_Entry =>
12442 Called_Subp := RE_Initialize_Protection_Entry;
12445 raise Program_Error;
12449 or else not Restricted
12450 or else Has_Interfaces (Protect_Rec)
12453 Make_Attribute_Reference (Loc,
12454 Prefix => Make_Identifier (Loc, Name_uInit),
12455 Attribute_Name => Name_Address));
12458 -- Entry_Bodies parameter. This is a pointer to an array of
12459 -- pointers to the entry body procedures and barrier functions of
12460 -- the object. If the protected type has no entries this object
12461 -- will not exist, in this case, pass a null.
12464 P_Arr := Entry_Bodies_Array (Ptyp);
12467 Make_Attribute_Reference (Loc,
12468 Prefix => New_Reference_To (P_Arr, Loc),
12469 Attribute_Name => Name_Unrestricted_Access));
12471 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12473 -- Find index mapping function (clumsy but ok for now)
12475 while Ekind (P_Arr) /= E_Function loop
12476 Next_Entity (P_Arr);
12480 Make_Attribute_Reference (Loc,
12482 New_Reference_To (P_Arr, Loc),
12483 Attribute_Name => Name_Unrestricted_Access));
12485 -- Build_Entry_Names generation flag. When set to true, the
12486 -- runtime will allocate an array to hold the string names
12487 -- of protected entries.
12489 if not Restricted_Profile then
12490 if Entry_Names_OK then
12492 New_Reference_To (Standard_True, Loc));
12495 New_Reference_To (Standard_False, Loc));
12500 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12501 Append_To (Args, Make_Null (Loc));
12503 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12504 Append_To (Args, Make_Null (Loc));
12505 Append_To (Args, Make_Null (Loc));
12506 Append_To (Args, New_Reference_To (Standard_False, Loc));
12510 Make_Procedure_Call_Statement (Loc,
12511 Name => New_Reference_To (RTE (Called_Subp), Loc),
12512 Parameter_Associations => Args));
12516 Make_Procedure_Call_Statement (Loc,
12517 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12518 Parameter_Associations => Args));
12521 if Has_Attach_Handler (Ptyp) then
12523 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12524 -- make the following call:
12526 -- Install_Handlers (_object,
12527 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12529 -- or, in the case of Ravenscar:
12531 -- Install_Restricted_Handlers
12532 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12535 Args : constant List_Id := New_List;
12536 Table : constant List_Id := New_List;
12537 Ritem : Node_Id := First_Rep_Item (Ptyp);
12540 -- Build the Attach_Handler table argument
12542 while Present (Ritem) loop
12543 if Nkind (Ritem) = N_Pragma
12544 and then Pragma_Name (Ritem) = Name_Attach_Handler
12547 Handler : constant Node_Id :=
12548 First (Pragma_Argument_Associations (Ritem));
12550 Interrupt : constant Node_Id := Next (Handler);
12551 Expr : constant Node_Id := Expression (Interrupt);
12555 Make_Aggregate (Loc, Expressions => New_List (
12556 Unchecked_Convert_To
12557 (RTE (RE_System_Interrupt_Id), Expr),
12558 Make_Attribute_Reference (Loc,
12559 Prefix => Make_Selected_Component (Loc,
12560 Make_Identifier (Loc, Name_uInit),
12561 Duplicate_Subexpr_No_Checks
12562 (Expression (Handler))),
12563 Attribute_Name => Name_Access))));
12567 Next_Rep_Item (Ritem);
12570 -- Append the table argument we just built
12572 Append_To (Args, Make_Aggregate (Loc, Table));
12574 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12575 -- call to the statements.
12578 -- Call a simplified version of Install_Handlers to be used
12579 -- when the Ravenscar restrictions are in effect
12580 -- (Install_Restricted_Handlers).
12583 Make_Procedure_Call_Statement (Loc,
12586 (RTE (RE_Install_Restricted_Handlers), Loc),
12587 Parameter_Associations => Args));
12590 -- First, prepends the _object argument
12593 Make_Attribute_Reference (Loc,
12595 Make_Selected_Component (Loc,
12596 Prefix => Make_Identifier (Loc, Name_uInit),
12597 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12598 Attribute_Name => Name_Unchecked_Access));
12600 -- Then, insert call to Install_Handlers
12603 Make_Procedure_Call_Statement (Loc,
12604 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
12605 Parameter_Associations => Args));
12611 end Make_Initialize_Protection;
12613 ---------------------------
12614 -- Make_Task_Create_Call --
12615 ---------------------------
12617 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
12618 Loc : constant Source_Ptr := Sloc (Task_Rec);
12628 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
12629 Tnam := Chars (Ttyp);
12631 -- Get task declaration. In the case of a task type declaration, this is
12632 -- simply the parent of the task type entity. In the single task
12633 -- declaration, this parent will be the implicit type, and we can find
12634 -- the corresponding single task declaration by searching forward in the
12635 -- declaration list in the tree.
12637 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12638 -- this type should have been removed during semantic analysis.
12640 Tdec := Parent (Ttyp);
12641 while not Nkind_In (Tdec, N_Task_Type_Declaration,
12642 N_Single_Task_Declaration)
12647 -- Now we can find the task definition from this declaration
12649 Tdef := Task_Definition (Tdec);
12651 -- Build the parameter list for the call. Note that _Init is the name
12652 -- of the formal for the object to be initialized, which is the task
12653 -- value record itself.
12657 -- Priority parameter. Set to Unspecified_Priority unless there is a
12658 -- priority pragma, in which case we take the value from the pragma.
12660 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
12662 Make_Selected_Component (Loc,
12663 Prefix => Make_Identifier (Loc, Name_uInit),
12664 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12667 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12670 -- Optional Stack parameter
12672 if Restricted_Profile then
12674 -- If the stack has been preallocated by the expander then
12675 -- pass its address. Otherwise, pass a null address.
12677 if Preallocated_Stacks_On_Target then
12679 Make_Attribute_Reference (Loc,
12681 Make_Selected_Component (Loc,
12682 Prefix => Make_Identifier (Loc, Name_uInit),
12683 Selector_Name => Make_Identifier (Loc, Name_uStack)),
12684 Attribute_Name => Name_Address));
12688 New_Reference_To (RTE (RE_Null_Address), Loc));
12692 -- Size parameter. If no Storage_Size pragma is present, then
12693 -- the size is taken from the taskZ variable for the type, which
12694 -- is either Unspecified_Size, or has been reset by the use of
12695 -- a Storage_Size attribute definition clause. If a pragma is
12696 -- present, then the size is taken from the _Size field of the
12697 -- task value record, which was set from the pragma value.
12700 and then Has_Storage_Size_Pragma (Tdef)
12703 Make_Selected_Component (Loc,
12704 Prefix => Make_Identifier (Loc, Name_uInit),
12705 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12709 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12712 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12713 -- Task_Info pragma, in which case we take the value from the pragma.
12716 and then Has_Task_Info_Pragma (Tdef)
12719 Make_Selected_Component (Loc,
12720 Prefix => Make_Identifier (Loc, Name_uInit),
12721 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12725 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12728 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
12729 -- in which case we take the value from the pragma. The parameter is
12730 -- passed as an Integer because in the case of unspecified CPU the
12731 -- value is not in the range of CPU_Range.
12733 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
12735 Convert_To (Standard_Integer,
12736 Make_Selected_Component (Loc,
12737 Prefix => Make_Identifier (Loc, Name_uInit),
12738 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
12742 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
12745 if not Restricted_Profile then
12747 -- Deadline parameter. If no Relative_Deadline pragma is present,
12748 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12749 -- the deadline is taken from the _Relative_Deadline field of the
12750 -- task value record, which was set from the pragma value. Note that
12751 -- this parameter must not be generated for the restricted profiles
12752 -- since Ravenscar does not allow deadlines.
12754 -- Case where pragma Relative_Deadline applies: use given value
12756 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12758 Make_Selected_Component (Loc,
12760 Make_Identifier (Loc, Name_uInit),
12762 Make_Identifier (Loc, Name_uRelative_Deadline)));
12764 -- No pragma Relative_Deadline apply to the task
12768 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12771 -- Number of entries. This is an expression of the form:
12773 -- n + _Init.a'Length + _Init.a'B'Length + ...
12775 -- where a,b... are the entry family names for the task definition
12778 Build_Entry_Count_Expression
12783 (Parent (Corresponding_Record_Type (Ttyp))))),
12785 Append_To (Args, Ecount);
12787 -- Master parameter. This is a reference to the _Master parameter of
12788 -- the initialization procedure, except in the case of the pragma
12789 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
12790 -- System.Tasking.Library_Task_Level.
12792 if Restriction_Active (No_Task_Hierarchy) = False then
12793 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12796 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
12800 -- State parameter. This is a pointer to the task body procedure. The
12801 -- required value is obtained by taking 'Unrestricted_Access of the task
12802 -- body procedure and converting it (with an unchecked conversion) to
12803 -- the type required by the task kernel. For further details, see the
12804 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12805 -- than 'Address in order to avoid creating trampolines.
12808 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12809 Subp_Ptr_Typ : constant Node_Id :=
12810 Create_Itype (E_Access_Subprogram_Type, Tdec);
12811 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12814 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12815 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12817 -- Be sure to freeze a reference to the access-to-subprogram type,
12818 -- otherwise gigi will complain that it's in the wrong scope, because
12819 -- it's actually inside the init procedure for the record type that
12820 -- corresponds to the task type.
12822 -- This processing is causing a crash in the .NET/JVM back ends that
12823 -- is not yet understood, so skip it in these cases ???
12825 if VM_Target = No_VM then
12826 Set_Itype (Ref, Subp_Ptr_Typ);
12827 Append_Freeze_Action (Task_Rec, Ref);
12830 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12831 Make_Qualified_Expression (Loc,
12832 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12834 Make_Attribute_Reference (Loc,
12836 New_Occurrence_Of (Body_Proc, Loc),
12837 Attribute_Name => Name_Unrestricted_Access))));
12839 -- For the .NET/JVM cases revert to the original code below ???
12843 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12844 Make_Attribute_Reference (Loc,
12846 New_Occurrence_Of (Body_Proc, Loc),
12847 Attribute_Name => Name_Address)));
12851 -- Discriminants parameter. This is just the address of the task
12852 -- value record itself (which contains the discriminant values
12855 Make_Attribute_Reference (Loc,
12856 Prefix => Make_Identifier (Loc, Name_uInit),
12857 Attribute_Name => Name_Address));
12859 -- Elaborated parameter. This is an access to the elaboration Boolean
12862 Make_Attribute_Reference (Loc,
12863 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12864 Attribute_Name => Name_Unchecked_Access));
12866 -- Chain parameter. This is a reference to the _Chain parameter of
12867 -- the initialization procedure.
12869 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12871 -- Task name parameter. Take this from the _Task_Id parameter to the
12872 -- init call unless there is a Task_Name pragma, in which case we take
12873 -- the value from the pragma.
12876 and then Has_Task_Name_Pragma (Tdef)
12878 -- Copy expression in full, because it may be dynamic and have
12884 (Pragma_Argument_Associations
12885 (Find_Task_Or_Protected_Pragma
12886 (Tdef, Name_Task_Name))))));
12889 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12892 -- Created_Task parameter. This is the _Task_Id field of the task
12896 Make_Selected_Component (Loc,
12897 Prefix => Make_Identifier (Loc, Name_uInit),
12898 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12900 -- Build_Entry_Names generation flag. When set to true, the runtime
12901 -- will allocate an array to hold the string names of task entries.
12903 if not Restricted_Profile then
12904 if Has_Entries (Ttyp)
12905 and then Entry_Names_OK
12907 Append_To (Args, New_Reference_To (Standard_True, Loc));
12909 Append_To (Args, New_Reference_To (Standard_False, Loc));
12913 if Restricted_Profile then
12914 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12916 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12920 Make_Procedure_Call_Statement (Loc,
12922 Parameter_Associations => Args);
12923 end Make_Task_Create_Call;
12925 ------------------------------
12926 -- Next_Protected_Operation --
12927 ------------------------------
12929 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12933 Next_Op := Next (N);
12934 while Present (Next_Op)
12935 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12941 end Next_Protected_Operation;
12943 ---------------------
12944 -- Null_Statements --
12945 ---------------------
12947 function Null_Statements (Stats : List_Id) return Boolean is
12951 Stmt := First (Stats);
12952 while Nkind (Stmt) /= N_Empty
12953 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12955 (Nkind (Stmt) = N_Pragma
12956 and then (Pragma_Name (Stmt) = Name_Unreferenced
12958 Pragma_Name (Stmt) = Name_Unmodified
12960 Pragma_Name (Stmt) = Name_Warnings)))
12965 return Nkind (Stmt) = N_Empty;
12966 end Null_Statements;
12968 --------------------------
12969 -- Parameter_Block_Pack --
12970 --------------------------
12972 function Parameter_Block_Pack
12974 Blk_Typ : Entity_Id;
12978 Stmts : List_Id) return Node_Id
12980 Actual : Entity_Id;
12981 Expr : Node_Id := Empty;
12982 Formal : Entity_Id;
12983 Has_Param : Boolean := False;
12986 Temp_Asn : Node_Id;
12987 Temp_Nam : Node_Id;
12990 Actual := First (Actuals);
12991 Formal := Defining_Identifier (First (Formals));
12992 Params := New_List;
12994 while Present (Actual) loop
12995 if Is_By_Copy_Type (Etype (Actual)) then
12997 -- Jnn : aliased <formal-type>
12999 Temp_Nam := Make_Temporary (Loc, 'J');
13002 Make_Object_Declaration (Loc,
13005 Defining_Identifier =>
13007 Object_Definition =>
13008 New_Reference_To (Etype (Formal), Loc)));
13010 if Ekind (Formal) /= E_Out_Parameter then
13016 New_Reference_To (Temp_Nam, Loc);
13018 Set_Assignment_OK (Temp_Asn);
13021 Make_Assignment_Statement (Loc,
13025 New_Copy_Tree (Actual)));
13029 -- Jnn'unchecked_access
13032 Make_Attribute_Reference (Loc,
13034 Name_Unchecked_Access,
13036 New_Reference_To (Temp_Nam, Loc)));
13040 -- The controlling parameter is omitted
13043 if not Is_Controlling_Actual (Actual) then
13045 Make_Reference (Loc, New_Copy_Tree (Actual)));
13051 Next_Actual (Actual);
13052 Next_Formal_With_Extras (Formal);
13056 Expr := Make_Aggregate (Loc, Params);
13061 -- J1'unchecked_access;
13062 -- <actual2>'reference;
13065 P := Make_Temporary (Loc, 'P');
13068 Make_Object_Declaration (Loc,
13069 Defining_Identifier =>
13071 Object_Definition =>
13072 New_Reference_To (Blk_Typ, Loc),
13077 end Parameter_Block_Pack;
13079 ----------------------------
13080 -- Parameter_Block_Unpack --
13081 ----------------------------
13083 function Parameter_Block_Unpack
13087 Formals : List_Id) return List_Id
13089 Actual : Entity_Id;
13091 Formal : Entity_Id;
13092 Has_Asnmt : Boolean := False;
13093 Result : constant List_Id := New_List;
13096 Actual := First (Actuals);
13097 Formal := Defining_Identifier (First (Formals));
13098 while Present (Actual) loop
13099 if Is_By_Copy_Type (Etype (Actual))
13100 and then Ekind (Formal) /= E_In_Parameter
13103 -- <actual> := P.<formal>;
13106 Make_Assignment_Statement (Loc,
13110 Make_Explicit_Dereference (Loc,
13111 Make_Selected_Component (Loc,
13113 New_Reference_To (P, Loc),
13115 Make_Identifier (Loc, Chars (Formal)))));
13117 Set_Assignment_OK (Name (Asnmt));
13118 Append_To (Result, Asnmt);
13123 Next_Actual (Actual);
13124 Next_Formal_With_Extras (Formal);
13130 return New_List (Make_Null_Statement (Loc));
13132 end Parameter_Block_Unpack;
13134 ----------------------
13135 -- Set_Discriminals --
13136 ----------------------
13138 procedure Set_Discriminals (Dec : Node_Id) is
13141 D_Minal : Entity_Id;
13144 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13145 Pdef := Defining_Identifier (Dec);
13147 if Has_Discriminants (Pdef) then
13148 D := First_Discriminant (Pdef);
13149 while Present (D) loop
13151 Make_Defining_Identifier (Sloc (D),
13152 Chars => New_External_Name (Chars (D), 'D'));
13154 Set_Ekind (D_Minal, E_Constant);
13155 Set_Etype (D_Minal, Etype (D));
13156 Set_Scope (D_Minal, Pdef);
13157 Set_Discriminal (D, D_Minal);
13158 Set_Discriminal_Link (D_Minal, D);
13160 Next_Discriminant (D);
13163 end Set_Discriminals;
13165 -----------------------
13166 -- Trivial_Accept_OK --
13167 -----------------------
13169 function Trivial_Accept_OK return Boolean is
13171 case Opt.Task_Dispatching_Policy is
13173 -- If we have the default task dispatching policy in effect, we can
13174 -- definitely do the optimization (one way of looking at this is to
13175 -- think of the formal definition of the default policy being allowed
13176 -- to run any task it likes after a rendezvous, so even if notionally
13177 -- a full rescheduling occurs, we can say that our dispatching policy
13178 -- (i.e. the default dispatching policy) reorders the queue to be the
13179 -- same as just before the call.
13184 -- FIFO_Within_Priorities certainly does not permit this
13185 -- optimization since the Rendezvous is a scheduling action that may
13186 -- require some other task to be run.
13191 -- For now, disallow the optimization for all other policies. This
13192 -- may be over-conservative, but it is certainly not incorrect.
13198 end Trivial_Accept_OK;