1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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)));
582 Actual_Family_Offset (
583 Make_Attribute_Reference (Sloc,
584 Attribute_Name => Name_Pos,
585 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
586 Expressions => New_List (Relocate_Node (Index))),
587 Type_Low_Bound (S)));
592 -- Now add lengths of preceding entries and entry families
594 Prev := First_Entity (Ttyp);
595 while Chars (Prev) /= Chars (Ent)
596 or else (Ekind (Prev) /= Ekind (Ent))
597 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
599 if Ekind (Prev) = E_Entry then
600 Set_Intval (Num, Intval (Num) + 1);
602 elsif Ekind (Prev) = E_Entry_Family then
604 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
606 -- The need for the following full view retrieval stems from this
607 -- complex case of nested generics and tasking:
610 -- type Formal_Index is range <>;
613 -- type Index is private;
620 -- type Index is new Formal_Index range 1 .. 10;
623 -- package body Outer is
625 -- entry Fam (Index); -- (2)
628 -- package body Inner is -- (3)
636 -- We are currently building the index expression for the entry
637 -- call "T.E" (1). Part of the expansion must mention the range
638 -- of the discrete type "Index" (2) of entry family "Fam".
640 -- However only the private view of type "Index" is available to
641 -- the inner generic (3) because there was no prior mention of
642 -- the type inside "Inner". This visibility requirement is
643 -- implicit and cannot be detected during the construction of
644 -- the generic trees and needs special handling.
647 and then Is_Private_Type (S)
648 and then Present (Full_View (S))
653 Lo := Type_Low_Bound (S);
654 Hi := Type_High_Bound (S);
662 Actual_Family_Offset (Hi, Lo),
664 Make_Integer_Literal (Sloc, 1)));
666 -- Other components are anonymous types to be ignored
676 end Actual_Index_Expression;
678 --------------------------
679 -- Add_Formal_Renamings --
680 --------------------------
682 procedure Add_Formal_Renamings
688 Ptr : constant Entity_Id :=
690 (Next (First (Parameter_Specifications (Spec))));
691 -- The name of the formal that holds the address of the parameter block
698 Renamed_Formal : Node_Id;
701 Formal := First_Formal (Ent);
702 while Present (Formal) loop
703 Comp := Entry_Component (Formal);
705 Make_Defining_Identifier (Sloc (Formal),
706 Chars => Chars (Formal));
707 Set_Etype (New_F, Etype (Formal));
708 Set_Scope (New_F, Ent);
710 -- Now we set debug info needed on New_F even though it does not come
711 -- from source, so that the debugger will get the right information
712 -- for these generated names.
714 Set_Debug_Info_Needed (New_F);
716 if Ekind (Formal) = E_In_Parameter then
717 Set_Ekind (New_F, E_Constant);
719 Set_Ekind (New_F, E_Variable);
720 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
723 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
726 Make_Selected_Component (Loc,
728 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
729 Make_Identifier (Loc, Chars (Ptr))),
730 Selector_Name => New_Occurrence_Of (Comp, Loc));
733 Build_Renamed_Formal_Declaration
734 (New_F, Formal, Comp, Renamed_Formal);
736 Append (Decl, Decls);
737 Set_Renamed_Object (Formal, New_F);
738 Next_Formal (Formal);
740 end Add_Formal_Renamings;
742 ------------------------
743 -- Add_Object_Pointer --
744 ------------------------
746 procedure Add_Object_Pointer
748 Conc_Typ : Entity_Id;
751 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
756 -- Create the renaming declaration for the Protection object of a
757 -- protected type. _Object is used by Complete_Entry_Body.
758 -- ??? An attempt to make this a renaming was unsuccessful.
760 -- Build the entity for the access type
763 Make_Defining_Identifier (Loc,
764 New_External_Name (Chars (Rec_Typ), 'P'));
767 -- _object : poVP := poVP!O;
770 Make_Object_Declaration (Loc,
771 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject),
772 Object_Definition => New_Occurrence_Of (Obj_Ptr, Loc),
774 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
775 Set_Debug_Info_Needed (Defining_Identifier (Decl));
776 Prepend_To (Decls, Decl);
779 -- type poVP is access poV;
782 Make_Full_Type_Declaration (Loc,
783 Defining_Identifier =>
786 Make_Access_To_Object_Definition (Loc,
787 Subtype_Indication =>
788 New_Occurrence_Of (Rec_Typ, Loc)));
789 Set_Debug_Info_Needed (Defining_Identifier (Decl));
790 Prepend_To (Decls, Decl);
791 end Add_Object_Pointer;
793 -----------------------
794 -- Build_Accept_Body --
795 -----------------------
797 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
798 Loc : constant Source_Ptr := Sloc (Astat);
799 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
806 -- At the end of the statement sequence, Complete_Rendezvous is called.
807 -- A label skipping the Complete_Rendezvous, and all other accept
808 -- processing, has already been added for the expansion of requeue
809 -- statements. The Sloc is copied from the last statement since it
810 -- is really part of this last statement.
814 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
815 Insert_Before (Last (Statements (Stats)), Call);
818 -- If exception handlers are present, then append Complete_Rendezvous
819 -- calls to the handlers, and construct the required outer block. As
820 -- above, the Sloc is copied from the last statement in the sequence.
822 if Present (Exception_Handlers (Stats)) then
823 Hand := First (Exception_Handlers (Stats));
824 while Present (Hand) loop
827 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
828 Append (Call, Statements (Hand));
834 Make_Handled_Sequence_Of_Statements (Loc,
835 Statements => New_List (
836 Make_Block_Statement (Loc,
837 Handled_Statement_Sequence => Stats)));
843 -- At this stage we know that the new statement sequence does
844 -- not have an exception handler part, so we supply one to call
845 -- Exceptional_Complete_Rendezvous. This handler is
847 -- when all others =>
848 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
850 -- We handle Abort_Signal to make sure that we properly catch the abort
851 -- case and wake up the caller.
853 Ohandle := Make_Others_Choice (Loc);
854 Set_All_Others (Ohandle);
856 Set_Exception_Handlers (New_S,
858 Make_Implicit_Exception_Handler (Loc,
859 Exception_Choices => New_List (Ohandle),
861 Statements => New_List (
862 Make_Procedure_Call_Statement (Sloc (Stats),
863 Name => New_Occurrence_Of (
864 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
865 Parameter_Associations => New_List (
866 Make_Function_Call (Sloc (Stats),
869 (RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
871 Set_Parent (New_S, Astat); -- temp parent for Analyze call
872 Analyze_Exception_Handlers (Exception_Handlers (New_S));
873 Expand_Exception_Handlers (New_S);
875 -- Exceptional_Complete_Rendezvous must be called with abort still
876 -- deferred, which is the case for a "when all others" handler.
879 end Build_Accept_Body;
881 -----------------------------------
882 -- Build_Activation_Chain_Entity --
883 -----------------------------------
885 procedure Build_Activation_Chain_Entity (N : Node_Id) is
886 function Has_Activation_Chain (Stmt : Node_Id) return Boolean;
887 -- Determine whether an extended return statement has activation chain
889 --------------------------
890 -- Has_Activation_Chain --
891 --------------------------
893 function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
897 Decl := First (Return_Object_Declarations (Stmt));
898 while Present (Decl) loop
899 if Nkind (Decl) = N_Object_Declaration
900 and then Chars (Defining_Identifier (Decl)) = Name_uChain
909 end Has_Activation_Chain;
914 Context_Id : Entity_Id;
917 -- Start of processing for Build_Activation_Chain_Entity
920 -- Activation chain is never used for sequential elaboration policy, see
921 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
923 if Partition_Elaboration_Policy = 'S' then
927 Find_Enclosing_Context (N, Context, Context_Id, Decls);
929 -- If activation chain entity has not been declared already, create one
931 if Nkind (Context) = N_Extended_Return_Statement
932 or else No (Activation_Chain_Entity (Context))
934 -- Since extended return statements do not store the entity of the
935 -- chain, examine the return object declarations to avoid creating
938 if Nkind (Context) = N_Extended_Return_Statement
939 and then Has_Activation_Chain (Context)
945 Loc : constant Source_Ptr := Sloc (Context);
950 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
952 -- Note: An extended return statement is not really a task
953 -- activator, but it does have an activation chain on which to
954 -- store the tasks temporarily. On successful return, the tasks
955 -- on this chain are moved to the chain passed in by the caller.
956 -- We do not build an Activation_Chain_Entity for an extended
957 -- return statement, because we do not want to build a call to
958 -- Activate_Tasks. Task activation is the responsibility of the
961 if Nkind (Context) /= N_Extended_Return_Statement then
962 Set_Activation_Chain_Entity (Context, Chain);
966 Make_Object_Declaration (Loc,
967 Defining_Identifier => Chain,
968 Aliased_Present => True,
970 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc));
972 Prepend_To (Decls, Decl);
974 -- Ensure that _chain appears in the proper scope of the context
976 if Context_Id /= Current_Scope then
977 Push_Scope (Context_Id);
985 end Build_Activation_Chain_Entity;
987 ----------------------------
988 -- Build_Barrier_Function --
989 ----------------------------
991 function Build_Barrier_Function
994 Pid : Node_Id) return Node_Id
996 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
997 Cond : constant Node_Id := Condition (Ent_Formals);
998 Loc : constant Source_Ptr := Sloc (Cond);
999 Func_Id : constant Entity_Id := Barrier_Function (Ent);
1000 Op_Decls : constant List_Id := New_List;
1002 Func_Body : Node_Id;
1005 -- Add a declaration for the Protection object, renaming declarations
1006 -- for the discriminals and privals and finally a declaration for the
1007 -- entry family index (if applicable).
1009 Install_Private_Data_Declarations (Sloc (N),
1015 Family => Ekind (Ent) = E_Entry_Family);
1017 -- If compiling with -fpreserve-control-flow, make sure we insert an
1018 -- IF statement so that the back-end knows to generate a conditional
1019 -- branch instruction, even if the condition is just the name of a
1020 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1021 -- such redundant IF statements under -fpreserve-control-flow
1022 -- (whether coming from this routine, or directly from source).
1024 if Opt.Suppress_Control_Flow_Optimizations then
1025 Stmt := Make_Implicit_If_Statement (Cond,
1027 Then_Statements => New_List (
1028 Make_Simple_Return_Statement (Loc,
1029 New_Occurrence_Of (Standard_True, Loc))),
1030 Else_Statements => New_List (
1031 Make_Simple_Return_Statement (Loc,
1032 New_Occurrence_Of (Standard_False, Loc))));
1035 Stmt := Make_Simple_Return_Statement (Loc, Cond);
1038 -- Note: the condition in the barrier function needs to be properly
1039 -- processed for the C/Fortran boolean possibility, but this happens
1040 -- automatically since the return statement does this normalization.
1043 Make_Subprogram_Body (Loc,
1045 Build_Barrier_Function_Specification (Loc,
1046 Make_Defining_Identifier (Loc, Chars (Func_Id))),
1047 Declarations => Op_Decls,
1048 Handled_Statement_Sequence =>
1049 Make_Handled_Sequence_Of_Statements (Loc,
1050 Statements => New_List (Stmt)));
1051 Set_Is_Entry_Barrier_Function (Func_Body);
1054 end Build_Barrier_Function;
1056 ------------------------------------------
1057 -- Build_Barrier_Function_Specification --
1058 ------------------------------------------
1060 function Build_Barrier_Function_Specification
1062 Def_Id : Entity_Id) return Node_Id
1065 Set_Debug_Info_Needed (Def_Id);
1067 return 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 => New_Occurrence_Of (Standard_Boolean, Loc));
1083 end Build_Barrier_Function_Specification;
1085 --------------------------
1086 -- Build_Call_With_Task --
1087 --------------------------
1089 function Build_Call_With_Task
1091 E : Entity_Id) return Node_Id
1093 Loc : constant Source_Ptr := Sloc (N);
1096 Make_Function_Call (Loc,
1097 Name => New_Occurrence_Of (E, Loc),
1098 Parameter_Associations => New_List (Concurrent_Ref (N)));
1099 end Build_Call_With_Task;
1101 -----------------------------
1102 -- Build_Class_Wide_Master --
1103 -----------------------------
1105 procedure Build_Class_Wide_Master (Typ : Entity_Id) is
1106 Loc : constant Source_Ptr := Sloc (Typ);
1107 Master_Id : Entity_Id;
1108 Master_Scope : Entity_Id;
1110 Related_Node : Node_Id;
1114 -- Nothing to do if there is no task hierarchy
1116 if Restriction_Active (No_Task_Hierarchy) then
1120 -- Find the declaration that created the access type, which is either a
1121 -- type declaration, or an object declaration with an access definition,
1122 -- in which case the type is anonymous.
1124 if Is_Itype (Typ) then
1125 Related_Node := Associated_Node_For_Itype (Typ);
1127 Related_Node := Parent (Typ);
1130 Master_Scope := Find_Master_Scope (Typ);
1132 -- Nothing to do if the master scope already contains a _master entity.
1133 -- The only exception to this is the following scenario:
1136 -- Transient_Scope_1
1139 -- Transient_Scope_2
1142 -- In this case the source scope is marked as having the master entity
1143 -- even though the actual declaration appears inside an inner scope. If
1144 -- the second transient scope requires a _master, it cannot use the one
1145 -- already declared because the entity is not visible.
1147 Name_Id := Make_Identifier (Loc, Name_uMaster);
1149 if not Has_Master_Entity (Master_Scope)
1150 or else No (Current_Entity_In_Scope (Name_Id))
1153 Master_Decl : Node_Id;
1155 Set_Has_Master_Entity (Master_Scope);
1158 -- _master : constant Integer := Current_Master.all;
1161 Make_Object_Declaration (Loc,
1162 Defining_Identifier =>
1163 Make_Defining_Identifier (Loc, Name_uMaster),
1164 Constant_Present => True,
1165 Object_Definition =>
1166 New_Occurrence_Of (Standard_Integer, Loc),
1168 Make_Explicit_Dereference (Loc,
1169 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
1171 Insert_Action (Find_Hook_Context (Related_Node), Master_Decl);
1172 Analyze (Master_Decl);
1174 -- Mark the containing scope as a task master. Masters associated
1175 -- with return statements are already marked at this stage (see
1176 -- Analyze_Subprogram_Body).
1178 if Ekind (Current_Scope) /= E_Return_Statement then
1180 Par : Node_Id := Related_Node;
1183 while Nkind (Par) /= N_Compilation_Unit loop
1184 Par := Parent (Par);
1186 -- If we fall off the top, we are at the outer level,
1187 -- and the environment task is our effective master,
1188 -- so nothing to mark.
1190 if Nkind_In (Par, N_Block_Statement,
1194 Set_Is_Task_Master (Par);
1204 Make_Defining_Identifier (Loc, New_External_Name (Chars (Typ), 'M'));
1207 -- typeMnn renames _master;
1210 Make_Object_Renaming_Declaration (Loc,
1211 Defining_Identifier => Master_Id,
1212 Subtype_Mark => New_Occurrence_Of (Standard_Integer, Loc),
1215 Insert_Action (Related_Node, Ren_Decl);
1217 Set_Master_Id (Typ, Master_Id);
1218 end Build_Class_Wide_Master;
1220 --------------------------------
1221 -- Build_Corresponding_Record --
1222 --------------------------------
1224 function Build_Corresponding_Record
1227 Loc : Source_Ptr) return Node_Id
1229 Rec_Ent : constant Entity_Id :=
1230 Make_Defining_Identifier
1231 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1234 New_Disc : Entity_Id;
1238 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1239 Set_Ekind (Rec_Ent, E_Record_Type);
1240 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1241 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1242 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1243 Set_Stored_Constraint (Rec_Ent, No_Elist);
1246 -- Use discriminals to create list of discriminants for record, and
1247 -- create new discriminals for use in default expressions, etc. It is
1248 -- worth noting that a task discriminant gives rise to 5 entities;
1250 -- a) The original discriminant.
1251 -- b) The discriminal for use in the task.
1252 -- c) The discriminant of the corresponding record.
1253 -- d) The discriminal for the init proc of the corresponding record.
1254 -- e) The local variable that renames the discriminant in the procedure
1255 -- for the task body.
1257 -- In fact the discriminals b) are used in the renaming declarations
1258 -- for e). See details in einfo (Handling of Discriminants).
1260 if Present (Discriminant_Specifications (N)) then
1262 Disc := First_Discriminant (Ctyp);
1264 while Present (Disc) loop
1265 New_Disc := CR_Discriminant (Disc);
1268 Make_Discriminant_Specification (Loc,
1269 Defining_Identifier => New_Disc,
1270 Discriminant_Type =>
1271 New_Occurrence_Of (Etype (Disc), Loc),
1273 New_Copy (Discriminant_Default_Value (Disc))));
1275 Next_Discriminant (Disc);
1282 -- Now we can construct the record type declaration. Note that this
1283 -- record is "limited tagged". It is "limited" to reflect the underlying
1284 -- limitedness of the task or protected object that it represents, and
1285 -- ensuring for example that it is properly passed by reference. It is
1286 -- "tagged" to give support to dispatching calls through interfaces. We
1287 -- propagate here the list of interfaces covered by the concurrent type
1288 -- (Ada 2005: AI-345).
1291 Make_Full_Type_Declaration (Loc,
1292 Defining_Identifier => Rec_Ent,
1293 Discriminant_Specifications => Dlist,
1295 Make_Record_Definition (Loc,
1297 Make_Component_List (Loc,
1298 Component_Items => Cdecls),
1300 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1301 Interface_List => Interface_List (N),
1302 Limited_Present => True));
1303 end Build_Corresponding_Record;
1305 ---------------------------------
1306 -- Build_Dispatching_Tag_Check --
1307 ---------------------------------
1309 function Build_Dispatching_Tag_Check
1311 N : Node_Id) return Node_Id
1313 Loc : constant Source_Ptr := Sloc (N);
1320 New_Occurrence_Of (K, Loc),
1322 New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc)),
1326 New_Occurrence_Of (K, Loc),
1328 New_Occurrence_Of (RTE (RE_TK_Tagged), Loc)));
1329 end Build_Dispatching_Tag_Check;
1331 ----------------------------------
1332 -- Build_Entry_Count_Expression --
1333 ----------------------------------
1335 function Build_Entry_Count_Expression
1336 (Concurrent_Type : Node_Id;
1337 Component_List : List_Id;
1338 Loc : Source_Ptr) return Node_Id
1350 -- Count number of non-family entries
1353 Ent := First_Entity (Concurrent_Type);
1354 while Present (Ent) loop
1355 if Ekind (Ent) = E_Entry then
1362 Ecount := Make_Integer_Literal (Loc, Eindx);
1364 -- Loop through entry families building the addition nodes
1366 Ent := First_Entity (Concurrent_Type);
1367 Comp := First (Component_List);
1368 while Present (Ent) loop
1369 if Ekind (Ent) = E_Entry_Family then
1370 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1374 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1375 Hi := Type_High_Bound (Typ);
1376 Lo := Type_Low_Bound (Typ);
1377 Large := Is_Potentially_Large_Family
1378 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1381 Left_Opnd => Ecount,
1382 Right_Opnd => Family_Size
1383 (Loc, Hi, Lo, Concurrent_Type, Large));
1390 end Build_Entry_Count_Expression;
1392 -----------------------
1393 -- Build_Entry_Names --
1394 -----------------------
1396 procedure Build_Entry_Names
1398 Obj_Typ : Entity_Id;
1401 Loc : constant Source_Ptr := Sloc (Obj_Ref);
1402 Data : Entity_Id := Empty;
1403 Index : Entity_Id := Empty;
1404 Typ : Entity_Id := Obj_Typ;
1406 procedure Build_Entry_Name (Comp_Id : Entity_Id);
1407 -- Given an entry [family], create a static string which denotes the
1408 -- name of Comp_Id and assign it to the underlying data structure which
1409 -- contains the entry names of a concurrent object.
1411 function Object_Reference return Node_Id;
1412 -- Return a reference to field _object or _task_id depending on the
1413 -- concurrent object being processed.
1415 ----------------------
1416 -- Build_Entry_Name --
1417 ----------------------
1419 procedure Build_Entry_Name (Comp_Id : Entity_Id) is
1420 function Build_Range (Def : Node_Id) return Node_Id;
1421 -- Given a discrete subtype definition of an entry family, generate a
1422 -- range node which covers the range of Def's type.
1424 procedure Create_Index_And_Data;
1425 -- Generate the declarations of variables Index and Data. Subsequent
1426 -- calls do nothing.
1428 function Increment_Index return Node_Id;
1429 -- Increment the index used in the assignment of string names to the
1432 function Name_Declaration (Def_Id : Entity_Id) return Node_Id;
1433 -- Given the name of a temporary variable, create the following
1434 -- declaration for it:
1436 -- Def_Id : aliased constant String := <String_Name_From_Buffer>;
1438 function Set_Entry_Name (Def_Id : Entity_Id) return Node_Id;
1439 -- Given the name of a temporary variable, place it in the array of
1440 -- string names. Generate:
1442 -- Data (Index) := Def_Id'Unchecked_Access;
1448 function Build_Range (Def : Node_Id) return Node_Id is
1449 High : Node_Id := Type_High_Bound (Etype (Def));
1450 Low : Node_Id := Type_Low_Bound (Etype (Def));
1453 -- If a bound references a discriminant, generate an identifier
1454 -- with the same name. Resolution will map it to the formals of
1457 if Is_Entity_Name (Low)
1458 and then Ekind (Entity (Low)) = E_Discriminant
1461 Make_Selected_Component (Loc,
1462 Prefix => New_Copy_Tree (Obj_Ref),
1463 Selector_Name => Make_Identifier (Loc, Chars (Low)));
1465 Low := New_Copy_Tree (Low);
1468 if Is_Entity_Name (High)
1469 and then Ekind (Entity (High)) = E_Discriminant
1472 Make_Selected_Component (Loc,
1473 Prefix => New_Copy_Tree (Obj_Ref),
1474 Selector_Name => Make_Identifier (Loc, Chars (High)));
1476 High := New_Copy_Tree (High);
1482 High_Bound => High);
1485 ---------------------------
1486 -- Create_Index_And_Data --
1487 ---------------------------
1489 procedure Create_Index_And_Data is
1491 if No (Index) and then No (Data) then
1498 if Is_Protected_Type (Typ) then
1499 Count := RO_PE_Number_Of_Entries;
1500 Data_Typ := RE_Protected_Entry_Names_Array;
1502 Count := RO_ST_Number_Of_Entries;
1503 Data_Typ := RE_Task_Entry_Names_Array;
1506 -- Step 1: Generate the declaration of the index variable:
1508 -- Index : Entry_Index := 1;
1510 Index := Make_Temporary (Loc, 'I');
1513 Make_Object_Declaration (Loc,
1514 Defining_Identifier => Index,
1515 Object_Definition =>
1516 New_Occurrence_Of (RTE (RE_Entry_Index), Loc),
1517 Expression => Make_Integer_Literal (Loc, 1)));
1519 -- Step 2: Generate the declaration of an array to house all
1522 -- Size : constant Entry_Index := <Count> (Obj_Ref);
1523 -- Data : aliased <Data_Typ> := (1 .. Size => null);
1525 Size := Make_Temporary (Loc, 'S');
1528 Make_Object_Declaration (Loc,
1529 Defining_Identifier => Size,
1530 Constant_Present => True,
1531 Object_Definition =>
1532 New_Occurrence_Of (RTE (RE_Entry_Index), Loc),
1534 Make_Function_Call (Loc,
1536 New_Occurrence_Of (RTE (Count), Loc),
1537 Parameter_Associations =>
1538 New_List (Object_Reference))));
1540 Data := Make_Temporary (Loc, 'A');
1543 Make_Object_Declaration (Loc,
1544 Defining_Identifier => Data,
1545 Aliased_Present => True,
1546 Object_Definition =>
1547 New_Occurrence_Of (RTE (Data_Typ), Loc),
1549 Make_Aggregate (Loc,
1550 Component_Associations => New_List (
1551 Make_Component_Association (Loc,
1552 Choices => New_List (
1555 Make_Integer_Literal (Loc, 1),
1557 New_Occurrence_Of (Size, Loc))),
1558 Expression => Make_Null (Loc))))));
1561 end Create_Index_And_Data;
1563 ---------------------
1564 -- Increment_Index --
1565 ---------------------
1567 function Increment_Index return Node_Id is
1570 Make_Assignment_Statement (Loc,
1571 Name => New_Occurrence_Of (Index, Loc),
1574 Left_Opnd => New_Occurrence_Of (Index, Loc),
1575 Right_Opnd => Make_Integer_Literal (Loc, 1)));
1576 end Increment_Index;
1578 ----------------------
1579 -- Name_Declaration --
1580 ----------------------
1582 function Name_Declaration (Def_Id : Entity_Id) return Node_Id is
1585 Make_Object_Declaration (Loc,
1586 Defining_Identifier => Def_Id,
1587 Aliased_Present => True,
1588 Constant_Present => True,
1589 Object_Definition =>
1590 New_Occurrence_Of (Standard_String, Loc),
1592 Make_String_Literal (Loc, String_From_Name_Buffer));
1593 end Name_Declaration;
1595 --------------------
1596 -- Set_Entry_Name --
1597 --------------------
1599 function Set_Entry_Name (Def_Id : Entity_Id) return Node_Id is
1602 Make_Assignment_Statement (Loc,
1604 Make_Indexed_Component (Loc,
1605 Prefix => New_Occurrence_Of (Data, Loc),
1606 Expressions => New_List (New_Occurrence_Of (Index, Loc))),
1609 Make_Attribute_Reference (Loc,
1610 Prefix => New_Occurrence_Of (Def_Id, Loc),
1611 Attribute_Name => Name_Unchecked_Access));
1616 Temp_Id : Entity_Id;
1619 -- Start of processing for Build_Entry_Name
1622 if Ekind (Comp_Id) = E_Entry_Family then
1623 Subt_Def := Discrete_Subtype_Definition (Parent (Comp_Id));
1625 Create_Index_And_Data;
1627 -- Step 1: Create the string name of the entry family.
1629 -- Temp : aliased constant String := "name ()";
1631 Temp_Id := Make_Temporary (Loc, 'S');
1632 Get_Name_String (Chars (Comp_Id));
1633 Add_Char_To_Name_Buffer (' ');
1634 Add_Char_To_Name_Buffer ('(');
1635 Add_Char_To_Name_Buffer (')');
1637 Append_To (Stmts, Name_Declaration (Temp_Id));
1640 -- for Member in Family_Low .. Family_High loop
1641 -- Set_Entry_Name (...);
1642 -- Index := Index + 1;
1646 Make_Loop_Statement (Loc,
1648 Make_Iteration_Scheme (Loc,
1649 Loop_Parameter_Specification =>
1650 Make_Loop_Parameter_Specification (Loc,
1651 Defining_Identifier =>
1652 Make_Temporary (Loc, 'L'),
1653 Discrete_Subtype_Definition =>
1654 Build_Range (Subt_Def))),
1656 Statements => New_List (
1657 Set_Entry_Name (Temp_Id),
1659 End_Label => Empty));
1664 Create_Index_And_Data;
1666 -- Step 1: Create the string name of the entry. Generate:
1667 -- Temp : aliased constant String := "name";
1669 Temp_Id := Make_Temporary (Loc, 'S');
1670 Get_Name_String (Chars (Comp_Id));
1672 Append_To (Stmts, Name_Declaration (Temp_Id));
1674 -- Step 2: Associate the string name with the underlying data
1677 Append_To (Stmts, Set_Entry_Name (Temp_Id));
1678 Append_To (Stmts, Increment_Index);
1680 end Build_Entry_Name;
1682 ----------------------
1683 -- Object_Reference --
1684 ----------------------
1686 function Object_Reference return Node_Id is
1687 Conc_Typ : constant Entity_Id := Corresponding_Record_Type (Typ);
1692 if Is_Protected_Type (Typ) then
1693 Field := Name_uObject;
1695 Field := Name_uTask_Id;
1699 Make_Selected_Component (Loc,
1701 Unchecked_Convert_To (Conc_Typ, New_Copy_Tree (Obj_Ref)),
1702 Selector_Name => Make_Identifier (Loc, Field));
1704 if Is_Protected_Type (Typ) then
1706 Make_Attribute_Reference (Loc,
1708 Attribute_Name => Name_Unchecked_Access);
1712 end Object_Reference;
1719 -- Start of processing for Build_Entry_Names
1722 -- Retrieve the original concurrent type
1724 if Is_Concurrent_Record_Type (Typ) then
1725 Typ := Corresponding_Concurrent_Type (Typ);
1728 pragma Assert (Is_Concurrent_Type (Typ));
1730 -- Nothing to do if the type has no entries
1732 if not Has_Entries (Typ) then
1736 -- Avoid generating entry names for a protected type with only one entry
1738 if Is_Protected_Type (Typ)
1739 and then Find_Protection_Type (Base_Type (Typ)) /=
1740 RTE (RE_Protection_Entries)
1745 -- Step 1: Populate the array with statically generated strings denoting
1746 -- entries and entry family names.
1748 Comp := First_Entity (Typ);
1749 while Present (Comp) loop
1750 if Comes_From_Source (Comp)
1751 and then Ekind_In (Comp, E_Entry, E_Entry_Family)
1753 Build_Entry_Name (Comp);
1759 -- Step 2: Associate the array with the related concurrent object:
1761 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1763 if Present (Data) then
1764 if Is_Protected_Type (Typ) then
1765 Proc := RO_PE_Set_Entry_Names;
1767 Proc := RO_ST_Set_Entry_Names;
1771 Make_Procedure_Call_Statement (Loc,
1772 Name => New_Occurrence_Of (RTE (Proc), Loc),
1773 Parameter_Associations => New_List (
1775 Make_Attribute_Reference (Loc,
1776 Prefix => New_Occurrence_Of (Data, Loc),
1777 Attribute_Name => Name_Unchecked_Access))));
1779 end Build_Entry_Names;
1781 ---------------------------
1782 -- Build_Parameter_Block --
1783 ---------------------------
1785 function Build_Parameter_Block
1789 Decls : List_Id) return Entity_Id
1795 Has_Comp : Boolean := False;
1799 Actual := First (Actuals);
1801 Formal := Defining_Identifier (First (Formals));
1803 while Present (Actual) loop
1804 if not Is_Controlling_Actual (Actual) then
1807 -- type Ann is access all <actual-type>
1809 Comp_Nam := Make_Temporary (Loc, 'A');
1812 Make_Full_Type_Declaration (Loc,
1813 Defining_Identifier => Comp_Nam,
1815 Make_Access_To_Object_Definition (Loc,
1816 All_Present => True,
1817 Constant_Present => Ekind (Formal) = E_In_Parameter,
1818 Subtype_Indication =>
1819 New_Occurrence_Of (Etype (Actual), Loc))));
1825 Make_Component_Declaration (Loc,
1826 Defining_Identifier =>
1827 Make_Defining_Identifier (Loc, Chars (Formal)),
1828 Component_Definition =>
1829 Make_Component_Definition (Loc,
1832 Subtype_Indication =>
1833 New_Occurrence_Of (Comp_Nam, Loc))));
1838 Next_Actual (Actual);
1839 Next_Formal_With_Extras (Formal);
1842 Rec_Nam := Make_Temporary (Loc, 'P');
1847 -- type Pnn is record
1852 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1853 -- the original parameter names and Ann1 .. AnnN are the access to
1857 Make_Full_Type_Declaration (Loc,
1858 Defining_Identifier =>
1861 Make_Record_Definition (Loc,
1863 Make_Component_List (Loc, Comps))));
1866 -- type Pnn is null record;
1869 Make_Full_Type_Declaration (Loc,
1870 Defining_Identifier =>
1873 Make_Record_Definition (Loc,
1874 Null_Present => True,
1875 Component_List => Empty)));
1879 end Build_Parameter_Block;
1881 --------------------------------------
1882 -- Build_Renamed_Formal_Declaration --
1883 --------------------------------------
1885 function Build_Renamed_Formal_Declaration
1889 Renamed_Formal : Node_Id) return Node_Id
1891 Loc : constant Source_Ptr := Sloc (New_F);
1895 -- If the formal is a tagged incomplete type, it is already passed
1896 -- by reference, so it is sufficient to rename the pointer component
1897 -- that corresponds to the actual. Otherwise we need to dereference
1898 -- the pointer component to obtain the actual.
1900 if Is_Incomplete_Type (Etype (Formal))
1901 and then Is_Tagged_Type (Etype (Formal))
1904 Make_Object_Renaming_Declaration (Loc,
1905 Defining_Identifier => New_F,
1906 Subtype_Mark => New_Occurrence_Of (Etype (Comp), Loc),
1907 Name => Renamed_Formal);
1911 Make_Object_Renaming_Declaration (Loc,
1912 Defining_Identifier => New_F,
1913 Subtype_Mark => New_Occurrence_Of (Etype (Formal), Loc),
1915 Make_Explicit_Dereference (Loc, Renamed_Formal));
1919 end Build_Renamed_Formal_Declaration;
1921 -----------------------
1922 -- Build_PPC_Wrapper --
1923 -----------------------
1925 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1926 Loc : constant Source_Ptr := Sloc (E);
1927 Synch_Type : constant Entity_Id := Scope (E);
1929 Wrapper_Id : constant Entity_Id :=
1930 Make_Defining_Identifier (Loc,
1931 Chars => New_External_Name (Chars (E), 'E'));
1932 -- the wrapper procedure name
1934 Wrapper_Body : Node_Id;
1936 Synch_Id : constant Entity_Id :=
1937 Make_Defining_Identifier (Loc,
1938 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1939 -- The parameter that designates the synchronized object in the call
1941 Actuals : constant List_Id := New_List;
1942 -- The actuals in the entry call
1944 Decls : constant List_Id := New_List;
1946 Entry_Call : Node_Id;
1947 Entry_Name : Node_Id;
1950 -- The specification of the wrapper procedure
1954 -- Only build the wrapper if entry has pre/postconditions.
1955 -- Should this be done unconditionally instead ???
1961 P := Pre_Post_Conditions (Contract (E));
1967 -- Transfer ppc pragmas to the declarations of the wrapper
1969 while Present (P) loop
1970 if Nam_In (Pragma_Name (P), Name_Precondition,
1973 Append (Relocate_Node (P), Decls);
1974 Set_Analyzed (Last (Decls), False);
1977 P := Next_Pragma (P);
1981 -- First formal is synchronized object
1984 Make_Parameter_Specification (Loc,
1985 Defining_Identifier => Synch_Id,
1986 Out_Present => True,
1988 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1991 Make_Selected_Component (Loc,
1992 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1993 Selector_Name => New_Occurrence_Of (E, Loc));
1995 -- If entity is entry family, second formal is the corresponding index,
1996 -- and entry name is an indexed component.
1998 if Ekind (E) = E_Entry_Family then
2000 Index : constant Entity_Id :=
2001 Make_Defining_Identifier (Loc, Name_I);
2004 Make_Parameter_Specification (Loc,
2005 Defining_Identifier => Index,
2007 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
2010 Make_Indexed_Component (Loc,
2011 Prefix => Entry_Name,
2012 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
2017 Make_Procedure_Call_Statement (Loc,
2019 Parameter_Associations => Actuals);
2021 -- Now add formals that match those of the entry, and build actuals for
2022 -- the nested entry call.
2026 New_Form : Entity_Id;
2027 Parm_Spec : Node_Id;
2030 Form := First_Formal (E);
2031 while Present (Form) loop
2032 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
2034 Make_Parameter_Specification (Loc,
2035 Defining_Identifier => New_Form,
2036 Out_Present => Out_Present (Parent (Form)),
2037 In_Present => In_Present (Parent (Form)),
2038 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
2040 Append (Parm_Spec, Specs);
2041 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
2046 -- Add renaming declarations for the discriminants of the enclosing
2047 -- type, which may be visible in the preconditions.
2049 if Has_Discriminants (Synch_Type) then
2055 D := First_Discriminant (Synch_Type);
2056 while Present (D) loop
2058 Make_Object_Renaming_Declaration (Loc,
2059 Defining_Identifier =>
2060 Make_Defining_Identifier (Loc, Chars (D)),
2061 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
2063 Make_Selected_Component (Loc,
2064 Prefix => New_Occurrence_Of (Synch_Id, Loc),
2065 Selector_Name => Make_Identifier (Loc, Chars (D))));
2066 Prepend (Decl, Decls);
2067 Next_Discriminant (D);
2072 Set_PPC_Wrapper (E, Wrapper_Id);
2074 Make_Subprogram_Body (Loc,
2076 Make_Procedure_Specification (Loc,
2077 Defining_Unit_Name => Wrapper_Id,
2078 Parameter_Specifications => Specs),
2079 Declarations => Decls,
2080 Handled_Statement_Sequence =>
2081 Make_Handled_Sequence_Of_Statements (Loc,
2082 Statements => New_List (Entry_Call)));
2084 -- The wrapper body is analyzed when the enclosing type is frozen
2086 Append_Freeze_Action (Defining_Entity (Decl), Wrapper_Body);
2087 end Build_PPC_Wrapper;
2089 --------------------------
2090 -- Build_Wrapper_Bodies --
2091 --------------------------
2093 procedure Build_Wrapper_Bodies
2098 Rec_Typ : Entity_Id;
2100 function Build_Wrapper_Body
2102 Subp_Id : Entity_Id;
2103 Obj_Typ : Entity_Id;
2104 Formals : List_Id) return Node_Id;
2105 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2106 -- associated with a protected or task type. Subp_Id is the subprogram
2107 -- name which will be wrapped. Obj_Typ is the type of the new formal
2108 -- parameter which handles dispatching and object notation. Formals are
2109 -- the original formals of Subp_Id which will be explicitly replicated.
2111 ------------------------
2112 -- Build_Wrapper_Body --
2113 ------------------------
2115 function Build_Wrapper_Body
2117 Subp_Id : Entity_Id;
2118 Obj_Typ : Entity_Id;
2119 Formals : List_Id) return Node_Id
2121 Body_Spec : Node_Id;
2124 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
2126 -- The subprogram is not overriding or is not a primitive declared
2127 -- between two views.
2129 if No (Body_Spec) then
2134 Actuals : List_Id := No_List;
2136 First_Form : Node_Id;
2141 -- Map formals to actuals. Use the list built for the wrapper
2142 -- spec, skipping the object notation parameter.
2144 First_Form := First (Parameter_Specifications (Body_Spec));
2146 Formal := First_Form;
2149 if Present (Formal) then
2150 Actuals := New_List;
2151 while Present (Formal) loop
2153 Make_Identifier (Loc,
2154 Chars => Chars (Defining_Identifier (Formal))));
2159 -- Special processing for primitives declared between a private
2160 -- type and its completion: the wrapper needs a properly typed
2161 -- parameter if the wrapped operation has a controlling first
2162 -- parameter. Note that this might not be the case for a function
2163 -- with a controlling result.
2165 if Is_Private_Primitive_Subprogram (Subp_Id) then
2166 if No (Actuals) then
2167 Actuals := New_List;
2170 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
2171 Prepend_To (Actuals,
2172 Unchecked_Convert_To
2173 (Corresponding_Concurrent_Type (Obj_Typ),
2174 Make_Identifier (Loc, Name_uO)));
2177 Prepend_To (Actuals,
2178 Make_Identifier (Loc,
2179 Chars => Chars (Defining_Identifier (First_Form))));
2182 Nam := New_Occurrence_Of (Subp_Id, Loc);
2184 -- An access-to-variable object parameter requires an explicit
2185 -- dereference in the unchecked conversion. This case occurs
2186 -- when a protected entry wrapper must override an interface
2187 -- level procedure with interface access as first parameter.
2189 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2191 if Nkind (Parameter_Type (First_Form)) =
2195 Make_Explicit_Dereference (Loc,
2196 Prefix => Make_Identifier (Loc, Name_uO));
2198 Conv_Id := Make_Identifier (Loc, Name_uO);
2202 Make_Selected_Component (Loc,
2204 Unchecked_Convert_To
2205 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
2206 Selector_Name => New_Occurrence_Of (Subp_Id, Loc));
2209 -- Create the subprogram body. For a function, the call to the
2210 -- actual subprogram has to be converted to the corresponding
2211 -- record if it is a controlling result.
2213 if Ekind (Subp_Id) = E_Function then
2219 Make_Function_Call (Loc,
2221 Parameter_Associations => Actuals);
2223 if Has_Controlling_Result (Subp_Id) then
2225 Unchecked_Convert_To
2226 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
2230 Make_Subprogram_Body (Loc,
2231 Specification => Body_Spec,
2232 Declarations => Empty_List,
2233 Handled_Statement_Sequence =>
2234 Make_Handled_Sequence_Of_Statements (Loc,
2235 Statements => New_List (
2236 Make_Simple_Return_Statement (Loc, Res))));
2241 Make_Subprogram_Body (Loc,
2242 Specification => Body_Spec,
2243 Declarations => Empty_List,
2244 Handled_Statement_Sequence =>
2245 Make_Handled_Sequence_Of_Statements (Loc,
2246 Statements => New_List (
2247 Make_Procedure_Call_Statement (Loc,
2249 Parameter_Associations => Actuals))));
2252 end Build_Wrapper_Body;
2254 -- Start of processing for Build_Wrapper_Bodies
2257 if Is_Concurrent_Type (Typ) then
2258 Rec_Typ := Corresponding_Record_Type (Typ);
2263 -- Generate wrapper bodies for a concurrent type which implements an
2266 if Present (Interfaces (Rec_Typ)) then
2268 Insert_Nod : Node_Id;
2270 Prim_Elmt : Elmt_Id;
2271 Prim_Decl : Node_Id;
2273 Wrap_Body : Node_Id;
2274 Wrap_Id : Entity_Id;
2279 -- Examine all primitive operations of the corresponding record
2280 -- type, looking for wrapper specs. Generate bodies in order to
2283 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
2284 while Present (Prim_Elmt) loop
2285 Prim := Node (Prim_Elmt);
2287 if (Ekind (Prim) = E_Function
2288 or else Ekind (Prim) = E_Procedure)
2289 and then Is_Primitive_Wrapper (Prim)
2291 Subp := Wrapped_Entity (Prim);
2292 Prim_Decl := Parent (Parent (Prim));
2295 Build_Wrapper_Body (Loc,
2298 Formals => Parameter_Specifications (Parent (Subp)));
2299 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2301 Set_Corresponding_Spec (Wrap_Body, Prim);
2302 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2304 Insert_After (Insert_Nod, Wrap_Body);
2305 Insert_Nod := Wrap_Body;
2307 Analyze (Wrap_Body);
2310 Next_Elmt (Prim_Elmt);
2314 end Build_Wrapper_Bodies;
2316 ------------------------
2317 -- Build_Wrapper_Spec --
2318 ------------------------
2320 function Build_Wrapper_Spec
2321 (Subp_Id : Entity_Id;
2322 Obj_Typ : Entity_Id;
2323 Formals : List_Id) return Node_Id
2325 Loc : constant Source_Ptr := Sloc (Subp_Id);
2326 First_Param : Node_Id;
2328 Iface_Elmt : Elmt_Id;
2329 Iface_Op : Entity_Id;
2330 Iface_Op_Elmt : Elmt_Id;
2332 function Overriding_Possible
2333 (Iface_Op : Entity_Id;
2334 Wrapper : Entity_Id) return Boolean;
2335 -- Determine whether a primitive operation can be overridden by Wrapper.
2336 -- Iface_Op is the candidate primitive operation of an interface type,
2337 -- Wrapper is the generated entry wrapper.
2339 function Replicate_Formals
2341 Formals : List_Id) return List_Id;
2342 -- An explicit parameter replication is required due to the Is_Entry_
2343 -- Formal flag being set for all the formals of an entry. The explicit
2344 -- replication removes the flag that would otherwise cause a different
2345 -- path of analysis.
2347 -------------------------
2348 -- Overriding_Possible --
2349 -------------------------
2351 function Overriding_Possible
2352 (Iface_Op : Entity_Id;
2353 Wrapper : Entity_Id) return Boolean
2355 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2356 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2358 function Type_Conformant_Parameters
2359 (Iface_Op_Params : List_Id;
2360 Wrapper_Params : List_Id) return Boolean;
2361 -- Determine whether the parameters of the generated entry wrapper
2362 -- and those of a primitive operation are type conformant. During
2363 -- this check, the first parameter of the primitive operation is
2364 -- skipped if it is a controlling argument: protected functions
2365 -- may have a controlling result.
2367 --------------------------------
2368 -- Type_Conformant_Parameters --
2369 --------------------------------
2371 function Type_Conformant_Parameters
2372 (Iface_Op_Params : List_Id;
2373 Wrapper_Params : List_Id) return Boolean
2375 Iface_Op_Param : Node_Id;
2376 Iface_Op_Typ : Entity_Id;
2377 Wrapper_Param : Node_Id;
2378 Wrapper_Typ : Entity_Id;
2381 -- Skip the first (controlling) parameter of primitive operation
2383 Iface_Op_Param := First (Iface_Op_Params);
2385 if Present (First_Formal (Iface_Op))
2386 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2388 Iface_Op_Param := Next (Iface_Op_Param);
2391 Wrapper_Param := First (Wrapper_Params);
2392 while Present (Iface_Op_Param)
2393 and then Present (Wrapper_Param)
2395 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2396 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2398 -- The two parameters must be mode conformant
2400 if not Conforming_Types
2401 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2406 Next (Iface_Op_Param);
2407 Next (Wrapper_Param);
2410 -- One of the lists is longer than the other
2412 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2417 end Type_Conformant_Parameters;
2419 -- Start of processing for Overriding_Possible
2422 if Chars (Iface_Op) /= Chars (Wrapper) then
2426 -- If an inherited subprogram is implemented by a protected procedure
2427 -- or an entry, then the first parameter of the inherited subprogram
2428 -- shall be of mode OUT or IN OUT, or access-to-variable parameter.
2430 if Ekind (Iface_Op) = E_Procedure
2431 and then Present (Parameter_Specifications (Iface_Op_Spec))
2434 Obj_Param : constant Node_Id :=
2435 First (Parameter_Specifications (Iface_Op_Spec));
2437 if not Out_Present (Obj_Param)
2438 and then Nkind (Parameter_Type (Obj_Param)) /=
2447 Type_Conformant_Parameters (
2448 Parameter_Specifications (Iface_Op_Spec),
2449 Parameter_Specifications (Wrapper_Spec));
2450 end Overriding_Possible;
2452 -----------------------
2453 -- Replicate_Formals --
2454 -----------------------
2456 function Replicate_Formals
2458 Formals : List_Id) return List_Id
2460 New_Formals : constant List_Id := New_List;
2462 Param_Type : Node_Id;
2465 Formal := First (Formals);
2467 -- Skip the object parameter when dealing with primitives declared
2468 -- between two views.
2470 if Is_Private_Primitive_Subprogram (Subp_Id)
2471 and then not Has_Controlling_Result (Subp_Id)
2473 Formal := Next (Formal);
2476 while Present (Formal) loop
2478 -- Create an explicit copy of the entry parameter
2480 -- When creating the wrapper subprogram for a primitive operation
2481 -- of a protected interface we must construct an equivalent
2482 -- signature to that of the overriding operation. For regular
2483 -- parameters we can just use the type of the formal, but for
2484 -- access to subprogram parameters we need to reanalyze the
2485 -- parameter type to create local entities for the signature of
2486 -- the subprogram type. Using the entities of the overriding
2487 -- subprogram will result in out-of-scope errors in the back-end.
2489 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2490 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2493 New_Occurrence_Of (Etype (Parameter_Type (Formal)), Loc);
2496 Append_To (New_Formals,
2497 Make_Parameter_Specification (Loc,
2498 Defining_Identifier =>
2499 Make_Defining_Identifier (Loc,
2500 Chars => Chars (Defining_Identifier (Formal))),
2501 In_Present => In_Present (Formal),
2502 Out_Present => Out_Present (Formal),
2503 Parameter_Type => Param_Type));
2509 end Replicate_Formals;
2511 -- Start of processing for Build_Wrapper_Spec
2514 -- There is no point in building wrappers for non-tagged concurrent
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 Set_Null_Exclusion_Present (Obj_Param_Typ,
2648 Null_Exclusion_Present (Parameter_Type (First_Param)));
2651 Obj_Param_Typ := New_Occurrence_Of (Obj_Typ, Loc);
2655 Make_Parameter_Specification (Loc,
2656 Defining_Identifier =>
2657 Make_Defining_Identifier (Loc,
2659 In_Present => In_Present (First_Param),
2660 Out_Present => Out_Present (First_Param),
2661 Parameter_Type => Obj_Param_Typ);
2663 Prepend_To (New_Formals, Obj_Param);
2665 -- If we are dealing with a primitive declared between two views,
2666 -- implemented by a synchronized operation, we need to create
2667 -- a default parameter. The mode of the parameter must match that
2668 -- of the primitive operation.
2671 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2673 Make_Parameter_Specification (Loc,
2674 Defining_Identifier =>
2675 Make_Defining_Identifier (Loc, Name_uO),
2676 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2677 Out_Present => Ekind (Subp_Id) /= E_Function,
2678 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2679 Prepend_To (New_Formals, Obj_Param);
2682 -- Build the final spec. If it is a function with a controlling
2683 -- result, it is a primitive operation of the corresponding
2684 -- record type, so mark the spec accordingly.
2686 if Ekind (Subp_Id) = E_Function then
2691 if Has_Controlling_Result (Subp_Id) then
2694 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2696 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2700 Make_Function_Specification (Loc,
2701 Defining_Unit_Name => Wrapper_Id,
2702 Parameter_Specifications => New_Formals,
2703 Result_Definition => Res_Def);
2707 Make_Procedure_Specification (Loc,
2708 Defining_Unit_Name => Wrapper_Id,
2709 Parameter_Specifications => New_Formals);
2712 end Build_Wrapper_Spec;
2714 -------------------------
2715 -- Build_Wrapper_Specs --
2716 -------------------------
2718 procedure Build_Wrapper_Specs
2724 Rec_Typ : Entity_Id;
2725 procedure Scan_Declarations (L : List_Id);
2726 -- Common processing for visible and private declarations
2727 -- of a protected type.
2729 procedure Scan_Declarations (L : List_Id) is
2731 Wrap_Decl : Node_Id;
2732 Wrap_Spec : Node_Id;
2740 while Present (Decl) loop
2743 if Nkind (Decl) = N_Entry_Declaration
2744 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2748 (Subp_Id => Defining_Identifier (Decl),
2750 Formals => Parameter_Specifications (Decl));
2752 elsif Nkind (Decl) = N_Subprogram_Declaration then
2755 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2758 Parameter_Specifications (Specification (Decl)));
2761 if Present (Wrap_Spec) then
2763 Make_Subprogram_Declaration (Loc,
2764 Specification => Wrap_Spec);
2766 Insert_After (N, Wrap_Decl);
2769 Analyze (Wrap_Decl);
2774 end Scan_Declarations;
2776 -- start of processing for Build_Wrapper_Specs
2779 if Is_Protected_Type (Typ) then
2780 Def := Protected_Definition (Parent (Typ));
2781 else pragma Assert (Is_Task_Type (Typ));
2782 Def := Task_Definition (Parent (Typ));
2785 Rec_Typ := Corresponding_Record_Type (Typ);
2787 -- Generate wrapper specs for a concurrent type which implements an
2788 -- interface. Operations in both the visible and private parts may
2789 -- implement progenitor operations.
2791 if Present (Interfaces (Rec_Typ))
2792 and then Present (Def)
2794 Scan_Declarations (Visible_Declarations (Def));
2795 Scan_Declarations (Private_Declarations (Def));
2797 end Build_Wrapper_Specs;
2799 ---------------------------
2800 -- Build_Find_Body_Index --
2801 ---------------------------
2803 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2804 Loc : constant Source_Ptr := Sloc (Typ);
2807 Has_F : Boolean := False;
2809 If_St : Node_Id := Empty;
2812 Decls : List_Id := New_List;
2815 Siz : Node_Id := Empty;
2817 procedure Add_If_Clause (Expr : Node_Id);
2818 -- Add test for range of current entry
2820 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2821 -- If a bound of an entry is given by a discriminant, retrieve the
2822 -- actual value of the discriminant from the enclosing object.
2828 procedure Add_If_Clause (Expr : Node_Id) is
2830 Stats : constant List_Id :=
2832 Make_Simple_Return_Statement (Loc,
2833 Expression => Make_Integer_Literal (Loc, Index + 1)));
2836 -- Index for current entry body
2840 -- Compute total length of entry queues so far
2848 Right_Opnd => Expr);
2853 Left_Opnd => Make_Identifier (Loc, Name_uE),
2856 -- Map entry queue indexes in the range of the current family
2857 -- into the current index, that designates the entry body.
2861 Make_Implicit_If_Statement (Typ,
2863 Then_Statements => Stats,
2864 Elsif_Parts => New_List);
2868 Append_To (Elsif_Parts (If_St),
2869 Make_Elsif_Part (Loc,
2871 Then_Statements => Stats));
2875 ------------------------------
2876 -- Convert_Discriminant_Ref --
2877 ------------------------------
2879 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2883 if Is_Entity_Name (Bound)
2884 and then Ekind (Entity (Bound)) = E_Discriminant
2887 Make_Selected_Component (Loc,
2889 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2890 Make_Explicit_Dereference (Loc,
2891 Make_Identifier (Loc, Name_uObject))),
2892 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2893 Set_Etype (B, Etype (Entity (Bound)));
2895 B := New_Copy_Tree (Bound);
2899 end Convert_Discriminant_Ref;
2901 -- Start of processing for Build_Find_Body_Index
2904 Spec := Build_Find_Body_Index_Spec (Typ);
2906 Ent := First_Entity (Typ);
2907 while Present (Ent) loop
2908 if Ekind (Ent) = E_Entry_Family then
2918 -- If the protected type has no entry families, there is a one-one
2919 -- correspondence between entry queue and entry body.
2922 Make_Simple_Return_Statement (Loc,
2923 Expression => Make_Identifier (Loc, Name_uE));
2926 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2929 -- if E <= l1 then return 1;
2930 -- elsif E <= l1 + l2 then return 2;
2935 Ent := First_Entity (Typ);
2937 Add_Object_Pointer (Loc, Typ, Decls);
2939 while Present (Ent) loop
2940 if Ekind (Ent) = E_Entry then
2941 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2943 elsif Ekind (Ent) = E_Entry_Family then
2944 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2945 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2946 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2947 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2956 Make_Simple_Return_Statement (Loc,
2957 Expression => Make_Integer_Literal (Loc, 1));
2959 elsif Nkind (Ret) = N_If_Statement then
2961 -- Ranges are in increasing order, so last one doesn't need guard
2964 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2967 Set_Else_Statements (Ret, Then_Statements (Nod));
2973 Make_Subprogram_Body (Loc,
2974 Specification => Spec,
2975 Declarations => Decls,
2976 Handled_Statement_Sequence =>
2977 Make_Handled_Sequence_Of_Statements (Loc,
2978 Statements => New_List (Ret)));
2979 end Build_Find_Body_Index;
2981 --------------------------------
2982 -- Build_Find_Body_Index_Spec --
2983 --------------------------------
2985 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2986 Loc : constant Source_Ptr := Sloc (Typ);
2987 Id : constant Entity_Id :=
2988 Make_Defining_Identifier (Loc,
2989 Chars => New_External_Name (Chars (Typ), 'F'));
2990 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2991 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2995 Make_Function_Specification (Loc,
2996 Defining_Unit_Name => Id,
2997 Parameter_Specifications => New_List (
2998 Make_Parameter_Specification (Loc,
2999 Defining_Identifier => Parm1,
3001 New_Occurrence_Of (RTE (RE_Address), Loc)),
3003 Make_Parameter_Specification (Loc,
3004 Defining_Identifier => Parm2,
3006 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
3008 Result_Definition => New_Occurrence_Of (
3009 RTE (RE_Protected_Entry_Index), Loc));
3010 end Build_Find_Body_Index_Spec;
3012 -----------------------------------------------
3013 -- Build_Lock_Free_Protected_Subprogram_Body --
3014 -----------------------------------------------
3016 function Build_Lock_Free_Protected_Subprogram_Body
3019 Unprot_Spec : Node_Id) return Node_Id
3021 Actuals : constant List_Id := New_List;
3022 Loc : constant Source_Ptr := Sloc (N);
3023 Spec : constant Node_Id := Specification (N);
3024 Unprot_Id : constant Entity_Id := Defining_Unit_Name (Unprot_Spec);
3026 Prot_Spec : Node_Id;
3030 -- Create the protected version of the body
3033 Build_Protected_Sub_Specification (N, Prot_Typ, Protected_Mode);
3035 -- Build the actual parameters which appear in the call to the
3036 -- unprotected version of the body.
3038 Formal := First (Parameter_Specifications (Prot_Spec));
3039 while Present (Formal) loop
3041 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
3046 -- Function case, generate:
3047 -- return <Unprot_Func_Call>;
3049 if Nkind (Spec) = N_Function_Specification then
3051 Make_Simple_Return_Statement (Loc,
3053 Make_Function_Call (Loc,
3055 Make_Identifier (Loc, Chars (Unprot_Id)),
3056 Parameter_Associations => Actuals));
3058 -- Procedure case, call the unprotected version
3062 Make_Procedure_Call_Statement (Loc,
3064 Make_Identifier (Loc, Chars (Unprot_Id)),
3065 Parameter_Associations => Actuals);
3069 Make_Subprogram_Body (Loc,
3070 Declarations => Empty_List,
3071 Specification => Prot_Spec,
3072 Handled_Statement_Sequence =>
3073 Make_Handled_Sequence_Of_Statements (Loc,
3074 Statements => New_List (Stmt)));
3075 end Build_Lock_Free_Protected_Subprogram_Body;
3077 -------------------------------------------------
3078 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3079 -------------------------------------------------
3081 -- Procedures which meet the lock-free implementation requirements and
3082 -- reference a unique scalar component Comp are expanded in the following
3085 -- procedure P (...) is
3086 -- Expected_Comp : constant Comp_Type :=
3088 -- (System.Atomic_Primitives.Lock_Free_Read_N
3089 -- (_Object.Comp'Address));
3093 -- <original declarations before the object renaming declaration
3096 -- Desired_Comp : Comp_Type := Expected_Comp;
3097 -- Comp : Comp_Type renames Desired_Comp;
3099 -- <original delarations after the object renaming declaration
3103 -- <original statements>
3104 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3105 -- (_Object.Comp'Address,
3106 -- Interfaces.Unsigned_N (Expected_Comp),
3107 -- Interfaces.Unsigned_N (Desired_Comp));
3112 -- Each return and raise statement of P is transformed into an atomic
3115 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3116 -- (_Object.Comp'Address,
3117 -- Interfaces.Unsigned_N (Expected_Comp),
3118 -- Interfaces.Unsigned_N (Desired_Comp));
3120 -- <original statement>
3125 -- Functions which meet the lock-free implementation requirements and
3126 -- reference a unique scalar component Comp are expanded in the following
3129 -- function F (...) return ... is
3130 -- <original declarations before the object renaming declaration
3133 -- Expected_Comp : constant Comp_Type :=
3135 -- (System.Atomic_Primitives.Lock_Free_Read_N
3136 -- (_Object.Comp'Address));
3137 -- Comp : Comp_Type renames Expected_Comp;
3139 -- <original delarations after the object renaming declaration of
3143 -- <original statements>
3146 function Build_Lock_Free_Unprotected_Subprogram_Body
3148 Prot_Typ : Node_Id) return Node_Id
3150 function Referenced_Component (N : Node_Id) return Entity_Id;
3151 -- Subprograms which meet the lock-free implementation criteria are
3152 -- allowed to reference only one unique component. Return the prival
3153 -- of the said component.
3155 --------------------------
3156 -- Referenced_Component --
3157 --------------------------
3159 function Referenced_Component (N : Node_Id) return Entity_Id is
3162 Source_Comp : Entity_Id := Empty;
3165 -- Find the unique source component which N references in its
3168 for Index in 1 .. Lock_Free_Subprogram_Table.Last loop
3170 Element : Lock_Free_Subprogram renames
3171 Lock_Free_Subprogram_Table.Table (Index);
3173 if Element.Sub_Body = N then
3174 Source_Comp := Element.Comp_Id;
3180 if No (Source_Comp) then
3184 -- Find the prival which corresponds to the source component within
3185 -- the declarations of N.
3187 Decl := First (Declarations (N));
3188 while Present (Decl) loop
3190 -- Privals appear as object renamings
3192 if Nkind (Decl) = N_Object_Renaming_Declaration then
3193 Comp := Defining_Identifier (Decl);
3195 if Present (Prival_Link (Comp))
3196 and then Prival_Link (Comp) = Source_Comp
3206 end Referenced_Component;
3210 Comp : constant Entity_Id := Referenced_Component (N);
3211 Loc : constant Source_Ptr := Sloc (N);
3212 Hand_Stmt_Seq : Node_Id := Handled_Statement_Sequence (N);
3213 Decls : List_Id := Declarations (N);
3215 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3218 -- Add renamings for the protection object, discriminals, privals and
3219 -- the entry index constant for use by debugger.
3221 Debug_Private_Data_Declarations (Decls);
3223 -- Perform the lock-free expansion when the subprogram references a
3224 -- protected component.
3226 if Present (Comp) then
3227 Protected_Component_Ref : declare
3228 Comp_Decl : constant Node_Id := Parent (Comp);
3229 Comp_Sel_Nam : constant Node_Id := Name (Comp_Decl);
3230 Comp_Type : constant Entity_Id := Etype (Comp);
3232 Is_Procedure : constant Boolean :=
3233 Ekind (Corresponding_Spec (N)) = E_Procedure;
3234 -- Indicates if N is a protected procedure body
3236 Block_Decls : List_Id;
3237 Try_Write : Entity_Id;
3238 Desired_Comp : Entity_Id;
3241 Label_Id : Entity_Id := Empty;
3243 Expected_Comp : Entity_Id;
3246 New_Copy_List (Statements (Hand_Stmt_Seq));
3248 Unsigned : Entity_Id;
3250 function Process_Node (N : Node_Id) return Traverse_Result;
3251 -- Transform a single node if it is a return statement, a raise
3252 -- statement or a reference to Comp.
3254 procedure Process_Stmts (Stmts : List_Id);
3255 -- Given a statement sequence Stmts, wrap any return or raise
3256 -- statements in the following manner:
3258 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3259 -- (_Object.Comp'Address,
3260 -- Interfaces.Unsigned_N (Expected_Comp),
3261 -- Interfaces.Unsigned_N (Desired_Comp))
3272 function Process_Node (N : Node_Id) return Traverse_Result is
3274 procedure Wrap_Statement (Stmt : Node_Id);
3275 -- Wrap an arbitrary statement inside an if statement where the
3276 -- condition does an atomic check on the state of the object.
3278 --------------------
3279 -- Wrap_Statement --
3280 --------------------
3282 procedure Wrap_Statement (Stmt : Node_Id) is
3284 -- The first time through, create the declaration of a label
3285 -- which is used to skip the remainder of source statements
3286 -- if the state of the object has changed.
3288 if No (Label_Id) then
3290 Make_Identifier (Loc, New_External_Name ('L', 0));
3291 Set_Entity (Label_Id,
3292 Make_Defining_Identifier (Loc, Chars (Label_Id)));
3296 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3297 -- (_Object.Comp'Address,
3298 -- Interfaces.Unsigned_N (Expected_Comp),
3299 -- Interfaces.Unsigned_N (Desired_Comp))
3307 Make_Implicit_If_Statement (N,
3309 Make_Function_Call (Loc,
3311 New_Occurrence_Of (Try_Write, Loc),
3312 Parameter_Associations => New_List (
3313 Make_Attribute_Reference (Loc,
3314 Prefix => Relocate_Node (Comp_Sel_Nam),
3315 Attribute_Name => Name_Address),
3317 Unchecked_Convert_To (Unsigned,
3318 New_Occurrence_Of (Expected_Comp, Loc)),
3320 Unchecked_Convert_To (Unsigned,
3321 New_Occurrence_Of (Desired_Comp, Loc)))),
3323 Then_Statements => New_List (Relocate_Node (Stmt)),
3325 Else_Statements => New_List (
3326 Make_Goto_Statement (Loc,
3328 New_Occurrence_Of (Entity (Label_Id), Loc)))));
3331 -- Start of processing for Process_Node
3334 -- Wrap each return and raise statement that appear inside a
3335 -- procedure. Skip the last return statement which is added by
3336 -- default since it is transformed into an exit statement.
3339 and then ((Nkind (N) = N_Simple_Return_Statement
3340 and then N /= Last (Stmts))
3341 or else Nkind (N) = N_Extended_Return_Statement
3342 or else (Nkind_In (N, N_Raise_Constraint_Error,
3343 N_Raise_Program_Error,
3345 N_Raise_Storage_Error)
3346 and then Comes_From_Source (N)))
3354 Set_Analyzed (N, False);
3359 procedure Process_Nodes is new Traverse_Proc (Process_Node);
3365 procedure Process_Stmts (Stmts : List_Id) is
3368 Stmt := First (Stmts);
3369 while Present (Stmt) loop
3370 Process_Nodes (Stmt);
3375 -- Start of processing for Protected_Component_Ref
3378 -- Get the type size
3380 if Known_Static_Esize (Comp_Type) then
3381 Typ_Size := UI_To_Int (Esize (Comp_Type));
3383 -- If the Esize (Object_Size) is unknown at compile time, look at
3384 -- the RM_Size (Value_Size) since it may have been set by an
3385 -- explicit representation clause.
3387 elsif Known_Static_RM_Size (Comp_Type) then
3388 Typ_Size := UI_To_Int (RM_Size (Comp_Type));
3390 -- Should not happen since this has already been checked in
3391 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3394 raise Program_Error;
3397 -- Retrieve all relevant atomic routines and types
3401 Try_Write := RTE (RE_Lock_Free_Try_Write_8);
3402 Read := RTE (RE_Lock_Free_Read_8);
3403 Unsigned := RTE (RE_Uint8);
3406 Try_Write := RTE (RE_Lock_Free_Try_Write_16);
3407 Read := RTE (RE_Lock_Free_Read_16);
3408 Unsigned := RTE (RE_Uint16);
3411 Try_Write := RTE (RE_Lock_Free_Try_Write_32);
3412 Read := RTE (RE_Lock_Free_Read_32);
3413 Unsigned := RTE (RE_Uint32);
3416 Try_Write := RTE (RE_Lock_Free_Try_Write_64);
3417 Read := RTE (RE_Lock_Free_Read_64);
3418 Unsigned := RTE (RE_Uint64);
3421 raise Program_Error;
3425 -- Expected_Comp : constant Comp_Type :=
3427 -- (System.Atomic_Primitives.Lock_Free_Read_N
3428 -- (_Object.Comp'Address));
3431 Make_Defining_Identifier (Loc,
3432 New_External_Name (Chars (Comp), Suffix => "_saved"));
3435 Make_Object_Declaration (Loc,
3436 Defining_Identifier => Expected_Comp,
3437 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3438 Constant_Present => True,
3440 Unchecked_Convert_To (Comp_Type,
3441 Make_Function_Call (Loc,
3442 Name => New_Occurrence_Of (Read, Loc),
3443 Parameter_Associations => New_List (
3444 Make_Attribute_Reference (Loc,
3445 Prefix => Relocate_Node (Comp_Sel_Nam),
3446 Attribute_Name => Name_Address)))));
3448 -- Protected procedures
3450 if Is_Procedure then
3451 -- Move the original declarations inside the generated block
3453 Block_Decls := Decls;
3455 -- Reset the declarations list of the protected procedure to
3456 -- contain only Decl.
3458 Decls := New_List (Decl);
3461 -- Desired_Comp : Comp_Type := Expected_Comp;
3464 Make_Defining_Identifier (Loc,
3465 New_External_Name (Chars (Comp), Suffix => "_current"));
3467 -- Insert the declarations of Expected_Comp and Desired_Comp in
3468 -- the block declarations right before the renaming of the
3469 -- protected component.
3471 Insert_Before (Comp_Decl,
3472 Make_Object_Declaration (Loc,
3473 Defining_Identifier => Desired_Comp,
3474 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3476 New_Occurrence_Of (Expected_Comp, Loc)));
3478 -- Protected function
3481 Desired_Comp := Expected_Comp;
3483 -- Insert the declaration of Expected_Comp in the function
3484 -- declarations right before the renaming of the protected
3487 Insert_Before (Comp_Decl, Decl);
3490 -- Rewrite the protected component renaming declaration to be a
3491 -- renaming of Desired_Comp.
3494 -- Comp : Comp_Type renames Desired_Comp;
3497 Make_Object_Renaming_Declaration (Loc,
3498 Defining_Identifier =>
3499 Defining_Identifier (Comp_Decl),
3501 New_Occurrence_Of (Comp_Type, Loc),
3503 New_Occurrence_Of (Desired_Comp, Loc)));
3505 -- Wrap any return or raise statements in Stmts in same the manner
3506 -- described in Process_Stmts.
3508 Process_Stmts (Stmts);
3511 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3512 -- (_Object.Comp'Address,
3513 -- Interfaces.Unsigned_N (Expected_Comp),
3514 -- Interfaces.Unsigned_N (Desired_Comp))
3516 if Is_Procedure then
3518 Make_Exit_Statement (Loc,
3520 Make_Function_Call (Loc,
3522 New_Occurrence_Of (Try_Write, Loc),
3523 Parameter_Associations => New_List (
3524 Make_Attribute_Reference (Loc,
3525 Prefix => Relocate_Node (Comp_Sel_Nam),
3526 Attribute_Name => Name_Address),
3528 Unchecked_Convert_To (Unsigned,
3529 New_Occurrence_Of (Expected_Comp, Loc)),
3531 Unchecked_Convert_To (Unsigned,
3532 New_Occurrence_Of (Desired_Comp, Loc)))));
3534 -- Small optimization: transform the default return statement
3535 -- of a procedure into the atomic exit statement.
3537 if Nkind (Last (Stmts)) = N_Simple_Return_Statement then
3538 Rewrite (Last (Stmts), Stmt);
3540 Append_To (Stmts, Stmt);
3544 -- Create the declaration of the label used to skip the rest of
3545 -- the source statements when the object state changes.
3547 if Present (Label_Id) then
3548 Label := Make_Label (Loc, Label_Id);
3550 Make_Implicit_Label_Declaration (Loc,
3551 Defining_Identifier => Entity (Label_Id),
3552 Label_Construct => Label));
3553 Append_To (Stmts, Label);
3565 if Is_Procedure then
3568 Make_Loop_Statement (Loc,
3569 Statements => New_List (
3570 Make_Block_Statement (Loc,
3571 Declarations => Block_Decls,
3572 Handled_Statement_Sequence =>
3573 Make_Handled_Sequence_Of_Statements (Loc,
3574 Statements => Stmts))),
3575 End_Label => Empty));
3579 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts);
3580 end Protected_Component_Ref;
3583 -- Make an unprotected version of the subprogram for use within the same
3584 -- object, with new name and extra parameter representing the object.
3587 Make_Subprogram_Body (Loc,
3589 Build_Protected_Sub_Specification (N, Prot_Typ, Unprotected_Mode),
3590 Declarations => Decls,
3591 Handled_Statement_Sequence => Hand_Stmt_Seq);
3592 end Build_Lock_Free_Unprotected_Subprogram_Body;
3594 -------------------------
3595 -- Build_Master_Entity --
3596 -------------------------
3598 procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
3599 Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
3601 Context_Id : Entity_Id;
3607 if Is_Itype (Obj_Or_Typ) then
3608 Par := Associated_Node_For_Itype (Obj_Or_Typ);
3610 Par := Parent (Obj_Or_Typ);
3613 -- When creating a master for a record component which is either a task
3614 -- or access-to-task, the enclosing record is the master scope and the
3615 -- proper insertion point is the component list.
3617 if Is_Record_Type (Current_Scope) then
3619 Context_Id := Current_Scope;
3620 Decls := List_Containing (Context);
3622 -- Default case for object declarations and access types. Note that the
3623 -- context is updated to the nearest enclosing body, block, package or
3624 -- return statement.
3627 Find_Enclosing_Context (Par, Context, Context_Id, Decls);
3630 -- Do not create a master if one already exists or there is no task
3633 if Has_Master_Entity (Context_Id)
3634 or else Restriction_Active (No_Task_Hierarchy)
3639 -- Create a master, generate:
3640 -- _Master : constant Master_Id := Current_Master.all;
3643 Make_Object_Declaration (Loc,
3644 Defining_Identifier =>
3645 Make_Defining_Identifier (Loc, Name_uMaster),
3646 Constant_Present => True,
3647 Object_Definition => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3649 Make_Explicit_Dereference (Loc,
3650 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
3652 -- The master is inserted at the start of the declarative list of the
3655 Prepend_To (Decls, Decl);
3657 -- In certain cases where transient scopes are involved, the immediate
3658 -- scope is not always the proper master scope. Ensure that the master
3659 -- declaration and entity appear in the same context.
3661 if Context_Id /= Current_Scope then
3662 Push_Scope (Context_Id);
3669 -- Mark the enclosing scope and its associated construct as being task
3672 Set_Has_Master_Entity (Context_Id);
3674 while Present (Context)
3675 and then Nkind (Context) /= N_Compilation_Unit
3677 if Nkind_In (Context, N_Block_Statement,
3681 Set_Is_Task_Master (Context);
3684 elsif Nkind (Parent (Context)) = N_Subunit then
3685 Context := Corresponding_Stub (Parent (Context));
3688 Context := Parent (Context);
3690 end Build_Master_Entity;
3692 ---------------------------
3693 -- Build_Master_Renaming --
3694 ---------------------------
3696 procedure Build_Master_Renaming
3697 (Ptr_Typ : Entity_Id;
3698 Ins_Nod : Node_Id := Empty)
3700 Loc : constant Source_Ptr := Sloc (Ptr_Typ);
3702 Master_Decl : Node_Id;
3703 Master_Id : Entity_Id;
3706 -- Nothing to do if there is no task hierarchy
3708 if Restriction_Active (No_Task_Hierarchy) then
3712 -- Determine the proper context to insert the master renaming
3714 if Present (Ins_Nod) then
3716 elsif Is_Itype (Ptr_Typ) then
3717 Context := Associated_Node_For_Itype (Ptr_Typ);
3719 Context := Parent (Ptr_Typ);
3723 -- <Ptr_Typ>M : Master_Id renames _Master;
3726 Make_Defining_Identifier (Loc,
3727 New_External_Name (Chars (Ptr_Typ), 'M'));
3730 Make_Object_Renaming_Declaration (Loc,
3731 Defining_Identifier => Master_Id,
3732 Subtype_Mark => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3733 Name => Make_Identifier (Loc, Name_uMaster));
3735 Insert_Action (Context, Master_Decl);
3737 -- The renamed master now services the access type
3739 Set_Master_Id (Ptr_Typ, Master_Id);
3740 end Build_Master_Renaming;
3742 -----------------------------------------
3743 -- Build_Private_Protected_Declaration --
3744 -----------------------------------------
3746 function Build_Private_Protected_Declaration
3747 (N : Node_Id) return Entity_Id
3749 Loc : constant Source_Ptr := Sloc (N);
3750 Body_Id : constant Entity_Id := Defining_Entity (N);
3755 Spec_Id : Entity_Id;
3758 Formal := First_Formal (Body_Id);
3760 -- The protected operation always has at least one formal, namely the
3761 -- object itself, but it is only placed in the parameter list if
3762 -- expansion is enabled.
3764 if Present (Formal) or else Expander_Active then
3765 Plist := Copy_Parameter_List (Body_Id);
3770 if Nkind (Specification (N)) = N_Procedure_Specification then
3772 Make_Procedure_Specification (Loc,
3773 Defining_Unit_Name =>
3774 Make_Defining_Identifier (Sloc (Body_Id),
3775 Chars => Chars (Body_Id)),
3776 Parameter_Specifications =>
3780 Make_Function_Specification (Loc,
3781 Defining_Unit_Name =>
3782 Make_Defining_Identifier (Sloc (Body_Id),
3783 Chars => Chars (Body_Id)),
3784 Parameter_Specifications => Plist,
3785 Result_Definition =>
3786 New_Occurrence_Of (Etype (Body_Id), Loc));
3789 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
3790 Insert_Before (N, Decl);
3791 Spec_Id := Defining_Unit_Name (New_Spec);
3793 -- Indicate that the entity comes from source, to ensure that cross-
3794 -- reference information is properly generated. The body itself is
3795 -- rewritten during expansion, and the body entity will not appear in
3796 -- calls to the operation.
3798 Set_Comes_From_Source (Spec_Id, True);
3800 Set_Has_Completion (Spec_Id);
3801 Set_Convention (Spec_Id, Convention_Protected);
3803 end Build_Private_Protected_Declaration;
3805 ---------------------------
3806 -- Build_Protected_Entry --
3807 ---------------------------
3809 function Build_Protected_Entry
3812 Pid : Node_Id) return Node_Id
3814 Loc : constant Source_Ptr := Sloc (N);
3816 Decls : constant List_Id := Declarations (N);
3817 End_Lab : constant Node_Id :=
3818 End_Label (Handled_Statement_Sequence (N));
3819 End_Loc : constant Source_Ptr :=
3820 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
3821 -- Used for the generated call to Complete_Entry_Body
3823 Han_Loc : Source_Ptr;
3824 -- Used for the exception handler, inserted at end of the body
3826 Op_Decls : constant List_Id := New_List;
3834 -- Set the source location on the exception handler only when debugging
3835 -- the expanded code (see Make_Implicit_Exception_Handler).
3837 if Debug_Generated_Code then
3840 -- Otherwise the inserted code should not be visible to the debugger
3843 Han_Loc := No_Location;
3847 Make_Defining_Identifier (Loc,
3848 Chars => Chars (Protected_Body_Subprogram (Ent)));
3850 Build_Protected_Entry_Specification (Loc, Edef, Empty);
3852 -- Add the following declarations:
3854 -- type poVP is access poV;
3855 -- _object : poVP := poVP (_O);
3857 -- where _O is the formal parameter associated with the concurrent
3858 -- object. These declarations are needed for Complete_Entry_Body.
3860 Add_Object_Pointer (Loc, Pid, Op_Decls);
3862 -- Add renamings for all formals, the Protection object, discriminals,
3863 -- privals and the entry index constant for use by debugger.
3865 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
3866 Debug_Private_Data_Declarations (Decls);
3868 -- Put the declarations and the statements from the entry
3872 Make_Block_Statement (Loc,
3873 Declarations => Decls,
3874 Handled_Statement_Sequence =>
3875 Handled_Statement_Sequence (N)));
3877 case Corresponding_Runtime_Package (Pid) is
3878 when System_Tasking_Protected_Objects_Entries =>
3879 Append_To (Op_Stats,
3880 Make_Procedure_Call_Statement (End_Loc,
3882 New_Occurrence_Of (RTE (RE_Complete_Entry_Body), Loc),
3883 Parameter_Associations => New_List (
3884 Make_Attribute_Reference (End_Loc,
3886 Make_Selected_Component (End_Loc,
3888 Make_Identifier (End_Loc, Name_uObject),
3890 Make_Identifier (End_Loc, Name_uObject)),
3891 Attribute_Name => Name_Unchecked_Access))));
3893 when System_Tasking_Protected_Objects_Single_Entry =>
3895 -- Historically, a call to Complete_Single_Entry_Body was
3896 -- inserted, but it was a null procedure.
3901 raise Program_Error;
3904 -- When exceptions can not be propagated, we never need to call
3905 -- Exception_Complete_Entry_Body
3907 if No_Exception_Handlers_Set then
3909 Make_Subprogram_Body (Loc,
3910 Specification => Espec,
3911 Declarations => Op_Decls,
3912 Handled_Statement_Sequence =>
3913 Make_Handled_Sequence_Of_Statements (Loc,
3914 Statements => Op_Stats,
3915 End_Label => End_Lab));
3918 Ohandle := Make_Others_Choice (Loc);
3919 Set_All_Others (Ohandle);
3921 case Corresponding_Runtime_Package (Pid) is
3922 when System_Tasking_Protected_Objects_Entries =>
3925 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
3927 when System_Tasking_Protected_Objects_Single_Entry =>
3930 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
3933 raise Program_Error;
3936 -- Establish link between subprogram body entity and source entry
3938 Set_Corresponding_Protected_Entry (Edef, Ent);
3940 -- Create body of entry procedure. The renaming declarations are
3941 -- placed ahead of the block that contains the actual entry body.
3944 Make_Subprogram_Body (Loc,
3945 Specification => Espec,
3946 Declarations => Op_Decls,
3947 Handled_Statement_Sequence =>
3948 Make_Handled_Sequence_Of_Statements (Loc,
3949 Statements => Op_Stats,
3950 End_Label => End_Lab,
3951 Exception_Handlers => New_List (
3952 Make_Implicit_Exception_Handler (Han_Loc,
3953 Exception_Choices => New_List (Ohandle),
3955 Statements => New_List (
3956 Make_Procedure_Call_Statement (Han_Loc,
3958 Parameter_Associations => New_List (
3959 Make_Attribute_Reference (Han_Loc,
3961 Make_Selected_Component (Han_Loc,
3963 Make_Identifier (Han_Loc, Name_uObject),
3965 Make_Identifier (Han_Loc, Name_uObject)),
3966 Attribute_Name => Name_Unchecked_Access),
3968 Make_Function_Call (Han_Loc,
3969 Name => New_Occurrence_Of (
3970 RTE (RE_Get_GNAT_Exception), Loc)))))))));
3972 end Build_Protected_Entry;
3974 -----------------------------------------
3975 -- Build_Protected_Entry_Specification --
3976 -----------------------------------------
3978 function Build_Protected_Entry_Specification
3981 Ent_Id : Entity_Id) return Node_Id
3983 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3986 Set_Debug_Info_Needed (Def_Id);
3988 if Present (Ent_Id) then
3989 Append_Elmt (P, Accept_Address (Ent_Id));
3993 Make_Procedure_Specification (Loc,
3994 Defining_Unit_Name => Def_Id,
3995 Parameter_Specifications => New_List (
3996 Make_Parameter_Specification (Loc,
3997 Defining_Identifier =>
3998 Make_Defining_Identifier (Loc, Name_uO),
4000 New_Occurrence_Of (RTE (RE_Address), Loc)),
4002 Make_Parameter_Specification (Loc,
4003 Defining_Identifier => P,
4005 New_Occurrence_Of (RTE (RE_Address), Loc)),
4007 Make_Parameter_Specification (Loc,
4008 Defining_Identifier =>
4009 Make_Defining_Identifier (Loc, Name_uE),
4011 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))));
4012 end Build_Protected_Entry_Specification;
4014 --------------------------
4015 -- Build_Protected_Spec --
4016 --------------------------
4018 function Build_Protected_Spec
4020 Obj_Type : Entity_Id;
4022 Unprotected : Boolean := False) return List_Id
4024 Loc : constant Source_Ptr := Sloc (N);
4027 New_Plist : List_Id;
4028 New_Param : Node_Id;
4031 New_Plist := New_List;
4033 Formal := First_Formal (Ident);
4034 while Present (Formal) loop
4036 Make_Parameter_Specification (Loc,
4037 Defining_Identifier =>
4038 Make_Defining_Identifier (Sloc (Formal), Chars (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 the 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 an assignment statement separate for the
4755 -- case of limited type. We cannot assign it unless the
4756 -- Assignment_OK flag is set first. An out formal of an
4757 -- access type must also be initialized from the actual,
4758 -- as stated in RM 6.4.1 (13), but no constraint is applied
4761 if Ekind (Formal) /= E_Out_Parameter
4762 or else Is_Access_Type (Etype (Formal))
4765 New_Occurrence_Of (Defining_Identifier (N_Node), Loc);
4766 Set_Assignment_OK (N_Var);
4768 Make_Assignment_Statement (Loc,
4770 Expression => Relocate_Node (Actual)));
4771 Set_Suppress_Assignment_Checks (Last (Stats));
4774 Append (N_Node, Decls);
4777 Make_Attribute_Reference (Loc,
4778 Attribute_Name => Name_Unchecked_Access,
4780 New_Occurrence_Of (Defining_Identifier (N_Node), Loc)));
4782 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4784 elsif Is_VM_By_Copy_Actual (Actual) then
4786 Make_Object_Declaration (Loc,
4787 Defining_Identifier => Make_Temporary (Loc, 'J'),
4788 Aliased_Present => True,
4789 Object_Definition =>
4790 New_Occurrence_Of (Etype (Formal), Loc),
4791 Expression => New_Copy_Tree (Actual));
4792 Set_Assignment_OK (N_Node);
4794 Append (N_Node, Decls);
4797 Make_Attribute_Reference (Loc,
4798 Attribute_Name => Name_Unchecked_Access,
4800 New_Occurrence_Of (Defining_Identifier (N_Node), Loc)));
4803 -- Interface class-wide formal
4805 if Ada_Version >= Ada_2005
4806 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
4807 and then Is_Interface (Etype (Formal))
4809 Iface_Typ := Etype (Etype (Formal));
4812 -- formal_iface_type! (actual.iface_tag)'reference
4815 Find_Interface_Tag (Etype (Actual), Iface_Typ);
4816 pragma Assert (Present (Iface_Tag));
4819 Make_Reference (Loc,
4820 Unchecked_Convert_To (Iface_Typ,
4821 Make_Selected_Component (Loc,
4823 Relocate_Node (Actual),
4825 New_Occurrence_Of (Iface_Tag, Loc)))));
4831 Make_Reference (Loc, Relocate_Node (Actual)));
4835 Next_Actual (Actual);
4836 Next_Formal_With_Extras (Formal);
4839 -- Now build the declaration of parameters initialized with the
4840 -- aggregate containing this constructed parameter list.
4842 P := Make_Defining_Identifier (Loc, Name_uP);
4845 Make_Object_Declaration (Loc,
4846 Defining_Identifier => P,
4847 Object_Definition =>
4848 New_Occurrence_Of (Designated_Type (Ent_Acc), Loc),
4850 Make_Aggregate (Loc, Expressions => Plist));
4853 Make_Attribute_Reference (Loc,
4854 Prefix => New_Occurrence_Of (P, Loc),
4855 Attribute_Name => Name_Address);
4857 Append (Pdecl, Decls);
4860 -- Now we can create the call, case of protected type
4862 if Is_Protected_Type (Conctyp) then
4863 case Corresponding_Runtime_Package (Conctyp) is
4864 when System_Tasking_Protected_Objects_Entries =>
4866 -- Change the type of the index declaration
4868 Set_Object_Definition (Xdecl,
4869 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc));
4871 -- Some additional declarations for protected entry calls
4877 -- Bnn : Communications_Block;
4879 Comm_Name := Make_Temporary (Loc, 'B');
4882 Make_Object_Declaration (Loc,
4883 Defining_Identifier => Comm_Name,
4884 Object_Definition =>
4886 (RTE (RE_Communication_Block), Loc)));
4888 -- Some additional statements for protected entry calls
4890 -- Protected_Entry_Call (
4891 -- Object => po._object'Access,
4892 -- E => <entry index>;
4893 -- Uninterpreted_Data => P'Address;
4894 -- Mode => Simple_Call;
4898 Make_Procedure_Call_Statement (Loc,
4900 New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
4902 Parameter_Associations => New_List (
4903 Make_Attribute_Reference (Loc,
4904 Attribute_Name => Name_Unchecked_Access,
4908 New_Occurrence_Of (RTE (RE_Simple_Call), Loc),
4909 New_Occurrence_Of (Comm_Name, Loc)));
4911 when System_Tasking_Protected_Objects_Single_Entry =>
4912 -- Protected_Single_Entry_Call (
4913 -- Object => po._object'Access,
4914 -- Uninterpreted_Data => P'Address);
4917 Make_Procedure_Call_Statement (Loc,
4918 Name => New_Occurrence_Of (
4919 RTE (RE_Protected_Single_Entry_Call), Loc),
4921 Parameter_Associations => New_List (
4922 Make_Attribute_Reference (Loc,
4923 Attribute_Name => Name_Unchecked_Access,
4928 raise Program_Error;
4931 -- Case of task type
4935 Make_Procedure_Call_Statement (Loc,
4936 Name => New_Occurrence_Of (RTE (RE_Call_Simple), Loc),
4937 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
4941 Append_To (Stats, Call);
4943 -- If there are out or in/out parameters by copy add assignment
4944 -- statements for the result values.
4946 if Present (Parms) then
4947 Actual := First_Actual (N);
4948 Formal := First_Formal (Ent);
4950 Set_Assignment_OK (Actual);
4951 while Present (Actual) loop
4952 if (Is_By_Copy_Type (Etype (Actual))
4953 or else Is_VM_By_Copy_Actual (Actual))
4954 and then Ekind (Formal) /= E_In_Parameter
4957 Make_Assignment_Statement (Loc,
4958 Name => New_Copy (Actual),
4960 Make_Explicit_Dereference (Loc,
4961 Make_Selected_Component (Loc,
4962 Prefix => New_Occurrence_Of (P, Loc),
4964 Make_Identifier (Loc, Chars (Formal)))));
4966 -- In all cases (including limited private types) we want
4967 -- the assignment to be valid.
4969 Set_Assignment_OK (Name (N_Node));
4971 -- If the call is the triggering alternative in an
4972 -- asynchronous select, or the entry_call alternative of a
4973 -- conditional entry call, the assignments for in-out
4974 -- parameters are incorporated into the statement list that
4975 -- follows, so that there are executed only if the entry
4978 if (Nkind (Parent (N)) = N_Triggering_Alternative
4979 and then N = Triggering_Statement (Parent (N)))
4981 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4982 and then N = Entry_Call_Statement (Parent (N)))
4984 if No (Statements (Parent (N))) then
4985 Set_Statements (Parent (N), New_List);
4988 Prepend (N_Node, Statements (Parent (N)));
4991 Insert_After (Call, N_Node);
4995 Next_Actual (Actual);
4996 Next_Formal_With_Extras (Formal);
5000 -- Finally, create block and analyze it
5003 Make_Block_Statement (Loc,
5004 Declarations => Decls,
5005 Handled_Statement_Sequence =>
5006 Make_Handled_Sequence_Of_Statements (Loc,
5007 Statements => Stats)));
5011 end Build_Simple_Entry_Call;
5013 --------------------------------
5014 -- Build_Task_Activation_Call --
5015 --------------------------------
5017 procedure Build_Task_Activation_Call (N : Node_Id) is
5018 Loc : constant Source_Ptr := Sloc (N);
5025 -- For sequential elaboration policy, all the tasks will be activated at
5026 -- the end of the elaboration.
5028 if Partition_Elaboration_Policy = 'S' then
5032 -- Get the activation chain entity. Except in the case of a package
5033 -- body, this is in the node that was passed. For a package body, we
5034 -- have to find the corresponding package declaration node.
5036 if Nkind (N) = N_Package_Body then
5037 P := Corresponding_Spec (N);
5040 exit when Nkind (P) = N_Package_Declaration;
5043 Chain := Activation_Chain_Entity (P);
5046 Chain := Activation_Chain_Entity (N);
5049 if Present (Chain) then
5050 if Restricted_Profile then
5051 Name := New_Occurrence_Of
5052 (RTE (RE_Activate_Restricted_Tasks), Loc);
5054 Name := New_Occurrence_Of
5055 (RTE (RE_Activate_Tasks), Loc);
5059 Make_Procedure_Call_Statement (Loc,
5061 Parameter_Associations =>
5062 New_List (Make_Attribute_Reference (Loc,
5063 Prefix => New_Occurrence_Of (Chain, Loc),
5064 Attribute_Name => Name_Unchecked_Access)));
5066 if Nkind (N) = N_Package_Declaration then
5067 if Present (Corresponding_Body (N)) then
5070 elsif Present (Private_Declarations (Specification (N))) then
5071 Append (Call, Private_Declarations (Specification (N)));
5074 Append (Call, Visible_Declarations (Specification (N)));
5078 if Present (Handled_Statement_Sequence (N)) then
5080 -- The call goes at the start of the statement sequence after
5081 -- the start of exception range label if one is present.
5087 Stm := First (Statements (Handled_Statement_Sequence (N)));
5089 -- A special case, skip exception range label if one is
5090 -- present (from front end zcx processing).
5092 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
5096 -- Another special case, if the first statement is a block
5097 -- from optimization of a local raise to a goto, then the
5098 -- call goes inside this block.
5100 if Nkind (Stm) = N_Block_Statement
5101 and then Exception_Junk (Stm)
5104 First (Statements (Handled_Statement_Sequence (Stm)));
5107 -- Insertion point is after any exception label pushes,
5108 -- since we want it covered by any local handlers.
5110 while Nkind (Stm) in N_Push_xxx_Label loop
5114 -- Now we have the proper insertion point
5116 Insert_Before (Stm, Call);
5120 Set_Handled_Statement_Sequence (N,
5121 Make_Handled_Sequence_Of_Statements (Loc,
5122 Statements => New_List (Call)));
5127 Check_Task_Activation (N);
5129 end Build_Task_Activation_Call;
5131 -------------------------------
5132 -- Build_Task_Allocate_Block --
5133 -------------------------------
5135 procedure Build_Task_Allocate_Block
5140 T : constant Entity_Id := Entity (Expression (N));
5141 Init : constant Entity_Id := Base_Init_Proc (T);
5142 Loc : constant Source_Ptr := Sloc (N);
5143 Chain : constant Entity_Id :=
5144 Make_Defining_Identifier (Loc, Name_uChain);
5145 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
5150 Make_Block_Statement (Loc,
5151 Identifier => New_Occurrence_Of (Blkent, Loc),
5152 Declarations => New_List (
5154 -- _Chain : Activation_Chain;
5156 Make_Object_Declaration (Loc,
5157 Defining_Identifier => Chain,
5158 Aliased_Present => True,
5159 Object_Definition =>
5160 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
5162 Handled_Statement_Sequence =>
5163 Make_Handled_Sequence_Of_Statements (Loc,
5165 Statements => New_List (
5169 Make_Procedure_Call_Statement (Loc,
5170 Name => New_Occurrence_Of (Init, Loc),
5171 Parameter_Associations => Args),
5173 -- Activate_Tasks (_Chain);
5175 Make_Procedure_Call_Statement (Loc,
5176 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
5177 Parameter_Associations => New_List (
5178 Make_Attribute_Reference (Loc,
5179 Prefix => New_Occurrence_Of (Chain, Loc),
5180 Attribute_Name => Name_Unchecked_Access))))),
5182 Has_Created_Identifier => True,
5183 Is_Task_Allocation_Block => True);
5186 Make_Implicit_Label_Declaration (Loc,
5187 Defining_Identifier => Blkent,
5188 Label_Construct => Block));
5190 Append_To (Actions, Block);
5192 Set_Activation_Chain_Entity (Block, Chain);
5193 end Build_Task_Allocate_Block;
5195 -----------------------------------------------
5196 -- Build_Task_Allocate_Block_With_Init_Stmts --
5197 -----------------------------------------------
5199 procedure Build_Task_Allocate_Block_With_Init_Stmts
5202 Init_Stmts : List_Id)
5204 Loc : constant Source_Ptr := Sloc (N);
5205 Chain : constant Entity_Id :=
5206 Make_Defining_Identifier (Loc, Name_uChain);
5207 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
5211 Append_To (Init_Stmts,
5212 Make_Procedure_Call_Statement (Loc,
5213 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
5214 Parameter_Associations => New_List (
5215 Make_Attribute_Reference (Loc,
5216 Prefix => New_Occurrence_Of (Chain, Loc),
5217 Attribute_Name => Name_Unchecked_Access))));
5220 Make_Block_Statement (Loc,
5221 Identifier => New_Occurrence_Of (Blkent, Loc),
5222 Declarations => New_List (
5224 -- _Chain : Activation_Chain;
5226 Make_Object_Declaration (Loc,
5227 Defining_Identifier => Chain,
5228 Aliased_Present => True,
5229 Object_Definition =>
5230 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
5232 Handled_Statement_Sequence =>
5233 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
5235 Has_Created_Identifier => True,
5236 Is_Task_Allocation_Block => True);
5239 Make_Implicit_Label_Declaration (Loc,
5240 Defining_Identifier => Blkent,
5241 Label_Construct => Block));
5243 Append_To (Actions, Block);
5245 Set_Activation_Chain_Entity (Block, Chain);
5246 end Build_Task_Allocate_Block_With_Init_Stmts;
5248 -----------------------------------
5249 -- Build_Task_Proc_Specification --
5250 -----------------------------------
5252 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
5253 Loc : constant Source_Ptr := Sloc (T);
5254 Spec_Id : Entity_Id;
5257 -- Case of explicit task type, suffix TB
5259 if Comes_From_Source (T) then
5261 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), "TB"));
5263 -- Case of anonymous task type, suffix B
5267 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), 'B'));
5270 Set_Is_Internal (Spec_Id);
5272 -- Associate the procedure with the task, if this is the declaration
5273 -- (and not the body) of the procedure.
5275 if No (Task_Body_Procedure (T)) then
5276 Set_Task_Body_Procedure (T, Spec_Id);
5280 Make_Procedure_Specification (Loc,
5281 Defining_Unit_Name => Spec_Id,
5282 Parameter_Specifications => New_List (
5283 Make_Parameter_Specification (Loc,
5284 Defining_Identifier =>
5285 Make_Defining_Identifier (Loc, Name_uTask),
5287 Make_Access_Definition (Loc,
5289 New_Occurrence_Of (Corresponding_Record_Type (T), Loc)))));
5290 end Build_Task_Proc_Specification;
5292 ---------------------------------------
5293 -- Build_Unprotected_Subprogram_Body --
5294 ---------------------------------------
5296 function Build_Unprotected_Subprogram_Body
5298 Pid : Node_Id) return Node_Id
5300 Decls : constant List_Id := Declarations (N);
5303 -- Add renamings for the Protection object, discriminals, privals and
5304 -- the entry index constant for use by debugger.
5306 Debug_Private_Data_Declarations (Decls);
5308 -- Make an unprotected version of the subprogram for use within the same
5309 -- object, with a new name and an additional parameter representing the
5313 Make_Subprogram_Body (Sloc (N),
5315 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
5316 Declarations => Decls,
5317 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
5318 end Build_Unprotected_Subprogram_Body;
5320 ----------------------------
5321 -- Collect_Entry_Families --
5322 ----------------------------
5324 procedure Collect_Entry_Families
5327 Current_Node : in out Node_Id;
5328 Conctyp : Entity_Id)
5331 Efam_Decl : Node_Id;
5332 Efam_Type : Entity_Id;
5335 Efam := First_Entity (Conctyp);
5336 while Present (Efam) loop
5337 if Ekind (Efam) = E_Entry_Family then
5338 Efam_Type := Make_Temporary (Loc, 'F');
5343 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
5345 Bas_Decl : Node_Id := Empty;
5350 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
5352 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
5353 Bas := Make_Temporary (Loc, 'B');
5356 Make_Subtype_Declaration (Loc,
5357 Defining_Identifier => Bas,
5358 Subtype_Indication =>
5359 Make_Subtype_Indication (Loc,
5361 New_Occurrence_Of (Standard_Integer, Loc),
5363 Make_Range_Constraint (Loc,
5364 Range_Expression => Make_Range (Loc,
5365 Make_Integer_Literal
5366 (Loc, -Entry_Family_Bound),
5367 Make_Integer_Literal
5368 (Loc, Entry_Family_Bound - 1)))));
5370 Insert_After (Current_Node, Bas_Decl);
5371 Current_Node := Bas_Decl;
5376 Make_Full_Type_Declaration (Loc,
5377 Defining_Identifier => Efam_Type,
5379 Make_Unconstrained_Array_Definition (Loc,
5381 (New_List (New_Occurrence_Of (Bas, Loc))),
5383 Component_Definition =>
5384 Make_Component_Definition (Loc,
5385 Aliased_Present => False,
5386 Subtype_Indication =>
5387 New_Occurrence_Of (Standard_Character, Loc))));
5390 Insert_After (Current_Node, Efam_Decl);
5391 Current_Node := Efam_Decl;
5392 Analyze (Efam_Decl);
5395 Make_Component_Declaration (Loc,
5396 Defining_Identifier =>
5397 Make_Defining_Identifier (Loc, Chars (Efam)),
5399 Component_Definition =>
5400 Make_Component_Definition (Loc,
5401 Aliased_Present => False,
5402 Subtype_Indication =>
5403 Make_Subtype_Indication (Loc,
5405 New_Occurrence_Of (Efam_Type, Loc),
5408 Make_Index_Or_Discriminant_Constraint (Loc,
5409 Constraints => New_List (
5411 (Etype (Discrete_Subtype_Definition
5412 (Parent (Efam))), Loc)))))));
5418 end Collect_Entry_Families;
5420 -----------------------
5421 -- Concurrent_Object --
5422 -----------------------
5424 function Concurrent_Object
5425 (Spec_Id : Entity_Id;
5426 Conc_Typ : Entity_Id) return Entity_Id
5429 -- Parameter _O or _object
5431 if Is_Protected_Type (Conc_Typ) then
5432 return First_Formal (Protected_Body_Subprogram (Spec_Id));
5437 pragma Assert (Is_Task_Type (Conc_Typ));
5438 return First_Formal (Task_Body_Procedure (Conc_Typ));
5440 end Concurrent_Object;
5442 ----------------------
5443 -- Copy_Result_Type --
5444 ----------------------
5446 function Copy_Result_Type (Res : Node_Id) return Node_Id is
5447 New_Res : constant Node_Id := New_Copy_Tree (Res);
5452 -- If the result type is an access_to_subprogram, we must create new
5453 -- entities for its spec.
5455 if Nkind (New_Res) = N_Access_Definition
5456 and then Present (Access_To_Subprogram_Definition (New_Res))
5458 -- Provide new entities for the formals
5460 Par_Spec := First (Parameter_Specifications
5461 (Access_To_Subprogram_Definition (New_Res)));
5462 while Present (Par_Spec) loop
5463 Formal := Defining_Identifier (Par_Spec);
5464 Set_Defining_Identifier (Par_Spec,
5465 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
5471 end Copy_Result_Type;
5473 --------------------
5474 -- Concurrent_Ref --
5475 --------------------
5477 -- The expression returned for a reference to a concurrent object has the
5480 -- taskV!(name)._Task_Id
5484 -- objectV!(name)._Object
5486 -- for a protected object. For the case of an access to a concurrent
5487 -- object, there is an extra explicit dereference:
5489 -- taskV!(name.all)._Task_Id
5490 -- objectV!(name.all)._Object
5492 -- here taskV and objectV are the types for the associated records, which
5493 -- contain the required _Task_Id and _Object fields for tasks and protected
5494 -- objects, respectively.
5496 -- For the case of a task type name, the expression is
5500 -- i.e. a call to the Self function which returns precisely this Task_Id
5502 -- For the case of a protected type name, the expression is
5506 -- which is a renaming of the _object field of the current object
5507 -- record, passed into protected operations as a parameter.
5509 function Concurrent_Ref (N : Node_Id) return Node_Id is
5510 Loc : constant Source_Ptr := Sloc (N);
5511 Ntyp : constant Entity_Id := Etype (N);
5515 function Is_Current_Task (T : Entity_Id) return Boolean;
5516 -- Check whether the reference is to the immediately enclosing task
5517 -- type, or to an outer one (rare but legal).
5519 ---------------------
5520 -- Is_Current_Task --
5521 ---------------------
5523 function Is_Current_Task (T : Entity_Id) return Boolean is
5527 Scop := Current_Scope;
5528 while Present (Scop)
5529 and then Scop /= Standard_Standard
5535 elsif Is_Task_Type (Scop) then
5538 -- If this is a procedure nested within the task type, we must
5539 -- assume that it can be called from an inner task, and therefore
5540 -- cannot treat it as a local reference.
5542 elsif Is_Overloadable (Scop) and then In_Open_Scopes (T) then
5546 Scop := Scope (Scop);
5550 -- We know that we are within the task body, so should have found it
5553 raise Program_Error;
5554 end Is_Current_Task;
5556 -- Start of processing for Concurrent_Ref
5559 if Is_Access_Type (Ntyp) then
5560 Dtyp := Designated_Type (Ntyp);
5562 if Is_Protected_Type (Dtyp) then
5563 Sel := Name_uObject;
5565 Sel := Name_uTask_Id;
5569 Make_Selected_Component (Loc,
5571 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
5572 Make_Explicit_Dereference (Loc, N)),
5573 Selector_Name => Make_Identifier (Loc, Sel));
5575 elsif Is_Entity_Name (N) and then Is_Concurrent_Type (Entity (N)) then
5576 if Is_Task_Type (Entity (N)) then
5578 if Is_Current_Task (Entity (N)) then
5580 Make_Function_Call (Loc,
5581 Name => New_Occurrence_Of (RTE (RE_Self), Loc));
5586 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
5587 T_Body : constant Node_Id :=
5588 Parent (Corresponding_Body (Parent (Entity (N))));
5592 Make_Object_Declaration (Loc,
5593 Defining_Identifier => T_Self,
5594 Object_Definition =>
5595 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
5597 Make_Function_Call (Loc,
5598 Name => New_Occurrence_Of (RTE (RE_Self), Loc)));
5599 Prepend (Decl, Declarations (T_Body));
5601 Set_Scope (T_Self, Entity (N));
5602 return New_Occurrence_Of (T_Self, Loc);
5607 pragma Assert (Is_Protected_Type (Entity (N)));
5610 New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc);
5614 if Is_Protected_Type (Ntyp) then
5615 Sel := Name_uObject;
5617 elsif Is_Task_Type (Ntyp) then
5618 Sel := Name_uTask_Id;
5621 raise Program_Error;
5625 Make_Selected_Component (Loc,
5627 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
5629 Selector_Name => Make_Identifier (Loc, Sel));
5633 ------------------------
5634 -- Convert_Concurrent --
5635 ------------------------
5637 function Convert_Concurrent
5639 Typ : Entity_Id) return Node_Id
5642 if not Is_Concurrent_Type (Typ) then
5646 Unchecked_Convert_To
5647 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
5649 end Convert_Concurrent;
5651 -------------------------------------
5652 -- Debug_Private_Data_Declarations --
5653 -------------------------------------
5655 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
5656 Debug_Nod : Node_Id;
5660 Decl := First (Decls);
5661 while Present (Decl) and then not Comes_From_Source (Decl) loop
5662 -- Declaration for concurrent entity _object and its access type,
5663 -- along with the entry index subtype:
5664 -- type prot_typVP is access prot_typV;
5665 -- _object : prot_typVP := prot_typV (_O);
5666 -- subtype Jnn is <Type of Index> range Low .. High;
5668 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
5669 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5671 -- Declaration for the Protection object, discriminals, privals and
5672 -- entry index constant:
5673 -- conc_typR : protection_typ renames _object._object;
5674 -- discr_nameD : discr_typ renames _object.discr_name;
5675 -- discr_nameD : discr_typ renames _task.discr_name;
5676 -- prival_name : comp_typ renames _object.comp_name;
5677 -- J : constant Jnn :=
5678 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5680 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
5681 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5682 Debug_Nod := Debug_Renaming_Declaration (Decl);
5684 if Present (Debug_Nod) then
5685 Insert_After (Decl, Debug_Nod);
5691 end Debug_Private_Data_Declarations;
5693 ------------------------------
5694 -- Ensure_Statement_Present --
5695 ------------------------------
5697 procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id) is
5701 if Opt.Suppress_Control_Flow_Optimizations
5702 and then Is_Empty_List (Statements (Alt))
5704 Stmt := Make_Null_Statement (Loc);
5706 -- Mark NULL statement as coming from source so that it is not
5707 -- eliminated by GIGI.
5709 -- Another covert channel. If this is a requirement, it must be
5710 -- documented in sinfo/einfo ???
5712 Set_Comes_From_Source (Stmt, True);
5714 Set_Statements (Alt, New_List (Stmt));
5716 end Ensure_Statement_Present;
5718 ----------------------------
5719 -- Entry_Index_Expression --
5720 ----------------------------
5722 function Entry_Index_Expression
5726 Ttyp : Entity_Id) return Node_Id
5736 -- The queues of entries and entry families appear in textual order in
5737 -- the associated record. The entry index is computed as the sum of the
5738 -- number of queues for all entries that precede the designated one, to
5739 -- which is added the index expression, if this expression denotes a
5740 -- member of a family.
5742 -- The following is a place holder for the count of simple entries
5744 Num := Make_Integer_Literal (Sloc, 1);
5746 -- We construct an expression which is a series of addition operations.
5747 -- The first operand is the number of single entries that precede this
5748 -- one, the second operand is the index value relative to the start of
5749 -- the referenced family, and the remaining operands are the lengths of
5750 -- the entry families that precede this entry, i.e. the constructed
5753 -- number_simple_entries +
5754 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5755 -- family'length + ...
5757 -- where index-value is the given index value, and s is the index
5758 -- subtype (we have to use pos because the subtype might be an
5759 -- enumeration type preventing direct subtraction). Note that the task
5760 -- entry array is one-indexed.
5762 -- The upper bound of the entry family may be a discriminant, so we
5763 -- retrieve the lower bound explicitly to compute offset, rather than
5764 -- using the index subtype which may mention a discriminant.
5766 if Present (Index) then
5767 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
5776 Make_Attribute_Reference (Sloc,
5777 Attribute_Name => Name_Pos,
5778 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
5779 Expressions => New_List (Relocate_Node (Index))),
5787 -- Now add lengths of preceding entries and entry families
5789 Prev := First_Entity (Ttyp);
5791 while Chars (Prev) /= Chars (Ent)
5792 or else (Ekind (Prev) /= Ekind (Ent))
5793 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
5795 if Ekind (Prev) = E_Entry then
5796 Set_Intval (Num, Intval (Num) + 1);
5798 elsif Ekind (Prev) = E_Entry_Family then
5800 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
5801 Lo := Type_Low_Bound (S);
5802 Hi := Type_High_Bound (S);
5807 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
5809 -- Other components are anonymous types to be ignored
5819 end Entry_Index_Expression;
5821 ---------------------------
5822 -- Establish_Task_Master --
5823 ---------------------------
5825 procedure Establish_Task_Master (N : Node_Id) is
5829 if Restriction_Active (No_Task_Hierarchy) = False then
5830 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
5832 -- The block may have no declarations (and nevertheless be a task
5833 -- master) if it contains a call that may return an object that
5836 if No (Declarations (N)) then
5837 Set_Declarations (N, New_List (Call));
5839 Prepend_To (Declarations (N), Call);
5844 end Establish_Task_Master;
5846 --------------------------------
5847 -- Expand_Accept_Declarations --
5848 --------------------------------
5850 -- Part of the expansion of an accept statement involves the creation of
5851 -- a declaration that can be referenced from the statement sequence of
5856 -- This declaration is inserted immediately before the accept statement
5857 -- and it is important that it be inserted before the statements of the
5858 -- statement sequence are analyzed. Thus it would be too late to create
5859 -- this declaration in the Expand_N_Accept_Statement routine, which is
5860 -- why there is a separate procedure to be called directly from Sem_Ch9.
5862 -- Ann is used to hold the address of the record containing the parameters
5863 -- (see Expand_N_Entry_Call for more details on how this record is built).
5864 -- References to the parameters do an unchecked conversion of this address
5865 -- to a pointer to the required record type, and then access the field that
5866 -- holds the value of the required parameter. The entity for the address
5867 -- variable is held as the top stack element (i.e. the last element) of the
5868 -- Accept_Address stack in the corresponding entry entity, and this element
5869 -- must be set in place before the statements are processed.
5871 -- The above description applies to the case of a stand alone accept
5872 -- statement, i.e. one not appearing as part of a select alternative.
5874 -- For the case of an accept that appears as part of a select alternative
5875 -- of a selective accept, we must still create the declaration right away,
5876 -- since Ann is needed immediately, but there is an important difference:
5878 -- The declaration is inserted before the selective accept, not before
5879 -- the accept statement (which is not part of a list anyway, and so would
5880 -- not accommodate inserted declarations)
5882 -- We only need one address variable for the entire selective accept. So
5883 -- the Ann declaration is created only for the first accept alternative,
5884 -- and subsequent accept alternatives reference the same Ann variable.
5886 -- We can distinguish the two cases by seeing whether the accept statement
5887 -- is part of a list. If not, then it must be in an accept alternative.
5889 -- To expand the requeue statement, a label is provided at the end of the
5890 -- accept statement or alternative of which it is a part, so that the
5891 -- statement can be skipped after the requeue is complete. This label is
5892 -- created here rather than during the expansion of the accept statement,
5893 -- because it will be needed by any requeue statements within the accept,
5894 -- which are expanded before the accept.
5896 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
5897 Loc : constant Source_Ptr := Sloc (N);
5898 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5899 Ann : Entity_Id := Empty;
5906 if Expander_Active then
5908 -- If we have no handled statement sequence, we may need to build
5909 -- a dummy sequence consisting of a null statement. This can be
5910 -- skipped if the trivial accept optimization is permitted.
5912 if not Trivial_Accept_OK
5914 (No (Stats) or else Null_Statements (Statements (Stats)))
5916 Set_Handled_Statement_Sequence (N,
5917 Make_Handled_Sequence_Of_Statements (Loc,
5918 Statements => New_List (Make_Null_Statement (Loc))));
5921 -- Create and declare two labels to be placed at the end of the
5922 -- accept statement. The first label is used to allow requeues to
5923 -- skip the remainder of entry processing. The second label is used
5924 -- to skip the remainder of entry processing if the rendezvous
5925 -- completes in the middle of the accept body.
5927 if Present (Handled_Statement_Sequence (N)) then
5932 Ent := Make_Temporary (Loc, 'L');
5933 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5935 Make_Implicit_Label_Declaration (Loc,
5936 Defining_Identifier => Ent,
5937 Label_Construct => Lab);
5938 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5940 Ent := Make_Temporary (Loc, 'L');
5941 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5943 Make_Implicit_Label_Declaration (Loc,
5944 Defining_Identifier => Ent,
5945 Label_Construct => Lab);
5946 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5954 -- Case of stand alone accept statement
5956 if Is_List_Member (N) then
5958 if Present (Handled_Statement_Sequence (N)) then
5959 Ann := Make_Temporary (Loc, 'A');
5962 Make_Object_Declaration (Loc,
5963 Defining_Identifier => Ann,
5964 Object_Definition =>
5965 New_Occurrence_Of (RTE (RE_Address), Loc));
5967 Insert_Before_And_Analyze (N, Adecl);
5968 Insert_Before_And_Analyze (N, Ldecl);
5969 Insert_Before_And_Analyze (N, Ldecl2);
5972 -- Case of accept statement which is in an accept alternative
5976 Acc_Alt : constant Node_Id := Parent (N);
5977 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
5981 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
5982 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
5984 -- ??? Consider a single label for select statements
5986 if Present (Handled_Statement_Sequence (N)) then
5988 Statements (Handled_Statement_Sequence (N)));
5992 Statements (Handled_Statement_Sequence (N)));
5996 -- Find first accept alternative of the selective accept. A
5997 -- valid selective accept must have at least one accept in it.
5999 Alt := First (Select_Alternatives (Sel_Acc));
6001 while Nkind (Alt) /= N_Accept_Alternative loop
6005 -- If this is the first accept statement, then we have to
6006 -- create the Ann variable, as for the stand alone case, except
6007 -- that it is inserted before the selective accept. Similarly,
6008 -- a label for requeue expansion must be declared.
6010 if N = Accept_Statement (Alt) then
6011 Ann := Make_Temporary (Loc, 'A');
6013 Make_Object_Declaration (Loc,
6014 Defining_Identifier => Ann,
6015 Object_Definition =>
6016 New_Occurrence_Of (RTE (RE_Address), Loc));
6018 Insert_Before_And_Analyze (Sel_Acc, Adecl);
6020 -- If this is not the first accept statement, then find the Ann
6021 -- variable allocated by the first accept and use it.
6025 Node (Last_Elmt (Accept_Address
6026 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
6031 -- Merge here with Ann either created or referenced, and Adecl
6032 -- pointing to the corresponding declaration. Remaining processing
6033 -- is the same for the two cases.
6035 if Present (Ann) then
6036 Append_Elmt (Ann, Accept_Address (Ent));
6037 Set_Debug_Info_Needed (Ann);
6040 -- Create renaming declarations for the entry formals. Each reference
6041 -- to a formal becomes a dereference of a component of the parameter
6042 -- block, whose address is held in Ann. These declarations are
6043 -- eventually inserted into the accept block, and analyzed there so
6044 -- that they have the proper scope for gdb and do not conflict with
6045 -- other declarations.
6047 if Present (Parameter_Specifications (N))
6048 and then Present (Handled_Statement_Sequence (N))
6055 Renamed_Formal : Node_Id;
6059 Formal := First_Formal (Ent);
6061 while Present (Formal) loop
6062 Comp := Entry_Component (Formal);
6063 New_F := Make_Defining_Identifier (Loc, Chars (Formal));
6065 Set_Etype (New_F, Etype (Formal));
6066 Set_Scope (New_F, Ent);
6068 -- Now we set debug info needed on New_F even though it does
6069 -- not come from source, so that the debugger will get the
6070 -- right information for these generated names.
6072 Set_Debug_Info_Needed (New_F);
6074 if Ekind (Formal) = E_In_Parameter then
6075 Set_Ekind (New_F, E_Constant);
6077 Set_Ekind (New_F, E_Variable);
6078 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
6081 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
6084 Make_Selected_Component (Loc,
6086 Unchecked_Convert_To (
6087 Entry_Parameters_Type (Ent),
6088 New_Occurrence_Of (Ann, Loc)),
6090 New_Occurrence_Of (Comp, Loc));
6093 Build_Renamed_Formal_Declaration
6094 (New_F, Formal, Comp, Renamed_Formal);
6096 if No (Declarations (N)) then
6097 Set_Declarations (N, New_List);
6100 Append (Decl, Declarations (N));
6101 Set_Renamed_Object (Formal, New_F);
6102 Next_Formal (Formal);
6109 end Expand_Accept_Declarations;
6111 ---------------------------------------------
6112 -- Expand_Access_Protected_Subprogram_Type --
6113 ---------------------------------------------
6115 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
6116 Loc : constant Source_Ptr := Sloc (N);
6118 T : constant Entity_Id := Defining_Identifier (N);
6119 D_T : constant Entity_Id := Designated_Type (T);
6120 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
6121 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
6122 P_List : constant List_Id := Build_Protected_Spec
6123 (N, RTE (RE_Address), D_T, False);
6129 -- Create access to subprogram with full signature
6131 if Etype (D_T) /= Standard_Void_Type then
6133 Make_Access_Function_Definition (Loc,
6134 Parameter_Specifications => P_List,
6135 Result_Definition =>
6136 Copy_Result_Type (Result_Definition (Type_Definition (N))));
6140 Make_Access_Procedure_Definition (Loc,
6141 Parameter_Specifications => P_List);
6145 Make_Full_Type_Declaration (Loc,
6146 Defining_Identifier => D_T2,
6147 Type_Definition => Def1);
6149 Insert_After_And_Analyze (N, Decl1);
6151 -- Associate the access to subprogram with its original access to
6152 -- protected subprogram type. Needed by the backend to know that this
6153 -- type corresponds with an access to protected subprogram type.
6155 Set_Original_Access_Type (D_T2, T);
6157 -- Create Equivalent_Type, a record with two components for an access to
6158 -- object and an access to subprogram.
6161 Make_Component_Declaration (Loc,
6162 Defining_Identifier => Make_Temporary (Loc, 'P'),
6163 Component_Definition =>
6164 Make_Component_Definition (Loc,
6165 Aliased_Present => False,
6166 Subtype_Indication =>
6167 New_Occurrence_Of (RTE (RE_Address), Loc))),
6169 Make_Component_Declaration (Loc,
6170 Defining_Identifier => Make_Temporary (Loc, 'S'),
6171 Component_Definition =>
6172 Make_Component_Definition (Loc,
6173 Aliased_Present => False,
6174 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
6177 Make_Full_Type_Declaration (Loc,
6178 Defining_Identifier => E_T,
6180 Make_Record_Definition (Loc,
6182 Make_Component_List (Loc, Component_Items => Comps)));
6184 Insert_After_And_Analyze (Decl1, Decl2);
6185 Set_Equivalent_Type (T, E_T);
6186 end Expand_Access_Protected_Subprogram_Type;
6188 --------------------------
6189 -- Expand_Entry_Barrier --
6190 --------------------------
6192 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
6193 Cond : constant Node_Id :=
6194 Condition (Entry_Body_Formal_Part (N));
6195 Prot : constant Entity_Id := Scope (Ent);
6196 Spec_Decl : constant Node_Id := Parent (Prot);
6199 Body_Decl : Node_Id;
6201 function Is_Global_Entity (N : Node_Id) return Traverse_Result;
6202 -- Check whether entity in Barrier is external to protected type.
6203 -- If so, barrier may not be properly synchronized.
6205 ----------------------
6206 -- Is_Global_Entity --
6207 ----------------------
6209 function Is_Global_Entity (N : Node_Id) return Traverse_Result is
6214 if Is_Entity_Name (N) and then Present (Entity (N)) then
6218 if Ekind (E) = E_Variable then
6219 if Scope (E) = Func then
6222 -- A protected call from a barrier to another object is ok
6224 elsif Ekind (Etype (E)) = E_Protected_Type then
6227 -- If the variable is within the package body we consider
6228 -- this safe. This is a common (if dubious) idiom.
6230 elsif S = Scope (Prot)
6231 and then Ekind_In (S, E_Package, E_Generic_Package)
6232 and then Nkind (Parent (E)) = N_Object_Declaration
6233 and then Nkind (Parent (Parent (E))) = N_Package_Body
6238 Error_Msg_N ("potentially unsynchronized barrier??", N);
6239 Error_Msg_N ("\& should be private component of type??", N);
6245 end Is_Global_Entity;
6247 procedure Check_Unprotected_Barrier is
6248 new Traverse_Proc (Is_Global_Entity);
6250 -- Start of processing for Expand_Entry_Barrier
6253 if No_Run_Time_Mode then
6254 Error_Msg_CRT ("entry barrier", N);
6258 -- The body of the entry barrier must be analyzed in the context of the
6259 -- protected object, but its scope is external to it, just as any other
6260 -- unprotected version of a protected operation. The specification has
6261 -- been produced when the protected type declaration was elaborated. We
6262 -- build the body, insert it in the enclosing scope, but analyze it in
6263 -- the current context. A more uniform approach would be to treat the
6264 -- barrier just as a protected function, and discard the protected
6265 -- version of it because it is never called.
6267 if Expander_Active then
6268 B_F := Build_Barrier_Function (N, Ent, Prot);
6269 Func := Barrier_Function (Ent);
6270 Set_Corresponding_Spec (B_F, Func);
6272 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
6274 if Nkind (Parent (Body_Decl)) = N_Subunit then
6275 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
6278 Insert_Before_And_Analyze (Body_Decl, B_F);
6280 Set_Discriminals (Spec_Decl);
6281 Set_Scope (Func, Scope (Prot));
6284 Analyze_And_Resolve (Cond, Any_Boolean);
6287 -- The Ravenscar profile restricts barriers to simple variables declared
6288 -- within the protected object. We also allow Boolean constants, since
6289 -- these appear in several published examples and are also allowed by
6292 -- Note that after analysis variables in this context will be replaced
6293 -- by the corresponding prival, that is to say a renaming of a selected
6294 -- component of the form _Object.Var. If expansion is disabled, as
6295 -- within a generic, we check that the entity appears in the current
6298 if Is_Entity_Name (Cond) then
6300 -- A small optimization of useless renamings. If the scope of the
6301 -- entity of the condition is not the barrier function, then the
6302 -- condition does not reference any of the generated renamings
6303 -- within the function.
6305 if Expander_Active and then Scope (Entity (Cond)) /= Func then
6306 Set_Declarations (B_F, Empty_List);
6309 if Entity (Cond) = Standard_False
6311 Entity (Cond) = Standard_True
6315 elsif not Expander_Active
6316 and then Scope (Entity (Cond)) = Current_Scope
6320 -- Check for case of _object.all.field (note that the explicit
6321 -- dereference gets inserted by analyze/expand of _object.field)
6323 elsif Present (Renamed_Object (Entity (Cond)))
6325 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
6329 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
6335 -- It is not a boolean variable or literal, so check the restriction.
6336 -- Note that it is safe to be calling Check_Restriction from here, even
6337 -- though this is part of the expander, since Expand_Entry_Barrier is
6338 -- called from Sem_Ch9 even in -gnatc mode.
6340 Check_Restriction (Simple_Barriers, Cond);
6342 -- Emit warning if barrier contains global entities and is thus
6343 -- potentially unsynchronized.
6345 Check_Unprotected_Barrier (Cond);
6346 end Expand_Entry_Barrier;
6348 ------------------------------
6349 -- Expand_N_Abort_Statement --
6350 ------------------------------
6352 -- Expand abort T1, T2, .. Tn; into:
6353 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6355 procedure Expand_N_Abort_Statement (N : Node_Id) is
6356 Loc : constant Source_Ptr := Sloc (N);
6357 Tlist : constant List_Id := Names (N);
6363 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
6366 Tasknm := First (Tlist);
6368 while Present (Tasknm) loop
6371 -- A task interface class-wide type object is being aborted. Retrieve
6372 -- its _task_id by calling a dispatching routine.
6374 if Ada_Version >= Ada_2005
6375 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
6376 and then Is_Interface (Etype (Tasknm))
6377 and then Is_Task_Interface (Etype (Tasknm))
6379 Append_To (Component_Associations (Aggr),
6380 Make_Component_Association (Loc,
6381 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6384 -- Task_Id (Tasknm._disp_get_task_id)
6386 Make_Unchecked_Type_Conversion (Loc,
6388 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
6390 Make_Selected_Component (Loc,
6391 Prefix => New_Copy_Tree (Tasknm),
6393 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
6396 Append_To (Component_Associations (Aggr),
6397 Make_Component_Association (Loc,
6398 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6399 Expression => Concurrent_Ref (Tasknm)));
6406 Make_Procedure_Call_Statement (Loc,
6407 Name => New_Occurrence_Of (RTE (RE_Abort_Tasks), Loc),
6408 Parameter_Associations => New_List (
6409 Make_Qualified_Expression (Loc,
6410 Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_List), Loc),
6411 Expression => Aggr))));
6414 end Expand_N_Abort_Statement;
6416 -------------------------------
6417 -- Expand_N_Accept_Statement --
6418 -------------------------------
6420 -- This procedure handles expansion of accept statements that stand alone,
6421 -- i.e. they are not part of an accept alternative. The expansion of
6422 -- accept statement in accept alternatives is handled by the routines
6423 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6424 -- following description applies only to stand alone accept statements.
6426 -- If there is no handled statement sequence, or only null statements, then
6427 -- this is called a trivial accept, and the expansion is:
6429 -- Accept_Trivial (entry-index)
6431 -- If there is a handled statement sequence, then the expansion is:
6438 -- Accept_Call (entry-index, Ann);
6439 -- Renaming_Declarations for formals
6440 -- <statement sequence from N_Accept_Statement node>
6441 -- Complete_Rendezvous;
6446 -- <exception handler from N_Accept_Statement node>
6447 -- Complete_Rendezvous;
6449 -- <exception handler from N_Accept_Statement node>
6450 -- Complete_Rendezvous;
6455 -- when all others =>
6456 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6459 -- The first three declarations were already inserted ahead of the accept
6460 -- statement by the Expand_Accept_Declarations procedure, which was called
6461 -- directly from the semantics during analysis of the accept statement,
6462 -- before analyzing its contained statements.
6464 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6465 -- from possible expansion activity (the original source of course does
6466 -- not have any declarations associated with the accept statement, since
6467 -- an accept statement has no declarative part). In particular, if the
6468 -- expander is active, the first such declaration is the declaration of
6469 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6471 -- The two blocks are merged into a single block if the inner block has
6472 -- no exception handlers, but otherwise two blocks are required, since
6473 -- exceptions might be raised in the exception handlers of the inner
6474 -- block, and Exceptional_Complete_Rendezvous must be called.
6476 procedure Expand_N_Accept_Statement (N : Node_Id) is
6477 Loc : constant Source_Ptr := Sloc (N);
6478 Stats : constant Node_Id := Handled_Statement_Sequence (N);
6479 Ename : constant Node_Id := Entry_Direct_Name (N);
6480 Eindx : constant Node_Id := Entry_Index (N);
6481 Eent : constant Entity_Id := Entity (Ename);
6482 Acstack : constant Elist_Id := Accept_Address (Eent);
6483 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
6484 Ttyp : constant Entity_Id := Etype (Scope (Eent));
6490 -- If the accept statement is not part of a list, then its parent must
6491 -- be an accept alternative, and, as described above, we do not do any
6492 -- expansion for such accept statements at this level.
6494 if not Is_List_Member (N) then
6495 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
6498 -- Trivial accept case (no statement sequence, or null statements).
6499 -- If the accept statement has declarations, then just insert them
6500 -- before the procedure call.
6502 elsif Trivial_Accept_OK
6503 and then (No (Stats) or else Null_Statements (Statements (Stats)))
6505 -- Remove declarations for renamings, because the parameter block
6506 -- will not be assigned.
6513 D := First (Declarations (N));
6514 while Present (D) loop
6516 if Nkind (D) = N_Object_Renaming_Declaration then
6524 if Present (Declarations (N)) then
6525 Insert_Actions (N, Declarations (N));
6529 Make_Procedure_Call_Statement (Loc,
6530 Name => New_Occurrence_Of (RTE (RE_Accept_Trivial), Loc),
6531 Parameter_Associations => New_List (
6532 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
6536 -- Discard Entry_Address that was created for it, so it will not be
6537 -- emitted if this accept statement is in the statement part of a
6538 -- delay alternative.
6540 if Present (Stats) then
6541 Remove_Last_Elmt (Acstack);
6544 -- Case of statement sequence present
6547 -- Construct the block, using the declarations from the accept
6548 -- statement if any to initialize the declarations of the block.
6550 Blkent := Make_Temporary (Loc, 'A');
6551 Set_Ekind (Blkent, E_Block);
6552 Set_Etype (Blkent, Standard_Void_Type);
6553 Set_Scope (Blkent, Current_Scope);
6556 Make_Block_Statement (Loc,
6557 Identifier => New_Occurrence_Of (Blkent, Loc),
6558 Declarations => Declarations (N),
6559 Handled_Statement_Sequence => Build_Accept_Body (N));
6561 -- For the analysis of the generated declarations, the parent node
6562 -- must be properly set.
6564 Set_Parent (Block, Parent (N));
6566 -- Prepend call to Accept_Call to main statement sequence If the
6567 -- accept has exception handlers, the statement sequence is wrapped
6568 -- in a block. Insert call and renaming declarations in the
6569 -- declarations of the block, so they are elaborated before the
6573 Make_Procedure_Call_Statement (Loc,
6574 Name => New_Occurrence_Of (RTE (RE_Accept_Call), Loc),
6575 Parameter_Associations => New_List (
6576 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
6577 New_Occurrence_Of (Ann, Loc)));
6579 if Parent (Stats) = N then
6580 Prepend (Call, Statements (Stats));
6582 Set_Declarations (Parent (Stats), New_List (Call));
6587 Push_Scope (Blkent);
6595 D := First (Declarations (N));
6596 while Present (D) loop
6599 if Nkind (D) = N_Object_Renaming_Declaration then
6601 -- The renaming declarations for the formals were created
6602 -- during analysis of the accept statement, and attached to
6603 -- the list of declarations. Place them now in the context
6604 -- of the accept block or subprogram.
6607 Typ := Entity (Subtype_Mark (D));
6608 Insert_After (Call, D);
6611 -- If the formal is class_wide, it does not have an actual
6612 -- subtype. The analysis of the renaming declaration creates
6613 -- one, but we need to retain the class-wide nature of the
6616 if Is_Class_Wide_Type (Typ) then
6617 Set_Etype (Defining_Identifier (D), Typ);
6628 -- Replace the accept statement by the new block
6633 -- Last step is to unstack the Accept_Address value
6635 Remove_Last_Elmt (Acstack);
6637 end Expand_N_Accept_Statement;
6639 ----------------------------------
6640 -- Expand_N_Asynchronous_Select --
6641 ----------------------------------
6643 -- This procedure assumes that the trigger statement is an entry call or
6644 -- a dispatching procedure call. A delay alternative should already have
6645 -- been expanded into an entry call to the appropriate delay object Wait
6648 -- If the trigger is a task entry call, the select is implemented with
6649 -- a Task_Entry_Call:
6654 -- P : parms := (parm, parm, parm);
6656 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6658 -- procedure _clean is
6661 -- Cancel_Task_Entry_Call (C);
6668 -- (<acceptor-task>, -- Acceptor
6669 -- <entry-index>, -- E
6670 -- P'Address, -- Uninterpreted_Data
6671 -- Asynchronous_Call, -- Mode
6672 -- B); -- Rendezvous_Successful
6679 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6682 -- when Abort_Signal => Abort_Undefer;
6689 -- <triggered-statements>
6693 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6694 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6698 -- P : parms := (parm, parm, parm);
6700 -- Call_Simple (acceptor-task, entry-index, P'Address);
6706 -- so the task at hand is to convert the latter expansion into the former
6708 -- If the trigger is a protected entry call, the select is implemented
6709 -- with Protected_Entry_Call:
6712 -- P : E1_Params := (param, param, param);
6713 -- Bnn : Communications_Block;
6718 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6720 -- procedure _clean is
6723 -- if Enqueued (Bnn) then
6724 -- Cancel_Protected_Entry_Call (Bnn);
6731 -- Protected_Entry_Call
6732 -- (po._object'Access, -- Object
6733 -- <entry index>, -- E
6734 -- P'Address, -- Uninterpreted_Data
6735 -- Asynchronous_Call, -- Mode
6738 -- if Enqueued (Bnn) then
6742 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6745 -- when Abort_Signal => Abort_Undefer;
6748 -- if not Cancelled (Bnn) then
6749 -- <triggered-statements>
6753 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6757 -- P : E1_Params := (param, param, param);
6758 -- Bnn : Communications_Block;
6761 -- Protected_Entry_Call
6762 -- (po._object'Access, -- Object
6763 -- <entry index>, -- E
6764 -- P'Address, -- Uninterpreted_Data
6765 -- Simple_Call, -- Mode
6772 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6776 -- B : Boolean := False;
6777 -- Bnn : Communication_Block;
6778 -- C : Ada.Tags.Prim_Op_Kind;
6779 -- D : System.Storage_Elements.Dummy_Communication_Block;
6780 -- K : Ada.Tags.Tagged_Kind :=
6781 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6782 -- P : Parameters := (Param1 .. ParamN);
6787 -- if K = Ada.Tags.TK_Limited_Tagged
6788 -- or else K = Ada.Tags.TK_Tagged
6790 -- <dispatching-call>;
6791 -- <triggering-statements>;
6795 -- Ada.Tags.Get_Offset_Index
6796 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6798 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6800 -- if C = POK_Protected_Entry then
6802 -- procedure _clean is
6804 -- if Enqueued (Bnn) then
6805 -- Cancel_Protected_Entry_Call (Bnn);
6811 -- _Disp_Asynchronous_Select
6812 -- (<object>, S, P'Address, D, B);
6813 -- Bnn := Communication_Block (D);
6815 -- Param1 := P.Param1;
6817 -- ParamN := P.ParamN;
6819 -- if Enqueued (Bnn) then
6820 -- <abortable-statements>
6823 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6826 -- when Abort_Signal => Abort_Undefer;
6829 -- if not Cancelled (Bnn) then
6830 -- <triggering-statements>
6833 -- elsif C = POK_Task_Entry then
6835 -- procedure _clean is
6837 -- Cancel_Task_Entry_Call (U);
6843 -- _Disp_Asynchronous_Select
6844 -- (<object>, S, P'Address, D, B);
6845 -- Bnn := Communication_Bloc (D);
6847 -- Param1 := P.Param1;
6849 -- ParamN := P.ParamN;
6854 -- <abortable-statements>
6856 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6859 -- when Abort_Signal => Abort_Undefer;
6863 -- <triggering-statements>
6868 -- <dispatching-call>;
6869 -- <triggering-statements>
6874 -- The job is to convert this to the asynchronous form
6876 -- If the trigger is a delay statement, it will have been expanded into
6877 -- a call to one of the GNARL delay procedures. This routine will convert
6878 -- this into a protected entry call on a delay object and then continue
6879 -- processing as for a protected entry call trigger. This requires
6880 -- declaring a Delay_Block object and adding a pointer to this object to
6881 -- the parameter list of the delay procedure to form the parameter list of
6882 -- the entry call. This object is used by the runtime to queue the delay
6885 -- For a description of the use of P and the assignments after the call,
6886 -- see Expand_N_Entry_Call_Statement.
6888 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
6889 Loc : constant Source_Ptr := Sloc (N);
6890 Abrt : constant Node_Id := Abortable_Part (N);
6891 Trig : constant Node_Id := Triggering_Alternative (N);
6893 Abort_Block_Ent : Entity_Id;
6894 Abortable_Block : Node_Id;
6897 Blk_Ent : constant Entity_Id := Make_Temporary (Loc, 'A');
6898 Blk_Typ : Entity_Id;
6900 Call_Ent : Entity_Id;
6901 Cancel_Param : Entity_Id;
6902 Cleanup_Block : Node_Id;
6903 Cleanup_Block_Ent : Entity_Id;
6904 Cleanup_Stmts : List_Id;
6905 Conc_Typ_Stmts : List_Id;
6907 Dblock_Ent : Entity_Id;
6912 Enqueue_Call : Node_Id;
6915 Handler_Stmt : Node_Id;
6917 Lim_Typ_Stmts : List_Id;
6923 ProtE_Stmts : List_Id;
6924 ProtP_Stmts : List_Id;
6927 TaskE_Stmts : List_Id;
6930 B : Entity_Id; -- Call status flag
6931 Bnn : Entity_Id; -- Communication block
6932 C : Entity_Id; -- Call kind
6933 K : Entity_Id; -- Tagged kind
6934 P : Entity_Id; -- Parameter block
6935 S : Entity_Id; -- Primitive operation slot
6936 T : Entity_Id; -- Additional status flag
6938 procedure Rewrite_Abortable_Part;
6939 -- If the trigger is a dispatching call, the expansion inserts multiple
6940 -- copies of the abortable part. This is both inefficient, and may lead
6941 -- to duplicate definitions that the back-end will reject, when the
6942 -- abortable part includes loops. This procedure rewrites the abortable
6943 -- part into a call to a generated procedure.
6945 ----------------------------
6946 -- Rewrite_Abortable_Part --
6947 ----------------------------
6949 procedure Rewrite_Abortable_Part is
6950 Proc : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
6955 Make_Subprogram_Body (Loc,
6957 Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc),
6958 Declarations => New_List,
6959 Handled_Statement_Sequence =>
6960 Make_Handled_Sequence_Of_Statements (Loc, Astats));
6961 Insert_Before (N, Decl);
6964 -- Rewrite abortable part into a call to this procedure.
6968 Make_Procedure_Call_Statement (Loc,
6969 Name => New_Occurrence_Of (Proc, Loc)));
6970 end Rewrite_Abortable_Part;
6973 Process_Statements_For_Controlled_Objects (Trig);
6974 Process_Statements_For_Controlled_Objects (Abrt);
6976 Ecall := Triggering_Statement (Trig);
6978 Ensure_Statement_Present (Sloc (Ecall), Trig);
6980 -- Retrieve Astats and Tstats now because the finalization machinery may
6981 -- wrap them in blocks.
6983 Astats := Statements (Abrt);
6984 Tstats := Statements (Trig);
6986 -- The arguments in the call may require dynamic allocation, and the
6987 -- call statement may have been transformed into a block. The block
6988 -- may contain additional declarations for internal entities, and the
6989 -- original call is found by sequential search.
6991 if Nkind (Ecall) = N_Block_Statement then
6992 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
6993 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
6994 N_Entry_Call_Statement)
7000 -- This is either a dispatching call or a delay statement used as a
7001 -- trigger which was expanded into a procedure call.
7003 if Nkind (Ecall) = N_Procedure_Call_Statement then
7004 if Ada_Version >= Ada_2005
7006 (No (Original_Node (Ecall))
7007 or else not Nkind_In (Original_Node (Ecall),
7008 N_Delay_Relative_Statement,
7009 N_Delay_Until_Statement))
7011 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
7013 Rewrite_Abortable_Part;
7017 -- Call status flag processing, generate:
7018 -- B : Boolean := False;
7020 B := Build_B (Loc, Decls);
7022 -- Communication block processing, generate:
7023 -- Bnn : Communication_Block;
7025 Bnn := Make_Temporary (Loc, 'B');
7027 Make_Object_Declaration (Loc,
7028 Defining_Identifier => Bnn,
7029 Object_Definition =>
7030 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
7032 -- Call kind processing, generate:
7033 -- C : Ada.Tags.Prim_Op_Kind;
7035 C := Build_C (Loc, Decls);
7037 -- Tagged kind processing, generate:
7038 -- K : Ada.Tags.Tagged_Kind :=
7039 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7041 -- Dummy communication block, generate:
7042 -- D : Dummy_Communication_Block;
7045 Make_Object_Declaration (Loc,
7046 Defining_Identifier =>
7047 Make_Defining_Identifier (Loc, Name_uD),
7048 Object_Definition =>
7050 (RTE (RE_Dummy_Communication_Block), Loc)));
7052 K := Build_K (Loc, Decls, Obj);
7054 -- Parameter block processing
7056 Blk_Typ := Build_Parameter_Block
7057 (Loc, Actuals, Formals, Decls);
7058 P := Parameter_Block_Pack
7059 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7061 -- Dispatch table slot processing, generate:
7064 S := Build_S (Loc, Decls);
7066 -- Additional status flag processing, generate:
7069 T := Make_Temporary (Loc, 'T');
7071 Make_Object_Declaration (Loc,
7072 Defining_Identifier => T,
7073 Object_Definition =>
7074 New_Occurrence_Of (Standard_Boolean, Loc)));
7076 ------------------------------
7077 -- Protected entry handling --
7078 ------------------------------
7081 -- Param1 := P.Param1;
7083 -- ParamN := P.ParamN;
7085 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7088 -- Bnn := Communication_Block (D);
7090 Prepend_To (Cleanup_Stmts,
7091 Make_Assignment_Statement (Loc,
7092 Name => New_Occurrence_Of (Bnn, Loc),
7094 Make_Unchecked_Type_Conversion (Loc,
7096 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7097 Expression => Make_Identifier (Loc, Name_uD))));
7100 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7102 Prepend_To (Cleanup_Stmts,
7103 Make_Procedure_Call_Statement (Loc,
7107 (Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select),
7109 Parameter_Associations =>
7111 New_Copy_Tree (Obj), -- <object>
7112 New_Occurrence_Of (S, Loc), -- S
7113 Make_Attribute_Reference (Loc, -- P'Address
7114 Prefix => New_Occurrence_Of (P, Loc),
7115 Attribute_Name => Name_Address),
7116 Make_Identifier (Loc, Name_uD), -- D
7117 New_Occurrence_Of (B, Loc)))); -- B
7120 -- if Enqueued (Bnn) then
7121 -- <abortable-statements>
7124 Append_To (Cleanup_Stmts,
7125 Make_Implicit_If_Statement (N,
7127 Make_Function_Call (Loc,
7129 New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7130 Parameter_Associations =>
7131 New_List (New_Occurrence_Of (Bnn, Loc))),
7134 New_Copy_List_Tree (Astats)));
7136 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7137 -- will then generate a _clean for the communication block Bnn.
7141 -- procedure _clean is
7143 -- if Enqueued (Bnn) then
7144 -- Cancel_Protected_Entry_Call (Bnn);
7153 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7155 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
7157 -- Wrap the cleanup block in an exception handling block
7163 -- when Abort_Signal => Abort_Undefer;
7166 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7169 Make_Implicit_Label_Declaration (Loc,
7170 Defining_Identifier => Abort_Block_Ent),
7173 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7176 -- if not Cancelled (Bnn) then
7177 -- <triggering-statements>
7180 Append_To (ProtE_Stmts,
7181 Make_Implicit_If_Statement (N,
7185 Make_Function_Call (Loc,
7187 New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7188 Parameter_Associations =>
7189 New_List (New_Occurrence_Of (Bnn, Loc)))),
7192 New_Copy_List_Tree (Tstats)));
7194 -------------------------
7195 -- Task entry handling --
7196 -------------------------
7199 -- Param1 := P.Param1;
7201 -- ParamN := P.ParamN;
7203 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7206 -- Bnn := Communication_Block (D);
7208 Append_To (TaskE_Stmts,
7209 Make_Assignment_Statement (Loc,
7211 New_Occurrence_Of (Bnn, Loc),
7213 Make_Unchecked_Type_Conversion (Loc,
7215 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7216 Expression => Make_Identifier (Loc, Name_uD))));
7219 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7221 Prepend_To (TaskE_Stmts,
7222 Make_Procedure_Call_Statement (Loc,
7225 Find_Prim_Op (Etype (Etype (Obj)),
7226 Name_uDisp_Asynchronous_Select),
7229 Parameter_Associations =>
7231 New_Copy_Tree (Obj), -- <object>
7232 New_Occurrence_Of (S, Loc), -- S
7233 Make_Attribute_Reference (Loc, -- P'Address
7234 Prefix => New_Occurrence_Of (P, Loc),
7235 Attribute_Name => Name_Address),
7236 Make_Identifier (Loc, Name_uD), -- D
7237 New_Occurrence_Of (B, Loc)))); -- B
7242 Prepend_To (TaskE_Stmts,
7243 Make_Procedure_Call_Statement (Loc,
7244 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
7245 Parameter_Associations => No_List));
7249 -- <abortable-statements>
7251 Cleanup_Stmts := New_Copy_List_Tree (Astats);
7253 Prepend_To (Cleanup_Stmts,
7254 Make_Procedure_Call_Statement (Loc,
7255 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
7256 Parameter_Associations => No_List));
7258 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7259 -- will generate a _clean for the additional status flag.
7263 -- procedure _clean is
7265 -- Cancel_Task_Entry_Call (U);
7273 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7275 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
7277 -- Wrap the cleanup block in an exception handling block
7283 -- when Abort_Signal => Abort_Undefer;
7286 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7288 Append_To (TaskE_Stmts,
7289 Make_Implicit_Label_Declaration (Loc,
7290 Defining_Identifier => Abort_Block_Ent));
7292 Append_To (TaskE_Stmts,
7294 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7298 -- <triggering-statements>
7301 Append_To (TaskE_Stmts,
7302 Make_Implicit_If_Statement (N,
7304 Make_Op_Not (Loc, Right_Opnd => New_Occurrence_Of (T, Loc)),
7307 New_Copy_List_Tree (Tstats)));
7309 ----------------------------------
7310 -- Protected procedure handling --
7311 ----------------------------------
7314 -- <dispatching-call>;
7315 -- <triggering-statements>
7317 ProtP_Stmts := New_Copy_List_Tree (Tstats);
7318 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
7321 -- S := Ada.Tags.Get_Offset_Index
7322 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7325 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7328 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7330 Append_To (Conc_Typ_Stmts,
7331 Make_Procedure_Call_Statement (Loc,
7334 (Find_Prim_Op (Etype (Etype (Obj)),
7335 Name_uDisp_Get_Prim_Op_Kind),
7337 Parameter_Associations =>
7339 New_Copy_Tree (Obj),
7340 New_Occurrence_Of (S, Loc),
7341 New_Occurrence_Of (C, Loc))));
7344 -- if C = POK_Procedure_Entry then
7346 -- elsif C = POK_Task_Entry then
7352 Append_To (Conc_Typ_Stmts,
7353 Make_Implicit_If_Statement (N,
7357 New_Occurrence_Of (C, Loc),
7359 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
7366 Make_Elsif_Part (Loc,
7370 New_Occurrence_Of (C, Loc),
7372 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc)),
7381 -- <dispatching-call>;
7382 -- <triggering-statements>
7384 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
7385 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
7388 -- if K = Ada.Tags.TK_Limited_Tagged
7389 -- or else K = Ada.Tags.TK_Tagged
7397 Make_Implicit_If_Statement (N,
7398 Condition => Build_Dispatching_Tag_Check (K, N),
7399 Then_Statements => Lim_Typ_Stmts,
7400 Else_Statements => Conc_Typ_Stmts));
7403 Make_Block_Statement (Loc,
7406 Handled_Statement_Sequence =>
7407 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7412 -- Delay triggering statement processing
7415 -- Add a Delay_Block object to the parameter list of the delay
7416 -- procedure to form the parameter list of the Wait entry call.
7418 Dblock_Ent := Make_Temporary (Loc, 'D');
7420 Pdef := Entity (Name (Ecall));
7422 if Is_RTE (Pdef, RO_CA_Delay_For) then
7424 New_Occurrence_Of (RTE (RE_Enqueue_Duration), Loc);
7426 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
7428 New_Occurrence_Of (RTE (RE_Enqueue_Calendar), Loc);
7430 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
7431 Enqueue_Call := New_Occurrence_Of (RTE (RE_Enqueue_RT), Loc);
7434 Append_To (Parameter_Associations (Ecall),
7435 Make_Attribute_Reference (Loc,
7436 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7437 Attribute_Name => Name_Unchecked_Access));
7439 -- Create the inner block to protect the abortable part
7441 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7444 Make_Procedure_Call_Statement (Loc,
7445 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc)));
7448 Make_Block_Statement (Loc,
7449 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7450 Handled_Statement_Sequence =>
7451 Make_Handled_Sequence_Of_Statements (Loc,
7452 Statements => Astats),
7453 Has_Created_Identifier => True,
7454 Is_Asynchronous_Call_Block => True);
7456 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7459 Make_Implicit_If_Statement (N,
7461 Make_Function_Call (Loc,
7462 Name => Enqueue_Call,
7463 Parameter_Associations => Parameter_Associations (Ecall)),
7465 New_List (Make_Block_Statement (Loc,
7466 Handled_Statement_Sequence =>
7467 Make_Handled_Sequence_Of_Statements (Loc,
7468 Statements => New_List (
7469 Make_Implicit_Label_Declaration (Loc,
7470 Defining_Identifier => Blk_Ent,
7471 Label_Construct => Abortable_Block),
7473 Exception_Handlers => Hdle)))));
7475 Stmts := New_List (Ecall);
7477 -- Construct statement sequence for new block
7480 Make_Implicit_If_Statement (N,
7482 Make_Function_Call (Loc,
7483 Name => New_Occurrence_Of (
7484 RTE (RE_Timed_Out), Loc),
7485 Parameter_Associations => New_List (
7486 Make_Attribute_Reference (Loc,
7487 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7488 Attribute_Name => Name_Unchecked_Access))),
7489 Then_Statements => Tstats));
7491 -- The result is the new block
7493 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
7496 Make_Block_Statement (Loc,
7497 Declarations => New_List (
7498 Make_Object_Declaration (Loc,
7499 Defining_Identifier => Dblock_Ent,
7500 Aliased_Present => True,
7501 Object_Definition =>
7502 New_Occurrence_Of (RTE (RE_Delay_Block), Loc))),
7504 Handled_Statement_Sequence =>
7505 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7515 Extract_Entry (Ecall, Concval, Ename, Index);
7516 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
7518 Stmts := Statements (Handled_Statement_Sequence (Ecall));
7519 Decls := Declarations (Ecall);
7521 if Is_Protected_Type (Etype (Concval)) then
7523 -- Get the declarations of the block expanded from the entry call
7525 Decl := First (Decls);
7526 while Present (Decl)
7527 and then (Nkind (Decl) /= N_Object_Declaration
7528 or else not Is_RTE (Etype (Object_Definition (Decl)),
7529 RE_Communication_Block))
7534 pragma Assert (Present (Decl));
7535 Cancel_Param := Defining_Identifier (Decl);
7537 -- Change the mode of the Protected_Entry_Call call
7539 -- Protected_Entry_Call (
7540 -- Object => po._object'Access,
7541 -- E => <entry index>;
7542 -- Uninterpreted_Data => P'Address;
7543 -- Mode => Asynchronous_Call;
7546 -- Skip assignments to temporaries created for in-out parameters
7548 -- This makes unwarranted assumptions about the shape of the expanded
7549 -- tree for the call, and should be cleaned up ???
7551 Stmt := First (Stmts);
7552 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7558 Param := First (Parameter_Associations (Call));
7559 while Present (Param)
7560 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7565 pragma Assert (Present (Param));
7566 Rewrite (Param, New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7569 -- Append an if statement to execute the abortable part
7572 -- if Enqueued (Bnn) then
7575 Make_Implicit_If_Statement (N,
7577 Make_Function_Call (Loc,
7578 Name => New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7579 Parameter_Associations => New_List (
7580 New_Occurrence_Of (Cancel_Param, Loc))),
7581 Then_Statements => Astats));
7584 Make_Block_Statement (Loc,
7585 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7586 Handled_Statement_Sequence =>
7587 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts),
7588 Has_Created_Identifier => True,
7589 Is_Asynchronous_Call_Block => True);
7591 -- For the VM call Update_Exception instead of Abort_Undefer.
7592 -- See 4jexcept.ads for an explanation.
7594 if VM_Target = No_VM then
7595 if Exception_Mechanism = Back_End_Exceptions then
7597 -- Aborts are not deferred at beginning of exception handlers
7600 Handler_Stmt := Make_Null_Statement (Loc);
7603 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
7604 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
7605 Parameter_Associations => No_List);
7608 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
7609 Name => New_Occurrence_Of (RTE (RE_Update_Exception), Loc),
7610 Parameter_Associations => New_List (
7611 Make_Function_Call (Loc,
7612 Name => New_Occurrence_Of
7613 (RTE (RE_Current_Target_Exception), Loc))));
7617 Make_Block_Statement (Loc,
7618 Handled_Statement_Sequence =>
7619 Make_Handled_Sequence_Of_Statements (Loc,
7620 Statements => New_List (
7621 Make_Implicit_Label_Declaration (Loc,
7622 Defining_Identifier => Blk_Ent,
7623 Label_Construct => Abortable_Block),
7628 Exception_Handlers => New_List (
7629 Make_Implicit_Exception_Handler (Loc,
7631 -- when Abort_Signal =>
7632 -- Abort_Undefer.all;
7634 Exception_Choices =>
7635 New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)),
7636 Statements => New_List (Handler_Stmt))))),
7638 -- if not Cancelled (Bnn) then
7639 -- triggered statements
7642 Make_Implicit_If_Statement (N,
7643 Condition => Make_Op_Not (Loc,
7645 Make_Function_Call (Loc,
7646 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7647 Parameter_Associations => New_List (
7648 New_Occurrence_Of (Cancel_Param, Loc)))),
7649 Then_Statements => Tstats));
7651 -- Asynchronous task entry call
7658 B := Make_Defining_Identifier (Loc, Name_uB);
7660 -- Insert declaration of B in declarations of existing block
7663 Make_Object_Declaration (Loc,
7664 Defining_Identifier => B,
7665 Object_Definition =>
7666 New_Occurrence_Of (Standard_Boolean, Loc)));
7668 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
7670 -- Insert declaration of C in declarations of existing block
7673 Make_Object_Declaration (Loc,
7674 Defining_Identifier => Cancel_Param,
7675 Object_Definition =>
7676 New_Occurrence_Of (Standard_Boolean, Loc)));
7678 -- Remove and save the call to Call_Simple
7680 Stmt := First (Stmts);
7682 -- Skip assignments to temporaries created for in-out parameters.
7683 -- This makes unwarranted assumptions about the shape of the expanded
7684 -- tree for the call, and should be cleaned up ???
7686 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7692 -- Create the inner block to protect the abortable part
7694 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7697 Make_Procedure_Call_Statement (Loc,
7698 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc)));
7701 Make_Block_Statement (Loc,
7702 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7703 Handled_Statement_Sequence =>
7704 Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats),
7705 Has_Created_Identifier => True,
7706 Is_Asynchronous_Call_Block => True);
7709 Make_Block_Statement (Loc,
7710 Handled_Statement_Sequence =>
7711 Make_Handled_Sequence_Of_Statements (Loc,
7712 Statements => New_List (
7713 Make_Implicit_Label_Declaration (Loc,
7714 Defining_Identifier => Blk_Ent,
7715 Label_Construct => Abortable_Block),
7717 Exception_Handlers => Hdle)));
7719 -- Create new call statement
7721 Params := Parameter_Associations (Call);
7724 New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7725 Append_To (Params, New_Occurrence_Of (B, Loc));
7728 Make_Procedure_Call_Statement (Loc,
7729 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
7730 Parameter_Associations => Params));
7732 -- Construct statement sequence for new block
7735 Make_Implicit_If_Statement (N,
7737 Make_Op_Not (Loc, New_Occurrence_Of (Cancel_Param, Loc)),
7738 Then_Statements => Tstats));
7740 -- Protected the call against abort
7743 Make_Procedure_Call_Statement (Loc,
7744 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
7745 Parameter_Associations => Empty_List));
7748 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
7750 -- The result is the new block
7753 Make_Block_Statement (Loc,
7754 Declarations => Decls,
7755 Handled_Statement_Sequence =>
7756 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7759 end Expand_N_Asynchronous_Select;
7761 -------------------------------------
7762 -- Expand_N_Conditional_Entry_Call --
7763 -------------------------------------
7765 -- The conditional task entry call is converted to a call to
7770 -- P : parms := (parm, parm, parm);
7774 -- (<acceptor-task>, -- Acceptor
7775 -- <entry-index>, -- E
7776 -- P'Address, -- Uninterpreted_Data
7777 -- Conditional_Call, -- Mode
7778 -- B); -- Rendezvous_Successful
7783 -- normal-statements
7789 -- For a description of the use of P and the assignments after the call,
7790 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7791 -- conditional entry call has already been expanded (by the Expand_N_Entry
7792 -- _Call_Statement procedure) as follows:
7795 -- P : parms := (parm, parm, parm);
7797 -- ... info for in-out parameters
7798 -- Call_Simple (acceptor-task, entry-index, P'Address);
7804 -- so the task at hand is to convert the latter expansion into the former
7806 -- The conditional protected entry call is converted to a call to
7807 -- Protected_Entry_Call:
7810 -- P : parms := (parm, parm, parm);
7811 -- Bnn : Communications_Block;
7814 -- Protected_Entry_Call
7815 -- (po._object'Access, -- Object
7816 -- <entry index>, -- E
7817 -- P'Address, -- Uninterpreted_Data
7818 -- Conditional_Call, -- Mode
7823 -- if Cancelled (Bnn) then
7826 -- normal-statements
7830 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7834 -- B : Boolean := False;
7835 -- C : Ada.Tags.Prim_Op_Kind;
7836 -- K : Ada.Tags.Tagged_Kind :=
7837 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7838 -- P : Parameters := (Param1 .. ParamN);
7842 -- if K = Ada.Tags.TK_Limited_Tagged
7843 -- or else K = Ada.Tags.TK_Tagged
7845 -- <dispatching-call>;
7846 -- <triggering-statements>
7850 -- Ada.Tags.Get_Offset_Index
7851 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7853 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7855 -- if C = POK_Protected_Entry
7856 -- or else C = POK_Task_Entry
7858 -- Param1 := P.Param1;
7860 -- ParamN := P.ParamN;
7864 -- if C = POK_Procedure
7865 -- or else C = POK_Protected_Procedure
7866 -- or else C = POK_Task_Procedure
7868 -- <dispatching-call>;
7871 -- <triggering-statements>
7873 -- <else-statements>
7878 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
7879 Loc : constant Source_Ptr := Sloc (N);
7880 Alt : constant Node_Id := Entry_Call_Alternative (N);
7881 Blk : Node_Id := Entry_Call_Statement (Alt);
7884 Blk_Typ : Entity_Id;
7886 Call_Ent : Entity_Id;
7887 Conc_Typ_Stmts : List_Id;
7891 Lim_Typ_Stmts : List_Id;
7898 Transient_Blk : Node_Id;
7901 B : Entity_Id; -- Call status flag
7902 C : Entity_Id; -- Call kind
7903 K : Entity_Id; -- Tagged kind
7904 P : Entity_Id; -- Parameter block
7905 S : Entity_Id; -- Primitive operation slot
7908 Process_Statements_For_Controlled_Objects (N);
7910 if Ada_Version >= Ada_2005
7911 and then Nkind (Blk) = N_Procedure_Call_Statement
7913 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7918 -- Call status flag processing, generate:
7919 -- B : Boolean := False;
7921 B := Build_B (Loc, Decls);
7923 -- Call kind processing, generate:
7924 -- C : Ada.Tags.Prim_Op_Kind;
7926 C := Build_C (Loc, Decls);
7928 -- Tagged kind processing, generate:
7929 -- K : Ada.Tags.Tagged_Kind :=
7930 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7932 K := Build_K (Loc, Decls, Obj);
7934 -- Parameter block processing
7936 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7937 P := Parameter_Block_Pack
7938 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7940 -- Dispatch table slot processing, generate:
7943 S := Build_S (Loc, Decls);
7946 -- S := Ada.Tags.Get_Offset_Index
7947 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7950 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7953 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7955 Append_To (Conc_Typ_Stmts,
7956 Make_Procedure_Call_Statement (Loc,
7959 Find_Prim_Op (Etype (Etype (Obj)),
7960 Name_uDisp_Conditional_Select),
7962 Parameter_Associations =>
7964 New_Copy_Tree (Obj), -- <object>
7965 New_Occurrence_Of (S, Loc), -- S
7966 Make_Attribute_Reference (Loc, -- P'Address
7967 Prefix => New_Occurrence_Of (P, Loc),
7968 Attribute_Name => Name_Address),
7969 New_Occurrence_Of (C, Loc), -- C
7970 New_Occurrence_Of (B, Loc)))); -- B
7973 -- if C = POK_Protected_Entry
7974 -- or else C = POK_Task_Entry
7976 -- Param1 := P.Param1;
7978 -- ParamN := P.ParamN;
7981 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7983 -- Generate the if statement only when the packed parameters need
7984 -- explicit assignments to their corresponding actuals.
7986 if Present (Unpack) then
7987 Append_To (Conc_Typ_Stmts,
7988 Make_Implicit_If_Statement (N,
7994 New_Occurrence_Of (C, Loc),
7996 New_Occurrence_Of (RTE (
7997 RE_POK_Protected_Entry), Loc)),
8002 New_Occurrence_Of (C, Loc),
8004 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
8006 Then_Statements => Unpack));
8011 -- if C = POK_Procedure
8012 -- or else C = POK_Protected_Procedure
8013 -- or else C = POK_Task_Procedure
8015 -- <dispatching-call>
8017 -- <normal-statements>
8019 -- <else-statements>
8022 N_Stats := New_Copy_List_Tree (Statements (Alt));
8024 Prepend_To (N_Stats,
8025 Make_Implicit_If_Statement (N,
8031 New_Occurrence_Of (C, Loc),
8033 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
8040 New_Occurrence_Of (C, Loc),
8042 New_Occurrence_Of (RTE (
8043 RE_POK_Protected_Procedure), Loc)),
8048 New_Occurrence_Of (C, Loc),
8050 New_Occurrence_Of (RTE (
8051 RE_POK_Task_Procedure), Loc)))),
8056 Append_To (Conc_Typ_Stmts,
8057 Make_Implicit_If_Statement (N,
8058 Condition => New_Occurrence_Of (B, Loc),
8059 Then_Statements => N_Stats,
8060 Else_Statements => Else_Statements (N)));
8063 -- <dispatching-call>;
8064 -- <triggering-statements>
8066 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
8067 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
8070 -- if K = Ada.Tags.TK_Limited_Tagged
8071 -- or else K = Ada.Tags.TK_Tagged
8079 Make_Implicit_If_Statement (N,
8080 Condition => Build_Dispatching_Tag_Check (K, N),
8081 Then_Statements => Lim_Typ_Stmts,
8082 Else_Statements => Conc_Typ_Stmts));
8085 Make_Block_Statement (Loc,
8088 Handled_Statement_Sequence =>
8089 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8091 -- As described above, the entry alternative is transformed into a
8092 -- block that contains the gnulli call, and possibly assignment
8093 -- statements for in-out parameters. The gnulli call may itself be
8094 -- rewritten into a transient block if some unconstrained parameters
8095 -- require it. We need to retrieve the call to complete its parameter
8100 First_Real_Statement (Handled_Statement_Sequence (Blk));
8102 if Present (Transient_Blk)
8103 and then Nkind (Transient_Blk) = N_Block_Statement
8105 Blk := Transient_Blk;
8108 Stmts := Statements (Handled_Statement_Sequence (Blk));
8109 Stmt := First (Stmts);
8110 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
8115 Params := Parameter_Associations (Call);
8117 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
8119 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8121 Param := First (Params);
8122 while Present (Param)
8123 and then not Is_RTE (Etype (Param), RE_Call_Modes)
8128 pragma Assert (Present (Param));
8130 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
8134 -- Find the Communication_Block parameter for the call to the
8135 -- Cancelled function.
8137 Decl := First (Declarations (Blk));
8138 while Present (Decl)
8139 and then not Is_RTE (Etype (Object_Definition (Decl)),
8140 RE_Communication_Block)
8145 -- Add an if statement to execute the else part if the call
8146 -- does not succeed (as indicated by the Cancelled predicate).
8149 Make_Implicit_If_Statement (N,
8150 Condition => Make_Function_Call (Loc,
8151 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
8152 Parameter_Associations => New_List (
8153 New_Occurrence_Of (Defining_Identifier (Decl), Loc))),
8154 Then_Statements => Else_Statements (N),
8155 Else_Statements => Statements (Alt)));
8158 B := Make_Defining_Identifier (Loc, Name_uB);
8160 -- Insert declaration of B in declarations of existing block
8162 if No (Declarations (Blk)) then
8163 Set_Declarations (Blk, New_List);
8166 Prepend_To (Declarations (Blk),
8167 Make_Object_Declaration (Loc,
8168 Defining_Identifier => B,
8169 Object_Definition =>
8170 New_Occurrence_Of (Standard_Boolean, Loc)));
8172 -- Create new call statement
8175 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
8176 Append_To (Params, New_Occurrence_Of (B, Loc));
8179 Make_Procedure_Call_Statement (Loc,
8180 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
8181 Parameter_Associations => Params));
8183 -- Construct statement sequence for new block
8186 Make_Implicit_If_Statement (N,
8187 Condition => New_Occurrence_Of (B, Loc),
8188 Then_Statements => Statements (Alt),
8189 Else_Statements => Else_Statements (N)));
8192 -- The result is the new block
8195 Make_Block_Statement (Loc,
8196 Declarations => Declarations (Blk),
8197 Handled_Statement_Sequence =>
8198 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8202 end Expand_N_Conditional_Entry_Call;
8204 ---------------------------------------
8205 -- Expand_N_Delay_Relative_Statement --
8206 ---------------------------------------
8208 -- Delay statement is implemented as a procedure call to Delay_For
8209 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8210 -- simple delays imposed by the use of Protected Objects.
8212 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
8213 Loc : constant Source_Ptr := Sloc (N);
8216 Make_Procedure_Call_Statement (Loc,
8217 Name => New_Occurrence_Of (RTE (RO_CA_Delay_For), Loc),
8218 Parameter_Associations => New_List (Expression (N))));
8220 end Expand_N_Delay_Relative_Statement;
8222 ------------------------------------
8223 -- Expand_N_Delay_Until_Statement --
8224 ------------------------------------
8226 -- Delay Until statement is implemented as a procedure call to
8227 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8229 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
8230 Loc : constant Source_Ptr := Sloc (N);
8234 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
8235 Typ := RTE (RO_CA_Delay_Until);
8237 Typ := RTE (RO_RT_Delay_Until);
8241 Make_Procedure_Call_Statement (Loc,
8242 Name => New_Occurrence_Of (Typ, Loc),
8243 Parameter_Associations => New_List (Expression (N))));
8246 end Expand_N_Delay_Until_Statement;
8248 -------------------------
8249 -- Expand_N_Entry_Body --
8250 -------------------------
8252 procedure Expand_N_Entry_Body (N : Node_Id) is
8254 -- Associate discriminals with the next protected operation body to be
8257 if Present (Next_Protected_Operation (N)) then
8258 Set_Discriminals (Parent (Current_Scope));
8260 end Expand_N_Entry_Body;
8262 -----------------------------------
8263 -- Expand_N_Entry_Call_Statement --
8264 -----------------------------------
8266 -- An entry call is expanded into GNARLI calls to implement a simple entry
8267 -- call (see Build_Simple_Entry_Call).
8269 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
8275 if No_Run_Time_Mode then
8276 Error_Msg_CRT ("entry call", N);
8280 -- If this entry call is part of an asynchronous select, don't expand it
8281 -- here; it will be expanded with the select statement. Don't expand
8282 -- timed entry calls either, as they are translated into asynchronous
8285 -- ??? This whole approach is questionable; it may be better to go back
8286 -- to allowing the expansion to take place and then attempting to fix it
8287 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8288 -- whether the expanded call is on a task or protected entry.
8290 if (Nkind (Parent (N)) /= N_Triggering_Alternative
8291 or else N /= Triggering_Statement (Parent (N)))
8292 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
8293 or else N /= Entry_Call_Statement (Parent (N))
8294 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
8296 Extract_Entry (N, Concval, Ename, Index);
8297 Build_Simple_Entry_Call (N, Concval, Ename, Index);
8299 end Expand_N_Entry_Call_Statement;
8301 --------------------------------
8302 -- Expand_N_Entry_Declaration --
8303 --------------------------------
8305 -- If there are parameters, then first, each of the formals is marked by
8306 -- setting Is_Entry_Formal. Next a record type is built which is used to
8307 -- hold the parameter values. The name of this record type is entryP where
8308 -- entry is the name of the entry, with an additional corresponding access
8309 -- type called entryPA. The record type has matching components for each
8310 -- formal (the component names are the same as the formal names). For
8311 -- elementary types, the component type matches the formal type. For
8312 -- composite types, an access type is declared (with the name formalA)
8313 -- which designates the formal type, and the type of the component is this
8314 -- access type. Finally the Entry_Component of each formal is set to
8315 -- reference the corresponding record component.
8317 procedure Expand_N_Entry_Declaration (N : Node_Id) is
8318 Loc : constant Source_Ptr := Sloc (N);
8319 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
8320 Components : List_Id;
8323 Last_Decl : Node_Id;
8324 Component : Entity_Id;
8327 Rec_Ent : Entity_Id;
8328 Acc_Ent : Entity_Id;
8331 Formal := First_Formal (Entry_Ent);
8334 -- Most processing is done only if parameters are present
8336 if Present (Formal) then
8337 Components := New_List;
8339 -- Loop through formals
8341 while Present (Formal) loop
8342 Set_Is_Entry_Formal (Formal);
8344 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
8345 Set_Entry_Component (Formal, Component);
8346 Set_Entry_Formal (Component, Formal);
8347 Ftype := Etype (Formal);
8349 -- Declare new access type and then append
8351 Ctype := Make_Temporary (Loc, 'A');
8354 Make_Full_Type_Declaration (Loc,
8355 Defining_Identifier => Ctype,
8357 Make_Access_To_Object_Definition (Loc,
8358 All_Present => True,
8359 Constant_Present => Ekind (Formal) = E_In_Parameter,
8360 Subtype_Indication => New_Occurrence_Of (Ftype, Loc)));
8362 Insert_After (Last_Decl, Decl);
8365 Append_To (Components,
8366 Make_Component_Declaration (Loc,
8367 Defining_Identifier => Component,
8368 Component_Definition =>
8369 Make_Component_Definition (Loc,
8370 Aliased_Present => False,
8371 Subtype_Indication => New_Occurrence_Of (Ctype, Loc))));
8373 Next_Formal_With_Extras (Formal);
8376 -- Create the Entry_Parameter_Record declaration
8378 Rec_Ent := Make_Temporary (Loc, 'P');
8381 Make_Full_Type_Declaration (Loc,
8382 Defining_Identifier => Rec_Ent,
8384 Make_Record_Definition (Loc,
8386 Make_Component_List (Loc,
8387 Component_Items => Components)));
8389 Insert_After (Last_Decl, Decl);
8392 -- Construct and link in the corresponding access type
8394 Acc_Ent := Make_Temporary (Loc, 'A');
8396 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
8399 Make_Full_Type_Declaration (Loc,
8400 Defining_Identifier => Acc_Ent,
8402 Make_Access_To_Object_Definition (Loc,
8403 All_Present => True,
8404 Subtype_Indication => New_Occurrence_Of (Rec_Ent, Loc)));
8406 Insert_After (Last_Decl, Decl);
8408 end Expand_N_Entry_Declaration;
8410 -----------------------------
8411 -- Expand_N_Protected_Body --
8412 -----------------------------
8414 -- Protected bodies are expanded to the completion of the subprograms
8415 -- created for the corresponding protected type. These are a protected and
8416 -- unprotected version of each protected subprogram in the object, a
8417 -- function to calculate each entry barrier, and a procedure to execute the
8418 -- sequence of statements of each protected entry body. For example, for
8419 -- protected type ptype:
8422 -- (O : System.Address;
8423 -- E : Protected_Entry_Index)
8426 -- <discriminant renamings>
8427 -- <private object renamings>
8429 -- return <barrier expression>;
8432 -- procedure pprocN (_object : in out poV;...) is
8433 -- <discriminant renamings>
8434 -- <private object renamings>
8436 -- <sequence of statements>
8439 -- procedure pprocP (_object : in out poV;...) is
8440 -- procedure _clean is
8443 -- ptypeS (_object, Pn);
8444 -- Unlock (_object._object'Access);
8445 -- Abort_Undefer.all;
8450 -- Lock (_object._object'Access);
8451 -- pprocN (_object;...);
8456 -- function pfuncN (_object : poV;...) return Return_Type is
8457 -- <discriminant renamings>
8458 -- <private object renamings>
8460 -- <sequence of statements>
8463 -- function pfuncP (_object : poV) return Return_Type is
8464 -- procedure _clean is
8466 -- Unlock (_object._object'Access);
8467 -- Abort_Undefer.all;
8472 -- Lock (_object._object'Access);
8473 -- return pfuncN (_object);
8480 -- (O : System.Address;
8481 -- P : System.Address;
8482 -- E : Protected_Entry_Index)
8484 -- <discriminant renamings>
8485 -- <private object renamings>
8486 -- type poVP is access poV;
8487 -- _Object : ptVP := ptVP!(O);
8491 -- <statement sequence>
8492 -- Complete_Entry_Body (_Object._Object);
8494 -- when all others =>
8495 -- Exceptional_Complete_Entry_Body (
8496 -- _Object._Object, Get_GNAT_Exception);
8500 -- The type poV is the record created for the protected type to hold
8501 -- the state of the protected object.
8503 procedure Expand_N_Protected_Body (N : Node_Id) is
8504 Loc : constant Source_Ptr := Sloc (N);
8505 Pid : constant Entity_Id := Corresponding_Spec (N);
8507 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Pid);
8508 -- This flag indicates whether the lock free implementation is active
8510 Current_Node : Node_Id;
8511 Disp_Op_Body : Node_Id;
8512 New_Op_Body : Node_Id;
8516 function Build_Dispatching_Subprogram_Body
8519 Prot_Bod : Node_Id) return Node_Id;
8520 -- Build a dispatching version of the protected subprogram body. The
8521 -- newly generated subprogram contains a call to the original protected
8522 -- body. The following code is generated:
8524 -- function <protected-function-name> (Param1 .. ParamN) return
8527 -- return <protected-function-name>P (Param1 .. ParamN);
8528 -- end <protected-function-name>;
8532 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8534 -- <protected-procedure-name>P (Param1 .. ParamN);
8535 -- end <protected-procedure-name>
8537 ---------------------------------------
8538 -- Build_Dispatching_Subprogram_Body --
8539 ---------------------------------------
8541 function Build_Dispatching_Subprogram_Body
8544 Prot_Bod : Node_Id) return Node_Id
8546 Loc : constant Source_Ptr := Sloc (N);
8553 -- Generate a specification without a letter suffix in order to
8554 -- override an interface function or procedure.
8556 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
8558 -- The formal parameters become the actuals of the protected function
8559 -- or procedure call.
8561 Actuals := New_List;
8562 Formal := First (Parameter_Specifications (Spec));
8563 while Present (Formal) loop
8565 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8569 if Nkind (Spec) = N_Procedure_Specification then
8572 Make_Procedure_Call_Statement (Loc,
8574 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8575 Parameter_Associations => Actuals));
8578 pragma Assert (Nkind (Spec) = N_Function_Specification);
8582 Make_Simple_Return_Statement (Loc,
8584 Make_Function_Call (Loc,
8586 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8587 Parameter_Associations => Actuals)));
8591 Make_Subprogram_Body (Loc,
8592 Declarations => Empty_List,
8593 Specification => Spec,
8594 Handled_Statement_Sequence =>
8595 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
8596 end Build_Dispatching_Subprogram_Body;
8598 -- Start of processing for Expand_N_Protected_Body
8601 if No_Run_Time_Mode then
8602 Error_Msg_CRT ("protected body", N);
8606 -- This is the proper body corresponding to a stub. The declarations
8607 -- must be inserted at the point of the stub, which in turn is in the
8608 -- declarative part of the parent unit.
8610 if Nkind (Parent (N)) = N_Subunit then
8611 Current_Node := Corresponding_Stub (Parent (N));
8616 Op_Body := First (Declarations (N));
8618 -- The protected body is replaced with the bodies of its
8619 -- protected operations, and the declarations for internal objects
8620 -- that may have been created for entry family bounds.
8622 Rewrite (N, Make_Null_Statement (Sloc (N)));
8625 while Present (Op_Body) loop
8626 case Nkind (Op_Body) is
8627 when N_Subprogram_Declaration =>
8630 when N_Subprogram_Body =>
8632 -- Do not create bodies for eliminated operations
8634 if not Is_Eliminated (Defining_Entity (Op_Body))
8635 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
8637 if Lock_Free_Active then
8639 Build_Lock_Free_Unprotected_Subprogram_Body
8643 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
8646 Insert_After (Current_Node, New_Op_Body);
8647 Current_Node := New_Op_Body;
8648 Analyze (New_Op_Body);
8650 -- Build the corresponding protected operation. It may
8651 -- appear that this is needed only if this is a visible
8652 -- operation of the type, or if it is an interrupt handler,
8653 -- and this was the strategy used previously in GNAT.
8655 -- However, the operation may be exported through a 'Access
8656 -- to an external caller. This is the common idiom in code
8657 -- that uses the Ada 2005 Timing_Events package. As a result
8658 -- we need to produce the protected body for both visible
8659 -- and private operations, as well as operations that only
8660 -- have a body in the source, and for which we create a
8661 -- declaration in the protected body itself.
8663 if Present (Corresponding_Spec (Op_Body)) then
8664 if Lock_Free_Active then
8666 Build_Lock_Free_Protected_Subprogram_Body
8667 (Op_Body, Pid, Specification (New_Op_Body));
8670 Build_Protected_Subprogram_Body
8671 (Op_Body, Pid, Specification (New_Op_Body));
8674 Insert_After (Current_Node, New_Op_Body);
8675 Analyze (New_Op_Body);
8677 Current_Node := New_Op_Body;
8679 -- Generate an overriding primitive operation body for
8680 -- this subprogram if the protected type implements an
8683 if Ada_Version >= Ada_2005
8685 Present (Interfaces (Corresponding_Record_Type (Pid)))
8688 Build_Dispatching_Subprogram_Body
8689 (Op_Body, Pid, New_Op_Body);
8691 Insert_After (Current_Node, Disp_Op_Body);
8692 Analyze (Disp_Op_Body);
8694 Current_Node := Disp_Op_Body;
8699 when N_Entry_Body =>
8700 Op_Id := Defining_Identifier (Op_Body);
8701 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
8703 Insert_After (Current_Node, New_Op_Body);
8704 Current_Node := New_Op_Body;
8705 Analyze (New_Op_Body);
8707 when N_Implicit_Label_Declaration =>
8710 when N_Itype_Reference =>
8711 Insert_After (Current_Node, New_Copy (Op_Body));
8713 when N_Freeze_Entity =>
8714 New_Op_Body := New_Copy (Op_Body);
8716 if Present (Entity (Op_Body))
8717 and then Freeze_Node (Entity (Op_Body)) = Op_Body
8719 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
8722 Insert_After (Current_Node, New_Op_Body);
8723 Current_Node := New_Op_Body;
8724 Analyze (New_Op_Body);
8727 New_Op_Body := New_Copy (Op_Body);
8728 Insert_After (Current_Node, New_Op_Body);
8729 Current_Node := New_Op_Body;
8730 Analyze (New_Op_Body);
8732 when N_Object_Declaration =>
8733 pragma Assert (not Comes_From_Source (Op_Body));
8734 New_Op_Body := New_Copy (Op_Body);
8735 Insert_After (Current_Node, New_Op_Body);
8736 Current_Node := New_Op_Body;
8737 Analyze (New_Op_Body);
8740 raise Program_Error;
8747 -- Finally, create the body of the function that maps an entry index
8748 -- into the corresponding body index, except when there is no entry, or
8749 -- in a Ravenscar-like profile.
8751 if Corresponding_Runtime_Package (Pid) =
8752 System_Tasking_Protected_Objects_Entries
8754 New_Op_Body := Build_Find_Body_Index (Pid);
8755 Insert_After (Current_Node, New_Op_Body);
8756 Current_Node := New_Op_Body;
8757 Analyze (New_Op_Body);
8760 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8761 -- protected body. At this point all wrapper specs have been created,
8762 -- frozen and included in the dispatch table for the protected type.
8764 if Ada_Version >= Ada_2005 then
8765 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
8767 end Expand_N_Protected_Body;
8769 -----------------------------------------
8770 -- Expand_N_Protected_Type_Declaration --
8771 -----------------------------------------
8773 -- First we create a corresponding record type declaration used to
8774 -- represent values of this protected type.
8775 -- The general form of this type declaration is
8777 -- type poV (discriminants) is record
8778 -- _Object : aliased <kind>Protection
8779 -- [(<entry count> [, <handler count>])];
8780 -- [entry_family : array (bounds) of Void;]
8781 -- <private data fields>
8784 -- The discriminants are present only if the corresponding protected type
8785 -- has discriminants, and they exactly mirror the protected type
8786 -- discriminants. The private data fields similarly mirror the private
8787 -- declarations of the protected type.
8789 -- The Object field is always present. It contains RTS specific data used
8790 -- to control the protected object. It is declared as Aliased so that it
8791 -- can be passed as a pointer to the RTS. This allows the protected record
8792 -- to be referenced within RTS data structures. An appropriate Protection
8793 -- type and discriminant are generated.
8795 -- The Service field is present for protected objects with entries. It
8796 -- contains sufficient information to allow the entry service procedure for
8797 -- this object to be called when the object is not known till runtime.
8799 -- One entry_family component is present for each entry family in the
8800 -- task definition (see Expand_N_Task_Type_Declaration).
8802 -- When a protected object is declared, an instance of the protected type
8803 -- value record is created. The elaboration of this declaration creates the
8804 -- correct bounds for the entry families, and also evaluates the priority
8805 -- expression if needed. The initialization routine for the protected type
8806 -- itself then calls Initialize_Protection with appropriate parameters to
8807 -- initialize the value of the Task_Id field. Install_Handlers may be also
8808 -- called if a pragma Attach_Handler applies.
8810 -- Note: this record is passed to the subprograms created by the expansion
8811 -- of protected subprograms and entries. It is an in parameter to protected
8812 -- functions and an in out parameter to procedures and entry bodies. The
8813 -- Entity_Id for this created record type is placed in the
8814 -- Corresponding_Record_Type field of the associated protected type entity.
8816 -- Next we create a procedure specifications for protected subprograms and
8817 -- entry bodies. For each protected subprograms two subprograms are
8818 -- created, an unprotected and a protected version. The unprotected version
8819 -- is called from within other operations of the same protected object.
8821 -- We also build the call to register the procedure if a pragma
8822 -- Interrupt_Handler applies.
8824 -- A single subprogram is created to service all entry bodies; it has an
8825 -- additional boolean out parameter indicating that the previous entry call
8826 -- made by the current task was serviced immediately, i.e. not by proxy.
8827 -- The O parameter contains a pointer to a record object of the type
8828 -- described above. An untyped interface is used here to allow this
8829 -- procedure to be called in places where the type of the object to be
8830 -- serviced is not known. This must be done, for example, when a call that
8831 -- may have been requeued is cancelled; the corresponding object must be
8832 -- serviced, but which object that is not known till runtime.
8835 -- (O : System.Address; P : out Boolean);
8836 -- procedure pprocN (_object : in out poV);
8837 -- procedure pproc (_object : in out poV);
8838 -- function pfuncN (_object : poV);
8839 -- function pfunc (_object : poV);
8842 -- Note that this must come after the record type declaration, since
8843 -- the specs refer to this type.
8845 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
8846 Loc : constant Source_Ptr := Sloc (N);
8847 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
8849 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Prot_Typ);
8850 -- This flag indicates whether the lock free implementation is active
8852 Pdef : constant Node_Id := Protected_Definition (N);
8853 -- This contains two lists; one for visible and one for private decls
8857 Discr_Map : constant Elist_Id := New_Elmt_List;
8861 Comp_Id : Entity_Id;
8863 Current_Node : Node_Id := N;
8864 Entries_Aggr : Node_Id;
8865 Body_Id : Entity_Id;
8868 Object_Comp : Node_Id;
8870 procedure Check_Inlining (Subp : Entity_Id);
8871 -- If the original operation has a pragma Inline, propagate the flag
8872 -- to the internal body, for possible inlining later on. The source
8873 -- operation is invisible to the back-end and is never actually called.
8875 procedure Expand_Entry_Declaration (Comp : Entity_Id);
8876 -- Create the subprograms for the barrier and for the body, and append
8877 -- then to Entry_Bodies_Array.
8879 function Static_Component_Size (Comp : Entity_Id) return Boolean;
8880 -- When compiling under the Ravenscar profile, private components must
8881 -- have a static size, or else a protected object will require heap
8882 -- allocation, violating the corresponding restriction. It is preferable
8883 -- to make this check here, because it provides a better error message
8884 -- than the back-end, which refers to the object as a whole.
8886 procedure Register_Handler;
8887 -- For a protected operation that is an interrupt handler, add the
8888 -- freeze action that will register it as such.
8890 --------------------
8891 -- Check_Inlining --
8892 --------------------
8894 procedure Check_Inlining (Subp : Entity_Id) is
8896 if Is_Inlined (Subp) then
8897 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8898 Set_Is_Inlined (Subp, False);
8902 ---------------------------------
8903 -- Check_Static_Component_Size --
8904 ---------------------------------
8906 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8907 Typ : constant Entity_Id := Etype (Comp);
8911 if Is_Scalar_Type (Typ) then
8914 elsif Is_Array_Type (Typ) then
8915 return Compile_Time_Known_Bounds (Typ);
8917 elsif Is_Record_Type (Typ) then
8918 C := First_Component (Typ);
8919 while Present (C) loop
8920 if not Static_Component_Size (C) then
8929 -- Any other type will be checked by the back-end
8934 end Static_Component_Size;
8936 ------------------------------
8937 -- Expand_Entry_Declaration --
8938 ------------------------------
8940 procedure Expand_Entry_Declaration (Comp : Entity_Id) is
8945 E_Count := E_Count + 1;
8946 Comp_Id := Defining_Identifier (Comp);
8949 Make_Defining_Identifier (Loc,
8950 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
8952 Make_Subprogram_Declaration (Loc,
8954 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
8956 Insert_After (Current_Node, Sub);
8959 -- Build wrapper procedure for pre/postconditions
8961 Build_PPC_Wrapper (Comp_Id, N);
8963 Set_Protected_Body_Subprogram
8964 (Defining_Identifier (Comp),
8965 Defining_Unit_Name (Specification (Sub)));
8967 Current_Node := Sub;
8970 Make_Defining_Identifier (Loc,
8971 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
8973 Make_Subprogram_Declaration (Loc,
8975 Build_Barrier_Function_Specification (Loc, Bdef));
8977 Insert_After (Current_Node, Sub);
8979 Set_Protected_Body_Subprogram (Bdef, Bdef);
8980 Set_Barrier_Function (Comp_Id, Bdef);
8981 Set_Scope (Bdef, Scope (Comp_Id));
8982 Current_Node := Sub;
8984 -- Collect pointers to the protected subprogram and the barrier
8985 -- of the current entry, for insertion into Entry_Bodies_Array.
8987 Append_To (Expressions (Entries_Aggr),
8988 Make_Aggregate (Loc,
8989 Expressions => New_List (
8990 Make_Attribute_Reference (Loc,
8991 Prefix => New_Occurrence_Of (Bdef, Loc),
8992 Attribute_Name => Name_Unrestricted_Access),
8993 Make_Attribute_Reference (Loc,
8994 Prefix => New_Occurrence_Of (Edef, Loc),
8995 Attribute_Name => Name_Unrestricted_Access))));
8996 end Expand_Entry_Declaration;
8998 ----------------------
8999 -- Register_Handler --
9000 ----------------------
9002 procedure Register_Handler is
9004 -- All semantic checks already done in Sem_Prag
9006 Prot_Proc : constant Entity_Id :=
9007 Defining_Unit_Name (Specification (Current_Node));
9009 Proc_Address : constant Node_Id :=
9010 Make_Attribute_Reference (Loc,
9012 New_Occurrence_Of (Prot_Proc, Loc),
9013 Attribute_Name => Name_Address);
9015 RTS_Call : constant Entity_Id :=
9016 Make_Procedure_Call_Statement (Loc,
9019 (RTE (RE_Register_Interrupt_Handler), Loc),
9020 Parameter_Associations => New_List (Proc_Address));
9022 Append_Freeze_Action (Prot_Proc, RTS_Call);
9023 end Register_Handler;
9025 -- Start of processing for Expand_N_Protected_Type_Declaration
9028 if Present (Corresponding_Record_Type (Prot_Typ)) then
9031 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
9034 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
9036 Qualify_Entity_Names (N);
9038 -- If the type has discriminants, their occurrences in the declaration
9039 -- have been replaced by the corresponding discriminals. For components
9040 -- that are constrained by discriminants, their homologues in the
9041 -- corresponding record type must refer to the discriminants of that
9042 -- record, so we must apply a new renaming to subtypes_indications:
9044 -- protected discriminant => discriminal => record discriminant
9046 -- This replacement is not applied to default expressions, for which
9047 -- the discriminal is correct.
9049 if Has_Discriminants (Prot_Typ) then
9055 Disc := First_Discriminant (Prot_Typ);
9056 Decl := First (Discriminant_Specifications (Rec_Decl));
9057 while Present (Disc) loop
9058 Append_Elmt (Discriminal (Disc), Discr_Map);
9059 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
9060 Next_Discriminant (Disc);
9066 -- Fill in the component declarations
9068 -- Add components for entry families. For each entry family, create an
9069 -- anonymous type declaration with the same size, and analyze the type.
9071 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
9073 pragma Assert (Present (Pdef));
9075 -- Add private field components
9077 if Present (Private_Declarations (Pdef)) then
9078 Priv := First (Private_Declarations (Pdef));
9079 while Present (Priv) loop
9080 if Nkind (Priv) = N_Component_Declaration then
9081 if not Static_Component_Size (Defining_Identifier (Priv)) then
9083 -- When compiling for a restricted profile, the private
9084 -- components must have a static size. If not, this is an
9085 -- error for a single protected declaration, and rates a
9086 -- warning on a protected type declaration.
9088 if not Comes_From_Source (Prot_Typ) then
9090 -- It's ok to be checking this restriction at expansion
9091 -- time, because this is only for the restricted profile,
9092 -- which is not subject to strict RM conformance, so it
9093 -- is OK to miss this check in -gnatc mode.
9095 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
9097 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
9098 Error_Msg_N ("component has non-static size??", Priv);
9100 ("\creation of protected object of type& will violate"
9101 & " restriction No_Implicit_Heap_Allocations??",
9106 -- The component definition consists of a subtype indication,
9107 -- or (in Ada 2005) an access definition. Make a copy of the
9108 -- proper definition.
9111 Old_Comp : constant Node_Id := Component_Definition (Priv);
9112 Oent : constant Entity_Id := Defining_Identifier (Priv);
9114 Nent : constant Entity_Id :=
9115 Make_Defining_Identifier (Sloc (Oent),
9116 Chars => Chars (Oent));
9119 if Present (Subtype_Indication (Old_Comp)) then
9121 Make_Component_Definition (Sloc (Oent),
9122 Aliased_Present => False,
9123 Subtype_Indication =>
9124 New_Copy_Tree (Subtype_Indication (Old_Comp),
9128 Make_Component_Definition (Sloc (Oent),
9129 Aliased_Present => False,
9130 Access_Definition =>
9131 New_Copy_Tree (Access_Definition (Old_Comp),
9136 Make_Component_Declaration (Loc,
9137 Defining_Identifier => Nent,
9138 Component_Definition => New_Comp,
9139 Expression => Expression (Priv));
9141 Set_Has_Per_Object_Constraint (Nent,
9142 Has_Per_Object_Constraint (Oent));
9144 Append_To (Cdecls, New_Priv);
9147 elsif Nkind (Priv) = N_Subprogram_Declaration then
9149 -- Make the unprotected version of the subprogram available
9150 -- for expansion of intra object calls. There is need for
9151 -- a protected version only if the subprogram is an interrupt
9152 -- handler, otherwise this operation can only be called from
9156 Make_Subprogram_Declaration (Loc,
9158 Build_Protected_Sub_Specification
9159 (Priv, Prot_Typ, Unprotected_Mode));
9161 Insert_After (Current_Node, Sub);
9164 Set_Protected_Body_Subprogram
9165 (Defining_Unit_Name (Specification (Priv)),
9166 Defining_Unit_Name (Specification (Sub)));
9167 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
9168 Current_Node := Sub;
9171 Make_Subprogram_Declaration (Loc,
9173 Build_Protected_Sub_Specification
9174 (Priv, Prot_Typ, Protected_Mode));
9176 Insert_After (Current_Node, Sub);
9178 Current_Node := Sub;
9180 if Is_Interrupt_Handler
9181 (Defining_Unit_Name (Specification (Priv)))
9183 if not Restricted_Profile then
9193 -- Except for the lock-free implementation, append the _Object field
9194 -- with the right type to the component list. We need to compute the
9195 -- number of entries, and in some cases the number of Attach_Handler
9198 if not Lock_Free_Active then
9201 Num_Attach_Handler : Int := 0;
9202 Protection_Subtype : Node_Id;
9203 Entry_Count_Expr : constant Node_Id :=
9204 Build_Entry_Count_Expression
9205 (Prot_Typ, Cdecls, Loc);
9208 if Has_Attach_Handler (Prot_Typ) then
9209 Ritem := First_Rep_Item (Prot_Typ);
9210 while Present (Ritem) loop
9211 if Nkind (Ritem) = N_Pragma
9212 and then Pragma_Name (Ritem) = Name_Attach_Handler
9214 Num_Attach_Handler := Num_Attach_Handler + 1;
9217 Next_Rep_Item (Ritem);
9221 -- Determine the proper protection type. There are two special
9222 -- cases: 1) when the protected type has dynamic interrupt
9223 -- handlers, and 2) when it has static handlers and we use a
9224 -- restricted profile.
9226 if Has_Attach_Handler (Prot_Typ)
9227 and then not Restricted_Profile
9229 Protection_Subtype :=
9230 Make_Subtype_Indication (Loc,
9233 (RTE (RE_Static_Interrupt_Protection), Loc),
9235 Make_Index_Or_Discriminant_Constraint (Loc,
9236 Constraints => New_List (
9238 Make_Integer_Literal (Loc, Num_Attach_Handler))));
9240 elsif Has_Interrupt_Handler (Prot_Typ)
9241 and then not Restriction_Active (No_Dynamic_Attachment)
9243 Protection_Subtype :=
9244 Make_Subtype_Indication (Loc,
9247 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
9249 Make_Index_Or_Discriminant_Constraint (Loc,
9250 Constraints => New_List (Entry_Count_Expr)));
9253 case Corresponding_Runtime_Package (Prot_Typ) is
9254 when System_Tasking_Protected_Objects_Entries =>
9255 Protection_Subtype :=
9256 Make_Subtype_Indication (Loc,
9259 (RTE (RE_Protection_Entries), Loc),
9261 Make_Index_Or_Discriminant_Constraint (Loc,
9262 Constraints => New_List (Entry_Count_Expr)));
9264 when System_Tasking_Protected_Objects_Single_Entry =>
9265 Protection_Subtype :=
9266 New_Occurrence_Of (RTE (RE_Protection_Entry), Loc);
9268 when System_Tasking_Protected_Objects =>
9269 Protection_Subtype :=
9270 New_Occurrence_Of (RTE (RE_Protection), Loc);
9273 raise Program_Error;
9278 Make_Component_Declaration (Loc,
9279 Defining_Identifier =>
9280 Make_Defining_Identifier (Loc, Name_uObject),
9281 Component_Definition =>
9282 Make_Component_Definition (Loc,
9283 Aliased_Present => True,
9284 Subtype_Indication => Protection_Subtype));
9287 -- Put the _Object component after the private component so that it
9288 -- be finalized early as required by 9.4 (20)
9290 Append_To (Cdecls, Object_Comp);
9293 Insert_After (Current_Node, Rec_Decl);
9294 Current_Node := Rec_Decl;
9296 -- Analyze the record declaration immediately after construction,
9297 -- because the initialization procedure is needed for single object
9298 -- declarations before the next entity is analyzed (the freeze call
9299 -- that generates this initialization procedure is found below).
9301 Analyze (Rec_Decl, Suppress => All_Checks);
9303 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9304 -- the corresponding record is frozen. If any wrappers are generated,
9305 -- Current_Node is updated accordingly.
9307 if Ada_Version >= Ada_2005 then
9308 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
9311 -- Collect pointers to entry bodies and their barriers, to be placed
9312 -- in the Entry_Bodies_Array for the type. For each entry/family we
9313 -- add an expression to the aggregate which is the initial value of
9314 -- this array. The array is declared after all protected subprograms.
9316 if Has_Entries (Prot_Typ) then
9317 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
9319 Entries_Aggr := Empty;
9322 -- Build two new procedure specifications for each protected subprogram;
9323 -- one to call from outside the object and one to call from inside.
9324 -- Build a barrier function and an entry body action procedure
9325 -- specification for each protected entry. Initialize the entry body
9326 -- array. If subprogram is flagged as eliminated, do not generate any
9327 -- internal operations.
9330 Comp := First (Visible_Declarations (Pdef));
9331 while Present (Comp) loop
9332 if Nkind (Comp) = N_Subprogram_Declaration then
9334 Make_Subprogram_Declaration (Loc,
9336 Build_Protected_Sub_Specification
9337 (Comp, Prot_Typ, Unprotected_Mode));
9339 Insert_After (Current_Node, Sub);
9342 Set_Protected_Body_Subprogram
9343 (Defining_Unit_Name (Specification (Comp)),
9344 Defining_Unit_Name (Specification (Sub)));
9345 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
9347 -- Make the protected version of the subprogram available for
9348 -- expansion of external calls.
9350 Current_Node := Sub;
9353 Make_Subprogram_Declaration (Loc,
9355 Build_Protected_Sub_Specification
9356 (Comp, Prot_Typ, Protected_Mode));
9358 Insert_After (Current_Node, Sub);
9361 Current_Node := Sub;
9363 -- Generate an overriding primitive operation specification for
9364 -- this subprogram if the protected type implements an interface.
9366 if Ada_Version >= Ada_2005
9368 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
9371 Make_Subprogram_Declaration (Loc,
9373 Build_Protected_Sub_Specification
9374 (Comp, Prot_Typ, Dispatching_Mode));
9376 Insert_After (Current_Node, Sub);
9379 Current_Node := Sub;
9382 -- If a pragma Interrupt_Handler applies, build and add a call to
9383 -- Register_Interrupt_Handler to the freezing actions of the
9384 -- protected version (Current_Node) of the subprogram:
9386 -- system.interrupts.register_interrupt_handler
9387 -- (prot_procP'address);
9389 if not Restricted_Profile
9390 and then Is_Interrupt_Handler
9391 (Defining_Unit_Name (Specification (Comp)))
9396 elsif Nkind (Comp) = N_Entry_Declaration then
9398 Expand_Entry_Declaration (Comp);
9405 -- If there are some private entry declarations, expand it as if they
9406 -- were visible entries.
9408 if Present (Private_Declarations (Pdef)) then
9409 Comp := First (Private_Declarations (Pdef));
9410 while Present (Comp) loop
9411 if Nkind (Comp) = N_Entry_Declaration then
9412 Expand_Entry_Declaration (Comp);
9419 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9420 -- all protected subprograms have been collected.
9422 if Has_Entries (Prot_Typ) then
9424 Make_Defining_Identifier (Sloc (Prot_Typ),
9425 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
9427 case Corresponding_Runtime_Package (Prot_Typ) is
9428 when System_Tasking_Protected_Objects_Entries =>
9429 Body_Arr := Make_Object_Declaration (Loc,
9430 Defining_Identifier => Body_Id,
9431 Aliased_Present => True,
9432 Object_Definition =>
9433 Make_Subtype_Indication (Loc,
9434 Subtype_Mark => New_Occurrence_Of (
9435 RTE (RE_Protected_Entry_Body_Array), Loc),
9437 Make_Index_Or_Discriminant_Constraint (Loc,
9438 Constraints => New_List (
9440 Make_Integer_Literal (Loc, 1),
9441 Make_Integer_Literal (Loc, E_Count))))),
9442 Expression => Entries_Aggr);
9444 when System_Tasking_Protected_Objects_Single_Entry =>
9445 Body_Arr := Make_Object_Declaration (Loc,
9446 Defining_Identifier => Body_Id,
9447 Aliased_Present => True,
9448 Object_Definition => New_Occurrence_Of
9449 (RTE (RE_Entry_Body), Loc),
9450 Expression => Remove_Head (Expressions (Entries_Aggr)));
9453 raise Program_Error;
9456 -- A pointer to this array will be placed in the corresponding record
9457 -- by its initialization procedure so this needs to be analyzed here.
9459 Insert_After (Current_Node, Body_Arr);
9460 Current_Node := Body_Arr;
9463 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
9465 -- Finally, build the function that maps an entry index into the
9466 -- corresponding body. A pointer to this function is placed in each
9467 -- object of the type. Except for a ravenscar-like profile (no abort,
9468 -- no entry queue, 1 entry)
9470 if Corresponding_Runtime_Package (Prot_Typ) =
9471 System_Tasking_Protected_Objects_Entries
9474 Make_Subprogram_Declaration (Loc,
9475 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
9476 Insert_After (Current_Node, Sub);
9480 end Expand_N_Protected_Type_Declaration;
9482 --------------------------------
9483 -- Expand_N_Requeue_Statement --
9484 --------------------------------
9486 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9487 -- operations, depending on the source and destination (task or protected
9488 -- object). A dispatching requeue statement is expanded into a call to the
9489 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9490 -- jump around the remainder of processing for the original entry and, if
9491 -- the destination is (different) protected object, to attempt to service
9492 -- it. The following illustrates the various cases:
9495 -- (O : System.Address;
9496 -- P : System.Address;
9497 -- E : Protected_Entry_Index)
9499 -- <discriminant renamings>
9500 -- <private object renamings>
9501 -- type poVP is access poV;
9502 -- _object : ptVP := ptVP!(O);
9506 -- <start of statement sequence for entry>
9508 -- -- Requeue from one protected entry body to another protected
9511 -- Requeue_Protected_Entry (
9512 -- _object._object'Access,
9513 -- new._object'Access,
9518 -- <some more of the statement sequence for entry>
9520 -- -- Requeue from an entry body to a task entry
9522 -- Requeue_Protected_To_Task_Entry (
9528 -- <rest of statement sequence for entry>
9529 -- Complete_Entry_Body (_object._object);
9532 -- when all others =>
9533 -- Exceptional_Complete_Entry_Body (
9534 -- _object._object, Get_GNAT_Exception);
9538 -- Requeue of a task entry call to a task entry
9540 -- Accept_Call (E, Ann);
9541 -- <start of statement sequence for accept statement>
9542 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9544 -- <rest of statement sequence for accept statement>
9546 -- Complete_Rendezvous;
9549 -- when all others =>
9550 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9552 -- Requeue of a task entry call to a protected entry
9554 -- Accept_Call (E, Ann);
9555 -- <start of statement sequence for accept statement>
9556 -- Requeue_Task_To_Protected_Entry (
9557 -- new._object'Access,
9562 -- <rest of statement sequence for accept statement>
9564 -- Complete_Rendezvous;
9567 -- when all others =>
9568 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9570 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9571 -- marked by pragma Implemented (XXX, By_Entry).
9573 -- The requeue is inside a protected entry:
9576 -- (O : System.Address;
9577 -- P : System.Address;
9578 -- E : Protected_Entry_Index)
9580 -- <discriminant renamings>
9581 -- <private object renamings>
9582 -- type poVP is access poV;
9583 -- _object : ptVP := ptVP!(O);
9587 -- <start of statement sequence for entry>
9590 -- (<interface class-wide object>,
9593 -- Ada.Tags.Get_Offset_Index
9595 -- <interface dispatch table index of target entry>),
9599 -- <rest of statement sequence for entry>
9600 -- Complete_Entry_Body (_object._object);
9603 -- when all others =>
9604 -- Exceptional_Complete_Entry_Body (
9605 -- _object._object, Get_GNAT_Exception);
9609 -- The requeue is inside a task entry:
9611 -- Accept_Call (E, Ann);
9612 -- <start of statement sequence for accept statement>
9614 -- (<interface class-wide object>,
9617 -- Ada.Tags.Get_Offset_Index
9619 -- <interface dispatch table index of target entrt>),
9623 -- <rest of statement sequence for accept statement>
9625 -- Complete_Rendezvous;
9628 -- when all others =>
9629 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9631 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9632 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9633 -- statement is replaced by a dispatching call with actual parameters taken
9634 -- from the inner-most accept statement or entry body.
9636 -- Target.Primitive (Param1, ..., ParamN);
9638 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9639 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9643 -- S : constant Offset_Index :=
9644 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9645 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9648 -- if C = POK_Protected_Entry
9649 -- or else C = POK_Task_Entry
9651 -- <statements for dispatching requeue>
9653 -- elsif C = POK_Protected_Procedure then
9654 -- <dispatching call equivalent>
9657 -- raise Program_Error;
9661 procedure Expand_N_Requeue_Statement (N : Node_Id) is
9662 Loc : constant Source_Ptr := Sloc (N);
9663 Conc_Typ : Entity_Id;
9667 Old_Typ : Entity_Id;
9669 function Build_Dispatching_Call_Equivalent return Node_Id;
9670 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9671 -- the form Concval.Ename. It is statically known that Ename is allowed
9672 -- to be implemented by a protected procedure. Create a dispatching call
9673 -- equivalent of Concval.Ename taking the actual parameters from the
9674 -- inner-most accept statement or entry body.
9676 function Build_Dispatching_Requeue return Node_Id;
9677 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9678 -- the form Concval.Ename. It is statically known that Ename is allowed
9679 -- to be implemented by a protected or a task entry. Create a call to
9680 -- primitive _Disp_Requeue which handles the low-level actions.
9682 function Build_Dispatching_Requeue_To_Any return Node_Id;
9683 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9684 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9685 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9686 -- determines at runtime whether Ename denotes an entry or a procedure
9687 -- and perform the appropriate kind of dispatching select.
9689 function Build_Normal_Requeue return Node_Id;
9690 -- N denotes a non-dispatching requeue statement to either a task or a
9691 -- protected entry. Build the appropriate runtime call to perform the
9694 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
9695 -- For a protected entry, create a return statement to skip the rest of
9696 -- the entry body. Otherwise, create a goto statement to skip the rest
9697 -- of a task accept statement. The lookup for the enclosing entry body
9698 -- or accept statement starts from Search.
9700 ---------------------------------------
9701 -- Build_Dispatching_Call_Equivalent --
9702 ---------------------------------------
9704 function Build_Dispatching_Call_Equivalent return Node_Id is
9705 Call_Ent : constant Entity_Id := Entity (Ename);
9706 Obj : constant Node_Id := Original_Node (Concval);
9713 -- Climb the parent chain looking for the inner-most entry body or
9714 -- accept statement.
9717 while Present (Acc_Ent)
9718 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
9721 Acc_Ent := Parent (Acc_Ent);
9724 -- A requeue statement should be housed inside an entry body or an
9725 -- accept statement at some level. If this is not the case, then the
9726 -- tree is malformed.
9728 pragma Assert (Present (Acc_Ent));
9730 -- Recover the list of formal parameters
9732 if Nkind (Acc_Ent) = N_Entry_Body then
9733 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
9736 Formals := Parameter_Specifications (Acc_Ent);
9738 -- Create the actual parameters for the dispatching call. These are
9739 -- simply copies of the entry body or accept statement formals in the
9740 -- same order as they appear.
9744 if Present (Formals) then
9745 Actuals := New_List;
9746 Formal := First (Formals);
9747 while Present (Formal) loop
9749 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
9755 -- Obj.Call_Ent (Actuals);
9758 Make_Procedure_Call_Statement (Loc,
9760 Make_Selected_Component (Loc,
9761 Prefix => Make_Identifier (Loc, Chars (Obj)),
9762 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
9764 Parameter_Associations => Actuals);
9765 end Build_Dispatching_Call_Equivalent;
9767 -------------------------------
9768 -- Build_Dispatching_Requeue --
9769 -------------------------------
9771 function Build_Dispatching_Requeue return Node_Id is
9772 Params : constant List_Id := New_List;
9775 -- Process the "with abort" parameter
9778 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
9780 -- Process the entry wrapper's position in the primary dispatch
9781 -- table parameter. Generate:
9783 -- Ada.Tags.Get_Entry_Index
9784 -- (T => To_Tag_Ptr (Obj'Address).all,
9786 -- Ada.Tags.Get_Offset_Index
9787 -- (Ada.Tags.Tag (Concval),
9788 -- <interface dispatch table position of Ename>));
9790 -- Note that Obj'Address is recursively expanded into a call to
9791 -- Base_Address (Obj).
9793 if Tagged_Type_Expansion then
9795 Make_Function_Call (Loc,
9796 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9797 Parameter_Associations => New_List (
9799 Make_Explicit_Dereference (Loc,
9800 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
9801 Make_Attribute_Reference (Loc,
9802 Prefix => New_Copy_Tree (Concval),
9803 Attribute_Name => Name_Address))),
9805 Make_Function_Call (Loc,
9806 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9807 Parameter_Associations => New_List (
9808 Unchecked_Convert_To (RTE (RE_Tag), Concval),
9809 Make_Integer_Literal (Loc,
9810 DT_Position (Entity (Ename))))))));
9816 Make_Function_Call (Loc,
9817 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9818 Parameter_Associations => New_List (
9820 Make_Attribute_Reference (Loc,
9822 Attribute_Name => Name_Tag),
9824 Make_Function_Call (Loc,
9825 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9827 Parameter_Associations => New_List (
9831 Make_Attribute_Reference (Loc,
9833 Attribute_Name => Name_Tag),
9837 Make_Attribute_Reference (Loc,
9838 Prefix => New_Occurrence_Of (Etype (Concval), Loc),
9839 Attribute_Name => Name_Tag),
9843 Make_Integer_Literal (Loc,
9844 DT_Position (Entity (Ename))))))));
9847 -- Specific actuals for protected to XXX requeue
9849 if Is_Protected_Type (Old_Typ) then
9851 Make_Attribute_Reference (Loc, -- _object'Address
9853 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9854 Attribute_Name => Name_Address));
9856 Prepend_To (Params, -- True
9857 New_Occurrence_Of (Standard_True, Loc));
9859 -- Specific actuals for task to XXX requeue
9862 pragma Assert (Is_Task_Type (Old_Typ));
9864 Prepend_To (Params, -- null
9865 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
9867 Prepend_To (Params, -- False
9868 New_Occurrence_Of (Standard_False, Loc));
9871 -- Add the object parameter
9873 Prepend_To (Params, New_Copy_Tree (Concval));
9876 -- _Disp_Requeue (<Params>);
9878 -- Find entity for Disp_Requeue operation, which belongs to
9879 -- the type and may not be directly visible.
9886 Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
9887 while Present (Elmt) loop
9889 exit when Chars (Op) = Name_uDisp_Requeue;
9894 Make_Procedure_Call_Statement (Loc,
9895 Name => New_Occurrence_Of (Op, Loc),
9896 Parameter_Associations => Params);
9898 end Build_Dispatching_Requeue;
9900 --------------------------------------
9901 -- Build_Dispatching_Requeue_To_Any --
9902 --------------------------------------
9904 function Build_Dispatching_Requeue_To_Any return Node_Id is
9905 Call_Ent : constant Entity_Id := Entity (Ename);
9906 Obj : constant Node_Id := Original_Node (Concval);
9907 Skip : constant Node_Id := Build_Skip_Statement (N);
9917 -- Dispatch table slot processing, generate:
9920 S := Build_S (Loc, Decls);
9922 -- Call kind processing, generate:
9923 -- C : Ada.Tags.Prim_Op_Kind;
9925 C := Build_C (Loc, Decls);
9928 -- S := Ada.Tags.Get_Offset_Index
9929 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9931 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
9934 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9937 Make_Procedure_Call_Statement (Loc,
9940 Find_Prim_Op (Etype (Etype (Obj)),
9941 Name_uDisp_Get_Prim_Op_Kind),
9943 Parameter_Associations => New_List (
9944 New_Copy_Tree (Obj),
9945 New_Occurrence_Of (S, Loc),
9946 New_Occurrence_Of (C, Loc))));
9950 -- if C = POK_Protected_Entry
9951 -- or else C = POK_Task_Entry
9954 Make_Implicit_If_Statement (N,
9960 New_Occurrence_Of (C, Loc),
9962 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
9967 New_Occurrence_Of (C, Loc),
9969 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
9971 -- Dispatching requeue equivalent
9973 Then_Statements => New_List (
9974 Build_Dispatching_Requeue,
9977 -- elsif C = POK_Protected_Procedure then
9979 Elsif_Parts => New_List (
9980 Make_Elsif_Part (Loc,
9984 New_Occurrence_Of (C, Loc),
9987 RTE (RE_POK_Protected_Procedure), Loc)),
9989 -- Dispatching call equivalent
9991 Then_Statements => New_List (
9992 Build_Dispatching_Call_Equivalent))),
9995 -- raise Program_Error;
9998 Else_Statements => New_List (
9999 Make_Raise_Program_Error (Loc,
10000 Reason => PE_Explicit_Raise))));
10002 -- Wrap everything into a block
10005 Make_Block_Statement (Loc,
10006 Declarations => Decls,
10007 Handled_Statement_Sequence =>
10008 Make_Handled_Sequence_Of_Statements (Loc,
10009 Statements => Stmts));
10010 end Build_Dispatching_Requeue_To_Any;
10012 --------------------------
10013 -- Build_Normal_Requeue --
10014 --------------------------
10016 function Build_Normal_Requeue return Node_Id is
10017 Params : constant List_Id := New_List;
10022 -- Process the "with abort" parameter
10024 Prepend_To (Params,
10025 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
10027 -- Add the index expression to the parameters. It is common among all
10030 Prepend_To (Params,
10031 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
10033 if Is_Protected_Type (Old_Typ) then
10035 Self_Param : Node_Id;
10039 Make_Attribute_Reference (Loc,
10041 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
10043 Name_Unchecked_Access);
10045 -- Protected to protected requeue
10047 if Is_Protected_Type (Conc_Typ) then
10049 New_Occurrence_Of (
10050 RTE (RE_Requeue_Protected_Entry), Loc);
10053 Make_Attribute_Reference (Loc,
10055 Concurrent_Ref (Concval),
10057 Name_Unchecked_Access);
10059 -- Protected to task requeue
10061 else pragma Assert (Is_Task_Type (Conc_Typ));
10063 New_Occurrence_Of (
10064 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
10066 Param := Concurrent_Ref (Concval);
10069 Prepend_To (Params, Param);
10070 Prepend_To (Params, Self_Param);
10073 else pragma Assert (Is_Task_Type (Old_Typ));
10075 -- Task to protected requeue
10077 if Is_Protected_Type (Conc_Typ) then
10079 New_Occurrence_Of (
10080 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
10083 Make_Attribute_Reference (Loc,
10085 Concurrent_Ref (Concval),
10087 Name_Unchecked_Access);
10089 -- Task to task requeue
10091 else pragma Assert (Is_Task_Type (Conc_Typ));
10093 New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc);
10095 Param := Concurrent_Ref (Concval);
10098 Prepend_To (Params, Param);
10102 Make_Procedure_Call_Statement (Loc,
10104 Parameter_Associations => Params);
10105 end Build_Normal_Requeue;
10107 --------------------------
10108 -- Build_Skip_Statement --
10109 --------------------------
10111 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
10112 Skip_Stmt : Node_Id;
10115 -- Build a return statement to skip the rest of the entire body
10117 if Is_Protected_Type (Old_Typ) then
10118 Skip_Stmt := Make_Simple_Return_Statement (Loc);
10120 -- If the requeue is within a task, find the end label of the
10121 -- enclosing accept statement and create a goto statement to it.
10129 -- Climb the parent chain looking for the enclosing accept
10132 Acc := Parent (Search);
10133 while Present (Acc)
10134 and then Nkind (Acc) /= N_Accept_Statement
10136 Acc := Parent (Acc);
10139 -- The last statement is the second label used for completing
10140 -- the rendezvous the usual way. The label we are looking for
10141 -- is right before it.
10144 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
10146 pragma Assert (Nkind (Label) = N_Label);
10148 -- Generate a goto statement to skip the rest of the accept
10151 Make_Goto_Statement (Loc,
10153 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
10157 Set_Analyzed (Skip_Stmt);
10160 end Build_Skip_Statement;
10162 -- Start of processing for Expand_N_Requeue_Statement
10165 -- Extract the components of the entry call
10167 Extract_Entry (N, Concval, Ename, Index);
10168 Conc_Typ := Etype (Concval);
10170 -- If the prefix is an access to class-wide type, dereference to get
10171 -- object and entry type.
10173 if Is_Access_Type (Conc_Typ) then
10174 Conc_Typ := Designated_Type (Conc_Typ);
10176 Make_Explicit_Dereference (Loc, Relocate_Node (Concval)));
10177 Analyze_And_Resolve (Concval, Conc_Typ);
10180 -- Examine the scope stack in order to find nearest enclosing protected
10181 -- or task type. This will constitute our invocation source.
10183 Old_Typ := Current_Scope;
10184 while Present (Old_Typ)
10185 and then not Is_Protected_Type (Old_Typ)
10186 and then not Is_Task_Type (Old_Typ)
10188 Old_Typ := Scope (Old_Typ);
10191 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10192 -- Concval.Ename where the type of Concval is class-wide concurrent
10195 if Ada_Version >= Ada_2012
10196 and then Present (Concval)
10197 and then Is_Class_Wide_Type (Conc_Typ)
10198 and then Is_Concurrent_Interface (Conc_Typ)
10201 Has_Impl : Boolean := False;
10202 Impl_Kind : Name_Id := No_Name;
10205 -- Check whether the Ename is flagged by pragma Implemented
10207 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
10209 Impl_Kind := Implementation_Kind (Entity (Ename));
10212 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10213 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10216 and then Impl_Kind = Name_By_Entry
10218 Rewrite (N, Build_Dispatching_Requeue);
10220 Insert_After (N, Build_Skip_Statement (N));
10222 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10223 -- a protected procedure. In this case the requeue is transformed
10224 -- into a dispatching call.
10227 and then Impl_Kind = Name_By_Protected_Procedure
10229 Rewrite (N, Build_Dispatching_Call_Equivalent);
10232 -- The procedure_or_entry_NAME's implementation kind is either
10233 -- By_Any, Optional, or pragma Implemented was not applied at all.
10234 -- In this case a runtime test determines whether Ename denotes an
10235 -- entry or a protected procedure and performs the appropriate
10239 Rewrite (N, Build_Dispatching_Requeue_To_Any);
10244 -- Processing for regular (non-dispatching) requeues
10247 Rewrite (N, Build_Normal_Requeue);
10249 Insert_After (N, Build_Skip_Statement (N));
10251 end Expand_N_Requeue_Statement;
10253 -------------------------------
10254 -- Expand_N_Selective_Accept --
10255 -------------------------------
10257 procedure Expand_N_Selective_Accept (N : Node_Id) is
10258 Loc : constant Source_Ptr := Sloc (N);
10259 Alts : constant List_Id := Select_Alternatives (N);
10261 -- Note: in the below declarations a lot of new lists are allocated
10262 -- unconditionally which may well not end up being used. That's not
10263 -- a good idea since it wastes space gratuitously ???
10265 Accept_Case : List_Id;
10266 Accept_List : constant List_Id := New_List;
10269 Alt_List : constant List_Id := New_List;
10270 Alt_Stats : List_Id;
10271 Ann : Entity_Id := Empty;
10273 Check_Guard : Boolean := True;
10275 Decls : constant List_Id := New_List;
10276 Stats : constant List_Id := New_List;
10277 Body_List : constant List_Id := New_List;
10278 Trailing_List : constant List_Id := New_List;
10281 Else_Present : Boolean := False;
10282 Terminate_Alt : Node_Id := Empty;
10283 Select_Mode : Node_Id;
10285 Delay_Case : List_Id;
10286 Delay_Count : Integer := 0;
10287 Delay_Val : Entity_Id;
10288 Delay_Index : Entity_Id;
10289 Delay_Min : Entity_Id;
10290 Delay_Num : Int := 1;
10291 Delay_Alt_List : List_Id := New_List;
10292 Delay_List : constant List_Id := New_List;
10296 First_Delay : Boolean := True;
10297 Guard_Open : Entity_Id;
10303 Num_Accept : Nat := 0;
10305 Time_Type : Entity_Id;
10306 Select_Call : Node_Id;
10308 Qnam : constant Entity_Id :=
10309 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
10311 Xnam : constant Entity_Id :=
10312 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
10314 -----------------------
10315 -- Local subprograms --
10316 -----------------------
10318 function Accept_Or_Raise return List_Id;
10319 -- For the rare case where delay alternatives all have guards, and
10320 -- all of them are closed, it is still possible that there were open
10321 -- accept alternatives with no callers. We must reexamine the
10322 -- Accept_List, and execute a selective wait with no else if some
10323 -- accept is open. If none, we raise program_error.
10325 procedure Add_Accept (Alt : Node_Id);
10326 -- Process a single accept statement in a select alternative. Build
10327 -- procedure for body of accept, and add entry to dispatch table with
10328 -- expression for guard, in preparation for call to run time select.
10330 function Make_And_Declare_Label (Num : Int) return Node_Id;
10331 -- Manufacture a label using Num as a serial number and declare it.
10332 -- The declaration is appended to Decls. The label marks the trailing
10333 -- statements of an accept or delay alternative.
10335 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
10336 -- Build call to Selective_Wait runtime routine
10338 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
10339 -- Add code to compare value of delay with previous values, and
10340 -- generate case entry for trailing statements.
10342 procedure Process_Accept_Alternative
10346 -- Add code to call corresponding procedure, and branch to
10347 -- trailing statements, if any.
10349 ---------------------
10350 -- Accept_Or_Raise --
10351 ---------------------
10353 function Accept_Or_Raise return List_Id is
10356 J : constant Entity_Id := Make_Temporary (Loc, 'J');
10359 -- We generate the following:
10361 -- for J in q'range loop
10362 -- if q(J).S /=null_task_entry then
10363 -- selective_wait (simple_mode,...);
10369 -- if no rendez_vous then
10370 -- raise program_error;
10373 -- Note that the code needs to know that the selector name
10374 -- in an Accept_Alternative is named S.
10376 Cond := Make_Op_Ne (Loc,
10378 Make_Selected_Component (Loc,
10380 Make_Indexed_Component (Loc,
10381 Prefix => New_Occurrence_Of (Qnam, Loc),
10382 Expressions => New_List (New_Occurrence_Of (J, Loc))),
10383 Selector_Name => Make_Identifier (Loc, Name_S)),
10385 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Loc));
10387 Stats := New_List (
10388 Make_Implicit_Loop_Statement (N,
10389 Iteration_Scheme =>
10390 Make_Iteration_Scheme (Loc,
10391 Loop_Parameter_Specification =>
10392 Make_Loop_Parameter_Specification (Loc,
10393 Defining_Identifier => J,
10394 Discrete_Subtype_Definition =>
10395 Make_Attribute_Reference (Loc,
10396 Prefix => New_Occurrence_Of (Qnam, Loc),
10397 Attribute_Name => Name_Range,
10398 Expressions => New_List (
10399 Make_Integer_Literal (Loc, 1))))),
10401 Statements => New_List (
10402 Make_Implicit_If_Statement (N,
10404 Then_Statements => New_List (
10406 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)),
10407 Make_Exit_Statement (Loc))))));
10410 Make_Raise_Program_Error (Loc,
10411 Condition => Make_Op_Eq (Loc,
10412 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
10414 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
10415 Reason => PE_All_Guards_Closed));
10418 end Accept_Or_Raise;
10424 procedure Add_Accept (Alt : Node_Id) is
10425 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
10426 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
10427 Eloc : constant Source_Ptr := Sloc (Ename);
10428 Eent : constant Entity_Id := Entity (Ename);
10429 Index : constant Node_Id := Entry_Index (Acc_Stm);
10430 Null_Body : Node_Id;
10431 Proc_Body : Node_Id;
10432 PB_Ent : Entity_Id;
10438 Ann := Node (Last_Elmt (Accept_Address (Eent)));
10441 if Present (Condition (Alt)) then
10443 Make_If_Expression (Eloc, New_List (
10445 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
10446 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Eloc)));
10449 Entry_Index_Expression
10450 (Eloc, Eent, Index, Scope (Eent));
10453 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
10454 Null_Body := New_Occurrence_Of (Standard_False, Eloc);
10456 -- Always add call to Abort_Undefer when generating code, since
10457 -- this is what the runtime expects (abort deferred in
10458 -- Selective_Wait). In CodePeer mode this only confuses the
10459 -- analysis with unknown calls, so don't do it.
10461 if not CodePeer_Mode then
10463 Make_Procedure_Call_Statement (Eloc,
10464 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Eloc));
10466 (First (Statements (Handled_Statement_Sequence
10467 (Accept_Statement (Alt)))),
10473 Make_Defining_Identifier (Eloc,
10474 New_External_Name (Chars (Ename), 'A', Num_Accept));
10476 if Comes_From_Source (Alt) then
10477 Set_Debug_Info_Needed (PB_Ent);
10481 Make_Subprogram_Body (Eloc,
10483 Make_Procedure_Specification (Eloc,
10484 Defining_Unit_Name => PB_Ent),
10485 Declarations => Declarations (Acc_Stm),
10486 Handled_Statement_Sequence =>
10487 Build_Accept_Body (Accept_Statement (Alt)));
10489 -- During the analysis of the body of the accept statement, any
10490 -- zero cost exception handler records were collected in the
10491 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10492 -- This is where we move them to where they belong, namely the
10493 -- newly created procedure.
10495 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
10496 Append (Proc_Body, Body_List);
10499 Null_Body := New_Occurrence_Of (Standard_True, Eloc);
10501 -- if accept statement has declarations, insert above, given that
10502 -- we are not creating a body for the accept.
10504 if Present (Declarations (Acc_Stm)) then
10505 Insert_Actions (N, Declarations (Acc_Stm));
10509 Append_To (Accept_List,
10510 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
10512 Num_Accept := Num_Accept + 1;
10515 ----------------------------
10516 -- Make_And_Declare_Label --
10517 ----------------------------
10519 function Make_And_Declare_Label (Num : Int) return Node_Id is
10523 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
10525 Make_Label (Loc, Lab_Id);
10528 Make_Implicit_Label_Declaration (Loc,
10529 Defining_Identifier =>
10530 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
10531 Label_Construct => Lab));
10534 end Make_And_Declare_Label;
10536 ----------------------
10537 -- Make_Select_Call --
10538 ----------------------
10540 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
10541 Params : constant List_Id := New_List;
10545 Make_Attribute_Reference (Loc,
10546 Prefix => New_Occurrence_Of (Qnam, Loc),
10547 Attribute_Name => Name_Unchecked_Access),
10549 Append (Select_Mode, Params);
10550 Append (New_Occurrence_Of (Ann, Loc), Params);
10551 Append (New_Occurrence_Of (Xnam, Loc), Params);
10554 Make_Procedure_Call_Statement (Loc,
10555 Name => New_Occurrence_Of (RTE (RE_Selective_Wait), Loc),
10556 Parameter_Associations => Params);
10557 end Make_Select_Call;
10559 --------------------------------
10560 -- Process_Accept_Alternative --
10561 --------------------------------
10563 procedure Process_Accept_Alternative
10568 Astmt : constant Node_Id := Accept_Statement (Alt);
10569 Alt_Stats : List_Id;
10572 Adjust_Condition (Condition (Alt));
10574 -- Accept with body
10576 if Present (Handled_Statement_Sequence (Astmt)) then
10579 Make_Procedure_Call_Statement (Sloc (Proc),
10582 (Defining_Unit_Name (Specification (Proc)),
10585 -- Accept with no body (followed by trailing statements)
10588 Alt_Stats := Empty_List;
10591 Ensure_Statement_Present (Sloc (Astmt), Alt);
10593 -- After the call, if any, branch to trailing statements, if any.
10594 -- We create a label for each, as well as the corresponding label
10597 if not Is_Empty_List (Statements (Alt)) then
10598 Lab := Make_And_Declare_Label (Index);
10599 Append (Lab, Trailing_List);
10600 Append_List (Statements (Alt), Trailing_List);
10601 Append_To (Trailing_List,
10602 Make_Goto_Statement (Loc,
10603 Name => New_Copy (Identifier (End_Lab))));
10609 Append_To (Alt_Stats,
10610 Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab))));
10612 Append_To (Alt_List,
10613 Make_Case_Statement_Alternative (Loc,
10614 Discrete_Choices => New_List (Make_Integer_Literal (Loc, Index)),
10615 Statements => Alt_Stats));
10616 end Process_Accept_Alternative;
10618 -------------------------------
10619 -- Process_Delay_Alternative --
10620 -------------------------------
10622 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
10623 Dloc : constant Source_Ptr := Sloc (Delay_Statement (Alt));
10625 Delay_Alt : List_Id;
10628 -- Deal with C/Fortran boolean as delay condition
10630 Adjust_Condition (Condition (Alt));
10632 -- Determine the smallest specified delay
10634 -- for each delay alternative generate:
10636 -- if guard-expression then
10637 -- Delay_Val := delay-expression;
10638 -- Guard_Open := True;
10639 -- if Delay_Val < Delay_Min then
10640 -- Delay_Min := Delay_Val;
10641 -- Delay_Index := Index;
10645 -- The enclosing if-statement is omitted if there is no guard
10647 if Delay_Count = 1 or else First_Delay then
10648 First_Delay := False;
10650 Delay_Alt := New_List (
10651 Make_Assignment_Statement (Loc,
10652 Name => New_Occurrence_Of (Delay_Min, Loc),
10653 Expression => Expression (Delay_Statement (Alt))));
10655 if Delay_Count > 1 then
10656 Append_To (Delay_Alt,
10657 Make_Assignment_Statement (Loc,
10658 Name => New_Occurrence_Of (Delay_Index, Loc),
10659 Expression => Make_Integer_Literal (Loc, Index)));
10663 Delay_Alt := New_List (
10664 Make_Assignment_Statement (Loc,
10665 Name => New_Occurrence_Of (Delay_Val, Loc),
10666 Expression => Expression (Delay_Statement (Alt))));
10668 if Time_Type = Standard_Duration then
10671 Left_Opnd => New_Occurrence_Of (Delay_Val, Loc),
10672 Right_Opnd => New_Occurrence_Of (Delay_Min, Loc));
10675 -- The scope of the time type must define a comparison
10676 -- operator. The scope itself may not be visible, so we
10677 -- construct a node with entity information to insure that
10678 -- semantic analysis can find the proper operator.
10681 Make_Function_Call (Loc,
10682 Name => Make_Selected_Component (Loc,
10684 New_Occurrence_Of (Scope (Time_Type), Loc),
10686 Make_Operator_Symbol (Loc,
10687 Chars => Name_Op_Lt,
10688 Strval => No_String)),
10689 Parameter_Associations =>
10691 New_Occurrence_Of (Delay_Val, Loc),
10692 New_Occurrence_Of (Delay_Min, Loc)));
10694 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
10697 Append_To (Delay_Alt,
10698 Make_Implicit_If_Statement (N,
10700 Then_Statements => New_List (
10701 Make_Assignment_Statement (Loc,
10702 Name => New_Occurrence_Of (Delay_Min, Loc),
10703 Expression => New_Occurrence_Of (Delay_Val, Loc)),
10705 Make_Assignment_Statement (Loc,
10706 Name => New_Occurrence_Of (Delay_Index, Loc),
10707 Expression => Make_Integer_Literal (Loc, Index)))));
10710 if Check_Guard then
10711 Append_To (Delay_Alt,
10712 Make_Assignment_Statement (Loc,
10713 Name => New_Occurrence_Of (Guard_Open, Loc),
10714 Expression => New_Occurrence_Of (Standard_True, Loc)));
10717 if Present (Condition (Alt)) then
10718 Delay_Alt := New_List (
10719 Make_Implicit_If_Statement (N,
10720 Condition => Condition (Alt),
10721 Then_Statements => Delay_Alt));
10724 Append_List (Delay_Alt, Delay_List);
10726 Ensure_Statement_Present (Dloc, Alt);
10728 -- If the delay alternative has a statement part, add choice to the
10729 -- case statements for delays.
10731 if not Is_Empty_List (Statements (Alt)) then
10733 if Delay_Count = 1 then
10734 Append_List (Statements (Alt), Delay_Alt_List);
10737 Append_To (Delay_Alt_List,
10738 Make_Case_Statement_Alternative (Loc,
10739 Discrete_Choices => New_List (
10740 Make_Integer_Literal (Loc, Index)),
10741 Statements => Statements (Alt)));
10744 elsif Delay_Count = 1 then
10746 -- If the single delay has no trailing statements, add a branch
10747 -- to the exit label to the selective wait.
10749 Delay_Alt_List := New_List (
10750 Make_Goto_Statement (Loc,
10751 Name => New_Copy (Identifier (End_Lab))));
10754 end Process_Delay_Alternative;
10756 -- Start of processing for Expand_N_Selective_Accept
10759 Process_Statements_For_Controlled_Objects (N);
10761 -- First insert some declarations before the select. The first is:
10765 -- This variable holds the parameters passed to the accept body. This
10766 -- declaration has already been inserted by the time we get here by
10767 -- a call to Expand_Accept_Declarations made from the semantics when
10768 -- processing the first accept statement contained in the select. We
10769 -- can find this entity as Accept_Address (E), where E is any of the
10770 -- entries references by contained accept statements.
10772 -- The first step is to scan the list of Selective_Accept_Statements
10773 -- to find this entity, and also count the number of accepts, and
10774 -- determine if terminated, delay or else is present:
10778 Alt := First (Alts);
10779 while Present (Alt) loop
10780 Process_Statements_For_Controlled_Objects (Alt);
10782 if Nkind (Alt) = N_Accept_Alternative then
10785 elsif Nkind (Alt) = N_Delay_Alternative then
10786 Delay_Count := Delay_Count + 1;
10788 -- If the delays are relative delays, the delay expressions have
10789 -- type Standard_Duration. Otherwise they must have some time type
10790 -- recognized by GNAT.
10792 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
10793 Time_Type := Standard_Duration;
10795 Time_Type := Etype (Expression (Delay_Statement (Alt)));
10797 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
10798 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
10803 "& is not a time type (RM 9.6(6))",
10804 Expression (Delay_Statement (Alt)), Time_Type);
10805 Time_Type := Standard_Duration;
10806 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
10810 if No (Condition (Alt)) then
10812 -- This guard will always be open
10814 Check_Guard := False;
10817 elsif Nkind (Alt) = N_Terminate_Alternative then
10818 Adjust_Condition (Condition (Alt));
10819 Terminate_Alt := Alt;
10822 Num_Alts := Num_Alts + 1;
10826 Else_Present := Present (Else_Statements (N));
10828 -- At the same time (see procedure Add_Accept) we build the accept list:
10830 -- Qnn : Accept_List (1 .. num-select) := (
10831 -- (null-body, entry-index),
10832 -- (null-body, entry-index),
10834 -- (null_body, entry-index));
10836 -- In the above declaration, null-body is True if the corresponding
10837 -- accept has no body, and false otherwise. The entry is either the
10838 -- entry index expression if there is no guard, or if a guard is
10839 -- present, then an if expression of the form:
10841 -- (if guard then entry-index else Null_Task_Entry)
10843 -- If a guard is statically known to be false, the entry can simply
10844 -- be omitted from the accept list.
10847 Make_Object_Declaration (Loc,
10848 Defining_Identifier => Qnam,
10849 Object_Definition => New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10850 Aliased_Present => True,
10852 Make_Qualified_Expression (Loc,
10854 New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10856 Make_Aggregate (Loc, Expressions => Accept_List))));
10858 -- Then we declare the variable that holds the index for the accept
10859 -- that will be selected for service:
10861 -- Xnn : Select_Index;
10864 Make_Object_Declaration (Loc,
10865 Defining_Identifier => Xnam,
10866 Object_Definition =>
10867 New_Occurrence_Of (RTE (RE_Select_Index), Loc),
10869 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)));
10871 -- After this follow procedure declarations for each accept body
10873 -- procedure Pnn is
10878 -- where the ... are statements from the corresponding procedure body.
10879 -- No parameters are involved, since the parameters are passed via Ann
10880 -- and the parameter references have already been expanded to be direct
10881 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10882 -- any embedded tasking statements (which would normally be illegal in
10883 -- procedures), have been converted to calls to the tasking runtime so
10884 -- there is no problem in putting them into procedures.
10886 -- The original accept statement has been expanded into a block in
10887 -- the same fashion as for simple accepts (see Build_Accept_Body).
10889 -- Note: we don't really need to build these procedures for the case
10890 -- where no delay statement is present, but it is just as easy to
10891 -- build them unconditionally, and not significantly inefficient,
10892 -- since if they are short they will be inlined anyway.
10894 -- The procedure declarations have been assembled in Body_List
10896 -- If delays are present, we must compute the required delay.
10897 -- We first generate the declarations:
10899 -- Delay_Index : Boolean := 0;
10900 -- Delay_Min : Some_Time_Type.Time;
10901 -- Delay_Val : Some_Time_Type.Time;
10903 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10904 -- active delay that is actually chosen as the basis for the possible
10905 -- delay if an immediate rendez-vous is not possible.
10907 -- In the most common case there is a single delay statement, and this
10908 -- is handled specially.
10910 if Delay_Count > 0 then
10912 -- Generate the required declarations
10915 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
10917 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
10919 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
10922 Make_Object_Declaration (Loc,
10923 Defining_Identifier => Delay_Val,
10924 Object_Definition => New_Occurrence_Of (Time_Type, Loc)));
10927 Make_Object_Declaration (Loc,
10928 Defining_Identifier => Delay_Index,
10929 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
10930 Expression => Make_Integer_Literal (Loc, 0)));
10933 Make_Object_Declaration (Loc,
10934 Defining_Identifier => Delay_Min,
10935 Object_Definition => New_Occurrence_Of (Time_Type, Loc),
10937 Unchecked_Convert_To (Time_Type,
10938 Make_Attribute_Reference (Loc,
10940 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
10941 Attribute_Name => Name_Last))));
10943 -- Create Duration and Delay_Mode objects used for passing a delay
10946 D := Make_Temporary (Loc, 'D');
10947 M := Make_Temporary (Loc, 'M');
10953 -- Note that these values are defined in s-osprim.ads and must
10954 -- be kept in sync:
10956 -- Relative : constant := 0;
10957 -- Absolute_Calendar : constant := 1;
10958 -- Absolute_RT : constant := 2;
10960 if Time_Type = Standard_Duration then
10961 Discr := Make_Integer_Literal (Loc, 0);
10963 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
10964 Discr := Make_Integer_Literal (Loc, 1);
10968 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
10969 Discr := Make_Integer_Literal (Loc, 2);
10973 Make_Object_Declaration (Loc,
10974 Defining_Identifier => D,
10975 Object_Definition =>
10976 New_Occurrence_Of (Standard_Duration, Loc)));
10979 Make_Object_Declaration (Loc,
10980 Defining_Identifier => M,
10981 Object_Definition =>
10982 New_Occurrence_Of (Standard_Integer, Loc),
10983 Expression => Discr));
10986 if Check_Guard then
10988 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
10991 Make_Object_Declaration (Loc,
10992 Defining_Identifier => Guard_Open,
10993 Object_Definition =>
10994 New_Occurrence_Of (Standard_Boolean, Loc),
10996 New_Occurrence_Of (Standard_False, Loc)));
10999 -- Delay_Count is zero, don't need M and D set (suppress warning)
11006 if Present (Terminate_Alt) then
11008 -- If the terminate alternative guard is False, use
11009 -- Simple_Mode; otherwise use Terminate_Mode.
11011 if Present (Condition (Terminate_Alt)) then
11012 Select_Mode := Make_If_Expression (Loc,
11013 New_List (Condition (Terminate_Alt),
11014 New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc),
11015 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)));
11017 Select_Mode := New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc);
11020 elsif Else_Present or Delay_Count > 0 then
11021 Select_Mode := New_Occurrence_Of (RTE (RE_Else_Mode), Loc);
11024 Select_Mode := New_Occurrence_Of (RTE (RE_Simple_Mode), Loc);
11027 Select_Call := Make_Select_Call (Select_Mode);
11028 Append (Select_Call, Stats);
11030 -- Now generate code to act on the result. There is an entry
11031 -- in this case for each accept statement with a non-null body,
11032 -- followed by a branch to the statements that follow the Accept.
11033 -- In the absence of delay alternatives, we generate:
11036 -- when No_Rendezvous => -- omitted if simple mode
11051 -- Lab0: Else_Statements;
11054 -- Lab1: Trailing_Statements1;
11057 -- Lab2: Trailing_Statements2;
11062 -- Generate label for common exit
11064 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
11066 -- First entry is the default case, when no rendezvous is possible
11068 Choices := New_List (New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc));
11070 if Else_Present then
11072 -- If no rendezvous is possible, the else part is executed
11074 Lab := Make_And_Declare_Label (0);
11075 Alt_Stats := New_List (
11076 Make_Goto_Statement (Loc,
11077 Name => New_Copy (Identifier (Lab))));
11079 Append (Lab, Trailing_List);
11080 Append_List (Else_Statements (N), Trailing_List);
11081 Append_To (Trailing_List,
11082 Make_Goto_Statement (Loc,
11083 Name => New_Copy (Identifier (End_Lab))));
11085 Alt_Stats := New_List (
11086 Make_Goto_Statement (Loc,
11087 Name => New_Copy (Identifier (End_Lab))));
11090 Append_To (Alt_List,
11091 Make_Case_Statement_Alternative (Loc,
11092 Discrete_Choices => Choices,
11093 Statements => Alt_Stats));
11095 -- We make use of the fact that Accept_Index is an integer type, and
11096 -- generate successive literals for entries for each accept. Only those
11097 -- for which there is a body or trailing statements get a case entry.
11099 Alt := First (Select_Alternatives (N));
11100 Proc := First (Body_List);
11101 while Present (Alt) loop
11103 if Nkind (Alt) = N_Accept_Alternative then
11104 Process_Accept_Alternative (Alt, Index, Proc);
11105 Index := Index + 1;
11108 (Handled_Statement_Sequence (Accept_Statement (Alt)))
11113 elsif Nkind (Alt) = N_Delay_Alternative then
11114 Process_Delay_Alternative (Alt, Delay_Num);
11115 Delay_Num := Delay_Num + 1;
11121 -- An others choice is always added to the main case, as well
11122 -- as the delay case (to satisfy the compiler).
11124 Append_To (Alt_List,
11125 Make_Case_Statement_Alternative (Loc,
11126 Discrete_Choices =>
11127 New_List (Make_Others_Choice (Loc)),
11129 New_List (Make_Goto_Statement (Loc,
11130 Name => New_Copy (Identifier (End_Lab))))));
11132 Accept_Case := New_List (
11133 Make_Case_Statement (Loc,
11134 Expression => New_Occurrence_Of (Xnam, Loc),
11135 Alternatives => Alt_List));
11137 Append_List (Trailing_List, Accept_Case);
11138 Append_List (Body_List, Decls);
11140 -- Construct case statement for trailing statements of delay
11141 -- alternatives, if there are several of them.
11143 if Delay_Count > 1 then
11144 Append_To (Delay_Alt_List,
11145 Make_Case_Statement_Alternative (Loc,
11146 Discrete_Choices =>
11147 New_List (Make_Others_Choice (Loc)),
11149 New_List (Make_Null_Statement (Loc))));
11151 Delay_Case := New_List (
11152 Make_Case_Statement (Loc,
11153 Expression => New_Occurrence_Of (Delay_Index, Loc),
11154 Alternatives => Delay_Alt_List));
11156 Delay_Case := Delay_Alt_List;
11159 -- If there are no delay alternatives, we append the case statement
11160 -- to the statement list.
11162 if Delay_Count = 0 then
11163 Append_List (Accept_Case, Stats);
11165 -- Delay alternatives present
11168 -- If delay alternatives are present we generate:
11170 -- find minimum delay.
11171 -- DX := minimum delay;
11172 -- M := <delay mode>;
11173 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11176 -- if X = No_Rendezvous then
11177 -- case statement for delay statements.
11179 -- case statement for accept alternatives.
11190 -- The type of the delay expression is known to be legal
11192 if Time_Type = Standard_Duration then
11193 Conv := New_Occurrence_Of (Delay_Min, Loc);
11195 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11196 Conv := Make_Function_Call (Loc,
11197 New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
11198 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11202 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11204 Conv := Make_Function_Call (Loc,
11205 New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
11206 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11209 Stmt := Make_Assignment_Statement (Loc,
11210 Name => New_Occurrence_Of (D, Loc),
11211 Expression => Conv);
11213 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11215 Parms := Parameter_Associations (Select_Call);
11216 Parm := First (Parms);
11218 while Present (Parm) and then Parm /= Select_Mode loop
11222 pragma Assert (Present (Parm));
11223 Rewrite (Parm, New_Occurrence_Of (RTE (RE_Delay_Mode), Loc));
11226 -- Prepare two new parameters of Duration and Delay_Mode type
11227 -- which represent the value and the mode of the minimum delay.
11230 Insert_After (Parm, New_Occurrence_Of (M, Loc));
11231 Insert_After (Parm, New_Occurrence_Of (D, Loc));
11233 -- Create a call to RTS
11235 Rewrite (Select_Call,
11236 Make_Procedure_Call_Statement (Loc,
11237 Name => New_Occurrence_Of (RTE (RE_Timed_Selective_Wait), Loc),
11238 Parameter_Associations => Parms));
11240 -- This new call should follow the calculation of the minimum
11243 Insert_List_Before (Select_Call, Delay_List);
11245 if Check_Guard then
11247 Make_Implicit_If_Statement (N,
11248 Condition => New_Occurrence_Of (Guard_Open, Loc),
11249 Then_Statements => New_List (
11250 New_Copy_Tree (Stmt),
11251 New_Copy_Tree (Select_Call)),
11252 Else_Statements => Accept_Or_Raise);
11253 Rewrite (Select_Call, Stmt);
11255 Insert_Before (Select_Call, Stmt);
11259 Make_Implicit_If_Statement (N,
11260 Condition => Make_Op_Eq (Loc,
11261 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
11263 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
11265 Then_Statements => Delay_Case,
11266 Else_Statements => Accept_Case);
11268 Append (Cases, Stats);
11271 Append (End_Lab, Stats);
11273 -- Replace accept statement with appropriate block
11276 Make_Block_Statement (Loc,
11277 Declarations => Decls,
11278 Handled_Statement_Sequence =>
11279 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats)));
11282 -- Note: have to worry more about abort deferral in above code ???
11284 -- Final step is to unstack the Accept_Address entries for all accept
11285 -- statements appearing in accept alternatives in the select statement
11287 Alt := First (Alts);
11288 while Present (Alt) loop
11289 if Nkind (Alt) = N_Accept_Alternative then
11290 Remove_Last_Elmt (Accept_Address
11291 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
11296 end Expand_N_Selective_Accept;
11298 --------------------------------------
11299 -- Expand_N_Single_Task_Declaration --
11300 --------------------------------------
11302 -- Single task declarations should never be present after semantic
11303 -- analysis, since we expect them to be replaced by a declaration of an
11304 -- anonymous task type, followed by a declaration of the task object. We
11305 -- include this routine to make sure that is happening.
11307 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
11309 raise Program_Error;
11310 end Expand_N_Single_Task_Declaration;
11312 ------------------------
11313 -- Expand_N_Task_Body --
11314 ------------------------
11316 -- Given a task body
11318 -- task body tname is
11324 -- This expansion routine converts it into a procedure and sets the
11325 -- elaboration flag for the procedure to true, to represent the fact
11326 -- that the task body is now elaborated:
11328 -- procedure tnameB (_Task : access tnameV) is
11329 -- discriminal : dtype renames _Task.discriminant;
11331 -- procedure _clean is
11333 -- Abort_Defer.all;
11335 -- Abort_Undefer.all;
11340 -- Abort_Undefer.all;
11342 -- System.Task_Stages.Complete_Activation;
11350 -- In addition, if the task body is an activator, then a call to activate
11351 -- tasks is added at the start of the statements, before the call to
11352 -- Complete_Activation, and if in addition the task is a master then it
11353 -- must be established as a master. These calls are inserted and analyzed
11354 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11357 -- There is one discriminal declaration line generated for each
11358 -- discriminant that is present to provide an easy reference point for
11359 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11361 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11362 -- task body procedures have a profile (Arg : System.Address). That is
11363 -- needed because GNARLI has to use the same access-to-subprogram type
11364 -- for all task types. We depend here on knowing that in GNAT, passing
11365 -- an address argument by value is identical to passing a record value
11366 -- by access (in either case a single pointer is passed), so even though
11367 -- this procedure has the wrong profile. In fact it's all OK, since the
11368 -- callings sequence is identical.
11370 procedure Expand_N_Task_Body (N : Node_Id) is
11371 Loc : constant Source_Ptr := Sloc (N);
11372 Ttyp : constant Entity_Id := Corresponding_Spec (N);
11376 Insert_Nod : Node_Id;
11377 -- Used to determine the proper location of wrapper body insertions
11380 -- Add renaming declarations for discriminals and a declaration for the
11381 -- entry family index (if applicable).
11383 Install_Private_Data_Declarations
11384 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
11386 -- Add a call to Abort_Undefer at the very beginning of the task
11387 -- body since this body is called with abort still deferred.
11389 if Abort_Allowed then
11390 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
11392 (First (Statements (Handled_Statement_Sequence (N))), Call);
11396 -- The statement part has already been protected with an at_end and
11397 -- cleanup actions. The call to Complete_Activation must be placed
11398 -- at the head of the sequence of statements of that block. The
11399 -- declarations have been merged in this sequence of statements but
11400 -- the first real statement is accessible from the First_Real_Statement
11401 -- field (which was set for exactly this purpose).
11403 if Restricted_Profile then
11404 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
11406 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
11410 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
11414 Make_Subprogram_Body (Loc,
11415 Specification => Build_Task_Proc_Specification (Ttyp),
11416 Declarations => Declarations (N),
11417 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
11419 -- If the task contains generic instantiations, cleanup actions are
11420 -- delayed until after instantiation. Transfer the activation chain to
11421 -- the subprogram, to insure that the activation call is properly
11422 -- generated. It the task body contains inner tasks, indicate that the
11423 -- subprogram is a task master.
11425 if Delay_Cleanups (Ttyp) then
11426 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
11427 Set_Is_Task_Master (New_N, Is_Task_Master (N));
11430 Rewrite (N, New_N);
11433 -- Set elaboration flag immediately after task body. If the body is a
11434 -- subunit, the flag is set in the declarative part containing the stub.
11436 if Nkind (Parent (N)) /= N_Subunit then
11438 Make_Assignment_Statement (Loc,
11440 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
11441 Expression => New_Occurrence_Of (Standard_True, Loc)));
11444 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11445 -- the task body. At this point all wrapper specs have been created,
11446 -- frozen and included in the dispatch table for the task type.
11448 if Ada_Version >= Ada_2005 then
11449 if Nkind (Parent (N)) = N_Subunit then
11450 Insert_Nod := Corresponding_Stub (Parent (N));
11455 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
11457 end Expand_N_Task_Body;
11459 ------------------------------------
11460 -- Expand_N_Task_Type_Declaration --
11461 ------------------------------------
11463 -- We have several things to do. First we must create a Boolean flag used
11464 -- to mark if the body is elaborated yet. This variable gets set to True
11465 -- when the body of the task is elaborated (we can't rely on the normal
11466 -- ABE mechanism for the task body, since we need to pass an access to
11467 -- this elaboration boolean to the runtime routines).
11469 -- taskE : aliased Boolean := False;
11471 -- Next a variable is declared to hold the task stack size (either the
11472 -- default : Unspecified_Size, or a value that is set by a pragma
11473 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11474 -- the variable is initialized with this value:
11476 -- taskZ : Size_Type := Unspecified_Size;
11478 -- taskZ : Size_Type := Size_Type (size_expression);
11480 -- Note: No variable is needed to hold the task relative deadline since
11481 -- its value would never be static because the parameter is of a private
11482 -- type (Ada.Real_Time.Time_Span).
11484 -- Next we create a corresponding record type declaration used to represent
11485 -- values of this task. The general form of this type declaration is
11487 -- type taskV (discriminants) is record
11488 -- _Task_Id : Task_Id;
11489 -- entry_family : array (bounds) of Void;
11490 -- _Priority : Integer := priority_expression;
11491 -- _Size : Size_Type := size_expression;
11492 -- _Task_Info : Task_Info_Type := task_info_expression;
11493 -- _CPU : Integer := cpu_range_expression;
11494 -- _Relative_Deadline : Time_Span := time_span_expression;
11495 -- _Domain : Dispatching_Domain := dd_expression;
11498 -- The discriminants are present only if the corresponding task type has
11499 -- discriminants, and they exactly mirror the task type discriminants.
11501 -- The Id field is always present. It contains the Task_Id value, as set by
11502 -- the call to Create_Task. Note that although the task is limited, the
11503 -- task value record type is not limited, so there is no problem in passing
11504 -- this field as an out parameter to Create_Task.
11506 -- One entry_family component is present for each entry family in the task
11507 -- definition. The bounds correspond to the bounds of the entry family
11508 -- (which may depend on discriminants). The element type is void, since we
11509 -- only need the bounds information for determining the entry index. Note
11510 -- that the use of an anonymous array would normally be illegal in this
11511 -- context, but this is a parser check, and the semantics is quite prepared
11512 -- to handle such a case.
11514 -- The _Size field is present only if a Storage_Size pragma appears in the
11515 -- task definition. The expression captures the argument that was present
11516 -- in the pragma, and is used to override the task stack size otherwise
11517 -- associated with the task type.
11519 -- The _Priority field is present only if the task entity has a Priority or
11520 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11521 -- definition clause). It will be filled at the freeze point, when the
11522 -- record init proc is built, to capture the expression of the rep item
11523 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11524 -- here since aspect evaluations are delayed till the freeze point.
11526 -- The _Task_Info field is present only if a Task_Info pragma appears in
11527 -- the task definition. The expression captures the argument that was
11528 -- present in the pragma, and is used to provide the Task_Image parameter
11529 -- to the call to Create_Task.
11531 -- The _CPU field is present only if the task entity has a CPU rep item
11532 -- (pragma, aspect specification or attribute definition clause). It will
11533 -- be filled at the freeze point, when the record init proc is built, to
11534 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11535 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11536 -- are delayed till the freeze point.
11538 -- The _Relative_Deadline field is present only if a Relative_Deadline
11539 -- pragma appears in the task definition. The expression captures the
11540 -- argument that was present in the pragma, and is used to provide the
11541 -- Relative_Deadline parameter to the call to Create_Task.
11543 -- The _Domain field is present only if the task entity has a
11544 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11545 -- definition clause). It will be filled at the freeze point, when the
11546 -- record init proc is built, to capture the expression of the rep item
11547 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11548 -- here since aspect evaluations are delayed till the freeze point.
11550 -- When a task is declared, an instance of the task value record is
11551 -- created. The elaboration of this declaration creates the correct bounds
11552 -- for the entry families, and also evaluates the size, priority, and
11553 -- task_Info expressions if needed. The initialization routine for the task
11554 -- type itself then calls Create_Task with appropriate parameters to
11555 -- initialize the value of the Task_Id field.
11557 -- Note: the address of this record is passed as the "Discriminants"
11558 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11559 -- body procedure, it does not matter that it does not quite match the
11560 -- GNARLI model of what is being passed (the record contains more than just
11561 -- the discriminants, but the discriminants can be found from the record
11564 -- The Entity_Id for this created record type is placed in the
11565 -- Corresponding_Record_Type field of the associated task type entity.
11567 -- Next we create a procedure specification for the task body procedure:
11569 -- procedure taskB (_Task : access taskV);
11571 -- Note that this must come after the record type declaration, since
11572 -- the spec refers to this type. It turns out that the initialization
11573 -- procedure for the value type references the task body spec, but that's
11574 -- fine, since it won't be generated till the freeze point for the type,
11575 -- which is certainly after the task body spec declaration.
11577 -- Finally, we set the task index value field of the entry attribute in
11578 -- the case of a simple entry.
11580 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
11581 Loc : constant Source_Ptr := Sloc (N);
11582 TaskId : constant Entity_Id := Defining_Identifier (N);
11583 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
11584 Tasknm : constant Name_Id := Chars (Tasktyp);
11585 Taskdef : constant Node_Id := Task_Definition (N);
11587 Body_Decl : Node_Id;
11589 Decl_Stack : Node_Id;
11590 Elab_Decl : Node_Id;
11591 Ent_Stack : Entity_Id;
11592 Proc_Spec : Node_Id;
11593 Rec_Decl : Node_Id;
11594 Rec_Ent : Entity_Id;
11595 Size_Decl : Entity_Id;
11596 Task_Size : Node_Id;
11598 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id;
11599 -- Searches the task definition T for the first occurrence of the pragma
11600 -- Relative Deadline. The caller has ensured that the pragma is present
11601 -- in the task definition. Note that this routine cannot be implemented
11602 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11603 -- not chained because their expansion into a procedure call statement
11604 -- would cause a break in the chain.
11606 ----------------------------------
11607 -- Get_Relative_Deadline_Pragma --
11608 ----------------------------------
11610 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id is
11614 N := First (Visible_Declarations (T));
11615 while Present (N) loop
11616 if Nkind (N) = N_Pragma
11617 and then Pragma_Name (N) = Name_Relative_Deadline
11625 N := First (Private_Declarations (T));
11626 while Present (N) loop
11627 if Nkind (N) = N_Pragma
11628 and then Pragma_Name (N) = Name_Relative_Deadline
11636 raise Program_Error;
11637 end Get_Relative_Deadline_Pragma;
11639 -- Start of processing for Expand_N_Task_Type_Declaration
11642 -- If already expanded, nothing to do
11644 if Present (Corresponding_Record_Type (Tasktyp)) then
11648 -- Here we will do the expansion
11650 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
11652 Rec_Ent := Defining_Identifier (Rec_Decl);
11653 Cdecls := Component_Items (Component_List
11654 (Type_Definition (Rec_Decl)));
11656 Qualify_Entity_Names (N);
11658 -- First create the elaboration variable
11661 Make_Object_Declaration (Loc,
11662 Defining_Identifier =>
11663 Make_Defining_Identifier (Sloc (Tasktyp),
11664 Chars => New_External_Name (Tasknm, 'E')),
11665 Aliased_Present => True,
11666 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
11667 Expression => New_Occurrence_Of (Standard_False, Loc));
11669 Insert_After (N, Elab_Decl);
11671 -- Next create the declaration of the size variable (tasknmZ)
11673 Set_Storage_Size_Variable (Tasktyp,
11674 Make_Defining_Identifier (Sloc (Tasktyp),
11675 Chars => New_External_Name (Tasknm, 'Z')));
11677 if Present (Taskdef)
11678 and then Has_Storage_Size_Pragma (Taskdef)
11680 Is_OK_Static_Expression
11682 (First (Pragma_Argument_Associations
11683 (Get_Rep_Pragma (TaskId, Name_Storage_Size)))))
11686 Make_Object_Declaration (Loc,
11687 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11688 Object_Definition =>
11689 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11691 Convert_To (RTE (RE_Size_Type),
11693 (Expression (First (Pragma_Argument_Associations
11695 (TaskId, Name_Storage_Size)))))));
11699 Make_Object_Declaration (Loc,
11700 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11701 Object_Definition =>
11702 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11704 New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
11707 Insert_After (Elab_Decl, Size_Decl);
11709 -- Next build the rest of the corresponding record declaration. This is
11710 -- done last, since the corresponding record initialization procedure
11711 -- will reference the previously created entities.
11713 -- Fill in the component declarations -- first the _Task_Id field
11716 Make_Component_Declaration (Loc,
11717 Defining_Identifier =>
11718 Make_Defining_Identifier (Loc, Name_uTask_Id),
11719 Component_Definition =>
11720 Make_Component_Definition (Loc,
11721 Aliased_Present => False,
11722 Subtype_Indication => New_Occurrence_Of (RTE (RO_ST_Task_Id),
11725 -- Declare static ATCB (that is, created by the expander) if we are
11726 -- using the Restricted run time.
11728 if Restricted_Profile then
11730 Make_Component_Declaration (Loc,
11731 Defining_Identifier =>
11732 Make_Defining_Identifier (Loc, Name_uATCB),
11734 Component_Definition =>
11735 Make_Component_Definition (Loc,
11736 Aliased_Present => True,
11737 Subtype_Indication => Make_Subtype_Indication (Loc,
11739 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
11742 Make_Index_Or_Discriminant_Constraint (Loc,
11744 New_List (Make_Integer_Literal (Loc, 0)))))));
11748 -- Declare static stack (that is, created by the expander) if we are
11749 -- using the Restricted run time on a bare board configuration.
11751 if Restricted_Profile
11752 and then Preallocated_Stacks_On_Target
11754 -- First we need to extract the appropriate stack size
11756 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
11758 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11760 Expr_N : constant Node_Id :=
11761 Expression (First (
11762 Pragma_Argument_Associations (
11763 Get_Rep_Pragma (TaskId, Name_Storage_Size))));
11764 Etyp : constant Entity_Id := Etype (Expr_N);
11765 P : constant Node_Id := Parent (Expr_N);
11768 -- The stack is defined inside the corresponding record.
11769 -- Therefore if the size of the stack is set by means of
11770 -- a discriminant, we must reference the discriminant of the
11771 -- corresponding record type.
11773 if Nkind (Expr_N) in N_Has_Entity
11774 and then Present (Discriminal_Link (Entity (Expr_N)))
11778 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
11780 Set_Parent (Task_Size, P);
11781 Set_Etype (Task_Size, Etyp);
11782 Set_Analyzed (Task_Size);
11785 Task_Size := Relocate_Node (Expr_N);
11791 New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc);
11794 Decl_Stack := Make_Component_Declaration (Loc,
11795 Defining_Identifier => Ent_Stack,
11797 Component_Definition =>
11798 Make_Component_Definition (Loc,
11799 Aliased_Present => True,
11800 Subtype_Indication => Make_Subtype_Indication (Loc,
11802 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
11805 Make_Index_Or_Discriminant_Constraint (Loc,
11806 Constraints => New_List (Make_Range (Loc,
11807 Low_Bound => Make_Integer_Literal (Loc, 1),
11808 High_Bound => Convert_To (RTE (RE_Storage_Offset),
11811 Append_To (Cdecls, Decl_Stack);
11813 -- The appropriate alignment for the stack is ensured by the run-time
11814 -- code in charge of task creation.
11818 -- Add components for entry families
11820 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
11822 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11823 -- item is present.
11825 if Has_Rep_Item (TaskId, Name_Priority, Check_Parents => False) then
11827 Make_Component_Declaration (Loc,
11828 Defining_Identifier =>
11829 Make_Defining_Identifier (Loc, Name_uPriority),
11830 Component_Definition =>
11831 Make_Component_Definition (Loc,
11832 Aliased_Present => False,
11833 Subtype_Indication =>
11834 New_Occurrence_Of (Standard_Integer, Loc))));
11837 -- Add the _Size component if a Storage_Size pragma is present
11839 if Present (Taskdef)
11840 and then Has_Storage_Size_Pragma (Taskdef)
11843 Make_Component_Declaration (Loc,
11844 Defining_Identifier =>
11845 Make_Defining_Identifier (Loc, Name_uSize),
11847 Component_Definition =>
11848 Make_Component_Definition (Loc,
11849 Aliased_Present => False,
11850 Subtype_Indication =>
11851 New_Occurrence_Of (RTE (RE_Size_Type), Loc)),
11854 Convert_To (RTE (RE_Size_Type),
11856 Expression (First (
11857 Pragma_Argument_Associations (
11858 Get_Rep_Pragma (TaskId, Name_Storage_Size))))))));
11861 -- Add the _Task_Info component if a Task_Info pragma is present
11863 if Has_Rep_Pragma (TaskId, Name_Task_Info, Check_Parents => False) then
11865 Make_Component_Declaration (Loc,
11866 Defining_Identifier =>
11867 Make_Defining_Identifier (Loc, Name_uTask_Info),
11869 Component_Definition =>
11870 Make_Component_Definition (Loc,
11871 Aliased_Present => False,
11872 Subtype_Indication =>
11873 New_Occurrence_Of (RTE (RE_Task_Info_Type), Loc)),
11875 Expression => New_Copy (
11876 Expression (First (
11877 Pragma_Argument_Associations (
11879 (TaskId, Name_Task_Info, Check_Parents => False)))))));
11882 -- Add the _CPU component if a CPU rep item is present
11884 if Has_Rep_Item (TaskId, Name_CPU, Check_Parents => False) then
11886 Make_Component_Declaration (Loc,
11887 Defining_Identifier =>
11888 Make_Defining_Identifier (Loc, Name_uCPU),
11890 Component_Definition =>
11891 Make_Component_Definition (Loc,
11892 Aliased_Present => False,
11893 Subtype_Indication =>
11894 New_Occurrence_Of (RTE (RE_CPU_Range), Loc))));
11897 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11898 -- present. If we are using a restricted run time this component will
11899 -- not be added (deadlines are not allowed by the Ravenscar profile).
11901 if not Restricted_Profile
11902 and then Present (Taskdef)
11903 and then Has_Relative_Deadline_Pragma (Taskdef)
11906 Make_Component_Declaration (Loc,
11907 Defining_Identifier =>
11908 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
11910 Component_Definition =>
11911 Make_Component_Definition (Loc,
11912 Aliased_Present => False,
11913 Subtype_Indication =>
11914 New_Occurrence_Of (RTE (RE_Time_Span), Loc)),
11917 Convert_To (RTE (RE_Time_Span),
11919 Expression (First (
11920 Pragma_Argument_Associations (
11921 Get_Relative_Deadline_Pragma (Taskdef))))))));
11924 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
11925 -- item is present. If we are using a restricted run time this component
11926 -- will not be added (dispatching domains are not allowed by the
11927 -- Ravenscar profile).
11929 if not Restricted_Profile
11932 (TaskId, Name_Dispatching_Domain, Check_Parents => False)
11935 Make_Component_Declaration (Loc,
11936 Defining_Identifier =>
11937 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
11939 Component_Definition =>
11940 Make_Component_Definition (Loc,
11941 Aliased_Present => False,
11942 Subtype_Indication =>
11944 (RTE (RE_Dispatching_Domain_Access), Loc))));
11947 Insert_After (Size_Decl, Rec_Decl);
11949 -- Analyze the record declaration immediately after construction,
11950 -- because the initialization procedure is needed for single task
11951 -- declarations before the next entity is analyzed.
11953 Analyze (Rec_Decl);
11955 -- Create the declaration of the task body procedure
11957 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
11959 Make_Subprogram_Declaration (Loc,
11960 Specification => Proc_Spec);
11962 Insert_After (Rec_Decl, Body_Decl);
11964 -- The subprogram does not comes from source, so we have to indicate the
11965 -- need for debugging information explicitly.
11967 if Comes_From_Source (Original_Node (N)) then
11968 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
11971 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
11972 -- the corresponding record has been frozen.
11974 if Ada_Version >= Ada_2005 then
11975 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
11978 -- Ada 2005 (AI-345): We must defer freezing to allow further
11979 -- declaration of primitive subprograms covering task interfaces
11981 if Ada_Version <= Ada_95 then
11983 -- Now we can freeze the corresponding record. This needs manually
11984 -- freezing, since it is really part of the task type, and the task
11985 -- type is frozen at this stage. We of course need the initialization
11986 -- procedure for this corresponding record type and we won't get it
11987 -- in time if we don't freeze now.
11990 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
11992 if Is_Non_Empty_List (L) then
11993 Insert_List_After (Body_Decl, L);
11998 -- Complete the expansion of access types to the current task type, if
11999 -- any were declared.
12001 Expand_Previous_Access_Type (Tasktyp);
12003 -- Create wrappers for entries that have pre/postconditions
12009 Ent := First_Entity (Tasktyp);
12010 while Present (Ent) loop
12011 if Ekind_In (Ent, E_Entry, E_Entry_Family)
12012 and then Present (Pre_Post_Conditions (Contract (Ent)))
12014 Build_PPC_Wrapper (Ent, N);
12020 end Expand_N_Task_Type_Declaration;
12022 -------------------------------
12023 -- Expand_N_Timed_Entry_Call --
12024 -------------------------------
12026 -- A timed entry call in normal case is not implemented using ATC mechanism
12027 -- anymore for efficiency reason.
12037 -- is expanded as follows:
12039 -- 1) When T.E is a task entry_call;
12043 -- X : Task_Entry_Index := <entry index>;
12044 -- DX : Duration := To_Duration (D);
12045 -- M : Delay_Mode := <discriminant>;
12046 -- P : parms := (parm, parm, parm);
12049 -- Timed_Protected_Entry_Call
12050 -- (<acceptor-task>, X, P'Address, DX, M, B);
12058 -- 2) When T.E is a protected entry_call;
12062 -- X : Protected_Entry_Index := <entry index>;
12063 -- DX : Duration := To_Duration (D);
12064 -- M : Delay_Mode := <discriminant>;
12065 -- P : parms := (parm, parm, parm);
12068 -- Timed_Protected_Entry_Call
12069 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12077 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12078 -- is no delay and the triggering statements are executed. We first
12079 -- determine the kind of of the triggering call and then execute a
12080 -- synchronized operation or a direct call.
12083 -- B : Boolean := False;
12084 -- C : Ada.Tags.Prim_Op_Kind;
12085 -- DX : Duration := To_Duration (D)
12086 -- K : Ada.Tags.Tagged_Kind :=
12087 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12088 -- M : Integer :=...;
12089 -- P : Parameters := (Param1 .. ParamN);
12093 -- if K = Ada.Tags.TK_Limited_Tagged
12094 -- or else K = Ada.Tags.TK_Tagged
12096 -- <dispatching-call>;
12101 -- Ada.Tags.Get_Offset_Index
12102 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12104 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12106 -- if C = POK_Protected_Entry
12107 -- or else C = POK_Task_Entry
12109 -- Param1 := P.Param1;
12111 -- ParamN := P.ParamN;
12115 -- if C = POK_Procedure
12116 -- or else C = POK_Protected_Procedure
12117 -- or else C = POK_Task_Procedure
12119 -- <dispatching-call>;
12125 -- <triggering-statements>
12127 -- <timed-statements>
12131 -- The triggering statement and the sequence of timed statements have not
12132 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12133 -- global references if within an instantiation.
12135 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
12136 Loc : constant Source_Ptr := Sloc (N);
12139 Blk_Typ : Entity_Id;
12141 Call_Ent : Entity_Id;
12142 Conc_Typ_Stmts : List_Id;
12144 D_Alt : constant Node_Id := Delay_Alternative (N);
12147 D_Stat : Node_Id := Delay_Statement (D_Alt);
12149 D_Type : Entity_Id;
12152 E_Alt : constant Node_Id := Entry_Call_Alternative (N);
12153 E_Call : Node_Id := Entry_Call_Statement (E_Alt);
12158 Is_Disp_Select : Boolean;
12159 Lim_Typ_Stmts : List_Id;
12168 B : Entity_Id; -- Call status flag
12169 C : Entity_Id; -- Call kind
12170 D : Entity_Id; -- Delay
12171 K : Entity_Id; -- Tagged kind
12172 M : Entity_Id; -- Delay mode
12173 P : Entity_Id; -- Parameter block
12174 S : Entity_Id; -- Primitive operation slot
12176 -- Start of processing for Expand_N_Timed_Entry_Call
12179 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12180 -- was already reported on spec, so do not attempt to expand the call.
12182 if Restriction_Active (No_Select_Statements) then
12186 Process_Statements_For_Controlled_Objects (E_Alt);
12187 Process_Statements_For_Controlled_Objects (D_Alt);
12189 Ensure_Statement_Present (Sloc (D_Stat), D_Alt);
12191 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12192 -- may wrap them in blocks.
12194 E_Stats := Statements (E_Alt);
12195 D_Stats := Statements (D_Alt);
12197 -- The arguments in the call may require dynamic allocation, and the
12198 -- call statement may have been transformed into a block. The block
12199 -- may contain additional declarations for internal entities, and the
12200 -- original call is found by sequential search.
12202 if Nkind (E_Call) = N_Block_Statement then
12203 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
12204 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
12205 N_Entry_Call_Statement)
12212 Ada_Version >= Ada_2005
12213 and then Nkind (E_Call) = N_Procedure_Call_Statement;
12215 if Is_Disp_Select then
12216 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
12222 -- B : Boolean := False;
12224 B := Build_B (Loc, Decls);
12227 -- C : Ada.Tags.Prim_Op_Kind;
12229 C := Build_C (Loc, Decls);
12231 -- Because the analysis of all statements was disabled, manually
12232 -- analyze the delay statement.
12235 D_Stat := Original_Node (D_Stat);
12238 -- Build an entry call using Simple_Entry_Call
12240 Extract_Entry (E_Call, Concval, Ename, Index);
12241 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
12243 Decls := Declarations (E_Call);
12244 Stmts := Statements (Handled_Statement_Sequence (E_Call));
12253 B := Make_Defining_Identifier (Loc, Name_uB);
12256 Make_Object_Declaration (Loc,
12257 Defining_Identifier => B,
12258 Object_Definition =>
12259 New_Occurrence_Of (Standard_Boolean, Loc)));
12262 -- Duration and mode processing
12264 D_Type := Base_Type (Etype (Expression (D_Stat)));
12266 -- Use the type of the delay expression (Calendar or Real_Time) to
12267 -- generate the appropriate conversion.
12269 if Nkind (D_Stat) = N_Delay_Relative_Statement then
12270 D_Disc := Make_Integer_Literal (Loc, 0);
12271 D_Conv := Relocate_Node (Expression (D_Stat));
12273 elsif Is_RTE (D_Type, RO_CA_Time) then
12274 D_Disc := Make_Integer_Literal (Loc, 1);
12276 Make_Function_Call (Loc,
12277 Name => New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
12278 Parameter_Associations =>
12279 New_List (New_Copy (Expression (D_Stat))));
12281 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
12282 D_Disc := Make_Integer_Literal (Loc, 2);
12284 Make_Function_Call (Loc,
12285 Name => New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
12286 Parameter_Associations =>
12287 New_List (New_Copy (Expression (D_Stat))));
12290 D := Make_Temporary (Loc, 'D');
12296 Make_Object_Declaration (Loc,
12297 Defining_Identifier => D,
12298 Object_Definition => New_Occurrence_Of (Standard_Duration, Loc)));
12300 M := Make_Temporary (Loc, 'M');
12303 -- M : Integer := (0 | 1 | 2);
12306 Make_Object_Declaration (Loc,
12307 Defining_Identifier => M,
12308 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
12309 Expression => D_Disc));
12311 -- Do the assignment at this stage only because the evaluation of the
12312 -- expression must not occur before (see ACVC C97302A).
12315 Make_Assignment_Statement (Loc,
12316 Name => New_Occurrence_Of (D, Loc),
12317 Expression => D_Conv));
12319 -- Parameter block processing
12321 -- Manually create the parameter block for dispatching calls. In the
12322 -- case of entries, the block has already been created during the call
12323 -- to Build_Simple_Entry_Call.
12325 if Is_Disp_Select then
12327 -- Tagged kind processing, generate:
12328 -- K : Ada.Tags.Tagged_Kind :=
12329 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12331 K := Build_K (Loc, Decls, Obj);
12333 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
12335 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
12337 -- Dispatch table slot processing, generate:
12340 S := Build_S (Loc, Decls);
12343 -- S := Ada.Tags.Get_Offset_Index
12344 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12347 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
12350 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12352 -- where Obj is the controlling formal parameter, S is the dispatch
12353 -- table slot number of the dispatching operation, P is the wrapped
12354 -- parameter block, D is the duration, M is the duration mode, C is
12355 -- the call kind and B is the call status.
12357 Params := New_List;
12359 Append_To (Params, New_Copy_Tree (Obj));
12360 Append_To (Params, New_Occurrence_Of (S, Loc));
12362 Make_Attribute_Reference (Loc,
12363 Prefix => New_Occurrence_Of (P, Loc),
12364 Attribute_Name => Name_Address));
12365 Append_To (Params, New_Occurrence_Of (D, Loc));
12366 Append_To (Params, New_Occurrence_Of (M, Loc));
12367 Append_To (Params, New_Occurrence_Of (C, Loc));
12368 Append_To (Params, New_Occurrence_Of (B, Loc));
12370 Append_To (Conc_Typ_Stmts,
12371 Make_Procedure_Call_Statement (Loc,
12375 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
12376 Parameter_Associations => Params));
12379 -- if C = POK_Protected_Entry
12380 -- or else C = POK_Task_Entry
12382 -- Param1 := P.Param1;
12384 -- ParamN := P.ParamN;
12387 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
12389 -- Generate the if statement only when the packed parameters need
12390 -- explicit assignments to their corresponding actuals.
12392 if Present (Unpack) then
12393 Append_To (Conc_Typ_Stmts,
12394 Make_Implicit_If_Statement (N,
12400 Left_Opnd => New_Occurrence_Of (C, Loc),
12403 (RTE (RE_POK_Protected_Entry), Loc)),
12407 Left_Opnd => New_Occurrence_Of (C, Loc),
12409 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
12411 Then_Statements => Unpack));
12417 -- if C = POK_Procedure
12418 -- or else C = POK_Protected_Procedure
12419 -- or else C = POK_Task_Procedure
12421 -- <dispatching-call>
12425 N_Stats := New_List (
12426 Make_Implicit_If_Statement (N,
12431 Left_Opnd => New_Occurrence_Of (C, Loc),
12433 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
12439 Left_Opnd => New_Occurrence_Of (C, Loc),
12441 New_Occurrence_Of (RTE (
12442 RE_POK_Protected_Procedure), Loc)),
12445 Left_Opnd => New_Occurrence_Of (C, Loc),
12448 (RTE (RE_POK_Task_Procedure), Loc)))),
12450 Then_Statements => New_List (E_Call)));
12452 Append_To (Conc_Typ_Stmts,
12453 Make_Implicit_If_Statement (N,
12454 Condition => New_Occurrence_Of (B, Loc),
12455 Then_Statements => N_Stats));
12458 -- <dispatching-call>;
12462 New_List (New_Copy_Tree (E_Call),
12463 Make_Assignment_Statement (Loc,
12464 Name => New_Occurrence_Of (B, Loc),
12465 Expression => New_Occurrence_Of (Standard_True, Loc)));
12468 -- if K = Ada.Tags.TK_Limited_Tagged
12469 -- or else K = Ada.Tags.TK_Tagged
12477 Make_Implicit_If_Statement (N,
12478 Condition => Build_Dispatching_Tag_Check (K, N),
12479 Then_Statements => Lim_Typ_Stmts,
12480 Else_Statements => Conc_Typ_Stmts));
12485 -- <triggering-statements>
12487 -- <timed-statements>
12491 Make_Implicit_If_Statement (N,
12492 Condition => New_Occurrence_Of (B, Loc),
12493 Then_Statements => E_Stats,
12494 Else_Statements => D_Stats));
12497 -- Simple case of a non-dispatching trigger. Skip assignments to
12498 -- temporaries created for in-out parameters.
12500 -- This makes unwarranted assumptions about the shape of the expanded
12501 -- tree for the call, and should be cleaned up ???
12503 Stmt := First (Stmts);
12504 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
12508 -- Do the assignment at this stage only because the evaluation
12509 -- of the expression must not occur before (see ACVC C97302A).
12511 Insert_Before (Stmt,
12512 Make_Assignment_Statement (Loc,
12513 Name => New_Occurrence_Of (D, Loc),
12514 Expression => D_Conv));
12517 Params := Parameter_Associations (Call);
12519 -- For a protected type, we build a Timed_Protected_Entry_Call
12521 if Is_Protected_Type (Etype (Concval)) then
12523 -- Create a new call statement
12525 Param := First (Params);
12526 while Present (Param)
12527 and then not Is_RTE (Etype (Param), RE_Call_Modes)
12532 Dummy := Remove_Next (Next (Param));
12534 -- Remove garbage is following the Cancel_Param if present
12536 Dummy := Next (Param);
12538 -- Remove the mode of the Protected_Entry_Call call, then remove
12539 -- the Communication_Block of the Protected_Entry_Call call, and
12540 -- finally add Duration and a Delay_Mode parameter
12542 pragma Assert (Present (Param));
12543 Rewrite (Param, New_Occurrence_Of (D, Loc));
12545 Rewrite (Dummy, New_Occurrence_Of (M, Loc));
12547 -- Add a Boolean flag for successful entry call
12549 Append_To (Params, New_Occurrence_Of (B, Loc));
12551 case Corresponding_Runtime_Package (Etype (Concval)) is
12552 when System_Tasking_Protected_Objects_Entries =>
12554 Make_Procedure_Call_Statement (Loc,
12557 (RTE (RE_Timed_Protected_Entry_Call), Loc),
12558 Parameter_Associations => Params));
12561 raise Program_Error;
12564 -- For the task case, build a Timed_Task_Entry_Call
12567 -- Create a new call statement
12569 Append_To (Params, New_Occurrence_Of (D, Loc));
12570 Append_To (Params, New_Occurrence_Of (M, Loc));
12571 Append_To (Params, New_Occurrence_Of (B, Loc));
12574 Make_Procedure_Call_Statement (Loc,
12576 New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
12577 Parameter_Associations => Params));
12581 Make_Implicit_If_Statement (N,
12582 Condition => New_Occurrence_Of (B, Loc),
12583 Then_Statements => E_Stats,
12584 Else_Statements => D_Stats));
12588 Make_Block_Statement (Loc,
12589 Declarations => Decls,
12590 Handled_Statement_Sequence =>
12591 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
12594 end Expand_N_Timed_Entry_Call;
12596 ----------------------------------------
12597 -- Expand_Protected_Body_Declarations --
12598 ----------------------------------------
12600 procedure Expand_Protected_Body_Declarations
12602 Spec_Id : Entity_Id)
12605 if No_Run_Time_Mode then
12606 Error_Msg_CRT ("protected body", N);
12609 elsif Expander_Active then
12611 -- Associate discriminals with the first subprogram or entry body to
12614 if Present (First_Protected_Operation (Declarations (N))) then
12615 Set_Discriminals (Parent (Spec_Id));
12618 end Expand_Protected_Body_Declarations;
12620 -------------------------
12621 -- External_Subprogram --
12622 -------------------------
12624 function External_Subprogram (E : Entity_Id) return Entity_Id is
12625 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
12628 -- The internal and external subprograms follow each other on the entity
12629 -- chain. Note that previously private operations had no separate
12630 -- external subprogram. We now create one in all cases, because a
12631 -- private operation may actually appear in an external call, through
12632 -- a 'Access reference used for a callback.
12634 -- If the operation is a function that returns an anonymous access type,
12635 -- the corresponding itype appears before the operation, and must be
12638 -- This mechanism is fragile, there should be a real link between the
12639 -- two versions of the operation, but there is no place to put it ???
12641 if Is_Access_Type (Next_Entity (Subp)) then
12642 return Next_Entity (Next_Entity (Subp));
12644 return Next_Entity (Subp);
12646 end External_Subprogram;
12648 ------------------------------
12649 -- Extract_Dispatching_Call --
12650 ------------------------------
12652 procedure Extract_Dispatching_Call
12654 Call_Ent : out Entity_Id;
12655 Object : out Entity_Id;
12656 Actuals : out List_Id;
12657 Formals : out List_Id)
12659 Call_Nam : Node_Id;
12662 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
12664 if Present (Original_Node (N)) then
12665 Call_Nam := Name (Original_Node (N));
12667 Call_Nam := Name (N);
12670 -- Retrieve the name of the dispatching procedure. It contains the
12671 -- dispatch table slot number.
12674 case Nkind (Call_Nam) is
12675 when N_Identifier =>
12678 when N_Selected_Component =>
12679 Call_Nam := Selector_Name (Call_Nam);
12682 raise Program_Error;
12687 Actuals := Parameter_Associations (N);
12688 Call_Ent := Entity (Call_Nam);
12689 Formals := Parameter_Specifications (Parent (Call_Ent));
12690 Object := First (Actuals);
12692 if Present (Original_Node (Object)) then
12693 Object := Original_Node (Object);
12696 -- If the type of the dispatching object is an access type then return
12697 -- an explicit dereference.
12699 if Is_Access_Type (Etype (Object)) then
12700 Object := Make_Explicit_Dereference (Sloc (N), Object);
12703 end Extract_Dispatching_Call;
12705 -------------------
12706 -- Extract_Entry --
12707 -------------------
12709 procedure Extract_Entry
12711 Concval : out Node_Id;
12712 Ename : out Node_Id;
12713 Index : out Node_Id)
12715 Nam : constant Node_Id := Name (N);
12718 -- For a simple entry, the name is a selected component, with the
12719 -- prefix being the task value, and the selector being the entry.
12721 if Nkind (Nam) = N_Selected_Component then
12722 Concval := Prefix (Nam);
12723 Ename := Selector_Name (Nam);
12726 -- For a member of an entry family, the name is an indexed component
12727 -- where the prefix is a selected component, whose prefix in turn is
12728 -- the task value, and whose selector is the entry family. The single
12729 -- expression in the expressions list of the indexed component is the
12730 -- subscript for the family.
12732 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
12733 Concval := Prefix (Prefix (Nam));
12734 Ename := Selector_Name (Prefix (Nam));
12735 Index := First (Expressions (Nam));
12739 -------------------
12740 -- Family_Offset --
12741 -------------------
12743 function Family_Offset
12748 Cap : Boolean) return Node_Id
12754 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
12755 -- If one of the bounds is a reference to a discriminant, replace with
12756 -- corresponding discriminal of type. Within the body of a task retrieve
12757 -- the renamed discriminant by simple visibility, using its generated
12758 -- name. Within a protected object, find the original discriminant and
12759 -- replace it with the discriminal of the current protected operation.
12761 ------------------------------
12762 -- Convert_Discriminant_Ref --
12763 ------------------------------
12765 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
12766 Loc : constant Source_Ptr := Sloc (Bound);
12771 if Is_Entity_Name (Bound)
12772 and then Ekind (Entity (Bound)) = E_Discriminant
12774 if Is_Task_Type (Ttyp)
12775 and then Has_Completion (Ttyp)
12777 B := Make_Identifier (Loc, Chars (Entity (Bound)));
12778 Find_Direct_Name (B);
12780 elsif Is_Protected_Type (Ttyp) then
12781 D := First_Discriminant (Ttyp);
12782 while Chars (D) /= Chars (Entity (Bound)) loop
12783 Next_Discriminant (D);
12786 B := New_Occurrence_Of (Discriminal (D), Loc);
12789 B := New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
12792 elsif Nkind (Bound) = N_Attribute_Reference then
12796 B := New_Copy_Tree (Bound);
12800 Make_Attribute_Reference (Loc,
12801 Attribute_Name => Name_Pos,
12802 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
12803 Expressions => New_List (B));
12804 end Convert_Discriminant_Ref;
12806 -- Start of processing for Family_Offset
12809 Real_Hi := Convert_Discriminant_Ref (Hi);
12810 Real_Lo := Convert_Discriminant_Ref (Lo);
12813 if Is_Task_Type (Ttyp) then
12814 Ityp := RTE (RE_Task_Entry_Index);
12816 Ityp := RTE (RE_Protected_Entry_Index);
12820 Make_Attribute_Reference (Loc,
12821 Prefix => New_Occurrence_Of (Ityp, Loc),
12822 Attribute_Name => Name_Min,
12823 Expressions => New_List (
12825 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12828 Make_Attribute_Reference (Loc,
12829 Prefix => New_Occurrence_Of (Ityp, Loc),
12830 Attribute_Name => Name_Max,
12831 Expressions => New_List (
12833 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12836 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12843 function Family_Size
12848 Cap : Boolean) return Node_Id
12853 if Is_Task_Type (Ttyp) then
12854 Ityp := RTE (RE_Task_Entry_Index);
12856 Ityp := RTE (RE_Protected_Entry_Index);
12860 Make_Attribute_Reference (Loc,
12861 Prefix => New_Occurrence_Of (Ityp, Loc),
12862 Attribute_Name => Name_Max,
12863 Expressions => New_List (
12866 Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
12868 Make_Integer_Literal (Loc, 1)),
12869 Make_Integer_Literal (Loc, 0)));
12872 ----------------------------
12873 -- Find_Enclosing_Context --
12874 ----------------------------
12876 procedure Find_Enclosing_Context
12878 Context : out Node_Id;
12879 Context_Id : out Entity_Id;
12880 Context_Decls : out List_Id)
12883 -- Traverse the parent chain looking for an enclosing body, block,
12884 -- package or return statement.
12886 Context := Parent (N);
12887 while not Nkind_In (Context, N_Block_Statement,
12889 N_Extended_Return_Statement,
12891 N_Package_Declaration,
12895 Context := Parent (Context);
12898 -- Extract the constituents of the context
12900 if Nkind (Context) = N_Extended_Return_Statement then
12901 Context_Decls := Return_Object_Declarations (Context);
12902 Context_Id := Return_Statement_Entity (Context);
12904 -- Package declarations and bodies use a common library-level activation
12905 -- chain or task master, therefore return the package declaration as the
12906 -- proper carrier for the appropriate flag.
12908 elsif Nkind (Context) = N_Package_Body then
12909 Context_Decls := Declarations (Context);
12910 Context_Id := Corresponding_Spec (Context);
12911 Context := Parent (Context_Id);
12913 if Nkind (Context) = N_Defining_Program_Unit_Name then
12914 Context := Parent (Parent (Context));
12916 Context := Parent (Context);
12919 elsif Nkind (Context) = N_Package_Declaration then
12920 Context_Decls := Visible_Declarations (Specification (Context));
12921 Context_Id := Defining_Unit_Name (Specification (Context));
12923 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12924 Context_Id := Defining_Identifier (Context_Id);
12928 Context_Decls := Declarations (Context);
12930 if Nkind (Context) = N_Block_Statement then
12931 Context_Id := Entity (Identifier (Context));
12933 elsif Nkind (Context) = N_Entry_Body then
12934 Context_Id := Defining_Identifier (Context);
12936 elsif Nkind (Context) = N_Subprogram_Body then
12937 if Present (Corresponding_Spec (Context)) then
12938 Context_Id := Corresponding_Spec (Context);
12940 Context_Id := Defining_Unit_Name (Specification (Context));
12942 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
12943 Context_Id := Defining_Identifier (Context_Id);
12947 elsif Nkind (Context) = N_Task_Body then
12948 Context_Id := Corresponding_Spec (Context);
12951 raise Program_Error;
12955 pragma Assert (Present (Context));
12956 pragma Assert (Present (Context_Id));
12957 pragma Assert (Present (Context_Decls));
12958 end Find_Enclosing_Context;
12960 -----------------------
12961 -- Find_Master_Scope --
12962 -----------------------
12964 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
12968 -- In Ada 2005, the master is the innermost enclosing scope that is not
12969 -- transient. If the enclosing block is the rewriting of a call or the
12970 -- scope is an extended return statement this is valid master. The
12971 -- master in an extended return is only used within the return, and is
12972 -- subsequently overwritten in Move_Activation_Chain, but it must exist
12973 -- now before that overwriting occurs.
12977 if Ada_Version >= Ada_2005 then
12978 while Is_Internal (S) loop
12979 if Nkind (Parent (S)) = N_Block_Statement
12981 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
12985 elsif Ekind (S) = E_Return_Statement then
12995 end Find_Master_Scope;
12997 -------------------------------
12998 -- First_Protected_Operation --
12999 -------------------------------
13001 function First_Protected_Operation (D : List_Id) return Node_Id is
13002 First_Op : Node_Id;
13005 First_Op := First (D);
13006 while Present (First_Op)
13007 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
13013 end First_Protected_Operation;
13015 ---------------------------------------
13016 -- Install_Private_Data_Declarations --
13017 ---------------------------------------
13019 procedure Install_Private_Data_Declarations
13021 Spec_Id : Entity_Id;
13022 Conc_Typ : Entity_Id;
13023 Body_Nod : Node_Id;
13025 Barrier : Boolean := False;
13026 Family : Boolean := False)
13028 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
13031 Insert_Node : Node_Id := Empty;
13032 Obj_Ent : Entity_Id;
13034 procedure Add (Decl : Node_Id);
13035 -- Add a single declaration after Insert_Node. If this is the first
13036 -- addition, Decl is added to the front of Decls and it becomes the
13039 function Replace_Bound (Bound : Node_Id) return Node_Id;
13040 -- The bounds of an entry index may depend on discriminants, create a
13041 -- reference to the corresponding prival. Otherwise return a duplicate
13042 -- of the original bound.
13048 procedure Add (Decl : Node_Id) is
13050 if No (Insert_Node) then
13051 Prepend_To (Decls, Decl);
13053 Insert_After (Insert_Node, Decl);
13056 Insert_Node := Decl;
13059 --------------------------
13060 -- Replace_Discriminant --
13061 --------------------------
13063 function Replace_Bound (Bound : Node_Id) return Node_Id is
13065 if Nkind (Bound) = N_Identifier
13066 and then Is_Discriminal (Entity (Bound))
13068 return Make_Identifier (Loc, Chars (Entity (Bound)));
13070 return Duplicate_Subexpr (Bound);
13074 -- Start of processing for Install_Private_Data_Declarations
13077 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13078 -- formal parameter _O, _object or _task depending on the context.
13080 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
13082 -- Special processing of _O for barrier functions, protected entries
13089 (Ekind (Spec_Id) = E_Entry
13090 or else Ekind (Spec_Id) = E_Entry_Family))
13093 Conc_Rec : constant Entity_Id :=
13094 Corresponding_Record_Type (Conc_Typ);
13095 Typ_Id : constant Entity_Id :=
13096 Make_Defining_Identifier (Loc,
13097 New_External_Name (Chars (Conc_Rec), 'P'));
13100 -- type prot_typVP is access prot_typV;
13103 Make_Full_Type_Declaration (Loc,
13104 Defining_Identifier => Typ_Id,
13106 Make_Access_To_Object_Definition (Loc,
13107 Subtype_Indication =>
13108 New_Occurrence_Of (Conc_Rec, Loc)));
13112 -- _object : prot_typVP := prot_typV (_O);
13115 Make_Object_Declaration (Loc,
13116 Defining_Identifier =>
13117 Make_Defining_Identifier (Loc, Name_uObject),
13118 Object_Definition => New_Occurrence_Of (Typ_Id, Loc),
13120 Unchecked_Convert_To (Typ_Id,
13121 New_Occurrence_Of (Obj_Ent, Loc)));
13124 -- Set the reference to the concurrent object
13126 Obj_Ent := Defining_Identifier (Decl);
13130 -- Step 2: Create the Protection object and build its declaration for
13131 -- any protected entry (family) of subprogram. Note for the lock-free
13132 -- implementation, the Protection object is not needed anymore.
13134 if Is_Protected and then not Uses_Lock_Free (Conc_Typ) then
13136 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
13140 Set_Protection_Object (Spec_Id, Prot_Ent);
13142 -- Determine the proper protection type
13144 if Has_Attach_Handler (Conc_Typ)
13145 and then not Restricted_Profile
13147 Prot_Typ := RE_Static_Interrupt_Protection;
13149 elsif Has_Interrupt_Handler (Conc_Typ)
13150 and then not Restriction_Active (No_Dynamic_Attachment)
13152 Prot_Typ := RE_Dynamic_Interrupt_Protection;
13155 case Corresponding_Runtime_Package (Conc_Typ) is
13156 when System_Tasking_Protected_Objects_Entries =>
13157 Prot_Typ := RE_Protection_Entries;
13159 when System_Tasking_Protected_Objects_Single_Entry =>
13160 Prot_Typ := RE_Protection_Entry;
13162 when System_Tasking_Protected_Objects =>
13163 Prot_Typ := RE_Protection;
13166 raise Program_Error;
13171 -- conc_typR : protection_typ renames _object._object;
13174 Make_Object_Renaming_Declaration (Loc,
13175 Defining_Identifier => Prot_Ent,
13177 New_Occurrence_Of (RTE (Prot_Typ), Loc),
13179 Make_Selected_Component (Loc,
13180 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13181 Selector_Name => Make_Identifier (Loc, Name_uObject)));
13186 -- Step 3: Add discriminant renamings (if any)
13188 if Has_Discriminants (Conc_Typ) then
13193 D := First_Discriminant (Conc_Typ);
13194 while Present (D) loop
13196 -- Adjust the source location
13198 Set_Sloc (Discriminal (D), Loc);
13201 -- discr_name : discr_typ renames _object.discr_name;
13203 -- discr_name : discr_typ renames _task.discr_name;
13206 Make_Object_Renaming_Declaration (Loc,
13207 Defining_Identifier => Discriminal (D),
13208 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
13210 Make_Selected_Component (Loc,
13211 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13212 Selector_Name => Make_Identifier (Loc, Chars (D))));
13215 Next_Discriminant (D);
13220 -- Step 4: Add private component renamings (if any)
13222 if Is_Protected then
13223 Def := Protected_Definition (Parent (Conc_Typ));
13225 if Present (Private_Declarations (Def)) then
13228 Comp_Id : Entity_Id;
13229 Decl_Id : Entity_Id;
13232 Comp := First (Private_Declarations (Def));
13233 while Present (Comp) loop
13234 if Nkind (Comp) = N_Component_Declaration then
13235 Comp_Id := Defining_Identifier (Comp);
13237 Make_Defining_Identifier (Loc, Chars (Comp_Id));
13239 -- Minimal decoration
13241 if Ekind (Spec_Id) = E_Function then
13242 Set_Ekind (Decl_Id, E_Constant);
13244 Set_Ekind (Decl_Id, E_Variable);
13247 Set_Prival (Comp_Id, Decl_Id);
13248 Set_Prival_Link (Decl_Id, Comp_Id);
13249 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
13252 -- comp_name : comp_typ renames _object.comp_name;
13255 Make_Object_Renaming_Declaration (Loc,
13256 Defining_Identifier => Decl_Id,
13258 New_Occurrence_Of (Etype (Comp_Id), Loc),
13260 Make_Selected_Component (Loc,
13262 New_Occurrence_Of (Obj_Ent, Loc),
13264 Make_Identifier (Loc, Chars (Comp_Id))));
13274 -- Step 5: Add the declaration of the entry index and the associated
13275 -- type for barrier functions and entry families.
13277 if (Barrier and then Family)
13278 or else Ekind (Spec_Id) = E_Entry_Family
13281 E : constant Entity_Id := Index_Object (Spec_Id);
13282 Index : constant Entity_Id :=
13283 Defining_Identifier (
13284 Entry_Index_Specification (
13285 Entry_Body_Formal_Part (Body_Nod)));
13286 Index_Con : constant Entity_Id :=
13287 Make_Defining_Identifier (Loc, Chars (Index));
13289 Index_Typ : Entity_Id;
13293 -- Minimal decoration
13295 Set_Ekind (Index_Con, E_Constant);
13296 Set_Entry_Index_Constant (Index, Index_Con);
13297 Set_Discriminal_Link (Index_Con, Index);
13299 -- Retrieve the bounds of the entry family
13301 High := Type_High_Bound (Etype (Index));
13302 Low := Type_Low_Bound (Etype (Index));
13304 -- In the simple case the entry family is given by a subtype
13305 -- mark and the index constant has the same type.
13307 if Is_Entity_Name (Original_Node (
13308 Discrete_Subtype_Definition (Parent (Index))))
13310 Index_Typ := Etype (Index);
13312 -- Otherwise a new subtype declaration is required
13315 High := Replace_Bound (High);
13316 Low := Replace_Bound (Low);
13318 Index_Typ := Make_Temporary (Loc, 'J');
13321 -- subtype Jnn is <Etype of Index> range Low .. High;
13324 Make_Subtype_Declaration (Loc,
13325 Defining_Identifier => Index_Typ,
13326 Subtype_Indication =>
13327 Make_Subtype_Indication (Loc,
13329 New_Occurrence_Of (Base_Type (Etype (Index)), Loc),
13331 Make_Range_Constraint (Loc,
13332 Range_Expression =>
13333 Make_Range (Loc, Low, High))));
13337 Set_Etype (Index_Con, Index_Typ);
13339 -- Create the object which designates the index:
13340 -- J : constant Jnn :=
13341 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13343 -- where Jnn is the subtype created above or the original type of
13344 -- the index, _E is a formal of the protected body subprogram and
13345 -- <index expr> is the index of the first family member.
13348 Make_Object_Declaration (Loc,
13349 Defining_Identifier => Index_Con,
13350 Constant_Present => True,
13351 Object_Definition =>
13352 New_Occurrence_Of (Index_Typ, Loc),
13355 Make_Attribute_Reference (Loc,
13357 New_Occurrence_Of (Index_Typ, Loc),
13358 Attribute_Name => Name_Val,
13360 Expressions => New_List (
13364 Make_Op_Subtract (Loc,
13366 New_Occurrence_Of (E, Loc),
13368 Entry_Index_Expression (Loc,
13369 Defining_Identifier (Body_Nod),
13373 Make_Attribute_Reference (Loc,
13375 New_Occurrence_Of (Index_Typ, Loc),
13376 Attribute_Name => Name_Pos,
13377 Expressions => New_List (
13378 Make_Attribute_Reference (Loc,
13380 New_Occurrence_Of (Index_Typ, Loc),
13381 Attribute_Name => Name_First)))))));
13385 end Install_Private_Data_Declarations;
13387 -----------------------
13388 -- Is_Exception_Safe --
13389 -----------------------
13391 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
13393 function Has_Side_Effect (N : Node_Id) return Boolean;
13394 -- Return True whenever encountering a subprogram call or raise
13395 -- statement of any kind in the sequence of statements
13397 ---------------------
13398 -- Has_Side_Effect --
13399 ---------------------
13401 -- What is this doing buried two levels down in exp_ch9. It seems like a
13402 -- generally useful function, and indeed there may be code duplication
13403 -- going on here ???
13405 function Has_Side_Effect (N : Node_Id) return Boolean is
13409 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
13410 -- Indicate whether N is a subprogram call or a raise statement
13412 ----------------------
13413 -- Is_Call_Or_Raise --
13414 ----------------------
13416 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
13418 return Nkind_In (N, N_Procedure_Call_Statement,
13421 N_Raise_Constraint_Error,
13422 N_Raise_Program_Error,
13423 N_Raise_Storage_Error);
13424 end Is_Call_Or_Raise;
13426 -- Start of processing for Has_Side_Effect
13430 while Present (Stmt) loop
13431 if Is_Call_Or_Raise (Stmt) then
13435 -- An object declaration can also contain a function call or a
13436 -- raise statement.
13438 if Nkind (Stmt) = N_Object_Declaration then
13439 Expr := Expression (Stmt);
13441 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
13450 end Has_Side_Effect;
13452 -- Start of processing for Is_Exception_Safe
13455 -- When exceptions can't be propagated, the subprogram returns normally
13457 if No_Exception_Handlers_Set then
13461 -- If the checks handled by the back end are not disabled, we cannot
13462 -- ensure that no exception will be raised.
13464 if not Access_Checks_Suppressed (Empty)
13465 or else not Discriminant_Checks_Suppressed (Empty)
13466 or else not Range_Checks_Suppressed (Empty)
13467 or else not Index_Checks_Suppressed (Empty)
13468 or else Opt.Stack_Checking_Enabled
13473 if Has_Side_Effect (First (Declarations (Subprogram)))
13476 (First (Statements (Handled_Statement_Sequence (Subprogram))))
13482 end Is_Exception_Safe;
13484 ---------------------------------
13485 -- Is_Potentially_Large_Family --
13486 ---------------------------------
13488 function Is_Potentially_Large_Family
13489 (Base_Index : Entity_Id;
13490 Conctyp : Entity_Id;
13492 Hi : Node_Id) return Boolean
13495 return Scope (Base_Index) = Standard_Standard
13496 and then Base_Index = Base_Type (Standard_Integer)
13497 and then Has_Discriminants (Conctyp)
13499 Present (Discriminant_Default_Value (First_Discriminant (Conctyp)))
13501 (Denotes_Discriminant (Lo, True)
13503 Denotes_Discriminant (Hi, True));
13504 end Is_Potentially_Large_Family;
13506 -------------------------------------
13507 -- Is_Private_Primitive_Subprogram --
13508 -------------------------------------
13510 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
13513 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
13514 and then Is_Private_Primitive (Id);
13515 end Is_Private_Primitive_Subprogram;
13521 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
13522 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
13523 Formal : Entity_Id;
13526 Formal := First_Formal (Bod_Subp);
13527 while Present (Formal) loop
13529 -- Look for formal parameter _E
13531 if Chars (Formal) = Name_uE then
13535 Next_Formal (Formal);
13538 -- A protected body subprogram should always have the parameter in
13541 raise Program_Error;
13544 --------------------------------
13545 -- Make_Initialize_Protection --
13546 --------------------------------
13548 function Make_Initialize_Protection
13549 (Protect_Rec : Entity_Id) return List_Id
13551 Loc : constant Source_Ptr := Sloc (Protect_Rec);
13554 Ptyp : constant Node_Id :=
13555 Corresponding_Concurrent_Type (Protect_Rec);
13557 L : constant List_Id := New_List;
13558 Has_Entry : constant Boolean := Has_Entries (Ptyp);
13559 Prio_Type : Entity_Id;
13560 Prio_Var : Entity_Id := Empty;
13561 Restricted : constant Boolean := Restricted_Profile;
13564 -- We may need two calls to properly initialize the object, one to
13565 -- Initialize_Protection, and possibly one to Install_Handlers if we
13566 -- have a pragma Attach_Handler.
13568 -- Get protected declaration. In the case of a task type declaration,
13569 -- this is simply the parent of the protected type entity. In the single
13570 -- protected object declaration, this parent will be the implicit type,
13571 -- and we can find the corresponding single protected object declaration
13572 -- by searching forward in the declaration list in the tree.
13574 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13575 -- of this type should have been removed during semantic analysis.
13577 Pdec := Parent (Ptyp);
13578 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
13579 N_Single_Protected_Declaration)
13584 -- Build the parameter list for the call. Note that _Init is the name
13585 -- of the formal for the object to be initialized, which is the task
13586 -- value record itself.
13590 -- For lock-free implementation, skip initializations of the Protection
13593 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13594 -- Object parameter. This is a pointer to the object of type
13595 -- Protection used by the GNARL to control the protected object.
13598 Make_Attribute_Reference (Loc,
13600 Make_Selected_Component (Loc,
13601 Prefix => Make_Identifier (Loc, Name_uInit),
13602 Selector_Name => Make_Identifier (Loc, Name_uObject)),
13603 Attribute_Name => Name_Unchecked_Access));
13605 -- Priority parameter. Set to Unspecified_Priority unless there is a
13606 -- Priority rep item, in which case we take the value from the pragma
13607 -- or attribute definition clause, or there is an Interrupt_Priority
13608 -- rep item and no Priority rep item, and we set the ceiling to
13609 -- Interrupt_Priority'Last, an implementation-defined value, see
13612 if Has_Rep_Item (Ptyp, Name_Priority, Check_Parents => False) then
13614 Prio_Clause : constant Node_Id :=
13616 (Ptyp, Name_Priority, Check_Parents => False);
13623 if Nkind (Prio_Clause) = N_Pragma then
13626 (First (Pragma_Argument_Associations (Prio_Clause)));
13628 -- Get_Rep_Item returns either priority pragma.
13630 if Pragma_Name (Prio_Clause) = Name_Priority then
13631 Prio_Type := RTE (RE_Any_Priority);
13633 Prio_Type := RTE (RE_Interrupt_Priority);
13636 -- Attribute definition clause Priority
13639 if Chars (Prio_Clause) = Name_Priority then
13640 Prio_Type := RTE (RE_Any_Priority);
13642 Prio_Type := RTE (RE_Interrupt_Priority);
13645 Prio := Expression (Prio_Clause);
13648 -- Always create a locale variable to capture the priority.
13649 -- The priority is also passed to Install_Restriced_Handlers.
13650 -- Note that it is really necessary to create this variable
13651 -- explicitly. It might be thought that removing side effects
13652 -- would the appropriate approach, but that could generate
13653 -- declarations improperly placed in the enclosing scope.
13655 Prio_Var := Make_Temporary (Loc, 'R', Prio);
13657 Make_Object_Declaration (Loc,
13658 Defining_Identifier => Prio_Var,
13659 Object_Definition => New_Occurrence_Of (Prio_Type, Loc),
13660 Expression => Relocate_Node (Prio)));
13662 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13665 -- When no priority is specified but an xx_Handler pragma is, we
13666 -- default to System.Interrupts.Default_Interrupt_Priority, see
13669 elsif Has_Attach_Handler (Ptyp)
13670 or else Has_Interrupt_Handler (Ptyp)
13673 New_Occurrence_Of (RTE (RE_Default_Interrupt_Priority), Loc));
13675 -- Normal case, no priority or xx_Handler specified, default priority
13679 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
13682 -- Test for Compiler_Info parameter. This parameter allows entry body
13683 -- procedures and barrier functions to be called from the runtime. It
13684 -- is a pointer to the record generated by the compiler to represent
13685 -- the protected object.
13687 -- A protected type without entries that covers an interface and
13688 -- overrides the abstract routines with protected procedures is
13689 -- considered equivalent to a protected type with entries in the
13690 -- context of dispatching select statements.
13692 -- Protected types with interrupt handlers (when not using a
13693 -- restricted profile) are also considered equivalent to protected
13694 -- types with entries.
13696 -- The types which are used (Static_Interrupt_Protection and
13697 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13700 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
13702 Called_Subp : RE_Id;
13706 when System_Tasking_Protected_Objects_Entries =>
13707 Called_Subp := RE_Initialize_Protection_Entries;
13709 -- Argument Compiler_Info
13712 Make_Attribute_Reference (Loc,
13713 Prefix => Make_Identifier (Loc, Name_uInit),
13714 Attribute_Name => Name_Address));
13716 when System_Tasking_Protected_Objects_Single_Entry =>
13717 Called_Subp := RE_Initialize_Protection_Entry;
13719 -- Argument Compiler_Info
13722 Make_Attribute_Reference (Loc,
13723 Prefix => Make_Identifier (Loc, Name_uInit),
13724 Attribute_Name => Name_Address));
13726 when System_Tasking_Protected_Objects =>
13727 Called_Subp := RE_Initialize_Protection;
13730 raise Program_Error;
13733 -- Entry_Bodies parameter. This is a pointer to an array of
13734 -- pointers to the entry body procedures and barrier functions of
13735 -- the object. If the protected type has no entries this object
13736 -- will not exist, in this case, pass a null (it can happen when
13737 -- there are protected interrupt handlers or interfaces).
13740 P_Arr := Entry_Bodies_Array (Ptyp);
13742 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13743 -- multiple entries).
13746 Make_Attribute_Reference (Loc,
13747 Prefix => New_Occurrence_Of (P_Arr, Loc),
13748 Attribute_Name => Name_Unrestricted_Access));
13750 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
13752 -- Find index mapping function (clumsy but ok for now)
13754 while Ekind (P_Arr) /= E_Function loop
13755 Next_Entity (P_Arr);
13759 Make_Attribute_Reference (Loc,
13760 Prefix => New_Occurrence_Of (P_Arr, Loc),
13761 Attribute_Name => Name_Unrestricted_Access));
13764 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
13766 -- This is the case where we have a protected object with
13767 -- interfaces and no entries, and the single entry restriction
13768 -- is in effect. We pass a null pointer for the entry
13769 -- parameter because there is no actual entry.
13771 Append_To (Args, Make_Null (Loc));
13773 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
13775 -- This is the case where we have a protected object with no
13777 -- - either interrupt handlers with non restricted profile,
13779 -- Note that the types which are used for interrupt handlers
13780 -- (Static/Dynamic_Interrupt_Protection) are derived from
13781 -- Protection_Entries. We pass two null pointers because there
13782 -- is no actual entry, and the initialization procedure needs
13783 -- both Entry_Bodies and Find_Body_Index.
13785 Append_To (Args, Make_Null (Loc));
13786 Append_To (Args, Make_Null (Loc));
13790 Make_Procedure_Call_Statement (Loc,
13792 New_Occurrence_Of (RTE (Called_Subp), Loc),
13793 Parameter_Associations => Args));
13797 if Has_Attach_Handler (Ptyp) then
13799 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13800 -- make the following call:
13802 -- Install_Handlers (_object,
13803 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13805 -- or, in the case of Ravenscar:
13807 -- Install_Restricted_Handlers
13808 -- (Prio, (Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13811 Args : constant List_Id := New_List;
13812 Table : constant List_Id := New_List;
13813 Ritem : Node_Id := First_Rep_Item (Ptyp);
13816 -- Build the Priority parameter (only for ravenscar)
13820 -- Priority comes from a pragma
13822 if Present (Prio_Var) then
13823 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13825 -- Priority is the default one
13830 (RTE (RE_Default_Interrupt_Priority), Loc));
13834 -- Build the Attach_Handler table argument
13836 while Present (Ritem) loop
13837 if Nkind (Ritem) = N_Pragma
13838 and then Pragma_Name (Ritem) = Name_Attach_Handler
13841 Handler : constant Node_Id :=
13842 First (Pragma_Argument_Associations (Ritem));
13844 Interrupt : constant Node_Id := Next (Handler);
13845 Expr : constant Node_Id := Expression (Interrupt);
13849 Make_Aggregate (Loc, Expressions => New_List (
13850 Unchecked_Convert_To
13851 (RTE (RE_System_Interrupt_Id), Expr),
13852 Make_Attribute_Reference (Loc,
13854 Make_Selected_Component (Loc,
13856 Make_Identifier (Loc, Name_uInit),
13858 Duplicate_Subexpr_No_Checks
13859 (Expression (Handler))),
13860 Attribute_Name => Name_Access))));
13864 Next_Rep_Item (Ritem);
13867 -- Append the table argument we just built
13869 Append_To (Args, Make_Aggregate (Loc, Table));
13871 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13872 -- call to the statements.
13875 -- Call a simplified version of Install_Handlers to be used
13876 -- when the Ravenscar restrictions are in effect
13877 -- (Install_Restricted_Handlers).
13880 Make_Procedure_Call_Statement (Loc,
13883 (RTE (RE_Install_Restricted_Handlers), Loc),
13884 Parameter_Associations => Args));
13887 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13889 -- First, prepends the _object argument
13892 Make_Attribute_Reference (Loc,
13894 Make_Selected_Component (Loc,
13895 Prefix => Make_Identifier (Loc, Name_uInit),
13897 Make_Identifier (Loc, Name_uObject)),
13898 Attribute_Name => Name_Unchecked_Access));
13901 -- Then, insert call to Install_Handlers
13904 Make_Procedure_Call_Statement (Loc,
13906 New_Occurrence_Of (RTE (RE_Install_Handlers), Loc),
13907 Parameter_Associations => Args));
13913 end Make_Initialize_Protection;
13915 ---------------------------
13916 -- Make_Task_Create_Call --
13917 ---------------------------
13919 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
13920 Loc : constant Source_Ptr := Sloc (Task_Rec);
13930 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
13931 Tnam := Chars (Ttyp);
13933 -- Get task declaration. In the case of a task type declaration, this is
13934 -- simply the parent of the task type entity. In the single task
13935 -- declaration, this parent will be the implicit type, and we can find
13936 -- the corresponding single task declaration by searching forward in the
13937 -- declaration list in the tree.
13939 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
13940 -- this type should have been removed during semantic analysis.
13942 Tdec := Parent (Ttyp);
13943 while not Nkind_In (Tdec, N_Task_Type_Declaration,
13944 N_Single_Task_Declaration)
13949 -- Now we can find the task definition from this declaration
13951 Tdef := Task_Definition (Tdec);
13953 -- Build the parameter list for the call. Note that _Init is the name
13954 -- of the formal for the object to be initialized, which is the task
13955 -- value record itself.
13959 -- Priority parameter. Set to Unspecified_Priority unless there is a
13960 -- Priority rep item, in which case we take the value from the rep item.
13962 if Has_Rep_Item (Ttyp, Name_Priority, Check_Parents => False) then
13964 Make_Selected_Component (Loc,
13965 Prefix => Make_Identifier (Loc, Name_uInit),
13966 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
13969 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
13972 -- Optional Stack parameter
13974 if Restricted_Profile then
13976 -- If the stack has been preallocated by the expander then
13977 -- pass its address. Otherwise, pass a null address.
13979 if Preallocated_Stacks_On_Target then
13981 Make_Attribute_Reference (Loc,
13983 Make_Selected_Component (Loc,
13984 Prefix => Make_Identifier (Loc, Name_uInit),
13985 Selector_Name => Make_Identifier (Loc, Name_uStack)),
13986 Attribute_Name => Name_Address));
13990 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
13994 -- Size parameter. If no Storage_Size pragma is present, then
13995 -- the size is taken from the taskZ variable for the type, which
13996 -- is either Unspecified_Size, or has been reset by the use of
13997 -- a Storage_Size attribute definition clause. If a pragma is
13998 -- present, then the size is taken from the _Size field of the
13999 -- task value record, which was set from the pragma value.
14002 and then Has_Storage_Size_Pragma (Tdef)
14005 Make_Selected_Component (Loc,
14006 Prefix => Make_Identifier (Loc, Name_uInit),
14007 Selector_Name => Make_Identifier (Loc, Name_uSize)));
14011 New_Occurrence_Of (Storage_Size_Variable (Ttyp), Loc));
14014 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14015 -- Task_Info pragma, in which case we take the value from the pragma.
14017 if Has_Rep_Pragma (Ttyp, Name_Task_Info, Check_Parents => False) then
14019 Make_Selected_Component (Loc,
14020 Prefix => Make_Identifier (Loc, Name_uInit),
14021 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
14025 New_Occurrence_Of (RTE (RE_Unspecified_Task_Info), Loc));
14028 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14029 -- in which case we take the value from the rep item. The parameter is
14030 -- passed as an Integer because in the case of unspecified CPU the
14031 -- value is not in the range of CPU_Range.
14033 if Has_Rep_Item (Ttyp, Name_CPU, Check_Parents => False) then
14035 Convert_To (Standard_Integer,
14036 Make_Selected_Component (Loc,
14037 Prefix => Make_Identifier (Loc, Name_uInit),
14038 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
14041 New_Occurrence_Of (RTE (RE_Unspecified_CPU), Loc));
14044 if not Restricted_Profile then
14046 -- Deadline parameter. If no Relative_Deadline pragma is present,
14047 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14048 -- the deadline is taken from the _Relative_Deadline field of the
14049 -- task value record, which was set from the pragma value. Note that
14050 -- this parameter must not be generated for the restricted profiles
14051 -- since Ravenscar does not allow deadlines.
14053 -- Case where pragma Relative_Deadline applies: use given value
14056 and then Has_Relative_Deadline_Pragma (Tdef)
14059 Make_Selected_Component (Loc,
14060 Prefix => Make_Identifier (Loc, Name_uInit),
14062 Make_Identifier (Loc, Name_uRelative_Deadline)));
14064 -- No pragma Relative_Deadline apply to the task
14068 New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc));
14071 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14072 -- present, then the dispatching domain is null. If a rep item is
14073 -- present, then the dispatching domain is taken from the
14074 -- _Dispatching_Domain field of the task value record, which was set
14075 -- from the rep item value. Note that this parameter must not be
14076 -- generated for the restricted profiles since Ravenscar does not
14077 -- allow dispatching domains.
14079 -- Case where Dispatching_Domain rep item applies: use given value
14082 (Ttyp, Name_Dispatching_Domain, Check_Parents => False)
14085 Make_Selected_Component (Loc,
14087 Make_Identifier (Loc, Name_uInit),
14089 Make_Identifier (Loc, Name_uDispatching_Domain)));
14091 -- No pragma or aspect Dispatching_Domain apply to the task
14094 Append_To (Args, Make_Null (Loc));
14097 -- Number of entries. This is an expression of the form:
14099 -- n + _Init.a'Length + _Init.a'B'Length + ...
14101 -- where a,b... are the entry family names for the task definition
14104 Build_Entry_Count_Expression
14109 (Parent (Corresponding_Record_Type (Ttyp))))),
14111 Append_To (Args, Ecount);
14113 -- Master parameter. This is a reference to the _Master parameter of
14114 -- the initialization procedure, except in the case of the pragma
14115 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14116 -- System.Tasking.Library_Task_Level.
14118 if Restriction_Active (No_Task_Hierarchy) = False then
14119 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
14122 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
14126 -- State parameter. This is a pointer to the task body procedure. The
14127 -- required value is obtained by taking 'Unrestricted_Access of the task
14128 -- body procedure and converting it (with an unchecked conversion) to
14129 -- the type required by the task kernel. For further details, see the
14130 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14131 -- than 'Address in order to avoid creating trampolines.
14134 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
14135 Subp_Ptr_Typ : constant Node_Id :=
14136 Create_Itype (E_Access_Subprogram_Type, Tdec);
14137 Ref : constant Node_Id := Make_Itype_Reference (Loc);
14140 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
14141 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
14143 -- Be sure to freeze a reference to the access-to-subprogram type,
14144 -- otherwise gigi will complain that it's in the wrong scope, because
14145 -- it's actually inside the init procedure for the record type that
14146 -- corresponds to the task type.
14148 -- This processing is causing a crash in the .NET/JVM back ends that
14149 -- is not yet understood, so skip it in these cases ???
14151 if VM_Target = No_VM then
14152 Set_Itype (Ref, Subp_Ptr_Typ);
14153 Append_Freeze_Action (Task_Rec, Ref);
14156 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
14157 Make_Qualified_Expression (Loc,
14158 Subtype_Mark => New_Occurrence_Of (Subp_Ptr_Typ, Loc),
14160 Make_Attribute_Reference (Loc,
14161 Prefix => New_Occurrence_Of (Body_Proc, Loc),
14162 Attribute_Name => Name_Unrestricted_Access))));
14164 -- For the .NET/JVM cases revert to the original code below ???
14168 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
14169 Make_Attribute_Reference (Loc,
14170 Prefix => New_Occurrence_Of (Body_Proc, Loc),
14171 Attribute_Name => Name_Address)));
14175 -- Discriminants parameter. This is just the address of the task
14176 -- value record itself (which contains the discriminant values
14179 Make_Attribute_Reference (Loc,
14180 Prefix => Make_Identifier (Loc, Name_uInit),
14181 Attribute_Name => Name_Address));
14183 -- Elaborated parameter. This is an access to the elaboration Boolean
14186 Make_Attribute_Reference (Loc,
14187 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
14188 Attribute_Name => Name_Unchecked_Access));
14190 -- Add Chain parameter (not done for sequential elaboration policy, see
14191 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14193 if Partition_Elaboration_Policy /= 'S' then
14194 Append_To (Args, Make_Identifier (Loc, Name_uChain));
14197 -- Task name parameter. Take this from the _Task_Id parameter to the
14198 -- init call unless there is a Task_Name pragma, in which case we take
14199 -- the value from the pragma.
14201 if Has_Rep_Pragma (Ttyp, Name_Task_Name, Check_Parents => False) then
14202 -- Copy expression in full, because it may be dynamic and have
14209 (Pragma_Argument_Associations
14211 (Ttyp, Name_Task_Name, Check_Parents => False))))));
14214 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
14217 -- Created_Task parameter. This is the _Task_Id field of the task
14221 Make_Selected_Component (Loc,
14222 Prefix => Make_Identifier (Loc, Name_uInit),
14223 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
14229 if Restricted_Profile then
14230 if Partition_Elaboration_Policy = 'S' then
14231 Create_RE := RE_Create_Restricted_Task_Sequential;
14233 Create_RE := RE_Create_Restricted_Task;
14236 Create_RE := RE_Create_Task;
14239 Name := New_Occurrence_Of (RTE (Create_RE), Loc);
14243 Make_Procedure_Call_Statement (Loc,
14245 Parameter_Associations => Args);
14246 end Make_Task_Create_Call;
14248 ------------------------------
14249 -- Next_Protected_Operation --
14250 ------------------------------
14252 function Next_Protected_Operation (N : Node_Id) return Node_Id is
14256 Next_Op := Next (N);
14257 while Present (Next_Op)
14258 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
14264 end Next_Protected_Operation;
14266 ---------------------
14267 -- Null_Statements --
14268 ---------------------
14270 function Null_Statements (Stats : List_Id) return Boolean is
14274 Stmt := First (Stats);
14275 while Nkind (Stmt) /= N_Empty
14276 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
14278 (Nkind (Stmt) = N_Pragma
14280 Nam_In (Pragma_Name (Stmt), Name_Unreferenced,
14287 return Nkind (Stmt) = N_Empty;
14288 end Null_Statements;
14290 --------------------------
14291 -- Parameter_Block_Pack --
14292 --------------------------
14294 function Parameter_Block_Pack
14296 Blk_Typ : Entity_Id;
14300 Stmts : List_Id) return Node_Id
14302 Actual : Entity_Id;
14303 Expr : Node_Id := Empty;
14304 Formal : Entity_Id;
14305 Has_Param : Boolean := False;
14308 Temp_Asn : Node_Id;
14309 Temp_Nam : Node_Id;
14312 Actual := First (Actuals);
14313 Formal := Defining_Identifier (First (Formals));
14314 Params := New_List;
14315 while Present (Actual) loop
14316 if Is_By_Copy_Type (Etype (Actual)) then
14318 -- Jnn : aliased <formal-type>
14320 Temp_Nam := Make_Temporary (Loc, 'J');
14323 Make_Object_Declaration (Loc,
14324 Aliased_Present => True,
14325 Defining_Identifier => Temp_Nam,
14326 Object_Definition =>
14327 New_Occurrence_Of (Etype (Formal), Loc)));
14329 if Ekind (Formal) /= E_Out_Parameter then
14335 New_Occurrence_Of (Temp_Nam, Loc);
14337 Set_Assignment_OK (Temp_Asn);
14340 Make_Assignment_Statement (Loc,
14342 Expression => New_Copy_Tree (Actual)));
14346 -- Jnn'unchecked_access
14349 Make_Attribute_Reference (Loc,
14350 Attribute_Name => Name_Unchecked_Access,
14351 Prefix => New_Occurrence_Of (Temp_Nam, Loc)));
14355 -- The controlling parameter is omitted
14358 if not Is_Controlling_Actual (Actual) then
14360 Make_Reference (Loc, New_Copy_Tree (Actual)));
14366 Next_Actual (Actual);
14367 Next_Formal_With_Extras (Formal);
14371 Expr := Make_Aggregate (Loc, Params);
14376 -- J1'unchecked_access;
14377 -- <actual2>'reference;
14380 P := Make_Temporary (Loc, 'P');
14383 Make_Object_Declaration (Loc,
14384 Defining_Identifier => P,
14385 Object_Definition => New_Occurrence_Of (Blk_Typ, Loc),
14386 Expression => Expr));
14389 end Parameter_Block_Pack;
14391 ----------------------------
14392 -- Parameter_Block_Unpack --
14393 ----------------------------
14395 function Parameter_Block_Unpack
14399 Formals : List_Id) return List_Id
14401 Actual : Entity_Id;
14403 Formal : Entity_Id;
14404 Has_Asnmt : Boolean := False;
14405 Result : constant List_Id := New_List;
14408 Actual := First (Actuals);
14409 Formal := Defining_Identifier (First (Formals));
14410 while Present (Actual) loop
14411 if Is_By_Copy_Type (Etype (Actual))
14412 and then Ekind (Formal) /= E_In_Parameter
14415 -- <actual> := P.<formal>;
14418 Make_Assignment_Statement (Loc,
14422 Make_Explicit_Dereference (Loc,
14423 Make_Selected_Component (Loc,
14425 New_Occurrence_Of (P, Loc),
14427 Make_Identifier (Loc, Chars (Formal)))));
14429 Set_Assignment_OK (Name (Asnmt));
14430 Append_To (Result, Asnmt);
14435 Next_Actual (Actual);
14436 Next_Formal_With_Extras (Formal);
14442 return New_List (Make_Null_Statement (Loc));
14444 end Parameter_Block_Unpack;
14446 ----------------------
14447 -- Set_Discriminals --
14448 ----------------------
14450 procedure Set_Discriminals (Dec : Node_Id) is
14453 D_Minal : Entity_Id;
14456 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
14457 Pdef := Defining_Identifier (Dec);
14459 if Has_Discriminants (Pdef) then
14460 D := First_Discriminant (Pdef);
14461 while Present (D) loop
14463 Make_Defining_Identifier (Sloc (D),
14464 Chars => New_External_Name (Chars (D), 'D'));
14466 Set_Ekind (D_Minal, E_Constant);
14467 Set_Etype (D_Minal, Etype (D));
14468 Set_Scope (D_Minal, Pdef);
14469 Set_Discriminal (D, D_Minal);
14470 Set_Discriminal_Link (D_Minal, D);
14472 Next_Discriminant (D);
14475 end Set_Discriminals;
14477 -----------------------
14478 -- Trivial_Accept_OK --
14479 -----------------------
14481 function Trivial_Accept_OK return Boolean is
14483 case Opt.Task_Dispatching_Policy is
14485 -- If we have the default task dispatching policy in effect, we can
14486 -- definitely do the optimization (one way of looking at this is to
14487 -- think of the formal definition of the default policy being allowed
14488 -- to run any task it likes after a rendezvous, so even if notionally
14489 -- a full rescheduling occurs, we can say that our dispatching policy
14490 -- (i.e. the default dispatching policy) reorders the queue to be the
14491 -- same as just before the call.
14496 -- FIFO_Within_Priorities certainly does not permit this
14497 -- optimization since the Rendezvous is a scheduling action that may
14498 -- require some other task to be run.
14503 -- For now, disallow the optimization for all other policies. This
14504 -- may be over-conservative, but it is certainly not incorrect.
14510 end Trivial_Accept_OK;