1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Ch3; use Exp_Ch3;
32 with Exp_Ch6; use Exp_Ch6;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Dbug; use Exp_Dbug;
35 with Exp_Disp; use Exp_Disp;
36 with Exp_Sel; use Exp_Sel;
37 with Exp_Smem; use Exp_Smem;
38 with Exp_Tss; use Exp_Tss;
39 with Exp_Util; use Exp_Util;
40 with Freeze; use Freeze;
42 with Itypes; use Itypes;
43 with Namet; use Namet;
44 with Nlists; use Nlists;
45 with Nmake; use Nmake;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aux; use Sem_Aux;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Ch9; use Sem_Ch9;
55 with Sem_Ch11; use Sem_Ch11;
56 with Sem_Elab; use Sem_Elab;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Res; use Sem_Res;
59 with Sem_Util; use Sem_Util;
60 with Sinfo; use Sinfo;
61 with Snames; use Snames;
62 with Stand; use Stand;
63 with Stringt; use Stringt;
64 with Targparm; use Targparm;
65 with Tbuild; use Tbuild;
66 with Uintp; use Uintp;
68 package body Exp_Ch9 is
70 -- The following constant establishes the upper bound for the index of
71 -- an entry family. It is used to limit the allocated size of protected
72 -- types with defaulted discriminant of an integer type, when the bound
73 -- of some entry family depends on a discriminant. The limitation to entry
74 -- families of 128K should be reasonable in all cases, and is a documented
75 -- implementation restriction.
77 Entry_Family_Bound : constant Int := 2**16;
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 function Actual_Index_Expression
87 Tsk : Entity_Id) return Node_Id;
88 -- Compute the index position for an entry call. Tsk is the target task. If
89 -- the bounds of some entry family depend on discriminants, the expression
90 -- computed by this function uses the discriminants of the target task.
92 procedure Add_Object_Pointer
96 -- Prepend an object pointer declaration to the declaration list Decls.
97 -- This object pointer is initialized to a type conversion of the System.
98 -- Address pointer passed to entry barrier functions and entry body
101 procedure Add_Formal_Renamings
106 -- Create renaming declarations for the formals, inside the procedure that
107 -- implements an entry body. The renamings make the original names of the
108 -- formals accessible to gdb, and serve no other purpose.
109 -- Spec is the specification of the procedure being built.
110 -- Decls is the list of declarations to be enhanced.
111 -- Ent is the entity for the original entry body.
113 function Build_Accept_Body (Astat : Node_Id) return Node_Id;
114 -- Transform accept statement into a block with added exception handler.
115 -- Used both for simple accept statements and for accept alternatives in
116 -- select statements. Astat is the accept statement.
118 function Build_Barrier_Function
121 Pid : Node_Id) return Node_Id;
122 -- Build the function body returning the value of the barrier expression
123 -- for the specified entry body.
125 function Build_Barrier_Function_Specification
127 Def_Id : Entity_Id) return Node_Id;
128 -- Build a specification for a function implementing the protected entry
129 -- barrier of the specified entry body.
131 function Build_Corresponding_Record
134 Loc : Source_Ptr) return Node_Id;
135 -- Common to tasks and protected types. Copy discriminant specifications,
136 -- build record declaration. N is the type declaration, Ctyp is the
137 -- concurrent entity (task type or protected type).
139 function Build_Dispatching_Tag_Check
141 N : Node_Id) return Node_Id;
142 -- Utility to create the tree to check whether the dispatching call in
143 -- a timed entry call, a conditional entry call, or an asynchronous
144 -- transfer of control is a call to a primitive of a non-synchronized type.
145 -- K is the temporary that holds the tagged kind of the target object, and
146 -- N is the enclosing construct.
148 function Build_Entry_Count_Expression
149 (Concurrent_Type : Node_Id;
150 Component_List : List_Id;
151 Loc : Source_Ptr) return Node_Id;
152 -- Compute number of entries for concurrent object. This is a count of
153 -- simple entries, followed by an expression that computes the length
154 -- of the range of each entry family. A single array with that size is
155 -- allocated for each concurrent object of the type.
157 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id;
158 -- Build the function that translates the entry index in the call
159 -- (which depends on the size of entry families) into an index into the
160 -- Entry_Bodies_Array, to determine the body and barrier function used
161 -- in a protected entry call. A pointer to this function appears in every
164 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id;
165 -- Build subprogram declaration for previous one
167 function Build_Lock_Free_Protected_Subprogram_Body
170 Unprot_Spec : Node_Id) return Node_Id;
171 -- N denotes a subprogram body of protected type Prot_Typ. Unprot_Spec is
172 -- the subprogram specification of the unprotected version of N. Transform
173 -- N such that it invokes the unprotected version of the body.
175 function Build_Lock_Free_Unprotected_Subprogram_Body
177 Prot_Typ : Node_Id) return Node_Id;
178 -- N denotes a subprogram body of protected type Prot_Typ. Build a version
179 -- of N where the original statements of N are synchronized through atomic
180 -- actions such as compare and exchange. Prior to invoking this routine, it
181 -- has been established that N can be implemented in a lock-free fashion.
183 function Build_Parameter_Block
187 Decls : List_Id) return Entity_Id;
188 -- Generate an access type for each actual parameter in the list Actuals.
189 -- Create an encapsulating record that contains all the actuals and return
190 -- its type. Generate:
191 -- type Ann1 is access all <actual1-type>
193 -- type AnnN is access all <actualN-type>
194 -- type Pnn is record
200 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id);
201 -- Build body of wrapper procedure for an entry or entry family that has
202 -- pre/postconditions. The body gathers the PPC's and expands them in the
203 -- usual way, and performs the entry call itself. This way preconditions
204 -- are evaluated before the call is queued. E is the entry in question,
205 -- and Decl is the enclosing synchronized type declaration at whose freeze
206 -- point the generated body is analyzed.
208 function Build_Protected_Entry
211 Pid : Node_Id) return Node_Id;
212 -- Build the procedure implementing the statement sequence of the specified
215 function Build_Protected_Entry_Specification
218 Ent_Id : Entity_Id) return Node_Id;
219 -- Build a specification for the procedure implementing the statements of
220 -- the specified entry body. Add attributes associating it with the entry
221 -- defining identifier Ent_Id.
223 function Build_Protected_Spec
225 Obj_Type : Entity_Id;
227 Unprotected : Boolean := False) return List_Id;
228 -- Utility shared by Build_Protected_Sub_Spec and Expand_Access_Protected_
229 -- Subprogram_Type. Builds signature of protected subprogram, adding the
230 -- formal that corresponds to the object itself. For an access to protected
231 -- subprogram, there is no object type to specify, so the parameter has
232 -- type Address and mode In. An indirect call through such a pointer will
233 -- convert the address to a reference to the actual object. The object is
234 -- a limited record and therefore a by_reference type.
236 function Build_Protected_Subprogram_Body
239 N_Op_Spec : Node_Id) return Node_Id;
240 -- This function is used to construct the protected version of a protected
241 -- subprogram. Its statement sequence first defers abort, then locks the
242 -- associated protected object, and then enters a block that contains a
243 -- call to the unprotected version of the subprogram (for details, see
244 -- Build_Unprotected_Subprogram_Body). This block statement requires a
245 -- cleanup handler that unlocks the object in all cases. For details,
246 -- see Exp_Ch7.Expand_Cleanup_Actions.
248 function Build_Renamed_Formal_Declaration
252 Renamed_Formal : Node_Id) return Node_Id;
253 -- Create a renaming declaration for a formal, within a protected entry
254 -- body or an accept body. The renamed object is a component of the
255 -- parameter block that is a parameter in the entry call.
257 -- In Ada 2012, if the formal is an incomplete tagged type, the renaming
258 -- does not dereference the corresponding component to prevent an illegal
259 -- use of the incomplete type (AI05-0151).
261 function Build_Selected_Name
263 Selector : Entity_Id;
264 Append_Char : Character := ' ') return Name_Id;
265 -- Build a name in the form of Prefix__Selector, with an optional character
266 -- appended. This is used for internal subprograms generated for operations
267 -- of protected types, including barrier functions. For the subprograms
268 -- generated for entry bodies and entry barriers, the generated name
269 -- includes a sequence number that makes names unique in the presence of
270 -- entry overloading. This is necessary because entry body procedures and
271 -- barrier functions all have the same signature.
273 procedure Build_Simple_Entry_Call
278 -- Some comments here would be useful ???
280 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id;
281 -- This routine constructs a specification for the procedure that we will
282 -- build for the task body for task type T. The spec has the form:
284 -- procedure tnameB (_Task : access tnameV);
286 -- where name is the character name taken from the task type entity that
287 -- is passed as the argument to the procedure, and tnameV is the task
288 -- value type that is associated with the task type.
290 function Build_Unprotected_Subprogram_Body
292 Pid : Node_Id) return Node_Id;
293 -- This routine constructs the unprotected version of a protected
294 -- subprogram body, which is contains all of the code in the original,
295 -- unexpanded body. This is the version of the protected subprogram that is
296 -- called from all protected operations on the same object, including the
297 -- protected version of the same subprogram.
299 procedure Build_Wrapper_Bodies
303 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
304 -- record of a concurrent type. N is the insertion node where all bodies
305 -- will be placed. This routine builds the bodies of the subprograms which
306 -- serve as an indirection mechanism to overriding primitives of concurrent
307 -- types, entries and protected procedures. Any new body is analyzed.
309 procedure Build_Wrapper_Specs
313 -- Ada 2005 (AI-345): Typ is either a concurrent type or the corresponding
314 -- record of a concurrent type. N is the insertion node where all specs
315 -- will be placed. This routine builds the specs of the subprograms which
316 -- serve as an indirection mechanism to overriding primitives of concurrent
317 -- types, entries and protected procedures. Any new spec is analyzed.
319 procedure Collect_Entry_Families
322 Current_Node : in out Node_Id;
323 Conctyp : Entity_Id);
324 -- For each entry family in a concurrent type, create an anonymous array
325 -- type of the right size, and add a component to the corresponding_record.
327 function Concurrent_Object
328 (Spec_Id : Entity_Id;
329 Conc_Typ : Entity_Id) return Entity_Id;
330 -- Given a subprogram entity Spec_Id and concurrent type Conc_Typ, return
331 -- the entity associated with the concurrent object in the Protected_Body_
332 -- Subprogram or the Task_Body_Procedure of Spec_Id. The returned entity
333 -- denotes formal parameter _O, _object or _task.
335 function Copy_Result_Type (Res : Node_Id) return Node_Id;
336 -- Copy the result type of a function specification, when building the
337 -- internal operation corresponding to a protected function, or when
338 -- expanding an access to protected function. If the result is an anonymous
339 -- access to subprogram itself, we need to create a new signature with the
340 -- same parameter names and the same resolved types, but with new entities
343 procedure Debug_Private_Data_Declarations (Decls : List_Id);
344 -- Decls is a list which may contain the declarations created by Install_
345 -- Private_Data_Declarations. All generated entities are marked as needing
346 -- debug info and debug nodes are manually generation where necessary. This
347 -- step of the expansion must to be done after private data has been moved
348 -- to its final resting scope to ensure proper visibility of debug objects.
350 procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id);
351 -- If control flow optimizations are suppressed, and Alt is an accept,
352 -- delay, or entry call alternative with no trailing statements, insert
353 -- a null trailing statement with the given Loc (which is the sloc of
354 -- the accept, delay, or entry call statement). There might not be any
355 -- generated code for the accept, delay, or entry call itself (the effect
356 -- of these statements is part of the general processsing done for the
357 -- enclosing selective accept, timed entry call, or asynchronous select),
358 -- and the null statement is there to carry the sloc of that statement to
359 -- the back-end for trace-based coverage analysis purposes.
361 procedure Extract_Dispatching_Call
363 Call_Ent : out Entity_Id;
364 Object : out Entity_Id;
365 Actuals : out List_Id;
366 Formals : out List_Id);
367 -- Given a dispatching call, extract the entity of the name of the call,
368 -- its actual dispatching object, its actual parameters and the formal
369 -- parameters of the overridden interface-level version. If the type of
370 -- the dispatching object is an access type then an explicit dereference
371 -- is returned in Object.
373 procedure Extract_Entry
375 Concval : out Node_Id;
377 Index : out Node_Id);
378 -- Given an entry call, returns the associated concurrent object, the entry
379 -- name, and the entry family index.
381 function Family_Offset
386 Cap : Boolean) return Node_Id;
387 -- Compute (Hi - Lo) for two entry family indexes. Hi is the index in an
388 -- accept statement, or the upper bound in the discrete subtype of an entry
389 -- declaration. Lo is the corresponding lower bound. Ttyp is the concurrent
390 -- type of the entry. If Cap is true, the result is capped according to
391 -- Entry_Family_Bound.
398 Cap : Boolean) return Node_Id;
399 -- Compute (Hi - Lo) + 1 Max 0, to determine the number of entries in a
400 -- family, and handle properly the superflat case. This is equivalent to
401 -- the use of 'Length on the index type, but must use Family_Offset to
402 -- handle properly the case of bounds that depend on discriminants. If
403 -- Cap is true, the result is capped according to Entry_Family_Bound.
405 procedure Find_Enclosing_Context
407 Context : out Node_Id;
408 Context_Id : out Entity_Id;
409 Context_Decls : out List_Id);
410 -- Subsidiary routine to procedures Build_Activation_Chain_Entity and
411 -- Build_Master_Entity. Given an arbitrary node in the tree, find the
412 -- nearest enclosing body, block, package or return statement and return
413 -- its constituents. Context is the enclosing construct, Context_Id is
414 -- the scope of Context_Id and Context_Decls is the declarative list of
417 function Index_Object (Spec_Id : Entity_Id) return Entity_Id;
418 -- Given a subprogram identifier, return the entity which is associated
419 -- with the protection entry index in the Protected_Body_Subprogram or
420 -- the Task_Body_Procedure of Spec_Id. The returned entity denotes formal
423 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean;
424 -- Tell whether a given subprogram cannot raise an exception
426 function Is_Potentially_Large_Family
427 (Base_Index : Entity_Id;
430 Hi : Node_Id) return Boolean;
432 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean;
433 -- Determine whether Id is a function or a procedure and is marked as a
434 -- private primitive.
436 function Null_Statements (Stats : List_Id) return Boolean;
437 -- Used to check DO-END sequence. Checks for equivalent of DO NULL; END.
438 -- Allows labels, and pragma Warnings/Unreferenced in the sequence as well
439 -- to still count as null. Returns True for a null sequence. The argument
440 -- is the list of statements from the DO-END sequence.
442 function Parameter_Block_Pack
448 Stmts : List_Id) return Entity_Id;
449 -- Set the components of the generated parameter block with the values
450 -- of the actual parameters. Generate aliased temporaries to capture the
451 -- values for types that are passed by copy. Otherwise generate a reference
452 -- to the actual's value. Return the address of the aggregate block.
454 -- Jnn1 : alias <formal-type1>;
455 -- Jnn1 := <actual1>;
458 -- Jnn1'unchecked_access;
459 -- <actual2>'reference;
462 function Parameter_Block_Unpack
466 Formals : List_Id) return List_Id;
467 -- Retrieve the values of the components from the parameter block and
468 -- assign then to the original actual parameters. Generate:
469 -- <actual1> := P.<formal1>;
471 -- <actualN> := P.<formalN>;
473 function Trivial_Accept_OK return Boolean;
474 -- If there is no DO-END block for an accept, or if the DO-END block has
475 -- only null statements, then it is possible to do the Rendezvous with much
476 -- less overhead using the Accept_Trivial routine in the run-time library.
477 -- However, this is not always a valid optimization. Whether it is valid or
478 -- not depends on the Task_Dispatching_Policy. The issue is whether a full
479 -- rescheduling action is required or not. In FIFO_Within_Priorities, such
480 -- a rescheduling is required, so this optimization is not allowed. This
481 -- function returns True if the optimization is permitted.
483 -----------------------------
484 -- Actual_Index_Expression --
485 -----------------------------
487 function Actual_Index_Expression
491 Tsk : Entity_Id) return Node_Id
493 Ttyp : constant Entity_Id := Etype (Tsk);
501 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id;
502 -- Compute difference between bounds of entry family
504 --------------------------
505 -- Actual_Family_Offset --
506 --------------------------
508 function Actual_Family_Offset (Hi, Lo : Node_Id) return Node_Id is
510 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
511 -- Replace a reference to a discriminant with a selected component
512 -- denoting the discriminant of the target task.
514 -----------------------------
515 -- Actual_Discriminant_Ref --
516 -----------------------------
518 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
519 Typ : constant Entity_Id := Etype (Bound);
523 if not Is_Entity_Name (Bound)
524 or else Ekind (Entity (Bound)) /= E_Discriminant
526 if Nkind (Bound) = N_Attribute_Reference then
529 B := New_Copy_Tree (Bound);
534 Make_Selected_Component (Sloc,
535 Prefix => New_Copy_Tree (Tsk),
536 Selector_Name => New_Occurrence_Of (Entity (Bound), Sloc));
538 Analyze_And_Resolve (B, Typ);
542 Make_Attribute_Reference (Sloc,
543 Attribute_Name => Name_Pos,
544 Prefix => New_Occurrence_Of (Etype (Bound), Sloc),
545 Expressions => New_List (B));
546 end Actual_Discriminant_Ref;
548 -- Start of processing for Actual_Family_Offset
552 Make_Op_Subtract (Sloc,
553 Left_Opnd => Actual_Discriminant_Ref (Hi),
554 Right_Opnd => Actual_Discriminant_Ref (Lo));
555 end Actual_Family_Offset;
557 -- Start of processing for Actual_Index_Expression
560 -- The queues of entries and entry families appear in textual order in
561 -- the associated record. The entry index is computed as the sum of the
562 -- number of queues for all entries that precede the designated one, to
563 -- which is added the index expression, if this expression denotes a
564 -- member of a family.
566 -- The following is a place holder for the count of simple entries
568 Num := Make_Integer_Literal (Sloc, 1);
570 -- We construct an expression which is a series of addition operations.
571 -- See comments in Entry_Index_Expression, which is identical in
574 if Present (Index) then
575 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
581 Actual_Family_Offset (
582 Make_Attribute_Reference (Sloc,
583 Attribute_Name => Name_Pos,
584 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
585 Expressions => New_List (Relocate_Node (Index))),
586 Type_Low_Bound (S)));
591 -- Now add lengths of preceding entries and entry families
593 Prev := First_Entity (Ttyp);
594 while Chars (Prev) /= Chars (Ent)
595 or else (Ekind (Prev) /= Ekind (Ent))
596 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
598 if Ekind (Prev) = E_Entry then
599 Set_Intval (Num, Intval (Num) + 1);
601 elsif Ekind (Prev) = E_Entry_Family then
603 Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
605 -- The need for the following full view retrieval stems from this
606 -- complex case of nested generics and tasking:
609 -- type Formal_Index is range <>;
612 -- type Index is private;
619 -- type Index is new Formal_Index range 1 .. 10;
622 -- package body Outer is
624 -- entry Fam (Index); -- (2)
627 -- package body Inner is -- (3)
635 -- We are currently building the index expression for the entry
636 -- call "T.E" (1). Part of the expansion must mention the range
637 -- of the discrete type "Index" (2) of entry family "Fam".
639 -- However only the private view of type "Index" is available to
640 -- the inner generic (3) because there was no prior mention of
641 -- the type inside "Inner". This visibility requirement is
642 -- implicit and cannot be detected during the construction of
643 -- the generic trees and needs special handling.
646 and then Is_Private_Type (S)
647 and then Present (Full_View (S))
652 Lo := Type_Low_Bound (S);
653 Hi := Type_High_Bound (S);
660 Left_Opnd => Actual_Family_Offset (Hi, Lo),
661 Right_Opnd => Make_Integer_Literal (Sloc, 1)));
663 -- Other components are anonymous types to be ignored
673 end Actual_Index_Expression;
675 --------------------------
676 -- Add_Formal_Renamings --
677 --------------------------
679 procedure Add_Formal_Renamings
685 Ptr : constant Entity_Id :=
687 (Next (First (Parameter_Specifications (Spec))));
688 -- The name of the formal that holds the address of the parameter block
695 Renamed_Formal : Node_Id;
698 Formal := First_Formal (Ent);
699 while Present (Formal) loop
700 Comp := Entry_Component (Formal);
702 Make_Defining_Identifier (Sloc (Formal),
703 Chars => Chars (Formal));
704 Set_Etype (New_F, Etype (Formal));
705 Set_Scope (New_F, Ent);
707 -- Now we set debug info needed on New_F even though it does not come
708 -- from source, so that the debugger will get the right information
709 -- for these generated names.
711 Set_Debug_Info_Needed (New_F);
713 if Ekind (Formal) = E_In_Parameter then
714 Set_Ekind (New_F, E_Constant);
716 Set_Ekind (New_F, E_Variable);
717 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
720 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
723 Make_Selected_Component (Loc,
725 Unchecked_Convert_To (Entry_Parameters_Type (Ent),
726 Make_Identifier (Loc, Chars (Ptr))),
727 Selector_Name => New_Occurrence_Of (Comp, Loc));
730 Build_Renamed_Formal_Declaration
731 (New_F, Formal, Comp, Renamed_Formal);
733 Append (Decl, Decls);
734 Set_Renamed_Object (Formal, New_F);
735 Next_Formal (Formal);
737 end Add_Formal_Renamings;
739 ------------------------
740 -- Add_Object_Pointer --
741 ------------------------
743 procedure Add_Object_Pointer
745 Conc_Typ : Entity_Id;
748 Rec_Typ : constant Entity_Id := Corresponding_Record_Type (Conc_Typ);
753 -- Create the renaming declaration for the Protection object of a
754 -- protected type. _Object is used by Complete_Entry_Body.
755 -- ??? An attempt to make this a renaming was unsuccessful.
757 -- Build the entity for the access type
760 Make_Defining_Identifier (Loc,
761 New_External_Name (Chars (Rec_Typ), 'P'));
764 -- _object : poVP := poVP!O;
767 Make_Object_Declaration (Loc,
768 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uObject),
769 Object_Definition => New_Occurrence_Of (Obj_Ptr, Loc),
771 Unchecked_Convert_To (Obj_Ptr, Make_Identifier (Loc, Name_uO)));
772 Set_Debug_Info_Needed (Defining_Identifier (Decl));
773 Prepend_To (Decls, Decl);
776 -- type poVP is access poV;
779 Make_Full_Type_Declaration (Loc,
780 Defining_Identifier =>
783 Make_Access_To_Object_Definition (Loc,
784 Subtype_Indication =>
785 New_Occurrence_Of (Rec_Typ, Loc)));
786 Set_Debug_Info_Needed (Defining_Identifier (Decl));
787 Prepend_To (Decls, Decl);
788 end Add_Object_Pointer;
790 -----------------------
791 -- Build_Accept_Body --
792 -----------------------
794 function Build_Accept_Body (Astat : Node_Id) return Node_Id is
795 Loc : constant Source_Ptr := Sloc (Astat);
796 Stats : constant Node_Id := Handled_Statement_Sequence (Astat);
803 -- At the end of the statement sequence, Complete_Rendezvous is called.
804 -- A label skipping the Complete_Rendezvous, and all other accept
805 -- processing, has already been added for the expansion of requeue
806 -- statements. The Sloc is copied from the last statement since it
807 -- is really part of this last statement.
811 (Sloc (Last (Statements (Stats))), RE_Complete_Rendezvous);
812 Insert_Before (Last (Statements (Stats)), Call);
815 -- If exception handlers are present, then append Complete_Rendezvous
816 -- calls to the handlers, and construct the required outer block. As
817 -- above, the Sloc is copied from the last statement in the sequence.
819 if Present (Exception_Handlers (Stats)) then
820 Hand := First (Exception_Handlers (Stats));
821 while Present (Hand) loop
824 (Sloc (Last (Statements (Hand))), RE_Complete_Rendezvous);
825 Append (Call, Statements (Hand));
831 Make_Handled_Sequence_Of_Statements (Loc,
832 Statements => New_List (
833 Make_Block_Statement (Loc,
834 Handled_Statement_Sequence => Stats)));
840 -- At this stage we know that the new statement sequence does
841 -- not have an exception handler part, so we supply one to call
842 -- Exceptional_Complete_Rendezvous. This handler is
844 -- when all others =>
845 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
847 -- We handle Abort_Signal to make sure that we properly catch the abort
848 -- case and wake up the caller.
850 Ohandle := Make_Others_Choice (Loc);
851 Set_All_Others (Ohandle);
853 Set_Exception_Handlers (New_S,
855 Make_Implicit_Exception_Handler (Loc,
856 Exception_Choices => New_List (Ohandle),
858 Statements => New_List (
859 Make_Procedure_Call_Statement (Sloc (Stats),
860 Name => New_Occurrence_Of (
861 RTE (RE_Exceptional_Complete_Rendezvous), Sloc (Stats)),
862 Parameter_Associations => New_List (
863 Make_Function_Call (Sloc (Stats),
866 (RTE (RE_Get_GNAT_Exception), Sloc (Stats)))))))));
868 Set_Parent (New_S, Astat); -- temp parent for Analyze call
869 Analyze_Exception_Handlers (Exception_Handlers (New_S));
870 Expand_Exception_Handlers (New_S);
872 -- Exceptional_Complete_Rendezvous must be called with abort still
873 -- deferred, which is the case for a "when all others" handler.
876 end Build_Accept_Body;
878 -----------------------------------
879 -- Build_Activation_Chain_Entity --
880 -----------------------------------
882 procedure Build_Activation_Chain_Entity (N : Node_Id) is
883 function Has_Activation_Chain (Stmt : Node_Id) return Boolean;
884 -- Determine whether an extended return statement has activation chain
886 --------------------------
887 -- Has_Activation_Chain --
888 --------------------------
890 function Has_Activation_Chain (Stmt : Node_Id) return Boolean is
894 Decl := First (Return_Object_Declarations (Stmt));
895 while Present (Decl) loop
896 if Nkind (Decl) = N_Object_Declaration
897 and then Chars (Defining_Identifier (Decl)) = Name_uChain
906 end Has_Activation_Chain;
911 Context_Id : Entity_Id;
914 -- Start of processing for Build_Activation_Chain_Entity
917 -- Activation chain is never used for sequential elaboration policy, see
918 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
920 if Partition_Elaboration_Policy = 'S' then
924 Find_Enclosing_Context (N, Context, Context_Id, Decls);
926 -- If activation chain entity has not been declared already, create one
928 if Nkind (Context) = N_Extended_Return_Statement
929 or else No (Activation_Chain_Entity (Context))
931 -- Since extended return statements do not store the entity of the
932 -- chain, examine the return object declarations to avoid creating
935 if Nkind (Context) = N_Extended_Return_Statement
936 and then Has_Activation_Chain (Context)
942 Loc : constant Source_Ptr := Sloc (Context);
947 Chain := Make_Defining_Identifier (Sloc (N), Name_uChain);
949 -- Note: An extended return statement is not really a task
950 -- activator, but it does have an activation chain on which to
951 -- store the tasks temporarily. On successful return, the tasks
952 -- on this chain are moved to the chain passed in by the caller.
953 -- We do not build an Activation_Chain_Entity for an extended
954 -- return statement, because we do not want to build a call to
955 -- Activate_Tasks. Task activation is the responsibility of the
958 if Nkind (Context) /= N_Extended_Return_Statement then
959 Set_Activation_Chain_Entity (Context, Chain);
963 Make_Object_Declaration (Loc,
964 Defining_Identifier => Chain,
965 Aliased_Present => True,
967 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc));
969 Prepend_To (Decls, Decl);
971 -- Ensure that _chain appears in the proper scope of the context
973 if Context_Id /= Current_Scope then
974 Push_Scope (Context_Id);
982 end Build_Activation_Chain_Entity;
984 ----------------------------
985 -- Build_Barrier_Function --
986 ----------------------------
988 function Build_Barrier_Function
991 Pid : Node_Id) return Node_Id
993 Ent_Formals : constant Node_Id := Entry_Body_Formal_Part (N);
994 Cond : constant Node_Id := Condition (Ent_Formals);
995 Loc : constant Source_Ptr := Sloc (Cond);
996 Func_Id : constant Entity_Id := Barrier_Function (Ent);
997 Op_Decls : constant List_Id := New_List;
1002 -- Add a declaration for the Protection object, renaming declarations
1003 -- for the discriminals and privals and finally a declaration for the
1004 -- entry family index (if applicable).
1006 Install_Private_Data_Declarations (Sloc (N),
1012 Family => Ekind (Ent) = E_Entry_Family);
1014 -- If compiling with -fpreserve-control-flow, make sure we insert an
1015 -- IF statement so that the back-end knows to generate a conditional
1016 -- branch instruction, even if the condition is just the name of a
1017 -- boolean object. Note that Expand_N_If_Statement knows to preserve
1018 -- such redundant IF statements under -fpreserve-control-flow
1019 -- (whether coming from this routine, or directly from source).
1021 if Opt.Suppress_Control_Flow_Optimizations then
1022 Stmt := Make_Implicit_If_Statement (Cond,
1024 Then_Statements => New_List (
1025 Make_Simple_Return_Statement (Loc,
1026 New_Occurrence_Of (Standard_True, Loc))),
1027 Else_Statements => New_List (
1028 Make_Simple_Return_Statement (Loc,
1029 New_Occurrence_Of (Standard_False, Loc))));
1032 Stmt := Make_Simple_Return_Statement (Loc, Cond);
1035 -- Note: the condition in the barrier function needs to be properly
1036 -- processed for the C/Fortran boolean possibility, but this happens
1037 -- automatically since the return statement does this normalization.
1040 Make_Subprogram_Body (Loc,
1042 Build_Barrier_Function_Specification (Loc,
1043 Make_Defining_Identifier (Loc, Chars (Func_Id))),
1044 Declarations => Op_Decls,
1045 Handled_Statement_Sequence =>
1046 Make_Handled_Sequence_Of_Statements (Loc,
1047 Statements => New_List (Stmt)));
1048 Set_Is_Entry_Barrier_Function (Func_Body);
1051 end Build_Barrier_Function;
1053 ------------------------------------------
1054 -- Build_Barrier_Function_Specification --
1055 ------------------------------------------
1057 function Build_Barrier_Function_Specification
1059 Def_Id : Entity_Id) return Node_Id
1062 Set_Debug_Info_Needed (Def_Id);
1064 return Make_Function_Specification (Loc,
1065 Defining_Unit_Name => Def_Id,
1066 Parameter_Specifications => New_List (
1067 Make_Parameter_Specification (Loc,
1068 Defining_Identifier =>
1069 Make_Defining_Identifier (Loc, Name_uO),
1071 New_Occurrence_Of (RTE (RE_Address), Loc)),
1073 Make_Parameter_Specification (Loc,
1074 Defining_Identifier =>
1075 Make_Defining_Identifier (Loc, Name_uE),
1077 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
1079 Result_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
1080 end Build_Barrier_Function_Specification;
1082 --------------------------
1083 -- Build_Call_With_Task --
1084 --------------------------
1086 function Build_Call_With_Task
1088 E : Entity_Id) return Node_Id
1090 Loc : constant Source_Ptr := Sloc (N);
1093 Make_Function_Call (Loc,
1094 Name => New_Occurrence_Of (E, Loc),
1095 Parameter_Associations => New_List (Concurrent_Ref (N)));
1096 end Build_Call_With_Task;
1098 -----------------------------
1099 -- Build_Class_Wide_Master --
1100 -----------------------------
1102 procedure Build_Class_Wide_Master (Typ : Entity_Id) is
1103 Loc : constant Source_Ptr := Sloc (Typ);
1104 Master_Id : Entity_Id;
1105 Master_Scope : Entity_Id;
1107 Related_Node : Node_Id;
1111 -- Nothing to do if there is no task hierarchy
1113 if Restriction_Active (No_Task_Hierarchy) then
1117 -- Find the declaration that created the access type, which is either a
1118 -- type declaration, or an object declaration with an access definition,
1119 -- in which case the type is anonymous.
1121 if Is_Itype (Typ) then
1122 Related_Node := Associated_Node_For_Itype (Typ);
1124 Related_Node := Parent (Typ);
1127 Master_Scope := Find_Master_Scope (Typ);
1129 -- Nothing to do if the master scope already contains a _master entity.
1130 -- The only exception to this is the following scenario:
1133 -- Transient_Scope_1
1136 -- Transient_Scope_2
1139 -- In this case the source scope is marked as having the master entity
1140 -- even though the actual declaration appears inside an inner scope. If
1141 -- the second transient scope requires a _master, it cannot use the one
1142 -- already declared because the entity is not visible.
1144 Name_Id := Make_Identifier (Loc, Name_uMaster);
1146 if not Has_Master_Entity (Master_Scope)
1147 or else No (Current_Entity_In_Scope (Name_Id))
1150 Master_Decl : Node_Id;
1152 Set_Has_Master_Entity (Master_Scope);
1155 -- _master : constant Integer := Current_Master.all;
1158 Make_Object_Declaration (Loc,
1159 Defining_Identifier =>
1160 Make_Defining_Identifier (Loc, Name_uMaster),
1161 Constant_Present => True,
1162 Object_Definition =>
1163 New_Occurrence_Of (Standard_Integer, Loc),
1165 Make_Explicit_Dereference (Loc,
1166 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
1168 Insert_Action (Find_Hook_Context (Related_Node), Master_Decl);
1169 Analyze (Master_Decl);
1171 -- Mark the containing scope as a task master. Masters associated
1172 -- with return statements are already marked at this stage (see
1173 -- Analyze_Subprogram_Body).
1175 if Ekind (Current_Scope) /= E_Return_Statement then
1177 Par : Node_Id := Related_Node;
1180 while Nkind (Par) /= N_Compilation_Unit loop
1181 Par := Parent (Par);
1183 -- If we fall off the top, we are at the outer level,
1184 -- and the environment task is our effective master,
1185 -- so nothing to mark.
1187 if Nkind_In (Par, N_Block_Statement,
1191 Set_Is_Task_Master (Par);
1201 Make_Defining_Identifier (Loc, New_External_Name (Chars (Typ), 'M'));
1204 -- typeMnn renames _master;
1207 Make_Object_Renaming_Declaration (Loc,
1208 Defining_Identifier => Master_Id,
1209 Subtype_Mark => New_Occurrence_Of (Standard_Integer, Loc),
1212 Insert_Action (Related_Node, Ren_Decl);
1214 Set_Master_Id (Typ, Master_Id);
1215 end Build_Class_Wide_Master;
1217 --------------------------------
1218 -- Build_Corresponding_Record --
1219 --------------------------------
1221 function Build_Corresponding_Record
1224 Loc : Source_Ptr) return Node_Id
1226 Rec_Ent : constant Entity_Id :=
1227 Make_Defining_Identifier
1228 (Loc, New_External_Name (Chars (Ctyp), 'V'));
1231 New_Disc : Entity_Id;
1235 Set_Corresponding_Record_Type (Ctyp, Rec_Ent);
1236 Set_Ekind (Rec_Ent, E_Record_Type);
1237 Set_Has_Delayed_Freeze (Rec_Ent, Has_Delayed_Freeze (Ctyp));
1238 Set_Is_Concurrent_Record_Type (Rec_Ent, True);
1239 Set_Corresponding_Concurrent_Type (Rec_Ent, Ctyp);
1240 Set_Stored_Constraint (Rec_Ent, No_Elist);
1243 -- Propagate type invariants to the corresponding record type
1245 Set_Has_Invariants (Rec_Ent, Has_Invariants (Ctyp));
1246 Set_Has_Inheritable_Invariants (Rec_Ent,
1247 Has_Inheritable_Invariants (Ctyp));
1249 -- Use discriminals to create list of discriminants for record, and
1250 -- create new discriminals for use in default expressions, etc. It is
1251 -- worth noting that a task discriminant gives rise to 5 entities;
1253 -- a) The original discriminant.
1254 -- b) The discriminal for use in the task.
1255 -- c) The discriminant of the corresponding record.
1256 -- d) The discriminal for the init proc of the corresponding record.
1257 -- e) The local variable that renames the discriminant in the procedure
1258 -- for the task body.
1260 -- In fact the discriminals b) are used in the renaming declarations
1261 -- for e). See details in einfo (Handling of Discriminants).
1263 if Present (Discriminant_Specifications (N)) then
1265 Disc := First_Discriminant (Ctyp);
1267 while Present (Disc) loop
1268 New_Disc := CR_Discriminant (Disc);
1271 Make_Discriminant_Specification (Loc,
1272 Defining_Identifier => New_Disc,
1273 Discriminant_Type =>
1274 New_Occurrence_Of (Etype (Disc), Loc),
1276 New_Copy (Discriminant_Default_Value (Disc))));
1278 Next_Discriminant (Disc);
1285 -- Now we can construct the record type declaration. Note that this
1286 -- record is "limited tagged". It is "limited" to reflect the underlying
1287 -- limitedness of the task or protected object that it represents, and
1288 -- ensuring for example that it is properly passed by reference. It is
1289 -- "tagged" to give support to dispatching calls through interfaces. We
1290 -- propagate here the list of interfaces covered by the concurrent type
1291 -- (Ada 2005: AI-345).
1294 Make_Full_Type_Declaration (Loc,
1295 Defining_Identifier => Rec_Ent,
1296 Discriminant_Specifications => Dlist,
1298 Make_Record_Definition (Loc,
1300 Make_Component_List (Loc, Component_Items => Cdecls),
1302 Ada_Version >= Ada_2005 and then Is_Tagged_Type (Ctyp),
1303 Interface_List => Interface_List (N),
1304 Limited_Present => True));
1305 end Build_Corresponding_Record;
1307 ---------------------------------
1308 -- Build_Dispatching_Tag_Check --
1309 ---------------------------------
1311 function Build_Dispatching_Tag_Check
1313 N : Node_Id) return Node_Id
1315 Loc : constant Source_Ptr := Sloc (N);
1322 New_Occurrence_Of (K, Loc),
1324 New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc)),
1328 New_Occurrence_Of (K, Loc),
1330 New_Occurrence_Of (RTE (RE_TK_Tagged), Loc)));
1331 end Build_Dispatching_Tag_Check;
1333 ----------------------------------
1334 -- Build_Entry_Count_Expression --
1335 ----------------------------------
1337 function Build_Entry_Count_Expression
1338 (Concurrent_Type : Node_Id;
1339 Component_List : List_Id;
1340 Loc : Source_Ptr) return Node_Id
1352 -- Count number of non-family entries
1355 Ent := First_Entity (Concurrent_Type);
1356 while Present (Ent) loop
1357 if Ekind (Ent) = E_Entry then
1364 Ecount := Make_Integer_Literal (Loc, Eindx);
1366 -- Loop through entry families building the addition nodes
1368 Ent := First_Entity (Concurrent_Type);
1369 Comp := First (Component_List);
1370 while Present (Ent) loop
1371 if Ekind (Ent) = E_Entry_Family then
1372 while Chars (Ent) /= Chars (Defining_Identifier (Comp)) loop
1376 Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
1377 Hi := Type_High_Bound (Typ);
1378 Lo := Type_Low_Bound (Typ);
1379 Large := Is_Potentially_Large_Family
1380 (Base_Type (Typ), Concurrent_Type, Lo, Hi);
1383 Left_Opnd => Ecount,
1385 Family_Size (Loc, Hi, Lo, Concurrent_Type, Large));
1392 end Build_Entry_Count_Expression;
1394 -----------------------
1395 -- Build_Entry_Names --
1396 -----------------------
1398 procedure Build_Entry_Names
1400 Obj_Typ : Entity_Id;
1403 Loc : constant Source_Ptr := Sloc (Obj_Ref);
1404 Data : Entity_Id := Empty;
1405 Index : Entity_Id := Empty;
1406 Typ : Entity_Id := Obj_Typ;
1408 procedure Build_Entry_Name (Comp_Id : Entity_Id);
1409 -- Given an entry [family], create a static string which denotes the
1410 -- name of Comp_Id and assign it to the underlying data structure which
1411 -- contains the entry names of a concurrent object.
1413 function Object_Reference return Node_Id;
1414 -- Return a reference to field _object or _task_id depending on the
1415 -- concurrent object being processed.
1417 ----------------------
1418 -- Build_Entry_Name --
1419 ----------------------
1421 procedure Build_Entry_Name (Comp_Id : Entity_Id) is
1422 function Build_Range (Def : Node_Id) return Node_Id;
1423 -- Given a discrete subtype definition of an entry family, generate a
1424 -- range node which covers the range of Def's type.
1426 procedure Create_Index_And_Data;
1427 -- Generate the declarations of variables Index and Data. Subsequent
1428 -- calls do nothing.
1430 function Increment_Index return Node_Id;
1431 -- Increment the index used in the assignment of string names to the
1434 function Name_Declaration (Def_Id : Entity_Id) return Node_Id;
1435 -- Given the name of a temporary variable, create the following
1436 -- declaration for it:
1438 -- Def_Id : aliased constant String := <String_Name_From_Buffer>;
1440 function Set_Entry_Name (Def_Id : Entity_Id) return Node_Id;
1441 -- Given the name of a temporary variable, place it in the array of
1442 -- string names. Generate:
1444 -- Data (Index) := Def_Id'Unchecked_Access;
1450 function Build_Range (Def : Node_Id) return Node_Id is
1451 High : Node_Id := Type_High_Bound (Etype (Def));
1452 Low : Node_Id := Type_Low_Bound (Etype (Def));
1455 -- If a bound references a discriminant, generate an identifier
1456 -- with the same name. Resolution will map it to the formals of
1459 if Is_Entity_Name (Low)
1460 and then Ekind (Entity (Low)) = E_Discriminant
1463 Make_Selected_Component (Loc,
1464 Prefix => New_Copy_Tree (Obj_Ref),
1465 Selector_Name => Make_Identifier (Loc, Chars (Low)));
1467 Low := New_Copy_Tree (Low);
1470 if Is_Entity_Name (High)
1471 and then Ekind (Entity (High)) = E_Discriminant
1474 Make_Selected_Component (Loc,
1475 Prefix => New_Copy_Tree (Obj_Ref),
1476 Selector_Name => Make_Identifier (Loc, Chars (High)));
1478 High := New_Copy_Tree (High);
1484 High_Bound => High);
1487 ---------------------------
1488 -- Create_Index_And_Data --
1489 ---------------------------
1491 procedure Create_Index_And_Data is
1493 if No (Index) and then No (Data) then
1500 if Is_Protected_Type (Typ) then
1501 Count := RO_PE_Number_Of_Entries;
1502 Data_Typ := RE_Protected_Entry_Names_Array;
1504 Count := RO_ST_Number_Of_Entries;
1505 Data_Typ := RE_Task_Entry_Names_Array;
1508 -- Step 1: Generate the declaration of the index variable:
1510 -- Index : Entry_Index := 1;
1512 Index := Make_Temporary (Loc, 'I');
1515 Make_Object_Declaration (Loc,
1516 Defining_Identifier => Index,
1517 Object_Definition =>
1518 New_Occurrence_Of (RTE (RE_Entry_Index), Loc),
1519 Expression => Make_Integer_Literal (Loc, 1)));
1521 -- Step 2: Generate the declaration of an array to house all
1524 -- Size : constant Entry_Index := <Count> (Obj_Ref);
1525 -- Data : aliased <Data_Typ> := (1 .. Size => null);
1527 Size := Make_Temporary (Loc, 'S');
1530 Make_Object_Declaration (Loc,
1531 Defining_Identifier => Size,
1532 Constant_Present => True,
1533 Object_Definition =>
1534 New_Occurrence_Of (RTE (RE_Entry_Index), Loc),
1536 Make_Function_Call (Loc,
1538 New_Occurrence_Of (RTE (Count), Loc),
1539 Parameter_Associations =>
1540 New_List (Object_Reference))));
1542 Data := Make_Temporary (Loc, 'A');
1545 Make_Object_Declaration (Loc,
1546 Defining_Identifier => Data,
1547 Aliased_Present => True,
1548 Object_Definition =>
1549 New_Occurrence_Of (RTE (Data_Typ), Loc),
1551 Make_Aggregate (Loc,
1552 Component_Associations => New_List (
1553 Make_Component_Association (Loc,
1554 Choices => New_List (
1557 Make_Integer_Literal (Loc, 1),
1559 New_Occurrence_Of (Size, Loc))),
1560 Expression => Make_Null (Loc))))));
1563 end Create_Index_And_Data;
1565 ---------------------
1566 -- Increment_Index --
1567 ---------------------
1569 function Increment_Index return Node_Id is
1572 Make_Assignment_Statement (Loc,
1573 Name => New_Occurrence_Of (Index, Loc),
1576 Left_Opnd => New_Occurrence_Of (Index, Loc),
1577 Right_Opnd => Make_Integer_Literal (Loc, 1)));
1578 end Increment_Index;
1580 ----------------------
1581 -- Name_Declaration --
1582 ----------------------
1584 function Name_Declaration (Def_Id : Entity_Id) return Node_Id is
1587 Make_Object_Declaration (Loc,
1588 Defining_Identifier => Def_Id,
1589 Aliased_Present => True,
1590 Constant_Present => True,
1591 Object_Definition =>
1592 New_Occurrence_Of (Standard_String, Loc),
1594 Make_String_Literal (Loc, String_From_Name_Buffer));
1595 end Name_Declaration;
1597 --------------------
1598 -- Set_Entry_Name --
1599 --------------------
1601 function Set_Entry_Name (Def_Id : Entity_Id) return Node_Id is
1604 Make_Assignment_Statement (Loc,
1606 Make_Indexed_Component (Loc,
1607 Prefix => New_Occurrence_Of (Data, Loc),
1608 Expressions => New_List (New_Occurrence_Of (Index, Loc))),
1611 Make_Attribute_Reference (Loc,
1612 Prefix => New_Occurrence_Of (Def_Id, Loc),
1613 Attribute_Name => Name_Unchecked_Access));
1618 Temp_Id : Entity_Id;
1621 -- Start of processing for Build_Entry_Name
1624 if Ekind (Comp_Id) = E_Entry_Family then
1625 Subt_Def := Discrete_Subtype_Definition (Parent (Comp_Id));
1627 Create_Index_And_Data;
1629 -- Step 1: Create the string name of the entry family.
1631 -- Temp : aliased constant String := "name ()";
1633 Temp_Id := Make_Temporary (Loc, 'S');
1634 Get_Name_String (Chars (Comp_Id));
1635 Add_Char_To_Name_Buffer (' ');
1636 Add_Char_To_Name_Buffer ('(');
1637 Add_Char_To_Name_Buffer (')');
1639 Append_To (Stmts, Name_Declaration (Temp_Id));
1642 -- for Member in Family_Low .. Family_High loop
1643 -- Set_Entry_Name (...);
1644 -- Index := Index + 1;
1648 Make_Loop_Statement (Loc,
1650 Make_Iteration_Scheme (Loc,
1651 Loop_Parameter_Specification =>
1652 Make_Loop_Parameter_Specification (Loc,
1653 Defining_Identifier =>
1654 Make_Temporary (Loc, 'L'),
1655 Discrete_Subtype_Definition =>
1656 Build_Range (Subt_Def))),
1658 Statements => New_List (
1659 Set_Entry_Name (Temp_Id),
1661 End_Label => Empty));
1666 Create_Index_And_Data;
1668 -- Step 1: Create the string name of the entry. Generate:
1669 -- Temp : aliased constant String := "name";
1671 Temp_Id := Make_Temporary (Loc, 'S');
1672 Get_Name_String (Chars (Comp_Id));
1674 Append_To (Stmts, Name_Declaration (Temp_Id));
1676 -- Step 2: Associate the string name with the underlying data
1679 Append_To (Stmts, Set_Entry_Name (Temp_Id));
1680 Append_To (Stmts, Increment_Index);
1682 end Build_Entry_Name;
1684 ----------------------
1685 -- Object_Reference --
1686 ----------------------
1688 function Object_Reference return Node_Id is
1689 Conc_Typ : constant Entity_Id := Corresponding_Record_Type (Typ);
1694 if Is_Protected_Type (Typ) then
1695 Field := Name_uObject;
1697 Field := Name_uTask_Id;
1701 Make_Selected_Component (Loc,
1703 Unchecked_Convert_To (Conc_Typ, New_Copy_Tree (Obj_Ref)),
1704 Selector_Name => Make_Identifier (Loc, Field));
1706 if Is_Protected_Type (Typ) then
1708 Make_Attribute_Reference (Loc,
1710 Attribute_Name => Name_Unchecked_Access);
1714 end Object_Reference;
1721 -- Start of processing for Build_Entry_Names
1724 -- Retrieve the original concurrent type
1726 if Is_Concurrent_Record_Type (Typ) then
1727 Typ := Corresponding_Concurrent_Type (Typ);
1730 pragma Assert (Is_Concurrent_Type (Typ));
1732 -- Nothing to do if the type has no entries
1734 if not Has_Entries (Typ) then
1738 -- Avoid generating entry names for a protected type with only one entry
1740 if Is_Protected_Type (Typ)
1741 and then Find_Protection_Type (Base_Type (Typ)) /=
1742 RTE (RE_Protection_Entries)
1747 -- Step 1: Populate the array with statically generated strings denoting
1748 -- entries and entry family names.
1750 Comp := First_Entity (Typ);
1751 while Present (Comp) loop
1752 if Comes_From_Source (Comp)
1753 and then Ekind_In (Comp, E_Entry, E_Entry_Family)
1755 Build_Entry_Name (Comp);
1761 -- Step 2: Associate the array with the related concurrent object:
1763 -- Set_Entry_Names (Obj_Ref, <Data>'Unchecked_Access);
1765 if Present (Data) then
1766 if Is_Protected_Type (Typ) then
1767 Proc := RO_PE_Set_Entry_Names;
1769 Proc := RO_ST_Set_Entry_Names;
1773 Make_Procedure_Call_Statement (Loc,
1774 Name => New_Occurrence_Of (RTE (Proc), Loc),
1775 Parameter_Associations => New_List (
1777 Make_Attribute_Reference (Loc,
1778 Prefix => New_Occurrence_Of (Data, Loc),
1779 Attribute_Name => Name_Unchecked_Access))));
1781 end Build_Entry_Names;
1783 ---------------------------
1784 -- Build_Parameter_Block --
1785 ---------------------------
1787 function Build_Parameter_Block
1791 Decls : List_Id) return Entity_Id
1797 Has_Comp : Boolean := False;
1801 Actual := First (Actuals);
1803 Formal := Defining_Identifier (First (Formals));
1805 while Present (Actual) loop
1806 if not Is_Controlling_Actual (Actual) then
1809 -- type Ann is access all <actual-type>
1811 Comp_Nam := Make_Temporary (Loc, 'A');
1814 Make_Full_Type_Declaration (Loc,
1815 Defining_Identifier => Comp_Nam,
1817 Make_Access_To_Object_Definition (Loc,
1818 All_Present => True,
1819 Constant_Present => Ekind (Formal) = E_In_Parameter,
1820 Subtype_Indication =>
1821 New_Occurrence_Of (Etype (Actual), Loc))));
1827 Make_Component_Declaration (Loc,
1828 Defining_Identifier =>
1829 Make_Defining_Identifier (Loc, Chars (Formal)),
1830 Component_Definition =>
1831 Make_Component_Definition (Loc,
1834 Subtype_Indication =>
1835 New_Occurrence_Of (Comp_Nam, Loc))));
1840 Next_Actual (Actual);
1841 Next_Formal_With_Extras (Formal);
1844 Rec_Nam := Make_Temporary (Loc, 'P');
1849 -- type Pnn is record
1854 -- where Pnn is a parameter wrapping record, Param1 .. ParamN are
1855 -- the original parameter names and Ann1 .. AnnN are the access to
1859 Make_Full_Type_Declaration (Loc,
1860 Defining_Identifier =>
1863 Make_Record_Definition (Loc,
1865 Make_Component_List (Loc, Comps))));
1868 -- type Pnn is null record;
1871 Make_Full_Type_Declaration (Loc,
1872 Defining_Identifier =>
1875 Make_Record_Definition (Loc,
1876 Null_Present => True,
1877 Component_List => Empty)));
1881 end Build_Parameter_Block;
1883 --------------------------------------
1884 -- Build_Renamed_Formal_Declaration --
1885 --------------------------------------
1887 function Build_Renamed_Formal_Declaration
1891 Renamed_Formal : Node_Id) return Node_Id
1893 Loc : constant Source_Ptr := Sloc (New_F);
1897 -- If the formal is a tagged incomplete type, it is already passed
1898 -- by reference, so it is sufficient to rename the pointer component
1899 -- that corresponds to the actual. Otherwise we need to dereference
1900 -- the pointer component to obtain the actual.
1902 if Is_Incomplete_Type (Etype (Formal))
1903 and then Is_Tagged_Type (Etype (Formal))
1906 Make_Object_Renaming_Declaration (Loc,
1907 Defining_Identifier => New_F,
1908 Subtype_Mark => New_Occurrence_Of (Etype (Comp), Loc),
1909 Name => Renamed_Formal);
1913 Make_Object_Renaming_Declaration (Loc,
1914 Defining_Identifier => New_F,
1915 Subtype_Mark => New_Occurrence_Of (Etype (Formal), Loc),
1917 Make_Explicit_Dereference (Loc, Renamed_Formal));
1921 end Build_Renamed_Formal_Declaration;
1923 -----------------------
1924 -- Build_PPC_Wrapper --
1925 -----------------------
1927 procedure Build_PPC_Wrapper (E : Entity_Id; Decl : Node_Id) is
1928 Items : constant Node_Id := Contract (E);
1929 Loc : constant Source_Ptr := Sloc (E);
1930 Synch_Type : constant Entity_Id := Scope (E);
1933 Entry_Call : Node_Id;
1934 Entry_Name : Node_Id;
1937 Synch_Id : Entity_Id;
1938 Wrapper_Id : Entity_Id;
1941 -- Only build the wrapper if entry has pre/postconditions
1942 -- Should this be done unconditionally instead ???
1944 if Present (Items) then
1945 Prag := Pre_Post_Conditions (Items);
1951 -- Transfer ppc pragmas to the declarations of the wrapper
1955 while Present (Prag) loop
1956 if Nam_In (Pragma_Name (Prag), Name_Precondition,
1959 Append (Relocate_Node (Prag), Decls);
1960 Set_Analyzed (Last (Decls), False);
1963 Prag := Next_Pragma (Prag);
1969 Actuals := New_List;
1971 Make_Defining_Identifier (Loc,
1972 Chars => New_External_Name (Chars (Scope (E)), 'A'));
1974 -- First formal is synchronized object
1976 Params := New_List (
1977 Make_Parameter_Specification (Loc,
1978 Defining_Identifier => Synch_Id,
1979 Out_Present => True,
1981 Parameter_Type => New_Occurrence_Of (Scope (E), Loc)));
1984 Make_Selected_Component (Loc,
1985 Prefix => New_Occurrence_Of (Synch_Id, Loc),
1986 Selector_Name => New_Occurrence_Of (E, Loc));
1988 -- If entity is entry family, second formal is the corresponding index,
1989 -- and entry name is an indexed component.
1991 if Ekind (E) = E_Entry_Family then
1993 Index : constant Entity_Id :=
1994 Make_Defining_Identifier (Loc, Name_I);
1997 Make_Parameter_Specification (Loc,
1998 Defining_Identifier => Index,
2000 New_Occurrence_Of (Entry_Index_Type (E), Loc)));
2003 Make_Indexed_Component (Loc,
2004 Prefix => Entry_Name,
2005 Expressions => New_List (New_Occurrence_Of (Index, Loc)));
2010 Make_Procedure_Call_Statement (Loc,
2012 Parameter_Associations => Actuals);
2014 -- Now add formals that match those of the entry, and build actuals for
2015 -- the nested entry call.
2019 New_Form : Entity_Id;
2020 Parm_Spec : Node_Id;
2023 Form := First_Formal (E);
2024 while Present (Form) loop
2025 New_Form := Make_Defining_Identifier (Loc, Chars (Form));
2027 Make_Parameter_Specification (Loc,
2028 Defining_Identifier => New_Form,
2029 Out_Present => Out_Present (Parent (Form)),
2030 In_Present => In_Present (Parent (Form)),
2031 Parameter_Type => New_Occurrence_Of (Etype (Form), Loc));
2033 Append (Parm_Spec, Params);
2034 Append (New_Occurrence_Of (New_Form, Loc), Actuals);
2039 -- Add renaming declarations for the discriminants of the enclosing
2040 -- type, which may be visible in the preconditions.
2042 if Has_Discriminants (Synch_Type) then
2048 D := First_Discriminant (Synch_Type);
2049 while Present (D) loop
2051 Make_Object_Renaming_Declaration (Loc,
2052 Defining_Identifier =>
2053 Make_Defining_Identifier (Loc, Chars (D)),
2054 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
2056 Make_Selected_Component (Loc,
2057 Prefix => New_Occurrence_Of (Synch_Id, Loc),
2058 Selector_Name => Make_Identifier (Loc, Chars (D))));
2059 Prepend (Decl, Decls);
2060 Next_Discriminant (D);
2066 Make_Defining_Identifier (Loc, New_External_Name (Chars (E), 'E'));
2067 Set_PPC_Wrapper (E, Wrapper_Id);
2069 -- The wrapper body is analyzed when the enclosing type is frozen
2071 Append_Freeze_Action (Defining_Entity (Decl),
2072 Make_Subprogram_Body (Loc,
2074 Make_Procedure_Specification (Loc,
2075 Defining_Unit_Name => Wrapper_Id,
2076 Parameter_Specifications => Params),
2077 Declarations => Decls,
2078 Handled_Statement_Sequence =>
2079 Make_Handled_Sequence_Of_Statements (Loc,
2080 Statements => New_List (Entry_Call))));
2081 end Build_PPC_Wrapper;
2083 --------------------------
2084 -- Build_Wrapper_Bodies --
2085 --------------------------
2087 procedure Build_Wrapper_Bodies
2092 Rec_Typ : Entity_Id;
2094 function Build_Wrapper_Body
2096 Subp_Id : Entity_Id;
2097 Obj_Typ : Entity_Id;
2098 Formals : List_Id) return Node_Id;
2099 -- Ada 2005 (AI-345): Build the body that wraps a primitive operation
2100 -- associated with a protected or task type. Subp_Id is the subprogram
2101 -- name which will be wrapped. Obj_Typ is the type of the new formal
2102 -- parameter which handles dispatching and object notation. Formals are
2103 -- the original formals of Subp_Id which will be explicitly replicated.
2105 ------------------------
2106 -- Build_Wrapper_Body --
2107 ------------------------
2109 function Build_Wrapper_Body
2111 Subp_Id : Entity_Id;
2112 Obj_Typ : Entity_Id;
2113 Formals : List_Id) return Node_Id
2115 Body_Spec : Node_Id;
2118 Body_Spec := Build_Wrapper_Spec (Subp_Id, Obj_Typ, Formals);
2120 -- The subprogram is not overriding or is not a primitive declared
2121 -- between two views.
2123 if No (Body_Spec) then
2128 Actuals : List_Id := No_List;
2130 First_Form : Node_Id;
2135 -- Map formals to actuals. Use the list built for the wrapper
2136 -- spec, skipping the object notation parameter.
2138 First_Form := First (Parameter_Specifications (Body_Spec));
2140 Formal := First_Form;
2143 if Present (Formal) then
2144 Actuals := New_List;
2145 while Present (Formal) loop
2147 Make_Identifier (Loc,
2148 Chars => Chars (Defining_Identifier (Formal))));
2153 -- Special processing for primitives declared between a private
2154 -- type and its completion: the wrapper needs a properly typed
2155 -- parameter if the wrapped operation has a controlling first
2156 -- parameter. Note that this might not be the case for a function
2157 -- with a controlling result.
2159 if Is_Private_Primitive_Subprogram (Subp_Id) then
2160 if No (Actuals) then
2161 Actuals := New_List;
2164 if Is_Controlling_Formal (First_Formal (Subp_Id)) then
2165 Prepend_To (Actuals,
2166 Unchecked_Convert_To
2167 (Corresponding_Concurrent_Type (Obj_Typ),
2168 Make_Identifier (Loc, Name_uO)));
2171 Prepend_To (Actuals,
2172 Make_Identifier (Loc,
2173 Chars => Chars (Defining_Identifier (First_Form))));
2176 Nam := New_Occurrence_Of (Subp_Id, Loc);
2178 -- An access-to-variable object parameter requires an explicit
2179 -- dereference in the unchecked conversion. This case occurs
2180 -- when a protected entry wrapper must override an interface
2181 -- level procedure with interface access as first parameter.
2183 -- O.all.Subp_Id (Formal_1, ..., Formal_N)
2185 if Nkind (Parameter_Type (First_Form)) =
2189 Make_Explicit_Dereference (Loc,
2190 Prefix => Make_Identifier (Loc, Name_uO));
2192 Conv_Id := Make_Identifier (Loc, Name_uO);
2196 Make_Selected_Component (Loc,
2198 Unchecked_Convert_To
2199 (Corresponding_Concurrent_Type (Obj_Typ), Conv_Id),
2200 Selector_Name => New_Occurrence_Of (Subp_Id, Loc));
2203 -- Create the subprogram body. For a function, the call to the
2204 -- actual subprogram has to be converted to the corresponding
2205 -- record if it is a controlling result.
2207 if Ekind (Subp_Id) = E_Function then
2213 Make_Function_Call (Loc,
2215 Parameter_Associations => Actuals);
2217 if Has_Controlling_Result (Subp_Id) then
2219 Unchecked_Convert_To
2220 (Corresponding_Record_Type (Etype (Subp_Id)), Res);
2224 Make_Subprogram_Body (Loc,
2225 Specification => Body_Spec,
2226 Declarations => Empty_List,
2227 Handled_Statement_Sequence =>
2228 Make_Handled_Sequence_Of_Statements (Loc,
2229 Statements => New_List (
2230 Make_Simple_Return_Statement (Loc, Res))));
2235 Make_Subprogram_Body (Loc,
2236 Specification => Body_Spec,
2237 Declarations => Empty_List,
2238 Handled_Statement_Sequence =>
2239 Make_Handled_Sequence_Of_Statements (Loc,
2240 Statements => New_List (
2241 Make_Procedure_Call_Statement (Loc,
2243 Parameter_Associations => Actuals))));
2246 end Build_Wrapper_Body;
2248 -- Start of processing for Build_Wrapper_Bodies
2251 if Is_Concurrent_Type (Typ) then
2252 Rec_Typ := Corresponding_Record_Type (Typ);
2257 -- Generate wrapper bodies for a concurrent type which implements an
2260 if Present (Interfaces (Rec_Typ)) then
2262 Insert_Nod : Node_Id;
2264 Prim_Elmt : Elmt_Id;
2265 Prim_Decl : Node_Id;
2267 Wrap_Body : Node_Id;
2268 Wrap_Id : Entity_Id;
2273 -- Examine all primitive operations of the corresponding record
2274 -- type, looking for wrapper specs. Generate bodies in order to
2277 Prim_Elmt := First_Elmt (Primitive_Operations (Rec_Typ));
2278 while Present (Prim_Elmt) loop
2279 Prim := Node (Prim_Elmt);
2281 if (Ekind (Prim) = E_Function
2282 or else Ekind (Prim) = E_Procedure)
2283 and then Is_Primitive_Wrapper (Prim)
2285 Subp := Wrapped_Entity (Prim);
2286 Prim_Decl := Parent (Parent (Prim));
2289 Build_Wrapper_Body (Loc,
2292 Formals => Parameter_Specifications (Parent (Subp)));
2293 Wrap_Id := Defining_Unit_Name (Specification (Wrap_Body));
2295 Set_Corresponding_Spec (Wrap_Body, Prim);
2296 Set_Corresponding_Body (Prim_Decl, Wrap_Id);
2298 Insert_After (Insert_Nod, Wrap_Body);
2299 Insert_Nod := Wrap_Body;
2301 Analyze (Wrap_Body);
2304 Next_Elmt (Prim_Elmt);
2308 end Build_Wrapper_Bodies;
2310 ------------------------
2311 -- Build_Wrapper_Spec --
2312 ------------------------
2314 function Build_Wrapper_Spec
2315 (Subp_Id : Entity_Id;
2316 Obj_Typ : Entity_Id;
2317 Formals : List_Id) return Node_Id
2319 Loc : constant Source_Ptr := Sloc (Subp_Id);
2320 First_Param : Node_Id;
2322 Iface_Elmt : Elmt_Id;
2323 Iface_Op : Entity_Id;
2324 Iface_Op_Elmt : Elmt_Id;
2326 function Overriding_Possible
2327 (Iface_Op : Entity_Id;
2328 Wrapper : Entity_Id) return Boolean;
2329 -- Determine whether a primitive operation can be overridden by Wrapper.
2330 -- Iface_Op is the candidate primitive operation of an interface type,
2331 -- Wrapper is the generated entry wrapper.
2333 function Replicate_Formals
2335 Formals : List_Id) return List_Id;
2336 -- An explicit parameter replication is required due to the Is_Entry_
2337 -- Formal flag being set for all the formals of an entry. The explicit
2338 -- replication removes the flag that would otherwise cause a different
2339 -- path of analysis.
2341 -------------------------
2342 -- Overriding_Possible --
2343 -------------------------
2345 function Overriding_Possible
2346 (Iface_Op : Entity_Id;
2347 Wrapper : Entity_Id) return Boolean
2349 Iface_Op_Spec : constant Node_Id := Parent (Iface_Op);
2350 Wrapper_Spec : constant Node_Id := Parent (Wrapper);
2352 function Type_Conformant_Parameters
2353 (Iface_Op_Params : List_Id;
2354 Wrapper_Params : List_Id) return Boolean;
2355 -- Determine whether the parameters of the generated entry wrapper
2356 -- and those of a primitive operation are type conformant. During
2357 -- this check, the first parameter of the primitive operation is
2358 -- skipped if it is a controlling argument: protected functions
2359 -- may have a controlling result.
2361 --------------------------------
2362 -- Type_Conformant_Parameters --
2363 --------------------------------
2365 function Type_Conformant_Parameters
2366 (Iface_Op_Params : List_Id;
2367 Wrapper_Params : List_Id) return Boolean
2369 Iface_Op_Param : Node_Id;
2370 Iface_Op_Typ : Entity_Id;
2371 Wrapper_Param : Node_Id;
2372 Wrapper_Typ : Entity_Id;
2375 -- Skip the first (controlling) parameter of primitive operation
2377 Iface_Op_Param := First (Iface_Op_Params);
2379 if Present (First_Formal (Iface_Op))
2380 and then Is_Controlling_Formal (First_Formal (Iface_Op))
2382 Iface_Op_Param := Next (Iface_Op_Param);
2385 Wrapper_Param := First (Wrapper_Params);
2386 while Present (Iface_Op_Param)
2387 and then Present (Wrapper_Param)
2389 Iface_Op_Typ := Find_Parameter_Type (Iface_Op_Param);
2390 Wrapper_Typ := Find_Parameter_Type (Wrapper_Param);
2392 -- The two parameters must be mode conformant
2394 if not Conforming_Types
2395 (Iface_Op_Typ, Wrapper_Typ, Mode_Conformant)
2400 Next (Iface_Op_Param);
2401 Next (Wrapper_Param);
2404 -- One of the lists is longer than the other
2406 if Present (Iface_Op_Param) or else Present (Wrapper_Param) then
2411 end Type_Conformant_Parameters;
2413 -- Start of processing for Overriding_Possible
2416 if Chars (Iface_Op) /= Chars (Wrapper) then
2420 -- If an inherited subprogram is implemented by a protected procedure
2421 -- or an entry, then the first parameter of the inherited subprogram
2422 -- must be of mode OUT or IN OUT, or access-to-variable parameter.
2424 if Ekind (Iface_Op) = E_Procedure
2425 and then Present (Parameter_Specifications (Iface_Op_Spec))
2428 Obj_Param : constant Node_Id :=
2429 First (Parameter_Specifications (Iface_Op_Spec));
2431 if not Out_Present (Obj_Param)
2432 and then Nkind (Parameter_Type (Obj_Param)) /=
2441 Type_Conformant_Parameters (
2442 Parameter_Specifications (Iface_Op_Spec),
2443 Parameter_Specifications (Wrapper_Spec));
2444 end Overriding_Possible;
2446 -----------------------
2447 -- Replicate_Formals --
2448 -----------------------
2450 function Replicate_Formals
2452 Formals : List_Id) return List_Id
2454 New_Formals : constant List_Id := New_List;
2456 Param_Type : Node_Id;
2459 Formal := First (Formals);
2461 -- Skip the object parameter when dealing with primitives declared
2462 -- between two views.
2464 if Is_Private_Primitive_Subprogram (Subp_Id)
2465 and then not Has_Controlling_Result (Subp_Id)
2467 Formal := Next (Formal);
2470 while Present (Formal) loop
2472 -- Create an explicit copy of the entry parameter
2474 -- When creating the wrapper subprogram for a primitive operation
2475 -- of a protected interface we must construct an equivalent
2476 -- signature to that of the overriding operation. For regular
2477 -- parameters we can just use the type of the formal, but for
2478 -- access to subprogram parameters we need to reanalyze the
2479 -- parameter type to create local entities for the signature of
2480 -- the subprogram type. Using the entities of the overriding
2481 -- subprogram will result in out-of-scope errors in the back-end.
2483 if Nkind (Parameter_Type (Formal)) = N_Access_Definition then
2484 Param_Type := Copy_Separate_Tree (Parameter_Type (Formal));
2487 New_Occurrence_Of (Etype (Parameter_Type (Formal)), Loc);
2490 Append_To (New_Formals,
2491 Make_Parameter_Specification (Loc,
2492 Defining_Identifier =>
2493 Make_Defining_Identifier (Loc,
2495 (Defining_Identifier (Formal))),
2496 In_Present => In_Present (Formal),
2497 Out_Present => Out_Present (Formal),
2498 Null_Exclusion_Present => Null_Exclusion_Present (Formal),
2499 Parameter_Type => Param_Type));
2505 end Replicate_Formals;
2507 -- Start of processing for Build_Wrapper_Spec
2510 -- No point in building wrappers for untagged concurrent types
2512 pragma Assert (Is_Tagged_Type (Obj_Typ));
2514 -- An entry or a protected procedure can override a routine where the
2515 -- controlling formal is either IN OUT, OUT or is of access-to-variable
2516 -- type. Since the wrapper must have the exact same signature as that of
2517 -- the overridden subprogram, we try to find the overriding candidate
2518 -- and use its controlling formal.
2520 First_Param := Empty;
2522 -- Check every implemented interface
2524 if Present (Interfaces (Obj_Typ)) then
2525 Iface_Elmt := First_Elmt (Interfaces (Obj_Typ));
2526 Search : while Present (Iface_Elmt) loop
2527 Iface := Node (Iface_Elmt);
2529 -- Check every interface primitive
2531 if Present (Primitive_Operations (Iface)) then
2532 Iface_Op_Elmt := First_Elmt (Primitive_Operations (Iface));
2533 while Present (Iface_Op_Elmt) loop
2534 Iface_Op := Node (Iface_Op_Elmt);
2536 -- Ignore predefined primitives
2538 if not Is_Predefined_Dispatching_Operation (Iface_Op) then
2539 Iface_Op := Ultimate_Alias (Iface_Op);
2541 -- The current primitive operation can be overridden by
2542 -- the generated entry wrapper.
2544 if Overriding_Possible (Iface_Op, Subp_Id) then
2546 First (Parameter_Specifications (Parent (Iface_Op)));
2552 Next_Elmt (Iface_Op_Elmt);
2556 Next_Elmt (Iface_Elmt);
2560 -- Ada 2012 (AI05-0090-1): If no interface primitive is covered by
2561 -- this subprogram and this is not a primitive declared between two
2562 -- views then force the generation of a wrapper. As an optimization,
2563 -- previous versions of the frontend avoid generating the wrapper;
2564 -- however, the wrapper facilitates locating and reporting an error
2565 -- when a duplicate declaration is found later. See example in
2569 and then not Is_Private_Primitive_Subprogram (Subp_Id)
2572 (Corresponding_Concurrent_Type (Obj_Typ))
2575 Make_Parameter_Specification (Loc,
2576 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uO),
2578 Out_Present => False,
2579 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2581 -- For entries and procedures of protected types the mode of
2582 -- the controlling argument must be in-out.
2586 Make_Parameter_Specification (Loc,
2587 Defining_Identifier =>
2588 Make_Defining_Identifier (Loc,
2591 Out_Present => (Ekind (Subp_Id) /= E_Function),
2592 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2597 Wrapper_Id : constant Entity_Id :=
2598 Make_Defining_Identifier (Loc, Chars (Subp_Id));
2599 New_Formals : List_Id;
2600 Obj_Param : Node_Id;
2601 Obj_Param_Typ : Entity_Id;
2604 -- Minimum decoration is needed to catch the entity in
2605 -- Sem_Ch6.Override_Dispatching_Operation.
2607 if Ekind (Subp_Id) = E_Function then
2608 Set_Ekind (Wrapper_Id, E_Function);
2610 Set_Ekind (Wrapper_Id, E_Procedure);
2613 Set_Is_Primitive_Wrapper (Wrapper_Id);
2614 Set_Wrapped_Entity (Wrapper_Id, Subp_Id);
2615 Set_Is_Private_Primitive (Wrapper_Id,
2616 Is_Private_Primitive_Subprogram (Subp_Id));
2618 -- Process the formals
2620 New_Formals := Replicate_Formals (Loc, Formals);
2622 -- A function with a controlling result and no first controlling
2623 -- formal needs no additional parameter.
2625 if Has_Controlling_Result (Subp_Id)
2627 (No (First_Formal (Subp_Id))
2628 or else not Is_Controlling_Formal (First_Formal (Subp_Id)))
2632 -- Routine Subp_Id has been found to override an interface primitive.
2633 -- If the interface operation has an access parameter, create a copy
2634 -- of it, with the same null exclusion indicator if present.
2636 elsif Present (First_Param) then
2637 if Nkind (Parameter_Type (First_Param)) = N_Access_Definition then
2639 Make_Access_Definition (Loc,
2641 New_Occurrence_Of (Obj_Typ, Loc),
2642 Null_Exclusion_Present =>
2643 Null_Exclusion_Present (Parameter_Type (First_Param)),
2645 Constant_Present (Parameter_Type (First_Param)));
2647 Obj_Param_Typ := New_Occurrence_Of (Obj_Typ, Loc);
2651 Make_Parameter_Specification (Loc,
2652 Defining_Identifier =>
2653 Make_Defining_Identifier (Loc,
2655 In_Present => In_Present (First_Param),
2656 Out_Present => Out_Present (First_Param),
2657 Parameter_Type => Obj_Param_Typ);
2659 Prepend_To (New_Formals, Obj_Param);
2661 -- If we are dealing with a primitive declared between two views,
2662 -- implemented by a synchronized operation, we need to create
2663 -- a default parameter. The mode of the parameter must match that
2664 -- of the primitive operation.
2667 pragma Assert (Is_Private_Primitive_Subprogram (Subp_Id));
2669 Make_Parameter_Specification (Loc,
2670 Defining_Identifier =>
2671 Make_Defining_Identifier (Loc, Name_uO),
2672 In_Present => In_Present (Parent (First_Entity (Subp_Id))),
2673 Out_Present => Ekind (Subp_Id) /= E_Function,
2674 Parameter_Type => New_Occurrence_Of (Obj_Typ, Loc));
2675 Prepend_To (New_Formals, Obj_Param);
2678 -- Build the final spec. If it is a function with a controlling
2679 -- result, it is a primitive operation of the corresponding
2680 -- record type, so mark the spec accordingly.
2682 if Ekind (Subp_Id) = E_Function then
2687 if Has_Controlling_Result (Subp_Id) then
2690 (Corresponding_Record_Type (Etype (Subp_Id)), Loc);
2692 Res_Def := New_Copy (Result_Definition (Parent (Subp_Id)));
2696 Make_Function_Specification (Loc,
2697 Defining_Unit_Name => Wrapper_Id,
2698 Parameter_Specifications => New_Formals,
2699 Result_Definition => Res_Def);
2703 Make_Procedure_Specification (Loc,
2704 Defining_Unit_Name => Wrapper_Id,
2705 Parameter_Specifications => New_Formals);
2708 end Build_Wrapper_Spec;
2710 -------------------------
2711 -- Build_Wrapper_Specs --
2712 -------------------------
2714 procedure Build_Wrapper_Specs
2720 Rec_Typ : Entity_Id;
2721 procedure Scan_Declarations (L : List_Id);
2722 -- Common processing for visible and private declarations
2723 -- of a protected type.
2725 procedure Scan_Declarations (L : List_Id) is
2727 Wrap_Decl : Node_Id;
2728 Wrap_Spec : Node_Id;
2736 while Present (Decl) loop
2739 if Nkind (Decl) = N_Entry_Declaration
2740 and then Ekind (Defining_Identifier (Decl)) = E_Entry
2744 (Subp_Id => Defining_Identifier (Decl),
2746 Formals => Parameter_Specifications (Decl));
2748 elsif Nkind (Decl) = N_Subprogram_Declaration then
2751 (Subp_Id => Defining_Unit_Name (Specification (Decl)),
2754 Parameter_Specifications (Specification (Decl)));
2757 if Present (Wrap_Spec) then
2759 Make_Subprogram_Declaration (Loc,
2760 Specification => Wrap_Spec);
2762 Insert_After (N, Wrap_Decl);
2765 Analyze (Wrap_Decl);
2770 end Scan_Declarations;
2772 -- start of processing for Build_Wrapper_Specs
2775 if Is_Protected_Type (Typ) then
2776 Def := Protected_Definition (Parent (Typ));
2777 else pragma Assert (Is_Task_Type (Typ));
2778 Def := Task_Definition (Parent (Typ));
2781 Rec_Typ := Corresponding_Record_Type (Typ);
2783 -- Generate wrapper specs for a concurrent type which implements an
2784 -- interface. Operations in both the visible and private parts may
2785 -- implement progenitor operations.
2787 if Present (Interfaces (Rec_Typ)) and then Present (Def) then
2788 Scan_Declarations (Visible_Declarations (Def));
2789 Scan_Declarations (Private_Declarations (Def));
2791 end Build_Wrapper_Specs;
2793 ---------------------------
2794 -- Build_Find_Body_Index --
2795 ---------------------------
2797 function Build_Find_Body_Index (Typ : Entity_Id) return Node_Id is
2798 Loc : constant Source_Ptr := Sloc (Typ);
2801 Has_F : Boolean := False;
2803 If_St : Node_Id := Empty;
2806 Decls : List_Id := New_List;
2809 Siz : Node_Id := Empty;
2811 procedure Add_If_Clause (Expr : Node_Id);
2812 -- Add test for range of current entry
2814 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
2815 -- If a bound of an entry is given by a discriminant, retrieve the
2816 -- actual value of the discriminant from the enclosing object.
2822 procedure Add_If_Clause (Expr : Node_Id) is
2824 Stats : constant List_Id :=
2826 Make_Simple_Return_Statement (Loc,
2827 Expression => Make_Integer_Literal (Loc, Index + 1)));
2830 -- Index for current entry body
2834 -- Compute total length of entry queues so far
2842 Right_Opnd => Expr);
2847 Left_Opnd => Make_Identifier (Loc, Name_uE),
2850 -- Map entry queue indexes in the range of the current family
2851 -- into the current index, that designates the entry body.
2855 Make_Implicit_If_Statement (Typ,
2857 Then_Statements => Stats,
2858 Elsif_Parts => New_List);
2862 Append_To (Elsif_Parts (If_St),
2863 Make_Elsif_Part (Loc,
2865 Then_Statements => Stats));
2869 ------------------------------
2870 -- Convert_Discriminant_Ref --
2871 ------------------------------
2873 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
2877 if Is_Entity_Name (Bound)
2878 and then Ekind (Entity (Bound)) = E_Discriminant
2881 Make_Selected_Component (Loc,
2883 Unchecked_Convert_To (Corresponding_Record_Type (Typ),
2884 Make_Explicit_Dereference (Loc,
2885 Make_Identifier (Loc, Name_uObject))),
2886 Selector_Name => Make_Identifier (Loc, Chars (Bound)));
2887 Set_Etype (B, Etype (Entity (Bound)));
2889 B := New_Copy_Tree (Bound);
2893 end Convert_Discriminant_Ref;
2895 -- Start of processing for Build_Find_Body_Index
2898 Spec := Build_Find_Body_Index_Spec (Typ);
2900 Ent := First_Entity (Typ);
2901 while Present (Ent) loop
2902 if Ekind (Ent) = E_Entry_Family then
2912 -- If the protected type has no entry families, there is a one-one
2913 -- correspondence between entry queue and entry body.
2916 Make_Simple_Return_Statement (Loc,
2917 Expression => Make_Identifier (Loc, Name_uE));
2920 -- Suppose entries e1, e2, ... have size l1, l2, ... we generate
2923 -- if E <= l1 then return 1;
2924 -- elsif E <= l1 + l2 then return 2;
2929 Ent := First_Entity (Typ);
2931 Add_Object_Pointer (Loc, Typ, Decls);
2933 while Present (Ent) loop
2934 if Ekind (Ent) = E_Entry then
2935 Add_If_Clause (Make_Integer_Literal (Loc, 1));
2937 elsif Ekind (Ent) = E_Entry_Family then
2938 E_Typ := Etype (Discrete_Subtype_Definition (Parent (Ent)));
2939 Hi := Convert_Discriminant_Ref (Type_High_Bound (E_Typ));
2940 Lo := Convert_Discriminant_Ref (Type_Low_Bound (E_Typ));
2941 Add_If_Clause (Family_Size (Loc, Hi, Lo, Typ, False));
2950 Make_Simple_Return_Statement (Loc,
2951 Expression => Make_Integer_Literal (Loc, 1));
2953 elsif Nkind (Ret) = N_If_Statement then
2955 -- Ranges are in increasing order, so last one doesn't need guard
2958 Nod : constant Node_Id := Last (Elsif_Parts (Ret));
2961 Set_Else_Statements (Ret, Then_Statements (Nod));
2967 Make_Subprogram_Body (Loc,
2968 Specification => Spec,
2969 Declarations => Decls,
2970 Handled_Statement_Sequence =>
2971 Make_Handled_Sequence_Of_Statements (Loc,
2972 Statements => New_List (Ret)));
2973 end Build_Find_Body_Index;
2975 --------------------------------
2976 -- Build_Find_Body_Index_Spec --
2977 --------------------------------
2979 function Build_Find_Body_Index_Spec (Typ : Entity_Id) return Node_Id is
2980 Loc : constant Source_Ptr := Sloc (Typ);
2981 Id : constant Entity_Id :=
2982 Make_Defining_Identifier (Loc,
2983 Chars => New_External_Name (Chars (Typ), 'F'));
2984 Parm1 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uO);
2985 Parm2 : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uE);
2989 Make_Function_Specification (Loc,
2990 Defining_Unit_Name => Id,
2991 Parameter_Specifications => New_List (
2992 Make_Parameter_Specification (Loc,
2993 Defining_Identifier => Parm1,
2995 New_Occurrence_Of (RTE (RE_Address), Loc)),
2997 Make_Parameter_Specification (Loc,
2998 Defining_Identifier => Parm2,
3000 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))),
3002 Result_Definition => New_Occurrence_Of (
3003 RTE (RE_Protected_Entry_Index), Loc));
3004 end Build_Find_Body_Index_Spec;
3006 -----------------------------------------------
3007 -- Build_Lock_Free_Protected_Subprogram_Body --
3008 -----------------------------------------------
3010 function Build_Lock_Free_Protected_Subprogram_Body
3013 Unprot_Spec : Node_Id) return Node_Id
3015 Actuals : constant List_Id := New_List;
3016 Loc : constant Source_Ptr := Sloc (N);
3017 Spec : constant Node_Id := Specification (N);
3018 Unprot_Id : constant Entity_Id := Defining_Unit_Name (Unprot_Spec);
3020 Prot_Spec : Node_Id;
3024 -- Create the protected version of the body
3027 Build_Protected_Sub_Specification (N, Prot_Typ, Protected_Mode);
3029 -- Build the actual parameters which appear in the call to the
3030 -- unprotected version of the body.
3032 Formal := First (Parameter_Specifications (Prot_Spec));
3033 while Present (Formal) loop
3035 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
3040 -- Function case, generate:
3041 -- return <Unprot_Func_Call>;
3043 if Nkind (Spec) = N_Function_Specification then
3045 Make_Simple_Return_Statement (Loc,
3047 Make_Function_Call (Loc,
3049 Make_Identifier (Loc, Chars (Unprot_Id)),
3050 Parameter_Associations => Actuals));
3052 -- Procedure case, call the unprotected version
3056 Make_Procedure_Call_Statement (Loc,
3058 Make_Identifier (Loc, Chars (Unprot_Id)),
3059 Parameter_Associations => Actuals);
3063 Make_Subprogram_Body (Loc,
3064 Declarations => Empty_List,
3065 Specification => Prot_Spec,
3066 Handled_Statement_Sequence =>
3067 Make_Handled_Sequence_Of_Statements (Loc,
3068 Statements => New_List (Stmt)));
3069 end Build_Lock_Free_Protected_Subprogram_Body;
3071 -------------------------------------------------
3072 -- Build_Lock_Free_Unprotected_Subprogram_Body --
3073 -------------------------------------------------
3075 -- Procedures which meet the lock-free implementation requirements and
3076 -- reference a unique scalar component Comp are expanded in the following
3079 -- procedure P (...) is
3080 -- Expected_Comp : constant Comp_Type :=
3082 -- (System.Atomic_Primitives.Lock_Free_Read_N
3083 -- (_Object.Comp'Address));
3087 -- <original declarations before the object renaming declaration
3090 -- Desired_Comp : Comp_Type := Expected_Comp;
3091 -- Comp : Comp_Type renames Desired_Comp;
3093 -- <original delarations after the object renaming declaration
3097 -- <original statements>
3098 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3099 -- (_Object.Comp'Address,
3100 -- Interfaces.Unsigned_N (Expected_Comp),
3101 -- Interfaces.Unsigned_N (Desired_Comp));
3106 -- Each return and raise statement of P is transformed into an atomic
3109 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3110 -- (_Object.Comp'Address,
3111 -- Interfaces.Unsigned_N (Expected_Comp),
3112 -- Interfaces.Unsigned_N (Desired_Comp));
3114 -- <original statement>
3119 -- Functions which meet the lock-free implementation requirements and
3120 -- reference a unique scalar component Comp are expanded in the following
3123 -- function F (...) return ... is
3124 -- <original declarations before the object renaming declaration
3127 -- Expected_Comp : constant Comp_Type :=
3129 -- (System.Atomic_Primitives.Lock_Free_Read_N
3130 -- (_Object.Comp'Address));
3131 -- Comp : Comp_Type renames Expected_Comp;
3133 -- <original delarations after the object renaming declaration of
3137 -- <original statements>
3140 function Build_Lock_Free_Unprotected_Subprogram_Body
3142 Prot_Typ : Node_Id) return Node_Id
3144 function Referenced_Component (N : Node_Id) return Entity_Id;
3145 -- Subprograms which meet the lock-free implementation criteria are
3146 -- allowed to reference only one unique component. Return the prival
3147 -- of the said component.
3149 --------------------------
3150 -- Referenced_Component --
3151 --------------------------
3153 function Referenced_Component (N : Node_Id) return Entity_Id is
3156 Source_Comp : Entity_Id := Empty;
3159 -- Find the unique source component which N references in its
3162 for Index in 1 .. Lock_Free_Subprogram_Table.Last loop
3164 Element : Lock_Free_Subprogram renames
3165 Lock_Free_Subprogram_Table.Table (Index);
3167 if Element.Sub_Body = N then
3168 Source_Comp := Element.Comp_Id;
3174 if No (Source_Comp) then
3178 -- Find the prival which corresponds to the source component within
3179 -- the declarations of N.
3181 Decl := First (Declarations (N));
3182 while Present (Decl) loop
3184 -- Privals appear as object renamings
3186 if Nkind (Decl) = N_Object_Renaming_Declaration then
3187 Comp := Defining_Identifier (Decl);
3189 if Present (Prival_Link (Comp))
3190 and then Prival_Link (Comp) = Source_Comp
3200 end Referenced_Component;
3204 Comp : constant Entity_Id := Referenced_Component (N);
3205 Loc : constant Source_Ptr := Sloc (N);
3206 Hand_Stmt_Seq : Node_Id := Handled_Statement_Sequence (N);
3207 Decls : List_Id := Declarations (N);
3209 -- Start of processing for Build_Lock_Free_Unprotected_Subprogram_Body
3212 -- Add renamings for the protection object, discriminals, privals and
3213 -- the entry index constant for use by debugger.
3215 Debug_Private_Data_Declarations (Decls);
3217 -- Perform the lock-free expansion when the subprogram references a
3218 -- protected component.
3220 if Present (Comp) then
3221 Protected_Component_Ref : declare
3222 Comp_Decl : constant Node_Id := Parent (Comp);
3223 Comp_Sel_Nam : constant Node_Id := Name (Comp_Decl);
3224 Comp_Type : constant Entity_Id := Etype (Comp);
3226 Is_Procedure : constant Boolean :=
3227 Ekind (Corresponding_Spec (N)) = E_Procedure;
3228 -- Indicates if N is a protected procedure body
3230 Block_Decls : List_Id;
3231 Try_Write : Entity_Id;
3232 Desired_Comp : Entity_Id;
3235 Label_Id : Entity_Id := Empty;
3237 Expected_Comp : Entity_Id;
3240 New_Copy_List (Statements (Hand_Stmt_Seq));
3242 Unsigned : Entity_Id;
3244 function Process_Node (N : Node_Id) return Traverse_Result;
3245 -- Transform a single node if it is a return statement, a raise
3246 -- statement or a reference to Comp.
3248 procedure Process_Stmts (Stmts : List_Id);
3249 -- Given a statement sequence Stmts, wrap any return or raise
3250 -- statements in the following manner:
3252 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3253 -- (_Object.Comp'Address,
3254 -- Interfaces.Unsigned_N (Expected_Comp),
3255 -- Interfaces.Unsigned_N (Desired_Comp))
3266 function Process_Node (N : Node_Id) return Traverse_Result is
3268 procedure Wrap_Statement (Stmt : Node_Id);
3269 -- Wrap an arbitrary statement inside an if statement where the
3270 -- condition does an atomic check on the state of the object.
3272 --------------------
3273 -- Wrap_Statement --
3274 --------------------
3276 procedure Wrap_Statement (Stmt : Node_Id) is
3278 -- The first time through, create the declaration of a label
3279 -- which is used to skip the remainder of source statements
3280 -- if the state of the object has changed.
3282 if No (Label_Id) then
3284 Make_Identifier (Loc, New_External_Name ('L', 0));
3285 Set_Entity (Label_Id,
3286 Make_Defining_Identifier (Loc, Chars (Label_Id)));
3290 -- if System.Atomic_Primitives.Lock_Free_Try_Write_N
3291 -- (_Object.Comp'Address,
3292 -- Interfaces.Unsigned_N (Expected_Comp),
3293 -- Interfaces.Unsigned_N (Desired_Comp))
3301 Make_Implicit_If_Statement (N,
3303 Make_Function_Call (Loc,
3305 New_Occurrence_Of (Try_Write, Loc),
3306 Parameter_Associations => New_List (
3307 Make_Attribute_Reference (Loc,
3308 Prefix => Relocate_Node (Comp_Sel_Nam),
3309 Attribute_Name => Name_Address),
3311 Unchecked_Convert_To (Unsigned,
3312 New_Occurrence_Of (Expected_Comp, Loc)),
3314 Unchecked_Convert_To (Unsigned,
3315 New_Occurrence_Of (Desired_Comp, Loc)))),
3317 Then_Statements => New_List (Relocate_Node (Stmt)),
3319 Else_Statements => New_List (
3320 Make_Goto_Statement (Loc,
3322 New_Occurrence_Of (Entity (Label_Id), Loc)))));
3325 -- Start of processing for Process_Node
3328 -- Wrap each return and raise statement that appear inside a
3329 -- procedure. Skip the last return statement which is added by
3330 -- default since it is transformed into an exit statement.
3333 and then ((Nkind (N) = N_Simple_Return_Statement
3334 and then N /= Last (Stmts))
3335 or else Nkind (N) = N_Extended_Return_Statement
3336 or else (Nkind_In (N, N_Raise_Constraint_Error,
3337 N_Raise_Program_Error,
3339 N_Raise_Storage_Error)
3340 and then Comes_From_Source (N)))
3348 Set_Analyzed (N, False);
3353 procedure Process_Nodes is new Traverse_Proc (Process_Node);
3359 procedure Process_Stmts (Stmts : List_Id) is
3362 Stmt := First (Stmts);
3363 while Present (Stmt) loop
3364 Process_Nodes (Stmt);
3369 -- Start of processing for Protected_Component_Ref
3372 -- Get the type size
3374 if Known_Static_Esize (Comp_Type) then
3375 Typ_Size := UI_To_Int (Esize (Comp_Type));
3377 -- If the Esize (Object_Size) is unknown at compile time, look at
3378 -- the RM_Size (Value_Size) since it may have been set by an
3379 -- explicit representation clause.
3381 elsif Known_Static_RM_Size (Comp_Type) then
3382 Typ_Size := UI_To_Int (RM_Size (Comp_Type));
3384 -- Should not happen since this has already been checked in
3385 -- Allows_Lock_Free_Implementation (see Sem_Ch9).
3388 raise Program_Error;
3391 -- Retrieve all relevant atomic routines and types
3395 Try_Write := RTE (RE_Lock_Free_Try_Write_8);
3396 Read := RTE (RE_Lock_Free_Read_8);
3397 Unsigned := RTE (RE_Uint8);
3400 Try_Write := RTE (RE_Lock_Free_Try_Write_16);
3401 Read := RTE (RE_Lock_Free_Read_16);
3402 Unsigned := RTE (RE_Uint16);
3405 Try_Write := RTE (RE_Lock_Free_Try_Write_32);
3406 Read := RTE (RE_Lock_Free_Read_32);
3407 Unsigned := RTE (RE_Uint32);
3410 Try_Write := RTE (RE_Lock_Free_Try_Write_64);
3411 Read := RTE (RE_Lock_Free_Read_64);
3412 Unsigned := RTE (RE_Uint64);
3415 raise Program_Error;
3419 -- Expected_Comp : constant Comp_Type :=
3421 -- (System.Atomic_Primitives.Lock_Free_Read_N
3422 -- (_Object.Comp'Address));
3425 Make_Defining_Identifier (Loc,
3426 New_External_Name (Chars (Comp), Suffix => "_saved"));
3429 Make_Object_Declaration (Loc,
3430 Defining_Identifier => Expected_Comp,
3431 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3432 Constant_Present => True,
3434 Unchecked_Convert_To (Comp_Type,
3435 Make_Function_Call (Loc,
3436 Name => New_Occurrence_Of (Read, Loc),
3437 Parameter_Associations => New_List (
3438 Make_Attribute_Reference (Loc,
3439 Prefix => Relocate_Node (Comp_Sel_Nam),
3440 Attribute_Name => Name_Address)))));
3442 -- Protected procedures
3444 if Is_Procedure then
3445 -- Move the original declarations inside the generated block
3447 Block_Decls := Decls;
3449 -- Reset the declarations list of the protected procedure to
3450 -- contain only Decl.
3452 Decls := New_List (Decl);
3455 -- Desired_Comp : Comp_Type := Expected_Comp;
3458 Make_Defining_Identifier (Loc,
3459 New_External_Name (Chars (Comp), Suffix => "_current"));
3461 -- Insert the declarations of Expected_Comp and Desired_Comp in
3462 -- the block declarations right before the renaming of the
3463 -- protected component.
3465 Insert_Before (Comp_Decl,
3466 Make_Object_Declaration (Loc,
3467 Defining_Identifier => Desired_Comp,
3468 Object_Definition => New_Occurrence_Of (Comp_Type, Loc),
3470 New_Occurrence_Of (Expected_Comp, Loc)));
3472 -- Protected function
3475 Desired_Comp := Expected_Comp;
3477 -- Insert the declaration of Expected_Comp in the function
3478 -- declarations right before the renaming of the protected
3481 Insert_Before (Comp_Decl, Decl);
3484 -- Rewrite the protected component renaming declaration to be a
3485 -- renaming of Desired_Comp.
3488 -- Comp : Comp_Type renames Desired_Comp;
3491 Make_Object_Renaming_Declaration (Loc,
3492 Defining_Identifier =>
3493 Defining_Identifier (Comp_Decl),
3495 New_Occurrence_Of (Comp_Type, Loc),
3497 New_Occurrence_Of (Desired_Comp, Loc)));
3499 -- Wrap any return or raise statements in Stmts in same the manner
3500 -- described in Process_Stmts.
3502 Process_Stmts (Stmts);
3505 -- exit when System.Atomic_Primitives.Lock_Free_Try_Write_N
3506 -- (_Object.Comp'Address,
3507 -- Interfaces.Unsigned_N (Expected_Comp),
3508 -- Interfaces.Unsigned_N (Desired_Comp))
3510 if Is_Procedure then
3512 Make_Exit_Statement (Loc,
3514 Make_Function_Call (Loc,
3516 New_Occurrence_Of (Try_Write, Loc),
3517 Parameter_Associations => New_List (
3518 Make_Attribute_Reference (Loc,
3519 Prefix => Relocate_Node (Comp_Sel_Nam),
3520 Attribute_Name => Name_Address),
3522 Unchecked_Convert_To (Unsigned,
3523 New_Occurrence_Of (Expected_Comp, Loc)),
3525 Unchecked_Convert_To (Unsigned,
3526 New_Occurrence_Of (Desired_Comp, Loc)))));
3528 -- Small optimization: transform the default return statement
3529 -- of a procedure into the atomic exit statement.
3531 if Nkind (Last (Stmts)) = N_Simple_Return_Statement then
3532 Rewrite (Last (Stmts), Stmt);
3534 Append_To (Stmts, Stmt);
3538 -- Create the declaration of the label used to skip the rest of
3539 -- the source statements when the object state changes.
3541 if Present (Label_Id) then
3542 Label := Make_Label (Loc, Label_Id);
3544 Make_Implicit_Label_Declaration (Loc,
3545 Defining_Identifier => Entity (Label_Id),
3546 Label_Construct => Label));
3547 Append_To (Stmts, Label);
3559 if Is_Procedure then
3562 Make_Loop_Statement (Loc,
3563 Statements => New_List (
3564 Make_Block_Statement (Loc,
3565 Declarations => Block_Decls,
3566 Handled_Statement_Sequence =>
3567 Make_Handled_Sequence_Of_Statements (Loc,
3568 Statements => Stmts))),
3569 End_Label => Empty));
3573 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts);
3574 end Protected_Component_Ref;
3577 -- Make an unprotected version of the subprogram for use within the same
3578 -- object, with new name and extra parameter representing the object.
3581 Make_Subprogram_Body (Loc,
3583 Build_Protected_Sub_Specification (N, Prot_Typ, Unprotected_Mode),
3584 Declarations => Decls,
3585 Handled_Statement_Sequence => Hand_Stmt_Seq);
3586 end Build_Lock_Free_Unprotected_Subprogram_Body;
3588 -------------------------
3589 -- Build_Master_Entity --
3590 -------------------------
3592 procedure Build_Master_Entity (Obj_Or_Typ : Entity_Id) is
3593 Loc : constant Source_Ptr := Sloc (Obj_Or_Typ);
3595 Context_Id : Entity_Id;
3601 if Is_Itype (Obj_Or_Typ) then
3602 Par := Associated_Node_For_Itype (Obj_Or_Typ);
3604 Par := Parent (Obj_Or_Typ);
3607 -- When creating a master for a record component which is either a task
3608 -- or access-to-task, the enclosing record is the master scope and the
3609 -- proper insertion point is the component list.
3611 if Is_Record_Type (Current_Scope) then
3613 Context_Id := Current_Scope;
3614 Decls := List_Containing (Context);
3616 -- Default case for object declarations and access types. Note that the
3617 -- context is updated to the nearest enclosing body, block, package or
3618 -- return statement.
3621 Find_Enclosing_Context (Par, Context, Context_Id, Decls);
3624 -- Do not create a master if one already exists or there is no task
3627 if Has_Master_Entity (Context_Id)
3628 or else Restriction_Active (No_Task_Hierarchy)
3633 -- Create a master, generate:
3634 -- _Master : constant Master_Id := Current_Master.all;
3637 Make_Object_Declaration (Loc,
3638 Defining_Identifier =>
3639 Make_Defining_Identifier (Loc, Name_uMaster),
3640 Constant_Present => True,
3641 Object_Definition => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3643 Make_Explicit_Dereference (Loc,
3644 New_Occurrence_Of (RTE (RE_Current_Master), Loc)));
3646 -- The master is inserted at the start of the declarative list of the
3649 Prepend_To (Decls, Decl);
3651 -- In certain cases where transient scopes are involved, the immediate
3652 -- scope is not always the proper master scope. Ensure that the master
3653 -- declaration and entity appear in the same context.
3655 if Context_Id /= Current_Scope then
3656 Push_Scope (Context_Id);
3663 -- Mark the enclosing scope and its associated construct as being task
3666 Set_Has_Master_Entity (Context_Id);
3668 while Present (Context)
3669 and then Nkind (Context) /= N_Compilation_Unit
3671 if Nkind_In (Context, N_Block_Statement,
3675 Set_Is_Task_Master (Context);
3678 elsif Nkind (Parent (Context)) = N_Subunit then
3679 Context := Corresponding_Stub (Parent (Context));
3682 Context := Parent (Context);
3684 end Build_Master_Entity;
3686 ---------------------------
3687 -- Build_Master_Renaming --
3688 ---------------------------
3690 procedure Build_Master_Renaming
3691 (Ptr_Typ : Entity_Id;
3692 Ins_Nod : Node_Id := Empty)
3694 Loc : constant Source_Ptr := Sloc (Ptr_Typ);
3696 Master_Decl : Node_Id;
3697 Master_Id : Entity_Id;
3700 -- Nothing to do if there is no task hierarchy
3702 if Restriction_Active (No_Task_Hierarchy) then
3706 -- Determine the proper context to insert the master renaming
3708 if Present (Ins_Nod) then
3710 elsif Is_Itype (Ptr_Typ) then
3711 Context := Associated_Node_For_Itype (Ptr_Typ);
3713 Context := Parent (Ptr_Typ);
3717 -- <Ptr_Typ>M : Master_Id renames _Master;
3720 Make_Defining_Identifier (Loc,
3721 New_External_Name (Chars (Ptr_Typ), 'M'));
3724 Make_Object_Renaming_Declaration (Loc,
3725 Defining_Identifier => Master_Id,
3726 Subtype_Mark => New_Occurrence_Of (RTE (RE_Master_Id), Loc),
3727 Name => Make_Identifier (Loc, Name_uMaster));
3729 Insert_Action (Context, Master_Decl);
3731 -- The renamed master now services the access type
3733 Set_Master_Id (Ptr_Typ, Master_Id);
3734 end Build_Master_Renaming;
3736 -----------------------------------------
3737 -- Build_Private_Protected_Declaration --
3738 -----------------------------------------
3740 function Build_Private_Protected_Declaration
3741 (N : Node_Id) return Entity_Id
3743 Loc : constant Source_Ptr := Sloc (N);
3744 Body_Id : constant Entity_Id := Defining_Entity (N);
3749 Spec_Id : Entity_Id;
3752 Formal := First_Formal (Body_Id);
3754 -- The protected operation always has at least one formal, namely the
3755 -- object itself, but it is only placed in the parameter list if
3756 -- expansion is enabled.
3758 if Present (Formal) or else Expander_Active then
3759 Plist := Copy_Parameter_List (Body_Id);
3764 if Nkind (Specification (N)) = N_Procedure_Specification then
3766 Make_Procedure_Specification (Loc,
3767 Defining_Unit_Name =>
3768 Make_Defining_Identifier (Sloc (Body_Id),
3769 Chars => Chars (Body_Id)),
3770 Parameter_Specifications =>
3774 Make_Function_Specification (Loc,
3775 Defining_Unit_Name =>
3776 Make_Defining_Identifier (Sloc (Body_Id),
3777 Chars => Chars (Body_Id)),
3778 Parameter_Specifications => Plist,
3779 Result_Definition =>
3780 New_Occurrence_Of (Etype (Body_Id), Loc));
3783 Decl := Make_Subprogram_Declaration (Loc, Specification => New_Spec);
3784 Insert_Before (N, Decl);
3785 Spec_Id := Defining_Unit_Name (New_Spec);
3787 -- Indicate that the entity comes from source, to ensure that cross-
3788 -- reference information is properly generated. The body itself is
3789 -- rewritten during expansion, and the body entity will not appear in
3790 -- calls to the operation.
3792 Set_Comes_From_Source (Spec_Id, True);
3794 Set_Has_Completion (Spec_Id);
3795 Set_Convention (Spec_Id, Convention_Protected);
3797 end Build_Private_Protected_Declaration;
3799 ---------------------------
3800 -- Build_Protected_Entry --
3801 ---------------------------
3803 function Build_Protected_Entry
3806 Pid : Node_Id) return Node_Id
3808 Loc : constant Source_Ptr := Sloc (N);
3810 Decls : constant List_Id := Declarations (N);
3811 End_Lab : constant Node_Id :=
3812 End_Label (Handled_Statement_Sequence (N));
3813 End_Loc : constant Source_Ptr :=
3814 Sloc (Last (Statements (Handled_Statement_Sequence (N))));
3815 -- Used for the generated call to Complete_Entry_Body
3817 Han_Loc : Source_Ptr;
3818 -- Used for the exception handler, inserted at end of the body
3820 Op_Decls : constant List_Id := New_List;
3828 -- Set the source location on the exception handler only when debugging
3829 -- the expanded code (see Make_Implicit_Exception_Handler).
3831 if Debug_Generated_Code then
3834 -- Otherwise the inserted code should not be visible to the debugger
3837 Han_Loc := No_Location;
3841 Make_Defining_Identifier (Loc,
3842 Chars => Chars (Protected_Body_Subprogram (Ent)));
3844 Build_Protected_Entry_Specification (Loc, Edef, Empty);
3846 -- Add the following declarations:
3848 -- type poVP is access poV;
3849 -- _object : poVP := poVP (_O);
3851 -- where _O is the formal parameter associated with the concurrent
3852 -- object. These declarations are needed for Complete_Entry_Body.
3854 Add_Object_Pointer (Loc, Pid, Op_Decls);
3856 -- Add renamings for all formals, the Protection object, discriminals,
3857 -- privals and the entry index constant for use by debugger.
3859 Add_Formal_Renamings (Espec, Op_Decls, Ent, Loc);
3860 Debug_Private_Data_Declarations (Decls);
3862 -- Put the declarations and the statements from the entry
3866 Make_Block_Statement (Loc,
3867 Declarations => Decls,
3868 Handled_Statement_Sequence =>
3869 Handled_Statement_Sequence (N)));
3871 case Corresponding_Runtime_Package (Pid) is
3872 when System_Tasking_Protected_Objects_Entries =>
3873 Append_To (Op_Stats,
3874 Make_Procedure_Call_Statement (End_Loc,
3876 New_Occurrence_Of (RTE (RE_Complete_Entry_Body), Loc),
3877 Parameter_Associations => New_List (
3878 Make_Attribute_Reference (End_Loc,
3880 Make_Selected_Component (End_Loc,
3882 Make_Identifier (End_Loc, Name_uObject),
3884 Make_Identifier (End_Loc, Name_uObject)),
3885 Attribute_Name => Name_Unchecked_Access))));
3887 when System_Tasking_Protected_Objects_Single_Entry =>
3889 -- Historically, a call to Complete_Single_Entry_Body was
3890 -- inserted, but it was a null procedure.
3895 raise Program_Error;
3898 -- When exceptions can not be propagated, we never need to call
3899 -- Exception_Complete_Entry_Body
3901 if No_Exception_Handlers_Set then
3903 Make_Subprogram_Body (Loc,
3904 Specification => Espec,
3905 Declarations => Op_Decls,
3906 Handled_Statement_Sequence =>
3907 Make_Handled_Sequence_Of_Statements (Loc,
3908 Statements => Op_Stats,
3909 End_Label => End_Lab));
3912 Ohandle := Make_Others_Choice (Loc);
3913 Set_All_Others (Ohandle);
3915 case Corresponding_Runtime_Package (Pid) is
3916 when System_Tasking_Protected_Objects_Entries =>
3919 (RTE (RE_Exceptional_Complete_Entry_Body), Loc);
3921 when System_Tasking_Protected_Objects_Single_Entry =>
3924 (RTE (RE_Exceptional_Complete_Single_Entry_Body), Loc);
3927 raise Program_Error;
3930 -- Establish link between subprogram body entity and source entry
3932 Set_Corresponding_Protected_Entry (Edef, Ent);
3934 -- Create body of entry procedure. The renaming declarations are
3935 -- placed ahead of the block that contains the actual entry body.
3938 Make_Subprogram_Body (Loc,
3939 Specification => Espec,
3940 Declarations => Op_Decls,
3941 Handled_Statement_Sequence =>
3942 Make_Handled_Sequence_Of_Statements (Loc,
3943 Statements => Op_Stats,
3944 End_Label => End_Lab,
3945 Exception_Handlers => New_List (
3946 Make_Implicit_Exception_Handler (Han_Loc,
3947 Exception_Choices => New_List (Ohandle),
3949 Statements => New_List (
3950 Make_Procedure_Call_Statement (Han_Loc,
3952 Parameter_Associations => New_List (
3953 Make_Attribute_Reference (Han_Loc,
3955 Make_Selected_Component (Han_Loc,
3957 Make_Identifier (Han_Loc, Name_uObject),
3959 Make_Identifier (Han_Loc, Name_uObject)),
3960 Attribute_Name => Name_Unchecked_Access),
3962 Make_Function_Call (Han_Loc,
3963 Name => New_Occurrence_Of (
3964 RTE (RE_Get_GNAT_Exception), Loc)))))))));
3966 end Build_Protected_Entry;
3968 -----------------------------------------
3969 -- Build_Protected_Entry_Specification --
3970 -----------------------------------------
3972 function Build_Protected_Entry_Specification
3975 Ent_Id : Entity_Id) return Node_Id
3977 P : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uP);
3980 Set_Debug_Info_Needed (Def_Id);
3982 if Present (Ent_Id) then
3983 Append_Elmt (P, Accept_Address (Ent_Id));
3987 Make_Procedure_Specification (Loc,
3988 Defining_Unit_Name => Def_Id,
3989 Parameter_Specifications => New_List (
3990 Make_Parameter_Specification (Loc,
3991 Defining_Identifier =>
3992 Make_Defining_Identifier (Loc, Name_uO),
3994 New_Occurrence_Of (RTE (RE_Address), Loc)),
3996 Make_Parameter_Specification (Loc,
3997 Defining_Identifier => P,
3999 New_Occurrence_Of (RTE (RE_Address), Loc)),
4001 Make_Parameter_Specification (Loc,
4002 Defining_Identifier =>
4003 Make_Defining_Identifier (Loc, Name_uE),
4005 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc))));
4006 end Build_Protected_Entry_Specification;
4008 --------------------------
4009 -- Build_Protected_Spec --
4010 --------------------------
4012 function Build_Protected_Spec
4014 Obj_Type : Entity_Id;
4016 Unprotected : Boolean := False) return List_Id
4018 Loc : constant Source_Ptr := Sloc (N);
4021 New_Plist : List_Id;
4022 New_Param : Node_Id;
4025 New_Plist := New_List;
4027 Formal := First_Formal (Ident);
4028 while Present (Formal) loop
4030 Make_Parameter_Specification (Loc,
4031 Defining_Identifier =>
4032 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4033 Aliased_Present => Aliased_Present (Parent (Formal)),
4034 In_Present => In_Present (Parent (Formal)),
4035 Out_Present => Out_Present (Parent (Formal)),
4036 Parameter_Type => New_Occurrence_Of (Etype (Formal), Loc));
4039 Set_Protected_Formal (Formal, Defining_Identifier (New_Param));
4042 Append (New_Param, New_Plist);
4043 Next_Formal (Formal);
4046 -- If the subprogram is a procedure and the context is not an access
4047 -- to protected subprogram, the parameter is in-out. Otherwise it is
4051 Make_Parameter_Specification (Loc,
4052 Defining_Identifier =>
4053 Make_Defining_Identifier (Loc, Name_uObject),
4056 (Etype (Ident) = Standard_Void_Type
4057 and then not Is_RTE (Obj_Type, RE_Address)),
4059 New_Occurrence_Of (Obj_Type, Loc));
4060 Set_Debug_Info_Needed (Defining_Identifier (Decl));
4061 Prepend_To (New_Plist, Decl);
4064 end Build_Protected_Spec;
4066 ---------------------------------------
4067 -- Build_Protected_Sub_Specification --
4068 ---------------------------------------
4070 function Build_Protected_Sub_Specification
4072 Prot_Typ : Entity_Id;
4073 Mode : Subprogram_Protection_Mode) return Node_Id
4075 Loc : constant Source_Ptr := Sloc (N);
4079 New_Plist : List_Id;
4082 Append_Chr : constant array (Subprogram_Protection_Mode) of Character :=
4083 (Dispatching_Mode => ' ',
4084 Protected_Mode => 'P',
4085 Unprotected_Mode => 'N');
4088 if Ekind (Defining_Unit_Name (Specification (N))) =
4091 Decl := Unit_Declaration_Node (Corresponding_Spec (N));
4096 Def_Id := Defining_Unit_Name (Specification (Decl));
4099 Build_Protected_Spec
4100 (Decl, Corresponding_Record_Type (Prot_Typ), Def_Id,
4101 Mode = Unprotected_Mode);
4103 Make_Defining_Identifier (Loc,
4104 Chars => Build_Selected_Name (Prot_Typ, Def_Id, Append_Chr (Mode)));
4106 -- The unprotected operation carries the user code, and debugging
4107 -- information must be generated for it, even though this spec does
4108 -- not come from source. It is also convenient to allow gdb to step
4109 -- into the protected operation, even though it only contains lock/
4112 Set_Debug_Info_Needed (New_Id);
4114 -- If a pragma Eliminate applies to the source entity, the internal
4115 -- subprograms will be eliminated as well.
4117 Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id));
4119 if Nkind (Specification (Decl)) = N_Procedure_Specification then
4121 Make_Procedure_Specification (Loc,
4122 Defining_Unit_Name => New_Id,
4123 Parameter_Specifications => New_Plist);
4125 -- Create a new specification for the anonymous subprogram type
4129 Make_Function_Specification (Loc,
4130 Defining_Unit_Name => New_Id,
4131 Parameter_Specifications => New_Plist,
4132 Result_Definition =>
4133 Copy_Result_Type (Result_Definition (Specification (Decl))));
4135 Set_Return_Present (Defining_Unit_Name (New_Spec));
4139 end Build_Protected_Sub_Specification;
4141 -------------------------------------
4142 -- Build_Protected_Subprogram_Body --
4143 -------------------------------------
4145 function Build_Protected_Subprogram_Body
4148 N_Op_Spec : Node_Id) return Node_Id
4150 Loc : constant Source_Ptr := Sloc (N);
4152 P_Op_Spec : Node_Id;
4155 Unprot_Call : Node_Id;
4157 Lock_Name : Node_Id;
4158 Lock_Stmt : Node_Id;
4160 Return_Stmt : Node_Id := Empty; -- init to avoid gcc 3 warning
4161 Pre_Stmts : List_Id := No_List; -- init to avoid gcc 3 warning
4163 Object_Parm : Node_Id;
4168 Op_Spec := Specification (N);
4169 Exc_Safe := Is_Exception_Safe (N);
4172 Build_Protected_Sub_Specification (N, Pid, Protected_Mode);
4174 -- Build a list of the formal parameters of the protected version of
4175 -- the subprogram to use as the actual parameters of the unprotected
4178 Uactuals := New_List;
4179 Pformal := First (Parameter_Specifications (P_Op_Spec));
4180 while Present (Pformal) loop
4181 Append_To (Uactuals,
4182 Make_Identifier (Loc, Chars (Defining_Identifier (Pformal))));
4186 -- Make a call to the unprotected version of the subprogram built above
4187 -- for use by the protected version built below.
4189 if Nkind (Op_Spec) = N_Function_Specification then
4191 R := Make_Temporary (Loc, 'R');
4193 Make_Object_Declaration (Loc,
4194 Defining_Identifier => R,
4195 Constant_Present => True,
4196 Object_Definition => New_Copy (Result_Definition (N_Op_Spec)),
4198 Make_Function_Call (Loc,
4199 Name => Make_Identifier (Loc,
4200 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
4201 Parameter_Associations => Uactuals));
4204 Make_Simple_Return_Statement (Loc,
4205 Expression => New_Occurrence_Of (R, Loc));
4208 Unprot_Call := Make_Simple_Return_Statement (Loc,
4209 Expression => Make_Function_Call (Loc,
4211 Make_Identifier (Loc,
4212 Chars => Chars (Defining_Unit_Name (N_Op_Spec))),
4213 Parameter_Associations => Uactuals));
4216 Lock_Kind := RE_Lock_Read_Only;
4220 Make_Procedure_Call_Statement (Loc,
4222 Make_Identifier (Loc, Chars (Defining_Unit_Name (N_Op_Spec))),
4223 Parameter_Associations => Uactuals);
4225 Lock_Kind := RE_Lock;
4228 -- Wrap call in block that will be covered by an at_end handler
4230 if not Exc_Safe then
4231 Unprot_Call := Make_Block_Statement (Loc,
4232 Handled_Statement_Sequence =>
4233 Make_Handled_Sequence_Of_Statements (Loc,
4234 Statements => New_List (Unprot_Call)));
4237 -- Make the protected subprogram body. This locks the protected
4238 -- object and calls the unprotected version of the subprogram.
4240 case Corresponding_Runtime_Package (Pid) is
4241 when System_Tasking_Protected_Objects_Entries =>
4242 Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entries), Loc);
4244 when System_Tasking_Protected_Objects_Single_Entry =>
4245 Lock_Name := New_Occurrence_Of (RTE (RE_Lock_Entry), Loc);
4247 when System_Tasking_Protected_Objects =>
4248 Lock_Name := New_Occurrence_Of (RTE (Lock_Kind), Loc);
4251 raise Program_Error;
4255 Make_Attribute_Reference (Loc,
4257 Make_Selected_Component (Loc,
4258 Prefix => Make_Identifier (Loc, Name_uObject),
4259 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4260 Attribute_Name => Name_Unchecked_Access);
4262 Lock_Stmt := Make_Procedure_Call_Statement (Loc,
4264 Parameter_Associations => New_List (Object_Parm));
4266 if Abort_Allowed then
4268 Make_Procedure_Call_Statement (Loc,
4269 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
4270 Parameter_Associations => Empty_List),
4274 Stmts := New_List (Lock_Stmt);
4277 if not Exc_Safe then
4278 Append (Unprot_Call, Stmts);
4280 if Nkind (Op_Spec) = N_Function_Specification then
4282 Stmts := Empty_List;
4284 Append (Unprot_Call, Stmts);
4287 -- Historical note: Previously, call to the cleanup was inserted
4288 -- here. This is now done by Build_Protected_Subprogram_Call_Cleanup,
4289 -- which is also shared by the 'not Exc_Safe' path.
4291 Build_Protected_Subprogram_Call_Cleanup (Op_Spec, Pid, Loc, Stmts);
4293 if Nkind (Op_Spec) = N_Function_Specification then
4294 Append (Return_Stmt, Stmts);
4295 Append (Make_Block_Statement (Loc,
4296 Declarations => New_List (Unprot_Call),
4297 Handled_Statement_Sequence =>
4298 Make_Handled_Sequence_Of_Statements (Loc,
4299 Statements => Stmts)), Pre_Stmts);
4305 Make_Subprogram_Body (Loc,
4306 Declarations => Empty_List,
4307 Specification => P_Op_Spec,
4308 Handled_Statement_Sequence =>
4309 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts));
4311 -- Mark this subprogram as a protected subprogram body so that the
4312 -- cleanup will be inserted. This is done only in the 'not Exc_Safe'
4313 -- path as otherwise the cleanup has already been inserted.
4315 if not Exc_Safe then
4316 Set_Is_Protected_Subprogram_Body (Sub_Body);
4320 end Build_Protected_Subprogram_Body;
4322 -------------------------------------
4323 -- Build_Protected_Subprogram_Call --
4324 -------------------------------------
4326 procedure Build_Protected_Subprogram_Call
4330 External : Boolean := True)
4332 Loc : constant Source_Ptr := Sloc (N);
4333 Sub : constant Entity_Id := Entity (Name);
4339 New_Sub := New_Occurrence_Of (External_Subprogram (Sub), Loc);
4342 New_Occurrence_Of (Protected_Body_Subprogram (Sub), Loc);
4345 if Present (Parameter_Associations (N)) then
4346 Params := New_Copy_List_Tree (Parameter_Associations (N));
4351 -- If the type is an untagged derived type, convert to the root type,
4352 -- which is the one on which the operations are defined.
4354 if Nkind (Rec) = N_Unchecked_Type_Conversion
4355 and then not Is_Tagged_Type (Etype (Rec))
4356 and then Is_Derived_Type (Etype (Rec))
4358 Set_Etype (Rec, Root_Type (Etype (Rec)));
4359 Set_Subtype_Mark (Rec,
4360 New_Occurrence_Of (Root_Type (Etype (Rec)), Sloc (N)));
4363 Prepend (Rec, Params);
4365 if Ekind (Sub) = E_Procedure then
4367 Make_Procedure_Call_Statement (Loc,
4369 Parameter_Associations => Params));
4372 pragma Assert (Ekind (Sub) = E_Function);
4374 Make_Function_Call (Loc,
4376 Parameter_Associations => Params));
4378 -- Preserve type of call for subsequent processing (required for
4379 -- call to Wrap_Transient_Expression in the case of a shared passive
4382 Set_Etype (N, Etype (New_Sub));
4386 and then Nkind (Rec) = N_Unchecked_Type_Conversion
4387 and then Is_Entity_Name (Expression (Rec))
4388 and then Is_Shared_Passive (Entity (Expression (Rec)))
4390 Add_Shared_Var_Lock_Procs (N);
4392 end Build_Protected_Subprogram_Call;
4394 ---------------------------------------------
4395 -- Build_Protected_Subprogram_Call_Cleanup --
4396 ---------------------------------------------
4398 procedure Build_Protected_Subprogram_Call_Cleanup
4407 -- If the associated protected object has entries, a protected
4408 -- procedure has to service entry queues. In this case generate:
4410 -- Service_Entries (_object._object'Access);
4412 if Nkind (Op_Spec) = N_Procedure_Specification
4413 and then Has_Entries (Conc_Typ)
4415 case Corresponding_Runtime_Package (Conc_Typ) is
4416 when System_Tasking_Protected_Objects_Entries =>
4417 Nam := New_Occurrence_Of (RTE (RE_Service_Entries), Loc);
4419 when System_Tasking_Protected_Objects_Single_Entry =>
4420 Nam := New_Occurrence_Of (RTE (RE_Service_Entry), Loc);
4423 raise Program_Error;
4427 Make_Procedure_Call_Statement (Loc,
4429 Parameter_Associations => New_List (
4430 Make_Attribute_Reference (Loc,
4432 Make_Selected_Component (Loc,
4433 Prefix => Make_Identifier (Loc, Name_uObject),
4434 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4435 Attribute_Name => Name_Unchecked_Access))));
4439 -- Unlock (_object._object'Access);
4441 case Corresponding_Runtime_Package (Conc_Typ) is
4442 when System_Tasking_Protected_Objects_Entries =>
4443 Nam := New_Occurrence_Of (RTE (RE_Unlock_Entries), Loc);
4445 when System_Tasking_Protected_Objects_Single_Entry =>
4446 Nam := New_Occurrence_Of (RTE (RE_Unlock_Entry), Loc);
4448 when System_Tasking_Protected_Objects =>
4449 Nam := New_Occurrence_Of (RTE (RE_Unlock), Loc);
4452 raise Program_Error;
4456 Make_Procedure_Call_Statement (Loc,
4458 Parameter_Associations => New_List (
4459 Make_Attribute_Reference (Loc,
4461 Make_Selected_Component (Loc,
4462 Prefix => Make_Identifier (Loc, Name_uObject),
4463 Selector_Name => Make_Identifier (Loc, Name_uObject)),
4464 Attribute_Name => Name_Unchecked_Access))));
4470 if Abort_Allowed then
4472 Make_Procedure_Call_Statement (Loc,
4474 New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
4475 Parameter_Associations => Empty_List));
4477 end Build_Protected_Subprogram_Call_Cleanup;
4479 -------------------------
4480 -- Build_Selected_Name --
4481 -------------------------
4483 function Build_Selected_Name
4484 (Prefix : Entity_Id;
4485 Selector : Entity_Id;
4486 Append_Char : Character := ' ') return Name_Id
4488 Select_Buffer : String (1 .. Hostparm.Max_Name_Length);
4489 Select_Len : Natural;
4492 Get_Name_String (Chars (Selector));
4493 Select_Len := Name_Len;
4494 Select_Buffer (1 .. Select_Len) := Name_Buffer (1 .. Name_Len);
4495 Get_Name_String (Chars (Prefix));
4497 -- If scope is anonymous type, discard suffix to recover name of
4498 -- single protected object. Otherwise use protected type name.
4500 if Name_Buffer (Name_Len) = 'T' then
4501 Name_Len := Name_Len - 1;
4504 Add_Str_To_Name_Buffer ("__");
4505 for J in 1 .. Select_Len loop
4506 Add_Char_To_Name_Buffer (Select_Buffer (J));
4509 -- Now add the Append_Char if specified. The encoding to follow
4510 -- depends on the type of entity. If Append_Char is either 'N' or 'P',
4511 -- then the entity is associated to a protected type subprogram.
4512 -- Otherwise, it is a protected type entry. For each case, the
4513 -- encoding to follow for the suffix is documented in exp_dbug.ads.
4515 -- It would be better to encapsulate this as a routine in Exp_Dbug ???
4517 if Append_Char /= ' ' then
4518 if Append_Char = 'P' or Append_Char = 'N' then
4519 Add_Char_To_Name_Buffer (Append_Char);
4522 Add_Str_To_Name_Buffer ((1 => '_', 2 => Append_Char));
4523 return New_External_Name (Name_Find, ' ', -1);
4528 end Build_Selected_Name;
4530 -----------------------------
4531 -- Build_Simple_Entry_Call --
4532 -----------------------------
4534 -- A task entry call is converted to a call to Call_Simple
4537 -- P : parms := (parm, parm, parm);
4539 -- Call_Simple (acceptor-task, entry-index, P'Address);
4545 -- Here Pnn is an aggregate of the type constructed for the entry to hold
4546 -- the parameters, and the constructed aggregate value contains either the
4547 -- parameters or, in the case of non-elementary types, references to these
4548 -- parameters. Then the address of this aggregate is passed to the runtime
4549 -- routine, along with the task id value and the task entry index value.
4550 -- Pnn is only required if parameters are present.
4552 -- The assignments after the call are present only in the case of in-out
4553 -- or out parameters for elementary types, and are used to assign back the
4554 -- resulting values of such parameters.
4556 -- Note: the reason that we insert a block here is that in the context
4557 -- of selects, conditional entry calls etc. the entry call statement
4558 -- appears on its own, not as an element of a list.
4560 -- A protected entry call is converted to a Protected_Entry_Call:
4563 -- P : E1_Params := (param, param, param);
4565 -- Bnn : Communications_Block;
4568 -- P : E1_Params := (param, param, param);
4569 -- Bnn : Communications_Block;
4572 -- Protected_Entry_Call (
4573 -- Object => po._object'Access,
4574 -- E => <entry index>;
4575 -- Uninterpreted_Data => P'Address;
4576 -- Mode => Simple_Call;
4583 procedure Build_Simple_Entry_Call
4592 -- If call has been inlined, nothing left to do
4594 if Nkind (N) = N_Block_Statement then
4598 -- Convert entry call to Call_Simple call
4601 Loc : constant Source_Ptr := Sloc (N);
4602 Parms : constant List_Id := Parameter_Associations (N);
4603 Stats : constant List_Id := New_List;
4606 Comm_Name : Entity_Id;
4610 Ent_Acc : Entity_Id;
4612 Iface_Tag : Entity_Id;
4613 Iface_Typ : Entity_Id;
4626 -- Simple entry and entry family cases merge here
4628 Ent := Entity (Ename);
4629 Ent_Acc := Entry_Parameters_Type (Ent);
4630 Conctyp := Etype (Concval);
4632 -- If prefix is an access type, dereference to obtain the task type
4634 if Is_Access_Type (Conctyp) then
4635 Conctyp := Designated_Type (Conctyp);
4638 -- Special case for protected subprogram calls
4640 if Is_Protected_Type (Conctyp)
4641 and then Is_Subprogram (Entity (Ename))
4643 if not Is_Eliminated (Entity (Ename)) then
4644 Build_Protected_Subprogram_Call
4645 (N, Ename, Convert_Concurrent (Concval, Conctyp));
4652 -- First parameter is the Task_Id value from the task value or the
4653 -- Object from the protected object value, obtained by selecting
4654 -- the _Task_Id or _Object from the result of doing an unchecked
4655 -- conversion to convert the value to the corresponding record type.
4657 if Nkind (Concval) = N_Function_Call
4658 and then Is_Task_Type (Conctyp)
4659 and then Ada_Version >= Ada_2005
4662 ExpR : constant Node_Id := Relocate_Node (Concval);
4663 Obj : constant Entity_Id := Make_Temporary (Loc, 'F', ExpR);
4668 Make_Object_Declaration (Loc,
4669 Defining_Identifier => Obj,
4670 Object_Definition => New_Occurrence_Of (Conctyp, Loc),
4671 Expression => ExpR);
4672 Set_Etype (Obj, Conctyp);
4673 Decls := New_List (Decl);
4674 Rewrite (Concval, New_Occurrence_Of (Obj, Loc));
4681 Parm1 := Concurrent_Ref (Concval);
4683 -- Second parameter is the entry index, computed by the routine
4684 -- provided for this purpose. The value of this expression is
4685 -- assigned to an intermediate variable to assure that any entry
4686 -- family index expressions are evaluated before the entry
4689 if not Is_Protected_Type (Conctyp)
4691 Corresponding_Runtime_Package (Conctyp) =
4692 System_Tasking_Protected_Objects_Entries
4694 X := Make_Defining_Identifier (Loc, Name_uX);
4697 Make_Object_Declaration (Loc,
4698 Defining_Identifier => X,
4699 Object_Definition =>
4700 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
4701 Expression => Actual_Index_Expression (
4702 Loc, Entity (Ename), Index, Concval));
4704 Append_To (Decls, Xdecl);
4705 Parm2 := New_Occurrence_Of (X, Loc);
4712 -- The third parameter is the packaged parameters. If there are
4713 -- none, then it is just the null address, since nothing is passed.
4716 Parm3 := New_Occurrence_Of (RTE (RE_Null_Address), Loc);
4719 -- Case of parameters present, where third argument is the address
4720 -- of a packaged record containing the required parameter values.
4723 -- First build a list of parameter values, which are references to
4724 -- objects of the parameter types.
4728 Actual := First_Actual (N);
4729 Formal := First_Formal (Ent);
4730 while Present (Actual) loop
4732 -- If it is a by_copy_type, copy it to a new variable. The
4733 -- packaged record has a field that points to this variable.
4735 if Is_By_Copy_Type (Etype (Actual)) then
4737 Make_Object_Declaration (Loc,
4738 Defining_Identifier => Make_Temporary (Loc, 'J'),
4739 Aliased_Present => True,
4740 Object_Definition =>
4741 New_Occurrence_Of (Etype (Formal), Loc));
4743 -- Mark the object as not needing initialization since the
4744 -- initialization is performed separately, avoiding errors
4745 -- on cases such as formals of null-excluding access types.
4747 Set_No_Initialization (N_Node);
4749 -- We must make an assignment statement separate for the
4750 -- case of limited type. We cannot assign it unless the
4751 -- Assignment_OK flag is set first. An out formal of an
4752 -- access type must also be initialized from the actual,
4753 -- as stated in RM 6.4.1 (13), but no constraint is applied
4756 if Ekind (Formal) /= E_Out_Parameter
4757 or else Is_Access_Type (Etype (Formal))
4760 New_Occurrence_Of (Defining_Identifier (N_Node), Loc);
4761 Set_Assignment_OK (N_Var);
4763 Make_Assignment_Statement (Loc,
4765 Expression => Relocate_Node (Actual)));
4767 -- If actual is an out parameter of a null-excluding
4768 -- access type, there is access check on entry, so set
4769 -- Suppress_Assignment_Checks on the generated statement
4770 -- that assigns the actual to the parameter block
4772 Set_Suppress_Assignment_Checks (Last (Stats));
4775 Append (N_Node, Decls);
4778 Make_Attribute_Reference (Loc,
4779 Attribute_Name => Name_Unchecked_Access,
4781 New_Occurrence_Of (Defining_Identifier (N_Node), Loc)));
4783 -- If it is a VM_By_Copy_Actual, copy it to a new variable
4785 elsif Is_VM_By_Copy_Actual (Actual) then
4787 Make_Object_Declaration (Loc,
4788 Defining_Identifier => Make_Temporary (Loc, 'J'),
4789 Aliased_Present => True,
4790 Object_Definition =>
4791 New_Occurrence_Of (Etype (Formal), Loc),
4792 Expression => New_Copy_Tree (Actual));
4793 Set_Assignment_OK (N_Node);
4795 Append (N_Node, Decls);
4798 Make_Attribute_Reference (Loc,
4799 Attribute_Name => Name_Unchecked_Access,
4801 New_Occurrence_Of (Defining_Identifier (N_Node), Loc)));
4804 -- Interface class-wide formal
4806 if Ada_Version >= Ada_2005
4807 and then Ekind (Etype (Formal)) = E_Class_Wide_Type
4808 and then Is_Interface (Etype (Formal))
4810 Iface_Typ := Etype (Etype (Formal));
4813 -- formal_iface_type! (actual.iface_tag)'reference
4816 Find_Interface_Tag (Etype (Actual), Iface_Typ);
4817 pragma Assert (Present (Iface_Tag));
4820 Make_Reference (Loc,
4821 Unchecked_Convert_To (Iface_Typ,
4822 Make_Selected_Component (Loc,
4824 Relocate_Node (Actual),
4826 New_Occurrence_Of (Iface_Tag, Loc)))));
4832 Make_Reference (Loc, Relocate_Node (Actual)));
4836 Next_Actual (Actual);
4837 Next_Formal_With_Extras (Formal);
4840 -- Now build the declaration of parameters initialized with the
4841 -- aggregate containing this constructed parameter list.
4843 P := Make_Defining_Identifier (Loc, Name_uP);
4846 Make_Object_Declaration (Loc,
4847 Defining_Identifier => P,
4848 Object_Definition =>
4849 New_Occurrence_Of (Designated_Type (Ent_Acc), Loc),
4851 Make_Aggregate (Loc, Expressions => Plist));
4854 Make_Attribute_Reference (Loc,
4855 Prefix => New_Occurrence_Of (P, Loc),
4856 Attribute_Name => Name_Address);
4858 Append (Pdecl, Decls);
4861 -- Now we can create the call, case of protected type
4863 if Is_Protected_Type (Conctyp) then
4864 case Corresponding_Runtime_Package (Conctyp) is
4865 when System_Tasking_Protected_Objects_Entries =>
4867 -- Change the type of the index declaration
4869 Set_Object_Definition (Xdecl,
4870 New_Occurrence_Of (RTE (RE_Protected_Entry_Index), Loc));
4872 -- Some additional declarations for protected entry calls
4878 -- Bnn : Communications_Block;
4880 Comm_Name := Make_Temporary (Loc, 'B');
4883 Make_Object_Declaration (Loc,
4884 Defining_Identifier => Comm_Name,
4885 Object_Definition =>
4887 (RTE (RE_Communication_Block), Loc)));
4889 -- Some additional statements for protected entry calls
4891 -- Protected_Entry_Call (
4892 -- Object => po._object'Access,
4893 -- E => <entry index>;
4894 -- Uninterpreted_Data => P'Address;
4895 -- Mode => Simple_Call;
4899 Make_Procedure_Call_Statement (Loc,
4901 New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
4903 Parameter_Associations => New_List (
4904 Make_Attribute_Reference (Loc,
4905 Attribute_Name => Name_Unchecked_Access,
4909 New_Occurrence_Of (RTE (RE_Simple_Call), Loc),
4910 New_Occurrence_Of (Comm_Name, Loc)));
4912 when System_Tasking_Protected_Objects_Single_Entry =>
4913 -- Protected_Single_Entry_Call (
4914 -- Object => po._object'Access,
4915 -- Uninterpreted_Data => P'Address);
4918 Make_Procedure_Call_Statement (Loc,
4919 Name => New_Occurrence_Of (
4920 RTE (RE_Protected_Single_Entry_Call), Loc),
4922 Parameter_Associations => New_List (
4923 Make_Attribute_Reference (Loc,
4924 Attribute_Name => Name_Unchecked_Access,
4929 raise Program_Error;
4932 -- Case of task type
4936 Make_Procedure_Call_Statement (Loc,
4937 Name => New_Occurrence_Of (RTE (RE_Call_Simple), Loc),
4938 Parameter_Associations => New_List (Parm1, Parm2, Parm3));
4942 Append_To (Stats, Call);
4944 -- If there are out or in/out parameters by copy add assignment
4945 -- statements for the result values.
4947 if Present (Parms) then
4948 Actual := First_Actual (N);
4949 Formal := First_Formal (Ent);
4951 Set_Assignment_OK (Actual);
4952 while Present (Actual) loop
4953 if (Is_By_Copy_Type (Etype (Actual))
4954 or else Is_VM_By_Copy_Actual (Actual))
4955 and then Ekind (Formal) /= E_In_Parameter
4958 Make_Assignment_Statement (Loc,
4959 Name => New_Copy (Actual),
4961 Make_Explicit_Dereference (Loc,
4962 Make_Selected_Component (Loc,
4963 Prefix => New_Occurrence_Of (P, Loc),
4965 Make_Identifier (Loc, Chars (Formal)))));
4967 -- In all cases (including limited private types) we want
4968 -- the assignment to be valid.
4970 Set_Assignment_OK (Name (N_Node));
4972 -- If the call is the triggering alternative in an
4973 -- asynchronous select, or the entry_call alternative of a
4974 -- conditional entry call, the assignments for in-out
4975 -- parameters are incorporated into the statement list that
4976 -- follows, so that there are executed only if the entry
4979 if (Nkind (Parent (N)) = N_Triggering_Alternative
4980 and then N = Triggering_Statement (Parent (N)))
4982 (Nkind (Parent (N)) = N_Entry_Call_Alternative
4983 and then N = Entry_Call_Statement (Parent (N)))
4985 if No (Statements (Parent (N))) then
4986 Set_Statements (Parent (N), New_List);
4989 Prepend (N_Node, Statements (Parent (N)));
4992 Insert_After (Call, N_Node);
4996 Next_Actual (Actual);
4997 Next_Formal_With_Extras (Formal);
5001 -- Finally, create block and analyze it
5004 Make_Block_Statement (Loc,
5005 Declarations => Decls,
5006 Handled_Statement_Sequence =>
5007 Make_Handled_Sequence_Of_Statements (Loc,
5008 Statements => Stats)));
5012 end Build_Simple_Entry_Call;
5014 --------------------------------
5015 -- Build_Task_Activation_Call --
5016 --------------------------------
5018 procedure Build_Task_Activation_Call (N : Node_Id) is
5019 Loc : constant Source_Ptr := Sloc (N);
5026 -- For sequential elaboration policy, all the tasks will be activated at
5027 -- the end of the elaboration.
5029 if Partition_Elaboration_Policy = 'S' then
5033 -- Get the activation chain entity. Except in the case of a package
5034 -- body, this is in the node that was passed. For a package body, we
5035 -- have to find the corresponding package declaration node.
5037 if Nkind (N) = N_Package_Body then
5038 P := Corresponding_Spec (N);
5041 exit when Nkind (P) = N_Package_Declaration;
5044 Chain := Activation_Chain_Entity (P);
5047 Chain := Activation_Chain_Entity (N);
5050 if Present (Chain) then
5051 if Restricted_Profile then
5052 Name := New_Occurrence_Of
5053 (RTE (RE_Activate_Restricted_Tasks), Loc);
5055 Name := New_Occurrence_Of
5056 (RTE (RE_Activate_Tasks), Loc);
5060 Make_Procedure_Call_Statement (Loc,
5062 Parameter_Associations =>
5063 New_List (Make_Attribute_Reference (Loc,
5064 Prefix => New_Occurrence_Of (Chain, Loc),
5065 Attribute_Name => Name_Unchecked_Access)));
5067 if Nkind (N) = N_Package_Declaration then
5068 if Present (Corresponding_Body (N)) then
5071 elsif Present (Private_Declarations (Specification (N))) then
5072 Append (Call, Private_Declarations (Specification (N)));
5075 Append (Call, Visible_Declarations (Specification (N)));
5079 if Present (Handled_Statement_Sequence (N)) then
5081 -- The call goes at the start of the statement sequence after
5082 -- the start of exception range label if one is present.
5088 Stm := First (Statements (Handled_Statement_Sequence (N)));
5090 -- A special case, skip exception range label if one is
5091 -- present (from front end zcx processing).
5093 if Nkind (Stm) = N_Label and then Exception_Junk (Stm) then
5097 -- Another special case, if the first statement is a block
5098 -- from optimization of a local raise to a goto, then the
5099 -- call goes inside this block.
5101 if Nkind (Stm) = N_Block_Statement
5102 and then Exception_Junk (Stm)
5105 First (Statements (Handled_Statement_Sequence (Stm)));
5108 -- Insertion point is after any exception label pushes,
5109 -- since we want it covered by any local handlers.
5111 while Nkind (Stm) in N_Push_xxx_Label loop
5115 -- Now we have the proper insertion point
5117 Insert_Before (Stm, Call);
5121 Set_Handled_Statement_Sequence (N,
5122 Make_Handled_Sequence_Of_Statements (Loc,
5123 Statements => New_List (Call)));
5128 Check_Task_Activation (N);
5130 end Build_Task_Activation_Call;
5132 -------------------------------
5133 -- Build_Task_Allocate_Block --
5134 -------------------------------
5136 procedure Build_Task_Allocate_Block
5141 T : constant Entity_Id := Entity (Expression (N));
5142 Init : constant Entity_Id := Base_Init_Proc (T);
5143 Loc : constant Source_Ptr := Sloc (N);
5144 Chain : constant Entity_Id :=
5145 Make_Defining_Identifier (Loc, Name_uChain);
5146 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
5151 Make_Block_Statement (Loc,
5152 Identifier => New_Occurrence_Of (Blkent, Loc),
5153 Declarations => New_List (
5155 -- _Chain : Activation_Chain;
5157 Make_Object_Declaration (Loc,
5158 Defining_Identifier => Chain,
5159 Aliased_Present => True,
5160 Object_Definition =>
5161 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
5163 Handled_Statement_Sequence =>
5164 Make_Handled_Sequence_Of_Statements (Loc,
5166 Statements => New_List (
5170 Make_Procedure_Call_Statement (Loc,
5171 Name => New_Occurrence_Of (Init, Loc),
5172 Parameter_Associations => Args),
5174 -- Activate_Tasks (_Chain);
5176 Make_Procedure_Call_Statement (Loc,
5177 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
5178 Parameter_Associations => New_List (
5179 Make_Attribute_Reference (Loc,
5180 Prefix => New_Occurrence_Of (Chain, Loc),
5181 Attribute_Name => Name_Unchecked_Access))))),
5183 Has_Created_Identifier => True,
5184 Is_Task_Allocation_Block => True);
5187 Make_Implicit_Label_Declaration (Loc,
5188 Defining_Identifier => Blkent,
5189 Label_Construct => Block));
5191 Append_To (Actions, Block);
5193 Set_Activation_Chain_Entity (Block, Chain);
5194 end Build_Task_Allocate_Block;
5196 -----------------------------------------------
5197 -- Build_Task_Allocate_Block_With_Init_Stmts --
5198 -----------------------------------------------
5200 procedure Build_Task_Allocate_Block_With_Init_Stmts
5203 Init_Stmts : List_Id)
5205 Loc : constant Source_Ptr := Sloc (N);
5206 Chain : constant Entity_Id :=
5207 Make_Defining_Identifier (Loc, Name_uChain);
5208 Blkent : constant Entity_Id := Make_Temporary (Loc, 'A');
5212 Append_To (Init_Stmts,
5213 Make_Procedure_Call_Statement (Loc,
5214 Name => New_Occurrence_Of (RTE (RE_Activate_Tasks), Loc),
5215 Parameter_Associations => New_List (
5216 Make_Attribute_Reference (Loc,
5217 Prefix => New_Occurrence_Of (Chain, Loc),
5218 Attribute_Name => Name_Unchecked_Access))));
5221 Make_Block_Statement (Loc,
5222 Identifier => New_Occurrence_Of (Blkent, Loc),
5223 Declarations => New_List (
5225 -- _Chain : Activation_Chain;
5227 Make_Object_Declaration (Loc,
5228 Defining_Identifier => Chain,
5229 Aliased_Present => True,
5230 Object_Definition =>
5231 New_Occurrence_Of (RTE (RE_Activation_Chain), Loc))),
5233 Handled_Statement_Sequence =>
5234 Make_Handled_Sequence_Of_Statements (Loc, Init_Stmts),
5236 Has_Created_Identifier => True,
5237 Is_Task_Allocation_Block => True);
5240 Make_Implicit_Label_Declaration (Loc,
5241 Defining_Identifier => Blkent,
5242 Label_Construct => Block));
5244 Append_To (Actions, Block);
5246 Set_Activation_Chain_Entity (Block, Chain);
5247 end Build_Task_Allocate_Block_With_Init_Stmts;
5249 -----------------------------------
5250 -- Build_Task_Proc_Specification --
5251 -----------------------------------
5253 function Build_Task_Proc_Specification (T : Entity_Id) return Node_Id is
5254 Loc : constant Source_Ptr := Sloc (T);
5255 Spec_Id : Entity_Id;
5258 -- Case of explicit task type, suffix TB
5260 if Comes_From_Source (T) then
5262 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), "TB"));
5264 -- Case of anonymous task type, suffix B
5268 Make_Defining_Identifier (Loc, New_External_Name (Chars (T), 'B'));
5271 Set_Is_Internal (Spec_Id);
5273 -- Associate the procedure with the task, if this is the declaration
5274 -- (and not the body) of the procedure.
5276 if No (Task_Body_Procedure (T)) then
5277 Set_Task_Body_Procedure (T, Spec_Id);
5281 Make_Procedure_Specification (Loc,
5282 Defining_Unit_Name => Spec_Id,
5283 Parameter_Specifications => New_List (
5284 Make_Parameter_Specification (Loc,
5285 Defining_Identifier =>
5286 Make_Defining_Identifier (Loc, Name_uTask),
5288 Make_Access_Definition (Loc,
5290 New_Occurrence_Of (Corresponding_Record_Type (T), Loc)))));
5291 end Build_Task_Proc_Specification;
5293 ---------------------------------------
5294 -- Build_Unprotected_Subprogram_Body --
5295 ---------------------------------------
5297 function Build_Unprotected_Subprogram_Body
5299 Pid : Node_Id) return Node_Id
5301 Decls : constant List_Id := Declarations (N);
5304 -- Add renamings for the Protection object, discriminals, privals and
5305 -- the entry index constant for use by debugger.
5307 Debug_Private_Data_Declarations (Decls);
5309 -- Make an unprotected version of the subprogram for use within the same
5310 -- object, with a new name and an additional parameter representing the
5314 Make_Subprogram_Body (Sloc (N),
5316 Build_Protected_Sub_Specification (N, Pid, Unprotected_Mode),
5317 Declarations => Decls,
5318 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
5319 end Build_Unprotected_Subprogram_Body;
5321 ----------------------------
5322 -- Collect_Entry_Families --
5323 ----------------------------
5325 procedure Collect_Entry_Families
5328 Current_Node : in out Node_Id;
5329 Conctyp : Entity_Id)
5332 Efam_Decl : Node_Id;
5333 Efam_Type : Entity_Id;
5336 Efam := First_Entity (Conctyp);
5337 while Present (Efam) loop
5338 if Ekind (Efam) = E_Entry_Family then
5339 Efam_Type := Make_Temporary (Loc, 'F');
5344 (Etype (Discrete_Subtype_Definition (Parent (Efam))));
5346 Bas_Decl : Node_Id := Empty;
5351 (Discrete_Subtype_Definition (Parent (Efam)), Lo, Hi);
5353 if Is_Potentially_Large_Family (Bas, Conctyp, Lo, Hi) then
5354 Bas := Make_Temporary (Loc, 'B');
5357 Make_Subtype_Declaration (Loc,
5358 Defining_Identifier => Bas,
5359 Subtype_Indication =>
5360 Make_Subtype_Indication (Loc,
5362 New_Occurrence_Of (Standard_Integer, Loc),
5364 Make_Range_Constraint (Loc,
5365 Range_Expression => Make_Range (Loc,
5366 Make_Integer_Literal
5367 (Loc, -Entry_Family_Bound),
5368 Make_Integer_Literal
5369 (Loc, Entry_Family_Bound - 1)))));
5371 Insert_After (Current_Node, Bas_Decl);
5372 Current_Node := Bas_Decl;
5377 Make_Full_Type_Declaration (Loc,
5378 Defining_Identifier => Efam_Type,
5380 Make_Unconstrained_Array_Definition (Loc,
5382 (New_List (New_Occurrence_Of (Bas, Loc))),
5384 Component_Definition =>
5385 Make_Component_Definition (Loc,
5386 Aliased_Present => False,
5387 Subtype_Indication =>
5388 New_Occurrence_Of (Standard_Character, Loc))));
5391 Insert_After (Current_Node, Efam_Decl);
5392 Current_Node := Efam_Decl;
5393 Analyze (Efam_Decl);
5396 Make_Component_Declaration (Loc,
5397 Defining_Identifier =>
5398 Make_Defining_Identifier (Loc, Chars (Efam)),
5400 Component_Definition =>
5401 Make_Component_Definition (Loc,
5402 Aliased_Present => False,
5403 Subtype_Indication =>
5404 Make_Subtype_Indication (Loc,
5406 New_Occurrence_Of (Efam_Type, Loc),
5409 Make_Index_Or_Discriminant_Constraint (Loc,
5410 Constraints => New_List (
5412 (Etype (Discrete_Subtype_Definition
5413 (Parent (Efam))), Loc)))))));
5419 end Collect_Entry_Families;
5421 -----------------------
5422 -- Concurrent_Object --
5423 -----------------------
5425 function Concurrent_Object
5426 (Spec_Id : Entity_Id;
5427 Conc_Typ : Entity_Id) return Entity_Id
5430 -- Parameter _O or _object
5432 if Is_Protected_Type (Conc_Typ) then
5433 return First_Formal (Protected_Body_Subprogram (Spec_Id));
5438 pragma Assert (Is_Task_Type (Conc_Typ));
5439 return First_Formal (Task_Body_Procedure (Conc_Typ));
5441 end Concurrent_Object;
5443 ----------------------
5444 -- Copy_Result_Type --
5445 ----------------------
5447 function Copy_Result_Type (Res : Node_Id) return Node_Id is
5448 New_Res : constant Node_Id := New_Copy_Tree (Res);
5453 -- If the result type is an access_to_subprogram, we must create new
5454 -- entities for its spec.
5456 if Nkind (New_Res) = N_Access_Definition
5457 and then Present (Access_To_Subprogram_Definition (New_Res))
5459 -- Provide new entities for the formals
5461 Par_Spec := First (Parameter_Specifications
5462 (Access_To_Subprogram_Definition (New_Res)));
5463 while Present (Par_Spec) loop
5464 Formal := Defining_Identifier (Par_Spec);
5465 Set_Defining_Identifier (Par_Spec,
5466 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)));
5472 end Copy_Result_Type;
5474 --------------------
5475 -- Concurrent_Ref --
5476 --------------------
5478 -- The expression returned for a reference to a concurrent object has the
5481 -- taskV!(name)._Task_Id
5485 -- objectV!(name)._Object
5487 -- for a protected object. For the case of an access to a concurrent
5488 -- object, there is an extra explicit dereference:
5490 -- taskV!(name.all)._Task_Id
5491 -- objectV!(name.all)._Object
5493 -- here taskV and objectV are the types for the associated records, which
5494 -- contain the required _Task_Id and _Object fields for tasks and protected
5495 -- objects, respectively.
5497 -- For the case of a task type name, the expression is
5501 -- i.e. a call to the Self function which returns precisely this Task_Id
5503 -- For the case of a protected type name, the expression is
5507 -- which is a renaming of the _object field of the current object
5508 -- record, passed into protected operations as a parameter.
5510 function Concurrent_Ref (N : Node_Id) return Node_Id is
5511 Loc : constant Source_Ptr := Sloc (N);
5512 Ntyp : constant Entity_Id := Etype (N);
5516 function Is_Current_Task (T : Entity_Id) return Boolean;
5517 -- Check whether the reference is to the immediately enclosing task
5518 -- type, or to an outer one (rare but legal).
5520 ---------------------
5521 -- Is_Current_Task --
5522 ---------------------
5524 function Is_Current_Task (T : Entity_Id) return Boolean is
5528 Scop := Current_Scope;
5529 while Present (Scop) and then Scop /= Standard_Standard loop
5533 elsif Is_Task_Type (Scop) then
5536 -- If this is a procedure nested within the task type, we must
5537 -- assume that it can be called from an inner task, and therefore
5538 -- cannot treat it as a local reference.
5540 elsif Is_Overloadable (Scop) and then In_Open_Scopes (T) then
5544 Scop := Scope (Scop);
5548 -- We know that we are within the task body, so should have found it
5551 raise Program_Error;
5552 end Is_Current_Task;
5554 -- Start of processing for Concurrent_Ref
5557 if Is_Access_Type (Ntyp) then
5558 Dtyp := Designated_Type (Ntyp);
5560 if Is_Protected_Type (Dtyp) then
5561 Sel := Name_uObject;
5563 Sel := Name_uTask_Id;
5567 Make_Selected_Component (Loc,
5569 Unchecked_Convert_To (Corresponding_Record_Type (Dtyp),
5570 Make_Explicit_Dereference (Loc, N)),
5571 Selector_Name => Make_Identifier (Loc, Sel));
5573 elsif Is_Entity_Name (N) and then Is_Concurrent_Type (Entity (N)) then
5574 if Is_Task_Type (Entity (N)) then
5576 if Is_Current_Task (Entity (N)) then
5578 Make_Function_Call (Loc,
5579 Name => New_Occurrence_Of (RTE (RE_Self), Loc));
5584 T_Self : constant Entity_Id := Make_Temporary (Loc, 'T');
5585 T_Body : constant Node_Id :=
5586 Parent (Corresponding_Body (Parent (Entity (N))));
5590 Make_Object_Declaration (Loc,
5591 Defining_Identifier => T_Self,
5592 Object_Definition =>
5593 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
5595 Make_Function_Call (Loc,
5596 Name => New_Occurrence_Of (RTE (RE_Self), Loc)));
5597 Prepend (Decl, Declarations (T_Body));
5599 Set_Scope (T_Self, Entity (N));
5600 return New_Occurrence_Of (T_Self, Loc);
5605 pragma Assert (Is_Protected_Type (Entity (N)));
5608 New_Occurrence_Of (Find_Protection_Object (Current_Scope), Loc);
5612 if Is_Protected_Type (Ntyp) then
5613 Sel := Name_uObject;
5615 elsif Is_Task_Type (Ntyp) then
5616 Sel := Name_uTask_Id;
5619 raise Program_Error;
5623 Make_Selected_Component (Loc,
5625 Unchecked_Convert_To (Corresponding_Record_Type (Ntyp),
5627 Selector_Name => Make_Identifier (Loc, Sel));
5631 ------------------------
5632 -- Convert_Concurrent --
5633 ------------------------
5635 function Convert_Concurrent
5637 Typ : Entity_Id) return Node_Id
5640 if not Is_Concurrent_Type (Typ) then
5644 Unchecked_Convert_To
5645 (Corresponding_Record_Type (Typ), New_Copy_Tree (N));
5647 end Convert_Concurrent;
5649 -------------------------------------
5650 -- Debug_Private_Data_Declarations --
5651 -------------------------------------
5653 procedure Debug_Private_Data_Declarations (Decls : List_Id) is
5654 Debug_Nod : Node_Id;
5658 Decl := First (Decls);
5659 while Present (Decl) and then not Comes_From_Source (Decl) loop
5661 -- Declaration for concurrent entity _object and its access type,
5662 -- along with the entry index subtype:
5663 -- type prot_typVP is access prot_typV;
5664 -- _object : prot_typVP := prot_typV (_O);
5665 -- subtype Jnn is <Type of Index> range Low .. High;
5667 if Nkind_In (Decl, N_Full_Type_Declaration, N_Object_Declaration) then
5668 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5670 -- Declaration for the Protection object, discriminals, privals and
5671 -- entry index constant:
5672 -- conc_typR : protection_typ renames _object._object;
5673 -- discr_nameD : discr_typ renames _object.discr_name;
5674 -- discr_nameD : discr_typ renames _task.discr_name;
5675 -- prival_name : comp_typ renames _object.comp_name;
5676 -- J : constant Jnn :=
5677 -- Jnn'Val (_E - <Index expression> + Jnn'Pos (Jnn'First));
5679 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
5680 Set_Debug_Info_Needed (Defining_Identifier (Decl));
5681 Debug_Nod := Debug_Renaming_Declaration (Decl);
5683 if Present (Debug_Nod) then
5684 Insert_After (Decl, Debug_Nod);
5690 end Debug_Private_Data_Declarations;
5692 ------------------------------
5693 -- Ensure_Statement_Present --
5694 ------------------------------
5696 procedure Ensure_Statement_Present (Loc : Source_Ptr; Alt : Node_Id) is
5700 if Opt.Suppress_Control_Flow_Optimizations
5701 and then Is_Empty_List (Statements (Alt))
5703 Stmt := Make_Null_Statement (Loc);
5705 -- Mark NULL statement as coming from source so that it is not
5706 -- eliminated by GIGI.
5708 -- Another covert channel. If this is a requirement, it must be
5709 -- documented in sinfo/einfo ???
5711 Set_Comes_From_Source (Stmt, True);
5713 Set_Statements (Alt, New_List (Stmt));
5715 end Ensure_Statement_Present;
5717 ----------------------------
5718 -- Entry_Index_Expression --
5719 ----------------------------
5721 function Entry_Index_Expression
5725 Ttyp : Entity_Id) return Node_Id
5735 -- The queues of entries and entry families appear in textual order in
5736 -- the associated record. The entry index is computed as the sum of the
5737 -- number of queues for all entries that precede the designated one, to
5738 -- which is added the index expression, if this expression denotes a
5739 -- member of a family.
5741 -- The following is a place holder for the count of simple entries
5743 Num := Make_Integer_Literal (Sloc, 1);
5745 -- We construct an expression which is a series of addition operations.
5746 -- The first operand is the number of single entries that precede this
5747 -- one, the second operand is the index value relative to the start of
5748 -- the referenced family, and the remaining operands are the lengths of
5749 -- the entry families that precede this entry, i.e. the constructed
5752 -- number_simple_entries +
5753 -- (s'pos (index-value) - s'pos (family'first)) + 1 +
5754 -- family'length + ...
5756 -- where index-value is the given index value, and s is the index
5757 -- subtype (we have to use pos because the subtype might be an
5758 -- enumeration type preventing direct subtraction). Note that the task
5759 -- entry array is one-indexed.
5761 -- The upper bound of the entry family may be a discriminant, so we
5762 -- retrieve the lower bound explicitly to compute offset, rather than
5763 -- using the index subtype which may mention a discriminant.
5765 if Present (Index) then
5766 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Ent)));
5774 Make_Attribute_Reference (Sloc,
5775 Attribute_Name => Name_Pos,
5776 Prefix => New_Occurrence_Of (Base_Type (S), Sloc),
5777 Expressions => New_List (Relocate_Node (Index))),
5785 -- Now add lengths of preceding entries and entry families
5787 Prev := First_Entity (Ttyp);
5789 while Chars (Prev) /= Chars (Ent)
5790 or else (Ekind (Prev) /= Ekind (Ent))
5791 or else not Sem_Ch6.Type_Conformant (Ent, Prev)
5793 if Ekind (Prev) = E_Entry then
5794 Set_Intval (Num, Intval (Num) + 1);
5796 elsif Ekind (Prev) = E_Entry_Family then
5797 S := Etype (Discrete_Subtype_Definition (Declaration_Node (Prev)));
5798 Lo := Type_Low_Bound (S);
5799 Hi := Type_High_Bound (S);
5804 Right_Opnd => Family_Size (Sloc, Hi, Lo, Ttyp, False));
5806 -- Other components are anonymous types to be ignored
5816 end Entry_Index_Expression;
5818 ---------------------------
5819 -- Establish_Task_Master --
5820 ---------------------------
5822 procedure Establish_Task_Master (N : Node_Id) is
5826 if Restriction_Active (No_Task_Hierarchy) = False then
5827 Call := Build_Runtime_Call (Sloc (N), RE_Enter_Master);
5829 -- The block may have no declarations (and nevertheless be a task
5830 -- master) if it contains a call that may return an object that
5833 if No (Declarations (N)) then
5834 Set_Declarations (N, New_List (Call));
5836 Prepend_To (Declarations (N), Call);
5841 end Establish_Task_Master;
5843 --------------------------------
5844 -- Expand_Accept_Declarations --
5845 --------------------------------
5847 -- Part of the expansion of an accept statement involves the creation of
5848 -- a declaration that can be referenced from the statement sequence of
5853 -- This declaration is inserted immediately before the accept statement
5854 -- and it is important that it be inserted before the statements of the
5855 -- statement sequence are analyzed. Thus it would be too late to create
5856 -- this declaration in the Expand_N_Accept_Statement routine, which is
5857 -- why there is a separate procedure to be called directly from Sem_Ch9.
5859 -- Ann is used to hold the address of the record containing the parameters
5860 -- (see Expand_N_Entry_Call for more details on how this record is built).
5861 -- References to the parameters do an unchecked conversion of this address
5862 -- to a pointer to the required record type, and then access the field that
5863 -- holds the value of the required parameter. The entity for the address
5864 -- variable is held as the top stack element (i.e. the last element) of the
5865 -- Accept_Address stack in the corresponding entry entity, and this element
5866 -- must be set in place before the statements are processed.
5868 -- The above description applies to the case of a stand alone accept
5869 -- statement, i.e. one not appearing as part of a select alternative.
5871 -- For the case of an accept that appears as part of a select alternative
5872 -- of a selective accept, we must still create the declaration right away,
5873 -- since Ann is needed immediately, but there is an important difference:
5875 -- The declaration is inserted before the selective accept, not before
5876 -- the accept statement (which is not part of a list anyway, and so would
5877 -- not accommodate inserted declarations)
5879 -- We only need one address variable for the entire selective accept. So
5880 -- the Ann declaration is created only for the first accept alternative,
5881 -- and subsequent accept alternatives reference the same Ann variable.
5883 -- We can distinguish the two cases by seeing whether the accept statement
5884 -- is part of a list. If not, then it must be in an accept alternative.
5886 -- To expand the requeue statement, a label is provided at the end of the
5887 -- accept statement or alternative of which it is a part, so that the
5888 -- statement can be skipped after the requeue is complete. This label is
5889 -- created here rather than during the expansion of the accept statement,
5890 -- because it will be needed by any requeue statements within the accept,
5891 -- which are expanded before the accept.
5893 procedure Expand_Accept_Declarations (N : Node_Id; Ent : Entity_Id) is
5894 Loc : constant Source_Ptr := Sloc (N);
5895 Stats : constant Node_Id := Handled_Statement_Sequence (N);
5896 Ann : Entity_Id := Empty;
5903 if Expander_Active then
5905 -- If we have no handled statement sequence, we may need to build
5906 -- a dummy sequence consisting of a null statement. This can be
5907 -- skipped if the trivial accept optimization is permitted.
5909 if not Trivial_Accept_OK
5910 and then (No (Stats) or else Null_Statements (Statements (Stats)))
5912 Set_Handled_Statement_Sequence (N,
5913 Make_Handled_Sequence_Of_Statements (Loc,
5914 Statements => New_List (Make_Null_Statement (Loc))));
5917 -- Create and declare two labels to be placed at the end of the
5918 -- accept statement. The first label is used to allow requeues to
5919 -- skip the remainder of entry processing. The second label is used
5920 -- to skip the remainder of entry processing if the rendezvous
5921 -- completes in the middle of the accept body.
5923 if Present (Handled_Statement_Sequence (N)) then
5928 Ent := Make_Temporary (Loc, 'L');
5929 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5931 Make_Implicit_Label_Declaration (Loc,
5932 Defining_Identifier => Ent,
5933 Label_Construct => Lab);
5934 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5936 Ent := Make_Temporary (Loc, 'L');
5937 Lab := Make_Label (Loc, New_Occurrence_Of (Ent, Loc));
5939 Make_Implicit_Label_Declaration (Loc,
5940 Defining_Identifier => Ent,
5941 Label_Construct => Lab);
5942 Append (Lab, Statements (Handled_Statement_Sequence (N)));
5950 -- Case of stand alone accept statement
5952 if Is_List_Member (N) then
5954 if Present (Handled_Statement_Sequence (N)) then
5955 Ann := Make_Temporary (Loc, 'A');
5958 Make_Object_Declaration (Loc,
5959 Defining_Identifier => Ann,
5960 Object_Definition =>
5961 New_Occurrence_Of (RTE (RE_Address), Loc));
5963 Insert_Before_And_Analyze (N, Adecl);
5964 Insert_Before_And_Analyze (N, Ldecl);
5965 Insert_Before_And_Analyze (N, Ldecl2);
5968 -- Case of accept statement which is in an accept alternative
5972 Acc_Alt : constant Node_Id := Parent (N);
5973 Sel_Acc : constant Node_Id := Parent (Acc_Alt);
5977 pragma Assert (Nkind (Acc_Alt) = N_Accept_Alternative);
5978 pragma Assert (Nkind (Sel_Acc) = N_Selective_Accept);
5980 -- ??? Consider a single label for select statements
5982 if Present (Handled_Statement_Sequence (N)) then
5984 Statements (Handled_Statement_Sequence (N)));
5988 Statements (Handled_Statement_Sequence (N)));
5992 -- Find first accept alternative of the selective accept. A
5993 -- valid selective accept must have at least one accept in it.
5995 Alt := First (Select_Alternatives (Sel_Acc));
5997 while Nkind (Alt) /= N_Accept_Alternative loop
6001 -- If this is the first accept statement, then we have to
6002 -- create the Ann variable, as for the stand alone case, except
6003 -- that it is inserted before the selective accept. Similarly,
6004 -- a label for requeue expansion must be declared.
6006 if N = Accept_Statement (Alt) then
6007 Ann := Make_Temporary (Loc, 'A');
6009 Make_Object_Declaration (Loc,
6010 Defining_Identifier => Ann,
6011 Object_Definition =>
6012 New_Occurrence_Of (RTE (RE_Address), Loc));
6014 Insert_Before_And_Analyze (Sel_Acc, Adecl);
6016 -- If this is not the first accept statement, then find the Ann
6017 -- variable allocated by the first accept and use it.
6021 Node (Last_Elmt (Accept_Address
6022 (Entity (Entry_Direct_Name (Accept_Statement (Alt))))));
6027 -- Merge here with Ann either created or referenced, and Adecl
6028 -- pointing to the corresponding declaration. Remaining processing
6029 -- is the same for the two cases.
6031 if Present (Ann) then
6032 Append_Elmt (Ann, Accept_Address (Ent));
6033 Set_Debug_Info_Needed (Ann);
6036 -- Create renaming declarations for the entry formals. Each reference
6037 -- to a formal becomes a dereference of a component of the parameter
6038 -- block, whose address is held in Ann. These declarations are
6039 -- eventually inserted into the accept block, and analyzed there so
6040 -- that they have the proper scope for gdb and do not conflict with
6041 -- other declarations.
6043 if Present (Parameter_Specifications (N))
6044 and then Present (Handled_Statement_Sequence (N))
6051 Renamed_Formal : Node_Id;
6055 Formal := First_Formal (Ent);
6057 while Present (Formal) loop
6058 Comp := Entry_Component (Formal);
6059 New_F := Make_Defining_Identifier (Loc, Chars (Formal));
6061 Set_Etype (New_F, Etype (Formal));
6062 Set_Scope (New_F, Ent);
6064 -- Now we set debug info needed on New_F even though it does
6065 -- not come from source, so that the debugger will get the
6066 -- right information for these generated names.
6068 Set_Debug_Info_Needed (New_F);
6070 if Ekind (Formal) = E_In_Parameter then
6071 Set_Ekind (New_F, E_Constant);
6073 Set_Ekind (New_F, E_Variable);
6074 Set_Extra_Constrained (New_F, Extra_Constrained (Formal));
6077 Set_Actual_Subtype (New_F, Actual_Subtype (Formal));
6080 Make_Selected_Component (Loc,
6082 Unchecked_Convert_To (
6083 Entry_Parameters_Type (Ent),
6084 New_Occurrence_Of (Ann, Loc)),
6086 New_Occurrence_Of (Comp, Loc));
6089 Build_Renamed_Formal_Declaration
6090 (New_F, Formal, Comp, Renamed_Formal);
6092 if No (Declarations (N)) then
6093 Set_Declarations (N, New_List);
6096 Append (Decl, Declarations (N));
6097 Set_Renamed_Object (Formal, New_F);
6098 Next_Formal (Formal);
6105 end Expand_Accept_Declarations;
6107 ---------------------------------------------
6108 -- Expand_Access_Protected_Subprogram_Type --
6109 ---------------------------------------------
6111 procedure Expand_Access_Protected_Subprogram_Type (N : Node_Id) is
6112 Loc : constant Source_Ptr := Sloc (N);
6114 T : constant Entity_Id := Defining_Identifier (N);
6115 D_T : constant Entity_Id := Designated_Type (T);
6116 D_T2 : constant Entity_Id := Make_Temporary (Loc, 'D');
6117 E_T : constant Entity_Id := Make_Temporary (Loc, 'E');
6118 P_List : constant List_Id := Build_Protected_Spec
6119 (N, RTE (RE_Address), D_T, False);
6125 -- Create access to subprogram with full signature
6127 if Etype (D_T) /= Standard_Void_Type then
6129 Make_Access_Function_Definition (Loc,
6130 Parameter_Specifications => P_List,
6131 Result_Definition =>
6132 Copy_Result_Type (Result_Definition (Type_Definition (N))));
6136 Make_Access_Procedure_Definition (Loc,
6137 Parameter_Specifications => P_List);
6141 Make_Full_Type_Declaration (Loc,
6142 Defining_Identifier => D_T2,
6143 Type_Definition => Def1);
6145 Insert_After_And_Analyze (N, Decl1);
6147 -- Associate the access to subprogram with its original access to
6148 -- protected subprogram type. Needed by the backend to know that this
6149 -- type corresponds with an access to protected subprogram type.
6151 Set_Original_Access_Type (D_T2, T);
6153 -- Create Equivalent_Type, a record with two components for an access to
6154 -- object and an access to subprogram.
6157 Make_Component_Declaration (Loc,
6158 Defining_Identifier => Make_Temporary (Loc, 'P'),
6159 Component_Definition =>
6160 Make_Component_Definition (Loc,
6161 Aliased_Present => False,
6162 Subtype_Indication =>
6163 New_Occurrence_Of (RTE (RE_Address), Loc))),
6165 Make_Component_Declaration (Loc,
6166 Defining_Identifier => Make_Temporary (Loc, 'S'),
6167 Component_Definition =>
6168 Make_Component_Definition (Loc,
6169 Aliased_Present => False,
6170 Subtype_Indication => New_Occurrence_Of (D_T2, Loc))));
6173 Make_Full_Type_Declaration (Loc,
6174 Defining_Identifier => E_T,
6176 Make_Record_Definition (Loc,
6178 Make_Component_List (Loc, Component_Items => Comps)));
6180 Insert_After_And_Analyze (Decl1, Decl2);
6181 Set_Equivalent_Type (T, E_T);
6182 end Expand_Access_Protected_Subprogram_Type;
6184 --------------------------
6185 -- Expand_Entry_Barrier --
6186 --------------------------
6188 procedure Expand_Entry_Barrier (N : Node_Id; Ent : Entity_Id) is
6189 Cond : constant Node_Id :=
6190 Condition (Entry_Body_Formal_Part (N));
6191 Prot : constant Entity_Id := Scope (Ent);
6192 Spec_Decl : constant Node_Id := Parent (Prot);
6195 Body_Decl : Node_Id;
6197 function Is_Global_Entity (N : Node_Id) return Traverse_Result;
6198 -- Check whether entity in Barrier is external to protected type.
6199 -- If so, barrier may not be properly synchronized.
6201 ----------------------
6202 -- Is_Global_Entity --
6203 ----------------------
6205 function Is_Global_Entity (N : Node_Id) return Traverse_Result is
6210 if Is_Entity_Name (N) and then Present (Entity (N)) then
6214 if Ekind (E) = E_Variable then
6215 if Scope (E) = Func then
6218 -- A protected call from a barrier to another object is ok
6220 elsif Ekind (Etype (E)) = E_Protected_Type then
6223 -- If the variable is within the package body we consider
6224 -- this safe. This is a common (if dubious) idiom.
6226 elsif S = Scope (Prot)
6227 and then Ekind_In (S, E_Package, E_Generic_Package)
6228 and then Nkind (Parent (E)) = N_Object_Declaration
6229 and then Nkind (Parent (Parent (E))) = N_Package_Body
6234 Error_Msg_N ("potentially unsynchronized barrier??", N);
6235 Error_Msg_N ("\& should be private component of type??", N);
6241 end Is_Global_Entity;
6243 procedure Check_Unprotected_Barrier is
6244 new Traverse_Proc (Is_Global_Entity);
6246 -- Start of processing for Expand_Entry_Barrier
6249 if No_Run_Time_Mode then
6250 Error_Msg_CRT ("entry barrier", N);
6254 -- The body of the entry barrier must be analyzed in the context of the
6255 -- protected object, but its scope is external to it, just as any other
6256 -- unprotected version of a protected operation. The specification has
6257 -- been produced when the protected type declaration was elaborated. We
6258 -- build the body, insert it in the enclosing scope, but analyze it in
6259 -- the current context. A more uniform approach would be to treat the
6260 -- barrier just as a protected function, and discard the protected
6261 -- version of it because it is never called.
6263 if Expander_Active then
6264 B_F := Build_Barrier_Function (N, Ent, Prot);
6265 Func := Barrier_Function (Ent);
6266 Set_Corresponding_Spec (B_F, Func);
6268 Body_Decl := Parent (Corresponding_Body (Spec_Decl));
6270 if Nkind (Parent (Body_Decl)) = N_Subunit then
6271 Body_Decl := Corresponding_Stub (Parent (Body_Decl));
6274 Insert_Before_And_Analyze (Body_Decl, B_F);
6276 Set_Discriminals (Spec_Decl);
6277 Set_Scope (Func, Scope (Prot));
6280 Analyze_And_Resolve (Cond, Any_Boolean);
6283 -- The Ravenscar profile restricts barriers to simple variables declared
6284 -- within the protected object. We also allow Boolean constants, since
6285 -- these appear in several published examples and are also allowed by
6288 -- Note that after analysis variables in this context will be replaced
6289 -- by the corresponding prival, that is to say a renaming of a selected
6290 -- component of the form _Object.Var. If expansion is disabled, as
6291 -- within a generic, we check that the entity appears in the current
6294 if Is_Entity_Name (Cond) then
6296 -- A small optimization of useless renamings. If the scope of the
6297 -- entity of the condition is not the barrier function, then the
6298 -- condition does not reference any of the generated renamings
6299 -- within the function.
6301 if Expander_Active and then Scope (Entity (Cond)) /= Func then
6302 Set_Declarations (B_F, Empty_List);
6305 if Entity (Cond) = Standard_False
6307 Entity (Cond) = Standard_True
6311 elsif not Expander_Active
6312 and then Scope (Entity (Cond)) = Current_Scope
6316 -- Check for case of _object.all.field (note that the explicit
6317 -- dereference gets inserted by analyze/expand of _object.field)
6319 elsif Present (Renamed_Object (Entity (Cond)))
6321 Nkind (Renamed_Object (Entity (Cond))) = N_Selected_Component
6325 (Prefix (Renamed_Object (Entity (Cond))))) = Name_uObject
6331 -- It is not a boolean variable or literal, so check the restriction.
6332 -- Note that it is safe to be calling Check_Restriction from here, even
6333 -- though this is part of the expander, since Expand_Entry_Barrier is
6334 -- called from Sem_Ch9 even in -gnatc mode.
6336 Check_Restriction (Simple_Barriers, Cond);
6338 -- Emit warning if barrier contains global entities and is thus
6339 -- potentially unsynchronized.
6341 Check_Unprotected_Barrier (Cond);
6342 end Expand_Entry_Barrier;
6344 ------------------------------
6345 -- Expand_N_Abort_Statement --
6346 ------------------------------
6348 -- Expand abort T1, T2, .. Tn; into:
6349 -- Abort_Tasks (Task_List'(1 => T1.Task_Id, 2 => T2.Task_Id ...))
6351 procedure Expand_N_Abort_Statement (N : Node_Id) is
6352 Loc : constant Source_Ptr := Sloc (N);
6353 Tlist : constant List_Id := Names (N);
6359 Aggr := Make_Aggregate (Loc, Component_Associations => New_List);
6362 Tasknm := First (Tlist);
6364 while Present (Tasknm) loop
6367 -- A task interface class-wide type object is being aborted. Retrieve
6368 -- its _task_id by calling a dispatching routine.
6370 if Ada_Version >= Ada_2005
6371 and then Ekind (Etype (Tasknm)) = E_Class_Wide_Type
6372 and then Is_Interface (Etype (Tasknm))
6373 and then Is_Task_Interface (Etype (Tasknm))
6375 Append_To (Component_Associations (Aggr),
6376 Make_Component_Association (Loc,
6377 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6380 -- Task_Id (Tasknm._disp_get_task_id)
6382 Make_Unchecked_Type_Conversion (Loc,
6384 New_Occurrence_Of (RTE (RO_ST_Task_Id), Loc),
6386 Make_Selected_Component (Loc,
6387 Prefix => New_Copy_Tree (Tasknm),
6389 Make_Identifier (Loc, Name_uDisp_Get_Task_Id)))));
6392 Append_To (Component_Associations (Aggr),
6393 Make_Component_Association (Loc,
6394 Choices => New_List (Make_Integer_Literal (Loc, Count)),
6395 Expression => Concurrent_Ref (Tasknm)));
6402 Make_Procedure_Call_Statement (Loc,
6403 Name => New_Occurrence_Of (RTE (RE_Abort_Tasks), Loc),
6404 Parameter_Associations => New_List (
6405 Make_Qualified_Expression (Loc,
6406 Subtype_Mark => New_Occurrence_Of (RTE (RE_Task_List), Loc),
6407 Expression => Aggr))));
6410 end Expand_N_Abort_Statement;
6412 -------------------------------
6413 -- Expand_N_Accept_Statement --
6414 -------------------------------
6416 -- This procedure handles expansion of accept statements that stand alone,
6417 -- i.e. they are not part of an accept alternative. The expansion of
6418 -- accept statement in accept alternatives is handled by the routines
6419 -- Expand_N_Accept_Alternative and Expand_N_Selective_Accept. The
6420 -- following description applies only to stand alone accept statements.
6422 -- If there is no handled statement sequence, or only null statements, then
6423 -- this is called a trivial accept, and the expansion is:
6425 -- Accept_Trivial (entry-index)
6427 -- If there is a handled statement sequence, then the expansion is:
6434 -- Accept_Call (entry-index, Ann);
6435 -- Renaming_Declarations for formals
6436 -- <statement sequence from N_Accept_Statement node>
6437 -- Complete_Rendezvous;
6442 -- <exception handler from N_Accept_Statement node>
6443 -- Complete_Rendezvous;
6445 -- <exception handler from N_Accept_Statement node>
6446 -- Complete_Rendezvous;
6451 -- when all others =>
6452 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
6455 -- The first three declarations were already inserted ahead of the accept
6456 -- statement by the Expand_Accept_Declarations procedure, which was called
6457 -- directly from the semantics during analysis of the accept statement,
6458 -- before analyzing its contained statements.
6460 -- The declarations from the N_Accept_Statement, as noted in Sinfo, come
6461 -- from possible expansion activity (the original source of course does
6462 -- not have any declarations associated with the accept statement, since
6463 -- an accept statement has no declarative part). In particular, if the
6464 -- expander is active, the first such declaration is the declaration of
6465 -- the Accept_Params_Ptr entity (see Sem_Ch9.Analyze_Accept_Statement).
6467 -- The two blocks are merged into a single block if the inner block has
6468 -- no exception handlers, but otherwise two blocks are required, since
6469 -- exceptions might be raised in the exception handlers of the inner
6470 -- block, and Exceptional_Complete_Rendezvous must be called.
6472 procedure Expand_N_Accept_Statement (N : Node_Id) is
6473 Loc : constant Source_Ptr := Sloc (N);
6474 Stats : constant Node_Id := Handled_Statement_Sequence (N);
6475 Ename : constant Node_Id := Entry_Direct_Name (N);
6476 Eindx : constant Node_Id := Entry_Index (N);
6477 Eent : constant Entity_Id := Entity (Ename);
6478 Acstack : constant Elist_Id := Accept_Address (Eent);
6479 Ann : constant Entity_Id := Node (Last_Elmt (Acstack));
6480 Ttyp : constant Entity_Id := Etype (Scope (Eent));
6486 -- If the accept statement is not part of a list, then its parent must
6487 -- be an accept alternative, and, as described above, we do not do any
6488 -- expansion for such accept statements at this level.
6490 if not Is_List_Member (N) then
6491 pragma Assert (Nkind (Parent (N)) = N_Accept_Alternative);
6494 -- Trivial accept case (no statement sequence, or null statements).
6495 -- If the accept statement has declarations, then just insert them
6496 -- before the procedure call.
6498 elsif Trivial_Accept_OK
6499 and then (No (Stats) or else Null_Statements (Statements (Stats)))
6501 -- Remove declarations for renamings, because the parameter block
6502 -- will not be assigned.
6509 D := First (Declarations (N));
6510 while Present (D) loop
6512 if Nkind (D) = N_Object_Renaming_Declaration then
6520 if Present (Declarations (N)) then
6521 Insert_Actions (N, Declarations (N));
6525 Make_Procedure_Call_Statement (Loc,
6526 Name => New_Occurrence_Of (RTE (RE_Accept_Trivial), Loc),
6527 Parameter_Associations => New_List (
6528 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp))));
6532 -- Discard Entry_Address that was created for it, so it will not be
6533 -- emitted if this accept statement is in the statement part of a
6534 -- delay alternative.
6536 if Present (Stats) then
6537 Remove_Last_Elmt (Acstack);
6540 -- Case of statement sequence present
6543 -- Construct the block, using the declarations from the accept
6544 -- statement if any to initialize the declarations of the block.
6546 Blkent := Make_Temporary (Loc, 'A');
6547 Set_Ekind (Blkent, E_Block);
6548 Set_Etype (Blkent, Standard_Void_Type);
6549 Set_Scope (Blkent, Current_Scope);
6552 Make_Block_Statement (Loc,
6553 Identifier => New_Occurrence_Of (Blkent, Loc),
6554 Declarations => Declarations (N),
6555 Handled_Statement_Sequence => Build_Accept_Body (N));
6557 -- For the analysis of the generated declarations, the parent node
6558 -- must be properly set.
6560 Set_Parent (Block, Parent (N));
6562 -- Prepend call to Accept_Call to main statement sequence If the
6563 -- accept has exception handlers, the statement sequence is wrapped
6564 -- in a block. Insert call and renaming declarations in the
6565 -- declarations of the block, so they are elaborated before the
6569 Make_Procedure_Call_Statement (Loc,
6570 Name => New_Occurrence_Of (RTE (RE_Accept_Call), Loc),
6571 Parameter_Associations => New_List (
6572 Entry_Index_Expression (Loc, Entity (Ename), Eindx, Ttyp),
6573 New_Occurrence_Of (Ann, Loc)));
6575 if Parent (Stats) = N then
6576 Prepend (Call, Statements (Stats));
6578 Set_Declarations (Parent (Stats), New_List (Call));
6583 Push_Scope (Blkent);
6591 D := First (Declarations (N));
6592 while Present (D) loop
6595 if Nkind (D) = N_Object_Renaming_Declaration then
6597 -- The renaming declarations for the formals were created
6598 -- during analysis of the accept statement, and attached to
6599 -- the list of declarations. Place them now in the context
6600 -- of the accept block or subprogram.
6603 Typ := Entity (Subtype_Mark (D));
6604 Insert_After (Call, D);
6607 -- If the formal is class_wide, it does not have an actual
6608 -- subtype. The analysis of the renaming declaration creates
6609 -- one, but we need to retain the class-wide nature of the
6612 if Is_Class_Wide_Type (Typ) then
6613 Set_Etype (Defining_Identifier (D), Typ);
6624 -- Replace the accept statement by the new block
6629 -- Last step is to unstack the Accept_Address value
6631 Remove_Last_Elmt (Acstack);
6633 end Expand_N_Accept_Statement;
6635 ----------------------------------
6636 -- Expand_N_Asynchronous_Select --
6637 ----------------------------------
6639 -- This procedure assumes that the trigger statement is an entry call or
6640 -- a dispatching procedure call. A delay alternative should already have
6641 -- been expanded into an entry call to the appropriate delay object Wait
6644 -- If the trigger is a task entry call, the select is implemented with
6645 -- a Task_Entry_Call:
6650 -- P : parms := (parm, parm, parm);
6652 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6654 -- procedure _clean is
6657 -- Cancel_Task_Entry_Call (C);
6664 -- (<acceptor-task>, -- Acceptor
6665 -- <entry-index>, -- E
6666 -- P'Address, -- Uninterpreted_Data
6667 -- Asynchronous_Call, -- Mode
6668 -- B); -- Rendezvous_Successful
6675 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6678 -- when Abort_Signal => Abort_Undefer;
6685 -- <triggered-statements>
6689 -- Note that Build_Simple_Entry_Call is used to expand the entry of the
6690 -- asynchronous entry call (by Expand_N_Entry_Call_Statement procedure)
6694 -- P : parms := (parm, parm, parm);
6696 -- Call_Simple (acceptor-task, entry-index, P'Address);
6702 -- so the task at hand is to convert the latter expansion into the former
6704 -- If the trigger is a protected entry call, the select is implemented
6705 -- with Protected_Entry_Call:
6708 -- P : E1_Params := (param, param, param);
6709 -- Bnn : Communications_Block;
6714 -- -- Clean is added by Exp_Ch7.Expand_Cleanup_Actions
6716 -- procedure _clean is
6719 -- if Enqueued (Bnn) then
6720 -- Cancel_Protected_Entry_Call (Bnn);
6727 -- Protected_Entry_Call
6728 -- (po._object'Access, -- Object
6729 -- <entry index>, -- E
6730 -- P'Address, -- Uninterpreted_Data
6731 -- Asynchronous_Call, -- Mode
6734 -- if Enqueued (Bnn) then
6738 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6741 -- when Abort_Signal => Abort_Undefer;
6744 -- if not Cancelled (Bnn) then
6745 -- <triggered-statements>
6749 -- Build_Simple_Entry_Call is used to expand the all to a simple protected
6753 -- P : E1_Params := (param, param, param);
6754 -- Bnn : Communications_Block;
6757 -- Protected_Entry_Call
6758 -- (po._object'Access, -- Object
6759 -- <entry index>, -- E
6760 -- P'Address, -- Uninterpreted_Data
6761 -- Simple_Call, -- Mode
6768 -- Ada 2005 (AI-345): If the trigger is a dispatching call, the select is
6772 -- B : Boolean := False;
6773 -- Bnn : Communication_Block;
6774 -- C : Ada.Tags.Prim_Op_Kind;
6775 -- D : System.Storage_Elements.Dummy_Communication_Block;
6776 -- K : Ada.Tags.Tagged_Kind :=
6777 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
6778 -- P : Parameters := (Param1 .. ParamN);
6783 -- if K = Ada.Tags.TK_Limited_Tagged
6784 -- or else K = Ada.Tags.TK_Tagged
6786 -- <dispatching-call>;
6787 -- <triggering-statements>;
6791 -- Ada.Tags.Get_Offset_Index
6792 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
6794 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
6796 -- if C = POK_Protected_Entry then
6798 -- procedure _clean is
6800 -- if Enqueued (Bnn) then
6801 -- Cancel_Protected_Entry_Call (Bnn);
6807 -- _Disp_Asynchronous_Select
6808 -- (<object>, S, P'Address, D, B);
6809 -- Bnn := Communication_Block (D);
6811 -- Param1 := P.Param1;
6813 -- ParamN := P.ParamN;
6815 -- if Enqueued (Bnn) then
6816 -- <abortable-statements>
6819 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6822 -- when Abort_Signal => Abort_Undefer;
6825 -- if not Cancelled (Bnn) then
6826 -- <triggering-statements>
6829 -- elsif C = POK_Task_Entry then
6831 -- procedure _clean is
6833 -- Cancel_Task_Entry_Call (U);
6839 -- _Disp_Asynchronous_Select
6840 -- (<object>, S, P'Address, D, B);
6841 -- Bnn := Communication_Bloc (D);
6843 -- Param1 := P.Param1;
6845 -- ParamN := P.ParamN;
6850 -- <abortable-statements>
6852 -- _clean; -- Added by Exp_Ch7.Expand_Cleanup_Actions
6855 -- when Abort_Signal => Abort_Undefer;
6859 -- <triggering-statements>
6864 -- <dispatching-call>;
6865 -- <triggering-statements>
6870 -- The job is to convert this to the asynchronous form
6872 -- If the trigger is a delay statement, it will have been expanded into
6873 -- a call to one of the GNARL delay procedures. This routine will convert
6874 -- this into a protected entry call on a delay object and then continue
6875 -- processing as for a protected entry call trigger. This requires
6876 -- declaring a Delay_Block object and adding a pointer to this object to
6877 -- the parameter list of the delay procedure to form the parameter list of
6878 -- the entry call. This object is used by the runtime to queue the delay
6881 -- For a description of the use of P and the assignments after the call,
6882 -- see Expand_N_Entry_Call_Statement.
6884 procedure Expand_N_Asynchronous_Select (N : Node_Id) is
6885 Loc : constant Source_Ptr := Sloc (N);
6886 Abrt : constant Node_Id := Abortable_Part (N);
6887 Trig : constant Node_Id := Triggering_Alternative (N);
6889 Abort_Block_Ent : Entity_Id;
6890 Abortable_Block : Node_Id;
6893 Blk_Ent : constant Entity_Id := Make_Temporary (Loc, 'A');
6894 Blk_Typ : Entity_Id;
6896 Call_Ent : Entity_Id;
6897 Cancel_Param : Entity_Id;
6898 Cleanup_Block : Node_Id;
6899 Cleanup_Block_Ent : Entity_Id;
6900 Cleanup_Stmts : List_Id;
6901 Conc_Typ_Stmts : List_Id;
6903 Dblock_Ent : Entity_Id;
6908 Enqueue_Call : Node_Id;
6911 Handler_Stmt : Node_Id;
6913 Lim_Typ_Stmts : List_Id;
6919 ProtE_Stmts : List_Id;
6920 ProtP_Stmts : List_Id;
6923 TaskE_Stmts : List_Id;
6926 B : Entity_Id; -- Call status flag
6927 Bnn : Entity_Id; -- Communication block
6928 C : Entity_Id; -- Call kind
6929 K : Entity_Id; -- Tagged kind
6930 P : Entity_Id; -- Parameter block
6931 S : Entity_Id; -- Primitive operation slot
6932 T : Entity_Id; -- Additional status flag
6934 procedure Rewrite_Abortable_Part;
6935 -- If the trigger is a dispatching call, the expansion inserts multiple
6936 -- copies of the abortable part. This is both inefficient, and may lead
6937 -- to duplicate definitions that the back-end will reject, when the
6938 -- abortable part includes loops. This procedure rewrites the abortable
6939 -- part into a call to a generated procedure.
6941 ----------------------------
6942 -- Rewrite_Abortable_Part --
6943 ----------------------------
6945 procedure Rewrite_Abortable_Part is
6946 Proc : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uA);
6951 Make_Subprogram_Body (Loc,
6953 Make_Procedure_Specification (Loc, Defining_Unit_Name => Proc),
6954 Declarations => New_List,
6955 Handled_Statement_Sequence =>
6956 Make_Handled_Sequence_Of_Statements (Loc, Astats));
6957 Insert_Before (N, Decl);
6960 -- Rewrite abortable part into a call to this procedure.
6964 Make_Procedure_Call_Statement (Loc,
6965 Name => New_Occurrence_Of (Proc, Loc)));
6966 end Rewrite_Abortable_Part;
6969 Process_Statements_For_Controlled_Objects (Trig);
6970 Process_Statements_For_Controlled_Objects (Abrt);
6972 Ecall := Triggering_Statement (Trig);
6974 Ensure_Statement_Present (Sloc (Ecall), Trig);
6976 -- Retrieve Astats and Tstats now because the finalization machinery may
6977 -- wrap them in blocks.
6979 Astats := Statements (Abrt);
6980 Tstats := Statements (Trig);
6982 -- The arguments in the call may require dynamic allocation, and the
6983 -- call statement may have been transformed into a block. The block
6984 -- may contain additional declarations for internal entities, and the
6985 -- original call is found by sequential search.
6987 if Nkind (Ecall) = N_Block_Statement then
6988 Ecall := First (Statements (Handled_Statement_Sequence (Ecall)));
6989 while not Nkind_In (Ecall, N_Procedure_Call_Statement,
6990 N_Entry_Call_Statement)
6996 -- This is either a dispatching call or a delay statement used as a
6997 -- trigger which was expanded into a procedure call.
6999 if Nkind (Ecall) = N_Procedure_Call_Statement then
7000 if Ada_Version >= Ada_2005
7002 (No (Original_Node (Ecall))
7003 or else not Nkind_In (Original_Node (Ecall),
7004 N_Delay_Relative_Statement,
7005 N_Delay_Until_Statement))
7007 Extract_Dispatching_Call (Ecall, Call_Ent, Obj, Actuals, Formals);
7009 Rewrite_Abortable_Part;
7013 -- Call status flag processing, generate:
7014 -- B : Boolean := False;
7016 B := Build_B (Loc, Decls);
7018 -- Communication block processing, generate:
7019 -- Bnn : Communication_Block;
7021 Bnn := Make_Temporary (Loc, 'B');
7023 Make_Object_Declaration (Loc,
7024 Defining_Identifier => Bnn,
7025 Object_Definition =>
7026 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
7028 -- Call kind processing, generate:
7029 -- C : Ada.Tags.Prim_Op_Kind;
7031 C := Build_C (Loc, Decls);
7033 -- Tagged kind processing, generate:
7034 -- K : Ada.Tags.Tagged_Kind :=
7035 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7037 -- Dummy communication block, generate:
7038 -- D : Dummy_Communication_Block;
7041 Make_Object_Declaration (Loc,
7042 Defining_Identifier =>
7043 Make_Defining_Identifier (Loc, Name_uD),
7044 Object_Definition =>
7046 (RTE (RE_Dummy_Communication_Block), Loc)));
7048 K := Build_K (Loc, Decls, Obj);
7050 -- Parameter block processing
7052 Blk_Typ := Build_Parameter_Block
7053 (Loc, Actuals, Formals, Decls);
7054 P := Parameter_Block_Pack
7055 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7057 -- Dispatch table slot processing, generate:
7060 S := Build_S (Loc, Decls);
7062 -- Additional status flag processing, generate:
7065 T := Make_Temporary (Loc, 'T');
7067 Make_Object_Declaration (Loc,
7068 Defining_Identifier => T,
7069 Object_Definition =>
7070 New_Occurrence_Of (Standard_Boolean, Loc)));
7072 ------------------------------
7073 -- Protected entry handling --
7074 ------------------------------
7077 -- Param1 := P.Param1;
7079 -- ParamN := P.ParamN;
7081 Cleanup_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7084 -- Bnn := Communication_Block (D);
7086 Prepend_To (Cleanup_Stmts,
7087 Make_Assignment_Statement (Loc,
7088 Name => New_Occurrence_Of (Bnn, Loc),
7090 Make_Unchecked_Type_Conversion (Loc,
7092 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7093 Expression => Make_Identifier (Loc, Name_uD))));
7096 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7098 Prepend_To (Cleanup_Stmts,
7099 Make_Procedure_Call_Statement (Loc,
7103 (Etype (Etype (Obj)), Name_uDisp_Asynchronous_Select),
7105 Parameter_Associations =>
7107 New_Copy_Tree (Obj), -- <object>
7108 New_Occurrence_Of (S, Loc), -- S
7109 Make_Attribute_Reference (Loc, -- P'Address
7110 Prefix => New_Occurrence_Of (P, Loc),
7111 Attribute_Name => Name_Address),
7112 Make_Identifier (Loc, Name_uD), -- D
7113 New_Occurrence_Of (B, Loc)))); -- B
7116 -- if Enqueued (Bnn) then
7117 -- <abortable-statements>
7120 Append_To (Cleanup_Stmts,
7121 Make_Implicit_If_Statement (N,
7123 Make_Function_Call (Loc,
7125 New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7126 Parameter_Associations =>
7127 New_List (New_Occurrence_Of (Bnn, Loc))),
7130 New_Copy_List_Tree (Astats)));
7132 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7133 -- will then generate a _clean for the communication block Bnn.
7137 -- procedure _clean is
7139 -- if Enqueued (Bnn) then
7140 -- Cancel_Protected_Entry_Call (Bnn);
7149 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7151 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, Bnn);
7153 -- Wrap the cleanup block in an exception handling block
7159 -- when Abort_Signal => Abort_Undefer;
7162 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7165 Make_Implicit_Label_Declaration (Loc,
7166 Defining_Identifier => Abort_Block_Ent),
7169 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7172 -- if not Cancelled (Bnn) then
7173 -- <triggering-statements>
7176 Append_To (ProtE_Stmts,
7177 Make_Implicit_If_Statement (N,
7181 Make_Function_Call (Loc,
7183 New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7184 Parameter_Associations =>
7185 New_List (New_Occurrence_Of (Bnn, Loc)))),
7188 New_Copy_List_Tree (Tstats)));
7190 -------------------------
7191 -- Task entry handling --
7192 -------------------------
7195 -- Param1 := P.Param1;
7197 -- ParamN := P.ParamN;
7199 TaskE_Stmts := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7202 -- Bnn := Communication_Block (D);
7204 Append_To (TaskE_Stmts,
7205 Make_Assignment_Statement (Loc,
7207 New_Occurrence_Of (Bnn, Loc),
7209 Make_Unchecked_Type_Conversion (Loc,
7211 New_Occurrence_Of (RTE (RE_Communication_Block), Loc),
7212 Expression => Make_Identifier (Loc, Name_uD))));
7215 -- _Disp_Asynchronous_Select (<object>, S, P'Address, D, B);
7217 Prepend_To (TaskE_Stmts,
7218 Make_Procedure_Call_Statement (Loc,
7221 Find_Prim_Op (Etype (Etype (Obj)),
7222 Name_uDisp_Asynchronous_Select),
7225 Parameter_Associations =>
7227 New_Copy_Tree (Obj), -- <object>
7228 New_Occurrence_Of (S, Loc), -- S
7229 Make_Attribute_Reference (Loc, -- P'Address
7230 Prefix => New_Occurrence_Of (P, Loc),
7231 Attribute_Name => Name_Address),
7232 Make_Identifier (Loc, Name_uD), -- D
7233 New_Occurrence_Of (B, Loc)))); -- B
7238 Prepend_To (TaskE_Stmts,
7239 Make_Procedure_Call_Statement (Loc,
7240 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
7241 Parameter_Associations => No_List));
7245 -- <abortable-statements>
7247 Cleanup_Stmts := New_Copy_List_Tree (Astats);
7249 Prepend_To (Cleanup_Stmts,
7250 Make_Procedure_Call_Statement (Loc,
7251 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
7252 Parameter_Associations => No_List));
7254 -- Wrap the statements in a block. Exp_Ch7.Expand_Cleanup_Actions
7255 -- will generate a _clean for the additional status flag.
7259 -- procedure _clean is
7261 -- Cancel_Task_Entry_Call (U);
7269 Cleanup_Block_Ent := Make_Temporary (Loc, 'C');
7271 Build_Cleanup_Block (Loc, Cleanup_Block_Ent, Cleanup_Stmts, T);
7273 -- Wrap the cleanup block in an exception handling block
7279 -- when Abort_Signal => Abort_Undefer;
7282 Abort_Block_Ent := Make_Temporary (Loc, 'A');
7284 Append_To (TaskE_Stmts,
7285 Make_Implicit_Label_Declaration (Loc,
7286 Defining_Identifier => Abort_Block_Ent));
7288 Append_To (TaskE_Stmts,
7290 (Loc, Abort_Block_Ent, Cleanup_Block_Ent, Cleanup_Block));
7294 -- <triggering-statements>
7297 Append_To (TaskE_Stmts,
7298 Make_Implicit_If_Statement (N,
7300 Make_Op_Not (Loc, Right_Opnd => New_Occurrence_Of (T, Loc)),
7303 New_Copy_List_Tree (Tstats)));
7305 ----------------------------------
7306 -- Protected procedure handling --
7307 ----------------------------------
7310 -- <dispatching-call>;
7311 -- <triggering-statements>
7313 ProtP_Stmts := New_Copy_List_Tree (Tstats);
7314 Prepend_To (ProtP_Stmts, New_Copy_Tree (Ecall));
7317 -- S := Ada.Tags.Get_Offset_Index
7318 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7321 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7324 -- _Disp_Get_Prim_Op_Kind (<object>, S, C);
7326 Append_To (Conc_Typ_Stmts,
7327 Make_Procedure_Call_Statement (Loc,
7330 (Find_Prim_Op (Etype (Etype (Obj)),
7331 Name_uDisp_Get_Prim_Op_Kind),
7333 Parameter_Associations =>
7335 New_Copy_Tree (Obj),
7336 New_Occurrence_Of (S, Loc),
7337 New_Occurrence_Of (C, Loc))));
7340 -- if C = POK_Procedure_Entry then
7342 -- elsif C = POK_Task_Entry then
7348 Append_To (Conc_Typ_Stmts,
7349 Make_Implicit_If_Statement (N,
7353 New_Occurrence_Of (C, Loc),
7355 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
7362 Make_Elsif_Part (Loc,
7366 New_Occurrence_Of (C, Loc),
7368 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc)),
7377 -- <dispatching-call>;
7378 -- <triggering-statements>
7380 Lim_Typ_Stmts := New_Copy_List_Tree (Tstats);
7381 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Ecall));
7384 -- if K = Ada.Tags.TK_Limited_Tagged
7385 -- or else K = Ada.Tags.TK_Tagged
7393 Make_Implicit_If_Statement (N,
7394 Condition => Build_Dispatching_Tag_Check (K, N),
7395 Then_Statements => Lim_Typ_Stmts,
7396 Else_Statements => Conc_Typ_Stmts));
7399 Make_Block_Statement (Loc,
7402 Handled_Statement_Sequence =>
7403 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7408 -- Delay triggering statement processing
7411 -- Add a Delay_Block object to the parameter list of the delay
7412 -- procedure to form the parameter list of the Wait entry call.
7414 Dblock_Ent := Make_Temporary (Loc, 'D');
7416 Pdef := Entity (Name (Ecall));
7418 if Is_RTE (Pdef, RO_CA_Delay_For) then
7420 New_Occurrence_Of (RTE (RE_Enqueue_Duration), Loc);
7422 elsif Is_RTE (Pdef, RO_CA_Delay_Until) then
7424 New_Occurrence_Of (RTE (RE_Enqueue_Calendar), Loc);
7426 else pragma Assert (Is_RTE (Pdef, RO_RT_Delay_Until));
7427 Enqueue_Call := New_Occurrence_Of (RTE (RE_Enqueue_RT), Loc);
7430 Append_To (Parameter_Associations (Ecall),
7431 Make_Attribute_Reference (Loc,
7432 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7433 Attribute_Name => Name_Unchecked_Access));
7435 -- Create the inner block to protect the abortable part
7437 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7440 Make_Procedure_Call_Statement (Loc,
7441 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc)));
7444 Make_Block_Statement (Loc,
7445 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7446 Handled_Statement_Sequence =>
7447 Make_Handled_Sequence_Of_Statements (Loc,
7448 Statements => Astats),
7449 Has_Created_Identifier => True,
7450 Is_Asynchronous_Call_Block => True);
7452 -- Append call to if Enqueue (When, DB'Unchecked_Access) then
7455 Make_Implicit_If_Statement (N,
7457 Make_Function_Call (Loc,
7458 Name => Enqueue_Call,
7459 Parameter_Associations => Parameter_Associations (Ecall)),
7461 New_List (Make_Block_Statement (Loc,
7462 Handled_Statement_Sequence =>
7463 Make_Handled_Sequence_Of_Statements (Loc,
7464 Statements => New_List (
7465 Make_Implicit_Label_Declaration (Loc,
7466 Defining_Identifier => Blk_Ent,
7467 Label_Construct => Abortable_Block),
7469 Exception_Handlers => Hdle)))));
7471 Stmts := New_List (Ecall);
7473 -- Construct statement sequence for new block
7476 Make_Implicit_If_Statement (N,
7478 Make_Function_Call (Loc,
7479 Name => New_Occurrence_Of (
7480 RTE (RE_Timed_Out), Loc),
7481 Parameter_Associations => New_List (
7482 Make_Attribute_Reference (Loc,
7483 Prefix => New_Occurrence_Of (Dblock_Ent, Loc),
7484 Attribute_Name => Name_Unchecked_Access))),
7485 Then_Statements => Tstats));
7487 -- The result is the new block
7489 Set_Entry_Cancel_Parameter (Blk_Ent, Dblock_Ent);
7492 Make_Block_Statement (Loc,
7493 Declarations => New_List (
7494 Make_Object_Declaration (Loc,
7495 Defining_Identifier => Dblock_Ent,
7496 Aliased_Present => True,
7497 Object_Definition =>
7498 New_Occurrence_Of (RTE (RE_Delay_Block), Loc))),
7500 Handled_Statement_Sequence =>
7501 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7511 Extract_Entry (Ecall, Concval, Ename, Index);
7512 Build_Simple_Entry_Call (Ecall, Concval, Ename, Index);
7514 Stmts := Statements (Handled_Statement_Sequence (Ecall));
7515 Decls := Declarations (Ecall);
7517 if Is_Protected_Type (Etype (Concval)) then
7519 -- Get the declarations of the block expanded from the entry call
7521 Decl := First (Decls);
7522 while Present (Decl)
7523 and then (Nkind (Decl) /= N_Object_Declaration
7524 or else not Is_RTE (Etype (Object_Definition (Decl)),
7525 RE_Communication_Block))
7530 pragma Assert (Present (Decl));
7531 Cancel_Param := Defining_Identifier (Decl);
7533 -- Change the mode of the Protected_Entry_Call call
7535 -- Protected_Entry_Call (
7536 -- Object => po._object'Access,
7537 -- E => <entry index>;
7538 -- Uninterpreted_Data => P'Address;
7539 -- Mode => Asynchronous_Call;
7542 -- Skip assignments to temporaries created for in-out parameters
7544 -- This makes unwarranted assumptions about the shape of the expanded
7545 -- tree for the call, and should be cleaned up ???
7547 Stmt := First (Stmts);
7548 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7554 Param := First (Parameter_Associations (Call));
7555 while Present (Param)
7556 and then not Is_RTE (Etype (Param), RE_Call_Modes)
7561 pragma Assert (Present (Param));
7562 Rewrite (Param, New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7565 -- Append an if statement to execute the abortable part
7568 -- if Enqueued (Bnn) then
7571 Make_Implicit_If_Statement (N,
7573 Make_Function_Call (Loc,
7574 Name => New_Occurrence_Of (RTE (RE_Enqueued), Loc),
7575 Parameter_Associations => New_List (
7576 New_Occurrence_Of (Cancel_Param, Loc))),
7577 Then_Statements => Astats));
7580 Make_Block_Statement (Loc,
7581 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7582 Handled_Statement_Sequence =>
7583 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stmts),
7584 Has_Created_Identifier => True,
7585 Is_Asynchronous_Call_Block => True);
7587 -- For the VM call Update_Exception instead of Abort_Undefer.
7588 -- See 4jexcept.ads for an explanation.
7590 if VM_Target = No_VM then
7591 if Exception_Mechanism = Back_End_Exceptions then
7593 -- Aborts are not deferred at beginning of exception handlers
7596 Handler_Stmt := Make_Null_Statement (Loc);
7599 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
7600 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc),
7601 Parameter_Associations => No_List);
7604 Handler_Stmt := Make_Procedure_Call_Statement (Loc,
7605 Name => New_Occurrence_Of (RTE (RE_Update_Exception), Loc),
7606 Parameter_Associations => New_List (
7607 Make_Function_Call (Loc,
7608 Name => New_Occurrence_Of
7609 (RTE (RE_Current_Target_Exception), Loc))));
7613 Make_Block_Statement (Loc,
7614 Handled_Statement_Sequence =>
7615 Make_Handled_Sequence_Of_Statements (Loc,
7616 Statements => New_List (
7617 Make_Implicit_Label_Declaration (Loc,
7618 Defining_Identifier => Blk_Ent,
7619 Label_Construct => Abortable_Block),
7624 Exception_Handlers => New_List (
7625 Make_Implicit_Exception_Handler (Loc,
7627 -- when Abort_Signal =>
7628 -- Abort_Undefer.all;
7630 Exception_Choices =>
7631 New_List (New_Occurrence_Of (Stand.Abort_Signal, Loc)),
7632 Statements => New_List (Handler_Stmt))))),
7634 -- if not Cancelled (Bnn) then
7635 -- triggered statements
7638 Make_Implicit_If_Statement (N,
7639 Condition => Make_Op_Not (Loc,
7641 Make_Function_Call (Loc,
7642 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
7643 Parameter_Associations => New_List (
7644 New_Occurrence_Of (Cancel_Param, Loc)))),
7645 Then_Statements => Tstats));
7647 -- Asynchronous task entry call
7654 B := Make_Defining_Identifier (Loc, Name_uB);
7656 -- Insert declaration of B in declarations of existing block
7659 Make_Object_Declaration (Loc,
7660 Defining_Identifier => B,
7661 Object_Definition =>
7662 New_Occurrence_Of (Standard_Boolean, Loc)));
7664 Cancel_Param := Make_Defining_Identifier (Loc, Name_uC);
7666 -- Insert declaration of C in declarations of existing block
7669 Make_Object_Declaration (Loc,
7670 Defining_Identifier => Cancel_Param,
7671 Object_Definition =>
7672 New_Occurrence_Of (Standard_Boolean, Loc)));
7674 -- Remove and save the call to Call_Simple
7676 Stmt := First (Stmts);
7678 -- Skip assignments to temporaries created for in-out parameters.
7679 -- This makes unwarranted assumptions about the shape of the expanded
7680 -- tree for the call, and should be cleaned up ???
7682 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
7688 -- Create the inner block to protect the abortable part
7690 Hdle := New_List (Build_Abort_Block_Handler (Loc));
7693 Make_Procedure_Call_Statement (Loc,
7694 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Loc)));
7697 Make_Block_Statement (Loc,
7698 Identifier => New_Occurrence_Of (Blk_Ent, Loc),
7699 Handled_Statement_Sequence =>
7700 Make_Handled_Sequence_Of_Statements (Loc, Statements => Astats),
7701 Has_Created_Identifier => True,
7702 Is_Asynchronous_Call_Block => True);
7705 Make_Block_Statement (Loc,
7706 Handled_Statement_Sequence =>
7707 Make_Handled_Sequence_Of_Statements (Loc,
7708 Statements => New_List (
7709 Make_Implicit_Label_Declaration (Loc,
7710 Defining_Identifier => Blk_Ent,
7711 Label_Construct => Abortable_Block),
7713 Exception_Handlers => Hdle)));
7715 -- Create new call statement
7717 Params := Parameter_Associations (Call);
7720 New_Occurrence_Of (RTE (RE_Asynchronous_Call), Loc));
7721 Append_To (Params, New_Occurrence_Of (B, Loc));
7724 Make_Procedure_Call_Statement (Loc,
7725 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
7726 Parameter_Associations => Params));
7728 -- Construct statement sequence for new block
7731 Make_Implicit_If_Statement (N,
7733 Make_Op_Not (Loc, New_Occurrence_Of (Cancel_Param, Loc)),
7734 Then_Statements => Tstats));
7736 -- Protected the call against abort
7739 Make_Procedure_Call_Statement (Loc,
7740 Name => New_Occurrence_Of (RTE (RE_Abort_Defer), Loc),
7741 Parameter_Associations => Empty_List));
7744 Set_Entry_Cancel_Parameter (Blk_Ent, Cancel_Param);
7746 -- The result is the new block
7749 Make_Block_Statement (Loc,
7750 Declarations => Decls,
7751 Handled_Statement_Sequence =>
7752 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
7755 end Expand_N_Asynchronous_Select;
7757 -------------------------------------
7758 -- Expand_N_Conditional_Entry_Call --
7759 -------------------------------------
7761 -- The conditional task entry call is converted to a call to
7766 -- P : parms := (parm, parm, parm);
7770 -- (<acceptor-task>, -- Acceptor
7771 -- <entry-index>, -- E
7772 -- P'Address, -- Uninterpreted_Data
7773 -- Conditional_Call, -- Mode
7774 -- B); -- Rendezvous_Successful
7779 -- normal-statements
7785 -- For a description of the use of P and the assignments after the call,
7786 -- see Expand_N_Entry_Call_Statement. Note that the entry call of the
7787 -- conditional entry call has already been expanded (by the Expand_N_Entry
7788 -- _Call_Statement procedure) as follows:
7791 -- P : parms := (parm, parm, parm);
7793 -- ... info for in-out parameters
7794 -- Call_Simple (acceptor-task, entry-index, P'Address);
7800 -- so the task at hand is to convert the latter expansion into the former
7802 -- The conditional protected entry call is converted to a call to
7803 -- Protected_Entry_Call:
7806 -- P : parms := (parm, parm, parm);
7807 -- Bnn : Communications_Block;
7810 -- Protected_Entry_Call
7811 -- (po._object'Access, -- Object
7812 -- <entry index>, -- E
7813 -- P'Address, -- Uninterpreted_Data
7814 -- Conditional_Call, -- Mode
7819 -- if Cancelled (Bnn) then
7822 -- normal-statements
7826 -- Ada 2005 (AI-345): A dispatching conditional entry call is converted
7830 -- B : Boolean := False;
7831 -- C : Ada.Tags.Prim_Op_Kind;
7832 -- K : Ada.Tags.Tagged_Kind :=
7833 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7834 -- P : Parameters := (Param1 .. ParamN);
7838 -- if K = Ada.Tags.TK_Limited_Tagged
7839 -- or else K = Ada.Tags.TK_Tagged
7841 -- <dispatching-call>;
7842 -- <triggering-statements>
7846 -- Ada.Tags.Get_Offset_Index
7847 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
7849 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7851 -- if C = POK_Protected_Entry
7852 -- or else C = POK_Task_Entry
7854 -- Param1 := P.Param1;
7856 -- ParamN := P.ParamN;
7860 -- if C = POK_Procedure
7861 -- or else C = POK_Protected_Procedure
7862 -- or else C = POK_Task_Procedure
7864 -- <dispatching-call>;
7867 -- <triggering-statements>
7869 -- <else-statements>
7874 procedure Expand_N_Conditional_Entry_Call (N : Node_Id) is
7875 Loc : constant Source_Ptr := Sloc (N);
7876 Alt : constant Node_Id := Entry_Call_Alternative (N);
7877 Blk : Node_Id := Entry_Call_Statement (Alt);
7880 Blk_Typ : Entity_Id;
7882 Call_Ent : Entity_Id;
7883 Conc_Typ_Stmts : List_Id;
7887 Lim_Typ_Stmts : List_Id;
7894 Transient_Blk : Node_Id;
7897 B : Entity_Id; -- Call status flag
7898 C : Entity_Id; -- Call kind
7899 K : Entity_Id; -- Tagged kind
7900 P : Entity_Id; -- Parameter block
7901 S : Entity_Id; -- Primitive operation slot
7904 Process_Statements_For_Controlled_Objects (N);
7906 if Ada_Version >= Ada_2005
7907 and then Nkind (Blk) = N_Procedure_Call_Statement
7909 Extract_Dispatching_Call (Blk, Call_Ent, Obj, Actuals, Formals);
7914 -- Call status flag processing, generate:
7915 -- B : Boolean := False;
7917 B := Build_B (Loc, Decls);
7919 -- Call kind processing, generate:
7920 -- C : Ada.Tags.Prim_Op_Kind;
7922 C := Build_C (Loc, Decls);
7924 -- Tagged kind processing, generate:
7925 -- K : Ada.Tags.Tagged_Kind :=
7926 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
7928 K := Build_K (Loc, Decls, Obj);
7930 -- Parameter block processing
7932 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
7933 P := Parameter_Block_Pack
7934 (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
7936 -- Dispatch table slot processing, generate:
7939 S := Build_S (Loc, Decls);
7942 -- S := Ada.Tags.Get_Offset_Index
7943 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
7946 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
7949 -- _Disp_Conditional_Select (<object>, S, P'Address, C, B);
7951 Append_To (Conc_Typ_Stmts,
7952 Make_Procedure_Call_Statement (Loc,
7955 Find_Prim_Op (Etype (Etype (Obj)),
7956 Name_uDisp_Conditional_Select),
7958 Parameter_Associations =>
7960 New_Copy_Tree (Obj), -- <object>
7961 New_Occurrence_Of (S, Loc), -- S
7962 Make_Attribute_Reference (Loc, -- P'Address
7963 Prefix => New_Occurrence_Of (P, Loc),
7964 Attribute_Name => Name_Address),
7965 New_Occurrence_Of (C, Loc), -- C
7966 New_Occurrence_Of (B, Loc)))); -- B
7969 -- if C = POK_Protected_Entry
7970 -- or else C = POK_Task_Entry
7972 -- Param1 := P.Param1;
7974 -- ParamN := P.ParamN;
7977 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
7979 -- Generate the if statement only when the packed parameters need
7980 -- explicit assignments to their corresponding actuals.
7982 if Present (Unpack) then
7983 Append_To (Conc_Typ_Stmts,
7984 Make_Implicit_If_Statement (N,
7990 New_Occurrence_Of (C, Loc),
7992 New_Occurrence_Of (RTE (
7993 RE_POK_Protected_Entry), Loc)),
7998 New_Occurrence_Of (C, Loc),
8000 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
8002 Then_Statements => Unpack));
8007 -- if C = POK_Procedure
8008 -- or else C = POK_Protected_Procedure
8009 -- or else C = POK_Task_Procedure
8011 -- <dispatching-call>
8013 -- <normal-statements>
8015 -- <else-statements>
8018 N_Stats := New_Copy_List_Tree (Statements (Alt));
8020 Prepend_To (N_Stats,
8021 Make_Implicit_If_Statement (N,
8027 New_Occurrence_Of (C, Loc),
8029 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
8036 New_Occurrence_Of (C, Loc),
8038 New_Occurrence_Of (RTE (
8039 RE_POK_Protected_Procedure), Loc)),
8044 New_Occurrence_Of (C, Loc),
8046 New_Occurrence_Of (RTE (
8047 RE_POK_Task_Procedure), Loc)))),
8052 Append_To (Conc_Typ_Stmts,
8053 Make_Implicit_If_Statement (N,
8054 Condition => New_Occurrence_Of (B, Loc),
8055 Then_Statements => N_Stats,
8056 Else_Statements => Else_Statements (N)));
8059 -- <dispatching-call>;
8060 -- <triggering-statements>
8062 Lim_Typ_Stmts := New_Copy_List_Tree (Statements (Alt));
8063 Prepend_To (Lim_Typ_Stmts, New_Copy_Tree (Blk));
8066 -- if K = Ada.Tags.TK_Limited_Tagged
8067 -- or else K = Ada.Tags.TK_Tagged
8075 Make_Implicit_If_Statement (N,
8076 Condition => Build_Dispatching_Tag_Check (K, N),
8077 Then_Statements => Lim_Typ_Stmts,
8078 Else_Statements => Conc_Typ_Stmts));
8081 Make_Block_Statement (Loc,
8084 Handled_Statement_Sequence =>
8085 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8087 -- As described above, the entry alternative is transformed into a
8088 -- block that contains the gnulli call, and possibly assignment
8089 -- statements for in-out parameters. The gnulli call may itself be
8090 -- rewritten into a transient block if some unconstrained parameters
8091 -- require it. We need to retrieve the call to complete its parameter
8096 First_Real_Statement (Handled_Statement_Sequence (Blk));
8098 if Present (Transient_Blk)
8099 and then Nkind (Transient_Blk) = N_Block_Statement
8101 Blk := Transient_Blk;
8104 Stmts := Statements (Handled_Statement_Sequence (Blk));
8105 Stmt := First (Stmts);
8106 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
8111 Params := Parameter_Associations (Call);
8113 if Is_RTE (Entity (Name (Call)), RE_Protected_Entry_Call) then
8115 -- Substitute Conditional_Entry_Call for Simple_Call parameter
8117 Param := First (Params);
8118 while Present (Param)
8119 and then not Is_RTE (Etype (Param), RE_Call_Modes)
8124 pragma Assert (Present (Param));
8126 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
8130 -- Find the Communication_Block parameter for the call to the
8131 -- Cancelled function.
8133 Decl := First (Declarations (Blk));
8134 while Present (Decl)
8135 and then not Is_RTE (Etype (Object_Definition (Decl)),
8136 RE_Communication_Block)
8141 -- Add an if statement to execute the else part if the call
8142 -- does not succeed (as indicated by the Cancelled predicate).
8145 Make_Implicit_If_Statement (N,
8146 Condition => Make_Function_Call (Loc,
8147 Name => New_Occurrence_Of (RTE (RE_Cancelled), Loc),
8148 Parameter_Associations => New_List (
8149 New_Occurrence_Of (Defining_Identifier (Decl), Loc))),
8150 Then_Statements => Else_Statements (N),
8151 Else_Statements => Statements (Alt)));
8154 B := Make_Defining_Identifier (Loc, Name_uB);
8156 -- Insert declaration of B in declarations of existing block
8158 if No (Declarations (Blk)) then
8159 Set_Declarations (Blk, New_List);
8162 Prepend_To (Declarations (Blk),
8163 Make_Object_Declaration (Loc,
8164 Defining_Identifier => B,
8165 Object_Definition =>
8166 New_Occurrence_Of (Standard_Boolean, Loc)));
8168 -- Create new call statement
8171 New_Occurrence_Of (RTE (RE_Conditional_Call), Loc));
8172 Append_To (Params, New_Occurrence_Of (B, Loc));
8175 Make_Procedure_Call_Statement (Loc,
8176 Name => New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
8177 Parameter_Associations => Params));
8179 -- Construct statement sequence for new block
8182 Make_Implicit_If_Statement (N,
8183 Condition => New_Occurrence_Of (B, Loc),
8184 Then_Statements => Statements (Alt),
8185 Else_Statements => Else_Statements (N)));
8188 -- The result is the new block
8191 Make_Block_Statement (Loc,
8192 Declarations => Declarations (Blk),
8193 Handled_Statement_Sequence =>
8194 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
8198 end Expand_N_Conditional_Entry_Call;
8200 ---------------------------------------
8201 -- Expand_N_Delay_Relative_Statement --
8202 ---------------------------------------
8204 -- Delay statement is implemented as a procedure call to Delay_For
8205 -- defined in Ada.Calendar.Delays in order to reduce the overhead of
8206 -- simple delays imposed by the use of Protected Objects.
8208 procedure Expand_N_Delay_Relative_Statement (N : Node_Id) is
8209 Loc : constant Source_Ptr := Sloc (N);
8212 Make_Procedure_Call_Statement (Loc,
8213 Name => New_Occurrence_Of (RTE (RO_CA_Delay_For), Loc),
8214 Parameter_Associations => New_List (Expression (N))));
8216 end Expand_N_Delay_Relative_Statement;
8218 ------------------------------------
8219 -- Expand_N_Delay_Until_Statement --
8220 ------------------------------------
8222 -- Delay Until statement is implemented as a procedure call to
8223 -- Delay_Until defined in Ada.Calendar.Delays and Ada.Real_Time.Delays.
8225 procedure Expand_N_Delay_Until_Statement (N : Node_Id) is
8226 Loc : constant Source_Ptr := Sloc (N);
8230 if Is_RTE (Base_Type (Etype (Expression (N))), RO_CA_Time) then
8231 Typ := RTE (RO_CA_Delay_Until);
8233 Typ := RTE (RO_RT_Delay_Until);
8237 Make_Procedure_Call_Statement (Loc,
8238 Name => New_Occurrence_Of (Typ, Loc),
8239 Parameter_Associations => New_List (Expression (N))));
8242 end Expand_N_Delay_Until_Statement;
8244 -------------------------
8245 -- Expand_N_Entry_Body --
8246 -------------------------
8248 procedure Expand_N_Entry_Body (N : Node_Id) is
8250 -- Associate discriminals with the next protected operation body to be
8253 if Present (Next_Protected_Operation (N)) then
8254 Set_Discriminals (Parent (Current_Scope));
8256 end Expand_N_Entry_Body;
8258 -----------------------------------
8259 -- Expand_N_Entry_Call_Statement --
8260 -----------------------------------
8262 -- An entry call is expanded into GNARLI calls to implement a simple entry
8263 -- call (see Build_Simple_Entry_Call).
8265 procedure Expand_N_Entry_Call_Statement (N : Node_Id) is
8271 if No_Run_Time_Mode then
8272 Error_Msg_CRT ("entry call", N);
8276 -- If this entry call is part of an asynchronous select, don't expand it
8277 -- here; it will be expanded with the select statement. Don't expand
8278 -- timed entry calls either, as they are translated into asynchronous
8281 -- ??? This whole approach is questionable; it may be better to go back
8282 -- to allowing the expansion to take place and then attempting to fix it
8283 -- up in Expand_N_Asynchronous_Select. The tricky part is figuring out
8284 -- whether the expanded call is on a task or protected entry.
8286 if (Nkind (Parent (N)) /= N_Triggering_Alternative
8287 or else N /= Triggering_Statement (Parent (N)))
8288 and then (Nkind (Parent (N)) /= N_Entry_Call_Alternative
8289 or else N /= Entry_Call_Statement (Parent (N))
8290 or else Nkind (Parent (Parent (N))) /= N_Timed_Entry_Call)
8292 Extract_Entry (N, Concval, Ename, Index);
8293 Build_Simple_Entry_Call (N, Concval, Ename, Index);
8295 end Expand_N_Entry_Call_Statement;
8297 --------------------------------
8298 -- Expand_N_Entry_Declaration --
8299 --------------------------------
8301 -- If there are parameters, then first, each of the formals is marked by
8302 -- setting Is_Entry_Formal. Next a record type is built which is used to
8303 -- hold the parameter values. The name of this record type is entryP where
8304 -- entry is the name of the entry, with an additional corresponding access
8305 -- type called entryPA. The record type has matching components for each
8306 -- formal (the component names are the same as the formal names). For
8307 -- elementary types, the component type matches the formal type. For
8308 -- composite types, an access type is declared (with the name formalA)
8309 -- which designates the formal type, and the type of the component is this
8310 -- access type. Finally the Entry_Component of each formal is set to
8311 -- reference the corresponding record component.
8313 procedure Expand_N_Entry_Declaration (N : Node_Id) is
8314 Loc : constant Source_Ptr := Sloc (N);
8315 Entry_Ent : constant Entity_Id := Defining_Identifier (N);
8316 Components : List_Id;
8319 Last_Decl : Node_Id;
8320 Component : Entity_Id;
8323 Rec_Ent : Entity_Id;
8324 Acc_Ent : Entity_Id;
8327 Formal := First_Formal (Entry_Ent);
8330 -- Most processing is done only if parameters are present
8332 if Present (Formal) then
8333 Components := New_List;
8335 -- Loop through formals
8337 while Present (Formal) loop
8338 Set_Is_Entry_Formal (Formal);
8340 Make_Defining_Identifier (Sloc (Formal), Chars (Formal));
8341 Set_Entry_Component (Formal, Component);
8342 Set_Entry_Formal (Component, Formal);
8343 Ftype := Etype (Formal);
8345 -- Declare new access type and then append
8347 Ctype := Make_Temporary (Loc, 'A');
8350 Make_Full_Type_Declaration (Loc,
8351 Defining_Identifier => Ctype,
8353 Make_Access_To_Object_Definition (Loc,
8354 All_Present => True,
8355 Constant_Present => Ekind (Formal) = E_In_Parameter,
8356 Subtype_Indication => New_Occurrence_Of (Ftype, Loc)));
8358 Insert_After (Last_Decl, Decl);
8361 Append_To (Components,
8362 Make_Component_Declaration (Loc,
8363 Defining_Identifier => Component,
8364 Component_Definition =>
8365 Make_Component_Definition (Loc,
8366 Aliased_Present => False,
8367 Subtype_Indication => New_Occurrence_Of (Ctype, Loc))));
8369 Next_Formal_With_Extras (Formal);
8372 -- Create the Entry_Parameter_Record declaration
8374 Rec_Ent := Make_Temporary (Loc, 'P');
8377 Make_Full_Type_Declaration (Loc,
8378 Defining_Identifier => Rec_Ent,
8380 Make_Record_Definition (Loc,
8382 Make_Component_List (Loc,
8383 Component_Items => Components)));
8385 Insert_After (Last_Decl, Decl);
8388 -- Construct and link in the corresponding access type
8390 Acc_Ent := Make_Temporary (Loc, 'A');
8392 Set_Entry_Parameters_Type (Entry_Ent, Acc_Ent);
8395 Make_Full_Type_Declaration (Loc,
8396 Defining_Identifier => Acc_Ent,
8398 Make_Access_To_Object_Definition (Loc,
8399 All_Present => True,
8400 Subtype_Indication => New_Occurrence_Of (Rec_Ent, Loc)));
8402 Insert_After (Last_Decl, Decl);
8404 end Expand_N_Entry_Declaration;
8406 -----------------------------
8407 -- Expand_N_Protected_Body --
8408 -----------------------------
8410 -- Protected bodies are expanded to the completion of the subprograms
8411 -- created for the corresponding protected type. These are a protected and
8412 -- unprotected version of each protected subprogram in the object, a
8413 -- function to calculate each entry barrier, and a procedure to execute the
8414 -- sequence of statements of each protected entry body. For example, for
8415 -- protected type ptype:
8418 -- (O : System.Address;
8419 -- E : Protected_Entry_Index)
8422 -- <discriminant renamings>
8423 -- <private object renamings>
8425 -- return <barrier expression>;
8428 -- procedure pprocN (_object : in out poV;...) is
8429 -- <discriminant renamings>
8430 -- <private object renamings>
8432 -- <sequence of statements>
8435 -- procedure pprocP (_object : in out poV;...) is
8436 -- procedure _clean is
8439 -- ptypeS (_object, Pn);
8440 -- Unlock (_object._object'Access);
8441 -- Abort_Undefer.all;
8446 -- Lock (_object._object'Access);
8447 -- pprocN (_object;...);
8452 -- function pfuncN (_object : poV;...) return Return_Type is
8453 -- <discriminant renamings>
8454 -- <private object renamings>
8456 -- <sequence of statements>
8459 -- function pfuncP (_object : poV) return Return_Type is
8460 -- procedure _clean is
8462 -- Unlock (_object._object'Access);
8463 -- Abort_Undefer.all;
8468 -- Lock (_object._object'Access);
8469 -- return pfuncN (_object);
8476 -- (O : System.Address;
8477 -- P : System.Address;
8478 -- E : Protected_Entry_Index)
8480 -- <discriminant renamings>
8481 -- <private object renamings>
8482 -- type poVP is access poV;
8483 -- _Object : ptVP := ptVP!(O);
8487 -- <statement sequence>
8488 -- Complete_Entry_Body (_Object._Object);
8490 -- when all others =>
8491 -- Exceptional_Complete_Entry_Body (
8492 -- _Object._Object, Get_GNAT_Exception);
8496 -- The type poV is the record created for the protected type to hold
8497 -- the state of the protected object.
8499 procedure Expand_N_Protected_Body (N : Node_Id) is
8500 Loc : constant Source_Ptr := Sloc (N);
8501 Pid : constant Entity_Id := Corresponding_Spec (N);
8503 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Pid);
8504 -- This flag indicates whether the lock free implementation is active
8506 Current_Node : Node_Id;
8507 Disp_Op_Body : Node_Id;
8508 New_Op_Body : Node_Id;
8512 function Build_Dispatching_Subprogram_Body
8515 Prot_Bod : Node_Id) return Node_Id;
8516 -- Build a dispatching version of the protected subprogram body. The
8517 -- newly generated subprogram contains a call to the original protected
8518 -- body. The following code is generated:
8520 -- function <protected-function-name> (Param1 .. ParamN) return
8523 -- return <protected-function-name>P (Param1 .. ParamN);
8524 -- end <protected-function-name>;
8528 -- procedure <protected-procedure-name> (Param1 .. ParamN) is
8530 -- <protected-procedure-name>P (Param1 .. ParamN);
8531 -- end <protected-procedure-name>
8533 ---------------------------------------
8534 -- Build_Dispatching_Subprogram_Body --
8535 ---------------------------------------
8537 function Build_Dispatching_Subprogram_Body
8540 Prot_Bod : Node_Id) return Node_Id
8542 Loc : constant Source_Ptr := Sloc (N);
8549 -- Generate a specification without a letter suffix in order to
8550 -- override an interface function or procedure.
8552 Spec := Build_Protected_Sub_Specification (N, Pid, Dispatching_Mode);
8554 -- The formal parameters become the actuals of the protected function
8555 -- or procedure call.
8557 Actuals := New_List;
8558 Formal := First (Parameter_Specifications (Spec));
8559 while Present (Formal) loop
8561 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
8565 if Nkind (Spec) = N_Procedure_Specification then
8568 Make_Procedure_Call_Statement (Loc,
8570 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8571 Parameter_Associations => Actuals));
8574 pragma Assert (Nkind (Spec) = N_Function_Specification);
8578 Make_Simple_Return_Statement (Loc,
8580 Make_Function_Call (Loc,
8582 New_Occurrence_Of (Corresponding_Spec (Prot_Bod), Loc),
8583 Parameter_Associations => Actuals)));
8587 Make_Subprogram_Body (Loc,
8588 Declarations => Empty_List,
8589 Specification => Spec,
8590 Handled_Statement_Sequence =>
8591 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
8592 end Build_Dispatching_Subprogram_Body;
8594 -- Start of processing for Expand_N_Protected_Body
8597 if No_Run_Time_Mode then
8598 Error_Msg_CRT ("protected body", N);
8602 -- This is the proper body corresponding to a stub. The declarations
8603 -- must be inserted at the point of the stub, which in turn is in the
8604 -- declarative part of the parent unit.
8606 if Nkind (Parent (N)) = N_Subunit then
8607 Current_Node := Corresponding_Stub (Parent (N));
8612 Op_Body := First (Declarations (N));
8614 -- The protected body is replaced with the bodies of its
8615 -- protected operations, and the declarations for internal objects
8616 -- that may have been created for entry family bounds.
8618 Rewrite (N, Make_Null_Statement (Sloc (N)));
8621 while Present (Op_Body) loop
8622 case Nkind (Op_Body) is
8623 when N_Subprogram_Declaration =>
8626 when N_Subprogram_Body =>
8628 -- Do not create bodies for eliminated operations
8630 if not Is_Eliminated (Defining_Entity (Op_Body))
8631 and then not Is_Eliminated (Corresponding_Spec (Op_Body))
8633 if Lock_Free_Active then
8635 Build_Lock_Free_Unprotected_Subprogram_Body
8639 Build_Unprotected_Subprogram_Body (Op_Body, Pid);
8642 Insert_After (Current_Node, New_Op_Body);
8643 Current_Node := New_Op_Body;
8644 Analyze (New_Op_Body);
8646 -- Build the corresponding protected operation. It may
8647 -- appear that this is needed only if this is a visible
8648 -- operation of the type, or if it is an interrupt handler,
8649 -- and this was the strategy used previously in GNAT.
8651 -- However, the operation may be exported through a 'Access
8652 -- to an external caller. This is the common idiom in code
8653 -- that uses the Ada 2005 Timing_Events package. As a result
8654 -- we need to produce the protected body for both visible
8655 -- and private operations, as well as operations that only
8656 -- have a body in the source, and for which we create a
8657 -- declaration in the protected body itself.
8659 if Present (Corresponding_Spec (Op_Body)) then
8660 if Lock_Free_Active then
8662 Build_Lock_Free_Protected_Subprogram_Body
8663 (Op_Body, Pid, Specification (New_Op_Body));
8666 Build_Protected_Subprogram_Body
8667 (Op_Body, Pid, Specification (New_Op_Body));
8670 Insert_After (Current_Node, New_Op_Body);
8671 Analyze (New_Op_Body);
8673 Current_Node := New_Op_Body;
8675 -- Generate an overriding primitive operation body for
8676 -- this subprogram if the protected type implements an
8679 if Ada_Version >= Ada_2005
8681 Present (Interfaces (Corresponding_Record_Type (Pid)))
8684 Build_Dispatching_Subprogram_Body
8685 (Op_Body, Pid, New_Op_Body);
8687 Insert_After (Current_Node, Disp_Op_Body);
8688 Analyze (Disp_Op_Body);
8690 Current_Node := Disp_Op_Body;
8695 when N_Entry_Body =>
8696 Op_Id := Defining_Identifier (Op_Body);
8697 New_Op_Body := Build_Protected_Entry (Op_Body, Op_Id, Pid);
8699 Insert_After (Current_Node, New_Op_Body);
8700 Current_Node := New_Op_Body;
8701 Analyze (New_Op_Body);
8703 when N_Implicit_Label_Declaration =>
8706 when N_Itype_Reference =>
8707 Insert_After (Current_Node, New_Copy (Op_Body));
8709 when N_Freeze_Entity =>
8710 New_Op_Body := New_Copy (Op_Body);
8712 if Present (Entity (Op_Body))
8713 and then Freeze_Node (Entity (Op_Body)) = Op_Body
8715 Set_Freeze_Node (Entity (Op_Body), New_Op_Body);
8718 Insert_After (Current_Node, New_Op_Body);
8719 Current_Node := New_Op_Body;
8720 Analyze (New_Op_Body);
8723 New_Op_Body := New_Copy (Op_Body);
8724 Insert_After (Current_Node, New_Op_Body);
8725 Current_Node := New_Op_Body;
8726 Analyze (New_Op_Body);
8728 when N_Object_Declaration =>
8729 pragma Assert (not Comes_From_Source (Op_Body));
8730 New_Op_Body := New_Copy (Op_Body);
8731 Insert_After (Current_Node, New_Op_Body);
8732 Current_Node := New_Op_Body;
8733 Analyze (New_Op_Body);
8736 raise Program_Error;
8743 -- Finally, create the body of the function that maps an entry index
8744 -- into the corresponding body index, except when there is no entry, or
8745 -- in a Ravenscar-like profile.
8747 if Corresponding_Runtime_Package (Pid) =
8748 System_Tasking_Protected_Objects_Entries
8750 New_Op_Body := Build_Find_Body_Index (Pid);
8751 Insert_After (Current_Node, New_Op_Body);
8752 Current_Node := New_Op_Body;
8753 Analyze (New_Op_Body);
8756 -- Ada 2005 (AI-345): Construct the primitive wrapper bodies after the
8757 -- protected body. At this point all wrapper specs have been created,
8758 -- frozen and included in the dispatch table for the protected type.
8760 if Ada_Version >= Ada_2005 then
8761 Build_Wrapper_Bodies (Loc, Pid, Current_Node);
8763 end Expand_N_Protected_Body;
8765 -----------------------------------------
8766 -- Expand_N_Protected_Type_Declaration --
8767 -----------------------------------------
8769 -- First we create a corresponding record type declaration used to
8770 -- represent values of this protected type.
8771 -- The general form of this type declaration is
8773 -- type poV (discriminants) is record
8774 -- _Object : aliased <kind>Protection
8775 -- [(<entry count> [, <handler count>])];
8776 -- [entry_family : array (bounds) of Void;]
8777 -- <private data fields>
8780 -- The discriminants are present only if the corresponding protected type
8781 -- has discriminants, and they exactly mirror the protected type
8782 -- discriminants. The private data fields similarly mirror the private
8783 -- declarations of the protected type.
8785 -- The Object field is always present. It contains RTS specific data used
8786 -- to control the protected object. It is declared as Aliased so that it
8787 -- can be passed as a pointer to the RTS. This allows the protected record
8788 -- to be referenced within RTS data structures. An appropriate Protection
8789 -- type and discriminant are generated.
8791 -- The Service field is present for protected objects with entries. It
8792 -- contains sufficient information to allow the entry service procedure for
8793 -- this object to be called when the object is not known till runtime.
8795 -- One entry_family component is present for each entry family in the
8796 -- task definition (see Expand_N_Task_Type_Declaration).
8798 -- When a protected object is declared, an instance of the protected type
8799 -- value record is created. The elaboration of this declaration creates the
8800 -- correct bounds for the entry families, and also evaluates the priority
8801 -- expression if needed. The initialization routine for the protected type
8802 -- itself then calls Initialize_Protection with appropriate parameters to
8803 -- initialize the value of the Task_Id field. Install_Handlers may be also
8804 -- called if a pragma Attach_Handler applies.
8806 -- Note: this record is passed to the subprograms created by the expansion
8807 -- of protected subprograms and entries. It is an in parameter to protected
8808 -- functions and an in out parameter to procedures and entry bodies. The
8809 -- Entity_Id for this created record type is placed in the
8810 -- Corresponding_Record_Type field of the associated protected type entity.
8812 -- Next we create a procedure specifications for protected subprograms and
8813 -- entry bodies. For each protected subprograms two subprograms are
8814 -- created, an unprotected and a protected version. The unprotected version
8815 -- is called from within other operations of the same protected object.
8817 -- We also build the call to register the procedure if a pragma
8818 -- Interrupt_Handler applies.
8820 -- A single subprogram is created to service all entry bodies; it has an
8821 -- additional boolean out parameter indicating that the previous entry call
8822 -- made by the current task was serviced immediately, i.e. not by proxy.
8823 -- The O parameter contains a pointer to a record object of the type
8824 -- described above. An untyped interface is used here to allow this
8825 -- procedure to be called in places where the type of the object to be
8826 -- serviced is not known. This must be done, for example, when a call that
8827 -- may have been requeued is cancelled; the corresponding object must be
8828 -- serviced, but which object that is not known till runtime.
8831 -- (O : System.Address; P : out Boolean);
8832 -- procedure pprocN (_object : in out poV);
8833 -- procedure pproc (_object : in out poV);
8834 -- function pfuncN (_object : poV);
8835 -- function pfunc (_object : poV);
8838 -- Note that this must come after the record type declaration, since
8839 -- the specs refer to this type.
8841 procedure Expand_N_Protected_Type_Declaration (N : Node_Id) is
8842 Loc : constant Source_Ptr := Sloc (N);
8843 Prot_Typ : constant Entity_Id := Defining_Identifier (N);
8845 Lock_Free_Active : constant Boolean := Uses_Lock_Free (Prot_Typ);
8846 -- This flag indicates whether the lock free implementation is active
8848 Pdef : constant Node_Id := Protected_Definition (N);
8849 -- This contains two lists; one for visible and one for private decls
8853 Discr_Map : constant Elist_Id := New_Elmt_List;
8857 Comp_Id : Entity_Id;
8859 Current_Node : Node_Id := N;
8860 Entries_Aggr : Node_Id;
8861 Body_Id : Entity_Id;
8864 Object_Comp : Node_Id;
8866 procedure Check_Inlining (Subp : Entity_Id);
8867 -- If the original operation has a pragma Inline, propagate the flag
8868 -- to the internal body, for possible inlining later on. The source
8869 -- operation is invisible to the back-end and is never actually called.
8871 function Discriminated_Size (Comp : Entity_Id) return Boolean;
8872 -- If a component size is not static then a warning will be emitted
8873 -- in Ravenscar or other restricted contexts. When a component is non-
8874 -- static because of a discriminant constraint we can specialize the
8875 -- warning by mentioning discriminants explicitly.
8877 procedure Expand_Entry_Declaration (Comp : Entity_Id);
8878 -- Create the subprograms for the barrier and for the body, and append
8879 -- then to Entry_Bodies_Array.
8881 function Static_Component_Size (Comp : Entity_Id) return Boolean;
8882 -- When compiling under the Ravenscar profile, private components must
8883 -- have a static size, or else a protected object will require heap
8884 -- allocation, violating the corresponding restriction. It is preferable
8885 -- to make this check here, because it provides a better error message
8886 -- than the back-end, which refers to the object as a whole.
8888 procedure Register_Handler;
8889 -- For a protected operation that is an interrupt handler, add the
8890 -- freeze action that will register it as such.
8892 --------------------
8893 -- Check_Inlining --
8894 --------------------
8896 procedure Check_Inlining (Subp : Entity_Id) is
8898 if Is_Inlined (Subp) then
8899 Set_Is_Inlined (Protected_Body_Subprogram (Subp));
8900 Set_Is_Inlined (Subp, False);
8904 ------------------------
8905 -- Discriminated_Size --
8906 ------------------------
8908 function Discriminated_Size (Comp : Entity_Id) return Boolean is
8909 Typ : constant Entity_Id := Etype (Comp);
8912 function Non_Static_Bound (Bound : Node_Id) return Boolean;
8913 -- Check whether the bound of an index is non-static and does denote
8914 -- a discriminant, in which case any protected object of the type
8915 -- will have a non-static size.
8917 ----------------------
8918 -- Non_Static_Bound --
8919 ----------------------
8921 function Non_Static_Bound (Bound : Node_Id) return Boolean is
8923 if Is_OK_Static_Expression (Bound) then
8926 elsif Is_Entity_Name (Bound)
8927 and then Present (Discriminal_Link (Entity (Bound)))
8934 end Non_Static_Bound;
8936 -- Start of processing for Discriminated_Size
8939 if not Is_Array_Type (Typ) then
8943 if Ekind (Typ) = E_Array_Subtype then
8944 Index := First_Index (Typ);
8945 while Present (Index) loop
8946 if Non_Static_Bound (Low_Bound (Index))
8947 or else Non_Static_Bound (High_Bound (Index))
8959 end Discriminated_Size;
8961 ---------------------------
8962 -- Static_Component_Size --
8963 ---------------------------
8965 function Static_Component_Size (Comp : Entity_Id) return Boolean is
8966 Typ : constant Entity_Id := Etype (Comp);
8970 if Is_Scalar_Type (Typ) then
8973 elsif Is_Array_Type (Typ) then
8974 return Compile_Time_Known_Bounds (Typ);
8976 elsif Is_Record_Type (Typ) then
8977 C := First_Component (Typ);
8978 while Present (C) loop
8979 if not Static_Component_Size (C) then
8988 -- Any other type will be checked by the back-end
8993 end Static_Component_Size;
8995 ------------------------------
8996 -- Expand_Entry_Declaration --
8997 ------------------------------
8999 procedure Expand_Entry_Declaration (Comp : Entity_Id) is
9004 E_Count := E_Count + 1;
9005 Comp_Id := Defining_Identifier (Comp);
9008 Make_Defining_Identifier (Loc,
9009 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'E'));
9011 Make_Subprogram_Declaration (Loc,
9013 Build_Protected_Entry_Specification (Loc, Edef, Comp_Id));
9015 Insert_After (Current_Node, Sub);
9018 -- Build wrapper procedure for pre/postconditions
9020 Build_PPC_Wrapper (Comp_Id, N);
9022 Set_Protected_Body_Subprogram
9023 (Defining_Identifier (Comp),
9024 Defining_Unit_Name (Specification (Sub)));
9026 Current_Node := Sub;
9029 Make_Defining_Identifier (Loc,
9030 Chars => Build_Selected_Name (Prot_Typ, Comp_Id, 'B'));
9032 Make_Subprogram_Declaration (Loc,
9034 Build_Barrier_Function_Specification (Loc, Bdef));
9036 Insert_After (Current_Node, Sub);
9038 Set_Protected_Body_Subprogram (Bdef, Bdef);
9039 Set_Barrier_Function (Comp_Id, Bdef);
9040 Set_Scope (Bdef, Scope (Comp_Id));
9041 Current_Node := Sub;
9043 -- Collect pointers to the protected subprogram and the barrier
9044 -- of the current entry, for insertion into Entry_Bodies_Array.
9046 Append_To (Expressions (Entries_Aggr),
9047 Make_Aggregate (Loc,
9048 Expressions => New_List (
9049 Make_Attribute_Reference (Loc,
9050 Prefix => New_Occurrence_Of (Bdef, Loc),
9051 Attribute_Name => Name_Unrestricted_Access),
9052 Make_Attribute_Reference (Loc,
9053 Prefix => New_Occurrence_Of (Edef, Loc),
9054 Attribute_Name => Name_Unrestricted_Access))));
9055 end Expand_Entry_Declaration;
9057 ----------------------
9058 -- Register_Handler --
9059 ----------------------
9061 procedure Register_Handler is
9063 -- All semantic checks already done in Sem_Prag
9065 Prot_Proc : constant Entity_Id :=
9066 Defining_Unit_Name (Specification (Current_Node));
9068 Proc_Address : constant Node_Id :=
9069 Make_Attribute_Reference (Loc,
9071 New_Occurrence_Of (Prot_Proc, Loc),
9072 Attribute_Name => Name_Address);
9074 RTS_Call : constant Entity_Id :=
9075 Make_Procedure_Call_Statement (Loc,
9078 (RTE (RE_Register_Interrupt_Handler), Loc),
9079 Parameter_Associations => New_List (Proc_Address));
9081 Append_Freeze_Action (Prot_Proc, RTS_Call);
9082 end Register_Handler;
9084 -- Start of processing for Expand_N_Protected_Type_Declaration
9087 if Present (Corresponding_Record_Type (Prot_Typ)) then
9090 Rec_Decl := Build_Corresponding_Record (N, Prot_Typ, Loc);
9093 Cdecls := Component_Items (Component_List (Type_Definition (Rec_Decl)));
9095 Qualify_Entity_Names (N);
9097 -- If the type has discriminants, their occurrences in the declaration
9098 -- have been replaced by the corresponding discriminals. For components
9099 -- that are constrained by discriminants, their homologues in the
9100 -- corresponding record type must refer to the discriminants of that
9101 -- record, so we must apply a new renaming to subtypes_indications:
9103 -- protected discriminant => discriminal => record discriminant
9105 -- This replacement is not applied to default expressions, for which
9106 -- the discriminal is correct.
9108 if Has_Discriminants (Prot_Typ) then
9114 Disc := First_Discriminant (Prot_Typ);
9115 Decl := First (Discriminant_Specifications (Rec_Decl));
9116 while Present (Disc) loop
9117 Append_Elmt (Discriminal (Disc), Discr_Map);
9118 Append_Elmt (Defining_Identifier (Decl), Discr_Map);
9119 Next_Discriminant (Disc);
9125 -- Fill in the component declarations
9127 -- Add components for entry families. For each entry family, create an
9128 -- anonymous type declaration with the same size, and analyze the type.
9130 Collect_Entry_Families (Loc, Cdecls, Current_Node, Prot_Typ);
9132 pragma Assert (Present (Pdef));
9134 -- Add private field components
9136 if Present (Private_Declarations (Pdef)) then
9137 Priv := First (Private_Declarations (Pdef));
9138 while Present (Priv) loop
9139 if Nkind (Priv) = N_Component_Declaration then
9140 if not Static_Component_Size (Defining_Identifier (Priv)) then
9142 -- When compiling for a restricted profile, the private
9143 -- components must have a static size. If not, this is an
9144 -- error for a single protected declaration, and rates a
9145 -- warning on a protected type declaration.
9147 if not Comes_From_Source (Prot_Typ) then
9149 -- It's ok to be checking this restriction at expansion
9150 -- time, because this is only for the restricted profile,
9151 -- which is not subject to strict RM conformance, so it
9152 -- is OK to miss this check in -gnatc mode.
9154 Check_Restriction (No_Implicit_Heap_Allocations, Priv);
9156 elsif Restriction_Active (No_Implicit_Heap_Allocations) then
9157 if not Discriminated_Size (Defining_Identifier (Priv))
9160 -- Any object of the type will be non-static.
9162 Error_Msg_N ("component has non-static size??", Priv);
9164 ("\creation of protected object of type& will"
9165 & " violate restriction "
9166 & "No_Implicit_Heap_Allocations??", Priv, Prot_Typ);
9169 -- Object will be non-static if discriminants are.
9172 ("creation of protected object of type& with "
9173 & "non-static discriminants will violate"
9174 & " restriction No_Implicit_Heap_Allocations??",
9180 -- The component definition consists of a subtype indication,
9181 -- or (in Ada 2005) an access definition. Make a copy of the
9182 -- proper definition.
9185 Old_Comp : constant Node_Id := Component_Definition (Priv);
9186 Oent : constant Entity_Id := Defining_Identifier (Priv);
9188 Nent : constant Entity_Id :=
9189 Make_Defining_Identifier (Sloc (Oent),
9190 Chars => Chars (Oent));
9193 if Present (Subtype_Indication (Old_Comp)) then
9195 Make_Component_Definition (Sloc (Oent),
9196 Aliased_Present => False,
9197 Subtype_Indication =>
9198 New_Copy_Tree (Subtype_Indication (Old_Comp),
9202 Make_Component_Definition (Sloc (Oent),
9203 Aliased_Present => False,
9204 Access_Definition =>
9205 New_Copy_Tree (Access_Definition (Old_Comp),
9210 Make_Component_Declaration (Loc,
9211 Defining_Identifier => Nent,
9212 Component_Definition => New_Comp,
9213 Expression => Expression (Priv));
9215 Set_Has_Per_Object_Constraint (Nent,
9216 Has_Per_Object_Constraint (Oent));
9218 Append_To (Cdecls, New_Priv);
9221 elsif Nkind (Priv) = N_Subprogram_Declaration then
9223 -- Make the unprotected version of the subprogram available
9224 -- for expansion of intra object calls. There is need for
9225 -- a protected version only if the subprogram is an interrupt
9226 -- handler, otherwise this operation can only be called from
9230 Make_Subprogram_Declaration (Loc,
9232 Build_Protected_Sub_Specification
9233 (Priv, Prot_Typ, Unprotected_Mode));
9235 Insert_After (Current_Node, Sub);
9238 Set_Protected_Body_Subprogram
9239 (Defining_Unit_Name (Specification (Priv)),
9240 Defining_Unit_Name (Specification (Sub)));
9241 Check_Inlining (Defining_Unit_Name (Specification (Priv)));
9242 Current_Node := Sub;
9245 Make_Subprogram_Declaration (Loc,
9247 Build_Protected_Sub_Specification
9248 (Priv, Prot_Typ, Protected_Mode));
9250 Insert_After (Current_Node, Sub);
9252 Current_Node := Sub;
9254 if Is_Interrupt_Handler
9255 (Defining_Unit_Name (Specification (Priv)))
9257 if not Restricted_Profile then
9267 -- Except for the lock-free implementation, append the _Object field
9268 -- with the right type to the component list. We need to compute the
9269 -- number of entries, and in some cases the number of Attach_Handler
9272 if not Lock_Free_Active then
9275 Num_Attach_Handler : Int := 0;
9276 Protection_Subtype : Node_Id;
9277 Entry_Count_Expr : constant Node_Id :=
9278 Build_Entry_Count_Expression
9279 (Prot_Typ, Cdecls, Loc);
9282 if Has_Attach_Handler (Prot_Typ) then
9283 Ritem := First_Rep_Item (Prot_Typ);
9284 while Present (Ritem) loop
9285 if Nkind (Ritem) = N_Pragma
9286 and then Pragma_Name (Ritem) = Name_Attach_Handler
9288 Num_Attach_Handler := Num_Attach_Handler + 1;
9291 Next_Rep_Item (Ritem);
9295 -- Determine the proper protection type. There are two special
9296 -- cases: 1) when the protected type has dynamic interrupt
9297 -- handlers, and 2) when it has static handlers and we use a
9298 -- restricted profile.
9300 if Has_Attach_Handler (Prot_Typ)
9301 and then not Restricted_Profile
9303 Protection_Subtype :=
9304 Make_Subtype_Indication (Loc,
9307 (RTE (RE_Static_Interrupt_Protection), Loc),
9309 Make_Index_Or_Discriminant_Constraint (Loc,
9310 Constraints => New_List (
9312 Make_Integer_Literal (Loc, Num_Attach_Handler))));
9314 elsif Has_Interrupt_Handler (Prot_Typ)
9315 and then not Restriction_Active (No_Dynamic_Attachment)
9317 Protection_Subtype :=
9318 Make_Subtype_Indication (Loc,
9321 (RTE (RE_Dynamic_Interrupt_Protection), Loc),
9323 Make_Index_Or_Discriminant_Constraint (Loc,
9324 Constraints => New_List (Entry_Count_Expr)));
9327 case Corresponding_Runtime_Package (Prot_Typ) is
9328 when System_Tasking_Protected_Objects_Entries =>
9329 Protection_Subtype :=
9330 Make_Subtype_Indication (Loc,
9333 (RTE (RE_Protection_Entries), Loc),
9335 Make_Index_Or_Discriminant_Constraint (Loc,
9336 Constraints => New_List (Entry_Count_Expr)));
9338 when System_Tasking_Protected_Objects_Single_Entry =>
9339 Protection_Subtype :=
9340 New_Occurrence_Of (RTE (RE_Protection_Entry), Loc);
9342 when System_Tasking_Protected_Objects =>
9343 Protection_Subtype :=
9344 New_Occurrence_Of (RTE (RE_Protection), Loc);
9347 raise Program_Error;
9352 Make_Component_Declaration (Loc,
9353 Defining_Identifier =>
9354 Make_Defining_Identifier (Loc, Name_uObject),
9355 Component_Definition =>
9356 Make_Component_Definition (Loc,
9357 Aliased_Present => True,
9358 Subtype_Indication => Protection_Subtype));
9361 -- Put the _Object component after the private component so that it
9362 -- be finalized early as required by 9.4 (20)
9364 Append_To (Cdecls, Object_Comp);
9367 Insert_After (Current_Node, Rec_Decl);
9368 Current_Node := Rec_Decl;
9370 -- Analyze the record declaration immediately after construction,
9371 -- because the initialization procedure is needed for single object
9372 -- declarations before the next entity is analyzed (the freeze call
9373 -- that generates this initialization procedure is found below).
9375 Analyze (Rec_Decl, Suppress => All_Checks);
9377 -- Ada 2005 (AI-345): Construct the primitive entry wrappers before
9378 -- the corresponding record is frozen. If any wrappers are generated,
9379 -- Current_Node is updated accordingly.
9381 if Ada_Version >= Ada_2005 then
9382 Build_Wrapper_Specs (Loc, Prot_Typ, Current_Node);
9385 -- Collect pointers to entry bodies and their barriers, to be placed
9386 -- in the Entry_Bodies_Array for the type. For each entry/family we
9387 -- add an expression to the aggregate which is the initial value of
9388 -- this array. The array is declared after all protected subprograms.
9390 if Has_Entries (Prot_Typ) then
9391 Entries_Aggr := Make_Aggregate (Loc, Expressions => New_List);
9393 Entries_Aggr := Empty;
9396 -- Build two new procedure specifications for each protected subprogram;
9397 -- one to call from outside the object and one to call from inside.
9398 -- Build a barrier function and an entry body action procedure
9399 -- specification for each protected entry. Initialize the entry body
9400 -- array. If subprogram is flagged as eliminated, do not generate any
9401 -- internal operations.
9404 Comp := First (Visible_Declarations (Pdef));
9405 while Present (Comp) loop
9406 if Nkind (Comp) = N_Subprogram_Declaration then
9408 Make_Subprogram_Declaration (Loc,
9410 Build_Protected_Sub_Specification
9411 (Comp, Prot_Typ, Unprotected_Mode));
9413 Insert_After (Current_Node, Sub);
9416 Set_Protected_Body_Subprogram
9417 (Defining_Unit_Name (Specification (Comp)),
9418 Defining_Unit_Name (Specification (Sub)));
9419 Check_Inlining (Defining_Unit_Name (Specification (Comp)));
9421 -- Make the protected version of the subprogram available for
9422 -- expansion of external calls.
9424 Current_Node := Sub;
9427 Make_Subprogram_Declaration (Loc,
9429 Build_Protected_Sub_Specification
9430 (Comp, Prot_Typ, Protected_Mode));
9432 Insert_After (Current_Node, Sub);
9435 Current_Node := Sub;
9437 -- Generate an overriding primitive operation specification for
9438 -- this subprogram if the protected type implements an interface.
9440 if Ada_Version >= Ada_2005
9442 Present (Interfaces (Corresponding_Record_Type (Prot_Typ)))
9445 Make_Subprogram_Declaration (Loc,
9447 Build_Protected_Sub_Specification
9448 (Comp, Prot_Typ, Dispatching_Mode));
9450 Insert_After (Current_Node, Sub);
9453 Current_Node := Sub;
9456 -- If a pragma Interrupt_Handler applies, build and add a call to
9457 -- Register_Interrupt_Handler to the freezing actions of the
9458 -- protected version (Current_Node) of the subprogram:
9460 -- system.interrupts.register_interrupt_handler
9461 -- (prot_procP'address);
9463 if not Restricted_Profile
9464 and then Is_Interrupt_Handler
9465 (Defining_Unit_Name (Specification (Comp)))
9470 elsif Nkind (Comp) = N_Entry_Declaration then
9472 Expand_Entry_Declaration (Comp);
9479 -- If there are some private entry declarations, expand it as if they
9480 -- were visible entries.
9482 if Present (Private_Declarations (Pdef)) then
9483 Comp := First (Private_Declarations (Pdef));
9484 while Present (Comp) loop
9485 if Nkind (Comp) = N_Entry_Declaration then
9486 Expand_Entry_Declaration (Comp);
9493 -- Emit declaration for Entry_Bodies_Array, now that the addresses of
9494 -- all protected subprograms have been collected.
9496 if Has_Entries (Prot_Typ) then
9498 Make_Defining_Identifier (Sloc (Prot_Typ),
9499 Chars => New_External_Name (Chars (Prot_Typ), 'A'));
9501 case Corresponding_Runtime_Package (Prot_Typ) is
9502 when System_Tasking_Protected_Objects_Entries =>
9503 Body_Arr := Make_Object_Declaration (Loc,
9504 Defining_Identifier => Body_Id,
9505 Aliased_Present => True,
9506 Object_Definition =>
9507 Make_Subtype_Indication (Loc,
9508 Subtype_Mark => New_Occurrence_Of (
9509 RTE (RE_Protected_Entry_Body_Array), Loc),
9511 Make_Index_Or_Discriminant_Constraint (Loc,
9512 Constraints => New_List (
9514 Make_Integer_Literal (Loc, 1),
9515 Make_Integer_Literal (Loc, E_Count))))),
9516 Expression => Entries_Aggr);
9518 when System_Tasking_Protected_Objects_Single_Entry =>
9519 Body_Arr := Make_Object_Declaration (Loc,
9520 Defining_Identifier => Body_Id,
9521 Aliased_Present => True,
9522 Object_Definition => New_Occurrence_Of
9523 (RTE (RE_Entry_Body), Loc),
9524 Expression => Remove_Head (Expressions (Entries_Aggr)));
9527 raise Program_Error;
9530 -- A pointer to this array will be placed in the corresponding record
9531 -- by its initialization procedure so this needs to be analyzed here.
9533 Insert_After (Current_Node, Body_Arr);
9534 Current_Node := Body_Arr;
9537 Set_Entry_Bodies_Array (Prot_Typ, Body_Id);
9539 -- Finally, build the function that maps an entry index into the
9540 -- corresponding body. A pointer to this function is placed in each
9541 -- object of the type. Except for a ravenscar-like profile (no abort,
9542 -- no entry queue, 1 entry)
9544 if Corresponding_Runtime_Package (Prot_Typ) =
9545 System_Tasking_Protected_Objects_Entries
9548 Make_Subprogram_Declaration (Loc,
9549 Specification => Build_Find_Body_Index_Spec (Prot_Typ));
9550 Insert_After (Current_Node, Sub);
9554 end Expand_N_Protected_Type_Declaration;
9556 --------------------------------
9557 -- Expand_N_Requeue_Statement --
9558 --------------------------------
9560 -- A non-dispatching requeue statement is expanded into one of four GNARLI
9561 -- operations, depending on the source and destination (task or protected
9562 -- object). A dispatching requeue statement is expanded into a call to the
9563 -- predefined primitive _Disp_Requeue. In addition, code is generated to
9564 -- jump around the remainder of processing for the original entry and, if
9565 -- the destination is (different) protected object, to attempt to service
9566 -- it. The following illustrates the various cases:
9569 -- (O : System.Address;
9570 -- P : System.Address;
9571 -- E : Protected_Entry_Index)
9573 -- <discriminant renamings>
9574 -- <private object renamings>
9575 -- type poVP is access poV;
9576 -- _object : ptVP := ptVP!(O);
9580 -- <start of statement sequence for entry>
9582 -- -- Requeue from one protected entry body to another protected
9585 -- Requeue_Protected_Entry (
9586 -- _object._object'Access,
9587 -- new._object'Access,
9592 -- <some more of the statement sequence for entry>
9594 -- -- Requeue from an entry body to a task entry
9596 -- Requeue_Protected_To_Task_Entry (
9602 -- <rest of statement sequence for entry>
9603 -- Complete_Entry_Body (_object._object);
9606 -- when all others =>
9607 -- Exceptional_Complete_Entry_Body (
9608 -- _object._object, Get_GNAT_Exception);
9612 -- Requeue of a task entry call to a task entry
9614 -- Accept_Call (E, Ann);
9615 -- <start of statement sequence for accept statement>
9616 -- Requeue_Task_Entry (New._task_id, E, Abort_Present);
9618 -- <rest of statement sequence for accept statement>
9620 -- Complete_Rendezvous;
9623 -- when all others =>
9624 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9626 -- Requeue of a task entry call to a protected entry
9628 -- Accept_Call (E, Ann);
9629 -- <start of statement sequence for accept statement>
9630 -- Requeue_Task_To_Protected_Entry (
9631 -- new._object'Access,
9636 -- <rest of statement sequence for accept statement>
9638 -- Complete_Rendezvous;
9641 -- when all others =>
9642 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9644 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9645 -- marked by pragma Implemented (XXX, By_Entry).
9647 -- The requeue is inside a protected entry:
9650 -- (O : System.Address;
9651 -- P : System.Address;
9652 -- E : Protected_Entry_Index)
9654 -- <discriminant renamings>
9655 -- <private object renamings>
9656 -- type poVP is access poV;
9657 -- _object : ptVP := ptVP!(O);
9661 -- <start of statement sequence for entry>
9664 -- (<interface class-wide object>,
9667 -- Ada.Tags.Get_Offset_Index
9669 -- <interface dispatch table index of target entry>),
9673 -- <rest of statement sequence for entry>
9674 -- Complete_Entry_Body (_object._object);
9677 -- when all others =>
9678 -- Exceptional_Complete_Entry_Body (
9679 -- _object._object, Get_GNAT_Exception);
9683 -- The requeue is inside a task entry:
9685 -- Accept_Call (E, Ann);
9686 -- <start of statement sequence for accept statement>
9688 -- (<interface class-wide object>,
9691 -- Ada.Tags.Get_Offset_Index
9693 -- <interface dispatch table index of target entrt>),
9697 -- <rest of statement sequence for accept statement>
9699 -- Complete_Rendezvous;
9702 -- when all others =>
9703 -- Exceptional_Complete_Rendezvous (Get_GNAT_Exception);
9705 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9706 -- marked by pragma Implemented (XXX, By_Protected_Procedure). The requeue
9707 -- statement is replaced by a dispatching call with actual parameters taken
9708 -- from the inner-most accept statement or entry body.
9710 -- Target.Primitive (Param1, ..., ParamN);
9712 -- Ada 2012 (AI05-0030): Dispatching requeue to an interface primitive
9713 -- marked by pragma Implemented (XXX, By_Any | Optional) or not marked
9717 -- S : constant Offset_Index :=
9718 -- Get_Offset_Index (Tag (Concval), DT_Position (Ename));
9719 -- C : constant Prim_Op_Kind := Get_Prim_Op_Kind (Tag (Concval), S);
9722 -- if C = POK_Protected_Entry
9723 -- or else C = POK_Task_Entry
9725 -- <statements for dispatching requeue>
9727 -- elsif C = POK_Protected_Procedure then
9728 -- <dispatching call equivalent>
9731 -- raise Program_Error;
9735 procedure Expand_N_Requeue_Statement (N : Node_Id) is
9736 Loc : constant Source_Ptr := Sloc (N);
9737 Conc_Typ : Entity_Id;
9741 Old_Typ : Entity_Id;
9743 function Build_Dispatching_Call_Equivalent return Node_Id;
9744 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9745 -- the form Concval.Ename. It is statically known that Ename is allowed
9746 -- to be implemented by a protected procedure. Create a dispatching call
9747 -- equivalent of Concval.Ename taking the actual parameters from the
9748 -- inner-most accept statement or entry body.
9750 function Build_Dispatching_Requeue return Node_Id;
9751 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9752 -- the form Concval.Ename. It is statically known that Ename is allowed
9753 -- to be implemented by a protected or a task entry. Create a call to
9754 -- primitive _Disp_Requeue which handles the low-level actions.
9756 function Build_Dispatching_Requeue_To_Any return Node_Id;
9757 -- Ada 2012 (AI05-0030): N denotes a dispatching requeue statement of
9758 -- the form Concval.Ename. Ename is either marked by pragma Implemented
9759 -- (XXX, By_Any | Optional) or not marked at all. Create a block which
9760 -- determines at runtime whether Ename denotes an entry or a procedure
9761 -- and perform the appropriate kind of dispatching select.
9763 function Build_Normal_Requeue return Node_Id;
9764 -- N denotes a non-dispatching requeue statement to either a task or a
9765 -- protected entry. Build the appropriate runtime call to perform the
9768 function Build_Skip_Statement (Search : Node_Id) return Node_Id;
9769 -- For a protected entry, create a return statement to skip the rest of
9770 -- the entry body. Otherwise, create a goto statement to skip the rest
9771 -- of a task accept statement. The lookup for the enclosing entry body
9772 -- or accept statement starts from Search.
9774 ---------------------------------------
9775 -- Build_Dispatching_Call_Equivalent --
9776 ---------------------------------------
9778 function Build_Dispatching_Call_Equivalent return Node_Id is
9779 Call_Ent : constant Entity_Id := Entity (Ename);
9780 Obj : constant Node_Id := Original_Node (Concval);
9787 -- Climb the parent chain looking for the inner-most entry body or
9788 -- accept statement.
9791 while Present (Acc_Ent)
9792 and then not Nkind_In (Acc_Ent, N_Accept_Statement,
9795 Acc_Ent := Parent (Acc_Ent);
9798 -- A requeue statement should be housed inside an entry body or an
9799 -- accept statement at some level. If this is not the case, then the
9800 -- tree is malformed.
9802 pragma Assert (Present (Acc_Ent));
9804 -- Recover the list of formal parameters
9806 if Nkind (Acc_Ent) = N_Entry_Body then
9807 Acc_Ent := Entry_Body_Formal_Part (Acc_Ent);
9810 Formals := Parameter_Specifications (Acc_Ent);
9812 -- Create the actual parameters for the dispatching call. These are
9813 -- simply copies of the entry body or accept statement formals in the
9814 -- same order as they appear.
9818 if Present (Formals) then
9819 Actuals := New_List;
9820 Formal := First (Formals);
9821 while Present (Formal) loop
9823 Make_Identifier (Loc, Chars (Defining_Identifier (Formal))));
9829 -- Obj.Call_Ent (Actuals);
9832 Make_Procedure_Call_Statement (Loc,
9834 Make_Selected_Component (Loc,
9835 Prefix => Make_Identifier (Loc, Chars (Obj)),
9836 Selector_Name => Make_Identifier (Loc, Chars (Call_Ent))),
9838 Parameter_Associations => Actuals);
9839 end Build_Dispatching_Call_Equivalent;
9841 -------------------------------
9842 -- Build_Dispatching_Requeue --
9843 -------------------------------
9845 function Build_Dispatching_Requeue return Node_Id is
9846 Params : constant List_Id := New_List;
9849 -- Process the "with abort" parameter
9852 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
9854 -- Process the entry wrapper's position in the primary dispatch
9855 -- table parameter. Generate:
9857 -- Ada.Tags.Get_Entry_Index
9858 -- (T => To_Tag_Ptr (Obj'Address).all,
9860 -- Ada.Tags.Get_Offset_Index
9861 -- (Ada.Tags.Tag (Concval),
9862 -- <interface dispatch table position of Ename>));
9864 -- Note that Obj'Address is recursively expanded into a call to
9865 -- Base_Address (Obj).
9867 if Tagged_Type_Expansion then
9869 Make_Function_Call (Loc,
9870 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9871 Parameter_Associations => New_List (
9873 Make_Explicit_Dereference (Loc,
9874 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
9875 Make_Attribute_Reference (Loc,
9876 Prefix => New_Copy_Tree (Concval),
9877 Attribute_Name => Name_Address))),
9879 Make_Function_Call (Loc,
9880 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9881 Parameter_Associations => New_List (
9882 Unchecked_Convert_To (RTE (RE_Tag), Concval),
9883 Make_Integer_Literal (Loc,
9884 DT_Position (Entity (Ename))))))));
9890 Make_Function_Call (Loc,
9891 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
9892 Parameter_Associations => New_List (
9894 Make_Attribute_Reference (Loc,
9896 Attribute_Name => Name_Tag),
9898 Make_Function_Call (Loc,
9899 Name => New_Occurrence_Of (RTE (RE_Get_Offset_Index), Loc),
9901 Parameter_Associations => New_List (
9905 Make_Attribute_Reference (Loc,
9907 Attribute_Name => Name_Tag),
9911 Make_Attribute_Reference (Loc,
9912 Prefix => New_Occurrence_Of (Etype (Concval), Loc),
9913 Attribute_Name => Name_Tag),
9917 Make_Integer_Literal (Loc,
9918 DT_Position (Entity (Ename))))))));
9921 -- Specific actuals for protected to XXX requeue
9923 if Is_Protected_Type (Old_Typ) then
9925 Make_Attribute_Reference (Loc, -- _object'Address
9927 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
9928 Attribute_Name => Name_Address));
9930 Prepend_To (Params, -- True
9931 New_Occurrence_Of (Standard_True, Loc));
9933 -- Specific actuals for task to XXX requeue
9936 pragma Assert (Is_Task_Type (Old_Typ));
9938 Prepend_To (Params, -- null
9939 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
9941 Prepend_To (Params, -- False
9942 New_Occurrence_Of (Standard_False, Loc));
9945 -- Add the object parameter
9947 Prepend_To (Params, New_Copy_Tree (Concval));
9950 -- _Disp_Requeue (<Params>);
9952 -- Find entity for Disp_Requeue operation, which belongs to
9953 -- the type and may not be directly visible.
9960 Elmt := First_Elmt (Primitive_Operations (Etype (Conc_Typ)));
9961 while Present (Elmt) loop
9963 exit when Chars (Op) = Name_uDisp_Requeue;
9968 Make_Procedure_Call_Statement (Loc,
9969 Name => New_Occurrence_Of (Op, Loc),
9970 Parameter_Associations => Params);
9972 end Build_Dispatching_Requeue;
9974 --------------------------------------
9975 -- Build_Dispatching_Requeue_To_Any --
9976 --------------------------------------
9978 function Build_Dispatching_Requeue_To_Any return Node_Id is
9979 Call_Ent : constant Entity_Id := Entity (Ename);
9980 Obj : constant Node_Id := Original_Node (Concval);
9981 Skip : constant Node_Id := Build_Skip_Statement (N);
9991 -- Dispatch table slot processing, generate:
9994 S := Build_S (Loc, Decls);
9996 -- Call kind processing, generate:
9997 -- C : Ada.Tags.Prim_Op_Kind;
9999 C := Build_C (Loc, Decls);
10002 -- S := Ada.Tags.Get_Offset_Index
10003 -- (Ada.Tags.Tag (Obj), DT_Position (Call_Ent));
10005 Append_To (Stmts, Build_S_Assignment (Loc, S, Obj, Call_Ent));
10008 -- _Disp_Get_Prim_Op_Kind (Obj, S, C);
10011 Make_Procedure_Call_Statement (Loc,
10013 New_Occurrence_Of (
10014 Find_Prim_Op (Etype (Etype (Obj)),
10015 Name_uDisp_Get_Prim_Op_Kind),
10017 Parameter_Associations => New_List (
10018 New_Copy_Tree (Obj),
10019 New_Occurrence_Of (S, Loc),
10020 New_Occurrence_Of (C, Loc))));
10024 -- if C = POK_Protected_Entry
10025 -- or else C = POK_Task_Entry
10028 Make_Implicit_If_Statement (N,
10034 New_Occurrence_Of (C, Loc),
10036 New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc)),
10041 New_Occurrence_Of (C, Loc),
10043 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
10045 -- Dispatching requeue equivalent
10047 Then_Statements => New_List (
10048 Build_Dispatching_Requeue,
10051 -- elsif C = POK_Protected_Procedure then
10053 Elsif_Parts => New_List (
10054 Make_Elsif_Part (Loc,
10058 New_Occurrence_Of (C, Loc),
10060 New_Occurrence_Of (
10061 RTE (RE_POK_Protected_Procedure), Loc)),
10063 -- Dispatching call equivalent
10065 Then_Statements => New_List (
10066 Build_Dispatching_Call_Equivalent))),
10069 -- raise Program_Error;
10072 Else_Statements => New_List (
10073 Make_Raise_Program_Error (Loc,
10074 Reason => PE_Explicit_Raise))));
10076 -- Wrap everything into a block
10079 Make_Block_Statement (Loc,
10080 Declarations => Decls,
10081 Handled_Statement_Sequence =>
10082 Make_Handled_Sequence_Of_Statements (Loc,
10083 Statements => Stmts));
10084 end Build_Dispatching_Requeue_To_Any;
10086 --------------------------
10087 -- Build_Normal_Requeue --
10088 --------------------------
10090 function Build_Normal_Requeue return Node_Id is
10091 Params : constant List_Id := New_List;
10096 -- Process the "with abort" parameter
10098 Prepend_To (Params,
10099 New_Occurrence_Of (Boolean_Literals (Abort_Present (N)), Loc));
10101 -- Add the index expression to the parameters. It is common among all
10104 Prepend_To (Params,
10105 Entry_Index_Expression (Loc, Entity (Ename), Index, Conc_Typ));
10107 if Is_Protected_Type (Old_Typ) then
10109 Self_Param : Node_Id;
10113 Make_Attribute_Reference (Loc,
10115 Concurrent_Ref (New_Occurrence_Of (Old_Typ, Loc)),
10117 Name_Unchecked_Access);
10119 -- Protected to protected requeue
10121 if Is_Protected_Type (Conc_Typ) then
10123 New_Occurrence_Of (
10124 RTE (RE_Requeue_Protected_Entry), Loc);
10127 Make_Attribute_Reference (Loc,
10129 Concurrent_Ref (Concval),
10131 Name_Unchecked_Access);
10133 -- Protected to task requeue
10135 else pragma Assert (Is_Task_Type (Conc_Typ));
10137 New_Occurrence_Of (
10138 RTE (RE_Requeue_Protected_To_Task_Entry), Loc);
10140 Param := Concurrent_Ref (Concval);
10143 Prepend_To (Params, Param);
10144 Prepend_To (Params, Self_Param);
10147 else pragma Assert (Is_Task_Type (Old_Typ));
10149 -- Task to protected requeue
10151 if Is_Protected_Type (Conc_Typ) then
10153 New_Occurrence_Of (
10154 RTE (RE_Requeue_Task_To_Protected_Entry), Loc);
10157 Make_Attribute_Reference (Loc,
10159 Concurrent_Ref (Concval),
10161 Name_Unchecked_Access);
10163 -- Task to task requeue
10165 else pragma Assert (Is_Task_Type (Conc_Typ));
10167 New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc);
10169 Param := Concurrent_Ref (Concval);
10172 Prepend_To (Params, Param);
10176 Make_Procedure_Call_Statement (Loc,
10178 Parameter_Associations => Params);
10179 end Build_Normal_Requeue;
10181 --------------------------
10182 -- Build_Skip_Statement --
10183 --------------------------
10185 function Build_Skip_Statement (Search : Node_Id) return Node_Id is
10186 Skip_Stmt : Node_Id;
10189 -- Build a return statement to skip the rest of the entire body
10191 if Is_Protected_Type (Old_Typ) then
10192 Skip_Stmt := Make_Simple_Return_Statement (Loc);
10194 -- If the requeue is within a task, find the end label of the
10195 -- enclosing accept statement and create a goto statement to it.
10203 -- Climb the parent chain looking for the enclosing accept
10206 Acc := Parent (Search);
10207 while Present (Acc)
10208 and then Nkind (Acc) /= N_Accept_Statement
10210 Acc := Parent (Acc);
10213 -- The last statement is the second label used for completing
10214 -- the rendezvous the usual way. The label we are looking for
10215 -- is right before it.
10218 Prev (Last (Statements (Handled_Statement_Sequence (Acc))));
10220 pragma Assert (Nkind (Label) = N_Label);
10222 -- Generate a goto statement to skip the rest of the accept
10225 Make_Goto_Statement (Loc,
10227 New_Occurrence_Of (Entity (Identifier (Label)), Loc));
10231 Set_Analyzed (Skip_Stmt);
10234 end Build_Skip_Statement;
10236 -- Start of processing for Expand_N_Requeue_Statement
10239 -- Extract the components of the entry call
10241 Extract_Entry (N, Concval, Ename, Index);
10242 Conc_Typ := Etype (Concval);
10244 -- If the prefix is an access to class-wide type, dereference to get
10245 -- object and entry type.
10247 if Is_Access_Type (Conc_Typ) then
10248 Conc_Typ := Designated_Type (Conc_Typ);
10250 Make_Explicit_Dereference (Loc, Relocate_Node (Concval)));
10251 Analyze_And_Resolve (Concval, Conc_Typ);
10254 -- Examine the scope stack in order to find nearest enclosing protected
10255 -- or task type. This will constitute our invocation source.
10257 Old_Typ := Current_Scope;
10258 while Present (Old_Typ)
10259 and then not Is_Protected_Type (Old_Typ)
10260 and then not Is_Task_Type (Old_Typ)
10262 Old_Typ := Scope (Old_Typ);
10265 -- Ada 2012 (AI05-0030): We have a dispatching requeue of the form
10266 -- Concval.Ename where the type of Concval is class-wide concurrent
10269 if Ada_Version >= Ada_2012
10270 and then Present (Concval)
10271 and then Is_Class_Wide_Type (Conc_Typ)
10272 and then Is_Concurrent_Interface (Conc_Typ)
10275 Has_Impl : Boolean := False;
10276 Impl_Kind : Name_Id := No_Name;
10279 -- Check whether the Ename is flagged by pragma Implemented
10281 if Has_Rep_Pragma (Entity (Ename), Name_Implemented) then
10283 Impl_Kind := Implementation_Kind (Entity (Ename));
10286 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10287 -- an entry. Create a call to predefined primitive _Disp_Requeue.
10289 if Has_Impl and then Impl_Kind = Name_By_Entry then
10290 Rewrite (N, Build_Dispatching_Requeue);
10292 Insert_After (N, Build_Skip_Statement (N));
10294 -- The procedure_or_entry_NAME is guaranteed to be overridden by
10295 -- a protected procedure. In this case the requeue is transformed
10296 -- into a dispatching call.
10299 and then Impl_Kind = Name_By_Protected_Procedure
10301 Rewrite (N, Build_Dispatching_Call_Equivalent);
10304 -- The procedure_or_entry_NAME's implementation kind is either
10305 -- By_Any, Optional, or pragma Implemented was not applied at all.
10306 -- In this case a runtime test determines whether Ename denotes an
10307 -- entry or a protected procedure and performs the appropriate
10311 Rewrite (N, Build_Dispatching_Requeue_To_Any);
10316 -- Processing for regular (non-dispatching) requeues
10319 Rewrite (N, Build_Normal_Requeue);
10321 Insert_After (N, Build_Skip_Statement (N));
10323 end Expand_N_Requeue_Statement;
10325 -------------------------------
10326 -- Expand_N_Selective_Accept --
10327 -------------------------------
10329 procedure Expand_N_Selective_Accept (N : Node_Id) is
10330 Loc : constant Source_Ptr := Sloc (N);
10331 Alts : constant List_Id := Select_Alternatives (N);
10333 -- Note: in the below declarations a lot of new lists are allocated
10334 -- unconditionally which may well not end up being used. That's not
10335 -- a good idea since it wastes space gratuitously ???
10337 Accept_Case : List_Id;
10338 Accept_List : constant List_Id := New_List;
10341 Alt_List : constant List_Id := New_List;
10342 Alt_Stats : List_Id;
10343 Ann : Entity_Id := Empty;
10345 Check_Guard : Boolean := True;
10347 Decls : constant List_Id := New_List;
10348 Stats : constant List_Id := New_List;
10349 Body_List : constant List_Id := New_List;
10350 Trailing_List : constant List_Id := New_List;
10353 Else_Present : Boolean := False;
10354 Terminate_Alt : Node_Id := Empty;
10355 Select_Mode : Node_Id;
10357 Delay_Case : List_Id;
10358 Delay_Count : Integer := 0;
10359 Delay_Val : Entity_Id;
10360 Delay_Index : Entity_Id;
10361 Delay_Min : Entity_Id;
10362 Delay_Num : Int := 1;
10363 Delay_Alt_List : List_Id := New_List;
10364 Delay_List : constant List_Id := New_List;
10368 First_Delay : Boolean := True;
10369 Guard_Open : Entity_Id;
10375 Num_Accept : Nat := 0;
10377 Time_Type : Entity_Id;
10378 Select_Call : Node_Id;
10380 Qnam : constant Entity_Id :=
10381 Make_Defining_Identifier (Loc, New_External_Name ('S', 0));
10383 Xnam : constant Entity_Id :=
10384 Make_Defining_Identifier (Loc, New_External_Name ('J', 1));
10386 -----------------------
10387 -- Local subprograms --
10388 -----------------------
10390 function Accept_Or_Raise return List_Id;
10391 -- For the rare case where delay alternatives all have guards, and
10392 -- all of them are closed, it is still possible that there were open
10393 -- accept alternatives with no callers. We must reexamine the
10394 -- Accept_List, and execute a selective wait with no else if some
10395 -- accept is open. If none, we raise program_error.
10397 procedure Add_Accept (Alt : Node_Id);
10398 -- Process a single accept statement in a select alternative. Build
10399 -- procedure for body of accept, and add entry to dispatch table with
10400 -- expression for guard, in preparation for call to run time select.
10402 function Make_And_Declare_Label (Num : Int) return Node_Id;
10403 -- Manufacture a label using Num as a serial number and declare it.
10404 -- The declaration is appended to Decls. The label marks the trailing
10405 -- statements of an accept or delay alternative.
10407 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id;
10408 -- Build call to Selective_Wait runtime routine
10410 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int);
10411 -- Add code to compare value of delay with previous values, and
10412 -- generate case entry for trailing statements.
10414 procedure Process_Accept_Alternative
10418 -- Add code to call corresponding procedure, and branch to
10419 -- trailing statements, if any.
10421 ---------------------
10422 -- Accept_Or_Raise --
10423 ---------------------
10425 function Accept_Or_Raise return List_Id is
10428 J : constant Entity_Id := Make_Temporary (Loc, 'J');
10431 -- We generate the following:
10433 -- for J in q'range loop
10434 -- if q(J).S /=null_task_entry then
10435 -- selective_wait (simple_mode,...);
10441 -- if no rendez_vous then
10442 -- raise program_error;
10445 -- Note that the code needs to know that the selector name
10446 -- in an Accept_Alternative is named S.
10448 Cond := Make_Op_Ne (Loc,
10450 Make_Selected_Component (Loc,
10452 Make_Indexed_Component (Loc,
10453 Prefix => New_Occurrence_Of (Qnam, Loc),
10454 Expressions => New_List (New_Occurrence_Of (J, Loc))),
10455 Selector_Name => Make_Identifier (Loc, Name_S)),
10457 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Loc));
10459 Stats := New_List (
10460 Make_Implicit_Loop_Statement (N,
10461 Iteration_Scheme =>
10462 Make_Iteration_Scheme (Loc,
10463 Loop_Parameter_Specification =>
10464 Make_Loop_Parameter_Specification (Loc,
10465 Defining_Identifier => J,
10466 Discrete_Subtype_Definition =>
10467 Make_Attribute_Reference (Loc,
10468 Prefix => New_Occurrence_Of (Qnam, Loc),
10469 Attribute_Name => Name_Range,
10470 Expressions => New_List (
10471 Make_Integer_Literal (Loc, 1))))),
10473 Statements => New_List (
10474 Make_Implicit_If_Statement (N,
10476 Then_Statements => New_List (
10478 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)),
10479 Make_Exit_Statement (Loc))))));
10482 Make_Raise_Program_Error (Loc,
10483 Condition => Make_Op_Eq (Loc,
10484 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
10486 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
10487 Reason => PE_All_Guards_Closed));
10490 end Accept_Or_Raise;
10496 procedure Add_Accept (Alt : Node_Id) is
10497 Acc_Stm : constant Node_Id := Accept_Statement (Alt);
10498 Ename : constant Node_Id := Entry_Direct_Name (Acc_Stm);
10499 Eloc : constant Source_Ptr := Sloc (Ename);
10500 Eent : constant Entity_Id := Entity (Ename);
10501 Index : constant Node_Id := Entry_Index (Acc_Stm);
10502 Null_Body : Node_Id;
10503 Proc_Body : Node_Id;
10504 PB_Ent : Entity_Id;
10510 Ann := Node (Last_Elmt (Accept_Address (Eent)));
10513 if Present (Condition (Alt)) then
10515 Make_If_Expression (Eloc, New_List (
10517 Entry_Index_Expression (Eloc, Eent, Index, Scope (Eent)),
10518 New_Occurrence_Of (RTE (RE_Null_Task_Entry), Eloc)));
10521 Entry_Index_Expression
10522 (Eloc, Eent, Index, Scope (Eent));
10525 if Present (Handled_Statement_Sequence (Accept_Statement (Alt))) then
10526 Null_Body := New_Occurrence_Of (Standard_False, Eloc);
10528 -- Always add call to Abort_Undefer when generating code, since
10529 -- this is what the runtime expects (abort deferred in
10530 -- Selective_Wait). In CodePeer mode this only confuses the
10531 -- analysis with unknown calls, so don't do it.
10533 if not CodePeer_Mode then
10535 Make_Procedure_Call_Statement (Eloc,
10536 Name => New_Occurrence_Of (RTE (RE_Abort_Undefer), Eloc));
10538 (First (Statements (Handled_Statement_Sequence
10539 (Accept_Statement (Alt)))),
10545 Make_Defining_Identifier (Eloc,
10546 New_External_Name (Chars (Ename), 'A', Num_Accept));
10548 if Comes_From_Source (Alt) then
10549 Set_Debug_Info_Needed (PB_Ent);
10553 Make_Subprogram_Body (Eloc,
10555 Make_Procedure_Specification (Eloc,
10556 Defining_Unit_Name => PB_Ent),
10557 Declarations => Declarations (Acc_Stm),
10558 Handled_Statement_Sequence =>
10559 Build_Accept_Body (Accept_Statement (Alt)));
10561 -- During the analysis of the body of the accept statement, any
10562 -- zero cost exception handler records were collected in the
10563 -- Accept_Handler_Records field of the N_Accept_Alternative node.
10564 -- This is where we move them to where they belong, namely the
10565 -- newly created procedure.
10567 Set_Handler_Records (PB_Ent, Accept_Handler_Records (Alt));
10568 Append (Proc_Body, Body_List);
10571 Null_Body := New_Occurrence_Of (Standard_True, Eloc);
10573 -- if accept statement has declarations, insert above, given that
10574 -- we are not creating a body for the accept.
10576 if Present (Declarations (Acc_Stm)) then
10577 Insert_Actions (N, Declarations (Acc_Stm));
10581 Append_To (Accept_List,
10582 Make_Aggregate (Eloc, Expressions => New_List (Null_Body, Expr)));
10584 Num_Accept := Num_Accept + 1;
10587 ----------------------------
10588 -- Make_And_Declare_Label --
10589 ----------------------------
10591 function Make_And_Declare_Label (Num : Int) return Node_Id is
10595 Lab_Id := Make_Identifier (Loc, New_External_Name ('L', Num));
10597 Make_Label (Loc, Lab_Id);
10600 Make_Implicit_Label_Declaration (Loc,
10601 Defining_Identifier =>
10602 Make_Defining_Identifier (Loc, Chars (Lab_Id)),
10603 Label_Construct => Lab));
10606 end Make_And_Declare_Label;
10608 ----------------------
10609 -- Make_Select_Call --
10610 ----------------------
10612 function Make_Select_Call (Select_Mode : Entity_Id) return Node_Id is
10613 Params : constant List_Id := New_List;
10617 Make_Attribute_Reference (Loc,
10618 Prefix => New_Occurrence_Of (Qnam, Loc),
10619 Attribute_Name => Name_Unchecked_Access));
10620 Append_To (Params, Select_Mode);
10621 Append_To (Params, New_Occurrence_Of (Ann, Loc));
10622 Append_To (Params, New_Occurrence_Of (Xnam, Loc));
10625 Make_Procedure_Call_Statement (Loc,
10626 Name => New_Occurrence_Of (RTE (RE_Selective_Wait), Loc),
10627 Parameter_Associations => Params);
10628 end Make_Select_Call;
10630 --------------------------------
10631 -- Process_Accept_Alternative --
10632 --------------------------------
10634 procedure Process_Accept_Alternative
10639 Astmt : constant Node_Id := Accept_Statement (Alt);
10640 Alt_Stats : List_Id;
10643 Adjust_Condition (Condition (Alt));
10645 -- Accept with body
10647 if Present (Handled_Statement_Sequence (Astmt)) then
10650 Make_Procedure_Call_Statement (Sloc (Proc),
10653 (Defining_Unit_Name (Specification (Proc)),
10656 -- Accept with no body (followed by trailing statements)
10659 Alt_Stats := Empty_List;
10662 Ensure_Statement_Present (Sloc (Astmt), Alt);
10664 -- After the call, if any, branch to trailing statements, if any.
10665 -- We create a label for each, as well as the corresponding label
10668 if not Is_Empty_List (Statements (Alt)) then
10669 Lab := Make_And_Declare_Label (Index);
10670 Append (Lab, Trailing_List);
10671 Append_List (Statements (Alt), Trailing_List);
10672 Append_To (Trailing_List,
10673 Make_Goto_Statement (Loc,
10674 Name => New_Copy (Identifier (End_Lab))));
10680 Append_To (Alt_Stats,
10681 Make_Goto_Statement (Loc, Name => New_Copy (Identifier (Lab))));
10683 Append_To (Alt_List,
10684 Make_Case_Statement_Alternative (Loc,
10685 Discrete_Choices => New_List (Make_Integer_Literal (Loc, Index)),
10686 Statements => Alt_Stats));
10687 end Process_Accept_Alternative;
10689 -------------------------------
10690 -- Process_Delay_Alternative --
10691 -------------------------------
10693 procedure Process_Delay_Alternative (Alt : Node_Id; Index : Int) is
10694 Dloc : constant Source_Ptr := Sloc (Delay_Statement (Alt));
10696 Delay_Alt : List_Id;
10699 -- Deal with C/Fortran boolean as delay condition
10701 Adjust_Condition (Condition (Alt));
10703 -- Determine the smallest specified delay
10705 -- for each delay alternative generate:
10707 -- if guard-expression then
10708 -- Delay_Val := delay-expression;
10709 -- Guard_Open := True;
10710 -- if Delay_Val < Delay_Min then
10711 -- Delay_Min := Delay_Val;
10712 -- Delay_Index := Index;
10716 -- The enclosing if-statement is omitted if there is no guard
10718 if Delay_Count = 1 or else First_Delay then
10719 First_Delay := False;
10721 Delay_Alt := New_List (
10722 Make_Assignment_Statement (Loc,
10723 Name => New_Occurrence_Of (Delay_Min, Loc),
10724 Expression => Expression (Delay_Statement (Alt))));
10726 if Delay_Count > 1 then
10727 Append_To (Delay_Alt,
10728 Make_Assignment_Statement (Loc,
10729 Name => New_Occurrence_Of (Delay_Index, Loc),
10730 Expression => Make_Integer_Literal (Loc, Index)));
10734 Delay_Alt := New_List (
10735 Make_Assignment_Statement (Loc,
10736 Name => New_Occurrence_Of (Delay_Val, Loc),
10737 Expression => Expression (Delay_Statement (Alt))));
10739 if Time_Type = Standard_Duration then
10742 Left_Opnd => New_Occurrence_Of (Delay_Val, Loc),
10743 Right_Opnd => New_Occurrence_Of (Delay_Min, Loc));
10746 -- The scope of the time type must define a comparison
10747 -- operator. The scope itself may not be visible, so we
10748 -- construct a node with entity information to insure that
10749 -- semantic analysis can find the proper operator.
10752 Make_Function_Call (Loc,
10753 Name => Make_Selected_Component (Loc,
10755 New_Occurrence_Of (Scope (Time_Type), Loc),
10757 Make_Operator_Symbol (Loc,
10758 Chars => Name_Op_Lt,
10759 Strval => No_String)),
10760 Parameter_Associations =>
10762 New_Occurrence_Of (Delay_Val, Loc),
10763 New_Occurrence_Of (Delay_Min, Loc)));
10765 Set_Entity (Prefix (Name (Cond)), Scope (Time_Type));
10768 Append_To (Delay_Alt,
10769 Make_Implicit_If_Statement (N,
10771 Then_Statements => New_List (
10772 Make_Assignment_Statement (Loc,
10773 Name => New_Occurrence_Of (Delay_Min, Loc),
10774 Expression => New_Occurrence_Of (Delay_Val, Loc)),
10776 Make_Assignment_Statement (Loc,
10777 Name => New_Occurrence_Of (Delay_Index, Loc),
10778 Expression => Make_Integer_Literal (Loc, Index)))));
10781 if Check_Guard then
10782 Append_To (Delay_Alt,
10783 Make_Assignment_Statement (Loc,
10784 Name => New_Occurrence_Of (Guard_Open, Loc),
10785 Expression => New_Occurrence_Of (Standard_True, Loc)));
10788 if Present (Condition (Alt)) then
10789 Delay_Alt := New_List (
10790 Make_Implicit_If_Statement (N,
10791 Condition => Condition (Alt),
10792 Then_Statements => Delay_Alt));
10795 Append_List (Delay_Alt, Delay_List);
10797 Ensure_Statement_Present (Dloc, Alt);
10799 -- If the delay alternative has a statement part, add choice to the
10800 -- case statements for delays.
10802 if not Is_Empty_List (Statements (Alt)) then
10804 if Delay_Count = 1 then
10805 Append_List (Statements (Alt), Delay_Alt_List);
10808 Append_To (Delay_Alt_List,
10809 Make_Case_Statement_Alternative (Loc,
10810 Discrete_Choices => New_List (
10811 Make_Integer_Literal (Loc, Index)),
10812 Statements => Statements (Alt)));
10815 elsif Delay_Count = 1 then
10817 -- If the single delay has no trailing statements, add a branch
10818 -- to the exit label to the selective wait.
10820 Delay_Alt_List := New_List (
10821 Make_Goto_Statement (Loc,
10822 Name => New_Copy (Identifier (End_Lab))));
10825 end Process_Delay_Alternative;
10827 -- Start of processing for Expand_N_Selective_Accept
10830 Process_Statements_For_Controlled_Objects (N);
10832 -- First insert some declarations before the select. The first is:
10836 -- This variable holds the parameters passed to the accept body. This
10837 -- declaration has already been inserted by the time we get here by
10838 -- a call to Expand_Accept_Declarations made from the semantics when
10839 -- processing the first accept statement contained in the select. We
10840 -- can find this entity as Accept_Address (E), where E is any of the
10841 -- entries references by contained accept statements.
10843 -- The first step is to scan the list of Selective_Accept_Statements
10844 -- to find this entity, and also count the number of accepts, and
10845 -- determine if terminated, delay or else is present:
10849 Alt := First (Alts);
10850 while Present (Alt) loop
10851 Process_Statements_For_Controlled_Objects (Alt);
10853 if Nkind (Alt) = N_Accept_Alternative then
10856 elsif Nkind (Alt) = N_Delay_Alternative then
10857 Delay_Count := Delay_Count + 1;
10859 -- If the delays are relative delays, the delay expressions have
10860 -- type Standard_Duration. Otherwise they must have some time type
10861 -- recognized by GNAT.
10863 if Nkind (Delay_Statement (Alt)) = N_Delay_Relative_Statement then
10864 Time_Type := Standard_Duration;
10866 Time_Type := Etype (Expression (Delay_Statement (Alt)));
10868 if Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time)
10869 or else Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time)
10874 "& is not a time type (RM 9.6(6))",
10875 Expression (Delay_Statement (Alt)), Time_Type);
10876 Time_Type := Standard_Duration;
10877 Set_Etype (Expression (Delay_Statement (Alt)), Any_Type);
10881 if No (Condition (Alt)) then
10883 -- This guard will always be open
10885 Check_Guard := False;
10888 elsif Nkind (Alt) = N_Terminate_Alternative then
10889 Adjust_Condition (Condition (Alt));
10890 Terminate_Alt := Alt;
10893 Num_Alts := Num_Alts + 1;
10897 Else_Present := Present (Else_Statements (N));
10899 -- At the same time (see procedure Add_Accept) we build the accept list:
10901 -- Qnn : Accept_List (1 .. num-select) := (
10902 -- (null-body, entry-index),
10903 -- (null-body, entry-index),
10905 -- (null_body, entry-index));
10907 -- In the above declaration, null-body is True if the corresponding
10908 -- accept has no body, and false otherwise. The entry is either the
10909 -- entry index expression if there is no guard, or if a guard is
10910 -- present, then an if expression of the form:
10912 -- (if guard then entry-index else Null_Task_Entry)
10914 -- If a guard is statically known to be false, the entry can simply
10915 -- be omitted from the accept list.
10918 Make_Object_Declaration (Loc,
10919 Defining_Identifier => Qnam,
10920 Object_Definition => New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10921 Aliased_Present => True,
10923 Make_Qualified_Expression (Loc,
10925 New_Occurrence_Of (RTE (RE_Accept_List), Loc),
10927 Make_Aggregate (Loc, Expressions => Accept_List))));
10929 -- Then we declare the variable that holds the index for the accept
10930 -- that will be selected for service:
10932 -- Xnn : Select_Index;
10935 Make_Object_Declaration (Loc,
10936 Defining_Identifier => Xnam,
10937 Object_Definition =>
10938 New_Occurrence_Of (RTE (RE_Select_Index), Loc),
10940 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)));
10942 -- After this follow procedure declarations for each accept body
10944 -- procedure Pnn is
10949 -- where the ... are statements from the corresponding procedure body.
10950 -- No parameters are involved, since the parameters are passed via Ann
10951 -- and the parameter references have already been expanded to be direct
10952 -- references to Ann (see Exp_Ch2.Expand_Entry_Parameter). Furthermore,
10953 -- any embedded tasking statements (which would normally be illegal in
10954 -- procedures), have been converted to calls to the tasking runtime so
10955 -- there is no problem in putting them into procedures.
10957 -- The original accept statement has been expanded into a block in
10958 -- the same fashion as for simple accepts (see Build_Accept_Body).
10960 -- Note: we don't really need to build these procedures for the case
10961 -- where no delay statement is present, but it is just as easy to
10962 -- build them unconditionally, and not significantly inefficient,
10963 -- since if they are short they will be inlined anyway.
10965 -- The procedure declarations have been assembled in Body_List
10967 -- If delays are present, we must compute the required delay.
10968 -- We first generate the declarations:
10970 -- Delay_Index : Boolean := 0;
10971 -- Delay_Min : Some_Time_Type.Time;
10972 -- Delay_Val : Some_Time_Type.Time;
10974 -- Delay_Index will be set to the index of the minimum delay, i.e. the
10975 -- active delay that is actually chosen as the basis for the possible
10976 -- delay if an immediate rendez-vous is not possible.
10978 -- In the most common case there is a single delay statement, and this
10979 -- is handled specially.
10981 if Delay_Count > 0 then
10983 -- Generate the required declarations
10986 Make_Defining_Identifier (Loc, New_External_Name ('D', 1));
10988 Make_Defining_Identifier (Loc, New_External_Name ('D', 2));
10990 Make_Defining_Identifier (Loc, New_External_Name ('D', 3));
10993 Make_Object_Declaration (Loc,
10994 Defining_Identifier => Delay_Val,
10995 Object_Definition => New_Occurrence_Of (Time_Type, Loc)));
10998 Make_Object_Declaration (Loc,
10999 Defining_Identifier => Delay_Index,
11000 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
11001 Expression => Make_Integer_Literal (Loc, 0)));
11004 Make_Object_Declaration (Loc,
11005 Defining_Identifier => Delay_Min,
11006 Object_Definition => New_Occurrence_Of (Time_Type, Loc),
11008 Unchecked_Convert_To (Time_Type,
11009 Make_Attribute_Reference (Loc,
11011 New_Occurrence_Of (Underlying_Type (Time_Type), Loc),
11012 Attribute_Name => Name_Last))));
11014 -- Create Duration and Delay_Mode objects used for passing a delay
11017 D := Make_Temporary (Loc, 'D');
11018 M := Make_Temporary (Loc, 'M');
11024 -- Note that these values are defined in s-osprim.ads and must
11025 -- be kept in sync:
11027 -- Relative : constant := 0;
11028 -- Absolute_Calendar : constant := 1;
11029 -- Absolute_RT : constant := 2;
11031 if Time_Type = Standard_Duration then
11032 Discr := Make_Integer_Literal (Loc, 0);
11034 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11035 Discr := Make_Integer_Literal (Loc, 1);
11039 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11040 Discr := Make_Integer_Literal (Loc, 2);
11044 Make_Object_Declaration (Loc,
11045 Defining_Identifier => D,
11046 Object_Definition =>
11047 New_Occurrence_Of (Standard_Duration, Loc)));
11050 Make_Object_Declaration (Loc,
11051 Defining_Identifier => M,
11052 Object_Definition =>
11053 New_Occurrence_Of (Standard_Integer, Loc),
11054 Expression => Discr));
11057 if Check_Guard then
11059 Make_Defining_Identifier (Loc, New_External_Name ('G', 1));
11062 Make_Object_Declaration (Loc,
11063 Defining_Identifier => Guard_Open,
11064 Object_Definition =>
11065 New_Occurrence_Of (Standard_Boolean, Loc),
11067 New_Occurrence_Of (Standard_False, Loc)));
11070 -- Delay_Count is zero, don't need M and D set (suppress warning)
11077 if Present (Terminate_Alt) then
11079 -- If the terminate alternative guard is False, use
11080 -- Simple_Mode; otherwise use Terminate_Mode.
11082 if Present (Condition (Terminate_Alt)) then
11083 Select_Mode := Make_If_Expression (Loc,
11084 New_List (Condition (Terminate_Alt),
11085 New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc),
11086 New_Occurrence_Of (RTE (RE_Simple_Mode), Loc)));
11088 Select_Mode := New_Occurrence_Of (RTE (RE_Terminate_Mode), Loc);
11091 elsif Else_Present or Delay_Count > 0 then
11092 Select_Mode := New_Occurrence_Of (RTE (RE_Else_Mode), Loc);
11095 Select_Mode := New_Occurrence_Of (RTE (RE_Simple_Mode), Loc);
11098 Select_Call := Make_Select_Call (Select_Mode);
11099 Append (Select_Call, Stats);
11101 -- Now generate code to act on the result. There is an entry
11102 -- in this case for each accept statement with a non-null body,
11103 -- followed by a branch to the statements that follow the Accept.
11104 -- In the absence of delay alternatives, we generate:
11107 -- when No_Rendezvous => -- omitted if simple mode
11122 -- Lab0: Else_Statements;
11125 -- Lab1: Trailing_Statements1;
11128 -- Lab2: Trailing_Statements2;
11133 -- Generate label for common exit
11135 End_Lab := Make_And_Declare_Label (Num_Alts + 1);
11137 -- First entry is the default case, when no rendezvous is possible
11139 Choices := New_List (New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc));
11141 if Else_Present then
11143 -- If no rendezvous is possible, the else part is executed
11145 Lab := Make_And_Declare_Label (0);
11146 Alt_Stats := New_List (
11147 Make_Goto_Statement (Loc,
11148 Name => New_Copy (Identifier (Lab))));
11150 Append (Lab, Trailing_List);
11151 Append_List (Else_Statements (N), Trailing_List);
11152 Append_To (Trailing_List,
11153 Make_Goto_Statement (Loc,
11154 Name => New_Copy (Identifier (End_Lab))));
11156 Alt_Stats := New_List (
11157 Make_Goto_Statement (Loc,
11158 Name => New_Copy (Identifier (End_Lab))));
11161 Append_To (Alt_List,
11162 Make_Case_Statement_Alternative (Loc,
11163 Discrete_Choices => Choices,
11164 Statements => Alt_Stats));
11166 -- We make use of the fact that Accept_Index is an integer type, and
11167 -- generate successive literals for entries for each accept. Only those
11168 -- for which there is a body or trailing statements get a case entry.
11170 Alt := First (Select_Alternatives (N));
11171 Proc := First (Body_List);
11172 while Present (Alt) loop
11174 if Nkind (Alt) = N_Accept_Alternative then
11175 Process_Accept_Alternative (Alt, Index, Proc);
11176 Index := Index + 1;
11179 (Handled_Statement_Sequence (Accept_Statement (Alt)))
11184 elsif Nkind (Alt) = N_Delay_Alternative then
11185 Process_Delay_Alternative (Alt, Delay_Num);
11186 Delay_Num := Delay_Num + 1;
11192 -- An others choice is always added to the main case, as well
11193 -- as the delay case (to satisfy the compiler).
11195 Append_To (Alt_List,
11196 Make_Case_Statement_Alternative (Loc,
11197 Discrete_Choices =>
11198 New_List (Make_Others_Choice (Loc)),
11200 New_List (Make_Goto_Statement (Loc,
11201 Name => New_Copy (Identifier (End_Lab))))));
11203 Accept_Case := New_List (
11204 Make_Case_Statement (Loc,
11205 Expression => New_Occurrence_Of (Xnam, Loc),
11206 Alternatives => Alt_List));
11208 Append_List (Trailing_List, Accept_Case);
11209 Append_List (Body_List, Decls);
11211 -- Construct case statement for trailing statements of delay
11212 -- alternatives, if there are several of them.
11214 if Delay_Count > 1 then
11215 Append_To (Delay_Alt_List,
11216 Make_Case_Statement_Alternative (Loc,
11217 Discrete_Choices =>
11218 New_List (Make_Others_Choice (Loc)),
11220 New_List (Make_Null_Statement (Loc))));
11222 Delay_Case := New_List (
11223 Make_Case_Statement (Loc,
11224 Expression => New_Occurrence_Of (Delay_Index, Loc),
11225 Alternatives => Delay_Alt_List));
11227 Delay_Case := Delay_Alt_List;
11230 -- If there are no delay alternatives, we append the case statement
11231 -- to the statement list.
11233 if Delay_Count = 0 then
11234 Append_List (Accept_Case, Stats);
11236 -- Delay alternatives present
11239 -- If delay alternatives are present we generate:
11241 -- find minimum delay.
11242 -- DX := minimum delay;
11243 -- M := <delay mode>;
11244 -- Timed_Selective_Wait (Q'Unchecked_Access, Delay_Mode, P,
11247 -- if X = No_Rendezvous then
11248 -- case statement for delay statements.
11250 -- case statement for accept alternatives.
11261 -- The type of the delay expression is known to be legal
11263 if Time_Type = Standard_Duration then
11264 Conv := New_Occurrence_Of (Delay_Min, Loc);
11266 elsif Is_RTE (Base_Type (Etype (Time_Type)), RO_CA_Time) then
11267 Conv := Make_Function_Call (Loc,
11268 New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
11269 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11273 (Is_RTE (Base_Type (Etype (Time_Type)), RO_RT_Time));
11275 Conv := Make_Function_Call (Loc,
11276 New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
11277 New_List (New_Occurrence_Of (Delay_Min, Loc)));
11280 Stmt := Make_Assignment_Statement (Loc,
11281 Name => New_Occurrence_Of (D, Loc),
11282 Expression => Conv);
11284 -- Change the value for Accept_Modes. (Else_Mode -> Delay_Mode)
11286 Parms := Parameter_Associations (Select_Call);
11288 Parm := First (Parms);
11289 while Present (Parm) and then Parm /= Select_Mode loop
11293 pragma Assert (Present (Parm));
11294 Rewrite (Parm, New_Occurrence_Of (RTE (RE_Delay_Mode), Loc));
11297 -- Prepare two new parameters of Duration and Delay_Mode type
11298 -- which represent the value and the mode of the minimum delay.
11301 Insert_After (Parm, New_Occurrence_Of (M, Loc));
11302 Insert_After (Parm, New_Occurrence_Of (D, Loc));
11304 -- Create a call to RTS
11306 Rewrite (Select_Call,
11307 Make_Procedure_Call_Statement (Loc,
11308 Name => New_Occurrence_Of (RTE (RE_Timed_Selective_Wait), Loc),
11309 Parameter_Associations => Parms));
11311 -- This new call should follow the calculation of the minimum
11314 Insert_List_Before (Select_Call, Delay_List);
11316 if Check_Guard then
11318 Make_Implicit_If_Statement (N,
11319 Condition => New_Occurrence_Of (Guard_Open, Loc),
11320 Then_Statements => New_List (
11321 New_Copy_Tree (Stmt),
11322 New_Copy_Tree (Select_Call)),
11323 Else_Statements => Accept_Or_Raise);
11324 Rewrite (Select_Call, Stmt);
11326 Insert_Before (Select_Call, Stmt);
11330 Make_Implicit_If_Statement (N,
11331 Condition => Make_Op_Eq (Loc,
11332 Left_Opnd => New_Occurrence_Of (Xnam, Loc),
11334 New_Occurrence_Of (RTE (RE_No_Rendezvous), Loc)),
11336 Then_Statements => Delay_Case,
11337 Else_Statements => Accept_Case);
11339 Append (Cases, Stats);
11343 Append (End_Lab, Stats);
11345 -- Replace accept statement with appropriate block
11348 Make_Block_Statement (Loc,
11349 Declarations => Decls,
11350 Handled_Statement_Sequence =>
11351 Make_Handled_Sequence_Of_Statements (Loc, Statements => Stats)));
11354 -- Note: have to worry more about abort deferral in above code ???
11356 -- Final step is to unstack the Accept_Address entries for all accept
11357 -- statements appearing in accept alternatives in the select statement
11359 Alt := First (Alts);
11360 while Present (Alt) loop
11361 if Nkind (Alt) = N_Accept_Alternative then
11362 Remove_Last_Elmt (Accept_Address
11363 (Entity (Entry_Direct_Name (Accept_Statement (Alt)))));
11368 end Expand_N_Selective_Accept;
11370 --------------------------------------
11371 -- Expand_N_Single_Task_Declaration --
11372 --------------------------------------
11374 -- Single task declarations should never be present after semantic
11375 -- analysis, since we expect them to be replaced by a declaration of an
11376 -- anonymous task type, followed by a declaration of the task object. We
11377 -- include this routine to make sure that is happening.
11379 procedure Expand_N_Single_Task_Declaration (N : Node_Id) is
11381 raise Program_Error;
11382 end Expand_N_Single_Task_Declaration;
11384 ------------------------
11385 -- Expand_N_Task_Body --
11386 ------------------------
11388 -- Given a task body
11390 -- task body tname is
11396 -- This expansion routine converts it into a procedure and sets the
11397 -- elaboration flag for the procedure to true, to represent the fact
11398 -- that the task body is now elaborated:
11400 -- procedure tnameB (_Task : access tnameV) is
11401 -- discriminal : dtype renames _Task.discriminant;
11403 -- procedure _clean is
11405 -- Abort_Defer.all;
11407 -- Abort_Undefer.all;
11412 -- Abort_Undefer.all;
11414 -- System.Task_Stages.Complete_Activation;
11422 -- In addition, if the task body is an activator, then a call to activate
11423 -- tasks is added at the start of the statements, before the call to
11424 -- Complete_Activation, and if in addition the task is a master then it
11425 -- must be established as a master. These calls are inserted and analyzed
11426 -- in Expand_Cleanup_Actions, when the Handled_Sequence_Of_Statements is
11429 -- There is one discriminal declaration line generated for each
11430 -- discriminant that is present to provide an easy reference point for
11431 -- discriminant references inside the body (see Exp_Ch2.Expand_Name).
11433 -- Note on relationship to GNARLI definition. In the GNARLI definition,
11434 -- task body procedures have a profile (Arg : System.Address). That is
11435 -- needed because GNARLI has to use the same access-to-subprogram type
11436 -- for all task types. We depend here on knowing that in GNAT, passing
11437 -- an address argument by value is identical to passing a record value
11438 -- by access (in either case a single pointer is passed), so even though
11439 -- this procedure has the wrong profile. In fact it's all OK, since the
11440 -- callings sequence is identical.
11442 procedure Expand_N_Task_Body (N : Node_Id) is
11443 Loc : constant Source_Ptr := Sloc (N);
11444 Ttyp : constant Entity_Id := Corresponding_Spec (N);
11448 Insert_Nod : Node_Id;
11449 -- Used to determine the proper location of wrapper body insertions
11452 -- if no task body procedure, means we had an error in configurable
11453 -- run-time mode, and there is no point in proceeding further.
11455 if No (Task_Body_Procedure (Ttyp)) then
11459 -- Add renaming declarations for discriminals and a declaration for the
11460 -- entry family index (if applicable).
11462 Install_Private_Data_Declarations
11463 (Loc, Task_Body_Procedure (Ttyp), Ttyp, N, Declarations (N));
11465 -- Add a call to Abort_Undefer at the very beginning of the task
11466 -- body since this body is called with abort still deferred.
11468 if Abort_Allowed then
11469 Call := Build_Runtime_Call (Loc, RE_Abort_Undefer);
11471 (First (Statements (Handled_Statement_Sequence (N))), Call);
11475 -- The statement part has already been protected with an at_end and
11476 -- cleanup actions. The call to Complete_Activation must be placed
11477 -- at the head of the sequence of statements of that block. The
11478 -- declarations have been merged in this sequence of statements but
11479 -- the first real statement is accessible from the First_Real_Statement
11480 -- field (which was set for exactly this purpose).
11482 if Restricted_Profile then
11483 Call := Build_Runtime_Call (Loc, RE_Complete_Restricted_Activation);
11485 Call := Build_Runtime_Call (Loc, RE_Complete_Activation);
11489 (First_Real_Statement (Handled_Statement_Sequence (N)), Call);
11493 Make_Subprogram_Body (Loc,
11494 Specification => Build_Task_Proc_Specification (Ttyp),
11495 Declarations => Declarations (N),
11496 Handled_Statement_Sequence => Handled_Statement_Sequence (N));
11498 -- If the task contains generic instantiations, cleanup actions are
11499 -- delayed until after instantiation. Transfer the activation chain to
11500 -- the subprogram, to insure that the activation call is properly
11501 -- generated. It the task body contains inner tasks, indicate that the
11502 -- subprogram is a task master.
11504 if Delay_Cleanups (Ttyp) then
11505 Set_Activation_Chain_Entity (New_N, Activation_Chain_Entity (N));
11506 Set_Is_Task_Master (New_N, Is_Task_Master (N));
11509 Rewrite (N, New_N);
11512 -- Set elaboration flag immediately after task body. If the body is a
11513 -- subunit, the flag is set in the declarative part containing the stub.
11515 if Nkind (Parent (N)) /= N_Subunit then
11517 Make_Assignment_Statement (Loc,
11519 Make_Identifier (Loc, New_External_Name (Chars (Ttyp), 'E')),
11520 Expression => New_Occurrence_Of (Standard_True, Loc)));
11523 -- Ada 2005 (AI-345): Construct the primitive entry wrapper bodies after
11524 -- the task body. At this point all wrapper specs have been created,
11525 -- frozen and included in the dispatch table for the task type.
11527 if Ada_Version >= Ada_2005 then
11528 if Nkind (Parent (N)) = N_Subunit then
11529 Insert_Nod := Corresponding_Stub (Parent (N));
11534 Build_Wrapper_Bodies (Loc, Ttyp, Insert_Nod);
11536 end Expand_N_Task_Body;
11538 ------------------------------------
11539 -- Expand_N_Task_Type_Declaration --
11540 ------------------------------------
11542 -- We have several things to do. First we must create a Boolean flag used
11543 -- to mark if the body is elaborated yet. This variable gets set to True
11544 -- when the body of the task is elaborated (we can't rely on the normal
11545 -- ABE mechanism for the task body, since we need to pass an access to
11546 -- this elaboration boolean to the runtime routines).
11548 -- taskE : aliased Boolean := False;
11550 -- Next a variable is declared to hold the task stack size (either the
11551 -- default : Unspecified_Size, or a value that is set by a pragma
11552 -- Storage_Size). If the value of the pragma Storage_Size is static, then
11553 -- the variable is initialized with this value:
11555 -- taskZ : Size_Type := Unspecified_Size;
11557 -- taskZ : Size_Type := Size_Type (size_expression);
11559 -- Note: No variable is needed to hold the task relative deadline since
11560 -- its value would never be static because the parameter is of a private
11561 -- type (Ada.Real_Time.Time_Span).
11563 -- Next we create a corresponding record type declaration used to represent
11564 -- values of this task. The general form of this type declaration is
11566 -- type taskV (discriminants) is record
11567 -- _Task_Id : Task_Id;
11568 -- entry_family : array (bounds) of Void;
11569 -- _Priority : Integer := priority_expression;
11570 -- _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 _Priority field is present only if the task entity has a Priority or
11599 -- Interrupt_Priority rep item (pragma, aspect specification or attribute
11600 -- definition clause). It will be filled at the freeze point, when the
11601 -- record init proc is built, to capture the expression of the rep item
11602 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11603 -- here since aspect evaluations are delayed till the freeze point.
11605 -- The _Task_Info field is present only if a Task_Info pragma appears in
11606 -- the task definition. The expression captures the argument that was
11607 -- present in the pragma, and is used to provide the Task_Image parameter
11608 -- to the call to Create_Task.
11610 -- The _CPU field is present only if the task entity has a CPU rep item
11611 -- (pragma, aspect specification or attribute definition clause). It will
11612 -- be filled at the freeze point, when the record init proc is built, to
11613 -- capture the expression of the rep item (see Build_Record_Init_Proc in
11614 -- Exp_Ch3). Note that it cannot be filled here since aspect evaluations
11615 -- are delayed till the freeze point.
11617 -- The _Relative_Deadline field is present only if a Relative_Deadline
11618 -- pragma appears in the task definition. The expression captures the
11619 -- argument that was present in the pragma, and is used to provide the
11620 -- Relative_Deadline parameter to the call to Create_Task.
11622 -- The _Domain field is present only if the task entity has a
11623 -- Dispatching_Domain rep item (pragma, aspect specification or attribute
11624 -- definition clause). It will be filled at the freeze point, when the
11625 -- record init proc is built, to capture the expression of the rep item
11626 -- (see Build_Record_Init_Proc in Exp_Ch3). Note that it cannot be filled
11627 -- here since aspect evaluations are delayed till the freeze point.
11629 -- When a task is declared, an instance of the task value record is
11630 -- created. The elaboration of this declaration creates the correct bounds
11631 -- for the entry families, and also evaluates the size, priority, and
11632 -- task_Info expressions if needed. The initialization routine for the task
11633 -- type itself then calls Create_Task with appropriate parameters to
11634 -- initialize the value of the Task_Id field.
11636 -- Note: the address of this record is passed as the "Discriminants"
11637 -- parameter for Create_Task. Since Create_Task merely passes this onto the
11638 -- body procedure, it does not matter that it does not quite match the
11639 -- GNARLI model of what is being passed (the record contains more than just
11640 -- the discriminants, but the discriminants can be found from the record
11643 -- The Entity_Id for this created record type is placed in the
11644 -- Corresponding_Record_Type field of the associated task type entity.
11646 -- Next we create a procedure specification for the task body procedure:
11648 -- procedure taskB (_Task : access taskV);
11650 -- Note that this must come after the record type declaration, since
11651 -- the spec refers to this type. It turns out that the initialization
11652 -- procedure for the value type references the task body spec, but that's
11653 -- fine, since it won't be generated till the freeze point for the type,
11654 -- which is certainly after the task body spec declaration.
11656 -- Finally, we set the task index value field of the entry attribute in
11657 -- the case of a simple entry.
11659 procedure Expand_N_Task_Type_Declaration (N : Node_Id) is
11660 Loc : constant Source_Ptr := Sloc (N);
11661 TaskId : constant Entity_Id := Defining_Identifier (N);
11662 Tasktyp : constant Entity_Id := Etype (Defining_Identifier (N));
11663 Tasknm : constant Name_Id := Chars (Tasktyp);
11664 Taskdef : constant Node_Id := Task_Definition (N);
11666 Body_Decl : Node_Id;
11668 Decl_Stack : Node_Id;
11669 Elab_Decl : Node_Id;
11670 Ent_Stack : Entity_Id;
11671 Proc_Spec : Node_Id;
11672 Rec_Decl : Node_Id;
11673 Rec_Ent : Entity_Id;
11674 Size_Decl : Entity_Id;
11675 Task_Size : Node_Id;
11677 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id;
11678 -- Searches the task definition T for the first occurrence of the pragma
11679 -- Relative Deadline. The caller has ensured that the pragma is present
11680 -- in the task definition. Note that this routine cannot be implemented
11681 -- with the Rep Item chain mechanism since Relative_Deadline pragmas are
11682 -- not chained because their expansion into a procedure call statement
11683 -- would cause a break in the chain.
11685 ----------------------------------
11686 -- Get_Relative_Deadline_Pragma --
11687 ----------------------------------
11689 function Get_Relative_Deadline_Pragma (T : Node_Id) return Node_Id is
11693 N := First (Visible_Declarations (T));
11694 while Present (N) loop
11695 if Nkind (N) = N_Pragma
11696 and then Pragma_Name (N) = Name_Relative_Deadline
11704 N := First (Private_Declarations (T));
11705 while Present (N) loop
11706 if Nkind (N) = N_Pragma
11707 and then Pragma_Name (N) = Name_Relative_Deadline
11715 raise Program_Error;
11716 end Get_Relative_Deadline_Pragma;
11718 -- Start of processing for Expand_N_Task_Type_Declaration
11721 -- If already expanded, nothing to do
11723 if Present (Corresponding_Record_Type (Tasktyp)) then
11727 -- Here we will do the expansion
11729 Rec_Decl := Build_Corresponding_Record (N, Tasktyp, Loc);
11731 Rec_Ent := Defining_Identifier (Rec_Decl);
11732 Cdecls := Component_Items (Component_List
11733 (Type_Definition (Rec_Decl)));
11735 Qualify_Entity_Names (N);
11737 -- First create the elaboration variable
11740 Make_Object_Declaration (Loc,
11741 Defining_Identifier =>
11742 Make_Defining_Identifier (Sloc (Tasktyp),
11743 Chars => New_External_Name (Tasknm, 'E')),
11744 Aliased_Present => True,
11745 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
11746 Expression => New_Occurrence_Of (Standard_False, Loc));
11748 Insert_After (N, Elab_Decl);
11750 -- Next create the declaration of the size variable (tasknmZ)
11752 Set_Storage_Size_Variable (Tasktyp,
11753 Make_Defining_Identifier (Sloc (Tasktyp),
11754 Chars => New_External_Name (Tasknm, 'Z')));
11756 if Present (Taskdef)
11757 and then Has_Storage_Size_Pragma (Taskdef)
11759 Is_OK_Static_Expression
11761 (First (Pragma_Argument_Associations
11762 (Get_Rep_Pragma (TaskId, Name_Storage_Size)))))
11765 Make_Object_Declaration (Loc,
11766 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11767 Object_Definition =>
11768 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11770 Convert_To (RTE (RE_Size_Type),
11772 (Expression (First (Pragma_Argument_Associations
11774 (TaskId, Name_Storage_Size)))))));
11778 Make_Object_Declaration (Loc,
11779 Defining_Identifier => Storage_Size_Variable (Tasktyp),
11780 Object_Definition =>
11781 New_Occurrence_Of (RTE (RE_Size_Type), Loc),
11783 New_Occurrence_Of (RTE (RE_Unspecified_Size), Loc));
11786 Insert_After (Elab_Decl, Size_Decl);
11788 -- Next build the rest of the corresponding record declaration. This is
11789 -- done last, since the corresponding record initialization procedure
11790 -- will reference the previously created entities.
11792 -- Fill in the component declarations -- first the _Task_Id field
11795 Make_Component_Declaration (Loc,
11796 Defining_Identifier =>
11797 Make_Defining_Identifier (Loc, Name_uTask_Id),
11798 Component_Definition =>
11799 Make_Component_Definition (Loc,
11800 Aliased_Present => False,
11801 Subtype_Indication => New_Occurrence_Of (RTE (RO_ST_Task_Id),
11804 -- Declare static ATCB (that is, created by the expander) if we are
11805 -- using the Restricted run time.
11807 if Restricted_Profile then
11809 Make_Component_Declaration (Loc,
11810 Defining_Identifier =>
11811 Make_Defining_Identifier (Loc, Name_uATCB),
11813 Component_Definition =>
11814 Make_Component_Definition (Loc,
11815 Aliased_Present => True,
11816 Subtype_Indication => Make_Subtype_Indication (Loc,
11818 New_Occurrence_Of (RTE (RE_Ada_Task_Control_Block), Loc),
11821 Make_Index_Or_Discriminant_Constraint (Loc,
11823 New_List (Make_Integer_Literal (Loc, 0)))))));
11827 -- Declare static stack (that is, created by the expander) if we are
11828 -- using the Restricted run time on a bare board configuration.
11830 if Restricted_Profile and then Preallocated_Stacks_On_Target then
11832 -- First we need to extract the appropriate stack size
11834 Ent_Stack := Make_Defining_Identifier (Loc, Name_uStack);
11836 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11838 Expr_N : constant Node_Id :=
11839 Expression (First (
11840 Pragma_Argument_Associations (
11841 Get_Rep_Pragma (TaskId, Name_Storage_Size))));
11842 Etyp : constant Entity_Id := Etype (Expr_N);
11843 P : constant Node_Id := Parent (Expr_N);
11846 -- The stack is defined inside the corresponding record.
11847 -- Therefore if the size of the stack is set by means of
11848 -- a discriminant, we must reference the discriminant of the
11849 -- corresponding record type.
11851 if Nkind (Expr_N) in N_Has_Entity
11852 and then Present (Discriminal_Link (Entity (Expr_N)))
11856 (CR_Discriminant (Discriminal_Link (Entity (Expr_N))),
11858 Set_Parent (Task_Size, P);
11859 Set_Etype (Task_Size, Etyp);
11860 Set_Analyzed (Task_Size);
11863 Task_Size := Relocate_Node (Expr_N);
11869 New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc);
11872 Decl_Stack := Make_Component_Declaration (Loc,
11873 Defining_Identifier => Ent_Stack,
11875 Component_Definition =>
11876 Make_Component_Definition (Loc,
11877 Aliased_Present => True,
11878 Subtype_Indication => Make_Subtype_Indication (Loc,
11880 New_Occurrence_Of (RTE (RE_Storage_Array), Loc),
11883 Make_Index_Or_Discriminant_Constraint (Loc,
11884 Constraints => New_List (Make_Range (Loc,
11885 Low_Bound => Make_Integer_Literal (Loc, 1),
11886 High_Bound => Convert_To (RTE (RE_Storage_Offset),
11889 Append_To (Cdecls, Decl_Stack);
11891 -- The appropriate alignment for the stack is ensured by the run-time
11892 -- code in charge of task creation.
11896 -- Add components for entry families
11898 Collect_Entry_Families (Loc, Cdecls, Size_Decl, Tasktyp);
11900 -- Add the _Priority component if a Interrupt_Priority or Priority rep
11901 -- item is present.
11903 if Has_Rep_Item (TaskId, Name_Priority, Check_Parents => False) then
11905 Make_Component_Declaration (Loc,
11906 Defining_Identifier =>
11907 Make_Defining_Identifier (Loc, Name_uPriority),
11908 Component_Definition =>
11909 Make_Component_Definition (Loc,
11910 Aliased_Present => False,
11911 Subtype_Indication =>
11912 New_Occurrence_Of (Standard_Integer, Loc))));
11915 -- Add the _Size component if a Storage_Size pragma is present
11917 if Present (Taskdef) and then Has_Storage_Size_Pragma (Taskdef) then
11919 Make_Component_Declaration (Loc,
11920 Defining_Identifier =>
11921 Make_Defining_Identifier (Loc, Name_uSize),
11923 Component_Definition =>
11924 Make_Component_Definition (Loc,
11925 Aliased_Present => False,
11926 Subtype_Indication =>
11927 New_Occurrence_Of (RTE (RE_Size_Type), Loc)),
11930 Convert_To (RTE (RE_Size_Type),
11932 Expression (First (
11933 Pragma_Argument_Associations (
11934 Get_Rep_Pragma (TaskId, Name_Storage_Size))))))));
11937 -- Add the _Task_Info component if a Task_Info pragma is present
11939 if Has_Rep_Pragma (TaskId, Name_Task_Info, Check_Parents => False) then
11941 Make_Component_Declaration (Loc,
11942 Defining_Identifier =>
11943 Make_Defining_Identifier (Loc, Name_uTask_Info),
11945 Component_Definition =>
11946 Make_Component_Definition (Loc,
11947 Aliased_Present => False,
11948 Subtype_Indication =>
11949 New_Occurrence_Of (RTE (RE_Task_Info_Type), Loc)),
11951 Expression => New_Copy (
11952 Expression (First (
11953 Pragma_Argument_Associations (
11955 (TaskId, Name_Task_Info, Check_Parents => False)))))));
11958 -- Add the _CPU component if a CPU rep item is present
11960 if Has_Rep_Item (TaskId, Name_CPU, Check_Parents => False) then
11962 Make_Component_Declaration (Loc,
11963 Defining_Identifier =>
11964 Make_Defining_Identifier (Loc, Name_uCPU),
11966 Component_Definition =>
11967 Make_Component_Definition (Loc,
11968 Aliased_Present => False,
11969 Subtype_Indication =>
11970 New_Occurrence_Of (RTE (RE_CPU_Range), Loc))));
11973 -- Add the _Relative_Deadline component if a Relative_Deadline pragma is
11974 -- present. If we are using a restricted run time this component will
11975 -- not be added (deadlines are not allowed by the Ravenscar profile).
11977 if not Restricted_Profile
11978 and then Present (Taskdef)
11979 and then Has_Relative_Deadline_Pragma (Taskdef)
11982 Make_Component_Declaration (Loc,
11983 Defining_Identifier =>
11984 Make_Defining_Identifier (Loc, Name_uRelative_Deadline),
11986 Component_Definition =>
11987 Make_Component_Definition (Loc,
11988 Aliased_Present => False,
11989 Subtype_Indication =>
11990 New_Occurrence_Of (RTE (RE_Time_Span), Loc)),
11993 Convert_To (RTE (RE_Time_Span),
11995 Expression (First (
11996 Pragma_Argument_Associations (
11997 Get_Relative_Deadline_Pragma (Taskdef))))))));
12000 -- Add the _Dispatching_Domain component if a Dispatching_Domain rep
12001 -- item is present. If we are using a restricted run time this component
12002 -- will not be added (dispatching domains are not allowed by the
12003 -- Ravenscar profile).
12005 if not Restricted_Profile
12008 (TaskId, Name_Dispatching_Domain, Check_Parents => False)
12011 Make_Component_Declaration (Loc,
12012 Defining_Identifier =>
12013 Make_Defining_Identifier (Loc, Name_uDispatching_Domain),
12015 Component_Definition =>
12016 Make_Component_Definition (Loc,
12017 Aliased_Present => False,
12018 Subtype_Indication =>
12020 (RTE (RE_Dispatching_Domain_Access), Loc))));
12023 Insert_After (Size_Decl, Rec_Decl);
12025 -- Analyze the record declaration immediately after construction,
12026 -- because the initialization procedure is needed for single task
12027 -- declarations before the next entity is analyzed.
12029 Analyze (Rec_Decl);
12031 -- Create the declaration of the task body procedure
12033 Proc_Spec := Build_Task_Proc_Specification (Tasktyp);
12035 Make_Subprogram_Declaration (Loc,
12036 Specification => Proc_Spec);
12038 Insert_After (Rec_Decl, Body_Decl);
12040 -- The subprogram does not comes from source, so we have to indicate the
12041 -- need for debugging information explicitly.
12043 if Comes_From_Source (Original_Node (N)) then
12044 Set_Debug_Info_Needed (Defining_Entity (Proc_Spec));
12047 -- Ada 2005 (AI-345): Construct the primitive entry wrapper specs before
12048 -- the corresponding record has been frozen.
12050 if Ada_Version >= Ada_2005 then
12051 Build_Wrapper_Specs (Loc, Tasktyp, Rec_Decl);
12054 -- Ada 2005 (AI-345): We must defer freezing to allow further
12055 -- declaration of primitive subprograms covering task interfaces
12057 if Ada_Version <= Ada_95 then
12059 -- Now we can freeze the corresponding record. This needs manually
12060 -- freezing, since it is really part of the task type, and the task
12061 -- type is frozen at this stage. We of course need the initialization
12062 -- procedure for this corresponding record type and we won't get it
12063 -- in time if we don't freeze now.
12066 L : constant List_Id := Freeze_Entity (Rec_Ent, N);
12068 if Is_Non_Empty_List (L) then
12069 Insert_List_After (Body_Decl, L);
12074 -- Complete the expansion of access types to the current task type, if
12075 -- any were declared.
12077 Expand_Previous_Access_Type (Tasktyp);
12079 -- Create wrappers for entries that have pre/postconditions
12085 Ent := First_Entity (Tasktyp);
12086 while Present (Ent) loop
12087 if Ekind_In (Ent, E_Entry, E_Entry_Family)
12088 and then Present (Contract (Ent))
12089 and then Present (Pre_Post_Conditions (Contract (Ent)))
12091 Build_PPC_Wrapper (Ent, N);
12097 end Expand_N_Task_Type_Declaration;
12099 -------------------------------
12100 -- Expand_N_Timed_Entry_Call --
12101 -------------------------------
12103 -- A timed entry call in normal case is not implemented using ATC mechanism
12104 -- anymore for efficiency reason.
12114 -- is expanded as follows:
12116 -- 1) When T.E is a task entry_call;
12120 -- X : Task_Entry_Index := <entry index>;
12121 -- DX : Duration := To_Duration (D);
12122 -- M : Delay_Mode := <discriminant>;
12123 -- P : parms := (parm, parm, parm);
12126 -- Timed_Protected_Entry_Call
12127 -- (<acceptor-task>, X, P'Address, DX, M, B);
12135 -- 2) When T.E is a protected entry_call;
12139 -- X : Protected_Entry_Index := <entry index>;
12140 -- DX : Duration := To_Duration (D);
12141 -- M : Delay_Mode := <discriminant>;
12142 -- P : parms := (parm, parm, parm);
12145 -- Timed_Protected_Entry_Call
12146 -- (<object>'unchecked_access, X, P'Address, DX, M, B);
12154 -- 3) Ada 2005 (AI-345): When T.E is a dispatching procedure call, there
12155 -- is no delay and the triggering statements are executed. We first
12156 -- determine the kind of the triggering call and then execute a
12157 -- synchronized operation or a direct call.
12160 -- B : Boolean := False;
12161 -- C : Ada.Tags.Prim_Op_Kind;
12162 -- DX : Duration := To_Duration (D)
12163 -- K : Ada.Tags.Tagged_Kind :=
12164 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag (<object>));
12165 -- M : Integer :=...;
12166 -- P : Parameters := (Param1 .. ParamN);
12170 -- if K = Ada.Tags.TK_Limited_Tagged
12171 -- or else K = Ada.Tags.TK_Tagged
12173 -- <dispatching-call>;
12178 -- Ada.Tags.Get_Offset_Index
12179 -- (Ada.Tags.Tag (<object>), DT_Position (<dispatching-call>));
12181 -- _Disp_Timed_Select (<object>, S, P'Address, DX, M, C, B);
12183 -- if C = POK_Protected_Entry
12184 -- or else C = POK_Task_Entry
12186 -- Param1 := P.Param1;
12188 -- ParamN := P.ParamN;
12192 -- if C = POK_Procedure
12193 -- or else C = POK_Protected_Procedure
12194 -- or else C = POK_Task_Procedure
12196 -- <dispatching-call>;
12202 -- <triggering-statements>
12204 -- <timed-statements>
12208 -- The triggering statement and the sequence of timed statements have not
12209 -- been analyzed yet (see Analyzed_Timed_Entry_Call), but they may contain
12210 -- global references if within an instantiation.
12212 procedure Expand_N_Timed_Entry_Call (N : Node_Id) is
12213 Loc : constant Source_Ptr := Sloc (N);
12216 Blk_Typ : Entity_Id;
12218 Call_Ent : Entity_Id;
12219 Conc_Typ_Stmts : List_Id;
12221 D_Alt : constant Node_Id := Delay_Alternative (N);
12224 D_Stat : Node_Id := Delay_Statement (D_Alt);
12226 D_Type : Entity_Id;
12229 E_Alt : constant Node_Id := Entry_Call_Alternative (N);
12230 E_Call : Node_Id := Entry_Call_Statement (E_Alt);
12235 Is_Disp_Select : Boolean;
12236 Lim_Typ_Stmts : List_Id;
12245 B : Entity_Id; -- Call status flag
12246 C : Entity_Id; -- Call kind
12247 D : Entity_Id; -- Delay
12248 K : Entity_Id; -- Tagged kind
12249 M : Entity_Id; -- Delay mode
12250 P : Entity_Id; -- Parameter block
12251 S : Entity_Id; -- Primitive operation slot
12253 -- Start of processing for Expand_N_Timed_Entry_Call
12256 -- Under the Ravenscar profile, timed entry calls are excluded. An error
12257 -- was already reported on spec, so do not attempt to expand the call.
12259 if Restriction_Active (No_Select_Statements) then
12263 Process_Statements_For_Controlled_Objects (E_Alt);
12264 Process_Statements_For_Controlled_Objects (D_Alt);
12266 Ensure_Statement_Present (Sloc (D_Stat), D_Alt);
12268 -- Retrieve E_Stats and D_Stats now because the finalization machinery
12269 -- may wrap them in blocks.
12271 E_Stats := Statements (E_Alt);
12272 D_Stats := Statements (D_Alt);
12274 -- The arguments in the call may require dynamic allocation, and the
12275 -- call statement may have been transformed into a block. The block
12276 -- may contain additional declarations for internal entities, and the
12277 -- original call is found by sequential search.
12279 if Nkind (E_Call) = N_Block_Statement then
12280 E_Call := First (Statements (Handled_Statement_Sequence (E_Call)));
12281 while not Nkind_In (E_Call, N_Procedure_Call_Statement,
12282 N_Entry_Call_Statement)
12289 Ada_Version >= Ada_2005
12290 and then Nkind (E_Call) = N_Procedure_Call_Statement;
12292 if Is_Disp_Select then
12293 Extract_Dispatching_Call (E_Call, Call_Ent, Obj, Actuals, Formals);
12299 -- B : Boolean := False;
12301 B := Build_B (Loc, Decls);
12304 -- C : Ada.Tags.Prim_Op_Kind;
12306 C := Build_C (Loc, Decls);
12308 -- Because the analysis of all statements was disabled, manually
12309 -- analyze the delay statement.
12312 D_Stat := Original_Node (D_Stat);
12315 -- Build an entry call using Simple_Entry_Call
12317 Extract_Entry (E_Call, Concval, Ename, Index);
12318 Build_Simple_Entry_Call (E_Call, Concval, Ename, Index);
12320 Decls := Declarations (E_Call);
12321 Stmts := Statements (Handled_Statement_Sequence (E_Call));
12330 B := Make_Defining_Identifier (Loc, Name_uB);
12333 Make_Object_Declaration (Loc,
12334 Defining_Identifier => B,
12335 Object_Definition =>
12336 New_Occurrence_Of (Standard_Boolean, Loc)));
12339 -- Duration and mode processing
12341 D_Type := Base_Type (Etype (Expression (D_Stat)));
12343 -- Use the type of the delay expression (Calendar or Real_Time) to
12344 -- generate the appropriate conversion.
12346 if Nkind (D_Stat) = N_Delay_Relative_Statement then
12347 D_Disc := Make_Integer_Literal (Loc, 0);
12348 D_Conv := Relocate_Node (Expression (D_Stat));
12350 elsif Is_RTE (D_Type, RO_CA_Time) then
12351 D_Disc := Make_Integer_Literal (Loc, 1);
12353 Make_Function_Call (Loc,
12354 Name => New_Occurrence_Of (RTE (RO_CA_To_Duration), Loc),
12355 Parameter_Associations =>
12356 New_List (New_Copy (Expression (D_Stat))));
12358 else pragma Assert (Is_RTE (D_Type, RO_RT_Time));
12359 D_Disc := Make_Integer_Literal (Loc, 2);
12361 Make_Function_Call (Loc,
12362 Name => New_Occurrence_Of (RTE (RO_RT_To_Duration), Loc),
12363 Parameter_Associations =>
12364 New_List (New_Copy (Expression (D_Stat))));
12367 D := Make_Temporary (Loc, 'D');
12373 Make_Object_Declaration (Loc,
12374 Defining_Identifier => D,
12375 Object_Definition => New_Occurrence_Of (Standard_Duration, Loc)));
12377 M := Make_Temporary (Loc, 'M');
12380 -- M : Integer := (0 | 1 | 2);
12383 Make_Object_Declaration (Loc,
12384 Defining_Identifier => M,
12385 Object_Definition => New_Occurrence_Of (Standard_Integer, Loc),
12386 Expression => D_Disc));
12388 -- Do the assignment at this stage only because the evaluation of the
12389 -- expression must not occur before (see ACVC C97302A).
12392 Make_Assignment_Statement (Loc,
12393 Name => New_Occurrence_Of (D, Loc),
12394 Expression => D_Conv));
12396 -- Parameter block processing
12398 -- Manually create the parameter block for dispatching calls. In the
12399 -- case of entries, the block has already been created during the call
12400 -- to Build_Simple_Entry_Call.
12402 if Is_Disp_Select then
12404 -- Tagged kind processing, generate:
12405 -- K : Ada.Tags.Tagged_Kind :=
12406 -- Ada.Tags.Get_Tagged_Kind (Ada.Tags.Tag <object>));
12408 K := Build_K (Loc, Decls, Obj);
12410 Blk_Typ := Build_Parameter_Block (Loc, Actuals, Formals, Decls);
12412 Parameter_Block_Pack (Loc, Blk_Typ, Actuals, Formals, Decls, Stmts);
12414 -- Dispatch table slot processing, generate:
12417 S := Build_S (Loc, Decls);
12420 -- S := Ada.Tags.Get_Offset_Index
12421 -- (Ada.Tags.Tag (<object>), DT_Position (Call_Ent));
12424 New_List (Build_S_Assignment (Loc, S, Obj, Call_Ent));
12427 -- _Disp_Timed_Select (<object>, S, P'Address, D, M, C, B);
12429 -- where Obj is the controlling formal parameter, S is the dispatch
12430 -- table slot number of the dispatching operation, P is the wrapped
12431 -- parameter block, D is the duration, M is the duration mode, C is
12432 -- the call kind and B is the call status.
12434 Params := New_List;
12436 Append_To (Params, New_Copy_Tree (Obj));
12437 Append_To (Params, New_Occurrence_Of (S, Loc));
12439 Make_Attribute_Reference (Loc,
12440 Prefix => New_Occurrence_Of (P, Loc),
12441 Attribute_Name => Name_Address));
12442 Append_To (Params, New_Occurrence_Of (D, Loc));
12443 Append_To (Params, New_Occurrence_Of (M, Loc));
12444 Append_To (Params, New_Occurrence_Of (C, Loc));
12445 Append_To (Params, New_Occurrence_Of (B, Loc));
12447 Append_To (Conc_Typ_Stmts,
12448 Make_Procedure_Call_Statement (Loc,
12452 (Etype (Etype (Obj)), Name_uDisp_Timed_Select), Loc),
12453 Parameter_Associations => Params));
12456 -- if C = POK_Protected_Entry
12457 -- or else C = POK_Task_Entry
12459 -- Param1 := P.Param1;
12461 -- ParamN := P.ParamN;
12464 Unpack := Parameter_Block_Unpack (Loc, P, Actuals, Formals);
12466 -- Generate the if statement only when the packed parameters need
12467 -- explicit assignments to their corresponding actuals.
12469 if Present (Unpack) then
12470 Append_To (Conc_Typ_Stmts,
12471 Make_Implicit_If_Statement (N,
12477 Left_Opnd => New_Occurrence_Of (C, Loc),
12480 (RTE (RE_POK_Protected_Entry), Loc)),
12484 Left_Opnd => New_Occurrence_Of (C, Loc),
12486 New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc))),
12488 Then_Statements => Unpack));
12494 -- if C = POK_Procedure
12495 -- or else C = POK_Protected_Procedure
12496 -- or else C = POK_Task_Procedure
12498 -- <dispatching-call>
12502 N_Stats := New_List (
12503 Make_Implicit_If_Statement (N,
12508 Left_Opnd => New_Occurrence_Of (C, Loc),
12510 New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)),
12516 Left_Opnd => New_Occurrence_Of (C, Loc),
12518 New_Occurrence_Of (RTE (
12519 RE_POK_Protected_Procedure), Loc)),
12522 Left_Opnd => New_Occurrence_Of (C, Loc),
12525 (RTE (RE_POK_Task_Procedure), Loc)))),
12527 Then_Statements => New_List (E_Call)));
12529 Append_To (Conc_Typ_Stmts,
12530 Make_Implicit_If_Statement (N,
12531 Condition => New_Occurrence_Of (B, Loc),
12532 Then_Statements => N_Stats));
12535 -- <dispatching-call>;
12539 New_List (New_Copy_Tree (E_Call),
12540 Make_Assignment_Statement (Loc,
12541 Name => New_Occurrence_Of (B, Loc),
12542 Expression => New_Occurrence_Of (Standard_True, Loc)));
12545 -- if K = Ada.Tags.TK_Limited_Tagged
12546 -- or else K = Ada.Tags.TK_Tagged
12554 Make_Implicit_If_Statement (N,
12555 Condition => Build_Dispatching_Tag_Check (K, N),
12556 Then_Statements => Lim_Typ_Stmts,
12557 Else_Statements => Conc_Typ_Stmts));
12562 -- <triggering-statements>
12564 -- <timed-statements>
12568 Make_Implicit_If_Statement (N,
12569 Condition => New_Occurrence_Of (B, Loc),
12570 Then_Statements => E_Stats,
12571 Else_Statements => D_Stats));
12574 -- Simple case of a non-dispatching trigger. Skip assignments to
12575 -- temporaries created for in-out parameters.
12577 -- This makes unwarranted assumptions about the shape of the expanded
12578 -- tree for the call, and should be cleaned up ???
12580 Stmt := First (Stmts);
12581 while Nkind (Stmt) /= N_Procedure_Call_Statement loop
12585 -- Do the assignment at this stage only because the evaluation
12586 -- of the expression must not occur before (see ACVC C97302A).
12588 Insert_Before (Stmt,
12589 Make_Assignment_Statement (Loc,
12590 Name => New_Occurrence_Of (D, Loc),
12591 Expression => D_Conv));
12594 Params := Parameter_Associations (Call);
12596 -- For a protected type, we build a Timed_Protected_Entry_Call
12598 if Is_Protected_Type (Etype (Concval)) then
12600 -- Create a new call statement
12602 Param := First (Params);
12603 while Present (Param)
12604 and then not Is_RTE (Etype (Param), RE_Call_Modes)
12609 Dummy := Remove_Next (Next (Param));
12611 -- Remove garbage is following the Cancel_Param if present
12613 Dummy := Next (Param);
12615 -- Remove the mode of the Protected_Entry_Call call, then remove
12616 -- the Communication_Block of the Protected_Entry_Call call, and
12617 -- finally add Duration and a Delay_Mode parameter
12619 pragma Assert (Present (Param));
12620 Rewrite (Param, New_Occurrence_Of (D, Loc));
12622 Rewrite (Dummy, New_Occurrence_Of (M, Loc));
12624 -- Add a Boolean flag for successful entry call
12626 Append_To (Params, New_Occurrence_Of (B, Loc));
12628 case Corresponding_Runtime_Package (Etype (Concval)) is
12629 when System_Tasking_Protected_Objects_Entries =>
12631 Make_Procedure_Call_Statement (Loc,
12634 (RTE (RE_Timed_Protected_Entry_Call), Loc),
12635 Parameter_Associations => Params));
12638 raise Program_Error;
12641 -- For the task case, build a Timed_Task_Entry_Call
12644 -- Create a new call statement
12646 Append_To (Params, New_Occurrence_Of (D, Loc));
12647 Append_To (Params, New_Occurrence_Of (M, Loc));
12648 Append_To (Params, New_Occurrence_Of (B, Loc));
12651 Make_Procedure_Call_Statement (Loc,
12653 New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
12654 Parameter_Associations => Params));
12658 Make_Implicit_If_Statement (N,
12659 Condition => New_Occurrence_Of (B, Loc),
12660 Then_Statements => E_Stats,
12661 Else_Statements => D_Stats));
12665 Make_Block_Statement (Loc,
12666 Declarations => Decls,
12667 Handled_Statement_Sequence =>
12668 Make_Handled_Sequence_Of_Statements (Loc, Stmts)));
12671 end Expand_N_Timed_Entry_Call;
12673 ----------------------------------------
12674 -- Expand_Protected_Body_Declarations --
12675 ----------------------------------------
12677 procedure Expand_Protected_Body_Declarations
12679 Spec_Id : Entity_Id)
12682 if No_Run_Time_Mode then
12683 Error_Msg_CRT ("protected body", N);
12686 elsif Expander_Active then
12688 -- Associate discriminals with the first subprogram or entry body to
12691 if Present (First_Protected_Operation (Declarations (N))) then
12692 Set_Discriminals (Parent (Spec_Id));
12695 end Expand_Protected_Body_Declarations;
12697 -------------------------
12698 -- External_Subprogram --
12699 -------------------------
12701 function External_Subprogram (E : Entity_Id) return Entity_Id is
12702 Subp : constant Entity_Id := Protected_Body_Subprogram (E);
12705 -- The internal and external subprograms follow each other on the entity
12706 -- chain. Note that previously private operations had no separate
12707 -- external subprogram. We now create one in all cases, because a
12708 -- private operation may actually appear in an external call, through
12709 -- a 'Access reference used for a callback.
12711 -- If the operation is a function that returns an anonymous access type,
12712 -- the corresponding itype appears before the operation, and must be
12715 -- This mechanism is fragile, there should be a real link between the
12716 -- two versions of the operation, but there is no place to put it ???
12718 if Is_Access_Type (Next_Entity (Subp)) then
12719 return Next_Entity (Next_Entity (Subp));
12721 return Next_Entity (Subp);
12723 end External_Subprogram;
12725 ------------------------------
12726 -- Extract_Dispatching_Call --
12727 ------------------------------
12729 procedure Extract_Dispatching_Call
12731 Call_Ent : out Entity_Id;
12732 Object : out Entity_Id;
12733 Actuals : out List_Id;
12734 Formals : out List_Id)
12736 Call_Nam : Node_Id;
12739 pragma Assert (Nkind (N) = N_Procedure_Call_Statement);
12741 if Present (Original_Node (N)) then
12742 Call_Nam := Name (Original_Node (N));
12744 Call_Nam := Name (N);
12747 -- Retrieve the name of the dispatching procedure. It contains the
12748 -- dispatch table slot number.
12751 case Nkind (Call_Nam) is
12752 when N_Identifier =>
12755 when N_Selected_Component =>
12756 Call_Nam := Selector_Name (Call_Nam);
12759 raise Program_Error;
12764 Actuals := Parameter_Associations (N);
12765 Call_Ent := Entity (Call_Nam);
12766 Formals := Parameter_Specifications (Parent (Call_Ent));
12767 Object := First (Actuals);
12769 if Present (Original_Node (Object)) then
12770 Object := Original_Node (Object);
12773 -- If the type of the dispatching object is an access type then return
12774 -- an explicit dereference.
12776 if Is_Access_Type (Etype (Object)) then
12777 Object := Make_Explicit_Dereference (Sloc (N), Object);
12780 end Extract_Dispatching_Call;
12782 -------------------
12783 -- Extract_Entry --
12784 -------------------
12786 procedure Extract_Entry
12788 Concval : out Node_Id;
12789 Ename : out Node_Id;
12790 Index : out Node_Id)
12792 Nam : constant Node_Id := Name (N);
12795 -- For a simple entry, the name is a selected component, with the
12796 -- prefix being the task value, and the selector being the entry.
12798 if Nkind (Nam) = N_Selected_Component then
12799 Concval := Prefix (Nam);
12800 Ename := Selector_Name (Nam);
12803 -- For a member of an entry family, the name is an indexed component
12804 -- where the prefix is a selected component, whose prefix in turn is
12805 -- the task value, and whose selector is the entry family. The single
12806 -- expression in the expressions list of the indexed component is the
12807 -- subscript for the family.
12809 else pragma Assert (Nkind (Nam) = N_Indexed_Component);
12810 Concval := Prefix (Prefix (Nam));
12811 Ename := Selector_Name (Prefix (Nam));
12812 Index := First (Expressions (Nam));
12815 -- Through indirection, the type may actually be a limited view of a
12816 -- concurrent type. When compiling a call, the non-limited view of the
12817 -- type is visible.
12819 if From_Limited_With (Etype (Concval)) then
12820 Set_Etype (Concval, Non_Limited_View (Etype (Concval)));
12824 -------------------
12825 -- Family_Offset --
12826 -------------------
12828 function Family_Offset
12833 Cap : Boolean) return Node_Id
12839 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id;
12840 -- If one of the bounds is a reference to a discriminant, replace with
12841 -- corresponding discriminal of type. Within the body of a task retrieve
12842 -- the renamed discriminant by simple visibility, using its generated
12843 -- name. Within a protected object, find the original discriminant and
12844 -- replace it with the discriminal of the current protected operation.
12846 ------------------------------
12847 -- Convert_Discriminant_Ref --
12848 ------------------------------
12850 function Convert_Discriminant_Ref (Bound : Node_Id) return Node_Id is
12851 Loc : constant Source_Ptr := Sloc (Bound);
12856 if Is_Entity_Name (Bound)
12857 and then Ekind (Entity (Bound)) = E_Discriminant
12859 if Is_Task_Type (Ttyp) and then Has_Completion (Ttyp) then
12860 B := Make_Identifier (Loc, Chars (Entity (Bound)));
12861 Find_Direct_Name (B);
12863 elsif Is_Protected_Type (Ttyp) then
12864 D := First_Discriminant (Ttyp);
12865 while Chars (D) /= Chars (Entity (Bound)) loop
12866 Next_Discriminant (D);
12869 B := New_Occurrence_Of (Discriminal (D), Loc);
12872 B := New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
12875 elsif Nkind (Bound) = N_Attribute_Reference then
12879 B := New_Copy_Tree (Bound);
12883 Make_Attribute_Reference (Loc,
12884 Attribute_Name => Name_Pos,
12885 Prefix => New_Occurrence_Of (Etype (Bound), Loc),
12886 Expressions => New_List (B));
12887 end Convert_Discriminant_Ref;
12889 -- Start of processing for Family_Offset
12892 Real_Hi := Convert_Discriminant_Ref (Hi);
12893 Real_Lo := Convert_Discriminant_Ref (Lo);
12896 if Is_Task_Type (Ttyp) then
12897 Ityp := RTE (RE_Task_Entry_Index);
12899 Ityp := RTE (RE_Protected_Entry_Index);
12903 Make_Attribute_Reference (Loc,
12904 Prefix => New_Occurrence_Of (Ityp, Loc),
12905 Attribute_Name => Name_Min,
12906 Expressions => New_List (
12908 Make_Integer_Literal (Loc, Entry_Family_Bound - 1)));
12911 Make_Attribute_Reference (Loc,
12912 Prefix => New_Occurrence_Of (Ityp, Loc),
12913 Attribute_Name => Name_Max,
12914 Expressions => New_List (
12916 Make_Integer_Literal (Loc, -Entry_Family_Bound)));
12919 return Make_Op_Subtract (Loc, Real_Hi, Real_Lo);
12926 function Family_Size
12931 Cap : Boolean) return Node_Id
12936 if Is_Task_Type (Ttyp) then
12937 Ityp := RTE (RE_Task_Entry_Index);
12939 Ityp := RTE (RE_Protected_Entry_Index);
12943 Make_Attribute_Reference (Loc,
12944 Prefix => New_Occurrence_Of (Ityp, Loc),
12945 Attribute_Name => Name_Max,
12946 Expressions => New_List (
12948 Left_Opnd => Family_Offset (Loc, Hi, Lo, Ttyp, Cap),
12949 Right_Opnd => Make_Integer_Literal (Loc, 1)),
12950 Make_Integer_Literal (Loc, 0)));
12953 ----------------------------
12954 -- Find_Enclosing_Context --
12955 ----------------------------
12957 procedure Find_Enclosing_Context
12959 Context : out Node_Id;
12960 Context_Id : out Entity_Id;
12961 Context_Decls : out List_Id)
12964 -- Traverse the parent chain looking for an enclosing body, block,
12965 -- package or return statement.
12967 Context := Parent (N);
12968 while not Nkind_In (Context, N_Block_Statement,
12970 N_Extended_Return_Statement,
12972 N_Package_Declaration,
12976 Context := Parent (Context);
12979 -- Extract the constituents of the context
12981 if Nkind (Context) = N_Extended_Return_Statement then
12982 Context_Decls := Return_Object_Declarations (Context);
12983 Context_Id := Return_Statement_Entity (Context);
12985 -- Package declarations and bodies use a common library-level activation
12986 -- chain or task master, therefore return the package declaration as the
12987 -- proper carrier for the appropriate flag.
12989 elsif Nkind (Context) = N_Package_Body then
12990 Context_Decls := Declarations (Context);
12991 Context_Id := Corresponding_Spec (Context);
12992 Context := Parent (Context_Id);
12994 if Nkind (Context) = N_Defining_Program_Unit_Name then
12995 Context := Parent (Parent (Context));
12997 Context := Parent (Context);
13000 elsif Nkind (Context) = N_Package_Declaration then
13001 Context_Decls := Visible_Declarations (Specification (Context));
13002 Context_Id := Defining_Unit_Name (Specification (Context));
13004 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13005 Context_Id := Defining_Identifier (Context_Id);
13009 Context_Decls := Declarations (Context);
13011 if Nkind (Context) = N_Block_Statement then
13012 Context_Id := Entity (Identifier (Context));
13014 elsif Nkind (Context) = N_Entry_Body then
13015 Context_Id := Defining_Identifier (Context);
13017 elsif Nkind (Context) = N_Subprogram_Body then
13018 if Present (Corresponding_Spec (Context)) then
13019 Context_Id := Corresponding_Spec (Context);
13021 Context_Id := Defining_Unit_Name (Specification (Context));
13023 if Nkind (Context_Id) = N_Defining_Program_Unit_Name then
13024 Context_Id := Defining_Identifier (Context_Id);
13028 elsif Nkind (Context) = N_Task_Body then
13029 Context_Id := Corresponding_Spec (Context);
13032 raise Program_Error;
13036 pragma Assert (Present (Context));
13037 pragma Assert (Present (Context_Id));
13038 pragma Assert (Present (Context_Decls));
13039 end Find_Enclosing_Context;
13041 -----------------------
13042 -- Find_Master_Scope --
13043 -----------------------
13045 function Find_Master_Scope (E : Entity_Id) return Entity_Id is
13049 -- In Ada 2005, the master is the innermost enclosing scope that is not
13050 -- transient. If the enclosing block is the rewriting of a call or the
13051 -- scope is an extended return statement this is valid master. The
13052 -- master in an extended return is only used within the return, and is
13053 -- subsequently overwritten in Move_Activation_Chain, but it must exist
13054 -- now before that overwriting occurs.
13058 if Ada_Version >= Ada_2005 then
13059 while Is_Internal (S) loop
13060 if Nkind (Parent (S)) = N_Block_Statement
13062 Nkind (Original_Node (Parent (S))) = N_Procedure_Call_Statement
13066 elsif Ekind (S) = E_Return_Statement then
13076 end Find_Master_Scope;
13078 -------------------------------
13079 -- First_Protected_Operation --
13080 -------------------------------
13082 function First_Protected_Operation (D : List_Id) return Node_Id is
13083 First_Op : Node_Id;
13086 First_Op := First (D);
13087 while Present (First_Op)
13088 and then not Nkind_In (First_Op, N_Subprogram_Body, N_Entry_Body)
13094 end First_Protected_Operation;
13096 ---------------------------------------
13097 -- Install_Private_Data_Declarations --
13098 ---------------------------------------
13100 procedure Install_Private_Data_Declarations
13102 Spec_Id : Entity_Id;
13103 Conc_Typ : Entity_Id;
13104 Body_Nod : Node_Id;
13106 Barrier : Boolean := False;
13107 Family : Boolean := False)
13109 Is_Protected : constant Boolean := Is_Protected_Type (Conc_Typ);
13112 Insert_Node : Node_Id := Empty;
13113 Obj_Ent : Entity_Id;
13115 procedure Add (Decl : Node_Id);
13116 -- Add a single declaration after Insert_Node. If this is the first
13117 -- addition, Decl is added to the front of Decls and it becomes the
13120 function Replace_Bound (Bound : Node_Id) return Node_Id;
13121 -- The bounds of an entry index may depend on discriminants, create a
13122 -- reference to the corresponding prival. Otherwise return a duplicate
13123 -- of the original bound.
13129 procedure Add (Decl : Node_Id) is
13131 if No (Insert_Node) then
13132 Prepend_To (Decls, Decl);
13134 Insert_After (Insert_Node, Decl);
13137 Insert_Node := Decl;
13140 --------------------------
13141 -- Replace_Discriminant --
13142 --------------------------
13144 function Replace_Bound (Bound : Node_Id) return Node_Id is
13146 if Nkind (Bound) = N_Identifier
13147 and then Is_Discriminal (Entity (Bound))
13149 return Make_Identifier (Loc, Chars (Entity (Bound)));
13151 return Duplicate_Subexpr (Bound);
13155 -- Start of processing for Install_Private_Data_Declarations
13158 -- Step 1: Retrieve the concurrent object entity. Obj_Ent can denote
13159 -- formal parameter _O, _object or _task depending on the context.
13161 Obj_Ent := Concurrent_Object (Spec_Id, Conc_Typ);
13163 -- Special processing of _O for barrier functions, protected entries
13170 (Ekind (Spec_Id) = E_Entry
13171 or else Ekind (Spec_Id) = E_Entry_Family))
13174 Conc_Rec : constant Entity_Id :=
13175 Corresponding_Record_Type (Conc_Typ);
13176 Typ_Id : constant Entity_Id :=
13177 Make_Defining_Identifier (Loc,
13178 New_External_Name (Chars (Conc_Rec), 'P'));
13181 -- type prot_typVP is access prot_typV;
13184 Make_Full_Type_Declaration (Loc,
13185 Defining_Identifier => Typ_Id,
13187 Make_Access_To_Object_Definition (Loc,
13188 Subtype_Indication =>
13189 New_Occurrence_Of (Conc_Rec, Loc)));
13193 -- _object : prot_typVP := prot_typV (_O);
13196 Make_Object_Declaration (Loc,
13197 Defining_Identifier =>
13198 Make_Defining_Identifier (Loc, Name_uObject),
13199 Object_Definition => New_Occurrence_Of (Typ_Id, Loc),
13201 Unchecked_Convert_To (Typ_Id,
13202 New_Occurrence_Of (Obj_Ent, Loc)));
13205 -- Set the reference to the concurrent object
13207 Obj_Ent := Defining_Identifier (Decl);
13211 -- Step 2: Create the Protection object and build its declaration for
13212 -- any protected entry (family) of subprogram. Note for the lock-free
13213 -- implementation, the Protection object is not needed anymore.
13215 if Is_Protected and then not Uses_Lock_Free (Conc_Typ) then
13217 Prot_Ent : constant Entity_Id := Make_Temporary (Loc, 'R');
13221 Set_Protection_Object (Spec_Id, Prot_Ent);
13223 -- Determine the proper protection type
13225 if Has_Attach_Handler (Conc_Typ)
13226 and then not Restricted_Profile
13228 Prot_Typ := RE_Static_Interrupt_Protection;
13230 elsif Has_Interrupt_Handler (Conc_Typ)
13231 and then not Restriction_Active (No_Dynamic_Attachment)
13233 Prot_Typ := RE_Dynamic_Interrupt_Protection;
13236 case Corresponding_Runtime_Package (Conc_Typ) is
13237 when System_Tasking_Protected_Objects_Entries =>
13238 Prot_Typ := RE_Protection_Entries;
13240 when System_Tasking_Protected_Objects_Single_Entry =>
13241 Prot_Typ := RE_Protection_Entry;
13243 when System_Tasking_Protected_Objects =>
13244 Prot_Typ := RE_Protection;
13247 raise Program_Error;
13252 -- conc_typR : protection_typ renames _object._object;
13255 Make_Object_Renaming_Declaration (Loc,
13256 Defining_Identifier => Prot_Ent,
13258 New_Occurrence_Of (RTE (Prot_Typ), Loc),
13260 Make_Selected_Component (Loc,
13261 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13262 Selector_Name => Make_Identifier (Loc, Name_uObject)));
13267 -- Step 3: Add discriminant renamings (if any)
13269 if Has_Discriminants (Conc_Typ) then
13274 D := First_Discriminant (Conc_Typ);
13275 while Present (D) loop
13277 -- Adjust the source location
13279 Set_Sloc (Discriminal (D), Loc);
13282 -- discr_name : discr_typ renames _object.discr_name;
13284 -- discr_name : discr_typ renames _task.discr_name;
13287 Make_Object_Renaming_Declaration (Loc,
13288 Defining_Identifier => Discriminal (D),
13289 Subtype_Mark => New_Occurrence_Of (Etype (D), Loc),
13291 Make_Selected_Component (Loc,
13292 Prefix => New_Occurrence_Of (Obj_Ent, Loc),
13293 Selector_Name => Make_Identifier (Loc, Chars (D))));
13296 Next_Discriminant (D);
13301 -- Step 4: Add private component renamings (if any)
13303 if Is_Protected then
13304 Def := Protected_Definition (Parent (Conc_Typ));
13306 if Present (Private_Declarations (Def)) then
13309 Comp_Id : Entity_Id;
13310 Decl_Id : Entity_Id;
13313 Comp := First (Private_Declarations (Def));
13314 while Present (Comp) loop
13315 if Nkind (Comp) = N_Component_Declaration then
13316 Comp_Id := Defining_Identifier (Comp);
13318 Make_Defining_Identifier (Loc, Chars (Comp_Id));
13320 -- Minimal decoration
13322 if Ekind (Spec_Id) = E_Function then
13323 Set_Ekind (Decl_Id, E_Constant);
13325 Set_Ekind (Decl_Id, E_Variable);
13328 Set_Prival (Comp_Id, Decl_Id);
13329 Set_Prival_Link (Decl_Id, Comp_Id);
13330 Set_Is_Aliased (Decl_Id, Is_Aliased (Comp_Id));
13333 -- comp_name : comp_typ renames _object.comp_name;
13336 Make_Object_Renaming_Declaration (Loc,
13337 Defining_Identifier => Decl_Id,
13339 New_Occurrence_Of (Etype (Comp_Id), Loc),
13341 Make_Selected_Component (Loc,
13343 New_Occurrence_Of (Obj_Ent, Loc),
13345 Make_Identifier (Loc, Chars (Comp_Id))));
13355 -- Step 5: Add the declaration of the entry index and the associated
13356 -- type for barrier functions and entry families.
13358 if (Barrier and Family) or else Ekind (Spec_Id) = E_Entry_Family then
13360 E : constant Entity_Id := Index_Object (Spec_Id);
13361 Index : constant Entity_Id :=
13362 Defining_Identifier
13363 (Entry_Index_Specification
13364 (Entry_Body_Formal_Part (Body_Nod)));
13365 Index_Con : constant Entity_Id :=
13366 Make_Defining_Identifier (Loc, Chars (Index));
13368 Index_Typ : Entity_Id;
13372 -- Minimal decoration
13374 Set_Ekind (Index_Con, E_Constant);
13375 Set_Entry_Index_Constant (Index, Index_Con);
13376 Set_Discriminal_Link (Index_Con, Index);
13378 -- Retrieve the bounds of the entry family
13380 High := Type_High_Bound (Etype (Index));
13381 Low := Type_Low_Bound (Etype (Index));
13383 -- In the simple case the entry family is given by a subtype
13384 -- mark and the index constant has the same type.
13386 if Is_Entity_Name (Original_Node (
13387 Discrete_Subtype_Definition (Parent (Index))))
13389 Index_Typ := Etype (Index);
13391 -- Otherwise a new subtype declaration is required
13394 High := Replace_Bound (High);
13395 Low := Replace_Bound (Low);
13397 Index_Typ := Make_Temporary (Loc, 'J');
13400 -- subtype Jnn is <Etype of Index> range Low .. High;
13403 Make_Subtype_Declaration (Loc,
13404 Defining_Identifier => Index_Typ,
13405 Subtype_Indication =>
13406 Make_Subtype_Indication (Loc,
13408 New_Occurrence_Of (Base_Type (Etype (Index)), Loc),
13410 Make_Range_Constraint (Loc,
13411 Range_Expression =>
13412 Make_Range (Loc, Low, High))));
13416 Set_Etype (Index_Con, Index_Typ);
13418 -- Create the object which designates the index:
13419 -- J : constant Jnn :=
13420 -- Jnn'Val (_E - <index expr> + Jnn'Pos (Jnn'First));
13422 -- where Jnn is the subtype created above or the original type of
13423 -- the index, _E is a formal of the protected body subprogram and
13424 -- <index expr> is the index of the first family member.
13427 Make_Object_Declaration (Loc,
13428 Defining_Identifier => Index_Con,
13429 Constant_Present => True,
13430 Object_Definition =>
13431 New_Occurrence_Of (Index_Typ, Loc),
13434 Make_Attribute_Reference (Loc,
13436 New_Occurrence_Of (Index_Typ, Loc),
13437 Attribute_Name => Name_Val,
13439 Expressions => New_List (
13443 Make_Op_Subtract (Loc,
13444 Left_Opnd => New_Occurrence_Of (E, Loc),
13446 Entry_Index_Expression (Loc,
13447 Defining_Identifier (Body_Nod),
13451 Make_Attribute_Reference (Loc,
13453 New_Occurrence_Of (Index_Typ, Loc),
13454 Attribute_Name => Name_Pos,
13455 Expressions => New_List (
13456 Make_Attribute_Reference (Loc,
13458 New_Occurrence_Of (Index_Typ, Loc),
13459 Attribute_Name => Name_First)))))));
13463 end Install_Private_Data_Declarations;
13465 -----------------------
13466 -- Is_Exception_Safe --
13467 -----------------------
13469 function Is_Exception_Safe (Subprogram : Node_Id) return Boolean is
13471 function Has_Side_Effect (N : Node_Id) return Boolean;
13472 -- Return True whenever encountering a subprogram call or raise
13473 -- statement of any kind in the sequence of statements
13475 ---------------------
13476 -- Has_Side_Effect --
13477 ---------------------
13479 -- What is this doing buried two levels down in exp_ch9. It seems like a
13480 -- generally useful function, and indeed there may be code duplication
13481 -- going on here ???
13483 function Has_Side_Effect (N : Node_Id) return Boolean is
13487 function Is_Call_Or_Raise (N : Node_Id) return Boolean;
13488 -- Indicate whether N is a subprogram call or a raise statement
13490 ----------------------
13491 -- Is_Call_Or_Raise --
13492 ----------------------
13494 function Is_Call_Or_Raise (N : Node_Id) return Boolean is
13496 return Nkind_In (N, N_Procedure_Call_Statement,
13499 N_Raise_Constraint_Error,
13500 N_Raise_Program_Error,
13501 N_Raise_Storage_Error);
13502 end Is_Call_Or_Raise;
13504 -- Start of processing for Has_Side_Effect
13508 while Present (Stmt) loop
13509 if Is_Call_Or_Raise (Stmt) then
13513 -- An object declaration can also contain a function call or a
13514 -- raise statement.
13516 if Nkind (Stmt) = N_Object_Declaration then
13517 Expr := Expression (Stmt);
13519 if Present (Expr) and then Is_Call_Or_Raise (Expr) then
13528 end Has_Side_Effect;
13530 -- Start of processing for Is_Exception_Safe
13533 -- When exceptions can't be propagated, the subprogram returns normally
13535 if No_Exception_Handlers_Set then
13539 -- If the checks handled by the back end are not disabled, we cannot
13540 -- ensure that no exception will be raised.
13542 if not Access_Checks_Suppressed (Empty)
13543 or else not Discriminant_Checks_Suppressed (Empty)
13544 or else not Range_Checks_Suppressed (Empty)
13545 or else not Index_Checks_Suppressed (Empty)
13546 or else Opt.Stack_Checking_Enabled
13551 if Has_Side_Effect (First (Declarations (Subprogram)))
13554 (First (Statements (Handled_Statement_Sequence (Subprogram))))
13560 end Is_Exception_Safe;
13562 ---------------------------------
13563 -- Is_Potentially_Large_Family --
13564 ---------------------------------
13566 function Is_Potentially_Large_Family
13567 (Base_Index : Entity_Id;
13568 Conctyp : Entity_Id;
13570 Hi : Node_Id) return Boolean
13573 return Scope (Base_Index) = Standard_Standard
13574 and then Base_Index = Base_Type (Standard_Integer)
13575 and then Has_Discriminants (Conctyp)
13577 Present (Discriminant_Default_Value (First_Discriminant (Conctyp)))
13579 (Denotes_Discriminant (Lo, True)
13581 Denotes_Discriminant (Hi, True));
13582 end Is_Potentially_Large_Family;
13584 -------------------------------------
13585 -- Is_Private_Primitive_Subprogram --
13586 -------------------------------------
13588 function Is_Private_Primitive_Subprogram (Id : Entity_Id) return Boolean is
13591 (Ekind (Id) = E_Function or else Ekind (Id) = E_Procedure)
13592 and then Is_Private_Primitive (Id);
13593 end Is_Private_Primitive_Subprogram;
13599 function Index_Object (Spec_Id : Entity_Id) return Entity_Id is
13600 Bod_Subp : constant Entity_Id := Protected_Body_Subprogram (Spec_Id);
13601 Formal : Entity_Id;
13604 Formal := First_Formal (Bod_Subp);
13605 while Present (Formal) loop
13607 -- Look for formal parameter _E
13609 if Chars (Formal) = Name_uE then
13613 Next_Formal (Formal);
13616 -- A protected body subprogram should always have the parameter in
13619 raise Program_Error;
13622 --------------------------------
13623 -- Make_Initialize_Protection --
13624 --------------------------------
13626 function Make_Initialize_Protection
13627 (Protect_Rec : Entity_Id) return List_Id
13629 Loc : constant Source_Ptr := Sloc (Protect_Rec);
13632 Ptyp : constant Node_Id :=
13633 Corresponding_Concurrent_Type (Protect_Rec);
13635 L : constant List_Id := New_List;
13636 Has_Entry : constant Boolean := Has_Entries (Ptyp);
13637 Prio_Type : Entity_Id;
13638 Prio_Var : Entity_Id := Empty;
13639 Restricted : constant Boolean := Restricted_Profile;
13642 -- We may need two calls to properly initialize the object, one to
13643 -- Initialize_Protection, and possibly one to Install_Handlers if we
13644 -- have a pragma Attach_Handler.
13646 -- Get protected declaration. In the case of a task type declaration,
13647 -- this is simply the parent of the protected type entity. In the single
13648 -- protected object declaration, this parent will be the implicit type,
13649 -- and we can find the corresponding single protected object declaration
13650 -- by searching forward in the declaration list in the tree.
13652 -- Is the test for N_Single_Protected_Declaration needed here??? Nodes
13653 -- of this type should have been removed during semantic analysis.
13655 Pdec := Parent (Ptyp);
13656 while not Nkind_In (Pdec, N_Protected_Type_Declaration,
13657 N_Single_Protected_Declaration)
13662 -- Build the parameter list for the call. Note that _Init is the name
13663 -- of the formal for the object to be initialized, which is the task
13664 -- value record itself.
13668 -- For lock-free implementation, skip initializations of the Protection
13671 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13673 -- Object parameter. This is a pointer to the object of type
13674 -- Protection used by the GNARL to control the protected object.
13677 Make_Attribute_Reference (Loc,
13679 Make_Selected_Component (Loc,
13680 Prefix => Make_Identifier (Loc, Name_uInit),
13681 Selector_Name => Make_Identifier (Loc, Name_uObject)),
13682 Attribute_Name => Name_Unchecked_Access));
13684 -- Priority parameter. Set to Unspecified_Priority unless there is a
13685 -- Priority rep item, in which case we take the value from the pragma
13686 -- or attribute definition clause, or there is an Interrupt_Priority
13687 -- rep item and no Priority rep item, and we set the ceiling to
13688 -- Interrupt_Priority'Last, an implementation-defined value, see
13691 if Has_Rep_Item (Ptyp, Name_Priority, Check_Parents => False) then
13693 Prio_Clause : constant Node_Id :=
13695 (Ptyp, Name_Priority, Check_Parents => False);
13702 if Nkind (Prio_Clause) = N_Pragma then
13705 (First (Pragma_Argument_Associations (Prio_Clause)));
13707 -- Get_Rep_Item returns either priority pragma.
13709 if Pragma_Name (Prio_Clause) = Name_Priority then
13710 Prio_Type := RTE (RE_Any_Priority);
13712 Prio_Type := RTE (RE_Interrupt_Priority);
13715 -- Attribute definition clause Priority
13718 if Chars (Prio_Clause) = Name_Priority then
13719 Prio_Type := RTE (RE_Any_Priority);
13721 Prio_Type := RTE (RE_Interrupt_Priority);
13724 Prio := Expression (Prio_Clause);
13727 -- Always create a locale variable to capture the priority.
13728 -- The priority is also passed to Install_Restriced_Handlers.
13729 -- Note that it is really necessary to create this variable
13730 -- explicitly. It might be thought that removing side effects
13731 -- would the appropriate approach, but that could generate
13732 -- declarations improperly placed in the enclosing scope.
13734 Prio_Var := Make_Temporary (Loc, 'R', Prio);
13736 Make_Object_Declaration (Loc,
13737 Defining_Identifier => Prio_Var,
13738 Object_Definition => New_Occurrence_Of (Prio_Type, Loc),
13739 Expression => Relocate_Node (Prio)));
13741 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13744 -- When no priority is specified but an xx_Handler pragma is, we
13745 -- default to System.Interrupts.Default_Interrupt_Priority, see
13748 elsif Has_Attach_Handler (Ptyp)
13749 or else Has_Interrupt_Handler (Ptyp)
13752 New_Occurrence_Of (RTE (RE_Default_Interrupt_Priority), Loc));
13754 -- Normal case, no priority or xx_Handler specified, default priority
13758 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
13761 -- Test for Compiler_Info parameter. This parameter allows entry body
13762 -- procedures and barrier functions to be called from the runtime. It
13763 -- is a pointer to the record generated by the compiler to represent
13764 -- the protected object.
13766 -- A protected type without entries that covers an interface and
13767 -- overrides the abstract routines with protected procedures is
13768 -- considered equivalent to a protected type with entries in the
13769 -- context of dispatching select statements.
13771 -- Protected types with interrupt handlers (when not using a
13772 -- restricted profile) are also considered equivalent to protected
13773 -- types with entries.
13775 -- The types which are used (Static_Interrupt_Protection and
13776 -- Dynamic_Interrupt_Protection) are derived from Protection_Entries.
13779 Pkg_Id : constant RTU_Id := Corresponding_Runtime_Package (Ptyp);
13781 Called_Subp : RE_Id;
13785 when System_Tasking_Protected_Objects_Entries =>
13786 Called_Subp := RE_Initialize_Protection_Entries;
13788 -- Argument Compiler_Info
13791 Make_Attribute_Reference (Loc,
13792 Prefix => Make_Identifier (Loc, Name_uInit),
13793 Attribute_Name => Name_Address));
13795 when System_Tasking_Protected_Objects_Single_Entry =>
13796 Called_Subp := RE_Initialize_Protection_Entry;
13798 -- Argument Compiler_Info
13801 Make_Attribute_Reference (Loc,
13802 Prefix => Make_Identifier (Loc, Name_uInit),
13803 Attribute_Name => Name_Address));
13805 when System_Tasking_Protected_Objects =>
13806 Called_Subp := RE_Initialize_Protection;
13809 raise Program_Error;
13812 -- Entry_Bodies parameter. This is a pointer to an array of
13813 -- pointers to the entry body procedures and barrier functions of
13814 -- the object. If the protected type has no entries this object
13815 -- will not exist, in this case, pass a null (it can happen when
13816 -- there are protected interrupt handlers or interfaces).
13819 P_Arr := Entry_Bodies_Array (Ptyp);
13821 -- Argument Entry_Body (for single entry) or Entry_Bodies (for
13822 -- multiple entries).
13825 Make_Attribute_Reference (Loc,
13826 Prefix => New_Occurrence_Of (P_Arr, Loc),
13827 Attribute_Name => Name_Unrestricted_Access));
13829 if Pkg_Id = System_Tasking_Protected_Objects_Entries then
13831 -- Find index mapping function (clumsy but ok for now)
13833 while Ekind (P_Arr) /= E_Function loop
13834 Next_Entity (P_Arr);
13838 Make_Attribute_Reference (Loc,
13839 Prefix => New_Occurrence_Of (P_Arr, Loc),
13840 Attribute_Name => Name_Unrestricted_Access));
13843 elsif Pkg_Id = System_Tasking_Protected_Objects_Single_Entry then
13845 -- This is the case where we have a protected object with
13846 -- interfaces and no entries, and the single entry restriction
13847 -- is in effect. We pass a null pointer for the entry
13848 -- parameter because there is no actual entry.
13850 Append_To (Args, Make_Null (Loc));
13852 elsif Pkg_Id = System_Tasking_Protected_Objects_Entries then
13854 -- This is the case where we have a protected object with no
13856 -- - either interrupt handlers with non restricted profile,
13858 -- Note that the types which are used for interrupt handlers
13859 -- (Static/Dynamic_Interrupt_Protection) are derived from
13860 -- Protection_Entries. We pass two null pointers because there
13861 -- is no actual entry, and the initialization procedure needs
13862 -- both Entry_Bodies and Find_Body_Index.
13864 Append_To (Args, Make_Null (Loc));
13865 Append_To (Args, Make_Null (Loc));
13869 Make_Procedure_Call_Statement (Loc,
13871 New_Occurrence_Of (RTE (Called_Subp), Loc),
13872 Parameter_Associations => Args));
13876 if Has_Attach_Handler (Ptyp) then
13878 -- We have a list of N Attach_Handler (ProcI, ExprI), and we have to
13879 -- make the following call:
13881 -- Install_Handlers (_object,
13882 -- ((Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13884 -- or, in the case of Ravenscar:
13886 -- Install_Restricted_Handlers
13887 -- (Prio, (Expr1, Proc1'access), ...., (ExprN, ProcN'access));
13890 Args : constant List_Id := New_List;
13891 Table : constant List_Id := New_List;
13892 Ritem : Node_Id := First_Rep_Item (Ptyp);
13895 -- Build the Priority parameter (only for ravenscar)
13899 -- Priority comes from a pragma
13901 if Present (Prio_Var) then
13902 Append_To (Args, New_Occurrence_Of (Prio_Var, Loc));
13904 -- Priority is the default one
13909 (RTE (RE_Default_Interrupt_Priority), Loc));
13913 -- Build the Attach_Handler table argument
13915 while Present (Ritem) loop
13916 if Nkind (Ritem) = N_Pragma
13917 and then Pragma_Name (Ritem) = Name_Attach_Handler
13920 Handler : constant Node_Id :=
13921 First (Pragma_Argument_Associations (Ritem));
13923 Interrupt : constant Node_Id := Next (Handler);
13924 Expr : constant Node_Id := Expression (Interrupt);
13928 Make_Aggregate (Loc, Expressions => New_List (
13929 Unchecked_Convert_To
13930 (RTE (RE_System_Interrupt_Id), Expr),
13931 Make_Attribute_Reference (Loc,
13933 Make_Selected_Component (Loc,
13935 Make_Identifier (Loc, Name_uInit),
13937 Duplicate_Subexpr_No_Checks
13938 (Expression (Handler))),
13939 Attribute_Name => Name_Access))));
13943 Next_Rep_Item (Ritem);
13946 -- Append the table argument we just built
13948 Append_To (Args, Make_Aggregate (Loc, Table));
13950 -- Append the Install_Handlers (or Install_Restricted_Handlers)
13951 -- call to the statements.
13954 -- Call a simplified version of Install_Handlers to be used
13955 -- when the Ravenscar restrictions are in effect
13956 -- (Install_Restricted_Handlers).
13959 Make_Procedure_Call_Statement (Loc,
13962 (RTE (RE_Install_Restricted_Handlers), Loc),
13963 Parameter_Associations => Args));
13966 if not Uses_Lock_Free (Defining_Identifier (Pdec)) then
13968 -- First, prepends the _object argument
13971 Make_Attribute_Reference (Loc,
13973 Make_Selected_Component (Loc,
13974 Prefix => Make_Identifier (Loc, Name_uInit),
13976 Make_Identifier (Loc, Name_uObject)),
13977 Attribute_Name => Name_Unchecked_Access));
13980 -- Then, insert call to Install_Handlers
13983 Make_Procedure_Call_Statement (Loc,
13985 New_Occurrence_Of (RTE (RE_Install_Handlers), Loc),
13986 Parameter_Associations => Args));
13992 end Make_Initialize_Protection;
13994 ---------------------------
13995 -- Make_Task_Create_Call --
13996 ---------------------------
13998 function Make_Task_Create_Call (Task_Rec : Entity_Id) return Node_Id is
13999 Loc : constant Source_Ptr := Sloc (Task_Rec);
14009 Ttyp := Corresponding_Concurrent_Type (Task_Rec);
14010 Tnam := Chars (Ttyp);
14012 -- Get task declaration. In the case of a task type declaration, this is
14013 -- simply the parent of the task type entity. In the single task
14014 -- declaration, this parent will be the implicit type, and we can find
14015 -- the corresponding single task declaration by searching forward in the
14016 -- declaration list in the tree.
14018 -- Is the test for N_Single_Task_Declaration needed here??? Nodes of
14019 -- this type should have been removed during semantic analysis.
14021 Tdec := Parent (Ttyp);
14022 while not Nkind_In (Tdec, N_Task_Type_Declaration,
14023 N_Single_Task_Declaration)
14028 -- Now we can find the task definition from this declaration
14030 Tdef := Task_Definition (Tdec);
14032 -- Build the parameter list for the call. Note that _Init is the name
14033 -- of the formal for the object to be initialized, which is the task
14034 -- value record itself.
14038 -- Priority parameter. Set to Unspecified_Priority unless there is a
14039 -- Priority rep item, in which case we take the value from the rep item.
14041 if Has_Rep_Item (Ttyp, Name_Priority, Check_Parents => False) then
14043 Make_Selected_Component (Loc,
14044 Prefix => Make_Identifier (Loc, Name_uInit),
14045 Selector_Name => Make_Identifier (Loc, Name_uPriority)));
14048 New_Occurrence_Of (RTE (RE_Unspecified_Priority), Loc));
14051 -- Optional Stack parameter
14053 if Restricted_Profile then
14055 -- If the stack has been preallocated by the expander then
14056 -- pass its address. Otherwise, pass a null address.
14058 if Preallocated_Stacks_On_Target then
14060 Make_Attribute_Reference (Loc,
14062 Make_Selected_Component (Loc,
14063 Prefix => Make_Identifier (Loc, Name_uInit),
14064 Selector_Name => Make_Identifier (Loc, Name_uStack)),
14065 Attribute_Name => Name_Address));
14069 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
14073 -- Size parameter. If no Storage_Size pragma is present, then
14074 -- the size is taken from the taskZ variable for the type, which
14075 -- is either Unspecified_Size, or has been reset by the use of
14076 -- a Storage_Size attribute definition clause. If a pragma is
14077 -- present, then the size is taken from the _Size field of the
14078 -- task value record, which was set from the pragma value.
14080 if Present (Tdef) and then Has_Storage_Size_Pragma (Tdef) then
14082 Make_Selected_Component (Loc,
14083 Prefix => Make_Identifier (Loc, Name_uInit),
14084 Selector_Name => Make_Identifier (Loc, Name_uSize)));
14088 New_Occurrence_Of (Storage_Size_Variable (Ttyp), Loc));
14091 -- Task_Info parameter. Set to Unspecified_Task_Info unless there is a
14092 -- Task_Info pragma, in which case we take the value from the pragma.
14094 if Has_Rep_Pragma (Ttyp, Name_Task_Info, Check_Parents => False) then
14096 Make_Selected_Component (Loc,
14097 Prefix => Make_Identifier (Loc, Name_uInit),
14098 Selector_Name => Make_Identifier (Loc, Name_uTask_Info)));
14102 New_Occurrence_Of (RTE (RE_Unspecified_Task_Info), Loc));
14105 -- CPU parameter. Set to Unspecified_CPU unless there is a CPU rep item,
14106 -- in which case we take the value from the rep item. The parameter is
14107 -- passed as an Integer because in the case of unspecified CPU the
14108 -- value is not in the range of CPU_Range.
14110 if Has_Rep_Item (Ttyp, Name_CPU, Check_Parents => False) then
14112 Convert_To (Standard_Integer,
14113 Make_Selected_Component (Loc,
14114 Prefix => Make_Identifier (Loc, Name_uInit),
14115 Selector_Name => Make_Identifier (Loc, Name_uCPU))));
14118 New_Occurrence_Of (RTE (RE_Unspecified_CPU), Loc));
14121 if not Restricted_Profile then
14123 -- Deadline parameter. If no Relative_Deadline pragma is present,
14124 -- then the deadline is Time_Span_Zero. If a pragma is present, then
14125 -- the deadline is taken from the _Relative_Deadline field of the
14126 -- task value record, which was set from the pragma value. Note that
14127 -- this parameter must not be generated for the restricted profiles
14128 -- since Ravenscar does not allow deadlines.
14130 -- Case where pragma Relative_Deadline applies: use given value
14132 if Present (Tdef) and then Has_Relative_Deadline_Pragma (Tdef) then
14134 Make_Selected_Component (Loc,
14135 Prefix => Make_Identifier (Loc, Name_uInit),
14137 Make_Identifier (Loc, Name_uRelative_Deadline)));
14139 -- No pragma Relative_Deadline apply to the task
14143 New_Occurrence_Of (RTE (RE_Time_Span_Zero), Loc));
14146 -- Dispatching_Domain parameter. If no Dispatching_Domain rep item is
14147 -- present, then the dispatching domain is null. If a rep item is
14148 -- present, then the dispatching domain is taken from the
14149 -- _Dispatching_Domain field of the task value record, which was set
14150 -- from the rep item value.
14152 -- Case where Dispatching_Domain rep item applies: use given value
14155 (Ttyp, Name_Dispatching_Domain, Check_Parents => False)
14158 Make_Selected_Component (Loc,
14160 Make_Identifier (Loc, Name_uInit),
14162 Make_Identifier (Loc, Name_uDispatching_Domain)));
14164 -- No pragma or aspect Dispatching_Domain applies to the task
14167 Append_To (Args, Make_Null (Loc));
14170 -- Number of entries. This is an expression of the form:
14172 -- n + _Init.a'Length + _Init.a'B'Length + ...
14174 -- where a,b... are the entry family names for the task definition
14177 Build_Entry_Count_Expression
14182 (Parent (Corresponding_Record_Type (Ttyp))))),
14184 Append_To (Args, Ecount);
14186 -- Master parameter. This is a reference to the _Master parameter of
14187 -- the initialization procedure, except in the case of the pragma
14188 -- Restrictions (No_Task_Hierarchy) where the value is fixed to
14189 -- System.Tasking.Library_Task_Level.
14191 if Restriction_Active (No_Task_Hierarchy) = False then
14192 Append_To (Args, Make_Identifier (Loc, Name_uMaster));
14195 New_Occurrence_Of (RTE (RE_Library_Task_Level), Loc));
14199 -- State parameter. This is a pointer to the task body procedure. The
14200 -- required value is obtained by taking 'Unrestricted_Access of the task
14201 -- body procedure and converting it (with an unchecked conversion) to
14202 -- the type required by the task kernel. For further details, see the
14203 -- description of Expand_N_Task_Body. We use 'Unrestricted_Access rather
14204 -- than 'Address in order to avoid creating trampolines.
14207 Body_Proc : constant Node_Id := Get_Task_Body_Procedure (Ttyp);
14208 Subp_Ptr_Typ : constant Node_Id :=
14209 Create_Itype (E_Access_Subprogram_Type, Tdec);
14210 Ref : constant Node_Id := Make_Itype_Reference (Loc);
14213 Set_Directly_Designated_Type (Subp_Ptr_Typ, Body_Proc);
14214 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
14216 -- Be sure to freeze a reference to the access-to-subprogram type,
14217 -- otherwise gigi will complain that it's in the wrong scope, because
14218 -- it's actually inside the init procedure for the record type that
14219 -- corresponds to the task type.
14221 -- This processing is causing a crash in the .NET/JVM back ends that
14222 -- is not yet understood, so skip it in these cases ???
14224 if VM_Target = No_VM then
14225 Set_Itype (Ref, Subp_Ptr_Typ);
14226 Append_Freeze_Action (Task_Rec, Ref);
14229 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
14230 Make_Qualified_Expression (Loc,
14231 Subtype_Mark => New_Occurrence_Of (Subp_Ptr_Typ, Loc),
14233 Make_Attribute_Reference (Loc,
14234 Prefix => New_Occurrence_Of (Body_Proc, Loc),
14235 Attribute_Name => Name_Unrestricted_Access))));
14237 -- For the .NET/JVM cases revert to the original code below ???
14241 Unchecked_Convert_To (RTE (RE_Task_Procedure_Access),
14242 Make_Attribute_Reference (Loc,
14243 Prefix => New_Occurrence_Of (Body_Proc, Loc),
14244 Attribute_Name => Name_Address)));
14248 -- Discriminants parameter. This is just the address of the task
14249 -- value record itself (which contains the discriminant values
14252 Make_Attribute_Reference (Loc,
14253 Prefix => Make_Identifier (Loc, Name_uInit),
14254 Attribute_Name => Name_Address));
14256 -- Elaborated parameter. This is an access to the elaboration Boolean
14259 Make_Attribute_Reference (Loc,
14260 Prefix => Make_Identifier (Loc, New_External_Name (Tnam, 'E')),
14261 Attribute_Name => Name_Unchecked_Access));
14263 -- Add Chain parameter (not done for sequential elaboration policy, see
14264 -- comment for Create_Restricted_Task_Sequential in s-tarest.ads).
14266 if Partition_Elaboration_Policy /= 'S' then
14267 Append_To (Args, Make_Identifier (Loc, Name_uChain));
14270 -- Task name parameter. Take this from the _Task_Id parameter to the
14271 -- init call unless there is a Task_Name pragma, in which case we take
14272 -- the value from the pragma.
14274 if Has_Rep_Pragma (Ttyp, Name_Task_Name, Check_Parents => False) then
14275 -- Copy expression in full, because it may be dynamic and have
14282 (Pragma_Argument_Associations
14284 (Ttyp, Name_Task_Name, Check_Parents => False))))));
14287 Append_To (Args, Make_Identifier (Loc, Name_uTask_Name));
14290 -- Created_Task parameter. This is the _Task_Id field of the task
14294 Make_Selected_Component (Loc,
14295 Prefix => Make_Identifier (Loc, Name_uInit),
14296 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)));
14302 if Restricted_Profile then
14303 if Partition_Elaboration_Policy = 'S' then
14304 Create_RE := RE_Create_Restricted_Task_Sequential;
14306 Create_RE := RE_Create_Restricted_Task;
14309 Create_RE := RE_Create_Task;
14312 Name := New_Occurrence_Of (RTE (Create_RE), Loc);
14316 Make_Procedure_Call_Statement (Loc,
14318 Parameter_Associations => Args);
14319 end Make_Task_Create_Call;
14321 ------------------------------
14322 -- Next_Protected_Operation --
14323 ------------------------------
14325 function Next_Protected_Operation (N : Node_Id) return Node_Id is
14329 Next_Op := Next (N);
14330 while Present (Next_Op)
14331 and then not Nkind_In (Next_Op, N_Subprogram_Body, N_Entry_Body)
14337 end Next_Protected_Operation;
14339 ---------------------
14340 -- Null_Statements --
14341 ---------------------
14343 function Null_Statements (Stats : List_Id) return Boolean is
14347 Stmt := First (Stats);
14348 while Nkind (Stmt) /= N_Empty
14349 and then (Nkind_In (Stmt, N_Null_Statement, N_Label)
14351 (Nkind (Stmt) = N_Pragma
14353 Nam_In (Pragma_Name (Stmt), Name_Unreferenced,
14360 return Nkind (Stmt) = N_Empty;
14361 end Null_Statements;
14363 --------------------------
14364 -- Parameter_Block_Pack --
14365 --------------------------
14367 function Parameter_Block_Pack
14369 Blk_Typ : Entity_Id;
14373 Stmts : List_Id) return Node_Id
14375 Actual : Entity_Id;
14376 Expr : Node_Id := Empty;
14377 Formal : Entity_Id;
14378 Has_Param : Boolean := False;
14381 Temp_Asn : Node_Id;
14382 Temp_Nam : Node_Id;
14385 Actual := First (Actuals);
14386 Formal := Defining_Identifier (First (Formals));
14387 Params := New_List;
14388 while Present (Actual) loop
14389 if Is_By_Copy_Type (Etype (Actual)) then
14391 -- Jnn : aliased <formal-type>
14393 Temp_Nam := Make_Temporary (Loc, 'J');
14396 Make_Object_Declaration (Loc,
14397 Aliased_Present => True,
14398 Defining_Identifier => Temp_Nam,
14399 Object_Definition =>
14400 New_Occurrence_Of (Etype (Formal), Loc)));
14402 if Ekind (Formal) /= E_Out_Parameter then
14408 New_Occurrence_Of (Temp_Nam, Loc);
14410 Set_Assignment_OK (Temp_Asn);
14413 Make_Assignment_Statement (Loc,
14415 Expression => New_Copy_Tree (Actual)));
14419 -- Jnn'unchecked_access
14422 Make_Attribute_Reference (Loc,
14423 Attribute_Name => Name_Unchecked_Access,
14424 Prefix => New_Occurrence_Of (Temp_Nam, Loc)));
14428 -- The controlling parameter is omitted
14431 if not Is_Controlling_Actual (Actual) then
14433 Make_Reference (Loc, New_Copy_Tree (Actual)));
14439 Next_Actual (Actual);
14440 Next_Formal_With_Extras (Formal);
14444 Expr := Make_Aggregate (Loc, Params);
14449 -- J1'unchecked_access;
14450 -- <actual2>'reference;
14453 P := Make_Temporary (Loc, 'P');
14456 Make_Object_Declaration (Loc,
14457 Defining_Identifier => P,
14458 Object_Definition => New_Occurrence_Of (Blk_Typ, Loc),
14459 Expression => Expr));
14462 end Parameter_Block_Pack;
14464 ----------------------------
14465 -- Parameter_Block_Unpack --
14466 ----------------------------
14468 function Parameter_Block_Unpack
14472 Formals : List_Id) return List_Id
14474 Actual : Entity_Id;
14476 Formal : Entity_Id;
14477 Has_Asnmt : Boolean := False;
14478 Result : constant List_Id := New_List;
14481 Actual := First (Actuals);
14482 Formal := Defining_Identifier (First (Formals));
14483 while Present (Actual) loop
14484 if Is_By_Copy_Type (Etype (Actual))
14485 and then Ekind (Formal) /= E_In_Parameter
14488 -- <actual> := P.<formal>;
14491 Make_Assignment_Statement (Loc,
14495 Make_Explicit_Dereference (Loc,
14496 Make_Selected_Component (Loc,
14498 New_Occurrence_Of (P, Loc),
14500 Make_Identifier (Loc, Chars (Formal)))));
14502 Set_Assignment_OK (Name (Asnmt));
14503 Append_To (Result, Asnmt);
14508 Next_Actual (Actual);
14509 Next_Formal_With_Extras (Formal);
14515 return New_List (Make_Null_Statement (Loc));
14517 end Parameter_Block_Unpack;
14519 ----------------------
14520 -- Set_Discriminals --
14521 ----------------------
14523 procedure Set_Discriminals (Dec : Node_Id) is
14526 D_Minal : Entity_Id;
14529 pragma Assert (Nkind (Dec) = N_Protected_Type_Declaration);
14530 Pdef := Defining_Identifier (Dec);
14532 if Has_Discriminants (Pdef) then
14533 D := First_Discriminant (Pdef);
14534 while Present (D) loop
14536 Make_Defining_Identifier (Sloc (D),
14537 Chars => New_External_Name (Chars (D), 'D'));
14539 Set_Ekind (D_Minal, E_Constant);
14540 Set_Etype (D_Minal, Etype (D));
14541 Set_Scope (D_Minal, Pdef);
14542 Set_Discriminal (D, D_Minal);
14543 Set_Discriminal_Link (D_Minal, D);
14545 Next_Discriminant (D);
14548 end Set_Discriminals;
14550 -----------------------
14551 -- Trivial_Accept_OK --
14552 -----------------------
14554 function Trivial_Accept_OK return Boolean is
14556 case Opt.Task_Dispatching_Policy is
14558 -- If we have the default task dispatching policy in effect, we can
14559 -- definitely do the optimization (one way of looking at this is to
14560 -- think of the formal definition of the default policy being allowed
14561 -- to run any task it likes after a rendezvous, so even if notionally
14562 -- a full rescheduling occurs, we can say that our dispatching policy
14563 -- (i.e. the default dispatching policy) reorders the queue to be the
14564 -- same as just before the call.
14569 -- FIFO_Within_Priorities certainly does not permit this
14570 -- optimization since the Rendezvous is a scheduling action that may
14571 -- require some other task to be run.
14576 -- For now, disallow the optimization for all other policies. This
14577 -- may be over-conservative, but it is certainly not incorrect.
14583 end Trivial_Accept_OK;