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
6030 when N_Expanded_Name
6033 if No (Entity (N)) then
6037 case Ekind (Entity (N)) is
6040 | E_Enumeration_Literal
6049 -- A variable in the protected type is expanded as a
6052 if Is_Simple_Barrier_Name (N) then
6060 when N_Character_Literal
6069 if Ekind (Entity (N)) = E_Operator then
6073 when N_Short_Circuit =>
6081 end Is_Pure_Barrier;
6083 function Check_Pure_Barriers is new Traverse_Func (Is_Pure_Barrier);
6085 -- Start of processing for Expand_Entry_Barrier
6088 if No_Run_Time_Mode then
6089 Error_Msg_CRT ("entry barrier", N);
6093 -- The body of the entry barrier must be analyzed in the context of the
6094 -- protected object, but its scope is external to it, just as any other
6095 -- unprotected version of a protected operation. The specification has
6096 -- been produced when the protected type declaration was elaborated. We
6097 -- build the body, insert it in the enclosing scope, but analyze it in
6098 -- the current context. A more uniform approach would be to treat the
6099 -- barrier just as a protected function, and discard the protected
6100 -- version of it because it is never called.
6102 if Expander_Active then
6103 B_F := Build_Barrier_Function (N, Ent, Prot);
6104 Func := Barrier_Function (Ent);
6105 Set_Corresponding_Spec (B_F, Func);
6107 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
6109 if Nkind (Parent (Body_Decl)) = N_Subunit then
6110 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
6113 Insert_Before_And_Analyze (Body_Decl, B_F);
6115 Set_Discriminals (Spec_Decl);
6116 Set_Scope (Func, Scope (Prot));
6119 Analyze_And_Resolve (Cond, Any_Boolean);
6122 -- Check Pure_Barriers restriction
6124 if Check_Pure_Barriers (Cond) = Abandon then
6125 Check_Restriction (Pure_Barriers, Cond);
6128 -- The Ravenscar profile restricts barriers to simple variables declared
6129 -- within the protected object. We also allow Boolean constants, since
6130 -- these appear in several published examples and are also allowed by
6133 -- Note that after analysis variables in this context will be replaced
6134 -- by the corresponding prival, that is to say a renaming of a selected
6135 -- component of the form _Object.Var. If expansion is disabled, as
6136 -- within a generic, we check that the entity appears in the current
6139 if Is_Entity_Name (Cond) then
6141 -- A small optimization of useless renamings. If the scope of the
6142 -- entity of the condition is not the barrier function, then the
6143 -- condition does not reference any of the generated renamings
6144 -- within the function.
6146 if Expander_Active and then Scope (Entity (Cond)) /= Func then
6147 Set_Declarations (B_F, Empty_List);
6150 if Entity (Cond) = Standard_False
6152 Entity (Cond) = Standard_True
6156 elsif Is_Simple_Barrier_Name (Cond) then
6161 -- It is not a boolean variable or literal, so check the restriction.
6162 -- Note that it is safe to be calling Check_Restriction from here, even
6163 -- though this is part of the expander, since Expand_Entry_Barrier is
6164 -- called from Sem_Ch9 even in -gnatc mode.
6166 Check_Restriction (Simple_Barriers, Cond);
6168 -- Emit warning if barrier contains global entities and is thus
6169 -- potentially unsynchronized.
6171 Check_Unprotected_Barrier (Cond);
6172 end Expand_Entry_Barrier;
6174 ------------------------------
6175 -- Expand_N_Abort_Statement --
6176 ------------------------------
6178 -- Expand abort T1, T2, .. Tn; into:
6179 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6181 procedure Expand_N_Abort_Statement (N : Node_Id) is
6182 Loc : constant Source_Ptr := Sloc (N);
6183 Tlist : constant List_Id := Names (N);
6189 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
6192 Tasknm := First (Tlist);
6194 while Present (Tasknm) loop
6197 -- A task interface class-wide type object is being aborted. Retrieve
6198 -- its _task_id by calling a dispatching routine.
6200 if Ada_Version >= Ada_2005
6201 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
6202 and then Is_Interface (Etype (Tasknm))
6203 and then Is_Task_Interface (Etype (Tasknm))
6205 Append_To (Component_Associations (Aggr),
6206 Make_Component_Association (Loc,
6207 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6210 -- Task_Id (Tasknm._disp_get_task_id)
6212 Make_Unchecked_Type_Conversion (Loc,
6214 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
6216 Make_Selected_Component (Loc,
6217 Prefix => New_Copy_Tree (Tasknm),
6219 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
6222 Append_To (Component_Associations (Aggr),
6223 Make_Component_Association (Loc,
6224 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6225 Expression => Concurrent_Ref (Tasknm)));
6232 Make_Procedure_Call_Statement (Loc,
6233 Name => New_Occurrence_Of (RTE (RE_Abort_Tasks), Loc),
6234 Parameter_Associations => New_List (
6235 Make_Qualified_Expression (Loc,
6236 Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_List), Loc),
6237 Expression => Aggr))));
6240 end Expand_N_Abort_Statement;
6242 -------------------------------
6243 -- Expand_N_Accept_Statement --
6244 -------------------------------
6246 -- This procedure handles expansion of accept statements that stand alone,
6247 -- i.e. they are not part of an accept alternative. The expansion of
6248 -- accept statement in accept alternatives is handled by the routines
6249 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6250 -- following description applies only to stand alone accept statements.
6252 -- If there is no handled statement sequence, or only null statements, then
6253 -- this is called a trivial accept, and the expansion is:
6255 -- Accept_Trivial (entry-index)
6257 -- If there is a handled statement sequence, then the expansion is:
6264 -- Accept_Call (entry-index, Ann);
6265 -- Renaming_Declarations for formals
6266 -- <statement sequence from N_Accept_Statement node>
6267 -- Complete_Rendezvous;
6272 -- <exception handler from N_Accept_Statement node>
6273 -- Complete_Rendezvous;
6275 -- <exception handler from N_Accept_Statement node>
6276 -- Complete_Rendezvous;
6281 -- when all others =>
6282 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6285 -- The first three declarations were already inserted ahead of the accept
6286 -- statement by the Expand_Accept_Declarations procedure, which was called
6287 -- directly from the semantics during analysis of the accept statement,
6288 -- before analyzing its contained statements.
6290 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6291 -- from possible expansion activity (the original source of course does
6292 -- not have any declarations associated with the accept statement, since
6293 -- an accept statement has no declarative part). In particular, if the
6294 -- expander is active, the first such declaration is the declaration of
6295 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6297 -- The two blocks are merged into a single block if the inner block has
6298 -- no exception handlers, but otherwise two blocks are required, since
6299 -- exceptions might be raised in the exception handlers of the inner
6300 -- block, and Exceptional_Complete_Rendezvous must be called.
6302 procedure Expand_N_Accept_Statement (N : Node_Id) is
6303 Loc : constant Source_Ptr := Sloc (N);
6304 Stats : constant Node_Id := Handled_Statement_Sequence (N);
6305 Ename : constant Node_Id := Entry_Direct_Name (N);
6306 Eindx : constant Node_Id := Entry_Index (N);
6307 Eent : constant Entity_Id := Entity (Ename);
6308 Acstack : constant Elist_Id := Accept_Address (Eent);
6309 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
6310 Ttyp : constant Entity_Id := Etype (Scope (Eent));
6316 -- If the accept statement is not part of a list, then its parent must
6317 -- be an accept alternative, and, as described above, we do not do any
6318 -- expansion for such accept statements at this level.
6320 if not Is_List_Member (N) then
6321 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
6324 -- Trivial accept case (no statement sequence, or null statements).
6325 -- If the accept statement has declarations, then just insert them
6326 -- before the procedure call.
6328 elsif Trivial_Accept_OK
6329 and then (No (Stats) or else Null_Statements (Statements (Stats)))
6331 -- Remove declarations for renamings, because the parameter block
6332 -- will not be assigned.
6339 D := First (Declarations (N));
6340 while Present (D) loop
6342 if Nkind (D) = N_Object_Renaming_Declaration then
6350 if Present (Declarations (N)) then
6351 Insert_Actions (N, Declarations (N));
6355 Make_Procedure_Call_Statement (Loc,
6356 Name => New_Occurrence_Of (RTE (RE_Accept_Trivial), Loc),
6357 Parameter_Associations => New_List (
6358 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
6362 -- Discard Entry_Address that was created for it, so it will not be
6363 -- emitted if this accept statement is in the statement part of a
6364 -- delay alternative.
6366 if Present (Stats) then
6367 Remove_Last_Elmt (Acstack);
6370 -- Case of statement sequence present
6373 -- Construct the block, using the declarations from the accept
6374 -- statement if any to initialize the declarations of the block.
6376 Blkent := Make_Temporary (Loc, 'A');
6377 Set_Ekind (Blkent, E_Block);
6378 Set_Etype (Blkent, Standard_Void_Type);
6379 Set_Scope (Blkent, Current_Scope);
6382 Make_Block_Statement (Loc,
6383 Identifier => New_Occurrence_Of (Blkent, Loc),
6384 Declarations => Declarations (N),
6385 Handled_Statement_Sequence => Build_Accept_Body (N));
6387 -- For the analysis of the generated declarations, the parent node
6388 -- must be properly set.
6390 Set_Parent (Block, Parent (N));
6392 -- Prepend call to Accept_Call to main statement sequence If the
6393 -- accept has exception handlers, the statement sequence is wrapped
6394 -- in a block. Insert call and renaming declarations in the
6395 -- declarations of the block, so they are elaborated before the
6399 Make_Procedure_Call_Statement (Loc,
6400 Name => New_Occurrence_Of (RTE (RE_Accept_Call), Loc),
6401 Parameter_Associations => New_List (
6402 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
6403 New_Occurrence_Of (Ann, Loc)));
6405 if Parent (Stats) = N then
6406 Prepend (Call, Statements (Stats));
6408 Set_Declarations (Parent (Stats), New_List (Call));
6413 Push_Scope (Blkent);
6421 D := First (Declarations (N));
6422 while Present (D) loop
6425 if Nkind (D) = N_Object_Renaming_Declaration then
6427 -- The renaming declarations for the formals were created
6428 -- during analysis of the accept statement, and attached to
6429 -- the list of declarations. Place them now in the context
6430 -- of the accept block or subprogram.
6433 Typ := Entity (Subtype_Mark (D));
6434 Insert_After (Call, D);
6437 -- If the formal is class_wide, it does not have an actual
6438 -- subtype. The analysis of the renaming declaration creates
6439 -- one, but we need to retain the class-wide nature of the
6442 if Is_Class_Wide_Type (Typ) then
6443 Set_Etype (Defining_Identifier (D), Typ);
6454 -- Replace the accept statement by the new block
6459 -- Last step is to unstack the Accept_Address value
6461 Remove_Last_Elmt (Acstack);
6463 end Expand_N_Accept_Statement;
6465 ----------------------------------
6466 -- Expand_N_Asynchronous_Select --
6467 ----------------------------------
6469 -- This procedure assumes that the trigger statement is an entry call or
6470 -- a dispatching procedure call. A delay alternative should already have
6471 -- been expanded into an entry call to the appropriate delay object Wait
6474 -- If the trigger is a task entry call, the select is implemented with
6475 -- a Task_Entry_Call:
6480 -- P : parms := (parm, parm, parm);
6482 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6484 -- procedure _clean is
6487 -- Cancel_Task_Entry_Call (C);
6494 -- (<acceptor-task>, -- Acceptor
6495 -- <entry-index>, -- E
6496 -- P'Address, -- Uninterpreted_Data
6497 -- Asynchronous_Call, -- Mode
6498 -- B); -- Rendezvous_Successful
6505 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6508 -- when Abort_Signal => Abort_Undefer;
6515 -- <triggered-statements>
6519 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6520 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6524 -- P : parms := (parm, parm, parm);
6526 -- Call_Simple (acceptor-task, entry-index, P'Address);
6532 -- so the task at hand is to convert the latter expansion into the former
6534 -- If the trigger is a protected entry call, the select is implemented
6535 -- with Protected_Entry_Call:
6538 -- P : E1_Params := (param, param, param);
6539 -- Bnn : Communications_Block;
6544 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6546 -- procedure _clean is
6549 -- if Enqueued (Bnn) then
6550 -- Cancel_Protected_Entry_Call (Bnn);
6557 -- Protected_Entry_Call
6558 -- (po._object'Access, -- Object
6559 -- <entry index>, -- E
6560 -- P'Address, -- Uninterpreted_Data
6561 -- Asynchronous_Call, -- Mode
6564 -- if Enqueued (Bnn) then
6568 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6571 -- when Abort_Signal => Abort_Undefer;
6574 -- if not Cancelled (Bnn) then
6575 -- <triggered-statements>
6579 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6583 -- P : E1_Params := (param, param, param);
6584 -- Bnn : Communications_Block;
6587 -- Protected_Entry_Call
6588 -- (po._object'Access, -- Object
6589 -- <entry index>, -- E
6590 -- P'Address, -- Uninterpreted_Data
6591 -- Simple_Call, -- Mode
6598 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6602 -- B : Boolean := False;
6603 -- Bnn : Communication_Block;
6604 -- C : Ada.Tags.Prim_Op_Kind;
6605 -- D : System.Storage_Elements.Dummy_Communication_Block;
6606 -- K : Ada.Tags.Tagged_Kind :=
6607 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6608 -- P : Parameters := (Param1 .. ParamN);
6613 -- if K = Ada.Tags.TK_Limited_Tagged
6614 -- or else K = Ada.Tags.TK_Tagged
6616 -- <dispatching-call>;
6617 -- <triggering-statements>;
6621 -- Ada.Tags.Get_Offset_Index
6622 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6624 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6626 -- if C = POK_Protected_Entry then
6628 -- procedure _clean is
6630 -- if Enqueued (Bnn) then
6631 -- Cancel_Protected_Entry_Call (Bnn);
6637 -- _Disp_Asynchronous_Select
6638 -- (<object>, S, P'Address, D, B);
6639 -- Bnn := Communication_Block (D);
6641 -- Param1 := P.Param1;
6643 -- ParamN := P.ParamN;
6645 -- if Enqueued (Bnn) then
6646 -- <abortable-statements>
6649 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6652 -- when Abort_Signal => Abort_Undefer;
6655 -- if not Cancelled (Bnn) then
6656 -- <triggering-statements>
6659 -- elsif C = POK_Task_Entry then
6661 -- procedure _clean is
6663 -- Cancel_Task_Entry_Call (U);
6669 -- _Disp_Asynchronous_Select
6670 -- (<object>, S, P'Address, D, B);
6671 -- Bnn := Communication_Bloc (D);
6673 -- Param1 := P.Param1;
6675 -- ParamN := P.ParamN;
6680 -- <abortable-statements>
6682 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6685 -- when Abort_Signal => Abort_Undefer;
6689 -- <triggering-statements>
6694 -- <dispatching-call>;
6695 -- <triggering-statements>
6700 -- The job is to convert this to the asynchronous form
6702 -- If the trigger is a delay statement, it will have been expanded into
6703 -- a call to one of the GNARL delay procedures. This routine will convert
6704 -- this into a protected entry call on a delay object and then continue
6705 -- processing as for a protected entry call trigger. This requires
6706 -- declaring a Delay_Block object and adding a pointer to this object to
6707 -- the parameter list of the delay procedure to form the parameter list of
6708 -- the entry call. This object is used by the runtime to queue the delay
6711 -- For a description of the use of P and the assignments after the call,
6712 -- see Expand_N_Entry_Call_Statement.
6714 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
6715 Loc : constant Source_Ptr := Sloc (N);
6716 Abrt : constant Node_Id := Abortable_Part (N);
6717 Trig : constant Node_Id := Triggering_Alternative (N);
6719 Abort_Block_Ent : Entity_Id;
6720 Abortable_Block : Node_Id;
6723 Blk_Ent : constant Entity_Id := Make_Temporary (Loc, 'A');
6724 Blk_Typ : Entity_Id;
6726 Call_Ent : Entity_Id;
6727 Cancel_Param : Entity_Id;
6728 Cleanup_Block : Node_Id;
6729 Cleanup_Block_Ent : Entity_Id;
6730 Cleanup_Stmts : List_Id;
6731 Conc_Typ_Stmts : List_Id;
6733 Dblock_Ent : Entity_Id;
6738 Enqueue_Call : Node_Id;
6741 Handler_Stmt : Node_Id;
6743 Lim_Typ_Stmts : List_Id;
6749 ProtE_Stmts : List_Id;
6750 ProtP_Stmts : List_Id;
6753 TaskE_Stmts : List_Id;
6756 B : Entity_Id; -- Call status flag
6757 Bnn : Entity_Id; -- Communication block
6758 C : Entity_Id; -- Call kind
6759 K : Entity_Id; -- Tagged kind
6760 P : Entity_Id; -- Parameter block
6761 S : Entity_Id; -- Primitive operation slot
6762 T : Entity_Id; -- Additional status flag
6764 procedure Rewrite_Abortable_Part;
6765 -- If the trigger is a dispatching call, the expansion inserts multiple
6766 -- copies of the abortable part. This is both inefficient, and may lead
6767 -- to duplicate definitions that the back-end will reject, when the
6768 -- abortable part includes loops. This procedure rewrites the abortable
6769 -- part into a call to a generated procedure.
6771 ----------------------------
6772 -- Rewrite_Abortable_Part --
6773 ----------------------------
6775 procedure Rewrite_Abortable_Part is
6776 Proc : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
6781 Make_Subprogram_Body (Loc,
6783 Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc),
6784 Declarations => New_List,
6785 Handled_Statement_Sequence =>
6786 Make_Handled_Sequence_Of_Statements (Loc, Astats));
6787 Insert_Before (N, Decl);
6790 -- Rewrite abortable part into a call to this procedure.
6794 Make_Procedure_Call_Statement (Loc,
6795 Name => New_Occurrence_Of (Proc, Loc)));
6796 end Rewrite_Abortable_Part;
6798 -- Start of processing for Expand_N_Asynchronous_Select
6801 -- Asynchronous select is not supported on restricted runtimes. Don't
6804 if Restricted_Profile then
6808 Process_Statements_For_Controlled_Objects (Trig);
6809 Process_Statements_For_Controlled_Objects (Abrt);
6811 Ecall := Triggering_Statement (Trig);
6813 Ensure_Statement_Present (Sloc (Ecall), Trig);
6815 -- Retrieve Astats and Tstats now because the finalization machinery may
6816 -- wrap them in blocks.
6818 Astats := Statements (Abrt);
6819 Tstats := Statements (Trig);
6821 -- The arguments in the call may require dynamic allocation, and the
6822 -- call statement may have been transformed into a block. The block
6823 -- may contain additional declarations for internal entities, and the
6824 -- original call is found by sequential search.
6826 if Nkind (Ecall) = N_Block_Statement then
6827 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
6828 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
6829 N_Entry_Call_Statement)
6835 -- This is either a dispatching call or a delay statement used as a
6836 -- trigger which was expanded into a procedure call.
6838 if Nkind (Ecall) = N_Procedure_Call_Statement then
6839 if Ada_Version >= Ada_2005
6841 (No (Original_Node (Ecall))
6842 or else not Nkind_In (Original_Node (Ecall),
6843 N_Delay_Relative_Statement,
6844 N_Delay_Until_Statement))
6846 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
6848 Rewrite_Abortable_Part;
6852 -- Call status flag processing, generate:
6853 -- B : Boolean := False;
6855 B := Build_B (Loc, Decls);
6857 -- Communication block processing, generate:
6858 -- Bnn : Communication_Block;
6860 Bnn := Make_Temporary (Loc, 'B');
6862 Make_Object_Declaration (Loc,
6863 Defining_Identifier => Bnn,
6864 Object_Definition =>
6865 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
6867 -- Call kind processing, generate:
6868 -- C : Ada.Tags.Prim_Op_Kind;
6870 C := Build_C (Loc, Decls);
6872 -- Tagged kind processing, generate:
6873 -- K : Ada.Tags.Tagged_Kind :=
6874 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6876 -- Dummy communication block, generate:
6877 -- D : Dummy_Communication_Block;
6880 Make_Object_Declaration (Loc,
6881 Defining_Identifier =>
6882 Make_Defining_Identifier (Loc, Name_uD),
6883 Object_Definition =>
6885 (RTE (RE_Dummy_Communication_Block), Loc)));
6887 K := Build_K (Loc, Decls, Obj);
6889 -- Parameter block processing
6891 Blk_Typ := Build_Parameter_Block
6892 (Loc, Actuals, Formals, Decls);
6893 P := Parameter_Block_Pack
6894 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
6896 -- Dispatch table slot processing, generate:
6899 S := Build_S (Loc, Decls);
6901 -- Additional status flag processing, generate:
6904 T := Make_Temporary (Loc, 'T');
6906 Make_Object_Declaration (Loc,
6907 Defining_Identifier => T,
6908 Object_Definition =>
6909 New_Occurrence_Of (Standard_Boolean, Loc)));
6911 ------------------------------
6912 -- Protected entry handling --
6913 ------------------------------
6916 -- Param1 := P.Param1;
6918 -- ParamN := P.ParamN;
6920 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
6923 -- Bnn := Communication_Block (D);
6925 Prepend_To (Cleanup_Stmts,
6926 Make_Assignment_Statement (Loc,
6927 Name => New_Occurrence_Of (Bnn, Loc),
6929 Make_Unchecked_Type_Conversion (Loc,
6931 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
6932 Expression => Make_Identifier (Loc, Name_uD))));
6935 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
6937 Prepend_To (Cleanup_Stmts,
6938 Make_Procedure_Call_Statement (Loc,
6942 (Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select),
6944 Parameter_Associations =>
6946 New_Copy_Tree (Obj), -- <object>
6947 New_Occurrence_Of (S, Loc), -- S
6948 Make_Attribute_Reference (Loc, -- P'Address
6949 Prefix => New_Occurrence_Of (P, Loc),
6950 Attribute_Name => Name_Address),
6951 Make_Identifier (Loc, Name_uD), -- D
6952 New_Occurrence_Of (B, Loc)))); -- B
6955 -- if Enqueued (Bnn) then
6956 -- <abortable-statements>
6959 Append_To (Cleanup_Stmts,
6960 Make_Implicit_If_Statement (N,
6962 Make_Function_Call (Loc,
6964 New_Occurrence_Of (RTE (RE_Enqueued), Loc),
6965 Parameter_Associations =>
6966 New_List (New_Occurrence_Of (Bnn, Loc))),
6969 New_Copy_List_Tree (Astats)));
6971 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
6972 -- will then generate a _clean for the communication block Bnn.
6976 -- procedure _clean is
6978 -- if Enqueued (Bnn) then
6979 -- Cancel_Protected_Entry_Call (Bnn);
6988 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
6990 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
6992 -- Wrap the cleanup block in an exception handling block
6998 -- when Abort_Signal => Abort_Undefer;
7001 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7004 Make_Implicit_Label_Declaration (Loc,
7005 Defining_Identifier => Abort_Block_Ent),
7008 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7011 -- if not Cancelled (Bnn) then
7012 -- <triggering-statements>
7015 Append_To (ProtE_Stmts,
7016 Make_Implicit_If_Statement (N,
7020 Make_Function_Call (Loc,
7022 New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7023 Parameter_Associations =>
7024 New_List (New_Occurrence_Of (Bnn, Loc)))),
7027 New_Copy_List_Tree (Tstats)));
7029 -------------------------
7030 -- Task entry handling --
7031 -------------------------
7034 -- Param1 := P.Param1;
7036 -- ParamN := P.ParamN;
7038 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7041 -- Bnn := Communication_Block (D);
7043 Append_To (TaskE_Stmts,
7044 Make_Assignment_Statement (Loc,
7046 New_Occurrence_Of (Bnn, Loc),
7048 Make_Unchecked_Type_Conversion (Loc,
7050 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7051 Expression => Make_Identifier (Loc, Name_uD))));
7054 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7056 Prepend_To (TaskE_Stmts,
7057 Make_Procedure_Call_Statement (Loc,
7060 Find_Prim_Op (Etype (Etype (Obj)),
7061 Name_uDisp_Asynchronous_Select),
7064 Parameter_Associations => New_List (
7065 New_Copy_Tree (Obj), -- <object>
7066 New_Occurrence_Of (S, Loc), -- S
7067 Make_Attribute_Reference (Loc, -- P'Address
7068 Prefix => New_Occurrence_Of (P, Loc),
7069 Attribute_Name => Name_Address),
7070 Make_Identifier (Loc, Name_uD), -- D
7071 New_Occurrence_Of (B, Loc)))); -- B
7076 Prepend_To (TaskE_Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
7080 -- <abortable-statements>
7082 Cleanup_Stmts := New_Copy_List_Tree (Astats);
7085 (Cleanup_Stmts, Build_Runtime_Call (Loc, RE_Abort_Undefer));
7087 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7088 -- will generate a _clean for the additional status flag.
7092 -- procedure _clean is
7094 -- Cancel_Task_Entry_Call (U);
7102 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7104 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
7106 -- Wrap the cleanup block in an exception handling block
7112 -- when Abort_Signal => Abort_Undefer;
7115 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7117 Append_To (TaskE_Stmts,
7118 Make_Implicit_Label_Declaration (Loc,
7119 Defining_Identifier => Abort_Block_Ent));
7121 Append_To (TaskE_Stmts,
7123 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7127 -- <triggering-statements>
7130 Append_To (TaskE_Stmts,
7131 Make_Implicit_If_Statement (N,
7133 Make_Op_Not (Loc, Right_Opnd => New_Occurrence_Of (T, Loc)),
7136 New_Copy_List_Tree (Tstats)));
7138 ----------------------------------
7139 -- Protected procedure handling --
7140 ----------------------------------
7143 -- <dispatching-call>;
7144 -- <triggering-statements>
7146 ProtP_Stmts := New_Copy_List_Tree (Tstats);
7147 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
7150 -- S := Ada.Tags.Get_Offset_Index
7151 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7154 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7157 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7159 Append_To (Conc_Typ_Stmts,
7160 Make_Procedure_Call_Statement (Loc,
7163 (Find_Prim_Op (Etype (Etype (Obj)),
7164 Name_uDisp_Get_Prim_Op_Kind),
7166 Parameter_Associations =>
7168 New_Copy_Tree (Obj),
7169 New_Occurrence_Of (S, Loc),
7170 New_Occurrence_Of (C, Loc))));
7173 -- if C = POK_Procedure_Entry then
7175 -- elsif C = POK_Task_Entry then
7181 Append_To (Conc_Typ_Stmts,
7182 Make_Implicit_If_Statement (N,
7186 New_Occurrence_Of (C, Loc),
7188 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
7195 Make_Elsif_Part (Loc,
7199 New_Occurrence_Of (C, Loc),
7201 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc)),
7210 -- <dispatching-call>;
7211 -- <triggering-statements>
7213 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
7214 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
7217 -- if K = Ada.Tags.TK_Limited_Tagged
7218 -- or else K = Ada.Tags.TK_Tagged
7226 Make_Implicit_If_Statement (N,
7227 Condition => Build_Dispatching_Tag_Check (K, N),
7228 Then_Statements => Lim_Typ_Stmts,
7229 Else_Statements => Conc_Typ_Stmts));
7232 Make_Block_Statement (Loc,
7235 Handled_Statement_Sequence =>
7236 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7241 -- Delay triggering statement processing
7244 -- Add a Delay_Block object to the parameter list of the delay
7245 -- procedure to form the parameter list of the Wait entry call.
7247 Dblock_Ent := Make_Temporary (Loc, 'D');
7249 Pdef := Entity (Name (Ecall));
7251 if Is_RTE (Pdef, RO_CA_Delay_For) then
7253 New_Occurrence_Of (RTE (RE_Enqueue_Duration), Loc);
7255 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
7257 New_Occurrence_Of (RTE (RE_Enqueue_Calendar), Loc);
7259 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
7260 Enqueue_Call := New_Occurrence_Of (RTE (RE_Enqueue_RT), Loc);
7263 Append_To (Parameter_Associations (Ecall),
7264 Make_Attribute_Reference (Loc,
7265 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7266 Attribute_Name => Name_Unchecked_Access));
7268 -- Create the inner block to protect the abortable part
7270 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7272 Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer));
7275 Make_Block_Statement (Loc,
7276 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7277 Handled_Statement_Sequence =>
7278 Make_Handled_Sequence_Of_Statements (Loc,
7279 Statements => Astats),
7280 Has_Created_Identifier => True,
7281 Is_Asynchronous_Call_Block => True);
7283 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7286 Make_Implicit_If_Statement (N,
7288 Make_Function_Call (Loc,
7289 Name => Enqueue_Call,
7290 Parameter_Associations => Parameter_Associations (Ecall)),
7292 New_List (Make_Block_Statement (Loc,
7293 Handled_Statement_Sequence =>
7294 Make_Handled_Sequence_Of_Statements (Loc,
7295 Statements => New_List (
7296 Make_Implicit_Label_Declaration (Loc,
7297 Defining_Identifier => Blk_Ent,
7298 Label_Construct => Abortable_Block),
7300 Exception_Handlers => Hdle)))));
7302 Stmts := New_List (Ecall);
7304 -- Construct statement sequence for new block
7307 Make_Implicit_If_Statement (N,
7309 Make_Function_Call (Loc,
7310 Name => New_Occurrence_Of (
7311 RTE (RE_Timed_Out), Loc),
7312 Parameter_Associations => New_List (
7313 Make_Attribute_Reference (Loc,
7314 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7315 Attribute_Name => Name_Unchecked_Access))),
7316 Then_Statements => Tstats));
7318 -- The result is the new block
7320 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
7323 Make_Block_Statement (Loc,
7324 Declarations => New_List (
7325 Make_Object_Declaration (Loc,
7326 Defining_Identifier => Dblock_Ent,
7327 Aliased_Present => True,
7328 Object_Definition =>
7329 New_Occurrence_Of (RTE (RE_Delay_Block), Loc))),
7331 Handled_Statement_Sequence =>
7332 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7342 Extract_Entry (Ecall, Concval, Ename, Index);
7343 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
7345 Stmts := Statements (Handled_Statement_Sequence (Ecall));
7346 Decls := Declarations (Ecall);
7348 if Is_Protected_Type (Etype (Concval)) then
7350 -- Get the declarations of the block expanded from the entry call
7352 Decl := First (Decls);
7353 while Present (Decl)
7354 and then (Nkind (Decl) /= N_Object_Declaration
7355 or else not Is_RTE (Etype (Object_Definition (Decl)),
7356 RE_Communication_Block))
7361 pragma Assert (Present (Decl));
7362 Cancel_Param := Defining_Identifier (Decl);
7364 -- Change the mode of the Protected_Entry_Call call
7366 -- Protected_Entry_Call (
7367 -- Object => po._object'Access,
7368 -- E => <entry index>;
7369 -- Uninterpreted_Data => P'Address;
7370 -- Mode => Asynchronous_Call;
7373 -- Skip assignments to temporaries created for in-out parameters
7375 -- This makes unwarranted assumptions about the shape of the expanded
7376 -- tree for the call, and should be cleaned up ???
7378 Stmt := First (Stmts);
7379 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7385 Param := First (Parameter_Associations (Call));
7386 while Present (Param)
7387 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7392 pragma Assert (Present (Param));
7393 Rewrite (Param, New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7396 -- Append an if statement to execute the abortable part
7399 -- if Enqueued (Bnn) then
7402 Make_Implicit_If_Statement (N,
7404 Make_Function_Call (Loc,
7405 Name => New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7406 Parameter_Associations => New_List (
7407 New_Occurrence_Of (Cancel_Param, Loc))),
7408 Then_Statements => Astats));
7411 Make_Block_Statement (Loc,
7412 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7413 Handled_Statement_Sequence =>
7414 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts),
7415 Has_Created_Identifier => True,
7416 Is_Asynchronous_Call_Block => True);
7418 -- Aborts are not deferred at beginning of exception handlers in
7421 if ZCX_Exceptions then
7422 Handler_Stmt := Make_Null_Statement (Loc);
7425 Handler_Stmt := Build_Runtime_Call (Loc, RE_Abort_Undefer);
7429 Make_Block_Statement (Loc,
7430 Handled_Statement_Sequence =>
7431 Make_Handled_Sequence_Of_Statements (Loc,
7432 Statements => New_List (
7433 Make_Implicit_Label_Declaration (Loc,
7434 Defining_Identifier => Blk_Ent,
7435 Label_Construct => Abortable_Block),
7440 Exception_Handlers => New_List (
7441 Make_Implicit_Exception_Handler (Loc,
7443 -- when Abort_Signal =>
7444 -- Abort_Undefer.all;
7446 Exception_Choices =>
7447 New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)),
7448 Statements => New_List (Handler_Stmt))))),
7450 -- if not Cancelled (Bnn) then
7451 -- triggered statements
7454 Make_Implicit_If_Statement (N,
7455 Condition => Make_Op_Not (Loc,
7457 Make_Function_Call (Loc,
7458 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7459 Parameter_Associations => New_List (
7460 New_Occurrence_Of (Cancel_Param, Loc)))),
7461 Then_Statements => Tstats));
7463 -- Asynchronous task entry call
7470 B := Make_Defining_Identifier (Loc, Name_uB);
7472 -- Insert declaration of B in declarations of existing block
7475 Make_Object_Declaration (Loc,
7476 Defining_Identifier => B,
7477 Object_Definition =>
7478 New_Occurrence_Of (Standard_Boolean, Loc)));
7480 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
7482 -- Insert declaration of C in declarations of existing block
7485 Make_Object_Declaration (Loc,
7486 Defining_Identifier => Cancel_Param,
7487 Object_Definition =>
7488 New_Occurrence_Of (Standard_Boolean, Loc)));
7490 -- Remove and save the call to Call_Simple
7492 Stmt := First (Stmts);
7494 -- Skip assignments to temporaries created for in-out parameters.
7495 -- This makes unwarranted assumptions about the shape of the expanded
7496 -- tree for the call, and should be cleaned up ???
7498 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7504 -- Create the inner block to protect the abortable part
7506 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7508 Prepend_To (Astats, Build_Runtime_Call (Loc, RE_Abort_Undefer));
7511 Make_Block_Statement (Loc,
7512 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7513 Handled_Statement_Sequence =>
7514 Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats),
7515 Has_Created_Identifier => True,
7516 Is_Asynchronous_Call_Block => True);
7519 Make_Block_Statement (Loc,
7520 Handled_Statement_Sequence =>
7521 Make_Handled_Sequence_Of_Statements (Loc,
7522 Statements => New_List (
7523 Make_Implicit_Label_Declaration (Loc,
7524 Defining_Identifier => Blk_Ent,
7525 Label_Construct => Abortable_Block),
7527 Exception_Handlers => Hdle)));
7529 -- Create new call statement
7531 Params := Parameter_Associations (Call);
7534 New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7535 Append_To (Params, New_Occurrence_Of (B, Loc));
7538 Make_Procedure_Call_Statement (Loc,
7539 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
7540 Parameter_Associations => Params));
7542 -- Construct statement sequence for new block
7545 Make_Implicit_If_Statement (N,
7547 Make_Op_Not (Loc, New_Occurrence_Of (Cancel_Param, Loc)),
7548 Then_Statements => Tstats));
7550 -- Protected the call against abort
7552 Prepend_To (Stmts, Build_Runtime_Call (Loc, RE_Abort_Defer));
7555 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
7557 -- The result is the new block
7560 Make_Block_Statement (Loc,
7561 Declarations => Decls,
7562 Handled_Statement_Sequence =>
7563 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7566 end Expand_N_Asynchronous_Select;
7568 -------------------------------------
7569 -- Expand_N_Conditional_Entry_Call --
7570 -------------------------------------
7572 -- The conditional task entry call is converted to a call to
7577 -- P : parms := (parm, parm, parm);
7581 -- (<acceptor-task>, -- Acceptor
7582 -- <entry-index>, -- E
7583 -- P'Address, -- Uninterpreted_Data
7584 -- Conditional_Call, -- Mode
7585 -- B); -- Rendezvous_Successful
7590 -- normal-statements
7596 -- For a description of the use of P and the assignments after the call,
7597 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7598 -- conditional entry call has already been expanded (by the Expand_N_Entry
7599 -- _Call_Statement procedure) as follows:
7602 -- P : parms := (parm, parm, parm);
7604 -- ... info for in-out parameters
7605 -- Call_Simple (acceptor-task, entry-index, P'Address);
7611 -- so the task at hand is to convert the latter expansion into the former
7613 -- The conditional protected entry call is converted to a call to
7614 -- Protected_Entry_Call:
7617 -- P : parms := (parm, parm, parm);
7618 -- Bnn : Communications_Block;
7621 -- Protected_Entry_Call
7622 -- (po._object'Access, -- Object
7623 -- <entry index>, -- E
7624 -- P'Address, -- Uninterpreted_Data
7625 -- Conditional_Call, -- Mode
7630 -- if Cancelled (Bnn) then
7633 -- normal-statements
7637 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7641 -- B : Boolean := False;
7642 -- C : Ada.Tags.Prim_Op_Kind;
7643 -- K : Ada.Tags.Tagged_Kind :=
7644 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7645 -- P : Parameters := (Param1 .. ParamN);
7649 -- if K = Ada.Tags.TK_Limited_Tagged
7650 -- or else K = Ada.Tags.TK_Tagged
7652 -- <dispatching-call>;
7653 -- <triggering-statements>
7657 -- Ada.Tags.Get_Offset_Index
7658 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7660 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7662 -- if C = POK_Protected_Entry
7663 -- or else C = POK_Task_Entry
7665 -- Param1 := P.Param1;
7667 -- ParamN := P.ParamN;
7671 -- if C = POK_Procedure
7672 -- or else C = POK_Protected_Procedure
7673 -- or else C = POK_Task_Procedure
7675 -- <dispatching-call>;
7678 -- <triggering-statements>
7680 -- <else-statements>
7685 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
7686 Loc : constant Source_Ptr := Sloc (N);
7687 Alt : constant Node_Id := Entry_Call_Alternative (N);
7688 Blk : Node_Id := Entry_Call_Statement (Alt);
7691 Blk_Typ : Entity_Id;
7693 Call_Ent : Entity_Id;
7694 Conc_Typ_Stmts : List_Id;
7698 Lim_Typ_Stmts : List_Id;
7705 Transient_Blk : Node_Id;
7708 B : Entity_Id; -- Call status flag
7709 C : Entity_Id; -- Call kind
7710 K : Entity_Id; -- Tagged kind
7711 P : Entity_Id; -- Parameter block
7712 S : Entity_Id; -- Primitive operation slot
7715 Process_Statements_For_Controlled_Objects (N);
7717 if Ada_Version >= Ada_2005
7718 and then Nkind (Blk) = N_Procedure_Call_Statement
7720 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7725 -- Call status flag processing, generate:
7726 -- B : Boolean := False;
7728 B := Build_B (Loc, Decls);
7730 -- Call kind processing, generate:
7731 -- C : Ada.Tags.Prim_Op_Kind;
7733 C := Build_C (Loc, Decls);
7735 -- Tagged kind processing, generate:
7736 -- K : Ada.Tags.Tagged_Kind :=
7737 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7739 K := Build_K (Loc, Decls, Obj);
7741 -- Parameter block processing
7743 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7744 P := Parameter_Block_Pack
7745 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7747 -- Dispatch table slot processing, generate:
7750 S := Build_S (Loc, Decls);
7753 -- S := Ada.Tags.Get_Offset_Index
7754 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7757 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7760 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7762 Append_To (Conc_Typ_Stmts,
7763 Make_Procedure_Call_Statement (Loc,
7766 Find_Prim_Op (Etype (Etype (Obj)),
7767 Name_uDisp_Conditional_Select),
7769 Parameter_Associations =>
7771 New_Copy_Tree (Obj), -- <object>
7772 New_Occurrence_Of (S, Loc), -- S
7773 Make_Attribute_Reference (Loc, -- P'Address
7774 Prefix => New_Occurrence_Of (P, Loc),
7775 Attribute_Name => Name_Address),
7776 New_Occurrence_Of (C, Loc), -- C
7777 New_Occurrence_Of (B, Loc)))); -- B
7780 -- if C = POK_Protected_Entry
7781 -- or else C = POK_Task_Entry
7783 -- Param1 := P.Param1;
7785 -- ParamN := P.ParamN;
7788 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7790 -- Generate the if statement only when the packed parameters need
7791 -- explicit assignments to their corresponding actuals.
7793 if Present (Unpack) then
7794 Append_To (Conc_Typ_Stmts,
7795 Make_Implicit_If_Statement (N,
7801 New_Occurrence_Of (C, Loc),
7803 New_Occurrence_Of (RTE (
7804 RE_POK_Protected_Entry), Loc)),
7809 New_Occurrence_Of (C, Loc),
7811 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
7813 Then_Statements => Unpack));
7818 -- if C = POK_Procedure
7819 -- or else C = POK_Protected_Procedure
7820 -- or else C = POK_Task_Procedure
7822 -- <dispatching-call>
7824 -- <normal-statements>
7826 -- <else-statements>
7829 N_Stats := New_Copy_List_Tree (Statements (Alt));
7831 Prepend_To (N_Stats,
7832 Make_Implicit_If_Statement (N,
7838 New_Occurrence_Of (C, Loc),
7840 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
7847 New_Occurrence_Of (C, Loc),
7849 New_Occurrence_Of (RTE (
7850 RE_POK_Protected_Procedure), Loc)),
7855 New_Occurrence_Of (C, Loc),
7857 New_Occurrence_Of (RTE (
7858 RE_POK_Task_Procedure), Loc)))),
7863 Append_To (Conc_Typ_Stmts,
7864 Make_Implicit_If_Statement (N,
7865 Condition => New_Occurrence_Of (B, Loc),
7866 Then_Statements => N_Stats,
7867 Else_Statements => Else_Statements (N)));
7870 -- <dispatching-call>;
7871 -- <triggering-statements>
7873 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
7874 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
7877 -- if K = Ada.Tags.TK_Limited_Tagged
7878 -- or else K = Ada.Tags.TK_Tagged
7886 Make_Implicit_If_Statement (N,
7887 Condition => Build_Dispatching_Tag_Check (K, N),
7888 Then_Statements => Lim_Typ_Stmts,
7889 Else_Statements => Conc_Typ_Stmts));
7892 Make_Block_Statement (Loc,
7895 Handled_Statement_Sequence =>
7896 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7898 -- As described above, the entry alternative is transformed into a
7899 -- block that contains the gnulli call, and possibly assignment
7900 -- statements for in-out parameters. The gnulli call may itself be
7901 -- rewritten into a transient block if some unconstrained parameters
7902 -- require it. We need to retrieve the call to complete its parameter
7907 First_Real_Statement (Handled_Statement_Sequence (Blk));
7909 if Present (Transient_Blk)
7910 and then Nkind (Transient_Blk) = N_Block_Statement
7912 Blk := Transient_Blk;
7915 Stmts := Statements (Handled_Statement_Sequence (Blk));
7916 Stmt := First (Stmts);
7917 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7922 Params := Parameter_Associations (Call);
7924 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
7926 -- Substitute Conditional_Entry_Call for Simple_Call parameter
7928 Param := First (Params);
7929 while Present (Param)
7930 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7935 pragma Assert (Present (Param));
7937 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
7941 -- Find the Communication_Block parameter for the call to the
7942 -- Cancelled function.
7944 Decl := First (Declarations (Blk));
7945 while Present (Decl)
7946 and then not Is_RTE (Etype (Object_Definition (Decl)),
7947 RE_Communication_Block)
7952 -- Add an if statement to execute the else part if the call
7953 -- does not succeed (as indicated by the Cancelled predicate).
7956 Make_Implicit_If_Statement (N,
7957 Condition => Make_Function_Call (Loc,
7958 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7959 Parameter_Associations => New_List (
7960 New_Occurrence_Of (Defining_Identifier (Decl), Loc))),
7961 Then_Statements => Else_Statements (N),
7962 Else_Statements => Statements (Alt)));
7965 B := Make_Defining_Identifier (Loc, Name_uB);
7967 -- Insert declaration of B in declarations of existing block
7969 if No (Declarations (Blk)) then
7970 Set_Declarations (Blk, New_List);
7973 Prepend_To (Declarations (Blk),
7974 Make_Object_Declaration (Loc,
7975 Defining_Identifier => B,
7976 Object_Definition =>
7977 New_Occurrence_Of (Standard_Boolean, Loc)));
7979 -- Create new call statement
7982 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
7983 Append_To (Params, New_Occurrence_Of (B, Loc));
7986 Make_Procedure_Call_Statement (Loc,
7987 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
7988 Parameter_Associations => Params));
7990 -- Construct statement sequence for new block
7993 Make_Implicit_If_Statement (N,
7994 Condition => New_Occurrence_Of (B, Loc),
7995 Then_Statements => Statements (Alt),
7996 Else_Statements => Else_Statements (N)));
7999 -- The result is the new block
8002 Make_Block_Statement (Loc,
8003 Declarations => Declarations (Blk),
8004 Handled_Statement_Sequence =>
8005 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8009 end Expand_N_Conditional_Entry_Call;
8011 ---------------------------------------
8012 -- Expand_N_Delay_Relative_Statement --
8013 ---------------------------------------
8015 -- Delay statement is implemented as a procedure call to Delay_For
8016 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8017 -- simple delays imposed by the use of Protected Objects.
8019 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
8020 Loc : constant Source_Ptr := Sloc (N);
8024 -- Try to use System.Relative_Delays.Delay_For only if available. This
8025 -- is the implementation used on restricted platforms when Ada.Calendar
8026 -- is not available.
8028 if RTE_Available (RO_RD_Delay_For) then
8029 Proc := RTE (RO_RD_Delay_For);
8031 -- Otherwise, use Ada.Calendar.Delays.Delay_For and emit an error
8032 -- message if not available.
8035 Proc := RTE (RO_CA_Delay_For);
8039 Make_Procedure_Call_Statement (Loc,
8040 Name => New_Occurrence_Of (Proc, Loc),
8041 Parameter_Associations => New_List (Expression (N))));
8043 end Expand_N_Delay_Relative_Statement;
8045 ------------------------------------
8046 -- Expand_N_Delay_Until_Statement --
8047 ------------------------------------
8049 -- Delay Until statement is implemented as a procedure call to
8050 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8052 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
8053 Loc : constant Source_Ptr := Sloc (N);
8057 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
8058 Typ := RTE (RO_CA_Delay_Until);
8060 Typ := RTE (RO_RT_Delay_Until);
8064 Make_Procedure_Call_Statement (Loc,
8065 Name => New_Occurrence_Of (Typ, Loc),
8066 Parameter_Associations => New_List (Expression (N))));
8069 end Expand_N_Delay_Until_Statement;
8071 -------------------------
8072 -- Expand_N_Entry_Body --
8073 -------------------------
8075 procedure Expand_N_Entry_Body (N : Node_Id) is
8077 -- Associate discriminals with the next protected operation body to be
8080 if Present (Next_Protected_Operation (N)) then
8081 Set_Discriminals (Parent (Current_Scope));
8083 end Expand_N_Entry_Body;
8085 -----------------------------------
8086 -- Expand_N_Entry_Call_Statement --
8087 -----------------------------------
8089 -- An entry call is expanded into GNARLI calls to implement a simple entry
8090 -- call (see Build_Simple_Entry_Call).
8092 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
8098 if No_Run_Time_Mode then
8099 Error_Msg_CRT ("entry call", N);
8103 -- If this entry call is part of an asynchronous select, don't expand it
8104 -- here; it will be expanded with the select statement. Don't expand
8105 -- timed entry calls either, as they are translated into asynchronous
8108 -- ??? This whole approach is questionable; it may be better to go back
8109 -- to allowing the expansion to take place and then attempting to fix it
8110 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8111 -- whether the expanded call is on a task or protected entry.
8113 if (Nkind (Parent (N)) /= N_Triggering_Alternative
8114 or else N /= Triggering_Statement (Parent (N)))
8115 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
8116 or else N /= Entry_Call_Statement (Parent (N))
8117 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
8119 Extract_Entry (N, Concval, Ename, Index);
8120 Build_Simple_Entry_Call (N, Concval, Ename, Index);
8122 end Expand_N_Entry_Call_Statement;
8124 --------------------------------
8125 -- Expand_N_Entry_Declaration --
8126 --------------------------------
8128 -- If there are parameters, then first, each of the formals is marked by
8129 -- setting Is_Entry_Formal. Next a record type is built which is used to
8130 -- hold the parameter values. The name of this record type is entryP where
8131 -- entry is the name of the entry, with an additional corresponding access
8132 -- type called entryPA. The record type has matching components for each
8133 -- formal (the component names are the same as the formal names). For
8134 -- elementary types, the component type matches the formal type. For
8135 -- composite types, an access type is declared (with the name formalA)
8136 -- which designates the formal type, and the type of the component is this
8137 -- access type. Finally the Entry_Component of each formal is set to
8138 -- reference the corresponding record component.
8140 procedure Expand_N_Entry_Declaration (N : Node_Id) is
8141 Loc : constant Source_Ptr := Sloc (N);
8142 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
8143 Components : List_Id;
8146 Last_Decl : Node_Id;
8147 Component : Entity_Id;
8150 Rec_Ent : Entity_Id;
8151 Acc_Ent : Entity_Id;
8154 Formal := First_Formal (Entry_Ent);
8157 -- Most processing is done only if parameters are present
8159 if Present (Formal) then
8160 Components := New_List;
8162 -- Loop through formals
8164 while Present (Formal) loop
8165 Set_Is_Entry_Formal (Formal);
8167 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
8168 Set_Entry_Component (Formal, Component);
8169 Set_Entry_Formal (Component, Formal);
8170 Ftype := Etype (Formal);
8172 -- Declare new access type and then append
8174 Ctype := Make_Temporary (Loc, 'A');
8175 Set_Is_Param_Block_Component_Type (Ctype);
8178 Make_Full_Type_Declaration (Loc,
8179 Defining_Identifier => Ctype,
8181 Make_Access_To_Object_Definition (Loc,
8182 All_Present => True,
8183 Constant_Present => Ekind (Formal) = E_In_Parameter,
8184 Subtype_Indication => New_Occurrence_Of (Ftype, Loc)));
8186 Insert_After (Last_Decl, Decl);
8189 Append_To (Components,
8190 Make_Component_Declaration (Loc,
8191 Defining_Identifier => Component,
8192 Component_Definition =>
8193 Make_Component_Definition (Loc,
8194 Aliased_Present => False,
8195 Subtype_Indication => New_Occurrence_Of (Ctype, Loc))));
8197 Next_Formal_With_Extras (Formal);
8200 -- Create the Entry_Parameter_Record declaration
8202 Rec_Ent := Make_Temporary (Loc, 'P');
8205 Make_Full_Type_Declaration (Loc,
8206 Defining_Identifier => Rec_Ent,
8208 Make_Record_Definition (Loc,
8210 Make_Component_List (Loc,
8211 Component_Items => Components)));
8213 Insert_After (Last_Decl, Decl);
8216 -- Construct and link in the corresponding access type
8218 Acc_Ent := Make_Temporary (Loc, 'A');
8220 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
8223 Make_Full_Type_Declaration (Loc,
8224 Defining_Identifier => Acc_Ent,
8226 Make_Access_To_Object_Definition (Loc,
8227 All_Present => True,
8228 Subtype_Indication => New_Occurrence_Of (Rec_Ent, Loc)));
8230 Insert_After (Last_Decl, Decl);
8232 end Expand_N_Entry_Declaration;
8234 -----------------------------
8235 -- Expand_N_Protected_Body --
8236 -----------------------------
8238 -- Protected bodies are expanded to the completion of the subprograms
8239 -- created for the corresponding protected type. These are a protected and
8240 -- unprotected version of each protected subprogram in the object, a
8241 -- function to calculate each entry barrier, and a procedure to execute the
8242 -- sequence of statements of each protected entry body. For example, for
8243 -- protected type ptype:
8246 -- (O : System.Address;
8247 -- E : Protected_Entry_Index)
8250 -- <discriminant renamings>
8251 -- <private object renamings>
8253 -- return <barrier expression>;
8256 -- procedure pprocN (_object : in out poV;...) is
8257 -- <discriminant renamings>
8258 -- <private object renamings>
8260 -- <sequence of statements>
8263 -- procedure pprocP (_object : in out poV;...) is
8264 -- procedure _clean is
8267 -- ptypeS (_object, Pn);
8268 -- Unlock (_object._object'Access);
8269 -- Abort_Undefer.all;
8274 -- Lock (_object._object'Access);
8275 -- pprocN (_object;...);
8280 -- function pfuncN (_object : poV;...) return Return_Type is
8281 -- <discriminant renamings>
8282 -- <private object renamings>
8284 -- <sequence of statements>
8287 -- function pfuncP (_object : poV) return Return_Type is
8288 -- procedure _clean is
8290 -- Unlock (_object._object'Access);
8291 -- Abort_Undefer.all;
8296 -- Lock (_object._object'Access);
8297 -- return pfuncN (_object);
8304 -- (O : System.Address;
8305 -- P : System.Address;
8306 -- E : Protected_Entry_Index)
8308 -- <discriminant renamings>
8309 -- <private object renamings>
8310 -- type poVP is access poV;
8311 -- _Object : ptVP := ptVP!(O);
8315 -- <statement sequence>
8316 -- Complete_Entry_Body (_Object._Object);
8318 -- when all others =>
8319 -- Exceptional_Complete_Entry_Body (
8320 -- _Object._Object, Get_GNAT_Exception);
8324 -- The type poV is the record created for the protected type to hold
8325 -- the state of the protected object.
8327 procedure Expand_N_Protected_Body (N : Node_Id) is
8328 Loc : constant Source_Ptr := Sloc (N);
8329 Pid : constant Entity_Id := Corresponding_Spec (N);
8331 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Pid);
8332 -- This flag indicates whether the lock free implementation is active
8334 Current_Node : Node_Id;
8335 Disp_Op_Body : Node_Id;
8336 New_Op_Body : Node_Id;
8340 function Build_Dispatching_Subprogram_Body
8343 Prot_Bod : Node_Id) return Node_Id;
8344 -- Build a dispatching version of the protected subprogram body. The
8345 -- newly generated subprogram contains a call to the original protected
8346 -- body. The following code is generated:
8348 -- function <protected-function-name> (Param1 .. ParamN) return
8351 -- return <protected-function-name>P (Param1 .. ParamN);
8352 -- end <protected-function-name>;
8356 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8358 -- <protected-procedure-name>P (Param1 .. ParamN);
8359 -- end <protected-procedure-name>
8361 ---------------------------------------
8362 -- Build_Dispatching_Subprogram_Body --
8363 ---------------------------------------
8365 function Build_Dispatching_Subprogram_Body
8368 Prot_Bod : Node_Id) return Node_Id
8370 Loc : constant Source_Ptr := Sloc (N);
8377 -- Generate a specification without a letter suffix in order to
8378 -- override an interface function or procedure.
8380 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
8382 -- The formal parameters become the actuals of the protected function
8383 -- or procedure call.
8385 Actuals := New_List;
8386 Formal := First (Parameter_Specifications (Spec));
8387 while Present (Formal) loop
8389 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8393 if Nkind (Spec) = N_Procedure_Specification then
8396 Make_Procedure_Call_Statement (Loc,
8398 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8399 Parameter_Associations => Actuals));
8402 pragma Assert (Nkind (Spec) = N_Function_Specification);
8406 Make_Simple_Return_Statement (Loc,
8408 Make_Function_Call (Loc,
8410 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8411 Parameter_Associations => Actuals)));
8415 Make_Subprogram_Body (Loc,
8416 Declarations => Empty_List,
8417 Specification => Spec,
8418 Handled_Statement_Sequence =>
8419 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
8420 end Build_Dispatching_Subprogram_Body;
8422 -- Start of processing for Expand_N_Protected_Body
8425 if No_Run_Time_Mode then
8426 Error_Msg_CRT ("protected body", N);
8430 -- This is the proper body corresponding to a stub. The declarations
8431 -- must be inserted at the point of the stub, which in turn is in the
8432 -- declarative part of the parent unit.
8434 if Nkind (Parent (N)) = N_Subunit then
8435 Current_Node := Corresponding_Stub (Parent (N));
8440 Op_Body := First (Declarations (N));
8442 -- The protected body is replaced with the bodies of its
8443 -- protected operations, and the declarations for internal objects
8444 -- that may have been created for entry family bounds.
8446 Rewrite (N, Make_Null_Statement (Sloc (N)));
8449 while Present (Op_Body) loop
8450 case Nkind (Op_Body) is
8451 when N_Subprogram_Declaration =>
8454 when N_Subprogram_Body =>
8456 -- Do not create bodies for eliminated operations
8458 if not Is_Eliminated (Defining_Entity (Op_Body))
8459 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
8461 if Lock_Free_Active then
8463 Build_Lock_Free_Unprotected_Subprogram_Body
8467 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
8470 Insert_After (Current_Node, New_Op_Body);
8471 Current_Node := New_Op_Body;
8472 Analyze (New_Op_Body);
8474 -- Build the corresponding protected operation. It may
8475 -- appear that this is needed only if this is a visible
8476 -- operation of the type, or if it is an interrupt handler,
8477 -- and this was the strategy used previously in GNAT.
8479 -- However, the operation may be exported through a 'Access
8480 -- to an external caller. This is the common idiom in code
8481 -- that uses the Ada 2005 Timing_Events package. As a result
8482 -- we need to produce the protected body for both visible
8483 -- and private operations, as well as operations that only
8484 -- have a body in the source, and for which we create a
8485 -- declaration in the protected body itself.
8487 if Present (Corresponding_Spec (Op_Body)) then
8488 if Lock_Free_Active then
8490 Build_Lock_Free_Protected_Subprogram_Body
8491 (Op_Body, Pid, Specification (New_Op_Body));
8494 Build_Protected_Subprogram_Body
8495 (Op_Body, Pid, Specification (New_Op_Body));
8498 Insert_After (Current_Node, New_Op_Body);
8499 Analyze (New_Op_Body);
8501 Current_Node := New_Op_Body;
8503 -- Generate an overriding primitive operation body for
8504 -- this subprogram if the protected type implements an
8507 if Ada_Version >= Ada_2005
8509 Present (Interfaces (Corresponding_Record_Type (Pid)))
8512 Build_Dispatching_Subprogram_Body
8513 (Op_Body, Pid, New_Op_Body);
8515 Insert_After (Current_Node, Disp_Op_Body);
8516 Analyze (Disp_Op_Body);
8518 Current_Node := Disp_Op_Body;
8523 when N_Entry_Body =>
8524 Op_Id := Defining_Identifier (Op_Body);
8525 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
8527 Insert_After (Current_Node, New_Op_Body);
8528 Current_Node := New_Op_Body;
8529 Analyze (New_Op_Body);
8531 when N_Implicit_Label_Declaration =>
8534 when N_Itype_Reference =>
8535 Insert_After (Current_Node, New_Copy (Op_Body));
8537 when N_Freeze_Entity =>
8538 New_Op_Body := New_Copy (Op_Body);
8540 if Present (Entity (Op_Body))
8541 and then Freeze_Node (Entity (Op_Body)) = Op_Body
8543 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
8546 Insert_After (Current_Node, New_Op_Body);
8547 Current_Node := New_Op_Body;
8548 Analyze (New_Op_Body);
8551 New_Op_Body := New_Copy (Op_Body);
8552 Insert_After (Current_Node, New_Op_Body);
8553 Current_Node := New_Op_Body;
8554 Analyze (New_Op_Body);
8556 when N_Object_Declaration =>
8557 pragma Assert (not Comes_From_Source (Op_Body));
8558 New_Op_Body := New_Copy (Op_Body);
8559 Insert_After (Current_Node, New_Op_Body);
8560 Current_Node := New_Op_Body;
8561 Analyze (New_Op_Body);
8564 raise Program_Error;
8570 -- Finally, create the body of the function that maps an entry index
8571 -- into the corresponding body index, except when there is no entry, or
8572 -- in a Ravenscar-like profile.
8574 if Corresponding_Runtime_Package (Pid) =
8575 System_Tasking_Protected_Objects_Entries
8577 New_Op_Body := Build_Find_Body_Index (Pid);
8578 Insert_After (Current_Node, New_Op_Body);
8579 Current_Node := New_Op_Body;
8580 Analyze (New_Op_Body);
8583 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8584 -- protected body. At this point all wrapper specs have been created,
8585 -- frozen and included in the dispatch table for the protected type.
8587 if Ada_Version >= Ada_2005 then
8588 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
8590 end Expand_N_Protected_Body;
8592 -----------------------------------------
8593 -- Expand_N_Protected_Type_Declaration --
8594 -----------------------------------------
8596 -- First we create a corresponding record type declaration used to
8597 -- represent values of this protected type.
8598 -- The general form of this type declaration is
8600 -- type poV (discriminants) is record
8601 -- _Object : aliased <kind>Protection
8602 -- [(<entry count> [, <handler count>])];
8603 -- [entry_family : array (bounds) of Void;]
8604 -- <private data fields>
8607 -- The discriminants are present only if the corresponding protected type
8608 -- has discriminants, and they exactly mirror the protected type
8609 -- discriminants. The private data fields similarly mirror the private
8610 -- declarations of the protected type.
8612 -- The Object field is always present. It contains RTS specific data used
8613 -- to control the protected object. It is declared as Aliased so that it
8614 -- can be passed as a pointer to the RTS. This allows the protected record
8615 -- to be referenced within RTS data structures. An appropriate Protection
8616 -- type and discriminant are generated.
8618 -- The Service field is present for protected objects with entries. It
8619 -- contains sufficient information to allow the entry service procedure for
8620 -- this object to be called when the object is not known till runtime.
8622 -- One entry_family component is present for each entry family in the
8623 -- task definition (see Expand_N_Task_Type_Declaration).
8625 -- When a protected object is declared, an instance of the protected type
8626 -- value record is created. The elaboration of this declaration creates the
8627 -- correct bounds for the entry families, and also evaluates the priority
8628 -- expression if needed. The initialization routine for the protected type
8629 -- itself then calls Initialize_Protection with appropriate parameters to
8630 -- initialize the value of the Task_Id field. Install_Handlers may be also
8631 -- called if a pragma Attach_Handler applies.
8633 -- Note: this record is passed to the subprograms created by the expansion
8634 -- of protected subprograms and entries. It is an in parameter to protected
8635 -- functions and an in out parameter to procedures and entry bodies. The
8636 -- Entity_Id for this created record type is placed in the
8637 -- Corresponding_Record_Type field of the associated protected type entity.
8639 -- Next we create a procedure specifications for protected subprograms and
8640 -- entry bodies. For each protected subprograms two subprograms are
8641 -- created, an unprotected and a protected version. The unprotected version
8642 -- is called from within other operations of the same protected object.
8644 -- We also build the call to register the procedure if a pragma
8645 -- Interrupt_Handler applies.
8647 -- A single subprogram is created to service all entry bodies; it has an
8648 -- additional boolean out parameter indicating that the previous entry call
8649 -- made by the current task was serviced immediately, i.e. not by proxy.
8650 -- The O parameter contains a pointer to a record object of the type
8651 -- described above. An untyped interface is used here to allow this
8652 -- procedure to be called in places where the type of the object to be
8653 -- serviced is not known. This must be done, for example, when a call that
8654 -- may have been requeued is cancelled; the corresponding object must be
8655 -- serviced, but which object that is not known till runtime.
8658 -- (O : System.Address; P : out Boolean);
8659 -- procedure pprocN (_object : in out poV);
8660 -- procedure pproc (_object : in out poV);
8661 -- function pfuncN (_object : poV);
8662 -- function pfunc (_object : poV);
8665 -- Note that this must come after the record type declaration, since
8666 -- the specs refer to this type.
8668 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
8669 Discr_Map : constant Elist_Id := New_Elmt_List;
8670 Loc : constant Source_Ptr := Sloc (N);
8671 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
8673 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Prot_Typ);
8674 -- This flag indicates whether the lock free implementation is active
8676 Pdef : constant Node_Id := Protected_Definition (N);
8677 -- This contains two lists; one for visible and one for private decls
8679 Current_Node : Node_Id := N;
8681 Entries_Aggr : Node_Id;
8683 procedure Check_Inlining (Subp : Entity_Id);
8684 -- If the original operation has a pragma Inline, propagate the flag
8685 -- to the internal body, for possible inlining later on. The source
8686 -- operation is invisible to the back-end and is never actually called.
8688 function Discriminated_Size (Comp : Entity_Id) return Boolean;
8689 -- If a component size is not static then a warning will be emitted
8690 -- in Ravenscar or other restricted contexts. When a component is non-
8691 -- static because of a discriminant constraint we can specialize the
8692 -- warning by mentioning discriminants explicitly.
8694 procedure Expand_Entry_Declaration (Decl : Node_Id);
8695 -- Create the entry barrier and the procedure body for entry declaration
8696 -- Decl. All generated subprograms are added to Entry_Bodies_Array.
8698 function Static_Component_Size (Comp : Entity_Id) return Boolean;
8699 -- When compiling under the Ravenscar profile, private components must
8700 -- have a static size, or else a protected object will require heap
8701 -- allocation, violating the corresponding restriction. It is preferable
8702 -- to make this check here, because it provides a better error message
8703 -- than the back-end, which refers to the object as a whole.
8705 procedure Register_Handler;
8706 -- For a protected operation that is an interrupt handler, add the
8707 -- freeze action that will register it as such.
8709 --------------------
8710 -- Check_Inlining --
8711 --------------------
8713 procedure Check_Inlining (Subp : Entity_Id) is
8715 if Is_Inlined (Subp) then
8716 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8717 Set_Is_Inlined (Subp, False);
8721 ------------------------
8722 -- Discriminated_Size --
8723 ------------------------
8725 function Discriminated_Size (Comp : Entity_Id) return Boolean is
8726 Typ : constant Entity_Id := Etype (Comp);
8729 function Non_Static_Bound (Bound : Node_Id) return Boolean;
8730 -- Check whether the bound of an index is non-static and does denote
8731 -- a discriminant, in which case any protected object of the type
8732 -- will have a non-static size.
8734 ----------------------
8735 -- Non_Static_Bound --
8736 ----------------------
8738 function Non_Static_Bound (Bound : Node_Id) return Boolean is
8740 if Is_OK_Static_Expression (Bound) then
8743 elsif Is_Entity_Name (Bound)
8744 and then Present (Discriminal_Link (Entity (Bound)))
8751 end Non_Static_Bound;
8753 -- Start of processing for Discriminated_Size
8756 if not Is_Array_Type (Typ) then
8760 if Ekind (Typ) = E_Array_Subtype then
8761 Index := First_Index (Typ);
8762 while Present (Index) loop
8763 if Non_Static_Bound (Low_Bound (Index))
8764 or else Non_Static_Bound (High_Bound (Index))
8776 end Discriminated_Size;
8778 ---------------------------
8779 -- Static_Component_Size --
8780 ---------------------------
8782 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8783 Typ : constant Entity_Id := Etype (Comp);
8787 if Is_Scalar_Type (Typ) then
8790 elsif Is_Array_Type (Typ) then
8791 return Compile_Time_Known_Bounds (Typ);
8793 elsif Is_Record_Type (Typ) then
8794 C := First_Component (Typ);
8795 while Present (C) loop
8796 if not Static_Component_Size (C) then
8805 -- Any other type will be checked by the back-end
8810 end Static_Component_Size;
8812 ------------------------------
8813 -- Expand_Entry_Declaration --
8814 ------------------------------
8816 procedure Expand_Entry_Declaration (Decl : Node_Id) is
8817 Ent_Id : constant Entity_Id := Defining_Entity (Decl);
8823 E_Count := E_Count + 1;
8825 -- Create the protected body subprogram
8828 Make_Defining_Identifier (Loc,
8829 Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'E'));
8830 Set_Protected_Body_Subprogram (Ent_Id, Bod_Id);
8833 Make_Subprogram_Declaration (Loc,
8835 Build_Protected_Entry_Specification (Loc, Bod_Id, Ent_Id));
8837 Insert_After (Current_Node, Subp);
8838 Current_Node := Subp;
8842 -- Build a wrapper procedure to handle contract cases, preconditions,
8843 -- and postconditions.
8845 Build_Contract_Wrapper (Ent_Id, N);
8847 -- Create the barrier function
8850 Make_Defining_Identifier (Loc,
8851 Chars => Build_Selected_Name (Prot_Typ, Ent_Id, 'B'));
8852 Set_Barrier_Function (Ent_Id, Bar_Id);
8855 Make_Subprogram_Declaration (Loc,
8857 Build_Barrier_Function_Specification (Loc, Bar_Id));
8858 Set_Is_Entry_Barrier_Function (Subp);
8860 Insert_After (Current_Node, Subp);
8861 Current_Node := Subp;
8865 Set_Protected_Body_Subprogram (Bar_Id, Bar_Id);
8866 Set_Scope (Bar_Id, Scope (Ent_Id));
8868 -- Collect pointers to the protected subprogram and the barrier
8869 -- of the current entry, for insertion into Entry_Bodies_Array.
8871 Append_To (Expressions (Entries_Aggr),
8872 Make_Aggregate (Loc,
8873 Expressions => New_List (
8874 Make_Attribute_Reference (Loc,
8875 Prefix => New_Occurrence_Of (Bar_Id, Loc),
8876 Attribute_Name => Name_Unrestricted_Access),
8877 Make_Attribute_Reference (Loc,
8878 Prefix => New_Occurrence_Of (Bod_Id, Loc),
8879 Attribute_Name => Name_Unrestricted_Access))));
8880 end Expand_Entry_Declaration;
8882 ----------------------
8883 -- Register_Handler --
8884 ----------------------
8886 procedure Register_Handler is
8888 -- All semantic checks already done in Sem_Prag
8890 Prot_Proc : constant Entity_Id :=
8891 Defining_Unit_Name (Specification (Current_Node));
8893 Proc_Address : constant Node_Id :=
8894 Make_Attribute_Reference (Loc,
8896 New_Occurrence_Of (Prot_Proc, Loc),
8897 Attribute_Name => Name_Address);
8899 RTS_Call : constant Entity_Id :=
8900 Make_Procedure_Call_Statement (Loc,
8903 (RTE (RE_Register_Interrupt_Handler), Loc),
8904 Parameter_Associations => New_List (Proc_Address));
8906 Append_Freeze_Action (Prot_Proc, RTS_Call);
8907 end Register_Handler;
8912 Body_Id : Entity_Id;
8918 Object_Comp : Node_Id;
8923 -- Start of processing for Expand_N_Protected_Type_Declaration
8926 if Present (Corresponding_Record_Type (Prot_Typ)) then
8929 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
8932 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
8934 Qualify_Entity_Names (N);
8936 -- If the type has discriminants, their occurrences in the declaration
8937 -- have been replaced by the corresponding discriminals. For components
8938 -- that are constrained by discriminants, their homologues in the
8939 -- corresponding record type must refer to the discriminants of that
8940 -- record, so we must apply a new renaming to subtypes_indications:
8942 -- protected discriminant => discriminal => record discriminant
8944 -- This replacement is not applied to default expressions, for which
8945 -- the discriminal is correct.
8947 if Has_Discriminants (Prot_Typ) then
8953 Disc := First_Discriminant (Prot_Typ);
8954 Decl := First (Discriminant_Specifications (Rec_Decl));
8955 while Present (Disc) loop
8956 Append_Elmt (Discriminal (Disc), Discr_Map);
8957 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
8958 Next_Discriminant (Disc);
8964 -- Fill in the component declarations
8966 -- Add components for entry families. For each entry family, create an
8967 -- anonymous type declaration with the same size, and analyze the type.
8969 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
8971 pragma Assert (Present (Pdef));
8973 Insert_After (Current_Node, Rec_Decl);
8974 Current_Node := Rec_Decl;
8976 -- Add private field components
8978 if Present (Private_Declarations (Pdef)) then
8979 Priv := First (Private_Declarations (Pdef));
8980 while Present (Priv) loop
8981 if Nkind (Priv) = N_Component_Declaration then
8982 if not Static_Component_Size (Defining_Identifier (Priv)) then
8984 -- When compiling for a restricted profile, the private
8985 -- components must have a static size. If not, this is an
8986 -- error for a single protected declaration, and rates a
8987 -- warning on a protected type declaration.
8989 if not Comes_From_Source (Prot_Typ) then
8991 -- It's ok to be checking this restriction at expansion
8992 -- time, because this is only for the restricted profile,
8993 -- which is not subject to strict RM conformance, so it
8994 -- is OK to miss this check in -gnatc mode.
8996 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
8998 (No_Implicit_Protected_Object_Allocations, Priv);
9000 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
9001 if not Discriminated_Size (Defining_Identifier (Priv))
9003 -- Any object of the type will be non-static.
9005 Error_Msg_N ("component has non-static size??", Priv);
9007 ("\creation of protected object of type& will "
9008 & "violate restriction "
9009 & "No_Implicit_Heap_Allocations??", Priv, Prot_Typ);
9012 -- Object will be non-static if discriminants are.
9015 ("creation of protected object of type& with "
9016 & "non-static discriminants will violate"
9017 & " restriction No_Implicit_Heap_Allocations??",
9021 -- Likewise for No_Implicit_Protected_Object_Allocations
9023 elsif Restriction_Active
9024 (No_Implicit_Protected_Object_Allocations)
9026 if not Discriminated_Size (Defining_Identifier (Priv))
9028 -- Any object of the type will be non-static.
9030 Error_Msg_N ("component has non-static size??", Priv);
9032 ("\creation of protected object of type& will "
9033 & "violate restriction "
9034 & "No_Implicit_Protected_Object_Allocations??",
9037 -- Object will be non-static if discriminants are.
9040 ("creation of protected object of type& with "
9041 & "non-static discriminants will violate "
9043 & "No_Implicit_Protected_Object_Allocations??",
9049 -- The component definition consists of a subtype indication,
9050 -- or (in Ada 2005) an access definition. Make a copy of the
9051 -- proper definition.
9054 Old_Comp : constant Node_Id := Component_Definition (Priv);
9055 Oent : constant Entity_Id := Defining_Identifier (Priv);
9056 Nent : constant Entity_Id :=
9057 Make_Defining_Identifier (Sloc (Oent),
9058 Chars => Chars (Oent));
9062 if Present (Subtype_Indication (Old_Comp)) then
9064 Make_Component_Definition (Sloc (Oent),
9065 Aliased_Present => False,
9066 Subtype_Indication =>
9068 (Subtype_Indication (Old_Comp), Discr_Map));
9071 Make_Component_Definition (Sloc (Oent),
9072 Aliased_Present => False,
9073 Access_Definition =>
9075 (Access_Definition (Old_Comp), Discr_Map));
9079 Make_Component_Declaration (Loc,
9080 Defining_Identifier => Nent,
9081 Component_Definition => New_Comp,
9082 Expression => Expression (Priv));
9084 Set_Has_Per_Object_Constraint (Nent,
9085 Has_Per_Object_Constraint (Oent));
9087 Append_To (Cdecls, New_Priv);
9090 elsif Nkind (Priv) = N_Subprogram_Declaration then
9092 -- Make the unprotected version of the subprogram available
9093 -- for expansion of intra object calls. There is need for
9094 -- a protected version only if the subprogram is an interrupt
9095 -- handler, otherwise this operation can only be called from
9099 Make_Subprogram_Declaration (Loc,
9101 Build_Protected_Sub_Specification
9102 (Priv, Prot_Typ, Unprotected_Mode));
9104 Insert_After (Current_Node, Sub);
9107 Set_Protected_Body_Subprogram
9108 (Defining_Unit_Name (Specification (Priv)),
9109 Defining_Unit_Name (Specification (Sub)));
9110 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
9111 Current_Node := Sub;
9114 Make_Subprogram_Declaration (Loc,
9116 Build_Protected_Sub_Specification
9117 (Priv, Prot_Typ, Protected_Mode));
9119 Insert_After (Current_Node, Sub);
9121 Current_Node := Sub;
9123 if Is_Interrupt_Handler
9124 (Defining_Unit_Name (Specification (Priv)))
9126 if not Restricted_Profile then
9136 -- Except for the lock-free implementation, append the _Object field
9137 -- with the right type to the component list. We need to compute the
9138 -- number of entries, and in some cases the number of Attach_Handler
9141 if not Lock_Free_Active then
9143 Entry_Count_Expr : constant Node_Id :=
9144 Build_Entry_Count_Expression
9145 (Prot_Typ, Cdecls, Loc);
9146 Num_Attach_Handler : Nat := 0;
9147 Protection_Subtype : Node_Id;
9151 if Has_Attach_Handler (Prot_Typ) then
9152 Ritem := First_Rep_Item (Prot_Typ);
9153 while Present (Ritem) loop
9154 if Nkind (Ritem) = N_Pragma
9155 and then Pragma_Name (Ritem) = Name_Attach_Handler
9157 Num_Attach_Handler := Num_Attach_Handler + 1;
9160 Next_Rep_Item (Ritem);
9164 -- Determine the proper protection type. There are two special
9165 -- cases: 1) when the protected type has dynamic interrupt
9166 -- handlers, and 2) when it has static handlers and we use a
9167 -- restricted profile.
9169 if Has_Attach_Handler (Prot_Typ)
9170 and then not Restricted_Profile
9172 Protection_Subtype :=
9173 Make_Subtype_Indication (Loc,
9176 (RTE (RE_Static_Interrupt_Protection), Loc),
9178 Make_Index_Or_Discriminant_Constraint (Loc,
9179 Constraints => New_List (
9181 Make_Integer_Literal (Loc, Num_Attach_Handler))));
9183 elsif Has_Interrupt_Handler (Prot_Typ)
9184 and then not Restriction_Active (No_Dynamic_Attachment)
9186 Protection_Subtype :=
9187 Make_Subtype_Indication (Loc,
9190 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
9192 Make_Index_Or_Discriminant_Constraint (Loc,
9193 Constraints => New_List (Entry_Count_Expr)));
9196 case Corresponding_Runtime_Package (Prot_Typ) is
9197 when System_Tasking_Protected_Objects_Entries =>
9198 Protection_Subtype :=
9199 Make_Subtype_Indication (Loc,
9202 (RTE (RE_Protection_Entries), Loc),
9204 Make_Index_Or_Discriminant_Constraint (Loc,
9205 Constraints => New_List (Entry_Count_Expr)));
9207 when System_Tasking_Protected_Objects_Single_Entry =>
9208 Protection_Subtype :=
9209 New_Occurrence_Of (RTE (RE_Protection_Entry), Loc);
9211 when System_Tasking_Protected_Objects =>
9212 Protection_Subtype :=
9213 New_Occurrence_Of (RTE (RE_Protection), Loc);
9216 raise Program_Error;
9221 Make_Component_Declaration (Loc,
9222 Defining_Identifier =>
9223 Make_Defining_Identifier (Loc, Name_uObject),
9224 Component_Definition =>
9225 Make_Component_Definition (Loc,
9226 Aliased_Present => True,
9227 Subtype_Indication => Protection_Subtype));
9230 -- Put the _Object component after the private component so that it
9231 -- be finalized early as required by 9.4 (20)
9233 Append_To (Cdecls, Object_Comp);
9236 -- Analyze the record declaration immediately after construction,
9237 -- because the initialization procedure is needed for single object
9238 -- declarations before the next entity is analyzed (the freeze call
9239 -- that generates this initialization procedure is found below).
9241 Analyze (Rec_Decl, Suppress => All_Checks);
9243 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9244 -- the corresponding record is frozen. If any wrappers are generated,
9245 -- Current_Node is updated accordingly.
9247 if Ada_Version >= Ada_2005 then
9248 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
9251 -- Collect pointers to entry bodies and their barriers, to be placed
9252 -- in the Entry_Bodies_Array for the type. For each entry/family we
9253 -- add an expression to the aggregate which is the initial value of
9254 -- this array. The array is declared after all protected subprograms.
9256 if Has_Entries (Prot_Typ) then
9257 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
9259 Entries_Aggr := Empty;
9262 -- Build two new procedure specifications for each protected subprogram;
9263 -- one to call from outside the object and one to call from inside.
9264 -- Build a barrier function and an entry body action procedure
9265 -- specification for each protected entry. Initialize the entry body
9266 -- array. If subprogram is flagged as eliminated, do not generate any
9267 -- internal operations.
9270 Comp := First (Visible_Declarations (Pdef));
9271 while Present (Comp) loop
9272 if Nkind (Comp) = N_Subprogram_Declaration then
9274 Make_Subprogram_Declaration (Loc,
9276 Build_Protected_Sub_Specification
9277 (Comp, Prot_Typ, Unprotected_Mode));
9279 Insert_After (Current_Node, Sub);
9282 Set_Protected_Body_Subprogram
9283 (Defining_Unit_Name (Specification (Comp)),
9284 Defining_Unit_Name (Specification (Sub)));
9285 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
9287 -- Make the protected version of the subprogram available for
9288 -- expansion of external calls.
9290 Current_Node := Sub;
9293 Make_Subprogram_Declaration (Loc,
9295 Build_Protected_Sub_Specification
9296 (Comp, Prot_Typ, Protected_Mode));
9298 Insert_After (Current_Node, Sub);
9301 Current_Node := Sub;
9303 -- Generate an overriding primitive operation specification for
9304 -- this subprogram if the protected type implements an interface
9305 -- and Build_Wrapper_Spec did not generate its wrapper.
9307 if Ada_Version >= Ada_2005
9309 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
9312 Found : Boolean := False;
9313 Prim_Elmt : Elmt_Id;
9319 (Primitive_Operations
9320 (Corresponding_Record_Type (Prot_Typ)));
9322 while Present (Prim_Elmt) loop
9323 Prim_Op := Node (Prim_Elmt);
9325 if Is_Primitive_Wrapper (Prim_Op)
9326 and then Wrapped_Entity (Prim_Op) =
9327 Defining_Entity (Specification (Comp))
9333 Next_Elmt (Prim_Elmt);
9338 Make_Subprogram_Declaration (Loc,
9340 Build_Protected_Sub_Specification
9341 (Comp, Prot_Typ, Dispatching_Mode));
9343 Insert_After (Current_Node, Sub);
9346 Current_Node := Sub;
9351 -- If a pragma Interrupt_Handler applies, build and add a call to
9352 -- Register_Interrupt_Handler to the freezing actions of the
9353 -- protected version (Current_Node) of the subprogram:
9355 -- system.interrupts.register_interrupt_handler
9356 -- (prot_procP'address);
9358 if not Restricted_Profile
9359 and then Is_Interrupt_Handler
9360 (Defining_Unit_Name (Specification (Comp)))
9365 elsif Nkind (Comp) = N_Entry_Declaration then
9366 Expand_Entry_Declaration (Comp);
9372 -- If there are some private entry declarations, expand it as if they
9373 -- were visible entries.
9375 if Present (Private_Declarations (Pdef)) then
9376 Comp := First (Private_Declarations (Pdef));
9377 while Present (Comp) loop
9378 if Nkind (Comp) = N_Entry_Declaration then
9379 Expand_Entry_Declaration (Comp);
9386 -- Create the declaration of an array object which contains the values
9387 -- of aspect/pragma Max_Queue_Length for all entries of the protected
9388 -- type. This object is later passed to the appropriate protected object
9389 -- initialization routine.
9391 if Has_Entries (Prot_Typ)
9392 and then Corresponding_Runtime_Package (Prot_Typ) =
9393 System_Tasking_Protected_Objects_Entries
9400 Maxes_Id : Entity_Id;
9401 Need_Array : Boolean := False;
9404 -- First check if there is any Max_Queue_Length pragma
9406 Item := First_Entity (Prot_Typ);
9407 while Present (Item) loop
9408 if Is_Entry (Item) and then Has_Max_Queue_Length (Item) then
9416 -- Gather the Max_Queue_Length values of all entries in a list. A
9417 -- value of zero indicates that the entry has no limitation on its
9422 Item := First_Entity (Prot_Typ);
9424 while Present (Item) loop
9425 if Is_Entry (Item) then
9428 Make_Integer_Literal
9429 (Loc, Get_Max_Queue_Length (Item)));
9435 -- Create the declaration of the array object. Generate:
9437 -- Maxes_Id : aliased constant
9438 -- Protected_Entry_Queue_Max_Array
9439 -- (1 .. Count) := (..., ...);
9442 Make_Defining_Identifier (Loc,
9443 Chars => New_External_Name (Chars (Prot_Typ), 'B'));
9446 Make_Object_Declaration (Loc,
9447 Defining_Identifier => Maxes_Id,
9448 Aliased_Present => True,
9449 Constant_Present => True,
9450 Object_Definition =>
9451 Make_Subtype_Indication (Loc,
9454 (RTE (RE_Protected_Entry_Queue_Max_Array), Loc),
9456 Make_Index_Or_Discriminant_Constraint (Loc,
9457 Constraints => New_List (
9459 Make_Integer_Literal (Loc, 1),
9460 Make_Integer_Literal (Loc, Count))))),
9461 Expression => Make_Aggregate (Loc, Maxes));
9463 -- A pointer to this array will be placed in the corresponding
9464 -- record by its initialization procedure so this needs to be
9467 Insert_After (Current_Node, Max_Vals);
9468 Current_Node := Max_Vals;
9471 Set_Entry_Max_Queue_Lengths_Array (Prot_Typ, Maxes_Id);
9476 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9477 -- all protected subprograms have been collected.
9479 if Has_Entries (Prot_Typ) then
9481 Make_Defining_Identifier (Sloc (Prot_Typ),
9482 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
9484 case Corresponding_Runtime_Package (Prot_Typ) is
9485 when System_Tasking_Protected_Objects_Entries =>
9486 Expr := Entries_Aggr;
9488 Make_Subtype_Indication (Loc,
9491 (RTE (RE_Protected_Entry_Body_Array), Loc),
9493 Make_Index_Or_Discriminant_Constraint (Loc,
9494 Constraints => New_List (
9496 Make_Integer_Literal (Loc, 1),
9497 Make_Integer_Literal (Loc, E_Count)))));
9499 when System_Tasking_Protected_Objects_Single_Entry =>
9500 Expr := Remove_Head (Expressions (Entries_Aggr));
9501 Obj_Def := New_Occurrence_Of (RTE (RE_Entry_Body), Loc);
9504 raise Program_Error;
9508 Make_Object_Declaration (Loc,
9509 Defining_Identifier => Body_Id,
9510 Aliased_Present => True,
9511 Constant_Present => True,
9512 Object_Definition => Obj_Def,
9513 Expression => Expr);
9515 -- A pointer to this array will be placed in the corresponding record
9516 -- by its initialization procedure so this needs to be analyzed here.
9518 Insert_After (Current_Node, Body_Arr);
9519 Current_Node := Body_Arr;
9522 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
9524 -- Finally, build the function that maps an entry index into the
9525 -- corresponding body. A pointer to this function is placed in each
9526 -- object of the type. Except for a ravenscar-like profile (no abort,
9527 -- no entry queue, 1 entry)
9529 if Corresponding_Runtime_Package (Prot_Typ) =
9530 System_Tasking_Protected_Objects_Entries
9533 Make_Subprogram_Declaration (Loc,
9534 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
9536 Insert_After (Current_Node, Sub);
9540 end Expand_N_Protected_Type_Declaration;
9542 --------------------------------
9543 -- Expand_N_Requeue_Statement --
9544 --------------------------------
9546 -- A nondispatching requeue statement is expanded into one of four GNARLI
9547 -- operations, depending on the source and destination (task or protected
9548 -- object). A dispatching requeue statement is expanded into a call to the
9549 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9550 -- jump around the remainder of processing for the original entry and, if
9551 -- the destination is (different) protected object, to attempt to service
9552 -- it. The following illustrates the various cases:
9555 -- (O : System.Address;
9556 -- P : System.Address;
9557 -- E : Protected_Entry_Index)
9559 -- <discriminant renamings>
9560 -- <private object renamings>
9561 -- type poVP is access poV;
9562 -- _object : ptVP := ptVP!(O);
9566 -- <start of statement sequence for entry>
9568 -- -- Requeue from one protected entry body to another protected
9571 -- Requeue_Protected_Entry (
9572 -- _object._object'Access,
9573 -- new._object'Access,
9578 -- <some more of the statement sequence for entry>
9580 -- -- Requeue from an entry body to a task entry
9582 -- Requeue_Protected_To_Task_Entry (
9588 -- <rest of statement sequence for entry>
9589 -- Complete_Entry_Body (_object._object);
9592 -- when all others =>
9593 -- Exceptional_Complete_Entry_Body (
9594 -- _object._object, Get_GNAT_Exception);
9598 -- Requeue of a task entry call to a task entry
9600 -- Accept_Call (E, Ann);
9601 -- <start of statement sequence for accept statement>
9602 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9604 -- <rest of statement sequence for accept statement>
9606 -- Complete_Rendezvous;
9609 -- when all others =>
9610 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9612 -- Requeue of a task entry call to a protected entry
9614 -- Accept_Call (E, Ann);
9615 -- <start of statement sequence for accept statement>
9616 -- Requeue_Task_To_Protected_Entry (
9617 -- new._object'Access,
9622 -- <rest of statement sequence for accept statement>
9624 -- Complete_Rendezvous;
9627 -- when all others =>
9628 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9630 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9631 -- marked by pragma Implemented (XXX, By_Entry).
9633 -- The requeue is inside a protected entry:
9636 -- (O : System.Address;
9637 -- P : System.Address;
9638 -- E : Protected_Entry_Index)
9640 -- <discriminant renamings>
9641 -- <private object renamings>
9642 -- type poVP is access poV;
9643 -- _object : ptVP := ptVP!(O);
9647 -- <start of statement sequence for entry>
9650 -- (<interface class-wide object>,
9653 -- Ada.Tags.Get_Offset_Index
9655 -- <interface dispatch table index of target entry>),
9659 -- <rest of statement sequence for entry>
9660 -- Complete_Entry_Body (_object._object);
9663 -- when all others =>
9664 -- Exceptional_Complete_Entry_Body (
9665 -- _object._object, Get_GNAT_Exception);
9669 -- The requeue is inside a task entry:
9671 -- Accept_Call (E, Ann);
9672 -- <start of statement sequence for accept statement>
9674 -- (<interface class-wide object>,
9677 -- Ada.Tags.Get_Offset_Index
9679 -- <interface dispatch table index of target entrt>),
9683 -- <rest of statement sequence for accept statement>
9685 -- Complete_Rendezvous;
9688 -- when all others =>
9689 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9691 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9692 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9693 -- statement is replaced by a dispatching call with actual parameters taken
9694 -- from the inner-most accept statement or entry body.
9696 -- Target.Primitive (Param1, ..., ParamN);
9698 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9699 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9703 -- S : constant Offset_Index :=
9704 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9705 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9708 -- if C = POK_Protected_Entry
9709 -- or else C = POK_Task_Entry
9711 -- <statements for dispatching requeue>
9713 -- elsif C = POK_Protected_Procedure then
9714 -- <dispatching call equivalent>
9717 -- raise Program_Error;
9721 procedure Expand_N_Requeue_Statement (N : Node_Id) is
9722 Loc : constant Source_Ptr := Sloc (N);
9723 Conc_Typ : Entity_Id;
9727 Old_Typ : Entity_Id;
9729 function Build_Dispatching_Call_Equivalent return Node_Id;
9730 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9731 -- the form Concval.Ename. It is statically known that Ename is allowed
9732 -- to be implemented by a protected procedure. Create a dispatching call
9733 -- equivalent of Concval.Ename taking the actual parameters from the
9734 -- inner-most accept statement or entry body.
9736 function Build_Dispatching_Requeue return Node_Id;
9737 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9738 -- the form Concval.Ename. It is statically known that Ename is allowed
9739 -- to be implemented by a protected or a task entry. Create a call to
9740 -- primitive _Disp_Requeue which handles the low-level actions.
9742 function Build_Dispatching_Requeue_To_Any return Node_Id;
9743 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9744 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9745 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9746 -- determines at runtime whether Ename denotes an entry or a procedure
9747 -- and perform the appropriate kind of dispatching select.
9749 function Build_Normal_Requeue return Node_Id;
9750 -- N denotes a nondispatching requeue statement to either a task or a
9751 -- protected entry. Build the appropriate runtime call to perform the
9754 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
9755 -- For a protected entry, create a return statement to skip the rest of
9756 -- the entry body. Otherwise, create a goto statement to skip the rest
9757 -- of a task accept statement. The lookup for the enclosing entry body
9758 -- or accept statement starts from Search.
9760 ---------------------------------------
9761 -- Build_Dispatching_Call_Equivalent --
9762 ---------------------------------------
9764 function Build_Dispatching_Call_Equivalent return Node_Id is
9765 Call_Ent : constant Entity_Id := Entity (Ename);
9766 Obj : constant Node_Id := Original_Node (Concval);
9773 -- Climb the parent chain looking for the inner-most entry body or
9774 -- accept statement.
9777 while Present (Acc_Ent)
9778 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
9781 Acc_Ent := Parent (Acc_Ent);
9784 -- A requeue statement should be housed inside an entry body or an
9785 -- accept statement at some level. If this is not the case, then the
9786 -- tree is malformed.
9788 pragma Assert (Present (Acc_Ent));
9790 -- Recover the list of formal parameters
9792 if Nkind (Acc_Ent) = N_Entry_Body then
9793 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
9796 Formals := Parameter_Specifications (Acc_Ent);
9798 -- Create the actual parameters for the dispatching call. These are
9799 -- simply copies of the entry body or accept statement formals in the
9800 -- same order as they appear.
9804 if Present (Formals) then
9805 Actuals := New_List;
9806 Formal := First (Formals);
9807 while Present (Formal) loop
9809 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
9815 -- Obj.Call_Ent (Actuals);
9818 Make_Procedure_Call_Statement (Loc,
9820 Make_Selected_Component (Loc,
9821 Prefix => Make_Identifier (Loc, Chars (Obj)),
9822 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
9824 Parameter_Associations => Actuals);
9825 end Build_Dispatching_Call_Equivalent;
9827 -------------------------------
9828 -- Build_Dispatching_Requeue --
9829 -------------------------------
9831 function Build_Dispatching_Requeue return Node_Id is
9832 Params : constant List_Id := New_List;
9835 -- Process the "with abort" parameter
9838 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
9840 -- Process the entry wrapper's position in the primary dispatch
9841 -- table parameter. Generate:
9843 -- Ada.Tags.Get_Entry_Index
9844 -- (T => To_Tag_Ptr (Obj'Address).all,
9846 -- Ada.Tags.Get_Offset_Index
9847 -- (Ada.Tags.Tag (Concval),
9848 -- <interface dispatch table position of Ename>));
9850 -- Note that Obj'Address is recursively expanded into a call to
9851 -- Base_Address (Obj).
9853 if Tagged_Type_Expansion then
9855 Make_Function_Call (Loc,
9856 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9857 Parameter_Associations => New_List (
9859 Make_Explicit_Dereference (Loc,
9860 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
9861 Make_Attribute_Reference (Loc,
9862 Prefix => New_Copy_Tree (Concval),
9863 Attribute_Name => Name_Address))),
9865 Make_Function_Call (Loc,
9866 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9867 Parameter_Associations => New_List (
9868 Unchecked_Convert_To (RTE (RE_Tag), Concval),
9869 Make_Integer_Literal (Loc,
9870 DT_Position (Entity (Ename))))))));
9876 Make_Function_Call (Loc,
9877 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9878 Parameter_Associations => New_List (
9880 Make_Attribute_Reference (Loc,
9882 Attribute_Name => Name_Tag),
9884 Make_Function_Call (Loc,
9885 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9887 Parameter_Associations => New_List (
9891 Make_Attribute_Reference (Loc,
9893 Attribute_Name => Name_Tag),
9897 Make_Attribute_Reference (Loc,
9898 Prefix => New_Occurrence_Of (Etype (Concval), Loc),
9899 Attribute_Name => Name_Tag),
9903 Make_Integer_Literal (Loc,
9904 DT_Position (Entity (Ename))))))));
9907 -- Specific actuals for protected to XXX requeue
9909 if Is_Protected_Type (Old_Typ) then
9911 Make_Attribute_Reference (Loc, -- _object'Address
9913 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9914 Attribute_Name => Name_Address));
9916 Prepend_To (Params, -- True
9917 New_Occurrence_Of (Standard_True, Loc));
9919 -- Specific actuals for task to XXX requeue
9922 pragma Assert (Is_Task_Type (Old_Typ));
9924 Prepend_To (Params, -- null
9925 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
9927 Prepend_To (Params, -- False
9928 New_Occurrence_Of (Standard_False, Loc));
9931 -- Add the object parameter
9933 Prepend_To (Params, New_Copy_Tree (Concval));
9936 -- _Disp_Requeue (<Params>);
9938 -- Find entity for Disp_Requeue operation, which belongs to
9939 -- the type and may not be directly visible.
9946 Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
9947 while Present (Elmt) loop
9949 exit when Chars (Op) = Name_uDisp_Requeue;
9954 Make_Procedure_Call_Statement (Loc,
9955 Name => New_Occurrence_Of (Op, Loc),
9956 Parameter_Associations => Params);
9958 end Build_Dispatching_Requeue;
9960 --------------------------------------
9961 -- Build_Dispatching_Requeue_To_Any --
9962 --------------------------------------
9964 function Build_Dispatching_Requeue_To_Any return Node_Id is
9965 Call_Ent : constant Entity_Id := Entity (Ename);
9966 Obj : constant Node_Id := Original_Node (Concval);
9967 Skip : constant Node_Id := Build_Skip_Statement (N);
9977 -- Dispatch table slot processing, generate:
9980 S := Build_S (Loc, Decls);
9982 -- Call kind processing, generate:
9983 -- C : Ada.Tags.Prim_Op_Kind;
9985 C := Build_C (Loc, Decls);
9988 -- S := Ada.Tags.Get_Offset_Index
9989 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
9991 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
9994 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
9997 Make_Procedure_Call_Statement (Loc,
10000 Find_Prim_Op (Etype (Etype (Obj)),
10001 Name_uDisp_Get_Prim_Op_Kind),
10003 Parameter_Associations => New_List (
10004 New_Copy_Tree (Obj),
10005 New_Occurrence_Of (S, Loc),
10006 New_Occurrence_Of (C, Loc))));
10010 -- if C = POK_Protected_Entry
10011 -- or else C = POK_Task_Entry
10014 Make_Implicit_If_Statement (N,
10020 New_Occurrence_Of (C, Loc),
10022 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
10027 New_Occurrence_Of (C, Loc),
10029 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
10031 -- Dispatching requeue equivalent
10033 Then_Statements => New_List (
10034 Build_Dispatching_Requeue,
10037 -- elsif C = POK_Protected_Procedure then
10039 Elsif_Parts => New_List (
10040 Make_Elsif_Part (Loc,
10044 New_Occurrence_Of (C, Loc),
10046 New_Occurrence_Of (
10047 RTE (RE_POK_Protected_Procedure), Loc)),
10049 -- Dispatching call equivalent
10051 Then_Statements => New_List (
10052 Build_Dispatching_Call_Equivalent))),
10055 -- raise Program_Error;
10058 Else_Statements => New_List (
10059 Make_Raise_Program_Error (Loc,
10060 Reason => PE_Explicit_Raise))));
10062 -- Wrap everything into a block
10065 Make_Block_Statement (Loc,
10066 Declarations => Decls,
10067 Handled_Statement_Sequence =>
10068 Make_Handled_Sequence_Of_Statements (Loc,
10069 Statements => Stmts));
10070 end Build_Dispatching_Requeue_To_Any;
10072 --------------------------
10073 -- Build_Normal_Requeue --
10074 --------------------------
10076 function Build_Normal_Requeue return Node_Id is
10077 Params : constant List_Id := New_List;
10082 -- Process the "with abort" parameter
10084 Prepend_To (Params,
10085 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
10087 -- Add the index expression to the parameters. It is common among all
10090 Prepend_To (Params,
10091 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
10093 if Is_Protected_Type (Old_Typ) then
10095 Self_Param : Node_Id;
10099 Make_Attribute_Reference (Loc,
10101 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
10103 Name_Unchecked_Access);
10105 -- Protected to protected requeue
10107 if Is_Protected_Type (Conc_Typ) then
10109 New_Occurrence_Of (
10110 RTE (RE_Requeue_Protected_Entry), Loc);
10113 Make_Attribute_Reference (Loc,
10115 Concurrent_Ref (Concval),
10117 Name_Unchecked_Access);
10119 -- Protected to task requeue
10121 else pragma Assert (Is_Task_Type (Conc_Typ));
10123 New_Occurrence_Of (
10124 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
10126 Param := Concurrent_Ref (Concval);
10129 Prepend_To (Params, Param);
10130 Prepend_To (Params, Self_Param);
10133 else pragma Assert (Is_Task_Type (Old_Typ));
10135 -- Task to protected requeue
10137 if Is_Protected_Type (Conc_Typ) then
10139 New_Occurrence_Of (
10140 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
10143 Make_Attribute_Reference (Loc,
10145 Concurrent_Ref (Concval),
10147 Name_Unchecked_Access);
10149 -- Task to task requeue
10151 else pragma Assert (Is_Task_Type (Conc_Typ));
10153 New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc);
10155 Param := Concurrent_Ref (Concval);
10158 Prepend_To (Params, Param);
10162 Make_Procedure_Call_Statement (Loc,
10164 Parameter_Associations => Params);
10165 end Build_Normal_Requeue;
10167 --------------------------
10168 -- Build_Skip_Statement --
10169 --------------------------
10171 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
10172 Skip_Stmt : Node_Id;
10175 -- Build a return statement to skip the rest of the entire body
10177 if Is_Protected_Type (Old_Typ) then
10178 Skip_Stmt := Make_Simple_Return_Statement (Loc);
10180 -- If the requeue is within a task, find the end label of the
10181 -- enclosing accept statement and create a goto statement to it.
10189 -- Climb the parent chain looking for the enclosing accept
10192 Acc := Parent (Search);
10193 while Present (Acc)
10194 and then Nkind (Acc) /= N_Accept_Statement
10196 Acc := Parent (Acc);
10199 -- The last statement is the second label used for completing
10200 -- the rendezvous the usual way. The label we are looking for
10201 -- is right before it.
10204 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
10206 pragma Assert (Nkind (Label) = N_Label);
10208 -- Generate a goto statement to skip the rest of the accept
10211 Make_Goto_Statement (Loc,
10213 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
10217 Set_Analyzed (Skip_Stmt);
10220 end Build_Skip_Statement;
10222 -- Start of processing for Expand_N_Requeue_Statement
10225 -- Extract the components of the entry call
10227 Extract_Entry (N, Concval, Ename, Index);
10228 Conc_Typ := Etype (Concval);
10230 -- If the prefix is an access to class-wide type, dereference to get
10231 -- object and entry type.
10233 if Is_Access_Type (Conc_Typ) then
10234 Conc_Typ := Designated_Type (Conc_Typ);
10236 Make_Explicit_Dereference (Loc, Relocate_Node (Concval)));
10237 Analyze_And_Resolve (Concval, Conc_Typ);
10240 -- Examine the scope stack in order to find nearest enclosing protected
10241 -- or task type. This will constitute our invocation source.
10243 Old_Typ := Current_Scope;
10244 while Present (Old_Typ)
10245 and then not Is_Protected_Type (Old_Typ)
10246 and then not Is_Task_Type (Old_Typ)
10248 Old_Typ := Scope (Old_Typ);
10251 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10252 -- Concval.Ename where the type of Concval is class-wide concurrent
10255 if Ada_Version >= Ada_2012
10256 and then Present (Concval)
10257 and then Is_Class_Wide_Type (Conc_Typ)
10258 and then Is_Concurrent_Interface (Conc_Typ)
10261 Has_Impl : Boolean := False;
10262 Impl_Kind : Name_Id := No_Name;
10265 -- Check whether the Ename is flagged by pragma Implemented
10267 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
10269 Impl_Kind := Implementation_Kind (Entity (Ename));
10272 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10273 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10275 if Has_Impl and then Impl_Kind = Name_By_Entry then
10276 Rewrite (N, Build_Dispatching_Requeue);
10278 Insert_After (N, Build_Skip_Statement (N));
10280 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10281 -- a protected procedure. In this case the requeue is transformed
10282 -- into a dispatching call.
10285 and then Impl_Kind = Name_By_Protected_Procedure
10287 Rewrite (N, Build_Dispatching_Call_Equivalent);
10290 -- The procedure_or_entry_NAME's implementation kind is either
10291 -- By_Any, Optional, or pragma Implemented was not applied at all.
10292 -- In this case a runtime test determines whether Ename denotes an
10293 -- entry or a protected procedure and performs the appropriate
10297 Rewrite (N, Build_Dispatching_Requeue_To_Any);
10302 -- Processing for regular (nondispatching) requeues
10305 Rewrite (N, Build_Normal_Requeue);
10307 Insert_After (N, Build_Skip_Statement (N));
10309 end Expand_N_Requeue_Statement;
10311 -------------------------------
10312 -- Expand_N_Selective_Accept --
10313 -------------------------------
10315 procedure Expand_N_Selective_Accept (N : Node_Id) is
10316 Loc : constant Source_Ptr := Sloc (N);
10317 Alts : constant List_Id := Select_Alternatives (N);
10319 -- Note: in the below declarations a lot of new lists are allocated
10320 -- unconditionally which may well not end up being used. That's not
10321 -- a good idea since it wastes space gratuitously ???
10323 Accept_Case : List_Id;
10324 Accept_List : constant List_Id := New_List;
10327 Alt_List : constant List_Id := New_List;
10328 Alt_Stats : List_Id;
10329 Ann : Entity_Id := Empty;
10331 Check_Guard : Boolean := True;
10333 Decls : constant List_Id := New_List;
10334 Stats : constant List_Id := New_List;
10335 Body_List : constant List_Id := New_List;
10336 Trailing_List : constant List_Id := New_List;
10339 Else_Present : Boolean := False;
10340 Terminate_Alt : Node_Id := Empty;
10341 Select_Mode : Node_Id;
10343 Delay_Case : List_Id;
10344 Delay_Count : Integer := 0;
10345 Delay_Val : Entity_Id;
10346 Delay_Index : Entity_Id;
10347 Delay_Min : Entity_Id;
10348 Delay_Num : Pos := 1;
10349 Delay_Alt_List : List_Id := New_List;
10350 Delay_List : constant List_Id := New_List;
10354 First_Delay : Boolean := True;
10355 Guard_Open : Entity_Id;
10361 Num_Accept : Nat := 0;
10363 Time_Type : Entity_Id;
10364 Select_Call : Node_Id;
10366 Qnam : constant Entity_Id :=
10367 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
10369 Xnam : constant Entity_Id :=
10370 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
10372 -----------------------
10373 -- Local subprograms --
10374 -----------------------
10376 function Accept_Or_Raise return List_Id;
10377 -- For the rare case where delay alternatives all have guards, and
10378 -- all of them are closed, it is still possible that there were open
10379 -- accept alternatives with no callers. We must reexamine the
10380 -- Accept_List, and execute a selective wait with no else if some
10381 -- accept is open. If none, we raise program_error.
10383 procedure Add_Accept (Alt : Node_Id);
10384 -- Process a single accept statement in a select alternative. Build
10385 -- procedure for body of accept, and add entry to dispatch table with
10386 -- expression for guard, in preparation for call to run time select.
10388 function Make_And_Declare_Label (Num : Int) return Node_Id;
10389 -- Manufacture a label using Num as a serial number and declare it.
10390 -- The declaration is appended to Decls. The label marks the trailing
10391 -- statements of an accept or delay alternative.
10393 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
10394 -- Build call to Selective_Wait runtime routine
10396 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
10397 -- Add code to compare value of delay with previous values, and
10398 -- generate case entry for trailing statements.
10400 procedure Process_Accept_Alternative
10404 -- Add code to call corresponding procedure, and branch to
10405 -- trailing statements, if any.
10407 ---------------------
10408 -- Accept_Or_Raise --
10409 ---------------------
10411 function Accept_Or_Raise return List_Id is
10414 J : constant Entity_Id := Make_Temporary (Loc, 'J');
10417 -- We generate the following:
10419 -- for J in q'range loop
10420 -- if q(J).S /=null_task_entry then
10421 -- selective_wait (simple_mode,...);
10427 -- if no rendez_vous then
10428 -- raise program_error;
10431 -- Note that the code needs to know that the selector name
10432 -- in an Accept_Alternative is named S.
10434 Cond := Make_Op_Ne (Loc,
10436 Make_Selected_Component (Loc,
10438 Make_Indexed_Component (Loc,
10439 Prefix => New_Occurrence_Of (Qnam, Loc),
10440 Expressions => New_List (New_Occurrence_Of (J, Loc))),
10441 Selector_Name => Make_Identifier (Loc, Name_S)),
10443 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Loc));
10445 Stats := New_List (
10446 Make_Implicit_Loop_Statement (N,
10447 Iteration_Scheme =>
10448 Make_Iteration_Scheme (Loc,
10449 Loop_Parameter_Specification =>
10450 Make_Loop_Parameter_Specification (Loc,
10451 Defining_Identifier => J,
10452 Discrete_Subtype_Definition =>
10453 Make_Attribute_Reference (Loc,
10454 Prefix => New_Occurrence_Of (Qnam, Loc),
10455 Attribute_Name => Name_Range,
10456 Expressions => New_List (
10457 Make_Integer_Literal (Loc, 1))))),
10459 Statements => New_List (
10460 Make_Implicit_If_Statement (N,
10462 Then_Statements => New_List (
10464 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)),
10465 Make_Exit_Statement (Loc))))));
10468 Make_Raise_Program_Error (Loc,
10469 Condition => Make_Op_Eq (Loc,
10470 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
10472 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
10473 Reason => PE_All_Guards_Closed));
10476 end Accept_Or_Raise;
10482 procedure Add_Accept (Alt : Node_Id) is
10483 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
10484 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
10485 Eloc : constant Source_Ptr := Sloc (Ename);
10486 Eent : constant Entity_Id := Entity (Ename);
10487 Index : constant Node_Id := Entry_Index (Acc_Stm);
10488 Null_Body : Node_Id;
10489 Proc_Body : Node_Id;
10490 PB_Ent : Entity_Id;
10496 Ann := Node (Last_Elmt (Accept_Address (Eent)));
10499 if Present (Condition (Alt)) then
10501 Make_If_Expression (Eloc, New_List (
10503 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
10504 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Eloc)));
10507 Entry_Index_Expression
10508 (Eloc, Eent, Index, Scope (Eent));
10511 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
10512 Null_Body := New_Occurrence_Of (Standard_False, Eloc);
10514 -- Always add call to Abort_Undefer when generating code, since
10515 -- this is what the runtime expects (abort deferred in
10516 -- Selective_Wait). In CodePeer mode this only confuses the
10517 -- analysis with unknown calls, so don't do it.
10519 if not CodePeer_Mode then
10520 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
10522 (First (Statements (Handled_Statement_Sequence
10523 (Accept_Statement (Alt)))),
10529 Make_Defining_Identifier (Eloc,
10530 New_External_Name (Chars (Ename), 'A', Num_Accept));
10532 if Comes_From_Source (Alt) then
10533 Set_Debug_Info_Needed (PB_Ent);
10537 Make_Subprogram_Body (Eloc,
10539 Make_Procedure_Specification (Eloc,
10540 Defining_Unit_Name => PB_Ent),
10541 Declarations => Declarations (Acc_Stm),
10542 Handled_Statement_Sequence =>
10543 Build_Accept_Body (Accept_Statement (Alt)));
10545 -- During the analysis of the body of the accept statement, any
10546 -- zero cost exception handler records were collected in the
10547 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10548 -- This is where we move them to where they belong, namely the
10549 -- newly created procedure.
10551 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
10552 Append (Proc_Body, Body_List);
10555 Null_Body := New_Occurrence_Of (Standard_True, Eloc);
10557 -- if accept statement has declarations, insert above, given that
10558 -- we are not creating a body for the accept.
10560 if Present (Declarations (Acc_Stm)) then
10561 Insert_Actions (N, Declarations (Acc_Stm));
10565 Append_To (Accept_List,
10566 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
10568 Num_Accept := Num_Accept + 1;
10571 ----------------------------
10572 -- Make_And_Declare_Label --
10573 ----------------------------
10575 function Make_And_Declare_Label (Num : Int) return Node_Id is
10579 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
10581 Make_Label (Loc, Lab_Id);
10584 Make_Implicit_Label_Declaration (Loc,
10585 Defining_Identifier =>
10586 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
10587 Label_Construct => Lab));
10590 end Make_And_Declare_Label;
10592 ----------------------
10593 -- Make_Select_Call --
10594 ----------------------
10596 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
10597 Params : constant List_Id := New_List;
10601 Make_Attribute_Reference (Loc,
10602 Prefix => New_Occurrence_Of (Qnam, Loc),
10603 Attribute_Name => Name_Unchecked_Access));
10604 Append_To (Params, Select_Mode);
10605 Append_To (Params, New_Occurrence_Of (Ann, Loc));
10606 Append_To (Params, New_Occurrence_Of (Xnam, Loc));
10609 Make_Procedure_Call_Statement (Loc,
10610 Name => New_Occurrence_Of (RTE (RE_Selective_Wait), Loc),
10611 Parameter_Associations => Params);
10612 end Make_Select_Call;
10614 --------------------------------
10615 -- Process_Accept_Alternative --
10616 --------------------------------
10618 procedure Process_Accept_Alternative
10623 Astmt : constant Node_Id := Accept_Statement (Alt);
10624 Alt_Stats : List_Id;
10627 Adjust_Condition (Condition (Alt));
10629 -- Accept with body
10631 if Present (Handled_Statement_Sequence (Astmt)) then
10634 Make_Procedure_Call_Statement (Sloc (Proc),
10637 (Defining_Unit_Name (Specification (Proc)),
10640 -- Accept with no body (followed by trailing statements)
10643 Alt_Stats := Empty_List;
10646 Ensure_Statement_Present (Sloc (Astmt), Alt);
10648 -- After the call, if any, branch to trailing statements, if any.
10649 -- We create a label for each, as well as the corresponding label
10652 if not Is_Empty_List (Statements (Alt)) then
10653 Lab := Make_And_Declare_Label (Index);
10654 Append (Lab, Trailing_List);
10655 Append_List (Statements (Alt), Trailing_List);
10656 Append_To (Trailing_List,
10657 Make_Goto_Statement (Loc,
10658 Name => New_Copy (Identifier (End_Lab))));
10664 Append_To (Alt_Stats,
10665 Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab))));
10667 Append_To (Alt_List,
10668 Make_Case_Statement_Alternative (Loc,
10669 Discrete_Choices => New_List (Make_Integer_Literal (Loc, Index)),
10670 Statements => Alt_Stats));
10671 end Process_Accept_Alternative;
10673 -------------------------------
10674 -- Process_Delay_Alternative --
10675 -------------------------------
10677 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
10678 Dloc : constant Source_Ptr := Sloc (Delay_Statement (Alt));
10680 Delay_Alt : List_Id;
10683 -- Deal with C/Fortran boolean as delay condition
10685 Adjust_Condition (Condition (Alt));
10687 -- Determine the smallest specified delay
10689 -- for each delay alternative generate:
10691 -- if guard-expression then
10692 -- Delay_Val := delay-expression;
10693 -- Guard_Open := True;
10694 -- if Delay_Val < Delay_Min then
10695 -- Delay_Min := Delay_Val;
10696 -- Delay_Index := Index;
10700 -- The enclosing if-statement is omitted if there is no guard
10702 if Delay_Count = 1 or else First_Delay then
10703 First_Delay := False;
10705 Delay_Alt := New_List (
10706 Make_Assignment_Statement (Loc,
10707 Name => New_Occurrence_Of (Delay_Min, Loc),
10708 Expression => Expression (Delay_Statement (Alt))));
10710 if Delay_Count > 1 then
10711 Append_To (Delay_Alt,
10712 Make_Assignment_Statement (Loc,
10713 Name => New_Occurrence_Of (Delay_Index, Loc),
10714 Expression => Make_Integer_Literal (Loc, Index)));
10718 Delay_Alt := New_List (
10719 Make_Assignment_Statement (Loc,
10720 Name => New_Occurrence_Of (Delay_Val, Loc),
10721 Expression => Expression (Delay_Statement (Alt))));
10723 if Time_Type = Standard_Duration then
10726 Left_Opnd => New_Occurrence_Of (Delay_Val, Loc),
10727 Right_Opnd => New_Occurrence_Of (Delay_Min, Loc));
10730 -- The scope of the time type must define a comparison
10731 -- operator. The scope itself may not be visible, so we
10732 -- construct a node with entity information to insure that
10733 -- semantic analysis can find the proper operator.
10736 Make_Function_Call (Loc,
10737 Name => Make_Selected_Component (Loc,
10739 New_Occurrence_Of (Scope (Time_Type), Loc),
10741 Make_Operator_Symbol (Loc,
10742 Chars => Name_Op_Lt,
10743 Strval => No_String)),
10744 Parameter_Associations =>
10746 New_Occurrence_Of (Delay_Val, Loc),
10747 New_Occurrence_Of (Delay_Min, Loc)));
10749 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
10752 Append_To (Delay_Alt,
10753 Make_Implicit_If_Statement (N,
10755 Then_Statements => New_List (
10756 Make_Assignment_Statement (Loc,
10757 Name => New_Occurrence_Of (Delay_Min, Loc),
10758 Expression => New_Occurrence_Of (Delay_Val, Loc)),
10760 Make_Assignment_Statement (Loc,
10761 Name => New_Occurrence_Of (Delay_Index, Loc),
10762 Expression => Make_Integer_Literal (Loc, Index)))));
10765 if Check_Guard then
10766 Append_To (Delay_Alt,
10767 Make_Assignment_Statement (Loc,
10768 Name => New_Occurrence_Of (Guard_Open, Loc),
10769 Expression => New_Occurrence_Of (Standard_True, Loc)));
10772 if Present (Condition (Alt)) then
10773 Delay_Alt := New_List (
10774 Make_Implicit_If_Statement (N,
10775 Condition => Condition (Alt),
10776 Then_Statements => Delay_Alt));
10779 Append_List (Delay_Alt, Delay_List);
10781 Ensure_Statement_Present (Dloc, Alt);
10783 -- If the delay alternative has a statement part, add choice to the
10784 -- case statements for delays.
10786 if not Is_Empty_List (Statements (Alt)) then
10788 if Delay_Count = 1 then
10789 Append_List (Statements (Alt), Delay_Alt_List);
10792 Append_To (Delay_Alt_List,
10793 Make_Case_Statement_Alternative (Loc,
10794 Discrete_Choices => New_List (
10795 Make_Integer_Literal (Loc, Index)),
10796 Statements => Statements (Alt)));
10799 elsif Delay_Count = 1 then
10801 -- If the single delay has no trailing statements, add a branch
10802 -- to the exit label to the selective wait.
10804 Delay_Alt_List := New_List (
10805 Make_Goto_Statement (Loc,
10806 Name => New_Copy (Identifier (End_Lab))));
10809 end Process_Delay_Alternative;
10811 -- Start of processing for Expand_N_Selective_Accept
10814 Process_Statements_For_Controlled_Objects (N);
10816 -- First insert some declarations before the select. The first is:
10820 -- This variable holds the parameters passed to the accept body. This
10821 -- declaration has already been inserted by the time we get here by
10822 -- a call to Expand_Accept_Declarations made from the semantics when
10823 -- processing the first accept statement contained in the select. We
10824 -- can find this entity as Accept_Address (E), where E is any of the
10825 -- entries references by contained accept statements.
10827 -- The first step is to scan the list of Selective_Accept_Statements
10828 -- to find this entity, and also count the number of accepts, and
10829 -- determine if terminated, delay or else is present:
10833 Alt := First (Alts);
10834 while Present (Alt) loop
10835 Process_Statements_For_Controlled_Objects (Alt);
10837 if Nkind (Alt) = N_Accept_Alternative then
10840 elsif Nkind (Alt) = N_Delay_Alternative then
10841 Delay_Count := Delay_Count + 1;
10843 -- If the delays are relative delays, the delay expressions have
10844 -- type Standard_Duration. Otherwise they must have some time type
10845 -- recognized by GNAT.
10847 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
10848 Time_Type := Standard_Duration;
10850 Time_Type := Etype (Expression (Delay_Statement (Alt)));
10852 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
10853 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
10858 "& is not a time type (RM 9.6(6))",
10859 Expression (Delay_Statement (Alt)), Time_Type);
10860 Time_Type := Standard_Duration;
10861 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
10865 if No (Condition (Alt)) then
10867 -- This guard will always be open
10869 Check_Guard := False;
10872 elsif Nkind (Alt) = N_Terminate_Alternative then
10873 Adjust_Condition (Condition (Alt));
10874 Terminate_Alt := Alt;
10877 Num_Alts := Num_Alts + 1;
10881 Else_Present := Present (Else_Statements (N));
10883 -- At the same time (see procedure Add_Accept) we build the accept list:
10885 -- Qnn : Accept_List (1 .. num-select) := (
10886 -- (null-body, entry-index),
10887 -- (null-body, entry-index),
10889 -- (null_body, entry-index));
10891 -- In the above declaration, null-body is True if the corresponding
10892 -- accept has no body, and false otherwise. The entry is either the
10893 -- entry index expression if there is no guard, or if a guard is
10894 -- present, then an if expression of the form:
10896 -- (if guard then entry-index else Null_Task_Entry)
10898 -- If a guard is statically known to be false, the entry can simply
10899 -- be omitted from the accept list.
10902 Make_Object_Declaration (Loc,
10903 Defining_Identifier => Qnam,
10904 Object_Definition => New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10905 Aliased_Present => True,
10907 Make_Qualified_Expression (Loc,
10909 New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10911 Make_Aggregate (Loc, Expressions => Accept_List))));
10913 -- Then we declare the variable that holds the index for the accept
10914 -- that will be selected for service:
10916 -- Xnn : Select_Index;
10919 Make_Object_Declaration (Loc,
10920 Defining_Identifier => Xnam,
10921 Object_Definition =>
10922 New_Occurrence_Of (RTE (RE_Select_Index), Loc),
10924 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)));
10926 -- After this follow procedure declarations for each accept body
10928 -- procedure Pnn is
10933 -- where the ... are statements from the corresponding procedure body.
10934 -- No parameters are involved, since the parameters are passed via Ann
10935 -- and the parameter references have already been expanded to be direct
10936 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10937 -- any embedded tasking statements (which would normally be illegal in
10938 -- procedures), have been converted to calls to the tasking runtime so
10939 -- there is no problem in putting them into procedures.
10941 -- The original accept statement has been expanded into a block in
10942 -- the same fashion as for simple accepts (see Build_Accept_Body).
10944 -- Note: we don't really need to build these procedures for the case
10945 -- where no delay statement is present, but it is just as easy to
10946 -- build them unconditionally, and not significantly inefficient,
10947 -- since if they are short they will be inlined anyway.
10949 -- The procedure declarations have been assembled in Body_List
10951 -- If delays are present, we must compute the required delay.
10952 -- We first generate the declarations:
10954 -- Delay_Index : Boolean := 0;
10955 -- Delay_Min : Some_Time_Type.Time;
10956 -- Delay_Val : Some_Time_Type.Time;
10958 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10959 -- active delay that is actually chosen as the basis for the possible
10960 -- delay if an immediate rendez-vous is not possible.
10962 -- In the most common case there is a single delay statement, and this
10963 -- is handled specially.
10965 if Delay_Count > 0 then
10967 -- Generate the required declarations
10970 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
10972 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
10974 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
10977 Make_Object_Declaration (Loc,
10978 Defining_Identifier => Delay_Val,
10979 Object_Definition => New_Occurrence_Of (Time_Type, Loc)));
10982 Make_Object_Declaration (Loc,
10983 Defining_Identifier => Delay_Index,
10984 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
10985 Expression => Make_Integer_Literal (Loc, 0)));
10988 Make_Object_Declaration (Loc,
10989 Defining_Identifier => Delay_Min,
10990 Object_Definition => New_Occurrence_Of (Time_Type, Loc),
10992 Unchecked_Convert_To (Time_Type,
10993 Make_Attribute_Reference (Loc,
10995 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
10996 Attribute_Name => Name_Last))));
10998 -- Create Duration and Delay_Mode objects used for passing a delay
11001 D := Make_Temporary (Loc, 'D');
11002 M := Make_Temporary (Loc, 'M');
11008 -- Note that these values are defined in s-osprim.ads and must
11009 -- be kept in sync:
11011 -- Relative : constant := 0;
11012 -- Absolute_Calendar : constant := 1;
11013 -- Absolute_RT : constant := 2;
11015 if Time_Type = Standard_Duration then
11016 Discr := Make_Integer_Literal (Loc, 0);
11018 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11019 Discr := Make_Integer_Literal (Loc, 1);
11023 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11024 Discr := Make_Integer_Literal (Loc, 2);
11028 Make_Object_Declaration (Loc,
11029 Defining_Identifier => D,
11030 Object_Definition =>
11031 New_Occurrence_Of (Standard_Duration, Loc)));
11034 Make_Object_Declaration (Loc,
11035 Defining_Identifier => M,
11036 Object_Definition =>
11037 New_Occurrence_Of (Standard_Integer, Loc),
11038 Expression => Discr));
11041 if Check_Guard then
11043 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
11046 Make_Object_Declaration (Loc,
11047 Defining_Identifier => Guard_Open,
11048 Object_Definition =>
11049 New_Occurrence_Of (Standard_Boolean, Loc),
11051 New_Occurrence_Of (Standard_False, Loc)));
11054 -- Delay_Count is zero, don't need M and D set (suppress warning)
11061 if Present (Terminate_Alt) then
11063 -- If the terminate alternative guard is False, use
11064 -- Simple_Mode; otherwise use Terminate_Mode.
11066 if Present (Condition (Terminate_Alt)) then
11067 Select_Mode := Make_If_Expression (Loc,
11068 New_List (Condition (Terminate_Alt),
11069 New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc),
11070 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)));
11072 Select_Mode := New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc);
11075 elsif Else_Present or Delay_Count > 0 then
11076 Select_Mode := New_Occurrence_Of (RTE (RE_Else_Mode), Loc);
11079 Select_Mode := New_Occurrence_Of (RTE (RE_Simple_Mode), Loc);
11082 Select_Call := Make_Select_Call (Select_Mode);
11083 Append (Select_Call, Stats);
11085 -- Now generate code to act on the result. There is an entry
11086 -- in this case for each accept statement with a non-null body,
11087 -- followed by a branch to the statements that follow the Accept.
11088 -- In the absence of delay alternatives, we generate:
11091 -- when No_Rendezvous => -- omitted if simple mode
11106 -- Lab0: Else_Statements;
11109 -- Lab1: Trailing_Statements1;
11112 -- Lab2: Trailing_Statements2;
11117 -- Generate label for common exit
11119 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
11121 -- First entry is the default case, when no rendezvous is possible
11123 Choices := New_List (New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc));
11125 if Else_Present then
11127 -- If no rendezvous is possible, the else part is executed
11129 Lab := Make_And_Declare_Label (0);
11130 Alt_Stats := New_List (
11131 Make_Goto_Statement (Loc,
11132 Name => New_Copy (Identifier (Lab))));
11134 Append (Lab, Trailing_List);
11135 Append_List (Else_Statements (N), Trailing_List);
11136 Append_To (Trailing_List,
11137 Make_Goto_Statement (Loc,
11138 Name => New_Copy (Identifier (End_Lab))));
11140 Alt_Stats := New_List (
11141 Make_Goto_Statement (Loc,
11142 Name => New_Copy (Identifier (End_Lab))));
11145 Append_To (Alt_List,
11146 Make_Case_Statement_Alternative (Loc,
11147 Discrete_Choices => Choices,
11148 Statements => Alt_Stats));
11150 -- We make use of the fact that Accept_Index is an integer type, and
11151 -- generate successive literals for entries for each accept. Only those
11152 -- for which there is a body or trailing statements get a case entry.
11154 Alt := First (Select_Alternatives (N));
11155 Proc := First (Body_List);
11156 while Present (Alt) loop
11158 if Nkind (Alt) = N_Accept_Alternative then
11159 Process_Accept_Alternative (Alt, Index, Proc);
11160 Index := Index + 1;
11163 (Handled_Statement_Sequence (Accept_Statement (Alt)))
11168 elsif Nkind (Alt) = N_Delay_Alternative then
11169 Process_Delay_Alternative (Alt, Delay_Num);
11170 Delay_Num := Delay_Num + 1;
11176 -- An others choice is always added to the main case, as well
11177 -- as the delay case (to satisfy the compiler).
11179 Append_To (Alt_List,
11180 Make_Case_Statement_Alternative (Loc,
11181 Discrete_Choices =>
11182 New_List (Make_Others_Choice (Loc)),
11184 New_List (Make_Goto_Statement (Loc,
11185 Name => New_Copy (Identifier (End_Lab))))));
11187 Accept_Case := New_List (
11188 Make_Case_Statement (Loc,
11189 Expression => New_Occurrence_Of (Xnam, Loc),
11190 Alternatives => Alt_List));
11192 Append_List (Trailing_List, Accept_Case);
11193 Append_List (Body_List, Decls);
11195 -- Construct case statement for trailing statements of delay
11196 -- alternatives, if there are several of them.
11198 if Delay_Count > 1 then
11199 Append_To (Delay_Alt_List,
11200 Make_Case_Statement_Alternative (Loc,
11201 Discrete_Choices =>
11202 New_List (Make_Others_Choice (Loc)),
11204 New_List (Make_Null_Statement (Loc))));
11206 Delay_Case := New_List (
11207 Make_Case_Statement (Loc,
11208 Expression => New_Occurrence_Of (Delay_Index, Loc),
11209 Alternatives => Delay_Alt_List));
11211 Delay_Case := Delay_Alt_List;
11214 -- If there are no delay alternatives, we append the case statement
11215 -- to the statement list.
11217 if Delay_Count = 0 then
11218 Append_List (Accept_Case, Stats);
11220 -- Delay alternatives present
11223 -- If delay alternatives are present we generate:
11225 -- find minimum delay.
11226 -- DX := minimum delay;
11227 -- M := <delay mode>;
11228 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11231 -- if X = No_Rendezvous then
11232 -- case statement for delay statements.
11234 -- case statement for accept alternatives.
11245 -- The type of the delay expression is known to be legal
11247 if Time_Type = Standard_Duration then
11248 Conv := New_Occurrence_Of (Delay_Min, Loc);
11250 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11251 Conv := Make_Function_Call (Loc,
11252 New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
11253 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11257 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11259 Conv := Make_Function_Call (Loc,
11260 New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
11261 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11264 Stmt := Make_Assignment_Statement (Loc,
11265 Name => New_Occurrence_Of (D, Loc),
11266 Expression => Conv);
11268 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11270 Parms := Parameter_Associations (Select_Call);
11272 Parm := First (Parms);
11273 while Present (Parm) and then Parm /= Select_Mode loop
11277 pragma Assert (Present (Parm));
11278 Rewrite (Parm, New_Occurrence_Of (RTE (RE_Delay_Mode), Loc));
11281 -- Prepare two new parameters of Duration and Delay_Mode type
11282 -- which represent the value and the mode of the minimum delay.
11285 Insert_After (Parm, New_Occurrence_Of (M, Loc));
11286 Insert_After (Parm, New_Occurrence_Of (D, Loc));
11288 -- Create a call to RTS
11290 Rewrite (Select_Call,
11291 Make_Procedure_Call_Statement (Loc,
11292 Name => New_Occurrence_Of (RTE (RE_Timed_Selective_Wait), Loc),
11293 Parameter_Associations => Parms));
11295 -- This new call should follow the calculation of the minimum
11298 Insert_List_Before (Select_Call, Delay_List);
11300 if Check_Guard then
11302 Make_Implicit_If_Statement (N,
11303 Condition => New_Occurrence_Of (Guard_Open, Loc),
11304 Then_Statements => New_List (
11305 New_Copy_Tree (Stmt),
11306 New_Copy_Tree (Select_Call)),
11307 Else_Statements => Accept_Or_Raise);
11308 Rewrite (Select_Call, Stmt);
11310 Insert_Before (Select_Call, Stmt);
11314 Make_Implicit_If_Statement (N,
11315 Condition => Make_Op_Eq (Loc,
11316 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
11318 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
11320 Then_Statements => Delay_Case,
11321 Else_Statements => Accept_Case);
11323 Append (Cases, Stats);
11327 Append (End_Lab, Stats);
11329 -- Replace accept statement with appropriate block
11332 Make_Block_Statement (Loc,
11333 Declarations => Decls,
11334 Handled_Statement_Sequence =>
11335 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats)));
11338 -- Note: have to worry more about abort deferral in above code ???
11340 -- Final step is to unstack the Accept_Address entries for all accept
11341 -- statements appearing in accept alternatives in the select statement
11343 Alt := First (Alts);
11344 while Present (Alt) loop
11345 if Nkind (Alt) = N_Accept_Alternative then
11346 Remove_Last_Elmt (Accept_Address
11347 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
11352 end Expand_N_Selective_Accept;
11354 -------------------------------------------
11355 -- Expand_N_Single_Protected_Declaration --
11356 -------------------------------------------
11358 -- A single protected declaration should never be present after semantic
11359 -- analysis because it is transformed into a protected type declaration
11360 -- and an accompanying anonymous object. This routine ensures that the
11361 -- transformation takes place.
11363 procedure Expand_N_Single_Protected_Declaration (N : Node_Id) is
11365 raise Program_Error;
11366 end Expand_N_Single_Protected_Declaration;
11368 --------------------------------------
11369 -- Expand_N_Single_Task_Declaration --
11370 --------------------------------------
11372 -- A single task declaration should never be present after semantic
11373 -- analysis because it is transformed into a task type declaration and
11374 -- an accompanying anonymous object. This routine ensures that the
11375 -- transformation takes place.
11377 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
11379 raise Program_Error;
11380 end Expand_N_Single_Task_Declaration;
11382 ------------------------
11383 -- Expand_N_Task_Body --
11384 ------------------------
11386 -- Given a task body
11388 -- task body tname is
11394 -- This expansion routine converts it into a procedure and sets the
11395 -- elaboration flag for the procedure to true, to represent the fact
11396 -- that the task body is now elaborated:
11398 -- procedure tnameB (_Task : access tnameV) is
11399 -- discriminal : dtype renames _Task.discriminant;
11401 -- procedure _clean is
11403 -- Abort_Defer.all;
11405 -- Abort_Undefer.all;
11410 -- Abort_Undefer.all;
11412 -- System.Task_Stages.Complete_Activation;
11420 -- In addition, if the task body is an activator, then a call to activate
11421 -- tasks is added at the start of the statements, before the call to
11422 -- Complete_Activation, and if in addition the task is a master then it
11423 -- must be established as a master. These calls are inserted and analyzed
11424 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11427 -- There is one discriminal declaration line generated for each
11428 -- discriminant that is present to provide an easy reference point for
11429 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11431 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11432 -- task body procedures have a profile (Arg : System.Address). That is
11433 -- needed because GNARLI has to use the same access-to-subprogram type
11434 -- for all task types. We depend here on knowing that in GNAT, passing
11435 -- an address argument by value is identical to passing a record value
11436 -- by access (in either case a single pointer is passed), so even though
11437 -- this procedure has the wrong profile. In fact it's all OK, since the
11438 -- callings sequence is identical.
11440 procedure Expand_N_Task_Body (N : Node_Id) is
11441 Loc : constant Source_Ptr := Sloc (N);
11442 Ttyp : constant Entity_Id := Corresponding_Spec (N);
11446 Insert_Nod : Node_Id;
11447 -- Used to determine the proper location of wrapper body insertions
11450 -- if no task body procedure, means we had an error in configurable
11451 -- run-time mode, and there is no point in proceeding further.
11453 if No (Task_Body_Procedure (Ttyp)) then
11457 -- Add renaming declarations for discriminals and a declaration for the
11458 -- entry family index (if applicable).
11460 Install_Private_Data_Declarations
11461 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
11463 -- Add a call to Abort_Undefer at the very beginning of the task
11464 -- body since this body is called with abort still deferred.
11466 if Abort_Allowed then
11467 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
11469 (First (Statements (Handled_Statement_Sequence (N))), Call);
11473 -- The statement part has already been protected with an at_end and
11474 -- cleanup actions. The call to Complete_Activation must be placed
11475 -- at the head of the sequence of statements of that block. The
11476 -- declarations have been merged in this sequence of statements but
11477 -- the first real statement is accessible from the First_Real_Statement
11478 -- field (which was set for exactly this purpose).
11480 if Restricted_Profile then
11481 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
11483 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
11487 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
11491 Make_Subprogram_Body (Loc,
11492 Specification => Build_Task_Proc_Specification (Ttyp),
11493 Declarations => Declarations (N),
11494 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
11495 Set_Is_Task_Body_Procedure (New_N);
11497 -- If the task contains generic instantiations, cleanup actions are
11498 -- delayed until after instantiation. Transfer the activation chain to
11499 -- the subprogram, to insure that the activation call is properly
11500 -- generated. It the task body contains inner tasks, indicate that the
11501 -- subprogram is a task master.
11503 if Delay_Cleanups (Ttyp) then
11504 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
11505 Set_Is_Task_Master (New_N, Is_Task_Master (N));
11508 Rewrite (N, New_N);
11511 -- Set elaboration flag immediately after task body. If the body is a
11512 -- subunit, the flag is set in the declarative part containing the stub.
11514 if Nkind (Parent (N)) /= N_Subunit then
11516 Make_Assignment_Statement (Loc,
11518 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
11519 Expression => New_Occurrence_Of (Standard_True, Loc)));
11522 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11523 -- the task body. At this point all wrapper specs have been created,
11524 -- frozen and included in the dispatch table for the task type.
11526 if Ada_Version >= Ada_2005 then
11527 if Nkind (Parent (N)) = N_Subunit then
11528 Insert_Nod := Corresponding_Stub (Parent (N));
11533 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
11535 end Expand_N_Task_Body;
11537 ------------------------------------
11538 -- Expand_N_Task_Type_Declaration --
11539 ------------------------------------
11541 -- We have several things to do. First we must create a Boolean flag used
11542 -- to mark if the body is elaborated yet. This variable gets set to True
11543 -- when the body of the task is elaborated (we can't rely on the normal
11544 -- ABE mechanism for the task body, since we need to pass an access to
11545 -- this elaboration boolean to the runtime routines).
11547 -- taskE : aliased Boolean := False;
11549 -- Next a variable is declared to hold the task stack size (either the
11550 -- default : Unspecified_Size, or a value that is set by a pragma
11551 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11552 -- the variable is initialized with this value:
11554 -- taskZ : Size_Type := Unspecified_Size;
11556 -- taskZ : Size_Type := Size_Type (size_expression);
11558 -- Note: No variable is needed to hold the task relative deadline since
11559 -- its value would never be static because the parameter is of a private
11560 -- type (Ada.Real_Time.Time_Span).
11562 -- Next we create a corresponding record type declaration used to represent
11563 -- values of this task. The general form of this type declaration is
11565 -- type taskV (discriminants) is record
11566 -- _Task_Id : Task_Id;
11567 -- entry_family : array (bounds) of Void;
11568 -- _Priority : Integer := priority_expression;
11569 -- _Size : Size_Type := size_expression;
11570 -- _Secondary_Stack_Size : Size_Type := size_expression;
11571 -- _Task_Info : Task_Info_Type := task_info_expression;
11572 -- _CPU : Integer := cpu_range_expression;
11573 -- _Relative_Deadline : Time_Span := time_span_expression;
11574 -- _Domain : Dispatching_Domain := dd_expression;
11577 -- The discriminants are present only if the corresponding task type has
11578 -- discriminants, and they exactly mirror the task type discriminants.
11580 -- The Id field is always present. It contains the Task_Id value, as set by
11581 -- the call to Create_Task. Note that although the task is limited, the
11582 -- task value record type is not limited, so there is no problem in passing
11583 -- this field as an out parameter to Create_Task.
11585 -- One entry_family component is present for each entry family in the task
11586 -- definition. The bounds correspond to the bounds of the entry family
11587 -- (which may depend on discriminants). The element type is void, since we
11588 -- only need the bounds information for determining the entry index. Note
11589 -- that the use of an anonymous array would normally be illegal in this
11590 -- context, but this is a parser check, and the semantics is quite prepared
11591 -- to handle such a case.
11593 -- The _Size field is present only if a Storage_Size pragma appears in the
11594 -- task definition. The expression captures the argument that was present
11595 -- in the pragma, and is used to override the task stack size otherwise
11596 -- associated with the task type.
11598 -- The _Secondary_Stack_Size field is present only the task entity has a
11599 -- Secondary_Stack_Size rep item. It will be filled at the freeze point,
11600 -- when the record init proc is built, to capture the expression of the
11601 -- rep item (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot
11602 -- be filled here since aspect evaluations are delayed till the freeze
11605 -- The _Priority field is present only if the task entity has a Priority or
11606 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11607 -- definition clause). It will be filled at the freeze point, when the
11608 -- record init proc is built, to capture the expression of the rep item
11609 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11610 -- here since aspect evaluations are delayed till the freeze point.
11612 -- The _Task_Info field is present only if a Task_Info pragma appears in
11613 -- the task definition. The expression captures the argument that was
11614 -- present in the pragma, and is used to provide the Task_Image parameter
11615 -- to the call to Create_Task.
11617 -- The _CPU field is present only if the task entity has a CPU rep item
11618 -- (pragma, aspect specification or attribute definition clause). It will
11619 -- be filled at the freeze point, when the record init proc is built, to
11620 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11621 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11622 -- are delayed till the freeze point.
11624 -- The _Relative_Deadline field is present only if a Relative_Deadline
11625 -- pragma appears in the task definition. The expression captures the
11626 -- argument that was present in the pragma, and is used to provide the
11627 -- Relative_Deadline parameter to the call to Create_Task.
11629 -- The _Domain field is present only if the task entity has a
11630 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11631 -- definition clause). It will be filled at the freeze point, when the
11632 -- record init proc is built, to capture the expression of the rep item
11633 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11634 -- here since aspect evaluations are delayed till the freeze point.
11636 -- When a task is declared, an instance of the task value record is
11637 -- created. The elaboration of this declaration creates the correct bounds
11638 -- for the entry families, and also evaluates the size, priority, and
11639 -- task_Info expressions if needed. The initialization routine for the task
11640 -- type itself then calls Create_Task with appropriate parameters to
11641 -- initialize the value of the Task_Id field.
11643 -- Note: the address of this record is passed as the "Discriminants"
11644 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11645 -- body procedure, it does not matter that it does not quite match the
11646 -- GNARLI model of what is being passed (the record contains more than just
11647 -- the discriminants, but the discriminants can be found from the record
11650 -- The Entity_Id for this created record type is placed in the
11651 -- Corresponding_Record_Type field of the associated task type entity.
11653 -- Next we create a procedure specification for the task body procedure:
11655 -- procedure taskB (_Task : access taskV);
11657 -- Note that this must come after the record type declaration, since
11658 -- the spec refers to this type. It turns out that the initialization
11659 -- procedure for the value type references the task body spec, but that's
11660 -- fine, since it won't be generated till the freeze point for the type,
11661 -- which is certainly after the task body spec declaration.
11663 -- Finally, we set the task index value field of the entry attribute in
11664 -- the case of a simple entry.
11666 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
11667 Loc : constant Source_Ptr := Sloc (N);
11668 TaskId : constant Entity_Id := Defining_Identifier (N);
11669 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
11670 Tasknm : constant Name_Id := Chars (Tasktyp);
11671 Taskdef : constant Node_Id := Task_Definition (N);
11673 Body_Decl : Node_Id;
11675 Decl_Stack : Node_Id;
11676 Elab_Decl : Node_Id;
11677 Ent_Stack : Entity_Id;
11678 Proc_Spec : Node_Id;
11679 Rec_Decl : Node_Id;
11680 Rec_Ent : Entity_Id;
11681 Size_Decl : Entity_Id;
11682 Task_Size : Node_Id;
11684 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id;
11685 -- Searches the task definition T for the first occurrence of the pragma
11686 -- Relative Deadline. The caller has ensured that the pragma is present
11687 -- in the task definition. Note that this routine cannot be implemented
11688 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11689 -- not chained because their expansion into a procedure call statement
11690 -- would cause a break in the chain.
11692 ----------------------------------
11693 -- Get_Relative_Deadline_Pragma --
11694 ----------------------------------
11696 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id is
11700 N := First (Visible_Declarations (T));
11701 while Present (N) loop
11702 if Nkind (N) = N_Pragma
11703 and then Pragma_Name (N) = Name_Relative_Deadline
11711 N := First (Private_Declarations (T));
11712 while Present (N) loop
11713 if Nkind (N) = N_Pragma
11714 and then Pragma_Name (N) = Name_Relative_Deadline
11722 raise Program_Error;
11723 end Get_Relative_Deadline_Pragma;
11725 -- Start of processing for Expand_N_Task_Type_Declaration
11728 -- If already expanded, nothing to do
11730 if Present (Corresponding_Record_Type (Tasktyp)) then
11734 -- Here we will do the expansion
11736 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
11738 Rec_Ent := Defining_Identifier (Rec_Decl);
11739 Cdecls := Component_Items (Component_List
11740 (Type_Definition (Rec_Decl)));
11742 Qualify_Entity_Names (N);
11744 -- First create the elaboration variable
11747 Make_Object_Declaration (Loc,
11748 Defining_Identifier =>
11749 Make_Defining_Identifier (Sloc (Tasktyp),
11750 Chars => New_External_Name (Tasknm, 'E')),
11751 Aliased_Present => True,
11752 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
11753 Expression => New_Occurrence_Of (Standard_False, Loc));
11755 Insert_After (N, Elab_Decl);
11757 -- Next create the declaration of the size variable (tasknmZ)
11759 Set_Storage_Size_Variable (Tasktyp,
11760 Make_Defining_Identifier (Sloc (Tasktyp),
11761 Chars => New_External_Name (Tasknm, 'Z')));
11763 if Present (Taskdef)
11764 and then Has_Storage_Size_Pragma (Taskdef)
11766 Is_OK_Static_Expression
11768 (First (Pragma_Argument_Associations
11769 (Get_Rep_Pragma (TaskId, Name_Storage_Size)))))
11772 Make_Object_Declaration (Loc,
11773 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11774 Object_Definition =>
11775 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11777 Convert_To (RTE (RE_Size_Type),
11779 (Expression (First (Pragma_Argument_Associations
11781 (TaskId, Name_Storage_Size)))))));
11785 Make_Object_Declaration (Loc,
11786 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11787 Object_Definition =>
11788 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11790 New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
11793 Insert_After (Elab_Decl, Size_Decl);
11795 -- Next build the rest of the corresponding record declaration. This is
11796 -- done last, since the corresponding record initialization procedure
11797 -- will reference the previously created entities.
11799 -- Fill in the component declarations -- first the _Task_Id field
11802 Make_Component_Declaration (Loc,
11803 Defining_Identifier =>
11804 Make_Defining_Identifier (Loc, Name_uTask_Id),
11805 Component_Definition =>
11806 Make_Component_Definition (Loc,
11807 Aliased_Present => False,
11808 Subtype_Indication => New_Occurrence_Of (RTE (RO_ST_Task_Id),
11811 -- Declare static ATCB (that is, created by the expander) if we are
11812 -- using the Restricted run time.
11814 if Restricted_Profile then
11816 Make_Component_Declaration (Loc,
11817 Defining_Identifier =>
11818 Make_Defining_Identifier (Loc, Name_uATCB),
11820 Component_Definition =>
11821 Make_Component_Definition (Loc,
11822 Aliased_Present => True,
11823 Subtype_Indication => Make_Subtype_Indication (Loc,
11825 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
11828 Make_Index_Or_Discriminant_Constraint (Loc,
11830 New_List (Make_Integer_Literal (Loc, 0)))))));
11834 -- Declare static stack (that is, created by the expander) if we are
11835 -- using the Restricted run time on a bare board configuration.
11837 if Restricted_Profile and then Preallocated_Stacks_On_Target then
11839 -- First we need to extract the appropriate stack size
11841 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
11843 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11845 Expr_N : constant Node_Id :=
11846 Expression (First (
11847 Pragma_Argument_Associations (
11848 Get_Rep_Pragma (TaskId, Name_Storage_Size))));
11849 Etyp : constant Entity_Id := Etype (Expr_N);
11850 P : constant Node_Id := Parent (Expr_N);
11853 -- The stack is defined inside the corresponding record.
11854 -- Therefore if the size of the stack is set by means of
11855 -- a discriminant, we must reference the discriminant of the
11856 -- corresponding record type.
11858 if Nkind (Expr_N) in N_Has_Entity
11859 and then Present (Discriminal_Link (Entity (Expr_N)))
11863 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
11865 Set_Parent (Task_Size, P);
11866 Set_Etype (Task_Size, Etyp);
11867 Set_Analyzed (Task_Size);
11870 Task_Size := Relocate_Node (Expr_N);
11876 New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc);
11879 Decl_Stack := Make_Component_Declaration (Loc,
11880 Defining_Identifier => Ent_Stack,
11882 Component_Definition =>
11883 Make_Component_Definition (Loc,
11884 Aliased_Present => True,
11885 Subtype_Indication => Make_Subtype_Indication (Loc,
11887 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
11890 Make_Index_Or_Discriminant_Constraint (Loc,
11891 Constraints => New_List (Make_Range (Loc,
11892 Low_Bound => Make_Integer_Literal (Loc, 1),
11893 High_Bound => Convert_To (RTE (RE_Storage_Offset),
11896 Append_To (Cdecls, Decl_Stack);
11898 -- The appropriate alignment for the stack is ensured by the run-time
11899 -- code in charge of task creation.
11903 -- Add components for entry families
11905 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
11907 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11908 -- item is present.
11910 if Has_Rep_Item (TaskId, Name_Priority, Check_Parents => False) then
11912 Make_Component_Declaration (Loc,
11913 Defining_Identifier =>
11914 Make_Defining_Identifier (Loc, Name_uPriority),
11915 Component_Definition =>
11916 Make_Component_Definition (Loc,
11917 Aliased_Present => False,
11918 Subtype_Indication =>
11919 New_Occurrence_Of (Standard_Integer, Loc))));
11922 -- Add the _Size component if a Storage_Size pragma is present
11924 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11926 Make_Component_Declaration (Loc,
11927 Defining_Identifier =>
11928 Make_Defining_Identifier (Loc, Name_uSize),
11930 Component_Definition =>
11931 Make_Component_Definition (Loc,
11932 Aliased_Present => False,
11933 Subtype_Indication =>
11934 New_Occurrence_Of (RTE (RE_Size_Type), Loc)),
11937 Convert_To (RTE (RE_Size_Type),
11939 Expression (First (
11940 Pragma_Argument_Associations (
11941 Get_Rep_Pragma (TaskId, Name_Storage_Size))))))));
11944 -- Add the _Secondary_Stack_Size component if a Secondary_Stack_Size
11945 -- rep item is present.
11948 (TaskId, Name_Secondary_Stack_Size, Check_Parents => False)
11951 Make_Component_Declaration (Loc,
11952 Defining_Identifier =>
11953 Make_Defining_Identifier (Loc, Name_uSecondary_Stack_Size),
11955 Component_Definition =>
11956 Make_Component_Definition (Loc,
11957 Aliased_Present => False,
11958 Subtype_Indication =>
11959 New_Occurrence_Of (RTE (RE_Size_Type), Loc))));
11962 -- Add the _Task_Info component if a Task_Info pragma is present
11964 if Has_Rep_Pragma (TaskId, Name_Task_Info, Check_Parents => False) then
11966 Make_Component_Declaration (Loc,
11967 Defining_Identifier =>
11968 Make_Defining_Identifier (Loc, Name_uTask_Info),
11970 Component_Definition =>
11971 Make_Component_Definition (Loc,
11972 Aliased_Present => False,
11973 Subtype_Indication =>
11974 New_Occurrence_Of (RTE (RE_Task_Info_Type), Loc)),
11976 Expression => New_Copy (
11977 Expression (First (
11978 Pragma_Argument_Associations (
11980 (TaskId, Name_Task_Info, Check_Parents => False)))))));
11983 -- Add the _CPU component if a CPU rep item is present
11985 if Has_Rep_Item (TaskId, Name_CPU, Check_Parents => False) then
11987 Make_Component_Declaration (Loc,
11988 Defining_Identifier =>
11989 Make_Defining_Identifier (Loc, Name_uCPU),
11991 Component_Definition =>
11992 Make_Component_Definition (Loc,
11993 Aliased_Present => False,
11994 Subtype_Indication =>
11995 New_Occurrence_Of (RTE (RE_CPU_Range), Loc))));
11998 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11999 -- present. If we are using a restricted run time this component will
12000 -- not be added (deadlines are not allowed by the Ravenscar profile).
12002 if not Restricted_Profile
12003 and then Present (Taskdef)
12004 and then Has_Relative_Deadline_Pragma (Taskdef)
12007 Make_Component_Declaration (Loc,
12008 Defining_Identifier =>
12009 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
12011 Component_Definition =>
12012 Make_Component_Definition (Loc,
12013 Aliased_Present => False,
12014 Subtype_Indication =>
12015 New_Occurrence_Of (RTE (RE_Time_Span), Loc)),
12018 Convert_To (RTE (RE_Time_Span),
12020 Expression (First (
12021 Pragma_Argument_Associations (
12022 Get_Relative_Deadline_Pragma (Taskdef))))))));
12025 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12026 -- item is present. If we are using a restricted run time this component
12027 -- will not be added (dispatching domains are not allowed by the
12028 -- Ravenscar profile).
12030 if not Restricted_Profile
12033 (TaskId, Name_Dispatching_Domain, Check_Parents => False)
12036 Make_Component_Declaration (Loc,
12037 Defining_Identifier =>
12038 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
12040 Component_Definition =>
12041 Make_Component_Definition (Loc,
12042 Aliased_Present => False,
12043 Subtype_Indication =>
12045 (RTE (RE_Dispatching_Domain_Access), Loc))));
12048 Insert_After (Size_Decl, Rec_Decl);
12050 -- Analyze the record declaration immediately after construction,
12051 -- because the initialization procedure is needed for single task
12052 -- declarations before the next entity is analyzed.
12054 Analyze (Rec_Decl);
12056 -- Create the declaration of the task body procedure
12058 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
12060 Make_Subprogram_Declaration (Loc,
12061 Specification => Proc_Spec);
12062 Set_Is_Task_Body_Procedure (Body_Decl);
12064 Insert_After (Rec_Decl, Body_Decl);
12066 -- The subprogram does not comes from source, so we have to indicate the
12067 -- need for debugging information explicitly.
12069 if Comes_From_Source (Original_Node (N)) then
12070 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
12073 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12074 -- the corresponding record has been frozen.
12076 if Ada_Version >= Ada_2005 then
12077 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
12080 -- Ada 2005 (AI-345): We must defer freezing to allow further
12081 -- declaration of primitive subprograms covering task interfaces
12083 if Ada_Version <= Ada_95 then
12085 -- Now we can freeze the corresponding record. This needs manually
12086 -- freezing, since it is really part of the task type, and the task
12087 -- type is frozen at this stage. We of course need the initialization
12088 -- procedure for this corresponding record type and we won't get it
12089 -- in time if we don't freeze now.
12092 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
12094 if Is_Non_Empty_List (L) then
12095 Insert_List_After (Body_Decl, L);
12100 -- Complete the expansion of access types to the current task type, if
12101 -- any were declared.
12103 Expand_Previous_Access_Type (Tasktyp);
12105 -- Create wrappers for entries that have contract cases, preconditions
12106 -- and postconditions.
12112 Ent := First_Entity (Tasktyp);
12113 while Present (Ent) loop
12114 if Ekind_In (Ent, E_Entry, E_Entry_Family) then
12115 Build_Contract_Wrapper (Ent, N);
12121 end Expand_N_Task_Type_Declaration;
12123 -------------------------------
12124 -- Expand_N_Timed_Entry_Call --
12125 -------------------------------
12127 -- A timed entry call in normal case is not implemented using ATC mechanism
12128 -- anymore for efficiency reason.
12138 -- is expanded as follows:
12140 -- 1) When T.E is a task entry_call;
12144 -- X : Task_Entry_Index := <entry index>;
12145 -- DX : Duration := To_Duration (D);
12146 -- M : Delay_Mode := <discriminant>;
12147 -- P : parms := (parm, parm, parm);
12150 -- Timed_Protected_Entry_Call
12151 -- (<acceptor-task>, X, P'Address, DX, M, B);
12159 -- 2) When T.E is a protected entry_call;
12163 -- X : Protected_Entry_Index := <entry index>;
12164 -- DX : Duration := To_Duration (D);
12165 -- M : Delay_Mode := <discriminant>;
12166 -- P : parms := (parm, parm, parm);
12169 -- Timed_Protected_Entry_Call
12170 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12178 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12179 -- is no delay and the triggering statements are executed. We first
12180 -- determine the kind of the triggering call and then execute a
12181 -- synchronized operation or a direct call.
12184 -- B : Boolean := False;
12185 -- C : Ada.Tags.Prim_Op_Kind;
12186 -- DX : Duration := To_Duration (D)
12187 -- K : Ada.Tags.Tagged_Kind :=
12188 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12189 -- M : Integer :=...;
12190 -- P : Parameters := (Param1 .. ParamN);
12194 -- if K = Ada.Tags.TK_Limited_Tagged
12195 -- or else K = Ada.Tags.TK_Tagged
12197 -- <dispatching-call>;
12202 -- Ada.Tags.Get_Offset_Index
12203 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12205 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12207 -- if C = POK_Protected_Entry
12208 -- or else C = POK_Task_Entry
12210 -- Param1 := P.Param1;
12212 -- ParamN := P.ParamN;
12216 -- if C = POK_Procedure
12217 -- or else C = POK_Protected_Procedure
12218 -- or else C = POK_Task_Procedure
12220 -- <dispatching-call>;
12226 -- <triggering-statements>
12228 -- <timed-statements>
12232 -- The triggering statement and the sequence of timed statements have not
12233 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12234 -- global references if within an instantiation.
12236 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
12237 Loc : constant Source_Ptr := Sloc (N);
12240 Blk_Typ : Entity_Id;
12242 Call_Ent : Entity_Id;
12243 Conc_Typ_Stmts : List_Id;
12245 D_Alt : constant Node_Id := Delay_Alternative (N);
12248 D_Stat : Node_Id := Delay_Statement (D_Alt);
12250 D_Type : Entity_Id;
12253 E_Alt : constant Node_Id := Entry_Call_Alternative (N);
12254 E_Call : Node_Id := Entry_Call_Statement (E_Alt);
12259 Is_Disp_Select : Boolean;
12260 Lim_Typ_Stmts : List_Id;
12269 B : Entity_Id; -- Call status flag
12270 C : Entity_Id; -- Call kind
12271 D : Entity_Id; -- Delay
12272 K : Entity_Id; -- Tagged kind
12273 M : Entity_Id; -- Delay mode
12274 P : Entity_Id; -- Parameter block
12275 S : Entity_Id; -- Primitive operation slot
12277 -- Start of processing for Expand_N_Timed_Entry_Call
12280 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12281 -- was already reported on spec, so do not attempt to expand the call.
12283 if Restriction_Active (No_Select_Statements) then
12287 Process_Statements_For_Controlled_Objects (E_Alt);
12288 Process_Statements_For_Controlled_Objects (D_Alt);
12290 Ensure_Statement_Present (Sloc (D_Stat), D_Alt);
12292 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12293 -- may wrap them in blocks.
12295 E_Stats := Statements (E_Alt);
12296 D_Stats := Statements (D_Alt);
12298 -- The arguments in the call may require dynamic allocation, and the
12299 -- call statement may have been transformed into a block. The block
12300 -- may contain additional declarations for internal entities, and the
12301 -- original call is found by sequential search.
12303 if Nkind (E_Call) = N_Block_Statement then
12304 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
12305 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
12306 N_Entry_Call_Statement)
12313 Ada_Version >= Ada_2005
12314 and then Nkind (E_Call) = N_Procedure_Call_Statement;
12316 if Is_Disp_Select then
12317 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
12323 -- B : Boolean := False;
12325 B := Build_B (Loc, Decls);
12328 -- C : Ada.Tags.Prim_Op_Kind;
12330 C := Build_C (Loc, Decls);
12332 -- Because the analysis of all statements was disabled, manually
12333 -- analyze the delay statement.
12336 D_Stat := Original_Node (D_Stat);
12339 -- Build an entry call using Simple_Entry_Call
12341 Extract_Entry (E_Call, Concval, Ename, Index);
12342 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
12344 Decls := Declarations (E_Call);
12345 Stmts := Statements (Handled_Statement_Sequence (E_Call));
12354 B := Make_Defining_Identifier (Loc, Name_uB);
12357 Make_Object_Declaration (Loc,
12358 Defining_Identifier => B,
12359 Object_Definition =>
12360 New_Occurrence_Of (Standard_Boolean, Loc)));
12363 -- Duration and mode processing
12365 D_Type := Base_Type (Etype (Expression (D_Stat)));
12367 -- Use the type of the delay expression (Calendar or Real_Time) to
12368 -- generate the appropriate conversion.
12370 if Nkind (D_Stat) = N_Delay_Relative_Statement then
12371 D_Disc := Make_Integer_Literal (Loc, 0);
12372 D_Conv := Relocate_Node (Expression (D_Stat));
12374 elsif Is_RTE (D_Type, RO_CA_Time) then
12375 D_Disc := Make_Integer_Literal (Loc, 1);
12377 Make_Function_Call (Loc,
12378 Name => New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
12379 Parameter_Associations =>
12380 New_List (New_Copy (Expression (D_Stat))));
12382 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
12383 D_Disc := Make_Integer_Literal (Loc, 2);
12385 Make_Function_Call (Loc,
12386 Name => New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
12387 Parameter_Associations =>
12388 New_List (New_Copy (Expression (D_Stat))));
12391 D := Make_Temporary (Loc, 'D');
12397 Make_Object_Declaration (Loc,
12398 Defining_Identifier => D,
12399 Object_Definition => New_Occurrence_Of (Standard_Duration, Loc)));
12401 M := Make_Temporary (Loc, 'M');
12404 -- M : Integer := (0 | 1 | 2);
12407 Make_Object_Declaration (Loc,
12408 Defining_Identifier => M,
12409 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
12410 Expression => D_Disc));
12412 -- Do the assignment at this stage only because the evaluation of the
12413 -- expression must not occur before (see ACVC C97302A).
12416 Make_Assignment_Statement (Loc,
12417 Name => New_Occurrence_Of (D, Loc),
12418 Expression => D_Conv));
12420 -- Parameter block processing
12422 -- Manually create the parameter block for dispatching calls. In the
12423 -- case of entries, the block has already been created during the call
12424 -- to Build_Simple_Entry_Call.
12426 if Is_Disp_Select then
12428 -- Tagged kind processing, generate:
12429 -- K : Ada.Tags.Tagged_Kind :=
12430 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12432 K := Build_K (Loc, Decls, Obj);
12434 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
12436 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
12438 -- Dispatch table slot processing, generate:
12441 S := Build_S (Loc, Decls);
12444 -- S := Ada.Tags.Get_Offset_Index
12445 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12448 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
12451 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12453 -- where Obj is the controlling formal parameter, S is the dispatch
12454 -- table slot number of the dispatching operation, P is the wrapped
12455 -- parameter block, D is the duration, M is the duration mode, C is
12456 -- the call kind and B is the call status.
12458 Params := New_List;
12460 Append_To (Params, New_Copy_Tree (Obj));
12461 Append_To (Params, New_Occurrence_Of (S, Loc));
12463 Make_Attribute_Reference (Loc,
12464 Prefix => New_Occurrence_Of (P, Loc),
12465 Attribute_Name => Name_Address));
12466 Append_To (Params, New_Occurrence_Of (D, Loc));
12467 Append_To (Params, New_Occurrence_Of (M, Loc));
12468 Append_To (Params, New_Occurrence_Of (C, Loc));
12469 Append_To (Params, New_Occurrence_Of (B, Loc));
12471 Append_To (Conc_Typ_Stmts,
12472 Make_Procedure_Call_Statement (Loc,
12476 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
12477 Parameter_Associations => Params));
12480 -- if C = POK_Protected_Entry
12481 -- or else C = POK_Task_Entry
12483 -- Param1 := P.Param1;
12485 -- ParamN := P.ParamN;
12488 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
12490 -- Generate the if statement only when the packed parameters need
12491 -- explicit assignments to their corresponding actuals.
12493 if Present (Unpack) then
12494 Append_To (Conc_Typ_Stmts,
12495 Make_Implicit_If_Statement (N,
12501 Left_Opnd => New_Occurrence_Of (C, Loc),
12504 (RTE (RE_POK_Protected_Entry), Loc)),
12508 Left_Opnd => New_Occurrence_Of (C, Loc),
12510 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
12512 Then_Statements => Unpack));
12518 -- if C = POK_Procedure
12519 -- or else C = POK_Protected_Procedure
12520 -- or else C = POK_Task_Procedure
12522 -- <dispatching-call>
12526 N_Stats := New_List (
12527 Make_Implicit_If_Statement (N,
12532 Left_Opnd => New_Occurrence_Of (C, Loc),
12534 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
12540 Left_Opnd => New_Occurrence_Of (C, Loc),
12542 New_Occurrence_Of (RTE (
12543 RE_POK_Protected_Procedure), Loc)),
12546 Left_Opnd => New_Occurrence_Of (C, Loc),
12549 (RTE (RE_POK_Task_Procedure), Loc)))),
12551 Then_Statements => New_List (E_Call)));
12553 Append_To (Conc_Typ_Stmts,
12554 Make_Implicit_If_Statement (N,
12555 Condition => New_Occurrence_Of (B, Loc),
12556 Then_Statements => N_Stats));
12559 -- <dispatching-call>;
12563 New_List (New_Copy_Tree (E_Call),
12564 Make_Assignment_Statement (Loc,
12565 Name => New_Occurrence_Of (B, Loc),
12566 Expression => New_Occurrence_Of (Standard_True, Loc)));
12569 -- if K = Ada.Tags.TK_Limited_Tagged
12570 -- or else K = Ada.Tags.TK_Tagged
12578 Make_Implicit_If_Statement (N,
12579 Condition => Build_Dispatching_Tag_Check (K, N),
12580 Then_Statements => Lim_Typ_Stmts,
12581 Else_Statements => Conc_Typ_Stmts));
12586 -- <triggering-statements>
12588 -- <timed-statements>
12592 Make_Implicit_If_Statement (N,
12593 Condition => New_Occurrence_Of (B, Loc),
12594 Then_Statements => E_Stats,
12595 Else_Statements => D_Stats));
12598 -- Simple case of a nondispatching trigger. Skip assignments to
12599 -- temporaries created for in-out parameters.
12601 -- This makes unwarranted assumptions about the shape of the expanded
12602 -- tree for the call, and should be cleaned up ???
12604 Stmt := First (Stmts);
12605 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
12609 -- Do the assignment at this stage only because the evaluation
12610 -- of the expression must not occur before (see ACVC C97302A).
12612 Insert_Before (Stmt,
12613 Make_Assignment_Statement (Loc,
12614 Name => New_Occurrence_Of (D, Loc),
12615 Expression => D_Conv));
12618 Params := Parameter_Associations (Call);
12620 -- For a protected type, we build a Timed_Protected_Entry_Call
12622 if Is_Protected_Type (Etype (Concval)) then
12624 -- Create a new call statement
12626 Param := First (Params);
12627 while Present (Param)
12628 and then not Is_RTE (Etype (Param), RE_Call_Modes)
12633 Dummy := Remove_Next (Next (Param));
12635 -- Remove garbage is following the Cancel_Param if present
12637 Dummy := Next (Param);
12639 -- Remove the mode of the Protected_Entry_Call call, then remove
12640 -- the Communication_Block of the Protected_Entry_Call call, and
12641 -- finally add Duration and a Delay_Mode parameter
12643 pragma Assert (Present (Param));
12644 Rewrite (Param, New_Occurrence_Of (D, Loc));
12646 Rewrite (Dummy, New_Occurrence_Of (M, Loc));
12648 -- Add a Boolean flag for successful entry call
12650 Append_To (Params, New_Occurrence_Of (B, Loc));
12652 case Corresponding_Runtime_Package (Etype (Concval)) is
12653 when System_Tasking_Protected_Objects_Entries =>
12655 Make_Procedure_Call_Statement (Loc,
12658 (RTE (RE_Timed_Protected_Entry_Call), Loc),
12659 Parameter_Associations => Params));
12662 raise Program_Error;
12665 -- For the task case, build a Timed_Task_Entry_Call
12668 -- Create a new call statement
12670 Append_To (Params, New_Occurrence_Of (D, Loc));
12671 Append_To (Params, New_Occurrence_Of (M, Loc));
12672 Append_To (Params, New_Occurrence_Of (B, Loc));
12675 Make_Procedure_Call_Statement (Loc,
12677 New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
12678 Parameter_Associations => Params));
12682 Make_Implicit_If_Statement (N,
12683 Condition => New_Occurrence_Of (B, Loc),
12684 Then_Statements => E_Stats,
12685 Else_Statements => D_Stats));
12689 Make_Block_Statement (Loc,
12690 Declarations => Decls,
12691 Handled_Statement_Sequence =>
12692 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
12695 end Expand_N_Timed_Entry_Call;
12697 ----------------------------------------
12698 -- Expand_Protected_Body_Declarations --
12699 ----------------------------------------
12701 procedure Expand_Protected_Body_Declarations
12703 Spec_Id : Entity_Id)
12706 if No_Run_Time_Mode then
12707 Error_Msg_CRT ("protected body", N);
12710 elsif Expander_Active then
12712 -- Associate discriminals with the first subprogram or entry body to
12715 if Present (First_Protected_Operation (Declarations (N))) then
12716 Set_Discriminals (Parent (Spec_Id));
12719 end Expand_Protected_Body_Declarations;
12721 -------------------------
12722 -- External_Subprogram --
12723 -------------------------
12725 function External_Subprogram (E : Entity_Id) return Entity_Id is
12726 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
12729 -- The internal and external subprograms follow each other on the entity
12730 -- chain. Note that previously private operations had no separate
12731 -- external subprogram. We now create one in all cases, because a
12732 -- private operation may actually appear in an external call, through
12733 -- a 'Access reference used for a callback.
12735 -- If the operation is a function that returns an anonymous access type,
12736 -- the corresponding itype appears before the operation, and must be
12739 -- This mechanism is fragile, there should be a real link between the
12740 -- two versions of the operation, but there is no place to put it ???
12742 if Is_Access_Type (Next_Entity (Subp)) then
12743 return Next_Entity (Next_Entity (Subp));
12745 return Next_Entity (Subp);
12747 end External_Subprogram;
12749 ------------------------------
12750 -- Extract_Dispatching_Call --
12751 ------------------------------
12753 procedure Extract_Dispatching_Call
12755 Call_Ent : out Entity_Id;
12756 Object : out Entity_Id;
12757 Actuals : out List_Id;
12758 Formals : out List_Id)
12760 Call_Nam : Node_Id;
12763 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
12765 if Present (Original_Node (N)) then
12766 Call_Nam := Name (Original_Node (N));
12768 Call_Nam := Name (N);
12771 -- Retrieve the name of the dispatching procedure. It contains the
12772 -- dispatch table slot number.
12775 case Nkind (Call_Nam) is
12776 when N_Identifier =>
12779 when N_Selected_Component =>
12780 Call_Nam := Selector_Name (Call_Nam);
12783 raise Program_Error;
12787 Actuals := Parameter_Associations (N);
12788 Call_Ent := Entity (Call_Nam);
12789 Formals := Parameter_Specifications (Parent (Call_Ent));
12790 Object := First (Actuals);
12792 if Present (Original_Node (Object)) then
12793 Object := Original_Node (Object);
12796 -- If the type of the dispatching object is an access type then return
12797 -- an explicit dereference.
12799 if Is_Access_Type (Etype (Object)) then
12800 Object := Make_Explicit_Dereference (Sloc (N), Object);
12803 end Extract_Dispatching_Call;
12805 -------------------
12806 -- Extract_Entry --
12807 -------------------
12809 procedure Extract_Entry
12811 Concval : out Node_Id;
12812 Ename : out Node_Id;
12813 Index : out Node_Id)
12815 Nam : constant Node_Id := Name (N);
12818 -- For a simple entry, the name is a selected component, with the
12819 -- prefix being the task value, and the selector being the entry.
12821 if Nkind (Nam) = N_Selected_Component then
12822 Concval := Prefix (Nam);
12823 Ename := Selector_Name (Nam);
12826 -- For a member of an entry family, the name is an indexed component
12827 -- where the prefix is a selected component, whose prefix in turn is
12828 -- the task value, and whose selector is the entry family. The single
12829 -- expression in the expressions list of the indexed component is the
12830 -- subscript for the family.
12832 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
12833 Concval := Prefix (Prefix (Nam));
12834 Ename := Selector_Name (Prefix (Nam));
12835 Index := First (Expressions (Nam));
12838 -- Through indirection, the type may actually be a limited view of a
12839 -- concurrent type. When compiling a call, the non-limited view of the
12840 -- type is visible.
12842 if From_Limited_With (Etype (Concval)) then
12843 Set_Etype (Concval, Non_Limited_View (Etype (Concval)));
12847 -------------------
12848 -- Family_Offset --
12849 -------------------
12851 function Family_Offset
12856 Cap : Boolean) return Node_Id
12862 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
12863 -- If one of the bounds is a reference to a discriminant, replace with
12864 -- corresponding discriminal of type. Within the body of a task retrieve
12865 -- the renamed discriminant by simple visibility, using its generated
12866 -- name. Within a protected object, find the original discriminant and
12867 -- replace it with the discriminal of the current protected operation.
12869 ------------------------------
12870 -- Convert_Discriminant_Ref --
12871 ------------------------------
12873 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
12874 Loc : constant Source_Ptr := Sloc (Bound);
12879 if Is_Entity_Name (Bound)
12880 and then Ekind (Entity (Bound)) = E_Discriminant
12882 if Is_Task_Type (Ttyp) and then Has_Completion (Ttyp) then
12883 B := Make_Identifier (Loc, Chars (Entity (Bound)));
12884 Find_Direct_Name (B);
12886 elsif Is_Protected_Type (Ttyp) then
12887 D := First_Discriminant (Ttyp);
12888 while Chars (D) /= Chars (Entity (Bound)) loop
12889 Next_Discriminant (D);
12892 B := New_Occurrence_Of (Discriminal (D), Loc);
12895 B := New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
12898 elsif Nkind (Bound) = N_Attribute_Reference then
12902 B := New_Copy_Tree (Bound);
12906 Make_Attribute_Reference (Loc,
12907 Attribute_Name => Name_Pos,
12908 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
12909 Expressions => New_List (B));
12910 end Convert_Discriminant_Ref;
12912 -- Start of processing for Family_Offset
12915 Real_Hi := Convert_Discriminant_Ref (Hi);
12916 Real_Lo := Convert_Discriminant_Ref (Lo);
12919 if Is_Task_Type (Ttyp) then
12920 Ityp := RTE (RE_Task_Entry_Index);
12922 Ityp := RTE (RE_Protected_Entry_Index);
12926 Make_Attribute_Reference (Loc,
12927 Prefix => New_Occurrence_Of (Ityp, Loc),
12928 Attribute_Name => Name_Min,
12929 Expressions => New_List (
12931 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12934 Make_Attribute_Reference (Loc,
12935 Prefix => New_Occurrence_Of (Ityp, Loc),
12936 Attribute_Name => Name_Max,
12937 Expressions => New_List (
12939 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12942 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12949 function Family_Size
12954 Cap : Boolean) return Node_Id
12959 if Is_Task_Type (Ttyp) then
12960 Ityp := RTE (RE_Task_Entry_Index);
12962 Ityp := RTE (RE_Protected_Entry_Index);
12966 Make_Attribute_Reference (Loc,
12967 Prefix => New_Occurrence_Of (Ityp, Loc),
12968 Attribute_Name => Name_Max,
12969 Expressions => New_List (
12971 Left_Opnd => Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
12972 Right_Opnd => Make_Integer_Literal (Loc, 1)),
12973 Make_Integer_Literal (Loc, 0)));
12976 ----------------------------
12977 -- Find_Enclosing_Context --
12978 ----------------------------
12980 procedure Find_Enclosing_Context
12982 Context : out Node_Id;
12983 Context_Id : out Entity_Id;
12984 Context_Decls : out List_Id)
12987 -- Traverse the parent chain looking for an enclosing body, block,
12988 -- package or return statement.
12990 Context := Parent (N);
12991 while Present (Context) loop
12992 if Nkind_In (Context, N_Entry_Body,
12993 N_Extended_Return_Statement,
12995 N_Package_Declaration,
13001 -- Do not consider block created to protect a list of statements with
13002 -- an Abort_Defer / Abort_Undefer_Direct pair.
13004 elsif Nkind (Context) = N_Block_Statement
13005 and then not Is_Abort_Block (Context)
13010 Context := Parent (Context);
13013 pragma Assert (Present (Context));
13015 -- Extract the constituents of the context
13017 if Nkind (Context) = N_Extended_Return_Statement then
13018 Context_Decls := Return_Object_Declarations (Context);
13019 Context_Id := Return_Statement_Entity (Context);
13021 -- Package declarations and bodies use a common library-level activation
13022 -- chain or task master, therefore return the package declaration as the
13023 -- proper carrier for the appropriate flag.
13025 elsif Nkind (Context) = N_Package_Body then
13026 Context_Decls := Declarations (Context);
13027 Context_Id := Corresponding_Spec (Context);
13028 Context := Parent (Context_Id);
13030 if Nkind (Context) = N_Defining_Program_Unit_Name then
13031 Context := Parent (Parent (Context));
13033 Context := Parent (Context);
13036 elsif Nkind (Context) = N_Package_Declaration then
13037 Context_Decls := Visible_Declarations (Specification (Context));
13038 Context_Id := Defining_Unit_Name (Specification (Context));
13040 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13041 Context_Id := Defining_Identifier (Context_Id);
13045 if Nkind (Context) = N_Block_Statement then
13046 Context_Id := Entity (Identifier (Context));
13048 elsif Nkind (Context) = N_Entry_Body then
13049 Context_Id := Defining_Identifier (Context);
13051 elsif Nkind (Context) = N_Subprogram_Body then
13052 if Present (Corresponding_Spec (Context)) then
13053 Context_Id := Corresponding_Spec (Context);
13055 Context_Id := Defining_Unit_Name (Specification (Context));
13057 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13058 Context_Id := Defining_Identifier (Context_Id);
13062 elsif Nkind (Context) = N_Task_Body then
13063 Context_Id := Corresponding_Spec (Context);
13066 raise Program_Error;
13069 Context_Decls := Declarations (Context);
13072 pragma Assert (Present (Context_Id));
13073 pragma Assert (Present (Context_Decls));
13074 end Find_Enclosing_Context;
13076 -----------------------
13077 -- Find_Master_Scope --
13078 -----------------------
13080 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
13084 -- In Ada 2005, the master is the innermost enclosing scope that is not
13085 -- transient. If the enclosing block is the rewriting of a call or the
13086 -- scope is an extended return statement this is valid master. The
13087 -- master in an extended return is only used within the return, and is
13088 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13089 -- now before that overwriting occurs.
13093 if Ada_Version >= Ada_2005 then
13094 while Is_Internal (S) loop
13095 if Nkind (Parent (S)) = N_Block_Statement
13097 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
13101 elsif Ekind (S) = E_Return_Statement then
13111 end Find_Master_Scope;
13113 -------------------------------
13114 -- First_Protected_Operation --
13115 -------------------------------
13117 function First_Protected_Operation (D : List_Id) return Node_Id is
13118 First_Op : Node_Id;
13121 First_Op := First (D);
13122 while Present (First_Op)
13123 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
13129 end First_Protected_Operation;
13131 ---------------------------------------
13132 -- Install_Private_Data_Declarations --
13133 ---------------------------------------
13135 procedure Install_Private_Data_Declarations
13137 Spec_Id : Entity_Id;
13138 Conc_Typ : Entity_Id;
13139 Body_Nod : Node_Id;
13141 Barrier : Boolean := False;
13142 Family : Boolean := False)
13144 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
13147 Insert_Node : Node_Id := Empty;
13148 Obj_Ent : Entity_Id;
13150 procedure Add (Decl : Node_Id);
13151 -- Add a single declaration after Insert_Node. If this is the first
13152 -- addition, Decl is added to the front of Decls and it becomes the
13155 function Replace_Bound (Bound : Node_Id) return Node_Id;
13156 -- The bounds of an entry index may depend on discriminants, create a
13157 -- reference to the corresponding prival. Otherwise return a duplicate
13158 -- of the original bound.
13164 procedure Add (Decl : Node_Id) is
13166 if No (Insert_Node) then
13167 Prepend_To (Decls, Decl);
13169 Insert_After (Insert_Node, Decl);
13172 Insert_Node := Decl;
13175 --------------------------
13176 -- Replace_Discriminant --
13177 --------------------------
13179 function Replace_Bound (Bound : Node_Id) return Node_Id is
13181 if Nkind (Bound) = N_Identifier
13182 and then Is_Discriminal (Entity (Bound))
13184 return Make_Identifier (Loc, Chars (Entity (Bound)));
13186 return Duplicate_Subexpr (Bound);
13190 -- Start of processing for Install_Private_Data_Declarations
13193 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13194 -- formal parameter _O, _object or _task depending on the context.
13196 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
13198 -- Special processing of _O for barrier functions, protected entries
13205 (Ekind (Spec_Id) = E_Entry
13206 or else Ekind (Spec_Id) = E_Entry_Family))
13209 Conc_Rec : constant Entity_Id :=
13210 Corresponding_Record_Type (Conc_Typ);
13211 Typ_Id : constant Entity_Id :=
13212 Make_Defining_Identifier (Loc,
13213 New_External_Name (Chars (Conc_Rec), 'P'));
13216 -- type prot_typVP is access prot_typV;
13219 Make_Full_Type_Declaration (Loc,
13220 Defining_Identifier => Typ_Id,
13222 Make_Access_To_Object_Definition (Loc,
13223 Subtype_Indication =>
13224 New_Occurrence_Of (Conc_Rec, Loc)));
13228 -- _object : prot_typVP := prot_typV (_O);
13231 Make_Object_Declaration (Loc,
13232 Defining_Identifier =>
13233 Make_Defining_Identifier (Loc, Name_uObject),
13234 Object_Definition => New_Occurrence_Of (Typ_Id, Loc),
13236 Unchecked_Convert_To (Typ_Id,
13237 New_Occurrence_Of (Obj_Ent, Loc)));
13240 -- Set the reference to the concurrent object
13242 Obj_Ent := Defining_Identifier (Decl);
13246 -- Step 2: Create the Protection object and build its declaration for
13247 -- any protected entry (family) of subprogram. Note for the lock-free
13248 -- implementation, the Protection object is not needed anymore.
13250 if Is_Protected and then not Uses_Lock_Free (Conc_Typ) then
13252 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
13256 Set_Protection_Object (Spec_Id, Prot_Ent);
13258 -- Determine the proper protection type
13260 if Has_Attach_Handler (Conc_Typ)
13261 and then not Restricted_Profile
13263 Prot_Typ := RE_Static_Interrupt_Protection;
13265 elsif Has_Interrupt_Handler (Conc_Typ)
13266 and then not Restriction_Active (No_Dynamic_Attachment)
13268 Prot_Typ := RE_Dynamic_Interrupt_Protection;
13271 case Corresponding_Runtime_Package (Conc_Typ) is
13272 when System_Tasking_Protected_Objects_Entries =>
13273 Prot_Typ := RE_Protection_Entries;
13275 when System_Tasking_Protected_Objects_Single_Entry =>
13276 Prot_Typ := RE_Protection_Entry;
13278 when System_Tasking_Protected_Objects =>
13279 Prot_Typ := RE_Protection;
13282 raise Program_Error;
13287 -- conc_typR : protection_typ renames _object._object;
13290 Make_Object_Renaming_Declaration (Loc,
13291 Defining_Identifier => Prot_Ent,
13293 New_Occurrence_Of (RTE (Prot_Typ), Loc),
13295 Make_Selected_Component (Loc,
13296 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13297 Selector_Name => Make_Identifier (Loc, Name_uObject)));
13302 -- Step 3: Add discriminant renamings (if any)
13304 if Has_Discriminants (Conc_Typ) then
13309 D := First_Discriminant (Conc_Typ);
13310 while Present (D) loop
13312 -- Adjust the source location
13314 Set_Sloc (Discriminal (D), Loc);
13317 -- discr_name : discr_typ renames _object.discr_name;
13319 -- discr_name : discr_typ renames _task.discr_name;
13322 Make_Object_Renaming_Declaration (Loc,
13323 Defining_Identifier => Discriminal (D),
13324 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
13326 Make_Selected_Component (Loc,
13327 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13328 Selector_Name => Make_Identifier (Loc, Chars (D))));
13331 Next_Discriminant (D);
13336 -- Step 4: Add private component renamings (if any)
13338 if Is_Protected then
13339 Def := Protected_Definition (Parent (Conc_Typ));
13341 if Present (Private_Declarations (Def)) then
13344 Comp_Id : Entity_Id;
13345 Decl_Id : Entity_Id;
13348 Comp := First (Private_Declarations (Def));
13349 while Present (Comp) loop
13350 if Nkind (Comp) = N_Component_Declaration then
13351 Comp_Id := Defining_Identifier (Comp);
13353 Make_Defining_Identifier (Loc, Chars (Comp_Id));
13355 -- Minimal decoration
13357 if Ekind (Spec_Id) = E_Function then
13358 Set_Ekind (Decl_Id, E_Constant);
13360 Set_Ekind (Decl_Id, E_Variable);
13363 Set_Prival (Comp_Id, Decl_Id);
13364 Set_Prival_Link (Decl_Id, Comp_Id);
13365 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
13368 -- comp_name : comp_typ renames _object.comp_name;
13371 Make_Object_Renaming_Declaration (Loc,
13372 Defining_Identifier => Decl_Id,
13374 New_Occurrence_Of (Etype (Comp_Id), Loc),
13376 Make_Selected_Component (Loc,
13378 New_Occurrence_Of (Obj_Ent, Loc),
13380 Make_Identifier (Loc, Chars (Comp_Id))));
13390 -- Step 5: Add the declaration of the entry index and the associated
13391 -- type for barrier functions and entry families.
13393 if (Barrier and Family) or else Ekind (Spec_Id) = E_Entry_Family then
13395 E : constant Entity_Id := Index_Object (Spec_Id);
13396 Index : constant Entity_Id :=
13397 Defining_Identifier
13398 (Entry_Index_Specification
13399 (Entry_Body_Formal_Part (Body_Nod)));
13400 Index_Con : constant Entity_Id :=
13401 Make_Defining_Identifier (Loc, Chars (Index));
13403 Index_Typ : Entity_Id;
13407 -- Minimal decoration
13409 Set_Ekind (Index_Con, E_Constant);
13410 Set_Entry_Index_Constant (Index, Index_Con);
13411 Set_Discriminal_Link (Index_Con, Index);
13413 -- Retrieve the bounds of the entry family
13415 High := Type_High_Bound (Etype (Index));
13416 Low := Type_Low_Bound (Etype (Index));
13418 -- In the simple case the entry family is given by a subtype mark
13419 -- and the index constant has the same type.
13421 if Is_Entity_Name (Original_Node (
13422 Discrete_Subtype_Definition (Parent (Index))))
13424 Index_Typ := Etype (Index);
13426 -- Otherwise a new subtype declaration is required
13429 High := Replace_Bound (High);
13430 Low := Replace_Bound (Low);
13432 Index_Typ := Make_Temporary (Loc, 'J');
13435 -- subtype Jnn is <Etype of Index> range Low .. High;
13438 Make_Subtype_Declaration (Loc,
13439 Defining_Identifier => Index_Typ,
13440 Subtype_Indication =>
13441 Make_Subtype_Indication (Loc,
13443 New_Occurrence_Of (Base_Type (Etype (Index)), Loc),
13445 Make_Range_Constraint (Loc,
13446 Range_Expression =>
13447 Make_Range (Loc, Low, High))));
13451 Set_Etype (Index_Con, Index_Typ);
13453 -- Create the object which designates the index:
13454 -- J : constant Jnn :=
13455 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13457 -- where Jnn is the subtype created above or the original type of
13458 -- the index, _E is a formal of the protected body subprogram and
13459 -- <index expr> is the index of the first family member.
13462 Make_Object_Declaration (Loc,
13463 Defining_Identifier => Index_Con,
13464 Constant_Present => True,
13465 Object_Definition =>
13466 New_Occurrence_Of (Index_Typ, Loc),
13469 Make_Attribute_Reference (Loc,
13471 New_Occurrence_Of (Index_Typ, Loc),
13472 Attribute_Name => Name_Val,
13474 Expressions => New_List (
13478 Make_Op_Subtract (Loc,
13479 Left_Opnd => New_Occurrence_Of (E, Loc),
13481 Entry_Index_Expression (Loc,
13482 Defining_Identifier (Body_Nod),
13486 Make_Attribute_Reference (Loc,
13488 New_Occurrence_Of (Index_Typ, Loc),
13489 Attribute_Name => Name_Pos,
13490 Expressions => New_List (
13491 Make_Attribute_Reference (Loc,
13493 New_Occurrence_Of (Index_Typ, Loc),
13494 Attribute_Name => Name_First)))))));
13498 end Install_Private_Data_Declarations;
13500 -----------------------
13501 -- Is_Exception_Safe --
13502 -----------------------
13504 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
13506 function Has_Side_Effect (N : Node_Id) return Boolean;
13507 -- Return True whenever encountering a subprogram call or raise
13508 -- statement of any kind in the sequence of statements
13510 ---------------------
13511 -- Has_Side_Effect --
13512 ---------------------
13514 -- What is this doing buried two levels down in exp_ch9. It seems like a
13515 -- generally useful function, and indeed there may be code duplication
13516 -- going on here ???
13518 function Has_Side_Effect (N : Node_Id) return Boolean is
13522 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
13523 -- Indicate whether N is a subprogram call or a raise statement
13525 ----------------------
13526 -- Is_Call_Or_Raise --
13527 ----------------------
13529 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
13531 return Nkind_In (N, N_Procedure_Call_Statement,
13534 N_Raise_Constraint_Error,
13535 N_Raise_Program_Error,
13536 N_Raise_Storage_Error);
13537 end Is_Call_Or_Raise;
13539 -- Start of processing for Has_Side_Effect
13543 while Present (Stmt) loop
13544 if Is_Call_Or_Raise (Stmt) then
13548 -- An object declaration can also contain a function call or a
13549 -- raise statement.
13551 if Nkind (Stmt) = N_Object_Declaration then
13552 Expr := Expression (Stmt);
13554 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
13563 end Has_Side_Effect;
13565 -- Start of processing for Is_Exception_Safe
13568 -- When exceptions can't be propagated, the subprogram returns normally
13570 if No_Exception_Handlers_Set then
13574 -- If the checks handled by the back end are not disabled, we cannot
13575 -- ensure that no exception will be raised.
13577 if not Access_Checks_Suppressed (Empty)
13578 or else not Discriminant_Checks_Suppressed (Empty)
13579 or else not Range_Checks_Suppressed (Empty)
13580 or else not Index_Checks_Suppressed (Empty)
13581 or else Opt.Stack_Checking_Enabled
13586 if Has_Side_Effect (First (Declarations (Subprogram)))
13589 (First (Statements (Handled_Statement_Sequence (Subprogram))))
13595 end Is_Exception_Safe;
13597 ---------------------------------
13598 -- Is_Potentially_Large_Family --
13599 ---------------------------------
13601 function Is_Potentially_Large_Family
13602 (Base_Index : Entity_Id;
13603 Conctyp : Entity_Id;
13605 Hi : Node_Id) return Boolean
13608 return Scope (Base_Index) = Standard_Standard
13609 and then Base_Index = Base_Type (Standard_Integer)
13610 and then Has_Discriminants (Conctyp)
13612 Present (Discriminant_Default_Value (First_Discriminant (Conctyp)))
13614 (Denotes_Discriminant (Lo, True)
13616 Denotes_Discriminant (Hi, True));
13617 end Is_Potentially_Large_Family;
13619 -------------------------------------
13620 -- Is_Private_Primitive_Subprogram --
13621 -------------------------------------
13623 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
13626 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
13627 and then Is_Private_Primitive (Id);
13628 end Is_Private_Primitive_Subprogram;
13634 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
13635 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
13636 Formal : Entity_Id;
13639 Formal := First_Formal (Bod_Subp);
13640 while Present (Formal) loop
13642 -- Look for formal parameter _E
13644 if Chars (Formal) = Name_uE then
13648 Next_Formal (Formal);
13651 -- A protected body subprogram should always have the parameter in
13654 raise Program_Error;
13657 --------------------------------
13658 -- Make_Initialize_Protection --
13659 --------------------------------
13661 function Make_Initialize_Protection
13662 (Protect_Rec : Entity_Id) return List_Id
13664 Loc : constant Source_Ptr := Sloc (Protect_Rec);
13667 Ptyp : constant Node_Id :=
13668 Corresponding_Concurrent_Type (Protect_Rec);
13670 L : constant List_Id := New_List;
13671 Has_Entry : constant Boolean := Has_Entries (Ptyp);
13672 Prio_Type : Entity_Id;
13673 Prio_Var : Entity_Id := Empty;
13674 Restricted : constant Boolean := Restricted_Profile;
13677 -- We may need two calls to properly initialize the object, one to
13678 -- Initialize_Protection, and possibly one to Install_Handlers if we
13679 -- have a pragma Attach_Handler.
13681 -- Get protected declaration. In the case of a task type declaration,
13682 -- this is simply the parent of the protected type entity. In the single
13683 -- protected object declaration, this parent will be the implicit type,
13684 -- and we can find the corresponding single protected object declaration
13685 -- by searching forward in the declaration list in the tree.
13687 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13688 -- of this type should have been removed during semantic analysis.
13690 Pdec := Parent (Ptyp);
13691 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
13692 N_Single_Protected_Declaration)
13697 -- Build the parameter list for the call. Note that _Init is the name
13698 -- of the formal for the object to be initialized, which is the task
13699 -- value record itself.
13703 -- For lock-free implementation, skip initializations of the Protection
13706 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13708 -- Object parameter. This is a pointer to the object of type
13709 -- Protection used by the GNARL to control the protected object.
13712 Make_Attribute_Reference (Loc,
13714 Make_Selected_Component (Loc,
13715 Prefix => Make_Identifier (Loc, Name_uInit),
13716 Selector_Name => Make_Identifier (Loc, Name_uObject)),
13717 Attribute_Name => Name_Unchecked_Access));
13719 -- Priority parameter. Set to Unspecified_Priority unless there is a
13720 -- Priority rep item, in which case we take the value from the pragma
13721 -- or attribute definition clause, or there is an Interrupt_Priority
13722 -- rep item and no Priority rep item, and we set the ceiling to
13723 -- Interrupt_Priority'Last, an implementation-defined value, see
13726 if Has_Rep_Item (Ptyp, Name_Priority, Check_Parents => False) then
13728 Prio_Clause : constant Node_Id :=
13730 (Ptyp, Name_Priority, Check_Parents => False);
13737 if Nkind (Prio_Clause) = N_Pragma then
13740 (First (Pragma_Argument_Associations (Prio_Clause)));
13742 -- Get_Rep_Item returns either priority pragma.
13744 if Pragma_Name (Prio_Clause) = Name_Priority then
13745 Prio_Type := RTE (RE_Any_Priority);
13747 Prio_Type := RTE (RE_Interrupt_Priority);
13750 -- Attribute definition clause Priority
13753 if Chars (Prio_Clause) = Name_Priority then
13754 Prio_Type := RTE (RE_Any_Priority);
13756 Prio_Type := RTE (RE_Interrupt_Priority);
13759 Prio := Expression (Prio_Clause);
13762 -- Always create a locale variable to capture the priority.
13763 -- The priority is also passed to Install_Restriced_Handlers.
13764 -- Note that it is really necessary to create this variable
13765 -- explicitly. It might be thought that removing side effects
13766 -- would the appropriate approach, but that could generate
13767 -- declarations improperly placed in the enclosing scope.
13769 Prio_Var := Make_Temporary (Loc, 'R', Prio);
13771 Make_Object_Declaration (Loc,
13772 Defining_Identifier => Prio_Var,
13773 Object_Definition => New_Occurrence_Of (Prio_Type, Loc),
13774 Expression => Relocate_Node (Prio)));
13776 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13779 -- When no priority is specified but an xx_Handler pragma is, we
13780 -- default to System.Interrupts.Default_Interrupt_Priority, see
13783 elsif Has_Attach_Handler (Ptyp)
13784 or else Has_Interrupt_Handler (Ptyp)
13787 New_Occurrence_Of (RTE (RE_Default_Interrupt_Priority), Loc));
13789 -- Normal case, no priority or xx_Handler specified, default priority
13793 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
13796 -- Test for Compiler_Info parameter. This parameter allows entry body
13797 -- procedures and barrier functions to be called from the runtime. It
13798 -- is a pointer to the record generated by the compiler to represent
13799 -- the protected object.
13801 -- A protected type without entries that covers an interface and
13802 -- overrides the abstract routines with protected procedures is
13803 -- considered equivalent to a protected type with entries in the
13804 -- context of dispatching select statements.
13806 -- Protected types with interrupt handlers (when not using a
13807 -- restricted profile) are also considered equivalent to protected
13808 -- types with entries.
13810 -- The types which are used (Static_Interrupt_Protection and
13811 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13814 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
13816 Called_Subp : RE_Id;
13820 when System_Tasking_Protected_Objects_Entries =>
13821 Called_Subp := RE_Initialize_Protection_Entries;
13823 -- Argument Compiler_Info
13826 Make_Attribute_Reference (Loc,
13827 Prefix => Make_Identifier (Loc, Name_uInit),
13828 Attribute_Name => Name_Address));
13830 when System_Tasking_Protected_Objects_Single_Entry =>
13831 Called_Subp := RE_Initialize_Protection_Entry;
13833 -- Argument Compiler_Info
13836 Make_Attribute_Reference (Loc,
13837 Prefix => Make_Identifier (Loc, Name_uInit),
13838 Attribute_Name => Name_Address));
13840 when System_Tasking_Protected_Objects =>
13841 Called_Subp := RE_Initialize_Protection;
13844 raise Program_Error;
13847 -- Entry_Queue_Maxes parameter. This is an access to an array of
13848 -- naturals representing the entry queue maximums for each entry
13849 -- in the protected type. Zero represents no max. The access is
13850 -- null if there is no limit for all entries (usual case).
13853 and then Pkg_Id = System_Tasking_Protected_Objects_Entries
13855 if Present (Entry_Max_Queue_Lengths_Array (Ptyp)) then
13857 Make_Attribute_Reference (Loc,
13860 (Entry_Max_Queue_Lengths_Array (Ptyp), Loc),
13861 Attribute_Name => Name_Unrestricted_Access));
13863 Append_To (Args, Make_Null (Loc));
13866 -- Edge cases exist where entry initialization functions are
13867 -- called, but no entries exist, so null is appended.
13869 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
13870 Append_To (Args, Make_Null (Loc));
13873 -- Entry_Bodies parameter. This is a pointer to an array of
13874 -- pointers to the entry body procedures and barrier functions of
13875 -- the object. If the protected type has no entries this object
13876 -- will not exist, in this case, pass a null (it can happen when
13877 -- there are protected interrupt handlers or interfaces).
13880 P_Arr := Entry_Bodies_Array (Ptyp);
13882 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13883 -- multiple entries).
13886 Make_Attribute_Reference (Loc,
13887 Prefix => New_Occurrence_Of (P_Arr, Loc),
13888 Attribute_Name => Name_Unrestricted_Access));
13890 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
13892 -- Find index mapping function (clumsy but ok for now)
13894 while Ekind (P_Arr) /= E_Function loop
13895 Next_Entity (P_Arr);
13899 Make_Attribute_Reference (Loc,
13900 Prefix => New_Occurrence_Of (P_Arr, Loc),
13901 Attribute_Name => Name_Unrestricted_Access));
13904 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
13906 -- This is the case where we have a protected object with
13907 -- interfaces and no entries, and the single entry restriction
13908 -- is in effect. We pass a null pointer for the entry
13909 -- parameter because there is no actual entry.
13911 Append_To (Args, Make_Null (Loc));
13913 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
13915 -- This is the case where we have a protected object with no
13917 -- - either interrupt handlers with non restricted profile,
13919 -- Note that the types which are used for interrupt handlers
13920 -- (Static/Dynamic_Interrupt_Protection) are derived from
13921 -- Protection_Entries. We pass two null pointers because there
13922 -- is no actual entry, and the initialization procedure needs
13923 -- both Entry_Bodies and Find_Body_Index.
13925 Append_To (Args, Make_Null (Loc));
13926 Append_To (Args, Make_Null (Loc));
13930 Make_Procedure_Call_Statement (Loc,
13932 New_Occurrence_Of (RTE (Called_Subp), Loc),
13933 Parameter_Associations => Args));
13937 if Has_Attach_Handler (Ptyp) then
13939 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13940 -- make the following call:
13942 -- Install_Handlers (_object,
13943 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13945 -- or, in the case of Ravenscar:
13947 -- Install_Restricted_Handlers
13948 -- (Prio, ((Expr1, Proc1'access), ...., (ExprN, ProcN'access)));
13951 Args : constant List_Id := New_List;
13952 Table : constant List_Id := New_List;
13953 Ritem : Node_Id := First_Rep_Item (Ptyp);
13956 -- Build the Priority parameter (only for ravenscar)
13960 -- Priority comes from a pragma
13962 if Present (Prio_Var) then
13963 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13965 -- Priority is the default one
13970 (RTE (RE_Default_Interrupt_Priority), Loc));
13974 -- Build the Attach_Handler table argument
13976 while Present (Ritem) loop
13977 if Nkind (Ritem) = N_Pragma
13978 and then Pragma_Name (Ritem) = Name_Attach_Handler
13981 Handler : constant Node_Id :=
13982 First (Pragma_Argument_Associations (Ritem));
13984 Interrupt : constant Node_Id := Next (Handler);
13985 Expr : constant Node_Id := Expression (Interrupt);
13989 Make_Aggregate (Loc, Expressions => New_List (
13990 Unchecked_Convert_To
13991 (RTE (RE_System_Interrupt_Id), Expr),
13992 Make_Attribute_Reference (Loc,
13994 Make_Selected_Component (Loc,
13996 Make_Identifier (Loc, Name_uInit),
13998 Duplicate_Subexpr_No_Checks
13999 (Expression (Handler))),
14000 Attribute_Name => Name_Access))));
14004 Next_Rep_Item (Ritem);
14007 -- Append the table argument we just built
14009 Append_To (Args, Make_Aggregate (Loc, Table));
14011 -- Append the Install_Handlers (or Install_Restricted_Handlers)
14012 -- call to the statements.
14015 -- Call a simplified version of Install_Handlers to be used
14016 -- when the Ravenscar restrictions are in effect
14017 -- (Install_Restricted_Handlers).
14020 Make_Procedure_Call_Statement (Loc,
14023 (RTE (RE_Install_Restricted_Handlers), Loc),
14024 Parameter_Associations => Args));
14027 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
14029 -- First, prepends the _object argument
14032 Make_Attribute_Reference (Loc,
14034 Make_Selected_Component (Loc,
14035 Prefix => Make_Identifier (Loc, Name_uInit),
14037 Make_Identifier (Loc, Name_uObject)),
14038 Attribute_Name => Name_Unchecked_Access));
14041 -- Then, insert call to Install_Handlers
14044 Make_Procedure_Call_Statement (Loc,
14046 New_Occurrence_Of (RTE (RE_Install_Handlers), Loc),
14047 Parameter_Associations => Args));
14053 end Make_Initialize_Protection;
14055 ---------------------------
14056 -- Make_Task_Create_Call --
14057 ---------------------------
14059 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
14060 Loc : constant Source_Ptr := Sloc (Task_Rec);
14070 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
14071 Tnam := Chars (Ttyp);
14073 -- Get task declaration. In the case of a task type declaration, this is
14074 -- simply the parent of the task type entity. In the single task
14075 -- declaration, this parent will be the implicit type, and we can find
14076 -- the corresponding single task declaration by searching forward in the
14077 -- declaration list in the tree.
14079 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14080 -- this type should have been removed during semantic analysis.
14082 Tdec := Parent (Ttyp);
14083 while not Nkind_In (Tdec, N_Task_Type_Declaration,
14084 N_Single_Task_Declaration)
14089 -- Now we can find the task definition from this declaration
14091 Tdef := Task_Definition (Tdec);
14093 -- Build the parameter list for the call. Note that _Init is the name
14094 -- of the formal for the object to be initialized, which is the task
14095 -- value record itself.
14099 -- Priority parameter. Set to Unspecified_Priority unless there is a
14100 -- Priority rep item, in which case we take the value from the rep item.
14102 if Has_Rep_Item (Ttyp, Name_Priority, Check_Parents => False) then
14104 Make_Selected_Component (Loc,
14105 Prefix => Make_Identifier (Loc, Name_uInit),
14106 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
14109 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
14112 -- Optional Stack parameter
14114 if Restricted_Profile then
14116 -- If the stack has been preallocated by the expander then
14117 -- pass its address. Otherwise, pass a null address.
14119 if Preallocated_Stacks_On_Target then
14121 Make_Attribute_Reference (Loc,
14123 Make_Selected_Component (Loc,
14124 Prefix => Make_Identifier (Loc, Name_uInit),
14125 Selector_Name => Make_Identifier (Loc, Name_uStack)),
14126 Attribute_Name => Name_Address));
14130 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
14134 -- Size parameter. If no Storage_Size pragma is present, then
14135 -- the size is taken from the taskZ variable for the type, which
14136 -- is either Unspecified_Size, or has been reset by the use of
14137 -- a Storage_Size attribute definition clause. If a pragma is
14138 -- present, then the size is taken from the _Size field of the
14139 -- task value record, which was set from the pragma value.
14141 if Present (Tdef) and then Has_Storage_Size_Pragma (Tdef) then
14143 Make_Selected_Component (Loc,
14144 Prefix => Make_Identifier (Loc, Name_uInit),
14145 Selector_Name => Make_Identifier (Loc, Name_uSize)));
14149 New_Occurrence_Of (Storage_Size_Variable (Ttyp), Loc));
14152 -- Secondary_Stack_Size parameter. Set Default_Secondary_Stack_Size
14153 -- unless there is a Secondary_Stack_Size rep item, in which case we
14154 -- take the value from the rep item. If the restriction
14155 -- No_Secondary_Stack is active then a size of 0 is passed regardless
14156 -- to prevent the allocation of the unused stack.
14158 if Restriction_Active (No_Secondary_Stack) then
14159 Append_To (Args, Make_Integer_Literal (Loc, 0));
14162 (Ttyp, Name_Secondary_Stack_Size, Check_Parents => False)
14165 Make_Selected_Component (Loc,
14166 Prefix => Make_Identifier (Loc, Name_uInit),
14168 Make_Identifier (Loc, Name_uSecondary_Stack_Size)));
14172 New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
14175 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14176 -- Task_Info pragma, in which case we take the value from the pragma.
14178 if Has_Rep_Pragma (Ttyp, Name_Task_Info, Check_Parents => False) then
14180 Make_Selected_Component (Loc,
14181 Prefix => Make_Identifier (Loc, Name_uInit),
14182 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
14186 New_Occurrence_Of (RTE (RE_Unspecified_Task_Info), Loc));
14189 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14190 -- in which case we take the value from the rep item. The parameter is
14191 -- passed as an Integer because in the case of unspecified CPU the
14192 -- value is not in the range of CPU_Range.
14194 if Has_Rep_Item (Ttyp, Name_CPU, Check_Parents => False) then
14196 Convert_To (Standard_Integer,
14197 Make_Selected_Component (Loc,
14198 Prefix => Make_Identifier (Loc, Name_uInit),
14199 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
14202 New_Occurrence_Of (RTE (RE_Unspecified_CPU), Loc));
14205 if not Restricted_Profile then
14207 -- Deadline parameter. If no Relative_Deadline pragma is present,
14208 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14209 -- the deadline is taken from the _Relative_Deadline field of the
14210 -- task value record, which was set from the pragma value. Note that
14211 -- this parameter must not be generated for the restricted profiles
14212 -- since Ravenscar does not allow deadlines.
14214 -- Case where pragma Relative_Deadline applies: use given value
14216 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
14218 Make_Selected_Component (Loc,
14219 Prefix => Make_Identifier (Loc, Name_uInit),
14221 Make_Identifier (Loc, Name_uRelative_Deadline)));
14223 -- No pragma Relative_Deadline apply to the task
14227 New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc));
14230 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14231 -- present, then the dispatching domain is null. If a rep item is
14232 -- present, then the dispatching domain is taken from the
14233 -- _Dispatching_Domain field of the task value record, which was set
14234 -- from the rep item value.
14236 -- Case where Dispatching_Domain rep item applies: use given value
14239 (Ttyp, Name_Dispatching_Domain, Check_Parents => False)
14242 Make_Selected_Component (Loc,
14244 Make_Identifier (Loc, Name_uInit),
14246 Make_Identifier (Loc, Name_uDispatching_Domain)));
14248 -- No pragma or aspect Dispatching_Domain applies to the task
14251 Append_To (Args, Make_Null (Loc));
14254 -- Number of entries. This is an expression of the form:
14256 -- n + _Init.a'Length + _Init.a'B'Length + ...
14258 -- where a,b... are the entry family names for the task definition
14261 Build_Entry_Count_Expression
14266 (Parent (Corresponding_Record_Type (Ttyp))))),
14268 Append_To (Args, Ecount);
14270 -- Master parameter. This is a reference to the _Master parameter of
14271 -- the initialization procedure, except in the case of the pragma
14272 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14273 -- System.Tasking.Library_Task_Level.
14275 if Restriction_Active (No_Task_Hierarchy) = False then
14276 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
14279 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
14283 -- State parameter. This is a pointer to the task body procedure. The
14284 -- required value is obtained by taking 'Unrestricted_Access of the task
14285 -- body procedure and converting it (with an unchecked conversion) to
14286 -- the type required by the task kernel. For further details, see the
14287 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14288 -- than 'Address in order to avoid creating trampolines.
14291 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
14292 Subp_Ptr_Typ : constant Node_Id :=
14293 Create_Itype (E_Access_Subprogram_Type, Tdec);
14294 Ref : constant Node_Id := Make_Itype_Reference (Loc);
14297 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
14298 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
14300 -- Be sure to freeze a reference to the access-to-subprogram type,
14301 -- otherwise gigi will complain that it's in the wrong scope, because
14302 -- it's actually inside the init procedure for the record type that
14303 -- corresponds to the task type.
14305 Set_Itype (Ref, Subp_Ptr_Typ);
14306 Append_Freeze_Action (Task_Rec, Ref);
14309 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
14310 Make_Qualified_Expression (Loc,
14311 Subtype_Mark => New_Occurrence_Of (Subp_Ptr_Typ, Loc),
14313 Make_Attribute_Reference (Loc,
14314 Prefix => New_Occurrence_Of (Body_Proc, Loc),
14315 Attribute_Name => Name_Unrestricted_Access))));
14318 -- Discriminants parameter. This is just the address of the task
14319 -- value record itself (which contains the discriminant values
14322 Make_Attribute_Reference (Loc,
14323 Prefix => Make_Identifier (Loc, Name_uInit),
14324 Attribute_Name => Name_Address));
14326 -- Elaborated parameter. This is an access to the elaboration Boolean
14329 Make_Attribute_Reference (Loc,
14330 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
14331 Attribute_Name => Name_Unchecked_Access));
14333 -- Add Chain parameter (not done for sequential elaboration policy, see
14334 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14336 if Partition_Elaboration_Policy /= 'S' then
14337 Append_To (Args, Make_Identifier (Loc, Name_uChain));
14340 -- Task name parameter. Take this from the _Task_Id parameter to the
14341 -- init call unless there is a Task_Name pragma, in which case we take
14342 -- the value from the pragma.
14344 if Has_Rep_Pragma (Ttyp, Name_Task_Name, Check_Parents => False) then
14345 -- Copy expression in full, because it may be dynamic and have
14352 (Pragma_Argument_Associations
14354 (Ttyp, Name_Task_Name, Check_Parents => False))))));
14357 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
14360 -- Created_Task parameter. This is the _Task_Id field of the task
14364 Make_Selected_Component (Loc,
14365 Prefix => Make_Identifier (Loc, Name_uInit),
14366 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
14372 if Restricted_Profile then
14373 if Partition_Elaboration_Policy = 'S' then
14374 Create_RE := RE_Create_Restricted_Task_Sequential;
14376 Create_RE := RE_Create_Restricted_Task;
14379 Create_RE := RE_Create_Task;
14382 Name := New_Occurrence_Of (RTE (Create_RE), Loc);
14386 Make_Procedure_Call_Statement (Loc,
14388 Parameter_Associations => Args);
14389 end Make_Task_Create_Call;
14391 ------------------------------
14392 -- Next_Protected_Operation --
14393 ------------------------------
14395 function Next_Protected_Operation (N : Node_Id) return Node_Id is
14399 -- Check whether there is a subsequent body for a protected operation
14400 -- in the current protected body. In Ada2012 that includes expression
14401 -- functions that are completions.
14403 Next_Op := Next (N);
14404 while Present (Next_Op)
14405 and then not Nkind_In (Next_Op,
14406 N_Subprogram_Body, N_Entry_Body, N_Expression_Function)
14412 end Next_Protected_Operation;
14414 ---------------------
14415 -- Null_Statements --
14416 ---------------------
14418 function Null_Statements (Stats : List_Id) return Boolean is
14422 Stmt := First (Stats);
14423 while Nkind (Stmt) /= N_Empty
14424 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
14426 (Nkind (Stmt) = N_Pragma
14428 Nam_In (Pragma_Name_Unmapped (Stmt),
14436 return Nkind (Stmt) = N_Empty;
14437 end Null_Statements;
14439 --------------------------
14440 -- Parameter_Block_Pack --
14441 --------------------------
14443 function Parameter_Block_Pack
14445 Blk_Typ : Entity_Id;
14449 Stmts : List_Id) return Node_Id
14451 Actual : Entity_Id;
14452 Expr : Node_Id := Empty;
14453 Formal : Entity_Id;
14454 Has_Param : Boolean := False;
14457 Temp_Asn : Node_Id;
14458 Temp_Nam : Node_Id;
14461 Actual := First (Actuals);
14462 Formal := Defining_Identifier (First (Formals));
14463 Params := New_List;
14464 while Present (Actual) loop
14465 if Is_By_Copy_Type (Etype (Actual)) then
14467 -- Jnn : aliased <formal-type>
14469 Temp_Nam := Make_Temporary (Loc, 'J');
14472 Make_Object_Declaration (Loc,
14473 Aliased_Present => True,
14474 Defining_Identifier => Temp_Nam,
14475 Object_Definition =>
14476 New_Occurrence_Of (Etype (Formal), Loc)));
14478 if Ekind (Formal) /= E_Out_Parameter then
14484 New_Occurrence_Of (Temp_Nam, Loc);
14486 Set_Assignment_OK (Temp_Asn);
14489 Make_Assignment_Statement (Loc,
14491 Expression => New_Copy_Tree (Actual)));
14495 -- Jnn'unchecked_access
14498 Make_Attribute_Reference (Loc,
14499 Attribute_Name => Name_Unchecked_Access,
14500 Prefix => New_Occurrence_Of (Temp_Nam, Loc)));
14504 -- The controlling parameter is omitted
14507 if not Is_Controlling_Actual (Actual) then
14509 Make_Reference (Loc, New_Copy_Tree (Actual)));
14515 Next_Actual (Actual);
14516 Next_Formal_With_Extras (Formal);
14520 Expr := Make_Aggregate (Loc, Params);
14525 -- J1'unchecked_access;
14526 -- <actual2>'reference;
14529 P := Make_Temporary (Loc, 'P');
14532 Make_Object_Declaration (Loc,
14533 Defining_Identifier => P,
14534 Object_Definition => New_Occurrence_Of (Blk_Typ, Loc),
14535 Expression => Expr));
14538 end Parameter_Block_Pack;
14540 ----------------------------
14541 -- Parameter_Block_Unpack --
14542 ----------------------------
14544 function Parameter_Block_Unpack
14548 Formals : List_Id) return List_Id
14550 Actual : Entity_Id;
14552 Formal : Entity_Id;
14553 Has_Asnmt : Boolean := False;
14554 Result : constant List_Id := New_List;
14557 Actual := First (Actuals);
14558 Formal := Defining_Identifier (First (Formals));
14559 while Present (Actual) loop
14560 if Is_By_Copy_Type (Etype (Actual))
14561 and then Ekind (Formal) /= E_In_Parameter
14564 -- <actual> := P.<formal>;
14567 Make_Assignment_Statement (Loc,
14571 Make_Explicit_Dereference (Loc,
14572 Make_Selected_Component (Loc,
14574 New_Occurrence_Of (P, Loc),
14576 Make_Identifier (Loc, Chars (Formal)))));
14578 Set_Assignment_OK (Name (Asnmt));
14579 Append_To (Result, Asnmt);
14584 Next_Actual (Actual);
14585 Next_Formal_With_Extras (Formal);
14591 return New_List (Make_Null_Statement (Loc));
14593 end Parameter_Block_Unpack;
14595 ----------------------
14596 -- Set_Discriminals --
14597 ----------------------
14599 procedure Set_Discriminals (Dec : Node_Id) is
14602 D_Minal : Entity_Id;
14605 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
14606 Pdef := Defining_Identifier (Dec);
14608 if Has_Discriminants (Pdef) then
14609 D := First_Discriminant (Pdef);
14610 while Present (D) loop
14612 Make_Defining_Identifier (Sloc (D),
14613 Chars => New_External_Name (Chars (D), 'D'));
14615 Set_Ekind (D_Minal, E_Constant);
14616 Set_Etype (D_Minal, Etype (D));
14617 Set_Scope (D_Minal, Pdef);
14618 Set_Discriminal (D, D_Minal);
14619 Set_Discriminal_Link (D_Minal, D);
14621 Next_Discriminant (D);
14624 end Set_Discriminals;
14626 -----------------------
14627 -- Trivial_Accept_OK --
14628 -----------------------
14630 function Trivial_Accept_OK return Boolean is
14632 case Opt.Task_Dispatching_Policy is
14634 -- If we have the default task dispatching policy in effect, we can
14635 -- definitely do the optimization (one way of looking at this is to
14636 -- think of the formal definition of the default policy being allowed
14637 -- to run any task it likes after a rendezvous, so even if notionally
14638 -- a full rescheduling occurs, we can say that our dispatching policy
14639 -- (i.e. the default dispatching policy) reorders the queue to be the
14640 -- same as just before the call.
14645 -- FIFO_Within_Priorities certainly does not permit this
14646 -- optimization since the Rendezvous is a scheduling action that may
14647 -- require some other task to be run.
14652 -- For now, disallow the optimization for all other policies. This
14653 -- may be over-conservative, but it is certainly not incorrect.
14658 end Trivial_Accept_OK;