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,
954 Then_Statements => New_List (
955 Make_Simple_Return_Statement (Loc,
956 New_Occurrence_Of (Standard_True, Loc))),
957 Else_Statements => New_List (
958 Make_Simple_Return_Statement (Loc,
959 New_Occurrence_Of (Standard_False, Loc))));
962 Stmt := Make_Simple_Return_Statement (Loc, Cond);
965 -- Note: the condition in the barrier function needs to be properly
966 -- processed for the C/Fortran boolean possibility, but this happens
967 -- automatically since the return statement does this normalization.
970 Make_Subprogram_Body (Loc,
972 Build_Barrier_Function_Specification (Loc,
973 Make_Defining_Identifier (Loc, Chars (Func_Id))),
974 Declarations => Op_Decls,
975 Handled_Statement_Sequence =>
976 Make_Handled_Sequence_Of_Statements (Loc,
977 Statements => New_List (Stmt)));
978 Set_Is_Entry_Barrier_Function (Func_Body);
981 end Build_Barrier_Function;
983 ------------------------------------------
984 -- Build_Barrier_Function_Specification --
985 ------------------------------------------
987 function Build_Barrier_Function_Specification
989 Def_Id : Entity_Id) return Node_Id
992 Set_Debug_Info_Needed (Def_Id);
994 return Make_Function_Specification (Loc,
995 Defining_Unit_Name => Def_Id,
996 Parameter_Specifications => New_List (
997 Make_Parameter_Specification (Loc,
998 Defining_Identifier =>
999 Make_Defining_Identifier (Loc, Name_uO),
1001 New_Reference_To (RTE (RE_Address), Loc)),
1003 Make_Parameter_Specification (Loc,
1004 Defining_Identifier =>
1005 Make_Defining_Identifier (Loc, Name_uE),
1007 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
1009 Result_Definition =>
1010 New_Reference_To (Standard_Boolean, Loc));
1011 end Build_Barrier_Function_Specification;
1013 --------------------------
1014 -- Build_Call_With_Task --
1015 --------------------------
1017 function Build_Call_With_Task
1019 E : Entity_Id) return Node_Id
1021 Loc : constant Source_Ptr := Sloc (N);
1024 Make_Function_Call (Loc,
1025 Name => New_Reference_To (E, Loc),
1026 Parameter_Associations => New_List (Concurrent_Ref (N)));
1027 end Build_Call_With_Task;
1029 --------------------------------
1030 -- Build_Corresponding_Record --
1031 --------------------------------
1033 function Build_Corresponding_Record
1036 Loc : Source_Ptr) return Node_Id
1038 Rec_Ent : constant Entity_Id :=
1039 Make_Defining_Identifier
1040 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1043 New_Disc : Entity_Id;
1047 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1048 Set_Ekind (Rec_Ent, E_Record_Type);
1049 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1050 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1051 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1052 Set_Stored_Constraint (Rec_Ent, No_Elist);
1055 -- Use discriminals to create list of discriminants for record, and
1056 -- create new discriminals for use in default expressions, etc. It is
1057 -- worth noting that a task discriminant gives rise to 5 entities;
1059 -- a) The original discriminant.
1060 -- b) The discriminal for use in the task.
1061 -- c) The discriminant of the corresponding record.
1062 -- d) The discriminal for the init proc of the corresponding record.
1063 -- e) The local variable that renames the discriminant in the procedure
1064 -- for the task body.
1066 -- In fact the discriminals b) are used in the renaming declarations
1067 -- for e). See details in einfo (Handling of Discriminants).
1069 if Present (Discriminant_Specifications (N)) then
1071 Disc := First_Discriminant (Ctyp);
1073 while Present (Disc) loop
1074 New_Disc := CR_Discriminant (Disc);
1077 Make_Discriminant_Specification (Loc,
1078 Defining_Identifier => New_Disc,
1079 Discriminant_Type =>
1080 New_Occurrence_Of (Etype (Disc), Loc),
1082 New_Copy (Discriminant_Default_Value (Disc))));
1084 Next_Discriminant (Disc);
1091 -- Now we can construct the record type declaration. Note that this
1092 -- record is "limited tagged". It is "limited" to reflect the underlying
1093 -- limitedness of the task or protected object that it represents, and
1094 -- ensuring for example that it is properly passed by reference. It is
1095 -- "tagged" to give support to dispatching calls through interfaces. We
1096 -- propagate here the list of interfaces covered by the concurrent type
1097 -- (Ada 2005: AI-345).
1100 Make_Full_Type_Declaration (Loc,
1101 Defining_Identifier => Rec_Ent,
1102 Discriminant_Specifications => Dlist,
1104 Make_Record_Definition (Loc,
1106 Make_Component_List (Loc,
1107 Component_Items => Cdecls),
1109 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1110 Interface_List => Interface_List (N),
1111 Limited_Present => True));
1112 end Build_Corresponding_Record;
1114 ----------------------------------
1115 -- Build_Entry_Count_Expression --
1116 ----------------------------------
1118 function Build_Entry_Count_Expression
1119 (Concurrent_Type : Node_Id;
1120 Component_List : List_Id;
1121 Loc : Source_Ptr) return Node_Id
1133 -- Count number of non-family entries
1136 Ent := First_Entity (Concurrent_Type);
1137 while Present (Ent) loop
1138 if Ekind (Ent) = E_Entry then
1145 Ecount := Make_Integer_Literal (Loc, Eindx);
1147 -- Loop through entry families building the addition nodes
1149 Ent := First_Entity (Concurrent_Type);
1150 Comp := First (Component_List);
1151 while Present (Ent) loop
1152 if Ekind (Ent) = E_Entry_Family then
1153 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1157 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1158 Hi := Type_High_Bound (Typ);
1159 Lo := Type_Low_Bound (Typ);
1160 Large := Is_Potentially_Large_Family
1161 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1164 Left_Opnd => Ecount,
1165 Right_Opnd => Family_Size
1166 (Loc, Hi, Lo, Concurrent_Type, Large));
1173 end Build_Entry_Count_Expression;
1175 -----------------------
1176 -- Build_Entry_Names --
1177 -----------------------
1179 function Build_Entry_Names (Conc_Typ : Entity_Id) return Node_Id is
1180 Loc : constant Source_Ptr := Sloc (Conc_Typ);
1186 Typ : Entity_Id := Conc_Typ;
1188 procedure Build_Entry_Family_Name (Id : Entity_Id);
1190 -- for Lnn in Family_Low .. Family_High loop
1193 -- (_init._object <or> _init._task_id,
1195 -- new String ("<Entry name>(" & Lnn'Img & ")"));
1197 -- Note that the bounds of the range may reference discriminants. The
1198 -- above construct is added directly to the statements of the block.
1200 procedure Build_Entry_Name (Id : Entity_Id);
1204 -- (_init._object <or>_init._task_id,
1206 -- new String ("<Entry name>");
1207 -- The above construct is added directly to the statements of the block.
1209 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id;
1210 -- Generate the call to the runtime routine Set_Entry_Name with actuals
1211 -- _init._task_id or _init._object, Inn and Arg3.
1213 procedure Increment_Index (Stmts : List_Id);
1214 -- Generate the following and add it to Stmts
1217 -----------------------------
1218 -- Build_Entry_Family_Name --
1219 -----------------------------
1221 procedure Build_Entry_Family_Name (Id : Entity_Id) is
1222 Def : constant Node_Id :=
1223 Discrete_Subtype_Definition (Parent (Id));
1224 L_Id : constant Entity_Id := Make_Temporary (Loc, 'L');
1225 L_Stmts : constant List_Id := New_List;
1228 function Build_Range (Def : Node_Id) return Node_Id;
1229 -- Given a discrete subtype definition of an entry family, generate a
1230 -- range node which covers the range of Def's type.
1236 function Build_Range (Def : Node_Id) return Node_Id is
1237 High : Node_Id := Type_High_Bound (Etype (Def));
1238 Low : Node_Id := Type_Low_Bound (Etype (Def));
1241 -- If a bound references a discriminant, generate an identifier
1242 -- with the same name. Resolution will map it to the formals of
1245 if Is_Entity_Name (Low)
1246 and then Ekind (Entity (Low)) = E_Discriminant
1248 Low := Make_Identifier (Loc, Chars (Low));
1250 Low := New_Copy_Tree (Low);
1253 if Is_Entity_Name (High)
1254 and then Ekind (Entity (High)) = E_Discriminant
1256 High := Make_Identifier (Loc, Chars (High));
1258 High := New_Copy_Tree (High);
1264 High_Bound => High);
1267 -- Start of processing for Build_Entry_Family_Name
1270 Get_Name_String (Chars (Id));
1272 -- Add a leading '('
1274 Add_Char_To_Name_Buffer ('(');
1277 -- new String'("<Entry name>(" & Lnn'Img & ")");
1279 -- This is an implicit heap allocation, and Comes_From_Source is
1280 -- False, which ensures that it will get flagged as a violation of
1281 -- No_Implicit_Heap_Allocations when that restriction applies.
1284 Make_Allocator (Loc,
1285 Make_Qualified_Expression (Loc,
1287 New_Reference_To (Standard_String, Loc),
1289 Make_Op_Concat (Loc,
1291 Make_Op_Concat (Loc,
1293 Make_String_Literal (Loc,
1294 Strval => String_From_Name_Buffer),
1296 Make_Attribute_Reference (Loc,
1298 New_Reference_To (L_Id, Loc),
1299 Attribute_Name => Name_Img)),
1301 Make_String_Literal (Loc,
1304 Increment_Index (L_Stmts);
1305 Append_To (L_Stmts, Build_Set_Entry_Name_Call (Val));
1308 -- for Lnn in Family_Low .. Family_High loop
1311 -- (_init._object <or> _init._task_id, Inn, <Val>);
1315 Make_Loop_Statement (Loc,
1317 Make_Iteration_Scheme (Loc,
1318 Loop_Parameter_Specification =>
1319 Make_Loop_Parameter_Specification (Loc,
1320 Defining_Identifier => L_Id,
1321 Discrete_Subtype_Definition => Build_Range (Def))),
1322 Statements => L_Stmts,
1323 End_Label => Empty));
1324 end Build_Entry_Family_Name;
1326 ----------------------
1327 -- Build_Entry_Name --
1328 ----------------------
1330 procedure Build_Entry_Name (Id : Entity_Id) is
1334 Get_Name_String (Chars (Id));
1336 -- This is an implicit heap allocation, and Comes_From_Source is
1337 -- False, which ensures that it will get flagged as a violation of
1338 -- No_Implicit_Heap_Allocations when that restriction applies.
1341 Make_Allocator (Loc,
1342 Make_Qualified_Expression (Loc,
1344 New_Reference_To (Standard_String, Loc),
1346 Make_String_Literal (Loc,
1347 String_From_Name_Buffer)));
1349 Increment_Index (B_Stmts);
1350 Append_To (B_Stmts, Build_Set_Entry_Name_Call (Val));
1351 end Build_Entry_Name;
1353 -------------------------------
1354 -- Build_Set_Entry_Name_Call --
1355 -------------------------------
1357 function Build_Set_Entry_Name_Call (Arg3 : Node_Id) return Node_Id is
1362 -- Determine the proper name for the first argument and the RTS
1365 if Is_Protected_Type (Typ) then
1366 Arg1 := Name_uObject;
1367 Proc := RO_PE_Set_Entry_Name;
1369 else pragma Assert (Is_Task_Type (Typ));
1370 Arg1 := Name_uTask_Id;
1371 Proc := RO_TS_Set_Entry_Name;
1375 -- Set_Entry_Name (_init.Arg1, Inn, Arg3);
1378 Make_Procedure_Call_Statement (Loc,
1380 New_Reference_To (RTE (Proc), Loc),
1381 Parameter_Associations => New_List (
1382 Make_Selected_Component (Loc, -- _init._object
1383 Prefix => -- _init._task_id
1384 Make_Identifier (Loc, Name_uInit),
1386 Make_Identifier (Loc, Arg1)),
1387 New_Reference_To (Index, Loc), -- Inn
1389 end Build_Set_Entry_Name_Call;
1391 ---------------------
1392 -- Increment_Index --
1393 ---------------------
1395 procedure Increment_Index (Stmts : List_Id) is
1401 Make_Assignment_Statement (Loc,
1403 New_Reference_To (Index, Loc),
1407 New_Reference_To (Index, Loc),
1409 Make_Integer_Literal (Loc, 1))));
1410 end Increment_Index;
1412 -- Start of processing for Build_Entry_Names
1415 -- Retrieve the original concurrent type
1417 if Is_Concurrent_Record_Type (Typ) then
1418 Typ := Corresponding_Concurrent_Type (Typ);
1421 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
1423 -- Nothing to do if the type has no entries
1425 if not Has_Entries (Typ) then
1429 -- Avoid generating entry names for a protected type with only one entry
1431 if Is_Protected_Type (Typ)
1432 and then Find_Protection_Type (Typ) /= RTE (RE_Protection_Entries)
1437 Index := Make_Temporary (Loc, 'I');
1439 -- Step 1: Generate the declaration of the index variable:
1440 -- Inn : Protected_Entry_Index := 0;
1442 -- Inn : Task_Entry_Index := 0;
1444 if Is_Protected_Type (Typ) then
1445 Index_Typ := RE_Protected_Entry_Index;
1447 Index_Typ := RE_Task_Entry_Index;
1450 B_Decls := New_List;
1452 Make_Object_Declaration (Loc,
1453 Defining_Identifier => Index,
1454 Object_Definition => New_Reference_To (RTE (Index_Typ), Loc),
1455 Expression => Make_Integer_Literal (Loc, 0)));
1457 B_Stmts := New_List;
1459 -- Step 2: Generate a call to Set_Entry_Name for each entry and entry
1462 Comp := First_Entity (Typ);
1463 while Present (Comp) loop
1464 if Ekind (Comp) = E_Entry then
1465 Build_Entry_Name (Comp);
1467 elsif Ekind (Comp) = E_Entry_Family then
1468 Build_Entry_Family_Name (Comp);
1474 -- Step 3: Wrap the statements in a block
1477 Make_Block_Statement (Loc,
1478 Declarations => B_Decls,
1479 Handled_Statement_Sequence =>
1480 Make_Handled_Sequence_Of_Statements (Loc,
1481 Statements => B_Stmts));
1482 end Build_Entry_Names;
1484 ---------------------------
1485 -- Build_Parameter_Block --
1486 ---------------------------
1488 function Build_Parameter_Block
1492 Decls : List_Id) return Entity_Id
1498 Has_Comp : Boolean := False;
1502 Actual := First (Actuals);
1504 Formal := Defining_Identifier (First (Formals));
1506 while Present (Actual) loop
1507 if not Is_Controlling_Actual (Actual) then
1510 -- type Ann is access all <actual-type>
1512 Comp_Nam := Make_Temporary (Loc, 'A');
1515 Make_Full_Type_Declaration (Loc,
1516 Defining_Identifier => Comp_Nam,
1518 Make_Access_To_Object_Definition (Loc,
1519 All_Present => True,
1520 Constant_Present => Ekind (Formal) = E_In_Parameter,
1521 Subtype_Indication =>
1522 New_Reference_To (Etype (Actual), Loc))));
1528 Make_Component_Declaration (Loc,
1529 Defining_Identifier =>
1530 Make_Defining_Identifier (Loc, Chars (Formal)),
1531 Component_Definition =>
1532 Make_Component_Definition (Loc,
1535 Subtype_Indication =>
1536 New_Reference_To (Comp_Nam, Loc))));
1541 Next_Actual (Actual);
1542 Next_Formal_With_Extras (Formal);
1545 Rec_Nam := Make_Temporary (Loc, 'P');
1550 -- type Pnn is record
1555 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1556 -- the original parameter names and Ann1 .. AnnN are the access to
1560 Make_Full_Type_Declaration (Loc,
1561 Defining_Identifier =>
1564 Make_Record_Definition (Loc,
1566 Make_Component_List (Loc, Comps))));
1569 -- type Pnn is null record;
1572 Make_Full_Type_Declaration (Loc,
1573 Defining_Identifier =>
1576 Make_Record_Definition (Loc,
1577 Null_Present => True,
1578 Component_List => Empty)));
1582 end Build_Parameter_Block;
1584 --------------------------------------
1585 -- Build_Renamed_Formal_Declaration --
1586 --------------------------------------
1588 function Build_Renamed_Formal_Declaration
1592 Renamed_Formal : Node_Id) return Node_Id
1594 Loc : constant Source_Ptr := Sloc (New_F);
1598 -- If the formal is a tagged incomplete type, it is already passed
1599 -- by reference, so it is sufficient to rename the pointer component
1600 -- that corresponds to the actual. Otherwise we need to dereference
1601 -- the pointer component to obtain the actual.
1603 if Is_Incomplete_Type (Etype (Formal))
1604 and then Is_Tagged_Type (Etype (Formal))
1607 Make_Object_Renaming_Declaration (Loc,
1608 Defining_Identifier => New_F,
1609 Subtype_Mark => New_Reference_To (Etype (Comp), Loc),
1610 Name => Renamed_Formal);
1614 Make_Object_Renaming_Declaration (Loc,
1615 Defining_Identifier => New_F,
1616 Subtype_Mark => New_Reference_To (Etype (Formal), Loc),
1618 Make_Explicit_Dereference (Loc, Renamed_Formal));
1622 end Build_Renamed_Formal_Declaration;
1624 -----------------------
1625 -- Build_PPC_Wrapper --
1626 -----------------------
1628 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1629 Loc : constant Source_Ptr := Sloc (E);
1630 Synch_Type : constant Entity_Id := Scope (E);
1632 Wrapper_Id : constant Entity_Id :=
1633 Make_Defining_Identifier (Loc,
1634 Chars => New_External_Name (Chars (E), 'E'));
1635 -- the wrapper procedure name
1637 Wrapper_Body : Node_Id;
1639 Synch_Id : constant Entity_Id :=
1640 Make_Defining_Identifier (Loc,
1641 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1642 -- The parameter that designates the synchronized object in the call
1644 Actuals : constant List_Id := New_List;
1645 -- the actuals in the entry call.
1647 Decls : constant List_Id := New_List;
1649 Entry_Call : Node_Id;
1650 Entry_Name : Node_Id;
1653 -- The specification of the wrapper procedure
1657 -- Only build the wrapper if entry has pre/postconditions.
1658 -- Should this be done unconditionally instead ???
1664 P := Spec_PPC_List (E);
1669 -- Transfer ppc pragmas to the declarations of the wrapper
1671 while Present (P) loop
1672 if Pragma_Name (P) = Name_Precondition
1673 or else Pragma_Name (P) = Name_Postcondition
1675 Append (Relocate_Node (P), Decls);
1676 Set_Analyzed (Last (Decls), False);
1679 P := Next_Pragma (P);
1683 -- First formal is synchronized object
1686 Make_Parameter_Specification (Loc,
1687 Defining_Identifier => Synch_Id,
1688 Out_Present => True,
1690 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1693 Make_Selected_Component (Loc,
1694 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1695 Selector_Name => New_Occurrence_Of (E, Loc));
1697 -- If entity is entry family, second formal is the corresponding index,
1698 -- and entry name is an indexed component.
1700 if Ekind (E) = E_Entry_Family then
1702 Index : constant Entity_Id :=
1703 Make_Defining_Identifier (Loc, Name_I);
1706 Make_Parameter_Specification (Loc,
1707 Defining_Identifier => Index,
1709 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1712 Make_Indexed_Component (Loc,
1713 Prefix => Entry_Name,
1714 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
1719 Make_Procedure_Call_Statement (Loc,
1721 Parameter_Associations => Actuals);
1723 -- Now add formals that match those of the entry, and build actuals for
1724 -- the nested entry call.
1728 New_Form : Entity_Id;
1729 Parm_Spec : Node_Id;
1732 Form := First_Formal (E);
1733 while Present (Form) loop
1734 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
1736 Make_Parameter_Specification (Loc,
1737 Defining_Identifier => New_Form,
1738 Out_Present => Out_Present (Parent (Form)),
1739 In_Present => In_Present (Parent (Form)),
1740 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
1742 Append (Parm_Spec, Specs);
1743 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
1748 -- Add renaming declarations for the discriminants of the enclosing
1749 -- type, which may be visible in the preconditions.
1751 if Has_Discriminants (Synch_Type) then
1757 D := First_Discriminant (Synch_Type);
1758 while Present (D) loop
1760 Make_Object_Renaming_Declaration (Loc,
1761 Defining_Identifier =>
1762 Make_Defining_Identifier (Loc, Chars (D)),
1763 Subtype_Mark => New_Reference_To (Etype (D), Loc),
1765 Make_Selected_Component (Loc,
1766 Prefix => New_Reference_To (Synch_Id, Loc),
1767 Selector_Name => Make_Identifier (Loc, Chars (D))));
1768 Prepend (Decl, Decls);
1769 Next_Discriminant (D);
1774 Set_PPC_Wrapper (E, Wrapper_Id);
1776 Make_Subprogram_Body (Loc,
1778 Make_Procedure_Specification (Loc,
1779 Defining_Unit_Name => Wrapper_Id,
1780 Parameter_Specifications => Specs),
1781 Declarations => Decls,
1782 Handled_Statement_Sequence =>
1783 Make_Handled_Sequence_Of_Statements (Loc,
1784 Statements => New_List (Entry_Call)));
1786 -- The wrapper body is analyzed when the enclosing type is frozen
1788 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
1789 end Build_PPC_Wrapper;
1791 --------------------------
1792 -- Build_Wrapper_Bodies --
1793 --------------------------
1795 procedure Build_Wrapper_Bodies
1800 Rec_Typ : Entity_Id;
1802 function Build_Wrapper_Body
1804 Subp_Id : Entity_Id;
1805 Obj_Typ : Entity_Id;
1806 Formals : List_Id) return Node_Id;
1807 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1808 -- associated with a protected or task type. Subp_Id is the subprogram
1809 -- name which will be wrapped. Obj_Typ is the type of the new formal
1810 -- parameter which handles dispatching and object notation. Formals are
1811 -- the original formals of Subp_Id which will be explicitly replicated.
1813 ------------------------
1814 -- Build_Wrapper_Body --
1815 ------------------------
1817 function Build_Wrapper_Body
1819 Subp_Id : Entity_Id;
1820 Obj_Typ : Entity_Id;
1821 Formals : List_Id) return Node_Id
1823 Body_Spec : Node_Id;
1826 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1828 -- The subprogram is not overriding or is not a primitive declared
1829 -- between two views.
1831 if No (Body_Spec) then
1836 Actuals : List_Id := No_List;
1838 First_Form : Node_Id;
1843 -- Map formals to actuals. Use the list built for the wrapper
1844 -- spec, skipping the object notation parameter.
1846 First_Form := First (Parameter_Specifications (Body_Spec));
1848 Formal := First_Form;
1851 if Present (Formal) then
1852 Actuals := New_List;
1853 while Present (Formal) loop
1855 Make_Identifier (Loc,
1856 Chars => Chars (Defining_Identifier (Formal))));
1861 -- Special processing for primitives declared between a private
1862 -- type and its completion: the wrapper needs a properly typed
1863 -- parameter if the wrapped operation has a controlling first
1864 -- parameter. Note that this might not be the case for a function
1865 -- with a controlling result.
1867 if Is_Private_Primitive_Subprogram (Subp_Id) then
1868 if No (Actuals) then
1869 Actuals := New_List;
1872 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1873 Prepend_To (Actuals,
1874 Unchecked_Convert_To
1875 (Corresponding_Concurrent_Type (Obj_Typ),
1876 Make_Identifier (Loc, Name_uO)));
1879 Prepend_To (Actuals,
1880 Make_Identifier (Loc,
1881 Chars => Chars (Defining_Identifier (First_Form))));
1884 Nam := New_Reference_To (Subp_Id, Loc);
1886 -- An access-to-variable object parameter requires an explicit
1887 -- dereference in the unchecked conversion. This case occurs
1888 -- when a protected entry wrapper must override an interface
1889 -- level procedure with interface access as first parameter.
1891 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1893 if Nkind (Parameter_Type (First_Form)) =
1897 Make_Explicit_Dereference (Loc,
1898 Prefix => Make_Identifier (Loc, Name_uO));
1900 Conv_Id := Make_Identifier (Loc, Name_uO);
1904 Make_Selected_Component (Loc,
1906 Unchecked_Convert_To
1907 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
1908 Selector_Name => New_Reference_To (Subp_Id, Loc));
1911 -- Create the subprogram body. For a function, the call to the
1912 -- actual subprogram has to be converted to the corresponding
1913 -- record if it is a controlling result.
1915 if Ekind (Subp_Id) = E_Function then
1921 Make_Function_Call (Loc,
1923 Parameter_Associations => Actuals);
1925 if Has_Controlling_Result (Subp_Id) then
1927 Unchecked_Convert_To
1928 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1932 Make_Subprogram_Body (Loc,
1933 Specification => Body_Spec,
1934 Declarations => Empty_List,
1935 Handled_Statement_Sequence =>
1936 Make_Handled_Sequence_Of_Statements (Loc,
1937 Statements => New_List (
1938 Make_Simple_Return_Statement (Loc, Res))));
1943 Make_Subprogram_Body (Loc,
1944 Specification => Body_Spec,
1945 Declarations => Empty_List,
1946 Handled_Statement_Sequence =>
1947 Make_Handled_Sequence_Of_Statements (Loc,
1948 Statements => New_List (
1949 Make_Procedure_Call_Statement (Loc,
1951 Parameter_Associations => Actuals))));
1954 end Build_Wrapper_Body;
1956 -- Start of processing for Build_Wrapper_Bodies
1959 if Is_Concurrent_Type (Typ) then
1960 Rec_Typ := Corresponding_Record_Type (Typ);
1965 -- Generate wrapper bodies for a concurrent type which implements an
1968 if Present (Interfaces (Rec_Typ)) then
1970 Insert_Nod : Node_Id;
1972 Prim_Elmt : Elmt_Id;
1973 Prim_Decl : Node_Id;
1975 Wrap_Body : Node_Id;
1976 Wrap_Id : Entity_Id;
1981 -- Examine all primitive operations of the corresponding record
1982 -- type, looking for wrapper specs. Generate bodies in order to
1985 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
1986 while Present (Prim_Elmt) loop
1987 Prim := Node (Prim_Elmt);
1989 if (Ekind (Prim) = E_Function
1990 or else Ekind (Prim) = E_Procedure)
1991 and then Is_Primitive_Wrapper (Prim)
1993 Subp := Wrapped_Entity (Prim);
1994 Prim_Decl := Parent (Parent (Prim));
1997 Build_Wrapper_Body (Loc,
2000 Formals => Parameter_Specifications (Parent (Subp)));
2001 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2003 Set_Corresponding_Spec (Wrap_Body, Prim);
2004 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2006 Insert_After (Insert_Nod, Wrap_Body);
2007 Insert_Nod := Wrap_Body;
2009 Analyze (Wrap_Body);
2012 Next_Elmt (Prim_Elmt);
2016 end Build_Wrapper_Bodies;
2018 ------------------------
2019 -- Build_Wrapper_Spec --
2020 ------------------------
2022 function Build_Wrapper_Spec
2023 (Subp_Id : Entity_Id;
2024 Obj_Typ : Entity_Id;
2025 Formals : List_Id) return Node_Id
2027 Loc : constant Source_Ptr := Sloc (Subp_Id);
2028 First_Param : Node_Id;
2030 Iface_Elmt : Elmt_Id;
2031 Iface_Op : Entity_Id;
2032 Iface_Op_Elmt : Elmt_Id;
2034 function Overriding_Possible
2035 (Iface_Op : Entity_Id;
2036 Wrapper : Entity_Id) return Boolean;
2037 -- Determine whether a primitive operation can be overridden by Wrapper.
2038 -- Iface_Op is the candidate primitive operation of an interface type,
2039 -- Wrapper is the generated entry wrapper.
2041 function Replicate_Formals
2043 Formals : List_Id) return List_Id;
2044 -- An explicit parameter replication is required due to the Is_Entry_
2045 -- Formal flag being set for all the formals of an entry. The explicit
2046 -- replication removes the flag that would otherwise cause a different
2047 -- path of analysis.
2049 -------------------------
2050 -- Overriding_Possible --
2051 -------------------------
2053 function Overriding_Possible
2054 (Iface_Op : Entity_Id;
2055 Wrapper : Entity_Id) return Boolean
2057 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2058 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2060 function Type_Conformant_Parameters
2061 (Iface_Op_Params : List_Id;
2062 Wrapper_Params : List_Id) return Boolean;
2063 -- Determine whether the parameters of the generated entry wrapper
2064 -- and those of a primitive operation are type conformant. During
2065 -- this check, the first parameter of the primitive operation is
2066 -- skipped if it is a controlling argument: protected functions
2067 -- may have a controlling result.
2069 --------------------------------
2070 -- Type_Conformant_Parameters --
2071 --------------------------------
2073 function Type_Conformant_Parameters
2074 (Iface_Op_Params : List_Id;
2075 Wrapper_Params : List_Id) return Boolean
2077 Iface_Op_Param : Node_Id;
2078 Iface_Op_Typ : Entity_Id;
2079 Wrapper_Param : Node_Id;
2080 Wrapper_Typ : Entity_Id;
2083 -- Skip the first (controlling) parameter of primitive operation
2085 Iface_Op_Param := First (Iface_Op_Params);
2087 if Present (First_Formal (Iface_Op))
2088 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2090 Iface_Op_Param := Next (Iface_Op_Param);
2093 Wrapper_Param := First (Wrapper_Params);
2094 while Present (Iface_Op_Param)
2095 and then Present (Wrapper_Param)
2097 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2098 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2100 -- The two parameters must be mode conformant
2102 if not Conforming_Types
2103 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2108 Next (Iface_Op_Param);
2109 Next (Wrapper_Param);
2112 -- One of the lists is longer than the other
2114 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2119 end Type_Conformant_Parameters;
2121 -- Start of processing for Overriding_Possible
2124 if Chars (Iface_Op) /= Chars (Wrapper) then
2128 -- If an inherited subprogram is implemented by a protected procedure
2129 -- or an entry, then the first parameter of the inherited subprogram
2130 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2132 if Ekind (Iface_Op) = E_Procedure
2133 and then Present (Parameter_Specifications (Iface_Op_Spec))
2136 Obj_Param : constant Node_Id :=
2137 First (Parameter_Specifications (Iface_Op_Spec));
2139 if not Out_Present (Obj_Param)
2140 and then Nkind (Parameter_Type (Obj_Param)) /=
2149 Type_Conformant_Parameters (
2150 Parameter_Specifications (Iface_Op_Spec),
2151 Parameter_Specifications (Wrapper_Spec));
2152 end Overriding_Possible;
2154 -----------------------
2155 -- Replicate_Formals --
2156 -----------------------
2158 function Replicate_Formals
2160 Formals : List_Id) return List_Id
2162 New_Formals : constant List_Id := New_List;
2164 Param_Type : Node_Id;
2167 Formal := First (Formals);
2169 -- Skip the object parameter when dealing with primitives declared
2170 -- between two views.
2172 if Is_Private_Primitive_Subprogram (Subp_Id)
2173 and then not Has_Controlling_Result (Subp_Id)
2175 Formal := Next (Formal);
2178 while Present (Formal) loop
2180 -- Create an explicit copy of the entry parameter
2182 -- When creating the wrapper subprogram for a primitive operation
2183 -- of a protected interface we must construct an equivalent
2184 -- signature to that of the overriding operation. For regular
2185 -- parameters we can just use the type of the formal, but for
2186 -- access to subprogram parameters we need to reanalyze the
2187 -- parameter type to create local entities for the signature of
2188 -- the subprogram type. Using the entities of the overriding
2189 -- subprogram will result in out-of-scope errors in the back-end.
2191 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2192 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2195 New_Reference_To (Etype (Parameter_Type (Formal)), Loc);
2198 Append_To (New_Formals,
2199 Make_Parameter_Specification (Loc,
2200 Defining_Identifier =>
2201 Make_Defining_Identifier (Loc,
2202 Chars => Chars (Defining_Identifier (Formal))),
2203 In_Present => In_Present (Formal),
2204 Out_Present => Out_Present (Formal),
2205 Parameter_Type => Param_Type));
2211 end Replicate_Formals;
2213 -- Start of processing for Build_Wrapper_Spec
2216 -- There is no point in building wrappers for non-tagged concurrent
2219 pragma Assert (Is_Tagged_Type (Obj_Typ));
2221 -- An entry or a protected procedure can override a routine where the
2222 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2223 -- type. Since the wrapper must have the exact same signature as that of
2224 -- the overridden subprogram, we try to find the overriding candidate
2225 -- and use its controlling formal.
2227 First_Param := Empty;
2229 -- Check every implemented interface
2231 if Present (Interfaces (Obj_Typ)) then
2232 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2233 Search : while Present (Iface_Elmt) loop
2234 Iface := Node (Iface_Elmt);
2236 -- Check every interface primitive
2238 if Present (Primitive_Operations (Iface)) then
2239 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2240 while Present (Iface_Op_Elmt) loop
2241 Iface_Op := Node (Iface_Op_Elmt);
2243 -- Ignore predefined primitives
2245 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2246 Iface_Op := Ultimate_Alias (Iface_Op);
2248 -- The current primitive operation can be overridden by
2249 -- the generated entry wrapper.
2251 if Overriding_Possible (Iface_Op, Subp_Id) then
2253 First (Parameter_Specifications (Parent (Iface_Op)));
2259 Next_Elmt (Iface_Op_Elmt);
2263 Next_Elmt (Iface_Elmt);
2267 -- If the subprogram to be wrapped is not overriding anything or is not
2268 -- a primitive declared between two views, do not produce anything. This
2269 -- avoids spurious errors involving overriding.
2272 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2278 Wrapper_Id : constant Entity_Id :=
2279 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2280 New_Formals : List_Id;
2281 Obj_Param : Node_Id;
2282 Obj_Param_Typ : Entity_Id;
2285 -- Minimum decoration is needed to catch the entity in
2286 -- Sem_Ch6.Override_Dispatching_Operation.
2288 if Ekind (Subp_Id) = E_Function then
2289 Set_Ekind (Wrapper_Id, E_Function);
2291 Set_Ekind (Wrapper_Id, E_Procedure);
2294 Set_Is_Primitive_Wrapper (Wrapper_Id);
2295 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2296 Set_Is_Private_Primitive (Wrapper_Id,
2297 Is_Private_Primitive_Subprogram (Subp_Id));
2299 -- Process the formals
2301 New_Formals := Replicate_Formals (Loc, Formals);
2303 -- A function with a controlling result and no first controlling
2304 -- formal needs no additional parameter.
2306 if Has_Controlling_Result (Subp_Id)
2308 (No (First_Formal (Subp_Id))
2309 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2313 -- Routine Subp_Id has been found to override an interface primitive.
2314 -- If the interface operation has an access parameter, create a copy
2315 -- of it, with the same null exclusion indicator if present.
2317 elsif Present (First_Param) then
2318 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2320 Make_Access_Definition (Loc,
2322 New_Reference_To (Obj_Typ, Loc));
2323 Set_Null_Exclusion_Present (Obj_Param_Typ,
2324 Null_Exclusion_Present (Parameter_Type (First_Param)));
2327 Obj_Param_Typ := New_Reference_To (Obj_Typ, Loc);
2331 Make_Parameter_Specification (Loc,
2332 Defining_Identifier =>
2333 Make_Defining_Identifier (Loc,
2335 In_Present => In_Present (First_Param),
2336 Out_Present => Out_Present (First_Param),
2337 Parameter_Type => Obj_Param_Typ);
2339 Prepend_To (New_Formals, Obj_Param);
2341 -- If we are dealing with a primitive declared between two views,
2342 -- implemented by a synchronized operation, we need to create
2343 -- a default parameter. The mode of the parameter must match that
2344 -- of the primitive operation.
2347 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2349 Make_Parameter_Specification (Loc,
2350 Defining_Identifier =>
2351 Make_Defining_Identifier (Loc, Name_uO),
2352 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2353 Out_Present => Ekind (Subp_Id) /= E_Function,
2354 Parameter_Type => New_Reference_To (Obj_Typ, Loc));
2355 Prepend_To (New_Formals, Obj_Param);
2358 -- Build the final spec. If it is a function with a controlling
2359 -- result, it is a primitive operation of the corresponding
2360 -- record type, so mark the spec accordingly.
2362 if Ekind (Subp_Id) = E_Function then
2367 if Has_Controlling_Result (Subp_Id) then
2370 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2372 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2376 Make_Function_Specification (Loc,
2377 Defining_Unit_Name => Wrapper_Id,
2378 Parameter_Specifications => New_Formals,
2379 Result_Definition => Res_Def);
2383 Make_Procedure_Specification (Loc,
2384 Defining_Unit_Name => Wrapper_Id,
2385 Parameter_Specifications => New_Formals);
2388 end Build_Wrapper_Spec;
2390 -------------------------
2391 -- Build_Wrapper_Specs --
2392 -------------------------
2394 procedure Build_Wrapper_Specs
2400 Rec_Typ : Entity_Id;
2401 procedure Scan_Declarations (L : List_Id);
2402 -- Common processing for visible and private declarations
2403 -- of a protected type.
2405 procedure Scan_Declarations (L : List_Id) is
2407 Wrap_Decl : Node_Id;
2408 Wrap_Spec : Node_Id;
2416 while Present (Decl) loop
2419 if Nkind (Decl) = N_Entry_Declaration
2420 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2424 (Subp_Id => Defining_Identifier (Decl),
2426 Formals => Parameter_Specifications (Decl));
2428 elsif Nkind (Decl) = N_Subprogram_Declaration then
2431 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2434 Parameter_Specifications (Specification (Decl)));
2437 if Present (Wrap_Spec) then
2439 Make_Subprogram_Declaration (Loc,
2440 Specification => Wrap_Spec);
2442 Insert_After (N, Wrap_Decl);
2445 Analyze (Wrap_Decl);
2450 end Scan_Declarations;
2452 -- start of processing for Build_Wrapper_Specs
2455 if Is_Protected_Type (Typ) then
2456 Def := Protected_Definition (Parent (Typ));
2457 else pragma Assert (Is_Task_Type (Typ));
2458 Def := Task_Definition (Parent (Typ));
2461 Rec_Typ := Corresponding_Record_Type (Typ);
2463 -- Generate wrapper specs for a concurrent type which implements an
2464 -- interface. Operations in both the visible and private parts may
2465 -- implement progenitor operations.
2467 if Present (Interfaces (Rec_Typ))
2468 and then Present (Def)
2470 Scan_Declarations (Visible_Declarations (Def));
2471 Scan_Declarations (Private_Declarations (Def));
2473 end Build_Wrapper_Specs;
2475 ---------------------------
2476 -- Build_Find_Body_Index --
2477 ---------------------------
2479 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2480 Loc : constant Source_Ptr := Sloc (Typ);
2483 Has_F : Boolean := False;
2485 If_St : Node_Id := Empty;
2488 Decls : List_Id := New_List;
2491 Siz : Node_Id := Empty;
2493 procedure Add_If_Clause (Expr : Node_Id);
2494 -- Add test for range of current entry
2496 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2497 -- If a bound of an entry is given by a discriminant, retrieve the
2498 -- actual value of the discriminant from the enclosing object.
2504 procedure Add_If_Clause (Expr : Node_Id) is
2506 Stats : constant List_Id :=
2508 Make_Simple_Return_Statement (Loc,
2509 Expression => Make_Integer_Literal (Loc, Index + 1)));
2512 -- Index for current entry body
2516 -- Compute total length of entry queues so far
2524 Right_Opnd => Expr);
2529 Left_Opnd => Make_Identifier (Loc, Name_uE),
2532 -- Map entry queue indexes in the range of the current family
2533 -- into the current index, that designates the entry body.
2537 Make_Implicit_If_Statement (Typ,
2539 Then_Statements => Stats,
2540 Elsif_Parts => New_List);
2546 Make_Elsif_Part (Loc,
2548 Then_Statements => Stats),
2549 Elsif_Parts (If_St));
2553 ------------------------------
2554 -- Convert_Discriminant_Ref --
2555 ------------------------------
2557 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2561 if Is_Entity_Name (Bound)
2562 and then Ekind (Entity (Bound)) = E_Discriminant
2565 Make_Selected_Component (Loc,
2567 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2568 Make_Explicit_Dereference (Loc,
2569 Make_Identifier (Loc, Name_uObject))),
2570 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2571 Set_Etype (B, Etype (Entity (Bound)));
2573 B := New_Copy_Tree (Bound);
2577 end Convert_Discriminant_Ref;
2579 -- Start of processing for Build_Find_Body_Index
2582 Spec := Build_Find_Body_Index_Spec (Typ);
2584 Ent := First_Entity (Typ);
2585 while Present (Ent) loop
2586 if Ekind (Ent) = E_Entry_Family then
2596 -- If the protected type has no entry families, there is a one-one
2597 -- correspondence between entry queue and entry body.
2600 Make_Simple_Return_Statement (Loc,
2601 Expression => Make_Identifier (Loc, Name_uE));
2604 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2607 -- if E <= l1 then return 1;
2608 -- elsif E <= l1 + l2 then return 2;
2613 Ent := First_Entity (Typ);
2615 Add_Object_Pointer (Loc, Typ, Decls);
2617 while Present (Ent) loop
2618 if Ekind (Ent) = E_Entry then
2619 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2621 elsif Ekind (Ent) = E_Entry_Family then
2622 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2623 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2624 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2625 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2634 Make_Simple_Return_Statement (Loc,
2635 Expression => Make_Integer_Literal (Loc, 1));
2637 elsif Nkind (Ret) = N_If_Statement then
2639 -- Ranges are in increasing order, so last one doesn't need guard
2642 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2645 Set_Else_Statements (Ret, Then_Statements (Nod));
2651 Make_Subprogram_Body (Loc,
2652 Specification => Spec,
2653 Declarations => Decls,
2654 Handled_Statement_Sequence =>
2655 Make_Handled_Sequence_Of_Statements (Loc,
2656 Statements => New_List (Ret)));
2657 end Build_Find_Body_Index;
2659 --------------------------------
2660 -- Build_Find_Body_Index_Spec --
2661 --------------------------------
2663 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2664 Loc : constant Source_Ptr := Sloc (Typ);
2665 Id : constant Entity_Id :=
2666 Make_Defining_Identifier (Loc,
2667 Chars => New_External_Name (Chars (Typ), 'F'));
2668 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2669 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2673 Make_Function_Specification (Loc,
2674 Defining_Unit_Name => Id,
2675 Parameter_Specifications => New_List (
2676 Make_Parameter_Specification (Loc,
2677 Defining_Identifier => Parm1,
2679 New_Reference_To (RTE (RE_Address), Loc)),
2681 Make_Parameter_Specification (Loc,
2682 Defining_Identifier => Parm2,
2684 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))),
2685 Result_Definition => New_Occurrence_Of (
2686 RTE (RE_Protected_Entry_Index), Loc));
2687 end Build_Find_Body_Index_Spec;
2689 -------------------------
2690 -- Build_Master_Entity --
2691 -------------------------
2693 procedure Build_Master_Entity (E : Entity_Id) is
2694 Loc : constant Source_Ptr := Sloc (E);
2700 S := Find_Master_Scope (E);
2702 -- Nothing to do if we already built a master entity for this scope
2703 -- or if there is no task hierarchy.
2705 if Has_Master_Entity (S)
2706 or else Restriction_Active (No_Task_Hierarchy)
2711 -- Otherwise first build the master entity
2712 -- _Master : constant Master_Id := Current_Master.all;
2713 -- and insert it just before the current declaration
2716 Make_Object_Declaration (Loc,
2717 Defining_Identifier =>
2718 Make_Defining_Identifier (Loc, Name_uMaster),
2719 Constant_Present => True,
2720 Object_Definition => New_Reference_To (RTE (RE_Master_Id), Loc),
2722 Make_Explicit_Dereference (Loc,
2723 New_Reference_To (RTE (RE_Current_Master), Loc)));
2726 Insert_Before (P, Decl);
2729 Set_Has_Master_Entity (S);
2731 -- Now mark the containing scope as a task master
2733 while Nkind (P) /= N_Compilation_Unit loop
2736 -- If we fall off the top, we are at the outer level, and the
2737 -- environment task is our effective master, so nothing to mark.
2740 (P, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
2742 Set_Is_Task_Master (P, True);
2745 elsif Nkind (Parent (P)) = N_Subunit then
2746 P := Corresponding_Stub (Parent (P));
2749 end Build_Master_Entity;
2751 -----------------------------------------
2752 -- Build_Private_Protected_Declaration --
2753 -----------------------------------------
2755 function Build_Private_Protected_Declaration
2756 (N : Node_Id) return Entity_Id
2758 Loc : constant Source_Ptr := Sloc (N);
2759 Body_Id : constant Entity_Id := Defining_Entity (N);
2764 Spec_Id : Entity_Id;
2767 Formal := First_Formal (Body_Id);
2769 -- The protected operation always has at least one formal, namely the
2770 -- object itself, but it is only placed in the parameter list if
2771 -- expansion is enabled.
2773 if Present (Formal) or else Expander_Active then
2774 Plist := Copy_Parameter_List (Body_Id);
2779 if Nkind (Specification (N)) = N_Procedure_Specification then
2781 Make_Procedure_Specification (Loc,
2782 Defining_Unit_Name =>
2783 Make_Defining_Identifier (Sloc (Body_Id),
2784 Chars => Chars (Body_Id)),
2785 Parameter_Specifications =>
2789 Make_Function_Specification (Loc,
2790 Defining_Unit_Name =>
2791 Make_Defining_Identifier (Sloc (Body_Id),
2792 Chars => Chars (Body_Id)),
2793 Parameter_Specifications => Plist,
2794 Result_Definition =>
2795 New_Occurrence_Of (Etype (Body_Id), Loc));
2798 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
2799 Insert_Before (N, Decl);
2800 Spec_Id := Defining_Unit_Name (New_Spec);
2802 -- Indicate that the entity comes from source, to ensure that cross-
2803 -- reference information is properly generated. The body itself is
2804 -- rewritten during expansion, and the body entity will not appear in
2805 -- calls to the operation.
2807 Set_Comes_From_Source (Spec_Id, True);
2809 Set_Has_Completion (Spec_Id);
2810 Set_Convention (Spec_Id, Convention_Protected);
2812 end Build_Private_Protected_Declaration;
2814 ---------------------------
2815 -- Build_Protected_Entry --
2816 ---------------------------
2818 function Build_Protected_Entry
2821 Pid : Node_Id) return Node_Id
2823 Loc : constant Source_Ptr := Sloc (N);
2825 Decls : constant List_Id := Declarations (N);
2826 End_Lab : constant Node_Id :=
2827 End_Label (Handled_Statement_Sequence (N));
2828 End_Loc : constant Source_Ptr :=
2829 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
2830 -- Used for the generated call to Complete_Entry_Body
2832 Han_Loc : Source_Ptr;
2833 -- Used for the exception handler, inserted at end of the body
2835 Op_Decls : constant List_Id := New_List;
2843 -- Set the source location on the exception handler only when debugging
2844 -- the expanded code (see Make_Implicit_Exception_Handler).
2846 if Debug_Generated_Code then
2849 -- Otherwise the inserted code should not be visible to the debugger
2852 Han_Loc := No_Location;
2856 Make_Defining_Identifier (Loc,
2857 Chars => Chars (Protected_Body_Subprogram (Ent)));
2859 Build_Protected_Entry_Specification (Loc, Edef, Empty);
2861 -- Add the following declarations:
2862 -- type poVP is access poV;
2863 -- _object : poVP := poVP (_O);
2865 -- where _O is the formal parameter associated with the concurrent
2866 -- object. These declarations are needed for Complete_Entry_Body.
2868 Add_Object_Pointer (Loc, Pid, Op_Decls);
2870 -- Add renamings for all formals, the Protection object, discriminals,
2871 -- privals and the entry index constant for use by debugger.
2873 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
2874 Debug_Private_Data_Declarations (Decls);
2876 case Corresponding_Runtime_Package (Pid) is
2877 when System_Tasking_Protected_Objects_Entries =>
2879 New_Reference_To (RTE (RE_Complete_Entry_Body), Loc);
2881 when System_Tasking_Protected_Objects_Single_Entry =>
2883 New_Reference_To (RTE (RE_Complete_Single_Entry_Body), Loc);
2886 raise Program_Error;
2889 Op_Stats := New_List (
2890 Make_Block_Statement (Loc,
2891 Declarations => Decls,
2892 Handled_Statement_Sequence =>
2893 Handled_Statement_Sequence (N)),
2895 Make_Procedure_Call_Statement (End_Loc,
2897 Parameter_Associations => New_List (
2898 Make_Attribute_Reference (End_Loc,
2900 Make_Selected_Component (End_Loc,
2901 Prefix => Make_Identifier (End_Loc, Name_uObject),
2902 Selector_Name => Make_Identifier (End_Loc, Name_uObject)),
2903 Attribute_Name => Name_Unchecked_Access))));
2905 -- When exceptions can not be propagated, we never need to call
2906 -- Exception_Complete_Entry_Body
2908 if No_Exception_Handlers_Set then
2910 Make_Subprogram_Body (Loc,
2911 Specification => Espec,
2912 Declarations => Op_Decls,
2913 Handled_Statement_Sequence =>
2914 Make_Handled_Sequence_Of_Statements (Loc,
2915 Statements => Op_Stats,
2916 End_Label => End_Lab));
2919 Ohandle := Make_Others_Choice (Loc);
2920 Set_All_Others (Ohandle);
2922 case Corresponding_Runtime_Package (Pid) is
2923 when System_Tasking_Protected_Objects_Entries =>
2926 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
2928 when System_Tasking_Protected_Objects_Single_Entry =>
2931 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
2934 raise Program_Error;
2937 -- Establish link between subprogram body entity and source entry.
2939 Set_Corresponding_Protected_Entry (Edef, Ent);
2941 -- Create body of entry procedure. The renaming declarations are
2942 -- placed ahead of the block that contains the actual entry body.
2945 Make_Subprogram_Body (Loc,
2946 Specification => Espec,
2947 Declarations => Op_Decls,
2948 Handled_Statement_Sequence =>
2949 Make_Handled_Sequence_Of_Statements (Loc,
2950 Statements => Op_Stats,
2951 End_Label => End_Lab,
2952 Exception_Handlers => New_List (
2953 Make_Implicit_Exception_Handler (Han_Loc,
2954 Exception_Choices => New_List (Ohandle),
2956 Statements => New_List (
2957 Make_Procedure_Call_Statement (Han_Loc,
2959 Parameter_Associations => New_List (
2960 Make_Attribute_Reference (Han_Loc,
2962 Make_Selected_Component (Han_Loc,
2964 Make_Identifier (Han_Loc, Name_uObject),
2966 Make_Identifier (Han_Loc, Name_uObject)),
2967 Attribute_Name => Name_Unchecked_Access),
2969 Make_Function_Call (Han_Loc,
2970 Name => New_Reference_To (
2971 RTE (RE_Get_GNAT_Exception), Loc)))))))));
2973 end Build_Protected_Entry;
2975 -----------------------------------------
2976 -- Build_Protected_Entry_Specification --
2977 -----------------------------------------
2979 function Build_Protected_Entry_Specification
2982 Ent_Id : Entity_Id) return Node_Id
2984 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
2987 Set_Debug_Info_Needed (Def_Id);
2989 if Present (Ent_Id) then
2990 Append_Elmt (P, Accept_Address (Ent_Id));
2994 Make_Procedure_Specification (Loc,
2995 Defining_Unit_Name => Def_Id,
2996 Parameter_Specifications => New_List (
2997 Make_Parameter_Specification (Loc,
2998 Defining_Identifier =>
2999 Make_Defining_Identifier (Loc, Name_uO),
3001 New_Reference_To (RTE (RE_Address), Loc)),
3003 Make_Parameter_Specification (Loc,
3004 Defining_Identifier => P,
3006 New_Reference_To (RTE (RE_Address), Loc)),
3008 Make_Parameter_Specification (Loc,
3009 Defining_Identifier =>
3010 Make_Defining_Identifier (Loc, Name_uE),
3012 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc))));
3013 end Build_Protected_Entry_Specification;
3015 --------------------------
3016 -- Build_Protected_Spec --
3017 --------------------------
3019 function Build_Protected_Spec
3021 Obj_Type : Entity_Id;
3023 Unprotected : Boolean := False) return List_Id
3025 Loc : constant Source_Ptr := Sloc (N);
3028 New_Plist : List_Id;
3029 New_Param : Node_Id;
3032 New_Plist := New_List;
3034 Formal := First_Formal (Ident);
3035 while Present (Formal) loop
3037 Make_Parameter_Specification (Loc,
3038 Defining_Identifier =>
3039 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
3040 In_Present => In_Present (Parent (Formal)),
3041 Out_Present => Out_Present (Parent (Formal)),
3042 Parameter_Type => New_Reference_To (Etype (Formal), Loc));
3045 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3048 Append (New_Param, New_Plist);
3049 Next_Formal (Formal);
3052 -- If the subprogram is a procedure and the context is not an access
3053 -- to protected subprogram, the parameter is in-out. Otherwise it is
3057 Make_Parameter_Specification (Loc,
3058 Defining_Identifier =>
3059 Make_Defining_Identifier (Loc, Name_uObject),
3062 (Etype (Ident) = Standard_Void_Type
3063 and then not Is_RTE (Obj_Type, RE_Address)),
3065 New_Reference_To (Obj_Type, Loc));
3066 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3067 Prepend_To (New_Plist, Decl);
3070 end Build_Protected_Spec;
3072 ---------------------------------------
3073 -- Build_Protected_Sub_Specification --
3074 ---------------------------------------
3076 function Build_Protected_Sub_Specification
3078 Prot_Typ : Entity_Id;
3079 Mode : Subprogram_Protection_Mode) return Node_Id
3081 Loc : constant Source_Ptr := Sloc (N);
3085 New_Plist : List_Id;
3088 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3089 (Dispatching_Mode => ' ',
3090 Protected_Mode => 'P',
3091 Unprotected_Mode => 'N');
3094 if Ekind (Defining_Unit_Name (Specification (N))) =
3097 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3102 Def_Id := Defining_Unit_Name (Specification (Decl));
3105 Build_Protected_Spec
3106 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3107 Mode = Unprotected_Mode);
3109 Make_Defining_Identifier (Loc,
3110 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3112 -- The unprotected operation carries the user code, and debugging
3113 -- information must be generated for it, even though this spec does
3114 -- not come from source. It is also convenient to allow gdb to step
3115 -- into the protected operation, even though it only contains lock/
3118 Set_Debug_Info_Needed (New_Id);
3120 -- If a pragma Eliminate applies to the source entity, the internal
3121 -- subprograms will be eliminated as well.
3123 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3125 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3127 Make_Procedure_Specification (Loc,
3128 Defining_Unit_Name => New_Id,
3129 Parameter_Specifications => New_Plist);
3131 -- Create a new specification for the anonymous subprogram type
3135 Make_Function_Specification (Loc,
3136 Defining_Unit_Name => New_Id,
3137 Parameter_Specifications => New_Plist,
3138 Result_Definition =>
3139 Copy_Result_Type (Result_Definition (Specification (Decl))));
3141 Set_Return_Present (Defining_Unit_Name (New_Spec));
3145 end Build_Protected_Sub_Specification;
3147 -------------------------------------
3148 -- Build_Protected_Subprogram_Body --
3149 -------------------------------------
3151 function Build_Protected_Subprogram_Body
3154 N_Op_Spec : Node_Id) return Node_Id
3156 Loc : constant Source_Ptr := Sloc (N);
3158 P_Op_Spec : Node_Id;
3161 Unprot_Call : Node_Id;
3163 Lock_Name : Node_Id;
3164 Lock_Stmt : Node_Id;
3165 Service_Name : Node_Id;
3167 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3168 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3170 Object_Parm : Node_Id;
3173 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
3174 -- Tell whether a given subprogram cannot raise an exception
3176 -----------------------
3177 -- Is_Exception_Safe --
3178 -----------------------
3180 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
3182 function Has_Side_Effect (N : Node_Id) return Boolean;
3183 -- Return True whenever encountering a subprogram call or raise
3184 -- statement of any kind in the sequence of statements
3186 ---------------------
3187 -- Has_Side_Effect --
3188 ---------------------
3190 -- What is this doing buried two levels down in exp_ch9. It seems
3191 -- like a generally useful function, and indeed there may be code
3192 -- duplication going on here ???
3194 function Has_Side_Effect (N : Node_Id) return Boolean is
3198 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
3199 -- Indicate whether N is a subprogram call or a raise statement
3201 ----------------------
3202 -- Is_Call_Or_Raise --
3203 ----------------------
3205 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
3207 return Nkind_In (N, N_Procedure_Call_Statement,
3210 N_Raise_Constraint_Error,
3211 N_Raise_Program_Error,
3212 N_Raise_Storage_Error);
3213 end Is_Call_Or_Raise;
3215 -- Start of processing for Has_Side_Effect
3219 while Present (Stmt) loop
3220 if Is_Call_Or_Raise (Stmt) then
3224 -- An object declaration can also contain a function call
3225 -- or a raise statement
3227 if Nkind (Stmt) = N_Object_Declaration then
3228 Expr := Expression (Stmt);
3230 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
3239 end Has_Side_Effect;
3241 -- Start of processing for Is_Exception_Safe
3244 -- If the checks handled by the back end are not disabled, we cannot
3245 -- ensure that no exception will be raised.
3247 if not Access_Checks_Suppressed (Empty)
3248 or else not Discriminant_Checks_Suppressed (Empty)
3249 or else not Range_Checks_Suppressed (Empty)
3250 or else not Index_Checks_Suppressed (Empty)
3251 or else Opt.Stack_Checking_Enabled
3256 if Has_Side_Effect (First (Declarations (Subprogram)))
3259 First (Statements (Handled_Statement_Sequence (Subprogram))))
3265 end Is_Exception_Safe;
3267 -- Start of processing for Build_Protected_Subprogram_Body
3270 Op_Spec := Specification (N);
3271 Exc_Safe := Is_Exception_Safe (N);
3274 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3276 -- Build a list of the formal parameters of the protected version of
3277 -- the subprogram to use as the actual parameters of the unprotected
3280 Uactuals := New_List;
3281 Pformal := First (Parameter_Specifications (P_Op_Spec));
3282 while Present (Pformal) loop
3283 Append_To (Uactuals,
3284 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
3288 -- Make a call to the unprotected version of the subprogram built above
3289 -- for use by the protected version built below.
3291 if Nkind (Op_Spec) = N_Function_Specification then
3293 R := Make_Temporary (Loc, 'R');
3295 Make_Object_Declaration (Loc,
3296 Defining_Identifier => R,
3297 Constant_Present => True,
3298 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
3300 Make_Function_Call (Loc,
3301 Name => Make_Identifier (Loc,
3302 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3303 Parameter_Associations => Uactuals));
3306 Make_Simple_Return_Statement (Loc,
3307 Expression => New_Reference_To (R, Loc));
3310 Unprot_Call := Make_Simple_Return_Statement (Loc,
3311 Expression => Make_Function_Call (Loc,
3313 Make_Identifier (Loc,
3314 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3315 Parameter_Associations => Uactuals));
3320 Make_Procedure_Call_Statement (Loc,
3322 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3323 Parameter_Associations => Uactuals);
3326 -- Wrap call in block that will be covered by an at_end handler
3328 if not Exc_Safe then
3329 Unprot_Call := Make_Block_Statement (Loc,
3330 Handled_Statement_Sequence =>
3331 Make_Handled_Sequence_Of_Statements (Loc,
3332 Statements => New_List (Unprot_Call)));
3335 -- Make the protected subprogram body. This locks the protected
3336 -- object and calls the unprotected version of the subprogram.
3338 case Corresponding_Runtime_Package (Pid) is
3339 when System_Tasking_Protected_Objects_Entries =>
3340 Lock_Name := New_Reference_To (RTE (RE_Lock_Entries), Loc);
3341 Service_Name := New_Reference_To (RTE (RE_Service_Entries), Loc);
3343 when System_Tasking_Protected_Objects_Single_Entry =>
3344 Lock_Name := New_Reference_To (RTE (RE_Lock_Entry), Loc);
3345 Service_Name := New_Reference_To (RTE (RE_Service_Entry), Loc);
3347 when System_Tasking_Protected_Objects =>
3348 Lock_Name := New_Reference_To (RTE (RE_Lock), Loc);
3349 Service_Name := New_Reference_To (RTE (RE_Unlock), Loc);
3352 raise Program_Error;
3356 Make_Attribute_Reference (Loc,
3358 Make_Selected_Component (Loc,
3359 Prefix => Make_Identifier (Loc, Name_uObject),
3360 Selector_Name => Make_Identifier (Loc, Name_uObject)),
3361 Attribute_Name => Name_Unchecked_Access);
3363 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
3365 Parameter_Associations => New_List (Object_Parm));
3367 if Abort_Allowed then
3369 Make_Procedure_Call_Statement (Loc,
3370 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
3371 Parameter_Associations => Empty_List),
3375 Stmts := New_List (Lock_Stmt);
3378 if not Exc_Safe then
3379 Append (Unprot_Call, Stmts);
3381 if Nkind (Op_Spec) = N_Function_Specification then
3383 Stmts := Empty_List;
3385 Append (Unprot_Call, Stmts);
3389 Make_Procedure_Call_Statement (Loc,
3390 Name => Service_Name,
3391 Parameter_Associations =>
3392 New_List (New_Copy_Tree (Object_Parm))),
3395 if Abort_Allowed then
3397 Make_Procedure_Call_Statement (Loc,
3398 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc),
3399 Parameter_Associations => Empty_List),
3403 if Nkind (Op_Spec) = N_Function_Specification then
3404 Append (Return_Stmt, Stmts);
3405 Append (Make_Block_Statement (Loc,
3406 Declarations => New_List (Unprot_Call),
3407 Handled_Statement_Sequence =>
3408 Make_Handled_Sequence_Of_Statements (Loc,
3409 Statements => Stmts)), Pre_Stmts);
3415 Make_Subprogram_Body (Loc,
3416 Declarations => Empty_List,
3417 Specification => P_Op_Spec,
3418 Handled_Statement_Sequence =>
3419 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
3421 if not Exc_Safe then
3422 Set_Is_Protected_Subprogram_Body (Sub_Body);
3426 end Build_Protected_Subprogram_Body;
3428 -------------------------------------
3429 -- Build_Protected_Subprogram_Call --
3430 -------------------------------------
3432 procedure Build_Protected_Subprogram_Call
3436 External : Boolean := True)
3438 Loc : constant Source_Ptr := Sloc (N);
3439 Sub : constant Entity_Id := Entity (Name);
3445 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
3448 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
3451 if Present (Parameter_Associations (N)) then
3452 Params := New_Copy_List_Tree (Parameter_Associations (N));
3457 -- If the type is an untagged derived type, convert to the root type,
3458 -- which is the one on which the operations are defined.
3460 if Nkind (Rec) = N_Unchecked_Type_Conversion
3461 and then not Is_Tagged_Type (Etype (Rec))
3462 and then Is_Derived_Type (Etype (Rec))
3464 Set_Etype (Rec, Root_Type (Etype (Rec)));
3465 Set_Subtype_Mark (Rec,
3466 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
3469 Prepend (Rec, Params);
3471 if Ekind (Sub) = E_Procedure then
3473 Make_Procedure_Call_Statement (Loc,
3475 Parameter_Associations => Params));
3478 pragma Assert (Ekind (Sub) = E_Function);
3480 Make_Function_Call (Loc,
3482 Parameter_Associations => Params));
3486 and then Nkind (Rec) = N_Unchecked_Type_Conversion
3487 and then Is_Entity_Name (Expression (Rec))
3488 and then Is_Shared_Passive (Entity (Expression (Rec)))
3490 Add_Shared_Var_Lock_Procs (N);
3492 end Build_Protected_Subprogram_Call;
3494 -------------------------
3495 -- Build_Selected_Name --
3496 -------------------------
3498 function Build_Selected_Name
3499 (Prefix : Entity_Id;
3500 Selector : Entity_Id;
3501 Append_Char : Character := ' ') return Name_Id
3503 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
3504 Select_Len : Natural;
3507 Get_Name_String (Chars (Selector));
3508 Select_Len := Name_Len;
3509 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
3510 Get_Name_String (Chars (Prefix));
3512 -- If scope is anonymous type, discard suffix to recover name of
3513 -- single protected object. Otherwise use protected type name.
3515 if Name_Buffer (Name_Len) = 'T' then
3516 Name_Len := Name_Len - 1;
3519 Add_Str_To_Name_Buffer ("__");
3520 for J in 1 .. Select_Len loop
3521 Add_Char_To_Name_Buffer (Select_Buffer (J));
3524 -- Now add the Append_Char if specified. The encoding to follow
3525 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
3526 -- then the entity is associated to a protected type subprogram.
3527 -- Otherwise, it is a protected type entry. For each case, the
3528 -- encoding to follow for the suffix is documented in exp_dbug.ads.
3530 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
3532 if Append_Char /= ' ' then
3533 if Append_Char = 'P' or Append_Char = 'N' then
3534 Add_Char_To_Name_Buffer (Append_Char);
3537 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
3538 return New_External_Name (Name_Find, ' ', -1);
3543 end Build_Selected_Name;
3545 -----------------------------
3546 -- Build_Simple_Entry_Call --
3547 -----------------------------
3549 -- A task entry call is converted to a call to Call_Simple
3552 -- P : parms := (parm, parm, parm);
3554 -- Call_Simple (acceptor-task, entry-index, P'Address);
3560 -- Here Pnn is an aggregate of the type constructed for the entry to hold
3561 -- the parameters, and the constructed aggregate value contains either the
3562 -- parameters or, in the case of non-elementary types, references to these
3563 -- parameters. Then the address of this aggregate is passed to the runtime
3564 -- routine, along with the task id value and the task entry index value.
3565 -- Pnn is only required if parameters are present.
3567 -- The assignments after the call are present only in the case of in-out
3568 -- or out parameters for elementary types, and are used to assign back the
3569 -- resulting values of such parameters.
3571 -- Note: the reason that we insert a block here is that in the context
3572 -- of selects, conditional entry calls etc. the entry call statement
3573 -- appears on its own, not as an element of a list.
3575 -- A protected entry call is converted to a Protected_Entry_Call:
3578 -- P : E1_Params := (param, param, param);
3580 -- Bnn : Communications_Block;
3583 -- P : E1_Params := (param, param, param);
3584 -- Bnn : Communications_Block;
3587 -- Protected_Entry_Call (
3588 -- Object => po._object'Access,
3589 -- E => <entry index>;
3590 -- Uninterpreted_Data => P'Address;
3591 -- Mode => Simple_Call;
3598 procedure Build_Simple_Entry_Call
3607 -- If call has been inlined, nothing left to do
3609 if Nkind (N) = N_Block_Statement then
3613 -- Convert entry call to Call_Simple call
3616 Loc : constant Source_Ptr := Sloc (N);
3617 Parms : constant List_Id := Parameter_Associations (N);
3618 Stats : constant List_Id := New_List;
3621 Comm_Name : Entity_Id;
3625 Ent_Acc : Entity_Id;
3627 Iface_Tag : Entity_Id;
3628 Iface_Typ : Entity_Id;
3641 -- Simple entry and entry family cases merge here
3643 Ent := Entity (Ename);
3644 Ent_Acc := Entry_Parameters_Type (Ent);
3645 Conctyp := Etype (Concval);
3647 -- If prefix is an access type, dereference to obtain the task type
3649 if Is_Access_Type (Conctyp) then
3650 Conctyp := Designated_Type (Conctyp);
3653 -- Special case for protected subprogram calls
3655 if Is_Protected_Type (Conctyp)
3656 and then Is_Subprogram (Entity (Ename))
3658 if not Is_Eliminated (Entity (Ename)) then
3659 Build_Protected_Subprogram_Call
3660 (N, Ename, Convert_Concurrent (Concval, Conctyp));
3667 -- First parameter is the Task_Id value from the task value or the
3668 -- Object from the protected object value, obtained by selecting
3669 -- the _Task_Id or _Object from the result of doing an unchecked
3670 -- conversion to convert the value to the corresponding record type.
3672 if Nkind (Concval) = N_Function_Call
3673 and then Is_Task_Type (Conctyp)
3674 and then Ada_Version >= Ada_2005
3677 ExpR : constant Node_Id := Relocate_Node (Concval);
3678 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
3683 Make_Object_Declaration (Loc,
3684 Defining_Identifier => Obj,
3685 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
3686 Expression => ExpR);
3687 Set_Etype (Obj, Conctyp);
3688 Decls := New_List (Decl);
3689 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
3696 Parm1 := Concurrent_Ref (Concval);
3698 -- Second parameter is the entry index, computed by the routine
3699 -- provided for this purpose. The value of this expression is
3700 -- assigned to an intermediate variable to assure that any entry
3701 -- family index expressions are evaluated before the entry
3705 or else Restriction_Active (No_Entry_Queue) = False
3706 or else not Is_Protected_Type (Conctyp)
3707 or else Number_Entries (Conctyp) > 1
3708 or else (Has_Attach_Handler (Conctyp)
3709 and then not Restricted_Profile)
3711 X := Make_Defining_Identifier (Loc, Name_uX);
3714 Make_Object_Declaration (Loc,
3715 Defining_Identifier => X,
3716 Object_Definition =>
3717 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3718 Expression => Actual_Index_Expression (
3719 Loc, Entity (Ename), Index, Concval));
3721 Append_To (Decls, Xdecl);
3722 Parm2 := New_Reference_To (X, Loc);
3729 -- The third parameter is the packaged parameters. If there are
3730 -- none, then it is just the null address, since nothing is passed.
3733 Parm3 := New_Reference_To (RTE (RE_Null_Address), Loc);
3736 -- Case of parameters present, where third argument is the address
3737 -- of a packaged record containing the required parameter values.
3740 -- First build a list of parameter values, which are references to
3741 -- objects of the parameter types.
3745 Actual := First_Actual (N);
3746 Formal := First_Formal (Ent);
3748 while Present (Actual) loop
3750 -- If it is a by_copy_type, copy it to a new variable. The
3751 -- packaged record has a field that points to this variable.
3753 if Is_By_Copy_Type (Etype (Actual)) then
3755 Make_Object_Declaration (Loc,
3756 Defining_Identifier => Make_Temporary (Loc, 'J'),
3757 Aliased_Present => True,
3758 Object_Definition =>
3759 New_Reference_To (Etype (Formal), Loc));
3761 -- Mark the object as not needing initialization since the
3762 -- initialization is performed separately, avoiding errors
3763 -- on cases such as formals of null-excluding access types.
3765 Set_No_Initialization (N_Node);
3767 -- We must make an assignment statement separate for the
3768 -- case of limited type. We cannot assign it unless the
3769 -- Assignment_OK flag is set first. An out formal of an
3770 -- access type must also be initialized from the actual,
3771 -- as stated in RM 6.4.1 (13).
3773 if Ekind (Formal) /= E_Out_Parameter
3774 or else Is_Access_Type (Etype (Formal))
3777 New_Reference_To (Defining_Identifier (N_Node), Loc);
3778 Set_Assignment_OK (N_Var);
3780 Make_Assignment_Statement (Loc,
3782 Expression => Relocate_Node (Actual)));
3785 Append (N_Node, Decls);
3788 Make_Attribute_Reference (Loc,
3789 Attribute_Name => Name_Unchecked_Access,
3791 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3793 -- If it is a VM_By_Copy_Actual, copy it to a new variable
3795 elsif Is_VM_By_Copy_Actual (Actual) then
3797 Make_Object_Declaration (Loc,
3798 Defining_Identifier => Make_Temporary (Loc, 'J'),
3799 Aliased_Present => True,
3800 Object_Definition =>
3801 New_Reference_To (Etype (Formal), Loc),
3802 Expression => New_Copy_Tree (Actual));
3803 Set_Assignment_OK (N_Node);
3805 Append (N_Node, Decls);
3808 Make_Attribute_Reference (Loc,
3809 Attribute_Name => Name_Unchecked_Access,
3811 New_Reference_To (Defining_Identifier (N_Node), Loc)));
3814 -- Interface class-wide formal
3816 if Ada_Version >= Ada_2005
3817 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
3818 and then Is_Interface (Etype (Formal))
3820 Iface_Typ := Etype (Etype (Formal));
3823 -- formal_iface_type! (actual.iface_tag)'reference
3826 Find_Interface_Tag (Etype (Actual), Iface_Typ);
3827 pragma Assert (Present (Iface_Tag));
3830 Make_Reference (Loc,
3831 Unchecked_Convert_To (Iface_Typ,
3832 Make_Selected_Component (Loc,
3834 Relocate_Node (Actual),
3836 New_Reference_To (Iface_Tag, Loc)))));
3842 Make_Reference (Loc, Relocate_Node (Actual)));
3846 Next_Actual (Actual);
3847 Next_Formal_With_Extras (Formal);
3850 -- Now build the declaration of parameters initialized with the
3851 -- aggregate containing this constructed parameter list.
3853 P := Make_Defining_Identifier (Loc, Name_uP);
3856 Make_Object_Declaration (Loc,
3857 Defining_Identifier => P,
3858 Object_Definition =>
3859 New_Reference_To (Designated_Type (Ent_Acc), Loc),
3861 Make_Aggregate (Loc, Expressions => Plist));
3864 Make_Attribute_Reference (Loc,
3865 Prefix => New_Reference_To (P, Loc),
3866 Attribute_Name => Name_Address);
3868 Append (Pdecl, Decls);
3871 -- Now we can create the call, case of protected type
3873 if Is_Protected_Type (Conctyp) then
3874 case Corresponding_Runtime_Package (Conctyp) is
3875 when System_Tasking_Protected_Objects_Entries =>
3877 -- Change the type of the index declaration
3879 Set_Object_Definition (Xdecl,
3880 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc));
3882 -- Some additional declarations for protected entry calls
3888 -- Bnn : Communications_Block;
3890 Comm_Name := Make_Temporary (Loc, 'B');
3893 Make_Object_Declaration (Loc,
3894 Defining_Identifier => Comm_Name,
3895 Object_Definition =>
3896 New_Reference_To (RTE (RE_Communication_Block), Loc)));
3898 -- Some additional statements for protected entry calls
3900 -- Protected_Entry_Call (
3901 -- Object => po._object'Access,
3902 -- E => <entry index>;
3903 -- Uninterpreted_Data => P'Address;
3904 -- Mode => Simple_Call;
3908 Make_Procedure_Call_Statement (Loc,
3910 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
3912 Parameter_Associations => New_List (
3913 Make_Attribute_Reference (Loc,
3914 Attribute_Name => Name_Unchecked_Access,
3918 New_Reference_To (RTE (RE_Simple_Call), Loc),
3919 New_Occurrence_Of (Comm_Name, Loc)));
3921 when System_Tasking_Protected_Objects_Single_Entry =>
3922 -- Protected_Single_Entry_Call (
3923 -- Object => po._object'Access,
3924 -- Uninterpreted_Data => P'Address;
3925 -- Mode => Simple_Call);
3928 Make_Procedure_Call_Statement (Loc,
3929 Name => New_Reference_To (
3930 RTE (RE_Protected_Single_Entry_Call), Loc),
3932 Parameter_Associations => New_List (
3933 Make_Attribute_Reference (Loc,
3934 Attribute_Name => Name_Unchecked_Access,
3937 New_Reference_To (RTE (RE_Simple_Call), Loc)));
3940 raise Program_Error;
3943 -- Case of task type
3947 Make_Procedure_Call_Statement (Loc,
3948 Name => New_Reference_To (RTE (RE_Call_Simple), Loc),
3949 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
3953 Append_To (Stats, Call);
3955 -- If there are out or in/out parameters by copy add assignment
3956 -- statements for the result values.
3958 if Present (Parms) then
3959 Actual := First_Actual (N);
3960 Formal := First_Formal (Ent);
3962 Set_Assignment_OK (Actual);
3963 while Present (Actual) loop
3964 if (Is_By_Copy_Type (Etype (Actual))
3965 or else Is_VM_By_Copy_Actual (Actual))
3966 and then Ekind (Formal) /= E_In_Parameter
3969 Make_Assignment_Statement (Loc,
3970 Name => New_Copy (Actual),
3972 Make_Explicit_Dereference (Loc,
3973 Make_Selected_Component (Loc,
3974 Prefix => New_Reference_To (P, Loc),
3976 Make_Identifier (Loc, Chars (Formal)))));
3978 -- In all cases (including limited private types) we want
3979 -- the assignment to be valid.
3981 Set_Assignment_OK (Name (N_Node));
3983 -- If the call is the triggering alternative in an
3984 -- asynchronous select, or the entry_call alternative of a
3985 -- conditional entry call, the assignments for in-out
3986 -- parameters are incorporated into the statement list that
3987 -- follows, so that there are executed only if the entry
3990 if (Nkind (Parent (N)) = N_Triggering_Alternative
3991 and then N = Triggering_Statement (Parent (N)))
3993 (Nkind (Parent (N)) = N_Entry_Call_Alternative
3994 and then N = Entry_Call_Statement (Parent (N)))
3996 if No (Statements (Parent (N))) then
3997 Set_Statements (Parent (N), New_List);
4000 Prepend (N_Node, Statements (Parent (N)));
4003 Insert_After (Call, N_Node);
4007 Next_Actual (Actual);
4008 Next_Formal_With_Extras (Formal);
4012 -- Finally, create block and analyze it
4015 Make_Block_Statement (Loc,
4016 Declarations => Decls,
4017 Handled_Statement_Sequence =>
4018 Make_Handled_Sequence_Of_Statements (Loc,
4019 Statements => Stats)));
4023 end Build_Simple_Entry_Call;
4025 --------------------------------
4026 -- Build_Task_Activation_Call --
4027 --------------------------------
4029 procedure Build_Task_Activation_Call (N : Node_Id) is
4030 Loc : constant Source_Ptr := Sloc (N);
4037 -- Get the activation chain entity. Except in the case of a package
4038 -- body, this is in the node that was passed. For a package body, we
4039 -- have to find the corresponding package declaration node.
4041 if Nkind (N) = N_Package_Body then
4042 P := Corresponding_Spec (N);
4045 exit when Nkind (P) = N_Package_Declaration;
4048 Chain := Activation_Chain_Entity (P);
4051 Chain := Activation_Chain_Entity (N);
4054 if Present (Chain) then
4055 if Restricted_Profile then
4056 Name := New_Reference_To (RTE (RE_Activate_Restricted_Tasks), Loc);
4058 Name := New_Reference_To (RTE (RE_Activate_Tasks), Loc);
4062 Make_Procedure_Call_Statement (Loc,
4064 Parameter_Associations =>
4065 New_List (Make_Attribute_Reference (Loc,
4066 Prefix => New_Occurrence_Of (Chain, Loc),
4067 Attribute_Name => Name_Unchecked_Access)));
4069 if Nkind (N) = N_Package_Declaration then
4070 if Present (Corresponding_Body (N)) then
4073 elsif Present (Private_Declarations (Specification (N))) then
4074 Append (Call, Private_Declarations (Specification (N)));
4077 Append (Call, Visible_Declarations (Specification (N)));
4081 if Present (Handled_Statement_Sequence (N)) then
4083 -- The call goes at the start of the statement sequence
4084 -- after the start of exception range label if one is present.
4090 Stm := First (Statements (Handled_Statement_Sequence (N)));
4092 -- A special case, skip exception range label if one is
4093 -- present (from front end zcx processing).
4095 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4099 -- Another special case, if the first statement is a block
4100 -- from optimization of a local raise to a goto, then the
4101 -- call goes inside this block.
4103 if Nkind (Stm) = N_Block_Statement
4104 and then Exception_Junk (Stm)
4107 First (Statements (Handled_Statement_Sequence (Stm)));
4110 -- Insertion point is after any exception label pushes,
4111 -- since we want it covered by any local handlers.
4113 while Nkind (Stm) in N_Push_xxx_Label loop
4117 -- Now we have the proper insertion point
4119 Insert_Before (Stm, Call);
4123 Set_Handled_Statement_Sequence (N,
4124 Make_Handled_Sequence_Of_Statements (Loc,
4125 Statements => New_List (Call)));
4130 Check_Task_Activation (N);
4132 end Build_Task_Activation_Call;
4134 -------------------------------
4135 -- Build_Task_Allocate_Block --
4136 -------------------------------
4138 procedure Build_Task_Allocate_Block
4143 T : constant Entity_Id := Entity (Expression (N));
4144 Init : constant Entity_Id := Base_Init_Proc (T);
4145 Loc : constant Source_Ptr := Sloc (N);
4146 Chain : constant Entity_Id :=
4147 Make_Defining_Identifier (Loc, Name_uChain);
4148 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4153 Make_Block_Statement (Loc,
4154 Identifier => New_Reference_To (Blkent, Loc),
4155 Declarations => New_List (
4157 -- _Chain : Activation_Chain;
4159 Make_Object_Declaration (Loc,
4160 Defining_Identifier => Chain,
4161 Aliased_Present => True,
4162 Object_Definition =>
4163 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4165 Handled_Statement_Sequence =>
4166 Make_Handled_Sequence_Of_Statements (Loc,
4168 Statements => New_List (
4172 Make_Procedure_Call_Statement (Loc,
4173 Name => New_Reference_To (Init, Loc),
4174 Parameter_Associations => Args),
4176 -- Activate_Tasks (_Chain);
4178 Make_Procedure_Call_Statement (Loc,
4179 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4180 Parameter_Associations => New_List (
4181 Make_Attribute_Reference (Loc,
4182 Prefix => New_Reference_To (Chain, Loc),
4183 Attribute_Name => Name_Unchecked_Access))))),
4185 Has_Created_Identifier => True,
4186 Is_Task_Allocation_Block => True);
4189 Make_Implicit_Label_Declaration (Loc,
4190 Defining_Identifier => Blkent,
4191 Label_Construct => Block));
4193 Append_To (Actions, Block);
4195 Set_Activation_Chain_Entity (Block, Chain);
4196 end Build_Task_Allocate_Block;
4198 -----------------------------------------------
4199 -- Build_Task_Allocate_Block_With_Init_Stmts --
4200 -----------------------------------------------
4202 procedure Build_Task_Allocate_Block_With_Init_Stmts
4205 Init_Stmts : List_Id)
4207 Loc : constant Source_Ptr := Sloc (N);
4208 Chain : constant Entity_Id :=
4209 Make_Defining_Identifier (Loc, Name_uChain);
4210 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4214 Append_To (Init_Stmts,
4215 Make_Procedure_Call_Statement (Loc,
4216 Name => New_Reference_To (RTE (RE_Activate_Tasks), Loc),
4217 Parameter_Associations => New_List (
4218 Make_Attribute_Reference (Loc,
4219 Prefix => New_Reference_To (Chain, Loc),
4220 Attribute_Name => Name_Unchecked_Access))));
4223 Make_Block_Statement (Loc,
4224 Identifier => New_Reference_To (Blkent, Loc),
4225 Declarations => New_List (
4227 -- _Chain : Activation_Chain;
4229 Make_Object_Declaration (Loc,
4230 Defining_Identifier => Chain,
4231 Aliased_Present => True,
4232 Object_Definition =>
4233 New_Reference_To (RTE (RE_Activation_Chain), Loc))),
4235 Handled_Statement_Sequence =>
4236 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4238 Has_Created_Identifier => True,
4239 Is_Task_Allocation_Block => True);
4242 Make_Implicit_Label_Declaration (Loc,
4243 Defining_Identifier => Blkent,
4244 Label_Construct => Block));
4246 Append_To (Actions, Block);
4248 Set_Activation_Chain_Entity (Block, Chain);
4249 end Build_Task_Allocate_Block_With_Init_Stmts;
4251 -----------------------------------
4252 -- Build_Task_Proc_Specification --
4253 -----------------------------------
4255 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4256 Loc : constant Source_Ptr := Sloc (T);
4257 Spec_Id : Entity_Id;
4260 -- Case of explicit task type, suffix TB
4262 if Comes_From_Source (T) then
4264 Make_Defining_Identifier (Loc,
4265 Chars => New_External_Name (Chars (T), "TB"));
4267 -- Case of anonymous task type, suffix B
4271 Make_Defining_Identifier (Loc,
4272 Chars => New_External_Name (Chars (T), 'B'));
4275 Set_Is_Internal (Spec_Id);
4277 -- Associate the procedure with the task, if this is the declaration
4278 -- (and not the body) of the procedure.
4280 if No (Task_Body_Procedure (T)) then
4281 Set_Task_Body_Procedure (T, Spec_Id);
4285 Make_Procedure_Specification (Loc,
4286 Defining_Unit_Name => Spec_Id,
4287 Parameter_Specifications => New_List (
4288 Make_Parameter_Specification (Loc,
4289 Defining_Identifier =>
4290 Make_Defining_Identifier (Loc, Name_uTask),
4292 Make_Access_Definition (Loc,
4294 New_Reference_To (Corresponding_Record_Type (T), Loc)))));
4295 end Build_Task_Proc_Specification;
4297 ---------------------------------------
4298 -- Build_Unprotected_Subprogram_Body --
4299 ---------------------------------------
4301 function Build_Unprotected_Subprogram_Body
4303 Pid : Node_Id) return Node_Id
4305 Decls : constant List_Id := Declarations (N);
4308 -- Add renamings for the Protection object, discriminals, privals and
4309 -- the entry index constant for use by debugger.
4311 Debug_Private_Data_Declarations (Decls);
4313 -- Make an unprotected version of the subprogram for use within the same
4314 -- object, with a new name and an additional parameter representing the
4318 Make_Subprogram_Body (Sloc (N),
4320 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
4321 Declarations => Decls,
4322 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
4323 end Build_Unprotected_Subprogram_Body;
4325 ----------------------------
4326 -- Collect_Entry_Families --
4327 ----------------------------
4329 procedure Collect_Entry_Families
4332 Current_Node : in out Node_Id;
4333 Conctyp : Entity_Id)
4336 Efam_Decl : Node_Id;
4337 Efam_Type : Entity_Id;
4340 Efam := First_Entity (Conctyp);
4341 while Present (Efam) loop
4342 if Ekind (Efam) = E_Entry_Family then
4343 Efam_Type := Make_Temporary (Loc, 'F');
4348 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
4350 Bas_Decl : Node_Id := Empty;
4355 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
4357 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
4358 Bas := Make_Temporary (Loc, 'B');
4361 Make_Subtype_Declaration (Loc,
4362 Defining_Identifier => Bas,
4363 Subtype_Indication =>
4364 Make_Subtype_Indication (Loc,
4366 New_Occurrence_Of (Standard_Integer, Loc),
4368 Make_Range_Constraint (Loc,
4369 Range_Expression => Make_Range (Loc,
4370 Make_Integer_Literal
4371 (Loc, -Entry_Family_Bound),
4372 Make_Integer_Literal
4373 (Loc, Entry_Family_Bound - 1)))));
4375 Insert_After (Current_Node, Bas_Decl);
4376 Current_Node := Bas_Decl;
4381 Make_Full_Type_Declaration (Loc,
4382 Defining_Identifier => Efam_Type,
4384 Make_Unconstrained_Array_Definition (Loc,
4386 (New_List (New_Occurrence_Of (Bas, Loc))),
4388 Component_Definition =>
4389 Make_Component_Definition (Loc,
4390 Aliased_Present => False,
4391 Subtype_Indication =>
4392 New_Reference_To (Standard_Character, Loc))));
4395 Insert_After (Current_Node, Efam_Decl);
4396 Current_Node := Efam_Decl;
4397 Analyze (Efam_Decl);
4400 Make_Component_Declaration (Loc,
4401 Defining_Identifier =>
4402 Make_Defining_Identifier (Loc, Chars (Efam)),
4404 Component_Definition =>
4405 Make_Component_Definition (Loc,
4406 Aliased_Present => False,
4407 Subtype_Indication =>
4408 Make_Subtype_Indication (Loc,
4410 New_Occurrence_Of (Efam_Type, Loc),
4413 Make_Index_Or_Discriminant_Constraint (Loc,
4414 Constraints => New_List (
4416 (Etype (Discrete_Subtype_Definition
4417 (Parent (Efam))), Loc)))))));
4423 end Collect_Entry_Families;
4425 -----------------------
4426 -- Concurrent_Object --
4427 -----------------------
4429 function Concurrent_Object
4430 (Spec_Id : Entity_Id;
4431 Conc_Typ : Entity_Id) return Entity_Id
4434 -- Parameter _O or _object
4436 if Is_Protected_Type (Conc_Typ) then
4437 return First_Formal (Protected_Body_Subprogram (Spec_Id));
4442 pragma Assert (Is_Task_Type (Conc_Typ));
4443 return First_Formal (Task_Body_Procedure (Conc_Typ));
4445 end Concurrent_Object;
4447 ----------------------
4448 -- Copy_Result_Type --
4449 ----------------------
4451 function Copy_Result_Type (Res : Node_Id) return Node_Id is
4452 New_Res : constant Node_Id := New_Copy_Tree (Res);
4457 -- If the result type is an access_to_subprogram, we must create
4458 -- new entities for its spec.
4460 if Nkind (New_Res) = N_Access_Definition
4461 and then Present (Access_To_Subprogram_Definition (New_Res))
4463 -- Provide new entities for the formals
4465 Par_Spec := First (Parameter_Specifications
4466 (Access_To_Subprogram_Definition (New_Res)));
4467 while Present (Par_Spec) loop
4468 Formal := Defining_Identifier (Par_Spec);
4469 Set_Defining_Identifier (Par_Spec,
4470 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
4476 end Copy_Result_Type;
4478 --------------------
4479 -- Concurrent_Ref --
4480 --------------------
4482 -- The expression returned for a reference to a concurrent object has the
4485 -- taskV!(name)._Task_Id
4489 -- objectV!(name)._Object
4491 -- for a protected object. For the case of an access to a concurrent
4492 -- object, there is an extra explicit dereference:
4494 -- taskV!(name.all)._Task_Id
4495 -- objectV!(name.all)._Object
4497 -- here taskV and objectV are the types for the associated records, which
4498 -- contain the required _Task_Id and _Object fields for tasks and protected
4499 -- objects, respectively.
4501 -- For the case of a task type name, the expression is
4505 -- i.e. a call to the Self function which returns precisely this Task_Id
4507 -- For the case of a protected type name, the expression is
4511 -- which is a renaming of the _object field of the current object
4512 -- record, passed into protected operations as a parameter.
4514 function Concurrent_Ref (N : Node_Id) return Node_Id is
4515 Loc : constant Source_Ptr := Sloc (N);
4516 Ntyp : constant Entity_Id := Etype (N);
4520 function Is_Current_Task (T : Entity_Id) return Boolean;
4521 -- Check whether the reference is to the immediately enclosing task
4522 -- type, or to an outer one (rare but legal).
4524 ---------------------
4525 -- Is_Current_Task --
4526 ---------------------
4528 function Is_Current_Task (T : Entity_Id) return Boolean is
4532 Scop := Current_Scope;
4533 while Present (Scop)
4534 and then Scop /= Standard_Standard
4540 elsif Is_Task_Type (Scop) then
4543 -- If this is a procedure nested within the task type, we must
4544 -- assume that it can be called from an inner task, and therefore
4545 -- cannot treat it as a local reference.
4547 elsif Is_Overloadable (Scop)
4548 and then In_Open_Scopes (T)
4553 Scop := Scope (Scop);
4557 -- We know that we are within the task body, so should have found it
4560 raise Program_Error;
4561 end Is_Current_Task;
4563 -- Start of processing for Concurrent_Ref
4566 if Is_Access_Type (Ntyp) then
4567 Dtyp := Designated_Type (Ntyp);
4569 if Is_Protected_Type (Dtyp) then
4570 Sel := Name_uObject;
4572 Sel := Name_uTask_Id;
4576 Make_Selected_Component (Loc,
4578 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
4579 Make_Explicit_Dereference (Loc, N)),
4580 Selector_Name => Make_Identifier (Loc, Sel));
4582 elsif Is_Entity_Name (N)
4583 and then Is_Concurrent_Type (Entity (N))
4585 if Is_Task_Type (Entity (N)) then
4587 if Is_Current_Task (Entity (N)) then
4589 Make_Function_Call (Loc,
4590 Name => New_Reference_To (RTE (RE_Self), Loc));
4595 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
4596 T_Body : constant Node_Id :=
4597 Parent (Corresponding_Body (Parent (Entity (N))));
4601 Make_Object_Declaration (Loc,
4602 Defining_Identifier => T_Self,
4603 Object_Definition =>
4604 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
4606 Make_Function_Call (Loc,
4607 Name => New_Reference_To (RTE (RE_Self), Loc)));
4608 Prepend (Decl, Declarations (T_Body));
4610 Set_Scope (T_Self, Entity (N));
4611 return New_Occurrence_Of (T_Self, Loc);
4616 pragma Assert (Is_Protected_Type (Entity (N)));
4619 New_Reference_To (Find_Protection_Object (Current_Scope), Loc);
4623 if Is_Protected_Type (Ntyp) then
4624 Sel := Name_uObject;
4626 elsif Is_Task_Type (Ntyp) then
4627 Sel := Name_uTask_Id;
4630 raise Program_Error;
4634 Make_Selected_Component (Loc,
4636 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
4638 Selector_Name => Make_Identifier (Loc, Sel));
4642 ------------------------
4643 -- Convert_Concurrent --
4644 ------------------------
4646 function Convert_Concurrent
4648 Typ : Entity_Id) return Node_Id
4651 if not Is_Concurrent_Type (Typ) then
4655 Unchecked_Convert_To
4656 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
4658 end Convert_Concurrent;
4660 -------------------------------------
4661 -- Debug_Private_Data_Declarations --
4662 -------------------------------------
4664 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
4665 Debug_Nod : Node_Id;
4669 Decl := First (Decls);
4670 while Present (Decl)
4671 and then not Comes_From_Source (Decl)
4673 -- Declaration for concurrent entity _object and its access type,
4674 -- along with the entry index subtype:
4675 -- type prot_typVP is access prot_typV;
4676 -- _object : prot_typVP := prot_typV (_O);
4677 -- subtype Jnn is <Type of Index> range Low .. High;
4679 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
4680 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4682 -- Declaration for the Protection object, discriminals, privals and
4683 -- entry index constant:
4684 -- conc_typR : protection_typ renames _object._object;
4685 -- discr_nameD : discr_typ renames _object.discr_name;
4686 -- discr_nameD : discr_typ renames _task.discr_name;
4687 -- prival_name : comp_typ renames _object.comp_name;
4688 -- J : constant Jnn :=
4689 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
4691 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
4692 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4693 Debug_Nod := Debug_Renaming_Declaration (Decl);
4695 if Present (Debug_Nod) then
4696 Insert_After (Decl, Debug_Nod);
4702 end Debug_Private_Data_Declarations;
4704 ----------------------------
4705 -- Entry_Index_Expression --
4706 ----------------------------
4708 function Entry_Index_Expression
4712 Ttyp : Entity_Id) return Node_Id
4722 -- The queues of entries and entry families appear in textual order in
4723 -- the associated record. The entry index is computed as the sum of the
4724 -- number of queues for all entries that precede the designated one, to
4725 -- which is added the index expression, if this expression denotes a
4726 -- member of a family.
4728 -- The following is a place holder for the count of simple entries
4730 Num := Make_Integer_Literal (Sloc, 1);
4732 -- We construct an expression which is a series of addition operations.
4733 -- The first operand is the number of single entries that precede this
4734 -- one, the second operand is the index value relative to the start of
4735 -- the referenced family, and the remaining operands are the lengths of
4736 -- the entry families that precede this entry, i.e. the constructed
4739 -- number_simple_entries +
4740 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
4741 -- family'length + ...
4743 -- where index-value is the given index value, and s is the index
4744 -- subtype (we have to use pos because the subtype might be an
4745 -- enumeration type preventing direct subtraction). Note that the task
4746 -- entry array is one-indexed.
4748 -- The upper bound of the entry family may be a discriminant, so we
4749 -- retrieve the lower bound explicitly to compute offset, rather than
4750 -- using the index subtype which may mention a discriminant.
4752 if Present (Index) then
4753 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
4762 Make_Attribute_Reference (Sloc,
4763 Attribute_Name => Name_Pos,
4764 Prefix => New_Reference_To (Base_Type (S), Sloc),
4765 Expressions => New_List (Relocate_Node (Index))),
4773 -- Now add lengths of preceding entries and entry families
4775 Prev := First_Entity (Ttyp);
4777 while Chars (Prev) /= Chars (Ent)
4778 or else (Ekind (Prev) /= Ekind (Ent))
4779 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
4781 if Ekind (Prev) = E_Entry then
4782 Set_Intval (Num, Intval (Num) + 1);
4784 elsif Ekind (Prev) = E_Entry_Family then
4786 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
4787 Lo := Type_Low_Bound (S);
4788 Hi := Type_High_Bound (S);
4793 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
4795 -- Other components are anonymous types to be ignored
4805 end Entry_Index_Expression;
4807 ---------------------------
4808 -- Establish_Task_Master --
4809 ---------------------------
4811 procedure Establish_Task_Master (N : Node_Id) is
4814 if Restriction_Active (No_Task_Hierarchy) = False then
4815 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
4816 Prepend_To (Declarations (N), Call);
4819 end Establish_Task_Master;
4821 --------------------------------
4822 -- Expand_Accept_Declarations --
4823 --------------------------------
4825 -- Part of the expansion of an accept statement involves the creation of
4826 -- a declaration that can be referenced from the statement sequence of
4831 -- This declaration is inserted immediately before the accept statement
4832 -- and it is important that it be inserted before the statements of the
4833 -- statement sequence are analyzed. Thus it would be too late to create
4834 -- this declaration in the Expand_N_Accept_Statement routine, which is
4835 -- why there is a separate procedure to be called directly from Sem_Ch9.
4837 -- Ann is used to hold the address of the record containing the parameters
4838 -- (see Expand_N_Entry_Call for more details on how this record is built).
4839 -- References to the parameters do an unchecked conversion of this address
4840 -- to a pointer to the required record type, and then access the field that
4841 -- holds the value of the required parameter. The entity for the address
4842 -- variable is held as the top stack element (i.e. the last element) of the
4843 -- Accept_Address stack in the corresponding entry entity, and this element
4844 -- must be set in place before the statements are processed.
4846 -- The above description applies to the case of a stand alone accept
4847 -- statement, i.e. one not appearing as part of a select alternative.
4849 -- For the case of an accept that appears as part of a select alternative
4850 -- of a selective accept, we must still create the declaration right away,
4851 -- since Ann is needed immediately, but there is an important difference:
4853 -- The declaration is inserted before the selective accept, not before
4854 -- the accept statement (which is not part of a list anyway, and so would
4855 -- not accommodate inserted declarations)
4857 -- We only need one address variable for the entire selective accept. So
4858 -- the Ann declaration is created only for the first accept alternative,
4859 -- and subsequent accept alternatives reference the same Ann variable.
4861 -- We can distinguish the two cases by seeing whether the accept statement
4862 -- is part of a list. If not, then it must be in an accept alternative.
4864 -- To expand the requeue statement, a label is provided at the end of the
4865 -- accept statement or alternative of which it is a part, so that the
4866 -- statement can be skipped after the requeue is complete. This label is
4867 -- created here rather than during the expansion of the accept statement,
4868 -- because it will be needed by any requeue statements within the accept,
4869 -- which are expanded before the accept.
4871 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
4872 Loc : constant Source_Ptr := Sloc (N);
4873 Stats : constant Node_Id := Handled_Statement_Sequence (N);
4874 Ann : Entity_Id := Empty;
4882 if Expander_Active then
4884 -- If we have no handled statement sequence, we may need to build
4885 -- a dummy sequence consisting of a null statement. This can be
4886 -- skipped if the trivial accept optimization is permitted.
4888 if not Trivial_Accept_OK
4890 (No (Stats) or else Null_Statements (Statements (Stats)))
4892 Set_Handled_Statement_Sequence (N,
4893 Make_Handled_Sequence_Of_Statements (Loc,
4894 New_List (Make_Null_Statement (Loc))));
4897 -- Create and declare two labels to be placed at the end of the
4898 -- accept statement. The first label is used to allow requeues to
4899 -- skip the remainder of entry processing. The second label is used
4900 -- to skip the remainder of entry processing if the rendezvous
4901 -- completes in the middle of the accept body.
4903 if Present (Handled_Statement_Sequence (N)) then
4908 Ent := Make_Temporary (Loc, 'L');
4909 Lab_Id := New_Reference_To (Ent, Loc);
4910 Lab := Make_Label (Loc, Lab_Id);
4912 Make_Implicit_Label_Declaration (Loc,
4913 Defining_Identifier => Ent,
4914 Label_Construct => Lab);
4915 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4917 Ent := Make_Temporary (Loc, 'L');
4918 Lab_Id := New_Reference_To (Ent, Loc);
4919 Lab := Make_Label (Loc, Lab_Id);
4921 Make_Implicit_Label_Declaration (Loc,
4922 Defining_Identifier => Ent,
4923 Label_Construct => Lab);
4924 Append (Lab, Statements (Handled_Statement_Sequence (N)));
4932 -- Case of stand alone accept statement
4934 if Is_List_Member (N) then
4936 if Present (Handled_Statement_Sequence (N)) then
4937 Ann := Make_Temporary (Loc, 'A');
4940 Make_Object_Declaration (Loc,
4941 Defining_Identifier => Ann,
4942 Object_Definition =>
4943 New_Reference_To (RTE (RE_Address), Loc));
4945 Insert_Before (N, Adecl);
4948 Insert_Before (N, Ldecl);
4951 Insert_Before (N, Ldecl2);
4955 -- Case of accept statement which is in an accept alternative
4959 Acc_Alt : constant Node_Id := Parent (N);
4960 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
4964 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
4965 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
4967 -- ??? Consider a single label for select statements
4969 if Present (Handled_Statement_Sequence (N)) then
4971 Statements (Handled_Statement_Sequence (N)));
4975 Statements (Handled_Statement_Sequence (N)));
4979 -- Find first accept alternative of the selective accept. A
4980 -- valid selective accept must have at least one accept in it.
4982 Alt := First (Select_Alternatives (Sel_Acc));
4984 while Nkind (Alt) /= N_Accept_Alternative loop
4988 -- If we are the first accept statement, then we have to create
4989 -- the Ann variable, as for the stand alone case, except that
4990 -- it is inserted before the selective accept. Similarly, a
4991 -- label for requeue expansion must be declared.
4993 if N = Accept_Statement (Alt) then
4994 Ann := Make_Temporary (Loc, 'A');
4996 Make_Object_Declaration (Loc,
4997 Defining_Identifier => Ann,
4998 Object_Definition =>
4999 New_Reference_To (RTE (RE_Address), Loc));
5001 Insert_Before (Sel_Acc, Adecl);
5004 -- If we are not the first accept statement, then find the Ann
5005 -- variable allocated by the first accept and use it.
5009 Node (Last_Elmt (Accept_Address
5010 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
5015 -- Merge here with Ann either created or referenced, and Adecl
5016 -- pointing to the corresponding declaration. Remaining processing
5017 -- is the same for the two cases.
5019 if Present (Ann) then
5020 Append_Elmt (Ann, Accept_Address (Ent));
5021 Set_Debug_Info_Needed (Ann);
5024 -- Create renaming declarations for the entry formals. Each reference
5025 -- to a formal becomes a dereference of a component of the parameter
5026 -- block, whose address is held in Ann. These declarations are
5027 -- eventually inserted into the accept block, and analyzed there so
5028 -- that they have the proper scope for gdb and do not conflict with
5029 -- other declarations.
5031 if Present (Parameter_Specifications (N))
5032 and then Present (Handled_Statement_Sequence (N))
5039 Renamed_Formal : Node_Id;
5043 Formal := First_Formal (Ent);
5045 while Present (Formal) loop
5046 Comp := Entry_Component (Formal);
5048 Make_Defining_Identifier (Loc, Chars (Formal));
5050 Set_Etype (New_F, Etype (Formal));
5051 Set_Scope (New_F, Ent);
5053 -- Now we set debug info needed on New_F even though it does
5054 -- not come from source, so that the debugger will get the
5055 -- right information for these generated names.
5057 Set_Debug_Info_Needed (New_F);
5059 if Ekind (Formal) = E_In_Parameter then
5060 Set_Ekind (New_F, E_Constant);
5062 Set_Ekind (New_F, E_Variable);
5063 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5066 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5069 Make_Selected_Component (Loc,
5071 Unchecked_Convert_To (
5072 Entry_Parameters_Type (Ent),
5073 New_Reference_To (Ann, Loc)),
5075 New_Reference_To (Comp, Loc));
5078 Build_Renamed_Formal_Declaration
5079 (New_F, Formal, Comp, Renamed_Formal);
5081 if No (Declarations (N)) then
5082 Set_Declarations (N, New_List);
5085 Append (Decl, Declarations (N));
5086 Set_Renamed_Object (Formal, New_F);
5087 Next_Formal (Formal);
5094 end Expand_Accept_Declarations;
5096 ---------------------------------------------
5097 -- Expand_Access_Protected_Subprogram_Type --
5098 ---------------------------------------------
5100 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5101 Loc : constant Source_Ptr := Sloc (N);
5103 T : constant Entity_Id := Defining_Identifier (N);
5104 D_T : constant Entity_Id := Designated_Type (T);
5105 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5106 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5107 P_List : constant List_Id := Build_Protected_Spec
5108 (N, RTE (RE_Address), D_T, False);
5114 -- Create access to subprogram with full signature
5116 if Etype (D_T) /= Standard_Void_Type then
5118 Make_Access_Function_Definition (Loc,
5119 Parameter_Specifications => P_List,
5120 Result_Definition =>
5121 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5125 Make_Access_Procedure_Definition (Loc,
5126 Parameter_Specifications => P_List);
5130 Make_Full_Type_Declaration (Loc,
5131 Defining_Identifier => D_T2,
5132 Type_Definition => Def1);
5134 Insert_After (N, Decl1);
5137 -- Associate the access to subprogram with its original access to
5138 -- protected subprogram type. Needed by the backend to know that this
5139 -- type corresponds with an access to protected subprogram type.
5141 Set_Original_Access_Type (D_T2, T);
5143 -- Create Equivalent_Type, a record with two components for an access to
5144 -- object and an access to subprogram.
5147 Make_Component_Declaration (Loc,
5148 Defining_Identifier => Make_Temporary (Loc, 'P'),
5149 Component_Definition =>
5150 Make_Component_Definition (Loc,
5151 Aliased_Present => False,
5152 Subtype_Indication =>
5153 New_Occurrence_Of (RTE (RE_Address), Loc))),
5155 Make_Component_Declaration (Loc,
5156 Defining_Identifier => Make_Temporary (Loc, 'S'),
5157 Component_Definition =>
5158 Make_Component_Definition (Loc,
5159 Aliased_Present => False,
5160 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5163 Make_Full_Type_Declaration (Loc,
5164 Defining_Identifier => E_T,
5166 Make_Record_Definition (Loc,
5168 Make_Component_List (Loc,
5169 Component_Items => Comps)));
5171 Insert_After (Decl1, Decl2);
5173 Set_Equivalent_Type (T, E_T);
5174 end Expand_Access_Protected_Subprogram_Type;
5176 --------------------------
5177 -- Expand_Entry_Barrier --
5178 --------------------------
5180 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5181 Cond : constant Node_Id :=
5182 Condition (Entry_Body_Formal_Part (N));
5183 Prot : constant Entity_Id := Scope (Ent);
5184 Spec_Decl : constant Node_Id := Parent (Prot);
5187 Body_Decl : Node_Id;
5190 if No_Run_Time_Mode then
5191 Error_Msg_CRT ("entry barrier", N);
5195 -- The body of the entry barrier must be analyzed in the context of the
5196 -- protected object, but its scope is external to it, just as any other
5197 -- unprotected version of a protected operation. The specification has
5198 -- been produced when the protected type declaration was elaborated. We
5199 -- build the body, insert it in the enclosing scope, but analyze it in
5200 -- the current context. A more uniform approach would be to treat the
5201 -- barrier just as a protected function, and discard the protected
5202 -- version of it because it is never called.
5204 if Expander_Active then
5205 B_F := Build_Barrier_Function (N, Ent, Prot);
5206 Func := Barrier_Function (Ent);
5207 Set_Corresponding_Spec (B_F, Func);
5209 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
5211 if Nkind (Parent (Body_Decl)) = N_Subunit then
5212 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
5215 Insert_Before_And_Analyze (Body_Decl, B_F);
5217 Set_Discriminals (Spec_Decl);
5218 Set_Scope (Func, Scope (Prot));
5221 Analyze_And_Resolve (Cond, Any_Boolean);
5224 -- The Ravenscar profile restricts barriers to simple variables declared
5225 -- within the protected object. We also allow Boolean constants, since
5226 -- these appear in several published examples and are also allowed by
5227 -- the Aonix compiler.
5229 -- Note that after analysis variables in this context will be replaced
5230 -- by the corresponding prival, that is to say a renaming of a selected
5231 -- component of the form _Object.Var. If expansion is disabled, as
5232 -- within a generic, we check that the entity appears in the current
5235 if Is_Entity_Name (Cond) then
5237 -- A small optimization of useless renamings. If the scope of the
5238 -- entity of the condition is not the barrier function, then the
5239 -- condition does not reference any of the generated renamings
5240 -- within the function.
5243 and then Scope (Entity (Cond)) /= Func
5245 Set_Declarations (B_F, Empty_List);
5248 if Entity (Cond) = Standard_False
5250 Entity (Cond) = Standard_True
5254 elsif not Expander_Active
5255 and then Scope (Entity (Cond)) = Current_Scope
5259 -- Check for case of _object.all.field (note that the explicit
5260 -- dereference gets inserted by analyze/expand of _object.field)
5262 elsif Present (Renamed_Object (Entity (Cond)))
5264 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
5268 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
5274 -- It is not a boolean variable or literal, so check the restriction
5276 Check_Restriction (Simple_Barriers, Cond);
5277 end Expand_Entry_Barrier;
5279 ------------------------------
5280 -- Expand_N_Abort_Statement --
5281 ------------------------------
5283 -- Expand abort T1, T2, .. Tn; into:
5284 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
5286 procedure Expand_N_Abort_Statement (N : Node_Id) is
5287 Loc : constant Source_Ptr := Sloc (N);
5288 Tlist : constant List_Id := Names (N);
5294 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
5297 Tasknm := First (Tlist);
5299 while Present (Tasknm) loop
5302 -- A task interface class-wide type object is being aborted.
5303 -- Retrieve its _task_id by calling a dispatching routine.
5305 if Ada_Version >= Ada_2005
5306 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
5307 and then Is_Interface (Etype (Tasknm))
5308 and then Is_Task_Interface (Etype (Tasknm))
5310 Append_To (Component_Associations (Aggr),
5311 Make_Component_Association (Loc,
5312 Choices => New_List (
5313 Make_Integer_Literal (Loc, Count)),
5316 -- Task_Id (Tasknm._disp_get_task_id)
5318 Make_Unchecked_Type_Conversion (Loc,
5320 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
5322 Make_Selected_Component (Loc,
5323 Prefix => New_Copy_Tree (Tasknm),
5325 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
5328 Append_To (Component_Associations (Aggr),
5329 Make_Component_Association (Loc,
5330 Choices => New_List (
5331 Make_Integer_Literal (Loc, Count)),
5332 Expression => Concurrent_Ref (Tasknm)));
5339 Make_Procedure_Call_Statement (Loc,
5340 Name => New_Reference_To (RTE (RE_Abort_Tasks), Loc),
5341 Parameter_Associations => New_List (
5342 Make_Qualified_Expression (Loc,
5343 Subtype_Mark => New_Reference_To (RTE (RE_Task_List), Loc),
5344 Expression => Aggr))));
5347 end Expand_N_Abort_Statement;
5349 -------------------------------
5350 -- Expand_N_Accept_Statement --
5351 -------------------------------
5353 -- This procedure handles expansion of accept statements that stand
5354 -- alone, i.e. they are not part of an accept alternative. The expansion
5355 -- of accept statement in accept alternatives is handled by the routines
5356 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
5357 -- following description applies only to stand alone accept statements.
5359 -- If there is no handled statement sequence, or only null statements,
5360 -- then this is called a trivial accept, and the expansion is:
5362 -- Accept_Trivial (entry-index)
5364 -- If there is a handled statement sequence, then the expansion is:
5371 -- Accept_Call (entry-index, Ann);
5372 -- Renaming_Declarations for formals
5373 -- <statement sequence from N_Accept_Statement node>
5374 -- Complete_Rendezvous;
5379 -- <exception handler from N_Accept_Statement node>
5380 -- Complete_Rendezvous;
5382 -- <exception handler from N_Accept_Statement node>
5383 -- Complete_Rendezvous;
5388 -- when all others =>
5389 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
5392 -- The first three declarations were already inserted ahead of the accept
5393 -- statement by the Expand_Accept_Declarations procedure, which was called
5394 -- directly from the semantics during analysis of the accept statement,
5395 -- before analyzing its contained statements.
5397 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
5398 -- from possible expansion activity (the original source of course does
5399 -- not have any declarations associated with the accept statement, since
5400 -- an accept statement has no declarative part). In particular, if the
5401 -- expander is active, the first such declaration is the declaration of
5402 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
5404 -- The two blocks are merged into a single block if the inner block has
5405 -- no exception handlers, but otherwise two blocks are required, since
5406 -- exceptions might be raised in the exception handlers of the inner
5407 -- block, and Exceptional_Complete_Rendezvous must be called.
5409 procedure Expand_N_Accept_Statement (N : Node_Id) is
5410 Loc : constant Source_Ptr := Sloc (N);
5411 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5412 Ename : constant Node_Id := Entry_Direct_Name (N);
5413 Eindx : constant Node_Id := Entry_Index (N);
5414 Eent : constant Entity_Id := Entity (Ename);
5415 Acstack : constant Elist_Id := Accept_Address (Eent);
5416 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
5417 Ttyp : constant Entity_Id := Etype (Scope (Eent));
5422 -- Start of processing for Expand_N_Accept_Statement
5425 -- If accept statement is not part of a list, then its parent must be
5426 -- an accept alternative, and, as described above, we do not do any
5427 -- expansion for such accept statements at this level.
5429 if not Is_List_Member (N) then
5430 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
5433 -- Trivial accept case (no statement sequence, or null statements).
5434 -- If the accept statement has declarations, then just insert them
5435 -- before the procedure call.
5437 elsif Trivial_Accept_OK
5438 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5440 -- Remove declarations for renamings, because the parameter block
5441 -- will not be assigned.
5448 D := First (Declarations (N));
5450 while Present (D) loop
5452 if Nkind (D) = N_Object_Renaming_Declaration then
5460 if Present (Declarations (N)) then
5461 Insert_Actions (N, Declarations (N));
5465 Make_Procedure_Call_Statement (Loc,
5466 Name => New_Reference_To (RTE (RE_Accept_Trivial), Loc),
5467 Parameter_Associations => New_List (
5468 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
5472 -- Discard Entry_Address that was created for it, so it will not be
5473 -- emitted if this accept statement is in the statement part of a
5474 -- delay alternative.
5476 if Present (Stats) then
5477 Remove_Last_Elmt (Acstack);
5480 -- Case of statement sequence present
5483 -- Construct the block, using the declarations from the accept
5484 -- statement if any to initialize the declarations of the block.
5486 Blkent := Make_Temporary (Loc, 'A');
5487 Set_Ekind (Blkent, E_Block);
5488 Set_Etype (Blkent, Standard_Void_Type);
5489 Set_Scope (Blkent, Current_Scope);
5492 Make_Block_Statement (Loc,
5493 Identifier => New_Reference_To (Blkent, Loc),
5494 Declarations => Declarations (N),
5495 Handled_Statement_Sequence => Build_Accept_Body (N));
5497 -- For the analysis of the generated declarations, the parent node
5498 -- must be properly set.
5500 Set_Parent (Block, Parent (N));
5502 -- Prepend call to Accept_Call to main statement sequence If the
5503 -- accept has exception handlers, the statement sequence is wrapped
5504 -- in a block. Insert call and renaming declarations in the
5505 -- declarations of the block, so they are elaborated before the
5509 Make_Procedure_Call_Statement (Loc,
5510 Name => New_Reference_To (RTE (RE_Accept_Call), Loc),
5511 Parameter_Associations => New_List (
5512 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
5513 New_Reference_To (Ann, Loc)));
5515 if Parent (Stats) = N then
5516 Prepend (Call, Statements (Stats));
5525 Push_Scope (Blkent);
5533 D := First (Declarations (N));
5534 while Present (D) loop
5537 if Nkind (D) = N_Object_Renaming_Declaration then
5539 -- The renaming declarations for the formals were created
5540 -- during analysis of the accept statement, and attached to
5541 -- the list of declarations. Place them now in the context
5542 -- of the accept block or subprogram.
5545 Typ := Entity (Subtype_Mark (D));
5546 Insert_After (Call, D);
5549 -- If the formal is class_wide, it does not have an actual
5550 -- subtype. The analysis of the renaming declaration creates
5551 -- one, but we need to retain the class-wide nature of the
5554 if Is_Class_Wide_Type (Typ) then
5555 Set_Etype (Defining_Identifier (D), Typ);
5566 -- Replace the accept statement by the new block
5571 -- Last step is to unstack the Accept_Address value
5573 Remove_Last_Elmt (Acstack);
5575 end Expand_N_Accept_Statement;
5577 ----------------------------------
5578 -- Expand_N_Asynchronous_Select --
5579 ----------------------------------
5581 -- This procedure assumes that the trigger statement is an entry call or
5582 -- a dispatching procedure call. A delay alternative should already have
5583 -- been expanded into an entry call to the appropriate delay object Wait
5586 -- If the trigger is a task entry call, the select is implemented with
5587 -- a Task_Entry_Call:
5592 -- P : parms := (parm, parm, parm);
5594 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5596 -- procedure _clean is
5599 -- Cancel_Task_Entry_Call (C);
5606 -- (<acceptor-task>, -- Acceptor
5607 -- <entry-index>, -- E
5608 -- P'Address, -- Uninterpreted_Data
5609 -- Asynchronous_Call, -- Mode
5610 -- B); -- Rendezvous_Successful
5617 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5620 -- when Abort_Signal => Abort_Undefer;
5627 -- <triggered-statements>
5631 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
5632 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
5636 -- P : parms := (parm, parm, parm);
5638 -- Call_Simple (acceptor-task, entry-index, P'Address);
5644 -- so the task at hand is to convert the latter expansion into the former
5646 -- If the trigger is a protected entry call, the select is implemented
5647 -- with Protected_Entry_Call:
5650 -- P : E1_Params := (param, param, param);
5651 -- Bnn : Communications_Block;
5656 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
5658 -- procedure _clean is
5661 -- if Enqueued (Bnn) then
5662 -- Cancel_Protected_Entry_Call (Bnn);
5669 -- Protected_Entry_Call
5670 -- (po._object'Access, -- Object
5671 -- <entry index>, -- E
5672 -- P'Address, -- Uninterpreted_Data
5673 -- Asynchronous_Call, -- Mode
5676 -- if Enqueued (Bnn) then
5680 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5683 -- when Abort_Signal => Abort_Undefer;
5686 -- if not Cancelled (Bnn) then
5687 -- <triggered-statements>
5691 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
5695 -- P : E1_Params := (param, param, param);
5696 -- Bnn : Communications_Block;
5699 -- Protected_Entry_Call
5700 -- (po._object'Access, -- Object
5701 -- <entry index>, -- E
5702 -- P'Address, -- Uninterpreted_Data
5703 -- Simple_Call, -- Mode
5710 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
5714 -- B : Boolean := False;
5715 -- Bnn : Communication_Block;
5716 -- C : Ada.Tags.Prim_Op_Kind;
5717 -- D : System.Storage_Elements.Dummy_Communication_Block;
5718 -- K : Ada.Tags.Tagged_Kind :=
5719 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5720 -- P : Parameters := (Param1 .. ParamN);
5725 -- if K = Ada.Tags.TK_Limited_Tagged then
5726 -- <dispatching-call>;
5727 -- <triggering-statements>;
5731 -- Ada.Tags.Get_Offset_Index
5732 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
5734 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
5736 -- if C = POK_Protected_Entry then
5738 -- procedure _clean is
5740 -- if Enqueued (Bnn) then
5741 -- Cancel_Protected_Entry_Call (Bnn);
5747 -- _Disp_Asynchronous_Select
5748 -- (<object>, S, P'Address, D, B);
5749 -- Bnn := Communication_Block (D);
5751 -- Param1 := P.Param1;
5753 -- ParamN := P.ParamN;
5755 -- if Enqueued (Bnn) then
5756 -- <abortable-statements>
5759 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5762 -- when Abort_Signal => Abort_Undefer;
5765 -- if not Cancelled (Bnn) then
5766 -- <triggering-statements>
5769 -- elsif C = POK_Task_Entry then
5771 -- procedure _clean is
5773 -- Cancel_Task_Entry_Call (U);
5779 -- _Disp_Asynchronous_Select
5780 -- (<object>, S, P'Address, D, B);
5781 -- Bnn := Communication_Bloc (D);
5783 -- Param1 := P.Param1;
5785 -- ParamN := P.ParamN;
5790 -- <abortable-statements>
5792 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
5795 -- when Abort_Signal => Abort_Undefer;
5799 -- <triggering-statements>
5804 -- <dispatching-call>;
5805 -- <triggering-statements>
5810 -- The job is to convert this to the asynchronous form
5812 -- If the trigger is a delay statement, it will have been expanded into a
5813 -- call to one of the GNARL delay procedures. This routine will convert
5814 -- this into a protected entry call on a delay object and then continue
5815 -- processing as for a protected entry call trigger. This requires
5816 -- declaring a Delay_Block object and adding a pointer to this object to
5817 -- the parameter list of the delay procedure to form the parameter list of
5818 -- the entry call. This object is used by the runtime to queue the delay
5821 -- For a description of the use of P and the assignments after the call,
5822 -- see Expand_N_Entry_Call_Statement.
5824 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
5825 Loc : constant Source_Ptr := Sloc (N);
5826 Abrt : constant Node_Id := Abortable_Part (N);
5827 Astats : constant List_Id := Statements (Abrt);
5828 Trig : constant Node_Id := Triggering_Alternative (N);
5829 Tstats : constant List_Id := Statements (Trig);
5831 Abort_Block_Ent : Entity_Id;
5832 Abortable_Block : Node_Id;
5834 Blk_Ent : Entity_Id;
5835 Blk_Typ : Entity_Id;
5837 Call_Ent : Entity_Id;
5838 Cancel_Param : Entity_Id;
5839 Cleanup_Block : Node_Id;
5840 Cleanup_Block_Ent : Entity_Id;
5841 Cleanup_Stmts : List_Id;
5842 Conc_Typ_Stmts : List_Id;
5844 Dblock_Ent : Entity_Id;
5849 Enqueue_Call : Node_Id;
5853 Lim_Typ_Stmts : List_Id;
5859 ProtE_Stmts : List_Id;
5860 ProtP_Stmts : List_Id;
5863 Target_Undefer : RE_Id;
5864 TaskE_Stmts : List_Id;
5865 Undefer_Args : List_Id := No_List;
5867 B : Entity_Id; -- Call status flag
5868 Bnn : Entity_Id; -- Communication block
5869 C : Entity_Id; -- Call kind
5870 K : Entity_Id; -- Tagged kind
5871 P : Entity_Id; -- Parameter block
5872 S : Entity_Id; -- Primitive operation slot
5873 T : Entity_Id; -- Additional status flag
5876 Blk_Ent := Make_Temporary (Loc, 'A');
5877 Ecall := Triggering_Statement (Trig);
5879 -- The arguments in the call may require dynamic allocation, and the
5880 -- call statement may have been transformed into a block. The block
5881 -- may contain additional declarations for internal entities, and the
5882 -- original call is found by sequential search.
5884 if Nkind (Ecall) = N_Block_Statement then
5885 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
5886 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
5887 N_Entry_Call_Statement)
5893 -- This is either a dispatching call or a delay statement used as a
5894 -- trigger which was expanded into a procedure call.
5896 if Nkind (Ecall) = N_Procedure_Call_Statement then
5897 if Ada_Version >= Ada_2005
5899 (No (Original_Node (Ecall))
5900 or else not Nkind_In (Original_Node (Ecall),
5901 N_Delay_Relative_Statement,
5902 N_Delay_Until_Statement))
5904 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
5909 -- Call status flag processing, generate:
5910 -- B : Boolean := False;
5912 B := Build_B (Loc, Decls);
5914 -- Communication block processing, generate:
5915 -- Bnn : Communication_Block;
5917 Bnn := Make_Temporary (Loc, 'B');
5919 Make_Object_Declaration (Loc,
5920 Defining_Identifier => Bnn,
5921 Object_Definition =>
5922 New_Reference_To (RTE (RE_Communication_Block), Loc)));
5924 -- Call kind processing, generate:
5925 -- C : Ada.Tags.Prim_Op_Kind;
5927 C := Build_C (Loc, Decls);
5929 -- Tagged kind processing, generate:
5930 -- K : Ada.Tags.Tagged_Kind :=
5931 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
5933 -- Dummy communication block, generate:
5934 -- D : Dummy_Communication_Block;
5937 Make_Object_Declaration (Loc,
5938 Defining_Identifier =>
5939 Make_Defining_Identifier (Loc, Name_uD),
5940 Object_Definition =>
5942 RTE (RE_Dummy_Communication_Block), Loc)));
5944 K := Build_K (Loc, Decls, Obj);
5946 -- Parameter block processing
5948 Blk_Typ := Build_Parameter_Block
5949 (Loc, Actuals, Formals, Decls);
5950 P := Parameter_Block_Pack
5951 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
5953 -- Dispatch table slot processing, generate:
5956 S := Build_S (Loc, Decls);
5958 -- Additional status flag processing, generate:
5961 T := Make_Temporary (Loc, 'T');
5963 Make_Object_Declaration (Loc,
5964 Defining_Identifier => T,
5965 Object_Definition =>
5966 New_Reference_To (Standard_Boolean, Loc)));
5968 ------------------------------
5969 -- Protected entry handling --
5970 ------------------------------
5973 -- Param1 := P.Param1;
5975 -- ParamN := P.ParamN;
5977 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
5980 -- Bnn := Communication_Block (D);
5982 Prepend_To (Cleanup_Stmts,
5983 Make_Assignment_Statement (Loc,
5985 New_Reference_To (Bnn, Loc),
5987 Make_Unchecked_Type_Conversion (Loc,
5989 New_Reference_To (RTE (RE_Communication_Block), Loc),
5990 Expression => Make_Identifier (Loc, Name_uD))));
5993 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
5995 Prepend_To (Cleanup_Stmts,
5996 Make_Procedure_Call_Statement (Loc,
5999 Find_Prim_Op (Etype (Etype (Obj)),
6000 Name_uDisp_Asynchronous_Select),
6002 Parameter_Associations =>
6004 New_Copy_Tree (Obj), -- <object>
6005 New_Reference_To (S, Loc), -- S
6006 Make_Attribute_Reference (Loc, -- P'Address
6008 New_Reference_To (P, Loc),
6011 Make_Identifier (Loc, Name_uD), -- D
6012 New_Reference_To (B, Loc)))); -- B
6015 -- if Enqueued (Bnn) then
6016 -- <abortable-statements>
6019 Append_To (Cleanup_Stmts,
6020 Make_If_Statement (Loc,
6022 Make_Function_Call (Loc,
6024 New_Reference_To (RTE (RE_Enqueued), Loc),
6025 Parameter_Associations =>
6027 New_Reference_To (Bnn, Loc))),
6030 New_Copy_List_Tree (Astats)));
6032 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6033 -- will then generate a _clean for the communication block Bnn.
6037 -- procedure _clean is
6039 -- if Enqueued (Bnn) then
6040 -- Cancel_Protected_Entry_Call (Bnn);
6049 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6051 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6053 -- Wrap the cleanup block in an exception handling block
6059 -- when Abort_Signal => Abort_Undefer;
6062 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6065 Make_Implicit_Label_Declaration (Loc,
6066 Defining_Identifier =>
6070 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6073 -- if not Cancelled (Bnn) then
6074 -- <triggering-statements>
6077 Append_To (ProtE_Stmts,
6078 Make_If_Statement (Loc,
6082 Make_Function_Call (Loc,
6084 New_Reference_To (RTE (RE_Cancelled), Loc),
6085 Parameter_Associations =>
6087 New_Reference_To (Bnn, Loc)))),
6090 New_Copy_List_Tree (Tstats)));
6092 -------------------------
6093 -- Task entry handling --
6094 -------------------------
6097 -- Param1 := P.Param1;
6099 -- ParamN := P.ParamN;
6101 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6104 -- Bnn := Communication_Block (D);
6106 Append_To (TaskE_Stmts,
6107 Make_Assignment_Statement (Loc,
6109 New_Reference_To (Bnn, Loc),
6111 Make_Unchecked_Type_Conversion (Loc,
6113 New_Reference_To (RTE (RE_Communication_Block), Loc),
6114 Expression => Make_Identifier (Loc, Name_uD))));
6117 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6119 Prepend_To (TaskE_Stmts,
6120 Make_Procedure_Call_Statement (Loc,
6123 Find_Prim_Op (Etype (Etype (Obj)),
6124 Name_uDisp_Asynchronous_Select),
6126 Parameter_Associations =>
6128 New_Copy_Tree (Obj), -- <object>
6129 New_Reference_To (S, Loc), -- S
6130 Make_Attribute_Reference (Loc, -- P'Address
6132 New_Reference_To (P, Loc),
6135 Make_Identifier (Loc, Name_uD), -- D
6136 New_Reference_To (B, Loc)))); -- B
6141 Prepend_To (TaskE_Stmts,
6142 Make_Procedure_Call_Statement (Loc,
6144 New_Reference_To (RTE (RE_Abort_Defer), Loc),
6145 Parameter_Associations =>
6150 -- <abortable-statements>
6152 Cleanup_Stmts := New_Copy_List_Tree (Astats);
6154 Prepend_To (Cleanup_Stmts,
6155 Make_Procedure_Call_Statement (Loc,
6157 New_Reference_To (RTE (RE_Abort_Undefer), Loc),
6158 Parameter_Associations =>
6161 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6162 -- will generate a _clean for the additional status flag.
6166 -- procedure _clean is
6168 -- Cancel_Task_Entry_Call (U);
6176 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6178 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
6180 -- Wrap the cleanup block in an exception handling block
6186 -- when Abort_Signal => Abort_Undefer;
6189 Abort_Block_Ent := Make_Temporary (Loc, 'A');
6191 Append_To (TaskE_Stmts,
6192 Make_Implicit_Label_Declaration (Loc,
6193 Defining_Identifier => Abort_Block_Ent));
6195 Append_To (TaskE_Stmts,
6197 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
6201 -- <triggering-statements>
6204 Append_To (TaskE_Stmts,
6205 Make_If_Statement (Loc,
6209 New_Reference_To (T, Loc)),
6212 New_Copy_List_Tree (Tstats)));
6214 ----------------------------------
6215 -- Protected procedure handling --
6216 ----------------------------------
6219 -- <dispatching-call>;
6220 -- <triggering-statements>
6222 ProtP_Stmts := New_Copy_List_Tree (Tstats);
6223 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
6226 -- S := Ada.Tags.Get_Offset_Index
6227 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6230 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6233 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6235 Append_To (Conc_Typ_Stmts,
6236 Make_Procedure_Call_Statement (Loc,
6239 Find_Prim_Op (Etype (Etype (Obj)),
6240 Name_uDisp_Get_Prim_Op_Kind),
6242 Parameter_Associations =>
6244 New_Copy_Tree (Obj),
6245 New_Reference_To (S, Loc),
6246 New_Reference_To (C, Loc))));
6249 -- if C = POK_Procedure_Entry then
6251 -- elsif C = POK_Task_Entry then
6257 Append_To (Conc_Typ_Stmts,
6258 Make_If_Statement (Loc,
6262 New_Reference_To (C, Loc),
6264 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
6271 Make_Elsif_Part (Loc,
6275 New_Reference_To (C, Loc),
6277 New_Reference_To (RTE (RE_POK_Task_Entry), Loc)),
6286 -- <dispatching-call>;
6287 -- <triggering-statements>
6289 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
6290 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
6293 -- if K = Ada.Tags.TK_Limited_Tagged then
6300 Make_If_Statement (Loc,
6304 New_Reference_To (K, Loc),
6306 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
6315 Make_Block_Statement (Loc,
6318 Handled_Statement_Sequence =>
6319 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6324 -- Delay triggering statement processing
6327 -- Add a Delay_Block object to the parameter list of the delay
6328 -- procedure to form the parameter list of the Wait entry call.
6330 Dblock_Ent := Make_Temporary (Loc, 'D');
6332 Pdef := Entity (Name (Ecall));
6334 if Is_RTE (Pdef, RO_CA_Delay_For) then
6336 New_Reference_To (RTE (RE_Enqueue_Duration), Loc);
6338 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
6340 New_Reference_To (RTE (RE_Enqueue_Calendar), Loc);
6342 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
6343 Enqueue_Call := New_Reference_To (RTE (RE_Enqueue_RT), Loc);
6346 Append_To (Parameter_Associations (Ecall),
6347 Make_Attribute_Reference (Loc,
6348 Prefix => New_Reference_To (Dblock_Ent, Loc),
6349 Attribute_Name => Name_Unchecked_Access));
6351 -- Create the inner block to protect the abortable part
6354 Make_Implicit_Exception_Handler (Loc,
6355 Exception_Choices =>
6356 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6357 Statements => New_List (
6358 Make_Procedure_Call_Statement (Loc,
6359 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6362 Make_Procedure_Call_Statement (Loc,
6363 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6366 Make_Block_Statement (Loc,
6367 Identifier => New_Reference_To (Blk_Ent, Loc),
6368 Handled_Statement_Sequence =>
6369 Make_Handled_Sequence_Of_Statements (Loc,
6370 Statements => Astats),
6371 Has_Created_Identifier => True,
6372 Is_Asynchronous_Call_Block => True);
6374 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
6377 Make_Implicit_If_Statement (N,
6378 Condition => Make_Function_Call (Loc,
6379 Name => Enqueue_Call,
6380 Parameter_Associations => Parameter_Associations (Ecall)),
6382 New_List (Make_Block_Statement (Loc,
6383 Handled_Statement_Sequence =>
6384 Make_Handled_Sequence_Of_Statements (Loc,
6385 Statements => New_List (
6386 Make_Implicit_Label_Declaration (Loc,
6387 Defining_Identifier => Blk_Ent,
6388 Label_Construct => Abortable_Block),
6390 Exception_Handlers => Hdle)))));
6392 Stmts := New_List (Ecall);
6394 -- Construct statement sequence for new block
6397 Make_Implicit_If_Statement (N,
6398 Condition => Make_Function_Call (Loc,
6399 Name => New_Reference_To (
6400 RTE (RE_Timed_Out), Loc),
6401 Parameter_Associations => New_List (
6402 Make_Attribute_Reference (Loc,
6403 Prefix => New_Reference_To (Dblock_Ent, Loc),
6404 Attribute_Name => Name_Unchecked_Access))),
6405 Then_Statements => Tstats));
6407 -- The result is the new block
6409 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
6412 Make_Block_Statement (Loc,
6413 Declarations => New_List (
6414 Make_Object_Declaration (Loc,
6415 Defining_Identifier => Dblock_Ent,
6416 Aliased_Present => True,
6417 Object_Definition => New_Reference_To (
6418 RTE (RE_Delay_Block), Loc))),
6420 Handled_Statement_Sequence =>
6421 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6431 Extract_Entry (Ecall, Concval, Ename, Index);
6432 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
6434 Stmts := Statements (Handled_Statement_Sequence (Ecall));
6435 Decls := Declarations (Ecall);
6437 if Is_Protected_Type (Etype (Concval)) then
6439 -- Get the declarations of the block expanded from the entry call
6441 Decl := First (Decls);
6442 while Present (Decl)
6444 (Nkind (Decl) /= N_Object_Declaration
6445 or else not Is_RTE (Etype (Object_Definition (Decl)),
6446 RE_Communication_Block))
6451 pragma Assert (Present (Decl));
6452 Cancel_Param := Defining_Identifier (Decl);
6454 -- Change the mode of the Protected_Entry_Call call
6456 -- Protected_Entry_Call (
6457 -- Object => po._object'Access,
6458 -- E => <entry index>;
6459 -- Uninterpreted_Data => P'Address;
6460 -- Mode => Asynchronous_Call;
6463 Stmt := First (Stmts);
6465 -- Skip assignments to temporaries created for in-out parameters
6467 -- This makes unwarranted assumptions about the shape of the expanded
6468 -- tree for the call, and should be cleaned up ???
6470 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6476 Param := First (Parameter_Associations (Call));
6477 while Present (Param)
6478 and then not Is_RTE (Etype (Param), RE_Call_Modes)
6483 pragma Assert (Present (Param));
6484 Rewrite (Param, New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6487 -- Append an if statement to execute the abortable part
6490 -- if Enqueued (Bnn) then
6493 Make_Implicit_If_Statement (N,
6494 Condition => Make_Function_Call (Loc,
6495 Name => New_Reference_To (
6496 RTE (RE_Enqueued), Loc),
6497 Parameter_Associations => New_List (
6498 New_Reference_To (Cancel_Param, Loc))),
6499 Then_Statements => Astats));
6502 Make_Block_Statement (Loc,
6503 Identifier => New_Reference_To (Blk_Ent, Loc),
6504 Handled_Statement_Sequence =>
6505 Make_Handled_Sequence_Of_Statements (Loc,
6506 Statements => Stmts),
6507 Has_Created_Identifier => True,
6508 Is_Asynchronous_Call_Block => True);
6510 -- For the VM call Update_Exception instead of Abort_Undefer.
6511 -- See 4jexcept.ads for an explanation.
6513 if VM_Target = No_VM then
6514 Target_Undefer := RE_Abort_Undefer;
6516 Target_Undefer := RE_Update_Exception;
6518 New_List (Make_Function_Call (Loc,
6519 Name => New_Occurrence_Of
6520 (RTE (RE_Current_Target_Exception), Loc)));
6524 Make_Block_Statement (Loc,
6525 Handled_Statement_Sequence =>
6526 Make_Handled_Sequence_Of_Statements (Loc,
6527 Statements => New_List (
6528 Make_Implicit_Label_Declaration (Loc,
6529 Defining_Identifier => Blk_Ent,
6530 Label_Construct => Abortable_Block),
6535 Exception_Handlers => New_List (
6536 Make_Implicit_Exception_Handler (Loc,
6538 -- when Abort_Signal =>
6539 -- Abort_Undefer.all;
6541 Exception_Choices =>
6542 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6543 Statements => New_List (
6544 Make_Procedure_Call_Statement (Loc,
6545 Name => New_Reference_To (
6546 RTE (Target_Undefer), Loc),
6547 Parameter_Associations => Undefer_Args)))))),
6549 -- if not Cancelled (Bnn) then
6550 -- triggered statements
6553 Make_Implicit_If_Statement (N,
6554 Condition => Make_Op_Not (Loc,
6556 Make_Function_Call (Loc,
6557 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
6558 Parameter_Associations => New_List (
6559 New_Occurrence_Of (Cancel_Param, Loc)))),
6560 Then_Statements => Tstats));
6562 -- Asynchronous task entry call
6569 B := Make_Defining_Identifier (Loc, Name_uB);
6571 -- Insert declaration of B in declarations of existing block
6574 Make_Object_Declaration (Loc,
6575 Defining_Identifier => B,
6576 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6578 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
6580 -- Insert declaration of C in declarations of existing block
6583 Make_Object_Declaration (Loc,
6584 Defining_Identifier => Cancel_Param,
6585 Object_Definition => New_Reference_To (Standard_Boolean, Loc)));
6587 -- Remove and save the call to Call_Simple
6589 Stmt := First (Stmts);
6591 -- Skip assignments to temporaries created for in-out parameters.
6592 -- This makes unwarranted assumptions about the shape of the expanded
6593 -- tree for the call, and should be cleaned up ???
6595 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
6601 -- Create the inner block to protect the abortable part
6604 Make_Implicit_Exception_Handler (Loc,
6605 Exception_Choices =>
6606 New_List (New_Reference_To (Stand.Abort_Signal, Loc)),
6609 Make_Procedure_Call_Statement (Loc,
6610 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)))));
6613 Make_Procedure_Call_Statement (Loc,
6614 Name => New_Reference_To (RTE (RE_Abort_Undefer), Loc)));
6617 Make_Block_Statement (Loc,
6618 Identifier => New_Reference_To (Blk_Ent, Loc),
6619 Handled_Statement_Sequence =>
6620 Make_Handled_Sequence_Of_Statements (Loc,
6621 Statements => Astats),
6622 Has_Created_Identifier => True,
6623 Is_Asynchronous_Call_Block => True);
6626 Make_Block_Statement (Loc,
6627 Handled_Statement_Sequence =>
6628 Make_Handled_Sequence_Of_Statements (Loc,
6629 Statements => New_List (
6630 Make_Implicit_Label_Declaration (Loc,
6631 Defining_Identifier =>
6636 Exception_Handlers => Hdle)));
6638 -- Create new call statement
6640 Params := Parameter_Associations (Call);
6643 New_Reference_To (RTE (RE_Asynchronous_Call), Loc));
6645 New_Reference_To (B, Loc));
6648 Make_Procedure_Call_Statement (Loc,
6650 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
6651 Parameter_Associations => Params));
6653 -- Construct statement sequence for new block
6656 Make_Implicit_If_Statement (N,
6659 New_Reference_To (Cancel_Param, Loc)),
6660 Then_Statements => Tstats));
6662 -- Protected the call against abort
6665 Make_Procedure_Call_Statement (Loc,
6666 Name => New_Reference_To (RTE (RE_Abort_Defer), Loc),
6667 Parameter_Associations => Empty_List));
6670 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
6672 -- The result is the new block
6675 Make_Block_Statement (Loc,
6676 Declarations => Decls,
6677 Handled_Statement_Sequence =>
6678 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
6681 end Expand_N_Asynchronous_Select;
6683 -------------------------------------
6684 -- Expand_N_Conditional_Entry_Call --
6685 -------------------------------------
6687 -- The conditional task entry call is converted to a call to
6692 -- P : parms := (parm, parm, parm);
6696 -- (<acceptor-task>, -- Acceptor
6697 -- <entry-index>, -- E
6698 -- P'Address, -- Uninterpreted_Data
6699 -- Conditional_Call, -- Mode
6700 -- B); -- Rendezvous_Successful
6705 -- normal-statements
6711 -- For a description of the use of P and the assignments after the call,
6712 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
6713 -- conditional entry call has already been expanded (by the Expand_N_Entry
6714 -- _Call_Statement procedure) as follows:
6717 -- P : parms := (parm, parm, parm);
6719 -- ... info for in-out parameters
6720 -- Call_Simple (acceptor-task, entry-index, P'Address);
6726 -- so the task at hand is to convert the latter expansion into the former
6728 -- The conditional protected entry call is converted to a call to
6729 -- Protected_Entry_Call:
6732 -- P : parms := (parm, parm, parm);
6733 -- Bnn : Communications_Block;
6736 -- Protected_Entry_Call
6737 -- (po._object'Access, -- Object
6738 -- <entry index>, -- E
6739 -- P'Address, -- Uninterpreted_Data
6740 -- Conditional_Call, -- Mode
6745 -- if Cancelled (Bnn) then
6748 -- normal-statements
6752 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
6756 -- B : Boolean := False;
6757 -- C : Ada.Tags.Prim_Op_Kind;
6758 -- K : Ada.Tags.Tagged_Kind :=
6759 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6760 -- P : Parameters := (Param1 .. ParamN);
6764 -- if K = Ada.Tags.TK_Limited_Tagged then
6765 -- <dispatching-call>;
6766 -- <triggering-statements>
6770 -- Ada.Tags.Get_Offset_Index
6771 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6773 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6775 -- if C = POK_Protected_Entry
6776 -- or else C = POK_Task_Entry
6778 -- Param1 := P.Param1;
6780 -- ParamN := P.ParamN;
6784 -- if C = POK_Procedure
6785 -- or else C = POK_Protected_Procedure
6786 -- or else C = POK_Task_Procedure
6788 -- <dispatching-call>;
6791 -- <triggering-statements>
6793 -- <else-statements>
6798 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
6799 Loc : constant Source_Ptr := Sloc (N);
6800 Alt : constant Node_Id := Entry_Call_Alternative (N);
6801 Blk : Node_Id := Entry_Call_Statement (Alt);
6804 Blk_Typ : Entity_Id;
6806 Call_Ent : Entity_Id;
6807 Conc_Typ_Stmts : List_Id;
6811 Lim_Typ_Stmts : List_Id;
6818 Transient_Blk : Node_Id;
6821 B : Entity_Id; -- Call status flag
6822 C : Entity_Id; -- Call kind
6823 K : Entity_Id; -- Tagged kind
6824 P : Entity_Id; -- Parameter block
6825 S : Entity_Id; -- Primitive operation slot
6828 if Ada_Version >= Ada_2005
6829 and then Nkind (Blk) = N_Procedure_Call_Statement
6831 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
6836 -- Call status flag processing, generate:
6837 -- B : Boolean := False;
6839 B := Build_B (Loc, Decls);
6841 -- Call kind processing, generate:
6842 -- C : Ada.Tags.Prim_Op_Kind;
6844 C := Build_C (Loc, Decls);
6846 -- Tagged kind processing, generate:
6847 -- K : Ada.Tags.Tagged_Kind :=
6848 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6850 K := Build_K (Loc, Decls, Obj);
6852 -- Parameter block processing
6854 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
6855 P := Parameter_Block_Pack
6856 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6858 -- Dispatch table slot processing, generate:
6861 S := Build_S (Loc, Decls);
6864 -- S := Ada.Tags.Get_Offset_Index
6865 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
6868 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
6871 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
6873 Append_To (Conc_Typ_Stmts,
6874 Make_Procedure_Call_Statement (Loc,
6877 Find_Prim_Op (Etype (Etype (Obj)),
6878 Name_uDisp_Conditional_Select),
6880 Parameter_Associations =>
6882 New_Copy_Tree (Obj), -- <object>
6883 New_Reference_To (S, Loc), -- S
6884 Make_Attribute_Reference (Loc, -- P'Address
6886 New_Reference_To (P, Loc),
6889 New_Reference_To (C, Loc), -- C
6890 New_Reference_To (B, Loc)))); -- B
6893 -- if C = POK_Protected_Entry
6894 -- or else C = POK_Task_Entry
6896 -- Param1 := P.Param1;
6898 -- ParamN := P.ParamN;
6901 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6903 -- Generate the if statement only when the packed parameters need
6904 -- explicit assignments to their corresponding actuals.
6906 if Present (Unpack) then
6907 Append_To (Conc_Typ_Stmts,
6908 Make_If_Statement (Loc,
6915 New_Reference_To (C, Loc),
6917 New_Reference_To (RTE (
6918 RE_POK_Protected_Entry), Loc)),
6922 New_Reference_To (C, Loc),
6924 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
6932 -- if C = POK_Procedure
6933 -- or else C = POK_Protected_Procedure
6934 -- or else C = POK_Task_Procedure
6936 -- <dispatching-call>
6938 -- <normal-statements>
6940 -- <else-statements>
6943 N_Stats := New_Copy_List_Tree (Statements (Alt));
6945 Prepend_To (N_Stats,
6946 Make_If_Statement (Loc,
6952 New_Reference_To (C, Loc),
6954 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
6961 New_Reference_To (C, Loc),
6963 New_Reference_To (RTE (
6964 RE_POK_Protected_Procedure), Loc)),
6969 New_Reference_To (C, Loc),
6971 New_Reference_To (RTE (
6972 RE_POK_Task_Procedure), Loc)))),
6977 Append_To (Conc_Typ_Stmts,
6978 Make_If_Statement (Loc,
6979 Condition => New_Reference_To (B, Loc),
6980 Then_Statements => N_Stats,
6981 Else_Statements => Else_Statements (N)));
6984 -- <dispatching-call>;
6985 -- <triggering-statements>
6987 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
6988 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
6991 -- if K = Ada.Tags.TK_Limited_Tagged then
6998 Make_If_Statement (Loc,
7002 New_Reference_To (K, Loc),
7004 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
7013 Make_Block_Statement (Loc,
7016 Handled_Statement_Sequence =>
7017 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7019 -- As described above, The entry alternative is transformed into a
7020 -- block that contains the gnulli call, and possibly assignment
7021 -- statements for in-out parameters. The gnulli call may itself be
7022 -- rewritten into a transient block if some unconstrained parameters
7023 -- require it. We need to retrieve the call to complete its parameter
7028 First_Real_Statement (Handled_Statement_Sequence (Blk));
7030 if Present (Transient_Blk)
7031 and then Nkind (Transient_Blk) = N_Block_Statement
7033 Blk := Transient_Blk;
7036 Stmts := Statements (Handled_Statement_Sequence (Blk));
7037 Stmt := First (Stmts);
7038 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7043 Params := Parameter_Associations (Call);
7045 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7047 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7049 Param := First (Params);
7050 while Present (Param)
7051 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7056 pragma Assert (Present (Param));
7057 Rewrite (Param, New_Reference_To (RTE (RE_Conditional_Call), Loc));
7061 -- Find the Communication_Block parameter for the call to the
7062 -- Cancelled function.
7064 Decl := First (Declarations (Blk));
7065 while Present (Decl)
7066 and then not Is_RTE (Etype (Object_Definition (Decl)),
7067 RE_Communication_Block)
7072 -- Add an if statement to execute the else part if the call
7073 -- does not succeed (as indicated by the Cancelled predicate).
7076 Make_Implicit_If_Statement (N,
7077 Condition => Make_Function_Call (Loc,
7078 Name => New_Reference_To (RTE (RE_Cancelled), Loc),
7079 Parameter_Associations => New_List (
7080 New_Reference_To (Defining_Identifier (Decl), Loc))),
7081 Then_Statements => Else_Statements (N),
7082 Else_Statements => Statements (Alt)));
7085 B := Make_Defining_Identifier (Loc, Name_uB);
7087 -- Insert declaration of B in declarations of existing block
7089 if No (Declarations (Blk)) then
7090 Set_Declarations (Blk, New_List);
7093 Prepend_To (Declarations (Blk),
7094 Make_Object_Declaration (Loc,
7095 Defining_Identifier => B,
7096 Object_Definition =>
7097 New_Reference_To (Standard_Boolean, Loc)));
7099 -- Create new call statement
7102 New_Reference_To (RTE (RE_Conditional_Call), Loc));
7103 Append_To (Params, New_Reference_To (B, Loc));
7106 Make_Procedure_Call_Statement (Loc,
7107 Name => New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
7108 Parameter_Associations => Params));
7110 -- Construct statement sequence for new block
7113 Make_Implicit_If_Statement (N,
7114 Condition => New_Reference_To (B, Loc),
7115 Then_Statements => Statements (Alt),
7116 Else_Statements => Else_Statements (N)));
7119 -- The result is the new block
7122 Make_Block_Statement (Loc,
7123 Declarations => Declarations (Blk),
7124 Handled_Statement_Sequence =>
7125 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7129 end Expand_N_Conditional_Entry_Call;
7131 ---------------------------------------
7132 -- Expand_N_Delay_Relative_Statement --
7133 ---------------------------------------
7135 -- Delay statement is implemented as a procedure call to Delay_For
7136 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
7137 -- simple delays imposed by the use of Protected Objects.
7139 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
7140 Loc : constant Source_Ptr := Sloc (N);
7143 Make_Procedure_Call_Statement (Loc,
7144 Name => New_Reference_To (RTE (RO_CA_Delay_For), Loc),
7145 Parameter_Associations => New_List (Expression (N))));
7147 end Expand_N_Delay_Relative_Statement;
7149 ------------------------------------
7150 -- Expand_N_Delay_Until_Statement --
7151 ------------------------------------
7153 -- Delay Until statement is implemented as a procedure call to
7154 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
7156 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
7157 Loc : constant Source_Ptr := Sloc (N);
7161 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
7162 Typ := RTE (RO_CA_Delay_Until);
7164 Typ := RTE (RO_RT_Delay_Until);
7168 Make_Procedure_Call_Statement (Loc,
7169 Name => New_Reference_To (Typ, Loc),
7170 Parameter_Associations => New_List (Expression (N))));
7173 end Expand_N_Delay_Until_Statement;
7175 -------------------------
7176 -- Expand_N_Entry_Body --
7177 -------------------------
7179 procedure Expand_N_Entry_Body (N : Node_Id) is
7181 -- Associate discriminals with the next protected operation body to be
7184 if Present (Next_Protected_Operation (N)) then
7185 Set_Discriminals (Parent (Current_Scope));
7187 end Expand_N_Entry_Body;
7189 -----------------------------------
7190 -- Expand_N_Entry_Call_Statement --
7191 -----------------------------------
7193 -- An entry call is expanded into GNARLI calls to implement a simple entry
7194 -- call (see Build_Simple_Entry_Call).
7196 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
7202 if No_Run_Time_Mode then
7203 Error_Msg_CRT ("entry call", N);
7207 -- If this entry call is part of an asynchronous select, don't expand it
7208 -- here; it will be expanded with the select statement. Don't expand
7209 -- timed entry calls either, as they are translated into asynchronous
7212 -- ??? This whole approach is questionable; it may be better to go back
7213 -- to allowing the expansion to take place and then attempting to fix it
7214 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
7215 -- whether the expanded call is on a task or protected entry.
7217 if (Nkind (Parent (N)) /= N_Triggering_Alternative
7218 or else N /= Triggering_Statement (Parent (N)))
7219 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
7220 or else N /= Entry_Call_Statement (Parent (N))
7221 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
7223 Extract_Entry (N, Concval, Ename, Index);
7224 Build_Simple_Entry_Call (N, Concval, Ename, Index);
7226 end Expand_N_Entry_Call_Statement;
7228 --------------------------------
7229 -- Expand_N_Entry_Declaration --
7230 --------------------------------
7232 -- If there are parameters, then first, each of the formals is marked by
7233 -- setting Is_Entry_Formal. Next a record type is built which is used to
7234 -- hold the parameter values. The name of this record type is entryP where
7235 -- entry is the name of the entry, with an additional corresponding access
7236 -- type called entryPA. The record type has matching components for each
7237 -- formal (the component names are the same as the formal names). For
7238 -- elementary types, the component type matches the formal type. For
7239 -- composite types, an access type is declared (with the name formalA)
7240 -- which designates the formal type, and the type of the component is this
7241 -- access type. Finally the Entry_Component of each formal is set to
7242 -- reference the corresponding record component.
7244 procedure Expand_N_Entry_Declaration (N : Node_Id) is
7245 Loc : constant Source_Ptr := Sloc (N);
7246 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
7247 Components : List_Id;
7250 Last_Decl : Node_Id;
7251 Component : Entity_Id;
7254 Rec_Ent : Entity_Id;
7255 Acc_Ent : Entity_Id;
7258 Formal := First_Formal (Entry_Ent);
7261 -- Most processing is done only if parameters are present
7263 if Present (Formal) then
7264 Components := New_List;
7266 -- Loop through formals
7268 while Present (Formal) loop
7269 Set_Is_Entry_Formal (Formal);
7271 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
7272 Set_Entry_Component (Formal, Component);
7273 Set_Entry_Formal (Component, Formal);
7274 Ftype := Etype (Formal);
7276 -- Declare new access type and then append
7278 Ctype := Make_Temporary (Loc, 'A');
7281 Make_Full_Type_Declaration (Loc,
7282 Defining_Identifier => Ctype,
7284 Make_Access_To_Object_Definition (Loc,
7285 All_Present => True,
7286 Constant_Present => Ekind (Formal) = E_In_Parameter,
7287 Subtype_Indication => New_Reference_To (Ftype, Loc)));
7289 Insert_After (Last_Decl, Decl);
7292 Append_To (Components,
7293 Make_Component_Declaration (Loc,
7294 Defining_Identifier => Component,
7295 Component_Definition =>
7296 Make_Component_Definition (Loc,
7297 Aliased_Present => False,
7298 Subtype_Indication => New_Reference_To (Ctype, Loc))));
7300 Next_Formal_With_Extras (Formal);
7303 -- Create the Entry_Parameter_Record declaration
7305 Rec_Ent := Make_Temporary (Loc, 'P');
7308 Make_Full_Type_Declaration (Loc,
7309 Defining_Identifier => Rec_Ent,
7311 Make_Record_Definition (Loc,
7313 Make_Component_List (Loc,
7314 Component_Items => Components)));
7316 Insert_After (Last_Decl, Decl);
7319 -- Construct and link in the corresponding access type
7321 Acc_Ent := Make_Temporary (Loc, 'A');
7323 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
7326 Make_Full_Type_Declaration (Loc,
7327 Defining_Identifier => Acc_Ent,
7329 Make_Access_To_Object_Definition (Loc,
7330 All_Present => True,
7331 Subtype_Indication => New_Reference_To (Rec_Ent, Loc)));
7333 Insert_After (Last_Decl, Decl);
7336 end Expand_N_Entry_Declaration;
7338 -----------------------------
7339 -- Expand_N_Protected_Body --
7340 -----------------------------
7342 -- Protected bodies are expanded to the completion of the subprograms
7343 -- created for the corresponding protected type. These are a protected and
7344 -- unprotected version of each protected subprogram in the object, a
7345 -- function to calculate each entry barrier, and a procedure to execute the
7346 -- sequence of statements of each protected entry body. For example, for
7347 -- protected type ptype:
7350 -- (O : System.Address;
7351 -- E : Protected_Entry_Index)
7354 -- <discriminant renamings>
7355 -- <private object renamings>
7357 -- return <barrier expression>;
7360 -- procedure pprocN (_object : in out poV;...) is
7361 -- <discriminant renamings>
7362 -- <private object renamings>
7364 -- <sequence of statements>
7367 -- procedure pprocP (_object : in out poV;...) is
7368 -- procedure _clean is
7371 -- ptypeS (_object, Pn);
7372 -- Unlock (_object._object'Access);
7373 -- Abort_Undefer.all;
7378 -- Lock (_object._object'Access);
7379 -- pprocN (_object;...);
7384 -- function pfuncN (_object : poV;...) return Return_Type is
7385 -- <discriminant renamings>
7386 -- <private object renamings>
7388 -- <sequence of statements>
7391 -- function pfuncP (_object : poV) return Return_Type is
7392 -- procedure _clean is
7394 -- Unlock (_object._object'Access);
7395 -- Abort_Undefer.all;
7400 -- Lock (_object._object'Access);
7401 -- return pfuncN (_object);
7408 -- (O : System.Address;
7409 -- P : System.Address;
7410 -- E : Protected_Entry_Index)
7412 -- <discriminant renamings>
7413 -- <private object renamings>
7414 -- type poVP is access poV;
7415 -- _Object : ptVP := ptVP!(O);
7419 -- <statement sequence>
7420 -- Complete_Entry_Body (_Object._Object);
7422 -- when all others =>
7423 -- Exceptional_Complete_Entry_Body (
7424 -- _Object._Object, Get_GNAT_Exception);
7428 -- The type poV is the record created for the protected type to hold
7429 -- the state of the protected object.
7431 procedure Expand_N_Protected_Body (N : Node_Id) is
7432 Loc : constant Source_Ptr := Sloc (N);
7433 Pid : constant Entity_Id := Corresponding_Spec (N);
7435 Current_Node : Node_Id;
7436 Disp_Op_Body : Node_Id;
7437 New_Op_Body : Node_Id;
7438 Num_Entries : Natural := 0;
7442 function Build_Dispatching_Subprogram_Body
7445 Prot_Bod : Node_Id) return Node_Id;
7446 -- Build a dispatching version of the protected subprogram body. The
7447 -- newly generated subprogram contains a call to the original protected
7448 -- body. The following code is generated:
7450 -- function <protected-function-name> (Param1 .. ParamN) return
7453 -- return <protected-function-name>P (Param1 .. ParamN);
7454 -- end <protected-function-name>;
7458 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
7460 -- <protected-procedure-name>P (Param1 .. ParamN);
7461 -- end <protected-procedure-name>
7463 ---------------------------------------
7464 -- Build_Dispatching_Subprogram_Body --
7465 ---------------------------------------
7467 function Build_Dispatching_Subprogram_Body
7470 Prot_Bod : Node_Id) return Node_Id
7472 Loc : constant Source_Ptr := Sloc (N);
7479 -- Generate a specification without a letter suffix in order to
7480 -- override an interface function or procedure.
7482 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
7484 -- The formal parameters become the actuals of the protected function
7485 -- or procedure call.
7487 Actuals := New_List;
7488 Formal := First (Parameter_Specifications (Spec));
7489 while Present (Formal) loop
7491 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
7496 if Nkind (Spec) = N_Procedure_Specification then
7499 Make_Procedure_Call_Statement (Loc,
7501 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7502 Parameter_Associations => Actuals));
7504 pragma Assert (Nkind (Spec) = N_Function_Specification);
7508 Make_Simple_Return_Statement (Loc,
7510 Make_Function_Call (Loc,
7512 New_Reference_To (Corresponding_Spec (Prot_Bod), Loc),
7513 Parameter_Associations => Actuals)));
7517 Make_Subprogram_Body (Loc,
7518 Declarations => Empty_List,
7519 Specification => Spec,
7520 Handled_Statement_Sequence =>
7521 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
7522 end Build_Dispatching_Subprogram_Body;
7524 -- Start of processing for Expand_N_Protected_Body
7527 if No_Run_Time_Mode then
7528 Error_Msg_CRT ("protected body", N);
7532 -- This is the proper body corresponding to a stub. The declarations
7533 -- must be inserted at the point of the stub, which in turn is in the
7534 -- declarative part of the parent unit.
7536 if Nkind (Parent (N)) = N_Subunit then
7537 Current_Node := Corresponding_Stub (Parent (N));
7542 Op_Body := First (Declarations (N));
7544 -- The protected body is replaced with the bodies of its
7545 -- protected operations, and the declarations for internal objects
7546 -- that may have been created for entry family bounds.
7548 Rewrite (N, Make_Null_Statement (Sloc (N)));
7551 while Present (Op_Body) loop
7552 case Nkind (Op_Body) is
7553 when N_Subprogram_Declaration =>
7556 when N_Subprogram_Body =>
7558 -- Do not create bodies for eliminated operations
7560 if not Is_Eliminated (Defining_Entity (Op_Body))
7561 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
7564 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
7566 Insert_After (Current_Node, New_Op_Body);
7567 Current_Node := New_Op_Body;
7568 Analyze (New_Op_Body);
7570 -- Build the corresponding protected operation. It may
7571 -- appear that this is needed only if this is a visible
7572 -- operation of the type, or if it is an interrupt handler,
7573 -- and this was the strategy used previously in GNAT.
7574 -- However, the operation may be exported through a 'Access
7575 -- to an external caller. This is the common idiom in code
7576 -- that uses the Ada 2005 Timing_Events package. As a result
7577 -- we need to produce the protected body for both visible
7578 -- and private operations, as well as operations that only
7579 -- have a body in the source, and for which we create a
7580 -- declaration in the protected body itself.
7582 if Present (Corresponding_Spec (Op_Body)) then
7584 Build_Protected_Subprogram_Body (
7585 Op_Body, Pid, Specification (New_Op_Body));
7587 Insert_After (Current_Node, New_Op_Body);
7588 Analyze (New_Op_Body);
7590 Current_Node := New_Op_Body;
7592 -- Generate an overriding primitive operation body for
7593 -- this subprogram if the protected type implements an
7596 if Ada_Version >= Ada_2005
7598 Present (Interfaces (Corresponding_Record_Type (Pid)))
7601 Build_Dispatching_Subprogram_Body
7602 (Op_Body, Pid, New_Op_Body);
7604 Insert_After (Current_Node, Disp_Op_Body);
7605 Analyze (Disp_Op_Body);
7607 Current_Node := Disp_Op_Body;
7612 when N_Entry_Body =>
7613 Op_Id := Defining_Identifier (Op_Body);
7614 Num_Entries := Num_Entries + 1;
7616 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
7618 Insert_After (Current_Node, New_Op_Body);
7619 Current_Node := New_Op_Body;
7620 Analyze (New_Op_Body);
7622 when N_Implicit_Label_Declaration =>
7625 when N_Itype_Reference =>
7626 Insert_After (Current_Node, New_Copy (Op_Body));
7628 when N_Freeze_Entity =>
7629 New_Op_Body := New_Copy (Op_Body);
7631 if Present (Entity (Op_Body))
7632 and then Freeze_Node (Entity (Op_Body)) = Op_Body
7634 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
7637 Insert_After (Current_Node, New_Op_Body);
7638 Current_Node := New_Op_Body;
7639 Analyze (New_Op_Body);
7642 New_Op_Body := New_Copy (Op_Body);
7643 Insert_After (Current_Node, New_Op_Body);
7644 Current_Node := New_Op_Body;
7645 Analyze (New_Op_Body);
7647 when N_Object_Declaration =>
7648 pragma Assert (not Comes_From_Source (Op_Body));
7649 New_Op_Body := New_Copy (Op_Body);
7650 Insert_After (Current_Node, New_Op_Body);
7651 Current_Node := New_Op_Body;
7652 Analyze (New_Op_Body);
7655 raise Program_Error;
7662 -- Finally, create the body of the function that maps an entry index
7663 -- into the corresponding body index, except when there is no entry, or
7664 -- in a Ravenscar-like profile.
7666 if Corresponding_Runtime_Package (Pid) =
7667 System_Tasking_Protected_Objects_Entries
7669 New_Op_Body := Build_Find_Body_Index (Pid);
7670 Insert_After (Current_Node, New_Op_Body);
7671 Current_Node := New_Op_Body;
7672 Analyze (New_Op_Body);
7675 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
7676 -- protected body. At this point all wrapper specs have been created,
7677 -- frozen and included in the dispatch table for the protected type.
7679 if Ada_Version >= Ada_2005 then
7680 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
7682 end Expand_N_Protected_Body;
7684 -----------------------------------------
7685 -- Expand_N_Protected_Type_Declaration --
7686 -----------------------------------------
7688 -- First we create a corresponding record type declaration used to
7689 -- represent values of this protected type.
7690 -- The general form of this type declaration is
7692 -- type poV (discriminants) is record
7693 -- _Object : aliased <kind>Protection
7694 -- [(<entry count> [, <handler count>])];
7695 -- [entry_family : array (bounds) of Void;]
7696 -- <private data fields>
7699 -- The discriminants are present only if the corresponding protected type
7700 -- has discriminants, and they exactly mirror the protected type
7701 -- discriminants. The private data fields similarly mirror the private
7702 -- declarations of the protected type.
7704 -- The Object field is always present. It contains RTS specific data used
7705 -- to control the protected object. It is declared as Aliased so that it
7706 -- can be passed as a pointer to the RTS. This allows the protected record
7707 -- to be referenced within RTS data structures. An appropriate Protection
7708 -- type and discriminant are generated.
7710 -- The Service field is present for protected objects with entries. It
7711 -- contains sufficient information to allow the entry service procedure for
7712 -- this object to be called when the object is not known till runtime.
7714 -- One entry_family component is present for each entry family in the
7715 -- task definition (see Expand_N_Task_Type_Declaration).
7717 -- When a protected object is declared, an instance of the protected type
7718 -- value record is created. The elaboration of this declaration creates the
7719 -- correct bounds for the entry families, and also evaluates the priority
7720 -- expression if needed. The initialization routine for the protected type
7721 -- itself then calls Initialize_Protection with appropriate parameters to
7722 -- initialize the value of the Task_Id field. Install_Handlers may be also
7723 -- called if a pragma Attach_Handler applies.
7725 -- Note: this record is passed to the subprograms created by the expansion
7726 -- of protected subprograms and entries. It is an in parameter to protected
7727 -- functions and an in out parameter to procedures and entry bodies. The
7728 -- Entity_Id for this created record type is placed in the
7729 -- Corresponding_Record_Type field of the associated protected type entity.
7731 -- Next we create a procedure specifications for protected subprograms and
7732 -- entry bodies. For each protected subprograms two subprograms are
7733 -- created, an unprotected and a protected version. The unprotected version
7734 -- is called from within other operations of the same protected object.
7736 -- We also build the call to register the procedure if a pragma
7737 -- Interrupt_Handler applies.
7739 -- A single subprogram is created to service all entry bodies; it has an
7740 -- additional boolean out parameter indicating that the previous entry call
7741 -- made by the current task was serviced immediately, i.e. not by proxy.
7742 -- The O parameter contains a pointer to a record object of the type
7743 -- described above. An untyped interface is used here to allow this
7744 -- procedure to be called in places where the type of the object to be
7745 -- serviced is not known. This must be done, for example, when a call that
7746 -- may have been requeued is cancelled; the corresponding object must be
7747 -- serviced, but which object that is not known till runtime.
7750 -- (O : System.Address; P : out Boolean);
7751 -- procedure pprocN (_object : in out poV);
7752 -- procedure pproc (_object : in out poV);
7753 -- function pfuncN (_object : poV);
7754 -- function pfunc (_object : poV);
7757 -- Note that this must come after the record type declaration, since
7758 -- the specs refer to this type.
7760 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
7761 Loc : constant Source_Ptr := Sloc (N);
7762 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
7764 Pdef : constant Node_Id := Protected_Definition (N);
7765 -- This contains two lists; one for visible and one for private decls
7769 Discr_Map : constant Elist_Id := New_Elmt_List;
7773 Comp_Id : Entity_Id;
7775 Current_Node : Node_Id := N;
7776 Bdef : Entity_Id := Empty; -- avoid uninit warning
7777 Edef : Entity_Id := Empty; -- avoid uninit warning
7778 Entries_Aggr : Node_Id;
7779 Body_Id : Entity_Id;
7782 Object_Comp : Node_Id;
7784 procedure Check_Inlining (Subp : Entity_Id);
7785 -- If the original operation has a pragma Inline, propagate the flag
7786 -- to the internal body, for possible inlining later on. The source
7787 -- operation is invisible to the back-end and is never actually called.
7789 function Static_Component_Size (Comp : Entity_Id) return Boolean;
7790 -- When compiling under the Ravenscar profile, private components must
7791 -- have a static size, or else a protected object will require heap
7792 -- allocation, violating the corresponding restriction. It is preferable
7793 -- to make this check here, because it provides a better error message
7794 -- than the back-end, which refers to the object as a whole.
7796 procedure Register_Handler;
7797 -- For a protected operation that is an interrupt handler, add the
7798 -- freeze action that will register it as such.
7800 --------------------
7801 -- Check_Inlining --
7802 --------------------
7804 procedure Check_Inlining (Subp : Entity_Id) is
7806 if Is_Inlined (Subp) then
7807 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
7808 Set_Is_Inlined (Subp, False);
7812 ---------------------------------
7813 -- Check_Static_Component_Size --
7814 ---------------------------------
7816 function Static_Component_Size (Comp : Entity_Id) return Boolean is
7817 Typ : constant Entity_Id := Etype (Comp);
7821 if Is_Scalar_Type (Typ) then
7824 elsif Is_Array_Type (Typ) then
7825 return Compile_Time_Known_Bounds (Typ);
7827 elsif Is_Record_Type (Typ) then
7828 C := First_Component (Typ);
7829 while Present (C) loop
7830 if not Static_Component_Size (C) then
7839 -- Any other types will be checked by the back-end
7844 end Static_Component_Size;
7846 ----------------------
7847 -- Register_Handler --
7848 ----------------------
7850 procedure Register_Handler is
7852 -- All semantic checks already done in Sem_Prag
7854 Prot_Proc : constant Entity_Id :=
7856 (Specification (Current_Node));
7858 Proc_Address : constant Node_Id :=
7859 Make_Attribute_Reference (Loc,
7860 Prefix => New_Reference_To (Prot_Proc, Loc),
7861 Attribute_Name => Name_Address);
7863 RTS_Call : constant Entity_Id :=
7864 Make_Procedure_Call_Statement (Loc,
7867 RTE (RE_Register_Interrupt_Handler), Loc),
7868 Parameter_Associations =>
7869 New_List (Proc_Address));
7871 Append_Freeze_Action (Prot_Proc, RTS_Call);
7872 end Register_Handler;
7874 -- Start of processing for Expand_N_Protected_Type_Declaration
7877 if Present (Corresponding_Record_Type (Prot_Typ)) then
7880 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
7883 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
7885 Qualify_Entity_Names (N);
7887 -- If the type has discriminants, their occurrences in the declaration
7888 -- have been replaced by the corresponding discriminals. For components
7889 -- that are constrained by discriminants, their homologues in the
7890 -- corresponding record type must refer to the discriminants of that
7891 -- record, so we must apply a new renaming to subtypes_indications:
7893 -- protected discriminant => discriminal => record discriminant
7895 -- This replacement is not applied to default expressions, for which
7896 -- the discriminal is correct.
7898 if Has_Discriminants (Prot_Typ) then
7904 Disc := First_Discriminant (Prot_Typ);
7905 Decl := First (Discriminant_Specifications (Rec_Decl));
7906 while Present (Disc) loop
7907 Append_Elmt (Discriminal (Disc), Discr_Map);
7908 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
7909 Next_Discriminant (Disc);
7915 -- Fill in the component declarations
7917 -- Add components for entry families. For each entry family, create an
7918 -- anonymous type declaration with the same size, and analyze the type.
7920 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
7922 -- Prepend the _Object field with the right type to the component list.
7923 -- We need to compute the number of entries, and in some cases the
7924 -- number of Attach_Handler pragmas.
7928 Num_Attach_Handler : Int := 0;
7929 Protection_Subtype : Node_Id;
7930 Entry_Count_Expr : constant Node_Id :=
7931 Build_Entry_Count_Expression
7932 (Prot_Typ, Cdecls, Loc);
7935 -- Could this be simplified using Corresponding_Runtime_Package???
7937 if Has_Attach_Handler (Prot_Typ) then
7938 Ritem := First_Rep_Item (Prot_Typ);
7939 while Present (Ritem) loop
7940 if Nkind (Ritem) = N_Pragma
7941 and then Pragma_Name (Ritem) = Name_Attach_Handler
7943 Num_Attach_Handler := Num_Attach_Handler + 1;
7946 Next_Rep_Item (Ritem);
7949 if Restricted_Profile then
7950 if Has_Entries (Prot_Typ) then
7951 Protection_Subtype :=
7952 New_Reference_To (RTE (RE_Protection_Entry), Loc);
7954 Protection_Subtype :=
7955 New_Reference_To (RTE (RE_Protection), Loc);
7958 Protection_Subtype :=
7959 Make_Subtype_Indication
7963 (RTE (RE_Static_Interrupt_Protection), Loc),
7965 Make_Index_Or_Discriminant_Constraint (
7967 Constraints => New_List (
7969 Make_Integer_Literal (Loc, Num_Attach_Handler))));
7972 elsif Has_Interrupt_Handler (Prot_Typ) then
7973 Protection_Subtype :=
7974 Make_Subtype_Indication (
7976 Subtype_Mark => New_Reference_To
7977 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
7979 Make_Index_Or_Discriminant_Constraint (
7981 Constraints => New_List (Entry_Count_Expr)));
7983 -- Type has explicit entries or generated primitive entry wrappers
7985 elsif Has_Entries (Prot_Typ)
7986 or else (Ada_Version >= Ada_2005
7987 and then Present (Interface_List (N)))
7989 case Corresponding_Runtime_Package (Prot_Typ) is
7990 when System_Tasking_Protected_Objects_Entries =>
7991 Protection_Subtype :=
7992 Make_Subtype_Indication (Loc,
7994 New_Reference_To (RTE (RE_Protection_Entries), Loc),
7996 Make_Index_Or_Discriminant_Constraint (
7998 Constraints => New_List (Entry_Count_Expr)));
8000 when System_Tasking_Protected_Objects_Single_Entry =>
8001 Protection_Subtype :=
8002 New_Reference_To (RTE (RE_Protection_Entry), Loc);
8005 raise Program_Error;
8009 Protection_Subtype := New_Reference_To (RTE (RE_Protection), Loc);
8013 Make_Component_Declaration (Loc,
8014 Defining_Identifier =>
8015 Make_Defining_Identifier (Loc, Name_uObject),
8016 Component_Definition =>
8017 Make_Component_Definition (Loc,
8018 Aliased_Present => True,
8019 Subtype_Indication => Protection_Subtype));
8022 pragma Assert (Present (Pdef));
8024 -- Add private field components
8026 if Present (Private_Declarations (Pdef)) then
8027 Priv := First (Private_Declarations (Pdef));
8029 while Present (Priv) loop
8031 if Nkind (Priv) = N_Component_Declaration then
8032 if not Static_Component_Size (Defining_Identifier (Priv)) then
8034 -- When compiling for a restricted profile, the private
8035 -- components must have a static size. If not, this is an
8036 -- error for a single protected declaration, and rates a
8037 -- warning on a protected type declaration.
8039 if not Comes_From_Source (Prot_Typ) then
8040 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8042 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
8043 Error_Msg_N ("component has non-static size?", Priv);
8045 ("\creation of protected object of type& will violate"
8046 & " restriction No_Implicit_Heap_Allocations?",
8051 -- The component definition consists of a subtype indication,
8052 -- or (in Ada 2005) an access definition. Make a copy of the
8053 -- proper definition.
8056 Old_Comp : constant Node_Id := Component_Definition (Priv);
8057 Oent : constant Entity_Id := Defining_Identifier (Priv);
8059 Nent : constant Entity_Id :=
8060 Make_Defining_Identifier (Sloc (Oent),
8061 Chars => Chars (Oent));
8064 if Present (Subtype_Indication (Old_Comp)) then
8066 Make_Component_Definition (Sloc (Oent),
8067 Aliased_Present => False,
8068 Subtype_Indication =>
8069 New_Copy_Tree (Subtype_Indication (Old_Comp),
8073 Make_Component_Definition (Sloc (Oent),
8074 Aliased_Present => False,
8075 Access_Definition =>
8076 New_Copy_Tree (Access_Definition (Old_Comp),
8081 Make_Component_Declaration (Loc,
8082 Defining_Identifier => Nent,
8083 Component_Definition => New_Comp,
8084 Expression => Expression (Priv));
8086 Set_Has_Per_Object_Constraint (Nent,
8087 Has_Per_Object_Constraint (Oent));
8089 Append_To (Cdecls, New_Priv);
8092 elsif Nkind (Priv) = N_Subprogram_Declaration then
8094 -- Make the unprotected version of the subprogram available
8095 -- for expansion of intra object calls. There is need for
8096 -- a protected version only if the subprogram is an interrupt
8097 -- handler, otherwise this operation can only be called from
8101 Make_Subprogram_Declaration (Loc,
8103 Build_Protected_Sub_Specification
8104 (Priv, Prot_Typ, Unprotected_Mode));
8106 Insert_After (Current_Node, Sub);
8109 Set_Protected_Body_Subprogram
8110 (Defining_Unit_Name (Specification (Priv)),
8111 Defining_Unit_Name (Specification (Sub)));
8112 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
8113 Current_Node := Sub;
8116 Make_Subprogram_Declaration (Loc,
8118 Build_Protected_Sub_Specification
8119 (Priv, Prot_Typ, Protected_Mode));
8121 Insert_After (Current_Node, Sub);
8123 Current_Node := Sub;
8125 if Is_Interrupt_Handler
8126 (Defining_Unit_Name (Specification (Priv)))
8128 if not Restricted_Profile then
8138 -- Put the _Object component after the private component so that it
8139 -- be finalized early as required by 9.4 (20)
8141 Append_To (Cdecls, Object_Comp);
8143 Insert_After (Current_Node, Rec_Decl);
8144 Current_Node := Rec_Decl;
8146 -- Analyze the record declaration immediately after construction,
8147 -- because the initialization procedure is needed for single object
8148 -- declarations before the next entity is analyzed (the freeze call
8149 -- that generates this initialization procedure is found below).
8151 Analyze (Rec_Decl, Suppress => All_Checks);
8153 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
8154 -- the corresponding record is frozen. If any wrappers are generated,
8155 -- Current_Node is updated accordingly.
8157 if Ada_Version >= Ada_2005 then
8158 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
8161 -- Collect pointers to entry bodies and their barriers, to be placed
8162 -- in the Entry_Bodies_Array for the type. For each entry/family we
8163 -- add an expression to the aggregate which is the initial value of
8164 -- this array. The array is declared after all protected subprograms.
8166 if Has_Entries (Prot_Typ) then
8167 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
8169 Entries_Aggr := Empty;
8172 -- Build two new procedure specifications for each protected subprogram;
8173 -- one to call from outside the object and one to call from inside.
8174 -- Build a barrier function and an entry body action procedure
8175 -- specification for each protected entry. Initialize the entry body
8176 -- array. If subprogram is flagged as eliminated, do not generate any
8177 -- internal operations.
8181 Comp := First (Visible_Declarations (Pdef));
8183 while Present (Comp) loop
8184 if Nkind (Comp) = N_Subprogram_Declaration then
8186 Make_Subprogram_Declaration (Loc,
8188 Build_Protected_Sub_Specification
8189 (Comp, Prot_Typ, Unprotected_Mode));
8191 Insert_After (Current_Node, Sub);
8194 Set_Protected_Body_Subprogram
8195 (Defining_Unit_Name (Specification (Comp)),
8196 Defining_Unit_Name (Specification (Sub)));
8197 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
8199 -- Make the protected version of the subprogram available for
8200 -- expansion of external calls.
8202 Current_Node := Sub;
8205 Make_Subprogram_Declaration (Loc,
8207 Build_Protected_Sub_Specification
8208 (Comp, Prot_Typ, Protected_Mode));
8210 Insert_After (Current_Node, Sub);
8213 Current_Node := Sub;
8215 -- Generate an overriding primitive operation specification for
8216 -- this subprogram if the protected type implements an interface.
8218 if Ada_Version >= Ada_2005
8220 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
8223 Make_Subprogram_Declaration (Loc,
8225 Build_Protected_Sub_Specification
8226 (Comp, Prot_Typ, Dispatching_Mode));
8228 Insert_After (Current_Node, Sub);
8231 Current_Node := Sub;
8234 -- If a pragma Interrupt_Handler applies, build and add a call to
8235 -- Register_Interrupt_Handler to the freezing actions of the
8236 -- protected version (Current_Node) of the subprogram:
8238 -- system.interrupts.register_interrupt_handler
8239 -- (prot_procP'address);
8241 if not Restricted_Profile
8242 and then Is_Interrupt_Handler
8243 (Defining_Unit_Name (Specification (Comp)))
8248 elsif Nkind (Comp) = N_Entry_Declaration then
8249 E_Count := E_Count + 1;
8250 Comp_Id := Defining_Identifier (Comp);
8253 Make_Defining_Identifier (Loc,
8254 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8256 Make_Subprogram_Declaration (Loc,
8258 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8260 Insert_After (Current_Node, Sub);
8263 -- build wrapper procedure for pre/postconditions.
8265 Build_PPC_Wrapper (Comp_Id, N);
8267 Set_Protected_Body_Subprogram
8268 (Defining_Identifier (Comp),
8269 Defining_Unit_Name (Specification (Sub)));
8271 Current_Node := Sub;
8274 Make_Defining_Identifier (Loc,
8275 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8277 Make_Subprogram_Declaration (Loc,
8279 Build_Barrier_Function_Specification (Loc, Bdef));
8281 Insert_After (Current_Node, Sub);
8283 Set_Protected_Body_Subprogram (Bdef, Bdef);
8284 Set_Barrier_Function (Comp_Id, Bdef);
8285 Set_Scope (Bdef, Scope (Comp_Id));
8286 Current_Node := Sub;
8288 -- Collect pointers to the protected subprogram and the barrier
8289 -- of the current entry, for insertion into Entry_Bodies_Array.
8292 Make_Aggregate (Loc,
8293 Expressions => New_List (
8294 Make_Attribute_Reference (Loc,
8295 Prefix => New_Reference_To (Bdef, Loc),
8296 Attribute_Name => Name_Unrestricted_Access),
8297 Make_Attribute_Reference (Loc,
8298 Prefix => New_Reference_To (Edef, Loc),
8299 Attribute_Name => Name_Unrestricted_Access))),
8300 Expressions (Entries_Aggr));
8307 -- If there are some private entry declarations, expand it as if they
8308 -- were visible entries.
8310 if Present (Private_Declarations (Pdef)) then
8311 Comp := First (Private_Declarations (Pdef));
8312 while Present (Comp) loop
8313 if Nkind (Comp) = N_Entry_Declaration then
8314 E_Count := E_Count + 1;
8315 Comp_Id := Defining_Identifier (Comp);
8318 Make_Defining_Identifier (Loc,
8319 Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8321 Make_Subprogram_Declaration (Loc,
8323 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8325 Insert_After (Current_Node, Sub);
8328 Set_Protected_Body_Subprogram
8329 (Defining_Identifier (Comp),
8330 Defining_Unit_Name (Specification (Sub)));
8332 Current_Node := Sub;
8335 Make_Defining_Identifier (Loc,
8336 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8339 Make_Subprogram_Declaration (Loc,
8341 Build_Barrier_Function_Specification (Loc, Bdef));
8343 Insert_After (Current_Node, Sub);
8345 Set_Protected_Body_Subprogram (Bdef, Bdef);
8346 Set_Barrier_Function (Comp_Id, Bdef);
8347 Set_Scope (Bdef, Scope (Comp_Id));
8348 Current_Node := Sub;
8350 -- Collect pointers to the protected subprogram and the barrier
8351 -- of the current entry, for insertion into Entry_Bodies_Array.
8353 Append_To (Expressions (Entries_Aggr),
8354 Make_Aggregate (Loc,
8355 Expressions => New_List (
8356 Make_Attribute_Reference (Loc,
8357 Prefix => New_Reference_To (Bdef, Loc),
8358 Attribute_Name => Name_Unrestricted_Access),
8359 Make_Attribute_Reference (Loc,
8360 Prefix => New_Reference_To (Edef, Loc),
8361 Attribute_Name => Name_Unrestricted_Access))));
8368 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
8369 -- all protected subprograms have been collected.
8371 if Has_Entries (Prot_Typ) then
8373 Make_Defining_Identifier (Sloc (Prot_Typ),
8374 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
8376 case Corresponding_Runtime_Package (Prot_Typ) is
8377 when System_Tasking_Protected_Objects_Entries =>
8378 Body_Arr := Make_Object_Declaration (Loc,
8379 Defining_Identifier => Body_Id,
8380 Aliased_Present => True,
8381 Object_Definition =>
8382 Make_Subtype_Indication (Loc,
8383 Subtype_Mark => New_Reference_To (
8384 RTE (RE_Protected_Entry_Body_Array), Loc),
8386 Make_Index_Or_Discriminant_Constraint (Loc,
8387 Constraints => New_List (
8389 Make_Integer_Literal (Loc, 1),
8390 Make_Integer_Literal (Loc, E_Count))))),
8391 Expression => Entries_Aggr);
8393 when System_Tasking_Protected_Objects_Single_Entry =>
8394 Body_Arr := Make_Object_Declaration (Loc,
8395 Defining_Identifier => Body_Id,
8396 Aliased_Present => True,
8397 Object_Definition => New_Reference_To
8398 (RTE (RE_Entry_Body), Loc),
8400 Make_Aggregate (Loc,
8401 Expressions => New_List (
8402 Make_Attribute_Reference (Loc,
8403 Prefix => New_Reference_To (Bdef, Loc),
8404 Attribute_Name => Name_Unrestricted_Access),
8405 Make_Attribute_Reference (Loc,
8406 Prefix => New_Reference_To (Edef, Loc),
8407 Attribute_Name => Name_Unrestricted_Access))));
8410 raise Program_Error;
8413 -- A pointer to this array will be placed in the corresponding record
8414 -- by its initialization procedure so this needs to be analyzed here.
8416 Insert_After (Current_Node, Body_Arr);
8417 Current_Node := Body_Arr;
8420 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
8422 -- Finally, build the function that maps an entry index into the
8423 -- corresponding body. A pointer to this function is placed in each
8424 -- object of the type. Except for a ravenscar-like profile (no abort,
8425 -- no entry queue, 1 entry)
8427 if Corresponding_Runtime_Package (Prot_Typ) =
8428 System_Tasking_Protected_Objects_Entries
8431 Make_Subprogram_Declaration (Loc,
8432 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
8433 Insert_After (Current_Node, Sub);
8437 end Expand_N_Protected_Type_Declaration;
8439 --------------------------------
8440 -- Expand_N_Requeue_Statement --
8441 --------------------------------
8443 -- A non-dispatching requeue statement is expanded into one of four GNARLI
8444 -- operations, depending on the source and destination (task or protected
8445 -- object). A dispatching requeue statement is expanded into a call to the
8446 -- predefined primitive _Disp_Requeue. In addition, code is generated to
8447 -- jump around the remainder of processing for the original entry and, if
8448 -- the destination is (different) protected object, to attempt to service
8449 -- it. The following illustrates the various cases:
8452 -- (O : System.Address;
8453 -- P : System.Address;
8454 -- E : Protected_Entry_Index)
8456 -- <discriminant renamings>
8457 -- <private object renamings>
8458 -- type poVP is access poV;
8459 -- _object : ptVP := ptVP!(O);
8463 -- <start of statement sequence for entry>
8465 -- -- Requeue from one protected entry body to another protected
8468 -- Requeue_Protected_Entry (
8469 -- _object._object'Access,
8470 -- new._object'Access,
8475 -- <some more of the statement sequence for entry>
8477 -- -- Requeue from an entry body to a task entry
8479 -- Requeue_Protected_To_Task_Entry (
8485 -- <rest of statement sequence for entry>
8486 -- Complete_Entry_Body (_object._object);
8489 -- when all others =>
8490 -- Exceptional_Complete_Entry_Body (
8491 -- _object._object, Get_GNAT_Exception);
8495 -- Requeue of a task entry call to a task entry
8497 -- Accept_Call (E, Ann);
8498 -- <start of statement sequence for accept statement>
8499 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
8501 -- <rest of statement sequence for accept statement>
8503 -- Complete_Rendezvous;
8506 -- when all others =>
8507 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8509 -- Requeue of a task entry call to a protected entry
8511 -- Accept_Call (E, Ann);
8512 -- <start of statement sequence for accept statement>
8513 -- Requeue_Task_To_Protected_Entry (
8514 -- new._object'Access,
8519 -- <rest of statement sequence for accept statement>
8521 -- Complete_Rendezvous;
8524 -- when all others =>
8525 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8527 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8528 -- marked by pragma Implemented (XXX, By_Entry).
8530 -- The requeue is inside a protected entry:
8533 -- (O : System.Address;
8534 -- P : System.Address;
8535 -- E : Protected_Entry_Index)
8537 -- <discriminant renamings>
8538 -- <private object renamings>
8539 -- type poVP is access poV;
8540 -- _object : ptVP := ptVP!(O);
8544 -- <start of statement sequence for entry>
8547 -- (<interface class-wide object>,
8550 -- Ada.Tags.Get_Offset_Index
8552 -- <interface dispatch table index of target entry>),
8556 -- <rest of statement sequence for entry>
8557 -- Complete_Entry_Body (_object._object);
8560 -- when all others =>
8561 -- Exceptional_Complete_Entry_Body (
8562 -- _object._object, Get_GNAT_Exception);
8566 -- The requeue is inside a task entry:
8568 -- Accept_Call (E, Ann);
8569 -- <start of statement sequence for accept statement>
8571 -- (<interface class-wide object>,
8574 -- Ada.Tags.Get_Offset_Index
8576 -- <interface dispatch table index of target entrt>),
8580 -- <rest of statement sequence for accept statement>
8582 -- Complete_Rendezvous;
8585 -- when all others =>
8586 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
8588 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8589 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
8590 -- statement is replaced by a dispatching call with actual parameters taken
8591 -- from the inner-most accept statement or entry body.
8593 -- Target.Primitive (Param1, ..., ParamN);
8595 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
8596 -- marked by pragma Implemented (XXX, By_Any) or not marked at all.
8599 -- S : constant Offset_Index :=
8600 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
8601 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
8604 -- if C = POK_Protected_Entry
8605 -- or else C = POK_Task_Entry
8607 -- <statements for dispatching requeue>
8609 -- elsif C = POK_Protected_Procedure then
8610 -- <dispatching call equivalent>
8613 -- raise Program_Error;
8617 procedure Expand_N_Requeue_Statement (N : Node_Id) is
8618 Loc : constant Source_Ptr := Sloc (N);
8619 Conc_Typ : Entity_Id;
8623 Old_Typ : Entity_Id;
8625 function Build_Dispatching_Call_Equivalent return Node_Id;
8626 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8627 -- the form Concval.Ename. It is statically known that Ename is allowed
8628 -- to be implemented by a protected procedure. Create a dispatching call
8629 -- equivalent of Concval.Ename taking the actual parameters from the
8630 -- inner-most accept statement or entry body.
8632 function Build_Dispatching_Requeue return Node_Id;
8633 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8634 -- the form Concval.Ename. It is statically known that Ename is allowed
8635 -- to be implemented by a protected or a task entry. Create a call to
8636 -- primitive _Disp_Requeue which handles the low-level actions.
8638 function Build_Dispatching_Requeue_To_Any return Node_Id;
8639 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
8640 -- the form Concval.Ename. Ename is either marked by pragma Implemented
8641 -- (XXX, By_Any) or not marked at all. Create a block which determines
8642 -- at runtime whether Ename denotes an entry or a procedure and perform
8643 -- the appropriate kind of dispatching select.
8645 function Build_Normal_Requeue return Node_Id;
8646 -- N denotes a non-dispatching requeue statement to either a task or a
8647 -- protected entry. Build the appropriate runtime call to perform the
8650 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
8651 -- For a protected entry, create a return statement to skip the rest of
8652 -- the entry body. Otherwise, create a goto statement to skip the rest
8653 -- of a task accept statement. The lookup for the enclosing entry body
8654 -- or accept statement starts from Search.
8656 ---------------------------------------
8657 -- Build_Dispatching_Call_Equivalent --
8658 ---------------------------------------
8660 function Build_Dispatching_Call_Equivalent return Node_Id is
8661 Call_Ent : constant Entity_Id := Entity (Ename);
8662 Obj : constant Node_Id := Original_Node (Concval);
8669 -- Climb the parent chain looking for the inner-most entry body or
8670 -- accept statement.
8673 while Present (Acc_Ent)
8674 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
8677 Acc_Ent := Parent (Acc_Ent);
8680 -- A requeue statement should be housed inside an entry body or an
8681 -- accept statement at some level. If this is not the case, then the
8682 -- tree is malformed.
8684 pragma Assert (Present (Acc_Ent));
8686 -- Recover the list of formal parameters
8688 if Nkind (Acc_Ent) = N_Entry_Body then
8689 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
8692 Formals := Parameter_Specifications (Acc_Ent);
8694 -- Create the actual parameters for the dispatching call. These are
8695 -- simply copies of the entry body or accept statement formals in the
8696 -- same order as they appear.
8700 if Present (Formals) then
8701 Actuals := New_List;
8702 Formal := First (Formals);
8703 while Present (Formal) loop
8705 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8711 -- Obj.Call_Ent (Actuals);
8714 Make_Procedure_Call_Statement (Loc,
8716 Make_Selected_Component (Loc,
8717 Prefix => Make_Identifier (Loc, Chars (Obj)),
8718 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
8720 Parameter_Associations => Actuals);
8721 end Build_Dispatching_Call_Equivalent;
8723 -------------------------------
8724 -- Build_Dispatching_Requeue --
8725 -------------------------------
8727 function Build_Dispatching_Requeue return Node_Id is
8728 Params : constant List_Id := New_List;
8731 -- Process the "with abort" parameter
8734 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8736 -- Process the entry wrapper's position in the primary dispatch
8737 -- table parameter. Generate:
8739 -- Ada.Tags.Get_Offset_Index
8740 -- (Ada.Tags.Tag (Concval),
8741 -- <interface dispatch table position of Ename>)
8743 if Tagged_Type_Expansion then
8745 Make_Function_Call (Loc,
8746 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8747 Parameter_Associations => New_List (
8748 Unchecked_Convert_To (RTE (RE_Tag), Concval),
8749 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8755 Make_Function_Call (Loc,
8756 Name => New_Reference_To (RTE (RE_Get_Offset_Index), Loc),
8758 Parameter_Associations => New_List (
8762 Make_Attribute_Reference (Loc,
8764 Attribute_Name => Name_Tag),
8768 Make_Attribute_Reference (Loc,
8769 Prefix => New_Reference_To (Etype (Concval), Loc),
8770 Attribute_Name => Name_Tag),
8774 Make_Integer_Literal (Loc, DT_Position (Entity (Ename))))));
8777 -- Specific actuals for protected to XXX requeue
8779 if Is_Protected_Type (Old_Typ) then
8781 Make_Attribute_Reference (Loc, -- _object'Address
8783 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8784 Attribute_Name => Name_Address));
8786 Prepend_To (Params, -- True
8787 New_Reference_To (Standard_True, Loc));
8789 -- Specific actuals for task to XXX requeue
8792 pragma Assert (Is_Task_Type (Old_Typ));
8794 Prepend_To (Params, -- null
8795 New_Reference_To (RTE (RE_Null_Address), Loc));
8797 Prepend_To (Params, -- False
8798 New_Reference_To (Standard_False, Loc));
8801 -- Add the object parameter
8803 Prepend_To (Params, New_Copy_Tree (Concval));
8806 -- _Disp_Requeue (<Params>);
8809 Make_Procedure_Call_Statement (Loc,
8810 Name => Make_Identifier (Loc, Name_uDisp_Requeue),
8811 Parameter_Associations => Params);
8812 end Build_Dispatching_Requeue;
8814 --------------------------------------
8815 -- Build_Dispatching_Requeue_To_Any --
8816 --------------------------------------
8818 function Build_Dispatching_Requeue_To_Any return Node_Id is
8819 Call_Ent : constant Entity_Id := Entity (Ename);
8820 Obj : constant Node_Id := Original_Node (Concval);
8821 Skip : constant Node_Id := Build_Skip_Statement (N);
8831 -- Dispatch table slot processing, generate:
8834 S := Build_S (Loc, Decls);
8836 -- Call kind processing, generate:
8837 -- C : Ada.Tags.Prim_Op_Kind;
8839 C := Build_C (Loc, Decls);
8842 -- S := Ada.Tags.Get_Offset_Index
8843 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
8845 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
8848 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
8851 Make_Procedure_Call_Statement (Loc,
8854 Find_Prim_Op (Etype (Etype (Obj)),
8855 Name_uDisp_Get_Prim_Op_Kind),
8857 Parameter_Associations => New_List (
8858 New_Copy_Tree (Obj),
8859 New_Reference_To (S, Loc),
8860 New_Reference_To (C, Loc))));
8864 -- if C = POK_Protected_Entry
8865 -- or else C = POK_Task_Entry
8868 Make_If_Statement (Loc,
8874 New_Reference_To (C, Loc),
8876 New_Reference_To (RTE (RE_POK_Protected_Entry), Loc)),
8881 New_Reference_To (C, Loc),
8883 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
8885 -- Dispatching requeue equivalent
8887 Then_Statements => New_List (
8888 Build_Dispatching_Requeue,
8891 -- elsif C = POK_Protected_Procedure then
8893 Elsif_Parts => New_List (
8894 Make_Elsif_Part (Loc,
8898 New_Reference_To (C, Loc),
8901 RTE (RE_POK_Protected_Procedure), Loc)),
8903 -- Dispatching call equivalent
8905 Then_Statements => New_List (
8906 Build_Dispatching_Call_Equivalent))),
8909 -- raise Program_Error;
8912 Else_Statements => New_List (
8913 Make_Raise_Program_Error (Loc,
8914 Reason => PE_Explicit_Raise))));
8916 -- Wrap everything into a block
8919 Make_Block_Statement (Loc,
8920 Declarations => Decls,
8921 Handled_Statement_Sequence =>
8922 Make_Handled_Sequence_Of_Statements (Loc,
8923 Statements => Stmts));
8924 end Build_Dispatching_Requeue_To_Any;
8926 --------------------------
8927 -- Build_Normal_Requeue --
8928 --------------------------
8930 function Build_Normal_Requeue return Node_Id is
8931 Params : constant List_Id := New_List;
8936 -- Process the "with abort" parameter
8939 New_Reference_To (Boolean_Literals (Abort_Present (N)), Loc));
8941 -- Add the index expression to the parameters. It is common among all
8945 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
8947 if Is_Protected_Type (Old_Typ) then
8949 Self_Param : Node_Id;
8953 Make_Attribute_Reference (Loc,
8955 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
8957 Name_Unchecked_Access);
8959 -- Protected to protected requeue
8961 if Is_Protected_Type (Conc_Typ) then
8964 RTE (RE_Requeue_Protected_Entry), Loc);
8967 Make_Attribute_Reference (Loc,
8969 Concurrent_Ref (Concval),
8971 Name_Unchecked_Access);
8973 -- Protected to task requeue
8975 else pragma Assert (Is_Task_Type (Conc_Typ));
8978 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
8980 Param := Concurrent_Ref (Concval);
8983 Prepend_To (Params, Param);
8984 Prepend_To (Params, Self_Param);
8987 else pragma Assert (Is_Task_Type (Old_Typ));
8989 -- Task to protected requeue
8991 if Is_Protected_Type (Conc_Typ) then
8994 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
8997 Make_Attribute_Reference (Loc,
8999 Concurrent_Ref (Concval),
9001 Name_Unchecked_Access);
9003 -- Task to task requeue
9005 else pragma Assert (Is_Task_Type (Conc_Typ));
9007 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc);
9009 Param := Concurrent_Ref (Concval);
9012 Prepend_To (Params, Param);
9016 Make_Procedure_Call_Statement (Loc,
9018 Parameter_Associations => Params);
9019 end Build_Normal_Requeue;
9021 --------------------------
9022 -- Build_Skip_Statement --
9023 --------------------------
9025 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
9026 Skip_Stmt : Node_Id;
9029 -- Build a return statement to skip the rest of the entire body
9031 if Is_Protected_Type (Old_Typ) then
9032 Skip_Stmt := Make_Simple_Return_Statement (Loc);
9034 -- If the requeue is within a task, find the end label of the
9035 -- enclosing accept statement and create a goto statement to it.
9043 -- Climb the parent chain looking for the enclosing accept
9046 Acc := Parent (Search);
9048 and then Nkind (Acc) /= N_Accept_Statement
9050 Acc := Parent (Acc);
9053 -- The last statement is the second label used for completing
9054 -- the rendezvous the usual way. The label we are looking for
9055 -- is right before it.
9058 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
9060 pragma Assert (Nkind (Label) = N_Label);
9062 -- Generate a goto statement to skip the rest of the accept
9065 Make_Goto_Statement (Loc,
9067 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
9071 Set_Analyzed (Skip_Stmt);
9074 end Build_Skip_Statement;
9076 -- Start of processing for Expand_N_Requeue_Statement
9079 -- Extract the components of the entry call
9081 Extract_Entry (N, Concval, Ename, Index);
9082 Conc_Typ := Etype (Concval);
9084 -- Examine the scope stack in order to find nearest enclosing protected
9085 -- or task type. This will constitute our invocation source.
9087 Old_Typ := Current_Scope;
9088 while Present (Old_Typ)
9089 and then not Is_Protected_Type (Old_Typ)
9090 and then not Is_Task_Type (Old_Typ)
9092 Old_Typ := Scope (Old_Typ);
9095 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
9096 -- Concval.Ename where the type of Concval is class-wide concurrent
9099 if Ada_Version >= Ada_2012
9100 and then Present (Concval)
9101 and then Is_Class_Wide_Type (Conc_Typ)
9102 and then Is_Concurrent_Interface (Conc_Typ)
9105 Has_Impl : Boolean := False;
9106 Impl_Kind : Name_Id := No_Name;
9109 -- Check whether the Ename is flagged by pragma Implemented
9111 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
9113 Impl_Kind := Implementation_Kind (Entity (Ename));
9116 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9117 -- an entry. Create a call to predefined primitive _Disp_Requeue.
9120 and then Impl_Kind = Name_By_Entry
9122 Rewrite (N, Build_Dispatching_Requeue);
9124 Insert_After (N, Build_Skip_Statement (N));
9126 -- The procedure_or_entry_NAME is guaranteed to be overridden by
9127 -- a protected procedure. In this case the requeue is transformed
9128 -- into a dispatching call.
9131 and then Impl_Kind = Name_By_Protected_Procedure
9133 Rewrite (N, Build_Dispatching_Call_Equivalent);
9136 -- The procedure_or_entry_NAME's implementation kind is either
9137 -- By_Any or pragma Implemented was not applied at all. In this
9138 -- case a runtime test determines whether Ename denotes an entry
9139 -- or a protected procedure and performs the appropriate call.
9142 Rewrite (N, Build_Dispatching_Requeue_To_Any);
9147 -- Processing for regular (non-dispatching) requeues
9150 Rewrite (N, Build_Normal_Requeue);
9152 Insert_After (N, Build_Skip_Statement (N));
9154 end Expand_N_Requeue_Statement;
9156 -------------------------------
9157 -- Expand_N_Selective_Accept --
9158 -------------------------------
9160 procedure Expand_N_Selective_Accept (N : Node_Id) is
9161 Loc : constant Source_Ptr := Sloc (N);
9162 Alts : constant List_Id := Select_Alternatives (N);
9164 -- Note: in the below declarations a lot of new lists are allocated
9165 -- unconditionally which may well not end up being used. That's
9166 -- not a good idea since it wastes space gratuitously ???
9168 Accept_Case : List_Id;
9169 Accept_List : constant List_Id := New_List;
9172 Alt_List : constant List_Id := New_List;
9173 Alt_Stats : List_Id;
9174 Ann : Entity_Id := Empty;
9177 Check_Guard : Boolean := True;
9179 Decls : constant List_Id := New_List;
9180 Stats : constant List_Id := New_List;
9181 Body_List : constant List_Id := New_List;
9182 Trailing_List : constant List_Id := New_List;
9185 Else_Present : Boolean := False;
9186 Terminate_Alt : Node_Id := Empty;
9187 Select_Mode : Node_Id;
9189 Delay_Case : List_Id;
9190 Delay_Count : Integer := 0;
9191 Delay_Val : Entity_Id;
9192 Delay_Index : Entity_Id;
9193 Delay_Min : Entity_Id;
9194 Delay_Num : Int := 1;
9195 Delay_Alt_List : List_Id := New_List;
9196 Delay_List : constant List_Id := New_List;
9200 First_Delay : Boolean := True;
9201 Guard_Open : Entity_Id;
9207 Num_Accept : Nat := 0;
9210 Time_Type : Entity_Id;
9212 Select_Call : Node_Id;
9214 Qnam : constant Entity_Id :=
9215 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
9217 Xnam : constant Entity_Id :=
9218 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
9220 -----------------------
9221 -- Local subprograms --
9222 -----------------------
9224 function Accept_Or_Raise return List_Id;
9225 -- For the rare case where delay alternatives all have guards, and
9226 -- all of them are closed, it is still possible that there were open
9227 -- accept alternatives with no callers. We must reexamine the
9228 -- Accept_List, and execute a selective wait with no else if some
9229 -- accept is open. If none, we raise program_error.
9231 procedure Add_Accept (Alt : Node_Id);
9232 -- Process a single accept statement in a select alternative. Build
9233 -- procedure for body of accept, and add entry to dispatch table with
9234 -- expression for guard, in preparation for call to run time select.
9236 function Make_And_Declare_Label (Num : Int) return Node_Id;
9237 -- Manufacture a label using Num as a serial number and declare it.
9238 -- The declaration is appended to Decls. The label marks the trailing
9239 -- statements of an accept or delay alternative.
9241 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
9242 -- Build call to Selective_Wait runtime routine
9244 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
9245 -- Add code to compare value of delay with previous values, and
9246 -- generate case entry for trailing statements.
9248 procedure Process_Accept_Alternative
9252 -- Add code to call corresponding procedure, and branch to
9253 -- trailing statements, if any.
9255 ---------------------
9256 -- Accept_Or_Raise --
9257 ---------------------
9259 function Accept_Or_Raise return List_Id is
9262 J : constant Entity_Id := Make_Temporary (Loc, 'J');
9265 -- We generate the following:
9267 -- for J in q'range loop
9268 -- if q(J).S /=null_task_entry then
9269 -- selective_wait (simple_mode,...);
9275 -- if no rendez_vous then
9276 -- raise program_error;
9279 -- Note that the code needs to know that the selector name
9280 -- in an Accept_Alternative is named S.
9282 Cond := Make_Op_Ne (Loc,
9284 Make_Selected_Component (Loc,
9286 Make_Indexed_Component (Loc,
9287 Prefix => New_Reference_To (Qnam, Loc),
9288 Expressions => New_List (New_Reference_To (J, Loc))),
9289 Selector_Name => Make_Identifier (Loc, Name_S)),
9291 New_Reference_To (RTE (RE_Null_Task_Entry), Loc));
9294 Make_Implicit_Loop_Statement (N,
9295 Identifier => Empty,
9297 Make_Iteration_Scheme (Loc,
9298 Loop_Parameter_Specification =>
9299 Make_Loop_Parameter_Specification (Loc,
9300 Defining_Identifier => J,
9301 Discrete_Subtype_Definition =>
9302 Make_Attribute_Reference (Loc,
9303 Prefix => New_Reference_To (Qnam, Loc),
9304 Attribute_Name => Name_Range,
9305 Expressions => New_List (
9306 Make_Integer_Literal (Loc, 1))))),
9308 Statements => New_List (
9309 Make_Implicit_If_Statement (N,
9311 Then_Statements => New_List (
9313 New_Reference_To (RTE (RE_Simple_Mode), Loc)),
9314 Make_Exit_Statement (Loc))))));
9317 Make_Raise_Program_Error (Loc,
9318 Condition => Make_Op_Eq (Loc,
9319 Left_Opnd => New_Reference_To (Xnam, Loc),
9321 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
9322 Reason => PE_All_Guards_Closed));
9325 end Accept_Or_Raise;
9331 procedure Add_Accept (Alt : Node_Id) is
9332 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
9333 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
9334 Eloc : constant Source_Ptr := Sloc (Ename);
9335 Eent : constant Entity_Id := Entity (Ename);
9336 Index : constant Node_Id := Entry_Index (Acc_Stm);
9337 Null_Body : Node_Id;
9338 Proc_Body : Node_Id;
9345 Ann := Node (Last_Elmt (Accept_Address (Eent)));
9348 if Present (Condition (Alt)) then
9350 Make_Conditional_Expression (Eloc, New_List (
9352 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
9353 New_Reference_To (RTE (RE_Null_Task_Entry), Eloc)));
9356 Entry_Index_Expression
9357 (Eloc, Eent, Index, Scope (Eent));
9360 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9361 Null_Body := New_Reference_To (Standard_False, Eloc);
9363 if Abort_Allowed then
9364 Call := Make_Procedure_Call_Statement (Eloc,
9365 Name => New_Reference_To (RTE (RE_Abort_Undefer), Eloc));
9366 Insert_Before (First (Statements (Handled_Statement_Sequence (
9367 Accept_Statement (Alt)))), Call);
9372 Make_Defining_Identifier (Eloc,
9373 New_External_Name (Chars (Ename), 'A', Num_Accept));
9375 if Comes_From_Source (Alt) then
9376 Set_Debug_Info_Needed (PB_Ent);
9380 Make_Subprogram_Body (Eloc,
9382 Make_Procedure_Specification (Eloc,
9383 Defining_Unit_Name => PB_Ent),
9384 Declarations => Declarations (Acc_Stm),
9385 Handled_Statement_Sequence =>
9386 Build_Accept_Body (Accept_Statement (Alt)));
9388 -- During the analysis of the body of the accept statement, any
9389 -- zero cost exception handler records were collected in the
9390 -- Accept_Handler_Records field of the N_Accept_Alternative node.
9391 -- This is where we move them to where they belong, namely the
9392 -- newly created procedure.
9394 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
9395 Append (Proc_Body, Body_List);
9398 Null_Body := New_Reference_To (Standard_True, Eloc);
9400 -- if accept statement has declarations, insert above, given that
9401 -- we are not creating a body for the accept.
9403 if Present (Declarations (Acc_Stm)) then
9404 Insert_Actions (N, Declarations (Acc_Stm));
9408 Append_To (Accept_List,
9409 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
9411 Num_Accept := Num_Accept + 1;
9414 ----------------------------
9415 -- Make_And_Declare_Label --
9416 ----------------------------
9418 function Make_And_Declare_Label (Num : Int) return Node_Id is
9422 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
9424 Make_Label (Loc, Lab_Id);
9427 Make_Implicit_Label_Declaration (Loc,
9428 Defining_Identifier =>
9429 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
9430 Label_Construct => Lab));
9433 end Make_And_Declare_Label;
9435 ----------------------
9436 -- Make_Select_Call --
9437 ----------------------
9439 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
9440 Params : constant List_Id := New_List;
9444 Make_Attribute_Reference (Loc,
9445 Prefix => New_Reference_To (Qnam, Loc),
9446 Attribute_Name => Name_Unchecked_Access),
9448 Append (Select_Mode, Params);
9449 Append (New_Reference_To (Ann, Loc), Params);
9450 Append (New_Reference_To (Xnam, Loc), Params);
9453 Make_Procedure_Call_Statement (Loc,
9454 Name => New_Reference_To (RTE (RE_Selective_Wait), Loc),
9455 Parameter_Associations => Params);
9456 end Make_Select_Call;
9458 --------------------------------
9459 -- Process_Accept_Alternative --
9460 --------------------------------
9462 procedure Process_Accept_Alternative
9467 Choices : List_Id := No_List;
9468 Alt_Stats : List_Id;
9471 Adjust_Condition (Condition (Alt));
9472 Alt_Stats := No_List;
9474 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
9475 Choices := New_List (
9476 Make_Integer_Literal (Loc, Index));
9478 Alt_Stats := New_List (
9479 Make_Procedure_Call_Statement (Sloc (Proc),
9480 Name => New_Reference_To (
9481 Defining_Unit_Name (Specification (Proc)), Sloc (Proc))));
9484 if Statements (Alt) /= Empty_List then
9486 if No (Alt_Stats) then
9488 -- Accept with no body, followed by trailing statements
9490 Choices := New_List (
9491 Make_Integer_Literal (Loc, Index));
9493 Alt_Stats := New_List;
9496 -- After the call, if any, branch to trailing statements. We
9497 -- create a label for each, as well as the corresponding label
9500 Lab := Make_And_Declare_Label (Index);
9501 Append_To (Alt_Stats,
9502 Make_Goto_Statement (Loc,
9503 Name => New_Copy (Identifier (Lab))));
9505 Append (Lab, Trailing_List);
9506 Append_List (Statements (Alt), Trailing_List);
9507 Append_To (Trailing_List,
9508 Make_Goto_Statement (Loc,
9509 Name => New_Copy (Identifier (End_Lab))));
9512 if Present (Alt_Stats) then
9514 -- Procedure call. and/or trailing statements
9516 Append_To (Alt_List,
9517 Make_Case_Statement_Alternative (Loc,
9518 Discrete_Choices => Choices,
9519 Statements => Alt_Stats));
9521 end Process_Accept_Alternative;
9523 -------------------------------
9524 -- Process_Delay_Alternative --
9525 -------------------------------
9527 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
9530 Delay_Alt : List_Id;
9533 -- Deal with C/Fortran boolean as delay condition
9535 Adjust_Condition (Condition (Alt));
9537 -- Determine the smallest specified delay
9539 -- for each delay alternative generate:
9541 -- if guard-expression then
9542 -- Delay_Val := delay-expression;
9543 -- Guard_Open := True;
9544 -- if Delay_Val < Delay_Min then
9545 -- Delay_Min := Delay_Val;
9546 -- Delay_Index := Index;
9550 -- The enclosing if-statement is omitted if there is no guard
9555 First_Delay := False;
9557 Delay_Alt := New_List (
9558 Make_Assignment_Statement (Loc,
9559 Name => New_Reference_To (Delay_Min, Loc),
9560 Expression => Expression (Delay_Statement (Alt))));
9562 if Delay_Count > 1 then
9563 Append_To (Delay_Alt,
9564 Make_Assignment_Statement (Loc,
9565 Name => New_Reference_To (Delay_Index, Loc),
9566 Expression => Make_Integer_Literal (Loc, Index)));
9570 Delay_Alt := New_List (
9571 Make_Assignment_Statement (Loc,
9572 Name => New_Reference_To (Delay_Val, Loc),
9573 Expression => Expression (Delay_Statement (Alt))));
9575 if Time_Type = Standard_Duration then
9578 Left_Opnd => New_Reference_To (Delay_Val, Loc),
9579 Right_Opnd => New_Reference_To (Delay_Min, Loc));
9582 -- The scope of the time type must define a comparison
9583 -- operator. The scope itself may not be visible, so we
9584 -- construct a node with entity information to insure that
9585 -- semantic analysis can find the proper operator.
9588 Make_Function_Call (Loc,
9589 Name => Make_Selected_Component (Loc,
9590 Prefix => New_Reference_To (Scope (Time_Type), Loc),
9592 Make_Operator_Symbol (Loc,
9593 Chars => Name_Op_Lt,
9594 Strval => No_String)),
9595 Parameter_Associations =>
9597 New_Reference_To (Delay_Val, Loc),
9598 New_Reference_To (Delay_Min, Loc)));
9600 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
9603 Append_To (Delay_Alt,
9604 Make_Implicit_If_Statement (N,
9606 Then_Statements => New_List (
9607 Make_Assignment_Statement (Loc,
9608 Name => New_Reference_To (Delay_Min, Loc),
9609 Expression => New_Reference_To (Delay_Val, Loc)),
9611 Make_Assignment_Statement (Loc,
9612 Name => New_Reference_To (Delay_Index, Loc),
9613 Expression => Make_Integer_Literal (Loc, Index)))));
9617 Append_To (Delay_Alt,
9618 Make_Assignment_Statement (Loc,
9619 Name => New_Reference_To (Guard_Open, Loc),
9620 Expression => New_Reference_To (Standard_True, Loc)));
9623 if Present (Condition (Alt)) then
9624 Delay_Alt := New_List (
9625 Make_Implicit_If_Statement (N,
9626 Condition => Condition (Alt),
9627 Then_Statements => Delay_Alt));
9630 Append_List (Delay_Alt, Delay_List);
9632 -- If the delay alternative has a statement part, add choice to the
9633 -- case statements for delays.
9635 if Present (Statements (Alt)) then
9637 if Delay_Count = 1 then
9638 Append_List (Statements (Alt), Delay_Alt_List);
9641 Choices := New_List (
9642 Make_Integer_Literal (Loc, Index));
9644 Append_To (Delay_Alt_List,
9645 Make_Case_Statement_Alternative (Loc,
9646 Discrete_Choices => Choices,
9647 Statements => Statements (Alt)));
9650 elsif Delay_Count = 1 then
9652 -- If the single delay has no trailing statements, add a branch
9653 -- to the exit label to the selective wait.
9655 Delay_Alt_List := New_List (
9656 Make_Goto_Statement (Loc,
9657 Name => New_Copy (Identifier (End_Lab))));
9660 end Process_Delay_Alternative;
9662 -- Start of processing for Expand_N_Selective_Accept
9665 -- First insert some declarations before the select. The first is:
9669 -- This variable holds the parameters passed to the accept body. This
9670 -- declaration has already been inserted by the time we get here by
9671 -- a call to Expand_Accept_Declarations made from the semantics when
9672 -- processing the first accept statement contained in the select. We
9673 -- can find this entity as Accept_Address (E), where E is any of the
9674 -- entries references by contained accept statements.
9676 -- The first step is to scan the list of Selective_Accept_Statements
9677 -- to find this entity, and also count the number of accepts, and
9678 -- determine if terminated, delay or else is present:
9682 Alt := First (Alts);
9683 while Present (Alt) loop
9685 if Nkind (Alt) = N_Accept_Alternative then
9688 elsif Nkind (Alt) = N_Delay_Alternative then
9689 Delay_Count := Delay_Count + 1;
9691 -- If the delays are relative delays, the delay expressions have
9692 -- type Standard_Duration. Otherwise they must have some time type
9693 -- recognized by GNAT.
9695 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
9696 Time_Type := Standard_Duration;
9698 Time_Type := Etype (Expression (Delay_Statement (Alt)));
9700 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
9701 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
9706 "& is not a time type (RM 9.6(6))",
9707 Expression (Delay_Statement (Alt)), Time_Type);
9708 Time_Type := Standard_Duration;
9709 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
9713 if No (Condition (Alt)) then
9715 -- This guard will always be open
9717 Check_Guard := False;
9720 elsif Nkind (Alt) = N_Terminate_Alternative then
9721 Adjust_Condition (Condition (Alt));
9722 Terminate_Alt := Alt;
9725 Num_Alts := Num_Alts + 1;
9729 Else_Present := Present (Else_Statements (N));
9731 -- At the same time (see procedure Add_Accept) we build the accept list:
9733 -- Qnn : Accept_List (1 .. num-select) := (
9734 -- (null-body, entry-index),
9735 -- (null-body, entry-index),
9737 -- (null_body, entry-index));
9739 -- In the above declaration, null-body is True if the corresponding
9740 -- accept has no body, and false otherwise. The entry is either the
9741 -- entry index expression if there is no guard, or if a guard is
9742 -- present, then a conditional expression of the form:
9744 -- (if guard then entry-index else Null_Task_Entry)
9746 -- If a guard is statically known to be false, the entry can simply
9747 -- be omitted from the accept list.
9750 Make_Object_Declaration (Loc,
9751 Defining_Identifier => Qnam,
9752 Object_Definition =>
9753 New_Reference_To (RTE (RE_Accept_List), Loc),
9754 Aliased_Present => True,
9757 Make_Qualified_Expression (Loc,
9759 New_Reference_To (RTE (RE_Accept_List), Loc),
9761 Make_Aggregate (Loc, Expressions => Accept_List)));
9765 -- Then we declare the variable that holds the index for the accept
9766 -- that will be selected for service:
9768 -- Xnn : Select_Index;
9771 Make_Object_Declaration (Loc,
9772 Defining_Identifier => Xnam,
9773 Object_Definition =>
9774 New_Reference_To (RTE (RE_Select_Index), Loc),
9776 New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9780 -- After this follow procedure declarations for each accept body
9787 -- where the ... are statements from the corresponding procedure body.
9788 -- No parameters are involved, since the parameters are passed via Ann
9789 -- and the parameter references have already been expanded to be direct
9790 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
9791 -- any embedded tasking statements (which would normally be illegal in
9792 -- procedures), have been converted to calls to the tasking runtime so
9793 -- there is no problem in putting them into procedures.
9795 -- The original accept statement has been expanded into a block in
9796 -- the same fashion as for simple accepts (see Build_Accept_Body).
9798 -- Note: we don't really need to build these procedures for the case
9799 -- where no delay statement is present, but it is just as easy to
9800 -- build them unconditionally, and not significantly inefficient,
9801 -- since if they are short they will be inlined anyway.
9803 -- The procedure declarations have been assembled in Body_List
9805 -- If delays are present, we must compute the required delay.
9806 -- We first generate the declarations:
9808 -- Delay_Index : Boolean := 0;
9809 -- Delay_Min : Some_Time_Type.Time;
9810 -- Delay_Val : Some_Time_Type.Time;
9812 -- Delay_Index will be set to the index of the minimum delay, i.e. the
9813 -- active delay that is actually chosen as the basis for the possible
9814 -- delay if an immediate rendez-vous is not possible.
9816 -- In the most common case there is a single delay statement, and this
9817 -- is handled specially.
9819 if Delay_Count > 0 then
9821 -- Generate the required declarations
9824 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
9826 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
9828 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
9831 Make_Object_Declaration (Loc,
9832 Defining_Identifier => Delay_Val,
9833 Object_Definition => New_Reference_To (Time_Type, Loc)));
9836 Make_Object_Declaration (Loc,
9837 Defining_Identifier => Delay_Index,
9838 Object_Definition => New_Reference_To (Standard_Integer, Loc),
9839 Expression => Make_Integer_Literal (Loc, 0)));
9842 Make_Object_Declaration (Loc,
9843 Defining_Identifier => Delay_Min,
9844 Object_Definition => New_Reference_To (Time_Type, Loc),
9846 Unchecked_Convert_To (Time_Type,
9847 Make_Attribute_Reference (Loc,
9849 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
9850 Attribute_Name => Name_Last))));
9852 -- Create Duration and Delay_Mode objects used for passing a delay
9855 D := Make_Temporary (Loc, 'D');
9856 M := Make_Temporary (Loc, 'M');
9862 -- Note that these values are defined in s-osprim.ads and must
9865 -- Relative : constant := 0;
9866 -- Absolute_Calendar : constant := 1;
9867 -- Absolute_RT : constant := 2;
9869 if Time_Type = Standard_Duration then
9870 Discr := Make_Integer_Literal (Loc, 0);
9872 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
9873 Discr := Make_Integer_Literal (Loc, 1);
9877 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
9878 Discr := Make_Integer_Literal (Loc, 2);
9882 Make_Object_Declaration (Loc,
9883 Defining_Identifier => D,
9884 Object_Definition =>
9885 New_Reference_To (Standard_Duration, Loc)));
9888 Make_Object_Declaration (Loc,
9889 Defining_Identifier => M,
9890 Object_Definition =>
9891 New_Reference_To (Standard_Integer, Loc),
9892 Expression => Discr));
9897 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
9900 Make_Object_Declaration (Loc,
9901 Defining_Identifier => Guard_Open,
9902 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
9903 Expression => New_Reference_To (Standard_False, Loc)));
9906 -- Delay_Count is zero, don't need M and D set (suppress warning)
9913 if Present (Terminate_Alt) then
9915 -- If the terminate alternative guard is False, use
9916 -- Simple_Mode; otherwise use Terminate_Mode.
9918 if Present (Condition (Terminate_Alt)) then
9919 Select_Mode := Make_Conditional_Expression (Loc,
9920 New_List (Condition (Terminate_Alt),
9921 New_Reference_To (RTE (RE_Terminate_Mode), Loc),
9922 New_Reference_To (RTE (RE_Simple_Mode), Loc)));
9924 Select_Mode := New_Reference_To (RTE (RE_Terminate_Mode), Loc);
9927 elsif Else_Present or Delay_Count > 0 then
9928 Select_Mode := New_Reference_To (RTE (RE_Else_Mode), Loc);
9931 Select_Mode := New_Reference_To (RTE (RE_Simple_Mode), Loc);
9934 Select_Call := Make_Select_Call (Select_Mode);
9935 Append (Select_Call, Stats);
9937 -- Now generate code to act on the result. There is an entry
9938 -- in this case for each accept statement with a non-null body,
9939 -- followed by a branch to the statements that follow the Accept.
9940 -- In the absence of delay alternatives, we generate:
9943 -- when No_Rendezvous => -- omitted if simple mode
9958 -- Lab0: Else_Statements;
9961 -- Lab1: Trailing_Statements1;
9964 -- Lab2: Trailing_Statements2;
9969 -- Generate label for common exit
9971 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
9973 -- First entry is the default case, when no rendezvous is possible
9975 Choices := New_List (New_Reference_To (RTE (RE_No_Rendezvous), Loc));
9977 if Else_Present then
9979 -- If no rendezvous is possible, the else part is executed
9981 Lab := Make_And_Declare_Label (0);
9982 Alt_Stats := New_List (
9983 Make_Goto_Statement (Loc,
9984 Name => New_Copy (Identifier (Lab))));
9986 Append (Lab, Trailing_List);
9987 Append_List (Else_Statements (N), Trailing_List);
9988 Append_To (Trailing_List,
9989 Make_Goto_Statement (Loc,
9990 Name => New_Copy (Identifier (End_Lab))));
9992 Alt_Stats := New_List (
9993 Make_Goto_Statement (Loc,
9994 Name => New_Copy (Identifier (End_Lab))));
9997 Append_To (Alt_List,
9998 Make_Case_Statement_Alternative (Loc,
9999 Discrete_Choices => Choices,
10000 Statements => Alt_Stats));
10002 -- We make use of the fact that Accept_Index is an integer type, and
10003 -- generate successive literals for entries for each accept. Only those
10004 -- for which there is a body or trailing statements get a case entry.
10006 Alt := First (Select_Alternatives (N));
10007 Proc := First (Body_List);
10008 while Present (Alt) loop
10010 if Nkind (Alt) = N_Accept_Alternative then
10011 Process_Accept_Alternative (Alt, Index, Proc);
10012 Index := Index + 1;
10015 (Handled_Statement_Sequence (Accept_Statement (Alt)))
10020 elsif Nkind (Alt) = N_Delay_Alternative then
10021 Process_Delay_Alternative (Alt, Delay_Num);
10022 Delay_Num := Delay_Num + 1;
10028 -- An others choice is always added to the main case, as well
10029 -- as the delay case (to satisfy the compiler).
10031 Append_To (Alt_List,
10032 Make_Case_Statement_Alternative (Loc,
10033 Discrete_Choices =>
10034 New_List (Make_Others_Choice (Loc)),
10036 New_List (Make_Goto_Statement (Loc,
10037 Name => New_Copy (Identifier (End_Lab))))));
10039 Accept_Case := New_List (
10040 Make_Case_Statement (Loc,
10041 Expression => New_Reference_To (Xnam, Loc),
10042 Alternatives => Alt_List));
10044 Append_List (Trailing_List, Accept_Case);
10045 Append (End_Lab, Accept_Case);
10046 Append_List (Body_List, Decls);
10048 -- Construct case statement for trailing statements of delay
10049 -- alternatives, if there are several of them.
10051 if Delay_Count > 1 then
10052 Append_To (Delay_Alt_List,
10053 Make_Case_Statement_Alternative (Loc,
10054 Discrete_Choices =>
10055 New_List (Make_Others_Choice (Loc)),
10057 New_List (Make_Null_Statement (Loc))));
10059 Delay_Case := New_List (
10060 Make_Case_Statement (Loc,
10061 Expression => New_Reference_To (Delay_Index, Loc),
10062 Alternatives => Delay_Alt_List));
10064 Delay_Case := Delay_Alt_List;
10067 -- If there are no delay alternatives, we append the case statement
10068 -- to the statement list.
10070 if Delay_Count = 0 then
10071 Append_List (Accept_Case, Stats);
10073 -- Delay alternatives present
10076 -- If delay alternatives are present we generate:
10078 -- find minimum delay.
10079 -- DX := minimum delay;
10080 -- M := <delay mode>;
10081 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
10084 -- if X = No_Rendezvous then
10085 -- case statement for delay statements.
10087 -- case statement for accept alternatives.
10098 -- The type of the delay expression is known to be legal
10100 if Time_Type = Standard_Duration then
10101 Conv := New_Reference_To (Delay_Min, Loc);
10103 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10104 Conv := Make_Function_Call (Loc,
10105 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
10106 New_List (New_Reference_To (Delay_Min, Loc)));
10110 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10112 Conv := Make_Function_Call (Loc,
10113 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
10114 New_List (New_Reference_To (Delay_Min, Loc)));
10117 Stmt := Make_Assignment_Statement (Loc,
10118 Name => New_Reference_To (D, Loc),
10119 Expression => Conv);
10121 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
10123 Parms := Parameter_Associations (Select_Call);
10124 Parm := First (Parms);
10126 while Present (Parm)
10127 and then Parm /= Select_Mode
10132 pragma Assert (Present (Parm));
10133 Rewrite (Parm, New_Reference_To (RTE (RE_Delay_Mode), Loc));
10136 -- Prepare two new parameters of Duration and Delay_Mode type
10137 -- which represent the value and the mode of the minimum delay.
10140 Insert_After (Parm, New_Reference_To (M, Loc));
10141 Insert_After (Parm, New_Reference_To (D, Loc));
10143 -- Create a call to RTS
10145 Rewrite (Select_Call,
10146 Make_Procedure_Call_Statement (Loc,
10147 Name => New_Reference_To (RTE (RE_Timed_Selective_Wait), Loc),
10148 Parameter_Associations => Parms));
10150 -- This new call should follow the calculation of the minimum
10153 Insert_List_Before (Select_Call, Delay_List);
10155 if Check_Guard then
10157 Make_Implicit_If_Statement (N,
10158 Condition => New_Reference_To (Guard_Open, Loc),
10160 New_List (New_Copy_Tree (Stmt),
10161 New_Copy_Tree (Select_Call)),
10162 Else_Statements => Accept_Or_Raise);
10163 Rewrite (Select_Call, Stmt);
10165 Insert_Before (Select_Call, Stmt);
10169 Make_Implicit_If_Statement (N,
10170 Condition => Make_Op_Eq (Loc,
10171 Left_Opnd => New_Reference_To (Xnam, Loc),
10173 New_Reference_To (RTE (RE_No_Rendezvous), Loc)),
10175 Then_Statements => Delay_Case,
10176 Else_Statements => Accept_Case);
10178 Append (Cases, Stats);
10182 -- Replace accept statement with appropriate block
10185 Make_Block_Statement (Loc,
10186 Declarations => Decls,
10187 Handled_Statement_Sequence =>
10188 Make_Handled_Sequence_Of_Statements (Loc,
10189 Statements => Stats));
10191 Rewrite (N, Block);
10194 -- Note: have to worry more about abort deferral in above code ???
10196 -- Final step is to unstack the Accept_Address entries for all accept
10197 -- statements appearing in accept alternatives in the select statement
10199 Alt := First (Alts);
10200 while Present (Alt) loop
10201 if Nkind (Alt) = N_Accept_Alternative then
10202 Remove_Last_Elmt (Accept_Address
10203 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
10208 end Expand_N_Selective_Accept;
10210 --------------------------------------
10211 -- Expand_N_Single_Task_Declaration --
10212 --------------------------------------
10214 -- Single task declarations should never be present after semantic
10215 -- analysis, since we expect them to be replaced by a declaration of an
10216 -- anonymous task type, followed by a declaration of the task object. We
10217 -- include this routine to make sure that is happening!
10219 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
10221 raise Program_Error;
10222 end Expand_N_Single_Task_Declaration;
10224 ------------------------
10225 -- Expand_N_Task_Body --
10226 ------------------------
10228 -- Given a task body
10230 -- task body tname is
10236 -- This expansion routine converts it into a procedure and sets the
10237 -- elaboration flag for the procedure to true, to represent the fact
10238 -- that the task body is now elaborated:
10240 -- procedure tnameB (_Task : access tnameV) is
10241 -- discriminal : dtype renames _Task.discriminant;
10243 -- procedure _clean is
10245 -- Abort_Defer.all;
10247 -- Abort_Undefer.all;
10252 -- Abort_Undefer.all;
10254 -- System.Task_Stages.Complete_Activation;
10262 -- In addition, if the task body is an activator, then a call to activate
10263 -- tasks is added at the start of the statements, before the call to
10264 -- Complete_Activation, and if in addition the task is a master then it
10265 -- must be established as a master. These calls are inserted and analyzed
10266 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
10269 -- There is one discriminal declaration line generated for each
10270 -- discriminant that is present to provide an easy reference point for
10271 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
10273 -- Note on relationship to GNARLI definition. In the GNARLI definition,
10274 -- task body procedures have a profile (Arg : System.Address). That is
10275 -- needed because GNARLI has to use the same access-to-subprogram type
10276 -- for all task types. We depend here on knowing that in GNAT, passing
10277 -- an address argument by value is identical to passing a record value
10278 -- by access (in either case a single pointer is passed), so even though
10279 -- this procedure has the wrong profile. In fact it's all OK, since the
10280 -- callings sequence is identical.
10282 procedure Expand_N_Task_Body (N : Node_Id) is
10283 Loc : constant Source_Ptr := Sloc (N);
10284 Ttyp : constant Entity_Id := Corresponding_Spec (N);
10288 Insert_Nod : Node_Id;
10289 -- Used to determine the proper location of wrapper body insertions
10292 -- Add renaming declarations for discriminals and a declaration for the
10293 -- entry family index (if applicable).
10295 Install_Private_Data_Declarations
10296 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
10298 -- Add a call to Abort_Undefer at the very beginning of the task
10299 -- body since this body is called with abort still deferred.
10301 if Abort_Allowed then
10302 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10304 (First (Statements (Handled_Statement_Sequence (N))), Call);
10308 -- The statement part has already been protected with an at_end and
10309 -- cleanup actions. The call to Complete_Activation must be placed
10310 -- at the head of the sequence of statements of that block. The
10311 -- declarations have been merged in this sequence of statements but
10312 -- the first real statement is accessible from the First_Real_Statement
10313 -- field (which was set for exactly this purpose).
10315 if Restricted_Profile then
10316 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
10318 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
10322 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
10326 Make_Subprogram_Body (Loc,
10327 Specification => Build_Task_Proc_Specification (Ttyp),
10328 Declarations => Declarations (N),
10329 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
10331 -- If the task contains generic instantiations, cleanup actions are
10332 -- delayed until after instantiation. Transfer the activation chain to
10333 -- the subprogram, to insure that the activation call is properly
10334 -- generated. It the task body contains inner tasks, indicate that the
10335 -- subprogram is a task master.
10337 if Delay_Cleanups (Ttyp) then
10338 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
10339 Set_Is_Task_Master (New_N, Is_Task_Master (N));
10342 Rewrite (N, New_N);
10345 -- Set elaboration flag immediately after task body. If the body is a
10346 -- subunit, the flag is set in the declarative part containing the stub.
10348 if Nkind (Parent (N)) /= N_Subunit then
10350 Make_Assignment_Statement (Loc,
10352 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
10353 Expression => New_Reference_To (Standard_True, Loc)));
10356 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
10357 -- the task body. At this point all wrapper specs have been created,
10358 -- frozen and included in the dispatch table for the task type.
10360 if Ada_Version >= Ada_2005 then
10361 if Nkind (Parent (N)) = N_Subunit then
10362 Insert_Nod := Corresponding_Stub (Parent (N));
10367 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
10369 end Expand_N_Task_Body;
10371 ------------------------------------
10372 -- Expand_N_Task_Type_Declaration --
10373 ------------------------------------
10375 -- We have several things to do. First we must create a Boolean flag used
10376 -- to mark if the body is elaborated yet. This variable gets set to True
10377 -- when the body of the task is elaborated (we can't rely on the normal
10378 -- ABE mechanism for the task body, since we need to pass an access to
10379 -- this elaboration boolean to the runtime routines).
10381 -- taskE : aliased Boolean := False;
10383 -- Next a variable is declared to hold the task stack size (either the
10384 -- default : Unspecified_Size, or a value that is set by a pragma
10385 -- Storage_Size). If the value of the pragma Storage_Size is static, then
10386 -- the variable is initialized with this value:
10388 -- taskZ : Size_Type := Unspecified_Size;
10390 -- taskZ : Size_Type := Size_Type (size_expression);
10392 -- Note: No variable is needed to hold the task relative deadline since
10393 -- its value would never be static because the parameter is of a private
10394 -- type (Ada.Real_Time.Time_Span).
10396 -- Next we create a corresponding record type declaration used to represent
10397 -- values of this task. The general form of this type declaration is
10399 -- type taskV (discriminants) is record
10400 -- _Task_Id : Task_Id;
10401 -- entry_family : array (bounds) of Void;
10402 -- _Priority : Integer := priority_expression;
10403 -- _Size : Size_Type := Size_Type (size_expression);
10404 -- _Task_Info : Task_Info_Type := task_info_expression;
10405 -- _CPU : Integer := cpu_range_expression;
10408 -- The discriminants are present only if the corresponding task type has
10409 -- discriminants, and they exactly mirror the task type discriminants.
10411 -- The Id field is always present. It contains the Task_Id value, as set by
10412 -- the call to Create_Task. Note that although the task is limited, the
10413 -- task value record type is not limited, so there is no problem in passing
10414 -- this field as an out parameter to Create_Task.
10416 -- One entry_family component is present for each entry family in the task
10417 -- definition. The bounds correspond to the bounds of the entry family
10418 -- (which may depend on discriminants). The element type is void, since we
10419 -- only need the bounds information for determining the entry index. Note
10420 -- that the use of an anonymous array would normally be illegal in this
10421 -- context, but this is a parser check, and the semantics is quite prepared
10422 -- to handle such a case.
10424 -- The _Size field is present only if a Storage_Size pragma appears in the
10425 -- task definition. The expression captures the argument that was present
10426 -- in the pragma, and is used to override the task stack size otherwise
10427 -- associated with the task type.
10429 -- The _Priority field is present only if a Priority or Interrupt_Priority
10430 -- pragma appears in the task definition. The expression captures the
10431 -- argument that was present in the pragma, and is used to provide the Size
10432 -- parameter to the call to Create_Task.
10434 -- The _Task_Info field is present only if a Task_Info pragma appears in
10435 -- the task definition. The expression captures the argument that was
10436 -- present in the pragma, and is used to provide the Task_Image parameter
10437 -- to the call to Create_Task.
10439 -- The _CPU field is present only if a CPU pragma appears in the task
10440 -- definition. The expression captures the argument that was present in
10441 -- the pragma, and is used to provide the CPU parameter to the call to
10444 -- The _Relative_Deadline field is present only if a Relative_Deadline
10445 -- pragma appears in the task definition. The expression captures the
10446 -- argument that was present in the pragma, and is used to provide the
10447 -- Relative_Deadline parameter to the call to Create_Task.
10449 -- When a task is declared, an instance of the task value record is
10450 -- created. The elaboration of this declaration creates the correct bounds
10451 -- for the entry families, and also evaluates the size, priority, and
10452 -- task_Info expressions if needed. The initialization routine for the task
10453 -- type itself then calls Create_Task with appropriate parameters to
10454 -- initialize the value of the Task_Id field.
10456 -- Note: the address of this record is passed as the "Discriminants"
10457 -- parameter for Create_Task. Since Create_Task merely passes this onto the
10458 -- body procedure, it does not matter that it does not quite match the
10459 -- GNARLI model of what is being passed (the record contains more than just
10460 -- the discriminants, but the discriminants can be found from the record
10463 -- The Entity_Id for this created record type is placed in the
10464 -- Corresponding_Record_Type field of the associated task type entity.
10466 -- Next we create a procedure specification for the task body procedure:
10468 -- procedure taskB (_Task : access taskV);
10470 -- Note that this must come after the record type declaration, since
10471 -- the spec refers to this type. It turns out that the initialization
10472 -- procedure for the value type references the task body spec, but that's
10473 -- fine, since it won't be generated till the freeze point for the type,
10474 -- which is certainly after the task body spec declaration.
10476 -- Finally, we set the task index value field of the entry attribute in
10477 -- the case of a simple entry.
10479 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
10480 Loc : constant Source_Ptr := Sloc (N);
10481 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
10482 Tasknm : constant Name_Id := Chars (Tasktyp);
10483 Taskdef : constant Node_Id := Task_Definition (N);
10485 Proc_Spec : Node_Id;
10486 Rec_Decl : Node_Id;
10487 Rec_Ent : Entity_Id;
10489 Elab_Decl : Node_Id;
10490 Size_Decl : Node_Id;
10491 Body_Decl : Node_Id;
10492 Task_Size : Node_Id;
10493 Ent_Stack : Entity_Id;
10494 Decl_Stack : Node_Id;
10497 -- If already expanded, nothing to do
10499 if Present (Corresponding_Record_Type (Tasktyp)) then
10503 -- Here we will do the expansion
10505 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
10507 Rec_Ent := Defining_Identifier (Rec_Decl);
10508 Cdecls := Component_Items (Component_List
10509 (Type_Definition (Rec_Decl)));
10511 Qualify_Entity_Names (N);
10513 -- First create the elaboration variable
10516 Make_Object_Declaration (Loc,
10517 Defining_Identifier =>
10518 Make_Defining_Identifier (Sloc (Tasktyp),
10519 Chars => New_External_Name (Tasknm, 'E')),
10520 Aliased_Present => True,
10521 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
10522 Expression => New_Reference_To (Standard_False, Loc));
10523 Insert_After (N, Elab_Decl);
10525 -- Next create the declaration of the size variable (tasknmZ)
10527 Set_Storage_Size_Variable (Tasktyp,
10528 Make_Defining_Identifier (Sloc (Tasktyp),
10529 Chars => New_External_Name (Tasknm, 'Z')));
10531 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) and then
10532 Is_Static_Expression (Expression (First (
10533 Pragma_Argument_Associations (Find_Task_Or_Protected_Pragma (
10534 Taskdef, Name_Storage_Size)))))
10537 Make_Object_Declaration (Loc,
10538 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10539 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10541 Convert_To (RTE (RE_Size_Type),
10543 Expression (First (
10544 Pragma_Argument_Associations (
10545 Find_Task_Or_Protected_Pragma
10546 (Taskdef, Name_Storage_Size)))))));
10550 Make_Object_Declaration (Loc,
10551 Defining_Identifier => Storage_Size_Variable (Tasktyp),
10552 Object_Definition => New_Reference_To (RTE (RE_Size_Type), Loc),
10553 Expression => New_Reference_To (RTE (RE_Unspecified_Size), Loc));
10556 Insert_After (Elab_Decl, Size_Decl);
10558 -- Next build the rest of the corresponding record declaration. This is
10559 -- done last, since the corresponding record initialization procedure
10560 -- will reference the previously created entities.
10562 -- Fill in the component declarations -- first the _Task_Id field
10565 Make_Component_Declaration (Loc,
10566 Defining_Identifier =>
10567 Make_Defining_Identifier (Loc, Name_uTask_Id),
10568 Component_Definition =>
10569 Make_Component_Definition (Loc,
10570 Aliased_Present => False,
10571 Subtype_Indication => New_Reference_To (RTE (RO_ST_Task_Id),
10574 -- Declare static ATCB (that is, created by the expander) if we are
10575 -- using the Restricted run time.
10577 if Restricted_Profile then
10579 Make_Component_Declaration (Loc,
10580 Defining_Identifier =>
10581 Make_Defining_Identifier (Loc, Name_uATCB),
10583 Component_Definition =>
10584 Make_Component_Definition (Loc,
10585 Aliased_Present => True,
10586 Subtype_Indication => Make_Subtype_Indication (Loc,
10587 Subtype_Mark => New_Occurrence_Of
10588 (RTE (RE_Ada_Task_Control_Block), Loc),
10591 Make_Index_Or_Discriminant_Constraint (Loc,
10593 New_List (Make_Integer_Literal (Loc, 0)))))));
10597 -- Declare static stack (that is, created by the expander) if we are
10598 -- using the Restricted run time on a bare board configuration.
10600 if Restricted_Profile
10601 and then Preallocated_Stacks_On_Target
10603 -- First we need to extract the appropriate stack size
10605 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
10607 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
10609 Expr_N : constant Node_Id :=
10610 Expression (First (
10611 Pragma_Argument_Associations (
10612 Find_Task_Or_Protected_Pragma
10613 (Taskdef, Name_Storage_Size))));
10614 Etyp : constant Entity_Id := Etype (Expr_N);
10615 P : constant Node_Id := Parent (Expr_N);
10618 -- The stack is defined inside the corresponding record.
10619 -- Therefore if the size of the stack is set by means of
10620 -- a discriminant, we must reference the discriminant of the
10621 -- corresponding record type.
10623 if Nkind (Expr_N) in N_Has_Entity
10624 and then Present (Discriminal_Link (Entity (Expr_N)))
10628 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
10630 Set_Parent (Task_Size, P);
10631 Set_Etype (Task_Size, Etyp);
10632 Set_Analyzed (Task_Size);
10635 Task_Size := Relocate_Node (Expr_N);
10641 New_Reference_To (RTE (RE_Default_Stack_Size), Loc);
10644 Decl_Stack := Make_Component_Declaration (Loc,
10645 Defining_Identifier => Ent_Stack,
10647 Component_Definition =>
10648 Make_Component_Definition (Loc,
10649 Aliased_Present => True,
10650 Subtype_Indication => Make_Subtype_Indication (Loc,
10652 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
10655 Make_Index_Or_Discriminant_Constraint (Loc,
10656 Constraints => New_List (Make_Range (Loc,
10657 Low_Bound => Make_Integer_Literal (Loc, 1),
10658 High_Bound => Convert_To (RTE (RE_Storage_Offset),
10661 Append_To (Cdecls, Decl_Stack);
10663 -- The appropriate alignment for the stack is ensured by the run-time
10664 -- code in charge of task creation.
10668 -- Add components for entry families
10670 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
10672 -- Add the _Priority component if a Priority pragma is present
10674 if Present (Taskdef) and then Has_Pragma_Priority (Taskdef) then
10676 Prag : constant Node_Id :=
10677 Find_Task_Or_Protected_Pragma (Taskdef, Name_Priority);
10681 Expr := First (Pragma_Argument_Associations (Prag));
10683 if Nkind (Expr) = N_Pragma_Argument_Association then
10684 Expr := Expression (Expr);
10687 Expr := New_Copy_Tree (Expr);
10689 -- Add conversion to proper type to do range check if required
10690 -- Note that for runtime units, we allow out of range interrupt
10691 -- priority values to be used in a priority pragma. This is for
10692 -- the benefit of some versions of System.Interrupts which use
10693 -- a special server task with maximum interrupt priority.
10695 if Pragma_Name (Prag) = Name_Priority
10696 and then not GNAT_Mode
10698 Rewrite (Expr, Convert_To (RTE (RE_Priority), Expr));
10700 Rewrite (Expr, Convert_To (RTE (RE_Any_Priority), Expr));
10704 Make_Component_Declaration (Loc,
10705 Defining_Identifier =>
10706 Make_Defining_Identifier (Loc, Name_uPriority),
10707 Component_Definition =>
10708 Make_Component_Definition (Loc,
10709 Aliased_Present => False,
10710 Subtype_Indication => New_Reference_To (Standard_Integer,
10712 Expression => Expr));
10716 -- Add the _Task_Size component if a Storage_Size pragma is present
10718 if Present (Taskdef)
10719 and then Has_Storage_Size_Pragma (Taskdef)
10722 Make_Component_Declaration (Loc,
10723 Defining_Identifier =>
10724 Make_Defining_Identifier (Loc, Name_uSize),
10726 Component_Definition =>
10727 Make_Component_Definition (Loc,
10728 Aliased_Present => False,
10729 Subtype_Indication => New_Reference_To (RTE (RE_Size_Type),
10733 Convert_To (RTE (RE_Size_Type),
10735 Expression (First (
10736 Pragma_Argument_Associations (
10737 Find_Task_Or_Protected_Pragma
10738 (Taskdef, Name_Storage_Size))))))));
10741 -- Add the _Task_Info component if a Task_Info pragma is present
10743 if Present (Taskdef) and then Has_Task_Info_Pragma (Taskdef) then
10745 Make_Component_Declaration (Loc,
10746 Defining_Identifier =>
10747 Make_Defining_Identifier (Loc, Name_uTask_Info),
10749 Component_Definition =>
10750 Make_Component_Definition (Loc,
10751 Aliased_Present => False,
10752 Subtype_Indication =>
10753 New_Reference_To (RTE (RE_Task_Info_Type), Loc)),
10755 Expression => New_Copy (
10756 Expression (First (
10757 Pragma_Argument_Associations (
10758 Find_Task_Or_Protected_Pragma
10759 (Taskdef, Name_Task_Info)))))));
10762 -- Add the _CPU component if a CPU pragma is present
10764 if Present (Taskdef) and then Has_Pragma_CPU (Taskdef) then
10766 Make_Component_Declaration (Loc,
10767 Defining_Identifier =>
10768 Make_Defining_Identifier (Loc, Name_uCPU),
10770 Component_Definition =>
10771 Make_Component_Definition (Loc,
10772 Aliased_Present => False,
10773 Subtype_Indication =>
10774 New_Reference_To (RTE (RE_CPU_Range), Loc)),
10776 Expression => New_Copy (
10777 Expression (First (
10778 Pragma_Argument_Associations (
10779 Find_Task_Or_Protected_Pragma
10780 (Taskdef, Name_CPU)))))));
10783 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
10784 -- present. If we are using a restricted run time this component will
10785 -- not be added (deadlines are not allowed by the Ravenscar profile).
10787 if not Restricted_Profile
10788 and then Present (Taskdef)
10789 and then Has_Relative_Deadline_Pragma (Taskdef)
10792 Make_Component_Declaration (Loc,
10793 Defining_Identifier =>
10794 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
10796 Component_Definition =>
10797 Make_Component_Definition (Loc,
10798 Aliased_Present => False,
10799 Subtype_Indication =>
10800 New_Reference_To (RTE (RE_Time_Span), Loc)),
10803 Convert_To (RTE (RE_Time_Span),
10805 Expression (First (
10806 Pragma_Argument_Associations (
10807 Find_Task_Or_Protected_Pragma
10808 (Taskdef, Name_Relative_Deadline))))))));
10811 Insert_After (Size_Decl, Rec_Decl);
10813 -- Analyze the record declaration immediately after construction,
10814 -- because the initialization procedure is needed for single task
10815 -- declarations before the next entity is analyzed.
10817 Analyze (Rec_Decl);
10819 -- Create the declaration of the task body procedure
10821 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
10823 Make_Subprogram_Declaration (Loc,
10824 Specification => Proc_Spec);
10826 Insert_After (Rec_Decl, Body_Decl);
10828 -- The subprogram does not comes from source, so we have to indicate the
10829 -- need for debugging information explicitly.
10831 if Comes_From_Source (Original_Node (N)) then
10832 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
10835 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
10836 -- the corresponding record has been frozen.
10838 if Ada_Version >= Ada_2005 then
10839 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
10842 -- Ada 2005 (AI-345): We must defer freezing to allow further
10843 -- declaration of primitive subprograms covering task interfaces
10845 if Ada_Version <= Ada_95 then
10847 -- Now we can freeze the corresponding record. This needs manually
10848 -- freezing, since it is really part of the task type, and the task
10849 -- type is frozen at this stage. We of course need the initialization
10850 -- procedure for this corresponding record type and we won't get it
10851 -- in time if we don't freeze now.
10854 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
10856 if Is_Non_Empty_List (L) then
10857 Insert_List_After (Body_Decl, L);
10862 -- Complete the expansion of access types to the current task type, if
10863 -- any were declared.
10865 Expand_Previous_Access_Type (Tasktyp);
10867 -- Create wrappers for entries that have pre/postconditions
10873 Ent := First_Entity (Tasktyp);
10874 while Present (Ent) loop
10875 if Ekind_In (Ent, E_Entry, E_Entry_Family)
10876 and then Present (Spec_PPC_List (Ent))
10878 Build_PPC_Wrapper (Ent, N);
10884 end Expand_N_Task_Type_Declaration;
10886 -------------------------------
10887 -- Expand_N_Timed_Entry_Call --
10888 -------------------------------
10890 -- A timed entry call in normal case is not implemented using ATC mechanism
10891 -- anymore for efficiency reason.
10901 -- is expanded as follow:
10903 -- 1) When T.E is a task entry_call;
10907 -- X : Task_Entry_Index := <entry index>;
10908 -- DX : Duration := To_Duration (D);
10909 -- M : Delay_Mode := <discriminant>;
10910 -- P : parms := (parm, parm, parm);
10913 -- Timed_Protected_Entry_Call
10914 -- (<acceptor-task>, X, P'Address, DX, M, B);
10922 -- 2) When T.E is a protected entry_call;
10926 -- X : Protected_Entry_Index := <entry index>;
10927 -- DX : Duration := To_Duration (D);
10928 -- M : Delay_Mode := <discriminant>;
10929 -- P : parms := (parm, parm, parm);
10932 -- Timed_Protected_Entry_Call
10933 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
10941 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call;
10944 -- B : Boolean := False;
10945 -- C : Ada.Tags.Prim_Op_Kind;
10946 -- DX : Duration := To_Duration (D)
10947 -- K : Ada.Tags.Tagged_Kind :=
10948 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
10949 -- M : Integer :=...;
10950 -- P : Parameters := (Param1 .. ParamN);
10954 -- if K = Ada.Tags.TK_Limited_Tagged then
10955 -- <dispatching-call>;
10956 -- <triggering-statements>
10960 -- Ada.Tags.Get_Offset_Index
10961 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
10963 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
10965 -- if C = POK_Protected_Entry
10966 -- or else C = POK_Task_Entry
10968 -- Param1 := P.Param1;
10970 -- ParamN := P.ParamN;
10974 -- if C = POK_Procedure
10975 -- or else C = POK_Protected_Procedure
10976 -- or else C = POK_Task_Procedure
10978 -- <dispatching-call>;
10981 -- <triggering-statements>
10983 -- <timed-statements>
10988 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
10989 Loc : constant Source_Ptr := Sloc (N);
10991 E_Call : Node_Id :=
10992 Entry_Call_Statement (Entry_Call_Alternative (N));
10993 E_Stats : constant List_Id :=
10994 Statements (Entry_Call_Alternative (N));
10995 D_Stat : Node_Id :=
10996 Delay_Statement (Delay_Alternative (N));
10997 D_Stats : constant List_Id :=
10998 Statements (Delay_Alternative (N));
11001 Blk_Typ : Entity_Id;
11003 Call_Ent : Entity_Id;
11004 Conc_Typ_Stmts : List_Id;
11008 D_Type : Entity_Id;
11014 Is_Disp_Select : Boolean;
11015 Lim_Typ_Stmts : List_Id;
11024 B : Entity_Id; -- Call status flag
11025 C : Entity_Id; -- Call kind
11026 D : Entity_Id; -- Delay
11027 K : Entity_Id; -- Tagged kind
11028 M : Entity_Id; -- Delay mode
11029 P : Entity_Id; -- Parameter block
11030 S : Entity_Id; -- Primitive operation slot
11033 -- Under the Ravenscar profile, timed entry calls are excluded. An error
11034 -- was already reported on spec, so do not attempt to expand the call.
11036 if Restriction_Active (No_Select_Statements) then
11040 -- The arguments in the call may require dynamic allocation, and the
11041 -- call statement may have been transformed into a block. The block
11042 -- may contain additional declarations for internal entities, and the
11043 -- original call is found by sequential search.
11045 if Nkind (E_Call) = N_Block_Statement then
11046 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
11047 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
11048 N_Entry_Call_Statement)
11055 Ada_Version >= Ada_2005
11056 and then Nkind (E_Call) = N_Procedure_Call_Statement;
11058 if Is_Disp_Select then
11059 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
11065 -- B : Boolean := False;
11067 B := Build_B (Loc, Decls);
11070 -- C : Ada.Tags.Prim_Op_Kind;
11072 C := Build_C (Loc, Decls);
11074 -- Because the analysis of all statements was disabled, manually
11075 -- analyze the delay statement.
11078 D_Stat := Original_Node (D_Stat);
11081 -- Build an entry call using Simple_Entry_Call
11083 Extract_Entry (E_Call, Concval, Ename, Index);
11084 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
11086 Decls := Declarations (E_Call);
11087 Stmts := Statements (Handled_Statement_Sequence (E_Call));
11096 B := Make_Defining_Identifier (Loc, Name_uB);
11099 Make_Object_Declaration (Loc,
11100 Defining_Identifier =>
11102 Object_Definition =>
11103 New_Reference_To (Standard_Boolean, Loc)));
11106 -- Duration and mode processing
11108 D_Type := Base_Type (Etype (Expression (D_Stat)));
11110 -- Use the type of the delay expression (Calendar or Real_Time) to
11111 -- generate the appropriate conversion.
11113 if Nkind (D_Stat) = N_Delay_Relative_Statement then
11114 D_Disc := Make_Integer_Literal (Loc, 0);
11115 D_Conv := Relocate_Node (Expression (D_Stat));
11117 elsif Is_RTE (D_Type, RO_CA_Time) then
11118 D_Disc := Make_Integer_Literal (Loc, 1);
11119 D_Conv := Make_Function_Call (Loc,
11120 New_Reference_To (RTE (RO_CA_To_Duration), Loc),
11121 New_List (New_Copy (Expression (D_Stat))));
11123 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
11124 D_Disc := Make_Integer_Literal (Loc, 2);
11125 D_Conv := Make_Function_Call (Loc,
11126 New_Reference_To (RTE (RO_RT_To_Duration), Loc),
11127 New_List (New_Copy (Expression (D_Stat))));
11130 D := Make_Temporary (Loc, 'D');
11136 Make_Object_Declaration (Loc,
11137 Defining_Identifier =>
11139 Object_Definition =>
11140 New_Reference_To (Standard_Duration, Loc)));
11142 M := Make_Temporary (Loc, 'M');
11145 -- M : Integer := (0 | 1 | 2);
11148 Make_Object_Declaration (Loc,
11149 Defining_Identifier =>
11151 Object_Definition =>
11152 New_Reference_To (Standard_Integer, Loc),
11156 -- Do the assignment at this stage only because the evaluation of the
11157 -- expression must not occur before (see ACVC C97302A).
11160 Make_Assignment_Statement (Loc,
11162 New_Reference_To (D, Loc),
11166 -- Parameter block processing
11168 -- Manually create the parameter block for dispatching calls. In the
11169 -- case of entries, the block has already been created during the call
11170 -- to Build_Simple_Entry_Call.
11172 if Is_Disp_Select then
11174 -- Tagged kind processing, generate:
11175 -- K : Ada.Tags.Tagged_Kind :=
11176 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
11178 K := Build_K (Loc, Decls, Obj);
11180 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
11181 P := Parameter_Block_Pack
11182 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
11184 -- Dispatch table slot processing, generate:
11187 S := Build_S (Loc, Decls);
11190 -- S := Ada.Tags.Get_Offset_Index
11191 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
11194 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
11197 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
11199 -- where Obj is the controlling formal parameter, S is the dispatch
11200 -- table slot number of the dispatching operation, P is the wrapped
11201 -- parameter block, D is the duration, M is the duration mode, C is
11202 -- the call kind and B is the call status.
11204 Params := New_List;
11206 Append_To (Params, New_Copy_Tree (Obj));
11207 Append_To (Params, New_Reference_To (S, Loc));
11208 Append_To (Params, Make_Attribute_Reference (Loc,
11209 Prefix => New_Reference_To (P, Loc),
11210 Attribute_Name => Name_Address));
11211 Append_To (Params, New_Reference_To (D, Loc));
11212 Append_To (Params, New_Reference_To (M, Loc));
11213 Append_To (Params, New_Reference_To (C, Loc));
11214 Append_To (Params, New_Reference_To (B, Loc));
11216 Append_To (Conc_Typ_Stmts,
11217 Make_Procedure_Call_Statement (Loc,
11220 Find_Prim_Op (Etype (Etype (Obj)),
11221 Name_uDisp_Timed_Select),
11223 Parameter_Associations =>
11227 -- if C = POK_Protected_Entry
11228 -- or else C = POK_Task_Entry
11230 -- Param1 := P.Param1;
11232 -- ParamN := P.ParamN;
11235 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
11237 -- Generate the if statement only when the packed parameters need
11238 -- explicit assignments to their corresponding actuals.
11240 if Present (Unpack) then
11241 Append_To (Conc_Typ_Stmts,
11242 Make_If_Statement (Loc,
11249 New_Reference_To (C, Loc),
11251 New_Reference_To (RTE (
11252 RE_POK_Protected_Entry), Loc)),
11256 New_Reference_To (C, Loc),
11258 New_Reference_To (RTE (RE_POK_Task_Entry), Loc))),
11267 -- if C = POK_Procedure
11268 -- or else C = POK_Protected_Procedure
11269 -- or else C = POK_Task_Procedure
11271 -- <dispatching-call>
11273 -- <triggering-statements>
11275 -- <timed-statements>
11278 N_Stats := New_Copy_List_Tree (E_Stats);
11280 Prepend_To (N_Stats,
11281 Make_If_Statement (Loc,
11288 New_Reference_To (C, Loc),
11290 New_Reference_To (RTE (RE_POK_Procedure), Loc)),
11296 New_Reference_To (C, Loc),
11298 New_Reference_To (RTE (
11299 RE_POK_Protected_Procedure), Loc)),
11303 New_Reference_To (C, Loc),
11305 New_Reference_To (RTE (
11306 RE_POK_Task_Procedure), Loc)))),
11309 New_List (E_Call)));
11311 Append_To (Conc_Typ_Stmts,
11312 Make_If_Statement (Loc,
11313 Condition => New_Reference_To (B, Loc),
11314 Then_Statements => N_Stats,
11315 Else_Statements => D_Stats));
11318 -- <dispatching-call>;
11319 -- <triggering-statements>
11321 Lim_Typ_Stmts := New_Copy_List_Tree (E_Stats);
11322 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (E_Call));
11325 -- if K = Ada.Tags.TK_Limited_Tagged then
11332 Make_If_Statement (Loc,
11336 New_Reference_To (K, Loc),
11338 New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc)),
11347 -- Skip assignments to temporaries created for in-out parameters.
11348 -- This makes unwarranted assumptions about the shape of the expanded
11349 -- tree for the call, and should be cleaned up ???
11351 Stmt := First (Stmts);
11352 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
11356 -- Do the assignment at this stage only because the evaluation
11357 -- of the expression must not occur before (see ACVC C97302A).
11359 Insert_Before (Stmt,
11360 Make_Assignment_Statement (Loc,
11361 Name => New_Reference_To (D, Loc),
11362 Expression => D_Conv));
11365 Params := Parameter_Associations (Call);
11367 -- For a protected type, we build a Timed_Protected_Entry_Call
11369 if Is_Protected_Type (Etype (Concval)) then
11371 -- Create a new call statement
11373 Param := First (Params);
11374 while Present (Param)
11375 and then not Is_RTE (Etype (Param), RE_Call_Modes)
11380 Dummy := Remove_Next (Next (Param));
11382 -- Remove garbage is following the Cancel_Param if present
11384 Dummy := Next (Param);
11386 -- Remove the mode of the Protected_Entry_Call call, then remove
11387 -- the Communication_Block of the Protected_Entry_Call call, and
11388 -- finally add Duration and a Delay_Mode parameter
11390 pragma Assert (Present (Param));
11391 Rewrite (Param, New_Reference_To (D, Loc));
11393 Rewrite (Dummy, New_Reference_To (M, Loc));
11395 -- Add a Boolean flag for successful entry call
11397 Append_To (Params, New_Reference_To (B, Loc));
11399 case Corresponding_Runtime_Package (Etype (Concval)) is
11400 when System_Tasking_Protected_Objects_Entries =>
11402 Make_Procedure_Call_Statement (Loc,
11405 (RTE (RE_Timed_Protected_Entry_Call), Loc),
11406 Parameter_Associations => Params));
11408 when System_Tasking_Protected_Objects_Single_Entry =>
11409 Param := First (Params);
11410 while Present (Param)
11412 Is_RTE (Etype (Param), RE_Protected_Entry_Index)
11420 Make_Procedure_Call_Statement (Loc,
11421 Name => New_Reference_To (
11422 RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
11423 Parameter_Associations => Params));
11426 raise Program_Error;
11429 -- For the task case, build a Timed_Task_Entry_Call
11432 -- Create a new call statement
11434 Append_To (Params, New_Reference_To (D, Loc));
11435 Append_To (Params, New_Reference_To (M, Loc));
11436 Append_To (Params, New_Reference_To (B, Loc));
11439 Make_Procedure_Call_Statement (Loc,
11441 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
11442 Parameter_Associations => Params));
11446 Make_Implicit_If_Statement (N,
11447 Condition => New_Reference_To (B, Loc),
11448 Then_Statements => E_Stats,
11449 Else_Statements => D_Stats));
11453 Make_Block_Statement (Loc,
11454 Declarations => Decls,
11455 Handled_Statement_Sequence =>
11456 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
11459 end Expand_N_Timed_Entry_Call;
11461 ----------------------------------------
11462 -- Expand_Protected_Body_Declarations --
11463 ----------------------------------------
11465 procedure Expand_Protected_Body_Declarations
11467 Spec_Id : Entity_Id)
11470 if No_Run_Time_Mode then
11471 Error_Msg_CRT ("protected body", N);
11474 elsif Expander_Active then
11476 -- Associate discriminals with the first subprogram or entry body to
11479 if Present (First_Protected_Operation (Declarations (N))) then
11480 Set_Discriminals (Parent (Spec_Id));
11483 end Expand_Protected_Body_Declarations;
11485 -------------------------
11486 -- External_Subprogram --
11487 -------------------------
11489 function External_Subprogram (E : Entity_Id) return Entity_Id is
11490 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
11493 -- The internal and external subprograms follow each other on the entity
11494 -- chain. Note that previously private operations had no separate
11495 -- external subprogram. We now create one in all cases, because a
11496 -- private operation may actually appear in an external call, through
11497 -- a 'Access reference used for a callback.
11499 -- If the operation is a function that returns an anonymous access type,
11500 -- the corresponding itype appears before the operation, and must be
11503 -- This mechanism is fragile, there should be a real link between the
11504 -- two versions of the operation, but there is no place to put it ???
11506 if Is_Access_Type (Next_Entity (Subp)) then
11507 return Next_Entity (Next_Entity (Subp));
11509 return Next_Entity (Subp);
11511 end External_Subprogram;
11513 ------------------------------
11514 -- Extract_Dispatching_Call --
11515 ------------------------------
11517 procedure Extract_Dispatching_Call
11519 Call_Ent : out Entity_Id;
11520 Object : out Entity_Id;
11521 Actuals : out List_Id;
11522 Formals : out List_Id)
11524 Call_Nam : Node_Id;
11527 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
11529 if Present (Original_Node (N)) then
11530 Call_Nam := Name (Original_Node (N));
11532 Call_Nam := Name (N);
11535 -- Retrieve the name of the dispatching procedure. It contains the
11536 -- dispatch table slot number.
11539 case Nkind (Call_Nam) is
11540 when N_Identifier =>
11543 when N_Selected_Component =>
11544 Call_Nam := Selector_Name (Call_Nam);
11547 raise Program_Error;
11552 Actuals := Parameter_Associations (N);
11553 Call_Ent := Entity (Call_Nam);
11554 Formals := Parameter_Specifications (Parent (Call_Ent));
11555 Object := First (Actuals);
11557 if Present (Original_Node (Object)) then
11558 Object := Original_Node (Object);
11561 -- If the type of the dispatching object is an access type then return
11562 -- an explicit dereference.
11564 if Is_Access_Type (Etype (Object)) then
11565 Object := Make_Explicit_Dereference (Sloc (N), Object);
11568 end Extract_Dispatching_Call;
11570 -------------------
11571 -- Extract_Entry --
11572 -------------------
11574 procedure Extract_Entry
11576 Concval : out Node_Id;
11577 Ename : out Node_Id;
11578 Index : out Node_Id)
11580 Nam : constant Node_Id := Name (N);
11583 -- For a simple entry, the name is a selected component, with the
11584 -- prefix being the task value, and the selector being the entry.
11586 if Nkind (Nam) = N_Selected_Component then
11587 Concval := Prefix (Nam);
11588 Ename := Selector_Name (Nam);
11591 -- For a member of an entry family, the name is an indexed component
11592 -- where the prefix is a selected component, whose prefix in turn is
11593 -- the task value, and whose selector is the entry family. The single
11594 -- expression in the expressions list of the indexed component is the
11595 -- subscript for the family.
11597 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
11598 Concval := Prefix (Prefix (Nam));
11599 Ename := Selector_Name (Prefix (Nam));
11600 Index := First (Expressions (Nam));
11604 -------------------
11605 -- Family_Offset --
11606 -------------------
11608 function Family_Offset
11613 Cap : Boolean) return Node_Id
11619 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
11620 -- If one of the bounds is a reference to a discriminant, replace with
11621 -- corresponding discriminal of type. Within the body of a task retrieve
11622 -- the renamed discriminant by simple visibility, using its generated
11623 -- name. Within a protected object, find the original discriminant and
11624 -- replace it with the discriminal of the current protected operation.
11626 ------------------------------
11627 -- Convert_Discriminant_Ref --
11628 ------------------------------
11630 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
11631 Loc : constant Source_Ptr := Sloc (Bound);
11636 if Is_Entity_Name (Bound)
11637 and then Ekind (Entity (Bound)) = E_Discriminant
11639 if Is_Task_Type (Ttyp)
11640 and then Has_Completion (Ttyp)
11642 B := Make_Identifier (Loc, Chars (Entity (Bound)));
11643 Find_Direct_Name (B);
11645 elsif Is_Protected_Type (Ttyp) then
11646 D := First_Discriminant (Ttyp);
11647 while Chars (D) /= Chars (Entity (Bound)) loop
11648 Next_Discriminant (D);
11651 B := New_Reference_To (Discriminal (D), Loc);
11654 B := New_Reference_To (Discriminal (Entity (Bound)), Loc);
11657 elsif Nkind (Bound) = N_Attribute_Reference then
11661 B := New_Copy_Tree (Bound);
11665 Make_Attribute_Reference (Loc,
11666 Attribute_Name => Name_Pos,
11667 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
11668 Expressions => New_List (B));
11669 end Convert_Discriminant_Ref;
11671 -- Start of processing for Family_Offset
11674 Real_Hi := Convert_Discriminant_Ref (Hi);
11675 Real_Lo := Convert_Discriminant_Ref (Lo);
11678 if Is_Task_Type (Ttyp) then
11679 Ityp := RTE (RE_Task_Entry_Index);
11681 Ityp := RTE (RE_Protected_Entry_Index);
11685 Make_Attribute_Reference (Loc,
11686 Prefix => New_Reference_To (Ityp, Loc),
11687 Attribute_Name => Name_Min,
11688 Expressions => New_List (
11690 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
11693 Make_Attribute_Reference (Loc,
11694 Prefix => New_Reference_To (Ityp, Loc),
11695 Attribute_Name => Name_Max,
11696 Expressions => New_List (
11698 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
11701 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
11708 function Family_Size
11713 Cap : Boolean) return Node_Id
11718 if Is_Task_Type (Ttyp) then
11719 Ityp := RTE (RE_Task_Entry_Index);
11721 Ityp := RTE (RE_Protected_Entry_Index);
11725 Make_Attribute_Reference (Loc,
11726 Prefix => New_Reference_To (Ityp, Loc),
11727 Attribute_Name => Name_Max,
11728 Expressions => New_List (
11731 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
11733 Make_Integer_Literal (Loc, 1)),
11734 Make_Integer_Literal (Loc, 0)));
11737 -----------------------
11738 -- Find_Master_Scope --
11739 -----------------------
11741 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
11745 -- In Ada2005, the master is the innermost enclosing scope that is not
11746 -- transient. If the enclosing block is the rewriting of a call or the
11747 -- scope is an extended return statement this is valid master. The
11748 -- master in an extended return is only used within the return, and is
11749 -- subsequently overwritten in Move_Activation_Chain, but it must exist
11750 -- now before that overwriting occurs.
11754 if Ada_Version >= Ada_2005 then
11755 while Is_Internal (S) loop
11756 if Nkind (Parent (S)) = N_Block_Statement
11758 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
11762 elsif Ekind (S) = E_Return_Statement then
11772 end Find_Master_Scope;
11774 -----------------------------------
11775 -- Find_Task_Or_Protected_Pragma --
11776 -----------------------------------
11778 function Find_Task_Or_Protected_Pragma
11780 P : Name_Id) return Node_Id
11785 N := First (Visible_Declarations (T));
11786 while Present (N) loop
11787 if Nkind (N) = N_Pragma then
11788 if Pragma_Name (N) = P then
11791 elsif P = Name_Priority
11792 and then Pragma_Name (N) = Name_Interrupt_Priority
11805 N := First (Private_Declarations (T));
11806 while Present (N) loop
11807 if Nkind (N) = N_Pragma then
11808 if Pragma_Name (N) = P then
11811 elsif P = Name_Priority
11812 and then Pragma_Name (N) = Name_Interrupt_Priority
11825 raise Program_Error;
11826 end Find_Task_Or_Protected_Pragma;
11828 -------------------------------
11829 -- First_Protected_Operation --
11830 -------------------------------
11832 function First_Protected_Operation (D : List_Id) return Node_Id is
11833 First_Op : Node_Id;
11836 First_Op := First (D);
11837 while Present (First_Op)
11838 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
11844 end First_Protected_Operation;
11846 ---------------------------------------
11847 -- Install_Private_Data_Declarations --
11848 ---------------------------------------
11850 procedure Install_Private_Data_Declarations
11852 Spec_Id : Entity_Id;
11853 Conc_Typ : Entity_Id;
11854 Body_Nod : Node_Id;
11856 Barrier : Boolean := False;
11857 Family : Boolean := False)
11859 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
11862 Insert_Node : Node_Id := Empty;
11863 Obj_Ent : Entity_Id;
11865 procedure Add (Decl : Node_Id);
11866 -- Add a single declaration after Insert_Node. If this is the first
11867 -- addition, Decl is added to the front of Decls and it becomes the
11870 function Replace_Bound (Bound : Node_Id) return Node_Id;
11871 -- The bounds of an entry index may depend on discriminants, create a
11872 -- reference to the corresponding prival. Otherwise return a duplicate
11873 -- of the original bound.
11879 procedure Add (Decl : Node_Id) is
11881 if No (Insert_Node) then
11882 Prepend_To (Decls, Decl);
11884 Insert_After (Insert_Node, Decl);
11887 Insert_Node := Decl;
11890 --------------------------
11891 -- Replace_Discriminant --
11892 --------------------------
11894 function Replace_Bound (Bound : Node_Id) return Node_Id is
11896 if Nkind (Bound) = N_Identifier
11897 and then Is_Discriminal (Entity (Bound))
11899 return Make_Identifier (Loc, Chars (Entity (Bound)));
11901 return Duplicate_Subexpr (Bound);
11905 -- Start of processing for Install_Private_Data_Declarations
11908 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
11909 -- formal parameter _O, _object or _task depending on the context.
11911 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
11913 -- Special processing of _O for barrier functions, protected entries
11920 (Ekind (Spec_Id) = E_Entry
11921 or else Ekind (Spec_Id) = E_Entry_Family))
11924 Conc_Rec : constant Entity_Id :=
11925 Corresponding_Record_Type (Conc_Typ);
11926 Typ_Id : constant Entity_Id :=
11927 Make_Defining_Identifier (Loc,
11928 New_External_Name (Chars (Conc_Rec), 'P'));
11931 -- type prot_typVP is access prot_typV;
11934 Make_Full_Type_Declaration (Loc,
11935 Defining_Identifier => Typ_Id,
11937 Make_Access_To_Object_Definition (Loc,
11938 Subtype_Indication =>
11939 New_Reference_To (Conc_Rec, Loc)));
11943 -- _object : prot_typVP := prot_typV (_O);
11946 Make_Object_Declaration (Loc,
11947 Defining_Identifier =>
11948 Make_Defining_Identifier (Loc, Name_uObject),
11949 Object_Definition => New_Reference_To (Typ_Id, Loc),
11951 Unchecked_Convert_To (Typ_Id,
11952 New_Reference_To (Obj_Ent, Loc)));
11955 -- Set the reference to the concurrent object
11957 Obj_Ent := Defining_Identifier (Decl);
11961 -- Step 2: Create the Protection object and build its declaration for
11962 -- any protected entry (family) of subprogram.
11964 if Is_Protected then
11966 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
11970 Set_Protection_Object (Spec_Id, Prot_Ent);
11972 -- Determine the proper protection type
11974 if Has_Attach_Handler (Conc_Typ)
11975 and then not Restricted_Profile
11977 Prot_Typ := RE_Static_Interrupt_Protection;
11979 elsif Has_Interrupt_Handler (Conc_Typ) then
11980 Prot_Typ := RE_Dynamic_Interrupt_Protection;
11982 -- The type has explicit entries or generated primitive entry
11985 elsif Has_Entries (Conc_Typ)
11987 (Ada_Version >= Ada_2005
11988 and then Present (Interface_List (Parent (Conc_Typ))))
11990 case Corresponding_Runtime_Package (Conc_Typ) is
11991 when System_Tasking_Protected_Objects_Entries =>
11992 Prot_Typ := RE_Protection_Entries;
11994 when System_Tasking_Protected_Objects_Single_Entry =>
11995 Prot_Typ := RE_Protection_Entry;
11998 raise Program_Error;
12002 Prot_Typ := RE_Protection;
12006 -- conc_typR : protection_typ renames _object._object;
12009 Make_Object_Renaming_Declaration (Loc,
12010 Defining_Identifier => Prot_Ent,
12012 New_Reference_To (RTE (Prot_Typ), Loc),
12014 Make_Selected_Component (Loc,
12015 Prefix => New_Reference_To (Obj_Ent, Loc),
12016 Selector_Name => Make_Identifier (Loc, Name_uObject)));
12021 -- Step 3: Add discriminant renamings (if any)
12023 if Has_Discriminants (Conc_Typ) then
12028 D := First_Discriminant (Conc_Typ);
12029 while Present (D) loop
12031 -- Adjust the source location
12033 Set_Sloc (Discriminal (D), Loc);
12036 -- discr_name : discr_typ renames _object.discr_name;
12038 -- discr_name : discr_typ renames _task.discr_name;
12041 Make_Object_Renaming_Declaration (Loc,
12042 Defining_Identifier => Discriminal (D),
12043 Subtype_Mark => New_Reference_To (Etype (D), Loc),
12045 Make_Selected_Component (Loc,
12046 Prefix => New_Reference_To (Obj_Ent, Loc),
12047 Selector_Name => Make_Identifier (Loc, Chars (D))));
12050 Next_Discriminant (D);
12055 -- Step 4: Add private component renamings (if any)
12057 if Is_Protected then
12058 Def := Protected_Definition (Parent (Conc_Typ));
12060 if Present (Private_Declarations (Def)) then
12063 Comp_Id : Entity_Id;
12064 Decl_Id : Entity_Id;
12067 Comp := First (Private_Declarations (Def));
12068 while Present (Comp) loop
12069 if Nkind (Comp) = N_Component_Declaration then
12070 Comp_Id := Defining_Identifier (Comp);
12072 Make_Defining_Identifier (Loc, Chars (Comp_Id));
12074 -- Minimal decoration
12076 if Ekind (Spec_Id) = E_Function then
12077 Set_Ekind (Decl_Id, E_Constant);
12079 Set_Ekind (Decl_Id, E_Variable);
12082 Set_Prival (Comp_Id, Decl_Id);
12083 Set_Prival_Link (Decl_Id, Comp_Id);
12084 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
12087 -- comp_name : comp_typ renames _object.comp_name;
12090 Make_Object_Renaming_Declaration (Loc,
12091 Defining_Identifier => Decl_Id,
12093 New_Reference_To (Etype (Comp_Id), Loc),
12095 Make_Selected_Component (Loc,
12097 New_Reference_To (Obj_Ent, Loc),
12099 Make_Identifier (Loc, Chars (Comp_Id))));
12109 -- Step 5: Add the declaration of the entry index and the associated
12110 -- type for barrier functions and entry families.
12112 if (Barrier and then Family)
12113 or else Ekind (Spec_Id) = E_Entry_Family
12116 E : constant Entity_Id := Index_Object (Spec_Id);
12117 Index : constant Entity_Id :=
12118 Defining_Identifier (
12119 Entry_Index_Specification (
12120 Entry_Body_Formal_Part (Body_Nod)));
12121 Index_Con : constant Entity_Id :=
12122 Make_Defining_Identifier (Loc, Chars (Index));
12124 Index_Typ : Entity_Id;
12128 -- Minimal decoration
12130 Set_Ekind (Index_Con, E_Constant);
12131 Set_Entry_Index_Constant (Index, Index_Con);
12132 Set_Discriminal_Link (Index_Con, Index);
12134 -- Retrieve the bounds of the entry family
12136 High := Type_High_Bound (Etype (Index));
12137 Low := Type_Low_Bound (Etype (Index));
12139 -- In the simple case the entry family is given by a subtype
12140 -- mark and the index constant has the same type.
12142 if Is_Entity_Name (Original_Node (
12143 Discrete_Subtype_Definition (Parent (Index))))
12145 Index_Typ := Etype (Index);
12147 -- Otherwise a new subtype declaration is required
12150 High := Replace_Bound (High);
12151 Low := Replace_Bound (Low);
12153 Index_Typ := Make_Temporary (Loc, 'J');
12156 -- subtype Jnn is <Etype of Index> range Low .. High;
12159 Make_Subtype_Declaration (Loc,
12160 Defining_Identifier => Index_Typ,
12161 Subtype_Indication =>
12162 Make_Subtype_Indication (Loc,
12164 New_Reference_To (Base_Type (Etype (Index)), Loc),
12166 Make_Range_Constraint (Loc,
12167 Range_Expression =>
12168 Make_Range (Loc, Low, High))));
12172 Set_Etype (Index_Con, Index_Typ);
12174 -- Create the object which designates the index:
12175 -- J : constant Jnn :=
12176 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
12178 -- where Jnn is the subtype created above or the original type of
12179 -- the index, _E is a formal of the protected body subprogram and
12180 -- <index expr> is the index of the first family member.
12183 Make_Object_Declaration (Loc,
12184 Defining_Identifier => Index_Con,
12185 Constant_Present => True,
12186 Object_Definition =>
12187 New_Reference_To (Index_Typ, Loc),
12190 Make_Attribute_Reference (Loc,
12192 New_Reference_To (Index_Typ, Loc),
12193 Attribute_Name => Name_Val,
12195 Expressions => New_List (
12199 Make_Op_Subtract (Loc,
12201 New_Reference_To (E, Loc),
12203 Entry_Index_Expression (Loc,
12204 Defining_Identifier (Body_Nod),
12208 Make_Attribute_Reference (Loc,
12210 New_Reference_To (Index_Typ, Loc),
12211 Attribute_Name => Name_Pos,
12212 Expressions => New_List (
12213 Make_Attribute_Reference (Loc,
12215 New_Reference_To (Index_Typ, Loc),
12216 Attribute_Name => Name_First)))))));
12220 end Install_Private_Data_Declarations;
12222 ---------------------------------
12223 -- Is_Potentially_Large_Family --
12224 ---------------------------------
12226 function Is_Potentially_Large_Family
12227 (Base_Index : Entity_Id;
12228 Conctyp : Entity_Id;
12230 Hi : Node_Id) return Boolean
12233 return Scope (Base_Index) = Standard_Standard
12234 and then Base_Index = Base_Type (Standard_Integer)
12235 and then Has_Discriminants (Conctyp)
12237 (Discriminant_Default_Value (First_Discriminant (Conctyp)))
12239 (Denotes_Discriminant (Lo, True)
12240 or else Denotes_Discriminant (Hi, True));
12241 end Is_Potentially_Large_Family;
12243 -------------------------------------
12244 -- Is_Private_Primitive_Subprogram --
12245 -------------------------------------
12247 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
12250 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
12251 and then Is_Private_Primitive (Id);
12252 end Is_Private_Primitive_Subprogram;
12258 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
12259 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
12260 Formal : Entity_Id;
12263 Formal := First_Formal (Bod_Subp);
12264 while Present (Formal) loop
12266 -- Look for formal parameter _E
12268 if Chars (Formal) = Name_uE then
12272 Next_Formal (Formal);
12275 -- A protected body subprogram should always have the parameter in
12278 raise Program_Error;
12281 --------------------------------
12282 -- Make_Initialize_Protection --
12283 --------------------------------
12285 function Make_Initialize_Protection
12286 (Protect_Rec : Entity_Id) return List_Id
12288 Loc : constant Source_Ptr := Sloc (Protect_Rec);
12292 Ptyp : constant Node_Id :=
12293 Corresponding_Concurrent_Type (Protect_Rec);
12295 L : constant List_Id := New_List;
12296 Has_Entry : constant Boolean := Has_Entries (Ptyp);
12297 Restricted : constant Boolean := Restricted_Profile;
12300 -- We may need two calls to properly initialize the object, one to
12301 -- Initialize_Protection, and possibly one to Install_Handlers if we
12302 -- have a pragma Attach_Handler.
12304 -- Get protected declaration. In the case of a task type declaration,
12305 -- this is simply the parent of the protected type entity. In the single
12306 -- protected object declaration, this parent will be the implicit type,
12307 -- and we can find the corresponding single protected object declaration
12308 -- by searching forward in the declaration list in the tree.
12310 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
12311 -- of this type should have been removed during semantic analysis.
12313 Pdec := Parent (Ptyp);
12314 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
12315 N_Single_Protected_Declaration)
12320 -- Now we can find the object definition from this declaration
12322 Pdef := Protected_Definition (Pdec);
12324 -- Build the parameter list for the call. Note that _Init is the name
12325 -- of the formal for the object to be initialized, which is the task
12326 -- value record itself.
12330 -- Object parameter. This is a pointer to the object of type
12331 -- Protection used by the GNARL to control the protected object.
12334 Make_Attribute_Reference (Loc,
12336 Make_Selected_Component (Loc,
12337 Prefix => Make_Identifier (Loc, Name_uInit),
12338 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12339 Attribute_Name => Name_Unchecked_Access));
12341 -- Priority parameter. Set to Unspecified_Priority unless there is a
12342 -- priority pragma, in which case we take the value from the pragma,
12343 -- or there is an interrupt pragma and no priority pragma, and we
12344 -- set the ceiling to Interrupt_Priority'Last, an implementation-
12345 -- defined value, see D.3(10).
12348 and then Has_Pragma_Priority (Pdef)
12351 Prio : constant Node_Id :=
12354 (Pragma_Argument_Associations
12355 (Find_Task_Or_Protected_Pragma
12356 (Pdef, Name_Priority))));
12360 -- If priority is a static expression, then we can duplicate it
12361 -- with no problem and simply append it to the argument list.
12363 if Is_Static_Expression (Prio) then
12365 Duplicate_Subexpr_No_Checks (Prio));
12367 -- Otherwise, the priority may be a per-object expression, if it
12368 -- depends on a discriminant of the type. In this case, create
12369 -- local variable to capture the expression. Note that it is
12370 -- really necessary to create this variable explicitly. It might
12371 -- be thought that removing side effects would the appropriate
12372 -- approach, but that could generate declarations improperly
12373 -- placed in the enclosing scope.
12375 -- Note: Use System.Any_Priority as the expected type for the
12376 -- non-static priority expression, in case the expression has not
12377 -- been analyzed yet (as occurs for example with pragma
12378 -- Interrupt_Priority).
12381 Temp := Make_Temporary (Loc, 'R', Prio);
12383 Make_Object_Declaration (Loc,
12384 Defining_Identifier => Temp,
12385 Object_Definition =>
12386 New_Occurrence_Of (RTE (RE_Any_Priority), Loc),
12387 Expression => Relocate_Node (Prio)));
12389 Append_To (Args, New_Occurrence_Of (Temp, Loc));
12393 -- When no priority is specified but an xx_Handler pragma is, we default
12394 -- to System.Interrupts.Default_Interrupt_Priority, see D.3(10).
12396 elsif Has_Interrupt_Handler (Ptyp)
12397 or else Has_Attach_Handler (Ptyp)
12400 New_Reference_To (RTE (RE_Default_Interrupt_Priority), Loc));
12402 -- Normal case, no priority or xx_Handler specified, default priority
12406 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12409 -- Test for Compiler_Info parameter. This parameter allows entry body
12410 -- procedures and barrier functions to be called from the runtime. It
12411 -- is a pointer to the record generated by the compiler to represent
12412 -- the protected object.
12414 -- A protected type without entries that covers an interface and
12415 -- overrides the abstract routines with protected procedures is
12416 -- considered equivalent to a protected type with entries in the
12417 -- context of dispatching select statements.
12420 or else Has_Interrupt_Handler (Ptyp)
12421 or else Has_Attach_Handler (Ptyp)
12422 or else Has_Interfaces (Protect_Rec)
12425 Pkg_Id : constant RTU_Id :=
12426 Corresponding_Runtime_Package (Ptyp);
12427 Called_Subp : RE_Id;
12431 when System_Tasking_Protected_Objects_Entries =>
12432 Called_Subp := RE_Initialize_Protection_Entries;
12434 when System_Tasking_Protected_Objects =>
12435 Called_Subp := RE_Initialize_Protection;
12437 when System_Tasking_Protected_Objects_Single_Entry =>
12438 Called_Subp := RE_Initialize_Protection_Entry;
12441 raise Program_Error;
12445 or else not Restricted
12446 or else Has_Interfaces (Protect_Rec)
12449 Make_Attribute_Reference (Loc,
12450 Prefix => Make_Identifier (Loc, Name_uInit),
12451 Attribute_Name => Name_Address));
12454 -- Entry_Bodies parameter. This is a pointer to an array of
12455 -- pointers to the entry body procedures and barrier functions of
12456 -- the object. If the protected type has no entries this object
12457 -- will not exist, in this case, pass a null.
12460 P_Arr := Entry_Bodies_Array (Ptyp);
12463 Make_Attribute_Reference (Loc,
12464 Prefix => New_Reference_To (P_Arr, Loc),
12465 Attribute_Name => Name_Unrestricted_Access));
12467 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
12469 -- Find index mapping function (clumsy but ok for now)
12471 while Ekind (P_Arr) /= E_Function loop
12472 Next_Entity (P_Arr);
12476 Make_Attribute_Reference (Loc,
12478 New_Reference_To (P_Arr, Loc),
12479 Attribute_Name => Name_Unrestricted_Access));
12481 -- Build_Entry_Names generation flag. When set to true, the
12482 -- runtime will allocate an array to hold the string names
12483 -- of protected entries.
12485 if not Restricted_Profile then
12486 if Entry_Names_OK then
12488 New_Reference_To (Standard_True, Loc));
12491 New_Reference_To (Standard_False, Loc));
12496 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
12497 Append_To (Args, Make_Null (Loc));
12499 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
12500 Append_To (Args, Make_Null (Loc));
12501 Append_To (Args, Make_Null (Loc));
12502 Append_To (Args, New_Reference_To (Standard_False, Loc));
12506 Make_Procedure_Call_Statement (Loc,
12507 Name => New_Reference_To (RTE (Called_Subp), Loc),
12508 Parameter_Associations => Args));
12512 Make_Procedure_Call_Statement (Loc,
12513 Name => New_Reference_To (RTE (RE_Initialize_Protection), Loc),
12514 Parameter_Associations => Args));
12517 if Has_Attach_Handler (Ptyp) then
12519 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
12520 -- make the following call:
12522 -- Install_Handlers (_object,
12523 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12525 -- or, in the case of Ravenscar:
12527 -- Install_Restricted_Handlers
12528 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
12531 Args : constant List_Id := New_List;
12532 Table : constant List_Id := New_List;
12533 Ritem : Node_Id := First_Rep_Item (Ptyp);
12536 -- Build the Attach_Handler table argument
12538 while Present (Ritem) loop
12539 if Nkind (Ritem) = N_Pragma
12540 and then Pragma_Name (Ritem) = Name_Attach_Handler
12543 Handler : constant Node_Id :=
12544 First (Pragma_Argument_Associations (Ritem));
12546 Interrupt : constant Node_Id := Next (Handler);
12547 Expr : constant Node_Id := Expression (Interrupt);
12551 Make_Aggregate (Loc, Expressions => New_List (
12552 Unchecked_Convert_To
12553 (RTE (RE_System_Interrupt_Id), Expr),
12554 Make_Attribute_Reference (Loc,
12555 Prefix => Make_Selected_Component (Loc,
12556 Make_Identifier (Loc, Name_uInit),
12557 Duplicate_Subexpr_No_Checks
12558 (Expression (Handler))),
12559 Attribute_Name => Name_Access))));
12563 Next_Rep_Item (Ritem);
12566 -- Append the table argument we just built
12568 Append_To (Args, Make_Aggregate (Loc, Table));
12570 -- Append the Install_Handlers (or Install_Restricted_Handlers)
12571 -- call to the statements.
12574 -- Call a simplified version of Install_Handlers to be used
12575 -- when the Ravenscar restrictions are in effect
12576 -- (Install_Restricted_Handlers).
12579 Make_Procedure_Call_Statement (Loc,
12582 (RTE (RE_Install_Restricted_Handlers), Loc),
12583 Parameter_Associations => Args));
12586 -- First, prepends the _object argument
12589 Make_Attribute_Reference (Loc,
12591 Make_Selected_Component (Loc,
12592 Prefix => Make_Identifier (Loc, Name_uInit),
12593 Selector_Name => Make_Identifier (Loc, Name_uObject)),
12594 Attribute_Name => Name_Unchecked_Access));
12596 -- Then, insert call to Install_Handlers
12599 Make_Procedure_Call_Statement (Loc,
12600 Name => New_Reference_To (RTE (RE_Install_Handlers), Loc),
12601 Parameter_Associations => Args));
12607 end Make_Initialize_Protection;
12609 ---------------------------
12610 -- Make_Task_Create_Call --
12611 ---------------------------
12613 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
12614 Loc : constant Source_Ptr := Sloc (Task_Rec);
12624 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
12625 Tnam := Chars (Ttyp);
12627 -- Get task declaration. In the case of a task type declaration, this is
12628 -- simply the parent of the task type entity. In the single task
12629 -- declaration, this parent will be the implicit type, and we can find
12630 -- the corresponding single task declaration by searching forward in the
12631 -- declaration list in the tree.
12633 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
12634 -- this type should have been removed during semantic analysis.
12636 Tdec := Parent (Ttyp);
12637 while not Nkind_In (Tdec, N_Task_Type_Declaration,
12638 N_Single_Task_Declaration)
12643 -- Now we can find the task definition from this declaration
12645 Tdef := Task_Definition (Tdec);
12647 -- Build the parameter list for the call. Note that _Init is the name
12648 -- of the formal for the object to be initialized, which is the task
12649 -- value record itself.
12653 -- Priority parameter. Set to Unspecified_Priority unless there is a
12654 -- priority pragma, in which case we take the value from the pragma.
12656 if Present (Tdef) and then Has_Pragma_Priority (Tdef) then
12658 Make_Selected_Component (Loc,
12659 Prefix => Make_Identifier (Loc, Name_uInit),
12660 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
12663 New_Reference_To (RTE (RE_Unspecified_Priority), Loc));
12666 -- Optional Stack parameter
12668 if Restricted_Profile then
12670 -- If the stack has been preallocated by the expander then
12671 -- pass its address. Otherwise, pass a null address.
12673 if Preallocated_Stacks_On_Target then
12675 Make_Attribute_Reference (Loc,
12677 Make_Selected_Component (Loc,
12678 Prefix => Make_Identifier (Loc, Name_uInit),
12679 Selector_Name => Make_Identifier (Loc, Name_uStack)),
12680 Attribute_Name => Name_Address));
12684 New_Reference_To (RTE (RE_Null_Address), Loc));
12688 -- Size parameter. If no Storage_Size pragma is present, then
12689 -- the size is taken from the taskZ variable for the type, which
12690 -- is either Unspecified_Size, or has been reset by the use of
12691 -- a Storage_Size attribute definition clause. If a pragma is
12692 -- present, then the size is taken from the _Size field of the
12693 -- task value record, which was set from the pragma value.
12696 and then Has_Storage_Size_Pragma (Tdef)
12699 Make_Selected_Component (Loc,
12700 Prefix => Make_Identifier (Loc, Name_uInit),
12701 Selector_Name => Make_Identifier (Loc, Name_uSize)));
12705 New_Reference_To (Storage_Size_Variable (Ttyp), Loc));
12708 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
12709 -- Task_Info pragma, in which case we take the value from the pragma.
12712 and then Has_Task_Info_Pragma (Tdef)
12715 Make_Selected_Component (Loc,
12716 Prefix => Make_Identifier (Loc, Name_uInit),
12717 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
12721 New_Reference_To (RTE (RE_Unspecified_Task_Info), Loc));
12724 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU pragma,
12725 -- in which case we take the value from the pragma. The parameter is
12726 -- passed as an Integer because in the case of unspecified CPU the
12727 -- value is not in the range of CPU_Range.
12729 if Present (Tdef) and then Has_Pragma_CPU (Tdef) then
12731 Convert_To (Standard_Integer,
12732 Make_Selected_Component (Loc,
12733 Prefix => Make_Identifier (Loc, Name_uInit),
12734 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
12738 New_Reference_To (RTE (RE_Unspecified_CPU), Loc));
12741 if not Restricted_Profile then
12743 -- Deadline parameter. If no Relative_Deadline pragma is present,
12744 -- then the deadline is Time_Span_Zero. If a pragma is present, then
12745 -- the deadline is taken from the _Relative_Deadline field of the
12746 -- task value record, which was set from the pragma value. Note that
12747 -- this parameter must not be generated for the restricted profiles
12748 -- since Ravenscar does not allow deadlines.
12750 -- Case where pragma Relative_Deadline applies: use given value
12752 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
12754 Make_Selected_Component (Loc,
12756 Make_Identifier (Loc, Name_uInit),
12758 Make_Identifier (Loc, Name_uRelative_Deadline)));
12760 -- No pragma Relative_Deadline apply to the task
12764 New_Reference_To (RTE (RE_Time_Span_Zero), Loc));
12767 -- Number of entries. This is an expression of the form:
12769 -- n + _Init.a'Length + _Init.a'B'Length + ...
12771 -- where a,b... are the entry family names for the task definition
12774 Build_Entry_Count_Expression
12779 (Parent (Corresponding_Record_Type (Ttyp))))),
12781 Append_To (Args, Ecount);
12783 -- Master parameter. This is a reference to the _Master parameter of
12784 -- the initialization procedure, except in the case of the pragma
12785 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
12786 -- System.Tasking.Library_Task_Level.
12788 if Restriction_Active (No_Task_Hierarchy) = False then
12789 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
12792 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
12796 -- State parameter. This is a pointer to the task body procedure. The
12797 -- required value is obtained by taking 'Unrestricted_Access of the task
12798 -- body procedure and converting it (with an unchecked conversion) to
12799 -- the type required by the task kernel. For further details, see the
12800 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
12801 -- than 'Address in order to avoid creating trampolines.
12804 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
12805 Subp_Ptr_Typ : constant Node_Id :=
12806 Create_Itype (E_Access_Subprogram_Type, Tdec);
12807 Ref : constant Node_Id := Make_Itype_Reference (Loc);
12810 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
12811 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
12813 -- Be sure to freeze a reference to the access-to-subprogram type,
12814 -- otherwise gigi will complain that it's in the wrong scope, because
12815 -- it's actually inside the init procedure for the record type that
12816 -- corresponds to the task type.
12818 -- This processing is causing a crash in the .NET/JVM back ends that
12819 -- is not yet understood, so skip it in these cases ???
12821 if VM_Target = No_VM then
12822 Set_Itype (Ref, Subp_Ptr_Typ);
12823 Append_Freeze_Action (Task_Rec, Ref);
12826 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12827 Make_Qualified_Expression (Loc,
12828 Subtype_Mark => New_Reference_To (Subp_Ptr_Typ, Loc),
12830 Make_Attribute_Reference (Loc,
12832 New_Occurrence_Of (Body_Proc, Loc),
12833 Attribute_Name => Name_Unrestricted_Access))));
12835 -- For the .NET/JVM cases revert to the original code below ???
12839 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
12840 Make_Attribute_Reference (Loc,
12842 New_Occurrence_Of (Body_Proc, Loc),
12843 Attribute_Name => Name_Address)));
12847 -- Discriminants parameter. This is just the address of the task
12848 -- value record itself (which contains the discriminant values
12851 Make_Attribute_Reference (Loc,
12852 Prefix => Make_Identifier (Loc, Name_uInit),
12853 Attribute_Name => Name_Address));
12855 -- Elaborated parameter. This is an access to the elaboration Boolean
12858 Make_Attribute_Reference (Loc,
12859 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
12860 Attribute_Name => Name_Unchecked_Access));
12862 -- Chain parameter. This is a reference to the _Chain parameter of
12863 -- the initialization procedure.
12865 Append_To (Args, Make_Identifier (Loc, Name_uChain));
12867 -- Task name parameter. Take this from the _Task_Id parameter to the
12868 -- init call unless there is a Task_Name pragma, in which case we take
12869 -- the value from the pragma.
12872 and then Has_Task_Name_Pragma (Tdef)
12874 -- Copy expression in full, because it may be dynamic and have
12880 (Pragma_Argument_Associations
12881 (Find_Task_Or_Protected_Pragma
12882 (Tdef, Name_Task_Name))))));
12885 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
12888 -- Created_Task parameter. This is the _Task_Id field of the task
12892 Make_Selected_Component (Loc,
12893 Prefix => Make_Identifier (Loc, Name_uInit),
12894 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
12896 -- Build_Entry_Names generation flag. When set to true, the runtime
12897 -- will allocate an array to hold the string names of task entries.
12899 if not Restricted_Profile then
12900 if Has_Entries (Ttyp)
12901 and then Entry_Names_OK
12903 Append_To (Args, New_Reference_To (Standard_True, Loc));
12905 Append_To (Args, New_Reference_To (Standard_False, Loc));
12909 if Restricted_Profile then
12910 Name := New_Reference_To (RTE (RE_Create_Restricted_Task), Loc);
12912 Name := New_Reference_To (RTE (RE_Create_Task), Loc);
12916 Make_Procedure_Call_Statement (Loc,
12918 Parameter_Associations => Args);
12919 end Make_Task_Create_Call;
12921 ------------------------------
12922 -- Next_Protected_Operation --
12923 ------------------------------
12925 function Next_Protected_Operation (N : Node_Id) return Node_Id is
12929 Next_Op := Next (N);
12930 while Present (Next_Op)
12931 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
12937 end Next_Protected_Operation;
12939 ---------------------
12940 -- Null_Statements --
12941 ---------------------
12943 function Null_Statements (Stats : List_Id) return Boolean is
12947 Stmt := First (Stats);
12948 while Nkind (Stmt) /= N_Empty
12949 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
12951 (Nkind (Stmt) = N_Pragma
12952 and then (Pragma_Name (Stmt) = Name_Unreferenced
12954 Pragma_Name (Stmt) = Name_Unmodified
12956 Pragma_Name (Stmt) = Name_Warnings)))
12961 return Nkind (Stmt) = N_Empty;
12962 end Null_Statements;
12964 --------------------------
12965 -- Parameter_Block_Pack --
12966 --------------------------
12968 function Parameter_Block_Pack
12970 Blk_Typ : Entity_Id;
12974 Stmts : List_Id) return Node_Id
12976 Actual : Entity_Id;
12977 Expr : Node_Id := Empty;
12978 Formal : Entity_Id;
12979 Has_Param : Boolean := False;
12982 Temp_Asn : Node_Id;
12983 Temp_Nam : Node_Id;
12986 Actual := First (Actuals);
12987 Formal := Defining_Identifier (First (Formals));
12988 Params := New_List;
12990 while Present (Actual) loop
12991 if Is_By_Copy_Type (Etype (Actual)) then
12993 -- Jnn : aliased <formal-type>
12995 Temp_Nam := Make_Temporary (Loc, 'J');
12998 Make_Object_Declaration (Loc,
13001 Defining_Identifier =>
13003 Object_Definition =>
13004 New_Reference_To (Etype (Formal), Loc)));
13006 if Ekind (Formal) /= E_Out_Parameter then
13012 New_Reference_To (Temp_Nam, Loc);
13014 Set_Assignment_OK (Temp_Asn);
13017 Make_Assignment_Statement (Loc,
13021 New_Copy_Tree (Actual)));
13025 -- Jnn'unchecked_access
13028 Make_Attribute_Reference (Loc,
13030 Name_Unchecked_Access,
13032 New_Reference_To (Temp_Nam, Loc)));
13036 -- The controlling parameter is omitted
13039 if not Is_Controlling_Actual (Actual) then
13041 Make_Reference (Loc, New_Copy_Tree (Actual)));
13047 Next_Actual (Actual);
13048 Next_Formal_With_Extras (Formal);
13052 Expr := Make_Aggregate (Loc, Params);
13057 -- J1'unchecked_access;
13058 -- <actual2>'reference;
13061 P := Make_Temporary (Loc, 'P');
13064 Make_Object_Declaration (Loc,
13065 Defining_Identifier =>
13067 Object_Definition =>
13068 New_Reference_To (Blk_Typ, Loc),
13073 end Parameter_Block_Pack;
13075 ----------------------------
13076 -- Parameter_Block_Unpack --
13077 ----------------------------
13079 function Parameter_Block_Unpack
13083 Formals : List_Id) return List_Id
13085 Actual : Entity_Id;
13087 Formal : Entity_Id;
13088 Has_Asnmt : Boolean := False;
13089 Result : constant List_Id := New_List;
13092 Actual := First (Actuals);
13093 Formal := Defining_Identifier (First (Formals));
13094 while Present (Actual) loop
13095 if Is_By_Copy_Type (Etype (Actual))
13096 and then Ekind (Formal) /= E_In_Parameter
13099 -- <actual> := P.<formal>;
13102 Make_Assignment_Statement (Loc,
13106 Make_Explicit_Dereference (Loc,
13107 Make_Selected_Component (Loc,
13109 New_Reference_To (P, Loc),
13111 Make_Identifier (Loc, Chars (Formal)))));
13113 Set_Assignment_OK (Name (Asnmt));
13114 Append_To (Result, Asnmt);
13119 Next_Actual (Actual);
13120 Next_Formal_With_Extras (Formal);
13126 return New_List (Make_Null_Statement (Loc));
13128 end Parameter_Block_Unpack;
13130 ----------------------
13131 -- Set_Discriminals --
13132 ----------------------
13134 procedure Set_Discriminals (Dec : Node_Id) is
13137 D_Minal : Entity_Id;
13140 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
13141 Pdef := Defining_Identifier (Dec);
13143 if Has_Discriminants (Pdef) then
13144 D := First_Discriminant (Pdef);
13145 while Present (D) loop
13147 Make_Defining_Identifier (Sloc (D),
13148 Chars => New_External_Name (Chars (D), 'D'));
13150 Set_Ekind (D_Minal, E_Constant);
13151 Set_Etype (D_Minal, Etype (D));
13152 Set_Scope (D_Minal, Pdef);
13153 Set_Discriminal (D, D_Minal);
13154 Set_Discriminal_Link (D_Minal, D);
13156 Next_Discriminant (D);
13159 end Set_Discriminals;
13161 -----------------------
13162 -- Trivial_Accept_OK --
13163 -----------------------
13165 function Trivial_Accept_OK return Boolean is
13167 case Opt.Task_Dispatching_Policy is
13169 -- If we have the default task dispatching policy in effect, we can
13170 -- definitely do the optimization (one way of looking at this is to
13171 -- think of the formal definition of the default policy being allowed
13172 -- to run any task it likes after a rendezvous, so even if notionally
13173 -- a full rescheduling occurs, we can say that our dispatching policy
13174 -- (i.e. the default dispatching policy) reorders the queue to be the
13175 -- same as just before the call.
13180 -- FIFO_Within_Priorities certainly does not permit this
13181 -- optimization since the Rendezvous is a scheduling action that may
13182 -- require some other task to be run.
13187 -- For now, disallow the optimization for all other policies. This
13188 -- may be over-conservative, but it is certainly not incorrect.
13194 end Trivial_Accept_OK;