1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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_Ch9; use Sem_Ch9;
55 with Sem_Ch11; use Sem_Ch11;
56 with Sem_Elab; use Sem_Elab;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Res; use Sem_Res;
59 with Sem_Util; use Sem_Util;
60 with Sinfo; use Sinfo;
61 with Snames; use Snames;
62 with Stand; use Stand;
63 with Stringt; use Stringt;
64 with Targparm; use Targparm;
65 with Tbuild; use Tbuild;
66 with Uintp; use Uintp;
68 package body Exp_Ch9 is
70 -- The following constant establishes the upper bound for the index of
71 -- an entry family. It is used to limit the allocated size of protected
72 -- types with defaulted discriminant of an integer type, when the bound
73 -- of some entry family depends on a discriminant. The limitation to entry
74 -- families of 128K should be reasonable in all cases, and is a documented
75 -- implementation restriction.
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_Dispatching_Tag_Check
141 N : Node_Id) return Node_Id;
142 -- Utility to create the tree to check whether the dispatching call in
143 -- a timed entry call, a conditional entry call, or an asynchronous
144 -- transfer of control is a call to a primitive of a non-synchronized type.
145 -- K is the temporary that holds the tagged kind of the target object, and
146 -- N is the enclosing construct.
148 function Build_Entry_Count_Expression
149 (Concurrent_Type : Node_Id;
150 Component_List : List_Id;
151 Loc : Source_Ptr) return Node_Id;
152 -- Compute number of entries for concurrent object. This is a count of
153 -- simple entries, followed by an expression that computes the length
154 -- of the range of each entry family. A single array with that size is
155 -- allocated for each concurrent object of the type.
157 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
158 -- Build the function that translates the entry index in the call
159 -- (which depends on the size of entry families) into an index into the
160 -- Entry_Bodies_Array, to determine the body and barrier function used
161 -- in a protected entry call. A pointer to this function appears in every
164 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
165 -- Build subprogram declaration for previous one
167 function Build_Lock_Free_Protected_Subprogram_Body
170 Unprot_Spec : Node_Id) return Node_Id;
171 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
172 -- the subprogram specification of the unprotected version of N. Transform
173 -- N such that it invokes the unprotected version of the body.
175 function Build_Lock_Free_Unprotected_Subprogram_Body
177 Prot_Typ : Node_Id) return Node_Id;
178 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
179 -- of N where the original statements of N are synchronized through atomic
180 -- actions such as compare and exchange. Prior to invoking this routine, it
181 -- has been established that N can be implemented in a lock-free fashion.
183 function Build_Parameter_Block
187 Decls : List_Id) return Entity_Id;
188 -- Generate an access type for each actual parameter in the list Actuals.
189 -- Create an encapsulating record that contains all the actuals and return
190 -- its type. Generate:
191 -- type Ann1 is access all <actual1-type>
193 -- type AnnN is access all <actualN-type>
194 -- type Pnn is record
200 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id);
201 -- Build body of wrapper procedure for an entry or entry family that has
202 -- pre/postconditions. The body gathers the PPC's and expands them in the
203 -- usual way, and performs the entry call itself. This way preconditions
204 -- are evaluated before the call is queued. E is the entry in question,
205 -- and Decl is the enclosing synchronized type declaration at whose freeze
206 -- point the generated body is analyzed.
208 function Build_Protected_Entry
211 Pid : Node_Id) return Node_Id;
212 -- Build the procedure implementing the statement sequence of the specified
215 function Build_Protected_Entry_Specification
218 Ent_Id : Entity_Id) return Node_Id;
219 -- Build a specification for the procedure implementing the statements of
220 -- the specified entry body. Add attributes associating it with the entry
221 -- defining identifier Ent_Id.
223 function Build_Protected_Spec
225 Obj_Type : Entity_Id;
227 Unprotected : Boolean := False) return List_Id;
228 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
229 -- Subprogram_Type. Builds signature of protected subprogram, adding the
230 -- formal that corresponds to the object itself. For an access to protected
231 -- subprogram, there is no object type to specify, so the parameter has
232 -- type Address and mode In. An indirect call through such a pointer will
233 -- convert the address to a reference to the actual object. The object is
234 -- a limited record and therefore a by_reference type.
236 function Build_Protected_Subprogram_Body
239 N_Op_Spec : Node_Id) return Node_Id;
240 -- This function is used to construct the protected version of a protected
241 -- subprogram. Its statement sequence first defers abort, then locks the
242 -- associated protected object, and then enters a block that contains a
243 -- call to the unprotected version of the subprogram (for details, see
244 -- Build_Unprotected_Subprogram_Body). This block statement requires a
245 -- cleanup handler that unlocks the object in all cases. For details,
246 -- see Exp_Ch7.Expand_Cleanup_Actions.
248 function Build_Renamed_Formal_Declaration
252 Renamed_Formal : Node_Id) return Node_Id;
253 -- Create a renaming declaration for a formal, within a protected entry
254 -- body or an accept body. The renamed object is a component of the
255 -- parameter block that is a parameter in the entry call.
257 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
258 -- does not dereference the corresponding component to prevent an illegal
259 -- use of the incomplete type (AI05-0151).
261 function Build_Selected_Name
263 Selector : Entity_Id;
264 Append_Char : Character := ' ') return Name_Id;
265 -- Build a name in the form of Prefix__Selector, with an optional character
266 -- appended. This is used for internal subprograms generated for operations
267 -- of protected types, including barrier functions. For the subprograms
268 -- generated for entry bodies and entry barriers, the generated name
269 -- includes a sequence number that makes names unique in the presence of
270 -- entry overloading. This is necessary because entry body procedures and
271 -- barrier functions all have the same signature.
273 procedure Build_Simple_Entry_Call
278 -- Some comments here would be useful ???
280 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
281 -- This routine constructs a specification for the procedure that we will
282 -- build for the task body for task type T. The spec has the form:
284 -- procedure tnameB (_Task : access tnameV);
286 -- where name is the character name taken from the task type entity that
287 -- is passed as the argument to the procedure, and tnameV is the task
288 -- value type that is associated with the task type.
290 function Build_Unprotected_Subprogram_Body
292 Pid : Node_Id) return Node_Id;
293 -- This routine constructs the unprotected version of a protected
294 -- subprogram body, which is contains all of the code in the original,
295 -- unexpanded body. This is the version of the protected subprogram that is
296 -- called from all protected operations on the same object, including the
297 -- protected version of the same subprogram.
299 procedure Build_Wrapper_Bodies
303 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
304 -- record of a concurrent type. N is the insertion node where all bodies
305 -- will be placed. This routine builds the bodies of the subprograms which
306 -- serve as an indirection mechanism to overriding primitives of concurrent
307 -- types, entries and protected procedures. Any new body is analyzed.
309 procedure Build_Wrapper_Specs
313 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
314 -- record of a concurrent type. N is the insertion node where all specs
315 -- will be placed. This routine builds the specs of the subprograms which
316 -- serve as an indirection mechanism to overriding primitives of concurrent
317 -- types, entries and protected procedures. Any new spec is analyzed.
319 procedure Collect_Entry_Families
322 Current_Node : in out Node_Id;
323 Conctyp : Entity_Id);
324 -- For each entry family in a concurrent type, create an anonymous array
325 -- type of the right size, and add a component to the corresponding_record.
327 function Concurrent_Object
328 (Spec_Id : Entity_Id;
329 Conc_Typ : Entity_Id) return Entity_Id;
330 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
331 -- the entity associated with the concurrent object in the Protected_Body_
332 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
333 -- denotes formal parameter _O, _object or _task.
335 function Copy_Result_Type (Res : Node_Id) return Node_Id;
336 -- Copy the result type of a function specification, when building the
337 -- internal operation corresponding to a protected function, or when
338 -- expanding an access to protected function. If the result is an anonymous
339 -- access to subprogram itself, we need to create a new signature with the
340 -- same parameter names and the same resolved types, but with new entities
343 procedure Debug_Private_Data_Declarations (Decls : List_Id);
344 -- Decls is a list which may contain the declarations created by Install_
345 -- Private_Data_Declarations. All generated entities are marked as needing
346 -- debug info and debug nodes are manually generation where necessary. This
347 -- step of the expansion must to be done after private data has been moved
348 -- to its final resting scope to ensure proper visibility of debug objects.
350 procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id);
351 -- If control flow optimizations are suppressed, and Alt is an accept,
352 -- delay, or entry call alternative with no trailing statements, insert
353 -- a null trailing statement with the given Loc (which is the sloc of
354 -- the accept, delay, or entry call statement). There might not be any
355 -- generated code for the accept, delay, or entry call itself (the effect
356 -- of these statements is part of the general processsing done for the
357 -- enclosing selective accept, timed entry call, or asynchronous select),
358 -- and the null statement is there to carry the sloc of that statement to
359 -- the back-end for trace-based coverage analysis purposes.
361 procedure Extract_Dispatching_Call
363 Call_Ent : out Entity_Id;
364 Object : out Entity_Id;
365 Actuals : out List_Id;
366 Formals : out List_Id);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
373 procedure Extract_Entry
375 Concval : out Node_Id;
377 Index : out Node_Id);
378 -- Given an entry call, returns the associated concurrent object, the entry
379 -- name, and the entry family index.
381 function Family_Offset
386 Cap : Boolean) return Node_Id;
387 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
388 -- accept statement, or the upper bound in the discrete subtype of an entry
389 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
390 -- type of the entry. If Cap is true, the result is capped according to
391 -- Entry_Family_Bound.
398 Cap : Boolean) return Node_Id;
399 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
400 -- family, and handle properly the superflat case. This is equivalent to
401 -- the use of 'Length on the index type, but must use Family_Offset to
402 -- handle properly the case of bounds that depend on discriminants. If
403 -- Cap is true, the result is capped according to Entry_Family_Bound.
405 procedure Find_Enclosing_Context
407 Context : out Node_Id;
408 Context_Id : out Entity_Id;
409 Context_Decls : out List_Id);
410 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
411 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
412 -- nearest enclosing body, block, package or return statement and return
413 -- its constituents. Context is the enclosing construct, Context_Id is
414 -- the scope of Context_Id and Context_Decls is the declarative list of
417 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
418 -- Given a subprogram identifier, return the entity which is associated
419 -- with the protection entry index in the Protected_Body_Subprogram or
420 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
423 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
424 -- Tell whether a given subprogram cannot raise an exception
426 function Is_Potentially_Large_Family
427 (Base_Index : Entity_Id;
430 Hi : Node_Id) return Boolean;
432 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
433 -- Determine whether Id is a function or a procedure and is marked as a
434 -- private primitive.
436 function Null_Statements (Stats : List_Id) return Boolean;
437 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
438 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
439 -- to still count as null. Returns True for a null sequence. The argument
440 -- is the list of statements from the DO-END sequence.
442 function Parameter_Block_Pack
448 Stmts : List_Id) return Entity_Id;
449 -- Set the components of the generated parameter block with the values
450 -- of the actual parameters. Generate aliased temporaries to capture the
451 -- values for types that are passed by copy. Otherwise generate a reference
452 -- to the actual's value. Return the address of the aggregate block.
454 -- Jnn1 : alias <formal-type1>;
455 -- Jnn1 := <actual1>;
458 -- Jnn1'unchecked_access;
459 -- <actual2>'reference;
462 function Parameter_Block_Unpack
466 Formals : List_Id) return List_Id;
467 -- Retrieve the values of the components from the parameter block and
468 -- assign then to the original actual parameters. Generate:
469 -- <actual1> := P.<formal1>;
471 -- <actualN> := P.<formalN>;
473 function Trivial_Accept_OK return Boolean;
474 -- If there is no DO-END block for an accept, or if the DO-END block has
475 -- only null statements, then it is possible to do the Rendezvous with much
476 -- less overhead using the Accept_Trivial routine in the run-time library.
477 -- However, this is not always a valid optimization. Whether it is valid or
478 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
479 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
480 -- a rescheduling is required, so this optimization is not allowed. This
481 -- function returns True if the optimization is permitted.
483 -----------------------------
484 -- Actual_Index_Expression --
485 -----------------------------
487 function Actual_Index_Expression
491 Tsk : Entity_Id) return Node_Id
493 Ttyp : constant Entity_Id := Etype (Tsk);
501 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
502 -- Compute difference between bounds of entry family
504 --------------------------
505 -- Actual_Family_Offset --
506 --------------------------
508 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
510 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
511 -- Replace a reference to a discriminant with a selected component
512 -- denoting the discriminant of the target task.
514 -----------------------------
515 -- Actual_Discriminant_Ref --
516 -----------------------------
518 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
519 Typ : constant Entity_Id := Etype (Bound);
523 if not Is_Entity_Name (Bound)
524 or else Ekind (Entity (Bound)) /= E_Discriminant
526 if Nkind (Bound) = N_Attribute_Reference then
529 B := New_Copy_Tree (Bound);
534 Make_Selected_Component (Sloc,
535 Prefix => New_Copy_Tree (Tsk),
536 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
538 Analyze_And_Resolve (B, Typ);
542 Make_Attribute_Reference (Sloc,
543 Attribute_Name => Name_Pos,
544 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
545 Expressions => New_List (B));
546 end Actual_Discriminant_Ref;
548 -- Start of processing for Actual_Family_Offset
552 Make_Op_Subtract (Sloc,
553 Left_Opnd => Actual_Discriminant_Ref (Hi),
554 Right_Opnd => Actual_Discriminant_Ref (Lo));
555 end Actual_Family_Offset;
557 -- Start of processing for Actual_Index_Expression
560 -- The queues of entries and entry families appear in textual order in
561 -- the associated record. The entry index is computed as the sum of the
562 -- number of queues for all entries that precede the designated one, to
563 -- which is added the index expression, if this expression denotes a
564 -- member of a family.
566 -- The following is a place holder for the count of simple entries
568 Num := Make_Integer_Literal (Sloc, 1);
570 -- We construct an expression which is a series of addition operations.
571 -- See comments in Entry_Index_Expression, which is identical in
574 if Present (Index) then
575 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
581 Actual_Family_Offset (
582 Make_Attribute_Reference (Sloc,
583 Attribute_Name => Name_Pos,
584 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
585 Expressions => New_List (Relocate_Node (Index))),
586 Type_Low_Bound (S)));
591 -- Now add lengths of preceding entries and entry families
593 Prev := First_Entity (Ttyp);
594 while Chars (Prev) /= Chars (Ent)
595 or else (Ekind (Prev) /= Ekind (Ent))
596 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
598 if Ekind (Prev) = E_Entry then
599 Set_Intval (Num, Intval (Num) + 1);
601 elsif Ekind (Prev) = E_Entry_Family then
603 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
605 -- The need for the following full view retrieval stems from this
606 -- complex case of nested generics and tasking:
609 -- type Formal_Index is range <>;
612 -- type Index is private;
619 -- type Index is new Formal_Index range 1 .. 10;
622 -- package body Outer is
624 -- entry Fam (Index); -- (2)
627 -- package body Inner is -- (3)
635 -- We are currently building the index expression for the entry
636 -- call "T.E" (1). Part of the expansion must mention the range
637 -- of the discrete type "Index" (2) of entry family "Fam".
639 -- However only the private view of type "Index" is available to
640 -- the inner generic (3) because there was no prior mention of
641 -- the type inside "Inner". This visibility requirement is
642 -- implicit and cannot be detected during the construction of
643 -- the generic trees and needs special handling.
646 and then Is_Private_Type (S)
647 and then Present (Full_View (S))
652 Lo := Type_Low_Bound (S);
653 Hi := Type_High_Bound (S);
660 Left_Opnd => Actual_Family_Offset (Hi, Lo),
661 Right_Opnd => Make_Integer_Literal (Sloc, 1)));
663 -- Other components are anonymous types to be ignored
673 end Actual_Index_Expression;
675 --------------------------
676 -- Add_Formal_Renamings --
677 --------------------------
679 procedure Add_Formal_Renamings
685 Ptr : constant Entity_Id :=
687 (Next (First (Parameter_Specifications (Spec))));
688 -- The name of the formal that holds the address of the parameter block
695 Renamed_Formal : Node_Id;
698 Formal := First_Formal (Ent);
699 while Present (Formal) loop
700 Comp := Entry_Component (Formal);
702 Make_Defining_Identifier (Sloc (Formal),
703 Chars => Chars (Formal));
704 Set_Etype (New_F, Etype (Formal));
705 Set_Scope (New_F, Ent);
707 -- Now we set debug info needed on New_F even though it does not come
708 -- from source, so that the debugger will get the right information
709 -- for these generated names.
711 Set_Debug_Info_Needed (New_F);
713 if Ekind (Formal) = E_In_Parameter then
714 Set_Ekind (New_F, E_Constant);
716 Set_Ekind (New_F, E_Variable);
717 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
720 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
723 Make_Selected_Component (Loc,
725 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
726 Make_Identifier (Loc, Chars (Ptr))),
727 Selector_Name => New_Occurrence_Of (Comp, Loc));
730 Build_Renamed_Formal_Declaration
731 (New_F, Formal, Comp, Renamed_Formal);
733 Append (Decl, Decls);
734 Set_Renamed_Object (Formal, New_F);
735 Next_Formal (Formal);
737 end Add_Formal_Renamings;
739 ------------------------
740 -- Add_Object_Pointer --
741 ------------------------
743 procedure Add_Object_Pointer
745 Conc_Typ : Entity_Id;
748 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
753 -- Create the renaming declaration for the Protection object of a
754 -- protected type. _Object is used by Complete_Entry_Body.
755 -- ??? An attempt to make this a renaming was unsuccessful.
757 -- Build the entity for the access type
760 Make_Defining_Identifier (Loc,
761 New_External_Name (Chars (Rec_Typ), 'P'));
764 -- _object : poVP := poVP!O;
767 Make_Object_Declaration (Loc,
768 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject),
769 Object_Definition => New_Occurrence_Of (Obj_Ptr, Loc),
771 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
772 Set_Debug_Info_Needed (Defining_Identifier (Decl));
773 Prepend_To (Decls, Decl);
776 -- type poVP is access poV;
779 Make_Full_Type_Declaration (Loc,
780 Defining_Identifier =>
783 Make_Access_To_Object_Definition (Loc,
784 Subtype_Indication =>
785 New_Occurrence_Of (Rec_Typ, Loc)));
786 Set_Debug_Info_Needed (Defining_Identifier (Decl));
787 Prepend_To (Decls, Decl);
788 end Add_Object_Pointer;
790 -----------------------
791 -- Build_Accept_Body --
792 -----------------------
794 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
795 Loc : constant Source_Ptr := Sloc (Astat);
796 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
803 -- At the end of the statement sequence, Complete_Rendezvous is called.
804 -- A label skipping the Complete_Rendezvous, and all other accept
805 -- processing, has already been added for the expansion of requeue
806 -- statements. The Sloc is copied from the last statement since it
807 -- is really part of this last statement.
811 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
812 Insert_Before (Last (Statements (Stats)), Call);
815 -- If exception handlers are present, then append Complete_Rendezvous
816 -- calls to the handlers, and construct the required outer block. As
817 -- above, the Sloc is copied from the last statement in the sequence.
819 if Present (Exception_Handlers (Stats)) then
820 Hand := First (Exception_Handlers (Stats));
821 while Present (Hand) loop
824 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
825 Append (Call, Statements (Hand));
831 Make_Handled_Sequence_Of_Statements (Loc,
832 Statements => New_List (
833 Make_Block_Statement (Loc,
834 Handled_Statement_Sequence => Stats)));
840 -- At this stage we know that the new statement sequence does
841 -- not have an exception handler part, so we supply one to call
842 -- Exceptional_Complete_Rendezvous. This handler is
844 -- when all others =>
845 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
847 -- We handle Abort_Signal to make sure that we properly catch the abort
848 -- case and wake up the caller.
850 Ohandle := Make_Others_Choice (Loc);
851 Set_All_Others (Ohandle);
853 Set_Exception_Handlers (New_S,
855 Make_Implicit_Exception_Handler (Loc,
856 Exception_Choices => New_List (Ohandle),
858 Statements => New_List (
859 Make_Procedure_Call_Statement (Sloc (Stats),
860 Name => New_Occurrence_Of (
861 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
862 Parameter_Associations => New_List (
863 Make_Function_Call (Sloc (Stats),
866 (RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
868 Set_Parent (New_S, Astat); -- temp parent for Analyze call
869 Analyze_Exception_Handlers (Exception_Handlers (New_S));
870 Expand_Exception_Handlers (New_S);
872 -- Exceptional_Complete_Rendezvous must be called with abort still
873 -- deferred, which is the case for a "when all others" handler.
876 end Build_Accept_Body;
878 -----------------------------------
879 -- Build_Activation_Chain_Entity --
880 -----------------------------------
882 procedure Build_Activation_Chain_Entity (N : Node_Id) is
883 function Has_Activation_Chain (Stmt : Node_Id) return Boolean;
884 -- Determine whether an extended return statement has activation chain
886 --------------------------
887 -- Has_Activation_Chain --
888 --------------------------
890 function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
894 Decl := First (Return_Object_Declarations (Stmt));
895 while Present (Decl) loop
896 if Nkind (Decl) = N_Object_Declaration
897 and then Chars (Defining_Identifier (Decl)) = Name_uChain
906 end Has_Activation_Chain;
911 Context_Id : Entity_Id;
914 -- Start of processing for Build_Activation_Chain_Entity
917 -- Activation chain is never used for sequential elaboration policy, see
918 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
920 if Partition_Elaboration_Policy = 'S' then
924 Find_Enclosing_Context (N, Context, Context_Id, Decls);
926 -- If activation chain entity has not been declared already, create one
928 if Nkind (Context) = N_Extended_Return_Statement
929 or else No (Activation_Chain_Entity (Context))
931 -- Since extended return statements do not store the entity of the
932 -- chain, examine the return object declarations to avoid creating
935 if Nkind (Context) = N_Extended_Return_Statement
936 and then Has_Activation_Chain (Context)
942 Loc : constant Source_Ptr := Sloc (Context);
947 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
949 -- Note: An extended return statement is not really a task
950 -- activator, but it does have an activation chain on which to
951 -- store the tasks temporarily. On successful return, the tasks
952 -- on this chain are moved to the chain passed in by the caller.
953 -- We do not build an Activation_Chain_Entity for an extended
954 -- return statement, because we do not want to build a call to
955 -- Activate_Tasks. Task activation is the responsibility of the
958 if Nkind (Context) /= N_Extended_Return_Statement then
959 Set_Activation_Chain_Entity (Context, Chain);
963 Make_Object_Declaration (Loc,
964 Defining_Identifier => Chain,
965 Aliased_Present => True,
967 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc));
969 Prepend_To (Decls, Decl);
971 -- Ensure that _chain appears in the proper scope of the context
973 if Context_Id /= Current_Scope then
974 Push_Scope (Context_Id);
982 end Build_Activation_Chain_Entity;
984 ----------------------------
985 -- Build_Barrier_Function --
986 ----------------------------
988 function Build_Barrier_Function
991 Pid : Node_Id) return Node_Id
993 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
994 Cond : constant Node_Id := Condition (Ent_Formals);
995 Loc : constant Source_Ptr := Sloc (Cond);
996 Func_Id : constant Entity_Id := Barrier_Function (Ent);
997 Op_Decls : constant List_Id := New_List;
1002 -- Add a declaration for the Protection object, renaming declarations
1003 -- for the discriminals and privals and finally a declaration for the
1004 -- entry family index (if applicable).
1006 Install_Private_Data_Declarations (Sloc (N),
1012 Family => Ekind (Ent) = E_Entry_Family);
1014 -- If compiling with -fpreserve-control-flow, make sure we insert an
1015 -- IF statement so that the back-end knows to generate a conditional
1016 -- branch instruction, even if the condition is just the name of a
1017 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1018 -- such redundant IF statements under -fpreserve-control-flow
1019 -- (whether coming from this routine, or directly from source).
1021 if Opt.Suppress_Control_Flow_Optimizations then
1023 Make_Implicit_If_Statement (Cond,
1025 Then_Statements => New_List (
1026 Make_Simple_Return_Statement (Loc,
1027 New_Occurrence_Of (Standard_True, Loc))),
1029 Else_Statements => New_List (
1030 Make_Simple_Return_Statement (Loc,
1031 New_Occurrence_Of (Standard_False, Loc))));
1034 Stmt := Make_Simple_Return_Statement (Loc, Cond);
1037 -- Note: the condition in the barrier function needs to be properly
1038 -- processed for the C/Fortran boolean possibility, but this happens
1039 -- automatically since the return statement does this normalization.
1042 Make_Subprogram_Body (Loc,
1044 Build_Barrier_Function_Specification (Loc,
1045 Make_Defining_Identifier (Loc, Chars (Func_Id))),
1046 Declarations => Op_Decls,
1047 Handled_Statement_Sequence =>
1048 Make_Handled_Sequence_Of_Statements (Loc,
1049 Statements => New_List (Stmt)));
1050 Set_Is_Entry_Barrier_Function (Func_Body);
1053 end Build_Barrier_Function;
1055 ------------------------------------------
1056 -- Build_Barrier_Function_Specification --
1057 ------------------------------------------
1059 function Build_Barrier_Function_Specification
1061 Def_Id : Entity_Id) return Node_Id
1064 Set_Debug_Info_Needed (Def_Id);
1067 Make_Function_Specification (Loc,
1068 Defining_Unit_Name => Def_Id,
1069 Parameter_Specifications => New_List (
1070 Make_Parameter_Specification (Loc,
1071 Defining_Identifier =>
1072 Make_Defining_Identifier (Loc, Name_uO),
1074 New_Occurrence_Of (RTE (RE_Address), Loc)),
1076 Make_Parameter_Specification (Loc,
1077 Defining_Identifier =>
1078 Make_Defining_Identifier (Loc, Name_uE),
1080 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
1082 Result_Definition =>
1083 New_Occurrence_Of (Standard_Boolean, Loc));
1084 end Build_Barrier_Function_Specification;
1086 --------------------------
1087 -- Build_Call_With_Task --
1088 --------------------------
1090 function Build_Call_With_Task
1092 E : Entity_Id) return Node_Id
1094 Loc : constant Source_Ptr := Sloc (N);
1097 Make_Function_Call (Loc,
1098 Name => New_Occurrence_Of (E, Loc),
1099 Parameter_Associations => New_List (Concurrent_Ref (N)));
1100 end Build_Call_With_Task;
1102 -----------------------------
1103 -- Build_Class_Wide_Master --
1104 -----------------------------
1106 procedure Build_Class_Wide_Master (Typ : Entity_Id) is
1107 Loc : constant Source_Ptr := Sloc (Typ);
1108 Master_Id : Entity_Id;
1109 Master_Scope : Entity_Id;
1111 Related_Node : Node_Id;
1115 -- Nothing to do if there is no task hierarchy
1117 if Restriction_Active (No_Task_Hierarchy) then
1121 -- Find the declaration that created the access type, which is either a
1122 -- type declaration, or an object declaration with an access definition,
1123 -- in which case the type is anonymous.
1125 if Is_Itype (Typ) then
1126 Related_Node := Associated_Node_For_Itype (Typ);
1128 Related_Node := Parent (Typ);
1131 Master_Scope := Find_Master_Scope (Typ);
1133 -- Nothing to do if the master scope already contains a _master entity.
1134 -- The only exception to this is the following scenario:
1137 -- Transient_Scope_1
1140 -- Transient_Scope_2
1143 -- In this case the source scope is marked as having the master entity
1144 -- even though the actual declaration appears inside an inner scope. If
1145 -- the second transient scope requires a _master, it cannot use the one
1146 -- already declared because the entity is not visible.
1148 Name_Id := Make_Identifier (Loc, Name_uMaster);
1150 if not Has_Master_Entity (Master_Scope)
1151 or else No (Current_Entity_In_Scope (Name_Id))
1154 Master_Decl : Node_Id;
1156 Set_Has_Master_Entity (Master_Scope);
1159 -- _master : constant Integer := Current_Master.all;
1162 Make_Object_Declaration (Loc,
1163 Defining_Identifier =>
1164 Make_Defining_Identifier (Loc, Name_uMaster),
1165 Constant_Present => True,
1166 Object_Definition =>
1167 New_Occurrence_Of (Standard_Integer, Loc),
1169 Make_Explicit_Dereference (Loc,
1170 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
1172 Insert_Action (Find_Hook_Context (Related_Node), Master_Decl);
1173 Analyze (Master_Decl);
1175 -- Mark the containing scope as a task master. Masters associated
1176 -- with return statements are already marked at this stage (see
1177 -- Analyze_Subprogram_Body).
1179 if Ekind (Current_Scope) /= E_Return_Statement then
1181 Par : Node_Id := Related_Node;
1184 while Nkind (Par) /= N_Compilation_Unit loop
1185 Par := Parent (Par);
1187 -- If we fall off the top, we are at the outer level,
1188 -- and the environment task is our effective master,
1189 -- so nothing to mark.
1191 if Nkind_In (Par, N_Block_Statement,
1195 Set_Is_Task_Master (Par);
1205 Make_Defining_Identifier (Loc, New_External_Name (Chars (Typ), 'M'));
1208 -- typeMnn renames _master;
1211 Make_Object_Renaming_Declaration (Loc,
1212 Defining_Identifier => Master_Id,
1213 Subtype_Mark => New_Occurrence_Of (Standard_Integer, Loc),
1216 Insert_Action (Related_Node, Ren_Decl);
1218 Set_Master_Id (Typ, Master_Id);
1219 end Build_Class_Wide_Master;
1221 --------------------------------
1222 -- Build_Corresponding_Record --
1223 --------------------------------
1225 function Build_Corresponding_Record
1228 Loc : Source_Ptr) return Node_Id
1230 Rec_Ent : constant Entity_Id :=
1231 Make_Defining_Identifier
1232 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1235 New_Disc : Entity_Id;
1239 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1240 Set_Ekind (Rec_Ent, E_Record_Type);
1241 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1242 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1243 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1244 Set_Stored_Constraint (Rec_Ent, No_Elist);
1247 -- Propagate type invariants to the corresponding record type
1249 Set_Has_Invariants (Rec_Ent, Has_Invariants (Ctyp));
1250 Set_Has_Inheritable_Invariants (Rec_Ent,
1251 Has_Inheritable_Invariants (Ctyp));
1253 -- Use discriminals to create list of discriminants for record, and
1254 -- create new discriminals for use in default expressions, etc. It is
1255 -- worth noting that a task discriminant gives rise to 5 entities;
1257 -- a) The original discriminant.
1258 -- b) The discriminal for use in the task.
1259 -- c) The discriminant of the corresponding record.
1260 -- d) The discriminal for the init proc of the corresponding record.
1261 -- e) The local variable that renames the discriminant in the procedure
1262 -- for the task body.
1264 -- In fact the discriminals b) are used in the renaming declarations
1265 -- for e). See details in einfo (Handling of Discriminants).
1267 if Present (Discriminant_Specifications (N)) then
1269 Disc := First_Discriminant (Ctyp);
1271 while Present (Disc) loop
1272 New_Disc := CR_Discriminant (Disc);
1275 Make_Discriminant_Specification (Loc,
1276 Defining_Identifier => New_Disc,
1277 Discriminant_Type =>
1278 New_Occurrence_Of (Etype (Disc), Loc),
1280 New_Copy (Discriminant_Default_Value (Disc))));
1282 Next_Discriminant (Disc);
1289 -- Now we can construct the record type declaration. Note that this
1290 -- record is "limited tagged". It is "limited" to reflect the underlying
1291 -- limitedness of the task or protected object that it represents, and
1292 -- ensuring for example that it is properly passed by reference. It is
1293 -- "tagged" to give support to dispatching calls through interfaces. We
1294 -- propagate here the list of interfaces covered by the concurrent type
1295 -- (Ada 2005: AI-345).
1298 Make_Full_Type_Declaration (Loc,
1299 Defining_Identifier => Rec_Ent,
1300 Discriminant_Specifications => Dlist,
1302 Make_Record_Definition (Loc,
1304 Make_Component_List (Loc, Component_Items => Cdecls),
1306 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1307 Interface_List => Interface_List (N),
1308 Limited_Present => True));
1309 end Build_Corresponding_Record;
1311 ---------------------------------
1312 -- Build_Dispatching_Tag_Check --
1313 ---------------------------------
1315 function Build_Dispatching_Tag_Check
1317 N : Node_Id) return Node_Id
1319 Loc : constant Source_Ptr := Sloc (N);
1326 New_Occurrence_Of (K, Loc),
1328 New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc)),
1332 New_Occurrence_Of (K, Loc),
1334 New_Occurrence_Of (RTE (RE_TK_Tagged), Loc)));
1335 end Build_Dispatching_Tag_Check;
1337 ----------------------------------
1338 -- Build_Entry_Count_Expression --
1339 ----------------------------------
1341 function Build_Entry_Count_Expression
1342 (Concurrent_Type : Node_Id;
1343 Component_List : List_Id;
1344 Loc : Source_Ptr) return Node_Id
1356 -- Count number of non-family entries
1359 Ent := First_Entity (Concurrent_Type);
1360 while Present (Ent) loop
1361 if Ekind (Ent) = E_Entry then
1368 Ecount := Make_Integer_Literal (Loc, Eindx);
1370 -- Loop through entry families building the addition nodes
1372 Ent := First_Entity (Concurrent_Type);
1373 Comp := First (Component_List);
1374 while Present (Ent) loop
1375 if Ekind (Ent) = E_Entry_Family then
1376 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1380 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1381 Hi := Type_High_Bound (Typ);
1382 Lo := Type_Low_Bound (Typ);
1383 Large := Is_Potentially_Large_Family
1384 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1387 Left_Opnd => Ecount,
1389 Family_Size (Loc, Hi, Lo, Concurrent_Type, Large));
1396 end Build_Entry_Count_Expression;
1398 -----------------------
1399 -- Build_Entry_Names --
1400 -----------------------
1402 procedure Build_Entry_Names
1404 Obj_Typ : Entity_Id;
1407 Loc : constant Source_Ptr := Sloc (Obj_Ref);
1408 Data : Entity_Id := Empty;
1409 Index : Entity_Id := Empty;
1410 Typ : Entity_Id := Obj_Typ;
1412 procedure Build_Entry_Name (Comp_Id : Entity_Id);
1413 -- Given an entry [family], create a static string which denotes the
1414 -- name of Comp_Id and assign it to the underlying data structure which
1415 -- contains the entry names of a concurrent object.
1417 function Object_Reference return Node_Id;
1418 -- Return a reference to field _object or _task_id depending on the
1419 -- concurrent object being processed.
1421 ----------------------
1422 -- Build_Entry_Name --
1423 ----------------------
1425 procedure Build_Entry_Name (Comp_Id : Entity_Id) is
1426 function Build_Range (Def : Node_Id) return Node_Id;
1427 -- Given a discrete subtype definition of an entry family, generate a
1428 -- range node which covers the range of Def's type.
1430 procedure Create_Index_And_Data;
1431 -- Generate the declarations of variables Index and Data. Subsequent
1432 -- calls do nothing.
1434 function Increment_Index return Node_Id;
1435 -- Increment the index used in the assignment of string names to the
1438 function Name_Declaration (Def_Id : Entity_Id) return Node_Id;
1439 -- Given the name of a temporary variable, create the following
1440 -- declaration for it:
1442 -- Def_Id : aliased constant String := <String_Name_From_Buffer>;
1444 function Set_Entry_Name (Def_Id : Entity_Id) return Node_Id;
1445 -- Given the name of a temporary variable, place it in the array of
1446 -- string names. Generate:
1448 -- Data (Index) := Def_Id'Unchecked_Access;
1454 function Build_Range (Def : Node_Id) return Node_Id is
1455 High : Node_Id := Type_High_Bound (Etype (Def));
1456 Low : Node_Id := Type_Low_Bound (Etype (Def));
1459 -- If a bound references a discriminant, generate an identifier
1460 -- with the same name. Resolution will map it to the formals of
1463 if Is_Entity_Name (Low)
1464 and then Ekind (Entity (Low)) = E_Discriminant
1467 Make_Selected_Component (Loc,
1468 Prefix => New_Copy_Tree (Obj_Ref),
1469 Selector_Name => Make_Identifier (Loc, Chars (Low)));
1471 Low := New_Copy_Tree (Low);
1474 if Is_Entity_Name (High)
1475 and then Ekind (Entity (High)) = E_Discriminant
1478 Make_Selected_Component (Loc,
1479 Prefix => New_Copy_Tree (Obj_Ref),
1480 Selector_Name => Make_Identifier (Loc, Chars (High)));
1482 High := New_Copy_Tree (High);
1488 High_Bound => High);
1491 ---------------------------
1492 -- Create_Index_And_Data --
1493 ---------------------------
1495 procedure Create_Index_And_Data is
1497 if No (Index) and then No (Data) then
1504 if Is_Protected_Type (Typ) then
1505 Count := RO_PE_Number_Of_Entries;
1506 Data_Typ := RE_Protected_Entry_Names_Array;
1508 Count := RO_ST_Number_Of_Entries;
1509 Data_Typ := RE_Task_Entry_Names_Array;
1512 -- Step 1: Generate the declaration of the index variable:
1514 -- Index : Entry_Index := 1;
1516 Index := Make_Temporary (Loc, 'I');
1519 Make_Object_Declaration (Loc,
1520 Defining_Identifier => Index,
1521 Object_Definition =>
1522 New_Occurrence_Of (RTE (RE_Entry_Index), Loc),
1523 Expression => Make_Integer_Literal (Loc, 1)));
1525 -- Step 2: Generate the declaration of an array to house all
1528 -- Size : constant Entry_Index := <Count> (Obj_Ref);
1529 -- Data : aliased <Data_Typ> := (1 .. Size => null);
1531 Size := Make_Temporary (Loc, 'S');
1534 Make_Object_Declaration (Loc,
1535 Defining_Identifier => Size,
1536 Constant_Present => True,
1537 Object_Definition =>
1538 New_Occurrence_Of (RTE (RE_Entry_Index), Loc),
1540 Make_Function_Call (Loc,
1542 New_Occurrence_Of (RTE (Count), Loc),
1543 Parameter_Associations =>
1544 New_List (Object_Reference))));
1546 Data := Make_Temporary (Loc, 'A');
1549 Make_Object_Declaration (Loc,
1550 Defining_Identifier => Data,
1551 Aliased_Present => True,
1552 Object_Definition =>
1553 New_Occurrence_Of (RTE (Data_Typ), Loc),
1555 Make_Aggregate (Loc,
1556 Component_Associations => New_List (
1557 Make_Component_Association (Loc,
1558 Choices => New_List (
1561 Make_Integer_Literal (Loc, 1),
1563 New_Occurrence_Of (Size, Loc))),
1564 Expression => Make_Null (Loc))))));
1567 end Create_Index_And_Data;
1569 ---------------------
1570 -- Increment_Index --
1571 ---------------------
1573 function Increment_Index return Node_Id is
1576 Make_Assignment_Statement (Loc,
1577 Name => New_Occurrence_Of (Index, Loc),
1580 Left_Opnd => New_Occurrence_Of (Index, Loc),
1581 Right_Opnd => Make_Integer_Literal (Loc, 1)));
1582 end Increment_Index;
1584 ----------------------
1585 -- Name_Declaration --
1586 ----------------------
1588 function Name_Declaration (Def_Id : Entity_Id) return Node_Id is
1591 Make_Object_Declaration (Loc,
1592 Defining_Identifier => Def_Id,
1593 Aliased_Present => True,
1594 Constant_Present => True,
1595 Object_Definition =>
1596 New_Occurrence_Of (Standard_String, Loc),
1598 Make_String_Literal (Loc, String_From_Name_Buffer));
1599 end Name_Declaration;
1601 --------------------
1602 -- Set_Entry_Name --
1603 --------------------
1605 function Set_Entry_Name (Def_Id : Entity_Id) return Node_Id is
1608 Make_Assignment_Statement (Loc,
1610 Make_Indexed_Component (Loc,
1611 Prefix => New_Occurrence_Of (Data, Loc),
1612 Expressions => New_List (New_Occurrence_Of (Index, Loc))),
1615 Make_Attribute_Reference (Loc,
1616 Prefix => New_Occurrence_Of (Def_Id, Loc),
1617 Attribute_Name => Name_Unchecked_Access));
1622 Temp_Id : Entity_Id;
1625 -- Start of processing for Build_Entry_Name
1628 if Ekind (Comp_Id) = E_Entry_Family then
1629 Subt_Def := Discrete_Subtype_Definition (Parent (Comp_Id));
1631 Create_Index_And_Data;
1633 -- Step 1: Create the string name of the entry family.
1635 -- Temp : aliased constant String := "name ()";
1637 Temp_Id := Make_Temporary (Loc, 'S');
1638 Get_Name_String (Chars (Comp_Id));
1639 Add_Char_To_Name_Buffer (' ');
1640 Add_Char_To_Name_Buffer ('(');
1641 Add_Char_To_Name_Buffer (')');
1643 Append_To (Stmts, Name_Declaration (Temp_Id));
1646 -- for Member in Family_Low .. Family_High loop
1647 -- Set_Entry_Name (...);
1648 -- Index := Index + 1;
1652 Make_Loop_Statement (Loc,
1654 Make_Iteration_Scheme (Loc,
1655 Loop_Parameter_Specification =>
1656 Make_Loop_Parameter_Specification (Loc,
1657 Defining_Identifier =>
1658 Make_Temporary (Loc, 'L'),
1659 Discrete_Subtype_Definition =>
1660 Build_Range (Subt_Def))),
1662 Statements => New_List (
1663 Set_Entry_Name (Temp_Id),
1665 End_Label => Empty));
1670 Create_Index_And_Data;
1672 -- Step 1: Create the string name of the entry. Generate:
1673 -- Temp : aliased constant String := "name";
1675 Temp_Id := Make_Temporary (Loc, 'S');
1676 Get_Name_String (Chars (Comp_Id));
1678 Append_To (Stmts, Name_Declaration (Temp_Id));
1680 -- Step 2: Associate the string name with the underlying data
1683 Append_To (Stmts, Set_Entry_Name (Temp_Id));
1684 Append_To (Stmts, Increment_Index);
1686 end Build_Entry_Name;
1688 ----------------------
1689 -- Object_Reference --
1690 ----------------------
1692 function Object_Reference return Node_Id is
1693 Conc_Typ : constant Entity_Id := Corresponding_Record_Type (Typ);
1698 if Is_Protected_Type (Typ) then
1699 Field := Name_uObject;
1701 Field := Name_uTask_Id;
1705 Make_Selected_Component (Loc,
1707 Unchecked_Convert_To (Conc_Typ, New_Copy_Tree (Obj_Ref)),
1708 Selector_Name => Make_Identifier (Loc, Field));
1710 if Is_Protected_Type (Typ) then
1712 Make_Attribute_Reference (Loc,
1714 Attribute_Name => Name_Unchecked_Access);
1718 end Object_Reference;
1725 -- Start of processing for Build_Entry_Names
1728 -- Retrieve the original concurrent type
1730 if Is_Concurrent_Record_Type (Typ) then
1731 Typ := Corresponding_Concurrent_Type (Typ);
1734 pragma Assert (Is_Concurrent_Type (Typ));
1736 -- Nothing to do if the type has no entries
1738 if not Has_Entries (Typ) then
1742 -- Avoid generating entry names for a protected type with only one entry
1744 if Is_Protected_Type (Typ)
1745 and then Find_Protection_Type (Base_Type (Typ)) /=
1746 RTE (RE_Protection_Entries)
1751 -- Step 1: Populate the array with statically generated strings denoting
1752 -- entries and entry family names.
1754 Comp := First_Entity (Typ);
1755 while Present (Comp) loop
1756 if Comes_From_Source (Comp)
1757 and then Ekind_In (Comp, E_Entry, E_Entry_Family)
1759 Build_Entry_Name (Comp);
1765 -- Step 2: Associate the array with the related concurrent object:
1767 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1769 if Present (Data) then
1770 if Is_Protected_Type (Typ) then
1771 Proc := RO_PE_Set_Entry_Names;
1773 Proc := RO_ST_Set_Entry_Names;
1777 Make_Procedure_Call_Statement (Loc,
1778 Name => New_Occurrence_Of (RTE (Proc), Loc),
1779 Parameter_Associations => New_List (
1781 Make_Attribute_Reference (Loc,
1782 Prefix => New_Occurrence_Of (Data, Loc),
1783 Attribute_Name => Name_Unchecked_Access))));
1785 end Build_Entry_Names;
1787 ---------------------------
1788 -- Build_Parameter_Block --
1789 ---------------------------
1791 function Build_Parameter_Block
1795 Decls : List_Id) return Entity_Id
1801 Has_Comp : Boolean := False;
1805 Actual := First (Actuals);
1807 Formal := Defining_Identifier (First (Formals));
1809 while Present (Actual) loop
1810 if not Is_Controlling_Actual (Actual) then
1813 -- type Ann is access all <actual-type>
1815 Comp_Nam := Make_Temporary (Loc, 'A');
1816 Set_Is_Param_Block_Component_Type (Comp_Nam);
1819 Make_Full_Type_Declaration (Loc,
1820 Defining_Identifier => Comp_Nam,
1822 Make_Access_To_Object_Definition (Loc,
1823 All_Present => True,
1824 Constant_Present => Ekind (Formal) = E_In_Parameter,
1825 Subtype_Indication =>
1826 New_Occurrence_Of (Etype (Actual), Loc))));
1832 Make_Component_Declaration (Loc,
1833 Defining_Identifier =>
1834 Make_Defining_Identifier (Loc, Chars (Formal)),
1835 Component_Definition =>
1836 Make_Component_Definition (Loc,
1839 Subtype_Indication =>
1840 New_Occurrence_Of (Comp_Nam, Loc))));
1845 Next_Actual (Actual);
1846 Next_Formal_With_Extras (Formal);
1849 Rec_Nam := Make_Temporary (Loc, 'P');
1854 -- type Pnn is record
1859 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1860 -- the original parameter names and Ann1 .. AnnN are the access to
1864 Make_Full_Type_Declaration (Loc,
1865 Defining_Identifier =>
1868 Make_Record_Definition (Loc,
1870 Make_Component_List (Loc, Comps))));
1873 -- type Pnn is null record;
1876 Make_Full_Type_Declaration (Loc,
1877 Defining_Identifier =>
1880 Make_Record_Definition (Loc,
1881 Null_Present => True,
1882 Component_List => Empty)));
1886 end Build_Parameter_Block;
1888 --------------------------------------
1889 -- Build_Renamed_Formal_Declaration --
1890 --------------------------------------
1892 function Build_Renamed_Formal_Declaration
1896 Renamed_Formal : Node_Id) return Node_Id
1898 Loc : constant Source_Ptr := Sloc (New_F);
1902 -- If the formal is a tagged incomplete type, it is already passed
1903 -- by reference, so it is sufficient to rename the pointer component
1904 -- that corresponds to the actual. Otherwise we need to dereference
1905 -- the pointer component to obtain the actual.
1907 if Is_Incomplete_Type (Etype (Formal))
1908 and then Is_Tagged_Type (Etype (Formal))
1911 Make_Object_Renaming_Declaration (Loc,
1912 Defining_Identifier => New_F,
1913 Subtype_Mark => New_Occurrence_Of (Etype (Comp), Loc),
1914 Name => Renamed_Formal);
1918 Make_Object_Renaming_Declaration (Loc,
1919 Defining_Identifier => New_F,
1920 Subtype_Mark => New_Occurrence_Of (Etype (Formal), Loc),
1922 Make_Explicit_Dereference (Loc, Renamed_Formal));
1926 end Build_Renamed_Formal_Declaration;
1928 -----------------------
1929 -- Build_PPC_Wrapper --
1930 -----------------------
1932 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1933 Items : constant Node_Id := Contract (E);
1934 Loc : constant Source_Ptr := Sloc (E);
1935 Synch_Type : constant Entity_Id := Scope (E);
1938 Entry_Call : Node_Id;
1939 Entry_Name : Node_Id;
1942 Synch_Id : Entity_Id;
1943 Wrapper_Id : Entity_Id;
1946 -- Only build the wrapper if entry has pre/postconditions
1947 -- Should this be done unconditionally instead ???
1949 if Present (Items) then
1950 Prag := Pre_Post_Conditions (Items);
1956 -- Transfer ppc pragmas to the declarations of the wrapper
1960 while Present (Prag) loop
1961 if Nam_In (Pragma_Name (Prag), Name_Precondition,
1964 Append (Relocate_Node (Prag), Decls);
1965 Set_Analyzed (Last (Decls), False);
1968 Prag := Next_Pragma (Prag);
1974 Actuals := New_List;
1976 Make_Defining_Identifier (Loc,
1977 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1979 -- First formal is synchronized object
1981 Params := New_List (
1982 Make_Parameter_Specification (Loc,
1983 Defining_Identifier => Synch_Id,
1984 Out_Present => True,
1986 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1989 Make_Selected_Component (Loc,
1990 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1991 Selector_Name => New_Occurrence_Of (E, Loc));
1993 -- If entity is entry family, second formal is the corresponding index,
1994 -- and entry name is an indexed component.
1996 if Ekind (E) = E_Entry_Family then
1998 Index : constant Entity_Id :=
1999 Make_Defining_Identifier (Loc, Name_I);
2002 Make_Parameter_Specification (Loc,
2003 Defining_Identifier => Index,
2005 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
2008 Make_Indexed_Component (Loc,
2009 Prefix => Entry_Name,
2010 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
2015 Make_Procedure_Call_Statement (Loc,
2017 Parameter_Associations => Actuals);
2019 -- Now add formals that match those of the entry, and build actuals for
2020 -- the nested entry call.
2024 New_Form : Entity_Id;
2025 Parm_Spec : Node_Id;
2028 Form := First_Formal (E);
2029 while Present (Form) loop
2030 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
2032 Make_Parameter_Specification (Loc,
2033 Defining_Identifier => New_Form,
2034 Out_Present => Out_Present (Parent (Form)),
2035 In_Present => In_Present (Parent (Form)),
2036 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
2038 Append (Parm_Spec, Params);
2039 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
2044 -- Add renaming declarations for the discriminants of the enclosing
2045 -- type, which may be visible in the preconditions.
2047 if Has_Discriminants (Synch_Type) then
2053 D := First_Discriminant (Synch_Type);
2054 while Present (D) loop
2056 Make_Object_Renaming_Declaration (Loc,
2057 Defining_Identifier =>
2058 Make_Defining_Identifier (Loc, Chars (D)),
2059 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
2061 Make_Selected_Component (Loc,
2062 Prefix => New_Occurrence_Of (Synch_Id, Loc),
2063 Selector_Name => Make_Identifier (Loc, Chars (D))));
2064 Prepend (Decl, Decls);
2065 Next_Discriminant (D);
2071 Make_Defining_Identifier (Loc, New_External_Name (Chars (E), 'E'));
2072 Set_PPC_Wrapper (E, Wrapper_Id);
2074 -- The wrapper body is analyzed when the enclosing type is frozen
2076 Append_Freeze_Action (Defining_Entity (Decl),
2077 Make_Subprogram_Body (Loc,
2079 Make_Procedure_Specification (Loc,
2080 Defining_Unit_Name => Wrapper_Id,
2081 Parameter_Specifications => Params),
2082 Declarations => Decls,
2083 Handled_Statement_Sequence =>
2084 Make_Handled_Sequence_Of_Statements (Loc,
2085 Statements => New_List (Entry_Call))));
2086 end Build_PPC_Wrapper;
2088 --------------------------
2089 -- Build_Wrapper_Bodies --
2090 --------------------------
2092 procedure Build_Wrapper_Bodies
2097 Rec_Typ : Entity_Id;
2099 function Build_Wrapper_Body
2101 Subp_Id : Entity_Id;
2102 Obj_Typ : Entity_Id;
2103 Formals : List_Id) return Node_Id;
2104 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2105 -- associated with a protected or task type. Subp_Id is the subprogram
2106 -- name which will be wrapped. Obj_Typ is the type of the new formal
2107 -- parameter which handles dispatching and object notation. Formals are
2108 -- the original formals of Subp_Id which will be explicitly replicated.
2110 ------------------------
2111 -- Build_Wrapper_Body --
2112 ------------------------
2114 function Build_Wrapper_Body
2116 Subp_Id : Entity_Id;
2117 Obj_Typ : Entity_Id;
2118 Formals : List_Id) return Node_Id
2120 Body_Spec : Node_Id;
2123 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
2125 -- The subprogram is not overriding or is not a primitive declared
2126 -- between two views.
2128 if No (Body_Spec) then
2133 Actuals : List_Id := No_List;
2135 First_Form : Node_Id;
2140 -- Map formals to actuals. Use the list built for the wrapper
2141 -- spec, skipping the object notation parameter.
2143 First_Form := First (Parameter_Specifications (Body_Spec));
2145 Formal := First_Form;
2148 if Present (Formal) then
2149 Actuals := New_List;
2150 while Present (Formal) loop
2152 Make_Identifier (Loc,
2153 Chars => Chars (Defining_Identifier (Formal))));
2158 -- Special processing for primitives declared between a private
2159 -- type and its completion: the wrapper needs a properly typed
2160 -- parameter if the wrapped operation has a controlling first
2161 -- parameter. Note that this might not be the case for a function
2162 -- with a controlling result.
2164 if Is_Private_Primitive_Subprogram (Subp_Id) then
2165 if No (Actuals) then
2166 Actuals := New_List;
2169 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
2170 Prepend_To (Actuals,
2171 Unchecked_Convert_To
2172 (Corresponding_Concurrent_Type (Obj_Typ),
2173 Make_Identifier (Loc, Name_uO)));
2176 Prepend_To (Actuals,
2177 Make_Identifier (Loc,
2178 Chars => Chars (Defining_Identifier (First_Form))));
2181 Nam := New_Occurrence_Of (Subp_Id, Loc);
2183 -- An access-to-variable object parameter requires an explicit
2184 -- dereference in the unchecked conversion. This case occurs
2185 -- when a protected entry wrapper must override an interface
2186 -- level procedure with interface access as first parameter.
2188 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2190 if Nkind (Parameter_Type (First_Form)) =
2194 Make_Explicit_Dereference (Loc,
2195 Prefix => Make_Identifier (Loc, Name_uO));
2197 Conv_Id := Make_Identifier (Loc, Name_uO);
2201 Make_Selected_Component (Loc,
2203 Unchecked_Convert_To
2204 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
2205 Selector_Name => New_Occurrence_Of (Subp_Id, Loc));
2208 -- Create the subprogram body. For a function, the call to the
2209 -- actual subprogram has to be converted to the corresponding
2210 -- record if it is a controlling result.
2212 if Ekind (Subp_Id) = E_Function then
2218 Make_Function_Call (Loc,
2220 Parameter_Associations => Actuals);
2222 if Has_Controlling_Result (Subp_Id) then
2224 Unchecked_Convert_To
2225 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
2229 Make_Subprogram_Body (Loc,
2230 Specification => Body_Spec,
2231 Declarations => Empty_List,
2232 Handled_Statement_Sequence =>
2233 Make_Handled_Sequence_Of_Statements (Loc,
2234 Statements => New_List (
2235 Make_Simple_Return_Statement (Loc, Res))));
2240 Make_Subprogram_Body (Loc,
2241 Specification => Body_Spec,
2242 Declarations => Empty_List,
2243 Handled_Statement_Sequence =>
2244 Make_Handled_Sequence_Of_Statements (Loc,
2245 Statements => New_List (
2246 Make_Procedure_Call_Statement (Loc,
2248 Parameter_Associations => Actuals))));
2251 end Build_Wrapper_Body;
2253 -- Start of processing for Build_Wrapper_Bodies
2256 if Is_Concurrent_Type (Typ) then
2257 Rec_Typ := Corresponding_Record_Type (Typ);
2262 -- Generate wrapper bodies for a concurrent type which implements an
2265 if Present (Interfaces (Rec_Typ)) then
2267 Insert_Nod : Node_Id;
2269 Prim_Elmt : Elmt_Id;
2270 Prim_Decl : Node_Id;
2272 Wrap_Body : Node_Id;
2273 Wrap_Id : Entity_Id;
2278 -- Examine all primitive operations of the corresponding record
2279 -- type, looking for wrapper specs. Generate bodies in order to
2282 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
2283 while Present (Prim_Elmt) loop
2284 Prim := Node (Prim_Elmt);
2286 if (Ekind (Prim) = E_Function
2287 or else Ekind (Prim) = E_Procedure)
2288 and then Is_Primitive_Wrapper (Prim)
2290 Subp := Wrapped_Entity (Prim);
2291 Prim_Decl := Parent (Parent (Prim));
2294 Build_Wrapper_Body (Loc,
2297 Formals => Parameter_Specifications (Parent (Subp)));
2298 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2300 Set_Corresponding_Spec (Wrap_Body, Prim);
2301 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2303 Insert_After (Insert_Nod, Wrap_Body);
2304 Insert_Nod := Wrap_Body;
2306 Analyze (Wrap_Body);
2309 Next_Elmt (Prim_Elmt);
2313 end Build_Wrapper_Bodies;
2315 ------------------------
2316 -- Build_Wrapper_Spec --
2317 ------------------------
2319 function Build_Wrapper_Spec
2320 (Subp_Id : Entity_Id;
2321 Obj_Typ : Entity_Id;
2322 Formals : List_Id) return Node_Id
2324 Loc : constant Source_Ptr := Sloc (Subp_Id);
2325 First_Param : Node_Id;
2327 Iface_Elmt : Elmt_Id;
2328 Iface_Op : Entity_Id;
2329 Iface_Op_Elmt : Elmt_Id;
2331 function Overriding_Possible
2332 (Iface_Op : Entity_Id;
2333 Wrapper : Entity_Id) return Boolean;
2334 -- Determine whether a primitive operation can be overridden by Wrapper.
2335 -- Iface_Op is the candidate primitive operation of an interface type,
2336 -- Wrapper is the generated entry wrapper.
2338 function Replicate_Formals
2340 Formals : List_Id) return List_Id;
2341 -- An explicit parameter replication is required due to the Is_Entry_
2342 -- Formal flag being set for all the formals of an entry. The explicit
2343 -- replication removes the flag that would otherwise cause a different
2344 -- path of analysis.
2346 -------------------------
2347 -- Overriding_Possible --
2348 -------------------------
2350 function Overriding_Possible
2351 (Iface_Op : Entity_Id;
2352 Wrapper : Entity_Id) return Boolean
2354 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2355 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2357 function Type_Conformant_Parameters
2358 (Iface_Op_Params : List_Id;
2359 Wrapper_Params : List_Id) return Boolean;
2360 -- Determine whether the parameters of the generated entry wrapper
2361 -- and those of a primitive operation are type conformant. During
2362 -- this check, the first parameter of the primitive operation is
2363 -- skipped if it is a controlling argument: protected functions
2364 -- may have a controlling result.
2366 --------------------------------
2367 -- Type_Conformant_Parameters --
2368 --------------------------------
2370 function Type_Conformant_Parameters
2371 (Iface_Op_Params : List_Id;
2372 Wrapper_Params : List_Id) return Boolean
2374 Iface_Op_Param : Node_Id;
2375 Iface_Op_Typ : Entity_Id;
2376 Wrapper_Param : Node_Id;
2377 Wrapper_Typ : Entity_Id;
2380 -- Skip the first (controlling) parameter of primitive operation
2382 Iface_Op_Param := First (Iface_Op_Params);
2384 if Present (First_Formal (Iface_Op))
2385 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2387 Iface_Op_Param := Next (Iface_Op_Param);
2390 Wrapper_Param := First (Wrapper_Params);
2391 while Present (Iface_Op_Param)
2392 and then Present (Wrapper_Param)
2394 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2395 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2397 -- The two parameters must be mode conformant
2399 if not Conforming_Types
2400 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2405 Next (Iface_Op_Param);
2406 Next (Wrapper_Param);
2409 -- One of the lists is longer than the other
2411 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2416 end Type_Conformant_Parameters;
2418 -- Start of processing for Overriding_Possible
2421 if Chars (Iface_Op) /= Chars (Wrapper) then
2425 -- If an inherited subprogram is implemented by a protected procedure
2426 -- or an entry, then the first parameter of the inherited subprogram
2427 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2429 if Ekind (Iface_Op) = E_Procedure
2430 and then Present (Parameter_Specifications (Iface_Op_Spec))
2433 Obj_Param : constant Node_Id :=
2434 First (Parameter_Specifications (Iface_Op_Spec));
2436 if not Out_Present (Obj_Param)
2437 and then Nkind (Parameter_Type (Obj_Param)) /=
2446 Type_Conformant_Parameters (
2447 Parameter_Specifications (Iface_Op_Spec),
2448 Parameter_Specifications (Wrapper_Spec));
2449 end Overriding_Possible;
2451 -----------------------
2452 -- Replicate_Formals --
2453 -----------------------
2455 function Replicate_Formals
2457 Formals : List_Id) return List_Id
2459 New_Formals : constant List_Id := New_List;
2461 Param_Type : Node_Id;
2464 Formal := First (Formals);
2466 -- Skip the object parameter when dealing with primitives declared
2467 -- between two views.
2469 if Is_Private_Primitive_Subprogram (Subp_Id)
2470 and then not Has_Controlling_Result (Subp_Id)
2472 Formal := Next (Formal);
2475 while Present (Formal) loop
2477 -- Create an explicit copy of the entry parameter
2479 -- When creating the wrapper subprogram for a primitive operation
2480 -- of a protected interface we must construct an equivalent
2481 -- signature to that of the overriding operation. For regular
2482 -- parameters we can just use the type of the formal, but for
2483 -- access to subprogram parameters we need to reanalyze the
2484 -- parameter type to create local entities for the signature of
2485 -- the subprogram type. Using the entities of the overriding
2486 -- subprogram will result in out-of-scope errors in the back-end.
2488 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2489 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2492 New_Occurrence_Of (Etype (Parameter_Type (Formal)), Loc);
2495 Append_To (New_Formals,
2496 Make_Parameter_Specification (Loc,
2497 Defining_Identifier =>
2498 Make_Defining_Identifier (Loc,
2500 (Defining_Identifier (Formal))),
2501 In_Present => In_Present (Formal),
2502 Out_Present => Out_Present (Formal),
2503 Null_Exclusion_Present => Null_Exclusion_Present (Formal),
2504 Parameter_Type => Param_Type));
2510 end Replicate_Formals;
2512 -- Start of processing for Build_Wrapper_Spec
2515 -- No point in building wrappers for untagged concurrent types
2517 pragma Assert (Is_Tagged_Type (Obj_Typ));
2519 -- An entry or a protected procedure can override a routine where the
2520 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2521 -- type. Since the wrapper must have the exact same signature as that of
2522 -- the overridden subprogram, we try to find the overriding candidate
2523 -- and use its controlling formal.
2525 First_Param := Empty;
2527 -- Check every implemented interface
2529 if Present (Interfaces (Obj_Typ)) then
2530 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2531 Search : while Present (Iface_Elmt) loop
2532 Iface := Node (Iface_Elmt);
2534 -- Check every interface primitive
2536 if Present (Primitive_Operations (Iface)) then
2537 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2538 while Present (Iface_Op_Elmt) loop
2539 Iface_Op := Node (Iface_Op_Elmt);
2541 -- Ignore predefined primitives
2543 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2544 Iface_Op := Ultimate_Alias (Iface_Op);
2546 -- The current primitive operation can be overridden by
2547 -- the generated entry wrapper.
2549 if Overriding_Possible (Iface_Op, Subp_Id) then
2551 First (Parameter_Specifications (Parent (Iface_Op)));
2557 Next_Elmt (Iface_Op_Elmt);
2561 Next_Elmt (Iface_Elmt);
2565 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2566 -- this subprogram and this is not a primitive declared between two
2567 -- views then force the generation of a wrapper. As an optimization,
2568 -- previous versions of the frontend avoid generating the wrapper;
2569 -- however, the wrapper facilitates locating and reporting an error
2570 -- when a duplicate declaration is found later. See example in
2574 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2577 (Corresponding_Concurrent_Type (Obj_Typ))
2580 Make_Parameter_Specification (Loc,
2581 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2583 Out_Present => False,
2584 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2586 -- For entries and procedures of protected types the mode of
2587 -- the controlling argument must be in-out.
2591 Make_Parameter_Specification (Loc,
2592 Defining_Identifier =>
2593 Make_Defining_Identifier (Loc,
2596 Out_Present => (Ekind (Subp_Id) /= E_Function),
2597 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2602 Wrapper_Id : constant Entity_Id :=
2603 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2604 New_Formals : List_Id;
2605 Obj_Param : Node_Id;
2606 Obj_Param_Typ : Entity_Id;
2609 -- Minimum decoration is needed to catch the entity in
2610 -- Sem_Ch6.Override_Dispatching_Operation.
2612 if Ekind (Subp_Id) = E_Function then
2613 Set_Ekind (Wrapper_Id, E_Function);
2615 Set_Ekind (Wrapper_Id, E_Procedure);
2618 Set_Is_Primitive_Wrapper (Wrapper_Id);
2619 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2620 Set_Is_Private_Primitive (Wrapper_Id,
2621 Is_Private_Primitive_Subprogram (Subp_Id));
2623 -- Process the formals
2625 New_Formals := Replicate_Formals (Loc, Formals);
2627 -- A function with a controlling result and no first controlling
2628 -- formal needs no additional parameter.
2630 if Has_Controlling_Result (Subp_Id)
2632 (No (First_Formal (Subp_Id))
2633 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2637 -- Routine Subp_Id has been found to override an interface primitive.
2638 -- If the interface operation has an access parameter, create a copy
2639 -- of it, with the same null exclusion indicator if present.
2641 elsif Present (First_Param) then
2642 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2644 Make_Access_Definition (Loc,
2646 New_Occurrence_Of (Obj_Typ, Loc),
2647 Null_Exclusion_Present =>
2648 Null_Exclusion_Present (Parameter_Type (First_Param)),
2650 Constant_Present (Parameter_Type (First_Param)));
2652 Obj_Param_Typ := New_Occurrence_Of (Obj_Typ, Loc);
2656 Make_Parameter_Specification (Loc,
2657 Defining_Identifier =>
2658 Make_Defining_Identifier (Loc,
2660 In_Present => In_Present (First_Param),
2661 Out_Present => Out_Present (First_Param),
2662 Parameter_Type => Obj_Param_Typ);
2664 Prepend_To (New_Formals, Obj_Param);
2666 -- If we are dealing with a primitive declared between two views,
2667 -- implemented by a synchronized operation, we need to create
2668 -- a default parameter. The mode of the parameter must match that
2669 -- of the primitive operation.
2672 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2674 Make_Parameter_Specification (Loc,
2675 Defining_Identifier =>
2676 Make_Defining_Identifier (Loc, Name_uO),
2677 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2678 Out_Present => Ekind (Subp_Id) /= E_Function,
2679 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2680 Prepend_To (New_Formals, Obj_Param);
2683 -- Build the final spec. If it is a function with a controlling
2684 -- result, it is a primitive operation of the corresponding
2685 -- record type, so mark the spec accordingly.
2687 if Ekind (Subp_Id) = E_Function then
2692 if Has_Controlling_Result (Subp_Id) then
2695 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2697 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2701 Make_Function_Specification (Loc,
2702 Defining_Unit_Name => Wrapper_Id,
2703 Parameter_Specifications => New_Formals,
2704 Result_Definition => Res_Def);
2708 Make_Procedure_Specification (Loc,
2709 Defining_Unit_Name => Wrapper_Id,
2710 Parameter_Specifications => New_Formals);
2713 end Build_Wrapper_Spec;
2715 -------------------------
2716 -- Build_Wrapper_Specs --
2717 -------------------------
2719 procedure Build_Wrapper_Specs
2725 Rec_Typ : Entity_Id;
2726 procedure Scan_Declarations (L : List_Id);
2727 -- Common processing for visible and private declarations
2728 -- of a protected type.
2730 procedure Scan_Declarations (L : List_Id) is
2732 Wrap_Decl : Node_Id;
2733 Wrap_Spec : Node_Id;
2741 while Present (Decl) loop
2744 if Nkind (Decl) = N_Entry_Declaration
2745 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2749 (Subp_Id => Defining_Identifier (Decl),
2751 Formals => Parameter_Specifications (Decl));
2753 elsif Nkind (Decl) = N_Subprogram_Declaration then
2756 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2759 Parameter_Specifications (Specification (Decl)));
2762 if Present (Wrap_Spec) then
2764 Make_Subprogram_Declaration (Loc,
2765 Specification => Wrap_Spec);
2767 Insert_After (N, Wrap_Decl);
2770 Analyze (Wrap_Decl);
2775 end Scan_Declarations;
2777 -- start of processing for Build_Wrapper_Specs
2780 if Is_Protected_Type (Typ) then
2781 Def := Protected_Definition (Parent (Typ));
2782 else pragma Assert (Is_Task_Type (Typ));
2783 Def := Task_Definition (Parent (Typ));
2786 Rec_Typ := Corresponding_Record_Type (Typ);
2788 -- Generate wrapper specs for a concurrent type which implements an
2789 -- interface. Operations in both the visible and private parts may
2790 -- implement progenitor operations.
2792 if Present (Interfaces (Rec_Typ)) and then Present (Def) then
2793 Scan_Declarations (Visible_Declarations (Def));
2794 Scan_Declarations (Private_Declarations (Def));
2796 end Build_Wrapper_Specs;
2798 ---------------------------
2799 -- Build_Find_Body_Index --
2800 ---------------------------
2802 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2803 Loc : constant Source_Ptr := Sloc (Typ);
2806 Has_F : Boolean := False;
2808 If_St : Node_Id := Empty;
2811 Decls : List_Id := New_List;
2814 Siz : Node_Id := Empty;
2816 procedure Add_If_Clause (Expr : Node_Id);
2817 -- Add test for range of current entry
2819 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2820 -- If a bound of an entry is given by a discriminant, retrieve the
2821 -- actual value of the discriminant from the enclosing object.
2827 procedure Add_If_Clause (Expr : Node_Id) is
2829 Stats : constant List_Id :=
2831 Make_Simple_Return_Statement (Loc,
2832 Expression => Make_Integer_Literal (Loc, Index + 1)));
2835 -- Index for current entry body
2839 -- Compute total length of entry queues so far
2847 Right_Opnd => Expr);
2852 Left_Opnd => Make_Identifier (Loc, Name_uE),
2855 -- Map entry queue indexes in the range of the current family
2856 -- into the current index, that designates the entry body.
2860 Make_Implicit_If_Statement (Typ,
2862 Then_Statements => Stats,
2863 Elsif_Parts => New_List);
2867 Append_To (Elsif_Parts (If_St),
2868 Make_Elsif_Part (Loc,
2870 Then_Statements => Stats));
2874 ------------------------------
2875 -- Convert_Discriminant_Ref --
2876 ------------------------------
2878 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2882 if Is_Entity_Name (Bound)
2883 and then Ekind (Entity (Bound)) = E_Discriminant
2886 Make_Selected_Component (Loc,
2888 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2889 Make_Explicit_Dereference (Loc,
2890 Make_Identifier (Loc, Name_uObject))),
2891 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2892 Set_Etype (B, Etype (Entity (Bound)));
2894 B := New_Copy_Tree (Bound);
2898 end Convert_Discriminant_Ref;
2900 -- Start of processing for Build_Find_Body_Index
2903 Spec := Build_Find_Body_Index_Spec (Typ);
2905 Ent := First_Entity (Typ);
2906 while Present (Ent) loop
2907 if Ekind (Ent) = E_Entry_Family then
2917 -- If the protected type has no entry families, there is a one-one
2918 -- correspondence between entry queue and entry body.
2921 Make_Simple_Return_Statement (Loc,
2922 Expression => Make_Identifier (Loc, Name_uE));
2925 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2928 -- if E <= l1 then return 1;
2929 -- elsif E <= l1 + l2 then return 2;
2934 Ent := First_Entity (Typ);
2936 Add_Object_Pointer (Loc, Typ, Decls);
2938 while Present (Ent) loop
2939 if Ekind (Ent) = E_Entry then
2940 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2942 elsif Ekind (Ent) = E_Entry_Family then
2943 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2944 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2945 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2946 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2955 Make_Simple_Return_Statement (Loc,
2956 Expression => Make_Integer_Literal (Loc, 1));
2958 elsif Nkind (Ret) = N_If_Statement then
2960 -- Ranges are in increasing order, so last one doesn't need guard
2963 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2966 Set_Else_Statements (Ret, Then_Statements (Nod));
2972 Make_Subprogram_Body (Loc,
2973 Specification => Spec,
2974 Declarations => Decls,
2975 Handled_Statement_Sequence =>
2976 Make_Handled_Sequence_Of_Statements (Loc,
2977 Statements => New_List (Ret)));
2978 end Build_Find_Body_Index;
2980 --------------------------------
2981 -- Build_Find_Body_Index_Spec --
2982 --------------------------------
2984 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2985 Loc : constant Source_Ptr := Sloc (Typ);
2986 Id : constant Entity_Id :=
2987 Make_Defining_Identifier (Loc,
2988 Chars => New_External_Name (Chars (Typ), 'F'));
2989 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2990 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2994 Make_Function_Specification (Loc,
2995 Defining_Unit_Name => Id,
2996 Parameter_Specifications => New_List (
2997 Make_Parameter_Specification (Loc,
2998 Defining_Identifier => Parm1,
3000 New_Occurrence_Of (RTE (RE_Address), Loc)),
3002 Make_Parameter_Specification (Loc,
3003 Defining_Identifier => Parm2,
3005 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
3007 Result_Definition => New_Occurrence_Of (
3008 RTE (RE_Protected_Entry_Index), Loc));
3009 end Build_Find_Body_Index_Spec;
3011 -----------------------------------------------
3012 -- Build_Lock_Free_Protected_Subprogram_Body --
3013 -----------------------------------------------
3015 function Build_Lock_Free_Protected_Subprogram_Body
3018 Unprot_Spec : Node_Id) return Node_Id
3020 Actuals : constant List_Id := New_List;
3021 Loc : constant Source_Ptr := Sloc (N);
3022 Spec : constant Node_Id := Specification (N);
3023 Unprot_Id : constant Entity_Id := Defining_Unit_Name (Unprot_Spec);
3025 Prot_Spec : Node_Id;
3029 -- Create the protected version of the body
3032 Build_Protected_Sub_Specification (N, Prot_Typ, Protected_Mode);
3034 -- Build the actual parameters which appear in the call to the
3035 -- unprotected version of the body.
3037 Formal := First (Parameter_Specifications (Prot_Spec));
3038 while Present (Formal) loop
3040 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
3045 -- Function case, generate:
3046 -- return <Unprot_Func_Call>;
3048 if Nkind (Spec) = N_Function_Specification then
3050 Make_Simple_Return_Statement (Loc,
3052 Make_Function_Call (Loc,
3054 Make_Identifier (Loc, Chars (Unprot_Id)),
3055 Parameter_Associations => Actuals));
3057 -- Procedure case, call the unprotected version
3061 Make_Procedure_Call_Statement (Loc,
3063 Make_Identifier (Loc, Chars (Unprot_Id)),
3064 Parameter_Associations => Actuals);
3068 Make_Subprogram_Body (Loc,
3069 Declarations => Empty_List,
3070 Specification => Prot_Spec,
3071 Handled_Statement_Sequence =>
3072 Make_Handled_Sequence_Of_Statements (Loc,
3073 Statements => New_List (Stmt)));
3074 end Build_Lock_Free_Protected_Subprogram_Body;
3076 -------------------------------------------------
3077 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3078 -------------------------------------------------
3080 -- Procedures which meet the lock-free implementation requirements and
3081 -- reference a unique scalar component Comp are expanded in the following
3084 -- procedure P (...) is
3085 -- Expected_Comp : constant Comp_Type :=
3087 -- (System.Atomic_Primitives.Lock_Free_Read_N
3088 -- (_Object.Comp'Address));
3092 -- <original declarations before the object renaming declaration
3095 -- Desired_Comp : Comp_Type := Expected_Comp;
3096 -- Comp : Comp_Type renames Desired_Comp;
3098 -- <original delarations after the object renaming declaration
3102 -- <original statements>
3103 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3104 -- (_Object.Comp'Address,
3105 -- Interfaces.Unsigned_N (Expected_Comp),
3106 -- Interfaces.Unsigned_N (Desired_Comp));
3111 -- Each return and raise statement of P is transformed into an atomic
3114 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3115 -- (_Object.Comp'Address,
3116 -- Interfaces.Unsigned_N (Expected_Comp),
3117 -- Interfaces.Unsigned_N (Desired_Comp));
3119 -- <original statement>
3124 -- Functions which meet the lock-free implementation requirements and
3125 -- reference a unique scalar component Comp are expanded in the following
3128 -- function F (...) return ... is
3129 -- <original declarations before the object renaming declaration
3132 -- Expected_Comp : constant Comp_Type :=
3134 -- (System.Atomic_Primitives.Lock_Free_Read_N
3135 -- (_Object.Comp'Address));
3136 -- Comp : Comp_Type renames Expected_Comp;
3138 -- <original delarations after the object renaming declaration of
3142 -- <original statements>
3145 function Build_Lock_Free_Unprotected_Subprogram_Body
3147 Prot_Typ : Node_Id) return Node_Id
3149 function Referenced_Component (N : Node_Id) return Entity_Id;
3150 -- Subprograms which meet the lock-free implementation criteria are
3151 -- allowed to reference only one unique component. Return the prival
3152 -- of the said component.
3154 --------------------------
3155 -- Referenced_Component --
3156 --------------------------
3158 function Referenced_Component (N : Node_Id) return Entity_Id is
3161 Source_Comp : Entity_Id := Empty;
3164 -- Find the unique source component which N references in its
3167 for Index in 1 .. Lock_Free_Subprogram_Table.Last loop
3169 Element : Lock_Free_Subprogram renames
3170 Lock_Free_Subprogram_Table.Table (Index);
3172 if Element.Sub_Body = N then
3173 Source_Comp := Element.Comp_Id;
3179 if No (Source_Comp) then
3183 -- Find the prival which corresponds to the source component within
3184 -- the declarations of N.
3186 Decl := First (Declarations (N));
3187 while Present (Decl) loop
3189 -- Privals appear as object renamings
3191 if Nkind (Decl) = N_Object_Renaming_Declaration then
3192 Comp := Defining_Identifier (Decl);
3194 if Present (Prival_Link (Comp))
3195 and then Prival_Link (Comp) = Source_Comp
3205 end Referenced_Component;
3209 Comp : constant Entity_Id := Referenced_Component (N);
3210 Loc : constant Source_Ptr := Sloc (N);
3211 Hand_Stmt_Seq : Node_Id := Handled_Statement_Sequence (N);
3212 Decls : List_Id := Declarations (N);
3214 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3217 -- Add renamings for the protection object, discriminals, privals and
3218 -- the entry index constant for use by debugger.
3220 Debug_Private_Data_Declarations (Decls);
3222 -- Perform the lock-free expansion when the subprogram references a
3223 -- protected component.
3225 if Present (Comp) then
3226 Protected_Component_Ref : declare
3227 Comp_Decl : constant Node_Id := Parent (Comp);
3228 Comp_Sel_Nam : constant Node_Id := Name (Comp_Decl);
3229 Comp_Type : constant Entity_Id := Etype (Comp);
3231 Is_Procedure : constant Boolean :=
3232 Ekind (Corresponding_Spec (N)) = E_Procedure;
3233 -- Indicates if N is a protected procedure body
3235 Block_Decls : List_Id;
3236 Try_Write : Entity_Id;
3237 Desired_Comp : Entity_Id;
3240 Label_Id : Entity_Id := Empty;
3242 Expected_Comp : Entity_Id;
3245 New_Copy_List (Statements (Hand_Stmt_Seq));
3247 Unsigned : Entity_Id;
3249 function Process_Node (N : Node_Id) return Traverse_Result;
3250 -- Transform a single node if it is a return statement, a raise
3251 -- statement or a reference to Comp.
3253 procedure Process_Stmts (Stmts : List_Id);
3254 -- Given a statement sequence Stmts, wrap any return or raise
3255 -- statements in the following manner:
3257 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3258 -- (_Object.Comp'Address,
3259 -- Interfaces.Unsigned_N (Expected_Comp),
3260 -- Interfaces.Unsigned_N (Desired_Comp))
3271 function Process_Node (N : Node_Id) return Traverse_Result is
3273 procedure Wrap_Statement (Stmt : Node_Id);
3274 -- Wrap an arbitrary statement inside an if statement where the
3275 -- condition does an atomic check on the state of the object.
3277 --------------------
3278 -- Wrap_Statement --
3279 --------------------
3281 procedure Wrap_Statement (Stmt : Node_Id) is
3283 -- The first time through, create the declaration of a label
3284 -- which is used to skip the remainder of source statements
3285 -- if the state of the object has changed.
3287 if No (Label_Id) then
3289 Make_Identifier (Loc, New_External_Name ('L', 0));
3290 Set_Entity (Label_Id,
3291 Make_Defining_Identifier (Loc, Chars (Label_Id)));
3295 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3296 -- (_Object.Comp'Address,
3297 -- Interfaces.Unsigned_N (Expected_Comp),
3298 -- Interfaces.Unsigned_N (Desired_Comp))
3306 Make_Implicit_If_Statement (N,
3308 Make_Function_Call (Loc,
3310 New_Occurrence_Of (Try_Write, Loc),
3311 Parameter_Associations => New_List (
3312 Make_Attribute_Reference (Loc,
3313 Prefix => Relocate_Node (Comp_Sel_Nam),
3314 Attribute_Name => Name_Address),
3316 Unchecked_Convert_To (Unsigned,
3317 New_Occurrence_Of (Expected_Comp, Loc)),
3319 Unchecked_Convert_To (Unsigned,
3320 New_Occurrence_Of (Desired_Comp, Loc)))),
3322 Then_Statements => New_List (Relocate_Node (Stmt)),
3324 Else_Statements => New_List (
3325 Make_Goto_Statement (Loc,
3327 New_Occurrence_Of (Entity (Label_Id), Loc)))));
3330 -- Start of processing for Process_Node
3333 -- Wrap each return and raise statement that appear inside a
3334 -- procedure. Skip the last return statement which is added by
3335 -- default since it is transformed into an exit statement.
3338 and then ((Nkind (N) = N_Simple_Return_Statement
3339 and then N /= Last (Stmts))
3340 or else Nkind (N) = N_Extended_Return_Statement
3341 or else (Nkind_In (N, N_Raise_Constraint_Error,
3342 N_Raise_Program_Error,
3344 N_Raise_Storage_Error)
3345 and then Comes_From_Source (N)))
3353 Set_Analyzed (N, False);
3358 procedure Process_Nodes is new Traverse_Proc (Process_Node);
3364 procedure Process_Stmts (Stmts : List_Id) is
3367 Stmt := First (Stmts);
3368 while Present (Stmt) loop
3369 Process_Nodes (Stmt);
3374 -- Start of processing for Protected_Component_Ref
3377 -- Get the type size
3379 if Known_Static_Esize (Comp_Type) then
3380 Typ_Size := UI_To_Int (Esize (Comp_Type));
3382 -- If the Esize (Object_Size) is unknown at compile time, look at
3383 -- the RM_Size (Value_Size) since it may have been set by an
3384 -- explicit representation clause.
3386 elsif Known_Static_RM_Size (Comp_Type) then
3387 Typ_Size := UI_To_Int (RM_Size (Comp_Type));
3389 -- Should not happen since this has already been checked in
3390 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3393 raise Program_Error;
3396 -- Retrieve all relevant atomic routines and types
3400 Try_Write := RTE (RE_Lock_Free_Try_Write_8);
3401 Read := RTE (RE_Lock_Free_Read_8);
3402 Unsigned := RTE (RE_Uint8);
3405 Try_Write := RTE (RE_Lock_Free_Try_Write_16);
3406 Read := RTE (RE_Lock_Free_Read_16);
3407 Unsigned := RTE (RE_Uint16);
3410 Try_Write := RTE (RE_Lock_Free_Try_Write_32);
3411 Read := RTE (RE_Lock_Free_Read_32);
3412 Unsigned := RTE (RE_Uint32);
3415 Try_Write := RTE (RE_Lock_Free_Try_Write_64);
3416 Read := RTE (RE_Lock_Free_Read_64);
3417 Unsigned := RTE (RE_Uint64);
3420 raise Program_Error;
3424 -- Expected_Comp : constant Comp_Type :=
3426 -- (System.Atomic_Primitives.Lock_Free_Read_N
3427 -- (_Object.Comp'Address));
3430 Make_Defining_Identifier (Loc,
3431 New_External_Name (Chars (Comp), Suffix => "_saved"));
3434 Make_Object_Declaration (Loc,
3435 Defining_Identifier => Expected_Comp,
3436 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3437 Constant_Present => True,
3439 Unchecked_Convert_To (Comp_Type,
3440 Make_Function_Call (Loc,
3441 Name => New_Occurrence_Of (Read, Loc),
3442 Parameter_Associations => New_List (
3443 Make_Attribute_Reference (Loc,
3444 Prefix => Relocate_Node (Comp_Sel_Nam),
3445 Attribute_Name => Name_Address)))));
3447 -- Protected procedures
3449 if Is_Procedure then
3450 -- Move the original declarations inside the generated block
3452 Block_Decls := Decls;
3454 -- Reset the declarations list of the protected procedure to
3455 -- contain only Decl.
3457 Decls := New_List (Decl);
3460 -- Desired_Comp : Comp_Type := Expected_Comp;
3463 Make_Defining_Identifier (Loc,
3464 New_External_Name (Chars (Comp), Suffix => "_current"));
3466 -- Insert the declarations of Expected_Comp and Desired_Comp in
3467 -- the block declarations right before the renaming of the
3468 -- protected component.
3470 Insert_Before (Comp_Decl,
3471 Make_Object_Declaration (Loc,
3472 Defining_Identifier => Desired_Comp,
3473 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3475 New_Occurrence_Of (Expected_Comp, Loc)));
3477 -- Protected function
3480 Desired_Comp := Expected_Comp;
3482 -- Insert the declaration of Expected_Comp in the function
3483 -- declarations right before the renaming of the protected
3486 Insert_Before (Comp_Decl, Decl);
3489 -- Rewrite the protected component renaming declaration to be a
3490 -- renaming of Desired_Comp.
3493 -- Comp : Comp_Type renames Desired_Comp;
3496 Make_Object_Renaming_Declaration (Loc,
3497 Defining_Identifier =>
3498 Defining_Identifier (Comp_Decl),
3500 New_Occurrence_Of (Comp_Type, Loc),
3502 New_Occurrence_Of (Desired_Comp, Loc)));
3504 -- Wrap any return or raise statements in Stmts in same the manner
3505 -- described in Process_Stmts.
3507 Process_Stmts (Stmts);
3510 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3511 -- (_Object.Comp'Address,
3512 -- Interfaces.Unsigned_N (Expected_Comp),
3513 -- Interfaces.Unsigned_N (Desired_Comp))
3515 if Is_Procedure then
3517 Make_Exit_Statement (Loc,
3519 Make_Function_Call (Loc,
3521 New_Occurrence_Of (Try_Write, Loc),
3522 Parameter_Associations => New_List (
3523 Make_Attribute_Reference (Loc,
3524 Prefix => Relocate_Node (Comp_Sel_Nam),
3525 Attribute_Name => Name_Address),
3527 Unchecked_Convert_To (Unsigned,
3528 New_Occurrence_Of (Expected_Comp, Loc)),
3530 Unchecked_Convert_To (Unsigned,
3531 New_Occurrence_Of (Desired_Comp, Loc)))));
3533 -- Small optimization: transform the default return statement
3534 -- of a procedure into the atomic exit statement.
3536 if Nkind (Last (Stmts)) = N_Simple_Return_Statement then
3537 Rewrite (Last (Stmts), Stmt);
3539 Append_To (Stmts, Stmt);
3543 -- Create the declaration of the label used to skip the rest of
3544 -- the source statements when the object state changes.
3546 if Present (Label_Id) then
3547 Label := Make_Label (Loc, Label_Id);
3549 Make_Implicit_Label_Declaration (Loc,
3550 Defining_Identifier => Entity (Label_Id),
3551 Label_Construct => Label));
3552 Append_To (Stmts, Label);
3564 if Is_Procedure then
3567 Make_Loop_Statement (Loc,
3568 Statements => New_List (
3569 Make_Block_Statement (Loc,
3570 Declarations => Block_Decls,
3571 Handled_Statement_Sequence =>
3572 Make_Handled_Sequence_Of_Statements (Loc,
3573 Statements => Stmts))),
3574 End_Label => Empty));
3578 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts);
3579 end Protected_Component_Ref;
3582 -- Make an unprotected version of the subprogram for use within the same
3583 -- object, with new name and extra parameter representing the object.
3586 Make_Subprogram_Body (Loc,
3588 Build_Protected_Sub_Specification (N, Prot_Typ, Unprotected_Mode),
3589 Declarations => Decls,
3590 Handled_Statement_Sequence => Hand_Stmt_Seq);
3591 end Build_Lock_Free_Unprotected_Subprogram_Body;
3593 -------------------------
3594 -- Build_Master_Entity --
3595 -------------------------
3597 procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
3598 Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
3600 Context_Id : Entity_Id;
3606 if Is_Itype (Obj_Or_Typ) then
3607 Par := Associated_Node_For_Itype (Obj_Or_Typ);
3609 Par := Parent (Obj_Or_Typ);
3612 -- When creating a master for a record component which is either a task
3613 -- or access-to-task, the enclosing record is the master scope and the
3614 -- proper insertion point is the component list.
3616 if Is_Record_Type (Current_Scope) then
3618 Context_Id := Current_Scope;
3619 Decls := List_Containing (Context);
3621 -- Default case for object declarations and access types. Note that the
3622 -- context is updated to the nearest enclosing body, block, package or
3623 -- return statement.
3626 Find_Enclosing_Context (Par, Context, Context_Id, Decls);
3629 -- Do not create a master if one already exists or there is no task
3632 if Has_Master_Entity (Context_Id)
3633 or else Restriction_Active (No_Task_Hierarchy)
3638 -- Create a master, generate:
3639 -- _Master : constant Master_Id := Current_Master.all;
3642 Make_Object_Declaration (Loc,
3643 Defining_Identifier =>
3644 Make_Defining_Identifier (Loc, Name_uMaster),
3645 Constant_Present => True,
3646 Object_Definition => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3648 Make_Explicit_Dereference (Loc,
3649 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
3651 -- The master is inserted at the start of the declarative list of the
3654 Prepend_To (Decls, Decl);
3656 -- In certain cases where transient scopes are involved, the immediate
3657 -- scope is not always the proper master scope. Ensure that the master
3658 -- declaration and entity appear in the same context.
3660 if Context_Id /= Current_Scope then
3661 Push_Scope (Context_Id);
3668 -- Mark the enclosing scope and its associated construct as being task
3671 Set_Has_Master_Entity (Context_Id);
3673 while Present (Context)
3674 and then Nkind (Context) /= N_Compilation_Unit
3676 if Nkind_In (Context, N_Block_Statement,
3680 Set_Is_Task_Master (Context);
3683 elsif Nkind (Parent (Context)) = N_Subunit then
3684 Context := Corresponding_Stub (Parent (Context));
3687 Context := Parent (Context);
3689 end Build_Master_Entity;
3691 ---------------------------
3692 -- Build_Master_Renaming --
3693 ---------------------------
3695 procedure Build_Master_Renaming
3696 (Ptr_Typ : Entity_Id;
3697 Ins_Nod : Node_Id := Empty)
3699 Loc : constant Source_Ptr := Sloc (Ptr_Typ);
3701 Master_Decl : Node_Id;
3702 Master_Id : Entity_Id;
3705 -- Nothing to do if there is no task hierarchy
3707 if Restriction_Active (No_Task_Hierarchy) then
3711 -- Determine the proper context to insert the master renaming
3713 if Present (Ins_Nod) then
3715 elsif Is_Itype (Ptr_Typ) then
3716 Context := Associated_Node_For_Itype (Ptr_Typ);
3718 Context := Parent (Ptr_Typ);
3722 -- <Ptr_Typ>M : Master_Id renames _Master;
3725 Make_Defining_Identifier (Loc,
3726 New_External_Name (Chars (Ptr_Typ), 'M'));
3729 Make_Object_Renaming_Declaration (Loc,
3730 Defining_Identifier => Master_Id,
3731 Subtype_Mark => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3732 Name => Make_Identifier (Loc, Name_uMaster));
3734 Insert_Action (Context, Master_Decl);
3736 -- The renamed master now services the access type
3738 Set_Master_Id (Ptr_Typ, Master_Id);
3739 end Build_Master_Renaming;
3741 -----------------------------------------
3742 -- Build_Private_Protected_Declaration --
3743 -----------------------------------------
3745 function Build_Private_Protected_Declaration
3746 (N : Node_Id) return Entity_Id
3748 Loc : constant Source_Ptr := Sloc (N);
3749 Body_Id : constant Entity_Id := Defining_Entity (N);
3754 Spec_Id : Entity_Id;
3757 Formal := First_Formal (Body_Id);
3759 -- The protected operation always has at least one formal, namely the
3760 -- object itself, but it is only placed in the parameter list if
3761 -- expansion is enabled.
3763 if Present (Formal) or else Expander_Active then
3764 Plist := Copy_Parameter_List (Body_Id);
3769 if Nkind (Specification (N)) = N_Procedure_Specification then
3771 Make_Procedure_Specification (Loc,
3772 Defining_Unit_Name =>
3773 Make_Defining_Identifier (Sloc (Body_Id),
3774 Chars => Chars (Body_Id)),
3775 Parameter_Specifications =>
3779 Make_Function_Specification (Loc,
3780 Defining_Unit_Name =>
3781 Make_Defining_Identifier (Sloc (Body_Id),
3782 Chars => Chars (Body_Id)),
3783 Parameter_Specifications => Plist,
3784 Result_Definition =>
3785 New_Occurrence_Of (Etype (Body_Id), Loc));
3788 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
3789 Insert_Before (N, Decl);
3790 Spec_Id := Defining_Unit_Name (New_Spec);
3792 -- Indicate that the entity comes from source, to ensure that cross-
3793 -- reference information is properly generated. The body itself is
3794 -- rewritten during expansion, and the body entity will not appear in
3795 -- calls to the operation.
3797 Set_Comes_From_Source (Spec_Id, True);
3799 Set_Has_Completion (Spec_Id);
3800 Set_Convention (Spec_Id, Convention_Protected);
3802 end Build_Private_Protected_Declaration;
3804 ---------------------------
3805 -- Build_Protected_Entry --
3806 ---------------------------
3808 function Build_Protected_Entry
3811 Pid : Node_Id) return Node_Id
3813 Loc : constant Source_Ptr := Sloc (N);
3815 Decls : constant List_Id := Declarations (N);
3816 End_Lab : constant Node_Id :=
3817 End_Label (Handled_Statement_Sequence (N));
3818 End_Loc : constant Source_Ptr :=
3819 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
3820 -- Used for the generated call to Complete_Entry_Body
3822 Han_Loc : Source_Ptr;
3823 -- Used for the exception handler, inserted at end of the body
3825 Op_Decls : constant List_Id := New_List;
3833 -- Set the source location on the exception handler only when debugging
3834 -- the expanded code (see Make_Implicit_Exception_Handler).
3836 if Debug_Generated_Code then
3839 -- Otherwise the inserted code should not be visible to the debugger
3842 Han_Loc := No_Location;
3846 Make_Defining_Identifier (Loc,
3847 Chars => Chars (Protected_Body_Subprogram (Ent)));
3849 Build_Protected_Entry_Specification (Loc, Edef, Empty);
3851 -- Add the following declarations:
3853 -- type poVP is access poV;
3854 -- _object : poVP := poVP (_O);
3856 -- where _O is the formal parameter associated with the concurrent
3857 -- object. These declarations are needed for Complete_Entry_Body.
3859 Add_Object_Pointer (Loc, Pid, Op_Decls);
3861 -- Add renamings for all formals, the Protection object, discriminals,
3862 -- privals and the entry index constant for use by debugger.
3864 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
3865 Debug_Private_Data_Declarations (Decls);
3867 -- Put the declarations and the statements from the entry
3871 Make_Block_Statement (Loc,
3872 Declarations => Decls,
3873 Handled_Statement_Sequence =>
3874 Handled_Statement_Sequence (N)));
3876 case Corresponding_Runtime_Package (Pid) is
3877 when System_Tasking_Protected_Objects_Entries =>
3878 Append_To (Op_Stats,
3879 Make_Procedure_Call_Statement (End_Loc,
3881 New_Occurrence_Of (RTE (RE_Complete_Entry_Body), Loc),
3882 Parameter_Associations => New_List (
3883 Make_Attribute_Reference (End_Loc,
3885 Make_Selected_Component (End_Loc,
3887 Make_Identifier (End_Loc, Name_uObject),
3889 Make_Identifier (End_Loc, Name_uObject)),
3890 Attribute_Name => Name_Unchecked_Access))));
3892 when System_Tasking_Protected_Objects_Single_Entry =>
3894 -- Historically, a call to Complete_Single_Entry_Body was
3895 -- inserted, but it was a null procedure.
3900 raise Program_Error;
3903 -- When exceptions can not be propagated, we never need to call
3904 -- Exception_Complete_Entry_Body
3906 if No_Exception_Handlers_Set then
3908 Make_Subprogram_Body (Loc,
3909 Specification => Espec,
3910 Declarations => Op_Decls,
3911 Handled_Statement_Sequence =>
3912 Make_Handled_Sequence_Of_Statements (Loc,
3913 Statements => Op_Stats,
3914 End_Label => End_Lab));
3917 Ohandle := Make_Others_Choice (Loc);
3918 Set_All_Others (Ohandle);
3920 case Corresponding_Runtime_Package (Pid) is
3921 when System_Tasking_Protected_Objects_Entries =>
3924 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
3926 when System_Tasking_Protected_Objects_Single_Entry =>
3929 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
3932 raise Program_Error;
3935 -- Establish link between subprogram body entity and source entry
3937 Set_Corresponding_Protected_Entry (Edef, Ent);
3939 -- Create body of entry procedure. The renaming declarations are
3940 -- placed ahead of the block that contains the actual entry body.
3943 Make_Subprogram_Body (Loc,
3944 Specification => Espec,
3945 Declarations => Op_Decls,
3946 Handled_Statement_Sequence =>
3947 Make_Handled_Sequence_Of_Statements (Loc,
3948 Statements => Op_Stats,
3949 End_Label => End_Lab,
3950 Exception_Handlers => New_List (
3951 Make_Implicit_Exception_Handler (Han_Loc,
3952 Exception_Choices => New_List (Ohandle),
3954 Statements => New_List (
3955 Make_Procedure_Call_Statement (Han_Loc,
3957 Parameter_Associations => New_List (
3958 Make_Attribute_Reference (Han_Loc,
3960 Make_Selected_Component (Han_Loc,
3962 Make_Identifier (Han_Loc, Name_uObject),
3964 Make_Identifier (Han_Loc, Name_uObject)),
3965 Attribute_Name => Name_Unchecked_Access),
3967 Make_Function_Call (Han_Loc,
3968 Name => New_Occurrence_Of (
3969 RTE (RE_Get_GNAT_Exception), Loc)))))))));
3971 end Build_Protected_Entry;
3973 -----------------------------------------
3974 -- Build_Protected_Entry_Specification --
3975 -----------------------------------------
3977 function Build_Protected_Entry_Specification
3980 Ent_Id : Entity_Id) return Node_Id
3982 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3985 Set_Debug_Info_Needed (Def_Id);
3987 if Present (Ent_Id) then
3988 Append_Elmt (P, Accept_Address (Ent_Id));
3992 Make_Procedure_Specification (Loc,
3993 Defining_Unit_Name => Def_Id,
3994 Parameter_Specifications => New_List (
3995 Make_Parameter_Specification (Loc,
3996 Defining_Identifier =>
3997 Make_Defining_Identifier (Loc, Name_uO),
3999 New_Occurrence_Of (RTE (RE_Address), Loc)),
4001 Make_Parameter_Specification (Loc,
4002 Defining_Identifier => P,
4004 New_Occurrence_Of (RTE (RE_Address), Loc)),
4006 Make_Parameter_Specification (Loc,
4007 Defining_Identifier =>
4008 Make_Defining_Identifier (Loc, Name_uE),
4010 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))));
4011 end Build_Protected_Entry_Specification;
4013 --------------------------
4014 -- Build_Protected_Spec --
4015 --------------------------
4017 function Build_Protected_Spec
4019 Obj_Type : Entity_Id;
4021 Unprotected : Boolean := False) return List_Id
4023 Loc : constant Source_Ptr := Sloc (N);
4026 New_Plist : List_Id;
4027 New_Param : Node_Id;
4030 New_Plist := New_List;
4032 Formal := First_Formal (Ident);
4033 while Present (Formal) loop
4035 Make_Parameter_Specification (Loc,
4036 Defining_Identifier =>
4037 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4038 Aliased_Present => Aliased_Present (Parent (Formal)),
4039 In_Present => In_Present (Parent (Formal)),
4040 Out_Present => Out_Present (Parent (Formal)),
4041 Parameter_Type => New_Occurrence_Of (Etype (Formal), Loc));
4044 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
4047 Append (New_Param, New_Plist);
4048 Next_Formal (Formal);
4051 -- If the subprogram is a procedure and the context is not an access
4052 -- to protected subprogram, the parameter is in-out. Otherwise it is
4056 Make_Parameter_Specification (Loc,
4057 Defining_Identifier =>
4058 Make_Defining_Identifier (Loc, Name_uObject),
4061 (Etype (Ident) = Standard_Void_Type
4062 and then not Is_RTE (Obj_Type, RE_Address)),
4064 New_Occurrence_Of (Obj_Type, Loc));
4065 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4066 Prepend_To (New_Plist, Decl);
4069 end Build_Protected_Spec;
4071 ---------------------------------------
4072 -- Build_Protected_Sub_Specification --
4073 ---------------------------------------
4075 function Build_Protected_Sub_Specification
4077 Prot_Typ : Entity_Id;
4078 Mode : Subprogram_Protection_Mode) return Node_Id
4080 Loc : constant Source_Ptr := Sloc (N);
4084 New_Plist : List_Id;
4087 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
4088 (Dispatching_Mode => ' ',
4089 Protected_Mode => 'P',
4090 Unprotected_Mode => 'N');
4093 if Ekind (Defining_Unit_Name (Specification (N))) =
4096 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
4101 Def_Id := Defining_Unit_Name (Specification (Decl));
4104 Build_Protected_Spec
4105 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
4106 Mode = Unprotected_Mode);
4108 Make_Defining_Identifier (Loc,
4109 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
4111 -- The unprotected operation carries the user code, and debugging
4112 -- information must be generated for it, even though this spec does
4113 -- not come from source. It is also convenient to allow gdb to step
4114 -- into the protected operation, even though it only contains lock/
4117 Set_Debug_Info_Needed (New_Id);
4119 -- If a pragma Eliminate applies to the source entity, the internal
4120 -- subprograms will be eliminated as well.
4122 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
4124 if Nkind (Specification (Decl)) = N_Procedure_Specification then
4126 Make_Procedure_Specification (Loc,
4127 Defining_Unit_Name => New_Id,
4128 Parameter_Specifications => New_Plist);
4130 -- Create a new specification for the anonymous subprogram type
4134 Make_Function_Specification (Loc,
4135 Defining_Unit_Name => New_Id,
4136 Parameter_Specifications => New_Plist,
4137 Result_Definition =>
4138 Copy_Result_Type (Result_Definition (Specification (Decl))));
4140 Set_Return_Present (Defining_Unit_Name (New_Spec));
4144 end Build_Protected_Sub_Specification;
4146 -------------------------------------
4147 -- Build_Protected_Subprogram_Body --
4148 -------------------------------------
4150 function Build_Protected_Subprogram_Body
4153 N_Op_Spec : Node_Id) return Node_Id
4155 Loc : constant Source_Ptr := Sloc (N);
4157 P_Op_Spec : Node_Id;
4160 Unprot_Call : Node_Id;
4162 Lock_Name : Node_Id;
4163 Lock_Stmt : Node_Id;
4165 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
4166 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
4168 Object_Parm : Node_Id;
4173 Op_Spec := Specification (N);
4174 Exc_Safe := Is_Exception_Safe (N);
4177 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
4179 -- Build a list of the formal parameters of the protected version of
4180 -- the subprogram to use as the actual parameters of the unprotected
4183 Uactuals := New_List;
4184 Pformal := First (Parameter_Specifications (P_Op_Spec));
4185 while Present (Pformal) loop
4186 Append_To (Uactuals,
4187 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
4191 -- Make a call to the unprotected version of the subprogram built above
4192 -- for use by the protected version built below.
4194 if Nkind (Op_Spec) = N_Function_Specification then
4196 R := Make_Temporary (Loc, 'R');
4198 Make_Object_Declaration (Loc,
4199 Defining_Identifier => R,
4200 Constant_Present => True,
4201 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
4203 Make_Function_Call (Loc,
4204 Name => Make_Identifier (Loc,
4205 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
4206 Parameter_Associations => Uactuals));
4209 Make_Simple_Return_Statement (Loc,
4210 Expression => New_Occurrence_Of (R, Loc));
4213 Unprot_Call := Make_Simple_Return_Statement (Loc,
4214 Expression => Make_Function_Call (Loc,
4216 Make_Identifier (Loc,
4217 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
4218 Parameter_Associations => Uactuals));
4221 Lock_Kind := RE_Lock_Read_Only;
4225 Make_Procedure_Call_Statement (Loc,
4227 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
4228 Parameter_Associations => Uactuals);
4230 Lock_Kind := RE_Lock;
4233 -- Wrap call in block that will be covered by an at_end handler
4235 if not Exc_Safe then
4236 Unprot_Call := Make_Block_Statement (Loc,
4237 Handled_Statement_Sequence =>
4238 Make_Handled_Sequence_Of_Statements (Loc,
4239 Statements => New_List (Unprot_Call)));
4242 -- Make the protected subprogram body. This locks the protected
4243 -- object and calls the unprotected version of the subprogram.
4245 case Corresponding_Runtime_Package (Pid) is
4246 when System_Tasking_Protected_Objects_Entries =>
4247 Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entries), Loc);
4249 when System_Tasking_Protected_Objects_Single_Entry =>
4250 Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entry), Loc);
4252 when System_Tasking_Protected_Objects =>
4253 Lock_Name := New_Occurrence_Of (RTE (Lock_Kind), Loc);
4256 raise Program_Error;
4260 Make_Attribute_Reference (Loc,
4262 Make_Selected_Component (Loc,
4263 Prefix => Make_Identifier (Loc, Name_uObject),
4264 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4265 Attribute_Name => Name_Unchecked_Access);
4267 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
4269 Parameter_Associations => New_List (Object_Parm));
4271 if Abort_Allowed then
4273 Make_Procedure_Call_Statement (Loc,
4274 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
4275 Parameter_Associations => Empty_List),
4279 Stmts := New_List (Lock_Stmt);
4282 if not Exc_Safe then
4283 Append (Unprot_Call, Stmts);
4285 if Nkind (Op_Spec) = N_Function_Specification then
4287 Stmts := Empty_List;
4289 Append (Unprot_Call, Stmts);
4292 -- Historical note: Previously, call to the cleanup was inserted
4293 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4294 -- which is also shared by the 'not Exc_Safe' path.
4296 Build_Protected_Subprogram_Call_Cleanup (Op_Spec, Pid, Loc, Stmts);
4298 if Nkind (Op_Spec) = N_Function_Specification then
4299 Append (Return_Stmt, Stmts);
4300 Append (Make_Block_Statement (Loc,
4301 Declarations => New_List (Unprot_Call),
4302 Handled_Statement_Sequence =>
4303 Make_Handled_Sequence_Of_Statements (Loc,
4304 Statements => Stmts)), Pre_Stmts);
4310 Make_Subprogram_Body (Loc,
4311 Declarations => Empty_List,
4312 Specification => P_Op_Spec,
4313 Handled_Statement_Sequence =>
4314 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
4316 -- Mark this subprogram as a protected subprogram body so that the
4317 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4318 -- path as otherwise the cleanup has already been inserted.
4320 if not Exc_Safe then
4321 Set_Is_Protected_Subprogram_Body (Sub_Body);
4325 end Build_Protected_Subprogram_Body;
4327 -------------------------------------
4328 -- Build_Protected_Subprogram_Call --
4329 -------------------------------------
4331 procedure Build_Protected_Subprogram_Call
4335 External : Boolean := True)
4337 Loc : constant Source_Ptr := Sloc (N);
4338 Sub : constant Entity_Id := Entity (Name);
4344 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
4347 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
4350 if Present (Parameter_Associations (N)) then
4351 Params := New_Copy_List_Tree (Parameter_Associations (N));
4356 -- If the type is an untagged derived type, convert to the root type,
4357 -- which is the one on which the operations are defined.
4359 if Nkind (Rec) = N_Unchecked_Type_Conversion
4360 and then not Is_Tagged_Type (Etype (Rec))
4361 and then Is_Derived_Type (Etype (Rec))
4363 Set_Etype (Rec, Root_Type (Etype (Rec)));
4364 Set_Subtype_Mark (Rec,
4365 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
4368 Prepend (Rec, Params);
4370 if Ekind (Sub) = E_Procedure then
4372 Make_Procedure_Call_Statement (Loc,
4374 Parameter_Associations => Params));
4377 pragma Assert (Ekind (Sub) = E_Function);
4379 Make_Function_Call (Loc,
4381 Parameter_Associations => Params));
4383 -- Preserve type of call for subsequent processing (required for
4384 -- call to Wrap_Transient_Expression in the case of a shared passive
4387 Set_Etype (N, Etype (New_Sub));
4391 and then Nkind (Rec) = N_Unchecked_Type_Conversion
4392 and then Is_Entity_Name (Expression (Rec))
4393 and then Is_Shared_Passive (Entity (Expression (Rec)))
4395 Add_Shared_Var_Lock_Procs (N);
4397 end Build_Protected_Subprogram_Call;
4399 ---------------------------------------------
4400 -- Build_Protected_Subprogram_Call_Cleanup --
4401 ---------------------------------------------
4403 procedure Build_Protected_Subprogram_Call_Cleanup
4412 -- If the associated protected object has entries, a protected
4413 -- procedure has to service entry queues. In this case generate:
4415 -- Service_Entries (_object._object'Access);
4417 if Nkind (Op_Spec) = N_Procedure_Specification
4418 and then Has_Entries (Conc_Typ)
4420 case Corresponding_Runtime_Package (Conc_Typ) is
4421 when System_Tasking_Protected_Objects_Entries =>
4422 Nam := New_Occurrence_Of (RTE (RE_Service_Entries), Loc);
4424 when System_Tasking_Protected_Objects_Single_Entry =>
4425 Nam := New_Occurrence_Of (RTE (RE_Service_Entry), Loc);
4428 raise Program_Error;
4432 Make_Procedure_Call_Statement (Loc,
4434 Parameter_Associations => New_List (
4435 Make_Attribute_Reference (Loc,
4437 Make_Selected_Component (Loc,
4438 Prefix => Make_Identifier (Loc, Name_uObject),
4439 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4440 Attribute_Name => Name_Unchecked_Access))));
4444 -- Unlock (_object._object'Access);
4446 case Corresponding_Runtime_Package (Conc_Typ) is
4447 when System_Tasking_Protected_Objects_Entries =>
4448 Nam := New_Occurrence_Of (RTE (RE_Unlock_Entries), Loc);
4450 when System_Tasking_Protected_Objects_Single_Entry =>
4451 Nam := New_Occurrence_Of (RTE (RE_Unlock_Entry), Loc);
4453 when System_Tasking_Protected_Objects =>
4454 Nam := New_Occurrence_Of (RTE (RE_Unlock), Loc);
4457 raise Program_Error;
4461 Make_Procedure_Call_Statement (Loc,
4463 Parameter_Associations => New_List (
4464 Make_Attribute_Reference (Loc,
4466 Make_Selected_Component (Loc,
4467 Prefix => Make_Identifier (Loc, Name_uObject),
4468 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4469 Attribute_Name => Name_Unchecked_Access))));
4475 if Abort_Allowed then
4477 Make_Procedure_Call_Statement (Loc,
4479 New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
4480 Parameter_Associations => Empty_List));
4482 end Build_Protected_Subprogram_Call_Cleanup;
4484 -------------------------
4485 -- Build_Selected_Name --
4486 -------------------------
4488 function Build_Selected_Name
4489 (Prefix : Entity_Id;
4490 Selector : Entity_Id;
4491 Append_Char : Character := ' ') return Name_Id
4493 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
4494 Select_Len : Natural;
4497 Get_Name_String (Chars (Selector));
4498 Select_Len := Name_Len;
4499 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
4500 Get_Name_String (Chars (Prefix));
4502 -- If scope is anonymous type, discard suffix to recover name of
4503 -- single protected object. Otherwise use protected type name.
4505 if Name_Buffer (Name_Len) = 'T' then
4506 Name_Len := Name_Len - 1;
4509 Add_Str_To_Name_Buffer ("__");
4510 for J in 1 .. Select_Len loop
4511 Add_Char_To_Name_Buffer (Select_Buffer (J));
4514 -- Now add the Append_Char if specified. The encoding to follow
4515 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4516 -- then the entity is associated to a protected type subprogram.
4517 -- Otherwise, it is a protected type entry. For each case, the
4518 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4520 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4522 if Append_Char /= ' ' then
4523 if Append_Char = 'P' or Append_Char = 'N' then
4524 Add_Char_To_Name_Buffer (Append_Char);
4527 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
4528 return New_External_Name (Name_Find, ' ', -1);
4533 end Build_Selected_Name;
4535 -----------------------------
4536 -- Build_Simple_Entry_Call --
4537 -----------------------------
4539 -- A task entry call is converted to a call to Call_Simple
4542 -- P : parms := (parm, parm, parm);
4544 -- Call_Simple (acceptor-task, entry-index, P'Address);
4550 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4551 -- the parameters, and the constructed aggregate value contains either the
4552 -- parameters or, in the case of non-elementary types, references to these
4553 -- parameters. Then the address of this aggregate is passed to the runtime
4554 -- routine, along with the task id value and the task entry index value.
4555 -- Pnn is only required if parameters are present.
4557 -- The assignments after the call are present only in the case of in-out
4558 -- or out parameters for elementary types, and are used to assign back the
4559 -- resulting values of such parameters.
4561 -- Note: the reason that we insert a block here is that in the context
4562 -- of selects, conditional entry calls etc. the entry call statement
4563 -- appears on its own, not as an element of a list.
4565 -- A protected entry call is converted to a Protected_Entry_Call:
4568 -- P : E1_Params := (param, param, param);
4570 -- Bnn : Communications_Block;
4573 -- P : E1_Params := (param, param, param);
4574 -- Bnn : Communications_Block;
4577 -- Protected_Entry_Call (
4578 -- Object => po._object'Access,
4579 -- E => <entry index>;
4580 -- Uninterpreted_Data => P'Address;
4581 -- Mode => Simple_Call;
4588 procedure Build_Simple_Entry_Call
4597 -- If call has been inlined, nothing left to do
4599 if Nkind (N) = N_Block_Statement then
4603 -- Convert entry call to Call_Simple call
4606 Loc : constant Source_Ptr := Sloc (N);
4607 Parms : constant List_Id := Parameter_Associations (N);
4608 Stats : constant List_Id := New_List;
4611 Comm_Name : Entity_Id;
4615 Ent_Acc : Entity_Id;
4617 Iface_Tag : Entity_Id;
4618 Iface_Typ : Entity_Id;
4631 -- Simple entry and entry family cases merge here
4633 Ent := Entity (Ename);
4634 Ent_Acc := Entry_Parameters_Type (Ent);
4635 Conctyp := Etype (Concval);
4637 -- If prefix is an access type, dereference to obtain the task type
4639 if Is_Access_Type (Conctyp) then
4640 Conctyp := Designated_Type (Conctyp);
4643 -- Special case for protected subprogram calls
4645 if Is_Protected_Type (Conctyp)
4646 and then Is_Subprogram (Entity (Ename))
4648 if not Is_Eliminated (Entity (Ename)) then
4649 Build_Protected_Subprogram_Call
4650 (N, Ename, Convert_Concurrent (Concval, Conctyp));
4657 -- First parameter is the Task_Id value from the task value or the
4658 -- Object from the protected object value, obtained by selecting
4659 -- the _Task_Id or _Object from the result of doing an unchecked
4660 -- conversion to convert the value to the corresponding record type.
4662 if Nkind (Concval) = N_Function_Call
4663 and then Is_Task_Type (Conctyp)
4664 and then Ada_Version >= Ada_2005
4667 ExpR : constant Node_Id := Relocate_Node (Concval);
4668 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
4673 Make_Object_Declaration (Loc,
4674 Defining_Identifier => Obj,
4675 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
4676 Expression => ExpR);
4677 Set_Etype (Obj, Conctyp);
4678 Decls := New_List (Decl);
4679 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
4686 Parm1 := Concurrent_Ref (Concval);
4688 -- Second parameter is the entry index, computed by the routine
4689 -- provided for this purpose. The value of this expression is
4690 -- assigned to an intermediate variable to assure that any entry
4691 -- family index expressions are evaluated before the entry
4694 if not Is_Protected_Type (Conctyp)
4696 Corresponding_Runtime_Package (Conctyp) =
4697 System_Tasking_Protected_Objects_Entries
4699 X := Make_Defining_Identifier (Loc, Name_uX);
4702 Make_Object_Declaration (Loc,
4703 Defining_Identifier => X,
4704 Object_Definition =>
4705 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
4706 Expression => Actual_Index_Expression (
4707 Loc, Entity (Ename), Index, Concval));
4709 Append_To (Decls, Xdecl);
4710 Parm2 := New_Occurrence_Of (X, Loc);
4717 -- The third parameter is the packaged parameters. If there are
4718 -- none, then it is just the null address, since nothing is passed.
4721 Parm3 := New_Occurrence_Of (RTE (RE_Null_Address), Loc);
4724 -- Case of parameters present, where third argument is the address
4725 -- of a packaged record containing the required parameter values.
4728 -- First build a list of parameter values, which are references to
4729 -- objects of the parameter types.
4733 Actual := First_Actual (N);
4734 Formal := First_Formal (Ent);
4735 while Present (Actual) loop
4737 -- If it is a by-copy type, copy it to a new variable. The
4738 -- packaged record has a field that points to this variable.
4740 if Is_By_Copy_Type (Etype (Actual)) then
4742 Make_Object_Declaration (Loc,
4743 Defining_Identifier => Make_Temporary (Loc, 'J'),
4744 Aliased_Present => True,
4745 Object_Definition =>
4746 New_Occurrence_Of (Etype (Formal), Loc));
4748 -- Mark the object as not needing initialization since the
4749 -- initialization is performed separately, avoiding errors
4750 -- on cases such as formals of null-excluding access types.
4752 Set_No_Initialization (N_Node);
4754 -- We must make a separate assignment statement for the
4755 -- case of limited types. We cannot assign it unless the
4756 -- Assignment_OK flag is set first. An out formal of an
4757 -- access type or whose type has a Default_Value must also
4758 -- be initialized from the actual (see RM 6.4.1 (13-13.1)),
4759 -- but no constraint, predicate, or null-exclusion check is
4760 -- applied before the call.
4762 if Ekind (Formal) /= E_Out_Parameter
4763 or else Is_Access_Type (Etype (Formal))
4765 (Is_Scalar_Type (Etype (Formal))
4767 Present (Default_Aspect_Value (Etype (Formal))))
4770 New_Occurrence_Of (Defining_Identifier (N_Node), Loc);
4771 Set_Assignment_OK (N_Var);
4773 Make_Assignment_Statement (Loc,
4775 Expression => Relocate_Node (Actual)));
4777 -- Mark the object as internal, so we don't later reset
4778 -- No_Initialization flag in Default_Initialize_Object,
4779 -- which would lead to needless default initialization.
4780 -- We don't set this outside the if statement, because
4781 -- out scalar parameters without Default_Value do require
4782 -- default initialization if Initialize_Scalars applies.
4784 Set_Is_Internal (Defining_Identifier (N_Node));
4786 -- If actual is an out parameter of a null-excluding
4787 -- access type, there is access check on entry, so set
4788 -- Suppress_Assignment_Checks on the generated statement
4789 -- that assigns the actual to the parameter block
4791 Set_Suppress_Assignment_Checks (Last (Stats));
4794 Append (N_Node, Decls);
4797 Make_Attribute_Reference (Loc,
4798 Attribute_Name => Name_Unchecked_Access,
4801 (Defining_Identifier (N_Node), Loc)));
4804 -- Interface class-wide formal
4806 if Ada_Version >= Ada_2005
4807 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
4808 and then Is_Interface (Etype (Formal))
4810 Iface_Typ := Etype (Etype (Formal));
4813 -- formal_iface_type! (actual.iface_tag)'reference
4816 Find_Interface_Tag (Etype (Actual), Iface_Typ);
4817 pragma Assert (Present (Iface_Tag));
4820 Make_Reference (Loc,
4821 Unchecked_Convert_To (Iface_Typ,
4822 Make_Selected_Component (Loc,
4824 Relocate_Node (Actual),
4826 New_Occurrence_Of (Iface_Tag, Loc)))));
4832 Make_Reference (Loc, Relocate_Node (Actual)));
4836 Next_Actual (Actual);
4837 Next_Formal_With_Extras (Formal);
4840 -- Now build the declaration of parameters initialized with the
4841 -- aggregate containing this constructed parameter list.
4843 P := Make_Defining_Identifier (Loc, Name_uP);
4846 Make_Object_Declaration (Loc,
4847 Defining_Identifier => P,
4848 Object_Definition =>
4849 New_Occurrence_Of (Designated_Type (Ent_Acc), Loc),
4851 Make_Aggregate (Loc, Expressions => Plist));
4854 Make_Attribute_Reference (Loc,
4855 Prefix => New_Occurrence_Of (P, Loc),
4856 Attribute_Name => Name_Address);
4858 Append (Pdecl, Decls);
4861 -- Now we can create the call, case of protected type
4863 if Is_Protected_Type (Conctyp) then
4864 case Corresponding_Runtime_Package (Conctyp) is
4865 when System_Tasking_Protected_Objects_Entries =>
4867 -- Change the type of the index declaration
4869 Set_Object_Definition (Xdecl,
4870 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc));
4872 -- Some additional declarations for protected entry calls
4878 -- Bnn : Communications_Block;
4880 Comm_Name := Make_Temporary (Loc, 'B');
4883 Make_Object_Declaration (Loc,
4884 Defining_Identifier => Comm_Name,
4885 Object_Definition =>
4887 (RTE (RE_Communication_Block), Loc)));
4889 -- Some additional statements for protected entry calls
4891 -- Protected_Entry_Call (
4892 -- Object => po._object'Access,
4893 -- E => <entry index>;
4894 -- Uninterpreted_Data => P'Address;
4895 -- Mode => Simple_Call;
4899 Make_Procedure_Call_Statement (Loc,
4901 New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
4903 Parameter_Associations => New_List (
4904 Make_Attribute_Reference (Loc,
4905 Attribute_Name => Name_Unchecked_Access,
4909 New_Occurrence_Of (RTE (RE_Simple_Call), Loc),
4910 New_Occurrence_Of (Comm_Name, Loc)));
4912 when System_Tasking_Protected_Objects_Single_Entry =>
4913 -- Protected_Single_Entry_Call (
4914 -- Object => po._object'Access,
4915 -- Uninterpreted_Data => P'Address);
4918 Make_Procedure_Call_Statement (Loc,
4921 (RTE (RE_Protected_Single_Entry_Call), Loc),
4923 Parameter_Associations => New_List (
4924 Make_Attribute_Reference (Loc,
4925 Attribute_Name => Name_Unchecked_Access,
4930 raise Program_Error;
4933 -- Case of task type
4937 Make_Procedure_Call_Statement (Loc,
4939 New_Occurrence_Of (RTE (RE_Call_Simple), Loc),
4940 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
4944 Append_To (Stats, Call);
4946 -- If there are out or in/out parameters by copy add assignment
4947 -- statements for the result values.
4949 if Present (Parms) then
4950 Actual := First_Actual (N);
4951 Formal := First_Formal (Ent);
4953 Set_Assignment_OK (Actual);
4954 while Present (Actual) loop
4955 if Is_By_Copy_Type (Etype (Actual))
4956 and then Ekind (Formal) /= E_In_Parameter
4959 Make_Assignment_Statement (Loc,
4960 Name => New_Copy (Actual),
4962 Make_Explicit_Dereference (Loc,
4963 Make_Selected_Component (Loc,
4964 Prefix => New_Occurrence_Of (P, Loc),
4966 Make_Identifier (Loc, Chars (Formal)))));
4968 -- In all cases (including limited private types) we want
4969 -- the assignment to be valid.
4971 Set_Assignment_OK (Name (N_Node));
4973 -- If the call is the triggering alternative in an
4974 -- asynchronous select, or the entry_call alternative of a
4975 -- conditional entry call, the assignments for in-out
4976 -- parameters are incorporated into the statement list that
4977 -- follows, so that there are executed only if the entry
4980 if (Nkind (Parent (N)) = N_Triggering_Alternative
4981 and then N = Triggering_Statement (Parent (N)))
4983 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4984 and then N = Entry_Call_Statement (Parent (N)))
4986 if No (Statements (Parent (N))) then
4987 Set_Statements (Parent (N), New_List);
4990 Prepend (N_Node, Statements (Parent (N)));
4993 Insert_After (Call, N_Node);
4997 Next_Actual (Actual);
4998 Next_Formal_With_Extras (Formal);
5002 -- Finally, create block and analyze it
5005 Make_Block_Statement (Loc,
5006 Declarations => Decls,
5007 Handled_Statement_Sequence =>
5008 Make_Handled_Sequence_Of_Statements (Loc,
5009 Statements => Stats)));
5013 end Build_Simple_Entry_Call;
5015 --------------------------------
5016 -- Build_Task_Activation_Call --
5017 --------------------------------
5019 procedure Build_Task_Activation_Call (N : Node_Id) is
5020 Loc : constant Source_Ptr := Sloc (N);
5027 -- For sequential elaboration policy, all the tasks will be activated at
5028 -- the end of the elaboration.
5030 if Partition_Elaboration_Policy = 'S' then
5034 -- Get the activation chain entity. Except in the case of a package
5035 -- body, this is in the node that was passed. For a package body, we
5036 -- have to find the corresponding package declaration node.
5038 if Nkind (N) = N_Package_Body then
5039 P := Corresponding_Spec (N);
5042 exit when Nkind (P) = N_Package_Declaration;
5045 Chain := Activation_Chain_Entity (P);
5048 Chain := Activation_Chain_Entity (N);
5051 if Present (Chain) then
5052 if Restricted_Profile then
5053 Name := New_Occurrence_Of
5054 (RTE (RE_Activate_Restricted_Tasks), Loc);
5056 Name := New_Occurrence_Of
5057 (RTE (RE_Activate_Tasks), Loc);
5061 Make_Procedure_Call_Statement (Loc,
5063 Parameter_Associations =>
5064 New_List (Make_Attribute_Reference (Loc,
5065 Prefix => New_Occurrence_Of (Chain, Loc),
5066 Attribute_Name => Name_Unchecked_Access)));
5068 if Nkind (N) = N_Package_Declaration then
5069 if Present (Corresponding_Body (N)) then
5072 elsif Present (Private_Declarations (Specification (N))) then
5073 Append (Call, Private_Declarations (Specification (N)));
5076 Append (Call, Visible_Declarations (Specification (N)));
5080 if Present (Handled_Statement_Sequence (N)) then
5082 -- The call goes at the start of the statement sequence after
5083 -- the start of exception range label if one is present.
5089 Stm := First (Statements (Handled_Statement_Sequence (N)));
5091 -- A special case, skip exception range label if one is
5092 -- present (from front end zcx processing).
5094 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
5098 -- Another special case, if the first statement is a block
5099 -- from optimization of a local raise to a goto, then the
5100 -- call goes inside this block.
5102 if Nkind (Stm) = N_Block_Statement
5103 and then Exception_Junk (Stm)
5106 First (Statements (Handled_Statement_Sequence (Stm)));
5109 -- Insertion point is after any exception label pushes,
5110 -- since we want it covered by any local handlers.
5112 while Nkind (Stm) in N_Push_xxx_Label loop
5116 -- Now we have the proper insertion point
5118 Insert_Before (Stm, Call);
5122 Set_Handled_Statement_Sequence (N,
5123 Make_Handled_Sequence_Of_Statements (Loc,
5124 Statements => New_List (Call)));
5129 Check_Task_Activation (N);
5131 end Build_Task_Activation_Call;
5133 -------------------------------
5134 -- Build_Task_Allocate_Block --
5135 -------------------------------
5137 procedure Build_Task_Allocate_Block
5142 T : constant Entity_Id := Entity (Expression (N));
5143 Init : constant Entity_Id := Base_Init_Proc (T);
5144 Loc : constant Source_Ptr := Sloc (N);
5145 Chain : constant Entity_Id :=
5146 Make_Defining_Identifier (Loc, Name_uChain);
5147 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
5152 Make_Block_Statement (Loc,
5153 Identifier => New_Occurrence_Of (Blkent, Loc),
5154 Declarations => New_List (
5156 -- _Chain : Activation_Chain;
5158 Make_Object_Declaration (Loc,
5159 Defining_Identifier => Chain,
5160 Aliased_Present => True,
5161 Object_Definition =>
5162 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
5164 Handled_Statement_Sequence =>
5165 Make_Handled_Sequence_Of_Statements (Loc,
5167 Statements => New_List (
5171 Make_Procedure_Call_Statement (Loc,
5172 Name => New_Occurrence_Of (Init, Loc),
5173 Parameter_Associations => Args),
5175 -- Activate_Tasks (_Chain);
5177 Make_Procedure_Call_Statement (Loc,
5178 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
5179 Parameter_Associations => New_List (
5180 Make_Attribute_Reference (Loc,
5181 Prefix => New_Occurrence_Of (Chain, Loc),
5182 Attribute_Name => Name_Unchecked_Access))))),
5184 Has_Created_Identifier => True,
5185 Is_Task_Allocation_Block => True);
5188 Make_Implicit_Label_Declaration (Loc,
5189 Defining_Identifier => Blkent,
5190 Label_Construct => Block));
5192 Append_To (Actions, Block);
5194 Set_Activation_Chain_Entity (Block, Chain);
5195 end Build_Task_Allocate_Block;
5197 -----------------------------------------------
5198 -- Build_Task_Allocate_Block_With_Init_Stmts --
5199 -----------------------------------------------
5201 procedure Build_Task_Allocate_Block_With_Init_Stmts
5204 Init_Stmts : List_Id)
5206 Loc : constant Source_Ptr := Sloc (N);
5207 Chain : constant Entity_Id :=
5208 Make_Defining_Identifier (Loc, Name_uChain);
5209 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
5213 Append_To (Init_Stmts,
5214 Make_Procedure_Call_Statement (Loc,
5215 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
5216 Parameter_Associations => New_List (
5217 Make_Attribute_Reference (Loc,
5218 Prefix => New_Occurrence_Of (Chain, Loc),
5219 Attribute_Name => Name_Unchecked_Access))));
5222 Make_Block_Statement (Loc,
5223 Identifier => New_Occurrence_Of (Blkent, Loc),
5224 Declarations => New_List (
5226 -- _Chain : Activation_Chain;
5228 Make_Object_Declaration (Loc,
5229 Defining_Identifier => Chain,
5230 Aliased_Present => True,
5231 Object_Definition =>
5232 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
5234 Handled_Statement_Sequence =>
5235 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
5237 Has_Created_Identifier => True,
5238 Is_Task_Allocation_Block => True);
5241 Make_Implicit_Label_Declaration (Loc,
5242 Defining_Identifier => Blkent,
5243 Label_Construct => Block));
5245 Append_To (Actions, Block);
5247 Set_Activation_Chain_Entity (Block, Chain);
5248 end Build_Task_Allocate_Block_With_Init_Stmts;
5250 -----------------------------------
5251 -- Build_Task_Proc_Specification --
5252 -----------------------------------
5254 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
5255 Loc : constant Source_Ptr := Sloc (T);
5256 Spec_Id : Entity_Id;
5259 -- Case of explicit task type, suffix TB
5261 if Comes_From_Source (T) then
5263 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), "TB"));
5265 -- Case of anonymous task type, suffix B
5269 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), 'B'));
5272 Set_Is_Internal (Spec_Id);
5274 -- Associate the procedure with the task, if this is the declaration
5275 -- (and not the body) of the procedure.
5277 if No (Task_Body_Procedure (T)) then
5278 Set_Task_Body_Procedure (T, Spec_Id);
5282 Make_Procedure_Specification (Loc,
5283 Defining_Unit_Name => Spec_Id,
5284 Parameter_Specifications => New_List (
5285 Make_Parameter_Specification (Loc,
5286 Defining_Identifier =>
5287 Make_Defining_Identifier (Loc, Name_uTask),
5289 Make_Access_Definition (Loc,
5291 New_Occurrence_Of (Corresponding_Record_Type (T), Loc)))));
5292 end Build_Task_Proc_Specification;
5294 ---------------------------------------
5295 -- Build_Unprotected_Subprogram_Body --
5296 ---------------------------------------
5298 function Build_Unprotected_Subprogram_Body
5300 Pid : Node_Id) return Node_Id
5302 Decls : constant List_Id := Declarations (N);
5305 -- Add renamings for the Protection object, discriminals, privals and
5306 -- the entry index constant for use by debugger.
5308 Debug_Private_Data_Declarations (Decls);
5310 -- Make an unprotected version of the subprogram for use within the same
5311 -- object, with a new name and an additional parameter representing the
5315 Make_Subprogram_Body (Sloc (N),
5317 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
5318 Declarations => Decls,
5319 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
5320 end Build_Unprotected_Subprogram_Body;
5322 ----------------------------
5323 -- Collect_Entry_Families --
5324 ----------------------------
5326 procedure Collect_Entry_Families
5329 Current_Node : in out Node_Id;
5330 Conctyp : Entity_Id)
5333 Efam_Decl : Node_Id;
5334 Efam_Type : Entity_Id;
5337 Efam := First_Entity (Conctyp);
5338 while Present (Efam) loop
5339 if Ekind (Efam) = E_Entry_Family then
5340 Efam_Type := Make_Temporary (Loc, 'F');
5345 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
5347 Bas_Decl : Node_Id := Empty;
5352 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
5354 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
5355 Bas := Make_Temporary (Loc, 'B');
5358 Make_Subtype_Declaration (Loc,
5359 Defining_Identifier => Bas,
5360 Subtype_Indication =>
5361 Make_Subtype_Indication (Loc,
5363 New_Occurrence_Of (Standard_Integer, Loc),
5365 Make_Range_Constraint (Loc,
5366 Range_Expression => Make_Range (Loc,
5367 Make_Integer_Literal
5368 (Loc, -Entry_Family_Bound),
5369 Make_Integer_Literal
5370 (Loc, Entry_Family_Bound - 1)))));
5372 Insert_After (Current_Node, Bas_Decl);
5373 Current_Node := Bas_Decl;
5378 Make_Full_Type_Declaration (Loc,
5379 Defining_Identifier => Efam_Type,
5381 Make_Unconstrained_Array_Definition (Loc,
5383 (New_List (New_Occurrence_Of (Bas, Loc))),
5385 Component_Definition =>
5386 Make_Component_Definition (Loc,
5387 Aliased_Present => False,
5388 Subtype_Indication =>
5389 New_Occurrence_Of (Standard_Character, Loc))));
5392 Insert_After (Current_Node, Efam_Decl);
5393 Current_Node := Efam_Decl;
5394 Analyze (Efam_Decl);
5397 Make_Component_Declaration (Loc,
5398 Defining_Identifier =>
5399 Make_Defining_Identifier (Loc, Chars (Efam)),
5401 Component_Definition =>
5402 Make_Component_Definition (Loc,
5403 Aliased_Present => False,
5404 Subtype_Indication =>
5405 Make_Subtype_Indication (Loc,
5407 New_Occurrence_Of (Efam_Type, Loc),
5410 Make_Index_Or_Discriminant_Constraint (Loc,
5411 Constraints => New_List (
5413 (Etype (Discrete_Subtype_Definition
5414 (Parent (Efam))), Loc)))))));
5420 end Collect_Entry_Families;
5422 -----------------------
5423 -- Concurrent_Object --
5424 -----------------------
5426 function Concurrent_Object
5427 (Spec_Id : Entity_Id;
5428 Conc_Typ : Entity_Id) return Entity_Id
5431 -- Parameter _O or _object
5433 if Is_Protected_Type (Conc_Typ) then
5434 return First_Formal (Protected_Body_Subprogram (Spec_Id));
5439 pragma Assert (Is_Task_Type (Conc_Typ));
5440 return First_Formal (Task_Body_Procedure (Conc_Typ));
5442 end Concurrent_Object;
5444 ----------------------
5445 -- Copy_Result_Type --
5446 ----------------------
5448 function Copy_Result_Type (Res : Node_Id) return Node_Id is
5449 New_Res : constant Node_Id := New_Copy_Tree (Res);
5454 -- If the result type is an access_to_subprogram, we must create new
5455 -- entities for its spec.
5457 if Nkind (New_Res) = N_Access_Definition
5458 and then Present (Access_To_Subprogram_Definition (New_Res))
5460 -- Provide new entities for the formals
5462 Par_Spec := First (Parameter_Specifications
5463 (Access_To_Subprogram_Definition (New_Res)));
5464 while Present (Par_Spec) loop
5465 Formal := Defining_Identifier (Par_Spec);
5466 Set_Defining_Identifier (Par_Spec,
5467 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
5473 end Copy_Result_Type;
5475 --------------------
5476 -- Concurrent_Ref --
5477 --------------------
5479 -- The expression returned for a reference to a concurrent object has the
5482 -- taskV!(name)._Task_Id
5486 -- objectV!(name)._Object
5488 -- for a protected object. For the case of an access to a concurrent
5489 -- object, there is an extra explicit dereference:
5491 -- taskV!(name.all)._Task_Id
5492 -- objectV!(name.all)._Object
5494 -- here taskV and objectV are the types for the associated records, which
5495 -- contain the required _Task_Id and _Object fields for tasks and protected
5496 -- objects, respectively.
5498 -- For the case of a task type name, the expression is
5502 -- i.e. a call to the Self function which returns precisely this Task_Id
5504 -- For the case of a protected type name, the expression is
5508 -- which is a renaming of the _object field of the current object
5509 -- record, passed into protected operations as a parameter.
5511 function Concurrent_Ref (N : Node_Id) return Node_Id is
5512 Loc : constant Source_Ptr := Sloc (N);
5513 Ntyp : constant Entity_Id := Etype (N);
5517 function Is_Current_Task (T : Entity_Id) return Boolean;
5518 -- Check whether the reference is to the immediately enclosing task
5519 -- type, or to an outer one (rare but legal).
5521 ---------------------
5522 -- Is_Current_Task --
5523 ---------------------
5525 function Is_Current_Task (T : Entity_Id) return Boolean is
5529 Scop := Current_Scope;
5530 while Present (Scop) and then Scop /= Standard_Standard loop
5534 elsif Is_Task_Type (Scop) then
5537 -- If this is a procedure nested within the task type, we must
5538 -- assume that it can be called from an inner task, and therefore
5539 -- cannot treat it as a local reference.
5541 elsif Is_Overloadable (Scop) and then In_Open_Scopes (T) then
5545 Scop := Scope (Scop);
5549 -- We know that we are within the task body, so should have found it
5552 raise Program_Error;
5553 end Is_Current_Task;
5555 -- Start of processing for Concurrent_Ref
5558 if Is_Access_Type (Ntyp) then
5559 Dtyp := Designated_Type (Ntyp);
5561 if Is_Protected_Type (Dtyp) then
5562 Sel := Name_uObject;
5564 Sel := Name_uTask_Id;
5568 Make_Selected_Component (Loc,
5570 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
5571 Make_Explicit_Dereference (Loc, N)),
5572 Selector_Name => Make_Identifier (Loc, Sel));
5574 elsif Is_Entity_Name (N) and then Is_Concurrent_Type (Entity (N)) then
5575 if Is_Task_Type (Entity (N)) then
5577 if Is_Current_Task (Entity (N)) then
5579 Make_Function_Call (Loc,
5580 Name => New_Occurrence_Of (RTE (RE_Self), Loc));
5585 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
5586 T_Body : constant Node_Id :=
5587 Parent (Corresponding_Body (Parent (Entity (N))));
5591 Make_Object_Declaration (Loc,
5592 Defining_Identifier => T_Self,
5593 Object_Definition =>
5594 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
5596 Make_Function_Call (Loc,
5597 Name => New_Occurrence_Of (RTE (RE_Self), Loc)));
5598 Prepend (Decl, Declarations (T_Body));
5600 Set_Scope (T_Self, Entity (N));
5601 return New_Occurrence_Of (T_Self, Loc);
5606 pragma Assert (Is_Protected_Type (Entity (N)));
5609 New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc);
5613 if Is_Protected_Type (Ntyp) then
5614 Sel := Name_uObject;
5615 elsif Is_Task_Type (Ntyp) then
5616 Sel := Name_uTask_Id;
5618 raise Program_Error;
5622 Make_Selected_Component (Loc,
5624 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
5626 Selector_Name => Make_Identifier (Loc, Sel));
5630 ------------------------
5631 -- Convert_Concurrent --
5632 ------------------------
5634 function Convert_Concurrent
5636 Typ : Entity_Id) return Node_Id
5639 if not Is_Concurrent_Type (Typ) then
5643 Unchecked_Convert_To
5644 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
5646 end Convert_Concurrent;
5648 -------------------------------------
5649 -- Debug_Private_Data_Declarations --
5650 -------------------------------------
5652 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
5653 Debug_Nod : Node_Id;
5657 Decl := First (Decls);
5658 while Present (Decl) and then not Comes_From_Source (Decl) loop
5660 -- Declaration for concurrent entity _object and its access type,
5661 -- along with the entry index subtype:
5662 -- type prot_typVP is access prot_typV;
5663 -- _object : prot_typVP := prot_typV (_O);
5664 -- subtype Jnn is <Type of Index> range Low .. High;
5666 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
5667 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5669 -- Declaration for the Protection object, discriminals, privals and
5670 -- entry index constant:
5671 -- conc_typR : protection_typ renames _object._object;
5672 -- discr_nameD : discr_typ renames _object.discr_name;
5673 -- discr_nameD : discr_typ renames _task.discr_name;
5674 -- prival_name : comp_typ renames _object.comp_name;
5675 -- J : constant Jnn :=
5676 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5678 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
5679 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5680 Debug_Nod := Debug_Renaming_Declaration (Decl);
5682 if Present (Debug_Nod) then
5683 Insert_After (Decl, Debug_Nod);
5689 end Debug_Private_Data_Declarations;
5691 ------------------------------
5692 -- Ensure_Statement_Present --
5693 ------------------------------
5695 procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id) is
5699 if Opt.Suppress_Control_Flow_Optimizations
5700 and then Is_Empty_List (Statements (Alt))
5702 Stmt := Make_Null_Statement (Loc);
5704 -- Mark NULL statement as coming from source so that it is not
5705 -- eliminated by GIGI.
5707 -- Another covert channel. If this is a requirement, it must be
5708 -- documented in sinfo/einfo ???
5710 Set_Comes_From_Source (Stmt, True);
5712 Set_Statements (Alt, New_List (Stmt));
5714 end Ensure_Statement_Present;
5716 ----------------------------
5717 -- Entry_Index_Expression --
5718 ----------------------------
5720 function Entry_Index_Expression
5724 Ttyp : Entity_Id) return Node_Id
5734 -- The queues of entries and entry families appear in textual order in
5735 -- the associated record. The entry index is computed as the sum of the
5736 -- number of queues for all entries that precede the designated one, to
5737 -- which is added the index expression, if this expression denotes a
5738 -- member of a family.
5740 -- The following is a place holder for the count of simple entries
5742 Num := Make_Integer_Literal (Sloc, 1);
5744 -- We construct an expression which is a series of addition operations.
5745 -- The first operand is the number of single entries that precede this
5746 -- one, the second operand is the index value relative to the start of
5747 -- the referenced family, and the remaining operands are the lengths of
5748 -- the entry families that precede this entry, i.e. the constructed
5751 -- number_simple_entries +
5752 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5753 -- family'length + ...
5755 -- where index-value is the given index value, and s is the index
5756 -- subtype (we have to use pos because the subtype might be an
5757 -- enumeration type preventing direct subtraction). Note that the task
5758 -- entry array is one-indexed.
5760 -- The upper bound of the entry family may be a discriminant, so we
5761 -- retrieve the lower bound explicitly to compute offset, rather than
5762 -- using the index subtype which may mention a discriminant.
5764 if Present (Index) then
5765 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
5773 Make_Attribute_Reference (Sloc,
5774 Attribute_Name => Name_Pos,
5775 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
5776 Expressions => New_List (Relocate_Node (Index))),
5784 -- Now add lengths of preceding entries and entry families
5786 Prev := First_Entity (Ttyp);
5787 while Chars (Prev) /= Chars (Ent)
5788 or else (Ekind (Prev) /= Ekind (Ent))
5789 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
5791 if Ekind (Prev) = E_Entry then
5792 Set_Intval (Num, Intval (Num) + 1);
5794 elsif Ekind (Prev) = E_Entry_Family then
5795 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
5796 Lo := Type_Low_Bound (S);
5797 Hi := Type_High_Bound (S);
5802 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
5804 -- Other components are anonymous types to be ignored
5814 end Entry_Index_Expression;
5816 ---------------------------
5817 -- Establish_Task_Master --
5818 ---------------------------
5820 procedure Establish_Task_Master (N : Node_Id) is
5824 if Restriction_Active (No_Task_Hierarchy) = False then
5825 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
5827 -- The block may have no declarations (and nevertheless be a task
5828 -- master) if it contains a call that may return an object that
5831 if No (Declarations (N)) then
5832 Set_Declarations (N, New_List (Call));
5834 Prepend_To (Declarations (N), Call);
5839 end Establish_Task_Master;
5841 --------------------------------
5842 -- Expand_Accept_Declarations --
5843 --------------------------------
5845 -- Part of the expansion of an accept statement involves the creation of
5846 -- a declaration that can be referenced from the statement sequence of
5851 -- This declaration is inserted immediately before the accept statement
5852 -- and it is important that it be inserted before the statements of the
5853 -- statement sequence are analyzed. Thus it would be too late to create
5854 -- this declaration in the Expand_N_Accept_Statement routine, which is
5855 -- why there is a separate procedure to be called directly from Sem_Ch9.
5857 -- Ann is used to hold the address of the record containing the parameters
5858 -- (see Expand_N_Entry_Call for more details on how this record is built).
5859 -- References to the parameters do an unchecked conversion of this address
5860 -- to a pointer to the required record type, and then access the field that
5861 -- holds the value of the required parameter. The entity for the address
5862 -- variable is held as the top stack element (i.e. the last element) of the
5863 -- Accept_Address stack in the corresponding entry entity, and this element
5864 -- must be set in place before the statements are processed.
5866 -- The above description applies to the case of a stand alone accept
5867 -- statement, i.e. one not appearing as part of a select alternative.
5869 -- For the case of an accept that appears as part of a select alternative
5870 -- of a selective accept, we must still create the declaration right away,
5871 -- since Ann is needed immediately, but there is an important difference:
5873 -- The declaration is inserted before the selective accept, not before
5874 -- the accept statement (which is not part of a list anyway, and so would
5875 -- not accommodate inserted declarations)
5877 -- We only need one address variable for the entire selective accept. So
5878 -- the Ann declaration is created only for the first accept alternative,
5879 -- and subsequent accept alternatives reference the same Ann variable.
5881 -- We can distinguish the two cases by seeing whether the accept statement
5882 -- is part of a list. If not, then it must be in an accept alternative.
5884 -- To expand the requeue statement, a label is provided at the end of the
5885 -- accept statement or alternative of which it is a part, so that the
5886 -- statement can be skipped after the requeue is complete. This label is
5887 -- created here rather than during the expansion of the accept statement,
5888 -- because it will be needed by any requeue statements within the accept,
5889 -- which are expanded before the accept.
5891 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
5892 Loc : constant Source_Ptr := Sloc (N);
5893 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5894 Ann : Entity_Id := Empty;
5901 if Expander_Active then
5903 -- If we have no handled statement sequence, we may need to build
5904 -- a dummy sequence consisting of a null statement. This can be
5905 -- skipped if the trivial accept optimization is permitted.
5907 if not Trivial_Accept_OK
5908 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5910 Set_Handled_Statement_Sequence (N,
5911 Make_Handled_Sequence_Of_Statements (Loc,
5912 Statements => New_List (Make_Null_Statement (Loc))));
5915 -- Create and declare two labels to be placed at the end of the
5916 -- accept statement. The first label is used to allow requeues to
5917 -- skip the remainder of entry processing. The second label is used
5918 -- to skip the remainder of entry processing if the rendezvous
5919 -- completes in the middle of the accept body.
5921 if Present (Handled_Statement_Sequence (N)) then
5926 Ent := Make_Temporary (Loc, 'L');
5927 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5929 Make_Implicit_Label_Declaration (Loc,
5930 Defining_Identifier => Ent,
5931 Label_Construct => Lab);
5932 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5934 Ent := Make_Temporary (Loc, 'L');
5935 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5937 Make_Implicit_Label_Declaration (Loc,
5938 Defining_Identifier => Ent,
5939 Label_Construct => Lab);
5940 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5948 -- Case of stand alone accept statement
5950 if Is_List_Member (N) then
5952 if Present (Handled_Statement_Sequence (N)) then
5953 Ann := Make_Temporary (Loc, 'A');
5956 Make_Object_Declaration (Loc,
5957 Defining_Identifier => Ann,
5958 Object_Definition =>
5959 New_Occurrence_Of (RTE (RE_Address), Loc));
5961 Insert_Before_And_Analyze (N, Adecl);
5962 Insert_Before_And_Analyze (N, Ldecl);
5963 Insert_Before_And_Analyze (N, Ldecl2);
5966 -- Case of accept statement which is in an accept alternative
5970 Acc_Alt : constant Node_Id := Parent (N);
5971 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
5975 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
5976 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
5978 -- ??? Consider a single label for select statements
5980 if Present (Handled_Statement_Sequence (N)) then
5982 Statements (Handled_Statement_Sequence (N)));
5986 Statements (Handled_Statement_Sequence (N)));
5990 -- Find first accept alternative of the selective accept. A
5991 -- valid selective accept must have at least one accept in it.
5993 Alt := First (Select_Alternatives (Sel_Acc));
5995 while Nkind (Alt) /= N_Accept_Alternative loop
5999 -- If this is the first accept statement, then we have to
6000 -- create the Ann variable, as for the stand alone case, except
6001 -- that it is inserted before the selective accept. Similarly,
6002 -- a label for requeue expansion must be declared.
6004 if N = Accept_Statement (Alt) then
6005 Ann := Make_Temporary (Loc, 'A');
6007 Make_Object_Declaration (Loc,
6008 Defining_Identifier => Ann,
6009 Object_Definition =>
6010 New_Occurrence_Of (RTE (RE_Address), Loc));
6012 Insert_Before_And_Analyze (Sel_Acc, Adecl);
6014 -- If this is not the first accept statement, then find the Ann
6015 -- variable allocated by the first accept and use it.
6019 Node (Last_Elmt (Accept_Address
6020 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
6025 -- Merge here with Ann either created or referenced, and Adecl
6026 -- pointing to the corresponding declaration. Remaining processing
6027 -- is the same for the two cases.
6029 if Present (Ann) then
6030 Append_Elmt (Ann, Accept_Address (Ent));
6031 Set_Debug_Info_Needed (Ann);
6034 -- Create renaming declarations for the entry formals. Each reference
6035 -- to a formal becomes a dereference of a component of the parameter
6036 -- block, whose address is held in Ann. These declarations are
6037 -- eventually inserted into the accept block, and analyzed there so
6038 -- that they have the proper scope for gdb and do not conflict with
6039 -- other declarations.
6041 if Present (Parameter_Specifications (N))
6042 and then Present (Handled_Statement_Sequence (N))
6049 Renamed_Formal : Node_Id;
6053 Formal := First_Formal (Ent);
6055 while Present (Formal) loop
6056 Comp := Entry_Component (Formal);
6057 New_F := Make_Defining_Identifier (Loc, Chars (Formal));
6059 Set_Etype (New_F, Etype (Formal));
6060 Set_Scope (New_F, Ent);
6062 -- Now we set debug info needed on New_F even though it does
6063 -- not come from source, so that the debugger will get the
6064 -- right information for these generated names.
6066 Set_Debug_Info_Needed (New_F);
6068 if Ekind (Formal) = E_In_Parameter then
6069 Set_Ekind (New_F, E_Constant);
6071 Set_Ekind (New_F, E_Variable);
6072 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
6075 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
6078 Make_Selected_Component (Loc,
6080 Unchecked_Convert_To (
6081 Entry_Parameters_Type (Ent),
6082 New_Occurrence_Of (Ann, Loc)),
6084 New_Occurrence_Of (Comp, Loc));
6087 Build_Renamed_Formal_Declaration
6088 (New_F, Formal, Comp, Renamed_Formal);
6090 if No (Declarations (N)) then
6091 Set_Declarations (N, New_List);
6094 Append (Decl, Declarations (N));
6095 Set_Renamed_Object (Formal, New_F);
6096 Next_Formal (Formal);
6103 end Expand_Accept_Declarations;
6105 ---------------------------------------------
6106 -- Expand_Access_Protected_Subprogram_Type --
6107 ---------------------------------------------
6109 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
6110 Loc : constant Source_Ptr := Sloc (N);
6112 T : constant Entity_Id := Defining_Identifier (N);
6113 D_T : constant Entity_Id := Designated_Type (T);
6114 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
6115 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
6116 P_List : constant List_Id := Build_Protected_Spec
6117 (N, RTE (RE_Address), D_T, False);
6123 -- Create access to subprogram with full signature
6125 if Etype (D_T) /= Standard_Void_Type then
6127 Make_Access_Function_Definition (Loc,
6128 Parameter_Specifications => P_List,
6129 Result_Definition =>
6130 Copy_Result_Type (Result_Definition (Type_Definition (N))));
6134 Make_Access_Procedure_Definition (Loc,
6135 Parameter_Specifications => P_List);
6139 Make_Full_Type_Declaration (Loc,
6140 Defining_Identifier => D_T2,
6141 Type_Definition => Def1);
6143 Insert_After_And_Analyze (N, Decl1);
6145 -- Associate the access to subprogram with its original access to
6146 -- protected subprogram type. Needed by the backend to know that this
6147 -- type corresponds with an access to protected subprogram type.
6149 Set_Original_Access_Type (D_T2, T);
6151 -- Create Equivalent_Type, a record with two components for an access to
6152 -- object and an access to subprogram.
6155 Make_Component_Declaration (Loc,
6156 Defining_Identifier => Make_Temporary (Loc, 'P'),
6157 Component_Definition =>
6158 Make_Component_Definition (Loc,
6159 Aliased_Present => False,
6160 Subtype_Indication =>
6161 New_Occurrence_Of (RTE (RE_Address), Loc))),
6163 Make_Component_Declaration (Loc,
6164 Defining_Identifier => Make_Temporary (Loc, 'S'),
6165 Component_Definition =>
6166 Make_Component_Definition (Loc,
6167 Aliased_Present => False,
6168 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
6171 Make_Full_Type_Declaration (Loc,
6172 Defining_Identifier => E_T,
6174 Make_Record_Definition (Loc,
6176 Make_Component_List (Loc, Component_Items => Comps)));
6178 Insert_After_And_Analyze (Decl1, Decl2);
6179 Set_Equivalent_Type (T, E_T);
6180 end Expand_Access_Protected_Subprogram_Type;
6182 --------------------------
6183 -- Expand_Entry_Barrier --
6184 --------------------------
6186 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
6187 Cond : constant Node_Id :=
6188 Condition (Entry_Body_Formal_Part (N));
6189 Prot : constant Entity_Id := Scope (Ent);
6190 Spec_Decl : constant Node_Id := Parent (Prot);
6191 Func : Entity_Id := Empty;
6193 Body_Decl : Node_Id;
6195 function Is_Global_Entity (N : Node_Id) return Traverse_Result;
6196 -- Check whether entity in Barrier is external to protected type.
6197 -- If so, barrier may not be properly synchronized.
6199 ----------------------
6200 -- Is_Global_Entity --
6201 ----------------------
6203 function Is_Global_Entity (N : Node_Id) return Traverse_Result is
6208 if Is_Entity_Name (N) and then Present (Entity (N)) then
6212 if Ekind (E) = E_Variable then
6214 -- If the variable is local to the barrier function generated
6215 -- during expansion, it is ok. If expansion is not performed,
6216 -- then Func is Empty so this test cannot succeed.
6218 if Scope (E) = Func then
6221 -- A protected call from a barrier to another object is ok
6223 elsif Ekind (Etype (E)) = E_Protected_Type then
6226 -- If the variable is within the package body we consider
6227 -- this safe. This is a common (if dubious) idiom.
6229 elsif S = Scope (Prot)
6230 and then Ekind_In (S, E_Package, E_Generic_Package)
6231 and then Nkind (Parent (E)) = N_Object_Declaration
6232 and then Nkind (Parent (Parent (E))) = N_Package_Body
6237 Error_Msg_N ("potentially unsynchronized barrier??", N);
6238 Error_Msg_N ("\& should be private component of type??", N);
6244 end Is_Global_Entity;
6246 procedure Check_Unprotected_Barrier is
6247 new Traverse_Proc (Is_Global_Entity);
6249 -- Start of processing for Expand_Entry_Barrier
6252 if No_Run_Time_Mode then
6253 Error_Msg_CRT ("entry barrier", N);
6257 -- The body of the entry barrier must be analyzed in the context of the
6258 -- protected object, but its scope is external to it, just as any other
6259 -- unprotected version of a protected operation. The specification has
6260 -- been produced when the protected type declaration was elaborated. We
6261 -- build the body, insert it in the enclosing scope, but analyze it in
6262 -- the current context. A more uniform approach would be to treat the
6263 -- barrier just as a protected function, and discard the protected
6264 -- version of it because it is never called.
6266 if Expander_Active then
6267 B_F := Build_Barrier_Function (N, Ent, Prot);
6268 Func := Barrier_Function (Ent);
6269 Set_Corresponding_Spec (B_F, Func);
6271 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
6273 if Nkind (Parent (Body_Decl)) = N_Subunit then
6274 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
6277 Insert_Before_And_Analyze (Body_Decl, B_F);
6279 Set_Discriminals (Spec_Decl);
6280 Set_Scope (Func, Scope (Prot));
6283 Analyze_And_Resolve (Cond, Any_Boolean);
6286 -- The Ravenscar profile restricts barriers to simple variables declared
6287 -- within the protected object. We also allow Boolean constants, since
6288 -- these appear in several published examples and are also allowed by
6291 -- Note that after analysis variables in this context will be replaced
6292 -- by the corresponding prival, that is to say a renaming of a selected
6293 -- component of the form _Object.Var. If expansion is disabled, as
6294 -- within a generic, we check that the entity appears in the current
6297 if Is_Entity_Name (Cond) then
6299 -- A small optimization of useless renamings. If the scope of the
6300 -- entity of the condition is not the barrier function, then the
6301 -- condition does not reference any of the generated renamings
6302 -- within the function.
6304 if Expander_Active and then Scope (Entity (Cond)) /= Func then
6305 Set_Declarations (B_F, Empty_List);
6308 if Entity (Cond) = Standard_False
6310 Entity (Cond) = Standard_True
6314 elsif not Expander_Active
6315 and then Scope (Entity (Cond)) = Current_Scope
6319 -- Check for case of _object.all.field (note that the explicit
6320 -- dereference gets inserted by analyze/expand of _object.field)
6322 elsif Present (Renamed_Object (Entity (Cond)))
6324 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
6328 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
6334 -- It is not a boolean variable or literal, so check the restriction.
6335 -- Note that it is safe to be calling Check_Restriction from here, even
6336 -- though this is part of the expander, since Expand_Entry_Barrier is
6337 -- called from Sem_Ch9 even in -gnatc mode.
6339 Check_Restriction (Simple_Barriers, Cond);
6341 -- Emit warning if barrier contains global entities and is thus
6342 -- potentially unsynchronized.
6344 Check_Unprotected_Barrier (Cond);
6345 end Expand_Entry_Barrier;
6347 ------------------------------
6348 -- Expand_N_Abort_Statement --
6349 ------------------------------
6351 -- Expand abort T1, T2, .. Tn; into:
6352 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6354 procedure Expand_N_Abort_Statement (N : Node_Id) is
6355 Loc : constant Source_Ptr := Sloc (N);
6356 Tlist : constant List_Id := Names (N);
6362 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
6365 Tasknm := First (Tlist);
6367 while Present (Tasknm) loop
6370 -- A task interface class-wide type object is being aborted. Retrieve
6371 -- its _task_id by calling a dispatching routine.
6373 if Ada_Version >= Ada_2005
6374 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
6375 and then Is_Interface (Etype (Tasknm))
6376 and then Is_Task_Interface (Etype (Tasknm))
6378 Append_To (Component_Associations (Aggr),
6379 Make_Component_Association (Loc,
6380 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6383 -- Task_Id (Tasknm._disp_get_task_id)
6385 Make_Unchecked_Type_Conversion (Loc,
6387 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
6389 Make_Selected_Component (Loc,
6390 Prefix => New_Copy_Tree (Tasknm),
6392 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
6395 Append_To (Component_Associations (Aggr),
6396 Make_Component_Association (Loc,
6397 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6398 Expression => Concurrent_Ref (Tasknm)));
6405 Make_Procedure_Call_Statement (Loc,
6406 Name => New_Occurrence_Of (RTE (RE_Abort_Tasks), Loc),
6407 Parameter_Associations => New_List (
6408 Make_Qualified_Expression (Loc,
6409 Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_List), Loc),
6410 Expression => Aggr))));
6413 end Expand_N_Abort_Statement;
6415 -------------------------------
6416 -- Expand_N_Accept_Statement --
6417 -------------------------------
6419 -- This procedure handles expansion of accept statements that stand alone,
6420 -- i.e. they are not part of an accept alternative. The expansion of
6421 -- accept statement in accept alternatives is handled by the routines
6422 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6423 -- following description applies only to stand alone accept statements.
6425 -- If there is no handled statement sequence, or only null statements, then
6426 -- this is called a trivial accept, and the expansion is:
6428 -- Accept_Trivial (entry-index)
6430 -- If there is a handled statement sequence, then the expansion is:
6437 -- Accept_Call (entry-index, Ann);
6438 -- Renaming_Declarations for formals
6439 -- <statement sequence from N_Accept_Statement node>
6440 -- Complete_Rendezvous;
6445 -- <exception handler from N_Accept_Statement node>
6446 -- Complete_Rendezvous;
6448 -- <exception handler from N_Accept_Statement node>
6449 -- Complete_Rendezvous;
6454 -- when all others =>
6455 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6458 -- The first three declarations were already inserted ahead of the accept
6459 -- statement by the Expand_Accept_Declarations procedure, which was called
6460 -- directly from the semantics during analysis of the accept statement,
6461 -- before analyzing its contained statements.
6463 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6464 -- from possible expansion activity (the original source of course does
6465 -- not have any declarations associated with the accept statement, since
6466 -- an accept statement has no declarative part). In particular, if the
6467 -- expander is active, the first such declaration is the declaration of
6468 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6470 -- The two blocks are merged into a single block if the inner block has
6471 -- no exception handlers, but otherwise two blocks are required, since
6472 -- exceptions might be raised in the exception handlers of the inner
6473 -- block, and Exceptional_Complete_Rendezvous must be called.
6475 procedure Expand_N_Accept_Statement (N : Node_Id) is
6476 Loc : constant Source_Ptr := Sloc (N);
6477 Stats : constant Node_Id := Handled_Statement_Sequence (N);
6478 Ename : constant Node_Id := Entry_Direct_Name (N);
6479 Eindx : constant Node_Id := Entry_Index (N);
6480 Eent : constant Entity_Id := Entity (Ename);
6481 Acstack : constant Elist_Id := Accept_Address (Eent);
6482 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
6483 Ttyp : constant Entity_Id := Etype (Scope (Eent));
6489 -- If the accept statement is not part of a list, then its parent must
6490 -- be an accept alternative, and, as described above, we do not do any
6491 -- expansion for such accept statements at this level.
6493 if not Is_List_Member (N) then
6494 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
6497 -- Trivial accept case (no statement sequence, or null statements).
6498 -- If the accept statement has declarations, then just insert them
6499 -- before the procedure call.
6501 elsif Trivial_Accept_OK
6502 and then (No (Stats) or else Null_Statements (Statements (Stats)))
6504 -- Remove declarations for renamings, because the parameter block
6505 -- will not be assigned.
6512 D := First (Declarations (N));
6513 while Present (D) loop
6515 if Nkind (D) = N_Object_Renaming_Declaration then
6523 if Present (Declarations (N)) then
6524 Insert_Actions (N, Declarations (N));
6528 Make_Procedure_Call_Statement (Loc,
6529 Name => New_Occurrence_Of (RTE (RE_Accept_Trivial), Loc),
6530 Parameter_Associations => New_List (
6531 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
6535 -- Discard Entry_Address that was created for it, so it will not be
6536 -- emitted if this accept statement is in the statement part of a
6537 -- delay alternative.
6539 if Present (Stats) then
6540 Remove_Last_Elmt (Acstack);
6543 -- Case of statement sequence present
6546 -- Construct the block, using the declarations from the accept
6547 -- statement if any to initialize the declarations of the block.
6549 Blkent := Make_Temporary (Loc, 'A');
6550 Set_Ekind (Blkent, E_Block);
6551 Set_Etype (Blkent, Standard_Void_Type);
6552 Set_Scope (Blkent, Current_Scope);
6555 Make_Block_Statement (Loc,
6556 Identifier => New_Occurrence_Of (Blkent, Loc),
6557 Declarations => Declarations (N),
6558 Handled_Statement_Sequence => Build_Accept_Body (N));
6560 -- For the analysis of the generated declarations, the parent node
6561 -- must be properly set.
6563 Set_Parent (Block, Parent (N));
6565 -- Prepend call to Accept_Call to main statement sequence If the
6566 -- accept has exception handlers, the statement sequence is wrapped
6567 -- in a block. Insert call and renaming declarations in the
6568 -- declarations of the block, so they are elaborated before the
6572 Make_Procedure_Call_Statement (Loc,
6573 Name => New_Occurrence_Of (RTE (RE_Accept_Call), Loc),
6574 Parameter_Associations => New_List (
6575 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
6576 New_Occurrence_Of (Ann, Loc)));
6578 if Parent (Stats) = N then
6579 Prepend (Call, Statements (Stats));
6581 Set_Declarations (Parent (Stats), New_List (Call));
6586 Push_Scope (Blkent);
6594 D := First (Declarations (N));
6595 while Present (D) loop
6598 if Nkind (D) = N_Object_Renaming_Declaration then
6600 -- The renaming declarations for the formals were created
6601 -- during analysis of the accept statement, and attached to
6602 -- the list of declarations. Place them now in the context
6603 -- of the accept block or subprogram.
6606 Typ := Entity (Subtype_Mark (D));
6607 Insert_After (Call, D);
6610 -- If the formal is class_wide, it does not have an actual
6611 -- subtype. The analysis of the renaming declaration creates
6612 -- one, but we need to retain the class-wide nature of the
6615 if Is_Class_Wide_Type (Typ) then
6616 Set_Etype (Defining_Identifier (D), Typ);
6627 -- Replace the accept statement by the new block
6632 -- Last step is to unstack the Accept_Address value
6634 Remove_Last_Elmt (Acstack);
6636 end Expand_N_Accept_Statement;
6638 ----------------------------------
6639 -- Expand_N_Asynchronous_Select --
6640 ----------------------------------
6642 -- This procedure assumes that the trigger statement is an entry call or
6643 -- a dispatching procedure call. A delay alternative should already have
6644 -- been expanded into an entry call to the appropriate delay object Wait
6647 -- If the trigger is a task entry call, the select is implemented with
6648 -- a Task_Entry_Call:
6653 -- P : parms := (parm, parm, parm);
6655 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6657 -- procedure _clean is
6660 -- Cancel_Task_Entry_Call (C);
6667 -- (<acceptor-task>, -- Acceptor
6668 -- <entry-index>, -- E
6669 -- P'Address, -- Uninterpreted_Data
6670 -- Asynchronous_Call, -- Mode
6671 -- B); -- Rendezvous_Successful
6678 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6681 -- when Abort_Signal => Abort_Undefer;
6688 -- <triggered-statements>
6692 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6693 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6697 -- P : parms := (parm, parm, parm);
6699 -- Call_Simple (acceptor-task, entry-index, P'Address);
6705 -- so the task at hand is to convert the latter expansion into the former
6707 -- If the trigger is a protected entry call, the select is implemented
6708 -- with Protected_Entry_Call:
6711 -- P : E1_Params := (param, param, param);
6712 -- Bnn : Communications_Block;
6717 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6719 -- procedure _clean is
6722 -- if Enqueued (Bnn) then
6723 -- Cancel_Protected_Entry_Call (Bnn);
6730 -- Protected_Entry_Call
6731 -- (po._object'Access, -- Object
6732 -- <entry index>, -- E
6733 -- P'Address, -- Uninterpreted_Data
6734 -- Asynchronous_Call, -- Mode
6737 -- if Enqueued (Bnn) then
6741 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6744 -- when Abort_Signal => Abort_Undefer;
6747 -- if not Cancelled (Bnn) then
6748 -- <triggered-statements>
6752 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6756 -- P : E1_Params := (param, param, param);
6757 -- Bnn : Communications_Block;
6760 -- Protected_Entry_Call
6761 -- (po._object'Access, -- Object
6762 -- <entry index>, -- E
6763 -- P'Address, -- Uninterpreted_Data
6764 -- Simple_Call, -- Mode
6771 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6775 -- B : Boolean := False;
6776 -- Bnn : Communication_Block;
6777 -- C : Ada.Tags.Prim_Op_Kind;
6778 -- D : System.Storage_Elements.Dummy_Communication_Block;
6779 -- K : Ada.Tags.Tagged_Kind :=
6780 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6781 -- P : Parameters := (Param1 .. ParamN);
6786 -- if K = Ada.Tags.TK_Limited_Tagged
6787 -- or else K = Ada.Tags.TK_Tagged
6789 -- <dispatching-call>;
6790 -- <triggering-statements>;
6794 -- Ada.Tags.Get_Offset_Index
6795 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6797 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6799 -- if C = POK_Protected_Entry then
6801 -- procedure _clean is
6803 -- if Enqueued (Bnn) then
6804 -- Cancel_Protected_Entry_Call (Bnn);
6810 -- _Disp_Asynchronous_Select
6811 -- (<object>, S, P'Address, D, B);
6812 -- Bnn := Communication_Block (D);
6814 -- Param1 := P.Param1;
6816 -- ParamN := P.ParamN;
6818 -- if Enqueued (Bnn) then
6819 -- <abortable-statements>
6822 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6825 -- when Abort_Signal => Abort_Undefer;
6828 -- if not Cancelled (Bnn) then
6829 -- <triggering-statements>
6832 -- elsif C = POK_Task_Entry then
6834 -- procedure _clean is
6836 -- Cancel_Task_Entry_Call (U);
6842 -- _Disp_Asynchronous_Select
6843 -- (<object>, S, P'Address, D, B);
6844 -- Bnn := Communication_Bloc (D);
6846 -- Param1 := P.Param1;
6848 -- ParamN := P.ParamN;
6853 -- <abortable-statements>
6855 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6858 -- when Abort_Signal => Abort_Undefer;
6862 -- <triggering-statements>
6867 -- <dispatching-call>;
6868 -- <triggering-statements>
6873 -- The job is to convert this to the asynchronous form
6875 -- If the trigger is a delay statement, it will have been expanded into
6876 -- a call to one of the GNARL delay procedures. This routine will convert
6877 -- this into a protected entry call on a delay object and then continue
6878 -- processing as for a protected entry call trigger. This requires
6879 -- declaring a Delay_Block object and adding a pointer to this object to
6880 -- the parameter list of the delay procedure to form the parameter list of
6881 -- the entry call. This object is used by the runtime to queue the delay
6884 -- For a description of the use of P and the assignments after the call,
6885 -- see Expand_N_Entry_Call_Statement.
6887 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
6888 Loc : constant Source_Ptr := Sloc (N);
6889 Abrt : constant Node_Id := Abortable_Part (N);
6890 Trig : constant Node_Id := Triggering_Alternative (N);
6892 Abort_Block_Ent : Entity_Id;
6893 Abortable_Block : Node_Id;
6896 Blk_Ent : constant Entity_Id := Make_Temporary (Loc, 'A');
6897 Blk_Typ : Entity_Id;
6899 Call_Ent : Entity_Id;
6900 Cancel_Param : Entity_Id;
6901 Cleanup_Block : Node_Id;
6902 Cleanup_Block_Ent : Entity_Id;
6903 Cleanup_Stmts : List_Id;
6904 Conc_Typ_Stmts : List_Id;
6906 Dblock_Ent : Entity_Id;
6911 Enqueue_Call : Node_Id;
6914 Handler_Stmt : Node_Id;
6916 Lim_Typ_Stmts : List_Id;
6922 ProtE_Stmts : List_Id;
6923 ProtP_Stmts : List_Id;
6926 TaskE_Stmts : List_Id;
6929 B : Entity_Id; -- Call status flag
6930 Bnn : Entity_Id; -- Communication block
6931 C : Entity_Id; -- Call kind
6932 K : Entity_Id; -- Tagged kind
6933 P : Entity_Id; -- Parameter block
6934 S : Entity_Id; -- Primitive operation slot
6935 T : Entity_Id; -- Additional status flag
6937 procedure Rewrite_Abortable_Part;
6938 -- If the trigger is a dispatching call, the expansion inserts multiple
6939 -- copies of the abortable part. This is both inefficient, and may lead
6940 -- to duplicate definitions that the back-end will reject, when the
6941 -- abortable part includes loops. This procedure rewrites the abortable
6942 -- part into a call to a generated procedure.
6944 ----------------------------
6945 -- Rewrite_Abortable_Part --
6946 ----------------------------
6948 procedure Rewrite_Abortable_Part is
6949 Proc : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
6954 Make_Subprogram_Body (Loc,
6956 Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc),
6957 Declarations => New_List,
6958 Handled_Statement_Sequence =>
6959 Make_Handled_Sequence_Of_Statements (Loc, Astats));
6960 Insert_Before (N, Decl);
6963 -- Rewrite abortable part into a call to this procedure.
6967 Make_Procedure_Call_Statement (Loc,
6968 Name => New_Occurrence_Of (Proc, Loc)));
6969 end Rewrite_Abortable_Part;
6972 Process_Statements_For_Controlled_Objects (Trig);
6973 Process_Statements_For_Controlled_Objects (Abrt);
6975 Ecall := Triggering_Statement (Trig);
6977 Ensure_Statement_Present (Sloc (Ecall), Trig);
6979 -- Retrieve Astats and Tstats now because the finalization machinery may
6980 -- wrap them in blocks.
6982 Astats := Statements (Abrt);
6983 Tstats := Statements (Trig);
6985 -- The arguments in the call may require dynamic allocation, and the
6986 -- call statement may have been transformed into a block. The block
6987 -- may contain additional declarations for internal entities, and the
6988 -- original call is found by sequential search.
6990 if Nkind (Ecall) = N_Block_Statement then
6991 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
6992 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
6993 N_Entry_Call_Statement)
6999 -- This is either a dispatching call or a delay statement used as a
7000 -- trigger which was expanded into a procedure call.
7002 if Nkind (Ecall) = N_Procedure_Call_Statement then
7003 if Ada_Version >= Ada_2005
7005 (No (Original_Node (Ecall))
7006 or else not Nkind_In (Original_Node (Ecall),
7007 N_Delay_Relative_Statement,
7008 N_Delay_Until_Statement))
7010 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
7012 Rewrite_Abortable_Part;
7016 -- Call status flag processing, generate:
7017 -- B : Boolean := False;
7019 B := Build_B (Loc, Decls);
7021 -- Communication block processing, generate:
7022 -- Bnn : Communication_Block;
7024 Bnn := Make_Temporary (Loc, 'B');
7026 Make_Object_Declaration (Loc,
7027 Defining_Identifier => Bnn,
7028 Object_Definition =>
7029 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
7031 -- Call kind processing, generate:
7032 -- C : Ada.Tags.Prim_Op_Kind;
7034 C := Build_C (Loc, Decls);
7036 -- Tagged kind processing, generate:
7037 -- K : Ada.Tags.Tagged_Kind :=
7038 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7040 -- Dummy communication block, generate:
7041 -- D : Dummy_Communication_Block;
7044 Make_Object_Declaration (Loc,
7045 Defining_Identifier =>
7046 Make_Defining_Identifier (Loc, Name_uD),
7047 Object_Definition =>
7049 (RTE (RE_Dummy_Communication_Block), Loc)));
7051 K := Build_K (Loc, Decls, Obj);
7053 -- Parameter block processing
7055 Blk_Typ := Build_Parameter_Block
7056 (Loc, Actuals, Formals, Decls);
7057 P := Parameter_Block_Pack
7058 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7060 -- Dispatch table slot processing, generate:
7063 S := Build_S (Loc, Decls);
7065 -- Additional status flag processing, generate:
7068 T := Make_Temporary (Loc, 'T');
7070 Make_Object_Declaration (Loc,
7071 Defining_Identifier => T,
7072 Object_Definition =>
7073 New_Occurrence_Of (Standard_Boolean, Loc)));
7075 ------------------------------
7076 -- Protected entry handling --
7077 ------------------------------
7080 -- Param1 := P.Param1;
7082 -- ParamN := P.ParamN;
7084 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7087 -- Bnn := Communication_Block (D);
7089 Prepend_To (Cleanup_Stmts,
7090 Make_Assignment_Statement (Loc,
7091 Name => New_Occurrence_Of (Bnn, Loc),
7093 Make_Unchecked_Type_Conversion (Loc,
7095 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7096 Expression => Make_Identifier (Loc, Name_uD))));
7099 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7101 Prepend_To (Cleanup_Stmts,
7102 Make_Procedure_Call_Statement (Loc,
7106 (Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select),
7108 Parameter_Associations =>
7110 New_Copy_Tree (Obj), -- <object>
7111 New_Occurrence_Of (S, Loc), -- S
7112 Make_Attribute_Reference (Loc, -- P'Address
7113 Prefix => New_Occurrence_Of (P, Loc),
7114 Attribute_Name => Name_Address),
7115 Make_Identifier (Loc, Name_uD), -- D
7116 New_Occurrence_Of (B, Loc)))); -- B
7119 -- if Enqueued (Bnn) then
7120 -- <abortable-statements>
7123 Append_To (Cleanup_Stmts,
7124 Make_Implicit_If_Statement (N,
7126 Make_Function_Call (Loc,
7128 New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7129 Parameter_Associations =>
7130 New_List (New_Occurrence_Of (Bnn, Loc))),
7133 New_Copy_List_Tree (Astats)));
7135 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7136 -- will then generate a _clean for the communication block Bnn.
7140 -- procedure _clean is
7142 -- if Enqueued (Bnn) then
7143 -- Cancel_Protected_Entry_Call (Bnn);
7152 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7154 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
7156 -- Wrap the cleanup block in an exception handling block
7162 -- when Abort_Signal => Abort_Undefer;
7165 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7168 Make_Implicit_Label_Declaration (Loc,
7169 Defining_Identifier => Abort_Block_Ent),
7172 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7175 -- if not Cancelled (Bnn) then
7176 -- <triggering-statements>
7179 Append_To (ProtE_Stmts,
7180 Make_Implicit_If_Statement (N,
7184 Make_Function_Call (Loc,
7186 New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7187 Parameter_Associations =>
7188 New_List (New_Occurrence_Of (Bnn, Loc)))),
7191 New_Copy_List_Tree (Tstats)));
7193 -------------------------
7194 -- Task entry handling --
7195 -------------------------
7198 -- Param1 := P.Param1;
7200 -- ParamN := P.ParamN;
7202 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7205 -- Bnn := Communication_Block (D);
7207 Append_To (TaskE_Stmts,
7208 Make_Assignment_Statement (Loc,
7210 New_Occurrence_Of (Bnn, Loc),
7212 Make_Unchecked_Type_Conversion (Loc,
7214 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7215 Expression => Make_Identifier (Loc, Name_uD))));
7218 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7220 Prepend_To (TaskE_Stmts,
7221 Make_Procedure_Call_Statement (Loc,
7224 Find_Prim_Op (Etype (Etype (Obj)),
7225 Name_uDisp_Asynchronous_Select),
7228 Parameter_Associations =>
7230 New_Copy_Tree (Obj), -- <object>
7231 New_Occurrence_Of (S, Loc), -- S
7232 Make_Attribute_Reference (Loc, -- P'Address
7233 Prefix => New_Occurrence_Of (P, Loc),
7234 Attribute_Name => Name_Address),
7235 Make_Identifier (Loc, Name_uD), -- D
7236 New_Occurrence_Of (B, Loc)))); -- B
7241 Prepend_To (TaskE_Stmts,
7242 Make_Procedure_Call_Statement (Loc,
7243 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
7244 Parameter_Associations => No_List));
7248 -- <abortable-statements>
7250 Cleanup_Stmts := New_Copy_List_Tree (Astats);
7252 Prepend_To (Cleanup_Stmts,
7253 Make_Procedure_Call_Statement (Loc,
7254 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
7255 Parameter_Associations => No_List));
7257 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7258 -- will generate a _clean for the additional status flag.
7262 -- procedure _clean is
7264 -- Cancel_Task_Entry_Call (U);
7272 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7274 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
7276 -- Wrap the cleanup block in an exception handling block
7282 -- when Abort_Signal => Abort_Undefer;
7285 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7287 Append_To (TaskE_Stmts,
7288 Make_Implicit_Label_Declaration (Loc,
7289 Defining_Identifier => Abort_Block_Ent));
7291 Append_To (TaskE_Stmts,
7293 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7297 -- <triggering-statements>
7300 Append_To (TaskE_Stmts,
7301 Make_Implicit_If_Statement (N,
7303 Make_Op_Not (Loc, Right_Opnd => New_Occurrence_Of (T, Loc)),
7306 New_Copy_List_Tree (Tstats)));
7308 ----------------------------------
7309 -- Protected procedure handling --
7310 ----------------------------------
7313 -- <dispatching-call>;
7314 -- <triggering-statements>
7316 ProtP_Stmts := New_Copy_List_Tree (Tstats);
7317 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
7320 -- S := Ada.Tags.Get_Offset_Index
7321 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7324 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7327 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7329 Append_To (Conc_Typ_Stmts,
7330 Make_Procedure_Call_Statement (Loc,
7333 (Find_Prim_Op (Etype (Etype (Obj)),
7334 Name_uDisp_Get_Prim_Op_Kind),
7336 Parameter_Associations =>
7338 New_Copy_Tree (Obj),
7339 New_Occurrence_Of (S, Loc),
7340 New_Occurrence_Of (C, Loc))));
7343 -- if C = POK_Procedure_Entry then
7345 -- elsif C = POK_Task_Entry then
7351 Append_To (Conc_Typ_Stmts,
7352 Make_Implicit_If_Statement (N,
7356 New_Occurrence_Of (C, Loc),
7358 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
7365 Make_Elsif_Part (Loc,
7369 New_Occurrence_Of (C, Loc),
7371 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc)),
7380 -- <dispatching-call>;
7381 -- <triggering-statements>
7383 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
7384 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
7387 -- if K = Ada.Tags.TK_Limited_Tagged
7388 -- or else K = Ada.Tags.TK_Tagged
7396 Make_Implicit_If_Statement (N,
7397 Condition => Build_Dispatching_Tag_Check (K, N),
7398 Then_Statements => Lim_Typ_Stmts,
7399 Else_Statements => Conc_Typ_Stmts));
7402 Make_Block_Statement (Loc,
7405 Handled_Statement_Sequence =>
7406 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7411 -- Delay triggering statement processing
7414 -- Add a Delay_Block object to the parameter list of the delay
7415 -- procedure to form the parameter list of the Wait entry call.
7417 Dblock_Ent := Make_Temporary (Loc, 'D');
7419 Pdef := Entity (Name (Ecall));
7421 if Is_RTE (Pdef, RO_CA_Delay_For) then
7423 New_Occurrence_Of (RTE (RE_Enqueue_Duration), Loc);
7425 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
7427 New_Occurrence_Of (RTE (RE_Enqueue_Calendar), Loc);
7429 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
7430 Enqueue_Call := New_Occurrence_Of (RTE (RE_Enqueue_RT), Loc);
7433 Append_To (Parameter_Associations (Ecall),
7434 Make_Attribute_Reference (Loc,
7435 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7436 Attribute_Name => Name_Unchecked_Access));
7438 -- Create the inner block to protect the abortable part
7440 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7443 Make_Procedure_Call_Statement (Loc,
7444 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc)));
7447 Make_Block_Statement (Loc,
7448 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7449 Handled_Statement_Sequence =>
7450 Make_Handled_Sequence_Of_Statements (Loc,
7451 Statements => Astats),
7452 Has_Created_Identifier => True,
7453 Is_Asynchronous_Call_Block => True);
7455 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7458 Make_Implicit_If_Statement (N,
7460 Make_Function_Call (Loc,
7461 Name => Enqueue_Call,
7462 Parameter_Associations => Parameter_Associations (Ecall)),
7464 New_List (Make_Block_Statement (Loc,
7465 Handled_Statement_Sequence =>
7466 Make_Handled_Sequence_Of_Statements (Loc,
7467 Statements => New_List (
7468 Make_Implicit_Label_Declaration (Loc,
7469 Defining_Identifier => Blk_Ent,
7470 Label_Construct => Abortable_Block),
7472 Exception_Handlers => Hdle)))));
7474 Stmts := New_List (Ecall);
7476 -- Construct statement sequence for new block
7479 Make_Implicit_If_Statement (N,
7481 Make_Function_Call (Loc,
7482 Name => New_Occurrence_Of (
7483 RTE (RE_Timed_Out), Loc),
7484 Parameter_Associations => New_List (
7485 Make_Attribute_Reference (Loc,
7486 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7487 Attribute_Name => Name_Unchecked_Access))),
7488 Then_Statements => Tstats));
7490 -- The result is the new block
7492 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
7495 Make_Block_Statement (Loc,
7496 Declarations => New_List (
7497 Make_Object_Declaration (Loc,
7498 Defining_Identifier => Dblock_Ent,
7499 Aliased_Present => True,
7500 Object_Definition =>
7501 New_Occurrence_Of (RTE (RE_Delay_Block), Loc))),
7503 Handled_Statement_Sequence =>
7504 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7514 Extract_Entry (Ecall, Concval, Ename, Index);
7515 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
7517 Stmts := Statements (Handled_Statement_Sequence (Ecall));
7518 Decls := Declarations (Ecall);
7520 if Is_Protected_Type (Etype (Concval)) then
7522 -- Get the declarations of the block expanded from the entry call
7524 Decl := First (Decls);
7525 while Present (Decl)
7526 and then (Nkind (Decl) /= N_Object_Declaration
7527 or else not Is_RTE (Etype (Object_Definition (Decl)),
7528 RE_Communication_Block))
7533 pragma Assert (Present (Decl));
7534 Cancel_Param := Defining_Identifier (Decl);
7536 -- Change the mode of the Protected_Entry_Call call
7538 -- Protected_Entry_Call (
7539 -- Object => po._object'Access,
7540 -- E => <entry index>;
7541 -- Uninterpreted_Data => P'Address;
7542 -- Mode => Asynchronous_Call;
7545 -- Skip assignments to temporaries created for in-out parameters
7547 -- This makes unwarranted assumptions about the shape of the expanded
7548 -- tree for the call, and should be cleaned up ???
7550 Stmt := First (Stmts);
7551 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7557 Param := First (Parameter_Associations (Call));
7558 while Present (Param)
7559 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7564 pragma Assert (Present (Param));
7565 Rewrite (Param, New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7568 -- Append an if statement to execute the abortable part
7571 -- if Enqueued (Bnn) then
7574 Make_Implicit_If_Statement (N,
7576 Make_Function_Call (Loc,
7577 Name => New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7578 Parameter_Associations => New_List (
7579 New_Occurrence_Of (Cancel_Param, Loc))),
7580 Then_Statements => Astats));
7583 Make_Block_Statement (Loc,
7584 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7585 Handled_Statement_Sequence =>
7586 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts),
7587 Has_Created_Identifier => True,
7588 Is_Asynchronous_Call_Block => True);
7590 if Exception_Mechanism = Back_End_Exceptions then
7592 -- Aborts are not deferred at beginning of exception handlers
7595 Handler_Stmt := Make_Null_Statement (Loc);
7598 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
7599 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
7600 Parameter_Associations => No_List);
7604 Make_Block_Statement (Loc,
7605 Handled_Statement_Sequence =>
7606 Make_Handled_Sequence_Of_Statements (Loc,
7607 Statements => New_List (
7608 Make_Implicit_Label_Declaration (Loc,
7609 Defining_Identifier => Blk_Ent,
7610 Label_Construct => Abortable_Block),
7615 Exception_Handlers => New_List (
7616 Make_Implicit_Exception_Handler (Loc,
7618 -- when Abort_Signal =>
7619 -- Abort_Undefer.all;
7621 Exception_Choices =>
7622 New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)),
7623 Statements => New_List (Handler_Stmt))))),
7625 -- if not Cancelled (Bnn) then
7626 -- triggered statements
7629 Make_Implicit_If_Statement (N,
7630 Condition => Make_Op_Not (Loc,
7632 Make_Function_Call (Loc,
7633 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7634 Parameter_Associations => New_List (
7635 New_Occurrence_Of (Cancel_Param, Loc)))),
7636 Then_Statements => Tstats));
7638 -- Asynchronous task entry call
7645 B := Make_Defining_Identifier (Loc, Name_uB);
7647 -- Insert declaration of B in declarations of existing block
7650 Make_Object_Declaration (Loc,
7651 Defining_Identifier => B,
7652 Object_Definition =>
7653 New_Occurrence_Of (Standard_Boolean, Loc)));
7655 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
7657 -- Insert declaration of C in declarations of existing block
7660 Make_Object_Declaration (Loc,
7661 Defining_Identifier => Cancel_Param,
7662 Object_Definition =>
7663 New_Occurrence_Of (Standard_Boolean, Loc)));
7665 -- Remove and save the call to Call_Simple
7667 Stmt := First (Stmts);
7669 -- Skip assignments to temporaries created for in-out parameters.
7670 -- This makes unwarranted assumptions about the shape of the expanded
7671 -- tree for the call, and should be cleaned up ???
7673 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7679 -- Create the inner block to protect the abortable part
7681 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7684 Make_Procedure_Call_Statement (Loc,
7685 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc)));
7688 Make_Block_Statement (Loc,
7689 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7690 Handled_Statement_Sequence =>
7691 Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats),
7692 Has_Created_Identifier => True,
7693 Is_Asynchronous_Call_Block => True);
7696 Make_Block_Statement (Loc,
7697 Handled_Statement_Sequence =>
7698 Make_Handled_Sequence_Of_Statements (Loc,
7699 Statements => New_List (
7700 Make_Implicit_Label_Declaration (Loc,
7701 Defining_Identifier => Blk_Ent,
7702 Label_Construct => Abortable_Block),
7704 Exception_Handlers => Hdle)));
7706 -- Create new call statement
7708 Params := Parameter_Associations (Call);
7711 New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7712 Append_To (Params, New_Occurrence_Of (B, Loc));
7715 Make_Procedure_Call_Statement (Loc,
7716 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
7717 Parameter_Associations => Params));
7719 -- Construct statement sequence for new block
7722 Make_Implicit_If_Statement (N,
7724 Make_Op_Not (Loc, New_Occurrence_Of (Cancel_Param, Loc)),
7725 Then_Statements => Tstats));
7727 -- Protected the call against abort
7730 Make_Procedure_Call_Statement (Loc,
7731 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
7732 Parameter_Associations => Empty_List));
7735 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
7737 -- The result is the new block
7740 Make_Block_Statement (Loc,
7741 Declarations => Decls,
7742 Handled_Statement_Sequence =>
7743 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7746 end Expand_N_Asynchronous_Select;
7748 -------------------------------------
7749 -- Expand_N_Conditional_Entry_Call --
7750 -------------------------------------
7752 -- The conditional task entry call is converted to a call to
7757 -- P : parms := (parm, parm, parm);
7761 -- (<acceptor-task>, -- Acceptor
7762 -- <entry-index>, -- E
7763 -- P'Address, -- Uninterpreted_Data
7764 -- Conditional_Call, -- Mode
7765 -- B); -- Rendezvous_Successful
7770 -- normal-statements
7776 -- For a description of the use of P and the assignments after the call,
7777 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7778 -- conditional entry call has already been expanded (by the Expand_N_Entry
7779 -- _Call_Statement procedure) as follows:
7782 -- P : parms := (parm, parm, parm);
7784 -- ... info for in-out parameters
7785 -- Call_Simple (acceptor-task, entry-index, P'Address);
7791 -- so the task at hand is to convert the latter expansion into the former
7793 -- The conditional protected entry call is converted to a call to
7794 -- Protected_Entry_Call:
7797 -- P : parms := (parm, parm, parm);
7798 -- Bnn : Communications_Block;
7801 -- Protected_Entry_Call
7802 -- (po._object'Access, -- Object
7803 -- <entry index>, -- E
7804 -- P'Address, -- Uninterpreted_Data
7805 -- Conditional_Call, -- Mode
7810 -- if Cancelled (Bnn) then
7813 -- normal-statements
7817 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7821 -- B : Boolean := False;
7822 -- C : Ada.Tags.Prim_Op_Kind;
7823 -- K : Ada.Tags.Tagged_Kind :=
7824 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7825 -- P : Parameters := (Param1 .. ParamN);
7829 -- if K = Ada.Tags.TK_Limited_Tagged
7830 -- or else K = Ada.Tags.TK_Tagged
7832 -- <dispatching-call>;
7833 -- <triggering-statements>
7837 -- Ada.Tags.Get_Offset_Index
7838 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7840 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7842 -- if C = POK_Protected_Entry
7843 -- or else C = POK_Task_Entry
7845 -- Param1 := P.Param1;
7847 -- ParamN := P.ParamN;
7851 -- if C = POK_Procedure
7852 -- or else C = POK_Protected_Procedure
7853 -- or else C = POK_Task_Procedure
7855 -- <dispatching-call>;
7858 -- <triggering-statements>
7860 -- <else-statements>
7865 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
7866 Loc : constant Source_Ptr := Sloc (N);
7867 Alt : constant Node_Id := Entry_Call_Alternative (N);
7868 Blk : Node_Id := Entry_Call_Statement (Alt);
7871 Blk_Typ : Entity_Id;
7873 Call_Ent : Entity_Id;
7874 Conc_Typ_Stmts : List_Id;
7878 Lim_Typ_Stmts : List_Id;
7885 Transient_Blk : Node_Id;
7888 B : Entity_Id; -- Call status flag
7889 C : Entity_Id; -- Call kind
7890 K : Entity_Id; -- Tagged kind
7891 P : Entity_Id; -- Parameter block
7892 S : Entity_Id; -- Primitive operation slot
7895 Process_Statements_For_Controlled_Objects (N);
7897 if Ada_Version >= Ada_2005
7898 and then Nkind (Blk) = N_Procedure_Call_Statement
7900 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7905 -- Call status flag processing, generate:
7906 -- B : Boolean := False;
7908 B := Build_B (Loc, Decls);
7910 -- Call kind processing, generate:
7911 -- C : Ada.Tags.Prim_Op_Kind;
7913 C := Build_C (Loc, Decls);
7915 -- Tagged kind processing, generate:
7916 -- K : Ada.Tags.Tagged_Kind :=
7917 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7919 K := Build_K (Loc, Decls, Obj);
7921 -- Parameter block processing
7923 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7924 P := Parameter_Block_Pack
7925 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7927 -- Dispatch table slot processing, generate:
7930 S := Build_S (Loc, Decls);
7933 -- S := Ada.Tags.Get_Offset_Index
7934 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7937 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7940 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7942 Append_To (Conc_Typ_Stmts,
7943 Make_Procedure_Call_Statement (Loc,
7946 Find_Prim_Op (Etype (Etype (Obj)),
7947 Name_uDisp_Conditional_Select),
7949 Parameter_Associations =>
7951 New_Copy_Tree (Obj), -- <object>
7952 New_Occurrence_Of (S, Loc), -- S
7953 Make_Attribute_Reference (Loc, -- P'Address
7954 Prefix => New_Occurrence_Of (P, Loc),
7955 Attribute_Name => Name_Address),
7956 New_Occurrence_Of (C, Loc), -- C
7957 New_Occurrence_Of (B, Loc)))); -- B
7960 -- if C = POK_Protected_Entry
7961 -- or else C = POK_Task_Entry
7963 -- Param1 := P.Param1;
7965 -- ParamN := P.ParamN;
7968 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7970 -- Generate the if statement only when the packed parameters need
7971 -- explicit assignments to their corresponding actuals.
7973 if Present (Unpack) then
7974 Append_To (Conc_Typ_Stmts,
7975 Make_Implicit_If_Statement (N,
7981 New_Occurrence_Of (C, Loc),
7983 New_Occurrence_Of (RTE (
7984 RE_POK_Protected_Entry), Loc)),
7989 New_Occurrence_Of (C, Loc),
7991 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
7993 Then_Statements => Unpack));
7998 -- if C = POK_Procedure
7999 -- or else C = POK_Protected_Procedure
8000 -- or else C = POK_Task_Procedure
8002 -- <dispatching-call>
8004 -- <normal-statements>
8006 -- <else-statements>
8009 N_Stats := New_Copy_List_Tree (Statements (Alt));
8011 Prepend_To (N_Stats,
8012 Make_Implicit_If_Statement (N,
8018 New_Occurrence_Of (C, Loc),
8020 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
8027 New_Occurrence_Of (C, Loc),
8029 New_Occurrence_Of (RTE (
8030 RE_POK_Protected_Procedure), Loc)),
8035 New_Occurrence_Of (C, Loc),
8037 New_Occurrence_Of (RTE (
8038 RE_POK_Task_Procedure), Loc)))),
8043 Append_To (Conc_Typ_Stmts,
8044 Make_Implicit_If_Statement (N,
8045 Condition => New_Occurrence_Of (B, Loc),
8046 Then_Statements => N_Stats,
8047 Else_Statements => Else_Statements (N)));
8050 -- <dispatching-call>;
8051 -- <triggering-statements>
8053 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
8054 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
8057 -- if K = Ada.Tags.TK_Limited_Tagged
8058 -- or else K = Ada.Tags.TK_Tagged
8066 Make_Implicit_If_Statement (N,
8067 Condition => Build_Dispatching_Tag_Check (K, N),
8068 Then_Statements => Lim_Typ_Stmts,
8069 Else_Statements => Conc_Typ_Stmts));
8072 Make_Block_Statement (Loc,
8075 Handled_Statement_Sequence =>
8076 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8078 -- As described above, the entry alternative is transformed into a
8079 -- block that contains the gnulli call, and possibly assignment
8080 -- statements for in-out parameters. The gnulli call may itself be
8081 -- rewritten into a transient block if some unconstrained parameters
8082 -- require it. We need to retrieve the call to complete its parameter
8087 First_Real_Statement (Handled_Statement_Sequence (Blk));
8089 if Present (Transient_Blk)
8090 and then Nkind (Transient_Blk) = N_Block_Statement
8092 Blk := Transient_Blk;
8095 Stmts := Statements (Handled_Statement_Sequence (Blk));
8096 Stmt := First (Stmts);
8097 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
8102 Params := Parameter_Associations (Call);
8104 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
8106 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8108 Param := First (Params);
8109 while Present (Param)
8110 and then not Is_RTE (Etype (Param), RE_Call_Modes)
8115 pragma Assert (Present (Param));
8117 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
8121 -- Find the Communication_Block parameter for the call to the
8122 -- Cancelled function.
8124 Decl := First (Declarations (Blk));
8125 while Present (Decl)
8126 and then not Is_RTE (Etype (Object_Definition (Decl)),
8127 RE_Communication_Block)
8132 -- Add an if statement to execute the else part if the call
8133 -- does not succeed (as indicated by the Cancelled predicate).
8136 Make_Implicit_If_Statement (N,
8137 Condition => Make_Function_Call (Loc,
8138 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
8139 Parameter_Associations => New_List (
8140 New_Occurrence_Of (Defining_Identifier (Decl), Loc))),
8141 Then_Statements => Else_Statements (N),
8142 Else_Statements => Statements (Alt)));
8145 B := Make_Defining_Identifier (Loc, Name_uB);
8147 -- Insert declaration of B in declarations of existing block
8149 if No (Declarations (Blk)) then
8150 Set_Declarations (Blk, New_List);
8153 Prepend_To (Declarations (Blk),
8154 Make_Object_Declaration (Loc,
8155 Defining_Identifier => B,
8156 Object_Definition =>
8157 New_Occurrence_Of (Standard_Boolean, Loc)));
8159 -- Create new call statement
8162 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
8163 Append_To (Params, New_Occurrence_Of (B, Loc));
8166 Make_Procedure_Call_Statement (Loc,
8167 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
8168 Parameter_Associations => Params));
8170 -- Construct statement sequence for new block
8173 Make_Implicit_If_Statement (N,
8174 Condition => New_Occurrence_Of (B, Loc),
8175 Then_Statements => Statements (Alt),
8176 Else_Statements => Else_Statements (N)));
8179 -- The result is the new block
8182 Make_Block_Statement (Loc,
8183 Declarations => Declarations (Blk),
8184 Handled_Statement_Sequence =>
8185 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8189 end Expand_N_Conditional_Entry_Call;
8191 ---------------------------------------
8192 -- Expand_N_Delay_Relative_Statement --
8193 ---------------------------------------
8195 -- Delay statement is implemented as a procedure call to Delay_For
8196 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8197 -- simple delays imposed by the use of Protected Objects.
8199 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
8200 Loc : constant Source_Ptr := Sloc (N);
8203 Make_Procedure_Call_Statement (Loc,
8204 Name => New_Occurrence_Of (RTE (RO_CA_Delay_For), Loc),
8205 Parameter_Associations => New_List (Expression (N))));
8207 end Expand_N_Delay_Relative_Statement;
8209 ------------------------------------
8210 -- Expand_N_Delay_Until_Statement --
8211 ------------------------------------
8213 -- Delay Until statement is implemented as a procedure call to
8214 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8216 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
8217 Loc : constant Source_Ptr := Sloc (N);
8221 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
8222 Typ := RTE (RO_CA_Delay_Until);
8224 Typ := RTE (RO_RT_Delay_Until);
8228 Make_Procedure_Call_Statement (Loc,
8229 Name => New_Occurrence_Of (Typ, Loc),
8230 Parameter_Associations => New_List (Expression (N))));
8233 end Expand_N_Delay_Until_Statement;
8235 -------------------------
8236 -- Expand_N_Entry_Body --
8237 -------------------------
8239 procedure Expand_N_Entry_Body (N : Node_Id) is
8241 -- Associate discriminals with the next protected operation body to be
8244 if Present (Next_Protected_Operation (N)) then
8245 Set_Discriminals (Parent (Current_Scope));
8247 end Expand_N_Entry_Body;
8249 -----------------------------------
8250 -- Expand_N_Entry_Call_Statement --
8251 -----------------------------------
8253 -- An entry call is expanded into GNARLI calls to implement a simple entry
8254 -- call (see Build_Simple_Entry_Call).
8256 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
8262 if No_Run_Time_Mode then
8263 Error_Msg_CRT ("entry call", N);
8267 -- If this entry call is part of an asynchronous select, don't expand it
8268 -- here; it will be expanded with the select statement. Don't expand
8269 -- timed entry calls either, as they are translated into asynchronous
8272 -- ??? This whole approach is questionable; it may be better to go back
8273 -- to allowing the expansion to take place and then attempting to fix it
8274 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8275 -- whether the expanded call is on a task or protected entry.
8277 if (Nkind (Parent (N)) /= N_Triggering_Alternative
8278 or else N /= Triggering_Statement (Parent (N)))
8279 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
8280 or else N /= Entry_Call_Statement (Parent (N))
8281 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
8283 Extract_Entry (N, Concval, Ename, Index);
8284 Build_Simple_Entry_Call (N, Concval, Ename, Index);
8286 end Expand_N_Entry_Call_Statement;
8288 --------------------------------
8289 -- Expand_N_Entry_Declaration --
8290 --------------------------------
8292 -- If there are parameters, then first, each of the formals is marked by
8293 -- setting Is_Entry_Formal. Next a record type is built which is used to
8294 -- hold the parameter values. The name of this record type is entryP where
8295 -- entry is the name of the entry, with an additional corresponding access
8296 -- type called entryPA. The record type has matching components for each
8297 -- formal (the component names are the same as the formal names). For
8298 -- elementary types, the component type matches the formal type. For
8299 -- composite types, an access type is declared (with the name formalA)
8300 -- which designates the formal type, and the type of the component is this
8301 -- access type. Finally the Entry_Component of each formal is set to
8302 -- reference the corresponding record component.
8304 procedure Expand_N_Entry_Declaration (N : Node_Id) is
8305 Loc : constant Source_Ptr := Sloc (N);
8306 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
8307 Components : List_Id;
8310 Last_Decl : Node_Id;
8311 Component : Entity_Id;
8314 Rec_Ent : Entity_Id;
8315 Acc_Ent : Entity_Id;
8318 Formal := First_Formal (Entry_Ent);
8321 -- Most processing is done only if parameters are present
8323 if Present (Formal) then
8324 Components := New_List;
8326 -- Loop through formals
8328 while Present (Formal) loop
8329 Set_Is_Entry_Formal (Formal);
8331 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
8332 Set_Entry_Component (Formal, Component);
8333 Set_Entry_Formal (Component, Formal);
8334 Ftype := Etype (Formal);
8336 -- Declare new access type and then append
8338 Ctype := Make_Temporary (Loc, 'A');
8339 Set_Is_Param_Block_Component_Type (Ctype);
8342 Make_Full_Type_Declaration (Loc,
8343 Defining_Identifier => Ctype,
8345 Make_Access_To_Object_Definition (Loc,
8346 All_Present => True,
8347 Constant_Present => Ekind (Formal) = E_In_Parameter,
8348 Subtype_Indication => New_Occurrence_Of (Ftype, Loc)));
8350 Insert_After (Last_Decl, Decl);
8353 Append_To (Components,
8354 Make_Component_Declaration (Loc,
8355 Defining_Identifier => Component,
8356 Component_Definition =>
8357 Make_Component_Definition (Loc,
8358 Aliased_Present => False,
8359 Subtype_Indication => New_Occurrence_Of (Ctype, Loc))));
8361 Next_Formal_With_Extras (Formal);
8364 -- Create the Entry_Parameter_Record declaration
8366 Rec_Ent := Make_Temporary (Loc, 'P');
8369 Make_Full_Type_Declaration (Loc,
8370 Defining_Identifier => Rec_Ent,
8372 Make_Record_Definition (Loc,
8374 Make_Component_List (Loc,
8375 Component_Items => Components)));
8377 Insert_After (Last_Decl, Decl);
8380 -- Construct and link in the corresponding access type
8382 Acc_Ent := Make_Temporary (Loc, 'A');
8384 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
8387 Make_Full_Type_Declaration (Loc,
8388 Defining_Identifier => Acc_Ent,
8390 Make_Access_To_Object_Definition (Loc,
8391 All_Present => True,
8392 Subtype_Indication => New_Occurrence_Of (Rec_Ent, Loc)));
8394 Insert_After (Last_Decl, Decl);
8396 end Expand_N_Entry_Declaration;
8398 -----------------------------
8399 -- Expand_N_Protected_Body --
8400 -----------------------------
8402 -- Protected bodies are expanded to the completion of the subprograms
8403 -- created for the corresponding protected type. These are a protected and
8404 -- unprotected version of each protected subprogram in the object, a
8405 -- function to calculate each entry barrier, and a procedure to execute the
8406 -- sequence of statements of each protected entry body. For example, for
8407 -- protected type ptype:
8410 -- (O : System.Address;
8411 -- E : Protected_Entry_Index)
8414 -- <discriminant renamings>
8415 -- <private object renamings>
8417 -- return <barrier expression>;
8420 -- procedure pprocN (_object : in out poV;...) is
8421 -- <discriminant renamings>
8422 -- <private object renamings>
8424 -- <sequence of statements>
8427 -- procedure pprocP (_object : in out poV;...) is
8428 -- procedure _clean is
8431 -- ptypeS (_object, Pn);
8432 -- Unlock (_object._object'Access);
8433 -- Abort_Undefer.all;
8438 -- Lock (_object._object'Access);
8439 -- pprocN (_object;...);
8444 -- function pfuncN (_object : poV;...) return Return_Type is
8445 -- <discriminant renamings>
8446 -- <private object renamings>
8448 -- <sequence of statements>
8451 -- function pfuncP (_object : poV) return Return_Type is
8452 -- procedure _clean is
8454 -- Unlock (_object._object'Access);
8455 -- Abort_Undefer.all;
8460 -- Lock (_object._object'Access);
8461 -- return pfuncN (_object);
8468 -- (O : System.Address;
8469 -- P : System.Address;
8470 -- E : Protected_Entry_Index)
8472 -- <discriminant renamings>
8473 -- <private object renamings>
8474 -- type poVP is access poV;
8475 -- _Object : ptVP := ptVP!(O);
8479 -- <statement sequence>
8480 -- Complete_Entry_Body (_Object._Object);
8482 -- when all others =>
8483 -- Exceptional_Complete_Entry_Body (
8484 -- _Object._Object, Get_GNAT_Exception);
8488 -- The type poV is the record created for the protected type to hold
8489 -- the state of the protected object.
8491 procedure Expand_N_Protected_Body (N : Node_Id) is
8492 Loc : constant Source_Ptr := Sloc (N);
8493 Pid : constant Entity_Id := Corresponding_Spec (N);
8495 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Pid);
8496 -- This flag indicates whether the lock free implementation is active
8498 Current_Node : Node_Id;
8499 Disp_Op_Body : Node_Id;
8500 New_Op_Body : Node_Id;
8504 function Build_Dispatching_Subprogram_Body
8507 Prot_Bod : Node_Id) return Node_Id;
8508 -- Build a dispatching version of the protected subprogram body. The
8509 -- newly generated subprogram contains a call to the original protected
8510 -- body. The following code is generated:
8512 -- function <protected-function-name> (Param1 .. ParamN) return
8515 -- return <protected-function-name>P (Param1 .. ParamN);
8516 -- end <protected-function-name>;
8520 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8522 -- <protected-procedure-name>P (Param1 .. ParamN);
8523 -- end <protected-procedure-name>
8525 ---------------------------------------
8526 -- Build_Dispatching_Subprogram_Body --
8527 ---------------------------------------
8529 function Build_Dispatching_Subprogram_Body
8532 Prot_Bod : Node_Id) return Node_Id
8534 Loc : constant Source_Ptr := Sloc (N);
8541 -- Generate a specification without a letter suffix in order to
8542 -- override an interface function or procedure.
8544 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
8546 -- The formal parameters become the actuals of the protected function
8547 -- or procedure call.
8549 Actuals := New_List;
8550 Formal := First (Parameter_Specifications (Spec));
8551 while Present (Formal) loop
8553 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8557 if Nkind (Spec) = N_Procedure_Specification then
8560 Make_Procedure_Call_Statement (Loc,
8562 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8563 Parameter_Associations => Actuals));
8566 pragma Assert (Nkind (Spec) = N_Function_Specification);
8570 Make_Simple_Return_Statement (Loc,
8572 Make_Function_Call (Loc,
8574 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8575 Parameter_Associations => Actuals)));
8579 Make_Subprogram_Body (Loc,
8580 Declarations => Empty_List,
8581 Specification => Spec,
8582 Handled_Statement_Sequence =>
8583 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
8584 end Build_Dispatching_Subprogram_Body;
8586 -- Start of processing for Expand_N_Protected_Body
8589 if No_Run_Time_Mode then
8590 Error_Msg_CRT ("protected body", N);
8594 -- This is the proper body corresponding to a stub. The declarations
8595 -- must be inserted at the point of the stub, which in turn is in the
8596 -- declarative part of the parent unit.
8598 if Nkind (Parent (N)) = N_Subunit then
8599 Current_Node := Corresponding_Stub (Parent (N));
8604 Op_Body := First (Declarations (N));
8606 -- The protected body is replaced with the bodies of its
8607 -- protected operations, and the declarations for internal objects
8608 -- that may have been created for entry family bounds.
8610 Rewrite (N, Make_Null_Statement (Sloc (N)));
8613 while Present (Op_Body) loop
8614 case Nkind (Op_Body) is
8615 when N_Subprogram_Declaration =>
8618 when N_Subprogram_Body =>
8620 -- Do not create bodies for eliminated operations
8622 if not Is_Eliminated (Defining_Entity (Op_Body))
8623 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
8625 if Lock_Free_Active then
8627 Build_Lock_Free_Unprotected_Subprogram_Body
8631 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
8634 Insert_After (Current_Node, New_Op_Body);
8635 Current_Node := New_Op_Body;
8636 Analyze (New_Op_Body);
8638 -- Build the corresponding protected operation. It may
8639 -- appear that this is needed only if this is a visible
8640 -- operation of the type, or if it is an interrupt handler,
8641 -- and this was the strategy used previously in GNAT.
8643 -- However, the operation may be exported through a 'Access
8644 -- to an external caller. This is the common idiom in code
8645 -- that uses the Ada 2005 Timing_Events package. As a result
8646 -- we need to produce the protected body for both visible
8647 -- and private operations, as well as operations that only
8648 -- have a body in the source, and for which we create a
8649 -- declaration in the protected body itself.
8651 if Present (Corresponding_Spec (Op_Body)) then
8652 if Lock_Free_Active then
8654 Build_Lock_Free_Protected_Subprogram_Body
8655 (Op_Body, Pid, Specification (New_Op_Body));
8658 Build_Protected_Subprogram_Body
8659 (Op_Body, Pid, Specification (New_Op_Body));
8662 Insert_After (Current_Node, New_Op_Body);
8663 Analyze (New_Op_Body);
8665 Current_Node := New_Op_Body;
8667 -- Generate an overriding primitive operation body for
8668 -- this subprogram if the protected type implements an
8671 if Ada_Version >= Ada_2005
8673 Present (Interfaces (Corresponding_Record_Type (Pid)))
8676 Build_Dispatching_Subprogram_Body
8677 (Op_Body, Pid, New_Op_Body);
8679 Insert_After (Current_Node, Disp_Op_Body);
8680 Analyze (Disp_Op_Body);
8682 Current_Node := Disp_Op_Body;
8687 when N_Entry_Body =>
8688 Op_Id := Defining_Identifier (Op_Body);
8689 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
8691 Insert_After (Current_Node, New_Op_Body);
8692 Current_Node := New_Op_Body;
8693 Analyze (New_Op_Body);
8695 when N_Implicit_Label_Declaration =>
8698 when N_Itype_Reference =>
8699 Insert_After (Current_Node, New_Copy (Op_Body));
8701 when N_Freeze_Entity =>
8702 New_Op_Body := New_Copy (Op_Body);
8704 if Present (Entity (Op_Body))
8705 and then Freeze_Node (Entity (Op_Body)) = Op_Body
8707 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
8710 Insert_After (Current_Node, New_Op_Body);
8711 Current_Node := New_Op_Body;
8712 Analyze (New_Op_Body);
8715 New_Op_Body := New_Copy (Op_Body);
8716 Insert_After (Current_Node, New_Op_Body);
8717 Current_Node := New_Op_Body;
8718 Analyze (New_Op_Body);
8720 when N_Object_Declaration =>
8721 pragma Assert (not Comes_From_Source (Op_Body));
8722 New_Op_Body := New_Copy (Op_Body);
8723 Insert_After (Current_Node, New_Op_Body);
8724 Current_Node := New_Op_Body;
8725 Analyze (New_Op_Body);
8728 raise Program_Error;
8735 -- Finally, create the body of the function that maps an entry index
8736 -- into the corresponding body index, except when there is no entry, or
8737 -- in a Ravenscar-like profile.
8739 if Corresponding_Runtime_Package (Pid) =
8740 System_Tasking_Protected_Objects_Entries
8742 New_Op_Body := Build_Find_Body_Index (Pid);
8743 Insert_After (Current_Node, New_Op_Body);
8744 Current_Node := New_Op_Body;
8745 Analyze (New_Op_Body);
8748 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8749 -- protected body. At this point all wrapper specs have been created,
8750 -- frozen and included in the dispatch table for the protected type.
8752 if Ada_Version >= Ada_2005 then
8753 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
8755 end Expand_N_Protected_Body;
8757 -----------------------------------------
8758 -- Expand_N_Protected_Type_Declaration --
8759 -----------------------------------------
8761 -- First we create a corresponding record type declaration used to
8762 -- represent values of this protected type.
8763 -- The general form of this type declaration is
8765 -- type poV (discriminants) is record
8766 -- _Object : aliased <kind>Protection
8767 -- [(<entry count> [, <handler count>])];
8768 -- [entry_family : array (bounds) of Void;]
8769 -- <private data fields>
8772 -- The discriminants are present only if the corresponding protected type
8773 -- has discriminants, and they exactly mirror the protected type
8774 -- discriminants. The private data fields similarly mirror the private
8775 -- declarations of the protected type.
8777 -- The Object field is always present. It contains RTS specific data used
8778 -- to control the protected object. It is declared as Aliased so that it
8779 -- can be passed as a pointer to the RTS. This allows the protected record
8780 -- to be referenced within RTS data structures. An appropriate Protection
8781 -- type and discriminant are generated.
8783 -- The Service field is present for protected objects with entries. It
8784 -- contains sufficient information to allow the entry service procedure for
8785 -- this object to be called when the object is not known till runtime.
8787 -- One entry_family component is present for each entry family in the
8788 -- task definition (see Expand_N_Task_Type_Declaration).
8790 -- When a protected object is declared, an instance of the protected type
8791 -- value record is created. The elaboration of this declaration creates the
8792 -- correct bounds for the entry families, and also evaluates the priority
8793 -- expression if needed. The initialization routine for the protected type
8794 -- itself then calls Initialize_Protection with appropriate parameters to
8795 -- initialize the value of the Task_Id field. Install_Handlers may be also
8796 -- called if a pragma Attach_Handler applies.
8798 -- Note: this record is passed to the subprograms created by the expansion
8799 -- of protected subprograms and entries. It is an in parameter to protected
8800 -- functions and an in out parameter to procedures and entry bodies. The
8801 -- Entity_Id for this created record type is placed in the
8802 -- Corresponding_Record_Type field of the associated protected type entity.
8804 -- Next we create a procedure specifications for protected subprograms and
8805 -- entry bodies. For each protected subprograms two subprograms are
8806 -- created, an unprotected and a protected version. The unprotected version
8807 -- is called from within other operations of the same protected object.
8809 -- We also build the call to register the procedure if a pragma
8810 -- Interrupt_Handler applies.
8812 -- A single subprogram is created to service all entry bodies; it has an
8813 -- additional boolean out parameter indicating that the previous entry call
8814 -- made by the current task was serviced immediately, i.e. not by proxy.
8815 -- The O parameter contains a pointer to a record object of the type
8816 -- described above. An untyped interface is used here to allow this
8817 -- procedure to be called in places where the type of the object to be
8818 -- serviced is not known. This must be done, for example, when a call that
8819 -- may have been requeued is cancelled; the corresponding object must be
8820 -- serviced, but which object that is not known till runtime.
8823 -- (O : System.Address; P : out Boolean);
8824 -- procedure pprocN (_object : in out poV);
8825 -- procedure pproc (_object : in out poV);
8826 -- function pfuncN (_object : poV);
8827 -- function pfunc (_object : poV);
8830 -- Note that this must come after the record type declaration, since
8831 -- the specs refer to this type.
8833 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
8834 Discr_Map : constant Elist_Id := New_Elmt_List;
8835 Loc : constant Source_Ptr := Sloc (N);
8836 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
8838 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Prot_Typ);
8839 -- This flag indicates whether the lock free implementation is active
8841 Pdef : constant Node_Id := Protected_Definition (N);
8842 -- This contains two lists; one for visible and one for private decls
8845 Body_Id : Entity_Id;
8848 Comp_Id : Entity_Id;
8849 Current_Node : Node_Id := N;
8851 Entries_Aggr : Node_Id;
8853 Object_Comp : Node_Id;
8858 procedure Check_Inlining (Subp : Entity_Id);
8859 -- If the original operation has a pragma Inline, propagate the flag
8860 -- to the internal body, for possible inlining later on. The source
8861 -- operation is invisible to the back-end and is never actually called.
8863 function Discriminated_Size (Comp : Entity_Id) return Boolean;
8864 -- If a component size is not static then a warning will be emitted
8865 -- in Ravenscar or other restricted contexts. When a component is non-
8866 -- static because of a discriminant constraint we can specialize the
8867 -- warning by mentioning discriminants explicitly.
8869 procedure Expand_Entry_Declaration (Comp : Entity_Id);
8870 -- Create the subprograms for the barrier and for the body, and append
8871 -- then to Entry_Bodies_Array.
8873 function Static_Component_Size (Comp : Entity_Id) return Boolean;
8874 -- When compiling under the Ravenscar profile, private components must
8875 -- have a static size, or else a protected object will require heap
8876 -- allocation, violating the corresponding restriction. It is preferable
8877 -- to make this check here, because it provides a better error message
8878 -- than the back-end, which refers to the object as a whole.
8880 procedure Register_Handler;
8881 -- For a protected operation that is an interrupt handler, add the
8882 -- freeze action that will register it as such.
8884 --------------------
8885 -- Check_Inlining --
8886 --------------------
8888 procedure Check_Inlining (Subp : Entity_Id) is
8890 if Is_Inlined (Subp) then
8891 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8892 Set_Is_Inlined (Subp, False);
8896 ------------------------
8897 -- Discriminated_Size --
8898 ------------------------
8900 function Discriminated_Size (Comp : Entity_Id) return Boolean is
8901 Typ : constant Entity_Id := Etype (Comp);
8904 function Non_Static_Bound (Bound : Node_Id) return Boolean;
8905 -- Check whether the bound of an index is non-static and does denote
8906 -- a discriminant, in which case any protected object of the type
8907 -- will have a non-static size.
8909 ----------------------
8910 -- Non_Static_Bound --
8911 ----------------------
8913 function Non_Static_Bound (Bound : Node_Id) return Boolean is
8915 if Is_OK_Static_Expression (Bound) then
8918 elsif Is_Entity_Name (Bound)
8919 and then Present (Discriminal_Link (Entity (Bound)))
8926 end Non_Static_Bound;
8928 -- Start of processing for Discriminated_Size
8931 if not Is_Array_Type (Typ) then
8935 if Ekind (Typ) = E_Array_Subtype then
8936 Index := First_Index (Typ);
8937 while Present (Index) loop
8938 if Non_Static_Bound (Low_Bound (Index))
8939 or else Non_Static_Bound (High_Bound (Index))
8951 end Discriminated_Size;
8953 ---------------------------
8954 -- Static_Component_Size --
8955 ---------------------------
8957 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8958 Typ : constant Entity_Id := Etype (Comp);
8962 if Is_Scalar_Type (Typ) then
8965 elsif Is_Array_Type (Typ) then
8966 return Compile_Time_Known_Bounds (Typ);
8968 elsif Is_Record_Type (Typ) then
8969 C := First_Component (Typ);
8970 while Present (C) loop
8971 if not Static_Component_Size (C) then
8980 -- Any other type will be checked by the back-end
8985 end Static_Component_Size;
8987 ------------------------------
8988 -- Expand_Entry_Declaration --
8989 ------------------------------
8991 procedure Expand_Entry_Declaration (Comp : Entity_Id) is
8996 E_Count := E_Count + 1;
8997 Comp_Id := Defining_Identifier (Comp);
9000 Make_Defining_Identifier (Loc,
9001 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
9003 Make_Subprogram_Declaration (Loc,
9005 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
9007 Insert_After (Current_Node, Sub);
9010 -- Build wrapper procedure for pre/postconditions
9012 Build_PPC_Wrapper (Comp_Id, N);
9014 Set_Protected_Body_Subprogram
9015 (Defining_Identifier (Comp),
9016 Defining_Unit_Name (Specification (Sub)));
9018 Current_Node := Sub;
9021 Make_Defining_Identifier (Loc,
9022 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
9024 Make_Subprogram_Declaration (Loc,
9026 Build_Barrier_Function_Specification (Loc, Bdef));
9027 Set_Is_Entry_Barrier_Function (Sub);
9029 Insert_After (Current_Node, Sub);
9031 Set_Protected_Body_Subprogram (Bdef, Bdef);
9032 Set_Barrier_Function (Comp_Id, Bdef);
9033 Set_Scope (Bdef, Scope (Comp_Id));
9034 Current_Node := Sub;
9036 -- Collect pointers to the protected subprogram and the barrier
9037 -- of the current entry, for insertion into Entry_Bodies_Array.
9039 Append_To (Expressions (Entries_Aggr),
9040 Make_Aggregate (Loc,
9041 Expressions => New_List (
9042 Make_Attribute_Reference (Loc,
9043 Prefix => New_Occurrence_Of (Bdef, Loc),
9044 Attribute_Name => Name_Unrestricted_Access),
9045 Make_Attribute_Reference (Loc,
9046 Prefix => New_Occurrence_Of (Edef, Loc),
9047 Attribute_Name => Name_Unrestricted_Access))));
9048 end Expand_Entry_Declaration;
9050 ----------------------
9051 -- Register_Handler --
9052 ----------------------
9054 procedure Register_Handler is
9056 -- All semantic checks already done in Sem_Prag
9058 Prot_Proc : constant Entity_Id :=
9059 Defining_Unit_Name (Specification (Current_Node));
9061 Proc_Address : constant Node_Id :=
9062 Make_Attribute_Reference (Loc,
9064 New_Occurrence_Of (Prot_Proc, Loc),
9065 Attribute_Name => Name_Address);
9067 RTS_Call : constant Entity_Id :=
9068 Make_Procedure_Call_Statement (Loc,
9071 (RTE (RE_Register_Interrupt_Handler), Loc),
9072 Parameter_Associations => New_List (Proc_Address));
9074 Append_Freeze_Action (Prot_Proc, RTS_Call);
9075 end Register_Handler;
9077 -- Start of processing for Expand_N_Protected_Type_Declaration
9080 if Present (Corresponding_Record_Type (Prot_Typ)) then
9083 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
9086 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
9088 Qualify_Entity_Names (N);
9090 -- If the type has discriminants, their occurrences in the declaration
9091 -- have been replaced by the corresponding discriminals. For components
9092 -- that are constrained by discriminants, their homologues in the
9093 -- corresponding record type must refer to the discriminants of that
9094 -- record, so we must apply a new renaming to subtypes_indications:
9096 -- protected discriminant => discriminal => record discriminant
9098 -- This replacement is not applied to default expressions, for which
9099 -- the discriminal is correct.
9101 if Has_Discriminants (Prot_Typ) then
9107 Disc := First_Discriminant (Prot_Typ);
9108 Decl := First (Discriminant_Specifications (Rec_Decl));
9109 while Present (Disc) loop
9110 Append_Elmt (Discriminal (Disc), Discr_Map);
9111 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
9112 Next_Discriminant (Disc);
9118 -- Fill in the component declarations
9120 -- Add components for entry families. For each entry family, create an
9121 -- anonymous type declaration with the same size, and analyze the type.
9123 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
9125 pragma Assert (Present (Pdef));
9127 -- Add private field components
9129 if Present (Private_Declarations (Pdef)) then
9130 Priv := First (Private_Declarations (Pdef));
9131 while Present (Priv) loop
9132 if Nkind (Priv) = N_Component_Declaration then
9133 if not Static_Component_Size (Defining_Identifier (Priv)) then
9135 -- When compiling for a restricted profile, the private
9136 -- components must have a static size. If not, this is an
9137 -- error for a single protected declaration, and rates a
9138 -- warning on a protected type declaration.
9140 if not Comes_From_Source (Prot_Typ) then
9142 -- It's ok to be checking this restriction at expansion
9143 -- time, because this is only for the restricted profile,
9144 -- which is not subject to strict RM conformance, so it
9145 -- is OK to miss this check in -gnatc mode.
9147 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
9149 (No_Implicit_Protected_Object_Allocations, Priv);
9151 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
9152 if not Discriminated_Size (Defining_Identifier (Priv))
9154 -- Any object of the type will be non-static.
9156 Error_Msg_N ("component has non-static size??", Priv);
9158 ("\creation of protected object of type& will "
9159 & "violate restriction "
9160 & "No_Implicit_Heap_Allocations??", Priv, Prot_Typ);
9163 -- Object will be non-static if discriminants are.
9166 ("creation of protected object of type& with "
9167 & "non-static discriminants will violate"
9168 & " restriction No_Implicit_Heap_Allocations??",
9172 -- Likewise for No_Implicit_Protected_Object_Allocations
9174 elsif Restriction_Active
9175 (No_Implicit_Protected_Object_Allocations)
9177 if not Discriminated_Size (Defining_Identifier (Priv))
9179 -- Any object of the type will be non-static.
9181 Error_Msg_N ("component has non-static size??", Priv);
9183 ("\creation of protected object of type& will "
9184 & "violate restriction "
9185 & "No_Implicit_Protected_Object_Allocations??",
9188 -- Object will be non-static if discriminants are.
9191 ("creation of protected object of type& with "
9192 & "non-static discriminants will violate "
9194 & "No_Implicit_Protected_Object_Allocations??",
9200 -- The component definition consists of a subtype indication,
9201 -- or (in Ada 2005) an access definition. Make a copy of the
9202 -- proper definition.
9205 Old_Comp : constant Node_Id := Component_Definition (Priv);
9206 Oent : constant Entity_Id := Defining_Identifier (Priv);
9207 Nent : constant Entity_Id :=
9208 Make_Defining_Identifier (Sloc (Oent),
9209 Chars => Chars (Oent));
9213 if Present (Subtype_Indication (Old_Comp)) then
9215 Make_Component_Definition (Sloc (Oent),
9216 Aliased_Present => False,
9217 Subtype_Indication =>
9219 (Subtype_Indication (Old_Comp), Discr_Map));
9222 Make_Component_Definition (Sloc (Oent),
9223 Aliased_Present => False,
9224 Access_Definition =>
9226 (Access_Definition (Old_Comp), Discr_Map));
9230 Make_Component_Declaration (Loc,
9231 Defining_Identifier => Nent,
9232 Component_Definition => New_Comp,
9233 Expression => Expression (Priv));
9235 Set_Has_Per_Object_Constraint (Nent,
9236 Has_Per_Object_Constraint (Oent));
9238 Append_To (Cdecls, New_Priv);
9241 elsif Nkind (Priv) = N_Subprogram_Declaration then
9243 -- Make the unprotected version of the subprogram available
9244 -- for expansion of intra object calls. There is need for
9245 -- a protected version only if the subprogram is an interrupt
9246 -- handler, otherwise this operation can only be called from
9250 Make_Subprogram_Declaration (Loc,
9252 Build_Protected_Sub_Specification
9253 (Priv, Prot_Typ, Unprotected_Mode));
9255 Insert_After (Current_Node, Sub);
9258 Set_Protected_Body_Subprogram
9259 (Defining_Unit_Name (Specification (Priv)),
9260 Defining_Unit_Name (Specification (Sub)));
9261 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
9262 Current_Node := Sub;
9265 Make_Subprogram_Declaration (Loc,
9267 Build_Protected_Sub_Specification
9268 (Priv, Prot_Typ, Protected_Mode));
9270 Insert_After (Current_Node, Sub);
9272 Current_Node := Sub;
9274 if Is_Interrupt_Handler
9275 (Defining_Unit_Name (Specification (Priv)))
9277 if not Restricted_Profile then
9287 -- Except for the lock-free implementation, append the _Object field
9288 -- with the right type to the component list. We need to compute the
9289 -- number of entries, and in some cases the number of Attach_Handler
9292 if not Lock_Free_Active then
9294 Entry_Count_Expr : constant Node_Id :=
9295 Build_Entry_Count_Expression
9296 (Prot_Typ, Cdecls, Loc);
9297 Num_Attach_Handler : Int := 0;
9298 Protection_Subtype : Node_Id;
9302 if Has_Attach_Handler (Prot_Typ) then
9303 Ritem := First_Rep_Item (Prot_Typ);
9304 while Present (Ritem) loop
9305 if Nkind (Ritem) = N_Pragma
9306 and then Pragma_Name (Ritem) = Name_Attach_Handler
9308 Num_Attach_Handler := Num_Attach_Handler + 1;
9311 Next_Rep_Item (Ritem);
9315 -- Determine the proper protection type. There are two special
9316 -- cases: 1) when the protected type has dynamic interrupt
9317 -- handlers, and 2) when it has static handlers and we use a
9318 -- restricted profile.
9320 if Has_Attach_Handler (Prot_Typ)
9321 and then not Restricted_Profile
9323 Protection_Subtype :=
9324 Make_Subtype_Indication (Loc,
9327 (RTE (RE_Static_Interrupt_Protection), Loc),
9329 Make_Index_Or_Discriminant_Constraint (Loc,
9330 Constraints => New_List (
9332 Make_Integer_Literal (Loc, Num_Attach_Handler))));
9334 elsif Has_Interrupt_Handler (Prot_Typ)
9335 and then not Restriction_Active (No_Dynamic_Attachment)
9337 Protection_Subtype :=
9338 Make_Subtype_Indication (Loc,
9341 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
9343 Make_Index_Or_Discriminant_Constraint (Loc,
9344 Constraints => New_List (Entry_Count_Expr)));
9347 case Corresponding_Runtime_Package (Prot_Typ) is
9348 when System_Tasking_Protected_Objects_Entries =>
9349 Protection_Subtype :=
9350 Make_Subtype_Indication (Loc,
9353 (RTE (RE_Protection_Entries), Loc),
9355 Make_Index_Or_Discriminant_Constraint (Loc,
9356 Constraints => New_List (Entry_Count_Expr)));
9358 when System_Tasking_Protected_Objects_Single_Entry =>
9359 Protection_Subtype :=
9360 New_Occurrence_Of (RTE (RE_Protection_Entry), Loc);
9362 when System_Tasking_Protected_Objects =>
9363 Protection_Subtype :=
9364 New_Occurrence_Of (RTE (RE_Protection), Loc);
9367 raise Program_Error;
9372 Make_Component_Declaration (Loc,
9373 Defining_Identifier =>
9374 Make_Defining_Identifier (Loc, Name_uObject),
9375 Component_Definition =>
9376 Make_Component_Definition (Loc,
9377 Aliased_Present => True,
9378 Subtype_Indication => Protection_Subtype));
9381 -- Put the _Object component after the private component so that it
9382 -- be finalized early as required by 9.4 (20)
9384 Append_To (Cdecls, Object_Comp);
9387 Insert_After (Current_Node, Rec_Decl);
9388 Current_Node := Rec_Decl;
9390 -- Analyze the record declaration immediately after construction,
9391 -- because the initialization procedure is needed for single object
9392 -- declarations before the next entity is analyzed (the freeze call
9393 -- that generates this initialization procedure is found below).
9395 Analyze (Rec_Decl, Suppress => All_Checks);
9397 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9398 -- the corresponding record is frozen. If any wrappers are generated,
9399 -- Current_Node is updated accordingly.
9401 if Ada_Version >= Ada_2005 then
9402 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
9405 -- Collect pointers to entry bodies and their barriers, to be placed
9406 -- in the Entry_Bodies_Array for the type. For each entry/family we
9407 -- add an expression to the aggregate which is the initial value of
9408 -- this array. The array is declared after all protected subprograms.
9410 if Has_Entries (Prot_Typ) then
9411 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
9413 Entries_Aggr := Empty;
9416 -- Build two new procedure specifications for each protected subprogram;
9417 -- one to call from outside the object and one to call from inside.
9418 -- Build a barrier function and an entry body action procedure
9419 -- specification for each protected entry. Initialize the entry body
9420 -- array. If subprogram is flagged as eliminated, do not generate any
9421 -- internal operations.
9424 Comp := First (Visible_Declarations (Pdef));
9425 while Present (Comp) loop
9426 if Nkind (Comp) = N_Subprogram_Declaration then
9428 Make_Subprogram_Declaration (Loc,
9430 Build_Protected_Sub_Specification
9431 (Comp, Prot_Typ, Unprotected_Mode));
9433 Insert_After (Current_Node, Sub);
9436 Set_Protected_Body_Subprogram
9437 (Defining_Unit_Name (Specification (Comp)),
9438 Defining_Unit_Name (Specification (Sub)));
9439 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
9441 -- Make the protected version of the subprogram available for
9442 -- expansion of external calls.
9444 Current_Node := Sub;
9447 Make_Subprogram_Declaration (Loc,
9449 Build_Protected_Sub_Specification
9450 (Comp, Prot_Typ, Protected_Mode));
9452 Insert_After (Current_Node, Sub);
9455 Current_Node := Sub;
9457 -- Generate an overriding primitive operation specification for
9458 -- this subprogram if the protected type implements an interface.
9460 if Ada_Version >= Ada_2005
9462 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
9465 Make_Subprogram_Declaration (Loc,
9467 Build_Protected_Sub_Specification
9468 (Comp, Prot_Typ, Dispatching_Mode));
9470 Insert_After (Current_Node, Sub);
9473 Current_Node := Sub;
9476 -- If a pragma Interrupt_Handler applies, build and add a call to
9477 -- Register_Interrupt_Handler to the freezing actions of the
9478 -- protected version (Current_Node) of the subprogram:
9480 -- system.interrupts.register_interrupt_handler
9481 -- (prot_procP'address);
9483 if not Restricted_Profile
9484 and then Is_Interrupt_Handler
9485 (Defining_Unit_Name (Specification (Comp)))
9490 elsif Nkind (Comp) = N_Entry_Declaration then
9491 Expand_Entry_Declaration (Comp);
9497 -- If there are some private entry declarations, expand it as if they
9498 -- were visible entries.
9500 if Present (Private_Declarations (Pdef)) then
9501 Comp := First (Private_Declarations (Pdef));
9502 while Present (Comp) loop
9503 if Nkind (Comp) = N_Entry_Declaration then
9504 Expand_Entry_Declaration (Comp);
9511 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9512 -- all protected subprograms have been collected.
9514 if Has_Entries (Prot_Typ) then
9516 Make_Defining_Identifier (Sloc (Prot_Typ),
9517 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
9519 case Corresponding_Runtime_Package (Prot_Typ) is
9520 when System_Tasking_Protected_Objects_Entries =>
9522 Make_Object_Declaration (Loc,
9523 Defining_Identifier => Body_Id,
9524 Aliased_Present => True,
9525 Object_Definition =>
9526 Make_Subtype_Indication (Loc,
9529 (RTE (RE_Protected_Entry_Body_Array), Loc),
9531 Make_Index_Or_Discriminant_Constraint (Loc,
9532 Constraints => New_List (
9534 Make_Integer_Literal (Loc, 1),
9535 Make_Integer_Literal (Loc, E_Count))))),
9536 Expression => Entries_Aggr);
9538 when System_Tasking_Protected_Objects_Single_Entry =>
9540 Make_Object_Declaration (Loc,
9541 Defining_Identifier => Body_Id,
9542 Aliased_Present => True,
9543 Object_Definition =>
9544 New_Occurrence_Of (RTE (RE_Entry_Body), Loc),
9545 Expression => Remove_Head (Expressions (Entries_Aggr)));
9548 raise Program_Error;
9551 -- A pointer to this array will be placed in the corresponding record
9552 -- by its initialization procedure so this needs to be analyzed here.
9554 Insert_After (Current_Node, Body_Arr);
9555 Current_Node := Body_Arr;
9558 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
9560 -- Finally, build the function that maps an entry index into the
9561 -- corresponding body. A pointer to this function is placed in each
9562 -- object of the type. Except for a ravenscar-like profile (no abort,
9563 -- no entry queue, 1 entry)
9565 if Corresponding_Runtime_Package (Prot_Typ) =
9566 System_Tasking_Protected_Objects_Entries
9569 Make_Subprogram_Declaration (Loc,
9570 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
9571 Insert_After (Current_Node, Sub);
9575 end Expand_N_Protected_Type_Declaration;
9577 --------------------------------
9578 -- Expand_N_Requeue_Statement --
9579 --------------------------------
9581 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9582 -- operations, depending on the source and destination (task or protected
9583 -- object). A dispatching requeue statement is expanded into a call to the
9584 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9585 -- jump around the remainder of processing for the original entry and, if
9586 -- the destination is (different) protected object, to attempt to service
9587 -- it. The following illustrates the various cases:
9590 -- (O : System.Address;
9591 -- P : System.Address;
9592 -- E : Protected_Entry_Index)
9594 -- <discriminant renamings>
9595 -- <private object renamings>
9596 -- type poVP is access poV;
9597 -- _object : ptVP := ptVP!(O);
9601 -- <start of statement sequence for entry>
9603 -- -- Requeue from one protected entry body to another protected
9606 -- Requeue_Protected_Entry (
9607 -- _object._object'Access,
9608 -- new._object'Access,
9613 -- <some more of the statement sequence for entry>
9615 -- -- Requeue from an entry body to a task entry
9617 -- Requeue_Protected_To_Task_Entry (
9623 -- <rest of statement sequence for entry>
9624 -- Complete_Entry_Body (_object._object);
9627 -- when all others =>
9628 -- Exceptional_Complete_Entry_Body (
9629 -- _object._object, Get_GNAT_Exception);
9633 -- Requeue of a task entry call to a task entry
9635 -- Accept_Call (E, Ann);
9636 -- <start of statement sequence for accept statement>
9637 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9639 -- <rest of statement sequence for accept statement>
9641 -- Complete_Rendezvous;
9644 -- when all others =>
9645 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9647 -- Requeue of a task entry call to a protected entry
9649 -- Accept_Call (E, Ann);
9650 -- <start of statement sequence for accept statement>
9651 -- Requeue_Task_To_Protected_Entry (
9652 -- new._object'Access,
9657 -- <rest of statement sequence for accept statement>
9659 -- Complete_Rendezvous;
9662 -- when all others =>
9663 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9665 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9666 -- marked by pragma Implemented (XXX, By_Entry).
9668 -- The requeue is inside a protected entry:
9671 -- (O : System.Address;
9672 -- P : System.Address;
9673 -- E : Protected_Entry_Index)
9675 -- <discriminant renamings>
9676 -- <private object renamings>
9677 -- type poVP is access poV;
9678 -- _object : ptVP := ptVP!(O);
9682 -- <start of statement sequence for entry>
9685 -- (<interface class-wide object>,
9688 -- Ada.Tags.Get_Offset_Index
9690 -- <interface dispatch table index of target entry>),
9694 -- <rest of statement sequence for entry>
9695 -- Complete_Entry_Body (_object._object);
9698 -- when all others =>
9699 -- Exceptional_Complete_Entry_Body (
9700 -- _object._object, Get_GNAT_Exception);
9704 -- The requeue is inside a task entry:
9706 -- Accept_Call (E, Ann);
9707 -- <start of statement sequence for accept statement>
9709 -- (<interface class-wide object>,
9712 -- Ada.Tags.Get_Offset_Index
9714 -- <interface dispatch table index of target entrt>),
9718 -- <rest of statement sequence for accept statement>
9720 -- Complete_Rendezvous;
9723 -- when all others =>
9724 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9726 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9727 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9728 -- statement is replaced by a dispatching call with actual parameters taken
9729 -- from the inner-most accept statement or entry body.
9731 -- Target.Primitive (Param1, ..., ParamN);
9733 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9734 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9738 -- S : constant Offset_Index :=
9739 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9740 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9743 -- if C = POK_Protected_Entry
9744 -- or else C = POK_Task_Entry
9746 -- <statements for dispatching requeue>
9748 -- elsif C = POK_Protected_Procedure then
9749 -- <dispatching call equivalent>
9752 -- raise Program_Error;
9756 procedure Expand_N_Requeue_Statement (N : Node_Id) is
9757 Loc : constant Source_Ptr := Sloc (N);
9758 Conc_Typ : Entity_Id;
9762 Old_Typ : Entity_Id;
9764 function Build_Dispatching_Call_Equivalent return Node_Id;
9765 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9766 -- the form Concval.Ename. It is statically known that Ename is allowed
9767 -- to be implemented by a protected procedure. Create a dispatching call
9768 -- equivalent of Concval.Ename taking the actual parameters from the
9769 -- inner-most accept statement or entry body.
9771 function Build_Dispatching_Requeue return Node_Id;
9772 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9773 -- the form Concval.Ename. It is statically known that Ename is allowed
9774 -- to be implemented by a protected or a task entry. Create a call to
9775 -- primitive _Disp_Requeue which handles the low-level actions.
9777 function Build_Dispatching_Requeue_To_Any return Node_Id;
9778 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9779 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9780 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9781 -- determines at runtime whether Ename denotes an entry or a procedure
9782 -- and perform the appropriate kind of dispatching select.
9784 function Build_Normal_Requeue return Node_Id;
9785 -- N denotes a non-dispatching requeue statement to either a task or a
9786 -- protected entry. Build the appropriate runtime call to perform the
9789 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
9790 -- For a protected entry, create a return statement to skip the rest of
9791 -- the entry body. Otherwise, create a goto statement to skip the rest
9792 -- of a task accept statement. The lookup for the enclosing entry body
9793 -- or accept statement starts from Search.
9795 ---------------------------------------
9796 -- Build_Dispatching_Call_Equivalent --
9797 ---------------------------------------
9799 function Build_Dispatching_Call_Equivalent return Node_Id is
9800 Call_Ent : constant Entity_Id := Entity (Ename);
9801 Obj : constant Node_Id := Original_Node (Concval);
9808 -- Climb the parent chain looking for the inner-most entry body or
9809 -- accept statement.
9812 while Present (Acc_Ent)
9813 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
9816 Acc_Ent := Parent (Acc_Ent);
9819 -- A requeue statement should be housed inside an entry body or an
9820 -- accept statement at some level. If this is not the case, then the
9821 -- tree is malformed.
9823 pragma Assert (Present (Acc_Ent));
9825 -- Recover the list of formal parameters
9827 if Nkind (Acc_Ent) = N_Entry_Body then
9828 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
9831 Formals := Parameter_Specifications (Acc_Ent);
9833 -- Create the actual parameters for the dispatching call. These are
9834 -- simply copies of the entry body or accept statement formals in the
9835 -- same order as they appear.
9839 if Present (Formals) then
9840 Actuals := New_List;
9841 Formal := First (Formals);
9842 while Present (Formal) loop
9844 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
9850 -- Obj.Call_Ent (Actuals);
9853 Make_Procedure_Call_Statement (Loc,
9855 Make_Selected_Component (Loc,
9856 Prefix => Make_Identifier (Loc, Chars (Obj)),
9857 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
9859 Parameter_Associations => Actuals);
9860 end Build_Dispatching_Call_Equivalent;
9862 -------------------------------
9863 -- Build_Dispatching_Requeue --
9864 -------------------------------
9866 function Build_Dispatching_Requeue return Node_Id is
9867 Params : constant List_Id := New_List;
9870 -- Process the "with abort" parameter
9873 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
9875 -- Process the entry wrapper's position in the primary dispatch
9876 -- table parameter. Generate:
9878 -- Ada.Tags.Get_Entry_Index
9879 -- (T => To_Tag_Ptr (Obj'Address).all,
9881 -- Ada.Tags.Get_Offset_Index
9882 -- (Ada.Tags.Tag (Concval),
9883 -- <interface dispatch table position of Ename>));
9885 -- Note that Obj'Address is recursively expanded into a call to
9886 -- Base_Address (Obj).
9888 if Tagged_Type_Expansion then
9890 Make_Function_Call (Loc,
9891 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9892 Parameter_Associations => New_List (
9894 Make_Explicit_Dereference (Loc,
9895 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
9896 Make_Attribute_Reference (Loc,
9897 Prefix => New_Copy_Tree (Concval),
9898 Attribute_Name => Name_Address))),
9900 Make_Function_Call (Loc,
9901 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9902 Parameter_Associations => New_List (
9903 Unchecked_Convert_To (RTE (RE_Tag), Concval),
9904 Make_Integer_Literal (Loc,
9905 DT_Position (Entity (Ename))))))));
9911 Make_Function_Call (Loc,
9912 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9913 Parameter_Associations => New_List (
9915 Make_Attribute_Reference (Loc,
9917 Attribute_Name => Name_Tag),
9919 Make_Function_Call (Loc,
9920 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9922 Parameter_Associations => New_List (
9926 Make_Attribute_Reference (Loc,
9928 Attribute_Name => Name_Tag),
9932 Make_Attribute_Reference (Loc,
9933 Prefix => New_Occurrence_Of (Etype (Concval), Loc),
9934 Attribute_Name => Name_Tag),
9938 Make_Integer_Literal (Loc,
9939 DT_Position (Entity (Ename))))))));
9942 -- Specific actuals for protected to XXX requeue
9944 if Is_Protected_Type (Old_Typ) then
9946 Make_Attribute_Reference (Loc, -- _object'Address
9948 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9949 Attribute_Name => Name_Address));
9951 Prepend_To (Params, -- True
9952 New_Occurrence_Of (Standard_True, Loc));
9954 -- Specific actuals for task to XXX requeue
9957 pragma Assert (Is_Task_Type (Old_Typ));
9959 Prepend_To (Params, -- null
9960 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
9962 Prepend_To (Params, -- False
9963 New_Occurrence_Of (Standard_False, Loc));
9966 -- Add the object parameter
9968 Prepend_To (Params, New_Copy_Tree (Concval));
9971 -- _Disp_Requeue (<Params>);
9973 -- Find entity for Disp_Requeue operation, which belongs to
9974 -- the type and may not be directly visible.
9981 Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
9982 while Present (Elmt) loop
9984 exit when Chars (Op) = Name_uDisp_Requeue;
9989 Make_Procedure_Call_Statement (Loc,
9990 Name => New_Occurrence_Of (Op, Loc),
9991 Parameter_Associations => Params);
9993 end Build_Dispatching_Requeue;
9995 --------------------------------------
9996 -- Build_Dispatching_Requeue_To_Any --
9997 --------------------------------------
9999 function Build_Dispatching_Requeue_To_Any return Node_Id is
10000 Call_Ent : constant Entity_Id := Entity (Ename);
10001 Obj : constant Node_Id := Original_Node (Concval);
10002 Skip : constant Node_Id := Build_Skip_Statement (N);
10012 -- Dispatch table slot processing, generate:
10015 S := Build_S (Loc, Decls);
10017 -- Call kind processing, generate:
10018 -- C : Ada.Tags.Prim_Op_Kind;
10020 C := Build_C (Loc, Decls);
10023 -- S := Ada.Tags.Get_Offset_Index
10024 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10026 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
10029 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10032 Make_Procedure_Call_Statement (Loc,
10034 New_Occurrence_Of (
10035 Find_Prim_Op (Etype (Etype (Obj)),
10036 Name_uDisp_Get_Prim_Op_Kind),
10038 Parameter_Associations => New_List (
10039 New_Copy_Tree (Obj),
10040 New_Occurrence_Of (S, Loc),
10041 New_Occurrence_Of (C, Loc))));
10045 -- if C = POK_Protected_Entry
10046 -- or else C = POK_Task_Entry
10049 Make_Implicit_If_Statement (N,
10055 New_Occurrence_Of (C, Loc),
10057 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
10062 New_Occurrence_Of (C, Loc),
10064 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
10066 -- Dispatching requeue equivalent
10068 Then_Statements => New_List (
10069 Build_Dispatching_Requeue,
10072 -- elsif C = POK_Protected_Procedure then
10074 Elsif_Parts => New_List (
10075 Make_Elsif_Part (Loc,
10079 New_Occurrence_Of (C, Loc),
10081 New_Occurrence_Of (
10082 RTE (RE_POK_Protected_Procedure), Loc)),
10084 -- Dispatching call equivalent
10086 Then_Statements => New_List (
10087 Build_Dispatching_Call_Equivalent))),
10090 -- raise Program_Error;
10093 Else_Statements => New_List (
10094 Make_Raise_Program_Error (Loc,
10095 Reason => PE_Explicit_Raise))));
10097 -- Wrap everything into a block
10100 Make_Block_Statement (Loc,
10101 Declarations => Decls,
10102 Handled_Statement_Sequence =>
10103 Make_Handled_Sequence_Of_Statements (Loc,
10104 Statements => Stmts));
10105 end Build_Dispatching_Requeue_To_Any;
10107 --------------------------
10108 -- Build_Normal_Requeue --
10109 --------------------------
10111 function Build_Normal_Requeue return Node_Id is
10112 Params : constant List_Id := New_List;
10117 -- Process the "with abort" parameter
10119 Prepend_To (Params,
10120 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
10122 -- Add the index expression to the parameters. It is common among all
10125 Prepend_To (Params,
10126 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
10128 if Is_Protected_Type (Old_Typ) then
10130 Self_Param : Node_Id;
10134 Make_Attribute_Reference (Loc,
10136 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
10138 Name_Unchecked_Access);
10140 -- Protected to protected requeue
10142 if Is_Protected_Type (Conc_Typ) then
10144 New_Occurrence_Of (
10145 RTE (RE_Requeue_Protected_Entry), Loc);
10148 Make_Attribute_Reference (Loc,
10150 Concurrent_Ref (Concval),
10152 Name_Unchecked_Access);
10154 -- Protected to task requeue
10156 else pragma Assert (Is_Task_Type (Conc_Typ));
10158 New_Occurrence_Of (
10159 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
10161 Param := Concurrent_Ref (Concval);
10164 Prepend_To (Params, Param);
10165 Prepend_To (Params, Self_Param);
10168 else pragma Assert (Is_Task_Type (Old_Typ));
10170 -- Task to protected requeue
10172 if Is_Protected_Type (Conc_Typ) then
10174 New_Occurrence_Of (
10175 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
10178 Make_Attribute_Reference (Loc,
10180 Concurrent_Ref (Concval),
10182 Name_Unchecked_Access);
10184 -- Task to task requeue
10186 else pragma Assert (Is_Task_Type (Conc_Typ));
10188 New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc);
10190 Param := Concurrent_Ref (Concval);
10193 Prepend_To (Params, Param);
10197 Make_Procedure_Call_Statement (Loc,
10199 Parameter_Associations => Params);
10200 end Build_Normal_Requeue;
10202 --------------------------
10203 -- Build_Skip_Statement --
10204 --------------------------
10206 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
10207 Skip_Stmt : Node_Id;
10210 -- Build a return statement to skip the rest of the entire body
10212 if Is_Protected_Type (Old_Typ) then
10213 Skip_Stmt := Make_Simple_Return_Statement (Loc);
10215 -- If the requeue is within a task, find the end label of the
10216 -- enclosing accept statement and create a goto statement to it.
10224 -- Climb the parent chain looking for the enclosing accept
10227 Acc := Parent (Search);
10228 while Present (Acc)
10229 and then Nkind (Acc) /= N_Accept_Statement
10231 Acc := Parent (Acc);
10234 -- The last statement is the second label used for completing
10235 -- the rendezvous the usual way. The label we are looking for
10236 -- is right before it.
10239 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
10241 pragma Assert (Nkind (Label) = N_Label);
10243 -- Generate a goto statement to skip the rest of the accept
10246 Make_Goto_Statement (Loc,
10248 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
10252 Set_Analyzed (Skip_Stmt);
10255 end Build_Skip_Statement;
10257 -- Start of processing for Expand_N_Requeue_Statement
10260 -- Extract the components of the entry call
10262 Extract_Entry (N, Concval, Ename, Index);
10263 Conc_Typ := Etype (Concval);
10265 -- If the prefix is an access to class-wide type, dereference to get
10266 -- object and entry type.
10268 if Is_Access_Type (Conc_Typ) then
10269 Conc_Typ := Designated_Type (Conc_Typ);
10271 Make_Explicit_Dereference (Loc, Relocate_Node (Concval)));
10272 Analyze_And_Resolve (Concval, Conc_Typ);
10275 -- Examine the scope stack in order to find nearest enclosing protected
10276 -- or task type. This will constitute our invocation source.
10278 Old_Typ := Current_Scope;
10279 while Present (Old_Typ)
10280 and then not Is_Protected_Type (Old_Typ)
10281 and then not Is_Task_Type (Old_Typ)
10283 Old_Typ := Scope (Old_Typ);
10286 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10287 -- Concval.Ename where the type of Concval is class-wide concurrent
10290 if Ada_Version >= Ada_2012
10291 and then Present (Concval)
10292 and then Is_Class_Wide_Type (Conc_Typ)
10293 and then Is_Concurrent_Interface (Conc_Typ)
10296 Has_Impl : Boolean := False;
10297 Impl_Kind : Name_Id := No_Name;
10300 -- Check whether the Ename is flagged by pragma Implemented
10302 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
10304 Impl_Kind := Implementation_Kind (Entity (Ename));
10307 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10308 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10310 if Has_Impl and then Impl_Kind = Name_By_Entry then
10311 Rewrite (N, Build_Dispatching_Requeue);
10313 Insert_After (N, Build_Skip_Statement (N));
10315 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10316 -- a protected procedure. In this case the requeue is transformed
10317 -- into a dispatching call.
10320 and then Impl_Kind = Name_By_Protected_Procedure
10322 Rewrite (N, Build_Dispatching_Call_Equivalent);
10325 -- The procedure_or_entry_NAME's implementation kind is either
10326 -- By_Any, Optional, or pragma Implemented was not applied at all.
10327 -- In this case a runtime test determines whether Ename denotes an
10328 -- entry or a protected procedure and performs the appropriate
10332 Rewrite (N, Build_Dispatching_Requeue_To_Any);
10337 -- Processing for regular (non-dispatching) requeues
10340 Rewrite (N, Build_Normal_Requeue);
10342 Insert_After (N, Build_Skip_Statement (N));
10344 end Expand_N_Requeue_Statement;
10346 -------------------------------
10347 -- Expand_N_Selective_Accept --
10348 -------------------------------
10350 procedure Expand_N_Selective_Accept (N : Node_Id) is
10351 Loc : constant Source_Ptr := Sloc (N);
10352 Alts : constant List_Id := Select_Alternatives (N);
10354 -- Note: in the below declarations a lot of new lists are allocated
10355 -- unconditionally which may well not end up being used. That's not
10356 -- a good idea since it wastes space gratuitously ???
10358 Accept_Case : List_Id;
10359 Accept_List : constant List_Id := New_List;
10362 Alt_List : constant List_Id := New_List;
10363 Alt_Stats : List_Id;
10364 Ann : Entity_Id := Empty;
10366 Check_Guard : Boolean := True;
10368 Decls : constant List_Id := New_List;
10369 Stats : constant List_Id := New_List;
10370 Body_List : constant List_Id := New_List;
10371 Trailing_List : constant List_Id := New_List;
10374 Else_Present : Boolean := False;
10375 Terminate_Alt : Node_Id := Empty;
10376 Select_Mode : Node_Id;
10378 Delay_Case : List_Id;
10379 Delay_Count : Integer := 0;
10380 Delay_Val : Entity_Id;
10381 Delay_Index : Entity_Id;
10382 Delay_Min : Entity_Id;
10383 Delay_Num : Int := 1;
10384 Delay_Alt_List : List_Id := New_List;
10385 Delay_List : constant List_Id := New_List;
10389 First_Delay : Boolean := True;
10390 Guard_Open : Entity_Id;
10396 Num_Accept : Nat := 0;
10398 Time_Type : Entity_Id;
10399 Select_Call : Node_Id;
10401 Qnam : constant Entity_Id :=
10402 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
10404 Xnam : constant Entity_Id :=
10405 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
10407 -----------------------
10408 -- Local subprograms --
10409 -----------------------
10411 function Accept_Or_Raise return List_Id;
10412 -- For the rare case where delay alternatives all have guards, and
10413 -- all of them are closed, it is still possible that there were open
10414 -- accept alternatives with no callers. We must reexamine the
10415 -- Accept_List, and execute a selective wait with no else if some
10416 -- accept is open. If none, we raise program_error.
10418 procedure Add_Accept (Alt : Node_Id);
10419 -- Process a single accept statement in a select alternative. Build
10420 -- procedure for body of accept, and add entry to dispatch table with
10421 -- expression for guard, in preparation for call to run time select.
10423 function Make_And_Declare_Label (Num : Int) return Node_Id;
10424 -- Manufacture a label using Num as a serial number and declare it.
10425 -- The declaration is appended to Decls. The label marks the trailing
10426 -- statements of an accept or delay alternative.
10428 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
10429 -- Build call to Selective_Wait runtime routine
10431 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
10432 -- Add code to compare value of delay with previous values, and
10433 -- generate case entry for trailing statements.
10435 procedure Process_Accept_Alternative
10439 -- Add code to call corresponding procedure, and branch to
10440 -- trailing statements, if any.
10442 ---------------------
10443 -- Accept_Or_Raise --
10444 ---------------------
10446 function Accept_Or_Raise return List_Id is
10449 J : constant Entity_Id := Make_Temporary (Loc, 'J');
10452 -- We generate the following:
10454 -- for J in q'range loop
10455 -- if q(J).S /=null_task_entry then
10456 -- selective_wait (simple_mode,...);
10462 -- if no rendez_vous then
10463 -- raise program_error;
10466 -- Note that the code needs to know that the selector name
10467 -- in an Accept_Alternative is named S.
10469 Cond := Make_Op_Ne (Loc,
10471 Make_Selected_Component (Loc,
10473 Make_Indexed_Component (Loc,
10474 Prefix => New_Occurrence_Of (Qnam, Loc),
10475 Expressions => New_List (New_Occurrence_Of (J, Loc))),
10476 Selector_Name => Make_Identifier (Loc, Name_S)),
10478 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Loc));
10480 Stats := New_List (
10481 Make_Implicit_Loop_Statement (N,
10482 Iteration_Scheme =>
10483 Make_Iteration_Scheme (Loc,
10484 Loop_Parameter_Specification =>
10485 Make_Loop_Parameter_Specification (Loc,
10486 Defining_Identifier => J,
10487 Discrete_Subtype_Definition =>
10488 Make_Attribute_Reference (Loc,
10489 Prefix => New_Occurrence_Of (Qnam, Loc),
10490 Attribute_Name => Name_Range,
10491 Expressions => New_List (
10492 Make_Integer_Literal (Loc, 1))))),
10494 Statements => New_List (
10495 Make_Implicit_If_Statement (N,
10497 Then_Statements => New_List (
10499 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)),
10500 Make_Exit_Statement (Loc))))));
10503 Make_Raise_Program_Error (Loc,
10504 Condition => Make_Op_Eq (Loc,
10505 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
10507 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
10508 Reason => PE_All_Guards_Closed));
10511 end Accept_Or_Raise;
10517 procedure Add_Accept (Alt : Node_Id) is
10518 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
10519 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
10520 Eloc : constant Source_Ptr := Sloc (Ename);
10521 Eent : constant Entity_Id := Entity (Ename);
10522 Index : constant Node_Id := Entry_Index (Acc_Stm);
10523 Null_Body : Node_Id;
10524 Proc_Body : Node_Id;
10525 PB_Ent : Entity_Id;
10531 Ann := Node (Last_Elmt (Accept_Address (Eent)));
10534 if Present (Condition (Alt)) then
10536 Make_If_Expression (Eloc, New_List (
10538 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
10539 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Eloc)));
10542 Entry_Index_Expression
10543 (Eloc, Eent, Index, Scope (Eent));
10546 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
10547 Null_Body := New_Occurrence_Of (Standard_False, Eloc);
10549 -- Always add call to Abort_Undefer when generating code, since
10550 -- this is what the runtime expects (abort deferred in
10551 -- Selective_Wait). In CodePeer mode this only confuses the
10552 -- analysis with unknown calls, so don't do it.
10554 if not CodePeer_Mode then
10556 Make_Procedure_Call_Statement (Eloc,
10557 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Eloc));
10559 (First (Statements (Handled_Statement_Sequence
10560 (Accept_Statement (Alt)))),
10566 Make_Defining_Identifier (Eloc,
10567 New_External_Name (Chars (Ename), 'A', Num_Accept));
10569 if Comes_From_Source (Alt) then
10570 Set_Debug_Info_Needed (PB_Ent);
10574 Make_Subprogram_Body (Eloc,
10576 Make_Procedure_Specification (Eloc,
10577 Defining_Unit_Name => PB_Ent),
10578 Declarations => Declarations (Acc_Stm),
10579 Handled_Statement_Sequence =>
10580 Build_Accept_Body (Accept_Statement (Alt)));
10582 -- During the analysis of the body of the accept statement, any
10583 -- zero cost exception handler records were collected in the
10584 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10585 -- This is where we move them to where they belong, namely the
10586 -- newly created procedure.
10588 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
10589 Append (Proc_Body, Body_List);
10592 Null_Body := New_Occurrence_Of (Standard_True, Eloc);
10594 -- if accept statement has declarations, insert above, given that
10595 -- we are not creating a body for the accept.
10597 if Present (Declarations (Acc_Stm)) then
10598 Insert_Actions (N, Declarations (Acc_Stm));
10602 Append_To (Accept_List,
10603 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
10605 Num_Accept := Num_Accept + 1;
10608 ----------------------------
10609 -- Make_And_Declare_Label --
10610 ----------------------------
10612 function Make_And_Declare_Label (Num : Int) return Node_Id is
10616 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
10618 Make_Label (Loc, Lab_Id);
10621 Make_Implicit_Label_Declaration (Loc,
10622 Defining_Identifier =>
10623 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
10624 Label_Construct => Lab));
10627 end Make_And_Declare_Label;
10629 ----------------------
10630 -- Make_Select_Call --
10631 ----------------------
10633 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
10634 Params : constant List_Id := New_List;
10638 Make_Attribute_Reference (Loc,
10639 Prefix => New_Occurrence_Of (Qnam, Loc),
10640 Attribute_Name => Name_Unchecked_Access));
10641 Append_To (Params, Select_Mode);
10642 Append_To (Params, New_Occurrence_Of (Ann, Loc));
10643 Append_To (Params, New_Occurrence_Of (Xnam, Loc));
10646 Make_Procedure_Call_Statement (Loc,
10647 Name => New_Occurrence_Of (RTE (RE_Selective_Wait), Loc),
10648 Parameter_Associations => Params);
10649 end Make_Select_Call;
10651 --------------------------------
10652 -- Process_Accept_Alternative --
10653 --------------------------------
10655 procedure Process_Accept_Alternative
10660 Astmt : constant Node_Id := Accept_Statement (Alt);
10661 Alt_Stats : List_Id;
10664 Adjust_Condition (Condition (Alt));
10666 -- Accept with body
10668 if Present (Handled_Statement_Sequence (Astmt)) then
10671 Make_Procedure_Call_Statement (Sloc (Proc),
10674 (Defining_Unit_Name (Specification (Proc)),
10677 -- Accept with no body (followed by trailing statements)
10680 Alt_Stats := Empty_List;
10683 Ensure_Statement_Present (Sloc (Astmt), Alt);
10685 -- After the call, if any, branch to trailing statements, if any.
10686 -- We create a label for each, as well as the corresponding label
10689 if not Is_Empty_List (Statements (Alt)) then
10690 Lab := Make_And_Declare_Label (Index);
10691 Append (Lab, Trailing_List);
10692 Append_List (Statements (Alt), Trailing_List);
10693 Append_To (Trailing_List,
10694 Make_Goto_Statement (Loc,
10695 Name => New_Copy (Identifier (End_Lab))));
10701 Append_To (Alt_Stats,
10702 Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab))));
10704 Append_To (Alt_List,
10705 Make_Case_Statement_Alternative (Loc,
10706 Discrete_Choices => New_List (Make_Integer_Literal (Loc, Index)),
10707 Statements => Alt_Stats));
10708 end Process_Accept_Alternative;
10710 -------------------------------
10711 -- Process_Delay_Alternative --
10712 -------------------------------
10714 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
10715 Dloc : constant Source_Ptr := Sloc (Delay_Statement (Alt));
10717 Delay_Alt : List_Id;
10720 -- Deal with C/Fortran boolean as delay condition
10722 Adjust_Condition (Condition (Alt));
10724 -- Determine the smallest specified delay
10726 -- for each delay alternative generate:
10728 -- if guard-expression then
10729 -- Delay_Val := delay-expression;
10730 -- Guard_Open := True;
10731 -- if Delay_Val < Delay_Min then
10732 -- Delay_Min := Delay_Val;
10733 -- Delay_Index := Index;
10737 -- The enclosing if-statement is omitted if there is no guard
10739 if Delay_Count = 1 or else First_Delay then
10740 First_Delay := False;
10742 Delay_Alt := New_List (
10743 Make_Assignment_Statement (Loc,
10744 Name => New_Occurrence_Of (Delay_Min, Loc),
10745 Expression => Expression (Delay_Statement (Alt))));
10747 if Delay_Count > 1 then
10748 Append_To (Delay_Alt,
10749 Make_Assignment_Statement (Loc,
10750 Name => New_Occurrence_Of (Delay_Index, Loc),
10751 Expression => Make_Integer_Literal (Loc, Index)));
10755 Delay_Alt := New_List (
10756 Make_Assignment_Statement (Loc,
10757 Name => New_Occurrence_Of (Delay_Val, Loc),
10758 Expression => Expression (Delay_Statement (Alt))));
10760 if Time_Type = Standard_Duration then
10763 Left_Opnd => New_Occurrence_Of (Delay_Val, Loc),
10764 Right_Opnd => New_Occurrence_Of (Delay_Min, Loc));
10767 -- The scope of the time type must define a comparison
10768 -- operator. The scope itself may not be visible, so we
10769 -- construct a node with entity information to insure that
10770 -- semantic analysis can find the proper operator.
10773 Make_Function_Call (Loc,
10774 Name => Make_Selected_Component (Loc,
10776 New_Occurrence_Of (Scope (Time_Type), Loc),
10778 Make_Operator_Symbol (Loc,
10779 Chars => Name_Op_Lt,
10780 Strval => No_String)),
10781 Parameter_Associations =>
10783 New_Occurrence_Of (Delay_Val, Loc),
10784 New_Occurrence_Of (Delay_Min, Loc)));
10786 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
10789 Append_To (Delay_Alt,
10790 Make_Implicit_If_Statement (N,
10792 Then_Statements => New_List (
10793 Make_Assignment_Statement (Loc,
10794 Name => New_Occurrence_Of (Delay_Min, Loc),
10795 Expression => New_Occurrence_Of (Delay_Val, Loc)),
10797 Make_Assignment_Statement (Loc,
10798 Name => New_Occurrence_Of (Delay_Index, Loc),
10799 Expression => Make_Integer_Literal (Loc, Index)))));
10802 if Check_Guard then
10803 Append_To (Delay_Alt,
10804 Make_Assignment_Statement (Loc,
10805 Name => New_Occurrence_Of (Guard_Open, Loc),
10806 Expression => New_Occurrence_Of (Standard_True, Loc)));
10809 if Present (Condition (Alt)) then
10810 Delay_Alt := New_List (
10811 Make_Implicit_If_Statement (N,
10812 Condition => Condition (Alt),
10813 Then_Statements => Delay_Alt));
10816 Append_List (Delay_Alt, Delay_List);
10818 Ensure_Statement_Present (Dloc, Alt);
10820 -- If the delay alternative has a statement part, add choice to the
10821 -- case statements for delays.
10823 if not Is_Empty_List (Statements (Alt)) then
10825 if Delay_Count = 1 then
10826 Append_List (Statements (Alt), Delay_Alt_List);
10829 Append_To (Delay_Alt_List,
10830 Make_Case_Statement_Alternative (Loc,
10831 Discrete_Choices => New_List (
10832 Make_Integer_Literal (Loc, Index)),
10833 Statements => Statements (Alt)));
10836 elsif Delay_Count = 1 then
10838 -- If the single delay has no trailing statements, add a branch
10839 -- to the exit label to the selective wait.
10841 Delay_Alt_List := New_List (
10842 Make_Goto_Statement (Loc,
10843 Name => New_Copy (Identifier (End_Lab))));
10846 end Process_Delay_Alternative;
10848 -- Start of processing for Expand_N_Selective_Accept
10851 Process_Statements_For_Controlled_Objects (N);
10853 -- First insert some declarations before the select. The first is:
10857 -- This variable holds the parameters passed to the accept body. This
10858 -- declaration has already been inserted by the time we get here by
10859 -- a call to Expand_Accept_Declarations made from the semantics when
10860 -- processing the first accept statement contained in the select. We
10861 -- can find this entity as Accept_Address (E), where E is any of the
10862 -- entries references by contained accept statements.
10864 -- The first step is to scan the list of Selective_Accept_Statements
10865 -- to find this entity, and also count the number of accepts, and
10866 -- determine if terminated, delay or else is present:
10870 Alt := First (Alts);
10871 while Present (Alt) loop
10872 Process_Statements_For_Controlled_Objects (Alt);
10874 if Nkind (Alt) = N_Accept_Alternative then
10877 elsif Nkind (Alt) = N_Delay_Alternative then
10878 Delay_Count := Delay_Count + 1;
10880 -- If the delays are relative delays, the delay expressions have
10881 -- type Standard_Duration. Otherwise they must have some time type
10882 -- recognized by GNAT.
10884 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
10885 Time_Type := Standard_Duration;
10887 Time_Type := Etype (Expression (Delay_Statement (Alt)));
10889 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
10890 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
10895 "& is not a time type (RM 9.6(6))",
10896 Expression (Delay_Statement (Alt)), Time_Type);
10897 Time_Type := Standard_Duration;
10898 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
10902 if No (Condition (Alt)) then
10904 -- This guard will always be open
10906 Check_Guard := False;
10909 elsif Nkind (Alt) = N_Terminate_Alternative then
10910 Adjust_Condition (Condition (Alt));
10911 Terminate_Alt := Alt;
10914 Num_Alts := Num_Alts + 1;
10918 Else_Present := Present (Else_Statements (N));
10920 -- At the same time (see procedure Add_Accept) we build the accept list:
10922 -- Qnn : Accept_List (1 .. num-select) := (
10923 -- (null-body, entry-index),
10924 -- (null-body, entry-index),
10926 -- (null_body, entry-index));
10928 -- In the above declaration, null-body is True if the corresponding
10929 -- accept has no body, and false otherwise. The entry is either the
10930 -- entry index expression if there is no guard, or if a guard is
10931 -- present, then an if expression of the form:
10933 -- (if guard then entry-index else Null_Task_Entry)
10935 -- If a guard is statically known to be false, the entry can simply
10936 -- be omitted from the accept list.
10939 Make_Object_Declaration (Loc,
10940 Defining_Identifier => Qnam,
10941 Object_Definition => New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10942 Aliased_Present => True,
10944 Make_Qualified_Expression (Loc,
10946 New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10948 Make_Aggregate (Loc, Expressions => Accept_List))));
10950 -- Then we declare the variable that holds the index for the accept
10951 -- that will be selected for service:
10953 -- Xnn : Select_Index;
10956 Make_Object_Declaration (Loc,
10957 Defining_Identifier => Xnam,
10958 Object_Definition =>
10959 New_Occurrence_Of (RTE (RE_Select_Index), Loc),
10961 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)));
10963 -- After this follow procedure declarations for each accept body
10965 -- procedure Pnn is
10970 -- where the ... are statements from the corresponding procedure body.
10971 -- No parameters are involved, since the parameters are passed via Ann
10972 -- and the parameter references have already been expanded to be direct
10973 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10974 -- any embedded tasking statements (which would normally be illegal in
10975 -- procedures), have been converted to calls to the tasking runtime so
10976 -- there is no problem in putting them into procedures.
10978 -- The original accept statement has been expanded into a block in
10979 -- the same fashion as for simple accepts (see Build_Accept_Body).
10981 -- Note: we don't really need to build these procedures for the case
10982 -- where no delay statement is present, but it is just as easy to
10983 -- build them unconditionally, and not significantly inefficient,
10984 -- since if they are short they will be inlined anyway.
10986 -- The procedure declarations have been assembled in Body_List
10988 -- If delays are present, we must compute the required delay.
10989 -- We first generate the declarations:
10991 -- Delay_Index : Boolean := 0;
10992 -- Delay_Min : Some_Time_Type.Time;
10993 -- Delay_Val : Some_Time_Type.Time;
10995 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10996 -- active delay that is actually chosen as the basis for the possible
10997 -- delay if an immediate rendez-vous is not possible.
10999 -- In the most common case there is a single delay statement, and this
11000 -- is handled specially.
11002 if Delay_Count > 0 then
11004 -- Generate the required declarations
11007 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
11009 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
11011 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
11014 Make_Object_Declaration (Loc,
11015 Defining_Identifier => Delay_Val,
11016 Object_Definition => New_Occurrence_Of (Time_Type, Loc)));
11019 Make_Object_Declaration (Loc,
11020 Defining_Identifier => Delay_Index,
11021 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
11022 Expression => Make_Integer_Literal (Loc, 0)));
11025 Make_Object_Declaration (Loc,
11026 Defining_Identifier => Delay_Min,
11027 Object_Definition => New_Occurrence_Of (Time_Type, Loc),
11029 Unchecked_Convert_To (Time_Type,
11030 Make_Attribute_Reference (Loc,
11032 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
11033 Attribute_Name => Name_Last))));
11035 -- Create Duration and Delay_Mode objects used for passing a delay
11038 D := Make_Temporary (Loc, 'D');
11039 M := Make_Temporary (Loc, 'M');
11045 -- Note that these values are defined in s-osprim.ads and must
11046 -- be kept in sync:
11048 -- Relative : constant := 0;
11049 -- Absolute_Calendar : constant := 1;
11050 -- Absolute_RT : constant := 2;
11052 if Time_Type = Standard_Duration then
11053 Discr := Make_Integer_Literal (Loc, 0);
11055 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11056 Discr := Make_Integer_Literal (Loc, 1);
11060 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11061 Discr := Make_Integer_Literal (Loc, 2);
11065 Make_Object_Declaration (Loc,
11066 Defining_Identifier => D,
11067 Object_Definition =>
11068 New_Occurrence_Of (Standard_Duration, Loc)));
11071 Make_Object_Declaration (Loc,
11072 Defining_Identifier => M,
11073 Object_Definition =>
11074 New_Occurrence_Of (Standard_Integer, Loc),
11075 Expression => Discr));
11078 if Check_Guard then
11080 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
11083 Make_Object_Declaration (Loc,
11084 Defining_Identifier => Guard_Open,
11085 Object_Definition =>
11086 New_Occurrence_Of (Standard_Boolean, Loc),
11088 New_Occurrence_Of (Standard_False, Loc)));
11091 -- Delay_Count is zero, don't need M and D set (suppress warning)
11098 if Present (Terminate_Alt) then
11100 -- If the terminate alternative guard is False, use
11101 -- Simple_Mode; otherwise use Terminate_Mode.
11103 if Present (Condition (Terminate_Alt)) then
11104 Select_Mode := Make_If_Expression (Loc,
11105 New_List (Condition (Terminate_Alt),
11106 New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc),
11107 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)));
11109 Select_Mode := New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc);
11112 elsif Else_Present or Delay_Count > 0 then
11113 Select_Mode := New_Occurrence_Of (RTE (RE_Else_Mode), Loc);
11116 Select_Mode := New_Occurrence_Of (RTE (RE_Simple_Mode), Loc);
11119 Select_Call := Make_Select_Call (Select_Mode);
11120 Append (Select_Call, Stats);
11122 -- Now generate code to act on the result. There is an entry
11123 -- in this case for each accept statement with a non-null body,
11124 -- followed by a branch to the statements that follow the Accept.
11125 -- In the absence of delay alternatives, we generate:
11128 -- when No_Rendezvous => -- omitted if simple mode
11143 -- Lab0: Else_Statements;
11146 -- Lab1: Trailing_Statements1;
11149 -- Lab2: Trailing_Statements2;
11154 -- Generate label for common exit
11156 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
11158 -- First entry is the default case, when no rendezvous is possible
11160 Choices := New_List (New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc));
11162 if Else_Present then
11164 -- If no rendezvous is possible, the else part is executed
11166 Lab := Make_And_Declare_Label (0);
11167 Alt_Stats := New_List (
11168 Make_Goto_Statement (Loc,
11169 Name => New_Copy (Identifier (Lab))));
11171 Append (Lab, Trailing_List);
11172 Append_List (Else_Statements (N), Trailing_List);
11173 Append_To (Trailing_List,
11174 Make_Goto_Statement (Loc,
11175 Name => New_Copy (Identifier (End_Lab))));
11177 Alt_Stats := New_List (
11178 Make_Goto_Statement (Loc,
11179 Name => New_Copy (Identifier (End_Lab))));
11182 Append_To (Alt_List,
11183 Make_Case_Statement_Alternative (Loc,
11184 Discrete_Choices => Choices,
11185 Statements => Alt_Stats));
11187 -- We make use of the fact that Accept_Index is an integer type, and
11188 -- generate successive literals for entries for each accept. Only those
11189 -- for which there is a body or trailing statements get a case entry.
11191 Alt := First (Select_Alternatives (N));
11192 Proc := First (Body_List);
11193 while Present (Alt) loop
11195 if Nkind (Alt) = N_Accept_Alternative then
11196 Process_Accept_Alternative (Alt, Index, Proc);
11197 Index := Index + 1;
11200 (Handled_Statement_Sequence (Accept_Statement (Alt)))
11205 elsif Nkind (Alt) = N_Delay_Alternative then
11206 Process_Delay_Alternative (Alt, Delay_Num);
11207 Delay_Num := Delay_Num + 1;
11213 -- An others choice is always added to the main case, as well
11214 -- as the delay case (to satisfy the compiler).
11216 Append_To (Alt_List,
11217 Make_Case_Statement_Alternative (Loc,
11218 Discrete_Choices =>
11219 New_List (Make_Others_Choice (Loc)),
11221 New_List (Make_Goto_Statement (Loc,
11222 Name => New_Copy (Identifier (End_Lab))))));
11224 Accept_Case := New_List (
11225 Make_Case_Statement (Loc,
11226 Expression => New_Occurrence_Of (Xnam, Loc),
11227 Alternatives => Alt_List));
11229 Append_List (Trailing_List, Accept_Case);
11230 Append_List (Body_List, Decls);
11232 -- Construct case statement for trailing statements of delay
11233 -- alternatives, if there are several of them.
11235 if Delay_Count > 1 then
11236 Append_To (Delay_Alt_List,
11237 Make_Case_Statement_Alternative (Loc,
11238 Discrete_Choices =>
11239 New_List (Make_Others_Choice (Loc)),
11241 New_List (Make_Null_Statement (Loc))));
11243 Delay_Case := New_List (
11244 Make_Case_Statement (Loc,
11245 Expression => New_Occurrence_Of (Delay_Index, Loc),
11246 Alternatives => Delay_Alt_List));
11248 Delay_Case := Delay_Alt_List;
11251 -- If there are no delay alternatives, we append the case statement
11252 -- to the statement list.
11254 if Delay_Count = 0 then
11255 Append_List (Accept_Case, Stats);
11257 -- Delay alternatives present
11260 -- If delay alternatives are present we generate:
11262 -- find minimum delay.
11263 -- DX := minimum delay;
11264 -- M := <delay mode>;
11265 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11268 -- if X = No_Rendezvous then
11269 -- case statement for delay statements.
11271 -- case statement for accept alternatives.
11282 -- The type of the delay expression is known to be legal
11284 if Time_Type = Standard_Duration then
11285 Conv := New_Occurrence_Of (Delay_Min, Loc);
11287 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11288 Conv := Make_Function_Call (Loc,
11289 New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
11290 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11294 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11296 Conv := Make_Function_Call (Loc,
11297 New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
11298 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11301 Stmt := Make_Assignment_Statement (Loc,
11302 Name => New_Occurrence_Of (D, Loc),
11303 Expression => Conv);
11305 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11307 Parms := Parameter_Associations (Select_Call);
11309 Parm := First (Parms);
11310 while Present (Parm) and then Parm /= Select_Mode loop
11314 pragma Assert (Present (Parm));
11315 Rewrite (Parm, New_Occurrence_Of (RTE (RE_Delay_Mode), Loc));
11318 -- Prepare two new parameters of Duration and Delay_Mode type
11319 -- which represent the value and the mode of the minimum delay.
11322 Insert_After (Parm, New_Occurrence_Of (M, Loc));
11323 Insert_After (Parm, New_Occurrence_Of (D, Loc));
11325 -- Create a call to RTS
11327 Rewrite (Select_Call,
11328 Make_Procedure_Call_Statement (Loc,
11329 Name => New_Occurrence_Of (RTE (RE_Timed_Selective_Wait), Loc),
11330 Parameter_Associations => Parms));
11332 -- This new call should follow the calculation of the minimum
11335 Insert_List_Before (Select_Call, Delay_List);
11337 if Check_Guard then
11339 Make_Implicit_If_Statement (N,
11340 Condition => New_Occurrence_Of (Guard_Open, Loc),
11341 Then_Statements => New_List (
11342 New_Copy_Tree (Stmt),
11343 New_Copy_Tree (Select_Call)),
11344 Else_Statements => Accept_Or_Raise);
11345 Rewrite (Select_Call, Stmt);
11347 Insert_Before (Select_Call, Stmt);
11351 Make_Implicit_If_Statement (N,
11352 Condition => Make_Op_Eq (Loc,
11353 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
11355 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
11357 Then_Statements => Delay_Case,
11358 Else_Statements => Accept_Case);
11360 Append (Cases, Stats);
11364 Append (End_Lab, Stats);
11366 -- Replace accept statement with appropriate block
11369 Make_Block_Statement (Loc,
11370 Declarations => Decls,
11371 Handled_Statement_Sequence =>
11372 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats)));
11375 -- Note: have to worry more about abort deferral in above code ???
11377 -- Final step is to unstack the Accept_Address entries for all accept
11378 -- statements appearing in accept alternatives in the select statement
11380 Alt := First (Alts);
11381 while Present (Alt) loop
11382 if Nkind (Alt) = N_Accept_Alternative then
11383 Remove_Last_Elmt (Accept_Address
11384 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
11389 end Expand_N_Selective_Accept;
11391 --------------------------------------
11392 -- Expand_N_Single_Task_Declaration --
11393 --------------------------------------
11395 -- Single task declarations should never be present after semantic
11396 -- analysis, since we expect them to be replaced by a declaration of an
11397 -- anonymous task type, followed by a declaration of the task object. We
11398 -- include this routine to make sure that is happening.
11400 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
11402 raise Program_Error;
11403 end Expand_N_Single_Task_Declaration;
11405 ------------------------
11406 -- Expand_N_Task_Body --
11407 ------------------------
11409 -- Given a task body
11411 -- task body tname is
11417 -- This expansion routine converts it into a procedure and sets the
11418 -- elaboration flag for the procedure to true, to represent the fact
11419 -- that the task body is now elaborated:
11421 -- procedure tnameB (_Task : access tnameV) is
11422 -- discriminal : dtype renames _Task.discriminant;
11424 -- procedure _clean is
11426 -- Abort_Defer.all;
11428 -- Abort_Undefer.all;
11433 -- Abort_Undefer.all;
11435 -- System.Task_Stages.Complete_Activation;
11443 -- In addition, if the task body is an activator, then a call to activate
11444 -- tasks is added at the start of the statements, before the call to
11445 -- Complete_Activation, and if in addition the task is a master then it
11446 -- must be established as a master. These calls are inserted and analyzed
11447 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11450 -- There is one discriminal declaration line generated for each
11451 -- discriminant that is present to provide an easy reference point for
11452 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11454 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11455 -- task body procedures have a profile (Arg : System.Address). That is
11456 -- needed because GNARLI has to use the same access-to-subprogram type
11457 -- for all task types. We depend here on knowing that in GNAT, passing
11458 -- an address argument by value is identical to passing a record value
11459 -- by access (in either case a single pointer is passed), so even though
11460 -- this procedure has the wrong profile. In fact it's all OK, since the
11461 -- callings sequence is identical.
11463 procedure Expand_N_Task_Body (N : Node_Id) is
11464 Loc : constant Source_Ptr := Sloc (N);
11465 Ttyp : constant Entity_Id := Corresponding_Spec (N);
11469 Insert_Nod : Node_Id;
11470 -- Used to determine the proper location of wrapper body insertions
11473 -- if no task body procedure, means we had an error in configurable
11474 -- run-time mode, and there is no point in proceeding further.
11476 if No (Task_Body_Procedure (Ttyp)) then
11480 -- Add renaming declarations for discriminals and a declaration for the
11481 -- entry family index (if applicable).
11483 Install_Private_Data_Declarations
11484 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
11486 -- Add a call to Abort_Undefer at the very beginning of the task
11487 -- body since this body is called with abort still deferred.
11489 if Abort_Allowed then
11490 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
11492 (First (Statements (Handled_Statement_Sequence (N))), Call);
11496 -- The statement part has already been protected with an at_end and
11497 -- cleanup actions. The call to Complete_Activation must be placed
11498 -- at the head of the sequence of statements of that block. The
11499 -- declarations have been merged in this sequence of statements but
11500 -- the first real statement is accessible from the First_Real_Statement
11501 -- field (which was set for exactly this purpose).
11503 if Restricted_Profile then
11504 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
11506 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
11510 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
11514 Make_Subprogram_Body (Loc,
11515 Specification => Build_Task_Proc_Specification (Ttyp),
11516 Declarations => Declarations (N),
11517 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
11518 Set_Is_Task_Body_Procedure (New_N);
11520 -- If the task contains generic instantiations, cleanup actions are
11521 -- delayed until after instantiation. Transfer the activation chain to
11522 -- the subprogram, to insure that the activation call is properly
11523 -- generated. It the task body contains inner tasks, indicate that the
11524 -- subprogram is a task master.
11526 if Delay_Cleanups (Ttyp) then
11527 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
11528 Set_Is_Task_Master (New_N, Is_Task_Master (N));
11531 Rewrite (N, New_N);
11534 -- Set elaboration flag immediately after task body. If the body is a
11535 -- subunit, the flag is set in the declarative part containing the stub.
11537 if Nkind (Parent (N)) /= N_Subunit then
11539 Make_Assignment_Statement (Loc,
11541 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
11542 Expression => New_Occurrence_Of (Standard_True, Loc)));
11545 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11546 -- the task body. At this point all wrapper specs have been created,
11547 -- frozen and included in the dispatch table for the task type.
11549 if Ada_Version >= Ada_2005 then
11550 if Nkind (Parent (N)) = N_Subunit then
11551 Insert_Nod := Corresponding_Stub (Parent (N));
11556 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
11558 end Expand_N_Task_Body;
11560 ------------------------------------
11561 -- Expand_N_Task_Type_Declaration --
11562 ------------------------------------
11564 -- We have several things to do. First we must create a Boolean flag used
11565 -- to mark if the body is elaborated yet. This variable gets set to True
11566 -- when the body of the task is elaborated (we can't rely on the normal
11567 -- ABE mechanism for the task body, since we need to pass an access to
11568 -- this elaboration boolean to the runtime routines).
11570 -- taskE : aliased Boolean := False;
11572 -- Next a variable is declared to hold the task stack size (either the
11573 -- default : Unspecified_Size, or a value that is set by a pragma
11574 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11575 -- the variable is initialized with this value:
11577 -- taskZ : Size_Type := Unspecified_Size;
11579 -- taskZ : Size_Type := Size_Type (size_expression);
11581 -- Note: No variable is needed to hold the task relative deadline since
11582 -- its value would never be static because the parameter is of a private
11583 -- type (Ada.Real_Time.Time_Span).
11585 -- Next we create a corresponding record type declaration used to represent
11586 -- values of this task. The general form of this type declaration is
11588 -- type taskV (discriminants) is record
11589 -- _Task_Id : Task_Id;
11590 -- entry_family : array (bounds) of Void;
11591 -- _Priority : Integer := priority_expression;
11592 -- _Size : Size_Type := size_expression;
11593 -- _Task_Info : Task_Info_Type := task_info_expression;
11594 -- _CPU : Integer := cpu_range_expression;
11595 -- _Relative_Deadline : Time_Span := time_span_expression;
11596 -- _Domain : Dispatching_Domain := dd_expression;
11599 -- The discriminants are present only if the corresponding task type has
11600 -- discriminants, and they exactly mirror the task type discriminants.
11602 -- The Id field is always present. It contains the Task_Id value, as set by
11603 -- the call to Create_Task. Note that although the task is limited, the
11604 -- task value record type is not limited, so there is no problem in passing
11605 -- this field as an out parameter to Create_Task.
11607 -- One entry_family component is present for each entry family in the task
11608 -- definition. The bounds correspond to the bounds of the entry family
11609 -- (which may depend on discriminants). The element type is void, since we
11610 -- only need the bounds information for determining the entry index. Note
11611 -- that the use of an anonymous array would normally be illegal in this
11612 -- context, but this is a parser check, and the semantics is quite prepared
11613 -- to handle such a case.
11615 -- The _Size field is present only if a Storage_Size pragma appears in the
11616 -- task definition. The expression captures the argument that was present
11617 -- in the pragma, and is used to override the task stack size otherwise
11618 -- associated with the task type.
11620 -- The _Priority field is present only if the task entity has a Priority or
11621 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11622 -- definition clause). It will be filled at the freeze point, when the
11623 -- record init proc is built, to capture the expression of the rep item
11624 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11625 -- here since aspect evaluations are delayed till the freeze point.
11627 -- The _Task_Info field is present only if a Task_Info pragma appears in
11628 -- the task definition. The expression captures the argument that was
11629 -- present in the pragma, and is used to provide the Task_Image parameter
11630 -- to the call to Create_Task.
11632 -- The _CPU field is present only if the task entity has a CPU rep item
11633 -- (pragma, aspect specification or attribute definition clause). It will
11634 -- be filled at the freeze point, when the record init proc is built, to
11635 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11636 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11637 -- are delayed till the freeze point.
11639 -- The _Relative_Deadline field is present only if a Relative_Deadline
11640 -- pragma appears in the task definition. The expression captures the
11641 -- argument that was present in the pragma, and is used to provide the
11642 -- Relative_Deadline parameter to the call to Create_Task.
11644 -- The _Domain field is present only if the task entity has a
11645 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11646 -- definition clause). It will be filled at the freeze point, when the
11647 -- record init proc is built, to capture the expression of the rep item
11648 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11649 -- here since aspect evaluations are delayed till the freeze point.
11651 -- When a task is declared, an instance of the task value record is
11652 -- created. The elaboration of this declaration creates the correct bounds
11653 -- for the entry families, and also evaluates the size, priority, and
11654 -- task_Info expressions if needed. The initialization routine for the task
11655 -- type itself then calls Create_Task with appropriate parameters to
11656 -- initialize the value of the Task_Id field.
11658 -- Note: the address of this record is passed as the "Discriminants"
11659 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11660 -- body procedure, it does not matter that it does not quite match the
11661 -- GNARLI model of what is being passed (the record contains more than just
11662 -- the discriminants, but the discriminants can be found from the record
11665 -- The Entity_Id for this created record type is placed in the
11666 -- Corresponding_Record_Type field of the associated task type entity.
11668 -- Next we create a procedure specification for the task body procedure:
11670 -- procedure taskB (_Task : access taskV);
11672 -- Note that this must come after the record type declaration, since
11673 -- the spec refers to this type. It turns out that the initialization
11674 -- procedure for the value type references the task body spec, but that's
11675 -- fine, since it won't be generated till the freeze point for the type,
11676 -- which is certainly after the task body spec declaration.
11678 -- Finally, we set the task index value field of the entry attribute in
11679 -- the case of a simple entry.
11681 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
11682 Loc : constant Source_Ptr := Sloc (N);
11683 TaskId : constant Entity_Id := Defining_Identifier (N);
11684 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
11685 Tasknm : constant Name_Id := Chars (Tasktyp);
11686 Taskdef : constant Node_Id := Task_Definition (N);
11688 Body_Decl : Node_Id;
11690 Decl_Stack : Node_Id;
11691 Elab_Decl : Node_Id;
11692 Ent_Stack : Entity_Id;
11693 Proc_Spec : Node_Id;
11694 Rec_Decl : Node_Id;
11695 Rec_Ent : Entity_Id;
11696 Size_Decl : Entity_Id;
11697 Task_Size : Node_Id;
11699 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id;
11700 -- Searches the task definition T for the first occurrence of the pragma
11701 -- Relative Deadline. The caller has ensured that the pragma is present
11702 -- in the task definition. Note that this routine cannot be implemented
11703 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11704 -- not chained because their expansion into a procedure call statement
11705 -- would cause a break in the chain.
11707 ----------------------------------
11708 -- Get_Relative_Deadline_Pragma --
11709 ----------------------------------
11711 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id is
11715 N := First (Visible_Declarations (T));
11716 while Present (N) loop
11717 if Nkind (N) = N_Pragma
11718 and then Pragma_Name (N) = Name_Relative_Deadline
11726 N := First (Private_Declarations (T));
11727 while Present (N) loop
11728 if Nkind (N) = N_Pragma
11729 and then Pragma_Name (N) = Name_Relative_Deadline
11737 raise Program_Error;
11738 end Get_Relative_Deadline_Pragma;
11740 -- Start of processing for Expand_N_Task_Type_Declaration
11743 -- If already expanded, nothing to do
11745 if Present (Corresponding_Record_Type (Tasktyp)) then
11749 -- Here we will do the expansion
11751 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
11753 Rec_Ent := Defining_Identifier (Rec_Decl);
11754 Cdecls := Component_Items (Component_List
11755 (Type_Definition (Rec_Decl)));
11757 Qualify_Entity_Names (N);
11759 -- First create the elaboration variable
11762 Make_Object_Declaration (Loc,
11763 Defining_Identifier =>
11764 Make_Defining_Identifier (Sloc (Tasktyp),
11765 Chars => New_External_Name (Tasknm, 'E')),
11766 Aliased_Present => True,
11767 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
11768 Expression => New_Occurrence_Of (Standard_False, Loc));
11770 Insert_After (N, Elab_Decl);
11772 -- Next create the declaration of the size variable (tasknmZ)
11774 Set_Storage_Size_Variable (Tasktyp,
11775 Make_Defining_Identifier (Sloc (Tasktyp),
11776 Chars => New_External_Name (Tasknm, 'Z')));
11778 if Present (Taskdef)
11779 and then Has_Storage_Size_Pragma (Taskdef)
11781 Is_OK_Static_Expression
11783 (First (Pragma_Argument_Associations
11784 (Get_Rep_Pragma (TaskId, Name_Storage_Size)))))
11787 Make_Object_Declaration (Loc,
11788 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11789 Object_Definition =>
11790 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11792 Convert_To (RTE (RE_Size_Type),
11794 (Expression (First (Pragma_Argument_Associations
11796 (TaskId, Name_Storage_Size)))))));
11800 Make_Object_Declaration (Loc,
11801 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11802 Object_Definition =>
11803 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11805 New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
11808 Insert_After (Elab_Decl, Size_Decl);
11810 -- Next build the rest of the corresponding record declaration. This is
11811 -- done last, since the corresponding record initialization procedure
11812 -- will reference the previously created entities.
11814 -- Fill in the component declarations -- first the _Task_Id field
11817 Make_Component_Declaration (Loc,
11818 Defining_Identifier =>
11819 Make_Defining_Identifier (Loc, Name_uTask_Id),
11820 Component_Definition =>
11821 Make_Component_Definition (Loc,
11822 Aliased_Present => False,
11823 Subtype_Indication => New_Occurrence_Of (RTE (RO_ST_Task_Id),
11826 -- Declare static ATCB (that is, created by the expander) if we are
11827 -- using the Restricted run time.
11829 if Restricted_Profile then
11831 Make_Component_Declaration (Loc,
11832 Defining_Identifier =>
11833 Make_Defining_Identifier (Loc, Name_uATCB),
11835 Component_Definition =>
11836 Make_Component_Definition (Loc,
11837 Aliased_Present => True,
11838 Subtype_Indication => Make_Subtype_Indication (Loc,
11840 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
11843 Make_Index_Or_Discriminant_Constraint (Loc,
11845 New_List (Make_Integer_Literal (Loc, 0)))))));
11849 -- Declare static stack (that is, created by the expander) if we are
11850 -- using the Restricted run time on a bare board configuration.
11852 if Restricted_Profile and then Preallocated_Stacks_On_Target then
11854 -- First we need to extract the appropriate stack size
11856 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
11858 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11860 Expr_N : constant Node_Id :=
11861 Expression (First (
11862 Pragma_Argument_Associations (
11863 Get_Rep_Pragma (TaskId, Name_Storage_Size))));
11864 Etyp : constant Entity_Id := Etype (Expr_N);
11865 P : constant Node_Id := Parent (Expr_N);
11868 -- The stack is defined inside the corresponding record.
11869 -- Therefore if the size of the stack is set by means of
11870 -- a discriminant, we must reference the discriminant of the
11871 -- corresponding record type.
11873 if Nkind (Expr_N) in N_Has_Entity
11874 and then Present (Discriminal_Link (Entity (Expr_N)))
11878 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
11880 Set_Parent (Task_Size, P);
11881 Set_Etype (Task_Size, Etyp);
11882 Set_Analyzed (Task_Size);
11885 Task_Size := Relocate_Node (Expr_N);
11891 New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc);
11894 Decl_Stack := Make_Component_Declaration (Loc,
11895 Defining_Identifier => Ent_Stack,
11897 Component_Definition =>
11898 Make_Component_Definition (Loc,
11899 Aliased_Present => True,
11900 Subtype_Indication => Make_Subtype_Indication (Loc,
11902 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
11905 Make_Index_Or_Discriminant_Constraint (Loc,
11906 Constraints => New_List (Make_Range (Loc,
11907 Low_Bound => Make_Integer_Literal (Loc, 1),
11908 High_Bound => Convert_To (RTE (RE_Storage_Offset),
11911 Append_To (Cdecls, Decl_Stack);
11913 -- The appropriate alignment for the stack is ensured by the run-time
11914 -- code in charge of task creation.
11918 -- Add components for entry families
11920 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
11922 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11923 -- item is present.
11925 if Has_Rep_Item (TaskId, Name_Priority, Check_Parents => False) then
11927 Make_Component_Declaration (Loc,
11928 Defining_Identifier =>
11929 Make_Defining_Identifier (Loc, Name_uPriority),
11930 Component_Definition =>
11931 Make_Component_Definition (Loc,
11932 Aliased_Present => False,
11933 Subtype_Indication =>
11934 New_Occurrence_Of (Standard_Integer, Loc))));
11937 -- Add the _Size component if a Storage_Size pragma is present
11939 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11941 Make_Component_Declaration (Loc,
11942 Defining_Identifier =>
11943 Make_Defining_Identifier (Loc, Name_uSize),
11945 Component_Definition =>
11946 Make_Component_Definition (Loc,
11947 Aliased_Present => False,
11948 Subtype_Indication =>
11949 New_Occurrence_Of (RTE (RE_Size_Type), Loc)),
11952 Convert_To (RTE (RE_Size_Type),
11954 Expression (First (
11955 Pragma_Argument_Associations (
11956 Get_Rep_Pragma (TaskId, Name_Storage_Size))))))));
11959 -- Add the _Task_Info component if a Task_Info pragma is present
11961 if Has_Rep_Pragma (TaskId, Name_Task_Info, Check_Parents => False) then
11963 Make_Component_Declaration (Loc,
11964 Defining_Identifier =>
11965 Make_Defining_Identifier (Loc, Name_uTask_Info),
11967 Component_Definition =>
11968 Make_Component_Definition (Loc,
11969 Aliased_Present => False,
11970 Subtype_Indication =>
11971 New_Occurrence_Of (RTE (RE_Task_Info_Type), Loc)),
11973 Expression => New_Copy (
11974 Expression (First (
11975 Pragma_Argument_Associations (
11977 (TaskId, Name_Task_Info, Check_Parents => False)))))));
11980 -- Add the _CPU component if a CPU rep item is present
11982 if Has_Rep_Item (TaskId, Name_CPU, Check_Parents => False) then
11984 Make_Component_Declaration (Loc,
11985 Defining_Identifier =>
11986 Make_Defining_Identifier (Loc, Name_uCPU),
11988 Component_Definition =>
11989 Make_Component_Definition (Loc,
11990 Aliased_Present => False,
11991 Subtype_Indication =>
11992 New_Occurrence_Of (RTE (RE_CPU_Range), Loc))));
11995 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11996 -- present. If we are using a restricted run time this component will
11997 -- not be added (deadlines are not allowed by the Ravenscar profile).
11999 if not Restricted_Profile
12000 and then Present (Taskdef)
12001 and then Has_Relative_Deadline_Pragma (Taskdef)
12004 Make_Component_Declaration (Loc,
12005 Defining_Identifier =>
12006 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
12008 Component_Definition =>
12009 Make_Component_Definition (Loc,
12010 Aliased_Present => False,
12011 Subtype_Indication =>
12012 New_Occurrence_Of (RTE (RE_Time_Span), Loc)),
12015 Convert_To (RTE (RE_Time_Span),
12017 Expression (First (
12018 Pragma_Argument_Associations (
12019 Get_Relative_Deadline_Pragma (Taskdef))))))));
12022 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12023 -- item is present. If we are using a restricted run time this component
12024 -- will not be added (dispatching domains are not allowed by the
12025 -- Ravenscar profile).
12027 if not Restricted_Profile
12030 (TaskId, Name_Dispatching_Domain, Check_Parents => False)
12033 Make_Component_Declaration (Loc,
12034 Defining_Identifier =>
12035 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
12037 Component_Definition =>
12038 Make_Component_Definition (Loc,
12039 Aliased_Present => False,
12040 Subtype_Indication =>
12042 (RTE (RE_Dispatching_Domain_Access), Loc))));
12045 Insert_After (Size_Decl, Rec_Decl);
12047 -- Analyze the record declaration immediately after construction,
12048 -- because the initialization procedure is needed for single task
12049 -- declarations before the next entity is analyzed.
12051 Analyze (Rec_Decl);
12053 -- Create the declaration of the task body procedure
12055 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
12057 Make_Subprogram_Declaration (Loc,
12058 Specification => Proc_Spec);
12059 Set_Is_Task_Body_Procedure (Body_Decl);
12061 Insert_After (Rec_Decl, Body_Decl);
12063 -- The subprogram does not comes from source, so we have to indicate the
12064 -- need for debugging information explicitly.
12066 if Comes_From_Source (Original_Node (N)) then
12067 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
12070 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12071 -- the corresponding record has been frozen.
12073 if Ada_Version >= Ada_2005 then
12074 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
12077 -- Ada 2005 (AI-345): We must defer freezing to allow further
12078 -- declaration of primitive subprograms covering task interfaces
12080 if Ada_Version <= Ada_95 then
12082 -- Now we can freeze the corresponding record. This needs manually
12083 -- freezing, since it is really part of the task type, and the task
12084 -- type is frozen at this stage. We of course need the initialization
12085 -- procedure for this corresponding record type and we won't get it
12086 -- in time if we don't freeze now.
12089 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
12091 if Is_Non_Empty_List (L) then
12092 Insert_List_After (Body_Decl, L);
12097 -- Complete the expansion of access types to the current task type, if
12098 -- any were declared.
12100 Expand_Previous_Access_Type (Tasktyp);
12102 -- Create wrappers for entries that have pre/postconditions
12108 Ent := First_Entity (Tasktyp);
12109 while Present (Ent) loop
12110 if Ekind_In (Ent, E_Entry, E_Entry_Family)
12111 and then Present (Contract (Ent))
12112 and then Present (Pre_Post_Conditions (Contract (Ent)))
12114 Build_PPC_Wrapper (Ent, N);
12120 end Expand_N_Task_Type_Declaration;
12122 -------------------------------
12123 -- Expand_N_Timed_Entry_Call --
12124 -------------------------------
12126 -- A timed entry call in normal case is not implemented using ATC mechanism
12127 -- anymore for efficiency reason.
12137 -- is expanded as follows:
12139 -- 1) When T.E is a task entry_call;
12143 -- X : Task_Entry_Index := <entry index>;
12144 -- DX : Duration := To_Duration (D);
12145 -- M : Delay_Mode := <discriminant>;
12146 -- P : parms := (parm, parm, parm);
12149 -- Timed_Protected_Entry_Call
12150 -- (<acceptor-task>, X, P'Address, DX, M, B);
12158 -- 2) When T.E is a protected entry_call;
12162 -- X : Protected_Entry_Index := <entry index>;
12163 -- DX : Duration := To_Duration (D);
12164 -- M : Delay_Mode := <discriminant>;
12165 -- P : parms := (parm, parm, parm);
12168 -- Timed_Protected_Entry_Call
12169 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12177 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12178 -- is no delay and the triggering statements are executed. We first
12179 -- determine the kind of the triggering call and then execute a
12180 -- synchronized operation or a direct call.
12183 -- B : Boolean := False;
12184 -- C : Ada.Tags.Prim_Op_Kind;
12185 -- DX : Duration := To_Duration (D)
12186 -- K : Ada.Tags.Tagged_Kind :=
12187 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12188 -- M : Integer :=...;
12189 -- P : Parameters := (Param1 .. ParamN);
12193 -- if K = Ada.Tags.TK_Limited_Tagged
12194 -- or else K = Ada.Tags.TK_Tagged
12196 -- <dispatching-call>;
12201 -- Ada.Tags.Get_Offset_Index
12202 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12204 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12206 -- if C = POK_Protected_Entry
12207 -- or else C = POK_Task_Entry
12209 -- Param1 := P.Param1;
12211 -- ParamN := P.ParamN;
12215 -- if C = POK_Procedure
12216 -- or else C = POK_Protected_Procedure
12217 -- or else C = POK_Task_Procedure
12219 -- <dispatching-call>;
12225 -- <triggering-statements>
12227 -- <timed-statements>
12231 -- The triggering statement and the sequence of timed statements have not
12232 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12233 -- global references if within an instantiation.
12235 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
12236 Loc : constant Source_Ptr := Sloc (N);
12239 Blk_Typ : Entity_Id;
12241 Call_Ent : Entity_Id;
12242 Conc_Typ_Stmts : List_Id;
12244 D_Alt : constant Node_Id := Delay_Alternative (N);
12247 D_Stat : Node_Id := Delay_Statement (D_Alt);
12249 D_Type : Entity_Id;
12252 E_Alt : constant Node_Id := Entry_Call_Alternative (N);
12253 E_Call : Node_Id := Entry_Call_Statement (E_Alt);
12258 Is_Disp_Select : Boolean;
12259 Lim_Typ_Stmts : List_Id;
12268 B : Entity_Id; -- Call status flag
12269 C : Entity_Id; -- Call kind
12270 D : Entity_Id; -- Delay
12271 K : Entity_Id; -- Tagged kind
12272 M : Entity_Id; -- Delay mode
12273 P : Entity_Id; -- Parameter block
12274 S : Entity_Id; -- Primitive operation slot
12276 -- Start of processing for Expand_N_Timed_Entry_Call
12279 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12280 -- was already reported on spec, so do not attempt to expand the call.
12282 if Restriction_Active (No_Select_Statements) then
12286 Process_Statements_For_Controlled_Objects (E_Alt);
12287 Process_Statements_For_Controlled_Objects (D_Alt);
12289 Ensure_Statement_Present (Sloc (D_Stat), D_Alt);
12291 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12292 -- may wrap them in blocks.
12294 E_Stats := Statements (E_Alt);
12295 D_Stats := Statements (D_Alt);
12297 -- The arguments in the call may require dynamic allocation, and the
12298 -- call statement may have been transformed into a block. The block
12299 -- may contain additional declarations for internal entities, and the
12300 -- original call is found by sequential search.
12302 if Nkind (E_Call) = N_Block_Statement then
12303 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
12304 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
12305 N_Entry_Call_Statement)
12312 Ada_Version >= Ada_2005
12313 and then Nkind (E_Call) = N_Procedure_Call_Statement;
12315 if Is_Disp_Select then
12316 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
12322 -- B : Boolean := False;
12324 B := Build_B (Loc, Decls);
12327 -- C : Ada.Tags.Prim_Op_Kind;
12329 C := Build_C (Loc, Decls);
12331 -- Because the analysis of all statements was disabled, manually
12332 -- analyze the delay statement.
12335 D_Stat := Original_Node (D_Stat);
12338 -- Build an entry call using Simple_Entry_Call
12340 Extract_Entry (E_Call, Concval, Ename, Index);
12341 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
12343 Decls := Declarations (E_Call);
12344 Stmts := Statements (Handled_Statement_Sequence (E_Call));
12353 B := Make_Defining_Identifier (Loc, Name_uB);
12356 Make_Object_Declaration (Loc,
12357 Defining_Identifier => B,
12358 Object_Definition =>
12359 New_Occurrence_Of (Standard_Boolean, Loc)));
12362 -- Duration and mode processing
12364 D_Type := Base_Type (Etype (Expression (D_Stat)));
12366 -- Use the type of the delay expression (Calendar or Real_Time) to
12367 -- generate the appropriate conversion.
12369 if Nkind (D_Stat) = N_Delay_Relative_Statement then
12370 D_Disc := Make_Integer_Literal (Loc, 0);
12371 D_Conv := Relocate_Node (Expression (D_Stat));
12373 elsif Is_RTE (D_Type, RO_CA_Time) then
12374 D_Disc := Make_Integer_Literal (Loc, 1);
12376 Make_Function_Call (Loc,
12377 Name => New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
12378 Parameter_Associations =>
12379 New_List (New_Copy (Expression (D_Stat))));
12381 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
12382 D_Disc := Make_Integer_Literal (Loc, 2);
12384 Make_Function_Call (Loc,
12385 Name => New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
12386 Parameter_Associations =>
12387 New_List (New_Copy (Expression (D_Stat))));
12390 D := Make_Temporary (Loc, 'D');
12396 Make_Object_Declaration (Loc,
12397 Defining_Identifier => D,
12398 Object_Definition => New_Occurrence_Of (Standard_Duration, Loc)));
12400 M := Make_Temporary (Loc, 'M');
12403 -- M : Integer := (0 | 1 | 2);
12406 Make_Object_Declaration (Loc,
12407 Defining_Identifier => M,
12408 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
12409 Expression => D_Disc));
12411 -- Do the assignment at this stage only because the evaluation of the
12412 -- expression must not occur before (see ACVC C97302A).
12415 Make_Assignment_Statement (Loc,
12416 Name => New_Occurrence_Of (D, Loc),
12417 Expression => D_Conv));
12419 -- Parameter block processing
12421 -- Manually create the parameter block for dispatching calls. In the
12422 -- case of entries, the block has already been created during the call
12423 -- to Build_Simple_Entry_Call.
12425 if Is_Disp_Select then
12427 -- Tagged kind processing, generate:
12428 -- K : Ada.Tags.Tagged_Kind :=
12429 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12431 K := Build_K (Loc, Decls, Obj);
12433 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
12435 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
12437 -- Dispatch table slot processing, generate:
12440 S := Build_S (Loc, Decls);
12443 -- S := Ada.Tags.Get_Offset_Index
12444 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12447 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
12450 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12452 -- where Obj is the controlling formal parameter, S is the dispatch
12453 -- table slot number of the dispatching operation, P is the wrapped
12454 -- parameter block, D is the duration, M is the duration mode, C is
12455 -- the call kind and B is the call status.
12457 Params := New_List;
12459 Append_To (Params, New_Copy_Tree (Obj));
12460 Append_To (Params, New_Occurrence_Of (S, Loc));
12462 Make_Attribute_Reference (Loc,
12463 Prefix => New_Occurrence_Of (P, Loc),
12464 Attribute_Name => Name_Address));
12465 Append_To (Params, New_Occurrence_Of (D, Loc));
12466 Append_To (Params, New_Occurrence_Of (M, Loc));
12467 Append_To (Params, New_Occurrence_Of (C, Loc));
12468 Append_To (Params, New_Occurrence_Of (B, Loc));
12470 Append_To (Conc_Typ_Stmts,
12471 Make_Procedure_Call_Statement (Loc,
12475 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
12476 Parameter_Associations => Params));
12479 -- if C = POK_Protected_Entry
12480 -- or else C = POK_Task_Entry
12482 -- Param1 := P.Param1;
12484 -- ParamN := P.ParamN;
12487 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
12489 -- Generate the if statement only when the packed parameters need
12490 -- explicit assignments to their corresponding actuals.
12492 if Present (Unpack) then
12493 Append_To (Conc_Typ_Stmts,
12494 Make_Implicit_If_Statement (N,
12500 Left_Opnd => New_Occurrence_Of (C, Loc),
12503 (RTE (RE_POK_Protected_Entry), Loc)),
12507 Left_Opnd => New_Occurrence_Of (C, Loc),
12509 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
12511 Then_Statements => Unpack));
12517 -- if C = POK_Procedure
12518 -- or else C = POK_Protected_Procedure
12519 -- or else C = POK_Task_Procedure
12521 -- <dispatching-call>
12525 N_Stats := New_List (
12526 Make_Implicit_If_Statement (N,
12531 Left_Opnd => New_Occurrence_Of (C, Loc),
12533 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
12539 Left_Opnd => New_Occurrence_Of (C, Loc),
12541 New_Occurrence_Of (RTE (
12542 RE_POK_Protected_Procedure), Loc)),
12545 Left_Opnd => New_Occurrence_Of (C, Loc),
12548 (RTE (RE_POK_Task_Procedure), Loc)))),
12550 Then_Statements => New_List (E_Call)));
12552 Append_To (Conc_Typ_Stmts,
12553 Make_Implicit_If_Statement (N,
12554 Condition => New_Occurrence_Of (B, Loc),
12555 Then_Statements => N_Stats));
12558 -- <dispatching-call>;
12562 New_List (New_Copy_Tree (E_Call),
12563 Make_Assignment_Statement (Loc,
12564 Name => New_Occurrence_Of (B, Loc),
12565 Expression => New_Occurrence_Of (Standard_True, Loc)));
12568 -- if K = Ada.Tags.TK_Limited_Tagged
12569 -- or else K = Ada.Tags.TK_Tagged
12577 Make_Implicit_If_Statement (N,
12578 Condition => Build_Dispatching_Tag_Check (K, N),
12579 Then_Statements => Lim_Typ_Stmts,
12580 Else_Statements => Conc_Typ_Stmts));
12585 -- <triggering-statements>
12587 -- <timed-statements>
12591 Make_Implicit_If_Statement (N,
12592 Condition => New_Occurrence_Of (B, Loc),
12593 Then_Statements => E_Stats,
12594 Else_Statements => D_Stats));
12597 -- Simple case of a non-dispatching trigger. Skip assignments to
12598 -- temporaries created for in-out parameters.
12600 -- This makes unwarranted assumptions about the shape of the expanded
12601 -- tree for the call, and should be cleaned up ???
12603 Stmt := First (Stmts);
12604 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
12608 -- Do the assignment at this stage only because the evaluation
12609 -- of the expression must not occur before (see ACVC C97302A).
12611 Insert_Before (Stmt,
12612 Make_Assignment_Statement (Loc,
12613 Name => New_Occurrence_Of (D, Loc),
12614 Expression => D_Conv));
12617 Params := Parameter_Associations (Call);
12619 -- For a protected type, we build a Timed_Protected_Entry_Call
12621 if Is_Protected_Type (Etype (Concval)) then
12623 -- Create a new call statement
12625 Param := First (Params);
12626 while Present (Param)
12627 and then not Is_RTE (Etype (Param), RE_Call_Modes)
12632 Dummy := Remove_Next (Next (Param));
12634 -- Remove garbage is following the Cancel_Param if present
12636 Dummy := Next (Param);
12638 -- Remove the mode of the Protected_Entry_Call call, then remove
12639 -- the Communication_Block of the Protected_Entry_Call call, and
12640 -- finally add Duration and a Delay_Mode parameter
12642 pragma Assert (Present (Param));
12643 Rewrite (Param, New_Occurrence_Of (D, Loc));
12645 Rewrite (Dummy, New_Occurrence_Of (M, Loc));
12647 -- Add a Boolean flag for successful entry call
12649 Append_To (Params, New_Occurrence_Of (B, Loc));
12651 case Corresponding_Runtime_Package (Etype (Concval)) is
12652 when System_Tasking_Protected_Objects_Entries =>
12654 Make_Procedure_Call_Statement (Loc,
12657 (RTE (RE_Timed_Protected_Entry_Call), Loc),
12658 Parameter_Associations => Params));
12661 raise Program_Error;
12664 -- For the task case, build a Timed_Task_Entry_Call
12667 -- Create a new call statement
12669 Append_To (Params, New_Occurrence_Of (D, Loc));
12670 Append_To (Params, New_Occurrence_Of (M, Loc));
12671 Append_To (Params, New_Occurrence_Of (B, Loc));
12674 Make_Procedure_Call_Statement (Loc,
12676 New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
12677 Parameter_Associations => Params));
12681 Make_Implicit_If_Statement (N,
12682 Condition => New_Occurrence_Of (B, Loc),
12683 Then_Statements => E_Stats,
12684 Else_Statements => D_Stats));
12688 Make_Block_Statement (Loc,
12689 Declarations => Decls,
12690 Handled_Statement_Sequence =>
12691 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
12694 end Expand_N_Timed_Entry_Call;
12696 ----------------------------------------
12697 -- Expand_Protected_Body_Declarations --
12698 ----------------------------------------
12700 procedure Expand_Protected_Body_Declarations
12702 Spec_Id : Entity_Id)
12705 if No_Run_Time_Mode then
12706 Error_Msg_CRT ("protected body", N);
12709 elsif Expander_Active then
12711 -- Associate discriminals with the first subprogram or entry body to
12714 if Present (First_Protected_Operation (Declarations (N))) then
12715 Set_Discriminals (Parent (Spec_Id));
12718 end Expand_Protected_Body_Declarations;
12720 -------------------------
12721 -- External_Subprogram --
12722 -------------------------
12724 function External_Subprogram (E : Entity_Id) return Entity_Id is
12725 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
12728 -- The internal and external subprograms follow each other on the entity
12729 -- chain. Note that previously private operations had no separate
12730 -- external subprogram. We now create one in all cases, because a
12731 -- private operation may actually appear in an external call, through
12732 -- a 'Access reference used for a callback.
12734 -- If the operation is a function that returns an anonymous access type,
12735 -- the corresponding itype appears before the operation, and must be
12738 -- This mechanism is fragile, there should be a real link between the
12739 -- two versions of the operation, but there is no place to put it ???
12741 if Is_Access_Type (Next_Entity (Subp)) then
12742 return Next_Entity (Next_Entity (Subp));
12744 return Next_Entity (Subp);
12746 end External_Subprogram;
12748 ------------------------------
12749 -- Extract_Dispatching_Call --
12750 ------------------------------
12752 procedure Extract_Dispatching_Call
12754 Call_Ent : out Entity_Id;
12755 Object : out Entity_Id;
12756 Actuals : out List_Id;
12757 Formals : out List_Id)
12759 Call_Nam : Node_Id;
12762 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
12764 if Present (Original_Node (N)) then
12765 Call_Nam := Name (Original_Node (N));
12767 Call_Nam := Name (N);
12770 -- Retrieve the name of the dispatching procedure. It contains the
12771 -- dispatch table slot number.
12774 case Nkind (Call_Nam) is
12775 when N_Identifier =>
12778 when N_Selected_Component =>
12779 Call_Nam := Selector_Name (Call_Nam);
12782 raise Program_Error;
12787 Actuals := Parameter_Associations (N);
12788 Call_Ent := Entity (Call_Nam);
12789 Formals := Parameter_Specifications (Parent (Call_Ent));
12790 Object := First (Actuals);
12792 if Present (Original_Node (Object)) then
12793 Object := Original_Node (Object);
12796 -- If the type of the dispatching object is an access type then return
12797 -- an explicit dereference.
12799 if Is_Access_Type (Etype (Object)) then
12800 Object := Make_Explicit_Dereference (Sloc (N), Object);
12803 end Extract_Dispatching_Call;
12805 -------------------
12806 -- Extract_Entry --
12807 -------------------
12809 procedure Extract_Entry
12811 Concval : out Node_Id;
12812 Ename : out Node_Id;
12813 Index : out Node_Id)
12815 Nam : constant Node_Id := Name (N);
12818 -- For a simple entry, the name is a selected component, with the
12819 -- prefix being the task value, and the selector being the entry.
12821 if Nkind (Nam) = N_Selected_Component then
12822 Concval := Prefix (Nam);
12823 Ename := Selector_Name (Nam);
12826 -- For a member of an entry family, the name is an indexed component
12827 -- where the prefix is a selected component, whose prefix in turn is
12828 -- the task value, and whose selector is the entry family. The single
12829 -- expression in the expressions list of the indexed component is the
12830 -- subscript for the family.
12832 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
12833 Concval := Prefix (Prefix (Nam));
12834 Ename := Selector_Name (Prefix (Nam));
12835 Index := First (Expressions (Nam));
12838 -- Through indirection, the type may actually be a limited view of a
12839 -- concurrent type. When compiling a call, the non-limited view of the
12840 -- type is visible.
12842 if From_Limited_With (Etype (Concval)) then
12843 Set_Etype (Concval, Non_Limited_View (Etype (Concval)));
12847 -------------------
12848 -- Family_Offset --
12849 -------------------
12851 function Family_Offset
12856 Cap : Boolean) return Node_Id
12862 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
12863 -- If one of the bounds is a reference to a discriminant, replace with
12864 -- corresponding discriminal of type. Within the body of a task retrieve
12865 -- the renamed discriminant by simple visibility, using its generated
12866 -- name. Within a protected object, find the original discriminant and
12867 -- replace it with the discriminal of the current protected operation.
12869 ------------------------------
12870 -- Convert_Discriminant_Ref --
12871 ------------------------------
12873 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
12874 Loc : constant Source_Ptr := Sloc (Bound);
12879 if Is_Entity_Name (Bound)
12880 and then Ekind (Entity (Bound)) = E_Discriminant
12882 if Is_Task_Type (Ttyp) and then Has_Completion (Ttyp) then
12883 B := Make_Identifier (Loc, Chars (Entity (Bound)));
12884 Find_Direct_Name (B);
12886 elsif Is_Protected_Type (Ttyp) then
12887 D := First_Discriminant (Ttyp);
12888 while Chars (D) /= Chars (Entity (Bound)) loop
12889 Next_Discriminant (D);
12892 B := New_Occurrence_Of (Discriminal (D), Loc);
12895 B := New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
12898 elsif Nkind (Bound) = N_Attribute_Reference then
12902 B := New_Copy_Tree (Bound);
12906 Make_Attribute_Reference (Loc,
12907 Attribute_Name => Name_Pos,
12908 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
12909 Expressions => New_List (B));
12910 end Convert_Discriminant_Ref;
12912 -- Start of processing for Family_Offset
12915 Real_Hi := Convert_Discriminant_Ref (Hi);
12916 Real_Lo := Convert_Discriminant_Ref (Lo);
12919 if Is_Task_Type (Ttyp) then
12920 Ityp := RTE (RE_Task_Entry_Index);
12922 Ityp := RTE (RE_Protected_Entry_Index);
12926 Make_Attribute_Reference (Loc,
12927 Prefix => New_Occurrence_Of (Ityp, Loc),
12928 Attribute_Name => Name_Min,
12929 Expressions => New_List (
12931 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12934 Make_Attribute_Reference (Loc,
12935 Prefix => New_Occurrence_Of (Ityp, Loc),
12936 Attribute_Name => Name_Max,
12937 Expressions => New_List (
12939 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12942 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12949 function Family_Size
12954 Cap : Boolean) return Node_Id
12959 if Is_Task_Type (Ttyp) then
12960 Ityp := RTE (RE_Task_Entry_Index);
12962 Ityp := RTE (RE_Protected_Entry_Index);
12966 Make_Attribute_Reference (Loc,
12967 Prefix => New_Occurrence_Of (Ityp, Loc),
12968 Attribute_Name => Name_Max,
12969 Expressions => New_List (
12971 Left_Opnd => Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
12972 Right_Opnd => Make_Integer_Literal (Loc, 1)),
12973 Make_Integer_Literal (Loc, 0)));
12976 ----------------------------
12977 -- Find_Enclosing_Context --
12978 ----------------------------
12980 procedure Find_Enclosing_Context
12982 Context : out Node_Id;
12983 Context_Id : out Entity_Id;
12984 Context_Decls : out List_Id)
12987 -- Traverse the parent chain looking for an enclosing body, block,
12988 -- package or return statement.
12990 Context := Parent (N);
12991 while not Nkind_In (Context, N_Block_Statement,
12993 N_Extended_Return_Statement,
12995 N_Package_Declaration,
12999 Context := Parent (Context);
13002 -- Extract the constituents of the context
13004 if Nkind (Context) = N_Extended_Return_Statement then
13005 Context_Decls := Return_Object_Declarations (Context);
13006 Context_Id := Return_Statement_Entity (Context);
13008 -- Package declarations and bodies use a common library-level activation
13009 -- chain or task master, therefore return the package declaration as the
13010 -- proper carrier for the appropriate flag.
13012 elsif Nkind (Context) = N_Package_Body then
13013 Context_Decls := Declarations (Context);
13014 Context_Id := Corresponding_Spec (Context);
13015 Context := Parent (Context_Id);
13017 if Nkind (Context) = N_Defining_Program_Unit_Name then
13018 Context := Parent (Parent (Context));
13020 Context := Parent (Context);
13023 elsif Nkind (Context) = N_Package_Declaration then
13024 Context_Decls := Visible_Declarations (Specification (Context));
13025 Context_Id := Defining_Unit_Name (Specification (Context));
13027 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13028 Context_Id := Defining_Identifier (Context_Id);
13032 Context_Decls := Declarations (Context);
13034 if Nkind (Context) = N_Block_Statement then
13035 Context_Id := Entity (Identifier (Context));
13037 elsif Nkind (Context) = N_Entry_Body then
13038 Context_Id := Defining_Identifier (Context);
13040 elsif Nkind (Context) = N_Subprogram_Body then
13041 if Present (Corresponding_Spec (Context)) then
13042 Context_Id := Corresponding_Spec (Context);
13044 Context_Id := Defining_Unit_Name (Specification (Context));
13046 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13047 Context_Id := Defining_Identifier (Context_Id);
13051 elsif Nkind (Context) = N_Task_Body then
13052 Context_Id := Corresponding_Spec (Context);
13055 raise Program_Error;
13059 pragma Assert (Present (Context));
13060 pragma Assert (Present (Context_Id));
13061 pragma Assert (Present (Context_Decls));
13062 end Find_Enclosing_Context;
13064 -----------------------
13065 -- Find_Master_Scope --
13066 -----------------------
13068 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
13072 -- In Ada 2005, the master is the innermost enclosing scope that is not
13073 -- transient. If the enclosing block is the rewriting of a call or the
13074 -- scope is an extended return statement this is valid master. The
13075 -- master in an extended return is only used within the return, and is
13076 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13077 -- now before that overwriting occurs.
13081 if Ada_Version >= Ada_2005 then
13082 while Is_Internal (S) loop
13083 if Nkind (Parent (S)) = N_Block_Statement
13085 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
13089 elsif Ekind (S) = E_Return_Statement then
13099 end Find_Master_Scope;
13101 -------------------------------
13102 -- First_Protected_Operation --
13103 -------------------------------
13105 function First_Protected_Operation (D : List_Id) return Node_Id is
13106 First_Op : Node_Id;
13109 First_Op := First (D);
13110 while Present (First_Op)
13111 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
13117 end First_Protected_Operation;
13119 ---------------------------------------
13120 -- Install_Private_Data_Declarations --
13121 ---------------------------------------
13123 procedure Install_Private_Data_Declarations
13125 Spec_Id : Entity_Id;
13126 Conc_Typ : Entity_Id;
13127 Body_Nod : Node_Id;
13129 Barrier : Boolean := False;
13130 Family : Boolean := False)
13132 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
13135 Insert_Node : Node_Id := Empty;
13136 Obj_Ent : Entity_Id;
13138 procedure Add (Decl : Node_Id);
13139 -- Add a single declaration after Insert_Node. If this is the first
13140 -- addition, Decl is added to the front of Decls and it becomes the
13143 function Replace_Bound (Bound : Node_Id) return Node_Id;
13144 -- The bounds of an entry index may depend on discriminants, create a
13145 -- reference to the corresponding prival. Otherwise return a duplicate
13146 -- of the original bound.
13152 procedure Add (Decl : Node_Id) is
13154 if No (Insert_Node) then
13155 Prepend_To (Decls, Decl);
13157 Insert_After (Insert_Node, Decl);
13160 Insert_Node := Decl;
13163 --------------------------
13164 -- Replace_Discriminant --
13165 --------------------------
13167 function Replace_Bound (Bound : Node_Id) return Node_Id is
13169 if Nkind (Bound) = N_Identifier
13170 and then Is_Discriminal (Entity (Bound))
13172 return Make_Identifier (Loc, Chars (Entity (Bound)));
13174 return Duplicate_Subexpr (Bound);
13178 -- Start of processing for Install_Private_Data_Declarations
13181 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13182 -- formal parameter _O, _object or _task depending on the context.
13184 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
13186 -- Special processing of _O for barrier functions, protected entries
13193 (Ekind (Spec_Id) = E_Entry
13194 or else Ekind (Spec_Id) = E_Entry_Family))
13197 Conc_Rec : constant Entity_Id :=
13198 Corresponding_Record_Type (Conc_Typ);
13199 Typ_Id : constant Entity_Id :=
13200 Make_Defining_Identifier (Loc,
13201 New_External_Name (Chars (Conc_Rec), 'P'));
13204 -- type prot_typVP is access prot_typV;
13207 Make_Full_Type_Declaration (Loc,
13208 Defining_Identifier => Typ_Id,
13210 Make_Access_To_Object_Definition (Loc,
13211 Subtype_Indication =>
13212 New_Occurrence_Of (Conc_Rec, Loc)));
13216 -- _object : prot_typVP := prot_typV (_O);
13219 Make_Object_Declaration (Loc,
13220 Defining_Identifier =>
13221 Make_Defining_Identifier (Loc, Name_uObject),
13222 Object_Definition => New_Occurrence_Of (Typ_Id, Loc),
13224 Unchecked_Convert_To (Typ_Id,
13225 New_Occurrence_Of (Obj_Ent, Loc)));
13228 -- Set the reference to the concurrent object
13230 Obj_Ent := Defining_Identifier (Decl);
13234 -- Step 2: Create the Protection object and build its declaration for
13235 -- any protected entry (family) of subprogram. Note for the lock-free
13236 -- implementation, the Protection object is not needed anymore.
13238 if Is_Protected and then not Uses_Lock_Free (Conc_Typ) then
13240 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
13244 Set_Protection_Object (Spec_Id, Prot_Ent);
13246 -- Determine the proper protection type
13248 if Has_Attach_Handler (Conc_Typ)
13249 and then not Restricted_Profile
13251 Prot_Typ := RE_Static_Interrupt_Protection;
13253 elsif Has_Interrupt_Handler (Conc_Typ)
13254 and then not Restriction_Active (No_Dynamic_Attachment)
13256 Prot_Typ := RE_Dynamic_Interrupt_Protection;
13259 case Corresponding_Runtime_Package (Conc_Typ) is
13260 when System_Tasking_Protected_Objects_Entries =>
13261 Prot_Typ := RE_Protection_Entries;
13263 when System_Tasking_Protected_Objects_Single_Entry =>
13264 Prot_Typ := RE_Protection_Entry;
13266 when System_Tasking_Protected_Objects =>
13267 Prot_Typ := RE_Protection;
13270 raise Program_Error;
13275 -- conc_typR : protection_typ renames _object._object;
13278 Make_Object_Renaming_Declaration (Loc,
13279 Defining_Identifier => Prot_Ent,
13281 New_Occurrence_Of (RTE (Prot_Typ), Loc),
13283 Make_Selected_Component (Loc,
13284 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13285 Selector_Name => Make_Identifier (Loc, Name_uObject)));
13290 -- Step 3: Add discriminant renamings (if any)
13292 if Has_Discriminants (Conc_Typ) then
13297 D := First_Discriminant (Conc_Typ);
13298 while Present (D) loop
13300 -- Adjust the source location
13302 Set_Sloc (Discriminal (D), Loc);
13305 -- discr_name : discr_typ renames _object.discr_name;
13307 -- discr_name : discr_typ renames _task.discr_name;
13310 Make_Object_Renaming_Declaration (Loc,
13311 Defining_Identifier => Discriminal (D),
13312 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
13314 Make_Selected_Component (Loc,
13315 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13316 Selector_Name => Make_Identifier (Loc, Chars (D))));
13319 Next_Discriminant (D);
13324 -- Step 4: Add private component renamings (if any)
13326 if Is_Protected then
13327 Def := Protected_Definition (Parent (Conc_Typ));
13329 if Present (Private_Declarations (Def)) then
13332 Comp_Id : Entity_Id;
13333 Decl_Id : Entity_Id;
13336 Comp := First (Private_Declarations (Def));
13337 while Present (Comp) loop
13338 if Nkind (Comp) = N_Component_Declaration then
13339 Comp_Id := Defining_Identifier (Comp);
13341 Make_Defining_Identifier (Loc, Chars (Comp_Id));
13343 -- Minimal decoration
13345 if Ekind (Spec_Id) = E_Function then
13346 Set_Ekind (Decl_Id, E_Constant);
13348 Set_Ekind (Decl_Id, E_Variable);
13351 Set_Prival (Comp_Id, Decl_Id);
13352 Set_Prival_Link (Decl_Id, Comp_Id);
13353 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
13356 -- comp_name : comp_typ renames _object.comp_name;
13359 Make_Object_Renaming_Declaration (Loc,
13360 Defining_Identifier => Decl_Id,
13362 New_Occurrence_Of (Etype (Comp_Id), Loc),
13364 Make_Selected_Component (Loc,
13366 New_Occurrence_Of (Obj_Ent, Loc),
13368 Make_Identifier (Loc, Chars (Comp_Id))));
13378 -- Step 5: Add the declaration of the entry index and the associated
13379 -- type for barrier functions and entry families.
13381 if (Barrier and Family) or else Ekind (Spec_Id) = E_Entry_Family then
13383 E : constant Entity_Id := Index_Object (Spec_Id);
13384 Index : constant Entity_Id :=
13385 Defining_Identifier
13386 (Entry_Index_Specification
13387 (Entry_Body_Formal_Part (Body_Nod)));
13388 Index_Con : constant Entity_Id :=
13389 Make_Defining_Identifier (Loc, Chars (Index));
13391 Index_Typ : Entity_Id;
13395 -- Minimal decoration
13397 Set_Ekind (Index_Con, E_Constant);
13398 Set_Entry_Index_Constant (Index, Index_Con);
13399 Set_Discriminal_Link (Index_Con, Index);
13401 -- Retrieve the bounds of the entry family
13403 High := Type_High_Bound (Etype (Index));
13404 Low := Type_Low_Bound (Etype (Index));
13406 -- In the simple case the entry family is given by a subtype
13407 -- mark and the index constant has the same type.
13409 if Is_Entity_Name (Original_Node (
13410 Discrete_Subtype_Definition (Parent (Index))))
13412 Index_Typ := Etype (Index);
13414 -- Otherwise a new subtype declaration is required
13417 High := Replace_Bound (High);
13418 Low := Replace_Bound (Low);
13420 Index_Typ := Make_Temporary (Loc, 'J');
13423 -- subtype Jnn is <Etype of Index> range Low .. High;
13426 Make_Subtype_Declaration (Loc,
13427 Defining_Identifier => Index_Typ,
13428 Subtype_Indication =>
13429 Make_Subtype_Indication (Loc,
13431 New_Occurrence_Of (Base_Type (Etype (Index)), Loc),
13433 Make_Range_Constraint (Loc,
13434 Range_Expression =>
13435 Make_Range (Loc, Low, High))));
13439 Set_Etype (Index_Con, Index_Typ);
13441 -- Create the object which designates the index:
13442 -- J : constant Jnn :=
13443 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13445 -- where Jnn is the subtype created above or the original type of
13446 -- the index, _E is a formal of the protected body subprogram and
13447 -- <index expr> is the index of the first family member.
13450 Make_Object_Declaration (Loc,
13451 Defining_Identifier => Index_Con,
13452 Constant_Present => True,
13453 Object_Definition =>
13454 New_Occurrence_Of (Index_Typ, Loc),
13457 Make_Attribute_Reference (Loc,
13459 New_Occurrence_Of (Index_Typ, Loc),
13460 Attribute_Name => Name_Val,
13462 Expressions => New_List (
13466 Make_Op_Subtract (Loc,
13467 Left_Opnd => New_Occurrence_Of (E, Loc),
13469 Entry_Index_Expression (Loc,
13470 Defining_Identifier (Body_Nod),
13474 Make_Attribute_Reference (Loc,
13476 New_Occurrence_Of (Index_Typ, Loc),
13477 Attribute_Name => Name_Pos,
13478 Expressions => New_List (
13479 Make_Attribute_Reference (Loc,
13481 New_Occurrence_Of (Index_Typ, Loc),
13482 Attribute_Name => Name_First)))))));
13486 end Install_Private_Data_Declarations;
13488 -----------------------
13489 -- Is_Exception_Safe --
13490 -----------------------
13492 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
13494 function Has_Side_Effect (N : Node_Id) return Boolean;
13495 -- Return True whenever encountering a subprogram call or raise
13496 -- statement of any kind in the sequence of statements
13498 ---------------------
13499 -- Has_Side_Effect --
13500 ---------------------
13502 -- What is this doing buried two levels down in exp_ch9. It seems like a
13503 -- generally useful function, and indeed there may be code duplication
13504 -- going on here ???
13506 function Has_Side_Effect (N : Node_Id) return Boolean is
13510 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
13511 -- Indicate whether N is a subprogram call or a raise statement
13513 ----------------------
13514 -- Is_Call_Or_Raise --
13515 ----------------------
13517 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
13519 return Nkind_In (N, N_Procedure_Call_Statement,
13522 N_Raise_Constraint_Error,
13523 N_Raise_Program_Error,
13524 N_Raise_Storage_Error);
13525 end Is_Call_Or_Raise;
13527 -- Start of processing for Has_Side_Effect
13531 while Present (Stmt) loop
13532 if Is_Call_Or_Raise (Stmt) then
13536 -- An object declaration can also contain a function call or a
13537 -- raise statement.
13539 if Nkind (Stmt) = N_Object_Declaration then
13540 Expr := Expression (Stmt);
13542 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
13551 end Has_Side_Effect;
13553 -- Start of processing for Is_Exception_Safe
13556 -- When exceptions can't be propagated, the subprogram returns normally
13558 if No_Exception_Handlers_Set then
13562 -- If the checks handled by the back end are not disabled, we cannot
13563 -- ensure that no exception will be raised.
13565 if not Access_Checks_Suppressed (Empty)
13566 or else not Discriminant_Checks_Suppressed (Empty)
13567 or else not Range_Checks_Suppressed (Empty)
13568 or else not Index_Checks_Suppressed (Empty)
13569 or else Opt.Stack_Checking_Enabled
13574 if Has_Side_Effect (First (Declarations (Subprogram)))
13577 (First (Statements (Handled_Statement_Sequence (Subprogram))))
13583 end Is_Exception_Safe;
13585 ---------------------------------
13586 -- Is_Potentially_Large_Family --
13587 ---------------------------------
13589 function Is_Potentially_Large_Family
13590 (Base_Index : Entity_Id;
13591 Conctyp : Entity_Id;
13593 Hi : Node_Id) return Boolean
13596 return Scope (Base_Index) = Standard_Standard
13597 and then Base_Index = Base_Type (Standard_Integer)
13598 and then Has_Discriminants (Conctyp)
13600 Present (Discriminant_Default_Value (First_Discriminant (Conctyp)))
13602 (Denotes_Discriminant (Lo, True)
13604 Denotes_Discriminant (Hi, True));
13605 end Is_Potentially_Large_Family;
13607 -------------------------------------
13608 -- Is_Private_Primitive_Subprogram --
13609 -------------------------------------
13611 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
13614 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
13615 and then Is_Private_Primitive (Id);
13616 end Is_Private_Primitive_Subprogram;
13622 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
13623 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
13624 Formal : Entity_Id;
13627 Formal := First_Formal (Bod_Subp);
13628 while Present (Formal) loop
13630 -- Look for formal parameter _E
13632 if Chars (Formal) = Name_uE then
13636 Next_Formal (Formal);
13639 -- A protected body subprogram should always have the parameter in
13642 raise Program_Error;
13645 --------------------------------
13646 -- Make_Initialize_Protection --
13647 --------------------------------
13649 function Make_Initialize_Protection
13650 (Protect_Rec : Entity_Id) return List_Id
13652 Loc : constant Source_Ptr := Sloc (Protect_Rec);
13655 Ptyp : constant Node_Id :=
13656 Corresponding_Concurrent_Type (Protect_Rec);
13658 L : constant List_Id := New_List;
13659 Has_Entry : constant Boolean := Has_Entries (Ptyp);
13660 Prio_Type : Entity_Id;
13661 Prio_Var : Entity_Id := Empty;
13662 Restricted : constant Boolean := Restricted_Profile;
13665 -- We may need two calls to properly initialize the object, one to
13666 -- Initialize_Protection, and possibly one to Install_Handlers if we
13667 -- have a pragma Attach_Handler.
13669 -- Get protected declaration. In the case of a task type declaration,
13670 -- this is simply the parent of the protected type entity. In the single
13671 -- protected object declaration, this parent will be the implicit type,
13672 -- and we can find the corresponding single protected object declaration
13673 -- by searching forward in the declaration list in the tree.
13675 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13676 -- of this type should have been removed during semantic analysis.
13678 Pdec := Parent (Ptyp);
13679 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
13680 N_Single_Protected_Declaration)
13685 -- Build the parameter list for the call. Note that _Init is the name
13686 -- of the formal for the object to be initialized, which is the task
13687 -- value record itself.
13691 -- For lock-free implementation, skip initializations of the Protection
13694 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13696 -- Object parameter. This is a pointer to the object of type
13697 -- Protection used by the GNARL to control the protected object.
13700 Make_Attribute_Reference (Loc,
13702 Make_Selected_Component (Loc,
13703 Prefix => Make_Identifier (Loc, Name_uInit),
13704 Selector_Name => Make_Identifier (Loc, Name_uObject)),
13705 Attribute_Name => Name_Unchecked_Access));
13707 -- Priority parameter. Set to Unspecified_Priority unless there is a
13708 -- Priority rep item, in which case we take the value from the pragma
13709 -- or attribute definition clause, or there is an Interrupt_Priority
13710 -- rep item and no Priority rep item, and we set the ceiling to
13711 -- Interrupt_Priority'Last, an implementation-defined value, see
13714 if Has_Rep_Item (Ptyp, Name_Priority, Check_Parents => False) then
13716 Prio_Clause : constant Node_Id :=
13718 (Ptyp, Name_Priority, Check_Parents => False);
13725 if Nkind (Prio_Clause) = N_Pragma then
13728 (First (Pragma_Argument_Associations (Prio_Clause)));
13730 -- Get_Rep_Item returns either priority pragma.
13732 if Pragma_Name (Prio_Clause) = Name_Priority then
13733 Prio_Type := RTE (RE_Any_Priority);
13735 Prio_Type := RTE (RE_Interrupt_Priority);
13738 -- Attribute definition clause Priority
13741 if Chars (Prio_Clause) = Name_Priority then
13742 Prio_Type := RTE (RE_Any_Priority);
13744 Prio_Type := RTE (RE_Interrupt_Priority);
13747 Prio := Expression (Prio_Clause);
13750 -- Always create a locale variable to capture the priority.
13751 -- The priority is also passed to Install_Restriced_Handlers.
13752 -- Note that it is really necessary to create this variable
13753 -- explicitly. It might be thought that removing side effects
13754 -- would the appropriate approach, but that could generate
13755 -- declarations improperly placed in the enclosing scope.
13757 Prio_Var := Make_Temporary (Loc, 'R', Prio);
13759 Make_Object_Declaration (Loc,
13760 Defining_Identifier => Prio_Var,
13761 Object_Definition => New_Occurrence_Of (Prio_Type, Loc),
13762 Expression => Relocate_Node (Prio)));
13764 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13767 -- When no priority is specified but an xx_Handler pragma is, we
13768 -- default to System.Interrupts.Default_Interrupt_Priority, see
13771 elsif Has_Attach_Handler (Ptyp)
13772 or else Has_Interrupt_Handler (Ptyp)
13775 New_Occurrence_Of (RTE (RE_Default_Interrupt_Priority), Loc));
13777 -- Normal case, no priority or xx_Handler specified, default priority
13781 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
13784 -- Test for Compiler_Info parameter. This parameter allows entry body
13785 -- procedures and barrier functions to be called from the runtime. It
13786 -- is a pointer to the record generated by the compiler to represent
13787 -- the protected object.
13789 -- A protected type without entries that covers an interface and
13790 -- overrides the abstract routines with protected procedures is
13791 -- considered equivalent to a protected type with entries in the
13792 -- context of dispatching select statements.
13794 -- Protected types with interrupt handlers (when not using a
13795 -- restricted profile) are also considered equivalent to protected
13796 -- types with entries.
13798 -- The types which are used (Static_Interrupt_Protection and
13799 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13802 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
13804 Called_Subp : RE_Id;
13808 when System_Tasking_Protected_Objects_Entries =>
13809 Called_Subp := RE_Initialize_Protection_Entries;
13811 -- Argument Compiler_Info
13814 Make_Attribute_Reference (Loc,
13815 Prefix => Make_Identifier (Loc, Name_uInit),
13816 Attribute_Name => Name_Address));
13818 when System_Tasking_Protected_Objects_Single_Entry =>
13819 Called_Subp := RE_Initialize_Protection_Entry;
13821 -- Argument Compiler_Info
13824 Make_Attribute_Reference (Loc,
13825 Prefix => Make_Identifier (Loc, Name_uInit),
13826 Attribute_Name => Name_Address));
13828 when System_Tasking_Protected_Objects =>
13829 Called_Subp := RE_Initialize_Protection;
13832 raise Program_Error;
13835 -- Entry_Bodies parameter. This is a pointer to an array of
13836 -- pointers to the entry body procedures and barrier functions of
13837 -- the object. If the protected type has no entries this object
13838 -- will not exist, in this case, pass a null (it can happen when
13839 -- there are protected interrupt handlers or interfaces).
13842 P_Arr := Entry_Bodies_Array (Ptyp);
13844 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13845 -- multiple entries).
13848 Make_Attribute_Reference (Loc,
13849 Prefix => New_Occurrence_Of (P_Arr, Loc),
13850 Attribute_Name => Name_Unrestricted_Access));
13852 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
13854 -- Find index mapping function (clumsy but ok for now)
13856 while Ekind (P_Arr) /= E_Function loop
13857 Next_Entity (P_Arr);
13861 Make_Attribute_Reference (Loc,
13862 Prefix => New_Occurrence_Of (P_Arr, Loc),
13863 Attribute_Name => Name_Unrestricted_Access));
13866 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
13868 -- This is the case where we have a protected object with
13869 -- interfaces and no entries, and the single entry restriction
13870 -- is in effect. We pass a null pointer for the entry
13871 -- parameter because there is no actual entry.
13873 Append_To (Args, Make_Null (Loc));
13875 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
13877 -- This is the case where we have a protected object with no
13879 -- - either interrupt handlers with non restricted profile,
13881 -- Note that the types which are used for interrupt handlers
13882 -- (Static/Dynamic_Interrupt_Protection) are derived from
13883 -- Protection_Entries. We pass two null pointers because there
13884 -- is no actual entry, and the initialization procedure needs
13885 -- both Entry_Bodies and Find_Body_Index.
13887 Append_To (Args, Make_Null (Loc));
13888 Append_To (Args, Make_Null (Loc));
13892 Make_Procedure_Call_Statement (Loc,
13894 New_Occurrence_Of (RTE (Called_Subp), Loc),
13895 Parameter_Associations => Args));
13899 if Has_Attach_Handler (Ptyp) then
13901 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13902 -- make the following call:
13904 -- Install_Handlers (_object,
13905 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13907 -- or, in the case of Ravenscar:
13909 -- Install_Restricted_Handlers
13910 -- (Prio, (Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13913 Args : constant List_Id := New_List;
13914 Table : constant List_Id := New_List;
13915 Ritem : Node_Id := First_Rep_Item (Ptyp);
13918 -- Build the Priority parameter (only for ravenscar)
13922 -- Priority comes from a pragma
13924 if Present (Prio_Var) then
13925 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13927 -- Priority is the default one
13932 (RTE (RE_Default_Interrupt_Priority), Loc));
13936 -- Build the Attach_Handler table argument
13938 while Present (Ritem) loop
13939 if Nkind (Ritem) = N_Pragma
13940 and then Pragma_Name (Ritem) = Name_Attach_Handler
13943 Handler : constant Node_Id :=
13944 First (Pragma_Argument_Associations (Ritem));
13946 Interrupt : constant Node_Id := Next (Handler);
13947 Expr : constant Node_Id := Expression (Interrupt);
13951 Make_Aggregate (Loc, Expressions => New_List (
13952 Unchecked_Convert_To
13953 (RTE (RE_System_Interrupt_Id), Expr),
13954 Make_Attribute_Reference (Loc,
13956 Make_Selected_Component (Loc,
13958 Make_Identifier (Loc, Name_uInit),
13960 Duplicate_Subexpr_No_Checks
13961 (Expression (Handler))),
13962 Attribute_Name => Name_Access))));
13966 Next_Rep_Item (Ritem);
13969 -- Append the table argument we just built
13971 Append_To (Args, Make_Aggregate (Loc, Table));
13973 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13974 -- call to the statements.
13977 -- Call a simplified version of Install_Handlers to be used
13978 -- when the Ravenscar restrictions are in effect
13979 -- (Install_Restricted_Handlers).
13982 Make_Procedure_Call_Statement (Loc,
13985 (RTE (RE_Install_Restricted_Handlers), Loc),
13986 Parameter_Associations => Args));
13989 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13991 -- First, prepends the _object argument
13994 Make_Attribute_Reference (Loc,
13996 Make_Selected_Component (Loc,
13997 Prefix => Make_Identifier (Loc, Name_uInit),
13999 Make_Identifier (Loc, Name_uObject)),
14000 Attribute_Name => Name_Unchecked_Access));
14003 -- Then, insert call to Install_Handlers
14006 Make_Procedure_Call_Statement (Loc,
14008 New_Occurrence_Of (RTE (RE_Install_Handlers), Loc),
14009 Parameter_Associations => Args));
14015 end Make_Initialize_Protection;
14017 ---------------------------
14018 -- Make_Task_Create_Call --
14019 ---------------------------
14021 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
14022 Loc : constant Source_Ptr := Sloc (Task_Rec);
14032 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
14033 Tnam := Chars (Ttyp);
14035 -- Get task declaration. In the case of a task type declaration, this is
14036 -- simply the parent of the task type entity. In the single task
14037 -- declaration, this parent will be the implicit type, and we can find
14038 -- the corresponding single task declaration by searching forward in the
14039 -- declaration list in the tree.
14041 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14042 -- this type should have been removed during semantic analysis.
14044 Tdec := Parent (Ttyp);
14045 while not Nkind_In (Tdec, N_Task_Type_Declaration,
14046 N_Single_Task_Declaration)
14051 -- Now we can find the task definition from this declaration
14053 Tdef := Task_Definition (Tdec);
14055 -- Build the parameter list for the call. Note that _Init is the name
14056 -- of the formal for the object to be initialized, which is the task
14057 -- value record itself.
14061 -- Priority parameter. Set to Unspecified_Priority unless there is a
14062 -- Priority rep item, in which case we take the value from the rep item.
14064 if Has_Rep_Item (Ttyp, Name_Priority, Check_Parents => False) then
14066 Make_Selected_Component (Loc,
14067 Prefix => Make_Identifier (Loc, Name_uInit),
14068 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
14071 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
14074 -- Optional Stack parameter
14076 if Restricted_Profile then
14078 -- If the stack has been preallocated by the expander then
14079 -- pass its address. Otherwise, pass a null address.
14081 if Preallocated_Stacks_On_Target then
14083 Make_Attribute_Reference (Loc,
14085 Make_Selected_Component (Loc,
14086 Prefix => Make_Identifier (Loc, Name_uInit),
14087 Selector_Name => Make_Identifier (Loc, Name_uStack)),
14088 Attribute_Name => Name_Address));
14092 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
14096 -- Size parameter. If no Storage_Size pragma is present, then
14097 -- the size is taken from the taskZ variable for the type, which
14098 -- is either Unspecified_Size, or has been reset by the use of
14099 -- a Storage_Size attribute definition clause. If a pragma is
14100 -- present, then the size is taken from the _Size field of the
14101 -- task value record, which was set from the pragma value.
14103 if Present (Tdef) and then Has_Storage_Size_Pragma (Tdef) then
14105 Make_Selected_Component (Loc,
14106 Prefix => Make_Identifier (Loc, Name_uInit),
14107 Selector_Name => Make_Identifier (Loc, Name_uSize)));
14111 New_Occurrence_Of (Storage_Size_Variable (Ttyp), Loc));
14114 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14115 -- Task_Info pragma, in which case we take the value from the pragma.
14117 if Has_Rep_Pragma (Ttyp, Name_Task_Info, Check_Parents => False) then
14119 Make_Selected_Component (Loc,
14120 Prefix => Make_Identifier (Loc, Name_uInit),
14121 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
14125 New_Occurrence_Of (RTE (RE_Unspecified_Task_Info), Loc));
14128 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14129 -- in which case we take the value from the rep item. The parameter is
14130 -- passed as an Integer because in the case of unspecified CPU the
14131 -- value is not in the range of CPU_Range.
14133 if Has_Rep_Item (Ttyp, Name_CPU, Check_Parents => False) then
14135 Convert_To (Standard_Integer,
14136 Make_Selected_Component (Loc,
14137 Prefix => Make_Identifier (Loc, Name_uInit),
14138 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
14141 New_Occurrence_Of (RTE (RE_Unspecified_CPU), Loc));
14144 if not Restricted_Profile then
14146 -- Deadline parameter. If no Relative_Deadline pragma is present,
14147 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14148 -- the deadline is taken from the _Relative_Deadline field of the
14149 -- task value record, which was set from the pragma value. Note that
14150 -- this parameter must not be generated for the restricted profiles
14151 -- since Ravenscar does not allow deadlines.
14153 -- Case where pragma Relative_Deadline applies: use given value
14155 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
14157 Make_Selected_Component (Loc,
14158 Prefix => Make_Identifier (Loc, Name_uInit),
14160 Make_Identifier (Loc, Name_uRelative_Deadline)));
14162 -- No pragma Relative_Deadline apply to the task
14166 New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc));
14169 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14170 -- present, then the dispatching domain is null. If a rep item is
14171 -- present, then the dispatching domain is taken from the
14172 -- _Dispatching_Domain field of the task value record, which was set
14173 -- from the rep item value.
14175 -- Case where Dispatching_Domain rep item applies: use given value
14178 (Ttyp, Name_Dispatching_Domain, Check_Parents => False)
14181 Make_Selected_Component (Loc,
14183 Make_Identifier (Loc, Name_uInit),
14185 Make_Identifier (Loc, Name_uDispatching_Domain)));
14187 -- No pragma or aspect Dispatching_Domain applies to the task
14190 Append_To (Args, Make_Null (Loc));
14193 -- Number of entries. This is an expression of the form:
14195 -- n + _Init.a'Length + _Init.a'B'Length + ...
14197 -- where a,b... are the entry family names for the task definition
14200 Build_Entry_Count_Expression
14205 (Parent (Corresponding_Record_Type (Ttyp))))),
14207 Append_To (Args, Ecount);
14209 -- Master parameter. This is a reference to the _Master parameter of
14210 -- the initialization procedure, except in the case of the pragma
14211 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14212 -- System.Tasking.Library_Task_Level.
14214 if Restriction_Active (No_Task_Hierarchy) = False then
14215 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
14218 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
14222 -- State parameter. This is a pointer to the task body procedure. The
14223 -- required value is obtained by taking 'Unrestricted_Access of the task
14224 -- body procedure and converting it (with an unchecked conversion) to
14225 -- the type required by the task kernel. For further details, see the
14226 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14227 -- than 'Address in order to avoid creating trampolines.
14230 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
14231 Subp_Ptr_Typ : constant Node_Id :=
14232 Create_Itype (E_Access_Subprogram_Type, Tdec);
14233 Ref : constant Node_Id := Make_Itype_Reference (Loc);
14236 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
14237 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
14239 -- Be sure to freeze a reference to the access-to-subprogram type,
14240 -- otherwise gigi will complain that it's in the wrong scope, because
14241 -- it's actually inside the init procedure for the record type that
14242 -- corresponds to the task type.
14244 Set_Itype (Ref, Subp_Ptr_Typ);
14245 Append_Freeze_Action (Task_Rec, Ref);
14248 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
14249 Make_Qualified_Expression (Loc,
14250 Subtype_Mark => New_Occurrence_Of (Subp_Ptr_Typ, Loc),
14252 Make_Attribute_Reference (Loc,
14253 Prefix => New_Occurrence_Of (Body_Proc, Loc),
14254 Attribute_Name => Name_Unrestricted_Access))));
14257 -- Discriminants parameter. This is just the address of the task
14258 -- value record itself (which contains the discriminant values
14261 Make_Attribute_Reference (Loc,
14262 Prefix => Make_Identifier (Loc, Name_uInit),
14263 Attribute_Name => Name_Address));
14265 -- Elaborated parameter. This is an access to the elaboration Boolean
14268 Make_Attribute_Reference (Loc,
14269 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
14270 Attribute_Name => Name_Unchecked_Access));
14272 -- Add Chain parameter (not done for sequential elaboration policy, see
14273 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14275 if Partition_Elaboration_Policy /= 'S' then
14276 Append_To (Args, Make_Identifier (Loc, Name_uChain));
14279 -- Task name parameter. Take this from the _Task_Id parameter to the
14280 -- init call unless there is a Task_Name pragma, in which case we take
14281 -- the value from the pragma.
14283 if Has_Rep_Pragma (Ttyp, Name_Task_Name, Check_Parents => False) then
14284 -- Copy expression in full, because it may be dynamic and have
14291 (Pragma_Argument_Associations
14293 (Ttyp, Name_Task_Name, Check_Parents => False))))));
14296 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
14299 -- Created_Task parameter. This is the _Task_Id field of the task
14303 Make_Selected_Component (Loc,
14304 Prefix => Make_Identifier (Loc, Name_uInit),
14305 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
14311 if Restricted_Profile then
14312 if Partition_Elaboration_Policy = 'S' then
14313 Create_RE := RE_Create_Restricted_Task_Sequential;
14315 Create_RE := RE_Create_Restricted_Task;
14318 Create_RE := RE_Create_Task;
14321 Name := New_Occurrence_Of (RTE (Create_RE), Loc);
14325 Make_Procedure_Call_Statement (Loc,
14327 Parameter_Associations => Args);
14328 end Make_Task_Create_Call;
14330 ------------------------------
14331 -- Next_Protected_Operation --
14332 ------------------------------
14334 function Next_Protected_Operation (N : Node_Id) return Node_Id is
14338 -- Check whether there is a subsequent body for a protected operation
14339 -- in the current protected body. In Ada2012 that includes expression
14340 -- functions that are completions.
14342 Next_Op := Next (N);
14343 while Present (Next_Op)
14344 and then not Nkind_In (Next_Op,
14345 N_Subprogram_Body, N_Entry_Body, N_Expression_Function)
14351 end Next_Protected_Operation;
14353 ---------------------
14354 -- Null_Statements --
14355 ---------------------
14357 function Null_Statements (Stats : List_Id) return Boolean is
14361 Stmt := First (Stats);
14362 while Nkind (Stmt) /= N_Empty
14363 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
14365 (Nkind (Stmt) = N_Pragma
14367 Nam_In (Pragma_Name (Stmt), Name_Unreferenced,
14374 return Nkind (Stmt) = N_Empty;
14375 end Null_Statements;
14377 --------------------------
14378 -- Parameter_Block_Pack --
14379 --------------------------
14381 function Parameter_Block_Pack
14383 Blk_Typ : Entity_Id;
14387 Stmts : List_Id) return Node_Id
14389 Actual : Entity_Id;
14390 Expr : Node_Id := Empty;
14391 Formal : Entity_Id;
14392 Has_Param : Boolean := False;
14395 Temp_Asn : Node_Id;
14396 Temp_Nam : Node_Id;
14399 Actual := First (Actuals);
14400 Formal := Defining_Identifier (First (Formals));
14401 Params := New_List;
14402 while Present (Actual) loop
14403 if Is_By_Copy_Type (Etype (Actual)) then
14405 -- Jnn : aliased <formal-type>
14407 Temp_Nam := Make_Temporary (Loc, 'J');
14410 Make_Object_Declaration (Loc,
14411 Aliased_Present => True,
14412 Defining_Identifier => Temp_Nam,
14413 Object_Definition =>
14414 New_Occurrence_Of (Etype (Formal), Loc)));
14416 if Ekind (Formal) /= E_Out_Parameter then
14422 New_Occurrence_Of (Temp_Nam, Loc);
14424 Set_Assignment_OK (Temp_Asn);
14427 Make_Assignment_Statement (Loc,
14429 Expression => New_Copy_Tree (Actual)));
14433 -- Jnn'unchecked_access
14436 Make_Attribute_Reference (Loc,
14437 Attribute_Name => Name_Unchecked_Access,
14438 Prefix => New_Occurrence_Of (Temp_Nam, Loc)));
14442 -- The controlling parameter is omitted
14445 if not Is_Controlling_Actual (Actual) then
14447 Make_Reference (Loc, New_Copy_Tree (Actual)));
14453 Next_Actual (Actual);
14454 Next_Formal_With_Extras (Formal);
14458 Expr := Make_Aggregate (Loc, Params);
14463 -- J1'unchecked_access;
14464 -- <actual2>'reference;
14467 P := Make_Temporary (Loc, 'P');
14470 Make_Object_Declaration (Loc,
14471 Defining_Identifier => P,
14472 Object_Definition => New_Occurrence_Of (Blk_Typ, Loc),
14473 Expression => Expr));
14476 end Parameter_Block_Pack;
14478 ----------------------------
14479 -- Parameter_Block_Unpack --
14480 ----------------------------
14482 function Parameter_Block_Unpack
14486 Formals : List_Id) return List_Id
14488 Actual : Entity_Id;
14490 Formal : Entity_Id;
14491 Has_Asnmt : Boolean := False;
14492 Result : constant List_Id := New_List;
14495 Actual := First (Actuals);
14496 Formal := Defining_Identifier (First (Formals));
14497 while Present (Actual) loop
14498 if Is_By_Copy_Type (Etype (Actual))
14499 and then Ekind (Formal) /= E_In_Parameter
14502 -- <actual> := P.<formal>;
14505 Make_Assignment_Statement (Loc,
14509 Make_Explicit_Dereference (Loc,
14510 Make_Selected_Component (Loc,
14512 New_Occurrence_Of (P, Loc),
14514 Make_Identifier (Loc, Chars (Formal)))));
14516 Set_Assignment_OK (Name (Asnmt));
14517 Append_To (Result, Asnmt);
14522 Next_Actual (Actual);
14523 Next_Formal_With_Extras (Formal);
14529 return New_List (Make_Null_Statement (Loc));
14531 end Parameter_Block_Unpack;
14533 ----------------------
14534 -- Set_Discriminals --
14535 ----------------------
14537 procedure Set_Discriminals (Dec : Node_Id) is
14540 D_Minal : Entity_Id;
14543 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
14544 Pdef := Defining_Identifier (Dec);
14546 if Has_Discriminants (Pdef) then
14547 D := First_Discriminant (Pdef);
14548 while Present (D) loop
14550 Make_Defining_Identifier (Sloc (D),
14551 Chars => New_External_Name (Chars (D), 'D'));
14553 Set_Ekind (D_Minal, E_Constant);
14554 Set_Etype (D_Minal, Etype (D));
14555 Set_Scope (D_Minal, Pdef);
14556 Set_Discriminal (D, D_Minal);
14557 Set_Discriminal_Link (D_Minal, D);
14559 Next_Discriminant (D);
14562 end Set_Discriminals;
14564 -----------------------
14565 -- Trivial_Accept_OK --
14566 -----------------------
14568 function Trivial_Accept_OK return Boolean is
14570 case Opt.Task_Dispatching_Policy is
14572 -- If we have the default task dispatching policy in effect, we can
14573 -- definitely do the optimization (one way of looking at this is to
14574 -- think of the formal definition of the default policy being allowed
14575 -- to run any task it likes after a rendezvous, so even if notionally
14576 -- a full rescheduling occurs, we can say that our dispatching policy
14577 -- (i.e. the default dispatching policy) reorders the queue to be the
14578 -- same as just before the call.
14583 -- FIFO_Within_Priorities certainly does not permit this
14584 -- optimization since the Rendezvous is a scheduling action that may
14585 -- require some other task to be run.
14590 -- For now, disallow the optimization for all other policies. This
14591 -- may be over-conservative, but it is certainly not incorrect.
14597 end Trivial_Accept_OK;