1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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 Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Uintp; use Uintp;
67 package body Exp_Ch9 is
69 -- The following constant establishes the upper bound for the index of
70 -- an entry family. It is used to limit the allocated size of protected
71 -- types with defaulted discriminant of an integer type, when the bound
72 -- of some entry family depends on a discriminant. The limitation to entry
73 -- families of 128K should be reasonable in all cases, and is a documented
74 -- implementation restriction.
76 Entry_Family_Bound : constant Pos := 2**16;
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 function Actual_Index_Expression
86 Tsk : Entity_Id) return Node_Id;
87 -- Compute the index position for an entry call. Tsk is the target task. If
88 -- the bounds of some entry family depend on discriminants, the expression
89 -- computed by this function uses the discriminants of the target task.
91 procedure Add_Object_Pointer
95 -- Prepend an object pointer declaration to the declaration list Decls.
96 -- This object pointer is initialized to a type conversion of the System.
97 -- Address pointer passed to entry barrier functions and entry body
100 procedure Add_Formal_Renamings
105 -- Create renaming declarations for the formals, inside the procedure that
106 -- implements an entry body. The renamings make the original names of the
107 -- formals accessible to gdb, and serve no other purpose.
108 -- Spec is the specification of the procedure being built.
109 -- Decls is the list of declarations to be enhanced.
110 -- Ent is the entity for the original entry body.
112 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
113 -- Transform accept statement into a block with added exception handler.
114 -- Used both for simple accept statements and for accept alternatives in
115 -- select statements. Astat is the accept statement.
117 function Build_Barrier_Function
120 Pid : Node_Id) return Node_Id;
121 -- Build the function body returning the value of the barrier expression
122 -- for the specified entry body.
124 function Build_Barrier_Function_Specification
126 Def_Id : Entity_Id) return Node_Id;
127 -- Build a specification for a function implementing the protected entry
128 -- barrier of the specified entry body.
130 procedure Build_Contract_Wrapper (E : Entity_Id; Decl : Node_Id);
131 -- Build the body of a wrapper procedure for an entry or entry family that
132 -- has contract cases, preconditions, or postconditions. The body gathers
133 -- the executable contract items and expands them in the usual way, and
134 -- performs the entry call itself. This way preconditions are evaluated
135 -- before the call is queued. E is the entry in question, and Decl is the
136 -- enclosing synchronized type declaration at whose freeze point the
137 -- generated body is analyzed.
139 function Build_Corresponding_Record
142 Loc : Source_Ptr) return Node_Id;
143 -- Common to tasks and protected types. Copy discriminant specifications,
144 -- build record declaration. N is the type declaration, Ctyp is the
145 -- concurrent entity (task type or protected type).
147 function Build_Dispatching_Tag_Check
149 N : Node_Id) return Node_Id;
150 -- Utility to create the tree to check whether the dispatching call in
151 -- a timed entry call, a conditional entry call, or an asynchronous
152 -- transfer of control is a call to a primitive of a non-synchronized type.
153 -- K is the temporary that holds the tagged kind of the target object, and
154 -- N is the enclosing construct.
156 function Build_Entry_Count_Expression
157 (Concurrent_Type : Node_Id;
158 Component_List : List_Id;
159 Loc : Source_Ptr) return Node_Id;
160 -- Compute number of entries for concurrent object. This is a count of
161 -- simple entries, followed by an expression that computes the length
162 -- of the range of each entry family. A single array with that size is
163 -- allocated for each concurrent object of the type.
165 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
166 -- Build the function that translates the entry index in the call
167 -- (which depends on the size of entry families) into an index into the
168 -- Entry_Bodies_Array, to determine the body and barrier function used
169 -- in a protected entry call. A pointer to this function appears in every
172 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
173 -- Build subprogram declaration for previous one
175 function Build_Lock_Free_Protected_Subprogram_Body
178 Unprot_Spec : Node_Id) return Node_Id;
179 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
180 -- the subprogram specification of the unprotected version of N. Transform
181 -- N such that it invokes the unprotected version of the body.
183 function Build_Lock_Free_Unprotected_Subprogram_Body
185 Prot_Typ : Node_Id) return Node_Id;
186 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
187 -- of N where the original statements of N are synchronized through atomic
188 -- actions such as compare and exchange. Prior to invoking this routine, it
189 -- has been established that N can be implemented in a lock-free fashion.
191 function Build_Parameter_Block
195 Decls : List_Id) return Entity_Id;
196 -- Generate an access type for each actual parameter in the list Actuals.
197 -- Create an encapsulating record that contains all the actuals and return
198 -- its type. Generate:
199 -- type Ann1 is access all <actual1-type>
201 -- type AnnN is access all <actualN-type>
202 -- type Pnn is record
208 function Build_Protected_Entry
211 Pid : Node_Id) return Node_Id;
212 -- Build the procedure implementing the statement sequence of the specified
215 function Build_Protected_Entry_Specification
218 Ent_Id : Entity_Id) return Node_Id;
219 -- Build a specification for the procedure implementing the statements of
220 -- the specified entry body. Add attributes associating it with the entry
221 -- defining identifier Ent_Id.
223 function Build_Protected_Spec
225 Obj_Type : Entity_Id;
227 Unprotected : Boolean := False) return List_Id;
228 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
229 -- Subprogram_Type. Builds signature of protected subprogram, adding the
230 -- formal that corresponds to the object itself. For an access to protected
231 -- subprogram, there is no object type to specify, so the parameter has
232 -- type Address and mode In. An indirect call through such a pointer will
233 -- convert the address to a reference to the actual object. The object is
234 -- a limited record and therefore a by_reference type.
236 function Build_Protected_Subprogram_Body
239 N_Op_Spec : Node_Id) return Node_Id;
240 -- This function is used to construct the protected version of a protected
241 -- subprogram. Its statement sequence first defers abort, then locks the
242 -- associated protected object, and then enters a block that contains a
243 -- call to the unprotected version of the subprogram (for details, see
244 -- Build_Unprotected_Subprogram_Body). This block statement requires a
245 -- cleanup handler that unlocks the object in all cases. For details,
246 -- see Exp_Ch7.Expand_Cleanup_Actions.
248 function Build_Renamed_Formal_Declaration
252 Renamed_Formal : Node_Id) return Node_Id;
253 -- Create a renaming declaration for a formal, within a protected entry
254 -- body or an accept body. The renamed object is a component of the
255 -- parameter block that is a parameter in the entry call.
257 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
258 -- does not dereference the corresponding component to prevent an illegal
259 -- use of the incomplete type (AI05-0151).
261 function Build_Selected_Name
263 Selector : Entity_Id;
264 Append_Char : Character := ' ') return Name_Id;
265 -- Build a name in the form of Prefix__Selector, with an optional character
266 -- appended. This is used for internal subprograms generated for operations
267 -- of protected types, including barrier functions. For the subprograms
268 -- generated for entry bodies and entry barriers, the generated name
269 -- includes a sequence number that makes names unique in the presence of
270 -- entry overloading. This is necessary because entry body procedures and
271 -- barrier functions all have the same signature.
273 procedure Build_Simple_Entry_Call
278 -- Some comments here would be useful ???
280 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
281 -- This routine constructs a specification for the procedure that we will
282 -- build for the task body for task type T. The spec has the form:
284 -- procedure tnameB (_Task : access tnameV);
286 -- where name is the character name taken from the task type entity that
287 -- is passed as the argument to the procedure, and tnameV is the task
288 -- value type that is associated with the task type.
290 function Build_Unprotected_Subprogram_Body
292 Pid : Node_Id) return Node_Id;
293 -- This routine constructs the unprotected version of a protected
294 -- subprogram body, which is contains all of the code in the original,
295 -- unexpanded body. This is the version of the protected subprogram that is
296 -- called from all protected operations on the same object, including the
297 -- protected version of the same subprogram.
299 procedure Build_Wrapper_Bodies
303 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
304 -- record of a concurrent type. N is the insertion node where all bodies
305 -- will be placed. This routine builds the bodies of the subprograms which
306 -- serve as an indirection mechanism to overriding primitives of concurrent
307 -- types, entries and protected procedures. Any new body is analyzed.
309 procedure Build_Wrapper_Specs
313 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
314 -- record of a concurrent type. N is the insertion node where all specs
315 -- will be placed. This routine builds the specs of the subprograms which
316 -- serve as an indirection mechanism to overriding primitives of concurrent
317 -- types, entries and protected procedures. Any new spec is analyzed.
319 procedure Collect_Entry_Families
322 Current_Node : in out Node_Id;
323 Conctyp : Entity_Id);
324 -- For each entry family in a concurrent type, create an anonymous array
325 -- type of the right size, and add a component to the corresponding_record.
327 function Concurrent_Object
328 (Spec_Id : Entity_Id;
329 Conc_Typ : Entity_Id) return Entity_Id;
330 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
331 -- the entity associated with the concurrent object in the Protected_Body_
332 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
333 -- denotes formal parameter _O, _object or _task.
335 function Copy_Result_Type (Res : Node_Id) return Node_Id;
336 -- Copy the result type of a function specification, when building the
337 -- internal operation corresponding to a protected function, or when
338 -- expanding an access to protected function. If the result is an anonymous
339 -- access to subprogram itself, we need to create a new signature with the
340 -- same parameter names and the same resolved types, but with new entities
343 procedure Debug_Private_Data_Declarations (Decls : List_Id);
344 -- Decls is a list which may contain the declarations created by Install_
345 -- Private_Data_Declarations. All generated entities are marked as needing
346 -- debug info and debug nodes are manually generation where necessary. This
347 -- step of the expansion must to be done after private data has been moved
348 -- to its final resting scope to ensure proper visibility of debug objects.
350 procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id);
351 -- If control flow optimizations are suppressed, and Alt is an accept,
352 -- delay, or entry call alternative with no trailing statements, insert
353 -- a null trailing statement with the given Loc (which is the sloc of
354 -- the accept, delay, or entry call statement). There might not be any
355 -- generated code for the accept, delay, or entry call itself (the effect
356 -- of these statements is part of the general processsing done for the
357 -- enclosing selective accept, timed entry call, or asynchronous select),
358 -- and the null statement is there to carry the sloc of that statement to
359 -- the back-end for trace-based coverage analysis purposes.
361 procedure Extract_Dispatching_Call
363 Call_Ent : out Entity_Id;
364 Object : out Entity_Id;
365 Actuals : out List_Id;
366 Formals : out List_Id);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
373 procedure Extract_Entry
375 Concval : out Node_Id;
377 Index : out Node_Id);
378 -- Given an entry call, returns the associated concurrent object, the entry
379 -- name, and the entry family index.
381 function Family_Offset
386 Cap : Boolean) return Node_Id;
387 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
388 -- accept statement, or the upper bound in the discrete subtype of an entry
389 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
390 -- type of the entry. If Cap is true, the result is capped according to
391 -- Entry_Family_Bound.
398 Cap : Boolean) return Node_Id;
399 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
400 -- family, and handle properly the superflat case. This is equivalent to
401 -- the use of 'Length on the index type, but must use Family_Offset to
402 -- handle properly the case of bounds that depend on discriminants. If
403 -- Cap is true, the result is capped according to Entry_Family_Bound.
405 procedure Find_Enclosing_Context
407 Context : out Node_Id;
408 Context_Id : out Entity_Id;
409 Context_Decls : out List_Id);
410 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
411 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
412 -- nearest enclosing body, block, package, or return statement and return
413 -- its constituents. Context is the enclosing construct, Context_Id is
414 -- the scope of Context_Id and Context_Decls is the declarative list of
417 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
418 -- Given a subprogram identifier, return the entity which is associated
419 -- with the protection entry index in the Protected_Body_Subprogram or
420 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
423 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
424 -- Tell whether a given subprogram cannot raise an exception
426 function Is_Potentially_Large_Family
427 (Base_Index : Entity_Id;
430 Hi : Node_Id) return Boolean;
432 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
433 -- Determine whether Id is a function or a procedure and is marked as a
434 -- private primitive.
436 function Null_Statements (Stats : List_Id) return Boolean;
437 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
438 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
439 -- to still count as null. Returns True for a null sequence. The argument
440 -- is the list of statements from the DO-END sequence.
442 function Parameter_Block_Pack
448 Stmts : List_Id) return Entity_Id;
449 -- Set the components of the generated parameter block with the values
450 -- of the actual parameters. Generate aliased temporaries to capture the
451 -- values for types that are passed by copy. Otherwise generate a reference
452 -- to the actual's value. Return the address of the aggregate block.
454 -- Jnn1 : alias <formal-type1>;
455 -- Jnn1 := <actual1>;
458 -- Jnn1'unchecked_access;
459 -- <actual2>'reference;
462 function Parameter_Block_Unpack
466 Formals : List_Id) return List_Id;
467 -- Retrieve the values of the components from the parameter block and
468 -- assign then to the original actual parameters. Generate:
469 -- <actual1> := P.<formal1>;
471 -- <actualN> := P.<formalN>;
473 function Trivial_Accept_OK return Boolean;
474 -- If there is no DO-END block for an accept, or if the DO-END block has
475 -- only null statements, then it is possible to do the Rendezvous with much
476 -- less overhead using the Accept_Trivial routine in the run-time library.
477 -- However, this is not always a valid optimization. Whether it is valid or
478 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
479 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
480 -- a rescheduling is required, so this optimization is not allowed. This
481 -- function returns True if the optimization is permitted.
483 -----------------------------
484 -- Actual_Index_Expression --
485 -----------------------------
487 function Actual_Index_Expression
491 Tsk : Entity_Id) return Node_Id
493 Ttyp : constant Entity_Id := Etype (Tsk);
501 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
502 -- Compute difference between bounds of entry family
504 --------------------------
505 -- Actual_Family_Offset --
506 --------------------------
508 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
510 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
511 -- Replace a reference to a discriminant with a selected component
512 -- denoting the discriminant of the target task.
514 -----------------------------
515 -- Actual_Discriminant_Ref --
516 -----------------------------
518 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
519 Typ : constant Entity_Id := Etype (Bound);
523 if not Is_Entity_Name (Bound)
524 or else Ekind (Entity (Bound)) /= E_Discriminant
526 if Nkind (Bound) = N_Attribute_Reference then
529 B := New_Copy_Tree (Bound);
534 Make_Selected_Component (Sloc,
535 Prefix => New_Copy_Tree (Tsk),
536 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
538 Analyze_And_Resolve (B, Typ);
542 Make_Attribute_Reference (Sloc,
543 Attribute_Name => Name_Pos,
544 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
545 Expressions => New_List (B));
546 end Actual_Discriminant_Ref;
548 -- Start of processing for Actual_Family_Offset
552 Make_Op_Subtract (Sloc,
553 Left_Opnd => Actual_Discriminant_Ref (Hi),
554 Right_Opnd => Actual_Discriminant_Ref (Lo));
555 end Actual_Family_Offset;
557 -- Start of processing for Actual_Index_Expression
560 -- The queues of entries and entry families appear in textual order in
561 -- the associated record. The entry index is computed as the sum of the
562 -- number of queues for all entries that precede the designated one, to
563 -- which is added the index expression, if this expression denotes a
564 -- member of a family.
566 -- The following is a place holder for the count of simple entries
568 Num := Make_Integer_Literal (Sloc, 1);
570 -- We construct an expression which is a series of addition operations.
571 -- See comments in Entry_Index_Expression, which is identical in
574 if Present (Index) then
575 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
581 Actual_Family_Offset (
582 Make_Attribute_Reference (Sloc,
583 Attribute_Name => Name_Pos,
584 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
585 Expressions => New_List (Relocate_Node (Index))),
586 Type_Low_Bound (S)));
591 -- Now add lengths of preceding entries and entry families
593 Prev := First_Entity (Ttyp);
594 while Chars (Prev) /= Chars (Ent)
595 or else (Ekind (Prev) /= Ekind (Ent))
596 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
598 if Ekind (Prev) = E_Entry then
599 Set_Intval (Num, Intval (Num) + 1);
601 elsif Ekind (Prev) = E_Entry_Family then
603 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
605 -- The need for the following full view retrieval stems from this
606 -- complex case of nested generics and tasking:
609 -- type Formal_Index is range <>;
612 -- type Index is private;
619 -- type Index is new Formal_Index range 1 .. 10;
622 -- package body Outer is
624 -- entry Fam (Index); -- (2)
627 -- package body Inner is -- (3)
635 -- We are currently building the index expression for the entry
636 -- call "T.E" (1). Part of the expansion must mention the range
637 -- of the discrete type "Index" (2) of entry family "Fam".
639 -- However only the private view of type "Index" is available to
640 -- the inner generic (3) because there was no prior mention of
641 -- the type inside "Inner". This visibility requirement is
642 -- implicit and cannot be detected during the construction of
643 -- the generic trees and needs special handling.
646 and then Is_Private_Type (S)
647 and then Present (Full_View (S))
652 Lo := Type_Low_Bound (S);
653 Hi := Type_High_Bound (S);
660 Left_Opnd => Actual_Family_Offset (Hi, Lo),
661 Right_Opnd => Make_Integer_Literal (Sloc, 1)));
663 -- Other components are anonymous types to be ignored
673 end Actual_Index_Expression;
675 --------------------------
676 -- Add_Formal_Renamings --
677 --------------------------
679 procedure Add_Formal_Renamings
685 Ptr : constant Entity_Id :=
687 (Next (First (Parameter_Specifications (Spec))));
688 -- The name of the formal that holds the address of the parameter block
695 Renamed_Formal : Node_Id;
698 Formal := First_Formal (Ent);
699 while Present (Formal) loop
700 Comp := Entry_Component (Formal);
702 Make_Defining_Identifier (Sloc (Formal),
703 Chars => Chars (Formal));
704 Set_Etype (New_F, Etype (Formal));
705 Set_Scope (New_F, Ent);
707 -- Now we set debug info needed on New_F even though it does not come
708 -- from source, so that the debugger will get the right information
709 -- for these generated names.
711 Set_Debug_Info_Needed (New_F);
713 if Ekind (Formal) = E_In_Parameter then
714 Set_Ekind (New_F, E_Constant);
716 Set_Ekind (New_F, E_Variable);
717 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
720 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
723 Make_Selected_Component (Loc,
725 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
726 Make_Identifier (Loc, Chars (Ptr))),
727 Selector_Name => New_Occurrence_Of (Comp, Loc));
730 Build_Renamed_Formal_Declaration
731 (New_F, Formal, Comp, Renamed_Formal);
733 Append (Decl, Decls);
734 Set_Renamed_Object (Formal, New_F);
735 Next_Formal (Formal);
737 end Add_Formal_Renamings;
739 ------------------------
740 -- Add_Object_Pointer --
741 ------------------------
743 procedure Add_Object_Pointer
745 Conc_Typ : Entity_Id;
748 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
753 -- Create the renaming declaration for the Protection object of a
754 -- protected type. _Object is used by Complete_Entry_Body.
755 -- ??? An attempt to make this a renaming was unsuccessful.
757 -- Build the entity for the access type
760 Make_Defining_Identifier (Loc,
761 New_External_Name (Chars (Rec_Typ), 'P'));
764 -- _object : poVP := poVP!O;
767 Make_Object_Declaration (Loc,
768 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject),
769 Object_Definition => New_Occurrence_Of (Obj_Ptr, Loc),
771 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
772 Set_Debug_Info_Needed (Defining_Identifier (Decl));
773 Prepend_To (Decls, Decl);
776 -- type poVP is access poV;
779 Make_Full_Type_Declaration (Loc,
780 Defining_Identifier =>
783 Make_Access_To_Object_Definition (Loc,
784 Subtype_Indication =>
785 New_Occurrence_Of (Rec_Typ, Loc)));
786 Set_Debug_Info_Needed (Defining_Identifier (Decl));
787 Prepend_To (Decls, Decl);
788 end Add_Object_Pointer;
790 -----------------------
791 -- Build_Accept_Body --
792 -----------------------
794 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
795 Loc : constant Source_Ptr := Sloc (Astat);
796 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
803 -- At the end of the statement sequence, Complete_Rendezvous is called.
804 -- A label skipping the Complete_Rendezvous, and all other accept
805 -- processing, has already been added for the expansion of requeue
806 -- statements. The Sloc is copied from the last statement since it
807 -- is really part of this last statement.
811 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
812 Insert_Before (Last (Statements (Stats)), Call);
815 -- If exception handlers are present, then append Complete_Rendezvous
816 -- calls to the handlers, and construct the required outer block. As
817 -- above, the Sloc is copied from the last statement in the sequence.
819 if Present (Exception_Handlers (Stats)) then
820 Hand := First (Exception_Handlers (Stats));
821 while Present (Hand) loop
824 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
825 Append (Call, Statements (Hand));
831 Make_Handled_Sequence_Of_Statements (Loc,
832 Statements => New_List (
833 Make_Block_Statement (Loc,
834 Handled_Statement_Sequence => Stats)));
840 -- At this stage we know that the new statement sequence does
841 -- not have an exception handler part, so we supply one to call
842 -- Exceptional_Complete_Rendezvous. This handler is
844 -- when all others =>
845 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
847 -- We handle Abort_Signal to make sure that we properly catch the abort
848 -- case and wake up the caller.
850 Ohandle := Make_Others_Choice (Loc);
851 Set_All_Others (Ohandle);
853 Set_Exception_Handlers (New_S,
855 Make_Implicit_Exception_Handler (Loc,
856 Exception_Choices => New_List (Ohandle),
858 Statements => New_List (
859 Make_Procedure_Call_Statement (Sloc (Stats),
860 Name => New_Occurrence_Of (
861 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
862 Parameter_Associations => New_List (
863 Make_Function_Call (Sloc (Stats),
866 (RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
868 Set_Parent (New_S, Astat); -- temp parent for Analyze call
869 Analyze_Exception_Handlers (Exception_Handlers (New_S));
870 Expand_Exception_Handlers (New_S);
872 -- Exceptional_Complete_Rendezvous must be called with abort still
873 -- deferred, which is the case for a "when all others" handler.
876 end Build_Accept_Body;
878 -----------------------------------
879 -- Build_Activation_Chain_Entity --
880 -----------------------------------
882 procedure Build_Activation_Chain_Entity (N : Node_Id) is
883 function Has_Activation_Chain (Stmt : Node_Id) return Boolean;
884 -- Determine whether an extended return statement has activation chain
886 --------------------------
887 -- Has_Activation_Chain --
888 --------------------------
890 function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
894 Decl := First (Return_Object_Declarations (Stmt));
895 while Present (Decl) loop
896 if Nkind (Decl) = N_Object_Declaration
897 and then Chars (Defining_Identifier (Decl)) = Name_uChain
906 end Has_Activation_Chain;
911 Context_Id : Entity_Id;
914 -- Start of processing for Build_Activation_Chain_Entity
917 -- Activation chain is never used for sequential elaboration policy, see
918 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
920 if Partition_Elaboration_Policy = 'S' then
924 Find_Enclosing_Context (N, Context, Context_Id, Decls);
926 -- If activation chain entity has not been declared already, create one
928 if Nkind (Context) = N_Extended_Return_Statement
929 or else No (Activation_Chain_Entity (Context))
931 -- Since extended return statements do not store the entity of the
932 -- chain, examine the return object declarations to avoid creating
935 if Nkind (Context) = N_Extended_Return_Statement
936 and then Has_Activation_Chain (Context)
942 Loc : constant Source_Ptr := Sloc (Context);
947 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
949 -- Note: An extended return statement is not really a task
950 -- activator, but it does have an activation chain on which to
951 -- store the tasks temporarily. On successful return, the tasks
952 -- on this chain are moved to the chain passed in by the caller.
953 -- We do not build an Activation_Chain_Entity for an extended
954 -- return statement, because we do not want to build a call to
955 -- Activate_Tasks. Task activation is the responsibility of the
958 if Nkind (Context) /= N_Extended_Return_Statement then
959 Set_Activation_Chain_Entity (Context, Chain);
963 Make_Object_Declaration (Loc,
964 Defining_Identifier => Chain,
965 Aliased_Present => True,
967 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc));
969 Prepend_To (Decls, Decl);
971 -- Ensure that _chain appears in the proper scope of the context
973 if Context_Id /= Current_Scope then
974 Push_Scope (Context_Id);
982 end Build_Activation_Chain_Entity;
984 ----------------------------
985 -- Build_Barrier_Function --
986 ----------------------------
988 function Build_Barrier_Function
991 Pid : Node_Id) return Node_Id
993 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
994 Cond : constant Node_Id := Condition (Ent_Formals);
995 Loc : constant Source_Ptr := Sloc (Cond);
996 Func_Id : constant Entity_Id := Barrier_Function (Ent);
997 Op_Decls : constant List_Id := New_List;
1002 -- Add a declaration for the Protection object, renaming declarations
1003 -- for the discriminals and privals and finally a declaration for the
1004 -- entry family index (if applicable).
1006 Install_Private_Data_Declarations (Sloc (N),
1012 Family => Ekind (Ent) = E_Entry_Family);
1014 -- If compiling with -fpreserve-control-flow, make sure we insert an
1015 -- IF statement so that the back-end knows to generate a conditional
1016 -- branch instruction, even if the condition is just the name of a
1017 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1018 -- such redundant IF statements under -fpreserve-control-flow
1019 -- (whether coming from this routine, or directly from source).
1021 if Opt.Suppress_Control_Flow_Optimizations then
1023 Make_Implicit_If_Statement (Cond,
1025 Then_Statements => New_List (
1026 Make_Simple_Return_Statement (Loc,
1027 New_Occurrence_Of (Standard_True, Loc))),
1029 Else_Statements => New_List (
1030 Make_Simple_Return_Statement (Loc,
1031 New_Occurrence_Of (Standard_False, Loc))));
1034 Stmt := Make_Simple_Return_Statement (Loc, Cond);
1037 -- Note: the condition in the barrier function needs to be properly
1038 -- processed for the C/Fortran boolean possibility, but this happens
1039 -- automatically since the return statement does this normalization.
1042 Make_Subprogram_Body (Loc,
1044 Build_Barrier_Function_Specification (Loc,
1045 Make_Defining_Identifier (Loc, Chars (Func_Id))),
1046 Declarations => Op_Decls,
1047 Handled_Statement_Sequence =>
1048 Make_Handled_Sequence_Of_Statements (Loc,
1049 Statements => New_List (Stmt)));
1050 Set_Is_Entry_Barrier_Function (Func_Body);
1053 end Build_Barrier_Function;
1055 ------------------------------------------
1056 -- Build_Barrier_Function_Specification --
1057 ------------------------------------------
1059 function Build_Barrier_Function_Specification
1061 Def_Id : Entity_Id) return Node_Id
1064 Set_Debug_Info_Needed (Def_Id);
1067 Make_Function_Specification (Loc,
1068 Defining_Unit_Name => Def_Id,
1069 Parameter_Specifications => New_List (
1070 Make_Parameter_Specification (Loc,
1071 Defining_Identifier =>
1072 Make_Defining_Identifier (Loc, Name_uO),
1074 New_Occurrence_Of (RTE (RE_Address), Loc)),
1076 Make_Parameter_Specification (Loc,
1077 Defining_Identifier =>
1078 Make_Defining_Identifier (Loc, Name_uE),
1080 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
1082 Result_Definition =>
1083 New_Occurrence_Of (Standard_Boolean, Loc));
1084 end Build_Barrier_Function_Specification;
1086 --------------------------
1087 -- Build_Call_With_Task --
1088 --------------------------
1090 function Build_Call_With_Task
1092 E : Entity_Id) return Node_Id
1094 Loc : constant Source_Ptr := Sloc (N);
1097 Make_Function_Call (Loc,
1098 Name => New_Occurrence_Of (E, Loc),
1099 Parameter_Associations => New_List (Concurrent_Ref (N)));
1100 end Build_Call_With_Task;
1102 -----------------------------
1103 -- Build_Class_Wide_Master --
1104 -----------------------------
1106 procedure Build_Class_Wide_Master (Typ : Entity_Id) is
1107 Loc : constant Source_Ptr := Sloc (Typ);
1108 Master_Decl : Node_Id;
1109 Master_Id : Entity_Id;
1110 Master_Scope : Entity_Id;
1112 Related_Node : Node_Id;
1116 -- Nothing to do if there is no task hierarchy
1118 if Restriction_Active (No_Task_Hierarchy) then
1122 -- Find the declaration that created the access type, which is either a
1123 -- type declaration, or an object declaration with an access definition,
1124 -- in which case the type is anonymous.
1126 if Is_Itype (Typ) then
1127 Related_Node := Associated_Node_For_Itype (Typ);
1129 Related_Node := Parent (Typ);
1132 Master_Scope := Find_Master_Scope (Typ);
1134 -- Nothing to do if the master scope already contains a _master entity.
1135 -- The only exception to this is the following scenario:
1138 -- Transient_Scope_1
1141 -- Transient_Scope_2
1144 -- In this case the source scope is marked as having the master entity
1145 -- even though the actual declaration appears inside an inner scope. If
1146 -- the second transient scope requires a _master, it cannot use the one
1147 -- already declared because the entity is not visible.
1149 Name_Id := Make_Identifier (Loc, Name_uMaster);
1150 Master_Decl := Empty;
1152 if not Has_Master_Entity (Master_Scope)
1153 or else No (Current_Entity_In_Scope (Name_Id))
1156 Set_Has_Master_Entity (Master_Scope);
1159 -- _master : constant Integer := Current_Master.all;
1162 Make_Object_Declaration (Loc,
1163 Defining_Identifier =>
1164 Make_Defining_Identifier (Loc, Name_uMaster),
1165 Constant_Present => True,
1166 Object_Definition =>
1167 New_Occurrence_Of (Standard_Integer, Loc),
1169 Make_Explicit_Dereference (Loc,
1170 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
1172 Insert_Action (Find_Hook_Context (Related_Node), Master_Decl);
1173 Analyze (Master_Decl);
1175 -- Mark the containing scope as a task master. Masters associated
1176 -- with return statements are already marked at this stage (see
1177 -- Analyze_Subprogram_Body).
1179 if Ekind (Current_Scope) /= E_Return_Statement then
1181 Par : Node_Id := Related_Node;
1184 while Nkind (Par) /= N_Compilation_Unit loop
1185 Par := Parent (Par);
1187 -- If we fall off the top, we are at the outer level,
1188 -- and the environment task is our effective master,
1189 -- so nothing to mark.
1191 if Nkind_In (Par, N_Block_Statement,
1195 Set_Is_Task_Master (Par);
1205 Make_Defining_Identifier (Loc, New_External_Name (Chars (Typ), 'M'));
1208 -- typeMnn renames _master;
1211 Make_Object_Renaming_Declaration (Loc,
1212 Defining_Identifier => Master_Id,
1213 Subtype_Mark => New_Occurrence_Of (Standard_Integer, Loc),
1216 -- If the master is declared locally, add the renaming declaration
1217 -- immediately after it, to prevent access-before-elaboration in the
1220 if Present (Master_Decl) then
1221 Insert_After (Master_Decl, Ren_Decl);
1225 Insert_Action (Related_Node, Ren_Decl);
1228 Set_Master_Id (Typ, Master_Id);
1229 end Build_Class_Wide_Master;
1231 ----------------------------
1232 -- Build_Contract_Wrapper --
1233 ----------------------------
1235 procedure Build_Contract_Wrapper (E : Entity_Id; Decl : Node_Id) is
1236 Conc_Typ : constant Entity_Id := Scope (E);
1237 Loc : constant Source_Ptr := Sloc (E);
1239 procedure Add_Discriminant_Renamings
1240 (Obj_Id : Entity_Id;
1242 -- Add renaming declarations for all discriminants of concurrent type
1243 -- Conc_Typ. Obj_Id is the entity of the wrapper formal parameter which
1244 -- represents the concurrent object.
1246 procedure Add_Matching_Formals
1248 Actuals : in out List_Id);
1249 -- Add formal parameters that match those of entry E to list Formals.
1250 -- The routine also adds matching actuals for the new formals to list
1253 procedure Transfer_Pragma (Prag : Node_Id; To : in out List_Id);
1254 -- Relocate pragma Prag to list To. The routine creates a new list if
1255 -- To does not exist.
1257 --------------------------------
1258 -- Add_Discriminant_Renamings --
1259 --------------------------------
1261 procedure Add_Discriminant_Renamings
1262 (Obj_Id : Entity_Id;
1268 -- Inspect the discriminants of the concurrent type and generate a
1269 -- renaming for each one.
1271 if Has_Discriminants (Conc_Typ) then
1272 Discr := First_Discriminant (Conc_Typ);
1273 while Present (Discr) loop
1275 Make_Object_Renaming_Declaration (Loc,
1276 Defining_Identifier =>
1277 Make_Defining_Identifier (Loc, Chars (Discr)),
1279 New_Occurrence_Of (Etype (Discr), Loc),
1281 Make_Selected_Component (Loc,
1282 Prefix => New_Occurrence_Of (Obj_Id, Loc),
1284 Make_Identifier (Loc, Chars (Discr)))));
1286 Next_Discriminant (Discr);
1289 end Add_Discriminant_Renamings;
1291 --------------------------
1292 -- Add_Matching_Formals --
1293 --------------------------
1295 procedure Add_Matching_Formals
1297 Actuals : in out List_Id)
1300 New_Formal : Entity_Id;
1303 -- Inspect the formal parameters of the entry and generate a new
1304 -- matching formal with the same name for the wrapper. A reference
1305 -- to the new formal becomes an actual in the entry call.
1307 Formal := First_Formal (E);
1308 while Present (Formal) loop
1309 New_Formal := Make_Defining_Identifier (Loc, Chars (Formal));
1311 Make_Parameter_Specification (Loc,
1312 Defining_Identifier => New_Formal,
1313 In_Present => In_Present (Parent (Formal)),
1314 Out_Present => Out_Present (Parent (Formal)),
1316 New_Occurrence_Of (Etype (Formal), Loc)));
1318 if No (Actuals) then
1319 Actuals := New_List;
1322 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1323 Next_Formal (Formal);
1325 end Add_Matching_Formals;
1327 ---------------------
1328 -- Transfer_Pragma --
1329 ---------------------
1331 procedure Transfer_Pragma (Prag : Node_Id; To : in out List_Id) is
1339 New_Prag := Relocate_Node (Prag);
1341 Set_Analyzed (New_Prag, False);
1342 Append (New_Prag, To);
1343 end Transfer_Pragma;
1347 Items : constant Node_Id := Contract (E);
1348 Actuals : List_Id := No_List;
1351 Decls : List_Id := No_List;
1353 Has_Pragma : Boolean := False;
1354 Index_Id : Entity_Id;
1357 Wrapper_Id : Entity_Id;
1359 -- Start of processing for Build_Contract_Wrapper
1362 -- This routine generates a specialized wrapper for a protected or task
1363 -- entry [family] which implements precondition/postcondition semantics.
1364 -- Preconditions and case guards of contract cases are checked before
1365 -- the protected action or rendezvous takes place. Postconditions and
1366 -- consequences of contract cases are checked after the protected action
1367 -- or rendezvous takes place. The structure of the generated wrapper is
1370 -- procedure Wrapper
1371 -- (Obj_Id : Conc_Typ; -- concurrent object
1372 -- [Index : Index_Typ;] -- index of entry family
1373 -- [Formal_1 : ...; -- parameters of original entry
1376 -- [Discr_1 : ... renames Obj_Id.Discr_1; -- discriminant
1377 -- Discr_N : ... renames Obj_Id.Discr_N;] -- renamings
1379 -- <precondition checks>
1380 -- <case guard checks>
1382 -- procedure _Postconditions is
1384 -- <postcondition checks>
1385 -- <consequence checks>
1386 -- end _Postconditions;
1389 -- Entry_Call (Obj_Id, [Index,] [Formal_1, Formal_N]);
1393 -- Create the wrapper only when the entry has at least one executable
1394 -- contract item such as contract cases, precondition or postcondition.
1396 if Present (Items) then
1398 -- Inspect the list of pre/postconditions and transfer all available
1399 -- pragmas to the declarative list of the wrapper.
1401 Prag := Pre_Post_Conditions (Items);
1402 while Present (Prag) loop
1403 if Nam_In (Pragma_Name_Unmapped (Prag),
1404 Name_Postcondition, Name_Precondition)
1405 and then Is_Checked (Prag)
1408 Transfer_Pragma (Prag, To => Decls);
1411 Prag := Next_Pragma (Prag);
1414 -- Inspect the list of test/contract cases and transfer only contract
1415 -- cases pragmas to the declarative part of the wrapper.
1417 Prag := Contract_Test_Cases (Items);
1418 while Present (Prag) loop
1419 if Pragma_Name (Prag) = Name_Contract_Cases
1420 and then Is_Checked (Prag)
1423 Transfer_Pragma (Prag, To => Decls);
1426 Prag := Next_Pragma (Prag);
1430 -- The entry lacks executable contract items and a wrapper is not needed
1432 if not Has_Pragma then
1436 -- Create the profile of the wrapper. The first formal parameter is the
1437 -- concurrent object.
1440 Make_Defining_Identifier (Loc,
1441 Chars => New_External_Name (Chars (Conc_Typ), 'A'));
1443 Formals := New_List (
1444 Make_Parameter_Specification (Loc,
1445 Defining_Identifier => Obj_Id,
1446 Out_Present => True,
1448 Parameter_Type => New_Occurrence_Of (Conc_Typ, Loc)));
1450 -- Construct the call to the original entry. The call will be gradually
1451 -- augmented with an optional entry index and extra parameters.
1454 Make_Selected_Component (Loc,
1455 Prefix => New_Occurrence_Of (Obj_Id, Loc),
1456 Selector_Name => New_Occurrence_Of (E, Loc));
1458 -- When creating a wrapper for an entry family, the second formal is the
1461 if Ekind (E) = E_Entry_Family then
1462 Index_Id := Make_Defining_Identifier (Loc, Name_I);
1465 Make_Parameter_Specification (Loc,
1466 Defining_Identifier => Index_Id,
1468 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
1470 -- The call to the original entry becomes an indexed component to
1471 -- accommodate the entry index.
1474 Make_Indexed_Component (Loc,
1476 Expressions => New_List (New_Occurrence_Of (Index_Id, Loc)));
1479 -- Add formal parameters to match those of the entry and build actuals
1480 -- for the entry call.
1482 Add_Matching_Formals (Formals, Actuals);
1485 Make_Procedure_Call_Statement (Loc,
1487 Parameter_Associations => Actuals);
1489 -- Add renaming declarations for the discriminants of the enclosing type
1490 -- as the various contract items may reference them.
1492 Add_Discriminant_Renamings (Obj_Id, Decls);
1495 Make_Defining_Identifier (Loc, New_External_Name (Chars (E), 'E'));
1496 Set_Contract_Wrapper (E, Wrapper_Id);
1497 Set_Is_Entry_Wrapper (Wrapper_Id);
1499 -- The wrapper body is analyzed when the enclosing type is frozen
1501 Append_Freeze_Action (Defining_Entity (Decl),
1502 Make_Subprogram_Body (Loc,
1504 Make_Procedure_Specification (Loc,
1505 Defining_Unit_Name => Wrapper_Id,
1506 Parameter_Specifications => Formals),
1507 Declarations => Decls,
1508 Handled_Statement_Sequence =>
1509 Make_Handled_Sequence_Of_Statements (Loc,
1510 Statements => New_List (Call))));
1511 end Build_Contract_Wrapper;
1513 --------------------------------
1514 -- Build_Corresponding_Record --
1515 --------------------------------
1517 function Build_Corresponding_Record
1520 Loc : Source_Ptr) return Node_Id
1522 Rec_Ent : constant Entity_Id :=
1523 Make_Defining_Identifier
1524 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1527 New_Disc : Entity_Id;
1531 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1532 Set_Ekind (Rec_Ent, E_Record_Type);
1533 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1534 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1535 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1536 Set_Stored_Constraint (Rec_Ent, No_Elist);
1539 -- Use discriminals to create list of discriminants for record, and
1540 -- create new discriminals for use in default expressions, etc. It is
1541 -- worth noting that a task discriminant gives rise to 5 entities;
1543 -- a) The original discriminant.
1544 -- b) The discriminal for use in the task.
1545 -- c) The discriminant of the corresponding record.
1546 -- d) The discriminal for the init proc of the corresponding record.
1547 -- e) The local variable that renames the discriminant in the procedure
1548 -- for the task body.
1550 -- In fact the discriminals b) are used in the renaming declarations
1551 -- for e). See details in einfo (Handling of Discriminants).
1553 if Present (Discriminant_Specifications (N)) then
1555 Disc := First_Discriminant (Ctyp);
1557 while Present (Disc) loop
1558 New_Disc := CR_Discriminant (Disc);
1561 Make_Discriminant_Specification (Loc,
1562 Defining_Identifier => New_Disc,
1563 Discriminant_Type =>
1564 New_Occurrence_Of (Etype (Disc), Loc),
1566 New_Copy (Discriminant_Default_Value (Disc))));
1568 Next_Discriminant (Disc);
1575 -- Now we can construct the record type declaration. Note that this
1576 -- record is "limited tagged". It is "limited" to reflect the underlying
1577 -- limitedness of the task or protected object that it represents, and
1578 -- ensuring for example that it is properly passed by reference. It is
1579 -- "tagged" to give support to dispatching calls through interfaces. We
1580 -- propagate here the list of interfaces covered by the concurrent type
1581 -- (Ada 2005: AI-345).
1584 Make_Full_Type_Declaration (Loc,
1585 Defining_Identifier => Rec_Ent,
1586 Discriminant_Specifications => Dlist,
1588 Make_Record_Definition (Loc,
1590 Make_Component_List (Loc, Component_Items => Cdecls),
1592 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1593 Interface_List => Interface_List (N),
1594 Limited_Present => True));
1595 end Build_Corresponding_Record;
1597 ---------------------------------
1598 -- Build_Dispatching_Tag_Check --
1599 ---------------------------------
1601 function Build_Dispatching_Tag_Check
1603 N : Node_Id) return Node_Id
1605 Loc : constant Source_Ptr := Sloc (N);
1612 New_Occurrence_Of (K, Loc),
1614 New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc)),
1618 New_Occurrence_Of (K, Loc),
1620 New_Occurrence_Of (RTE (RE_TK_Tagged), Loc)));
1621 end Build_Dispatching_Tag_Check;
1623 ----------------------------------
1624 -- Build_Entry_Count_Expression --
1625 ----------------------------------
1627 function Build_Entry_Count_Expression
1628 (Concurrent_Type : Node_Id;
1629 Component_List : List_Id;
1630 Loc : Source_Ptr) return Node_Id
1642 -- Count number of non-family entries
1645 Ent := First_Entity (Concurrent_Type);
1646 while Present (Ent) loop
1647 if Ekind (Ent) = E_Entry then
1654 Ecount := Make_Integer_Literal (Loc, Eindx);
1656 -- Loop through entry families building the addition nodes
1658 Ent := First_Entity (Concurrent_Type);
1659 Comp := First (Component_List);
1660 while Present (Ent) loop
1661 if Ekind (Ent) = E_Entry_Family then
1662 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1666 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1667 Hi := Type_High_Bound (Typ);
1668 Lo := Type_Low_Bound (Typ);
1669 Large := Is_Potentially_Large_Family
1670 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1673 Left_Opnd => Ecount,
1675 Family_Size (Loc, Hi, Lo, Concurrent_Type, Large));
1682 end Build_Entry_Count_Expression;
1684 ---------------------------
1685 -- Build_Parameter_Block --
1686 ---------------------------
1688 function Build_Parameter_Block
1692 Decls : List_Id) return Entity_Id
1698 Has_Comp : Boolean := False;
1702 Actual := First (Actuals);
1704 Formal := Defining_Identifier (First (Formals));
1706 while Present (Actual) loop
1707 if not Is_Controlling_Actual (Actual) then
1710 -- type Ann is access all <actual-type>
1712 Comp_Nam := Make_Temporary (Loc, 'A');
1713 Set_Is_Param_Block_Component_Type (Comp_Nam);
1716 Make_Full_Type_Declaration (Loc,
1717 Defining_Identifier => Comp_Nam,
1719 Make_Access_To_Object_Definition (Loc,
1720 All_Present => True,
1721 Constant_Present => Ekind (Formal) = E_In_Parameter,
1722 Subtype_Indication =>
1723 New_Occurrence_Of (Etype (Actual), Loc))));
1729 Make_Component_Declaration (Loc,
1730 Defining_Identifier =>
1731 Make_Defining_Identifier (Loc, Chars (Formal)),
1732 Component_Definition =>
1733 Make_Component_Definition (Loc,
1736 Subtype_Indication =>
1737 New_Occurrence_Of (Comp_Nam, Loc))));
1742 Next_Actual (Actual);
1743 Next_Formal_With_Extras (Formal);
1746 Rec_Nam := Make_Temporary (Loc, 'P');
1751 -- type Pnn is record
1756 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1757 -- the original parameter names and Ann1 .. AnnN are the access to
1761 Make_Full_Type_Declaration (Loc,
1762 Defining_Identifier =>
1765 Make_Record_Definition (Loc,
1767 Make_Component_List (Loc, Comps))));
1770 -- type Pnn is null record;
1773 Make_Full_Type_Declaration (Loc,
1774 Defining_Identifier =>
1777 Make_Record_Definition (Loc,
1778 Null_Present => True,
1779 Component_List => Empty)));
1783 end Build_Parameter_Block;
1785 --------------------------------------
1786 -- Build_Renamed_Formal_Declaration --
1787 --------------------------------------
1789 function Build_Renamed_Formal_Declaration
1793 Renamed_Formal : Node_Id) return Node_Id
1795 Loc : constant Source_Ptr := Sloc (New_F);
1799 -- If the formal is a tagged incomplete type, it is already passed
1800 -- by reference, so it is sufficient to rename the pointer component
1801 -- that corresponds to the actual. Otherwise we need to dereference
1802 -- the pointer component to obtain the actual.
1804 if Is_Incomplete_Type (Etype (Formal))
1805 and then Is_Tagged_Type (Etype (Formal))
1808 Make_Object_Renaming_Declaration (Loc,
1809 Defining_Identifier => New_F,
1810 Subtype_Mark => New_Occurrence_Of (Etype (Comp), Loc),
1811 Name => Renamed_Formal);
1815 Make_Object_Renaming_Declaration (Loc,
1816 Defining_Identifier => New_F,
1817 Subtype_Mark => New_Occurrence_Of (Etype (Formal), Loc),
1819 Make_Explicit_Dereference (Loc, Renamed_Formal));
1823 end Build_Renamed_Formal_Declaration;
1825 --------------------------
1826 -- Build_Wrapper_Bodies --
1827 --------------------------
1829 procedure Build_Wrapper_Bodies
1834 Rec_Typ : Entity_Id;
1836 function Build_Wrapper_Body
1838 Subp_Id : Entity_Id;
1839 Obj_Typ : Entity_Id;
1840 Formals : List_Id) return Node_Id;
1841 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
1842 -- associated with a protected or task type. Subp_Id is the subprogram
1843 -- name which will be wrapped. Obj_Typ is the type of the new formal
1844 -- parameter which handles dispatching and object notation. Formals are
1845 -- the original formals of Subp_Id which will be explicitly replicated.
1847 ------------------------
1848 -- Build_Wrapper_Body --
1849 ------------------------
1851 function Build_Wrapper_Body
1853 Subp_Id : Entity_Id;
1854 Obj_Typ : Entity_Id;
1855 Formals : List_Id) return Node_Id
1857 Body_Spec : Node_Id;
1860 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
1862 -- The subprogram is not overriding or is not a primitive declared
1863 -- between two views.
1865 if No (Body_Spec) then
1870 Actuals : List_Id := No_List;
1872 First_Form : Node_Id;
1877 -- Map formals to actuals. Use the list built for the wrapper
1878 -- spec, skipping the object notation parameter.
1880 First_Form := First (Parameter_Specifications (Body_Spec));
1882 Formal := First_Form;
1885 if Present (Formal) then
1886 Actuals := New_List;
1887 while Present (Formal) loop
1889 Make_Identifier (Loc,
1890 Chars => Chars (Defining_Identifier (Formal))));
1895 -- Special processing for primitives declared between a private
1896 -- type and its completion: the wrapper needs a properly typed
1897 -- parameter if the wrapped operation has a controlling first
1898 -- parameter. Note that this might not be the case for a function
1899 -- with a controlling result.
1901 if Is_Private_Primitive_Subprogram (Subp_Id) then
1902 if No (Actuals) then
1903 Actuals := New_List;
1906 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
1907 Prepend_To (Actuals,
1908 Unchecked_Convert_To
1909 (Corresponding_Concurrent_Type (Obj_Typ),
1910 Make_Identifier (Loc, Name_uO)));
1913 Prepend_To (Actuals,
1914 Make_Identifier (Loc,
1915 Chars => Chars (Defining_Identifier (First_Form))));
1918 Nam := New_Occurrence_Of (Subp_Id, Loc);
1920 -- An access-to-variable object parameter requires an explicit
1921 -- dereference in the unchecked conversion. This case occurs
1922 -- when a protected entry wrapper must override an interface
1923 -- level procedure with interface access as first parameter.
1925 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
1927 if Nkind (Parameter_Type (First_Form)) =
1931 Make_Explicit_Dereference (Loc,
1932 Prefix => Make_Identifier (Loc, Name_uO));
1934 Conv_Id := Make_Identifier (Loc, Name_uO);
1938 Make_Selected_Component (Loc,
1940 Unchecked_Convert_To
1941 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
1942 Selector_Name => New_Occurrence_Of (Subp_Id, Loc));
1945 -- Create the subprogram body. For a function, the call to the
1946 -- actual subprogram has to be converted to the corresponding
1947 -- record if it is a controlling result.
1949 if Ekind (Subp_Id) = E_Function then
1955 Make_Function_Call (Loc,
1957 Parameter_Associations => Actuals);
1959 if Has_Controlling_Result (Subp_Id) then
1961 Unchecked_Convert_To
1962 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
1966 Make_Subprogram_Body (Loc,
1967 Specification => Body_Spec,
1968 Declarations => Empty_List,
1969 Handled_Statement_Sequence =>
1970 Make_Handled_Sequence_Of_Statements (Loc,
1971 Statements => New_List (
1972 Make_Simple_Return_Statement (Loc, Res))));
1977 Make_Subprogram_Body (Loc,
1978 Specification => Body_Spec,
1979 Declarations => Empty_List,
1980 Handled_Statement_Sequence =>
1981 Make_Handled_Sequence_Of_Statements (Loc,
1982 Statements => New_List (
1983 Make_Procedure_Call_Statement (Loc,
1985 Parameter_Associations => Actuals))));
1988 end Build_Wrapper_Body;
1990 -- Start of processing for Build_Wrapper_Bodies
1993 if Is_Concurrent_Type (Typ) then
1994 Rec_Typ := Corresponding_Record_Type (Typ);
1999 -- Generate wrapper bodies for a concurrent type which implements an
2002 if Present (Interfaces (Rec_Typ)) then
2004 Insert_Nod : Node_Id;
2006 Prim_Elmt : Elmt_Id;
2007 Prim_Decl : Node_Id;
2009 Wrap_Body : Node_Id;
2010 Wrap_Id : Entity_Id;
2015 -- Examine all primitive operations of the corresponding record
2016 -- type, looking for wrapper specs. Generate bodies in order to
2019 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
2020 while Present (Prim_Elmt) loop
2021 Prim := Node (Prim_Elmt);
2023 if (Ekind (Prim) = E_Function
2024 or else Ekind (Prim) = E_Procedure)
2025 and then Is_Primitive_Wrapper (Prim)
2027 Subp := Wrapped_Entity (Prim);
2028 Prim_Decl := Parent (Parent (Prim));
2031 Build_Wrapper_Body (Loc,
2034 Formals => Parameter_Specifications (Parent (Subp)));
2035 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2037 Set_Corresponding_Spec (Wrap_Body, Prim);
2038 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2040 Insert_After (Insert_Nod, Wrap_Body);
2041 Insert_Nod := Wrap_Body;
2043 Analyze (Wrap_Body);
2046 Next_Elmt (Prim_Elmt);
2050 end Build_Wrapper_Bodies;
2052 ------------------------
2053 -- Build_Wrapper_Spec --
2054 ------------------------
2056 function Build_Wrapper_Spec
2057 (Subp_Id : Entity_Id;
2058 Obj_Typ : Entity_Id;
2059 Formals : List_Id) return Node_Id
2061 function Overriding_Possible
2062 (Iface_Op : Entity_Id;
2063 Wrapper : Entity_Id) return Boolean;
2064 -- Determine whether a primitive operation can be overridden by Wrapper.
2065 -- Iface_Op is the candidate primitive operation of an interface type,
2066 -- Wrapper is the generated entry wrapper.
2068 function Replicate_Formals
2070 Formals : List_Id) return List_Id;
2071 -- An explicit parameter replication is required due to the Is_Entry_
2072 -- Formal flag being set for all the formals of an entry. The explicit
2073 -- replication removes the flag that would otherwise cause a different
2074 -- path of analysis.
2076 -------------------------
2077 -- Overriding_Possible --
2078 -------------------------
2080 function Overriding_Possible
2081 (Iface_Op : Entity_Id;
2082 Wrapper : Entity_Id) return Boolean
2084 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2085 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2087 function Type_Conformant_Parameters
2088 (Iface_Op_Params : List_Id;
2089 Wrapper_Params : List_Id) return Boolean;
2090 -- Determine whether the parameters of the generated entry wrapper
2091 -- and those of a primitive operation are type conformant. During
2092 -- this check, the first parameter of the primitive operation is
2093 -- skipped if it is a controlling argument: protected functions
2094 -- may have a controlling result.
2096 --------------------------------
2097 -- Type_Conformant_Parameters --
2098 --------------------------------
2100 function Type_Conformant_Parameters
2101 (Iface_Op_Params : List_Id;
2102 Wrapper_Params : List_Id) return Boolean
2104 Iface_Op_Param : Node_Id;
2105 Iface_Op_Typ : Entity_Id;
2106 Wrapper_Param : Node_Id;
2107 Wrapper_Typ : Entity_Id;
2110 -- Skip the first (controlling) parameter of primitive operation
2112 Iface_Op_Param := First (Iface_Op_Params);
2114 if Present (First_Formal (Iface_Op))
2115 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2117 Iface_Op_Param := Next (Iface_Op_Param);
2120 Wrapper_Param := First (Wrapper_Params);
2121 while Present (Iface_Op_Param)
2122 and then Present (Wrapper_Param)
2124 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2125 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2127 -- The two parameters must be mode conformant
2129 if not Conforming_Types
2130 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2135 Next (Iface_Op_Param);
2136 Next (Wrapper_Param);
2139 -- One of the lists is longer than the other
2141 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2146 end Type_Conformant_Parameters;
2148 -- Start of processing for Overriding_Possible
2151 if Chars (Iface_Op) /= Chars (Wrapper) then
2155 -- If an inherited subprogram is implemented by a protected procedure
2156 -- or an entry, then the first parameter of the inherited subprogram
2157 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2159 if Ekind (Iface_Op) = E_Procedure
2160 and then Present (Parameter_Specifications (Iface_Op_Spec))
2163 Obj_Param : constant Node_Id :=
2164 First (Parameter_Specifications (Iface_Op_Spec));
2166 if not Out_Present (Obj_Param)
2167 and then Nkind (Parameter_Type (Obj_Param)) /=
2176 Type_Conformant_Parameters
2177 (Parameter_Specifications (Iface_Op_Spec),
2178 Parameter_Specifications (Wrapper_Spec));
2179 end Overriding_Possible;
2181 -----------------------
2182 -- Replicate_Formals --
2183 -----------------------
2185 function Replicate_Formals
2187 Formals : List_Id) return List_Id
2189 New_Formals : constant List_Id := New_List;
2191 Param_Type : Node_Id;
2194 Formal := First (Formals);
2196 -- Skip the object parameter when dealing with primitives declared
2197 -- between two views.
2199 if Is_Private_Primitive_Subprogram (Subp_Id)
2200 and then not Has_Controlling_Result (Subp_Id)
2202 Formal := Next (Formal);
2205 while Present (Formal) loop
2207 -- Create an explicit copy of the entry parameter
2209 -- When creating the wrapper subprogram for a primitive operation
2210 -- of a protected interface we must construct an equivalent
2211 -- signature to that of the overriding operation. For regular
2212 -- parameters we can just use the type of the formal, but for
2213 -- access to subprogram parameters we need to reanalyze the
2214 -- parameter type to create local entities for the signature of
2215 -- the subprogram type. Using the entities of the overriding
2216 -- subprogram will result in out-of-scope errors in the back-end.
2218 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2219 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2222 New_Occurrence_Of (Etype (Parameter_Type (Formal)), Loc);
2225 Append_To (New_Formals,
2226 Make_Parameter_Specification (Loc,
2227 Defining_Identifier =>
2228 Make_Defining_Identifier (Loc,
2229 Chars => Chars (Defining_Identifier (Formal))),
2230 In_Present => In_Present (Formal),
2231 Out_Present => Out_Present (Formal),
2232 Null_Exclusion_Present => Null_Exclusion_Present (Formal),
2233 Parameter_Type => Param_Type));
2239 end Replicate_Formals;
2243 Loc : constant Source_Ptr := Sloc (Subp_Id);
2244 First_Param : Node_Id := Empty;
2246 Iface_Elmt : Elmt_Id;
2247 Iface_Op : Entity_Id;
2248 Iface_Op_Elmt : Elmt_Id;
2249 Overridden_Subp : Entity_Id;
2251 -- Start of processing for Build_Wrapper_Spec
2254 -- No point in building wrappers for untagged concurrent types
2256 pragma Assert (Is_Tagged_Type (Obj_Typ));
2258 -- Check if this subprogram has a profile that matches some interface
2261 Check_Synchronized_Overriding (Subp_Id, Overridden_Subp);
2263 if Present (Overridden_Subp) then
2265 First (Parameter_Specifications (Parent (Overridden_Subp)));
2267 -- An entry or a protected procedure can override a routine where the
2268 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2269 -- type. Since the wrapper must have the exact same signature as that of
2270 -- the overridden subprogram, we try to find the overriding candidate
2271 -- and use its controlling formal.
2273 -- Check every implemented interface
2275 elsif Present (Interfaces (Obj_Typ)) then
2276 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2277 Search : while Present (Iface_Elmt) loop
2278 Iface := Node (Iface_Elmt);
2280 -- Check every interface primitive
2282 if Present (Primitive_Operations (Iface)) then
2283 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2284 while Present (Iface_Op_Elmt) loop
2285 Iface_Op := Node (Iface_Op_Elmt);
2287 -- Ignore predefined primitives
2289 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2290 Iface_Op := Ultimate_Alias (Iface_Op);
2292 -- The current primitive operation can be overridden by
2293 -- the generated entry wrapper.
2295 if Overriding_Possible (Iface_Op, Subp_Id) then
2297 First (Parameter_Specifications (Parent (Iface_Op)));
2303 Next_Elmt (Iface_Op_Elmt);
2307 Next_Elmt (Iface_Elmt);
2311 -- Do not generate the wrapper if no interface primitive is covered by
2312 -- the subprogram and it is not a primitive declared between two views
2313 -- (see Process_Full_View).
2316 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2322 Wrapper_Id : constant Entity_Id :=
2323 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2324 New_Formals : List_Id;
2325 Obj_Param : Node_Id;
2326 Obj_Param_Typ : Entity_Id;
2329 -- Minimum decoration is needed to catch the entity in
2330 -- Sem_Ch6.Override_Dispatching_Operation.
2332 if Ekind (Subp_Id) = E_Function then
2333 Set_Ekind (Wrapper_Id, E_Function);
2335 Set_Ekind (Wrapper_Id, E_Procedure);
2338 Set_Is_Primitive_Wrapper (Wrapper_Id);
2339 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2340 Set_Is_Private_Primitive (Wrapper_Id,
2341 Is_Private_Primitive_Subprogram (Subp_Id));
2343 -- Process the formals
2345 New_Formals := Replicate_Formals (Loc, Formals);
2347 -- A function with a controlling result and no first controlling
2348 -- formal needs no additional parameter.
2350 if Has_Controlling_Result (Subp_Id)
2352 (No (First_Formal (Subp_Id))
2353 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2357 -- Routine Subp_Id has been found to override an interface primitive.
2358 -- If the interface operation has an access parameter, create a copy
2359 -- of it, with the same null exclusion indicator if present.
2361 elsif Present (First_Param) then
2362 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2364 Make_Access_Definition (Loc,
2366 New_Occurrence_Of (Obj_Typ, Loc),
2367 Null_Exclusion_Present =>
2368 Null_Exclusion_Present (Parameter_Type (First_Param)),
2370 Constant_Present (Parameter_Type (First_Param)));
2372 Obj_Param_Typ := New_Occurrence_Of (Obj_Typ, Loc);
2376 Make_Parameter_Specification (Loc,
2377 Defining_Identifier =>
2378 Make_Defining_Identifier (Loc,
2380 In_Present => In_Present (First_Param),
2381 Out_Present => Out_Present (First_Param),
2382 Parameter_Type => Obj_Param_Typ);
2384 Prepend_To (New_Formals, Obj_Param);
2386 -- If we are dealing with a primitive declared between two views,
2387 -- implemented by a synchronized operation, we need to create
2388 -- a default parameter. The mode of the parameter must match that
2389 -- of the primitive operation.
2392 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2395 Make_Parameter_Specification (Loc,
2396 Defining_Identifier =>
2397 Make_Defining_Identifier (Loc, Name_uO),
2399 In_Present (Parent (First_Entity (Subp_Id))),
2400 Out_Present => Ekind (Subp_Id) /= E_Function,
2401 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2403 Prepend_To (New_Formals, Obj_Param);
2406 -- Build the final spec. If it is a function with a controlling
2407 -- result, it is a primitive operation of the corresponding
2408 -- record type, so mark the spec accordingly.
2410 if Ekind (Subp_Id) = E_Function then
2415 if Has_Controlling_Result (Subp_Id) then
2418 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2420 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2424 Make_Function_Specification (Loc,
2425 Defining_Unit_Name => Wrapper_Id,
2426 Parameter_Specifications => New_Formals,
2427 Result_Definition => Res_Def);
2431 Make_Procedure_Specification (Loc,
2432 Defining_Unit_Name => Wrapper_Id,
2433 Parameter_Specifications => New_Formals);
2436 end Build_Wrapper_Spec;
2438 -------------------------
2439 -- Build_Wrapper_Specs --
2440 -------------------------
2442 procedure Build_Wrapper_Specs
2448 Rec_Typ : Entity_Id;
2449 procedure Scan_Declarations (L : List_Id);
2450 -- Common processing for visible and private declarations
2451 -- of a protected type.
2453 procedure Scan_Declarations (L : List_Id) is
2455 Wrap_Decl : Node_Id;
2456 Wrap_Spec : Node_Id;
2464 while Present (Decl) loop
2467 if Nkind (Decl) = N_Entry_Declaration
2468 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2472 (Subp_Id => Defining_Identifier (Decl),
2474 Formals => Parameter_Specifications (Decl));
2476 elsif Nkind (Decl) = N_Subprogram_Declaration then
2479 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2482 Parameter_Specifications (Specification (Decl)));
2485 if Present (Wrap_Spec) then
2487 Make_Subprogram_Declaration (Loc,
2488 Specification => Wrap_Spec);
2490 Insert_After (N, Wrap_Decl);
2493 Analyze (Wrap_Decl);
2498 end Scan_Declarations;
2500 -- start of processing for Build_Wrapper_Specs
2503 if Is_Protected_Type (Typ) then
2504 Def := Protected_Definition (Parent (Typ));
2505 else pragma Assert (Is_Task_Type (Typ));
2506 Def := Task_Definition (Parent (Typ));
2509 Rec_Typ := Corresponding_Record_Type (Typ);
2511 -- Generate wrapper specs for a concurrent type which implements an
2512 -- interface. Operations in both the visible and private parts may
2513 -- implement progenitor operations.
2515 if Present (Interfaces (Rec_Typ)) and then Present (Def) then
2516 Scan_Declarations (Visible_Declarations (Def));
2517 Scan_Declarations (Private_Declarations (Def));
2519 end Build_Wrapper_Specs;
2521 ---------------------------
2522 -- Build_Find_Body_Index --
2523 ---------------------------
2525 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2526 Loc : constant Source_Ptr := Sloc (Typ);
2529 Has_F : Boolean := False;
2531 If_St : Node_Id := Empty;
2534 Decls : List_Id := New_List;
2537 Siz : Node_Id := Empty;
2539 procedure Add_If_Clause (Expr : Node_Id);
2540 -- Add test for range of current entry
2542 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2543 -- If a bound of an entry is given by a discriminant, retrieve the
2544 -- actual value of the discriminant from the enclosing object.
2550 procedure Add_If_Clause (Expr : Node_Id) is
2552 Stats : constant List_Id :=
2554 Make_Simple_Return_Statement (Loc,
2555 Expression => Make_Integer_Literal (Loc, Index + 1)));
2558 -- Index for current entry body
2562 -- Compute total length of entry queues so far
2570 Right_Opnd => Expr);
2575 Left_Opnd => Make_Identifier (Loc, Name_uE),
2578 -- Map entry queue indexes in the range of the current family
2579 -- into the current index, that designates the entry body.
2583 Make_Implicit_If_Statement (Typ,
2585 Then_Statements => Stats,
2586 Elsif_Parts => New_List);
2590 Append_To (Elsif_Parts (If_St),
2591 Make_Elsif_Part (Loc,
2593 Then_Statements => Stats));
2597 ------------------------------
2598 -- Convert_Discriminant_Ref --
2599 ------------------------------
2601 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2605 if Is_Entity_Name (Bound)
2606 and then Ekind (Entity (Bound)) = E_Discriminant
2609 Make_Selected_Component (Loc,
2611 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2612 Make_Explicit_Dereference (Loc,
2613 Make_Identifier (Loc, Name_uObject))),
2614 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2615 Set_Etype (B, Etype (Entity (Bound)));
2617 B := New_Copy_Tree (Bound);
2621 end Convert_Discriminant_Ref;
2623 -- Start of processing for Build_Find_Body_Index
2626 Spec := Build_Find_Body_Index_Spec (Typ);
2628 Ent := First_Entity (Typ);
2629 while Present (Ent) loop
2630 if Ekind (Ent) = E_Entry_Family then
2640 -- If the protected type has no entry families, there is a one-one
2641 -- correspondence between entry queue and entry body.
2644 Make_Simple_Return_Statement (Loc,
2645 Expression => Make_Identifier (Loc, Name_uE));
2648 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2651 -- if E <= l1 then return 1;
2652 -- elsif E <= l1 + l2 then return 2;
2657 Ent := First_Entity (Typ);
2659 Add_Object_Pointer (Loc, Typ, Decls);
2661 while Present (Ent) loop
2662 if Ekind (Ent) = E_Entry then
2663 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2665 elsif Ekind (Ent) = E_Entry_Family then
2666 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2667 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2668 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2669 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2678 Make_Simple_Return_Statement (Loc,
2679 Expression => Make_Integer_Literal (Loc, 1));
2681 elsif Nkind (Ret) = N_If_Statement then
2683 -- Ranges are in increasing order, so last one doesn't need guard
2686 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2689 Set_Else_Statements (Ret, Then_Statements (Nod));
2695 Make_Subprogram_Body (Loc,
2696 Specification => Spec,
2697 Declarations => Decls,
2698 Handled_Statement_Sequence =>
2699 Make_Handled_Sequence_Of_Statements (Loc,
2700 Statements => New_List (Ret)));
2701 end Build_Find_Body_Index;
2703 --------------------------------
2704 -- Build_Find_Body_Index_Spec --
2705 --------------------------------
2707 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2708 Loc : constant Source_Ptr := Sloc (Typ);
2709 Id : constant Entity_Id :=
2710 Make_Defining_Identifier (Loc,
2711 Chars => New_External_Name (Chars (Typ), 'F'));
2712 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2713 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2717 Make_Function_Specification (Loc,
2718 Defining_Unit_Name => Id,
2719 Parameter_Specifications => New_List (
2720 Make_Parameter_Specification (Loc,
2721 Defining_Identifier => Parm1,
2723 New_Occurrence_Of (RTE (RE_Address), Loc)),
2725 Make_Parameter_Specification (Loc,
2726 Defining_Identifier => Parm2,
2728 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
2730 Result_Definition => New_Occurrence_Of (
2731 RTE (RE_Protected_Entry_Index), Loc));
2732 end Build_Find_Body_Index_Spec;
2734 -----------------------------------------------
2735 -- Build_Lock_Free_Protected_Subprogram_Body --
2736 -----------------------------------------------
2738 function Build_Lock_Free_Protected_Subprogram_Body
2741 Unprot_Spec : Node_Id) return Node_Id
2743 Actuals : constant List_Id := New_List;
2744 Loc : constant Source_Ptr := Sloc (N);
2745 Spec : constant Node_Id := Specification (N);
2746 Unprot_Id : constant Entity_Id := Defining_Unit_Name (Unprot_Spec);
2748 Prot_Spec : Node_Id;
2752 -- Create the protected version of the body
2755 Build_Protected_Sub_Specification (N, Prot_Typ, Protected_Mode);
2757 -- Build the actual parameters which appear in the call to the
2758 -- unprotected version of the body.
2760 Formal := First (Parameter_Specifications (Prot_Spec));
2761 while Present (Formal) loop
2763 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
2768 -- Function case, generate:
2769 -- return <Unprot_Func_Call>;
2771 if Nkind (Spec) = N_Function_Specification then
2773 Make_Simple_Return_Statement (Loc,
2775 Make_Function_Call (Loc,
2777 Make_Identifier (Loc, Chars (Unprot_Id)),
2778 Parameter_Associations => Actuals));
2780 -- Procedure case, call the unprotected version
2784 Make_Procedure_Call_Statement (Loc,
2786 Make_Identifier (Loc, Chars (Unprot_Id)),
2787 Parameter_Associations => Actuals);
2791 Make_Subprogram_Body (Loc,
2792 Declarations => Empty_List,
2793 Specification => Prot_Spec,
2794 Handled_Statement_Sequence =>
2795 Make_Handled_Sequence_Of_Statements (Loc,
2796 Statements => New_List (Stmt)));
2797 end Build_Lock_Free_Protected_Subprogram_Body;
2799 -------------------------------------------------
2800 -- Build_Lock_Free_Unprotected_Subprogram_Body --
2801 -------------------------------------------------
2803 -- Procedures which meet the lock-free implementation requirements and
2804 -- reference a unique scalar component Comp are expanded in the following
2807 -- procedure P (...) is
2808 -- Expected_Comp : constant Comp_Type :=
2810 -- (System.Atomic_Primitives.Lock_Free_Read_N
2811 -- (_Object.Comp'Address));
2815 -- <original declarations before the object renaming declaration
2818 -- Desired_Comp : Comp_Type := Expected_Comp;
2819 -- Comp : Comp_Type renames Desired_Comp;
2821 -- <original delarations after the object renaming declaration
2825 -- <original statements>
2826 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
2827 -- (_Object.Comp'Address,
2828 -- Interfaces.Unsigned_N (Expected_Comp),
2829 -- Interfaces.Unsigned_N (Desired_Comp));
2834 -- Each return and raise statement of P is transformed into an atomic
2837 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2838 -- (_Object.Comp'Address,
2839 -- Interfaces.Unsigned_N (Expected_Comp),
2840 -- Interfaces.Unsigned_N (Desired_Comp));
2842 -- <original statement>
2847 -- Functions which meet the lock-free implementation requirements and
2848 -- reference a unique scalar component Comp are expanded in the following
2851 -- function F (...) return ... is
2852 -- <original declarations before the object renaming declaration
2855 -- Expected_Comp : constant Comp_Type :=
2857 -- (System.Atomic_Primitives.Lock_Free_Read_N
2858 -- (_Object.Comp'Address));
2859 -- Comp : Comp_Type renames Expected_Comp;
2861 -- <original delarations after the object renaming declaration of
2865 -- <original statements>
2868 function Build_Lock_Free_Unprotected_Subprogram_Body
2870 Prot_Typ : Node_Id) return Node_Id
2872 function Referenced_Component (N : Node_Id) return Entity_Id;
2873 -- Subprograms which meet the lock-free implementation criteria are
2874 -- allowed to reference only one unique component. Return the prival
2875 -- of the said component.
2877 --------------------------
2878 -- Referenced_Component --
2879 --------------------------
2881 function Referenced_Component (N : Node_Id) return Entity_Id is
2884 Source_Comp : Entity_Id := Empty;
2887 -- Find the unique source component which N references in its
2890 for Index in 1 .. Lock_Free_Subprogram_Table.Last loop
2892 Element : Lock_Free_Subprogram renames
2893 Lock_Free_Subprogram_Table.Table (Index);
2895 if Element.Sub_Body = N then
2896 Source_Comp := Element.Comp_Id;
2902 if No (Source_Comp) then
2906 -- Find the prival which corresponds to the source component within
2907 -- the declarations of N.
2909 Decl := First (Declarations (N));
2910 while Present (Decl) loop
2912 -- Privals appear as object renamings
2914 if Nkind (Decl) = N_Object_Renaming_Declaration then
2915 Comp := Defining_Identifier (Decl);
2917 if Present (Prival_Link (Comp))
2918 and then Prival_Link (Comp) = Source_Comp
2928 end Referenced_Component;
2932 Comp : constant Entity_Id := Referenced_Component (N);
2933 Loc : constant Source_Ptr := Sloc (N);
2934 Hand_Stmt_Seq : Node_Id := Handled_Statement_Sequence (N);
2935 Decls : List_Id := Declarations (N);
2937 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
2940 -- Add renamings for the protection object, discriminals, privals, and
2941 -- the entry index constant for use by debugger.
2943 Debug_Private_Data_Declarations (Decls);
2945 -- Perform the lock-free expansion when the subprogram references a
2946 -- protected component.
2948 if Present (Comp) then
2949 Protected_Component_Ref : declare
2950 Comp_Decl : constant Node_Id := Parent (Comp);
2951 Comp_Sel_Nam : constant Node_Id := Name (Comp_Decl);
2952 Comp_Type : constant Entity_Id := Etype (Comp);
2954 Is_Procedure : constant Boolean :=
2955 Ekind (Corresponding_Spec (N)) = E_Procedure;
2956 -- Indicates if N is a protected procedure body
2958 Block_Decls : List_Id;
2959 Try_Write : Entity_Id;
2960 Desired_Comp : Entity_Id;
2963 Label_Id : Entity_Id := Empty;
2965 Expected_Comp : Entity_Id;
2968 New_Copy_List (Statements (Hand_Stmt_Seq));
2970 Unsigned : Entity_Id;
2972 function Process_Node (N : Node_Id) return Traverse_Result;
2973 -- Transform a single node if it is a return statement, a raise
2974 -- statement or a reference to Comp.
2976 procedure Process_Stmts (Stmts : List_Id);
2977 -- Given a statement sequence Stmts, wrap any return or raise
2978 -- statements in the following manner:
2980 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
2981 -- (_Object.Comp'Address,
2982 -- Interfaces.Unsigned_N (Expected_Comp),
2983 -- Interfaces.Unsigned_N (Desired_Comp))
2994 function Process_Node (N : Node_Id) return Traverse_Result is
2996 procedure Wrap_Statement (Stmt : Node_Id);
2997 -- Wrap an arbitrary statement inside an if statement where the
2998 -- condition does an atomic check on the state of the object.
3000 --------------------
3001 -- Wrap_Statement --
3002 --------------------
3004 procedure Wrap_Statement (Stmt : Node_Id) is
3006 -- The first time through, create the declaration of a label
3007 -- which is used to skip the remainder of source statements
3008 -- if the state of the object has changed.
3010 if No (Label_Id) then
3012 Make_Identifier (Loc, New_External_Name ('L', 0));
3013 Set_Entity (Label_Id,
3014 Make_Defining_Identifier (Loc, Chars (Label_Id)));
3018 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3019 -- (_Object.Comp'Address,
3020 -- Interfaces.Unsigned_N (Expected_Comp),
3021 -- Interfaces.Unsigned_N (Desired_Comp))
3029 Make_Implicit_If_Statement (N,
3031 Make_Function_Call (Loc,
3033 New_Occurrence_Of (Try_Write, Loc),
3034 Parameter_Associations => New_List (
3035 Make_Attribute_Reference (Loc,
3036 Prefix => Relocate_Node (Comp_Sel_Nam),
3037 Attribute_Name => Name_Address),
3039 Unchecked_Convert_To (Unsigned,
3040 New_Occurrence_Of (Expected_Comp, Loc)),
3042 Unchecked_Convert_To (Unsigned,
3043 New_Occurrence_Of (Desired_Comp, Loc)))),
3045 Then_Statements => New_List (Relocate_Node (Stmt)),
3047 Else_Statements => New_List (
3048 Make_Goto_Statement (Loc,
3050 New_Occurrence_Of (Entity (Label_Id), Loc)))));
3053 -- Start of processing for Process_Node
3056 -- Wrap each return and raise statement that appear inside a
3057 -- procedure. Skip the last return statement which is added by
3058 -- default since it is transformed into an exit statement.
3061 and then ((Nkind (N) = N_Simple_Return_Statement
3062 and then N /= Last (Stmts))
3063 or else Nkind (N) = N_Extended_Return_Statement
3064 or else (Nkind_In (N, N_Raise_Constraint_Error,
3065 N_Raise_Program_Error,
3067 N_Raise_Storage_Error)
3068 and then Comes_From_Source (N)))
3076 Set_Analyzed (N, False);
3081 procedure Process_Nodes is new Traverse_Proc (Process_Node);
3087 procedure Process_Stmts (Stmts : List_Id) is
3090 Stmt := First (Stmts);
3091 while Present (Stmt) loop
3092 Process_Nodes (Stmt);
3097 -- Start of processing for Protected_Component_Ref
3100 -- Get the type size
3102 if Known_Static_Esize (Comp_Type) then
3103 Typ_Size := UI_To_Int (Esize (Comp_Type));
3105 -- If the Esize (Object_Size) is unknown at compile time, look at
3106 -- the RM_Size (Value_Size) since it may have been set by an
3107 -- explicit representation clause.
3109 elsif Known_Static_RM_Size (Comp_Type) then
3110 Typ_Size := UI_To_Int (RM_Size (Comp_Type));
3112 -- Should not happen since this has already been checked in
3113 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3116 raise Program_Error;
3119 -- Retrieve all relevant atomic routines and types
3123 Try_Write := RTE (RE_Lock_Free_Try_Write_8);
3124 Read := RTE (RE_Lock_Free_Read_8);
3125 Unsigned := RTE (RE_Uint8);
3128 Try_Write := RTE (RE_Lock_Free_Try_Write_16);
3129 Read := RTE (RE_Lock_Free_Read_16);
3130 Unsigned := RTE (RE_Uint16);
3133 Try_Write := RTE (RE_Lock_Free_Try_Write_32);
3134 Read := RTE (RE_Lock_Free_Read_32);
3135 Unsigned := RTE (RE_Uint32);
3138 Try_Write := RTE (RE_Lock_Free_Try_Write_64);
3139 Read := RTE (RE_Lock_Free_Read_64);
3140 Unsigned := RTE (RE_Uint64);
3143 raise Program_Error;
3147 -- Expected_Comp : constant Comp_Type :=
3149 -- (System.Atomic_Primitives.Lock_Free_Read_N
3150 -- (_Object.Comp'Address));
3153 Make_Defining_Identifier (Loc,
3154 New_External_Name (Chars (Comp), Suffix => "_saved"));
3157 Make_Object_Declaration (Loc,
3158 Defining_Identifier => Expected_Comp,
3159 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3160 Constant_Present => True,
3162 Unchecked_Convert_To (Comp_Type,
3163 Make_Function_Call (Loc,
3164 Name => New_Occurrence_Of (Read, Loc),
3165 Parameter_Associations => New_List (
3166 Make_Attribute_Reference (Loc,
3167 Prefix => Relocate_Node (Comp_Sel_Nam),
3168 Attribute_Name => Name_Address)))));
3170 -- Protected procedures
3172 if Is_Procedure then
3173 -- Move the original declarations inside the generated block
3175 Block_Decls := Decls;
3177 -- Reset the declarations list of the protected procedure to
3178 -- contain only Decl.
3180 Decls := New_List (Decl);
3183 -- Desired_Comp : Comp_Type := Expected_Comp;
3186 Make_Defining_Identifier (Loc,
3187 New_External_Name (Chars (Comp), Suffix => "_current"));
3189 -- Insert the declarations of Expected_Comp and Desired_Comp in
3190 -- the block declarations right before the renaming of the
3191 -- protected component.
3193 Insert_Before (Comp_Decl,
3194 Make_Object_Declaration (Loc,
3195 Defining_Identifier => Desired_Comp,
3196 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3198 New_Occurrence_Of (Expected_Comp, Loc)));
3200 -- Protected function
3203 Desired_Comp := Expected_Comp;
3205 -- Insert the declaration of Expected_Comp in the function
3206 -- declarations right before the renaming of the protected
3209 Insert_Before (Comp_Decl, Decl);
3212 -- Rewrite the protected component renaming declaration to be a
3213 -- renaming of Desired_Comp.
3216 -- Comp : Comp_Type renames Desired_Comp;
3219 Make_Object_Renaming_Declaration (Loc,
3220 Defining_Identifier =>
3221 Defining_Identifier (Comp_Decl),
3223 New_Occurrence_Of (Comp_Type, Loc),
3225 New_Occurrence_Of (Desired_Comp, Loc)));
3227 -- Wrap any return or raise statements in Stmts in same the manner
3228 -- described in Process_Stmts.
3230 Process_Stmts (Stmts);
3233 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3234 -- (_Object.Comp'Address,
3235 -- Interfaces.Unsigned_N (Expected_Comp),
3236 -- Interfaces.Unsigned_N (Desired_Comp))
3238 if Is_Procedure then
3240 Make_Exit_Statement (Loc,
3242 Make_Function_Call (Loc,
3244 New_Occurrence_Of (Try_Write, Loc),
3245 Parameter_Associations => New_List (
3246 Make_Attribute_Reference (Loc,
3247 Prefix => Relocate_Node (Comp_Sel_Nam),
3248 Attribute_Name => Name_Address),
3250 Unchecked_Convert_To (Unsigned,
3251 New_Occurrence_Of (Expected_Comp, Loc)),
3253 Unchecked_Convert_To (Unsigned,
3254 New_Occurrence_Of (Desired_Comp, Loc)))));
3256 -- Small optimization: transform the default return statement
3257 -- of a procedure into the atomic exit statement.
3259 if Nkind (Last (Stmts)) = N_Simple_Return_Statement then
3260 Rewrite (Last (Stmts), Stmt);
3262 Append_To (Stmts, Stmt);
3266 -- Create the declaration of the label used to skip the rest of
3267 -- the source statements when the object state changes.
3269 if Present (Label_Id) then
3270 Label := Make_Label (Loc, Label_Id);
3272 Make_Implicit_Label_Declaration (Loc,
3273 Defining_Identifier => Entity (Label_Id),
3274 Label_Construct => Label));
3275 Append_To (Stmts, Label);
3287 if Is_Procedure then
3290 Make_Loop_Statement (Loc,
3291 Statements => New_List (
3292 Make_Block_Statement (Loc,
3293 Declarations => Block_Decls,
3294 Handled_Statement_Sequence =>
3295 Make_Handled_Sequence_Of_Statements (Loc,
3296 Statements => Stmts))),
3297 End_Label => Empty));
3301 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts);
3302 end Protected_Component_Ref;
3305 -- Make an unprotected version of the subprogram for use within the same
3306 -- object, with new name and extra parameter representing the object.
3309 Make_Subprogram_Body (Loc,
3311 Build_Protected_Sub_Specification (N, Prot_Typ, Unprotected_Mode),
3312 Declarations => Decls,
3313 Handled_Statement_Sequence => Hand_Stmt_Seq);
3314 end Build_Lock_Free_Unprotected_Subprogram_Body;
3316 -------------------------
3317 -- Build_Master_Entity --
3318 -------------------------
3320 procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
3321 Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
3323 Context_Id : Entity_Id;
3329 if Is_Itype (Obj_Or_Typ) then
3330 Par := Associated_Node_For_Itype (Obj_Or_Typ);
3332 Par := Parent (Obj_Or_Typ);
3335 -- When creating a master for a record component which is either a task
3336 -- or access-to-task, the enclosing record is the master scope and the
3337 -- proper insertion point is the component list.
3339 if Is_Record_Type (Current_Scope) then
3341 Context_Id := Current_Scope;
3342 Decls := List_Containing (Context);
3344 -- Default case for object declarations and access types. Note that the
3345 -- context is updated to the nearest enclosing body, block, package, or
3346 -- return statement.
3349 Find_Enclosing_Context (Par, Context, Context_Id, Decls);
3352 -- Nothing to do if the context already has a master
3354 if Has_Master_Entity (Context_Id) then
3357 -- Nothing to do if tasks or tasking hierarchies are prohibited
3359 elsif Restriction_Active (No_Tasking)
3360 or else Restriction_Active (No_Task_Hierarchy)
3365 -- Create a master, generate:
3366 -- _Master : constant Master_Id := Current_Master.all;
3369 Make_Object_Declaration (Loc,
3370 Defining_Identifier =>
3371 Make_Defining_Identifier (Loc, Name_uMaster),
3372 Constant_Present => True,
3373 Object_Definition => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3375 Make_Explicit_Dereference (Loc,
3376 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
3378 -- The master is inserted at the start of the declarative list of the
3381 Prepend_To (Decls, Decl);
3383 -- In certain cases where transient scopes are involved, the immediate
3384 -- scope is not always the proper master scope. Ensure that the master
3385 -- declaration and entity appear in the same context.
3387 if Context_Id /= Current_Scope then
3388 Push_Scope (Context_Id);
3395 -- Mark the enclosing scope and its associated construct as being task
3398 Set_Has_Master_Entity (Context_Id);
3400 while Present (Context)
3401 and then Nkind (Context) /= N_Compilation_Unit
3403 if Nkind_In (Context, N_Block_Statement,
3407 Set_Is_Task_Master (Context);
3410 elsif Nkind (Parent (Context)) = N_Subunit then
3411 Context := Corresponding_Stub (Parent (Context));
3414 Context := Parent (Context);
3416 end Build_Master_Entity;
3418 ---------------------------
3419 -- Build_Master_Renaming --
3420 ---------------------------
3422 procedure Build_Master_Renaming
3423 (Ptr_Typ : Entity_Id;
3424 Ins_Nod : Node_Id := Empty)
3426 Loc : constant Source_Ptr := Sloc (Ptr_Typ);
3428 Master_Decl : Node_Id;
3429 Master_Id : Entity_Id;
3432 -- Nothing to do if tasks or tasking hierarchies are prohibited
3434 if Restriction_Active (No_Tasking)
3435 or else Restriction_Active (No_Task_Hierarchy)
3440 -- Determine the proper context to insert the master renaming
3442 if Present (Ins_Nod) then
3444 elsif Is_Itype (Ptr_Typ) then
3445 Context := Associated_Node_For_Itype (Ptr_Typ);
3447 Context := Parent (Ptr_Typ);
3451 -- <Ptr_Typ>M : Master_Id renames _Master;
3454 Make_Defining_Identifier (Loc,
3455 New_External_Name (Chars (Ptr_Typ), 'M'));
3458 Make_Object_Renaming_Declaration (Loc,
3459 Defining_Identifier => Master_Id,
3460 Subtype_Mark => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3461 Name => Make_Identifier (Loc, Name_uMaster));
3463 Insert_Action (Context, Master_Decl);
3465 -- The renamed master now services the access type
3467 Set_Master_Id (Ptr_Typ, Master_Id);
3468 end Build_Master_Renaming;
3470 -----------------------------------------
3471 -- Build_Private_Protected_Declaration --
3472 -----------------------------------------
3474 function Build_Private_Protected_Declaration
3475 (N : Node_Id) return Entity_Id
3477 Loc : constant Source_Ptr := Sloc (N);
3478 Body_Id : constant Entity_Id := Defining_Entity (N);
3483 Spec_Id : Entity_Id;
3486 Formal := First_Formal (Body_Id);
3488 -- The protected operation always has at least one formal, namely the
3489 -- object itself, but it is only placed in the parameter list if
3490 -- expansion is enabled.
3492 if Present (Formal) or else Expander_Active then
3493 Plist := Copy_Parameter_List (Body_Id);
3498 if Nkind (Specification (N)) = N_Procedure_Specification then
3500 Make_Procedure_Specification (Loc,
3501 Defining_Unit_Name =>
3502 Make_Defining_Identifier (Sloc (Body_Id),
3503 Chars => Chars (Body_Id)),
3504 Parameter_Specifications =>
3508 Make_Function_Specification (Loc,
3509 Defining_Unit_Name =>
3510 Make_Defining_Identifier (Sloc (Body_Id),
3511 Chars => Chars (Body_Id)),
3512 Parameter_Specifications => Plist,
3513 Result_Definition =>
3514 New_Occurrence_Of (Etype (Body_Id), Loc));
3517 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
3518 Insert_Before (N, Decl);
3519 Spec_Id := Defining_Unit_Name (New_Spec);
3521 -- Indicate that the entity comes from source, to ensure that cross-
3522 -- reference information is properly generated. The body itself is
3523 -- rewritten during expansion, and the body entity will not appear in
3524 -- calls to the operation.
3526 Set_Comes_From_Source (Spec_Id, True);
3528 Set_Has_Completion (Spec_Id);
3529 Set_Convention (Spec_Id, Convention_Protected);
3531 end Build_Private_Protected_Declaration;
3533 ---------------------------
3534 -- Build_Protected_Entry --
3535 ---------------------------
3537 function Build_Protected_Entry
3540 Pid : Node_Id) return Node_Id
3542 Bod_Decls : constant List_Id := New_List;
3543 Decls : constant List_Id := Declarations (N);
3544 End_Lab : constant Node_Id :=
3545 End_Label (Handled_Statement_Sequence (N));
3546 End_Loc : constant Source_Ptr :=
3547 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
3548 -- Used for the generated call to Complete_Entry_Body
3550 Loc : constant Source_Ptr := Sloc (N);
3554 Bod_Stmts : List_Id;
3558 EH_Loc : Source_Ptr;
3559 -- Used for the exception handler, inserted at end of the body
3562 -- Set the source location on the exception handler only when debugging
3563 -- the expanded code (see Make_Implicit_Exception_Handler).
3565 if Debug_Generated_Code then
3568 -- Otherwise the inserted code should not be visible to the debugger
3571 EH_Loc := No_Location;
3575 Make_Defining_Identifier (Loc,
3576 Chars => Chars (Protected_Body_Subprogram (Ent)));
3577 Bod_Spec := Build_Protected_Entry_Specification (Loc, Bod_Id, Empty);
3579 -- Add the following declarations:
3581 -- type poVP is access poV;
3582 -- _object : poVP := poVP (_O);
3584 -- where _O is the formal parameter associated with the concurrent
3585 -- object. These declarations are needed for Complete_Entry_Body.
3587 Add_Object_Pointer (Loc, Pid, Bod_Decls);
3589 -- Add renamings for all formals, the Protection object, discriminals,
3590 -- privals and the entry index constant for use by debugger.
3592 Add_Formal_Renamings (Bod_Spec, Bod_Decls, Ent, Loc);
3593 Debug_Private_Data_Declarations (Decls);
3595 -- Put the declarations and the statements from the entry
3599 Make_Block_Statement (Loc,
3600 Declarations => Decls,
3601 Handled_Statement_Sequence => Handled_Statement_Sequence (N)));
3603 case Corresponding_Runtime_Package (Pid) is
3604 when System_Tasking_Protected_Objects_Entries =>
3605 Append_To (Bod_Stmts,
3606 Make_Procedure_Call_Statement (End_Loc,
3608 New_Occurrence_Of (RTE (RE_Complete_Entry_Body), Loc),
3609 Parameter_Associations => New_List (
3610 Make_Attribute_Reference (End_Loc,
3612 Make_Selected_Component (End_Loc,
3614 Make_Identifier (End_Loc, Name_uObject),
3616 Make_Identifier (End_Loc, Name_uObject)),
3617 Attribute_Name => Name_Unchecked_Access))));
3619 when System_Tasking_Protected_Objects_Single_Entry =>
3621 -- Historically, a call to Complete_Single_Entry_Body was
3622 -- inserted, but it was a null procedure.
3627 raise Program_Error;
3630 -- When exceptions can not be propagated, we never need to call
3631 -- Exception_Complete_Entry_Body.
3633 if No_Exception_Handlers_Set then
3635 Make_Subprogram_Body (Loc,
3636 Specification => Bod_Spec,
3637 Declarations => Bod_Decls,
3638 Handled_Statement_Sequence =>
3639 Make_Handled_Sequence_Of_Statements (Loc,
3640 Statements => Bod_Stmts,
3641 End_Label => End_Lab));
3644 Ohandle := Make_Others_Choice (Loc);
3645 Set_All_Others (Ohandle);
3647 case Corresponding_Runtime_Package (Pid) is
3648 when System_Tasking_Protected_Objects_Entries =>
3651 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
3653 when System_Tasking_Protected_Objects_Single_Entry =>
3656 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
3659 raise Program_Error;
3662 -- Establish link between subprogram body entity and source entry
3664 Set_Corresponding_Protected_Entry (Bod_Id, Ent);
3666 -- Create body of entry procedure. The renaming declarations are
3667 -- placed ahead of the block that contains the actual entry body.
3670 Make_Subprogram_Body (Loc,
3671 Specification => Bod_Spec,
3672 Declarations => Bod_Decls,
3673 Handled_Statement_Sequence =>
3674 Make_Handled_Sequence_Of_Statements (Loc,
3675 Statements => Bod_Stmts,
3676 End_Label => End_Lab,
3677 Exception_Handlers => New_List (
3678 Make_Implicit_Exception_Handler (EH_Loc,
3679 Exception_Choices => New_List (Ohandle),
3681 Statements => New_List (
3682 Make_Procedure_Call_Statement (EH_Loc,
3684 Parameter_Associations => New_List (
3685 Make_Attribute_Reference (EH_Loc,
3687 Make_Selected_Component (EH_Loc,
3689 Make_Identifier (EH_Loc, Name_uObject),
3691 Make_Identifier (EH_Loc, Name_uObject)),
3692 Attribute_Name => Name_Unchecked_Access),
3694 Make_Function_Call (EH_Loc,
3697 (RTE (RE_Get_GNAT_Exception), Loc)))))))));
3699 end Build_Protected_Entry;
3701 -----------------------------------------
3702 -- Build_Protected_Entry_Specification --
3703 -----------------------------------------
3705 function Build_Protected_Entry_Specification
3708 Ent_Id : Entity_Id) return Node_Id
3710 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3713 Set_Debug_Info_Needed (Def_Id);
3715 if Present (Ent_Id) then
3716 Append_Elmt (P, Accept_Address (Ent_Id));
3720 Make_Procedure_Specification (Loc,
3721 Defining_Unit_Name => Def_Id,
3722 Parameter_Specifications => New_List (
3723 Make_Parameter_Specification (Loc,
3724 Defining_Identifier =>
3725 Make_Defining_Identifier (Loc, Name_uO),
3727 New_Occurrence_Of (RTE (RE_Address), Loc)),
3729 Make_Parameter_Specification (Loc,
3730 Defining_Identifier => P,
3732 New_Occurrence_Of (RTE (RE_Address), Loc)),
3734 Make_Parameter_Specification (Loc,
3735 Defining_Identifier =>
3736 Make_Defining_Identifier (Loc, Name_uE),
3738 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))));
3739 end Build_Protected_Entry_Specification;
3741 --------------------------
3742 -- Build_Protected_Spec --
3743 --------------------------
3745 function Build_Protected_Spec
3747 Obj_Type : Entity_Id;
3749 Unprotected : Boolean := False) return List_Id
3751 Loc : constant Source_Ptr := Sloc (N);
3754 New_Plist : List_Id;
3755 New_Param : Node_Id;
3758 New_Plist := New_List;
3760 Formal := First_Formal (Ident);
3761 while Present (Formal) loop
3763 Make_Parameter_Specification (Loc,
3764 Defining_Identifier =>
3765 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
3766 Aliased_Present => Aliased_Present (Parent (Formal)),
3767 In_Present => In_Present (Parent (Formal)),
3768 Out_Present => Out_Present (Parent (Formal)),
3769 Parameter_Type => New_Occurrence_Of (Etype (Formal), Loc));
3772 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
3775 Append (New_Param, New_Plist);
3776 Next_Formal (Formal);
3779 -- If the subprogram is a procedure and the context is not an access
3780 -- to protected subprogram, the parameter is in-out. Otherwise it is
3784 Make_Parameter_Specification (Loc,
3785 Defining_Identifier =>
3786 Make_Defining_Identifier (Loc, Name_uObject),
3789 (Etype (Ident) = Standard_Void_Type
3790 and then not Is_RTE (Obj_Type, RE_Address)),
3792 New_Occurrence_Of (Obj_Type, Loc));
3793 Set_Debug_Info_Needed (Defining_Identifier (Decl));
3794 Prepend_To (New_Plist, Decl);
3797 end Build_Protected_Spec;
3799 ---------------------------------------
3800 -- Build_Protected_Sub_Specification --
3801 ---------------------------------------
3803 function Build_Protected_Sub_Specification
3805 Prot_Typ : Entity_Id;
3806 Mode : Subprogram_Protection_Mode) return Node_Id
3808 Loc : constant Source_Ptr := Sloc (N);
3812 New_Plist : List_Id;
3815 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
3816 (Dispatching_Mode => ' ',
3817 Protected_Mode => 'P',
3818 Unprotected_Mode => 'N');
3821 if Ekind (Defining_Unit_Name (Specification (N))) = E_Subprogram_Body
3823 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
3828 Def_Id := Defining_Unit_Name (Specification (Decl));
3831 Build_Protected_Spec
3832 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
3833 Mode = Unprotected_Mode);
3835 Make_Defining_Identifier (Loc,
3836 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
3838 -- Reference the original nondispatching subprogram since the analysis
3839 -- of the object.operation notation may need its original name (see
3840 -- Sem_Ch4.Names_Match).
3842 if Mode = Dispatching_Mode then
3843 Set_Ekind (New_Id, Ekind (Def_Id));
3844 Set_Original_Protected_Subprogram (New_Id, Def_Id);
3847 -- The unprotected operation carries the user code, and debugging
3848 -- information must be generated for it, even though this spec does
3849 -- not come from source. It is also convenient to allow gdb to step
3850 -- into the protected operation, even though it only contains lock/
3853 Set_Debug_Info_Needed (New_Id);
3855 -- If a pragma Eliminate applies to the source entity, the internal
3856 -- subprograms will be eliminated as well.
3858 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
3860 if Nkind (Specification (Decl)) = N_Procedure_Specification then
3862 Make_Procedure_Specification (Loc,
3863 Defining_Unit_Name => New_Id,
3864 Parameter_Specifications => New_Plist);
3866 -- Create a new specification for the anonymous subprogram type
3870 Make_Function_Specification (Loc,
3871 Defining_Unit_Name => New_Id,
3872 Parameter_Specifications => New_Plist,
3873 Result_Definition =>
3874 Copy_Result_Type (Result_Definition (Specification (Decl))));
3876 Set_Return_Present (Defining_Unit_Name (New_Spec));
3880 end Build_Protected_Sub_Specification;
3882 -------------------------------------
3883 -- Build_Protected_Subprogram_Body --
3884 -------------------------------------
3886 function Build_Protected_Subprogram_Body
3889 N_Op_Spec : Node_Id) return Node_Id
3891 Loc : constant Source_Ptr := Sloc (N);
3893 P_Op_Spec : Node_Id;
3896 Unprot_Call : Node_Id;
3898 Lock_Name : Node_Id;
3899 Lock_Stmt : Node_Id;
3901 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
3902 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
3904 Object_Parm : Node_Id;
3909 Op_Spec := Specification (N);
3910 Exc_Safe := Is_Exception_Safe (N);
3913 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
3915 -- Build a list of the formal parameters of the protected version of
3916 -- the subprogram to use as the actual parameters of the unprotected
3919 Uactuals := New_List;
3920 Pformal := First (Parameter_Specifications (P_Op_Spec));
3921 while Present (Pformal) loop
3922 Append_To (Uactuals,
3923 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
3927 -- Make a call to the unprotected version of the subprogram built above
3928 -- for use by the protected version built below.
3930 if Nkind (Op_Spec) = N_Function_Specification then
3932 R := Make_Temporary (Loc, 'R');
3935 Make_Object_Declaration (Loc,
3936 Defining_Identifier => R,
3937 Constant_Present => True,
3938 Object_Definition =>
3939 New_Copy (Result_Definition (N_Op_Spec)),
3941 Make_Function_Call (Loc,
3943 Make_Identifier (Loc,
3944 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3945 Parameter_Associations => Uactuals));
3948 Make_Simple_Return_Statement (Loc,
3949 Expression => New_Occurrence_Of (R, Loc));
3953 Make_Simple_Return_Statement (Loc,
3955 Make_Function_Call (Loc,
3957 Make_Identifier (Loc,
3958 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
3959 Parameter_Associations => Uactuals));
3962 Lock_Kind := RE_Lock_Read_Only;
3966 Make_Procedure_Call_Statement (Loc,
3968 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
3969 Parameter_Associations => Uactuals);
3971 Lock_Kind := RE_Lock;
3974 -- Wrap call in block that will be covered by an at_end handler
3976 if not Exc_Safe then
3978 Make_Block_Statement (Loc,
3979 Handled_Statement_Sequence =>
3980 Make_Handled_Sequence_Of_Statements (Loc,
3981 Statements => New_List (Unprot_Call)));
3984 -- Make the protected subprogram body. This locks the protected
3985 -- object and calls the unprotected version of the subprogram.
3987 case Corresponding_Runtime_Package (Pid) is
3988 when System_Tasking_Protected_Objects_Entries =>
3989 Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entries), Loc);
3991 when System_Tasking_Protected_Objects_Single_Entry =>
3992 Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entry), Loc);
3994 when System_Tasking_Protected_Objects =>
3995 Lock_Name := New_Occurrence_Of (RTE (Lock_Kind), Loc);
3998 raise Program_Error;
4002 Make_Attribute_Reference (Loc,
4004 Make_Selected_Component (Loc,
4005 Prefix => Make_Identifier (Loc, Name_uObject),
4006 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4007 Attribute_Name => Name_Unchecked_Access);
4010 Make_Procedure_Call_Statement (Loc,
4012 Parameter_Associations => New_List (Object_Parm));
4014 if Abort_Allowed then
4016 Build_Runtime_Call (Loc, RE_Abort_Defer),
4020 Stmts := New_List (Lock_Stmt);
4023 if not Exc_Safe then
4024 Append (Unprot_Call, Stmts);
4026 if Nkind (Op_Spec) = N_Function_Specification then
4028 Stmts := Empty_List;
4030 Append (Unprot_Call, Stmts);
4033 -- Historical note: Previously, call to the cleanup was inserted
4034 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4035 -- which is also shared by the 'not Exc_Safe' path.
4037 Build_Protected_Subprogram_Call_Cleanup (Op_Spec, Pid, Loc, Stmts);
4039 if Nkind (Op_Spec) = N_Function_Specification then
4040 Append_To (Stmts, Return_Stmt);
4041 Append_To (Pre_Stmts,
4042 Make_Block_Statement (Loc,
4043 Declarations => New_List (Unprot_Call),
4044 Handled_Statement_Sequence =>
4045 Make_Handled_Sequence_Of_Statements (Loc,
4046 Statements => Stmts)));
4052 Make_Subprogram_Body (Loc,
4053 Declarations => Empty_List,
4054 Specification => P_Op_Spec,
4055 Handled_Statement_Sequence =>
4056 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
4058 -- Mark this subprogram as a protected subprogram body so that the
4059 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4060 -- path as otherwise the cleanup has already been inserted.
4062 if not Exc_Safe then
4063 Set_Is_Protected_Subprogram_Body (Sub_Body);
4067 end Build_Protected_Subprogram_Body;
4069 -------------------------------------
4070 -- Build_Protected_Subprogram_Call --
4071 -------------------------------------
4073 procedure Build_Protected_Subprogram_Call
4077 External : Boolean := True)
4079 Loc : constant Source_Ptr := Sloc (N);
4080 Sub : constant Entity_Id := Entity (Name);
4086 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
4089 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
4092 if Present (Parameter_Associations (N)) then
4093 Params := New_Copy_List_Tree (Parameter_Associations (N));
4098 -- If the type is an untagged derived type, convert to the root type,
4099 -- which is the one on which the operations are defined.
4101 if Nkind (Rec) = N_Unchecked_Type_Conversion
4102 and then not Is_Tagged_Type (Etype (Rec))
4103 and then Is_Derived_Type (Etype (Rec))
4105 Set_Etype (Rec, Root_Type (Etype (Rec)));
4106 Set_Subtype_Mark (Rec,
4107 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
4110 Prepend (Rec, Params);
4112 if Ekind (Sub) = E_Procedure then
4114 Make_Procedure_Call_Statement (Loc,
4116 Parameter_Associations => Params));
4119 pragma Assert (Ekind (Sub) = E_Function);
4121 Make_Function_Call (Loc,
4123 Parameter_Associations => Params));
4125 -- Preserve type of call for subsequent processing (required for
4126 -- call to Wrap_Transient_Expression in the case of a shared passive
4129 Set_Etype (N, Etype (New_Sub));
4133 and then Nkind (Rec) = N_Unchecked_Type_Conversion
4134 and then Is_Entity_Name (Expression (Rec))
4135 and then Is_Shared_Passive (Entity (Expression (Rec)))
4137 Add_Shared_Var_Lock_Procs (N);
4139 end Build_Protected_Subprogram_Call;
4141 ---------------------------------------------
4142 -- Build_Protected_Subprogram_Call_Cleanup --
4143 ---------------------------------------------
4145 procedure Build_Protected_Subprogram_Call_Cleanup
4154 -- If the associated protected object has entries, a protected
4155 -- procedure has to service entry queues. In this case generate:
4157 -- Service_Entries (_object._object'Access);
4159 if Nkind (Op_Spec) = N_Procedure_Specification
4160 and then Has_Entries (Conc_Typ)
4162 case Corresponding_Runtime_Package (Conc_Typ) is
4163 when System_Tasking_Protected_Objects_Entries =>
4164 Nam := New_Occurrence_Of (RTE (RE_Service_Entries), Loc);
4166 when System_Tasking_Protected_Objects_Single_Entry =>
4167 Nam := New_Occurrence_Of (RTE (RE_Service_Entry), Loc);
4170 raise Program_Error;
4174 Make_Procedure_Call_Statement (Loc,
4176 Parameter_Associations => New_List (
4177 Make_Attribute_Reference (Loc,
4179 Make_Selected_Component (Loc,
4180 Prefix => Make_Identifier (Loc, Name_uObject),
4181 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4182 Attribute_Name => Name_Unchecked_Access))));
4186 -- Unlock (_object._object'Access);
4188 case Corresponding_Runtime_Package (Conc_Typ) is
4189 when System_Tasking_Protected_Objects_Entries =>
4190 Nam := New_Occurrence_Of (RTE (RE_Unlock_Entries), Loc);
4192 when System_Tasking_Protected_Objects_Single_Entry =>
4193 Nam := New_Occurrence_Of (RTE (RE_Unlock_Entry), Loc);
4195 when System_Tasking_Protected_Objects =>
4196 Nam := New_Occurrence_Of (RTE (RE_Unlock), Loc);
4199 raise Program_Error;
4203 Make_Procedure_Call_Statement (Loc,
4205 Parameter_Associations => New_List (
4206 Make_Attribute_Reference (Loc,
4208 Make_Selected_Component (Loc,
4209 Prefix => Make_Identifier (Loc, Name_uObject),
4210 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4211 Attribute_Name => Name_Unchecked_Access))));
4217 if Abort_Allowed then
4218 Append_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
4220 end Build_Protected_Subprogram_Call_Cleanup;
4222 -------------------------
4223 -- Build_Selected_Name --
4224 -------------------------
4226 function Build_Selected_Name
4227 (Prefix : Entity_Id;
4228 Selector : Entity_Id;
4229 Append_Char : Character := ' ') return Name_Id
4231 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
4232 Select_Len : Natural;
4235 Get_Name_String (Chars (Selector));
4236 Select_Len := Name_Len;
4237 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
4238 Get_Name_String (Chars (Prefix));
4240 -- If scope is anonymous type, discard suffix to recover name of
4241 -- single protected object. Otherwise use protected type name.
4243 if Name_Buffer (Name_Len) = 'T' then
4244 Name_Len := Name_Len - 1;
4247 Add_Str_To_Name_Buffer ("__");
4248 for J in 1 .. Select_Len loop
4249 Add_Char_To_Name_Buffer (Select_Buffer (J));
4252 -- Now add the Append_Char if specified. The encoding to follow
4253 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4254 -- then the entity is associated to a protected type subprogram.
4255 -- Otherwise, it is a protected type entry. For each case, the
4256 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4258 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4260 if Append_Char /= ' ' then
4261 if Append_Char = 'P' or Append_Char = 'N' then
4262 Add_Char_To_Name_Buffer (Append_Char);
4265 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
4266 return New_External_Name (Name_Find, ' ', -1);
4271 end Build_Selected_Name;
4273 -----------------------------
4274 -- Build_Simple_Entry_Call --
4275 -----------------------------
4277 -- A task entry call is converted to a call to Call_Simple
4280 -- P : parms := (parm, parm, parm);
4282 -- Call_Simple (acceptor-task, entry-index, P'Address);
4288 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4289 -- the parameters, and the constructed aggregate value contains either the
4290 -- parameters or, in the case of non-elementary types, references to these
4291 -- parameters. Then the address of this aggregate is passed to the runtime
4292 -- routine, along with the task id value and the task entry index value.
4293 -- Pnn is only required if parameters are present.
4295 -- The assignments after the call are present only in the case of in-out
4296 -- or out parameters for elementary types, and are used to assign back the
4297 -- resulting values of such parameters.
4299 -- Note: the reason that we insert a block here is that in the context
4300 -- of selects, conditional entry calls etc. the entry call statement
4301 -- appears on its own, not as an element of a list.
4303 -- A protected entry call is converted to a Protected_Entry_Call:
4306 -- P : E1_Params := (param, param, param);
4308 -- Bnn : Communications_Block;
4311 -- P : E1_Params := (param, param, param);
4312 -- Bnn : Communications_Block;
4315 -- Protected_Entry_Call (
4316 -- Object => po._object'Access,
4317 -- E => <entry index>;
4318 -- Uninterpreted_Data => P'Address;
4319 -- Mode => Simple_Call;
4326 procedure Build_Simple_Entry_Call
4335 -- If call has been inlined, nothing left to do
4337 if Nkind (N) = N_Block_Statement then
4341 -- Convert entry call to Call_Simple call
4344 Loc : constant Source_Ptr := Sloc (N);
4345 Parms : constant List_Id := Parameter_Associations (N);
4346 Stats : constant List_Id := New_List;
4349 Comm_Name : Entity_Id;
4353 Ent_Acc : Entity_Id;
4355 Iface_Tag : Entity_Id;
4356 Iface_Typ : Entity_Id;
4369 -- Simple entry and entry family cases merge here
4371 Ent := Entity (Ename);
4372 Ent_Acc := Entry_Parameters_Type (Ent);
4373 Conctyp := Etype (Concval);
4375 -- If prefix is an access type, dereference to obtain the task type
4377 if Is_Access_Type (Conctyp) then
4378 Conctyp := Designated_Type (Conctyp);
4381 -- Special case for protected subprogram calls
4383 if Is_Protected_Type (Conctyp)
4384 and then Is_Subprogram (Entity (Ename))
4386 if not Is_Eliminated (Entity (Ename)) then
4387 Build_Protected_Subprogram_Call
4388 (N, Ename, Convert_Concurrent (Concval, Conctyp));
4395 -- First parameter is the Task_Id value from the task value or the
4396 -- Object from the protected object value, obtained by selecting
4397 -- the _Task_Id or _Object from the result of doing an unchecked
4398 -- conversion to convert the value to the corresponding record type.
4400 if Nkind (Concval) = N_Function_Call
4401 and then Is_Task_Type (Conctyp)
4402 and then Ada_Version >= Ada_2005
4405 ExpR : constant Node_Id := Relocate_Node (Concval);
4406 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
4411 Make_Object_Declaration (Loc,
4412 Defining_Identifier => Obj,
4413 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
4414 Expression => ExpR);
4415 Set_Etype (Obj, Conctyp);
4416 Decls := New_List (Decl);
4417 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
4424 Parm1 := Concurrent_Ref (Concval);
4426 -- Second parameter is the entry index, computed by the routine
4427 -- provided for this purpose. The value of this expression is
4428 -- assigned to an intermediate variable to assure that any entry
4429 -- family index expressions are evaluated before the entry
4432 if not Is_Protected_Type (Conctyp)
4434 Corresponding_Runtime_Package (Conctyp) =
4435 System_Tasking_Protected_Objects_Entries
4437 X := Make_Defining_Identifier (Loc, Name_uX);
4440 Make_Object_Declaration (Loc,
4441 Defining_Identifier => X,
4442 Object_Definition =>
4443 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
4444 Expression => Actual_Index_Expression (
4445 Loc, Entity (Ename), Index, Concval));
4447 Append_To (Decls, Xdecl);
4448 Parm2 := New_Occurrence_Of (X, Loc);
4455 -- The third parameter is the packaged parameters. If there are
4456 -- none, then it is just the null address, since nothing is passed.
4459 Parm3 := New_Occurrence_Of (RTE (RE_Null_Address), Loc);
4462 -- Case of parameters present, where third argument is the address
4463 -- of a packaged record containing the required parameter values.
4466 -- First build a list of parameter values, which are references to
4467 -- objects of the parameter types.
4471 Actual := First_Actual (N);
4472 Formal := First_Formal (Ent);
4473 while Present (Actual) loop
4475 -- If it is a by-copy type, copy it to a new variable. The
4476 -- packaged record has a field that points to this variable.
4478 if Is_By_Copy_Type (Etype (Actual)) then
4480 Make_Object_Declaration (Loc,
4481 Defining_Identifier => Make_Temporary (Loc, 'J'),
4482 Aliased_Present => True,
4483 Object_Definition =>
4484 New_Occurrence_Of (Etype (Formal), Loc));
4486 -- Mark the object as not needing initialization since the
4487 -- initialization is performed separately, avoiding errors
4488 -- on cases such as formals of null-excluding access types.
4490 Set_No_Initialization (N_Node);
4492 -- We must make a separate assignment statement for the
4493 -- case of limited types. We cannot assign it unless the
4494 -- Assignment_OK flag is set first. An out formal of an
4495 -- access type or whose type has a Default_Value must also
4496 -- be initialized from the actual (see RM 6.4.1 (13-13.1)),
4497 -- but no constraint, predicate, or null-exclusion check is
4498 -- applied before the call.
4500 if Ekind (Formal) /= E_Out_Parameter
4501 or else Is_Access_Type (Etype (Formal))
4503 (Is_Scalar_Type (Etype (Formal))
4505 Present (Default_Aspect_Value (Etype (Formal))))
4508 New_Occurrence_Of (Defining_Identifier (N_Node), Loc);
4509 Set_Assignment_OK (N_Var);
4511 Make_Assignment_Statement (Loc,
4513 Expression => Relocate_Node (Actual)));
4515 -- Mark the object as internal, so we don't later reset
4516 -- No_Initialization flag in Default_Initialize_Object,
4517 -- which would lead to needless default initialization.
4518 -- We don't set this outside the if statement, because
4519 -- out scalar parameters without Default_Value do require
4520 -- default initialization if Initialize_Scalars applies.
4522 Set_Is_Internal (Defining_Identifier (N_Node));
4524 -- If actual is an out parameter of a null-excluding
4525 -- access type, there is access check on entry, so set
4526 -- Suppress_Assignment_Checks on the generated statement
4527 -- that assigns the actual to the parameter block.
4529 Set_Suppress_Assignment_Checks (Last (Stats));
4532 Append (N_Node, Decls);
4535 Make_Attribute_Reference (Loc,
4536 Attribute_Name => Name_Unchecked_Access,
4539 (Defining_Identifier (N_Node), Loc)));
4542 -- Interface class-wide formal
4544 if Ada_Version >= Ada_2005
4545 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
4546 and then Is_Interface (Etype (Formal))
4548 Iface_Typ := Etype (Etype (Formal));
4551 -- formal_iface_type! (actual.iface_tag)'reference
4554 Find_Interface_Tag (Etype (Actual), Iface_Typ);
4555 pragma Assert (Present (Iface_Tag));
4558 Make_Reference (Loc,
4559 Unchecked_Convert_To (Iface_Typ,
4560 Make_Selected_Component (Loc,
4562 Relocate_Node (Actual),
4564 New_Occurrence_Of (Iface_Tag, Loc)))));
4570 Make_Reference (Loc, Relocate_Node (Actual)));
4574 Next_Actual (Actual);
4575 Next_Formal_With_Extras (Formal);
4578 -- Now build the declaration of parameters initialized with the
4579 -- aggregate containing this constructed parameter list.
4581 P := Make_Defining_Identifier (Loc, Name_uP);
4584 Make_Object_Declaration (Loc,
4585 Defining_Identifier => P,
4586 Object_Definition =>
4587 New_Occurrence_Of (Designated_Type (Ent_Acc), Loc),
4589 Make_Aggregate (Loc, Expressions => Plist));
4592 Make_Attribute_Reference (Loc,
4593 Prefix => New_Occurrence_Of (P, Loc),
4594 Attribute_Name => Name_Address);
4596 Append (Pdecl, Decls);
4599 -- Now we can create the call, case of protected type
4601 if Is_Protected_Type (Conctyp) then
4602 case Corresponding_Runtime_Package (Conctyp) is
4603 when System_Tasking_Protected_Objects_Entries =>
4605 -- Change the type of the index declaration
4607 Set_Object_Definition (Xdecl,
4608 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc));
4610 -- Some additional declarations for protected entry calls
4616 -- Bnn : Communications_Block;
4618 Comm_Name := Make_Temporary (Loc, 'B');
4621 Make_Object_Declaration (Loc,
4622 Defining_Identifier => Comm_Name,
4623 Object_Definition =>
4625 (RTE (RE_Communication_Block), Loc)));
4627 -- Some additional statements for protected entry calls
4629 -- Protected_Entry_Call
4630 -- (Object => po._object'Access,
4631 -- E => <entry index>;
4632 -- Uninterpreted_Data => P'Address;
4633 -- Mode => Simple_Call;
4637 Make_Procedure_Call_Statement (Loc,
4639 New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
4641 Parameter_Associations => New_List (
4642 Make_Attribute_Reference (Loc,
4643 Attribute_Name => Name_Unchecked_Access,
4647 New_Occurrence_Of (RTE (RE_Simple_Call), Loc),
4648 New_Occurrence_Of (Comm_Name, Loc)));
4650 when System_Tasking_Protected_Objects_Single_Entry =>
4652 -- Protected_Single_Entry_Call
4653 -- (Object => po._object'Access,
4654 -- Uninterpreted_Data => P'Address);
4657 Make_Procedure_Call_Statement (Loc,
4660 (RTE (RE_Protected_Single_Entry_Call), Loc),
4662 Parameter_Associations => New_List (
4663 Make_Attribute_Reference (Loc,
4664 Attribute_Name => Name_Unchecked_Access,
4669 raise Program_Error;
4672 -- Case of task type
4676 Make_Procedure_Call_Statement (Loc,
4678 New_Occurrence_Of (RTE (RE_Call_Simple), Loc),
4679 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
4683 Append_To (Stats, Call);
4685 -- If there are out or in/out parameters by copy add assignment
4686 -- statements for the result values.
4688 if Present (Parms) then
4689 Actual := First_Actual (N);
4690 Formal := First_Formal (Ent);
4692 Set_Assignment_OK (Actual);
4693 while Present (Actual) loop
4694 if Is_By_Copy_Type (Etype (Actual))
4695 and then Ekind (Formal) /= E_In_Parameter
4698 Make_Assignment_Statement (Loc,
4699 Name => New_Copy (Actual),
4701 Make_Explicit_Dereference (Loc,
4702 Make_Selected_Component (Loc,
4703 Prefix => New_Occurrence_Of (P, Loc),
4705 Make_Identifier (Loc, Chars (Formal)))));
4707 -- In all cases (including limited private types) we want
4708 -- the assignment to be valid.
4710 Set_Assignment_OK (Name (N_Node));
4712 -- If the call is the triggering alternative in an
4713 -- asynchronous select, or the entry_call alternative of a
4714 -- conditional entry call, the assignments for in-out
4715 -- parameters are incorporated into the statement list that
4716 -- follows, so that there are executed only if the entry
4719 if (Nkind (Parent (N)) = N_Triggering_Alternative
4720 and then N = Triggering_Statement (Parent (N)))
4722 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4723 and then N = Entry_Call_Statement (Parent (N)))
4725 if No (Statements (Parent (N))) then
4726 Set_Statements (Parent (N), New_List);
4729 Prepend (N_Node, Statements (Parent (N)));
4732 Insert_After (Call, N_Node);
4736 Next_Actual (Actual);
4737 Next_Formal_With_Extras (Formal);
4741 -- Finally, create block and analyze it
4744 Make_Block_Statement (Loc,
4745 Declarations => Decls,
4746 Handled_Statement_Sequence =>
4747 Make_Handled_Sequence_Of_Statements (Loc,
4748 Statements => Stats)));
4752 end Build_Simple_Entry_Call;
4754 --------------------------------
4755 -- Build_Task_Activation_Call --
4756 --------------------------------
4758 procedure Build_Task_Activation_Call (N : Node_Id) is
4759 Loc : constant Source_Ptr := Sloc (N);
4766 -- For sequential elaboration policy, all the tasks will be activated at
4767 -- the end of the elaboration.
4769 if Partition_Elaboration_Policy = 'S' then
4773 -- Get the activation chain entity. Except in the case of a package
4774 -- body, this is in the node that was passed. For a package body, we
4775 -- have to find the corresponding package declaration node.
4777 if Nkind (N) = N_Package_Body then
4778 P := Corresponding_Spec (N);
4781 exit when Nkind (P) = N_Package_Declaration;
4784 Chain := Activation_Chain_Entity (P);
4787 Chain := Activation_Chain_Entity (N);
4790 if Present (Chain) then
4791 if Restricted_Profile then
4792 Name := New_Occurrence_Of
4793 (RTE (RE_Activate_Restricted_Tasks), Loc);
4795 Name := New_Occurrence_Of
4796 (RTE (RE_Activate_Tasks), Loc);
4800 Make_Procedure_Call_Statement (Loc,
4802 Parameter_Associations =>
4803 New_List (Make_Attribute_Reference (Loc,
4804 Prefix => New_Occurrence_Of (Chain, Loc),
4805 Attribute_Name => Name_Unchecked_Access)));
4807 if Nkind (N) = N_Package_Declaration then
4808 if Present (Corresponding_Body (N)) then
4811 elsif Present (Private_Declarations (Specification (N))) then
4812 Append (Call, Private_Declarations (Specification (N)));
4815 Append (Call, Visible_Declarations (Specification (N)));
4819 if Present (Handled_Statement_Sequence (N)) then
4821 -- The call goes at the start of the statement sequence after
4822 -- the start of exception range label if one is present.
4828 Stm := First (Statements (Handled_Statement_Sequence (N)));
4830 -- A special case, skip exception range label if one is
4831 -- present (from front end zcx processing).
4833 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
4837 -- Another special case, if the first statement is a block
4838 -- from optimization of a local raise to a goto, then the
4839 -- call goes inside this block.
4841 if Nkind (Stm) = N_Block_Statement
4842 and then Exception_Junk (Stm)
4845 First (Statements (Handled_Statement_Sequence (Stm)));
4848 -- Insertion point is after any exception label pushes,
4849 -- since we want it covered by any local handlers.
4851 while Nkind (Stm) in N_Push_xxx_Label loop
4855 -- Now we have the proper insertion point
4857 Insert_Before (Stm, Call);
4861 Set_Handled_Statement_Sequence (N,
4862 Make_Handled_Sequence_Of_Statements (Loc,
4863 Statements => New_List (Call)));
4868 Check_Task_Activation (N);
4870 end Build_Task_Activation_Call;
4872 -------------------------------
4873 -- Build_Task_Allocate_Block --
4874 -------------------------------
4876 procedure Build_Task_Allocate_Block
4881 T : constant Entity_Id := Entity (Expression (N));
4882 Init : constant Entity_Id := Base_Init_Proc (T);
4883 Loc : constant Source_Ptr := Sloc (N);
4884 Chain : constant Entity_Id :=
4885 Make_Defining_Identifier (Loc, Name_uChain);
4886 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4891 Make_Block_Statement (Loc,
4892 Identifier => New_Occurrence_Of (Blkent, Loc),
4893 Declarations => New_List (
4895 -- _Chain : Activation_Chain;
4897 Make_Object_Declaration (Loc,
4898 Defining_Identifier => Chain,
4899 Aliased_Present => True,
4900 Object_Definition =>
4901 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
4903 Handled_Statement_Sequence =>
4904 Make_Handled_Sequence_Of_Statements (Loc,
4906 Statements => New_List (
4910 Make_Procedure_Call_Statement (Loc,
4911 Name => New_Occurrence_Of (Init, Loc),
4912 Parameter_Associations => Args),
4914 -- Activate_Tasks (_Chain);
4916 Make_Procedure_Call_Statement (Loc,
4917 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
4918 Parameter_Associations => New_List (
4919 Make_Attribute_Reference (Loc,
4920 Prefix => New_Occurrence_Of (Chain, Loc),
4921 Attribute_Name => Name_Unchecked_Access))))),
4923 Has_Created_Identifier => True,
4924 Is_Task_Allocation_Block => True);
4927 Make_Implicit_Label_Declaration (Loc,
4928 Defining_Identifier => Blkent,
4929 Label_Construct => Block));
4931 Append_To (Actions, Block);
4933 Set_Activation_Chain_Entity (Block, Chain);
4934 end Build_Task_Allocate_Block;
4936 -----------------------------------------------
4937 -- Build_Task_Allocate_Block_With_Init_Stmts --
4938 -----------------------------------------------
4940 procedure Build_Task_Allocate_Block_With_Init_Stmts
4943 Init_Stmts : List_Id)
4945 Loc : constant Source_Ptr := Sloc (N);
4946 Chain : constant Entity_Id :=
4947 Make_Defining_Identifier (Loc, Name_uChain);
4948 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
4952 Append_To (Init_Stmts,
4953 Make_Procedure_Call_Statement (Loc,
4954 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
4955 Parameter_Associations => New_List (
4956 Make_Attribute_Reference (Loc,
4957 Prefix => New_Occurrence_Of (Chain, Loc),
4958 Attribute_Name => Name_Unchecked_Access))));
4961 Make_Block_Statement (Loc,
4962 Identifier => New_Occurrence_Of (Blkent, Loc),
4963 Declarations => New_List (
4965 -- _Chain : Activation_Chain;
4967 Make_Object_Declaration (Loc,
4968 Defining_Identifier => Chain,
4969 Aliased_Present => True,
4970 Object_Definition =>
4971 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
4973 Handled_Statement_Sequence =>
4974 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
4976 Has_Created_Identifier => True,
4977 Is_Task_Allocation_Block => True);
4980 Make_Implicit_Label_Declaration (Loc,
4981 Defining_Identifier => Blkent,
4982 Label_Construct => Block));
4984 Append_To (Actions, Block);
4986 Set_Activation_Chain_Entity (Block, Chain);
4987 end Build_Task_Allocate_Block_With_Init_Stmts;
4989 -----------------------------------
4990 -- Build_Task_Proc_Specification --
4991 -----------------------------------
4993 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
4994 Loc : constant Source_Ptr := Sloc (T);
4995 Spec_Id : Entity_Id;
4998 -- Case of explicit task type, suffix TB
5000 if Comes_From_Source (T) then
5002 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), "TB"));
5004 -- Case of anonymous task type, suffix B
5008 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), 'B'));
5011 Set_Is_Internal (Spec_Id);
5013 -- Associate the procedure with the task, if this is the declaration
5014 -- (and not the body) of the procedure.
5016 if No (Task_Body_Procedure (T)) then
5017 Set_Task_Body_Procedure (T, Spec_Id);
5021 Make_Procedure_Specification (Loc,
5022 Defining_Unit_Name => Spec_Id,
5023 Parameter_Specifications => New_List (
5024 Make_Parameter_Specification (Loc,
5025 Defining_Identifier =>
5026 Make_Defining_Identifier (Loc, Name_uTask),
5028 Make_Access_Definition (Loc,
5030 New_Occurrence_Of (Corresponding_Record_Type (T), Loc)))));
5031 end Build_Task_Proc_Specification;
5033 ---------------------------------------
5034 -- Build_Unprotected_Subprogram_Body --
5035 ---------------------------------------
5037 function Build_Unprotected_Subprogram_Body
5039 Pid : Node_Id) return Node_Id
5041 Decls : constant List_Id := Declarations (N);
5044 -- Add renamings for the Protection object, discriminals, privals, and
5045 -- the entry index constant for use by debugger.
5047 Debug_Private_Data_Declarations (Decls);
5049 -- Make an unprotected version of the subprogram for use within the same
5050 -- object, with a new name and an additional parameter representing the
5054 Make_Subprogram_Body (Sloc (N),
5056 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
5057 Declarations => Decls,
5058 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
5059 end Build_Unprotected_Subprogram_Body;
5061 ----------------------------
5062 -- Collect_Entry_Families --
5063 ----------------------------
5065 procedure Collect_Entry_Families
5068 Current_Node : in out Node_Id;
5069 Conctyp : Entity_Id)
5072 Efam_Decl : Node_Id;
5073 Efam_Type : Entity_Id;
5076 Efam := First_Entity (Conctyp);
5077 while Present (Efam) loop
5078 if Ekind (Efam) = E_Entry_Family then
5079 Efam_Type := Make_Temporary (Loc, 'F');
5084 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
5086 Bas_Decl : Node_Id := Empty;
5091 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
5093 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
5094 Bas := Make_Temporary (Loc, 'B');
5097 Make_Subtype_Declaration (Loc,
5098 Defining_Identifier => Bas,
5099 Subtype_Indication =>
5100 Make_Subtype_Indication (Loc,
5102 New_Occurrence_Of (Standard_Integer, Loc),
5104 Make_Range_Constraint (Loc,
5105 Range_Expression => Make_Range (Loc,
5106 Make_Integer_Literal
5107 (Loc, -Entry_Family_Bound),
5108 Make_Integer_Literal
5109 (Loc, Entry_Family_Bound - 1)))));
5111 Insert_After (Current_Node, Bas_Decl);
5112 Current_Node := Bas_Decl;
5117 Make_Full_Type_Declaration (Loc,
5118 Defining_Identifier => Efam_Type,
5120 Make_Unconstrained_Array_Definition (Loc,
5122 (New_List (New_Occurrence_Of (Bas, Loc))),
5124 Component_Definition =>
5125 Make_Component_Definition (Loc,
5126 Aliased_Present => False,
5127 Subtype_Indication =>
5128 New_Occurrence_Of (Standard_Character, Loc))));
5131 Insert_After (Current_Node, Efam_Decl);
5132 Current_Node := Efam_Decl;
5133 Analyze (Efam_Decl);
5136 Make_Component_Declaration (Loc,
5137 Defining_Identifier =>
5138 Make_Defining_Identifier (Loc, Chars (Efam)),
5140 Component_Definition =>
5141 Make_Component_Definition (Loc,
5142 Aliased_Present => False,
5143 Subtype_Indication =>
5144 Make_Subtype_Indication (Loc,
5146 New_Occurrence_Of (Efam_Type, Loc),
5149 Make_Index_Or_Discriminant_Constraint (Loc,
5150 Constraints => New_List (
5152 (Etype (Discrete_Subtype_Definition
5153 (Parent (Efam))), Loc)))))));
5159 end Collect_Entry_Families;
5161 -----------------------
5162 -- Concurrent_Object --
5163 -----------------------
5165 function Concurrent_Object
5166 (Spec_Id : Entity_Id;
5167 Conc_Typ : Entity_Id) return Entity_Id
5170 -- Parameter _O or _object
5172 if Is_Protected_Type (Conc_Typ) then
5173 return First_Formal (Protected_Body_Subprogram (Spec_Id));
5178 pragma Assert (Is_Task_Type (Conc_Typ));
5179 return First_Formal (Task_Body_Procedure (Conc_Typ));
5181 end Concurrent_Object;
5183 ----------------------
5184 -- Copy_Result_Type --
5185 ----------------------
5187 function Copy_Result_Type (Res : Node_Id) return Node_Id is
5188 New_Res : constant Node_Id := New_Copy_Tree (Res);
5193 -- If the result type is an access_to_subprogram, we must create new
5194 -- entities for its spec.
5196 if Nkind (New_Res) = N_Access_Definition
5197 and then Present (Access_To_Subprogram_Definition (New_Res))
5199 -- Provide new entities for the formals
5201 Par_Spec := First (Parameter_Specifications
5202 (Access_To_Subprogram_Definition (New_Res)));
5203 while Present (Par_Spec) loop
5204 Formal := Defining_Identifier (Par_Spec);
5205 Set_Defining_Identifier (Par_Spec,
5206 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
5212 end Copy_Result_Type;
5214 --------------------
5215 -- Concurrent_Ref --
5216 --------------------
5218 -- The expression returned for a reference to a concurrent object has the
5221 -- taskV!(name)._Task_Id
5225 -- objectV!(name)._Object
5227 -- for a protected object. For the case of an access to a concurrent
5228 -- object, there is an extra explicit dereference:
5230 -- taskV!(name.all)._Task_Id
5231 -- objectV!(name.all)._Object
5233 -- here taskV and objectV are the types for the associated records, which
5234 -- contain the required _Task_Id and _Object fields for tasks and protected
5235 -- objects, respectively.
5237 -- For the case of a task type name, the expression is
5241 -- i.e. a call to the Self function which returns precisely this Task_Id
5243 -- For the case of a protected type name, the expression is
5247 -- which is a renaming of the _object field of the current object
5248 -- record, passed into protected operations as a parameter.
5250 function Concurrent_Ref (N : Node_Id) return Node_Id is
5251 Loc : constant Source_Ptr := Sloc (N);
5252 Ntyp : constant Entity_Id := Etype (N);
5256 function Is_Current_Task (T : Entity_Id) return Boolean;
5257 -- Check whether the reference is to the immediately enclosing task
5258 -- type, or to an outer one (rare but legal).
5260 ---------------------
5261 -- Is_Current_Task --
5262 ---------------------
5264 function Is_Current_Task (T : Entity_Id) return Boolean is
5268 Scop := Current_Scope;
5269 while Present (Scop) and then Scop /= Standard_Standard loop
5273 elsif Is_Task_Type (Scop) then
5276 -- If this is a procedure nested within the task type, we must
5277 -- assume that it can be called from an inner task, and therefore
5278 -- cannot treat it as a local reference.
5280 elsif Is_Overloadable (Scop) and then In_Open_Scopes (T) then
5284 Scop := Scope (Scop);
5288 -- We know that we are within the task body, so should have found it
5291 raise Program_Error;
5292 end Is_Current_Task;
5294 -- Start of processing for Concurrent_Ref
5297 if Is_Access_Type (Ntyp) then
5298 Dtyp := Designated_Type (Ntyp);
5300 if Is_Protected_Type (Dtyp) then
5301 Sel := Name_uObject;
5303 Sel := Name_uTask_Id;
5307 Make_Selected_Component (Loc,
5309 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
5310 Make_Explicit_Dereference (Loc, N)),
5311 Selector_Name => Make_Identifier (Loc, Sel));
5313 elsif Is_Entity_Name (N) and then Is_Concurrent_Type (Entity (N)) then
5314 if Is_Task_Type (Entity (N)) then
5316 if Is_Current_Task (Entity (N)) then
5318 Make_Function_Call (Loc,
5319 Name => New_Occurrence_Of (RTE (RE_Self), Loc));
5324 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
5325 T_Body : constant Node_Id :=
5326 Parent (Corresponding_Body (Parent (Entity (N))));
5330 Make_Object_Declaration (Loc,
5331 Defining_Identifier => T_Self,
5332 Object_Definition =>
5333 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
5335 Make_Function_Call (Loc,
5336 Name => New_Occurrence_Of (RTE (RE_Self), Loc)));
5337 Prepend (Decl, Declarations (T_Body));
5339 Set_Scope (T_Self, Entity (N));
5340 return New_Occurrence_Of (T_Self, Loc);
5345 pragma Assert (Is_Protected_Type (Entity (N)));
5348 New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc);
5352 if Is_Protected_Type (Ntyp) then
5353 Sel := Name_uObject;
5354 elsif Is_Task_Type (Ntyp) then
5355 Sel := Name_uTask_Id;
5357 raise Program_Error;
5361 Make_Selected_Component (Loc,
5363 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
5365 Selector_Name => Make_Identifier (Loc, Sel));
5369 ------------------------
5370 -- Convert_Concurrent --
5371 ------------------------
5373 function Convert_Concurrent
5375 Typ : Entity_Id) return Node_Id
5378 if not Is_Concurrent_Type (Typ) then
5382 Unchecked_Convert_To
5383 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
5385 end Convert_Concurrent;
5387 -------------------------------------
5388 -- Debug_Private_Data_Declarations --
5389 -------------------------------------
5391 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
5392 Debug_Nod : Node_Id;
5396 Decl := First (Decls);
5397 while Present (Decl) and then not Comes_From_Source (Decl) loop
5399 -- Declaration for concurrent entity _object and its access type,
5400 -- along with the entry index subtype:
5401 -- type prot_typVP is access prot_typV;
5402 -- _object : prot_typVP := prot_typV (_O);
5403 -- subtype Jnn is <Type of Index> range Low .. High;
5405 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
5406 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5408 -- Declaration for the Protection object, discriminals, privals, and
5409 -- entry index constant:
5410 -- conc_typR : protection_typ renames _object._object;
5411 -- discr_nameD : discr_typ renames _object.discr_name;
5412 -- discr_nameD : discr_typ renames _task.discr_name;
5413 -- prival_name : comp_typ renames _object.comp_name;
5414 -- J : constant Jnn :=
5415 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5417 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
5418 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5419 Debug_Nod := Debug_Renaming_Declaration (Decl);
5421 if Present (Debug_Nod) then
5422 Insert_After (Decl, Debug_Nod);
5428 end Debug_Private_Data_Declarations;
5430 ------------------------------
5431 -- Ensure_Statement_Present --
5432 ------------------------------
5434 procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id) is
5438 if Opt.Suppress_Control_Flow_Optimizations
5439 and then Is_Empty_List (Statements (Alt))
5441 Stmt := Make_Null_Statement (Loc);
5443 -- Mark NULL statement as coming from source so that it is not
5444 -- eliminated by GIGI.
5446 -- Another covert channel. If this is a requirement, it must be
5447 -- documented in sinfo/einfo ???
5449 Set_Comes_From_Source (Stmt, True);
5451 Set_Statements (Alt, New_List (Stmt));
5453 end Ensure_Statement_Present;
5455 ----------------------------
5456 -- Entry_Index_Expression --
5457 ----------------------------
5459 function Entry_Index_Expression
5463 Ttyp : Entity_Id) return Node_Id
5473 -- The queues of entries and entry families appear in textual order in
5474 -- the associated record. The entry index is computed as the sum of the
5475 -- number of queues for all entries that precede the designated one, to
5476 -- which is added the index expression, if this expression denotes a
5477 -- member of a family.
5479 -- The following is a place holder for the count of simple entries
5481 Num := Make_Integer_Literal (Sloc, 1);
5483 -- We construct an expression which is a series of addition operations.
5484 -- The first operand is the number of single entries that precede this
5485 -- one, the second operand is the index value relative to the start of
5486 -- the referenced family, and the remaining operands are the lengths of
5487 -- the entry families that precede this entry, i.e. the constructed
5490 -- number_simple_entries +
5491 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5492 -- family'length + ...
5494 -- where index-value is the given index value, and s is the index
5495 -- subtype (we have to use pos because the subtype might be an
5496 -- enumeration type preventing direct subtraction). Note that the task
5497 -- entry array is one-indexed.
5499 -- The upper bound of the entry family may be a discriminant, so we
5500 -- retrieve the lower bound explicitly to compute offset, rather than
5501 -- using the index subtype which may mention a discriminant.
5503 if Present (Index) then
5504 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
5512 Make_Attribute_Reference (Sloc,
5513 Attribute_Name => Name_Pos,
5514 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
5515 Expressions => New_List (Relocate_Node (Index))),
5523 -- Now add lengths of preceding entries and entry families
5525 Prev := First_Entity (Ttyp);
5526 while Chars (Prev) /= Chars (Ent)
5527 or else (Ekind (Prev) /= Ekind (Ent))
5528 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
5530 if Ekind (Prev) = E_Entry then
5531 Set_Intval (Num, Intval (Num) + 1);
5533 elsif Ekind (Prev) = E_Entry_Family then
5534 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
5535 Lo := Type_Low_Bound (S);
5536 Hi := Type_High_Bound (S);
5541 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
5543 -- Other components are anonymous types to be ignored
5553 end Entry_Index_Expression;
5555 ---------------------------
5556 -- Establish_Task_Master --
5557 ---------------------------
5559 procedure Establish_Task_Master (N : Node_Id) is
5563 if Restriction_Active (No_Task_Hierarchy) = False then
5564 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
5566 -- The block may have no declarations (and nevertheless be a task
5567 -- master) if it contains a call that may return an object that
5570 if No (Declarations (N)) then
5571 Set_Declarations (N, New_List (Call));
5573 Prepend_To (Declarations (N), Call);
5578 end Establish_Task_Master;
5580 --------------------------------
5581 -- Expand_Accept_Declarations --
5582 --------------------------------
5584 -- Part of the expansion of an accept statement involves the creation of
5585 -- a declaration that can be referenced from the statement sequence of
5590 -- This declaration is inserted immediately before the accept statement
5591 -- and it is important that it be inserted before the statements of the
5592 -- statement sequence are analyzed. Thus it would be too late to create
5593 -- this declaration in the Expand_N_Accept_Statement routine, which is
5594 -- why there is a separate procedure to be called directly from Sem_Ch9.
5596 -- Ann is used to hold the address of the record containing the parameters
5597 -- (see Expand_N_Entry_Call for more details on how this record is built).
5598 -- References to the parameters do an unchecked conversion of this address
5599 -- to a pointer to the required record type, and then access the field that
5600 -- holds the value of the required parameter. The entity for the address
5601 -- variable is held as the top stack element (i.e. the last element) of the
5602 -- Accept_Address stack in the corresponding entry entity, and this element
5603 -- must be set in place before the statements are processed.
5605 -- The above description applies to the case of a stand alone accept
5606 -- statement, i.e. one not appearing as part of a select alternative.
5608 -- For the case of an accept that appears as part of a select alternative
5609 -- of a selective accept, we must still create the declaration right away,
5610 -- since Ann is needed immediately, but there is an important difference:
5612 -- The declaration is inserted before the selective accept, not before
5613 -- the accept statement (which is not part of a list anyway, and so would
5614 -- not accommodate inserted declarations)
5616 -- We only need one address variable for the entire selective accept. So
5617 -- the Ann declaration is created only for the first accept alternative,
5618 -- and subsequent accept alternatives reference the same Ann variable.
5620 -- We can distinguish the two cases by seeing whether the accept statement
5621 -- is part of a list. If not, then it must be in an accept alternative.
5623 -- To expand the requeue statement, a label is provided at the end of the
5624 -- accept statement or alternative of which it is a part, so that the
5625 -- statement can be skipped after the requeue is complete. This label is
5626 -- created here rather than during the expansion of the accept statement,
5627 -- because it will be needed by any requeue statements within the accept,
5628 -- which are expanded before the accept.
5630 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
5631 Loc : constant Source_Ptr := Sloc (N);
5632 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5633 Ann : Entity_Id := Empty;
5640 if Expander_Active then
5642 -- If we have no handled statement sequence, we may need to build
5643 -- a dummy sequence consisting of a null statement. This can be
5644 -- skipped if the trivial accept optimization is permitted.
5646 if not Trivial_Accept_OK
5647 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5649 Set_Handled_Statement_Sequence (N,
5650 Make_Handled_Sequence_Of_Statements (Loc,
5651 Statements => New_List (Make_Null_Statement (Loc))));
5654 -- Create and declare two labels to be placed at the end of the
5655 -- accept statement. The first label is used to allow requeues to
5656 -- skip the remainder of entry processing. The second label is used
5657 -- to skip the remainder of entry processing if the rendezvous
5658 -- completes in the middle of the accept body.
5660 if Present (Handled_Statement_Sequence (N)) then
5665 Ent := Make_Temporary (Loc, 'L');
5666 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5668 Make_Implicit_Label_Declaration (Loc,
5669 Defining_Identifier => Ent,
5670 Label_Construct => Lab);
5671 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5673 Ent := Make_Temporary (Loc, 'L');
5674 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5676 Make_Implicit_Label_Declaration (Loc,
5677 Defining_Identifier => Ent,
5678 Label_Construct => Lab);
5679 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5687 -- Case of stand alone accept statement
5689 if Is_List_Member (N) then
5691 if Present (Handled_Statement_Sequence (N)) then
5692 Ann := Make_Temporary (Loc, 'A');
5695 Make_Object_Declaration (Loc,
5696 Defining_Identifier => Ann,
5697 Object_Definition =>
5698 New_Occurrence_Of (RTE (RE_Address), Loc));
5700 Insert_Before_And_Analyze (N, Adecl);
5701 Insert_Before_And_Analyze (N, Ldecl);
5702 Insert_Before_And_Analyze (N, Ldecl2);
5705 -- Case of accept statement which is in an accept alternative
5709 Acc_Alt : constant Node_Id := Parent (N);
5710 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
5714 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
5715 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
5717 -- ??? Consider a single label for select statements
5719 if Present (Handled_Statement_Sequence (N)) then
5721 Statements (Handled_Statement_Sequence (N)));
5725 Statements (Handled_Statement_Sequence (N)));
5729 -- Find first accept alternative of the selective accept. A
5730 -- valid selective accept must have at least one accept in it.
5732 Alt := First (Select_Alternatives (Sel_Acc));
5734 while Nkind (Alt) /= N_Accept_Alternative loop
5738 -- If this is the first accept statement, then we have to
5739 -- create the Ann variable, as for the stand alone case, except
5740 -- that it is inserted before the selective accept. Similarly,
5741 -- a label for requeue expansion must be declared.
5743 if N = Accept_Statement (Alt) then
5744 Ann := Make_Temporary (Loc, 'A');
5746 Make_Object_Declaration (Loc,
5747 Defining_Identifier => Ann,
5748 Object_Definition =>
5749 New_Occurrence_Of (RTE (RE_Address), Loc));
5751 Insert_Before_And_Analyze (Sel_Acc, Adecl);
5753 -- If this is not the first accept statement, then find the Ann
5754 -- variable allocated by the first accept and use it.
5758 Node (Last_Elmt (Accept_Address
5759 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
5764 -- Merge here with Ann either created or referenced, and Adecl
5765 -- pointing to the corresponding declaration. Remaining processing
5766 -- is the same for the two cases.
5768 if Present (Ann) then
5769 Append_Elmt (Ann, Accept_Address (Ent));
5770 Set_Debug_Info_Needed (Ann);
5773 -- Create renaming declarations for the entry formals. Each reference
5774 -- to a formal becomes a dereference of a component of the parameter
5775 -- block, whose address is held in Ann. These declarations are
5776 -- eventually inserted into the accept block, and analyzed there so
5777 -- that they have the proper scope for gdb and do not conflict with
5778 -- other declarations.
5780 if Present (Parameter_Specifications (N))
5781 and then Present (Handled_Statement_Sequence (N))
5788 Renamed_Formal : Node_Id;
5792 Formal := First_Formal (Ent);
5794 while Present (Formal) loop
5795 Comp := Entry_Component (Formal);
5796 New_F := Make_Defining_Identifier (Loc, Chars (Formal));
5798 Set_Etype (New_F, Etype (Formal));
5799 Set_Scope (New_F, Ent);
5801 -- Now we set debug info needed on New_F even though it does
5802 -- not come from source, so that the debugger will get the
5803 -- right information for these generated names.
5805 Set_Debug_Info_Needed (New_F);
5807 if Ekind (Formal) = E_In_Parameter then
5808 Set_Ekind (New_F, E_Constant);
5810 Set_Ekind (New_F, E_Variable);
5811 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
5814 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
5817 Make_Selected_Component (Loc,
5819 Unchecked_Convert_To (
5820 Entry_Parameters_Type (Ent),
5821 New_Occurrence_Of (Ann, Loc)),
5823 New_Occurrence_Of (Comp, Loc));
5826 Build_Renamed_Formal_Declaration
5827 (New_F, Formal, Comp, Renamed_Formal);
5829 if No (Declarations (N)) then
5830 Set_Declarations (N, New_List);
5833 Append (Decl, Declarations (N));
5834 Set_Renamed_Object (Formal, New_F);
5835 Next_Formal (Formal);
5842 end Expand_Accept_Declarations;
5844 ---------------------------------------------
5845 -- Expand_Access_Protected_Subprogram_Type --
5846 ---------------------------------------------
5848 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
5849 Loc : constant Source_Ptr := Sloc (N);
5850 T : constant Entity_Id := Defining_Identifier (N);
5851 D_T : constant Entity_Id := Designated_Type (T);
5852 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
5853 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
5854 P_List : constant List_Id :=
5855 Build_Protected_Spec (N, RTE (RE_Address), D_T, False);
5863 -- Create access to subprogram with full signature
5865 if Etype (D_T) /= Standard_Void_Type then
5867 Make_Access_Function_Definition (Loc,
5868 Parameter_Specifications => P_List,
5869 Result_Definition =>
5870 Copy_Result_Type (Result_Definition (Type_Definition (N))));
5874 Make_Access_Procedure_Definition (Loc,
5875 Parameter_Specifications => P_List);
5879 Make_Full_Type_Declaration (Loc,
5880 Defining_Identifier => D_T2,
5881 Type_Definition => Def1);
5883 -- Declare the new types before the original one since the latter will
5884 -- refer to them through the Equivalent_Type slot.
5886 Insert_Before_And_Analyze (N, Decl1);
5888 -- Associate the access to subprogram with its original access to
5889 -- protected subprogram type. Needed by the backend to know that this
5890 -- type corresponds with an access to protected subprogram type.
5892 Set_Original_Access_Type (D_T2, T);
5894 -- Create Equivalent_Type, a record with two components for an access to
5895 -- object and an access to subprogram.
5898 Make_Component_Declaration (Loc,
5899 Defining_Identifier => Make_Temporary (Loc, 'P'),
5900 Component_Definition =>
5901 Make_Component_Definition (Loc,
5902 Aliased_Present => False,
5903 Subtype_Indication =>
5904 New_Occurrence_Of (RTE (RE_Address), Loc))),
5906 Make_Component_Declaration (Loc,
5907 Defining_Identifier => Make_Temporary (Loc, 'S'),
5908 Component_Definition =>
5909 Make_Component_Definition (Loc,
5910 Aliased_Present => False,
5911 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
5914 Make_Full_Type_Declaration (Loc,
5915 Defining_Identifier => E_T,
5917 Make_Record_Definition (Loc,
5919 Make_Component_List (Loc, Component_Items => Comps)));
5921 Insert_Before_And_Analyze (N, Decl2);
5922 Set_Equivalent_Type (T, E_T);
5923 end Expand_Access_Protected_Subprogram_Type;
5925 --------------------------
5926 -- Expand_Entry_Barrier --
5927 --------------------------
5929 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
5930 Cond : constant Node_Id :=
5931 Condition (Entry_Body_Formal_Part (N));
5932 Prot : constant Entity_Id := Scope (Ent);
5933 Spec_Decl : constant Node_Id := Parent (Prot);
5934 Func : Entity_Id := Empty;
5936 Body_Decl : Node_Id;
5938 function Is_Global_Entity (N : Node_Id) return Traverse_Result;
5939 -- Check whether entity in Barrier is external to protected type.
5940 -- If so, barrier may not be properly synchronized.
5942 function Is_Pure_Barrier (N : Node_Id) return Traverse_Result;
5943 -- Check whether N follows the Pure_Barriers restriction. Return OK if
5946 function Is_Simple_Barrier_Name (N : Node_Id) return Boolean;
5947 -- Check whether entity name N denotes a component of the protected
5948 -- object. This is used to check the Simple_Barrier restriction.
5950 ----------------------
5951 -- Is_Global_Entity --
5952 ----------------------
5954 function Is_Global_Entity (N : Node_Id) return Traverse_Result is
5959 if Is_Entity_Name (N) and then Present (Entity (N)) then
5963 if Ekind (E) = E_Variable then
5965 -- If the variable is local to the barrier function generated
5966 -- during expansion, it is ok. If expansion is not performed,
5967 -- then Func is Empty so this test cannot succeed.
5969 if Scope (E) = Func then
5972 -- A protected call from a barrier to another object is ok
5974 elsif Ekind (Etype (E)) = E_Protected_Type then
5977 -- If the variable is within the package body we consider
5978 -- this safe. This is a common (if dubious) idiom.
5980 elsif S = Scope (Prot)
5981 and then Ekind_In (S, E_Package, E_Generic_Package)
5982 and then Nkind (Parent (E)) = N_Object_Declaration
5983 and then Nkind (Parent (Parent (E))) = N_Package_Body
5988 Error_Msg_N ("potentially unsynchronized barrier??", N);
5989 Error_Msg_N ("\& should be private component of type??", N);
5995 end Is_Global_Entity;
5997 procedure Check_Unprotected_Barrier is
5998 new Traverse_Proc (Is_Global_Entity);
6000 ----------------------------
6001 -- Is_Simple_Barrier_Name --
6002 ----------------------------
6004 function Is_Simple_Barrier_Name (N : Node_Id) return Boolean is
6008 -- Check for case of _object.all.field (note that the explicit
6009 -- dereference gets inserted by analyze/expand of _object.field).
6011 if Expander_Active then
6012 Renamed := Renamed_Object (Entity (N));
6016 and then Nkind (Renamed) = N_Selected_Component
6017 and then Chars (Prefix (Prefix (Renamed))) = Name_uObject;
6019 return Scope (Entity (N)) = Current_Scope;
6021 end Is_Simple_Barrier_Name;
6023 ---------------------
6024 -- Is_Pure_Barrier --
6025 ---------------------
6027 function Is_Pure_Barrier (N : Node_Id) return Traverse_Result is
6028 function Is_Count_Attribute (N : Node_Id) return Boolean;
6029 -- Check whether N is part of an expansion of the Count attribute.
6030 -- Return True if N represents the expanded function call.
6032 ------------------------
6033 -- Is_Count_Attribute --
6034 ------------------------
6036 function Is_Count_Attribute (N : Node_Id) return Boolean is
6039 Nkind (N) = N_Function_Call
6040 and then Present (Original_Node (N))
6041 and then Nkind (Original_Node (N)) = N_Attribute_Reference
6042 and then Attribute_Name (Original_Node (N)) = Name_Count;
6043 end Is_Count_Attribute;
6045 -- Start of processing for Is_Pure_Barrier
6049 when N_Expanded_Name
6052 if No (Entity (N)) then
6056 if Present (Parent (N))
6057 and then Is_Count_Attribute (Parent (N))
6062 case Ekind (Entity (N)) is
6065 | E_Enumeration_Literal
6074 -- A variable in the protected type is expanded as a
6077 if Is_Simple_Barrier_Name (N) then
6085 when N_Function_Call =>
6086 if Is_Count_Attribute (N) then
6090 when N_Character_Literal
6099 if Ekind (Entity (N)) = E_Operator then
6103 when N_Short_Circuit =>
6111 end Is_Pure_Barrier;
6113 function Check_Pure_Barriers is new Traverse_Func (Is_Pure_Barrier);
6115 -- Start of processing for Expand_Entry_Barrier
6118 if No_Run_Time_Mode then
6119 Error_Msg_CRT ("entry barrier", N);
6123 -- The body of the entry barrier must be analyzed in the context of the
6124 -- protected object, but its scope is external to it, just as any other
6125 -- unprotected version of a protected operation. The specification has
6126 -- been produced when the protected type declaration was elaborated. We
6127 -- build the body, insert it in the enclosing scope, but analyze it in
6128 -- the current context. A more uniform approach would be to treat the
6129 -- barrier just as a protected function, and discard the protected
6130 -- version of it because it is never called.
6132 if Expander_Active then
6133 B_F := Build_Barrier_Function (N, Ent, Prot);
6134 Func := Barrier_Function (Ent);
6135 Set_Corresponding_Spec (B_F, Func);
6137 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
6139 if Nkind (Parent (Body_Decl)) = N_Subunit then
6140 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
6143 Insert_Before_And_Analyze (Body_Decl, B_F);
6145 Set_Discriminals (Spec_Decl);
6146 Set_Scope (Func, Scope (Prot));
6149 Analyze_And_Resolve (Cond, Any_Boolean);
6152 -- Check Pure_Barriers restriction
6154 if Check_Pure_Barriers (Cond) = Abandon then
6155 Check_Restriction (Pure_Barriers, Cond);
6158 -- The Ravenscar profile restricts barriers to simple variables declared
6159 -- within the protected object. We also allow Boolean constants, since
6160 -- these appear in several published examples and are also allowed by
6163 -- Note that after analysis variables in this context will be replaced
6164 -- by the corresponding prival, that is to say a renaming of a selected
6165 -- component of the form _Object.Var. If expansion is disabled, as
6166 -- within a generic, we check that the entity appears in the current
6169 if Is_Entity_Name (Cond) then
6171 -- A small optimization of useless renamings. If the scope of the
6172 -- entity of the condition is not the barrier function, then the
6173 -- condition does not reference any of the generated renamings
6174 -- within the function.
6176 if Expander_Active and then Scope (Entity (Cond)) /= Func then
6177 Set_Declarations (B_F, Empty_List);
6180 if Entity (Cond) = Standard_False
6182 Entity (Cond) = Standard_True
6186 elsif Is_Simple_Barrier_Name (Cond) then
6191 -- It is not a boolean variable or literal, so check the restriction.
6192 -- Note that it is safe to be calling Check_Restriction from here, even
6193 -- though this is part of the expander, since Expand_Entry_Barrier is
6194 -- called from Sem_Ch9 even in -gnatc mode.
6196 Check_Restriction (Simple_Barriers, Cond);
6198 -- Emit warning if barrier contains global entities and is thus
6199 -- potentially unsynchronized.
6201 Check_Unprotected_Barrier (Cond);
6202 end Expand_Entry_Barrier;
6204 ------------------------------
6205 -- Expand_N_Abort_Statement --
6206 ------------------------------
6208 -- Expand abort T1, T2, .. Tn; into:
6209 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6211 procedure Expand_N_Abort_Statement (N : Node_Id) is
6212 Loc : constant Source_Ptr := Sloc (N);
6213 Tlist : constant List_Id := Names (N);
6219 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
6222 Tasknm := First (Tlist);
6224 while Present (Tasknm) loop
6227 -- A task interface class-wide type object is being aborted. Retrieve
6228 -- its _task_id by calling a dispatching routine.
6230 if Ada_Version >= Ada_2005
6231 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
6232 and then Is_Interface (Etype (Tasknm))
6233 and then Is_Task_Interface (Etype (Tasknm))
6235 Append_To (Component_Associations (Aggr),
6236 Make_Component_Association (Loc,
6237 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6240 -- Task_Id (Tasknm._disp_get_task_id)
6242 Make_Unchecked_Type_Conversion (Loc,
6244 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
6246 Make_Selected_Component (Loc,
6247 Prefix => New_Copy_Tree (Tasknm),
6249 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
6252 Append_To (Component_Associations (Aggr),
6253 Make_Component_Association (Loc,
6254 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6255 Expression => Concurrent_Ref (Tasknm)));
6262 Make_Procedure_Call_Statement (Loc,
6263 Name => New_Occurrence_Of (RTE (RE_Abort_Tasks), Loc),
6264 Parameter_Associations => New_List (
6265 Make_Qualified_Expression (Loc,
6266 Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_List), Loc),
6267 Expression => Aggr))));
6270 end Expand_N_Abort_Statement;
6272 -------------------------------
6273 -- Expand_N_Accept_Statement --
6274 -------------------------------
6276 -- This procedure handles expansion of accept statements that stand alone,
6277 -- i.e. they are not part of an accept alternative. The expansion of
6278 -- accept statement in accept alternatives is handled by the routines
6279 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6280 -- following description applies only to stand alone accept statements.
6282 -- If there is no handled statement sequence, or only null statements, then
6283 -- this is called a trivial accept, and the expansion is:
6285 -- Accept_Trivial (entry-index)
6287 -- If there is a handled statement sequence, then the expansion is:
6294 -- Accept_Call (entry-index, Ann);
6295 -- Renaming_Declarations for formals
6296 -- <statement sequence from N_Accept_Statement node>
6297 -- Complete_Rendezvous;
6302 -- <exception handler from N_Accept_Statement node>
6303 -- Complete_Rendezvous;
6305 -- <exception handler from N_Accept_Statement node>
6306 -- Complete_Rendezvous;
6311 -- when all others =>
6312 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6315 -- The first three declarations were already inserted ahead of the accept
6316 -- statement by the Expand_Accept_Declarations procedure, which was called
6317 -- directly from the semantics during analysis of the accept statement,
6318 -- before analyzing its contained statements.
6320 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6321 -- from possible expansion activity (the original source of course does
6322 -- not have any declarations associated with the accept statement, since
6323 -- an accept statement has no declarative part). In particular, if the
6324 -- expander is active, the first such declaration is the declaration of
6325 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6327 -- The two blocks are merged into a single block if the inner block has
6328 -- no exception handlers, but otherwise two blocks are required, since
6329 -- exceptions might be raised in the exception handlers of the inner
6330 -- block, and Exceptional_Complete_Rendezvous must be called.
6332 procedure Expand_N_Accept_Statement (N : Node_Id) is
6333 Loc : constant Source_Ptr := Sloc (N);
6334 Stats : constant Node_Id := Handled_Statement_Sequence (N);
6335 Ename : constant Node_Id := Entry_Direct_Name (N);
6336 Eindx : constant Node_Id := Entry_Index (N);
6337 Eent : constant Entity_Id := Entity (Ename);
6338 Acstack : constant Elist_Id := Accept_Address (Eent);
6339 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
6340 Ttyp : constant Entity_Id := Etype (Scope (Eent));
6346 -- If the accept statement is not part of a list, then its parent must
6347 -- be an accept alternative, and, as described above, we do not do any
6348 -- expansion for such accept statements at this level.
6350 if not Is_List_Member (N) then
6351 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
6354 -- Trivial accept case (no statement sequence, or null statements).
6355 -- If the accept statement has declarations, then just insert them
6356 -- before the procedure call.
6358 elsif Trivial_Accept_OK
6359 and then (No (Stats) or else Null_Statements (Statements (Stats)))
6361 -- Remove declarations for renamings, because the parameter block
6362 -- will not be assigned.
6369 D := First (Declarations (N));
6370 while Present (D) loop
6372 if Nkind (D) = N_Object_Renaming_Declaration then
6380 if Present (Declarations (N)) then
6381 Insert_Actions (N, Declarations (N));
6385 Make_Procedure_Call_Statement (Loc,
6386 Name => New_Occurrence_Of (RTE (RE_Accept_Trivial), Loc),
6387 Parameter_Associations => New_List (
6388 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
6392 -- Discard Entry_Address that was created for it, so it will not be
6393 -- emitted if this accept statement is in the statement part of a
6394 -- delay alternative.
6396 if Present (Stats) then
6397 Remove_Last_Elmt (Acstack);
6400 -- Case of statement sequence present
6403 -- Construct the block, using the declarations from the accept
6404 -- statement if any to initialize the declarations of the block.
6406 Blkent := Make_Temporary (Loc, 'A');
6407 Set_Ekind (Blkent, E_Block);
6408 Set_Etype (Blkent, Standard_Void_Type);
6409 Set_Scope (Blkent, Current_Scope);
6412 Make_Block_Statement (Loc,
6413 Identifier => New_Occurrence_Of (Blkent, Loc),
6414 Declarations => Declarations (N),
6415 Handled_Statement_Sequence => Build_Accept_Body (N));
6417 -- For the analysis of the generated declarations, the parent node
6418 -- must be properly set.
6420 Set_Parent (Block, Parent (N));
6422 -- Prepend call to Accept_Call to main statement sequence If the
6423 -- accept has exception handlers, the statement sequence is wrapped
6424 -- in a block. Insert call and renaming declarations in the
6425 -- declarations of the block, so they are elaborated before the
6429 Make_Procedure_Call_Statement (Loc,
6430 Name => New_Occurrence_Of (RTE (RE_Accept_Call), Loc),
6431 Parameter_Associations => New_List (
6432 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
6433 New_Occurrence_Of (Ann, Loc)));
6435 if Parent (Stats) = N then
6436 Prepend (Call, Statements (Stats));
6438 Set_Declarations (Parent (Stats), New_List (Call));
6443 Push_Scope (Blkent);
6451 D := First (Declarations (N));
6452 while Present (D) loop
6455 if Nkind (D) = N_Object_Renaming_Declaration then
6457 -- The renaming declarations for the formals were created
6458 -- during analysis of the accept statement, and attached to
6459 -- the list of declarations. Place them now in the context
6460 -- of the accept block or subprogram.
6463 Typ := Entity (Subtype_Mark (D));
6464 Insert_After (Call, D);
6467 -- If the formal is class_wide, it does not have an actual
6468 -- subtype. The analysis of the renaming declaration creates
6469 -- one, but we need to retain the class-wide nature of the
6472 if Is_Class_Wide_Type (Typ) then
6473 Set_Etype (Defining_Identifier (D), Typ);
6484 -- Replace the accept statement by the new block
6489 -- Last step is to unstack the Accept_Address value
6491 Remove_Last_Elmt (Acstack);
6493 end Expand_N_Accept_Statement;
6495 ----------------------------------
6496 -- Expand_N_Asynchronous_Select --
6497 ----------------------------------
6499 -- This procedure assumes that the trigger statement is an entry call or
6500 -- a dispatching procedure call. A delay alternative should already have
6501 -- been expanded into an entry call to the appropriate delay object Wait
6504 -- If the trigger is a task entry call, the select is implemented with
6505 -- a Task_Entry_Call:
6510 -- P : parms := (parm, parm, parm);
6512 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6514 -- procedure _clean is
6517 -- Cancel_Task_Entry_Call (C);
6524 -- (<acceptor-task>, -- Acceptor
6525 -- <entry-index>, -- E
6526 -- P'Address, -- Uninterpreted_Data
6527 -- Asynchronous_Call, -- Mode
6528 -- B); -- Rendezvous_Successful
6535 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6538 -- when Abort_Signal => Abort_Undefer;
6545 -- <triggered-statements>
6549 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6550 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6554 -- P : parms := (parm, parm, parm);
6556 -- Call_Simple (acceptor-task, entry-index, P'Address);
6562 -- so the task at hand is to convert the latter expansion into the former
6564 -- If the trigger is a protected entry call, the select is implemented
6565 -- with Protected_Entry_Call:
6568 -- P : E1_Params := (param, param, param);
6569 -- Bnn : Communications_Block;
6574 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6576 -- procedure _clean is
6579 -- if Enqueued (Bnn) then
6580 -- Cancel_Protected_Entry_Call (Bnn);
6587 -- Protected_Entry_Call
6588 -- (po._object'Access, -- Object
6589 -- <entry index>, -- E
6590 -- P'Address, -- Uninterpreted_Data
6591 -- Asynchronous_Call, -- Mode
6594 -- if Enqueued (Bnn) then
6598 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6601 -- when Abort_Signal => Abort_Undefer;
6604 -- if not Cancelled (Bnn) then
6605 -- <triggered-statements>
6609 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6613 -- P : E1_Params := (param, param, param);
6614 -- Bnn : Communications_Block;
6617 -- Protected_Entry_Call
6618 -- (po._object'Access, -- Object
6619 -- <entry index>, -- E
6620 -- P'Address, -- Uninterpreted_Data
6621 -- Simple_Call, -- Mode
6628 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6632 -- B : Boolean := False;
6633 -- Bnn : Communication_Block;
6634 -- C : Ada.Tags.Prim_Op_Kind;
6635 -- D : System.Storage_Elements.Dummy_Communication_Block;
6636 -- K : Ada.Tags.Tagged_Kind :=
6637 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6638 -- P : Parameters := (Param1 .. ParamN);
6643 -- if K = Ada.Tags.TK_Limited_Tagged
6644 -- or else K = Ada.Tags.TK_Tagged
6646 -- <dispatching-call>;
6647 -- <triggering-statements>;
6651 -- Ada.Tags.Get_Offset_Index
6652 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6654 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6656 -- if C = POK_Protected_Entry then
6658 -- procedure _clean is
6660 -- if Enqueued (Bnn) then
6661 -- Cancel_Protected_Entry_Call (Bnn);
6667 -- _Disp_Asynchronous_Select
6668 -- (<object>, S, P'Address, D, B);
6669 -- Bnn := Communication_Block (D);
6671 -- Param1 := P.Param1;
6673 -- ParamN := P.ParamN;
6675 -- if Enqueued (Bnn) then
6676 -- <abortable-statements>
6679 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6682 -- when Abort_Signal => Abort_Undefer;
6685 -- if not Cancelled (Bnn) then
6686 -- <triggering-statements>
6689 -- elsif C = POK_Task_Entry then
6691 -- procedure _clean is
6693 -- Cancel_Task_Entry_Call (U);
6699 -- _Disp_Asynchronous_Select
6700 -- (<object>, S, P'Address, D, B);
6701 -- Bnn := Communication_Bloc (D);
6703 -- Param1 := P.Param1;
6705 -- ParamN := P.ParamN;
6710 -- <abortable-statements>
6712 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6715 -- when Abort_Signal => Abort_Undefer;
6719 -- <triggering-statements>
6724 -- <dispatching-call>;
6725 -- <triggering-statements>
6730 -- The job is to convert this to the asynchronous form
6732 -- If the trigger is a delay statement, it will have been expanded into
6733 -- a call to one of the GNARL delay procedures. This routine will convert
6734 -- this into a protected entry call on a delay object and then continue
6735 -- processing as for a protected entry call trigger. This requires
6736 -- declaring a Delay_Block object and adding a pointer to this object to
6737 -- the parameter list of the delay procedure to form the parameter list of
6738 -- the entry call. This object is used by the runtime to queue the delay
6741 -- For a description of the use of P and the assignments after the call,
6742 -- see Expand_N_Entry_Call_Statement.
6744 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
6745 Loc : constant Source_Ptr := Sloc (N);
6746 Abrt : constant Node_Id := Abortable_Part (N);
6747 Trig : constant Node_Id := Triggering_Alternative (N);
6749 Abort_Block_Ent : Entity_Id;
6750 Abortable_Block : Node_Id;
6753 Blk_Ent : constant Entity_Id := Make_Temporary (Loc, 'A');
6754 Blk_Typ : Entity_Id;
6756 Call_Ent : Entity_Id;
6757 Cancel_Param : Entity_Id;
6758 Cleanup_Block : Node_Id;
6759 Cleanup_Block_Ent : Entity_Id;
6760 Cleanup_Stmts : List_Id;
6761 Conc_Typ_Stmts : List_Id;
6763 Dblock_Ent : Entity_Id;
6768 Enqueue_Call : Node_Id;
6771 Handler_Stmt : Node_Id;
6773 Lim_Typ_Stmts : List_Id;
6779 ProtE_Stmts : List_Id;
6780 ProtP_Stmts : List_Id;
6783 TaskE_Stmts : List_Id;
6786 B : Entity_Id; -- Call status flag
6787 Bnn : Entity_Id; -- Communication block
6788 C : Entity_Id; -- Call kind
6789 K : Entity_Id; -- Tagged kind
6790 P : Entity_Id; -- Parameter block
6791 S : Entity_Id; -- Primitive operation slot
6792 T : Entity_Id; -- Additional status flag
6794 procedure Rewrite_Abortable_Part;
6795 -- If the trigger is a dispatching call, the expansion inserts multiple
6796 -- copies of the abortable part. This is both inefficient, and may lead
6797 -- to duplicate definitions that the back-end will reject, when the
6798 -- abortable part includes loops. This procedure rewrites the abortable
6799 -- part into a call to a generated procedure.
6801 ----------------------------
6802 -- Rewrite_Abortable_Part --
6803 ----------------------------
6805 procedure Rewrite_Abortable_Part is
6806 Proc : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
6811 Make_Subprogram_Body (Loc,
6813 Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc),
6814 Declarations => New_List,
6815 Handled_Statement_Sequence =>
6816 Make_Handled_Sequence_Of_Statements (Loc, Astats));
6817 Insert_Before (N, Decl);
6820 -- Rewrite abortable part into a call to this procedure
6824 Make_Procedure_Call_Statement (Loc,
6825 Name => New_Occurrence_Of (Proc, Loc)));
6826 end Rewrite_Abortable_Part;
6828 -- Start of processing for Expand_N_Asynchronous_Select
6831 -- Asynchronous select is not supported on restricted runtimes. Don't
6834 if Restricted_Profile then
6838 Process_Statements_For_Controlled_Objects (Trig);
6839 Process_Statements_For_Controlled_Objects (Abrt);
6841 Ecall := Triggering_Statement (Trig);
6843 Ensure_Statement_Present (Sloc (Ecall), Trig);
6845 -- Retrieve Astats and Tstats now because the finalization machinery may
6846 -- wrap them in blocks.
6848 Astats := Statements (Abrt);
6849 Tstats := Statements (Trig);
6851 -- The arguments in the call may require dynamic allocation, and the
6852 -- call statement may have been transformed into a block. The block
6853 -- may contain additional declarations for internal entities, and the
6854 -- original call is found by sequential search.
6856 if Nkind (Ecall) = N_Block_Statement then
6857 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
6858 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
6859 N_Entry_Call_Statement)
6865 -- This is either a dispatching call or a delay statement used as a
6866 -- trigger which was expanded into a procedure call.
6868 if Nkind (Ecall) = N_Procedure_Call_Statement then
6869 if Ada_Version >= Ada_2005
6871 (No (Original_Node (Ecall))
6872 or else not Nkind_In (Original_Node (Ecall),
6873 N_Delay_Relative_Statement,
6874 N_Delay_Until_Statement))
6876 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
6878 Rewrite_Abortable_Part;
6882 -- Call status flag processing, generate:
6883 -- B : Boolean := False;
6885 B := Build_B (Loc, Decls);
6887 -- Communication block processing, generate:
6888 -- Bnn : Communication_Block;
6890 Bnn := Make_Temporary (Loc, 'B');
6892 Make_Object_Declaration (Loc,
6893 Defining_Identifier => Bnn,
6894 Object_Definition =>
6895 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
6897 -- Call kind processing, generate:
6898 -- C : Ada.Tags.Prim_Op_Kind;
6900 C := Build_C (Loc, Decls);
6902 -- Tagged kind processing, generate:
6903 -- K : Ada.Tags.Tagged_Kind :=
6904 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6906 -- Dummy communication block, generate:
6907 -- D : Dummy_Communication_Block;
6910 Make_Object_Declaration (Loc,
6911 Defining_Identifier =>
6912 Make_Defining_Identifier (Loc, Name_uD),
6913 Object_Definition =>
6915 (RTE (RE_Dummy_Communication_Block), Loc)));
6917 K := Build_K (Loc, Decls, Obj);
6919 -- Parameter block processing
6921 Blk_Typ := Build_Parameter_Block
6922 (Loc, Actuals, Formals, Decls);
6923 P := Parameter_Block_Pack
6924 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6926 -- Dispatch table slot processing, generate:
6929 S := Build_S (Loc, Decls);
6931 -- Additional status flag processing, generate:
6934 T := Make_Temporary (Loc, 'T');
6936 Make_Object_Declaration (Loc,
6937 Defining_Identifier => T,
6938 Object_Definition =>
6939 New_Occurrence_Of (Standard_Boolean, Loc)));
6941 ------------------------------
6942 -- Protected entry handling --
6943 ------------------------------
6946 -- Param1 := P.Param1;
6948 -- ParamN := P.ParamN;
6950 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6953 -- Bnn := Communication_Block (D);
6955 Prepend_To (Cleanup_Stmts,
6956 Make_Assignment_Statement (Loc,
6957 Name => New_Occurrence_Of (Bnn, Loc),
6959 Make_Unchecked_Type_Conversion (Loc,
6961 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
6962 Expression => Make_Identifier (Loc, Name_uD))));
6965 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6967 Prepend_To (Cleanup_Stmts,
6968 Make_Procedure_Call_Statement (Loc,
6972 (Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select),
6974 Parameter_Associations =>
6976 New_Copy_Tree (Obj), -- <object>
6977 New_Occurrence_Of (S, Loc), -- S
6978 Make_Attribute_Reference (Loc, -- P'Address
6979 Prefix => New_Occurrence_Of (P, Loc),
6980 Attribute_Name => Name_Address),
6981 Make_Identifier (Loc, Name_uD), -- D
6982 New_Occurrence_Of (B, Loc)))); -- B
6985 -- if Enqueued (Bnn) then
6986 -- <abortable-statements>
6989 Append_To (Cleanup_Stmts,
6990 Make_Implicit_If_Statement (N,
6992 Make_Function_Call (Loc,
6994 New_Occurrence_Of (RTE (RE_Enqueued), Loc),
6995 Parameter_Associations =>
6996 New_List (New_Occurrence_Of (Bnn, Loc))),
6999 New_Copy_List_Tree (Astats)));
7001 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7002 -- will then generate a _clean for the communication block Bnn.
7006 -- procedure _clean is
7008 -- if Enqueued (Bnn) then
7009 -- Cancel_Protected_Entry_Call (Bnn);
7018 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7020 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
7022 -- Wrap the cleanup block in an exception handling block
7028 -- when Abort_Signal => Abort_Undefer;
7031 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7034 Make_Implicit_Label_Declaration (Loc,
7035 Defining_Identifier => Abort_Block_Ent),
7038 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7041 -- if not Cancelled (Bnn) then
7042 -- <triggering-statements>
7045 Append_To (ProtE_Stmts,
7046 Make_Implicit_If_Statement (N,
7050 Make_Function_Call (Loc,
7052 New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7053 Parameter_Associations =>
7054 New_List (New_Occurrence_Of (Bnn, Loc)))),
7057 New_Copy_List_Tree (Tstats)));
7059 -------------------------
7060 -- Task entry handling --
7061 -------------------------
7064 -- Param1 := P.Param1;
7066 -- ParamN := P.ParamN;
7068 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7071 -- Bnn := Communication_Block (D);
7073 Append_To (TaskE_Stmts,
7074 Make_Assignment_Statement (Loc,
7076 New_Occurrence_Of (Bnn, Loc),
7078 Make_Unchecked_Type_Conversion (Loc,
7080 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7081 Expression => Make_Identifier (Loc, Name_uD))));
7084 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7086 Prepend_To (TaskE_Stmts,
7087 Make_Procedure_Call_Statement (Loc,
7090 Find_Prim_Op (Etype (Etype (Obj)),
7091 Name_uDisp_Asynchronous_Select),
7094 Parameter_Associations => New_List (
7095 New_Copy_Tree (Obj), -- <object>
7096 New_Occurrence_Of (S, Loc), -- S
7097 Make_Attribute_Reference (Loc, -- P'Address
7098 Prefix => New_Occurrence_Of (P, Loc),
7099 Attribute_Name => Name_Address),
7100 Make_Identifier (Loc, Name_uD), -- D
7101 New_Occurrence_Of (B, Loc)))); -- B
7106 Prepend_To (TaskE_Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
7110 -- <abortable-statements>
7112 Cleanup_Stmts := New_Copy_List_Tree (Astats);
7115 (Cleanup_Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
7117 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7118 -- will generate a _clean for the additional status flag.
7122 -- procedure _clean is
7124 -- Cancel_Task_Entry_Call (U);
7132 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7134 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
7136 -- Wrap the cleanup block in an exception handling block
7142 -- when Abort_Signal => Abort_Undefer;
7145 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7147 Append_To (TaskE_Stmts,
7148 Make_Implicit_Label_Declaration (Loc,
7149 Defining_Identifier => Abort_Block_Ent));
7151 Append_To (TaskE_Stmts,
7153 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7157 -- <triggering-statements>
7160 Append_To (TaskE_Stmts,
7161 Make_Implicit_If_Statement (N,
7163 Make_Op_Not (Loc, Right_Opnd => New_Occurrence_Of (T, Loc)),
7166 New_Copy_List_Tree (Tstats)));
7168 ----------------------------------
7169 -- Protected procedure handling --
7170 ----------------------------------
7173 -- <dispatching-call>;
7174 -- <triggering-statements>
7176 ProtP_Stmts := New_Copy_List_Tree (Tstats);
7177 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
7180 -- S := Ada.Tags.Get_Offset_Index
7181 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7184 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7187 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7189 Append_To (Conc_Typ_Stmts,
7190 Make_Procedure_Call_Statement (Loc,
7193 (Find_Prim_Op (Etype (Etype (Obj)),
7194 Name_uDisp_Get_Prim_Op_Kind),
7196 Parameter_Associations =>
7198 New_Copy_Tree (Obj),
7199 New_Occurrence_Of (S, Loc),
7200 New_Occurrence_Of (C, Loc))));
7203 -- if C = POK_Procedure_Entry then
7205 -- elsif C = POK_Task_Entry then
7211 Append_To (Conc_Typ_Stmts,
7212 Make_Implicit_If_Statement (N,
7216 New_Occurrence_Of (C, Loc),
7218 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
7225 Make_Elsif_Part (Loc,
7229 New_Occurrence_Of (C, Loc),
7231 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc)),
7240 -- <dispatching-call>;
7241 -- <triggering-statements>
7243 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
7244 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
7247 -- if K = Ada.Tags.TK_Limited_Tagged
7248 -- or else K = Ada.Tags.TK_Tagged
7256 Make_Implicit_If_Statement (N,
7257 Condition => Build_Dispatching_Tag_Check (K, N),
7258 Then_Statements => Lim_Typ_Stmts,
7259 Else_Statements => Conc_Typ_Stmts));
7262 Make_Block_Statement (Loc,
7265 Handled_Statement_Sequence =>
7266 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7271 -- Delay triggering statement processing
7274 -- Add a Delay_Block object to the parameter list of the delay
7275 -- procedure to form the parameter list of the Wait entry call.
7277 Dblock_Ent := Make_Temporary (Loc, 'D');
7279 Pdef := Entity (Name (Ecall));
7281 if Is_RTE (Pdef, RO_CA_Delay_For) then
7283 New_Occurrence_Of (RTE (RE_Enqueue_Duration), Loc);
7285 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
7287 New_Occurrence_Of (RTE (RE_Enqueue_Calendar), Loc);
7289 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
7290 Enqueue_Call := New_Occurrence_Of (RTE (RE_Enqueue_RT), Loc);
7293 Append_To (Parameter_Associations (Ecall),
7294 Make_Attribute_Reference (Loc,
7295 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7296 Attribute_Name => Name_Unchecked_Access));
7298 -- Create the inner block to protect the abortable part
7300 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7302 Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer));
7305 Make_Block_Statement (Loc,
7306 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7307 Handled_Statement_Sequence =>
7308 Make_Handled_Sequence_Of_Statements (Loc,
7309 Statements => Astats),
7310 Has_Created_Identifier => True,
7311 Is_Asynchronous_Call_Block => True);
7313 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7316 Make_Implicit_If_Statement (N,
7318 Make_Function_Call (Loc,
7319 Name => Enqueue_Call,
7320 Parameter_Associations => Parameter_Associations (Ecall)),
7322 New_List (Make_Block_Statement (Loc,
7323 Handled_Statement_Sequence =>
7324 Make_Handled_Sequence_Of_Statements (Loc,
7325 Statements => New_List (
7326 Make_Implicit_Label_Declaration (Loc,
7327 Defining_Identifier => Blk_Ent,
7328 Label_Construct => Abortable_Block),
7330 Exception_Handlers => Hdle)))));
7332 Stmts := New_List (Ecall);
7334 -- Construct statement sequence for new block
7337 Make_Implicit_If_Statement (N,
7339 Make_Function_Call (Loc,
7340 Name => New_Occurrence_Of (
7341 RTE (RE_Timed_Out), Loc),
7342 Parameter_Associations => New_List (
7343 Make_Attribute_Reference (Loc,
7344 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7345 Attribute_Name => Name_Unchecked_Access))),
7346 Then_Statements => Tstats));
7348 -- The result is the new block
7350 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
7353 Make_Block_Statement (Loc,
7354 Declarations => New_List (
7355 Make_Object_Declaration (Loc,
7356 Defining_Identifier => Dblock_Ent,
7357 Aliased_Present => True,
7358 Object_Definition =>
7359 New_Occurrence_Of (RTE (RE_Delay_Block), Loc))),
7361 Handled_Statement_Sequence =>
7362 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7372 Extract_Entry (Ecall, Concval, Ename, Index);
7373 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
7375 Stmts := Statements (Handled_Statement_Sequence (Ecall));
7376 Decls := Declarations (Ecall);
7378 if Is_Protected_Type (Etype (Concval)) then
7380 -- Get the declarations of the block expanded from the entry call
7382 Decl := First (Decls);
7383 while Present (Decl)
7384 and then (Nkind (Decl) /= N_Object_Declaration
7385 or else not Is_RTE (Etype (Object_Definition (Decl)),
7386 RE_Communication_Block))
7391 pragma Assert (Present (Decl));
7392 Cancel_Param := Defining_Identifier (Decl);
7394 -- Change the mode of the Protected_Entry_Call call
7396 -- Protected_Entry_Call (
7397 -- Object => po._object'Access,
7398 -- E => <entry index>;
7399 -- Uninterpreted_Data => P'Address;
7400 -- Mode => Asynchronous_Call;
7403 -- Skip assignments to temporaries created for in-out parameters
7405 -- This makes unwarranted assumptions about the shape of the expanded
7406 -- tree for the call, and should be cleaned up ???
7408 Stmt := First (Stmts);
7409 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7415 Param := First (Parameter_Associations (Call));
7416 while Present (Param)
7417 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7422 pragma Assert (Present (Param));
7423 Rewrite (Param, New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7426 -- Append an if statement to execute the abortable part
7429 -- if Enqueued (Bnn) then
7432 Make_Implicit_If_Statement (N,
7434 Make_Function_Call (Loc,
7435 Name => New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7436 Parameter_Associations => New_List (
7437 New_Occurrence_Of (Cancel_Param, Loc))),
7438 Then_Statements => Astats));
7441 Make_Block_Statement (Loc,
7442 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7443 Handled_Statement_Sequence =>
7444 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts),
7445 Has_Created_Identifier => True,
7446 Is_Asynchronous_Call_Block => True);
7448 -- Aborts are not deferred at beginning of exception handlers in
7451 if ZCX_Exceptions then
7452 Handler_Stmt := Make_Null_Statement (Loc);
7455 Handler_Stmt := Build_Runtime_Call (Loc, RE_Abort_Undefer);
7459 Make_Block_Statement (Loc,
7460 Handled_Statement_Sequence =>
7461 Make_Handled_Sequence_Of_Statements (Loc,
7462 Statements => New_List (
7463 Make_Implicit_Label_Declaration (Loc,
7464 Defining_Identifier => Blk_Ent,
7465 Label_Construct => Abortable_Block),
7470 Exception_Handlers => New_List (
7471 Make_Implicit_Exception_Handler (Loc,
7473 -- when Abort_Signal =>
7474 -- Abort_Undefer.all;
7476 Exception_Choices =>
7477 New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)),
7478 Statements => New_List (Handler_Stmt))))),
7480 -- if not Cancelled (Bnn) then
7481 -- triggered statements
7484 Make_Implicit_If_Statement (N,
7485 Condition => Make_Op_Not (Loc,
7487 Make_Function_Call (Loc,
7488 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7489 Parameter_Associations => New_List (
7490 New_Occurrence_Of (Cancel_Param, Loc)))),
7491 Then_Statements => Tstats));
7493 -- Asynchronous task entry call
7500 B := Make_Defining_Identifier (Loc, Name_uB);
7502 -- Insert declaration of B in declarations of existing block
7505 Make_Object_Declaration (Loc,
7506 Defining_Identifier => B,
7507 Object_Definition =>
7508 New_Occurrence_Of (Standard_Boolean, Loc)));
7510 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
7512 -- Insert declaration of C in declarations of existing block
7515 Make_Object_Declaration (Loc,
7516 Defining_Identifier => Cancel_Param,
7517 Object_Definition =>
7518 New_Occurrence_Of (Standard_Boolean, Loc)));
7520 -- Remove and save the call to Call_Simple
7522 Stmt := First (Stmts);
7524 -- Skip assignments to temporaries created for in-out parameters.
7525 -- This makes unwarranted assumptions about the shape of the expanded
7526 -- tree for the call, and should be cleaned up ???
7528 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7534 -- Create the inner block to protect the abortable part
7536 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7538 Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer));
7541 Make_Block_Statement (Loc,
7542 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7543 Handled_Statement_Sequence =>
7544 Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats),
7545 Has_Created_Identifier => True,
7546 Is_Asynchronous_Call_Block => True);
7549 Make_Block_Statement (Loc,
7550 Handled_Statement_Sequence =>
7551 Make_Handled_Sequence_Of_Statements (Loc,
7552 Statements => New_List (
7553 Make_Implicit_Label_Declaration (Loc,
7554 Defining_Identifier => Blk_Ent,
7555 Label_Construct => Abortable_Block),
7557 Exception_Handlers => Hdle)));
7559 -- Create new call statement
7561 Params := Parameter_Associations (Call);
7564 New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7565 Append_To (Params, New_Occurrence_Of (B, Loc));
7568 Make_Procedure_Call_Statement (Loc,
7569 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
7570 Parameter_Associations => Params));
7572 -- Construct statement sequence for new block
7575 Make_Implicit_If_Statement (N,
7577 Make_Op_Not (Loc, New_Occurrence_Of (Cancel_Param, Loc)),
7578 Then_Statements => Tstats));
7580 -- Protected the call against abort
7582 Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
7585 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
7587 -- The result is the new block
7590 Make_Block_Statement (Loc,
7591 Declarations => Decls,
7592 Handled_Statement_Sequence =>
7593 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7596 end Expand_N_Asynchronous_Select;
7598 -------------------------------------
7599 -- Expand_N_Conditional_Entry_Call --
7600 -------------------------------------
7602 -- The conditional task entry call is converted to a call to
7607 -- P : parms := (parm, parm, parm);
7611 -- (<acceptor-task>, -- Acceptor
7612 -- <entry-index>, -- E
7613 -- P'Address, -- Uninterpreted_Data
7614 -- Conditional_Call, -- Mode
7615 -- B); -- Rendezvous_Successful
7620 -- normal-statements
7626 -- For a description of the use of P and the assignments after the call,
7627 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7628 -- conditional entry call has already been expanded (by the Expand_N_Entry
7629 -- _Call_Statement procedure) as follows:
7632 -- P : parms := (parm, parm, parm);
7634 -- ... info for in-out parameters
7635 -- Call_Simple (acceptor-task, entry-index, P'Address);
7641 -- so the task at hand is to convert the latter expansion into the former
7643 -- The conditional protected entry call is converted to a call to
7644 -- Protected_Entry_Call:
7647 -- P : parms := (parm, parm, parm);
7648 -- Bnn : Communications_Block;
7651 -- Protected_Entry_Call
7652 -- (po._object'Access, -- Object
7653 -- <entry index>, -- E
7654 -- P'Address, -- Uninterpreted_Data
7655 -- Conditional_Call, -- Mode
7660 -- if Cancelled (Bnn) then
7663 -- normal-statements
7667 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7671 -- B : Boolean := False;
7672 -- C : Ada.Tags.Prim_Op_Kind;
7673 -- K : Ada.Tags.Tagged_Kind :=
7674 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7675 -- P : Parameters := (Param1 .. ParamN);
7679 -- if K = Ada.Tags.TK_Limited_Tagged
7680 -- or else K = Ada.Tags.TK_Tagged
7682 -- <dispatching-call>;
7683 -- <triggering-statements>
7687 -- Ada.Tags.Get_Offset_Index
7688 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7690 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7692 -- if C = POK_Protected_Entry
7693 -- or else C = POK_Task_Entry
7695 -- Param1 := P.Param1;
7697 -- ParamN := P.ParamN;
7701 -- if C = POK_Procedure
7702 -- or else C = POK_Protected_Procedure
7703 -- or else C = POK_Task_Procedure
7705 -- <dispatching-call>;
7708 -- <triggering-statements>
7710 -- <else-statements>
7715 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
7716 Loc : constant Source_Ptr := Sloc (N);
7717 Alt : constant Node_Id := Entry_Call_Alternative (N);
7718 Blk : Node_Id := Entry_Call_Statement (Alt);
7721 Blk_Typ : Entity_Id;
7723 Call_Ent : Entity_Id;
7724 Conc_Typ_Stmts : List_Id;
7728 Lim_Typ_Stmts : List_Id;
7735 Transient_Blk : Node_Id;
7738 B : Entity_Id; -- Call status flag
7739 C : Entity_Id; -- Call kind
7740 K : Entity_Id; -- Tagged kind
7741 P : Entity_Id; -- Parameter block
7742 S : Entity_Id; -- Primitive operation slot
7745 Process_Statements_For_Controlled_Objects (N);
7747 if Ada_Version >= Ada_2005
7748 and then Nkind (Blk) = N_Procedure_Call_Statement
7750 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7755 -- Call status flag processing, generate:
7756 -- B : Boolean := False;
7758 B := Build_B (Loc, Decls);
7760 -- Call kind processing, generate:
7761 -- C : Ada.Tags.Prim_Op_Kind;
7763 C := Build_C (Loc, Decls);
7765 -- Tagged kind processing, generate:
7766 -- K : Ada.Tags.Tagged_Kind :=
7767 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7769 K := Build_K (Loc, Decls, Obj);
7771 -- Parameter block processing
7773 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7774 P := Parameter_Block_Pack
7775 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7777 -- Dispatch table slot processing, generate:
7780 S := Build_S (Loc, Decls);
7783 -- S := Ada.Tags.Get_Offset_Index
7784 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7787 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7790 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7792 Append_To (Conc_Typ_Stmts,
7793 Make_Procedure_Call_Statement (Loc,
7796 Find_Prim_Op (Etype (Etype (Obj)),
7797 Name_uDisp_Conditional_Select),
7799 Parameter_Associations =>
7801 New_Copy_Tree (Obj), -- <object>
7802 New_Occurrence_Of (S, Loc), -- S
7803 Make_Attribute_Reference (Loc, -- P'Address
7804 Prefix => New_Occurrence_Of (P, Loc),
7805 Attribute_Name => Name_Address),
7806 New_Occurrence_Of (C, Loc), -- C
7807 New_Occurrence_Of (B, Loc)))); -- B
7810 -- if C = POK_Protected_Entry
7811 -- or else C = POK_Task_Entry
7813 -- Param1 := P.Param1;
7815 -- ParamN := P.ParamN;
7818 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7820 -- Generate the if statement only when the packed parameters need
7821 -- explicit assignments to their corresponding actuals.
7823 if Present (Unpack) then
7824 Append_To (Conc_Typ_Stmts,
7825 Make_Implicit_If_Statement (N,
7831 New_Occurrence_Of (C, Loc),
7833 New_Occurrence_Of (RTE (
7834 RE_POK_Protected_Entry), Loc)),
7839 New_Occurrence_Of (C, Loc),
7841 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
7843 Then_Statements => Unpack));
7848 -- if C = POK_Procedure
7849 -- or else C = POK_Protected_Procedure
7850 -- or else C = POK_Task_Procedure
7852 -- <dispatching-call>
7854 -- <normal-statements>
7856 -- <else-statements>
7859 N_Stats := New_Copy_List_Tree (Statements (Alt));
7861 Prepend_To (N_Stats,
7862 Make_Implicit_If_Statement (N,
7868 New_Occurrence_Of (C, Loc),
7870 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
7877 New_Occurrence_Of (C, Loc),
7879 New_Occurrence_Of (RTE (
7880 RE_POK_Protected_Procedure), Loc)),
7885 New_Occurrence_Of (C, Loc),
7887 New_Occurrence_Of (RTE (
7888 RE_POK_Task_Procedure), Loc)))),
7893 Append_To (Conc_Typ_Stmts,
7894 Make_Implicit_If_Statement (N,
7895 Condition => New_Occurrence_Of (B, Loc),
7896 Then_Statements => N_Stats,
7897 Else_Statements => Else_Statements (N)));
7900 -- <dispatching-call>;
7901 -- <triggering-statements>
7903 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
7904 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
7907 -- if K = Ada.Tags.TK_Limited_Tagged
7908 -- or else K = Ada.Tags.TK_Tagged
7916 Make_Implicit_If_Statement (N,
7917 Condition => Build_Dispatching_Tag_Check (K, N),
7918 Then_Statements => Lim_Typ_Stmts,
7919 Else_Statements => Conc_Typ_Stmts));
7922 Make_Block_Statement (Loc,
7925 Handled_Statement_Sequence =>
7926 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7928 -- As described above, the entry alternative is transformed into a
7929 -- block that contains the gnulli call, and possibly assignment
7930 -- statements for in-out parameters. The gnulli call may itself be
7931 -- rewritten into a transient block if some unconstrained parameters
7932 -- require it. We need to retrieve the call to complete its parameter
7937 First_Real_Statement (Handled_Statement_Sequence (Blk));
7939 if Present (Transient_Blk)
7940 and then Nkind (Transient_Blk) = N_Block_Statement
7942 Blk := Transient_Blk;
7945 Stmts := Statements (Handled_Statement_Sequence (Blk));
7946 Stmt := First (Stmts);
7947 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7952 Params := Parameter_Associations (Call);
7954 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7956 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7958 Param := First (Params);
7959 while Present (Param)
7960 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7965 pragma Assert (Present (Param));
7967 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
7971 -- Find the Communication_Block parameter for the call to the
7972 -- Cancelled function.
7974 Decl := First (Declarations (Blk));
7975 while Present (Decl)
7976 and then not Is_RTE (Etype (Object_Definition (Decl)),
7977 RE_Communication_Block)
7982 -- Add an if statement to execute the else part if the call
7983 -- does not succeed (as indicated by the Cancelled predicate).
7986 Make_Implicit_If_Statement (N,
7987 Condition => Make_Function_Call (Loc,
7988 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7989 Parameter_Associations => New_List (
7990 New_Occurrence_Of (Defining_Identifier (Decl), Loc))),
7991 Then_Statements => Else_Statements (N),
7992 Else_Statements => Statements (Alt)));
7995 B := Make_Defining_Identifier (Loc, Name_uB);
7997 -- Insert declaration of B in declarations of existing block
7999 if No (Declarations (Blk)) then
8000 Set_Declarations (Blk, New_List);
8003 Prepend_To (Declarations (Blk),
8004 Make_Object_Declaration (Loc,
8005 Defining_Identifier => B,
8006 Object_Definition =>
8007 New_Occurrence_Of (Standard_Boolean, Loc)));
8009 -- Create new call statement
8012 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
8013 Append_To (Params, New_Occurrence_Of (B, Loc));
8016 Make_Procedure_Call_Statement (Loc,
8017 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
8018 Parameter_Associations => Params));
8020 -- Construct statement sequence for new block
8023 Make_Implicit_If_Statement (N,
8024 Condition => New_Occurrence_Of (B, Loc),
8025 Then_Statements => Statements (Alt),
8026 Else_Statements => Else_Statements (N)));
8029 -- The result is the new block
8032 Make_Block_Statement (Loc,
8033 Declarations => Declarations (Blk),
8034 Handled_Statement_Sequence =>
8035 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8039 end Expand_N_Conditional_Entry_Call;
8041 ---------------------------------------
8042 -- Expand_N_Delay_Relative_Statement --
8043 ---------------------------------------
8045 -- Delay statement is implemented as a procedure call to Delay_For
8046 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8047 -- simple delays imposed by the use of Protected Objects.
8049 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
8050 Loc : constant Source_Ptr := Sloc (N);
8054 -- Try to use System.Relative_Delays.Delay_For only if available. This
8055 -- is the implementation used on restricted platforms when Ada.Calendar
8056 -- is not available.
8058 if RTE_Available (RO_RD_Delay_For) then
8059 Proc := RTE (RO_RD_Delay_For);
8061 -- Otherwise, use Ada.Calendar.Delays.Delay_For and emit an error
8062 -- message if not available.
8065 Proc := RTE (RO_CA_Delay_For);
8069 Make_Procedure_Call_Statement (Loc,
8070 Name => New_Occurrence_Of (Proc, Loc),
8071 Parameter_Associations => New_List (Expression (N))));
8073 end Expand_N_Delay_Relative_Statement;
8075 ------------------------------------
8076 -- Expand_N_Delay_Until_Statement --
8077 ------------------------------------
8079 -- Delay Until statement is implemented as a procedure call to
8080 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8082 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
8083 Loc : constant Source_Ptr := Sloc (N);
8087 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
8088 Typ := RTE (RO_CA_Delay_Until);
8090 Typ := RTE (RO_RT_Delay_Until);
8094 Make_Procedure_Call_Statement (Loc,
8095 Name => New_Occurrence_Of (Typ, Loc),
8096 Parameter_Associations => New_List (Expression (N))));
8099 end Expand_N_Delay_Until_Statement;
8101 -------------------------
8102 -- Expand_N_Entry_Body --
8103 -------------------------
8105 procedure Expand_N_Entry_Body (N : Node_Id) is
8107 -- Associate discriminals with the next protected operation body to be
8110 if Present (Next_Protected_Operation (N)) then
8111 Set_Discriminals (Parent (Current_Scope));
8113 end Expand_N_Entry_Body;
8115 -----------------------------------
8116 -- Expand_N_Entry_Call_Statement --
8117 -----------------------------------
8119 -- An entry call is expanded into GNARLI calls to implement a simple entry
8120 -- call (see Build_Simple_Entry_Call).
8122 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
8128 if No_Run_Time_Mode then
8129 Error_Msg_CRT ("entry call", N);
8133 -- If this entry call is part of an asynchronous select, don't expand it
8134 -- here; it will be expanded with the select statement. Don't expand
8135 -- timed entry calls either, as they are translated into asynchronous
8138 -- ??? This whole approach is questionable; it may be better to go back
8139 -- to allowing the expansion to take place and then attempting to fix it
8140 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8141 -- whether the expanded call is on a task or protected entry.
8143 if (Nkind (Parent (N)) /= N_Triggering_Alternative
8144 or else N /= Triggering_Statement (Parent (N)))
8145 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
8146 or else N /= Entry_Call_Statement (Parent (N))
8147 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
8149 Extract_Entry (N, Concval, Ename, Index);
8150 Build_Simple_Entry_Call (N, Concval, Ename, Index);
8152 end Expand_N_Entry_Call_Statement;
8154 --------------------------------
8155 -- Expand_N_Entry_Declaration --
8156 --------------------------------
8158 -- If there are parameters, then first, each of the formals is marked by
8159 -- setting Is_Entry_Formal. Next a record type is built which is used to
8160 -- hold the parameter values. The name of this record type is entryP where
8161 -- entry is the name of the entry, with an additional corresponding access
8162 -- type called entryPA. The record type has matching components for each
8163 -- formal (the component names are the same as the formal names). For
8164 -- elementary types, the component type matches the formal type. For
8165 -- composite types, an access type is declared (with the name formalA)
8166 -- which designates the formal type, and the type of the component is this
8167 -- access type. Finally the Entry_Component of each formal is set to
8168 -- reference the corresponding record component.
8170 procedure Expand_N_Entry_Declaration (N : Node_Id) is
8171 Loc : constant Source_Ptr := Sloc (N);
8172 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
8173 Components : List_Id;
8176 Last_Decl : Node_Id;
8177 Component : Entity_Id;
8180 Rec_Ent : Entity_Id;
8181 Acc_Ent : Entity_Id;
8184 Formal := First_Formal (Entry_Ent);
8187 -- Most processing is done only if parameters are present
8189 if Present (Formal) then
8190 Components := New_List;
8192 -- Loop through formals
8194 while Present (Formal) loop
8195 Set_Is_Entry_Formal (Formal);
8197 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
8198 Set_Entry_Component (Formal, Component);
8199 Set_Entry_Formal (Component, Formal);
8200 Ftype := Etype (Formal);
8202 -- Declare new access type and then append
8204 Ctype := Make_Temporary (Loc, 'A');
8205 Set_Is_Param_Block_Component_Type (Ctype);
8208 Make_Full_Type_Declaration (Loc,
8209 Defining_Identifier => Ctype,
8211 Make_Access_To_Object_Definition (Loc,
8212 All_Present => True,
8213 Constant_Present => Ekind (Formal) = E_In_Parameter,
8214 Subtype_Indication => New_Occurrence_Of (Ftype, Loc)));
8216 Insert_After (Last_Decl, Decl);
8219 Append_To (Components,
8220 Make_Component_Declaration (Loc,
8221 Defining_Identifier => Component,
8222 Component_Definition =>
8223 Make_Component_Definition (Loc,
8224 Aliased_Present => False,
8225 Subtype_Indication => New_Occurrence_Of (Ctype, Loc))));
8227 Next_Formal_With_Extras (Formal);
8230 -- Create the Entry_Parameter_Record declaration
8232 Rec_Ent := Make_Temporary (Loc, 'P');
8235 Make_Full_Type_Declaration (Loc,
8236 Defining_Identifier => Rec_Ent,
8238 Make_Record_Definition (Loc,
8240 Make_Component_List (Loc,
8241 Component_Items => Components)));
8243 Insert_After (Last_Decl, Decl);
8246 -- Construct and link in the corresponding access type
8248 Acc_Ent := Make_Temporary (Loc, 'A');
8250 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
8253 Make_Full_Type_Declaration (Loc,
8254 Defining_Identifier => Acc_Ent,
8256 Make_Access_To_Object_Definition (Loc,
8257 All_Present => True,
8258 Subtype_Indication => New_Occurrence_Of (Rec_Ent, Loc)));
8260 Insert_After (Last_Decl, Decl);
8262 end Expand_N_Entry_Declaration;
8264 -----------------------------
8265 -- Expand_N_Protected_Body --
8266 -----------------------------
8268 -- Protected bodies are expanded to the completion of the subprograms
8269 -- created for the corresponding protected type. These are a protected and
8270 -- unprotected version of each protected subprogram in the object, a
8271 -- function to calculate each entry barrier, and a procedure to execute the
8272 -- sequence of statements of each protected entry body. For example, for
8273 -- protected type ptype:
8276 -- (O : System.Address;
8277 -- E : Protected_Entry_Index)
8280 -- <discriminant renamings>
8281 -- <private object renamings>
8283 -- return <barrier expression>;
8286 -- procedure pprocN (_object : in out poV;...) is
8287 -- <discriminant renamings>
8288 -- <private object renamings>
8290 -- <sequence of statements>
8293 -- procedure pprocP (_object : in out poV;...) is
8294 -- procedure _clean is
8297 -- ptypeS (_object, Pn);
8298 -- Unlock (_object._object'Access);
8299 -- Abort_Undefer.all;
8304 -- Lock (_object._object'Access);
8305 -- pprocN (_object;...);
8310 -- function pfuncN (_object : poV;...) return Return_Type is
8311 -- <discriminant renamings>
8312 -- <private object renamings>
8314 -- <sequence of statements>
8317 -- function pfuncP (_object : poV) return Return_Type is
8318 -- procedure _clean is
8320 -- Unlock (_object._object'Access);
8321 -- Abort_Undefer.all;
8326 -- Lock (_object._object'Access);
8327 -- return pfuncN (_object);
8334 -- (O : System.Address;
8335 -- P : System.Address;
8336 -- E : Protected_Entry_Index)
8338 -- <discriminant renamings>
8339 -- <private object renamings>
8340 -- type poVP is access poV;
8341 -- _Object : ptVP := ptVP!(O);
8345 -- <statement sequence>
8346 -- Complete_Entry_Body (_Object._Object);
8348 -- when all others =>
8349 -- Exceptional_Complete_Entry_Body (
8350 -- _Object._Object, Get_GNAT_Exception);
8354 -- The type poV is the record created for the protected type to hold
8355 -- the state of the protected object.
8357 procedure Expand_N_Protected_Body (N : Node_Id) is
8358 Loc : constant Source_Ptr := Sloc (N);
8359 Pid : constant Entity_Id := Corresponding_Spec (N);
8361 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Pid);
8362 -- This flag indicates whether the lock free implementation is active
8364 Current_Node : Node_Id;
8365 Disp_Op_Body : Node_Id;
8366 New_Op_Body : Node_Id;
8370 function Build_Dispatching_Subprogram_Body
8373 Prot_Bod : Node_Id) return Node_Id;
8374 -- Build a dispatching version of the protected subprogram body. The
8375 -- newly generated subprogram contains a call to the original protected
8376 -- body. The following code is generated:
8378 -- function <protected-function-name> (Param1 .. ParamN) return
8381 -- return <protected-function-name>P (Param1 .. ParamN);
8382 -- end <protected-function-name>;
8386 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8388 -- <protected-procedure-name>P (Param1 .. ParamN);
8389 -- end <protected-procedure-name>
8391 ---------------------------------------
8392 -- Build_Dispatching_Subprogram_Body --
8393 ---------------------------------------
8395 function Build_Dispatching_Subprogram_Body
8398 Prot_Bod : Node_Id) return Node_Id
8400 Loc : constant Source_Ptr := Sloc (N);
8407 -- Generate a specification without a letter suffix in order to
8408 -- override an interface function or procedure.
8410 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
8412 -- The formal parameters become the actuals of the protected function
8413 -- or procedure call.
8415 Actuals := New_List;
8416 Formal := First (Parameter_Specifications (Spec));
8417 while Present (Formal) loop
8419 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8423 if Nkind (Spec) = N_Procedure_Specification then
8426 Make_Procedure_Call_Statement (Loc,
8428 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8429 Parameter_Associations => Actuals));
8432 pragma Assert (Nkind (Spec) = N_Function_Specification);
8436 Make_Simple_Return_Statement (Loc,
8438 Make_Function_Call (Loc,
8440 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8441 Parameter_Associations => Actuals)));
8445 Make_Subprogram_Body (Loc,
8446 Declarations => Empty_List,
8447 Specification => Spec,
8448 Handled_Statement_Sequence =>
8449 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
8450 end Build_Dispatching_Subprogram_Body;
8452 -- Start of processing for Expand_N_Protected_Body
8455 if No_Run_Time_Mode then
8456 Error_Msg_CRT ("protected body", N);
8460 -- This is the proper body corresponding to a stub. The declarations
8461 -- must be inserted at the point of the stub, which in turn is in the
8462 -- declarative part of the parent unit.
8464 if Nkind (Parent (N)) = N_Subunit then
8465 Current_Node := Corresponding_Stub (Parent (N));
8470 Op_Body := First (Declarations (N));
8472 -- The protected body is replaced with the bodies of its
8473 -- protected operations, and the declarations for internal objects
8474 -- that may have been created for entry family bounds.
8476 Rewrite (N, Make_Null_Statement (Sloc (N)));
8479 while Present (Op_Body) loop
8480 case Nkind (Op_Body) is
8481 when N_Subprogram_Declaration =>
8484 when N_Subprogram_Body =>
8486 -- Do not create bodies for eliminated operations
8488 if not Is_Eliminated (Defining_Entity (Op_Body))
8489 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
8491 if Lock_Free_Active then
8493 Build_Lock_Free_Unprotected_Subprogram_Body
8497 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
8500 Insert_After (Current_Node, New_Op_Body);
8501 Current_Node := New_Op_Body;
8502 Analyze (New_Op_Body);
8504 -- Build the corresponding protected operation. It may
8505 -- appear that this is needed only if this is a visible
8506 -- operation of the type, or if it is an interrupt handler,
8507 -- and this was the strategy used previously in GNAT.
8509 -- However, the operation may be exported through a 'Access
8510 -- to an external caller. This is the common idiom in code
8511 -- that uses the Ada 2005 Timing_Events package. As a result
8512 -- we need to produce the protected body for both visible
8513 -- and private operations, as well as operations that only
8514 -- have a body in the source, and for which we create a
8515 -- declaration in the protected body itself.
8517 if Present (Corresponding_Spec (Op_Body)) then
8518 if Lock_Free_Active then
8520 Build_Lock_Free_Protected_Subprogram_Body
8521 (Op_Body, Pid, Specification (New_Op_Body));
8524 Build_Protected_Subprogram_Body
8525 (Op_Body, Pid, Specification (New_Op_Body));
8528 Insert_After (Current_Node, New_Op_Body);
8529 Analyze (New_Op_Body);
8531 Current_Node := New_Op_Body;
8533 -- Generate an overriding primitive operation body for
8534 -- this subprogram if the protected type implements an
8537 if Ada_Version >= Ada_2005
8539 Present (Interfaces (Corresponding_Record_Type (Pid)))
8542 Build_Dispatching_Subprogram_Body
8543 (Op_Body, Pid, New_Op_Body);
8545 Insert_After (Current_Node, Disp_Op_Body);
8546 Analyze (Disp_Op_Body);
8548 Current_Node := Disp_Op_Body;
8553 when N_Entry_Body =>
8554 Op_Id := Defining_Identifier (Op_Body);
8555 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
8557 Insert_After (Current_Node, New_Op_Body);
8558 Current_Node := New_Op_Body;
8559 Analyze (New_Op_Body);
8561 when N_Implicit_Label_Declaration =>
8564 when N_Itype_Reference =>
8565 Insert_After (Current_Node, New_Copy (Op_Body));
8567 when N_Freeze_Entity =>
8568 New_Op_Body := New_Copy (Op_Body);
8570 if Present (Entity (Op_Body))
8571 and then Freeze_Node (Entity (Op_Body)) = Op_Body
8573 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
8576 Insert_After (Current_Node, New_Op_Body);
8577 Current_Node := New_Op_Body;
8578 Analyze (New_Op_Body);
8581 New_Op_Body := New_Copy (Op_Body);
8582 Insert_After (Current_Node, New_Op_Body);
8583 Current_Node := New_Op_Body;
8584 Analyze (New_Op_Body);
8586 when N_Object_Declaration =>
8587 pragma Assert (not Comes_From_Source (Op_Body));
8588 New_Op_Body := New_Copy (Op_Body);
8589 Insert_After (Current_Node, New_Op_Body);
8590 Current_Node := New_Op_Body;
8591 Analyze (New_Op_Body);
8594 raise Program_Error;
8600 -- Finally, create the body of the function that maps an entry index
8601 -- into the corresponding body index, except when there is no entry, or
8602 -- in a Ravenscar-like profile.
8604 if Corresponding_Runtime_Package (Pid) =
8605 System_Tasking_Protected_Objects_Entries
8607 New_Op_Body := Build_Find_Body_Index (Pid);
8608 Insert_After (Current_Node, New_Op_Body);
8609 Current_Node := New_Op_Body;
8610 Analyze (New_Op_Body);
8613 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8614 -- protected body. At this point all wrapper specs have been created,
8615 -- frozen and included in the dispatch table for the protected type.
8617 if Ada_Version >= Ada_2005 then
8618 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
8620 end Expand_N_Protected_Body;
8622 -----------------------------------------
8623 -- Expand_N_Protected_Type_Declaration --
8624 -----------------------------------------
8626 -- First we create a corresponding record type declaration used to
8627 -- represent values of this protected type.
8628 -- The general form of this type declaration is
8630 -- type poV (discriminants) is record
8631 -- _Object : aliased <kind>Protection
8632 -- [(<entry count> [, <handler count>])];
8633 -- [entry_family : array (bounds) of Void;]
8634 -- <private data fields>
8637 -- The discriminants are present only if the corresponding protected type
8638 -- has discriminants, and they exactly mirror the protected type
8639 -- discriminants. The private data fields similarly mirror the private
8640 -- declarations of the protected type.
8642 -- The Object field is always present. It contains RTS specific data used
8643 -- to control the protected object. It is declared as Aliased so that it
8644 -- can be passed as a pointer to the RTS. This allows the protected record
8645 -- to be referenced within RTS data structures. An appropriate Protection
8646 -- type and discriminant are generated.
8648 -- The Service field is present for protected objects with entries. It
8649 -- contains sufficient information to allow the entry service procedure for
8650 -- this object to be called when the object is not known till runtime.
8652 -- One entry_family component is present for each entry family in the
8653 -- task definition (see Expand_N_Task_Type_Declaration).
8655 -- When a protected object is declared, an instance of the protected type
8656 -- value record is created. The elaboration of this declaration creates the
8657 -- correct bounds for the entry families, and also evaluates the priority
8658 -- expression if needed. The initialization routine for the protected type
8659 -- itself then calls Initialize_Protection with appropriate parameters to
8660 -- initialize the value of the Task_Id field. Install_Handlers may be also
8661 -- called if a pragma Attach_Handler applies.
8663 -- Note: this record is passed to the subprograms created by the expansion
8664 -- of protected subprograms and entries. It is an in parameter to protected
8665 -- functions and an in out parameter to procedures and entry bodies. The
8666 -- Entity_Id for this created record type is placed in the
8667 -- Corresponding_Record_Type field of the associated protected type entity.
8669 -- Next we create a procedure specifications for protected subprograms and
8670 -- entry bodies. For each protected subprograms two subprograms are
8671 -- created, an unprotected and a protected version. The unprotected version
8672 -- is called from within other operations of the same protected object.
8674 -- We also build the call to register the procedure if a pragma
8675 -- Interrupt_Handler applies.
8677 -- A single subprogram is created to service all entry bodies; it has an
8678 -- additional boolean out parameter indicating that the previous entry call
8679 -- made by the current task was serviced immediately, i.e. not by proxy.
8680 -- The O parameter contains a pointer to a record object of the type
8681 -- described above. An untyped interface is used here to allow this
8682 -- procedure to be called in places where the type of the object to be
8683 -- serviced is not known. This must be done, for example, when a call that
8684 -- may have been requeued is cancelled; the corresponding object must be
8685 -- serviced, but which object that is not known till runtime.
8688 -- (O : System.Address; P : out Boolean);
8689 -- procedure pprocN (_object : in out poV);
8690 -- procedure pproc (_object : in out poV);
8691 -- function pfuncN (_object : poV);
8692 -- function pfunc (_object : poV);
8695 -- Note that this must come after the record type declaration, since
8696 -- the specs refer to this type.
8698 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
8699 Discr_Map : constant Elist_Id := New_Elmt_List;
8700 Loc : constant Source_Ptr := Sloc (N);
8701 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
8703 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Prot_Typ);
8704 -- This flag indicates whether the lock free implementation is active
8706 Pdef : constant Node_Id := Protected_Definition (N);
8707 -- This contains two lists; one for visible and one for private decls
8709 Current_Node : Node_Id := N;
8711 Entries_Aggr : Node_Id;
8713 procedure Check_Inlining (Subp : Entity_Id);
8714 -- If the original operation has a pragma Inline, propagate the flag
8715 -- to the internal body, for possible inlining later on. The source
8716 -- operation is invisible to the back-end and is never actually called.
8718 function Discriminated_Size (Comp : Entity_Id) return Boolean;
8719 -- If a component size is not static then a warning will be emitted
8720 -- in Ravenscar or other restricted contexts. When a component is non-
8721 -- static because of a discriminant constraint we can specialize the
8722 -- warning by mentioning discriminants explicitly.
8724 procedure Expand_Entry_Declaration (Decl : Node_Id);
8725 -- Create the entry barrier and the procedure body for entry declaration
8726 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8728 function Static_Component_Size (Comp : Entity_Id) return Boolean;
8729 -- When compiling under the Ravenscar profile, private components must
8730 -- have a static size, or else a protected object will require heap
8731 -- allocation, violating the corresponding restriction. It is preferable
8732 -- to make this check here, because it provides a better error message
8733 -- than the back-end, which refers to the object as a whole.
8735 procedure Register_Handler;
8736 -- For a protected operation that is an interrupt handler, add the
8737 -- freeze action that will register it as such.
8739 --------------------
8740 -- Check_Inlining --
8741 --------------------
8743 procedure Check_Inlining (Subp : Entity_Id) is
8745 if Is_Inlined (Subp) then
8746 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8747 Set_Is_Inlined (Subp, False);
8751 ------------------------
8752 -- Discriminated_Size --
8753 ------------------------
8755 function Discriminated_Size (Comp : Entity_Id) return Boolean is
8756 Typ : constant Entity_Id := Etype (Comp);
8759 function Non_Static_Bound (Bound : Node_Id) return Boolean;
8760 -- Check whether the bound of an index is non-static and does denote
8761 -- a discriminant, in which case any protected object of the type
8762 -- will have a non-static size.
8764 ----------------------
8765 -- Non_Static_Bound --
8766 ----------------------
8768 function Non_Static_Bound (Bound : Node_Id) return Boolean is
8770 if Is_OK_Static_Expression (Bound) then
8773 elsif Is_Entity_Name (Bound)
8774 and then Present (Discriminal_Link (Entity (Bound)))
8781 end Non_Static_Bound;
8783 -- Start of processing for Discriminated_Size
8786 if not Is_Array_Type (Typ) then
8790 if Ekind (Typ) = E_Array_Subtype then
8791 Index := First_Index (Typ);
8792 while Present (Index) loop
8793 if Non_Static_Bound (Low_Bound (Index))
8794 or else Non_Static_Bound (High_Bound (Index))
8806 end Discriminated_Size;
8808 ---------------------------
8809 -- Static_Component_Size --
8810 ---------------------------
8812 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8813 Typ : constant Entity_Id := Etype (Comp);
8817 if Is_Scalar_Type (Typ) then
8820 elsif Is_Array_Type (Typ) then
8821 return Compile_Time_Known_Bounds (Typ);
8823 elsif Is_Record_Type (Typ) then
8824 C := First_Component (Typ);
8825 while Present (C) loop
8826 if not Static_Component_Size (C) then
8835 -- Any other type will be checked by the back-end
8840 end Static_Component_Size;
8842 ------------------------------
8843 -- Expand_Entry_Declaration --
8844 ------------------------------
8846 procedure Expand_Entry_Declaration (Decl : Node_Id) is
8847 Ent_Id : constant Entity_Id := Defining_Entity (Decl);
8853 E_Count := E_Count + 1;
8855 -- Create the protected body subprogram
8858 Make_Defining_Identifier (Loc,
8859 Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'E'));
8860 Set_Protected_Body_Subprogram (Ent_Id, Bod_Id);
8863 Make_Subprogram_Declaration (Loc,
8865 Build_Protected_Entry_Specification (Loc, Bod_Id, Ent_Id));
8867 Insert_After (Current_Node, Subp);
8868 Current_Node := Subp;
8872 -- Build a wrapper procedure to handle contract cases, preconditions,
8873 -- and postconditions.
8875 Build_Contract_Wrapper (Ent_Id, N);
8877 -- Create the barrier function
8880 Make_Defining_Identifier (Loc,
8881 Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'B'));
8882 Set_Barrier_Function (Ent_Id, Bar_Id);
8885 Make_Subprogram_Declaration (Loc,
8887 Build_Barrier_Function_Specification (Loc, Bar_Id));
8888 Set_Is_Entry_Barrier_Function (Subp);
8890 Insert_After (Current_Node, Subp);
8891 Current_Node := Subp;
8895 Set_Protected_Body_Subprogram (Bar_Id, Bar_Id);
8896 Set_Scope (Bar_Id, Scope (Ent_Id));
8898 -- Collect pointers to the protected subprogram and the barrier
8899 -- of the current entry, for insertion into Entry_Bodies_Array.
8901 Append_To (Expressions (Entries_Aggr),
8902 Make_Aggregate (Loc,
8903 Expressions => New_List (
8904 Make_Attribute_Reference (Loc,
8905 Prefix => New_Occurrence_Of (Bar_Id, Loc),
8906 Attribute_Name => Name_Unrestricted_Access),
8907 Make_Attribute_Reference (Loc,
8908 Prefix => New_Occurrence_Of (Bod_Id, Loc),
8909 Attribute_Name => Name_Unrestricted_Access))));
8910 end Expand_Entry_Declaration;
8912 ----------------------
8913 -- Register_Handler --
8914 ----------------------
8916 procedure Register_Handler is
8918 -- All semantic checks already done in Sem_Prag
8920 Prot_Proc : constant Entity_Id :=
8921 Defining_Unit_Name (Specification (Current_Node));
8923 Proc_Address : constant Node_Id :=
8924 Make_Attribute_Reference (Loc,
8926 New_Occurrence_Of (Prot_Proc, Loc),
8927 Attribute_Name => Name_Address);
8929 RTS_Call : constant Entity_Id :=
8930 Make_Procedure_Call_Statement (Loc,
8933 (RTE (RE_Register_Interrupt_Handler), Loc),
8934 Parameter_Associations => New_List (Proc_Address));
8936 Append_Freeze_Action (Prot_Proc, RTS_Call);
8937 end Register_Handler;
8942 Body_Id : Entity_Id;
8948 Object_Comp : Node_Id;
8953 -- Start of processing for Expand_N_Protected_Type_Declaration
8956 if Present (Corresponding_Record_Type (Prot_Typ)) then
8959 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
8962 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
8964 Qualify_Entity_Names (N);
8966 -- If the type has discriminants, their occurrences in the declaration
8967 -- have been replaced by the corresponding discriminals. For components
8968 -- that are constrained by discriminants, their homologues in the
8969 -- corresponding record type must refer to the discriminants of that
8970 -- record, so we must apply a new renaming to subtypes_indications:
8972 -- protected discriminant => discriminal => record discriminant
8974 -- This replacement is not applied to default expressions, for which
8975 -- the discriminal is correct.
8977 if Has_Discriminants (Prot_Typ) then
8983 Disc := First_Discriminant (Prot_Typ);
8984 Decl := First (Discriminant_Specifications (Rec_Decl));
8985 while Present (Disc) loop
8986 Append_Elmt (Discriminal (Disc), Discr_Map);
8987 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
8988 Next_Discriminant (Disc);
8994 -- Fill in the component declarations
8996 -- Add components for entry families. For each entry family, create an
8997 -- anonymous type declaration with the same size, and analyze the type.
8999 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
9001 pragma Assert (Present (Pdef));
9003 Insert_After (Current_Node, Rec_Decl);
9004 Current_Node := Rec_Decl;
9006 -- Add private field components
9008 if Present (Private_Declarations (Pdef)) then
9009 Priv := First (Private_Declarations (Pdef));
9010 while Present (Priv) loop
9011 if Nkind (Priv) = N_Component_Declaration then
9012 if not Static_Component_Size (Defining_Identifier (Priv)) then
9014 -- When compiling for a restricted profile, the private
9015 -- components must have a static size. If not, this is an
9016 -- error for a single protected declaration, and rates a
9017 -- warning on a protected type declaration.
9019 if not Comes_From_Source (Prot_Typ) then
9021 -- It's ok to be checking this restriction at expansion
9022 -- time, because this is only for the restricted profile,
9023 -- which is not subject to strict RM conformance, so it
9024 -- is OK to miss this check in -gnatc mode.
9026 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
9028 (No_Implicit_Protected_Object_Allocations, Priv);
9030 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
9031 if not Discriminated_Size (Defining_Identifier (Priv))
9033 -- Any object of the type will be non-static
9035 Error_Msg_N ("component has non-static size??", Priv);
9037 ("\creation of protected object of type& will "
9038 & "violate restriction "
9039 & "No_Implicit_Heap_Allocations??", Priv, Prot_Typ);
9041 -- Object will be non-static if discriminants are
9044 ("creation of protected object of type& with "
9045 & "non-static discriminants will violate "
9046 & "restriction No_Implicit_Heap_Allocations??",
9050 -- Likewise for No_Implicit_Protected_Object_Allocations
9052 elsif Restriction_Active
9053 (No_Implicit_Protected_Object_Allocations)
9055 if not Discriminated_Size (Defining_Identifier (Priv))
9057 -- Any object of the type will be non-static
9059 Error_Msg_N ("component has non-static size??", Priv);
9061 ("\creation of protected object of type& will "
9062 & "violate restriction "
9063 & "No_Implicit_Protected_Object_Allocations??",
9066 -- Object will be non-static if discriminants are
9069 ("creation of protected object of type& with "
9070 & "non-static discriminants will violate "
9072 & "No_Implicit_Protected_Object_Allocations??",
9078 -- The component definition consists of a subtype indication,
9079 -- or (in Ada 2005) an access definition. Make a copy of the
9080 -- proper definition.
9083 Old_Comp : constant Node_Id := Component_Definition (Priv);
9084 Oent : constant Entity_Id := Defining_Identifier (Priv);
9085 Nent : constant Entity_Id :=
9086 Make_Defining_Identifier (Sloc (Oent),
9087 Chars => Chars (Oent));
9091 if Present (Subtype_Indication (Old_Comp)) then
9093 Make_Component_Definition (Sloc (Oent),
9094 Aliased_Present => False,
9095 Subtype_Indication =>
9097 (Subtype_Indication (Old_Comp), Discr_Map));
9100 Make_Component_Definition (Sloc (Oent),
9101 Aliased_Present => False,
9102 Access_Definition =>
9104 (Access_Definition (Old_Comp), Discr_Map));
9108 Make_Component_Declaration (Loc,
9109 Defining_Identifier => Nent,
9110 Component_Definition => New_Comp,
9111 Expression => Expression (Priv));
9113 Set_Has_Per_Object_Constraint (Nent,
9114 Has_Per_Object_Constraint (Oent));
9116 Append_To (Cdecls, New_Priv);
9119 elsif Nkind (Priv) = N_Subprogram_Declaration then
9121 -- Make the unprotected version of the subprogram available
9122 -- for expansion of intra object calls. There is need for
9123 -- a protected version only if the subprogram is an interrupt
9124 -- handler, otherwise this operation can only be called from
9128 Make_Subprogram_Declaration (Loc,
9130 Build_Protected_Sub_Specification
9131 (Priv, Prot_Typ, Unprotected_Mode));
9133 Insert_After (Current_Node, Sub);
9136 Set_Protected_Body_Subprogram
9137 (Defining_Unit_Name (Specification (Priv)),
9138 Defining_Unit_Name (Specification (Sub)));
9139 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
9140 Current_Node := Sub;
9143 Make_Subprogram_Declaration (Loc,
9145 Build_Protected_Sub_Specification
9146 (Priv, Prot_Typ, Protected_Mode));
9148 Insert_After (Current_Node, Sub);
9150 Current_Node := Sub;
9152 if Is_Interrupt_Handler
9153 (Defining_Unit_Name (Specification (Priv)))
9155 if not Restricted_Profile then
9165 -- Except for the lock-free implementation, append the _Object field
9166 -- with the right type to the component list. We need to compute the
9167 -- number of entries, and in some cases the number of Attach_Handler
9170 if not Lock_Free_Active then
9172 Entry_Count_Expr : constant Node_Id :=
9173 Build_Entry_Count_Expression
9174 (Prot_Typ, Cdecls, Loc);
9175 Num_Attach_Handler : Nat := 0;
9176 Protection_Subtype : Node_Id;
9180 if Has_Attach_Handler (Prot_Typ) then
9181 Ritem := First_Rep_Item (Prot_Typ);
9182 while Present (Ritem) loop
9183 if Nkind (Ritem) = N_Pragma
9184 and then Pragma_Name (Ritem) = Name_Attach_Handler
9186 Num_Attach_Handler := Num_Attach_Handler + 1;
9189 Next_Rep_Item (Ritem);
9193 -- Determine the proper protection type. There are two special
9194 -- cases: 1) when the protected type has dynamic interrupt
9195 -- handlers, and 2) when it has static handlers and we use a
9196 -- restricted profile.
9198 if Has_Attach_Handler (Prot_Typ)
9199 and then not Restricted_Profile
9201 Protection_Subtype :=
9202 Make_Subtype_Indication (Loc,
9205 (RTE (RE_Static_Interrupt_Protection), Loc),
9207 Make_Index_Or_Discriminant_Constraint (Loc,
9208 Constraints => New_List (
9210 Make_Integer_Literal (Loc, Num_Attach_Handler))));
9212 elsif Has_Interrupt_Handler (Prot_Typ)
9213 and then not Restriction_Active (No_Dynamic_Attachment)
9215 Protection_Subtype :=
9216 Make_Subtype_Indication (Loc,
9219 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
9221 Make_Index_Or_Discriminant_Constraint (Loc,
9222 Constraints => New_List (Entry_Count_Expr)));
9225 case Corresponding_Runtime_Package (Prot_Typ) is
9226 when System_Tasking_Protected_Objects_Entries =>
9227 Protection_Subtype :=
9228 Make_Subtype_Indication (Loc,
9231 (RTE (RE_Protection_Entries), Loc),
9233 Make_Index_Or_Discriminant_Constraint (Loc,
9234 Constraints => New_List (Entry_Count_Expr)));
9236 when System_Tasking_Protected_Objects_Single_Entry =>
9237 Protection_Subtype :=
9238 New_Occurrence_Of (RTE (RE_Protection_Entry), Loc);
9240 when System_Tasking_Protected_Objects =>
9241 Protection_Subtype :=
9242 New_Occurrence_Of (RTE (RE_Protection), Loc);
9245 raise Program_Error;
9250 Make_Component_Declaration (Loc,
9251 Defining_Identifier =>
9252 Make_Defining_Identifier (Loc, Name_uObject),
9253 Component_Definition =>
9254 Make_Component_Definition (Loc,
9255 Aliased_Present => True,
9256 Subtype_Indication => Protection_Subtype));
9259 -- Put the _Object component after the private component so that it
9260 -- be finalized early as required by 9.4 (20)
9262 Append_To (Cdecls, Object_Comp);
9265 -- Analyze the record declaration immediately after construction,
9266 -- because the initialization procedure is needed for single object
9267 -- declarations before the next entity is analyzed (the freeze call
9268 -- that generates this initialization procedure is found below).
9270 Analyze (Rec_Decl, Suppress => All_Checks);
9272 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9273 -- the corresponding record is frozen. If any wrappers are generated,
9274 -- Current_Node is updated accordingly.
9276 if Ada_Version >= Ada_2005 then
9277 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
9280 -- Collect pointers to entry bodies and their barriers, to be placed
9281 -- in the Entry_Bodies_Array for the type. For each entry/family we
9282 -- add an expression to the aggregate which is the initial value of
9283 -- this array. The array is declared after all protected subprograms.
9285 if Has_Entries (Prot_Typ) then
9286 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
9288 Entries_Aggr := Empty;
9291 -- Build two new procedure specifications for each protected subprogram;
9292 -- one to call from outside the object and one to call from inside.
9293 -- Build a barrier function and an entry body action procedure
9294 -- specification for each protected entry. Initialize the entry body
9295 -- array. If subprogram is flagged as eliminated, do not generate any
9296 -- internal operations.
9299 Comp := First (Visible_Declarations (Pdef));
9300 while Present (Comp) loop
9301 if Nkind (Comp) = N_Subprogram_Declaration then
9303 Make_Subprogram_Declaration (Loc,
9305 Build_Protected_Sub_Specification
9306 (Comp, Prot_Typ, Unprotected_Mode));
9308 Insert_After (Current_Node, Sub);
9311 Set_Protected_Body_Subprogram
9312 (Defining_Unit_Name (Specification (Comp)),
9313 Defining_Unit_Name (Specification (Sub)));
9314 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
9316 -- Make the protected version of the subprogram available for
9317 -- expansion of external calls.
9319 Current_Node := Sub;
9322 Make_Subprogram_Declaration (Loc,
9324 Build_Protected_Sub_Specification
9325 (Comp, Prot_Typ, Protected_Mode));
9327 Insert_After (Current_Node, Sub);
9330 Current_Node := Sub;
9332 -- Generate an overriding primitive operation specification for
9333 -- this subprogram if the protected type implements an interface
9334 -- and Build_Wrapper_Spec did not generate its wrapper.
9336 if Ada_Version >= Ada_2005
9338 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
9341 Found : Boolean := False;
9342 Prim_Elmt : Elmt_Id;
9348 (Primitive_Operations
9349 (Corresponding_Record_Type (Prot_Typ)));
9351 while Present (Prim_Elmt) loop
9352 Prim_Op := Node (Prim_Elmt);
9354 if Is_Primitive_Wrapper (Prim_Op)
9355 and then Wrapped_Entity (Prim_Op) =
9356 Defining_Entity (Specification (Comp))
9362 Next_Elmt (Prim_Elmt);
9367 Make_Subprogram_Declaration (Loc,
9369 Build_Protected_Sub_Specification
9370 (Comp, Prot_Typ, Dispatching_Mode));
9372 Insert_After (Current_Node, Sub);
9375 Current_Node := Sub;
9380 -- If a pragma Interrupt_Handler applies, build and add a call to
9381 -- Register_Interrupt_Handler to the freezing actions of the
9382 -- protected version (Current_Node) of the subprogram:
9384 -- system.interrupts.register_interrupt_handler
9385 -- (prot_procP'address);
9387 if not Restricted_Profile
9388 and then Is_Interrupt_Handler
9389 (Defining_Unit_Name (Specification (Comp)))
9394 elsif Nkind (Comp) = N_Entry_Declaration then
9395 Expand_Entry_Declaration (Comp);
9401 -- If there are some private entry declarations, expand it as if they
9402 -- were visible entries.
9404 if Present (Private_Declarations (Pdef)) then
9405 Comp := First (Private_Declarations (Pdef));
9406 while Present (Comp) loop
9407 if Nkind (Comp) = N_Entry_Declaration then
9408 Expand_Entry_Declaration (Comp);
9415 -- Create the declaration of an array object which contains the values
9416 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9417 -- type. This object is later passed to the appropriate protected object
9418 -- initialization routine.
9420 if Has_Entries (Prot_Typ)
9421 and then Corresponding_Runtime_Package (Prot_Typ) =
9422 System_Tasking_Protected_Objects_Entries
9429 Maxes_Id : Entity_Id;
9430 Need_Array : Boolean := False;
9433 -- First check if there is any Max_Queue_Length pragma
9435 Item := First_Entity (Prot_Typ);
9436 while Present (Item) loop
9437 if Is_Entry (Item) and then Has_Max_Queue_Length (Item) then
9445 -- Gather the Max_Queue_Length values of all entries in a list. A
9446 -- value of zero indicates that the entry has no limitation on its
9451 Item := First_Entity (Prot_Typ);
9453 while Present (Item) loop
9454 if Is_Entry (Item) then
9457 Make_Integer_Literal
9458 (Loc, Get_Max_Queue_Length (Item)));
9464 -- Create the declaration of the array object. Generate:
9466 -- Maxes_Id : aliased constant
9467 -- Protected_Entry_Queue_Max_Array
9468 -- (1 .. Count) := (..., ...);
9471 Make_Defining_Identifier (Loc,
9472 Chars => New_External_Name (Chars (Prot_Typ), 'B'));
9475 Make_Object_Declaration (Loc,
9476 Defining_Identifier => Maxes_Id,
9477 Aliased_Present => True,
9478 Constant_Present => True,
9479 Object_Definition =>
9480 Make_Subtype_Indication (Loc,
9483 (RTE (RE_Protected_Entry_Queue_Max_Array), Loc),
9485 Make_Index_Or_Discriminant_Constraint (Loc,
9486 Constraints => New_List (
9488 Make_Integer_Literal (Loc, 1),
9489 Make_Integer_Literal (Loc, Count))))),
9490 Expression => Make_Aggregate (Loc, Maxes));
9492 -- A pointer to this array will be placed in the corresponding
9493 -- record by its initialization procedure so this needs to be
9496 Insert_After (Current_Node, Max_Vals);
9497 Current_Node := Max_Vals;
9500 Set_Entry_Max_Queue_Lengths_Array (Prot_Typ, Maxes_Id);
9505 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9506 -- all protected subprograms have been collected.
9508 if Has_Entries (Prot_Typ) then
9510 Make_Defining_Identifier (Sloc (Prot_Typ),
9511 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
9513 case Corresponding_Runtime_Package (Prot_Typ) is
9514 when System_Tasking_Protected_Objects_Entries =>
9515 Expr := Entries_Aggr;
9517 Make_Subtype_Indication (Loc,
9520 (RTE (RE_Protected_Entry_Body_Array), Loc),
9522 Make_Index_Or_Discriminant_Constraint (Loc,
9523 Constraints => New_List (
9525 Make_Integer_Literal (Loc, 1),
9526 Make_Integer_Literal (Loc, E_Count)))));
9528 when System_Tasking_Protected_Objects_Single_Entry =>
9529 Expr := Remove_Head (Expressions (Entries_Aggr));
9530 Obj_Def := New_Occurrence_Of (RTE (RE_Entry_Body), Loc);
9533 raise Program_Error;
9537 Make_Object_Declaration (Loc,
9538 Defining_Identifier => Body_Id,
9539 Aliased_Present => True,
9540 Constant_Present => True,
9541 Object_Definition => Obj_Def,
9542 Expression => Expr);
9544 -- A pointer to this array will be placed in the corresponding record
9545 -- by its initialization procedure so this needs to be analyzed here.
9547 Insert_After (Current_Node, Body_Arr);
9548 Current_Node := Body_Arr;
9551 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
9553 -- Finally, build the function that maps an entry index into the
9554 -- corresponding body. A pointer to this function is placed in each
9555 -- object of the type. Except for a ravenscar-like profile (no abort,
9556 -- no entry queue, 1 entry)
9558 if Corresponding_Runtime_Package (Prot_Typ) =
9559 System_Tasking_Protected_Objects_Entries
9562 Make_Subprogram_Declaration (Loc,
9563 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
9565 Insert_After (Current_Node, Sub);
9569 end Expand_N_Protected_Type_Declaration;
9571 --------------------------------
9572 -- Expand_N_Requeue_Statement --
9573 --------------------------------
9575 -- A nondispatching requeue statement is expanded into one of four GNARLI
9576 -- operations, depending on the source and destination (task or protected
9577 -- object). A dispatching requeue statement is expanded into a call to the
9578 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9579 -- jump around the remainder of processing for the original entry and, if
9580 -- the destination is (different) protected object, to attempt to service
9581 -- it. The following illustrates the various cases:
9584 -- (O : System.Address;
9585 -- P : System.Address;
9586 -- E : Protected_Entry_Index)
9588 -- <discriminant renamings>
9589 -- <private object renamings>
9590 -- type poVP is access poV;
9591 -- _object : ptVP := ptVP!(O);
9595 -- <start of statement sequence for entry>
9597 -- -- Requeue from one protected entry body to another protected
9600 -- Requeue_Protected_Entry (
9601 -- _object._object'Access,
9602 -- new._object'Access,
9607 -- <some more of the statement sequence for entry>
9609 -- -- Requeue from an entry body to a task entry
9611 -- Requeue_Protected_To_Task_Entry (
9617 -- <rest of statement sequence for entry>
9618 -- Complete_Entry_Body (_object._object);
9621 -- when all others =>
9622 -- Exceptional_Complete_Entry_Body (
9623 -- _object._object, Get_GNAT_Exception);
9627 -- Requeue of a task entry call to a task entry
9629 -- Accept_Call (E, Ann);
9630 -- <start of statement sequence for accept statement>
9631 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9633 -- <rest of statement sequence for accept statement>
9635 -- Complete_Rendezvous;
9638 -- when all others =>
9639 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9641 -- Requeue of a task entry call to a protected entry
9643 -- Accept_Call (E, Ann);
9644 -- <start of statement sequence for accept statement>
9645 -- Requeue_Task_To_Protected_Entry (
9646 -- new._object'Access,
9651 -- <rest of statement sequence for accept statement>
9653 -- Complete_Rendezvous;
9656 -- when all others =>
9657 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9659 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9660 -- marked by pragma Implemented (XXX, By_Entry).
9662 -- The requeue is inside a protected entry:
9665 -- (O : System.Address;
9666 -- P : System.Address;
9667 -- E : Protected_Entry_Index)
9669 -- <discriminant renamings>
9670 -- <private object renamings>
9671 -- type poVP is access poV;
9672 -- _object : ptVP := ptVP!(O);
9676 -- <start of statement sequence for entry>
9679 -- (<interface class-wide object>,
9682 -- Ada.Tags.Get_Offset_Index
9684 -- <interface dispatch table index of target entry>),
9688 -- <rest of statement sequence for entry>
9689 -- Complete_Entry_Body (_object._object);
9692 -- when all others =>
9693 -- Exceptional_Complete_Entry_Body (
9694 -- _object._object, Get_GNAT_Exception);
9698 -- The requeue is inside a task entry:
9700 -- Accept_Call (E, Ann);
9701 -- <start of statement sequence for accept statement>
9703 -- (<interface class-wide object>,
9706 -- Ada.Tags.Get_Offset_Index
9708 -- <interface dispatch table index of target entrt>),
9712 -- <rest of statement sequence for accept statement>
9714 -- Complete_Rendezvous;
9717 -- when all others =>
9718 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9720 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9721 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9722 -- statement is replaced by a dispatching call with actual parameters taken
9723 -- from the inner-most accept statement or entry body.
9725 -- Target.Primitive (Param1, ..., ParamN);
9727 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9728 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9732 -- S : constant Offset_Index :=
9733 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9734 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9737 -- if C = POK_Protected_Entry
9738 -- or else C = POK_Task_Entry
9740 -- <statements for dispatching requeue>
9742 -- elsif C = POK_Protected_Procedure then
9743 -- <dispatching call equivalent>
9746 -- raise Program_Error;
9750 procedure Expand_N_Requeue_Statement (N : Node_Id) is
9751 Loc : constant Source_Ptr := Sloc (N);
9752 Conc_Typ : Entity_Id;
9756 Old_Typ : Entity_Id;
9758 function Build_Dispatching_Call_Equivalent return Node_Id;
9759 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9760 -- the form Concval.Ename. It is statically known that Ename is allowed
9761 -- to be implemented by a protected procedure. Create a dispatching call
9762 -- equivalent of Concval.Ename taking the actual parameters from the
9763 -- inner-most accept statement or entry body.
9765 function Build_Dispatching_Requeue return Node_Id;
9766 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9767 -- the form Concval.Ename. It is statically known that Ename is allowed
9768 -- to be implemented by a protected or a task entry. Create a call to
9769 -- primitive _Disp_Requeue which handles the low-level actions.
9771 function Build_Dispatching_Requeue_To_Any return Node_Id;
9772 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9773 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9774 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9775 -- determines at runtime whether Ename denotes an entry or a procedure
9776 -- and perform the appropriate kind of dispatching select.
9778 function Build_Normal_Requeue return Node_Id;
9779 -- N denotes a nondispatching requeue statement to either a task or a
9780 -- protected entry. Build the appropriate runtime call to perform the
9783 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
9784 -- For a protected entry, create a return statement to skip the rest of
9785 -- the entry body. Otherwise, create a goto statement to skip the rest
9786 -- of a task accept statement. The lookup for the enclosing entry body
9787 -- or accept statement starts from Search.
9789 ---------------------------------------
9790 -- Build_Dispatching_Call_Equivalent --
9791 ---------------------------------------
9793 function Build_Dispatching_Call_Equivalent return Node_Id is
9794 Call_Ent : constant Entity_Id := Entity (Ename);
9795 Obj : constant Node_Id := Original_Node (Concval);
9802 -- Climb the parent chain looking for the inner-most entry body or
9803 -- accept statement.
9806 while Present (Acc_Ent)
9807 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
9810 Acc_Ent := Parent (Acc_Ent);
9813 -- A requeue statement should be housed inside an entry body or an
9814 -- accept statement at some level. If this is not the case, then the
9815 -- tree is malformed.
9817 pragma Assert (Present (Acc_Ent));
9819 -- Recover the list of formal parameters
9821 if Nkind (Acc_Ent) = N_Entry_Body then
9822 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
9825 Formals := Parameter_Specifications (Acc_Ent);
9827 -- Create the actual parameters for the dispatching call. These are
9828 -- simply copies of the entry body or accept statement formals in the
9829 -- same order as they appear.
9833 if Present (Formals) then
9834 Actuals := New_List;
9835 Formal := First (Formals);
9836 while Present (Formal) loop
9838 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
9844 -- Obj.Call_Ent (Actuals);
9847 Make_Procedure_Call_Statement (Loc,
9849 Make_Selected_Component (Loc,
9850 Prefix => Make_Identifier (Loc, Chars (Obj)),
9851 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
9853 Parameter_Associations => Actuals);
9854 end Build_Dispatching_Call_Equivalent;
9856 -------------------------------
9857 -- Build_Dispatching_Requeue --
9858 -------------------------------
9860 function Build_Dispatching_Requeue return Node_Id is
9861 Params : constant List_Id := New_List;
9864 -- Process the "with abort" parameter
9867 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
9869 -- Process the entry wrapper's position in the primary dispatch
9870 -- table parameter. Generate:
9872 -- Ada.Tags.Get_Entry_Index
9873 -- (T => To_Tag_Ptr (Obj'Address).all,
9875 -- Ada.Tags.Get_Offset_Index
9876 -- (Ada.Tags.Tag (Concval),
9877 -- <interface dispatch table position of Ename>));
9879 -- Note that Obj'Address is recursively expanded into a call to
9880 -- Base_Address (Obj).
9882 if Tagged_Type_Expansion then
9884 Make_Function_Call (Loc,
9885 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9886 Parameter_Associations => New_List (
9888 Make_Explicit_Dereference (Loc,
9889 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
9890 Make_Attribute_Reference (Loc,
9891 Prefix => New_Copy_Tree (Concval),
9892 Attribute_Name => Name_Address))),
9894 Make_Function_Call (Loc,
9895 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9896 Parameter_Associations => New_List (
9897 Unchecked_Convert_To (RTE (RE_Tag), Concval),
9898 Make_Integer_Literal (Loc,
9899 DT_Position (Entity (Ename))))))));
9905 Make_Function_Call (Loc,
9906 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9907 Parameter_Associations => New_List (
9909 Make_Attribute_Reference (Loc,
9911 Attribute_Name => Name_Tag),
9913 Make_Function_Call (Loc,
9914 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9916 Parameter_Associations => New_List (
9920 Make_Attribute_Reference (Loc,
9922 Attribute_Name => Name_Tag),
9926 Make_Attribute_Reference (Loc,
9927 Prefix => New_Occurrence_Of (Etype (Concval), Loc),
9928 Attribute_Name => Name_Tag),
9932 Make_Integer_Literal (Loc,
9933 DT_Position (Entity (Ename))))))));
9936 -- Specific actuals for protected to XXX requeue
9938 if Is_Protected_Type (Old_Typ) then
9940 Make_Attribute_Reference (Loc, -- _object'Address
9942 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9943 Attribute_Name => Name_Address));
9945 Prepend_To (Params, -- True
9946 New_Occurrence_Of (Standard_True, Loc));
9948 -- Specific actuals for task to XXX requeue
9951 pragma Assert (Is_Task_Type (Old_Typ));
9953 Prepend_To (Params, -- null
9954 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
9956 Prepend_To (Params, -- False
9957 New_Occurrence_Of (Standard_False, Loc));
9960 -- Add the object parameter
9962 Prepend_To (Params, New_Copy_Tree (Concval));
9965 -- _Disp_Requeue (<Params>);
9967 -- Find entity for Disp_Requeue operation, which belongs to
9968 -- the type and may not be directly visible.
9975 Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
9976 while Present (Elmt) loop
9978 exit when Chars (Op) = Name_uDisp_Requeue;
9983 Make_Procedure_Call_Statement (Loc,
9984 Name => New_Occurrence_Of (Op, Loc),
9985 Parameter_Associations => Params);
9987 end Build_Dispatching_Requeue;
9989 --------------------------------------
9990 -- Build_Dispatching_Requeue_To_Any --
9991 --------------------------------------
9993 function Build_Dispatching_Requeue_To_Any return Node_Id is
9994 Call_Ent : constant Entity_Id := Entity (Ename);
9995 Obj : constant Node_Id := Original_Node (Concval);
9996 Skip : constant Node_Id := Build_Skip_Statement (N);
10006 -- Dispatch table slot processing, generate:
10009 S := Build_S (Loc, Decls);
10011 -- Call kind processing, generate:
10012 -- C : Ada.Tags.Prim_Op_Kind;
10014 C := Build_C (Loc, Decls);
10017 -- S := Ada.Tags.Get_Offset_Index
10018 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10020 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
10023 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10026 Make_Procedure_Call_Statement (Loc,
10028 New_Occurrence_Of (
10029 Find_Prim_Op (Etype (Etype (Obj)),
10030 Name_uDisp_Get_Prim_Op_Kind),
10032 Parameter_Associations => New_List (
10033 New_Copy_Tree (Obj),
10034 New_Occurrence_Of (S, Loc),
10035 New_Occurrence_Of (C, Loc))));
10039 -- if C = POK_Protected_Entry
10040 -- or else C = POK_Task_Entry
10043 Make_Implicit_If_Statement (N,
10049 New_Occurrence_Of (C, Loc),
10051 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
10056 New_Occurrence_Of (C, Loc),
10058 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
10060 -- Dispatching requeue equivalent
10062 Then_Statements => New_List (
10063 Build_Dispatching_Requeue,
10066 -- elsif C = POK_Protected_Procedure then
10068 Elsif_Parts => New_List (
10069 Make_Elsif_Part (Loc,
10073 New_Occurrence_Of (C, Loc),
10075 New_Occurrence_Of (
10076 RTE (RE_POK_Protected_Procedure), Loc)),
10078 -- Dispatching call equivalent
10080 Then_Statements => New_List (
10081 Build_Dispatching_Call_Equivalent))),
10084 -- raise Program_Error;
10087 Else_Statements => New_List (
10088 Make_Raise_Program_Error (Loc,
10089 Reason => PE_Explicit_Raise))));
10091 -- Wrap everything into a block
10094 Make_Block_Statement (Loc,
10095 Declarations => Decls,
10096 Handled_Statement_Sequence =>
10097 Make_Handled_Sequence_Of_Statements (Loc,
10098 Statements => Stmts));
10099 end Build_Dispatching_Requeue_To_Any;
10101 --------------------------
10102 -- Build_Normal_Requeue --
10103 --------------------------
10105 function Build_Normal_Requeue return Node_Id is
10106 Params : constant List_Id := New_List;
10111 -- Process the "with abort" parameter
10113 Prepend_To (Params,
10114 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
10116 -- Add the index expression to the parameters. It is common among all
10119 Prepend_To (Params,
10120 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
10122 if Is_Protected_Type (Old_Typ) then
10124 Self_Param : Node_Id;
10128 Make_Attribute_Reference (Loc,
10130 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
10132 Name_Unchecked_Access);
10134 -- Protected to protected requeue
10136 if Is_Protected_Type (Conc_Typ) then
10138 New_Occurrence_Of (
10139 RTE (RE_Requeue_Protected_Entry), Loc);
10142 Make_Attribute_Reference (Loc,
10144 Concurrent_Ref (Concval),
10146 Name_Unchecked_Access);
10148 -- Protected to task requeue
10150 else pragma Assert (Is_Task_Type (Conc_Typ));
10152 New_Occurrence_Of (
10153 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
10155 Param := Concurrent_Ref (Concval);
10158 Prepend_To (Params, Param);
10159 Prepend_To (Params, Self_Param);
10162 else pragma Assert (Is_Task_Type (Old_Typ));
10164 -- Task to protected requeue
10166 if Is_Protected_Type (Conc_Typ) then
10168 New_Occurrence_Of (
10169 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
10172 Make_Attribute_Reference (Loc,
10174 Concurrent_Ref (Concval),
10176 Name_Unchecked_Access);
10178 -- Task to task requeue
10180 else pragma Assert (Is_Task_Type (Conc_Typ));
10182 New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc);
10184 Param := Concurrent_Ref (Concval);
10187 Prepend_To (Params, Param);
10191 Make_Procedure_Call_Statement (Loc,
10193 Parameter_Associations => Params);
10194 end Build_Normal_Requeue;
10196 --------------------------
10197 -- Build_Skip_Statement --
10198 --------------------------
10200 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
10201 Skip_Stmt : Node_Id;
10204 -- Build a return statement to skip the rest of the entire body
10206 if Is_Protected_Type (Old_Typ) then
10207 Skip_Stmt := Make_Simple_Return_Statement (Loc);
10209 -- If the requeue is within a task, find the end label of the
10210 -- enclosing accept statement and create a goto statement to it.
10218 -- Climb the parent chain looking for the enclosing accept
10221 Acc := Parent (Search);
10222 while Present (Acc)
10223 and then Nkind (Acc) /= N_Accept_Statement
10225 Acc := Parent (Acc);
10228 -- The last statement is the second label used for completing
10229 -- the rendezvous the usual way. The label we are looking for
10230 -- is right before it.
10233 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
10235 pragma Assert (Nkind (Label) = N_Label);
10237 -- Generate a goto statement to skip the rest of the accept
10240 Make_Goto_Statement (Loc,
10242 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
10246 Set_Analyzed (Skip_Stmt);
10249 end Build_Skip_Statement;
10251 -- Start of processing for Expand_N_Requeue_Statement
10254 -- Extract the components of the entry call
10256 Extract_Entry (N, Concval, Ename, Index);
10257 Conc_Typ := Etype (Concval);
10259 -- If the prefix is an access to class-wide type, dereference to get
10260 -- object and entry type.
10262 if Is_Access_Type (Conc_Typ) then
10263 Conc_Typ := Designated_Type (Conc_Typ);
10265 Make_Explicit_Dereference (Loc, Relocate_Node (Concval)));
10266 Analyze_And_Resolve (Concval, Conc_Typ);
10269 -- Examine the scope stack in order to find nearest enclosing protected
10270 -- or task type. This will constitute our invocation source.
10272 Old_Typ := Current_Scope;
10273 while Present (Old_Typ)
10274 and then not Is_Protected_Type (Old_Typ)
10275 and then not Is_Task_Type (Old_Typ)
10277 Old_Typ := Scope (Old_Typ);
10280 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10281 -- Concval.Ename where the type of Concval is class-wide concurrent
10284 if Ada_Version >= Ada_2012
10285 and then Present (Concval)
10286 and then Is_Class_Wide_Type (Conc_Typ)
10287 and then Is_Concurrent_Interface (Conc_Typ)
10290 Has_Impl : Boolean := False;
10291 Impl_Kind : Name_Id := No_Name;
10294 -- Check whether the Ename is flagged by pragma Implemented
10296 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
10298 Impl_Kind := Implementation_Kind (Entity (Ename));
10301 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10302 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10304 if Has_Impl and then Impl_Kind = Name_By_Entry then
10305 Rewrite (N, Build_Dispatching_Requeue);
10307 Insert_After (N, Build_Skip_Statement (N));
10309 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10310 -- a protected procedure. In this case the requeue is transformed
10311 -- into a dispatching call.
10314 and then Impl_Kind = Name_By_Protected_Procedure
10316 Rewrite (N, Build_Dispatching_Call_Equivalent);
10319 -- The procedure_or_entry_NAME's implementation kind is either
10320 -- By_Any, Optional, or pragma Implemented was not applied at all.
10321 -- In this case a runtime test determines whether Ename denotes an
10322 -- entry or a protected procedure and performs the appropriate
10326 Rewrite (N, Build_Dispatching_Requeue_To_Any);
10331 -- Processing for regular (nondispatching) requeues
10334 Rewrite (N, Build_Normal_Requeue);
10336 Insert_After (N, Build_Skip_Statement (N));
10338 end Expand_N_Requeue_Statement;
10340 -------------------------------
10341 -- Expand_N_Selective_Accept --
10342 -------------------------------
10344 procedure Expand_N_Selective_Accept (N : Node_Id) is
10345 Loc : constant Source_Ptr := Sloc (N);
10346 Alts : constant List_Id := Select_Alternatives (N);
10348 -- Note: in the below declarations a lot of new lists are allocated
10349 -- unconditionally which may well not end up being used. That's not
10350 -- a good idea since it wastes space gratuitously ???
10352 Accept_Case : List_Id;
10353 Accept_List : constant List_Id := New_List;
10356 Alt_List : constant List_Id := New_List;
10357 Alt_Stats : List_Id;
10358 Ann : Entity_Id := Empty;
10360 Check_Guard : Boolean := True;
10362 Decls : constant List_Id := New_List;
10363 Stats : constant List_Id := New_List;
10364 Body_List : constant List_Id := New_List;
10365 Trailing_List : constant List_Id := New_List;
10368 Else_Present : Boolean := False;
10369 Terminate_Alt : Node_Id := Empty;
10370 Select_Mode : Node_Id;
10372 Delay_Case : List_Id;
10373 Delay_Count : Integer := 0;
10374 Delay_Val : Entity_Id;
10375 Delay_Index : Entity_Id;
10376 Delay_Min : Entity_Id;
10377 Delay_Num : Pos := 1;
10378 Delay_Alt_List : List_Id := New_List;
10379 Delay_List : constant List_Id := New_List;
10383 First_Delay : Boolean := True;
10384 Guard_Open : Entity_Id;
10390 Num_Accept : Nat := 0;
10392 Time_Type : Entity_Id;
10393 Select_Call : Node_Id;
10395 Qnam : constant Entity_Id :=
10396 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
10398 Xnam : constant Entity_Id :=
10399 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
10401 -----------------------
10402 -- Local subprograms --
10403 -----------------------
10405 function Accept_Or_Raise return List_Id;
10406 -- For the rare case where delay alternatives all have guards, and
10407 -- all of them are closed, it is still possible that there were open
10408 -- accept alternatives with no callers. We must reexamine the
10409 -- Accept_List, and execute a selective wait with no else if some
10410 -- accept is open. If none, we raise program_error.
10412 procedure Add_Accept (Alt : Node_Id);
10413 -- Process a single accept statement in a select alternative. Build
10414 -- procedure for body of accept, and add entry to dispatch table with
10415 -- expression for guard, in preparation for call to run time select.
10417 function Make_And_Declare_Label (Num : Int) return Node_Id;
10418 -- Manufacture a label using Num as a serial number and declare it.
10419 -- The declaration is appended to Decls. The label marks the trailing
10420 -- statements of an accept or delay alternative.
10422 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
10423 -- Build call to Selective_Wait runtime routine
10425 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
10426 -- Add code to compare value of delay with previous values, and
10427 -- generate case entry for trailing statements.
10429 procedure Process_Accept_Alternative
10433 -- Add code to call corresponding procedure, and branch to
10434 -- trailing statements, if any.
10436 ---------------------
10437 -- Accept_Or_Raise --
10438 ---------------------
10440 function Accept_Or_Raise return List_Id is
10443 J : constant Entity_Id := Make_Temporary (Loc, 'J');
10446 -- We generate the following:
10448 -- for J in q'range loop
10449 -- if q(J).S /=null_task_entry then
10450 -- selective_wait (simple_mode,...);
10456 -- if no rendez_vous then
10457 -- raise program_error;
10460 -- Note that the code needs to know that the selector name
10461 -- in an Accept_Alternative is named S.
10463 Cond := Make_Op_Ne (Loc,
10465 Make_Selected_Component (Loc,
10467 Make_Indexed_Component (Loc,
10468 Prefix => New_Occurrence_Of (Qnam, Loc),
10469 Expressions => New_List (New_Occurrence_Of (J, Loc))),
10470 Selector_Name => Make_Identifier (Loc, Name_S)),
10472 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Loc));
10474 Stats := New_List (
10475 Make_Implicit_Loop_Statement (N,
10476 Iteration_Scheme =>
10477 Make_Iteration_Scheme (Loc,
10478 Loop_Parameter_Specification =>
10479 Make_Loop_Parameter_Specification (Loc,
10480 Defining_Identifier => J,
10481 Discrete_Subtype_Definition =>
10482 Make_Attribute_Reference (Loc,
10483 Prefix => New_Occurrence_Of (Qnam, Loc),
10484 Attribute_Name => Name_Range,
10485 Expressions => New_List (
10486 Make_Integer_Literal (Loc, 1))))),
10488 Statements => New_List (
10489 Make_Implicit_If_Statement (N,
10491 Then_Statements => New_List (
10493 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)),
10494 Make_Exit_Statement (Loc))))));
10497 Make_Raise_Program_Error (Loc,
10498 Condition => Make_Op_Eq (Loc,
10499 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
10501 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
10502 Reason => PE_All_Guards_Closed));
10505 end Accept_Or_Raise;
10511 procedure Add_Accept (Alt : Node_Id) is
10512 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
10513 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
10514 Eloc : constant Source_Ptr := Sloc (Ename);
10515 Eent : constant Entity_Id := Entity (Ename);
10516 Index : constant Node_Id := Entry_Index (Acc_Stm);
10517 Null_Body : Node_Id;
10518 Proc_Body : Node_Id;
10519 PB_Ent : Entity_Id;
10525 Ann := Node (Last_Elmt (Accept_Address (Eent)));
10528 if Present (Condition (Alt)) then
10530 Make_If_Expression (Eloc, New_List (
10532 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
10533 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Eloc)));
10536 Entry_Index_Expression
10537 (Eloc, Eent, Index, Scope (Eent));
10540 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
10541 Null_Body := New_Occurrence_Of (Standard_False, Eloc);
10543 -- Always add call to Abort_Undefer when generating code, since
10544 -- this is what the runtime expects (abort deferred in
10545 -- Selective_Wait). In CodePeer mode this only confuses the
10546 -- analysis with unknown calls, so don't do it.
10548 if not CodePeer_Mode then
10549 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10551 (First (Statements (Handled_Statement_Sequence
10552 (Accept_Statement (Alt)))),
10558 Make_Defining_Identifier (Eloc,
10559 New_External_Name (Chars (Ename), 'A', Num_Accept));
10561 if Comes_From_Source (Alt) then
10562 Set_Debug_Info_Needed (PB_Ent);
10566 Make_Subprogram_Body (Eloc,
10568 Make_Procedure_Specification (Eloc,
10569 Defining_Unit_Name => PB_Ent),
10570 Declarations => Declarations (Acc_Stm),
10571 Handled_Statement_Sequence =>
10572 Build_Accept_Body (Accept_Statement (Alt)));
10574 -- During the analysis of the body of the accept statement, any
10575 -- zero cost exception handler records were collected in the
10576 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10577 -- This is where we move them to where they belong, namely the
10578 -- newly created procedure.
10580 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
10581 Append (Proc_Body, Body_List);
10584 Null_Body := New_Occurrence_Of (Standard_True, Eloc);
10586 -- if accept statement has declarations, insert above, given that
10587 -- we are not creating a body for the accept.
10589 if Present (Declarations (Acc_Stm)) then
10590 Insert_Actions (N, Declarations (Acc_Stm));
10594 Append_To (Accept_List,
10595 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
10597 Num_Accept := Num_Accept + 1;
10600 ----------------------------
10601 -- Make_And_Declare_Label --
10602 ----------------------------
10604 function Make_And_Declare_Label (Num : Int) return Node_Id is
10608 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
10610 Make_Label (Loc, Lab_Id);
10613 Make_Implicit_Label_Declaration (Loc,
10614 Defining_Identifier =>
10615 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
10616 Label_Construct => Lab));
10619 end Make_And_Declare_Label;
10621 ----------------------
10622 -- Make_Select_Call --
10623 ----------------------
10625 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
10626 Params : constant List_Id := New_List;
10630 Make_Attribute_Reference (Loc,
10631 Prefix => New_Occurrence_Of (Qnam, Loc),
10632 Attribute_Name => Name_Unchecked_Access));
10633 Append_To (Params, Select_Mode);
10634 Append_To (Params, New_Occurrence_Of (Ann, Loc));
10635 Append_To (Params, New_Occurrence_Of (Xnam, Loc));
10638 Make_Procedure_Call_Statement (Loc,
10639 Name => New_Occurrence_Of (RTE (RE_Selective_Wait), Loc),
10640 Parameter_Associations => Params);
10641 end Make_Select_Call;
10643 --------------------------------
10644 -- Process_Accept_Alternative --
10645 --------------------------------
10647 procedure Process_Accept_Alternative
10652 Astmt : constant Node_Id := Accept_Statement (Alt);
10653 Alt_Stats : List_Id;
10656 Adjust_Condition (Condition (Alt));
10658 -- Accept with body
10660 if Present (Handled_Statement_Sequence (Astmt)) then
10663 Make_Procedure_Call_Statement (Sloc (Proc),
10666 (Defining_Unit_Name (Specification (Proc)),
10669 -- Accept with no body (followed by trailing statements)
10672 Alt_Stats := Empty_List;
10675 Ensure_Statement_Present (Sloc (Astmt), Alt);
10677 -- After the call, if any, branch to trailing statements, if any.
10678 -- We create a label for each, as well as the corresponding label
10681 if not Is_Empty_List (Statements (Alt)) then
10682 Lab := Make_And_Declare_Label (Index);
10683 Append (Lab, Trailing_List);
10684 Append_List (Statements (Alt), Trailing_List);
10685 Append_To (Trailing_List,
10686 Make_Goto_Statement (Loc,
10687 Name => New_Copy (Identifier (End_Lab))));
10693 Append_To (Alt_Stats,
10694 Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab))));
10696 Append_To (Alt_List,
10697 Make_Case_Statement_Alternative (Loc,
10698 Discrete_Choices => New_List (Make_Integer_Literal (Loc, Index)),
10699 Statements => Alt_Stats));
10700 end Process_Accept_Alternative;
10702 -------------------------------
10703 -- Process_Delay_Alternative --
10704 -------------------------------
10706 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
10707 Dloc : constant Source_Ptr := Sloc (Delay_Statement (Alt));
10709 Delay_Alt : List_Id;
10712 -- Deal with C/Fortran boolean as delay condition
10714 Adjust_Condition (Condition (Alt));
10716 -- Determine the smallest specified delay
10718 -- for each delay alternative generate:
10720 -- if guard-expression then
10721 -- Delay_Val := delay-expression;
10722 -- Guard_Open := True;
10723 -- if Delay_Val < Delay_Min then
10724 -- Delay_Min := Delay_Val;
10725 -- Delay_Index := Index;
10729 -- The enclosing if-statement is omitted if there is no guard
10731 if Delay_Count = 1 or else First_Delay then
10732 First_Delay := False;
10734 Delay_Alt := New_List (
10735 Make_Assignment_Statement (Loc,
10736 Name => New_Occurrence_Of (Delay_Min, Loc),
10737 Expression => Expression (Delay_Statement (Alt))));
10739 if Delay_Count > 1 then
10740 Append_To (Delay_Alt,
10741 Make_Assignment_Statement (Loc,
10742 Name => New_Occurrence_Of (Delay_Index, Loc),
10743 Expression => Make_Integer_Literal (Loc, Index)));
10747 Delay_Alt := New_List (
10748 Make_Assignment_Statement (Loc,
10749 Name => New_Occurrence_Of (Delay_Val, Loc),
10750 Expression => Expression (Delay_Statement (Alt))));
10752 if Time_Type = Standard_Duration then
10755 Left_Opnd => New_Occurrence_Of (Delay_Val, Loc),
10756 Right_Opnd => New_Occurrence_Of (Delay_Min, Loc));
10759 -- The scope of the time type must define a comparison
10760 -- operator. The scope itself may not be visible, so we
10761 -- construct a node with entity information to insure that
10762 -- semantic analysis can find the proper operator.
10765 Make_Function_Call (Loc,
10766 Name => Make_Selected_Component (Loc,
10768 New_Occurrence_Of (Scope (Time_Type), Loc),
10770 Make_Operator_Symbol (Loc,
10771 Chars => Name_Op_Lt,
10772 Strval => No_String)),
10773 Parameter_Associations =>
10775 New_Occurrence_Of (Delay_Val, Loc),
10776 New_Occurrence_Of (Delay_Min, Loc)));
10778 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
10781 Append_To (Delay_Alt,
10782 Make_Implicit_If_Statement (N,
10784 Then_Statements => New_List (
10785 Make_Assignment_Statement (Loc,
10786 Name => New_Occurrence_Of (Delay_Min, Loc),
10787 Expression => New_Occurrence_Of (Delay_Val, Loc)),
10789 Make_Assignment_Statement (Loc,
10790 Name => New_Occurrence_Of (Delay_Index, Loc),
10791 Expression => Make_Integer_Literal (Loc, Index)))));
10794 if Check_Guard then
10795 Append_To (Delay_Alt,
10796 Make_Assignment_Statement (Loc,
10797 Name => New_Occurrence_Of (Guard_Open, Loc),
10798 Expression => New_Occurrence_Of (Standard_True, Loc)));
10801 if Present (Condition (Alt)) then
10802 Delay_Alt := New_List (
10803 Make_Implicit_If_Statement (N,
10804 Condition => Condition (Alt),
10805 Then_Statements => Delay_Alt));
10808 Append_List (Delay_Alt, Delay_List);
10810 Ensure_Statement_Present (Dloc, Alt);
10812 -- If the delay alternative has a statement part, add choice to the
10813 -- case statements for delays.
10815 if not Is_Empty_List (Statements (Alt)) then
10817 if Delay_Count = 1 then
10818 Append_List (Statements (Alt), Delay_Alt_List);
10821 Append_To (Delay_Alt_List,
10822 Make_Case_Statement_Alternative (Loc,
10823 Discrete_Choices => New_List (
10824 Make_Integer_Literal (Loc, Index)),
10825 Statements => Statements (Alt)));
10828 elsif Delay_Count = 1 then
10830 -- If the single delay has no trailing statements, add a branch
10831 -- to the exit label to the selective wait.
10833 Delay_Alt_List := New_List (
10834 Make_Goto_Statement (Loc,
10835 Name => New_Copy (Identifier (End_Lab))));
10838 end Process_Delay_Alternative;
10840 -- Start of processing for Expand_N_Selective_Accept
10843 Process_Statements_For_Controlled_Objects (N);
10845 -- First insert some declarations before the select. The first is:
10849 -- This variable holds the parameters passed to the accept body. This
10850 -- declaration has already been inserted by the time we get here by
10851 -- a call to Expand_Accept_Declarations made from the semantics when
10852 -- processing the first accept statement contained in the select. We
10853 -- can find this entity as Accept_Address (E), where E is any of the
10854 -- entries references by contained accept statements.
10856 -- The first step is to scan the list of Selective_Accept_Statements
10857 -- to find this entity, and also count the number of accepts, and
10858 -- determine if terminated, delay or else is present:
10862 Alt := First (Alts);
10863 while Present (Alt) loop
10864 Process_Statements_For_Controlled_Objects (Alt);
10866 if Nkind (Alt) = N_Accept_Alternative then
10869 elsif Nkind (Alt) = N_Delay_Alternative then
10870 Delay_Count := Delay_Count + 1;
10872 -- If the delays are relative delays, the delay expressions have
10873 -- type Standard_Duration. Otherwise they must have some time type
10874 -- recognized by GNAT.
10876 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
10877 Time_Type := Standard_Duration;
10879 Time_Type := Etype (Expression (Delay_Statement (Alt)));
10881 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
10882 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
10887 "& is not a time type (RM 9.6(6))",
10888 Expression (Delay_Statement (Alt)), Time_Type);
10889 Time_Type := Standard_Duration;
10890 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
10894 if No (Condition (Alt)) then
10896 -- This guard will always be open
10898 Check_Guard := False;
10901 elsif Nkind (Alt) = N_Terminate_Alternative then
10902 Adjust_Condition (Condition (Alt));
10903 Terminate_Alt := Alt;
10906 Num_Alts := Num_Alts + 1;
10910 Else_Present := Present (Else_Statements (N));
10912 -- At the same time (see procedure Add_Accept) we build the accept list:
10914 -- Qnn : Accept_List (1 .. num-select) := (
10915 -- (null-body, entry-index),
10916 -- (null-body, entry-index),
10918 -- (null_body, entry-index));
10920 -- In the above declaration, null-body is True if the corresponding
10921 -- accept has no body, and false otherwise. The entry is either the
10922 -- entry index expression if there is no guard, or if a guard is
10923 -- present, then an if expression of the form:
10925 -- (if guard then entry-index else Null_Task_Entry)
10927 -- If a guard is statically known to be false, the entry can simply
10928 -- be omitted from the accept list.
10931 Make_Object_Declaration (Loc,
10932 Defining_Identifier => Qnam,
10933 Object_Definition => New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10934 Aliased_Present => True,
10936 Make_Qualified_Expression (Loc,
10938 New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10940 Make_Aggregate (Loc, Expressions => Accept_List))));
10942 -- Then we declare the variable that holds the index for the accept
10943 -- that will be selected for service:
10945 -- Xnn : Select_Index;
10948 Make_Object_Declaration (Loc,
10949 Defining_Identifier => Xnam,
10950 Object_Definition =>
10951 New_Occurrence_Of (RTE (RE_Select_Index), Loc),
10953 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)));
10955 -- After this follow procedure declarations for each accept body
10957 -- procedure Pnn is
10962 -- where the ... are statements from the corresponding procedure body.
10963 -- No parameters are involved, since the parameters are passed via Ann
10964 -- and the parameter references have already been expanded to be direct
10965 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10966 -- any embedded tasking statements (which would normally be illegal in
10967 -- procedures), have been converted to calls to the tasking runtime so
10968 -- there is no problem in putting them into procedures.
10970 -- The original accept statement has been expanded into a block in
10971 -- the same fashion as for simple accepts (see Build_Accept_Body).
10973 -- Note: we don't really need to build these procedures for the case
10974 -- where no delay statement is present, but it is just as easy to
10975 -- build them unconditionally, and not significantly inefficient,
10976 -- since if they are short they will be inlined anyway.
10978 -- The procedure declarations have been assembled in Body_List
10980 -- If delays are present, we must compute the required delay.
10981 -- We first generate the declarations:
10983 -- Delay_Index : Boolean := 0;
10984 -- Delay_Min : Some_Time_Type.Time;
10985 -- Delay_Val : Some_Time_Type.Time;
10987 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10988 -- active delay that is actually chosen as the basis for the possible
10989 -- delay if an immediate rendez-vous is not possible.
10991 -- In the most common case there is a single delay statement, and this
10992 -- is handled specially.
10994 if Delay_Count > 0 then
10996 -- Generate the required declarations
10999 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
11001 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
11003 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
11006 Make_Object_Declaration (Loc,
11007 Defining_Identifier => Delay_Val,
11008 Object_Definition => New_Occurrence_Of (Time_Type, Loc)));
11011 Make_Object_Declaration (Loc,
11012 Defining_Identifier => Delay_Index,
11013 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
11014 Expression => Make_Integer_Literal (Loc, 0)));
11017 Make_Object_Declaration (Loc,
11018 Defining_Identifier => Delay_Min,
11019 Object_Definition => New_Occurrence_Of (Time_Type, Loc),
11021 Unchecked_Convert_To (Time_Type,
11022 Make_Attribute_Reference (Loc,
11024 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
11025 Attribute_Name => Name_Last))));
11027 -- Create Duration and Delay_Mode objects used for passing a delay
11030 D := Make_Temporary (Loc, 'D');
11031 M := Make_Temporary (Loc, 'M');
11037 -- Note that these values are defined in s-osprim.ads and must
11038 -- be kept in sync:
11040 -- Relative : constant := 0;
11041 -- Absolute_Calendar : constant := 1;
11042 -- Absolute_RT : constant := 2;
11044 if Time_Type = Standard_Duration then
11045 Discr := Make_Integer_Literal (Loc, 0);
11047 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11048 Discr := Make_Integer_Literal (Loc, 1);
11052 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11053 Discr := Make_Integer_Literal (Loc, 2);
11057 Make_Object_Declaration (Loc,
11058 Defining_Identifier => D,
11059 Object_Definition =>
11060 New_Occurrence_Of (Standard_Duration, Loc)));
11063 Make_Object_Declaration (Loc,
11064 Defining_Identifier => M,
11065 Object_Definition =>
11066 New_Occurrence_Of (Standard_Integer, Loc),
11067 Expression => Discr));
11070 if Check_Guard then
11072 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
11075 Make_Object_Declaration (Loc,
11076 Defining_Identifier => Guard_Open,
11077 Object_Definition =>
11078 New_Occurrence_Of (Standard_Boolean, Loc),
11080 New_Occurrence_Of (Standard_False, Loc)));
11083 -- Delay_Count is zero, don't need M and D set (suppress warning)
11090 if Present (Terminate_Alt) then
11092 -- If the terminate alternative guard is False, use
11093 -- Simple_Mode; otherwise use Terminate_Mode.
11095 if Present (Condition (Terminate_Alt)) then
11096 Select_Mode := Make_If_Expression (Loc,
11097 New_List (Condition (Terminate_Alt),
11098 New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc),
11099 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)));
11101 Select_Mode := New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc);
11104 elsif Else_Present or Delay_Count > 0 then
11105 Select_Mode := New_Occurrence_Of (RTE (RE_Else_Mode), Loc);
11108 Select_Mode := New_Occurrence_Of (RTE (RE_Simple_Mode), Loc);
11111 Select_Call := Make_Select_Call (Select_Mode);
11112 Append (Select_Call, Stats);
11114 -- Now generate code to act on the result. There is an entry
11115 -- in this case for each accept statement with a non-null body,
11116 -- followed by a branch to the statements that follow the Accept.
11117 -- In the absence of delay alternatives, we generate:
11120 -- when No_Rendezvous => -- omitted if simple mode
11135 -- Lab0: Else_Statements;
11138 -- Lab1: Trailing_Statements1;
11141 -- Lab2: Trailing_Statements2;
11146 -- Generate label for common exit
11148 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
11150 -- First entry is the default case, when no rendezvous is possible
11152 Choices := New_List (New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc));
11154 if Else_Present then
11156 -- If no rendezvous is possible, the else part is executed
11158 Lab := Make_And_Declare_Label (0);
11159 Alt_Stats := New_List (
11160 Make_Goto_Statement (Loc,
11161 Name => New_Copy (Identifier (Lab))));
11163 Append (Lab, Trailing_List);
11164 Append_List (Else_Statements (N), Trailing_List);
11165 Append_To (Trailing_List,
11166 Make_Goto_Statement (Loc,
11167 Name => New_Copy (Identifier (End_Lab))));
11169 Alt_Stats := New_List (
11170 Make_Goto_Statement (Loc,
11171 Name => New_Copy (Identifier (End_Lab))));
11174 Append_To (Alt_List,
11175 Make_Case_Statement_Alternative (Loc,
11176 Discrete_Choices => Choices,
11177 Statements => Alt_Stats));
11179 -- We make use of the fact that Accept_Index is an integer type, and
11180 -- generate successive literals for entries for each accept. Only those
11181 -- for which there is a body or trailing statements get a case entry.
11183 Alt := First (Select_Alternatives (N));
11184 Proc := First (Body_List);
11185 while Present (Alt) loop
11187 if Nkind (Alt) = N_Accept_Alternative then
11188 Process_Accept_Alternative (Alt, Index, Proc);
11189 Index := Index + 1;
11192 (Handled_Statement_Sequence (Accept_Statement (Alt)))
11197 elsif Nkind (Alt) = N_Delay_Alternative then
11198 Process_Delay_Alternative (Alt, Delay_Num);
11199 Delay_Num := Delay_Num + 1;
11205 -- An others choice is always added to the main case, as well
11206 -- as the delay case (to satisfy the compiler).
11208 Append_To (Alt_List,
11209 Make_Case_Statement_Alternative (Loc,
11210 Discrete_Choices =>
11211 New_List (Make_Others_Choice (Loc)),
11213 New_List (Make_Goto_Statement (Loc,
11214 Name => New_Copy (Identifier (End_Lab))))));
11216 Accept_Case := New_List (
11217 Make_Case_Statement (Loc,
11218 Expression => New_Occurrence_Of (Xnam, Loc),
11219 Alternatives => Alt_List));
11221 Append_List (Trailing_List, Accept_Case);
11222 Append_List (Body_List, Decls);
11224 -- Construct case statement for trailing statements of delay
11225 -- alternatives, if there are several of them.
11227 if Delay_Count > 1 then
11228 Append_To (Delay_Alt_List,
11229 Make_Case_Statement_Alternative (Loc,
11230 Discrete_Choices =>
11231 New_List (Make_Others_Choice (Loc)),
11233 New_List (Make_Null_Statement (Loc))));
11235 Delay_Case := New_List (
11236 Make_Case_Statement (Loc,
11237 Expression => New_Occurrence_Of (Delay_Index, Loc),
11238 Alternatives => Delay_Alt_List));
11240 Delay_Case := Delay_Alt_List;
11243 -- If there are no delay alternatives, we append the case statement
11244 -- to the statement list.
11246 if Delay_Count = 0 then
11247 Append_List (Accept_Case, Stats);
11249 -- Delay alternatives present
11252 -- If delay alternatives are present we generate:
11254 -- find minimum delay.
11255 -- DX := minimum delay;
11256 -- M := <delay mode>;
11257 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11260 -- if X = No_Rendezvous then
11261 -- case statement for delay statements.
11263 -- case statement for accept alternatives.
11274 -- The type of the delay expression is known to be legal
11276 if Time_Type = Standard_Duration then
11277 Conv := New_Occurrence_Of (Delay_Min, Loc);
11279 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11280 Conv := Make_Function_Call (Loc,
11281 New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
11282 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11286 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11288 Conv := Make_Function_Call (Loc,
11289 New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
11290 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11293 Stmt := Make_Assignment_Statement (Loc,
11294 Name => New_Occurrence_Of (D, Loc),
11295 Expression => Conv);
11297 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11299 Parms := Parameter_Associations (Select_Call);
11301 Parm := First (Parms);
11302 while Present (Parm) and then Parm /= Select_Mode loop
11306 pragma Assert (Present (Parm));
11307 Rewrite (Parm, New_Occurrence_Of (RTE (RE_Delay_Mode), Loc));
11310 -- Prepare two new parameters of Duration and Delay_Mode type
11311 -- which represent the value and the mode of the minimum delay.
11314 Insert_After (Parm, New_Occurrence_Of (M, Loc));
11315 Insert_After (Parm, New_Occurrence_Of (D, Loc));
11317 -- Create a call to RTS
11319 Rewrite (Select_Call,
11320 Make_Procedure_Call_Statement (Loc,
11321 Name => New_Occurrence_Of (RTE (RE_Timed_Selective_Wait), Loc),
11322 Parameter_Associations => Parms));
11324 -- This new call should follow the calculation of the minimum
11327 Insert_List_Before (Select_Call, Delay_List);
11329 if Check_Guard then
11331 Make_Implicit_If_Statement (N,
11332 Condition => New_Occurrence_Of (Guard_Open, Loc),
11333 Then_Statements => New_List (
11334 New_Copy_Tree (Stmt),
11335 New_Copy_Tree (Select_Call)),
11336 Else_Statements => Accept_Or_Raise);
11337 Rewrite (Select_Call, Stmt);
11339 Insert_Before (Select_Call, Stmt);
11343 Make_Implicit_If_Statement (N,
11344 Condition => Make_Op_Eq (Loc,
11345 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
11347 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
11349 Then_Statements => Delay_Case,
11350 Else_Statements => Accept_Case);
11352 Append (Cases, Stats);
11356 Append (End_Lab, Stats);
11358 -- Replace accept statement with appropriate block
11361 Make_Block_Statement (Loc,
11362 Declarations => Decls,
11363 Handled_Statement_Sequence =>
11364 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats)));
11367 -- Note: have to worry more about abort deferral in above code ???
11369 -- Final step is to unstack the Accept_Address entries for all accept
11370 -- statements appearing in accept alternatives in the select statement
11372 Alt := First (Alts);
11373 while Present (Alt) loop
11374 if Nkind (Alt) = N_Accept_Alternative then
11375 Remove_Last_Elmt (Accept_Address
11376 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
11381 end Expand_N_Selective_Accept;
11383 -------------------------------------------
11384 -- Expand_N_Single_Protected_Declaration --
11385 -------------------------------------------
11387 -- A single protected declaration should never be present after semantic
11388 -- analysis because it is transformed into a protected type declaration
11389 -- and an accompanying anonymous object. This routine ensures that the
11390 -- transformation takes place.
11392 procedure Expand_N_Single_Protected_Declaration (N : Node_Id) is
11394 raise Program_Error;
11395 end Expand_N_Single_Protected_Declaration;
11397 --------------------------------------
11398 -- Expand_N_Single_Task_Declaration --
11399 --------------------------------------
11401 -- A single task declaration should never be present after semantic
11402 -- analysis because it is transformed into a task type declaration and
11403 -- an accompanying anonymous object. This routine ensures that the
11404 -- transformation takes place.
11406 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
11408 raise Program_Error;
11409 end Expand_N_Single_Task_Declaration;
11411 ------------------------
11412 -- Expand_N_Task_Body --
11413 ------------------------
11415 -- Given a task body
11417 -- task body tname is
11423 -- This expansion routine converts it into a procedure and sets the
11424 -- elaboration flag for the procedure to true, to represent the fact
11425 -- that the task body is now elaborated:
11427 -- procedure tnameB (_Task : access tnameV) is
11428 -- discriminal : dtype renames _Task.discriminant;
11430 -- procedure _clean is
11432 -- Abort_Defer.all;
11434 -- Abort_Undefer.all;
11439 -- Abort_Undefer.all;
11441 -- System.Task_Stages.Complete_Activation;
11449 -- In addition, if the task body is an activator, then a call to activate
11450 -- tasks is added at the start of the statements, before the call to
11451 -- Complete_Activation, and if in addition the task is a master then it
11452 -- must be established as a master. These calls are inserted and analyzed
11453 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11456 -- There is one discriminal declaration line generated for each
11457 -- discriminant that is present to provide an easy reference point for
11458 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11460 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11461 -- task body procedures have a profile (Arg : System.Address). That is
11462 -- needed because GNARLI has to use the same access-to-subprogram type
11463 -- for all task types. We depend here on knowing that in GNAT, passing
11464 -- an address argument by value is identical to passing a record value
11465 -- by access (in either case a single pointer is passed), so even though
11466 -- this procedure has the wrong profile. In fact it's all OK, since the
11467 -- callings sequence is identical.
11469 procedure Expand_N_Task_Body (N : Node_Id) is
11470 Loc : constant Source_Ptr := Sloc (N);
11471 Ttyp : constant Entity_Id := Corresponding_Spec (N);
11475 Insert_Nod : Node_Id;
11476 -- Used to determine the proper location of wrapper body insertions
11479 -- if no task body procedure, means we had an error in configurable
11480 -- run-time mode, and there is no point in proceeding further.
11482 if No (Task_Body_Procedure (Ttyp)) then
11486 -- Add renaming declarations for discriminals and a declaration for the
11487 -- entry family index (if applicable).
11489 Install_Private_Data_Declarations
11490 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
11492 -- Add a call to Abort_Undefer at the very beginning of the task
11493 -- body since this body is called with abort still deferred.
11495 if Abort_Allowed then
11496 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
11498 (First (Statements (Handled_Statement_Sequence (N))), Call);
11502 -- The statement part has already been protected with an at_end and
11503 -- cleanup actions. The call to Complete_Activation must be placed
11504 -- at the head of the sequence of statements of that block. The
11505 -- declarations have been merged in this sequence of statements but
11506 -- the first real statement is accessible from the First_Real_Statement
11507 -- field (which was set for exactly this purpose).
11509 if Restricted_Profile then
11510 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
11512 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
11516 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
11520 Make_Subprogram_Body (Loc,
11521 Specification => Build_Task_Proc_Specification (Ttyp),
11522 Declarations => Declarations (N),
11523 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
11524 Set_Is_Task_Body_Procedure (New_N);
11526 -- If the task contains generic instantiations, cleanup actions are
11527 -- delayed until after instantiation. Transfer the activation chain to
11528 -- the subprogram, to insure that the activation call is properly
11529 -- generated. It the task body contains inner tasks, indicate that the
11530 -- subprogram is a task master.
11532 if Delay_Cleanups (Ttyp) then
11533 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
11534 Set_Is_Task_Master (New_N, Is_Task_Master (N));
11537 Rewrite (N, New_N);
11540 -- Set elaboration flag immediately after task body. If the body is a
11541 -- subunit, the flag is set in the declarative part containing the stub.
11543 if Nkind (Parent (N)) /= N_Subunit then
11545 Make_Assignment_Statement (Loc,
11547 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
11548 Expression => New_Occurrence_Of (Standard_True, Loc)));
11551 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11552 -- the task body. At this point all wrapper specs have been created,
11553 -- frozen and included in the dispatch table for the task type.
11555 if Ada_Version >= Ada_2005 then
11556 if Nkind (Parent (N)) = N_Subunit then
11557 Insert_Nod := Corresponding_Stub (Parent (N));
11562 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
11564 end Expand_N_Task_Body;
11566 ------------------------------------
11567 -- Expand_N_Task_Type_Declaration --
11568 ------------------------------------
11570 -- We have several things to do. First we must create a Boolean flag used
11571 -- to mark if the body is elaborated yet. This variable gets set to True
11572 -- when the body of the task is elaborated (we can't rely on the normal
11573 -- ABE mechanism for the task body, since we need to pass an access to
11574 -- this elaboration boolean to the runtime routines).
11576 -- taskE : aliased Boolean := False;
11578 -- Next a variable is declared to hold the task stack size (either the
11579 -- default : Unspecified_Size, or a value that is set by a pragma
11580 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11581 -- the variable is initialized with this value:
11583 -- taskZ : Size_Type := Unspecified_Size;
11585 -- taskZ : Size_Type := Size_Type (size_expression);
11587 -- Note: No variable is needed to hold the task relative deadline since
11588 -- its value would never be static because the parameter is of a private
11589 -- type (Ada.Real_Time.Time_Span).
11591 -- Next we create a corresponding record type declaration used to represent
11592 -- values of this task. The general form of this type declaration is
11594 -- type taskV (discriminants) is record
11595 -- _Task_Id : Task_Id;
11596 -- entry_family : array (bounds) of Void;
11597 -- _Priority : Integer := priority_expression;
11598 -- _Size : Size_Type := size_expression;
11599 -- _Secondary_Stack_Size : Size_Type := size_expression;
11600 -- _Task_Info : Task_Info_Type := task_info_expression;
11601 -- _CPU : Integer := cpu_range_expression;
11602 -- _Relative_Deadline : Time_Span := time_span_expression;
11603 -- _Domain : Dispatching_Domain := dd_expression;
11606 -- The discriminants are present only if the corresponding task type has
11607 -- discriminants, and they exactly mirror the task type discriminants.
11609 -- The Id field is always present. It contains the Task_Id value, as set by
11610 -- the call to Create_Task. Note that although the task is limited, the
11611 -- task value record type is not limited, so there is no problem in passing
11612 -- this field as an out parameter to Create_Task.
11614 -- One entry_family component is present for each entry family in the task
11615 -- definition. The bounds correspond to the bounds of the entry family
11616 -- (which may depend on discriminants). The element type is void, since we
11617 -- only need the bounds information for determining the entry index. Note
11618 -- that the use of an anonymous array would normally be illegal in this
11619 -- context, but this is a parser check, and the semantics is quite prepared
11620 -- to handle such a case.
11622 -- The _Size field is present only if a Storage_Size pragma appears in the
11623 -- task definition. The expression captures the argument that was present
11624 -- in the pragma, and is used to override the task stack size otherwise
11625 -- associated with the task type.
11627 -- The _Secondary_Stack_Size field is present only the task entity has a
11628 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11629 -- when the record init proc is built, to capture the expression of the
11630 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11631 -- be filled here since aspect evaluations are delayed till the freeze
11634 -- The _Priority field is present only if the task entity has a Priority or
11635 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11636 -- definition clause). It will be filled at the freeze point, when the
11637 -- record init proc is built, to capture the expression of the rep item
11638 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11639 -- here since aspect evaluations are delayed till the freeze point.
11641 -- The _Task_Info field is present only if a Task_Info pragma appears in
11642 -- the task definition. The expression captures the argument that was
11643 -- present in the pragma, and is used to provide the Task_Image parameter
11644 -- to the call to Create_Task.
11646 -- The _CPU field is present only if the task entity has a CPU rep item
11647 -- (pragma, aspect specification or attribute definition clause). It will
11648 -- be filled at the freeze point, when the record init proc is built, to
11649 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11650 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11651 -- are delayed till the freeze point.
11653 -- The _Relative_Deadline field is present only if a Relative_Deadline
11654 -- pragma appears in the task definition. The expression captures the
11655 -- argument that was present in the pragma, and is used to provide the
11656 -- Relative_Deadline parameter to the call to Create_Task.
11658 -- The _Domain field is present only if the task entity has a
11659 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11660 -- definition clause). It will be filled at the freeze point, when the
11661 -- record init proc is built, to capture the expression of the rep item
11662 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11663 -- here since aspect evaluations are delayed till the freeze point.
11665 -- When a task is declared, an instance of the task value record is
11666 -- created. The elaboration of this declaration creates the correct bounds
11667 -- for the entry families, and also evaluates the size, priority, and
11668 -- task_Info expressions if needed. The initialization routine for the task
11669 -- type itself then calls Create_Task with appropriate parameters to
11670 -- initialize the value of the Task_Id field.
11672 -- Note: the address of this record is passed as the "Discriminants"
11673 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11674 -- body procedure, it does not matter that it does not quite match the
11675 -- GNARLI model of what is being passed (the record contains more than just
11676 -- the discriminants, but the discriminants can be found from the record
11679 -- The Entity_Id for this created record type is placed in the
11680 -- Corresponding_Record_Type field of the associated task type entity.
11682 -- Next we create a procedure specification for the task body procedure:
11684 -- procedure taskB (_Task : access taskV);
11686 -- Note that this must come after the record type declaration, since
11687 -- the spec refers to this type. It turns out that the initialization
11688 -- procedure for the value type references the task body spec, but that's
11689 -- fine, since it won't be generated till the freeze point for the type,
11690 -- which is certainly after the task body spec declaration.
11692 -- Finally, we set the task index value field of the entry attribute in
11693 -- the case of a simple entry.
11695 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
11696 Loc : constant Source_Ptr := Sloc (N);
11697 TaskId : constant Entity_Id := Defining_Identifier (N);
11698 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
11699 Tasknm : constant Name_Id := Chars (Tasktyp);
11700 Taskdef : constant Node_Id := Task_Definition (N);
11702 Body_Decl : Node_Id;
11704 Decl_Stack : Node_Id;
11705 Elab_Decl : Node_Id;
11706 Ent_Stack : Entity_Id;
11707 Proc_Spec : Node_Id;
11708 Rec_Decl : Node_Id;
11709 Rec_Ent : Entity_Id;
11710 Size_Decl : Entity_Id;
11711 Task_Size : Node_Id;
11713 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id;
11714 -- Searches the task definition T for the first occurrence of the pragma
11715 -- Relative Deadline. The caller has ensured that the pragma is present
11716 -- in the task definition. Note that this routine cannot be implemented
11717 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11718 -- not chained because their expansion into a procedure call statement
11719 -- would cause a break in the chain.
11721 ----------------------------------
11722 -- Get_Relative_Deadline_Pragma --
11723 ----------------------------------
11725 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id is
11729 N := First (Visible_Declarations (T));
11730 while Present (N) loop
11731 if Nkind (N) = N_Pragma
11732 and then Pragma_Name (N) = Name_Relative_Deadline
11740 N := First (Private_Declarations (T));
11741 while Present (N) loop
11742 if Nkind (N) = N_Pragma
11743 and then Pragma_Name (N) = Name_Relative_Deadline
11751 raise Program_Error;
11752 end Get_Relative_Deadline_Pragma;
11754 -- Start of processing for Expand_N_Task_Type_Declaration
11757 -- If already expanded, nothing to do
11759 if Present (Corresponding_Record_Type (Tasktyp)) then
11763 -- Here we will do the expansion
11765 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
11767 Rec_Ent := Defining_Identifier (Rec_Decl);
11768 Cdecls := Component_Items (Component_List
11769 (Type_Definition (Rec_Decl)));
11771 Qualify_Entity_Names (N);
11773 -- First create the elaboration variable
11776 Make_Object_Declaration (Loc,
11777 Defining_Identifier =>
11778 Make_Defining_Identifier (Sloc (Tasktyp),
11779 Chars => New_External_Name (Tasknm, 'E')),
11780 Aliased_Present => True,
11781 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
11782 Expression => New_Occurrence_Of (Standard_False, Loc));
11784 Insert_After (N, Elab_Decl);
11786 -- Next create the declaration of the size variable (tasknmZ)
11788 Set_Storage_Size_Variable (Tasktyp,
11789 Make_Defining_Identifier (Sloc (Tasktyp),
11790 Chars => New_External_Name (Tasknm, 'Z')));
11792 if Present (Taskdef)
11793 and then Has_Storage_Size_Pragma (Taskdef)
11795 Is_OK_Static_Expression
11797 (First (Pragma_Argument_Associations
11798 (Get_Rep_Pragma (TaskId, Name_Storage_Size)))))
11801 Make_Object_Declaration (Loc,
11802 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11803 Object_Definition =>
11804 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11806 Convert_To (RTE (RE_Size_Type),
11808 (Expression (First (Pragma_Argument_Associations
11810 (TaskId, Name_Storage_Size)))))));
11814 Make_Object_Declaration (Loc,
11815 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11816 Object_Definition =>
11817 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11819 New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
11822 Insert_After (Elab_Decl, Size_Decl);
11824 -- Next build the rest of the corresponding record declaration. This is
11825 -- done last, since the corresponding record initialization procedure
11826 -- will reference the previously created entities.
11828 -- Fill in the component declarations -- first the _Task_Id field
11831 Make_Component_Declaration (Loc,
11832 Defining_Identifier =>
11833 Make_Defining_Identifier (Loc, Name_uTask_Id),
11834 Component_Definition =>
11835 Make_Component_Definition (Loc,
11836 Aliased_Present => False,
11837 Subtype_Indication => New_Occurrence_Of (RTE (RO_ST_Task_Id),
11840 -- Declare static ATCB (that is, created by the expander) if we are
11841 -- using the Restricted run time.
11843 if Restricted_Profile then
11845 Make_Component_Declaration (Loc,
11846 Defining_Identifier =>
11847 Make_Defining_Identifier (Loc, Name_uATCB),
11849 Component_Definition =>
11850 Make_Component_Definition (Loc,
11851 Aliased_Present => True,
11852 Subtype_Indication => Make_Subtype_Indication (Loc,
11854 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
11857 Make_Index_Or_Discriminant_Constraint (Loc,
11859 New_List (Make_Integer_Literal (Loc, 0)))))));
11863 -- Declare static stack (that is, created by the expander) if we are
11864 -- using the Restricted run time on a bare board configuration.
11866 if Restricted_Profile and then Preallocated_Stacks_On_Target then
11868 -- First we need to extract the appropriate stack size
11870 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
11872 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11874 Expr_N : constant Node_Id :=
11875 Expression (First (
11876 Pragma_Argument_Associations (
11877 Get_Rep_Pragma (TaskId, Name_Storage_Size))));
11878 Etyp : constant Entity_Id := Etype (Expr_N);
11879 P : constant Node_Id := Parent (Expr_N);
11882 -- The stack is defined inside the corresponding record.
11883 -- Therefore if the size of the stack is set by means of
11884 -- a discriminant, we must reference the discriminant of the
11885 -- corresponding record type.
11887 if Nkind (Expr_N) in N_Has_Entity
11888 and then Present (Discriminal_Link (Entity (Expr_N)))
11892 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
11894 Set_Parent (Task_Size, P);
11895 Set_Etype (Task_Size, Etyp);
11896 Set_Analyzed (Task_Size);
11899 Task_Size := Relocate_Node (Expr_N);
11905 New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc);
11908 Decl_Stack := Make_Component_Declaration (Loc,
11909 Defining_Identifier => Ent_Stack,
11911 Component_Definition =>
11912 Make_Component_Definition (Loc,
11913 Aliased_Present => True,
11914 Subtype_Indication => Make_Subtype_Indication (Loc,
11916 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
11919 Make_Index_Or_Discriminant_Constraint (Loc,
11920 Constraints => New_List (Make_Range (Loc,
11921 Low_Bound => Make_Integer_Literal (Loc, 1),
11922 High_Bound => Convert_To (RTE (RE_Storage_Offset),
11925 Append_To (Cdecls, Decl_Stack);
11927 -- The appropriate alignment for the stack is ensured by the run-time
11928 -- code in charge of task creation.
11932 -- Add components for entry families
11934 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
11936 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11937 -- item is present.
11939 if Has_Rep_Item (TaskId, Name_Priority, Check_Parents => False) then
11941 Make_Component_Declaration (Loc,
11942 Defining_Identifier =>
11943 Make_Defining_Identifier (Loc, Name_uPriority),
11944 Component_Definition =>
11945 Make_Component_Definition (Loc,
11946 Aliased_Present => False,
11947 Subtype_Indication =>
11948 New_Occurrence_Of (Standard_Integer, Loc))));
11951 -- Add the _Size component if a Storage_Size pragma is present
11953 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11955 Make_Component_Declaration (Loc,
11956 Defining_Identifier =>
11957 Make_Defining_Identifier (Loc, Name_uSize),
11959 Component_Definition =>
11960 Make_Component_Definition (Loc,
11961 Aliased_Present => False,
11962 Subtype_Indication =>
11963 New_Occurrence_Of (RTE (RE_Size_Type), Loc)),
11966 Convert_To (RTE (RE_Size_Type),
11968 Expression (First (
11969 Pragma_Argument_Associations (
11970 Get_Rep_Pragma (TaskId, Name_Storage_Size))))))));
11973 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
11974 -- rep item is present.
11977 (TaskId, Name_Secondary_Stack_Size, Check_Parents => False)
11980 Make_Component_Declaration (Loc,
11981 Defining_Identifier =>
11982 Make_Defining_Identifier (Loc, Name_uSecondary_Stack_Size),
11984 Component_Definition =>
11985 Make_Component_Definition (Loc,
11986 Aliased_Present => False,
11987 Subtype_Indication =>
11988 New_Occurrence_Of (RTE (RE_Size_Type), Loc))));
11991 -- Add the _Task_Info component if a Task_Info pragma is present
11993 if Has_Rep_Pragma (TaskId, Name_Task_Info, Check_Parents => False) then
11995 Make_Component_Declaration (Loc,
11996 Defining_Identifier =>
11997 Make_Defining_Identifier (Loc, Name_uTask_Info),
11999 Component_Definition =>
12000 Make_Component_Definition (Loc,
12001 Aliased_Present => False,
12002 Subtype_Indication =>
12003 New_Occurrence_Of (RTE (RE_Task_Info_Type), Loc)),
12005 Expression => New_Copy (
12006 Expression (First (
12007 Pragma_Argument_Associations (
12009 (TaskId, Name_Task_Info, Check_Parents => False)))))));
12012 -- Add the _CPU component if a CPU rep item is present
12014 if Has_Rep_Item (TaskId, Name_CPU, Check_Parents => False) then
12016 Make_Component_Declaration (Loc,
12017 Defining_Identifier =>
12018 Make_Defining_Identifier (Loc, Name_uCPU),
12020 Component_Definition =>
12021 Make_Component_Definition (Loc,
12022 Aliased_Present => False,
12023 Subtype_Indication =>
12024 New_Occurrence_Of (RTE (RE_CPU_Range), Loc))));
12027 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
12028 -- present. If we are using a restricted run time this component will
12029 -- not be added (deadlines are not allowed by the Ravenscar profile).
12031 if not Restricted_Profile
12032 and then Present (Taskdef)
12033 and then Has_Relative_Deadline_Pragma (Taskdef)
12036 Make_Component_Declaration (Loc,
12037 Defining_Identifier =>
12038 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
12040 Component_Definition =>
12041 Make_Component_Definition (Loc,
12042 Aliased_Present => False,
12043 Subtype_Indication =>
12044 New_Occurrence_Of (RTE (RE_Time_Span), Loc)),
12047 Convert_To (RTE (RE_Time_Span),
12049 Expression (First (
12050 Pragma_Argument_Associations (
12051 Get_Relative_Deadline_Pragma (Taskdef))))))));
12054 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12055 -- item is present. If we are using a restricted run time this component
12056 -- will not be added (dispatching domains are not allowed by the
12057 -- Ravenscar profile).
12059 if not Restricted_Profile
12062 (TaskId, Name_Dispatching_Domain, Check_Parents => False)
12065 Make_Component_Declaration (Loc,
12066 Defining_Identifier =>
12067 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
12069 Component_Definition =>
12070 Make_Component_Definition (Loc,
12071 Aliased_Present => False,
12072 Subtype_Indication =>
12074 (RTE (RE_Dispatching_Domain_Access), Loc))));
12077 Insert_After (Size_Decl, Rec_Decl);
12079 -- Analyze the record declaration immediately after construction,
12080 -- because the initialization procedure is needed for single task
12081 -- declarations before the next entity is analyzed.
12083 Analyze (Rec_Decl);
12085 -- Create the declaration of the task body procedure
12087 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
12089 Make_Subprogram_Declaration (Loc,
12090 Specification => Proc_Spec);
12091 Set_Is_Task_Body_Procedure (Body_Decl);
12093 Insert_After (Rec_Decl, Body_Decl);
12095 -- The subprogram does not comes from source, so we have to indicate the
12096 -- need for debugging information explicitly.
12098 if Comes_From_Source (Original_Node (N)) then
12099 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
12102 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12103 -- the corresponding record has been frozen.
12105 if Ada_Version >= Ada_2005 then
12106 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
12109 -- Ada 2005 (AI-345): We must defer freezing to allow further
12110 -- declaration of primitive subprograms covering task interfaces
12112 if Ada_Version <= Ada_95 then
12114 -- Now we can freeze the corresponding record. This needs manually
12115 -- freezing, since it is really part of the task type, and the task
12116 -- type is frozen at this stage. We of course need the initialization
12117 -- procedure for this corresponding record type and we won't get it
12118 -- in time if we don't freeze now.
12121 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
12123 if Is_Non_Empty_List (L) then
12124 Insert_List_After (Body_Decl, L);
12129 -- Complete the expansion of access types to the current task type, if
12130 -- any were declared.
12132 Expand_Previous_Access_Type (Tasktyp);
12134 -- Create wrappers for entries that have contract cases, preconditions
12135 -- and postconditions.
12141 Ent := First_Entity (Tasktyp);
12142 while Present (Ent) loop
12143 if Ekind_In (Ent, E_Entry, E_Entry_Family) then
12144 Build_Contract_Wrapper (Ent, N);
12150 end Expand_N_Task_Type_Declaration;
12152 -------------------------------
12153 -- Expand_N_Timed_Entry_Call --
12154 -------------------------------
12156 -- A timed entry call in normal case is not implemented using ATC mechanism
12157 -- anymore for efficiency reason.
12167 -- is expanded as follows:
12169 -- 1) When T.E is a task entry_call;
12173 -- X : Task_Entry_Index := <entry index>;
12174 -- DX : Duration := To_Duration (D);
12175 -- M : Delay_Mode := <discriminant>;
12176 -- P : parms := (parm, parm, parm);
12179 -- Timed_Protected_Entry_Call
12180 -- (<acceptor-task>, X, P'Address, DX, M, B);
12188 -- 2) When T.E is a protected entry_call;
12192 -- X : Protected_Entry_Index := <entry index>;
12193 -- DX : Duration := To_Duration (D);
12194 -- M : Delay_Mode := <discriminant>;
12195 -- P : parms := (parm, parm, parm);
12198 -- Timed_Protected_Entry_Call
12199 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12207 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12208 -- is no delay and the triggering statements are executed. We first
12209 -- determine the kind of the triggering call and then execute a
12210 -- synchronized operation or a direct call.
12213 -- B : Boolean := False;
12214 -- C : Ada.Tags.Prim_Op_Kind;
12215 -- DX : Duration := To_Duration (D)
12216 -- K : Ada.Tags.Tagged_Kind :=
12217 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12218 -- M : Integer :=...;
12219 -- P : Parameters := (Param1 .. ParamN);
12223 -- if K = Ada.Tags.TK_Limited_Tagged
12224 -- or else K = Ada.Tags.TK_Tagged
12226 -- <dispatching-call>;
12231 -- Ada.Tags.Get_Offset_Index
12232 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12234 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12236 -- if C = POK_Protected_Entry
12237 -- or else C = POK_Task_Entry
12239 -- Param1 := P.Param1;
12241 -- ParamN := P.ParamN;
12245 -- if C = POK_Procedure
12246 -- or else C = POK_Protected_Procedure
12247 -- or else C = POK_Task_Procedure
12249 -- <dispatching-call>;
12255 -- <triggering-statements>
12257 -- <timed-statements>
12261 -- The triggering statement and the sequence of timed statements have not
12262 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12263 -- global references if within an instantiation.
12265 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
12266 Loc : constant Source_Ptr := Sloc (N);
12269 Blk_Typ : Entity_Id;
12271 Call_Ent : Entity_Id;
12272 Conc_Typ_Stmts : List_Id;
12274 D_Alt : constant Node_Id := Delay_Alternative (N);
12277 D_Stat : Node_Id := Delay_Statement (D_Alt);
12279 D_Type : Entity_Id;
12282 E_Alt : constant Node_Id := Entry_Call_Alternative (N);
12283 E_Call : Node_Id := Entry_Call_Statement (E_Alt);
12288 Is_Disp_Select : Boolean;
12289 Lim_Typ_Stmts : List_Id;
12298 B : Entity_Id; -- Call status flag
12299 C : Entity_Id; -- Call kind
12300 D : Entity_Id; -- Delay
12301 K : Entity_Id; -- Tagged kind
12302 M : Entity_Id; -- Delay mode
12303 P : Entity_Id; -- Parameter block
12304 S : Entity_Id; -- Primitive operation slot
12306 -- Start of processing for Expand_N_Timed_Entry_Call
12309 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12310 -- was already reported on spec, so do not attempt to expand the call.
12312 if Restriction_Active (No_Select_Statements) then
12316 Process_Statements_For_Controlled_Objects (E_Alt);
12317 Process_Statements_For_Controlled_Objects (D_Alt);
12319 Ensure_Statement_Present (Sloc (D_Stat), D_Alt);
12321 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12322 -- may wrap them in blocks.
12324 E_Stats := Statements (E_Alt);
12325 D_Stats := Statements (D_Alt);
12327 -- The arguments in the call may require dynamic allocation, and the
12328 -- call statement may have been transformed into a block. The block
12329 -- may contain additional declarations for internal entities, and the
12330 -- original call is found by sequential search.
12332 if Nkind (E_Call) = N_Block_Statement then
12333 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
12334 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
12335 N_Entry_Call_Statement)
12342 Ada_Version >= Ada_2005
12343 and then Nkind (E_Call) = N_Procedure_Call_Statement;
12345 if Is_Disp_Select then
12346 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
12352 -- B : Boolean := False;
12354 B := Build_B (Loc, Decls);
12357 -- C : Ada.Tags.Prim_Op_Kind;
12359 C := Build_C (Loc, Decls);
12361 -- Because the analysis of all statements was disabled, manually
12362 -- analyze the delay statement.
12365 D_Stat := Original_Node (D_Stat);
12368 -- Build an entry call using Simple_Entry_Call
12370 Extract_Entry (E_Call, Concval, Ename, Index);
12371 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
12373 Decls := Declarations (E_Call);
12374 Stmts := Statements (Handled_Statement_Sequence (E_Call));
12383 B := Make_Defining_Identifier (Loc, Name_uB);
12386 Make_Object_Declaration (Loc,
12387 Defining_Identifier => B,
12388 Object_Definition =>
12389 New_Occurrence_Of (Standard_Boolean, Loc)));
12392 -- Duration and mode processing
12394 D_Type := Base_Type (Etype (Expression (D_Stat)));
12396 -- Use the type of the delay expression (Calendar or Real_Time) to
12397 -- generate the appropriate conversion.
12399 if Nkind (D_Stat) = N_Delay_Relative_Statement then
12400 D_Disc := Make_Integer_Literal (Loc, 0);
12401 D_Conv := Relocate_Node (Expression (D_Stat));
12403 elsif Is_RTE (D_Type, RO_CA_Time) then
12404 D_Disc := Make_Integer_Literal (Loc, 1);
12406 Make_Function_Call (Loc,
12407 Name => New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
12408 Parameter_Associations =>
12409 New_List (New_Copy (Expression (D_Stat))));
12411 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
12412 D_Disc := Make_Integer_Literal (Loc, 2);
12414 Make_Function_Call (Loc,
12415 Name => New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
12416 Parameter_Associations =>
12417 New_List (New_Copy (Expression (D_Stat))));
12420 D := Make_Temporary (Loc, 'D');
12426 Make_Object_Declaration (Loc,
12427 Defining_Identifier => D,
12428 Object_Definition => New_Occurrence_Of (Standard_Duration, Loc)));
12430 M := Make_Temporary (Loc, 'M');
12433 -- M : Integer := (0 | 1 | 2);
12436 Make_Object_Declaration (Loc,
12437 Defining_Identifier => M,
12438 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
12439 Expression => D_Disc));
12441 -- Do the assignment at this stage only because the evaluation of the
12442 -- expression must not occur before (see ACVC C97302A).
12445 Make_Assignment_Statement (Loc,
12446 Name => New_Occurrence_Of (D, Loc),
12447 Expression => D_Conv));
12449 -- Parameter block processing
12451 -- Manually create the parameter block for dispatching calls. In the
12452 -- case of entries, the block has already been created during the call
12453 -- to Build_Simple_Entry_Call.
12455 if Is_Disp_Select then
12457 -- Tagged kind processing, generate:
12458 -- K : Ada.Tags.Tagged_Kind :=
12459 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12461 K := Build_K (Loc, Decls, Obj);
12463 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
12465 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
12467 -- Dispatch table slot processing, generate:
12470 S := Build_S (Loc, Decls);
12473 -- S := Ada.Tags.Get_Offset_Index
12474 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12477 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
12480 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12482 -- where Obj is the controlling formal parameter, S is the dispatch
12483 -- table slot number of the dispatching operation, P is the wrapped
12484 -- parameter block, D is the duration, M is the duration mode, C is
12485 -- the call kind and B is the call status.
12487 Params := New_List;
12489 Append_To (Params, New_Copy_Tree (Obj));
12490 Append_To (Params, New_Occurrence_Of (S, Loc));
12492 Make_Attribute_Reference (Loc,
12493 Prefix => New_Occurrence_Of (P, Loc),
12494 Attribute_Name => Name_Address));
12495 Append_To (Params, New_Occurrence_Of (D, Loc));
12496 Append_To (Params, New_Occurrence_Of (M, Loc));
12497 Append_To (Params, New_Occurrence_Of (C, Loc));
12498 Append_To (Params, New_Occurrence_Of (B, Loc));
12500 Append_To (Conc_Typ_Stmts,
12501 Make_Procedure_Call_Statement (Loc,
12505 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
12506 Parameter_Associations => Params));
12509 -- if C = POK_Protected_Entry
12510 -- or else C = POK_Task_Entry
12512 -- Param1 := P.Param1;
12514 -- ParamN := P.ParamN;
12517 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
12519 -- Generate the if statement only when the packed parameters need
12520 -- explicit assignments to their corresponding actuals.
12522 if Present (Unpack) then
12523 Append_To (Conc_Typ_Stmts,
12524 Make_Implicit_If_Statement (N,
12530 Left_Opnd => New_Occurrence_Of (C, Loc),
12533 (RTE (RE_POK_Protected_Entry), Loc)),
12537 Left_Opnd => New_Occurrence_Of (C, Loc),
12539 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
12541 Then_Statements => Unpack));
12547 -- if C = POK_Procedure
12548 -- or else C = POK_Protected_Procedure
12549 -- or else C = POK_Task_Procedure
12551 -- <dispatching-call>
12555 N_Stats := New_List (
12556 Make_Implicit_If_Statement (N,
12561 Left_Opnd => New_Occurrence_Of (C, Loc),
12563 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
12569 Left_Opnd => New_Occurrence_Of (C, Loc),
12571 New_Occurrence_Of (RTE (
12572 RE_POK_Protected_Procedure), Loc)),
12575 Left_Opnd => New_Occurrence_Of (C, Loc),
12578 (RTE (RE_POK_Task_Procedure), Loc)))),
12580 Then_Statements => New_List (E_Call)));
12582 Append_To (Conc_Typ_Stmts,
12583 Make_Implicit_If_Statement (N,
12584 Condition => New_Occurrence_Of (B, Loc),
12585 Then_Statements => N_Stats));
12588 -- <dispatching-call>;
12592 New_List (New_Copy_Tree (E_Call),
12593 Make_Assignment_Statement (Loc,
12594 Name => New_Occurrence_Of (B, Loc),
12595 Expression => New_Occurrence_Of (Standard_True, Loc)));
12598 -- if K = Ada.Tags.TK_Limited_Tagged
12599 -- or else K = Ada.Tags.TK_Tagged
12607 Make_Implicit_If_Statement (N,
12608 Condition => Build_Dispatching_Tag_Check (K, N),
12609 Then_Statements => Lim_Typ_Stmts,
12610 Else_Statements => Conc_Typ_Stmts));
12615 -- <triggering-statements>
12617 -- <timed-statements>
12621 Make_Implicit_If_Statement (N,
12622 Condition => New_Occurrence_Of (B, Loc),
12623 Then_Statements => E_Stats,
12624 Else_Statements => D_Stats));
12627 -- Simple case of a nondispatching trigger. Skip assignments to
12628 -- temporaries created for in-out parameters.
12630 -- This makes unwarranted assumptions about the shape of the expanded
12631 -- tree for the call, and should be cleaned up ???
12633 Stmt := First (Stmts);
12634 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
12638 -- Do the assignment at this stage only because the evaluation
12639 -- of the expression must not occur before (see ACVC C97302A).
12641 Insert_Before (Stmt,
12642 Make_Assignment_Statement (Loc,
12643 Name => New_Occurrence_Of (D, Loc),
12644 Expression => D_Conv));
12647 Params := Parameter_Associations (Call);
12649 -- For a protected type, we build a Timed_Protected_Entry_Call
12651 if Is_Protected_Type (Etype (Concval)) then
12653 -- Create a new call statement
12655 Param := First (Params);
12656 while Present (Param)
12657 and then not Is_RTE (Etype (Param), RE_Call_Modes)
12662 Dummy := Remove_Next (Next (Param));
12664 -- Remove garbage is following the Cancel_Param if present
12666 Dummy := Next (Param);
12668 -- Remove the mode of the Protected_Entry_Call call, then remove
12669 -- the Communication_Block of the Protected_Entry_Call call, and
12670 -- finally add Duration and a Delay_Mode parameter
12672 pragma Assert (Present (Param));
12673 Rewrite (Param, New_Occurrence_Of (D, Loc));
12675 Rewrite (Dummy, New_Occurrence_Of (M, Loc));
12677 -- Add a Boolean flag for successful entry call
12679 Append_To (Params, New_Occurrence_Of (B, Loc));
12681 case Corresponding_Runtime_Package (Etype (Concval)) is
12682 when System_Tasking_Protected_Objects_Entries =>
12684 Make_Procedure_Call_Statement (Loc,
12687 (RTE (RE_Timed_Protected_Entry_Call), Loc),
12688 Parameter_Associations => Params));
12691 raise Program_Error;
12694 -- For the task case, build a Timed_Task_Entry_Call
12697 -- Create a new call statement
12699 Append_To (Params, New_Occurrence_Of (D, Loc));
12700 Append_To (Params, New_Occurrence_Of (M, Loc));
12701 Append_To (Params, New_Occurrence_Of (B, Loc));
12704 Make_Procedure_Call_Statement (Loc,
12706 New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
12707 Parameter_Associations => Params));
12711 Make_Implicit_If_Statement (N,
12712 Condition => New_Occurrence_Of (B, Loc),
12713 Then_Statements => E_Stats,
12714 Else_Statements => D_Stats));
12718 Make_Block_Statement (Loc,
12719 Declarations => Decls,
12720 Handled_Statement_Sequence =>
12721 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
12724 end Expand_N_Timed_Entry_Call;
12726 ----------------------------------------
12727 -- Expand_Protected_Body_Declarations --
12728 ----------------------------------------
12730 procedure Expand_Protected_Body_Declarations
12732 Spec_Id : Entity_Id)
12735 if No_Run_Time_Mode then
12736 Error_Msg_CRT ("protected body", N);
12739 elsif Expander_Active then
12741 -- Associate discriminals with the first subprogram or entry body to
12744 if Present (First_Protected_Operation (Declarations (N))) then
12745 Set_Discriminals (Parent (Spec_Id));
12748 end Expand_Protected_Body_Declarations;
12750 -------------------------
12751 -- External_Subprogram --
12752 -------------------------
12754 function External_Subprogram (E : Entity_Id) return Entity_Id is
12755 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
12758 -- The internal and external subprograms follow each other on the entity
12759 -- chain. Note that previously private operations had no separate
12760 -- external subprogram. We now create one in all cases, because a
12761 -- private operation may actually appear in an external call, through
12762 -- a 'Access reference used for a callback.
12764 -- If the operation is a function that returns an anonymous access type,
12765 -- the corresponding itype appears before the operation, and must be
12768 -- This mechanism is fragile, there should be a real link between the
12769 -- two versions of the operation, but there is no place to put it ???
12771 if Is_Access_Type (Next_Entity (Subp)) then
12772 return Next_Entity (Next_Entity (Subp));
12774 return Next_Entity (Subp);
12776 end External_Subprogram;
12778 ------------------------------
12779 -- Extract_Dispatching_Call --
12780 ------------------------------
12782 procedure Extract_Dispatching_Call
12784 Call_Ent : out Entity_Id;
12785 Object : out Entity_Id;
12786 Actuals : out List_Id;
12787 Formals : out List_Id)
12789 Call_Nam : Node_Id;
12792 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
12794 if Present (Original_Node (N)) then
12795 Call_Nam := Name (Original_Node (N));
12797 Call_Nam := Name (N);
12800 -- Retrieve the name of the dispatching procedure. It contains the
12801 -- dispatch table slot number.
12804 case Nkind (Call_Nam) is
12805 when N_Identifier =>
12808 when N_Selected_Component =>
12809 Call_Nam := Selector_Name (Call_Nam);
12812 raise Program_Error;
12816 Actuals := Parameter_Associations (N);
12817 Call_Ent := Entity (Call_Nam);
12818 Formals := Parameter_Specifications (Parent (Call_Ent));
12819 Object := First (Actuals);
12821 if Present (Original_Node (Object)) then
12822 Object := Original_Node (Object);
12825 -- If the type of the dispatching object is an access type then return
12826 -- an explicit dereference.
12828 if Is_Access_Type (Etype (Object)) then
12829 Object := Make_Explicit_Dereference (Sloc (N), Object);
12832 end Extract_Dispatching_Call;
12834 -------------------
12835 -- Extract_Entry --
12836 -------------------
12838 procedure Extract_Entry
12840 Concval : out Node_Id;
12841 Ename : out Node_Id;
12842 Index : out Node_Id)
12844 Nam : constant Node_Id := Name (N);
12847 -- For a simple entry, the name is a selected component, with the
12848 -- prefix being the task value, and the selector being the entry.
12850 if Nkind (Nam) = N_Selected_Component then
12851 Concval := Prefix (Nam);
12852 Ename := Selector_Name (Nam);
12855 -- For a member of an entry family, the name is an indexed component
12856 -- where the prefix is a selected component, whose prefix in turn is
12857 -- the task value, and whose selector is the entry family. The single
12858 -- expression in the expressions list of the indexed component is the
12859 -- subscript for the family.
12861 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
12862 Concval := Prefix (Prefix (Nam));
12863 Ename := Selector_Name (Prefix (Nam));
12864 Index := First (Expressions (Nam));
12867 -- Through indirection, the type may actually be a limited view of a
12868 -- concurrent type. When compiling a call, the non-limited view of the
12869 -- type is visible.
12871 if From_Limited_With (Etype (Concval)) then
12872 Set_Etype (Concval, Non_Limited_View (Etype (Concval)));
12876 -------------------
12877 -- Family_Offset --
12878 -------------------
12880 function Family_Offset
12885 Cap : Boolean) return Node_Id
12891 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
12892 -- If one of the bounds is a reference to a discriminant, replace with
12893 -- corresponding discriminal of type. Within the body of a task retrieve
12894 -- the renamed discriminant by simple visibility, using its generated
12895 -- name. Within a protected object, find the original discriminant and
12896 -- replace it with the discriminal of the current protected operation.
12898 ------------------------------
12899 -- Convert_Discriminant_Ref --
12900 ------------------------------
12902 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
12903 Loc : constant Source_Ptr := Sloc (Bound);
12908 if Is_Entity_Name (Bound)
12909 and then Ekind (Entity (Bound)) = E_Discriminant
12911 if Is_Task_Type (Ttyp) and then Has_Completion (Ttyp) then
12912 B := Make_Identifier (Loc, Chars (Entity (Bound)));
12913 Find_Direct_Name (B);
12915 elsif Is_Protected_Type (Ttyp) then
12916 D := First_Discriminant (Ttyp);
12917 while Chars (D) /= Chars (Entity (Bound)) loop
12918 Next_Discriminant (D);
12921 B := New_Occurrence_Of (Discriminal (D), Loc);
12924 B := New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
12927 elsif Nkind (Bound) = N_Attribute_Reference then
12931 B := New_Copy_Tree (Bound);
12935 Make_Attribute_Reference (Loc,
12936 Attribute_Name => Name_Pos,
12937 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
12938 Expressions => New_List (B));
12939 end Convert_Discriminant_Ref;
12941 -- Start of processing for Family_Offset
12944 Real_Hi := Convert_Discriminant_Ref (Hi);
12945 Real_Lo := Convert_Discriminant_Ref (Lo);
12948 if Is_Task_Type (Ttyp) then
12949 Ityp := RTE (RE_Task_Entry_Index);
12951 Ityp := RTE (RE_Protected_Entry_Index);
12955 Make_Attribute_Reference (Loc,
12956 Prefix => New_Occurrence_Of (Ityp, Loc),
12957 Attribute_Name => Name_Min,
12958 Expressions => New_List (
12960 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12963 Make_Attribute_Reference (Loc,
12964 Prefix => New_Occurrence_Of (Ityp, Loc),
12965 Attribute_Name => Name_Max,
12966 Expressions => New_List (
12968 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12971 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12978 function Family_Size
12983 Cap : Boolean) return Node_Id
12988 if Is_Task_Type (Ttyp) then
12989 Ityp := RTE (RE_Task_Entry_Index);
12991 Ityp := RTE (RE_Protected_Entry_Index);
12995 Make_Attribute_Reference (Loc,
12996 Prefix => New_Occurrence_Of (Ityp, Loc),
12997 Attribute_Name => Name_Max,
12998 Expressions => New_List (
13000 Left_Opnd => Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
13001 Right_Opnd => Make_Integer_Literal (Loc, 1)),
13002 Make_Integer_Literal (Loc, 0)));
13005 ----------------------------
13006 -- Find_Enclosing_Context --
13007 ----------------------------
13009 procedure Find_Enclosing_Context
13011 Context : out Node_Id;
13012 Context_Id : out Entity_Id;
13013 Context_Decls : out List_Id)
13016 -- Traverse the parent chain looking for an enclosing body, block,
13017 -- package or return statement.
13019 Context := Parent (N);
13020 while Present (Context) loop
13021 if Nkind_In (Context, N_Entry_Body,
13022 N_Extended_Return_Statement,
13024 N_Package_Declaration,
13030 -- Do not consider block created to protect a list of statements with
13031 -- an Abort_Defer / Abort_Undefer_Direct pair.
13033 elsif Nkind (Context) = N_Block_Statement
13034 and then not Is_Abort_Block (Context)
13039 Context := Parent (Context);
13042 pragma Assert (Present (Context));
13044 -- Extract the constituents of the context
13046 if Nkind (Context) = N_Extended_Return_Statement then
13047 Context_Decls := Return_Object_Declarations (Context);
13048 Context_Id := Return_Statement_Entity (Context);
13050 -- Package declarations and bodies use a common library-level activation
13051 -- chain or task master, therefore return the package declaration as the
13052 -- proper carrier for the appropriate flag.
13054 elsif Nkind (Context) = N_Package_Body then
13055 Context_Decls := Declarations (Context);
13056 Context_Id := Corresponding_Spec (Context);
13057 Context := Parent (Context_Id);
13059 if Nkind (Context) = N_Defining_Program_Unit_Name then
13060 Context := Parent (Parent (Context));
13062 Context := Parent (Context);
13065 elsif Nkind (Context) = N_Package_Declaration then
13066 Context_Decls := Visible_Declarations (Specification (Context));
13067 Context_Id := Defining_Unit_Name (Specification (Context));
13069 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13070 Context_Id := Defining_Identifier (Context_Id);
13074 if Nkind (Context) = N_Block_Statement then
13075 Context_Id := Entity (Identifier (Context));
13077 elsif Nkind (Context) = N_Entry_Body then
13078 Context_Id := Defining_Identifier (Context);
13080 elsif Nkind (Context) = N_Subprogram_Body then
13081 if Present (Corresponding_Spec (Context)) then
13082 Context_Id := Corresponding_Spec (Context);
13084 Context_Id := Defining_Unit_Name (Specification (Context));
13086 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13087 Context_Id := Defining_Identifier (Context_Id);
13091 elsif Nkind (Context) = N_Task_Body then
13092 Context_Id := Corresponding_Spec (Context);
13095 raise Program_Error;
13098 Context_Decls := Declarations (Context);
13101 pragma Assert (Present (Context_Id));
13102 pragma Assert (Present (Context_Decls));
13103 end Find_Enclosing_Context;
13105 -----------------------
13106 -- Find_Master_Scope --
13107 -----------------------
13109 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
13113 -- In Ada 2005, the master is the innermost enclosing scope that is not
13114 -- transient. If the enclosing block is the rewriting of a call or the
13115 -- scope is an extended return statement this is valid master. The
13116 -- master in an extended return is only used within the return, and is
13117 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13118 -- now before that overwriting occurs.
13122 if Ada_Version >= Ada_2005 then
13123 while Is_Internal (S) loop
13124 if Nkind (Parent (S)) = N_Block_Statement
13126 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
13130 elsif Ekind (S) = E_Return_Statement then
13140 end Find_Master_Scope;
13142 -------------------------------
13143 -- First_Protected_Operation --
13144 -------------------------------
13146 function First_Protected_Operation (D : List_Id) return Node_Id is
13147 First_Op : Node_Id;
13150 First_Op := First (D);
13151 while Present (First_Op)
13152 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
13158 end First_Protected_Operation;
13160 ---------------------------------------
13161 -- Install_Private_Data_Declarations --
13162 ---------------------------------------
13164 procedure Install_Private_Data_Declarations
13166 Spec_Id : Entity_Id;
13167 Conc_Typ : Entity_Id;
13168 Body_Nod : Node_Id;
13170 Barrier : Boolean := False;
13171 Family : Boolean := False)
13173 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
13176 Insert_Node : Node_Id := Empty;
13177 Obj_Ent : Entity_Id;
13179 procedure Add (Decl : Node_Id);
13180 -- Add a single declaration after Insert_Node. If this is the first
13181 -- addition, Decl is added to the front of Decls and it becomes the
13184 function Replace_Bound (Bound : Node_Id) return Node_Id;
13185 -- The bounds of an entry index may depend on discriminants, create a
13186 -- reference to the corresponding prival. Otherwise return a duplicate
13187 -- of the original bound.
13193 procedure Add (Decl : Node_Id) is
13195 if No (Insert_Node) then
13196 Prepend_To (Decls, Decl);
13198 Insert_After (Insert_Node, Decl);
13201 Insert_Node := Decl;
13204 --------------------------
13205 -- Replace_Discriminant --
13206 --------------------------
13208 function Replace_Bound (Bound : Node_Id) return Node_Id is
13210 if Nkind (Bound) = N_Identifier
13211 and then Is_Discriminal (Entity (Bound))
13213 return Make_Identifier (Loc, Chars (Entity (Bound)));
13215 return Duplicate_Subexpr (Bound);
13219 -- Start of processing for Install_Private_Data_Declarations
13222 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13223 -- formal parameter _O, _object or _task depending on the context.
13225 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
13227 -- Special processing of _O for barrier functions, protected entries
13234 (Ekind (Spec_Id) = E_Entry
13235 or else Ekind (Spec_Id) = E_Entry_Family))
13238 Conc_Rec : constant Entity_Id :=
13239 Corresponding_Record_Type (Conc_Typ);
13240 Typ_Id : constant Entity_Id :=
13241 Make_Defining_Identifier (Loc,
13242 New_External_Name (Chars (Conc_Rec), 'P'));
13245 -- type prot_typVP is access prot_typV;
13248 Make_Full_Type_Declaration (Loc,
13249 Defining_Identifier => Typ_Id,
13251 Make_Access_To_Object_Definition (Loc,
13252 Subtype_Indication =>
13253 New_Occurrence_Of (Conc_Rec, Loc)));
13257 -- _object : prot_typVP := prot_typV (_O);
13260 Make_Object_Declaration (Loc,
13261 Defining_Identifier =>
13262 Make_Defining_Identifier (Loc, Name_uObject),
13263 Object_Definition => New_Occurrence_Of (Typ_Id, Loc),
13265 Unchecked_Convert_To (Typ_Id,
13266 New_Occurrence_Of (Obj_Ent, Loc)));
13269 -- Set the reference to the concurrent object
13271 Obj_Ent := Defining_Identifier (Decl);
13275 -- Step 2: Create the Protection object and build its declaration for
13276 -- any protected entry (family) of subprogram. Note for the lock-free
13277 -- implementation, the Protection object is not needed anymore.
13279 if Is_Protected and then not Uses_Lock_Free (Conc_Typ) then
13281 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
13285 Set_Protection_Object (Spec_Id, Prot_Ent);
13287 -- Determine the proper protection type
13289 if Has_Attach_Handler (Conc_Typ)
13290 and then not Restricted_Profile
13292 Prot_Typ := RE_Static_Interrupt_Protection;
13294 elsif Has_Interrupt_Handler (Conc_Typ)
13295 and then not Restriction_Active (No_Dynamic_Attachment)
13297 Prot_Typ := RE_Dynamic_Interrupt_Protection;
13300 case Corresponding_Runtime_Package (Conc_Typ) is
13301 when System_Tasking_Protected_Objects_Entries =>
13302 Prot_Typ := RE_Protection_Entries;
13304 when System_Tasking_Protected_Objects_Single_Entry =>
13305 Prot_Typ := RE_Protection_Entry;
13307 when System_Tasking_Protected_Objects =>
13308 Prot_Typ := RE_Protection;
13311 raise Program_Error;
13316 -- conc_typR : protection_typ renames _object._object;
13319 Make_Object_Renaming_Declaration (Loc,
13320 Defining_Identifier => Prot_Ent,
13322 New_Occurrence_Of (RTE (Prot_Typ), Loc),
13324 Make_Selected_Component (Loc,
13325 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13326 Selector_Name => Make_Identifier (Loc, Name_uObject)));
13331 -- Step 3: Add discriminant renamings (if any)
13333 if Has_Discriminants (Conc_Typ) then
13338 D := First_Discriminant (Conc_Typ);
13339 while Present (D) loop
13341 -- Adjust the source location
13343 Set_Sloc (Discriminal (D), Loc);
13346 -- discr_name : discr_typ renames _object.discr_name;
13348 -- discr_name : discr_typ renames _task.discr_name;
13351 Make_Object_Renaming_Declaration (Loc,
13352 Defining_Identifier => Discriminal (D),
13353 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
13355 Make_Selected_Component (Loc,
13356 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13357 Selector_Name => Make_Identifier (Loc, Chars (D))));
13360 Next_Discriminant (D);
13365 -- Step 4: Add private component renamings (if any)
13367 if Is_Protected then
13368 Def := Protected_Definition (Parent (Conc_Typ));
13370 if Present (Private_Declarations (Def)) then
13373 Comp_Id : Entity_Id;
13374 Decl_Id : Entity_Id;
13377 Comp := First (Private_Declarations (Def));
13378 while Present (Comp) loop
13379 if Nkind (Comp) = N_Component_Declaration then
13380 Comp_Id := Defining_Identifier (Comp);
13382 Make_Defining_Identifier (Loc, Chars (Comp_Id));
13384 -- Minimal decoration
13386 if Ekind (Spec_Id) = E_Function then
13387 Set_Ekind (Decl_Id, E_Constant);
13389 Set_Ekind (Decl_Id, E_Variable);
13392 Set_Prival (Comp_Id, Decl_Id);
13393 Set_Prival_Link (Decl_Id, Comp_Id);
13394 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
13397 -- comp_name : comp_typ renames _object.comp_name;
13400 Make_Object_Renaming_Declaration (Loc,
13401 Defining_Identifier => Decl_Id,
13403 New_Occurrence_Of (Etype (Comp_Id), Loc),
13405 Make_Selected_Component (Loc,
13407 New_Occurrence_Of (Obj_Ent, Loc),
13409 Make_Identifier (Loc, Chars (Comp_Id))));
13419 -- Step 5: Add the declaration of the entry index and the associated
13420 -- type for barrier functions and entry families.
13422 if (Barrier and Family) or else Ekind (Spec_Id) = E_Entry_Family then
13424 E : constant Entity_Id := Index_Object (Spec_Id);
13425 Index : constant Entity_Id :=
13426 Defining_Identifier
13427 (Entry_Index_Specification
13428 (Entry_Body_Formal_Part (Body_Nod)));
13429 Index_Con : constant Entity_Id :=
13430 Make_Defining_Identifier (Loc, Chars (Index));
13432 Index_Typ : Entity_Id;
13436 -- Minimal decoration
13438 Set_Ekind (Index_Con, E_Constant);
13439 Set_Entry_Index_Constant (Index, Index_Con);
13440 Set_Discriminal_Link (Index_Con, Index);
13442 -- Retrieve the bounds of the entry family
13444 High := Type_High_Bound (Etype (Index));
13445 Low := Type_Low_Bound (Etype (Index));
13447 -- In the simple case the entry family is given by a subtype mark
13448 -- and the index constant has the same type.
13450 if Is_Entity_Name (Original_Node (
13451 Discrete_Subtype_Definition (Parent (Index))))
13453 Index_Typ := Etype (Index);
13455 -- Otherwise a new subtype declaration is required
13458 High := Replace_Bound (High);
13459 Low := Replace_Bound (Low);
13461 Index_Typ := Make_Temporary (Loc, 'J');
13464 -- subtype Jnn is <Etype of Index> range Low .. High;
13467 Make_Subtype_Declaration (Loc,
13468 Defining_Identifier => Index_Typ,
13469 Subtype_Indication =>
13470 Make_Subtype_Indication (Loc,
13472 New_Occurrence_Of (Base_Type (Etype (Index)), Loc),
13474 Make_Range_Constraint (Loc,
13475 Range_Expression =>
13476 Make_Range (Loc, Low, High))));
13480 Set_Etype (Index_Con, Index_Typ);
13482 -- Create the object which designates the index:
13483 -- J : constant Jnn :=
13484 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13486 -- where Jnn is the subtype created above or the original type of
13487 -- the index, _E is a formal of the protected body subprogram and
13488 -- <index expr> is the index of the first family member.
13491 Make_Object_Declaration (Loc,
13492 Defining_Identifier => Index_Con,
13493 Constant_Present => True,
13494 Object_Definition =>
13495 New_Occurrence_Of (Index_Typ, Loc),
13498 Make_Attribute_Reference (Loc,
13500 New_Occurrence_Of (Index_Typ, Loc),
13501 Attribute_Name => Name_Val,
13503 Expressions => New_List (
13507 Make_Op_Subtract (Loc,
13508 Left_Opnd => New_Occurrence_Of (E, Loc),
13510 Entry_Index_Expression (Loc,
13511 Defining_Identifier (Body_Nod),
13515 Make_Attribute_Reference (Loc,
13517 New_Occurrence_Of (Index_Typ, Loc),
13518 Attribute_Name => Name_Pos,
13519 Expressions => New_List (
13520 Make_Attribute_Reference (Loc,
13522 New_Occurrence_Of (Index_Typ, Loc),
13523 Attribute_Name => Name_First)))))));
13527 end Install_Private_Data_Declarations;
13529 -----------------------
13530 -- Is_Exception_Safe --
13531 -----------------------
13533 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
13535 function Has_Side_Effect (N : Node_Id) return Boolean;
13536 -- Return True whenever encountering a subprogram call or raise
13537 -- statement of any kind in the sequence of statements
13539 ---------------------
13540 -- Has_Side_Effect --
13541 ---------------------
13543 -- What is this doing buried two levels down in exp_ch9. It seems like a
13544 -- generally useful function, and indeed there may be code duplication
13545 -- going on here ???
13547 function Has_Side_Effect (N : Node_Id) return Boolean is
13551 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
13552 -- Indicate whether N is a subprogram call or a raise statement
13554 ----------------------
13555 -- Is_Call_Or_Raise --
13556 ----------------------
13558 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
13560 return Nkind_In (N, N_Procedure_Call_Statement,
13563 N_Raise_Constraint_Error,
13564 N_Raise_Program_Error,
13565 N_Raise_Storage_Error);
13566 end Is_Call_Or_Raise;
13568 -- Start of processing for Has_Side_Effect
13572 while Present (Stmt) loop
13573 if Is_Call_Or_Raise (Stmt) then
13577 -- An object declaration can also contain a function call or a
13578 -- raise statement.
13580 if Nkind (Stmt) = N_Object_Declaration then
13581 Expr := Expression (Stmt);
13583 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
13592 end Has_Side_Effect;
13594 -- Start of processing for Is_Exception_Safe
13597 -- When exceptions can't be propagated, the subprogram returns normally
13599 if No_Exception_Handlers_Set then
13603 -- If the checks handled by the back end are not disabled, we cannot
13604 -- ensure that no exception will be raised.
13606 if not Access_Checks_Suppressed (Empty)
13607 or else not Discriminant_Checks_Suppressed (Empty)
13608 or else not Range_Checks_Suppressed (Empty)
13609 or else not Index_Checks_Suppressed (Empty)
13610 or else Opt.Stack_Checking_Enabled
13615 if Has_Side_Effect (First (Declarations (Subprogram)))
13618 (First (Statements (Handled_Statement_Sequence (Subprogram))))
13624 end Is_Exception_Safe;
13626 ---------------------------------
13627 -- Is_Potentially_Large_Family --
13628 ---------------------------------
13630 function Is_Potentially_Large_Family
13631 (Base_Index : Entity_Id;
13632 Conctyp : Entity_Id;
13634 Hi : Node_Id) return Boolean
13637 return Scope (Base_Index) = Standard_Standard
13638 and then Base_Index = Base_Type (Standard_Integer)
13639 and then Has_Discriminants (Conctyp)
13641 Present (Discriminant_Default_Value (First_Discriminant (Conctyp)))
13643 (Denotes_Discriminant (Lo, True)
13645 Denotes_Discriminant (Hi, True));
13646 end Is_Potentially_Large_Family;
13648 -------------------------------------
13649 -- Is_Private_Primitive_Subprogram --
13650 -------------------------------------
13652 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
13655 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
13656 and then Is_Private_Primitive (Id);
13657 end Is_Private_Primitive_Subprogram;
13663 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
13664 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
13665 Formal : Entity_Id;
13668 Formal := First_Formal (Bod_Subp);
13669 while Present (Formal) loop
13671 -- Look for formal parameter _E
13673 if Chars (Formal) = Name_uE then
13677 Next_Formal (Formal);
13680 -- A protected body subprogram should always have the parameter in
13683 raise Program_Error;
13686 --------------------------------
13687 -- Make_Initialize_Protection --
13688 --------------------------------
13690 function Make_Initialize_Protection
13691 (Protect_Rec : Entity_Id) return List_Id
13693 Loc : constant Source_Ptr := Sloc (Protect_Rec);
13696 Ptyp : constant Node_Id :=
13697 Corresponding_Concurrent_Type (Protect_Rec);
13699 L : constant List_Id := New_List;
13700 Has_Entry : constant Boolean := Has_Entries (Ptyp);
13701 Prio_Type : Entity_Id;
13702 Prio_Var : Entity_Id := Empty;
13703 Restricted : constant Boolean := Restricted_Profile;
13706 -- We may need two calls to properly initialize the object, one to
13707 -- Initialize_Protection, and possibly one to Install_Handlers if we
13708 -- have a pragma Attach_Handler.
13710 -- Get protected declaration. In the case of a task type declaration,
13711 -- this is simply the parent of the protected type entity. In the single
13712 -- protected object declaration, this parent will be the implicit type,
13713 -- and we can find the corresponding single protected object declaration
13714 -- by searching forward in the declaration list in the tree.
13716 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13717 -- of this type should have been removed during semantic analysis.
13719 Pdec := Parent (Ptyp);
13720 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
13721 N_Single_Protected_Declaration)
13726 -- Build the parameter list for the call. Note that _Init is the name
13727 -- of the formal for the object to be initialized, which is the task
13728 -- value record itself.
13732 -- For lock-free implementation, skip initializations of the Protection
13735 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13737 -- Object parameter. This is a pointer to the object of type
13738 -- Protection used by the GNARL to control the protected object.
13741 Make_Attribute_Reference (Loc,
13743 Make_Selected_Component (Loc,
13744 Prefix => Make_Identifier (Loc, Name_uInit),
13745 Selector_Name => Make_Identifier (Loc, Name_uObject)),
13746 Attribute_Name => Name_Unchecked_Access));
13748 -- Priority parameter. Set to Unspecified_Priority unless there is a
13749 -- Priority rep item, in which case we take the value from the pragma
13750 -- or attribute definition clause, or there is an Interrupt_Priority
13751 -- rep item and no Priority rep item, and we set the ceiling to
13752 -- Interrupt_Priority'Last, an implementation-defined value, see
13755 if Has_Rep_Item (Ptyp, Name_Priority, Check_Parents => False) then
13757 Prio_Clause : constant Node_Id :=
13759 (Ptyp, Name_Priority, Check_Parents => False);
13766 if Nkind (Prio_Clause) = N_Pragma then
13769 (First (Pragma_Argument_Associations (Prio_Clause)));
13771 -- Get_Rep_Item returns either priority pragma
13773 if Pragma_Name (Prio_Clause) = Name_Priority then
13774 Prio_Type := RTE (RE_Any_Priority);
13776 Prio_Type := RTE (RE_Interrupt_Priority);
13779 -- Attribute definition clause Priority
13782 if Chars (Prio_Clause) = Name_Priority then
13783 Prio_Type := RTE (RE_Any_Priority);
13785 Prio_Type := RTE (RE_Interrupt_Priority);
13788 Prio := Expression (Prio_Clause);
13791 -- Always create a locale variable to capture the priority.
13792 -- The priority is also passed to Install_Restriced_Handlers.
13793 -- Note that it is really necessary to create this variable
13794 -- explicitly. It might be thought that removing side effects
13795 -- would the appropriate approach, but that could generate
13796 -- declarations improperly placed in the enclosing scope.
13798 Prio_Var := Make_Temporary (Loc, 'R', Prio);
13800 Make_Object_Declaration (Loc,
13801 Defining_Identifier => Prio_Var,
13802 Object_Definition => New_Occurrence_Of (Prio_Type, Loc),
13803 Expression => Relocate_Node (Prio)));
13805 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13808 -- When no priority is specified but an xx_Handler pragma is, we
13809 -- default to System.Interrupts.Default_Interrupt_Priority, see
13812 elsif Has_Attach_Handler (Ptyp)
13813 or else Has_Interrupt_Handler (Ptyp)
13816 New_Occurrence_Of (RTE (RE_Default_Interrupt_Priority), Loc));
13818 -- Normal case, no priority or xx_Handler specified, default priority
13822 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
13825 -- Test for Compiler_Info parameter. This parameter allows entry body
13826 -- procedures and barrier functions to be called from the runtime. It
13827 -- is a pointer to the record generated by the compiler to represent
13828 -- the protected object.
13830 -- A protected type without entries that covers an interface and
13831 -- overrides the abstract routines with protected procedures is
13832 -- considered equivalent to a protected type with entries in the
13833 -- context of dispatching select statements.
13835 -- Protected types with interrupt handlers (when not using a
13836 -- restricted profile) are also considered equivalent to protected
13837 -- types with entries.
13839 -- The types which are used (Static_Interrupt_Protection and
13840 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13843 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
13845 Called_Subp : RE_Id;
13849 when System_Tasking_Protected_Objects_Entries =>
13850 Called_Subp := RE_Initialize_Protection_Entries;
13852 -- Argument Compiler_Info
13855 Make_Attribute_Reference (Loc,
13856 Prefix => Make_Identifier (Loc, Name_uInit),
13857 Attribute_Name => Name_Address));
13859 when System_Tasking_Protected_Objects_Single_Entry =>
13860 Called_Subp := RE_Initialize_Protection_Entry;
13862 -- Argument Compiler_Info
13865 Make_Attribute_Reference (Loc,
13866 Prefix => Make_Identifier (Loc, Name_uInit),
13867 Attribute_Name => Name_Address));
13869 when System_Tasking_Protected_Objects =>
13870 Called_Subp := RE_Initialize_Protection;
13873 raise Program_Error;
13876 -- Entry_Queue_Maxes parameter. This is an access to an array of
13877 -- naturals representing the entry queue maximums for each entry
13878 -- in the protected type. Zero represents no max. The access is
13879 -- null if there is no limit for all entries (usual case).
13882 and then Pkg_Id = System_Tasking_Protected_Objects_Entries
13884 if Present (Entry_Max_Queue_Lengths_Array (Ptyp)) then
13886 Make_Attribute_Reference (Loc,
13889 (Entry_Max_Queue_Lengths_Array (Ptyp), Loc),
13890 Attribute_Name => Name_Unrestricted_Access));
13892 Append_To (Args, Make_Null (Loc));
13895 -- Edge cases exist where entry initialization functions are
13896 -- called, but no entries exist, so null is appended.
13898 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
13899 Append_To (Args, Make_Null (Loc));
13902 -- Entry_Bodies parameter. This is a pointer to an array of
13903 -- pointers to the entry body procedures and barrier functions of
13904 -- the object. If the protected type has no entries this object
13905 -- will not exist, in this case, pass a null (it can happen when
13906 -- there are protected interrupt handlers or interfaces).
13909 P_Arr := Entry_Bodies_Array (Ptyp);
13911 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13912 -- multiple entries).
13915 Make_Attribute_Reference (Loc,
13916 Prefix => New_Occurrence_Of (P_Arr, Loc),
13917 Attribute_Name => Name_Unrestricted_Access));
13919 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
13921 -- Find index mapping function (clumsy but ok for now)
13923 while Ekind (P_Arr) /= E_Function loop
13924 Next_Entity (P_Arr);
13928 Make_Attribute_Reference (Loc,
13929 Prefix => New_Occurrence_Of (P_Arr, Loc),
13930 Attribute_Name => Name_Unrestricted_Access));
13933 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
13935 -- This is the case where we have a protected object with
13936 -- interfaces and no entries, and the single entry restriction
13937 -- is in effect. We pass a null pointer for the entry
13938 -- parameter because there is no actual entry.
13940 Append_To (Args, Make_Null (Loc));
13942 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
13944 -- This is the case where we have a protected object with no
13946 -- - either interrupt handlers with non restricted profile,
13948 -- Note that the types which are used for interrupt handlers
13949 -- (Static/Dynamic_Interrupt_Protection) are derived from
13950 -- Protection_Entries. We pass two null pointers because there
13951 -- is no actual entry, and the initialization procedure needs
13952 -- both Entry_Bodies and Find_Body_Index.
13954 Append_To (Args, Make_Null (Loc));
13955 Append_To (Args, Make_Null (Loc));
13959 Make_Procedure_Call_Statement (Loc,
13961 New_Occurrence_Of (RTE (Called_Subp), Loc),
13962 Parameter_Associations => Args));
13966 if Has_Attach_Handler (Ptyp) then
13968 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13969 -- make the following call:
13971 -- Install_Handlers (_object,
13972 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13974 -- or, in the case of Ravenscar:
13976 -- Install_Restricted_Handlers
13977 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
13980 Args : constant List_Id := New_List;
13981 Table : constant List_Id := New_List;
13982 Ritem : Node_Id := First_Rep_Item (Ptyp);
13985 -- Build the Priority parameter (only for ravenscar)
13989 -- Priority comes from a pragma
13991 if Present (Prio_Var) then
13992 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13994 -- Priority is the default one
13999 (RTE (RE_Default_Interrupt_Priority), Loc));
14003 -- Build the Attach_Handler table argument
14005 while Present (Ritem) loop
14006 if Nkind (Ritem) = N_Pragma
14007 and then Pragma_Name (Ritem) = Name_Attach_Handler
14010 Handler : constant Node_Id :=
14011 First (Pragma_Argument_Associations (Ritem));
14013 Interrupt : constant Node_Id := Next (Handler);
14014 Expr : constant Node_Id := Expression (Interrupt);
14018 Make_Aggregate (Loc, Expressions => New_List (
14019 Unchecked_Convert_To
14020 (RTE (RE_System_Interrupt_Id), Expr),
14021 Make_Attribute_Reference (Loc,
14023 Make_Selected_Component (Loc,
14025 Make_Identifier (Loc, Name_uInit),
14027 Duplicate_Subexpr_No_Checks
14028 (Expression (Handler))),
14029 Attribute_Name => Name_Access))));
14033 Next_Rep_Item (Ritem);
14036 -- Append the table argument we just built
14038 Append_To (Args, Make_Aggregate (Loc, Table));
14040 -- Append the Install_Handlers (or Install_Restricted_Handlers)
14041 -- call to the statements.
14044 -- Call a simplified version of Install_Handlers to be used
14045 -- when the Ravenscar restrictions are in effect
14046 -- (Install_Restricted_Handlers).
14049 Make_Procedure_Call_Statement (Loc,
14052 (RTE (RE_Install_Restricted_Handlers), Loc),
14053 Parameter_Associations => Args));
14056 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
14058 -- First, prepends the _object argument
14061 Make_Attribute_Reference (Loc,
14063 Make_Selected_Component (Loc,
14064 Prefix => Make_Identifier (Loc, Name_uInit),
14066 Make_Identifier (Loc, Name_uObject)),
14067 Attribute_Name => Name_Unchecked_Access));
14070 -- Then, insert call to Install_Handlers
14073 Make_Procedure_Call_Statement (Loc,
14075 New_Occurrence_Of (RTE (RE_Install_Handlers), Loc),
14076 Parameter_Associations => Args));
14082 end Make_Initialize_Protection;
14084 ---------------------------
14085 -- Make_Task_Create_Call --
14086 ---------------------------
14088 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
14089 Loc : constant Source_Ptr := Sloc (Task_Rec);
14099 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
14100 Tnam := Chars (Ttyp);
14102 -- Get task declaration. In the case of a task type declaration, this is
14103 -- simply the parent of the task type entity. In the single task
14104 -- declaration, this parent will be the implicit type, and we can find
14105 -- the corresponding single task declaration by searching forward in the
14106 -- declaration list in the tree.
14108 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14109 -- this type should have been removed during semantic analysis.
14111 Tdec := Parent (Ttyp);
14112 while not Nkind_In (Tdec, N_Task_Type_Declaration,
14113 N_Single_Task_Declaration)
14118 -- Now we can find the task definition from this declaration
14120 Tdef := Task_Definition (Tdec);
14122 -- Build the parameter list for the call. Note that _Init is the name
14123 -- of the formal for the object to be initialized, which is the task
14124 -- value record itself.
14128 -- Priority parameter. Set to Unspecified_Priority unless there is a
14129 -- Priority rep item, in which case we take the value from the rep item.
14131 if Has_Rep_Item (Ttyp, Name_Priority, Check_Parents => False) then
14133 Make_Selected_Component (Loc,
14134 Prefix => Make_Identifier (Loc, Name_uInit),
14135 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
14138 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
14141 -- Optional Stack parameter
14143 if Restricted_Profile then
14145 -- If the stack has been preallocated by the expander then
14146 -- pass its address. Otherwise, pass a null address.
14148 if Preallocated_Stacks_On_Target then
14150 Make_Attribute_Reference (Loc,
14152 Make_Selected_Component (Loc,
14153 Prefix => Make_Identifier (Loc, Name_uInit),
14154 Selector_Name => Make_Identifier (Loc, Name_uStack)),
14155 Attribute_Name => Name_Address));
14159 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
14163 -- Size parameter. If no Storage_Size pragma is present, then
14164 -- the size is taken from the taskZ variable for the type, which
14165 -- is either Unspecified_Size, or has been reset by the use of
14166 -- a Storage_Size attribute definition clause. If a pragma is
14167 -- present, then the size is taken from the _Size field of the
14168 -- task value record, which was set from the pragma value.
14170 if Present (Tdef) and then Has_Storage_Size_Pragma (Tdef) then
14172 Make_Selected_Component (Loc,
14173 Prefix => Make_Identifier (Loc, Name_uInit),
14174 Selector_Name => Make_Identifier (Loc, Name_uSize)));
14178 New_Occurrence_Of (Storage_Size_Variable (Ttyp), Loc));
14181 -- Secondary_Stack_Size parameter. Set Default_Secondary_Stack_Size
14182 -- unless there is a Secondary_Stack_Size rep item, in which case we
14183 -- take the value from the rep item. If the restriction
14184 -- No_Secondary_Stack is active then a size of 0 is passed regardless
14185 -- to prevent the allocation of the unused stack.
14187 if Restriction_Active (No_Secondary_Stack) then
14188 Append_To (Args, Make_Integer_Literal (Loc, 0));
14191 (Ttyp, Name_Secondary_Stack_Size, Check_Parents => False)
14194 Make_Selected_Component (Loc,
14195 Prefix => Make_Identifier (Loc, Name_uInit),
14197 Make_Identifier (Loc, Name_uSecondary_Stack_Size)));
14201 New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
14204 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14205 -- Task_Info pragma, in which case we take the value from the pragma.
14207 if Has_Rep_Pragma (Ttyp, Name_Task_Info, Check_Parents => False) then
14209 Make_Selected_Component (Loc,
14210 Prefix => Make_Identifier (Loc, Name_uInit),
14211 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
14215 New_Occurrence_Of (RTE (RE_Unspecified_Task_Info), Loc));
14218 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14219 -- in which case we take the value from the rep item. The parameter is
14220 -- passed as an Integer because in the case of unspecified CPU the
14221 -- value is not in the range of CPU_Range.
14223 if Has_Rep_Item (Ttyp, Name_CPU, Check_Parents => False) then
14225 Convert_To (Standard_Integer,
14226 Make_Selected_Component (Loc,
14227 Prefix => Make_Identifier (Loc, Name_uInit),
14228 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
14231 New_Occurrence_Of (RTE (RE_Unspecified_CPU), Loc));
14234 if not Restricted_Profile then
14236 -- Deadline parameter. If no Relative_Deadline pragma is present,
14237 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14238 -- the deadline is taken from the _Relative_Deadline field of the
14239 -- task value record, which was set from the pragma value. Note that
14240 -- this parameter must not be generated for the restricted profiles
14241 -- since Ravenscar does not allow deadlines.
14243 -- Case where pragma Relative_Deadline applies: use given value
14245 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
14247 Make_Selected_Component (Loc,
14248 Prefix => Make_Identifier (Loc, Name_uInit),
14250 Make_Identifier (Loc, Name_uRelative_Deadline)));
14252 -- No pragma Relative_Deadline apply to the task
14256 New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc));
14259 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14260 -- present, then the dispatching domain is null. If a rep item is
14261 -- present, then the dispatching domain is taken from the
14262 -- _Dispatching_Domain field of the task value record, which was set
14263 -- from the rep item value.
14265 -- Case where Dispatching_Domain rep item applies: use given value
14268 (Ttyp, Name_Dispatching_Domain, Check_Parents => False)
14271 Make_Selected_Component (Loc,
14273 Make_Identifier (Loc, Name_uInit),
14275 Make_Identifier (Loc, Name_uDispatching_Domain)));
14277 -- No pragma or aspect Dispatching_Domain applies to the task
14280 Append_To (Args, Make_Null (Loc));
14283 -- Number of entries. This is an expression of the form:
14285 -- n + _Init.a'Length + _Init.a'B'Length + ...
14287 -- where a,b... are the entry family names for the task definition
14290 Build_Entry_Count_Expression
14295 (Parent (Corresponding_Record_Type (Ttyp))))),
14297 Append_To (Args, Ecount);
14299 -- Master parameter. This is a reference to the _Master parameter of
14300 -- the initialization procedure, except in the case of the pragma
14301 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14302 -- System.Tasking.Library_Task_Level.
14304 if Restriction_Active (No_Task_Hierarchy) = False then
14305 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
14308 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
14312 -- State parameter. This is a pointer to the task body procedure. The
14313 -- required value is obtained by taking 'Unrestricted_Access of the task
14314 -- body procedure and converting it (with an unchecked conversion) to
14315 -- the type required by the task kernel. For further details, see the
14316 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14317 -- than 'Address in order to avoid creating trampolines.
14320 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
14321 Subp_Ptr_Typ : constant Node_Id :=
14322 Create_Itype (E_Access_Subprogram_Type, Tdec);
14323 Ref : constant Node_Id := Make_Itype_Reference (Loc);
14326 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
14327 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
14329 -- Be sure to freeze a reference to the access-to-subprogram type,
14330 -- otherwise gigi will complain that it's in the wrong scope, because
14331 -- it's actually inside the init procedure for the record type that
14332 -- corresponds to the task type.
14334 Set_Itype (Ref, Subp_Ptr_Typ);
14335 Append_Freeze_Action (Task_Rec, Ref);
14338 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
14339 Make_Qualified_Expression (Loc,
14340 Subtype_Mark => New_Occurrence_Of (Subp_Ptr_Typ, Loc),
14342 Make_Attribute_Reference (Loc,
14343 Prefix => New_Occurrence_Of (Body_Proc, Loc),
14344 Attribute_Name => Name_Unrestricted_Access))));
14347 -- Discriminants parameter. This is just the address of the task
14348 -- value record itself (which contains the discriminant values
14351 Make_Attribute_Reference (Loc,
14352 Prefix => Make_Identifier (Loc, Name_uInit),
14353 Attribute_Name => Name_Address));
14355 -- Elaborated parameter. This is an access to the elaboration Boolean
14358 Make_Attribute_Reference (Loc,
14359 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
14360 Attribute_Name => Name_Unchecked_Access));
14362 -- Add Chain parameter (not done for sequential elaboration policy, see
14363 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14365 if Partition_Elaboration_Policy /= 'S' then
14366 Append_To (Args, Make_Identifier (Loc, Name_uChain));
14369 -- Task name parameter. Take this from the _Task_Id parameter to the
14370 -- init call unless there is a Task_Name pragma, in which case we take
14371 -- the value from the pragma.
14373 if Has_Rep_Pragma (Ttyp, Name_Task_Name, Check_Parents => False) then
14374 -- Copy expression in full, because it may be dynamic and have
14381 (Pragma_Argument_Associations
14383 (Ttyp, Name_Task_Name, Check_Parents => False))))));
14386 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
14389 -- Created_Task parameter. This is the _Task_Id field of the task
14393 Make_Selected_Component (Loc,
14394 Prefix => Make_Identifier (Loc, Name_uInit),
14395 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
14401 if Restricted_Profile then
14402 if Partition_Elaboration_Policy = 'S' then
14403 Create_RE := RE_Create_Restricted_Task_Sequential;
14405 Create_RE := RE_Create_Restricted_Task;
14408 Create_RE := RE_Create_Task;
14411 Name := New_Occurrence_Of (RTE (Create_RE), Loc);
14415 Make_Procedure_Call_Statement (Loc,
14417 Parameter_Associations => Args);
14418 end Make_Task_Create_Call;
14420 ------------------------------
14421 -- Next_Protected_Operation --
14422 ------------------------------
14424 function Next_Protected_Operation (N : Node_Id) return Node_Id is
14428 -- Check whether there is a subsequent body for a protected operation
14429 -- in the current protected body. In Ada2012 that includes expression
14430 -- functions that are completions.
14432 Next_Op := Next (N);
14433 while Present (Next_Op)
14434 and then not Nkind_In (Next_Op,
14435 N_Subprogram_Body, N_Entry_Body, N_Expression_Function)
14441 end Next_Protected_Operation;
14443 ---------------------
14444 -- Null_Statements --
14445 ---------------------
14447 function Null_Statements (Stats : List_Id) return Boolean is
14451 Stmt := First (Stats);
14452 while Nkind (Stmt) /= N_Empty
14453 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
14455 (Nkind (Stmt) = N_Pragma
14457 Nam_In (Pragma_Name_Unmapped (Stmt),
14465 return Nkind (Stmt) = N_Empty;
14466 end Null_Statements;
14468 --------------------------
14469 -- Parameter_Block_Pack --
14470 --------------------------
14472 function Parameter_Block_Pack
14474 Blk_Typ : Entity_Id;
14478 Stmts : List_Id) return Node_Id
14480 Actual : Entity_Id;
14481 Expr : Node_Id := Empty;
14482 Formal : Entity_Id;
14483 Has_Param : Boolean := False;
14486 Temp_Asn : Node_Id;
14487 Temp_Nam : Node_Id;
14490 Actual := First (Actuals);
14491 Formal := Defining_Identifier (First (Formals));
14492 Params := New_List;
14493 while Present (Actual) loop
14494 if Is_By_Copy_Type (Etype (Actual)) then
14496 -- Jnn : aliased <formal-type>
14498 Temp_Nam := Make_Temporary (Loc, 'J');
14501 Make_Object_Declaration (Loc,
14502 Aliased_Present => True,
14503 Defining_Identifier => Temp_Nam,
14504 Object_Definition =>
14505 New_Occurrence_Of (Etype (Formal), Loc)));
14507 if Ekind (Formal) /= E_Out_Parameter then
14513 New_Occurrence_Of (Temp_Nam, Loc);
14515 Set_Assignment_OK (Temp_Asn);
14518 Make_Assignment_Statement (Loc,
14520 Expression => New_Copy_Tree (Actual)));
14524 -- Jnn'unchecked_access
14527 Make_Attribute_Reference (Loc,
14528 Attribute_Name => Name_Unchecked_Access,
14529 Prefix => New_Occurrence_Of (Temp_Nam, Loc)));
14533 -- The controlling parameter is omitted
14536 if not Is_Controlling_Actual (Actual) then
14538 Make_Reference (Loc, New_Copy_Tree (Actual)));
14544 Next_Actual (Actual);
14545 Next_Formal_With_Extras (Formal);
14549 Expr := Make_Aggregate (Loc, Params);
14554 -- J1'unchecked_access;
14555 -- <actual2>'reference;
14558 P := Make_Temporary (Loc, 'P');
14561 Make_Object_Declaration (Loc,
14562 Defining_Identifier => P,
14563 Object_Definition => New_Occurrence_Of (Blk_Typ, Loc),
14564 Expression => Expr));
14567 end Parameter_Block_Pack;
14569 ----------------------------
14570 -- Parameter_Block_Unpack --
14571 ----------------------------
14573 function Parameter_Block_Unpack
14577 Formals : List_Id) return List_Id
14579 Actual : Entity_Id;
14581 Formal : Entity_Id;
14582 Has_Asnmt : Boolean := False;
14583 Result : constant List_Id := New_List;
14586 Actual := First (Actuals);
14587 Formal := Defining_Identifier (First (Formals));
14588 while Present (Actual) loop
14589 if Is_By_Copy_Type (Etype (Actual))
14590 and then Ekind (Formal) /= E_In_Parameter
14593 -- <actual> := P.<formal>;
14596 Make_Assignment_Statement (Loc,
14600 Make_Explicit_Dereference (Loc,
14601 Make_Selected_Component (Loc,
14603 New_Occurrence_Of (P, Loc),
14605 Make_Identifier (Loc, Chars (Formal)))));
14607 Set_Assignment_OK (Name (Asnmt));
14608 Append_To (Result, Asnmt);
14613 Next_Actual (Actual);
14614 Next_Formal_With_Extras (Formal);
14620 return New_List (Make_Null_Statement (Loc));
14622 end Parameter_Block_Unpack;
14624 ----------------------
14625 -- Set_Discriminals --
14626 ----------------------
14628 procedure Set_Discriminals (Dec : Node_Id) is
14631 D_Minal : Entity_Id;
14634 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
14635 Pdef := Defining_Identifier (Dec);
14637 if Has_Discriminants (Pdef) then
14638 D := First_Discriminant (Pdef);
14639 while Present (D) loop
14641 Make_Defining_Identifier (Sloc (D),
14642 Chars => New_External_Name (Chars (D), 'D'));
14644 Set_Ekind (D_Minal, E_Constant);
14645 Set_Etype (D_Minal, Etype (D));
14646 Set_Scope (D_Minal, Pdef);
14647 Set_Discriminal (D, D_Minal);
14648 Set_Discriminal_Link (D_Minal, D);
14650 Next_Discriminant (D);
14653 end Set_Discriminals;
14655 -----------------------
14656 -- Trivial_Accept_OK --
14657 -----------------------
14659 function Trivial_Accept_OK return Boolean is
14661 case Opt.Task_Dispatching_Policy is
14663 -- If we have the default task dispatching policy in effect, we can
14664 -- definitely do the optimization (one way of looking at this is to
14665 -- think of the formal definition of the default policy being allowed
14666 -- to run any task it likes after a rendezvous, so even if notionally
14667 -- a full rescheduling occurs, we can say that our dispatching policy
14668 -- (i.e. the default dispatching policy) reorders the queue to be the
14669 -- same as just before the call.
14674 -- FIFO_Within_Priorities certainly does not permit this
14675 -- optimization since the Rendezvous is a scheduling action that may
14676 -- require some other task to be run.
14681 -- For now, disallow the optimization for all other policies. This
14682 -- may be over-conservative, but it is certainly not incorrect.
14687 end Trivial_Accept_OK;