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 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2267 -- this subprogram and this is not a primitive declared between two
2268 -- views then force the generation of a wrapper. As an optimization,
2269 -- previous versions of the frontend avoid generating the wrapper;
2270 -- however, the wrapper facilitates locating and reporting an error
2271 -- when a duplicate declaration is found later. See example in
2275 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2278 (Corresponding_Concurrent_Type (Obj_Typ))
2281 Make_Parameter_Specification (Loc,
2282 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2284 Out_Present => False,
2285 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2287 -- For entries and procedures of protected types the mode of
2288 -- the controlling argument must be in-out.
2292 Make_Parameter_Specification (Loc,
2293 Defining_Identifier =>
2294 Make_Defining_Identifier (Loc,
2297 Out_Present => (Ekind (Subp_Id) /= E_Function),
2298 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2303 Wrapper_Id : constant Entity_Id :=
2304 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2305 New_Formals : List_Id;
2306 Obj_Param : Node_Id;
2307 Obj_Param_Typ : Entity_Id;
2310 -- Minimum decoration is needed to catch the entity in
2311 -- Sem_Ch6.Override_Dispatching_Operation.
2313 if Ekind (Subp_Id) = E_Function then
2314 Set_Ekind (Wrapper_Id, E_Function);
2316 Set_Ekind (Wrapper_Id, E_Procedure);
2319 Set_Is_Primitive_Wrapper (Wrapper_Id);
2320 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2321 Set_Is_Private_Primitive (Wrapper_Id,
2322 Is_Private_Primitive_Subprogram (Subp_Id));
2324 -- Process the formals
2326 New_Formals := Replicate_Formals (Loc, Formals);
2328 -- A function with a controlling result and no first controlling
2329 -- formal needs no additional parameter.
2331 if Has_Controlling_Result (Subp_Id)
2333 (No (First_Formal (Subp_Id))
2334 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2338 -- Routine Subp_Id has been found to override an interface primitive.
2339 -- If the interface operation has an access parameter, create a copy
2340 -- of it, with the same null exclusion indicator if present.
2342 elsif Present (First_Param) then
2343 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2345 Make_Access_Definition (Loc,
2347 New_Reference_To (Obj_Typ, Loc));
2348 Set_Null_Exclusion_Present (Obj_Param_Typ,
2349 Null_Exclusion_Present (Parameter_Type (First_Param)));
2352 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2356 Make_Parameter_Specification (Loc,
2357 Defining_Identifier =>
2358 Make_Defining_Identifier (Loc,
2360 In_Present => In_Present (First_Param),
2361 Out_Present => Out_Present (First_Param),
2362 Parameter_Type => Obj_Param_Typ);
2364 Prepend_To (New_Formals, Obj_Param);
2366 -- If we are dealing with a primitive declared between two views,
2367 -- implemented by a synchronized operation, we need to create
2368 -- a default parameter. The mode of the parameter must match that
2369 -- of the primitive operation.
2372 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2374 Make_Parameter_Specification (Loc,
2375 Defining_Identifier =>
2376 Make_Defining_Identifier (Loc, Name_uO),
2377 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2378 Out_Present => Ekind (Subp_Id) /= E_Function,
2379 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2380 Prepend_To (New_Formals, Obj_Param);
2383 -- Build the final spec. If it is a function with a controlling
2384 -- result, it is a primitive operation of the corresponding
2385 -- record type, so mark the spec accordingly.
2387 if Ekind (Subp_Id) = E_Function then
2392 if Has_Controlling_Result (Subp_Id) then
2395 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2397 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2401 Make_Function_Specification (Loc,
2402 Defining_Unit_Name => Wrapper_Id,
2403 Parameter_Specifications => New_Formals,
2404 Result_Definition => Res_Def);
2408 Make_Procedure_Specification (Loc,
2409 Defining_Unit_Name => Wrapper_Id,
2410 Parameter_Specifications => New_Formals);
2413 end Build_Wrapper_Spec;
2415 -------------------------
2416 -- Build_Wrapper_Specs --
2417 -------------------------
2419 procedure Build_Wrapper_Specs
2425 Rec_Typ : Entity_Id;
2426 procedure Scan_Declarations (L : List_Id);
2427 -- Common processing for visible and private declarations
2428 -- of a protected type.
2430 procedure Scan_Declarations (L : List_Id) is
2432 Wrap_Decl : Node_Id;
2433 Wrap_Spec : Node_Id;
2441 while Present (Decl) loop
2444 if Nkind (Decl) = N_Entry_Declaration
2445 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2449 (Subp_Id => Defining_Identifier (Decl),
2451 Formals => Parameter_Specifications (Decl));
2453 elsif Nkind (Decl) = N_Subprogram_Declaration then
2456 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2459 Parameter_Specifications (Specification (Decl)));
2462 if Present (Wrap_Spec) then
2464 Make_Subprogram_Declaration (Loc,
2465 Specification => Wrap_Spec);
2467 Insert_After (N, Wrap_Decl);
2470 Analyze (Wrap_Decl);
2475 end Scan_Declarations;
2477 -- start of processing for Build_Wrapper_Specs
2480 if Is_Protected_Type (Typ) then
2481 Def := Protected_Definition (Parent (Typ));
2482 else pragma Assert (Is_Task_Type (Typ));
2483 Def := Task_Definition (Parent (Typ));
2486 Rec_Typ := Corresponding_Record_Type (Typ);
2488 -- Generate wrapper specs for a concurrent type which implements an
2489 -- interface. Operations in both the visible and private parts may
2490 -- implement progenitor operations.
2492 if Present (Interfaces (Rec_Typ))
2493 and then Present (Def)
2495 Scan_Declarations (Visible_Declarations (Def));
2496 Scan_Declarations (Private_Declarations (Def));
2498 end Build_Wrapper_Specs;
2500 ---------------------------
2501 -- Build_Find_Body_Index --
2502 ---------------------------
2504 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2505 Loc : constant Source_Ptr := Sloc (Typ);
2508 Has_F : Boolean := False;
2510 If_St : Node_Id := Empty;
2513 Decls : List_Id := New_List;
2516 Siz : Node_Id := Empty;
2518 procedure Add_If_Clause (Expr : Node_Id);
2519 -- Add test for range of current entry
2521 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2522 -- If a bound of an entry is given by a discriminant, retrieve the
2523 -- actual value of the discriminant from the enclosing object.
2529 procedure Add_If_Clause (Expr : Node_Id) is
2531 Stats : constant List_Id :=
2533 Make_Simple_Return_Statement (Loc,
2534 Expression => Make_Integer_Literal (Loc, Index + 1)));
2537 -- Index for current entry body
2541 -- Compute total length of entry queues so far
2549 Right_Opnd => Expr);
2554 Left_Opnd => Make_Identifier (Loc, Name_uE),
2557 -- Map entry queue indexes in the range of the current family
2558 -- into the current index, that designates the entry body.
2562 Make_Implicit_If_Statement (Typ,
2564 Then_Statements => Stats,
2565 Elsif_Parts => New_List);
2571 Make_Elsif_Part (Loc,
2573 Then_Statements => Stats),
2574 Elsif_Parts (If_St));
2578 ------------------------------
2579 -- Convert_Discriminant_Ref --
2580 ------------------------------
2582 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2586 if Is_Entity_Name (Bound)
2587 and then Ekind (Entity (Bound)) = E_Discriminant
2590 Make_Selected_Component (Loc,
2592 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2593 Make_Explicit_Dereference (Loc,
2594 Make_Identifier (Loc, Name_uObject))),
2595 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2596 Set_Etype (B, Etype (Entity (Bound)));
2598 B := New_Copy_Tree (Bound);
2602 end Convert_Discriminant_Ref;
2604 -- Start of processing for Build_Find_Body_Index
2607 Spec := Build_Find_Body_Index_Spec (Typ);
2609 Ent := First_Entity (Typ);
2610 while Present (Ent) loop
2611 if Ekind (Ent) = E_Entry_Family then
2621 -- If the protected type has no entry families, there is a one-one
2622 -- correspondence between entry queue and entry body.
2625 Make_Simple_Return_Statement (Loc,
2626 Expression => Make_Identifier (Loc, Name_uE));
2629 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2632 -- if E <= l1 then return 1;
2633 -- elsif E <= l1 + l2 then return 2;
2638 Ent := First_Entity (Typ);
2640 Add_Object_Pointer (Loc, Typ, Decls);
2642 while Present (Ent) loop
2643 if Ekind (Ent) = E_Entry then
2644 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2646 elsif Ekind (Ent) = E_Entry_Family then
2647 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2648 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2649 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2650 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2659 Make_Simple_Return_Statement (Loc,
2660 Expression => Make_Integer_Literal (Loc, 1));
2662 elsif Nkind (Ret) = N_If_Statement then
2664 -- Ranges are in increasing order, so last one doesn't need guard
2667 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2670 Set_Else_Statements (Ret, Then_Statements (Nod));
2676 Make_Subprogram_Body (Loc,
2677 Specification => Spec,
2678 Declarations => Decls,
2679 Handled_Statement_Sequence =>
2680 Make_Handled_Sequence_Of_Statements (Loc,
2681 Statements => New_List (Ret)));
2682 end Build_Find_Body_Index;
2684 --------------------------------
2685 -- Build_Find_Body_Index_Spec --
2686 --------------------------------
2688 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2689 Loc : constant Source_Ptr := Sloc (Typ);
2690 Id : constant Entity_Id :=
2691 Make_Defining_Identifier (Loc,
2692 Chars => New_External_Name (Chars (Typ), 'F'));
2693 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2694 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2698 Make_Function_Specification (Loc,
2699 Defining_Unit_Name => Id,
2700 Parameter_Specifications => New_List (
2701 Make_Parameter_Specification (Loc,
2702 Defining_Identifier => Parm1,
2704 New_Reference_To (RTE (RE_Address), Loc)),
2706 Make_Parameter_Specification (Loc,
2707 Defining_Identifier => Parm2,
2709 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2710 Result_Definition => New_Occurrence_Of (
2711 RTE (RE_Protected_Entry_Index), Loc));
2712 end Build_Find_Body_Index_Spec;
2714 -------------------------
2715 -- Build_Master_Entity --
2716 -------------------------
2718 procedure Build_Master_Entity (E : Entity_Id) is
2719 Loc : constant Source_Ptr := Sloc (E);
2725 S := Find_Master_Scope (E);
2727 -- Nothing to do if we already built a master entity for this scope
2728 -- or if there is no task hierarchy.
2730 if Has_Master_Entity (S)
2731 or else Restriction_Active (No_Task_Hierarchy)
2736 -- Otherwise first build the master entity
2737 -- _Master : constant Master_Id := Current_Master.all;
2738 -- and insert it just before the current declaration
2741 Make_Object_Declaration (Loc,
2742 Defining_Identifier =>
2743 Make_Defining_Identifier (Loc, Name_uMaster),
2744 Constant_Present => True,
2745 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2747 Make_Explicit_Dereference (Loc,
2748 New_Reference_To (RTE (RE_Current_Master), Loc)));
2751 Insert_Before (P, Decl);
2754 Set_Has_Master_Entity (S);
2756 -- Now mark the containing scope as a task master
2758 while Nkind (P) /= N_Compilation_Unit loop
2761 -- If we fall off the top, we are at the outer level, and the
2762 -- environment task is our effective master, so nothing to mark.
2765 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2767 Set_Is_Task_Master (P, True);
2770 elsif Nkind (Parent (P)) = N_Subunit then
2771 P := Corresponding_Stub (Parent (P));
2774 end Build_Master_Entity;
2776 -----------------------------------------
2777 -- Build_Private_Protected_Declaration --
2778 -----------------------------------------
2780 function Build_Private_Protected_Declaration
2781 (N : Node_Id) return Entity_Id
2783 Loc : constant Source_Ptr := Sloc (N);
2784 Body_Id : constant Entity_Id := Defining_Entity (N);
2789 Spec_Id : Entity_Id;
2792 Formal := First_Formal (Body_Id);
2794 -- The protected operation always has at least one formal, namely the
2795 -- object itself, but it is only placed in the parameter list if
2796 -- expansion is enabled.
2798 if Present (Formal) or else Expander_Active then
2799 Plist := Copy_Parameter_List (Body_Id);
2804 if Nkind (Specification (N)) = N_Procedure_Specification then
2806 Make_Procedure_Specification (Loc,
2807 Defining_Unit_Name =>
2808 Make_Defining_Identifier (Sloc (Body_Id),
2809 Chars => Chars (Body_Id)),
2810 Parameter_Specifications =>
2814 Make_Function_Specification (Loc,
2815 Defining_Unit_Name =>
2816 Make_Defining_Identifier (Sloc (Body_Id),
2817 Chars => Chars (Body_Id)),
2818 Parameter_Specifications => Plist,
2819 Result_Definition =>
2820 New_Occurrence_Of (Etype (Body_Id), Loc));
2823 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2824 Insert_Before (N, Decl);
2825 Spec_Id := Defining_Unit_Name (New_Spec);
2827 -- Indicate that the entity comes from source, to ensure that cross-
2828 -- reference information is properly generated. The body itself is
2829 -- rewritten during expansion, and the body entity will not appear in
2830 -- calls to the operation.
2832 Set_Comes_From_Source (Spec_Id, True);
2834 Set_Has_Completion (Spec_Id);
2835 Set_Convention (Spec_Id, Convention_Protected);
2837 end Build_Private_Protected_Declaration;
2839 ---------------------------
2840 -- Build_Protected_Entry --
2841 ---------------------------
2843 function Build_Protected_Entry
2846 Pid : Node_Id) return Node_Id
2848 Loc : constant Source_Ptr := Sloc (N);
2850 Decls : constant List_Id := Declarations (N);
2851 End_Lab : constant Node_Id :=
2852 End_Label (Handled_Statement_Sequence (N));
2853 End_Loc : constant Source_Ptr :=
2854 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2855 -- Used for the generated call to Complete_Entry_Body
2857 Han_Loc : Source_Ptr;
2858 -- Used for the exception handler, inserted at end of the body
2860 Op_Decls : constant List_Id := New_List;
2868 -- Set the source location on the exception handler only when debugging
2869 -- the expanded code (see Make_Implicit_Exception_Handler).
2871 if Debug_Generated_Code then
2874 -- Otherwise the inserted code should not be visible to the debugger
2877 Han_Loc := No_Location;
2881 Make_Defining_Identifier (Loc,
2882 Chars => Chars (Protected_Body_Subprogram (Ent)));
2884 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2886 -- Add the following declarations:
2887 -- type poVP is access poV;
2888 -- _object : poVP := poVP (_O);
2890 -- where _O is the formal parameter associated with the concurrent
2891 -- object. These declarations are needed for Complete_Entry_Body.
2893 Add_Object_Pointer (Loc, Pid, Op_Decls);
2895 -- Add renamings for all formals, the Protection object, discriminals,
2896 -- privals and the entry index constant for use by debugger.
2898 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2899 Debug_Private_Data_Declarations (Decls);
2901 case Corresponding_Runtime_Package (Pid) is
2902 when System_Tasking_Protected_Objects_Entries =>
2904 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2906 when System_Tasking_Protected_Objects_Single_Entry =>
2908 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2911 raise Program_Error;
2914 Op_Stats := New_List (
2915 Make_Block_Statement (Loc,
2916 Declarations => Decls,
2917 Handled_Statement_Sequence =>
2918 Handled_Statement_Sequence (N)),
2920 Make_Procedure_Call_Statement (End_Loc,
2922 Parameter_Associations => New_List (
2923 Make_Attribute_Reference (End_Loc,
2925 Make_Selected_Component (End_Loc,
2926 Prefix => Make_Identifier (End_Loc, Name_uObject),
2927 Selector_Name => Make_Identifier (End_Loc, Name_uObject)),
2928 Attribute_Name => Name_Unchecked_Access))));
2930 -- When exceptions can not be propagated, we never need to call
2931 -- Exception_Complete_Entry_Body
2933 if No_Exception_Handlers_Set then
2935 Make_Subprogram_Body (Loc,
2936 Specification => Espec,
2937 Declarations => Op_Decls,
2938 Handled_Statement_Sequence =>
2939 Make_Handled_Sequence_Of_Statements (Loc,
2940 Statements => Op_Stats,
2941 End_Label => End_Lab));
2944 Ohandle := Make_Others_Choice (Loc);
2945 Set_All_Others (Ohandle);
2947 case Corresponding_Runtime_Package (Pid) is
2948 when System_Tasking_Protected_Objects_Entries =>
2951 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2953 when System_Tasking_Protected_Objects_Single_Entry =>
2956 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2959 raise Program_Error;
2962 -- Establish link between subprogram body entity and source entry.
2964 Set_Corresponding_Protected_Entry (Edef, Ent);
2966 -- Create body of entry procedure. The renaming declarations are
2967 -- placed ahead of the block that contains the actual entry body.
2970 Make_Subprogram_Body (Loc,
2971 Specification => Espec,
2972 Declarations => Op_Decls,
2973 Handled_Statement_Sequence =>
2974 Make_Handled_Sequence_Of_Statements (Loc,
2975 Statements => Op_Stats,
2976 End_Label => End_Lab,
2977 Exception_Handlers => New_List (
2978 Make_Implicit_Exception_Handler (Han_Loc,
2979 Exception_Choices => New_List (Ohandle),
2981 Statements => New_List (
2982 Make_Procedure_Call_Statement (Han_Loc,
2984 Parameter_Associations => New_List (
2985 Make_Attribute_Reference (Han_Loc,
2987 Make_Selected_Component (Han_Loc,
2989 Make_Identifier (Han_Loc, Name_uObject),
2991 Make_Identifier (Han_Loc, Name_uObject)),
2992 Attribute_Name => Name_Unchecked_Access),
2994 Make_Function_Call (Han_Loc,
2995 Name => New_Reference_To (
2996 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2998 end Build_Protected_Entry;
3000 -----------------------------------------
3001 -- Build_Protected_Entry_Specification --
3002 -----------------------------------------
3004 function Build_Protected_Entry_Specification
3007 Ent_Id : Entity_Id) return Node_Id
3009 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3012 Set_Debug_Info_Needed (Def_Id);
3014 if Present (Ent_Id) then
3015 Append_Elmt (P, Accept_Address (Ent_Id));
3019 Make_Procedure_Specification (Loc,
3020 Defining_Unit_Name => Def_Id,
3021 Parameter_Specifications => New_List (
3022 Make_Parameter_Specification (Loc,
3023 Defining_Identifier =>
3024 Make_Defining_Identifier (Loc, Name_uO),
3026 New_Reference_To (RTE (RE_Address), Loc)),
3028 Make_Parameter_Specification (Loc,
3029 Defining_Identifier => P,
3031 New_Reference_To (RTE (RE_Address), Loc)),
3033 Make_Parameter_Specification (Loc,
3034 Defining_Identifier =>
3035 Make_Defining_Identifier (Loc, Name_uE),
3037 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
3038 end Build_Protected_Entry_Specification;
3040 --------------------------
3041 -- Build_Protected_Spec --
3042 --------------------------
3044 function Build_Protected_Spec
3046 Obj_Type : Entity_Id;
3048 Unprotected : Boolean := False) return List_Id
3050 Loc : constant Source_Ptr := Sloc (N);
3053 New_Plist : List_Id;
3054 New_Param : Node_Id;
3057 New_Plist := New_List;
3059 Formal := First_Formal (Ident);
3060 while Present (Formal) loop
3062 Make_Parameter_Specification (Loc,
3063 Defining_Identifier =>
3064 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
3065 In_Present => In_Present (Parent (Formal)),
3066 Out_Present => Out_Present (Parent (Formal)),
3067 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
3070 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3073 Append (New_Param, New_Plist);
3074 Next_Formal (Formal);
3077 -- If the subprogram is a procedure and the context is not an access
3078 -- to protected subprogram, the parameter is in-out. Otherwise it is
3082 Make_Parameter_Specification (Loc,
3083 Defining_Identifier =>
3084 Make_Defining_Identifier (Loc, Name_uObject),
3087 (Etype (Ident) = Standard_Void_Type
3088 and then not Is_RTE (Obj_Type, RE_Address)),
3090 New_Reference_To (Obj_Type, Loc));
3091 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3092 Prepend_To (New_Plist, Decl);
3095 end Build_Protected_Spec;
3097 ---------------------------------------
3098 -- Build_Protected_Sub_Specification --
3099 ---------------------------------------
3101 function Build_Protected_Sub_Specification
3103 Prot_Typ : Entity_Id;
3104 Mode : Subprogram_Protection_Mode) return Node_Id
3106 Loc : constant Source_Ptr := Sloc (N);
3110 New_Plist : List_Id;
3113 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3114 (Dispatching_Mode => ' ',
3115 Protected_Mode => 'P',
3116 Unprotected_Mode => 'N');
3119 if Ekind (Defining_Unit_Name (Specification (N))) =
3122 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3127 Def_Id := Defining_Unit_Name (Specification (Decl));
3130 Build_Protected_Spec
3131 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3132 Mode = Unprotected_Mode);
3134 Make_Defining_Identifier (Loc,
3135 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3137 -- The unprotected operation carries the user code, and debugging
3138 -- information must be generated for it, even though this spec does
3139 -- not come from source. It is also convenient to allow gdb to step
3140 -- into the protected operation, even though it only contains lock/
3143 Set_Debug_Info_Needed (New_Id);
3145 -- If a pragma Eliminate applies to the source entity, the internal
3146 -- subprograms will be eliminated as well.
3148 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3150 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3152 Make_Procedure_Specification (Loc,
3153 Defining_Unit_Name => New_Id,
3154 Parameter_Specifications => New_Plist);
3156 -- Create a new specification for the anonymous subprogram type
3160 Make_Function_Specification (Loc,
3161 Defining_Unit_Name => New_Id,
3162 Parameter_Specifications => New_Plist,
3163 Result_Definition =>
3164 Copy_Result_Type (Result_Definition (Specification (Decl))));
3166 Set_Return_Present (Defining_Unit_Name (New_Spec));
3170 end Build_Protected_Sub_Specification;
3172 -------------------------------------
3173 -- Build_Protected_Subprogram_Body --
3174 -------------------------------------
3176 function Build_Protected_Subprogram_Body
3179 N_Op_Spec : Node_Id) return Node_Id
3181 Loc : constant Source_Ptr := Sloc (N);
3183 P_Op_Spec : Node_Id;
3186 Unprot_Call : Node_Id;
3188 Lock_Name : Node_Id;
3189 Lock_Stmt : Node_Id;
3190 Service_Name : Node_Id;
3192 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3193 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3195 Object_Parm : Node_Id;
3198 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3199 -- Tell whether a given subprogram cannot raise an exception
3201 -----------------------
3202 -- Is_Exception_Safe --
3203 -----------------------
3205 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3207 function Has_Side_Effect (N : Node_Id) return Boolean;
3208 -- Return True whenever encountering a subprogram call or raise
3209 -- statement of any kind in the sequence of statements
3211 ---------------------
3212 -- Has_Side_Effect --
3213 ---------------------
3215 -- What is this doing buried two levels down in exp_ch9. It seems
3216 -- like a generally useful function, and indeed there may be code
3217 -- duplication going on here ???
3219 function Has_Side_Effect (N : Node_Id) return Boolean is
3223 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3224 -- Indicate whether N is a subprogram call or a raise statement
3226 ----------------------
3227 -- Is_Call_Or_Raise --
3228 ----------------------
3230 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3232 return Nkind_In (N, N_Procedure_Call_Statement,
3235 N_Raise_Constraint_Error,
3236 N_Raise_Program_Error,
3237 N_Raise_Storage_Error);
3238 end Is_Call_Or_Raise;
3240 -- Start of processing for Has_Side_Effect
3244 while Present (Stmt) loop
3245 if Is_Call_Or_Raise (Stmt) then
3249 -- An object declaration can also contain a function call
3250 -- or a raise statement
3252 if Nkind (Stmt) = N_Object_Declaration then
3253 Expr := Expression (Stmt);
3255 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3264 end Has_Side_Effect;
3266 -- Start of processing for Is_Exception_Safe
3269 -- If the checks handled by the back end are not disabled, we cannot
3270 -- ensure that no exception will be raised.
3272 if not Access_Checks_Suppressed (Empty)
3273 or else not Discriminant_Checks_Suppressed (Empty)
3274 or else not Range_Checks_Suppressed (Empty)
3275 or else not Index_Checks_Suppressed (Empty)
3276 or else Opt.Stack_Checking_Enabled
3281 if Has_Side_Effect (First (Declarations (Subprogram)))
3284 First (Statements (Handled_Statement_Sequence (Subprogram))))
3290 end Is_Exception_Safe;
3292 -- Start of processing for Build_Protected_Subprogram_Body
3295 Op_Spec := Specification (N);
3296 Exc_Safe := Is_Exception_Safe (N);
3299 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3301 -- Build a list of the formal parameters of the protected version of
3302 -- the subprogram to use as the actual parameters of the unprotected
3305 Uactuals := New_List;
3306 Pformal := First (Parameter_Specifications (P_Op_Spec));
3307 while Present (Pformal) loop
3308 Append_To (Uactuals,
3309 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
3313 -- Make a call to the unprotected version of the subprogram built above
3314 -- for use by the protected version built below.
3316 if Nkind (Op_Spec) = N_Function_Specification then
3318 R := Make_Temporary (Loc, 'R');
3320 Make_Object_Declaration (Loc,
3321 Defining_Identifier => R,
3322 Constant_Present => True,
3323 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3325 Make_Function_Call (Loc,
3326 Name => Make_Identifier (Loc,
3327 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3328 Parameter_Associations => Uactuals));
3331 Make_Simple_Return_Statement (Loc,
3332 Expression => New_Reference_To (R, Loc));
3335 Unprot_Call := Make_Simple_Return_Statement (Loc,
3336 Expression => Make_Function_Call (Loc,
3338 Make_Identifier (Loc,
3339 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3340 Parameter_Associations => Uactuals));
3345 Make_Procedure_Call_Statement (Loc,
3347 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3348 Parameter_Associations => Uactuals);
3351 -- Wrap call in block that will be covered by an at_end handler
3353 if not Exc_Safe then
3354 Unprot_Call := Make_Block_Statement (Loc,
3355 Handled_Statement_Sequence =>
3356 Make_Handled_Sequence_Of_Statements (Loc,
3357 Statements => New_List (Unprot_Call)));
3360 -- Make the protected subprogram body. This locks the protected
3361 -- object and calls the unprotected version of the subprogram.
3363 case Corresponding_Runtime_Package (Pid) is
3364 when System_Tasking_Protected_Objects_Entries =>
3365 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3366 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3368 when System_Tasking_Protected_Objects_Single_Entry =>
3369 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3370 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3372 when System_Tasking_Protected_Objects =>
3373 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3374 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3377 raise Program_Error;
3381 Make_Attribute_Reference (Loc,
3383 Make_Selected_Component (Loc,
3384 Prefix => Make_Identifier (Loc, Name_uObject),
3385 Selector_Name => Make_Identifier (Loc, Name_uObject)),
3386 Attribute_Name => Name_Unchecked_Access);
3388 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3390 Parameter_Associations => New_List (Object_Parm));
3392 if Abort_Allowed then
3394 Make_Procedure_Call_Statement (Loc,
3395 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3396 Parameter_Associations => Empty_List),
3400 Stmts := New_List (Lock_Stmt);
3403 if not Exc_Safe then
3404 Append (Unprot_Call, Stmts);
3406 if Nkind (Op_Spec) = N_Function_Specification then
3408 Stmts := Empty_List;
3410 Append (Unprot_Call, Stmts);
3414 Make_Procedure_Call_Statement (Loc,
3415 Name => Service_Name,
3416 Parameter_Associations =>
3417 New_List (New_Copy_Tree (Object_Parm))),
3420 if Abort_Allowed then
3422 Make_Procedure_Call_Statement (Loc,
3423 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3424 Parameter_Associations => Empty_List),
3428 if Nkind (Op_Spec) = N_Function_Specification then
3429 Append (Return_Stmt, Stmts);
3430 Append (Make_Block_Statement (Loc,
3431 Declarations => New_List (Unprot_Call),
3432 Handled_Statement_Sequence =>
3433 Make_Handled_Sequence_Of_Statements (Loc,
3434 Statements => Stmts)), Pre_Stmts);
3440 Make_Subprogram_Body (Loc,
3441 Declarations => Empty_List,
3442 Specification => P_Op_Spec,
3443 Handled_Statement_Sequence =>
3444 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3446 if not Exc_Safe then
3447 Set_Is_Protected_Subprogram_Body (Sub_Body);
3451 end Build_Protected_Subprogram_Body;
3453 -------------------------------------
3454 -- Build_Protected_Subprogram_Call --
3455 -------------------------------------
3457 procedure Build_Protected_Subprogram_Call
3461 External : Boolean := True)
3463 Loc : constant Source_Ptr := Sloc (N);
3464 Sub : constant Entity_Id := Entity (Name);
3470 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3473 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3476 if Present (Parameter_Associations (N)) then
3477 Params := New_Copy_List_Tree (Parameter_Associations (N));
3482 -- If the type is an untagged derived type, convert to the root type,
3483 -- which is the one on which the operations are defined.
3485 if Nkind (Rec) = N_Unchecked_Type_Conversion
3486 and then not Is_Tagged_Type (Etype (Rec))
3487 and then Is_Derived_Type (Etype (Rec))
3489 Set_Etype (Rec, Root_Type (Etype (Rec)));
3490 Set_Subtype_Mark (Rec,
3491 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3494 Prepend (Rec, Params);
3496 if Ekind (Sub) = E_Procedure then
3498 Make_Procedure_Call_Statement (Loc,
3500 Parameter_Associations => Params));
3503 pragma Assert (Ekind (Sub) = E_Function);
3505 Make_Function_Call (Loc,
3507 Parameter_Associations => Params));
3511 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3512 and then Is_Entity_Name (Expression (Rec))
3513 and then Is_Shared_Passive (Entity (Expression (Rec)))
3515 Add_Shared_Var_Lock_Procs (N);
3517 end Build_Protected_Subprogram_Call;
3519 -------------------------
3520 -- Build_Selected_Name --
3521 -------------------------
3523 function Build_Selected_Name
3524 (Prefix : Entity_Id;
3525 Selector : Entity_Id;
3526 Append_Char : Character := ' ') return Name_Id
3528 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3529 Select_Len : Natural;
3532 Get_Name_String (Chars (Selector));
3533 Select_Len := Name_Len;
3534 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3535 Get_Name_String (Chars (Prefix));
3537 -- If scope is anonymous type, discard suffix to recover name of
3538 -- single protected object. Otherwise use protected type name.
3540 if Name_Buffer (Name_Len) = 'T' then
3541 Name_Len := Name_Len - 1;
3544 Add_Str_To_Name_Buffer ("__");
3545 for J in 1 .. Select_Len loop
3546 Add_Char_To_Name_Buffer (Select_Buffer (J));
3549 -- Now add the Append_Char if specified. The encoding to follow
3550 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3551 -- then the entity is associated to a protected type subprogram.
3552 -- Otherwise, it is a protected type entry. For each case, the
3553 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3555 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3557 if Append_Char /= ' ' then
3558 if Append_Char = 'P' or Append_Char = 'N' then
3559 Add_Char_To_Name_Buffer (Append_Char);
3562 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3563 return New_External_Name (Name_Find, ' ', -1);
3568 end Build_Selected_Name;
3570 -----------------------------
3571 -- Build_Simple_Entry_Call --
3572 -----------------------------
3574 -- A task entry call is converted to a call to Call_Simple
3577 -- P : parms := (parm, parm, parm);
3579 -- Call_Simple (acceptor-task, entry-index, P'Address);
3585 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3586 -- the parameters, and the constructed aggregate value contains either the
3587 -- parameters or, in the case of non-elementary types, references to these
3588 -- parameters. Then the address of this aggregate is passed to the runtime
3589 -- routine, along with the task id value and the task entry index value.
3590 -- Pnn is only required if parameters are present.
3592 -- The assignments after the call are present only in the case of in-out
3593 -- or out parameters for elementary types, and are used to assign back the
3594 -- resulting values of such parameters.
3596 -- Note: the reason that we insert a block here is that in the context
3597 -- of selects, conditional entry calls etc. the entry call statement
3598 -- appears on its own, not as an element of a list.
3600 -- A protected entry call is converted to a Protected_Entry_Call:
3603 -- P : E1_Params := (param, param, param);
3605 -- Bnn : Communications_Block;
3608 -- P : E1_Params := (param, param, param);
3609 -- Bnn : Communications_Block;
3612 -- Protected_Entry_Call (
3613 -- Object => po._object'Access,
3614 -- E => <entry index>;
3615 -- Uninterpreted_Data => P'Address;
3616 -- Mode => Simple_Call;
3623 procedure Build_Simple_Entry_Call
3632 -- If call has been inlined, nothing left to do
3634 if Nkind (N) = N_Block_Statement then
3638 -- Convert entry call to Call_Simple call
3641 Loc : constant Source_Ptr := Sloc (N);
3642 Parms : constant List_Id := Parameter_Associations (N);
3643 Stats : constant List_Id := New_List;
3646 Comm_Name : Entity_Id;
3650 Ent_Acc : Entity_Id;
3652 Iface_Tag : Entity_Id;
3653 Iface_Typ : Entity_Id;
3666 -- Simple entry and entry family cases merge here
3668 Ent := Entity (Ename);
3669 Ent_Acc := Entry_Parameters_Type (Ent);
3670 Conctyp := Etype (Concval);
3672 -- If prefix is an access type, dereference to obtain the task type
3674 if Is_Access_Type (Conctyp) then
3675 Conctyp := Designated_Type (Conctyp);
3678 -- Special case for protected subprogram calls
3680 if Is_Protected_Type (Conctyp)
3681 and then Is_Subprogram (Entity (Ename))
3683 if not Is_Eliminated (Entity (Ename)) then
3684 Build_Protected_Subprogram_Call
3685 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3692 -- First parameter is the Task_Id value from the task value or the
3693 -- Object from the protected object value, obtained by selecting
3694 -- the _Task_Id or _Object from the result of doing an unchecked
3695 -- conversion to convert the value to the corresponding record type.
3697 if Nkind (Concval) = N_Function_Call
3698 and then Is_Task_Type (Conctyp)
3699 and then Ada_Version >= Ada_2005
3702 ExpR : constant Node_Id := Relocate_Node (Concval);
3703 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3708 Make_Object_Declaration (Loc,
3709 Defining_Identifier => Obj,
3710 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3711 Expression => ExpR);
3712 Set_Etype (Obj, Conctyp);
3713 Decls := New_List (Decl);
3714 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3721 Parm1 := Concurrent_Ref (Concval);
3723 -- Second parameter is the entry index, computed by the routine
3724 -- provided for this purpose. The value of this expression is
3725 -- assigned to an intermediate variable to assure that any entry
3726 -- family index expressions are evaluated before the entry
3730 or else Restriction_Active (No_Entry_Queue) = False
3731 or else not Is_Protected_Type (Conctyp)
3732 or else Number_Entries (Conctyp) > 1
3733 or else (Has_Attach_Handler (Conctyp)
3734 and then not Restricted_Profile)
3736 X := Make_Defining_Identifier (Loc, Name_uX);
3739 Make_Object_Declaration (Loc,
3740 Defining_Identifier => X,
3741 Object_Definition =>
3742 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3743 Expression => Actual_Index_Expression (
3744 Loc, Entity (Ename), Index, Concval));
3746 Append_To (Decls, Xdecl);
3747 Parm2 := New_Reference_To (X, Loc);
3754 -- The third parameter is the packaged parameters. If there are
3755 -- none, then it is just the null address, since nothing is passed.
3758 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3761 -- Case of parameters present, where third argument is the address
3762 -- of a packaged record containing the required parameter values.
3765 -- First build a list of parameter values, which are references to
3766 -- objects of the parameter types.
3770 Actual := First_Actual (N);
3771 Formal := First_Formal (Ent);
3773 while Present (Actual) loop
3775 -- If it is a by_copy_type, copy it to a new variable. The
3776 -- packaged record has a field that points to this variable.
3778 if Is_By_Copy_Type (Etype (Actual)) then
3780 Make_Object_Declaration (Loc,
3781 Defining_Identifier => Make_Temporary (Loc, 'J'),
3782 Aliased_Present => True,
3783 Object_Definition =>
3784 New_Reference_To (Etype (Formal), Loc));
3786 -- Mark the object as not needing initialization since the
3787 -- initialization is performed separately, avoiding errors
3788 -- on cases such as formals of null-excluding access types.
3790 Set_No_Initialization (N_Node);
3792 -- We must make an assignment statement separate for the
3793 -- case of limited type. We cannot assign it unless the
3794 -- Assignment_OK flag is set first. An out formal of an
3795 -- access type must also be initialized from the actual,
3796 -- as stated in RM 6.4.1 (13).
3798 if Ekind (Formal) /= E_Out_Parameter
3799 or else Is_Access_Type (Etype (Formal))
3802 New_Reference_To (Defining_Identifier (N_Node), Loc);
3803 Set_Assignment_OK (N_Var);
3805 Make_Assignment_Statement (Loc,
3807 Expression => Relocate_Node (Actual)));
3810 Append (N_Node, Decls);
3813 Make_Attribute_Reference (Loc,
3814 Attribute_Name => Name_Unchecked_Access,
3816 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3818 -- If it is a VM_By_Copy_Actual, copy it to a new variable
3820 elsif Is_VM_By_Copy_Actual (Actual) then
3822 Make_Object_Declaration (Loc,
3823 Defining_Identifier => Make_Temporary (Loc, 'J'),
3824 Aliased_Present => True,
3825 Object_Definition =>
3826 New_Reference_To (Etype (Formal), Loc),
3827 Expression => New_Copy_Tree (Actual));
3828 Set_Assignment_OK (N_Node);
3830 Append (N_Node, Decls);
3833 Make_Attribute_Reference (Loc,
3834 Attribute_Name => Name_Unchecked_Access,
3836 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3839 -- Interface class-wide formal
3841 if Ada_Version >= Ada_2005
3842 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3843 and then Is_Interface (Etype (Formal))
3845 Iface_Typ := Etype (Etype (Formal));
3848 -- formal_iface_type! (actual.iface_tag)'reference
3851 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3852 pragma Assert (Present (Iface_Tag));
3855 Make_Reference (Loc,
3856 Unchecked_Convert_To (Iface_Typ,
3857 Make_Selected_Component (Loc,
3859 Relocate_Node (Actual),
3861 New_Reference_To (Iface_Tag, Loc)))));
3867 Make_Reference (Loc, Relocate_Node (Actual)));
3871 Next_Actual (Actual);
3872 Next_Formal_With_Extras (Formal);
3875 -- Now build the declaration of parameters initialized with the
3876 -- aggregate containing this constructed parameter list.
3878 P := Make_Defining_Identifier (Loc, Name_uP);
3881 Make_Object_Declaration (Loc,
3882 Defining_Identifier => P,
3883 Object_Definition =>
3884 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3886 Make_Aggregate (Loc, Expressions => Plist));
3889 Make_Attribute_Reference (Loc,
3890 Prefix => New_Reference_To (P, Loc),
3891 Attribute_Name => Name_Address);
3893 Append (Pdecl, Decls);
3896 -- Now we can create the call, case of protected type
3898 if Is_Protected_Type (Conctyp) then
3899 case Corresponding_Runtime_Package (Conctyp) is
3900 when System_Tasking_Protected_Objects_Entries =>
3902 -- Change the type of the index declaration
3904 Set_Object_Definition (Xdecl,
3905 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3907 -- Some additional declarations for protected entry calls
3913 -- Bnn : Communications_Block;
3915 Comm_Name := Make_Temporary (Loc, 'B');
3918 Make_Object_Declaration (Loc,
3919 Defining_Identifier => Comm_Name,
3920 Object_Definition =>
3921 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3923 -- Some additional statements for protected entry calls
3925 -- Protected_Entry_Call (
3926 -- Object => po._object'Access,
3927 -- E => <entry index>;
3928 -- Uninterpreted_Data => P'Address;
3929 -- Mode => Simple_Call;
3933 Make_Procedure_Call_Statement (Loc,
3935 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3937 Parameter_Associations => New_List (
3938 Make_Attribute_Reference (Loc,
3939 Attribute_Name => Name_Unchecked_Access,
3943 New_Reference_To (RTE (RE_Simple_Call), Loc),
3944 New_Occurrence_Of (Comm_Name, Loc)));
3946 when System_Tasking_Protected_Objects_Single_Entry =>
3947 -- Protected_Single_Entry_Call (
3948 -- Object => po._object'Access,
3949 -- Uninterpreted_Data => P'Address;
3950 -- Mode => Simple_Call);
3953 Make_Procedure_Call_Statement (Loc,
3954 Name => New_Reference_To (
3955 RTE (RE_Protected_Single_Entry_Call), Loc),
3957 Parameter_Associations => New_List (
3958 Make_Attribute_Reference (Loc,
3959 Attribute_Name => Name_Unchecked_Access,
3962 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3965 raise Program_Error;
3968 -- Case of task type
3972 Make_Procedure_Call_Statement (Loc,
3973 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3974 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3978 Append_To (Stats, Call);
3980 -- If there are out or in/out parameters by copy add assignment
3981 -- statements for the result values.
3983 if Present (Parms) then
3984 Actual := First_Actual (N);
3985 Formal := First_Formal (Ent);
3987 Set_Assignment_OK (Actual);
3988 while Present (Actual) loop
3989 if (Is_By_Copy_Type (Etype (Actual))
3990 or else Is_VM_By_Copy_Actual (Actual))
3991 and then Ekind (Formal) /= E_In_Parameter
3994 Make_Assignment_Statement (Loc,
3995 Name => New_Copy (Actual),
3997 Make_Explicit_Dereference (Loc,
3998 Make_Selected_Component (Loc,
3999 Prefix => New_Reference_To (P, Loc),
4001 Make_Identifier (Loc, Chars (Formal)))));
4003 -- In all cases (including limited private types) we want
4004 -- the assignment to be valid.
4006 Set_Assignment_OK (Name (N_Node));
4008 -- If the call is the triggering alternative in an
4009 -- asynchronous select, or the entry_call alternative of a
4010 -- conditional entry call, the assignments for in-out
4011 -- parameters are incorporated into the statement list that
4012 -- follows, so that there are executed only if the entry
4015 if (Nkind (Parent (N)) = N_Triggering_Alternative
4016 and then N = Triggering_Statement (Parent (N)))
4018 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4019 and then N = Entry_Call_Statement (Parent (N)))
4021 if No (Statements (Parent (N))) then
4022 Set_Statements (Parent (N), New_List);
4025 Prepend (N_Node, Statements (Parent (N)));
4028 Insert_After (Call, N_Node);
4032 Next_Actual (Actual);
4033 Next_Formal_With_Extras (Formal);
4037 -- Finally, create block and analyze it
4040 Make_Block_Statement (Loc,
4041 Declarations => Decls,
4042 Handled_Statement_Sequence =>
4043 Make_Handled_Sequence_Of_Statements (Loc,
4044 Statements => Stats)));
4048 end Build_Simple_Entry_Call;
4050 --------------------------------
4051 -- Build_Task_Activation_Call --
4052 --------------------------------
4054 procedure Build_Task_Activation_Call (N : Node_Id) is
4055 Loc : constant Source_Ptr := Sloc (N);
4062 -- Get the activation chain entity. Except in the case of a package
4063 -- body, this is in the node that was passed. For a package body, we
4064 -- have to find the corresponding package declaration node.
4066 if Nkind (N) = N_Package_Body then
4067 P := Corresponding_Spec (N);
4070 exit when Nkind (P) = N_Package_Declaration;
4073 Chain := Activation_Chain_Entity (P);
4076 Chain := Activation_Chain_Entity (N);
4079 if Present (Chain) then
4080 if Restricted_Profile then
4081 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
4083 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4087 Make_Procedure_Call_Statement (Loc,
4089 Parameter_Associations =>
4090 New_List (Make_Attribute_Reference (Loc,
4091 Prefix => New_Occurrence_Of (Chain, Loc),
4092 Attribute_Name => Name_Unchecked_Access)));
4094 if Nkind (N) = N_Package_Declaration then
4095 if Present (Corresponding_Body (N)) then
4098 elsif Present (Private_Declarations (Specification (N))) then
4099 Append (Call, Private_Declarations (Specification (N)));
4102 Append (Call, Visible_Declarations (Specification (N)));
4106 if Present (Handled_Statement_Sequence (N)) then
4108 -- The call goes at the start of the statement sequence
4109 -- after the start of exception range label if one is present.
4115 Stm := First (Statements (Handled_Statement_Sequence (N)));
4117 -- A special case, skip exception range label if one is
4118 -- present (from front end zcx processing).
4120 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4124 -- Another special case, if the first statement is a block
4125 -- from optimization of a local raise to a goto, then the
4126 -- call goes inside this block.
4128 if Nkind (Stm) = N_Block_Statement
4129 and then Exception_Junk (Stm)
4132 First (Statements (Handled_Statement_Sequence (Stm)));
4135 -- Insertion point is after any exception label pushes,
4136 -- since we want it covered by any local handlers.
4138 while Nkind (Stm) in N_Push_xxx_Label loop
4142 -- Now we have the proper insertion point
4144 Insert_Before (Stm, Call);
4148 Set_Handled_Statement_Sequence (N,
4149 Make_Handled_Sequence_Of_Statements (Loc,
4150 Statements => New_List (Call)));
4155 Check_Task_Activation (N);
4157 end Build_Task_Activation_Call;
4159 -------------------------------
4160 -- Build_Task_Allocate_Block --
4161 -------------------------------
4163 procedure Build_Task_Allocate_Block
4168 T : constant Entity_Id := Entity (Expression (N));
4169 Init : constant Entity_Id := Base_Init_Proc (T);
4170 Loc : constant Source_Ptr := Sloc (N);
4171 Chain : constant Entity_Id :=
4172 Make_Defining_Identifier (Loc, Name_uChain);
4173 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4178 Make_Block_Statement (Loc,
4179 Identifier => New_Reference_To (Blkent, Loc),
4180 Declarations => New_List (
4182 -- _Chain : Activation_Chain;
4184 Make_Object_Declaration (Loc,
4185 Defining_Identifier => Chain,
4186 Aliased_Present => True,
4187 Object_Definition =>
4188 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4190 Handled_Statement_Sequence =>
4191 Make_Handled_Sequence_Of_Statements (Loc,
4193 Statements => New_List (
4197 Make_Procedure_Call_Statement (Loc,
4198 Name => New_Reference_To (Init, Loc),
4199 Parameter_Associations => Args),
4201 -- Activate_Tasks (_Chain);
4203 Make_Procedure_Call_Statement (Loc,
4204 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4205 Parameter_Associations => New_List (
4206 Make_Attribute_Reference (Loc,
4207 Prefix => New_Reference_To (Chain, Loc),
4208 Attribute_Name => Name_Unchecked_Access))))),
4210 Has_Created_Identifier => True,
4211 Is_Task_Allocation_Block => True);
4214 Make_Implicit_Label_Declaration (Loc,
4215 Defining_Identifier => Blkent,
4216 Label_Construct => Block));
4218 Append_To (Actions, Block);
4220 Set_Activation_Chain_Entity (Block, Chain);
4221 end Build_Task_Allocate_Block;
4223 -----------------------------------------------
4224 -- Build_Task_Allocate_Block_With_Init_Stmts --
4225 -----------------------------------------------
4227 procedure Build_Task_Allocate_Block_With_Init_Stmts
4230 Init_Stmts : List_Id)
4232 Loc : constant Source_Ptr := Sloc (N);
4233 Chain : constant Entity_Id :=
4234 Make_Defining_Identifier (Loc, Name_uChain);
4235 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4239 Append_To (Init_Stmts,
4240 Make_Procedure_Call_Statement (Loc,
4241 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4242 Parameter_Associations => New_List (
4243 Make_Attribute_Reference (Loc,
4244 Prefix => New_Reference_To (Chain, Loc),
4245 Attribute_Name => Name_Unchecked_Access))));
4248 Make_Block_Statement (Loc,
4249 Identifier => New_Reference_To (Blkent, Loc),
4250 Declarations => New_List (
4252 -- _Chain : Activation_Chain;
4254 Make_Object_Declaration (Loc,
4255 Defining_Identifier => Chain,
4256 Aliased_Present => True,
4257 Object_Definition =>
4258 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4260 Handled_Statement_Sequence =>
4261 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4263 Has_Created_Identifier => True,
4264 Is_Task_Allocation_Block => True);
4267 Make_Implicit_Label_Declaration (Loc,
4268 Defining_Identifier => Blkent,
4269 Label_Construct => Block));
4271 Append_To (Actions, Block);
4273 Set_Activation_Chain_Entity (Block, Chain);
4274 end Build_Task_Allocate_Block_With_Init_Stmts;
4276 -----------------------------------
4277 -- Build_Task_Proc_Specification --
4278 -----------------------------------
4280 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4281 Loc : constant Source_Ptr := Sloc (T);
4282 Spec_Id : Entity_Id;
4285 -- Case of explicit task type, suffix TB
4287 if Comes_From_Source (T) then
4289 Make_Defining_Identifier (Loc,
4290 Chars => New_External_Name (Chars (T), "TB"));
4292 -- Case of anonymous task type, suffix B
4296 Make_Defining_Identifier (Loc,
4297 Chars => New_External_Name (Chars (T), 'B'));
4300 Set_Is_Internal (Spec_Id);
4302 -- Associate the procedure with the task, if this is the declaration
4303 -- (and not the body) of the procedure.
4305 if No (Task_Body_Procedure (T)) then
4306 Set_Task_Body_Procedure (T, Spec_Id);
4310 Make_Procedure_Specification (Loc,
4311 Defining_Unit_Name => Spec_Id,
4312 Parameter_Specifications => New_List (
4313 Make_Parameter_Specification (Loc,
4314 Defining_Identifier =>
4315 Make_Defining_Identifier (Loc, Name_uTask),
4317 Make_Access_Definition (Loc,
4319 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4320 end Build_Task_Proc_Specification;
4322 ---------------------------------------
4323 -- Build_Unprotected_Subprogram_Body --
4324 ---------------------------------------
4326 function Build_Unprotected_Subprogram_Body
4328 Pid : Node_Id) return Node_Id
4330 Decls : constant List_Id := Declarations (N);
4333 -- Add renamings for the Protection object, discriminals, privals and
4334 -- the entry index constant for use by debugger.
4336 Debug_Private_Data_Declarations (Decls);
4338 -- Make an unprotected version of the subprogram for use within the same
4339 -- object, with a new name and an additional parameter representing the
4343 Make_Subprogram_Body (Sloc (N),
4345 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4346 Declarations => Decls,
4347 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4348 end Build_Unprotected_Subprogram_Body;
4350 ----------------------------
4351 -- Collect_Entry_Families --
4352 ----------------------------
4354 procedure Collect_Entry_Families
4357 Current_Node : in out Node_Id;
4358 Conctyp : Entity_Id)
4361 Efam_Decl : Node_Id;
4362 Efam_Type : Entity_Id;
4365 Efam := First_Entity (Conctyp);
4366 while Present (Efam) loop
4367 if Ekind (Efam) = E_Entry_Family then
4368 Efam_Type := Make_Temporary (Loc, 'F');
4373 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4375 Bas_Decl : Node_Id := Empty;
4380 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4382 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4383 Bas := Make_Temporary (Loc, 'B');
4386 Make_Subtype_Declaration (Loc,
4387 Defining_Identifier => Bas,
4388 Subtype_Indication =>
4389 Make_Subtype_Indication (Loc,
4391 New_Occurrence_Of (Standard_Integer, Loc),
4393 Make_Range_Constraint (Loc,
4394 Range_Expression => Make_Range (Loc,
4395 Make_Integer_Literal
4396 (Loc, -Entry_Family_Bound),
4397 Make_Integer_Literal
4398 (Loc, Entry_Family_Bound - 1)))));
4400 Insert_After (Current_Node, Bas_Decl);
4401 Current_Node := Bas_Decl;
4406 Make_Full_Type_Declaration (Loc,
4407 Defining_Identifier => Efam_Type,
4409 Make_Unconstrained_Array_Definition (Loc,
4411 (New_List (New_Occurrence_Of (Bas, Loc))),
4413 Component_Definition =>
4414 Make_Component_Definition (Loc,
4415 Aliased_Present => False,
4416 Subtype_Indication =>
4417 New_Reference_To (Standard_Character, Loc))));
4420 Insert_After (Current_Node, Efam_Decl);
4421 Current_Node := Efam_Decl;
4422 Analyze (Efam_Decl);
4425 Make_Component_Declaration (Loc,
4426 Defining_Identifier =>
4427 Make_Defining_Identifier (Loc, Chars (Efam)),
4429 Component_Definition =>
4430 Make_Component_Definition (Loc,
4431 Aliased_Present => False,
4432 Subtype_Indication =>
4433 Make_Subtype_Indication (Loc,
4435 New_Occurrence_Of (Efam_Type, Loc),
4438 Make_Index_Or_Discriminant_Constraint (Loc,
4439 Constraints => New_List (
4441 (Etype (Discrete_Subtype_Definition
4442 (Parent (Efam))), Loc)))))));
4448 end Collect_Entry_Families;
4450 -----------------------
4451 -- Concurrent_Object --
4452 -----------------------
4454 function Concurrent_Object
4455 (Spec_Id : Entity_Id;
4456 Conc_Typ : Entity_Id) return Entity_Id
4459 -- Parameter _O or _object
4461 if Is_Protected_Type (Conc_Typ) then
4462 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4467 pragma Assert (Is_Task_Type (Conc_Typ));
4468 return First_Formal (Task_Body_Procedure (Conc_Typ));
4470 end Concurrent_Object;
4472 ----------------------
4473 -- Copy_Result_Type --
4474 ----------------------
4476 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4477 New_Res : constant Node_Id := New_Copy_Tree (Res);
4482 -- If the result type is an access_to_subprogram, we must create
4483 -- new entities for its spec.
4485 if Nkind (New_Res) = N_Access_Definition
4486 and then Present (Access_To_Subprogram_Definition (New_Res))
4488 -- Provide new entities for the formals
4490 Par_Spec := First (Parameter_Specifications
4491 (Access_To_Subprogram_Definition (New_Res)));
4492 while Present (Par_Spec) loop
4493 Formal := Defining_Identifier (Par_Spec);
4494 Set_Defining_Identifier (Par_Spec,
4495 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4501 end Copy_Result_Type;
4503 --------------------
4504 -- Concurrent_Ref --
4505 --------------------
4507 -- The expression returned for a reference to a concurrent object has the
4510 -- taskV!(name)._Task_Id
4514 -- objectV!(name)._Object
4516 -- for a protected object. For the case of an access to a concurrent
4517 -- object, there is an extra explicit dereference:
4519 -- taskV!(name.all)._Task_Id
4520 -- objectV!(name.all)._Object
4522 -- here taskV and objectV are the types for the associated records, which
4523 -- contain the required _Task_Id and _Object fields for tasks and protected
4524 -- objects, respectively.
4526 -- For the case of a task type name, the expression is
4530 -- i.e. a call to the Self function which returns precisely this Task_Id
4532 -- For the case of a protected type name, the expression is
4536 -- which is a renaming of the _object field of the current object
4537 -- record, passed into protected operations as a parameter.
4539 function Concurrent_Ref (N : Node_Id) return Node_Id is
4540 Loc : constant Source_Ptr := Sloc (N);
4541 Ntyp : constant Entity_Id := Etype (N);
4545 function Is_Current_Task (T : Entity_Id) return Boolean;
4546 -- Check whether the reference is to the immediately enclosing task
4547 -- type, or to an outer one (rare but legal).
4549 ---------------------
4550 -- Is_Current_Task --
4551 ---------------------
4553 function Is_Current_Task (T : Entity_Id) return Boolean is
4557 Scop := Current_Scope;
4558 while Present (Scop)
4559 and then Scop /= Standard_Standard
4565 elsif Is_Task_Type (Scop) then
4568 -- If this is a procedure nested within the task type, we must
4569 -- assume that it can be called from an inner task, and therefore
4570 -- cannot treat it as a local reference.
4572 elsif Is_Overloadable (Scop)
4573 and then In_Open_Scopes (T)
4578 Scop := Scope (Scop);
4582 -- We know that we are within the task body, so should have found it
4585 raise Program_Error;
4586 end Is_Current_Task;
4588 -- Start of processing for Concurrent_Ref
4591 if Is_Access_Type (Ntyp) then
4592 Dtyp := Designated_Type (Ntyp);
4594 if Is_Protected_Type (Dtyp) then
4595 Sel := Name_uObject;
4597 Sel := Name_uTask_Id;
4601 Make_Selected_Component (Loc,
4603 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4604 Make_Explicit_Dereference (Loc, N)),
4605 Selector_Name => Make_Identifier (Loc, Sel));
4607 elsif Is_Entity_Name (N)
4608 and then Is_Concurrent_Type (Entity (N))
4610 if Is_Task_Type (Entity (N)) then
4612 if Is_Current_Task (Entity (N)) then
4614 Make_Function_Call (Loc,
4615 Name => New_Reference_To (RTE (RE_Self), Loc));
4620 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4621 T_Body : constant Node_Id :=
4622 Parent (Corresponding_Body (Parent (Entity (N))));
4626 Make_Object_Declaration (Loc,
4627 Defining_Identifier => T_Self,
4628 Object_Definition =>
4629 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4631 Make_Function_Call (Loc,
4632 Name => New_Reference_To (RTE (RE_Self), Loc)));
4633 Prepend (Decl, Declarations (T_Body));
4635 Set_Scope (T_Self, Entity (N));
4636 return New_Occurrence_Of (T_Self, Loc);
4641 pragma Assert (Is_Protected_Type (Entity (N)));
4644 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4648 if Is_Protected_Type (Ntyp) then
4649 Sel := Name_uObject;
4651 elsif Is_Task_Type (Ntyp) then
4652 Sel := Name_uTask_Id;
4655 raise Program_Error;
4659 Make_Selected_Component (Loc,
4661 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4663 Selector_Name => Make_Identifier (Loc, Sel));
4667 ------------------------
4668 -- Convert_Concurrent --
4669 ------------------------
4671 function Convert_Concurrent
4673 Typ : Entity_Id) return Node_Id
4676 if not Is_Concurrent_Type (Typ) then
4680 Unchecked_Convert_To
4681 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4683 end Convert_Concurrent;
4685 -------------------------------------
4686 -- Debug_Private_Data_Declarations --
4687 -------------------------------------
4689 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4690 Debug_Nod : Node_Id;
4694 Decl := First (Decls);
4695 while Present (Decl)
4696 and then not Comes_From_Source (Decl)
4698 -- Declaration for concurrent entity _object and its access type,
4699 -- along with the entry index subtype:
4700 -- type prot_typVP is access prot_typV;
4701 -- _object : prot_typVP := prot_typV (_O);
4702 -- subtype Jnn is <Type of Index> range Low .. High;
4704 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4705 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4707 -- Declaration for the Protection object, discriminals, privals and
4708 -- entry index constant:
4709 -- conc_typR : protection_typ renames _object._object;
4710 -- discr_nameD : discr_typ renames _object.discr_name;
4711 -- discr_nameD : discr_typ renames _task.discr_name;
4712 -- prival_name : comp_typ renames _object.comp_name;
4713 -- J : constant Jnn :=
4714 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4716 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4717 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4718 Debug_Nod := Debug_Renaming_Declaration (Decl);
4720 if Present (Debug_Nod) then
4721 Insert_After (Decl, Debug_Nod);
4727 end Debug_Private_Data_Declarations;
4729 ----------------------------
4730 -- Entry_Index_Expression --
4731 ----------------------------
4733 function Entry_Index_Expression
4737 Ttyp : Entity_Id) return Node_Id
4747 -- The queues of entries and entry families appear in textual order in
4748 -- the associated record. The entry index is computed as the sum of the
4749 -- number of queues for all entries that precede the designated one, to
4750 -- which is added the index expression, if this expression denotes a
4751 -- member of a family.
4753 -- The following is a place holder for the count of simple entries
4755 Num := Make_Integer_Literal (Sloc, 1);
4757 -- We construct an expression which is a series of addition operations.
4758 -- The first operand is the number of single entries that precede this
4759 -- one, the second operand is the index value relative to the start of
4760 -- the referenced family, and the remaining operands are the lengths of
4761 -- the entry families that precede this entry, i.e. the constructed
4764 -- number_simple_entries +
4765 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4766 -- family'length + ...
4768 -- where index-value is the given index value, and s is the index
4769 -- subtype (we have to use pos because the subtype might be an
4770 -- enumeration type preventing direct subtraction). Note that the task
4771 -- entry array is one-indexed.
4773 -- The upper bound of the entry family may be a discriminant, so we
4774 -- retrieve the lower bound explicitly to compute offset, rather than
4775 -- using the index subtype which may mention a discriminant.
4777 if Present (Index) then
4778 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4787 Make_Attribute_Reference (Sloc,
4788 Attribute_Name => Name_Pos,
4789 Prefix => New_Reference_To (Base_Type (S), Sloc),
4790 Expressions => New_List (Relocate_Node (Index))),
4798 -- Now add lengths of preceding entries and entry families
4800 Prev := First_Entity (Ttyp);
4802 while Chars (Prev) /= Chars (Ent)
4803 or else (Ekind (Prev) /= Ekind (Ent))
4804 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4806 if Ekind (Prev) = E_Entry then
4807 Set_Intval (Num, Intval (Num) + 1);
4809 elsif Ekind (Prev) = E_Entry_Family then
4811 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4812 Lo := Type_Low_Bound (S);
4813 Hi := Type_High_Bound (S);
4818 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4820 -- Other components are anonymous types to be ignored
4830 end Entry_Index_Expression;
4832 ---------------------------
4833 -- Establish_Task_Master --
4834 ---------------------------
4836 procedure Establish_Task_Master (N : Node_Id) is
4839 if Restriction_Active (No_Task_Hierarchy) = False then
4840 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4841 Prepend_To (Declarations (N), Call);
4844 end Establish_Task_Master;
4846 --------------------------------
4847 -- Expand_Accept_Declarations --
4848 --------------------------------
4850 -- Part of the expansion of an accept statement involves the creation of
4851 -- a declaration that can be referenced from the statement sequence of
4856 -- This declaration is inserted immediately before the accept statement
4857 -- and it is important that it be inserted before the statements of the
4858 -- statement sequence are analyzed. Thus it would be too late to create
4859 -- this declaration in the Expand_N_Accept_Statement routine, which is
4860 -- why there is a separate procedure to be called directly from Sem_Ch9.
4862 -- Ann is used to hold the address of the record containing the parameters
4863 -- (see Expand_N_Entry_Call for more details on how this record is built).
4864 -- References to the parameters do an unchecked conversion of this address
4865 -- to a pointer to the required record type, and then access the field that
4866 -- holds the value of the required parameter. The entity for the address
4867 -- variable is held as the top stack element (i.e. the last element) of the
4868 -- Accept_Address stack in the corresponding entry entity, and this element
4869 -- must be set in place before the statements are processed.
4871 -- The above description applies to the case of a stand alone accept
4872 -- statement, i.e. one not appearing as part of a select alternative.
4874 -- For the case of an accept that appears as part of a select alternative
4875 -- of a selective accept, we must still create the declaration right away,
4876 -- since Ann is needed immediately, but there is an important difference:
4878 -- The declaration is inserted before the selective accept, not before
4879 -- the accept statement (which is not part of a list anyway, and so would
4880 -- not accommodate inserted declarations)
4882 -- We only need one address variable for the entire selective accept. So
4883 -- the Ann declaration is created only for the first accept alternative,
4884 -- and subsequent accept alternatives reference the same Ann variable.
4886 -- We can distinguish the two cases by seeing whether the accept statement
4887 -- is part of a list. If not, then it must be in an accept alternative.
4889 -- To expand the requeue statement, a label is provided at the end of the
4890 -- accept statement or alternative of which it is a part, so that the
4891 -- statement can be skipped after the requeue is complete. This label is
4892 -- created here rather than during the expansion of the accept statement,
4893 -- because it will be needed by any requeue statements within the accept,
4894 -- which are expanded before the accept.
4896 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4897 Loc : constant Source_Ptr := Sloc (N);
4898 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4899 Ann : Entity_Id := Empty;
4907 if Full_Expander_Active then
4909 -- If we have no handled statement sequence, we may need to build
4910 -- a dummy sequence consisting of a null statement. This can be
4911 -- skipped if the trivial accept optimization is permitted.
4913 if not Trivial_Accept_OK
4915 (No (Stats) or else Null_Statements (Statements (Stats)))
4917 Set_Handled_Statement_Sequence (N,
4918 Make_Handled_Sequence_Of_Statements (Loc,
4919 Statements => New_List (Make_Null_Statement (Loc))));
4922 -- Create and declare two labels to be placed at the end of the
4923 -- accept statement. The first label is used to allow requeues to
4924 -- skip the remainder of entry processing. The second label is used
4925 -- to skip the remainder of entry processing if the rendezvous
4926 -- completes in the middle of the accept body.
4928 if Present (Handled_Statement_Sequence (N)) then
4933 Ent := Make_Temporary (Loc, 'L');
4934 Lab_Id := New_Reference_To (Ent, Loc);
4935 Lab := Make_Label (Loc, Lab_Id);
4937 Make_Implicit_Label_Declaration (Loc,
4938 Defining_Identifier => Ent,
4939 Label_Construct => Lab);
4940 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4942 Ent := Make_Temporary (Loc, 'L');
4943 Lab_Id := New_Reference_To (Ent, Loc);
4944 Lab := Make_Label (Loc, Lab_Id);
4946 Make_Implicit_Label_Declaration (Loc,
4947 Defining_Identifier => Ent,
4948 Label_Construct => Lab);
4949 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4957 -- Case of stand alone accept statement
4959 if Is_List_Member (N) then
4961 if Present (Handled_Statement_Sequence (N)) then
4962 Ann := Make_Temporary (Loc, 'A');
4965 Make_Object_Declaration (Loc,
4966 Defining_Identifier => Ann,
4967 Object_Definition =>
4968 New_Reference_To (RTE (RE_Address), Loc));
4970 Insert_Before (N, Adecl);
4973 Insert_Before (N, Ldecl);
4976 Insert_Before (N, Ldecl2);
4980 -- Case of accept statement which is in an accept alternative
4984 Acc_Alt : constant Node_Id := Parent (N);
4985 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4989 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4990 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4992 -- ??? Consider a single label for select statements
4994 if Present (Handled_Statement_Sequence (N)) then
4996 Statements (Handled_Statement_Sequence (N)));
5000 Statements (Handled_Statement_Sequence (N)));
5004 -- Find first accept alternative of the selective accept. A
5005 -- valid selective accept must have at least one accept in it.
5007 Alt := First (Select_Alternatives (Sel_Acc));
5009 while Nkind (Alt) /= N_Accept_Alternative loop
5013 -- If we are the first accept statement, then we have to create
5014 -- the Ann variable, as for the stand alone case, except that
5015 -- it is inserted before the selective accept. Similarly, a
5016 -- label for requeue expansion must be declared.
5018 if N = Accept_Statement (Alt) then
5019 Ann := Make_Temporary (Loc, 'A');
5021 Make_Object_Declaration (Loc,
5022 Defining_Identifier => Ann,
5023 Object_Definition =>
5024 New_Reference_To (RTE (RE_Address), Loc));
5026 Insert_Before (Sel_Acc, Adecl);
5029 -- If we are not the first accept statement, then find the Ann
5030 -- variable allocated by the first accept and use it.
5034 Node (Last_Elmt (Accept_Address
5035 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
5040 -- Merge here with Ann either created or referenced, and Adecl
5041 -- pointing to the corresponding declaration. Remaining processing
5042 -- is the same for the two cases.
5044 if Present (Ann) then
5045 Append_Elmt (Ann, Accept_Address (Ent));
5046 Set_Debug_Info_Needed (Ann);
5049 -- Create renaming declarations for the entry formals. Each reference
5050 -- to a formal becomes a dereference of a component of the parameter
5051 -- block, whose address is held in Ann. These declarations are
5052 -- eventually inserted into the accept block, and analyzed there so
5053 -- that they have the proper scope for gdb and do not conflict with
5054 -- other declarations.
5056 if Present (Parameter_Specifications (N))
5057 and then Present (Handled_Statement_Sequence (N))
5064 Renamed_Formal : Node_Id;
5068 Formal := First_Formal (Ent);
5070 while Present (Formal) loop
5071 Comp := Entry_Component (Formal);
5073 Make_Defining_Identifier (Loc, Chars (Formal));
5075 Set_Etype (New_F, Etype (Formal));
5076 Set_Scope (New_F, Ent);
5078 -- Now we set debug info needed on New_F even though it does
5079 -- not come from source, so that the debugger will get the
5080 -- right information for these generated names.
5082 Set_Debug_Info_Needed (New_F);
5084 if Ekind (Formal) = E_In_Parameter then
5085 Set_Ekind (New_F, E_Constant);
5087 Set_Ekind (New_F, E_Variable);
5088 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5091 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5094 Make_Selected_Component (Loc,
5096 Unchecked_Convert_To (
5097 Entry_Parameters_Type (Ent),
5098 New_Reference_To (Ann, Loc)),
5100 New_Reference_To (Comp, Loc));
5103 Build_Renamed_Formal_Declaration
5104 (New_F, Formal, Comp, Renamed_Formal);
5106 if No (Declarations (N)) then
5107 Set_Declarations (N, New_List);
5110 Append (Decl, Declarations (N));
5111 Set_Renamed_Object (Formal, New_F);
5112 Next_Formal (Formal);
5119 end Expand_Accept_Declarations;
5121 ---------------------------------------------
5122 -- Expand_Access_Protected_Subprogram_Type --
5123 ---------------------------------------------
5125 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5126 Loc : constant Source_Ptr := Sloc (N);
5128 T : constant Entity_Id := Defining_Identifier (N);
5129 D_T : constant Entity_Id := Designated_Type (T);
5130 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5131 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5132 P_List : constant List_Id := Build_Protected_Spec
5133 (N, RTE (RE_Address), D_T, False);
5139 -- Create access to subprogram with full signature
5141 if Etype (D_T) /= Standard_Void_Type then
5143 Make_Access_Function_Definition (Loc,
5144 Parameter_Specifications => P_List,
5145 Result_Definition =>
5146 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5150 Make_Access_Procedure_Definition (Loc,
5151 Parameter_Specifications => P_List);
5155 Make_Full_Type_Declaration (Loc,
5156 Defining_Identifier => D_T2,
5157 Type_Definition => Def1);
5159 Insert_After (N, Decl1);
5162 -- Associate the access to subprogram with its original access to
5163 -- protected subprogram type. Needed by the backend to know that this
5164 -- type corresponds with an access to protected subprogram type.
5166 Set_Original_Access_Type (D_T2, T);
5168 -- Create Equivalent_Type, a record with two components for an access to
5169 -- object and an access to subprogram.
5172 Make_Component_Declaration (Loc,
5173 Defining_Identifier => Make_Temporary (Loc, 'P'),
5174 Component_Definition =>
5175 Make_Component_Definition (Loc,
5176 Aliased_Present => False,
5177 Subtype_Indication =>
5178 New_Occurrence_Of (RTE (RE_Address), Loc))),
5180 Make_Component_Declaration (Loc,
5181 Defining_Identifier => Make_Temporary (Loc, 'S'),
5182 Component_Definition =>
5183 Make_Component_Definition (Loc,
5184 Aliased_Present => False,
5185 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5188 Make_Full_Type_Declaration (Loc,
5189 Defining_Identifier => E_T,
5191 Make_Record_Definition (Loc,
5193 Make_Component_List (Loc,
5194 Component_Items => Comps)));
5196 Insert_After (Decl1, Decl2);
5198 Set_Equivalent_Type (T, E_T);
5199 end Expand_Access_Protected_Subprogram_Type;
5201 --------------------------
5202 -- Expand_Entry_Barrier --
5203 --------------------------
5205 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5206 Cond : constant Node_Id :=
5207 Condition (Entry_Body_Formal_Part (N));
5208 Prot : constant Entity_Id := Scope (Ent);
5209 Spec_Decl : constant Node_Id := Parent (Prot);
5212 Body_Decl : Node_Id;
5215 if No_Run_Time_Mode then
5216 Error_Msg_CRT ("entry barrier", N);
5220 -- The body of the entry barrier must be analyzed in the context of the
5221 -- protected object, but its scope is external to it, just as any other
5222 -- unprotected version of a protected operation. The specification has
5223 -- been produced when the protected type declaration was elaborated. We
5224 -- build the body, insert it in the enclosing scope, but analyze it in
5225 -- the current context. A more uniform approach would be to treat the
5226 -- barrier just as a protected function, and discard the protected
5227 -- version of it because it is never called.
5229 if Full_Expander_Active then
5230 B_F := Build_Barrier_Function (N, Ent, Prot);
5231 Func := Barrier_Function (Ent);
5232 Set_Corresponding_Spec (B_F, Func);
5234 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5236 if Nkind (Parent (Body_Decl)) = N_Subunit then
5237 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5240 Insert_Before_And_Analyze (Body_Decl, B_F);
5242 Set_Discriminals (Spec_Decl);
5243 Set_Scope (Func, Scope (Prot));
5246 Analyze_And_Resolve (Cond, Any_Boolean);
5249 -- The Ravenscar profile restricts barriers to simple variables declared
5250 -- within the protected object. We also allow Boolean constants, since
5251 -- these appear in several published examples and are also allowed by
5252 -- the Aonix compiler.
5254 -- Note that after analysis variables in this context will be replaced
5255 -- by the corresponding prival, that is to say a renaming of a selected
5256 -- component of the form _Object.Var. If expansion is disabled, as
5257 -- within a generic, we check that the entity appears in the current
5260 if Is_Entity_Name (Cond) then
5262 -- A small optimization of useless renamings. If the scope of the
5263 -- entity of the condition is not the barrier function, then the
5264 -- condition does not reference any of the generated renamings
5265 -- within the function.
5267 if Full_Expander_Active
5268 and then Scope (Entity (Cond)) /= Func
5270 Set_Declarations (B_F, Empty_List);
5273 if Entity (Cond) = Standard_False
5275 Entity (Cond) = Standard_True
5279 elsif not Expander_Active
5280 and then Scope (Entity (Cond)) = Current_Scope
5284 -- Check for case of _object.all.field (note that the explicit
5285 -- dereference gets inserted by analyze/expand of _object.field)
5287 elsif Present (Renamed_Object (Entity (Cond)))
5289 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5293 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5299 -- It is not a boolean variable or literal, so check the restriction
5301 Check_Restriction (Simple_Barriers, Cond);
5302 end Expand_Entry_Barrier;
5304 ------------------------------
5305 -- Expand_N_Abort_Statement --
5306 ------------------------------
5308 -- Expand abort T1, T2, .. Tn; into:
5309 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5311 procedure Expand_N_Abort_Statement (N : Node_Id) is
5312 Loc : constant Source_Ptr := Sloc (N);
5313 Tlist : constant List_Id := Names (N);
5319 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5322 Tasknm := First (Tlist);
5324 while Present (Tasknm) loop
5327 -- A task interface class-wide type object is being aborted.
5328 -- Retrieve its _task_id by calling a dispatching routine.
5330 if Ada_Version >= Ada_2005
5331 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5332 and then Is_Interface (Etype (Tasknm))
5333 and then Is_Task_Interface (Etype (Tasknm))
5335 Append_To (Component_Associations (Aggr),
5336 Make_Component_Association (Loc,
5337 Choices => New_List (
5338 Make_Integer_Literal (Loc, Count)),
5341 -- Task_Id (Tasknm._disp_get_task_id)
5343 Make_Unchecked_Type_Conversion (Loc,
5345 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5347 Make_Selected_Component (Loc,
5348 Prefix => New_Copy_Tree (Tasknm),
5350 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5353 Append_To (Component_Associations (Aggr),
5354 Make_Component_Association (Loc,
5355 Choices => New_List (
5356 Make_Integer_Literal (Loc, Count)),
5357 Expression => Concurrent_Ref (Tasknm)));
5364 Make_Procedure_Call_Statement (Loc,
5365 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5366 Parameter_Associations => New_List (
5367 Make_Qualified_Expression (Loc,
5368 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5369 Expression => Aggr))));
5372 end Expand_N_Abort_Statement;
5374 -------------------------------
5375 -- Expand_N_Accept_Statement --
5376 -------------------------------
5378 -- This procedure handles expansion of accept statements that stand
5379 -- alone, i.e. they are not part of an accept alternative. The expansion
5380 -- of accept statement in accept alternatives is handled by the routines
5381 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5382 -- following description applies only to stand alone accept statements.
5384 -- If there is no handled statement sequence, or only null statements,
5385 -- then this is called a trivial accept, and the expansion is:
5387 -- Accept_Trivial (entry-index)
5389 -- If there is a handled statement sequence, then the expansion is:
5396 -- Accept_Call (entry-index, Ann);
5397 -- Renaming_Declarations for formals
5398 -- <statement sequence from N_Accept_Statement node>
5399 -- Complete_Rendezvous;
5404 -- <exception handler from N_Accept_Statement node>
5405 -- Complete_Rendezvous;
5407 -- <exception handler from N_Accept_Statement node>
5408 -- Complete_Rendezvous;
5413 -- when all others =>
5414 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5417 -- The first three declarations were already inserted ahead of the accept
5418 -- statement by the Expand_Accept_Declarations procedure, which was called
5419 -- directly from the semantics during analysis of the accept statement,
5420 -- before analyzing its contained statements.
5422 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5423 -- from possible expansion activity (the original source of course does
5424 -- not have any declarations associated with the accept statement, since
5425 -- an accept statement has no declarative part). In particular, if the
5426 -- expander is active, the first such declaration is the declaration of
5427 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5429 -- The two blocks are merged into a single block if the inner block has
5430 -- no exception handlers, but otherwise two blocks are required, since
5431 -- exceptions might be raised in the exception handlers of the inner
5432 -- block, and Exceptional_Complete_Rendezvous must be called.
5434 procedure Expand_N_Accept_Statement (N : Node_Id) is
5435 Loc : constant Source_Ptr := Sloc (N);
5436 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5437 Ename : constant Node_Id := Entry_Direct_Name (N);
5438 Eindx : constant Node_Id := Entry_Index (N);
5439 Eent : constant Entity_Id := Entity (Ename);
5440 Acstack : constant Elist_Id := Accept_Address (Eent);
5441 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5442 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5447 -- Start of processing for Expand_N_Accept_Statement
5450 -- If accept statement is not part of a list, then its parent must be
5451 -- an accept alternative, and, as described above, we do not do any
5452 -- expansion for such accept statements at this level.
5454 if not Is_List_Member (N) then
5455 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5458 -- Trivial accept case (no statement sequence, or null statements).
5459 -- If the accept statement has declarations, then just insert them
5460 -- before the procedure call.
5462 elsif Trivial_Accept_OK
5463 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5465 -- Remove declarations for renamings, because the parameter block
5466 -- will not be assigned.
5473 D := First (Declarations (N));
5475 while Present (D) loop
5477 if Nkind (D) = N_Object_Renaming_Declaration then
5485 if Present (Declarations (N)) then
5486 Insert_Actions (N, Declarations (N));
5490 Make_Procedure_Call_Statement (Loc,
5491 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5492 Parameter_Associations => New_List (
5493 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5497 -- Discard Entry_Address that was created for it, so it will not be
5498 -- emitted if this accept statement is in the statement part of a
5499 -- delay alternative.
5501 if Present (Stats) then
5502 Remove_Last_Elmt (Acstack);
5505 -- Case of statement sequence present
5508 -- Construct the block, using the declarations from the accept
5509 -- statement if any to initialize the declarations of the block.
5511 Blkent := Make_Temporary (Loc, 'A');
5512 Set_Ekind (Blkent, E_Block);
5513 Set_Etype (Blkent, Standard_Void_Type);
5514 Set_Scope (Blkent, Current_Scope);
5517 Make_Block_Statement (Loc,
5518 Identifier => New_Reference_To (Blkent, Loc),
5519 Declarations => Declarations (N),
5520 Handled_Statement_Sequence => Build_Accept_Body (N));
5522 -- For the analysis of the generated declarations, the parent node
5523 -- must be properly set.
5525 Set_Parent (Block, Parent (N));
5527 -- Prepend call to Accept_Call to main statement sequence If the
5528 -- accept has exception handlers, the statement sequence is wrapped
5529 -- in a block. Insert call and renaming declarations in the
5530 -- declarations of the block, so they are elaborated before the
5534 Make_Procedure_Call_Statement (Loc,
5535 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5536 Parameter_Associations => New_List (
5537 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5538 New_Reference_To (Ann, Loc)));
5540 if Parent (Stats) = N then
5541 Prepend (Call, Statements (Stats));
5550 Push_Scope (Blkent);
5558 D := First (Declarations (N));
5559 while Present (D) loop
5562 if Nkind (D) = N_Object_Renaming_Declaration then
5564 -- The renaming declarations for the formals were created
5565 -- during analysis of the accept statement, and attached to
5566 -- the list of declarations. Place them now in the context
5567 -- of the accept block or subprogram.
5570 Typ := Entity (Subtype_Mark (D));
5571 Insert_After (Call, D);
5574 -- If the formal is class_wide, it does not have an actual
5575 -- subtype. The analysis of the renaming declaration creates
5576 -- one, but we need to retain the class-wide nature of the
5579 if Is_Class_Wide_Type (Typ) then
5580 Set_Etype (Defining_Identifier (D), Typ);
5591 -- Replace the accept statement by the new block
5596 -- Last step is to unstack the Accept_Address value
5598 Remove_Last_Elmt (Acstack);
5600 end Expand_N_Accept_Statement;
5602 ----------------------------------
5603 -- Expand_N_Asynchronous_Select --
5604 ----------------------------------
5606 -- This procedure assumes that the trigger statement is an entry call or
5607 -- a dispatching procedure call. A delay alternative should already have
5608 -- been expanded into an entry call to the appropriate delay object Wait
5611 -- If the trigger is a task entry call, the select is implemented with
5612 -- a Task_Entry_Call:
5617 -- P : parms := (parm, parm, parm);
5619 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5621 -- procedure _clean is
5624 -- Cancel_Task_Entry_Call (C);
5631 -- (<acceptor-task>, -- Acceptor
5632 -- <entry-index>, -- E
5633 -- P'Address, -- Uninterpreted_Data
5634 -- Asynchronous_Call, -- Mode
5635 -- B); -- Rendezvous_Successful
5642 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5645 -- when Abort_Signal => Abort_Undefer;
5652 -- <triggered-statements>
5656 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5657 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5661 -- P : parms := (parm, parm, parm);
5663 -- Call_Simple (acceptor-task, entry-index, P'Address);
5669 -- so the task at hand is to convert the latter expansion into the former
5671 -- If the trigger is a protected entry call, the select is implemented
5672 -- with Protected_Entry_Call:
5675 -- P : E1_Params := (param, param, param);
5676 -- Bnn : Communications_Block;
5681 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5683 -- procedure _clean is
5686 -- if Enqueued (Bnn) then
5687 -- Cancel_Protected_Entry_Call (Bnn);
5694 -- Protected_Entry_Call
5695 -- (po._object'Access, -- Object
5696 -- <entry index>, -- E
5697 -- P'Address, -- Uninterpreted_Data
5698 -- Asynchronous_Call, -- Mode
5701 -- if Enqueued (Bnn) then
5705 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5708 -- when Abort_Signal => Abort_Undefer;
5711 -- if not Cancelled (Bnn) then
5712 -- <triggered-statements>
5716 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5720 -- P : E1_Params := (param, param, param);
5721 -- Bnn : Communications_Block;
5724 -- Protected_Entry_Call
5725 -- (po._object'Access, -- Object
5726 -- <entry index>, -- E
5727 -- P'Address, -- Uninterpreted_Data
5728 -- Simple_Call, -- Mode
5735 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5739 -- B : Boolean := False;
5740 -- Bnn : Communication_Block;
5741 -- C : Ada.Tags.Prim_Op_Kind;
5742 -- D : System.Storage_Elements.Dummy_Communication_Block;
5743 -- K : Ada.Tags.Tagged_Kind :=
5744 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5745 -- P : Parameters := (Param1 .. ParamN);
5750 -- if K = Ada.Tags.TK_Limited_Tagged then
5751 -- <dispatching-call>;
5752 -- <triggering-statements>;
5756 -- Ada.Tags.Get_Offset_Index
5757 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5759 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5761 -- if C = POK_Protected_Entry then
5763 -- procedure _clean is
5765 -- if Enqueued (Bnn) then
5766 -- Cancel_Protected_Entry_Call (Bnn);
5772 -- _Disp_Asynchronous_Select
5773 -- (<object>, S, P'Address, D, B);
5774 -- Bnn := Communication_Block (D);
5776 -- Param1 := P.Param1;
5778 -- ParamN := P.ParamN;
5780 -- if Enqueued (Bnn) then
5781 -- <abortable-statements>
5784 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5787 -- when Abort_Signal => Abort_Undefer;
5790 -- if not Cancelled (Bnn) then
5791 -- <triggering-statements>
5794 -- elsif C = POK_Task_Entry then
5796 -- procedure _clean is
5798 -- Cancel_Task_Entry_Call (U);
5804 -- _Disp_Asynchronous_Select
5805 -- (<object>, S, P'Address, D, B);
5806 -- Bnn := Communication_Bloc (D);
5808 -- Param1 := P.Param1;
5810 -- ParamN := P.ParamN;
5815 -- <abortable-statements>
5817 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5820 -- when Abort_Signal => Abort_Undefer;
5824 -- <triggering-statements>
5829 -- <dispatching-call>;
5830 -- <triggering-statements>
5835 -- The job is to convert this to the asynchronous form
5837 -- If the trigger is a delay statement, it will have been expanded into a
5838 -- call to one of the GNARL delay procedures. This routine will convert
5839 -- this into a protected entry call on a delay object and then continue
5840 -- processing as for a protected entry call trigger. This requires
5841 -- declaring a Delay_Block object and adding a pointer to this object to
5842 -- the parameter list of the delay procedure to form the parameter list of
5843 -- the entry call. This object is used by the runtime to queue the delay
5846 -- For a description of the use of P and the assignments after the call,
5847 -- see Expand_N_Entry_Call_Statement.
5849 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5850 Loc : constant Source_Ptr := Sloc (N);
5851 Abrt : constant Node_Id := Abortable_Part (N);
5852 Astats : constant List_Id := Statements (Abrt);
5853 Trig : constant Node_Id := Triggering_Alternative (N);
5854 Tstats : constant List_Id := Statements (Trig);
5856 Abort_Block_Ent : Entity_Id;
5857 Abortable_Block : Node_Id;
5859 Blk_Ent : Entity_Id;
5860 Blk_Typ : Entity_Id;
5862 Call_Ent : Entity_Id;
5863 Cancel_Param : Entity_Id;
5864 Cleanup_Block : Node_Id;
5865 Cleanup_Block_Ent : Entity_Id;
5866 Cleanup_Stmts : List_Id;
5867 Conc_Typ_Stmts : List_Id;
5869 Dblock_Ent : Entity_Id;
5874 Enqueue_Call : Node_Id;
5877 Handler_Stmt : Node_Id;
5879 Lim_Typ_Stmts : List_Id;
5885 ProtE_Stmts : List_Id;
5886 ProtP_Stmts : List_Id;
5889 TaskE_Stmts : List_Id;
5891 B : Entity_Id; -- Call status flag
5892 Bnn : Entity_Id; -- Communication block
5893 C : Entity_Id; -- Call kind
5894 K : Entity_Id; -- Tagged kind
5895 P : Entity_Id; -- Parameter block
5896 S : Entity_Id; -- Primitive operation slot
5897 T : Entity_Id; -- Additional status flag
5900 Process_Statements_For_Controlled_Objects (Trig);
5901 Process_Statements_For_Controlled_Objects (Abrt);
5903 Blk_Ent := Make_Temporary (Loc, 'A');
5904 Ecall := Triggering_Statement (Trig);
5906 -- The arguments in the call may require dynamic allocation, and the
5907 -- call statement may have been transformed into a block. The block
5908 -- may contain additional declarations for internal entities, and the
5909 -- original call is found by sequential search.
5911 if Nkind (Ecall) = N_Block_Statement then
5912 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5913 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5914 N_Entry_Call_Statement)
5920 -- This is either a dispatching call or a delay statement used as a
5921 -- trigger which was expanded into a procedure call.
5923 if Nkind (Ecall) = N_Procedure_Call_Statement then
5924 if Ada_Version >= Ada_2005
5926 (No (Original_Node (Ecall))
5927 or else not Nkind_In (Original_Node (Ecall),
5928 N_Delay_Relative_Statement,
5929 N_Delay_Until_Statement))
5931 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5936 -- Call status flag processing, generate:
5937 -- B : Boolean := False;
5939 B := Build_B (Loc, Decls);
5941 -- Communication block processing, generate:
5942 -- Bnn : Communication_Block;
5944 Bnn := Make_Temporary (Loc, 'B');
5946 Make_Object_Declaration (Loc,
5947 Defining_Identifier => Bnn,
5948 Object_Definition =>
5949 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5951 -- Call kind processing, generate:
5952 -- C : Ada.Tags.Prim_Op_Kind;
5954 C := Build_C (Loc, Decls);
5956 -- Tagged kind processing, generate:
5957 -- K : Ada.Tags.Tagged_Kind :=
5958 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5960 -- Dummy communication block, generate:
5961 -- D : Dummy_Communication_Block;
5964 Make_Object_Declaration (Loc,
5965 Defining_Identifier =>
5966 Make_Defining_Identifier (Loc, Name_uD),
5967 Object_Definition =>
5969 RTE (RE_Dummy_Communication_Block), Loc)));
5971 K := Build_K (Loc, Decls, Obj);
5973 -- Parameter block processing
5975 Blk_Typ := Build_Parameter_Block
5976 (Loc, Actuals, Formals, Decls);
5977 P := Parameter_Block_Pack
5978 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5980 -- Dispatch table slot processing, generate:
5983 S := Build_S (Loc, Decls);
5985 -- Additional status flag processing, generate:
5988 T := Make_Temporary (Loc, 'T');
5990 Make_Object_Declaration (Loc,
5991 Defining_Identifier => T,
5992 Object_Definition =>
5993 New_Reference_To (Standard_Boolean, Loc)));
5995 ------------------------------
5996 -- Protected entry handling --
5997 ------------------------------
6000 -- Param1 := P.Param1;
6002 -- ParamN := P.ParamN;
6004 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6007 -- Bnn := Communication_Block (D);
6009 Prepend_To (Cleanup_Stmts,
6010 Make_Assignment_Statement (Loc,
6012 New_Reference_To (Bnn, Loc),
6014 Make_Unchecked_Type_Conversion (Loc,
6016 New_Reference_To (RTE (RE_Communication_Block), Loc),
6017 Expression => Make_Identifier (Loc, Name_uD))));
6020 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6022 Prepend_To (Cleanup_Stmts,
6023 Make_Procedure_Call_Statement (Loc,
6026 Find_Prim_Op (Etype (Etype (Obj)),
6027 Name_uDisp_Asynchronous_Select),
6029 Parameter_Associations =>
6031 New_Copy_Tree (Obj), -- <object>
6032 New_Reference_To (S, Loc), -- S
6033 Make_Attribute_Reference (Loc, -- P'Address
6035 New_Reference_To (P, Loc),
6038 Make_Identifier (Loc, Name_uD), -- D
6039 New_Reference_To (B, Loc)))); -- B
6042 -- if Enqueued (Bnn) then
6043 -- <abortable-statements>
6046 Append_To (Cleanup_Stmts,
6047 Make_If_Statement (Loc,
6049 Make_Function_Call (Loc,
6051 New_Reference_To (RTE (RE_Enqueued), Loc),
6052 Parameter_Associations =>
6054 New_Reference_To (Bnn, Loc))),
6057 New_Copy_List_Tree (Astats)));
6059 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6060 -- will then generate a _clean for the communication block Bnn.
6064 -- procedure _clean is
6066 -- if Enqueued (Bnn) then
6067 -- Cancel_Protected_Entry_Call (Bnn);
6076 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6078 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6080 -- Wrap the cleanup block in an exception handling block
6086 -- when Abort_Signal => Abort_Undefer;
6089 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6092 Make_Implicit_Label_Declaration (Loc,
6093 Defining_Identifier =>
6097 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6100 -- if not Cancelled (Bnn) then
6101 -- <triggering-statements>
6104 Append_To (ProtE_Stmts,
6105 Make_If_Statement (Loc,
6109 Make_Function_Call (Loc,
6111 New_Reference_To (RTE (RE_Cancelled), Loc),
6112 Parameter_Associations =>
6114 New_Reference_To (Bnn, Loc)))),
6117 New_Copy_List_Tree (Tstats)));
6119 -------------------------
6120 -- Task entry handling --
6121 -------------------------
6124 -- Param1 := P.Param1;
6126 -- ParamN := P.ParamN;
6128 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6131 -- Bnn := Communication_Block (D);
6133 Append_To (TaskE_Stmts,
6134 Make_Assignment_Statement (Loc,
6136 New_Reference_To (Bnn, Loc),
6138 Make_Unchecked_Type_Conversion (Loc,
6140 New_Reference_To (RTE (RE_Communication_Block), Loc),
6141 Expression => Make_Identifier (Loc, Name_uD))));
6144 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6146 Prepend_To (TaskE_Stmts,
6147 Make_Procedure_Call_Statement (Loc,
6150 Find_Prim_Op (Etype (Etype (Obj)),
6151 Name_uDisp_Asynchronous_Select),
6153 Parameter_Associations =>
6155 New_Copy_Tree (Obj), -- <object>
6156 New_Reference_To (S, Loc), -- S
6157 Make_Attribute_Reference (Loc, -- P'Address
6159 New_Reference_To (P, Loc),
6162 Make_Identifier (Loc, Name_uD), -- D
6163 New_Reference_To (B, Loc)))); -- B
6168 Prepend_To (TaskE_Stmts,
6169 Make_Procedure_Call_Statement (Loc,
6171 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6172 Parameter_Associations =>
6177 -- <abortable-statements>
6179 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6181 Prepend_To (Cleanup_Stmts,
6182 Make_Procedure_Call_Statement (Loc,
6184 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6185 Parameter_Associations =>
6188 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6189 -- will generate a _clean for the additional status flag.
6193 -- procedure _clean is
6195 -- Cancel_Task_Entry_Call (U);
6203 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6205 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6207 -- Wrap the cleanup block in an exception handling block
6213 -- when Abort_Signal => Abort_Undefer;
6216 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6218 Append_To (TaskE_Stmts,
6219 Make_Implicit_Label_Declaration (Loc,
6220 Defining_Identifier => Abort_Block_Ent));
6222 Append_To (TaskE_Stmts,
6224 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6228 -- <triggering-statements>
6231 Append_To (TaskE_Stmts,
6232 Make_If_Statement (Loc,
6236 New_Reference_To (T, Loc)),
6239 New_Copy_List_Tree (Tstats)));
6241 ----------------------------------
6242 -- Protected procedure handling --
6243 ----------------------------------
6246 -- <dispatching-call>;
6247 -- <triggering-statements>
6249 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6250 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6253 -- S := Ada.Tags.Get_Offset_Index
6254 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6257 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6260 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6262 Append_To (Conc_Typ_Stmts,
6263 Make_Procedure_Call_Statement (Loc,
6266 Find_Prim_Op (Etype (Etype (Obj)),
6267 Name_uDisp_Get_Prim_Op_Kind),
6269 Parameter_Associations =>
6271 New_Copy_Tree (Obj),
6272 New_Reference_To (S, Loc),
6273 New_Reference_To (C, Loc))));
6276 -- if C = POK_Procedure_Entry then
6278 -- elsif C = POK_Task_Entry then
6284 Append_To (Conc_Typ_Stmts,
6285 Make_If_Statement (Loc,
6289 New_Reference_To (C, Loc),
6291 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6298 Make_Elsif_Part (Loc,
6302 New_Reference_To (C, Loc),
6304 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6313 -- <dispatching-call>;
6314 -- <triggering-statements>
6316 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6317 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6320 -- if K = Ada.Tags.TK_Limited_Tagged then
6327 Make_If_Statement (Loc,
6331 New_Reference_To (K, Loc),
6333 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6342 Make_Block_Statement (Loc,
6345 Handled_Statement_Sequence =>
6346 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6351 -- Delay triggering statement processing
6354 -- Add a Delay_Block object to the parameter list of the delay
6355 -- procedure to form the parameter list of the Wait entry call.
6357 Dblock_Ent := Make_Temporary (Loc, 'D');
6359 Pdef := Entity (Name (Ecall));
6361 if Is_RTE (Pdef, RO_CA_Delay_For) then
6363 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6365 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6367 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6369 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6370 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6373 Append_To (Parameter_Associations (Ecall),
6374 Make_Attribute_Reference (Loc,
6375 Prefix => New_Reference_To (Dblock_Ent, Loc),
6376 Attribute_Name => Name_Unchecked_Access));
6378 -- Create the inner block to protect the abortable part
6380 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6383 Make_Procedure_Call_Statement (Loc,
6384 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6387 Make_Block_Statement (Loc,
6388 Identifier => New_Reference_To (Blk_Ent, Loc),
6389 Handled_Statement_Sequence =>
6390 Make_Handled_Sequence_Of_Statements (Loc,
6391 Statements => Astats),
6392 Has_Created_Identifier => True,
6393 Is_Asynchronous_Call_Block => True);
6395 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6398 Make_Implicit_If_Statement (N,
6399 Condition => Make_Function_Call (Loc,
6400 Name => Enqueue_Call,
6401 Parameter_Associations => Parameter_Associations (Ecall)),
6403 New_List (Make_Block_Statement (Loc,
6404 Handled_Statement_Sequence =>
6405 Make_Handled_Sequence_Of_Statements (Loc,
6406 Statements => New_List (
6407 Make_Implicit_Label_Declaration (Loc,
6408 Defining_Identifier => Blk_Ent,
6409 Label_Construct => Abortable_Block),
6411 Exception_Handlers => Hdle)))));
6413 Stmts := New_List (Ecall);
6415 -- Construct statement sequence for new block
6418 Make_Implicit_If_Statement (N,
6419 Condition => Make_Function_Call (Loc,
6420 Name => New_Reference_To (
6421 RTE (RE_Timed_Out), Loc),
6422 Parameter_Associations => New_List (
6423 Make_Attribute_Reference (Loc,
6424 Prefix => New_Reference_To (Dblock_Ent, Loc),
6425 Attribute_Name => Name_Unchecked_Access))),
6426 Then_Statements => Tstats));
6428 -- The result is the new block
6430 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6433 Make_Block_Statement (Loc,
6434 Declarations => New_List (
6435 Make_Object_Declaration (Loc,
6436 Defining_Identifier => Dblock_Ent,
6437 Aliased_Present => True,
6438 Object_Definition => New_Reference_To (
6439 RTE (RE_Delay_Block), Loc))),
6441 Handled_Statement_Sequence =>
6442 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6452 Extract_Entry (Ecall, Concval, Ename, Index);
6453 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6455 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6456 Decls := Declarations (Ecall);
6458 if Is_Protected_Type (Etype (Concval)) then
6460 -- Get the declarations of the block expanded from the entry call
6462 Decl := First (Decls);
6463 while Present (Decl)
6465 (Nkind (Decl) /= N_Object_Declaration
6466 or else not Is_RTE (Etype (Object_Definition (Decl)),
6467 RE_Communication_Block))
6472 pragma Assert (Present (Decl));
6473 Cancel_Param := Defining_Identifier (Decl);
6475 -- Change the mode of the Protected_Entry_Call call
6477 -- Protected_Entry_Call (
6478 -- Object => po._object'Access,
6479 -- E => <entry index>;
6480 -- Uninterpreted_Data => P'Address;
6481 -- Mode => Asynchronous_Call;
6484 Stmt := First (Stmts);
6486 -- Skip assignments to temporaries created for in-out parameters
6488 -- This makes unwarranted assumptions about the shape of the expanded
6489 -- tree for the call, and should be cleaned up ???
6491 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6497 Param := First (Parameter_Associations (Call));
6498 while Present (Param)
6499 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6504 pragma Assert (Present (Param));
6505 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6508 -- Append an if statement to execute the abortable part
6511 -- if Enqueued (Bnn) then
6514 Make_Implicit_If_Statement (N,
6515 Condition => Make_Function_Call (Loc,
6516 Name => New_Reference_To (RTE (RE_Enqueued), Loc),
6517 Parameter_Associations => New_List (
6518 New_Reference_To (Cancel_Param, Loc))),
6519 Then_Statements => Astats));
6522 Make_Block_Statement (Loc,
6523 Identifier => New_Reference_To (Blk_Ent, Loc),
6524 Handled_Statement_Sequence =>
6525 Make_Handled_Sequence_Of_Statements (Loc,
6526 Statements => Stmts),
6527 Has_Created_Identifier => True,
6528 Is_Asynchronous_Call_Block => True);
6530 -- For the VM call Update_Exception instead of Abort_Undefer.
6531 -- See 4jexcept.ads for an explanation.
6533 if VM_Target = No_VM then
6534 if Exception_Mechanism = Back_End_Exceptions then
6536 -- Aborts are not deferred at beginning of exception handlers
6539 Handler_Stmt := Make_Null_Statement (Loc);
6542 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6543 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6544 Parameter_Associations => No_List);
6547 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
6548 Name => New_Reference_To (RTE (RE_Update_Exception), Loc),
6549 Parameter_Associations => New_List (
6550 Make_Function_Call (Loc,
6551 Name => New_Occurrence_Of
6552 (RTE (RE_Current_Target_Exception), Loc))));
6556 Make_Block_Statement (Loc,
6557 Handled_Statement_Sequence =>
6558 Make_Handled_Sequence_Of_Statements (Loc,
6559 Statements => New_List (
6560 Make_Implicit_Label_Declaration (Loc,
6561 Defining_Identifier => Blk_Ent,
6562 Label_Construct => Abortable_Block),
6567 Exception_Handlers => New_List (
6568 Make_Implicit_Exception_Handler (Loc,
6570 -- when Abort_Signal =>
6571 -- Abort_Undefer.all;
6573 Exception_Choices =>
6574 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6575 Statements => New_List (Handler_Stmt))))),
6577 -- if not Cancelled (Bnn) then
6578 -- triggered statements
6581 Make_Implicit_If_Statement (N,
6582 Condition => Make_Op_Not (Loc,
6584 Make_Function_Call (Loc,
6585 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6586 Parameter_Associations => New_List (
6587 New_Occurrence_Of (Cancel_Param, Loc)))),
6588 Then_Statements => Tstats));
6590 -- Asynchronous task entry call
6597 B := Make_Defining_Identifier (Loc, Name_uB);
6599 -- Insert declaration of B in declarations of existing block
6602 Make_Object_Declaration (Loc,
6603 Defining_Identifier => B,
6604 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6606 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6608 -- Insert declaration of C in declarations of existing block
6611 Make_Object_Declaration (Loc,
6612 Defining_Identifier => Cancel_Param,
6613 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6615 -- Remove and save the call to Call_Simple
6617 Stmt := First (Stmts);
6619 -- Skip assignments to temporaries created for in-out parameters.
6620 -- This makes unwarranted assumptions about the shape of the expanded
6621 -- tree for the call, and should be cleaned up ???
6623 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6629 -- Create the inner block to protect the abortable part
6631 Hdle := New_List (Build_Abort_Block_Handler (Loc));
6634 Make_Procedure_Call_Statement (Loc,
6635 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6638 Make_Block_Statement (Loc,
6639 Identifier => New_Reference_To (Blk_Ent, Loc),
6640 Handled_Statement_Sequence =>
6641 Make_Handled_Sequence_Of_Statements (Loc,
6642 Statements => Astats),
6643 Has_Created_Identifier => True,
6644 Is_Asynchronous_Call_Block => True);
6647 Make_Block_Statement (Loc,
6648 Handled_Statement_Sequence =>
6649 Make_Handled_Sequence_Of_Statements (Loc,
6650 Statements => New_List (
6651 Make_Implicit_Label_Declaration (Loc,
6652 Defining_Identifier =>
6657 Exception_Handlers => Hdle)));
6659 -- Create new call statement
6661 Params := Parameter_Associations (Call);
6664 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6666 New_Reference_To (B, Loc));
6669 Make_Procedure_Call_Statement (Loc,
6671 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6672 Parameter_Associations => Params));
6674 -- Construct statement sequence for new block
6677 Make_Implicit_If_Statement (N,
6680 New_Reference_To (Cancel_Param, Loc)),
6681 Then_Statements => Tstats));
6683 -- Protected the call against abort
6686 Make_Procedure_Call_Statement (Loc,
6687 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6688 Parameter_Associations => Empty_List));
6691 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6693 -- The result is the new block
6696 Make_Block_Statement (Loc,
6697 Declarations => Decls,
6698 Handled_Statement_Sequence =>
6699 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6702 end Expand_N_Asynchronous_Select;
6704 -------------------------------------
6705 -- Expand_N_Conditional_Entry_Call --
6706 -------------------------------------
6708 -- The conditional task entry call is converted to a call to
6713 -- P : parms := (parm, parm, parm);
6717 -- (<acceptor-task>, -- Acceptor
6718 -- <entry-index>, -- E
6719 -- P'Address, -- Uninterpreted_Data
6720 -- Conditional_Call, -- Mode
6721 -- B); -- Rendezvous_Successful
6726 -- normal-statements
6732 -- For a description of the use of P and the assignments after the call,
6733 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6734 -- conditional entry call has already been expanded (by the Expand_N_Entry
6735 -- _Call_Statement procedure) as follows:
6738 -- P : parms := (parm, parm, parm);
6740 -- ... info for in-out parameters
6741 -- Call_Simple (acceptor-task, entry-index, P'Address);
6747 -- so the task at hand is to convert the latter expansion into the former
6749 -- The conditional protected entry call is converted to a call to
6750 -- Protected_Entry_Call:
6753 -- P : parms := (parm, parm, parm);
6754 -- Bnn : Communications_Block;
6757 -- Protected_Entry_Call
6758 -- (po._object'Access, -- Object
6759 -- <entry index>, -- E
6760 -- P'Address, -- Uninterpreted_Data
6761 -- Conditional_Call, -- Mode
6766 -- if Cancelled (Bnn) then
6769 -- normal-statements
6773 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6777 -- B : Boolean := False;
6778 -- C : Ada.Tags.Prim_Op_Kind;
6779 -- K : Ada.Tags.Tagged_Kind :=
6780 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6781 -- P : Parameters := (Param1 .. ParamN);
6785 -- if K = Ada.Tags.TK_Limited_Tagged then
6786 -- <dispatching-call>;
6787 -- <triggering-statements>
6791 -- Ada.Tags.Get_Offset_Index
6792 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6794 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6796 -- if C = POK_Protected_Entry
6797 -- or else C = POK_Task_Entry
6799 -- Param1 := P.Param1;
6801 -- ParamN := P.ParamN;
6805 -- if C = POK_Procedure
6806 -- or else C = POK_Protected_Procedure
6807 -- or else C = POK_Task_Procedure
6809 -- <dispatching-call>;
6812 -- <triggering-statements>
6814 -- <else-statements>
6819 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6820 Loc : constant Source_Ptr := Sloc (N);
6821 Alt : constant Node_Id := Entry_Call_Alternative (N);
6822 Blk : Node_Id := Entry_Call_Statement (Alt);
6825 Blk_Typ : Entity_Id;
6827 Call_Ent : Entity_Id;
6828 Conc_Typ_Stmts : List_Id;
6832 Lim_Typ_Stmts : List_Id;
6839 Transient_Blk : Node_Id;
6842 B : Entity_Id; -- Call status flag
6843 C : Entity_Id; -- Call kind
6844 K : Entity_Id; -- Tagged kind
6845 P : Entity_Id; -- Parameter block
6846 S : Entity_Id; -- Primitive operation slot
6849 Process_Statements_For_Controlled_Objects (N);
6851 if Ada_Version >= Ada_2005
6852 and then Nkind (Blk) = N_Procedure_Call_Statement
6854 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6859 -- Call status flag processing, generate:
6860 -- B : Boolean := False;
6862 B := Build_B (Loc, Decls);
6864 -- Call kind processing, generate:
6865 -- C : Ada.Tags.Prim_Op_Kind;
6867 C := Build_C (Loc, Decls);
6869 -- Tagged kind processing, generate:
6870 -- K : Ada.Tags.Tagged_Kind :=
6871 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6873 K := Build_K (Loc, Decls, Obj);
6875 -- Parameter block processing
6877 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6878 P := Parameter_Block_Pack
6879 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6881 -- Dispatch table slot processing, generate:
6884 S := Build_S (Loc, Decls);
6887 -- S := Ada.Tags.Get_Offset_Index
6888 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6891 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6894 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6896 Append_To (Conc_Typ_Stmts,
6897 Make_Procedure_Call_Statement (Loc,
6900 Find_Prim_Op (Etype (Etype (Obj)),
6901 Name_uDisp_Conditional_Select),
6903 Parameter_Associations =>
6905 New_Copy_Tree (Obj), -- <object>
6906 New_Reference_To (S, Loc), -- S
6907 Make_Attribute_Reference (Loc, -- P'Address
6909 New_Reference_To (P, Loc),
6912 New_Reference_To (C, Loc), -- C
6913 New_Reference_To (B, Loc)))); -- B
6916 -- if C = POK_Protected_Entry
6917 -- or else C = POK_Task_Entry
6919 -- Param1 := P.Param1;
6921 -- ParamN := P.ParamN;
6924 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6926 -- Generate the if statement only when the packed parameters need
6927 -- explicit assignments to their corresponding actuals.
6929 if Present (Unpack) then
6930 Append_To (Conc_Typ_Stmts,
6931 Make_If_Statement (Loc,
6938 New_Reference_To (C, Loc),
6940 New_Reference_To (RTE (
6941 RE_POK_Protected_Entry), Loc)),
6945 New_Reference_To (C, Loc),
6947 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6955 -- if C = POK_Procedure
6956 -- or else C = POK_Protected_Procedure
6957 -- or else C = POK_Task_Procedure
6959 -- <dispatching-call>
6961 -- <normal-statements>
6963 -- <else-statements>
6966 N_Stats := New_Copy_List_Tree (Statements (Alt));
6968 Prepend_To (N_Stats,
6969 Make_If_Statement (Loc,
6975 New_Reference_To (C, Loc),
6977 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6984 New_Reference_To (C, Loc),
6986 New_Reference_To (RTE (
6987 RE_POK_Protected_Procedure), Loc)),
6992 New_Reference_To (C, Loc),
6994 New_Reference_To (RTE (
6995 RE_POK_Task_Procedure), Loc)))),
7000 Append_To (Conc_Typ_Stmts,
7001 Make_If_Statement (Loc,
7002 Condition => New_Reference_To (B, Loc),
7003 Then_Statements => N_Stats,
7004 Else_Statements => Else_Statements (N)));
7007 -- <dispatching-call>;
7008 -- <triggering-statements>
7010 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
7011 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
7014 -- if K = Ada.Tags.TK_Limited_Tagged then
7021 Make_If_Statement (Loc,
7025 New_Reference_To (K, Loc),
7027 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
7036 Make_Block_Statement (Loc,
7039 Handled_Statement_Sequence =>
7040 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7042 -- As described above, The entry alternative is transformed into a
7043 -- block that contains the gnulli call, and possibly assignment
7044 -- statements for in-out parameters. The gnulli call may itself be
7045 -- rewritten into a transient block if some unconstrained parameters
7046 -- require it. We need to retrieve the call to complete its parameter
7051 First_Real_Statement (Handled_Statement_Sequence (Blk));
7053 if Present (Transient_Blk)
7054 and then Nkind (Transient_Blk) = N_Block_Statement
7056 Blk := Transient_Blk;
7059 Stmts := Statements (Handled_Statement_Sequence (Blk));
7060 Stmt := First (Stmts);
7061 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7066 Params := Parameter_Associations (Call);
7068 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7070 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7072 Param := First (Params);
7073 while Present (Param)
7074 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7079 pragma Assert (Present (Param));
7080 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
7084 -- Find the Communication_Block parameter for the call to the
7085 -- Cancelled function.
7087 Decl := First (Declarations (Blk));
7088 while Present (Decl)
7089 and then not Is_RTE (Etype (Object_Definition (Decl)),
7090 RE_Communication_Block)
7095 -- Add an if statement to execute the else part if the call
7096 -- does not succeed (as indicated by the Cancelled predicate).
7099 Make_Implicit_If_Statement (N,
7100 Condition => Make_Function_Call (Loc,
7101 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
7102 Parameter_Associations => New_List (
7103 New_Reference_To (Defining_Identifier (Decl), Loc))),
7104 Then_Statements => Else_Statements (N),
7105 Else_Statements => Statements (Alt)));
7108 B := Make_Defining_Identifier (Loc, Name_uB);
7110 -- Insert declaration of B in declarations of existing block
7112 if No (Declarations (Blk)) then
7113 Set_Declarations (Blk, New_List);
7116 Prepend_To (Declarations (Blk),
7117 Make_Object_Declaration (Loc,
7118 Defining_Identifier => B,
7119 Object_Definition =>
7120 New_Reference_To (Standard_Boolean, Loc)));
7122 -- Create new call statement
7125 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7126 Append_To (Params, New_Reference_To (B, Loc));
7129 Make_Procedure_Call_Statement (Loc,
7130 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7131 Parameter_Associations => Params));
7133 -- Construct statement sequence for new block
7136 Make_Implicit_If_Statement (N,
7137 Condition => New_Reference_To (B, Loc),
7138 Then_Statements => Statements (Alt),
7139 Else_Statements => Else_Statements (N)));
7142 -- The result is the new block
7145 Make_Block_Statement (Loc,
7146 Declarations => Declarations (Blk),
7147 Handled_Statement_Sequence =>
7148 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7152 end Expand_N_Conditional_Entry_Call;
7154 ---------------------------------------
7155 -- Expand_N_Delay_Relative_Statement --
7156 ---------------------------------------
7158 -- Delay statement is implemented as a procedure call to Delay_For
7159 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7160 -- simple delays imposed by the use of Protected Objects.
7162 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7163 Loc : constant Source_Ptr := Sloc (N);
7166 Make_Procedure_Call_Statement (Loc,
7167 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7168 Parameter_Associations => New_List (Expression (N))));
7170 end Expand_N_Delay_Relative_Statement;
7172 ------------------------------------
7173 -- Expand_N_Delay_Until_Statement --
7174 ------------------------------------
7176 -- Delay Until statement is implemented as a procedure call to
7177 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7179 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7180 Loc : constant Source_Ptr := Sloc (N);
7184 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7185 Typ := RTE (RO_CA_Delay_Until);
7187 Typ := RTE (RO_RT_Delay_Until);
7191 Make_Procedure_Call_Statement (Loc,
7192 Name => New_Reference_To (Typ, Loc),
7193 Parameter_Associations => New_List (Expression (N))));
7196 end Expand_N_Delay_Until_Statement;
7198 -------------------------
7199 -- Expand_N_Entry_Body --
7200 -------------------------
7202 procedure Expand_N_Entry_Body (N : Node_Id) is
7204 -- Associate discriminals with the next protected operation body to be
7207 if Present (Next_Protected_Operation (N)) then
7208 Set_Discriminals (Parent (Current_Scope));
7210 end Expand_N_Entry_Body;
7212 -----------------------------------
7213 -- Expand_N_Entry_Call_Statement --
7214 -----------------------------------
7216 -- An entry call is expanded into GNARLI calls to implement a simple entry
7217 -- call (see Build_Simple_Entry_Call).
7219 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7225 if No_Run_Time_Mode then
7226 Error_Msg_CRT ("entry call", N);
7230 -- If this entry call is part of an asynchronous select, don't expand it
7231 -- here; it will be expanded with the select statement. Don't expand
7232 -- timed entry calls either, as they are translated into asynchronous
7235 -- ??? This whole approach is questionable; it may be better to go back
7236 -- to allowing the expansion to take place and then attempting to fix it
7237 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7238 -- whether the expanded call is on a task or protected entry.
7240 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7241 or else N /= Triggering_Statement (Parent (N)))
7242 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7243 or else N /= Entry_Call_Statement (Parent (N))
7244 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7246 Extract_Entry (N, Concval, Ename, Index);
7247 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7249 end Expand_N_Entry_Call_Statement;
7251 --------------------------------
7252 -- Expand_N_Entry_Declaration --
7253 --------------------------------
7255 -- If there are parameters, then first, each of the formals is marked by
7256 -- setting Is_Entry_Formal. Next a record type is built which is used to
7257 -- hold the parameter values. The name of this record type is entryP where
7258 -- entry is the name of the entry, with an additional corresponding access
7259 -- type called entryPA. The record type has matching components for each
7260 -- formal (the component names are the same as the formal names). For
7261 -- elementary types, the component type matches the formal type. For
7262 -- composite types, an access type is declared (with the name formalA)
7263 -- which designates the formal type, and the type of the component is this
7264 -- access type. Finally the Entry_Component of each formal is set to
7265 -- reference the corresponding record component.
7267 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7268 Loc : constant Source_Ptr := Sloc (N);
7269 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7270 Components : List_Id;
7273 Last_Decl : Node_Id;
7274 Component : Entity_Id;
7277 Rec_Ent : Entity_Id;
7278 Acc_Ent : Entity_Id;
7281 Formal := First_Formal (Entry_Ent);
7284 -- Most processing is done only if parameters are present
7286 if Present (Formal) then
7287 Components := New_List;
7289 -- Loop through formals
7291 while Present (Formal) loop
7292 Set_Is_Entry_Formal (Formal);
7294 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7295 Set_Entry_Component (Formal, Component);
7296 Set_Entry_Formal (Component, Formal);
7297 Ftype := Etype (Formal);
7299 -- Declare new access type and then append
7301 Ctype := Make_Temporary (Loc, 'A');
7304 Make_Full_Type_Declaration (Loc,
7305 Defining_Identifier => Ctype,
7307 Make_Access_To_Object_Definition (Loc,
7308 All_Present => True,
7309 Constant_Present => Ekind (Formal) = E_In_Parameter,
7310 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7312 Insert_After (Last_Decl, Decl);
7315 Append_To (Components,
7316 Make_Component_Declaration (Loc,
7317 Defining_Identifier => Component,
7318 Component_Definition =>
7319 Make_Component_Definition (Loc,
7320 Aliased_Present => False,
7321 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7323 Next_Formal_With_Extras (Formal);
7326 -- Create the Entry_Parameter_Record declaration
7328 Rec_Ent := Make_Temporary (Loc, 'P');
7331 Make_Full_Type_Declaration (Loc,
7332 Defining_Identifier => Rec_Ent,
7334 Make_Record_Definition (Loc,
7336 Make_Component_List (Loc,
7337 Component_Items => Components)));
7339 Insert_After (Last_Decl, Decl);
7342 -- Construct and link in the corresponding access type
7344 Acc_Ent := Make_Temporary (Loc, 'A');
7346 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7349 Make_Full_Type_Declaration (Loc,
7350 Defining_Identifier => Acc_Ent,
7352 Make_Access_To_Object_Definition (Loc,
7353 All_Present => True,
7354 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7356 Insert_After (Last_Decl, Decl);
7358 end Expand_N_Entry_Declaration;
7360 -----------------------------
7361 -- Expand_N_Protected_Body --
7362 -----------------------------
7364 -- Protected bodies are expanded to the completion of the subprograms
7365 -- created for the corresponding protected type. These are a protected and
7366 -- unprotected version of each protected subprogram in the object, a
7367 -- function to calculate each entry barrier, and a procedure to execute the
7368 -- sequence of statements of each protected entry body. For example, for
7369 -- protected type ptype:
7372 -- (O : System.Address;
7373 -- E : Protected_Entry_Index)
7376 -- <discriminant renamings>
7377 -- <private object renamings>
7379 -- return <barrier expression>;
7382 -- procedure pprocN (_object : in out poV;...) is
7383 -- <discriminant renamings>
7384 -- <private object renamings>
7386 -- <sequence of statements>
7389 -- procedure pprocP (_object : in out poV;...) is
7390 -- procedure _clean is
7393 -- ptypeS (_object, Pn);
7394 -- Unlock (_object._object'Access);
7395 -- Abort_Undefer.all;
7400 -- Lock (_object._object'Access);
7401 -- pprocN (_object;...);
7406 -- function pfuncN (_object : poV;...) return Return_Type is
7407 -- <discriminant renamings>
7408 -- <private object renamings>
7410 -- <sequence of statements>
7413 -- function pfuncP (_object : poV) return Return_Type is
7414 -- procedure _clean is
7416 -- Unlock (_object._object'Access);
7417 -- Abort_Undefer.all;
7422 -- Lock (_object._object'Access);
7423 -- return pfuncN (_object);
7430 -- (O : System.Address;
7431 -- P : System.Address;
7432 -- E : Protected_Entry_Index)
7434 -- <discriminant renamings>
7435 -- <private object renamings>
7436 -- type poVP is access poV;
7437 -- _Object : ptVP := ptVP!(O);
7441 -- <statement sequence>
7442 -- Complete_Entry_Body (_Object._Object);
7444 -- when all others =>
7445 -- Exceptional_Complete_Entry_Body (
7446 -- _Object._Object, Get_GNAT_Exception);
7450 -- The type poV is the record created for the protected type to hold
7451 -- the state of the protected object.
7453 procedure Expand_N_Protected_Body (N : Node_Id) is
7454 Loc : constant Source_Ptr := Sloc (N);
7455 Pid : constant Entity_Id := Corresponding_Spec (N);
7457 Current_Node : Node_Id;
7458 Disp_Op_Body : Node_Id;
7459 New_Op_Body : Node_Id;
7460 Num_Entries : Natural := 0;
7464 function Build_Dispatching_Subprogram_Body
7467 Prot_Bod : Node_Id) return Node_Id;
7468 -- Build a dispatching version of the protected subprogram body. The
7469 -- newly generated subprogram contains a call to the original protected
7470 -- body. The following code is generated:
7472 -- function <protected-function-name> (Param1 .. ParamN) return
7475 -- return <protected-function-name>P (Param1 .. ParamN);
7476 -- end <protected-function-name>;
7480 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7482 -- <protected-procedure-name>P (Param1 .. ParamN);
7483 -- end <protected-procedure-name>
7485 ---------------------------------------
7486 -- Build_Dispatching_Subprogram_Body --
7487 ---------------------------------------
7489 function Build_Dispatching_Subprogram_Body
7492 Prot_Bod : Node_Id) return Node_Id
7494 Loc : constant Source_Ptr := Sloc (N);
7501 -- Generate a specification without a letter suffix in order to
7502 -- override an interface function or procedure.
7504 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7506 -- The formal parameters become the actuals of the protected function
7507 -- or procedure call.
7509 Actuals := New_List;
7510 Formal := First (Parameter_Specifications (Spec));
7511 while Present (Formal) loop
7513 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7518 if Nkind (Spec) = N_Procedure_Specification then
7521 Make_Procedure_Call_Statement (Loc,
7523 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7524 Parameter_Associations => Actuals));
7526 pragma Assert (Nkind (Spec) = N_Function_Specification);
7530 Make_Simple_Return_Statement (Loc,
7532 Make_Function_Call (Loc,
7534 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7535 Parameter_Associations => Actuals)));
7539 Make_Subprogram_Body (Loc,
7540 Declarations => Empty_List,
7541 Specification => Spec,
7542 Handled_Statement_Sequence =>
7543 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7544 end Build_Dispatching_Subprogram_Body;
7546 -- Start of processing for Expand_N_Protected_Body
7549 if No_Run_Time_Mode then
7550 Error_Msg_CRT ("protected body", N);
7554 -- This is the proper body corresponding to a stub. The declarations
7555 -- must be inserted at the point of the stub, which in turn is in the
7556 -- declarative part of the parent unit.
7558 if Nkind (Parent (N)) = N_Subunit then
7559 Current_Node := Corresponding_Stub (Parent (N));
7564 Op_Body := First (Declarations (N));
7566 -- The protected body is replaced with the bodies of its
7567 -- protected operations, and the declarations for internal objects
7568 -- that may have been created for entry family bounds.
7570 Rewrite (N, Make_Null_Statement (Sloc (N)));
7573 while Present (Op_Body) loop
7574 case Nkind (Op_Body) is
7575 when N_Subprogram_Declaration =>
7578 when N_Subprogram_Body =>
7580 -- Do not create bodies for eliminated operations
7582 if not Is_Eliminated (Defining_Entity (Op_Body))
7583 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7586 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7588 Insert_After (Current_Node, New_Op_Body);
7589 Current_Node := New_Op_Body;
7590 Analyze (New_Op_Body);
7592 -- Build the corresponding protected operation. It may
7593 -- appear that this is needed only if this is a visible
7594 -- operation of the type, or if it is an interrupt handler,
7595 -- and this was the strategy used previously in GNAT.
7596 -- However, the operation may be exported through a 'Access
7597 -- to an external caller. This is the common idiom in code
7598 -- that uses the Ada 2005 Timing_Events package. As a result
7599 -- we need to produce the protected body for both visible
7600 -- and private operations, as well as operations that only
7601 -- have a body in the source, and for which we create a
7602 -- declaration in the protected body itself.
7604 if Present (Corresponding_Spec (Op_Body)) then
7606 Build_Protected_Subprogram_Body (
7607 Op_Body, Pid, Specification (New_Op_Body));
7609 Insert_After (Current_Node, New_Op_Body);
7610 Analyze (New_Op_Body);
7612 Current_Node := New_Op_Body;
7614 -- Generate an overriding primitive operation body for
7615 -- this subprogram if the protected type implements an
7618 if Ada_Version >= Ada_2005
7620 Present (Interfaces (Corresponding_Record_Type (Pid)))
7623 Build_Dispatching_Subprogram_Body
7624 (Op_Body, Pid, New_Op_Body);
7626 Insert_After (Current_Node, Disp_Op_Body);
7627 Analyze (Disp_Op_Body);
7629 Current_Node := Disp_Op_Body;
7634 when N_Entry_Body =>
7635 Op_Id := Defining_Identifier (Op_Body);
7636 Num_Entries := Num_Entries + 1;
7638 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7640 Insert_After (Current_Node, New_Op_Body);
7641 Current_Node := New_Op_Body;
7642 Analyze (New_Op_Body);
7644 when N_Implicit_Label_Declaration =>
7647 when N_Itype_Reference =>
7648 Insert_After (Current_Node, New_Copy (Op_Body));
7650 when N_Freeze_Entity =>
7651 New_Op_Body := New_Copy (Op_Body);
7653 if Present (Entity (Op_Body))
7654 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7656 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7659 Insert_After (Current_Node, New_Op_Body);
7660 Current_Node := New_Op_Body;
7661 Analyze (New_Op_Body);
7664 New_Op_Body := New_Copy (Op_Body);
7665 Insert_After (Current_Node, New_Op_Body);
7666 Current_Node := New_Op_Body;
7667 Analyze (New_Op_Body);
7669 when N_Object_Declaration =>
7670 pragma Assert (not Comes_From_Source (Op_Body));
7671 New_Op_Body := New_Copy (Op_Body);
7672 Insert_After (Current_Node, New_Op_Body);
7673 Current_Node := New_Op_Body;
7674 Analyze (New_Op_Body);
7677 raise Program_Error;
7684 -- Finally, create the body of the function that maps an entry index
7685 -- into the corresponding body index, except when there is no entry, or
7686 -- in a Ravenscar-like profile.
7688 if Corresponding_Runtime_Package (Pid) =
7689 System_Tasking_Protected_Objects_Entries
7691 New_Op_Body := Build_Find_Body_Index (Pid);
7692 Insert_After (Current_Node, New_Op_Body);
7693 Current_Node := New_Op_Body;
7694 Analyze (New_Op_Body);
7697 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7698 -- protected body. At this point all wrapper specs have been created,
7699 -- frozen and included in the dispatch table for the protected type.
7701 if Ada_Version >= Ada_2005 then
7702 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7704 end Expand_N_Protected_Body;
7706 -----------------------------------------
7707 -- Expand_N_Protected_Type_Declaration --
7708 -----------------------------------------
7710 -- First we create a corresponding record type declaration used to
7711 -- represent values of this protected type.
7712 -- The general form of this type declaration is
7714 -- type poV (discriminants) is record
7715 -- _Object : aliased <kind>Protection
7716 -- [(<entry count> [, <handler count>])];
7717 -- [entry_family : array (bounds) of Void;]
7718 -- <private data fields>
7721 -- The discriminants are present only if the corresponding protected type
7722 -- has discriminants, and they exactly mirror the protected type
7723 -- discriminants. The private data fields similarly mirror the private
7724 -- declarations of the protected type.
7726 -- The Object field is always present. It contains RTS specific data used
7727 -- to control the protected object. It is declared as Aliased so that it
7728 -- can be passed as a pointer to the RTS. This allows the protected record
7729 -- to be referenced within RTS data structures. An appropriate Protection
7730 -- type and discriminant are generated.
7732 -- The Service field is present for protected objects with entries. It
7733 -- contains sufficient information to allow the entry service procedure for
7734 -- this object to be called when the object is not known till runtime.
7736 -- One entry_family component is present for each entry family in the
7737 -- task definition (see Expand_N_Task_Type_Declaration).
7739 -- When a protected object is declared, an instance of the protected type
7740 -- value record is created. The elaboration of this declaration creates the
7741 -- correct bounds for the entry families, and also evaluates the priority
7742 -- expression if needed. The initialization routine for the protected type
7743 -- itself then calls Initialize_Protection with appropriate parameters to
7744 -- initialize the value of the Task_Id field. Install_Handlers may be also
7745 -- called if a pragma Attach_Handler applies.
7747 -- Note: this record is passed to the subprograms created by the expansion
7748 -- of protected subprograms and entries. It is an in parameter to protected
7749 -- functions and an in out parameter to procedures and entry bodies. The
7750 -- Entity_Id for this created record type is placed in the
7751 -- Corresponding_Record_Type field of the associated protected type entity.
7753 -- Next we create a procedure specifications for protected subprograms and
7754 -- entry bodies. For each protected subprograms two subprograms are
7755 -- created, an unprotected and a protected version. The unprotected version
7756 -- is called from within other operations of the same protected object.
7758 -- We also build the call to register the procedure if a pragma
7759 -- Interrupt_Handler applies.
7761 -- A single subprogram is created to service all entry bodies; it has an
7762 -- additional boolean out parameter indicating that the previous entry call
7763 -- made by the current task was serviced immediately, i.e. not by proxy.
7764 -- The O parameter contains a pointer to a record object of the type
7765 -- described above. An untyped interface is used here to allow this
7766 -- procedure to be called in places where the type of the object to be
7767 -- serviced is not known. This must be done, for example, when a call that
7768 -- may have been requeued is cancelled; the corresponding object must be
7769 -- serviced, but which object that is not known till runtime.
7772 -- (O : System.Address; P : out Boolean);
7773 -- procedure pprocN (_object : in out poV);
7774 -- procedure pproc (_object : in out poV);
7775 -- function pfuncN (_object : poV);
7776 -- function pfunc (_object : poV);
7779 -- Note that this must come after the record type declaration, since
7780 -- the specs refer to this type.
7782 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7783 Loc : constant Source_Ptr := Sloc (N);
7784 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7786 Pdef : constant Node_Id := Protected_Definition (N);
7787 -- This contains two lists; one for visible and one for private decls
7791 Discr_Map : constant Elist_Id := New_Elmt_List;
7795 Comp_Id : Entity_Id;
7797 Current_Node : Node_Id := N;
7798 Bdef : Entity_Id := Empty; -- avoid uninit warning
7799 Edef : Entity_Id := Empty; -- avoid uninit warning
7800 Entries_Aggr : Node_Id;
7801 Body_Id : Entity_Id;
7804 Object_Comp : Node_Id;
7806 procedure Check_Inlining (Subp : Entity_Id);
7807 -- If the original operation has a pragma Inline, propagate the flag
7808 -- to the internal body, for possible inlining later on. The source
7809 -- operation is invisible to the back-end and is never actually called.
7811 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7812 -- When compiling under the Ravenscar profile, private components must
7813 -- have a static size, or else a protected object will require heap
7814 -- allocation, violating the corresponding restriction. It is preferable
7815 -- to make this check here, because it provides a better error message
7816 -- than the back-end, which refers to the object as a whole.
7818 procedure Register_Handler;
7819 -- For a protected operation that is an interrupt handler, add the
7820 -- freeze action that will register it as such.
7822 --------------------
7823 -- Check_Inlining --
7824 --------------------
7826 procedure Check_Inlining (Subp : Entity_Id) is
7828 if Is_Inlined (Subp) then
7829 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7830 Set_Is_Inlined (Subp, False);
7834 ---------------------------------
7835 -- Check_Static_Component_Size --
7836 ---------------------------------
7838 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7839 Typ : constant Entity_Id := Etype (Comp);
7843 if Is_Scalar_Type (Typ) then
7846 elsif Is_Array_Type (Typ) then
7847 return Compile_Time_Known_Bounds (Typ);
7849 elsif Is_Record_Type (Typ) then
7850 C := First_Component (Typ);
7851 while Present (C) loop
7852 if not Static_Component_Size (C) then
7861 -- Any other types will be checked by the back-end
7866 end Static_Component_Size;
7868 ----------------------
7869 -- Register_Handler --
7870 ----------------------
7872 procedure Register_Handler is
7874 -- All semantic checks already done in Sem_Prag
7876 Prot_Proc : constant Entity_Id :=
7878 (Specification (Current_Node));
7880 Proc_Address : constant Node_Id :=
7881 Make_Attribute_Reference (Loc,
7882 Prefix => New_Reference_To (Prot_Proc, Loc),
7883 Attribute_Name => Name_Address);
7885 RTS_Call : constant Entity_Id :=
7886 Make_Procedure_Call_Statement (Loc,
7889 RTE (RE_Register_Interrupt_Handler), Loc),
7890 Parameter_Associations =>
7891 New_List (Proc_Address));
7893 Append_Freeze_Action (Prot_Proc, RTS_Call);
7894 end Register_Handler;
7896 -- Start of processing for Expand_N_Protected_Type_Declaration
7899 if Present (Corresponding_Record_Type (Prot_Typ)) then
7902 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7905 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7907 Qualify_Entity_Names (N);
7909 -- If the type has discriminants, their occurrences in the declaration
7910 -- have been replaced by the corresponding discriminals. For components
7911 -- that are constrained by discriminants, their homologues in the
7912 -- corresponding record type must refer to the discriminants of that
7913 -- record, so we must apply a new renaming to subtypes_indications:
7915 -- protected discriminant => discriminal => record discriminant
7917 -- This replacement is not applied to default expressions, for which
7918 -- the discriminal is correct.
7920 if Has_Discriminants (Prot_Typ) then
7926 Disc := First_Discriminant (Prot_Typ);
7927 Decl := First (Discriminant_Specifications (Rec_Decl));
7928 while Present (Disc) loop
7929 Append_Elmt (Discriminal (Disc), Discr_Map);
7930 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7931 Next_Discriminant (Disc);
7937 -- Fill in the component declarations
7939 -- Add components for entry families. For each entry family, create an
7940 -- anonymous type declaration with the same size, and analyze the type.
7942 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7944 -- Prepend the _Object field with the right type to the component list.
7945 -- We need to compute the number of entries, and in some cases the
7946 -- number of Attach_Handler pragmas.
7950 Num_Attach_Handler : Int := 0;
7951 Protection_Subtype : Node_Id;
7952 Entry_Count_Expr : constant Node_Id :=
7953 Build_Entry_Count_Expression
7954 (Prot_Typ, Cdecls, Loc);
7957 -- Could this be simplified using Corresponding_Runtime_Package???
7959 if Has_Attach_Handler (Prot_Typ) then
7960 Ritem := First_Rep_Item (Prot_Typ);
7961 while Present (Ritem) loop
7962 if Nkind (Ritem) = N_Pragma
7963 and then Pragma_Name (Ritem) = Name_Attach_Handler
7965 Num_Attach_Handler := Num_Attach_Handler + 1;
7968 Next_Rep_Item (Ritem);
7971 if Restricted_Profile then
7972 if Has_Entries (Prot_Typ) then
7973 Protection_Subtype :=
7974 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7976 Protection_Subtype :=
7977 New_Reference_To (RTE (RE_Protection), Loc);
7980 Protection_Subtype :=
7981 Make_Subtype_Indication
7985 (RTE (RE_Static_Interrupt_Protection), Loc),
7987 Make_Index_Or_Discriminant_Constraint (
7989 Constraints => New_List (
7991 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7994 elsif Has_Interrupt_Handler (Prot_Typ) then
7995 Protection_Subtype :=
7996 Make_Subtype_Indication (
7998 Subtype_Mark => New_Reference_To
7999 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
8001 Make_Index_Or_Discriminant_Constraint (
8003 Constraints => New_List (Entry_Count_Expr)));
8005 -- Type has explicit entries or generated primitive entry wrappers
8007 elsif Has_Entries (Prot_Typ)
8008 or else (Ada_Version >= Ada_2005
8009 and then Present (Interface_List (N)))
8011 case Corresponding_Runtime_Package (Prot_Typ) is
8012 when System_Tasking_Protected_Objects_Entries =>
8013 Protection_Subtype :=
8014 Make_Subtype_Indication (Loc,
8016 New_Reference_To (RTE (RE_Protection_Entries), Loc),
8018 Make_Index_Or_Discriminant_Constraint (
8020 Constraints => New_List (Entry_Count_Expr)));
8022 when System_Tasking_Protected_Objects_Single_Entry =>
8023 Protection_Subtype :=
8024 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8027 raise Program_Error;
8031 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
8035 Make_Component_Declaration (Loc,
8036 Defining_Identifier =>
8037 Make_Defining_Identifier (Loc, Name_uObject),
8038 Component_Definition =>
8039 Make_Component_Definition (Loc,
8040 Aliased_Present => True,
8041 Subtype_Indication => Protection_Subtype));
8044 pragma Assert (Present (Pdef));
8046 -- Add private field components
8048 if Present (Private_Declarations (Pdef)) then
8049 Priv := First (Private_Declarations (Pdef));
8051 while Present (Priv) loop
8053 if Nkind (Priv) = N_Component_Declaration then
8054 if not Static_Component_Size (Defining_Identifier (Priv)) then
8056 -- When compiling for a restricted profile, the private
8057 -- components must have a static size. If not, this is an
8058 -- error for a single protected declaration, and rates a
8059 -- warning on a protected type declaration.
8061 if not Comes_From_Source (Prot_Typ) then
8062 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8064 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8065 Error_Msg_N ("component has non-static size?", Priv);
8067 ("\creation of protected object of type& will violate"
8068 & " restriction No_Implicit_Heap_Allocations?",
8073 -- The component definition consists of a subtype indication,
8074 -- or (in Ada 2005) an access definition. Make a copy of the
8075 -- proper definition.
8078 Old_Comp : constant Node_Id := Component_Definition (Priv);
8079 Oent : constant Entity_Id := Defining_Identifier (Priv);
8081 Nent : constant Entity_Id :=
8082 Make_Defining_Identifier (Sloc (Oent),
8083 Chars => Chars (Oent));
8086 if Present (Subtype_Indication (Old_Comp)) then
8088 Make_Component_Definition (Sloc (Oent),
8089 Aliased_Present => False,
8090 Subtype_Indication =>
8091 New_Copy_Tree (Subtype_Indication (Old_Comp),
8095 Make_Component_Definition (Sloc (Oent),
8096 Aliased_Present => False,
8097 Access_Definition =>
8098 New_Copy_Tree (Access_Definition (Old_Comp),
8103 Make_Component_Declaration (Loc,
8104 Defining_Identifier => Nent,
8105 Component_Definition => New_Comp,
8106 Expression => Expression (Priv));
8108 Set_Has_Per_Object_Constraint (Nent,
8109 Has_Per_Object_Constraint (Oent));
8111 Append_To (Cdecls, New_Priv);
8114 elsif Nkind (Priv) = N_Subprogram_Declaration then
8116 -- Make the unprotected version of the subprogram available
8117 -- for expansion of intra object calls. There is need for
8118 -- a protected version only if the subprogram is an interrupt
8119 -- handler, otherwise this operation can only be called from
8123 Make_Subprogram_Declaration (Loc,
8125 Build_Protected_Sub_Specification
8126 (Priv, Prot_Typ, Unprotected_Mode));
8128 Insert_After (Current_Node, Sub);
8131 Set_Protected_Body_Subprogram
8132 (Defining_Unit_Name (Specification (Priv)),
8133 Defining_Unit_Name (Specification (Sub)));
8134 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8135 Current_Node := Sub;
8138 Make_Subprogram_Declaration (Loc,
8140 Build_Protected_Sub_Specification
8141 (Priv, Prot_Typ, Protected_Mode));
8143 Insert_After (Current_Node, Sub);
8145 Current_Node := Sub;
8147 if Is_Interrupt_Handler
8148 (Defining_Unit_Name (Specification (Priv)))
8150 if not Restricted_Profile then
8160 -- Put the _Object component after the private component so that it
8161 -- be finalized early as required by 9.4 (20)
8163 Append_To (Cdecls, Object_Comp);
8165 Insert_After (Current_Node, Rec_Decl);
8166 Current_Node := Rec_Decl;
8168 -- Analyze the record declaration immediately after construction,
8169 -- because the initialization procedure is needed for single object
8170 -- declarations before the next entity is analyzed (the freeze call
8171 -- that generates this initialization procedure is found below).
8173 Analyze (Rec_Decl, Suppress => All_Checks);
8175 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8176 -- the corresponding record is frozen. If any wrappers are generated,
8177 -- Current_Node is updated accordingly.
8179 if Ada_Version >= Ada_2005 then
8180 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8183 -- Collect pointers to entry bodies and their barriers, to be placed
8184 -- in the Entry_Bodies_Array for the type. For each entry/family we
8185 -- add an expression to the aggregate which is the initial value of
8186 -- this array. The array is declared after all protected subprograms.
8188 if Has_Entries (Prot_Typ) then
8189 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8191 Entries_Aggr := Empty;
8194 -- Build two new procedure specifications for each protected subprogram;
8195 -- one to call from outside the object and one to call from inside.
8196 -- Build a barrier function and an entry body action procedure
8197 -- specification for each protected entry. Initialize the entry body
8198 -- array. If subprogram is flagged as eliminated, do not generate any
8199 -- internal operations.
8203 Comp := First (Visible_Declarations (Pdef));
8205 while Present (Comp) loop
8206 if Nkind (Comp) = N_Subprogram_Declaration then
8208 Make_Subprogram_Declaration (Loc,
8210 Build_Protected_Sub_Specification
8211 (Comp, Prot_Typ, Unprotected_Mode));
8213 Insert_After (Current_Node, Sub);
8216 Set_Protected_Body_Subprogram
8217 (Defining_Unit_Name (Specification (Comp)),
8218 Defining_Unit_Name (Specification (Sub)));
8219 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8221 -- Make the protected version of the subprogram available for
8222 -- expansion of external calls.
8224 Current_Node := Sub;
8227 Make_Subprogram_Declaration (Loc,
8229 Build_Protected_Sub_Specification
8230 (Comp, Prot_Typ, Protected_Mode));
8232 Insert_After (Current_Node, Sub);
8235 Current_Node := Sub;
8237 -- Generate an overriding primitive operation specification for
8238 -- this subprogram if the protected type implements an interface.
8240 if Ada_Version >= Ada_2005
8242 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8245 Make_Subprogram_Declaration (Loc,
8247 Build_Protected_Sub_Specification
8248 (Comp, Prot_Typ, Dispatching_Mode));
8250 Insert_After (Current_Node, Sub);
8253 Current_Node := Sub;
8256 -- If a pragma Interrupt_Handler applies, build and add a call to
8257 -- Register_Interrupt_Handler to the freezing actions of the
8258 -- protected version (Current_Node) of the subprogram:
8260 -- system.interrupts.register_interrupt_handler
8261 -- (prot_procP'address);
8263 if not Restricted_Profile
8264 and then Is_Interrupt_Handler
8265 (Defining_Unit_Name (Specification (Comp)))
8270 elsif Nkind (Comp) = N_Entry_Declaration then
8271 E_Count := E_Count + 1;
8272 Comp_Id := Defining_Identifier (Comp);
8275 Make_Defining_Identifier (Loc,
8276 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8278 Make_Subprogram_Declaration (Loc,
8280 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8282 Insert_After (Current_Node, Sub);
8285 -- build wrapper procedure for pre/postconditions.
8287 Build_PPC_Wrapper (Comp_Id, N);
8289 Set_Protected_Body_Subprogram
8290 (Defining_Identifier (Comp),
8291 Defining_Unit_Name (Specification (Sub)));
8293 Current_Node := Sub;
8296 Make_Defining_Identifier (Loc,
8297 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8299 Make_Subprogram_Declaration (Loc,
8301 Build_Barrier_Function_Specification (Loc, Bdef));
8303 Insert_After (Current_Node, Sub);
8305 Set_Protected_Body_Subprogram (Bdef, Bdef);
8306 Set_Barrier_Function (Comp_Id, Bdef);
8307 Set_Scope (Bdef, Scope (Comp_Id));
8308 Current_Node := Sub;
8310 -- Collect pointers to the protected subprogram and the barrier
8311 -- of the current entry, for insertion into Entry_Bodies_Array.
8314 Make_Aggregate (Loc,
8315 Expressions => New_List (
8316 Make_Attribute_Reference (Loc,
8317 Prefix => New_Reference_To (Bdef, Loc),
8318 Attribute_Name => Name_Unrestricted_Access),
8319 Make_Attribute_Reference (Loc,
8320 Prefix => New_Reference_To (Edef, Loc),
8321 Attribute_Name => Name_Unrestricted_Access))),
8322 Expressions (Entries_Aggr));
8329 -- If there are some private entry declarations, expand it as if they
8330 -- were visible entries.
8332 if Present (Private_Declarations (Pdef)) then
8333 Comp := First (Private_Declarations (Pdef));
8334 while Present (Comp) loop
8335 if Nkind (Comp) = N_Entry_Declaration then
8336 E_Count := E_Count + 1;
8337 Comp_Id := Defining_Identifier (Comp);
8340 Make_Defining_Identifier (Loc,
8341 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8343 Make_Subprogram_Declaration (Loc,
8345 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8347 Insert_After (Current_Node, Sub);
8350 Set_Protected_Body_Subprogram
8351 (Defining_Identifier (Comp),
8352 Defining_Unit_Name (Specification (Sub)));
8354 Current_Node := Sub;
8357 Make_Defining_Identifier (Loc,
8358 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8361 Make_Subprogram_Declaration (Loc,
8363 Build_Barrier_Function_Specification (Loc, Bdef));
8365 Insert_After (Current_Node, Sub);
8367 Set_Protected_Body_Subprogram (Bdef, Bdef);
8368 Set_Barrier_Function (Comp_Id, Bdef);
8369 Set_Scope (Bdef, Scope (Comp_Id));
8370 Current_Node := Sub;
8372 -- Collect pointers to the protected subprogram and the barrier
8373 -- of the current entry, for insertion into Entry_Bodies_Array.
8375 Append_To (Expressions (Entries_Aggr),
8376 Make_Aggregate (Loc,
8377 Expressions => New_List (
8378 Make_Attribute_Reference (Loc,
8379 Prefix => New_Reference_To (Bdef, Loc),
8380 Attribute_Name => Name_Unrestricted_Access),
8381 Make_Attribute_Reference (Loc,
8382 Prefix => New_Reference_To (Edef, Loc),
8383 Attribute_Name => Name_Unrestricted_Access))));
8390 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8391 -- all protected subprograms have been collected.
8393 if Has_Entries (Prot_Typ) then
8395 Make_Defining_Identifier (Sloc (Prot_Typ),
8396 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8398 case Corresponding_Runtime_Package (Prot_Typ) is
8399 when System_Tasking_Protected_Objects_Entries =>
8400 Body_Arr := Make_Object_Declaration (Loc,
8401 Defining_Identifier => Body_Id,
8402 Aliased_Present => True,
8403 Object_Definition =>
8404 Make_Subtype_Indication (Loc,
8405 Subtype_Mark => New_Reference_To (
8406 RTE (RE_Protected_Entry_Body_Array), Loc),
8408 Make_Index_Or_Discriminant_Constraint (Loc,
8409 Constraints => New_List (
8411 Make_Integer_Literal (Loc, 1),
8412 Make_Integer_Literal (Loc, E_Count))))),
8413 Expression => Entries_Aggr);
8415 when System_Tasking_Protected_Objects_Single_Entry =>
8416 Body_Arr := Make_Object_Declaration (Loc,
8417 Defining_Identifier => Body_Id,
8418 Aliased_Present => True,
8419 Object_Definition => New_Reference_To
8420 (RTE (RE_Entry_Body), Loc),
8422 Make_Aggregate (Loc,
8423 Expressions => New_List (
8424 Make_Attribute_Reference (Loc,
8425 Prefix => New_Reference_To (Bdef, Loc),
8426 Attribute_Name => Name_Unrestricted_Access),
8427 Make_Attribute_Reference (Loc,
8428 Prefix => New_Reference_To (Edef, Loc),
8429 Attribute_Name => Name_Unrestricted_Access))));
8432 raise Program_Error;
8435 -- A pointer to this array will be placed in the corresponding record
8436 -- by its initialization procedure so this needs to be analyzed here.
8438 Insert_After (Current_Node, Body_Arr);
8439 Current_Node := Body_Arr;
8442 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8444 -- Finally, build the function that maps an entry index into the
8445 -- corresponding body. A pointer to this function is placed in each
8446 -- object of the type. Except for a ravenscar-like profile (no abort,
8447 -- no entry queue, 1 entry)
8449 if Corresponding_Runtime_Package (Prot_Typ) =
8450 System_Tasking_Protected_Objects_Entries
8453 Make_Subprogram_Declaration (Loc,
8454 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8455 Insert_After (Current_Node, Sub);
8459 end Expand_N_Protected_Type_Declaration;
8461 --------------------------------
8462 -- Expand_N_Requeue_Statement --
8463 --------------------------------
8465 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8466 -- operations, depending on the source and destination (task or protected
8467 -- object). A dispatching requeue statement is expanded into a call to the
8468 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8469 -- jump around the remainder of processing for the original entry and, if
8470 -- the destination is (different) protected object, to attempt to service
8471 -- it. The following illustrates the various cases:
8474 -- (O : System.Address;
8475 -- P : System.Address;
8476 -- E : Protected_Entry_Index)
8478 -- <discriminant renamings>
8479 -- <private object renamings>
8480 -- type poVP is access poV;
8481 -- _object : ptVP := ptVP!(O);
8485 -- <start of statement sequence for entry>
8487 -- -- Requeue from one protected entry body to another protected
8490 -- Requeue_Protected_Entry (
8491 -- _object._object'Access,
8492 -- new._object'Access,
8497 -- <some more of the statement sequence for entry>
8499 -- -- Requeue from an entry body to a task entry
8501 -- Requeue_Protected_To_Task_Entry (
8507 -- <rest of statement sequence for entry>
8508 -- Complete_Entry_Body (_object._object);
8511 -- when all others =>
8512 -- Exceptional_Complete_Entry_Body (
8513 -- _object._object, Get_GNAT_Exception);
8517 -- Requeue of a task entry call to a task entry
8519 -- Accept_Call (E, Ann);
8520 -- <start of statement sequence for accept statement>
8521 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8523 -- <rest of statement sequence for accept statement>
8525 -- Complete_Rendezvous;
8528 -- when all others =>
8529 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8531 -- Requeue of a task entry call to a protected entry
8533 -- Accept_Call (E, Ann);
8534 -- <start of statement sequence for accept statement>
8535 -- Requeue_Task_To_Protected_Entry (
8536 -- new._object'Access,
8541 -- <rest of statement sequence for accept statement>
8543 -- Complete_Rendezvous;
8546 -- when all others =>
8547 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8549 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8550 -- marked by pragma Implemented (XXX, By_Entry).
8552 -- The requeue is inside a protected entry:
8555 -- (O : System.Address;
8556 -- P : System.Address;
8557 -- E : Protected_Entry_Index)
8559 -- <discriminant renamings>
8560 -- <private object renamings>
8561 -- type poVP is access poV;
8562 -- _object : ptVP := ptVP!(O);
8566 -- <start of statement sequence for entry>
8569 -- (<interface class-wide object>,
8572 -- Ada.Tags.Get_Offset_Index
8574 -- <interface dispatch table index of target entry>),
8578 -- <rest of statement sequence for entry>
8579 -- Complete_Entry_Body (_object._object);
8582 -- when all others =>
8583 -- Exceptional_Complete_Entry_Body (
8584 -- _object._object, Get_GNAT_Exception);
8588 -- The requeue is inside a task entry:
8590 -- Accept_Call (E, Ann);
8591 -- <start of statement sequence for accept statement>
8593 -- (<interface class-wide object>,
8596 -- Ada.Tags.Get_Offset_Index
8598 -- <interface dispatch table index of target entrt>),
8602 -- <rest of statement sequence for accept statement>
8604 -- Complete_Rendezvous;
8607 -- when all others =>
8608 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8610 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8611 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8612 -- statement is replaced by a dispatching call with actual parameters taken
8613 -- from the inner-most accept statement or entry body.
8615 -- Target.Primitive (Param1, ..., ParamN);
8617 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8618 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8621 -- S : constant Offset_Index :=
8622 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8623 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8626 -- if C = POK_Protected_Entry
8627 -- or else C = POK_Task_Entry
8629 -- <statements for dispatching requeue>
8631 -- elsif C = POK_Protected_Procedure then
8632 -- <dispatching call equivalent>
8635 -- raise Program_Error;
8639 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8640 Loc : constant Source_Ptr := Sloc (N);
8641 Conc_Typ : Entity_Id;
8645 Old_Typ : Entity_Id;
8647 function Build_Dispatching_Call_Equivalent return Node_Id;
8648 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8649 -- the form Concval.Ename. It is statically known that Ename is allowed
8650 -- to be implemented by a protected procedure. Create a dispatching call
8651 -- equivalent of Concval.Ename taking the actual parameters from the
8652 -- inner-most accept statement or entry body.
8654 function Build_Dispatching_Requeue return Node_Id;
8655 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8656 -- the form Concval.Ename. It is statically known that Ename is allowed
8657 -- to be implemented by a protected or a task entry. Create a call to
8658 -- primitive _Disp_Requeue which handles the low-level actions.
8660 function Build_Dispatching_Requeue_To_Any return Node_Id;
8661 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8662 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8663 -- (XXX, By_Any) or not marked at all. Create a block which determines
8664 -- at runtime whether Ename denotes an entry or a procedure and perform
8665 -- the appropriate kind of dispatching select.
8667 function Build_Normal_Requeue return Node_Id;
8668 -- N denotes a non-dispatching requeue statement to either a task or a
8669 -- protected entry. Build the appropriate runtime call to perform the
8672 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8673 -- For a protected entry, create a return statement to skip the rest of
8674 -- the entry body. Otherwise, create a goto statement to skip the rest
8675 -- of a task accept statement. The lookup for the enclosing entry body
8676 -- or accept statement starts from Search.
8678 ---------------------------------------
8679 -- Build_Dispatching_Call_Equivalent --
8680 ---------------------------------------
8682 function Build_Dispatching_Call_Equivalent return Node_Id is
8683 Call_Ent : constant Entity_Id := Entity (Ename);
8684 Obj : constant Node_Id := Original_Node (Concval);
8691 -- Climb the parent chain looking for the inner-most entry body or
8692 -- accept statement.
8695 while Present (Acc_Ent)
8696 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8699 Acc_Ent := Parent (Acc_Ent);
8702 -- A requeue statement should be housed inside an entry body or an
8703 -- accept statement at some level. If this is not the case, then the
8704 -- tree is malformed.
8706 pragma Assert (Present (Acc_Ent));
8708 -- Recover the list of formal parameters
8710 if Nkind (Acc_Ent) = N_Entry_Body then
8711 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8714 Formals := Parameter_Specifications (Acc_Ent);
8716 -- Create the actual parameters for the dispatching call. These are
8717 -- simply copies of the entry body or accept statement formals in the
8718 -- same order as they appear.
8722 if Present (Formals) then
8723 Actuals := New_List;
8724 Formal := First (Formals);
8725 while Present (Formal) loop
8727 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8733 -- Obj.Call_Ent (Actuals);
8736 Make_Procedure_Call_Statement (Loc,
8738 Make_Selected_Component (Loc,
8739 Prefix => Make_Identifier (Loc, Chars (Obj)),
8740 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
8742 Parameter_Associations => Actuals);
8743 end Build_Dispatching_Call_Equivalent;
8745 -------------------------------
8746 -- Build_Dispatching_Requeue --
8747 -------------------------------
8749 function Build_Dispatching_Requeue return Node_Id is
8750 Params : constant List_Id := New_List;
8753 -- Process the "with abort" parameter
8756 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8758 -- Process the entry wrapper's position in the primary dispatch
8759 -- table parameter. Generate:
8761 -- Ada.Tags.Get_Offset_Index
8762 -- (Ada.Tags.Tag (Concval),
8763 -- <interface dispatch table position of Ename>)
8765 if Tagged_Type_Expansion then
8767 Make_Function_Call (Loc,
8768 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8769 Parameter_Associations => New_List (
8770 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8771 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8777 Make_Function_Call (Loc,
8778 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8780 Parameter_Associations => New_List (
8784 Make_Attribute_Reference (Loc,
8786 Attribute_Name => Name_Tag),
8790 Make_Attribute_Reference (Loc,
8791 Prefix => New_Reference_To (Etype (Concval), Loc),
8792 Attribute_Name => Name_Tag),
8796 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8799 -- Specific actuals for protected to XXX requeue
8801 if Is_Protected_Type (Old_Typ) then
8803 Make_Attribute_Reference (Loc, -- _object'Address
8805 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8806 Attribute_Name => Name_Address));
8808 Prepend_To (Params, -- True
8809 New_Reference_To (Standard_True, Loc));
8811 -- Specific actuals for task to XXX requeue
8814 pragma Assert (Is_Task_Type (Old_Typ));
8816 Prepend_To (Params, -- null
8817 New_Reference_To (RTE (RE_Null_Address), Loc));
8819 Prepend_To (Params, -- False
8820 New_Reference_To (Standard_False, Loc));
8823 -- Add the object parameter
8825 Prepend_To (Params, New_Copy_Tree (Concval));
8828 -- _Disp_Requeue (<Params>);
8831 Make_Procedure_Call_Statement (Loc,
8832 Name => Make_Identifier (Loc, Name_uDisp_Requeue),
8833 Parameter_Associations => Params);
8834 end Build_Dispatching_Requeue;
8836 --------------------------------------
8837 -- Build_Dispatching_Requeue_To_Any --
8838 --------------------------------------
8840 function Build_Dispatching_Requeue_To_Any return Node_Id is
8841 Call_Ent : constant Entity_Id := Entity (Ename);
8842 Obj : constant Node_Id := Original_Node (Concval);
8843 Skip : constant Node_Id := Build_Skip_Statement (N);
8853 -- Dispatch table slot processing, generate:
8856 S := Build_S (Loc, Decls);
8858 -- Call kind processing, generate:
8859 -- C : Ada.Tags.Prim_Op_Kind;
8861 C := Build_C (Loc, Decls);
8864 -- S := Ada.Tags.Get_Offset_Index
8865 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
8867 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
8870 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
8873 Make_Procedure_Call_Statement (Loc,
8876 Find_Prim_Op (Etype (Etype (Obj)),
8877 Name_uDisp_Get_Prim_Op_Kind),
8879 Parameter_Associations => New_List (
8880 New_Copy_Tree (Obj),
8881 New_Reference_To (S, Loc),
8882 New_Reference_To (C, Loc))));
8886 -- if C = POK_Protected_Entry
8887 -- or else C = POK_Task_Entry
8890 Make_If_Statement (Loc,
8896 New_Reference_To (C, Loc),
8898 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
8903 New_Reference_To (C, Loc),
8905 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
8907 -- Dispatching requeue equivalent
8909 Then_Statements => New_List (
8910 Build_Dispatching_Requeue,
8913 -- elsif C = POK_Protected_Procedure then
8915 Elsif_Parts => New_List (
8916 Make_Elsif_Part (Loc,
8920 New_Reference_To (C, Loc),
8923 RTE (RE_POK_Protected_Procedure), Loc)),
8925 -- Dispatching call equivalent
8927 Then_Statements => New_List (
8928 Build_Dispatching_Call_Equivalent))),
8931 -- raise Program_Error;
8934 Else_Statements => New_List (
8935 Make_Raise_Program_Error (Loc,
8936 Reason => PE_Explicit_Raise))));
8938 -- Wrap everything into a block
8941 Make_Block_Statement (Loc,
8942 Declarations => Decls,
8943 Handled_Statement_Sequence =>
8944 Make_Handled_Sequence_Of_Statements (Loc,
8945 Statements => Stmts));
8946 end Build_Dispatching_Requeue_To_Any;
8948 --------------------------
8949 -- Build_Normal_Requeue --
8950 --------------------------
8952 function Build_Normal_Requeue return Node_Id is
8953 Params : constant List_Id := New_List;
8958 -- Process the "with abort" parameter
8961 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8963 -- Add the index expression to the parameters. It is common among all
8967 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8969 if Is_Protected_Type (Old_Typ) then
8971 Self_Param : Node_Id;
8975 Make_Attribute_Reference (Loc,
8977 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8979 Name_Unchecked_Access);
8981 -- Protected to protected requeue
8983 if Is_Protected_Type (Conc_Typ) then
8986 RTE (RE_Requeue_Protected_Entry), Loc);
8989 Make_Attribute_Reference (Loc,
8991 Concurrent_Ref (Concval),
8993 Name_Unchecked_Access);
8995 -- Protected to task requeue
8997 else pragma Assert (Is_Task_Type (Conc_Typ));
9000 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
9002 Param := Concurrent_Ref (Concval);
9005 Prepend_To (Params, Param);
9006 Prepend_To (Params, Self_Param);
9009 else pragma Assert (Is_Task_Type (Old_Typ));
9011 -- Task to protected requeue
9013 if Is_Protected_Type (Conc_Typ) then
9016 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
9019 Make_Attribute_Reference (Loc,
9021 Concurrent_Ref (Concval),
9023 Name_Unchecked_Access);
9025 -- Task to task requeue
9027 else pragma Assert (Is_Task_Type (Conc_Typ));
9029 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
9031 Param := Concurrent_Ref (Concval);
9034 Prepend_To (Params, Param);
9038 Make_Procedure_Call_Statement (Loc,
9040 Parameter_Associations => Params);
9041 end Build_Normal_Requeue;
9043 --------------------------
9044 -- Build_Skip_Statement --
9045 --------------------------
9047 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
9048 Skip_Stmt : Node_Id;
9051 -- Build a return statement to skip the rest of the entire body
9053 if Is_Protected_Type (Old_Typ) then
9054 Skip_Stmt := Make_Simple_Return_Statement (Loc);
9056 -- If the requeue is within a task, find the end label of the
9057 -- enclosing accept statement and create a goto statement to it.
9065 -- Climb the parent chain looking for the enclosing accept
9068 Acc := Parent (Search);
9070 and then Nkind (Acc) /= N_Accept_Statement
9072 Acc := Parent (Acc);
9075 -- The last statement is the second label used for completing
9076 -- the rendezvous the usual way. The label we are looking for
9077 -- is right before it.
9080 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
9082 pragma Assert (Nkind (Label) = N_Label);
9084 -- Generate a goto statement to skip the rest of the accept
9087 Make_Goto_Statement (Loc,
9089 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9093 Set_Analyzed (Skip_Stmt);
9096 end Build_Skip_Statement;
9098 -- Start of processing for Expand_N_Requeue_Statement
9101 -- Extract the components of the entry call
9103 Extract_Entry (N, Concval, Ename, Index);
9104 Conc_Typ := Etype (Concval);
9106 -- Examine the scope stack in order to find nearest enclosing protected
9107 -- or task type. This will constitute our invocation source.
9109 Old_Typ := Current_Scope;
9110 while Present (Old_Typ)
9111 and then not Is_Protected_Type (Old_Typ)
9112 and then not Is_Task_Type (Old_Typ)
9114 Old_Typ := Scope (Old_Typ);
9117 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9118 -- Concval.Ename where the type of Concval is class-wide concurrent
9121 if Ada_Version >= Ada_2012
9122 and then Present (Concval)
9123 and then Is_Class_Wide_Type (Conc_Typ)
9124 and then Is_Concurrent_Interface (Conc_Typ)
9127 Has_Impl : Boolean := False;
9128 Impl_Kind : Name_Id := No_Name;
9131 -- Check whether the Ename is flagged by pragma Implemented
9133 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9135 Impl_Kind := Implementation_Kind (Entity (Ename));
9138 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9139 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9142 and then Impl_Kind = Name_By_Entry
9144 Rewrite (N, Build_Dispatching_Requeue);
9146 Insert_After (N, Build_Skip_Statement (N));
9148 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9149 -- a protected procedure. In this case the requeue is transformed
9150 -- into a dispatching call.
9153 and then Impl_Kind = Name_By_Protected_Procedure
9155 Rewrite (N, Build_Dispatching_Call_Equivalent);
9158 -- The procedure_or_entry_NAME's implementation kind is either
9159 -- By_Any or pragma Implemented was not applied at all. In this
9160 -- case a runtime test determines whether Ename denotes an entry
9161 -- or a protected procedure and performs the appropriate call.
9164 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9169 -- Processing for regular (non-dispatching) requeues
9172 Rewrite (N, Build_Normal_Requeue);
9174 Insert_After (N, Build_Skip_Statement (N));
9176 end Expand_N_Requeue_Statement;
9178 -------------------------------
9179 -- Expand_N_Selective_Accept --
9180 -------------------------------
9182 procedure Expand_N_Selective_Accept (N : Node_Id) is
9183 Loc : constant Source_Ptr := Sloc (N);
9184 Alts : constant List_Id := Select_Alternatives (N);
9186 -- Note: in the below declarations a lot of new lists are allocated
9187 -- unconditionally which may well not end up being used. That's
9188 -- not a good idea since it wastes space gratuitously ???
9190 Accept_Case : List_Id;
9191 Accept_List : constant List_Id := New_List;
9194 Alt_List : constant List_Id := New_List;
9195 Alt_Stats : List_Id;
9196 Ann : Entity_Id := Empty;
9199 Check_Guard : Boolean := True;
9201 Decls : constant List_Id := New_List;
9202 Stats : constant List_Id := New_List;
9203 Body_List : constant List_Id := New_List;
9204 Trailing_List : constant List_Id := New_List;
9207 Else_Present : Boolean := False;
9208 Terminate_Alt : Node_Id := Empty;
9209 Select_Mode : Node_Id;
9211 Delay_Case : List_Id;
9212 Delay_Count : Integer := 0;
9213 Delay_Val : Entity_Id;
9214 Delay_Index : Entity_Id;
9215 Delay_Min : Entity_Id;
9216 Delay_Num : Int := 1;
9217 Delay_Alt_List : List_Id := New_List;
9218 Delay_List : constant List_Id := New_List;
9222 First_Delay : Boolean := True;
9223 Guard_Open : Entity_Id;
9229 Num_Accept : Nat := 0;
9232 Time_Type : Entity_Id;
9234 Select_Call : Node_Id;
9236 Qnam : constant Entity_Id :=
9237 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9239 Xnam : constant Entity_Id :=
9240 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9242 -----------------------
9243 -- Local subprograms --
9244 -----------------------
9246 function Accept_Or_Raise return List_Id;
9247 -- For the rare case where delay alternatives all have guards, and
9248 -- all of them are closed, it is still possible that there were open
9249 -- accept alternatives with no callers. We must reexamine the
9250 -- Accept_List, and execute a selective wait with no else if some
9251 -- accept is open. If none, we raise program_error.
9253 procedure Add_Accept (Alt : Node_Id);
9254 -- Process a single accept statement in a select alternative. Build
9255 -- procedure for body of accept, and add entry to dispatch table with
9256 -- expression for guard, in preparation for call to run time select.
9258 function Make_And_Declare_Label (Num : Int) return Node_Id;
9259 -- Manufacture a label using Num as a serial number and declare it.
9260 -- The declaration is appended to Decls. The label marks the trailing
9261 -- statements of an accept or delay alternative.
9263 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9264 -- Build call to Selective_Wait runtime routine
9266 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9267 -- Add code to compare value of delay with previous values, and
9268 -- generate case entry for trailing statements.
9270 procedure Process_Accept_Alternative
9274 -- Add code to call corresponding procedure, and branch to
9275 -- trailing statements, if any.
9277 ---------------------
9278 -- Accept_Or_Raise --
9279 ---------------------
9281 function Accept_Or_Raise return List_Id is
9284 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9287 -- We generate the following:
9289 -- for J in q'range loop
9290 -- if q(J).S /=null_task_entry then
9291 -- selective_wait (simple_mode,...);
9297 -- if no rendez_vous then
9298 -- raise program_error;
9301 -- Note that the code needs to know that the selector name
9302 -- in an Accept_Alternative is named S.
9304 Cond := Make_Op_Ne (Loc,
9306 Make_Selected_Component (Loc,
9308 Make_Indexed_Component (Loc,
9309 Prefix => New_Reference_To (Qnam, Loc),
9310 Expressions => New_List (New_Reference_To (J, Loc))),
9311 Selector_Name => Make_Identifier (Loc, Name_S)),
9313 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9316 Make_Implicit_Loop_Statement (N,
9317 Identifier => Empty,
9319 Make_Iteration_Scheme (Loc,
9320 Loop_Parameter_Specification =>
9321 Make_Loop_Parameter_Specification (Loc,
9322 Defining_Identifier => J,
9323 Discrete_Subtype_Definition =>
9324 Make_Attribute_Reference (Loc,
9325 Prefix => New_Reference_To (Qnam, Loc),
9326 Attribute_Name => Name_Range,
9327 Expressions => New_List (
9328 Make_Integer_Literal (Loc, 1))))),
9330 Statements => New_List (
9331 Make_Implicit_If_Statement (N,
9333 Then_Statements => New_List (
9335 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9336 Make_Exit_Statement (Loc))))));
9339 Make_Raise_Program_Error (Loc,
9340 Condition => Make_Op_Eq (Loc,
9341 Left_Opnd => New_Reference_To (Xnam, Loc),
9343 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9344 Reason => PE_All_Guards_Closed));
9347 end Accept_Or_Raise;
9353 procedure Add_Accept (Alt : Node_Id) is
9354 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9355 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9356 Eloc : constant Source_Ptr := Sloc (Ename);
9357 Eent : constant Entity_Id := Entity (Ename);
9358 Index : constant Node_Id := Entry_Index (Acc_Stm);
9359 Null_Body : Node_Id;
9360 Proc_Body : Node_Id;
9367 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9370 if Present (Condition (Alt)) then
9372 Make_Conditional_Expression (Eloc, New_List (
9374 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9375 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9378 Entry_Index_Expression
9379 (Eloc, Eent, Index, Scope (Eent));
9382 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9383 Null_Body := New_Reference_To (Standard_False, Eloc);
9385 if Abort_Allowed then
9386 Call := Make_Procedure_Call_Statement (Eloc,
9387 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9388 Insert_Before (First (Statements (Handled_Statement_Sequence (
9389 Accept_Statement (Alt)))), Call);
9394 Make_Defining_Identifier (Eloc,
9395 New_External_Name (Chars (Ename), 'A', Num_Accept));
9397 if Comes_From_Source (Alt) then
9398 Set_Debug_Info_Needed (PB_Ent);
9402 Make_Subprogram_Body (Eloc,
9404 Make_Procedure_Specification (Eloc,
9405 Defining_Unit_Name => PB_Ent),
9406 Declarations => Declarations (Acc_Stm),
9407 Handled_Statement_Sequence =>
9408 Build_Accept_Body (Accept_Statement (Alt)));
9410 -- During the analysis of the body of the accept statement, any
9411 -- zero cost exception handler records were collected in the
9412 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9413 -- This is where we move them to where they belong, namely the
9414 -- newly created procedure.
9416 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9417 Append (Proc_Body, Body_List);
9420 Null_Body := New_Reference_To (Standard_True, Eloc);
9422 -- if accept statement has declarations, insert above, given that
9423 -- we are not creating a body for the accept.
9425 if Present (Declarations (Acc_Stm)) then
9426 Insert_Actions (N, Declarations (Acc_Stm));
9430 Append_To (Accept_List,
9431 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9433 Num_Accept := Num_Accept + 1;
9436 ----------------------------
9437 -- Make_And_Declare_Label --
9438 ----------------------------
9440 function Make_And_Declare_Label (Num : Int) return Node_Id is
9444 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9446 Make_Label (Loc, Lab_Id);
9449 Make_Implicit_Label_Declaration (Loc,
9450 Defining_Identifier =>
9451 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9452 Label_Construct => Lab));
9455 end Make_And_Declare_Label;
9457 ----------------------
9458 -- Make_Select_Call --
9459 ----------------------
9461 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9462 Params : constant List_Id := New_List;
9466 Make_Attribute_Reference (Loc,
9467 Prefix => New_Reference_To (Qnam, Loc),
9468 Attribute_Name => Name_Unchecked_Access),
9470 Append (Select_Mode, Params);
9471 Append (New_Reference_To (Ann, Loc), Params);
9472 Append (New_Reference_To (Xnam, Loc), Params);
9475 Make_Procedure_Call_Statement (Loc,
9476 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9477 Parameter_Associations => Params);
9478 end Make_Select_Call;
9480 --------------------------------
9481 -- Process_Accept_Alternative --
9482 --------------------------------
9484 procedure Process_Accept_Alternative
9489 Choices : List_Id := No_List;
9490 Alt_Stats : List_Id;
9493 Adjust_Condition (Condition (Alt));
9494 Alt_Stats := No_List;
9496 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9497 Choices := New_List (
9498 Make_Integer_Literal (Loc, Index));
9500 Alt_Stats := New_List (
9501 Make_Procedure_Call_Statement (Sloc (Proc),
9502 Name => New_Reference_To (
9503 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9506 if Statements (Alt) /= Empty_List then
9508 if No (Alt_Stats) then
9510 -- Accept with no body, followed by trailing statements
9512 Choices := New_List (
9513 Make_Integer_Literal (Loc, Index));
9515 Alt_Stats := New_List;
9518 -- After the call, if any, branch to trailing statements. We
9519 -- create a label for each, as well as the corresponding label
9522 Lab := Make_And_Declare_Label (Index);
9523 Append_To (Alt_Stats,
9524 Make_Goto_Statement (Loc,
9525 Name => New_Copy (Identifier (Lab))));
9527 Append (Lab, Trailing_List);
9528 Append_List (Statements (Alt), Trailing_List);
9529 Append_To (Trailing_List,
9530 Make_Goto_Statement (Loc,
9531 Name => New_Copy (Identifier (End_Lab))));
9534 if Present (Alt_Stats) then
9536 -- Procedure call. and/or trailing statements
9538 Append_To (Alt_List,
9539 Make_Case_Statement_Alternative (Loc,
9540 Discrete_Choices => Choices,
9541 Statements => Alt_Stats));
9543 end Process_Accept_Alternative;
9545 -------------------------------
9546 -- Process_Delay_Alternative --
9547 -------------------------------
9549 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9552 Delay_Alt : List_Id;
9555 -- Deal with C/Fortran boolean as delay condition
9557 Adjust_Condition (Condition (Alt));
9559 -- Determine the smallest specified delay
9561 -- for each delay alternative generate:
9563 -- if guard-expression then
9564 -- Delay_Val := delay-expression;
9565 -- Guard_Open := True;
9566 -- if Delay_Val < Delay_Min then
9567 -- Delay_Min := Delay_Val;
9568 -- Delay_Index := Index;
9572 -- The enclosing if-statement is omitted if there is no guard
9577 First_Delay := False;
9579 Delay_Alt := New_List (
9580 Make_Assignment_Statement (Loc,
9581 Name => New_Reference_To (Delay_Min, Loc),
9582 Expression => Expression (Delay_Statement (Alt))));
9584 if Delay_Count > 1 then
9585 Append_To (Delay_Alt,
9586 Make_Assignment_Statement (Loc,
9587 Name => New_Reference_To (Delay_Index, Loc),
9588 Expression => Make_Integer_Literal (Loc, Index)));
9592 Delay_Alt := New_List (
9593 Make_Assignment_Statement (Loc,
9594 Name => New_Reference_To (Delay_Val, Loc),
9595 Expression => Expression (Delay_Statement (Alt))));
9597 if Time_Type = Standard_Duration then
9600 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9601 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9604 -- The scope of the time type must define a comparison
9605 -- operator. The scope itself may not be visible, so we
9606 -- construct a node with entity information to insure that
9607 -- semantic analysis can find the proper operator.
9610 Make_Function_Call (Loc,
9611 Name => Make_Selected_Component (Loc,
9612 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9614 Make_Operator_Symbol (Loc,
9615 Chars => Name_Op_Lt,
9616 Strval => No_String)),
9617 Parameter_Associations =>
9619 New_Reference_To (Delay_Val, Loc),
9620 New_Reference_To (Delay_Min, Loc)));
9622 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9625 Append_To (Delay_Alt,
9626 Make_Implicit_If_Statement (N,
9628 Then_Statements => New_List (
9629 Make_Assignment_Statement (Loc,
9630 Name => New_Reference_To (Delay_Min, Loc),
9631 Expression => New_Reference_To (Delay_Val, Loc)),
9633 Make_Assignment_Statement (Loc,
9634 Name => New_Reference_To (Delay_Index, Loc),
9635 Expression => Make_Integer_Literal (Loc, Index)))));
9639 Append_To (Delay_Alt,
9640 Make_Assignment_Statement (Loc,
9641 Name => New_Reference_To (Guard_Open, Loc),
9642 Expression => New_Reference_To (Standard_True, Loc)));
9645 if Present (Condition (Alt)) then
9646 Delay_Alt := New_List (
9647 Make_Implicit_If_Statement (N,
9648 Condition => Condition (Alt),
9649 Then_Statements => Delay_Alt));
9652 Append_List (Delay_Alt, Delay_List);
9654 -- If the delay alternative has a statement part, add choice to the
9655 -- case statements for delays.
9657 if Present (Statements (Alt)) then
9659 if Delay_Count = 1 then
9660 Append_List (Statements (Alt), Delay_Alt_List);
9663 Choices := New_List (
9664 Make_Integer_Literal (Loc, Index));
9666 Append_To (Delay_Alt_List,
9667 Make_Case_Statement_Alternative (Loc,
9668 Discrete_Choices => Choices,
9669 Statements => Statements (Alt)));
9672 elsif Delay_Count = 1 then
9674 -- If the single delay has no trailing statements, add a branch
9675 -- to the exit label to the selective wait.
9677 Delay_Alt_List := New_List (
9678 Make_Goto_Statement (Loc,
9679 Name => New_Copy (Identifier (End_Lab))));
9682 end Process_Delay_Alternative;
9684 -- Start of processing for Expand_N_Selective_Accept
9687 Process_Statements_For_Controlled_Objects (N);
9689 -- First insert some declarations before the select. The first is:
9693 -- This variable holds the parameters passed to the accept body. This
9694 -- declaration has already been inserted by the time we get here by
9695 -- a call to Expand_Accept_Declarations made from the semantics when
9696 -- processing the first accept statement contained in the select. We
9697 -- can find this entity as Accept_Address (E), where E is any of the
9698 -- entries references by contained accept statements.
9700 -- The first step is to scan the list of Selective_Accept_Statements
9701 -- to find this entity, and also count the number of accepts, and
9702 -- determine if terminated, delay or else is present:
9706 Alt := First (Alts);
9707 while Present (Alt) loop
9708 Process_Statements_For_Controlled_Objects (Alt);
9710 if Nkind (Alt) = N_Accept_Alternative then
9713 elsif Nkind (Alt) = N_Delay_Alternative then
9714 Delay_Count := Delay_Count + 1;
9716 -- If the delays are relative delays, the delay expressions have
9717 -- type Standard_Duration. Otherwise they must have some time type
9718 -- recognized by GNAT.
9720 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9721 Time_Type := Standard_Duration;
9723 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9725 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9726 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9731 "& is not a time type (RM 9.6(6))",
9732 Expression (Delay_Statement (Alt)), Time_Type);
9733 Time_Type := Standard_Duration;
9734 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9738 if No (Condition (Alt)) then
9740 -- This guard will always be open
9742 Check_Guard := False;
9745 elsif Nkind (Alt) = N_Terminate_Alternative then
9746 Adjust_Condition (Condition (Alt));
9747 Terminate_Alt := Alt;
9750 Num_Alts := Num_Alts + 1;
9754 Else_Present := Present (Else_Statements (N));
9756 -- At the same time (see procedure Add_Accept) we build the accept list:
9758 -- Qnn : Accept_List (1 .. num-select) := (
9759 -- (null-body, entry-index),
9760 -- (null-body, entry-index),
9762 -- (null_body, entry-index));
9764 -- In the above declaration, null-body is True if the corresponding
9765 -- accept has no body, and false otherwise. The entry is either the
9766 -- entry index expression if there is no guard, or if a guard is
9767 -- present, then a conditional expression of the form:
9769 -- (if guard then entry-index else Null_Task_Entry)
9771 -- If a guard is statically known to be false, the entry can simply
9772 -- be omitted from the accept list.
9775 Make_Object_Declaration (Loc,
9776 Defining_Identifier => Qnam,
9777 Object_Definition =>
9778 New_Reference_To (RTE (RE_Accept_List), Loc),
9779 Aliased_Present => True,
9782 Make_Qualified_Expression (Loc,
9784 New_Reference_To (RTE (RE_Accept_List), Loc),
9786 Make_Aggregate (Loc, Expressions => Accept_List)));
9790 -- Then we declare the variable that holds the index for the accept
9791 -- that will be selected for service:
9793 -- Xnn : Select_Index;
9796 Make_Object_Declaration (Loc,
9797 Defining_Identifier => Xnam,
9798 Object_Definition =>
9799 New_Reference_To (RTE (RE_Select_Index), Loc),
9801 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9805 -- After this follow procedure declarations for each accept body
9812 -- where the ... are statements from the corresponding procedure body.
9813 -- No parameters are involved, since the parameters are passed via Ann
9814 -- and the parameter references have already been expanded to be direct
9815 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9816 -- any embedded tasking statements (which would normally be illegal in
9817 -- procedures), have been converted to calls to the tasking runtime so
9818 -- there is no problem in putting them into procedures.
9820 -- The original accept statement has been expanded into a block in
9821 -- the same fashion as for simple accepts (see Build_Accept_Body).
9823 -- Note: we don't really need to build these procedures for the case
9824 -- where no delay statement is present, but it is just as easy to
9825 -- build them unconditionally, and not significantly inefficient,
9826 -- since if they are short they will be inlined anyway.
9828 -- The procedure declarations have been assembled in Body_List
9830 -- If delays are present, we must compute the required delay.
9831 -- We first generate the declarations:
9833 -- Delay_Index : Boolean := 0;
9834 -- Delay_Min : Some_Time_Type.Time;
9835 -- Delay_Val : Some_Time_Type.Time;
9837 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9838 -- active delay that is actually chosen as the basis for the possible
9839 -- delay if an immediate rendez-vous is not possible.
9841 -- In the most common case there is a single delay statement, and this
9842 -- is handled specially.
9844 if Delay_Count > 0 then
9846 -- Generate the required declarations
9849 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9851 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9853 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9856 Make_Object_Declaration (Loc,
9857 Defining_Identifier => Delay_Val,
9858 Object_Definition => New_Reference_To (Time_Type, Loc)));
9861 Make_Object_Declaration (Loc,
9862 Defining_Identifier => Delay_Index,
9863 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9864 Expression => Make_Integer_Literal (Loc, 0)));
9867 Make_Object_Declaration (Loc,
9868 Defining_Identifier => Delay_Min,
9869 Object_Definition => New_Reference_To (Time_Type, Loc),
9871 Unchecked_Convert_To (Time_Type,
9872 Make_Attribute_Reference (Loc,
9874 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9875 Attribute_Name => Name_Last))));
9877 -- Create Duration and Delay_Mode objects used for passing a delay
9880 D := Make_Temporary (Loc, 'D');
9881 M := Make_Temporary (Loc, 'M');
9887 -- Note that these values are defined in s-osprim.ads and must
9890 -- Relative : constant := 0;
9891 -- Absolute_Calendar : constant := 1;
9892 -- Absolute_RT : constant := 2;
9894 if Time_Type = Standard_Duration then
9895 Discr := Make_Integer_Literal (Loc, 0);
9897 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9898 Discr := Make_Integer_Literal (Loc, 1);
9902 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9903 Discr := Make_Integer_Literal (Loc, 2);
9907 Make_Object_Declaration (Loc,
9908 Defining_Identifier => D,
9909 Object_Definition =>
9910 New_Reference_To (Standard_Duration, Loc)));
9913 Make_Object_Declaration (Loc,
9914 Defining_Identifier => M,
9915 Object_Definition =>
9916 New_Reference_To (Standard_Integer, Loc),
9917 Expression => Discr));
9922 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9925 Make_Object_Declaration (Loc,
9926 Defining_Identifier => Guard_Open,
9927 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9928 Expression => New_Reference_To (Standard_False, Loc)));
9931 -- Delay_Count is zero, don't need M and D set (suppress warning)
9938 if Present (Terminate_Alt) then
9940 -- If the terminate alternative guard is False, use
9941 -- Simple_Mode; otherwise use Terminate_Mode.
9943 if Present (Condition (Terminate_Alt)) then
9944 Select_Mode := Make_Conditional_Expression (Loc,
9945 New_List (Condition (Terminate_Alt),
9946 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9947 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9949 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9952 elsif Else_Present or Delay_Count > 0 then
9953 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9956 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9959 Select_Call := Make_Select_Call (Select_Mode);
9960 Append (Select_Call, Stats);
9962 -- Now generate code to act on the result. There is an entry
9963 -- in this case for each accept statement with a non-null body,
9964 -- followed by a branch to the statements that follow the Accept.
9965 -- In the absence of delay alternatives, we generate:
9968 -- when No_Rendezvous => -- omitted if simple mode
9983 -- Lab0: Else_Statements;
9986 -- Lab1: Trailing_Statements1;
9989 -- Lab2: Trailing_Statements2;
9994 -- Generate label for common exit
9996 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9998 -- First entry is the default case, when no rendezvous is possible
10000 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
10002 if Else_Present then
10004 -- If no rendezvous is possible, the else part is executed
10006 Lab := Make_And_Declare_Label (0);
10007 Alt_Stats := New_List (
10008 Make_Goto_Statement (Loc,
10009 Name => New_Copy (Identifier (Lab))));
10011 Append (Lab, Trailing_List);
10012 Append_List (Else_Statements (N), Trailing_List);
10013 Append_To (Trailing_List,
10014 Make_Goto_Statement (Loc,
10015 Name => New_Copy (Identifier (End_Lab))));
10017 Alt_Stats := New_List (
10018 Make_Goto_Statement (Loc,
10019 Name => New_Copy (Identifier (End_Lab))));
10022 Append_To (Alt_List,
10023 Make_Case_Statement_Alternative (Loc,
10024 Discrete_Choices => Choices,
10025 Statements => Alt_Stats));
10027 -- We make use of the fact that Accept_Index is an integer type, and
10028 -- generate successive literals for entries for each accept. Only those
10029 -- for which there is a body or trailing statements get a case entry.
10031 Alt := First (Select_Alternatives (N));
10032 Proc := First (Body_List);
10033 while Present (Alt) loop
10035 if Nkind (Alt) = N_Accept_Alternative then
10036 Process_Accept_Alternative (Alt, Index, Proc);
10037 Index := Index + 1;
10040 (Handled_Statement_Sequence (Accept_Statement (Alt)))
10045 elsif Nkind (Alt) = N_Delay_Alternative then
10046 Process_Delay_Alternative (Alt, Delay_Num);
10047 Delay_Num := Delay_Num + 1;
10053 -- An others choice is always added to the main case, as well
10054 -- as the delay case (to satisfy the compiler).
10056 Append_To (Alt_List,
10057 Make_Case_Statement_Alternative (Loc,
10058 Discrete_Choices =>
10059 New_List (Make_Others_Choice (Loc)),
10061 New_List (Make_Goto_Statement (Loc,
10062 Name => New_Copy (Identifier (End_Lab))))));
10064 Accept_Case := New_List (
10065 Make_Case_Statement (Loc,
10066 Expression => New_Reference_To (Xnam, Loc),
10067 Alternatives => Alt_List));
10069 Append_List (Trailing_List, Accept_Case);
10070 Append (End_Lab, Accept_Case);
10071 Append_List (Body_List, Decls);
10073 -- Construct case statement for trailing statements of delay
10074 -- alternatives, if there are several of them.
10076 if Delay_Count > 1 then
10077 Append_To (Delay_Alt_List,
10078 Make_Case_Statement_Alternative (Loc,
10079 Discrete_Choices =>
10080 New_List (Make_Others_Choice (Loc)),
10082 New_List (Make_Null_Statement (Loc))));
10084 Delay_Case := New_List (
10085 Make_Case_Statement (Loc,
10086 Expression => New_Reference_To (Delay_Index, Loc),
10087 Alternatives => Delay_Alt_List));
10089 Delay_Case := Delay_Alt_List;
10092 -- If there are no delay alternatives, we append the case statement
10093 -- to the statement list.
10095 if Delay_Count = 0 then
10096 Append_List (Accept_Case, Stats);
10098 -- Delay alternatives present
10101 -- If delay alternatives are present we generate:
10103 -- find minimum delay.
10104 -- DX := minimum delay;
10105 -- M := <delay mode>;
10106 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10109 -- if X = No_Rendezvous then
10110 -- case statement for delay statements.
10112 -- case statement for accept alternatives.
10123 -- The type of the delay expression is known to be legal
10125 if Time_Type = Standard_Duration then
10126 Conv := New_Reference_To (Delay_Min, Loc);
10128 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10129 Conv := Make_Function_Call (Loc,
10130 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10131 New_List (New_Reference_To (Delay_Min, Loc)));
10135 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10137 Conv := Make_Function_Call (Loc,
10138 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10139 New_List (New_Reference_To (Delay_Min, Loc)));
10142 Stmt := Make_Assignment_Statement (Loc,
10143 Name => New_Reference_To (D, Loc),
10144 Expression => Conv);
10146 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10148 Parms := Parameter_Associations (Select_Call);
10149 Parm := First (Parms);
10151 while Present (Parm)
10152 and then Parm /= Select_Mode
10157 pragma Assert (Present (Parm));
10158 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10161 -- Prepare two new parameters of Duration and Delay_Mode type
10162 -- which represent the value and the mode of the minimum delay.
10165 Insert_After (Parm, New_Reference_To (M, Loc));
10166 Insert_After (Parm, New_Reference_To (D, Loc));
10168 -- Create a call to RTS
10170 Rewrite (Select_Call,
10171 Make_Procedure_Call_Statement (Loc,
10172 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10173 Parameter_Associations => Parms));
10175 -- This new call should follow the calculation of the minimum
10178 Insert_List_Before (Select_Call, Delay_List);
10180 if Check_Guard then
10182 Make_Implicit_If_Statement (N,
10183 Condition => New_Reference_To (Guard_Open, Loc),
10185 New_List (New_Copy_Tree (Stmt),
10186 New_Copy_Tree (Select_Call)),
10187 Else_Statements => Accept_Or_Raise);
10188 Rewrite (Select_Call, Stmt);
10190 Insert_Before (Select_Call, Stmt);
10194 Make_Implicit_If_Statement (N,
10195 Condition => Make_Op_Eq (Loc,
10196 Left_Opnd => New_Reference_To (Xnam, Loc),
10198 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10200 Then_Statements => Delay_Case,
10201 Else_Statements => Accept_Case);
10203 Append (Cases, Stats);
10207 -- Replace accept statement with appropriate block
10210 Make_Block_Statement (Loc,
10211 Declarations => Decls,
10212 Handled_Statement_Sequence =>
10213 Make_Handled_Sequence_Of_Statements (Loc,
10214 Statements => Stats));
10216 Rewrite (N, Block);
10219 -- Note: have to worry more about abort deferral in above code ???
10221 -- Final step is to unstack the Accept_Address entries for all accept
10222 -- statements appearing in accept alternatives in the select statement
10224 Alt := First (Alts);
10225 while Present (Alt) loop
10226 if Nkind (Alt) = N_Accept_Alternative then
10227 Remove_Last_Elmt (Accept_Address
10228 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10233 end Expand_N_Selective_Accept;
10235 --------------------------------------
10236 -- Expand_N_Single_Task_Declaration --
10237 --------------------------------------
10239 -- Single task declarations should never be present after semantic
10240 -- analysis, since we expect them to be replaced by a declaration of an
10241 -- anonymous task type, followed by a declaration of the task object. We
10242 -- include this routine to make sure that is happening!
10244 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10246 raise Program_Error;
10247 end Expand_N_Single_Task_Declaration;
10249 ------------------------
10250 -- Expand_N_Task_Body --
10251 ------------------------
10253 -- Given a task body
10255 -- task body tname is
10261 -- This expansion routine converts it into a procedure and sets the
10262 -- elaboration flag for the procedure to true, to represent the fact
10263 -- that the task body is now elaborated:
10265 -- procedure tnameB (_Task : access tnameV) is
10266 -- discriminal : dtype renames _Task.discriminant;
10268 -- procedure _clean is
10270 -- Abort_Defer.all;
10272 -- Abort_Undefer.all;
10277 -- Abort_Undefer.all;
10279 -- System.Task_Stages.Complete_Activation;
10287 -- In addition, if the task body is an activator, then a call to activate
10288 -- tasks is added at the start of the statements, before the call to
10289 -- Complete_Activation, and if in addition the task is a master then it
10290 -- must be established as a master. These calls are inserted and analyzed
10291 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10294 -- There is one discriminal declaration line generated for each
10295 -- discriminant that is present to provide an easy reference point for
10296 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10298 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10299 -- task body procedures have a profile (Arg : System.Address). That is
10300 -- needed because GNARLI has to use the same access-to-subprogram type
10301 -- for all task types. We depend here on knowing that in GNAT, passing
10302 -- an address argument by value is identical to passing a record value
10303 -- by access (in either case a single pointer is passed), so even though
10304 -- this procedure has the wrong profile. In fact it's all OK, since the
10305 -- callings sequence is identical.
10307 procedure Expand_N_Task_Body (N : Node_Id) is
10308 Loc : constant Source_Ptr := Sloc (N);
10309 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10313 Insert_Nod : Node_Id;
10314 -- Used to determine the proper location of wrapper body insertions
10317 -- Add renaming declarations for discriminals and a declaration for the
10318 -- entry family index (if applicable).
10320 Install_Private_Data_Declarations
10321 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10323 -- Add a call to Abort_Undefer at the very beginning of the task
10324 -- body since this body is called with abort still deferred.
10326 if Abort_Allowed then
10327 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10329 (First (Statements (Handled_Statement_Sequence (N))), Call);
10333 -- The statement part has already been protected with an at_end and
10334 -- cleanup actions. The call to Complete_Activation must be placed
10335 -- at the head of the sequence of statements of that block. The
10336 -- declarations have been merged in this sequence of statements but
10337 -- the first real statement is accessible from the First_Real_Statement
10338 -- field (which was set for exactly this purpose).
10340 if Restricted_Profile then
10341 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10343 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10347 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10351 Make_Subprogram_Body (Loc,
10352 Specification => Build_Task_Proc_Specification (Ttyp),
10353 Declarations => Declarations (N),
10354 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10356 -- If the task contains generic instantiations, cleanup actions are
10357 -- delayed until after instantiation. Transfer the activation chain to
10358 -- the subprogram, to insure that the activation call is properly
10359 -- generated. It the task body contains inner tasks, indicate that the
10360 -- subprogram is a task master.
10362 if Delay_Cleanups (Ttyp) then
10363 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10364 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10367 Rewrite (N, New_N);
10370 -- Set elaboration flag immediately after task body. If the body is a
10371 -- subunit, the flag is set in the declarative part containing the stub.
10373 if Nkind (Parent (N)) /= N_Subunit then
10375 Make_Assignment_Statement (Loc,
10377 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10378 Expression => New_Reference_To (Standard_True, Loc)));
10381 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10382 -- the task body. At this point all wrapper specs have been created,
10383 -- frozen and included in the dispatch table for the task type.
10385 if Ada_Version >= Ada_2005 then
10386 if Nkind (Parent (N)) = N_Subunit then
10387 Insert_Nod := Corresponding_Stub (Parent (N));
10392 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10394 end Expand_N_Task_Body;
10396 ------------------------------------
10397 -- Expand_N_Task_Type_Declaration --
10398 ------------------------------------
10400 -- We have several things to do. First we must create a Boolean flag used
10401 -- to mark if the body is elaborated yet. This variable gets set to True
10402 -- when the body of the task is elaborated (we can't rely on the normal
10403 -- ABE mechanism for the task body, since we need to pass an access to
10404 -- this elaboration boolean to the runtime routines).
10406 -- taskE : aliased Boolean := False;
10408 -- Next a variable is declared to hold the task stack size (either the
10409 -- default : Unspecified_Size, or a value that is set by a pragma
10410 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10411 -- the variable is initialized with this value:
10413 -- taskZ : Size_Type := Unspecified_Size;
10415 -- taskZ : Size_Type := Size_Type (size_expression);
10417 -- Note: No variable is needed to hold the task relative deadline since
10418 -- its value would never be static because the parameter is of a private
10419 -- type (Ada.Real_Time.Time_Span).
10421 -- Next we create a corresponding record type declaration used to represent
10422 -- values of this task. The general form of this type declaration is
10424 -- type taskV (discriminants) is record
10425 -- _Task_Id : Task_Id;
10426 -- entry_family : array (bounds) of Void;
10427 -- _Priority : Integer := priority_expression;
10428 -- _Size : Size_Type := Size_Type (size_expression);
10429 -- _Task_Info : Task_Info_Type := task_info_expression;
10430 -- _CPU : Integer := cpu_range_expression;
10433 -- The discriminants are present only if the corresponding task type has
10434 -- discriminants, and they exactly mirror the task type discriminants.
10436 -- The Id field is always present. It contains the Task_Id value, as set by
10437 -- the call to Create_Task. Note that although the task is limited, the
10438 -- task value record type is not limited, so there is no problem in passing
10439 -- this field as an out parameter to Create_Task.
10441 -- One entry_family component is present for each entry family in the task
10442 -- definition. The bounds correspond to the bounds of the entry family
10443 -- (which may depend on discriminants). The element type is void, since we
10444 -- only need the bounds information for determining the entry index. Note
10445 -- that the use of an anonymous array would normally be illegal in this
10446 -- context, but this is a parser check, and the semantics is quite prepared
10447 -- to handle such a case.
10449 -- The _Size field is present only if a Storage_Size pragma appears in the
10450 -- task definition. The expression captures the argument that was present
10451 -- in the pragma, and is used to override the task stack size otherwise
10452 -- associated with the task type.
10454 -- The _Priority field is present only if a Priority or Interrupt_Priority
10455 -- pragma appears in the task definition. The expression captures the
10456 -- argument that was present in the pragma, and is used to provide the Size
10457 -- parameter to the call to Create_Task.
10459 -- The _Task_Info field is present only if a Task_Info pragma appears in
10460 -- the task definition. The expression captures the argument that was
10461 -- present in the pragma, and is used to provide the Task_Image parameter
10462 -- to the call to Create_Task.
10464 -- The _CPU field is present only if a CPU pragma appears in the task
10465 -- definition. The expression captures the argument that was present in
10466 -- the pragma, and is used to provide the CPU parameter to the call to
10469 -- The _Relative_Deadline field is present only if a Relative_Deadline
10470 -- pragma appears in the task definition. The expression captures the
10471 -- argument that was present in the pragma, and is used to provide the
10472 -- Relative_Deadline parameter to the call to Create_Task.
10474 -- When a task is declared, an instance of the task value record is
10475 -- created. The elaboration of this declaration creates the correct bounds
10476 -- for the entry families, and also evaluates the size, priority, and
10477 -- task_Info expressions if needed. The initialization routine for the task
10478 -- type itself then calls Create_Task with appropriate parameters to
10479 -- initialize the value of the Task_Id field.
10481 -- Note: the address of this record is passed as the "Discriminants"
10482 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10483 -- body procedure, it does not matter that it does not quite match the
10484 -- GNARLI model of what is being passed (the record contains more than just
10485 -- the discriminants, but the discriminants can be found from the record
10488 -- The Entity_Id for this created record type is placed in the
10489 -- Corresponding_Record_Type field of the associated task type entity.
10491 -- Next we create a procedure specification for the task body procedure:
10493 -- procedure taskB (_Task : access taskV);
10495 -- Note that this must come after the record type declaration, since
10496 -- the spec refers to this type. It turns out that the initialization
10497 -- procedure for the value type references the task body spec, but that's
10498 -- fine, since it won't be generated till the freeze point for the type,
10499 -- which is certainly after the task body spec declaration.
10501 -- Finally, we set the task index value field of the entry attribute in
10502 -- the case of a simple entry.
10504 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10505 Loc : constant Source_Ptr := Sloc (N);
10506 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10507 Tasknm : constant Name_Id := Chars (Tasktyp);
10508 Taskdef : constant Node_Id := Task_Definition (N);
10510 Proc_Spec : Node_Id;
10511 Rec_Decl : Node_Id;
10512 Rec_Ent : Entity_Id;
10514 Elab_Decl : Node_Id;
10515 Size_Decl : Node_Id;
10516 Body_Decl : Node_Id;
10517 Task_Size : Node_Id;
10518 Ent_Stack : Entity_Id;
10519 Decl_Stack : Node_Id;
10522 -- If already expanded, nothing to do
10524 if Present (Corresponding_Record_Type (Tasktyp)) then
10528 -- Here we will do the expansion
10530 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10532 Rec_Ent := Defining_Identifier (Rec_Decl);
10533 Cdecls := Component_Items (Component_List
10534 (Type_Definition (Rec_Decl)));
10536 Qualify_Entity_Names (N);
10538 -- First create the elaboration variable
10541 Make_Object_Declaration (Loc,
10542 Defining_Identifier =>
10543 Make_Defining_Identifier (Sloc (Tasktyp),
10544 Chars => New_External_Name (Tasknm, 'E')),
10545 Aliased_Present => True,
10546 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10547 Expression => New_Reference_To (Standard_False, Loc));
10548 Insert_After (N, Elab_Decl);
10550 -- Next create the declaration of the size variable (tasknmZ)
10552 Set_Storage_Size_Variable (Tasktyp,
10553 Make_Defining_Identifier (Sloc (Tasktyp),
10554 Chars => New_External_Name (Tasknm, 'Z')));
10556 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
10557 Is_Static_Expression (Expression (First (
10558 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
10559 Taskdef, Name_Storage_Size)))))
10562 Make_Object_Declaration (Loc,
10563 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10564 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10566 Convert_To (RTE (RE_Size_Type),
10568 Expression (First (
10569 Pragma_Argument_Associations (
10570 Find_Task_Or_Protected_Pragma
10571 (Taskdef, Name_Storage_Size)))))));
10575 Make_Object_Declaration (Loc,
10576 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10577 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10578 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10581 Insert_After (Elab_Decl, Size_Decl);
10583 -- Next build the rest of the corresponding record declaration. This is
10584 -- done last, since the corresponding record initialization procedure
10585 -- will reference the previously created entities.
10587 -- Fill in the component declarations -- first the _Task_Id field
10590 Make_Component_Declaration (Loc,
10591 Defining_Identifier =>
10592 Make_Defining_Identifier (Loc, Name_uTask_Id),
10593 Component_Definition =>
10594 Make_Component_Definition (Loc,
10595 Aliased_Present => False,
10596 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10599 -- Declare static ATCB (that is, created by the expander) if we are
10600 -- using the Restricted run time.
10602 if Restricted_Profile then
10604 Make_Component_Declaration (Loc,
10605 Defining_Identifier =>
10606 Make_Defining_Identifier (Loc, Name_uATCB),
10608 Component_Definition =>
10609 Make_Component_Definition (Loc,
10610 Aliased_Present => True,
10611 Subtype_Indication => Make_Subtype_Indication (Loc,
10612 Subtype_Mark => New_Occurrence_Of
10613 (RTE (RE_Ada_Task_Control_Block), Loc),
10616 Make_Index_Or_Discriminant_Constraint (Loc,
10618 New_List (Make_Integer_Literal (Loc, 0)))))));
10622 -- Declare static stack (that is, created by the expander) if we are
10623 -- using the Restricted run time on a bare board configuration.
10625 if Restricted_Profile
10626 and then Preallocated_Stacks_On_Target
10628 -- First we need to extract the appropriate stack size
10630 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10632 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10634 Expr_N : constant Node_Id :=
10635 Expression (First (
10636 Pragma_Argument_Associations (
10637 Find_Task_Or_Protected_Pragma
10638 (Taskdef, Name_Storage_Size))));
10639 Etyp : constant Entity_Id := Etype (Expr_N);
10640 P : constant Node_Id := Parent (Expr_N);
10643 -- The stack is defined inside the corresponding record.
10644 -- Therefore if the size of the stack is set by means of
10645 -- a discriminant, we must reference the discriminant of the
10646 -- corresponding record type.
10648 if Nkind (Expr_N) in N_Has_Entity
10649 and then Present (Discriminal_Link (Entity (Expr_N)))
10653 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10655 Set_Parent (Task_Size, P);
10656 Set_Etype (Task_Size, Etyp);
10657 Set_Analyzed (Task_Size);
10660 Task_Size := Relocate_Node (Expr_N);
10666 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10669 Decl_Stack := Make_Component_Declaration (Loc,
10670 Defining_Identifier => Ent_Stack,
10672 Component_Definition =>
10673 Make_Component_Definition (Loc,
10674 Aliased_Present => True,
10675 Subtype_Indication => Make_Subtype_Indication (Loc,
10677 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10680 Make_Index_Or_Discriminant_Constraint (Loc,
10681 Constraints => New_List (Make_Range (Loc,
10682 Low_Bound => Make_Integer_Literal (Loc, 1),
10683 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10686 Append_To (Cdecls, Decl_Stack);
10688 -- The appropriate alignment for the stack is ensured by the run-time
10689 -- code in charge of task creation.
10693 -- Add components for entry families
10695 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10697 -- Add the _Priority component if a Priority pragma is present
10699 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10701 Prag : constant Node_Id :=
10702 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10706 Expr := First (Pragma_Argument_Associations (Prag));
10708 if Nkind (Expr) = N_Pragma_Argument_Association then
10709 Expr := Expression (Expr);
10712 Expr := New_Copy_Tree (Expr);
10714 -- Add conversion to proper type to do range check if required
10715 -- Note that for runtime units, we allow out of range interrupt
10716 -- priority values to be used in a priority pragma. This is for
10717 -- the benefit of some versions of System.Interrupts which use
10718 -- a special server task with maximum interrupt priority.
10720 if Pragma_Name (Prag) = Name_Priority
10721 and then not GNAT_Mode
10723 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10725 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10729 Make_Component_Declaration (Loc,
10730 Defining_Identifier =>
10731 Make_Defining_Identifier (Loc, Name_uPriority),
10732 Component_Definition =>
10733 Make_Component_Definition (Loc,
10734 Aliased_Present => False,
10735 Subtype_Indication => New_Reference_To (Standard_Integer,
10737 Expression => Expr));
10741 -- Add the _Task_Size component if a Storage_Size pragma is present
10743 if Present (Taskdef)
10744 and then Has_Storage_Size_Pragma (Taskdef)
10747 Make_Component_Declaration (Loc,
10748 Defining_Identifier =>
10749 Make_Defining_Identifier (Loc, Name_uSize),
10751 Component_Definition =>
10752 Make_Component_Definition (Loc,
10753 Aliased_Present => False,
10754 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10758 Convert_To (RTE (RE_Size_Type),
10760 Expression (First (
10761 Pragma_Argument_Associations (
10762 Find_Task_Or_Protected_Pragma
10763 (Taskdef, Name_Storage_Size))))))));
10766 -- Add the _Task_Info component if a Task_Info pragma is present
10768 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10770 Make_Component_Declaration (Loc,
10771 Defining_Identifier =>
10772 Make_Defining_Identifier (Loc, Name_uTask_Info),
10774 Component_Definition =>
10775 Make_Component_Definition (Loc,
10776 Aliased_Present => False,
10777 Subtype_Indication =>
10778 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10780 Expression => New_Copy (
10781 Expression (First (
10782 Pragma_Argument_Associations (
10783 Find_Task_Or_Protected_Pragma
10784 (Taskdef, Name_Task_Info)))))));
10787 -- Add the _CPU component if a CPU pragma is present
10789 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
10791 Make_Component_Declaration (Loc,
10792 Defining_Identifier =>
10793 Make_Defining_Identifier (Loc, Name_uCPU),
10795 Component_Definition =>
10796 Make_Component_Definition (Loc,
10797 Aliased_Present => False,
10798 Subtype_Indication =>
10799 New_Reference_To (RTE (RE_CPU_Range), Loc)),
10801 Expression => New_Copy (
10802 Expression (First (
10803 Pragma_Argument_Associations (
10804 Find_Task_Or_Protected_Pragma
10805 (Taskdef, Name_CPU)))))));
10808 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10809 -- present. If we are using a restricted run time this component will
10810 -- not be added (deadlines are not allowed by the Ravenscar profile).
10812 if not Restricted_Profile
10813 and then Present (Taskdef)
10814 and then Has_Relative_Deadline_Pragma (Taskdef)
10817 Make_Component_Declaration (Loc,
10818 Defining_Identifier =>
10819 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10821 Component_Definition =>
10822 Make_Component_Definition (Loc,
10823 Aliased_Present => False,
10824 Subtype_Indication =>
10825 New_Reference_To (RTE (RE_Time_Span), Loc)),
10828 Convert_To (RTE (RE_Time_Span),
10830 Expression (First (
10831 Pragma_Argument_Associations (
10832 Find_Task_Or_Protected_Pragma
10833 (Taskdef, Name_Relative_Deadline))))))));
10836 Insert_After (Size_Decl, Rec_Decl);
10838 -- Analyze the record declaration immediately after construction,
10839 -- because the initialization procedure is needed for single task
10840 -- declarations before the next entity is analyzed.
10842 Analyze (Rec_Decl);
10844 -- Create the declaration of the task body procedure
10846 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10848 Make_Subprogram_Declaration (Loc,
10849 Specification => Proc_Spec);
10851 Insert_After (Rec_Decl, Body_Decl);
10853 -- The subprogram does not comes from source, so we have to indicate the
10854 -- need for debugging information explicitly.
10856 if Comes_From_Source (Original_Node (N)) then
10857 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10860 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10861 -- the corresponding record has been frozen.
10863 if Ada_Version >= Ada_2005 then
10864 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10867 -- Ada 2005 (AI-345): We must defer freezing to allow further
10868 -- declaration of primitive subprograms covering task interfaces
10870 if Ada_Version <= Ada_95 then
10872 -- Now we can freeze the corresponding record. This needs manually
10873 -- freezing, since it is really part of the task type, and the task
10874 -- type is frozen at this stage. We of course need the initialization
10875 -- procedure for this corresponding record type and we won't get it
10876 -- in time if we don't freeze now.
10879 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
10881 if Is_Non_Empty_List (L) then
10882 Insert_List_After (Body_Decl, L);
10887 -- Complete the expansion of access types to the current task type, if
10888 -- any were declared.
10890 Expand_Previous_Access_Type (Tasktyp);
10892 -- Create wrappers for entries that have pre/postconditions
10898 Ent := First_Entity (Tasktyp);
10899 while Present (Ent) loop
10900 if Ekind_In (Ent, E_Entry, E_Entry_Family)
10901 and then Present (Spec_PPC_List (Contract (Ent)))
10903 Build_PPC_Wrapper (Ent, N);
10909 end Expand_N_Task_Type_Declaration;
10911 -------------------------------
10912 -- Expand_N_Timed_Entry_Call --
10913 -------------------------------
10915 -- A timed entry call in normal case is not implemented using ATC mechanism
10916 -- anymore for efficiency reason.
10926 -- is expanded as follow:
10928 -- 1) When T.E is a task entry_call;
10932 -- X : Task_Entry_Index := <entry index>;
10933 -- DX : Duration := To_Duration (D);
10934 -- M : Delay_Mode := <discriminant>;
10935 -- P : parms := (parm, parm, parm);
10938 -- Timed_Protected_Entry_Call
10939 -- (<acceptor-task>, X, P'Address, DX, M, B);
10947 -- 2) When T.E is a protected entry_call;
10951 -- X : Protected_Entry_Index := <entry index>;
10952 -- DX : Duration := To_Duration (D);
10953 -- M : Delay_Mode := <discriminant>;
10954 -- P : parms := (parm, parm, parm);
10957 -- Timed_Protected_Entry_Call
10958 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10966 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10969 -- B : Boolean := False;
10970 -- C : Ada.Tags.Prim_Op_Kind;
10971 -- DX : Duration := To_Duration (D)
10972 -- K : Ada.Tags.Tagged_Kind :=
10973 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10974 -- M : Integer :=...;
10975 -- P : Parameters := (Param1 .. ParamN);
10979 -- if K = Ada.Tags.TK_Limited_Tagged then
10980 -- <dispatching-call>;
10981 -- <triggering-statements>
10985 -- Ada.Tags.Get_Offset_Index
10986 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10988 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10990 -- if C = POK_Protected_Entry
10991 -- or else C = POK_Task_Entry
10993 -- Param1 := P.Param1;
10995 -- ParamN := P.ParamN;
10999 -- if C = POK_Procedure
11000 -- or else C = POK_Protected_Procedure
11001 -- or else C = POK_Task_Procedure
11003 -- <dispatching-call>;
11006 -- <triggering-statements>
11008 -- <timed-statements>
11013 -- The triggering statement and the sequence of timed statements have not
11014 -- been analyzed yet (see Analyzed_Timed_Entry_Call). They may contain
11015 -- local declarations, and therefore the copies that are made during
11016 -- expansion must be disjoint, as for any other inlining.
11018 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
11019 Loc : constant Source_Ptr := Sloc (N);
11021 E_Call : Node_Id :=
11022 Entry_Call_Statement (Entry_Call_Alternative (N));
11023 E_Stats : constant List_Id :=
11024 Statements (Entry_Call_Alternative (N));
11025 D_Stat : Node_Id :=
11026 Delay_Statement (Delay_Alternative (N));
11027 D_Stats : constant List_Id :=
11028 Statements (Delay_Alternative (N));
11031 Blk_Typ : Entity_Id;
11033 Call_Ent : Entity_Id;
11034 Conc_Typ_Stmts : List_Id;
11038 D_Type : Entity_Id;
11044 Is_Disp_Select : Boolean;
11045 Lim_Typ_Stmts : List_Id;
11054 B : Entity_Id; -- Call status flag
11055 C : Entity_Id; -- Call kind
11056 D : Entity_Id; -- Delay
11057 K : Entity_Id; -- Tagged kind
11058 M : Entity_Id; -- Delay mode
11059 P : Entity_Id; -- Parameter block
11060 S : Entity_Id; -- Primitive operation slot
11063 -- Under the Ravenscar profile, timed entry calls are excluded. An error
11064 -- was already reported on spec, so do not attempt to expand the call.
11066 if Restriction_Active (No_Select_Statements) then
11070 Process_Statements_For_Controlled_Objects (Entry_Call_Alternative (N));
11071 Process_Statements_For_Controlled_Objects (Delay_Alternative (N));
11073 -- The arguments in the call may require dynamic allocation, and the
11074 -- call statement may have been transformed into a block. The block
11075 -- may contain additional declarations for internal entities, and the
11076 -- original call is found by sequential search.
11078 if Nkind (E_Call) = N_Block_Statement then
11079 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
11080 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
11081 N_Entry_Call_Statement)
11088 Ada_Version >= Ada_2005
11089 and then Nkind (E_Call) = N_Procedure_Call_Statement;
11091 if Is_Disp_Select then
11092 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11098 -- B : Boolean := False;
11100 B := Build_B (Loc, Decls);
11103 -- C : Ada.Tags.Prim_Op_Kind;
11105 C := Build_C (Loc, Decls);
11107 -- Because the analysis of all statements was disabled, manually
11108 -- analyze the delay statement.
11111 D_Stat := Original_Node (D_Stat);
11114 -- Build an entry call using Simple_Entry_Call
11116 Extract_Entry (E_Call, Concval, Ename, Index);
11117 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11119 Decls := Declarations (E_Call);
11120 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11129 B := Make_Defining_Identifier (Loc, Name_uB);
11132 Make_Object_Declaration (Loc,
11133 Defining_Identifier =>
11135 Object_Definition =>
11136 New_Reference_To (Standard_Boolean, Loc)));
11139 -- Duration and mode processing
11141 D_Type := Base_Type (Etype (Expression (D_Stat)));
11143 -- Use the type of the delay expression (Calendar or Real_Time) to
11144 -- generate the appropriate conversion.
11146 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11147 D_Disc := Make_Integer_Literal (Loc, 0);
11148 D_Conv := Relocate_Node (Expression (D_Stat));
11150 elsif Is_RTE (D_Type, RO_CA_Time) then
11151 D_Disc := Make_Integer_Literal (Loc, 1);
11152 D_Conv := Make_Function_Call (Loc,
11153 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11154 New_List (New_Copy (Expression (D_Stat))));
11156 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11157 D_Disc := Make_Integer_Literal (Loc, 2);
11158 D_Conv := Make_Function_Call (Loc,
11159 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11160 New_List (New_Copy (Expression (D_Stat))));
11163 D := Make_Temporary (Loc, 'D');
11169 Make_Object_Declaration (Loc,
11170 Defining_Identifier =>
11172 Object_Definition =>
11173 New_Reference_To (Standard_Duration, Loc)));
11175 M := Make_Temporary (Loc, 'M');
11178 -- M : Integer := (0 | 1 | 2);
11181 Make_Object_Declaration (Loc,
11182 Defining_Identifier =>
11184 Object_Definition =>
11185 New_Reference_To (Standard_Integer, Loc),
11189 -- Do the assignment at this stage only because the evaluation of the
11190 -- expression must not occur before (see ACVC C97302A).
11193 Make_Assignment_Statement (Loc,
11195 New_Reference_To (D, Loc),
11199 -- Parameter block processing
11201 -- Manually create the parameter block for dispatching calls. In the
11202 -- case of entries, the block has already been created during the call
11203 -- to Build_Simple_Entry_Call.
11205 if Is_Disp_Select then
11207 -- Tagged kind processing, generate:
11208 -- K : Ada.Tags.Tagged_Kind :=
11209 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11211 K := Build_K (Loc, Decls, Obj);
11213 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11214 P := Parameter_Block_Pack
11215 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11217 -- Dispatch table slot processing, generate:
11220 S := Build_S (Loc, Decls);
11223 -- S := Ada.Tags.Get_Offset_Index
11224 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11227 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11230 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11232 -- where Obj is the controlling formal parameter, S is the dispatch
11233 -- table slot number of the dispatching operation, P is the wrapped
11234 -- parameter block, D is the duration, M is the duration mode, C is
11235 -- the call kind and B is the call status.
11237 Params := New_List;
11239 Append_To (Params, New_Copy_Tree (Obj));
11240 Append_To (Params, New_Reference_To (S, Loc));
11241 Append_To (Params, Make_Attribute_Reference (Loc,
11242 Prefix => New_Reference_To (P, Loc),
11243 Attribute_Name => Name_Address));
11244 Append_To (Params, New_Reference_To (D, Loc));
11245 Append_To (Params, New_Reference_To (M, Loc));
11246 Append_To (Params, New_Reference_To (C, Loc));
11247 Append_To (Params, New_Reference_To (B, Loc));
11249 Append_To (Conc_Typ_Stmts,
11250 Make_Procedure_Call_Statement (Loc,
11253 Find_Prim_Op (Etype (Etype (Obj)),
11254 Name_uDisp_Timed_Select),
11256 Parameter_Associations =>
11260 -- if C = POK_Protected_Entry
11261 -- or else C = POK_Task_Entry
11263 -- Param1 := P.Param1;
11265 -- ParamN := P.ParamN;
11268 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11270 -- Generate the if statement only when the packed parameters need
11271 -- explicit assignments to their corresponding actuals.
11273 if Present (Unpack) then
11274 Append_To (Conc_Typ_Stmts,
11275 Make_If_Statement (Loc,
11282 New_Reference_To (C, Loc),
11284 New_Reference_To (RTE (
11285 RE_POK_Protected_Entry), Loc)),
11289 New_Reference_To (C, Loc),
11291 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11300 -- if C = POK_Procedure
11301 -- or else C = POK_Protected_Procedure
11302 -- or else C = POK_Task_Procedure
11304 -- <dispatching-call>
11306 -- <triggering-statements>
11308 -- <timed-statements>
11311 N_Stats := Copy_Separate_List (E_Stats);
11313 Prepend_To (N_Stats,
11314 Make_If_Statement (Loc,
11321 New_Reference_To (C, Loc),
11323 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11329 New_Reference_To (C, Loc),
11331 New_Reference_To (RTE (
11332 RE_POK_Protected_Procedure), Loc)),
11336 New_Reference_To (C, Loc),
11338 New_Reference_To (RTE (
11339 RE_POK_Task_Procedure), Loc)))),
11342 New_List (E_Call)));
11344 Append_To (Conc_Typ_Stmts,
11345 Make_If_Statement (Loc,
11346 Condition => New_Reference_To (B, Loc),
11347 Then_Statements => N_Stats,
11348 Else_Statements => D_Stats));
11351 -- <dispatching-call>;
11352 -- <triggering-statements>
11354 Lim_Typ_Stmts := Copy_Separate_List (E_Stats);
11355 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11358 -- if K = Ada.Tags.TK_Limited_Tagged then
11365 Make_If_Statement (Loc,
11369 New_Reference_To (K, Loc),
11371 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11380 -- Skip assignments to temporaries created for in-out parameters.
11381 -- This makes unwarranted assumptions about the shape of the expanded
11382 -- tree for the call, and should be cleaned up ???
11384 Stmt := First (Stmts);
11385 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11389 -- Do the assignment at this stage only because the evaluation
11390 -- of the expression must not occur before (see ACVC C97302A).
11392 Insert_Before (Stmt,
11393 Make_Assignment_Statement (Loc,
11394 Name => New_Reference_To (D, Loc),
11395 Expression => D_Conv));
11398 Params := Parameter_Associations (Call);
11400 -- For a protected type, we build a Timed_Protected_Entry_Call
11402 if Is_Protected_Type (Etype (Concval)) then
11404 -- Create a new call statement
11406 Param := First (Params);
11407 while Present (Param)
11408 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11413 Dummy := Remove_Next (Next (Param));
11415 -- Remove garbage is following the Cancel_Param if present
11417 Dummy := Next (Param);
11419 -- Remove the mode of the Protected_Entry_Call call, then remove
11420 -- the Communication_Block of the Protected_Entry_Call call, and
11421 -- finally add Duration and a Delay_Mode parameter
11423 pragma Assert (Present (Param));
11424 Rewrite (Param, New_Reference_To (D, Loc));
11426 Rewrite (Dummy, New_Reference_To (M, Loc));
11428 -- Add a Boolean flag for successful entry call
11430 Append_To (Params, New_Reference_To (B, Loc));
11432 case Corresponding_Runtime_Package (Etype (Concval)) is
11433 when System_Tasking_Protected_Objects_Entries =>
11435 Make_Procedure_Call_Statement (Loc,
11438 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11439 Parameter_Associations => Params));
11441 when System_Tasking_Protected_Objects_Single_Entry =>
11442 Param := First (Params);
11443 while Present (Param)
11445 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11453 Make_Procedure_Call_Statement (Loc,
11454 Name => New_Reference_To (
11455 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11456 Parameter_Associations => Params));
11459 raise Program_Error;
11462 -- For the task case, build a Timed_Task_Entry_Call
11465 -- Create a new call statement
11467 Append_To (Params, New_Reference_To (D, Loc));
11468 Append_To (Params, New_Reference_To (M, Loc));
11469 Append_To (Params, New_Reference_To (B, Loc));
11472 Make_Procedure_Call_Statement (Loc,
11474 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11475 Parameter_Associations => Params));
11479 Make_Implicit_If_Statement (N,
11480 Condition => New_Reference_To (B, Loc),
11481 Then_Statements => E_Stats,
11482 Else_Statements => D_Stats));
11486 Make_Block_Statement (Loc,
11487 Declarations => Decls,
11488 Handled_Statement_Sequence =>
11489 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11492 end Expand_N_Timed_Entry_Call;
11494 ----------------------------------------
11495 -- Expand_Protected_Body_Declarations --
11496 ----------------------------------------
11498 procedure Expand_Protected_Body_Declarations
11500 Spec_Id : Entity_Id)
11503 if No_Run_Time_Mode then
11504 Error_Msg_CRT ("protected body", N);
11507 elsif Full_Expander_Active then
11509 -- Associate discriminals with the first subprogram or entry body to
11512 if Present (First_Protected_Operation (Declarations (N))) then
11513 Set_Discriminals (Parent (Spec_Id));
11516 end Expand_Protected_Body_Declarations;
11518 -------------------------
11519 -- External_Subprogram --
11520 -------------------------
11522 function External_Subprogram (E : Entity_Id) return Entity_Id is
11523 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11526 -- The internal and external subprograms follow each other on the entity
11527 -- chain. Note that previously private operations had no separate
11528 -- external subprogram. We now create one in all cases, because a
11529 -- private operation may actually appear in an external call, through
11530 -- a 'Access reference used for a callback.
11532 -- If the operation is a function that returns an anonymous access type,
11533 -- the corresponding itype appears before the operation, and must be
11536 -- This mechanism is fragile, there should be a real link between the
11537 -- two versions of the operation, but there is no place to put it ???
11539 if Is_Access_Type (Next_Entity (Subp)) then
11540 return Next_Entity (Next_Entity (Subp));
11542 return Next_Entity (Subp);
11544 end External_Subprogram;
11546 ------------------------------
11547 -- Extract_Dispatching_Call --
11548 ------------------------------
11550 procedure Extract_Dispatching_Call
11552 Call_Ent : out Entity_Id;
11553 Object : out Entity_Id;
11554 Actuals : out List_Id;
11555 Formals : out List_Id)
11557 Call_Nam : Node_Id;
11560 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11562 if Present (Original_Node (N)) then
11563 Call_Nam := Name (Original_Node (N));
11565 Call_Nam := Name (N);
11568 -- Retrieve the name of the dispatching procedure. It contains the
11569 -- dispatch table slot number.
11572 case Nkind (Call_Nam) is
11573 when N_Identifier =>
11576 when N_Selected_Component =>
11577 Call_Nam := Selector_Name (Call_Nam);
11580 raise Program_Error;
11585 Actuals := Parameter_Associations (N);
11586 Call_Ent := Entity (Call_Nam);
11587 Formals := Parameter_Specifications (Parent (Call_Ent));
11588 Object := First (Actuals);
11590 if Present (Original_Node (Object)) then
11591 Object := Original_Node (Object);
11594 -- If the type of the dispatching object is an access type then return
11595 -- an explicit dereference.
11597 if Is_Access_Type (Etype (Object)) then
11598 Object := Make_Explicit_Dereference (Sloc (N), Object);
11601 end Extract_Dispatching_Call;
11603 -------------------
11604 -- Extract_Entry --
11605 -------------------
11607 procedure Extract_Entry
11609 Concval : out Node_Id;
11610 Ename : out Node_Id;
11611 Index : out Node_Id)
11613 Nam : constant Node_Id := Name (N);
11616 -- For a simple entry, the name is a selected component, with the
11617 -- prefix being the task value, and the selector being the entry.
11619 if Nkind (Nam) = N_Selected_Component then
11620 Concval := Prefix (Nam);
11621 Ename := Selector_Name (Nam);
11624 -- For a member of an entry family, the name is an indexed component
11625 -- where the prefix is a selected component, whose prefix in turn is
11626 -- the task value, and whose selector is the entry family. The single
11627 -- expression in the expressions list of the indexed component is the
11628 -- subscript for the family.
11630 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11631 Concval := Prefix (Prefix (Nam));
11632 Ename := Selector_Name (Prefix (Nam));
11633 Index := First (Expressions (Nam));
11637 -------------------
11638 -- Family_Offset --
11639 -------------------
11641 function Family_Offset
11646 Cap : Boolean) return Node_Id
11652 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11653 -- If one of the bounds is a reference to a discriminant, replace with
11654 -- corresponding discriminal of type. Within the body of a task retrieve
11655 -- the renamed discriminant by simple visibility, using its generated
11656 -- name. Within a protected object, find the original discriminant and
11657 -- replace it with the discriminal of the current protected operation.
11659 ------------------------------
11660 -- Convert_Discriminant_Ref --
11661 ------------------------------
11663 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11664 Loc : constant Source_Ptr := Sloc (Bound);
11669 if Is_Entity_Name (Bound)
11670 and then Ekind (Entity (Bound)) = E_Discriminant
11672 if Is_Task_Type (Ttyp)
11673 and then Has_Completion (Ttyp)
11675 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11676 Find_Direct_Name (B);
11678 elsif Is_Protected_Type (Ttyp) then
11679 D := First_Discriminant (Ttyp);
11680 while Chars (D) /= Chars (Entity (Bound)) loop
11681 Next_Discriminant (D);
11684 B := New_Reference_To (Discriminal (D), Loc);
11687 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11690 elsif Nkind (Bound) = N_Attribute_Reference then
11694 B := New_Copy_Tree (Bound);
11698 Make_Attribute_Reference (Loc,
11699 Attribute_Name => Name_Pos,
11700 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11701 Expressions => New_List (B));
11702 end Convert_Discriminant_Ref;
11704 -- Start of processing for Family_Offset
11707 Real_Hi := Convert_Discriminant_Ref (Hi);
11708 Real_Lo := Convert_Discriminant_Ref (Lo);
11711 if Is_Task_Type (Ttyp) then
11712 Ityp := RTE (RE_Task_Entry_Index);
11714 Ityp := RTE (RE_Protected_Entry_Index);
11718 Make_Attribute_Reference (Loc,
11719 Prefix => New_Reference_To (Ityp, Loc),
11720 Attribute_Name => Name_Min,
11721 Expressions => New_List (
11723 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11726 Make_Attribute_Reference (Loc,
11727 Prefix => New_Reference_To (Ityp, Loc),
11728 Attribute_Name => Name_Max,
11729 Expressions => New_List (
11731 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11734 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11741 function Family_Size
11746 Cap : Boolean) return Node_Id
11751 if Is_Task_Type (Ttyp) then
11752 Ityp := RTE (RE_Task_Entry_Index);
11754 Ityp := RTE (RE_Protected_Entry_Index);
11758 Make_Attribute_Reference (Loc,
11759 Prefix => New_Reference_To (Ityp, Loc),
11760 Attribute_Name => Name_Max,
11761 Expressions => New_List (
11764 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11766 Make_Integer_Literal (Loc, 1)),
11767 Make_Integer_Literal (Loc, 0)));
11770 -----------------------
11771 -- Find_Master_Scope --
11772 -----------------------
11774 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
11778 -- In Ada2005, the master is the innermost enclosing scope that is not
11779 -- transient. If the enclosing block is the rewriting of a call or the
11780 -- scope is an extended return statement this is valid master. The
11781 -- master in an extended return is only used within the return, and is
11782 -- subsequently overwritten in Move_Activation_Chain, but it must exist
11783 -- now before that overwriting occurs.
11787 if Ada_Version >= Ada_2005 then
11788 while Is_Internal (S) loop
11789 if Nkind (Parent (S)) = N_Block_Statement
11791 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
11795 elsif Ekind (S) = E_Return_Statement then
11805 end Find_Master_Scope;
11807 -----------------------------------
11808 -- Find_Task_Or_Protected_Pragma --
11809 -----------------------------------
11811 function Find_Task_Or_Protected_Pragma
11813 P : Name_Id) return Node_Id
11818 N := First (Visible_Declarations (T));
11819 while Present (N) loop
11820 if Nkind (N) = N_Pragma then
11821 if Pragma_Name (N) = P then
11824 elsif P = Name_Priority
11825 and then Pragma_Name (N) = Name_Interrupt_Priority
11838 N := First (Private_Declarations (T));
11839 while Present (N) loop
11840 if Nkind (N) = N_Pragma then
11841 if Pragma_Name (N) = P then
11844 elsif P = Name_Priority
11845 and then Pragma_Name (N) = Name_Interrupt_Priority
11858 raise Program_Error;
11859 end Find_Task_Or_Protected_Pragma;
11861 -------------------------------
11862 -- First_Protected_Operation --
11863 -------------------------------
11865 function First_Protected_Operation (D : List_Id) return Node_Id is
11866 First_Op : Node_Id;
11869 First_Op := First (D);
11870 while Present (First_Op)
11871 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11877 end First_Protected_Operation;
11879 ---------------------------------------
11880 -- Install_Private_Data_Declarations --
11881 ---------------------------------------
11883 procedure Install_Private_Data_Declarations
11885 Spec_Id : Entity_Id;
11886 Conc_Typ : Entity_Id;
11887 Body_Nod : Node_Id;
11889 Barrier : Boolean := False;
11890 Family : Boolean := False)
11892 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11895 Insert_Node : Node_Id := Empty;
11896 Obj_Ent : Entity_Id;
11898 procedure Add (Decl : Node_Id);
11899 -- Add a single declaration after Insert_Node. If this is the first
11900 -- addition, Decl is added to the front of Decls and it becomes the
11903 function Replace_Bound (Bound : Node_Id) return Node_Id;
11904 -- The bounds of an entry index may depend on discriminants, create a
11905 -- reference to the corresponding prival. Otherwise return a duplicate
11906 -- of the original bound.
11912 procedure Add (Decl : Node_Id) is
11914 if No (Insert_Node) then
11915 Prepend_To (Decls, Decl);
11917 Insert_After (Insert_Node, Decl);
11920 Insert_Node := Decl;
11923 --------------------------
11924 -- Replace_Discriminant --
11925 --------------------------
11927 function Replace_Bound (Bound : Node_Id) return Node_Id is
11929 if Nkind (Bound) = N_Identifier
11930 and then Is_Discriminal (Entity (Bound))
11932 return Make_Identifier (Loc, Chars (Entity (Bound)));
11934 return Duplicate_Subexpr (Bound);
11938 -- Start of processing for Install_Private_Data_Declarations
11941 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11942 -- formal parameter _O, _object or _task depending on the context.
11944 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11946 -- Special processing of _O for barrier functions, protected entries
11953 (Ekind (Spec_Id) = E_Entry
11954 or else Ekind (Spec_Id) = E_Entry_Family))
11957 Conc_Rec : constant Entity_Id :=
11958 Corresponding_Record_Type (Conc_Typ);
11959 Typ_Id : constant Entity_Id :=
11960 Make_Defining_Identifier (Loc,
11961 New_External_Name (Chars (Conc_Rec), 'P'));
11964 -- type prot_typVP is access prot_typV;
11967 Make_Full_Type_Declaration (Loc,
11968 Defining_Identifier => Typ_Id,
11970 Make_Access_To_Object_Definition (Loc,
11971 Subtype_Indication =>
11972 New_Reference_To (Conc_Rec, Loc)));
11976 -- _object : prot_typVP := prot_typV (_O);
11979 Make_Object_Declaration (Loc,
11980 Defining_Identifier =>
11981 Make_Defining_Identifier (Loc, Name_uObject),
11982 Object_Definition => New_Reference_To (Typ_Id, Loc),
11984 Unchecked_Convert_To (Typ_Id,
11985 New_Reference_To (Obj_Ent, Loc)));
11988 -- Set the reference to the concurrent object
11990 Obj_Ent := Defining_Identifier (Decl);
11994 -- Step 2: Create the Protection object and build its declaration for
11995 -- any protected entry (family) of subprogram.
11997 if Is_Protected then
11999 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
12003 Set_Protection_Object (Spec_Id, Prot_Ent);
12005 -- Determine the proper protection type
12007 if Has_Attach_Handler (Conc_Typ)
12008 and then not Restricted_Profile
12010 Prot_Typ := RE_Static_Interrupt_Protection;
12012 elsif Has_Interrupt_Handler (Conc_Typ) then
12013 Prot_Typ := RE_Dynamic_Interrupt_Protection;
12015 -- The type has explicit entries or generated primitive entry
12018 elsif Has_Entries (Conc_Typ)
12020 (Ada_Version >= Ada_2005
12021 and then Present (Interface_List (Parent (Conc_Typ))))
12023 case Corresponding_Runtime_Package (Conc_Typ) is
12024 when System_Tasking_Protected_Objects_Entries =>
12025 Prot_Typ := RE_Protection_Entries;
12027 when System_Tasking_Protected_Objects_Single_Entry =>
12028 Prot_Typ := RE_Protection_Entry;
12031 raise Program_Error;
12035 Prot_Typ := RE_Protection;
12039 -- conc_typR : protection_typ renames _object._object;
12042 Make_Object_Renaming_Declaration (Loc,
12043 Defining_Identifier => Prot_Ent,
12045 New_Reference_To (RTE (Prot_Typ), Loc),
12047 Make_Selected_Component (Loc,
12048 Prefix => New_Reference_To (Obj_Ent, Loc),
12049 Selector_Name => Make_Identifier (Loc, Name_uObject)));
12054 -- Step 3: Add discriminant renamings (if any)
12056 if Has_Discriminants (Conc_Typ) then
12061 D := First_Discriminant (Conc_Typ);
12062 while Present (D) loop
12064 -- Adjust the source location
12066 Set_Sloc (Discriminal (D), Loc);
12069 -- discr_name : discr_typ renames _object.discr_name;
12071 -- discr_name : discr_typ renames _task.discr_name;
12074 Make_Object_Renaming_Declaration (Loc,
12075 Defining_Identifier => Discriminal (D),
12076 Subtype_Mark => New_Reference_To (Etype (D), Loc),
12078 Make_Selected_Component (Loc,
12079 Prefix => New_Reference_To (Obj_Ent, Loc),
12080 Selector_Name => Make_Identifier (Loc, Chars (D))));
12083 Next_Discriminant (D);
12088 -- Step 4: Add private component renamings (if any)
12090 if Is_Protected then
12091 Def := Protected_Definition (Parent (Conc_Typ));
12093 if Present (Private_Declarations (Def)) then
12096 Comp_Id : Entity_Id;
12097 Decl_Id : Entity_Id;
12100 Comp := First (Private_Declarations (Def));
12101 while Present (Comp) loop
12102 if Nkind (Comp) = N_Component_Declaration then
12103 Comp_Id := Defining_Identifier (Comp);
12105 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12107 -- Minimal decoration
12109 if Ekind (Spec_Id) = E_Function then
12110 Set_Ekind (Decl_Id, E_Constant);
12112 Set_Ekind (Decl_Id, E_Variable);
12115 Set_Prival (Comp_Id, Decl_Id);
12116 Set_Prival_Link (Decl_Id, Comp_Id);
12117 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
12120 -- comp_name : comp_typ renames _object.comp_name;
12123 Make_Object_Renaming_Declaration (Loc,
12124 Defining_Identifier => Decl_Id,
12126 New_Reference_To (Etype (Comp_Id), Loc),
12128 Make_Selected_Component (Loc,
12130 New_Reference_To (Obj_Ent, Loc),
12132 Make_Identifier (Loc, Chars (Comp_Id))));
12142 -- Step 5: Add the declaration of the entry index and the associated
12143 -- type for barrier functions and entry families.
12145 if (Barrier and then Family)
12146 or else Ekind (Spec_Id) = E_Entry_Family
12149 E : constant Entity_Id := Index_Object (Spec_Id);
12150 Index : constant Entity_Id :=
12151 Defining_Identifier (
12152 Entry_Index_Specification (
12153 Entry_Body_Formal_Part (Body_Nod)));
12154 Index_Con : constant Entity_Id :=
12155 Make_Defining_Identifier (Loc, Chars (Index));
12157 Index_Typ : Entity_Id;
12161 -- Minimal decoration
12163 Set_Ekind (Index_Con, E_Constant);
12164 Set_Entry_Index_Constant (Index, Index_Con);
12165 Set_Discriminal_Link (Index_Con, Index);
12167 -- Retrieve the bounds of the entry family
12169 High := Type_High_Bound (Etype (Index));
12170 Low := Type_Low_Bound (Etype (Index));
12172 -- In the simple case the entry family is given by a subtype
12173 -- mark and the index constant has the same type.
12175 if Is_Entity_Name (Original_Node (
12176 Discrete_Subtype_Definition (Parent (Index))))
12178 Index_Typ := Etype (Index);
12180 -- Otherwise a new subtype declaration is required
12183 High := Replace_Bound (High);
12184 Low := Replace_Bound (Low);
12186 Index_Typ := Make_Temporary (Loc, 'J');
12189 -- subtype Jnn is <Etype of Index> range Low .. High;
12192 Make_Subtype_Declaration (Loc,
12193 Defining_Identifier => Index_Typ,
12194 Subtype_Indication =>
12195 Make_Subtype_Indication (Loc,
12197 New_Reference_To (Base_Type (Etype (Index)), Loc),
12199 Make_Range_Constraint (Loc,
12200 Range_Expression =>
12201 Make_Range (Loc, Low, High))));
12205 Set_Etype (Index_Con, Index_Typ);
12207 -- Create the object which designates the index:
12208 -- J : constant Jnn :=
12209 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12211 -- where Jnn is the subtype created above or the original type of
12212 -- the index, _E is a formal of the protected body subprogram and
12213 -- <index expr> is the index of the first family member.
12216 Make_Object_Declaration (Loc,
12217 Defining_Identifier => Index_Con,
12218 Constant_Present => True,
12219 Object_Definition =>
12220 New_Reference_To (Index_Typ, Loc),
12223 Make_Attribute_Reference (Loc,
12225 New_Reference_To (Index_Typ, Loc),
12226 Attribute_Name => Name_Val,
12228 Expressions => New_List (
12232 Make_Op_Subtract (Loc,
12234 New_Reference_To (E, Loc),
12236 Entry_Index_Expression (Loc,
12237 Defining_Identifier (Body_Nod),
12241 Make_Attribute_Reference (Loc,
12243 New_Reference_To (Index_Typ, Loc),
12244 Attribute_Name => Name_Pos,
12245 Expressions => New_List (
12246 Make_Attribute_Reference (Loc,
12248 New_Reference_To (Index_Typ, Loc),
12249 Attribute_Name => Name_First)))))));
12253 end Install_Private_Data_Declarations;
12255 ---------------------------------
12256 -- Is_Potentially_Large_Family --
12257 ---------------------------------
12259 function Is_Potentially_Large_Family
12260 (Base_Index : Entity_Id;
12261 Conctyp : Entity_Id;
12263 Hi : Node_Id) return Boolean
12266 return Scope (Base_Index) = Standard_Standard
12267 and then Base_Index = Base_Type (Standard_Integer)
12268 and then Has_Discriminants (Conctyp)
12270 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12272 (Denotes_Discriminant (Lo, True)
12273 or else Denotes_Discriminant (Hi, True));
12274 end Is_Potentially_Large_Family;
12276 -------------------------------------
12277 -- Is_Private_Primitive_Subprogram --
12278 -------------------------------------
12280 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12283 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12284 and then Is_Private_Primitive (Id);
12285 end Is_Private_Primitive_Subprogram;
12291 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12292 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12293 Formal : Entity_Id;
12296 Formal := First_Formal (Bod_Subp);
12297 while Present (Formal) loop
12299 -- Look for formal parameter _E
12301 if Chars (Formal) = Name_uE then
12305 Next_Formal (Formal);
12308 -- A protected body subprogram should always have the parameter in
12311 raise Program_Error;
12314 --------------------------------
12315 -- Make_Initialize_Protection --
12316 --------------------------------
12318 function Make_Initialize_Protection
12319 (Protect_Rec : Entity_Id) return List_Id
12321 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12325 Ptyp : constant Node_Id :=
12326 Corresponding_Concurrent_Type (Protect_Rec);
12328 L : constant List_Id := New_List;
12329 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12330 Restricted : constant Boolean := Restricted_Profile;
12333 -- We may need two calls to properly initialize the object, one to
12334 -- Initialize_Protection, and possibly one to Install_Handlers if we
12335 -- have a pragma Attach_Handler.
12337 -- Get protected declaration. In the case of a task type declaration,
12338 -- this is simply the parent of the protected type entity. In the single
12339 -- protected object declaration, this parent will be the implicit type,
12340 -- and we can find the corresponding single protected object declaration
12341 -- by searching forward in the declaration list in the tree.
12343 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12344 -- of this type should have been removed during semantic analysis.
12346 Pdec := Parent (Ptyp);
12347 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12348 N_Single_Protected_Declaration)
12353 -- Now we can find the object definition from this declaration
12355 Pdef := Protected_Definition (Pdec);
12357 -- Build the parameter list for the call. Note that _Init is the name
12358 -- of the formal for the object to be initialized, which is the task
12359 -- value record itself.
12363 -- Object parameter. This is a pointer to the object of type
12364 -- Protection used by the GNARL to control the protected object.
12367 Make_Attribute_Reference (Loc,
12369 Make_Selected_Component (Loc,
12370 Prefix => Make_Identifier (Loc, Name_uInit),
12371 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12372 Attribute_Name => Name_Unchecked_Access));
12374 -- Priority parameter. Set to Unspecified_Priority unless there is a
12375 -- priority pragma, in which case we take the value from the pragma,
12376 -- or there is an interrupt pragma and no priority pragma, and we
12377 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12378 -- defined value, see D.3(10).
12381 and then Has_Pragma_Priority (Pdef)
12384 Prio : constant Node_Id :=
12387 (Pragma_Argument_Associations
12388 (Find_Task_Or_Protected_Pragma
12389 (Pdef, Name_Priority))));
12393 -- If priority is a static expression, then we can duplicate it
12394 -- with no problem and simply append it to the argument list.
12396 if Is_Static_Expression (Prio) then
12398 Duplicate_Subexpr_No_Checks (Prio));
12400 -- Otherwise, the priority may be a per-object expression, if it
12401 -- depends on a discriminant of the type. In this case, create
12402 -- local variable to capture the expression. Note that it is
12403 -- really necessary to create this variable explicitly. It might
12404 -- be thought that removing side effects would the appropriate
12405 -- approach, but that could generate declarations improperly
12406 -- placed in the enclosing scope.
12408 -- Note: Use System.Any_Priority as the expected type for the
12409 -- non-static priority expression, in case the expression has not
12410 -- been analyzed yet (as occurs for example with pragma
12411 -- Interrupt_Priority).
12414 Temp := Make_Temporary (Loc, 'R', Prio);
12416 Make_Object_Declaration (Loc,
12417 Defining_Identifier => Temp,
12418 Object_Definition =>
12419 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12420 Expression => Relocate_Node (Prio)));
12422 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12426 -- When no priority is specified but an xx_Handler pragma is, we default
12427 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12429 elsif Has_Interrupt_Handler (Ptyp)
12430 or else Has_Attach_Handler (Ptyp)
12433 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12435 -- Normal case, no priority or xx_Handler specified, default priority
12439 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12442 -- Test for Compiler_Info parameter. This parameter allows entry body
12443 -- procedures and barrier functions to be called from the runtime. It
12444 -- is a pointer to the record generated by the compiler to represent
12445 -- the protected object.
12447 -- A protected type without entries that covers an interface and
12448 -- overrides the abstract routines with protected procedures is
12449 -- considered equivalent to a protected type with entries in the
12450 -- context of dispatching select statements.
12453 or else Has_Interrupt_Handler (Ptyp)
12454 or else Has_Attach_Handler (Ptyp)
12455 or else Has_Interfaces (Protect_Rec)
12458 Pkg_Id : constant RTU_Id :=
12459 Corresponding_Runtime_Package (Ptyp);
12460 Called_Subp : RE_Id;
12464 when System_Tasking_Protected_Objects_Entries =>
12465 Called_Subp := RE_Initialize_Protection_Entries;
12467 when System_Tasking_Protected_Objects =>
12468 Called_Subp := RE_Initialize_Protection;
12470 when System_Tasking_Protected_Objects_Single_Entry =>
12471 Called_Subp := RE_Initialize_Protection_Entry;
12474 raise Program_Error;
12478 or else not Restricted
12479 or else Has_Interfaces (Protect_Rec)
12482 Make_Attribute_Reference (Loc,
12483 Prefix => Make_Identifier (Loc, Name_uInit),
12484 Attribute_Name => Name_Address));
12487 -- Entry_Bodies parameter. This is a pointer to an array of
12488 -- pointers to the entry body procedures and barrier functions of
12489 -- the object. If the protected type has no entries this object
12490 -- will not exist, in this case, pass a null.
12493 P_Arr := Entry_Bodies_Array (Ptyp);
12496 Make_Attribute_Reference (Loc,
12497 Prefix => New_Reference_To (P_Arr, Loc),
12498 Attribute_Name => Name_Unrestricted_Access));
12500 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12502 -- Find index mapping function (clumsy but ok for now)
12504 while Ekind (P_Arr) /= E_Function loop
12505 Next_Entity (P_Arr);
12509 Make_Attribute_Reference (Loc,
12511 New_Reference_To (P_Arr, Loc),
12512 Attribute_Name => Name_Unrestricted_Access));
12514 -- Build_Entry_Names generation flag. When set to true, the
12515 -- runtime will allocate an array to hold the string names
12516 -- of protected entries.
12518 if not Restricted_Profile then
12519 if Entry_Names_OK then
12521 New_Reference_To (Standard_True, Loc));
12524 New_Reference_To (Standard_False, Loc));
12529 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12530 Append_To (Args, Make_Null (Loc));
12532 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12533 Append_To (Args, Make_Null (Loc));
12534 Append_To (Args, Make_Null (Loc));
12535 Append_To (Args, New_Reference_To (Standard_False, Loc));
12539 Make_Procedure_Call_Statement (Loc,
12540 Name => New_Reference_To (RTE (Called_Subp), Loc),
12541 Parameter_Associations => Args));
12545 Make_Procedure_Call_Statement (Loc,
12546 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12547 Parameter_Associations => Args));
12550 if Has_Attach_Handler (Ptyp) then
12552 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12553 -- make the following call:
12555 -- Install_Handlers (_object,
12556 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12558 -- or, in the case of Ravenscar:
12560 -- Install_Restricted_Handlers
12561 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12564 Args : constant List_Id := New_List;
12565 Table : constant List_Id := New_List;
12566 Ritem : Node_Id := First_Rep_Item (Ptyp);
12569 -- Build the Attach_Handler table argument
12571 while Present (Ritem) loop
12572 if Nkind (Ritem) = N_Pragma
12573 and then Pragma_Name (Ritem) = Name_Attach_Handler
12576 Handler : constant Node_Id :=
12577 First (Pragma_Argument_Associations (Ritem));
12579 Interrupt : constant Node_Id := Next (Handler);
12580 Expr : constant Node_Id := Expression (Interrupt);
12584 Make_Aggregate (Loc, Expressions => New_List (
12585 Unchecked_Convert_To
12586 (RTE (RE_System_Interrupt_Id), Expr),
12587 Make_Attribute_Reference (Loc,
12588 Prefix => Make_Selected_Component (Loc,
12589 Make_Identifier (Loc, Name_uInit),
12590 Duplicate_Subexpr_No_Checks
12591 (Expression (Handler))),
12592 Attribute_Name => Name_Access))));
12596 Next_Rep_Item (Ritem);
12599 -- Append the table argument we just built
12601 Append_To (Args, Make_Aggregate (Loc, Table));
12603 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12604 -- call to the statements.
12607 -- Call a simplified version of Install_Handlers to be used
12608 -- when the Ravenscar restrictions are in effect
12609 -- (Install_Restricted_Handlers).
12612 Make_Procedure_Call_Statement (Loc,
12615 (RTE (RE_Install_Restricted_Handlers), Loc),
12616 Parameter_Associations => Args));
12619 -- First, prepends the _object argument
12622 Make_Attribute_Reference (Loc,
12624 Make_Selected_Component (Loc,
12625 Prefix => Make_Identifier (Loc, Name_uInit),
12626 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12627 Attribute_Name => Name_Unchecked_Access));
12629 -- Then, insert call to Install_Handlers
12632 Make_Procedure_Call_Statement (Loc,
12633 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
12634 Parameter_Associations => Args));
12640 end Make_Initialize_Protection;
12642 ---------------------------
12643 -- Make_Task_Create_Call --
12644 ---------------------------
12646 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
12647 Loc : constant Source_Ptr := Sloc (Task_Rec);
12657 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
12658 Tnam := Chars (Ttyp);
12660 -- Get task declaration. In the case of a task type declaration, this is
12661 -- simply the parent of the task type entity. In the single task
12662 -- declaration, this parent will be the implicit type, and we can find
12663 -- the corresponding single task declaration by searching forward in the
12664 -- declaration list in the tree.
12666 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12667 -- this type should have been removed during semantic analysis.
12669 Tdec := Parent (Ttyp);
12670 while not Nkind_In (Tdec, N_Task_Type_Declaration,
12671 N_Single_Task_Declaration)
12676 -- Now we can find the task definition from this declaration
12678 Tdef := Task_Definition (Tdec);
12680 -- Build the parameter list for the call. Note that _Init is the name
12681 -- of the formal for the object to be initialized, which is the task
12682 -- value record itself.
12686 -- Priority parameter. Set to Unspecified_Priority unless there is a
12687 -- priority pragma, in which case we take the value from the pragma.
12689 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
12691 Make_Selected_Component (Loc,
12692 Prefix => Make_Identifier (Loc, Name_uInit),
12693 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12696 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12699 -- Optional Stack parameter
12701 if Restricted_Profile then
12703 -- If the stack has been preallocated by the expander then
12704 -- pass its address. Otherwise, pass a null address.
12706 if Preallocated_Stacks_On_Target then
12708 Make_Attribute_Reference (Loc,
12710 Make_Selected_Component (Loc,
12711 Prefix => Make_Identifier (Loc, Name_uInit),
12712 Selector_Name => Make_Identifier (Loc, Name_uStack)),
12713 Attribute_Name => Name_Address));
12717 New_Reference_To (RTE (RE_Null_Address), Loc));
12721 -- Size parameter. If no Storage_Size pragma is present, then
12722 -- the size is taken from the taskZ variable for the type, which
12723 -- is either Unspecified_Size, or has been reset by the use of
12724 -- a Storage_Size attribute definition clause. If a pragma is
12725 -- present, then the size is taken from the _Size field of the
12726 -- task value record, which was set from the pragma value.
12729 and then Has_Storage_Size_Pragma (Tdef)
12732 Make_Selected_Component (Loc,
12733 Prefix => Make_Identifier (Loc, Name_uInit),
12734 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12738 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12741 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12742 -- Task_Info pragma, in which case we take the value from the pragma.
12745 and then Has_Task_Info_Pragma (Tdef)
12748 Make_Selected_Component (Loc,
12749 Prefix => Make_Identifier (Loc, Name_uInit),
12750 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12754 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12757 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
12758 -- in which case we take the value from the pragma. The parameter is
12759 -- passed as an Integer because in the case of unspecified CPU the
12760 -- value is not in the range of CPU_Range.
12762 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
12764 Convert_To (Standard_Integer,
12765 Make_Selected_Component (Loc,
12766 Prefix => Make_Identifier (Loc, Name_uInit),
12767 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
12771 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
12774 if not Restricted_Profile then
12776 -- Deadline parameter. If no Relative_Deadline pragma is present,
12777 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12778 -- the deadline is taken from the _Relative_Deadline field of the
12779 -- task value record, which was set from the pragma value. Note that
12780 -- this parameter must not be generated for the restricted profiles
12781 -- since Ravenscar does not allow deadlines.
12783 -- Case where pragma Relative_Deadline applies: use given value
12785 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12787 Make_Selected_Component (Loc,
12789 Make_Identifier (Loc, Name_uInit),
12791 Make_Identifier (Loc, Name_uRelative_Deadline)));
12793 -- No pragma Relative_Deadline apply to the task
12797 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12800 -- Number of entries. This is an expression of the form:
12802 -- n + _Init.a'Length + _Init.a'B'Length + ...
12804 -- where a,b... are the entry family names for the task definition
12807 Build_Entry_Count_Expression
12812 (Parent (Corresponding_Record_Type (Ttyp))))),
12814 Append_To (Args, Ecount);
12816 -- Master parameter. This is a reference to the _Master parameter of
12817 -- the initialization procedure, except in the case of the pragma
12818 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
12819 -- System.Tasking.Library_Task_Level.
12821 if Restriction_Active (No_Task_Hierarchy) = False then
12822 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12825 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
12829 -- State parameter. This is a pointer to the task body procedure. The
12830 -- required value is obtained by taking 'Unrestricted_Access of the task
12831 -- body procedure and converting it (with an unchecked conversion) to
12832 -- the type required by the task kernel. For further details, see the
12833 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12834 -- than 'Address in order to avoid creating trampolines.
12837 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12838 Subp_Ptr_Typ : constant Node_Id :=
12839 Create_Itype (E_Access_Subprogram_Type, Tdec);
12840 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12843 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12844 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12846 -- Be sure to freeze a reference to the access-to-subprogram type,
12847 -- otherwise gigi will complain that it's in the wrong scope, because
12848 -- it's actually inside the init procedure for the record type that
12849 -- corresponds to the task type.
12851 -- This processing is causing a crash in the .NET/JVM back ends that
12852 -- is not yet understood, so skip it in these cases ???
12854 if VM_Target = No_VM then
12855 Set_Itype (Ref, Subp_Ptr_Typ);
12856 Append_Freeze_Action (Task_Rec, Ref);
12859 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12860 Make_Qualified_Expression (Loc,
12861 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12863 Make_Attribute_Reference (Loc,
12865 New_Occurrence_Of (Body_Proc, Loc),
12866 Attribute_Name => Name_Unrestricted_Access))));
12868 -- For the .NET/JVM cases revert to the original code below ???
12872 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12873 Make_Attribute_Reference (Loc,
12875 New_Occurrence_Of (Body_Proc, Loc),
12876 Attribute_Name => Name_Address)));
12880 -- Discriminants parameter. This is just the address of the task
12881 -- value record itself (which contains the discriminant values
12884 Make_Attribute_Reference (Loc,
12885 Prefix => Make_Identifier (Loc, Name_uInit),
12886 Attribute_Name => Name_Address));
12888 -- Elaborated parameter. This is an access to the elaboration Boolean
12891 Make_Attribute_Reference (Loc,
12892 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12893 Attribute_Name => Name_Unchecked_Access));
12895 -- Chain parameter. This is a reference to the _Chain parameter of
12896 -- the initialization procedure.
12898 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12900 -- Task name parameter. Take this from the _Task_Id parameter to the
12901 -- init call unless there is a Task_Name pragma, in which case we take
12902 -- the value from the pragma.
12905 and then Has_Task_Name_Pragma (Tdef)
12907 -- Copy expression in full, because it may be dynamic and have
12913 (Pragma_Argument_Associations
12914 (Find_Task_Or_Protected_Pragma
12915 (Tdef, Name_Task_Name))))));
12918 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12921 -- Created_Task parameter. This is the _Task_Id field of the task
12925 Make_Selected_Component (Loc,
12926 Prefix => Make_Identifier (Loc, Name_uInit),
12927 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12929 -- Build_Entry_Names generation flag. When set to true, the runtime
12930 -- will allocate an array to hold the string names of task entries.
12932 if not Restricted_Profile then
12933 if Has_Entries (Ttyp)
12934 and then Entry_Names_OK
12936 Append_To (Args, New_Reference_To (Standard_True, Loc));
12938 Append_To (Args, New_Reference_To (Standard_False, Loc));
12942 if Restricted_Profile then
12943 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12945 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12949 Make_Procedure_Call_Statement (Loc,
12951 Parameter_Associations => Args);
12952 end Make_Task_Create_Call;
12954 ------------------------------
12955 -- Next_Protected_Operation --
12956 ------------------------------
12958 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12962 Next_Op := Next (N);
12963 while Present (Next_Op)
12964 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12970 end Next_Protected_Operation;
12972 ---------------------
12973 -- Null_Statements --
12974 ---------------------
12976 function Null_Statements (Stats : List_Id) return Boolean is
12980 Stmt := First (Stats);
12981 while Nkind (Stmt) /= N_Empty
12982 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12984 (Nkind (Stmt) = N_Pragma
12985 and then (Pragma_Name (Stmt) = Name_Unreferenced
12987 Pragma_Name (Stmt) = Name_Unmodified
12989 Pragma_Name (Stmt) = Name_Warnings)))
12994 return Nkind (Stmt) = N_Empty;
12995 end Null_Statements;
12997 --------------------------
12998 -- Parameter_Block_Pack --
12999 --------------------------
13001 function Parameter_Block_Pack
13003 Blk_Typ : Entity_Id;
13007 Stmts : List_Id) return Node_Id
13009 Actual : Entity_Id;
13010 Expr : Node_Id := Empty;
13011 Formal : Entity_Id;
13012 Has_Param : Boolean := False;
13015 Temp_Asn : Node_Id;
13016 Temp_Nam : Node_Id;
13019 Actual := First (Actuals);
13020 Formal := Defining_Identifier (First (Formals));
13021 Params := New_List;
13023 while Present (Actual) loop
13024 if Is_By_Copy_Type (Etype (Actual)) then
13026 -- Jnn : aliased <formal-type>
13028 Temp_Nam := Make_Temporary (Loc, 'J');
13031 Make_Object_Declaration (Loc,
13034 Defining_Identifier =>
13036 Object_Definition =>
13037 New_Reference_To (Etype (Formal), Loc)));
13039 if Ekind (Formal) /= E_Out_Parameter then
13045 New_Reference_To (Temp_Nam, Loc);
13047 Set_Assignment_OK (Temp_Asn);
13050 Make_Assignment_Statement (Loc,
13054 New_Copy_Tree (Actual)));
13058 -- Jnn'unchecked_access
13061 Make_Attribute_Reference (Loc,
13063 Name_Unchecked_Access,
13065 New_Reference_To (Temp_Nam, Loc)));
13069 -- The controlling parameter is omitted
13072 if not Is_Controlling_Actual (Actual) then
13074 Make_Reference (Loc, New_Copy_Tree (Actual)));
13080 Next_Actual (Actual);
13081 Next_Formal_With_Extras (Formal);
13085 Expr := Make_Aggregate (Loc, Params);
13090 -- J1'unchecked_access;
13091 -- <actual2>'reference;
13094 P := Make_Temporary (Loc, 'P');
13097 Make_Object_Declaration (Loc,
13098 Defining_Identifier =>
13100 Object_Definition =>
13101 New_Reference_To (Blk_Typ, Loc),
13106 end Parameter_Block_Pack;
13108 ----------------------------
13109 -- Parameter_Block_Unpack --
13110 ----------------------------
13112 function Parameter_Block_Unpack
13116 Formals : List_Id) return List_Id
13118 Actual : Entity_Id;
13120 Formal : Entity_Id;
13121 Has_Asnmt : Boolean := False;
13122 Result : constant List_Id := New_List;
13125 Actual := First (Actuals);
13126 Formal := Defining_Identifier (First (Formals));
13127 while Present (Actual) loop
13128 if Is_By_Copy_Type (Etype (Actual))
13129 and then Ekind (Formal) /= E_In_Parameter
13132 -- <actual> := P.<formal>;
13135 Make_Assignment_Statement (Loc,
13139 Make_Explicit_Dereference (Loc,
13140 Make_Selected_Component (Loc,
13142 New_Reference_To (P, Loc),
13144 Make_Identifier (Loc, Chars (Formal)))));
13146 Set_Assignment_OK (Name (Asnmt));
13147 Append_To (Result, Asnmt);
13152 Next_Actual (Actual);
13153 Next_Formal_With_Extras (Formal);
13159 return New_List (Make_Null_Statement (Loc));
13161 end Parameter_Block_Unpack;
13163 ----------------------
13164 -- Set_Discriminals --
13165 ----------------------
13167 procedure Set_Discriminals (Dec : Node_Id) is
13170 D_Minal : Entity_Id;
13173 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13174 Pdef := Defining_Identifier (Dec);
13176 if Has_Discriminants (Pdef) then
13177 D := First_Discriminant (Pdef);
13178 while Present (D) loop
13180 Make_Defining_Identifier (Sloc (D),
13181 Chars => New_External_Name (Chars (D), 'D'));
13183 Set_Ekind (D_Minal, E_Constant);
13184 Set_Etype (D_Minal, Etype (D));
13185 Set_Scope (D_Minal, Pdef);
13186 Set_Discriminal (D, D_Minal);
13187 Set_Discriminal_Link (D_Minal, D);
13189 Next_Discriminant (D);
13192 end Set_Discriminals;
13194 -----------------------
13195 -- Trivial_Accept_OK --
13196 -----------------------
13198 function Trivial_Accept_OK return Boolean is
13200 case Opt.Task_Dispatching_Policy is
13202 -- If we have the default task dispatching policy in effect, we can
13203 -- definitely do the optimization (one way of looking at this is to
13204 -- think of the formal definition of the default policy being allowed
13205 -- to run any task it likes after a rendezvous, so even if notionally
13206 -- a full rescheduling occurs, we can say that our dispatching policy
13207 -- (i.e. the default dispatching policy) reorders the queue to be the
13208 -- same as just before the call.
13213 -- FIFO_Within_Priorities certainly does not permit this
13214 -- optimization since the Rendezvous is a scheduling action that may
13215 -- require some other task to be run.
13220 -- For now, disallow the optimization for all other policies. This
13221 -- may be over-conservative, but it is certainly not incorrect.
13227 end Trivial_Accept_OK;